30 if (!defined(
'NOCSRFCHECK')) {
31 define(
'NOCSRFCHECK',
'1');
33 if (!defined(
'NOTOKENRENEWAL')) {
34 define(
'NOTOKENRENEWAL',
'1');
36 if (!defined(
'NOREQUIREMENU')) {
37 define(
'NOREQUIREMENU',
'1');
39 if (!defined(
'NOREQUIREHTML')) {
40 define(
'NOREQUIREHTML',
'1');
42 if (!defined(
'NOREQUIREAJAX')) {
43 define(
'NOREQUIREAJAX',
'1');
46 if (!defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
47 require
'../main.inc.php';
49 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
50 require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
51 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
52 require_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
53 $hookmanager->initHooks(array(
'takeposinvoice'));
57 $langs->loadLangs(array(
"companies",
"commercial",
"bills",
"cashdesk",
"stocks",
"banks"));
60 $action =
GETPOST(
'action',
'aZ09');
61 $idproduct =
GETPOST(
'idproduct',
'int');
62 $place = (
GETPOST(
'place',
'aZ09') ?
GETPOST(
'place',
'aZ09') : 0);
64 $mobilepage =
GETPOST(
'mobilepage',
'alpha');
68 if (empty($user->rights->takepos->run) && !defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
77 if ((
getDolGlobalString(
'TAKEPOS_PHONE_BASIC_LAYOUT') == 1 && $conf->browser->layout ==
'phone') || defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
79 if ($_SESSION[
"takeposterminal"] ==
"") {
81 $_SESSION[
"takeposterminal"] = 1;
83 header(
"Location: ".DOL_URL_ROOT.
"/takepos/index.php");
87 $title =
'TakePOS - Dolibarr '.DOL_VERSION;
88 if (!empty($conf->global->MAIN_APPLICATION_TITLE)) {
89 $title =
'TakePOS - '.$conf->global->MAIN_APPLICATION_TITLE;
91 $head =
'<meta name="apple-mobile-web-app-title" content="TakePOS"/>
92 <meta name="apple-mobile-web-app-capable" content="yes">
93 <meta name="mobile-web-app-capable" content="yes">
94 <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>';
96 '/takepos/css/pos.css.php',
97 '/takepos/js/jquery.colorbox-min.js'
99 $arrayofjs = array(
'/takepos/js/jquery.colorbox-min.js');
102 top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss);
113 header($_SERVER[
'SERVER_PROTOCOL'].
' 500 Internal Server Error',
true, 500);
119 $number =
GETPOST(
'number',
'alpha');
120 $idline =
GETPOST(
'idline',
'int');
121 $selectedline =
GETPOST(
'selectedline',
'int');
122 $desc =
GETPOST(
'desc',
'alphanohtml');
126 $invoiceid =
GETPOST(
'invoiceid',
'int');
129 if ($pay ==
'cash') {
132 if ($pay ==
'card') {
135 if ($pay ==
'cheque') {
142 $sql =
"SELECT id FROM ".MAIN_DB_PREFIX.
"c_paiement";
143 $sql .=
" WHERE entity IN (".getEntity(
'c_paiement').
")";
144 $sql .=
" AND code = '".$db->escape($paycode).
"'";
145 $resql = $db->query($sql);
147 $obj = $db->fetch_object(
$resql);
149 $paiementid = $obj->id;
155 if ($invoiceid > 0) {
156 $ret = $invoice->fetch($invoiceid);
158 $ret = $invoice->fetch(
'',
'(PROV-POS'. (isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'') .
'-'.$place.
')');
161 $placeid = $invoice->id;
164 $constforcompanyid =
'CASHDESK_ID_THIRDPARTY'. (isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
167 if ($invoice->socid > 0) {
168 $soc->fetch($invoice->socid);
174 if (
isModEnabled(
'multicurrency') && !empty($_SESSION[
"takeposcustomercurrency"])) {
175 if ($invoice->multicurrency_code != $_SESSION[
"takeposcustomercurrency"]) {
176 $invoice->setMulticurrencyCode($_SESSION[
"takeposcustomercurrency"]);
186 $reshook=$hookmanager->executeHooks(
'doActions', $parameters, $invoice, $action);
187 if ($reshook < 0)
setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
189 if (empty($reshook)) {
191 if ($action ==
'valid' && $user->rights->facture->creer) {
195 if (!empty($conf->global->TAKEPOS_CAN_FORCE_BANK_ACCOUNT_DURING_PAYMENT)) {
196 $bankaccount =
GETPOST(
'accountid',
'int');
199 $bankaccount = $conf->global->{
'CASHDESK_ID_BANKACCOUNT_CASH'.$_SESSION[
"takeposterminal"]};
200 } elseif ($pay ==
"CHQ") {
201 $bankaccount = $conf->global->{
'CASHDESK_ID_BANKACCOUNT_CHEQUE'.$_SESSION[
"takeposterminal"]};
203 $accountname =
"CASHDESK_ID_BANKACCOUNT_".$pay.$_SESSION[
"takeposterminal"];
204 $bankaccount = $conf->global->$accountname;
208 if ($bankaccount <= 0 && $pay !=
"delayed" &&
isModEnabled(
'banque')) {
209 $errormsg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"BankAccount"));
217 $invoice->fetch($placeid);
219 if ($invoice->total_ttc < 0) {
220 $invoice->type = $invoice::TYPE_CREDIT_NOTE;
222 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"facture WHERE";
223 $sql .=
" fk_soc = ".((int) $invoice->socid);
224 $sql .=
" AND type <> ".Facture::TYPE_CREDIT_NOTE;
225 $sql .=
" AND fk_statut >= ".$invoice::STATUS_VALIDATED;
226 $sql .=
" ORDER BY rowid DESC";
228 $resql = $db->query($sql);
230 $obj = $db->fetch_object(
$resql);
231 $fk_source = $obj->rowid;
232 if ($fk_source ==
null) {
233 fail($langs->transnoentitiesnoconv(
"NoPreviousBillForCustomer"));
236 fail($langs->transnoentitiesnoconv(
"NoPreviousBillForCustomer"));
238 $invoice->fk_facture_source = $fk_source;
239 $invoice->update($user);
249 $constantforkey =
'CASHDESK_NO_DECREASE_STOCK'.$_SESSION[
"takeposterminal"];
254 if ($invoice->getRemainToPay() > 0) {
260 } elseif (count($invoice->lines) == 0) {
264 } elseif (
isModEnabled(
'stock') && $conf->global->$constantforkey !=
"1") {
265 $savconst = $conf->global->STOCK_CALCULATE_ON_BILL;
266 $conf->global->STOCK_CALCULATE_ON_BILL = 1;
268 $constantforkey =
'CASHDESK_ID_WAREHOUSE'.$_SESSION[
"takeposterminal"];
269 dol_syslog(
"Validate invoice with stock change into warehouse defined into constant ".$constantforkey.
" = ".$conf->global->$constantforkey);
271 if (
isModEnabled(
'productbatch') && !empty($conf->global->CASHDESK_FORCE_DECREASE_STOCK)) {
272 require_once DOL_DOCUMENT_ROOT.
'/product/class/productbatch.class.php';
275 $res = $invoice->validate($user,
'', $conf->global->$constantforkey, 0, $batch_rule);
277 $conf->global->STOCK_CALCULATE_ON_BILL = $savconst;
279 $res = $invoice->validate($user);
282 $langs->load(
"admin");
283 dol_htmloutput_errors($invoice->error ==
'NotConfigured' ? $langs->trans(
"NotConfigured").
' (TakePos numbering module)': $invoice->error, $invoice->errors, 1);
294 if (!$error && $res >= 0) {
295 $remaintopay = $invoice->getRemainToPay();
296 if ($remaintopay > 0) {
298 $payment->datepaye = $now;
299 $payment->fk_account = $bankaccount;
300 $payment->amounts[$invoice->id] = $amountofpayment;
307 if ($amountofpayment == 0 || $amountofpayment > $remaintopay) {
308 $payment->amounts[$invoice->id] = $remaintopay;
311 $payment->paiementid = $paiementid;
312 $payment->num_payment = $invoice->ref;
314 if ($pay !=
"delayed") {
315 $payment->create($user);
316 $payment->addPaymentToBank($user,
'payment',
'(CustomerInvoicePayment)', $bankaccount,
'',
'');
321 $remaintopay = $invoice->getRemainToPay();
325 if ($remaintopay == 0) {
326 dol_syslog(
"Invoice is paid, so we set it to status Paid");
327 $result = $invoice->setPaid($user);
332 $invoice->setPaymentMethods($paiementid);
334 dol_syslog(
"Invoice is not paid, remain to pay = ".$remaintopay);
341 if ($action ==
'creditnote' && $user->rights->facture->creer) {
342 $creditnote =
new Facture($db);
343 $creditnote->socid = $invoice->socid;
345 $creditnote->module_source =
'takepos';
346 $creditnote->pos_source = isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'' ;
348 $creditnote->fk_facture_source = $placeid;
349 $creditnote->remise_absolue = $invoice->remise_absolue;
350 $creditnote->remise_percent = $invoice->remise_percent;
351 $creditnote->create($user);
353 foreach ($invoice->lines as $line) {
355 if (method_exists($line,
'fetch_optionals')) {
357 $line->fetch_optionals();
360 if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) {
364 $source_fk_prev_id = $line->fk_prev_id;
365 $line->fk_prev_id = $line->id;
366 if (!empty($invoice->tab_previous_situation_invoice)) {
369 $tab_jumped_credit_notes = array();
370 $lineIndex = count($invoice->tab_previous_situation_invoice) - 1;
371 $searchPreviousInvoice =
true;
372 while ($searchPreviousInvoice) {
374 $searchPreviousInvoice =
false;
378 $tab_jumped_credit_notes[$lineIndex] = $invoice->tab_previous_situation_invoice[$lineIndex]->id;
384 $maxPrevSituationPercent = 0;
385 foreach ($invoice->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine) {
386 if ($prevLine->id == $source_fk_prev_id) {
387 $maxPrevSituationPercent = max($maxPrevSituationPercent, $prevLine->situation_percent);
390 $line->total_ht = $line->total_ht - $prevLine->total_ht;
391 $line->total_tva = $line->total_tva - $prevLine->total_tva;
392 $line->total_ttc = $line->total_ttc - $prevLine->total_ttc;
393 $line->total_localtax1 = $line->total_localtax1 - $prevLine->total_localtax1;
394 $line->total_localtax2 = $line->total_localtax2 - $prevLine->total_localtax2;
396 $line->multicurrency_subprice = $line->multicurrency_subprice - $prevLine->multicurrency_subprice;
397 $line->multicurrency_total_ht = $line->multicurrency_total_ht - $prevLine->multicurrency_total_ht;
398 $line->multicurrency_total_tva = $line->multicurrency_total_tva - $prevLine->multicurrency_total_tva;
399 $line->multicurrency_total_ttc = $line->multicurrency_total_ttc - $prevLine->multicurrency_total_ttc;
404 $line->situation_percent = $maxPrevSituationPercent - $line->situation_percent;
409 $maxPrevSituationPercent = 0;
410 foreach ($tab_jumped_credit_notes as $index => $creditnoteid) {
411 foreach ($invoice->tab_previous_situation_invoice[$index]->lines as $prevLine) {
412 if ($prevLine->fk_prev_id == $source_fk_prev_id) {
413 $maxPrevSituationPercent = $prevLine->situation_percent;
415 $line->total_ht -= $prevLine->total_ht;
416 $line->total_tva -= $prevLine->total_tva;
417 $line->total_ttc -= $prevLine->total_ttc;
418 $line->total_localtax1 -= $prevLine->total_localtax1;
419 $line->total_localtax2 -= $prevLine->total_localtax2;
421 $line->multicurrency_subprice -= $prevLine->multicurrency_subprice;
422 $line->multicurrency_total_ht -= $prevLine->multicurrency_total_ht;
423 $line->multicurrency_total_tva -= $prevLine->multicurrency_total_tva;
424 $line->multicurrency_total_ttc -= $prevLine->multicurrency_total_ttc;
430 $line->situation_percent += $maxPrevSituationPercent;
436 $line->fk_facture = $creditnote->id;
437 $line->fk_parent_line = $fk_parent_line;
439 $line->subprice = -$line->subprice;
440 $line->pa_ht = $line->pa_ht;
441 $line->total_ht = -$line->total_ht;
442 $line->total_tva = -$line->total_tva;
443 $line->total_ttc = -$line->total_ttc;
444 $line->total_localtax1 = -$line->total_localtax1;
445 $line->total_localtax2 = -$line->total_localtax2;
447 $line->multicurrency_subprice = -$line->multicurrency_subprice;
448 $line->multicurrency_total_ht = -$line->multicurrency_total_ht;
449 $line->multicurrency_total_tva = -$line->multicurrency_total_tva;
450 $line->multicurrency_total_ttc = -$line->multicurrency_total_ttc;
452 $result = $line->insert(0, 1);
454 $creditnote->lines[] = $line;
457 if ($result > 0 && $line->product_type == 9) {
458 $fk_parent_line = $result;
461 $creditnote->update_price(1);
463 $constantforkey =
'CASHDESK_NO_DECREASE_STOCK'.$_SESSION[
"takeposterminal"];
464 if (
isModEnabled(
'stock') && $conf->global->$constantforkey !=
"1") {
465 $savconst = $conf->global->STOCK_CALCULATE_ON_BILL;
466 $conf->global->STOCK_CALCULATE_ON_BILL = 1;
467 $constantforkey =
'CASHDESK_ID_WAREHOUSE'.$_SESSION[
"takeposterminal"];
468 dol_syslog(
"Validate invoice with stock change into warehouse defined into constant ".$constantforkey.
" = ".$conf->global->$constantforkey);
470 if (
isModEnabled(
'productbatch') && !empty($conf->global->CASHDESK_FORCE_DECREASE_STOCK)) {
471 require_once DOL_DOCUMENT_ROOT.
'/product/class/productbatch.class.php';
474 $res = $creditnote->validate($user,
'', $conf->global->$constantforkey, 0, $batch_rule);
475 $conf->global->STOCK_CALCULATE_ON_BILL = $savconst;
477 $res = $creditnote->validate($user);
481 if ($action ==
'history' || $action ==
'creditnote') {
482 if ($action ==
'creditnote') {
483 $placeid = $creditnote->id;
485 $placeid = (int)
GETPOST(
'placeid',
'int');
488 $invoice->fetch($placeid);
491 if (($action ==
"addline" || $action ==
"freezone") && $placeid == 0) {
494 $invoice->module_source =
'takepos';
495 $invoice->pos_source = isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'' ;
496 $invoice->entity = !empty($_SESSION[
"takeposinvoiceentity"]) ? $_SESSION[
"takeposinvoiceentity"] : $conf->entity;
498 if ($invoice->socid <= 0) {
499 $langs->load(
'errors');
502 $placeid = $invoice->create($user);
506 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facture set ref='(PROV-POS".$_SESSION[
"takeposterminal"].
"-".$place.
")' where rowid = ".((int) $placeid);
511 if ($action ==
"addline") {
513 $prod->fetch($idproduct);
516 $customer->fetch($invoice->socid);
518 $datapriceofproduct = $prod->getSellPrice($mysoc, $customer, 0);
521 $price = $datapriceofproduct[
'pu_ht'];
522 $price_ttc = $datapriceofproduct[
'pu_ttc'];
524 $price_base_type = empty($datapriceofproduct[
'price_base_type']) ?
'HT' : $datapriceofproduct[
'price_base_type'];
525 $tva_tx = $datapriceofproduct[
'tva_tx'];
526 $tva_npr = $datapriceofproduct[
'tva_npr'];
529 $localtax1_tx =
get_localtax($tva_tx, 1, $customer, $mysoc, $tva_npr);
530 $localtax2_tx =
get_localtax($tva_tx, 2, $customer, $mysoc, $tva_npr);
532 if (!empty($conf->global->TAKEPOS_SUPPLEMENTS)) {
533 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
535 $categories = $cat->containing($idproduct,
'product');
536 $found = (array_search($conf->global->TAKEPOS_SUPPLEMENTS_CATEGORY, array_column($categories,
'id')));
537 if ($found !==
false) {
538 $sql =
"SELECT fk_parent_line FROM ".MAIN_DB_PREFIX.
"facturedet where rowid=$selectedline";
539 $resql = $db->query($sql);
540 $row = $db->fetch_array(
$resql);
541 if ($row[0] ==
null) {
542 $parent_line = $selectedline;
544 $parent_line = $row[0];
551 if (!empty($conf->global->TAKEPOS_GROUP_SAME_PRODUCT) && $line->special_code !=
"4") {
552 foreach ($invoice->lines as $line) {
553 if ($line->product_ref == $prod->ref) {
554 if ($line->special_code==4)
continue;
555 $result = $invoice->updateline($line->id, $line->desc, $line->subprice, $line->qty + $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);
559 $idoflineadded = $line->id;
565 if ($idoflineadded <= 0) {
566 $invoice->fetch_thirdparty();
567 $array_options = array();
570 $parameters = array(
'prod' => $prod);
571 $reshook=$hookmanager->executeHooks(
'completeTakePosAddLine', $parameters, $invoice, $action);
572 if ($reshook < 0)
setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
574 if (empty($reshook)) {
575 $idoflineadded = $invoice->addline($prod->description, $price, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, $idproduct, $customer->remise_percent,
'', 0, 0, 0,
'', $price_base_type, $price_ttc, $prod->type, -1, 0,
'', 0, (!empty($parent_line)) ? $parent_line :
'',
null,
'',
'', $array_options, 100,
'',
null, 0);
578 if (!empty($conf->global->TAKEPOS_CUSTOMER_DISPLAY)) {
579 $CUSTOMER_DISPLAY_line1 = $prod->label;
580 $CUSTOMER_DISPLAY_line2 =
price($price_ttc);
584 $invoice->fetch($placeid);
587 if ($action ==
"freezone") {
589 $customer->fetch($invoice->socid);
591 $tva_tx =
GETPOST(
'tva_tx',
'alpha');
593 if (!preg_match(
'/\((.*)\)/', $tva_tx)) {
601 $localtax1_tx =
get_localtax($tva_tx, 1, $customer, $mysoc, $tva_npr);
602 $localtax2_tx =
get_localtax($tva_tx, 2, $customer, $mysoc, $tva_npr);
604 $invoice->addline($desc, $number, 1, $tva_tx, $localtax1_tx, $localtax2_tx, 0, 0,
'', 0, 0, 0,
'',
getDolGlobalInt(
'TAKEPOS_CHANGE_PRICE_HT') ?
'HT' :
'TTC', $number, 0, -1, 0,
'', 0, 0,
null,
'',
'', 0, 100,
'',
null, 0);
605 $invoice->fetch($placeid);
608 if ($action ==
"addnote") {
609 $desc =
GETPOST(
'addnote',
'alpha');
611 $invoice->update_note($desc,
'_public');
612 }
else foreach ($invoice->lines as $line) {
613 if ($line->id == $idline) {
614 $result = $invoice->updateline($line->id, $desc, $line->subprice, $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);
617 $invoice->fetch($placeid);
620 if ($action ==
"deleteline") {
621 if ($idline > 0 and $placeid > 0) {
622 $invoice->deleteline($idline);
623 $invoice->fetch($placeid);
624 } elseif ($placeid > 0) {
625 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"facturedet where fk_facture = ".((int) $placeid).
" ORDER BY rowid DESC";
626 $resql = $db->query($sql);
627 $row = $db->fetch_array(
$resql);
628 $deletelineid = $row[0];
629 $invoice->deleteline($deletelineid);
630 $invoice->fetch($placeid);
632 if (count($invoice->lines) == 0) {
633 $invoice->delete($user);
634 header(
"Location: ".DOL_URL_ROOT.
"/takepos/invoice.php");
640 if ($action ==
"delete") {
643 $result = $invoice->fetch($placeid);
650 foreach ($invoice->lines as $line) {
651 $tmpres = $invoice->deleteline($line->id);
658 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facture";
659 $varforconst =
'CASHDESK_ID_THIRDPARTY'.$_SESSION[
"takeposterminal"];
660 $sql .=
" SET fk_soc = ".((int) $conf->global->$varforconst).
", ";
661 $sql .=
" datec = '".$db->idate(
dol_now()).
"'";
662 $sql .=
" WHERE ref = '(PROV-POS".$db->escape($_SESSION[
"takeposterminal"].
"-".$place).
")'";
663 $resql1 = $db->query($sql);
665 if ($resdeletelines && $resql1) {
671 $invoice->fetch($placeid);
676 if ($action ==
"updateqty") {
677 foreach ($invoice->lines as $line) {
678 if ($line->id == $idline) {
679 if (!$user->rights->takepos->editlines || (!$user->rights->takepos->editorderedlines && $line->special_code ==
"4")) {
682 $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);
687 $invoice->fetch($placeid);
690 if ($action ==
"updateprice") {
692 $customer->fetch($invoice->socid);
694 foreach ($invoice->lines as $line) {
695 if ($line->id == $idline) {
697 $prod->fetch($line->fk_product);
698 $datapriceofproduct = $prod->getSellPrice($mysoc, $customer, 0);
699 $price_min = $datapriceofproduct[
'price_min'];
700 $usercanproductignorepricemin = ((!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->produit->ignore_price_min_advance)) || empty($conf->global->MAIN_USE_ADVANCED_PERMS));
701 $pu_ht =
price2num($number / (1 + ($line->tva_tx / 100)),
'MU');
703 if ($usercanproductignorepricemin && (!empty($price_min) && (
price2num($pu_ht) * (1 -
price2num($line->remise_percent) / 100) <
price2num($price_min)))) {
704 echo $langs->trans(
"CantBeLessThanMinPrice");
706 if (empty($user->rights->takepos->editlines) || (empty($user->rights->takepos->editorderedlines) && $line->special_code ==
"4")) {
709 $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);
711 $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,
'TTC', $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);
718 $invoice->fetch($placeid);
721 if ($action ==
"updatereduction") {
723 $customer->fetch($invoice->socid);
725 foreach ($invoice->lines as $line) {
726 if ($line->id == $idline) {
727 dol_syslog(
"updatereduction Process line ".$line->id.
' to apply discount of '.$number.
'%');
730 $prod->fetch($line->fk_product);
732 $datapriceofproduct = $prod->getSellPrice($mysoc, $customer, 0);
733 $price_min = $datapriceofproduct[
'price_min'];
734 $usercanproductignorepricemin = ((!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->produit->ignore_price_min_advance)) || empty($conf->global->MAIN_USE_ADVANCED_PERMS));
736 $pu_ht =
price2num($line->subprice / (1 + ($line->tva_tx / 100)),
'MU');
739 if ($usercanproductignorepricemin && (!empty($price_min) && (
price2num($line->subprice) * (1 -
price2num($number) / 100) <
price2num($price_min)))) {
740 echo $langs->trans(
"CantBeLessThanMinPrice");
742 if (empty($user->rights->takepos->editlines) || (empty($user->rights->takepos->editorderedlines) && $line->special_code ==
"4")) {
745 $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);
752 $invoice->fetch($placeid);
753 } elseif ($action ==
'update_reduction_global') {
754 foreach ($invoice->lines as $line) {
755 $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);
758 $invoice->fetch($placeid);
761 if ($action ==
"order" and $placeid != 0) {
762 include_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
763 if ($conf->global->TAKEPOS_PRINT_METHOD ==
"receiptprinter" || $conf->global->TAKEPOS_PRINT_METHOD ==
"takeposconnector") {
764 require_once DOL_DOCUMENT_ROOT.
'/core/class/dolreceiptprinter.class.php';
768 $sql =
"SELECT label FROM ".MAIN_DB_PREFIX.
"takepos_floor_tables where rowid=".((int) $place);
769 $resql = $db->query($sql);
770 $row = $db->fetch_object(
$resql);
771 $headerorder =
'<html><br><b>'.$langs->trans(
'Place').
' '.$row->label.
'<br><table width="65%"><thead><tr><th class="left">'.$langs->trans(
"Label").
'</th><th class="right">'.$langs->trans(
"Qty").
'</th></tr></thead><tbody>';
772 $footerorder =
'</tbody></table>'.dol_print_date(
dol_now(),
'dayhour').
'<br></html>';
773 $order_receipt_printer1 =
"";
774 $order_receipt_printer2 =
"";
775 $order_receipt_printer3 =
"";
776 $catsprinter1 = explode(
';', $conf->global->TAKEPOS_PRINTED_CATEGORIES_1);
777 $catsprinter2 = explode(
';', $conf->global->TAKEPOS_PRINTED_CATEGORIES_2);
778 $catsprinter3 = explode(
';', $conf->global->TAKEPOS_PRINTED_CATEGORIES_3);
780 foreach ($invoice->lines as $line) {
781 if ($line->special_code ==
"4") {
785 $existing = $c->containing($line->fk_product, Categorie::TYPE_PRODUCT,
'id');
786 $result = array_intersect($catsprinter1, $existing);
787 $count = count($result);
788 if (!$line->fk_product) {
793 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facturedet set special_code='1' where rowid=".$line->id;
795 $order_receipt_printer1 .=
'<tr><td class="left">';
796 if ($line->fk_product) {
797 $order_receipt_printer1 .= $line->product_label;
799 $order_receipt_printer1 .= $line->description;
801 $order_receipt_printer1 .=
'</td><td class="right">'.$line->qty;
802 if (!empty($line->array_options[
'options_order_notes'])) {
803 $order_receipt_printer1 .=
"<br>(".$line->array_options[
'options_order_notes'].
")";
805 $order_receipt_printer1 .=
'</td></tr>';
808 if (($conf->global->TAKEPOS_PRINT_METHOD ==
"receiptprinter" || $conf->global->TAKEPOS_PRINT_METHOD ==
"takeposconnector") && $linestoprint > 0) {
809 $invoice->fetch($placeid);
810 $printer->orderprinter = 1;
812 echo
"var orderprinter1esc='";
813 $ret = $printer->sendToPrinter($invoice,
getDolGlobalInt(
'TAKEPOS_TEMPLATE_TO_USE_FOR_ORDERS'.$_SESSION[
"takeposterminal"]),
getDolGlobalInt(
'TAKEPOS_ORDER_PRINTER1_TO_USE'.$_SESSION[
"takeposterminal"]));
816 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facturedet set special_code='4' where special_code='1' and fk_facture=".$invoice->id;
818 $invoice->fetch($placeid);
821 foreach ($invoice->lines as $line) {
822 if ($line->special_code ==
"4") {
826 $existing = $c->containing($line->fk_product, Categorie::TYPE_PRODUCT,
'id');
827 $result = array_intersect($catsprinter2, $existing);
828 $count = count($result);
831 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facturedet set special_code='2' where rowid=".$line->id;
833 $order_receipt_printer2 .=
'<tr>'.$line->product_label.
'<td class="right">'.$line->qty;
834 if (!empty($line->array_options[
'options_order_notes'])) {
835 $order_receipt_printer2 .=
"<br>(".$line->array_options[
'options_order_notes'].
")";
837 $order_receipt_printer2 .=
'</td></tr>';
840 if (($conf->global->TAKEPOS_PRINT_METHOD ==
"receiptprinter" || $conf->global->TAKEPOS_PRINT_METHOD ==
"takeposconnector") && $linestoprint > 0) {
841 $invoice->fetch($placeid);
842 $printer->orderprinter = 2;
844 echo
"var orderprinter2esc='";
845 $ret = $printer->sendToPrinter($invoice,
getDolGlobalInt(
'TAKEPOS_TEMPLATE_TO_USE_FOR_ORDERS'.$_SESSION[
"takeposterminal"]),
getDolGlobalInt(
'TAKEPOS_ORDER_PRINTER2_TO_USE'.$_SESSION[
"takeposterminal"]));
848 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facturedet set special_code='4' where special_code='2' and fk_facture=".$invoice->id;
850 $invoice->fetch($placeid);
853 foreach ($invoice->lines as $line) {
854 if ($line->special_code ==
"4") {
858 $existing = $c->containing($line->fk_product, Categorie::TYPE_PRODUCT,
'id');
859 $result = array_intersect($catsprinter3, $existing);
860 $count = count($result);
863 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facturedet set special_code='3' where rowid=".$line->id;
865 $order_receipt_printer3 .=
'<tr>'.$line->product_label.
'<td class="right">'.$line->qty;
866 if (!empty($line->array_options[
'options_order_notes'])) {
867 $order_receipt_printer3 .=
"<br>(".$line->array_options[
'options_order_notes'].
")";
869 $order_receipt_printer3 .=
'</td></tr>';
872 if (($conf->global->TAKEPOS_PRINT_METHOD ==
"receiptprinter" || $conf->global->TAKEPOS_PRINT_METHOD ==
"takeposconnector") && $linestoprint > 0) {
873 $invoice->fetch($placeid);
874 $printer->orderprinter = 3;
876 echo
"var orderprinter3esc='";
877 $ret = $printer->sendToPrinter($invoice,
getDolGlobalInt(
'TAKEPOS_TEMPLATE_TO_USE_FOR_ORDERS'.$_SESSION[
"takeposterminal"]),
getDolGlobalInt(
'TAKEPOS_ORDER_PRINTER3_TO_USE'.$_SESSION[
"takeposterminal"]));
880 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facturedet set special_code='4' where special_code='3' and fk_facture=".$invoice->id;
882 $invoice->fetch($placeid);
885 $sectionwithinvoicelink =
'';
886 if ($action ==
"valid" || $action ==
"history" || $action ==
'creditnote') {
887 $sectionwithinvoicelink .=
'<!-- Section with invoice link -->'.
"\n";
888 $sectionwithinvoicelink .=
'<span style="font-size:120%;" class="center">';
889 $sectionwithinvoicelink .= $invoice->getNomUrl(1,
'', 0, 0,
'', 0, 0, -1,
'_backoffice').
" - ";
890 $remaintopay = $invoice->getRemainToPay();
891 if ($remaintopay > 0) {
892 $sectionwithinvoicelink .= $langs->trans(
'RemainToPay').
': <span class="amountremaintopay" style="font-size: unset">'.
price($remaintopay, 1, $langs, 1, -1, -1, $conf->currency).
'</span>';
894 if ($invoice->paye) {
895 $sectionwithinvoicelink .=
'<span class="amountpaymentcomplete" style="font-size: unset">'.$langs->trans(
"Paid").
'</span>';
897 $sectionwithinvoicelink .= $langs->trans(
'BillShortStatusValidated');
900 $sectionwithinvoicelink .=
'</span><br>';
902 if (
getDolGlobalString(
'TAKEPOS_PRINT_SERVER') && filter_var($conf->global->TAKEPOS_PRINT_SERVER, FILTER_VALIDATE_URL) ==
true) {
903 $sectionwithinvoicelink .=
' <button id="buttonprint" type="button" onclick="TakeposConnector('.$placeid.
');">'.$langs->trans(
'PrintTicket').
'</button>';
905 $sectionwithinvoicelink .=
' <button id="buttonprint" type="button" onclick="TakeposPrinting('.$placeid.
');">'.$langs->trans(
'PrintTicket').
'</button>';
908 $sectionwithinvoicelink .=
' <button id="buttonprint" type="button" onclick="DolibarrTakeposPrinting('.$placeid.
');">'.$langs->trans(
'PrintTicket').
'</button>';
910 $sectionwithinvoicelink .=
' <button id="buttonprint" type="button" onclick="Print('.$placeid.
');">'.$langs->trans(
'PrintTicket').
'</button>';
912 $sectionwithinvoicelink .=
' <button id="buttonprint" type="button" onclick="PrintBox('.$placeid.
', \'without_details\');">'.$langs->trans(
'PrintWithoutDetails').
'</button>';
915 $sectionwithinvoicelink .=
' <button id="buttonprint" type="button" onclick="Print('.$placeid.
', 1);">'.$langs->trans(
'GiftReceipt').
'</button>';
918 if (
getDolGlobalString(
'TAKEPOS_EMAIL_TEMPLATE_INVOICE') && $conf->global->TAKEPOS_EMAIL_TEMPLATE_INVOICE > 0) {
919 $sectionwithinvoicelink .=
' <button id="buttonsend" type="button" onclick="SendTicket('.$placeid.
');">'.$langs->trans(
'SendTicket').
'</button>';
922 if ($remaintopay <= 0 &&
getDolGlobalString(
'TAKEPOS_AUTO_PRINT_TICKETS') && $action !=
"history") {
923 $sectionwithinvoicelink .=
'<script type="text/javascript">$("#buttonprint").click();</script>';
935 <script
type=
"text/javascript">
938 <?php
if ($action==
"valid") echo
"var place=0;";?>
939 var placeid=<?php echo ($placeid > 0 ? $placeid : 0); ?>;
940 $(document).ready(
function() {
941 var idoflineadded = <?php echo (empty($idoflineadded) ? 0 : $idoflineadded); ?>;
943 $(
'.posinvoiceline').click(
function(){
944 console.log(
"Click done on "+this.
id);
945 $(
'.posinvoiceline').removeClass(
"selected");
946 $(
this).addClass(
"selected");
947 if (selectedline==this.
id)
return;
948 else selectedline=this.id;
949 selectedtext=$(
'#'+selectedline).find(
"td:first").html();
951 if (defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
952 print
'$("#phonediv1").load("auto_order.php?action=editline&token='.newToken().
'&placeid="+placeid+"&selectedline="+selectedline, function() {
959 if (idoflineadded > 0)
961 console.log(
"Auto select "+idoflineadded);
962 $(
'.posinvoiceline#'+idoflineadded).click();
966 if ($action ==
"order" && !empty($order_receipt_printer1)) {
967 if (filter_var($conf->global->TAKEPOS_PRINT_SERVER, FILTER_VALIDATE_URL) ==
true) {
971 url:
'<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>/printer/index.php',
972 data:
'invoice='+orderprinter1esc
979 url:
'http://<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>:8111/print',
981 print $headerorder.$order_receipt_printer1.$footerorder; ?>'
987 if ($action ==
"order" && !empty($order_receipt_printer2)) {
988 if (filter_var($conf->global->TAKEPOS_PRINT_SERVER, FILTER_VALIDATE_URL) ==
true) {
992 url:
'<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>/printer/index.php?printer=2',
993 data:
'invoice='+orderprinter2esc
1000 url:
'http://<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>:8111/print2',
1002 print $headerorder.$order_receipt_printer2.$footerorder; ?>'
1008 if ($action ==
"order" && !empty($order_receipt_printer3)) {
1009 if (filter_var($conf->global->TAKEPOS_PRINT_SERVER, FILTER_VALIDATE_URL) ==
true) {
1013 url:
'<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>/printer/index.php?printer=3',
1014 data:
'invoice='+orderprinter3esc
1021 if ($action ==
"search" || $action ==
"valid") {
1023 parent.setFocusOnSearchField();
1028 if ($action ==
"temp" && !empty($ticket_printer1)) {
1032 url:
'http://<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>:8111/print',
1034 print $header_soc.$header_ticket.$body_ticket.$ticket_printer1.$ticket_total.$footer_ticket; ?>'
1039 if ($action ==
"search") {
1041 $(
'#search').focus();
1049 function SendTicket(
id)
1051 console.log(
"Open box to select the Print/Send form");
1052 $.colorbox({href:
"send.php?facid="+id, width:
"70%", height:
"30%", transition:
"none", iframe:
"true", title:
'<?php echo dol_escape_js($langs->trans("SendTicket")); ?>'});
1055 function PrintBox(
id, action) {
1056 console.log(
"Open box before printing");
1057 $.colorbox({href:
"printbox.php?facid="+
id+
"&action="+action, width:
"80%", height:
"200px", transition:
"none", iframe:
"true", title:
"<?php echo $langs->trans("PrintWithoutDetails
"); ?>"});
1060 function Print(
id, gift){
1061 console.log(
"Call Print() to generate the receipt.");
1062 $.colorbox({href:
"receipt.php?facid="+
id+
"&gift="+gift, width:
"40%", height:
"90%", transition:
"none", iframe:
"true", title:
'<?php echo dol_escape_js($langs->trans("PrintTicket")); ?>'});
1065 function TakeposPrinting(
id){
1067 console.log(
"TakeposPrinting" +
id);
1068 $.get(
"receipt.php?facid="+
id,
function(data, status){
1069 receipt=data.replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g,
'');
1072 url:
'http://<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER
'); ?>:8111/print',
1078 function TakeposConnector(
id){
1079 console.log(
"TakeposConnector" +
id);
1080 $.get(
"<?php echo DOL_URL_ROOT; ?>/takepos/ajax/ajax.php?action=printinvoiceticket&term=<?php echo urlencode(isset($_SESSION["takeposterminal
"]) ? $_SESSION["takeposterminal
"] : ''); ?>&id="+
id+
"&token=<?php echo currentToken(); ?>",
function(data, status) {
1083 url:
'<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER
'); ?>/printer/index.php',
1084 data:
'invoice='+data
1089 function DolibarrTakeposPrinting(
id) {
1090 console.log(
"DolibarrTakeposPrinting Printing invoice ticket " +
id)
1093 data: { token:
'<?php echo currentToken(); ?>' },
1094 url:
"<?php print DOL_URL_ROOT.'/takepos/ajax/ajax.php?action=printinvoiceticket&term='.urlencode(isset($_SESSION["takeposterminal
"]) ? $_SESSION["takeposterminal
"] : '').'&id='; ?>" + id,
1098 function CreditNote() {
1099 $(
"#poslines").load(
"invoice.php?action=creditnote&token=<?php echo newToken() ?>&invoiceid="+placeid,
function() {
1103 function SetNote() {
1104 $(
"#poslines").load(
"invoice.php?action=addnote&token=<?php echo newToken() ?>&invoiceid="+placeid+
"&idline="+selectedline, {
"addnote": $(
"#textinput").val() });
1108 $( document ).ready(
function() {
1109 console.log(
"Set customer info and sales in header placeid=<?php echo $placeid; ?> status=<?php echo $invoice->statut; ?>");
1112 $s = $langs->trans(
"Customer");
1113 if ($invoice->id > 0 && ($invoice->socid != $conf->global->$constforcompanyid)) {
1118 $(
"#customerandsales").html(
'');
1119 $(
"#shoppingcart").html(
'');
1121 $(
"#customerandsales").append(
'<a class="valignmiddle tdoverflowmax100 minwidth100" id="customer" onclick="Customer();" title="<?php print dol_escape_js($s); ?>"><span class="fas fa-building paddingrightonly"></span><?php print dol_escape_js($s); ?></a>');
1124 $sql =
"SELECT rowid, datec, ref FROM ".MAIN_DB_PREFIX.
"facture";
1125 if (empty($conf->global->TAKEPOS_CAN_EDIT_IF_ALREADY_VALIDATED)) {
1127 $sql .=
" WHERE ref LIKE '(PROV-POS".$db->escape(isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'').
"-0%' AND entity IN (".
getEntity(
'invoice').
")";
1130 $sql .=
" WHERE pos_source = '".$db->escape($_SESSION[
"takeposterminal"]).
"'";
1131 $sql .=
" AND module_source = 'takepos'";
1132 $sql .=
" AND entity IN (".getEntity(
'invoice').
")";
1135 $sql .= $db->order(
'datec',
'ASC');
1136 $resql = $db->query($sql);
1139 while ($obj = $db->fetch_object(
$resql)) {
1140 echo
'$("#shoppingcart").append(\'';
1141 echo
'<a class="valignmiddle" title="'.dol_escape_js($langs->trans(
"SaleStartedAt",
dol_print_date($db->jdate($obj->datec),
'%H:%M',
'tzuser')).
' - '.$obj->ref).
'" onclick="place=\\\'';
1142 $num_sale = str_replace(
")",
"", str_replace(
"(PROV-POS".$_SESSION[
"takeposterminal"].
"-",
"", $obj->ref));
1144 if (str_replace(
"-",
"", $num_sale) > $max_sale) {
1145 $max_sale = str_replace(
"-",
"", $num_sale);
1147 echo
'\\\'; invoiceid=\\\'';
1149 echo
'\\\'; Refresh();">';
1150 if ($placeid == $obj->rowid) {
1153 echo
'<span class="fa fa-shopping-cart paddingright"></span>'.dol_print_date($db->jdate($obj->datec),
'%H:%M',
'tzuser');
1154 if ($placeid == $obj->rowid) {
1159 echo
'$("#shoppingcart").append(\'<a onclick="place=\\\'0-';
1161 echo
'\\\'; invoiceid=0; Refresh();"><div><span class="fa fa-plus" title="'.dol_escape_htmltag($langs->trans(
"StartAParallelSale")).
'"><span class="fa fa-shopping-cart"></span></div></a>\');';
1169 $constantforkey =
'CASHDESK_NO_DECREASE_STOCK'. (isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
1172 $constantforkey =
'CASHDESK_ID_WAREHOUSE'. (isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
1174 if ($idwarehouse > 0) {
1175 $s =
'<span class="small">';
1177 $warehouse->fetch($idwarehouse);
1178 $s .=
'<span class="hideonsmartphone">'.$langs->trans(
"Warehouse").
'<br></span>'.$warehouse->ref;
1180 $s .=
' ('.$langs->trans(
"Closed").
')';
1183 print
"$('#infowarehouse').html('".dol_escape_js($s).
"');";
1184 print
'$("#infowarehouse").css("display", "inline-block");';
1186 $s =
'<span class="small hideonsmartphone">';
1187 $s .= $langs->trans(
"StockChangeDisabled").
'<br>'.$langs->trans(
"NoWarehouseDefinedForTerminal");
1189 print
"$('#infowarehouse').html('".dol_escape_js($s).
"');";
1190 if (!empty($conf->dol_optimize_smallscreen)) {
1191 print
'$("#infowarehouse").css("display", "none");';
1195 $s =
'<span class="small hideonsmartphone">'.$langs->trans(
"StockChangeDisabled").
'</span>';
1196 print
"$('#infowarehouse').html('".dol_escape_js($s).
"');";
1197 if (!empty($conf->dol_optimize_smallscreen)) {
1198 print
'$("#infowarehouse").css("display", "none");';
1206 if (
isModEnabled(
'adherent') && $invoice->socid > 0 && $invoice->socid != $conf->global->$constforcompanyid) {
1207 $s =
'<span class="small">';
1208 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
1209 $langs->load(
"members");
1210 $s .= $langs->trans(
"Member").
': ';
1212 $result = $adh->fetch(
'',
'', $invoice->socid);
1214 $adh->ref = $adh->getFullName($langs);
1218 $s .= $adh->getFullName($langs);
1219 $s .=
' - '.$adh->type;
1220 if ($adh->datefin) {
1221 $s .=
'<br>'.$langs->trans(
"SubscriptionEndDate").
': '.
dol_print_date($adh->datefin,
'day');
1222 if ($adh->hasDelay()) {
1223 $s .=
" ".img_warning($langs->trans(
"Late"));
1226 $s .=
'<br>'.$langs->trans(
"SubscriptionNotReceived");
1227 if ($adh->statut > 0) {
1228 $s .=
" ".img_warning($langs->trans(
"Late"));
1235 $s .=
'<br>'.$langs->trans(
"ThirdpartyNotLinkedToMember");
1240 $(
"#moreinfo").html(
'<?php print dol_escape_js($s); ?>');
1246 if (!empty($conf->global->TAKEPOS_CUSTOMER_DISPLAY)) {
1247 echo
"function CustomerDisplay(){";
1248 echo
"var line1='".$CUSTOMER_DISPLAY_line1.
"'.substring(0,20);";
1249 echo
"line1=line1.padEnd(20);";
1250 echo
"var line2='".$CUSTOMER_DISPLAY_line2.
"'.substring(0,20);";
1251 echo
"line2=line2.padEnd(20);";
1254 data: { text: line1+line2 },
1255 url: '".getDolGlobalString(
'TAKEPOS_PRINT_SERVER').
"/display/index.php',
1266 if (!empty($conf->use_javascript_ajax)) {
1267 print
"\n".
'<!-- Includes JS Footer of Dolibarr -->'.
"\n";
1268 print
'<script src="'.DOL_URL_ROOT.
'/core/js/lib_foot.js.php?lang='.$langs->defaultlang.
'"></script>'.
"\n";
1271 print
'<!-- invoice.php place='.(int) $place.
' invoice='.$invoice->ref.
' mobilepage='.(empty($mobilepage) ?
'' : $mobilepage).
' $_SESSION["basiclayout"]='.(empty($_SESSION[
"basiclayout"])?
'':$_SESSION[
"basiclayout"]).
' conf->global->TAKEPOS_BAR_RESTAURANT='.
getDolGlobalString(
'TAKEPOS_BAR_RESTAURANT').
' -->'.
"\n";
1272 print
'<div class="div-table-responsive-no-min invoice">';
1273 print
'<table id="tablelines" class="noborder noshadow postablelines" width="100%">';
1274 if ($sectionwithinvoicelink && ($mobilepage ==
"invoice" || $mobilepage ==
"")) {
1275 if (!empty($conf->global->TAKEPOS_SHOW_HT)) {
1276 print
'<tr><td colspan="5">'.$sectionwithinvoicelink.
'</td></tr>';
1278 print
'<tr><td colspan="4">'.$sectionwithinvoicelink.
'</td></tr>';
1281 print
'<tr class="liste_titre nodrag nodrop">';
1282 print
'<td class="linecoldescription">';
1284 if (empty($mobilepage) || $mobilepage ==
"invoice") {
1285 print
'<input type="hidden" name="invoiceid" id="invoiceid" value="'.$invoice->id.
'">';
1288 $sql =
"SELECT floor, label FROM ".MAIN_DB_PREFIX.
"takepos_floor_tables where rowid=".((int) $place);
1289 $resql = $db->query($sql);
1290 $obj = $db->fetch_object(
$resql);
1292 $label = $obj->label;
1293 $floor = $obj->floor;
1295 if ($mobilepage ==
"invoice" || $mobilepage ==
"") {
1298 print
'<span class="opacitymedium">'.$langs->trans(
'Place').
"</span> <b>".(empty($label) ?
'?' : $label).
"</b><br>";
1299 print
'<span class="opacitymedium">'.$langs->trans(
'Floor').
"</span> <b>".(empty($floor) ?
'?' : $floor).
"</b>";
1300 } elseif (defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1302 } elseif ($mobilepage ==
"cats") {
1303 print $langs->trans(
'Category');
1304 } elseif ($mobilepage ==
"products") {
1305 print $langs->trans(
'Label');
1308 print $langs->trans(
"Products");
1313 $parameters=array();
1314 $reshook=$hookmanager->executeHooks(
'completeTakePosInvoiceHeader', $parameters, $invoice, $action);
1315 if ($reshook < 0)
setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
1316 print $hookmanager->resPrint;
1318 if (empty($_SESSION[
"basiclayout"]) || $_SESSION[
"basiclayout"] != 1) {
1319 print
'<td class="linecolqty right">'.$langs->trans(
'ReductionShort').
'</td>';
1320 print
'<td class="linecolqty right">'.$langs->trans(
'Qty').
'</td>';
1322 print
'<td class="linecolht right nowraponall">';
1323 print
'<span class="opacitymedium small">' . $langs->trans(
'TotalHTShort') .
'</span><br>';
1325 if (empty($mobilepage) || $mobilepage ==
"invoice") {
1326 print
'<span id="linecolht-span-total" style="font-size:1.3em; font-weight: bold;">' .
price($invoice->total_ht, 1,
'', 1, -1, -1, $conf->currency) .
'</span>';
1327 if (
isModEnabled(
'multicurrency') && $_SESSION[
"takeposcustomercurrency"] !=
"" && $conf->currency != $_SESSION[
"takeposcustomercurrency"]) {
1329 include_once DOL_DOCUMENT_ROOT .
'/multicurrency/class/multicurrency.class.php';
1331 $multicurrency->fetch(0, $_SESSION[
"takeposcustomercurrency"]);
1332 print
'<br><span id="linecolht-span-total" style="font-size:0.9em; font-style:italic;">(' .
price($invoice->total_ht * $multicurrency->rate->rate) .
' ' . $_SESSION[
"takeposcustomercurrency"] .
')</span>';
1338 print
'<td class="linecolht right nowraponall">';
1339 print
'<span class="opacitymedium small">'.$langs->trans(
'TotalTTCShort').
'</span><br>';
1341 if (empty($mobilepage) || $mobilepage ==
"invoice") {
1342 print
'<span id="linecolht-span-total" style="font-size:1.3em; font-weight: bold;">'.price($invoice->total_ttc, 1,
'', 1, -1, -1, $conf->currency).
'</span>';
1343 if (
isModEnabled(
'multicurrency') && !empty($_SESSION[
"takeposcustomercurrency"]) && $conf->currency != $_SESSION[
"takeposcustomercurrency"]) {
1345 include_once DOL_DOCUMENT_ROOT.
'/multicurrency/class/multicurrency.class.php';
1347 $multicurrency->fetch(0, $_SESSION[
"takeposcustomercurrency"]);
1348 print
'<br><span id="linecolht-span-total" style="font-size:0.9em; font-style:italic;">('.price($invoice->total_ttc * $multicurrency->rate->rate).
' '.$_SESSION[
"takeposcustomercurrency"].
')</span>';
1353 } elseif ($mobilepage ==
"invoice") {
1354 print
'<td class="linecolqty right">'.$langs->trans(
'Qty').
'</td>';
1359 if (!empty($_SESSION[
"basiclayout"]) && $_SESSION[
"basiclayout"] == 1) {
1360 if ($mobilepage ==
"cats") {
1361 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1363 $categories = $categorie->get_full_arbo(
'product');
1365 foreach ($categories as $row) {
1366 if (defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1367 $htmlforlines .=
'<div class="leftcat';
1369 $htmlforlines .=
'<tr class="drag drop oddeven posinvoiceline';
1371 $htmlforlines .=
'" onclick="LoadProducts('.$row[
'id'].
');">';
1372 if (defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1373 $htmlforlines .=
'<img class="imgwrapper" width="33%" src="'.DOL_URL_ROOT.
'/takepos/public/auto_order.php?genimg=cat&query=cat&id='.$row[
'id'].
'"><br>';
1375 $htmlforlines .=
'<td class="left">';
1377 $htmlforlines .= $row[
'label'];
1378 if (defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1379 $htmlforlines .=
'</div>'.
"\n";
1381 $htmlforlines .=
'</td></tr>'.
"\n";
1384 $htmlforlines .=
'</table>';
1385 $htmlforlines .=
'</table>';
1386 print $htmlforlines;
1389 if ($mobilepage ==
"products") {
1390 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1392 $catid =
GETPOST(
'catid',
'int');
1393 $result = $object->fetch($catid);
1394 $prods = $object->getObjectsInCateg(
"product");
1396 foreach ($prods as $row) {
1397 if (defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1398 $htmlforlines .=
'<div class="leftcat';
1400 $htmlforlines .=
'<tr class="drag drop oddeven posinvoiceline';
1402 $htmlforlines .=
'" onclick="AddProduct(\''.$place.
'\',
'.$row->id.')
">';
1403 if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1404 $htmlforlines .= '<img class="imgwrapper
" width="33%
" src="'.DOL_URL_ROOT.'/takepos/
public/auto_order.php?genimg=pro&query=pro&
id=
'.$row->id.'"><br>';
1405 $htmlforlines .= $row->label.''.price($row->price_ttc, 1, $langs, 1, -1, -1, $conf->currency);
1406 $htmlforlines .= '</div>'."\n
";
1408 $htmlforlines .= '<td class="left
">';
1409 $htmlforlines .= $row->label;
1410 $htmlforlines .= '<div class="right
">'.price($row->price_ttc, 1, $langs, 1, -1, -1, $conf->currency).'</div>';
1411 $htmlforlines .= '</tr>'."\n
";
1414 $htmlforlines .= '</table>';
1415 print $htmlforlines;
1418 if ($mobilepage == "places
") {
1419 $sql = "SELECT
rowid, entity, label, leftpos, toppos, floor FROM
".MAIN_DB_PREFIX."takepos_floor_tables
";
1420 $resql = $db->query($sql);
1423 while ($row = $db->fetch_array($resql)) {
1425 $htmlforlines .= '<tr class="drag drop oddeven posinvoiceline
';
1426 $htmlforlines .= '" onclick="LoadPlace(\
''.$row[
'label'].
'\')
">';
1427 $htmlforlines .= '<td class="left
">';
1428 $htmlforlines .= $row['label'];
1429 $htmlforlines .= '</td>';
1430 $htmlforlines .= '</tr>'."\n
";
1432 $htmlforlines .= '</table>';
1433 print $htmlforlines;
1438 //In Phone basic layout hide some content depends situation
1439 if (!empty($_SESSION["basiclayout
"]) && $_SESSION["basiclayout
"] == 1 && $mobilepage != "invoice
" && $action != "order
") {
1443 if (is_array($invoice->lines) && count($invoice->lines)) {
1444 print '<!-- invoice.php show lines of invoices -->'."\n
";
1445 $tmplines = array_reverse($invoice->lines);
1446 $htmlsupplements = array();
1447 foreach ($tmplines as $line) {
1448 if ($line->fk_parent_line != false) {
1449 $htmlsupplements[$line->fk_parent_line] .= '<tr class="drag drop oddeven posinvoiceline
';
1450 if ($line->special_code == "4") {
1451 $htmlsupplements[$line->fk_parent_line] .= ' order
';
1453 $htmlsupplements[$line->fk_parent_line] .= '" id="'.$line->id.'"';
1454 if ($line->special_code == "4
") {
1455 $htmlsupplements[$line->fk_parent_line] .= ' title="'.dol_escape_htmltag($langs->trans("AlreadyPrinted")).'"';
1457 $htmlsupplements[$line->fk_parent_line] .= '>';
1458 $htmlsupplements[$line->fk_parent_line] .= '<td class="left
">';
1459 $htmlsupplements[$line->fk_parent_line] .= img_picto('', 'rightarrow');
1460 if ($line->product_label) {
1461 $htmlsupplements[$line->fk_parent_line] .= $line->product_label;
1463 if ($line->product_label && $line->desc) {
1464 $htmlsupplements[$line->fk_parent_line] .= '<br>';
1466 if ($line->product_label != $line->desc) {
1467 $firstline = dolGetFirstLineOfText($line->desc);
1468 if ($firstline != $line->desc) {
1469 $htmlsupplements[$line->fk_parent_line] .= $form->textwithpicto(dolGetFirstLineOfText($line->desc), $line->desc);
1471 $htmlsupplements[$line->fk_parent_line] .= $line->desc;
1474 $htmlsupplements[$line->fk_parent_line] .= '</td>';
1476 // complete line by hook
1477 $parameters=array('line' => $line);
1478 $reshook=$hookmanager->executeHooks('completeTakePosInvoiceParentLine', $parameters, $invoice, $action); // Note that $action and $object may have been modified by some hooks
1479 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1480 $htmlsupplements[$line->fk_parent_line] .= $hookmanager->resPrint;
1482 if (empty($_SESSION["basiclayout
"]) || $_SESSION["basiclayout
"] != 1) {
1483 $htmlsupplements[$line->fk_parent_line] .= '<td class="right
">'.vatrate($line->remise_percent, true).'</td>';
1484 $htmlsupplements[$line->fk_parent_line] .= '<td class="right
">'.$line->qty.'</td>';
1485 $htmlsupplements[$line->fk_parent_line] .= '<td class="right
">'.price($line->total_ttc).'</td>';
1487 $htmlsupplements[$line->fk_parent_line] .= '</tr>'."\n
";
1492 $htmlforlines .= '<tr class="drag drop oddeven posinvoiceline
';
1493 if ($line->special_code == "4") {
1494 $htmlforlines .= ' order
';
1496 $htmlforlines .= '" id="'.$line->id.'"';
1497 if ($line->special_code == "4
") {
1498 $htmlforlines .= ' title="'.dol_escape_htmltag($langs->trans("AlreadyPrinted")).'"';
1500 $htmlforlines .= '>';
1501 $htmlforlines .= '<td class="left
">';
1502 if (!empty($_SESSION["basiclayout
"]) && $_SESSION["basiclayout
"] == 1) {
1503 $htmlforlines .= '<span class="phoneqty
">'.$line->qty."</span> x
";
1505 if (isset($line->product_type)) {
1506 if (empty($line->product_type)) {
1507 $htmlforlines .= img_object('', 'product').' ';
1509 $htmlforlines .= img_object('', 'service').' ';
1512 if (empty($conf->global->TAKEPOS_SHOW_N_FIRST_LINES)) {
1514 if ($line->product_ref) {
1515 $tooltiptext .= '<b>'.$langs->trans("Ref
").'</b> : '.$line->product_ref.'<br>';
1516 $tooltiptext .= '<b>'.$langs->trans("Label
").'</b> : '.$line->product_label.'<br>';
1517 if ($line->product_label != $line->desc) {
1519 $tooltiptext .= '<br>';
1521 $tooltiptext .= $line->desc;
1524 if ($conf->global->TAKEPOS_SHOW_PRODUCT_REFERENCE == 1) {
1525 $htmlforlines .= $form->textwithpicto($line->product_label ? '<b>' . $line->product_ref . '</b> - ' . $line->product_label : dolGetFirstLineOfText($line->desc, 1), $tooltiptext);
1527 $htmlforlines .= $form->textwithpicto($line->product_label ? $line->product_label : ($line->product_ref ? $line->product_ref : dolGetFirstLineOfText($line->desc, 1)), $tooltiptext);
1530 if ($line->product_label) {
1531 $htmlforlines .= $line->product_label;
1533 if ($line->product_label != $line->desc) {
1534 if ($line->product_label && $line->desc) {
1535 $htmlforlines .= '<br>';
1537 $firstline = dolGetFirstLineOfText($line->desc, $conf->global->TAKEPOS_SHOW_N_FIRST_LINES);
1538 if ($firstline != $line->desc) {
1539 $htmlforlines .= $form->textwithpicto(dolGetFirstLineOfText($line->desc), $line->desc);
1541 $htmlforlines .= $line->desc;
1545 if (!empty($line->array_options['options_order_notes'])) {
1546 $htmlforlines .= "<br>(
".$line->array_options['options_order_notes'].")
";
1548 if (!empty($_SESSION["basiclayout
"]) && $_SESSION["basiclayout
"] == 1) {
1549 $htmlforlines .= '</td><td class="right phonetable
"><button type="button
" onclick="SetQty(place,
'.$line->rowid.',
'.($line->qty - 1).');
" class="publicphonebutton2 phonered
">-</button> <button type="button
" onclick="SetQty(place,
'.$line->rowid.',
'.($line->qty + 1).');
" class="publicphonebutton2 phonegreen
">+</button>';
1551 if (empty($_SESSION["basiclayout
"]) || $_SESSION["basiclayout
"] != 1) {
1553 $moreinfo .= $langs->transcountry("TotalHT
", $mysoc->country_code).': '.price($line->total_ht);
1554 if ($line->vat_src_code) {
1555 $moreinfo .= '<br>'.$langs->trans("VATCode
").': '.$line->vat_src_code;
1557 $moreinfo .= '<br>'.$langs->transcountry("TotalVAT
", $mysoc->country_code).': '.price($line->total_tva);
1558 $moreinfo .= '<br>'.$langs->transcountry("TotalLT1
", $mysoc->country_code).': '.price($line->total_localtax1);
1559 $moreinfo .= '<br>'.$langs->transcountry("TotalLT2
", $mysoc->country_code).': '.price($line->total_localtax2);
1560 $moreinfo .= '<br>'.$langs->transcountry("TotalTTC
", $mysoc->country_code).': '.price($line->total_ttc);
1561 //$moreinfo .= $langs->trans("TotalHT
").': '.$line->total_ht;
1562 if ($line->date_start || $line->date_end) {
1563 $htmlforlines .= '<br><div class="clearboth nowraponall
">'.get_date_range($line->date_start, $line->date_end).'</div>';
1565 $htmlforlines .= '</td>';
1567 // complete line by hook
1568 $parameters=array('line' => $line);
1569 $reshook=$hookmanager->executeHooks('completeTakePosInvoiceLine', $parameters, $invoice, $action); // Note that $action and $object may have been modified by some hooks
1570 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1571 $htmlforlines .= $hookmanager->resPrint;
1573 $htmlforlines .= '<td class="right
">'.vatrate($line->remise_percent, true).'</td>';
1574 $htmlforlines .= '<td class="right
">';
1575 if (isModEnabled('stock') && !empty($user->rights->stock->mouvement->lire)) {
1576 $constantforkey = 'CASHDESK_ID_WAREHOUSE'.$_SESSION["takeposterminal
"];
1577 if (!empty($conf->global->$constantforkey) && $line->fk_product > 0 && empty($conf->global->TAKEPOS_HIDE_STOCK_ON_LINE)) {
1578 $sql = "SELECT e.rowid, e.ref, e.lieu, e.fk_parent, e.statut, ps.reel, ps.rowid as product_stock_id, p.pmp
";
1579 $sql .= " FROM
".MAIN_DB_PREFIX."entrepot as e,
";
1580 $sql .= " ".MAIN_DB_PREFIX."product_stock as ps
";
1581 $sql .= " LEFT JOIN
".MAIN_DB_PREFIX."product as p ON p.rowid = ps.fk_product
";
1582 $sql .= " WHERE ps.reel != 0
";
1583 $sql .= " AND ps.fk_entrepot =
".((int) $conf->global->$constantforkey);
1584 $sql .= " AND e.entity IN (
".getEntity('stock').")
";
1585 $sql .= " AND ps.fk_product =
".((int) $line->fk_product);
1586 $resql = $db->query($sql);
1588 $obj = $db->fetch_object($resql);
1589 $stock_real = price2num($obj->reel, 'MS');
1590 $htmlforlines .= $line->qty;
1591 if ($line->qty && $line->qty > $stock_real) {
1592 $htmlforlines .= '<span style="color: var(--amountremaintopaycolor)
">';
1594 $htmlforlines .= ' <span class="posstocktoolow
">('.$langs->trans("Stock
").' '.$stock_real.')</span>';
1595 if ($line->qty && $line->qty > $stock_real) {
1596 $htmlforlines .= "</span>
";
1599 dol_print_error($db);
1602 $htmlforlines .= $line->qty;
1605 $htmlforlines .= $line->qty;
1608 $htmlforlines .= '</td>';
1609 if (getDolGlobalString('TAKEPOS_SHOW_HT')) {
1610 $htmlforlines .= '<td class="right classfortooltip
" title="'.$moreinfo.'">';
1611 $htmlforlines .= price($line->total_ht, 1, '', 1, -1, -1, $conf->currency);
1612 if (isModEnabled('multicurrency') && !empty($_SESSION["takeposcustomercurrency
"]) && $conf->currency != $_SESSION["takeposcustomercurrency
"]) {
1613 //Only show customer currency if multicurrency module is enabled, if currency selected and if this currency selected is not the same as main currency
1614 include_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php';
1615 $multicurrency = new MultiCurrency($db);
1616 $multicurrency->fetch(0, $_SESSION["takeposcustomercurrency
"]);
1617 $htmlforlines .= '<br><span id="linecolht-span-total
" style="font-size:0.9em; font-style:italic;
">('.price($line->total_ht * $multicurrency->rate->rate).' '.$_SESSION["takeposcustomercurrency
"].')</span>';
1619 $htmlforlines .= '</td>';
1621 $htmlforlines .= '<td class="right classfortooltip
" title="'.$moreinfo.'">';
1622 $htmlforlines .= price($line->total_ttc, 1, '', 1, -1, -1, $conf->currency);
1623 if (isModEnabled('multicurrency') && !empty($_SESSION["takeposcustomercurrency
"]) && $conf->currency != $_SESSION["takeposcustomercurrency
"]) {
1624 //Only show customer currency if multicurrency module is enabled, if currency selected and if this currency selected is not the same as main currency
1625 include_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php';
1626 $multicurrency = new MultiCurrency($db);
1627 $multicurrency->fetch(0, $_SESSION["takeposcustomercurrency
"]);
1628 $htmlforlines .= '<br><span id="linecolht-span-total
" style="font-size:0.9em; font-style:italic;
">('.price($line->total_ttc * $multicurrency->rate->rate).' '.$_SESSION["takeposcustomercurrency
"].')</span>';
1630 $htmlforlines .= '</td>';
1632 $htmlforlines .= '</tr>'."\n
";
1633 $htmlforlines .= empty($htmlsupplements[$line->id]) ? '' : $htmlsupplements[$line->id];
1635 print $htmlforlines;
1638 print '<tr class="drag drop oddeven
"><td class="left
"><span class="opacitymedium
">'.$langs->trans("Empty
").'</span></td><td></td><td></td><td></td>';
1639 if (!empty($conf->global->TAKEPOS_SHOW_HT)) {
1644 } else { // No invoice generated yet
1645 print '<tr class="drag drop oddeven
"><td class="left
"><span class="opacitymedium
">'.$langs->trans("Empty
").'</span></td><td></td><td></td><td></td>';
1647 if (!empty($conf->global->TAKEPOS_SHOW_HT)) {
1655 if (($action == "valid
" || $action == "history
") && $invoice->type != Facture::TYPE_CREDIT_NOTE) {
1656 print '<button id="buttonprint
" type="button
" onclick="ModalBox(\
'ModalCreditNote\')">'.$langs->trans(
'CreateCreditNote').
'</button>';
1660 if ($action ==
"search") {
1662 <input type="text" id="search" class="input-search-takepos" name="search" onkeyup="Search2(\'\', null);" style="width: 80%; font-size: 150%;" placeholder="'.dol_escape_htmltag($langs->trans(
'Search')).
'">