From 4afb85bd1d36ccdd4e4cd5ad7e0db956d9441038 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 19 Mar 2014 22:30:25 +0100 Subject: [PATCH] Fix: Several fix into workflow/condition for invoice payments or convert into discount. --- htdocs/compta/facture.php | 41 +++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index f8655c7c850..46d868085c3 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -578,14 +578,21 @@ else if ($action == 'confirm_canceled' && $confirm == 'yes') // Convertir en reduc else if ($action == 'confirm_converttoreduc' && $confirm == 'yes' && $user->rights->facture->creer) { - $db->begin(); - $object->fetch($id); $object->fetch_thirdparty(); $object->fetch_lines(); - if (!empty($object->paye)) // protection against multiple submit + // Check if there is already a discount (protection to avoid duplicate creation when resubmit post) + $discountcheck=new DiscountAbsolute($db); + $result=$discountcheck->fetch(0,$object->id); + + $canconvert=0; + if ($object->type == 3 && $object->paye == 1 && empty($discountcheck->id)) $canconvert=1; // we can convert deposit into discount if deposit is payed completely and not already converted (see real condition into condition used to show button converttoreduc) + if ($object->type == 2 && $object->paye == 0 && empty($discountcheck->id)) $canconvert=1; // we can convert credit note into discount if credit note is not payed back and amount of payment is 0 (see real condition into condition used to show button converttoreduc) + if ($canconvert) { + $db->begin(); + // Boucle sur chaque taux de tva $i=0; foreach($object->lines as $line) @@ -1980,9 +1987,10 @@ if ($action == 'update_extras') } + /* * View -*/ + */ $form = new Form($db); $formother=new FormOther($db); @@ -2185,6 +2193,7 @@ if ($action == 'create') $options.=''; } + // Show link for credit note $facids=$facturestatic->list_qualified_avoir_invoices($soc->id); if ($facids < 0) { @@ -3592,7 +3601,10 @@ else if ($id > 0 || ! empty($ref)) } // Reopen a standard paid invoice - if (($object->type == 0 || $object->type == 1) && ($object->statut == 2 || $object->statut == 3)) // A paid invoice (partially or completely) + if ((($object->type == 0 || $object->type == 1) + || ($object->type == 2 && empty($discount->id)) + || ($object->type == 3 && empty($discount->id))) + && ($object->statut == 2 || $object->statut == 3)) // A paid invoice (partially or completely) { if (! $objectidnext && $object->close_code != 'replaced') // Not replaced by another invoice { @@ -3679,23 +3691,32 @@ else if ($id > 0 || ! empty($ref)) // For credit note only if ($object->type == 2 && $object->statut == 1 && $object->paye == 0 && $user->rights->facture->paiement) { - print '
'.$langs->trans('DoPaymentBack').'
'; + if ($resteapayer == 0) + { + print '
'.$langs->trans('DoPaymentBack').'
'; + } + else + { + print '
'.$langs->trans('DoPaymentBack').'
'; + } } + // For credit note if ($object->type == 2 && $object->statut == 1 && $object->paye == 0 && $user->rights->facture->creer && $object->getSommePaiement() == 0) { print '
'.$langs->trans('ConvertToReduc').'
'; } // For deposit invoice - if ($object->type == 3 && $object->statut == 2 && $resteapayer == 0 && $user->rights->facture->creer && empty($discount->id)) + if ($object->type == 3 && $object->paye == 1 && $resteapayer == 0 && $user->rights->facture->creer && empty($discount->id)) { print '
'.$langs->trans('ConvertToReduc').'
'; } } - // Classify paid (if not deposit and not credit note. Such invoice are "converted") - if ($object->statut == 1 && $object->paye == 0 && $user->rights->facture->paiement && - (($object->type != 2 && $object->type != 3 && $resteapayer <= 0) || ($object->type == 2 && $resteapayer >= 0)) ) + // Classify paid + if ($object->statut == 1 && $object->paye == 0 && $user->rights->facture->paiement && (($object->type != 2 && $object->type != 3 && $resteapayer <= 0) || ($object->type == 2 && $resteapayer >= 0)) + || ($object->type == 3 && $object->paye == 0 && $resteapayer == 0 && $user->rights->facture->paiement && empty($discount->id)) + ) { print '
'.$langs->trans('ClassifyPaid').'
'; }