Try to add a patch but keep it with a condition because of several problems.
This commit is contained in:
parent
ff904e662b
commit
f12075a028
@ -262,7 +262,15 @@ if ($_GET['action'] == 'create' || $_POST['action'] == 'confirm_paiement' || $_P
|
|||||||
jQuery(\'.fieldrequireddyn\').removeClass(\'fieldrequired\');
|
jQuery(\'.fieldrequireddyn\').removeClass(\'fieldrequired\');
|
||||||
}
|
}
|
||||||
});';
|
});';
|
||||||
|
print 'jQuery("#amountpayment").keyup(function() {
|
||||||
|
alter_amount_payment();
|
||||||
|
});';
|
||||||
|
print 'jQuery("#amountpayment").change(function() {
|
||||||
|
alter_amount_payment();
|
||||||
|
});';
|
||||||
|
print 'alter_amount_payment();';
|
||||||
print '});';
|
print '});';
|
||||||
|
|
||||||
print '</script>'."\n";
|
print '</script>'."\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -287,12 +295,34 @@ if ($_GET['action'] == 'create' || $_POST['action'] == 'confirm_paiement' || $_P
|
|||||||
print '</td>';
|
print '</td>';
|
||||||
print '<td>'.$langs->trans('Comments').'</td></tr>';
|
print '<td>'.$langs->trans('Comments').'</td></tr>';
|
||||||
|
|
||||||
|
$rowspan=5;
|
||||||
|
if (! empty($conf->global->MAIN_JS_ON_PAYMENT)) $rowspan++;
|
||||||
|
|
||||||
|
// Payment mode
|
||||||
print '<tr><td><span class="fieldrequired">'.$langs->trans('PaymentMode').'</span></td><td>';
|
print '<tr><td><span class="fieldrequired">'.$langs->trans('PaymentMode').'</span></td><td>';
|
||||||
$html->select_types_paiements(GETPOST('paiementcode'),'paiementcode','',2);
|
$html->select_types_paiements(GETPOST('paiementcode'),'paiementcode','',2);
|
||||||
print "</td>\n";
|
print "</td>\n";
|
||||||
|
print '<td rowspan="'.$rowspan.'" valign="top">';
|
||||||
|
print '<textarea name="comment" wrap="soft" cols="60" rows="'.ROWS_4.'">'.(empty($_POST['comment'])?'':$_POST['comment']).'</textarea></td>';
|
||||||
|
print '</tr>';
|
||||||
|
|
||||||
print '<td rowspan="5" valign="top">';
|
// Payment amount
|
||||||
print '<textarea name="comment" wrap="soft" cols="60" rows="'.ROWS_4.'">'.(empty($_POST['comment'])?'':$_POST['comment']).'</textarea></td></tr>';
|
if (! empty($conf->global->MAIN_JS_ON_PAYMENT))
|
||||||
|
{
|
||||||
|
print '<tr><td><span class="fieldrequired">'.$langs->trans('AmountPayment').'</span></td>';
|
||||||
|
print '<td>';
|
||||||
|
if ($_POST["action"] == 'add_paiement')
|
||||||
|
{
|
||||||
|
print '<input id="amountpayment" name="amountpaymenthidden" size="8" type="text" value="'.(empty($_POST['amountpayment'])?'':$_POST['amountpayment']).'" disabled="true">';
|
||||||
|
print '<input name="amountpayment" type="hidden" value="'.(empty($_POST['amountpayment'])?'':$_POST['amountpayment']).'">';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
print '<input id="amountpayment" name="amountpayment" size="8" type="text" value="'.(empty($_POST['amountpayment'])?'':$_POST['amountpayment']).'">';
|
||||||
|
}
|
||||||
|
print '</td>';
|
||||||
|
print '</tr>';
|
||||||
|
}
|
||||||
|
|
||||||
print '<tr>';
|
print '<tr>';
|
||||||
if ($conf->banque->enabled)
|
if ($conf->banque->enabled)
|
||||||
@ -309,6 +339,7 @@ if ($_GET['action'] == 'create' || $_POST['action'] == 'confirm_paiement' || $_P
|
|||||||
}
|
}
|
||||||
print "</tr>\n";
|
print "</tr>\n";
|
||||||
|
|
||||||
|
// Cheque number
|
||||||
print '<tr><td>'.$langs->trans('Numero');
|
print '<tr><td>'.$langs->trans('Numero');
|
||||||
print ' <em>('.$langs->trans("ChequeOrTransferNumber").')</em>';
|
print ' <em>('.$langs->trans("ChequeOrTransferNumber").')</em>';
|
||||||
print '</td>';
|
print '</td>';
|
||||||
@ -320,6 +351,7 @@ if ($_GET['action'] == 'create' || $_POST['action'] == 'confirm_paiement' || $_P
|
|||||||
print '</td>';
|
print '</td>';
|
||||||
print '<td><input id="fieldchqemetteur" name="chqemetteur" size="30" type="text" value="'.GETPOST('chqemetteur').'"></td></tr>';
|
print '<td><input id="fieldchqemetteur" name="chqemetteur" size="30" type="text" value="'.GETPOST('chqemetteur').'"></td></tr>';
|
||||||
|
|
||||||
|
// Bank name
|
||||||
print '<tr><td>'.$langs->trans('Bank');
|
print '<tr><td>'.$langs->trans('Bank');
|
||||||
print ' <em>('.$langs->trans("ChequeBank").')</em>';
|
print ' <em>('.$langs->trans("ChequeBank").')</em>';
|
||||||
print '</td>';
|
print '</td>';
|
||||||
@ -366,6 +398,114 @@ if ($_GET['action'] == 'create' || $_POST['action'] == 'confirm_paiement' || $_P
|
|||||||
print '<td align="right"> </td>';
|
print '<td align="right"> </td>';
|
||||||
print "</tr>\n";
|
print "</tr>\n";
|
||||||
|
|
||||||
|
// FIXME Does not work yet because :
|
||||||
|
// - Does not support non , and non . decimal separator.
|
||||||
|
// - Does not use dolibarr param rounding
|
||||||
|
// - Other minor bugs
|
||||||
|
if (! empty($conf->global->MAIN_JS_ON_PAYMENT))
|
||||||
|
{
|
||||||
|
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;
|
$var=True;
|
||||||
$total=0;
|
$total=0;
|
||||||
$totalrecu=0;
|
$totalrecu=0;
|
||||||
@ -405,18 +545,32 @@ if ($_GET['action'] == 'create' || $_POST['action'] == 'confirm_paiement' || $_P
|
|||||||
|
|
||||||
// Remain to pay
|
// Remain to pay
|
||||||
print '<td align="right">'.price($remaintopay).'</td>';
|
print '<td align="right">'.price($remaintopay).'</td>';
|
||||||
|
$test= price(price2num($objp->total_ttc - $paiement - $creditnotes - $deposits));
|
||||||
|
|
||||||
// Amount
|
// Amount
|
||||||
print '<td align="right">';
|
print '<td align="right">';
|
||||||
|
|
||||||
|
// Add remind amount
|
||||||
|
$namef = 'amount_'.$objp->facid;
|
||||||
|
|
||||||
$namef = 'amount_'.$objp->facid;
|
$namef = 'amount_'.$objp->facid;
|
||||||
if ($_POST["action"] != 'add_paiement')
|
if ($_POST["action"] != 'add_paiement')
|
||||||
{
|
{
|
||||||
print '<input type="text" size="8" name="'.$namef.'" value="'.$_POST[$namef].'">';
|
if (! empty($conf->global->MAIN_JS_ON_PAYMENT))
|
||||||
|
{
|
||||||
|
print img_picto($langs->trans('AddRemind'),'rightarrow.png','id="calcRemind'.$i.'" onclick="calcRemind(\''.$i.'\');return false;"');
|
||||||
|
print '<script type="text/javascript" language="javascript">';
|
||||||
|
print 'amountInput.push(new Array("'.$namef.'","'.price(price2num($objp->total_ttc - $paiement - $creditnotes - $deposits)).'","0"));'; // Push a new Array into the amountInput Array
|
||||||
|
print 'jQuery(document).ready(function () {';
|
||||||
|
print 'jQuery("#'.$namef.'").keyup(function() { changeAmount('.$i.'); });';
|
||||||
|
print '});</script>';
|
||||||
|
}
|
||||||
|
print '<input id="'.$namef.'" type="text" size="8" name="'.$namef.'" value="'.$_POST[$namef].'">';
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
print '<input type="text" size="8" name="'.$namef.'_disabled" value="'.$_POST[$namef].'" disabled="true">';
|
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 id="'.$namef.'" type="hidden" name="'.$namef.'" value="'.$_POST[$namef].'">';
|
||||||
}
|
}
|
||||||
print "</td>";
|
print "</td>";
|
||||||
|
|
||||||
@ -449,7 +603,7 @@ if ($_GET['action'] == 'create' || $_POST['action'] == 'confirm_paiement' || $_P
|
|||||||
if ($totalrecudeposits) print '+'.price($totalrecudeposits);
|
if ($totalrecudeposits) print '+'.price($totalrecudeposits);
|
||||||
print '</b></td>';
|
print '</b></td>';
|
||||||
print '<td align="right"><b>'.price(price2num($total_ttc - $totalrecu - $totalrecucreditnote - $totalrecudeposits,'MT')).'</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 '<td align="center"> </td>';
|
||||||
print "</tr>\n";
|
print "</tr>\n";
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user