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,
'',
'');
317 $remaintopay = $invoice->getRemainToPay();
321 if ($remaintopay == 0) {
322 dol_syslog(
"Invoice is paid, so we set it to status Paid");
323 $result = $invoice->setPaid($user);
328 $invoice->setPaymentMethods($paiementid);
330 dol_syslog(
"Invoice is not paid, remain to pay = ".$remaintopay);
337 if ($action ==
'creditnote' && $user->rights->facture->creer) {
338 $creditnote =
new Facture($db);
339 $creditnote->socid = $invoice->socid;
341 $creditnote->module_source =
'takepos';
342 $creditnote->pos_source = isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'' ;
344 $creditnote->fk_facture_source = $placeid;
345 $creditnote->remise_absolue = $invoice->remise_absolue;
346 $creditnote->remise_percent = $invoice->remise_percent;
347 $creditnote->create($user);
349 foreach ($invoice->lines as $line) {
351 if (method_exists($line,
'fetch_optionals')) {
353 $line->fetch_optionals();
356 if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) {
360 $source_fk_prev_id = $line->fk_prev_id;
361 $line->fk_prev_id = $line->id;
362 if (!empty($invoice->tab_previous_situation_invoice)) {
365 $tab_jumped_credit_notes = array();
366 $lineIndex = count($invoice->tab_previous_situation_invoice) - 1;
367 $searchPreviousInvoice =
true;
368 while ($searchPreviousInvoice) {
370 $searchPreviousInvoice =
false;
374 $tab_jumped_credit_notes[$lineIndex] = $invoice->tab_previous_situation_invoice[$lineIndex]->id;
380 $maxPrevSituationPercent = 0;
381 foreach ($invoice->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine) {
382 if ($prevLine->id == $source_fk_prev_id) {
383 $maxPrevSituationPercent = max($maxPrevSituationPercent, $prevLine->situation_percent);
386 $line->total_ht = $line->total_ht - $prevLine->total_ht;
387 $line->total_tva = $line->total_tva - $prevLine->total_tva;
388 $line->total_ttc = $line->total_ttc - $prevLine->total_ttc;
389 $line->total_localtax1 = $line->total_localtax1 - $prevLine->total_localtax1;
390 $line->total_localtax2 = $line->total_localtax2 - $prevLine->total_localtax2;
392 $line->multicurrency_subprice = $line->multicurrency_subprice - $prevLine->multicurrency_subprice;
393 $line->multicurrency_total_ht = $line->multicurrency_total_ht - $prevLine->multicurrency_total_ht;
394 $line->multicurrency_total_tva = $line->multicurrency_total_tva - $prevLine->multicurrency_total_tva;
395 $line->multicurrency_total_ttc = $line->multicurrency_total_ttc - $prevLine->multicurrency_total_ttc;
400 $line->situation_percent = $maxPrevSituationPercent - $line->situation_percent;
405 $maxPrevSituationPercent = 0;
406 foreach ($tab_jumped_credit_notes as $index => $creditnoteid) {
407 foreach ($invoice->tab_previous_situation_invoice[$index]->lines as $prevLine) {
408 if ($prevLine->fk_prev_id == $source_fk_prev_id) {
409 $maxPrevSituationPercent = $prevLine->situation_percent;
411 $line->total_ht -= $prevLine->total_ht;
412 $line->total_tva -= $prevLine->total_tva;
413 $line->total_ttc -= $prevLine->total_ttc;
414 $line->total_localtax1 -= $prevLine->total_localtax1;
415 $line->total_localtax2 -= $prevLine->total_localtax2;
417 $line->multicurrency_subprice -= $prevLine->multicurrency_subprice;
418 $line->multicurrency_total_ht -= $prevLine->multicurrency_total_ht;
419 $line->multicurrency_total_tva -= $prevLine->multicurrency_total_tva;
420 $line->multicurrency_total_ttc -= $prevLine->multicurrency_total_ttc;
426 $line->situation_percent += $maxPrevSituationPercent;
432 $line->fk_facture = $creditnote->id;
433 $line->fk_parent_line = $fk_parent_line;
435 $line->subprice = -$line->subprice;
436 $line->pa_ht = $line->pa_ht;
437 $line->total_ht = -$line->total_ht;
438 $line->total_tva = -$line->total_tva;
439 $line->total_ttc = -$line->total_ttc;
440 $line->total_localtax1 = -$line->total_localtax1;
441 $line->total_localtax2 = -$line->total_localtax2;
443 $line->multicurrency_subprice = -$line->multicurrency_subprice;
444 $line->multicurrency_total_ht = -$line->multicurrency_total_ht;
445 $line->multicurrency_total_tva = -$line->multicurrency_total_tva;
446 $line->multicurrency_total_ttc = -$line->multicurrency_total_ttc;
448 $result = $line->insert(0, 1);
450 $creditnote->lines[] = $line;
453 if ($result > 0 && $line->product_type == 9) {
454 $fk_parent_line = $result;
457 $creditnote->update_price(1);
459 $constantforkey =
'CASHDESK_NO_DECREASE_STOCK'.$_SESSION[
"takeposterminal"];
460 if (
isModEnabled(
'stock') && $conf->global->$constantforkey !=
"1") {
461 $savconst = $conf->global->STOCK_CALCULATE_ON_BILL;
462 $conf->global->STOCK_CALCULATE_ON_BILL = 1;
463 $constantforkey =
'CASHDESK_ID_WAREHOUSE'.$_SESSION[
"takeposterminal"];
464 dol_syslog(
"Validate invoice with stock change into warehouse defined into constant ".$constantforkey.
" = ".$conf->global->$constantforkey);
466 if (
isModEnabled(
'productbatch') && !empty($conf->global->CASHDESK_FORCE_DECREASE_STOCK)) {
467 require_once DOL_DOCUMENT_ROOT.
'/product/class/productbatch.class.php';
470 $res = $creditnote->validate($user,
'', $conf->global->$constantforkey, 0, $batch_rule);
471 $conf->global->STOCK_CALCULATE_ON_BILL = $savconst;
473 $res = $creditnote->validate($user);
477 if ($action ==
'history' || $action ==
'creditnote') {
478 if ($action ==
'creditnote') {
479 $placeid = $creditnote->id;
481 $placeid = (int)
GETPOST(
'placeid',
'int');
484 $invoice->fetch($placeid);
487 if (($action ==
"addline" || $action ==
"freezone") && $placeid == 0) {
490 $invoice->module_source =
'takepos';
491 $invoice->pos_source = isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'' ;
492 $invoice->entity = !empty($_SESSION[
"takeposinvoiceentity"]) ? $_SESSION[
"takeposinvoiceentity"] : $conf->entity;
494 if ($invoice->socid <= 0) {
495 $langs->load(
'errors');
498 $placeid = $invoice->create($user);
502 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facture set ref='(PROV-POS".$_SESSION[
"takeposterminal"].
"-".$place.
")' where rowid = ".((int) $placeid);
507 if ($action ==
"addline") {
509 $prod->fetch($idproduct);
512 $customer->fetch($invoice->socid);
514 $datapriceofproduct = $prod->getSellPrice($mysoc, $customer, 0);
517 $price = $datapriceofproduct[
'pu_ht'];
518 $price_ttc = $datapriceofproduct[
'pu_ttc'];
520 $price_base_type = empty($datapriceofproduct[
'price_base_type']) ?
'HT' : $datapriceofproduct[
'price_base_type'];
521 $tva_tx = $datapriceofproduct[
'tva_tx'];
522 $tva_npr = $datapriceofproduct[
'tva_npr'];
525 $localtax1_tx =
get_localtax($tva_tx, 1, $customer, $mysoc, $tva_npr);
526 $localtax2_tx =
get_localtax($tva_tx, 2, $customer, $mysoc, $tva_npr);
528 if (!empty($conf->global->TAKEPOS_SUPPLEMENTS)) {
529 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
531 $categories = $cat->containing($idproduct,
'product');
532 $found = (array_search($conf->global->TAKEPOS_SUPPLEMENTS_CATEGORY, array_column($categories,
'id')));
533 if ($found !==
false) {
534 $sql =
"SELECT fk_parent_line FROM ".MAIN_DB_PREFIX.
"facturedet where rowid=$selectedline";
535 $resql = $db->query($sql);
536 $row = $db->fetch_array(
$resql);
537 if ($row[0] ==
null) {
538 $parent_line = $selectedline;
540 $parent_line = $row[0];
547 if (!empty($conf->global->TAKEPOS_GROUP_SAME_PRODUCT) && $line->special_code !=
"4") {
548 foreach ($invoice->lines as $line) {
549 if ($line->product_ref == $prod->ref) {
550 if ($line->special_code==4)
continue;
551 $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);
555 $idoflineadded = $line->id;
561 if ($idoflineadded <= 0) {
562 $invoice->fetch_thirdparty();
563 $array_options = array();
566 $parameters = array(
'prod' => $prod);
567 $reshook=$hookmanager->executeHooks(
'completeTakePosAddLine', $parameters, $invoice, $action);
568 if ($reshook < 0)
setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
570 if (empty($reshook)) {
571 $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);
574 if (!empty($conf->global->TAKEPOS_CUSTOMER_DISPLAY)) {
575 $CUSTOMER_DISPLAY_line1 = $prod->label;
576 $CUSTOMER_DISPLAY_line2 =
price($price_ttc);
580 $invoice->fetch($placeid);
583 if ($action ==
"freezone") {
585 $customer->fetch($invoice->socid);
587 $tva_tx =
GETPOST(
'tva_tx',
'alpha');
589 if (!preg_match(
'/\((.*)\)/', $tva_tx)) {
597 $localtax1_tx =
get_localtax($tva_tx, 1, $customer, $mysoc, $tva_npr);
598 $localtax2_tx =
get_localtax($tva_tx, 2, $customer, $mysoc, $tva_npr);
600 $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);
601 $invoice->fetch($placeid);
604 if ($action ==
"addnote") {
605 $desc =
GETPOST(
'addnote',
'alpha');
607 $invoice->update_note($desc,
'_public');
608 }
else foreach ($invoice->lines as $line) {
609 if ($line->id == $idline) {
610 $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);
613 $invoice->fetch($placeid);
616 if ($action ==
"deleteline") {
617 if ($idline > 0 and $placeid > 0) {
618 $invoice->deleteline($idline);
619 $invoice->fetch($placeid);
620 } elseif ($placeid > 0) {
621 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"facturedet where fk_facture = ".((int) $placeid).
" ORDER BY rowid DESC";
622 $resql = $db->query($sql);
623 $row = $db->fetch_array(
$resql);
624 $deletelineid = $row[0];
625 $invoice->deleteline($deletelineid);
626 $invoice->fetch($placeid);
628 if (count($invoice->lines) == 0) {
629 $invoice->delete($user);
630 header(
"Location: ".DOL_URL_ROOT.
"/takepos/invoice.php");
636 if ($action ==
"delete") {
639 $result = $invoice->fetch($placeid);
646 foreach ($invoice->lines as $line) {
647 $tmpres = $invoice->deleteline($line->id);
654 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facture";
655 $varforconst =
'CASHDESK_ID_THIRDPARTY'.$_SESSION[
"takeposterminal"];
656 $sql .=
" SET fk_soc = ".((int) $conf->global->$varforconst).
", ";
657 $sql .=
" datec = '".$db->idate(
dol_now()).
"'";
658 $sql .=
" WHERE ref = '(PROV-POS".$db->escape($_SESSION[
"takeposterminal"].
"-".$place).
")'";
659 $resql1 = $db->query($sql);
661 if ($resdeletelines && $resql1) {
667 $invoice->fetch($placeid);
672 if ($action ==
"updateqty") {
673 foreach ($invoice->lines as $line) {
674 if ($line->id == $idline) {
675 if (!$user->rights->takepos->editlines || (!$user->rights->takepos->editorderedlines && $line->special_code ==
"4")) {
678 $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);
683 $invoice->fetch($placeid);
686 if ($action ==
"updateprice") {
688 $customer->fetch($invoice->socid);
690 foreach ($invoice->lines as $line) {
691 if ($line->id == $idline) {
693 $prod->fetch($line->fk_product);
694 $datapriceofproduct = $prod->getSellPrice($mysoc, $customer, 0);
695 $price_min = $datapriceofproduct[
'price_min'];
696 $usercanproductignorepricemin = ((!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->produit->ignore_price_min_advance)) || empty($conf->global->MAIN_USE_ADVANCED_PERMS));
697 $pu_ht =
price2num($number / (1 + ($line->tva_tx / 100)),
'MU');
699 if ($usercanproductignorepricemin && (!empty($price_min) && (
price2num($pu_ht) * (1 -
price2num($line->remise_percent) / 100) <
price2num($price_min)))) {
700 echo $langs->trans(
"CantBeLessThanMinPrice");
702 if (empty($user->rights->takepos->editlines) || (empty($user->rights->takepos->editorderedlines) && $line->special_code ==
"4")) {
705 $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);
707 $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);
714 $invoice->fetch($placeid);
717 if ($action ==
"updatereduction") {
719 $customer->fetch($invoice->socid);
721 foreach ($invoice->lines as $line) {
722 if ($line->id == $idline) {
723 dol_syslog(
"updatereduction Process line ".$line->id.
' to apply discount of '.$number.
'%');
726 $prod->fetch($line->fk_product);
728 $datapriceofproduct = $prod->getSellPrice($mysoc, $customer, 0);
729 $price_min = $datapriceofproduct[
'price_min'];
730 $usercanproductignorepricemin = ((!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->produit->ignore_price_min_advance)) || empty($conf->global->MAIN_USE_ADVANCED_PERMS));
732 $pu_ht =
price2num($line->subprice / (1 + ($line->tva_tx / 100)),
'MU');
735 if ($usercanproductignorepricemin && (!empty($price_min) && (
price2num($line->subprice) * (1 -
price2num($number) / 100) <
price2num($price_min)))) {
736 echo $langs->trans(
"CantBeLessThanMinPrice");
738 if (empty($user->rights->takepos->editlines) || (empty($user->rights->takepos->editorderedlines) && $line->special_code ==
"4")) {
741 $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);
748 $invoice->fetch($placeid);
749 } elseif ($action ==
'update_reduction_global') {
750 foreach ($invoice->lines as $line) {
751 $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);
754 $invoice->fetch($placeid);
757 if ($action ==
"order" and $placeid != 0) {
758 include_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
759 if ($conf->global->TAKEPOS_PRINT_METHOD ==
"receiptprinter" || $conf->global->TAKEPOS_PRINT_METHOD ==
"takeposconnector") {
760 require_once DOL_DOCUMENT_ROOT.
'/core/class/dolreceiptprinter.class.php';
764 $sql =
"SELECT label FROM ".MAIN_DB_PREFIX.
"takepos_floor_tables where rowid=".((int) $place);
765 $resql = $db->query($sql);
766 $row = $db->fetch_object(
$resql);
767 $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>';
768 $footerorder =
'</tbody></table>'.dol_print_date(
dol_now(),
'dayhour').
'<br></html>';
769 $order_receipt_printer1 =
"";
770 $order_receipt_printer2 =
"";
771 $order_receipt_printer3 =
"";
772 $catsprinter1 = explode(
';', $conf->global->TAKEPOS_PRINTED_CATEGORIES_1);
773 $catsprinter2 = explode(
';', $conf->global->TAKEPOS_PRINTED_CATEGORIES_2);
774 $catsprinter3 = explode(
';', $conf->global->TAKEPOS_PRINTED_CATEGORIES_3);
776 foreach ($invoice->lines as $line) {
777 if ($line->special_code ==
"4") {
781 $existing = $c->containing($line->fk_product, Categorie::TYPE_PRODUCT,
'id');
782 $result = array_intersect($catsprinter1, $existing);
783 $count = count($result);
784 if (!$line->fk_product) {
789 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facturedet set special_code='1' where rowid=".$line->id;
791 $order_receipt_printer1 .=
'<tr><td class="left">';
792 if ($line->fk_product) {
793 $order_receipt_printer1 .= $line->product_label;
795 $order_receipt_printer1 .= $line->description;
797 $order_receipt_printer1 .=
'</td><td class="right">'.$line->qty;
798 if (!empty($line->array_options[
'options_order_notes'])) {
799 $order_receipt_printer1 .=
"<br>(".$line->array_options[
'options_order_notes'].
")";
801 $order_receipt_printer1 .=
'</td></tr>';
804 if (($conf->global->TAKEPOS_PRINT_METHOD ==
"receiptprinter" || $conf->global->TAKEPOS_PRINT_METHOD ==
"takeposconnector") && $linestoprint > 0) {
805 $invoice->fetch($placeid);
806 $printer->orderprinter = 1;
808 echo
"var orderprinter1esc='";
809 $ret = $printer->sendToPrinter($invoice,
getDolGlobalInt(
'TAKEPOS_TEMPLATE_TO_USE_FOR_ORDERS'.$_SESSION[
"takeposterminal"]),
getDolGlobalInt(
'TAKEPOS_ORDER_PRINTER1_TO_USE'.$_SESSION[
"takeposterminal"]));
812 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facturedet set special_code='4' where special_code='1' and fk_facture=".$invoice->id;
814 $invoice->fetch($placeid);
817 foreach ($invoice->lines as $line) {
818 if ($line->special_code ==
"4") {
822 $existing = $c->containing($line->fk_product, Categorie::TYPE_PRODUCT,
'id');
823 $result = array_intersect($catsprinter2, $existing);
824 $count = count($result);
827 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facturedet set special_code='2' where rowid=".$line->id;
829 $order_receipt_printer2 .=
'<tr>'.$line->product_label.
'<td class="right">'.$line->qty;
830 if (!empty($line->array_options[
'options_order_notes'])) {
831 $order_receipt_printer2 .=
"<br>(".$line->array_options[
'options_order_notes'].
")";
833 $order_receipt_printer2 .=
'</td></tr>';
836 if (($conf->global->TAKEPOS_PRINT_METHOD ==
"receiptprinter" || $conf->global->TAKEPOS_PRINT_METHOD ==
"takeposconnector") && $linestoprint > 0) {
837 $invoice->fetch($placeid);
838 $printer->orderprinter = 2;
840 echo
"var orderprinter2esc='";
841 $ret = $printer->sendToPrinter($invoice,
getDolGlobalInt(
'TAKEPOS_TEMPLATE_TO_USE_FOR_ORDERS'.$_SESSION[
"takeposterminal"]),
getDolGlobalInt(
'TAKEPOS_ORDER_PRINTER2_TO_USE'.$_SESSION[
"takeposterminal"]));
844 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facturedet set special_code='4' where special_code='2' and fk_facture=".$invoice->id;
846 $invoice->fetch($placeid);
849 foreach ($invoice->lines as $line) {
850 if ($line->special_code ==
"4") {
854 $existing = $c->containing($line->fk_product, Categorie::TYPE_PRODUCT,
'id');
855 $result = array_intersect($catsprinter3, $existing);
856 $count = count($result);
859 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facturedet set special_code='3' where rowid=".$line->id;
861 $order_receipt_printer3 .=
'<tr>'.$line->product_label.
'<td class="right">'.$line->qty;
862 if (!empty($line->array_options[
'options_order_notes'])) {
863 $order_receipt_printer3 .=
"<br>(".$line->array_options[
'options_order_notes'].
")";
865 $order_receipt_printer3 .=
'</td></tr>';
868 if (($conf->global->TAKEPOS_PRINT_METHOD ==
"receiptprinter" || $conf->global->TAKEPOS_PRINT_METHOD ==
"takeposconnector") && $linestoprint > 0) {
869 $invoice->fetch($placeid);
870 $printer->orderprinter = 3;
872 echo
"var orderprinter3esc='";
873 $ret = $printer->sendToPrinter($invoice,
getDolGlobalInt(
'TAKEPOS_TEMPLATE_TO_USE_FOR_ORDERS'.$_SESSION[
"takeposterminal"]),
getDolGlobalInt(
'TAKEPOS_ORDER_PRINTER3_TO_USE'.$_SESSION[
"takeposterminal"]));
876 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facturedet set special_code='4' where special_code='3' and fk_facture=".$invoice->id;
878 $invoice->fetch($placeid);
881 $sectionwithinvoicelink =
'';
882 if ($action ==
"valid" || $action ==
"history" || $action ==
'creditnote') {
883 $sectionwithinvoicelink .=
'<!-- Section with invoice link -->'.
"\n";
884 $sectionwithinvoicelink .=
'<span style="font-size:120%;" class="center">';
885 $sectionwithinvoicelink .= $invoice->getNomUrl(1,
'', 0, 0,
'', 0, 0, -1,
'_backoffice').
" - ";
886 $remaintopay = $invoice->getRemainToPay();
887 if ($remaintopay > 0) {
888 $sectionwithinvoicelink .= $langs->trans(
'RemainToPay').
': <span class="amountremaintopay" style="font-size: unset">'.
price($remaintopay, 1, $langs, 1, -1, -1, $conf->currency).
'</span>';
890 if ($invoice->paye) {
891 $sectionwithinvoicelink .=
'<span class="amountpaymentcomplete" style="font-size: unset">'.$langs->trans(
"Paid").
'</span>';
893 $sectionwithinvoicelink .= $langs->trans(
'BillShortStatusValidated');
896 $sectionwithinvoicelink .=
'</span><br>';
898 if (
getDolGlobalString(
'TAKEPOS_PRINT_SERVER') && filter_var($conf->global->TAKEPOS_PRINT_SERVER, FILTER_VALIDATE_URL) ==
true) {
899 $sectionwithinvoicelink .=
' <button id="buttonprint" type="button" onclick="TakeposConnector('.$placeid.
');">'.$langs->trans(
'PrintTicket').
'</button>';
901 $sectionwithinvoicelink .=
' <button id="buttonprint" type="button" onclick="TakeposPrinting('.$placeid.
');">'.$langs->trans(
'PrintTicket').
'</button>';
904 $sectionwithinvoicelink .=
' <button id="buttonprint" type="button" onclick="DolibarrTakeposPrinting('.$placeid.
');">'.$langs->trans(
'PrintTicket').
'</button>';
906 $sectionwithinvoicelink .=
' <button id="buttonprint" type="button" onclick="Print('.$placeid.
');">'.$langs->trans(
'PrintTicket').
'</button>';
908 $sectionwithinvoicelink .=
' <button id="buttonprint" type="button" onclick="PrintBox('.$placeid.
', \'without_details\');">'.$langs->trans(
'PrintWithoutDetails').
'</button>';
911 $sectionwithinvoicelink .=
' <button id="buttonprint" type="button" onclick="Print('.$placeid.
', 1);">'.$langs->trans(
'GiftReceipt').
'</button>';
914 if (
getDolGlobalString(
'TAKEPOS_EMAIL_TEMPLATE_INVOICE') && $conf->global->TAKEPOS_EMAIL_TEMPLATE_INVOICE > 0) {
915 $sectionwithinvoicelink .=
' <button id="buttonsend" type="button" onclick="SendTicket('.$placeid.
');">'.$langs->trans(
'SendTicket').
'</button>';
918 if ($remaintopay <= 0 &&
getDolGlobalString(
'TAKEPOS_AUTO_PRINT_TICKETS') && $action !=
"history") {
919 $sectionwithinvoicelink .=
'<script type="text/javascript">$("#buttonprint").click();</script>';
931 <script
type=
"text/javascript">
934 <?php
if ($action==
"valid") echo
"var place=0;";?>
935 var placeid=<?php echo ($placeid > 0 ? $placeid : 0); ?>;
936 $(document).ready(
function() {
937 var idoflineadded = <?php echo (empty($idoflineadded) ? 0 : $idoflineadded); ?>;
939 $(
'.posinvoiceline').click(
function(){
940 console.log(
"Click done on "+this.
id);
941 $(
'.posinvoiceline').removeClass(
"selected");
942 $(
this).addClass(
"selected");
943 if (selectedline==this.
id)
return;
944 else selectedline=this.id;
945 selectedtext=$(
'#'+selectedline).find(
"td:first").html();
947 if (defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
948 print
'$("#phonediv1").load("auto_order.php?action=editline&token='.newToken().
'&placeid="+placeid+"&selectedline="+selectedline, function() {
955 if (idoflineadded > 0)
957 console.log(
"Auto select "+idoflineadded);
958 $(
'.posinvoiceline#'+idoflineadded).click();
962 if ($action ==
"order" && !empty($order_receipt_printer1)) {
963 if (filter_var($conf->global->TAKEPOS_PRINT_SERVER, FILTER_VALIDATE_URL) ==
true) {
967 url:
'<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>/printer/index.php',
968 data:
'invoice='+orderprinter1esc
975 url:
'http://<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>:8111/print',
977 print $headerorder.$order_receipt_printer1.$footerorder; ?>'
983 if ($action ==
"order" && !empty($order_receipt_printer2)) {
984 if (filter_var($conf->global->TAKEPOS_PRINT_SERVER, FILTER_VALIDATE_URL) ==
true) {
988 url:
'<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>/printer/index.php?printer=2',
989 data:
'invoice='+orderprinter2esc
996 url:
'http://<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>:8111/print2',
998 print $headerorder.$order_receipt_printer2.$footerorder; ?>'
1004 if ($action ==
"order" && !empty($order_receipt_printer3)) {
1005 if (filter_var($conf->global->TAKEPOS_PRINT_SERVER, FILTER_VALIDATE_URL) ==
true) {
1009 url:
'<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>/printer/index.php?printer=3',
1010 data:
'invoice='+orderprinter3esc
1017 if ($action ==
"search" || $action ==
"valid") {
1019 parent.setFocusOnSearchField();
1024 if ($action ==
"temp" && !empty($ticket_printer1)) {
1028 url:
'http://<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>:8111/print',
1030 print $header_soc.$header_ticket.$body_ticket.$ticket_printer1.$ticket_total.$footer_ticket; ?>'
1035 if ($action ==
"search") {
1037 $(
'#search').focus();
1045 function SendTicket(
id)
1047 console.log(
"Open box to select the Print/Send form");
1048 $.colorbox({href:
"send.php?facid="+id, width:
"70%", height:
"30%", transition:
"none", iframe:
"true", title:
'<?php echo dol_escape_js($langs->trans("SendTicket")); ?>'});
1051 function PrintBox(
id, action) {
1052 console.log(
"Open box before printing");
1053 $.colorbox({href:
"printbox.php?facid="+
id+
"&action="+action, width:
"80%", height:
"200px", transition:
"none", iframe:
"true", title:
"<?php echo $langs->trans("PrintWithoutDetails
"); ?>"});
1056 function Print(
id, gift){
1057 console.log(
"Call Print() to generate the receipt.");
1058 $.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")); ?>'});
1061 function TakeposPrinting(
id){
1063 console.log(
"TakeposPrinting" +
id);
1064 $.get(
"receipt.php?facid="+
id,
function(data, status){
1065 receipt=data.replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g,
'');
1068 url:
'http://<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER
'); ?>:8111/print',
1074 function TakeposConnector(
id){
1075 console.log(
"TakeposConnector" +
id);
1076 $.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) {
1079 url:
'<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER
'); ?>/printer/index.php',
1080 data:
'invoice='+data
1085 function DolibarrTakeposPrinting(
id) {
1086 console.log(
"DolibarrTakeposPrinting Printing invoice ticket " +
id)
1089 data: { token:
'<?php echo currentToken(); ?>' },
1090 url:
"<?php print DOL_URL_ROOT.'/takepos/ajax/ajax.php?action=printinvoiceticket&term='.urlencode(isset($_SESSION["takeposterminal
"]) ? $_SESSION["takeposterminal
"] : '').'&id='; ?>" + id,
1094 function CreditNote() {
1095 $(
"#poslines").load(
"invoice.php?action=creditnote&token=<?php echo newToken() ?>&invoiceid="+placeid,
function() {
1099 function SetNote() {
1100 $(
"#poslines").load(
"invoice.php?action=addnote&token=<?php echo newToken() ?>&invoiceid="+placeid+
"&idline="+selectedline, {
"addnote": $(
"#textinput").val() });
1104 $( document ).ready(
function() {
1105 console.log(
"Set customer info and sales in header placeid=<?php echo $placeid; ?> status=<?php echo $invoice->statut; ?>");
1108 $s = $langs->trans(
"Customer");
1109 if ($invoice->id > 0 && ($invoice->socid != $conf->global->$constforcompanyid)) {
1114 $(
"#customerandsales").html(
'');
1115 $(
"#shoppingcart").html(
'');
1117 $(
"#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>');
1120 $sql =
"SELECT rowid, datec, ref FROM ".MAIN_DB_PREFIX.
"facture";
1121 if (empty($conf->global->TAKEPOS_CAN_EDIT_IF_ALREADY_VALIDATED)) {
1123 $sql .=
" WHERE ref LIKE '(PROV-POS".$db->escape(isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'').
"-0%' AND entity IN (".
getEntity(
'invoice').
")";
1126 $sql .=
" WHERE pos_source = '".$db->escape($_SESSION[
"takeposterminal"]).
"'";
1127 $sql .=
" AND module_source = 'takepos'";
1128 $sql .=
" AND entity IN (".getEntity(
'invoice').
")";
1131 $sql .= $db->order(
'datec',
'ASC');
1132 $resql = $db->query($sql);
1135 while ($obj = $db->fetch_object(
$resql)) {
1136 echo
'$("#shoppingcart").append(\'';
1137 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=\\\'';
1138 $num_sale = str_replace(
")",
"", str_replace(
"(PROV-POS".$_SESSION[
"takeposterminal"].
"-",
"", $obj->ref));
1140 if (str_replace(
"-",
"", $num_sale) > $max_sale) {
1141 $max_sale = str_replace(
"-",
"", $num_sale);
1143 echo
'\\\'; invoiceid=\\\'';
1145 echo
'\\\'; Refresh();">';
1146 if ($placeid == $obj->rowid) {
1149 echo
'<span class="fa fa-shopping-cart paddingright"></span>'.dol_print_date($db->jdate($obj->datec),
'%H:%M',
'tzuser');
1150 if ($placeid == $obj->rowid) {
1155 echo
'$("#shoppingcart").append(\'<a onclick="place=\\\'0-';
1157 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>\');';
1165 $constantforkey =
'CASHDESK_NO_DECREASE_STOCK'. (isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
1168 $constantforkey =
'CASHDESK_ID_WAREHOUSE'. (isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
1170 if ($idwarehouse > 0) {
1171 $s =
'<span class="small">';
1173 $warehouse->fetch($idwarehouse);
1174 $s .=
'<span class="hideonsmartphone">'.$langs->trans(
"Warehouse").
'<br></span>'.$warehouse->ref;
1176 $s .=
' ('.$langs->trans(
"Closed").
')';
1179 print
"$('#infowarehouse').html('".dol_escape_js($s).
"');";
1180 print
'$("#infowarehouse").css("display", "inline-block");';
1182 $s =
'<span class="small hideonsmartphone">';
1183 $s .= $langs->trans(
"StockChangeDisabled").
'<br>'.$langs->trans(
"NoWarehouseDefinedForTerminal");
1185 print
"$('#infowarehouse').html('".dol_escape_js($s).
"');";
1186 if (!empty($conf->dol_optimize_smallscreen)) {
1187 print
'$("#infowarehouse").css("display", "none");';
1191 $s =
'<span class="small hideonsmartphone">'.$langs->trans(
"StockChangeDisabled").
'</span>';
1192 print
"$('#infowarehouse').html('".dol_escape_js($s).
"');";
1193 if (!empty($conf->dol_optimize_smallscreen)) {
1194 print
'$("#infowarehouse").css("display", "none");';
1202 if (
isModEnabled(
'adherent') && $invoice->socid > 0 && $invoice->socid != $conf->global->$constforcompanyid) {
1203 $s =
'<span class="small">';
1204 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
1205 $langs->load(
"members");
1206 $s .= $langs->trans(
"Member").
': ';
1208 $result = $adh->fetch(
'',
'', $invoice->socid);
1210 $adh->ref = $adh->getFullName($langs);
1214 $s .= $adh->getFullName($langs);
1215 $s .=
' - '.$adh->type;
1216 if ($adh->datefin) {
1217 $s .=
'<br>'.$langs->trans(
"SubscriptionEndDate").
': '.
dol_print_date($adh->datefin,
'day');
1218 if ($adh->hasDelay()) {
1219 $s .=
" ".img_warning($langs->trans(
"Late"));
1222 $s .=
'<br>'.$langs->trans(
"SubscriptionNotReceived");
1223 if ($adh->statut > 0) {
1224 $s .=
" ".img_warning($langs->trans(
"Late"));
1231 $s .=
'<br>'.$langs->trans(
"ThirdpartyNotLinkedToMember");
1236 $(
"#moreinfo").html(
'<?php print dol_escape_js($s); ?>');
1242 if (!empty($conf->global->TAKEPOS_CUSTOMER_DISPLAY)) {
1243 echo
"function CustomerDisplay(){";
1244 echo
"var line1='".$CUSTOMER_DISPLAY_line1.
"'.substring(0,20);";
1245 echo
"line1=line1.padEnd(20);";
1246 echo
"var line2='".$CUSTOMER_DISPLAY_line2.
"'.substring(0,20);";
1247 echo
"line2=line2.padEnd(20);";
1250 data: { text: line1+line2 },
1251 url: '".getDolGlobalString(
'TAKEPOS_PRINT_SERVER').
"/display/index.php',
1262 if (!empty($conf->use_javascript_ajax)) {
1263 print
"\n".
'<!-- Includes JS Footer of Dolibarr -->'.
"\n";
1264 print
'<script src="'.DOL_URL_ROOT.
'/core/js/lib_foot.js.php?lang='.$langs->defaultlang.
'"></script>'.
"\n";
1267 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";
1268 print
'<div class="div-table-responsive-no-min invoice">';
1269 print
'<table id="tablelines" class="noborder noshadow postablelines" width="100%">';
1270 if ($sectionwithinvoicelink && ($mobilepage ==
"invoice" || $mobilepage ==
"")) {
1271 if (!empty($conf->global->TAKEPOS_SHOW_HT)) {
1272 print
'<tr><td colspan="5">'.$sectionwithinvoicelink.
'</td></tr>';
1274 print
'<tr><td colspan="4">'.$sectionwithinvoicelink.
'</td></tr>';
1277 print
'<tr class="liste_titre nodrag nodrop">';
1278 print
'<td class="linecoldescription">';
1280 if (empty($mobilepage) || $mobilepage ==
"invoice") {
1281 print
'<input type="hidden" name="invoiceid" id="invoiceid" value="'.$invoice->id.
'">';
1284 $sql =
"SELECT floor, label FROM ".MAIN_DB_PREFIX.
"takepos_floor_tables where rowid=".((int) $place);
1285 $resql = $db->query($sql);
1286 $obj = $db->fetch_object(
$resql);
1288 $label = $obj->label;
1289 $floor = $obj->floor;
1291 if ($mobilepage ==
"invoice" || $mobilepage ==
"") {
1294 print
'<span class="opacitymedium">'.$langs->trans(
'Place').
"</span> <b>".(empty($label) ?
'?' : $label).
"</b><br>";
1295 print
'<span class="opacitymedium">'.$langs->trans(
'Floor').
"</span> <b>".(empty($floor) ?
'?' : $floor).
"</b>";
1296 } elseif (defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1298 } elseif ($mobilepage ==
"cats") {
1299 print $langs->trans(
'Category');
1300 } elseif ($mobilepage ==
"products") {
1301 print $langs->trans(
'Label');
1304 print $langs->trans(
"Products");
1309 $parameters=array();
1310 $reshook=$hookmanager->executeHooks(
'completeTakePosInvoiceHeader', $parameters, $invoice, $action);
1311 if ($reshook < 0)
setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
1312 print $hookmanager->resPrint;
1314 if (empty($_SESSION[
"basiclayout"]) || $_SESSION[
"basiclayout"] != 1) {
1315 print
'<td class="linecolqty right">'.$langs->trans(
'ReductionShort').
'</td>';
1316 print
'<td class="linecolqty right">'.$langs->trans(
'Qty').
'</td>';
1318 print
'<td class="linecolht right nowraponall">';
1319 print
'<span class="opacitymedium small">' . $langs->trans(
'TotalHTShort') .
'</span><br>';
1321 if (empty($mobilepage) || $mobilepage ==
"invoice") {
1322 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>';
1323 if (
isModEnabled(
'multicurrency') && $_SESSION[
"takeposcustomercurrency"] !=
"" && $conf->currency != $_SESSION[
"takeposcustomercurrency"]) {
1325 include_once DOL_DOCUMENT_ROOT .
'/multicurrency/class/multicurrency.class.php';
1327 $multicurrency->fetch(0, $_SESSION[
"takeposcustomercurrency"]);
1328 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>';
1334 print
'<td class="linecolht right nowraponall">';
1335 print
'<span class="opacitymedium small">'.$langs->trans(
'TotalTTCShort').
'</span><br>';
1337 if (empty($mobilepage) || $mobilepage ==
"invoice") {
1338 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>';
1339 if (
isModEnabled(
'multicurrency') && !empty($_SESSION[
"takeposcustomercurrency"]) && $conf->currency != $_SESSION[
"takeposcustomercurrency"]) {
1341 include_once DOL_DOCUMENT_ROOT.
'/multicurrency/class/multicurrency.class.php';
1343 $multicurrency->fetch(0, $_SESSION[
"takeposcustomercurrency"]);
1344 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>';
1349 } elseif ($mobilepage ==
"invoice") {
1350 print
'<td class="linecolqty right">'.$langs->trans(
'Qty').
'</td>';
1355 if (!empty($_SESSION[
"basiclayout"]) && $_SESSION[
"basiclayout"] == 1) {
1356 if ($mobilepage ==
"cats") {
1357 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1359 $categories = $categorie->get_full_arbo(
'product');
1361 foreach ($categories as $row) {
1362 if (defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1363 $htmlforlines .=
'<div class="leftcat';
1365 $htmlforlines .=
'<tr class="drag drop oddeven posinvoiceline';
1367 $htmlforlines .=
'" onclick="LoadProducts('.$row[
'id'].
');">';
1368 if (defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1369 $htmlforlines .=
'<img class="imgwrapper" width="33%" src="'.DOL_URL_ROOT.
'/takepos/public/auto_order.php?genimg=cat&query=cat&id='.$row[
'id'].
'"><br>';
1371 $htmlforlines .=
'<td class="left">';
1373 $htmlforlines .= $row[
'label'];
1374 if (defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1375 $htmlforlines .=
'</div>'.
"\n";
1377 $htmlforlines .=
'</td></tr>'.
"\n";
1380 $htmlforlines .=
'</table>';
1381 $htmlforlines .=
'</table>';
1382 print $htmlforlines;
1385 if ($mobilepage ==
"products") {
1386 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1388 $catid =
GETPOST(
'catid',
'int');
1389 $result = $object->fetch($catid);
1390 $prods = $object->getObjectsInCateg(
"product");
1392 foreach ($prods as $row) {
1393 if (defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1394 $htmlforlines .=
'<div class="leftcat';
1396 $htmlforlines .=
'<tr class="drag drop oddeven posinvoiceline';
1398 $htmlforlines .=
'" onclick="AddProduct(\''.$place.
'\',
'.$row->id.')
">';
1399 if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1400 $htmlforlines .= '<img class="imgwrapper
" width="33%
" src="'.DOL_URL_ROOT.'/takepos/
public/auto_order.php?genimg=pro&query=pro&
id=
'.$row->id.'"><br>';
1401 $htmlforlines .= $row->label.''.price($row->price_ttc, 1, $langs, 1, -1, -1, $conf->currency);
1402 $htmlforlines .= '</div>'."\n
";
1404 $htmlforlines .= '<td class="left
">';
1405 $htmlforlines .= $row->label;
1406 $htmlforlines .= '<div class="right
">'.price($row->price_ttc, 1, $langs, 1, -1, -1, $conf->currency).'</div>';
1407 $htmlforlines .= '</tr>'."\n
";
1410 $htmlforlines .= '</table>';
1411 print $htmlforlines;
1414 if ($mobilepage == "places
") {
1415 $sql = "SELECT
rowid, entity, label, leftpos, toppos, floor FROM
".MAIN_DB_PREFIX."takepos_floor_tables
";
1416 $resql = $db->query($sql);
1419 while ($row = $db->fetch_array($resql)) {
1421 $htmlforlines .= '<tr class="drag drop oddeven posinvoiceline
';
1422 $htmlforlines .= '" onclick="LoadPlace(\
''.$row[
'label'].
'\')
">';
1423 $htmlforlines .= '<td class="left
">';
1424 $htmlforlines .= $row['label'];
1425 $htmlforlines .= '</td>';
1426 $htmlforlines .= '</tr>'."\n
";
1428 $htmlforlines .= '</table>';
1429 print $htmlforlines;
1434 //In Phone basic layout hide some content depends situation
1435 if (!empty($_SESSION["basiclayout
"]) && $_SESSION["basiclayout
"] == 1 && $mobilepage != "invoice
" && $action != "order
") {
1439 if (is_array($invoice->lines) && count($invoice->lines)) {
1440 print '<!-- invoice.php show lines of invoices -->'."\n
";
1441 $tmplines = array_reverse($invoice->lines);
1442 $htmlsupplements = array();
1443 foreach ($tmplines as $line) {
1444 if ($line->fk_parent_line != false) {
1445 $htmlsupplements[$line->fk_parent_line] .= '<tr class="drag drop oddeven posinvoiceline
';
1446 if ($line->special_code == "4") {
1447 $htmlsupplements[$line->fk_parent_line] .= ' order
';
1449 $htmlsupplements[$line->fk_parent_line] .= '" id="'.$line->id.'"';
1450 if ($line->special_code == "4
") {
1451 $htmlsupplements[$line->fk_parent_line] .= ' title="'.dol_escape_htmltag($langs->trans("AlreadyPrinted")).'"';
1453 $htmlsupplements[$line->fk_parent_line] .= '>';
1454 $htmlsupplements[$line->fk_parent_line] .= '<td class="left
">';
1455 $htmlsupplements[$line->fk_parent_line] .= img_picto('', 'rightarrow');
1456 if ($line->product_label) {
1457 $htmlsupplements[$line->fk_parent_line] .= $line->product_label;
1459 if ($line->product_label && $line->desc) {
1460 $htmlsupplements[$line->fk_parent_line] .= '<br>';
1462 if ($line->product_label != $line->desc) {
1463 $firstline = dolGetFirstLineOfText($line->desc);
1464 if ($firstline != $line->desc) {
1465 $htmlsupplements[$line->fk_parent_line] .= $form->textwithpicto(dolGetFirstLineOfText($line->desc), $line->desc);
1467 $htmlsupplements[$line->fk_parent_line] .= $line->desc;
1470 $htmlsupplements[$line->fk_parent_line] .= '</td>';
1472 // complete line by hook
1473 $parameters=array('line' => $line);
1474 $reshook=$hookmanager->executeHooks('completeTakePosInvoiceParentLine', $parameters, $invoice, $action); // Note that $action and $object may have been modified by some hooks
1475 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1476 $htmlsupplements[$line->fk_parent_line] .= $hookmanager->resPrint;
1478 if (empty($_SESSION["basiclayout
"]) || $_SESSION["basiclayout
"] != 1) {
1479 $htmlsupplements[$line->fk_parent_line] .= '<td class="right
">'.vatrate($line->remise_percent, true).'</td>';
1480 $htmlsupplements[$line->fk_parent_line] .= '<td class="right
">'.$line->qty.'</td>';
1481 $htmlsupplements[$line->fk_parent_line] .= '<td class="right
">'.price($line->total_ttc).'</td>';
1483 $htmlsupplements[$line->fk_parent_line] .= '</tr>'."\n
";
1488 $htmlforlines .= '<tr class="drag drop oddeven posinvoiceline
';
1489 if ($line->special_code == "4") {
1490 $htmlforlines .= ' order
';
1492 $htmlforlines .= '" id="'.$line->id.'"';
1493 if ($line->special_code == "4
") {
1494 $htmlforlines .= ' title="'.dol_escape_htmltag($langs->trans("AlreadyPrinted")).'"';
1496 $htmlforlines .= '>';
1497 $htmlforlines .= '<td class="left
">';
1498 if (!empty($_SESSION["basiclayout
"]) && $_SESSION["basiclayout
"] == 1) {
1499 $htmlforlines .= '<span class="phoneqty
">'.$line->qty."</span> x
";
1501 if (isset($line->product_type)) {
1502 if (empty($line->product_type)) {
1503 $htmlforlines .= img_object('', 'product').' ';
1505 $htmlforlines .= img_object('', 'service').' ';
1508 if (empty($conf->global->TAKEPOS_SHOW_N_FIRST_LINES)) {
1510 if ($line->product_ref) {
1511 $tooltiptext .= '<b>'.$langs->trans("Ref
").'</b> : '.$line->product_ref.'<br>';
1512 $tooltiptext .= '<b>'.$langs->trans("Label
").'</b> : '.$line->product_label.'<br>';
1513 if ($line->product_label != $line->desc) {
1515 $tooltiptext .= '<br>';
1517 $tooltiptext .= $line->desc;
1520 if ($conf->global->TAKEPOS_SHOW_PRODUCT_REFERENCE == 1) {
1521 $htmlforlines .= $form->textwithpicto($line->product_label ? '<b>' . $line->product_ref . '</b> - ' . $line->product_label : dolGetFirstLineOfText($line->desc, 1), $tooltiptext);
1523 $htmlforlines .= $form->textwithpicto($line->product_label ? $line->product_label : ($line->product_ref ? $line->product_ref : dolGetFirstLineOfText($line->desc, 1)), $tooltiptext);
1526 if ($line->product_label) {
1527 $htmlforlines .= $line->product_label;
1529 if ($line->product_label != $line->desc) {
1530 if ($line->product_label && $line->desc) {
1531 $htmlforlines .= '<br>';
1533 $firstline = dolGetFirstLineOfText($line->desc, $conf->global->TAKEPOS_SHOW_N_FIRST_LINES);
1534 if ($firstline != $line->desc) {
1535 $htmlforlines .= $form->textwithpicto(dolGetFirstLineOfText($line->desc), $line->desc);
1537 $htmlforlines .= $line->desc;
1541 if (!empty($line->array_options['options_order_notes'])) {
1542 $htmlforlines .= "<br>(
".$line->array_options['options_order_notes'].")
";
1544 if (!empty($_SESSION["basiclayout
"]) && $_SESSION["basiclayout
"] == 1) {
1545 $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>';
1547 if (empty($_SESSION["basiclayout
"]) || $_SESSION["basiclayout
"] != 1) {
1549 $moreinfo .= $langs->transcountry("TotalHT
", $mysoc->country_code).': '.price($line->total_ht);
1550 if ($line->vat_src_code) {
1551 $moreinfo .= '<br>'.$langs->trans("VATCode
").': '.$line->vat_src_code;
1553 $moreinfo .= '<br>'.$langs->transcountry("TotalVAT
", $mysoc->country_code).': '.price($line->total_tva);
1554 $moreinfo .= '<br>'.$langs->transcountry("TotalLT1
", $mysoc->country_code).': '.price($line->total_localtax1);
1555 $moreinfo .= '<br>'.$langs->transcountry("TotalLT2
", $mysoc->country_code).': '.price($line->total_localtax2);
1556 $moreinfo .= '<br>'.$langs->transcountry("TotalTTC
", $mysoc->country_code).': '.price($line->total_ttc);
1557 //$moreinfo .= $langs->trans("TotalHT
").': '.$line->total_ht;
1558 if ($line->date_start || $line->date_end) {
1559 $htmlforlines .= '<br><div class="clearboth nowraponall
">'.get_date_range($line->date_start, $line->date_end).'</div>';
1561 $htmlforlines .= '</td>';
1563 // complete line by hook
1564 $parameters=array('line' => $line);
1565 $reshook=$hookmanager->executeHooks('completeTakePosInvoiceLine', $parameters, $invoice, $action); // Note that $action and $object may have been modified by some hooks
1566 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1567 $htmlforlines .= $hookmanager->resPrint;
1569 $htmlforlines .= '<td class="right
">'.vatrate($line->remise_percent, true).'</td>';
1570 $htmlforlines .= '<td class="right
">';
1571 if (isModEnabled('stock') && !empty($user->rights->stock->mouvement->lire)) {
1572 $constantforkey = 'CASHDESK_ID_WAREHOUSE'.$_SESSION["takeposterminal
"];
1573 if (!empty($conf->global->$constantforkey) && $line->fk_product > 0 && empty($conf->global->TAKEPOS_HIDE_STOCK_ON_LINE)) {
1574 $sql = "SELECT e.rowid, e.ref, e.lieu, e.fk_parent, e.statut, ps.reel, ps.rowid as product_stock_id, p.pmp
";
1575 $sql .= " FROM
".MAIN_DB_PREFIX."entrepot as e,
";
1576 $sql .= " ".MAIN_DB_PREFIX."product_stock as ps
";
1577 $sql .= " LEFT JOIN
".MAIN_DB_PREFIX."product as p ON p.rowid = ps.fk_product
";
1578 $sql .= " WHERE ps.reel != 0
";
1579 $sql .= " AND ps.fk_entrepot =
".((int) $conf->global->$constantforkey);
1580 $sql .= " AND e.entity IN (
".getEntity('stock').")
";
1581 $sql .= " AND ps.fk_product =
".((int) $line->fk_product);
1582 $resql = $db->query($sql);
1584 $obj = $db->fetch_object($resql);
1585 $stock_real = price2num($obj->reel, 'MS');
1586 $htmlforlines .= $line->qty;
1587 if ($line->qty && $line->qty > $stock_real) {
1588 $htmlforlines .= '<span style="color: var(--amountremaintopaycolor)
">';
1590 $htmlforlines .= ' <span class="posstocktoolow
">('.$langs->trans("Stock
").' '.$stock_real.')</span>';
1591 if ($line->qty && $line->qty > $stock_real) {
1592 $htmlforlines .= "</span>
";
1595 dol_print_error($db);
1598 $htmlforlines .= $line->qty;
1601 $htmlforlines .= $line->qty;
1604 $htmlforlines .= '</td>';
1605 if (getDolGlobalString('TAKEPOS_SHOW_HT')) {
1606 $htmlforlines .= '<td class="right classfortooltip
" title="'.$moreinfo.'">';
1607 $htmlforlines .= price($line->total_ht, 1, '', 1, -1, -1, $conf->currency);
1608 if (isModEnabled('multicurrency') && !empty($_SESSION["takeposcustomercurrency
"]) && $conf->currency != $_SESSION["takeposcustomercurrency
"]) {
1609 //Only show customer currency if multicurrency module is enabled, if currency selected and if this currency selected is not the same as main currency
1610 include_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php';
1611 $multicurrency = new MultiCurrency($db);
1612 $multicurrency->fetch(0, $_SESSION["takeposcustomercurrency
"]);
1613 $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>';
1615 $htmlforlines .= '</td>';
1617 $htmlforlines .= '<td class="right classfortooltip
" title="'.$moreinfo.'">';
1618 $htmlforlines .= price($line->total_ttc, 1, '', 1, -1, -1, $conf->currency);
1619 if (isModEnabled('multicurrency') && !empty($_SESSION["takeposcustomercurrency
"]) && $conf->currency != $_SESSION["takeposcustomercurrency
"]) {
1620 //Only show customer currency if multicurrency module is enabled, if currency selected and if this currency selected is not the same as main currency
1621 include_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php';
1622 $multicurrency = new MultiCurrency($db);
1623 $multicurrency->fetch(0, $_SESSION["takeposcustomercurrency
"]);
1624 $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>';
1626 $htmlforlines .= '</td>';
1628 $htmlforlines .= '</tr>'."\n
";
1629 $htmlforlines .= empty($htmlsupplements[$line->id]) ? '' : $htmlsupplements[$line->id];
1631 print $htmlforlines;
1634 print '<tr class="drag drop oddeven
"><td class="left
"><span class="opacitymedium
">'.$langs->trans("Empty
").'</span></td><td></td><td></td><td></td>';
1635 if (!empty($conf->global->TAKEPOS_SHOW_HT)) {
1640 } else { // No invoice generated yet
1641 print '<tr class="drag drop oddeven
"><td class="left
"><span class="opacitymedium
">'.$langs->trans("Empty
").'</span></td><td></td><td></td><td></td>';
1643 if (!empty($conf->global->TAKEPOS_SHOW_HT)) {
1651 if (($action == "valid
" || $action == "history
") && $invoice->type != Facture::TYPE_CREDIT_NOTE) {
1652 print '<button id="buttonprint
" type="button
" onclick="ModalBox(\
'ModalCreditNote\')">'.$langs->trans(
'CreateCreditNote').
'</button>';
1656 if ($action ==
"search") {
1658 <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')).
'">