103 header($_SERVER[
'SERVER_PROTOCOL'].
' 500 Internal Server Error',
true, 500);
109$number =
GETPOST(
'number',
'alpha');
112$desc =
GETPOST(
'desc',
'alphanohtml');
125if ($pay ==
'cheque') {
132 $sql =
"SELECT id FROM ".MAIN_DB_PREFIX.
"c_paiement";
133 $sql .=
" WHERE entity IN (".getEntity(
'c_paiement').
")";
134 $sql .=
" AND code = '".$db->escape($paycode).
"'";
135 $resql = $db->query($sql);
137 $obj = $db->fetch_object($resql);
139 $paiementid = $obj->id;
146 $ret = $invoice->fetch($invoiceid);
148 $ret = $invoice->fetch(
'',
'(PROV-POS'.$takeposterminal.
'-'.$place.
')');
151 $placeid = $invoice->id;
154$constforcompanyid =
'CASHDESK_ID_THIRDPARTY'.$takeposterminal;
157if ($invoice->socid > 0) {
158 $soc->fetch($invoice->socid);
164if (isModEnabled(
'project') &&
getDolGlobalInt(
"CASHDESK_ID_PROJECT".$takeposterminal)) {
165 $invoice->fk_project =
getDolGlobalInt(
"CASHDESK_ID_PROJECT".$takeposterminal);
169if (isModEnabled(
'multicurrency') && !empty($_SESSION[
"takeposcustomercurrency"])) {
170 if ($invoice->multicurrency_code != $_SESSION[
"takeposcustomercurrency"]) {
171 $invoice->setMulticurrencyCode($_SESSION[
"takeposcustomercurrency"]);
175$term = empty($_SESSION[
"takeposterminal"]) ? 1 : $_SESSION[
"takeposterminal"];
182$parameters = array();
183$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $invoice, $action);
188if (empty($reshook)) {
190 if ($action ==
'valid' && $user->hasRight(
'facture',
'creer')) {
198 $bankaccount =
getDolGlobalInt(
'CASHDESK_ID_BANKACCOUNT_CASH'.$_SESSION[
"takeposterminal"]);
199 } elseif ($pay ==
"CHQ") {
200 $bankaccount =
getDolGlobalInt(
'CASHDESK_ID_BANKACCOUNT_CHEQUE'.$_SESSION[
"takeposterminal"]);
202 $accountname =
"CASHDESK_ID_BANKACCOUNT_".$pay.$_SESSION[
"takeposterminal"];
207 if ($bankaccount <= 0 && $pay !=
"delayed" && isModEnabled(
"bank")) {
208 $errormsg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"BankAccount"));
216 $invoice->fetch($placeid);
220 if ($invoice->total_ttc < 0) {
221 $invoice->type = $invoice::TYPE_CREDIT_NOTE;
223 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"facture";
224 $sql .=
" WHERE entity IN (".getEntity(
'invoice').
")";
225 $sql .=
" AND fk_soc = ".((int) $invoice->socid);
226 $sql .=
" AND type <> ".Facture::TYPE_CREDIT_NOTE;
227 $sql .=
" AND fk_statut >= ".$invoice::STATUS_VALIDATED;
228 $sql .=
" ORDER BY rowid DESC";
230 $resql = $db->query($sql);
232 $obj = $db->fetch_object($resql);
233 $fk_source = $obj->rowid;
234 if ($fk_source ==
null) {
235 fail($langs->transnoentitiesnoconv(
"NoPreviousBillForCustomer"));
238 fail($langs->transnoentitiesnoconv(
"NoPreviousBillForCustomer"));
240 $invoice->fk_facture_source = $fk_source;
241 $invoice->update($user);
244 $constantforkey =
'CASHDESK_NO_DECREASE_STOCK'.(isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
251 if ($invoice->getRemainToPay() > 0) {
257 } elseif (count($invoice->lines) == 0) {
261 } elseif (isModEnabled(
'stock') && !isModEnabled(
'productbatch') && $allowstockchange) {
266 $conf->global->STOCK_CALCULATE_ON_BILL = 1;
268 $constantforkey =
'CASHDESK_ID_WAREHOUSE'.(isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
269 dol_syslog(
"Validate invoice with stock change. Warehouse defined into constant ".$constantforkey.
" = ".
getDolGlobalString($constantforkey));
274 $res = $invoice->validate($user,
'',
getDolGlobalInt($constantforkey), 0, $batch_rule);
277 $conf->global->STOCK_CALCULATE_ON_BILL = $savconst;
280 $res = $invoice->validate($user);
283 $langs->load(
"admin");
284 dol_htmloutput_errors($invoice->error ==
'NotConfigured' ? $langs->trans(
"NotConfigured").
' (TakePos numbering module)' : $invoice->error, $invoice->errors, 1);
289 if (!$error && $res >= 0) {
290 $remaintopay = $invoice->getRemainToPay();
291 if ($remaintopay > 0) {
294 $payment->datepaye = $now;
295 $payment->fk_account = $bankaccount;
300 $payment->amounts[$invoice->id] = $amountofpayment;
303 if ($amountofpayment <= 0 || $amountofpayment > $remaintopay) {
304 $payment->amounts[$invoice->id] = $remaintopay;
308 $payment->paiementid = $paiementid;
309 $payment->num_payment = $invoice->ref;
311 if ($pay !=
"delayed") {
312 $res = $payment->create($user);
318 $res = $payment->addPaymentToBank($user,
'payment',
'(CustomerInvoicePayment)', $bankaccount,
'',
'');
321 dol_htmloutput_errors($langs->trans(
'ErrorNoPaymentDefined').
' '.$payment->error, $payment->errors, 1);
323 $remaintopay = $invoice->getRemainToPay();
329 if ($remaintopay == 0) {
330 dol_syslog(
"Invoice is paid, so we set it to status Paid");
331 $result = $invoice->setPaid($user);
334 $invoice->status = $invoice::STATUS_CLOSED;
337 $invoice->setPaymentMethods($paiementid);
339 dol_syslog(
"Invoice is not paid, remain to pay = ".$remaintopay);
346 if (!$error && $res >= 0) {
347 if (isModEnabled(
'stock') && isModEnabled(
'productbatch') && $allowstockchange) {
349 dol_syslog(
"Now we record the stock movement for each qualified line");
352 require_once DOL_DOCUMENT_ROOT .
"/product/stock/class/mouvementstock.class.php";
353 $constantforkey =
'CASHDESK_ID_WAREHOUSE'.$_SESSION[
"takeposterminal"];
356 $labeltakeposmovement =
'TakePOS - '.$langs->trans(
"Invoice").
' '.$invoice->ref;
358 foreach ($invoice->lines as $line) {
360 $warehouseid = ($line->fk_warehouse ? $line->fk_warehouse :
getDolGlobalInt($constantforkey));
363 if ($line->batch !=
'' && $warehouseid > 0) {
365 $prod_batch->find(0,
'',
'', $line->batch, $warehouseid);
368 $mouvP->setOrigin($invoice->element, $invoice->id);
370 $res = $mouvP->livraison($user, $line->fk_product, $warehouseid, $line->qty, $line->price, $labeltakeposmovement,
'',
'',
'', $prod_batch->batch, $prod_batch->id, $inventorycode);
377 $mouvP->setOrigin($invoice->element, $invoice->id);
379 $res = $mouvP->livraison($user, $line->fk_product, $warehouseid, $line->qty, $line->price, $labeltakeposmovement,
'',
'',
'',
'', 0, $inventorycode);
389 if (!$error && $res >= 0) {
395 if ($action ==
'creditnote' && $user->hasRight(
'facture',
'creer')) {
398 $creditnote =
new Facture($db);
399 $creditnote->socid = $invoice->socid;
401 $creditnote->module_source =
'takepos';
402 $creditnote->pos_source = isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'' ;
404 $creditnote->fk_facture_source = $placeid;
407 $creditnote->create($user);
411 foreach ($invoice->lines as $line) {
413 if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) {
418 if (!empty($invoice->situation_counter)) {
419 $source_fk_prev_id = $line->fk_prev_id;
420 $line->fk_prev_id = $line->id;
421 if (!empty($invoice->tab_previous_situation_invoice)) {
424 $tab_jumped_credit_notes = array();
425 $lineIndex = count($invoice->tab_previous_situation_invoice) - 1;
426 $searchPreviousInvoice =
true;
427 while ($searchPreviousInvoice) {
428 if ($invoice->tab_previous_situation_invoice[$lineIndex]->situation_cycle_ref || $lineIndex < 1) {
429 $searchPreviousInvoice =
false;
433 $tab_jumped_credit_notes[$lineIndex] = $invoice->tab_previous_situation_invoice[$lineIndex]->id;
439 $maxPrevSituationPercent = 0;
440 foreach ($invoice->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine) {
441 if ($prevLine->id == $source_fk_prev_id) {
442 $maxPrevSituationPercent = max($maxPrevSituationPercent, $prevLine->situation_percent);
445 $line->total_ht -= $prevLine->total_ht;
446 $line->total_tva -= $prevLine->total_tva;
447 $line->total_ttc -= $prevLine->total_ttc;
448 $line->total_localtax1 -= $prevLine->total_localtax1;
449 $line->total_localtax2 -= $prevLine->total_localtax2;
451 $line->multicurrency_subprice -= $prevLine->multicurrency_subprice;
452 $line->multicurrency_total_ht -= $prevLine->multicurrency_total_ht;
453 $line->multicurrency_total_tva -= $prevLine->multicurrency_total_tva;
454 $line->multicurrency_total_ttc -= $prevLine->multicurrency_total_ttc;
459 $line->situation_percent = $maxPrevSituationPercent - $line->situation_percent;
464 $maxPrevSituationPercent = 0;
465 foreach ($tab_jumped_credit_notes as $index => $creditnoteid) {
466 foreach ($invoice->tab_previous_situation_invoice[$index]->lines as $prevLine) {
467 if ($prevLine->fk_prev_id == $source_fk_prev_id) {
468 $maxPrevSituationPercent = $prevLine->situation_percent;
470 $line->total_ht -= $prevLine->total_ht;
471 $line->total_tva -= $prevLine->total_tva;
472 $line->total_ttc -= $prevLine->total_ttc;
473 $line->total_localtax1 -= $prevLine->total_localtax1;
474 $line->total_localtax2 -= $prevLine->total_localtax2;
476 $line->multicurrency_subprice -= $prevLine->multicurrency_subprice;
477 $line->multicurrency_total_ht -= $prevLine->multicurrency_total_ht;
478 $line->multicurrency_total_tva -= $prevLine->multicurrency_total_tva;
479 $line->multicurrency_total_ttc -= $prevLine->multicurrency_total_ttc;
485 $line->situation_percent += $maxPrevSituationPercent;
493 $line->fk_facture = $creditnote->id;
494 $line->fk_parent_line = $fk_parent_line;
496 $line->subprice = -$line->subprice;
498 $line->total_ht = -$line->total_ht;
499 $line->total_tva = -$line->total_tva;
500 $line->total_ttc = -$line->total_ttc;
501 $line->total_localtax1 = -$line->total_localtax1;
502 $line->total_localtax2 = -$line->total_localtax2;
504 $line->multicurrency_subprice = -$line->multicurrency_subprice;
505 $line->multicurrency_total_ht = -$line->multicurrency_total_ht;
506 $line->multicurrency_total_tva = -$line->multicurrency_total_tva;
507 $line->multicurrency_total_ttc = -$line->multicurrency_total_ttc;
509 $result = $line->insert(0, 1);
511 $creditnote->lines[] = $line;
514 if ($result > 0 && $line->product_type == 9) {
515 $fk_parent_line = $result;
518 $creditnote->update_price(1);
522 $constantforkey =
'CASHDESK_NO_DECREASE_STOCK'.(isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
525 if (isModEnabled(
'stock') && !isModEnabled(
'productbatch') && $allowstockchange) {
529 $conf->global->STOCK_CALCULATE_ON_BILL = 1;
531 $constantforkey =
'CASHDESK_ID_WAREHOUSE'.(isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
533 dol_syslog(
"Validate invoice with stock change into warehouse defined into constant ".$constantforkey.
" = ".
getDolGlobalString($constantforkey).
" or warehouseid= ".$warehouseid.
" if defined.");
538 $res = $creditnote->validate($user,
'',
getDolGlobalString($constantforkey), 0, $batch_rule);
545 $conf->global->STOCK_CALCULATE_ON_BILL = $savconst;
547 $res = $creditnote->validate($user);
551 if (!$error && $res >= 0) {
552 if (isModEnabled(
'stock') && isModEnabled(
'productbatch') && $allowstockchange) {
554 dol_syslog(
"Now we record the stock movement for each qualified line");
557 require_once DOL_DOCUMENT_ROOT .
"/product/stock/class/mouvementstock.class.php";
558 $constantforkey =
'CASHDESK_ID_WAREHOUSE'.$_SESSION[
"takeposterminal"];
561 $labeltakeposmovement =
'TakePOS - '.$langs->trans(
"CreditNote").
' '.$creditnote->ref;
563 foreach ($creditnote->lines as $line) {
565 $warehouseid = ($line->fk_warehouse ? $line->fk_warehouse :
getDolGlobalInt($constantforkey));
568 if ($line->batch !=
'' && $warehouseid > 0) {
573 $mouvP->setOrigin($creditnote->element, $creditnote->id);
575 $res = $mouvP->reception($user, $line->fk_product, $warehouseid, $line->qty, $line->price, $labeltakeposmovement,
'',
'', $line->batch,
'', 0, $inventorycode);
582 $mouvP->setOrigin($creditnote->element, $creditnote->id);
584 $res = $mouvP->reception($user, $line->fk_product, $warehouseid, $line->qty, $line->price, $labeltakeposmovement,
'',
'',
'',
'', 0, $inventorycode);
594 if (!$error && $res >= 0) {
597 $creditnote->id = $placeid;
602 if (($action ==
'history' || $action ==
'creditnote') && $user->hasRight(
'takepos',
'run')) {
603 if ($action ==
'creditnote' && $creditnote->id > 0) {
604 $placeid = $creditnote->id;
610 $invoice->fetch($placeid);
614 if (($action ==
"addline" || $action ==
"freezone") && $placeid == 0 && ($user->hasRight(
'takepos',
'run') || defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
617 include_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
620 $invoice->module_source =
'takepos';
621 $invoice->pos_source = isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'' ;
622 $invoice->entity = !empty($_SESSION[
"takeposinvoiceentity"]) ? $_SESSION[
"takeposinvoiceentity"] :
$conf->entity;
624 if ($invoice->socid <= 0) {
625 $langs->load(
'errors');
631 $placeid = $invoice->create($user);
635 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facture";
636 $sql .=
" SET ref='(PROV-POS".$_SESSION[
"takeposterminal"].
"-".$place.
")'";
637 $sql .=
" WHERE rowid = ".((int) $placeid);
638 $resql = $db->query($sql);
652 if ($action ==
"addline" && ($user->hasRight(
'takepos',
'run') || defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
654 $prod->fetch($idproduct);
657 $customer->fetch($invoice->socid);
659 $datapriceofproduct = $prod->getSellPrice($mysoc, $customer, 0);
662 $price = $datapriceofproduct[
'pu_ht'];
663 $price_ttc = $datapriceofproduct[
'pu_ttc'];
665 $price_base_type = empty($datapriceofproduct[
'price_base_type']) ?
'HT' : $datapriceofproduct[
'price_base_type'];
666 $tva_tx = $datapriceofproduct[
'tva_tx'];
667 $tva_npr = $datapriceofproduct[
'tva_npr'];
670 $localtax1_tx =
get_localtax($tva_tx, 1, $customer, $mysoc, $tva_npr);
671 $localtax2_tx =
get_localtax($tva_tx, 2, $customer, $mysoc, $tva_npr);
674 if (isModEnabled(
'productbatch') && isModEnabled(
'stock')) {
675 $batch =
GETPOST(
'batch',
'alpha');
677 if (!empty($batch)) {
678 $action =
"setbatch";
679 } elseif ($prod->status_batch > 0) {
684 $prod->load_stock(
'warehouseopen');
686 $constantforkey =
'CASHDESK_ID_WAREHOUSE'.$_SESSION[
"takeposterminal"];
690 foreach ($prod->stock_warehouse as $tmpwarehouseid => $tmpval) {
695 if (!empty($prod->stock_warehouse[$tmpwarehouseid]) && is_array($prod->stock_warehouse[$tmpwarehouseid]->detail_batch)) {
696 if (is_object($prod->stock_warehouse[$tmpwarehouseid]) && count($prod->stock_warehouse[$tmpwarehouseid]->detail_batch)) {
697 foreach ($prod->stock_warehouse[$tmpwarehouseid]->detail_batch as $dbatch) {
706 echo
"function addbatch(batch, warehouseid) {\n";
707 echo
"console.log('We add batch '+batch+' from warehouse id '+warehouseid);\n";
708 echo
'$("#poslines").load("'.DOL_URL_ROOT.
'/takepos/invoice.php?action=addline&batch="+encodeURI(batch)+"&warehouseid="+warehouseid+"&place='.$place.
'&idproduct='.$idproduct.
'&token='.
newToken().
'", function() {});'.
"\n";
713 echo
"<center>".$langs->trans(
"SearchIntoBatch").
": <b> $nbofsuggested </b></center><br><table>";
714 foreach ($prod->stock_warehouse as $tmpwarehouseid => $tmpval) {
719 if (!empty($prod->stock_warehouse[$tmpwarehouseid]) && is_array($prod->stock_warehouse[$tmpwarehouseid]->detail_batch)) {
720 foreach ($prod->stock_warehouse[$tmpwarehouseid]->detail_batch as $dbatch) {
721 $batchStock = + $dbatch->qty;
722 $quantityToBeDelivered = 1;
723 $deliverableQty = min($quantityToBeDelivered, $batchStock);
725 print
'<!-- subj='.$suggestednb.
'/'.$nbofsuggested.
' -->';
726 print
'<!-- Show details of lot/serial in warehouseid='.$tmpwarehouseid.
' -->';
727 print
'<td class="left">';
729 $detail .=
'<span class="opacitymedium">'.$langs->trans(
"LotSerial").
':</span> '.$dbatch->batch;
736 $detail .=
'</td><td>';
737 $detail .=
'<span class="opacitymedium">'.$langs->trans(
"Qty").
':</span> '.$dbatch->qty;
738 $detail .=
'</td><td>';
739 $detail .=
' <button class="marginleftonly" onclick="addbatch(\''.dol_escape_js($dbatch->batch).
'\',
'.$tmpwarehouseid.')
">'.$langs->trans("Select
")."</
button>
";
743 $quantityToBeDelivered -= $deliverableQty;
744 if ($quantityToBeDelivered < 0) {
745 $quantityToBeDelivered = 0;
754 print '</body></html>';
760 if (getDolGlobalString('TAKEPOS_SUPPLEMENTS')) {
761 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
762 $cat = new Categorie($db);
763 $categories = $cat->containing($idproduct, 'product');
764 $found = (array_search(getDolGlobalInt('TAKEPOS_SUPPLEMENTS_CATEGORY'), array_column($categories, 'id')));
765 if ($found !== false) { // If this product is a supplement
766 $sql = "SELECT fk_parent_line FROM
".MAIN_DB_PREFIX."facturedet where rowid =
".((int) $selectedline);
767 $resql = $db->query($sql);
768 $row = $db->fetch_array($resql);
769 if ($row[0] == null) {
770 $parent_line = $selectedline;
772 $parent_line = $row[0]; //If the parent line is already a supplement, add the supplement to the main product
779 // Group if enabled. Skip group if line already sent to the printer
780 if (getDolGlobalString('TAKEPOS_GROUP_SAME_PRODUCT')) {
781 foreach ($invoice->lines as $line) {
782 if ($line->product_ref == $prod->ref) {
783 if ($line->special_code == 4) {
785 } // If this line is sended to printer create new line
786 // check if qty in stock
787 if (getDolGlobalString('TAKEPOS_QTY_IN_STOCK') && (($line->qty + $qty) > $prod->stock_reel)) {
788 $invoice->error = $langs->trans("ErrorStockIsNotEnough
");
789 dol_htmloutput_errors($invoice->error, $invoice->errors, 1);
793 $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);
795 dol_htmloutput_errors($invoice->error, $invoice->errors, 1);
797 $idoflineadded = $line->id;
803 if ($idoflineadded <= 0 && empty($err)) {
804 $invoice->fetch_thirdparty();
805 $array_options = array();
807 $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);
809 /* setup of margin calculation */
810 if (getDolGlobalString('MARGIN_TYPE')) {
811 if (getDolGlobalString('MARGIN_TYPE') == 'pmp' && !empty($prod->pmp)) {
812 $line['fk_fournprice'] = null;
813 $line['pa_ht'] = $prod->pmp;
814 } elseif (getDolGlobalString('MARGIN_TYPE') == 'costprice' && !empty($prod->cost_price)) {
815 $line['fk_fournprice'] = null;
816 $line['pa_ht'] = $prod->cost_price;
818 // default is fournprice
819 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
820 $pf = new ProductFournisseur($db);
821 if ($pf->find_min_price_product_fournisseur($idproduct, $qty) > 0) {
822 $line['fk_fournprice'] = $pf->product_fourn_price_id;
823 $line['pa_ht'] = $pf->fourn_unitprice_with_discount;
824 if (getDolGlobalString('PRODUCT_CHARGES') && $pf->fourn_charges > 0) {
825 $line['pa_ht'] += (float) $pf->fourn_charges / $pf->fourn_qty;
831 // complete line by hook
832 $parameters = array('prod' => $prod, 'line' => $line);
833 $reshook = $hookmanager->executeHooks('completeTakePosAddLine', $parameters, $invoice, $action); // Note that $action and $line may have been modified by some hooks
835 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
839 if (empty($reshook)) {
840 if (!empty($hookmanager->resArray)) {
841 $line = $hookmanager->resArray;
844 // check if qty in stock
845 if (getDolGlobalString('TAKEPOS_QTY_IN_STOCK') && $qty > $prod->stock_reel) {
846 $invoice->error = $langs->trans("ErrorStockIsNotEnough
");
847 dol_htmloutput_errors($invoice->error, $invoice->errors, 1);
852 $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);
856 if (getDolGlobalString('TAKEPOS_CUSTOMER_DISPLAY')) {
857 $CUSTOMER_DISPLAY_line1 = $prod->label;
858 $CUSTOMER_DISPLAY_line2 = price($price_ttc);
862 $invoice->fetch($placeid);
865 // If we add a line by submitting freezone form (invoice exists here because it was created juste before if it didn't exists)
866 if ($action == "freezone
" && $user->hasRight('takepos', 'run')) {
867 $customer = new Societe($db);
868 $customer->fetch($invoice->socid);
870 $tva_tx = GETPOST('tva_tx', 'alpha');
872 if (!preg_match('/\((.*)\)/', $tva_tx)) {
873 $tva_tx = price2num($tva_tx);
876 $tva_tx = get_default_tva($mysoc, $customer);
880 $localtax1_tx = get_localtax($tva_tx, 1, $customer, $mysoc, $tva_npr);
881 $localtax2_tx = get_localtax($tva_tx, 2, $customer, $mysoc, $tva_npr);
883 $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);
885 dol_htmloutput_errors($invoice->error, $invoice->errors, 1);
887 $invoice->fetch($placeid);
890 if ($action == "addnote
" && ($user->hasRight('takepos', 'run') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
891 $desc = GETPOST('addnote', 'alpha');
893 $invoice->update_note($desc, '_public');
895 foreach ($invoice->lines as $line) {
896 if ($line->id == $idline) {
897 $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);
901 $invoice->fetch($placeid);
904 if ($action == "deleteline
" && ($user->hasRight('takepos', 'run') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
906 $permissiontoupdateline = ($user->hasRight('takepos', 'editlines') && ($user->hasRight('takepos', 'editorderedlines') || $line->special_code != "4
"));
907 if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
908 if ($invoice->status == $invoice::STATUS_DRAFT && $invoice->pos_source && $invoice->module_source == 'takepos') {
909 $permissiontoupdateline = true;
910 // TODO Add also a test on $_SESSION('publicobjectid'] defined at creation of object
911 // TODO Check also that invoice->ref is (PROV-POS1-2) with 1 = terminal and 2, the table ID
915 if ($idline > 0 && $placeid > 0) { // If invoice exists and line selected. To avoid errors if deleted from another device or no line selected.
916 $invoice->deleteLine($idline);
917 $invoice->fetch($placeid);
918 } elseif ($placeid > 0) { // If invoice exists but no line selected, proceed to delete last line.
919 $sql = "SELECT rowid FROM
".MAIN_DB_PREFIX."facturedet where fk_facture =
".((int) $placeid)." ORDER BY rowid DESC
";
920 $resql = $db->query($sql);
921 $row = $db->fetch_array($resql);
922 $deletelineid = $row[0];
923 $invoice->deleteLine($deletelineid);
924 $invoice->fetch($placeid);
927 if (count($invoice->lines) == 0) {
928 $invoice->delete($user);
930 if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
931 header("Location:
".DOL_URL_ROOT."/takepos/public/auto_order.php
");
933 header("Location:
".DOL_URL_ROOT."/takepos/invoice.php
");
939 // Action to delete or discard an invoice
940 if ($action == "delete
" && ($user->hasRight('takepos', 'run') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
941 // $placeid is the invoice id (it differs from place) and is defined if the place is set and
942 // the ref of invoice is '(PROV-POS'.$_SESSION["takeposterminal
"].'-'.$place.')', so the fetch at beginning of page works.
944 $result = $invoice->fetch($placeid);
946 if ($result > 0 && $invoice->status == Facture::STATUS_DRAFT) {
949 // We delete the lines
951 foreach ($invoice->lines as $line) {
952 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
953 $tmpres = $invoice->deleteLine($line->id);
960 $sql = "UPDATE
".MAIN_DB_PREFIX."facture
";
961 $varforconst = 'CASHDESK_ID_THIRDPARTY'.$_SESSION["takeposterminal
"];
962 $sql .= " SET fk_soc =
".((int) getDolGlobalString($varforconst)).",
";
963 $sql .= " datec =
'".$db->idate(dol_now())."'";
964 $sql .= " WHERE entity IN (
".getEntity('invoice').")
";
965 $sql .= " AND
ref =
'(PROV-POS".$db->escape($_SESSION["takeposterminal"]."-".$place).")'";
966 $resql1 = $db->query($sql);
968 if ($resdeletelines && $resql1) {
974 $invoice->fetch($placeid);
979 if ($action == "updateqty
") { // Test on permission is done later
980 foreach ($invoice->lines as $line) {
981 if ($line->id == $idline) {
982 $permissiontoupdateline = ($user->hasRight('takepos', 'editlines') && ($user->hasRight('takepos', 'editorderedlines') || $line->special_code != "4
"));
983 if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
984 if ($invoice->status == $invoice::STATUS_DRAFT && $invoice->pos_source && $invoice->module_source == 'takepos') {
985 $permissiontoupdateline = true;
986 // TODO Add also a test on $_SESSION('publicobjectid'] defined at creation of object
987 // TODO Check also that invoice->ref is (PROV-POS1-2) with 1 = terminal and 2, the table ID
990 if (!$permissiontoupdateline) {
991 dol_htmloutput_errors($langs->trans("NotEnoughPermissions
", "TakePos
").' - No permission to updateqty', [], 1);
993 $vatratecode = $line->tva_tx;
994 if ($line->vat_src_code) {
995 $vatratecode .= ' ('.$line->vat_src_code.')';
998 $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);
1003 $invoice->fetch($placeid);
1006 if ($action == "updateprice
") { // Test on permission is done later
1007 $customer = new Societe($db);
1008 $customer->fetch($invoice->socid);
1010 foreach ($invoice->lines as $line) {
1011 if ($line->id == $idline) {
1012 $prod = new Product($db);
1013 $prod->fetch($line->fk_product);
1014 $datapriceofproduct = $prod->getSellPrice($mysoc, $customer, 0);
1015 $price_min = $datapriceofproduct['price_min'];
1016 $usercanproductignorepricemin = ((getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !$user->hasRight('produit', 'ignore_price_min_advance')) || !getDolGlobalString('MAIN_USE_ADVANCED_PERMS'));
1018 $vatratecleaned = $line->tva_tx;
1020 if (preg_match('/^(.*)\s*\((.*)\)$/', (string) $line->tva_tx, $reg)) { // If vat is "xx (yy)
"
1021 $vatratecleaned = trim($reg[1]);
1022 //$vatratecode = $reg[2];
1025 $pu_ht = price2num((float) price2num($number, 'MU') / (1 + ((float) $vatratecleaned / 100)), 'MU');
1027 if ($usercanproductignorepricemin && (!empty($price_min) && ((float) price2num($pu_ht) * (1 - (float) price2num($line->remise_percent) / 100) < price2num($price_min)))) {
1028 $langs->load("products
");
1029 dol_htmloutput_errors($langs->trans("CantBeLessThanMinPrice
", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, -1, $conf->currency)));
1030 // echo $langs->trans("CantBeLessThanMinPrice
");
1032 $permissiontoupdateline = ($user->hasRight('takepos', 'editlines') && ($user->hasRight('takepos', 'editorderedlines') || $line->special_code != "4
"));
1033 if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1034 if ($invoice->status == $invoice::STATUS_DRAFT && $invoice->pos_source && $invoice->module_source == 'takepos') {
1035 $permissiontoupdateline = true;
1036 // TODO Add also a test on $_SESSION('publicobjectid'] defined at creation of object
1037 // TODO Check also that invoice->ref is (PROV-POS1-2) with 1 = terminal and 2, the table ID
1041 $vatratecode = $line->tva_tx;
1042 if ($line->vat_src_code) {
1043 $vatratecode .= ' ('.$line->vat_src_code.')';
1046 if (!$permissiontoupdateline) {
1047 dol_htmloutput_errors($langs->trans("NotEnoughPermissions
", "TakePos
").' - No permission to updateprice', [], 1);
1048 } elseif (getDolGlobalInt('TAKEPOS_CHANGE_PRICE_HT') == 1) {
1049 $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);
1051 $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);
1058 $invoice->fetch($placeid);
1061 if ($action == "updatereduction
") { // Test on permission is done later
1062 $customer = new Societe($db);
1063 $customer->fetch($invoice->socid);
1065 foreach ($invoice->lines as $line) {
1066 if ($line->id == $idline) {
1067 dol_syslog("updatereduction Process line
".$line->id.' to apply discount of '.$number.'%');
1069 $prod = new Product($db);
1070 $prod->fetch($line->fk_product);
1072 $datapriceofproduct = $prod->getSellPrice($mysoc, $customer, 0);
1073 $price_min = $datapriceofproduct['price_min'];
1074 $usercanproductignorepricemin = ((getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !$user->hasRight('produit', 'ignore_price_min_advance')) || !getDolGlobalString('MAIN_USE_ADVANCED_PERMS'));
1076 $pu_ht = price2num($line->subprice / (1 + ($line->tva_tx / 100)), 'MU');
1079 if ($usercanproductignorepricemin && (!empty($price_min) && ((float) price2num($line->subprice) * (1 - (float) price2num($number) / 100) < (float) price2num($price_min)))) {
1080 $langs->load("products
");
1081 dol_htmloutput_errors($langs->trans("CantBeLessThanMinPrice
", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, -1, $conf->currency)));
1083 $permissiontoupdateline = ($user->hasRight('takepos', 'editlines') && ($user->hasRight('takepos', 'editorderedlines') || $line->special_code != "4
"));
1084 if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1085 if ($invoice->status == $invoice::STATUS_DRAFT && $invoice->pos_source && $invoice->module_source == 'takepos') {
1086 $permissiontoupdateline = true;
1087 // TODO Add also a test on $_SESSION('publicobjectid'] defined at creation of object
1088 // TODO Check also that invoice->ref is (PROV-POS1-2) with 1 = terminal and 2, the table ID
1091 if (!$permissiontoupdateline) {
1092 dol_htmloutput_errors($langs->trans("NotEnoughPermissions
", "TakePos
"), [], 1);
1094 $vatratecode = $line->tva_tx;
1095 if ($line->vat_src_code) {
1096 $vatratecode .= ' ('.$line->vat_src_code.')';
1098 $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);
1105 $invoice->fetch($placeid);
1106 } elseif ($action == 'update_reduction_global' && $user->hasRight('takepos', 'editlines')) {
1107 foreach ($invoice->lines as $line) {
1108 $vatratecode = $line->tva_tx;
1109 if ($line->vat_src_code) {
1110 $vatratecode .= ' ('.$line->vat_src_code.')';
1112 $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);
1115 $invoice->fetch($placeid);
1118 if ($action == "setbatch
" && ($user->hasRight('takepos', 'run') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
1119 $constantforkey = 'CASHDESK_ID_WAREHOUSE'.$_SESSION["takeposterminal
"];
1120 $warehouseid = (GETPOSTINT('warehouseid') > 0 ? GETPOSTINT('warehouseid') : getDolGlobalInt($constantforkey)); // Get the warehouse id from GETPOSTINT('warehouseid'), otherwise use default setup.
1121 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet SET batch =
'".$db->escape($batch)."', fk_warehouse =
".((int) $warehouseid);
1122 $sql .= " WHERE rowid=
".((int) $idoflineadded);
1126 if ($action == "order
" && $placeid != 0 && ($user->hasRight('takepos', 'run') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
1127 include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
1128 if ((isModEnabled('receiptprinter') && getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term) > 0) || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter
" || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector
") {
1129 require_once DOL_DOCUMENT_ROOT.'/core/class/dolreceiptprinter.class.php';
1130 $printer = new dolReceiptPrinter($db);
1133 $sql = "SELECT label FROM
".MAIN_DB_PREFIX."takepos_floor_tables where rowid=
".((int) $place);
1134 $resql = $db->query($sql);
1135 $row = $db->fetch_object($resql);
1136 $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>';
1137 $footerorder = '</tbody></table>'.dol_print_date(dol_now(), 'dayhour').'<br></html>';
1138 $order_receipt_printer1 = "";
1139 $order_receipt_printer2 = "";
1140 $order_receipt_printer3 = "";
1141 $catsprinter1 = explode(';', getDolGlobalString('TAKEPOS_PRINTED_CATEGORIES_1'));
1142 $catsprinter2 = explode(';', getDolGlobalString('TAKEPOS_PRINTED_CATEGORIES_2'));
1143 $catsprinter3 = explode(';', getDolGlobalString('TAKEPOS_PRINTED_CATEGORIES_3'));
1145 foreach ($invoice->lines as $line) {
1146 if ($line->special_code == "4
") {
1149 $c = new Categorie($db);
1150 $existing = $c->containing($line->fk_product, Categorie::TYPE_PRODUCT, 'id');
1151 $result = array_intersect($catsprinter1, $existing);
1152 $count = count($result);
1153 if (!$line->fk_product) {
1154 $count++; // Print Free-text item (Unassigned printer) to Printer 1
1158 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet set special_code=
'1' where rowid=
".$line->id; //Set to print on printer 1
1160 $order_receipt_printer1 .= '<tr><td class="left
">';
1161 if ($line->fk_product) {
1162 $order_receipt_printer1 .= $line->product_label;
1164 $order_receipt_printer1 .= $line->description;
1166 $order_receipt_printer1 .= '</td><td class="right
">'.$line->qty;
1167 if (!empty($line->array_options['options_order_notes'])) {
1168 $order_receipt_printer1 .= "<br>(
".$line->array_options['options_order_notes'].")
";
1170 $order_receipt_printer1 .= '</td></tr>';
1173 if (((isModEnabled('receiptprinter') && getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term) > 0) || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter
" || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector
") && $linestoprint > 0) {
1174 $invoice->fetch($placeid); //Reload object before send to printer
1175 $printer->orderprinter = 1;
1177 echo "var orderprinter1esc=
'";
1178 $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
1181 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet
set special_code=
'4' where special_code=
'1' and fk_facture=
".$invoice->id; // Set as printed
1183 $invoice->fetch($placeid); //Reload object after set lines as printed
1186 foreach ($invoice->lines as $line) {
1187 if ($line->special_code == "4
") {
1190 $c = new Categorie($db);
1191 $existing = $c->containing($line->fk_product, Categorie::TYPE_PRODUCT, 'id');
1192 $result = array_intersect($catsprinter2, $existing);
1193 $count = count($result);
1196 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet
set special_code=
'2' where rowid=
".$line->id; //Set to print on printer 2
1198 $order_receipt_printer2 .= '<tr>'.$line->product_label.'<td class="right
">'.$line->qty;
1199 if (!empty($line->array_options['options_order_notes'])) {
1200 $order_receipt_printer2 .= "<br>(
".$line->array_options['options_order_notes'].")
";
1202 $order_receipt_printer2 .= '</td></tr>';
1205 if (((isModEnabled('receiptprinter') && getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term) > 0) || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter
" || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector
") && $linestoprint > 0) {
1206 $invoice->fetch($placeid); //Reload object before send to printer
1207 $printer->orderprinter = 2;
1209 echo "var orderprinter2esc=
'";
1210 $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
1213 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet
set special_code=
'4' where special_code=
'2' and fk_facture=
".$invoice->id; // Set as printed
1215 $invoice->fetch($placeid); //Reload object after set lines as printed
1218 foreach ($invoice->lines as $line) {
1219 if ($line->special_code == "4
") {
1222 $c = new Categorie($db);
1223 $existing = $c->containing($line->fk_product, Categorie::TYPE_PRODUCT, 'id');
1224 $result = array_intersect($catsprinter3, $existing);
1225 $count = count($result);
1228 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet
set special_code=
'3' where rowid=
".$line->id; //Set to print on printer 3
1230 $order_receipt_printer3 .= '<tr>'.$line->product_label.'<td class="right
">'.$line->qty;
1231 if (!empty($line->array_options['options_order_notes'])) {
1232 $order_receipt_printer3 .= "<br>(
".$line->array_options['options_order_notes'].")
";
1234 $order_receipt_printer3 .= '</td></tr>';
1237 if (((isModEnabled('receiptprinter') && getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term) > 0) || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter
" || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector
") && $linestoprint > 0) {
1238 $invoice->fetch($placeid); //Reload object before send to printer
1239 $printer->orderprinter = 3;
1241 echo "var orderprinter3esc=
'";
1242 $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
1245 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet
set special_code=
'4' where special_code=
'3' and fk_facture=
".$invoice->id; // Set as printed
1247 $invoice->fetch($placeid); //Reload object after set lines as printed
1250 $sectionwithinvoicelink = '';
1251 if (($action == "valid
" || $action == "history
" || $action == 'creditnote') && $user->hasRight('takepos', 'run')) {
1252 $sectionwithinvoicelink .= '<!-- Section with invoice link -->'."\n
";
1253 $sectionwithinvoicelink .= '<span style="font-size:120%;
" class="center
">';
1254 $sectionwithinvoicelink .= $invoice->getNomUrl(1, '', 0, 0, '', 0, 0, -1, '_backoffice')." -
";
1255 $remaintopay = $invoice->getRemainToPay();
1256 if ($remaintopay > 0) {
1257 $sectionwithinvoicelink .= $langs->trans('RemainToPay').': <span class="amountremaintopay
" style="font-size: unset
">'.price($remaintopay, 1, $langs, 1, -1, -1, $conf->currency).'</span>';
1259 if ($invoice->paye) {
1260 $sectionwithinvoicelink .= '<span class="amountpaymentcomplete
" style="font-size: unset
">'.$langs->trans("Paid
").'</span>';
1262 $sectionwithinvoicelink .= $langs->trans('BillShortStatusValidated');
1266 $sectionwithinvoicelink .= '</span><br>';
1267 if (getDolGlobalInt('TAKEPOS_PRINT_INVOICE_DOC_INSTEAD_OF_RECEIPT')) {
1268 $sectionwithinvoicelink .= ' <a target="_blank
" class="button" href="' . DOL_URL_ROOT . '/document.php?token=
' . newToken() . '&modulepart=facture&file=
' . $invoice->ref . '/
' . $invoice->ref . '.pdf
">Invoice</a>';
1269 } elseif (getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector
") {
1270 if (getDolGlobalString('TAKEPOS_PRINT_SERVER') && filter_var(getDolGlobalString('TAKEPOS_PRINT_SERVER'), FILTER_VALIDATE_URL) == true) {
1271 $sectionwithinvoicelink .= ' <button id="buttonprint
" type="button" onclick="TakeposConnector(
'.$placeid.')
">'.$langs->trans('PrintTicket').'</button>';
1273 $sectionwithinvoicelink .= ' <button id="buttonprint
" type="button" onclick="TakeposPrinting(
'.$placeid.')
">'.$langs->trans('PrintTicket').'</button>';
1275 } elseif ((isModEnabled('receiptprinter') && getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term) > 0) || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter
") {
1276 $sectionwithinvoicelink .= ' <button id="buttonprint
" type="button" onclick="DolibarrTakeposPrinting(
'.$placeid.')
">'.$langs->trans('PrintTicket').'</button>';
1278 $sectionwithinvoicelink .= ' <button id="buttonprint
" type="button" onclick="Print(
'.$placeid.')
">'.$langs->trans('PrintTicket').'</button>';
1279 if (getDolGlobalString('TAKEPOS_PRINT_WITHOUT_DETAILS')) {
1280 $sectionwithinvoicelink .= ' <button id="buttonprint
" type="button" onclick="PrintBox(
'.$placeid.', \
'without_details\')">'.$langs->trans(
'PrintWithoutDetails').
'</button>';
1283 $sectionwithinvoicelink .=
' <button id="buttonprint" type="button" onclick="Print('.$placeid.
', 1)">'.$langs->trans(
'GiftReceipt').
'</button>';
1287 $sectionwithinvoicelink .=
' <button id="buttonsend" type="button" onclick="SendTicket('.$placeid.
')">'.$langs->trans(
'SendTicket').
'</button>';
1290 if ($remaintopay <= 0 &&
getDolGlobalString(
'TAKEPOS_AUTO_PRINT_TICKETS') && $action !=
"history") {
1291 $sectionwithinvoicelink .=
'<script type="text/javascript">$("#buttonprint").click();</script>';
1301$form =
new Form($db);
1304if ((
getDolGlobalString(
'TAKEPOS_PHONE_BASIC_LAYOUT') == 1 &&
$conf->browser->layout ==
'phone') || defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1305 $title =
'TakePOS - Dolibarr '.DOL_VERSION;
1309 $head =
'<meta name="apple-mobile-web-app-title" content="TakePOS"/>
1310 <meta name="apple-mobile-web-app-capable" content="yes">
1311 <meta name="mobile-web-app-capable" content="yes">
1312 <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>';
1313 $arrayofcss = array(
1314 '/takepos/css/pos.css.php',
1316 $arrayofjs = array(
'/takepos/js/jquery.colorbox-min.js');
1319 top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss);
1321 print
'<body>'.
"\n";
1328<script
type=
"text/javascript">
1331<?php
if ($action ==
"valid") {
1332 echo
"var place=0;";
1334var placeid=<?php echo($placeid > 0 ? $placeid : 0); ?>;
1335$(document).ready(
function() {
1336 var idoflineadded = <?php echo(empty($idoflineadded) ? 0 : $idoflineadded); ?>;
1338 $(
'.posinvoiceline').click(
function(){
1339 console.log(
"Click done on "+this.
id);
1340 $(
'.posinvoiceline').removeClass(
"selected");
1341 $(
this).addClass(
"selected");
1345 if (selectedline == this.
id) {
1348 selectedline = this.id;
1350 selectedtext=$(
'#'+selectedline).find(
"td:first").html();
1352 if (defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1353 print
'$("#phonediv1").load("'.DOL_URL_ROOT.
'/takepos/public/auto_order.php?action=editline&token='.
newToken().
'&placeid="+placeid+"&selectedline="+selectedline, function() {
1360 if (idoflineadded > 0)
1362 console.log(
"Auto select "+idoflineadded);
1363 $(
'.posinvoiceline#'+idoflineadded).click();
1367if ($action ==
"order" && !empty($order_receipt_printer1)) {
1368 if (filter_var(
getDolGlobalString(
'TAKEPOS_PRINT_SERVER'), FILTER_VALIDATE_URL) ==
true) {
1372 url:
'<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER
'); ?>/printer/index.php',
1373 data:
'invoice='+orderprinter1esc
1380 url:
'http://<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER
'); ?>:8111/print',
1382 print $headerorder.$order_receipt_printer1.$footerorder; ?>'
1388if ($action ==
"order" && !empty($order_receipt_printer2)) {
1389 if (filter_var(
getDolGlobalString(
'TAKEPOS_PRINT_SERVER'), FILTER_VALIDATE_URL) ==
true) {
1393 url:
'<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER
'); ?>/printer/index.php?printer=2',
1394 data:
'invoice='+orderprinter2esc
1401 url:
'http://<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER
'); ?>:8111/print2',
1403 print $headerorder.$order_receipt_printer2.$footerorder; ?>'
1409if ($action ==
"order" && !empty($order_receipt_printer3)) {
1410 if (filter_var(
getDolGlobalString(
'TAKEPOS_PRINT_SERVER'), FILTER_VALIDATE_URL) ==
true) {
1414 url:
'<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER
'); ?>/printer/index.php?printer=3',
1415 data:
'invoice='+orderprinter3esc
1422if ($action ==
"search" || $action ==
"valid") {
1424 parent.ClearSearch(
true);
1429if ($action ==
"temp" && !empty($ticket_printer1)) {
1433 url:
'http://<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER
'); ?>:8111/print',
1435 print $header_soc.$header_ticket.$body_ticket.$ticket_printer1.$ticket_total.$footer_ticket; ?>'
1440if ($action ==
"search") {
1442 $(
'#search').focus();
1450function SendTicket(
id)
1452 console.log(
"Open box to select the Print/Send form");
1453 $.colorbox({href:
"send.php?facid="+id, width:
"70%", height:
"30%", transition:
"none", iframe:
"true", title:
'<?php echo dol_escape_js($langs->trans("SendTicket")); ?>'});
1457function PrintBox(
id, action) {
1458 console.log(
"Open box before printing");
1459 $.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
"); ?>"});
1463function Print(
id, gift){
1464 console.log(
"Call Print() to generate the receipt.");
1465 $.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")); ?>'});
1469function TakeposPrinting(
id){
1471 console.log(
"TakeposPrinting" +
id);
1472 $.get(
"receipt.php?facid="+
id,
function(data,
status) {
1473 receipt=data.replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g,
'');
1476 url:
'http://<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER
'); ?>:8111/print',
1483function TakeposConnector(
id){
1484 console.log(
"TakeposConnector" +
id);
1485 $.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) {
1488 url:
'<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER
'); ?>/printer/index.php',
1489 data:
'invoice='+data
1497function DolibarrTakeposPrinting(
id) {
1498 console.log(
"DolibarrTakeposPrinting Printing invoice ticket " +
id);
1501 data: { token:
'<?php echo currentToken(); ?>' },
1502 url:
"<?php print DOL_URL_ROOT.'/takepos/ajax/ajax.php?action=printinvoiceticket&token='.newToken().'&term='.urlencode(isset($_SESSION["takeposterminal
"]) ? $_SESSION["takeposterminal
"] : '').'&id='; ?>" + id,
1509function CreditNote() {
1510 $(
"#poslines").load(
"<?php print DOL_URL_ROOT; ?>/takepos/invoice.php?action=creditnote&token=<?php echo newToken() ?>&invoiceid="+placeid,
function() { });
1516 $(
"#poslines").load(
"<?php print DOL_URL_ROOT; ?>/takepos/invoice.php?action=addnote&token=<?php echo newToken() ?>&invoiceid="+placeid+
"&idline="+selectedline, {
"addnote": $(
"#textinput").val() });
1521$( document ).ready(
function() {
1522 console.log(
"Set customer info and sales in header placeid=<?php echo $placeid; ?> status=<?php echo $invoice->statut; ?>");
1525 $s = $langs->trans(
"Customer");
1526 if ($invoice->id > 0 && ($invoice->socid !=
getDolGlobalString($constforcompanyid))) {
1529 $contactids = $invoice->getIdContact(
'external',
'BILLING');
1530 $contactid = $contactids[0];
1531 if ($contactid > 0) {
1533 $contact->fetch($contactid);
1534 $s .=
" - " . $contact->getFullName($langs);
1538 print
'$("#idcustomer").val("");';
1542 $(
"#customerandsales").html(
'');
1543 $(
"#shoppingcart").html(
'');
1546 $(
"#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>');
1548 $(
"#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>');
1552 $sql =
"SELECT rowid, datec, ref FROM ".MAIN_DB_PREFIX.
"facture";
1553 $sql .=
" WHERE entity IN (".getEntity(
'invoice').
")";
1556 $sql .=
" AND ref LIKE '(PROV-POS".$db->escape(isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'').
"-0%'";
1559 $sql .=
" AND pos_source = '".$db->escape($_SESSION[
"takeposterminal"]).
"'";
1560 $sql .=
" AND module_source = 'takepos'";
1563 $sql .= $db->order(
'datec',
'ASC');
1564 $resql = $db->query($sql);
1567 while ($obj = $db->fetch_object($resql)) {
1568 echo
'$("#shoppingcart").append(\'';
1569 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=\\\'';
1570 $num_sale = str_replace(
")",
"", str_replace(
"(PROV-POS".$_SESSION[
"takeposterminal"].
"-",
"", $obj->ref));
1572 if (str_replace(
"-",
"", $num_sale) > $max_sale) {
1573 $max_sale = str_replace(
"-",
"", $num_sale);
1575 echo
'\\\'; invoiceid=\\\'';
1577 echo
'\\\'; Refresh();">';
1578 if ($placeid == $obj->rowid) {
1579 echo
'<span class="basketselected">';
1581 echo
'<span class="basketnotselected">';
1583 echo
'<span class="fa fa-shopping-cart paddingright"></span>'.dol_print_date($db->jdate($obj->datec),
'%H:%M',
'tzuser');
1587 echo
'$("#shoppingcart").append(\'<a onclick="place=\\\'0-';
1589 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>\');';
1597 $constantforkey =
'CASHDESK_NO_DECREASE_STOCK'. (isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
1598 if (isModEnabled(
'stock')) {
1600 $constantforkey =
'CASHDESK_ID_WAREHOUSE'. (isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
1602 if ($idwarehouse > 0) {
1603 $s =
'<span class="small">';
1605 $warehouse->fetch($idwarehouse);
1606 $s .=
'<span class="hideonsmartphone">'.$langs->trans(
"Warehouse").
'<br></span>'.$warehouse->ref;
1608 $s .=
' ('.$langs->trans(
"Closed").
')';
1611 print
"$('#infowarehouse').html('".dol_escape_js($s).
"');";
1612 print
'$("#infowarehouse").css("display", "inline-block");';
1614 $s =
'<span class="small hideonsmartphone">';
1615 $s .= $langs->trans(
"StockChangeDisabled").
'<br>'.$langs->trans(
"NoWarehouseDefinedForTerminal");
1617 print
"$('#infowarehouse').html('".dol_escape_js($s).
"');";
1618 if (!empty(
$conf->dol_optimize_smallscreen)) {
1619 print
'$("#infowarehouse").css("display", "none");';
1623 $s =
'<span class="small hideonsmartphone">'.$langs->trans(
"StockChangeDisabled").
'</span>';
1624 print
"$('#infowarehouse').html('".dol_escape_js($s).
"');";
1625 if (!empty(
$conf->dol_optimize_smallscreen)) {
1626 print
'$("#infowarehouse").css("display", "none");';
1634 if (isModEnabled(
'member') && $invoice->socid > 0 && $invoice->socid !=
getDolGlobalInt($constforcompanyid)) {
1635 $s =
'<span class="small">';
1636 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
1637 $langs->load(
"members");
1638 $s .= $langs->trans(
"Member").
': ';
1640 $result = $adh->fetch(
'',
'', $invoice->socid);
1642 $adh->ref = $adh->getFullName($langs);
1646 $s .= $adh->getFullName($langs);
1647 $s .=
' - '.$adh->type;
1648 if ($adh->datefin) {
1649 $s .=
'<br>'.$langs->trans(
"SubscriptionEndDate").
': '.
dol_print_date($adh->datefin,
'day');
1650 if ($adh->hasDelay()) {
1651 $s .=
" ".img_warning($langs->trans(
"Late"));
1654 $s .=
'<br>'.$langs->trans(
"SubscriptionNotReceived");
1655 if ($adh->statut > 0) {
1656 $s .=
" ".img_warning($langs->trans(
"Late"));
1663 $s .=
'<br>'.$langs->trans(
"ThirdpartyNotLinkedToMember");
1668 $(
"#moreinfo").html(
'<?php print dol_escape_js($s); ?>');
1675 echo
"function CustomerDisplay(){";
1676 echo
"var line1='".$CUSTOMER_DISPLAY_line1.
"'.substring(0,20);";
1677 echo
"line1=line1.padEnd(20);";
1678 echo
"var line2='".$CUSTOMER_DISPLAY_line2.
"'.substring(0,20);";
1679 echo
"line2=line2.padEnd(20);";
1682 data: { text: line1+line2 },
1683 url: '".getDolGlobalString(
'TAKEPOS_PRINT_SERVER').
"/display/index.php',
1694if (!empty(
$conf->use_javascript_ajax)) {
1695 print
"\n".
'<!-- Includes JS Footer of Dolibarr -->'.
"\n";
1696 print
'<script src="'.DOL_URL_ROOT.
'/core/js/lib_foot.js.php?lang='.$langs->defaultlang.
'"></script>'.
"\n";