dolibarr/htdocs/compta/facture/apercu.php

379 lines
15 KiB
PHP
Raw Normal View History

<?php
2005-01-07 15:08:57 +01:00
/* Copyright (C) 2002-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
* Copyright (C) 2004-2007 Laurent Destailleur <eldy@users.sourceforge.net>
2012-12-30 15:13:49 +01:00
* Copyright (C) 2005-2011 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2014 Frederic France <frederic.france@free.fr>
2004-10-07 11:36:56 +02:00
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
2004-10-07 11:36:56 +02:00
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
2011-08-01 00:21:57 +02:00
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2004-10-07 11:36:56 +02:00
*
*/
2005-04-14 01:33:12 +02:00
/**
* \file htdocs/compta/facture/apercu.php
* \ingroup facture
* \brief Preview Tab of invoice
*/
2004-10-07 11:36:56 +02:00
require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/invoice.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
2012-09-15 10:01:35 +02:00
if (! empty($conf->projet->enabled)) require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
2004-10-07 11:36:56 +02:00
$langs->load("bills");
// Security check
$socid=0;
2012-02-27 22:26:22 +01:00
$id = GETPOST('facid','int');
$ref = GETPOST("ref");
if ($user->societe_id) $socid=$user->societe_id;
$result = restrictedArea($user, 'facture', $id);
/*
* View
*/
$now=dol_now();
2004-10-07 11:36:56 +02:00
llxHeader('',$langs->trans("Bill"),'Facture');
$form = new Form($db);
2004-10-07 11:36:56 +02:00
/* *************************************************************************** */
/* */
/* Mode fiche */
/* */
/* *************************************************************************** */
if ($id > 0 || ! empty($ref))
{
$object = New Facture($db);
2011-05-21 16:24:09 +02:00
if ($object->fetch($id,$ref) > 0)
{
2011-09-11 20:35:38 +02:00
$soc = new Societe($db);
$soc->fetch($object->socid);
2011-05-21 16:24:09 +02:00
$head = facture_prepare_head($object);
2009-08-05 20:22:40 +02:00
dol_fiche_head($head, 'preview', $langs->trans("InvoiceCustomer"), 0, 'bill');
$totalpaye = $object->getSommePaiement();
/*
* Invoice
*/
print '<table class="border" width="100%">';
2009-03-02 19:25:51 +01:00
// Ref
print '<tr><td width="25%">'.$langs->trans('Ref').'</td>';
print '<td colspan="5">'.$object->ref.'</td>';
print '</tr>';
// Ref customer
print '<tr><td>'.$langs->trans('RefCustomer').'</td>';
print '<td colspan="5">'.$object->ref_client.'</td>';
print '</tr>';
// Thirdparty
print '<tr><td>'.$langs->trans("Company").'</td>';
print '<td colspan="5">'.$soc->getNomUrl(1,'compta').'</td>';
print '</tr>';
// Type
print '<tr><td>'.$langs->trans('Type').'</td>';
print '<td colspan="5">';
print $object->getLibType();
if ($object->type == Facture::TYPE_REPLACEMENT)
{
$facreplaced=new Facture($db);
$facreplaced->fetch($object->fk_facture_source);
print ' ('.$langs->transnoentities("ReplaceInvoice",$facreplaced->getNomUrl(1)).')';
}
if ($object->type == Facture::TYPE_CREDIT_NOTE)
{
$facusing=new Facture($db);
$facusing->fetch($object->fk_facture_source);
print ' ('.$langs->transnoentities("CorrectInvoice",$facusing->getNomUrl(1)).')';
}
$facidavoir=$object->getListIdAvoirFromInvoice();
2011-09-17 21:49:50 +02:00
if (count($facidavoir) > 0)
{
print ' ('.$langs->transnoentities("InvoiceHasAvoir");
$i=0;
foreach($facidavoir as $id)
{
if ($i==0) print ' ';
else print ',';
$facavoir=new Facture($db);
$facavoir->fetch($id);
print $facavoir->getNomUrl(1);
}
print ')';
}
if ($objectidnext > 0)
{
$facthatreplace=new Facture($db);
$facthatreplace->fetch($objectidnext);
print ' ('.$langs->transnoentities("ReplacedByInvoice",$facthatreplace->getNomUrl(1)).')';
}
print '</td>';
print '</tr>';
// Relative and absolute discounts
$addabsolutediscount=' <a href="'.DOL_URL_ROOT.'/comm/remx.php?id='.$soc->id.'&backtopage='.urlencode($_SERVER["PHP_SELF"]).'?facid='.$object->id.'">'.$langs->trans("AddGlobalDiscount").'</a>';
$addcreditnote=' <a href="'.DOL_URL_ROOT.'/compta/facture.php?action=create&socid='.$soc->id.'&type=2&backtopage='.urlencode($_SERVER["PHP_SELF"]).'?facid='.$object->id.'">'.$langs->trans("AddCreditNote").'</a>';
print '<tr><td>'.$langs->trans('Discounts').'</td>';
print '<td colspan="5">';
if ($soc->remise_percent) print $langs->trans("CompanyHasRelativeDiscount",$soc->remise_percent);
else print $langs->trans("CompanyHasNoRelativeDiscount");
if ($absolute_discount > 0)
{
print '. ';
if ($object->statut > Facture::STATUS_DRAFT || $object->type == Facture::TYPE_CREDIT_NOTE || $object->type == Facture::TYPE_DEPOSIT)
{
if ($object->statut == Facture::STATUS_DRAFT)
{
print $langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->transnoentities("Currency".$conf->currency));
print '. ';
}
else
{
if ($object->statut < Facture::STATUS_VALIDATED || $object->type == Facture::TYPE_CREDIT_NOTE || $object->type == Facture::TYPE_DEPOSIT)
{
$text=$langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->transnoentities("Currency".$conf->currency));
print '<br>'.$text.'.<br>';
}
else
{
$text=$langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->transnoentities("Currency".$conf->currency));
$text2=$langs->trans("AbsoluteDiscountUse");
print $form->textwithpicto($text,$text2);
}
}
}
else
{
// Remise dispo de type remise fixe (not credit note)
$filter='fk_facture_source IS NULL';
print '<br>';
$form->form_remise_dispo($_SERVER["PHP_SELF"].'?facid='.$object->id, 0, 'remise_id',$soc->id, $absolute_discount, $filter, $resteapayer, ' - '.$addabsolutediscount);
}
}
else
{
if ($absolute_creditnote > 0) // If not linked will be added later
{
if ($object->statut == Facture::STATUS_DRAFT && $object->type != Facture::TYPE_CREDIT_NOTE && $object->type != Facture::TYPE_DEPOSIT) print ' - '.$addabsolutediscount.'<br>';
else print '.';
}
else print '. ';
}
if ($absolute_creditnote > 0)
{
// If validated, we show link "add credit note to payment"
if ($object->statut != Facture::STATUS_VALIDATED || $object->type == Facture::TYPE_CREDIT_NOTE || $object->type == Facture::TYPE_DEPOSIT)
{
if ($object->statut == Facture::STATUS_DRAFT && $object->type != Facture::TYPE_DEPOSIT)
{
$text=$langs->trans("CompanyHasCreditNote",price($absolute_creditnote),$langs->transnoentities("Currency".$conf->currency));
print $form->textwithpicto($text,$langs->trans("CreditNoteDepositUse"));
}
else
{
print $langs->trans("CompanyHasCreditNote",price($absolute_creditnote),$langs->transnoentities("Currency".$conf->currency)).'.';
}
}
else
{
// Remise dispo de type avoir
$filter='fk_facture_source IS NOT NULL';
if (! $absolute_discount) print '<br>';
$form->form_remise_dispo($_SERVER["PHP_SELF"].'?facid='.$object->id, 0, 'remise_id_for_payment', $soc->id, $absolute_creditnote, $filter, $resteapayer);
}
}
if (! $absolute_discount && ! $absolute_creditnote)
{
print $langs->trans("CompanyHasNoAbsoluteDiscount");
if ($object->statut == Facture::STATUS_DRAFT && $object->type != Facture::TYPE_CREDIT_NOTE && $object->type != Facture::TYPE_DEPOSIT) print ' - '.$addabsolutediscount.'<br>';
else print '. ';
}
/*if ($object->statut == 0 && $object->type != 2 && $object->type != 3)
{
if (! $absolute_discount && ! $absolute_creditnote) print '<br>';
//print ' &nbsp; - &nbsp; ';
print $addabsolutediscount;
//print ' &nbsp; - &nbsp; '.$addcreditnote; // We disbale link to credit note
}*/
print '</td>';
print '</tr>';
// Dates
print '<tr><td>'.$langs->trans("Date").'</td>';
print '<td>'.dol_print_date($object->date,"daytext").'</td>';
// Right part with $rowspan lines
$rowspan=5;
if (! empty($conf->projet->enabled)) $rowspan++;
print '<td rowspan="'.$rowspan.'" valign="top" width="50%">';
/*
* Documents
*/
$objectref = dol_sanitizeFileName($object->ref);
2006-06-09 17:47:20 +02:00
$dir_output = $conf->facture->dir_output . "/";
$filepath = $dir_output . $objectref . "/";
$file = $filepath . $objectref . ".pdf";
$filedetail = $filepath . $objectref . "-detail.pdf";
2011-05-21 16:24:09 +02:00
$relativepath = $objectref.'/'.$objectref.'.pdf';
$relativepathdetail = $objectref.'/'.$objectref.'-detail.pdf';
2014-04-30 13:50:25 +02:00
// Define path to preview pdf file (preview precompiled "file.ext" are "file.ext_preview.png")
$fileimage = $file.'_preview.png'; // If PDF has 1 page
2014-04-30 13:50:25 +02:00
$fileimagebis = $file.'_preview-0.pdf.png'; // If PDF has more than one page
$relativepathimage = $relativepath.'_preview.png';
$var=true;
// Si fichier PDF existe
if (file_exists($file))
{
$encfile = urlencode($file);
2014-11-26 20:35:08 +01:00
print '<table class="nobordernopadding" width="100%">';
print '<tr class="liste_titre"><td colspan="4">'.$langs->trans("Documents").'</td></tr>';
2013-06-20 09:18:12 +02:00
print "<tr ".$bc[$var]."><td>".$langs->trans("Bill")." PDF</td>";
2013-04-20 20:30:18 +02:00
print '<td><a data-ajax="false" href="'.DOL_URL_ROOT . '/document.php?modulepart=facture&file='.urlencode($relativepath).'">'.$object->ref.'.pdf</a></td>';
print '<td align="right">'.dol_print_size(dol_filesize($file)). '</td>';
print '<td align="right">'.dol_print_date(dol_filemtime($file),'dayhour').'</td>';
print '</tr>';
// Si fichier detail PDF existe
if (file_exists($filedetail)) // facture detaillee supplementaire
{
2013-06-20 09:18:12 +02:00
print "<tr ".$bc[$var]."><td>Facture detaillee</td>";
2013-04-20 20:30:18 +02:00
print '<td><a data-ajax="false" href="'.DOL_URL_ROOT . '/document.php?modulepart=facture&file='.urlencode($relativepathdetail).'">'.$object->ref.'-detail.pdf</a></td>';
print '<td align="right">'.dol_print_size(dol_filesize($filedetail)).'</td>';
print '<td align="right">'.dol_print_date(dol_filemtime($filedetail),'dayhour').'</td>';
print '</tr>';
}
print "</table>\n";
// Conversion du PDF en image png si fichier png non existant
if (! file_exists($fileimage) && ! file_exists($fileimagebis))
{
if (class_exists("Imagick"))
{
2014-04-30 13:50:25 +02:00
$ret = dol_convert_file($file,'png',$fileimage);
if ($ret < 0) $error++;
}
else
{
$langs->load("errors");
print '<font class="error">'.$langs->trans("ErrorNoImagickReadimage").'</font>';
}
}
}
print "</td></tr>";
2014-11-26 20:07:47 +01:00
// Total HT
print '<tr><td>'.$langs->trans("AmountHT").'</td>';
print '<td align="right" class="nowrap"><b>' . price($object->total_ht, '', $langs, 0, - 1, - 1, $conf->currency) . '</b></td>';
print '</tr>';
2014-11-26 20:07:47 +01:00
// Total VAT
print '<tr><td>'.$langs->trans('AmountVAT').'</td>';
print '<td align="right" class="nowrap"><b>' . price($object->total_tva, '', $langs, 0, - 1, - 1, $conf->currency) . '</b></td>';
print '</tr>';
2014-11-26 20:07:47 +01:00
// Total TTC
print '<tr><td>'.$langs->trans('AmountTTC').'</td>';
print '<td align="right" class="nowrap"><b>' . price($object->total_ttc, '', $langs, 0, - 1, - 1, $conf->currency) . '</b></td>';
print '</tr>';
// Statut
print '<tr><td>'.$langs->trans('Status').'</td>';
print '<td align="left">'.($object->getLibStatut(4,$totalpaye)).'</td>';
print '</tr>';
// Projet
2012-09-15 10:01:35 +02:00
if (! empty($conf->projet->enabled))
{
$langs->load("projects");
print '<tr><td>'.$langs->trans("Project").'</td>';
print '<td>';
if ($object->fk_project > 0)
{
2010-03-11 15:31:16 +01:00
$project = New Project($db);
$project->fetch($object->fk_project);
print '<a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$object->fk_project.'">'.$project->title.'</a>';
}
else
{
print '&nbsp;';
}
print '</td></tr>';
}
print '</table>';
2011-05-21 16:24:09 +02:00
dol_fiche_end();
2004-10-07 11:36:56 +02:00
}
else
2004-10-07 11:36:56 +02:00
{
// Facture non trouvee
print $langs->trans("ErrorBillNotFound",$id);
2004-10-07 11:36:56 +02:00
}
2009-03-02 19:25:51 +01:00
}
2004-10-07 11:36:56 +02:00
print '<table class="border" width="100%">';
print '<tr><td>';
print '<div class="photolist">';
// Si fichier png PDF d'1 page trouve
2004-10-07 11:36:56 +02:00
if (file_exists($fileimage))
2009-03-02 19:25:51 +01:00
{
print '<img class="photo photowithmargin" src="'.DOL_URL_ROOT . '/viewimage.php?modulepart=apercufacture&amp;file='.urlencode($relativepathimage).'">';
2004-10-07 11:36:56 +02:00
}
// Si fichier png PDF de plus d'1 page trouve
elseif (file_exists($fileimagebis))
{
$multiple = preg_replace('/\.png/','',$relativepath) . "-";
2011-05-21 16:24:09 +02:00
for ($i = 0; $i < 20; $i++)
{
$preview = $multiple.$i.'.png';
2011-05-21 16:24:09 +02:00
if (file_exists($dir_output.$preview))
{
print '<img class="photo photowithmargin" src="'.DOL_URL_ROOT . '/viewimage.php?modulepart=apercufacture&amp;file='.urlencode($preview).'"><p>';
}
}
2006-06-09 17:47:20 +02:00
}
print '</div>';
print '</td></tr>';
print '</table>';
llxFooter();
2014-10-17 12:56:54 +02:00
$db->close();