* Copyright (C) 2004 Eric Seigne * Copyright (C) 2004-2007 Laurent Destailleur * Copyright (C) 2005-2011 Regis Houssin * * 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 2 of the License, or * (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 * along with this program. If not, see . * * $Id: apercu.php,v 1.73 2011/07/31 22:23:13 eldy Exp $ */ /** * \file htdocs/compta/facture/apercu.php * \ingroup facture * \brief Page de l'onglet apercu d'une facture * \version $Revision: 1.73 $ */ require("../../main.inc.php"); require_once(DOL_DOCUMENT_ROOT."/compta/facture/class/facture.class.php"); require_once(DOL_DOCUMENT_ROOT.'/lib/invoice.lib.php'); require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php"); if ($conf->projet->enabled) require_once(DOL_DOCUMENT_ROOT."/projet/class/project.class.php"); $langs->load("bills"); // Security check $socid=0; $id = GETPOST("facid"); $ref = GETPOST("ref"); if ($user->societe_id) $socid=$user->societe_id; $result = restrictedArea($user, 'facture', $id); /* * View */ $now=dol_now(); llxHeader('',$langs->trans("Bill"),'Facture'); $html = new Form($db); /* *************************************************************************** */ /* */ /* Mode fiche */ /* */ /* *************************************************************************** */ if ($id > 0 || ! empty($ref)) { $object = New Facture($db); if ($object->fetch($id,$ref) > 0) { $soc = new Societe($db, $object->socid); $soc->fetch($object->socid); $author = new User($db); if ($object->user_author) { $author->fetch($object->user_author); } $head = facture_prepare_head($object); dol_fiche_head($head, 'preview', $langs->trans("InvoiceCustomer"), 0, 'bill'); $totalpaye = $object->getSommePaiement(); /* * Facture */ print ''; $rowspan=3; // Reference print ''; // Societe print ''; print ''; print ''; // Type print ''; // Relative and absolute discounts $addabsolutediscount=' '.$langs->trans("AddGlobalDiscount").''; $addcreditnote=' '.$langs->trans("AddCreditNote").''; print ''; // Dates print ''; print ''; print ""; // Date payment term print ''; // Conditions reglement print ''; print ''; // Mode de reglement print ''; $nbrows=5; if ($conf->projet->enabled) $nbrows++; print '"; print ''; print ''; print ''; print ''; print ''; print ''; print ''; // Statut print ''; // Projet if ($conf->projet->enabled) { $langs->load("projects"); print ''; print ''; } print '
'.$langs->trans('Ref').''.$object->ref.'
'.$langs->trans("Company").''.$soc->getNomUrl(1,'compta').'
'.$langs->trans('Type').''; print $object->getLibType(); if ($object->type == 1) { $facreplaced=new Facture($db); $facreplaced->fetch($object->fk_facture_source); print ' ('.$langs->transnoentities("ReplaceInvoice",$facreplaced->getNomUrl(1)).')'; } if ($object->type == 2) { $facusing=new Facture($db); $facusing->fetch($object->fk_facture_source); print ' ('.$langs->transnoentities("CorrectInvoice",$facusing->getNomUrl(1)).')'; } $facidavoir=$object->getListIdAvoirFromInvoice(); if (sizeof($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 '
'.$langs->trans('Discounts'); print ''; if ($soc->remise_client) print $langs->trans("CompanyHasRelativeDiscount",$soc->remise_client); else print $langs->trans("CompanyHasNoRelativeDiscount"); if ($absolute_discount > 0) { print '. '; if ($object->statut > 0 || $object->type == 2 || $object->type == 3) { if ($object->statut == 0) { print $langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->transnoentities("Currency".$conf->monnaie)); print '. '; } else { if ($object->statut < 1 || $object->type == 2 || $object->type == 3) { $text=$langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->transnoentities("Currency".$conf->monnaie)); print '
'.$text.'.
'; } else { $text=$langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->transnoentities("Currency".$conf->monnaie)); $text2=$langs->trans("AbsoluteDiscountUse"); print $html->textwithpicto($text,$text2); } } } else { // Remise dispo de type remise fixe (not credit note) $filter='fk_facture_source IS NULL'; print '
'; $html->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 linke will be added later { if ($object->statut == 0 && $object->type != 2 && $object->type != 3) print ' - '.$addabsolutediscount.'
'; else print '.'; } else print '. '; } if ($absolute_creditnote > 0) { // If validated, we show link "add credit note to payment" if ($object->statut != 1 || $object->type == 2 || $object->type == 3) { if ($object->statut == 0 && $object->type != 3) { $text=$langs->trans("CompanyHasCreditNote",price($absolute_creditnote),$langs->transnoentities("Currency".$conf->monnaie)); print $html->textwithpicto($text,$langs->trans("CreditNoteDepositUse")); } else { print $langs->trans("CompanyHasCreditNote",price($absolute_creditnote),$langs->transnoentities("Currency".$conf->monnaie)).'.'; } } else { // Remise dispo de type avoir $filter='fk_facture_source IS NOT NULL'; if (! $absolute_discount) print '
'; $html->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 == 0 && $object->type != 2 && $object->type != 3) print ' - '.$addabsolutediscount.'
'; else print '. '; } /*if ($object->statut == 0 && $object->type != 2 && $object->type != 3) { if (! $absolute_discount && ! $absolute_creditnote) print '
'; //print '   -   '; print $addabsolutediscount; //print '   -   '.$addcreditnote; // We disbale link to credit note }*/ print '
'.$langs->trans("Date").''.dol_print_date($object->date,"daytext").'
'; print ''; if ($object->type != 2 && $action != 'editpaymentterm' && $object->brouillon && $user->rights->facture->creer) print ''; print '
'; print $langs->trans('DateMaxPayment'); print 'id.'">'.img_edit($langs->trans('SetDate'),1).'
'; print '
'; if ($object->type != 2) { if ($action == 'editpaymentterm') { $html->form_date($_SERVER['PHP_SELF'].'?facid='.$object->id,$object->date_lim_reglement,'paymentterm'); } else { print dol_print_date($object->date_lim_reglement,'daytext'); if ($object->date_lim_reglement < ($now - $conf->facture->client->warning_delay) && ! $object->paye && $object->statut == 1 && ! $object->am) print img_warning($langs->trans('Late')); } } else { print ' '; } print '
'.$langs->trans("PaymentConditionsShort").''; $html->form_conditions_reglement($_SERVER["PHP_SELF"]."?facid=$object->id",$object->cond_reglement_id,"none"); print '
'; print ''; if ($action != 'editmode' && $object->brouillon && $user->rights->facture->creer) print ''; print '
'; print $langs->trans('PaymentMode'); print 'id.'">'.img_edit($langs->trans('SetMode'),1).'
'; print '
'; if ($action == 'editmode') { $html->form_modes_reglement($_SERVER['PHP_SELF'].'?facid='.$object->id,$object->mode_reglement_id,'mode_reglement_id'); } else { $html->form_modes_reglement($_SERVER['PHP_SELF'].'?facid='.$object->id,$object->mode_reglement_id,'none'); } print ''; /* * Documents */ $objectref = dol_sanitizeFileName($object->ref); $dir_output = $conf->facture->dir_output . "/"; $filepath = $dir_output . $objectref . "/"; $file = $filepath . $objectref . ".pdf"; $filedetail = $filepath . $objectref . "-detail.pdf"; $relativepath = $objectref.'/'.$objectref.'.pdf'; $relativepathdetail = $objectref.'/'.$objectref.'-detail.pdf'; // Chemin vers png apercus $fileimage = $file.".png"; // Si PDF d'1 page $fileimagebis = $file."-0.png"; // Si PDF de plus d'1 page $relativepathimage = $relativepath.'.png'; $var=true; // Si fichier PDF existe if (file_exists($file)) { $encfile = urlencode($file); print_titre($langs->trans("Documents")); print ''; print ""; print ''; print ''; print ''; print ''; // Si fichier detail PDF existe if (file_exists($filedetail)) // facture detaillee supplementaire { print ""; print ''; print ''; print ''; print ''; } print "
".$langs->trans("Bill")." PDF'.$object->ref.'.pdf'.dol_print_size(dol_filesize($file)). ''.dol_print_date(dol_filemtime($file),'dayhour').'
Facture detaillee'.$object->ref.'-detail.pdf'.dol_print_size(dol_filesize($filedetail)).''.dol_print_date(dol_filemtime($filedetail),'dayhour').'
\n"; // Conversion du PDF en image png si fichier png non existant if (! file_exists($fileimage) && ! file_exists($fileimagebis)) { if (class_exists("Imagick")) { $ret = dol_convert_file($file); if ($ret < 0) $error++; } else { $langs->load("other"); print ''.$langs->trans("ErrorNoImagickReadimage").''; } } } print "
'.$langs->trans("AmountHT").''.price($object->total_ht).''.$langs->trans("Currency".$conf->monnaie).'
'.$langs->trans('AmountVAT').''.price($object->total_tva).''.$langs->trans('Currency'.$conf->monnaie).'
'.$langs->trans('AmountTTC').''.price($object->total_ttc).''.$langs->trans('Currency'.$conf->monnaie).'
'.$langs->trans('Status').''.($object->getLibStatut(4,$totalpaye)).'
'.$langs->trans("Project").''; if ($object->fk_project > 0) { $project = New Project($db); $project->fetch($object->fk_project); print ''.$project->title.''; } else { print ' '; } print '
'; dol_fiche_end(); } else { // Facture non trouvee print $langs->trans("ErrorBillNotFound",$_GET["facid"]); } } // Si fichier png PDF d'1 page trouve if (file_exists($fileimage)) { print ''; } // Si fichier png PDF de plus d'1 page trouve elseif (file_exists($fileimagebis)) { $multiple = preg_replace('/\.png/','',$relativepath) . "-"; for ($i = 0; $i < 20; $i++) { $preview = $multiple.$i.'.png'; if (file_exists($dir_output.$preview)) { print '

'; } } } $db->close(); llxFooter('$Date: 2011/07/31 22:23:13 $ - $Revision: 1.73 $'); ?>