103 header($_SERVER[
'SERVER_PROTOCOL'].
' 500 Internal Server Error',
true, 500);
109$number =
GETPOST(
'number',
'alpha');
112$desc =
GETPOST(
'desc',
'alphanohtml');
125if ($pay ==
'cheque') {
132 $sql =
"SELECT id FROM ".MAIN_DB_PREFIX.
"c_paiement";
133 $sql .=
" WHERE entity IN (".getEntity(
'c_paiement').
")";
134 $sql .=
" AND code = '".$db->escape($paycode).
"'";
135 $resql = $db->query($sql);
137 $obj = $db->fetch_object($resql);
139 $paiementid = $obj->id;
146 $ret = $invoice->fetch($invoiceid);
148 $ret = $invoice->fetch(
'',
'(PROV-POS'.$takeposterminal.
'-'.$place.
')');
151 $placeid = $invoice->id;
154$constforcompanyid =
'CASHDESK_ID_THIRDPARTY'.$takeposterminal;
157if ($invoice->socid > 0) {
158 $soc->fetch($invoice->socid);
164if (isModEnabled(
'project') &&
getDolGlobalInt(
"CASHDESK_ID_PROJECT".$takeposterminal)) {
165 $invoice->fk_project =
getDolGlobalInt(
"CASHDESK_ID_PROJECT".$takeposterminal);
169if (isModEnabled(
'multicurrency') && !empty($_SESSION[
"takeposcustomercurrency"])) {
170 if ($invoice->multicurrency_code != $_SESSION[
"takeposcustomercurrency"]) {
171 $invoice->setMulticurrencyCode($_SESSION[
"takeposcustomercurrency"]);
175$term = empty($_SESSION[
"takeposterminal"]) ? 1 : $_SESSION[
"takeposterminal"];
182$parameters = array();
183$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $invoice, $action);
188if (empty($reshook)) {
190 if ($action ==
'valid' && $user->hasRight(
'facture',
'creer')) {
198 $bankaccount =
getDolGlobalInt(
'CASHDESK_ID_BANKACCOUNT_CASH'.$_SESSION[
"takeposterminal"]);
199 } elseif ($pay ==
"CHQ") {
200 $bankaccount =
getDolGlobalInt(
'CASHDESK_ID_BANKACCOUNT_CHEQUE'.$_SESSION[
"takeposterminal"]);
202 $accountname =
"CASHDESK_ID_BANKACCOUNT_".$pay.$_SESSION[
"takeposterminal"];
207 if ($bankaccount <= 0 && $pay !=
"delayed" && isModEnabled(
"bank")) {
208 $errormsg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"BankAccount"));
216 $invoice->fetch($placeid);
220 if ($invoice->total_ttc < 0) {
221 $invoice->type = $invoice::TYPE_CREDIT_NOTE;
223 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"facture";
224 $sql .=
" WHERE entity IN (".getEntity(
'invoice').
")";
225 $sql .=
" AND fk_soc = ".((int) $invoice->socid);
226 $sql .=
" AND type <> ".Facture::TYPE_CREDIT_NOTE;
227 $sql .=
" AND fk_statut >= ".$invoice::STATUS_VALIDATED;
228 $sql .=
" ORDER BY rowid DESC";
230 $resql = $db->query($sql);
232 $obj = $db->fetch_object($resql);
233 $fk_source = $obj->rowid;
234 if ($fk_source ==
null) {
235 fail($langs->transnoentitiesnoconv(
"NoPreviousBillForCustomer"));
238 fail($langs->transnoentitiesnoconv(
"NoPreviousBillForCustomer"));
240 $invoice->fk_facture_source = $fk_source;
241 $invoice->update($user);
244 $constantforkey =
'CASHDESK_NO_DECREASE_STOCK'.(isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
251 if ($invoice->getRemainToPay() > 0) {
257 } elseif (count($invoice->lines) == 0) {
261 } elseif (isModEnabled(
'stock') && !isModEnabled(
'productbatch') && $allowstockchange) {
266 $conf->global->STOCK_CALCULATE_ON_BILL = 1;
268 $constantforkey =
'CASHDESK_ID_WAREHOUSE'.(isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
269 dol_syslog(
"Validate invoice with stock change. Warehouse defined into constant ".$constantforkey.
" = ".
getDolGlobalString($constantforkey));
274 $res = $invoice->validate($user,
'',
getDolGlobalInt($constantforkey), 0, $batch_rule);
277 $conf->global->STOCK_CALCULATE_ON_BILL = $savconst;
280 $res = $invoice->validate($user);
283 $langs->load(
"admin");
284 dol_htmloutput_errors($invoice->error ==
'NotConfigured' ? $langs->trans(
"NotConfigured").
' (TakePos numbering module)' : $invoice->error, $invoice->errors, 1);
289 if (!$error && $res >= 0) {
290 $remaintopay = $invoice->getRemainToPay();
291 if ($remaintopay > 0) {
293 $payment->datepaye = $now;
294 $payment->fk_account = $bankaccount;
295 $payment->amounts[$invoice->id] = $amountofpayment;
302 if ($amountofpayment <= 0 || $amountofpayment > $remaintopay) {
303 $payment->amounts[$invoice->id] = $remaintopay;
306 $payment->paiementid = $paiementid;
307 $payment->num_payment = $invoice->ref;
309 if ($pay !=
"delayed") {
310 $payment->create($user);
311 $res = $payment->addPaymentToBank($user,
'payment',
'(CustomerInvoicePayment)', $bankaccount,
'',
'');
316 $remaintopay = $invoice->getRemainToPay();
322 if ($remaintopay == 0) {
323 dol_syslog(
"Invoice is paid, so we set it to status Paid");
324 $result = $invoice->setPaid($user);
329 $invoice->setPaymentMethods($paiementid);
331 dol_syslog(
"Invoice is not paid, remain to pay = ".$remaintopay);
338 if (!$error && $res >= 0) {
339 if (isModEnabled(
'stock') && isModEnabled(
'productbatch') && $allowstockchange) {
341 dol_syslog(
"Now we record the stock movement for each qualified line");
344 require_once DOL_DOCUMENT_ROOT .
"/product/stock/class/mouvementstock.class.php";
345 $constantforkey =
'CASHDESK_ID_WAREHOUSE'.$_SESSION[
"takeposterminal"];
348 $labeltakeposmovement =
'TakePOS - '.$langs->trans(
"Invoice").
' '.$invoice->ref;
350 foreach ($invoice->lines as $line) {
352 $warehouseid = ($line->fk_warehouse ? $line->fk_warehouse :
getDolGlobalInt($constantforkey));
355 if ($line->batch !=
'' && $warehouseid > 0) {
357 $prod_batch->find(0,
'',
'', $line->batch, $warehouseid);
360 $mouvP->setOrigin($invoice->element, $invoice->id);
362 $res = $mouvP->livraison($user, $line->fk_product, $warehouseid, $line->qty, $line->price, $labeltakeposmovement,
'',
'',
'', $prod_batch->batch, $prod_batch->id, $inventorycode);
369 $mouvP->setOrigin($invoice->element, $invoice->id);
371 $res = $mouvP->livraison($user, $line->fk_product, $warehouseid, $line->qty, $line->price, $labeltakeposmovement,
'',
'',
'',
'', 0, $inventorycode);
381 if (!$error && $res >= 0) {
387 if ($action ==
'creditnote' && $user->hasRight(
'facture',
'creer')) {
390 $creditnote =
new Facture($db);
391 $creditnote->socid = $invoice->socid;
393 $creditnote->module_source =
'takepos';
394 $creditnote->pos_source = isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'' ;
396 $creditnote->fk_facture_source = $placeid;
399 $creditnote->create($user);
403 foreach ($invoice->lines as $line) {
405 if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) {
410 if (!empty($invoice->situation_counter)) {
411 $source_fk_prev_id = $line->fk_prev_id;
412 $line->fk_prev_id = $line->id;
413 if (!empty($invoice->tab_previous_situation_invoice)) {
416 $tab_jumped_credit_notes = array();
417 $lineIndex = count($invoice->tab_previous_situation_invoice) - 1;
418 $searchPreviousInvoice =
true;
419 while ($searchPreviousInvoice) {
420 if ($invoice->tab_previous_situation_invoice[$lineIndex]->situation_cycle_ref || $lineIndex < 1) {
421 $searchPreviousInvoice =
false;
425 $tab_jumped_credit_notes[$lineIndex] = $invoice->tab_previous_situation_invoice[$lineIndex]->id;
431 $maxPrevSituationPercent = 0;
432 foreach ($invoice->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine) {
433 if ($prevLine->id == $source_fk_prev_id) {
434 $maxPrevSituationPercent = max($maxPrevSituationPercent, $prevLine->situation_percent);
437 $line->total_ht -= $prevLine->total_ht;
438 $line->total_tva -= $prevLine->total_tva;
439 $line->total_ttc -= $prevLine->total_ttc;
440 $line->total_localtax1 -= $prevLine->total_localtax1;
441 $line->total_localtax2 -= $prevLine->total_localtax2;
443 $line->multicurrency_subprice -= $prevLine->multicurrency_subprice;
444 $line->multicurrency_total_ht -= $prevLine->multicurrency_total_ht;
445 $line->multicurrency_total_tva -= $prevLine->multicurrency_total_tva;
446 $line->multicurrency_total_ttc -= $prevLine->multicurrency_total_ttc;
451 $line->situation_percent = $maxPrevSituationPercent - $line->situation_percent;
456 $maxPrevSituationPercent = 0;
457 foreach ($tab_jumped_credit_notes as $index => $creditnoteid) {
458 foreach ($invoice->tab_previous_situation_invoice[$index]->lines as $prevLine) {
459 if ($prevLine->fk_prev_id == $source_fk_prev_id) {
460 $maxPrevSituationPercent = $prevLine->situation_percent;
462 $line->total_ht -= $prevLine->total_ht;
463 $line->total_tva -= $prevLine->total_tva;
464 $line->total_ttc -= $prevLine->total_ttc;
465 $line->total_localtax1 -= $prevLine->total_localtax1;
466 $line->total_localtax2 -= $prevLine->total_localtax2;
468 $line->multicurrency_subprice -= $prevLine->multicurrency_subprice;
469 $line->multicurrency_total_ht -= $prevLine->multicurrency_total_ht;
470 $line->multicurrency_total_tva -= $prevLine->multicurrency_total_tva;
471 $line->multicurrency_total_ttc -= $prevLine->multicurrency_total_ttc;
477 $line->situation_percent += $maxPrevSituationPercent;
485 $line->fk_facture = $creditnote->id;
486 $line->fk_parent_line = $fk_parent_line;
488 $line->subprice = -$line->subprice;
490 $line->total_ht = -$line->total_ht;
491 $line->total_tva = -$line->total_tva;
492 $line->total_ttc = -$line->total_ttc;
493 $line->total_localtax1 = -$line->total_localtax1;
494 $line->total_localtax2 = -$line->total_localtax2;
496 $line->multicurrency_subprice = -$line->multicurrency_subprice;
497 $line->multicurrency_total_ht = -$line->multicurrency_total_ht;
498 $line->multicurrency_total_tva = -$line->multicurrency_total_tva;
499 $line->multicurrency_total_ttc = -$line->multicurrency_total_ttc;
501 $result = $line->insert(0, 1);
503 $creditnote->lines[] = $line;
506 if ($result > 0 && $line->product_type == 9) {
507 $fk_parent_line = $result;
510 $creditnote->update_price(1);
514 $constantforkey =
'CASHDESK_NO_DECREASE_STOCK'.(isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
517 if (isModEnabled(
'stock') && !isModEnabled(
'productbatch') && $allowstockchange) {
521 $conf->global->STOCK_CALCULATE_ON_BILL = 1;
523 $constantforkey =
'CASHDESK_ID_WAREHOUSE'.(isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
525 dol_syslog(
"Validate invoice with stock change into warehouse defined into constant ".$constantforkey.
" = ".
getDolGlobalString($constantforkey).
" or warehouseid= ".$warehouseid.
" if defined.");
530 $res = $creditnote->validate($user,
'',
getDolGlobalString($constantforkey), 0, $batch_rule);
537 $conf->global->STOCK_CALCULATE_ON_BILL = $savconst;
539 $res = $creditnote->validate($user);
543 if (!$error && $res >= 0) {
544 if (isModEnabled(
'stock') && isModEnabled(
'productbatch') && $allowstockchange) {
546 dol_syslog(
"Now we record the stock movement for each qualified line");
549 require_once DOL_DOCUMENT_ROOT .
"/product/stock/class/mouvementstock.class.php";
550 $constantforkey =
'CASHDESK_ID_WAREHOUSE'.$_SESSION[
"takeposterminal"];
553 $labeltakeposmovement =
'TakePOS - '.$langs->trans(
"CreditNote").
' '.$creditnote->ref;
555 foreach ($creditnote->lines as $line) {
557 $warehouseid = ($line->fk_warehouse ? $line->fk_warehouse :
getDolGlobalInt($constantforkey));
560 if ($line->batch !=
'' && $warehouseid > 0) {
565 $mouvP->setOrigin($creditnote->element, $creditnote->id);
567 $res = $mouvP->reception($user, $line->fk_product, $warehouseid, $line->qty, $line->price, $labeltakeposmovement,
'',
'', $line->batch,
'', 0, $inventorycode);
574 $mouvP->setOrigin($creditnote->element, $creditnote->id);
576 $res = $mouvP->reception($user, $line->fk_product, $warehouseid, $line->qty, $line->price, $labeltakeposmovement,
'',
'',
'',
'', 0, $inventorycode);
586 if (!$error && $res >= 0) {
589 $creditnote->id = $placeid;
594 if (($action ==
'history' || $action ==
'creditnote') && $user->hasRight(
'takepos',
'run')) {
595 if ($action ==
'creditnote' && $creditnote->id > 0) {
596 $placeid = $creditnote->id;
602 $invoice->fetch($placeid);
606 if (($action ==
"addline" || $action ==
"freezone") && $placeid == 0 && ($user->hasRight(
'takepos',
'run') || defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
609 include_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
612 $invoice->module_source =
'takepos';
613 $invoice->pos_source = isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'' ;
614 $invoice->entity = !empty($_SESSION[
"takeposinvoiceentity"]) ? $_SESSION[
"takeposinvoiceentity"] :
$conf->entity;
616 if ($invoice->socid <= 0) {
617 $langs->load(
'errors');
623 $placeid = $invoice->create($user);
627 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facture";
628 $sql .=
" SET ref='(PROV-POS".$_SESSION[
"takeposterminal"].
"-".$place.
")'";
629 $sql .=
" WHERE rowid = ".((int) $placeid);
630 $resql = $db->query($sql);
644 if ($action ==
"addline" && ($user->hasRight(
'takepos',
'run') || defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
646 $prod->fetch($idproduct);
649 $customer->fetch($invoice->socid);
651 $datapriceofproduct = $prod->getSellPrice($mysoc, $customer, 0);
654 $price = $datapriceofproduct[
'pu_ht'];
655 $price_ttc = $datapriceofproduct[
'pu_ttc'];
657 $price_base_type = empty($datapriceofproduct[
'price_base_type']) ?
'HT' : $datapriceofproduct[
'price_base_type'];
658 $tva_tx = $datapriceofproduct[
'tva_tx'];
659 $tva_npr = $datapriceofproduct[
'tva_npr'];
662 $localtax1_tx =
get_localtax($tva_tx, 1, $customer, $mysoc, $tva_npr);
663 $localtax2_tx =
get_localtax($tva_tx, 2, $customer, $mysoc, $tva_npr);
666 if (isModEnabled(
'productbatch') && isModEnabled(
'stock')) {
667 $batch =
GETPOST(
'batch',
'alpha');
669 if (!empty($batch)) {
670 $action =
"setbatch";
671 } elseif ($prod->status_batch > 0) {
676 $prod->load_stock(
'warehouseopen');
678 $constantforkey =
'CASHDESK_ID_WAREHOUSE'.$_SESSION[
"takeposterminal"];
682 foreach ($prod->stock_warehouse as $tmpwarehouseid => $tmpval) {
687 if (!empty($prod->stock_warehouse[$tmpwarehouseid]) && is_array($prod->stock_warehouse[$tmpwarehouseid]->detail_batch)) {
688 if (is_object($prod->stock_warehouse[$tmpwarehouseid]) && count($prod->stock_warehouse[$tmpwarehouseid]->detail_batch)) {
689 foreach ($prod->stock_warehouse[$tmpwarehouseid]->detail_batch as $dbatch) {
698 echo
"function addbatch(batch, warehouseid) {\n";
699 echo
"console.log('We add batch '+batch+' from warehouse id '+warehouseid);\n";
700 echo
'$("#poslines").load("'.DOL_URL_ROOT.
'/takepos/invoice.php?action=addline&batch="+encodeURI(batch)+"&warehouseid="+warehouseid+"&place='.$place.
'&idproduct='.$idproduct.
'&token='.
newToken().
'", function() {});'.
"\n";
705 echo
"<center>".$langs->trans(
"SearchIntoBatch").
": <b> $nbofsuggested </b></center><br><table>";
706 foreach ($prod->stock_warehouse as $tmpwarehouseid => $tmpval) {
711 if (!empty($prod->stock_warehouse[$tmpwarehouseid]) && is_array($prod->stock_warehouse[$tmpwarehouseid]->detail_batch)) {
712 foreach ($prod->stock_warehouse[$tmpwarehouseid]->detail_batch as $dbatch) {
713 $batchStock = + $dbatch->qty;
714 $quantityToBeDelivered = 1;
715 $deliverableQty = min($quantityToBeDelivered, $batchStock);
717 print
'<!-- subj='.$suggestednb.
'/'.$nbofsuggested.
' -->';
718 print
'<!-- Show details of lot/serial in warehouseid='.$tmpwarehouseid.
' -->';
719 print
'<td class="left">';
721 $detail .=
'<span class="opacitymedium">'.$langs->trans(
"LotSerial").
':</span> '.$dbatch->batch;
728 $detail .=
'</td><td>';
729 $detail .=
'<span class="opacitymedium">'.$langs->trans(
"Qty").
':</span> '.$dbatch->qty;
730 $detail .=
'</td><td>';
731 $detail .=
' <button class="marginleftonly" onclick="addbatch(\''.dol_escape_js($dbatch->batch).
'\',
'.$tmpwarehouseid.')
">'.$langs->trans("Select
")."</
button>
";
735 $quantityToBeDelivered -= $deliverableQty;
736 if ($quantityToBeDelivered < 0) {
737 $quantityToBeDelivered = 0;
746 print '</body></html>';
752 if (getDolGlobalString('TAKEPOS_SUPPLEMENTS')) {
753 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
754 $cat = new Categorie($db);
755 $categories = $cat->containing($idproduct, 'product');
756 $found = (array_search(getDolGlobalInt('TAKEPOS_SUPPLEMENTS_CATEGORY'), array_column($categories, 'id')));
757 if ($found !== false) { // If this product is a supplement
758 $sql = "SELECT fk_parent_line FROM
".MAIN_DB_PREFIX."facturedet where rowid =
".((int) $selectedline);
759 $resql = $db->query($sql);
760 $row = $db->fetch_array($resql);
761 if ($row[0] == null) {
762 $parent_line = $selectedline;
764 $parent_line = $row[0]; //If the parent line is already a supplement, add the supplement to the main product
771 // Group if enabled. Skip group if line already sent to the printer
772 if (getDolGlobalString('TAKEPOS_GROUP_SAME_PRODUCT')) {
773 foreach ($invoice->lines as $line) {
774 if ($line->product_ref == $prod->ref) {
775 if ($line->special_code == 4) {
777 } // If this line is sended to printer create new line
778 // check if qty in stock
779 if (getDolGlobalString('TAKEPOS_QTY_IN_STOCK') && (($line->qty + $qty) > $prod->stock_reel)) {
780 $invoice->error = $langs->trans("ErrorStockIsNotEnough
");
781 dol_htmloutput_errors($invoice->error, $invoice->errors, 1);
785 $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);
787 dol_htmloutput_errors($invoice->error, $invoice->errors, 1);
789 $idoflineadded = $line->id;
795 if ($idoflineadded <= 0 && empty($err)) {
796 $invoice->fetch_thirdparty();
797 $array_options = array();
799 $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);
801 /* setup of margin calculation */
802 if (getDolGlobalString('MARGIN_TYPE')) {
803 if (getDolGlobalString('MARGIN_TYPE') == 'pmp' && !empty($prod->pmp)) {
804 $line['fk_fournprice'] = null;
805 $line['pa_ht'] = $prod->pmp;
806 } elseif (getDolGlobalString('MARGIN_TYPE') == 'costprice' && !empty($prod->cost_price)) {
807 $line['fk_fournprice'] = null;
808 $line['pa_ht'] = $prod->cost_price;
810 // default is fournprice
811 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
812 $pf = new ProductFournisseur($db);
813 if ($pf->find_min_price_product_fournisseur($idproduct, $qty) > 0) {
814 $line['fk_fournprice'] = $pf->product_fourn_price_id;
815 $line['pa_ht'] = $pf->fourn_unitprice_with_discount;
816 if (getDolGlobalString('PRODUCT_CHARGES') && $pf->fourn_charges > 0) {
817 $line['pa_ht'] += (float) $pf->fourn_charges / $pf->fourn_qty;
823 // complete line by hook
824 $parameters = array('prod' => $prod, 'line' => $line);
825 $reshook = $hookmanager->executeHooks('completeTakePosAddLine', $parameters, $invoice, $action); // Note that $action and $line may have been modified by some hooks
827 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
831 if (empty($reshook)) {
832 if (!empty($hookmanager->resArray)) {
833 $line = $hookmanager->resArray;
836 // check if qty in stock
837 if (getDolGlobalString('TAKEPOS_QTY_IN_STOCK') && $qty > $prod->stock_reel) {
838 $invoice->error = $langs->trans("ErrorStockIsNotEnough
");
839 dol_htmloutput_errors($invoice->error, $invoice->errors, 1);
844 $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);
848 if (getDolGlobalString('TAKEPOS_CUSTOMER_DISPLAY')) {
849 $CUSTOMER_DISPLAY_line1 = $prod->label;
850 $CUSTOMER_DISPLAY_line2 = price($price_ttc);
854 $invoice->fetch($placeid);
857 // If we add a line by submitting freezone form (invoice exists here because it was created juste before if it didn't exists)
858 if ($action == "freezone
" && $user->hasRight('takepos', 'run')) {
859 $customer = new Societe($db);
860 $customer->fetch($invoice->socid);
862 $tva_tx = GETPOST('tva_tx', 'alpha');
864 if (!preg_match('/\((.*)\)/', $tva_tx)) {
865 $tva_tx = price2num($tva_tx);
868 $tva_tx = get_default_tva($mysoc, $customer);
872 $localtax1_tx = get_localtax($tva_tx, 1, $customer, $mysoc, $tva_npr);
873 $localtax2_tx = get_localtax($tva_tx, 2, $customer, $mysoc, $tva_npr);
875 $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);
877 dol_htmloutput_errors($invoice->error, $invoice->errors, 1);
879 $invoice->fetch($placeid);
882 if ($action == "addnote
" && ($user->hasRight('takepos', 'run') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
883 $desc = GETPOST('addnote', 'alpha');
885 $invoice->update_note($desc, '_public');
887 foreach ($invoice->lines as $line) {
888 if ($line->id == $idline) {
889 $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);
893 $invoice->fetch($placeid);
896 if ($action == "deleteline
" && ($user->hasRight('takepos', 'run') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
898 $permissiontoupdateline = ($user->hasRight('takepos', 'editlines') && ($user->hasRight('takepos', 'editorderedlines') || $line->special_code != "4
"));
899 if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
900 if ($invoice->status == $invoice::STATUS_DRAFT && $invoice->pos_source && $invoice->module_source == 'takepos') {
901 $permissiontoupdateline = true;
902 // TODO Add also a test on $_SESSION('publicobjectid'] defined at creation of object
903 // TODO Check also that invoice->ref is (PROV-POS1-2) with 1 = terminal and 2, the table ID
907 if ($idline > 0 && $placeid > 0) { // If invoice exists and line selected. To avoid errors if deleted from another device or no line selected.
908 $invoice->deleteLine($idline);
909 $invoice->fetch($placeid);
910 } elseif ($placeid > 0) { // If invoice exists but no line selected, proceed to delete last line.
911 $sql = "SELECT rowid FROM
".MAIN_DB_PREFIX."facturedet where fk_facture =
".((int) $placeid)." ORDER BY rowid DESC
";
912 $resql = $db->query($sql);
913 $row = $db->fetch_array($resql);
914 $deletelineid = $row[0];
915 $invoice->deleteLine($deletelineid);
916 $invoice->fetch($placeid);
919 if (count($invoice->lines) == 0) {
920 $invoice->delete($user);
922 if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
923 header("Location:
".DOL_URL_ROOT."/takepos/public/auto_order.php
");
925 header("Location:
".DOL_URL_ROOT."/takepos/invoice.php
");
931 // Action to delete or discard an invoice
932 if ($action == "delete
" && ($user->hasRight('takepos', 'run') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
933 // $placeid is the invoice id (it differs from place) and is defined if the place is set and
934 // the ref of invoice is '(PROV-POS'.$_SESSION["takeposterminal
"].'-'.$place.')', so the fetch at beginning of page works.
936 $result = $invoice->fetch($placeid);
938 if ($result > 0 && $invoice->status == Facture::STATUS_DRAFT) {
941 // We delete the lines
943 foreach ($invoice->lines as $line) {
944 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
945 $tmpres = $invoice->deleteLine($line->id);
952 $sql = "UPDATE
".MAIN_DB_PREFIX."facture
";
953 $varforconst = 'CASHDESK_ID_THIRDPARTY'.$_SESSION["takeposterminal
"];
954 $sql .= " SET fk_soc =
".((int) getDolGlobalString($varforconst)).",
";
955 $sql .= " datec =
'".$db->idate(dol_now())."'";
956 $sql .= " WHERE entity IN (
".getEntity('invoice').")
";
957 $sql .= " AND
ref =
'(PROV-POS".$db->escape($_SESSION["takeposterminal"]."-".$place).")'";
958 $resql1 = $db->query($sql);
960 if ($resdeletelines && $resql1) {
966 $invoice->fetch($placeid);
971 if ($action == "updateqty
") { // Test on permission is done later
972 foreach ($invoice->lines as $line) {
973 if ($line->id == $idline) {
974 $permissiontoupdateline = ($user->hasRight('takepos', 'editlines') && ($user->hasRight('takepos', 'editorderedlines') || $line->special_code != "4
"));
975 if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
976 if ($invoice->status == $invoice::STATUS_DRAFT && $invoice->pos_source && $invoice->module_source == 'takepos') {
977 $permissiontoupdateline = true;
978 // TODO Add also a test on $_SESSION('publicobjectid'] defined at creation of object
979 // TODO Check also that invoice->ref is (PROV-POS1-2) with 1 = terminal and 2, the table ID
982 if (!$permissiontoupdateline) {
983 dol_htmloutput_errors($langs->trans("NotEnoughPermissions
", "TakePos
").' - No permission to updateqty', [], 1);
985 $vatratecode = $line->tva_tx;
986 if ($line->vat_src_code) {
987 $vatratecode .= ' ('.$line->vat_src_code.')';
990 $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);
995 $invoice->fetch($placeid);
998 if ($action == "updateprice
") { // Test on permission is done later
999 $customer = new Societe($db);
1000 $customer->fetch($invoice->socid);
1002 foreach ($invoice->lines as $line) {
1003 if ($line->id == $idline) {
1004 $prod = new Product($db);
1005 $prod->fetch($line->fk_product);
1006 $datapriceofproduct = $prod->getSellPrice($mysoc, $customer, 0);
1007 $price_min = $datapriceofproduct['price_min'];
1008 $usercanproductignorepricemin = ((getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !$user->hasRight('produit', 'ignore_price_min_advance')) || !getDolGlobalString('MAIN_USE_ADVANCED_PERMS'));
1010 $vatratecleaned = $line->tva_tx;
1012 if (preg_match('/^(.*)\s*\((.*)\)$/', (string) $line->tva_tx, $reg)) { // If vat is "xx (yy)
"
1013 $vatratecleaned = trim($reg[1]);
1014 //$vatratecode = $reg[2];
1017 $pu_ht = price2num((float) price2num($number, 'MU') / (1 + ((float) $vatratecleaned / 100)), 'MU');
1019 if ($usercanproductignorepricemin && (!empty($price_min) && ((float) price2num($pu_ht) * (1 - (float) price2num($line->remise_percent) / 100) < price2num($price_min)))) {
1020 $langs->load("products
");
1021 dol_htmloutput_errors($langs->trans("CantBeLessThanMinPrice
", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, -1, $conf->currency)));
1022 // echo $langs->trans("CantBeLessThanMinPrice
");
1024 $permissiontoupdateline = ($user->hasRight('takepos', 'editlines') && ($user->hasRight('takepos', 'editorderedlines') || $line->special_code != "4
"));
1025 if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1026 if ($invoice->status == $invoice::STATUS_DRAFT && $invoice->pos_source && $invoice->module_source == 'takepos') {
1027 $permissiontoupdateline = true;
1028 // TODO Add also a test on $_SESSION('publicobjectid'] defined at creation of object
1029 // TODO Check also that invoice->ref is (PROV-POS1-2) with 1 = terminal and 2, the table ID
1033 $vatratecode = $line->tva_tx;
1034 if ($line->vat_src_code) {
1035 $vatratecode .= ' ('.$line->vat_src_code.')';
1038 if (!$permissiontoupdateline) {
1039 dol_htmloutput_errors($langs->trans("NotEnoughPermissions
", "TakePos
").' - No permission to updateprice', [], 1);
1040 } elseif (getDolGlobalInt('TAKEPOS_CHANGE_PRICE_HT') == 1) {
1041 $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);
1043 $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);
1050 $invoice->fetch($placeid);
1053 if ($action == "updatereduction
") { // Test on permission is done later
1054 $customer = new Societe($db);
1055 $customer->fetch($invoice->socid);
1057 foreach ($invoice->lines as $line) {
1058 if ($line->id == $idline) {
1059 dol_syslog("updatereduction Process line
".$line->id.' to apply discount of '.$number.'%');
1061 $prod = new Product($db);
1062 $prod->fetch($line->fk_product);
1064 $datapriceofproduct = $prod->getSellPrice($mysoc, $customer, 0);
1065 $price_min = $datapriceofproduct['price_min'];
1066 $usercanproductignorepricemin = ((getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !$user->hasRight('produit', 'ignore_price_min_advance')) || !getDolGlobalString('MAIN_USE_ADVANCED_PERMS'));
1068 $pu_ht = price2num($line->subprice / (1 + ($line->tva_tx / 100)), 'MU');
1071 if ($usercanproductignorepricemin && (!empty($price_min) && ((float) price2num($line->subprice) * (1 - (float) price2num($number) / 100) < (float) price2num($price_min)))) {
1072 $langs->load("products
");
1073 dol_htmloutput_errors($langs->trans("CantBeLessThanMinPrice
", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, -1, $conf->currency)));
1075 $permissiontoupdateline = ($user->hasRight('takepos', 'editlines') && ($user->hasRight('takepos', 'editorderedlines') || $line->special_code != "4
"));
1076 if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1077 if ($invoice->status == $invoice::STATUS_DRAFT && $invoice->pos_source && $invoice->module_source == 'takepos') {
1078 $permissiontoupdateline = true;
1079 // TODO Add also a test on $_SESSION('publicobjectid'] defined at creation of object
1080 // TODO Check also that invoice->ref is (PROV-POS1-2) with 1 = terminal and 2, the table ID
1083 if (!$permissiontoupdateline) {
1084 dol_htmloutput_errors($langs->trans("NotEnoughPermissions
", "TakePos
"), [], 1);
1086 $vatratecode = $line->tva_tx;
1087 if ($line->vat_src_code) {
1088 $vatratecode .= ' ('.$line->vat_src_code.')';
1090 $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);
1097 $invoice->fetch($placeid);
1098 } elseif ($action == 'update_reduction_global' && $user->hasRight('takepos', 'editlines')) {
1099 foreach ($invoice->lines as $line) {
1100 $vatratecode = $line->tva_tx;
1101 if ($line->vat_src_code) {
1102 $vatratecode .= ' ('.$line->vat_src_code.')';
1104 $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);
1107 $invoice->fetch($placeid);
1110 if ($action == "setbatch
" && ($user->hasRight('takepos', 'run') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
1111 $constantforkey = 'CASHDESK_ID_WAREHOUSE'.$_SESSION["takeposterminal
"];
1112 $warehouseid = (GETPOSTINT('warehouseid') > 0 ? GETPOSTINT('warehouseid') : getDolGlobalInt($constantforkey)); // Get the warehouse id from GETPOSTINT('warehouseid'), otherwise use default setup.
1113 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet SET batch =
'".$db->escape($batch)."', fk_warehouse =
".((int) $warehouseid);
1114 $sql .= " WHERE rowid=
".((int) $idoflineadded);
1118 if ($action == "order
" && $placeid != 0 && ($user->hasRight('takepos', 'run') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
1119 include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
1120 if ((isModEnabled('receiptprinter') && getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term) > 0) || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter
" || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector
") {
1121 require_once DOL_DOCUMENT_ROOT.'/core/class/dolreceiptprinter.class.php';
1122 $printer = new dolReceiptPrinter($db);
1125 $sql = "SELECT label FROM
".MAIN_DB_PREFIX."takepos_floor_tables where rowid=
".((int) $place);
1126 $resql = $db->query($sql);
1127 $row = $db->fetch_object($resql);
1128 $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>';
1129 $footerorder = '</tbody></table>'.dol_print_date(dol_now(), 'dayhour').'<br></html>';
1130 $order_receipt_printer1 = "";
1131 $order_receipt_printer2 = "";
1132 $order_receipt_printer3 = "";
1133 $catsprinter1 = explode(';', getDolGlobalString('TAKEPOS_PRINTED_CATEGORIES_1'));
1134 $catsprinter2 = explode(';', getDolGlobalString('TAKEPOS_PRINTED_CATEGORIES_2'));
1135 $catsprinter3 = explode(';', getDolGlobalString('TAKEPOS_PRINTED_CATEGORIES_3'));
1137 foreach ($invoice->lines as $line) {
1138 if ($line->special_code == "4
") {
1141 $c = new Categorie($db);
1142 $existing = $c->containing($line->fk_product, Categorie::TYPE_PRODUCT, 'id');
1143 $result = array_intersect($catsprinter1, $existing);
1144 $count = count($result);
1145 if (!$line->fk_product) {
1146 $count++; // Print Free-text item (Unassigned printer) to Printer 1
1150 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet set special_code=
'1' where rowid=
".$line->id; //Set to print on printer 1
1152 $order_receipt_printer1 .= '<tr><td class="left
">';
1153 if ($line->fk_product) {
1154 $order_receipt_printer1 .= $line->product_label;
1156 $order_receipt_printer1 .= $line->description;
1158 $order_receipt_printer1 .= '</td><td class="right
">'.$line->qty;
1159 if (!empty($line->array_options['options_order_notes'])) {
1160 $order_receipt_printer1 .= "<br>(
".$line->array_options['options_order_notes'].")
";
1162 $order_receipt_printer1 .= '</td></tr>';
1165 if (((isModEnabled('receiptprinter') && getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term) > 0) || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter
" || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector
") && $linestoprint > 0) {
1166 $invoice->fetch($placeid); //Reload object before send to printer
1167 $printer->orderprinter = 1;
1169 echo "var orderprinter1esc=
'";
1170 $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
1173 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet
set special_code=
'4' where special_code=
'1' and fk_facture=
".$invoice->id; // Set as printed
1175 $invoice->fetch($placeid); //Reload object after set lines as printed
1178 foreach ($invoice->lines as $line) {
1179 if ($line->special_code == "4
") {
1182 $c = new Categorie($db);
1183 $existing = $c->containing($line->fk_product, Categorie::TYPE_PRODUCT, 'id');
1184 $result = array_intersect($catsprinter2, $existing);
1185 $count = count($result);
1188 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet
set special_code=
'2' where rowid=
".$line->id; //Set to print on printer 2
1190 $order_receipt_printer2 .= '<tr>'.$line->product_label.'<td class="right
">'.$line->qty;
1191 if (!empty($line->array_options['options_order_notes'])) {
1192 $order_receipt_printer2 .= "<br>(
".$line->array_options['options_order_notes'].")
";
1194 $order_receipt_printer2 .= '</td></tr>';
1197 if (((isModEnabled('receiptprinter') && getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term) > 0) || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter
" || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector
") && $linestoprint > 0) {
1198 $invoice->fetch($placeid); //Reload object before send to printer
1199 $printer->orderprinter = 2;
1201 echo "var orderprinter2esc=
'";
1202 $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
1205 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet
set special_code=
'4' where special_code=
'2' and fk_facture=
".$invoice->id; // Set as printed
1207 $invoice->fetch($placeid); //Reload object after set lines as printed
1210 foreach ($invoice->lines as $line) {
1211 if ($line->special_code == "4
") {
1214 $c = new Categorie($db);
1215 $existing = $c->containing($line->fk_product, Categorie::TYPE_PRODUCT, 'id');
1216 $result = array_intersect($catsprinter3, $existing);
1217 $count = count($result);
1220 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet
set special_code=
'3' where rowid=
".$line->id; //Set to print on printer 3
1222 $order_receipt_printer3 .= '<tr>'.$line->product_label.'<td class="right
">'.$line->qty;
1223 if (!empty($line->array_options['options_order_notes'])) {
1224 $order_receipt_printer3 .= "<br>(
".$line->array_options['options_order_notes'].")
";
1226 $order_receipt_printer3 .= '</td></tr>';
1229 if (((isModEnabled('receiptprinter') && getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term) > 0) || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter
" || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector
") && $linestoprint > 0) {
1230 $invoice->fetch($placeid); //Reload object before send to printer
1231 $printer->orderprinter = 3;
1233 echo "var orderprinter3esc=
'";
1234 $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
1237 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet
set special_code=
'4' where special_code=
'3' and fk_facture=
".$invoice->id; // Set as printed
1239 $invoice->fetch($placeid); //Reload object after set lines as printed
1242 $sectionwithinvoicelink = '';
1243 if (($action == "valid
" || $action == "history
" || $action == 'creditnote') && $user->hasRight('takepos', 'run')) {
1244 $sectionwithinvoicelink .= '<!-- Section with invoice link -->'."\n
";
1245 $sectionwithinvoicelink .= '<span style="font-size:120%;
" class="center
">';
1246 $sectionwithinvoicelink .= $invoice->getNomUrl(1, '', 0, 0, '', 0, 0, -1, '_backoffice')." -
";
1247 $remaintopay = $invoice->getRemainToPay();
1248 if ($remaintopay > 0) {
1249 $sectionwithinvoicelink .= $langs->trans('RemainToPay').': <span class="amountremaintopay
" style="font-size: unset
">'.price($remaintopay, 1, $langs, 1, -1, -1, $conf->currency).'</span>';
1251 if ($invoice->paye) {
1252 $sectionwithinvoicelink .= '<span class="amountpaymentcomplete
" style="font-size: unset
">'.$langs->trans("Paid
").'</span>';
1254 $sectionwithinvoicelink .= $langs->trans('BillShortStatusValidated');
1258 $sectionwithinvoicelink .= '</span><br>';
1259 if (getDolGlobalInt('TAKEPOS_PRINT_INVOICE_DOC_INSTEAD_OF_RECEIPT')) {
1260 $sectionwithinvoicelink .= ' <a target="_blank
" class="button" href="' . DOL_URL_ROOT . '/document.php?token=
' . newToken() . '&modulepart=facture&file=
' . $invoice->ref . '/
' . $invoice->ref . '.pdf
">Invoice</a>';
1261 } elseif (getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector
") {
1262 if (getDolGlobalString('TAKEPOS_PRINT_SERVER') && filter_var(getDolGlobalString('TAKEPOS_PRINT_SERVER'), FILTER_VALIDATE_URL) == true) {
1263 $sectionwithinvoicelink .= ' <button id="buttonprint
" type="button" onclick="TakeposConnector(
'.$placeid.')
">'.$langs->trans('PrintTicket').'</button>';
1265 $sectionwithinvoicelink .= ' <button id="buttonprint
" type="button" onclick="TakeposPrinting(
'.$placeid.')
">'.$langs->trans('PrintTicket').'</button>';
1267 } elseif ((isModEnabled('receiptprinter') && getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term) > 0) || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter
") {
1268 $sectionwithinvoicelink .= ' <button id="buttonprint
" type="button" onclick="DolibarrTakeposPrinting(
'.$placeid.')
">'.$langs->trans('PrintTicket').'</button>';
1270 $sectionwithinvoicelink .= ' <button id="buttonprint
" type="button" onclick="Print(
'.$placeid.')
">'.$langs->trans('PrintTicket').'</button>';
1271 if (getDolGlobalString('TAKEPOS_PRINT_WITHOUT_DETAILS')) {
1272 $sectionwithinvoicelink .= ' <button id="buttonprint
" type="button" onclick="PrintBox(
'.$placeid.', \
'without_details\')">'.$langs->trans(
'PrintWithoutDetails').
'</button>';
1275 $sectionwithinvoicelink .=
' <button id="buttonprint" type="button" onclick="Print('.$placeid.
', 1)">'.$langs->trans(
'GiftReceipt').
'</button>';
1279 $sectionwithinvoicelink .=
' <button id="buttonsend" type="button" onclick="SendTicket('.$placeid.
')">'.$langs->trans(
'SendTicket').
'</button>';
1282 if ($remaintopay <= 0 &&
getDolGlobalString(
'TAKEPOS_AUTO_PRINT_TICKETS') && $action !=
"history") {
1283 $sectionwithinvoicelink .=
'<script type="text/javascript">$("#buttonprint").click();</script>';
1293$form =
new Form($db);
1296if ((
getDolGlobalString(
'TAKEPOS_PHONE_BASIC_LAYOUT') == 1 &&
$conf->browser->layout ==
'phone') || defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1297 $title =
'TakePOS - Dolibarr '.DOL_VERSION;
1301 $head =
'<meta name="apple-mobile-web-app-title" content="TakePOS"/>
1302 <meta name="apple-mobile-web-app-capable" content="yes">
1303 <meta name="mobile-web-app-capable" content="yes">
1304 <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>';
1305 $arrayofcss = array(
1306 '/takepos/css/pos.css.php',
1308 $arrayofjs = array(
'/takepos/js/jquery.colorbox-min.js');
1311 top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss);
1313 print
'<body>'.
"\n";
1320<script
type=
"text/javascript">
1323<?php
if ($action ==
"valid") {
1324 echo
"var place=0;";
1326var placeid=<?php echo($placeid > 0 ? $placeid : 0); ?>;
1327$(document).ready(
function() {
1328 var idoflineadded = <?php echo(empty($idoflineadded) ? 0 : $idoflineadded); ?>;
1330 $(
'.posinvoiceline').click(
function(){
1331 console.log(
"Click done on "+this.
id);
1332 $(
'.posinvoiceline').removeClass(
"selected");
1333 $(
this).addClass(
"selected");
1337 if (selectedline == this.
id) {
1340 selectedline = this.id;
1342 selectedtext=$(
'#'+selectedline).find(
"td:first").html();
1344 if (defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1345 print
'$("#phonediv1").load("'.DOL_URL_ROOT.
'/takepos/public/auto_order.php?action=editline&token='.
newToken().
'&placeid="+placeid+"&selectedline="+selectedline, function() {
1352 if (idoflineadded > 0)
1354 console.log(
"Auto select "+idoflineadded);
1355 $(
'.posinvoiceline#'+idoflineadded).click();
1359if ($action ==
"order" && !empty($order_receipt_printer1)) {
1360 if (filter_var(
getDolGlobalString(
'TAKEPOS_PRINT_SERVER'), FILTER_VALIDATE_URL) ==
true) {
1364 url:
'<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER
'); ?>/printer/index.php',
1365 data:
'invoice='+orderprinter1esc
1372 url:
'http://<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER
'); ?>:8111/print',
1374 print $headerorder.$order_receipt_printer1.$footerorder; ?>'
1380if ($action ==
"order" && !empty($order_receipt_printer2)) {
1381 if (filter_var(
getDolGlobalString(
'TAKEPOS_PRINT_SERVER'), FILTER_VALIDATE_URL) ==
true) {
1385 url:
'<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER
'); ?>/printer/index.php?printer=2',
1386 data:
'invoice='+orderprinter2esc
1393 url:
'http://<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER
'); ?>:8111/print2',
1395 print $headerorder.$order_receipt_printer2.$footerorder; ?>'
1401if ($action ==
"order" && !empty($order_receipt_printer3)) {
1402 if (filter_var(
getDolGlobalString(
'TAKEPOS_PRINT_SERVER'), FILTER_VALIDATE_URL) ==
true) {
1406 url:
'<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER
'); ?>/printer/index.php?printer=3',
1407 data:
'invoice='+orderprinter3esc
1414if ($action ==
"search" || $action ==
"valid") {
1416 parent.ClearSearch(
true);
1421if ($action ==
"temp" && !empty($ticket_printer1)) {
1425 url:
'http://<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER
'); ?>:8111/print',
1427 print $header_soc.$header_ticket.$body_ticket.$ticket_printer1.$ticket_total.$footer_ticket; ?>'
1432if ($action ==
"search") {
1434 $(
'#search').focus();
1442function SendTicket(
id)
1444 console.log(
"Open box to select the Print/Send form");
1445 $.colorbox({href:
"send.php?facid="+id, width:
"70%", height:
"30%", transition:
"none", iframe:
"true", title:
'<?php echo dol_escape_js($langs->trans("SendTicket")); ?>'});
1449function PrintBox(
id, action) {
1450 console.log(
"Open box before printing");
1451 $.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
"); ?>"});
1455function Print(
id, gift){
1456 console.log(
"Call Print() to generate the receipt.");
1457 $.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")); ?>'});
1461function TakeposPrinting(
id){
1463 console.log(
"TakeposPrinting" +
id);
1464 $.get(
"receipt.php?facid="+
id,
function(data,
status) {
1465 receipt=data.replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g,
'');
1468 url:
'http://<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER
'); ?>:8111/print',
1475function TakeposConnector(
id){
1476 console.log(
"TakeposConnector" +
id);
1477 $.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) {
1480 url:
'<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER
'); ?>/printer/index.php',
1481 data:
'invoice='+data
1489function DolibarrTakeposPrinting(
id) {
1490 console.log(
"DolibarrTakeposPrinting Printing invoice ticket " +
id);
1493 data: { token:
'<?php echo currentToken(); ?>' },
1494 url:
"<?php print DOL_URL_ROOT.'/takepos/ajax/ajax.php?action=printinvoiceticket&token='.newToken().'&term='.urlencode(isset($_SESSION["takeposterminal
"]) ? $_SESSION["takeposterminal
"] : '').'&id='; ?>" + id,
1501function CreditNote() {
1502 $(
"#poslines").load(
"<?php print DOL_URL_ROOT; ?>/takepos/invoice.php?action=creditnote&token=<?php echo newToken() ?>&invoiceid="+placeid,
function() { });
1508 $(
"#poslines").load(
"<?php print DOL_URL_ROOT; ?>/takepos/invoice.php?action=addnote&token=<?php echo newToken() ?>&invoiceid="+placeid+
"&idline="+selectedline, {
"addnote": $(
"#textinput").val() });
1513$( document ).ready(
function() {
1514 console.log(
"Set customer info and sales in header placeid=<?php echo $placeid; ?> status=<?php echo $invoice->statut; ?>");
1517 $s = $langs->trans(
"Customer");
1518 if ($invoice->id > 0 && ($invoice->socid !=
getDolGlobalString($constforcompanyid))) {
1521 $contactids = $invoice->getIdContact(
'external',
'BILLING');
1522 $contactid = $contactids[0];
1523 if ($contactid > 0) {
1525 $contact->fetch($contactid);
1526 $s .=
" - " . $contact->getFullName($langs);
1530 print
'$("#idcustomer").val("");';
1534 $(
"#customerandsales").html(
'');
1535 $(
"#shoppingcart").html(
'');
1538 $(
"#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>');
1540 $(
"#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>');
1544 $sql =
"SELECT rowid, datec, ref FROM ".MAIN_DB_PREFIX.
"facture";
1545 $sql .=
" WHERE entity IN (".getEntity(
'invoice').
")";
1548 $sql .=
" AND ref LIKE '(PROV-POS".$db->escape(isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'').
"-0%'";
1551 $sql .=
" AND pos_source = '".$db->escape($_SESSION[
"takeposterminal"]).
"'";
1552 $sql .=
" AND module_source = 'takepos'";
1555 $sql .= $db->order(
'datec',
'ASC');
1556 $resql = $db->query($sql);
1559 while ($obj = $db->fetch_object($resql)) {
1560 echo
'$("#shoppingcart").append(\'';
1561 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=\\\'';
1562 $num_sale = str_replace(
")",
"", str_replace(
"(PROV-POS".$_SESSION[
"takeposterminal"].
"-",
"", $obj->ref));
1564 if (str_replace(
"-",
"", $num_sale) > $max_sale) {
1565 $max_sale = str_replace(
"-",
"", $num_sale);
1567 echo
'\\\'; invoiceid=\\\'';
1569 echo
'\\\'; Refresh();">';
1570 if ($placeid == $obj->rowid) {
1571 echo
'<span class="basketselected">';
1573 echo
'<span class="basketnotselected">';
1575 echo
'<span class="fa fa-shopping-cart paddingright"></span>'.dol_print_date($db->jdate($obj->datec),
'%H:%M',
'tzuser');
1579 echo
'$("#shoppingcart").append(\'<a onclick="place=\\\'0-';
1581 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>\');';
1589 $constantforkey =
'CASHDESK_NO_DECREASE_STOCK'. (isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
1590 if (isModEnabled(
'stock')) {
1592 $constantforkey =
'CASHDESK_ID_WAREHOUSE'. (isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
1594 if ($idwarehouse > 0) {
1595 $s =
'<span class="small">';
1597 $warehouse->fetch($idwarehouse);
1598 $s .=
'<span class="hideonsmartphone">'.$langs->trans(
"Warehouse").
'<br></span>'.$warehouse->ref;
1600 $s .=
' ('.$langs->trans(
"Closed").
')';
1603 print
"$('#infowarehouse').html('".dol_escape_js($s).
"');";
1604 print
'$("#infowarehouse").css("display", "inline-block");';
1606 $s =
'<span class="small hideonsmartphone">';
1607 $s .= $langs->trans(
"StockChangeDisabled").
'<br>'.$langs->trans(
"NoWarehouseDefinedForTerminal");
1609 print
"$('#infowarehouse').html('".dol_escape_js($s).
"');";
1610 if (!empty(
$conf->dol_optimize_smallscreen)) {
1611 print
'$("#infowarehouse").css("display", "none");';
1615 $s =
'<span class="small hideonsmartphone">'.$langs->trans(
"StockChangeDisabled").
'</span>';
1616 print
"$('#infowarehouse').html('".dol_escape_js($s).
"');";
1617 if (!empty(
$conf->dol_optimize_smallscreen)) {
1618 print
'$("#infowarehouse").css("display", "none");';
1626 if (isModEnabled(
'member') && $invoice->socid > 0 && $invoice->socid !=
getDolGlobalInt($constforcompanyid)) {
1627 $s =
'<span class="small">';
1628 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
1629 $langs->load(
"members");
1630 $s .= $langs->trans(
"Member").
': ';
1632 $result = $adh->fetch(
'',
'', $invoice->socid);
1634 $adh->ref = $adh->getFullName($langs);
1638 $s .= $adh->getFullName($langs);
1639 $s .=
' - '.$adh->type;
1640 if ($adh->datefin) {
1641 $s .=
'<br>'.$langs->trans(
"SubscriptionEndDate").
': '.
dol_print_date($adh->datefin,
'day');
1642 if ($adh->hasDelay()) {
1643 $s .=
" ".img_warning($langs->trans(
"Late"));
1646 $s .=
'<br>'.$langs->trans(
"SubscriptionNotReceived");
1647 if ($adh->statut > 0) {
1648 $s .=
" ".img_warning($langs->trans(
"Late"));
1655 $s .=
'<br>'.$langs->trans(
"ThirdpartyNotLinkedToMember");
1660 $(
"#moreinfo").html(
'<?php print dol_escape_js($s); ?>');
1667 echo
"function CustomerDisplay(){";
1668 echo
"var line1='".$CUSTOMER_DISPLAY_line1.
"'.substring(0,20);";
1669 echo
"line1=line1.padEnd(20);";
1670 echo
"var line2='".$CUSTOMER_DISPLAY_line2.
"'.substring(0,20);";
1671 echo
"line2=line2.padEnd(20);";
1674 data: { text: line1+line2 },
1675 url: '".getDolGlobalString(
'TAKEPOS_PRINT_SERVER').
"/display/index.php',
1686if (!empty(
$conf->use_javascript_ajax)) {
1687 print
"\n".
'<!-- Includes JS Footer of Dolibarr -->'.
"\n";
1688 print
'<script src="'.DOL_URL_ROOT.
'/core/js/lib_foot.js.php?lang='.$langs->defaultlang.
'"></script>'.
"\n";