From ec0733d2026e52034a648d33fe343ec1cde59454 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 27 Mar 2019 12:40:32 +0100 Subject: [PATCH] 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"),