From 4f3d4950e1ba0439fc73a6e59f000753d82ca56d Mon Sep 17 00:00:00 2001 From: andreubisquerra Date: Tue, 12 Nov 2019 13:01:16 +0100 Subject: [PATCH 1/4] Check if draft exists in TakePOS customer list Check if draft invoice already exists, if not create it --- htdocs/societe/list.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/htdocs/societe/list.php b/htdocs/societe/list.php index afd4c89aab5..bbe9f6a9424 100644 --- a/htdocs/societe/list.php +++ b/htdocs/societe/list.php @@ -231,7 +231,25 @@ if ($action == "change") // Change customer for TakePOS $idcustomer = GETPOST('idcustomer', 'int'); $place = (GETPOST('place', 'int') > 0 ? GETPOST('place', 'int') : 0); // $place is id of table for Ba or Restaurant - // @TODO Check if draft invoice already exists, if not create it or return a warning to ask to enter at least one line to have it created automatically + // Check if draft invoice already exists, if not create it + $sql = 'SELECT * FROM '.MAIN_DB_PREFIX.'facture + where ref=\'(PROV-POS'.$_SESSION["takeposterminal"].'-'.$place.')\' + AND entity IN ('.getEntity('invoice').')'; + $result = $db->query($sql); + $num_lines = $db->num_rows($result); + if ($num_lines==0) + { + require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php'; + $invoice = new Facture($db); + $invoice->socid = $conf->global->{'CASHDESK_ID_THIRDPARTY'.$_SESSION["takeposterminal"]}; + $invoice->date = dol_now(); + $invoice->module_source = 'takepos'; + $invoice->pos_source = $_SESSION["takeposterminal"]; + $placeid =$invoice->create($user); + $sql="UPDATE ".MAIN_DB_PREFIX."facture set ref='(PROV-POS".$_SESSION["takeposterminal"]."-".$place.")' where rowid=".$placeid; + $db->query($sql); + } + $sql = "UPDATE ".MAIN_DB_PREFIX."facture set fk_soc=".$idcustomer." where ref='(PROV-POS".$_SESSION["takeposterminal"]."-".$place.")'"; $resql = $db->query($sql); ?> From 34b832507959882da8c70467aea8d6fd551e95e5 Mon Sep 17 00:00:00 2001 From: andreubisquerra Date: Tue, 12 Nov 2019 14:21:49 +0100 Subject: [PATCH 2/4] Update list.php --- htdocs/societe/list.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/societe/list.php b/htdocs/societe/list.php index bbe9f6a9424..a62dde1d79d 100644 --- a/htdocs/societe/list.php +++ b/htdocs/societe/list.php @@ -249,7 +249,7 @@ if ($action == "change") // Change customer for TakePOS $sql="UPDATE ".MAIN_DB_PREFIX."facture set ref='(PROV-POS".$_SESSION["takeposterminal"]."-".$place.")' where rowid=".$placeid; $db->query($sql); } - + $sql = "UPDATE ".MAIN_DB_PREFIX."facture set fk_soc=".$idcustomer." where ref='(PROV-POS".$_SESSION["takeposterminal"]."-".$place.")'"; $resql = $db->query($sql); ?> From cc70ffd1b36dc8b25398d7bfd9361570d1cb4ac8 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 13 Nov 2019 18:47:35 +0100 Subject: [PATCH 3/4] Update list.php --- htdocs/societe/list.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/htdocs/societe/list.php b/htdocs/societe/list.php index a62dde1d79d..da5d4c268fd 100644 --- a/htdocs/societe/list.php +++ b/htdocs/societe/list.php @@ -232,9 +232,7 @@ if ($action == "change") // Change customer for TakePOS $place = (GETPOST('place', 'int') > 0 ? GETPOST('place', 'int') : 0); // $place is id of table for Ba or Restaurant // Check if draft invoice already exists, if not create it - $sql = 'SELECT * FROM '.MAIN_DB_PREFIX.'facture - where ref=\'(PROV-POS'.$_SESSION["takeposterminal"].'-'.$place.')\' - AND entity IN ('.getEntity('invoice').')'; + $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."facture where ref='(PROV-POS".$_SESSION["takeposterminal"]."-".$place.")' AND entity IN (".getEntity('invoice').")"; $result = $db->query($sql); $num_lines = $db->num_rows($result); if ($num_lines==0) From a14042e4b21b04566dedde76830d26f2c1ac6d9f Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 13 Nov 2019 18:48:39 +0100 Subject: [PATCH 4/4] Update list.php --- htdocs/societe/list.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/htdocs/societe/list.php b/htdocs/societe/list.php index da5d4c268fd..504ccb37a25 100644 --- a/htdocs/societe/list.php +++ b/htdocs/societe/list.php @@ -239,7 +239,8 @@ if ($action == "change") // Change customer for TakePOS { require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php'; $invoice = new Facture($db); - $invoice->socid = $conf->global->{'CASHDESK_ID_THIRDPARTY'.$_SESSION["takeposterminal"]}; + $constforthirdpartyid = 'CASHDESK_ID_THIRDPARTY'.$_SESSION["takeposterminal"]; + $invoice->socid = $conf->global->$constforthirdpartyid; $invoice->date = dol_now(); $invoice->module_source = 'takepos'; $invoice->pos_source = $_SESSION["takeposterminal"];