Bonjour à tous,
Vous trouverez ci-joint un patch pour le paiement des factures,
ajoutant sur la page de règlement un champ pour indiquer le montant
d'un paiement, un bouton par facture pour déduire à ce total le
maximum et l'afficher dans le champ associé (le cas échéant, ce bouton
peut déduire un montant négatif au champ en question). Calcul et
affiche également le montant restant à affecter en fonction du montant
payé, sur la ligne de total et à chaque changement de valeur d'un des
champs ajouté ou clic sur un bouton js.
Autre sujet, M. De Lambert m'a parlé d'une tâche qui consisterait à
donner la possibilité à l'utilisateur de créer des champs
personnalisés. Si vous avez des infos ou des détails à ce sujet, je
suis preneur.
translation:
Hello everyone,
You will find attached a patch for the payment of the bills, adding
the page a field to indicate the amount of any payment, a button per
invoice to infer that the maximum total and display it in the
associated field (If applicable, this button can deduce a negative
amount to the field in question). Calculation and also displays the
remaining amount to be allocated according to the amount paid on the
total line and at each change in value of an added field or click on a
js button.
Another subject, Mr. Lambert told me about a task would be to provide
an opportunity for the user to create custom fields. If you have any
info or details about it, I'm interested.
Anthony Poiret
### Eclipse Workspace Patch 1.0
#P dolibarr
Index: htdocs/compta/paiement.php
===================================================================
RCS file: /sources/dolibarr/dolibarr/htdocs/compta/paiement.php,v
retrieving revision 1.99
diff -u -r1.99 paiement.php
--- htdocs/compta/paiement.php 19 Mar 2011 13:59:05 -0000 1.99
+++ htdocs/compta/paiement.php 5 May 2011 09:57:57 -0000
@@ -324,7 +324,12 @@
print ' <em>('.$langs->trans("ChequeBank").')</em>';
print '</td>';
print '<td><input name="chqbank" size="30" type="text"
value="'.GETPOST('chqbank').'"></td></tr>';
-
+ print '<tr><td>'.$langs->trans('AmountPayment');
+ print '</td>';
+
+ // Field to input the payment amount
+ print '<td><input name="amountpayment" size="8" type="text"
value="'.(empty($_POST['amountpayment'])?'0':$_POST['amountpayment']).'"
onchange="javascript:alter_amount_payment();return false;" ></td></tr>';
+
print '</table>';
/*
@@ -362,9 +367,110 @@
print '<td
align="right">'.$langs->trans('AmountTTC').'</td>';
print '<td
align="right">'.$langs->trans('Received').'</td>';
print '<td
align="right">'.$langs->trans('RemainderToPay').'</td>';
- print '<td
align="right">'.$langs->trans('PaymentAmount').'</td>';
print '<td align="right"> </td>';
- print "</tr>\n";
+ print '<td
align="right">'.$langs->trans('PaymentAmount').'</td>';
+ print '<td align="right"> </td>';
+ print "</tr>\n";
+ print '<script type="text/javascript"
language="javascript">
+
+ /* This Array is used to get and store Array
containing (String format):
+ * [0]-> the $namef of the
linked text field (in order to get and set ElementsById)
+ * [1]-> the linked
invoice amount
+ * [2]-> the linked amount
payed (in order to calculate the remaining payment amount)
*/
+ var amountInput = new Array();
+
+ var totalAmount = 0;
+ var paymentRemaining = 0;
+
+ /* This function is used to round floats to
monetary format
*/
+ function roundNumber(num,dec) {
+ var result =
Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
+ return result;
+ }
+
+ /* This function is used to parse php
Strings(floats with coma) to javascript floats (with stops)
*/
+ function convertFloat(str)
+ {
+ return
parseFloat(str.replace(/,/, \'.\').split(\' \').join(\'\'));
+ }
+
+ /* This function is used to convert javascript
floats (stored as String) to coma floats (as String too) */
+ function toComaStr(str)
+ {
+ return str.replace(/\./, ",");
+ }
+
+ /* This function is called onclick of the
buttons linked to the invoices. It refreshes the linked payed amount
+ * contained by the corresponding array, and
the text field linked to the corresponding invoice
*/
+ function calcRemind(index)
+ {
+ invoiceAmount =
convertFloat(amountInput[index][1]);
+ var payedAmount =
amountInput[index][2] != 0 ? convertFloat(amountInput[index][2]) : 0;
+ paymentRemaining =
paymentRemaining + payedAmount;
+ payedAmount = 0;
+ if(paymentRemaining -
invoiceAmount < 0)
+ {
+ payedAmount =
paymentRemaining;
+ paymentRemaining = 0;
+ }else
+ {
+ paymentRemaining -=
invoiceAmount;
+ payedAmount =
invoiceAmount;
+ }
+ if(payedAmount < 0)
+ {
+ paymentRemaining +=
payedAmount;
+ payedAmount = 0;
+ }
+ amountInput[index][2] =
payedAmount.toString();
+
document.getElementById(amountInput[index][0]).value =
toComaStr(roundNumber(payedAmount,2).toString());
+ changeSumAmount();
+ }
+
+ /* This function is called when the payment\'s
amount is change. It refreshes the array containing
+ * the amounts payed (from the text fields
linked to invoices)
*/
+ function alter_amount_payment()
+ {
+ totalAmount =
document.add_paiement.amountpayment.value != 0 ?
convertFloat(document.add_paiement.amountpayment.value) : 0;
+ totalAmount =
isNaN(totalAmount) ? 0 : totalAmount;
+ paymentRemaining = totalAmount;
+ for(var ii=0;
ii<amountInput.length; ii++)
+ {
+
if(isNaN(convertFloat(document.getElementById(amountInput[ii][0]).value)))
+
amountInput[ii][2] = 0;
+ else
+
paymentRemaining -=
convertFloat(document.getElementById(amountInput[ii][0]).value);
+ }
+ changeSumAmount();
+ }
+
+ /* This function is called when a change occurs
on the text fields link to the invoices amount
+ * to pay
*/
+ function changeAmount(index)
+ {
+ var oldAmount =
amountInput[index][2];
+ var newAmount =
isNaN(document.getElementById(amountInput[index][0]).value) ? 0 :
document.getElementById(amountInput[index][0]).value;
+ paymentRemaining += oldAmount -
newAmount ;
+ amountInput[index][2] =
newAmount;
+ changeSumAmount();
+ }
+
+ /* This function is called when any change
occurs on the amounts objects to print the remaining
+ * amount of the payment to divide into
invoices amount
*/
+ function changeSumAmount(t)
+ {
+ var dispatchRemaining =
totalAmount;
+ for(var ii = 0; ii <
amountInput.length; ii++)
+ {
+ dispatchRemaining -=
amountInput[ii][2] != 0 ? convertFloat(amountInput[ii][2]) : 0;
+ }
+ if(dispatchRemaining < 0)
+
document.getElementById("amount_sum_payment").style.setProperty("color","#ff0000","");
+ else
+
document.getElementById("amount_sum_payment").style.removeProperty("color");
+
document.getElementById("amount_sum_payment").innerHTML=
"'.$langs->trans('RemainToDivide').'"+toComaStr(roundNumber(dispatchRemaining,2).toString());
+ }
+ </script>';
$var=True;
$total=0;
@@ -405,18 +511,24 @@
// Remain to pay
print '<td
align="right">'.price($remaintopay).'</td>';
-
+ $test= price(price2num($objp->total_ttc
- $paiement - $creditnotes - $deposits));
+
+ // Add remind amount
+ $namef = 'amount_'.$objp->facid;
+ print '<script type="text/javascript"
language="javascript">amountInput.push(new
Array("'.$namef.'","'.price(price2num($objp->total_ttc - $paiement -
$creditnotes - $deposits)).'","0"));</script>'; // Push a new Array into the
amountInput Array
+ print '<td align="right"><button
class="button" onclick="calcRemind(\''.$i.'\');return
false;">'.$langs->trans('AddRemind').'</button></td>';
+
// Amount
print '<td align="right">';
$namef = 'amount_'.$objp->facid;
if ($_POST["action"] != 'add_paiement')
{
- print '<input type="text"
size="8" name="'.$namef.'" value="'.$_POST[$namef].'">';
+ print '<input id="'.$namef.'"
type="text" onchange="javascript:changeAmount('.$i.');return false;" size="8"
name="'.$namef.'" value="'.$_POST[$namef].'">';
}
else
{
- print '<input type="text"
size="8" name="'.$namef.'_disabled" value="'.$_POST[$namef].'"
disabled="true">';
- print '<input type="hidden"
name="'.$namef.'" value="'.$_POST[$namef].'">';
+ print '<input type="text"
onchange="javascript:changeAmount();return false;" size="8"
name="'.$namef.'_disabled" value="'.$_POST[$namef].'" disabled="true">';
+ print '<input id="'.$namef.'"
type="hidden" name="'.$namef.'" value="'.$_POST[$namef].'">';
}
print "</td>";
@@ -450,6 +562,7 @@
print '</b></td>';
print '<td
align="right"><b>'.price(price2num($total_ttc - $totalrecu -
$totalrecucreditnote - $totalrecudeposits,'MT')).'</b></td>';
print '<td align="center"> </td>';
+ print '<td align="right"
id="amount_sum_payment" style="font-weight:bold;"></td>';
print '<td align="center"> </td>';
print "</tr>\n";
}
Index: htdocs/langs/en_US/compta.lang
===================================================================
RCS file: /sources/dolibarr/dolibarr/htdocs/langs/en_US/compta.lang,v
retrieving revision 1.70
diff -u -r1.70 compta.lang
--- htdocs/langs/en_US/compta.lang 19 Jan 2011 09:21:48 -0000 1.70
+++ htdocs/langs/en_US/compta.lang 5 May 2011 09:57:57 -0000
@@ -123,4 +123,5 @@
DescPurchasesJournal=Purchases Journal
InvoiceRef=Invoice ref.
CodeNotDef=Not defined
-
+AddRemind=Calculate payment
+RemainToDivide= Remain to divide :
Index: htdocs/langs/fr_FR/compta.lang
===================================================================
RCS file: /sources/dolibarr/dolibarr/htdocs/langs/fr_FR/compta.lang,v
retrieving revision 1.88
diff -u -r1.88 compta.lang
--- htdocs/langs/fr_FR/compta.lang 28 Dec 2010 23:52:17 -0000 1.88
+++ htdocs/langs/fr_FR/compta.lang 5 May 2011 09:57:57 -0000
@@ -135,4 +135,6 @@
COMPTA_SERVICE_SOLD_ACCOUNT=Code comptable par défaut pour services vendus (si
non défini sur fiche service)
COMPTA_VAT_ACCOUNT=Code comptable par défaut pour TVA (si non défini dans
dictionnaire "Taux de TVA")
COMPTA_ACCOUNT_CUSTOMER=Code comptable client par défaut (si non défini sur
fiche tiers)
-COMPTA_ACCOUNT_SUPPLIER=Code comptable fournisseur par défaut (si non défini
sur fiche tiers)
\ No newline at end of file
+COMPTA_ACCOUNT_SUPPLIER=Code comptable fournisseur par défaut (si non défini
sur fiche tiers)
+AddRemind=Calculer le paiement
+RemainToDivide=Reste à répartir :
\ No newline at end of file
_______________________________________________
Dolibarr-dev mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/dolibarr-dev