|
@@ -214,7 +214,7 @@ if (empty($reshook))
|
|
|
setEventMessages($langs->transnoentities('ErrorFieldRequired',$langs->transnoentities('Date')), null, 'errors');
|
|
|
$error++;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// Check if payments in both currency
|
|
|
if ($totalpayment > 0 && $multicurrency_totalpayment > 0)
|
|
|
{
|
|
@@ -320,7 +320,7 @@ $form=new Form($db);
|
|
|
if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paiement')
|
|
|
{
|
|
|
$object = new FactureFournisseur($db);
|
|
|
- $object->fetch($facid);
|
|
|
+ $result = $object->fetch($facid);
|
|
|
|
|
|
$datefacture=dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear'));
|
|
|
$dateinvoice=($datefacture==''?(empty($conf->global->MAIN_AUTOFILL_DATE)?-1:''):$datefacture);
|
|
@@ -341,9 +341,83 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
|
|
|
{
|
|
|
$obj = $db->fetch_object($resql);
|
|
|
$total = $obj->total;
|
|
|
-
|
|
|
+
|
|
|
print load_fiche_titre($langs->trans('DoPayment'));
|
|
|
|
|
|
+ // Add realtime total information
|
|
|
+ if (! empty($conf->use_javascript_ajax))
|
|
|
+ {
|
|
|
+ print "\n".'<script type="text/javascript" language="javascript">';
|
|
|
+ print '$(document).ready(function () {
|
|
|
+
|
|
|
+ function _elemToJson(selector)
|
|
|
+ {
|
|
|
+ var subJson = {};
|
|
|
+ $.map(selector.serializeArray(), function(n,i)
|
|
|
+ {
|
|
|
+ subJson[n["name"]] = n["value"];
|
|
|
+ });
|
|
|
+
|
|
|
+ return subJson;
|
|
|
+ }
|
|
|
+ function callForResult(imgId)
|
|
|
+ {
|
|
|
+ var json = {};
|
|
|
+ var form = $("#payment_form");
|
|
|
+
|
|
|
+ json["invoice_type"] = $("#invoice_type").val();
|
|
|
+ json["amountPayment"] = $("#amountpayment").attr("value");
|
|
|
+ json["amounts"] = _elemToJson(form.find("input.amount"));
|
|
|
+ json["remains"] = _elemToJson(form.find("input.remain"));
|
|
|
+
|
|
|
+ if (imgId != null) {
|
|
|
+ json["imgClicked"] = imgId;
|
|
|
+ }
|
|
|
+
|
|
|
+ $.post("'.DOL_URL_ROOT.'/compta/ajaxpayment.php", json, function(data)
|
|
|
+ {
|
|
|
+ json = $.parseJSON(data);
|
|
|
+
|
|
|
+ form.data(json);
|
|
|
+
|
|
|
+ for (var key in json)
|
|
|
+ {
|
|
|
+ if (key == "result") {
|
|
|
+ if (json["makeRed"]) {
|
|
|
+ $("#"+key).addClass("error");
|
|
|
+ } else {
|
|
|
+ $("#"+key).removeClass("error");
|
|
|
+ }
|
|
|
+ json[key]=json["label"]+" "+json[key];
|
|
|
+ $("#"+key).text(json[key]);
|
|
|
+ } else {console.log(key);
|
|
|
+ form.find("input[name*=\""+key+"\"]").each(function() {
|
|
|
+ $(this).attr("value", json[key]);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ $("#payment_form").find("input.amount").change(function() {
|
|
|
+ callForResult();
|
|
|
+ });
|
|
|
+ $("#payment_form").find("input.amount").keyup(function() {
|
|
|
+ callForResult();
|
|
|
+ });
|
|
|
+ ';
|
|
|
+
|
|
|
+ print ' });'."\n";
|
|
|
+
|
|
|
+ //Add js for AutoFill
|
|
|
+ print ' $(document).ready(function () {';
|
|
|
+ print ' $(".AutoFillAmout").on(\'click touchstart\', function(){
|
|
|
+ $("input[name="+$(this).data(\'rowname\')+"]").val($(this).data("value")).trigger("change");
|
|
|
+ });';
|
|
|
+ print ' });'."\n";
|
|
|
+
|
|
|
+ print ' </script>'."\n";
|
|
|
+ }
|
|
|
+
|
|
|
print '<form id="payment_form" name="addpaiement" action="'.$_SERVER["PHP_SELF"].'" method="POST">';
|
|
|
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
|
|
print '<input type="hidden" name="action" value="add_paiement">';
|
|
@@ -353,7 +427,7 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
|
|
|
print '<input type="hidden" name="societe" value="'.$obj->name.'">';
|
|
|
|
|
|
dol_fiche_head(null);
|
|
|
-
|
|
|
+
|
|
|
print '<table class="border" width="100%">';
|
|
|
|
|
|
print '<tr><td class="fieldrequired titlefieldcreate">'.$langs->trans('Company').'</td><td>';
|
|
@@ -384,7 +458,7 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
|
|
|
print '</table>';
|
|
|
dol_fiche_end();
|
|
|
|
|
|
-
|
|
|
+
|
|
|
$parameters=array('facid'=>$facid, 'ref'=>$ref, 'objcanvas'=>$objcanvas);
|
|
|
$reshook=$hookmanager->executeHooks('paymentsupplierinvoices',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
|
|
|
$error=$hookmanager->error; $errors=$hookmanager->errors;
|
|
@@ -408,6 +482,9 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
|
|
|
$num = $db->num_rows($resql);
|
|
|
if ($num > 0)
|
|
|
{
|
|
|
+ $sign=1;
|
|
|
+ if ($object->type == 2) $sign=-1;
|
|
|
+
|
|
|
$i = 0;
|
|
|
print '<br>';
|
|
|
|
|
@@ -447,19 +524,37 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
|
|
|
while ($i < $num)
|
|
|
{
|
|
|
$objp = $db->fetch_object($resql);
|
|
|
-
|
|
|
+
|
|
|
+ $invoice=new FactureFournisseur($db);
|
|
|
+ $invoice->fetch($objp->facid);
|
|
|
+ $paiement = $invoice->getSommePaiement();
|
|
|
+ $creditnotes=$invoice->getSumCreditNotesUsed();
|
|
|
+ $deposits=$invoice->getSumDepositsUsed();
|
|
|
+ $alreadypayed=price2num($paiement + $creditnotes + $deposits,'MT');
|
|
|
+ $remaintopay=price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits,'MT');
|
|
|
+
|
|
|
+ // Multicurrency Price
|
|
|
+ if (!empty($conf->multicurrency->enabled))
|
|
|
+ {
|
|
|
+ $multicurrency_payment = $invoice->getSommePaiement(1);
|
|
|
+ $multicurrency_creditnotes=$invoice->getSumCreditNotesUsed(1);
|
|
|
+ $multicurrency_deposits=$invoice->getSumDepositsUsed(1);
|
|
|
+ $multicurrency_alreadypayed=price2num($multicurrency_payment + $multicurrency_creditnotes + $multicurrency_deposits,'MT');
|
|
|
+ $multicurrency_remaintopay=price2num($invoice->multicurrency_total_ttc - $multicurrency_payment - $multicurrency_creditnotes - $multicurrency_deposits,'MT');
|
|
|
+ }
|
|
|
+
|
|
|
print '<tr class="oddeven">';
|
|
|
-
|
|
|
+
|
|
|
// Ref
|
|
|
print '<td>';
|
|
|
$invoicesupplierstatic->ref=$objp->ref;
|
|
|
$invoicesupplierstatic->id=$objp->facid;
|
|
|
print $invoicesupplierstatic->getNomUrl(1);
|
|
|
print '</td>';
|
|
|
-
|
|
|
+
|
|
|
// Ref supplier
|
|
|
print '<td>'.$objp->ref_supplier.'</td>';
|
|
|
-
|
|
|
+
|
|
|
// Date
|
|
|
if ($objp->df > 0 )
|
|
|
{
|
|
@@ -470,13 +565,13 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
|
|
|
{
|
|
|
print '<td align="center"><b>!!!</b></td>';
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// Multicurrency
|
|
|
- if (!empty($conf->multicurrency->enabled))
|
|
|
+ if (!empty($conf->multicurrency->enabled))
|
|
|
{
|
|
|
// Currency
|
|
|
print '<td align="center">'.$objp->multicurrency_code."</td>\n";
|
|
|
-
|
|
|
+
|
|
|
print '<td align="right">';
|
|
|
if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency)
|
|
|
{
|
|
@@ -485,14 +580,14 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
|
|
|
print '</td>';
|
|
|
|
|
|
print '<td align="right">';
|
|
|
- if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency)
|
|
|
- {
|
|
|
+ if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency)
|
|
|
+ {
|
|
|
print price($objp->multicurrency_am);
|
|
|
}
|
|
|
print '</td>';
|
|
|
-
|
|
|
+
|
|
|
print '<td align="right">';
|
|
|
- if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency)
|
|
|
+ if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency)
|
|
|
{
|
|
|
print price($objp->multicurrency_total_ttc - $objp->multicurrency_am);
|
|
|
}
|
|
@@ -500,32 +595,58 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
|
|
|
}
|
|
|
|
|
|
print '<td align="right">'.price($objp->total_ttc).'</td>';
|
|
|
-
|
|
|
+
|
|
|
print '<td align="right">'.price($objp->am).'</td>';
|
|
|
-
|
|
|
- print '<td align="right">'.price($objp->total_ttc - $objp->am).'</td>';
|
|
|
-
|
|
|
+
|
|
|
+ print '<td align="right">'.price($remaintopay).'</td>';
|
|
|
+
|
|
|
+ // Amount
|
|
|
print '<td align="center">';
|
|
|
+
|
|
|
$namef = 'amount_'.$objp->facid;
|
|
|
- if (!empty($conf->use_javascript_ajax))
|
|
|
- print img_picto("Auto fill",'rightarrow', "class='AutoFillAmout' data-rowname='".$namef."' data-value='".($objp->total_ttc - $objp->am)."'");
|
|
|
- print '<input type="text" size="8" name="'.$namef.'" value="'.GETPOST($namef).'">';
|
|
|
+ $nameRemain = 'remain_'.$objp->facid;
|
|
|
+
|
|
|
+ if ($action != 'add_paiement')
|
|
|
+ {
|
|
|
+ if (!empty($conf->use_javascript_ajax))
|
|
|
+ print img_picto("Auto fill",'rightarrow', "class='AutoFillAmout' data-rowname='".$namef."' data-value='".($sign * $remaintopay)."'");
|
|
|
+ print '<input type="hidden" class="remain" name="'.$nameRemain.'" value="'.$remaintopay.'">';
|
|
|
+ print '<input type="text" size="8" class="amount" name="'.$namef.'" value="'.dol_escape_htmltag(GETPOST($namef)).'">';
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ print '<input type="text" size="8" name="'.$namef.'_disabled" value="'.dol_escape_htmltag(GETPOST($namef)).'" disabled>';
|
|
|
+ print '<input type="hidden" name="'.$namef.'" value="'.dol_escape_htmltag(GETPOST($namef)).'">';
|
|
|
+ }
|
|
|
print "</td>";
|
|
|
-
|
|
|
- // Multicurrency
|
|
|
- if (!empty($conf->multicurrency->enabled))
|
|
|
+
|
|
|
+ // Multicurrency Price
|
|
|
+ if (! empty($conf->multicurrency->enabled))
|
|
|
{
|
|
|
- print '<td align="center">';
|
|
|
+ print '<td align="right">';
|
|
|
+
|
|
|
+ // Add remind multicurrency amount
|
|
|
+ $namef = 'multicurrency_amount_'.$objp->facid;
|
|
|
+ $nameRemain = 'multicurrency_remain_'.$objp->facid;
|
|
|
+
|
|
|
if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency)
|
|
|
{
|
|
|
- $namef = 'multicurrency_amount_'.$objp->facid;
|
|
|
- if (!empty($conf->use_javascript_ajax))
|
|
|
- print img_picto("Auto fill",'rightarrow', "class='AutoFillAmout' data-rowname='".$namef."' data-value='".($objp->multicurrency_total_ttc - $objp->multicurrency_am)."'");
|
|
|
- print '<input type="text" size="8" class="multicurrency_amount" name="'.$namef.'" value="'.GETPOST($namef).'">';
|
|
|
+ if ($action != 'add_paiement')
|
|
|
+ {
|
|
|
+ if (!empty($conf->use_javascript_ajax))
|
|
|
+ print img_picto("Auto fill",'rightarrow', "class='AutoFillAmout' data-rowname='".$namef."' data-value='".($sign * $multicurrency_remaintopay)."'");
|
|
|
+ print '<input type=hidden class="multicurrency_remain" name="'.$nameRemain.'" value="'.$multicurrency_remaintopay.'">';
|
|
|
+ print '<input type="text" size="8" class="multicurrency_amount" name="'.$namef.'" value="'.$_POST[$namef].'">';
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ print '<input type="text" size="8" name="'.$namef.'_disabled" value="'.$_POST[$namef].'" disabled>';
|
|
|
+ print '<input type="hidden" name="'.$namef.'" value="'.$_POST[$namef].'">';
|
|
|
+ }
|
|
|
}
|
|
|
- print "</td>";
|
|
|
+ print "</td>";
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
print "</tr>\n";
|
|
|
$total+=$objp->total_ht;
|
|
|
$total_ttc+=$objp->total_ttc;
|
|
@@ -544,12 +665,12 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
|
|
|
print '<td align="right"><b>'.price($total_ttc).'</b></td>';
|
|
|
print '<td align="right"><b>'.price($totalrecu).'</b></td>';
|
|
|
print '<td align="right"><b>'.price($total_ttc - $totalrecu).'</b></td>';
|
|
|
- print '<td align="center"> </td>';
|
|
|
- if (!empty($conf->multicurrency->enabled)) print '<td> </td>';
|
|
|
+ print '<td align="center" id="result" style="font-weight: bold;"></td>'; // Autofilled
|
|
|
+ if (!empty($conf->multicurrency->enabled)) print '<td align="right" id="multicurrency_result" style="font-weight: bold;"></td>';
|
|
|
print "</tr>\n";
|
|
|
}
|
|
|
print "</table>\n";
|
|
|
-
|
|
|
+
|
|
|
print "</div>";
|
|
|
}
|
|
|
$db->free($resql);
|
|
@@ -574,7 +695,7 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
|
|
|
|
|
|
print '<br>';
|
|
|
if (!empty($totalpayment)) $text=$langs->trans('ConfirmSupplierPayment',price($totalpayment),$langs->trans("Currency".$conf->currency));
|
|
|
- if (!empty($multicurrency_totalpayment))
|
|
|
+ if (!empty($multicurrency_totalpayment))
|
|
|
{
|
|
|
$text.='<br>'.$langs->trans('ConfirmSupplierPayment',price($multicurrency_totalpayment),$langs->trans("paymentInInvoiceCurrency"));
|
|
|
}
|
|
@@ -589,7 +710,7 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
|
|
|
print '</form>';
|
|
|
}
|
|
|
}
|
|
|
- else dol_print_error($db);
|
|
|
+ else dol_print_error($db);
|
|
|
}
|
|
|
|
|
|
/*
|
|
@@ -635,14 +756,14 @@ if (empty($action))
|
|
|
$sql.= " GROUP BY p.rowid, p.datep, p.amount, p.num_paiement, s.rowid, s.nom, c.code, c.libelle, ba.rowid, ba.label";
|
|
|
if (!$user->rights->societe->client->voir) $sql .= ", sc.fk_soc, sc.fk_user";
|
|
|
$sql.= $db->order($sortfield,$sortorder);
|
|
|
-
|
|
|
+
|
|
|
$nbtotalofrecords = '';
|
|
|
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
|
|
|
{
|
|
|
$result = $db->query($sql);
|
|
|
$nbtotalofrecords = $db->num_rows($result);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
$sql.= $db->plimit($limit+1, $offset);
|
|
|
|
|
|
$resql = $db->query($sql);
|
|
@@ -667,9 +788,9 @@ if (empty($action))
|
|
|
$tmpkey=preg_replace('/search_options_/','',$key);
|
|
|
if ($val != '') $param.='&search_options_'.$tmpkey.'='.urlencode($val);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
$massactionbutton=$form->selectMassAction('', $massaction == 'presend' ? array() : array('presend'=>$langs->trans("SendByMail"), 'builddoc'=>$langs->trans("PDFMerge")));
|
|
|
-
|
|
|
+
|
|
|
print_barre_liste($langs->trans('SupplierPayments'), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_accountancy.png', 0, '', '', $limit);
|
|
|
|
|
|
print '<form method="GET" action="'.$_SERVER["PHP_SELF"].'">';
|
|
@@ -680,24 +801,24 @@ if (empty($action))
|
|
|
print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
|
|
|
print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
|
|
|
print '<input type="hidden" name="page" value="'.$page.'">';
|
|
|
-
|
|
|
+
|
|
|
$moreforfilter='';
|
|
|
-
|
|
|
+
|
|
|
$parameters=array();
|
|
|
$reshook=$hookmanager->executeHooks('printFieldPreListTitle',$parameters); // Note that $action and $object may have been modified by hook
|
|
|
if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint;
|
|
|
else $moreforfilter = $hookmanager->resPrint;
|
|
|
-
|
|
|
+
|
|
|
if ($moreforfilter)
|
|
|
{
|
|
|
print '<div class="liste_titre liste_titre_bydiv centpercent">';
|
|
|
print $moreforfilter;
|
|
|
print '</div>';
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
$varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
|
|
|
$selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
|
|
|
-
|
|
|
+
|
|
|
print '<div class="div-table-responsive">';
|
|
|
print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
|
|
|
|
|
@@ -739,11 +860,11 @@ if (empty($action))
|
|
|
//print_liste_field_titre($langs->trans('Invoice'),$_SERVER["PHP_SELF"],'ref_supplier','',$param,'',$sortfield,$sortorder);
|
|
|
print_liste_field_titre('');
|
|
|
print "</tr>\n";
|
|
|
-
|
|
|
+
|
|
|
while ($i < min($num,$limit))
|
|
|
{
|
|
|
$objp = $db->fetch_object($resql);
|
|
|
-
|
|
|
+
|
|
|
print '<tr class="oddeven">';
|
|
|
|
|
|
// Ref payment
|
|
@@ -764,7 +885,7 @@ if (empty($action))
|
|
|
|
|
|
// Payment number
|
|
|
print '<td>'.$objp->num_paiement.'</td>';
|
|
|
-
|
|
|
+
|
|
|
print '<td>';
|
|
|
if ($objp->bid) print '<a href="'.DOL_URL_ROOT.'/compta/bank/bankentries.php?account='.$objp->bid.'">'.img_object($langs->trans("ShowAccount"),'account').' '.dol_trunc($objp->label,24).'</a>';
|
|
|
else print ' ';
|