diff --git a/htdocs/takepos/invoice.php b/htdocs/takepos/invoice.php index ef829863a17..cba620f4048 100644 --- a/htdocs/takepos/invoice.php +++ b/htdocs/takepos/invoice.php @@ -1,5 +1,6 @@ +/** + * Copyright (C) 2018 Andreu Bisquerra * * 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 @@ -15,46 +16,55 @@ * along with this program. If not, see . */ -//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'); -//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1'); -if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK','1'); -if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1'); -if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1'); -if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1'); -if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1'); +// 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'); +// if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1'); +if (!defined('NOCSRFCHECK')) { define('NOCSRFCHECK', '1'); } +if (!defined('NOTOKENRENEWAL')) { define('NOTOKENRENEWAL', '1'); } +if (!defined('NOREQUIREMENU')) { define('NOREQUIREMENU', '1'); } +if (!defined('NOREQUIREHTML')) { define('NOREQUIREHTML', '1'); } +if (!defined('NOREQUIREAJAX')) { define('NOREQUIREAJAX', '1'); } +require '../main.inc.php'; -require '../main.inc.php'; // Load $user and permissions -require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; -require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php'; + // Load $user and permissions -$langs->loadLangs(array("bills", "cashdesk")); +require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php'; -$id = GETPOST('id','int'); -$action = GETPOST('action','alpha'); -$idproduct = GETPOST('idproduct','int'); -$place = GETPOST('place','int'); +require_once DOL_DOCUMENT_ROOT . '/compta/paiement/class/paiement.class.php'; + +$langs->loadLangs( + array( + "bills", + "cashdesk" + ) +); +$id = GETPOST('id', 'int'); +$action = GETPOST('action', 'alpha'); +$idproduct = GETPOST('idproduct', 'int'); +$place = GETPOST('place', 'int'); $number = GETPOST('number'); $idline = GETPOST('idline'); -$desc = GETPOST('desc','alpha'); +$desc = GETPOST('desc', 'alpha'); $pay = GETPOST('pay'); - $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; // not necesary -else{ - $invoice = new Facture($db); - $invoice->fetch($placeid); +$row = $db->fetch_array($resql); +$placeid = $row[0]; + +if (!$placeid) { $placeid = 0; // not necesary +} else +{ + $invoice = new Facture($db); + $invoice->fetch($placeid); } /* - * Actions - */ +* Actions +*/ -if ($action == 'valid' && $user->rights->facture->creer){ +if ($action == 'valid' && $user->rights->facture->creer) +{ if ($pay=="cash") $bankaccount=$conf->global->CASHDESK_ID_BANKACCOUNT_CASH; else if ($pay=="card") $bankaccount=$conf->global->CASHDESK_ID_BANKACCOUNT_CB; else if ($pay=="cheque") $bankaccount=$conf->global->CASHDESK_ID_BANKACCOUNT_CHEQUE; @@ -68,19 +78,23 @@ if ($action == 'valid' && $user->rights->facture->creer){ $payment->datepaye=$now; $payment->bank_account=$bankaccount; $payment->amounts[$invoice->id]=$invoice->total_ttc; - if ($pay=="cash") $payment->paiementid=4; + + if ($pay=="cash") $payment->paiementid=4; else if ($pay=="card") $payment->paiementid=6; else if ($pay=="cheque") $payment->paiementid=7; $payment->num_paiement=$invoice->ref; - $payment->create($user); + + $payment->create($user); $payment->addPaymentToBank($user, 'payment', '(CustomerInvoicePayment)', $bankaccount, '', ''); - $invoice->set_paid($user); + + $invoice->set_paid($user); } -if (($action=="addline" || $action=="freezone") and $placeid==0) +if (($action=="addline" || $action=="freezone") && $placeid==0) { // $place is id of POS, $placeid is id of invoice - if ($placeid==0) { + if ($placeid==0) + { $invoice = new Facture($db); $invoice->socid=$conf->global->CASHDESK_ID_THIRDPARTY; $invoice->date=dol_now(); @@ -94,105 +108,176 @@ if (($action=="addline" || $action=="freezone") and $placeid==0) } } -if ($action=="addline"){ - $prod = new Product($db); - $prod->fetch($idproduct); - $invoice->addline($prod->description, $prod->price, 1, $prod->tva_tx, $prod->localtax1_tx, $prod->localtax2_tx, $idproduct, $prod->remise_percent, '', 0, 0, 0, '', $prod->price_base_type, $prod->price_ttc, $prod->type, - 1, 0, '', 0, 0, null, 0, '', 0, 100, '', null, 0); - $invoice->fetch($placeid); +if ($action == "addline") { + $prod = new Product($db); + $prod->fetch($idproduct); + $invoice->addline($prod->description, $prod->price, 1, $prod->tva_tx, $prod->localtax1_tx, $prod->localtax2_tx, $idproduct, $prod->remise_percent, '', 0, 0, 0, '', $prod->price_base_type, $prod->price_ttc, $prod->type, -1, 0, '', 0, 0, null, 0, '', 0, 100, '', null, 0); + $invoice->fetch($placeid); } -if ($action=="freezone"){ - $invoice->addline($desc, $number, 1, $conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS, 0, 0, 0, 0, '', 0, 0, 0, '', 'TTC', $number, 0, - 1, 0, '', 0, 0, null, 0, '', 0, 100, '', null, 0); - $invoice->fetch($placeid); +if ($action == "freezone") { + $invoice->addline($desc, $number, 1, $conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS, 0, 0, 0, 0, '', 0, 0, 0, '', 'TTC', $number, 0, -1, 0, '', 0, 0, null, 0, '', 0, 100, '', null, 0); + $invoice->fetch($placeid); } -if ($action=="deleteline"){ - if ($idline>0 and $placeid>0){ //If exist invoice and line, to avoid errors if deleted from other device or no line selected +if ($action == "deleteline") { + if ($idline > 0 and $placeid > 0) { //If exist invoice and line, to avoid errors if deleted from other device or no line selected $invoice->deleteline($idline); $invoice->fetch($placeid); } - else if ($placeid>0){ //If exist invoice, but no line selected, proced to delete last line - $sql="SELECT rowid FROM ".MAIN_DB_PREFIX."facturedet where fk_facture='$placeid' order by rowid DESC"; + else + if ($placeid > 0) { //If exist invoice, but no line selected, proced to delete last line + $sql = "SELECT rowid FROM " . MAIN_DB_PREFIX . "facturedet where fk_facture='$placeid' order by rowid DESC"; $resql = $db->query($sql); - $row = $db->fetch_array ($resql); - $deletelineid=$row[0]; + $row = $db->fetch_array($resql); + $deletelineid = $row[0]; $invoice->deleteline($deletelineid); $invoice->fetch($placeid); } } -if ($action=="updateqty"){ - foreach ($invoice->lines as $line){ - if ($line->id==$idline) $result = $invoice->updateline($line->id, $line->desc, $line->subprice, $number, $line->remise_percent, - $line->date_start, $line->date_end, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, 'HT', $line->info_bits, $line->product_type, - $line->fk_parent_line, 0, $line->fk_fournprice, $line->pa_ht, $line->label, $line->special_code, $line->array_options, $line->situation_percent, - $line->fk_unit); +if ($action == "updateqty") { + foreach($invoice->lines as $line) + { + if ($line->id == $idline) { $result = $invoice->updateline($line->id, $line->desc, $line->subprice, $number, $line->remise_percent, $line->date_start, $line->date_end, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, 'HT', $line->info_bits, $line->product_type, $line->fk_parent_line, 0, $line->fk_fournprice, $line->pa_ht, $line->label, $line->special_code, $line->array_options, $line->situation_percent, $line->fk_unit); + } } - $invoice->fetch($placeid); + + $invoice->fetch($placeid); } -if ($action=="updateprice"){ - foreach ($invoice->lines as $line){ - if ($line->id==$idline) $result = $invoice->updateline($line->id, $line->desc, $number, $line->qty, $line->remise_percent, - $line->date_start, $line->date_end, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, 'HT', $line->info_bits, $line->product_type, - $line->fk_parent_line, 0, $line->fk_fournprice, $line->pa_ht, $line->label, $line->special_code, $line->array_options, $line->situation_percent, - $line->fk_unit); +if ($action == "updateprice") { + foreach($invoice->lines as $line) + { + if ($line->id == $idline) { $result = $invoice->updateline($line->id, $line->desc, $number, $line->qty, $line->remise_percent, $line->date_start, $line->date_end, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, 'HT', $line->info_bits, $line->product_type, $line->fk_parent_line, 0, $line->fk_fournprice, $line->pa_ht, $line->label, $line->special_code, $line->array_options, $line->situation_percent, $line->fk_unit); + } } - $invoice->fetch($placeid); + + $invoice->fetch($placeid); } -if ($action=="updatereduction"){ - foreach ($invoice->lines as $line){ - if ($line->id==$idline) $result = $invoice->updateline($line->id, $line->desc, $line->subprice, $line->qty, $number, - $line->date_start, $line->date_end, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, 'HT', $line->info_bits, $line->product_type, - $line->fk_parent_line, 0, $line->fk_fournprice, $line->pa_ht, $line->label, $line->special_code, $line->array_options, $line->situation_percent, - $line->fk_unit); +if ($action == "updatereduction") { + foreach($invoice->lines as $line) + { + if ($line->id == $idline) { $result = $invoice->updateline($line->id, $line->desc, $line->subprice, $line->qty, $number, $line->date_start, $line->date_end, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, 'HT', $line->info_bits, $line->product_type, $line->fk_parent_line, 0, $line->fk_fournprice, $line->pa_ht, $line->label, $line->special_code, $line->array_options, $line->situation_percent, $line->fk_unit); + } } - $invoice->fetch($placeid); + + $invoice->fetch($placeid); } -if ($action=="order" and $placeid!=0){ - require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php'; - $headerorder='
'.$langs->trans('Place').' '.$place.'
'; - $footerorder='
'.$langs->trans("Label").''.$langs->trans("Qty").'
'.dol_print_date(dol_now(), 'dayhour').'
'; - $order_receipt_printer1=""; - $order_receipt_printer2=""; - $catsprinter1 = explode(';',$conf->global->TAKEPOS_PRINTED_CATEGORIES_1); - $catsprinter2 = explode(';',$conf->global->TAKEPOS_PRINTED_CATEGORIES_2); - foreach ($invoice->lines as $line){ - if ($line->special_code=="3") continue; - $c = new Categorie($db); - $existing = $c->containing($line->fk_product, Categorie::TYPE_PRODUCT, 'id'); - $result = array_intersect($catsprinter1, $existing); - $count=count($result); - if ($count>0){ - $sql="UPDATE ".MAIN_DB_PREFIX."facturedet set special_code='3' where rowid=$line->rowid"; - $db->query($sql); - $order_receipt_printer1.=''.$line->product_label.''.$line->qty.''; - } +if ($action == "order" and $placeid != 0) { + include_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php'; + + $headerorder = '
' . $langs->trans('Place') . ' ' . $place . '
'; + $footerorder = '
' . $langs->trans("Label") . '' . $langs->trans("Qty") . '
' . dol_print_date(dol_now(), 'dayhour') . '
'; + $order_receipt_printer1 = ""; + $order_receipt_printer2 = ""; + $catsprinter1 = explode(';', $conf->global->TAKEPOS_PRINTED_CATEGORIES_1); + $catsprinter2 = explode(';', $conf->global->TAKEPOS_PRINTED_CATEGORIES_2); + foreach($invoice->lines as $line) + { + if ($line->special_code == "3") { continue; + } + $c = new Categorie($db); + $existing = $c->containing($line->fk_product, Categorie::TYPE_PRODUCT, 'id'); + $result = array_intersect($catsprinter1, $existing); + $count = count($result); + if ($count > 0) { + $sql = "UPDATE " . MAIN_DB_PREFIX . "facturedet set special_code='3' where rowid=$line->rowid"; + $db->query($sql); + $order_receipt_printer1.= '' . $line->product_label . '' . $line->qty . ''; + } } - foreach ($invoice->lines as $line){ - if ($line->special_code=="3") continue; - $c = new Categorie($db); - $existing = $c->containing($line->fk_product, Categorie::TYPE_PRODUCT, 'id'); - $result = array_intersect($catsprinter2, $existing); - $count=count($result); - if ($count>0){ - $sql="UPDATE ".MAIN_DB_PREFIX."facturedet set special_code='3' where rowid=$line->rowid"; - $db->query($sql); - $order_receipt_printer2.=''.$line->product_label.''.$line->qty.''; - } + + foreach($invoice->lines as $line) + { + if ($line->special_code == "3") { continue; + } + $c = new Categorie($db); + $existing = $c->containing($line->fk_product, Categorie::TYPE_PRODUCT, 'id'); + $result = array_intersect($catsprinter2, $existing); + $count = count($result); + if ($count > 0) { + $sql = "UPDATE " . MAIN_DB_PREFIX . "facturedet set special_code='3' where rowid=$line->rowid"; + $db->query($sql); + $order_receipt_printer2.= '' . $line->product_label . '' . $line->qty . ''; + } } - $invoice->fetch($placeid); + + $invoice->fetch($placeid); +} + +// temporary ticket feature + +if ($action == "temp" and $placeid != 0) { + include_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php'; + + // issues with special characters with jPosBoxprinting ->javascript, stringCleanCharts() temporarily fix them until to find a more elegant solution. + + function stringCleanCharts($text) + { + $utf8 = array( + '/[áàâãªä]/u' => 'a', + '/[ÁÀÂÃÄ]/u' => 'A', + '/[ÍÌÎÏ]/u' => 'I', + '/[íìîï]/u' => 'i', + '/[éèêë]/u' => 'e', + '/[ÉÈÊË]/u' => 'E', + '/[óòôõºö]/u' => 'o', + '/[ÓÒÔÕÖ]/u' => 'O', + '/[úùûü]/u' => 'u', + '/[ÚÙÛÜ]/u' => 'U', + '/ç/' => 'c', + '/Ç/' => 'C', + '/ñ/' => 'n', + '/Ñ/' => 'N', + '/–/' => '-', + '/[’‘‹›‚\']/u' => ' ', + '/[“”«»„]/u' => ' ', + '/ /' => ' ', + ); + return preg_replace(array_keys($utf8), array_values($utf8), $text); + } + + $mysocname = stringCleanCharts($mysoc->name); + $mysocaddress = stringCleanCharts($mysoc->address); + $mysoctown = stringCleanCharts($mysoc->town); + $mysoczip = stringCleanCharts($mysoc->zip); + $mysocphone = stringCleanCharts($mysoc->phone); + $mysocurl = stringCleanCharts($mysoc->url); + $header_soc = '
' . $mysocname . '
' . $mysocaddress . '
' . $mysoczip . ' ' . $mysoctown . '

' . $langs->trans("Phone") . ': ' . $mysocphone . '
' . $mysocurl; + $header_ticket = '

' . $langs->trans("Temporary ticket") . '
' . $langs->trans("date") . ':
' . dol_print_date(dol_now(), 'dayhour') . '
' . $langs->trans('Place') . ' ' . $place . '


'; + $body_ticket = ''; + $footer_ticket = '

' . $langs->trans("Cashier") . ': ' . $user->firstname . '
' . $langs->trans("Thanks for your coming !") . '
'; + $ticket_printer1 = ""; + $catsprinter1 = explode(';', $conf->global->TAKEPOS_PRINTED_CATEGORIES_1); + foreach($invoice->lines as $line) + { + if ($line->special_code == "3") { continue; + } + $c = new Categorie($db); + $existing = $c->containing($line->fk_product, Categorie::TYPE_PRODUCT, 'id'); + $result = array_intersect($catsprinter1, $existing); + $count = count($result); + if ($count > 0) { + $sql = "UPDATE " . MAIN_DB_PREFIX . "facturedet set special_code='3' where rowid=$line->rowid"; + $db->query($sql); + $ticket_printer1.= ''; + $ticket_total = '
' . $langs->trans("Label") . '' . $langs->trans("Qty") . '' . $langs->trans("Price") . '' . $langs->trans("TotalTTC") . '
' . $line->product_label . '' . $line->qty . '' . $line->total_ttc / $line->qty . '' . $line->total_ttc . '
' . $langs->trans("TotalHT") . ': ' . price($invoice->total_ht, 1, '', 1, -1, -1, $conf->currency) . '
' . $langs->trans("TotalVAT") . ': ' . price($invoice->total_tva, 1, '', 1, -1, -1, $conf->currency) . '
' . $langs->trans("TotalTTC") . ': ' . price($invoice->total_ttc, 1, '', 1, -1, -1, $conf->currency) . '
'; + } + } + + $invoice->fetch($placeid); } ?> @@ -252,23 +375,31 @@ function TakeposPrinting(id){ print '
'; print ''; print ''; -print ''; -print ''; -print ''; +print ''; +print ''; +print ''; print "\n"; -if ($placeid>0) foreach ($invoice->lines as $line) -{ - print ''; - print ''; - print ''; - print ''; - print ''; + +if ($placeid > 0) { + foreach($invoice->lines as $line) + { + print ''; + print ''; + print ''; + print ''; + print ''; + } } + print '
'.$langs->trans('Description').''.$langs->trans('Qty').''.$langs->trans('TotalHTShort').'' . $langs->trans('Description') . '' . $langs->trans('Qty') . '' . $langs->trans('TotalHTShort') . '
'.$line->product_label.$line->desc.''.$line->qty.''.price($line->total_ttc).'
' . $line->product_label . $line->desc . '' . $line->qty . '' . price($line->total_ttc) . '
'; + print '

'.$langs->trans('TotalTTC'); + if($conf->global->TAKEPOS_BAR_RESTAURANT) print " ".$langs->trans('Place')." ".$place; + print ': '.price($invoice->total_ttc, 1, '', 1, - 1, - 1, $conf->currency).' 

'; //if ($invoice->socid != $conf->global->CASHDESK_ID_THIRDPARTY){ @@ -284,9 +415,32 @@ if ($action=="valid"){ if ($conf->global->TAKEPOSCONNECTOR) print '
'; else print '
'; } -if ($action=="search"){ - print '
- total_ttc, 1, '', 1, -1, -1, $conf->currency) . ' 

'; + +// if ($invoice->socid != $conf->global->CASHDESK_ID_THIRDPARTY){ + +$soc = new Societe($db); + +if ($invoice->socid > 0) { $soc->fetch($invoice->socid); +} else { $soc->fetch($conf->global->CASHDESK_ID_THIRDPARTY); +} +print '

'; +print $langs->trans("Customer") . ': ' . $soc->name; +print '

'; + +// } + +if ($action == "valid") { + print '

' . $invoice->facnumber . " " . $langs->trans('BillShortStatusValidated') . '

'; + if ($conf->global->TAKEPOSCONNECTOR) { print '
'; + } else { print '
'; + } +} + +if ($action == "search") { + print '
+ '; } + print '
'; diff --git a/htdocs/takepos/receipt.php b/htdocs/takepos/receipt.php index 05fdea52760..788e2391f14 100644 --- a/htdocs/takepos/receipt.php +++ b/htdocs/takepos/receipt.php @@ -46,12 +46,14 @@ $object->fetch($facid);
-name; ?> +'.$mysoc->name.'';?>

- +'.$langs->trans("Phone").': '.$mysoc->phone; + ?> +

ref;


- +
+ @@ -78,6 +81,7 @@ print $object->ref; + ref;
trans("Label"); ?> trans("Qty"); ?>trans("Price"); ?> trans("TotalTTC"); ?>
product_label;?> qty;?>total_ttc/$line->qty;?> total_ttc);?>
trans("TotalTTC").''.price($object->total_ttc, 1, '', 1, - 1, - 1, $conf->currency)."\n";?>
+
+
+
+
+trans("Cashier: "); +echo $user->firstname.'
'.$mysoc->url.'
'; +echo '
'.$langs->trans("Thanks for your coming !").'
'; +?>