From ed81d35e38c22309c6ddfe5132fc849267c15ec9 Mon Sep 17 00:00:00 2001 From: David Beniamine Date: Fri, 22 Mar 2019 09:06:44 +0100 Subject: [PATCH 1/8] Allow negative bills --- htdocs/takepos/invoice.php | 34 ++++++++++++++++++++++++++++++++++ htdocs/takepos/pay.php | 14 +++++++++----- 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/htdocs/takepos/invoice.php b/htdocs/takepos/invoice.php index 45a65af3f94..f8a51849412 100644 --- a/htdocs/takepos/invoice.php +++ b/htdocs/takepos/invoice.php @@ -41,6 +41,20 @@ $idline = GETPOST('idline'); $desc = GETPOST('desc', 'alpha'); $pay = GETPOST('pay'); +/** + * Abort invoice creationg with a given error message + * + * @param string $message Message explaining the error to the user + * @return void + */ +function fail($message) +{ + header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error', true, 500); + die($message); +} + + + $placeid = 0; // $placeid is id of invoice $invoice = new Facture($db); @@ -62,6 +76,26 @@ if ($action == 'valid' && $user->rights->facture->creer) $invoice = new Facture($db); $invoice->fetch($placeid); + if($invoice->total_ttc<0){ + $invoice->type= $invoice::TYPE_CREDIT_NOTE; + $sql="SELECT rowid FROM ".MAIN_DB_PREFIX."facture WHERE "; + $sql.="fk_soc = '".$invoice->socid."' "; + $sql.="AND type <> ".Facture::TYPE_CREDIT_NOTE." "; + $sql.="AND fk_statut >= ".$invoice::STATUS_VALIDATED." "; + $sql.="ORDER BY rowid DESC"; + $resql = $db->query($sql); + if($resql){ + $obj = $db->fetch_object($resql); + $fk_source=$obj->rowid; + if($fk_source == null){ + fail($langs->transnoentitiesnoconv("NoPreviousBillForCustomer")); + } + }else{ + fail($langs->transnoentitiesnoconv("NoPreviousBillForCustomer")); + } + $invoice->fk_facture_source=$fk_source; + $invoice->update($user); + } if (! empty($conf->stock->enabled) and $conf->global->CASHDESK_NO_DECREASE_STOCK!="1") $invoice->validate($user, '', $conf->global->CASHDESK_ID_WAREHOUSE); else $invoice->validate($user); diff --git a/htdocs/takepos/pay.php b/htdocs/takepos/pay.php index 33524b80a8c..7f8b300bb8b 100644 --- a/htdocs/takepos/pay.php +++ b/htdocs/takepos/pay.php @@ -66,7 +66,7 @@ $langs->loadLangs(array("main", "bills", "cashdesk")); $('#change1').html(parseFloat(received).toFixed(2)); if (parseFloat(received)>total_ttc;?>) { - var change=parseFloat(parseFloat(received)-total_ttc;?>); + var change=parseFloat(parseFloat(received)-(total_ttc;?>)); $('#change2').html(change.toFixed(2)); } } @@ -79,10 +79,14 @@ $langs->loadLangs(array("main", "bills", "cashdesk")); } function Validate(payment){ - parent.$("#poslines").load("invoice.php?place=&action=valid&pay="+payment, function() { - parent.$("#poslines").scrollTop(parent.$("#poslines")[0].scrollHeight); - parent.$.colorbox.close(); - }); + parent.$("#poslines").load("invoice.php?place=&action=valid&pay="+payment, function(response, status, xhr) { + if(status == "error"){ + alert(response); + }else{ + parent.$("#poslines").scrollTop(parent.$("#poslines")[0].scrollHeight); + parent.$.colorbox.close(); + } + }); } From 2c71b98d0dc6ef626acf225d631cda903c184054 Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Wed, 27 Mar 2019 11:05:43 +0100 Subject: [PATCH 2/8] NEW automatic / manual selector form --- htdocs/core/lib/functions.lib.php | 35 +++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 0937981164b..e8547792965 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -14,6 +14,7 @@ * Copyright (C) 2014-2015 Marcos García * Copyright (C) 2015 Jean-François Ferry * Copyright (C) 2018-2019 Frédéric France + * Copyright (C) 2019 Thibault Foucart * * 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 @@ -5211,6 +5212,40 @@ function yn($yesno, $case = 1, $color = 0) return $result; } +/** + * Return automatic or manual in current language + * + * @param string $automaticmanual Value to test (1, 'automatic', 'true' or 0, 'manual', 'false') + * @param integer $case 1=Yes/No, 0=yes/no, 2=Disabled checkbox, 3=Disabled checkbox + Automatic/Manual + * @param int $color 0=texte only, 1=Text is formated with a color font style ('ok' or 'error'), 2=Text is formated with 'ok' color. + * @return string HTML string + */ +function am($automaticmanual, $case = 1, $color = 0) +{ + global $langs; + $result='unknown'; $classname=''; + if ($automaticmanual == 1 || strtolower($automaticmanual) == 'automatic' || strtolower($automaticmanual) == 'true') // A mettre avant test sur no a cause du == 0 + { + $result=$langs->trans('automatic'); + if ($case == 1 || $case == 3) $result=$langs->trans("Automatic"); + if ($case == 2) $result=''; + if ($case == 3) $result=' '.$result; + + $classname='ok'; + } + elseif ($yesno == 0 || strtolower($automaticmanual) == 'manual' || strtolower($automaticmanual) == 'false') + { + $result=$langs->trans("manual"); + if ($case == 1 || $case == 3) $result=$langs->trans("Manual"); + if ($case == 2) $result=''; + if ($case == 3) $result=' '.$result; + + if ($color == 2) $classname='ok'; + else $classname='error'; + } + if ($color) return ''.$result.''; + return $result; +} /** * Return a path to have a the directory according to object where files are stored. From 2cc9b61a9fdc0ba48f4cdd189b9ec2b87ed833ec Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Wed, 27 Mar 2019 11:10:30 +0100 Subject: [PATCH 3/8] Update html.form.class.php --- htdocs/core/class/html.form.class.php | 39 +++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 4f61435f124..85a4f1922b0 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -21,6 +21,7 @@ * Copyright (C) 2018 Nicolas ZABOURI * Copyright (C) 2018 Christophe Battarel * Copyright (C) 2018 Josep Lluis Amador + * Copyright (C) 2019 Thibault FOUCART * * 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 @@ -6774,7 +6775,45 @@ class Form return $resultyesno; } + /** + * Return an html string with a select combo box to choose yes or no + * + * @param string $htmlname Name of html select field + * @param string $value Pre-selected value + * @param int $option 0 return automatic/manual, 1 return 1/0 + * @param bool $disabled true or false + * @param int $useempty 1=Add empty line + * @return string See option + */ + public function selectautomanual($htmlname, $value = '', $option = 0, $disabled = false, $useempty = 0) + { + global $langs; + $automatic="automatic"; $manual="manual"; + if ($option) + { + $automatic="1"; + $manual="0"; + } + + $disabled = ($disabled ? ' disabled' : ''); + + $resultautomanual = ''."\n"; + return $resultautomanual; + } // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** From a8286eb1002c30d792c94777b4f685db76dab2bd Mon Sep 17 00:00:00 2001 From: David Beniamine Date: Thu, 28 Mar 2019 08:13:02 +0100 Subject: [PATCH 4/8] Fix CI --- htdocs/takepos/invoice.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/takepos/invoice.php b/htdocs/takepos/invoice.php index 3846829b6e9..9247cdb4d70 100644 --- a/htdocs/takepos/invoice.php +++ b/htdocs/takepos/invoice.php @@ -83,7 +83,7 @@ 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; - else + else { $accountname="CASHDESK_ID_BANKACCOUNT_".$pay; $bankaccount=$conf->global->$accountname; From 42bd9f4c74bd01ece8b17dfb56597dc179bd6c67 Mon Sep 17 00:00:00 2001 From: David Beniamine Date: Thu, 28 Mar 2019 08:58:19 +0100 Subject: [PATCH 5/8] Fix CI again --- htdocs/takepos/invoice.php | 1 - 1 file changed, 1 deletion(-) diff --git a/htdocs/takepos/invoice.php b/htdocs/takepos/invoice.php index 139a8463b6f..4b52309aa1b 100644 --- a/htdocs/takepos/invoice.php +++ b/htdocs/takepos/invoice.php @@ -512,7 +512,6 @@ if ($placeid > 0) else { print ''.$langs->trans("Empty").''; - } } From 1a228ed95cc6b60876185bd0aa8b945a147d8ac8 Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Sun, 31 Mar 2019 19:25:45 +0200 Subject: [PATCH 6/8] transfert to html.otherform.class.php --- htdocs/core/class/html.form.class.php | 41 --------------------------- 1 file changed, 41 deletions(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 85a4f1922b0..374fdfcfbaa 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -21,7 +21,6 @@ * Copyright (C) 2018 Nicolas ZABOURI * Copyright (C) 2018 Christophe Battarel * Copyright (C) 2018 Josep Lluis Amador - * Copyright (C) 2019 Thibault FOUCART * * 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 @@ -6775,46 +6774,6 @@ class Form return $resultyesno; } - /** - * Return an html string with a select combo box to choose yes or no - * - * @param string $htmlname Name of html select field - * @param string $value Pre-selected value - * @param int $option 0 return automatic/manual, 1 return 1/0 - * @param bool $disabled true or false - * @param int $useempty 1=Add empty line - * @return string See option - */ - public function selectautomanual($htmlname, $value = '', $option = 0, $disabled = false, $useempty = 0) - { - global $langs; - - $automatic="automatic"; $manual="manual"; - if ($option) - { - $automatic="1"; - $manual="0"; - } - - $disabled = ($disabled ? ' disabled' : ''); - - $resultautomanual = ''."\n"; - return $resultautomanual; - } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Return list of export templates From 13c93ba1c280a881313d10103236e24495f5e1f0 Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Sun, 31 Mar 2019 19:26:40 +0200 Subject: [PATCH 7/8] transfert from html.form.class.php --- htdocs/core/class/html.formother.class.php | 41 ++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/htdocs/core/class/html.formother.class.php b/htdocs/core/class/html.formother.class.php index 3957e44daf5..200a0d1f9f3 100644 --- a/htdocs/core/class/html.formother.class.php +++ b/htdocs/core/class/html.formother.class.php @@ -9,6 +9,7 @@ * Copyright (C) 2006 Marc Barilley/Ocebo * Copyright (C) 2007 Franky Van Liedekerke * Copyright (C) 2007 Patrick Raguin + * Copyright (C) 2019 Thibault FOUCART * * 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 @@ -1232,4 +1233,44 @@ class FormOther dol_print_error($this->db); } } + + /** + * Return an html string with a select combo box to choose yes or no + * + * @param string $htmlname Name of html select field + * @param string $value Pre-selected value + * @param int $option 0 return automatic/manual, 1 return 1/0 + * @param bool $disabled true or false + * @param int $useempty 1=Add empty line + * @return string See option + */ + public function selectautomanual($htmlname, $value = '', $option = 0, $disabled = false, $useempty = 0) + { + global $langs; + + $automatic="automatic"; $manual="manual"; + if ($option) + { + $automatic="1"; + $manual="0"; + } + + $disabled = ($disabled ? ' disabled' : ''); + + $resultautomanual = ''."\n"; + return $resultautomanual; + } } From 69b04e2189161fd092445816ec00ffe36e7359c0 Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Sun, 31 Mar 2019 19:28:45 +0200 Subject: [PATCH 8/8] Update html.formother.class.php --- htdocs/core/class/html.formother.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/class/html.formother.class.php b/htdocs/core/class/html.formother.class.php index 200a0d1f9f3..546b57b4a5f 100644 --- a/htdocs/core/class/html.formother.class.php +++ b/htdocs/core/class/html.formother.class.php @@ -1244,7 +1244,7 @@ class FormOther * @param int $useempty 1=Add empty line * @return string See option */ - public function selectautomanual($htmlname, $value = '', $option = 0, $disabled = false, $useempty = 0) + public function selectAutoManual($htmlname, $value = '', $option = 0, $disabled = false, $useempty = 0) { global $langs;