2
0
forked from Wavyzz/dolibarr

Fix: Avoid converting into reduction twice and draft invoice

This commit is contained in:
Ferran Marcet
2018-06-15 11:19:04 +02:00
parent e18a5d148c
commit a21e138c70
2 changed files with 34 additions and 32 deletions

View File

@@ -12,7 +12,7 @@
* Copyright (C) 2013 Jean-Francois FERRY <jfefe@aternatik.fr>
* Copyright (C) 2013-2014 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
* Copyright (C) 2014 Ferran Marcet <fmarcet@2byte.es>
* Copyright (C) 2014-2018 Ferran Marcet <fmarcet@2byte.es>
* Copyright (C) 2015-2016 Marcos García <marcosgdf@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
@@ -4408,7 +4408,7 @@ else if ($id > 0 || ! empty($ref))
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?facid=' . $object->id . '&amp;action=converttoreduc">' . $langs->trans('ConvertToReduc') . '</a></div>';
}
// For deposit invoice
if ($object->type == Facture::TYPE_DEPOSIT && $user->rights->facture->creer && empty($discount->id))
if ($object->type == Facture::TYPE_DEPOSIT && $user->rights->facture->creer && $object->statut > 0 && empty($discount->id))
{
print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?facid='.$object->id.'&amp;action=converttoreduc">'.$langs->trans('ConvertToReduc').'</a></div>';
}

View File

@@ -6,6 +6,7 @@
* Copyright (C) 2014 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
* Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
* 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
* 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();
// Insert one discount by VAT rate category
$discount = new DiscountAbsolute($this->db);
$discount->fetch('',$invoice->id);
if (empty($discount->id)) {
$discount->description = '(DEPOSIT)';
$discount->fk_soc = $invoice->socid;
$discount->fk_facture_source = $invoice->id;
// Loop on each vat rate
$i = 0;
foreach ($invoice->lines as $line)
{
if ($line->total_ht!=0)
{ // no need to create discount if amount is null
foreach ($invoice->lines as $line) {
if ($line->total_ht != 0) { // no need to create discount if amount is null
$amount_ht[$line->tva_tx] += $line->total_ht;
$amount_tva[$line->tva_tx] += $line->total_tva;
$amount_ttc[$line->tva_tx] += $line->total_ttc;
@@ -301,26 +310,19 @@ class Paiement extends CommonObject
}
}
// Insert one discount by VAT rate category
$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)
{
foreach ($amount_ht as $tva_tx => $xxx) {
$discount->amount_ht = abs($amount_ht[$tva_tx]);
$discount->amount_tva = abs($amount_tva[$tva_tx]);
$discount->amount_ttc = abs($amount_ttc[$tva_tx]);
$discount->tva_tx = abs($tva_tx);
$result = $discount->create($user);
if ($result < 0)
{
if ($result < 0) {
$error++;
break;
}
}
}
if ($error)
{