FIX Payment on supplier invoice should not mix credit note and standard
invoices.
This commit is contained in:
parent
49d65710ba
commit
9f8f45d5bc
@ -4656,6 +4656,14 @@ elseif ($id > 0 || ! empty($ref))
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// POS Ticket
|
||||||
|
if (! empty($conf->takepos->enabled) && $object->module_source == 'takepos')
|
||||||
|
{
|
||||||
|
$langs->load("cashdesk");
|
||||||
|
$receipt_url=DOL_URL_ROOT."/takepos/receipt.php";
|
||||||
|
print '<div class="inline-block divButAction"><a target="_blank" class="butAction" href="' . $receipt_url . '?facid=' . $object->id.'">' . $langs->trans('POSTicket') .'</a></div>';
|
||||||
|
}
|
||||||
|
|
||||||
// Create payment
|
// Create payment
|
||||||
if ($object->type != Facture::TYPE_CREDIT_NOTE && $object->statut == 1 && $object->paye == 0 && $usercanissuepayment) {
|
if ($object->type != Facture::TYPE_CREDIT_NOTE && $object->statut == 1 && $object->paye == 0 && $usercanissuepayment) {
|
||||||
if ($objectidnext) {
|
if ($objectidnext) {
|
||||||
@ -4700,13 +4708,6 @@ elseif ($id > 0 || ! empty($ref))
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// POS Ticket
|
|
||||||
if (! empty($conf->takepos->enabled) && $object->module_source != '')
|
|
||||||
{
|
|
||||||
$receipt_url=DOL_URL_ROOT."/takepos/receipt.php";
|
|
||||||
print '<div class="inline-block divButAction"><a target="_blank" class="butAction" href="' . $receipt_url . '?facid=' . $object->id.'">' . $langs->trans('POSTicket') .'</a></div>';
|
|
||||||
}
|
|
||||||
|
|
||||||
// Classify paid
|
// Classify paid
|
||||||
if ($object->statut == 1 && $object->paye == 0 && $usercanissuepayment && (($object->type != Facture::TYPE_CREDIT_NOTE && $object->type != Facture::TYPE_DEPOSIT && $resteapayer <= 0) || ($object->type == Facture::TYPE_CREDIT_NOTE && $resteapayer >= 0))
|
if ($object->statut == 1 && $object->paye == 0 && $usercanissuepayment && (($object->type != Facture::TYPE_CREDIT_NOTE && $object->type != Facture::TYPE_DEPOSIT && $resteapayer <= 0) || ($object->type == Facture::TYPE_CREDIT_NOTE && $resteapayer >= 0))
|
||||||
|| ($object->type == Facture::TYPE_DEPOSIT && $object->paye == 0 && $object->total_ttc > 0 && $resteapayer == 0 && $usercanissuepayment && empty($discount->id))
|
|| ($object->type == Facture::TYPE_DEPOSIT && $object->paye == 0 && $object->total_ttc > 0 && $resteapayer == 0 && $usercanissuepayment && empty($discount->id))
|
||||||
|
|||||||
@ -222,18 +222,25 @@ if (empty($reshook))
|
|||||||
if ($socid > 0) $thirdparty->fetch($socid);
|
if ($socid > 0) $thirdparty->fetch($socid);
|
||||||
|
|
||||||
// Clean parameters amount if payment is for a credit note
|
// Clean parameters amount if payment is for a credit note
|
||||||
if (GETPOST('type') == Facture::TYPE_CREDIT_NOTE)
|
foreach ($amounts as $key => $value) // How payment is dispatched
|
||||||
{
|
{
|
||||||
foreach ($amounts as $key => $value) // How payment is dispatch
|
$tmpinvoice = new Facture($db);
|
||||||
|
$tmpinvoice->fetch($key);
|
||||||
|
if ($tmpinvoice->type == Facture::TYPE_CREDIT_NOTE)
|
||||||
{
|
{
|
||||||
$newvalue = price2num($value, 'MT');
|
$newvalue = price2num($value, 'MT');
|
||||||
$amounts[$key] = -$newvalue;
|
$amounts[$key] = - abs($newvalue);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($multicurrency_amounts as $key => $value) // How payment is dispatch
|
foreach ($multicurrency_amounts as $key => $value) // How payment is dispatched
|
||||||
|
{
|
||||||
|
$tmpinvoice = new Facture($db);
|
||||||
|
$tmpinvoice->fetch($key);
|
||||||
|
if ($tmpinvoice->type == Facture::TYPE_CREDIT_NOTE)
|
||||||
{
|
{
|
||||||
$newvalue = price2num($value, 'MT');
|
$newvalue = price2num($value, 'MT');
|
||||||
$multicurrency_amounts[$key] = -$newvalue;
|
$multicurrency_amounts[$key] = - abs($newvalue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -544,7 +551,7 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
|
|||||||
}
|
}
|
||||||
$sql.= ') AND f.paye = 0';
|
$sql.= ') AND f.paye = 0';
|
||||||
$sql.= ' AND f.fk_statut = 1'; // Statut=0 => not validated, Statut=2 => canceled
|
$sql.= ' AND f.fk_statut = 1'; // Statut=0 => not validated, Statut=2 => canceled
|
||||||
if ($facture->type != 2)
|
if ($facture->type != Facture::TYPE_CREDIT_NOTE)
|
||||||
{
|
{
|
||||||
$sql .= ' AND type IN (0,1,3,5)'; // Standard invoice, replacement, deposit, situation
|
$sql .= ' AND type IN (0,1,3,5)'; // Standard invoice, replacement, deposit, situation
|
||||||
}
|
}
|
||||||
@ -552,7 +559,6 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
|
|||||||
{
|
{
|
||||||
$sql .= ' AND type = 2'; // If paying back a credit note, we show all credit notes
|
$sql .= ' AND type = 2'; // If paying back a credit note, we show all credit notes
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort invoices by date and serial number: the older one comes first
|
// Sort invoices by date and serial number: the older one comes first
|
||||||
$sql.=' ORDER BY f.datef ASC, f.ref ASC';
|
$sql.=' ORDER BY f.datef ASC, f.ref ASC';
|
||||||
|
|
||||||
@ -562,9 +568,6 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
|
|||||||
$num = $db->num_rows($resql);
|
$num = $db->num_rows($resql);
|
||||||
if ($num > 0)
|
if ($num > 0)
|
||||||
{
|
{
|
||||||
$sign=1;
|
|
||||||
if ($facture->type == 2) $sign=-1;
|
|
||||||
|
|
||||||
$arraytitle=$langs->trans('Invoice');
|
$arraytitle=$langs->trans('Invoice');
|
||||||
if ($facture->type == 2) $arraytitle=$langs->trans("CreditNotes");
|
if ($facture->type == 2) $arraytitle=$langs->trans("CreditNotes");
|
||||||
$alreadypayedlabel=$langs->trans('Received');
|
$alreadypayedlabel=$langs->trans('Received');
|
||||||
@ -606,6 +609,9 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
|
|||||||
{
|
{
|
||||||
$objp = $db->fetch_object($resql);
|
$objp = $db->fetch_object($resql);
|
||||||
|
|
||||||
|
$sign=1;
|
||||||
|
if ($facture->type == Facture::TYPE_CREDIT_NOTE) $sign=-1;
|
||||||
|
|
||||||
$soc = new Societe($db);
|
$soc = new Societe($db);
|
||||||
$soc->fetch($objp->socid);
|
$soc->fetch($objp->socid);
|
||||||
|
|
||||||
|
|||||||
@ -251,21 +251,32 @@ if (empty($reshook))
|
|||||||
$datepaye = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
|
$datepaye = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
|
||||||
|
|
||||||
// Clean parameters amount if payment is for a credit note
|
// Clean parameters amount if payment is for a credit note
|
||||||
if (GETPOST('type', 'int') == FactureFournisseur::TYPE_CREDIT_NOTE)
|
foreach ($amounts as $key => $value) // How payment is dispatched
|
||||||
{
|
{
|
||||||
foreach ($amounts as $key => $value) // How payment is dispatch
|
$tmpinvoice = new FactureFournisseur($db);
|
||||||
|
$tmpinvoice->fetch($key);
|
||||||
|
if ($tmpinvoice->type == FactureFournisseur::TYPE_CREDIT_NOTE)
|
||||||
{
|
{
|
||||||
$newvalue = price2num($value, 'MT');
|
$newvalue = price2num($value, 'MT');
|
||||||
$amounts[$key] = -$newvalue;
|
$amounts[$key] = - abs($newvalue);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($multicurrency_amounts as $key => $value) // How payment is dispatch
|
foreach ($multicurrency_amounts as $key => $value) // How payment is dispatched
|
||||||
|
{
|
||||||
|
$tmpinvoice = new FactureFournisseur($db);
|
||||||
|
$tmpinvoice->fetch($key);
|
||||||
|
if ($tmpinvoice->type == FactureFournisseur::TYPE_CREDIT_NOTE)
|
||||||
{
|
{
|
||||||
$newvalue = price2num($value, 'MT');
|
$newvalue = price2num($value, 'MT');
|
||||||
$multicurrency_amounts[$key] = -$newvalue;
|
$multicurrency_amounts[$key] = - abs($newvalue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//var_dump($amounts);
|
||||||
|
//var_dump($multicurrency_amounts);
|
||||||
|
//exit;
|
||||||
|
|
||||||
if (! $error)
|
if (! $error)
|
||||||
{
|
{
|
||||||
$db->begin();
|
$db->begin();
|
||||||
@ -491,26 +502,35 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
|
|||||||
if (empty($reshook))
|
if (empty($reshook))
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* Autres factures impayees
|
* All unpayed supplier invoices
|
||||||
*/
|
*/
|
||||||
$sql = 'SELECT f.rowid as facid, f.ref, f.ref_supplier, f.total_ht, f.total_ttc, f.multicurrency_total_ttc, f.datef as df,';
|
$sql = 'SELECT f.rowid as facid, f.ref, f.ref_supplier, f.type, f.total_ht, f.total_ttc, f.multicurrency_total_ttc, f.datef as df, f.date_lim_reglement as dlr,';
|
||||||
$sql.= ' SUM(pf.amount) as am, SUM(pf.multicurrency_amount) as multicurrency_am, f.date_lim_reglement as dlr';
|
$sql.= ' SUM(pf.amount) as am, SUM(pf.multicurrency_amount) as multicurrency_am';
|
||||||
$sql.= ' FROM '.MAIN_DB_PREFIX.'facture_fourn as f';
|
$sql.= ' FROM '.MAIN_DB_PREFIX.'facture_fourn as f';
|
||||||
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf ON pf.fk_facturefourn = f.rowid';
|
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf ON pf.fk_facturefourn = f.rowid';
|
||||||
$sql.= " WHERE f.entity = ".$conf->entity;
|
$sql.= " WHERE f.entity = ".$conf->entity;
|
||||||
$sql.= ' AND f.fk_soc = '.$object->socid;
|
$sql.= ' AND f.fk_soc = '.$object->socid;
|
||||||
$sql.= ' AND f.paye = 0';
|
$sql.= ' AND f.paye = 0';
|
||||||
$sql.= ' AND f.fk_statut = 1'; // Statut=0 => non validee, Statut=2 => annulee
|
$sql.= ' AND f.fk_statut = 1'; // Statut=0 => non validee, Statut=2 => annulee
|
||||||
$sql.= ' GROUP BY f.rowid, f.ref, f.ref_supplier, f.total_ht, f.total_ttc, f.multicurrency_total_ttc, f.datef, f.date_lim_reglement';
|
if ($object->type != FactureFournisseur::TYPE_CREDIT_NOTE)
|
||||||
|
{
|
||||||
|
$sql .= ' AND f.type IN (0,1,3,5)'; // Standard invoice, replacement, deposit, situation
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$sql .= ' AND f.type = 2'; // If paying back a credit note, we show all credit notes
|
||||||
|
}
|
||||||
|
// Group by because we have a total
|
||||||
|
$sql.= ' GROUP BY f.datef, f.ref, f.ref_supplier, f.rowid, f.type, f.total_ht, f.total_ttc, f.multicurrency_total_ttc, f.datef, f.date_lim_reglement';
|
||||||
|
// Sort invoices by date and serial number: the older one comes first
|
||||||
|
$sql.= ' ORDER BY f.datef ASC, f.ref ASC';
|
||||||
|
|
||||||
$resql = $db->query($sql);
|
$resql = $db->query($sql);
|
||||||
if ($resql)
|
if ($resql)
|
||||||
{
|
{
|
||||||
$num = $db->num_rows($resql);
|
$num = $db->num_rows($resql);
|
||||||
if ($num > 0)
|
if ($num > 0)
|
||||||
{
|
{
|
||||||
$sign=1;
|
|
||||||
if ($object->type == 2) $sign=-1;
|
|
||||||
|
|
||||||
$i = 0;
|
$i = 0;
|
||||||
print '<br>';
|
print '<br>';
|
||||||
|
|
||||||
@ -551,8 +571,15 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
|
|||||||
{
|
{
|
||||||
$objp = $db->fetch_object($resql);
|
$objp = $db->fetch_object($resql);
|
||||||
|
|
||||||
|
$sign=1;
|
||||||
|
if ($objp->type == FactureFournisseur::TYPE_CREDIT_NOTE) $sign=-1;
|
||||||
|
|
||||||
$invoice=new FactureFournisseur($db);
|
$invoice=new FactureFournisseur($db);
|
||||||
$invoice->fetch($objp->facid);
|
$invoice->fetch($objp->facid);
|
||||||
|
|
||||||
|
$invoicesupplierstatic->ref=$objp->ref;
|
||||||
|
$invoicesupplierstatic->id=$objp->facid;
|
||||||
|
|
||||||
$paiement = $invoice->getSommePaiement();
|
$paiement = $invoice->getSommePaiement();
|
||||||
$creditnotes=$invoice->getSumCreditNotesUsed();
|
$creditnotes=$invoice->getSumCreditNotesUsed();
|
||||||
$deposits=$invoice->getSumDepositsUsed();
|
$deposits=$invoice->getSumDepositsUsed();
|
||||||
@ -572,9 +599,7 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
|
|||||||
print '<tr class="oddeven">';
|
print '<tr class="oddeven">';
|
||||||
|
|
||||||
// Ref
|
// Ref
|
||||||
print '<td>';
|
print '<td class="nowraponall">';
|
||||||
$invoicesupplierstatic->ref=$objp->ref;
|
|
||||||
$invoicesupplierstatic->id=$objp->facid;
|
|
||||||
print $invoicesupplierstatic->getNomUrl(1);
|
print $invoicesupplierstatic->getNomUrl(1);
|
||||||
print '</td>';
|
print '</td>';
|
||||||
|
|
||||||
@ -648,7 +673,7 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
|
|||||||
print '<td class="right">'.price($sign * $remaintopay).'</td>';
|
print '<td class="right">'.price($sign * $remaintopay).'</td>';
|
||||||
|
|
||||||
// Amount
|
// Amount
|
||||||
print '<td class="center">';
|
print '<td class="center nowraponall">';
|
||||||
|
|
||||||
$namef = 'amount_'.$objp->facid;
|
$namef = 'amount_'.$objp->facid;
|
||||||
$nameRemain = 'remain_'.$objp->facid;
|
$nameRemain = 'remain_'.$objp->facid;
|
||||||
@ -711,12 +736,12 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
|
|||||||
if (!empty($conf->multicurrency->enabled)) print '<td> </td>';
|
if (!empty($conf->multicurrency->enabled)) print '<td> </td>';
|
||||||
if (!empty($conf->multicurrency->enabled)) print '<td> </td>';
|
if (!empty($conf->multicurrency->enabled)) print '<td> </td>';
|
||||||
if (!empty($conf->multicurrency->enabled)) print '<td> </td>';
|
if (!empty($conf->multicurrency->enabled)) print '<td> </td>';
|
||||||
print '<td class="right"><b>'.price($total_ttc).'</b></td>';
|
print '<td class="right"><b>'.price($sign * $total_ttc).'</b></td>';
|
||||||
print '<td class="right"><b>'.price($totalrecu);
|
print '<td class="right"><b>'.price($sign * $totalrecu);
|
||||||
if ($totalrecucreditnote) print '+'.price($totalrecucreditnote);
|
if ($totalrecucreditnote) print '+'.price($totalrecucreditnote);
|
||||||
if ($totalrecudeposits) print '+'.price($totalrecudeposits);
|
if ($totalrecudeposits) print '+'.price($totalrecudeposits);
|
||||||
print '</b></td>';
|
print '</b></td>';
|
||||||
print '<td class="right"><b>'.price(price2num($total_ttc - $totalrecu - $totalrecucreditnote - $totalrecudeposits, 'MT')).'</b></td>';
|
print '<td class="right"><b>'.price($sign * price2num($total_ttc - $totalrecu - $totalrecucreditnote - $totalrecudeposits, 'MT')).'</b></td>';
|
||||||
print '<td class="center" id="result" style="font-weight: bold;"></td>'; // Autofilled
|
print '<td class="center" id="result" style="font-weight: bold;"></td>'; // Autofilled
|
||||||
if (!empty($conf->multicurrency->enabled)) print '<td class="right" id="multicurrency_result" style="font-weight: bold;"></td>';
|
if (!empty($conf->multicurrency->enabled)) print '<td class="right" id="multicurrency_result" style="font-weight: bold;"></td>';
|
||||||
print "</tr>\n";
|
print "</tr>\n";
|
||||||
|
|||||||
@ -67,3 +67,4 @@ ValidateAndClose=Validate and close
|
|||||||
Terminal=Terminal
|
Terminal=Terminal
|
||||||
NumberOfTerminals=Number of Terminals
|
NumberOfTerminals=Number of Terminals
|
||||||
TerminalSelect=Select terminal you want to use:
|
TerminalSelect=Select terminal you want to use:
|
||||||
|
POSTicket=POS Ticket
|
||||||
Loading…
Reference in New Issue
Block a user