From 2e8fd25299c7f7d10b0c1a067f03cfb6e839b77e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 1 Jan 2020 21:54:47 +0100 Subject: [PATCH] FIX Local taxes was not correctly supported in TakePOS. --- htdocs/compta/facture/card.php | 2 +- htdocs/core/lib/functions.lib.php | 1 + htdocs/product/class/product.class.php | 38 +++++++------- htdocs/takepos/invoice.php | 70 +++++++++++++++++--------- htdocs/takepos/takepos.php | 10 +++- 5 files changed, 74 insertions(+), 47 deletions(-) diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index 4f9229bf839..3f3bffc6cd2 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -1537,7 +1537,7 @@ if (empty($reshook)) if (!empty($lines[$i]->vat_src_code) && !preg_match('/\(/', $tva_tx)) $tva_tx .= ' ('.$lines[$i]->vat_src_code.')'; // View third's localtaxes for NOW and do not use value from origin. - // TODO Is this really what we want ? Yes if source if template invoice but what if proposal or order ? + // TODO Is this really what we want ? Yes if source is template invoice but what if proposal or order ? $localtax1_tx = get_localtax($tva_tx, 1, $object->thirdparty); $localtax2_tx = get_localtax($tva_tx, 2, $object->thirdparty); diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 7d82336dd16..eb58b94c7c2 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -4677,6 +4677,7 @@ function get_localtax($vatrate, $local, $thirdparty_buyer = "", $thirdparty_sell dol_syslog("get_localtax tva=".$vatrate." local=".$local." thirdparty_buyer id=".(is_object($thirdparty_buyer) ? $thirdparty_buyer->id : '')."/country_code=".(is_object($thirdparty_buyer) ? $thirdparty_buyer->country_code : '')." thirdparty_seller id=".$thirdparty_seller->id."/country_code=".$thirdparty_seller->country_code." thirdparty_seller localtax1_assuj=".$thirdparty_seller->localtax1_assuj." thirdparty_seller localtax2_assuj=".$thirdparty_seller->localtax2_assuj); $vatratecleaned = $vatrate; + $reg = array(); if (preg_match('/^(.*)\s*\((.*)\)$/', $vatrate, $reg)) // If vat is "xx (yy)" { $vatratecleaned = trim($reg[1]); diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 9e100871537..ca0f8112fc1 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -1597,26 +1597,25 @@ class Product extends CommonObject * @param Societe $thirdparty_seller Seller * @param Societe $thirdparty_buyer Buyer * @param int $pqp Id of product per price if a selection was done of such a price - * @return array Array of price information + * @return array Array of price information array('pu_ht'=> , 'pu_ttc'=> , 'tva_tx'=>'X.Y (code)', ...), 'tva_npr'=>0, ...) * @see get_buyprice(), find_min_price_product_fournisseur() */ public function getSellPrice($thirdparty_seller, $thirdparty_buyer, $pqp = 0) { global $conf, $db; - // Update if prices fields are defined - $tva_tx = get_default_tva($thirdparty_seller, $thirdparty_buyer, $this->id); - $tva_npr = get_default_npr($thirdparty_seller, $thirdparty_buyer, $this->id); - if (empty($tva_tx)) $tva_npr = 0; + // Update if prices fields are defined + $tva_tx = get_default_tva($thirdparty_seller, $thirdparty_buyer, $this->id); + $tva_npr = get_default_npr($thirdparty_seller, $thirdparty_buyer, $this->id); + if (empty($tva_tx)) $tva_npr = 0; - $pu_ht = $this->price; - $pu_ttc = $this->price_ttc; - $price_min = $this->price_min; - $price_base_type = $this->price_base_type; + $pu_ht = $this->price; + $pu_ttc = $this->price_ttc; + $price_min = $this->price_min; + $price_base_type = $this->price_base_type; - // If price per segment - if (!empty($conf->global->PRODUIT_MULTIPRICES) && !empty($thirdparty_buyer->price_level)) - { + // If price per segment + if (!empty($conf->global->PRODUIT_MULTIPRICES) && !empty($thirdparty_buyer->price_level)) { $pu_ht = $this->multiprices[$thirdparty_buyer->price_level]; $pu_ttc = $this->multiprices_ttc[$thirdparty_buyer->price_level]; $price_min = $this->multiprices_min[$thirdparty_buyer->price_level]; @@ -1628,9 +1627,8 @@ class Product extends CommonObject if (empty($tva_tx)) $tva_npr = 0; } } - // If price per customer - elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) - { + // If price per customer + elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) { require_once DOL_DOCUMENT_ROOT.'/product/class/productcustomerprice.class.php'; $prodcustprice = new Productcustomerprice($db); @@ -1650,9 +1648,8 @@ class Product extends CommonObject } } } - // If price per quantity - elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY)) - { + // If price per quantity + elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY)) { if ($this->prices_by_qty[0]) // yes, this product has some prices per quantity { // Search price into product_price_by_qty from $this->id @@ -1672,9 +1669,8 @@ class Product extends CommonObject } } } - // If price per quantity and customer - elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) - { + // If price per quantity and customer + elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) { if ($this->prices_by_qty[$thirdparty_buyer->price_level]) // yes, this product has some prices per quantity { // Search price into product_price_by_qty from $this->id diff --git a/htdocs/takepos/invoice.php b/htdocs/takepos/invoice.php index 23bc09a7268..f684d18741d 100644 --- a/htdocs/takepos/invoice.php +++ b/htdocs/takepos/invoice.php @@ -43,6 +43,7 @@ $id = GETPOST('id', 'int'); $action = GETPOST('action', 'alpha'); $idproduct = GETPOST('idproduct', 'int'); $place = (GETPOST('place', 'int') > 0 ? GETPOST('place', 'int') : 0); // $place is id of table for Bar or Restaurant +$placeid = 0; // $placeid is ID of invoice if ($conf->global->TAKEPOS_PHONE_BASIC_LAYOUT == 1 && $conf->browser->layout == 'phone') { @@ -83,8 +84,6 @@ function fail($message) -$placeid = 0; // $placeid is id of invoice - $number = GETPOST('number', 'alpha'); $idline = GETPOST('idline', 'int'); $desc = GETPOST('desc', 'alpha'); @@ -121,6 +120,12 @@ if ($ret > 0) $placeid = $invoice->id; } +$constforcompanyid = 'CASHDESK_ID_THIRDPARTY'.$_SESSION["takeposterminal"]; + +$soc = new Societe($db); +if ($invoice->socid > 0) $soc->fetch($invoice->socid); +else $soc->fetch($conf->global->$constforcompanyid); + /* * Actions @@ -233,7 +238,7 @@ if ($action == 'history') if (($action == "addline" || $action == "freezone") && $placeid == 0) { - $invoice->socid = $conf->global->{'CASHDESK_ID_THIRDPARTY'.$_SESSION["takeposterminal"]}; + $invoice->socid = $conf->global->$constforcompanyid; $invoice->date = dol_now(); $invoice->module_source = 'takepos'; $invoice->pos_source = $_SESSION["takeposterminal"]; @@ -263,27 +268,34 @@ if ($action == "addline") $customer = new Societe($db); $customer->fetch($invoice->socid); - $price = $prod->price; - $tva_tx = $prod->tva_tx; - $price_ttc = $prod->price_ttc; - $price_base_type = $prod->price_base_type; + $datapriceofproduct = $prod->getSellPrice($mysoc, $customer, 0); - if (!empty($conf->global->PRODUIT_MULTIPRICES)) - { - $price = $prod->multiprices[$customer->price_level]; - $tva_tx = $prod->multiprices_tva_tx[$customer->price_level]; - $price_ttc = $prod->multiprices_ttc[$customer->price_level]; - $price_base_type = $prod->multiprices_base_type[$customer->price_level]; - } + $price = $datapriceofproduct['pu_ht']; + $price_ttc = $datapriceofproduct['pu_ttc']; + //$price_min = $datapriceofproduct['price_min']; + $price_base_type = $datapriceofproduct['price_base_type']; + $tva_tx = $datapriceofproduct['tva_tx']; + $tva_npr = $datapriceofproduct['tva_npr']; - $idoflineadded = $invoice->addline($prod->description, $price, 1, $tva_tx, $prod->localtax1_tx, $prod->localtax2_tx, $idproduct, $customer->remise_percent, '', 0, 0, 0, '', $price_base_type, $price_ttc, $prod->type, -1, 0, '', 0, 0, null, 0, '', 0, 100, '', null, 0); + // Local Taxes + $localtax1_tx = get_localtax($tva_tx, 1, $customer, $mysoc, $tva_npr); + $localtax2_tx = get_localtax($tva_tx, 2, $customer, $mysoc, $tva_npr); + + $idoflineadded = $invoice->addline($prod->description, $price, 1, $tva_tx, $localtax1_tx, $localtax2_tx, $idproduct, $customer->remise_percent, '', 0, 0, 0, '', $price_base_type, $price_ttc, $prod->type, -1, 0, '', 0, 0, null, 0, '', 0, 100, '', null, 0); $invoice->fetch($placeid); } if ($action == "freezone") { $customer = new Societe($db); $customer->fetch($invoice->socid); - $invoice->addline($desc, $number, 1, get_default_tva($mysoc, $customer), 0, 0, 0, 0, '', 0, 0, 0, '', 'TTC', $number, 0, -1, 0, '', 0, 0, null, 0, '', 0, 100, '', null, 0); + + $tva_tx = get_default_tva($mysoc, $customer); + + // Local Taxes + $localtax1_tx = get_localtax($tva_tx, 1, $customer, $mysoc, $tva_npr); + $localtax2_tx = get_localtax($tva_tx, 2, $customer, $mysoc, $tva_npr); + + $invoice->addline($desc, $number, 1, $tva_tx, $localtax1_tx, $localtax2_tx, 0, 0, '', 0, 0, 0, '', 'TTC', $number, 0, -1, 0, '', 0, 0, null, 0, '', 0, 100, '', null, 0); $invoice->fetch($placeid); } @@ -392,7 +404,8 @@ if ($action == "order" and $placeid != 0) $catsprinter2 = explode(';', $conf->global->TAKEPOS_PRINTED_CATEGORIES_2); foreach ($invoice->lines as $line) { - if ($line->special_code == "4") { continue; + if ($line->special_code == "4") { + continue; } $c = new Categorie($db); $existing = $c->containing($line->fk_product, Categorie::TYPE_PRODUCT, 'id'); @@ -409,7 +422,8 @@ if ($action == "order" and $placeid != 0) foreach ($invoice->lines as $line) { - if ($line->special_code == "4") { continue; + if ($line->special_code == "4") { + continue; } $c = new Categorie($db); $existing = $c->containing($line->fk_product, Categorie::TYPE_PRODUCT, 'id'); @@ -618,6 +632,7 @@ if ($_SESSION["basiclayout"] != 1) } print "\n"; + if ($_SESSION["basiclayout"] == 1) { if ($mobilepage == "cats") @@ -720,10 +735,20 @@ if ($placeid > 0) if (!empty($line->array_options['options_order_notes'])) $htmlforlines .= "
(".$line->array_options['options_order_notes'].")"; if ($_SESSION["basiclayout"] != 1) { + $moreinfo = ''; + $moreinfo .= $langs->transcountry("TotalHT", $mysoc->country_code).': '.price($line->total_ht); + if ($line->vat_src_code) $moreinfo .= '
'.$langs->trans("VATCode").': '.$line->vat_src_code; + $moreinfo .= '
'.$langs->transcountry("TotalVAT", $mysoc->country_code).': '.price($line->total_vat); + //$moreinfo .= '
'.$langs->transcountry("VATRate", $mysoc->country_code).': '.price($line->); + $moreinfo .= '
'.$langs->transcountry("TotalLT1", $mysoc->country_code).': '.price($line->total_localtax1); + $moreinfo .= '
'.$langs->transcountry("TotalLT2", $mysoc->country_code).': '.price($line->total_localtax2); + $moreinfo .= '
'.$langs->transcountry("TotalTTC", $mysoc->country_code).': '.price($line->total_ttc); + //$moreinfo .= $langs->trans("TotalHT").': '.$line->total_ht; + $htmlforlines .= ''; $htmlforlines .= ''.vatrate($line->remise_percent, true).''; $htmlforlines .= ''.$line->qty.''; - $htmlforlines .= ''.price($line->total_ttc).''; + $htmlforlines .= ''.price($line->total_ttc).''; } $htmlforlines .= ''."\n"; @@ -741,12 +766,9 @@ else { // No invoice generated yet print ''; -if ($invoice->socid != $conf->global->{'CASHDESK_ID_THIRDPARTY'.$_SESSION["takeposterminal"]}) + +if ($invoice->socid != $conf->global->$constforcompanyid) { - $constforcompanyid = 'CASHDESK_ID_THIRDPARTY'.$_SESSION["takeposterminal"]; - $soc = new Societe($db); - if ($invoice->socid > 0) $soc->fetch($invoice->socid); - else $soc->fetch($conf->global->$constforcompanyid); print ''; print '

'; print $langs->trans("Customer").': '.$soc->name; diff --git a/htdocs/takepos/takepos.php b/htdocs/takepos/takepos.php index fed82019d62..4662681217e 100644 --- a/htdocs/takepos/takepos.php +++ b/htdocs/takepos/takepos.php @@ -34,11 +34,12 @@ if (!defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1'); require '../main.inc.php'; // Load $user and permissions require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php'; +require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; -$place = (GETPOST('place', 'int') > 0 ? GETPOST('place', 'int') : 0); // $place is id of table for Ba or Restaurant +$place = (GETPOST('place', 'int') > 0 ? GETPOST('place', 'int') : 0); // $place is id of table for Bar or Restaurant $action = GETPOST('action', 'alpha'); $setterminal = GETPOST('setterminal', 'int'); @@ -70,6 +71,13 @@ if ($conf->browser->layout == 'phone') $MAXCATEG = (empty($conf->global->TAKEPOS_NB_MAXCATEG) ? $maxcategbydefaultforthisdevice : $conf->global->TAKEPOS_NB_MAXCATEG); $MAXPRODUCT = (empty($conf->global->TAKEPOS_NB_MAXPRODUCT) ? $maxproductbydefaultforthisdevice : $conf->global->TAKEPOS_NB_MAXPRODUCT); +/* +$constforcompanyid = 'CASHDESK_ID_THIRDPARTY'.$_SESSION["takeposterminal"]; +$soc = new Societe($db); +if ($invoice->socid > 0) $soc->fetch($invoice->socid); +else $soc->fetch($conf->global->$constforcompanyid); +*/ + /* * View