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);
201if (empty($reshook)) {
203 if ($action ==
'valid' && $user->hasRight(
'facture',
'creer')) {
211 $bankaccount =
getDolGlobalInt(
'CASHDESK_ID_BANKACCOUNT_CASH'.$_SESSION[
"takeposterminal"]);
212 } elseif ($pay ==
"CHQ") {
213 $bankaccount =
getDolGlobalInt(
'CASHDESK_ID_BANKACCOUNT_CHEQUE'.$_SESSION[
"takeposterminal"]);
215 $accountname =
"CASHDESK_ID_BANKACCOUNT_".$pay.$_SESSION[
"takeposterminal"];
220 if ($bankaccount <= 0 && $pay !=
"delayed" && isModEnabled(
"bank")) {
221 $errormsg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"BankAccount"));
229 $invoice->fetch($placeid);
233 if ($invoice->total_ttc < 0) {
234 $invoice->type = $invoice::TYPE_CREDIT_NOTE;
236 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"facture";
237 $sql .=
" WHERE entity IN (".getEntity(
'invoice').
")";
238 $sql .=
" AND fk_soc = ".((int) $invoice->socid);
239 $sql .=
" AND type <> ".Facture::TYPE_CREDIT_NOTE;
240 $sql .=
" AND fk_statut >= ".$invoice::STATUS_VALIDATED;
241 $sql .=
" ORDER BY rowid DESC";
243 $resql = $db->query($sql);
245 $obj = $db->fetch_object($resql);
246 $fk_source = $obj->rowid;
247 if ($fk_source ==
null) {
248 fail($langs->transnoentitiesnoconv(
"NoPreviousBillForCustomer"));
251 fail($langs->transnoentitiesnoconv(
"NoPreviousBillForCustomer"));
253 $invoice->fk_facture_source = $fk_source;
254 $invoice->update($user);
257 $constantforkey =
'CASHDESK_NO_DECREASE_STOCK'.(isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
264 if ($invoice->getRemainToPay() > 0) {
270 } elseif (count($invoice->lines) == 0) {
274 } elseif (isModEnabled(
'stock') && !isModEnabled(
'productbatch') && $allowstockchange) {
279 $conf->global->STOCK_CALCULATE_ON_BILL = 1;
281 $constantforkey =
'CASHDESK_ID_WAREHOUSE'.$_SESSION[
"takeposterminal"];
282 dol_syslog(
"Validate invoice with stock change. Warehouse defined into constant ".$constantforkey.
" = ".
getDolGlobalString($constantforkey));
287 $res = $invoice->validate($user,
'',
getDolGlobalInt($constantforkey), 0, $batch_rule);
290 $conf->global->STOCK_CALCULATE_ON_BILL = $savconst;
293 $res = $invoice->validate($user);
296 $langs->load(
"admin");
297 dol_htmloutput_errors($invoice->error ==
'NotConfigured' ? $langs->trans(
"NotConfigured").
' (TakePos numbering module)' : $invoice->error, $invoice->errors, 1);
302 if (!$error && $res >= 0) {
303 $remaintopay = $invoice->getRemainToPay();
304 if ($remaintopay > 0) {
306 $payment->datepaye = $now;
307 $payment->fk_account = $bankaccount;
308 $payment->amounts[$invoice->id] = $amountofpayment;
315 if ($amountofpayment <= 0 || $amountofpayment > $remaintopay) {
316 $payment->amounts[$invoice->id] = $remaintopay;
319 $payment->paiementid = $paiementid;
320 $payment->num_payment = $invoice->ref;
322 if ($pay !=
"delayed") {
323 $result = $payment->create($user);
328 $res = $payment->addPaymentToBank($user,
'payment',
'(CustomerInvoicePayment)', $bankaccount,
'',
'');
334 $remaintopay = $invoice->getRemainToPay();
340 if ($remaintopay == 0) {
341 dol_syslog(
"Invoice is paid, so we set it to status Paid");
342 $result = $invoice->setPaid($user);
347 $invoice->setPaymentMethods($paiementid);
349 dol_syslog(
"Invoice is not paid, remain to pay = ".$remaintopay);
356 if (!$error && $res >= 0) {
357 if (isModEnabled(
'stock') && isModEnabled(
'productbatch') && $allowstockchange) {
359 dol_syslog(
"Now we record the stock movement for each qualified line");
362 require_once DOL_DOCUMENT_ROOT .
"/product/stock/class/mouvementstock.class.php";
363 $constantforkey =
'CASHDESK_ID_WAREHOUSE'.$_SESSION[
"takeposterminal"];
366 $labeltakeposmovement =
'TakePOS - '.$langs->trans(
"Invoice").
' '.$invoice->ref;
368 foreach ($invoice->lines as $line) {
370 $warehouseid = ($line->fk_warehouse ? $line->fk_warehouse :
getDolGlobalInt($constantforkey));
373 if ($line->batch !=
'' && $warehouseid > 0) {
375 $prod_batch->find(0,
'',
'', $line->batch, $warehouseid);
378 $mouvP->setOrigin($invoice->element, $invoice->id);
380 $res = $mouvP->livraison($user, $line->fk_product, $warehouseid, $line->qty, $line->price, $labeltakeposmovement,
'',
'',
'', $prod_batch->batch, $prod_batch->id, $inventorycode);
387 $mouvP->setOrigin($invoice->element, $invoice->id);
389 $res = $mouvP->livraison($user, $line->fk_product, $warehouseid, $line->qty, $line->price, $labeltakeposmovement,
'',
'',
'',
'', 0, $inventorycode);
399 if (!$error && $res >= 0) {
405 if ($action ==
'creditnote' && $user->hasRight(
'facture',
'creer')) {
408 $creditnote =
new Facture($db);
409 $creditnote->socid = $invoice->socid;
411 $creditnote->module_source =
'takepos';
412 $creditnote->pos_source = isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'' ;
414 $creditnote->fk_facture_source = $placeid;
417 $creditnote->create($user);
419 foreach ($invoice->lines as $line) {
421 if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) {
426 if (!empty($invoice->situation_counter)) {
427 $source_fk_prev_id = $line->fk_prev_id;
428 $line->fk_prev_id = $line->id;
429 if (!empty($invoice->tab_previous_situation_invoice)) {
432 $tab_jumped_credit_notes = array();
433 $lineIndex = count($invoice->tab_previous_situation_invoice) - 1;
434 $searchPreviousInvoice =
true;
435 while ($searchPreviousInvoice) {
436 if ($invoice->tab_previous_situation_invoice[$lineIndex]->situation_cycle_ref || $lineIndex < 1) {
437 $searchPreviousInvoice =
false;
441 $tab_jumped_credit_notes[$lineIndex] = $invoice->tab_previous_situation_invoice[$lineIndex]->id;
447 $maxPrevSituationPercent = 0;
448 foreach ($invoice->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine) {
449 if ($prevLine->id == $source_fk_prev_id) {
450 $maxPrevSituationPercent = max($maxPrevSituationPercent, $prevLine->situation_percent);
453 $line->total_ht = $line->total_ht - $prevLine->total_ht;
454 $line->total_tva = $line->total_tva - $prevLine->total_tva;
455 $line->total_ttc = $line->total_ttc - $prevLine->total_ttc;
456 $line->total_localtax1 = $line->total_localtax1 - $prevLine->total_localtax1;
457 $line->total_localtax2 = $line->total_localtax2 - $prevLine->total_localtax2;
459 $line->multicurrency_subprice = $line->multicurrency_subprice - $prevLine->multicurrency_subprice;
460 $line->multicurrency_total_ht = $line->multicurrency_total_ht - $prevLine->multicurrency_total_ht;
461 $line->multicurrency_total_tva = $line->multicurrency_total_tva - $prevLine->multicurrency_total_tva;
462 $line->multicurrency_total_ttc = $line->multicurrency_total_ttc - $prevLine->multicurrency_total_ttc;
467 $line->situation_percent = $maxPrevSituationPercent - $line->situation_percent;
472 $maxPrevSituationPercent = 0;
473 foreach ($tab_jumped_credit_notes as $index => $creditnoteid) {
474 foreach ($invoice->tab_previous_situation_invoice[$index]->lines as $prevLine) {
475 if ($prevLine->fk_prev_id == $source_fk_prev_id) {
476 $maxPrevSituationPercent = $prevLine->situation_percent;
478 $line->total_ht -= $prevLine->total_ht;
479 $line->total_tva -= $prevLine->total_tva;
480 $line->total_ttc -= $prevLine->total_ttc;
481 $line->total_localtax1 -= $prevLine->total_localtax1;
482 $line->total_localtax2 -= $prevLine->total_localtax2;
484 $line->multicurrency_subprice -= $prevLine->multicurrency_subprice;
485 $line->multicurrency_total_ht -= $prevLine->multicurrency_total_ht;
486 $line->multicurrency_total_tva -= $prevLine->multicurrency_total_tva;
487 $line->multicurrency_total_ttc -= $prevLine->multicurrency_total_ttc;
493 $line->situation_percent += $maxPrevSituationPercent;
501 $line->fk_facture = $creditnote->id;
502 $line->fk_parent_line = $fk_parent_line;
504 $line->subprice = -$line->subprice;
506 $line->total_ht = -$line->total_ht;
507 $line->total_tva = -$line->total_tva;
508 $line->total_ttc = -$line->total_ttc;
509 $line->total_localtax1 = -$line->total_localtax1;
510 $line->total_localtax2 = -$line->total_localtax2;
512 $line->multicurrency_subprice = -$line->multicurrency_subprice;
513 $line->multicurrency_total_ht = -$line->multicurrency_total_ht;
514 $line->multicurrency_total_tva = -$line->multicurrency_total_tva;
515 $line->multicurrency_total_ttc = -$line->multicurrency_total_ttc;
517 $result = $line->insert(0, 1);
519 $creditnote->lines[] = $line;
522 if ($result > 0 && $line->product_type == 9) {
523 $fk_parent_line = $result;
526 $creditnote->update_price(1);
530 $constantforkey =
'CASHDESK_NO_DECREASE_STOCK'.(isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
533 if (isModEnabled(
'stock') && !isModEnabled(
'productbatch') && $allowstockchange) {
537 $conf->global->STOCK_CALCULATE_ON_BILL = 1;
539 $constantforkey =
'CASHDESK_ID_WAREHOUSE'.(isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
541 dol_syslog(
"Validate invoice with stock change into warehouse defined into constant ".$constantforkey.
" = ".
getDolGlobalString($constantforkey).
" or warehouseid= ".$warehouseid.
" if defined.");
546 $res = $creditnote->validate($user,
'',
getDolGlobalString($constantforkey), 0, $batch_rule);
553 $conf->global->STOCK_CALCULATE_ON_BILL = $savconst;
555 $res = $creditnote->validate($user);
559 if (!$error && $res >= 0) {
560 if (isModEnabled(
'stock') && isModEnabled(
'productbatch') && $allowstockchange) {
562 dol_syslog(
"Now we record the stock movement for each qualified line");
565 require_once DOL_DOCUMENT_ROOT .
"/product/stock/class/mouvementstock.class.php";
566 $constantforkey =
'CASHDESK_ID_WAREHOUSE'.$_SESSION[
"takeposterminal"];
569 $labeltakeposmovement =
'TakePOS - '.$langs->trans(
"CreditNote").
' '.$creditnote->ref;
571 foreach ($creditnote->lines as $line) {
573 $warehouseid = ($line->fk_warehouse ? $line->fk_warehouse :
getDolGlobalInt($constantforkey));
576 if ($line->batch !=
'' && $warehouseid > 0) {
581 $mouvP->setOrigin($creditnote->element, $creditnote->id);
583 $res = $mouvP->reception($user, $line->fk_product, $warehouseid, $line->qty, $line->price, $labeltakeposmovement,
'',
'', $line->batch,
'', 0, $inventorycode);
590 $mouvP->setOrigin($creditnote->element, $creditnote->id);
592 $res = $mouvP->reception($user, $line->fk_product, $warehouseid, $line->qty, $line->price, $labeltakeposmovement,
'',
'',
'',
'', 0, $inventorycode);
602 if (!$error && $res >= 0) {
605 $creditnote->id = $placeid;
610 if (($action ==
'history' || $action ==
'creditnote') && $user->hasRight(
'takepos',
'run')) {
611 if ($action ==
'creditnote' && $creditnote->id > 0) {
612 $placeid = $creditnote->id;
618 $invoice->fetch($placeid);
622 if (($action ==
"addline" || $action ==
"freezone") && $placeid == 0 && ($user->hasRight(
'takepos',
'run') || defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
625 include_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
628 $invoice->module_source =
'takepos';
629 $invoice->pos_source = isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'' ;
630 $invoice->entity = !empty($_SESSION[
"takeposinvoiceentity"]) ? $_SESSION[
"takeposinvoiceentity"] : $conf->entity;
632 if ($invoice->socid <= 0) {
633 $langs->load(
'errors');
639 $placeid = $invoice->create($user);
643 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facture set ref='(PROV-POS".$_SESSION[
"takeposterminal"].
"-".$place.
")' where rowid = ".((int) $placeid);
644 $resql = $db->query($sql);
658 if ($action ==
"addline" && ($user->hasRight(
'takepos',
'run') || defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
660 $prod->fetch($idproduct);
663 $customer->fetch($invoice->socid);
665 $datapriceofproduct = $prod->getSellPrice($mysoc, $customer, 0);
667 $qty = GETPOSTISSET(
'qty') ?
GETPOSTINT(
'qty') : 1;
668 $price = $datapriceofproduct[
'pu_ht'];
669 $price_ttc = $datapriceofproduct[
'pu_ttc'];
671 $price_base_type = empty($datapriceofproduct[
'price_base_type']) ?
'HT' : $datapriceofproduct[
'price_base_type'];
672 $tva_tx = $datapriceofproduct[
'tva_tx'];
673 $tva_npr = $datapriceofproduct[
'tva_npr'];
676 $localtax1_tx =
get_localtax($tva_tx, 1, $customer, $mysoc, $tva_npr);
677 $localtax2_tx =
get_localtax($tva_tx, 2, $customer, $mysoc, $tva_npr);
680 if (isModEnabled(
'productbatch') && isModEnabled(
'stock')) {
681 $batch =
GETPOST(
'batch',
'alpha');
683 if (!empty($batch)) {
684 $action =
"setbatch";
685 } elseif ($prod->status_batch > 0) {
690 $prod->load_stock(
'warehouseopen');
692 $constantforkey =
'CASHDESK_ID_WAREHOUSE'.$_SESSION[
"takeposterminal"];
696 foreach ($prod->stock_warehouse as $tmpwarehouseid => $tmpval) {
701 if (!empty($prod->stock_warehouse[$tmpwarehouseid]) && is_array($prod->stock_warehouse[$tmpwarehouseid]->detail_batch)) {
702 if (is_object($prod->stock_warehouse[$tmpwarehouseid]) && count($prod->stock_warehouse[$tmpwarehouseid]->detail_batch)) {
703 foreach ($prod->stock_warehouse[$tmpwarehouseid]->detail_batch as $dbatch) {
712 echo
"function addbatch(batch, warehouseid) {\n";
713 echo
"console.log('We add batch '+batch+' from warehouse id '+warehouseid);\n";
714 echo
'$("#poslines").load("'.DOL_URL_ROOT.
'/takepos/invoice.php?action=addline&batch="+encodeURI(batch)+"&warehouseid="+warehouseid+"&place='.$place.
'&idproduct='.$idproduct.
'&token='.
newToken().
'", function() {});'.
"\n";
719 echo
"<center>".$langs->trans(
"SearchIntoBatch").
": <b> $nbofsuggested </b></center><br><table>";
720 foreach ($prod->stock_warehouse as $tmpwarehouseid => $tmpval) {
725 if (!empty($prod->stock_warehouse[$tmpwarehouseid]) && is_array($prod->stock_warehouse[$tmpwarehouseid]->detail_batch)) {
726 foreach ($prod->stock_warehouse[$tmpwarehouseid]->detail_batch as $dbatch) {
727 $batchStock = + $dbatch->qty;
728 $quantityToBeDelivered = 1;
729 $deliverableQty = min($quantityToBeDelivered, $batchStock);
731 print
'<!-- subj='.$suggestednb.
'/'.$nbofsuggested.
' -->';
732 print
'<!-- Show details of lot/serial in warehouseid='.$tmpwarehouseid.
' -->';
733 print
'<td class="left">';
735 $detail .=
'<span class="opacitymedium">'.$langs->trans(
"LotSerial").
':</span> '.$dbatch->batch;
742 $detail .=
'</td><td>';
743 $detail .=
'<span class="opacitymedium">'.$langs->trans(
"Qty").
':</span> '.$dbatch->qty;
744 $detail .=
'</td><td>';
745 $detail .=
' <button class="marginleftonly" onclick="addbatch(\''.dol_escape_js($dbatch->batch).
'\',
'.$tmpwarehouseid.')
">'.$langs->trans("Select
")."</
button>
";
749 $quantityToBeDelivered -= $deliverableQty;
750 if ($quantityToBeDelivered < 0) {
751 $quantityToBeDelivered = 0;
760 print '</body></html>';
766 if (getDolGlobalString('TAKEPOS_SUPPLEMENTS')) {
767 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
768 $cat = new Categorie($db);
769 $categories = $cat->containing($idproduct, 'product');
770 $found = (array_search(getDolGlobalInt('TAKEPOS_SUPPLEMENTS_CATEGORY'), array_column($categories, 'id')));
771 if ($found !== false) { // If this product is a supplement
772 $sql = "SELECT fk_parent_line FROM
".MAIN_DB_PREFIX."facturedet where
rowid =
".((int) $selectedline);
773 $resql = $db->query($sql);
774 $row = $db->fetch_array($resql);
775 if ($row[0] == null) {
776 $parent_line = $selectedline;
778 $parent_line = $row[0]; //If the parent line is already a supplement, add the supplement to the main product
785 // Group if enabled. Skip group if line already sent to the printer
786 if (getDolGlobalString('TAKEPOS_GROUP_SAME_PRODUCT')) {
787 foreach ($invoice->lines as $line) {
788 if ($line->product_ref == $prod->ref) {
789 if ($line->special_code == 4) {
791 } // If this line is sended to printer create new line
792 // check if qty in stock
793 if (getDolGlobalString('TAKEPOS_QTY_IN_STOCK') && (($line->qty + $qty) > $prod->stock_reel)) {
794 $invoice->error = $langs->trans("ErrorStockIsNotEnough
");
795 dol_htmloutput_errors($invoice->error, $invoice->errors, 1);
799 $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);
801 dol_htmloutput_errors($invoice->error, $invoice->errors, 1);
803 $idoflineadded = $line->id;
809 if ($idoflineadded <= 0 && empty($err)) {
810 $invoice->fetch_thirdparty();
811 $array_options = array();
813 $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);
815 /* setup of margin calculation */
816 if (isset($conf->global->MARGIN_TYPE)) {
817 if (getDolGlobalString('MARGIN_TYPE') == 'pmp' && !empty($prod->pmp)) {
818 $line['fk_fournprice'] = null;
819 $line['pa_ht'] = $prod->pmp;
820 } elseif (getDolGlobalString('MARGIN_TYPE') == 'costprice' && !empty($prod->cost_price)) {
821 $line['fk_fournprice'] = null;
822 $line['pa_ht'] = $prod->cost_price;
824 // default is fournprice
825 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
826 $pf = new ProductFournisseur($db);
827 if ($pf->find_min_price_product_fournisseur($idproduct, $qty) > 0) {
828 $line['fk_fournprice'] = $pf->product_fourn_price_id;
829 $line['pa_ht'] = $pf->fourn_unitprice_with_discount;
830 if (getDolGlobalString('PRODUCT_CHARGES') && $pf->fourn_charges > 0) {
831 $line['pa_ht'] += $pf->fourn_charges / $pf->fourn_qty;
837 // complete line by hook
838 $parameters = array('prod' => $prod, 'line' => $line);
839 $reshook = $hookmanager->executeHooks('completeTakePosAddLine', $parameters, $invoice, $action); // Note that $action and $line may have been modified by some hooks
841 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
845 if (empty($reshook)) {
846 if (!empty($hookmanager->resArray)) {
847 $line = $hookmanager->resArray;
850 // check if qty in stock
851 if (getDolGlobalString('TAKEPOS_QTY_IN_STOCK') && $qty > $prod->stock_reel) {
852 $invoice->error = $langs->trans("ErrorStockIsNotEnough
");
853 dol_htmloutput_errors($invoice->error, $invoice->errors, 1);
858 $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);
862 if (getDolGlobalString('TAKEPOS_CUSTOMER_DISPLAY')) {
863 $CUSTOMER_DISPLAY_line1 = $prod->label;
864 $CUSTOMER_DISPLAY_line2 = price($price_ttc);
868 $invoice->fetch($placeid);
871 // If we add a line by submitting freezone form (invoice exists here because it was created juste before if it didn't exists)
872 if ($action == "freezone
" && $user->hasRight('takepos', 'run')) {
873 $customer = new Societe($db);
874 $customer->fetch($invoice->socid);
876 $tva_tx = GETPOST('tva_tx', 'alpha');
878 if (!preg_match('/\((.*)\)/', $tva_tx)) {
879 $tva_tx = price2num($tva_tx);
882 $tva_tx = get_default_tva($mysoc, $customer);
886 $localtax1_tx = get_localtax($tva_tx, 1, $customer, $mysoc, $tva_npr);
887 $localtax2_tx = get_localtax($tva_tx, 2, $customer, $mysoc, $tva_npr);
889 $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);
891 dol_htmloutput_errors($invoice->error, $invoice->errors, 1);
893 $invoice->fetch($placeid);
896 if ($action == "addnote
" && ($user->hasRight('takepos', 'run') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
897 $desc = GETPOST('addnote', 'alpha');
899 $invoice->update_note($desc, '_public');
901 foreach ($invoice->lines as $line) {
902 if ($line->id == $idline) {
903 $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);
907 $invoice->fetch($placeid);
910 if ($action == "deleteline
" && ($user->hasRight('takepos', 'run') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
912 $permissiontoupdateline = ($user->hasRight('takepos', 'editlines') && ($user->hasRight('takepos', 'editorderedlines') || $line->special_code != "4
"));
913 if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
914 if ($invoice->status == $invoice::STATUS_DRAFT && $invoice->pos_source && $invoice->module_source == 'takepos') {
915 $permissiontoupdateline = true;
916 // TODO Add also a test on $_SESSION('publicobjectid'] defined at creation of object
917 // TODO Check also that invoice->ref is (PROV-POS1-2) with 1 = terminal and 2, the invoice ID
921 if ($idline > 0 && $placeid > 0) { // If invoice exists and line selected. To avoid errors if deleted from another device or no line selected.
922 $invoice->deleteLine($idline);
923 $invoice->fetch($placeid);
924 } elseif ($placeid > 0) { // If invoice exists but no line selected, proceed to delete last line.
925 $sql = "SELECT
rowid FROM
".MAIN_DB_PREFIX."facturedet where fk_facture =
".((int) $placeid)." ORDER BY
rowid DESC
";
926 $resql = $db->query($sql);
927 $row = $db->fetch_array($resql);
928 $deletelineid = $row[0];
929 $invoice->deleteLine($deletelineid);
930 $invoice->fetch($placeid);
933 if (count($invoice->lines) == 0) {
934 $invoice->delete($user);
936 if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
937 header("Location:
".DOL_URL_ROOT."/takepos/public/auto_order.php
");
939 header("Location:
".DOL_URL_ROOT."/takepos/invoice.php
");
945 // Action to delete or discard an invoice
946 if ($action == "delete
" && ($user->hasRight('takepos', 'run') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
947 // $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.
949 $result = $invoice->fetch($placeid);
951 if ($result > 0 && $invoice->statut == Facture::STATUS_DRAFT) {
954 // We delete the lines
956 foreach ($invoice->lines as $line) {
957 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
958 $tmpres = $invoice->deleteLine($line->id);
965 $sql = "UPDATE
".MAIN_DB_PREFIX."facture
";
966 $varforconst = 'CASHDESK_ID_THIRDPARTY'.$_SESSION["takeposterminal
"];
967 $sql .= " SET fk_soc =
".((int) getDolGlobalString($varforconst)).",
";
968 $sql .= " datec =
'".$db->idate(dol_now())."'";
969 $sql .= " WHERE entity IN (
".getEntity('invoice').")
";
970 $sql .= " AND
ref =
'(PROV-POS".$db->escape($_SESSION["takeposterminal"]."-".$place).")'";
971 $resql1 = $db->query($sql);
973 if ($resdeletelines && $resql1) {
979 $invoice->fetch($placeid);
984 if ($action == "updateqty
") { // Test on permission is done later
985 foreach ($invoice->lines as $line) {
986 if ($line->id == $idline) {
987 $permissiontoupdateline = ($user->hasRight('takepos', 'editlines') && ($user->hasRight('takepos', 'editorderedlines') || $line->special_code != "4
"));
988 if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
989 if ($invoice->status == $invoice::STATUS_DRAFT && $invoice->pos_source && $invoice->module_source == 'takepos') {
990 $permissiontoupdateline = true;
991 // TODO Add also a test on $_SESSION('publicobjectid'] defined at creation of object
992 // TODO Check also that invoice->ref is (PROV-POS1-2) with 1 = terminal and 2, the invoice ID
995 if (!$permissiontoupdateline) {
996 dol_htmloutput_errors($langs->trans("NotEnoughPermissions
", "TakePos
").' - No permission to updateqty', null, 1);
998 $vatratecode = $line->tva_tx;
999 if ($line->vat_src_code) {
1000 $vatratecode .= ' ('.$line->vat_src_code.')';
1003 $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);
1008 $invoice->fetch($placeid);
1011 if ($action == "updateprice
") { // Test on permission is done later
1012 $customer = new Societe($db);
1013 $customer->fetch($invoice->socid);
1015 foreach ($invoice->lines as $line) {
1016 if ($line->id == $idline) {
1017 $prod = new Product($db);
1018 $prod->fetch($line->fk_product);
1019 $datapriceofproduct = $prod->getSellPrice($mysoc, $customer, 0);
1020 $price_min = $datapriceofproduct['price_min'];
1021 $usercanproductignorepricemin = ((getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !$user->hasRight('produit', 'ignore_price_min_advance')) || !getDolGlobalString('MAIN_USE_ADVANCED_PERMS'));
1022 $pu_ht = price2num($number / (1 + ($line->tva_tx / 100)), 'MU');
1024 if ($usercanproductignorepricemin && (!empty($price_min) && (price2num($pu_ht) * (1 - price2num($line->remise_percent) / 100) < price2num($price_min)))) {
1025 $langs->load("products
");
1026 dol_htmloutput_errors($langs->trans("CantBeLessThanMinPrice
", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, -1, $conf->currency)));
1027 //echo $langs->trans("CantBeLessThanMinPrice
");
1029 $permissiontoupdateline = ($user->hasRight('takepos', 'editlines') && ($user->hasRight('takepos', 'editorderedlines') || $line->special_code != "4
"));
1030 if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1031 if ($invoice->status == $invoice::STATUS_DRAFT && $invoice->pos_source && $invoice->module_source == 'takepos') {
1032 $permissiontoupdateline = true;
1033 // TODO Add also a test on $_SESSION('publicobjectid'] defined at creation of object
1034 // TODO Check also that invoice->ref is (PROV-POS1-2) with 1 = terminal and 2, the invoice ID
1038 $vatratecode = $line->tva_tx;
1039 if ($line->vat_src_code) {
1040 $vatratecode .= ' ('.$line->vat_src_code.')';
1043 if (!$permissiontoupdateline) {
1044 dol_htmloutput_errors($langs->trans("NotEnoughPermissions
", "TakePos
").' - No permission to updateprice', null, 1);
1045 } elseif (getDolGlobalInt('TAKEPOS_CHANGE_PRICE_HT') == 1) {
1046 $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);
1048 $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);
1055 $invoice->fetch($placeid);
1058 if ($action == "updatereduction
") { // Test on permission is done later
1059 $customer = new Societe($db);
1060 $customer->fetch($invoice->socid);
1062 foreach ($invoice->lines as $line) {
1063 if ($line->id == $idline) {
1064 dol_syslog("updatereduction Process line
".$line->id.' to apply discount of '.$number.'%');
1066 $prod = new Product($db);
1067 $prod->fetch($line->fk_product);
1069 $datapriceofproduct = $prod->getSellPrice($mysoc, $customer, 0);
1070 $price_min = $datapriceofproduct['price_min'];
1071 $usercanproductignorepricemin = ((getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !$user->hasRight('produit', 'ignore_price_min_advance')) || !getDolGlobalString('MAIN_USE_ADVANCED_PERMS'));
1073 $pu_ht = price2num($line->subprice / (1 + ($line->tva_tx / 100)), 'MU');
1076 if ($usercanproductignorepricemin && (!empty($price_min) && (price2num($line->subprice) * (1 - price2num($number) / 100) < price2num($price_min)))) {
1077 $langs->load("products
");
1078 dol_htmloutput_errors($langs->trans("CantBeLessThanMinPrice
", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, -1, $conf->currency)));
1080 $permissiontoupdateline = ($user->hasRight('takepos', 'editlines') && ($user->hasRight('takepos', 'editorderedlines') || $line->special_code != "4
"));
1081 if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1082 if ($invoice->status == $invoice::STATUS_DRAFT && $invoice->pos_source && $invoice->module_source == 'takepos') {
1083 $permissiontoupdateline = true;
1084 // TODO Add also a test on $_SESSION('publicobjectid'] defined at creation of object
1085 // TODO Check also that invoice->ref is (PROV-POS1-2) with 1 = terminal and 2, the invoice ID
1088 if (!$permissiontoupdateline) {
1089 dol_htmloutput_errors($langs->trans("NotEnoughPermissions
", "TakePos
"), null, 1);
1091 $vatratecode = $line->tva_tx;
1092 if ($line->vat_src_code) {
1093 $vatratecode .= ' ('.$line->vat_src_code.')';
1095 $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);
1102 $invoice->fetch($placeid);
1103 } elseif ($action == 'update_reduction_global' && $user->hasRight('takepos', 'editlines')) {
1104 foreach ($invoice->lines as $line) {
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);
1112 $invoice->fetch($placeid);
1115 if ($action == "setbatch
" && ($user->hasRight('takepos', 'run') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
1116 $constantforkey = 'CASHDESK_ID_WAREHOUSE'.$_SESSION["takeposterminal
"];
1117 $warehouseid = (GETPOSTINT('warehouseid') > 0 ? GETPOSTINT('warehouseid') : getDolGlobalInt($constantforkey)); // Get the warehouse id from GETPOSTINT('warehouseid'), otherwise use default setup.
1118 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet SET batch =
'".$db->escape($batch)."', fk_warehouse =
".((int) $warehouseid);
1119 $sql .= " WHERE
rowid=
".((int) $idoflineadded);
1123 if ($action == "order
" && $placeid != 0 && ($user->hasRight('takepos', 'run') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
1124 include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
1125 if ((isModEnabled('receiptprinter') && getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term) > 0) || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter
" || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector
") {
1126 require_once DOL_DOCUMENT_ROOT.'/core/class/dolreceiptprinter.class.php';
1127 $printer = new dolReceiptPrinter($db);
1130 $sql = "SELECT label FROM
".MAIN_DB_PREFIX."takepos_floor_tables where
rowid=
".((int) $place);
1131 $resql = $db->query($sql);
1132 $row = $db->fetch_object($resql);
1133 $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>';
1134 $footerorder = '</tbody></table>'.dol_print_date(dol_now(), 'dayhour').'<br></html>';
1135 $order_receipt_printer1 = "";
1136 $order_receipt_printer2 = "";
1137 $order_receipt_printer3 = "";
1138 $catsprinter1 = explode(';', getDolGlobalString('TAKEPOS_PRINTED_CATEGORIES_1'));
1139 $catsprinter2 = explode(';', getDolGlobalString('TAKEPOS_PRINTED_CATEGORIES_2'));
1140 $catsprinter3 = explode(';', getDolGlobalString('TAKEPOS_PRINTED_CATEGORIES_3'));
1142 foreach ($invoice->lines as $line) {
1143 if ($line->special_code == "4
") {
1146 $c = new Categorie($db);
1147 $existing = $c->containing($line->fk_product, Categorie::TYPE_PRODUCT, 'id');
1148 $result = array_intersect($catsprinter1, $existing);
1149 $count = count($result);
1150 if (!$line->fk_product) {
1151 $count++; // Print Free-text item (Unassigned printer) to Printer 1
1155 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet set special_code=
'1' where
rowid=
".$line->id; //Set to print on printer 1
1157 $order_receipt_printer1 .= '<tr><td class="left
">';
1158 if ($line->fk_product) {
1159 $order_receipt_printer1 .= $line->product_label;
1161 $order_receipt_printer1 .= $line->description;
1163 $order_receipt_printer1 .= '</td><td class="right
">'.$line->qty;
1164 if (!empty($line->array_options['options_order_notes'])) {
1165 $order_receipt_printer1 .= "<br>(
".$line->array_options['options_order_notes'].")
";
1167 $order_receipt_printer1 .= '</td></tr>';
1170 if (((isModEnabled('receiptprinter') && getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term) > 0) || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter
" || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector
") && $linestoprint > 0) {
1171 $invoice->fetch($placeid); //Reload object before send to printer
1172 $printer->orderprinter = 1;
1174 echo "var orderprinter1esc=
'";
1175 $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
1178 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet
set special_code=
'4' where special_code=
'1' and fk_facture=
".$invoice->id; // Set as printed
1180 $invoice->fetch($placeid); //Reload object after set lines as printed
1183 foreach ($invoice->lines as $line) {
1184 if ($line->special_code == "4
") {
1187 $c = new Categorie($db);
1188 $existing = $c->containing($line->fk_product, Categorie::TYPE_PRODUCT, 'id');
1189 $result = array_intersect($catsprinter2, $existing);
1190 $count = count($result);
1193 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet
set special_code=
'2' where
rowid=
".$line->id; //Set to print on printer 2
1195 $order_receipt_printer2 .= '<tr>'.$line->product_label.'<td class="right
">'.$line->qty;
1196 if (!empty($line->array_options['options_order_notes'])) {
1197 $order_receipt_printer2 .= "<br>(
".$line->array_options['options_order_notes'].")
";
1199 $order_receipt_printer2 .= '</td></tr>';
1202 if (((isModEnabled('receiptprinter') && getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term) > 0) || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter
" || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector
") && $linestoprint > 0) {
1203 $invoice->fetch($placeid); //Reload object before send to printer
1204 $printer->orderprinter = 2;
1206 echo "var orderprinter2esc=
'";
1207 $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
1210 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet
set special_code=
'4' where special_code=
'2' and fk_facture=
".$invoice->id; // Set as printed
1212 $invoice->fetch($placeid); //Reload object after set lines as printed
1215 foreach ($invoice->lines as $line) {
1216 if ($line->special_code == "4
") {
1219 $c = new Categorie($db);
1220 $existing = $c->containing($line->fk_product, Categorie::TYPE_PRODUCT, 'id');
1221 $result = array_intersect($catsprinter3, $existing);
1222 $count = count($result);
1225 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet
set special_code=
'3' where
rowid=
".$line->id; //Set to print on printer 3
1227 $order_receipt_printer3 .= '<tr>'.$line->product_label.'<td class="right
">'.$line->qty;
1228 if (!empty($line->array_options['options_order_notes'])) {
1229 $order_receipt_printer3 .= "<br>(
".$line->array_options['options_order_notes'].")
";
1231 $order_receipt_printer3 .= '</td></tr>';
1234 if (((isModEnabled('receiptprinter') && getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term) > 0) || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter
" || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector
") && $linestoprint > 0) {
1235 $invoice->fetch($placeid); //Reload object before send to printer
1236 $printer->orderprinter = 3;
1238 echo "var orderprinter3esc=
'";
1239 $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
1242 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet
set special_code=
'4' where special_code=
'3' and fk_facture=
".$invoice->id; // Set as printed
1244 $invoice->fetch($placeid); //Reload object after set lines as printed
1247 $sectionwithinvoicelink = '';
1248 if (($action == "valid
" || $action == "history
" || $action == 'creditnote') && $user->hasRight('takepos', 'run')) {
1249 $sectionwithinvoicelink .= '<!-- Section with invoice link -->'."\n
";
1250 $sectionwithinvoicelink .= '<span style="font-size:120%;
" class="center
">';
1251 $sectionwithinvoicelink .= $invoice->getNomUrl(1, '', 0, 0, '', 0, 0, -1, '_backoffice')." -
";
1252 $remaintopay = $invoice->getRemainToPay();
1253 if ($remaintopay > 0) {
1254 $sectionwithinvoicelink .= $langs->trans('RemainToPay').': <span class="amountremaintopay
" style="font-size: unset
">'.price($remaintopay, 1, $langs, 1, -1, -1, $conf->currency).'</span>';
1256 if ($invoice->paye) {
1257 $sectionwithinvoicelink .= '<span class="amountpaymentcomplete
" style="font-size: unset
">'.$langs->trans("Paid
").'</span>';
1259 $sectionwithinvoicelink .= $langs->trans('BillShortStatusValidated');
1263 $sectionwithinvoicelink .= '</span><br>';
1264 if (getDolGlobalInt('TAKEPOS_PRINT_INVOICE_DOC_INSTEAD_OF_RECEIPT')) {
1265 $sectionwithinvoicelink .= ' <a target="_blank
" class="button" href="' . DOL_URL_ROOT . '/document.php?token=
' . newToken() . '&modulepart=facture&file=
' . $invoice->ref . '/
' . $invoice->ref . '.pdf
">Invoice</a>';
1266 } elseif (getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector
") {
1267 if (getDolGlobalString('TAKEPOS_PRINT_SERVER') && filter_var($conf->global->TAKEPOS_PRINT_SERVER, FILTER_VALIDATE_URL) == true) {
1268 $sectionwithinvoicelink .= ' <button id="buttonprint
" type="button" onclick="TakeposConnector(
'.$placeid.')
">'.$langs->trans('PrintTicket').'</button>';
1270 $sectionwithinvoicelink .= ' <button id="buttonprint
" type="button" onclick="TakeposPrinting(
'.$placeid.')
">'.$langs->trans('PrintTicket').'</button>';
1272 } elseif ((isModEnabled('receiptprinter') && getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term) > 0) || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter
") {
1273 $sectionwithinvoicelink .= ' <button id="buttonprint
" type="button" onclick="DolibarrTakeposPrinting(
'.$placeid.')
">'.$langs->trans('PrintTicket').'</button>';
1275 $sectionwithinvoicelink .= ' <button id="buttonprint
" type="button" onclick="Print(
'.$placeid.')
">'.$langs->trans('PrintTicket').'</button>';
1276 if (getDolGlobalString('TAKEPOS_PRINT_WITHOUT_DETAILS')) {
1277 $sectionwithinvoicelink .= ' <button id="buttonprint
" type="button" onclick="PrintBox(
'.$placeid.', \
'without_details\')">'.$langs->trans(
'PrintWithoutDetails').
'</button>';
1280 $sectionwithinvoicelink .=
' <button id="buttonprint" type="button" onclick="Print('.$placeid.
', 1)">'.$langs->trans(
'GiftReceipt').
'</button>';
1284 $sectionwithinvoicelink .=
' <button id="buttonsend" type="button" onclick="SendTicket('.$placeid.
')">'.$langs->trans(
'SendTicket').
'</button>';
1287 if ($remaintopay <= 0 &&
getDolGlobalString(
'TAKEPOS_AUTO_PRINT_TICKETS') && $action !=
"history") {
1288 $sectionwithinvoicelink .=
'<script type="text/javascript">$("#buttonprint").click();</script>';
1298$form =
new Form($db);
1301if ((
getDolGlobalString(
'TAKEPOS_PHONE_BASIC_LAYOUT') == 1 && $conf->browser->layout ==
'phone') || defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1302 $title =
'TakePOS - Dolibarr '.DOL_VERSION;
1306 $head =
'<meta name="apple-mobile-web-app-title" content="TakePOS"/>
1307 <meta name="apple-mobile-web-app-capable" content="yes">
1308 <meta name="mobile-web-app-capable" content="yes">
1309 <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>';
1310 $arrayofcss = array(
1311 '/takepos/css/pos.css.php',
1313 $arrayofjs = array(
'/takepos/js/jquery.colorbox-min.js');
1316 top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss);
1318 print
'<body>'.
"\n";
1325<script
type=
"text/javascript">
1328<?php
if ($action ==
"valid") {
1329 echo
"var place=0;";
1331var placeid=<?php echo($placeid > 0 ? $placeid : 0); ?>;
1332$(document).ready(
function() {
1333 var idoflineadded = <?php echo(empty($idoflineadded) ? 0 : $idoflineadded); ?>;
1335 $(
'.posinvoiceline').click(
function(){
1336 console.log(
"Click done on "+this.
id);
1337 $(
'.posinvoiceline').removeClass(
"selected");
1338 $(
this).addClass(
"selected");
1342 if (selectedline == this.
id) {
1345 selectedline = this.id;
1347 selectedtext=$(
'#'+selectedline).find(
"td:first").html();
1349 if (defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1350 print
'$("#phonediv1").load("'.DOL_URL_ROOT.
'/takepos/public/auto_order.php?action=editline&token='.
newToken().
'&placeid="+placeid+"&selectedline="+selectedline, function() {
1357 if (idoflineadded > 0)
1359 console.log(
"Auto select "+idoflineadded);
1360 $(
'.posinvoiceline#'+idoflineadded).click();
1364if ($action ==
"order" && !empty($order_receipt_printer1)) {
1365 if (filter_var($conf->global->TAKEPOS_PRINT_SERVER, FILTER_VALIDATE_URL) ==
true) {
1369 url:
'<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>/printer/index.php',
1370 data:
'invoice='+orderprinter1esc
1377 url:
'http://<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>:8111/print',
1379 print $headerorder.$order_receipt_printer1.$footerorder; ?>'
1385if ($action ==
"order" && !empty($order_receipt_printer2)) {
1386 if (filter_var($conf->global->TAKEPOS_PRINT_SERVER, FILTER_VALIDATE_URL) ==
true) {
1390 url:
'<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>/printer/index.php?printer=2',
1391 data:
'invoice='+orderprinter2esc
1398 url:
'http://<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>:8111/print2',
1400 print $headerorder.$order_receipt_printer2.$footerorder; ?>'
1406if ($action ==
"order" && !empty($order_receipt_printer3)) {
1407 if (filter_var($conf->global->TAKEPOS_PRINT_SERVER, FILTER_VALIDATE_URL) ==
true) {
1411 url:
'<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>/printer/index.php?printer=3',
1412 data:
'invoice='+orderprinter3esc
1419if ($action ==
"search" || $action ==
"valid") {
1421 parent.ClearSearch(
true);
1426if ($action ==
"temp" && !empty($ticket_printer1)) {
1430 url:
'http://<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>:8111/print',
1432 print $header_soc.$header_ticket.$body_ticket.$ticket_printer1.$ticket_total.$footer_ticket; ?>'
1437if ($action ==
"search") {
1439 $(
'#search').focus();
1447function SendTicket(
id)
1449 console.log(
"Open box to select the Print/Send form");
1450 $.colorbox({href:
"send.php?facid="+id, width:
"70%", height:
"30%", transition:
"none", iframe:
"true", title:
'<?php echo dol_escape_js($langs->trans("SendTicket")); ?>'});
1454function PrintBox(
id, action) {
1455 console.log(
"Open box before printing");
1456 $.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
"); ?>"});
1460function Print(
id, gift){
1461 console.log(
"Call Print() to generate the receipt.");
1462 $.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")); ?>'});
1466function TakeposPrinting(
id){
1468 console.log(
"TakeposPrinting" +
id);
1469 $.get(
"receipt.php?facid="+
id,
function(data,
status) {
1470 receipt=data.replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g,
'');
1473 url:
'http://<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER
'); ?>:8111/print',
1480function TakeposConnector(
id){
1481 console.log(
"TakeposConnector" +
id);
1482 $.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) {
1485 url:
'<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER
'); ?>/printer/index.php',
1486 data:
'invoice='+data
1494function DolibarrTakeposPrinting(
id) {
1495 console.log(
"DolibarrTakeposPrinting Printing invoice ticket " +
id);
1498 data: { token:
'<?php echo currentToken(); ?>' },
1499 url:
"<?php print DOL_URL_ROOT.'/takepos/ajax/ajax.php?action=printinvoiceticket&token='.newToken().'&term='.urlencode(isset($_SESSION["takeposterminal
"]) ? $_SESSION["takeposterminal
"] : '').'&id='; ?>" + id,
1506function CreditNote() {
1507 $(
"#poslines").load(
"<?php print DOL_URL_ROOT; ?>/takepos/invoice.php?action=creditnote&token=<?php echo newToken() ?>&invoiceid="+placeid,
function() { });
1513 $(
"#poslines").load(
"<?php print DOL_URL_ROOT; ?>/takepos/invoice.php?action=addnote&token=<?php echo newToken() ?>&invoiceid="+placeid+
"&idline="+selectedline, {
"addnote": $(
"#textinput").val() });
1518$( document ).ready(
function() {
1519 console.log(
"Set customer info and sales in header placeid=<?php echo $placeid; ?> status=<?php echo $invoice->statut; ?>");
1522 $s = $langs->trans(
"Customer");
1523 if ($invoice->id > 0 && ($invoice->socid !=
getDolGlobalString($constforcompanyid))) {
1526 $contactids = $invoice->getIdContact(
'external',
'BILLING');
1527 $contactid = $contactids[0];
1528 if ($contactid > 0) {
1530 $contact->fetch($contactid);
1531 $s .=
" - " . $contact->getFullName($langs);
1537 $(
"#customerandsales").html(
'');
1538 $(
"#shoppingcart").html(
'');
1541 $(
"#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>');
1543 $(
"#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>');
1547 $sql =
"SELECT rowid, datec, ref FROM ".MAIN_DB_PREFIX.
"facture";
1548 $sql .=
" WHERE entity IN (".getEntity(
'invoice').
")";
1551 $sql .=
" AND ref LIKE '(PROV-POS".$db->escape(isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'').
"-0%'";
1554 $sql .=
" AND pos_source = '".$db->escape($_SESSION[
"takeposterminal"]).
"'";
1555 $sql .=
" AND module_source = 'takepos'";
1558 $sql .= $db->order(
'datec',
'ASC');
1559 $resql = $db->query($sql);
1562 while ($obj = $db->fetch_object($resql)) {
1563 echo
'$("#shoppingcart").append(\'';
1564 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=\\\'';
1565 $num_sale = str_replace(
")",
"", str_replace(
"(PROV-POS".$_SESSION[
"takeposterminal"].
"-",
"", $obj->ref));
1567 if (str_replace(
"-",
"", $num_sale) > $max_sale) {
1568 $max_sale = str_replace(
"-",
"", $num_sale);
1570 echo
'\\\'; invoiceid=\\\'';
1572 echo
'\\\'; Refresh();">';
1573 if ($placeid == $obj->rowid) {
1574 echo
'<span class="basketselected">';
1576 echo
'<span class="basketnotselected">';
1578 echo
'<span class="fa fa-shopping-cart paddingright"></span>'.dol_print_date($db->jdate($obj->datec),
'%H:%M',
'tzuser');
1582 echo
'$("#shoppingcart").append(\'<a onclick="place=\\\'0-';
1584 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>\');';
1592 $constantforkey =
'CASHDESK_NO_DECREASE_STOCK'. (isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
1593 if (isModEnabled(
'stock')) {
1595 $constantforkey =
'CASHDESK_ID_WAREHOUSE'. (isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
1597 if ($idwarehouse > 0) {
1598 $s =
'<span class="small">';
1600 $warehouse->fetch($idwarehouse);
1601 $s .=
'<span class="hideonsmartphone">'.$langs->trans(
"Warehouse").
'<br></span>'.$warehouse->ref;
1603 $s .=
' ('.$langs->trans(
"Closed").
')';
1606 print
"$('#infowarehouse').html('".dol_escape_js($s).
"');";
1607 print
'$("#infowarehouse").css("display", "inline-block");';
1609 $s =
'<span class="small hideonsmartphone">';
1610 $s .= $langs->trans(
"StockChangeDisabled").
'<br>'.$langs->trans(
"NoWarehouseDefinedForTerminal");
1612 print
"$('#infowarehouse').html('".dol_escape_js($s).
"');";
1613 if (!empty($conf->dol_optimize_smallscreen)) {
1614 print
'$("#infowarehouse").css("display", "none");';
1618 $s =
'<span class="small hideonsmartphone">'.$langs->trans(
"StockChangeDisabled").
'</span>';
1619 print
"$('#infowarehouse').html('".dol_escape_js($s).
"');";
1620 if (!empty($conf->dol_optimize_smallscreen)) {
1621 print
'$("#infowarehouse").css("display", "none");';
1629 if (isModEnabled(
'member') && $invoice->socid > 0 && $invoice->socid !=
getDolGlobalInt($constforcompanyid)) {
1630 $s =
'<span class="small">';
1631 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
1632 $langs->load(
"members");
1633 $s .= $langs->trans(
"Member").
': ';
1635 $result = $adh->fetch(
'',
'', $invoice->socid);
1637 $adh->ref = $adh->getFullName($langs);
1641 $s .= $adh->getFullName($langs);
1642 $s .=
' - '.$adh->type;
1643 if ($adh->datefin) {
1644 $s .=
'<br>'.$langs->trans(
"SubscriptionEndDate").
': '.
dol_print_date($adh->datefin,
'day');
1645 if ($adh->hasDelay()) {
1646 $s .=
" ".img_warning($langs->trans(
"Late"));
1649 $s .=
'<br>'.$langs->trans(
"SubscriptionNotReceived");
1650 if ($adh->statut > 0) {
1651 $s .=
" ".img_warning($langs->trans(
"Late"));
1658 $s .=
'<br>'.$langs->trans(
"ThirdpartyNotLinkedToMember");
1663 $(
"#moreinfo").html(
'<?php print dol_escape_js($s); ?>');
1670 echo
"function CustomerDisplay(){";
1671 echo
"var line1='".$CUSTOMER_DISPLAY_line1.
"'.substring(0,20);";
1672 echo
"line1=line1.padEnd(20);";
1673 echo
"var line2='".$CUSTOMER_DISPLAY_line2.
"'.substring(0,20);";
1674 echo
"line2=line2.padEnd(20);";
1677 data: { text: line1+line2 },
1678 url: '".getDolGlobalString(
'TAKEPOS_PRINT_SERVER').
"/display/index.php',
1689if (!empty($conf->use_javascript_ajax)) {
1690 print
"\n".
'<!-- Includes JS Footer of Dolibarr -->'.
"\n";
1691 print
'<script src="'.DOL_URL_ROOT.
'/core/js/lib_foot.js.php?lang='.$langs->defaultlang.
'"></script>'.
"\n";