forked from Wavyzz/dolibarr
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
245 lines
11 KiB
PHP
245 lines
11 KiB
PHP
<?php
|
|
/* Copyright (C) 2018 Andreu Bisquerra <jove@bisquerra.com>
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
//if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER', '1'); // Not disabled cause need to load personalized language
|
|
//if (! defined('NOREQUIREDB')) define('NOREQUIREDB', '1'); // Not disabled cause need to load personalized language
|
|
//if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1');
|
|
//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN', '1');
|
|
if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK', '1');
|
|
if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1');
|
|
if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1');
|
|
if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1');
|
|
if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1');
|
|
|
|
$_GET['theme']="md"; // Force theme. MD theme provides better look and feel to TakePOS
|
|
|
|
require '../main.inc.php'; // Load $user and permissions
|
|
require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php';
|
|
|
|
$place = GETPOST('place', 'int');
|
|
|
|
|
|
/*
|
|
* View
|
|
*/
|
|
|
|
$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 does not exist yet
|
|
else{
|
|
$invoice = new Facture($db);
|
|
$invoice->fetch($placeid);
|
|
}
|
|
|
|
top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss);
|
|
|
|
$langs->loadLangs(array("main", "bills", "cashdesk"));
|
|
|
|
$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";
|
|
$resql = $db->query($sql);
|
|
$paiements = array();
|
|
if ($resql) {
|
|
while ($obj = $db->fetch_object($resql)) {
|
|
$paycode = $obj->code;
|
|
if ($paycode == 'LIQ') $paycode = 'CASH';
|
|
if ($paycode == 'CB') $paycode = 'CB';
|
|
if ($paycode == 'CHQ') $paycode = 'CHEQUE';
|
|
|
|
$accountname="CASHDESK_ID_BANKACCOUNT_".$paycode;
|
|
if (! empty($conf->global->$accountname) && $conf->global->$accountname > 0) array_push($paiements, $obj);
|
|
}
|
|
}
|
|
?>
|
|
<link rel="stylesheet" href="css/pos.css">
|
|
</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 (empty($conf->global->TAKEPOS_NUMPAD)) print 'received+=String(price);'."\n";
|
|
else print 'received+=parseFloat(price);'."\n";
|
|
?>
|
|
$('.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(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;
|
|
$('.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)
|
|
{
|
|
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>
|
|
|
|
<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: 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: 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: 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:33%; left:5%; height:55%; width:91%;">
|
|
<?php
|
|
$action_buttons = array(
|
|
array(
|
|
"function" =>"reset()",
|
|
"span" => "style='font-size: 150%;'",
|
|
"text" => "C",
|
|
),
|
|
array(
|
|
"function" => "parent.$.colorbox.close();",
|
|
"span" => "id='printtext'",
|
|
"text" => $langs->trans("GoBack"),
|
|
),
|
|
);
|
|
$numpad=$conf->global->TAKEPOS_NUMPAD;
|
|
?>
|
|
<button type="button" class="calcbutton" onclick="addreceived(<?php if ($numpad==0) print "7"; else print "10";?>);"><?php if ($numpad==0) print "7"; else print "10";?></button>
|
|
<button type="button" class="calcbutton" onclick="addreceived(<?php if ($numpad==0) print "8"; else print "20";?>);"><?php if ($numpad==0) print "8"; else print "20";?></button>
|
|
<button type="button" class="calcbutton" onclick="addreceived(<?php if ($numpad==0) print "9"; else print "50";?>);"><?php if ($numpad==0) print "9"; else print "50";?></button>
|
|
<?php if (count($paiements) > 0) {
|
|
$paycode = $paiements[0]->code;
|
|
if ($paycode == 'LIQ') $paycode = 'cash';
|
|
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]->label); ?></button>
|
|
<?php } else { ?>
|
|
<button type="button" class="calcbutton2"><?php echo $langs->trans("NoPaimementModesDefined");?></button>
|
|
<?php } ?>
|
|
<button type="button" class="calcbutton" onclick="addreceived(<?php if ($numpad==0) print "4"; else print "1";?>);"><?php if ($numpad==0) print "4"; else print "1";?></button>
|
|
<button type="button" class="calcbutton" onclick="addreceived(<?php if ($numpad==0) print "5"; else print "2";?>);"><?php if ($numpad==0) print "5"; else print "2";?></button>
|
|
<button type="button" class="calcbutton" onclick="addreceived(<?php if ($numpad==0) print "6"; else print "5";?>);"><?php if ($numpad==0) print "6"; else print "5";?></button>
|
|
<?php if (count($paiements) > 1) {
|
|
$paycode = $paiements[1]->code;
|
|
if ($paycode == 'LIQ') $paycode = 'cash';
|
|
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]->label); ?></button>
|
|
<?php } else {
|
|
$button = array_pop($action_buttons);
|
|
?>
|
|
<button type="button" class="calcbutton2" onclick="<?php echo $button["function"];?>"><span <?php echo $button["span"];?>><?php echo $button["text"];?></span></button>
|
|
<?php } ?>
|
|
<button type="button" class="calcbutton" onclick="addreceived(<?php if ($numpad==0) print "1"; else print "0.10";?>);"><?php if ($numpad==0) print "1"; else print "0.10";?></button>
|
|
<button type="button" class="calcbutton" onclick="addreceived(<?php if ($numpad==0) print "2"; else print "0.20";?>);"><?php if ($numpad==0) print "2"; else print "0.20";?></button>
|
|
<button type="button" class="calcbutton" onclick="addreceived(<?php if ($numpad==0) print "3"; else print "0.50";?>);"><?php if ($numpad==0) print "3"; else print "0.50";?></button>
|
|
<?php if (count($paiements) > 2) {
|
|
$paycode = $paiements[2]->code;
|
|
if ($paycode == 'LIQ') $paycode = 'cash';
|
|
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]->label); ?></button>
|
|
<?php } else { ?>
|
|
<?php
|
|
$button = array_pop($action_buttons);
|
|
?>
|
|
<button type="button" class="calcbutton2" onclick="<?php echo $button["function"];?>"><span <?php echo $button["span"];?>><?php echo $button["text"];?></span></button>
|
|
<?php } ?>
|
|
<button type="button" class="calcbutton" onclick="addreceived(<?php if ($numpad==0) print "0"; else print "0.01";?>);"><?php if ($numpad==0) print "0"; else print "0.01";?></button>
|
|
<button type="button" class="calcbutton" onclick="addreceived(<?php if ($numpad==0) print "'000'"; else print "0.02";?>);"><?php if ($numpad==0) print "000"; else print "0.02";?></button>
|
|
<button type="button" class="calcbutton" onclick="addreceived(<?php if ($numpad==0) print "'.'"; else print "0.05";?>);"><?php if ($numpad==0) print "."; else print "0.05";?></button>
|
|
<?php
|
|
$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]->label); ?></button>
|
|
<?php
|
|
$i=$i+1;
|
|
}
|
|
$class=($i==3)?"calcbutton3":"calcbutton2";
|
|
foreach($action_buttons as $button){
|
|
?>
|
|
<button type="button" class="<?php echo $class;?>" onclick="<?php echo $button["function"];?>"><span <?php echo $button["span"];?>><?php echo $button["text"];?></span></button>
|
|
<?php
|
|
}
|
|
?>
|
|
</div>
|
|
|
|
</body>
|
|
</html>
|