125 header($_SERVER[
'SERVER_PROTOCOL'].
' 500 Internal Server Error',
true, 500);
131$number =
GETPOST(
'number',
'alpha');
134$desc =
GETPOST(
'desc',
'alphanohtml');
147if ($pay ==
'cheque') {
154 $sql =
"SELECT id FROM ".MAIN_DB_PREFIX.
"c_paiement";
155 $sql .=
" WHERE entity IN (".getEntity(
'c_paiement').
")";
156 $sql .=
" AND code = '".$db->escape($paycode).
"'";
157 $resql = $db->query($sql);
159 $obj = $db->fetch_object($resql);
161 $paiementid = $obj->id;
168 $ret = $invoice->fetch($invoiceid);
170 $ret = $invoice->fetch(
'',
'(PROV-POS'.$takeposterminal.
'-'.$place.
')');
173 $placeid = $invoice->id;
176$constforcompanyid =
'CASHDESK_ID_THIRDPARTY'.$takeposterminal;
179if ($invoice->socid > 0) {
180 $soc->fetch($invoice->socid);
186if (isModEnabled(
'project') &&
getDolGlobalInt(
"CASHDESK_ID_PROJECT".$takeposterminal)) {
187 $invoice->fk_project =
getDolGlobalInt(
"CASHDESK_ID_PROJECT".$takeposterminal);
191if (isModEnabled(
'multicurrency') && !empty($_SESSION[
"takeposcustomercurrency"])) {
192 if ($invoice->multicurrency_code != $_SESSION[
"takeposcustomercurrency"]) {
193 $invoice->setMulticurrencyCode($_SESSION[
"takeposcustomercurrency"]);
197$term = empty($_SESSION[
"takeposterminal"]) ? 1 : $_SESSION[
"takeposterminal"];
204$parameters = array();
205$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $invoice, $action);
210if (empty($reshook)) {
212 if ($action ==
'valid' && $user->hasRight(
'facture',
'creer')) {
220 $bankaccount =
getDolGlobalInt(
'CASHDESK_ID_BANKACCOUNT_CASH'.$_SESSION[
"takeposterminal"]);
221 } elseif ($pay ==
"CHQ") {
222 $bankaccount =
getDolGlobalInt(
'CASHDESK_ID_BANKACCOUNT_CHEQUE'.$_SESSION[
"takeposterminal"]);
224 $accountname =
"CASHDESK_ID_BANKACCOUNT_".$pay.$_SESSION[
"takeposterminal"];
229 if ($bankaccount <= 0 && $pay !=
"delayed" && isModEnabled(
"bank")) {
230 $errormsg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"BankAccount"));
238 $invoice->fetch($placeid);
242 if ($invoice->total_ttc < 0) {
243 $invoice->type = $invoice::TYPE_CREDIT_NOTE;
245 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"facture";
246 $sql .=
" WHERE entity IN (".getEntity(
'invoice').
")";
247 $sql .=
" AND fk_soc = ".((int) $invoice->socid);
248 $sql .=
" AND type <> ".Facture::TYPE_CREDIT_NOTE;
249 $sql .=
" AND fk_statut >= ".$invoice::STATUS_VALIDATED;
250 $sql .=
" ORDER BY rowid DESC";
252 $resql = $db->query($sql);
254 $obj = $db->fetch_object($resql);
255 $fk_source = $obj->rowid;
256 if ($fk_source ==
null) {
257 fail($langs->transnoentitiesnoconv(
"NoPreviousBillForCustomer"));
260 fail($langs->transnoentitiesnoconv(
"NoPreviousBillForCustomer"));
262 $invoice->fk_facture_source = $fk_source;
263 $invoice->update($user);
266 $constantforkey =
'CASHDESK_NO_DECREASE_STOCK'.(isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
273 if ($invoice->getRemainToPay() > 0) {
279 } elseif (count($invoice->lines) == 0) {
283 } elseif (isModEnabled(
'stock') && !isModEnabled(
'productbatch') && $allowstockchange) {
288 $conf->global->STOCK_CALCULATE_ON_BILL = 1;
290 $constantforkey =
'CASHDESK_ID_WAREHOUSE'.(isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
291 dol_syslog(
"Validate invoice with stock change. Warehouse defined into constant ".$constantforkey.
" = ".
getDolGlobalString($constantforkey));
296 $res = $invoice->validate($user,
'',
getDolGlobalInt($constantforkey), 0, $batch_rule);
299 $conf->global->STOCK_CALCULATE_ON_BILL = $savconst;
302 $res = $invoice->validate($user);
305 $langs->load(
"admin");
306 dol_htmloutput_errors($invoice->error ==
'NotConfigured' ? $langs->trans(
"NotConfigured").
' (TakePos numbering module)' : $invoice->error, $invoice->errors, 1);
311 if (!$error && $res >= 0) {
312 $remaintopay = $invoice->getRemainToPay();
313 if ($remaintopay > 0) {
316 $payment->datepaye = $now;
317 $payment->fk_account = $bankaccount;
322 $payment->amounts[$invoice->id] = $amountofpayment;
325 if ($amountofpayment <= 0 || $amountofpayment > $remaintopay) {
326 $payment->amounts[$invoice->id] = $remaintopay;
330 $payment->paiementid = $paiementid;
331 $payment->num_payment = $invoice->ref;
333 if ($pay !=
"delayed") {
334 $res = $payment->create($user);
339 $res = $payment->addPaymentToBank($user,
'payment',
'(CustomerInvoicePayment)', $bankaccount,
'',
'');
342 dol_htmloutput_errors($langs->trans(
'ErrorNoPaymentDefined').
' '.$payment->error, $payment->errors, 1);
345 $remaintopay = $invoice->getRemainToPay();
351 if ($remaintopay == 0) {
352 dol_syslog(
"Invoice is paid, so we set it to status Paid");
353 $result = $invoice->setPaid($user);
356 $invoice->status = $invoice::STATUS_CLOSED;
359 $invoice->setPaymentMethods($paiementid);
361 dol_syslog(
"Invoice is not paid, remain to pay = ".$remaintopay);
368 if (!$error && $res >= 0) {
369 if (isModEnabled(
'stock') && isModEnabled(
'productbatch') && $allowstockchange) {
371 dol_syslog(
"Now we record the stock movement for each qualified line");
374 require_once DOL_DOCUMENT_ROOT .
"/product/stock/class/mouvementstock.class.php";
375 $constantforkey =
'CASHDESK_ID_WAREHOUSE'.$_SESSION[
"takeposterminal"];
378 $labeltakeposmovement =
'TakePOS - '.$langs->trans(
"Invoice").
' '.$invoice->ref;
380 foreach ($invoice->lines as $line) {
382 $warehouseid = ($line->fk_warehouse ? $line->fk_warehouse :
getDolGlobalInt($constantforkey));
385 if ($line->batch !=
'' && $warehouseid > 0) {
387 $prod_batch->find(0,
'',
'', $line->batch, $warehouseid);
390 $mouvP->setOrigin($invoice->element, $invoice->id);
392 $res = $mouvP->livraison($user, $line->fk_product, $warehouseid, $line->qty, $line->price, $labeltakeposmovement,
'',
'',
'', $prod_batch->batch, $prod_batch->id, $inventorycode);
399 $mouvP->setOrigin($invoice->element, $invoice->id);
401 $res = $mouvP->livraison($user, $line->fk_product, $warehouseid, $line->qty, $line->price, $labeltakeposmovement,
'',
'',
'',
'', 0, $inventorycode);
411 if (!$error && $res >= 0) {
417 if ($action ==
'creditnote' && $user->hasRight(
'facture',
'creer')) {
420 $creditnote =
new Facture($db);
421 $creditnote->socid = $invoice->socid;
423 $creditnote->module_source =
'takepos';
424 $creditnote->pos_source = isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'' ;
426 $creditnote->fk_facture_source = $placeid;
429 $creditnote->create($user);
433 foreach ($invoice->lines as $line) {
435 if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) {
440 if (!empty($invoice->situation_counter)) {
441 $source_fk_prev_id = $line->fk_prev_id;
442 $line->fk_prev_id = $line->id;
443 if (!empty($invoice->tab_previous_situation_invoice)) {
446 $tab_jumped_credit_notes = array();
447 $lineIndex = count($invoice->tab_previous_situation_invoice) - 1;
448 $searchPreviousInvoice =
true;
449 while ($searchPreviousInvoice) {
450 if ($invoice->tab_previous_situation_invoice[$lineIndex]->situation_cycle_ref || $lineIndex < 1) {
451 $searchPreviousInvoice =
false;
455 $tab_jumped_credit_notes[$lineIndex] = $invoice->tab_previous_situation_invoice[$lineIndex]->id;
461 $maxPrevSituationPercent = 0;
462 foreach ($invoice->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine) {
463 if ($prevLine->id == $source_fk_prev_id) {
464 $maxPrevSituationPercent = max($maxPrevSituationPercent, $prevLine->situation_percent);
467 $line->total_ht -= $prevLine->total_ht;
468 $line->total_tva -= $prevLine->total_tva;
469 $line->total_ttc -= $prevLine->total_ttc;
470 $line->total_localtax1 -= $prevLine->total_localtax1;
471 $line->total_localtax2 -= $prevLine->total_localtax2;
473 $line->multicurrency_subprice -= $prevLine->multicurrency_subprice;
474 $line->multicurrency_total_ht -= $prevLine->multicurrency_total_ht;
475 $line->multicurrency_total_tva -= $prevLine->multicurrency_total_tva;
476 $line->multicurrency_total_ttc -= $prevLine->multicurrency_total_ttc;
481 $line->situation_percent = $maxPrevSituationPercent - $line->situation_percent;
486 $maxPrevSituationPercent = 0;
487 foreach ($tab_jumped_credit_notes as $index => $creditnoteid) {
488 foreach ($invoice->tab_previous_situation_invoice[$index]->lines as $prevLine) {
489 if ($prevLine->fk_prev_id == $source_fk_prev_id) {
490 $maxPrevSituationPercent = $prevLine->situation_percent;
492 $line->total_ht -= $prevLine->total_ht;
493 $line->total_tva -= $prevLine->total_tva;
494 $line->total_ttc -= $prevLine->total_ttc;
495 $line->total_localtax1 -= $prevLine->total_localtax1;
496 $line->total_localtax2 -= $prevLine->total_localtax2;
498 $line->multicurrency_subprice -= $prevLine->multicurrency_subprice;
499 $line->multicurrency_total_ht -= $prevLine->multicurrency_total_ht;
500 $line->multicurrency_total_tva -= $prevLine->multicurrency_total_tva;
501 $line->multicurrency_total_ttc -= $prevLine->multicurrency_total_ttc;
507 $line->situation_percent += $maxPrevSituationPercent;
515 $line->fk_facture = $creditnote->id;
516 $line->fk_parent_line = $fk_parent_line;
518 $line->subprice = -$line->subprice;
520 $line->total_ht = -$line->total_ht;
521 $line->total_tva = -$line->total_tva;
522 $line->total_ttc = -$line->total_ttc;
523 $line->total_localtax1 = -$line->total_localtax1;
524 $line->total_localtax2 = -$line->total_localtax2;
526 $line->multicurrency_subprice = -$line->multicurrency_subprice;
527 $line->multicurrency_total_ht = -$line->multicurrency_total_ht;
528 $line->multicurrency_total_tva = -$line->multicurrency_total_tva;
529 $line->multicurrency_total_ttc = -$line->multicurrency_total_ttc;
531 $result = $line->insert(0, 1);
533 $creditnote->lines[] = $line;
536 if ($result > 0 && $line->product_type == 9) {
537 $fk_parent_line = $result;
540 $creditnote->update_price(1);
544 $constantforkey =
'CASHDESK_NO_DECREASE_STOCK'.(isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
547 if (isModEnabled(
'stock') && !isModEnabled(
'productbatch') && $allowstockchange) {
551 $conf->global->STOCK_CALCULATE_ON_BILL = 1;
553 $constantforkey =
'CASHDESK_ID_WAREHOUSE'.(isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
555 dol_syslog(
"Validate invoice with stock change into warehouse defined into constant ".$constantforkey.
" = ".
getDolGlobalString($constantforkey).
" or warehouseid= ".$warehouseid.
" if defined.");
560 $res = $creditnote->validate($user,
'',
getDolGlobalString($constantforkey), 0, $batch_rule);
567 $conf->global->STOCK_CALCULATE_ON_BILL = $savconst;
569 $res = $creditnote->validate($user);
573 if (!$error && $res >= 0) {
574 if (isModEnabled(
'stock') && isModEnabled(
'productbatch') && $allowstockchange) {
576 dol_syslog(
"Now we record the stock movement for each qualified line");
579 require_once DOL_DOCUMENT_ROOT .
"/product/stock/class/mouvementstock.class.php";
580 $constantforkey =
'CASHDESK_ID_WAREHOUSE'.$_SESSION[
"takeposterminal"];
583 $labeltakeposmovement =
'TakePOS - '.$langs->trans(
"CreditNote").
' '.$creditnote->ref;
585 foreach ($creditnote->lines as $line) {
587 $warehouseid = ($line->fk_warehouse ? $line->fk_warehouse :
getDolGlobalInt($constantforkey));
590 if ($line->batch !=
'' && $warehouseid > 0) {
595 $mouvP->setOrigin($creditnote->element, $creditnote->id);
597 $res = $mouvP->reception($user, $line->fk_product, $warehouseid, $line->qty, $line->price, $labeltakeposmovement,
'',
'', $line->batch,
'', 0, $inventorycode);
604 $mouvP->setOrigin($creditnote->element, $creditnote->id);
606 $res = $mouvP->reception($user, $line->fk_product, $warehouseid, $line->qty, $line->price, $labeltakeposmovement,
'',
'',
'',
'', 0, $inventorycode);
616 if (!$error && $res >= 0) {
619 $creditnote->id = $placeid;
624 if (($action ==
'history' || $action ==
'creditnote') && $user->hasRight(
'takepos',
'run')) {
625 if ($action ==
'creditnote' && $creditnote->id > 0) {
626 $placeid = $creditnote->id;
632 $invoice->fetch($placeid);
636 if (($action ==
"addline" || $action ==
"freezone") && $placeid == 0 && ($user->hasRight(
'takepos',
'run') || defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
639 $dolnowtzuserrel =
dol_now(
'tzuserrel');
643 $dateinvoice =
dol_mktime(0, 0, 0, (
int) $monthuser, (
int) $dayuser, (
int) $yearuser,
'tzserver');
645 include_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
646 $invoice->date = $dateinvoice;
648 $invoice->module_source =
'takepos';
649 $invoice->pos_source = isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'' ;
650 $invoice->entity = !empty($_SESSION[
"takeposinvoiceentity"]) ? $_SESSION[
"takeposinvoiceentity"] :
$conf->entity;
652 if ($invoice->socid <= 0) {
653 $langs->load(
'errors');
659 $placeid = $invoice->create($user);
663 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facture";
664 $sql .=
" SET ref='(PROV-POS".$_SESSION[
"takeposterminal"].
"-".$place.
")'";
665 $sql .=
" WHERE rowid = ".((int) $placeid);
666 $resql = $db->query($sql);
680 if ($action ==
"addline" && ($user->hasRight(
'takepos',
'run') || defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
682 $prod->fetch($idproduct);
685 $customer->fetch($invoice->socid);
687 $datapriceofproduct = $prod->getSellPrice($mysoc, $customer, 0);
690 $price = $datapriceofproduct[
'pu_ht'];
691 $price_ttc = $datapriceofproduct[
'pu_ttc'];
693 $price_base_type = empty($datapriceofproduct[
'price_base_type']) ?
'HT' : $datapriceofproduct[
'price_base_type'];
694 $tva_tx = $datapriceofproduct[
'tva_tx'];
695 $tva_npr = $datapriceofproduct[
'tva_npr'];
698 $localtax1_tx =
get_localtax($tva_tx, 1, $customer, $mysoc, $tva_npr);
699 $localtax2_tx =
get_localtax($tva_tx, 2, $customer, $mysoc, $tva_npr);
702 if (isModEnabled(
'productbatch') && isModEnabled(
'stock')) {
703 $batch =
GETPOST(
'batch',
'alpha');
705 if (!empty($batch)) {
706 $action =
"setbatch";
707 } elseif ($prod->status_batch > 0) {
712 $prod->load_stock(
'warehouseopen');
714 $constantforkey =
'CASHDESK_ID_WAREHOUSE'.$_SESSION[
"takeposterminal"];
718 foreach ($prod->stock_warehouse as $tmpwarehouseid => $tmpval) {
723 if (!empty($prod->stock_warehouse[$tmpwarehouseid]) && is_array($prod->stock_warehouse[$tmpwarehouseid]->detail_batch)) {
724 if (is_object($prod->stock_warehouse[$tmpwarehouseid]) && count($prod->stock_warehouse[$tmpwarehouseid]->detail_batch)) {
725 foreach ($prod->stock_warehouse[$tmpwarehouseid]->detail_batch as $dbatch) {
734 echo
"function addbatch(batch, warehouseid) {\n";
735 echo
"console.log('We add batch '+batch+' from warehouse id '+warehouseid);\n";
736 echo
'$("#poslines").load("'.DOL_URL_ROOT.
'/takepos/invoice.php?action=addline&batch="+encodeURI(batch)+"&warehouseid="+warehouseid+"&place='.$place.
'&idproduct='.$idproduct.
'&token='.
newToken().
'", function() {});'.
"\n";
741 echo
"<center>".$langs->trans(
"SearchIntoBatch").
": <b> $nbofsuggested </b></center><br><table>";
742 foreach ($prod->stock_warehouse as $tmpwarehouseid => $tmpval) {
747 if (!empty($prod->stock_warehouse[$tmpwarehouseid]) && is_array($prod->stock_warehouse[$tmpwarehouseid]->detail_batch)) {
748 foreach ($prod->stock_warehouse[$tmpwarehouseid]->detail_batch as $dbatch) {
749 $batchStock = + $dbatch->qty;
750 $quantityToBeDelivered = 1;
751 $deliverableQty = min($quantityToBeDelivered, $batchStock);
753 print
'<!-- subj='.$suggestednb.
'/'.$nbofsuggested.
' -->';
754 print
'<!-- Show details of lot/serial in warehouseid='.$tmpwarehouseid.
' -->';
755 print
'<td class="left">';
757 $detail .=
'<span class="opacitymedium">'.$langs->trans(
"LotSerial").
':</span> '.$dbatch->batch;
764 $detail .=
'</td><td>';
765 $detail .=
'<span class="opacitymedium">'.$langs->trans(
"Qty").
':</span> '.$dbatch->qty;
766 $detail .=
'</td><td>';
767 $detail .=
' <button class="marginleftonly" onclick="addbatch(\''.dol_escape_js($dbatch->batch).
'\',
'.$tmpwarehouseid.')
">'.$langs->trans("Select
")."</
button>
";
771 $quantityToBeDelivered -= $deliverableQty;
772 if ($quantityToBeDelivered < 0) {
773 $quantityToBeDelivered = 0;
782 print '</body></html>';
788 if (getDolGlobalString('TAKEPOS_SUPPLEMENTS')) {
789 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
790 $cat = new Categorie($db);
791 $categories = $cat->containing($idproduct, 'product');
792 $found = (array_search(getDolGlobalInt('TAKEPOS_SUPPLEMENTS_CATEGORY'), array_column($categories, 'id')));
793 if ($found !== false) { // If this product is a supplement
794 $sql = "SELECT fk_parent_line FROM
".MAIN_DB_PREFIX."facturedet where rowid =
".((int) $selectedline);
795 $resql = $db->query($sql);
796 $row = $db->fetch_array($resql);
797 if ($row[0] == null) {
798 $parent_line = $selectedline;
800 $parent_line = $row[0]; //If the parent line is already a supplement, add the supplement to the main product
807 // Group if enabled. Skip group if line already sent to the printer
808 if (getDolGlobalString('TAKEPOS_GROUP_SAME_PRODUCT')) {
809 foreach ($invoice->lines as $line) {
810 if ($line->product_ref == $prod->ref) {
811 if ($line->special_code == 4) {
813 } // If this line is sended to printer create new line
814 // check if qty in stock
815 if (getDolGlobalString('TAKEPOS_QTY_IN_STOCK') && (($line->qty + $qty) > $prod->stock_reel)) {
816 $invoice->error = $langs->trans("ErrorStockIsNotEnough
");
817 dol_htmloutput_errors($invoice->error, $invoice->errors, 1);
821 $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);
823 dol_htmloutput_errors($invoice->error, $invoice->errors, 1);
825 $idoflineadded = $line->id;
831 if ($idoflineadded <= 0 && empty($err)) {
832 $invoice->fetch_thirdparty();
833 $array_options = array();
835 $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);
837 /* setup of margin calculation */
838 if (getDolGlobalString('MARGIN_TYPE')) {
839 if (getDolGlobalString('MARGIN_TYPE') == 'pmp' && !empty($prod->pmp)) {
840 $line['fk_fournprice'] = null;
841 $line['pa_ht'] = $prod->pmp;
842 } elseif (getDolGlobalString('MARGIN_TYPE') == 'costprice' && !empty($prod->cost_price)) {
843 $line['fk_fournprice'] = null;
844 $line['pa_ht'] = $prod->cost_price;
846 // default is fournprice
847 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
848 $pf = new ProductFournisseur($db);
849 if ($pf->find_min_price_product_fournisseur($idproduct, $qty) > 0) {
850 $line['fk_fournprice'] = $pf->product_fourn_price_id;
851 $line['pa_ht'] = $pf->fourn_unitprice_with_discount;
852 if (getDolGlobalString('PRODUCT_CHARGES') && $pf->fourn_charges > 0) {
853 $line['pa_ht'] += (float) $pf->fourn_charges / $pf->fourn_qty;
859 // complete line by hook
860 $parameters = array('prod' => $prod, 'line' => $line);
861 $reshook = $hookmanager->executeHooks('completeTakePosAddLine', $parameters, $invoice, $action); // Note that $action and $line may have been modified by some hooks
863 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
867 if (empty($reshook)) {
868 if (!empty($hookmanager->resArray)) {
869 $line = $hookmanager->resArray;
872 // check if qty in stock
873 if (getDolGlobalString('TAKEPOS_QTY_IN_STOCK') && $qty > $prod->stock_reel) {
874 $invoice->error = $langs->trans("ErrorStockIsNotEnough
");
875 dol_htmloutput_errors($invoice->error, $invoice->errors, 1);
880 $idoflineadded = $invoice->addline($line['description'], $line['price'], $qty, $line['tva_tx'], $line['localtax1_tx'], $line['localtax2_tx'], $idproduct, $line['remise_percent'], '', 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, '', null, 0);
884 if (getDolGlobalString('TAKEPOS_CUSTOMER_DISPLAY')) {
885 $CUSTOMER_DISPLAY_line1 = $prod->label;
886 $CUSTOMER_DISPLAY_line2 = price($price_ttc);
890 $invoice->fetch($placeid);
893 // If we add a line by submitting freezone form (invoice exists here because it was created juste before if it didn't exists)
894 if ($action == "freezone
" && $user->hasRight('takepos', 'run')) {
895 $customer = new Societe($db);
896 $customer->fetch($invoice->socid);
898 $tva_tx = GETPOST('tva_tx', 'alpha');
900 if (!preg_match('/\((.*)\)/', $tva_tx)) {
901 $tva_tx = price2num($tva_tx);
904 $tva_tx = get_default_tva($mysoc, $customer);
908 $localtax1_tx = get_localtax($tva_tx, 1, $customer, $mysoc, $tva_npr);
909 $localtax2_tx = get_localtax($tva_tx, 2, $customer, $mysoc, $tva_npr);
911 $res = $invoice->addline($desc, $number, 1, $tva_tx, $localtax1_tx, $localtax2_tx, 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, null, '', '', 0, 100, '', null, 0);
913 dol_htmloutput_errors($invoice->error, $invoice->errors, 1);
915 $invoice->fetch($placeid);
918 if ($action == "addnote
" && ($user->hasRight('takepos', 'run') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
919 $desc = GETPOST('addnote', 'alpha');
921 $invoice->update_note($desc, '_public');
923 foreach ($invoice->lines as $line) {
924 if ($line->id == $idline) {
925 $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);
929 $invoice->fetch($placeid);
932 if ($action == "deleteline
" && ($user->hasRight('takepos', 'run') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
934 $permissiontoupdateline = ($user->hasRight('takepos', 'editlines') && ($user->hasRight('takepos', 'editorderedlines') || $line->special_code != "4
"));
935 if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
936 if ($invoice->status == $invoice::STATUS_DRAFT && $invoice->pos_source && $invoice->module_source == 'takepos') {
937 $permissiontoupdateline = true;
938 // TODO Add also a test on $_SESSION('publicobjectid'] defined at creation of object
939 // TODO Check also that invoice->ref is (PROV-POS1-2) with 1 = terminal and 2, the table ID
943 if ($idline > 0 && $placeid > 0) { // If invoice exists and line selected. To avoid errors if deleted from another device or no line selected.
944 $invoice->deleteLine($idline);
945 $invoice->fetch($placeid);
946 } elseif ($placeid > 0) { // If invoice exists but no line selected, proceed to delete last line.
947 $sql = "SELECT rowid FROM
".MAIN_DB_PREFIX."facturedet where fk_facture =
".((int) $placeid)." ORDER BY rowid DESC
";
948 $resql = $db->query($sql);
949 $row = $db->fetch_array($resql);
950 $deletelineid = $row[0];
951 $invoice->deleteLine($deletelineid);
952 $invoice->fetch($placeid);
955 if (count($invoice->lines) == 0) {
956 $invoice->delete($user);
958 if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
959 header("Location:
".DOL_URL_ROOT."/takepos/public/auto_order.php
");
961 header("Location:
".DOL_URL_ROOT."/takepos/invoice.php
");
967 // Action to delete or discard an invoice
968 if ($action == "delete
" && ($user->hasRight('takepos', 'run') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
969 // $placeid is the invoice id (it differs from place) and is defined if the place is set and
970 // the ref of invoice is '(PROV-POS'.$_SESSION["takeposterminal
"].'-'.$place.')', so the fetch at beginning of page works.
972 $result = $invoice->fetch($placeid);
974 if ($result > 0 && $invoice->status == Facture::STATUS_DRAFT) {
977 // We delete the lines
979 foreach ($invoice->lines as $line) {
980 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
981 $tmpres = $invoice->deleteLine($line->id);
988 $sql = "UPDATE
".MAIN_DB_PREFIX."facture
";
989 $varforconst = 'CASHDESK_ID_THIRDPARTY'.$_SESSION["takeposterminal
"];
990 $sql .= " SET fk_soc =
".((int) getDolGlobalString($varforconst)).",
";
991 $sql .= " datec =
'".$db->idate(dol_now())."'";
992 $sql .= " WHERE entity IN (
".getEntity('invoice').")
";
993 $sql .= " AND
ref =
'(PROV-POS".$db->escape($_SESSION["takeposterminal"]."-".$place).")'";
994 $resql1 = $db->query($sql);
996 if ($resdeletelines && $resql1) {
1002 $invoice->fetch($placeid);
1007 if ($action == "updateqty
") { // Test on permission is done later
1008 foreach ($invoice->lines as $line) {
1009 if ($line->id == $idline) {
1010 $permissiontoupdateline = ($user->hasRight('takepos', 'editlines') && ($user->hasRight('takepos', 'editorderedlines') || $line->special_code != "4
"));
1011 if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1012 if ($invoice->status == $invoice::STATUS_DRAFT && $invoice->pos_source && $invoice->module_source == 'takepos') {
1013 $permissiontoupdateline = true;
1014 // TODO Add also a test on $_SESSION('publicobjectid'] defined at creation of object
1015 // TODO Check also that invoice->ref is (PROV-POS1-2) with 1 = terminal and 2, the table ID
1018 if (!$permissiontoupdateline) {
1019 dol_htmloutput_errors($langs->trans("NotEnoughPermissions
", "TakePos
").' - No permission to updateqty', [], 1);
1021 $vatratecode = $line->tva_tx;
1022 if ($line->vat_src_code) {
1023 $vatratecode .= ' ('.$line->vat_src_code.')';
1026 $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);
1031 $invoice->fetch($placeid);
1034 if ($action == "updateprice
") { // Test on permission is done later
1035 $customer = new Societe($db);
1036 $customer->fetch($invoice->socid);
1038 foreach ($invoice->lines as $line) {
1039 if ($line->id == $idline) {
1040 $prod = new Product($db);
1041 $prod->fetch($line->fk_product);
1042 $datapriceofproduct = $prod->getSellPrice($mysoc, $customer, 0);
1043 $price_min = $datapriceofproduct['price_min'];
1044 $usercanproductignorepricemin = ((getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !$user->hasRight('produit', 'ignore_price_min_advance')) || !getDolGlobalString('MAIN_USE_ADVANCED_PERMS'));
1046 $vatratecleaned = $line->tva_tx;
1048 if (preg_match('/^(.*)\s*\((.*)\)$/', (string) $line->tva_tx, $reg)) { // If vat is "xx (yy)
"
1049 $vatratecleaned = trim($reg[1]);
1050 //$vatratecode = $reg[2];
1053 $pu_ht = price2num((float) price2num($number, 'MU') / (1 + ((float) $vatratecleaned / 100)), 'MU');
1055 if ($usercanproductignorepricemin && (!empty($price_min) && ((float) price2num($pu_ht) * (1 - (float) price2num($line->remise_percent) / 100) < price2num($price_min)))) {
1056 $langs->load("products
");
1057 dol_htmloutput_errors($langs->trans("CantBeLessThanMinPrice
", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, -1, $conf->currency)));
1058 // echo $langs->trans("CantBeLessThanMinPrice
");
1060 $permissiontoupdateline = ($user->hasRight('takepos', 'editlines') && ($user->hasRight('takepos', 'editorderedlines') || $line->special_code != "4
"));
1061 if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1062 if ($invoice->status == $invoice::STATUS_DRAFT && $invoice->pos_source && $invoice->module_source == 'takepos') {
1063 $permissiontoupdateline = true;
1064 // TODO Add also a test on $_SESSION('publicobjectid'] defined at creation of object
1065 // TODO Check also that invoice->ref is (PROV-POS1-2) with 1 = terminal and 2, the table ID
1069 $vatratecode = $line->tva_tx;
1070 if ($line->vat_src_code) {
1071 $vatratecode .= ' ('.$line->vat_src_code.')';
1074 if (!$permissiontoupdateline) {
1075 dol_htmloutput_errors($langs->trans("NotEnoughPermissions
", "TakePos
").' - No permission to updateprice', [], 1);
1076 } elseif (getDolGlobalInt('TAKEPOS_CHANGE_PRICE_HT') == 1) {
1077 $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);
1079 $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);
1086 $invoice->fetch($placeid);
1089 if ($action == "updatereduction
") { // Test on permission is done later
1090 $customer = new Societe($db);
1091 $customer->fetch($invoice->socid);
1093 foreach ($invoice->lines as $line) {
1094 if ($line->id == $idline) {
1095 dol_syslog("updatereduction Process line
".$line->id.' to apply discount of '.$number.'%');
1097 $prod = new Product($db);
1098 $prod->fetch($line->fk_product);
1100 $datapriceofproduct = $prod->getSellPrice($mysoc, $customer, 0);
1101 $price_min = $datapriceofproduct['price_min'];
1102 $usercanproductignorepricemin = ((getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !$user->hasRight('produit', 'ignore_price_min_advance')) || !getDolGlobalString('MAIN_USE_ADVANCED_PERMS'));
1104 $pu_ht = price2num($line->subprice / (1 + ($line->tva_tx / 100)), 'MU');
1107 if ($usercanproductignorepricemin && (!empty($price_min) && ((float) price2num($line->subprice) * (1 - (float) price2num($number) / 100) < (float) price2num($price_min)))) {
1108 $langs->load("products
");
1109 dol_htmloutput_errors($langs->trans("CantBeLessThanMinPrice
", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, -1, $conf->currency)));
1111 $permissiontoupdateline = ($user->hasRight('takepos', 'editlines') && ($user->hasRight('takepos', 'editorderedlines') || $line->special_code != "4
"));
1112 if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1113 if ($invoice->status == $invoice::STATUS_DRAFT && $invoice->pos_source && $invoice->module_source == 'takepos') {
1114 $permissiontoupdateline = true;
1115 // TODO Add also a test on $_SESSION('publicobjectid'] defined at creation of object
1116 // TODO Check also that invoice->ref is (PROV-POS1-2) with 1 = terminal and 2, the table ID
1119 if (!$permissiontoupdateline) {
1120 dol_htmloutput_errors($langs->trans("NotEnoughPermissions
", "TakePos
"), [], 1);
1122 $vatratecode = $line->tva_tx;
1123 if ($line->vat_src_code) {
1124 $vatratecode .= ' ('.$line->vat_src_code.')';
1126 $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);
1133 $invoice->fetch($placeid);
1134 } elseif ($action == 'update_reduction_global' && $user->hasRight('takepos', 'editlines')) {
1135 foreach ($invoice->lines as $line) {
1136 $vatratecode = $line->tva_tx;
1137 if ($line->vat_src_code) {
1138 $vatratecode .= ' ('.$line->vat_src_code.')';
1140 $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);
1143 $invoice->fetch($placeid);
1146 if ($action == "setbatch
" && ($user->hasRight('takepos', 'run') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
1147 $constantforkey = 'CASHDESK_ID_WAREHOUSE'.$_SESSION["takeposterminal
"];
1148 $warehouseid = (GETPOSTINT('warehouseid') > 0 ? GETPOSTINT('warehouseid') : getDolGlobalInt($constantforkey)); // Get the warehouse id from GETPOSTINT('warehouseid'), otherwise use default setup.
1149 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet SET batch =
'".$db->escape($batch)."', fk_warehouse =
".((int) $warehouseid);
1150 $sql .= " WHERE rowid=
".((int) $idoflineadded);
1154 if ($action == "order
" && $placeid != 0 && ($user->hasRight('takepos', 'run') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
1155 include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
1156 if ((isModEnabled('receiptprinter') && getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term) > 0) || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter
" || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector
") {
1157 require_once DOL_DOCUMENT_ROOT.'/core/class/dolreceiptprinter.class.php';
1158 $printer = new dolReceiptPrinter($db);
1161 $sql = "SELECT label FROM
".MAIN_DB_PREFIX."takepos_floor_tables where rowid=
".((int) $place);
1162 $resql = $db->query($sql);
1163 $row = $db->fetch_object($resql);
1164 $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>';
1165 $footerorder = '</tbody></table>'.dol_print_date(dol_now(), 'dayhour').'<br></html>';
1166 $order_receipt_printer1 = "";
1167 $order_receipt_printer2 = "";
1168 $order_receipt_printer3 = "";
1169 $catsprinter1 = explode(';', getDolGlobalString('TAKEPOS_PRINTED_CATEGORIES_1'));
1170 $catsprinter2 = explode(';', getDolGlobalString('TAKEPOS_PRINTED_CATEGORIES_2'));
1171 $catsprinter3 = explode(';', getDolGlobalString('TAKEPOS_PRINTED_CATEGORIES_3'));
1173 foreach ($invoice->lines as $line) {
1174 if ($line->special_code == "4
") {
1177 $c = new Categorie($db);
1178 $existing = $c->containing($line->fk_product, Categorie::TYPE_PRODUCT, 'id');
1179 $result = array_intersect($catsprinter1, $existing);
1180 $count = count($result);
1181 if (!$line->fk_product) {
1182 $count++; // Print Free-text item (Unassigned printer) to Printer 1
1186 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet set special_code=
'1' where rowid=
".$line->id; //Set to print on printer 1
1188 $order_receipt_printer1 .= '<tr><td class="left
">';
1189 if ($line->fk_product) {
1190 $order_receipt_printer1 .= $line->product_label;
1192 $order_receipt_printer1 .= $line->description;
1194 $order_receipt_printer1 .= '</td><td class="right
">'.$line->qty;
1195 if (!empty($line->array_options['options_order_notes'])) {
1196 $order_receipt_printer1 .= "<br>(
".$line->array_options['options_order_notes'].")
";
1198 $order_receipt_printer1 .= '</td></tr>';
1201 if (((isModEnabled('receiptprinter') && getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term) > 0) || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter
" || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector
") && $linestoprint > 0) {
1202 $invoice->fetch($placeid); //Reload object before send to printer
1203 $printer->orderprinter = 1;
1205 echo "var orderprinter1esc=
'";
1206 $ret = $printer->sendToPrinter($invoice, getDolGlobalInt('TAKEPOS_TEMPLATE_TO_USE_FOR_ORDERS
'.$_SESSION["takeposterminal"]), getDolGlobalInt('TAKEPOS_ORDER_PRINTER1_TO_USE
'.$_SESSION["takeposterminal"])); // PRINT TO PRINTER 1
1209 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet
set special_code=
'4' where special_code=
'1' and fk_facture=
".$invoice->id; // Set as printed
1211 $invoice->fetch($placeid); //Reload object after set lines as printed
1214 foreach ($invoice->lines as $line) {
1215 if ($line->special_code == "4
") {
1218 $c = new Categorie($db);
1219 $existing = $c->containing($line->fk_product, Categorie::TYPE_PRODUCT, 'id');
1220 $result = array_intersect($catsprinter2, $existing);
1221 $count = count($result);
1224 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet
set special_code=
'2' where rowid=
".$line->id; //Set to print on printer 2
1226 $order_receipt_printer2 .= '<tr>'.$line->product_label.'<td class="right
">'.$line->qty;
1227 if (!empty($line->array_options['options_order_notes'])) {
1228 $order_receipt_printer2 .= "<br>(
".$line->array_options['options_order_notes'].")
";
1230 $order_receipt_printer2 .= '</td></tr>';
1233 if (((isModEnabled('receiptprinter') && getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term) > 0) || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter
" || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector
") && $linestoprint > 0) {
1234 $invoice->fetch($placeid); //Reload object before send to printer
1235 $printer->orderprinter = 2;
1237 echo "var orderprinter2esc=
'";
1238 $ret = $printer->sendToPrinter($invoice, getDolGlobalInt('TAKEPOS_TEMPLATE_TO_USE_FOR_ORDERS
'.$_SESSION["takeposterminal"]), getDolGlobalInt('TAKEPOS_ORDER_PRINTER2_TO_USE
'.$_SESSION["takeposterminal"])); // PRINT TO PRINTER 2
1241 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet
set special_code=
'4' where special_code=
'2' and fk_facture=
".$invoice->id; // Set as printed
1243 $invoice->fetch($placeid); //Reload object after set lines as printed
1246 foreach ($invoice->lines as $line) {
1247 if ($line->special_code == "4
") {
1250 $c = new Categorie($db);
1251 $existing = $c->containing($line->fk_product, Categorie::TYPE_PRODUCT, 'id');
1252 $result = array_intersect($catsprinter3, $existing);
1253 $count = count($result);
1256 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet
set special_code=
'3' where rowid=
".$line->id; //Set to print on printer 3
1258 $order_receipt_printer3 .= '<tr>'.$line->product_label.'<td class="right
">'.$line->qty;
1259 if (!empty($line->array_options['options_order_notes'])) {
1260 $order_receipt_printer3 .= "<br>(
".$line->array_options['options_order_notes'].")
";
1262 $order_receipt_printer3 .= '</td></tr>';
1265 if (((isModEnabled('receiptprinter') && getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term) > 0) || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter
" || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector
") && $linestoprint > 0) {
1266 $invoice->fetch($placeid); //Reload object before send to printer
1267 $printer->orderprinter = 3;
1269 echo "var orderprinter3esc=
'";
1270 $ret = $printer->sendToPrinter($invoice, getDolGlobalInt('TAKEPOS_TEMPLATE_TO_USE_FOR_ORDERS
'.$_SESSION["takeposterminal"]), getDolGlobalInt('TAKEPOS_ORDER_PRINTER3_TO_USE
'.$_SESSION["takeposterminal"])); // PRINT TO PRINTER 3
1273 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet
set special_code=
'4' where special_code=
'3' and fk_facture=
".$invoice->id; // Set as printed
1275 $invoice->fetch($placeid); //Reload object after set lines as printed
1278 $sectionwithinvoicelink = '';
1279 if (($action == "valid
" || $action == "history
" || $action == 'creditnote' || ($action == 'addline' && $invoice->status == $invoice::STATUS_CLOSED)) && $user->hasRight('takepos', 'run')) {
1280 $sectionwithinvoicelink .= '<!-- Section with invoice link -->'."\n
";
1281 $sectionwithinvoicelink .= '<span style="font-size:120%;
" class="center
inline-block marginbottomonly
">';
1282 $sectionwithinvoicelink .= $invoice->getNomUrl(1, '', 0, 0, '', 0, 0, -1, '_backoffice')." -
";
1283 $remaintopay = $invoice->getRemainToPay();
1284 if ($remaintopay > 0) {
1285 $sectionwithinvoicelink .= $langs->trans('RemainToPay').': <span class="amountremaintopay
" style="font-size: unset
">'.price($remaintopay, 1, $langs, 1, -1, -1, $conf->currency).'</span>';
1287 $sectionwithinvoicelink .= $invoice->getLibStatut(2);
1290 $sectionwithinvoicelink .= '</span><br>';
1291 if (getDolGlobalInt('TAKEPOS_PRINT_INVOICE_DOC_INSTEAD_OF_RECEIPT')) {
1292 $sectionwithinvoicelink .= ' <a target="_blank
" class="button" href="' . DOL_URL_ROOT . '/document.php?token=
' . newToken() . '&modulepart=facture&file=
' . $invoice->ref . '/
' . $invoice->ref . '.pdf
">Invoice</a>';
1293 } elseif (getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector
") {
1294 if (getDolGlobalString('TAKEPOS_PRINT_SERVER') && filter_var(getDolGlobalString('TAKEPOS_PRINT_SERVER'), FILTER_VALIDATE_URL) == true) {
1295 $sectionwithinvoicelink .= ' <button id="buttonprint
" type="button" onclick="TakeposConnector(
'.$placeid.')
">'.$langs->trans('PrintTicket').'</button>';
1297 $sectionwithinvoicelink .= ' <button id="buttonprint
" type="button" onclick="TakeposPrinting(
'.$placeid.')
">'.$langs->trans('PrintTicket').'</button>';
1299 } elseif ((isModEnabled('receiptprinter') && getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term) > 0) || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter
") {
1300 $sectionwithinvoicelink .= ' <button id="buttonprint
" type="button" onclick="DolibarrTakeposPrinting(
'.$placeid.')
">'.$langs->trans('PrintTicket').'</button>';
1302 $sectionwithinvoicelink .= ' <button id="buttonprint
" type="button" onclick="Print(
'.$placeid.')
">'.$langs->trans('PrintTicket').'</button>';
1303 if (getDolGlobalString('TAKEPOS_PRINT_WITHOUT_DETAILS')) {
1304 $sectionwithinvoicelink .= ' <button id="buttonprint
" type="button" onclick="PrintBox(
'.$placeid.', \
'without_details\')">'.$langs->trans(
'PrintWithoutDetails').
'</button>';
1307 $sectionwithinvoicelink .=
' <button id="buttonprint" type="button" onclick="Print('.$placeid.
', 1)">'.$langs->trans(
'GiftReceipt').
'</button>';
1311 $sectionwithinvoicelink .=
' <button id="buttonsend" type="button" onclick="SendTicket('.$placeid.
')">'.$langs->trans(
'SendTicket').
'</button>';
1314 if ($remaintopay <= 0 &&
getDolGlobalString(
'TAKEPOS_AUTO_PRINT_TICKETS') && $action !=
"history") {
1315 $sectionwithinvoicelink .=
'<script type="text/javascript">$("#buttonprint").click();</script>';
1325$form =
new Form($db);
1328if ((
getDolGlobalString(
'TAKEPOS_PHONE_BASIC_LAYOUT') == 1 &&
$conf->browser->layout ==
'phone') || defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1329 $title =
'TakePOS - Dolibarr '.DOL_VERSION;
1333 $head =
'<meta name="apple-mobile-web-app-title" content="TakePOS"/>
1334 <meta name="apple-mobile-web-app-capable" content="yes">
1335 <meta name="mobile-web-app-capable" content="yes">
1336 <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>';
1337 $arrayofcss = array(
1338 '/takepos/css/pos.css.php',
1340 $arrayofjs = array(
'/takepos/js/jquery.colorbox-min.js');
1343 top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss);
1345 print
'<body>'.
"\n";
1352<script
type=
"text/javascript">
1355<?php
if ($action ==
"valid") {
1356 echo
"var place=0;";
1358var placeid=<?php echo($placeid > 0 ? $placeid : 0); ?>;
1359$(document).ready(
function() {
1360 var idoflineadded = <?php echo(empty($idoflineadded) ? 0 : $idoflineadded); ?>;
1362 $(
'.posinvoiceline').click(
function(){
1363 console.log(
"Click done on "+this.
id);
1364 $(
'.posinvoiceline').removeClass(
"selected");
1365 $(
this).addClass(
"selected");
1369 if (selectedline == this.
id) {
1372 selectedline = this.id;
1374 selectedtext=$(
'#'+selectedline).find(
"td:first").html();
1376 if (defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1377 print
'$("#phonediv1").load("'.DOL_URL_ROOT.
'/takepos/public/auto_order.php?action=editline&token='.
newToken().
'&placeid="+placeid+"&selectedline="+selectedline, function() {
1384 if (idoflineadded > 0)
1386 console.log(
"Auto select "+idoflineadded);
1387 $(
'.posinvoiceline#'+idoflineadded).click();
1391if ($action ==
"order" && !empty($order_receipt_printer1)) {
1392 if (filter_var(
getDolGlobalString(
'TAKEPOS_PRINT_SERVER'), FILTER_VALIDATE_URL) ==
true) {
1396 url:
'<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER
'); ?>/printer/index.php',
1397 data:
'invoice='+orderprinter1esc
1404 url:
'http://<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER
'); ?>:8111/print',
1406 print $headerorder.$order_receipt_printer1.$footerorder; ?>'
1412if ($action ==
"order" && !empty($order_receipt_printer2)) {
1413 if (filter_var(
getDolGlobalString(
'TAKEPOS_PRINT_SERVER'), FILTER_VALIDATE_URL) ==
true) {
1417 url:
'<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER
'); ?>/printer/index.php?printer=2',
1418 data:
'invoice='+orderprinter2esc
1425 url:
'http://<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER
'); ?>:8111/print2',
1427 print $headerorder.$order_receipt_printer2.$footerorder; ?>'
1433if ($action ==
"order" && !empty($order_receipt_printer3)) {
1434 if (filter_var(
getDolGlobalString(
'TAKEPOS_PRINT_SERVER'), FILTER_VALIDATE_URL) ==
true) {
1438 url:
'<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER
'); ?>/printer/index.php?printer=3',
1439 data:
'invoice='+orderprinter3esc
1446if ($action ==
"search" || $action ==
"valid") {
1448 parent.ClearSearch(
true);
1453if ($action ==
"temp" && !empty($ticket_printer1)) {
1457 url:
'http://<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER
'); ?>:8111/print',
1459 print $header_soc.$header_ticket.$body_ticket.$ticket_printer1.$ticket_total.$footer_ticket; ?>'
1464if ($action ==
"search") {
1466 $(
'#search').focus();
1474function SendTicket(
id)
1476 console.log(
"Open box to select the Print/Send form");
1477 $.colorbox({href:
"send.php?facid="+id, width:
"70%", height:
"30%", transition:
"none", iframe:
"true", title:
'<?php echo dol_escape_js($langs->trans("SendTicket")); ?>'});
1481function PrintBox(
id, action) {
1482 console.log(
"Open box before printing");
1483 $.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
"); ?>"});
1487function Print(
id, gift){
1488 console.log(
"Call Print() to generate the receipt.");
1489 $.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")); ?>'});
1493function TakeposPrinting(
id){
1495 console.log(
"TakeposPrinting" +
id);
1496 $.get(
"receipt.php?facid="+
id,
function(data,
status) {
1497 receipt=data.replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g,
'');
1500 url:
'http://<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER
'); ?>:8111/print',
1507function TakeposConnector(
id){
1508 console.log(
"TakeposConnector" +
id);
1509 $.get(
"<?php echo DOL_URL_ROOT; ?>/takepos/ajax/ajax.php?action=printinvoiceticket&token=<?php echo newToken(); ?>&term=<?php echo urlencode(isset($_SESSION["takeposterminal
"]) ? $_SESSION["takeposterminal
"] : ''); ?>&id="+
id+
"&token=<?php echo currentToken(); ?>",
function(data,
status) {
1512 url:
'<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER
'); ?>/printer/index.php',
1513 data:
'invoice='+data
1521function DolibarrTakeposPrinting(
id) {
1522 console.log(
"DolibarrTakeposPrinting Printing invoice ticket " +
id);
1525 data: { token:
'<?php echo currentToken(); ?>' },
1526 url:
"<?php print DOL_URL_ROOT.'/takepos/ajax/ajax.php?action=printinvoiceticket&token='.newToken().'&term='.urlencode(isset($_SESSION["takeposterminal
"]) ? $_SESSION["takeposterminal
"] : '').'&id='; ?>" + id,
1533function CreditNote() {
1534 $(
"#poslines").load(
"<?php print DOL_URL_ROOT; ?>/takepos/invoice.php?action=creditnote&token=<?php echo newToken() ?>&invoiceid="+placeid,
function() { });
1540 $(
"#poslines").load(
"<?php print DOL_URL_ROOT; ?>/takepos/invoice.php?action=addnote&token=<?php echo newToken() ?>&invoiceid="+placeid+
"&idline="+selectedline, {
"addnote": $(
"#textinput").val() });
1545$( document ).ready(
function() {
1546 console.log(
"Set customer info and sales in header placeid=<?php echo $placeid; ?> status=<?php echo $invoice->statut; ?>");
1549 $s = $langs->trans(
"Customer");
1550 if ($invoice->id > 0 && ($invoice->socid !=
getDolGlobalString($constforcompanyid))) {
1553 $contactids = $invoice->getIdContact(
'external',
'BILLING');
1554 $contactid = $contactids[0];
1555 if ($contactid > 0) {
1557 $contact->fetch($contactid);
1558 $s .=
" - " . $contact->getFullName($langs);
1562 print
'$("#idcustomer").val("");';
1566 $(
"#customerandsales").html(
'');
1567 $(
"#shoppingcart").html(
'');
1570 $(
"#customerandsales").append(
'<a class="valignmiddle tdoverflowmax100 minwidth100" id="customer" onclick="Customer();" title="<?php print dol_escape_js(dol_escape_htmltag($s)); ?>"><span class="fas fa-building paddingrightonly"></span><?php print dol_escape_js($s); ?></a>');
1572 $(
"#customerandsales").append(
'<a class="valignmiddle tdoverflowmax300 minwidth100" id="contact" onclick="Contact();" title="<?php print dol_escape_js(dol_escape_htmltag($s)); ?>"><span class="fas fa-building paddingrightonly"></span><?php print dol_escape_js($s); ?></a>');
1576 $sql =
"SELECT rowid, datec, ref FROM ".MAIN_DB_PREFIX.
"facture";
1577 $sql .=
" WHERE entity IN (".getEntity(
'invoice').
")";
1580 $sql .=
" AND ref LIKE '(PROV-POS".$db->escape(isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'').
"-0%'";
1583 $sql .=
" AND pos_source = '".$db->escape($_SESSION[
"takeposterminal"]).
"'";
1584 $sql .=
" AND module_source = 'takepos'";
1587 $sql .= $db->order(
'datec',
'ASC');
1588 $resql = $db->query($sql);
1591 while ($obj = $db->fetch_object($resql)) {
1592 echo
'$("#shoppingcart").append(\'';
1593 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=\\\'';
1594 $num_sale = str_replace(
")",
"", str_replace(
"(PROV-POS".$_SESSION[
"takeposterminal"].
"-",
"", $obj->ref));
1596 if (str_replace(
"-",
"", $num_sale) > $max_sale) {
1597 $max_sale = str_replace(
"-",
"", $num_sale);
1599 echo
'\\\'; invoiceid=\\\'';
1601 echo
'\\\'; Refresh();">';
1602 if ($placeid == $obj->rowid) {
1603 echo
'<span class="basketselected">';
1605 echo
'<span class="basketnotselected">';
1607 echo
'<span class="fa fa-shopping-cart paddingright"></span>'.dol_print_date($db->jdate($obj->datec),
'%H:%M',
'tzuser');
1611 echo
'$("#shoppingcart").append(\'<a onclick="place=\\\'0-';
1613 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>\');';
1621 $constantforkey =
'CASHDESK_NO_DECREASE_STOCK'. (isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
1622 if (isModEnabled(
'stock')) {
1624 $constantforkey =
'CASHDESK_ID_WAREHOUSE'. (isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
1626 if ($idwarehouse > 0) {
1627 $s =
'<span class="small">';
1629 $warehouse->fetch($idwarehouse);
1630 $s .=
'<span class="hideonsmartphone">'.$langs->trans(
"Warehouse").
'<br></span>'.$warehouse->ref;
1632 $s .=
' ('.$langs->trans(
"Closed").
')';
1635 print
"$('#infowarehouse').html('".dol_escape_js($s).
"');";
1636 print
'$("#infowarehouse").css("display", "inline-block");';
1638 $s =
'<span class="small hideonsmartphone">';
1639 $s .= $langs->trans(
"StockChangeDisabled").
'<br>'.$langs->trans(
"NoWarehouseDefinedForTerminal");
1641 print
"$('#infowarehouse').html('".dol_escape_js($s).
"');";
1642 if (!empty(
$conf->dol_optimize_smallscreen)) {
1643 print
'$("#infowarehouse").css("display", "none");';
1647 $s =
'<span class="small hideonsmartphone">'.$langs->trans(
"StockChangeDisabled").
'</span>';
1648 print
"$('#infowarehouse').html('".dol_escape_js($s).
"');";
1649 if (!empty(
$conf->dol_optimize_smallscreen)) {
1650 print
'$("#infowarehouse").css("display", "none");';
1658 if (isModEnabled(
'member') && $invoice->socid > 0 && $invoice->socid !=
getDolGlobalInt($constforcompanyid)) {
1659 $s =
'<span class="small">';
1660 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
1661 $langs->load(
"members");
1662 $s .= $langs->trans(
"Member").
': ';
1664 $result = $adh->fetch(
'',
'', $invoice->socid);
1666 $adh->ref = $adh->getFullName($langs);
1670 $s .= $adh->getFullName($langs);
1671 $s .=
' - '.$adh->type;
1672 if ($adh->datefin) {
1673 $s .=
'<br>'.$langs->trans(
"SubscriptionEndDate").
': '.
dol_print_date($adh->datefin,
'day');
1674 if ($adh->hasDelay()) {
1675 $s .=
" ".img_warning($langs->trans(
"Late"));
1678 $s .=
'<br>'.$langs->trans(
"SubscriptionNotReceived");
1679 if ($adh->statut > 0) {
1680 $s .=
" ".img_warning($langs->trans(
"Late"));
1687 $s .=
'<br>'.$langs->trans(
"ThirdpartyNotLinkedToMember");
1692 $(
"#moreinfo").html(
'<?php print dol_escape_js($s); ?>');
1699 echo
"function CustomerDisplay(){";
1700 echo
"var line1='".$CUSTOMER_DISPLAY_line1.
"'.substring(0,20);";
1701 echo
"line1=line1.padEnd(20);";
1702 echo
"var line2='".$CUSTOMER_DISPLAY_line2.
"'.substring(0,20);";
1703 echo
"line2=line2.padEnd(20);";
1706 data: { text: line1+line2 },
1707 url: '".getDolGlobalString(
'TAKEPOS_PRINT_SERVER').
"/display/index.php',
1718if (!empty(
$conf->use_javascript_ajax)) {
1719 print
"\n".
'<!-- Includes JS Footer of Dolibarr -->'.
"\n";
1720 print
'<script src="'.DOL_URL_ROOT.
'/core/js/lib_foot.js.php?lang='.$langs->defaultlang.
'"></script>'.
"\n";
1723$usediv = (
GETPOST(
'format') ==
'div');
1725print
'<!-- 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";
1726print
'<div class="div-table-responsive-no-min invoice">';
1728 print
'<div id="tablelines">';
1730 print
'<table id="tablelines" class="noborder noshadow postablelines centpercent">';
1733$buttontocreatecreditnote =
'';
1734if (($action ==
"valid" || $action ==
"history" || ($action ==
"addline" && $invoice->status == $invoice::STATUS_CLOSED)) && $invoice->type !=
Facture::TYPE_CREDIT_NOTE && !
getDolGlobalString(
'TAKEPOS_NO_CREDITNOTE')) {
1735 $buttontocreatecreditnote .=
' <!-- Show button to create a credit note -->'.
"\n";
1736 $buttontocreatecreditnote .=
'<button id="buttonprint" type="button" onclick="ModalBox(\'ModalCreditNote\')">'.$langs->trans(
'CreateCreditNote').
'</button>';
1737 if (
getDolGlobalInt(
'TAKEPOS_PRINT_INVOICE_DOC_INSTEAD_OF_RECEIPT')) {
1738 $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>';
1743if ($sectionwithinvoicelink && ($mobilepage ==
"invoice" || $mobilepage ==
"")) {
1744 print
'<!-- Print table line with link to invoice ref -->';
1746 print
'<tr><td colspan="5" class="paddingtopimp paddingbottomimp" style="padding-top: 10px !important; padding-bottom: 10px !important;">';
1747 print $sectionwithinvoicelink;
1748 print $buttontocreatecreditnote;
1751 print
'<tr><td colspan="4" class="paddingtopimp paddingbottomimp" style="padding-top: 10px !important; padding-bottom: 10px !important;">';
1752 print $sectionwithinvoicelink;
1753 print $buttontocreatecreditnote;
1760 print
'<tr class="liste_titre nodrag nodrop">';
1761 print
'<td class="linecoldescription">';
1764if (empty($mobilepage) || $mobilepage ==
"invoice") {
1765 print
'<!-- hidden var used by some js functions -->';
1766 print
'<input type="hidden" name="invoiceid" id="invoiceid" value="'.$invoice->id.
'">';
1767 print
'<input type="hidden" name="thirdpartyid" id="thirdpartyid" value="'.$invoice->socid.
'">';
1771 $sql =
"SELECT floor, label FROM ".MAIN_DB_PREFIX.
"takepos_floor_tables where rowid=".((int) $place);
1772 $resql = $db->query($sql);
1773 $obj = $db->fetch_object($resql);
1775 $label = $obj->label;
1776 $floor = $obj->floor;
1778 if ($mobilepage ==
"invoice" || $mobilepage ==
"") {
1781 print
'<span class="opacitymedium">'.$langs->trans(
'Place').
"</span> <b>".(empty($label) ?
'?' : $label).
"</b><br>";
1782 print
'<span class="opacitymedium">'.$langs->trans(
'Floor').
"</span> <b>".(empty($floor) ?
'?' : $floor).
"</b>";
1789$parameters = array();
1790$reshook = $hookmanager->executeHooks(
'completeTakePosInvoiceHeader', $parameters, $invoice, $action);
1794print $hookmanager->resPrint;
1796if (empty($_SESSION[
"basiclayout"]) || $_SESSION[
"basiclayout"] != 1) {
1798 print
'<td class="linecolqty right">'.$langs->trans(
'PriceUHT').
'</td>';
1800 print
'<td class="linecolqty right">'.$langs->trans(
'ReductionShort').
'</td>';
1801 print
'<td class="linecolqty right">'.$langs->trans(
'Qty').
'</td>';
1803 print
'<td class="linecolht right nowraponall">';
1804 print
'<span class="opacitymedium small">' . $langs->trans(
'TotalHTShort') .
'</span><br>';
1806 if (empty($mobilepage) || $mobilepage ==
"invoice") {
1807 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>';
1808 if (isModEnabled(
'multicurrency') && !empty($_SESSION[
"takeposcustomercurrency"]) &&
$conf->currency != $_SESSION[
"takeposcustomercurrency"]) {
1810 include_once DOL_DOCUMENT_ROOT .
'/multicurrency/class/multicurrency.class.php';
1812 $multicurrency->fetch(0, $_SESSION[
"takeposcustomercurrency"]);
1813 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>';
1818 print
'<td class="linecolht right nowraponall">';
1819 print
'<span class="opacitymedium small">'.$langs->trans(
'TotalTTCShort').
'</span><br>';
1821 if (empty($mobilepage) || $mobilepage ==
"invoice") {
1822 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>';
1823 if (isModEnabled(
'multicurrency') && !empty($_SESSION[
"takeposcustomercurrency"]) &&
$conf->currency != $_SESSION[
"takeposcustomercurrency"]) {
1825 include_once DOL_DOCUMENT_ROOT.
'/multicurrency/class/multicurrency.class.php';
1827 $multicurrency->fetch(0, $_SESSION[
"takeposcustomercurrency"]);
1828 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>';
1832} elseif ($mobilepage ==
"invoice") {
1833 print
'<td class="linecolqty right">'.$langs->trans(
'Qty').
'</td>';
1839if (!empty($_SESSION[
"basiclayout"]) && $_SESSION[
"basiclayout"] == 1) {
1840 if ($mobilepage ==
"cats") {
1841 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1843 $categories = $categorie->get_full_arbo(
'product');
1845 foreach ($categories as $row) {
1846 if (defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1847 $htmlforlines .=
'<div class="leftcat"';
1849 $htmlforlines .=
'<tr class="drag drop oddeven posinvoiceline"';
1851 $htmlforlines .=
' onclick="LoadProducts('.$row[
'id'].
');">';
1852 if (defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1853 $htmlforlines .=
'<img class="imgwrapper" width="33%" src="'.DOL_URL_ROOT.
'/takepos/public/auto_order.php?genimg=cat&query=cat&id='.$row[
'id'].
'"><br>';
1855 $htmlforlines .=
'<td class="left">';
1857 $htmlforlines .= $row[
'label'];
1858 if (defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1859 $htmlforlines .=
'</div>'.
"\n";
1861 $htmlforlines .=
'</td></tr>'.
"\n";
1864 print $htmlforlines;
1867 if ($mobilepage ==
"products") {
1868 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1871 $result =
$object->fetch($catid);
1872 $prods =
$object->getObjectsInCateg(
"product");
1874 foreach ($prods as $row) {
1875 if (defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1876 $htmlforlines .=
'<div class="leftcat"';
1878 $htmlforlines .=
'<tr class="drag drop oddeven posinvoiceline"';
1880 $htmlforlines .=
' onclick="AddProduct(\''.$place.
'\',
'.$row->id.')
"';
1881 $htmlforlines .= '>';
1882 if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1883 $htmlforlines .= '<img class="imgwrapper
" width="33%
" src="'.DOL_URL_ROOT.'/takepos/
public/auto_order.php?genimg=pro&query=pro&
id=
'.$row->id.'"><br>';
1884 $htmlforlines .= $row->label.' '.price($row->price_ttc, 1, $langs, 1, -1, -1, $conf->currency);
1885 $htmlforlines .= '</div>'."\n
";
1887 $htmlforlines .= '<td class="left
">';
1888 $htmlforlines .= $row->label;
1889 $htmlforlines .= '<div class="right
">'.price($row->price_ttc, 1, $langs, 1, -1, -1, $conf->currency).'</div>';
1890 $htmlforlines .= '</td>';
1891 $htmlforlines .= '</tr>'."\n
";
1894 print $htmlforlines;
1897 if ($mobilepage == "places
") {
1898 $sql = "SELECT rowid, entity, label, leftpos, toppos, floor FROM
".MAIN_DB_PREFIX."takepos_floor_tables
";
1899 $resql = $db->query($sql);
1903 while ($row = $db->fetch_array($resql)) {
1905 $htmlforlines .= '<tr class="drag drop oddeven posinvoiceline
';
1906 $htmlforlines .= '" onclick="LoadPlace(\
''.$row[
'label'].
'\')
">';
1907 $htmlforlines .= '<td class="left
">';
1908 $htmlforlines .= $row['label'];
1909 $htmlforlines .= '</td>';
1910 $htmlforlines .= '</tr>'."\n
";
1912 print $htmlforlines;
1917 //In Phone basic layout hide some content depends situation
1918 if (!empty($_SESSION["basiclayout
"]) && $_SESSION["basiclayout
"] == 1 && $mobilepage != "invoice
" && $action != "order
") {
1922 // Loop on each lines on invoice
1923 if (is_array($invoice->lines) && count($invoice->lines)) {
1924 print '<!-- invoice.php show lines of invoices -->'."\n
";
1925 $tmplines = array_reverse($invoice->lines);
1926 $htmlsupplements = array();
1927 foreach ($tmplines as $line) {
1928 if ($line->fk_parent_line != false) {
1929 $htmlsupplements[$line->fk_parent_line] .= '<tr class="drag drop oddeven posinvoiceline
';
1930 if ($line->special_code == "4") {
1931 $htmlsupplements[$line->fk_parent_line] .= ' order
';
1933 $htmlsupplements[$line->fk_parent_line] .= '" id="'.$line->id.'"';
1934 if ($line->special_code == "4
") {
1935 $htmlsupplements[$line->fk_parent_line] .= ' title="'.dol_escape_htmltag($langs->trans("AlreadyPrinted")).'"';
1937 $htmlsupplements[$line->fk_parent_line] .= '>';
1938 $htmlsupplements[$line->fk_parent_line] .= '<td class="left
">';
1939 $htmlsupplements[$line->fk_parent_line] .= img_picto('', 'rightarrow');
1940 if ($line->product_label) {
1941 $htmlsupplements[$line->fk_parent_line] .= $line->product_label;
1943 if ($line->product_label && $line->desc) {
1944 $htmlsupplements[$line->fk_parent_line] .= '<br>';
1946 if ($line->product_label != $line->desc) {
1947 $firstline = dolGetFirstLineOfText($line->desc);
1948 if ($firstline != $line->desc) {
1949 $htmlsupplements[$line->fk_parent_line] .= $form->textwithpicto(dolGetFirstLineOfText($line->desc), $line->desc);
1951 $htmlsupplements[$line->fk_parent_line] .= $line->desc;
1954 $htmlsupplements[$line->fk_parent_line] .= '</td>';
1956 // complete line by hook
1957 $parameters = array('line' => $line);
1958 $reshook = $hookmanager->executeHooks('completeTakePosInvoiceParentLine', $parameters, $invoice, $action); // Note that $action and $object may have been modified by some hooks
1960 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1962 $htmlsupplements[$line->fk_parent_line] .= $hookmanager->resPrint;
1964 if (empty($_SESSION["basiclayout
"]) || $_SESSION["basiclayout
"] != 1) {
1965 $htmlsupplements[$line->fk_parent_line] .= '<td class="right
">'.vatrate(price2num($line->remise_percent), true).'</td>';
1966 $htmlsupplements[$line->fk_parent_line] .= '<td class="right
">'.$line->qty.'</td>';
1967 $htmlsupplements[$line->fk_parent_line] .= '<td class="right
">'.price($line->total_ttc).'</td>';
1969 $htmlsupplements[$line->fk_parent_line] .= '</tr>'."\n
";
1974 $htmlforlines .= '<tr class="drag drop oddeven posinvoiceline
';
1975 if ($line->special_code == "4") {
1976 $htmlforlines .= ' order
';
1978 $htmlforlines .= '" id="'.$line->id.'"';
1979 if ($line->special_code == "4
") {
1980 $htmlforlines .= ' title="'.dol_escape_htmltag($langs->trans("AlreadyPrinted")).'"';
1982 $htmlforlines .= '>';
1983 $htmlforlines .= '<td class="left
">';
1984 if (!empty($_SESSION["basiclayout
"]) && $_SESSION["basiclayout
"] == 1) {
1985 $htmlforlines .= '<span class="phoneqty
">'.$line->qty."</span> x
";
1987 if (isset($line->product_type)) {
1988 if (empty($line->product_type)) {
1989 $htmlforlines .= img_object('', 'product').' ';
1991 $htmlforlines .= img_object('', 'service').' ';
1995 if (!getDolGlobalString('TAKEPOS_SHOW_N_FIRST_LINES')) {
1996 if ($line->product_ref) {
1997 $tooltiptext .= '<b>'.$langs->trans("Ref
").'</b> : '.$line->product_ref.'<br>';
1998 $tooltiptext .= '<b>'.$langs->trans("Label
").'</b> : '.$line->product_label.'<br>';
1999 if (!empty($line->batch)) {
2000 $tooltiptext .= '<br><b>'.$langs->trans("LotSerial
").'</b> : '.$line->batch.'<br>';
2002 if (!empty($line->fk_warehouse)) {
2003 $tooltiptext .= '<b>'.$langs->trans("Warehouse
").'</b> : '.$line->fk_warehouse.'<br>';
2005 if ($line->product_label != $line->desc) {
2007 $tooltiptext .= '<br>';
2009 $tooltiptext .= $line->desc;
2012 if (getDolGlobalInt('TAKEPOS_SHOW_PRODUCT_REFERENCE') == 1) {
2013 $htmlforlines .= $form->textwithpicto($line->product_label ? '<b>' . $line->product_ref . '</b> - ' . $line->product_label : dolGetFirstLineOfText($line->desc, 1), $tooltiptext);
2014 } elseif (getDolGlobalInt('TAKEPOS_SHOW_PRODUCT_REFERENCE') == 2) {
2015 $htmlforlines .= $form->textwithpicto($line->product_ref ? '<b>'.$line->product_ref.'<b>' : dolGetFirstLineOfText($line->desc, 1), $tooltiptext);
2017 $htmlforlines .= $form->textwithpicto($line->product_label ? $line->product_label : ($line->product_ref ? $line->product_ref : dolGetFirstLineOfText($line->desc, 1)), $tooltiptext);
2020 if ($line->product_ref) {
2021 $tooltiptext .= '<b>'.$langs->trans("Ref
").'</b> : '.$line->product_ref.'<br>';
2022 $tooltiptext .= '<b>'.$langs->trans("Label
").'</b> : '.$line->product_label.'<br>';
2024 if (!empty($line->batch)) {
2025 $tooltiptext .= '<br><b>'.$langs->trans("LotSerial
").'</b> : '.$line->batch.'<br>';
2027 if (!empty($line->fk_warehouse)) {
2028 $tooltiptext .= '<b>'.$langs->trans("Warehouse
").'</b> : '.$line->fk_warehouse.'<br>';
2031 if ($line->product_label) {
2032 $htmlforlines .= $line->product_label;
2034 if ($line->product_label != $line->desc) {
2035 if ($line->product_label && $line->desc) {
2036 $htmlforlines .= '<br>';
2038 $firstline = dolGetFirstLineOfText($line->desc, getDolGlobalInt('TAKEPOS_SHOW_N_FIRST_LINES'));
2039 if ($firstline != $line->desc) {
2040 $htmlforlines .= $form->textwithpicto(dolGetFirstLineOfText($line->desc), $line->desc);
2042 $htmlforlines .= $line->desc;
2046 if (!empty($line->array_options['options_order_notes'])) {
2047 $htmlforlines .= "<br>(
".$line->array_options['options_order_notes'].")
";
2049 if (!empty($_SESSION["basiclayout
"]) && $_SESSION["basiclayout
"] == 1) {
2050 $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>';
2052 if (empty($_SESSION["basiclayout
"]) || $_SESSION["basiclayout
"] != 1) {
2054 $moreinfo .= $langs->transcountry("TotalHT
", $mysoc->country_code).': '.price($line->total_ht);
2055 if ($line->vat_src_code) {
2056 $moreinfo .= '<br>'.$langs->trans("VATCode
").': '.$line->vat_src_code;
2058 $moreinfo .= '<br>'.$langs->transcountry("TotalVAT
", $mysoc->country_code).': '.price($line->total_tva);
2059 $moreinfo .= '<br>'.$langs->transcountry("TotalLT1
", $mysoc->country_code).': '.price($line->total_localtax1);
2060 $moreinfo .= '<br>'.$langs->transcountry("TotalLT2
", $mysoc->country_code).': '.price($line->total_localtax2);
2061 $moreinfo .= '<hr>';
2062 $moreinfo .= $langs->transcountry("TotalTTC
", $mysoc->country_code).': '.price($line->total_ttc);
2063 //$moreinfo .= $langs->trans("TotalHT
").': '.$line->total_ht;
2064 if ($line->date_start || $line->date_end) {
2065 $htmlforlines .= '<br><div class="clearboth nowraponall
">'.get_date_range($line->date_start, $line->date_end).'</div>';
2067 $htmlforlines .= '</td>';
2069 // complete line by hook
2070 $parameters = array('line' => $line);
2071 $reshook = $hookmanager->executeHooks('completeTakePosInvoiceLine', $parameters, $invoice, $action); // Note that $action and $object may have been modified by some hooks
2073 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
2075 $htmlforlines .= $hookmanager->resPrint;
2077 if (getDolGlobalInt("TAKEPOS_SHOW_SUBPRICE
")) {
2078 $htmlforlines .= '<td class="right
">'.price($line->subprice).'</td>';
2080 $htmlforlines .= '<td class="right
">'.vatrate(price2num($line->remise_percent), true).'</td>';
2081 $htmlforlines .= '<td class="right
">';
2082 if (isModEnabled('stock') && $user->hasRight('stock', 'mouvement', 'lire')) {
2083 $constantforkey = 'CASHDESK_ID_WAREHOUSE'.$_SESSION["takeposterminal
"];
2084 if (getDolGlobalString($constantforkey) && $line->fk_product > 0 && !getDolGlobalString('TAKEPOS_HIDE_STOCK_ON_LINE')) {
2085 $sql = "SELECT e.rowid, e.ref, e.lieu, e.fk_parent, e.statut, ps.reel, ps.rowid as product_stock_id, p.pmp
";
2086 $sql .= " FROM
".MAIN_DB_PREFIX."entrepot as e,
";
2087 $sql .= " ".MAIN_DB_PREFIX."product_stock as ps
";
2088 $sql .= " LEFT JOIN
".MAIN_DB_PREFIX."product as p ON p.rowid = ps.fk_product
";
2089 $sql .= " WHERE ps.reel != 0
";
2090 $sql .= " AND ps.fk_entrepot =
".((int) getDolGlobalString($constantforkey));
2091 $sql .= " AND e.entity IN (
".getEntity('stock').")
";
2092 $sql .= " AND ps.fk_product =
".((int) $line->fk_product);
2093 $resql = $db->query($sql);
2096 $obj = $db->fetch_object($resql);
2098 $stock_real = price2num($obj->reel, 'MS');
2100 $htmlforlines .= $line->qty;
2101 $htmlforlines .= ' ';
2102 $htmlforlines .= '<span class="opacitylow
" title="'.$langs->trans("Stock").' '.price($stock_real, 1, '', 1, 0).'">';
2103 $htmlforlines .= '(';
2104 if ($line->qty && $line->qty > $stock_real) {
2105 $htmlforlines .= '<span style="color: var(--amountremaintopaycolor)
">';
2107 $htmlforlines .= img_picto('', 'stock', 'class="pictofixedwidth
"').price($stock_real, 1, '', 1, 0);
2108 if ($line->qty && $line->qty > $stock_real) {
2109 $htmlforlines .= "</span>
";
2111 $htmlforlines .= ')';
2112 $htmlforlines .= '</span>';
2114 dol_print_error($db);
2117 $htmlforlines .= $line->qty;
2120 $htmlforlines .= $line->qty;
2123 $htmlforlines .= '</td>';
2124 if (getDolGlobalInt('TAKEPOS_SHOW_HT')) {
2125 $htmlforlines .= '<td class="right classfortooltip
" title="'.$moreinfo.'">';
2126 $htmlforlines .= price($line->total_ht, 1, '', 1, -1, -1, $conf->currency);
2127 if (isModEnabled('multicurrency') && !empty($_SESSION["takeposcustomercurrency
"]) && $conf->currency != $_SESSION["takeposcustomercurrency
"]) {
2128 //Only show customer currency if multicurrency module is enabled, if currency selected and if this currency selected is not the same as main currency
2129 include_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php';
2130 $multicurrency = new MultiCurrency($db);
2131 $multicurrency->fetch(0, $_SESSION["takeposcustomercurrency
"]);
2132 $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>';
2134 $htmlforlines .= '</td>';
2136 $htmlforlines .= '<td class="right classfortooltip
" title="'.$moreinfo.'">';
2137 $htmlforlines .= price($line->total_ttc, 1, '', 1, -1, -1, $conf->currency);
2138 if (isModEnabled('multicurrency') && !empty($_SESSION["takeposcustomercurrency
"]) && $conf->currency != $_SESSION["takeposcustomercurrency
"]) {
2139 //Only show customer currency if multicurrency module is enabled, if currency selected and if this currency selected is not the same as main currency
2140 include_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php';
2141 $multicurrency = new MultiCurrency($db);
2142 $multicurrency->fetch(0, $_SESSION["takeposcustomercurrency
"]);
2143 $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>';
2145 $htmlforlines .= '</td>';
2147 $htmlforlines .= '</tr>'."\n
";
2148 $htmlforlines .= empty($htmlsupplements[$line->id]) ? '' : $htmlsupplements[$line->id];
2150 print $htmlforlines;
2153 print '<tr class="drag drop oddeven
"><td class="left
"><span class="opacitymedium
">'.$langs->trans("Empty
").'</span></td><td></td>';
2154 if (empty($_SESSION["basiclayout
"]) || $_SESSION["basiclayout
"] != 1) {
2155 print '<td></td><td></td>';
2156 if (getDolGlobalString('TAKEPOS_SHOW_HT')) {
2162} else { // No invoice generated yet
2163 print '<tr class="drag drop oddeven
"><td class="left
"><span class="opacitymedium
">'.$langs->trans("Empty
").'</span></td><td></td>';
2164 if (empty($_SESSION["basiclayout
"]) || $_SESSION["basiclayout
"] != 1) {
2165 print '<td></td><td></td>';
2166 if (getDolGlobalString('TAKEPOS_SHOW_HT')) {
2179if ($action == "search
") {
2181 <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
')).'">
2188if ((getDolGlobalString('TAKEPOS_PHONE_BASIC_LAYOUT') == 1 && $conf->browser->layout == 'phone') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
2189 print '</body></html>';