116 header($_SERVER[
'SERVER_PROTOCOL'].
' 500 Internal Server Error',
true, 500);
122$number =
GETPOST(
'number',
'alpha');
125$desc =
GETPOST(
'desc',
'alphanohtml');
138if ($pay ==
'cheque') {
145 $sql =
"SELECT id FROM ".MAIN_DB_PREFIX.
"c_paiement";
146 $sql .=
" WHERE entity IN (".getEntity(
'c_paiement').
")";
147 $sql .=
" AND code = '".$db->escape($paycode).
"'";
148 $resql = $db->query($sql);
150 $obj = $db->fetch_object($resql);
152 $paiementid = $obj->id;
159 $ret = $invoice->fetch($invoiceid);
161 $ret = $invoice->fetch(
'',
'(PROV-POS'.$takeposterminal.
'-'.$place.
')');
164 $placeid = $invoice->id;
167$constforcompanyid =
'CASHDESK_ID_THIRDPARTY'.$takeposterminal;
170if ($invoice->socid > 0) {
171 $soc->fetch($invoice->socid);
177if (isModEnabled(
'project') &&
getDolGlobalInt(
"CASHDESK_ID_PROJECT".$takeposterminal)) {
178 $invoice->fk_project =
getDolGlobalInt(
"CASHDESK_ID_PROJECT".$takeposterminal);
182if (isModEnabled(
'multicurrency') && !empty($_SESSION[
"takeposcustomercurrency"])) {
183 if ($invoice->multicurrency_code != $_SESSION[
"takeposcustomercurrency"]) {
184 $invoice->setMulticurrencyCode($_SESSION[
"takeposcustomercurrency"]);
188$term = empty($_SESSION[
"takeposterminal"]) ? 1 : $_SESSION[
"takeposterminal"];
195$parameters = array();
196$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $invoice, $action);
204if (in_array($action, array(
'deleteline',
'updateqty',
'updateprice',
'updatereduction',
'update_reduction_global')) && !$user->hasRight(
'takepos',
'editlines')) {
209if (empty($reshook)) {
211 if ($action ==
'valid' && $user->hasRight(
'facture',
'creer')) {
219 $bankaccount =
getDolGlobalInt(
'CASHDESK_ID_BANKACCOUNT_CASH'.$_SESSION[
"takeposterminal"]);
220 } elseif ($pay ==
"CHQ") {
221 $bankaccount =
getDolGlobalInt(
'CASHDESK_ID_BANKACCOUNT_CHEQUE'.$_SESSION[
"takeposterminal"]);
223 $accountname =
"CASHDESK_ID_BANKACCOUNT_".$pay.$_SESSION[
"takeposterminal"];
228 if ($bankaccount <= 0 && $pay !=
"delayed" && isModEnabled(
"bank")) {
229 $errormsg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"BankAccount"));
237 $invoice->fetch($placeid);
241 if ($invoice->total_ttc < 0) {
242 $invoice->type = $invoice::TYPE_CREDIT_NOTE;
244 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"facture";
245 $sql .=
" WHERE entity IN (".getEntity(
'invoice').
")";
246 $sql .=
" AND fk_soc = ".((int) $invoice->socid);
247 $sql .=
" AND type <> ".Facture::TYPE_CREDIT_NOTE;
248 $sql .=
" AND fk_statut >= ".$invoice::STATUS_VALIDATED;
249 $sql .=
" ORDER BY rowid DESC";
251 $resql = $db->query($sql);
253 $obj = $db->fetch_object($resql);
254 $fk_source = $obj->rowid;
255 if ($fk_source ==
null) {
256 fail($langs->transnoentitiesnoconv(
"NoPreviousBillForCustomer"));
259 fail($langs->transnoentitiesnoconv(
"NoPreviousBillForCustomer"));
261 $invoice->fk_facture_source = $fk_source;
262 $invoice->update($user);
265 $constantforkey =
'CASHDESK_NO_DECREASE_STOCK'.(isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
272 if ($invoice->getRemainToPay() > 0) {
278 } elseif (count($invoice->lines) == 0) {
282 } elseif (isModEnabled(
'stock') && !isModEnabled(
'productbatch') && $allowstockchange) {
287 $conf->global->STOCK_CALCULATE_ON_BILL = 1;
289 $constantforkey =
'CASHDESK_ID_WAREHOUSE'.$_SESSION[
"takeposterminal"];
290 dol_syslog(
"Validate invoice with stock change. Warehouse defined into constant ".$constantforkey.
" = ".
getDolGlobalString($constantforkey));
295 $res = $invoice->validate($user,
'',
getDolGlobalInt($constantforkey), 0, $batch_rule);
298 $conf->global->STOCK_CALCULATE_ON_BILL = $savconst;
301 $res = $invoice->validate($user);
304 $langs->load(
"admin");
305 dol_htmloutput_errors($invoice->error ==
'NotConfigured' ? $langs->trans(
"NotConfigured").
' (TakePos numbering module)' : $invoice->error, $invoice->errors, 1);
310 if (!$error && $res >= 0) {
311 $remaintopay = $invoice->getRemainToPay();
312 if ($remaintopay > 0) {
314 $payment->datepaye = $now;
315 $payment->fk_account = $bankaccount;
316 $payment->amounts[$invoice->id] = $amountofpayment;
323 if ($amountofpayment <= 0 || $amountofpayment > $remaintopay) {
324 $payment->amounts[$invoice->id] = $remaintopay;
327 $payment->paiementid = $paiementid;
328 $payment->num_payment = $invoice->ref;
330 if ($pay !=
"delayed") {
331 $result = $payment->create($user);
336 $res = $payment->addPaymentToBank($user,
'payment',
'(CustomerInvoicePayment)', $bankaccount,
'',
'');
342 $remaintopay = $invoice->getRemainToPay();
348 if ($remaintopay == 0) {
349 dol_syslog(
"Invoice is paid, so we set it to status Paid");
350 $result = $invoice->setPaid($user);
355 $invoice->setPaymentMethods($paiementid);
357 dol_syslog(
"Invoice is not paid, remain to pay = ".$remaintopay);
364 if (!$error && $res >= 0) {
365 if (isModEnabled(
'stock') && isModEnabled(
'productbatch') && $allowstockchange) {
367 dol_syslog(
"Now we record the stock movement for each qualified line");
370 require_once DOL_DOCUMENT_ROOT .
"/product/stock/class/mouvementstock.class.php";
371 $constantforkey =
'CASHDESK_ID_WAREHOUSE'.$_SESSION[
"takeposterminal"];
374 $labeltakeposmovement =
'TakePOS - '.$langs->trans(
"Invoice").
' '.$invoice->ref;
376 foreach ($invoice->lines as $line) {
378 $warehouseid = ($line->fk_warehouse ? $line->fk_warehouse :
getDolGlobalInt($constantforkey));
381 if ($line->batch !=
'' && $warehouseid > 0) {
383 $prod_batch->find(0,
'',
'', $line->batch, $warehouseid);
386 $mouvP->setOrigin($invoice->element, $invoice->id);
388 $res = $mouvP->livraison($user, $line->fk_product, $warehouseid, $line->qty, $line->price, $labeltakeposmovement,
'',
'',
'', $prod_batch->batch, $prod_batch->id, $inventorycode);
395 $mouvP->setOrigin($invoice->element, $invoice->id);
397 $res = $mouvP->livraison($user, $line->fk_product, $warehouseid, $line->qty, $line->price, $labeltakeposmovement,
'',
'',
'',
'', 0, $inventorycode);
407 if (!$error && $res >= 0) {
413 if ($action ==
'creditnote' && $user->hasRight(
'facture',
'creer')) {
416 $creditnote =
new Facture($db);
417 $creditnote->socid = $invoice->socid;
419 $creditnote->module_source =
'takepos';
420 $creditnote->pos_source = isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'' ;
422 $creditnote->fk_facture_source = $placeid;
425 $creditnote->create($user);
427 foreach ($invoice->lines as $line) {
429 if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) {
434 if (!empty($invoice->situation_counter)) {
435 $source_fk_prev_id = $line->fk_prev_id;
436 $line->fk_prev_id = $line->id;
437 if (!empty($invoice->tab_previous_situation_invoice)) {
440 $tab_jumped_credit_notes = array();
441 $lineIndex = count($invoice->tab_previous_situation_invoice) - 1;
442 $searchPreviousInvoice =
true;
443 while ($searchPreviousInvoice) {
444 if ($invoice->tab_previous_situation_invoice[$lineIndex]->situation_cycle_ref || $lineIndex < 1) {
445 $searchPreviousInvoice =
false;
449 $tab_jumped_credit_notes[$lineIndex] = $invoice->tab_previous_situation_invoice[$lineIndex]->id;
455 $maxPrevSituationPercent = 0;
456 foreach ($invoice->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine) {
457 if ($prevLine->id == $source_fk_prev_id) {
458 $maxPrevSituationPercent = max($maxPrevSituationPercent, $prevLine->situation_percent);
461 $line->total_ht = $line->total_ht - $prevLine->total_ht;
462 $line->total_tva = $line->total_tva - $prevLine->total_tva;
463 $line->total_ttc = $line->total_ttc - $prevLine->total_ttc;
464 $line->total_localtax1 = $line->total_localtax1 - $prevLine->total_localtax1;
465 $line->total_localtax2 = $line->total_localtax2 - $prevLine->total_localtax2;
467 $line->multicurrency_subprice = $line->multicurrency_subprice - $prevLine->multicurrency_subprice;
468 $line->multicurrency_total_ht = $line->multicurrency_total_ht - $prevLine->multicurrency_total_ht;
469 $line->multicurrency_total_tva = $line->multicurrency_total_tva - $prevLine->multicurrency_total_tva;
470 $line->multicurrency_total_ttc = $line->multicurrency_total_ttc - $prevLine->multicurrency_total_ttc;
475 $line->situation_percent = $maxPrevSituationPercent - $line->situation_percent;
480 $maxPrevSituationPercent = 0;
481 foreach ($tab_jumped_credit_notes as $index => $creditnoteid) {
482 foreach ($invoice->tab_previous_situation_invoice[$index]->lines as $prevLine) {
483 if ($prevLine->fk_prev_id == $source_fk_prev_id) {
484 $maxPrevSituationPercent = $prevLine->situation_percent;
486 $line->total_ht -= $prevLine->total_ht;
487 $line->total_tva -= $prevLine->total_tva;
488 $line->total_ttc -= $prevLine->total_ttc;
489 $line->total_localtax1 -= $prevLine->total_localtax1;
490 $line->total_localtax2 -= $prevLine->total_localtax2;
492 $line->multicurrency_subprice -= $prevLine->multicurrency_subprice;
493 $line->multicurrency_total_ht -= $prevLine->multicurrency_total_ht;
494 $line->multicurrency_total_tva -= $prevLine->multicurrency_total_tva;
495 $line->multicurrency_total_ttc -= $prevLine->multicurrency_total_ttc;
501 $line->situation_percent += $maxPrevSituationPercent;
509 $line->fk_facture = $creditnote->id;
510 $line->fk_parent_line = $fk_parent_line;
512 $line->subprice = -$line->subprice;
514 $line->total_ht = -$line->total_ht;
515 $line->total_tva = -$line->total_tva;
516 $line->total_ttc = -$line->total_ttc;
517 $line->total_localtax1 = -$line->total_localtax1;
518 $line->total_localtax2 = -$line->total_localtax2;
520 $line->multicurrency_subprice = -$line->multicurrency_subprice;
521 $line->multicurrency_total_ht = -$line->multicurrency_total_ht;
522 $line->multicurrency_total_tva = -$line->multicurrency_total_tva;
523 $line->multicurrency_total_ttc = -$line->multicurrency_total_ttc;
525 $result = $line->insert(0, 1);
527 $creditnote->lines[] = $line;
530 if ($result > 0 && $line->product_type == 9) {
531 $fk_parent_line = $result;
534 $creditnote->update_price(1);
538 $constantforkey =
'CASHDESK_NO_DECREASE_STOCK'.(isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
541 if (isModEnabled(
'stock') && !isModEnabled(
'productbatch') && $allowstockchange) {
545 $conf->global->STOCK_CALCULATE_ON_BILL = 1;
547 $constantforkey =
'CASHDESK_ID_WAREHOUSE'.(isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
549 dol_syslog(
"Validate invoice with stock change into warehouse defined into constant ".$constantforkey.
" = ".
getDolGlobalString($constantforkey).
" or warehouseid= ".$warehouseid.
" if defined.");
554 $res = $creditnote->validate($user,
'',
getDolGlobalString($constantforkey), 0, $batch_rule);
561 $conf->global->STOCK_CALCULATE_ON_BILL = $savconst;
563 $res = $creditnote->validate($user);
567 if (!$error && $res >= 0) {
568 if (isModEnabled(
'stock') && isModEnabled(
'productbatch') && $allowstockchange) {
570 dol_syslog(
"Now we record the stock movement for each qualified line");
573 require_once DOL_DOCUMENT_ROOT .
"/product/stock/class/mouvementstock.class.php";
574 $constantforkey =
'CASHDESK_ID_WAREHOUSE'.$_SESSION[
"takeposterminal"];
577 $labeltakeposmovement =
'TakePOS - '.$langs->trans(
"CreditNote").
' '.$creditnote->ref;
579 foreach ($creditnote->lines as $line) {
581 $warehouseid = ($line->fk_warehouse ? $line->fk_warehouse :
getDolGlobalInt($constantforkey));
584 if ($line->batch !=
'' && $warehouseid > 0) {
589 $mouvP->setOrigin($creditnote->element, $creditnote->id);
591 $res = $mouvP->reception($user, $line->fk_product, $warehouseid, $line->qty, $line->price, $labeltakeposmovement,
'',
'', $line->batch,
'', 0, $inventorycode);
598 $mouvP->setOrigin($creditnote->element, $creditnote->id);
600 $res = $mouvP->reception($user, $line->fk_product, $warehouseid, $line->qty, $line->price, $labeltakeposmovement,
'',
'',
'',
'', 0, $inventorycode);
610 if (!$error && $res >= 0) {
613 $creditnote->id = $placeid;
618 if (($action ==
'history' || $action ==
'creditnote') && $user->hasRight(
'takepos',
'run')) {
619 if ($action ==
'creditnote' && $creditnote->id > 0) {
620 $placeid = $creditnote->id;
626 $invoice->fetch($placeid);
630 if (($action ==
"addline" || $action ==
"freezone") && $placeid == 0 && ($user->hasRight(
'takepos',
'run') || defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
633 $dolnowtzuserrel =
dol_now(
'tzuserrel');
637 $dateinvoice =
dol_mktime(0, 0, 0, (
int) $monthuser, (
int) $dayuser, (
int) $yearuser,
'tzserver');
639 include_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
640 $invoice->date = $dateinvoice;
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 set ref='(PROV-POS".$_SESSION[
"takeposterminal"].
"-".$place.
")' where rowid = ".((int) $placeid);
658 $resql = $db->query($sql);
672 if ($action ==
"addline" && ($user->hasRight(
'takepos',
'run') || defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
674 $prod->fetch($idproduct);
677 $customer->fetch($invoice->socid);
679 $datapriceofproduct = $prod->getSellPrice($mysoc, $customer, 0);
681 $qty = GETPOSTISSET(
'qty') ?
GETPOSTINT(
'qty') : 1;
682 $price = $datapriceofproduct[
'pu_ht'];
683 $price_ttc = $datapriceofproduct[
'pu_ttc'];
685 $price_base_type = empty($datapriceofproduct[
'price_base_type']) ?
'HT' : $datapriceofproduct[
'price_base_type'];
686 $tva_tx = $datapriceofproduct[
'tva_tx'];
687 $tva_npr = $datapriceofproduct[
'tva_npr'];
690 $localtax1_tx =
get_localtax($tva_tx, 1, $customer, $mysoc, $tva_npr);
691 $localtax2_tx =
get_localtax($tva_tx, 2, $customer, $mysoc, $tva_npr);
694 if (isModEnabled(
'productbatch') && isModEnabled(
'stock')) {
695 $batch =
GETPOST(
'batch',
'alpha');
697 if (!empty($batch)) {
698 $action =
"setbatch";
699 } elseif ($prod->status_batch > 0) {
704 $prod->load_stock(
'warehouseopen');
706 $constantforkey =
'CASHDESK_ID_WAREHOUSE'.$_SESSION[
"takeposterminal"];
710 foreach ($prod->stock_warehouse as $tmpwarehouseid => $tmpval) {
715 if (!empty($prod->stock_warehouse[$tmpwarehouseid]) && is_array($prod->stock_warehouse[$tmpwarehouseid]->detail_batch)) {
716 if (is_object($prod->stock_warehouse[$tmpwarehouseid]) && count($prod->stock_warehouse[$tmpwarehouseid]->detail_batch)) {
717 foreach ($prod->stock_warehouse[$tmpwarehouseid]->detail_batch as $dbatch) {
726 echo
"function addbatch(batch, warehouseid) {\n";
727 echo
"console.log('We add batch '+batch+' from warehouse id '+warehouseid);\n";
728 echo
'$("#poslines").load("'.DOL_URL_ROOT.
'/takepos/invoice.php?action=addline&batch="+encodeURI(batch)+"&warehouseid="+warehouseid+"&place='.$place.
'&idproduct='.$idproduct.
'&token='.
newToken().
'", function() {});'.
"\n";
733 echo
"<center>".$langs->trans(
"SearchIntoBatch").
": <b> $nbofsuggested </b></center><br><table>";
734 foreach ($prod->stock_warehouse as $tmpwarehouseid => $tmpval) {
739 if (!empty($prod->stock_warehouse[$tmpwarehouseid]) && is_array($prod->stock_warehouse[$tmpwarehouseid]->detail_batch)) {
740 foreach ($prod->stock_warehouse[$tmpwarehouseid]->detail_batch as $dbatch) {
741 $batchStock = + $dbatch->qty;
742 $quantityToBeDelivered = 1;
743 $deliverableQty = min($quantityToBeDelivered, $batchStock);
745 print
'<!-- subj='.$suggestednb.
'/'.$nbofsuggested.
' -->';
746 print
'<!-- Show details of lot/serial in warehouseid='.$tmpwarehouseid.
' -->';
747 print
'<td class="left">';
749 $detail .=
'<span class="opacitymedium">'.$langs->trans(
"LotSerial").
':</span> '.$dbatch->batch;
756 $detail .=
'</td><td>';
757 $detail .=
'<span class="opacitymedium">'.$langs->trans(
"Qty").
':</span> '.$dbatch->qty;
758 $detail .=
'</td><td>';
759 $detail .=
' <button class="marginleftonly" onclick="addbatch(\''.dol_escape_js($dbatch->batch).
'\',
'.$tmpwarehouseid.')
">'.$langs->trans("Select
")."</
button>
";
763 $quantityToBeDelivered -= $deliverableQty;
764 if ($quantityToBeDelivered < 0) {
765 $quantityToBeDelivered = 0;
774 print '</body></html>';
780 if (getDolGlobalString('TAKEPOS_SUPPLEMENTS')) {
781 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
782 $cat = new Categorie($db);
783 $categories = $cat->containing($idproduct, 'product');
784 $found = (array_search(getDolGlobalInt('TAKEPOS_SUPPLEMENTS_CATEGORY'), array_column($categories, 'id')));
785 if ($found !== false) { // If this product is a supplement
786 $sql = "SELECT fk_parent_line FROM
".MAIN_DB_PREFIX."facturedet where
rowid =
".((int) $selectedline);
787 $resql = $db->query($sql);
788 $row = $db->fetch_array($resql);
789 if ($row[0] == null) {
790 $parent_line = $selectedline;
792 $parent_line = $row[0]; //If the parent line is already a supplement, add the supplement to the main product
799 // Group if enabled. Skip group if line already sent to the printer
800 if (getDolGlobalString('TAKEPOS_GROUP_SAME_PRODUCT')) {
801 foreach ($invoice->lines as $line) {
802 if ($line->product_ref == $prod->ref) {
803 if ($line->special_code == 4) {
805 } // If this line is sended to printer create new line
806 // check if qty in stock
807 if (getDolGlobalString('TAKEPOS_QTY_IN_STOCK') && (($line->qty + $qty) > $prod->stock_reel)) {
808 $invoice->error = $langs->trans("ErrorStockIsNotEnough
");
809 dol_htmloutput_errors($invoice->error, $invoice->errors, 1);
813 $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);
815 dol_htmloutput_errors($invoice->error, $invoice->errors, 1);
817 $idoflineadded = $line->id;
823 if ($idoflineadded <= 0 && empty($err)) {
824 $invoice->fetch_thirdparty();
825 $array_options = array();
827 $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);
829 /* setup of margin calculation */
830 if (isset($conf->global->MARGIN_TYPE)) {
831 if (getDolGlobalString('MARGIN_TYPE') == 'pmp' && !empty($prod->pmp)) {
832 $line['fk_fournprice'] = null;
833 $line['pa_ht'] = $prod->pmp;
834 } elseif (getDolGlobalString('MARGIN_TYPE') == 'costprice' && !empty($prod->cost_price)) {
835 $line['fk_fournprice'] = null;
836 $line['pa_ht'] = $prod->cost_price;
838 // default is fournprice
839 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
840 $pf = new ProductFournisseur($db);
841 if ($pf->find_min_price_product_fournisseur($idproduct, $qty) > 0) {
842 $line['fk_fournprice'] = $pf->product_fourn_price_id;
843 $line['pa_ht'] = $pf->fourn_unitprice_with_discount;
844 if (getDolGlobalString('PRODUCT_CHARGES') && $pf->fourn_charges > 0) {
845 $line['pa_ht'] += $pf->fourn_charges / $pf->fourn_qty;
851 // complete line by hook
852 $parameters = array('prod' => $prod, 'line' => $line);
853 $reshook = $hookmanager->executeHooks('completeTakePosAddLine', $parameters, $invoice, $action); // Note that $action and $line may have been modified by some hooks
855 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
859 if (empty($reshook)) {
860 if (!empty($hookmanager->resArray)) {
861 $line = $hookmanager->resArray;
864 // check if qty in stock
865 if (getDolGlobalString('TAKEPOS_QTY_IN_STOCK') && $qty > $prod->stock_reel) {
866 $invoice->error = $langs->trans("ErrorStockIsNotEnough
");
867 dol_htmloutput_errors($invoice->error, $invoice->errors, 1);
872 $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);
876 if (getDolGlobalString('TAKEPOS_CUSTOMER_DISPLAY')) {
877 $CUSTOMER_DISPLAY_line1 = $prod->label;
878 $CUSTOMER_DISPLAY_line2 = price($price_ttc);
882 $invoice->fetch($placeid);
885 // If we add a line by submitting freezone form (invoice exists here because it was created juste before if it didn't exists)
886 if ($action == "freezone
" && $user->hasRight('takepos', 'run')) {
887 $customer = new Societe($db);
888 $customer->fetch($invoice->socid);
890 $tva_tx = GETPOST('tva_tx', 'alpha');
892 if (!preg_match('/\((.*)\)/', $tva_tx)) {
893 $tva_tx = price2num($tva_tx);
896 $tva_tx = get_default_tva($mysoc, $customer);
900 $localtax1_tx = get_localtax($tva_tx, 1, $customer, $mysoc, $tva_npr);
901 $localtax2_tx = get_localtax($tva_tx, 2, $customer, $mysoc, $tva_npr);
903 $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);
905 dol_htmloutput_errors($invoice->error, $invoice->errors, 1);
907 $invoice->fetch($placeid);
910 if ($action == "addnote
" && ($user->hasRight('takepos', 'run') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
911 $desc = GETPOST('addnote', 'alpha');
913 $invoice->update_note($desc, '_public');
915 foreach ($invoice->lines as $line) {
916 if ($line->id == $idline) {
917 $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);
921 $invoice->fetch($placeid);
924 if ($action == "deleteline
" && ($user->hasRight('takepos', 'run') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
926 $permissiontoupdateline = ($user->hasRight('takepos', 'editlines') && ($user->hasRight('takepos', 'editorderedlines') || $line->special_code != "4
"));
927 if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
928 if ($invoice->status == $invoice::STATUS_DRAFT && $invoice->pos_source && $invoice->module_source == 'takepos') {
929 $permissiontoupdateline = true;
930 // TODO Add also a test on $_SESSION('publicobjectid'] defined at creation of object
931 // TODO Check also that invoice->ref is (PROV-POS1-2) with 1 = terminal and 2, the invoice ID
935 if ($idline > 0 && $placeid > 0) { // If invoice exists and line selected. To avoid errors if deleted from another device or no line selected.
936 $invoice->deleteLine($idline);
937 $invoice->fetch($placeid);
938 } elseif ($placeid > 0) { // If invoice exists but no line selected, proceed to delete last line.
939 $sql = "SELECT
rowid FROM
".MAIN_DB_PREFIX."facturedet where fk_facture =
".((int) $placeid)." ORDER BY
rowid DESC
";
940 $resql = $db->query($sql);
941 $row = $db->fetch_array($resql);
942 $deletelineid = $row[0];
943 $invoice->deleteLine($deletelineid);
944 $invoice->fetch($placeid);
947 if (count($invoice->lines) == 0) {
948 $invoice->delete($user);
950 if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
951 header("Location:
".DOL_URL_ROOT."/takepos/public/auto_order.php
");
953 header("Location:
".DOL_URL_ROOT."/takepos/invoice.php
");
959 // Action to delete or discard an invoice
960 if ($action == "delete
" && ($user->hasRight('takepos', 'run') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
961 // $placeid is the invoice id (it differs from place) and is defined if the place is set and the ref of invoice is '(PROV-POS'.$_SESSION["takeposterminal
"].'-'.$place.')', so the fetch at beginning of page works.
963 $result = $invoice->fetch($placeid);
965 if ($result > 0 && $invoice->statut == Facture::STATUS_DRAFT) {
968 // We delete the lines
970 foreach ($invoice->lines as $line) {
971 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
972 $tmpres = $invoice->deleteLine($line->id);
979 $sql = "UPDATE
".MAIN_DB_PREFIX."facture
";
980 $varforconst = 'CASHDESK_ID_THIRDPARTY'.$_SESSION["takeposterminal
"];
981 $sql .= " SET fk_soc =
".((int) getDolGlobalString($varforconst)).",
";
982 $sql .= " datec =
'".$db->idate(dol_now())."'";
983 $sql .= " WHERE entity IN (
".getEntity('invoice').")
";
984 $sql .= " AND
ref =
'(PROV-POS".$db->escape($_SESSION["takeposterminal"]."-".$place).")'";
985 $resql1 = $db->query($sql);
987 if ($resdeletelines && $resql1) {
993 $invoice->fetch($placeid);
998 if ($action == "updateqty
") { // Test on permission is done later
999 foreach ($invoice->lines as $line) {
1000 if ($line->id == $idline) {
1001 $permissiontoupdateline = ($user->hasRight('takepos', 'editlines') && ($user->hasRight('takepos', 'editorderedlines') || $line->special_code != "4
"));
1002 if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1003 if ($invoice->status == $invoice::STATUS_DRAFT && $invoice->pos_source && $invoice->module_source == 'takepos') {
1004 $permissiontoupdateline = true;
1005 // TODO Add also a test on $_SESSION('publicobjectid'] defined at creation of object
1006 // TODO Check also that invoice->ref is (PROV-POS1-2) with 1 = terminal and 2, the invoice ID
1009 if (!$permissiontoupdateline) {
1010 dol_htmloutput_errors($langs->trans("NotEnoughPermissions
", "TakePos
").' - No permission to updateqty', null, 1);
1012 $vatratecode = $line->tva_tx;
1013 if ($line->vat_src_code) {
1014 $vatratecode .= ' ('.$line->vat_src_code.')';
1017 $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);
1022 $invoice->fetch($placeid);
1025 if ($action == "updateprice
") { // Test on permission is done later
1026 $customer = new Societe($db);
1027 $customer->fetch($invoice->socid);
1029 foreach ($invoice->lines as $line) {
1030 if ($line->id == $idline) {
1031 $prod = new Product($db);
1032 $prod->fetch($line->fk_product);
1033 $datapriceofproduct = $prod->getSellPrice($mysoc, $customer, 0);
1034 $price_min = $datapriceofproduct['price_min'];
1035 $usercanproductignorepricemin = ((getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !$user->hasRight('produit', 'ignore_price_min_advance')) || !getDolGlobalString('MAIN_USE_ADVANCED_PERMS'));
1036 $pu_ht = price2num($number / (1 + ($line->tva_tx / 100)), 'MU');
1038 if ($usercanproductignorepricemin && (!empty($price_min) && (price2num($pu_ht) * (1 - price2num($line->remise_percent) / 100) < price2num($price_min)))) {
1039 $langs->load("products
");
1040 dol_htmloutput_errors($langs->trans("CantBeLessThanMinPrice
", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, -1, $conf->currency)));
1041 //echo $langs->trans("CantBeLessThanMinPrice
");
1043 $permissiontoupdateline = ($user->hasRight('takepos', 'editlines') && ($user->hasRight('takepos', 'editorderedlines') || $line->special_code != "4
"));
1044 if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1045 if ($invoice->status == $invoice::STATUS_DRAFT && $invoice->pos_source && $invoice->module_source == 'takepos') {
1046 $permissiontoupdateline = true;
1047 // TODO Add also a test on $_SESSION('publicobjectid'] defined at creation of object
1048 // TODO Check also that invoice->ref is (PROV-POS1-2) with 1 = terminal and 2, the invoice ID
1052 $vatratecode = $line->tva_tx;
1053 if ($line->vat_src_code) {
1054 $vatratecode .= ' ('.$line->vat_src_code.')';
1057 if (!$permissiontoupdateline) {
1058 dol_htmloutput_errors($langs->trans("NotEnoughPermissions
", "TakePos
").' - No permission to updateprice', null, 1);
1059 } elseif (getDolGlobalInt('TAKEPOS_CHANGE_PRICE_HT') == 1) {
1060 $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);
1062 $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);
1069 $invoice->fetch($placeid);
1072 if ($action == "updatereduction
") { // Test on permission is done later
1073 $customer = new Societe($db);
1074 $customer->fetch($invoice->socid);
1076 foreach ($invoice->lines as $line) {
1077 if ($line->id == $idline) {
1078 dol_syslog("updatereduction Process line
".$line->id.' to apply discount of '.$number.'%');
1080 $prod = new Product($db);
1081 $prod->fetch($line->fk_product);
1083 $datapriceofproduct = $prod->getSellPrice($mysoc, $customer, 0);
1084 $price_min = $datapriceofproduct['price_min'];
1085 $usercanproductignorepricemin = ((getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !$user->hasRight('produit', 'ignore_price_min_advance')) || !getDolGlobalString('MAIN_USE_ADVANCED_PERMS'));
1087 $pu_ht = price2num($line->subprice / (1 + ($line->tva_tx / 100)), 'MU');
1090 if ($usercanproductignorepricemin && (!empty($price_min) && (price2num($line->subprice) * (1 - price2num($number) / 100) < price2num($price_min)))) {
1091 $langs->load("products
");
1092 dol_htmloutput_errors($langs->trans("CantBeLessThanMinPrice
", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, -1, $conf->currency)));
1094 $permissiontoupdateline = ($user->hasRight('takepos', 'editlines') && ($user->hasRight('takepos', 'editorderedlines') || $line->special_code != "4
"));
1095 if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1096 if ($invoice->status == $invoice::STATUS_DRAFT && $invoice->pos_source && $invoice->module_source == 'takepos') {
1097 $permissiontoupdateline = true;
1098 // TODO Add also a test on $_SESSION('publicobjectid'] defined at creation of object
1099 // TODO Check also that invoice->ref is (PROV-POS1-2) with 1 = terminal and 2, the invoice ID
1102 if (!$permissiontoupdateline) {
1103 dol_htmloutput_errors($langs->trans("NotEnoughPermissions
", "TakePos
"), null, 1);
1105 $vatratecode = $line->tva_tx;
1106 if ($line->vat_src_code) {
1107 $vatratecode .= ' ('.$line->vat_src_code.')';
1109 $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);
1116 $invoice->fetch($placeid);
1117 } elseif ($action == 'update_reduction_global' && $user->hasRight('takepos', 'editlines')) {
1118 foreach ($invoice->lines as $line) {
1119 $vatratecode = $line->tva_tx;
1120 if ($line->vat_src_code) {
1121 $vatratecode .= ' ('.$line->vat_src_code.')';
1123 $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);
1126 $invoice->fetch($placeid);
1129 if ($action == "setbatch
" && ($user->hasRight('takepos', 'run') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
1130 $constantforkey = 'CASHDESK_ID_WAREHOUSE'.$_SESSION["takeposterminal
"];
1131 $warehouseid = (GETPOSTINT('warehouseid') > 0 ? GETPOSTINT('warehouseid') : getDolGlobalInt($constantforkey)); // Get the warehouse id from GETPOSTINT('warehouseid'), otherwise use default setup.
1132 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet SET batch =
'".$db->escape($batch)."', fk_warehouse =
".((int) $warehouseid);
1133 $sql .= " WHERE
rowid=
".((int) $idoflineadded);
1137 if ($action == "order
" && $placeid != 0 && ($user->hasRight('takepos', 'run') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
1138 include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
1139 if ((isModEnabled('receiptprinter') && getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term) > 0) || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter
" || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector
") {
1140 require_once DOL_DOCUMENT_ROOT.'/core/class/dolreceiptprinter.class.php';
1141 $printer = new dolReceiptPrinter($db);
1144 $sql = "SELECT label FROM
".MAIN_DB_PREFIX."takepos_floor_tables where
rowid=
".((int) $place);
1145 $resql = $db->query($sql);
1146 $row = $db->fetch_object($resql);
1147 $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>';
1148 $footerorder = '</tbody></table>'.dol_print_date(dol_now(), 'dayhour').'<br></html>';
1149 $order_receipt_printer1 = "";
1150 $order_receipt_printer2 = "";
1151 $order_receipt_printer3 = "";
1152 $catsprinter1 = explode(';', getDolGlobalString('TAKEPOS_PRINTED_CATEGORIES_1'));
1153 $catsprinter2 = explode(';', getDolGlobalString('TAKEPOS_PRINTED_CATEGORIES_2'));
1154 $catsprinter3 = explode(';', getDolGlobalString('TAKEPOS_PRINTED_CATEGORIES_3'));
1156 foreach ($invoice->lines as $line) {
1157 if ($line->special_code == "4
") {
1160 $c = new Categorie($db);
1161 $existing = $c->containing($line->fk_product, Categorie::TYPE_PRODUCT, 'id');
1162 $result = array_intersect($catsprinter1, $existing);
1163 $count = count($result);
1164 if (!$line->fk_product) {
1165 $count++; // Print Free-text item (Unassigned printer) to Printer 1
1169 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet set special_code=
'1' where
rowid=
".$line->id; //Set to print on printer 1
1171 $order_receipt_printer1 .= '<tr><td class="left
">';
1172 if ($line->fk_product) {
1173 $order_receipt_printer1 .= $line->product_label;
1175 $order_receipt_printer1 .= $line->description;
1177 $order_receipt_printer1 .= '</td><td class="right
">'.$line->qty;
1178 if (!empty($line->array_options['options_order_notes'])) {
1179 $order_receipt_printer1 .= "<br>(
".$line->array_options['options_order_notes'].")
";
1181 $order_receipt_printer1 .= '</td></tr>';
1184 if (((isModEnabled('receiptprinter') && getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term) > 0) || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter
" || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector
") && $linestoprint > 0) {
1185 $invoice->fetch($placeid); //Reload object before send to printer
1186 $printer->orderprinter = 1;
1188 echo "var orderprinter1esc=
'";
1189 $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
1192 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet
set special_code=
'4' where special_code=
'1' and fk_facture=
".$invoice->id; // Set as printed
1194 $invoice->fetch($placeid); //Reload object after set lines as printed
1197 foreach ($invoice->lines as $line) {
1198 if ($line->special_code == "4
") {
1201 $c = new Categorie($db);
1202 $existing = $c->containing($line->fk_product, Categorie::TYPE_PRODUCT, 'id');
1203 $result = array_intersect($catsprinter2, $existing);
1204 $count = count($result);
1207 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet
set special_code=
'2' where
rowid=
".$line->id; //Set to print on printer 2
1209 $order_receipt_printer2 .= '<tr>'.$line->product_label.'<td class="right
">'.$line->qty;
1210 if (!empty($line->array_options['options_order_notes'])) {
1211 $order_receipt_printer2 .= "<br>(
".$line->array_options['options_order_notes'].")
";
1213 $order_receipt_printer2 .= '</td></tr>';
1216 if (((isModEnabled('receiptprinter') && getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term) > 0) || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter
" || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector
") && $linestoprint > 0) {
1217 $invoice->fetch($placeid); //Reload object before send to printer
1218 $printer->orderprinter = 2;
1220 echo "var orderprinter2esc=
'";
1221 $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
1224 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet
set special_code=
'4' where special_code=
'2' and fk_facture=
".$invoice->id; // Set as printed
1226 $invoice->fetch($placeid); //Reload object after set lines as printed
1229 foreach ($invoice->lines as $line) {
1230 if ($line->special_code == "4
") {
1233 $c = new Categorie($db);
1234 $existing = $c->containing($line->fk_product, Categorie::TYPE_PRODUCT, 'id');
1235 $result = array_intersect($catsprinter3, $existing);
1236 $count = count($result);
1239 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet
set special_code=
'3' where
rowid=
".$line->id; //Set to print on printer 3
1241 $order_receipt_printer3 .= '<tr>'.$line->product_label.'<td class="right
">'.$line->qty;
1242 if (!empty($line->array_options['options_order_notes'])) {
1243 $order_receipt_printer3 .= "<br>(
".$line->array_options['options_order_notes'].")
";
1245 $order_receipt_printer3 .= '</td></tr>';
1248 if (((isModEnabled('receiptprinter') && getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term) > 0) || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter
" || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector
") && $linestoprint > 0) {
1249 $invoice->fetch($placeid); //Reload object before send to printer
1250 $printer->orderprinter = 3;
1252 echo "var orderprinter3esc=
'";
1253 $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
1256 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet
set special_code=
'4' where special_code=
'3' and fk_facture=
".$invoice->id; // Set as printed
1258 $invoice->fetch($placeid); //Reload object after set lines as printed
1261 $sectionwithinvoicelink = '';
1262 if (($action == "valid
" || $action == "history
" || $action == 'creditnote') && $user->hasRight('takepos', 'run')) {
1263 $sectionwithinvoicelink .= '<!-- Section with invoice link -->'."\n
";
1264 $sectionwithinvoicelink .= '<span style="font-size:120%;
" class="center
">';
1265 $sectionwithinvoicelink .= $invoice->getNomUrl(1, '', 0, 0, '', 0, 0, -1, '_backoffice')." -
";
1266 $remaintopay = $invoice->getRemainToPay();
1267 if ($remaintopay > 0) {
1268 $sectionwithinvoicelink .= $langs->trans('RemainToPay').': <span class="amountremaintopay
" style="font-size: unset
">'.price($remaintopay, 1, $langs, 1, -1, -1, $conf->currency).'</span>';
1270 if ($invoice->paye) {
1271 $sectionwithinvoicelink .= '<span class="amountpaymentcomplete
" style="font-size: unset
">'.$langs->trans("Paid
").'</span>';
1273 $sectionwithinvoicelink .= $langs->trans('BillShortStatusValidated');
1277 $sectionwithinvoicelink .= '</span><br>';
1278 if (getDolGlobalInt('TAKEPOS_PRINT_INVOICE_DOC_INSTEAD_OF_RECEIPT')) {
1279 $sectionwithinvoicelink .= ' <a target="_blank
" class="button" href="' . DOL_URL_ROOT . '/document.php?token=
' . newToken() . '&modulepart=facture&file=
' . $invoice->ref . '/
' . $invoice->ref . '.pdf
">Invoice</a>';
1280 } elseif (getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector
") {
1281 if (getDolGlobalString('TAKEPOS_PRINT_SERVER') && filter_var($conf->global->TAKEPOS_PRINT_SERVER, FILTER_VALIDATE_URL) == true) {
1282 $sectionwithinvoicelink .= ' <button id="buttonprint
" type="button" onclick="TakeposConnector(
'.$placeid.')
">'.$langs->trans('PrintTicket').'</button>';
1284 $sectionwithinvoicelink .= ' <button id="buttonprint
" type="button" onclick="TakeposPrinting(
'.$placeid.')
">'.$langs->trans('PrintTicket').'</button>';
1286 } elseif ((isModEnabled('receiptprinter') && getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term) > 0) || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter
") {
1287 $sectionwithinvoicelink .= ' <button id="buttonprint
" type="button" onclick="DolibarrTakeposPrinting(
'.$placeid.')
">'.$langs->trans('PrintTicket').'</button>';
1289 $sectionwithinvoicelink .= ' <button id="buttonprint
" type="button" onclick="Print(
'.$placeid.')
">'.$langs->trans('PrintTicket').'</button>';
1290 if (getDolGlobalString('TAKEPOS_PRINT_WITHOUT_DETAILS')) {
1291 $sectionwithinvoicelink .= ' <button id="buttonprint
" type="button" onclick="PrintBox(
'.$placeid.', \
'without_details\')">'.$langs->trans(
'PrintWithoutDetails').
'</button>';
1294 $sectionwithinvoicelink .=
' <button id="buttonprint" type="button" onclick="Print('.$placeid.
', 1)">'.$langs->trans(
'GiftReceipt').
'</button>';
1298 $sectionwithinvoicelink .=
' <button id="buttonsend" type="button" onclick="SendTicket('.$placeid.
')">'.$langs->trans(
'SendTicket').
'</button>';
1301 if ($remaintopay <= 0 &&
getDolGlobalString(
'TAKEPOS_AUTO_PRINT_TICKETS') && $action !=
"history") {
1302 $sectionwithinvoicelink .=
'<script type="text/javascript">$("#buttonprint").click();</script>';
1312$form =
new Form($db);
1315if ((
getDolGlobalString(
'TAKEPOS_PHONE_BASIC_LAYOUT') == 1 && $conf->browser->layout ==
'phone') || defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1316 $title =
'TakePOS - Dolibarr '.DOL_VERSION;
1320 $head =
'<meta name="apple-mobile-web-app-title" content="TakePOS"/>
1321 <meta name="apple-mobile-web-app-capable" content="yes">
1322 <meta name="mobile-web-app-capable" content="yes">
1323 <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>';
1324 $arrayofcss = array(
1325 '/takepos/css/pos.css.php',
1327 $arrayofjs = array(
'/takepos/js/jquery.colorbox-min.js');
1330 top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss);
1332 print
'<body>'.
"\n";
1339<script
type=
"text/javascript">
1342<?php
if ($action ==
"valid") {
1343 echo
"var place=0;";
1345var placeid=<?php echo($placeid > 0 ? $placeid : 0); ?>;
1346$(document).ready(
function() {
1347 var idoflineadded = <?php echo(empty($idoflineadded) ? 0 : $idoflineadded); ?>;
1349 $(
'.posinvoiceline').click(
function(){
1350 console.log(
"Click done on "+this.
id);
1351 $(
'.posinvoiceline').removeClass(
"selected");
1352 $(
this).addClass(
"selected");
1356 if (selectedline == this.
id) {
1359 selectedline = this.id;
1361 selectedtext=$(
'#'+selectedline).find(
"td:first").html();
1363 if (defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1364 print
'$("#phonediv1").load("'.DOL_URL_ROOT.
'/takepos/public/auto_order.php?action=editline&token='.
newToken().
'&placeid="+placeid+"&selectedline="+selectedline, function() {
1371 if (idoflineadded > 0)
1373 console.log(
"Auto select "+idoflineadded);
1374 $(
'.posinvoiceline#'+idoflineadded).click();
1378if ($action ==
"order" && !empty($order_receipt_printer1)) {
1379 if (filter_var($conf->global->TAKEPOS_PRINT_SERVER, FILTER_VALIDATE_URL) ==
true) {
1383 url:
'<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>/printer/index.php',
1384 data:
'invoice='+orderprinter1esc
1391 url:
'http://<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>:8111/print',
1393 print $headerorder.$order_receipt_printer1.$footerorder; ?>'
1399if ($action ==
"order" && !empty($order_receipt_printer2)) {
1400 if (filter_var($conf->global->TAKEPOS_PRINT_SERVER, FILTER_VALIDATE_URL) ==
true) {
1404 url:
'<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>/printer/index.php?printer=2',
1405 data:
'invoice='+orderprinter2esc
1412 url:
'http://<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>:8111/print2',
1414 print $headerorder.$order_receipt_printer2.$footerorder; ?>'
1420if ($action ==
"order" && !empty($order_receipt_printer3)) {
1421 if (filter_var($conf->global->TAKEPOS_PRINT_SERVER, FILTER_VALIDATE_URL) ==
true) {
1425 url:
'<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>/printer/index.php?printer=3',
1426 data:
'invoice='+orderprinter3esc
1433if ($action ==
"search" || $action ==
"valid") {
1435 parent.ClearSearch(
true);
1440if ($action ==
"temp" && !empty($ticket_printer1)) {
1444 url:
'http://<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>:8111/print',
1446 print $header_soc.$header_ticket.$body_ticket.$ticket_printer1.$ticket_total.$footer_ticket; ?>'
1451if ($action ==
"search") {
1453 $(
'#search').focus();
1461function SendTicket(
id)
1463 console.log(
"Open box to select the Print/Send form");
1464 $.colorbox({href:
"send.php?facid="+id, width:
"70%", height:
"30%", transition:
"none", iframe:
"true", title:
'<?php echo dol_escape_js($langs->trans("SendTicket")); ?>'});
1468function PrintBox(
id, action) {
1469 console.log(
"Open box before printing");
1470 $.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
"); ?>"});
1474function Print(
id, gift){
1475 console.log(
"Call Print() to generate the receipt.");
1476 $.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")); ?>'});
1480function TakeposPrinting(
id){
1482 console.log(
"TakeposPrinting" +
id);
1483 $.get(
"receipt.php?facid="+
id,
function(data,
status) {
1484 receipt=data.replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g,
'');
1487 url:
'http://<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER
'); ?>:8111/print',
1494function TakeposConnector(
id){
1495 console.log(
"TakeposConnector" +
id);
1496 $.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) {
1499 url:
'<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER
'); ?>/printer/index.php',
1500 data:
'invoice='+data
1508function DolibarrTakeposPrinting(
id) {
1509 console.log(
"DolibarrTakeposPrinting Printing invoice ticket " +
id);
1512 data: { token:
'<?php echo currentToken(); ?>' },
1513 url:
"<?php print DOL_URL_ROOT.'/takepos/ajax/ajax.php?action=printinvoiceticket&token='.newToken().'&term='.urlencode(isset($_SESSION["takeposterminal
"]) ? $_SESSION["takeposterminal
"] : '').'&id='; ?>" + id,
1520function CreditNote() {
1521 $(
"#poslines").load(
"<?php print DOL_URL_ROOT; ?>/takepos/invoice.php?action=creditnote&token=<?php echo newToken() ?>&invoiceid="+placeid,
function() { });
1527 $(
"#poslines").load(
"<?php print DOL_URL_ROOT; ?>/takepos/invoice.php?action=addnote&token=<?php echo newToken() ?>&invoiceid="+placeid+
"&idline="+selectedline, {
"addnote": $(
"#textinput").val() });
1532$( document ).ready(
function() {
1533 console.log(
"Set customer info and sales in header placeid=<?php echo $placeid; ?> status=<?php echo $invoice->statut; ?>");
1536 $s = $langs->trans(
"Customer");
1537 if ($invoice->id > 0 && ($invoice->socid !=
getDolGlobalString($constforcompanyid))) {
1540 $contactids = $invoice->getIdContact(
'external',
'BILLING');
1541 $contactid = $contactids[0];
1542 if ($contactid > 0) {
1544 $contact->fetch($contactid);
1545 $s .=
" - " . $contact->getFullName($langs);
1551 $(
"#customerandsales").html(
'');
1552 $(
"#shoppingcart").html(
'');
1555 $(
"#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>');
1557 $(
"#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>');
1561 $sql =
"SELECT rowid, datec, ref FROM ".MAIN_DB_PREFIX.
"facture";
1562 $sql .=
" WHERE entity IN (".getEntity(
'invoice').
")";
1565 $sql .=
" AND ref LIKE '(PROV-POS".$db->escape(isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'').
"-0%'";
1568 $sql .=
" AND pos_source = '".$db->escape($_SESSION[
"takeposterminal"]).
"'";
1569 $sql .=
" AND module_source = 'takepos'";
1572 $sql .= $db->order(
'datec',
'ASC');
1573 $resql = $db->query($sql);
1576 while ($obj = $db->fetch_object($resql)) {
1577 echo
'$("#shoppingcart").append(\'';
1578 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=\\\'';
1579 $num_sale = str_replace(
")",
"", str_replace(
"(PROV-POS".$_SESSION[
"takeposterminal"].
"-",
"", $obj->ref));
1581 if (str_replace(
"-",
"", $num_sale) > $max_sale) {
1582 $max_sale = str_replace(
"-",
"", $num_sale);
1584 echo
'\\\'; invoiceid=\\\'';
1586 echo
'\\\'; Refresh();">';
1587 if ($placeid == $obj->rowid) {
1588 echo
'<span class="basketselected">';
1590 echo
'<span class="basketnotselected">';
1592 echo
'<span class="fa fa-shopping-cart paddingright"></span>'.dol_print_date($db->jdate($obj->datec),
'%H:%M',
'tzuser');
1596 echo
'$("#shoppingcart").append(\'<a onclick="place=\\\'0-';
1598 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>\');';
1606 $constantforkey =
'CASHDESK_NO_DECREASE_STOCK'. (isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
1607 if (isModEnabled(
'stock')) {
1609 $constantforkey =
'CASHDESK_ID_WAREHOUSE'. (isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
1611 if ($idwarehouse > 0) {
1612 $s =
'<span class="small">';
1614 $warehouse->fetch($idwarehouse);
1615 $s .=
'<span class="hideonsmartphone">'.$langs->trans(
"Warehouse").
'<br></span>'.$warehouse->ref;
1617 $s .=
' ('.$langs->trans(
"Closed").
')';
1620 print
"$('#infowarehouse').html('".dol_escape_js($s).
"');";
1621 print
'$("#infowarehouse").css("display", "inline-block");';
1623 $s =
'<span class="small hideonsmartphone">';
1624 $s .= $langs->trans(
"StockChangeDisabled").
'<br>'.$langs->trans(
"NoWarehouseDefinedForTerminal");
1626 print
"$('#infowarehouse').html('".dol_escape_js($s).
"');";
1627 if (!empty($conf->dol_optimize_smallscreen)) {
1628 print
'$("#infowarehouse").css("display", "none");';
1632 $s =
'<span class="small hideonsmartphone">'.$langs->trans(
"StockChangeDisabled").
'</span>';
1633 print
"$('#infowarehouse').html('".dol_escape_js($s).
"');";
1634 if (!empty($conf->dol_optimize_smallscreen)) {
1635 print
'$("#infowarehouse").css("display", "none");';
1643 if (isModEnabled(
'member') && $invoice->socid > 0 && $invoice->socid !=
getDolGlobalInt($constforcompanyid)) {
1644 $s =
'<span class="small">';
1645 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
1646 $langs->load(
"members");
1647 $s .= $langs->trans(
"Member").
': ';
1649 $result = $adh->fetch(
'',
'', $invoice->socid);
1651 $adh->ref = $adh->getFullName($langs);
1655 $s .= $adh->getFullName($langs);
1656 $s .=
' - '.$adh->type;
1657 if ($adh->datefin) {
1658 $s .=
'<br>'.$langs->trans(
"SubscriptionEndDate").
': '.
dol_print_date($adh->datefin,
'day');
1659 if ($adh->hasDelay()) {
1660 $s .=
" ".img_warning($langs->trans(
"Late"));
1663 $s .=
'<br>'.$langs->trans(
"SubscriptionNotReceived");
1664 if ($adh->statut > 0) {
1665 $s .=
" ".img_warning($langs->trans(
"Late"));
1672 $s .=
'<br>'.$langs->trans(
"ThirdpartyNotLinkedToMember");
1677 $(
"#moreinfo").html(
'<?php print dol_escape_js($s); ?>');
1684 echo
"function CustomerDisplay(){";
1685 echo
"var line1='".$CUSTOMER_DISPLAY_line1.
"'.substring(0,20);";
1686 echo
"line1=line1.padEnd(20);";
1687 echo
"var line2='".$CUSTOMER_DISPLAY_line2.
"'.substring(0,20);";
1688 echo
"line2=line2.padEnd(20);";
1691 data: { text: line1+line2 },
1692 url: '".getDolGlobalString(
'TAKEPOS_PRINT_SERVER').
"/display/index.php',
1703if (!empty($conf->use_javascript_ajax)) {
1704 print
"\n".
'<!-- Includes JS Footer of Dolibarr -->'.
"\n";
1705 print
'<script src="'.DOL_URL_ROOT.
'/core/js/lib_foot.js.php?lang='.$langs->defaultlang.
'"></script>'.
"\n";