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 include_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
642 $invoice->module_source =
'takepos';
643 $invoice->pos_source = isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'' ;
644 $invoice->entity = !empty($_SESSION[
"takeposinvoiceentity"]) ? $_SESSION[
"takeposinvoiceentity"] :
$conf->entity;
646 if ($invoice->socid <= 0) {
647 $langs->load(
'errors');
653 $placeid = $invoice->create($user);
657 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facture";
658 $sql .=
" SET ref='(PROV-POS".$_SESSION[
"takeposterminal"].
"-".$place.
")'";
659 $sql .=
" WHERE rowid = ".((int) $placeid);
660 $resql = $db->query($sql);
674 if ($action ==
"addline" && ($user->hasRight(
'takepos',
'run') || defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
676 $prod->fetch($idproduct);
679 $customer->fetch($invoice->socid);
681 $datapriceofproduct = $prod->getSellPrice($mysoc, $customer, 0);
684 $price = $datapriceofproduct[
'pu_ht'];
685 $price_ttc = $datapriceofproduct[
'pu_ttc'];
687 $price_base_type = empty($datapriceofproduct[
'price_base_type']) ?
'HT' : $datapriceofproduct[
'price_base_type'];
688 $tva_tx = $datapriceofproduct[
'tva_tx'];
689 $tva_npr = $datapriceofproduct[
'tva_npr'];
692 $localtax1_tx =
get_localtax($tva_tx, 1, $customer, $mysoc, $tva_npr);
693 $localtax2_tx =
get_localtax($tva_tx, 2, $customer, $mysoc, $tva_npr);
696 if (isModEnabled(
'productbatch') && isModEnabled(
'stock')) {
697 $batch =
GETPOST(
'batch',
'alpha');
699 if (!empty($batch)) {
700 $action =
"setbatch";
701 } elseif ($prod->status_batch > 0) {
706 $prod->load_stock(
'warehouseopen');
708 $constantforkey =
'CASHDESK_ID_WAREHOUSE'.$_SESSION[
"takeposterminal"];
712 foreach ($prod->stock_warehouse as $tmpwarehouseid => $tmpval) {
717 if (!empty($prod->stock_warehouse[$tmpwarehouseid]) && is_array($prod->stock_warehouse[$tmpwarehouseid]->detail_batch)) {
718 if (is_object($prod->stock_warehouse[$tmpwarehouseid]) && count($prod->stock_warehouse[$tmpwarehouseid]->detail_batch)) {
719 foreach ($prod->stock_warehouse[$tmpwarehouseid]->detail_batch as $dbatch) {
728 echo
"function addbatch(batch, warehouseid) {\n";
729 echo
"console.log('We add batch '+batch+' from warehouse id '+warehouseid);\n";
730 echo
'$("#poslines").load("'.DOL_URL_ROOT.
'/takepos/invoice.php?action=addline&batch="+encodeURI(batch)+"&warehouseid="+warehouseid+"&place='.$place.
'&idproduct='.$idproduct.
'&token='.
newToken().
'", function() {});'.
"\n";
735 echo
"<center>".$langs->trans(
"SearchIntoBatch").
": <b> $nbofsuggested </b></center><br><table>";
736 foreach ($prod->stock_warehouse as $tmpwarehouseid => $tmpval) {
741 if (!empty($prod->stock_warehouse[$tmpwarehouseid]) && is_array($prod->stock_warehouse[$tmpwarehouseid]->detail_batch)) {
742 foreach ($prod->stock_warehouse[$tmpwarehouseid]->detail_batch as $dbatch) {
743 $batchStock = + $dbatch->qty;
744 $quantityToBeDelivered = 1;
745 $deliverableQty = min($quantityToBeDelivered, $batchStock);
747 print
'<!-- subj='.$suggestednb.
'/'.$nbofsuggested.
' -->';
748 print
'<!-- Show details of lot/serial in warehouseid='.$tmpwarehouseid.
' -->';
749 print
'<td class="left">';
751 $detail .=
'<span class="opacitymedium">'.$langs->trans(
"LotSerial").
':</span> '.$dbatch->batch;
758 $detail .=
'</td><td>';
759 $detail .=
'<span class="opacitymedium">'.$langs->trans(
"Qty").
':</span> '.$dbatch->qty;
760 $detail .=
'</td><td>';
761 $detail .=
' <button class="marginleftonly" onclick="addbatch(\''.dol_escape_js($dbatch->batch).
'\',
'.$tmpwarehouseid.')
">'.$langs->trans("Select
")."</
button>
";
765 $quantityToBeDelivered -= $deliverableQty;
766 if ($quantityToBeDelivered < 0) {
767 $quantityToBeDelivered = 0;
776 print '</body></html>';
782 if (getDolGlobalString('TAKEPOS_SUPPLEMENTS')) {
783 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
784 $cat = new Categorie($db);
785 $categories = $cat->containing($idproduct, 'product');
786 $found = (array_search(getDolGlobalInt('TAKEPOS_SUPPLEMENTS_CATEGORY'), array_column($categories, 'id')));
787 if ($found !== false) { // If this product is a supplement
788 $sql = "SELECT fk_parent_line FROM
".MAIN_DB_PREFIX."facturedet where rowid =
".((int) $selectedline);
789 $resql = $db->query($sql);
790 $row = $db->fetch_array($resql);
791 if ($row[0] == null) {
792 $parent_line = $selectedline;
794 $parent_line = $row[0]; //If the parent line is already a supplement, add the supplement to the main product
801 // Group if enabled. Skip group if line already sent to the printer
802 if (getDolGlobalString('TAKEPOS_GROUP_SAME_PRODUCT')) {
803 foreach ($invoice->lines as $line) {
804 if ($line->product_ref == $prod->ref) {
805 if ($line->special_code == 4) {
807 } // If this line is sended to printer create new line
808 // check if qty in stock
809 if (getDolGlobalString('TAKEPOS_QTY_IN_STOCK') && (($line->qty + $qty) > $prod->stock_reel)) {
810 $invoice->error = $langs->trans("ErrorStockIsNotEnough
");
811 dol_htmloutput_errors($invoice->error, $invoice->errors, 1);
815 $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);
817 dol_htmloutput_errors($invoice->error, $invoice->errors, 1);
819 $idoflineadded = $line->id;
825 if ($idoflineadded <= 0 && empty($err)) {
826 $invoice->fetch_thirdparty();
827 $array_options = array();
829 $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);
831 /* setup of margin calculation */
832 if (getDolGlobalString('MARGIN_TYPE')) {
833 if (getDolGlobalString('MARGIN_TYPE') == 'pmp' && !empty($prod->pmp)) {
834 $line['fk_fournprice'] = null;
835 $line['pa_ht'] = $prod->pmp;
836 } elseif (getDolGlobalString('MARGIN_TYPE') == 'costprice' && !empty($prod->cost_price)) {
837 $line['fk_fournprice'] = null;
838 $line['pa_ht'] = $prod->cost_price;
840 // default is fournprice
841 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
842 $pf = new ProductFournisseur($db);
843 if ($pf->find_min_price_product_fournisseur($idproduct, $qty) > 0) {
844 $line['fk_fournprice'] = $pf->product_fourn_price_id;
845 $line['pa_ht'] = $pf->fourn_unitprice_with_discount;
846 if (getDolGlobalString('PRODUCT_CHARGES') && $pf->fourn_charges > 0) {
847 $line['pa_ht'] += (float) $pf->fourn_charges / $pf->fourn_qty;
853 // complete line by hook
854 $parameters = array('prod' => $prod, 'line' => $line);
855 $reshook = $hookmanager->executeHooks('completeTakePosAddLine', $parameters, $invoice, $action); // Note that $action and $line may have been modified by some hooks
857 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
861 if (empty($reshook)) {
862 if (!empty($hookmanager->resArray)) {
863 $line = $hookmanager->resArray;
866 // check if qty in stock
867 if (getDolGlobalString('TAKEPOS_QTY_IN_STOCK') && $qty > $prod->stock_reel) {
868 $invoice->error = $langs->trans("ErrorStockIsNotEnough
");
869 dol_htmloutput_errors($invoice->error, $invoice->errors, 1);
874 $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);
878 if (getDolGlobalString('TAKEPOS_CUSTOMER_DISPLAY')) {
879 $CUSTOMER_DISPLAY_line1 = $prod->label;
880 $CUSTOMER_DISPLAY_line2 = price($price_ttc);
884 $invoice->fetch($placeid);
887 // If we add a line by submitting freezone form (invoice exists here because it was created juste before if it didn't exists)
888 if ($action == "freezone
" && $user->hasRight('takepos', 'run')) {
889 $customer = new Societe($db);
890 $customer->fetch($invoice->socid);
892 $tva_tx = GETPOST('tva_tx', 'alpha');
894 if (!preg_match('/\((.*)\)/', $tva_tx)) {
895 $tva_tx = price2num($tva_tx);
898 $tva_tx = get_default_tva($mysoc, $customer);
902 $localtax1_tx = get_localtax($tva_tx, 1, $customer, $mysoc, $tva_npr);
903 $localtax2_tx = get_localtax($tva_tx, 2, $customer, $mysoc, $tva_npr);
905 $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);
907 dol_htmloutput_errors($invoice->error, $invoice->errors, 1);
909 $invoice->fetch($placeid);
912 if ($action == "addnote
" && ($user->hasRight('takepos', 'run') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
913 $desc = GETPOST('addnote', 'alpha');
915 $invoice->update_note($desc, '_public');
917 foreach ($invoice->lines as $line) {
918 if ($line->id == $idline) {
919 $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);
923 $invoice->fetch($placeid);
926 if ($action == "deleteline
" && ($user->hasRight('takepos', 'run') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
928 $permissiontoupdateline = ($user->hasRight('takepos', 'editlines') && ($user->hasRight('takepos', 'editorderedlines') || $line->special_code != "4
"));
929 if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
930 if ($invoice->status == $invoice::STATUS_DRAFT && $invoice->pos_source && $invoice->module_source == 'takepos') {
931 $permissiontoupdateline = true;
932 // TODO Add also a test on $_SESSION('publicobjectid'] defined at creation of object
933 // TODO Check also that invoice->ref is (PROV-POS1-2) with 1 = terminal and 2, the table ID
937 if ($idline > 0 && $placeid > 0) { // If invoice exists and line selected. To avoid errors if deleted from another device or no line selected.
938 $invoice->deleteLine($idline);
939 $invoice->fetch($placeid);
940 } elseif ($placeid > 0) { // If invoice exists but no line selected, proceed to delete last line.
941 $sql = "SELECT rowid FROM
".MAIN_DB_PREFIX."facturedet where fk_facture =
".((int) $placeid)." ORDER BY rowid DESC
";
942 $resql = $db->query($sql);
943 $row = $db->fetch_array($resql);
944 $deletelineid = $row[0];
945 $invoice->deleteLine($deletelineid);
946 $invoice->fetch($placeid);
949 if (count($invoice->lines) == 0) {
950 $invoice->delete($user);
952 if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
953 header("Location:
".DOL_URL_ROOT."/takepos/public/auto_order.php
");
955 header("Location:
".DOL_URL_ROOT."/takepos/invoice.php
");
961 // Action to delete or discard an invoice
962 if ($action == "delete
" && ($user->hasRight('takepos', 'run') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
963 // $placeid is the invoice id (it differs from place) and is defined if the place is set and
964 // the ref of invoice is '(PROV-POS'.$_SESSION["takeposterminal
"].'-'.$place.')', so the fetch at beginning of page works.
966 $result = $invoice->fetch($placeid);
968 if ($result > 0 && $invoice->status == Facture::STATUS_DRAFT) {
971 // We delete the lines
973 foreach ($invoice->lines as $line) {
974 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
975 $tmpres = $invoice->deleteLine($line->id);
982 $sql = "UPDATE
".MAIN_DB_PREFIX."facture
";
983 $varforconst = 'CASHDESK_ID_THIRDPARTY'.$_SESSION["takeposterminal
"];
984 $sql .= " SET fk_soc =
".((int) getDolGlobalString($varforconst)).",
";
985 $sql .= " datec =
'".$db->idate(dol_now())."'";
986 $sql .= " WHERE entity IN (
".getEntity('invoice').")
";
987 $sql .= " AND
ref =
'(PROV-POS".$db->escape($_SESSION["takeposterminal"]."-".$place).")'";
988 $resql1 = $db->query($sql);
990 if ($resdeletelines && $resql1) {
996 $invoice->fetch($placeid);
1001 if ($action == "updateqty
") { // Test on permission is done later
1002 foreach ($invoice->lines as $line) {
1003 if ($line->id == $idline) {
1004 $permissiontoupdateline = ($user->hasRight('takepos', 'editlines') && ($user->hasRight('takepos', 'editorderedlines') || $line->special_code != "4
"));
1005 if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1006 if ($invoice->status == $invoice::STATUS_DRAFT && $invoice->pos_source && $invoice->module_source == 'takepos') {
1007 $permissiontoupdateline = true;
1008 // TODO Add also a test on $_SESSION('publicobjectid'] defined at creation of object
1009 // TODO Check also that invoice->ref is (PROV-POS1-2) with 1 = terminal and 2, the table ID
1012 if (!$permissiontoupdateline) {
1013 dol_htmloutput_errors($langs->trans("NotEnoughPermissions
", "TakePos
").' - No permission to updateqty', [], 1);
1015 $vatratecode = $line->tva_tx;
1016 if ($line->vat_src_code) {
1017 $vatratecode .= ' ('.$line->vat_src_code.')';
1020 $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);
1025 $invoice->fetch($placeid);
1028 if ($action == "updateprice
") { // Test on permission is done later
1029 $customer = new Societe($db);
1030 $customer->fetch($invoice->socid);
1032 foreach ($invoice->lines as $line) {
1033 if ($line->id == $idline) {
1034 $prod = new Product($db);
1035 $prod->fetch($line->fk_product);
1036 $datapriceofproduct = $prod->getSellPrice($mysoc, $customer, 0);
1037 $price_min = $datapriceofproduct['price_min'];
1038 $usercanproductignorepricemin = ((getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !$user->hasRight('produit', 'ignore_price_min_advance')) || !getDolGlobalString('MAIN_USE_ADVANCED_PERMS'));
1040 $vatratecleaned = $line->tva_tx;
1042 if (preg_match('/^(.*)\s*\((.*)\)$/', (string) $line->tva_tx, $reg)) { // If vat is "xx (yy)
"
1043 $vatratecleaned = trim($reg[1]);
1044 //$vatratecode = $reg[2];
1047 $pu_ht = price2num((float) price2num($number, 'MU') / (1 + ((float) $vatratecleaned / 100)), 'MU');
1049 if ($usercanproductignorepricemin && (!empty($price_min) && ((float) price2num($pu_ht) * (1 - (float) price2num($line->remise_percent) / 100) < price2num($price_min)))) {
1050 $langs->load("products
");
1051 dol_htmloutput_errors($langs->trans("CantBeLessThanMinPrice
", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, -1, $conf->currency)));
1052 // echo $langs->trans("CantBeLessThanMinPrice
");
1054 $permissiontoupdateline = ($user->hasRight('takepos', 'editlines') && ($user->hasRight('takepos', 'editorderedlines') || $line->special_code != "4
"));
1055 if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1056 if ($invoice->status == $invoice::STATUS_DRAFT && $invoice->pos_source && $invoice->module_source == 'takepos') {
1057 $permissiontoupdateline = true;
1058 // TODO Add also a test on $_SESSION('publicobjectid'] defined at creation of object
1059 // TODO Check also that invoice->ref is (PROV-POS1-2) with 1 = terminal and 2, the table ID
1063 $vatratecode = $line->tva_tx;
1064 if ($line->vat_src_code) {
1065 $vatratecode .= ' ('.$line->vat_src_code.')';
1068 if (!$permissiontoupdateline) {
1069 dol_htmloutput_errors($langs->trans("NotEnoughPermissions
", "TakePos
").' - No permission to updateprice', [], 1);
1070 } elseif (getDolGlobalInt('TAKEPOS_CHANGE_PRICE_HT') == 1) {
1071 $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);
1073 $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);
1080 $invoice->fetch($placeid);
1083 if ($action == "updatereduction
") { // Test on permission is done later
1084 $customer = new Societe($db);
1085 $customer->fetch($invoice->socid);
1087 foreach ($invoice->lines as $line) {
1088 if ($line->id == $idline) {
1089 dol_syslog("updatereduction Process line
".$line->id.' to apply discount of '.$number.'%');
1091 $prod = new Product($db);
1092 $prod->fetch($line->fk_product);
1094 $datapriceofproduct = $prod->getSellPrice($mysoc, $customer, 0);
1095 $price_min = $datapriceofproduct['price_min'];
1096 $usercanproductignorepricemin = ((getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !$user->hasRight('produit', 'ignore_price_min_advance')) || !getDolGlobalString('MAIN_USE_ADVANCED_PERMS'));
1098 $pu_ht = price2num($line->subprice / (1 + ($line->tva_tx / 100)), 'MU');
1101 if ($usercanproductignorepricemin && (!empty($price_min) && ((float) price2num($line->subprice) * (1 - (float) price2num($number) / 100) < (float) price2num($price_min)))) {
1102 $langs->load("products
");
1103 dol_htmloutput_errors($langs->trans("CantBeLessThanMinPrice
", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, -1, $conf->currency)));
1105 $permissiontoupdateline = ($user->hasRight('takepos', 'editlines') && ($user->hasRight('takepos', 'editorderedlines') || $line->special_code != "4
"));
1106 if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1107 if ($invoice->status == $invoice::STATUS_DRAFT && $invoice->pos_source && $invoice->module_source == 'takepos') {
1108 $permissiontoupdateline = true;
1109 // TODO Add also a test on $_SESSION('publicobjectid'] defined at creation of object
1110 // TODO Check also that invoice->ref is (PROV-POS1-2) with 1 = terminal and 2, the table ID
1113 if (!$permissiontoupdateline) {
1114 dol_htmloutput_errors($langs->trans("NotEnoughPermissions
", "TakePos
"), [], 1);
1116 $vatratecode = $line->tva_tx;
1117 if ($line->vat_src_code) {
1118 $vatratecode .= ' ('.$line->vat_src_code.')';
1120 $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);
1127 $invoice->fetch($placeid);
1128 } elseif ($action == 'update_reduction_global' && $user->hasRight('takepos', 'editlines')) {
1129 foreach ($invoice->lines as $line) {
1130 $vatratecode = $line->tva_tx;
1131 if ($line->vat_src_code) {
1132 $vatratecode .= ' ('.$line->vat_src_code.')';
1134 $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);
1137 $invoice->fetch($placeid);
1140 if ($action == "setbatch
" && ($user->hasRight('takepos', 'run') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
1141 $constantforkey = 'CASHDESK_ID_WAREHOUSE'.$_SESSION["takeposterminal
"];
1142 $warehouseid = (GETPOSTINT('warehouseid') > 0 ? GETPOSTINT('warehouseid') : getDolGlobalInt($constantforkey)); // Get the warehouse id from GETPOSTINT('warehouseid'), otherwise use default setup.
1143 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet SET batch =
'".$db->escape($batch)."', fk_warehouse =
".((int) $warehouseid);
1144 $sql .= " WHERE rowid=
".((int) $idoflineadded);
1148 if ($action == "order
" && $placeid != 0 && ($user->hasRight('takepos', 'run') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
1149 include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
1150 if ((isModEnabled('receiptprinter') && getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term) > 0) || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter
" || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector
") {
1151 require_once DOL_DOCUMENT_ROOT.'/core/class/dolreceiptprinter.class.php';
1152 $printer = new dolReceiptPrinter($db);
1155 $sql = "SELECT label FROM
".MAIN_DB_PREFIX."takepos_floor_tables where rowid=
".((int) $place);
1156 $resql = $db->query($sql);
1157 $row = $db->fetch_object($resql);
1158 $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>';
1159 $footerorder = '</tbody></table>'.dol_print_date(dol_now(), 'dayhour').'<br></html>';
1160 $order_receipt_printer1 = "";
1161 $order_receipt_printer2 = "";
1162 $order_receipt_printer3 = "";
1163 $catsprinter1 = explode(';', getDolGlobalString('TAKEPOS_PRINTED_CATEGORIES_1'));
1164 $catsprinter2 = explode(';', getDolGlobalString('TAKEPOS_PRINTED_CATEGORIES_2'));
1165 $catsprinter3 = explode(';', getDolGlobalString('TAKEPOS_PRINTED_CATEGORIES_3'));
1167 foreach ($invoice->lines as $line) {
1168 if ($line->special_code == "4
") {
1171 $c = new Categorie($db);
1172 $existing = $c->containing($line->fk_product, Categorie::TYPE_PRODUCT, 'id');
1173 $result = array_intersect($catsprinter1, $existing);
1174 $count = count($result);
1175 if (!$line->fk_product) {
1176 $count++; // Print Free-text item (Unassigned printer) to Printer 1
1180 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet set special_code=
'1' where rowid=
".$line->id; //Set to print on printer 1
1182 $order_receipt_printer1 .= '<tr><td class="left
">';
1183 if ($line->fk_product) {
1184 $order_receipt_printer1 .= $line->product_label;
1186 $order_receipt_printer1 .= $line->description;
1188 $order_receipt_printer1 .= '</td><td class="right
">'.$line->qty;
1189 if (!empty($line->array_options['options_order_notes'])) {
1190 $order_receipt_printer1 .= "<br>(
".$line->array_options['options_order_notes'].")
";
1192 $order_receipt_printer1 .= '</td></tr>';
1195 if (((isModEnabled('receiptprinter') && getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term) > 0) || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter
" || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector
") && $linestoprint > 0) {
1196 $invoice->fetch($placeid); //Reload object before send to printer
1197 $printer->orderprinter = 1;
1199 echo "var orderprinter1esc=
'";
1200 $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
1203 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet
set special_code=
'4' where special_code=
'1' and fk_facture=
".$invoice->id; // Set as printed
1205 $invoice->fetch($placeid); //Reload object after set lines as printed
1208 foreach ($invoice->lines as $line) {
1209 if ($line->special_code == "4
") {
1212 $c = new Categorie($db);
1213 $existing = $c->containing($line->fk_product, Categorie::TYPE_PRODUCT, 'id');
1214 $result = array_intersect($catsprinter2, $existing);
1215 $count = count($result);
1218 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet
set special_code=
'2' where rowid=
".$line->id; //Set to print on printer 2
1220 $order_receipt_printer2 .= '<tr>'.$line->product_label.'<td class="right
">'.$line->qty;
1221 if (!empty($line->array_options['options_order_notes'])) {
1222 $order_receipt_printer2 .= "<br>(
".$line->array_options['options_order_notes'].")
";
1224 $order_receipt_printer2 .= '</td></tr>';
1227 if (((isModEnabled('receiptprinter') && getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term) > 0) || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter
" || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector
") && $linestoprint > 0) {
1228 $invoice->fetch($placeid); //Reload object before send to printer
1229 $printer->orderprinter = 2;
1231 echo "var orderprinter2esc=
'";
1232 $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
1235 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet
set special_code=
'4' where special_code=
'2' and fk_facture=
".$invoice->id; // Set as printed
1237 $invoice->fetch($placeid); //Reload object after set lines as printed
1240 foreach ($invoice->lines as $line) {
1241 if ($line->special_code == "4
") {
1244 $c = new Categorie($db);
1245 $existing = $c->containing($line->fk_product, Categorie::TYPE_PRODUCT, 'id');
1246 $result = array_intersect($catsprinter3, $existing);
1247 $count = count($result);
1250 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet
set special_code=
'3' where rowid=
".$line->id; //Set to print on printer 3
1252 $order_receipt_printer3 .= '<tr>'.$line->product_label.'<td class="right
">'.$line->qty;
1253 if (!empty($line->array_options['options_order_notes'])) {
1254 $order_receipt_printer3 .= "<br>(
".$line->array_options['options_order_notes'].")
";
1256 $order_receipt_printer3 .= '</td></tr>';
1259 if (((isModEnabled('receiptprinter') && getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term) > 0) || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter
" || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector
") && $linestoprint > 0) {
1260 $invoice->fetch($placeid); //Reload object before send to printer
1261 $printer->orderprinter = 3;
1263 echo "var orderprinter3esc=
'";
1264 $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
1267 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet
set special_code=
'4' where special_code=
'3' and fk_facture=
".$invoice->id; // Set as printed
1269 $invoice->fetch($placeid); //Reload object after set lines as printed
1272 $sectionwithinvoicelink = '';
1273 if (($action == "valid
" || $action == "history
" || $action == 'creditnote' || ($action == 'addline' && $invoice->status == $invoice::STATUS_CLOSED)) && $user->hasRight('takepos', 'run')) {
1274 $sectionwithinvoicelink .= '<!-- Section with invoice link -->'."\n
";
1275 $sectionwithinvoicelink .= '<span style="font-size:120%;
" class="center
inline-block marginbottomonly
">';
1276 $sectionwithinvoicelink .= $invoice->getNomUrl(1, '', 0, 0, '', 0, 0, -1, '_backoffice')." -
";
1277 $remaintopay = $invoice->getRemainToPay();
1278 if ($remaintopay > 0) {
1279 $sectionwithinvoicelink .= $langs->trans('RemainToPay').': <span class="amountremaintopay
" style="font-size: unset
">'.price($remaintopay, 1, $langs, 1, -1, -1, $conf->currency).'</span>';
1281 $sectionwithinvoicelink .= $invoice->getLibStatut(2);
1284 $sectionwithinvoicelink .= '</span><br>';
1285 if (getDolGlobalInt('TAKEPOS_PRINT_INVOICE_DOC_INSTEAD_OF_RECEIPT')) {
1286 $sectionwithinvoicelink .= ' <a target="_blank
" class="button" href="' . DOL_URL_ROOT . '/document.php?token=
' . newToken() . '&modulepart=facture&file=
' . $invoice->ref . '/
' . $invoice->ref . '.pdf
">Invoice</a>';
1287 } elseif (getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector
") {
1288 if (getDolGlobalString('TAKEPOS_PRINT_SERVER') && filter_var(getDolGlobalString('TAKEPOS_PRINT_SERVER'), FILTER_VALIDATE_URL) == true) {
1289 $sectionwithinvoicelink .= ' <button id="buttonprint
" type="button" onclick="TakeposConnector(
'.$placeid.')
">'.$langs->trans('PrintTicket').'</button>';
1291 $sectionwithinvoicelink .= ' <button id="buttonprint
" type="button" onclick="TakeposPrinting(
'.$placeid.')
">'.$langs->trans('PrintTicket').'</button>';
1293 } elseif ((isModEnabled('receiptprinter') && getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term) > 0) || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter
") {
1294 $sectionwithinvoicelink .= ' <button id="buttonprint
" type="button" onclick="DolibarrTakeposPrinting(
'.$placeid.')
">'.$langs->trans('PrintTicket').'</button>';
1296 $sectionwithinvoicelink .= ' <button id="buttonprint
" type="button" onclick="Print(
'.$placeid.')
">'.$langs->trans('PrintTicket').'</button>';
1297 if (getDolGlobalString('TAKEPOS_PRINT_WITHOUT_DETAILS')) {
1298 $sectionwithinvoicelink .= ' <button id="buttonprint
" type="button" onclick="PrintBox(
'.$placeid.', \
'without_details\')">'.$langs->trans(
'PrintWithoutDetails').
'</button>';
1301 $sectionwithinvoicelink .=
' <button id="buttonprint" type="button" onclick="Print('.$placeid.
', 1)">'.$langs->trans(
'GiftReceipt').
'</button>';
1305 $sectionwithinvoicelink .=
' <button id="buttonsend" type="button" onclick="SendTicket('.$placeid.
')">'.$langs->trans(
'SendTicket').
'</button>';
1308 if ($remaintopay <= 0 &&
getDolGlobalString(
'TAKEPOS_AUTO_PRINT_TICKETS') && $action !=
"history") {
1309 $sectionwithinvoicelink .=
'<script type="text/javascript">$("#buttonprint").click();</script>';
1319$form =
new Form($db);
1322if ((
getDolGlobalString(
'TAKEPOS_PHONE_BASIC_LAYOUT') == 1 &&
$conf->browser->layout ==
'phone') || defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1323 $title =
'TakePOS - Dolibarr '.DOL_VERSION;
1327 $head =
'<meta name="apple-mobile-web-app-title" content="TakePOS"/>
1328 <meta name="apple-mobile-web-app-capable" content="yes">
1329 <meta name="mobile-web-app-capable" content="yes">
1330 <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>';
1331 $arrayofcss = array(
1332 '/takepos/css/pos.css.php',
1334 $arrayofjs = array(
'/takepos/js/jquery.colorbox-min.js');
1337 top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss);
1339 print
'<body>'.
"\n";
1346<script
type=
"text/javascript">
1349<?php
if ($action ==
"valid") {
1350 echo
"var place=0;";
1352var placeid=<?php echo($placeid > 0 ? $placeid : 0); ?>;
1353$(document).ready(
function() {
1354 var idoflineadded = <?php echo(empty($idoflineadded) ? 0 : $idoflineadded); ?>;
1356 $(
'.posinvoiceline').click(
function(){
1357 console.log(
"Click done on "+this.
id);
1358 $(
'.posinvoiceline').removeClass(
"selected");
1359 $(
this).addClass(
"selected");
1363 if (selectedline == this.
id) {
1366 selectedline = this.id;
1368 selectedtext=$(
'#'+selectedline).find(
"td:first").html();
1370 if (defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1371 print
'$("#phonediv1").load("'.DOL_URL_ROOT.
'/takepos/public/auto_order.php?action=editline&token='.
newToken().
'&placeid="+placeid+"&selectedline="+selectedline, function() {
1378 if (idoflineadded > 0)
1380 console.log(
"Auto select "+idoflineadded);
1381 $(
'.posinvoiceline#'+idoflineadded).click();
1385if ($action ==
"order" && !empty($order_receipt_printer1)) {
1386 if (filter_var(
getDolGlobalString(
'TAKEPOS_PRINT_SERVER'), FILTER_VALIDATE_URL) ==
true) {
1390 url:
'<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER
'); ?>/printer/index.php',
1391 data:
'invoice='+orderprinter1esc
1398 url:
'http://<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER
'); ?>:8111/print',
1400 print $headerorder.$order_receipt_printer1.$footerorder; ?>'
1406if ($action ==
"order" && !empty($order_receipt_printer2)) {
1407 if (filter_var(
getDolGlobalString(
'TAKEPOS_PRINT_SERVER'), FILTER_VALIDATE_URL) ==
true) {
1411 url:
'<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER
'); ?>/printer/index.php?printer=2',
1412 data:
'invoice='+orderprinter2esc
1419 url:
'http://<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER
'); ?>:8111/print2',
1421 print $headerorder.$order_receipt_printer2.$footerorder; ?>'
1427if ($action ==
"order" && !empty($order_receipt_printer3)) {
1428 if (filter_var(
getDolGlobalString(
'TAKEPOS_PRINT_SERVER'), FILTER_VALIDATE_URL) ==
true) {
1432 url:
'<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER
'); ?>/printer/index.php?printer=3',
1433 data:
'invoice='+orderprinter3esc
1440if ($action ==
"search" || $action ==
"valid") {
1442 parent.ClearSearch(
true);
1447if ($action ==
"temp" && !empty($ticket_printer1)) {
1451 url:
'http://<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER
'); ?>:8111/print',
1453 print $header_soc.$header_ticket.$body_ticket.$ticket_printer1.$ticket_total.$footer_ticket; ?>'
1458if ($action ==
"search") {
1460 $(
'#search').focus();
1468function SendTicket(
id)
1470 console.log(
"Open box to select the Print/Send form");
1471 $.colorbox({href:
"send.php?facid="+id, width:
"70%", height:
"30%", transition:
"none", iframe:
"true", title:
'<?php echo dol_escape_js($langs->trans("SendTicket")); ?>'});
1475function PrintBox(
id, action) {
1476 console.log(
"Open box before printing");
1477 $.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
"); ?>"});
1481function Print(
id, gift){
1482 console.log(
"Call Print() to generate the receipt.");
1483 $.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")); ?>'});
1487function TakeposPrinting(
id){
1489 console.log(
"TakeposPrinting" +
id);
1490 $.get(
"receipt.php?facid="+
id,
function(data,
status) {
1491 receipt=data.replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g,
'');
1494 url:
'http://<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER
'); ?>:8111/print',
1501function TakeposConnector(
id){
1502 console.log(
"TakeposConnector" +
id);
1503 $.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) {
1506 url:
'<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER
'); ?>/printer/index.php',
1507 data:
'invoice='+data
1515function DolibarrTakeposPrinting(
id) {
1516 console.log(
"DolibarrTakeposPrinting Printing invoice ticket " +
id);
1519 data: { token:
'<?php echo currentToken(); ?>' },
1520 url:
"<?php print DOL_URL_ROOT.'/takepos/ajax/ajax.php?action=printinvoiceticket&token='.newToken().'&term='.urlencode(isset($_SESSION["takeposterminal
"]) ? $_SESSION["takeposterminal
"] : '').'&id='; ?>" + id,
1527function CreditNote() {
1528 $(
"#poslines").load(
"<?php print DOL_URL_ROOT; ?>/takepos/invoice.php?action=creditnote&token=<?php echo newToken() ?>&invoiceid="+placeid,
function() { });
1534 $(
"#poslines").load(
"<?php print DOL_URL_ROOT; ?>/takepos/invoice.php?action=addnote&token=<?php echo newToken() ?>&invoiceid="+placeid+
"&idline="+selectedline, {
"addnote": $(
"#textinput").val() });
1539$( document ).ready(
function() {
1540 console.log(
"Set customer info and sales in header placeid=<?php echo $placeid; ?> status=<?php echo $invoice->statut; ?>");
1543 $s = $langs->trans(
"Customer");
1544 if ($invoice->id > 0 && ($invoice->socid !=
getDolGlobalString($constforcompanyid))) {
1547 $contactids = $invoice->getIdContact(
'external',
'BILLING');
1548 $contactid = $contactids[0];
1549 if ($contactid > 0) {
1551 $contact->fetch($contactid);
1552 $s .=
" - " . $contact->getFullName($langs);
1556 print
'$("#idcustomer").val("");';
1560 $(
"#customerandsales").html(
'');
1561 $(
"#shoppingcart").html(
'');
1564 $(
"#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>');
1566 $(
"#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>');
1570 $sql =
"SELECT rowid, datec, ref FROM ".MAIN_DB_PREFIX.
"facture";
1571 $sql .=
" WHERE entity IN (".getEntity(
'invoice').
")";
1574 $sql .=
" AND ref LIKE '(PROV-POS".$db->escape(isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'').
"-0%'";
1577 $sql .=
" AND pos_source = '".$db->escape($_SESSION[
"takeposterminal"]).
"'";
1578 $sql .=
" AND module_source = 'takepos'";
1581 $sql .= $db->order(
'datec',
'ASC');
1582 $resql = $db->query($sql);
1585 while ($obj = $db->fetch_object($resql)) {
1586 echo
'$("#shoppingcart").append(\'';
1587 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=\\\'';
1588 $num_sale = str_replace(
")",
"", str_replace(
"(PROV-POS".$_SESSION[
"takeposterminal"].
"-",
"", $obj->ref));
1590 if (str_replace(
"-",
"", $num_sale) > $max_sale) {
1591 $max_sale = str_replace(
"-",
"", $num_sale);
1593 echo
'\\\'; invoiceid=\\\'';
1595 echo
'\\\'; Refresh();">';
1596 if ($placeid == $obj->rowid) {
1597 echo
'<span class="basketselected">';
1599 echo
'<span class="basketnotselected">';
1601 echo
'<span class="fa fa-shopping-cart paddingright"></span>'.dol_print_date($db->jdate($obj->datec),
'%H:%M',
'tzuser');
1605 echo
'$("#shoppingcart").append(\'<a onclick="place=\\\'0-';
1607 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>\');';
1615 $constantforkey =
'CASHDESK_NO_DECREASE_STOCK'. (isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
1616 if (isModEnabled(
'stock')) {
1618 $constantforkey =
'CASHDESK_ID_WAREHOUSE'. (isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
1620 if ($idwarehouse > 0) {
1621 $s =
'<span class="small">';
1623 $warehouse->fetch($idwarehouse);
1624 $s .=
'<span class="hideonsmartphone">'.$langs->trans(
"Warehouse").
'<br></span>'.$warehouse->ref;
1626 $s .=
' ('.$langs->trans(
"Closed").
')';
1629 print
"$('#infowarehouse').html('".dol_escape_js($s).
"');";
1630 print
'$("#infowarehouse").css("display", "inline-block");';
1632 $s =
'<span class="small hideonsmartphone">';
1633 $s .= $langs->trans(
"StockChangeDisabled").
'<br>'.$langs->trans(
"NoWarehouseDefinedForTerminal");
1635 print
"$('#infowarehouse').html('".dol_escape_js($s).
"');";
1636 if (!empty(
$conf->dol_optimize_smallscreen)) {
1637 print
'$("#infowarehouse").css("display", "none");';
1641 $s =
'<span class="small hideonsmartphone">'.$langs->trans(
"StockChangeDisabled").
'</span>';
1642 print
"$('#infowarehouse').html('".dol_escape_js($s).
"');";
1643 if (!empty(
$conf->dol_optimize_smallscreen)) {
1644 print
'$("#infowarehouse").css("display", "none");';
1652 if (isModEnabled(
'member') && $invoice->socid > 0 && $invoice->socid !=
getDolGlobalInt($constforcompanyid)) {
1653 $s =
'<span class="small">';
1654 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
1655 $langs->load(
"members");
1656 $s .= $langs->trans(
"Member").
': ';
1658 $result = $adh->fetch(
'',
'', $invoice->socid);
1660 $adh->ref = $adh->getFullName($langs);
1664 $s .= $adh->getFullName($langs);
1665 $s .=
' - '.$adh->type;
1666 if ($adh->datefin) {
1667 $s .=
'<br>'.$langs->trans(
"SubscriptionEndDate").
': '.
dol_print_date($adh->datefin,
'day');
1668 if ($adh->hasDelay()) {
1669 $s .=
" ".img_warning($langs->trans(
"Late"));
1672 $s .=
'<br>'.$langs->trans(
"SubscriptionNotReceived");
1673 if ($adh->statut > 0) {
1674 $s .=
" ".img_warning($langs->trans(
"Late"));
1681 $s .=
'<br>'.$langs->trans(
"ThirdpartyNotLinkedToMember");
1686 $(
"#moreinfo").html(
'<?php print dol_escape_js($s); ?>');
1693 echo
"function CustomerDisplay(){";
1694 echo
"var line1='".$CUSTOMER_DISPLAY_line1.
"'.substring(0,20);";
1695 echo
"line1=line1.padEnd(20);";
1696 echo
"var line2='".$CUSTOMER_DISPLAY_line2.
"'.substring(0,20);";
1697 echo
"line2=line2.padEnd(20);";
1700 data: { text: line1+line2 },
1701 url: '".getDolGlobalString(
'TAKEPOS_PRINT_SERVER').
"/display/index.php',
1712if (!empty(
$conf->use_javascript_ajax)) {
1713 print
"\n".
'<!-- Includes JS Footer of Dolibarr -->'.
"\n";
1714 print
'<script src="'.DOL_URL_ROOT.
'/core/js/lib_foot.js.php?lang='.$langs->defaultlang.
'"></script>'.
"\n";
1717$usediv = (
GETPOST(
'format') ==
'div');
1719print
'<!-- 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";
1720print
'<div class="div-table-responsive-no-min invoice">';
1722 print
'<div id="tablelines">';
1724 print
'<table id="tablelines" class="noborder noshadow postablelines centpercent">';
1727$buttontocreatecreditnote =
'';
1728if (($action ==
"valid" || $action ==
"history" || ($action ==
"addline" && $invoice->status == $invoice::STATUS_CLOSED)) && $invoice->type !=
Facture::TYPE_CREDIT_NOTE && !
getDolGlobalString(
'TAKEPOS_NO_CREDITNOTE')) {
1729 $buttontocreatecreditnote .=
' <!-- Show button to create a credit note -->'.
"\n";
1730 $buttontocreatecreditnote .=
'<button id="buttonprint" type="button" onclick="ModalBox(\'ModalCreditNote\')">'.$langs->trans(
'CreateCreditNote').
'</button>';
1731 if (
getDolGlobalInt(
'TAKEPOS_PRINT_INVOICE_DOC_INSTEAD_OF_RECEIPT')) {
1732 $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>';
1737if ($sectionwithinvoicelink && ($mobilepage ==
"invoice" || $mobilepage ==
"")) {
1738 print
'<!-- Print table line with link to invoice ref -->';
1740 print
'<tr><td colspan="5" class="paddingtopimp paddingbottomimp" style="padding-top: 10px !important; padding-bottom: 10px !important;">';
1741 print $sectionwithinvoicelink;
1742 print $buttontocreatecreditnote;
1745 print
'<tr><td colspan="4" class="paddingtopimp paddingbottomimp" style="padding-top: 10px !important; padding-bottom: 10px !important;">';
1746 print $sectionwithinvoicelink;
1747 print $buttontocreatecreditnote;
1754 print
'<tr class="liste_titre nodrag nodrop">';
1755 print
'<td class="linecoldescription">';
1758if (empty($mobilepage) || $mobilepage ==
"invoice") {
1759 print
'<!-- hidden var used by some js functions -->';
1760 print
'<input type="hidden" name="invoiceid" id="invoiceid" value="'.$invoice->id.
'">';
1761 print
'<input type="hidden" name="thirdpartyid" id="thirdpartyid" value="'.$invoice->socid.
'">';
1765 $sql =
"SELECT floor, label FROM ".MAIN_DB_PREFIX.
"takepos_floor_tables where rowid=".((int) $place);
1766 $resql = $db->query($sql);
1767 $obj = $db->fetch_object($resql);
1769 $label = $obj->label;
1770 $floor = $obj->floor;
1772 if ($mobilepage ==
"invoice" || $mobilepage ==
"") {
1775 print
'<span class="opacitymedium">'.$langs->trans(
'Place').
"</span> <b>".(empty($label) ?
'?' : $label).
"</b><br>";
1776 print
'<span class="opacitymedium">'.$langs->trans(
'Floor').
"</span> <b>".(empty($floor) ?
'?' : $floor).
"</b>";
1783$parameters = array();
1784$reshook = $hookmanager->executeHooks(
'completeTakePosInvoiceHeader', $parameters, $invoice, $action);
1788print $hookmanager->resPrint;
1790if (empty($_SESSION[
"basiclayout"]) || $_SESSION[
"basiclayout"] != 1) {
1792 print
'<td class="linecolqty right">'.$langs->trans(
'PriceUHT').
'</td>';
1794 print
'<td class="linecolqty right">'.$langs->trans(
'ReductionShort').
'</td>';
1795 print
'<td class="linecolqty right">'.$langs->trans(
'Qty').
'</td>';
1797 print
'<td class="linecolht right nowraponall">';
1798 print
'<span class="opacitymedium small">' . $langs->trans(
'TotalHTShort') .
'</span><br>';
1800 if (empty($mobilepage) || $mobilepage ==
"invoice") {
1801 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>';
1802 if (isModEnabled(
'multicurrency') && !empty($_SESSION[
"takeposcustomercurrency"]) &&
$conf->currency != $_SESSION[
"takeposcustomercurrency"]) {
1804 include_once DOL_DOCUMENT_ROOT .
'/multicurrency/class/multicurrency.class.php';
1806 $multicurrency->fetch(0, $_SESSION[
"takeposcustomercurrency"]);
1807 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>';
1812 print
'<td class="linecolht right nowraponall">';
1813 print
'<span class="opacitymedium small">'.$langs->trans(
'TotalTTCShort').
'</span><br>';
1815 if (empty($mobilepage) || $mobilepage ==
"invoice") {
1816 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>';
1817 if (isModEnabled(
'multicurrency') && !empty($_SESSION[
"takeposcustomercurrency"]) &&
$conf->currency != $_SESSION[
"takeposcustomercurrency"]) {
1819 include_once DOL_DOCUMENT_ROOT.
'/multicurrency/class/multicurrency.class.php';
1821 $multicurrency->fetch(0, $_SESSION[
"takeposcustomercurrency"]);
1822 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>';
1826} elseif ($mobilepage ==
"invoice") {
1827 print
'<td class="linecolqty right">'.$langs->trans(
'Qty').
'</td>';
1833if (!empty($_SESSION[
"basiclayout"]) && $_SESSION[
"basiclayout"] == 1) {
1834 if ($mobilepage ==
"cats") {
1835 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1837 $categories = $categorie->get_full_arbo(
'product');
1839 foreach ($categories as $row) {
1840 if (defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1841 $htmlforlines .=
'<div class="leftcat"';
1843 $htmlforlines .=
'<tr class="drag drop oddeven posinvoiceline"';
1845 $htmlforlines .=
' onclick="LoadProducts('.$row[
'id'].
');">';
1846 if (defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1847 $htmlforlines .=
'<img class="imgwrapper" width="33%" src="'.DOL_URL_ROOT.
'/takepos/public/auto_order.php?genimg=cat&query=cat&id='.$row[
'id'].
'"><br>';
1849 $htmlforlines .=
'<td class="left">';
1851 $htmlforlines .= $row[
'label'];
1852 if (defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1853 $htmlforlines .=
'</div>'.
"\n";
1855 $htmlforlines .=
'</td></tr>'.
"\n";
1858 print $htmlforlines;
1861 if ($mobilepage ==
"products") {
1862 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1865 $result =
$object->fetch($catid);
1866 $prods =
$object->getObjectsInCateg(
"product");
1868 foreach ($prods as $row) {
1869 if (defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1870 $htmlforlines .=
'<div class="leftcat"';
1872 $htmlforlines .=
'<tr class="drag drop oddeven posinvoiceline"';
1874 $htmlforlines .=
' onclick="AddProduct(\''.$place.
'\',
'.$row->id.')
"';
1875 $htmlforlines .= '>';
1876 if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1877 $htmlforlines .= '<img class="imgwrapper
" width="33%
" src="'.DOL_URL_ROOT.'/takepos/
public/auto_order.php?genimg=pro&query=pro&
id=
'.$row->id.'"><br>';
1878 $htmlforlines .= $row->label.' '.price($row->price_ttc, 1, $langs, 1, -1, -1, $conf->currency);
1879 $htmlforlines .= '</div>'."\n
";
1881 $htmlforlines .= '<td class="left
">';
1882 $htmlforlines .= $row->label;
1883 $htmlforlines .= '<div class="right
">'.price($row->price_ttc, 1, $langs, 1, -1, -1, $conf->currency).'</div>';
1884 $htmlforlines .= '</td>';
1885 $htmlforlines .= '</tr>'."\n
";
1888 print $htmlforlines;
1891 if ($mobilepage == "places
") {
1892 $sql = "SELECT rowid, entity, label, leftpos, toppos, floor FROM
".MAIN_DB_PREFIX."takepos_floor_tables
";
1893 $resql = $db->query($sql);
1897 while ($row = $db->fetch_array($resql)) {
1899 $htmlforlines .= '<tr class="drag drop oddeven posinvoiceline
';
1900 $htmlforlines .= '" onclick="LoadPlace(\
''.$row[
'label'].
'\')
">';
1901 $htmlforlines .= '<td class="left
">';
1902 $htmlforlines .= $row['label'];
1903 $htmlforlines .= '</td>';
1904 $htmlforlines .= '</tr>'."\n
";
1906 print $htmlforlines;
1911 //In Phone basic layout hide some content depends situation
1912 if (!empty($_SESSION["basiclayout
"]) && $_SESSION["basiclayout
"] == 1 && $mobilepage != "invoice
" && $action != "order
") {
1916 // Loop on each lines on invoice
1917 if (is_array($invoice->lines) && count($invoice->lines)) {
1918 print '<!-- invoice.php show lines of invoices -->'."\n
";
1919 $tmplines = array_reverse($invoice->lines);
1920 $htmlsupplements = array();
1921 foreach ($tmplines as $line) {
1922 if ($line->fk_parent_line != false) {
1923 $htmlsupplements[$line->fk_parent_line] .= '<tr class="drag drop oddeven posinvoiceline
';
1924 if ($line->special_code == "4") {
1925 $htmlsupplements[$line->fk_parent_line] .= ' order
';
1927 $htmlsupplements[$line->fk_parent_line] .= '" id="'.$line->id.'"';
1928 if ($line->special_code == "4
") {
1929 $htmlsupplements[$line->fk_parent_line] .= ' title="'.dol_escape_htmltag($langs->trans("AlreadyPrinted")).'"';
1931 $htmlsupplements[$line->fk_parent_line] .= '>';
1932 $htmlsupplements[$line->fk_parent_line] .= '<td class="left
">';
1933 $htmlsupplements[$line->fk_parent_line] .= img_picto('', 'rightarrow');
1934 if ($line->product_label) {
1935 $htmlsupplements[$line->fk_parent_line] .= $line->product_label;
1937 if ($line->product_label && $line->desc) {
1938 $htmlsupplements[$line->fk_parent_line] .= '<br>';
1940 if ($line->product_label != $line->desc) {
1941 $firstline = dolGetFirstLineOfText($line->desc);
1942 if ($firstline != $line->desc) {
1943 $htmlsupplements[$line->fk_parent_line] .= $form->textwithpicto(dolGetFirstLineOfText($line->desc), $line->desc);
1945 $htmlsupplements[$line->fk_parent_line] .= $line->desc;
1948 $htmlsupplements[$line->fk_parent_line] .= '</td>';
1950 // complete line by hook
1951 $parameters = array('line' => $line);
1952 $reshook = $hookmanager->executeHooks('completeTakePosInvoiceParentLine', $parameters, $invoice, $action); // Note that $action and $object may have been modified by some hooks
1954 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1956 $htmlsupplements[$line->fk_parent_line] .= $hookmanager->resPrint;
1958 if (empty($_SESSION["basiclayout
"]) || $_SESSION["basiclayout
"] != 1) {
1959 $htmlsupplements[$line->fk_parent_line] .= '<td class="right
">'.vatrate(price2num($line->remise_percent), true).'</td>';
1960 $htmlsupplements[$line->fk_parent_line] .= '<td class="right
">'.$line->qty.'</td>';
1961 $htmlsupplements[$line->fk_parent_line] .= '<td class="right
">'.price($line->total_ttc).'</td>';
1963 $htmlsupplements[$line->fk_parent_line] .= '</tr>'."\n
";
1968 $htmlforlines .= '<tr class="drag drop oddeven posinvoiceline
';
1969 if ($line->special_code == "4") {
1970 $htmlforlines .= ' order
';
1972 $htmlforlines .= '" id="'.$line->id.'"';
1973 if ($line->special_code == "4
") {
1974 $htmlforlines .= ' title="'.dol_escape_htmltag($langs->trans("AlreadyPrinted")).'"';
1976 $htmlforlines .= '>';
1977 $htmlforlines .= '<td class="left
">';
1978 if (!empty($_SESSION["basiclayout
"]) && $_SESSION["basiclayout
"] == 1) {
1979 $htmlforlines .= '<span class="phoneqty
">'.$line->qty."</span> x
";
1981 if (isset($line->product_type)) {
1982 if (empty($line->product_type)) {
1983 $htmlforlines .= img_object('', 'product').' ';
1985 $htmlforlines .= img_object('', 'service').' ';
1989 if (!getDolGlobalString('TAKEPOS_SHOW_N_FIRST_LINES')) {
1990 if ($line->product_ref) {
1991 $tooltiptext .= '<b>'.$langs->trans("Ref
").'</b> : '.$line->product_ref.'<br>';
1992 $tooltiptext .= '<b>'.$langs->trans("Label
").'</b> : '.$line->product_label.'<br>';
1993 if (!empty($line->batch)) {
1994 $tooltiptext .= '<br><b>'.$langs->trans("LotSerial
").'</b> : '.$line->batch.'<br>';
1996 if (!empty($line->fk_warehouse)) {
1997 $tooltiptext .= '<b>'.$langs->trans("Warehouse
").'</b> : '.$line->fk_warehouse.'<br>';
1999 if ($line->product_label != $line->desc) {
2001 $tooltiptext .= '<br>';
2003 $tooltiptext .= $line->desc;
2006 if (getDolGlobalInt('TAKEPOS_SHOW_PRODUCT_REFERENCE') == 1) {
2007 $htmlforlines .= $form->textwithpicto($line->product_label ? '<b>' . $line->product_ref . '</b> - ' . $line->product_label : dolGetFirstLineOfText($line->desc, 1), $tooltiptext);
2008 } elseif (getDolGlobalInt('TAKEPOS_SHOW_PRODUCT_REFERENCE') == 2) {
2009 $htmlforlines .= $form->textwithpicto($line->product_ref ? '<b>'.$line->product_ref.'<b>' : dolGetFirstLineOfText($line->desc, 1), $tooltiptext);
2011 $htmlforlines .= $form->textwithpicto($line->product_label ? $line->product_label : ($line->product_ref ? $line->product_ref : dolGetFirstLineOfText($line->desc, 1)), $tooltiptext);
2014 if ($line->product_ref) {
2015 $tooltiptext .= '<b>'.$langs->trans("Ref
").'</b> : '.$line->product_ref.'<br>';
2016 $tooltiptext .= '<b>'.$langs->trans("Label
").'</b> : '.$line->product_label.'<br>';
2018 if (!empty($line->batch)) {
2019 $tooltiptext .= '<br><b>'.$langs->trans("LotSerial
").'</b> : '.$line->batch.'<br>';
2021 if (!empty($line->fk_warehouse)) {
2022 $tooltiptext .= '<b>'.$langs->trans("Warehouse
").'</b> : '.$line->fk_warehouse.'<br>';
2025 if ($line->product_label) {
2026 $htmlforlines .= $line->product_label;
2028 if ($line->product_label != $line->desc) {
2029 if ($line->product_label && $line->desc) {
2030 $htmlforlines .= '<br>';
2032 $firstline = dolGetFirstLineOfText($line->desc, getDolGlobalInt('TAKEPOS_SHOW_N_FIRST_LINES'));
2033 if ($firstline != $line->desc) {
2034 $htmlforlines .= $form->textwithpicto(dolGetFirstLineOfText($line->desc), $line->desc);
2036 $htmlforlines .= $line->desc;
2040 if (!empty($line->array_options['options_order_notes'])) {
2041 $htmlforlines .= "<br>(
".$line->array_options['options_order_notes'].")
";
2043 if (!empty($_SESSION["basiclayout
"]) && $_SESSION["basiclayout
"] == 1) {
2044 $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>';
2046 if (empty($_SESSION["basiclayout
"]) || $_SESSION["basiclayout
"] != 1) {
2048 $moreinfo .= $langs->transcountry("TotalHT
", $mysoc->country_code).': '.price($line->total_ht);
2049 if ($line->vat_src_code) {
2050 $moreinfo .= '<br>'.$langs->trans("VATCode
").': '.$line->vat_src_code;
2052 $moreinfo .= '<br>'.$langs->transcountry("TotalVAT
", $mysoc->country_code).': '.price($line->total_tva);
2053 $moreinfo .= '<br>'.$langs->transcountry("TotalLT1
", $mysoc->country_code).': '.price($line->total_localtax1);
2054 $moreinfo .= '<br>'.$langs->transcountry("TotalLT2
", $mysoc->country_code).': '.price($line->total_localtax2);
2055 $moreinfo .= '<hr>';
2056 $moreinfo .= $langs->transcountry("TotalTTC
", $mysoc->country_code).': '.price($line->total_ttc);
2057 //$moreinfo .= $langs->trans("TotalHT
").': '.$line->total_ht;
2058 if ($line->date_start || $line->date_end) {
2059 $htmlforlines .= '<br><div class="clearboth nowraponall
">'.get_date_range($line->date_start, $line->date_end).'</div>';
2061 $htmlforlines .= '</td>';
2063 // complete line by hook
2064 $parameters = array('line' => $line);
2065 $reshook = $hookmanager->executeHooks('completeTakePosInvoiceLine', $parameters, $invoice, $action); // Note that $action and $object may have been modified by some hooks
2067 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
2069 $htmlforlines .= $hookmanager->resPrint;
2071 if (getDolGlobalInt("TAKEPOS_SHOW_SUBPRICE
")) {
2072 $htmlforlines .= '<td class="right
">'.price($line->subprice).'</td>';
2074 $htmlforlines .= '<td class="right
">'.vatrate(price2num($line->remise_percent), true).'</td>';
2075 $htmlforlines .= '<td class="right
">';
2076 if (isModEnabled('stock') && $user->hasRight('stock', 'mouvement', 'lire')) {
2077 $constantforkey = 'CASHDESK_ID_WAREHOUSE'.$_SESSION["takeposterminal
"];
2078 if (getDolGlobalString($constantforkey) && $line->fk_product > 0 && !getDolGlobalString('TAKEPOS_HIDE_STOCK_ON_LINE')) {
2079 $sql = "SELECT e.rowid, e.ref, e.lieu, e.fk_parent, e.statut, ps.reel, ps.rowid as product_stock_id, p.pmp
";
2080 $sql .= " FROM
".MAIN_DB_PREFIX."entrepot as e,
";
2081 $sql .= " ".MAIN_DB_PREFIX."product_stock as ps
";
2082 $sql .= " LEFT JOIN
".MAIN_DB_PREFIX."product as p ON p.rowid = ps.fk_product
";
2083 $sql .= " WHERE ps.reel != 0
";
2084 $sql .= " AND ps.fk_entrepot =
".((int) getDolGlobalString($constantforkey));
2085 $sql .= " AND e.entity IN (
".getEntity('stock').")
";
2086 $sql .= " AND ps.fk_product =
".((int) $line->fk_product);
2087 $resql = $db->query($sql);
2090 $obj = $db->fetch_object($resql);
2092 $stock_real = price2num($obj->reel, 'MS');
2094 $htmlforlines .= $line->qty;
2095 $htmlforlines .= ' ';
2096 $htmlforlines .= '<span class="opacitylow
" title="'.$langs->trans("Stock").' '.price($stock_real, 1, '', 1, 0).'">';
2097 $htmlforlines .= '(';
2098 if ($line->qty && $line->qty > $stock_real) {
2099 $htmlforlines .= '<span style="color: var(--amountremaintopaycolor)
">';
2101 $htmlforlines .= img_picto('', 'stock', 'class="pictofixedwidth
"').price($stock_real, 1, '', 1, 0);
2102 if ($line->qty && $line->qty > $stock_real) {
2103 $htmlforlines .= "</span>
";
2105 $htmlforlines .= ')';
2106 $htmlforlines .= '</span>';
2108 dol_print_error($db);
2111 $htmlforlines .= $line->qty;
2114 $htmlforlines .= $line->qty;
2117 $htmlforlines .= '</td>';
2118 if (getDolGlobalInt('TAKEPOS_SHOW_HT')) {
2119 $htmlforlines .= '<td class="right classfortooltip
" title="'.$moreinfo.'">';
2120 $htmlforlines .= price($line->total_ht, 1, '', 1, -1, -1, $conf->currency);
2121 if (isModEnabled('multicurrency') && !empty($_SESSION["takeposcustomercurrency
"]) && $conf->currency != $_SESSION["takeposcustomercurrency
"]) {
2122 //Only show customer currency if multicurrency module is enabled, if currency selected and if this currency selected is not the same as main currency
2123 include_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php';
2124 $multicurrency = new MultiCurrency($db);
2125 $multicurrency->fetch(0, $_SESSION["takeposcustomercurrency
"]);
2126 $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>';
2128 $htmlforlines .= '</td>';
2130 $htmlforlines .= '<td class="right classfortooltip
" title="'.$moreinfo.'">';
2131 $htmlforlines .= price($line->total_ttc, 1, '', 1, -1, -1, $conf->currency);
2132 if (isModEnabled('multicurrency') && !empty($_SESSION["takeposcustomercurrency
"]) && $conf->currency != $_SESSION["takeposcustomercurrency
"]) {
2133 //Only show customer currency if multicurrency module is enabled, if currency selected and if this currency selected is not the same as main currency
2134 include_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php';
2135 $multicurrency = new MultiCurrency($db);
2136 $multicurrency->fetch(0, $_SESSION["takeposcustomercurrency
"]);
2137 $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>';
2139 $htmlforlines .= '</td>';
2141 $htmlforlines .= '</tr>'."\n
";
2142 $htmlforlines .= empty($htmlsupplements[$line->id]) ? '' : $htmlsupplements[$line->id];
2144 print $htmlforlines;
2147 print '<tr class="drag drop oddeven
"><td class="left
"><span class="opacitymedium
">'.$langs->trans("Empty
").'</span></td><td></td>';
2148 if (empty($_SESSION["basiclayout
"]) || $_SESSION["basiclayout
"] != 1) {
2149 print '<td></td><td></td>';
2150 if (getDolGlobalString('TAKEPOS_SHOW_HT')) {
2156} else { // No invoice generated yet
2157 print '<tr class="drag drop oddeven
"><td class="left
"><span class="opacitymedium
">'.$langs->trans("Empty
").'</span></td><td></td>';
2158 if (empty($_SESSION["basiclayout
"]) || $_SESSION["basiclayout
"] != 1) {
2159 print '<td></td><td></td>';
2160 if (getDolGlobalString('TAKEPOS_SHOW_HT')) {
2173if ($action == "search
") {
2175 <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
')).'">
2182if ((getDolGlobalString('TAKEPOS_PHONE_BASIC_LAYOUT') == 1 && $conf->browser->layout == 'phone') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
2183 print '</body></html>';