From 480b08bd0bd46519d4ca2cfaaf8cf0df4580d252 Mon Sep 17 00:00:00 2001 From: gauthier Date: Thu, 24 Nov 2016 15:48:04 +0100 Subject: [PATCH 1/6] NEW : convert exceiss received to reduc --- htdocs/comm/remx.php | 9 +++++ htdocs/compta/facture.php | 66 ++++++++++++++++++++++++++++------- htdocs/langs/en_US/bills.lang | 4 +-- 3 files changed, 64 insertions(+), 15 deletions(-) diff --git a/htdocs/comm/remx.php b/htdocs/comm/remx.php index e358b842d2d..372ee529b8b 100644 --- a/htdocs/comm/remx.php +++ b/htdocs/comm/remx.php @@ -369,6 +369,15 @@ if ($socid > 0) print preg_replace('/\(DEPOSIT\)/',$langs->trans("InvoiceDeposit"),$obj->description).' '.$facturestatic->getNomURl(1); print ''; } + elseif (preg_match('/\(EXCESS RECEIVED\)/',$obj->description)) + { + print ''; + $facturestatic->id=$obj->fk_facture_source; + $facturestatic->ref=$obj->ref; + $facturestatic->type=$obj->type; + print preg_replace('/\(EXCESS RECEIVED\)/',$langs->trans("Invoice"),$obj->description).' '.$facturestatic->getNomURl(1); + print ''; + } else { print ''; diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 34ed1383e14..8cafa015d92 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -579,7 +579,7 @@ if (empty($reshook)) $canconvert=0; if ($object->type == Facture::TYPE_DEPOSIT && $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 == Facture::TYPE_CREDIT_NOTE && $object->paye == 0 && empty($discountcheck->id)) $canconvert=1; // we can convert credit note into discount if credit note is not payed back and not already converted and amount of payment is 0 (see real condition into condition used to show button converttoreduc) + if (($object->type == Facture::TYPE_CREDIT_NOTE || $object->type == Facture::TYPE_STANDARD) && $object->paye == 0 && empty($discountcheck->id)) $canconvert=1; // we can convert credit note into discount if credit note is not payed back and not already converted and amount of payment is 0 (see real condition into condition used to show button converttoreduc) if ($canconvert) { $db->begin(); @@ -596,13 +596,15 @@ if (empty($reshook)) $i ++; } } - +//var_dump($amount_ht, $amount_tva, $amount_ttc);exit; // Insert one discount by VAT rate category $discount = new DiscountAbsolute($db); if ($object->type == Facture::TYPE_CREDIT_NOTE) $discount->description = '(CREDIT_NOTE)'; elseif ($object->type == Facture::TYPE_DEPOSIT) $discount->description = '(DEPOSIT)'; + elseif ($object->type == Facture::TYPE_STANDARD) + $discount->description = '(EXCESS RECEIVED)'; else { setEventMessages($langs->trans('CantConvertToReducAnInvoiceOfThisType'), null, 'errors'); } @@ -611,13 +613,22 @@ if (empty($reshook)) $discount->fk_facture_source = $object->id; $error = 0; - - 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); + + if ($object->type == Facture::TYPE_STANDARD) { + + // If we're on a standard invoice, we have to get excess received to create it in TTC wuthout VAT + + $sql = 'SELECT SUM(pf.amount) as total_paiements + FROM llx_c_paiement as c, llx_paiement_facture as pf, llx_paiement as p + WHERE pf.fk_facture = 10 AND p.fk_paiement = c.id AND pf.fk_paiement = p.rowid ORDER BY p.datep, p.tms'; + + $resql = $db->query($sql); + $res = $db->fetch_object($resql); + $total_paiements = $res->total_paiements; + + $discount->amount_ht = $discount->amount_ttc = $total_paiements - $object->total_ttc; + $discount->amount_tva = 0; + $discount->tva_tx = 0; $result = $discount->create($user); if ($result < 0) @@ -625,8 +636,25 @@ if (empty($reshook)) $error++; break; } + + } else { + + 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) + { + $error++; + break; + } + } + } - if (empty($error)) { // Classe facture @@ -2587,7 +2615,10 @@ else if ($id > 0 || ! empty($ref)) // Confirmation de la conversion de l'avoir en reduc if ($action == 'converttoreduc') { - $text = $langs->trans('ConfirmConvertToReduc'); + if($object->type == 0) $type_fac = 'ExcessReceived'; + elseif($object->type == 2) $type_fac = 'CreditNote'; + elseif($object->type == 3) $type_fac = 'Deposit'; + $text = $langs->trans('ConfirmConvertToReduc', strtolower($langs->transnoentities($type_fac))); $formconfirm = $form->formconfirm($_SERVER['PHP_SELF'] . '?facid=' . $object->id, $langs->trans('ConvertToReduc'), $text, 'confirm_converttoreduc', '', "yes", 2); } @@ -2829,7 +2860,10 @@ else if ($id > 0 || ! empty($ref)) $discount = new DiscountAbsolute($db); $result = $discount->fetch(0, $object->id); if ($result > 0) { - $morehtmlref = ' (' . $langs->trans("CreditNoteConvertedIntoDiscount", $discount->getNomUrl(1, 'discount')) . ')'; + if($object->type == 0) $type_fac = 'ExcessReceived'; + elseif($object->type == 2) $type_fac = 'CreditNote'; + elseif($object->type == 3) $type_fac = 'Deposit'; + $morehtmlref = ' (' . $langs->trans("CreditNoteConvertedIntoDiscount", strtolower($langs->transnoentities($type_fac)), $discount->getNomUrl(1, 'discount')) . ')'; } if ($result < 0) { dol_print_error('', $discount->error); @@ -3205,6 +3239,7 @@ else if ($id > 0 || ! empty($ref)) print $langs->trans('RemainderToPay'); else print $langs->trans('ExcessReceived'); + print ' :'; print '' . price($resteapayeraffiche) . ''; print ' '; @@ -3688,7 +3723,7 @@ else if ($id > 0 || ! empty($ref)) } // Reverse back money or convert to reduction - if ($object->type == Facture::TYPE_CREDIT_NOTE || $object->type == Facture::TYPE_DEPOSIT) { + if ($object->type == Facture::TYPE_CREDIT_NOTE || $object->type == Facture::TYPE_DEPOSIT || $object->type == Facture::TYPE_STANDARD) { // For credit note only if ($object->type == Facture::TYPE_CREDIT_NOTE && $object->statut == 1 && $object->paye == 0 && $user->rights->facture->paiement) { @@ -3702,6 +3737,11 @@ else if ($id > 0 || ! empty($ref)) } } + // For standard invoice with excess received + if ($object->type == Facture::TYPE_STANDARD && empty($object->paye) && ($object->total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits) < 0 && $user->rights->facture->creer && empty($discount->id)) + { + print '
'.$langs->trans('ConvertToReduc').'
'; + } // For credit note if ($object->type == Facture::TYPE_CREDIT_NOTE && $object->statut == 1 && $object->paye == 0 && $user->rights->facture->creer && $object->getSommePaiement() == 0) { print '
' . $langs->trans('ConvertToReduc') . '
'; diff --git a/htdocs/langs/en_US/bills.lang b/htdocs/langs/en_US/bills.lang index bfbe32b803e..fb27b364dcf 100644 --- a/htdocs/langs/en_US/bills.lang +++ b/htdocs/langs/en_US/bills.lang @@ -61,7 +61,7 @@ PaymentsBack=Payments back PaidBack=Paid back DeletePayment=Delete payment ConfirmDeletePayment=Are you sure you want to delete this payment ? -ConfirmConvertToReduc=Do you want to convert this credit note or deposit into an absolute discount ?
The amount will so be saved among all discounts and could be used as a discount for a current or a future invoice for this customer. +ConfirmConvertToReduc=Do you want to convert this %s into an absolute discount ?
The amount will so be saved among all discounts and could be used as a discount for a current or a future invoice for this customer. SupplierPayments=Suppliers payments ReceivedPayments=Received payments ReceivedCustomersPayments=Payments received from customers @@ -386,7 +386,7 @@ ChequeDeposits=Checks deposits Cheques=Checks DepositId=Id deposit NbCheque=Number of checks -CreditNoteConvertedIntoDiscount=This credit note or deposit invoice has been converted into %s +CreditNoteConvertedIntoDiscount=This %s has been converted into %s UsBillingContactAsIncoiveRecipientIfExist=Use customer billing contact address instead of third party address as recipient for invoices ShowUnpaidAll=Show all unpaid invoices ShowUnpaidLateOnly=Show late unpaid invoices only From c433829d27420b7a51733c50109de522c29b6704 Mon Sep 17 00:00:00 2001 From: gauthier Date: Fri, 25 Nov 2016 11:04:42 +0100 Subject: [PATCH 2/6] NEW : interface --- htdocs/compta/facture.php | 6 +++--- htdocs/core/class/commonobject.class.php | 6 ++++++ htdocs/core/class/html.form.class.php | 3 ++- htdocs/core/lib/doc.lib.php | 6 ++++++ htdocs/core/lib/pdf.lib.php | 6 ++++++ htdocs/core/tpl/objectline_view.tpl.php | 7 +++++++ htdocs/langs/en_US/bills.lang | 2 ++ htdocs/societe/consumption.php | 7 +++++++ 8 files changed, 39 insertions(+), 4 deletions(-) diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 8cafa015d92..8ef7f39e0b8 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -2591,8 +2591,8 @@ else if ($id > 0 || ! empty($ref)) $filterabsolutediscount = "fk_facture_source IS NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice $filtercreditnote = "fk_facture_source IS NOT NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice } else { - $filterabsolutediscount = "fk_facture_source IS NULL OR (fk_facture_source IS NOT NULL AND description LIKE '(DEPOSIT)%')"; - $filtercreditnote = "fk_facture_source IS NOT NULL AND description NOT LIKE '(DEPOSIT)%'"; + $filterabsolutediscount = "fk_facture_source IS NULL OR (fk_facture_source IS NOT NULL AND (description LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%'))"; + $filtercreditnote = "fk_facture_source IS NOT NULL AND description NOT LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%'"; } $absolute_discount = $soc->getAvailableDiscounts('', $filterabsolutediscount); @@ -3740,7 +3740,7 @@ else if ($id > 0 || ! empty($ref)) // For standard invoice with excess received if ($object->type == Facture::TYPE_STANDARD && empty($object->paye) && ($object->total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits) < 0 && $user->rights->facture->creer && empty($discount->id)) { - print ''; + print ''; } // For credit note if ($object->type == Facture::TYPE_CREDIT_NOTE && $object->statut == 1 && $object->paye == 0 && $user->rights->facture->creer && $object->getSommePaiement() == 0) { diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 3279d372a0e..eaf8166e141 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -3411,6 +3411,12 @@ abstract class CommonObject $discount->fetch($line->fk_remise_except); $this->tpl['description'] = $langs->transnoentities("DiscountFromDeposit",$discount->getNomUrl(0)); } + elseif ($line->desc == '(EXCESS RECEIVED)') + { + $discount=new DiscountAbsolute($this->db); + $discount->fetch($line->fk_remise_except); + $this->tpl['description'] = $langs->transnoentities("DiscountFromExcessReceived",$discount->getNomUrl(0)); + } else { $this->tpl['description'] = dol_trunc($line->desc,60); diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index c4273a779a9..fcd60169470 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -1130,6 +1130,7 @@ class Form $desc=dol_trunc($obj->description,40); if (preg_match('/\(CREDIT_NOTE\)/', $desc)) $desc=preg_replace('/\(CREDIT_NOTE\)/', $langs->trans("CreditNote"), $desc); if (preg_match('/\(DEPOSIT\)/', $desc)) $desc=preg_replace('/\(DEPOSIT\)/', $langs->trans("Deposit"), $desc); + if (preg_match('/\(EXCESS RECEIVED\)/', $desc)) $desc=preg_replace('/\(EXCESS RECEIVED\)/', $langs->trans("ExcessReceived"), $desc); $selectstring=''; if ($selected > 0 && $selected == $obj->rowid) $selectstring=' selected'; @@ -3762,7 +3763,7 @@ class Form } else { - if (! $filter || $filter=="fk_facture_source IS NULL OR (fk_facture_source IS NOT NULL AND description LIKE '(DEPOSIT)%')") print $langs->trans("CompanyHasAbsoluteDiscount",price($amount,0,$langs,0,0,-1,$conf->currency)).': '; + if (! $filter || $filter=="fk_facture_source IS NULL OR (fk_facture_source IS NOT NULL AND (description LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%'))") print $langs->trans("CompanyHasAbsoluteDiscount",price($amount,0,$langs,0,0,-1,$conf->currency)).': '; else print $langs->trans("CompanyHasCreditNote",price($amount,0,$langs,0,0,-1,$conf->currency)).': '; } $newfilter='fk_facture IS NULL AND fk_facture_line IS NULL'; // Remises disponibles diff --git a/htdocs/core/lib/doc.lib.php b/htdocs/core/lib/doc.lib.php index 76337ec2763..99e576ad057 100644 --- a/htdocs/core/lib/doc.lib.php +++ b/htdocs/core/lib/doc.lib.php @@ -83,6 +83,12 @@ function doc_getlinedesc($line,$outputlangs,$hideref=0,$hidedesc=0,$issupplierli // Add date of deposit if (! empty($conf->global->INVOICE_ADD_DEPOSIT_DATE)) $libelleproduitservice.=' ('.dol_print_date($discount->datec,'day','',$outputlangs).')'; } + elseif ($desc == '(EXCESS RECEIVED)' && $line->fk_remise_except) + { + $discount=new DiscountAbsolute($db); + $discount->fetch($line->fk_remise_except); + $libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromExcessReceived",$discount->ref_facture_source); + } else { if ($idprod) diff --git a/htdocs/core/lib/pdf.lib.php b/htdocs/core/lib/pdf.lib.php index 8b21fcdefe9..80f0727bdf4 100644 --- a/htdocs/core/lib/pdf.lib.php +++ b/htdocs/core/lib/pdf.lib.php @@ -1149,6 +1149,12 @@ function pdf_getlinedesc($object,$i,$outputlangs,$hideref=0,$hidedesc=0,$issuppl // Add date of deposit if (! empty($conf->global->INVOICE_ADD_DEPOSIT_DATE)) echo ' ('.dol_print_date($discount->datec,'day','',$outputlangs).')'; } + if ($desc == '(EXCESS RECEIVED)' && $object->lines[$i]->fk_remise_except) + { + $discount=new DiscountAbsolute($db); + $discount->fetch($object->lines[$i]->fk_remise_except); + $libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromExcessReceived",$discount->ref_facture_source); + } else { if ($idprod) diff --git a/htdocs/core/tpl/objectline_view.tpl.php b/htdocs/core/tpl/objectline_view.tpl.php index 7162ac66cb9..30bf2eeb05c 100644 --- a/htdocs/core/tpl/objectline_view.tpl.php +++ b/htdocs/core/tpl/objectline_view.tpl.php @@ -61,6 +61,7 @@ if (empty($usemargins)) $usemargins=0; $txt=''; print img_object($langs->trans("ShowReduc"),'reduc').' '; if ($line->description == '(DEPOSIT)') $txt=$langs->trans("Deposit"); + elseif ($line->description == '(EXCESS RECEIVED)') $txt=$langs->trans("ExcessReceived"); //else $txt=$langs->trans("Discount"); print $txt; ?> @@ -82,6 +83,12 @@ if (empty($usemargins)) $usemargins=0; // Add date of deposit if (! empty($conf->global->INVOICE_ADD_DEPOSIT_DATE)) echo ' ('.dol_print_date($discount->datec).')'; } + elseif ($line->description == '(EXCESS RECEIVED)' && $objp->fk_remise_except > 0) + { + $discount=new DiscountAbsolute($this->db); + $discount->fetch($line->fk_remise_except); + echo ($txt?' - ':'').$langs->transnoentities("DiscountFromExcessReceived",$discount->getNomUrl(0)); + } else { echo ($txt?' - ':'').dol_htmlentitiesbr($line->description); diff --git a/htdocs/langs/en_US/bills.lang b/htdocs/langs/en_US/bills.lang index fb27b364dcf..5a3ab004308 100644 --- a/htdocs/langs/en_US/bills.lang +++ b/htdocs/langs/en_US/bills.lang @@ -99,6 +99,7 @@ SendRemindByMail=Send reminder by EMail DoPayment=Do payment DoPaymentBack=Do payment back ConvertToReduc=Convert into future discount +ConvertExcessReceivedToReduc=Convert excess received into future discount EnterPaymentReceivedFromCustomer=Enter payment received from customer EnterPaymentDueToCustomer=Make payment due to customer DisabledBecauseRemainderToPayIsZero=Disabled because remaining unpaid is zero @@ -255,6 +256,7 @@ Deposit=Deposit Deposits=Deposits DiscountFromCreditNote=Discount from credit note %s DiscountFromDeposit=Payments from deposit invoice %s +DiscountFromExcessReceived=Payments from excess received of invoice %s AbsoluteDiscountUse=This kind of credit can be used on invoice before its validation CreditNoteDepositUse=Invoice must be validated to use this king of credits NewGlobalDiscount=New absolute discount diff --git a/htdocs/societe/consumption.php b/htdocs/societe/consumption.php index ea2cb899893..4bfbe99528a 100644 --- a/htdocs/societe/consumption.php +++ b/htdocs/societe/consumption.php @@ -461,6 +461,7 @@ if ($sql_select) $txt=''; print img_object($langs->trans("ShowReduc"),'reduc').' '; if ($objp->description == '(DEPOSIT)') $txt=$langs->trans("Deposit"); + elseif ($objp->description == '(EXCESS RECEIVED)') $txt=$langs->trans("ExcessReceived"); //else $txt=$langs->trans("Discount"); print $txt; ?> @@ -474,6 +475,12 @@ if ($sql_select) $discount->fetch($objp->fk_remise_except); echo ($txt?' - ':'').$langs->transnoentities("DiscountFromCreditNote",$discount->getNomUrl(0)); } + if ($objp->description == '(EXCESS RECEIVED)' && $objp->fk_remise_except > 0) + { + $discount=new DiscountAbsolute($db); + $discount->fetch($objp->fk_remise_except); + echo ($txt?' - ':'').$langs->transnoentities("DiscountFromExcessReceived",$discount->getNomUrl(0)); + } elseif ($objp->description == '(DEPOSIT)' && $objp->fk_remise_except > 0) { $discount=new DiscountAbsolute($db); From 792e12e6c50ae08db3421bce440ac94ac7146704 Mon Sep 17 00:00:00 2001 From: gauthier Date: Fri, 25 Nov 2016 11:09:15 +0100 Subject: [PATCH 3/6] FIX : interface --- htdocs/comm/remx.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/htdocs/comm/remx.php b/htdocs/comm/remx.php index 372ee529b8b..716018dbcca 100644 --- a/htdocs/comm/remx.php +++ b/htdocs/comm/remx.php @@ -537,6 +537,15 @@ if ($socid > 0) print preg_replace('/\(DEPOSIT\)/',$langs->trans("InvoiceDeposit"),$obj->description).' '.$facturestatic->getNomURl(1); print ''; } + elseif (preg_match('/\(EXCESS RECEIVED\)/',$obj->description)) + { + print ''; + $facturestatic->id=$obj->fk_facture_source; + $facturestatic->ref=$obj->ref; + $facturestatic->type=$obj->type; + print preg_replace('/\(EXCESS RECEIVED\)/',$langs->trans("Invoice"),$obj->description).' '.$facturestatic->getNomURl(1); + print ''; + } else { print ''; From 3f6f1ac86fb91b18995becbd58850c9759afac81 Mon Sep 17 00:00:00 2001 From: gauthier Date: Mon, 28 Nov 2016 17:12:17 +0100 Subject: [PATCH 4/6] fix : where fk_facture = object id --- htdocs/compta/facture.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 8ef7f39e0b8..bc36f16e9e4 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -620,7 +620,7 @@ if (empty($reshook)) $sql = 'SELECT SUM(pf.amount) as total_paiements FROM llx_c_paiement as c, llx_paiement_facture as pf, llx_paiement as p - WHERE pf.fk_facture = 10 AND p.fk_paiement = c.id AND pf.fk_paiement = p.rowid ORDER BY p.datep, p.tms'; + WHERE pf.fk_facture = '.$object->id.' AND p.fk_paiement = c.id AND pf.fk_paiement = p.rowid ORDER BY p.datep, p.tms'; $resql = $db->query($sql); $res = $db->fetch_object($resql); From d8aa572ad79fab306964a1a7e5e615368225cd84 Mon Sep 17 00:00:00 2001 From: gauthier Date: Mon, 28 Nov 2016 17:38:20 +0100 Subject: [PATCH 5/6] FIX : fetch discount desappeared in develop... --- htdocs/compta/facture.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 7e1baf5395f..a846fb15e00 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -3870,7 +3870,10 @@ else if ($id > 0 || ! empty($ref)) } } } - + + $discount = new DiscountAbsolute($db); + $result = $discount->fetch(0, $object->id); + // Reopen a standard paid invoice if ((($object->type == Facture::TYPE_STANDARD || $object->type == Facture::TYPE_REPLACEMENT) || ($object->type == Facture::TYPE_CREDIT_NOTE && empty($discount->id)) From ef721bebc60933940c2ef0f00fa3dd398518e55f Mon Sep 17 00:00:00 2001 From: gauthier Date: Fri, 9 Dec 2016 17:48:03 +0100 Subject: [PATCH 6/6] FIX : break with no iteration --- htdocs/compta/facture.php | 1 - 1 file changed, 1 deletion(-) diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index a846fb15e00..b5008801645 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -657,7 +657,6 @@ if (empty($reshook)) if ($result < 0) { $error++; - break; } } else {