Skip to content

Commit

Permalink
Fix autofill of amount on supplier payment page
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Jul 14, 2017
1 parent 1ad7210 commit e551c0a
Show file tree
Hide file tree
Showing 2 changed files with 206 additions and 85 deletions.
70 changes: 35 additions & 35 deletions htdocs/compta/paiement.php
Expand Up @@ -99,7 +99,7 @@
$atleastonepaymentnotnull = 0;

// Generate payment array and check if there is payment higher than invoice and payment date before invoice date
$tmpinvoice=new Facture($db);
$tmpinvoice=new Facture($db);
foreach ($_POST as $key => $value)
{
if (substr($key,0,7) == 'amount_')
Expand Down Expand Up @@ -188,7 +188,7 @@
setEventMessages($langs->transnoentities('ErrorFieldRequired',$langs->transnoentities('Date')), null, 'errors');
$error++;
}

// Check if payments in both currency
if ($totalpayment > 0 && $multicurrency_totalpayment > 0)
{
Expand Down Expand Up @@ -228,7 +228,7 @@
$newvalue = price2num($value,'MT');
$amounts[$key] = -$newvalue;
}

foreach ($multicurrency_amounts as $key => $value) // How payment is dispatch
{
$newvalue = price2num($value,'MT');
Expand Down Expand Up @@ -319,7 +319,7 @@
if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paiement')
{
$facture = new Facture($db);
$result=$facture->fetch($facid);
$result = $facture->fetch($facid);

if ($result >= 0)
{
Expand Down Expand Up @@ -389,7 +389,7 @@ function _elemToJson(selector)
{
subJson[n["name"]] = n["value"];
});
return subJson;
}
function callForResult(imgId)
Expand Down Expand Up @@ -516,31 +516,31 @@ function callForResult(imgId)
print '<tr><td>'.$langs->trans('Comments').'</td>';
print '<td class="tdtop">';
print '<textarea name="comment" wrap="soft" class="quatrevingtpercent" rows="'.ROWS_3.'">'.GETPOST('comment').'</textarea></td></tr>';

print '</table>';

dol_fiche_end();


/*
* List of unpaid invoices
*/

$sql = 'SELECT f.rowid as facid, f.facnumber, f.total_ttc, f.multicurrency_code, f.multicurrency_total_ttc, f.type, ';
$sql.= ' f.datef as df, f.fk_soc as socid';
$sql.= ' FROM '.MAIN_DB_PREFIX.'facture as f';

if(!empty($conf->global->FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS)) {
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON (f.fk_soc = s.rowid)';
}

$sql.= ' WHERE f.entity = '.$conf->entity;
$sql.= ' AND (f.fk_soc = '.$facture->socid;

if(!empty($conf->global->FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS) && !empty($facture->thirdparty->parent)) {
$sql.= ' OR f.fk_soc IN (SELECT rowid FROM '.MAIN_DB_PREFIX.'societe WHERE parent = '.$facture->thirdparty->parent.')';
}

$sql.= ') AND f.paye = 0';
$sql.= ' AND f.fk_statut = 1'; // Statut=0 => not validated, Statut=2 => canceled
if ($facture->type != 2)
Expand Down Expand Up @@ -577,7 +577,7 @@ function callForResult(imgId)
//print '<tr><td colspan="3">';
print '<br>';
print '<table class="noborder" width="100%">';

print '<tr class="liste_titre">';
print '<td>'.$arraytitle.'</td>';
print '<td align="center">'.$langs->trans('Date').'</td>';
Expand All @@ -602,7 +602,7 @@ function callForResult(imgId)
while ($i < $num)
{
$objp = $db->fetch_object($resql);


$soc = new Societe($db);
$soc->fetch($objp->socid);
Expand All @@ -614,17 +614,17 @@ function callForResult(imgId)
$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))
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">';

print '<td>';
Expand All @@ -634,36 +634,36 @@ function callForResult(imgId)

// Date
print '<td align="center">'.dol_print_date($db->jdate($objp->df),'day')."</td>\n";

// Currency
if (!empty($conf->multicurrency->enabled)) print '<td align="center">'.$objp->multicurrency_code."</td>\n";

// Multicurrency Price
if (!empty($conf->multicurrency->enabled))
if (!empty($conf->multicurrency->enabled))
{
print '<td align="right">';
if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency) print price($sign * $objp->multicurrency_total_ttc);
print '</td>';

// Multicurrency Price
print '<td align="right">';
if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency)
if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency)
{
print price($sign * $multicurrency_payment);
if ($multicurrency_creditnotes) print '+'.price($multicurrency_creditnotes);
if ($multicurrency_deposits) print '+'.price($multicurrency_deposits);
}
print '</td>';

// Multicurrency Price
print '<td align="right">';
if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency) print price($sign * $multicurrency_remaintopay);
print '</td>';
}

// Price
print '<td align="right">'.price($sign * $objp->total_ttc).'</td>';

// Received or paid back
print '<td align="right">'.price($sign * $paiement);
if ($creditnotes) print '+'.price($creditnotes);
Expand All @@ -685,7 +685,7 @@ function callForResult(imgId)
{
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="hidden" class="remain" name="'.$nameRemain.'" value="'.$remaintopay.'">';
print '<input type="text" size="8" class="amount" name="'.$namef.'" value="'.dol_escape_htmltag(GETPOST($namef)).'">';
}
else
Expand All @@ -696,14 +696,14 @@ function callForResult(imgId)
print "</td>";

// Multicurrency Price
if (! empty($conf->multicurrency->enabled))
if (! empty($conf->multicurrency->enabled))
{
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)
{
if ($action != 'add_paiement')
Expand All @@ -723,7 +723,7 @@ function callForResult(imgId)
}

// Warning
print '<td align="center" width="16">';
print '<td align="center" width="16">';
//print "xx".$amounts[$invoice->id]."-".$amountsresttopay[$invoice->id]."<br>";
if ($amounts[$invoice->id] && (abs($amounts[$invoice->id]) > abs($amountsresttopay[$invoice->id]))
|| $multicurrency_amounts[$invoice->id] && (abs($multicurrency_amounts[$invoice->id]) > abs($multicurrency_amountsresttopay[$invoice->id])))
Expand All @@ -744,7 +744,7 @@ function callForResult(imgId)
$totalrecudeposits+=$deposits;
$i++;
}

if ($i > 1)
{
// Print total
Expand All @@ -760,7 +760,7 @@ function callForResult(imgId)
if ($totalrecudeposits) print '+'.price($totalrecudeposits);
print '</b></td>';
print '<td align="right"><b>'.price($sign * price2num($total_ttc - $totalrecu - $totalrecucreditnote - $totalrecudeposits,'MT')).'</b></td>';
print '<td align="right" id="result" style="font-weight: bold;"></td>';
print '<td align="right" 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 '<td align="center">&nbsp;</td>';
print "</tr>\n";
Expand Down Expand Up @@ -802,9 +802,9 @@ function callForResult(imgId)

print '<br>';
if (!empty($totalpayment)) $text=$langs->trans('ConfirmCustomerPayment',$totalpayment,$langs->trans("Currency".$conf->currency));
if (!empty($multicurrency_totalpayment))
if (!empty($multicurrency_totalpayment))
{
$text.='<br />'.$langs->trans('ConfirmCustomerPayment',$multicurrency_totalpayment,$langs->trans("paymentInInvoiceCurrency"));
$text.='<br>'.$langs->trans('ConfirmCustomerPayment',$multicurrency_totalpayment,$langs->trans("paymentInInvoiceCurrency"));
}
if (GETPOST('closepaidinvoices'))
{
Expand Down Expand Up @@ -864,7 +864,7 @@ function callForResult(imgId)
while ($i < min($num,$limit))
{
$objp = $db->fetch_object($resql);

print '<tr class="oddeven">';
print '<td><a href="'.DOL_URL_ROOT.'/compta/facture/card.php?facid='.$objp->facid.'">'.$objp->facnumber."</a></td>\n";
print '<td>'.dol_print_date($db->jdate($objp->dp))."</td>\n";
Expand Down

0 comments on commit e551c0a

Please sign in to comment.