34if (!defined(
'NOTOKENRENEWAL')) {
35 define(
'NOTOKENRENEWAL',
'1');
37if (!defined(
'NOREQUIREMENU')) {
38 define(
'NOREQUIREMENU',
'1');
40if (!defined(
'NOREQUIREHTML')) {
41 define(
'NOREQUIREHTML',
'1');
43if (!defined(
'NOREQUIREAJAX')) {
44 define(
'NOREQUIREAJAX',
'1');
48if (!defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
49 require
'../main.inc.php';
51require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
52require_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
53require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
54require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
55require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
65$hookmanager->initHooks(array(
'takeposinvoice'));
67$langs->loadLangs(array(
"companies",
"commercial",
"bills",
"cashdesk",
"stocks",
"banks"));
69$action =
GETPOST(
'action',
'aZ09');
73$mobilepage =
GETPOST(
'mobilepage',
'alpha');
74$batch =
GETPOST(
'batch',
'alpha');
75$sourceinvoiceid =
GETPOSTINT(
'sourceinvoiceid');
79if (!$user->hasRight(
'takepos',
'run') && !defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
83if (defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
85 if ($_SESSION[
"takeposterminal"] ==
"") {
87 $_SESSION[
"takeposterminal"] = 1;
89 header(
"Location: ".DOL_URL_ROOT.
"/takepos/index.php");
96$takeposterminal = isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'';
99if (empty($takeposterminal)) {
101 $_SESSION[
"takeposterminal"] = 1;
102 $takeposterminal = 1;
103 } elseif (!empty($_COOKIE[
"takeposterminal"])) {
104 $_SESSION[
"takeposterminal"] = preg_replace(
'/[^a-zA-Z0-9_\-]/',
'', $_COOKIE[
"takeposterminal"]);
105 $takeposterminal = $_SESSION[
"takeposterminal"];
108<script
type=
"text/javascript">
110 ModalBox(
'ModalTerminal');
127 header($_SERVER[
'SERVER_PROTOCOL'].
' 500 Internal Server Error',
true, 500);
138function takeposDeleteLineWithChildren($invoice, $lineid)
140 $lineid = (int) $lineid;
145 $childrenbyparent = array();
146 if (is_array($invoice->lines)) {
147 foreach ($invoice->lines as $line) {
148 $parentid = (int) $line->fk_parent_line;
150 $childrenbyparent[$parentid][] = (int) $line->id;
155 $linestodelete = array();
156 $stack = array($lineid);
157 while (!empty($stack)) {
158 $currentlineid = array_pop($stack);
159 if (in_array($currentlineid, $linestodelete,
true)) {
163 $linestodelete[] = $currentlineid;
164 if (!empty($childrenbyparent[$currentlineid])) {
165 foreach ($childrenbyparent[$currentlineid] as $childlineid) {
166 $stack[] = $childlineid;
172 foreach (array_reverse($linestodelete) as $deletelineid) {
174 $sql_discount =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"societe_remise_except WHERE fk_facture_line = ".((int) $deletelineid);
175 $resql_discount = $invoice->db->query($sql_discount);
176 if ($resql_discount && $invoice->db->num_rows($resql_discount) > 0) {
177 $obj_discount = $invoice->db->fetch_object($resql_discount);
178 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
180 if ($discount_to_unlink->fetch($obj_discount->rowid) > 0) {
181 $discount_to_unlink->unlink_invoice();
185 $result = $invoice->deleteLine($deletelineid);
199$desc =
GETPOST(
'desc',
'alphanohtml');
212if ($pay ==
'cheque') {
219 $sql =
"SELECT id, code FROM ".MAIN_DB_PREFIX.
"c_paiement";
220 $sql .=
" WHERE entity IN (".getEntity(
'c_paiement').
")";
221 $sql .=
" AND code = '".$db->escape($paycode).
"'";
222 $resql = $db->query($sql);
224 $obj = $db->fetch_object($resql);
226 $paiementid = $obj->id;
233 $ret = $invoice->fetch($invoiceid);
235 $ret = $invoice->fetch(0,
'(PROV-POS'.$takeposterminal.
'-'.$place.
')');
238 $placeid = $invoice->id;
241$constforcompanyid =
'CASHDESK_ID_THIRDPARTY'.$takeposterminal;
244if ($invoice->socid > 0) {
245 $soc->fetch($invoice->socid);
252 $invoice->fk_project =
getDolGlobalInt(
"CASHDESK_ID_PROJECT".$takeposterminal);
256if (
isModEnabled(
'multicurrency') && !empty($_SESSION[
"takeposcustomercurrency"])) {
257 if ($invoice->multicurrency_code != $_SESSION[
"takeposcustomercurrency"]) {
258 $invoice->setMulticurrencyCode($_SESSION[
"takeposcustomercurrency"]);
262$term = empty($_SESSION[
"takeposterminal"]) ? 1 : $_SESSION[
"takeposterminal"];
269$parameters = array();
270$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $invoice, $action);
272 setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
276$sectionwithinvoicelink =
'';
277$CUSTOMER_DISPLAY_line1 =
'';
278$CUSTOMER_DISPLAY_line2 =
'';
288if (in_array($action, array(
'deleteline',
'updateqty',
'updateprice',
'updatereduction',
'update_reduction_global')) && !$user->hasRight(
'takepos',
'editlines')) {
294if (empty($reshook)) {
295 if ($action ==
'cloneticket' && $user->hasRight(
'takepos',
'run')) {
299 $sourceinvoice =
new Facture($db);
300 $result = $sourceinvoice->fetch($sourceinvoiceid);
301 $targetentity = !empty($_SESSION[
'takeposinvoiceentity']) ? (int) $_SESSION[
'takeposinvoiceentity'] : (int)
$conf->entity;
304 $langs->load(
'errors');
305 $clonemessage = $langs->trans(
'ErrorBadValueForParameter',
'sourceinvoiceid');
306 setEventMessages($clonemessage,
null,
'errors');
308 $cloneinvoice =
dol_clone($sourceinvoice, 1);
309 '@phan-var-force Facture $cloneinvoice';
310 $cloneinvoice->date =
dol_now();
311 $cloneid = $cloneinvoice->createFromClone($user, $sourceinvoiceid, $targetentity);
315 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"facture WHERE ref = '(PROV-POS".$db->escape((
string) $takeposterminal).
"-0)' AND entity IN (".
getEntity(
'invoice').
")";
316 $resql = $db->query($sql);
317 if ($resql && $db->num_rows($resql) > 0) {
319 $sql =
"SELECT ref FROM ".MAIN_DB_PREFIX.
"facture WHERE entity IN (".
getEntity(
'invoice').
") AND ref LIKE '(PROV-POS".$db->escape((
string) $takeposterminal).
"-0-%'";
320 $resql2 = $db->query($sql);
322 while ($obj = $db->fetch_object($resql2)) {
323 $num_sale = str_replace(
")",
"", str_replace(
"(PROV-POS".$takeposterminal.
"-0-",
"", $obj->ref));
324 if ((
int) $num_sale > $max_sale) {
325 $max_sale = (int) $num_sale;
329 $cloneplace =
'0-'.($max_sale + 1);
332 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facture";
333 $sql .=
" SET module_source = 'takepos', pos_source = '".$db->escape((
string) $takeposterminal).
"',";
334 $sql .=
" ref = '".$db->escape(
"(PROV-POS".((
string) $takeposterminal).
"-".$cloneplace.
")").
"'";
335 $sql .=
" WHERE rowid = ".((int) $cloneid);
336 $result = $db->query($sql);
339 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facturedet";
340 $sql .=
" SET batch = NULL, fk_warehouse = NULL";
341 $sql .=
" WHERE fk_facture = ".((int) $cloneid);
342 $sql .=
" AND fk_product IN (SELECT rowid FROM ".MAIN_DB_PREFIX.
"product WHERE tobatch > 0)";
343 $result = $db->query($sql);
347 if ($cloneid > 0 && $result) {
348 $place = $cloneplace;
351 $invoice->fetch($cloneid);
355 $cloneinvoice->fetch($cloneid);
356 $cloneinvoice->delete($user);
359 $langs->load(
'errors');
360 $clonemessage = !empty($cloneinvoice->error) ? $cloneinvoice->error : $langs->trans(
'ErrorFailedToCloneTicket');
361 setEventMessages($clonemessage, $cloneinvoice->errors,
'errors');
365 if (
GETPOST(
'format',
'aZ09') ==
'json') {
369 $sql =
'SELECT fd.rowid, fd.fk_product';
370 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facturedet AS fd, '.MAIN_DB_PREFIX.
'product AS p';
371 $sql .=
' WHERE fd.fk_product = p.rowid';
372 $sql .=
' AND fd.fk_facture = '.((int) $cloneid);
373 $sql .=
" AND (fd.batch IS NULL OR fd.batch = '') AND p.tobatch > 0";
374 $sql .=
' ORDER BY fd.rang, fd.rowid';
375 $sql .= $db->plimit(1);
376 $resql = $db->query($sql);
377 if ($resql && ($obj = $db->fetch_object($resql))) {
378 $batchlineid = (int) $obj->rowid;
379 $batchproductid = (int) $obj->fk_product;
384 echo json_encode(array(
'success' => $cloneid > 0,
'invoiceid' => $cloneid,
'place' => $cloneplace,
'batchlineid' => $batchlineid,
'batchproductid' => $batchproductid,
'message' => $clonemessage));
392 $sql =
"SELECT MIN(ref) as firstref FROM ".MAIN_DB_PREFIX.
"pos_cash_fence";
393 $sql .=
" WHERE entity = ".((int)
$conf->entity);
394 $sql .=
" AND posnumber = ".((int) $takeposterminal);
395 $sql .=
" AND year_close = ".((int) $tmpcurrentday[
'year']);
397 $sql .=
" (month_close IS NULL AND day_close IS NULL)";
398 $sql .=
" OR (month_close = ".((int) $tmpcurrentday[
'mon']).
" AND day_close IS NULL)";
399 $sql .=
" OR (month_close = ".((int) $tmpcurrentday[
'mon']).
" AND day_close = ".((int) $tmpcurrentday[
'mday']).
")";
401 $sql .=
" AND status = 1";
404 $resql = $db->query($sql);
406 $obj = $db->fetch_object($resql);
408 $refcashcontrol = $obj->firstref;
412 if ($refcashcontrol) {
414 $langs->load(
'errors');
415 dol_htmloutput_errors($langs->trans(
"ACashControlHasBeenclosedForCurrentDay", $refcashcontrol), [], 1);
420 if ($action ==
'valid' && $user->hasRight(
'takepos',
'run')) {
428 $bankaccount =
getDolGlobalInt(
'CASHDESK_ID_BANKACCOUNT_CASH'.$_SESSION[
"takeposterminal"]);
429 } elseif ($pay ==
"CHQ") {
430 $bankaccount =
getDolGlobalInt(
'CASHDESK_ID_BANKACCOUNT_CHEQUE'.$_SESSION[
"takeposterminal"]);
432 $accountname =
"CASHDESK_ID_BANKACCOUNT_".$pay.$_SESSION[
"takeposterminal"];
437 if ($bankaccount <= 0 && $pay !=
"delayed" &&
isModEnabled(
"bank")) {
438 $errormsg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"BankAccount"));
446 $invoice->fetch($placeid);
448 $invoice->oldcopy =
dol_clone($invoice, 2);
452 if ($invoice->total_ttc < 0) {
453 $invoice->type = $invoice::TYPE_CREDIT_NOTE;
455 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"facture";
456 $sql .=
" WHERE entity IN (".getEntity(
'invoice').
")";
457 $sql .=
" AND fk_soc = ".((int) $invoice->socid);
458 $sql .=
" AND type <> ".Facture::TYPE_CREDIT_NOTE;
459 $sql .=
" AND fk_statut >= ".$invoice::STATUS_VALIDATED;
460 $sql .=
" ORDER BY rowid DESC";
463 $resql = $db->query($sql);
465 $obj = $db->fetch_object($resql);
466 $fk_source = $obj->rowid;
467 if ((
int) $fk_source == 0) {
468 fail($langs->transnoentitiesnoconv(
"NoPreviousBillForCustomer"));
471 fail($langs->transnoentitiesnoconv(
"NoPreviousBillForCustomer"));
473 $invoice->fk_facture_source = $fk_source;
474 $invoice->update($user);
477 $constantforkey =
'CASHDESK_NO_DECREASE_STOCK'.(isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
484 $remaintopay = $invoice->getRemainToPay();
491 } elseif (count($invoice->lines) == 0) {
500 $conf->global->STOCK_CALCULATE_ON_BILL = 1;
502 $constantforkey =
'CASHDESK_ID_WAREHOUSE'.(isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
503 dol_syslog(
"Validate invoice with stock change. Warehouse defined into constant ".$constantforkey.
" = ".
getDolGlobalString($constantforkey));
508 $res = $invoice->validate($user,
'',
getDolGlobalInt($constantforkey), 0, $batch_rule);
511 $conf->global->STOCK_CALCULATE_ON_BILL = $savconst;
514 dol_syslog(
"Call validate on invoice ".$invoice->ref, LOG_DEBUG);
515 $res = $invoice->validate($user);
518 $langs->load(
"admin");
519 dol_htmloutput_errors($invoice->error ==
'NotConfigured' ? $langs->trans(
"NotConfigured").
' (TakePos numbering module)' : $invoice->error, $invoice->errors, 1);
524 if (!$error && $res >= 0) {
525 $remaintopay = $invoice->getRemainToPay();
530 $payment->datepaye = $now;
531 $payment->fk_account = $bankaccount;
536 $payment->amounts[$invoice->id] = $amountofpayment;
539 if ($amountofpayment <= 0 || $amountofpayment > $remaintopay) {
540 $payment->amounts[$invoice->id] = $remaintopay;
544 $payment->paiementid = $paiementid;
545 $payment->paiementcode = $paycode;
546 $payment->num_payment =
'';
548 if ($pay !=
"delayed") {
549 $res = $payment->create($user);
556 if (!empty($payment->warnings)) {
560 $res = $payment->addPaymentToBank($user,
'payment',
'(CustomerInvoicePayment)', $bankaccount,
'',
'');
563 dol_htmloutput_mesg($langs->trans(
'ErrorNoPaymentDefined').
' '.$payment->error, $payment->errors,
'error', 1);
566 $remaintopay = $invoice->getRemainToPay();
572 if ($remaintopay == 0) {
573 dol_syslog(
"Invoice is paid, so we set it to status Paid");
574 $result = $invoice->setPaid($user);
577 $invoice->status = $invoice::STATUS_CLOSED;
578 $invoice->close_code =
'';
581 $invoice->setPaymentMethods($paiementid);
583 dol_syslog(
"Invoice is not paid, remain to pay = ".$remaintopay);
592 if (!$error && $res >= 0) {
595 dol_syslog(
"Now we record the stock movement for each qualified line");
598 require_once DOL_DOCUMENT_ROOT .
"/product/stock/class/mouvementstock.class.php";
599 $constantforkey =
'CASHDESK_ID_WAREHOUSE'.$_SESSION[
"takeposterminal"];
602 $labeltakeposmovement =
'TakePOS - '.$langs->transnoentitiesnoconv(
"Invoice").
' '.$invoice->ref;
604 foreach ($invoice->lines as $line) {
606 $warehouseid = ($line->fk_warehouse ? $line->fk_warehouse :
getDolGlobalInt($constantforkey));
609 if ($line->batch !=
'' && $warehouseid > 0) {
611 $prod_batch->find(0,
'',
'', $line->batch, $warehouseid, (
int) $line->fk_product);
614 $mouvP->setOrigin($invoice->element, $invoice->id);
617 $res = $mouvP->reception($user, $line->fk_product, $warehouseid, $line->qty, $line->price, $labeltakeposmovement,
'',
'', $line->batch,
'', 0, $inventorycode);
619 $res = $mouvP->livraison($user, $line->fk_product, $warehouseid, $line->qty, $line->price, $labeltakeposmovement,
'',
'',
'', $prod_batch->batch, $prod_batch->id, $inventorycode);
628 $mouvP->setOrigin($invoice->element, $invoice->id);
631 $res = $mouvP->reception($user, $line->fk_product, $warehouseid, $line->qty, $line->price, $labeltakeposmovement,
'',
'',
'',
'', 0, $inventorycode);
633 $res = $mouvP->livraison($user, $line->fk_product, $warehouseid, $line->qty, $line->price, $labeltakeposmovement,
'',
'',
'',
'', 0, $inventorycode);
645 if (!$error && $res >= 0) {
648 $invoice->ref = $invoice->oldcopy->ref;
649 $invoice->paye = $invoice->oldcopy->paye;
650 $invoice->status = $invoice->oldcopy->status;
651 $invoice->statut = $invoice->oldcopy->statut;
658 if ($action ==
'creditnote' && $user->hasRight(
'takepos',
'run')) {
661 $creditnote =
new Facture($db);
662 $creditnote->socid = $invoice->socid;
664 $creditnote->module_source =
'takepos';
665 $creditnote->pos_source = isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'' ;
667 $creditnote->fk_facture_source = $placeid;
669 $creditnote->create($user);
673 foreach ($invoice->lines as $line) {
675 if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) {
680 if (!empty($invoice->situation_counter)) {
681 $source_fk_prev_id = $line->fk_prev_id;
682 $line->fk_prev_id = $line->id;
683 if (!empty($invoice->tab_previous_situation_invoice)) {
686 $tab_jumped_credit_notes = array();
687 $lineIndex = count($invoice->tab_previous_situation_invoice) - 1;
688 $searchPreviousInvoice =
true;
689 while ($searchPreviousInvoice) {
690 if ($invoice->tab_previous_situation_invoice[$lineIndex]->situation_cycle_ref || $lineIndex < 1) {
691 $searchPreviousInvoice =
false;
695 $tab_jumped_credit_notes[$lineIndex] = $invoice->tab_previous_situation_invoice[$lineIndex]->id;
701 $maxPrevSituationPercent = 0;
702 foreach ($invoice->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine) {
703 if ($prevLine->id == $source_fk_prev_id) {
704 $maxPrevSituationPercent = max($maxPrevSituationPercent, $prevLine->situation_percent);
707 $line->total_ht -= $prevLine->total_ht;
708 $line->total_tva -= $prevLine->total_tva;
709 $line->total_ttc -= $prevLine->total_ttc;
710 $line->total_localtax1 -= $prevLine->total_localtax1;
711 $line->total_localtax2 -= $prevLine->total_localtax2;
713 $line->multicurrency_subprice -= $prevLine->multicurrency_subprice;
714 $line->multicurrency_total_ht -= $prevLine->multicurrency_total_ht;
715 $line->multicurrency_total_tva -= $prevLine->multicurrency_total_tva;
716 $line->multicurrency_total_ttc -= $prevLine->multicurrency_total_ttc;
721 $line->situation_percent = $maxPrevSituationPercent - $line->situation_percent;
726 $maxPrevSituationPercent = 0;
727 foreach ($tab_jumped_credit_notes as $index => $creditnoteid) {
728 foreach ($invoice->tab_previous_situation_invoice[$index]->lines as $prevLine) {
729 if ($prevLine->fk_prev_id == $source_fk_prev_id) {
730 $maxPrevSituationPercent = $prevLine->situation_percent;
732 $line->total_ht -= $prevLine->total_ht;
733 $line->total_tva -= $prevLine->total_tva;
734 $line->total_ttc -= $prevLine->total_ttc;
735 $line->total_localtax1 -= $prevLine->total_localtax1;
736 $line->total_localtax2 -= $prevLine->total_localtax2;
738 $line->multicurrency_subprice -= $prevLine->multicurrency_subprice;
739 $line->multicurrency_total_ht -= $prevLine->multicurrency_total_ht;
740 $line->multicurrency_total_tva -= $prevLine->multicurrency_total_tva;
741 $line->multicurrency_total_ttc -= $prevLine->multicurrency_total_ttc;
747 $line->situation_percent += $maxPrevSituationPercent;
755 $line->fk_facture = $creditnote->id;
756 $line->fk_parent_line = $fk_parent_line;
758 $line->subprice = -$line->subprice;
760 $line->total_ht = -$line->total_ht;
761 $line->total_tva = -$line->total_tva;
762 $line->total_ttc = -$line->total_ttc;
763 $line->total_localtax1 = -$line->total_localtax1;
764 $line->total_localtax2 = -$line->total_localtax2;
766 $line->multicurrency_subprice = -$line->multicurrency_subprice;
767 $line->multicurrency_total_ht = -$line->multicurrency_total_ht;
768 $line->multicurrency_total_tva = -$line->multicurrency_total_tva;
769 $line->multicurrency_total_ttc = -$line->multicurrency_total_ttc;
771 $result = $line->insert(0, 1);
773 $creditnote->lines[] = $line;
776 if ($result > 0 && $line->product_type == 9) {
777 $fk_parent_line = $result;
780 $creditnote->update_price(1);
788 $constantforkey =
'CASHDESK_NO_DECREASE_STOCK'.(isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
793 $conf->global->STOCK_CALCULATE_ON_BILL = 1;
795 $constantforkey =
'CASHDESK_ID_WAREHOUSE'.(isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
798 dol_syslog(
"Validate invoice with stock change into warehouse defined into constant ".$constantforkey.
" = ".
getDolGlobalString($constantforkey).
" or warehouseid= ".$warehouseid.
" if defined.");
801 $res = $creditnote->validate($user,
'', $warehouseid, 0, $batch_rule);
808 $conf->global->STOCK_CALCULATE_ON_BILL = $savconst;
810 $res = $creditnote->validate($user);
814 if (!$error && $res >= 0) {
816 dol_syslog(
"Now we record the stock movement for each qualified line");
818 require_once DOL_DOCUMENT_ROOT .
"/product/stock/class/mouvementstock.class.php";
819 $constantforkey =
'CASHDESK_ID_WAREHOUSE'.(isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
821 $labeltakeposmovement =
'TakePOS - '.$langs->transnoentitiesnoconv(
"CreditNote").
' '.$creditnote->ref;
823 foreach ($creditnote->lines as $line) {
825 $warehouseid = ($line->fk_warehouse ? $line->fk_warehouse :
getDolGlobalInt($constantforkey));
828 $mouvP->setOrigin($creditnote->element, $creditnote->id);
830 $batch_to_use = ($line->batch !=
'' && $warehouseid > 0) ? $line->batch :
'';
832 $res = $mouvP->reception($user, $line->fk_product, $warehouseid, $line->qty, $line->price, $labeltakeposmovement,
'',
'', $batch_to_use,
'', 0, $inventorycode);
845 $creditnote->id = $placeid;
850 if (($action ==
'history' || $action ==
'creditnote') && $user->hasRight(
'takepos',
'run')) {
851 if ($action ==
'creditnote' && $creditnote !==
null && $creditnote->id > 0) {
852 $placeid = $creditnote->id;
858 $invoice->fetch($placeid);
862 if (($action ==
"addline" || $action ==
"freezone") && $placeid == 0 && ($user->hasRight(
'takepos',
'run') || defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
865 $dolnowtzuserrel =
dol_now(
'tzuserrel');
869 $dateinvoice =
dol_mktime(0, 0, 0, (
int) $monthuser, (
int) $dayuser, (
int) $yearuser,
'tzserver');
871 include_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
872 $invoice->date = $dateinvoice;
886 $invoice->module_source =
'takepos';
887 $invoice->pos_source = isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'' ;
888 $invoice->entity = !empty($_SESSION[
"takeposinvoiceentity"]) ? $_SESSION[
"takeposinvoiceentity"] :
$conf->entity;
890 if ($invoice->socid <= 0) {
891 $langs->load(
'errors');
897 $placeid = $invoice->create($user);
903 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facture";
904 $sql .=
" SET ref='(PROV-POS".$_SESSION[
"takeposterminal"].
"-".$place.
")'";
905 $sql .=
" WHERE rowid = ".((int) $placeid);
906 $resql = $db->query($sql);
922 if ($action ==
"addline" && ($user->hasRight(
'takepos',
'run') || defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
924 $prod->fetch($idproduct);
927 $customer->fetch($invoice->socid);
929 $datapriceofproduct = $prod->getSellPrice(
$mysoc, $customer, 0);
932 $price = $datapriceofproduct[
'pu_ht'];
933 $price_ttc = $datapriceofproduct[
'pu_ttc'];
935 $price_base_type = empty($datapriceofproduct[
'price_base_type']) ?
'HT' : $datapriceofproduct[
'price_base_type'];
936 $tva_tx = $datapriceofproduct[
'tva_tx'];
937 $tva_npr = (int) $datapriceofproduct[
'tva_npr'];
945 $batch =
GETPOST(
'batch',
'alpha');
947 if (!empty($batch)) {
948 $action =
"setbatch";
949 } elseif ($prod->status_batch > 0) {
954 $prod->load_stock(
'warehouseopen');
956 $constantforkey =
'CASHDESK_ID_WAREHOUSE'.$_SESSION[
"takeposterminal"];
960 foreach ($prod->stock_warehouse as $tmpwarehouseid => $tmpval) {
965 if (!empty($prod->stock_warehouse[$tmpwarehouseid]) && is_array($prod->stock_warehouse[$tmpwarehouseid]->detail_batch)) {
966 if (is_object($prod->stock_warehouse[$tmpwarehouseid]) && count($prod->stock_warehouse[$tmpwarehouseid]->detail_batch)) {
967 foreach ($prod->stock_warehouse[$tmpwarehouseid]->detail_batch as $dbatch) {
976 echo
"function addbatch(batch, warehouseid) {\n";
977 echo
"console.log('We add batch '+batch+' from warehouse id '+warehouseid);\n";
978 echo
'$("#poslines").load("'.DOL_URL_ROOT.
'/takepos/invoice.php?action=addline&batch="+encodeURIComponent(batch)+"&warehouseid="+warehouseid+"&place='.$place.
'&idproduct='.$idproduct.
'&token='.
newToken().
'", function() {});'.
"\n";
983 echo
"<center>".$langs->trans(
"SearchIntoBatch").
": <b> $nbofsuggested </b></center><br><table>";
984 foreach ($prod->stock_warehouse as $tmpwarehouseid => $tmpval) {
989 if (!empty($prod->stock_warehouse[$tmpwarehouseid]) && is_array($prod->stock_warehouse[$tmpwarehouseid]->detail_batch)) {
990 foreach ($prod->stock_warehouse[$tmpwarehouseid]->detail_batch as $dbatch) {
991 $batchStock = + $dbatch->qty;
992 $quantityToBeDelivered = 1;
993 $deliverableQty = min($quantityToBeDelivered, $batchStock);
995 print
'<!-- subj='.$suggestednb.
'/'.$nbofsuggested.
' -->';
996 print
'<!-- Show details of lot/serial in warehouseid='.$tmpwarehouseid.
' -->';
997 print
'<td class="left">';
999 $detail .=
'<span class="opacitymedium">'.$langs->trans(
"LotSerial").
':</span> '.$dbatch->batch;
1006 $detail .=
'</td><td>';
1007 $detail .=
'<span class="opacitymedium">'.$langs->trans(
"Qty").
':</span> '.$dbatch->qty;
1008 $detail .=
'</td><td>';
1009 $detail .=
' <button class="marginleftonly" onclick="addbatch(\''.dol_escape_js($dbatch->batch).
'\',
'.$tmpwarehouseid.')
">'.$langs->trans("Select
")."</
button>
";
1013 $quantityToBeDelivered -= $deliverableQty;
1014 if ($quantityToBeDelivered < 0) {
1015 $quantityToBeDelivered = 0;
1023 if ($nbofsuggested == 0) {
1024 // Add manual entry for returns or new batches when stock is 0
1025 print '<tr><td class="left
" style="padding-top: 10px; border-top: 1px solid #ddd; text-align: center;
">';
1026 print '<span class="opacitymedium
">'.$langs->trans("LotSerial
").' (Manual) :</span> ';
1027 print '<input type="text
" id="manual_batch_add
" class="flat
" size="10
"> ';
1028 print '<button class="button" onclick="addbatch(document.getElementById(\
'manual_batch_add\').value, '.$warehouseid.
')">'.$langs->trans(
"Add").
'</button>';
1034 print
'</body></html>';
1041 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1043 $categories = $cat->containing($idproduct,
'product');
1044 $found = (array_search(
getDolGlobalInt(
'TAKEPOS_SUPPLEMENTS_CATEGORY'), array_column($categories,
'id')));
1045 if ($found !==
false) {
1046 $sql =
"SELECT fk_parent_line FROM ".MAIN_DB_PREFIX.
"facturedet where rowid = ".((int) $selectedline);
1047 $resql = $db->query($sql);
1048 $row = $db->fetch_array($resql);
1049 if ($row[0] ==
null) {
1050 $parent_line = $selectedline;
1052 $parent_line = $row[0];
1059 if (
getDolGlobalString(
'TAKEPOS_GROUP_SAME_PRODUCT') && empty($prod->status_batch)) {
1060 foreach ($invoice->lines as $line) {
1061 if ($line->product_ref == $prod->ref) {
1062 if ($line->special_code == 4) {
1066 if (
getDolGlobalString(
'TAKEPOS_QTY_IN_STOCK') && (($line->qty + $qty) > $prod->stock_reel)) {
1067 $invoice->error = $langs->trans(
"ErrorStockIsNotEnough");
1072 $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);
1076 $idoflineadded = $line->id;
1082 if ($idoflineadded <= 0 && empty($err)) {
1083 $invoice->fetch_thirdparty();
1084 $array_options = array();
1086 $line = array(
'description' => $prod->description,
'price' => $price,
'tva_tx' => $tva_tx,
'localtax1_tx' => $localtax1_tx,
'localtax2_tx' => $localtax2_tx,
'remise_percent' => $customer->remise_percent,
'price_ttc' => $price_ttc,
'array_options' => $array_options);
1091 $line[
'fk_fournprice'] =
null;
1092 $line[
'pa_ht'] = $prod->pmp;
1093 } elseif (
getDolGlobalString(
'MARGIN_TYPE') ==
'costprice' && !empty($prod->cost_price)) {
1094 $line[
'fk_fournprice'] =
null;
1095 $line[
'pa_ht'] = $prod->cost_price;
1098 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
1100 if ($pf->find_min_price_product_fournisseur($idproduct, $qty) > 0) {
1101 $line[
'fk_fournprice'] = $pf->product_fourn_price_id;
1102 $line[
'pa_ht'] = $pf->fourn_unitprice_with_discount;
1104 $line[
'pa_ht'] += (float) $pf->fourn_charges / $pf->fourn_qty;
1111 $parameters = array(
'prod' => $prod,
'line' => $line);
1112 $reshook = $hookmanager->executeHooks(
'completeTakePosAddLine', $parameters, $invoice, $action);
1114 setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
1118 if (empty($reshook)) {
1119 if (!empty($hookmanager->resArray)) {
1120 $line = $hookmanager->resArray;
1125 $invoice->error = $langs->trans(
"ErrorStockIsNotEnough");
1131 $idoflineadded = $invoice->addline($line[
'description'], $line[
'price'], $qty, $line[
'tva_tx'], $line[
'localtax1_tx'], $line[
'localtax2_tx'], $idproduct, (
float) $line[
'remise_percent'],
'', 0, 0, 0, 0, $price_base_type, $line[
'price_ttc'], $prod->type, -1, 0,
'', 0, (empty($parent_line) ?
'' : $parent_line), (empty($line[
'fk_fournprice']) ? 0 : $line[
'fk_fournprice']), (empty($line[
'pa_ht']) ?
'' : $line[
'pa_ht']),
'', $line[
'array_options'], 100, 0, $prod->fk_unit, 0);
1136 $CUSTOMER_DISPLAY_line1 = $prod->label;
1137 $CUSTOMER_DISPLAY_line2 =
price($price_ttc);
1141 $invoice->fetch($placeid);
1145 if ($action ==
"freezone" && $user->hasRight(
'takepos',
'run')) {
1147 $customer->fetch($invoice->socid);
1149 $tva_tx =
GETPOST(
'tva_tx',
'alpha');
1150 if ($tva_tx !=
'') {
1151 if (!preg_match(
'/\((.*)\)/', $tva_tx)) {
1162 $res = $invoice->addline($desc, $number, 1, $tva_tx, $localtax1_tx, $localtax2_tx, 0, 0,
'', 0, 0, 0, 0,
getDolGlobalInt(
'TAKEPOS_DISCOUNT_TTC') ? ($number >= 0 ?
'HT' :
'TTC') : (
getDolGlobalInt(
'TAKEPOS_CHANGE_PRICE_HT') ?
'HT' :
'TTC'), $number, 0, -1, 0,
'', 0, 0, 0, 0,
'', array(), 100, 0, null, 0);
1166 $invoice->fetch($placeid);
1169 if ($action ==
"addnote" && ($user->hasRight(
'takepos',
'run') || defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
1170 $desc =
GETPOST(
'addnote',
'alpha');
1172 $invoice->update_note($desc,
'_public');
1174 foreach ($invoice->lines as $line) {
1175 if ($line->id == $idline) {
1176 $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);
1180 $invoice->fetch($placeid);
1183 if ($action ==
"deleteline" && ($user->hasRight(
'takepos',
'editlines') || defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
1195 if ($idline > 0 && $placeid > 0) {
1196 $result = takeposDeleteLineWithChildren($invoice, $idline);
1200 $invoice->fetch($placeid);
1201 } elseif ($placeid > 0) {
1202 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"facturedet where fk_facture = ".((int) $placeid).
" ORDER BY rowid DESC";
1203 $resql = $db->query($sql);
1204 $obj = $db->fetch_object($resql);
1206 $deletelineid = $obj->rowid;
1207 $result = takeposDeleteLineWithChildren($invoice, $deletelineid);
1212 $invoice->fetch($placeid);
1217 if (count($invoice->lines) == 0) {
1222 $defaultsocid = (int)
getDolGlobalString(
'CASHDESK_ID_THIRDPARTY'.$_SESSION[
"takeposterminal"]);
1223 $invoicesocid = (int) $invoice->socid;
1224 if ($invoicesocid === 0 || $invoicesocid === $defaultsocid) {
1225 $invoice->delete($user);
1227 if (defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1228 header(
"Location: ".DOL_URL_ROOT.
"/takepos/public/auto_order.php");
1230 header(
"Location: ".DOL_URL_ROOT.
"/takepos/invoice.php");
1238 if ($action ==
"delete" && ($user->hasRight(
'takepos',
'run') || defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
1242 $result = $invoice->fetch($placeid);
1248 $resdeletelines = 1;
1249 foreach ($invoice->lines as $line) {
1251 $tmpres = $invoice->deleteLine($line->id);
1253 $resdeletelines = 0;
1258 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facture";
1259 $varforconst =
'CASHDESK_ID_THIRDPARTY'.$_SESSION[
"takeposterminal"];
1261 $sql .=
" datec = '".$db->idate(
dol_now()).
"'";
1262 $sql .=
" WHERE entity IN (".getEntity(
'invoice').
")";
1263 $sql .=
" AND ref = '(PROV-POS".$db->escape($_SESSION[
"takeposterminal"].
"-".$place).
")'";
1264 $resql1 = $db->query($sql);
1266 if ($resdeletelines && $resql1) {
1272 $invoice->fetch($placeid);
1279 if ($action ==
"discardsale" && ($user->hasRight(
'takepos',
'run') || defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
1281 $result = $invoice->fetch($placeid);
1283 $invoice->delete($user);
1289 if ($action ==
"updateqty") {
1290 foreach ($invoice->lines as $line) {
1291 if ($line->id == $idline) {
1292 $permissiontoupdateline = ($user->hasRight(
'takepos',
'editlines') && ($user->hasRight(
'takepos',
'editorderedlines') || $line->special_code !=
"4"));
1293 if (defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1294 if ($invoice->status == $invoice::STATUS_DRAFT && $invoice->pos_source && $invoice->module_source ==
'takepos') {
1295 $permissiontoupdateline =
true;
1300 if (!$permissiontoupdateline) {
1301 dol_htmloutput_errors($langs->trans(
"NotEnoughPermissions",
"TakePos").
' - No permission to updateqty', [], 1);
1304 $result = takeposDeleteLineWithChildren($invoice, $line->id);
1309 $vatratecode = $line->tva_tx;
1310 if ($line->vat_src_code) {
1311 $vatratecode .=
' ('.$line->vat_src_code.
')';
1314 $result = $invoice->updateline($line->id, $line->desc, $line->subprice, $number, $line->remise_percent, $line->date_start, $line->date_end, $vatratecode, $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);
1320 $invoice->fetch($placeid);
1323 if ($action ==
"updateprice") {
1325 $customer->fetch($invoice->socid);
1327 foreach ($invoice->lines as $line) {
1328 if ($line->id == $idline) {
1330 $prod->fetch($line->fk_product);
1331 $datapriceofproduct = $prod->getSellPrice(
$mysoc, $customer, 0);
1332 $price_min = $datapriceofproduct[
'price_min'];
1333 $usercanproductignorepricemin = ((
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !$user->hasRight(
'produit',
'ignore_price_min_advance')) || !
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS'));
1335 $vatratecleaned = $line->tva_tx;
1337 if (preg_match(
'/^(.*)\s*\((.*)\)$/', (
string) $line->tva_tx, $reg)) {
1338 $vatratecleaned = trim($reg[1]);
1342 $pu_ht =
price2num((
float)
price2num($number,
'MU') / (1 + ((
float) $vatratecleaned / 100)),
'MU');
1344 if ($usercanproductignorepricemin && (!empty($price_min) && ((
float)
price2num($pu_ht) * (1 - (
float)
price2num($line->remise_percent) / 100) <
price2num($price_min)))) {
1345 $langs->load(
"products");
1349 $permissiontoupdateline = ($user->hasRight(
'takepos',
'editlines') && ($user->hasRight(
'takepos',
'editorderedlines') || $line->special_code !=
"4"));
1350 if (defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1351 if ($invoice->status == $invoice::STATUS_DRAFT && $invoice->pos_source && $invoice->module_source ==
'takepos') {
1352 $permissiontoupdateline =
true;
1358 $vatratecode = $line->tva_tx;
1359 if ($line->vat_src_code) {
1360 $vatratecode .=
' ('.$line->vat_src_code.
')';
1363 if (!$permissiontoupdateline) {
1364 dol_htmloutput_errors($langs->trans(
"NotEnoughPermissions",
"TakePos").
' - No permission to updateprice', [], 1);
1366 $result = $invoice->updateline($line->id, $line->desc, $number, $line->qty, $line->remise_percent, $line->date_start, $line->date_end, $vatratecode, $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);
1368 $result = $invoice->updateline($line->id, $line->desc, $number, $line->qty, $line->remise_percent, $line->date_start, $line->date_end, $vatratecode, $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);
1375 $invoice->fetch($placeid);
1378 if ($action ==
"updatereduction") {
1380 $customer->fetch($invoice->socid);
1382 foreach ($invoice->lines as $line) {
1383 if ($line->id == $idline) {
1384 dol_syslog(
"updatereduction Process line ".$line->id.
' to apply discount of '.$number.
'%');
1387 $prod->fetch($line->fk_product);
1389 $datapriceofproduct = $prod->getSellPrice(
$mysoc, $customer, 0);
1390 $price_min = $datapriceofproduct[
'price_min'];
1391 $usercanproductignorepricemin = ((
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !$user->hasRight(
'produit',
'ignore_price_min_advance')) || !
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS'));
1393 $pu_ht =
price2num($line->subprice / (1 + ($line->tva_tx / 100)),
'MU');
1396 if ($usercanproductignorepricemin && (!empty($price_min) && ((
float)
price2num($line->subprice) * (1 - (
float)
price2num($number) / 100) < (
float)
price2num($price_min)))) {
1397 $langs->load(
"products");
1400 $permissiontoupdateline = ($user->hasRight(
'takepos',
'editlines') && ($user->hasRight(
'takepos',
'editorderedlines') || $line->special_code !=
"4"));
1401 if (defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1402 if ($invoice->status == $invoice::STATUS_DRAFT && $invoice->pos_source && $invoice->module_source ==
'takepos') {
1403 $permissiontoupdateline =
true;
1408 if (!$permissiontoupdateline) {
1411 $vatratecode = $line->tva_tx;
1412 if ($line->vat_src_code) {
1413 $vatratecode .=
' ('.$line->vat_src_code.
')';
1415 $result = $invoice->updateline($line->id, $line->desc, $line->subprice, $line->qty, $number, $line->date_start, $line->date_end, $vatratecode, $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);
1422 $invoice->fetch($placeid);
1423 } elseif ($action ==
'update_reduction_global' && $user->hasRight(
'takepos',
'editlines')) {
1424 foreach ($invoice->lines as $line) {
1425 $vatratecode = $line->tva_tx;
1426 if ($line->vat_src_code) {
1427 $vatratecode .=
' ('.$line->vat_src_code.
')';
1429 $result = $invoice->updateline($line->id, $line->desc, $line->subprice, $line->qty, $number, $line->date_start, $line->date_end, $vatratecode, $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);
1432 $invoice->fetch($placeid);
1435 if ($action ==
"editbatch_popup" && ($user->hasRight(
'takepos',
'run') || defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
1439 $prod->fetch($idproduct);
1440 $prod->load_stock(
'warehouseopen');
1442 $constantforkey =
'CASHDESK_ID_WAREHOUSE'.$_SESSION[
"takeposterminal"];
1445 print
'<html><body>';
1446 print
'<div class="divscroll">';
1447 print
'<div class="marginbottomonly"><b>'.dolPrintLabel($prod->label).
'</b>'.(!empty($prod->ref) ?
' <span class="opacitymedium">('.dolPrintLabel($prod->ref).
')</span>' :
'').
'</div>';
1448 print
'<table class="noborder">';
1451 if (is_array($prod->stock_warehouse)) {
1452 foreach ($prod->stock_warehouse as $tmpwarehouseid => $tmpval) {
1456 if (!empty($prod->stock_warehouse[$tmpwarehouseid]) && is_array($prod->stock_warehouse[$tmpwarehouseid]->detail_batch)) {
1457 foreach ($prod->stock_warehouse[$tmpwarehouseid]->detail_batch as $dbatch) {
1459 $detail .=
'<span class="opacitymedium">'.$langs->trans(
"LotSerial").
':</span> '.$dbatch->batch;
1460 $detail .=
' <span class="opacitymedium">'.$langs->trans(
"Qty").
':</span> '.$dbatch->qty;
1461 $detail .=
' <button class="marginleftonly" onclick="updatebatch(\''.dol_escape_js($dbatch->batch).
'\',
'.$tmpwarehouseid.',
'.$idline.',
'.((int) $clonebatch).')
">'.$langs->trans("Select
")."</
button>
";
1463 print '<tr><td class="left
">'.$detail;
1470 if ($nbofsuggested == 0) {
1471 print '<tr><td class="left
">'.$langs->trans("NoRecordFound
").'</td></tr>';
1474 // Add manual entry for returns or new batches
1475 print '<tr><td class="left
" style="padding-top: 10px; border-top: 1px solid #ddd;
">';
1476 print '<span class="opacitymedium
">'.$langs->trans("LotSerial
").' (Manual) :</span> ';
1477 print '<input type="text
" id="manual_batch
" class="flat
" size="10
"> ';
1478 print '<button class="button" onclick="updatebatch(document.getElementById(\
'manual_batch\').value, '.$warehouseid.
', '.$idline.
', '.((
int) $clonebatch).
')">'.$langs->trans(
"Add").
'</button>';
1479 print
' <button type="button" class="button button-cancel" onclick="$(\'#poslines\').load(\'invoice.php?place=\'+place+\'&invoiceid=\'+invoiceid);">'.$langs->trans(
"Cancel").
'</button>';
1483 print
'</div></body></html>';
1487 if ($action ==
"setbatch" && ($user->hasRight(
'takepos',
'run') || defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
1488 $constantforkey =
'CASHDESK_ID_WAREHOUSE'.$_SESSION[
"takeposterminal"];
1490 $idline = (empty($idoflineadded) ?
GETPOSTINT(
'idline') : $idoflineadded);
1491 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facturedet SET batch = '".$db->escape($batch).
"', fk_warehouse = ".((int) $warehouseid);
1492 $sql .=
" WHERE rowid = ".((int) $idline).
" AND fk_facture = ".((int) $placeid);
1496 $invoice->fetch($placeid);
1499 $sql =
'SELECT fd.rowid, fd.fk_product';
1500 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facturedet AS fd, '.MAIN_DB_PREFIX.
'product AS p';
1501 $sql .=
' WHERE fd.fk_product = p.rowid';
1502 $sql .=
' AND fd.fk_facture = '.((int) $placeid);
1503 $sql .=
" AND (fd.batch IS NULL OR fd.batch = '') AND p.tobatch > 0";
1504 $sql .=
' ORDER BY fd.rang, fd.rowid';
1505 $sql .= $db->plimit(1);
1506 $resql = $db->query($sql);
1507 if ($resql && ($obj = $db->fetch_object($resql))) {
1508 print
'<script>editbatch('.((int) $obj->rowid).
', '.((int) $obj->fk_product).
', 1);</script>';
1514 if ($action ==
"order" && $placeid != 0 && ($user->hasRight(
'takepos',
'run') || defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
1515 include_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1517 require_once DOL_DOCUMENT_ROOT.
'/takepos/class/dolreceiptprinter.class.php';
1521 $sql =
"SELECT label FROM ".MAIN_DB_PREFIX.
"takepos_floor_tables where rowid = ".((int) $place);
1522 $resql = $db->query($sql);
1523 $row = $db->fetch_object($resql);
1524 $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>';
1525 $footerorder =
'</tbody></table>'.dol_print_date(
dol_now(),
'dayhour').
'<br></html>';
1526 $order_receipt_printer1 =
"";
1527 $order_receipt_printer2 =
"";
1528 $order_receipt_printer3 =
"";
1533 foreach ($invoice->lines as $line) {
1534 if ($line->special_code ==
"4") {
1538 $existing =
$c->containing($line->fk_product, Categorie::TYPE_PRODUCT,
'id');
1539 $result = array_intersect($catsprinter1, $existing);
1540 $count = count($result);
1541 if (!$line->fk_product) {
1546 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facturedet set special_code='1' where rowid = ".((int) $line->id);
1548 $order_receipt_printer1 .=
'<tr><td class="left">';
1549 if ($line->fk_product) {
1550 $order_receipt_printer1 .= $line->product_label;
1552 $order_receipt_printer1 .= $line->description;
1554 $order_receipt_printer1 .=
'</td><td class="right">'.$line->qty;
1555 if (!empty($line->array_options[
'options_order_notes'])) {
1556 $order_receipt_printer1 .=
"<br>(".$line->array_options[
'options_order_notes'].
")";
1558 $order_receipt_printer1 .=
'</td></tr>';
1562 $invoice->fetch($placeid);
1563 $printer->orderprinter = 1;
1565 echo
"var orderprinter1esc='";
1566 $ret = $printer->sendToPrinter($invoice,
getDolGlobalInt(
'TAKEPOS_TEMPLATE_TO_USE_FOR_ORDERS'.$_SESSION[
"takeposterminal"]),
getDolGlobalInt(
'TAKEPOS_ORDER_PRINTER1_TO_USE'.$_SESSION[
"takeposterminal"]));
1569 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facturedet set special_code='4' where special_code='1' and fk_facture = ".((int) $invoice->id);
1571 $invoice->fetch($placeid);
1574 foreach ($invoice->lines as $line) {
1575 if ($line->special_code ==
"4") {
1579 $existing =
$c->containing($line->fk_product, Categorie::TYPE_PRODUCT,
'id');
1580 $result = array_intersect($catsprinter2, $existing);
1581 $count = count($result);
1584 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facturedet set special_code='2' where rowid = ".((int) $line->id);
1586 $order_receipt_printer2 .=
'<tr>'.$line->product_label.
'<td class="right">'.$line->qty;
1587 if (!empty($line->array_options[
'options_order_notes'])) {
1588 $order_receipt_printer2 .=
"<br>(".$line->array_options[
'options_order_notes'].
")";
1590 $order_receipt_printer2 .=
'</td></tr>';
1594 $invoice->fetch($placeid);
1595 $printer->orderprinter = 2;
1597 echo
"var orderprinter2esc='";
1598 $ret = $printer->sendToPrinter($invoice,
getDolGlobalInt(
'TAKEPOS_TEMPLATE_TO_USE_FOR_ORDERS'.$_SESSION[
"takeposterminal"]),
getDolGlobalInt(
'TAKEPOS_ORDER_PRINTER2_TO_USE'.$_SESSION[
"takeposterminal"]));
1601 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facturedet set special_code='4' where special_code='2' and fk_facture = ".((int) $invoice->id);
1603 $invoice->fetch($placeid);
1606 foreach ($invoice->lines as $line) {
1607 if ($line->special_code ==
"4") {
1611 $existing =
$c->containing($line->fk_product, Categorie::TYPE_PRODUCT,
'id');
1612 $result = array_intersect($catsprinter3, $existing);
1613 $count = count($result);
1616 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facturedet set special_code='3' where rowid = ".((int) $line->id);
1618 $order_receipt_printer3 .=
'<tr>'.$line->product_label.
'<td class="right">'.$line->qty;
1619 if (!empty($line->array_options[
'options_order_notes'])) {
1620 $order_receipt_printer3 .=
"<br>(".$line->array_options[
'options_order_notes'].
")";
1622 $order_receipt_printer3 .=
'</td></tr>';
1626 $invoice->fetch($placeid);
1627 $printer->orderprinter = 3;
1629 echo
"var orderprinter3esc='";
1630 $ret = $printer->sendToPrinter($invoice,
getDolGlobalInt(
'TAKEPOS_TEMPLATE_TO_USE_FOR_ORDERS'.$_SESSION[
"takeposterminal"]),
getDolGlobalInt(
'TAKEPOS_ORDER_PRINTER3_TO_USE'.$_SESSION[
"takeposterminal"]));
1633 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facturedet set special_code='4' where special_code='3' and fk_facture = ".((int) $invoice->id);
1635 $invoice->fetch($placeid);
1638 $sectionwithinvoicelink =
'';
1639 if (($action ==
"valid" || $action ==
"history" || $action ==
'creditnote' || ($action ==
'addline' && $invoice->status == $invoice::STATUS_CLOSED)) && $user->hasRight(
'takepos',
'run')) {
1640 $sectionwithinvoicelink .=
'<!-- Section with invoice link -->'.
"\n";
1641 $sectionwithinvoicelink .=
'<span style="font-size:120%;" class="center inline-block marginbottomonly">';
1642 if ($invoice->status == $invoice::STATUS_DRAFT) {
1643 $sectionwithinvoicelink .= $invoice->ref;
1645 $sectionwithinvoicelink .= $invoice->getNomUrl(1,
'', 0, 0,
'', 0, 0, -1,
'_backoffice');
1647 $sectionwithinvoicelink .=
" - ";
1648 $remaintopay = $invoice->getRemainToPay();
1649 if ($remaintopay > 0) {
1650 $sectionwithinvoicelink .= $langs->trans(
'RemainToPay').
': <span class="amountremaintopay" style="font-size: unset">'.
price($remaintopay, 1, $langs, 1, -1, -1,
$conf->currency).
'</span>';
1652 $sectionwithinvoicelink .= $invoice->getLibStatut(2);
1655 $sectionwithinvoicelink .=
'</span><br>';
1657 $customprinterallowed =
false;
1658 $customprinttemplateallowed =
true;
1663 $customprinterallowed =
true;
1664 $customprinttemplateallowed =
true;
1667 include_once DOL_DOCUMENT_ROOT.
'/blockedlog/lib/blockedlog.lib.php';
1670 $customprinttemplateallowed =
false;
1673 if ($invoice->status == $invoice::STATUS_CLOSED) {
1674 if (
getDolGlobalInt(
'TAKEPOS_PRINT_INVOICE_DOC_INSTEAD_OF_RECEIPT')) {
1675 $sectionwithinvoicelink .=
' <a target="_blank" class="button" href="' . DOL_URL_ROOT .
'/document.php?token=' .
newToken() .
'&modulepart=facture&file=' . $invoice->ref .
'/' . $invoice->ref .
'.pdf">'.$langs->trans(
"Invoice").
'</a>';
1682 $sectionwithinvoicelink .=
' <button id="buttonprint" type="button" onclick="PrintByESCPOSOld('.$placeid.
')">'.$langs->trans(
'PrintTicket').
'</button>';
1686 $sectionwithinvoicelink .=
' <button id="buttonprint" type="button" onclick="PrintHTMLToSlashPrint('.$placeid.
')">'.$langs->trans(
'PrintTicket').
'</button>';
1688 } elseif ($customprinterallowed && $customprinttemplateallowed && (
isModEnabled(
'receiptprinter') &&
getDolGlobalInt(
'TAKEPOS_PRINTER_TO_USE'.$term) > 0) ||
getDolGlobalString(
'TAKEPOS_PRINT_METHOD') ==
"receiptprinter") {
1691 $sectionwithinvoicelink .=
' <button id="buttonprint" type="button" onclick="PrintByESCPOS('.$placeid.
')" title="'.dolPrintHTMLForAttribute($langs->trans(
"SentToPrinter").
' '.$nameOfPrinter).
'">'.$langs->trans(
'PrintTicket').
'</button>';
1694 $sectionwithinvoicelink .=
' <button id="buttonprint" type="button" onclick="PrintByBrowser('.$placeid.
')">'.$langs->trans(
'PrintTicket').
'</button>';
1697 if ($customprinttemplateallowed &&
getDolGlobalString(
'TAKEPOS_PRINT_WITHOUT_DETAILS')) {
1698 $sectionwithinvoicelink .=
' <button id="buttonprint" type="button" onclick="PrintBox('.$placeid.
', \'without_details\')">'.$langs->trans(
'PrintWithoutDetails').
'</button>';
1701 $sectionwithinvoicelink .=
' <button id="buttonprint" type="button" onclick="PrintByBrowser('.$placeid.
', 1)">'.$langs->trans(
'GiftReceipt').
'</button>';
1706 $sectionwithinvoicelink .=
' <button id="buttonsend" type="button" onclick="SendTicket('.$placeid.
')">'.$langs->trans(
'SendTicket').
'</button>';
1709 if ($remaintopay <= 0 &&
getDolGlobalString(
'TAKEPOS_AUTO_PRINT_TICKETS') && $action !=
"history") {
1710 $sectionwithinvoicelink .=
'<script type="text/javascript">console.log("Emulate click on #buttonprint"); $("#buttonprint").click();</script>';
1721$form =
new Form($db);
1724if (defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1725 $title =
'TakePOS - Dolibarr '.DOL_VERSION;
1729 $head =
'<meta name="apple-mobile-web-app-title" content="TakePOS"/>
1730 <meta name="apple-mobile-web-app-capable" content="yes">
1731 <meta name="mobile-web-app-capable" content="yes">
1732 <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>';
1733 $arrayofcss = array(
1734 '/takepos/css/pos.css.php',
1736 $arrayofjs = array(
'/takepos/js/jquery.colorbox-min.js');
1739 top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss);
1741 print
'<body>'.
"\n";
1748<script
type=
"text/javascript">
1751<?php
if ($action ==
"valid") {
1752 echo
"var place=0;";
1754var placeid=<?php echo($placeid > 0 ? $placeid : 0); ?>;
1755$(document).ready(
function() {
1756 var idoflineadded = <?php echo(empty($idoflineadded) ? 0 : $idoflineadded); ?>;
1758 $(
'.posinvoiceline').click(
function(){
1759 console.log(
"Click done on "+this.
id);
1760 $(
'.posinvoiceline').removeClass(
"selected");
1761 $(
this).addClass(
"selected");
1765 if (selectedline == this.
id) {
1768 selectedline = this.id;
1770 selectedtext=$(
'#'+selectedline).find(
"td:first").html();
1772 if (defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1773 print
'$("#phonediv1").load("'.DOL_URL_ROOT.
'/takepos/public/auto_order.php?action=editline&token='.
newToken().
'&placeid="+placeid+"&selectedline="+selectedline, function() {
1780 if (idoflineadded > 0)
1782 console.log(
"Auto select "+idoflineadded);
1783 $(
'.posinvoiceline#'+idoflineadded).click();
1787if ($action ==
"order" && !empty($order_receipt_printer1)) {
1788 if (filter_var(
getDolGlobalString(
'TAKEPOS_PRINT_SERVER'), FILTER_VALIDATE_URL) ==
true) {
1792 url:
'<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER
'); ?>/printer/index.php',
1793 data:
'invoice='+orderprinter1esc
1800 url:
'http://<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER
'); ?>:8111/print',
1802 print $headerorder.$order_receipt_printer1.$footerorder; ?>'
1808if ($action ==
"order" && !empty($order_receipt_printer2)) {
1809 if (filter_var(
getDolGlobalString(
'TAKEPOS_PRINT_SERVER'), FILTER_VALIDATE_URL) ==
true) {
1813 url:
'<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER
'); ?>/printer/index.php?printer=2',
1814 data:
'invoice='+orderprinter2esc
1821 url:
'http://<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER
'); ?>:8111/print2',
1823 print $headerorder.$order_receipt_printer2.$footerorder; ?>'
1829if ($action ==
"order" && !empty($order_receipt_printer3)) {
1830 if (filter_var(
getDolGlobalString(
'TAKEPOS_PRINT_SERVER'), FILTER_VALIDATE_URL) ==
true) {
1834 url:
'<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER
'); ?>/printer/index.php?printer=3',
1835 data:
'invoice='+orderprinter3esc
1842if ($action ==
"search" || $action ==
"valid") {
1844 parent.ClearSearch(
true);
1849if ($action ==
"search") {
1851 $(
'#search').focus();
1859function SendTicket(
id)
1861 console.log(
"Open box to select the Print/Send form");
1862 $.colorbox({href:
"send.php?facid="+id, width:
"70%", height:
"30%", transition:
"none", iframe:
"true", title:<?php echo
"'".dol_escape_js($langs->trans(
"SendTicket")).
"'" ; ?>});
1867function PrintBox(
id, action) {
1868 console.log(
"Open box before printing");
1869 $.colorbox({href:
"printbox.php?facid="+
id+
"&action="+action+
"&token=<?php echo newToken(); ?>", width:
"80%", height:
"200px", transition:
"none", iframe:
"true", title:
"<?php echo $langs->trans("PrintWithoutDetails
"); ?>"});
1874function PrintByBrowser(
id, gift) {
1875 console.log(
"Call PrintByBrowser() to generate the receipt.");
1876 $.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")).
"'" ; ?>});
1881function PrintHTMLToSlashPrint(
id){
1883 console.log(
"PrintHTMLToSlashPrint" +
id);
1884 $.get(
"receipt.php?facid="+
id,
function(data,
status) {
1885 receipt=data.replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g,
'');
1888 url:
'http://<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER
'); ?>:8111/print',
1896function PrintByESCPOSOld(
id){
1897 console.log(
"PrintByESCPOSOld id=" +
id);
1898 $.get(
"<?php echo DOL_URL_ROOT; ?>/takepos/ajax/ajax.php?action=printinvoiceticket&token=<?php echo currentToken(); ?>&term=<?php echo urlencode(isset($_SESSION["takeposterminal
"]) ? $_SESSION["takeposterminal
"] : ''); ?>&id="+
id,
function(data,
status) {
1901 url:
'<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER
'); ?>/printer/index.php',
1902 data:
'invoice='+data
1913function PrintByESCPOS(
id) {
1914 console.log(
"PrintByESCPOS Printing invoice ticket by calling takepos/aja/ajax.php id=" +
id);
1918 data: { token:
'<?php echo currentToken(); ?>' },
1919 url:
"<?php print DOL_URL_ROOT.'/takepos/ajax/ajax.php?action=printinvoiceticket&token='.currentToken().'&term='.urlencode(isset($_SESSION["takeposterminal
"]) ? $_SESSION["takeposterminal
"] : '').'&id='; ?>" + id,
1920 success:
function(){
1921 showPrintResultPopup(<?php echo
"'".
dol_escape_js($langs->trans(
"SentToPrinter").
' '.$nameOfPrinter).
"'" ; ?>, 2000);
1924 showPrintResultPopup(<?php echo
"'".
dol_escape_js($langs->trans(
"FailedToSendToPrinter")).
"'" ; ?>, 2000);
1931function showPrintResultPopup(message, duration) {
1932 $(
"#dialogforpopuptakepos").show().text(message).fadeIn();
1934 setTimeout(
function(){
1935 $(
"#dialogforpopuptakepos").fadeOut().hide();
1942var creditNoteParams=
"";
1943function CreditNote() {
1945 $parameters = array();
1946 $reshook = $hookmanager->executeHooks(
'paramsForCreditNote', $parameters, $invoice, $action);?>
1947 $(
"#poslines").load(
"<?php
1948 print DOL_URL_ROOT; ?>/takepos/invoice.php?action=creditnote&token=<?php echo newToken() ?>&invoiceid="+placeid+creditNoteParams,
function() { });
1955 $(
"#poslines").load(
"<?php print DOL_URL_ROOT; ?>/takepos/invoice.php?action=addnote&token=<?php echo newToken() ?>&invoiceid="+placeid+
"&idline="+selectedline, {
"addnote": $(
"#textinput").val() });
1960$( document ).ready(
function() {
1961 console.log(
"Set customer info and sales in header placeid=<?php echo $placeid; ?> status=<?php echo $invoice->statut; ?>");
1964 $s = $langs->trans(
"Customer");
1965 if ($invoice->id > 0 && ($invoice->socid !=
getDolGlobalString($constforcompanyid))) {
1968 $contactids = $invoice->getIdContact(
'external',
'BILLING');
1969 $contactid = $contactids[0];
1970 if ($contactid > 0) {
1972 $contact->fetch($contactid);
1973 $s .=
" - " . $contact->getFullName($langs);
1977 print
'$("#idcustomer").val("");';
1981 $(
"#customerandsales").html(
'');
1982 $(
"#shoppingcart").html(
'');
1985 $(
"#customerandsales").append(
'<a class="valignmiddle tdoverflowmax100 minwidth100" id="customer" onclick="Customer();" title="<?php print dol_escape_js(dol_escape_htmltag((string) $s)); ?>"><span class="fas fa-building paddingrightonly"></span><?php print dol_escape_js((string) $s); ?></a>');
1987 $(
"#customerandsales").append(
'<a class="valignmiddle tdoverflowmax300 minwidth100" id="contact" onclick="Contact();" title="<?php print dol_escape_js(dol_escape_htmltag((string) $s)); ?>"><span class="fas fa-building paddingrightonly"></span><?php print dol_escape_js((string) $s); ?></a>');
1991 $sql =
"SELECT rowid, datec, ref FROM ".MAIN_DB_PREFIX.
"facture";
1992 $sql .=
" WHERE entity IN (".getEntity(
'invoice').
")";
1995 $sql .=
" AND ref LIKE '(PROV-POS".$db->escape(isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'').
"-0%'";
1998 $sql .=
" AND pos_source = '".$db->escape((
string) $_SESSION[
"takeposterminal"]).
"'";
1999 $sql .=
" AND module_source = 'takepos'";
2002 $sql .= $db->order(
'datec',
'ASC');
2003 $resql = $db->query($sql);
2006 while ($obj = $db->fetch_object($resql)) {
2007 $num_sale = str_replace(
")",
"", str_replace(
"(PROV-POS".$_SESSION[
"takeposterminal"].
"-",
"", $obj->ref));
2008 if (str_replace(
"-",
"", $num_sale) > $max_sale) {
2009 $max_sale = str_replace(
"-",
"", $num_sale);
2012 $htmlsale =
'<a class="valignmiddle" title="'.dol_escape_htmltag($langs->trans(
"SaleStartedAt",
dol_print_date($db->jdate($obj->datec),
'%H:%M',
'tzuser')).
' - '.$obj->ref).
'"';
2013 $htmlsale .=
' onclick="place=\''.$num_sale.
'\'; invoiceid=\
''.$obj->rowid.
'\'; Refresh();
">';
2014 $htmlsale .= '<span class="'.($placeid == $obj->rowid ? 'basketselected
' : 'basketnotselected
').'">';
2015 $htmlsale .= '<span class="fa fa-shopping-cart paddingright
"></span>'.dol_print_date($db->jdate($obj->datec), '%H:%M', 'tzuser');
2016 $htmlsale .= '</span>';
2017 $htmlsale .= '</a>';
2018 echo '$("#shoppingcart
").append(\''.dol_escape_js($htmlsale, 1).'\');';
2020 echo '$("#shoppingcart
").append(\'<a onclick="place=\\\
'0-';
2022 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>\');';
2024 dol_print_error($db);
2030 $constantforkey =
'CASHDESK_NO_DECREASE_STOCK'. (isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
2033 $constantforkey =
'CASHDESK_ID_WAREHOUSE'. (isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
2035 if ($idwarehouse > 0) {
2036 $s =
'<span class="small">';
2038 $warehouse->fetch($idwarehouse);
2039 $s .=
'<span class="hideonsmartphone">'.$langs->trans(
"Warehouse").
'<br></span>'.$warehouse->ref;
2041 $s .=
' ('.$langs->trans(
"Closed").
')';
2044 print
"$('#infowarehouse').html('".dol_escape_js($s).
"');";
2045 print
'$("#infowarehouse").css("display", "inline-block");';
2047 $s =
'<span class="small hideonsmartphone">';
2048 $s .= $langs->trans(
"StockChangeDisabled").
'<br>'.$langs->trans(
"NoWarehouseDefinedForTerminal");
2050 print
"$('#infowarehouse').html('".dol_escape_js($s).
"');";
2051 if (!empty(
$conf->dol_optimize_smallscreen)) {
2052 print
'$("#infowarehouse").css("display", "none");';
2056 $s =
'<span class="small hideonsmartphone">'.$langs->trans(
"StockChangeDisabled").
'</span>';
2057 print
"$('#infowarehouse').html('".dol_escape_js($s).
"');";
2058 if (!empty(
$conf->dol_optimize_smallscreen)) {
2059 print
'$("#infowarehouse").css("display", "none");';
2068 $s =
'<span class="small">';
2069 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
2070 $langs->load(
"members");
2071 $s .= $langs->trans(
"Member").
': ';
2073 $result = $adh->fetch(0,
'', $invoice->socid);
2075 $adh->ref = $adh->getFullName($langs);
2079 $s .= $adh->getFullName($langs);
2080 $s .=
' - '.$adh->type;
2081 if ($adh->datefin) {
2082 $s .=
'<br>'.$langs->trans(
"SubscriptionEndDate").
': '.
dol_print_date($adh->datefin,
'day');
2083 if ($adh->hasDelay()) {
2084 $s .=
" ".img_warning($langs->trans(
"Late"));
2087 $s .=
'<br>'.$langs->trans(
"SubscriptionNotReceived");
2088 if ($adh->status > 0) {
2089 $s .=
" ".img_warning($langs->trans(
"Late"));
2096 $s .=
'<br>'.$langs->trans(
"ThirdpartyNotLinkedToMember");
2101 $(
"#moreinfo").html(<?php print
"'".
dol_escape_js($s).
"'" ; ?>);
2108 echo
"function CustomerDisplay(){";
2109 echo
"var line1='".$CUSTOMER_DISPLAY_line1.
"'.substring(0,20);";
2110 echo
"line1=line1.padEnd(20);";
2111 echo
"var line2='".$CUSTOMER_DISPLAY_line2.
"'.substring(0,20);";
2112 echo
"line2=line2.padEnd(20);";
2114 echo
'webSocketCustomerDisplay.send(line1);';
2115 echo
'webSocketCustomerDisplay.send(line2);';
2119 data: { text: line1+line2 },
2120 url: '".getDolGlobalString(
'TAKEPOS_PRINT_SERVER').
"/display/index.php',
2133if (!empty(
$conf->use_javascript_ajax)) {
2134 print
"\n".
'<!-- Includes JS Footer of Dolibarr -->'.
"\n";
2135 print
'<script src="'.DOL_URL_ROOT.
'/core/js/lib_foot.js.php?lang='.$langs->defaultlang.
'"></script>'.
"\n";
2138$usediv = (
GETPOST(
'format',
'aZ09') ==
'div');
2140print
'<!-- invoice.php place='.(int) $place.
' invoice='.$invoice->ref.
' usediv='.json_encode($usediv).
', mobilepage='.(empty($mobilepage) ?
'' : $mobilepage).
' $_SESSION["basiclayout"]='.(empty($_SESSION[
"basiclayout"]) ?
'' : $_SESSION[
"basiclayout"]).
' conf TAKEPOS_BAR_RESTAURANT='.
getDolGlobalString(
'TAKEPOS_BAR_RESTAURANT').
' -->'.
"\n";
2141print
'<div class="div-table-responsive-no-min invoice">';
2143 print
'<div id="tablelines">';
2145 print
'<table id="tablelines" class="noborder noshadow postablelines centpercent">';
2148$buttontocreatecreditnote =
'';
2149if (($action ==
"valid" || $action ==
"history" || $action ==
"addline")
2151 $buttontocreatecreditnote .=
' <!-- Show button to create a credit note -->'.
"\n";
2152 $buttontocreatecreditnote .=
'<button id="buttonprint" type="button" onclick="ModalBox(\'ModalCreditNote\')">'.$langs->trans(
'CreateCreditNote').
'</button>';
2153 if (
getDolGlobalInt(
'TAKEPOS_PRINT_INVOICE_DOC_INSTEAD_OF_RECEIPT')) {
2154 $buttontocreatecreditnote .=
' <a target="_blank" class="button" href="' . DOL_URL_ROOT .
'/document.php?token=' .
newToken() .
'&modulepart=facture&file=' . urlencode($invoice->ref .
'/' . $invoice->ref .
'.pdf').
'">'.$langs->trans(
"Invoice").
'</a>';
2158$buttontocloneticket =
'';
2160 $buttontocloneticket .=
' <button id="buttonclone" type="button" onclick="CloneTicket('.((int) $invoice->id).
')">'.$langs->trans(
'CloneTicket').
'</button>';
2164if ($sectionwithinvoicelink && ($mobilepage ==
"invoice" || $mobilepage ==
"")) {
2165 print
'<!-- Print table line with link to invoice ref -->';
2167 print
'<tr><td colspan="5" class="paddingtopimp paddingbottomimp" style="padding-top: 10px !important; padding-bottom: 10px !important;">';
2168 print $sectionwithinvoicelink;
2169 print $buttontocreatecreditnote;
2170 print $buttontocloneticket;
2173 print
'<tr><td colspan="4" class="paddingtopimp paddingbottomimp" style="padding-top: 10px !important; padding-bottom: 10px !important;">';
2174 print $sectionwithinvoicelink;
2175 print $buttontocreatecreditnote;
2176 print $buttontocloneticket;
2183 print
'<tr class="liste_titre nodrag nodrop">';
2184 print
'<td class="linecoldescription">';
2187if (empty($mobilepage) || $mobilepage ==
"invoice") {
2188 print
'<!-- hidden var used by some js functions -->';
2189 print
'<input type="hidden" name="invoiceid" id="invoiceid" value="'.$invoice->id.
'">';
2190 print
'<input type="hidden" name="thirdpartyid" id="thirdpartyid" value="'.$invoice->socid.
'">';
2194 $sql =
"SELECT floor, label FROM ".MAIN_DB_PREFIX.
"takepos_floor_tables where rowid = ".((int) $place);
2195 $resql = $db->query($sql);
2196 $obj = $db->fetch_object($resql);
2198 $label = $obj->label;
2199 $floor = $obj->floor;
2201 if ($mobilepage ==
"invoice" || $mobilepage ==
"") {
2204 print
'<span class="opacitymedium">'.$langs->trans(
'Place').
"</span> <b>".(empty($label) ?
'?' : $label).
"</b><br>";
2205 print
'<span class="opacitymedium">'.$langs->trans(
'Floor').
"</span> <b>".(empty($floor) ?
'?' : $floor).
"</b>";
2212$parameters = array();
2213$reshook = $hookmanager->executeHooks(
'completeTakePosInvoiceHeader', $parameters, $invoice, $action);
2215 setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
2217print $hookmanager->resPrint;
2219if (empty($_SESSION[
"basiclayout"]) || $_SESSION[
"basiclayout"] != 1) {
2221 print
'<td class="linecolqty right">'.$langs->trans(
'PriceUHT').
'</td>';
2223 print
'<td class="linecolqty right">'.$langs->trans(
'ReductionShort').
'</td>';
2224 print
'<td class="linecolqty right">'.$langs->trans(
'Qty').
'</td>';
2226 print
'<td class="linecolht right nowraponall">';
2227 print
'<span class="opacitymedium small">' . $langs->trans(
'TotalHTShort') .
'</span><br>';
2229 if (empty($mobilepage) || $mobilepage ==
"invoice") {
2230 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>';
2231 if (
isModEnabled(
'multicurrency') && !empty($_SESSION[
"takeposcustomercurrency"]) &&
$conf->currency != $_SESSION[
"takeposcustomercurrency"]) {
2233 include_once DOL_DOCUMENT_ROOT .
'/multicurrency/class/multicurrency.class.php';
2235 $multicurrency->fetch(0, $_SESSION[
"takeposcustomercurrency"]);
2236 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>';
2241 print
'<td class="linecolht right nowraponall">';
2242 print
'<span class="opacitymedium small">'.$langs->trans(
'TotalTTCShort').
'</span><br>';
2244 if (empty($mobilepage) || $mobilepage ==
"invoice") {
2245 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>';
2246 if (
isModEnabled(
'multicurrency') && !empty($_SESSION[
"takeposcustomercurrency"]) &&
$conf->currency != $_SESSION[
"takeposcustomercurrency"]) {
2248 include_once DOL_DOCUMENT_ROOT.
'/multicurrency/class/multicurrency.class.php';
2250 $multicurrency->fetch(0, $_SESSION[
"takeposcustomercurrency"]);
2251 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>';
2255} elseif ($mobilepage ==
"invoice") {
2256 print
'<td class="linecolqty right">'.$langs->trans(
'Qty').
'</td>';
2262if (!empty($_SESSION[
"basiclayout"]) && $_SESSION[
"basiclayout"] == 1) {
2263 if ($mobilepage ==
"cats") {
2264 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
2266 $categories = $categorie->get_full_arbo(
'product');
2268 foreach ($categories as $row) {
2269 if (defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
2270 $htmlforlines .=
'<div class="leftcat"';
2272 $htmlforlines .=
'<tr class="drag drop oddeven posinvoiceline"';
2274 $htmlforlines .=
' onclick="LoadProducts('.$row[
'id'].
');">';
2275 if (defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
2276 $htmlforlines .=
'<img class="imgwrapper" width="33%" src="'.DOL_URL_ROOT.
'/takepos/public/auto_order.php?genimg=cat&query=cat&id='.$row[
'id'].
'"><br>';
2278 $htmlforlines .=
'<td class="left">';
2280 $htmlforlines .= $row[
'label'];
2281 if (defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
2282 $htmlforlines .=
'</div>'.
"\n";
2284 $htmlforlines .=
'</td></tr>'.
"\n";
2287 print $htmlforlines;
2290 if ($mobilepage ==
"products") {
2291 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
2294 $result =
$object->fetch($catid);
2295 $prods =
$object->getObjectsInCateg(
"product");
2297 '@phan-var-force Product[] $prods';
2299 foreach ($prods as $row) {
2300 if (defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
2301 $htmlforlines .=
'<div class="leftcat"';
2303 $htmlforlines .=
'<tr class="drag drop oddeven posinvoiceline"';
2305 $htmlforlines .=
' onclick="AddProduct(\''.$place.
'\',
'.$row->id.')
"';
2306 $htmlforlines .= '>';
2307 if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
2308 $htmlforlines .= '<img class="imgwrapper
" width="33%
" src="'.DOL_URL_ROOT.'/takepos/
public/auto_order.php?genimg=pro&query=pro&
id=
'.$row->id.'"><br>';
2309 $htmlforlines .= $row->label.' '.price($row->price_ttc, 1, $langs, 1, -1, -1, $conf->currency);
2310 $htmlforlines .= '</div>'."\n
";
2312 $htmlforlines .= '<td class="left
">';
2313 $htmlforlines .= $row->label;
2314 $htmlforlines .= '<div class="right
">'.price($row->price_ttc, 1, $langs, 1, -1, -1, $conf->currency).'</div>';
2315 $htmlforlines .= '</td>';
2316 $htmlforlines .= '</tr>'."\n
";
2319 print $htmlforlines;
2322 if ($mobilepage == "places
") {
2323 $sql = "SELECT rowid, entity, label, leftpos, toppos, floor FROM
".MAIN_DB_PREFIX."takepos_floor_tables
";
2324 $resql = $db->query($sql);
2328 while ($row = $db->fetch_array($resql)) {
2330 $htmlforlines .= '<tr class="drag drop oddeven posinvoiceline
';
2331 $htmlforlines .= '" onclick="LoadPlace(\
''.$row[
'label'].
'\')
">';
2332 $htmlforlines .= '<td class="left
">';
2333 $htmlforlines .= $row['label'];
2334 $htmlforlines .= '</td>';
2335 $htmlforlines .= '</tr>'."\n
";
2337 print $htmlforlines;
2342 //In Phone basic layout hide some content depends situation
2343 if (!empty($_SESSION["basiclayout
"]) && $_SESSION["basiclayout
"] == 1 && $mobilepage != "invoice
" && $action != "order
") {
2347 // Loop on each lines on invoice
2348 if (is_array($invoice->lines) && count($invoice->lines)) {
2349 print '<!-- invoice.php show lines of invoices -->'."\n
";
2350 $tmplines = array_reverse($invoice->lines);
2351 $htmlsupplements = array();
2352 foreach ($tmplines as $line) {
2353 if ($line->fk_parent_line != false) {
2354 if (!isset($htmlsupplements[$line->fk_parent_line])) {
2355 $htmlsupplements[$line->fk_parent_line] = '';
2357 $htmlsupplements[$line->fk_parent_line] .= '<tr class="drag drop oddeven posinvoiceline
';
2358 if ($line->special_code == "4") {
2359 $htmlsupplements[$line->fk_parent_line] .= ' order
';
2361 $htmlsupplements[$line->fk_parent_line] .= '" id="'.$line->id.'"';
2362 if ($line->special_code == "4
") {
2363 $htmlsupplements[$line->fk_parent_line] .= ' title="'.dol_escape_htmltag($langs->trans("AlreadyPrinted")).'"';
2365 $htmlsupplements[$line->fk_parent_line] .= '>';
2366 $htmlsupplements[$line->fk_parent_line] .= '<td class="left
">';
2367 $htmlsupplements[$line->fk_parent_line] .= img_picto('', 'rightarrow.png');
2368 if ($line->product_label) {
2369 $htmlsupplements[$line->fk_parent_line] .= $line->product_label;
2371 if ($line->product_label && $line->desc) {
2372 $htmlsupplements[$line->fk_parent_line] .= '<br>';
2374 if ($line->product_label != $line->desc) {
2375 $firstline = dolGetFirstLineOfText($line->desc);
2376 if ($firstline != $line->desc) {
2377 $htmlsupplements[$line->fk_parent_line] .= $form->textwithpicto(dolGetFirstLineOfText($line->desc), $line->desc);
2379 $htmlsupplements[$line->fk_parent_line] .= $line->desc;
2382 $htmlsupplements[$line->fk_parent_line] .= '</td>';
2384 // complete line by hook
2385 $parameters = array('line' => $line);
2386 $reshook = $hookmanager->executeHooks('completeTakePosInvoiceParentLine', $parameters, $invoice, $action); // Note that $action and $object may have been modified by some hooks
2388 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
2390 $htmlsupplements[$line->fk_parent_line] .= $hookmanager->resPrint;
2392 if (empty($_SESSION["basiclayout
"]) || $_SESSION["basiclayout
"] != 1) {
2393 $htmlsupplements[$line->fk_parent_line] .= '<td class="right
">'.vatrate(price2num($line->remise_percent), true).'</td>';
2394 $htmlsupplements[$line->fk_parent_line] .= '<td class="right
">'.$line->qty.'</td>';
2395 $htmlsupplements[$line->fk_parent_line] .= '<td class="right
">'.price($line->total_ttc).'</td>';
2397 $htmlsupplements[$line->fk_parent_line] .= '</tr>'."\n
";
2402 $htmlforlines .= '<tr class="drag drop oddeven posinvoiceline
';
2403 if ($line->special_code == "4") {
2404 $htmlforlines .= ' order
';
2406 $htmlforlines .= '" id="'.$line->id.'"';
2407 if ($line->special_code == "4
") {
2408 $htmlforlines .= ' title="'.dol_escape_htmltag($langs->trans("AlreadyPrinted")).'"';
2410 $htmlforlines .= '>';
2411 $htmlforlines .= '<td class="left
">';
2412 if (!empty($_SESSION["basiclayout
"]) && $_SESSION["basiclayout
"] == 1) {
2413 $htmlforlines .= '<span class="phoneqty
">'.$line->qty."</span> x
";
2415 if (isset($line->product_type)) {
2416 if (empty($line->product_type)) {
2417 $htmlforlines .= img_object('', 'product').' ';
2419 $htmlforlines .= img_object('', 'service').' ';
2423 if (!getDolGlobalString('TAKEPOS_SHOW_N_FIRST_LINES')) {
2424 if ($line->product_ref) {
2425 $tooltiptext .= '<b>'.$langs->trans("Ref
").'</b> : '.$line->product_ref.'<br>';
2426 $tooltiptext .= '<b>'.$langs->trans("Label
").'</b> : '.$line->product_label.'<br>';
2427 if (!empty($line->batch)) {
2428 $tooltiptext .= '<br><b>'.$langs->trans("LotSerial
").'</b> : '.$line->batch.'<br>';
2430 if (!empty($line->fk_warehouse)) {
2431 $tooltiptext .= '<b>'.$langs->trans("Warehouse
").'</b> : '.$line->fk_warehouse.'<br>';
2433 if ($line->product_label != $line->desc) {
2435 $tooltiptext .= '<br>';
2437 $tooltiptext .= $line->desc;
2440 if (getDolGlobalInt('TAKEPOS_SHOW_PRODUCT_REFERENCE') == 1) {
2441 $htmlforlines .= $form->textwithpicto($line->product_label ? '<b>' . $line->product_ref . '</b> - ' . $line->product_label : dolGetFirstLineOfText($line->desc, 1), $tooltiptext);
2442 } elseif (getDolGlobalInt('TAKEPOS_SHOW_PRODUCT_REFERENCE') == 2) {
2443 $htmlforlines .= $form->textwithpicto($line->product_ref ? '<b>'.$line->product_ref.'<b>' : dolGetFirstLineOfText($line->desc, 1), $tooltiptext);
2445 $htmlforlines .= $form->textwithpicto($line->product_label ? $line->product_label : ($line->product_ref ? $line->product_ref : dolGetFirstLineOfText($line->desc, 1)), $tooltiptext);
2448 if ($line->product_ref) {
2449 $tooltiptext .= '<b>'.$langs->trans("Ref
").'</b> : '.$line->product_ref.'<br>';
2450 $tooltiptext .= '<b>'.$langs->trans("Label
").'</b> : '.$line->product_label.'<br>';
2452 if (!empty($line->batch)) {
2453 $tooltiptext .= '<br><b>'.$langs->trans("LotSerial
").'</b> : '.$line->batch.'<br>';
2455 if (!empty($line->fk_warehouse)) {
2456 $tooltiptext .= '<b>'.$langs->trans("Warehouse
").'</b> : '.$line->fk_warehouse.'<br>';
2459 if ($line->product_label) {
2460 $htmlforlines .= $line->product_label;
2462 if ($line->product_label != $line->desc) {
2463 if ($line->product_label && $line->desc) {
2464 $htmlforlines .= '<br>';
2466 $firstline = dolGetFirstLineOfText($line->desc, getDolGlobalInt('TAKEPOS_SHOW_N_FIRST_LINES'));
2467 if ($firstline != $line->desc) {
2468 $htmlforlines .= $form->textwithpicto(dolGetFirstLineOfText($line->desc), $line->desc);
2470 $htmlforlines .= $line->desc;
2474 if (!empty($line->array_options['options_order_notes'])) {
2475 $htmlforlines .= "<br>(
".$line->array_options['options_order_notes'].")
";
2477 if (isModEnabled('productbatch') && $line->fk_product > 0) {
2478 if (!is_object($line->product) || !($line->product->id > 0)) {
2479 $line->fetch_product();
2482 if (is_object($line->product) && $line->product->status_batch > 0) {
2483 $batch_display = empty($line->batch) ? $langs->trans("NotDefined
") : dol_escape_htmltag($line->batch);
2484 $htmlforlines .= '<br><span class="opacitymedium
">'.$langs->trans("LotSerial
").' : '.$batch_display.'</span>';
2485 // Only show edit button if invoice is a Draft (status == 0)
2486 if ($invoice->status == Facture::STATUS_DRAFT) {
2487 $htmlforlines .= ' <a href="#
" onclick="editbatch(
'.$line->id.',
'.$line->fk_product.');
return false;
" title="'.dol_escape_htmltag($langs->trans("Modify")).'">'.img_edit().'</a>';
2491 if (!empty($_SESSION["basiclayout
"]) && $_SESSION["basiclayout
"] == 1) {
2492 $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>';
2494 if (empty($_SESSION["basiclayout
"]) || $_SESSION["basiclayout
"] != 1) {
2495 // Set the content of tooltip
2497 $moreinfo .= $langs->trans("VATRate
").': '.price($line->tva_tx).' %<br>';
2498 $moreinfo .= $langs->trans("UnitPrice
").': '.price($line->subprice).'<br>';
2499 $moreinfo .= '<br>';
2500 $moreinfo .= $langs->transcountry("TotalHT
", $mysoc->country_code).': '.price($line->total_ht);
2501 if ($line->vat_src_code) {
2502 $moreinfo .= '<br>'.$langs->trans("VATCode
").': '.$line->vat_src_code;
2504 $moreinfo .= '<br>'.$langs->trans("TotalVAT
").': '.price($line->total_tva);
2505 if ($mysoc->useLocalTax(1, 1, $mysoc)) {
2506 $moreinfo .= '<br>'.$langs->transcountry("TotalLT1
", $mysoc->country_code).': '.price($line->total_localtax1);
2508 if ($mysoc->useLocalTax(2, 1, $mysoc)) {
2509 $moreinfo .= '<br>'.$langs->transcountry("TotalLT2
", $mysoc->country_code).': '.price($line->total_localtax2);
2511 $moreinfo .= '<hr>';
2512 $moreinfo .= $langs->transcountry("TotalTTC
", $mysoc->country_code).': '.price($line->total_ttc);
2513 //$moreinfo .= $langs->trans("TotalHT
").': '.$line->total_ht;
2514 if ($line->date_start || $line->date_end) {
2515 $htmlforlines .= '<br><div class="clearboth nowraponall
">'.get_date_range($line->date_start, $line->date_end).'</div>';
2517 $htmlforlines .= '</td>';
2519 // complete line by hook
2520 $parameters = array('line' => $line);
2521 $reshook = $hookmanager->executeHooks('completeTakePosInvoiceLine', $parameters, $invoice, $action); // Note that $action and $object may have been modified by some hooks
2523 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
2525 $htmlforlines .= $hookmanager->resPrint;
2527 if (getDolGlobalInt("TAKEPOS_SHOW_SUBPRICE
")) {
2528 $htmlforlines .= '<td class="right
">'.price($line->subprice).'</td>';
2530 $htmlforlines .= '<td class="right
">'.vatrate(price2num($line->remise_percent), true).'</td>';
2531 // nowraponall keeps the qty and its '(stock)' block on one line: on narrow layouts
2532 // the native display otherwise wraps over three lines inside the qty column.
2533 $htmlforlines .= '<td class="right nowraponall
">';
2534 $htmlforlines .= $line->qty;
2535 if (isModEnabled('stock') && $user->hasRight('stock', 'mouvement', 'lire')) {
2536 $constantforkey = 'CASHDESK_ID_WAREHOUSE'.$_SESSION["takeposterminal
"];
2537 if (getDolGlobalString($constantforkey) && $line->fk_product > 0 && !getDolGlobalString('TAKEPOS_HIDE_STOCK_ON_LINE')) {
2538 $productChildrenNb = 0;
2539 if (getDolGlobalInt('PRODUIT_SOUSPRODUITS')) {
2540 if (!is_object($line->product) || !($line->product->id > 0)) {
2541 $line->fetch_product();
2543 if (is_object($line->product)) {
2544 $productChildrenNb = $line->product->hasFatherOrChild(1);
2547 if ($productChildrenNb == 0) {
2548 $sql = "SELECT e.rowid, e.ref, e.lieu, e.fk_parent, e.statut, ps.reel, ps.rowid as product_stock_id, p.pmp
";
2549 $sql .= " FROM
".MAIN_DB_PREFIX."entrepot as e,
";
2550 $sql .= " ".MAIN_DB_PREFIX."product_stock as ps
";
2551 $sql .= " LEFT JOIN
".MAIN_DB_PREFIX."product as p ON p.rowid = ps.fk_product
";
2552 $sql .= " WHERE ps.reel != 0
";
2553 $sql .= " AND ps.fk_entrepot =
".((int) getDolGlobalString($constantforkey));
2554 $sql .= " AND e.entity IN (
".getEntity('stock').")
";
2555 $sql .= " AND ps.fk_product =
".((int) $line->fk_product);
2556 $resql = $db->query($sql);
2559 $obj = $db->fetch_object($resql);
2561 $stock_real = price2num($obj->reel, 'MS');
2563 $htmlforlines .= ' ';
2564 $htmlforlines .= '<span class="opacitylow
" title="'.$langs->trans("Stock").' '.price($stock_real, 1, '', 1, 0).'">';
2565 $htmlforlines .= '(';
2566 if ($line->qty && $line->qty > $stock_real) {
2567 $htmlforlines .= '<span style="color: var(--amountremaintopaycolor)
">';
2569 $htmlforlines .= img_picto('', 'stock', 'class="pictofixedwidth
"').price($stock_real, 1, '', 1, 0);
2570 if ($line->qty && $line->qty > $stock_real) {
2571 $htmlforlines .= "</span>
";
2573 $htmlforlines .= ')';
2574 $htmlforlines .= '</span>';
2576 dol_print_error($db);
2582 $htmlforlines .= '</td>';
2583 if (getDolGlobalInt('TAKEPOS_SHOW_HT')) {
2584 $htmlforlines .= '<td class="right classfortooltip
" title="'.$moreinfo.'">';
2585 $htmlforlines .= price($line->total_ht, 1, '', 1, -1, -1, $conf->currency);
2586 if (isModEnabled('multicurrency') && !empty($_SESSION["takeposcustomercurrency
"]) && $conf->currency != $_SESSION["takeposcustomercurrency
"]) {
2587 //Only show customer currency if multicurrency module is enabled, if currency selected and if this currency selected is not the same as main currency
2588 include_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php';
2589 $multicurrency = new MultiCurrency($db);
2590 $multicurrency->fetch(0, $_SESSION["takeposcustomercurrency
"]);
2591 $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>';
2593 $htmlforlines .= '</td>';
2595 $htmlforlines .= '<td class="right classfortooltip
" title="'.$moreinfo.'">';
2596 $htmlforlines .= price($line->total_ttc, 1, '', 1, -1, -1, $conf->currency);
2597 if (isModEnabled('multicurrency') && !empty($_SESSION["takeposcustomercurrency
"]) && $conf->currency != $_SESSION["takeposcustomercurrency
"]) {
2598 //Only show customer currency if multicurrency module is enabled, if currency selected and if this currency selected is not the same as main currency
2599 include_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php';
2600 $multicurrency = new MultiCurrency($db);
2601 $multicurrency->fetch(0, $_SESSION["takeposcustomercurrency
"]);
2602 $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>';
2604 $htmlforlines .= '</td>';
2606 $htmlforlines .= '</tr>'."\n
";
2607 $htmlforlines .= empty($htmlsupplements[$line->id]) ? '' : $htmlsupplements[$line->id];
2609 print $htmlforlines;
2612 print '<tr class="drag drop oddeven
"><td class="left
"><span class="opacitymedium
">'.$langs->trans("Empty
").'</span></td><td></td>';
2613 if (empty($_SESSION["basiclayout
"]) || $_SESSION["basiclayout
"] != 1) {
2614 print '<td></td><td></td>';
2615 if (getDolGlobalString('TAKEPOS_SHOW_HT')) {
2621} else { // No invoice generated yet
2622 print '<tr class="drag drop oddeven
"><td class="left
"><span class="opacitymedium
">'.$langs->trans("Empty
").'</span></td><td></td>';
2623 if (empty($_SESSION["basiclayout
"]) || $_SESSION["basiclayout
"] != 1) {
2624 print '<td></td><td></td>';
2625 if (getDolGlobalString('TAKEPOS_SHOW_HT')) {
2638if ($action == "search
") {
2640 <input type="text
" id="search
" class="input-nobottom
" name="search
" onkeyup="Search2(\
'\',
null);
" style="width: 80%; font-size: 150%;
" placeholder="'.dol_escape_htmltag($langs->trans('Search
')).'">
2647if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
2648 print '</body></html>';
if(! $sortfield) if(! $sortorder) $object
$propal type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
isALNERunningVersion($blockedlogusagealreadychecked=0, $blockedlogmoduleonalreadychecked=0)
Return if the application is executed with the LNE requirements on.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to manage members of a foundation.
const STATUS_EXCLUDED
Excluded.
Class to manage categories.
Class to manage absolute discounts.
Class to manage warehouses.
const STATUS_CLOSED
Warehouse closed, inactive.
Class to manage invoices.
const STATUS_DRAFT
Draft status.
const STATUS_VALIDATED
Validated (need to be paid)
const TYPE_CREDIT_NOTE
Credit note invoice.
const STATUS_CLOSED
Classified paid.
Class to manage stock movements.
Class to manage payments of customer invoices.
Class to manage predefined suppliers products.
Class to manage products or services.
Manage record for batch number management.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Receipt Printers.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
dol_now($mode='gmt')
Return date for now.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='', $useCache=true)
Return an id or code from a code or id.
price2num($amount, $rounding='', $option=0, $currencycode='')
Function that return a number with universal decimal format (decimal separator is '.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into JavaScript code.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTFLOAT($paramname, $rounding='', $option=2)
Return the value of a $_GET or $_POST supervariable, converted into float.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_clone($srcobject, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
get_default_tva(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that return vat rate of a product line (according to seller, buyer and product vat rate) VAT...
get_localtax($vatrate, $local, $thirdparty_buyer=null, $thirdparty_seller=null, $vatnpr=0)
Return localtax rate for a particular VAT rate, when selling a product with vat $vatrate,...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
dol_htmloutput_mesg($mesgstring='', $mesgarray=array(), $style='ok', $keepembedded=0)
Print formatted messages to output (Used to show messages on html output).
dol_htmloutput_errors($mesgstring='', $mesgarray=array(), $keepembedded=0)
Print formatted error messages to output (Used to show messages on html output).
top_htmlhead($head, $title='', $disablejs=0, $disablehead=0, $arrayofjs=array(), $arrayofcss=array(), $disableforlogin=0, $disablenofollow=0, $disablenoindex=0)
Output html header of a page.
if(!defined( 'NOREQUIREMENU')) if(!empty(GETPOST('seteventmessages', 'alpha'))) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.
if(empty( $takeposterminal)) fail($message)
Abort invoice creation with a given error message.
multi select button
0 = Do not include form tag and submit button -1 = Do not include form tag but include submit button