From 3ada34c736f781d4990a371522ff288f0db25408 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 2 Dec 2008 23:42:07 +0000 Subject: [PATCH] Fix: credit note support on pdf invoice --- htdocs/discount.class.php | 10 +-- htdocs/facture.class.php | 50 ++++++------- .../modules/facture/pdf_crabe.modules.php | 43 +++++++----- .../modules/facture/pdf_oursin.modules.php | 70 +++++++++++++------ 4 files changed, 104 insertions(+), 69 deletions(-) diff --git a/htdocs/discount.class.php b/htdocs/discount.class.php index 7255f4dff82..a1dc978bc86 100644 --- a/htdocs/discount.class.php +++ b/htdocs/discount.class.php @@ -44,12 +44,12 @@ class DiscountAbsolute var $datec; // Date creation var $fk_facture_line; // Id invoice line when a discount linked to invoice line var $fk_facture; // Id invoice when a discoutn linked to invoice - var $fk_facture_source; // Id facture avoir à l'origine de la remise - var $ref_facture_source; // Ref facture avoir à l'origine de la remise + var $fk_facture_source; // Id facture avoir � l'origine de la remise + var $ref_facture_source; // Ref facture avoir � l'origine de la remise /** * \brief Constructeur de la classe - * \param DB handler accès base de données + * \param DB handler acc�s base de donn�es */ function DiscountAbsolute($DB) { @@ -59,9 +59,9 @@ class DiscountAbsolute /** * \brief Charge objet remise depuis la base - * \param rowid id du projet à charger + * \param rowid id du projet � charger * \param fk_facture_source fk_facture_source - * \return int <0 si ko, =0 si non trouvé, >0 si ok + * \return int <0 si ko, =0 si non trouv�, >0 si ok */ function fetch($rowid,$fk_facture_source=0) { diff --git a/htdocs/facture.class.php b/htdocs/facture.class.php index 1e38fbbc92f..94e84413384 100644 --- a/htdocs/facture.class.php +++ b/htdocs/facture.class.php @@ -393,9 +393,9 @@ class Facture extends CommonObject function createFromClone($fromid,$invertdetail=0) { global $user,$langs; - + $error=0; - + $object=new Facture($this->db); $this->db->begin(); @@ -415,24 +415,24 @@ class Facture extends CommonObject $object->close_code = ''; $object->close_note = ''; $object->products = $object->lignes; // Tant que products encore utilisé - + // Create clone $result=$object->create($user); // Other options - if ($result < 0) + if ($result < 0) { $this->error=$object->error; $error++; } - + if (! $error) { - - - + + + } - + // End if (! $error) { @@ -682,7 +682,7 @@ class Facture extends CommonObject { global $conf, $langs; $error=0; - + // Clean parameters if (isset($this->facnumber)) $this->facnumber=trim($this->ref); @@ -711,7 +711,7 @@ class Facture extends CommonObject if (isset($this->note_public)) $this->note_public=trim($this->note_public); if (isset($this->modelpdf)) $this->modelpdf=trim($this->modelpdf); if (isset($this->import_key)) $this->import_key=trim($this->import_key); - + // Check parameters // Put here code to add control on parameters values @@ -1913,15 +1913,15 @@ class Facture extends CommonObject { $obj = $this->db->fetch_object($resql); if ($obj) - { - // Si il y en a - return $obj->rowid; - } - else - { - // Si aucune facture ne remplace - return 0; - } + { + // Si il y en a + return $obj->rowid; + } + else + { + // Si aucune facture ne remplace + return 0; + } } else { @@ -2167,7 +2167,7 @@ class Facture extends CommonObject if ($this->statut >= 0 && $this->paye == 0) { // Define cond_reglement_id and datelim - if (strval($date) != '') + if (strval($date) != '') { $datelim=$date; $cond_reglement_id=0; @@ -2343,8 +2343,8 @@ class Facture extends CommonObject while ($obj=$this->db->fetch_object($resql)) { $return[$obj->rowid]=array( 'id' => $obj->rowid, - 'ref' => $obj->facnumber, - 'status' => $obj->fk_statut); + 'ref' => $obj->facnumber, + 'status' => $obj->fk_statut); } //print_r($return); return $return; @@ -2361,7 +2361,7 @@ class Facture extends CommonObject /** * \brief Renvoi liste des factures qualifiables pour correction par avoir * Les factures qui respectent les regles suivantes sont retournees: - * (validée + paiement en cours) ou classée (payée completement ou payée partiellement) + pas deja remplacée + pas deja avoir + * (validée + paiement en cours) ou classée (payée completement ou payée partiellement) + pas deja remplacée + pas deja avoi * \param socid Id societe * \return array Tableau des factures ($id => $ref) */ @@ -2423,7 +2423,7 @@ class Facture extends CommonObject $soc = new Societe($this->db); $soc->id = $this->socid; $soc->load_ban(); - + if ($this->statut > 0 && $this->paye == 0 && $this->mode_reglement_id == 3) { $sql = 'SELECT count(*) FROM '.MAIN_DB_PREFIX.'prelevement_facture_demande'; diff --git a/htdocs/includes/modules/facture/pdf_crabe.modules.php b/htdocs/includes/modules/facture/pdf_crabe.modules.php index bcfd7fc0479..185ecc93e7c 100644 --- a/htdocs/includes/modules/facture/pdf_crabe.modules.php +++ b/htdocs/includes/modules/facture/pdf_crabe.modules.php @@ -469,7 +469,9 @@ class pdf_crabe extends ModelePDFFactures $y=0; - // Loop on each credit note included + $pdf->SetFont('Arial','',6); + + // Loop on each credit note included $sql = "SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,"; $sql.= " re.description, re.fk_facture_source, re.fk_facture_source"; $sql.= " FROM ".MAIN_DB_PREFIX ."societe_remise_except as re"; @@ -516,7 +518,6 @@ class pdf_crabe extends ModelePDFFactures $resql=$this->db->query($sql); if ($resql) { - $pdf->SetFont('Arial','',6); $num = $this->db->num_rows($resql); $i=0; while ($i < $num) { @@ -729,16 +730,15 @@ class pdf_crabe extends ModelePDFFactures // Tableau total $lltot = 200; $col1x = 120; $col2x = 182; $largcol2 = $lltot - $col2x; + $index = 0; + // Total HT $pdf->SetFillColor(255,255,255); $pdf->SetXY ($col1x, $tab2_top + 0); $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT"), 0, 'L', 1); - $pdf->SetXY ($col2x, $tab2_top + 0); $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_ht + $object->remise), 0, 'R', 1); - $index = 0; - // Affichage des totaux de TVA par taux (conformement a la reglementation) $pdf->SetFillColor(248,248,248); @@ -750,7 +750,6 @@ class pdf_crabe extends ModelePDFFactures $index++; $pdf->SetXY ($col1x, $tab2_top + $tab2_hl * $index); - $tvacompl=''; if (eregi('\*',$tvakey)) { @@ -760,7 +759,6 @@ class pdf_crabe extends ModelePDFFactures $totalvat =$outputlangs->transnoentities("TotalVAT").' '; $totalvat.=vatrate($tvakey,1).$tvacompl; $pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1); - $pdf->SetXY ($col2x, $tab2_top + $tab2_hl * $index); $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval), 0, 'R', 1); } @@ -770,13 +768,13 @@ class pdf_crabe extends ModelePDFFactures $index++; $pdf->SetXY ($col1x, $tab2_top + $tab2_hl * $index); $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalVAT"), 0, 'L', 1); - $pdf->SetXY ($col2x, $tab2_top + $tab2_hl * $index); $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_tva), 0, 'R', 1); } $useborder=0; + // Total TTC $index++; $pdf->SetXY ($col1x, $tab2_top + $tab2_hl * $index); $pdf->SetTextColor(0,0,60); @@ -784,24 +782,37 @@ class pdf_crabe extends ModelePDFFactures $text=$outputlangs->transnoentities("TotalTTC"); if ($object->type == 2) $text=$outputlangs->transnoentities("TotalTTCToYourCredit"); $pdf->MultiCell($col2x-$col1x, $tab2_hl, $text, $useborder, 'L', 1); - $pdf->SetXY ($col2x, $tab2_top + $tab2_hl * $index); $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_ttc), $useborder, 'R', 1); $pdf->SetTextColor(0,0,0); - if ($deja_regle > 0) + $creditnoteamount=$object->getSommeCreditNote(); + $resteapayer = $object->total_ttc - $deja_regle - $creditnoteamount; + if ($object->paye) $resteapayer=0; + + if ($deja_regle > 0 || $creditnoteamount > 0) { + // Already payed $index++; - $pdf->SetXY ($col1x, $tab2_top + $tab2_hl * $index); $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("AlreadyPayed"), 0, 'L', 0); - $pdf->SetXY ($col2x, $tab2_top + $tab2_hl * $index); $pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle), 0, 'R', 0); - $resteapayer = $object->total_ttc - $deja_regle; + // Credit note + if ($creditnoteamount) + { + $index++; + $pdf->SetXY ($col1x, $tab2_top + $tab2_hl * $index); + $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("CreditNotes"), 0, 'L', 0); + $pdf->SetXY ($col2x, $tab2_top + $tab2_hl * $index); + $pdf->MultiCell($largcol2, $tab2_hl, price($creditnoteamount), 0, 'R', 0); + } + + $resteapayer = $object->total_ttc - $deja_regle - $creditnoteamount; if ($object->paye) $resteapayer=0; + // Escompte if ($object->close_code == 'discount_vat') { $index++; @@ -809,19 +820,17 @@ class pdf_crabe extends ModelePDFFactures $pdf->SetXY ($col1x, $tab2_top + $tab2_hl * $index); $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("EscompteOffered"), $useborder, 'L', 1); - $pdf->SetXY ($col2x, $tab2_top + $tab2_hl * $index); $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_ttc - $deja_regle), $useborder, 'R', 1); $resteapayer=0; } - $index++; - $pdf->SetTextColor(0,0,60); + $index++; + $pdf->SetTextColor(0,0,60); $pdf->SetFillColor(224,224,224); $pdf->SetXY ($col1x, $tab2_top + $tab2_hl * $index); $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay"), $useborder, 'L', 1); - $pdf->SetXY ($col2x, $tab2_top + $tab2_hl * $index); $pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer), $useborder, 'R', 1); diff --git a/htdocs/includes/modules/facture/pdf_oursin.modules.php b/htdocs/includes/modules/facture/pdf_oursin.modules.php index 2cf09dc1b87..e748d4657d5 100644 --- a/htdocs/includes/modules/facture/pdf_oursin.modules.php +++ b/htdocs/includes/modules/facture/pdf_oursin.modules.php @@ -311,7 +311,7 @@ class pdf_oursin extends ModelePDFFactures $pdf->MultiCell(80, 5, $titre, 0, 'L'); $pdf->SetFont('Arial','',10); $pdf->SetXY($this->marges['g']+44, 217); - $lib_condition_paiement=$outputlangs->transnoentities("PaymentCondition".$fac->cond_reglement_code)!=('PaymentCondition'.$fac->cond_reglement_code)?$outputlangs->transnoentities("PaymentCondition".$fac->cond_reglement_code):$fac->cond_reglement; + $lib_condition_paiement=$outputlangs->transnoentities("PaymentCondition".$fac->cond_reglement_code)!=('PaymentCondition'.$fac->cond_reglement_code)?$outputlangs->transnoentities("PaymentCondition".$fac->cond_reglement_code):$outputlangs->convToOutputCharset($fac->cond_reglement); $pdf->MultiCell(80, 5, $lib_condition_paiement,0,'L'); } @@ -358,7 +358,7 @@ class pdf_oursin extends ModelePDFFactures function _tableau_versements(&$pdf, $fac, $posy, $outputlangs) { $tab3_posx = $this->marges['g']+110; - $tab3_top = $this->marges['h']+235; + $tab3_top = $posy + 8; $tab3_width = 80; $tab3_height = 4; @@ -379,6 +379,8 @@ class pdf_oursin extends ModelePDFFactures $y=0; + $pdf->SetFont('Arial','',6); + // Loop on each credit note included $sql = "SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,"; $sql.= " re.description, re.fk_facture_source, re.fk_facture_source"; @@ -426,7 +428,6 @@ class pdf_oursin extends ModelePDFFactures $resql=$this->db->query($sql); if ($resql) { - $pdf->SetFont('Arial','',6); $num = $this->db->num_rows($resql); $i=0; while ($i < $num) @@ -508,48 +509,73 @@ class pdf_oursin extends ModelePDFFactures $pdf->MultiCell(100, $tab2_hl, $outputlangs->transnoentities("VATIsNotUsedForInvoice"), 0, 'L', 0); } - // Tableau total + $index = 0; + + // Total TTC $col1x=$this->marges['g']+110; $col2x=$this->marges['g']+164; $pdf->SetXY ($col1x, $tab2_top + 0); $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT"), 0, 'L', 0); - $pdf->SetXY ($col2x, $tab2_top + 0); $pdf->MultiCell(26, $tab2_hl, price($fac->total_ht + $fac->remise), 0, 'R', 0); - $index = 1; - + // Total VAT + $index++; $pdf->SetXY ($col1x, $tab2_top + $tab2_hl * $index); $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalVAT"), 0, 'L', 0); - $pdf->SetXY ($col2x, $tab2_top + $tab2_hl * $index); $pdf->MultiCell(26, $tab2_hl, price($fac->total_tva), 0, 'R', 0); - $pdf->SetXY ($col1x, $tab2_top + $tab2_hl * ($index+1)); + // Total TTC + $index++; + $pdf->SetXY ($col1x, $tab2_top + $tab2_hl * $index); $pdf->SetTextColor(22,137,210); $pdf->SetFont('Arial','B', 11); $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC"), 0, 'L', 0); - - $pdf->SetXY ($col2x, $tab2_top + $tab2_hl * ($index+1)); + $pdf->SetXY ($col2x, $tab2_top + $tab2_hl * $index); $pdf->MultiCell(26, $tab2_hl, price($fac->total_ttc), 0, 'R', 0); $pdf->SetTextColor(0,0,0); - if ($deja_regle > 0) - { - $pdf->SetXY ($col1x, $tab2_top + $tab2_hl * ($index+2)); + $creditnoteamount=$fac->getSommeCreditNote(); + $resteapayer = $fac->total_ttc - $deja_regle - $creditnoteamount; + if ($object->paye) $resteapayer=0; + + if ($deja_regle > 0 || $creditnoteamount > 0) + { + $pdf->SetFont('Arial','', 10); + + // Already payed + $index++; + $pdf->SetXY ($col1x, $tab2_top + $tab2_hl * $index); $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("AlreadyPayed"), 0, 'L', 0); - - $pdf->SetXY ($col2x, $tab2_top + $tab2_hl * ($index+2)); + $pdf->SetXY ($col2x, $tab2_top + $tab2_hl * $index); $pdf->MultiCell(26, $tab2_hl, price($deja_regle), 0, 'R', 0); - $pdf->SetXY ($col1x, $tab2_top + $tab2_hl * ($index+3)); - $pdf->SetTextColor(22,137,210); - $pdf->SetFont('Arial','B', 11); + // Credit note + if ($creditnoteamount) + { + $index++; + $pdf->SetXY ($col1x, $tab2_top + $tab2_hl * $index); + $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("CreditNotes"), 0, 'L', 0); + $pdf->SetXY ($col2x, $tab2_top + $tab2_hl * $index); + $pdf->MultiCell($largcol2, $tab2_hl, price($creditnoteamount), 0, 'R', 0); + } + + $resteapayer = $object->total_ttc - $deja_regle - $creditnoteamount; + if ($object->paye) $resteapayer=0; + + $index++; + $pdf->SetTextColor(0,0,60); + $pdf->SetFont('Arial','B', 11); + $pdf->SetXY ($col1x, $tab2_top + $tab2_hl * $index); $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay"), 0, 'L', 0); - - $pdf->SetXY ($col2x, $tab2_top + $tab2_hl * ($index+3)); + $pdf->SetFillColor(224,224,224); + $pdf->SetXY ($col2x, $tab2_top + $tab2_hl * $index); $pdf->MultiCell(26, $tab2_hl, price($fac->total_ttc - $deja_regle), 0, 'R', 0); $pdf->SetTextColor(0,0,0); } + + $index++; + return ($tab2_top + ($tab2_hl * $index)); } /* @@ -577,7 +603,7 @@ class pdf_oursin extends ModelePDFFactures for ($i = 0 ; $i < $nblignes ; $i++) if ($fac->lignes[$i]->remise_percent) { - $rem=1; + $rem=1; } if ($rem==1) {