diff --git a/htdocs/compta/paiement/class/paiement.class.php b/htdocs/compta/paiement/class/paiement.class.php index 5e01454dd75..c7dd83ee253 100644 --- a/htdocs/compta/paiement/class/paiement.class.php +++ b/htdocs/compta/paiement/class/paiement.class.php @@ -9,6 +9,7 @@ * Copyright (C) 2018 Ferran Marcet * Copyright (C) 2018 Thibault FOUCART * Copyright (C) 2018 Frédéric France + * Copyright (C) 2020 Andreu Bisquerra Gaya * * 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 @@ -73,6 +74,8 @@ class Paiement extends CommonObject public $amounts = array(); // array: invoice ID => amount for that invoice (in the main currency)> public $multicurrency_amounts = array(); // array: invoice ID => amount for that invoice (in the invoice's currency)> + public $pos_change = 0; // Excess received in TakePOS cash payment + public $author; public $paiementid; // Type of payment. Id saved into fields fk_paiement on llx_paiement public $paiementcode; // Code of payment. @@ -288,8 +291,8 @@ class Paiement extends CommonObject $num_payment = ($this->num_payment ? $this->num_payment : $this->num_paiement); $note = ($this->note_public ? $this->note_public : $this->note); - $sql = "INSERT INTO ".MAIN_DB_PREFIX."paiement (entity, ref, datec, datep, amount, multicurrency_amount, fk_paiement, num_paiement, note, ext_payment_id, ext_payment_site, fk_user_creat)"; - $sql .= " VALUES (".$conf->entity.", '".$this->db->escape($this->ref)."', '".$this->db->idate($now)."', '".$this->db->idate($this->datepaye)."', ".$total.", ".$mtotal.", ".$this->paiementid.", '".$this->db->escape($num_payment)."', '".$this->db->escape($note)."', ".($this->ext_payment_id ? "'".$this->db->escape($this->ext_payment_id)."'" : "null").", ".($this->ext_payment_site ? "'".$this->db->escape($this->ext_payment_site)."'" : "null").", ".$user->id.")"; + $sql = "INSERT INTO ".MAIN_DB_PREFIX."paiement (entity, ref, datec, datep, amount, multicurrency_amount, fk_paiement, num_paiement, note, ext_payment_id, ext_payment_site, fk_user_creat, pos_change)"; + $sql .= " VALUES (".$conf->entity.", '".$this->db->escape($this->ref)."', '".$this->db->idate($now)."', '".$this->db->idate($this->datepaye)."', ".$total.", ".$mtotal.", ".$this->paiementid.", '".$this->db->escape($num_payment)."', '".$this->db->escape($note)."', ".($this->ext_payment_id ? "'".$this->db->escape($this->ext_payment_id)."'" : "null").", ".($this->ext_payment_site ? "'".$this->db->escape($this->ext_payment_site)."'" : "null").", ".$user->id.", ".((int) $this->pos_change).")"; $resql = $this->db->query($sql); if ($resql) diff --git a/htdocs/core/class/dolreceiptprinter.class.php b/htdocs/core/class/dolreceiptprinter.class.php index 3234b1900f2..b7929e6a159 100644 --- a/htdocs/core/class/dolreceiptprinter.class.php +++ b/htdocs/core/class/dolreceiptprinter.class.php @@ -186,7 +186,7 @@ class dolReceiptPrinter extends Printer 'dol_value_month' => 'DOL_VALUE_MONTH', 'dol_value_day' => 'DOL_VALUE_DAY', 'dol_value_day_letters' => 'DOL_VALUE_DAY', - //'dol_print_payment', + 'dol_print_payment' => 'DOL_PRINT_PAYMENT', 'dol_print_logo' => 'DOL_PRINT_LOGO', 'dol_print_logo_old' => 'DOL_PRINT_LOGO_OLD', 'dol_value_object_id' => 'InvoiceID', @@ -775,6 +775,35 @@ class dolReceiptPrinter extends Printer } } break; + case 'DOL_PRINT_PAYMENT': + $sql = "SELECT p.pos_change as pos_change, p.datep as date, p.fk_paiement, p.num_paiement as num, pf.amount as amount, pf.multicurrency_amount,"; + $sql .= " cp.code"; + $sql .= " FROM ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."paiement as p"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON p.fk_paiement = cp.id"; + $sql .= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".$object->id; + $sql .= " ORDER BY p.datep"; + $resql = $this->db->query($sql); + if ($resql) + { + $num = $this->db->num_rows($resql); + $i = 0; + while ($i < $num) { + $row = $this->db->fetch_object($resql); + $spacestoadd = $nbcharactbyline - strlen($langs->transnoentitiesnoconv("PaymentTypeShort".$row->code)) - 12; + $spaces = str_repeat(' ', $spacestoadd); + $amount_payment=($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount; + if ($row->code == "LIQ") $amount_payment = $amount_payment + $row->pos_change; // Show amount with excess received if is cash payment + $this->printer->text($spaces.$langs->transnoentitiesnoconv("PaymentTypeShort".$row->code).' '.str_pad(price($amount_payment), 10, ' ', STR_PAD_LEFT)."\n"); + if ($row->code == "LIQ" && $row->pos_change>0) // Print change only in cash payments + { + $spacestoadd = $nbcharactbyline - strlen($langs->trans("Change")) - 12; + $spaces = str_repeat(' ', $spacestoadd); + $this->printer->text($spaces.$langs->trans("Change").' '.str_pad(price($row->pos_change), 10, ' ', STR_PAD_LEFT)."\n"); + } + $i++; + } + } + break; default: $this->printer->text($vals[$tplline]['tag']); $this->printer->text($vals[$tplline]['value']); diff --git a/htdocs/install/mysql/migration/12.0.0-13.0.0.sql b/htdocs/install/mysql/migration/12.0.0-13.0.0.sql index 108dc94f485..322b1bee322 100644 --- a/htdocs/install/mysql/migration/12.0.0-13.0.0.sql +++ b/htdocs/install/mysql/migration/12.0.0-13.0.0.sql @@ -261,6 +261,8 @@ ALTER TABLE llx_projet ADD COLUMN email_msgid varchar(255); ALTER TABLE llx_ticket ADD COLUMN email_msgid varchar(255); ALTER TABLE llx_actioncomm ADD COLUMN reply_to varchar(255); +ALTER TABLE llx_paiement ADD pos_change DOUBLE(24,8) DEFAULT 0 AFTER fk_export_compta; + insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('CONTACT_CREATE','Contact address created','Executed when a contact is created','contact',50); insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('CONTACT_SENTBYMAIL','Mails sent from third party card','Executed when you send email from contact adress card','contact',51); insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('CONTACT_DELETE','Contact address deleted','Executed when a contact is deleted','contact',52); diff --git a/htdocs/install/mysql/tables/llx_paiement.sql b/htdocs/install/mysql/tables/llx_paiement.sql index d0cfd727d95..d19d38312a4 100644 --- a/htdocs/install/mysql/tables/llx_paiement.sql +++ b/htdocs/install/mysql/tables/llx_paiement.sql @@ -37,5 +37,6 @@ create table llx_paiement fk_user_creat integer, -- utilisateur qui a cree l'info fk_user_modif integer, -- utilisateur qui a modifie l'info statut smallint DEFAULT 0 NOT NULL, -- Satut, 0 ou 1, 1 n'est plus supprimable - fk_export_compta integer DEFAULT 0 NOT NULL -- fk_export_compta 0 pas exporte + fk_export_compta integer DEFAULT 0 NOT NULL, -- fk_export_compta 0 pas exporte + pos_change double(24,8) DEFAULT 0 -- Excess received in TakePOS cash payment )ENGINE=innodb; diff --git a/htdocs/langs/en_US/cashdesk.lang b/htdocs/langs/en_US/cashdesk.lang index 094c70ca687..40691eb70e7 100644 --- a/htdocs/langs/en_US/cashdesk.lang +++ b/htdocs/langs/en_US/cashdesk.lang @@ -121,3 +121,4 @@ GiftReceiptButton=Add a "Gift receipt" button GiftReceipt=Gift receipt ModuleReceiptPrinterMustBeEnabled=Module Receipt printer must have been enabled first AllowDelayedPayment=Allow delayed payment +PrintPaymentMethodOnReceipts=Print payment method on tickets|receipts \ No newline at end of file diff --git a/htdocs/takepos/admin/receipt.php b/htdocs/takepos/admin/receipt.php index 27b3a20cab9..cff6eabd449 100644 --- a/htdocs/takepos/admin/receipt.php +++ b/htdocs/takepos/admin/receipt.php @@ -48,6 +48,7 @@ if (GETPOST('action', 'alpha') == 'set') $res = dolibarr_set_const($db, "TAKEPOS_SHOW_CUSTOMER", GETPOST('TAKEPOS_SHOW_CUSTOMER', 'alpha'), 'chaine', 0, '', $conf->entity); $res = dolibarr_set_const($db, "TAKEPOS_AUTO_PRINT_TICKETS", GETPOST('TAKEPOS_AUTO_PRINT_TICKETS', 'int'), 'int', 0, '', $conf->entity); $res = dolibarr_set_const($db, "TAKEPOS_PRINT_SERVER", GETPOST('TAKEPOS_PRINT_SERVER', 'alpha'), 'chaine', 0, '', $conf->entity); + $res = dolibarr_set_const($db, "TAKEPOS_PRINT_PAYMENT_METHOD", GETPOST('TAKEPOS_PRINT_PAYMENT_METHOD', 'alpha'), 'chaine', 0, '', $conf->entity); dol_syslog("admin/cashdesk: level ".GETPOST('level', 'alpha')); @@ -216,6 +217,13 @@ if ($conf->global->TAKEPOS_PRINT_METHOD == "browser" || $conf->global->TAKEPOS_P print ''; print $form->selectyesno("TAKEPOS_SHOW_CUSTOMER", $conf->global->TAKEPOS_SHOW_CUSTOMER, 1); print "\n"; + + // Print payment method + print ''; + print $langs->trans('PrintPaymentMethodOnReceipts'); + print ''; + print $form->selectyesno("TAKEPOS_PRINT_PAYMENT_METHOD", $conf->global->TAKEPOS_PRINT_PAYMENT_METHOD, 1); + print "\n"; } // Auto print tickets diff --git a/htdocs/takepos/invoice.php b/htdocs/takepos/invoice.php index d4274d90444..a25c809b551 100644 --- a/htdocs/takepos/invoice.php +++ b/htdocs/takepos/invoice.php @@ -241,6 +241,7 @@ if ($action == 'valid' && $user->rights->facture->creer) $payment->datepaye = $now; $payment->fk_account = $bankaccount; $payment->amounts[$invoice->id] = $amountofpayment; + if ($pay == 'cash') $payment->pos_change = price2num(GETPOST('excess', 'alpha')); // If user has not used change control, add total invoice payment // Or if user has used change control and the amount of payment is higher than remain to pay, add the remain to pay diff --git a/htdocs/takepos/pay.php b/htdocs/takepos/pay.php index 0a1c60a5a57..f63aec61289 100644 --- a/htdocs/takepos/pay.php +++ b/htdocs/takepos/pay.php @@ -186,11 +186,12 @@ else print "var received=0;"; var invoiceid = 0 ? $invoiceid : 0); ?>; var accountid = $("#selectaccountid").val(); var amountpayed = $("#change1").val(); + var excess = $("#change2").val(); if (amountpayed > total_ttc; ?>) { amountpayed = total_ttc; ?>; } console.log("We click on the payment mode to pay amount = "+amountpayed); - parent.$("#poslines").load("invoice.php?place=&action=valid&pay="+payment+"&amount="+amountpayed+"&invoiceid="+invoiceid+"&accountid="+accountid, function() { + parent.$("#poslines").load("invoice.php?place=&action=valid&pay="+payment+"&amount="+amountpayed+"&excess="+excess+"&invoiceid="+invoiceid+"&accountid="+accountid, function() { if (amountpayed > || amountpayed == || amountpayed==0 ) parent.$.colorbox.close(); else location.reload(); }); diff --git a/htdocs/takepos/receipt.php b/htdocs/takepos/receipt.php index 99000c278de..c7ca395a316 100644 --- a/htdocs/takepos/receipt.php +++ b/htdocs/takepos/receipt.php @@ -181,6 +181,47 @@ if ($conf->global->TAKEPOS_SHOW_CUSTOMER) trans("TotalTTC").''.price($object->total_ttc, 1, '', 1, - 1, - 1, $conf->currency)."\n"; ?> +global->TAKEPOS_PRINT_PAYMENT_METHOD) { + $sql = "SELECT p.pos_change as pos_change, p.datep as date, p.fk_paiement, p.num_paiement as num, pf.amount as amount, pf.multicurrency_amount,"; + $sql .= " cp.code"; + $sql .= " FROM ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."paiement as p"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON p.fk_paiement = cp.id"; + $sql .= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".$facid; + $sql .= " ORDER BY p.datep"; + $resql = $db->query($sql); + if ($resql) + { + $num = $db->num_rows($resql); + $i = 0; + while ($i < $num) { + $row = $db->fetch_object($resql); + echo ''; + echo ''; + echo $langs->transnoentitiesnoconv("PaymentTypeShort".$row->code); + echo ''; + echo ''; + $amount_payment=($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount; + if ($row->code == "LIQ") $amount_payment = $amount_payment + $row->pos_change; // Show amount with excess received if is cash payment + echo price($amount_payment, 1, '', 1, - 1, - 1, $conf->currency); + echo ''; + echo ''; + if ($row->code == "LIQ" && $row->pos_change>0) // Print change only in cash payments + { + echo ''; + echo ''; + echo $langs->trans("Change"); + echo ''; + echo ''; + echo price($row->pos_change, 1, '', 1, - 1, - 1, $conf->currency); + echo ''; + echo ''; + } + $i++; + } + } +} +?>