From 7990d7f018a115ee013203c3c354c3680993065a Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 27 Mar 2019 12:40:32 +0100 Subject: [PATCH 1/3] Use color on the amount of the payment page of TakePOS module FIX Use pricejs instead of toFixed to be compatible with all currencies WIP Prepare to be able to enter different payment modes on same invoice --- htdocs/core/js/lib_head.js.php | 19 +++++++ htdocs/takepos/css/pos.css | 10 +++- htdocs/takepos/invoice.php | 51 +++++++++++------- htdocs/takepos/pay.php | 95 ++++++++++++++++++++++++---------- htdocs/takepos/takepos.php | 6 +-- 5 files changed, 131 insertions(+), 50 deletions(-) diff --git a/htdocs/core/js/lib_head.js.php b/htdocs/core/js/lib_head.js.php index 6a16357f6fa..c81a365bfbc 100644 --- a/htdocs/core/js/lib_head.js.php +++ b/htdocs/core/js/lib_head.js.php @@ -1009,6 +1009,25 @@ function getParameterByName(name, valueifnotfound) function dolroundjs(number, decimals) { return +(Math.round(number + "e+" + decimals) + "e-" + decimals); } +/** + * Function similar to PHP price() + * + * @param {number|string} amount The amount to show + * @param {string} mode 'MT' or 'MU' + * @return {string} The amount with digits + */ +function pricejs(amount, mode) { + var main_max_dec_shown = global->MAIN_MAX_DECIMALS_SHOWN); ?>; + var main_rounding_unit = global->MAIN_MAX_DECIMALS_UNIT; ?>; + var main_rounding_tot = global->MAIN_MAX_DECIMALS_TOT; ?>; + + console.log(amount); + + if (mode == 'MU') return amount.toFixed(main_rounding_unit); + if (mode == 'MT') return amount.toFixed(main_rounding_tot); + return 'Bad value for parameter mode'; +} + /** * Function similar to PHP price2num() * diff --git a/htdocs/takepos/css/pos.css b/htdocs/takepos/css/pos.css index 086e4e5fcb0..4b90f712f1d 100644 --- a/htdocs/takepos/css/pos.css +++ b/htdocs/takepos/css/pos.css @@ -103,7 +103,6 @@ div.description{ width:100%; /* styling below */ background-color:black; - font-family: 'tahoma'; color:white; opacity:0.8; /* transparency */ filter:alpha(opacity=80); /* IE transparency */ @@ -209,6 +208,15 @@ div.catwatermark{ padding-left: 5px; } +.colorwhite { + color: white; +} +.colorred { + color: red; +} +.colorgreen { + color: green; +} p.description_content{ padding:10px; margin:0px; diff --git a/htdocs/takepos/invoice.php b/htdocs/takepos/invoice.php index 4d6299b3c0a..a0020ec1f41 100644 --- a/htdocs/takepos/invoice.php +++ b/htdocs/takepos/invoice.php @@ -36,10 +36,11 @@ $id = GETPOST('id', 'int'); $action = GETPOST('action', 'alpha'); $idproduct = GETPOST('idproduct', 'int'); $place = (GETPOSTISSET('place')?GETPOST('place', 'int'):0); // $place is id of POS -$number = GETPOST('number'); -$idline = GETPOST('idline'); +$number = GETPOST('number', 'alpha'); +$idline = GETPOST('idline', 'int'); $desc = GETPOST('desc', 'alpha'); -$pay = GETPOST('pay'); +$pay = GETPOST('pay', 'alpha'); +$amountofpayment = price2num(GETPOST('amount', 'alpha')); $placeid = 0; // $placeid is id of invoice @@ -48,28 +49,29 @@ $ret = $invoice->fetch('', '(PROV-POS-'.$place.')'); if ($ret > 0) $placeid = $invoice->id; $paycode = $pay; -if ($pay == 'cash') $paycode = 'LIQ'; -if ($pay == 'card') $paycode = 'CB'; -if ($pay == 'cheque') $paycode = 'CHQ'; - +if ($pay == 'cash') $paycode = 'LIQ'; // For backward compatibility +if ($pay == 'card') $paycode = 'CB'; // For backward compatibility +if ($pay == 'cheque') $paycode = 'CHQ'; // For backward compatibility + // Retrieve paiementid $sql = "SELECT id FROM ".MAIN_DB_PREFIX."c_paiement"; $sql.= " WHERE entity IN (".getEntity('c_paiement').")"; -$sql.= " AND code = '".$paycode."'"; +$sql.= " AND code = '".$db->escape($paycode)."'"; $resql = $db->query($sql); $codes = $db->fetch_array($resql); $paiementid=$codes[0]; + /* * Actions */ if ($action == 'valid' && $user->rights->facture->creer) { - if ($pay == "cash") $bankaccount = $conf->global->CASHDESK_ID_BANKACCOUNT_CASH; - elseif ($pay == "card") $bankaccount = $conf->global->CASHDESK_ID_BANKACCOUNT_CB; - elseif ($pay == "cheque") $bankaccount = $conf->global->CASHDESK_ID_BANKACCOUNT_CHEQUE; - else + if ($pay == "cash") $bankaccount = $conf->global->CASHDESK_ID_BANKACCOUNT_CASH; // For backward compatibility + elseif ($pay == "card") $bankaccount = $conf->global->CASHDESK_ID_BANKACCOUNT_CB; // For backward compatibility + elseif ($pay == "cheque") $bankaccount = $conf->global->CASHDESK_ID_BANKACCOUNT_CHEQUE; // For backward compatibility + else { $accountname="CASHDESK_ID_BANKACCOUNT_".$pay; $bankaccount=$conf->global->$accountname; @@ -79,22 +81,26 @@ if ($action == 'valid' && $user->rights->facture->creer) $invoice = new Facture($db); $invoice->fetch($placeid); - if (! empty($conf->stock->enabled) and $conf->global->CASHDESK_NO_DECREASE_STOCK!="1") $invoice->validate($user, '', $conf->global->CASHDESK_ID_WAREHOUSE); + if (! empty($conf->stock->enabled) && $conf->global->CASHDESK_NO_DECREASE_STOCK != "1") $invoice->validate($user, '', $conf->global->CASHDESK_ID_WAREHOUSE); else $invoice->validate($user); // Add the payment $payment=new Paiement($db); $payment->datepaye = $now; - $payment->bank_account = $bankaccount; - $payment->amounts[$invoice->id] = $invoice->total_ttc; + $payment->fk_account = $bankaccount; + $payment->amounts[$invoice->id] = $amountofpayment; $payment->paiementid=$paiementid; - $payment->num_paiement=$invoice->ref; + $payment->num_payment=$invoice->ref; $payment->create($user); $payment->addPaymentToBank($user, 'payment', '(CustomerInvoicePayment)', $bankaccount, '', ''); - $invoice->set_paid($user); + + if ($amountofpayment == $invoice->getRemainToPay()) + { + $invoice->set_paid($user); + } } if (($action=="addline" || $action=="freezone") && $placeid == 0) @@ -388,7 +394,16 @@ if ($invoice->socid != $conf->global->CASHDESK_ID_THIRDPARTY) } if ($action=="valid") { - print '

'.$invoice->ref." ".$langs->trans('BillShortStatusValidated').'

'; + print '

'; + if ($invoice->getRemainToPay() > 0) + { + print $invoice->getNomUrl(1)." ".$langs->trans('Generated'); + } + else + { + print $invoice->getNomUrl(1)." ".$langs->trans('BillShortStatusValidated'); + } + print '

'; if ($conf->global->TAKEPOSCONNECTOR) print '
'; else print '
'; if($conf->global->TAKEPOS_AUTO_PRINT_TICKETS) print ''; diff --git a/htdocs/takepos/pay.php b/htdocs/takepos/pay.php index a4c7f5680f6..81e2db34f3f 100644 --- a/htdocs/takepos/pay.php +++ b/htdocs/takepos/pay.php @@ -41,7 +41,7 @@ $sql="SELECT rowid FROM ".MAIN_DB_PREFIX."facture where ref='(PROV-POS-".$place. $resql = $db->query($sql); $row = $db->fetch_array($resql); $placeid=$row[0]; -if (! $placeid) $placeid=0; // Invoice not exist +if (! $placeid) $placeid=0; // Invoice does not exist yet else{ $invoice = new Facture($db); $invoice->fetch($placeid); @@ -51,7 +51,7 @@ top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss); $langs->loadLangs(array("main", "bills", "cashdesk")); -$sql = "SELECT code, libelle FROM ".MAIN_DB_PREFIX."c_paiement"; +$sql = "SELECT code, libelle as label FROM ".MAIN_DB_PREFIX."c_paiement"; $sql.= " WHERE entity IN (".getEntity('c_paiement').")"; $sql.= " AND active = 1"; $sql.= " ORDER BY libelle"; @@ -70,58 +70,97 @@ if ($resql) { } ?> - - - -
+
-
trans('TotalTTC');?>: total_ttc, 1, '', 1, - 1, - 1, $conf->currency) ?>
+
trans('TotalTTC');?>: total_ttc, 1, '', 1, -1, -1) ?>
-
trans("AlreadyPaid"); ?>:
+
trans("AlreadyPaid"); ?>:
-
trans("Change"); ?>:
+
trans("Change"); ?>:
-
+
global->TAKEPOS_NUMPAD; if ($paycode == 'CB') $paycode = 'card'; if ($paycode == 'CHQ') $paycode = 'cheque'; ?> - + @@ -159,7 +198,7 @@ $numpad=$conf->global->TAKEPOS_NUMPAD; if ($paycode == 'CB') $paycode = 'card'; if ($paycode == 'CHQ') $paycode = 'cheque'; ?> - + @@ -174,7 +213,7 @@ $button = array_pop($action_buttons); if ($paycode == 'CB') $paycode = 'card'; if ($paycode == 'CHQ') $paycode = 'cheque'; ?> - + - + global->$accountname) && $conf->global->$accountname > 0) array_push($paiementsModes, $obj); } @@ -484,7 +484,7 @@ $menus[$r++]=array('title'=>$langs->trans("FreeZone"), $menus[$r++]=array('title'=>$langs->trans("Customer"), 'action'=>'Customer();'); $menus[$r++]=array('title'=>$langs->trans("BackOffice"), - 'action'=>'window.open(\''.(DOL_URL_ROOT ? DOL_URL_ROOT : '/').'\', \'_self\');'); + 'action'=>'window.open(\''.(DOL_URL_ROOT ? DOL_URL_ROOT : '/').'\', \'_backoffice\');'); $menus[$r++]=array('title'=>$langs->trans("ValidateBill"), 'action'=>'CloseBill();'); $menus[$r++]=array('title'=>$langs->trans("Logout"), From 9a7e6ce178ada812b3dfd9c1caa2e0d1e0e18508 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 27 Mar 2019 15:42:53 +0100 Subject: [PATCH 2/3] TakePOS Can enter payment in several times and with different modes --- htdocs/compta/facture/class/facture.class.php | 9 ++- htdocs/core/js/lib_head.js.php | 2 - htdocs/takepos/invoice.php | 59 +++++++++++---- htdocs/takepos/pay.php | 74 +++++++++++++------ htdocs/takepos/takepos.php | 12 +-- 5 files changed, 108 insertions(+), 48 deletions(-) diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 15d985db6bf..2e299740290 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -1199,9 +1199,10 @@ class Facture extends CommonInvoice * @param int $notooltip 1=Disable tooltip * @param int $addlinktonotes 1=Add link to notes * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking + * @param string $target Target of link ('', '_self', '_blank', '_parent', '_backoffice', ...) * @return string String with URL */ - public function getNomUrl($withpicto = 0, $option = '', $max = 0, $short = 0, $moretitle = '', $notooltip = 0, $addlinktonotes = 0, $save_lastsearch_value = -1) + public function getNomUrl($withpicto = 0, $option = '', $max = 0, $short = 0, $moretitle = '', $notooltip = 0, $addlinktonotes = 0, $save_lastsearch_value = -1, $target = '') { global $langs, $conf, $user, $form; @@ -1254,7 +1255,7 @@ class Facture extends CommonInvoice if ($moretitle) $label.=' - '.$moretitle; } - $linkclose=''; + $linkclose=($target?' target="'.$target.'"':''); if (empty($notooltip) && $user->rights->facture->lire) { if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) @@ -2720,7 +2721,7 @@ class Facture extends CommonInvoice // Check parameters if ($type < 0) return -1; - + if ($date_start && $date_end && $date_start > $date_end) { $langs->load("errors"); $this->error=$langs->trans('ErrorStartDateGreaterEnd'); @@ -2929,7 +2930,7 @@ class Facture extends CommonInvoice return -3; } } - + if ($date_start && $date_end && $date_start > $date_end) { $langs->load("errors"); $this->error=$langs->trans('ErrorStartDateGreaterEnd'); diff --git a/htdocs/core/js/lib_head.js.php b/htdocs/core/js/lib_head.js.php index c81a365bfbc..db86d5e8b58 100644 --- a/htdocs/core/js/lib_head.js.php +++ b/htdocs/core/js/lib_head.js.php @@ -1021,8 +1021,6 @@ function pricejs(amount, mode) { var main_rounding_unit = global->MAIN_MAX_DECIMALS_UNIT; ?>; var main_rounding_tot = global->MAIN_MAX_DECIMALS_TOT; ?>; - console.log(amount); - if (mode == 'MU') return amount.toFixed(main_rounding_unit); if (mode == 'MT') return amount.toFixed(main_rounding_tot); return 'Bad value for parameter mode'; diff --git a/htdocs/takepos/invoice.php b/htdocs/takepos/invoice.php index a0020ec1f41..e4dde53e9e7 100644 --- a/htdocs/takepos/invoice.php +++ b/htdocs/takepos/invoice.php @@ -42,11 +42,7 @@ $desc = GETPOST('desc', 'alpha'); $pay = GETPOST('pay', 'alpha'); $amountofpayment = price2num(GETPOST('amount', 'alpha')); -$placeid = 0; // $placeid is id of invoice - -$invoice = new Facture($db); -$ret = $invoice->fetch('', '(PROV-POS-'.$place.')'); -if ($ret > 0) $placeid = $invoice->id; +$invoiceid = GETPOST('invoiceid', 'int'); $paycode = $pay; if ($pay == 'cash') $paycode = 'LIQ'; // For backward compatibility @@ -62,6 +58,21 @@ $codes = $db->fetch_array($resql); $paiementid=$codes[0]; +$invoice = new Facture($db); +if ($invoiceid > 0) +{ + $ret = $invoice->fetch($invoiceid); +} +else +{ + $ret = $invoice->fetch('', '(PROV-POS-'.$place.')'); +} +if ($ret > 0) +{ + $placeid = $invoice->id; +} + + /* * Actions */ @@ -81,8 +92,14 @@ if ($action == 'valid' && $user->rights->facture->creer) $invoice = new Facture($db); $invoice->fetch($placeid); - if (! empty($conf->stock->enabled) && $conf->global->CASHDESK_NO_DECREASE_STOCK != "1") $invoice->validate($user, '', $conf->global->CASHDESK_ID_WAREHOUSE); - else $invoice->validate($user); + if (! empty($conf->stock->enabled) && $conf->global->CASHDESK_NO_DECREASE_STOCK != "1") + { + $invoice->validate($user, '', $conf->global->CASHDESK_ID_WAREHOUSE); + } + else + { + $invoice->validate($user); + } // Add the payment $payment=new Paiement($db); @@ -96,10 +113,9 @@ if ($action == 'valid' && $user->rights->facture->creer) $payment->create($user); $payment->addPaymentToBank($user, 'payment', '(CustomerInvoicePayment)', $bankaccount, '', ''); - - if ($amountofpayment == $invoice->getRemainToPay()) + if ($invoice->getRemainToPay() == 0) { - $invoice->set_paid($user); + $result = $invoice->set_paid($user); } } @@ -248,6 +264,11 @@ if ($action == "order" and $placeid != 0) { $invoice->fetch($placeid); } + +/* + * View + */ + ?>