94 header($_SERVER[
'SERVER_PROTOCOL'].
' 500 Internal Server Error',
true, 500);
100$number =
GETPOST(
'number',
'alpha');
103$desc =
GETPOST(
'desc',
'alphanohtml');
116if ($pay ==
'cheque') {
123 $sql =
"SELECT id FROM ".MAIN_DB_PREFIX.
"c_paiement";
124 $sql .=
" WHERE entity IN (".getEntity(
'c_paiement').
")";
125 $sql .=
" AND code = '".$db->escape($paycode).
"'";
126 $resql = $db->query($sql);
128 $obj = $db->fetch_object($resql);
130 $paiementid = $obj->id;
137 $ret = $invoice->fetch($invoiceid);
139 $ret = $invoice->fetch(
'',
'(PROV-POS'.$takeposterminal.
'-'.$place.
')');
142 $placeid = $invoice->id;
145$constforcompanyid =
'CASHDESK_ID_THIRDPARTY'.$takeposterminal;
148if ($invoice->socid > 0) {
149 $soc->fetch($invoice->socid);
155if (isModEnabled(
'project') &&
getDolGlobalInt(
"CASHDESK_ID_PROJECT".$takeposterminal)) {
156 $invoice->fk_project =
getDolGlobalInt(
"CASHDESK_ID_PROJECT".$takeposterminal);
160if (isModEnabled(
'multicurrency') && !empty($_SESSION[
"takeposcustomercurrency"])) {
161 if ($invoice->multicurrency_code != $_SESSION[
"takeposcustomercurrency"]) {
162 $invoice->setMulticurrencyCode($_SESSION[
"takeposcustomercurrency"]);
166$term = empty($_SESSION[
"takeposterminal"]) ? 1 : $_SESSION[
"takeposterminal"];
173$parameters = array();
174$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $invoice, $action);
179if (empty($reshook)) {
181 if ($action ==
'valid' && $user->hasRight(
'facture',
'creer')) {
189 $bankaccount =
getDolGlobalInt(
'CASHDESK_ID_BANKACCOUNT_CASH'.$_SESSION[
"takeposterminal"]);
190 } elseif ($pay ==
"CHQ") {
191 $bankaccount =
getDolGlobalInt(
'CASHDESK_ID_BANKACCOUNT_CHEQUE'.$_SESSION[
"takeposterminal"]);
193 $accountname =
"CASHDESK_ID_BANKACCOUNT_".$pay.$_SESSION[
"takeposterminal"];
198 if ($bankaccount <= 0 && $pay !=
"delayed" && isModEnabled(
"bank")) {
199 $errormsg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"BankAccount"));
207 $invoice->fetch($placeid);
211 if ($invoice->total_ttc < 0) {
212 $invoice->type = $invoice::TYPE_CREDIT_NOTE;
214 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"facture";
215 $sql .=
" WHERE entity IN (".getEntity(
'invoice').
")";
216 $sql .=
" AND fk_soc = ".((int) $invoice->socid);
217 $sql .=
" AND type <> ".Facture::TYPE_CREDIT_NOTE;
218 $sql .=
" AND fk_statut >= ".$invoice::STATUS_VALIDATED;
219 $sql .=
" ORDER BY rowid DESC";
221 $resql = $db->query($sql);
223 $obj = $db->fetch_object($resql);
224 $fk_source = $obj->rowid;
225 if ($fk_source ==
null) {
226 fail($langs->transnoentitiesnoconv(
"NoPreviousBillForCustomer"));
229 fail($langs->transnoentitiesnoconv(
"NoPreviousBillForCustomer"));
231 $invoice->fk_facture_source = $fk_source;
232 $invoice->update($user);
235 $constantforkey =
'CASHDESK_NO_DECREASE_STOCK'.(isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
242 if ($invoice->getRemainToPay() > 0) {
248 } elseif (count($invoice->lines) == 0) {
252 } elseif (isModEnabled(
'stock') && !isModEnabled(
'productbatch') && $allowstockchange) {
257 $conf->global->STOCK_CALCULATE_ON_BILL = 1;
259 $constantforkey =
'CASHDESK_ID_WAREHOUSE'.$_SESSION[
"takeposterminal"];
260 dol_syslog(
"Validate invoice with stock change. Warehouse defined into constant ".$constantforkey.
" = ".
getDolGlobalString($constantforkey));
265 $res = $invoice->validate($user,
'',
getDolGlobalInt($constantforkey), 0, $batch_rule);
268 $conf->global->STOCK_CALCULATE_ON_BILL = $savconst;
271 $res = $invoice->validate($user);
274 $langs->load(
"admin");
275 dol_htmloutput_errors($invoice->error ==
'NotConfigured' ? $langs->trans(
"NotConfigured").
' (TakePos numbering module)' : $invoice->error, $invoice->errors, 1);
280 if (!$error && $res >= 0) {
281 $remaintopay = $invoice->getRemainToPay();
282 if ($remaintopay > 0) {
284 $payment->datepaye = $now;
285 $payment->fk_account = $bankaccount;
286 $payment->amounts[$invoice->id] = $amountofpayment;
293 if ($amountofpayment <= 0 || $amountofpayment > $remaintopay) {
294 $payment->amounts[$invoice->id] = $remaintopay;
297 $payment->paiementid = $paiementid;
298 $payment->num_payment = $invoice->ref;
300 if ($pay !=
"delayed") {
301 $payment->create($user);
302 $res = $payment->addPaymentToBank($user,
'payment',
'(CustomerInvoicePayment)', $bankaccount,
'',
'');
307 $remaintopay = $invoice->getRemainToPay();
313 if ($remaintopay == 0) {
314 dol_syslog(
"Invoice is paid, so we set it to status Paid");
315 $result = $invoice->setPaid($user);
320 $invoice->setPaymentMethods($paiementid);
322 dol_syslog(
"Invoice is not paid, remain to pay = ".$remaintopay);
329 if (!$error && $res >= 0) {
330 if (isModEnabled(
'stock') && isModEnabled(
'productbatch') && $allowstockchange) {
332 dol_syslog(
"Now we record the stock movement for each qualified line");
335 require_once DOL_DOCUMENT_ROOT .
"/product/stock/class/mouvementstock.class.php";
336 $constantforkey =
'CASHDESK_ID_WAREHOUSE'.$_SESSION[
"takeposterminal"];
339 $labeltakeposmovement =
'TakePOS - '.$langs->trans(
"Invoice").
' '.$invoice->ref;
341 foreach ($invoice->lines as $line) {
343 $warehouseid = ($line->fk_warehouse ? $line->fk_warehouse :
getDolGlobalInt($constantforkey));
346 if ($line->batch !=
'' && $warehouseid > 0) {
348 $prod_batch->find(0,
'',
'', $line->batch, $warehouseid);
351 $mouvP->setOrigin($invoice->element, $invoice->id);
353 $res = $mouvP->livraison($user, $line->fk_product, $warehouseid, $line->qty, $line->price, $labeltakeposmovement,
'',
'',
'', $prod_batch->batch, $prod_batch->id, $inventorycode);
360 $mouvP->setOrigin($invoice->element, $invoice->id);
362 $res = $mouvP->livraison($user, $line->fk_product, $warehouseid, $line->qty, $line->price, $labeltakeposmovement,
'',
'',
'',
'', 0, $inventorycode);
372 if (!$error && $res >= 0) {
378 if ($action ==
'creditnote' && $user->hasRight(
'facture',
'creer')) {
381 $creditnote =
new Facture($db);
382 $creditnote->socid = $invoice->socid;
384 $creditnote->module_source =
'takepos';
385 $creditnote->pos_source = isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'' ;
387 $creditnote->fk_facture_source = $placeid;
390 $creditnote->create($user);
392 foreach ($invoice->lines as $line) {
394 if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) {
399 if (!empty($invoice->situation_counter)) {
400 $source_fk_prev_id = $line->fk_prev_id;
401 $line->fk_prev_id = $line->id;
402 if (!empty($invoice->tab_previous_situation_invoice)) {
405 $tab_jumped_credit_notes = array();
406 $lineIndex = count($invoice->tab_previous_situation_invoice) - 1;
407 $searchPreviousInvoice =
true;
408 while ($searchPreviousInvoice) {
409 if ($invoice->tab_previous_situation_invoice[$lineIndex]->situation_cycle_ref || $lineIndex < 1) {
410 $searchPreviousInvoice =
false;
414 $tab_jumped_credit_notes[$lineIndex] = $invoice->tab_previous_situation_invoice[$lineIndex]->id;
420 $maxPrevSituationPercent = 0;
421 foreach ($invoice->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine) {
422 if ($prevLine->id == $source_fk_prev_id) {
423 $maxPrevSituationPercent = max($maxPrevSituationPercent, $prevLine->situation_percent);
426 $line->total_ht = $line->total_ht - $prevLine->total_ht;
427 $line->total_tva = $line->total_tva - $prevLine->total_tva;
428 $line->total_ttc = $line->total_ttc - $prevLine->total_ttc;
429 $line->total_localtax1 = $line->total_localtax1 - $prevLine->total_localtax1;
430 $line->total_localtax2 = $line->total_localtax2 - $prevLine->total_localtax2;
432 $line->multicurrency_subprice = $line->multicurrency_subprice - $prevLine->multicurrency_subprice;
433 $line->multicurrency_total_ht = $line->multicurrency_total_ht - $prevLine->multicurrency_total_ht;
434 $line->multicurrency_total_tva = $line->multicurrency_total_tva - $prevLine->multicurrency_total_tva;
435 $line->multicurrency_total_ttc = $line->multicurrency_total_ttc - $prevLine->multicurrency_total_ttc;
440 $line->situation_percent = $maxPrevSituationPercent - $line->situation_percent;
445 $maxPrevSituationPercent = 0;
446 foreach ($tab_jumped_credit_notes as $index => $creditnoteid) {
447 foreach ($invoice->tab_previous_situation_invoice[$index]->lines as $prevLine) {
448 if ($prevLine->fk_prev_id == $source_fk_prev_id) {
449 $maxPrevSituationPercent = $prevLine->situation_percent;
451 $line->total_ht -= $prevLine->total_ht;
452 $line->total_tva -= $prevLine->total_tva;
453 $line->total_ttc -= $prevLine->total_ttc;
454 $line->total_localtax1 -= $prevLine->total_localtax1;
455 $line->total_localtax2 -= $prevLine->total_localtax2;
457 $line->multicurrency_subprice -= $prevLine->multicurrency_subprice;
458 $line->multicurrency_total_ht -= $prevLine->multicurrency_total_ht;
459 $line->multicurrency_total_tva -= $prevLine->multicurrency_total_tva;
460 $line->multicurrency_total_ttc -= $prevLine->multicurrency_total_ttc;
466 $line->situation_percent += $maxPrevSituationPercent;
474 $line->fk_facture = $creditnote->id;
475 $line->fk_parent_line = $fk_parent_line;
477 $line->subprice = -$line->subprice;
479 $line->total_ht = -$line->total_ht;
480 $line->total_tva = -$line->total_tva;
481 $line->total_ttc = -$line->total_ttc;
482 $line->total_localtax1 = -$line->total_localtax1;
483 $line->total_localtax2 = -$line->total_localtax2;
485 $line->multicurrency_subprice = -$line->multicurrency_subprice;
486 $line->multicurrency_total_ht = -$line->multicurrency_total_ht;
487 $line->multicurrency_total_tva = -$line->multicurrency_total_tva;
488 $line->multicurrency_total_ttc = -$line->multicurrency_total_ttc;
490 $result = $line->insert(0, 1);
492 $creditnote->lines[] = $line;
495 if ($result > 0 && $line->product_type == 9) {
496 $fk_parent_line = $result;
499 $creditnote->update_price(1);
503 $constantforkey =
'CASHDESK_NO_DECREASE_STOCK'.(isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
506 if (isModEnabled(
'stock') && !isModEnabled(
'productbatch') && $allowstockchange) {
510 $conf->global->STOCK_CALCULATE_ON_BILL = 1;
512 $constantforkey =
'CASHDESK_ID_WAREHOUSE'.(isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
514 dol_syslog(
"Validate invoice with stock change into warehouse defined into constant ".$constantforkey.
" = ".
getDolGlobalString($constantforkey).
" or warehouseid= ".$warehouseid.
" if defined.");
519 $res = $creditnote->validate($user,
'',
getDolGlobalString($constantforkey), 0, $batch_rule);
526 $conf->global->STOCK_CALCULATE_ON_BILL = $savconst;
528 $res = $creditnote->validate($user);
532 if (!$error && $res >= 0) {
533 if (isModEnabled(
'stock') && isModEnabled(
'productbatch') && $allowstockchange) {
535 dol_syslog(
"Now we record the stock movement for each qualified line");
538 require_once DOL_DOCUMENT_ROOT .
"/product/stock/class/mouvementstock.class.php";
539 $constantforkey =
'CASHDESK_ID_WAREHOUSE'.$_SESSION[
"takeposterminal"];
542 $labeltakeposmovement =
'TakePOS - '.$langs->trans(
"CreditNote").
' '.$creditnote->ref;
544 foreach ($creditnote->lines as $line) {
546 $warehouseid = ($line->fk_warehouse ? $line->fk_warehouse :
getDolGlobalInt($constantforkey));
549 if ($line->batch !=
'' && $warehouseid > 0) {
554 $mouvP->setOrigin($creditnote->element, $creditnote->id);
556 $res = $mouvP->reception($user, $line->fk_product, $warehouseid, $line->qty, $line->price, $labeltakeposmovement,
'',
'', $line->batch,
'', 0, $inventorycode);
563 $mouvP->setOrigin($creditnote->element, $creditnote->id);
565 $res = $mouvP->reception($user, $line->fk_product, $warehouseid, $line->qty, $line->price, $labeltakeposmovement,
'',
'',
'',
'', 0, $inventorycode);
575 if (!$error && $res >= 0) {
578 $creditnote->id = $placeid;
583 if (($action ==
'history' || $action ==
'creditnote') && $user->hasRight(
'takepos',
'run')) {
584 if ($action ==
'creditnote' && $creditnote->id > 0) {
585 $placeid = $creditnote->id;
591 $invoice->fetch($placeid);
595 if (($action ==
"addline" || $action ==
"freezone") && $placeid == 0 && ($user->hasRight(
'takepos',
'run') || defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
598 include_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
601 $invoice->module_source =
'takepos';
602 $invoice->pos_source = isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'' ;
603 $invoice->entity = !empty($_SESSION[
"takeposinvoiceentity"]) ? $_SESSION[
"takeposinvoiceentity"] : $conf->entity;
605 if ($invoice->socid <= 0) {
606 $langs->load(
'errors');
612 $placeid = $invoice->create($user);
616 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facture set ref='(PROV-POS".$_SESSION[
"takeposterminal"].
"-".$place.
")' where rowid = ".((int) $placeid);
617 $resql = $db->query($sql);
631 if ($action ==
"addline" && ($user->hasRight(
'takepos',
'run') || defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
633 $prod->fetch($idproduct);
636 $customer->fetch($invoice->socid);
638 $datapriceofproduct = $prod->getSellPrice($mysoc, $customer, 0);
640 $qty = GETPOSTISSET(
'qty') ?
GETPOSTINT(
'qty') : 1;
641 $price = $datapriceofproduct[
'pu_ht'];
642 $price_ttc = $datapriceofproduct[
'pu_ttc'];
644 $price_base_type = empty($datapriceofproduct[
'price_base_type']) ?
'HT' : $datapriceofproduct[
'price_base_type'];
645 $tva_tx = $datapriceofproduct[
'tva_tx'];
646 $tva_npr = $datapriceofproduct[
'tva_npr'];
649 $localtax1_tx =
get_localtax($tva_tx, 1, $customer, $mysoc, $tva_npr);
650 $localtax2_tx =
get_localtax($tva_tx, 2, $customer, $mysoc, $tva_npr);
653 if (isModEnabled(
'productbatch') && isModEnabled(
'stock')) {
654 $batch =
GETPOST(
'batch',
'alpha');
656 if (!empty($batch)) {
657 $action =
"setbatch";
658 } elseif ($prod->status_batch > 0) {
663 $prod->load_stock(
'warehouseopen');
665 $constantforkey =
'CASHDESK_ID_WAREHOUSE'.$_SESSION[
"takeposterminal"];
669 foreach ($prod->stock_warehouse as $tmpwarehouseid => $tmpval) {
674 if (!empty($prod->stock_warehouse[$tmpwarehouseid]) && is_array($prod->stock_warehouse[$tmpwarehouseid]->detail_batch)) {
675 if (is_object($prod->stock_warehouse[$tmpwarehouseid]) && count($prod->stock_warehouse[$tmpwarehouseid]->detail_batch)) {
676 foreach ($prod->stock_warehouse[$tmpwarehouseid]->detail_batch as $dbatch) {
685 echo
"function addbatch(batch, warehouseid) {\n";
686 echo
"console.log('We add batch '+batch+' from warehouse id '+warehouseid);\n";
687 echo
'$("#poslines").load("'.DOL_URL_ROOT.
'/takepos/invoice.php?action=addline&batch="+encodeURI(batch)+"&warehouseid="+warehouseid+"&place='.$place.
'&idproduct='.$idproduct.
'&token='.
newToken().
'", function() {});'.
"\n";
692 echo
"<center>".$langs->trans(
"SearchIntoBatch").
": <b> $nbofsuggested </b></center><br><table>";
693 foreach ($prod->stock_warehouse as $tmpwarehouseid => $tmpval) {
698 if (!empty($prod->stock_warehouse[$tmpwarehouseid]) && is_array($prod->stock_warehouse[$tmpwarehouseid]->detail_batch)) {
699 foreach ($prod->stock_warehouse[$tmpwarehouseid]->detail_batch as $dbatch) {
700 $batchStock = + $dbatch->qty;
701 $quantityToBeDelivered = 1;
702 $deliverableQty = min($quantityToBeDelivered, $batchStock);
704 print
'<!-- subj='.$suggestednb.
'/'.$nbofsuggested.
' -->';
705 print
'<!-- Show details of lot/serial in warehouseid='.$tmpwarehouseid.
' -->';
706 print
'<td class="left">';
708 $detail .=
'<span class="opacitymedium">'.$langs->trans(
"LotSerial").
':</span> '.$dbatch->batch;
715 $detail .=
'</td><td>';
716 $detail .=
'<span class="opacitymedium">'.$langs->trans(
"Qty").
':</span> '.$dbatch->qty;
717 $detail .=
'</td><td>';
718 $detail .=
' <button class="marginleftonly" onclick="addbatch(\''.dol_escape_js($dbatch->batch).
'\',
'.$tmpwarehouseid.')
">'.$langs->trans("Select
")."</
button>
";
722 $quantityToBeDelivered -= $deliverableQty;
723 if ($quantityToBeDelivered < 0) {
724 $quantityToBeDelivered = 0;
733 print '</body></html>';
739 if (getDolGlobalString('TAKEPOS_SUPPLEMENTS')) {
740 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
741 $cat = new Categorie($db);
742 $categories = $cat->containing($idproduct, 'product');
743 $found = (array_search(getDolGlobalInt('TAKEPOS_SUPPLEMENTS_CATEGORY'), array_column($categories, 'id')));
744 if ($found !== false) { // If this product is a supplement
745 $sql = "SELECT fk_parent_line FROM
".MAIN_DB_PREFIX."facturedet where
rowid =
".((int) $selectedline);
746 $resql = $db->query($sql);
747 $row = $db->fetch_array($resql);
748 if ($row[0] == null) {
749 $parent_line = $selectedline;
751 $parent_line = $row[0]; //If the parent line is already a supplement, add the supplement to the main product
758 // Group if enabled. Skip group if line already sent to the printer
759 if (getDolGlobalString('TAKEPOS_GROUP_SAME_PRODUCT')) {
760 foreach ($invoice->lines as $line) {
761 if ($line->product_ref == $prod->ref) {
762 if ($line->special_code == 4) {
764 } // If this line is sended to printer create new line
765 // check if qty in stock
766 if (getDolGlobalString('TAKEPOS_QTY_IN_STOCK') && (($line->qty + $qty) > $prod->stock_reel)) {
767 $invoice->error = $langs->trans("ErrorStockIsNotEnough
");
768 dol_htmloutput_errors($invoice->error, $invoice->errors, 1);
772 $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);
774 dol_htmloutput_errors($invoice->error, $invoice->errors, 1);
776 $idoflineadded = $line->id;
782 if ($idoflineadded <= 0 && empty($err)) {
783 $invoice->fetch_thirdparty();
784 $array_options = array();
786 $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);
788 /* setup of margin calculation */
789 if (isset($conf->global->MARGIN_TYPE)) {
790 if (getDolGlobalString('MARGIN_TYPE') == 'pmp' && !empty($prod->pmp)) {
791 $line['fk_fournprice'] = null;
792 $line['pa_ht'] = $prod->pmp;
793 } elseif (getDolGlobalString('MARGIN_TYPE') == 'costprice' && !empty($prod->cost_price)) {
794 $line['fk_fournprice'] = null;
795 $line['pa_ht'] = $prod->cost_price;
797 // default is fournprice
798 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
799 $pf = new ProductFournisseur($db);
800 if ($pf->find_min_price_product_fournisseur($idproduct, $qty) > 0) {
801 $line['fk_fournprice'] = $pf->product_fourn_price_id;
802 $line['pa_ht'] = $pf->fourn_unitprice_with_discount;
803 if (getDolGlobalString('PRODUCT_CHARGES') && $pf->fourn_charges > 0) {
804 $line['pa_ht'] += $pf->fourn_charges / $pf->fourn_qty;
810 // complete line by hook
811 $parameters = array('prod' => $prod, 'line' => $line);
812 $reshook = $hookmanager->executeHooks('completeTakePosAddLine', $parameters, $invoice, $action); // Note that $action and $line may have been modified by some hooks
814 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
818 if (empty($reshook)) {
819 if (!empty($hookmanager->resArray)) {
820 $line = $hookmanager->resArray;
823 // check if qty in stock
824 if (getDolGlobalString('TAKEPOS_QTY_IN_STOCK') && $qty > $prod->stock_reel) {
825 $invoice->error = $langs->trans("ErrorStockIsNotEnough
");
826 dol_htmloutput_errors($invoice->error, $invoice->errors, 1);
831 $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);
835 if (getDolGlobalString('TAKEPOS_CUSTOMER_DISPLAY')) {
836 $CUSTOMER_DISPLAY_line1 = $prod->label;
837 $CUSTOMER_DISPLAY_line2 = price($price_ttc);
841 $invoice->fetch($placeid);
844 // If we add a line by submitting freezone form (invoice exists here because it was created juste before if it didn't exists)
845 if ($action == "freezone
" && $user->hasRight('takepos', 'run')) {
846 $customer = new Societe($db);
847 $customer->fetch($invoice->socid);
849 $tva_tx = GETPOST('tva_tx', 'alpha');
851 if (!preg_match('/\((.*)\)/', $tva_tx)) {
852 $tva_tx = price2num($tva_tx);
855 $tva_tx = get_default_tva($mysoc, $customer);
859 $localtax1_tx = get_localtax($tva_tx, 1, $customer, $mysoc, $tva_npr);
860 $localtax2_tx = get_localtax($tva_tx, 2, $customer, $mysoc, $tva_npr);
862 $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);
864 dol_htmloutput_errors($invoice->error, $invoice->errors, 1);
866 $invoice->fetch($placeid);
869 if ($action == "addnote
" && ($user->hasRight('takepos', 'run') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
870 $desc = GETPOST('addnote', 'alpha');
872 $invoice->update_note($desc, '_public');
874 foreach ($invoice->lines as $line) {
875 if ($line->id == $idline) {
876 $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);
880 $invoice->fetch($placeid);
883 if ($action == "deleteline
" && ($user->hasRight('takepos', 'run') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
885 $permissiontoupdateline = ($user->hasRight('takepos', 'editlines') && ($user->hasRight('takepos', 'editorderedlines') || $line->special_code != "4
"));
886 if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
887 if ($invoice->status == $invoice::STATUS_DRAFT && $invoice->pos_source && $invoice->module_source == 'takepos') {
888 $permissiontoupdateline = true;
889 // TODO Add also a test on $_SESSION('publicobjectid'] defined at creation of object
890 // TODO Check also that invoice->ref is (PROV-POS1-2) with 1 = terminal and 2, the invoice ID
894 if ($idline > 0 && $placeid > 0) { // If invoice exists and line selected. To avoid errors if deleted from another device or no line selected.
895 $invoice->deleteLine($idline);
896 $invoice->fetch($placeid);
897 } elseif ($placeid > 0) { // If invoice exists but no line selected, proceed to delete last line.
898 $sql = "SELECT
rowid FROM
".MAIN_DB_PREFIX."facturedet where fk_facture =
".((int) $placeid)." ORDER BY
rowid DESC
";
899 $resql = $db->query($sql);
900 $row = $db->fetch_array($resql);
901 $deletelineid = $row[0];
902 $invoice->deleteLine($deletelineid);
903 $invoice->fetch($placeid);
906 if (count($invoice->lines) == 0) {
907 $invoice->delete($user);
909 if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
910 header("Location:
".DOL_URL_ROOT."/takepos/public/auto_order.php
");
912 header("Location:
".DOL_URL_ROOT."/takepos/invoice.php
");
918 // Action to delete or discard an invoice
919 if ($action == "delete
" && ($user->hasRight('takepos', 'run') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
920 // $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.
922 $result = $invoice->fetch($placeid);
924 if ($result > 0 && $invoice->statut == Facture::STATUS_DRAFT) {
927 // We delete the lines
929 foreach ($invoice->lines as $line) {
930 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
931 $tmpres = $invoice->deleteLine($line->id);
938 $sql = "UPDATE
".MAIN_DB_PREFIX."facture
";
939 $varforconst = 'CASHDESK_ID_THIRDPARTY'.$_SESSION["takeposterminal
"];
940 $sql .= " SET fk_soc =
".((int) getDolGlobalString($varforconst)).",
";
941 $sql .= " datec =
'".$db->idate(dol_now())."'";
942 $sql .= " WHERE entity IN (
".getEntity('invoice').")
";
943 $sql .= " AND
ref =
'(PROV-POS".$db->escape($_SESSION["takeposterminal"]."-".$place).")'";
944 $resql1 = $db->query($sql);
946 if ($resdeletelines && $resql1) {
952 $invoice->fetch($placeid);
957 if ($action == "updateqty
") { // Test on permission is done later
958 foreach ($invoice->lines as $line) {
959 if ($line->id == $idline) {
960 $permissiontoupdateline = ($user->hasRight('takepos', 'editlines') && ($user->hasRight('takepos', 'editorderedlines') || $line->special_code != "4
"));
961 if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
962 if ($invoice->status == $invoice::STATUS_DRAFT && $invoice->pos_source && $invoice->module_source == 'takepos') {
963 $permissiontoupdateline = true;
964 // TODO Add also a test on $_SESSION('publicobjectid'] defined at creation of object
965 // TODO Check also that invoice->ref is (PROV-POS1-2) with 1 = terminal and 2, the invoice ID
968 if (!$permissiontoupdateline) {
969 dol_htmloutput_errors($langs->trans("NotEnoughPermissions
", "TakePos
").' - No permission to updateqty', null, 1);
971 $result = $invoice->updateline($line->id, $line->desc, $line->subprice, $number, $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);
976 $invoice->fetch($placeid);
979 if ($action == "updateprice
") { // Test on permission is done later
980 $customer = new Societe($db);
981 $customer->fetch($invoice->socid);
983 foreach ($invoice->lines as $line) {
984 if ($line->id == $idline) {
985 $prod = new Product($db);
986 $prod->fetch($line->fk_product);
987 $datapriceofproduct = $prod->getSellPrice($mysoc, $customer, 0);
988 $price_min = $datapriceofproduct['price_min'];
989 $usercanproductignorepricemin = ((getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !$user->hasRight('produit', 'ignore_price_min_advance')) || !getDolGlobalString('MAIN_USE_ADVANCED_PERMS'));
990 $pu_ht = price2num($number / (1 + ($line->tva_tx / 100)), 'MU');
992 if ($usercanproductignorepricemin && (!empty($price_min) && (price2num($pu_ht) * (1 - price2num($line->remise_percent) / 100) < price2num($price_min)))) {
993 $langs->load("products
");
994 dol_htmloutput_errors($langs->trans("CantBeLessThanMinPrice
", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, -1, $conf->currency)));
995 //echo $langs->trans("CantBeLessThanMinPrice
");
997 $permissiontoupdateline = ($user->hasRight('takepos', 'editlines') && ($user->hasRight('takepos', 'editorderedlines') || $line->special_code != "4
"));
998 if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
999 if ($invoice->status == $invoice::STATUS_DRAFT && $invoice->pos_source && $invoice->module_source == 'takepos') {
1000 $permissiontoupdateline = true;
1001 // TODO Add also a test on $_SESSION('publicobjectid'] defined at creation of object
1002 // TODO Check also that invoice->ref is (PROV-POS1-2) with 1 = terminal and 2, the invoice ID
1005 if (!$permissiontoupdateline) {
1006 dol_htmloutput_errors($langs->trans("NotEnoughPermissions
", "TakePos
").' - No permission to updateprice', null, 1);
1007 } elseif (getDolGlobalInt('TAKEPOS_CHANGE_PRICE_HT') == 1) {
1008 $result = $invoice->updateline($line->id, $line->desc, $number, $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);
1010 $result = $invoice->updateline($line->id, $line->desc, $number, $line->qty, $line->remise_percent, $line->date_start, $line->date_end, $line->tva_tx, $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);
1017 $invoice->fetch($placeid);
1020 if ($action == "updatereduction
") { // Test on permission is done later
1021 $customer = new Societe($db);
1022 $customer->fetch($invoice->socid);
1024 foreach ($invoice->lines as $line) {
1025 if ($line->id == $idline) {
1026 dol_syslog("updatereduction Process line
".$line->id.' to apply discount of '.$number.'%');
1028 $prod = new Product($db);
1029 $prod->fetch($line->fk_product);
1031 $datapriceofproduct = $prod->getSellPrice($mysoc, $customer, 0);
1032 $price_min = $datapriceofproduct['price_min'];
1033 $usercanproductignorepricemin = ((getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !$user->hasRight('produit', 'ignore_price_min_advance')) || !getDolGlobalString('MAIN_USE_ADVANCED_PERMS'));
1035 $pu_ht = price2num($line->subprice / (1 + ($line->tva_tx / 100)), 'MU');
1038 if ($usercanproductignorepricemin && (!empty($price_min) && (price2num($line->subprice) * (1 - price2num($number) / 100) < price2num($price_min)))) {
1039 $langs->load("products
");
1040 dol_htmloutput_errors($langs->trans("CantBeLessThanMinPrice
", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, -1, $conf->currency)));
1042 $permissiontoupdateline = ($user->hasRight('takepos', 'editlines') && ($user->hasRight('takepos', 'editorderedlines') || $line->special_code != "4
"));
1043 if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1044 if ($invoice->status == $invoice::STATUS_DRAFT && $invoice->pos_source && $invoice->module_source == 'takepos') {
1045 $permissiontoupdateline = true;
1046 // TODO Add also a test on $_SESSION('publicobjectid'] defined at creation of object
1047 // TODO Check also that invoice->ref is (PROV-POS1-2) with 1 = terminal and 2, the invoice ID
1050 if (!$permissiontoupdateline) {
1051 dol_htmloutput_errors($langs->trans("NotEnoughPermissions
", "TakePos
"), null, 1);
1053 $result = $invoice->updateline($line->id, $line->desc, $line->subprice, $line->qty, $number, $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);
1060 $invoice->fetch($placeid);
1061 } elseif ($action == 'update_reduction_global' && $user->hasRight('takepos', 'editlines')) {
1062 foreach ($invoice->lines as $line) {
1063 $result = $invoice->updateline($line->id, $line->desc, $line->subprice, $line->qty, $number, $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);
1066 $invoice->fetch($placeid);
1069 if ($action == "setbatch
" && ($user->hasRight('takepos', 'run') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
1070 $constantforkey = 'CASHDESK_ID_WAREHOUSE'.$_SESSION["takeposterminal
"];
1071 $warehouseid = (GETPOSTINT('warehouseid') > 0 ? GETPOSTINT('warehouseid') : getDolGlobalInt($constantforkey)); // Get the warehouse id from GETPOSTINT('warehouseid'), otherwise use default setup.
1072 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet SET batch =
'".$db->escape($batch)."', fk_warehouse =
".((int) $warehouseid);
1073 $sql .= " WHERE
rowid=
".((int) $idoflineadded);
1077 if ($action == "order
" && $placeid != 0 && ($user->hasRight('takepos', 'run') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
1078 include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
1079 if ((isModEnabled('receiptprinter') && getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term) > 0) || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter
" || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector
") {
1080 require_once DOL_DOCUMENT_ROOT.'/core/class/dolreceiptprinter.class.php';
1081 $printer = new dolReceiptPrinter($db);
1084 $sql = "SELECT label FROM
".MAIN_DB_PREFIX."takepos_floor_tables where
rowid=
".((int) $place);
1085 $resql = $db->query($sql);
1086 $row = $db->fetch_object($resql);
1087 $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>';
1088 $footerorder = '</tbody></table>'.dol_print_date(dol_now(), 'dayhour').'<br></html>';
1089 $order_receipt_printer1 = "";
1090 $order_receipt_printer2 = "";
1091 $order_receipt_printer3 = "";
1092 $catsprinter1 = explode(';', getDolGlobalString('TAKEPOS_PRINTED_CATEGORIES_1'));
1093 $catsprinter2 = explode(';', getDolGlobalString('TAKEPOS_PRINTED_CATEGORIES_2'));
1094 $catsprinter3 = explode(';', getDolGlobalString('TAKEPOS_PRINTED_CATEGORIES_3'));
1096 foreach ($invoice->lines as $line) {
1097 if ($line->special_code == "4
") {
1100 $c = new Categorie($db);
1101 $existing = $c->containing($line->fk_product, Categorie::TYPE_PRODUCT, 'id');
1102 $result = array_intersect($catsprinter1, $existing);
1103 $count = count($result);
1104 if (!$line->fk_product) {
1105 $count++; // Print Free-text item (Unassigned printer) to Printer 1
1109 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet set special_code=
'1' where
rowid=
".$line->id; //Set to print on printer 1
1111 $order_receipt_printer1 .= '<tr><td class="left
">';
1112 if ($line->fk_product) {
1113 $order_receipt_printer1 .= $line->product_label;
1115 $order_receipt_printer1 .= $line->description;
1117 $order_receipt_printer1 .= '</td><td class="right
">'.$line->qty;
1118 if (!empty($line->array_options['options_order_notes'])) {
1119 $order_receipt_printer1 .= "<br>(
".$line->array_options['options_order_notes'].")
";
1121 $order_receipt_printer1 .= '</td></tr>';
1124 if (((isModEnabled('receiptprinter') && getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term) > 0) || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter
" || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector
") && $linestoprint > 0) {
1125 $invoice->fetch($placeid); //Reload object before send to printer
1126 $printer->orderprinter = 1;
1128 echo "var orderprinter1esc=
'";
1129 $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
1132 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet
set special_code=
'4' where special_code=
'1' and fk_facture=
".$invoice->id; // Set as printed
1134 $invoice->fetch($placeid); //Reload object after set lines as printed
1137 foreach ($invoice->lines as $line) {
1138 if ($line->special_code == "4
") {
1141 $c = new Categorie($db);
1142 $existing = $c->containing($line->fk_product, Categorie::TYPE_PRODUCT, 'id');
1143 $result = array_intersect($catsprinter2, $existing);
1144 $count = count($result);
1147 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet
set special_code=
'2' where
rowid=
".$line->id; //Set to print on printer 2
1149 $order_receipt_printer2 .= '<tr>'.$line->product_label.'<td class="right
">'.$line->qty;
1150 if (!empty($line->array_options['options_order_notes'])) {
1151 $order_receipt_printer2 .= "<br>(
".$line->array_options['options_order_notes'].")
";
1153 $order_receipt_printer2 .= '</td></tr>';
1156 if (((isModEnabled('receiptprinter') && getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term) > 0) || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter
" || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector
") && $linestoprint > 0) {
1157 $invoice->fetch($placeid); //Reload object before send to printer
1158 $printer->orderprinter = 2;
1160 echo "var orderprinter2esc=
'";
1161 $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
1164 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet
set special_code=
'4' where special_code=
'2' and fk_facture=
".$invoice->id; // Set as printed
1166 $invoice->fetch($placeid); //Reload object after set lines as printed
1169 foreach ($invoice->lines as $line) {
1170 if ($line->special_code == "4
") {
1173 $c = new Categorie($db);
1174 $existing = $c->containing($line->fk_product, Categorie::TYPE_PRODUCT, 'id');
1175 $result = array_intersect($catsprinter3, $existing);
1176 $count = count($result);
1179 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet
set special_code=
'3' where
rowid=
".$line->id; //Set to print on printer 3
1181 $order_receipt_printer3 .= '<tr>'.$line->product_label.'<td class="right
">'.$line->qty;
1182 if (!empty($line->array_options['options_order_notes'])) {
1183 $order_receipt_printer3 .= "<br>(
".$line->array_options['options_order_notes'].")
";
1185 $order_receipt_printer3 .= '</td></tr>';
1188 if (((isModEnabled('receiptprinter') && getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term) > 0) || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter
" || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector
") && $linestoprint > 0) {
1189 $invoice->fetch($placeid); //Reload object before send to printer
1190 $printer->orderprinter = 3;
1192 echo "var orderprinter3esc=
'";
1193 $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
1196 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet
set special_code=
'4' where special_code=
'3' and fk_facture=
".$invoice->id; // Set as printed
1198 $invoice->fetch($placeid); //Reload object after set lines as printed
1201 $sectionwithinvoicelink = '';
1202 if (($action == "valid
" || $action == "history
" || $action == 'creditnote') && $user->hasRight('takepos', 'run')) {
1203 $sectionwithinvoicelink .= '<!-- Section with invoice link -->'."\n
";
1204 $sectionwithinvoicelink .= '<span style="font-size:120%;
" class="center
">';
1205 $sectionwithinvoicelink .= $invoice->getNomUrl(1, '', 0, 0, '', 0, 0, -1, '_backoffice')." -
";
1206 $remaintopay = $invoice->getRemainToPay();
1207 if ($remaintopay > 0) {
1208 $sectionwithinvoicelink .= $langs->trans('RemainToPay').': <span class="amountremaintopay
" style="font-size: unset
">'.price($remaintopay, 1, $langs, 1, -1, -1, $conf->currency).'</span>';
1210 if ($invoice->paye) {
1211 $sectionwithinvoicelink .= '<span class="amountpaymentcomplete
" style="font-size: unset
">'.$langs->trans("Paid
").'</span>';
1213 $sectionwithinvoicelink .= $langs->trans('BillShortStatusValidated');
1217 $sectionwithinvoicelink .= '</span><br>';
1218 if (getDolGlobalInt('TAKEPOS_PRINT_INVOICE_DOC_INSTEAD_OF_RECEIPT')) {
1219 $sectionwithinvoicelink .= ' <a target="_blank
" class="button" href="' . DOL_URL_ROOT . '/document.php?token=
' . newToken() . '&modulepart=facture&file=
' . $invoice->ref . '/
' . $invoice->ref . '.pdf
">Invoice</a>';
1220 } elseif (getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector
") {
1221 if (getDolGlobalString('TAKEPOS_PRINT_SERVER') && filter_var($conf->global->TAKEPOS_PRINT_SERVER, FILTER_VALIDATE_URL) == true) {
1222 $sectionwithinvoicelink .= ' <button id="buttonprint
" type="button" onclick="TakeposConnector(
'.$placeid.')
">'.$langs->trans('PrintTicket').'</button>';
1224 $sectionwithinvoicelink .= ' <button id="buttonprint
" type="button" onclick="TakeposPrinting(
'.$placeid.')
">'.$langs->trans('PrintTicket').'</button>';
1226 } elseif ((isModEnabled('receiptprinter') && getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term) > 0) || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter
") {
1227 $sectionwithinvoicelink .= ' <button id="buttonprint
" type="button" onclick="DolibarrTakeposPrinting(
'.$placeid.')
">'.$langs->trans('PrintTicket').'</button>';
1229 $sectionwithinvoicelink .= ' <button id="buttonprint
" type="button" onclick="Print(
'.$placeid.')
">'.$langs->trans('PrintTicket').'</button>';
1230 if (getDolGlobalString('TAKEPOS_PRINT_WITHOUT_DETAILS')) {
1231 $sectionwithinvoicelink .= ' <button id="buttonprint
" type="button" onclick="PrintBox(
'.$placeid.', \
'without_details\')">'.$langs->trans(
'PrintWithoutDetails').
'</button>';
1234 $sectionwithinvoicelink .=
' <button id="buttonprint" type="button" onclick="Print('.$placeid.
', 1)">'.$langs->trans(
'GiftReceipt').
'</button>';
1238 $sectionwithinvoicelink .=
' <button id="buttonsend" type="button" onclick="SendTicket('.$placeid.
')">'.$langs->trans(
'SendTicket').
'</button>';
1241 if ($remaintopay <= 0 &&
getDolGlobalString(
'TAKEPOS_AUTO_PRINT_TICKETS') && $action !=
"history") {
1242 $sectionwithinvoicelink .=
'<script type="text/javascript">$("#buttonprint").click();</script>';
1252$form =
new Form($db);
1255if ((
getDolGlobalString(
'TAKEPOS_PHONE_BASIC_LAYOUT') == 1 && $conf->browser->layout ==
'phone') || defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1256 $title =
'TakePOS - Dolibarr '.DOL_VERSION;
1260 $head =
'<meta name="apple-mobile-web-app-title" content="TakePOS"/>
1261 <meta name="apple-mobile-web-app-capable" content="yes">
1262 <meta name="mobile-web-app-capable" content="yes">
1263 <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>';
1264 $arrayofcss = array(
1265 '/takepos/css/pos.css.php',
1267 $arrayofjs = array(
'/takepos/js/jquery.colorbox-min.js');
1270 top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss);
1272 print
'<body>'.
"\n";
1279<script
type=
"text/javascript">
1282<?php
if ($action ==
"valid") {
1283 echo
"var place=0;";
1285var placeid=<?php echo($placeid > 0 ? $placeid : 0); ?>;
1286$(document).ready(
function() {
1287 var idoflineadded = <?php echo(empty($idoflineadded) ? 0 : $idoflineadded); ?>;
1289 $(
'.posinvoiceline').click(
function(){
1290 console.log(
"Click done on "+this.
id);
1291 $(
'.posinvoiceline').removeClass(
"selected");
1292 $(
this).addClass(
"selected");
1296 if (selectedline == this.
id) {
1299 selectedline = this.id;
1301 selectedtext=$(
'#'+selectedline).find(
"td:first").html();
1303 if (defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1304 print
'$("#phonediv1").load("'.DOL_URL_ROOT.
'/takepos/public/auto_order.php?action=editline&token='.
newToken().
'&placeid="+placeid+"&selectedline="+selectedline, function() {
1311 if (idoflineadded > 0)
1313 console.log(
"Auto select "+idoflineadded);
1314 $(
'.posinvoiceline#'+idoflineadded).click();
1318if ($action ==
"order" && !empty($order_receipt_printer1)) {
1319 if (filter_var($conf->global->TAKEPOS_PRINT_SERVER, FILTER_VALIDATE_URL) ==
true) {
1323 url:
'<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>/printer/index.php',
1324 data:
'invoice='+orderprinter1esc
1331 url:
'http://<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>:8111/print',
1333 print $headerorder.$order_receipt_printer1.$footerorder; ?>'
1339if ($action ==
"order" && !empty($order_receipt_printer2)) {
1340 if (filter_var($conf->global->TAKEPOS_PRINT_SERVER, FILTER_VALIDATE_URL) ==
true) {
1344 url:
'<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>/printer/index.php?printer=2',
1345 data:
'invoice='+orderprinter2esc
1352 url:
'http://<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>:8111/print2',
1354 print $headerorder.$order_receipt_printer2.$footerorder; ?>'
1360if ($action ==
"order" && !empty($order_receipt_printer3)) {
1361 if (filter_var($conf->global->TAKEPOS_PRINT_SERVER, FILTER_VALIDATE_URL) ==
true) {
1365 url:
'<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>/printer/index.php?printer=3',
1366 data:
'invoice='+orderprinter3esc
1373if ($action ==
"search" || $action ==
"valid") {
1375 parent.ClearSearch(
true);
1380if ($action ==
"temp" && !empty($ticket_printer1)) {
1384 url:
'http://<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>:8111/print',
1386 print $header_soc.$header_ticket.$body_ticket.$ticket_printer1.$ticket_total.$footer_ticket; ?>'
1391if ($action ==
"search") {
1393 $(
'#search').focus();
1401function SendTicket(
id)
1403 console.log(
"Open box to select the Print/Send form");
1404 $.colorbox({href:
"send.php?facid="+id, width:
"70%", height:
"30%", transition:
"none", iframe:
"true", title:
'<?php echo dol_escape_js($langs->trans("SendTicket")); ?>'});
1408function PrintBox(
id, action) {
1409 console.log(
"Open box before printing");
1410 $.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
"); ?>"});
1414function Print(
id, gift){
1415 console.log(
"Call Print() to generate the receipt.");
1416 $.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")); ?>'});
1420function TakeposPrinting(
id){
1422 console.log(
"TakeposPrinting" +
id);
1423 $.get(
"receipt.php?facid="+
id,
function(data,
status) {
1424 receipt=data.replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g,
'');
1427 url:
'http://<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER
'); ?>:8111/print',
1434function TakeposConnector(
id){
1435 console.log(
"TakeposConnector" +
id);
1436 $.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) {
1439 url:
'<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER
'); ?>/printer/index.php',
1440 data:
'invoice='+data
1448function DolibarrTakeposPrinting(
id) {
1449 console.log(
"DolibarrTakeposPrinting Printing invoice ticket " +
id);
1452 data: { token:
'<?php echo currentToken(); ?>' },
1453 url:
"<?php print DOL_URL_ROOT.'/takepos/ajax/ajax.php?action=printinvoiceticket&token='.newToken().'&term='.urlencode(isset($_SESSION["takeposterminal
"]) ? $_SESSION["takeposterminal
"] : '').'&id='; ?>" + id,
1460function CreditNote() {
1461 $(
"#poslines").load(
"<?php print DOL_URL_ROOT; ?>/takepos/invoice.php?action=creditnote&token=<?php echo newToken() ?>&invoiceid="+placeid,
function() { });
1467 $(
"#poslines").load(
"<?php print DOL_URL_ROOT; ?>/takepos/invoice.php?action=addnote&token=<?php echo newToken() ?>&invoiceid="+placeid+
"&idline="+selectedline, {
"addnote": $(
"#textinput").val() });
1472$( document ).ready(
function() {
1473 console.log(
"Set customer info and sales in header placeid=<?php echo $placeid; ?> status=<?php echo $invoice->statut; ?>");
1476 $s = $langs->trans(
"Customer");
1477 if ($invoice->id > 0 && ($invoice->socid !=
getDolGlobalString($constforcompanyid))) {
1480 $contactids = $invoice->getIdContact(
'external',
'BILLING');
1481 $contactid = $contactids[0];
1482 if ($contactid > 0) {
1484 $contact->fetch($contactid);
1485 $s .=
" - " . $contact->getFullName($langs);
1491 $(
"#customerandsales").html(
'');
1492 $(
"#shoppingcart").html(
'');
1495 $(
"#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>');
1497 $(
"#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>');
1501 $sql =
"SELECT rowid, datec, ref FROM ".MAIN_DB_PREFIX.
"facture";
1502 $sql .=
" WHERE entity IN (".getEntity(
'invoice').
")";
1505 $sql .=
" AND ref LIKE '(PROV-POS".$db->escape(isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'').
"-0%'";
1508 $sql .=
" AND pos_source = '".$db->escape($_SESSION[
"takeposterminal"]).
"'";
1509 $sql .=
" AND module_source = 'takepos'";
1512 $sql .= $db->order(
'datec',
'ASC');
1513 $resql = $db->query($sql);
1516 while ($obj = $db->fetch_object($resql)) {
1517 echo
'$("#shoppingcart").append(\'';
1518 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=\\\'';
1519 $num_sale = str_replace(
")",
"", str_replace(
"(PROV-POS".$_SESSION[
"takeposterminal"].
"-",
"", $obj->ref));
1521 if (str_replace(
"-",
"", $num_sale) > $max_sale) {
1522 $max_sale = str_replace(
"-",
"", $num_sale);
1524 echo
'\\\'; invoiceid=\\\'';
1526 echo
'\\\'; Refresh();">';
1527 if ($placeid == $obj->rowid) {
1528 echo
'<span class="basketselected">';
1530 echo
'<span class="basketnotselected">';
1532 echo
'<span class="fa fa-shopping-cart paddingright"></span>'.dol_print_date($db->jdate($obj->datec),
'%H:%M',
'tzuser');
1536 echo
'$("#shoppingcart").append(\'<a onclick="place=\\\'0-';
1538 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>\');';
1546 $constantforkey =
'CASHDESK_NO_DECREASE_STOCK'. (isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
1547 if (isModEnabled(
'stock')) {
1549 $constantforkey =
'CASHDESK_ID_WAREHOUSE'. (isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
1551 if ($idwarehouse > 0) {
1552 $s =
'<span class="small">';
1554 $warehouse->fetch($idwarehouse);
1555 $s .=
'<span class="hideonsmartphone">'.$langs->trans(
"Warehouse").
'<br></span>'.$warehouse->ref;
1557 $s .=
' ('.$langs->trans(
"Closed").
')';
1560 print
"$('#infowarehouse').html('".dol_escape_js($s).
"');";
1561 print
'$("#infowarehouse").css("display", "inline-block");';
1563 $s =
'<span class="small hideonsmartphone">';
1564 $s .= $langs->trans(
"StockChangeDisabled").
'<br>'.$langs->trans(
"NoWarehouseDefinedForTerminal");
1566 print
"$('#infowarehouse').html('".dol_escape_js($s).
"');";
1567 if (!empty($conf->dol_optimize_smallscreen)) {
1568 print
'$("#infowarehouse").css("display", "none");';
1572 $s =
'<span class="small hideonsmartphone">'.$langs->trans(
"StockChangeDisabled").
'</span>';
1573 print
"$('#infowarehouse').html('".dol_escape_js($s).
"');";
1574 if (!empty($conf->dol_optimize_smallscreen)) {
1575 print
'$("#infowarehouse").css("display", "none");';
1583 if (isModEnabled(
'member') && $invoice->socid > 0 && $invoice->socid !=
getDolGlobalInt($constforcompanyid)) {
1584 $s =
'<span class="small">';
1585 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
1586 $langs->load(
"members");
1587 $s .= $langs->trans(
"Member").
': ';
1589 $result = $adh->fetch(
'',
'', $invoice->socid);
1591 $adh->ref = $adh->getFullName($langs);
1595 $s .= $adh->getFullName($langs);
1596 $s .=
' - '.$adh->type;
1597 if ($adh->datefin) {
1598 $s .=
'<br>'.$langs->trans(
"SubscriptionEndDate").
': '.
dol_print_date($adh->datefin,
'day');
1599 if ($adh->hasDelay()) {
1600 $s .=
" ".img_warning($langs->trans(
"Late"));
1603 $s .=
'<br>'.$langs->trans(
"SubscriptionNotReceived");
1604 if ($adh->statut > 0) {
1605 $s .=
" ".img_warning($langs->trans(
"Late"));
1612 $s .=
'<br>'.$langs->trans(
"ThirdpartyNotLinkedToMember");
1617 $(
"#moreinfo").html(
'<?php print dol_escape_js($s); ?>');
1624 echo
"function CustomerDisplay(){";
1625 echo
"var line1='".$CUSTOMER_DISPLAY_line1.
"'.substring(0,20);";
1626 echo
"line1=line1.padEnd(20);";
1627 echo
"var line2='".$CUSTOMER_DISPLAY_line2.
"'.substring(0,20);";
1628 echo
"line2=line2.padEnd(20);";
1631 data: { text: line1+line2 },
1632 url: '".getDolGlobalString(
'TAKEPOS_PRINT_SERVER').
"/display/index.php',
1643if (!empty($conf->use_javascript_ajax)) {
1644 print
"\n".
'<!-- Includes JS Footer of Dolibarr -->'.
"\n";
1645 print
'<script src="'.DOL_URL_ROOT.
'/core/js/lib_foot.js.php?lang='.$langs->defaultlang.
'"></script>'.
"\n";