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 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()
*

View File

@@ -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;

View File

@@ -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,27 +49,28 @@ $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;
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;
@@ -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, '', '');
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 '<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>';
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>';

View File

@@ -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) {
}
?>
<link rel="stylesheet" href="css/pos.css">
<script>
</head>
<body>
<script>
<?php
if ($conf->global->TAKEPOS_NUMPAD==0) print "var received='';";
else print "var received=0;";
?>
var alreadypayed = <?php echo $invoice->getRemainToPay(); ?>;
function addreceived(price)
{
<?php
if ($conf->global->TAKEPOS_NUMPAD==0) print 'received+=String(price);';
else print 'received+=parseFloat(price);';
if (empty($conf->global->TAKEPOS_NUMPAD)) print 'received+=String(price);'."\n";
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;?>)
{
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()
{
received=0;
addreceived(0);
$('#change2').html(received.toFixed(2));
$('.change1').html(pricejs(alreadypayed, 'MT'));
$('.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){
parent.$("#poslines").load("invoice.php?place=<?php echo $place;?>&action=valid&pay="+payment, function() {
function Validate(payment)
{
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.$.colorbox.close();
});
}
</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>
<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 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 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>
</center>
</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
$action_buttons = array(
array(
@@ -146,7 +185,7 @@ $numpad=$conf->global->TAKEPOS_NUMPAD;
if ($paycode == 'CB') $paycode = 'card';
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 { ?>
<button type="button" class="calcbutton2"><?php echo $langs->trans("NoPaimementModesDefined");?></button>
<?php } ?>
@@ -159,7 +198,7 @@ $numpad=$conf->global->TAKEPOS_NUMPAD;
if ($paycode == 'CB') $paycode = 'card';
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 {
$button = array_pop($action_buttons);
?>
@@ -174,7 +213,7 @@ $button = array_pop($action_buttons);
if ($paycode == 'CB') $paycode = 'card';
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
$button = array_pop($action_buttons);
@@ -188,7 +227,7 @@ $button = array_pop($action_buttons);
$i=3;
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
$i=$i+1;
}

View File

@@ -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"),