Fix regression on vat calculation when invoice was not a situation
invoice
This commit is contained in:
parent
e0809fc750
commit
1b30c1adb4
@ -141,8 +141,8 @@ if ($result) {
|
||||
|
||||
// Situation invoices handling
|
||||
$line = new FactureLigne($db);
|
||||
$line->fetch($obj->rowid);
|
||||
$prev_progress = $line->get_prev_progress();
|
||||
$line->fetch($obj->fdid); // id of line
|
||||
$prev_progress = $line->get_prev_progress($obj->rowid); // id of invoice
|
||||
if ($obj->type == Facture::TYPE_SITUATION) {
|
||||
// Avoid divide by 0
|
||||
if ($obj->situation_percent == 0) {
|
||||
|
||||
@ -1564,7 +1564,7 @@ if (empty($reshook))
|
||||
|
||||
$line = new FactureLigne($db);
|
||||
$line->fetch(GETPOST('lineid'));
|
||||
$percent = $line->get_prev_progress();
|
||||
$percent = $line->get_prev_progress($object->id);
|
||||
|
||||
if (GETPOST('progress') < $percent)
|
||||
{
|
||||
@ -1682,7 +1682,7 @@ if (empty($reshook))
|
||||
{
|
||||
foreach ($object->lines as $line)
|
||||
{
|
||||
$percent = $line->get_prev_progress();
|
||||
$percent = $line->get_prev_progress($object->id);
|
||||
if (GETPOST('all_progress') < $percent) {
|
||||
$mesg = '<div class="warning">' . $langs->trans("CantBeLessThanMinPercent") . '</div>';
|
||||
$result = -1;
|
||||
|
||||
@ -4256,15 +4256,22 @@ class FactureLigne extends CommonInvoiceLine
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns situation_percent of the previous line
|
||||
* Returns situation_percent of the previous line.
|
||||
* Warning: If invoice is a replacement invoice, this->fk_prev_id is id of the replaced line.
|
||||
*
|
||||
* @return int >= 0
|
||||
* @param int $invoiceid Invoice id
|
||||
* @return int >= 0
|
||||
*/
|
||||
function get_prev_progress()
|
||||
function get_prev_progress($invoiceid)
|
||||
{
|
||||
if (is_null($this->fk_prev_id) || empty($this->fk_prev_id) || $this->fk_prev_id == "") {
|
||||
return 0;
|
||||
} else {
|
||||
// If invoice is a not a situation invoice, this->fk_prev_id is used for something else
|
||||
$tmpinvoice=new Facture($this->db);
|
||||
$tmpinvoice->fetch($invoiceid);
|
||||
if ($tmpinvoice->type != Facture::TYPE_SITUATION) return 0;
|
||||
|
||||
$sql = 'SELECT situation_percent FROM ' . MAIN_DB_PREFIX . 'facturedet WHERE rowid=' . $this->fk_prev_id;
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql && $resql->num_rows > 0) {
|
||||
|
||||
@ -166,8 +166,8 @@ if ($result)
|
||||
|
||||
// Situation invoices handling
|
||||
$line = new FactureLigne($db);
|
||||
$line->fetch($obj->id);
|
||||
$prev_progress = $line->get_prev_progress();
|
||||
$line->fetch($obj->id); // id of line
|
||||
$prev_progress = $line->get_prev_progress($obj->rowid); // id on invoice
|
||||
if ($obj->type==Facture::TYPE_SITUATION) {
|
||||
// Avoid divide by 0
|
||||
if ($obj->situation_percent == 0) {
|
||||
|
||||
@ -167,7 +167,7 @@ class pdf_crabe extends ModelePDFFactures
|
||||
function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hidedesc=0,$hideref=0)
|
||||
{
|
||||
global $user,$langs,$conf,$mysoc,$db,$hookmanager;
|
||||
|
||||
|
||||
if (! is_object($outputlangs)) $outputlangs=$langs;
|
||||
// For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
|
||||
if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
|
||||
@ -540,13 +540,14 @@ class pdf_crabe extends ModelePDFFactures
|
||||
$pdf->MultiCell($this->page_largeur-$this->marge_droite-$this->postotalht, 3, $total_excl_tax, 0, 'R', 0);
|
||||
|
||||
// Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva
|
||||
$prev_progress = $object->lines[$i]->get_prev_progress();
|
||||
$prev_progress = $object->lines[$i]->get_prev_progress($object->id);
|
||||
if ($prev_progress > 0) // Compute progress from previous situation
|
||||
{
|
||||
$tvaligne = $object->lines[$i]->total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
|
||||
} else {
|
||||
$tvaligne = $object->lines[$i]->total_tva;
|
||||
}
|
||||
|
||||
$localtax1ligne=$object->lines[$i]->total_localtax1;
|
||||
$localtax2ligne=$object->lines[$i]->total_localtax2;
|
||||
$localtax1_rate=$object->lines[$i]->localtax1_tx;
|
||||
@ -1103,7 +1104,8 @@ class pdf_crabe extends ModelePDFFactures
|
||||
}
|
||||
}
|
||||
}
|
||||
//}
|
||||
|
||||
//}
|
||||
// VAT
|
||||
foreach($this->tva as $tvakey => $tvaval)
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user