From 77ca4241a571ba96b6e1e8bfbb686db38c5b4e73 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 9 Dec 2012 18:39:42 +0100 Subject: [PATCH] New: Can input a payment back onto an credit note. --- ChangeLog | 1 + htdocs/compta/ajaxpayment.php | 4 +- htdocs/compta/facture.php | 35 ++++++-- htdocs/compta/paiement.php | 86 ++++++++++++------- .../compta/paiement/class/paiement.class.php | 12 ++- htdocs/compta/paiement/liste.php | 10 +-- .../modules/facture/doc/pdf_crabe.modules.php | 18 ++-- htdocs/langs/en_US/banks.lang | 1 + htdocs/langs/en_US/bills.lang | 7 ++ htdocs/langs/en_US/compta.lang | 6 +- htdocs/langs/fr_FR/banks.lang | 1 + htdocs/langs/fr_FR/bills.lang | 10 ++- htdocs/langs/fr_FR/compta.lang | 6 +- 13 files changed, 134 insertions(+), 63 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8fd47651f99..308b1704819 100644 --- a/ChangeLog +++ b/ChangeLog @@ -9,6 +9,7 @@ For users: - New: Add field "signature" into thirdparty card. If filled, text is added at end of predefined email texts. If option MAIL_DO_NOT_USE_SIGN is on, this feature is disabled. +- New: Can input a payment back onto an credit note. - New: Add link "Back to list" on all cards. - New: After first install, warning are visible onto mandatory setup not configured. Show also total number of activated modules. diff --git a/htdocs/compta/ajaxpayment.php b/htdocs/compta/ajaxpayment.php index cf042bccc49..59e0fb90a00 100644 --- a/htdocs/compta/ajaxpayment.php +++ b/htdocs/compta/ajaxpayment.php @@ -42,13 +42,13 @@ $langs->load('compta'); */ //init var +$invoice_type = GETPOST('invoice_type','int'); $amountPayment = $_POST['amountPayment']; $amounts = $_POST['amounts']; // from text inputs : invoice amount payment (check required) $remains = $_POST['remains']; // from dolibarr's object (no need to check) $currentInvId = $_POST['imgClicked']; // from DOM elements : imgId (equals invoice id) // Getting the posted keys=>values, sanitize the ones who are from text inputs -// from text inputs : total amount $amountPayment = $amountPayment!='' ? ( is_numeric(price2num($amountPayment)) ? price2num($amountPayment) : '' ) : ''; // keep void if not a valid entry // Clean checkamounts @@ -62,7 +62,7 @@ foreach ($amounts as $key => $value) foreach ($remains as $key => $value) { $value = price2num($value); - $remains[$key]=$value; + $remains[$key]=(($invoice_type)==2?-1:1)*$value; if (empty($value)) unset($remains[$key]); } diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index a66f53f7458..27ffdf3323b 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -2647,6 +2647,9 @@ else if ($id > 0 || ! empty($ref)) * List of payments */ + $sign=1; + if ($object->type == 2) $sign=-1; + $nbrows=8; $nbcols=2; if (! empty($conf->projet->enabled)) $nbrows++; if (! empty($conf->banque->enabled)) $nbcols++; @@ -2686,9 +2689,9 @@ else if ($id > 0 || ! empty($ref)) { $num = $db->num_rows($result); $i = 0; - - if ($object->type != 2) - { + + //if ($object->type != 2) + //{ if ($num > 0) { while ($i < $num) @@ -2709,7 +2712,7 @@ else if ($id > 0 || ! empty($ref)) if ($bankaccountstatic->id) print $bankaccountstatic->getNomUrl(1,'transactions'); print ''; } - print ''.price($objp->amount).''; + print ''.price($sign * $objp->amount).''; print ' '; print ''; $i++; @@ -2719,7 +2722,7 @@ else if ($id > 0 || ! empty($ref)) { print ''.$langs->trans("None").''; } - } + //} $db->free($result); } else @@ -2819,11 +2822,27 @@ else if ($id > 0 || ! empty($ref)) print ''.price($resteapayeraffiche).''; print ' '; } - else + else // Credit note { + // Total already paid back + print ''; + print $langs->trans('AlreadyPaidBack'); + print ' :'.price($sign * $totalpaye).' '; + + // Billed + print ''.$langs->trans("Billed").' :'.price($sign * $object->total_ttc).' '; + + // Remainder to pay back + print ''; + if ($resteapayeraffiche <= 0) print $langs->trans('RemainderToPayBack'); + else print $langs->trans('ExcessPaydBack'); + print ' :'; + print ''.price($sign * $resteapayeraffiche).''; + print ' '; + // Sold credit note - print ''.$langs->trans('TotalTTC').' :'; - print ''.price(abs($object->total_ttc)).' '; + //print ''.$langs->trans('TotalTTC').' :'; + //print ''.price($sign * $object->total_ttc).' '; } print ''; diff --git a/htdocs/compta/paiement.php b/htdocs/compta/paiement.php index 4819172cff5..e680368d380 100644 --- a/htdocs/compta/paiement.php +++ b/htdocs/compta/paiement.php @@ -83,7 +83,7 @@ if ($action == 'add_paiement' || ($action == 'confirm_paiement' && $confirm=='ye $tmpfacture=new Facture($db); $tmpfacture->fetch($cursorfacid); $amountsresttopay[$cursorfacid]=price2num($tmpfacture->total_ttc-$tmpfacture->getSommePaiement()); - if ($amounts[$cursorfacid] && $amounts[$cursorfacid] > $amountsresttopay[$cursorfacid]) + if ($amounts[$cursorfacid] && (abs($amounts[$cursorfacid]) > abs($amountsresttopay[$cursorfacid]))) { $addwarning=1; $formquestion['text'] = img_warning($langs->trans("PaymentHigherThanReminderToPay")).' '.$langs->trans("HelpPaymentHigherThanReminderToPay"); @@ -147,6 +147,16 @@ if ($action == 'confirm_paiement' && $confirm == 'yes') $db->begin(); + // Clean parameters amount if payment is for a credit note + if (GETPOST('type') == 2) + { + foreach ($amounts as $key => $value) // How payment is dispatch + { + $newvalue = price2num($value,'MT'); + $amounts[$key] = -$newvalue; + } + } + // Creation of payment line $paiement = new Paiement($db); $paiement->datepaye = $datepaye; @@ -157,7 +167,7 @@ if ($action == 'confirm_paiement' && $confirm == 'yes') if (! $error) { - $paiement_id = $paiement->create($user,(GETPOST('closepaidinvoices')=='on'?1:0)); + $paiement_id = $paiement->create($user, (GETPOST('closepaidinvoices')=='on'?1:0)); if ($paiement_id < 0) { $errmsg=$paiement->error; @@ -167,7 +177,9 @@ if ($action == 'confirm_paiement' && $confirm == 'yes') if (! $error) { - $result=$paiement->addPaymentToBank($user,'payment','(CustomerInvoicePayment)',$_POST['accountid'],$_POST['chqemetteur'],$_POST['chqbank']); + $label='(CustomerInvoicePayment)'; + if (GETPOST('type') == 2) $label='(CustomerInvoicePaymentBack)'; + $result=$paiement->addPaymentToBank($user,'payment',$label,$_POST['accountid'],$_POST['chqemetteur'],$_POST['chqbank']); if ($result < 0) { $errmsg=$paiement->error; @@ -227,15 +239,6 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie dol_htmloutput_errors($errmsg); - // Bouchon - if ($facture->type == 2) - { - $langs->load('other'); - print $langs->trans("FeatureNotYetAvailable"); - llxFooter(); - exit; - } - // Initialize data for confirmation (this is used because data can be change during confirmation) if ($action == 'add_paiement') { @@ -253,6 +256,8 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie if (! empty($conf->global->PAYPAL_BANK_ACCOUNT)) $accountid=$conf->global->PAYPAL_BANK_ACCOUNT; $paymentnum=$facture->ref_int; } + + // Add realtime total information if ($conf->use_javascript_ajax) { print "\n".'