Changes to support deposit invoices

This commit is contained in:
Laurent Destailleur 2009-03-02 21:21:49 +00:00
parent 5aa4ba6a42
commit 36faecca0d
6 changed files with 229 additions and 151 deletions

View File

@ -1916,13 +1916,15 @@ else
$soc->fetch($fac->socid); $soc->fetch($fac->socid);
$totalpaye = $fac->getSommePaiement(); $totalpaye = $fac->getSommePaiement();
$totalavoir = $fac->getSommeCreditNote(); $totalcreditnotes = $fac->getSumCreditNotesUsed();
$totaldeposits = $fac->getSumDepositsUsed();
//print "totalpaye=".$totalpaye." totalcreditnotes=".$totalcreditnotes." totaldeposts=".$totaldeposits;
// We cal also use bcadd to avoid pb with floating points // We cal also use bcadd to avoid pb with floating points
// For example print 239.2 - 229.3 - 9.9; does not return 0. // For example print 239.2 - 229.3 - 9.9; does not return 0.
//$resteapayer=bcadd($fac->total_ttc,$totalpaye,$conf->global->MAIN_MAX_DECIMALS_TOT); //$resteapayer=bcadd($fac->total_ttc,$totalpaye,$conf->global->MAIN_MAX_DECIMALS_TOT);
//$resteapayer=bcadd($resteapayer,$totalavoir,$conf->global->MAIN_MAX_DECIMALS_TOT); //$resteapayer=bcadd($resteapayer,$totalavoir,$conf->global->MAIN_MAX_DECIMALS_TOT);
$resteapayer = price2num($fac->total_ttc - $totalpaye - $totalavoir,'MT'); $resteapayer = price2num($fac->total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits,'MT');
if ($fac->paye) $resteapayer=0; if ($fac->paye) $resteapayer=0;
$resteapayeraffiche=$resteapayer; $resteapayeraffiche=$resteapayer;
@ -2091,7 +2093,7 @@ else
print '<table class="border" width="100%">'; print '<table class="border" width="100%">';
// Reference // Ref
print '<tr><td width="20%">'.$langs->trans('Ref').'</td>'; print '<tr><td width="20%">'.$langs->trans('Ref').'</td>';
print '<td colspan="5">'; print '<td colspan="5">';
$morehtmlref=''; $morehtmlref='';
@ -2255,7 +2257,7 @@ else
} }
else else
{ {
print '&nbsp;'; print dol_print_date($fac->date,'daytext');
} }
print '</td>'; print '</td>';
@ -3173,7 +3175,7 @@ else
if ($fac->statut == 1 && $fac->paye == 0 && $resteapayer > 0 if ($fac->statut == 1 && $fac->paye == 0 && $resteapayer > 0
&& $user->rights->facture->paiement) && $user->rights->facture->paiement)
{ {
if ($totalpaye > 0 || $totalavoir > 0) if ($totalpaye > 0 || $totalcreditnotes > 0)
{ {
// If one payment or one credit note was linked to this invoice // If one payment or one credit note was linked to this invoice
print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?facid='.$fac->id.'&amp;action=payed">'.$langs->trans('ClassifyPayedPartially').'</a>'; print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?facid='.$fac->id.'&amp;action=payed">'.$langs->trans('ClassifyPayedPartially').'</a>';

View File

@ -366,6 +366,8 @@ if ($_GET['action'] == 'create' || $_POST['action'] == 'confirm_paiement' || $_P
$var=True; $var=True;
$total=0; $total=0;
$totalrecu=0; $totalrecu=0;
$totalrecucreditnote=0;
$totalrecudeposits=0;
while ($i < $num) while ($i < $num)
{ {
@ -376,7 +378,8 @@ if ($_GET['action'] == 'create' || $_POST['action'] == 'confirm_paiement' || $_P
$facturestatic->id=$objp->facid; $facturestatic->id=$objp->facid;
$facturestatic->type=$objp->type; $facturestatic->type=$objp->type;
$creditnote=$facturestatic->getSommeCreditNote(); $creditnotes=$facturestatic->getSumCreditNotesUsed();
$deposits=$facturestatic->getSumDepositsUsed();
print '<tr '.$bc[$var].'>'; print '<tr '.$bc[$var].'>';
@ -392,11 +395,12 @@ if ($_GET['action'] == 'create' || $_POST['action'] == 'confirm_paiement' || $_P
// Recu // Recu
print '<td align="right">'.price($objp->am); print '<td align="right">'.price($objp->am);
if ($creditnote) print '+'.price($creditnote); if ($creditnotes) print '+'.price($creditnotes);
if ($deposits) print '+'.price($deposits);
print '</td>'; print '</td>';
// Reste a payer // Reste a payer
print '<td align="right">'.price(price2num($objp->total_ttc - $objp->am - $creditnote,'MT')).'</td>'; print '<td align="right">'.price(price2num($objp->total_ttc - $objp->am - $creditnotes - $deposits,'MT')).'</td>';
// Montant // Montant
print '<td align="right">'; print '<td align="right">';
@ -418,7 +422,8 @@ if ($_GET['action'] == 'create' || $_POST['action'] == 'confirm_paiement' || $_P
$total+=$objp->total; $total+=$objp->total;
$total_ttc+=$objp->total_ttc; $total_ttc+=$objp->total_ttc;
$totalrecu+=$objp->am; $totalrecu+=$objp->am;
$totalrecucreditnote+=$creditnote; $totalrecucreditnote+=$creditnotes;
$totalrecudeposits+=$deposits;
$i++; $i++;
} }
if ($i > 1) if ($i > 1)
@ -429,8 +434,9 @@ if ($_GET['action'] == 'create' || $_POST['action'] == 'confirm_paiement' || $_P
print '<td align="right"><b>'.price($total_ttc).'</b></td>'; print '<td align="right"><b>'.price($total_ttc).'</b></td>';
print '<td align="right"><b>'.price($totalrecu); print '<td align="right"><b>'.price($totalrecu);
if ($totalrecucreditnote) print '+'.price($totalrecucreditnote); if ($totalrecucreditnote) print '+'.price($totalrecucreditnote);
if ($totalrecudeposits) print '+'.price($totalrecudeposits);
print '</b></td>'; print '</b></td>';
print '<td align="right"><b>'.price(price2num($total_ttc - $totalrecu - $totalrecucreditnote,'MT')).'</b></td>'; print '<td align="right"><b>'.price(price2num($total_ttc - $totalrecu - $totalrecucreditnote - $totalrecudeposits,'MT')).'</b></td>';
print '<td align="center">&nbsp;</td>'; print '<td align="center">&nbsp;</td>';
print '<td align="center">&nbsp;</td>'; print '<td align="center">&nbsp;</td>';
print "</tr>\n"; print "</tr>\n";

View File

@ -323,16 +323,17 @@ class DiscountAbsolute
/** /**
* \brief Renvoie montant TTC des avoirs utilises par la facture * \brief Return amount (with tax) of all credit notes and deposits invoices used by invoice
* \return int <0 if KO, Credit note amount otherwise * \return int <0 if KO, Sum of credit notes and deposits amount otherwise
*/ */
function getSommeCreditNote($invoice) function getSumCreditNotesUsed($invoice)
{ {
$sql = 'SELECT sum(rc.amount_ttc) as amount'; $sql = 'SELECT sum(rc.amount_ttc) as amount';
$sql.= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc'; $sql.= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc, '.MAIN_DB_PREFIX.'facture as f';
$sql.= ' WHERE rc.fk_facture = '.$invoice->id; $sql.= ' WHERE rc.fk_facture_source=f.rowid AND rc.fk_facture = '.$invoice->id;
$sql.= ' AND f.type = 2';
dol_syslog("DiscountAbsolute::getSommeCreditNote sql=".$sql,LOG_DEBUG); dol_syslog("DiscountAbsolute::getSumCreditNotesUsed sql=".$sql,LOG_DEBUG);
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
{ {
@ -345,12 +346,35 @@ class DiscountAbsolute
} }
} }
/**
* \brief Return amount (with tax) of all deposits invoices used by invoice
* \return int <0 if KO, Sum of credit notes and deposits amount otherwise
*/
function getSumDepositsUsed($invoice)
{
$sql = 'SELECT sum(rc.amount_ttc) as amount';
$sql.= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc, '.MAIN_DB_PREFIX.'facture as f';
$sql.= ' WHERE rc.fk_facture_source=f.rowid AND rc.fk_facture = '.$invoice->id;
$sql.= ' AND f.type = 3';
dol_syslog("DiscountAbsolute::getSumDepositsUsed sql=".$sql,LOG_DEBUG);
$resql=$this->db->query($sql);
if ($resql)
{
$obj = $this->db->fetch_object($resql);
return $obj->amount;
}
else
{
return -1;
}
}
/** /**
\brief Renvoie nom clicable (avec eventuellement le picto) * \brief Return clicable ref of object (with picto or not)
\param withpicto 0=Pas de picto, 1=Inclut le picto dans le lien, 2=Picto seul * \param withpicto 0=Pas de picto, 1=Inclut le picto dans le lien, 2=Picto seul
\param option Sur quoi pointe le lien * \param option Sur quoi pointe le lien
\return string Chaine avec URL * \return string Chaine avec URL
*/ */
function getNomUrl($withpicto,$option='invoice') function getNomUrl($withpicto,$option='invoice')
{ {

View File

@ -1867,15 +1867,36 @@ class Facture extends CommonObject
} }
/** /**
* \brief Renvoie montant TTC des avoirs utilises par la facture * \brief Return amount (with tax) of all credit notes and deposits invoices used by invoice
* \return int <0 if KO, Credit note amount otherwise * \return int <0 if KO, Sum of credit notes and deposits amount otherwise
*/ */
function getSommeCreditNote() function getSumCreditNotesUsed()
{ {
require_once(DOL_DOCUMENT_ROOT.'/discount.class.php'); require_once(DOL_DOCUMENT_ROOT.'/discount.class.php');
$discountstatic=new DiscountAbsolute($this->db); $discountstatic=new DiscountAbsolute($this->db);
$result=$discountstatic->getSommeCreditNote($this); $result=$discountstatic->getSumCreditNotesUsed($this);
if ($result >= 0)
{
return $result;
}
else
{
$this->error=$discountstatic->error;
return -1;
}
}
/**
* \brief Return amount (with tax) of all deposits invoices used by invoice
* \return int <0 if KO, Sum of deposits amount otherwise
*/
function getSumDepositsUsed()
{
require_once(DOL_DOCUMENT_ROOT.'/discount.class.php');
$discountstatic=new DiscountAbsolute($this->db);
$result=$discountstatic->getSumDepositsUsed($this);
if ($result >= 0) if ($result >= 0)
{ {
return $result; return $result;

View File

@ -134,9 +134,10 @@ class pdf_crabe extends ModelePDFFactures
$fac->fetch_client(); $fac->fetch_client();
$deja_regle = $fac->getSommePaiement(); $deja_regle = $fac->getSommePaiement();
$amount_credit_not_included = $fac->getSommeCreditNote(); $amount_credit_notes_included = $fac->getSumCreditNotesUsed();
$amount_deposits_included = $fac->getSumDepositsUsed();
// D<EFBFBD>finition de $dir et $file // Definition of $dir and $file
if ($fac->specimen) if ($fac->specimen)
{ {
$dir = $conf->facture->dir_output; $dir = $conf->facture->dir_output;
@ -364,7 +365,7 @@ class pdf_crabe extends ModelePDFFactures
$posy=$this->_tableau_tot($pdf, $fac, $deja_regle, $bottomlasttab, $outputlangs); $posy=$this->_tableau_tot($pdf, $fac, $deja_regle, $bottomlasttab, $outputlangs);
// Affiche zone versements // Affiche zone versements
if ($deja_regle || $amount_credit_not_included) if ($deja_regle || $amount_credit_notes_included || $amount_deposits_included)
{ {
$posy=$this->_tableau_versements($pdf, $fac, $posy, $outputlangs); $posy=$this->_tableau_versements($pdf, $fac, $posy, $outputlangs);
} }
@ -436,11 +437,12 @@ class pdf_crabe extends ModelePDFFactures
$pdf->SetFont('Arial','',6); $pdf->SetFont('Arial','',6);
// Loop on each credit note included // Loop on each deposits and credit notes included
$sql = "SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,"; $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.= " re.description, re.fk_facture_source, re.fk_facture_source,";
$sql.= " FROM ".MAIN_DB_PREFIX ."societe_remise_except as re"; $sql.= " f.type, f.datef";
$sql.= " WHERE fk_facture = ".$fac->id; $sql.= " FROM ".MAIN_DB_PREFIX ."societe_remise_except as re, ".MAIN_DB_PREFIX ."facture as f";
$sql.= " WHERE re.fk_facture_source = f.rowid AND re.fk_facture = ".$fac->id;
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
{ {
@ -452,14 +454,18 @@ class pdf_crabe extends ModelePDFFactures
$y+=3; $y+=3;
$obj = $this->db->fetch_object($resql); $obj = $this->db->fetch_object($resql);
if ($obj->type == 2) $text=$outputlangs->trans("CreditNote");
elseif ($obj->type == 3) $text=$outputlangs->trans("Deposit");
else $text=$outputlangs->trans("UnknownType");
$invoice->fetch($obj->fk_facture_source); $invoice->fetch($obj->fk_facture_source);
$pdf->SetXY ($tab3_posx, $tab3_top+$y ); $pdf->SetXY ($tab3_posx, $tab3_top+$y );
$pdf->MultiCell(20, 3,'', 0, 'L', 0); $pdf->MultiCell(20, 3, dol_print_date($obj->datef,'day',false,$outputlangs,true), 0, 'L', 0);
$pdf->SetXY ($tab3_posx+21, $tab3_top+$y); $pdf->SetXY ($tab3_posx+21, $tab3_top+$y);
$pdf->MultiCell(20, 3, price($obj->amount_ttc), 0, 'L', 0); $pdf->MultiCell(20, 3, price($obj->amount_ttc), 0, 'L', 0);
$pdf->SetXY ($tab3_posx+41, $tab3_top+$y); $pdf->SetXY ($tab3_posx+41, $tab3_top+$y);
$pdf->MultiCell(20, 3, $outputlangs->trans("CreditNote"), 0, 'L', 0); $pdf->MultiCell(20, 3, $text, 0, 'L', 0);
$pdf->SetXY ($tab3_posx+60, $tab3_top+$y); $pdf->SetXY ($tab3_posx+60, $tab3_top+$y);
$pdf->MultiCell(20, 3, $invoice->ref, 0, 'L', 0); $pdf->MultiCell(20, 3, $invoice->ref, 0, 'L', 0);
@ -754,18 +760,20 @@ class pdf_crabe extends ModelePDFFactures
} }
$pdf->SetTextColor(0,0,0); $pdf->SetTextColor(0,0,0);
$creditnoteamount=$object->getSommeCreditNote(); $creditnoteamount=$object->getSumCreditNotesUsed();
$resteapayer = $object->total_ttc - $deja_regle - $creditnoteamount; $depositsamount=$object->getSumDepositsUsed();
//print "x".$creditnoteamount."-".$depositsamount;exit;
$resteapayer = price2num($object->total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 'MT');
if ($object->paye) $resteapayer=0; if ($object->paye) $resteapayer=0;
if ($deja_regle > 0 || $creditnoteamount > 0) if ($deja_regle > 0 || $creditnoteamount > 0 || $depositsamount > 0)
{ {
// Already payed // Already payed + Deposits
$index++; $index++;
$pdf->SetXY ($col1x, $tab2_top + $tab2_hl * $index); $pdf->SetXY ($col1x, $tab2_top + $tab2_hl * $index);
$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("AlreadyPayed"), 0, 'L', 0); $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("Payed"), 0, 'L', 0);
$pdf->SetXY ($col2x, $tab2_top + $tab2_hl * $index); $pdf->SetXY ($col2x, $tab2_top + $tab2_hl * $index);
$pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle), 0, 'R', 0); $pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle + $depositsamount), 0, 'R', 0);
// Credit note // Credit note
if ($creditnoteamount) if ($creditnoteamount)
@ -777,9 +785,6 @@ class pdf_crabe extends ModelePDFFactures
$pdf->MultiCell($largcol2, $tab2_hl, price($creditnoteamount), 0, 'R', 0); $pdf->MultiCell($largcol2, $tab2_hl, price($creditnoteamount), 0, 'R', 0);
} }
$resteapayer = $object->total_ttc - $deja_regle - $creditnoteamount;
if ($object->paye) $resteapayer=0;
// Escompte // Escompte
if ($object->close_code == 'discount_vat') if ($object->close_code == 'discount_vat')
{ {
@ -789,7 +794,7 @@ class pdf_crabe extends ModelePDFFactures
$pdf->SetXY ($col1x, $tab2_top + $tab2_hl * $index); $pdf->SetXY ($col1x, $tab2_top + $tab2_hl * $index);
$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("EscompteOffered"), $useborder, 'L', 1); $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("EscompteOffered"), $useborder, 'L', 1);
$pdf->SetXY ($col2x, $tab2_top + $tab2_hl * $index); $pdf->SetXY ($col2x, $tab2_top + $tab2_hl * $index);
$pdf->MultiCell($largcol2, $tab2_hl, price($object->total_ttc - $deja_regle), $useborder, 'R', 1); $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_ttc - $deja_regle - $creditnoteamount - $depositsamount), $useborder, 'R', 1);
$resteapayer=0; $resteapayer=0;
} }

View File

@ -133,10 +133,10 @@ class pdf_oursin extends ModelePDFFactures
$fac->fetch_client(); $fac->fetch_client();
$deja_regle = $fac->getSommePaiement(); $deja_regle = $fac->getSommePaiement();
$amount_credit_not_included = $fac->getSommeCreditNote(); $amount_credit_notes_included = $fac->getSumCreditNotesUsed();
$amount_deposits_included = $fac->getSumDepositsUsed();
// Definition of $dir and $file
// D<>finition de $dir et $file
if ($fac->specimen) if ($fac->specimen)
{ {
$dir = $conf->facture->dir_output; $dir = $conf->facture->dir_output;
@ -277,7 +277,7 @@ class pdf_oursin extends ModelePDFFactures
$posy=$this->_tableau_tot($pdf, $fac, $deja_regle, $bottomlasttab, $outputlangs); $posy=$this->_tableau_tot($pdf, $fac, $deja_regle, $bottomlasttab, $outputlangs);
// Affiche zone versements // Affiche zone versements
if ($deja_regle || $amount_credit_not_included) if ($deja_regle || $amount_credit_notes_included || $amount_deposits_included)
{ {
$posy=$this->_tableau_versements($pdf, $fac, $posy, $outputlangs); $posy=$this->_tableau_versements($pdf, $fac, $posy, $outputlangs);
} }
@ -350,9 +350,10 @@ class pdf_oursin extends ModelePDFFactures
// Loop on each credit note included // Loop on each credit note included
$sql = "SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,"; $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.= " re.description, re.fk_facture_source, re.fk_facture_source,";
$sql.= " FROM ".MAIN_DB_PREFIX ."societe_remise_except as re"; $sql.= " f.type, f.datef";
$sql.= " WHERE fk_facture = ".$fac->id; $sql.= " FROM ".MAIN_DB_PREFIX ."societe_remise_except as re, ".MAIN_DB_PREFIX ."facture as f";
$sql.= " WHERE re.fk_facture_source = f.rowid AND re.fk_facture = ".$fac->id;
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
{ {
@ -364,14 +365,18 @@ class pdf_oursin extends ModelePDFFactures
$y+=3; $y+=3;
$obj = $this->db->fetch_object($resql); $obj = $this->db->fetch_object($resql);
if ($obj->type == 2) $text=$outputlangs->trans("CreditNote");
elseif ($obj->type == 3) $text=$outputlangs->trans("Deposit");
else $text=$outputlangs->trans("UnknownType");
$invoice->fetch($obj->fk_facture_source); $invoice->fetch($obj->fk_facture_source);
$pdf->SetXY ($tab3_posx, $tab3_top+$y ); $pdf->SetXY ($tab3_posx, $tab3_top+$y );
$pdf->MultiCell(20, 3,'', 0, 'L', 0); $pdf->MultiCell(20, 3, dol_print_date($obj->datef,'day',false,$outputlangs,true), 0, 'L', 0);
$pdf->SetXY ($tab3_posx+21, $tab3_top+$y); $pdf->SetXY ($tab3_posx+21, $tab3_top+$y);
$pdf->MultiCell(20, 3, price($obj->amount_ttc), 0, 'L', 0); $pdf->MultiCell(20, 3, price($obj->amount_ttc), 0, 'L', 0);
$pdf->SetXY ($tab3_posx+41, $tab3_top+$y); $pdf->SetXY ($tab3_posx+41, $tab3_top+$y);
$pdf->MultiCell(20, 3, $outputlangs->trans("CreditNote"), 0, 'L', 0); $pdf->MultiCell(20, 3, $text, 0, 'L', 0);
$pdf->SetXY ($tab3_posx+60, $tab3_top+$y); $pdf->SetXY ($tab3_posx+60, $tab3_top+$y);
$pdf->MultiCell(20, 3, $invoice->ref, 0, 'L', 0); $pdf->MultiCell(20, 3, $invoice->ref, 0, 'L', 0);
@ -584,11 +589,14 @@ class pdf_oursin extends ModelePDFFactures
/** /**
* \brief Affiche le total a payer * \brief Affiche le total a payer
* \param pdf objet PDF * \param pdf Objet PDF
* \param fac objet facture * \param object Objet facture
* \param deja_regle montant deja regle * \param deja_regle Montant deja regle
* \param posy Position depart
* \param outputlangs Objet langs
* \return y Position pour suite
*/ */
function _tableau_tot(&$pdf, $fac, $deja_regle, $posy, $outputlangs) function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
{ {
global $conf,$langs; global $conf,$langs;
@ -621,7 +629,7 @@ class pdf_oursin extends ModelePDFFactures
$pdf->SetXY ($col1x, $tab2_top + 0); $pdf->SetXY ($col1x, $tab2_top + 0);
$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT"), 0, 'L', 0); $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT"), 0, 'L', 0);
$pdf->SetXY ($col2x, $tab2_top + 0); $pdf->SetXY ($col2x, $tab2_top + 0);
$pdf->MultiCell($largcol2, $tab2_hl, price($fac->total_ht + $fac->remise), 0, 'R', 0); $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_ht + $object->remise), 0, 'R', 0);
// Show VAT by rates and total // Show VAT by rates and total
$pdf->SetFillColor(248,248,248); $pdf->SetFillColor(248,248,248);
@ -670,24 +678,25 @@ class pdf_oursin extends ModelePDFFactures
$pdf->SetFont('Arial','B', 11); $pdf->SetFont('Arial','B', 11);
$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC"), 0, 'L', 0); $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC"), 0, 'L', 0);
$pdf->SetXY ($col2x, $tab2_top + $tab2_hl * $index); $pdf->SetXY ($col2x, $tab2_top + $tab2_hl * $index);
$pdf->MultiCell($largcol2, $tab2_hl, price($fac->total_ttc), 0, 'R', 0); $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_ttc), 0, 'R', 0);
$pdf->SetTextColor(0,0,0); $pdf->SetTextColor(0,0,0);
} }
$creditnoteamount=$fac->getSommeCreditNote(); $creditnoteamount=$object->getSumCreditNotesUsed();
$resteapayer = $fac->total_ttc - $deja_regle - $creditnoteamount; $depositsamount=$object->getSumDepositsUsed();
$resteapayer = price2num($object->total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 'MT');
if ($object->paye) $resteapayer=0; if ($object->paye) $resteapayer=0;
if ($deja_regle > 0 || $creditnoteamount > 0) if ($deja_regle > 0 || $creditnoteamount > 0 || $depositsamount > 0)
{ {
$pdf->SetFont('Arial','', 10); $pdf->SetFont('Arial','', 10);
// Already payed // Already payed + Deposits
$index++; $index++;
$pdf->SetXY ($col1x, $tab2_top + $tab2_hl * $index); $pdf->SetXY ($col1x, $tab2_top + $tab2_hl * $index);
$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("AlreadyPayed"), 0, 'L', 0); $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("AlreadyPayed"), 0, 'L', 0);
$pdf->SetXY ($col2x, $tab2_top + $tab2_hl * $index); $pdf->SetXY ($col2x, $tab2_top + $tab2_hl * $index);
$pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle), 0, 'R', 0); $pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle + $depositsamount), 0, 'R', 0);
// Credit note // Credit note
if ($creditnoteamount) if ($creditnoteamount)
@ -699,17 +708,30 @@ class pdf_oursin extends ModelePDFFactures
$pdf->MultiCell($largcol2, $tab2_hl, price($creditnoteamount), 0, 'R', 0); $pdf->MultiCell($largcol2, $tab2_hl, price($creditnoteamount), 0, 'R', 0);
} }
$resteapayer = $object->total_ttc - $deja_regle - $creditnoteamount; // Escompte
if ($object->paye) $resteapayer=0; if ($object->close_code == 'discount_vat')
{
$index++;
$pdf->SetFillColor(255,255,255);
$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 - $creditnoteamount - $depositsamount), $useborder, 'R', 1);
$resteapayer=0;
}
$index++; $index++;
$pdf->SetTextColor(0,0,60); $pdf->SetTextColor(0,0,60);
$pdf->SetFont('Arial','B', 11);
$pdf->SetXY ($col1x, $tab2_top + $tab2_hl * $index); $pdf->SetXY ($col1x, $tab2_top + $tab2_hl * $index);
$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay"), 0, 'L', 0); $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay"), 0, 'L', 0);
$pdf->SetFillColor(224,224,224); $pdf->SetFillColor(224,224,224);
$pdf->SetXY ($col2x, $tab2_top + $tab2_hl * $index); $pdf->SetXY ($col2x, $tab2_top + $tab2_hl * $index);
$pdf->MultiCell($largcol2, $tab2_hl, price($fac->total_ttc - $deja_regle), 0, 'R', 0); $pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer), 0, 'R', 0);
// Fin
$pdf->SetFont('Arial','B', 11);
$pdf->SetTextColor(0,0,0); $pdf->SetTextColor(0,0,0);
} }
@ -721,7 +743,7 @@ class pdf_oursin extends ModelePDFFactures
* \brief Affiche la grille des lignes de factures * \brief Affiche la grille des lignes de factures
* \param pdf objet PDF * \param pdf objet PDF
*/ */
function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $fac, $outputlangs) function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $object, $outputlangs)
{ {
global $conf,$langs; global $conf,$langs;
$langs->load("main"); $langs->load("main");
@ -740,10 +762,10 @@ class pdf_oursin extends ModelePDFFactures
$pdf->Text($this->marges['g']+135, $tab_top + 5,$outputlangs->transnoentities("PriceUHT")); $pdf->Text($this->marges['g']+135, $tab_top + 5,$outputlangs->transnoentities("PriceUHT"));
$pdf->Text($this->marges['g']+153, $tab_top + 5, $outputlangs->transnoentities("Qty")); $pdf->Text($this->marges['g']+153, $tab_top + 5, $outputlangs->transnoentities("Qty"));
$nblignes = sizeof($fac->lignes); $nblignes = sizeof($object->lignes);
$rem=0; $rem=0;
for ($i = 0 ; $i < $nblignes ; $i++) for ($i = 0 ; $i < $nblignes ; $i++)
if ($fac->lignes[$i]->remise_percent) if ($object->lignes[$i]->remise_percent)
{ {
$rem=1; $rem=1;
} }
@ -761,7 +783,7 @@ class pdf_oursin extends ModelePDFFactures
* \param pdf objet PDF * \param pdf objet PDF
* \param fac objet facture * \param fac objet facture
*/ */
function _pagehead(&$pdf, $fac, $showadress=0, $outputlangs) function _pagehead(&$pdf, $object, $showadress=0, $outputlangs)
{ {
global $langs,$conf; global $langs,$conf;
$langs->load("main"); $langs->load("main");
@ -770,7 +792,7 @@ class pdf_oursin extends ModelePDFFactures
$langs->load("companies"); $langs->load("companies");
//Affiche le filigrane brouillon - Print Draft Watermark //Affiche le filigrane brouillon - Print Draft Watermark
if($fac->statut==0 && (! empty($conf->global->FACTURE_DRAFT_WATERMARK)) ) if($object->statut==0 && (! empty($conf->global->FACTURE_DRAFT_WATERMARK)) )
{ {
$watermark_angle=atan($this->page_hauteur/$this->page_largeur); $watermark_angle=atan($this->page_hauteur/$this->page_largeur);
$watermark_x=5; $watermark_x=5;
@ -867,8 +889,6 @@ class pdf_oursin extends ModelePDFFactures
$pdf->SetXY($this->marges['g']+100,$posy-5); $pdf->SetXY($this->marges['g']+100,$posy-5);
$pdf->SetFont('Arial','B',11); $pdf->SetFont('Arial','B',11);
$object=$fac;
// If BILLING contact defined on invoice, we use it // If BILLING contact defined on invoice, we use it
$usecontact=false; $usecontact=false;
if ($conf->global->FACTURE_USE_BILL_CONTACT_AS_RECIPIENT) if ($conf->global->FACTURE_USE_BILL_CONTACT_AS_RECIPIENT)
@ -940,11 +960,11 @@ class pdf_oursin extends ModelePDFFactures
if ($object->type == 2) $title=$outputlangs->transnoentities("InvoiceAvoir"); if ($object->type == 2) $title=$outputlangs->transnoentities("InvoiceAvoir");
if ($object->type == 3) $title=$outputlangs->transnoentities("InvoiceDeposit"); if ($object->type == 3) $title=$outputlangs->transnoentities("InvoiceDeposit");
if ($object->type == 4) $title=$outputlangs->transnoentities("InvoiceProFormat"); if ($object->type == 4) $title=$outputlangs->transnoentities("InvoiceProFormat");
$pdf->MultiCell(100, 10, $title.' '.$outputlangs->transnoentities("Of").' '.dol_print_date($fac->date,"day",false,$outputlangs,true), '' , 'L'); $pdf->MultiCell(100, 10, $title.' '.$outputlangs->transnoentities("Of").' '.dol_print_date($object->date,"day",false,$outputlangs,true), '' , 'L');
$pdf->SetFont('Arial','B',11); $pdf->SetFont('Arial','B',11);
$pdf->SetXY($this->marges['g'],$posy); $pdf->SetXY($this->marges['g'],$posy);
$pdf->SetTextColor(22,137,210); $pdf->SetTextColor(22,137,210);
$pdf->MultiCell(100, 10, $outputlangs->transnoentities("RefBill")." : " . $outputlangs->transnoentities($fac->ref), '', 'L'); $pdf->MultiCell(100, 10, $outputlangs->transnoentities("RefBill")." : " . $outputlangs->transnoentities($object->ref), '', 'L');
$pdf->SetTextColor(0,0,0); $pdf->SetTextColor(0,0,0);
$posy+=4; $posy+=4;
@ -1004,12 +1024,12 @@ class pdf_oursin extends ModelePDFFactures
{ {
$outputlangs->load('propal'); $outputlangs->load('propal');
$sql = "SELECT ".$fac->db->pdate("p.datep")." as dp, p.ref, p.rowid as propalid"; $sql = "SELECT ".$object->db->pdate("p.datep")." as dp, p.ref, p.rowid as propalid";
$sql .= " FROM ".MAIN_DB_PREFIX."propal as p, ".MAIN_DB_PREFIX."fa_pr as fp WHERE fp.fk_propal = p.rowid AND fp.fk_facture = $fac->id"; $sql .= " FROM ".MAIN_DB_PREFIX."propal as p, ".MAIN_DB_PREFIX."fa_pr as fp WHERE fp.fk_propal = p.rowid AND fp.fk_facture = $object->id";
$result = $fac->db->query($sql); $result = $object->db->query($sql);
if ($result) if ($result)
{ {
$objp = $fac->db->fetch_object(); $objp = $object->db->fetch_object();
if ($objp->ref) if ($objp->ref)
{ {
$posy+=4; $posy+=4;
@ -1032,7 +1052,7 @@ class pdf_oursin extends ModelePDFFactures
* \param pdf objet PDF * \param pdf objet PDF
* \param fac objet facture * \param fac objet facture
*/ */
function _pagefoot(&$pdf, $fac, $outputlangs) function _pagefoot(&$pdf, $object, $outputlangs)
{ {
return pdf_pagefoot($pdf,$outputlangs,'FACTURE_FREE_TEXT',$this->emetteur,$this->marge_basse,$this->marge_gauche,$this->page_hauteur); return pdf_pagefoot($pdf,$outputlangs,'FACTURE_FREE_TEXT',$this->emetteur,$this->marge_basse,$this->marge_gauche,$this->page_hauteur);
} }