diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php
index beebe3cb561..85b4e3bb728 100644
--- a/htdocs/compta/facture/card.php
+++ b/htdocs/compta/facture/card.php
@@ -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 '
';
+ }
+
// Create payment
if ($object->type != Facture::TYPE_CREDIT_NOTE && $object->statut == 1 && $object->paye == 0 && $usercanissuepayment) {
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 '';
- }
-
// 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))
|| ($object->type == Facture::TYPE_DEPOSIT && $object->paye == 0 && $object->total_ttc > 0 && $resteapayer == 0 && $usercanissuepayment && empty($discount->id))
diff --git a/htdocs/compta/paiement.php b/htdocs/compta/paiement.php
index 336b306fff1..ab141f028bd 100644
--- a/htdocs/compta/paiement.php
+++ b/htdocs/compta/paiement.php
@@ -222,19 +222,26 @@ if (empty($reshook))
if ($socid > 0) $thirdparty->fetch($socid);
// 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
- {
- $newvalue = price2num($value, 'MT');
- $amounts[$key] = -$newvalue;
- }
+ $tmpinvoice = new Facture($db);
+ $tmpinvoice->fetch($key);
+ if ($tmpinvoice->type == Facture::TYPE_CREDIT_NOTE)
+ {
+ $newvalue = price2num($value, 'MT');
+ $amounts[$key] = - abs($newvalue);
+ }
+ }
- foreach ($multicurrency_amounts as $key => $value) // How payment is dispatch
- {
- $newvalue = price2num($value, 'MT');
- $multicurrency_amounts[$key] = -$newvalue;
- }
+ 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');
+ $multicurrency_amounts[$key] = - abs($newvalue);
+ }
}
if (! empty($conf->banque->enabled))
@@ -544,7 +551,7 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
}
$sql.= ') AND f.paye = 0';
$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
}
@@ -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
}
-
// Sort invoices by date and serial number: the older one comes first
$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);
if ($num > 0)
{
- $sign=1;
- if ($facture->type == 2) $sign=-1;
-
$arraytitle=$langs->trans('Invoice');
if ($facture->type == 2) $arraytitle=$langs->trans("CreditNotes");
$alreadypayedlabel=$langs->trans('Received');
@@ -606,6 +609,9 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
{
$objp = $db->fetch_object($resql);
+ $sign=1;
+ if ($facture->type == Facture::TYPE_CREDIT_NOTE) $sign=-1;
+
$soc = new Societe($db);
$soc->fetch($objp->socid);
@@ -631,7 +637,7 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
print '';
print $invoice->getNomUrl(1, '');
- if($objp->socid != $facture->thirdparty->id) print ' - '.$soc->getNomUrl(1).' ';
+ if ($objp->socid != $facture->thirdparty->id) print ' - '.$soc->getNomUrl(1).' ';
print " | \n";
// Date
diff --git a/htdocs/fourn/facture/paiement.php b/htdocs/fourn/facture/paiement.php
index aa24196ec2f..a84acde6e04 100644
--- a/htdocs/fourn/facture/paiement.php
+++ b/htdocs/fourn/facture/paiement.php
@@ -251,21 +251,32 @@ if (empty($reshook))
$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
- 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');
- $amounts[$key] = -$newvalue;
- }
-
- foreach ($multicurrency_amounts as $key => $value) // How payment is dispatch
- {
- $newvalue = price2num($value, 'MT');
- $multicurrency_amounts[$key] = -$newvalue;
+ $amounts[$key] = - abs($newvalue);
}
}
+ 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');
+ $multicurrency_amounts[$key] = - abs($newvalue);
+ }
+ }
+
+ //var_dump($amounts);
+ //var_dump($multicurrency_amounts);
+ //exit;
+
if (! $error)
{
$db->begin();
@@ -491,26 +502,35 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
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.= ' SUM(pf.amount) as am, SUM(pf.multicurrency_amount) as multicurrency_am, f.date_lim_reglement as dlr';
+ $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';
$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.= " WHERE f.entity = ".$conf->entity;
$sql.= ' AND f.fk_soc = '.$object->socid;
$sql.= ' AND f.paye = 0';
$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);
if ($resql)
{
$num = $db->num_rows($resql);
if ($num > 0)
{
- $sign=1;
- if ($object->type == 2) $sign=-1;
-
$i = 0;
print '
';
@@ -551,8 +571,15 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
{
$objp = $db->fetch_object($resql);
+ $sign=1;
+ if ($objp->type == FactureFournisseur::TYPE_CREDIT_NOTE) $sign=-1;
+
$invoice=new FactureFournisseur($db);
$invoice->fetch($objp->facid);
+
+ $invoicesupplierstatic->ref=$objp->ref;
+ $invoicesupplierstatic->id=$objp->facid;
+
$paiement = $invoice->getSommePaiement();
$creditnotes=$invoice->getSumCreditNotesUsed();
$deposits=$invoice->getSumDepositsUsed();
@@ -572,9 +599,7 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
print '';
// Ref
- print '| ';
- $invoicesupplierstatic->ref=$objp->ref;
- $invoicesupplierstatic->id=$objp->facid;
+ print ' | ';
print $invoicesupplierstatic->getNomUrl(1);
print ' | ';
@@ -582,7 +607,7 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
print ''.$objp->ref_supplier.' | ';
// Date
- if ($objp->df > 0 )
+ if ($objp->df > 0)
{
print '';
print dol_print_date($db->jdate($objp->df), 'day').' | ';
@@ -593,7 +618,7 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
}
// Date Max Payment
- if ($objp->dlr > 0 )
+ if ($objp->dlr > 0)
{
print '';
print dol_print_date($db->jdate($objp->dlr), 'day');
@@ -648,7 +673,7 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
print ' | '.price($sign * $remaintopay).' | ';
// Amount
- print '';
+ print ' | ';
$namef = 'amount_'.$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 ' | | ';
if (!empty($conf->multicurrency->enabled)) print ' | ';
if (!empty($conf->multicurrency->enabled)) print ' | ';
- print ''.price($total_ttc).' | ';
- print ''.price($totalrecu);
+ print ' | '.price($sign * $total_ttc).' | ';
+ print ''.price($sign * $totalrecu);
if ($totalrecucreditnote) print '+'.price($totalrecucreditnote);
if ($totalrecudeposits) print '+'.price($totalrecudeposits);
print ' | ';
- print ''.price(price2num($total_ttc - $totalrecu - $totalrecucreditnote - $totalrecudeposits, 'MT')).' | ';
+ print ''.price($sign * price2num($total_ttc - $totalrecu - $totalrecucreditnote - $totalrecudeposits, 'MT')).' | ';
print ' | '; // Autofilled
if (!empty($conf->multicurrency->enabled)) print ' | ';
print "
\n";
@@ -936,11 +961,11 @@ if (empty($action) || $action == 'list')
print_liste_field_titre("Account", $_SERVER["PHP_SELF"], 'ba.label', '', $param, '', $sortfield, $sortorder);
}
print_liste_field_titre("Amount", $_SERVER["PHP_SELF"], 'p.amount', '', $param, '', $sortfield, $sortorder, 'right ');
-
+
$parameters=array('arrayfields'=>$arrayfields,'param'=>$param,'sortfield'=>$sortfield,'sortorder'=>$sortorder);
$reshook=$hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint;
-
+
print_liste_field_titre('', $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'maxwidthsearch ');
print "\n";
@@ -955,29 +980,29 @@ if (empty($action) || $action == 'list')
// Ref payment
print ''.img_object($langs->trans('ShowPayment'), 'payment').' '.$objp->pid.' | ';
if (! $i) $totalarray['nbfield']++;
-
+
// Date
$dateformatforpayment = 'day';
if (! empty($conf->global->INVOICE_USE_HOURS_FOR_PAYMENT)) $dateformatforpayment='dayhour';
print ''.dol_print_date($db->jdate($objp->dp), $dateformatforpayment)." | \n";
if (! $i) $totalarray['nbfield']++;
-
+
// Thirdparty
print '';
if ($objp->socid) print ''.img_object($langs->trans('ShowCompany'), 'company').' '.dol_trunc($objp->name, 32).'';
else print ' ';
print ' | ';
if (! $i) $totalarray['nbfield']++;
-
+
// Type
$payment_type = $langs->trans("PaymentType".$objp->paiement_type)!=("PaymentType".$objp->paiement_type)?$langs->trans("PaymentType".$objp->paiement_type):$objp->paiement_libelle;
print ''.$payment_type.' '.dol_trunc($objp->num_paiement, 32)." | \n";
if (! $i) $totalarray['nbfield']++;
-
+
// Payment number
print ''.$objp->num_paiement.' | ';
if (! $i) $totalarray['nbfield']++;
-
+
// Account
if (! empty($conf->banque->enabled))
{
@@ -987,13 +1012,13 @@ if (empty($action) || $action == 'list')
print '';
if (! $i) $totalarray['nbfield']++;
}
-
+
// Amount
print ''.price($objp->pamount).' | ';
if (! $i) $totalarray['nbfield']++;
$totalarray['pos'][7]='amount';
$totalarray['val']['amount'] += $objp->pamount;
-
+
// Ref invoice
/*$invoicesupplierstatic->ref=$objp->ref_supplier;
$invoicesupplierstatic->id=$objp->facid;
@@ -1003,11 +1028,11 @@ if (empty($action) || $action == 'list')
print ' | ';
if (! $i) $totalarray['nbfield']++;
-
+
print '';
$i++;
}
-
+
// Show total line
if (isset($totalarray['pos']))
{
@@ -1029,7 +1054,7 @@ if (empty($action) || $action == 'list')
}
print '';
}
-
+
print "";
print "";
print "\n";
diff --git a/htdocs/langs/en_US/cashdesk.lang b/htdocs/langs/en_US/cashdesk.lang
index f0e2d029878..8ba3bda053f 100644
--- a/htdocs/langs/en_US/cashdesk.lang
+++ b/htdocs/langs/en_US/cashdesk.lang
@@ -66,4 +66,5 @@ History=History
ValidateAndClose=Validate and close
Terminal=Terminal
NumberOfTerminals=Number of Terminals
-TerminalSelect=Select terminal you want to use:
\ No newline at end of file
+TerminalSelect=Select terminal you want to use:
+POSTicket=POS Ticket
\ No newline at end of file