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) {
173 $result = $invoice->deleteLine($deletelineid);
184$number = (float)
GETPOST(
'number',
'alpha');
187$desc =
GETPOST(
'desc',
'alphanohtml');
200if ($pay ==
'cheque') {
207 $sql =
"SELECT id, code FROM ".MAIN_DB_PREFIX.
"c_paiement";
208 $sql .=
" WHERE entity IN (".getEntity(
'c_paiement').
")";
209 $sql .=
" AND code = '".$db->escape($paycode).
"'";
210 $resql = $db->query($sql);
212 $obj = $db->fetch_object($resql);
214 $paiementid = $obj->id;
221 $ret = $invoice->fetch($invoiceid);
223 $ret = $invoice->fetch(0,
'(PROV-POS'.$takeposterminal.
'-'.$place.
')');
226 $placeid = $invoice->id;
229$constforcompanyid =
'CASHDESK_ID_THIRDPARTY'.$takeposterminal;
232if ($invoice->socid > 0) {
233 $soc->fetch($invoice->socid);
240 $invoice->fk_project =
getDolGlobalInt(
"CASHDESK_ID_PROJECT".$takeposterminal);
244if (
isModEnabled(
'multicurrency') && !empty($_SESSION[
"takeposcustomercurrency"])) {
245 if ($invoice->multicurrency_code != $_SESSION[
"takeposcustomercurrency"]) {
246 $invoice->setMulticurrencyCode($_SESSION[
"takeposcustomercurrency"]);
250$term = empty($_SESSION[
"takeposterminal"]) ? 1 : $_SESSION[
"takeposterminal"];
257$parameters = array();
258$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $invoice, $action);
260 setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
264$sectionwithinvoicelink =
'';
265$CUSTOMER_DISPLAY_line1 =
'';
266$CUSTOMER_DISPLAY_line2 =
'';
276if (in_array($action, array(
'deleteline',
'updateqty',
'updateprice',
'updatereduction',
'update_reduction_global')) && !$user->hasRight(
'takepos',
'editlines')) {
282if (empty($reshook)) {
283 if ($action ==
'cloneticket' && $user->hasRight(
'takepos',
'run')) {
287 $sourceinvoice =
new Facture($db);
288 $result = $sourceinvoice->fetch($sourceinvoiceid);
289 $targetentity = !empty($_SESSION[
'takeposinvoiceentity']) ? (int) $_SESSION[
'takeposinvoiceentity'] : (int)
$conf->entity;
292 $langs->load(
'errors');
293 $clonemessage = $langs->trans(
'ErrorBadValueForParameter',
'sourceinvoiceid');
294 setEventMessages($clonemessage,
null,
'errors');
296 $cloneinvoice =
dol_clone($sourceinvoice, 1);
297 '@phan-var-force Facture $cloneinvoice';
298 $cloneinvoice->date =
dol_now();
299 $cloneid = $cloneinvoice->createFromClone($user, $sourceinvoiceid, $targetentity);
303 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"facture WHERE ref = '(PROV-POS".$db->escape((
string) $takeposterminal).
"-0)' AND entity IN (".
getEntity(
'invoice').
")";
304 $resql = $db->query($sql);
305 if ($resql && $db->num_rows($resql) > 0) {
307 $sql =
"SELECT ref FROM ".MAIN_DB_PREFIX.
"facture WHERE entity IN (".
getEntity(
'invoice').
") AND ref LIKE '(PROV-POS".$db->escape((
string) $takeposterminal).
"-0-%'";
308 $resql2 = $db->query($sql);
310 while ($obj = $db->fetch_object($resql2)) {
311 $num_sale = str_replace(
")",
"", str_replace(
"(PROV-POS".$takeposterminal.
"-0-",
"", $obj->ref));
312 if ((
int) $num_sale > $max_sale) {
313 $max_sale = (int) $num_sale;
317 $cloneplace =
'0-'.($max_sale + 1);
320 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facture";
321 $sql .=
" SET module_source = 'takepos', pos_source = '".$db->escape((
string) $takeposterminal).
"',";
322 $sql .=
" ref = '".$db->escape(
"(PROV-POS".((
string) $takeposterminal).
"-".$cloneplace.
")").
"'";
323 $sql .=
" WHERE rowid = ".((int) $cloneid);
324 $result = $db->query($sql);
327 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facturedet";
328 $sql .=
" SET batch = NULL, fk_warehouse = NULL";
329 $sql .=
" WHERE fk_facture = ".((int) $cloneid);
330 $sql .=
" AND fk_product IN (SELECT rowid FROM ".MAIN_DB_PREFIX.
"product WHERE tobatch > 0)";
331 $result = $db->query($sql);
335 if ($cloneid > 0 && $result) {
336 $place = $cloneplace;
339 $invoice->fetch($cloneid);
343 $cloneinvoice->fetch($cloneid);
344 $cloneinvoice->delete($user);
347 $langs->load(
'errors');
348 $clonemessage = !empty($cloneinvoice->error) ? $cloneinvoice->error : $langs->trans(
'ErrorFailedToCloneTicket');
349 setEventMessages($clonemessage, $cloneinvoice->errors,
'errors');
353 if (
GETPOST(
'format',
'aZ09') ==
'json') {
357 $sql =
'SELECT fd.rowid, fd.fk_product';
358 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facturedet AS fd, '.MAIN_DB_PREFIX.
'product AS p';
359 $sql .=
' WHERE fd.fk_product = p.rowid';
360 $sql .=
' AND fd.fk_facture = '.((int) $cloneid);
361 $sql .=
" AND (fd.batch IS NULL OR fd.batch = '') AND p.tobatch > 0";
362 $sql .=
' ORDER BY fd.rang, fd.rowid';
363 $sql .= $db->plimit(1);
364 $resql = $db->query($sql);
365 if ($resql && ($obj = $db->fetch_object($resql))) {
366 $batchlineid = (int) $obj->rowid;
367 $batchproductid = (int) $obj->fk_product;
372 echo json_encode(array(
'success' => $cloneid > 0,
'invoiceid' => $cloneid,
'place' => $cloneplace,
'batchlineid' => $batchlineid,
'batchproductid' => $batchproductid,
'message' => $clonemessage));
380 $sql =
"SELECT MIN(ref) as firstref FROM ".MAIN_DB_PREFIX.
"pos_cash_fence";
381 $sql .=
" WHERE entity = ".((int)
$conf->entity);
382 $sql .=
" AND posnumber = ".((int) $takeposterminal);
383 $sql .=
" AND year_close = ".((int) $tmpcurrentday[
'year']);
385 $sql .=
" (month_close IS NULL AND day_close IS NULL)";
386 $sql .=
" OR (month_close = ".((int) $tmpcurrentday[
'mon']).
" AND day_close IS NULL)";
387 $sql .=
" OR (month_close = ".((int) $tmpcurrentday[
'mon']).
" AND day_close = ".((int) $tmpcurrentday[
'mday']).
")";
389 $sql .=
" AND status = 1";
392 $resql = $db->query($sql);
394 $obj = $db->fetch_object($resql);
396 $refcashcontrol = $obj->firstref;
400 if ($refcashcontrol) {
402 $langs->load(
'errors');
403 dol_htmloutput_errors($langs->trans(
"ACashControlHasBeenclosedForCurrentDay", $refcashcontrol), [], 1);
408 if ($action ==
'valid' && $user->hasRight(
'takepos',
'run')) {
416 $bankaccount =
getDolGlobalInt(
'CASHDESK_ID_BANKACCOUNT_CASH'.$_SESSION[
"takeposterminal"]);
417 } elseif ($pay ==
"CHQ") {
418 $bankaccount =
getDolGlobalInt(
'CASHDESK_ID_BANKACCOUNT_CHEQUE'.$_SESSION[
"takeposterminal"]);
420 $accountname =
"CASHDESK_ID_BANKACCOUNT_".$pay.$_SESSION[
"takeposterminal"];
425 if ($bankaccount <= 0 && $pay !=
"delayed" &&
isModEnabled(
"bank")) {
426 $errormsg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"BankAccount"));
434 $invoice->fetch($placeid);
436 $invoice->oldcopy =
dol_clone($invoice, 2);
440 if ($invoice->total_ttc < 0) {
441 $invoice->type = $invoice::TYPE_CREDIT_NOTE;
443 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"facture";
444 $sql .=
" WHERE entity IN (".getEntity(
'invoice').
")";
445 $sql .=
" AND fk_soc = ".((int) $invoice->socid);
446 $sql .=
" AND type <> ".Facture::TYPE_CREDIT_NOTE;
447 $sql .=
" AND fk_statut >= ".$invoice::STATUS_VALIDATED;
448 $sql .=
" ORDER BY rowid DESC";
451 $resql = $db->query($sql);
453 $obj = $db->fetch_object($resql);
454 $fk_source = $obj->rowid;
455 if ((
int) $fk_source == 0) {
456 fail($langs->transnoentitiesnoconv(
"NoPreviousBillForCustomer"));
459 fail($langs->transnoentitiesnoconv(
"NoPreviousBillForCustomer"));
461 $invoice->fk_facture_source = $fk_source;
462 $invoice->update($user);
465 $constantforkey =
'CASHDESK_NO_DECREASE_STOCK'.(isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
472 $remaintopay = $invoice->getRemainToPay();
479 } elseif (count($invoice->lines) == 0) {
488 $conf->global->STOCK_CALCULATE_ON_BILL = 1;
490 $constantforkey =
'CASHDESK_ID_WAREHOUSE'.(isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
491 dol_syslog(
"Validate invoice with stock change. Warehouse defined into constant ".$constantforkey.
" = ".
getDolGlobalString($constantforkey));
496 $res = $invoice->validate($user,
'',
getDolGlobalInt($constantforkey), 0, $batch_rule);
499 $conf->global->STOCK_CALCULATE_ON_BILL = $savconst;
502 dol_syslog(
"Call validate on invoice ".$invoice->ref, LOG_DEBUG);
503 $res = $invoice->validate($user);
506 $langs->load(
"admin");
507 dol_htmloutput_errors($invoice->error ==
'NotConfigured' ? $langs->trans(
"NotConfigured").
' (TakePos numbering module)' : $invoice->error, $invoice->errors, 1);
512 if (!$error && $res >= 0) {
513 $remaintopay = $invoice->getRemainToPay();
518 $payment->datepaye = $now;
519 $payment->fk_account = $bankaccount;
524 $payment->amounts[$invoice->id] = $amountofpayment;
527 if ($amountofpayment <= 0 || $amountofpayment > $remaintopay) {
528 $payment->amounts[$invoice->id] = $remaintopay;
532 $payment->paiementid = $paiementid;
533 $payment->paiementcode = $paycode;
534 $payment->num_payment =
'';
536 if ($pay !=
"delayed") {
537 $res = $payment->create($user);
544 if (!empty($payment->warnings)) {
548 $res = $payment->addPaymentToBank($user,
'payment',
'(CustomerInvoicePayment)', $bankaccount,
'',
'');
551 dol_htmloutput_mesg($langs->trans(
'ErrorNoPaymentDefined').
' '.$payment->error, $payment->errors,
'error', 1);
554 $remaintopay = $invoice->getRemainToPay();
560 if ($remaintopay == 0) {
561 dol_syslog(
"Invoice is paid, so we set it to status Paid");
562 $result = $invoice->setPaid($user);
565 $invoice->status = $invoice::STATUS_CLOSED;
566 $invoice->close_code =
'';
569 $invoice->setPaymentMethods($paiementid);
571 dol_syslog(
"Invoice is not paid, remain to pay = ".$remaintopay);
580 if (!$error && $res >= 0) {
583 dol_syslog(
"Now we record the stock movement for each qualified line");
586 require_once DOL_DOCUMENT_ROOT .
"/product/stock/class/mouvementstock.class.php";
587 $constantforkey =
'CASHDESK_ID_WAREHOUSE'.$_SESSION[
"takeposterminal"];
590 $labeltakeposmovement =
'TakePOS - '.$langs->trans(
"Invoice").
' '.$invoice->ref;
592 foreach ($invoice->lines as $line) {
594 $warehouseid = ($line->fk_warehouse ? $line->fk_warehouse :
getDolGlobalInt($constantforkey));
597 if ($line->batch !=
'' && $warehouseid > 0) {
599 $prod_batch->find(0,
'',
'', $line->batch, $warehouseid, (
int) $line->fk_product);
602 $mouvP->setOrigin($invoice->element, $invoice->id);
605 $res = $mouvP->reception($user, $line->fk_product, $warehouseid, $line->qty, $line->price, $labeltakeposmovement,
'',
'', $line->batch,
'', 0, $inventorycode);
607 $res = $mouvP->livraison($user, $line->fk_product, $warehouseid, $line->qty, $line->price, $labeltakeposmovement,
'',
'',
'', $prod_batch->batch, $prod_batch->id, $inventorycode);
616 $mouvP->setOrigin($invoice->element, $invoice->id);
619 $res = $mouvP->reception($user, $line->fk_product, $warehouseid, $line->qty, $line->price, $labeltakeposmovement,
'',
'',
'',
'', 0, $inventorycode);
621 $res = $mouvP->livraison($user, $line->fk_product, $warehouseid, $line->qty, $line->price, $labeltakeposmovement,
'',
'',
'',
'', 0, $inventorycode);
633 if (!$error && $res >= 0) {
636 $invoice->ref = $invoice->oldcopy->ref;
637 $invoice->paye = $invoice->oldcopy->paye;
638 $invoice->status = $invoice->oldcopy->status;
639 $invoice->statut = $invoice->oldcopy->statut;
646 if ($action ==
'creditnote' && $user->hasRight(
'takepos',
'run')) {
649 $creditnote =
new Facture($db);
650 $creditnote->socid = $invoice->socid;
652 $creditnote->module_source =
'takepos';
653 $creditnote->pos_source = isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'' ;
655 $creditnote->fk_facture_source = $placeid;
657 $creditnote->create($user);
661 foreach ($invoice->lines as $line) {
663 if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) {
668 if (!empty($invoice->situation_counter)) {
669 $source_fk_prev_id = $line->fk_prev_id;
670 $line->fk_prev_id = $line->id;
671 if (!empty($invoice->tab_previous_situation_invoice)) {
674 $tab_jumped_credit_notes = array();
675 $lineIndex = count($invoice->tab_previous_situation_invoice) - 1;
676 $searchPreviousInvoice =
true;
677 while ($searchPreviousInvoice) {
678 if ($invoice->tab_previous_situation_invoice[$lineIndex]->situation_cycle_ref || $lineIndex < 1) {
679 $searchPreviousInvoice =
false;
683 $tab_jumped_credit_notes[$lineIndex] = $invoice->tab_previous_situation_invoice[$lineIndex]->id;
689 $maxPrevSituationPercent = 0;
690 foreach ($invoice->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine) {
691 if ($prevLine->id == $source_fk_prev_id) {
692 $maxPrevSituationPercent = max($maxPrevSituationPercent, $prevLine->situation_percent);
695 $line->total_ht -= $prevLine->total_ht;
696 $line->total_tva -= $prevLine->total_tva;
697 $line->total_ttc -= $prevLine->total_ttc;
698 $line->total_localtax1 -= $prevLine->total_localtax1;
699 $line->total_localtax2 -= $prevLine->total_localtax2;
701 $line->multicurrency_subprice -= $prevLine->multicurrency_subprice;
702 $line->multicurrency_total_ht -= $prevLine->multicurrency_total_ht;
703 $line->multicurrency_total_tva -= $prevLine->multicurrency_total_tva;
704 $line->multicurrency_total_ttc -= $prevLine->multicurrency_total_ttc;
709 $line->situation_percent = $maxPrevSituationPercent - $line->situation_percent;
714 $maxPrevSituationPercent = 0;
715 foreach ($tab_jumped_credit_notes as $index => $creditnoteid) {
716 foreach ($invoice->tab_previous_situation_invoice[$index]->lines as $prevLine) {
717 if ($prevLine->fk_prev_id == $source_fk_prev_id) {
718 $maxPrevSituationPercent = $prevLine->situation_percent;
720 $line->total_ht -= $prevLine->total_ht;
721 $line->total_tva -= $prevLine->total_tva;
722 $line->total_ttc -= $prevLine->total_ttc;
723 $line->total_localtax1 -= $prevLine->total_localtax1;
724 $line->total_localtax2 -= $prevLine->total_localtax2;
726 $line->multicurrency_subprice -= $prevLine->multicurrency_subprice;
727 $line->multicurrency_total_ht -= $prevLine->multicurrency_total_ht;
728 $line->multicurrency_total_tva -= $prevLine->multicurrency_total_tva;
729 $line->multicurrency_total_ttc -= $prevLine->multicurrency_total_ttc;
735 $line->situation_percent += $maxPrevSituationPercent;
743 $line->fk_facture = $creditnote->id;
744 $line->fk_parent_line = $fk_parent_line;
746 $line->subprice = -$line->subprice;
748 $line->total_ht = -$line->total_ht;
749 $line->total_tva = -$line->total_tva;
750 $line->total_ttc = -$line->total_ttc;
751 $line->total_localtax1 = -$line->total_localtax1;
752 $line->total_localtax2 = -$line->total_localtax2;
754 $line->multicurrency_subprice = -$line->multicurrency_subprice;
755 $line->multicurrency_total_ht = -$line->multicurrency_total_ht;
756 $line->multicurrency_total_tva = -$line->multicurrency_total_tva;
757 $line->multicurrency_total_ttc = -$line->multicurrency_total_ttc;
759 $result = $line->insert(0, 1);
761 $creditnote->lines[] = $line;
764 if ($result > 0 && $line->product_type == 9) {
765 $fk_parent_line = $result;
768 $creditnote->update_price(1);
776 $constantforkey =
'CASHDESK_NO_DECREASE_STOCK'.(isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
781 $conf->global->STOCK_CALCULATE_ON_BILL = 1;
783 $constantforkey =
'CASHDESK_ID_WAREHOUSE'.(isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
786 dol_syslog(
"Validate invoice with stock change into warehouse defined into constant ".$constantforkey.
" = ".
getDolGlobalString($constantforkey).
" or warehouseid= ".$warehouseid.
" if defined.");
789 $res = $creditnote->validate($user,
'', $warehouseid, 0, $batch_rule);
796 $conf->global->STOCK_CALCULATE_ON_BILL = $savconst;
798 $res = $creditnote->validate($user);
802 if (!$error && $res >= 0) {
804 dol_syslog(
"Now we record the stock movement for each qualified line");
806 require_once DOL_DOCUMENT_ROOT .
"/product/stock/class/mouvementstock.class.php";
807 $constantforkey =
'CASHDESK_ID_WAREHOUSE'.(isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
809 $labeltakeposmovement =
'TakePOS - '.$langs->trans(
"CreditNote").
' '.$creditnote->ref;
811 foreach ($creditnote->lines as $line) {
813 $warehouseid = ($line->fk_warehouse ? $line->fk_warehouse :
getDolGlobalInt($constantforkey));
816 $mouvP->setOrigin($creditnote->element, $creditnote->id);
818 $batch_to_use = ($line->batch !=
'' && $warehouseid > 0) ? $line->batch :
'';
820 $res = $mouvP->reception($user, $line->fk_product, $warehouseid, $line->qty, $line->price, $labeltakeposmovement,
'',
'', $batch_to_use,
'', 0, $inventorycode);
833 $creditnote->id = $placeid;
838 if (($action ==
'history' || $action ==
'creditnote') && $user->hasRight(
'takepos',
'run')) {
839 if ($action ==
'creditnote' && $creditnote !==
null && $creditnote->id > 0) {
840 $placeid = $creditnote->id;
846 $invoice->fetch($placeid);
850 if (($action ==
"addline" || $action ==
"freezone") && $placeid == 0 && ($user->hasRight(
'takepos',
'run') || defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
853 $dolnowtzuserrel =
dol_now(
'tzuserrel');
857 $dateinvoice =
dol_mktime(0, 0, 0, (
int) $monthuser, (
int) $dayuser, (
int) $yearuser,
'tzserver');
859 include_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
860 $invoice->date = $dateinvoice;
874 $invoice->module_source =
'takepos';
875 $invoice->pos_source = isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'' ;
876 $invoice->entity = !empty($_SESSION[
"takeposinvoiceentity"]) ? $_SESSION[
"takeposinvoiceentity"] :
$conf->entity;
878 if ($invoice->socid <= 0) {
879 $langs->load(
'errors');
885 $placeid = $invoice->create($user);
891 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facture";
892 $sql .=
" SET ref='(PROV-POS".$_SESSION[
"takeposterminal"].
"-".$place.
")'";
893 $sql .=
" WHERE rowid = ".((int) $placeid);
894 $resql = $db->query($sql);
910 if ($action ==
"addline" && ($user->hasRight(
'takepos',
'run') || defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
912 $prod->fetch($idproduct);
915 $customer->fetch($invoice->socid);
917 $datapriceofproduct =
$prod->getSellPrice(
$mysoc, $customer, 0);
920 $price = $datapriceofproduct[
'pu_ht'];
921 $price_ttc = $datapriceofproduct[
'pu_ttc'];
923 $price_base_type = empty($datapriceofproduct[
'price_base_type']) ?
'HT' : $datapriceofproduct[
'price_base_type'];
924 $tva_tx = $datapriceofproduct[
'tva_tx'];
925 $tva_npr = (int) $datapriceofproduct[
'tva_npr'];
933 $batch =
GETPOST(
'batch',
'alpha');
935 if (!empty($batch)) {
936 $action =
"setbatch";
937 } elseif (
$prod->status_batch > 0) {
942 $prod->load_stock(
'warehouseopen');
944 $constantforkey =
'CASHDESK_ID_WAREHOUSE'.$_SESSION[
"takeposterminal"];
948 foreach (
$prod->stock_warehouse as $tmpwarehouseid => $tmpval) {
953 if (!empty(
$prod->stock_warehouse[$tmpwarehouseid]) && is_array(
$prod->stock_warehouse[$tmpwarehouseid]->detail_batch)) {
954 if (is_object(
$prod->stock_warehouse[$tmpwarehouseid]) && count(
$prod->stock_warehouse[$tmpwarehouseid]->detail_batch)) {
955 foreach (
$prod->stock_warehouse[$tmpwarehouseid]->detail_batch as $dbatch) {
964 echo
"function addbatch(batch, warehouseid) {\n";
965 echo
"console.log('We add batch '+batch+' from warehouse id '+warehouseid);\n";
966 echo
'$("#poslines").load("'.DOL_URL_ROOT.
'/takepos/invoice.php?action=addline&batch="+encodeURIComponent(batch)+"&warehouseid="+warehouseid+"&place='.$place.
'&idproduct='.$idproduct.
'&token='.
newToken().
'", function() {});'.
"\n";
971 echo
"<center>".$langs->trans(
"SearchIntoBatch").
": <b> $nbofsuggested </b></center><br><table>";
972 foreach (
$prod->stock_warehouse as $tmpwarehouseid => $tmpval) {
977 if (!empty(
$prod->stock_warehouse[$tmpwarehouseid]) && is_array(
$prod->stock_warehouse[$tmpwarehouseid]->detail_batch)) {
978 foreach (
$prod->stock_warehouse[$tmpwarehouseid]->detail_batch as $dbatch) {
979 $batchStock = + $dbatch->qty;
980 $quantityToBeDelivered = 1;
981 $deliverableQty = min($quantityToBeDelivered, $batchStock);
983 print
'<!-- subj='.$suggestednb.
'/'.$nbofsuggested.
' -->';
984 print
'<!-- Show details of lot/serial in warehouseid='.$tmpwarehouseid.
' -->';
985 print
'<td class="left">';
987 $detail .=
'<span class="opacitymedium">'.$langs->trans(
"LotSerial").
':</span> '.$dbatch->batch;
994 $detail .=
'</td><td>';
995 $detail .=
'<span class="opacitymedium">'.$langs->trans(
"Qty").
':</span> '.$dbatch->qty;
996 $detail .=
'</td><td>';
997 $detail .=
' <button class="marginleftonly" onclick="addbatch(\''.dol_escape_js($dbatch->batch).
'\',
'.$tmpwarehouseid.')
">'.$langs->trans("Select
")."</
button>
";
1001 $quantityToBeDelivered -= $deliverableQty;
1002 if ($quantityToBeDelivered < 0) {
1003 $quantityToBeDelivered = 0;
1011 if ($nbofsuggested == 0) {
1012 // Add manual entry for returns or new batches when stock is 0
1013 print '<tr><td class="left
" style="padding-top: 10px; border-top: 1px solid #ddd; text-align: center;
">';
1014 print '<span class="opacitymedium
">'.$langs->trans("LotSerial
").' (Manual) :</span> ';
1015 print '<input type="text
" id="manual_batch_add
" class="flat
" size="10
"> ';
1016 print '<button class="button" onclick="addbatch(document.getElementById(\
'manual_batch_add\').value, '.$warehouseid.
')">'.$langs->trans(
"Add").
'</button>';
1022 print
'</body></html>';
1029 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1031 $categories = $cat->containing($idproduct,
'product');
1032 $found = (array_search(
getDolGlobalInt(
'TAKEPOS_SUPPLEMENTS_CATEGORY'), array_column($categories,
'id')));
1033 if ($found !==
false) {
1034 $sql =
"SELECT fk_parent_line FROM ".MAIN_DB_PREFIX.
"facturedet where rowid = ".((int) $selectedline);
1035 $resql = $db->query($sql);
1036 $row = $db->fetch_array($resql);
1037 if ($row[0] ==
null) {
1038 $parent_line = $selectedline;
1040 $parent_line = $row[0];
1048 foreach ($invoice->lines as $line) {
1049 if ($line->product_ref ==
$prod->ref) {
1050 if ($line->special_code == 4) {
1055 $invoice->error = $langs->trans(
"ErrorStockIsNotEnough");
1060 $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);
1064 $idoflineadded = $line->id;
1070 if ($idoflineadded <= 0 && empty($err)) {
1071 $invoice->fetch_thirdparty();
1072 $array_options = array();
1074 $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);
1079 $line[
'fk_fournprice'] =
null;
1080 $line[
'pa_ht'] =
$prod->pmp;
1082 $line[
'fk_fournprice'] =
null;
1083 $line[
'pa_ht'] =
$prod->cost_price;
1086 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
1088 if ($pf->find_min_price_product_fournisseur($idproduct, $qty) > 0) {
1089 $line[
'fk_fournprice'] = $pf->product_fourn_price_id;
1090 $line[
'pa_ht'] = $pf->fourn_unitprice_with_discount;
1092 $line[
'pa_ht'] += (float) $pf->fourn_charges / $pf->fourn_qty;
1099 $parameters = array(
'prod' =>
$prod,
'line' => $line);
1100 $reshook = $hookmanager->executeHooks(
'completeTakePosAddLine', $parameters, $invoice, $action);
1102 setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
1106 if (empty($reshook)) {
1107 if (!empty($hookmanager->resArray)) {
1108 $line = $hookmanager->resArray;
1113 $invoice->error = $langs->trans(
"ErrorStockIsNotEnough");
1119 $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);
1124 $CUSTOMER_DISPLAY_line1 =
$prod->label;
1125 $CUSTOMER_DISPLAY_line2 =
price($price_ttc);
1129 $invoice->fetch($placeid);
1133 if ($action ==
"freezone" && $user->hasRight(
'takepos',
'run')) {
1135 $customer->fetch($invoice->socid);
1137 $tva_tx =
GETPOST(
'tva_tx',
'alpha');
1138 if ($tva_tx !=
'') {
1139 if (!preg_match(
'/\((.*)\)/', $tva_tx)) {
1150 $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);
1154 $invoice->fetch($placeid);
1157 if ($action ==
"addnote" && ($user->hasRight(
'takepos',
'run') || defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
1158 $desc =
GETPOST(
'addnote',
'alpha');
1160 $invoice->update_note($desc,
'_public');
1162 foreach ($invoice->lines as $line) {
1163 if ($line->id == $idline) {
1164 $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);
1168 $invoice->fetch($placeid);
1171 if ($action ==
"deleteline" && ($user->hasRight(
'takepos',
'editlines') || defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
1183 if ($idline > 0 && $placeid > 0) {
1184 $result = takeposDeleteLineWithChildren($invoice, $idline);
1188 $invoice->fetch($placeid);
1189 } elseif ($placeid > 0) {
1190 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"facturedet where fk_facture = ".((int) $placeid).
" ORDER BY rowid DESC";
1191 $resql = $db->query($sql);
1192 $obj = $db->fetch_object($resql);
1194 $deletelineid = $obj->rowid;
1195 $result = takeposDeleteLineWithChildren($invoice, $deletelineid);
1200 $invoice->fetch($placeid);
1205 if (count($invoice->lines) == 0) {
1210 $defaultsocid = (int)
getDolGlobalString(
'CASHDESK_ID_THIRDPARTY'.$_SESSION[
"takeposterminal"]);
1211 $invoicesocid = (int) $invoice->socid;
1212 if ($invoicesocid === 0 || $invoicesocid === $defaultsocid) {
1213 $invoice->delete($user);
1215 if (defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1216 header(
"Location: ".DOL_URL_ROOT.
"/takepos/public/auto_order.php");
1218 header(
"Location: ".DOL_URL_ROOT.
"/takepos/invoice.php");
1226 if ($action ==
"delete" && ($user->hasRight(
'takepos',
'run') || defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
1230 $result = $invoice->fetch($placeid);
1236 $resdeletelines = 1;
1237 foreach ($invoice->lines as $line) {
1239 $tmpres = $invoice->deleteLine($line->id);
1241 $resdeletelines = 0;
1246 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facture";
1247 $varforconst =
'CASHDESK_ID_THIRDPARTY'.$_SESSION[
"takeposterminal"];
1249 $sql .=
" datec = '".$db->idate(
dol_now()).
"'";
1250 $sql .=
" WHERE entity IN (".getEntity(
'invoice').
")";
1251 $sql .=
" AND ref = '(PROV-POS".$db->escape($_SESSION[
"takeposterminal"].
"-".$place).
")'";
1252 $resql1 = $db->query($sql);
1254 if ($resdeletelines && $resql1) {
1260 $invoice->fetch($placeid);
1267 if ($action ==
"discardsale" && ($user->hasRight(
'takepos',
'run') || defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
1269 $result = $invoice->fetch($placeid);
1271 $invoice->delete($user);
1277 if ($action ==
"updateqty") {
1278 foreach ($invoice->lines as $line) {
1279 if ($line->id == $idline) {
1280 $permissiontoupdateline = ($user->hasRight(
'takepos',
'editlines') && ($user->hasRight(
'takepos',
'editorderedlines') || $line->special_code !=
"4"));
1281 if (defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1282 if ($invoice->status == $invoice::STATUS_DRAFT && $invoice->pos_source && $invoice->module_source ==
'takepos') {
1283 $permissiontoupdateline =
true;
1288 if (!$permissiontoupdateline) {
1289 dol_htmloutput_errors($langs->trans(
"NotEnoughPermissions",
"TakePos").
' - No permission to updateqty', [], 1);
1292 $result = takeposDeleteLineWithChildren($invoice, $line->id);
1297 $vatratecode = $line->tva_tx;
1298 if ($line->vat_src_code) {
1299 $vatratecode .=
' ('.$line->vat_src_code.
')';
1302 $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);
1308 $invoice->fetch($placeid);
1311 if ($action ==
"updateprice") {
1313 $customer->fetch($invoice->socid);
1315 foreach ($invoice->lines as $line) {
1316 if ($line->id == $idline) {
1318 $prod->fetch($line->fk_product);
1319 $datapriceofproduct =
$prod->getSellPrice(
$mysoc, $customer, 0);
1320 $price_min = $datapriceofproduct[
'price_min'];
1321 $usercanproductignorepricemin = ((
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !$user->hasRight(
'produit',
'ignore_price_min_advance')) || !
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS'));
1323 $vatratecleaned = $line->tva_tx;
1325 if (preg_match(
'/^(.*)\s*\((.*)\)$/', (
string) $line->tva_tx, $reg)) {
1326 $vatratecleaned = trim($reg[1]);
1330 $pu_ht =
price2num((
float)
price2num($number,
'MU') / (1 + ((
float) $vatratecleaned / 100)),
'MU');
1332 if ($usercanproductignorepricemin && (!empty($price_min) && ((
float)
price2num($pu_ht) * (1 - (
float)
price2num($line->remise_percent) / 100) <
price2num($price_min)))) {
1333 $langs->load(
"products");
1337 $permissiontoupdateline = ($user->hasRight(
'takepos',
'editlines') && ($user->hasRight(
'takepos',
'editorderedlines') || $line->special_code !=
"4"));
1338 if (defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1339 if ($invoice->status == $invoice::STATUS_DRAFT && $invoice->pos_source && $invoice->module_source ==
'takepos') {
1340 $permissiontoupdateline =
true;
1346 $vatratecode = $line->tva_tx;
1347 if ($line->vat_src_code) {
1348 $vatratecode .=
' ('.$line->vat_src_code.
')';
1351 if (!$permissiontoupdateline) {
1352 dol_htmloutput_errors($langs->trans(
"NotEnoughPermissions",
"TakePos").
' - No permission to updateprice', [], 1);
1354 $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);
1356 $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);
1363 $invoice->fetch($placeid);
1366 if ($action ==
"updatereduction") {
1368 $customer->fetch($invoice->socid);
1370 foreach ($invoice->lines as $line) {
1371 if ($line->id == $idline) {
1372 dol_syslog(
"updatereduction Process line ".$line->id.
' to apply discount of '.$number.
'%');
1375 $prod->fetch($line->fk_product);
1377 $datapriceofproduct =
$prod->getSellPrice(
$mysoc, $customer, 0);
1378 $price_min = $datapriceofproduct[
'price_min'];
1379 $usercanproductignorepricemin = ((
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !$user->hasRight(
'produit',
'ignore_price_min_advance')) || !
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS'));
1381 $pu_ht =
price2num($line->subprice / (1 + ($line->tva_tx / 100)),
'MU');
1384 if ($usercanproductignorepricemin && (!empty($price_min) && ((
float)
price2num($line->subprice) * (1 - (
float)
price2num($number) / 100) < (
float)
price2num($price_min)))) {
1385 $langs->load(
"products");
1388 $permissiontoupdateline = ($user->hasRight(
'takepos',
'editlines') && ($user->hasRight(
'takepos',
'editorderedlines') || $line->special_code !=
"4"));
1389 if (defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1390 if ($invoice->status == $invoice::STATUS_DRAFT && $invoice->pos_source && $invoice->module_source ==
'takepos') {
1391 $permissiontoupdateline =
true;
1396 if (!$permissiontoupdateline) {
1399 $vatratecode = $line->tva_tx;
1400 if ($line->vat_src_code) {
1401 $vatratecode .=
' ('.$line->vat_src_code.
')';
1403 $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);
1410 $invoice->fetch($placeid);
1411 } elseif ($action ==
'update_reduction_global' && $user->hasRight(
'takepos',
'editlines')) {
1412 foreach ($invoice->lines as $line) {
1413 $vatratecode = $line->tva_tx;
1414 if ($line->vat_src_code) {
1415 $vatratecode .=
' ('.$line->vat_src_code.
')';
1417 $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);
1420 $invoice->fetch($placeid);
1423 if ($action ==
"editbatch_popup" && ($user->hasRight(
'takepos',
'run') || defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
1427 $prod->fetch($idproduct);
1428 $prod->load_stock(
'warehouseopen');
1430 $constantforkey =
'CASHDESK_ID_WAREHOUSE'.$_SESSION[
"takeposterminal"];
1433 print
'<html><body>';
1434 print
'<div class="divscroll">';
1435 print
'<div class="marginbottomonly"><b>'.dolPrintLabel(
$prod->label).
'</b>'.(!empty(
$prod->ref) ?
' <span class="opacitymedium">('.dolPrintLabel(
$prod->ref).
')</span>' :
'').
'</div>';
1436 print
'<table class="noborder">';
1439 if (is_array(
$prod->stock_warehouse)) {
1440 foreach (
$prod->stock_warehouse as $tmpwarehouseid => $tmpval) {
1444 if (!empty(
$prod->stock_warehouse[$tmpwarehouseid]) && is_array(
$prod->stock_warehouse[$tmpwarehouseid]->detail_batch)) {
1445 foreach (
$prod->stock_warehouse[$tmpwarehouseid]->detail_batch as $dbatch) {
1447 $detail .=
'<span class="opacitymedium">'.$langs->trans(
"LotSerial").
':</span> '.$dbatch->batch;
1448 $detail .=
' <span class="opacitymedium">'.$langs->trans(
"Qty").
':</span> '.$dbatch->qty;
1449 $detail .=
' <button class="marginleftonly" onclick="updatebatch(\''.dol_escape_js($dbatch->batch).
'\',
'.$tmpwarehouseid.',
'.$idline.',
'.((int) $clonebatch).')
">'.$langs->trans("Select
")."</
button>
";
1451 print '<tr><td class="left
">'.$detail;
1458 if ($nbofsuggested == 0) {
1459 print '<tr><td class="left
">'.$langs->trans("NoRecordFound
").'</td></tr>';
1462 // Add manual entry for returns or new batches
1463 print '<tr><td class="left
" style="padding-top: 10px; border-top: 1px solid #ddd;
">';
1464 print '<span class="opacitymedium
">'.$langs->trans("LotSerial
").' (Manual) :</span> ';
1465 print '<input type="text
" id="manual_batch
" class="flat
" size="10
"> ';
1466 print '<button class="button" onclick="updatebatch(document.getElementById(\
'manual_batch\').value, '.$warehouseid.
', '.$idline.
', '.((
int) $clonebatch).
')">'.$langs->trans(
"Add").
'</button>';
1467 print
' <button type="button" class="button button-cancel" onclick="$(\'#poslines\').load(\'invoice.php?place=\'+place+\'&invoiceid=\'+invoiceid);">'.$langs->trans(
"Cancel").
'</button>';
1471 print
'</div></body></html>';
1475 if ($action ==
"setbatch" && ($user->hasRight(
'takepos',
'run') || defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
1476 $constantforkey =
'CASHDESK_ID_WAREHOUSE'.$_SESSION[
"takeposterminal"];
1478 $idline = (empty($idoflineadded) ?
GETPOSTINT(
'idline') : $idoflineadded);
1479 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facturedet SET batch = '".$db->escape($batch).
"', fk_warehouse = ".((int) $warehouseid);
1480 $sql .=
" WHERE rowid = ".((int) $idline).
" AND fk_facture = ".((int) $placeid);
1484 $invoice->fetch($placeid);
1487 $sql =
'SELECT fd.rowid, fd.fk_product';
1488 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facturedet AS fd, '.MAIN_DB_PREFIX.
'product AS p';
1489 $sql .=
' WHERE fd.fk_product = p.rowid';
1490 $sql .=
' AND fd.fk_facture = '.((int) $placeid);
1491 $sql .=
" AND (fd.batch IS NULL OR fd.batch = '') AND p.tobatch > 0";
1492 $sql .=
' ORDER BY fd.rang, fd.rowid';
1493 $sql .= $db->plimit(1);
1494 $resql = $db->query($sql);
1495 if ($resql && ($obj = $db->fetch_object($resql))) {
1496 print
'<script>editbatch('.((int) $obj->rowid).
', '.((int) $obj->fk_product).
', 1);</script>';
1502 if ($action ==
"order" && $placeid != 0 && ($user->hasRight(
'takepos',
'run') || defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
1503 include_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1505 require_once DOL_DOCUMENT_ROOT.
'/takepos/class/dolreceiptprinter.class.php';
1509 $sql =
"SELECT label FROM ".MAIN_DB_PREFIX.
"takepos_floor_tables where rowid = ".((int) $place);
1510 $resql = $db->query($sql);
1511 $row = $db->fetch_object($resql);
1512 $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>';
1513 $footerorder =
'</tbody></table>'.dol_print_date(
dol_now(),
'dayhour').
'<br></html>';
1514 $order_receipt_printer1 =
"";
1515 $order_receipt_printer2 =
"";
1516 $order_receipt_printer3 =
"";
1521 foreach ($invoice->lines as $line) {
1522 if ($line->special_code ==
"4") {
1526 $existing =
$c->containing($line->fk_product, Categorie::TYPE_PRODUCT,
'id');
1527 $result = array_intersect($catsprinter1, $existing);
1528 $count = count($result);
1529 if (!$line->fk_product) {
1534 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facturedet set special_code='1' where rowid = ".((int) $line->id);
1536 $order_receipt_printer1 .=
'<tr><td class="left">';
1537 if ($line->fk_product) {
1538 $order_receipt_printer1 .= $line->product_label;
1540 $order_receipt_printer1 .= $line->description;
1542 $order_receipt_printer1 .=
'</td><td class="right">'.$line->qty;
1543 if (!empty($line->array_options[
'options_order_notes'])) {
1544 $order_receipt_printer1 .=
"<br>(".$line->array_options[
'options_order_notes'].
")";
1546 $order_receipt_printer1 .=
'</td></tr>';
1550 $invoice->fetch($placeid);
1551 $printer->orderprinter = 1;
1553 echo
"var orderprinter1esc='";
1554 $ret = $printer->sendToPrinter($invoice,
getDolGlobalInt(
'TAKEPOS_TEMPLATE_TO_USE_FOR_ORDERS'.$_SESSION[
"takeposterminal"]),
getDolGlobalInt(
'TAKEPOS_ORDER_PRINTER1_TO_USE'.$_SESSION[
"takeposterminal"]));
1557 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facturedet set special_code='4' where special_code='1' and fk_facture = ".((int) $invoice->id);
1559 $invoice->fetch($placeid);
1562 foreach ($invoice->lines as $line) {
1563 if ($line->special_code ==
"4") {
1567 $existing =
$c->containing($line->fk_product, Categorie::TYPE_PRODUCT,
'id');
1568 $result = array_intersect($catsprinter2, $existing);
1569 $count = count($result);
1572 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facturedet set special_code='2' where rowid = ".((int) $line->id);
1574 $order_receipt_printer2 .=
'<tr>'.$line->product_label.
'<td class="right">'.$line->qty;
1575 if (!empty($line->array_options[
'options_order_notes'])) {
1576 $order_receipt_printer2 .=
"<br>(".$line->array_options[
'options_order_notes'].
")";
1578 $order_receipt_printer2 .=
'</td></tr>';
1582 $invoice->fetch($placeid);
1583 $printer->orderprinter = 2;
1585 echo
"var orderprinter2esc='";
1586 $ret = $printer->sendToPrinter($invoice,
getDolGlobalInt(
'TAKEPOS_TEMPLATE_TO_USE_FOR_ORDERS'.$_SESSION[
"takeposterminal"]),
getDolGlobalInt(
'TAKEPOS_ORDER_PRINTER2_TO_USE'.$_SESSION[
"takeposterminal"]));
1589 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facturedet set special_code='4' where special_code='2' and fk_facture = ".((int) $invoice->id);
1591 $invoice->fetch($placeid);
1594 foreach ($invoice->lines as $line) {
1595 if ($line->special_code ==
"4") {
1599 $existing =
$c->containing($line->fk_product, Categorie::TYPE_PRODUCT,
'id');
1600 $result = array_intersect($catsprinter3, $existing);
1601 $count = count($result);
1604 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facturedet set special_code='3' where rowid = ".((int) $line->id);
1606 $order_receipt_printer3 .=
'<tr>'.$line->product_label.
'<td class="right">'.$line->qty;
1607 if (!empty($line->array_options[
'options_order_notes'])) {
1608 $order_receipt_printer3 .=
"<br>(".$line->array_options[
'options_order_notes'].
")";
1610 $order_receipt_printer3 .=
'</td></tr>';
1614 $invoice->fetch($placeid);
1615 $printer->orderprinter = 3;
1617 echo
"var orderprinter3esc='";
1618 $ret = $printer->sendToPrinter($invoice,
getDolGlobalInt(
'TAKEPOS_TEMPLATE_TO_USE_FOR_ORDERS'.$_SESSION[
"takeposterminal"]),
getDolGlobalInt(
'TAKEPOS_ORDER_PRINTER3_TO_USE'.$_SESSION[
"takeposterminal"]));
1621 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facturedet set special_code='4' where special_code='3' and fk_facture = ".((int) $invoice->id);
1623 $invoice->fetch($placeid);
1626 $sectionwithinvoicelink =
'';
1627 if (($action ==
"valid" || $action ==
"history" || $action ==
'creditnote' || ($action ==
'addline' && $invoice->status == $invoice::STATUS_CLOSED)) && $user->hasRight(
'takepos',
'run')) {
1628 $sectionwithinvoicelink .=
'<!-- Section with invoice link -->'.
"\n";
1629 $sectionwithinvoicelink .=
'<span style="font-size:120%;" class="center inline-block marginbottomonly">';
1630 if ($invoice->status == $invoice::STATUS_DRAFT) {
1631 $sectionwithinvoicelink .= $invoice->ref;
1633 $sectionwithinvoicelink .= $invoice->getNomUrl(1,
'', 0, 0,
'', 0, 0, -1,
'_backoffice');
1635 $sectionwithinvoicelink .=
" - ";
1636 $remaintopay = $invoice->getRemainToPay();
1637 if ($remaintopay > 0) {
1638 $sectionwithinvoicelink .= $langs->trans(
'RemainToPay').
': <span class="amountremaintopay" style="font-size: unset">'.
price($remaintopay, 1, $langs, 1, -1, -1,
$conf->currency).
'</span>';
1640 $sectionwithinvoicelink .= $invoice->getLibStatut(2);
1643 $sectionwithinvoicelink .=
'</span><br>';
1645 $customprinterallowed =
false;
1646 $customprinttemplateallowed =
true;
1651 $customprinterallowed =
true;
1652 $customprinttemplateallowed =
true;
1655 include_once DOL_DOCUMENT_ROOT.
'/blockedlog/lib/blockedlog.lib.php';
1658 $customprinttemplateallowed =
false;
1661 if ($invoice->status == $invoice::STATUS_CLOSED) {
1662 if (
getDolGlobalInt(
'TAKEPOS_PRINT_INVOICE_DOC_INSTEAD_OF_RECEIPT')) {
1663 $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>';
1670 $sectionwithinvoicelink .=
' <button id="buttonprint" type="button" onclick="PrintByESCPOSOld('.$placeid.
')">'.$langs->trans(
'PrintTicket').
'</button>';
1674 $sectionwithinvoicelink .=
' <button id="buttonprint" type="button" onclick="PrintHTMLToSlashPrint('.$placeid.
')">'.$langs->trans(
'PrintTicket').
'</button>';
1676 } elseif ($customprinterallowed && $customprinttemplateallowed && (
isModEnabled(
'receiptprinter') &&
getDolGlobalInt(
'TAKEPOS_PRINTER_TO_USE'.$term) > 0) ||
getDolGlobalString(
'TAKEPOS_PRINT_METHOD') ==
"receiptprinter") {
1679 $sectionwithinvoicelink .=
' <button id="buttonprint" type="button" onclick="PrintByESCPOS('.$placeid.
')" title="'.dolPrintHTMLForAttribute($langs->trans(
"SentToPrinter").
' '.$nameOfPrinter).
'">'.$langs->trans(
'PrintTicket').
'</button>';
1682 $sectionwithinvoicelink .=
' <button id="buttonprint" type="button" onclick="PrintByBrowser('.$placeid.
')">'.$langs->trans(
'PrintTicket').
'</button>';
1685 if ($customprinttemplateallowed &&
getDolGlobalString(
'TAKEPOS_PRINT_WITHOUT_DETAILS')) {
1686 $sectionwithinvoicelink .=
' <button id="buttonprint" type="button" onclick="PrintBox('.$placeid.
', \'without_details\')">'.$langs->trans(
'PrintWithoutDetails').
'</button>';
1689 $sectionwithinvoicelink .=
' <button id="buttonprint" type="button" onclick="PrintByBrowser('.$placeid.
', 1)">'.$langs->trans(
'GiftReceipt').
'</button>';
1694 $sectionwithinvoicelink .=
' <button id="buttonsend" type="button" onclick="SendTicket('.$placeid.
')">'.$langs->trans(
'SendTicket').
'</button>';
1697 if ($remaintopay <= 0 &&
getDolGlobalString(
'TAKEPOS_AUTO_PRINT_TICKETS') && $action !=
"history") {
1698 $sectionwithinvoicelink .=
'<script type="text/javascript">console.log("Emulate click on #buttonprint"); $("#buttonprint").click();</script>';
1709$form =
new Form($db);
1712if (defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1713 $title =
'TakePOS - Dolibarr '.DOL_VERSION;
1717 $head =
'<meta name="apple-mobile-web-app-title" content="TakePOS"/>
1718 <meta name="apple-mobile-web-app-capable" content="yes">
1719 <meta name="mobile-web-app-capable" content="yes">
1720 <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>';
1721 $arrayofcss = array(
1722 '/takepos/css/pos.css.php',
1724 $arrayofjs = array(
'/takepos/js/jquery.colorbox-min.js');
1727 top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss);
1729 print
'<body>'.
"\n";
1736<script
type=
"text/javascript">
1739<?php
if ($action ==
"valid") {
1740 echo
"var place=0;";
1742var placeid=<?php echo($placeid > 0 ? $placeid : 0); ?>;
1743$(document).ready(
function() {
1744 var idoflineadded = <?php echo(empty($idoflineadded) ? 0 : $idoflineadded); ?>;
1746 $(
'.posinvoiceline').click(
function(){
1747 console.log(
"Click done on "+this.
id);
1748 $(
'.posinvoiceline').removeClass(
"selected");
1749 $(
this).addClass(
"selected");
1753 if (selectedline == this.
id) {
1756 selectedline = this.id;
1758 selectedtext=$(
'#'+selectedline).find(
"td:first").html();
1760 if (defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1761 print
'$("#phonediv1").load("'.DOL_URL_ROOT.
'/takepos/public/auto_order.php?action=editline&token='.
newToken().
'&placeid="+placeid+"&selectedline="+selectedline, function() {
1768 if (idoflineadded > 0)
1770 console.log(
"Auto select "+idoflineadded);
1771 $(
'.posinvoiceline#'+idoflineadded).click();
1775if ($action ==
"order" && !empty($order_receipt_printer1)) {
1776 if (filter_var(
getDolGlobalString(
'TAKEPOS_PRINT_SERVER'), FILTER_VALIDATE_URL) ==
true) {
1780 url:
'<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER
'); ?>/printer/index.php',
1781 data:
'invoice='+orderprinter1esc
1788 url:
'http://<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER
'); ?>:8111/print',
1790 print $headerorder.$order_receipt_printer1.$footerorder; ?>'
1796if ($action ==
"order" && !empty($order_receipt_printer2)) {
1797 if (filter_var(
getDolGlobalString(
'TAKEPOS_PRINT_SERVER'), FILTER_VALIDATE_URL) ==
true) {
1801 url:
'<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER
'); ?>/printer/index.php?printer=2',
1802 data:
'invoice='+orderprinter2esc
1809 url:
'http://<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER
'); ?>:8111/print2',
1811 print $headerorder.$order_receipt_printer2.$footerorder; ?>'
1817if ($action ==
"order" && !empty($order_receipt_printer3)) {
1818 if (filter_var(
getDolGlobalString(
'TAKEPOS_PRINT_SERVER'), FILTER_VALIDATE_URL) ==
true) {
1822 url:
'<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER
'); ?>/printer/index.php?printer=3',
1823 data:
'invoice='+orderprinter3esc
1830if ($action ==
"search" || $action ==
"valid") {
1832 parent.ClearSearch(
true);
1837if ($action ==
"search") {
1839 $(
'#search').focus();
1847function SendTicket(
id)
1849 console.log(
"Open box to select the Print/Send form");
1850 $.colorbox({href:
"send.php?facid="+id, width:
"70%", height:
"30%", transition:
"none", iframe:
"true", title:<?php echo
"'".dol_escape_js($langs->trans(
"SendTicket")).
"'" ; ?>});
1855function PrintBox(
id, action) {
1856 console.log(
"Open box before printing");
1857 $.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
"); ?>"});
1862function PrintByBrowser(
id, gift) {
1863 console.log(
"Call PrintByBrowser() to generate the receipt.");
1864 $.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")).
"'" ; ?>});
1869function PrintHTMLToSlashPrint(
id){
1871 console.log(
"PrintHTMLToSlashPrint" +
id);
1872 $.get(
"receipt.php?facid="+
id,
function(data,
status) {
1873 receipt=data.replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g,
'');
1876 url:
'http://<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER
'); ?>:8111/print',
1884function PrintByESCPOSOld(
id){
1885 console.log(
"PrintByESCPOSOld id=" +
id);
1886 $.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) {
1889 url:
'<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER
'); ?>/printer/index.php',
1890 data:
'invoice='+data
1901function PrintByESCPOS(
id) {
1902 console.log(
"PrintByESCPOS Printing invoice ticket by calling takepos/aja/ajax.php id=" +
id);
1906 data: { token:
'<?php echo currentToken(); ?>' },
1907 url:
"<?php print DOL_URL_ROOT.'/takepos/ajax/ajax.php?action=printinvoiceticket&token='.currentToken().'&term='.urlencode(isset($_SESSION["takeposterminal
"]) ? $_SESSION["takeposterminal
"] : '').'&id='; ?>" + id,
1908 success:
function(){
1909 showPrintResultPopup(<?php echo
"'".
dol_escape_js($langs->trans(
"SentToPrinter").
' '.$nameOfPrinter).
"'" ; ?>, 2000);
1912 showPrintResultPopup(<?php echo
"'".
dol_escape_js($langs->trans(
"FailedToSendToPrinter")).
"'" ; ?>, 2000);
1919function showPrintResultPopup(message, duration) {
1920 $(
"#dialogforpopuptakepos").show().text(message).fadeIn();
1922 setTimeout(
function(){
1923 $(
"#dialogforpopuptakepos").fadeOut().hide();
1930var creditNoteParams=
"";
1931function CreditNote() {
1933 $parameters = array();
1934 $reshook = $hookmanager->executeHooks(
'paramsForCreditNote', $parameters, $invoice, $action);?>
1935 $(
"#poslines").load(
"<?php
1936 print DOL_URL_ROOT; ?>/takepos/invoice.php?action=creditnote&token=<?php echo newToken() ?>&invoiceid="+placeid+creditNoteParams,
function() { });
1943 $(
"#poslines").load(
"<?php print DOL_URL_ROOT; ?>/takepos/invoice.php?action=addnote&token=<?php echo newToken() ?>&invoiceid="+placeid+
"&idline="+selectedline, {
"addnote": $(
"#textinput").val() });
1948$( document ).ready(
function() {
1949 console.log(
"Set customer info and sales in header placeid=<?php echo $placeid; ?> status=<?php echo $invoice->statut; ?>");
1952 $s = $langs->trans(
"Customer");
1953 if ($invoice->id > 0 && ($invoice->socid !=
getDolGlobalString($constforcompanyid))) {
1956 $contactids = $invoice->getIdContact(
'external',
'BILLING');
1957 $contactid = $contactids[0];
1958 if ($contactid > 0) {
1960 $contact->fetch($contactid);
1961 $s .=
" - " . $contact->getFullName($langs);
1965 print
'$("#idcustomer").val("");';
1969 $(
"#customerandsales").html(
'');
1970 $(
"#shoppingcart").html(
'');
1973 $(
"#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>');
1975 $(
"#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>');
1979 $sql =
"SELECT rowid, datec, ref FROM ".MAIN_DB_PREFIX.
"facture";
1980 $sql .=
" WHERE entity IN (".getEntity(
'invoice').
")";
1983 $sql .=
" AND ref LIKE '(PROV-POS".$db->escape(isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'').
"-0%'";
1986 $sql .=
" AND pos_source = '".$db->escape((
string) $_SESSION[
"takeposterminal"]).
"'";
1987 $sql .=
" AND module_source = 'takepos'";
1990 $sql .= $db->order(
'datec',
'ASC');
1991 $resql = $db->query($sql);
1994 while ($obj = $db->fetch_object($resql)) {
1995 echo
'$("#shoppingcart").append(\'';
1996 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=\\\'';
1997 $num_sale = str_replace(
")",
"", str_replace(
"(PROV-POS".$_SESSION[
"takeposterminal"].
"-",
"", $obj->ref));
1999 if (str_replace(
"-",
"", $num_sale) > $max_sale) {
2000 $max_sale = str_replace(
"-",
"", $num_sale);
2002 echo
'\\\'; invoiceid=\\\'';
2004 echo
'\\\'; Refresh();">';
2005 if ($placeid == $obj->rowid) {
2006 echo
'<span class="basketselected">';
2008 echo
'<span class="basketnotselected">';
2010 echo
'<span class="fa fa-shopping-cart paddingright"></span>'.dol_print_date($db->jdate($obj->datec),
'%H:%M',
'tzuser');
2014 echo
'$("#shoppingcart").append(\'<a onclick="place=\\\'0-';
2016 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>\');';
2018 dol_print_error($db);
2024 $constantforkey =
'CASHDESK_NO_DECREASE_STOCK'. (isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
2027 $constantforkey =
'CASHDESK_ID_WAREHOUSE'. (isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
2029 if ($idwarehouse > 0) {
2030 $s =
'<span class="small">';
2032 $warehouse->fetch($idwarehouse);
2033 $s .=
'<span class="hideonsmartphone">'.$langs->trans(
"Warehouse").
'<br></span>'.$warehouse->ref;
2035 $s .=
' ('.$langs->trans(
"Closed").
')';
2038 print
"$('#infowarehouse').html('".dol_escape_js($s).
"');";
2039 print
'$("#infowarehouse").css("display", "inline-block");';
2041 $s =
'<span class="small hideonsmartphone">';
2042 $s .= $langs->trans(
"StockChangeDisabled").
'<br>'.$langs->trans(
"NoWarehouseDefinedForTerminal");
2044 print
"$('#infowarehouse').html('".dol_escape_js($s).
"');";
2045 if (!empty(
$conf->dol_optimize_smallscreen)) {
2046 print
'$("#infowarehouse").css("display", "none");';
2050 $s =
'<span class="small hideonsmartphone">'.$langs->trans(
"StockChangeDisabled").
'</span>';
2051 print
"$('#infowarehouse').html('".dol_escape_js($s).
"');";
2052 if (!empty(
$conf->dol_optimize_smallscreen)) {
2053 print
'$("#infowarehouse").css("display", "none");';
2062 $s =
'<span class="small">';
2063 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
2064 $langs->load(
"members");
2065 $s .= $langs->trans(
"Member").
': ';
2067 $result = $adh->fetch(0,
'', $invoice->socid);
2069 $adh->ref = $adh->getFullName($langs);
2073 $s .= $adh->getFullName($langs);
2074 $s .=
' - '.$adh->type;
2075 if ($adh->datefin) {
2076 $s .=
'<br>'.$langs->trans(
"SubscriptionEndDate").
': '.
dol_print_date($adh->datefin,
'day');
2077 if ($adh->hasDelay()) {
2078 $s .=
" ".img_warning($langs->trans(
"Late"));
2081 $s .=
'<br>'.$langs->trans(
"SubscriptionNotReceived");
2082 if ($adh->status > 0) {
2083 $s .=
" ".img_warning($langs->trans(
"Late"));
2090 $s .=
'<br>'.$langs->trans(
"ThirdpartyNotLinkedToMember");
2095 $(
"#moreinfo").html(<?php print
"'".
dol_escape_js($s).
"'" ; ?>);
2102 echo
"function CustomerDisplay(){";
2103 echo
"var line1='".$CUSTOMER_DISPLAY_line1.
"'.substring(0,20);";
2104 echo
"line1=line1.padEnd(20);";
2105 echo
"var line2='".$CUSTOMER_DISPLAY_line2.
"'.substring(0,20);";
2106 echo
"line2=line2.padEnd(20);";
2108 echo
'webSocketCustomerDisplay.send(line1);';
2109 echo
'webSocketCustomerDisplay.send(line2);';
2113 data: { text: line1+line2 },
2114 url: '".getDolGlobalString(
'TAKEPOS_PRINT_SERVER').
"/display/index.php',
2127if (!empty(
$conf->use_javascript_ajax)) {
2128 print
"\n".
'<!-- Includes JS Footer of Dolibarr -->'.
"\n";
2129 print
'<script src="'.DOL_URL_ROOT.
'/core/js/lib_foot.js.php?lang='.$langs->defaultlang.
'"></script>'.
"\n";
2132$usediv = (
GETPOST(
'format',
'aZ09') ==
'div');
2134print
'<!-- 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";
2135print
'<div class="div-table-responsive-no-min invoice">';
2137 print
'<div id="tablelines">';
2139 print
'<table id="tablelines" class="noborder noshadow postablelines centpercent">';
2142$buttontocreatecreditnote =
'';
2143if (($action ==
"valid" || $action ==
"history" || $action ==
"addline")
2145 $buttontocreatecreditnote .=
' <!-- Show button to create a credit note -->'.
"\n";
2146 $buttontocreatecreditnote .=
'<button id="buttonprint" type="button" onclick="ModalBox(\'ModalCreditNote\')">'.$langs->trans(
'CreateCreditNote').
'</button>';
2147 if (
getDolGlobalInt(
'TAKEPOS_PRINT_INVOICE_DOC_INSTEAD_OF_RECEIPT')) {
2148 $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>';
2152$buttontocloneticket =
'';
2154 $buttontocloneticket .=
' <button id="buttonclone" type="button" onclick="CloneTicket('.((int) $invoice->id).
')">'.$langs->trans(
'CloneTicket').
'</button>';
2158if ($sectionwithinvoicelink && ($mobilepage ==
"invoice" || $mobilepage ==
"")) {
2159 print
'<!-- Print table line with link to invoice ref -->';
2161 print
'<tr><td colspan="5" class="paddingtopimp paddingbottomimp" style="padding-top: 10px !important; padding-bottom: 10px !important;">';
2162 print $sectionwithinvoicelink;
2163 print $buttontocreatecreditnote;
2164 print $buttontocloneticket;
2167 print
'<tr><td colspan="4" class="paddingtopimp paddingbottomimp" style="padding-top: 10px !important; padding-bottom: 10px !important;">';
2168 print $sectionwithinvoicelink;
2169 print $buttontocreatecreditnote;
2170 print $buttontocloneticket;
2177 print
'<tr class="liste_titre nodrag nodrop">';
2178 print
'<td class="linecoldescription">';
2181if (empty($mobilepage) || $mobilepage ==
"invoice") {
2182 print
'<!-- hidden var used by some js functions -->';
2183 print
'<input type="hidden" name="invoiceid" id="invoiceid" value="'.$invoice->id.
'">';
2184 print
'<input type="hidden" name="thirdpartyid" id="thirdpartyid" value="'.$invoice->socid.
'">';
2188 $sql =
"SELECT floor, label FROM ".MAIN_DB_PREFIX.
"takepos_floor_tables where rowid = ".((int) $place);
2189 $resql = $db->query($sql);
2190 $obj = $db->fetch_object($resql);
2192 $label = $obj->label;
2193 $floor = $obj->floor;
2195 if ($mobilepage ==
"invoice" || $mobilepage ==
"") {
2198 print
'<span class="opacitymedium">'.$langs->trans(
'Place').
"</span> <b>".(empty($label) ?
'?' : $label).
"</b><br>";
2199 print
'<span class="opacitymedium">'.$langs->trans(
'Floor').
"</span> <b>".(empty($floor) ?
'?' : $floor).
"</b>";
2206$parameters = array();
2207$reshook = $hookmanager->executeHooks(
'completeTakePosInvoiceHeader', $parameters, $invoice, $action);
2209 setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
2211print $hookmanager->resPrint;
2213if (empty($_SESSION[
"basiclayout"]) || $_SESSION[
"basiclayout"] != 1) {
2215 print
'<td class="linecolqty right">'.$langs->trans(
'PriceUHT').
'</td>';
2217 print
'<td class="linecolqty right">'.$langs->trans(
'ReductionShort').
'</td>';
2218 print
'<td class="linecolqty right">'.$langs->trans(
'Qty').
'</td>';
2220 print
'<td class="linecolht right nowraponall">';
2221 print
'<span class="opacitymedium small">' . $langs->trans(
'TotalHTShort') .
'</span><br>';
2223 if (empty($mobilepage) || $mobilepage ==
"invoice") {
2224 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>';
2225 if (
isModEnabled(
'multicurrency') && !empty($_SESSION[
"takeposcustomercurrency"]) &&
$conf->currency != $_SESSION[
"takeposcustomercurrency"]) {
2227 include_once DOL_DOCUMENT_ROOT .
'/multicurrency/class/multicurrency.class.php';
2229 $multicurrency->fetch(0, $_SESSION[
"takeposcustomercurrency"]);
2230 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>';
2235 print
'<td class="linecolht right nowraponall">';
2236 print
'<span class="opacitymedium small">'.$langs->trans(
'TotalTTCShort').
'</span><br>';
2238 if (empty($mobilepage) || $mobilepage ==
"invoice") {
2239 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>';
2240 if (
isModEnabled(
'multicurrency') && !empty($_SESSION[
"takeposcustomercurrency"]) &&
$conf->currency != $_SESSION[
"takeposcustomercurrency"]) {
2242 include_once DOL_DOCUMENT_ROOT.
'/multicurrency/class/multicurrency.class.php';
2244 $multicurrency->fetch(0, $_SESSION[
"takeposcustomercurrency"]);
2245 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>';
2249} elseif ($mobilepage ==
"invoice") {
2250 print
'<td class="linecolqty right">'.$langs->trans(
'Qty').
'</td>';
2256if (!empty($_SESSION[
"basiclayout"]) && $_SESSION[
"basiclayout"] == 1) {
2257 if ($mobilepage ==
"cats") {
2258 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
2260 $categories = $categorie->get_full_arbo(
'product');
2262 foreach ($categories as $row) {
2263 if (defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
2264 $htmlforlines .=
'<div class="leftcat"';
2266 $htmlforlines .=
'<tr class="drag drop oddeven posinvoiceline"';
2268 $htmlforlines .=
' onclick="LoadProducts('.$row[
'id'].
');">';
2269 if (defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
2270 $htmlforlines .=
'<img class="imgwrapper" width="33%" src="'.DOL_URL_ROOT.
'/takepos/public/auto_order.php?genimg=cat&query=cat&id='.$row[
'id'].
'"><br>';
2272 $htmlforlines .=
'<td class="left">';
2274 $htmlforlines .= $row[
'label'];
2275 if (defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
2276 $htmlforlines .=
'</div>'.
"\n";
2278 $htmlforlines .=
'</td></tr>'.
"\n";
2281 print $htmlforlines;
2284 if ($mobilepage ==
"products") {
2285 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
2288 $result =
$object->fetch($catid);
2289 $prods =
$object->getObjectsInCateg(
"product");
2291 '@phan-var-force Product[] $prods';
2293 foreach ($prods as $row) {
2294 if (defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
2295 $htmlforlines .=
'<div class="leftcat"';
2297 $htmlforlines .=
'<tr class="drag drop oddeven posinvoiceline"';
2299 $htmlforlines .=
' onclick="AddProduct(\''.$place.
'\',
'.$row->id.')
"';
2300 $htmlforlines .= '>';
2301 if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
2302 $htmlforlines .= '<img class="imgwrapper
" width="33%
" src="'.DOL_URL_ROOT.'/takepos/
public/auto_order.php?genimg=pro&query=pro&
id=
'.$row->id.'"><br>';
2303 $htmlforlines .= $row->label.' '.price($row->price_ttc, 1, $langs, 1, -1, -1, $conf->currency);
2304 $htmlforlines .= '</div>'."\n
";
2306 $htmlforlines .= '<td class="left
">';
2307 $htmlforlines .= $row->label;
2308 $htmlforlines .= '<div class="right
">'.price($row->price_ttc, 1, $langs, 1, -1, -1, $conf->currency).'</div>';
2309 $htmlforlines .= '</td>';
2310 $htmlforlines .= '</tr>'."\n
";
2313 print $htmlforlines;
2316 if ($mobilepage == "places
") {
2317 $sql = "SELECT rowid, entity, label, leftpos, toppos, floor FROM
".MAIN_DB_PREFIX."takepos_floor_tables
";
2318 $resql = $db->query($sql);
2322 while ($row = $db->fetch_array($resql)) {
2324 $htmlforlines .= '<tr class="drag drop oddeven posinvoiceline
';
2325 $htmlforlines .= '" onclick="LoadPlace(\
''.$row[
'label'].
'\')
">';
2326 $htmlforlines .= '<td class="left
">';
2327 $htmlforlines .= $row['label'];
2328 $htmlforlines .= '</td>';
2329 $htmlforlines .= '</tr>'."\n
";
2331 print $htmlforlines;
2336 //In Phone basic layout hide some content depends situation
2337 if (!empty($_SESSION["basiclayout
"]) && $_SESSION["basiclayout
"] == 1 && $mobilepage != "invoice
" && $action != "order
") {
2341 // Loop on each lines on invoice
2342 if (is_array($invoice->lines) && count($invoice->lines)) {
2343 print '<!-- invoice.php show lines of invoices -->'."\n
";
2344 $tmplines = array_reverse($invoice->lines);
2345 $htmlsupplements = array();
2346 foreach ($tmplines as $line) {
2347 if ($line->fk_parent_line != false) {
2348 if (!isset($htmlsupplements[$line->fk_parent_line])) {
2349 $htmlsupplements[$line->fk_parent_line] = '';
2351 $htmlsupplements[$line->fk_parent_line] .= '<tr class="drag drop oddeven posinvoiceline
';
2352 if ($line->special_code == "4") {
2353 $htmlsupplements[$line->fk_parent_line] .= ' order
';
2355 $htmlsupplements[$line->fk_parent_line] .= '" id="'.$line->id.'"';
2356 if ($line->special_code == "4
") {
2357 $htmlsupplements[$line->fk_parent_line] .= ' title="'.dol_escape_htmltag($langs->trans("AlreadyPrinted")).'"';
2359 $htmlsupplements[$line->fk_parent_line] .= '>';
2360 $htmlsupplements[$line->fk_parent_line] .= '<td class="left
">';
2361 $htmlsupplements[$line->fk_parent_line] .= img_picto('', 'rightarrow.png');
2362 if ($line->product_label) {
2363 $htmlsupplements[$line->fk_parent_line] .= $line->product_label;
2365 if ($line->product_label && $line->desc) {
2366 $htmlsupplements[$line->fk_parent_line] .= '<br>';
2368 if ($line->product_label != $line->desc) {
2369 $firstline = dolGetFirstLineOfText($line->desc);
2370 if ($firstline != $line->desc) {
2371 $htmlsupplements[$line->fk_parent_line] .= $form->textwithpicto(dolGetFirstLineOfText($line->desc), $line->desc);
2373 $htmlsupplements[$line->fk_parent_line] .= $line->desc;
2376 $htmlsupplements[$line->fk_parent_line] .= '</td>';
2378 // complete line by hook
2379 $parameters = array('line' => $line);
2380 $reshook = $hookmanager->executeHooks('completeTakePosInvoiceParentLine', $parameters, $invoice, $action); // Note that $action and $object may have been modified by some hooks
2382 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
2384 $htmlsupplements[$line->fk_parent_line] .= $hookmanager->resPrint;
2386 if (empty($_SESSION["basiclayout
"]) || $_SESSION["basiclayout
"] != 1) {
2387 $htmlsupplements[$line->fk_parent_line] .= '<td class="right
">'.vatrate(price2num($line->remise_percent), true).'</td>';
2388 $htmlsupplements[$line->fk_parent_line] .= '<td class="right
">'.$line->qty.'</td>';
2389 $htmlsupplements[$line->fk_parent_line] .= '<td class="right
">'.price($line->total_ttc).'</td>';
2391 $htmlsupplements[$line->fk_parent_line] .= '</tr>'."\n
";
2396 $htmlforlines .= '<tr class="drag drop oddeven posinvoiceline
';
2397 if ($line->special_code == "4") {
2398 $htmlforlines .= ' order
';
2400 $htmlforlines .= '" id="'.$line->id.'"';
2401 if ($line->special_code == "4
") {
2402 $htmlforlines .= ' title="'.dol_escape_htmltag($langs->trans("AlreadyPrinted")).'"';
2404 $htmlforlines .= '>';
2405 $htmlforlines .= '<td class="left
">';
2406 if (!empty($_SESSION["basiclayout
"]) && $_SESSION["basiclayout
"] == 1) {
2407 $htmlforlines .= '<span class="phoneqty
">'.$line->qty."</span> x
";
2409 if (isset($line->product_type)) {
2410 if (empty($line->product_type)) {
2411 $htmlforlines .= img_object('', 'product').' ';
2413 $htmlforlines .= img_object('', 'service').' ';
2417 if (!getDolGlobalString('TAKEPOS_SHOW_N_FIRST_LINES')) {
2418 if ($line->product_ref) {
2419 $tooltiptext .= '<b>'.$langs->trans("Ref
").'</b> : '.$line->product_ref.'<br>';
2420 $tooltiptext .= '<b>'.$langs->trans("Label
").'</b> : '.$line->product_label.'<br>';
2421 if (!empty($line->batch)) {
2422 $tooltiptext .= '<br><b>'.$langs->trans("LotSerial
").'</b> : '.$line->batch.'<br>';
2424 if (!empty($line->fk_warehouse)) {
2425 $tooltiptext .= '<b>'.$langs->trans("Warehouse
").'</b> : '.$line->fk_warehouse.'<br>';
2427 if ($line->product_label != $line->desc) {
2429 $tooltiptext .= '<br>';
2431 $tooltiptext .= $line->desc;
2434 if (getDolGlobalInt('TAKEPOS_SHOW_PRODUCT_REFERENCE') == 1) {
2435 $htmlforlines .= $form->textwithpicto($line->product_label ? '<b>' . $line->product_ref . '</b> - ' . $line->product_label : dolGetFirstLineOfText($line->desc, 1), $tooltiptext);
2436 } elseif (getDolGlobalInt('TAKEPOS_SHOW_PRODUCT_REFERENCE') == 2) {
2437 $htmlforlines .= $form->textwithpicto($line->product_ref ? '<b>'.$line->product_ref.'<b>' : dolGetFirstLineOfText($line->desc, 1), $tooltiptext);
2439 $htmlforlines .= $form->textwithpicto($line->product_label ? $line->product_label : ($line->product_ref ? $line->product_ref : dolGetFirstLineOfText($line->desc, 1)), $tooltiptext);
2442 if ($line->product_ref) {
2443 $tooltiptext .= '<b>'.$langs->trans("Ref
").'</b> : '.$line->product_ref.'<br>';
2444 $tooltiptext .= '<b>'.$langs->trans("Label
").'</b> : '.$line->product_label.'<br>';
2446 if (!empty($line->batch)) {
2447 $tooltiptext .= '<br><b>'.$langs->trans("LotSerial
").'</b> : '.$line->batch.'<br>';
2449 if (!empty($line->fk_warehouse)) {
2450 $tooltiptext .= '<b>'.$langs->trans("Warehouse
").'</b> : '.$line->fk_warehouse.'<br>';
2453 if ($line->product_label) {
2454 $htmlforlines .= $line->product_label;
2456 if ($line->product_label != $line->desc) {
2457 if ($line->product_label && $line->desc) {
2458 $htmlforlines .= '<br>';
2460 $firstline = dolGetFirstLineOfText($line->desc, getDolGlobalInt('TAKEPOS_SHOW_N_FIRST_LINES'));
2461 if ($firstline != $line->desc) {
2462 $htmlforlines .= $form->textwithpicto(dolGetFirstLineOfText($line->desc), $line->desc);
2464 $htmlforlines .= $line->desc;
2468 if (!empty($line->array_options['options_order_notes'])) {
2469 $htmlforlines .= "<br>(
".$line->array_options['options_order_notes'].")
";
2471 if (isModEnabled('productbatch') && $line->fk_product > 0) {
2472 if (!is_object($line->product) || !($line->product->id > 0)) {
2473 $line->fetch_product();
2476 if (is_object($line->product) && $line->product->status_batch > 0) {
2477 $batch_display = empty($line->batch) ? $langs->trans("NotDefined
") : dol_escape_htmltag($line->batch);
2478 $htmlforlines .= '<br><span class="opacitymedium
">'.$langs->trans("LotSerial
").' : '.$batch_display.'</span>';
2479 // Only show edit button if invoice is a Draft (status == 0)
2480 if ($invoice->status == Facture::STATUS_DRAFT) {
2481 $htmlforlines .= ' <a href="#
" onclick="editbatch(
'.$line->id.',
'.$line->fk_product.');
return false;
" title="'.dol_escape_htmltag($langs->trans("Modify")).'">'.img_edit().'</a>';
2485 if (!empty($_SESSION["basiclayout
"]) && $_SESSION["basiclayout
"] == 1) {
2486 $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>';
2488 if (empty($_SESSION["basiclayout
"]) || $_SESSION["basiclayout
"] != 1) {
2489 // Set the content of tooltip
2491 $moreinfo .= $langs->trans("VATRate
").': '.price($line->tva_tx).' %<br>';
2492 $moreinfo .= $langs->trans("UnitPrice
").': '.price($line->subprice).'<br>';
2493 $moreinfo .= '<br>';
2494 $moreinfo .= $langs->transcountry("TotalHT
", $mysoc->country_code).': '.price($line->total_ht);
2495 if ($line->vat_src_code) {
2496 $moreinfo .= '<br>'.$langs->trans("VATCode
").': '.$line->vat_src_code;
2498 $moreinfo .= '<br>'.$langs->trans("TotalVAT
").': '.price($line->total_tva);
2499 if ($mysoc->useLocalTax(1, 1, $mysoc)) {
2500 $moreinfo .= '<br>'.$langs->transcountry("TotalLT1
", $mysoc->country_code).': '.price($line->total_localtax1);
2502 if ($mysoc->useLocalTax(2, 1, $mysoc)) {
2503 $moreinfo .= '<br>'.$langs->transcountry("TotalLT2
", $mysoc->country_code).': '.price($line->total_localtax2);
2505 $moreinfo .= '<hr>';
2506 $moreinfo .= $langs->transcountry("TotalTTC
", $mysoc->country_code).': '.price($line->total_ttc);
2507 //$moreinfo .= $langs->trans("TotalHT
").': '.$line->total_ht;
2508 if ($line->date_start || $line->date_end) {
2509 $htmlforlines .= '<br><div class="clearboth nowraponall
">'.get_date_range($line->date_start, $line->date_end).'</div>';
2511 $htmlforlines .= '</td>';
2513 // complete line by hook
2514 $parameters = array('line' => $line);
2515 $reshook = $hookmanager->executeHooks('completeTakePosInvoiceLine', $parameters, $invoice, $action); // Note that $action and $object may have been modified by some hooks
2517 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
2519 $htmlforlines .= $hookmanager->resPrint;
2521 if (getDolGlobalInt("TAKEPOS_SHOW_SUBPRICE
")) {
2522 $htmlforlines .= '<td class="right
">'.price($line->subprice).'</td>';
2524 $htmlforlines .= '<td class="right
">'.vatrate(price2num($line->remise_percent), true).'</td>';
2525 // nowraponall keeps the qty and its '(stock)' block on one line: on narrow layouts
2526 // the native display otherwise wraps over three lines inside the qty column.
2527 $htmlforlines .= '<td class="right nowraponall
">';
2528 $htmlforlines .= $line->qty;
2529 if (isModEnabled('stock') && $user->hasRight('stock', 'mouvement', 'lire')) {
2530 $constantforkey = 'CASHDESK_ID_WAREHOUSE'.$_SESSION["takeposterminal
"];
2531 if (getDolGlobalString($constantforkey) && $line->fk_product > 0 && !getDolGlobalString('TAKEPOS_HIDE_STOCK_ON_LINE')) {
2532 $productChildrenNb = 0;
2533 if (getDolGlobalInt('PRODUIT_SOUSPRODUITS')) {
2534 if (!is_object($line->product) || !($line->product->id > 0)) {
2535 $line->fetch_product();
2537 if (is_object($line->product)) {
2538 $productChildrenNb = $line->product->hasFatherOrChild(1);
2541 if ($productChildrenNb == 0) {
2542 $sql = "SELECT e.rowid, e.ref, e.lieu, e.fk_parent, e.statut, ps.reel, ps.rowid as product_stock_id, p.pmp
";
2543 $sql .= " FROM
".MAIN_DB_PREFIX."entrepot as e,
";
2544 $sql .= " ".MAIN_DB_PREFIX."product_stock as ps
";
2545 $sql .= " LEFT JOIN
".MAIN_DB_PREFIX."product as p ON p.rowid = ps.fk_product
";
2546 $sql .= " WHERE ps.reel != 0
";
2547 $sql .= " AND ps.fk_entrepot =
".((int) getDolGlobalString($constantforkey));
2548 $sql .= " AND e.entity IN (
".getEntity('stock').")
";
2549 $sql .= " AND ps.fk_product =
".((int) $line->fk_product);
2550 $resql = $db->query($sql);
2553 $obj = $db->fetch_object($resql);
2555 $stock_real = price2num($obj->reel, 'MS');
2557 $htmlforlines .= $line->qty;
2558 $htmlforlines .= ' ';
2559 $htmlforlines .= '<span class="opacitylow
" title="'.$langs->trans("Stock").' '.price($stock_real, 1, '', 1, 0).'">';
2560 $htmlforlines .= '(';
2561 if ($line->qty && $line->qty > $stock_real) {
2562 $htmlforlines .= '<span style="color: var(--amountremaintopaycolor)
">';
2564 $htmlforlines .= img_picto('', 'stock', 'class="pictofixedwidth
"').price($stock_real, 1, '', 1, 0);
2565 if ($line->qty && $line->qty > $stock_real) {
2566 $htmlforlines .= "</span>
";
2568 $htmlforlines .= ')';
2569 $htmlforlines .= '</span>';
2571 dol_print_error($db);
2577 $htmlforlines .= '</td>';
2578 if (getDolGlobalInt('TAKEPOS_SHOW_HT')) {
2579 $htmlforlines .= '<td class="right classfortooltip
" title="'.$moreinfo.'">';
2580 $htmlforlines .= price($line->total_ht, 1, '', 1, -1, -1, $conf->currency);
2581 if (isModEnabled('multicurrency') && !empty($_SESSION["takeposcustomercurrency
"]) && $conf->currency != $_SESSION["takeposcustomercurrency
"]) {
2582 //Only show customer currency if multicurrency module is enabled, if currency selected and if this currency selected is not the same as main currency
2583 include_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php';
2584 $multicurrency = new MultiCurrency($db);
2585 $multicurrency->fetch(0, $_SESSION["takeposcustomercurrency
"]);
2586 $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>';
2588 $htmlforlines .= '</td>';
2590 $htmlforlines .= '<td class="right classfortooltip
" title="'.$moreinfo.'">';
2591 $htmlforlines .= price($line->total_ttc, 1, '', 1, -1, -1, $conf->currency);
2592 if (isModEnabled('multicurrency') && !empty($_SESSION["takeposcustomercurrency
"]) && $conf->currency != $_SESSION["takeposcustomercurrency
"]) {
2593 //Only show customer currency if multicurrency module is enabled, if currency selected and if this currency selected is not the same as main currency
2594 include_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php';
2595 $multicurrency = new MultiCurrency($db);
2596 $multicurrency->fetch(0, $_SESSION["takeposcustomercurrency
"]);
2597 $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>';
2599 $htmlforlines .= '</td>';
2601 $htmlforlines .= '</tr>'."\n
";
2602 $htmlforlines .= empty($htmlsupplements[$line->id]) ? '' : $htmlsupplements[$line->id];
2604 print $htmlforlines;
2607 print '<tr class="drag drop oddeven
"><td class="left
"><span class="opacitymedium
">'.$langs->trans("Empty
").'</span></td><td></td>';
2608 if (empty($_SESSION["basiclayout
"]) || $_SESSION["basiclayout
"] != 1) {
2609 print '<td></td><td></td>';
2610 if (getDolGlobalString('TAKEPOS_SHOW_HT')) {
2616} else { // No invoice generated yet
2617 print '<tr class="drag drop oddeven
"><td class="left
"><span class="opacitymedium
">'.$langs->trans("Empty
").'</span></td><td></td>';
2618 if (empty($_SESSION["basiclayout
"]) || $_SESSION["basiclayout
"] != 1) {
2619 print '<td></td><td></td>';
2620 if (getDolGlobalString('TAKEPOS_SHOW_HT')) {
2633if ($action == "search
") {
2635 <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
')).'">
2642if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
2643 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.
Class to manage members of a foundation.
const STATUS_EXCLUDED
Excluded.
Class to manage categories.
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)
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.
multi select button
0 = Do not include form tag and submit button -1 = Do not include form tag but include submit button
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.