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);
$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
// 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($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;
$resteapayeraffiche=$resteapayer;
@ -2091,7 +2093,7 @@ else
print '<table class="border" width="100%">';
// Reference
// Ref
print '<tr><td width="20%">'.$langs->trans('Ref').'</td>';
print '<td colspan="5">';
$morehtmlref='';
@ -2255,7 +2257,7 @@ else
}
else
{
print '&nbsp;';
print dol_print_date($fac->date,'daytext');
}
print '</td>';
@ -2293,59 +2295,59 @@ else
$resql=$db->query($sql);
if ($resql)
{
$numdeposits = $db->num_rows($resql);
$i = 0;
$invoice=new Facture($db);
// Loop on each deposit applied
while ($i < $numdeposits)
{
$objinvoice = $db->fetch_object($resql);
$invoice->fetch($objinvoice->fk_facture_source);
if ($invoice->type != 3) continue; // only deposits
$numdeposits = $db->num_rows($resql);
$i = 0;
$invoice=new Facture($db);
// Loop on each deposit applied
while ($i < $numdeposits)
{
$objinvoice = $db->fetch_object($resql);
$invoice->fetch($objinvoice->fk_facture_source);
if ($invoice->type != 3) continue; // only deposits
// For each deposits, get payments
$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 = '.$invoice->id.' AND p.fk_paiement = c.id AND pf.fk_paiement = p.rowid';
$sql.= ' ORDER BY dp, tms';
// For each deposits, get payments
$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 = '.$invoice->id.' AND p.fk_paiement = c.id AND pf.fk_paiement = p.rowid';
$sql.= ' ORDER BY dp, tms';
$resqlpayment = $db->query($sql);
if ($resqlpayment)
{
$numpayments = $db->num_rows($resqlpayment);
$j = 0;
while ($j < $numpayments)
{
$objpayment = $db->fetch_object($resqlpayement);
$var=!$var;
$resqlpayment = $db->query($sql);
if ($resqlpayment)
{
$numpayments = $db->num_rows($resqlpayment);
$j = 0;
while ($j < $numpayments)
{
$objpayment = $db->fetch_object($resqlpayement);
$var=!$var;
print '<tr '.$bc[$var].'><td>';
print '<a href="'.DOL_URL_ROOT.'/compta/paiement/fiche.php?id='.$objpayment->rowid.'">'.img_object($langs->trans('ShowPayment'),'payment').' ';
print dol_print_date($objpayment->dp,'day').'</a>';
print '<tr '.$bc[$var].'><td>';
print '<a href="'.DOL_URL_ROOT.'/compta/paiement/fiche.php?id='.$objpayment->rowid.'">'.img_object($langs->trans('ShowPayment'),'payment').' ';
print dol_print_date($objpayment->dp,'day').'</a>';
print ' ('.$langs->trans("Deposit").' ';
print $invoice->getNomUrl(0).')';
print ' ('.$langs->trans("Deposit").' ';
print $invoice->getNomUrl(0).')';
print '</td>';
print '<td>'.$objpayment->paiement_type.' '.$objpayement->num_paiement.'</td>';
print '<td align="right">'.price($objpayment->amount).'</td>';
// Remove deposit invoice
print '<td align="right">';
print '<a href="'.$_SERVER["PHP_SELF"].'?facid='.$fac->id.'&action=unlinkdiscount&discountid='.$objinvoice->rowid.'">'.img_delete().'</a>';
print '</td>';
print '</tr>';
print '</td>';
print '<td>'.$objpayment->paiement_type.' '.$objpayement->num_paiement.'</td>';
print '<td align="right">'.price($objpayment->amount).'</td>';
// Remove deposit invoice
print '<td align="right">';
print '<a href="'.$_SERVER["PHP_SELF"].'?facid='.$fac->id.'&action=unlinkdiscount&discountid='.$objinvoice->rowid.'">'.img_delete().'</a>';
print '</td>';
print '</tr>';
$j++;
$depositamount += $obj->amount;
}
}
$i++;
}
$j++;
$depositamount += $obj->amount;
}
}
$i++;
}
}
else
{
dol_print_error($db);
dol_print_error($db);
}
*/
@ -3173,7 +3175,7 @@ else
if ($fac->statut == 1 && $fac->paye == 0 && $resteapayer > 0
&& $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
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;
$total=0;
$totalrecu=0;
$totalrecucreditnote=0;
$totalrecudeposits=0;
while ($i < $num)
{
@ -376,7 +378,8 @@ if ($_GET['action'] == 'create' || $_POST['action'] == 'confirm_paiement' || $_P
$facturestatic->id=$objp->facid;
$facturestatic->type=$objp->type;
$creditnote=$facturestatic->getSommeCreditNote();
$creditnotes=$facturestatic->getSumCreditNotesUsed();
$deposits=$facturestatic->getSumDepositsUsed();
print '<tr '.$bc[$var].'>';
@ -392,11 +395,12 @@ if ($_GET['action'] == 'create' || $_POST['action'] == 'confirm_paiement' || $_P
// Recu
print '<td align="right">'.price($objp->am);
if ($creditnote) print '+'.price($creditnote);
if ($creditnotes) print '+'.price($creditnotes);
if ($deposits) print '+'.price($deposits);
print '</td>';
// 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
print '<td align="right">';
@ -418,7 +422,8 @@ if ($_GET['action'] == 'create' || $_POST['action'] == 'confirm_paiement' || $_P
$total+=$objp->total;
$total_ttc+=$objp->total_ttc;
$totalrecu+=$objp->am;
$totalrecucreditnote+=$creditnote;
$totalrecucreditnote+=$creditnotes;
$totalrecudeposits+=$deposits;
$i++;
}
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($totalrecu);
if ($totalrecucreditnote) print '+'.price($totalrecucreditnote);
if ($totalrecudeposits) print '+'.price($totalrecudeposits);
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 "</tr>\n";

View File

@ -33,7 +33,7 @@ class DiscountAbsolute
{
var $db;
var $error;
var $id; // Id remise
var $amount_ht; //
var $amount_tva; //
@ -46,7 +46,7 @@ class DiscountAbsolute
var $fk_facture; // Id invoice when a discoutn linked to invoice
var $fk_facture_source; // Id facture avoir <20> l'origine de la remise
var $ref_facture_source; // Ref facture avoir <20> l'origine de la remise
/**
* \brief Constructeur de la classe
* \param DB handler acc<EFBFBD>s base de donn<EFBFBD>es
@ -91,7 +91,7 @@ class DiscountAbsolute
if ($this->db->num_rows($resql))
{
$obj = $this->db->fetch_object($resql);
$this->id = $obj->rowid;
$this->fk_soc = $obj->fk_soc;
$this->amount_ht = $obj->amount_ht;
@ -105,7 +105,7 @@ class DiscountAbsolute
$this->ref_facture_source = $obj->ref_facture_source; // Ref avoir source
$this->description = $obj->description;
$this->datec = $obj->datec;
$this->db->free($resql);
return 1;
}
@ -131,13 +131,13 @@ class DiscountAbsolute
function create($user)
{
global $conf, $langs;
// Nettoyage parametres
$this->amount_ht=price2num($this->amount_ht);
$this->amount_tva=price2num($this->amount_tva);
$this->amount_ttc=price2num($this->amount_ttc);
$this->tva_tx=price2num($this->tva_tx);
// Insert request
$sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_remise_except";
$sql.= " (datec, fk_soc, fk_user, description,";
@ -172,9 +172,9 @@ class DiscountAbsolute
function delete()
{
global $conf, $langs;
$this->db->begin();
$sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_remise_except ";
$sql.= " WHERE rowid = ".$this->id." AND (fk_facture_line IS NULL or fk_facture IS NULL)";
@ -216,9 +216,9 @@ class DiscountAbsolute
return -1;
}
}
/**
* \brief Link the discount to a particular invoice line or a particular invoice
* \param rowidline Invoice line id
@ -228,17 +228,17 @@ class DiscountAbsolute
function link_to_invoice($rowidline,$rowidinvoice)
{
// Check parameters
if (! $rowidline && ! $rowidinvoice)
if (! $rowidline && ! $rowidinvoice)
{
$this->error='ErrorBadParameters';
return -1;
}
if ($rowidline && $rowidinvoice)
if ($rowidline && $rowidinvoice)
{
$this->error='ErrorBadParameters';
return -2;
}
$sql ="UPDATE ".MAIN_DB_PREFIX."societe_remise_except";
if ($rowidline) $sql.=" SET fk_facture_line = ".$rowidline;
if ($rowidinvoice) $sql.=" SET fk_facture = ".$rowidinvoice;
@ -257,7 +257,7 @@ class DiscountAbsolute
return -3;
}
}
/**
* \brief Link the discount to a particular invoice line or a particular invoice
@ -321,18 +321,19 @@ class DiscountAbsolute
return -1;
}
/**
* \brief Renvoie montant TTC des avoirs utilises par la facture
* \return int <0 if KO, Credit note amount otherwise
* \brief Return amount (with tax) of all credit notes and deposits invoices used by invoice
* \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.= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc';
$sql.= ' WHERE rc.fk_facture = '.$invoice->id;
$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 = 2';
dol_syslog("DiscountAbsolute::getSommeCreditNote sql=".$sql,LOG_DEBUG);
dol_syslog("DiscountAbsolute::getSumCreditNotesUsed sql=".$sql,LOG_DEBUG);
$resql=$this->db->query($sql);
if ($resql)
{
@ -342,22 +343,45 @@ class DiscountAbsolute
else
{
return -1;
}
}
}
/**
* \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)
\param withpicto 0=Pas de picto, 1=Inclut le picto dans le lien, 2=Picto seul
\param option Sur quoi pointe le lien
\return string Chaine avec URL
*/
* \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 option Sur quoi pointe le lien
* \return string Chaine avec URL
*/
function getNomUrl($withpicto,$option='invoice')
{
global $langs;
$result='';
if ($option == 'invoice')
{
$lien = '<a href="'.DOL_URL_ROOT.'/compta/facture.php?facid='.$this->fk_facture_source.'">';
@ -374,13 +398,13 @@ class DiscountAbsolute
$ref=$langs->trans("Discount");
$picto='generic';
}
if ($withpicto) $result.=($lien.img_object($label,$picto).$lienfin);
if ($withpicto && $withpicto != 2) $result.=' ';
$result.=$lien.$ref.$lienfin;
return $result;
}
}
?>

View File

@ -1867,15 +1867,36 @@ class Facture extends CommonObject
}
/**
* \brief Renvoie montant TTC des avoirs utilises par la facture
* \return int <0 if KO, Credit note amount otherwise
* \brief Return amount (with tax) of all credit notes and deposits invoices used by invoice
* \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');
$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)
{
return $result;

View File

@ -132,11 +132,12 @@ class pdf_crabe extends ModelePDFFactures
$ret=$fac->fetch($id);
}
$fac->fetch_client();
$deja_regle = $fac->getSommePaiement();
$amount_credit_not_included = $fac->getSommeCreditNote();
// D<>finition de $dir et $file
$deja_regle = $fac->getSommePaiement();
$amount_credit_notes_included = $fac->getSumCreditNotesUsed();
$amount_deposits_included = $fac->getSumDepositsUsed();
// Definition of $dir and $file
if ($fac->specimen)
{
$dir = $conf->facture->dir_output;
@ -364,7 +365,7 @@ class pdf_crabe extends ModelePDFFactures
$posy=$this->_tableau_tot($pdf, $fac, $deja_regle, $bottomlasttab, $outputlangs);
// 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);
}
@ -436,11 +437,12 @@ class pdf_crabe extends ModelePDFFactures
$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.= " re.description, re.fk_facture_source, re.fk_facture_source";
$sql.= " FROM ".MAIN_DB_PREFIX ."societe_remise_except as re";
$sql.= " WHERE fk_facture = ".$fac->id;
$sql.= " re.description, re.fk_facture_source, re.fk_facture_source,";
$sql.= " f.type, f.datef";
$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);
if ($resql)
{
@ -452,14 +454,18 @@ class pdf_crabe extends ModelePDFFactures
$y+=3;
$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);
$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->MultiCell(20, 3, price($obj->amount_ttc), 0, 'L', 0);
$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->MultiCell(20, 3, $invoice->ref, 0, 'L', 0);
@ -754,18 +760,20 @@ class pdf_crabe extends ModelePDFFactures
}
$pdf->SetTextColor(0,0,0);
$creditnoteamount=$object->getSommeCreditNote();
$resteapayer = $object->total_ttc - $deja_regle - $creditnoteamount;
$creditnoteamount=$object->getSumCreditNotesUsed();
$depositsamount=$object->getSumDepositsUsed();
//print "x".$creditnoteamount."-".$depositsamount;exit;
$resteapayer = price2num($object->total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 'MT');
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++;
$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->MultiCell($largcol2, $tab2_hl, price($deja_regle), 0, 'R', 0);
$pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle + $depositsamount), 0, 'R', 0);
// Credit note
if ($creditnoteamount)
@ -777,9 +785,6 @@ class pdf_crabe extends ModelePDFFactures
$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')
{
@ -789,7 +794,7 @@ 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);
$pdf->MultiCell($largcol2, $tab2_hl, price($object->total_ttc - $deja_regle - $creditnoteamount - $depositsamount), $useborder, 'R', 1);
$resteapayer=0;
}
@ -1004,7 +1009,7 @@ class pdf_crabe extends ModelePDFFactures
$pdf->SetTextColor(0,0,60);
$pdf->MultiCell(100, 3, $outputlangs->transnoentities("CustomerCode")." : " . $object->client->code_client, '', 'R');
}
if ($showadress)
{
// Emetteur

View File

@ -133,10 +133,10 @@ class pdf_oursin extends ModelePDFFactures
$fac->fetch_client();
$deja_regle = $fac->getSommePaiement();
$amount_credit_not_included = $fac->getSommeCreditNote();
$amount_credit_notes_included = $fac->getSumCreditNotesUsed();
$amount_deposits_included = $fac->getSumDepositsUsed();
// D<>finition de $dir et $file
// Definition of $dir and $file
if ($fac->specimen)
{
$dir = $conf->facture->dir_output;
@ -277,7 +277,7 @@ class pdf_oursin extends ModelePDFFactures
$posy=$this->_tableau_tot($pdf, $fac, $deja_regle, $bottomlasttab, $outputlangs);
// 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);
}
@ -350,9 +350,10 @@ class pdf_oursin extends ModelePDFFactures
// 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";
$sql.= " WHERE fk_facture = ".$fac->id;
$sql.= " re.description, re.fk_facture_source, re.fk_facture_source,";
$sql.= " f.type, f.datef";
$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);
if ($resql)
{
@ -364,14 +365,18 @@ class pdf_oursin extends ModelePDFFactures
$y+=3;
$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);
$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->MultiCell(20, 3, price($obj->amount_ttc), 0, 'L', 0);
$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->MultiCell(20, 3, $invoice->ref, 0, 'L', 0);
@ -583,12 +588,15 @@ class pdf_oursin extends ModelePDFFactures
/**
* \brief Affiche le total a payer
* \param pdf objet PDF
* \param fac objet facture
* \param deja_regle montant deja regle
* \brief Affiche le total a payer
* \param pdf Objet PDF
* \param object Objet facture
* \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;
@ -621,7 +629,7 @@ class pdf_oursin extends ModelePDFFactures
$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($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
$pdf->SetFillColor(248,248,248);
@ -670,24 +678,25 @@ class pdf_oursin extends ModelePDFFactures
$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);
$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);
}
$creditnoteamount=$fac->getSommeCreditNote();
$resteapayer = $fac->total_ttc - $deja_regle - $creditnoteamount;
$creditnoteamount=$object->getSumCreditNotesUsed();
$depositsamount=$object->getSumDepositsUsed();
$resteapayer = price2num($object->total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 'MT');
if ($object->paye) $resteapayer=0;
if ($deja_regle > 0 || $creditnoteamount > 0)
if ($deja_regle > 0 || $creditnoteamount > 0 || $depositsamount > 0)
{
$pdf->SetFont('Arial','', 10);
// Already payed
// Already payed + Deposits
$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);
$pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle + $depositsamount), 0, 'R', 0);
// Credit note
if ($creditnoteamount)
@ -699,17 +708,30 @@ class pdf_oursin extends ModelePDFFactures
$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++;
$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++;
$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->SetFillColor(224,224,224);
$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);
}
@ -721,7 +743,7 @@ class pdf_oursin extends ModelePDFFactures
* \brief Affiche la grille des lignes de factures
* \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;
$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']+153, $tab_top + 5, $outputlangs->transnoentities("Qty"));
$nblignes = sizeof($fac->lignes);
$nblignes = sizeof($object->lignes);
$rem=0;
for ($i = 0 ; $i < $nblignes ; $i++)
if ($fac->lignes[$i]->remise_percent)
if ($object->lignes[$i]->remise_percent)
{
$rem=1;
}
@ -761,7 +783,7 @@ class pdf_oursin extends ModelePDFFactures
* \param pdf objet PDF
* \param fac objet facture
*/
function _pagehead(&$pdf, $fac, $showadress=0, $outputlangs)
function _pagehead(&$pdf, $object, $showadress=0, $outputlangs)
{
global $langs,$conf;
$langs->load("main");
@ -770,7 +792,7 @@ class pdf_oursin extends ModelePDFFactures
$langs->load("companies");
//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_x=5;
@ -867,8 +889,6 @@ class pdf_oursin extends ModelePDFFactures
$pdf->SetXY($this->marges['g']+100,$posy-5);
$pdf->SetFont('Arial','B',11);
$object=$fac;
// If BILLING contact defined on invoice, we use it
$usecontact=false;
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 == 3) $title=$outputlangs->transnoentities("InvoiceDeposit");
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->SetXY($this->marges['g'],$posy);
$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);
$posy+=4;
@ -1004,12 +1024,12 @@ class pdf_oursin extends ModelePDFFactures
{
$outputlangs->load('propal');
$sql = "SELECT ".$fac->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";
$result = $fac->db->query($sql);
$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 = $object->id";
$result = $object->db->query($sql);
if ($result)
{
$objp = $fac->db->fetch_object();
$objp = $object->db->fetch_object();
if ($objp->ref)
{
$posy+=4;
@ -1032,7 +1052,7 @@ class pdf_oursin extends ModelePDFFactures
* \param pdf objet PDF
* \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);
}