Fix: credit note support on pdf invoice

This commit is contained in:
Laurent Destailleur 2008-12-02 23:42:07 +00:00
parent 4250c4c982
commit 3ada34c736
4 changed files with 104 additions and 69 deletions

View File

@ -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 <EFBFBD> l'origine de la remise
var $ref_facture_source; // Ref facture avoir <EFBFBD> l'origine de la remise
/**
* \brief Constructeur de la classe
* \param DB handler accès base de données
* \param DB handler acc<EFBFBD>s base de donn<EFBFBD>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 <EFBFBD> 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<EFBFBD>, >0 si ok
*/
function fetch($rowid,$fk_facture_source=0)
{

View File

@ -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';

View File

@ -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);

View File

@ -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)
{