Merge pull request #8972 from fmarcet/7.0
FIX Avoid converting into reduction twice and draft invoice
This commit is contained in:
commit
cfc8e8b0ef
@ -6,6 +6,7 @@
|
|||||||
* Copyright (C) 2014 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
|
* Copyright (C) 2014 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
|
||||||
* Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
|
* Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
|
||||||
* Copyright (C) 2015 Juanjo Menent <jmenent@2byte.es>
|
* Copyright (C) 2015 Juanjo Menent <jmenent@2byte.es>
|
||||||
|
* Copyright (C) 2018 Ferran Marcet <fmarcet@2byte.es>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -288,12 +289,20 @@ class Paiement extends CommonObject
|
|||||||
{
|
{
|
||||||
$amount_ht = $amount_tva = $amount_ttc = array();
|
$amount_ht = $amount_tva = $amount_ttc = array();
|
||||||
|
|
||||||
|
// Insert one discount by VAT rate category
|
||||||
|
$discount = new DiscountAbsolute($this->db);
|
||||||
|
$discount->fetch('',$invoice->id);
|
||||||
|
if (empty($discount->id)) { // If the invoice was not yet converted into a discount (this may have been done manually before we come here)
|
||||||
|
|
||||||
|
|
||||||
|
$discount->description = '(DEPOSIT)';
|
||||||
|
$discount->fk_soc = $invoice->socid;
|
||||||
|
$discount->fk_facture_source = $invoice->id;
|
||||||
|
|
||||||
// Loop on each vat rate
|
// Loop on each vat rate
|
||||||
$i = 0;
|
$i = 0;
|
||||||
foreach ($invoice->lines as $line)
|
foreach ($invoice->lines as $line) {
|
||||||
{
|
if ($line->total_ht != 0) { // no need to create discount if amount is null
|
||||||
if ($line->total_ht!=0)
|
|
||||||
{ // no need to create discount if amount is null
|
|
||||||
$amount_ht[$line->tva_tx] += $line->total_ht;
|
$amount_ht[$line->tva_tx] += $line->total_ht;
|
||||||
$amount_tva[$line->tva_tx] += $line->total_tva;
|
$amount_tva[$line->tva_tx] += $line->total_tva;
|
||||||
$amount_ttc[$line->tva_tx] += $line->total_ttc;
|
$amount_ttc[$line->tva_tx] += $line->total_ttc;
|
||||||
@ -301,26 +310,19 @@ class Paiement extends CommonObject
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert one discount by VAT rate category
|
foreach ($amount_ht as $tva_tx => $xxx) {
|
||||||
$discount = new DiscountAbsolute($this->db);
|
|
||||||
$discount->description = '(DEPOSIT)';
|
|
||||||
$discount->fk_soc = $invoice->socid;
|
|
||||||
$discount->fk_facture_source = $invoice->id;
|
|
||||||
|
|
||||||
foreach ($amount_ht as $tva_tx => $xxx)
|
|
||||||
{
|
|
||||||
$discount->amount_ht = abs($amount_ht[$tva_tx]);
|
$discount->amount_ht = abs($amount_ht[$tva_tx]);
|
||||||
$discount->amount_tva = abs($amount_tva[$tva_tx]);
|
$discount->amount_tva = abs($amount_tva[$tva_tx]);
|
||||||
$discount->amount_ttc = abs($amount_ttc[$tva_tx]);
|
$discount->amount_ttc = abs($amount_ttc[$tva_tx]);
|
||||||
$discount->tva_tx = abs($tva_tx);
|
$discount->tva_tx = abs($tva_tx);
|
||||||
|
|
||||||
$result = $discount->create($user);
|
$result = $discount->create($user);
|
||||||
if ($result < 0)
|
if ($result < 0) {
|
||||||
{
|
|
||||||
$error++;
|
$error++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($error)
|
if ($error)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user