2
0
forked from Wavyzz/dolibarr

TakePOS Can enter payment in several times and with different modes

This commit is contained in:
Laurent Destailleur
2019-03-27 15:42:53 +01:00
committed by unknown
parent 7990d7f018
commit 9a7e6ce178
5 changed files with 108 additions and 48 deletions

View File

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

View File

@@ -1021,8 +1021,6 @@ function pricejs(amount, mode) {
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';

View File

@@ -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
*/
?>
<style>
.selected {
@@ -307,11 +328,12 @@ $(document).ready(function(){
$('table tbody tr').removeClass("selected");
$(this).addClass("selected");
if (selectedline==this.id) return; // If is already selected
else selectedline=this.id;
else selectedline=this.id;
selectedtext=$('#'+selectedline).find("td:first").html();
});
<?php
if ($action == "temp" and $ticket_printer1 != "") {
?>
$.ajax({
@@ -379,7 +401,7 @@ print '</table>';
print '<p style="font-size:120%;" class="right"><b>'.$langs->trans('TotalTTC');
if($conf->global->TAKEPOS_BAR_RESTAURANT) print " ".$langs->trans('Place')." ".$place;
if ($conf->global->TAKEPOS_BAR_RESTAURANT) print " ".$langs->trans('Place')." ".$place;
print ': '.price($invoice->total_ttc, 1, '', 1, - 1, - 1, $conf->currency).'&nbsp;</b></p>';
@@ -392,21 +414,26 @@ if ($invoice->socid != $conf->global->CASHDESK_ID_THIRDPARTY)
print $langs->trans("Customer").': '.$soc->name;
print '</p>';
}
if ($action=="valid")
{
print '<p style="font-size:120%;" class="center"><b>';
print '<!-- Area with validated invoice -->'."\n";
print '<input type="hidden" name="invoiceid" id="invoiceid" value="'.$invoice->id.'">';
print '<p style="font-size:120%;" class="center"><b>';
print $invoice->getNomUrl(1, '', 0, 0, '', 0, 0, -1, '_backoffice')." - ";
if ($invoice->getRemainToPay() > 0)
{
print $invoice->getNomUrl(1)." ".$langs->trans('Generated');
print $langs->trans('Generated');
}
else
{
print $invoice->getNomUrl(1)." ".$langs->trans('BillShortStatusValidated');
if ($invoice->paye) print $langs->trans("Payed");
else print $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>';
if ($conf->global->TAKEPOS_AUTO_PRINT_TICKETS) print '<script language="javascript">$("#buttonprint").click();</script>';
}
if ($action == "search")

View File

@@ -15,6 +15,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/takepos/pay.php
* \ingroup takepos
* \brief Page with the content of the popup to enter payments
*/
//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');
@@ -25,26 +31,38 @@ 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
//$_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');
$invoiceid = GETPOST('invoiceid', '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);
$invoice = new Facture($db);
if ($invoiceid > 0)
{
$invoice->fetch($invoiceid);
}
else
{
$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->fetch($placeid);
}
}
top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss);
@@ -74,11 +92,19 @@ if ($resql) {
<body>
<script>
<?php
if ($conf->global->TAKEPOS_NUMPAD==0) print "var received='';";
else print "var received=0;";
?>
var alreadypayed = <?php echo $invoice->getRemainToPay(); ?>;
<?php
$remaintopay = 0;
if ($invoice->id > 0)
{
$remaintopay = $invoice->getRemainToPay();
}
$alreadypayed = (is_object($invoice) ? ($invoice->total_ttc - $remaintopay) : 0);
if ($conf->global->TAKEPOS_NUMPAD==0) print "var received='';";
else print "var received=0;";
?>
var alreadypayed = <?php echo $alreadypayed ?>;
function addreceived(price)
{
@@ -88,9 +114,9 @@ if ($resql) {
?>
$('.change1').html(pricejs(parseFloat(received), 'MT'));
$('.change1').val(parseFloat(received));
if (parseFloat(received) > <?php echo $invoice->total_ttc;?>)
if ((alreadypayed + parseFloat(received)) > <?php echo $invoice->total_ttc;?>)
{
var change=parseFloat(parseFloat(received)-<?php echo $invoice->total_ttc;?>);
var change=parseFloat(alreadypayed + parseFloat(received) - <?php echo $invoice->total_ttc;?>);
$('.change2').html(pricejs(change, 'MT'));
$('.change2').val(change);
$('.change1').removeClass('colorred');
@@ -122,8 +148,8 @@ if ($resql) {
function reset()
{
received=0;
$('.change1').html(pricejs(alreadypayed, 'MT'));
$('.change1').val(price2numjs(alreadypayed));
$('.change1').html(pricejs(received, 'MT'));
$('.change1').val(price2numjs(received));
$('.change2').html(pricejs(received, 'MT'));
$('.change2').val(price2numjs(received));
$('.change1').removeClass('colorgreen');
@@ -134,12 +160,13 @@ if ($resql) {
function Validate(payment)
{
var invoiceid = <?php echo ($invoiceid > 0 ? $invoiceid : 0); ?>;
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").load("invoice.php?place=<?php echo $place;?>&action=valid&pay="+payment+"&amount="+amountpayed+"&invoiceid="+invoiceid, function() {
parent.$("#poslines").scrollTop(parent.$("#poslines")[0].scrollHeight);
parent.$.colorbox.close();
});
@@ -151,8 +178,13 @@ if ($resql) {
<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>
<?php if ($remaintopay != $invoice->total_ttc) { ?>
<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('RemainToPay');?>: </font><span id="remaintopaydisplay" class="colorwhite"><?php echo price($remaintopay, 1, '', 1, -1, -1) ?></span></font></span></center>
</div>
<?php } ?>
<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>
<center><span style='font-family: verdana,arial,helvetica; font-size: 200%;'><font color="white"><?php echo $langs->trans("Received"); ?>: </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>
@@ -171,7 +203,7 @@ $action_buttons = array(
array(
"function" => "parent.$.colorbox.close();",
"span" => "id='printtext'",
"text" => $langs->trans("GoBack"),
"text" => $langs->trans("Cancel"),
),
);
$numpad=$conf->global->TAKEPOS_NUMPAD;

View File

@@ -113,7 +113,7 @@ var pageactions=0;
var place="<?php echo $place;?>";
var editaction="qty";
var editnumber="";
function PrintCategories(first){
function PrintCategories(first) {
for (i = 0; i < 14; i++) {
if (typeof (categories[parseInt(i)+parseInt(first)]) == "undefined") break;
$("#catdesc"+i).text(categories[parseInt(i)+parseInt(first)]['label']);
@@ -123,7 +123,7 @@ function PrintCategories(first){
}
}
function MoreCategories(moreorless){
function MoreCategories(moreorless) {
if (moreorless=="more"){
$('#catimg15').animate({opacity: '0.5'}, 1);
$('#catimg15').animate({opacity: '1'}, 100);
@@ -153,7 +153,7 @@ function MoreCategories(moreorless){
}
}
function LoadProducts(position, issubcat=false){
function LoadProducts(position, issubcat=false) {
$('#catimg'+position).animate({opacity: '0.5'}, 1);
$('#catimg'+position).animate({opacity: '1'}, 100);
if (issubcat==true) currentcat=$('#prodiv'+position).data('rowid');
@@ -262,7 +262,9 @@ function Customer(){
}
function CloseBill(){
$.colorbox({href:"pay.php?place="+place, width:"80%", height:"90%", transition:"none", iframe:"true", title:"<?php echo $langs->trans("CloseBill");?>"});
invoiceid = $("#invoiceid").val();
console.log("Open popup to enter payment on invoiceid="+invoiceid);
$.colorbox({href:"pay.php?place="+place+"&invoiceid="+invoiceid, width:"80%", height:"90%", transition:"none", iframe:"true", title:""});
}
function Floors(){
@@ -485,7 +487,7 @@ $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 : '/').'\', \'_backoffice\');');
$menus[$r++]=array('title'=>$langs->trans("ValidateBill"),
$menus[$r++]=array('title'=>$langs->trans("DoPayment"),
'action'=>'CloseBill();');
$menus[$r++]=array('title'=>$langs->trans("Logout"),
'action'=>'window.location.href=\''.DOL_URL_ROOT.'/user/logout.php\';');