diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php
index 88a75024348..e437692ab83 100644
--- a/htdocs/compta/facture.php
+++ b/htdocs/compta/facture.php
@@ -1597,1503 +1597,1407 @@ if ($_GET['action'] == 'create')
}
else
{
- /* *************************************************************************** */
- /* */
- /* Fiche en mode visu */
- /* */
- /* *************************************************************************** */
- $id = $_GET['facid'];
- if ($id > 0)
- {
- if ($mesg) print $mesg.'
';
-
- $fac = New Facture($db);
- if ( $fac->fetch($_GET['facid'], $user->societe_id) > 0)
+ /* *************************************************************************** */
+ /* */
+ /* Fiche en mode visu */
+ /* */
+ /* *************************************************************************** */
+ $id = $_GET['facid'];
+ if ($id > 0)
{
- $soc = new Societe($db, $fac->socid);
- $soc->fetch($fac->socid);
- $absolute_discount=$soc->getCurrentDiscount();
-
- $totalpaye = $fac->getSommePaiement();
- $resteapayer = $fac->total_ttc - $totalpaye;
- if ($fac->paye) $resteapayer=0;
-
- $author = new User($db);
- if ($fac->user_author)
- {
- $author->id = $fac->user_author;
- $author->fetch();
- }
-
- $facidnext=$fac->getIdReplacingInvoice();
-
-
- $head = facture_prepare_head($fac);
-
- dolibarr_fiche_head($head, 'compta', $langs->trans('InvoiceCustomer'));
-
- /*
- * Confirmation de la suppression de la facture
- */
- if ($_GET['action'] == 'delete')
- {
- $text=$langs->trans('ConfirmDeleteBill');
- $html->form_confirm($_SERVER['PHP_SELF'].'?facid='.$fac->id,$langs->trans('DeleteBill'),$text,'confirm_delete');
- print '
';
- }
-
- /*
- * Confirmation de la validation
- */
- if ($_GET['action'] == 'valid')
- {
- // on vérifie si la facture est en numérotation provisoire
- $facref = substr($fac->ref, 1, 4);
- if ($facref == 'PROV')
+ if ($mesg) print $mesg.'
';
+
+ $fac = New Facture($db);
+ if ( $fac->fetch($_GET['facid'], $user->societe_id) > 0)
{
- $numfa = $fac->getNextNumRef($soc);
- }
- else
- {
- $numfa = $fac->ref;
- }
-
- $text=$langs->trans('ConfirmValidateBill',$numfa);
- if ($conf->notification->enabled)
- {
- require_once(DOL_DOCUMENT_ROOT ."/notify.class.php");
- $notify=new Notify($db);
- $text.='
';
- $text.=$notify->confirmMessage(2,$fac->socid);
- }
-
- $html->form_confirm($_SERVER["PHP_SELF"].'?facid='.$fac->id,$langs->trans('ValidateBill'),$text,'confirm_valid');
- print '
';
- }
-
- /*
- * Confirmation du classement payé
- */
- if ($_GET['action'] == 'payed' && $resteapayer <= 0)
- {
- $html->form_confirm($_SERVER["PHP_SELF"].'?facid='.$fac->id,$langs->trans('ClassifyPayed'),$langs->trans('ConfirmClassifyPayedBill',$fac->ref),'confirm_payed');
- print '
';
- }
- if ($_GET['action'] == 'payed' && $resteapayer > 0)
- {
- // Code
- $close[0]['code']='discount_vat';
- $close[1]['code']='badcustomer';
- $close[2]['code']='abandon';
- // Help
- $close[0]['label']=$langs->trans("HelpEscompte").'
'.$langs->trans("ConfirmClassifyPayedPartiallyVat");
- $close[1]['label']=$langs->trans("ConfirmClassifyPayedPartiallyBadCustomer");
- $close[2]['label']=$langs->trans("ConfirmClassifyPayedPartiallyOther");
- // Texte
- $close[0]['reason']=$html->textwithhelp($langs->transnoentities("ConfirmClassifyPayedPartiallyReasonDiscountVat",$resteapayer,$langs->trans("Currency".$conf->monnaie)),$close[0]['label'],1);
- $close[1]['reason']=$html->textwithhelp($langs->transnoentities("ConfirmClassifyPayedPartiallyReasonBadCustomer",$resteapayer,$langs->trans("Currency".$conf->monnaie)),$close[1]['label'],1);
- $close[2]['reason']=$html->textwithhelp($langs->transnoentities("ConfirmClassifyPayedPartiallyReasonOther",$resteapayer,$langs->trans("Currency".$conf->monnaie)),$close[2]['label'],1);
- // arrayreasons
- $arrayreasons[$close[0]['code']]=$close[0]['reason'];
- $arrayreasons[$close[1]['code']]=$close[1]['reason'];
- $arrayreasons[$close[2]['code']]=$close[2]['reason'];
-
- // Crée un tableau formulaire
- $formquestion=array(
- 'text' => $langs->trans("ConfirmClassifyPayedPartiallyQuestion"),
- array('type' => 'radio', 'name' => 'close_code', 'label' => $langs->trans("Reason"), 'values' => $arrayreasons),
- array('type' => 'text', 'name' => 'close_note', 'label' => $langs->trans("Comment"), 'value' => '', 'size' => '100')
- );
- // Paiement incomplet. On demande si motif = escompte ou autre
- $html->form_confirm($_SERVER["PHP_SELF"].'?facid='.$fac->id,$langs->trans('ClassifyPayed'),$langs->trans('ConfirmClassifyPayedPartially',$fac->ref),'confirm_payed_partially',$formquestion);
- print '
';
- }
-
- /*
- * Confirmation du classement abandonne
- */
- if ($_GET['action'] == 'canceled')
- {
- // S'il y a une facture de remplacement pas encore validée (etat brouillon),
- // on ne permet pas de classer abandonner la facture.
- if ($facidnext)
- {
- $facturereplacement=new Facture($db);
- $facturereplacement->fetch($facidnext);
- $statusreplacement=$facturereplacement->statut;
- }
- if ($facidnext && $statusreplacement == 0)
- {
- print '
| '.$langs->trans('Ref').' | '.$fac->ref.' | ||||||||||||||||||||||||||||||||
';
- print '
| '; - if ($user->rights->facture->creer && $_GET['action'] == 'RefCustomerOrder') - { - print ''; - } - else - { - print $fac->ref_client; - } - print ' | '; - print '||||||||||||||||||||||||||||||||
| '.$langs->trans('Company').' | '; - print ''.$soc->getNomUrl(1,'compta').' | '; - print '||||||||||||||||||||||||||||||||
| '.$langs->trans('Type').' | '; - print $fac->getLibType(); - if ($fac->type == 1) - { - $facreplaced=new Facture($db); - $facreplaced->fetch($fac->fk_facture_source); - print ' ('.$langs->transnoentities("ReplaceInvoice",$facreplaced->getNomUrl(1)).')'; - } - if ($fac->type == 2) - { - $facreplaced=new Facture($db); - $facreplaced->fetch($fac->fk_facture_source); - print ' ('.$langs->transnoentities("CorrectInvoice",$facreplaced->getNomUrl(1)).')'; - } - $facidavoir=$fac->getIdAvoirInvoice(); - 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 ($facidnext > 0) - { - $facthatreplace=new Facture($db); - $facthatreplace->fetch($facidnext); - print ' ('.$langs->transnoentities("ReplacedByInvoice",$facthatreplace->getNomUrl(1)).')'; - } - print ' | ||||||||||||||||||||||||||||||||
| '.$langs->trans('Discounts').' | ';
- if ($soc->remise_client) print $langs->trans("CompanyHasRelativeDiscount",$soc->remise_client);
- else print $langs->trans("CompanyHasNoRelativeDiscount");
- print '. ';
- if ($absolute_discount)
- {
- if ($fac->statut > 0 || $fac->type == 2)
- {
- print $langs->trans("CompanyHasAbsoluteDiscount",$absolute_discount,$langs->trans("Currency".$conf->monnaie));
- }
- else
- {
- print ' '; - print $html->form_remise_dispo($_SERVER["PHP_SELF"].'?facid='.$fac->id,0,'remise_id',$soc->id,$absolute_discount); - } - } - else print $langs->trans("CompanyHasNoAbsoluteDiscount").'.'; - print ' | ||||||||||||||||||||||||||||||||
| '.$langs->trans('Date').' | '; - print ''.dolibarr_print_date($fac->date,'%A %d %B %Y').' | '; - - $nbrows=8; - if ($conf->global->FAC_USE_CUSTOMER_ORDER_REF) $nbrows++; - if ($conf->projet->enabled) $nbrows++; - - print '';
-
- /*
- * Liste des paiements
- */
- $sql = 'SELECT '.$db->pdate('datep').' as dp, pf.amount,';
- $sql.= ' c.libelle as paiement_type, p.num_paiement, p.rowid';
- $sql.= ' FROM '.MAIN_DB_PREFIX.'paiement as p, '.MAIN_DB_PREFIX.'c_paiement as c, '.MAIN_DB_PREFIX.'paiement_facture as pf';
- $sql.= ' WHERE pf.fk_facture = '.$fac->id.' AND p.fk_paiement = c.id AND pf.fk_paiement = p.rowid';
- $sql.= ' ORDER BY dp DESC';
-
- $result = $db->query($sql);
- if ($result)
- {
- $num = $db->num_rows($result);
- $i = 0;
- print '
| |||||||||||||||||||||||||||||||
| '.$langs->trans('DateMaxPayment').' | '; - print ''; - if ($fac->type != 2) - { - print dolibarr_print_date($fac->date_lim_reglement,'%A %d %B %Y'); - if ($fac->date_lim_reglement < (time() - $conf->facture->client->warning_delay) && ! $fac->paye && $fac->statut == 1 && ! $fac->am) print img_warning($langs->trans('Late')); - } - else - { - print ' '; - } - print ' | ||||||||||||||||||||||||||||||||
';
- print '
| '; - if ($fac->type != 2) - { - if ($_GET['action'] == 'editconditions') - { - $html->form_conditions_reglement($_SERVER['PHP_SELF'].'?facid='.$fac->id,$fac->cond_reglement_id,'cond_reglement_id'); - } - else - { - $html->form_conditions_reglement($_SERVER['PHP_SELF'].'?facid='.$fac->id,$fac->cond_reglement_id,'none'); - } - } - else - { - print ' '; - } - print ' | ||||||||||||||||||||||||||||||||
';
- print '
| '; - if ($_GET['action'] == 'editmode') - { - $html->form_modes_reglement($_SERVER['PHP_SELF'].'?facid='.$fac->id,$fac->mode_reglement_id,'mode_reglement_id'); - } - else - { - $html->form_modes_reglement($_SERVER['PHP_SELF'].'?facid='.$fac->id,$fac->mode_reglement_id,'none'); - } - print ' | ||||||||||||||||||||||||||||||||
| '.$langs->trans('AmountHT').' | '; - print ''.price($fac->total_ht).' | '; - print ''.$langs->trans('Currency'.$conf->monnaie).' | |||||||||||||||||||||||||||||||
| '.$langs->trans('AmountVAT').' | '.price($fac->total_tva).' | '; - print ''.$langs->trans('Currency'.$conf->monnaie).' | |||||||||||||||||||||||||||||||
| '.$langs->trans('AmountTTC').' | '.price($fac->total_ttc).' | '; - print ''.$langs->trans('Currency'.$conf->monnaie).' | |||||||||||||||||||||||||||||||
| '.$langs->trans('Status').' | '; - print ''.($fac->getLibStatut(4,$totalpaye)).' | ||||||||||||||||||||||||||||||||
';
-
- print '
| '; - if ($_GET['action'] == 'classer') - { - $html->form_project($_SERVER['PHP_SELF'].'?facid='.$fac->id,$fac->socid,$fac->projetid,'projetid'); - } - else - { - $html->form_project($_SERVER['PHP_SELF'].'?facid='.$fac->id,$fac->socid,$fac->projetid,'none'); - } - print ' | '; - print '||||||||||||||||||||||||||||||||
| '.$langs->trans('Description').' | '; - print ''.$langs->trans('VAT').' | '; - print ''.$langs->trans('PriceUHT').' | '; - print ''.$langs->trans('Qty').' | '; - print ''.$langs->trans('ReductionShort').' | '; - print ''.$langs->trans('AmountHT').' | '; - print ''; - print ' | '; - print ' | '; - print " | ||||||
| ';
- print ''; // ancre pour retourner sur la ligne
- print '';
- if ($objp->fk_product_type) print img_object($langs->trans('ShowService'),'service');
- else print img_object($langs->trans('ShowProduct'),'product');
- print ' '.$objp->ref.'';
- print ' - '.nl2br(stripslashes($objp->product));
- print_date_range($objp->date_start,$objp->date_end);
- print ($objp->description && $objp->description!=$objp->product)?' '.stripslashes(nl2br($objp->description)):''; - - // \todo Ne faut-il pas rendre $conf->global->PRODUIT_CHANGE_PROD_DESC toujours a on - if ($conf->global->PRODUIT_DESC_IN_FORM && !$conf->global->PRODUIT_CHANGE_PROD_DESC) - { - print ' '.nl2br($objp->product_desc); - } - - print ' | ';
- }
- else
- {
- print ''; - print ''; // ancre pour retourner sur la ligne - if (($objp->info_bits & 2) == 2) - { - print ''; - print img_object($langs->trans("ShowReduc"),'reduc').' '.$langs->trans("Discount"); - print ''; - if ($objp->description) print ' - '.nl2br($objp->description); - } - else - { - print nl2br($objp->description); - print_date_range($objp->date_start,$objp->date_end); - } - print " | \n"; - } - print ''.$objp->tva_taux.'% | '; - print ''.price($objp->subprice)." | \n"; - print ''; - if (($objp->info_bits & 2) != 2) - { - print $objp->qty; - } - else print ' '; - print ' | '; - if ($objp->remise_percent > 0) - { - print ''.$objp->remise_percent."% | \n"; - } - else - { - print ''; - } - print ' | '.price($objp->subprice*$objp->qty*(100-$objp->remise_percent)/100)." | \n"; - - // Icone d'edition et suppression - if ($fac->statut == 0 && $user->rights->facture->creer) - { - print 'id.'&action=editline&rowid='.$objp->rowid.'#'.$objp->rowid.'">'; - print img_edit(); - print ' | '; - if ($conf->global->PRODUIT_CONFIRM_DELETE_LINE) - { - print 'id.'&action=delete_product_line&rowid='.$objp->rowid.'">'; - } - else - { - print ' | id.'&action=deleteline&rowid='.$objp->rowid.'">'; - } - print img_delete(); - print ' | '; - print ''; - if ($i > 0) - { - print 'id.'&action=up&rowid='.$objp->rowid.'">'; - print img_up(); - print ''; - } - if ($i < $num_lignes-1) - { - print 'id.'&action=down&rowid='.$objp->rowid.'">'; - print img_down(); - print ''; - } - print ' | '; - } - else - { - print ''; - } - print ' | ||
| '; - print ''; // ancre - print $langs->trans('Description').' | '; - print ''.$langs->trans('VAT').' | '; - print ''.$langs->trans('PriceUHT').' | '; - print ''.$langs->trans('Qty').' | '; - print ''.$langs->trans('ReductionShort').' | '; - print ''; - print ' | '; - print ' | '; - print ' | '; - print " | ||||||
| ';
- print ''; // ancre
-
- /*
- * Documents générés
- */
- $filename=sanitize_string($fac->ref);
- $filedir=$conf->facture->dir_output . '/' . sanitize_string($fac->ref);
- $urlsource=$_SERVER['PHP_SELF'].'?facid='.$fac->id;
- $genallowed=($fac->statut >= 1 && $user->rights->facture->creer);
- $delallowed=$user->rights->facture->supprimer;
-
- $var=true;
-
- print ' '; - $somethingshown=$html->show_documents('facture',$filename,$filedir,$urlsource,$genallowed,$delallowed,$fac->modelpdf); - - /* - * Propales rattachées - */ - $sql = 'SELECT '.$db->pdate('p.datep').' as dp, p.price, p.ref, p.rowid as propalid'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'propal as p'; - if (!$conf->commande->enabled) - { - $sql .= ", ".MAIN_DB_PREFIX."fa_pr as fp"; - $sql .= " WHERE fp.fk_propal = p.rowid AND fp.fk_facture = ".$fac->id; - } - else - { - $sql .= ", ".MAIN_DB_PREFIX."co_pr as cp, ".MAIN_DB_PREFIX."co_fa as cf"; - $sql .= " WHERE cf.fk_facture = ".$fac->id." AND cf.fk_commande = cp.fk_commande AND cp.fk_propale = p.rowid"; - } - - $resql = $db->query($sql); - if ($resql) - { - $num = $db->num_rows($resql); - if ($num) - { - $i = 0; $total = 0; - if ($somethingshown) print ' '; - $somethingshown=1; - print_titre($langs->trans('RelatedCommercialProposals')); - print '
'; - $somethingshown=1; - print_titre($langs->trans('RelatedOrders')); - print '
'; + + + /* + * Lignes de factures + */ + $sql = 'SELECT l.fk_product, l.description, l.price, l.qty, l.rowid, l.tva_taux,'; + $sql.= ' l.remise_percent, l.subprice, l.info_bits,'; + $sql.= ' '.$db->pdate('l.date_start').' as date_start,'; + $sql.= ' '.$db->pdate('l.date_end').' as date_end,'; + $sql.= ' p.ref, p.fk_product_type, p.label as product,'; + $sql.= ' p.description as product_desc'; + $sql.= ' FROM '.MAIN_DB_PREFIX.'facturedet as l'; + $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product p ON l.fk_product=p.rowid'; + $sql.= ' WHERE l.fk_facture = '.$fac->id; + $sql.= ' ORDER BY l.rang ASC, l.rowid'; + + $resql = $db->query($sql); + if ($resql) + { + $num_lignes = $db->num_rows($resql); + $i = 0; $total = 0; + + print '
';
+
+ // Editer une facture déjà validée, sans paiement effectué et pas exporté en compta
+ if ($fac->statut == 1)
+ {
+ // On vérifie si les lignes de factures ont été exportées en compta et/ou ventilées
+ $ventilExportCompta = $fac->getVentilExportCompta();
+
+ if ($conf->global->FACTURE_ENABLE_EDITDELETE && $user->rights->facture->modifier
+ && ($resteapayer == $fac->total_ttc && $fac->paye == 0 && $ventilExportCompta == 0))
+ {
+ print ''.$langs->trans('Edit').'';
+ }
+ }
+
+ // Récurrente
+ if (! $conf->global->FACTURE_DISABLE_RECUR)
+ {
+ print ''.$langs->trans("ChangeIntoRepeatableInvoice").'';
+ }
+
+ // Valider
+ if ($fac->statut == 0 && $num_lignes > 0)
+ {
+ if ($user->rights->facture->valider)
+ {
+ print 'id.'&action=valid">'.$langs->trans('Validate').'';
+ }
+ }
+ else
+ {
+ // Générer
+ if ($fac->statut >= 1 && $user->rights->facture->creer)
+ {
+ if ($fac->paye == 0)
+ {
+ print 'id.'&action=builddoc">'.$langs->trans('BuildPDF').'';
+ }
+ else
+ {
+ print 'id.'&action=builddoc">'.$langs->trans('RebuildPDF').'';
+ }
+ }
+ }
+
+ // Envoyer
+ if ($fac->statut == 1 && $user->rights->facture->envoyer)
+ {
+ if ($facidnext)
+ {
+ print ''.$langs->trans('SendByMail').'';
+ }
+ else
+ {
+ print ''.$langs->trans('SendByMail').'';
+ }
+ }
+
+ // Envoyer une relance
+ if ($fac->statut == 1 && $resteapayer > 0 && $user->rights->facture->envoyer)
+ {
+ if ($facidnext)
+ {
+ print ''.$langs->trans('SendRemindByMail').'';
+ }
+ else
+ {
+ print ''.$langs->trans('SendRemindByMail').'';
+ }
+ }
+
+ // Emettre paiement
+ if ($fac->statut == 1 && $fac->paye == 0 && $user->rights->facture->paiement)
+ {
+ if ($facidnext)
+ {
+ print ''.$langs->trans('DoPaiement').'';
+ }
+ else
+ {
+ print ''.$langs->trans('DoPaiement').'';
+ }
+ }
+
+ // Classer 'payé'
+ if ($fac->statut == 1 && $fac->paye == 0 && $user->rights->facture->paiement
+ && $resteapayer <= 0)
+ {
+ print ''.$langs->trans('ClassifyPayed').'';
+ }
+
+ // Classer 'fermée' (possible si validée et pas encore classée payée)
+ if ($fac->statut == 1 && $fac->paye == 0 && $resteapayer > 0
+ && $user->rights->facture->paiement)
+ {
+ if ($totalpaye > 0)
+ {
+ print ''.$langs->trans('ClassifyPayedPartially').'';
+ }
+ else
+ {
+ print ''.$langs->trans('ClassifyCanceled').'';
+
+ // \todo
+ // Ajouter bouton "Annuler et Créer facture remplacement"
+ }
+ }
+
+ // Supprimer
+ if ($fac->is_erasable() && $user->rights->facture->supprimer && $_GET['action'] != 'delete')
+ {
+ print 'id.'&action=delete">'.$langs->trans('Delete').'';
+ }
+
+ print ' ';
+ }
+
+ print '
'; + print_titre($langs->trans('SendBillByMail')); + + $liste[0]=' '; + foreach ($soc->thirdparty_and_contact_email_array() as $key=>$value) + { + $liste[$key]=$value; + } + + // Créé l'objet formulaire mail + include_once(DOL_DOCUMENT_ROOT.'/html.formmail.class.php'); + $formmail = new FormMail($db); + $formmail->fromname = $user->fullname; + $formmail->frommail = $user->email; + $formmail->withfrom=1; + $formmail->withto=$liste; + $formmail->withcc=1; + $formmail->withtopic=$langs->trans('SendBillRef','__FACREF__'); + $formmail->withfile=1; + $formmail->withbody=1; + $formmail->withdeliveryreceipt=1; + $formmail->withcancel=1; + // Tableau des substitutions + $formmail->substit['__FACREF__']=$fac->ref; + // Tableau des paramètres complémentaires du post + $formmail->param['action']='send'; + $formmail->param['models']='facture_send'; + $formmail->param['facid']=$fac->id; + $formmail->param['returnurl']=DOL_URL_ROOT.'/compta/facture.php?facid='.$fac->id; + + $formmail->show_form(); + + print ' '; + } + + if ($_GET['action'] == 'prerelance') + { + $facref = sanitize_string($fac->ref); + $file = $conf->facture->dir_output . '/' . $facref . '/' . $facref . '.pdf'; + + // Construit PDF si non existant + if (! is_readable($file)) + { + if ($_REQUEST['lang_id']) + { + $outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs"); + $outputlangs->setDefaultLang($_REQUEST['lang_id']); + } + $result=facture_pdf_create($db, $fac->id, '', $_REQUEST['model'], $outputlangs); + if ($result <= 0) + { + dolibarr_print_error($db,$result); + exit; + } + } + + print ' '; + print_titre($langs->trans('SendReminderBillByMail')); + + $liste[0]=' '; + foreach ($soc->thirdparty_and_contact_email_array() as $key=>$value) + { + $liste[$key]=$value; + } + + // Créé l'objet formulaire mail + include_once(DOL_DOCUMENT_ROOT.'/html.formmail.class.php'); + $formmail = new FormMail($db); + $formmail->fromname = $user->fullname; + $formmail->frommail = $user->email; + $formmail->withfrom=1; + $formmail->withto=$liste; + $formmail->withcc=1; + $formmail->withtopic=$langs->trans('SendReminderBillRef','__FACREF__'); + $formmail->withfile=1; + $formmail->withbody=1; + $formmail->withdeliveryreceipt=1; + // Tableau des substitutions + $formmail->substit['__FACREF__']=$fac->ref; + // Tableau des paramètres complémentaires + $formmail->param['action']='relance'; + $formmail->param['models']='facture_relance'; + $formmail->param['facid']=$fac->id; + $formmail->param['returnurl']=DOL_URL_ROOT.'/compta/facture.php?facid='.$fac->id; + + $formmail->show_form(); + + print ' '; } - print ' '.$langs->trans('TotalHT').' | ';
- print ' | ';
- print ' | ';
- print ''.price($total).' | | ';
+ if (! $sortorder) $sortorder='DESC';
+ if (! $sortfield) $sortfield='f.datef';
- /*
- * Liste des actions propres à la facture
- */
- $sql = 'SELECT id, '.$db->pdate('a.datea').' as da, a.label, a.note, code';
- $sql .= ' FROM '.MAIN_DB_PREFIX.'actioncomm as a, '.MAIN_DB_PREFIX.'user as u ';
- $sql .= ' WHERE a.fk_user_author = u.rowid ';
- $sql .= ' AND a.fk_action in (9,10) ';
- $sql .= ' AND a.fk_soc = '.$fac->socid ;
- $sql .= ' AND a.fk_facture = '.$fac->id;
+ $facturestatic=new Facture($db);
- $resql = $db->query($sql);
- if ($resql)
- {
- $num = $db->num_rows($resql);
- if ($num)
+ if ($page == -1) $page = 0 ;
+
+ $sql = 'SELECT ';
+ $sql.= ' f.rowid as facid, f.facnumber, f.type, f.increment, f.total, f.total_ttc,';
+ $sql.= ' '.$db->pdate('f.datef').' as df, '.$db->pdate('f.date_lim_reglement').' as datelimite,';
+ $sql.= ' f.paye as paye, f.fk_statut,';
+ $sql.= ' s.nom, s.idp';
+ if (! $sall) $sql.= ' ,sum(pf.amount) as am';
+ $sql.= ' FROM '.MAIN_DB_PREFIX.'societe as s';
+ $sql.= ','.MAIN_DB_PREFIX.'facture as f';
+ if (! $sall) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiement_facture as pf ON f.rowid=pf.fk_facture ';
+ if ($sall) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'facturedet as fd ON f.rowid=fd.fk_facture ';
+ $sql.= ' WHERE f.fk_soc = s.idp';
+ if ($socid) $sql .= ' AND s.idp = '.$socid;
+ if ($month > 0) $sql .= ' AND date_format(f.datef, \'%m\') = '.$month;
+ if ($_GET['filtre'])
{
- print ' '; - print_titre($langs->trans('ActionsOnBill')); - - $i = 0; $total = 0; - print '
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||