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
This commit is contained in:
Laurent Destailleur
2019-03-27 12:40:32 +01:00
parent fb30b9bb82
commit ec0733d202
5 changed files with 131 additions and 50 deletions

View File

@@ -1009,6 +1009,25 @@ function getParameterByName(name, valueifnotfound)
function dolroundjs(number, decimals) { return +(Math.round(number + "e+" + decimals) + "e-" + decimals); } 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 = <?php echo (int) str_replace('.', '', $conf->global->MAIN_MAX_DECIMALS_SHOWN); ?>;
var main_rounding_unit = <?php echo (int) $conf->global->MAIN_MAX_DECIMALS_UNIT; ?>;
var main_rounding_tot = <?php echo (int) $conf->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() * Function similar to PHP price2num()
* *

View File

@@ -103,7 +103,6 @@ div.description{
width:100%; width:100%;
/* styling below */ /* styling below */
background-color:black; background-color:black;
font-family: 'tahoma';
color:white; color:white;
opacity:0.8; /* transparency */ opacity:0.8; /* transparency */
filter:alpha(opacity=80); /* IE transparency */ filter:alpha(opacity=80); /* IE transparency */
@@ -209,6 +208,15 @@ div.catwatermark{
padding-left: 5px; padding-left: 5px;
} }
.colorwhite {
color: white;
}
.colorred {
color: red;
}
.colorgreen {
color: green;
}
p.description_content{ p.description_content{
padding:10px; padding:10px;
margin:0px; margin:0px;

View File

@@ -36,10 +36,11 @@ $id = GETPOST('id', 'int');
$action = GETPOST('action', 'alpha'); $action = GETPOST('action', 'alpha');
$idproduct = GETPOST('idproduct', 'int'); $idproduct = GETPOST('idproduct', 'int');
$place = (GETPOSTISSET('place')?GETPOST('place', 'int'):0); // $place is id of POS $place = (GETPOSTISSET('place')?GETPOST('place', 'int'):0); // $place is id of POS
$number = GETPOST('number'); $number = GETPOST('number', 'alpha');
$idline = GETPOST('idline'); $idline = GETPOST('idline', 'int');
$desc = GETPOST('desc', 'alpha'); $desc = GETPOST('desc', 'alpha');
$pay = GETPOST('pay'); $pay = GETPOST('pay', 'alpha');
$amountofpayment = price2num(GETPOST('amount', 'alpha'));
$placeid = 0; // $placeid is id of invoice $placeid = 0; // $placeid is id of invoice
@@ -48,27 +49,28 @@ $ret = $invoice->fetch('', '(PROV-POS-'.$place.')');
if ($ret > 0) $placeid = $invoice->id; if ($ret > 0) $placeid = $invoice->id;
$paycode = $pay; $paycode = $pay;
if ($pay == 'cash') $paycode = 'LIQ'; if ($pay == 'cash') $paycode = 'LIQ'; // For backward compatibility
if ($pay == 'card') $paycode = 'CB'; if ($pay == 'card') $paycode = 'CB'; // For backward compatibility
if ($pay == 'cheque') $paycode = 'CHQ'; if ($pay == 'cheque') $paycode = 'CHQ'; // For backward compatibility
// Retrieve paiementid // Retrieve paiementid
$sql = "SELECT id FROM ".MAIN_DB_PREFIX."c_paiement"; $sql = "SELECT id FROM ".MAIN_DB_PREFIX."c_paiement";
$sql.= " WHERE entity IN (".getEntity('c_paiement').")"; $sql.= " WHERE entity IN (".getEntity('c_paiement').")";
$sql.= " AND code = '".$paycode."'"; $sql.= " AND code = '".$db->escape($paycode)."'";
$resql = $db->query($sql); $resql = $db->query($sql);
$codes = $db->fetch_array($resql); $codes = $db->fetch_array($resql);
$paiementid=$codes[0]; $paiementid=$codes[0];
/* /*
* Actions * Actions
*/ */
if ($action == 'valid' && $user->rights->facture->creer) if ($action == 'valid' && $user->rights->facture->creer)
{ {
if ($pay == "cash") $bankaccount = $conf->global->CASHDESK_ID_BANKACCOUNT_CASH; if ($pay == "cash") $bankaccount = $conf->global->CASHDESK_ID_BANKACCOUNT_CASH; // For backward compatibility
elseif ($pay == "card") $bankaccount = $conf->global->CASHDESK_ID_BANKACCOUNT_CB; elseif ($pay == "card") $bankaccount = $conf->global->CASHDESK_ID_BANKACCOUNT_CB; // For backward compatibility
elseif ($pay == "cheque") $bankaccount = $conf->global->CASHDESK_ID_BANKACCOUNT_CHEQUE; elseif ($pay == "cheque") $bankaccount = $conf->global->CASHDESK_ID_BANKACCOUNT_CHEQUE; // For backward compatibility
else else
{ {
$accountname="CASHDESK_ID_BANKACCOUNT_".$pay; $accountname="CASHDESK_ID_BANKACCOUNT_".$pay;
@@ -79,23 +81,27 @@ if ($action == 'valid' && $user->rights->facture->creer)
$invoice = new Facture($db); $invoice = new Facture($db);
$invoice->fetch($placeid); $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); else $invoice->validate($user);
// Add the payment // Add the payment
$payment=new Paiement($db); $payment=new Paiement($db);
$payment->datepaye = $now; $payment->datepaye = $now;
$payment->bank_account = $bankaccount; $payment->fk_account = $bankaccount;
$payment->amounts[$invoice->id] = $invoice->total_ttc; $payment->amounts[$invoice->id] = $amountofpayment;
$payment->paiementid=$paiementid; $payment->paiementid=$paiementid;
$payment->num_paiement=$invoice->ref; $payment->num_payment=$invoice->ref;
$payment->create($user); $payment->create($user);
$payment->addPaymentToBank($user, 'payment', '(CustomerInvoicePayment)', $bankaccount, '', ''); $payment->addPaymentToBank($user, 'payment', '(CustomerInvoicePayment)', $bankaccount, '', '');
if ($amountofpayment == $invoice->getRemainToPay())
{
$invoice->set_paid($user); $invoice->set_paid($user);
} }
}
if (($action=="addline" || $action=="freezone") && $placeid == 0) if (($action=="addline" || $action=="freezone") && $placeid == 0)
{ {
@@ -388,7 +394,16 @@ if ($invoice->socid != $conf->global->CASHDESK_ID_THIRDPARTY)
} }
if ($action=="valid") if ($action=="valid")
{ {
print '<p style="font-size:120%;" class="center"><b>'.$invoice->ref." ".$langs->trans('BillShortStatusValidated').'</b></p>'; print '<p style="font-size:120%;" class="center"><b>';
if ($invoice->getRemainToPay() > 0)
{
print $invoice->getNomUrl(1)." ".$langs->trans('Generated');
}
else
{
print $invoice->getNomUrl(1)." ".$langs->trans('BillShortStatusValidated');
}
print '</b></p>';
if ($conf->global->TAKEPOSCONNECTOR) print '<center><button type="button" onclick="TakeposPrinting('.$placeid.');">'.$langs->trans('PrintTicket').'</button><center>'; if ($conf->global->TAKEPOSCONNECTOR) print '<center><button type="button" onclick="TakeposPrinting('.$placeid.');">'.$langs->trans('PrintTicket').'</button><center>';
else print '<center><button id="buttonprint" type="button" onclick="Print('.$placeid.');">'.$langs->trans('PrintTicket').'</button><center>'; else print '<center><button id="buttonprint" type="button" onclick="Print('.$placeid.');">'.$langs->trans('PrintTicket').'</button><center>';
if($conf->global->TAKEPOS_AUTO_PRINT_TICKETS) print '<script language="javascript">$("#buttonprint").click();</script>'; if($conf->global->TAKEPOS_AUTO_PRINT_TICKETS) print '<script language="javascript">$("#buttonprint").click();</script>';

View File

@@ -41,7 +41,7 @@ $sql="SELECT rowid FROM ".MAIN_DB_PREFIX."facture where ref='(PROV-POS-".$place.
$resql = $db->query($sql); $resql = $db->query($sql);
$row = $db->fetch_array($resql); $row = $db->fetch_array($resql);
$placeid=$row[0]; $placeid=$row[0];
if (! $placeid) $placeid=0; // Invoice not exist if (! $placeid) $placeid=0; // Invoice does not exist yet
else{ else{
$invoice = new Facture($db); $invoice = new Facture($db);
$invoice->fetch($placeid); $invoice->fetch($placeid);
@@ -51,7 +51,7 @@ top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss);
$langs->loadLangs(array("main", "bills", "cashdesk")); $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.= " WHERE entity IN (".getEntity('c_paiement').")";
$sql.= " AND active = 1"; $sql.= " AND active = 1";
$sql.= " ORDER BY libelle"; $sql.= " ORDER BY libelle";
@@ -70,58 +70,97 @@ if ($resql) {
} }
?> ?>
<link rel="stylesheet" href="css/pos.css"> <link rel="stylesheet" href="css/pos.css">
</head>
<body>
<script> <script>
<?php <?php
if ($conf->global->TAKEPOS_NUMPAD==0) print "var received='';"; if ($conf->global->TAKEPOS_NUMPAD==0) print "var received='';";
else print "var received=0;"; else print "var received=0;";
?> ?>
var alreadypayed = <?php echo $invoice->getRemainToPay(); ?>;
function addreceived(price) function addreceived(price)
{ {
<?php <?php
if ($conf->global->TAKEPOS_NUMPAD==0) print 'received+=String(price);'; if (empty($conf->global->TAKEPOS_NUMPAD)) print 'received+=String(price);'."\n";
else print 'received+=parseFloat(price);'; else print 'received+=parseFloat(price);'."\n";
?> ?>
$('#change1').html(parseFloat(received).toFixed(2)); $('.change1').html(pricejs(parseFloat(received), 'MT'));
$('.change1').val(parseFloat(received));
if (parseFloat(received) > <?php echo $invoice->total_ttc;?>) if (parseFloat(received) > <?php echo $invoice->total_ttc;?>)
{ {
var change=parseFloat(parseFloat(received)-<?php echo $invoice->total_ttc;?>); var change=parseFloat(parseFloat(received)-<?php echo $invoice->total_ttc;?>);
$('#change2').html(change.toFixed(2)); $('.change2').html(pricejs(change, 'MT'));
$('.change2').val(change);
$('.change1').removeClass('colorred');
$('.change1').addClass('colorgreen');
$('.change2').removeClass('colorwhite');
$('.change2').addClass('colorred');
}
else
{
$('.change2').html(pricejs(0, 'MT'));
$('.change2').val(0);
if ((alreadypayed + parseFloat(received)) == <?php echo $invoice->total_ttc;?>)
{
$('.change1').removeClass('colorred');
$('.change1').addClass('colorgreen');
$('.change2').removeClass('colorred');
$('.change2').addClass('colorwhite');
}
else
{
$('.change1').removeClass('colorgreen');
$('.change1').addClass('colorred');
$('.change2').removeClass('colorred');
$('.change2').addClass('colorwhite');
}
} }
} }
function reset() function reset()
{ {
received=0; received=0;
addreceived(0); $('.change1').html(pricejs(alreadypayed, 'MT'));
$('#change2').html(received.toFixed(2)); $('.change1').val(price2numjs(alreadypayed));
$('.change2').html(pricejs(received, 'MT'));
$('.change2').val(price2numjs(received));
$('.change1').removeClass('colorgreen');
$('.change1').addClass('colorred');
$('.change2').removeClass('colorred');
$('.change2').addClass('colorwhite');
} }
function Validate(payment){ function Validate(payment)
parent.$("#poslines").load("invoice.php?place=<?php echo $place;?>&action=valid&pay="+payment, function() { {
var amountpayed = $("#change1").val();
if (amountpayed > <?php echo $invoice->total_ttc; ?>) {
amountpayed = <?php echo $invoice->total_ttc; ?>;
}
console.log("We click on the payment mode to pay amount = "+amountpayed);
parent.$("#poslines").load("invoice.php?place=<?php echo $place;?>&action=valid&pay="+payment+"&amount="+amountpayed, function() {
parent.$("#poslines").scrollTop(parent.$("#poslines")[0].scrollHeight); parent.$("#poslines").scrollTop(parent.$("#poslines")[0].scrollHeight);
parent.$.colorbox.close(); parent.$.colorbox.close();
}); });
} }
</script> </script>
</head>
<body>
<div style="position:absolute; top:2%; left:5%; height:36%; width:91%;"> <div style="position:absolute; top:2%; left:5%; height:30%; width:91%;">
<center> <center>
<div style="width:40%; background-color:#222222; border-radius:8px; margin-bottom: 4px;"> <div style="width:40%; background-color:#222222; border-radius:8px; margin-bottom: 4px;">
<center><span style='font-family: digital; font-size: 280%;'><font color="white"><?php echo $langs->trans('TotalTTC');?>: </font><font color="red"><span id="totaldisplay"><?php echo price($invoice->total_ttc, 1, '', 1, - 1, - 1, $conf->currency) ?></span></span></center> <center><span style='font-family: verdana,arial,helvetica; font-size: 200%;'><font color="white"><?php echo $langs->trans('TotalTTC');?>: </font><span id="totaldisplay" class="colorwhite"><?php echo price($invoice->total_ttc, 1, '', 1, -1, -1) ?></span></font></span></center>
</div> </div>
<div style="width:40%; background-color:#333333; border-radius:8px; margin-bottom: 4px;"> <div style="width:40%; background-color:#333333; border-radius:8px; margin-bottom: 4px;">
<center><span style='font-family: digital; font-size: 250%;'><font color="white"><?php echo $langs->trans("AlreadyPaid"); ?>: </font><font color="red"><span id="change1"><?php echo price(0) ?></span></center> <center><span style='font-family: verdana,arial,helvetica; font-size: 200%;'><font color="white"><?php echo $langs->trans("AlreadyPaid"); ?>: </font><span class="change1 colorred"><?php echo price(0) ?></span><input type="hidden" id="change1" class="change1" value="0"></font></center>
</div> </div>
<div style="width:40%; background-color:#333333; border-radius:8px; margin-bottom: 4px;"> <div style="width:40%; background-color:#333333; border-radius:8px; margin-bottom: 4px;">
<center><span style='font-family: digital; font-size: 250%;'><font color="white"><?php echo $langs->trans("Change"); ?>: </font><font color="red"><span id="change2"><?php echo price(0) ?></span></span></center> <center><span style='font-family: verdana,arial,helvetica; font-size: 200%;'><font color="white"><?php echo $langs->trans("Change"); ?>: </font><span class="change2 colorwhite"><?php echo price(0) ?></span><input type="hidden" id="change2" class="change2" value="0"></font></span></center>
</div> </div>
</center> </center>
</div> </div>
<div style="position:absolute; top:40%; left:5%; height:55%; width:91%;"> <div style="position:absolute; top:33%; left:5%; height:55%; width:91%;">
<?php <?php
$action_buttons = array( $action_buttons = array(
array( array(
@@ -146,7 +185,7 @@ $numpad=$conf->global->TAKEPOS_NUMPAD;
if ($paycode == 'CB') $paycode = 'card'; if ($paycode == 'CB') $paycode = 'card';
if ($paycode == 'CHQ') $paycode = 'cheque'; if ($paycode == 'CHQ') $paycode = 'cheque';
?> ?>
<button type="button" class="calcbutton2" onclick="Validate('<?php echo $langs->trans($paycode); ?>');"><?php echo $langs->trans($paiements[0]->libelle); ?></button> <button type="button" class="calcbutton2" onclick="Validate('<?php echo $langs->trans($paycode); ?>');"><?php echo $langs->trans($paiements[0]->label); ?></button>
<?php } else { ?> <?php } else { ?>
<button type="button" class="calcbutton2"><?php echo $langs->trans("NoPaimementModesDefined");?></button> <button type="button" class="calcbutton2"><?php echo $langs->trans("NoPaimementModesDefined");?></button>
<?php } ?> <?php } ?>
@@ -159,7 +198,7 @@ $numpad=$conf->global->TAKEPOS_NUMPAD;
if ($paycode == 'CB') $paycode = 'card'; if ($paycode == 'CB') $paycode = 'card';
if ($paycode == 'CHQ') $paycode = 'cheque'; if ($paycode == 'CHQ') $paycode = 'cheque';
?> ?>
<button type="button" class="calcbutton2" onclick="Validate('<?php echo $langs->trans($paycode); ?>');"><?php echo $langs->trans($paiements[1]->libelle); ?></button> <button type="button" class="calcbutton2" onclick="Validate('<?php echo $langs->trans($paycode); ?>');"><?php echo $langs->trans($paiements[1]->label); ?></button>
<?php } else { <?php } else {
$button = array_pop($action_buttons); $button = array_pop($action_buttons);
?> ?>
@@ -174,7 +213,7 @@ $button = array_pop($action_buttons);
if ($paycode == 'CB') $paycode = 'card'; if ($paycode == 'CB') $paycode = 'card';
if ($paycode == 'CHQ') $paycode = 'cheque'; if ($paycode == 'CHQ') $paycode = 'cheque';
?> ?>
<button type="button" class="calcbutton2" onclick="Validate('<?php echo $langs->trans($paycode); ?>');"><?php echo $langs->trans($paiements[2]->libelle); ?></button> <button type="button" class="calcbutton2" onclick="Validate('<?php echo $langs->trans($paycode); ?>');"><?php echo $langs->trans($paiements[2]->label); ?></button>
<?php } else { ?> <?php } else { ?>
<?php <?php
$button = array_pop($action_buttons); $button = array_pop($action_buttons);
@@ -188,7 +227,7 @@ $button = array_pop($action_buttons);
$i=3; $i=3;
while($i < count($paiements)){ while($i < count($paiements)){
?> ?>
<button type="button" class="calcbutton2" onclick="Validate('<?php echo $langs->trans($paiements[$i]->code); ?>');"><?php echo $langs->trans($paiements[$i]->libelle); ?></button> <button type="button" class="calcbutton2" onclick="Validate('<?php echo $langs->trans($paiements[$i]->code); ?>');"><?php echo $langs->trans($paiements[$i]->label); ?></button>
<?php <?php
$i=$i+1; $i=$i+1;
} }

View File

@@ -484,7 +484,7 @@ $menus[$r++]=array('title'=>$langs->trans("FreeZone"),
$menus[$r++]=array('title'=>$langs->trans("Customer"), $menus[$r++]=array('title'=>$langs->trans("Customer"),
'action'=>'Customer();'); 'action'=>'Customer();');
$menus[$r++]=array('title'=>$langs->trans("BackOffice"), $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"), $menus[$r++]=array('title'=>$langs->trans("ValidateBill"),
'action'=>'CloseBill();'); 'action'=>'CloseBill();');
$menus[$r++]=array('title'=>$langs->trans("Logout"), $menus[$r++]=array('title'=>$langs->trans("Logout"),