116 header($_SERVER[
'SERVER_PROTOCOL'].
' 500 Internal Server Error',
true, 500);
122$number =
GETPOST(
'number',
'alpha');
125$desc =
GETPOST(
'desc',
'alphanohtml');
138if ($pay ==
'cheque') {
145 $sql =
"SELECT id FROM ".MAIN_DB_PREFIX.
"c_paiement";
146 $sql .=
" WHERE entity IN (".getEntity(
'c_paiement').
")";
147 $sql .=
" AND code = '".$db->escape($paycode).
"'";
148 $resql = $db->query($sql);
150 $obj = $db->fetch_object($resql);
152 $paiementid = $obj->id;
159 $ret = $invoice->fetch($invoiceid);
161 $ret = $invoice->fetch(
'',
'(PROV-POS'.$takeposterminal.
'-'.$place.
')');
164 $placeid = $invoice->id;
167$constforcompanyid =
'CASHDESK_ID_THIRDPARTY'.$takeposterminal;
170if ($invoice->socid > 0) {
171 $soc->fetch($invoice->socid);
177if (isModEnabled(
'project') &&
getDolGlobalInt(
"CASHDESK_ID_PROJECT".$takeposterminal)) {
178 $invoice->fk_project =
getDolGlobalInt(
"CASHDESK_ID_PROJECT".$takeposterminal);
182if (isModEnabled(
'multicurrency') && !empty($_SESSION[
"takeposcustomercurrency"])) {
183 if ($invoice->multicurrency_code != $_SESSION[
"takeposcustomercurrency"]) {
184 $invoice->setMulticurrencyCode($_SESSION[
"takeposcustomercurrency"]);
188$term = empty($_SESSION[
"takeposterminal"]) ? 1 : $_SESSION[
"takeposterminal"];
195$parameters = array();
196$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $invoice, $action);
201if (empty($reshook)) {
203 if ($action ==
'valid' && $user->hasRight(
'facture',
'creer')) {
211 $bankaccount =
getDolGlobalInt(
'CASHDESK_ID_BANKACCOUNT_CASH'.$_SESSION[
"takeposterminal"]);
212 } elseif ($pay ==
"CHQ") {
213 $bankaccount =
getDolGlobalInt(
'CASHDESK_ID_BANKACCOUNT_CHEQUE'.$_SESSION[
"takeposterminal"]);
215 $accountname =
"CASHDESK_ID_BANKACCOUNT_".$pay.$_SESSION[
"takeposterminal"];
220 if ($bankaccount <= 0 && $pay !=
"delayed" && isModEnabled(
"bank")) {
221 $errormsg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"BankAccount"));
229 $invoice->fetch($placeid);
233 if ($invoice->total_ttc < 0) {
234 $invoice->type = $invoice::TYPE_CREDIT_NOTE;
236 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"facture";
237 $sql .=
" WHERE entity IN (".getEntity(
'invoice').
")";
238 $sql .=
" AND fk_soc = ".((int) $invoice->socid);
239 $sql .=
" AND type <> ".Facture::TYPE_CREDIT_NOTE;
240 $sql .=
" AND fk_statut >= ".$invoice::STATUS_VALIDATED;
241 $sql .=
" ORDER BY rowid DESC";
243 $resql = $db->query($sql);
245 $obj = $db->fetch_object($resql);
246 $fk_source = $obj->rowid;
247 if ($fk_source ==
null) {
248 fail($langs->transnoentitiesnoconv(
"NoPreviousBillForCustomer"));
251 fail($langs->transnoentitiesnoconv(
"NoPreviousBillForCustomer"));
253 $invoice->fk_facture_source = $fk_source;
254 $invoice->update($user);
257 $constantforkey =
'CASHDESK_NO_DECREASE_STOCK'.(isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
264 if ($invoice->getRemainToPay() > 0) {
270 } elseif (count($invoice->lines) == 0) {
274 } elseif (isModEnabled(
'stock') && !isModEnabled(
'productbatch') && $allowstockchange) {
279 $conf->global->STOCK_CALCULATE_ON_BILL = 1;
281 $constantforkey =
'CASHDESK_ID_WAREHOUSE'.$_SESSION[
"takeposterminal"];
282 dol_syslog(
"Validate invoice with stock change. Warehouse defined into constant ".$constantforkey.
" = ".
getDolGlobalString($constantforkey));
287 $res = $invoice->validate($user,
'',
getDolGlobalInt($constantforkey), 0, $batch_rule);
290 $conf->global->STOCK_CALCULATE_ON_BILL = $savconst;
293 $res = $invoice->validate($user);
296 $langs->load(
"admin");
297 dol_htmloutput_errors($invoice->error ==
'NotConfigured' ? $langs->trans(
"NotConfigured").
' (TakePos numbering module)' : $invoice->error, $invoice->errors, 1);
302 if (!$error && $res >= 0) {
303 $remaintopay = $invoice->getRemainToPay();
304 if ($remaintopay > 0) {
306 $payment->datepaye = $now;
307 $payment->fk_account = $bankaccount;
308 $payment->amounts[$invoice->id] = $amountofpayment;
315 if ($amountofpayment <= 0 || $amountofpayment > $remaintopay) {
316 $payment->amounts[$invoice->id] = $remaintopay;
319 $payment->paiementid = $paiementid;
320 $payment->num_payment = $invoice->ref;
322 if ($pay !=
"delayed") {
323 $result = $payment->create($user);
328 $res = $payment->addPaymentToBank($user,
'payment',
'(CustomerInvoicePayment)', $bankaccount,
'',
'');
334 $remaintopay = $invoice->getRemainToPay();
340 if ($remaintopay == 0) {
341 dol_syslog(
"Invoice is paid, so we set it to status Paid");
342 $result = $invoice->setPaid($user);
347 $invoice->setPaymentMethods($paiementid);
349 dol_syslog(
"Invoice is not paid, remain to pay = ".$remaintopay);
356 if (!$error && $res >= 0) {
357 if (isModEnabled(
'stock') && isModEnabled(
'productbatch') && $allowstockchange) {
359 dol_syslog(
"Now we record the stock movement for each qualified line");
362 require_once DOL_DOCUMENT_ROOT .
"/product/stock/class/mouvementstock.class.php";
363 $constantforkey =
'CASHDESK_ID_WAREHOUSE'.$_SESSION[
"takeposterminal"];
366 $labeltakeposmovement =
'TakePOS - '.$langs->trans(
"Invoice").
' '.$invoice->ref;
368 foreach ($invoice->lines as $line) {
370 $warehouseid = ($line->fk_warehouse ? $line->fk_warehouse :
getDolGlobalInt($constantforkey));
373 if ($line->batch !=
'' && $warehouseid > 0) {
375 $prod_batch->find(0,
'',
'', $line->batch, $warehouseid);
378 $mouvP->setOrigin($invoice->element, $invoice->id);
380 $res = $mouvP->livraison($user, $line->fk_product, $warehouseid, $line->qty, $line->price, $labeltakeposmovement,
'',
'',
'', $prod_batch->batch, $prod_batch->id, $inventorycode);
387 $mouvP->setOrigin($invoice->element, $invoice->id);
389 $res = $mouvP->livraison($user, $line->fk_product, $warehouseid, $line->qty, $line->price, $labeltakeposmovement,
'',
'',
'',
'', 0, $inventorycode);
399 if (!$error && $res >= 0) {
405 if ($action ==
'creditnote' && $user->hasRight(
'facture',
'creer')) {
408 $creditnote =
new Facture($db);
409 $creditnote->socid = $invoice->socid;
411 $creditnote->module_source =
'takepos';
412 $creditnote->pos_source = isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'' ;
414 $creditnote->fk_facture_source = $placeid;
417 $creditnote->create($user);
419 foreach ($invoice->lines as $line) {
421 if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) {
426 if (!empty($invoice->situation_counter)) {
427 $source_fk_prev_id = $line->fk_prev_id;
428 $line->fk_prev_id = $line->id;
429 if (!empty($invoice->tab_previous_situation_invoice)) {
432 $tab_jumped_credit_notes = array();
433 $lineIndex = count($invoice->tab_previous_situation_invoice) - 1;
434 $searchPreviousInvoice =
true;
435 while ($searchPreviousInvoice) {
436 if ($invoice->tab_previous_situation_invoice[$lineIndex]->situation_cycle_ref || $lineIndex < 1) {
437 $searchPreviousInvoice =
false;
441 $tab_jumped_credit_notes[$lineIndex] = $invoice->tab_previous_situation_invoice[$lineIndex]->id;
447 $maxPrevSituationPercent = 0;
448 foreach ($invoice->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine) {
449 if ($prevLine->id == $source_fk_prev_id) {
450 $maxPrevSituationPercent = max($maxPrevSituationPercent, $prevLine->situation_percent);
453 $line->total_ht = $line->total_ht - $prevLine->total_ht;
454 $line->total_tva = $line->total_tva - $prevLine->total_tva;
455 $line->total_ttc = $line->total_ttc - $prevLine->total_ttc;
456 $line->total_localtax1 = $line->total_localtax1 - $prevLine->total_localtax1;
457 $line->total_localtax2 = $line->total_localtax2 - $prevLine->total_localtax2;
459 $line->multicurrency_subprice = $line->multicurrency_subprice - $prevLine->multicurrency_subprice;
460 $line->multicurrency_total_ht = $line->multicurrency_total_ht - $prevLine->multicurrency_total_ht;
461 $line->multicurrency_total_tva = $line->multicurrency_total_tva - $prevLine->multicurrency_total_tva;
462 $line->multicurrency_total_ttc = $line->multicurrency_total_ttc - $prevLine->multicurrency_total_ttc;
467 $line->situation_percent = $maxPrevSituationPercent - $line->situation_percent;
472 $maxPrevSituationPercent = 0;
473 foreach ($tab_jumped_credit_notes as $index => $creditnoteid) {
474 foreach ($invoice->tab_previous_situation_invoice[$index]->lines as $prevLine) {
475 if ($prevLine->fk_prev_id == $source_fk_prev_id) {
476 $maxPrevSituationPercent = $prevLine->situation_percent;
478 $line->total_ht -= $prevLine->total_ht;
479 $line->total_tva -= $prevLine->total_tva;
480 $line->total_ttc -= $prevLine->total_ttc;
481 $line->total_localtax1 -= $prevLine->total_localtax1;
482 $line->total_localtax2 -= $prevLine->total_localtax2;
484 $line->multicurrency_subprice -= $prevLine->multicurrency_subprice;
485 $line->multicurrency_total_ht -= $prevLine->multicurrency_total_ht;
486 $line->multicurrency_total_tva -= $prevLine->multicurrency_total_tva;
487 $line->multicurrency_total_ttc -= $prevLine->multicurrency_total_ttc;
493 $line->situation_percent += $maxPrevSituationPercent;
501 $line->fk_facture = $creditnote->id;
502 $line->fk_parent_line = $fk_parent_line;
504 $line->subprice = -$line->subprice;
506 $line->total_ht = -$line->total_ht;
507 $line->total_tva = -$line->total_tva;
508 $line->total_ttc = -$line->total_ttc;
509 $line->total_localtax1 = -$line->total_localtax1;
510 $line->total_localtax2 = -$line->total_localtax2;
512 $line->multicurrency_subprice = -$line->multicurrency_subprice;
513 $line->multicurrency_total_ht = -$line->multicurrency_total_ht;
514 $line->multicurrency_total_tva = -$line->multicurrency_total_tva;
515 $line->multicurrency_total_ttc = -$line->multicurrency_total_ttc;
517 $result = $line->insert(0, 1);
519 $creditnote->lines[] = $line;
522 if ($result > 0 && $line->product_type == 9) {
523 $fk_parent_line = $result;
526 $creditnote->update_price(1);
530 $constantforkey =
'CASHDESK_NO_DECREASE_STOCK'.(isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
533 if (isModEnabled(
'stock') && !isModEnabled(
'productbatch') && $allowstockchange) {
537 $conf->global->STOCK_CALCULATE_ON_BILL = 1;
539 $constantforkey =
'CASHDESK_ID_WAREHOUSE'.(isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
541 dol_syslog(
"Validate invoice with stock change into warehouse defined into constant ".$constantforkey.
" = ".
getDolGlobalString($constantforkey).
" or warehouseid= ".$warehouseid.
" if defined.");
546 $res = $creditnote->validate($user,
'',
getDolGlobalString($constantforkey), 0, $batch_rule);
553 $conf->global->STOCK_CALCULATE_ON_BILL = $savconst;
555 $res = $creditnote->validate($user);
559 if (!$error && $res >= 0) {
560 if (isModEnabled(
'stock') && isModEnabled(
'productbatch') && $allowstockchange) {
562 dol_syslog(
"Now we record the stock movement for each qualified line");
565 require_once DOL_DOCUMENT_ROOT .
"/product/stock/class/mouvementstock.class.php";
566 $constantforkey =
'CASHDESK_ID_WAREHOUSE'.$_SESSION[
"takeposterminal"];
569 $labeltakeposmovement =
'TakePOS - '.$langs->trans(
"CreditNote").
' '.$creditnote->ref;
571 foreach ($creditnote->lines as $line) {
573 $warehouseid = ($line->fk_warehouse ? $line->fk_warehouse :
getDolGlobalInt($constantforkey));
576 if ($line->batch !=
'' && $warehouseid > 0) {
581 $mouvP->setOrigin($creditnote->element, $creditnote->id);
583 $res = $mouvP->reception($user, $line->fk_product, $warehouseid, $line->qty, $line->price, $labeltakeposmovement,
'',
'', $line->batch,
'', 0, $inventorycode);
590 $mouvP->setOrigin($creditnote->element, $creditnote->id);
592 $res = $mouvP->reception($user, $line->fk_product, $warehouseid, $line->qty, $line->price, $labeltakeposmovement,
'',
'',
'',
'', 0, $inventorycode);
602 if (!$error && $res >= 0) {
605 $creditnote->id = $placeid;
610 if (($action ==
'history' || $action ==
'creditnote') && $user->hasRight(
'takepos',
'run')) {
611 if ($action ==
'creditnote' && $creditnote->id > 0) {
612 $placeid = $creditnote->id;
618 $invoice->fetch($placeid);
622 if (($action ==
"addline" || $action ==
"freezone") && $placeid == 0 && ($user->hasRight(
'takepos',
'run') || defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
625 $dolnowtzuserrel =
dol_now(
'tzuserrel');
629 $dateinvoice =
dol_mktime(0, 0, 0, (
int) $monthuser, (
int) $dayuser, (
int) $yearuser,
'tzserver');
631 include_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
632 $invoice->date = $dateinvoice;
634 $invoice->module_source =
'takepos';
635 $invoice->pos_source = isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'' ;
636 $invoice->entity = !empty($_SESSION[
"takeposinvoiceentity"]) ? $_SESSION[
"takeposinvoiceentity"] : $conf->entity;
638 if ($invoice->socid <= 0) {
639 $langs->load(
'errors');
645 $placeid = $invoice->create($user);
649 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facture set ref='(PROV-POS".$_SESSION[
"takeposterminal"].
"-".$place.
")' where rowid = ".((int) $placeid);
650 $resql = $db->query($sql);
664 if ($action ==
"addline" && ($user->hasRight(
'takepos',
'run') || defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
666 $prod->fetch($idproduct);
669 $customer->fetch($invoice->socid);
671 $datapriceofproduct = $prod->getSellPrice($mysoc, $customer, 0);
673 $qty = GETPOSTISSET(
'qty') ?
GETPOSTINT(
'qty') : 1;
674 $price = $datapriceofproduct[
'pu_ht'];
675 $price_ttc = $datapriceofproduct[
'pu_ttc'];
677 $price_base_type = empty($datapriceofproduct[
'price_base_type']) ?
'HT' : $datapriceofproduct[
'price_base_type'];
678 $tva_tx = $datapriceofproduct[
'tva_tx'];
679 $tva_npr = $datapriceofproduct[
'tva_npr'];
682 $localtax1_tx =
get_localtax($tva_tx, 1, $customer, $mysoc, $tva_npr);
683 $localtax2_tx =
get_localtax($tva_tx, 2, $customer, $mysoc, $tva_npr);
686 if (isModEnabled(
'productbatch') && isModEnabled(
'stock')) {
687 $batch =
GETPOST(
'batch',
'alpha');
689 if (!empty($batch)) {
690 $action =
"setbatch";
691 } elseif ($prod->status_batch > 0) {
696 $prod->load_stock(
'warehouseopen');
698 $constantforkey =
'CASHDESK_ID_WAREHOUSE'.$_SESSION[
"takeposterminal"];
702 foreach ($prod->stock_warehouse as $tmpwarehouseid => $tmpval) {
707 if (!empty($prod->stock_warehouse[$tmpwarehouseid]) && is_array($prod->stock_warehouse[$tmpwarehouseid]->detail_batch)) {
708 if (is_object($prod->stock_warehouse[$tmpwarehouseid]) && count($prod->stock_warehouse[$tmpwarehouseid]->detail_batch)) {
709 foreach ($prod->stock_warehouse[$tmpwarehouseid]->detail_batch as $dbatch) {
718 echo
"function addbatch(batch, warehouseid) {\n";
719 echo
"console.log('We add batch '+batch+' from warehouse id '+warehouseid);\n";
720 echo
'$("#poslines").load("'.DOL_URL_ROOT.
'/takepos/invoice.php?action=addline&batch="+encodeURI(batch)+"&warehouseid="+warehouseid+"&place='.$place.
'&idproduct='.$idproduct.
'&token='.
newToken().
'", function() {});'.
"\n";
725 echo
"<center>".$langs->trans(
"SearchIntoBatch").
": <b> $nbofsuggested </b></center><br><table>";
726 foreach ($prod->stock_warehouse as $tmpwarehouseid => $tmpval) {
731 if (!empty($prod->stock_warehouse[$tmpwarehouseid]) && is_array($prod->stock_warehouse[$tmpwarehouseid]->detail_batch)) {
732 foreach ($prod->stock_warehouse[$tmpwarehouseid]->detail_batch as $dbatch) {
733 $batchStock = + $dbatch->qty;
734 $quantityToBeDelivered = 1;
735 $deliverableQty = min($quantityToBeDelivered, $batchStock);
737 print
'<!-- subj='.$suggestednb.
'/'.$nbofsuggested.
' -->';
738 print
'<!-- Show details of lot/serial in warehouseid='.$tmpwarehouseid.
' -->';
739 print
'<td class="left">';
741 $detail .=
'<span class="opacitymedium">'.$langs->trans(
"LotSerial").
':</span> '.$dbatch->batch;
748 $detail .=
'</td><td>';
749 $detail .=
'<span class="opacitymedium">'.$langs->trans(
"Qty").
':</span> '.$dbatch->qty;
750 $detail .=
'</td><td>';
751 $detail .=
' <button class="marginleftonly" onclick="addbatch(\''.dol_escape_js($dbatch->batch).
'\',
'.$tmpwarehouseid.')
">'.$langs->trans("Select
")."</
button>
";
755 $quantityToBeDelivered -= $deliverableQty;
756 if ($quantityToBeDelivered < 0) {
757 $quantityToBeDelivered = 0;
766 print '</body></html>';
772 if (getDolGlobalString('TAKEPOS_SUPPLEMENTS')) {
773 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
774 $cat = new Categorie($db);
775 $categories = $cat->containing($idproduct, 'product');
776 $found = (array_search(getDolGlobalInt('TAKEPOS_SUPPLEMENTS_CATEGORY'), array_column($categories, 'id')));
777 if ($found !== false) { // If this product is a supplement
778 $sql = "SELECT fk_parent_line FROM
".MAIN_DB_PREFIX."facturedet where
rowid =
".((int) $selectedline);
779 $resql = $db->query($sql);
780 $row = $db->fetch_array($resql);
781 if ($row[0] == null) {
782 $parent_line = $selectedline;
784 $parent_line = $row[0]; //If the parent line is already a supplement, add the supplement to the main product
791 // Group if enabled. Skip group if line already sent to the printer
792 if (getDolGlobalString('TAKEPOS_GROUP_SAME_PRODUCT')) {
793 foreach ($invoice->lines as $line) {
794 if ($line->product_ref == $prod->ref) {
795 if ($line->special_code == 4) {
797 } // If this line is sended to printer create new line
798 // check if qty in stock
799 if (getDolGlobalString('TAKEPOS_QTY_IN_STOCK') && (($line->qty + $qty) > $prod->stock_reel)) {
800 $invoice->error = $langs->trans("ErrorStockIsNotEnough
");
801 dol_htmloutput_errors($invoice->error, $invoice->errors, 1);
805 $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);
807 dol_htmloutput_errors($invoice->error, $invoice->errors, 1);
809 $idoflineadded = $line->id;
815 if ($idoflineadded <= 0 && empty($err)) {
816 $invoice->fetch_thirdparty();
817 $array_options = array();
819 $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);
821 /* setup of margin calculation */
822 if (isset($conf->global->MARGIN_TYPE)) {
823 if (getDolGlobalString('MARGIN_TYPE') == 'pmp' && !empty($prod->pmp)) {
824 $line['fk_fournprice'] = null;
825 $line['pa_ht'] = $prod->pmp;
826 } elseif (getDolGlobalString('MARGIN_TYPE') == 'costprice' && !empty($prod->cost_price)) {
827 $line['fk_fournprice'] = null;
828 $line['pa_ht'] = $prod->cost_price;
830 // default is fournprice
831 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
832 $pf = new ProductFournisseur($db);
833 if ($pf->find_min_price_product_fournisseur($idproduct, $qty) > 0) {
834 $line['fk_fournprice'] = $pf->product_fourn_price_id;
835 $line['pa_ht'] = $pf->fourn_unitprice_with_discount;
836 if (getDolGlobalString('PRODUCT_CHARGES') && $pf->fourn_charges > 0) {
837 $line['pa_ht'] += $pf->fourn_charges / $pf->fourn_qty;
843 // complete line by hook
844 $parameters = array('prod' => $prod, 'line' => $line);
845 $reshook = $hookmanager->executeHooks('completeTakePosAddLine', $parameters, $invoice, $action); // Note that $action and $line may have been modified by some hooks
847 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
851 if (empty($reshook)) {
852 if (!empty($hookmanager->resArray)) {
853 $line = $hookmanager->resArray;
856 // check if qty in stock
857 if (getDolGlobalString('TAKEPOS_QTY_IN_STOCK') && $qty > $prod->stock_reel) {
858 $invoice->error = $langs->trans("ErrorStockIsNotEnough
");
859 dol_htmloutput_errors($invoice->error, $invoice->errors, 1);
864 $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);
868 if (getDolGlobalString('TAKEPOS_CUSTOMER_DISPLAY')) {
869 $CUSTOMER_DISPLAY_line1 = $prod->label;
870 $CUSTOMER_DISPLAY_line2 = price($price_ttc);
874 $invoice->fetch($placeid);
877 // If we add a line by submitting freezone form (invoice exists here because it was created juste before if it didn't exists)
878 if ($action == "freezone
" && $user->hasRight('takepos', 'run')) {
879 $customer = new Societe($db);
880 $customer->fetch($invoice->socid);
882 $tva_tx = GETPOST('tva_tx', 'alpha');
884 if (!preg_match('/\((.*)\)/', $tva_tx)) {
885 $tva_tx = price2num($tva_tx);
888 $tva_tx = get_default_tva($mysoc, $customer);
892 $localtax1_tx = get_localtax($tva_tx, 1, $customer, $mysoc, $tva_npr);
893 $localtax2_tx = get_localtax($tva_tx, 2, $customer, $mysoc, $tva_npr);
895 $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);
897 dol_htmloutput_errors($invoice->error, $invoice->errors, 1);
899 $invoice->fetch($placeid);
902 if ($action == "addnote
" && ($user->hasRight('takepos', 'run') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
903 $desc = GETPOST('addnote', 'alpha');
905 $invoice->update_note($desc, '_public');
907 foreach ($invoice->lines as $line) {
908 if ($line->id == $idline) {
909 $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);
913 $invoice->fetch($placeid);
916 if ($action == "deleteline
" && ($user->hasRight('takepos', 'run') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
918 $permissiontoupdateline = ($user->hasRight('takepos', 'editlines') && ($user->hasRight('takepos', 'editorderedlines') || $line->special_code != "4
"));
919 if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
920 if ($invoice->status == $invoice::STATUS_DRAFT && $invoice->pos_source && $invoice->module_source == 'takepos') {
921 $permissiontoupdateline = true;
922 // TODO Add also a test on $_SESSION('publicobjectid'] defined at creation of object
923 // TODO Check also that invoice->ref is (PROV-POS1-2) with 1 = terminal and 2, the invoice ID
927 if ($idline > 0 && $placeid > 0) { // If invoice exists and line selected. To avoid errors if deleted from another device or no line selected.
928 $invoice->deleteLine($idline);
929 $invoice->fetch($placeid);
930 } elseif ($placeid > 0) { // If invoice exists but no line selected, proceed to delete last line.
931 $sql = "SELECT
rowid FROM
".MAIN_DB_PREFIX."facturedet where fk_facture =
".((int) $placeid)." ORDER BY
rowid DESC
";
932 $resql = $db->query($sql);
933 $row = $db->fetch_array($resql);
934 $deletelineid = $row[0];
935 $invoice->deleteLine($deletelineid);
936 $invoice->fetch($placeid);
939 if (count($invoice->lines) == 0) {
940 $invoice->delete($user);
942 if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
943 header("Location:
".DOL_URL_ROOT."/takepos/public/auto_order.php
");
945 header("Location:
".DOL_URL_ROOT."/takepos/invoice.php
");
951 // Action to delete or discard an invoice
952 if ($action == "delete
" && ($user->hasRight('takepos', 'run') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
953 // $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.
955 $result = $invoice->fetch($placeid);
957 if ($result > 0 && $invoice->statut == Facture::STATUS_DRAFT) {
960 // We delete the lines
962 foreach ($invoice->lines as $line) {
963 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
964 $tmpres = $invoice->deleteLine($line->id);
971 $sql = "UPDATE
".MAIN_DB_PREFIX."facture
";
972 $varforconst = 'CASHDESK_ID_THIRDPARTY'.$_SESSION["takeposterminal
"];
973 $sql .= " SET fk_soc =
".((int) getDolGlobalString($varforconst)).",
";
974 $sql .= " datec =
'".$db->idate(dol_now())."'";
975 $sql .= " WHERE entity IN (
".getEntity('invoice').")
";
976 $sql .= " AND
ref =
'(PROV-POS".$db->escape($_SESSION["takeposterminal"]."-".$place).")'";
977 $resql1 = $db->query($sql);
979 if ($resdeletelines && $resql1) {
985 $invoice->fetch($placeid);
990 if ($action == "updateqty
") { // Test on permission is done later
991 foreach ($invoice->lines as $line) {
992 if ($line->id == $idline) {
993 $permissiontoupdateline = ($user->hasRight('takepos', 'editlines') && ($user->hasRight('takepos', 'editorderedlines') || $line->special_code != "4
"));
994 if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
995 if ($invoice->status == $invoice::STATUS_DRAFT && $invoice->pos_source && $invoice->module_source == 'takepos') {
996 $permissiontoupdateline = true;
997 // TODO Add also a test on $_SESSION('publicobjectid'] defined at creation of object
998 // TODO Check also that invoice->ref is (PROV-POS1-2) with 1 = terminal and 2, the invoice ID
1001 if (!$permissiontoupdateline) {
1002 dol_htmloutput_errors($langs->trans("NotEnoughPermissions
", "TakePos
").' - No permission to updateqty', null, 1);
1004 $vatratecode = $line->tva_tx;
1005 if ($line->vat_src_code) {
1006 $vatratecode .= ' ('.$line->vat_src_code.')';
1009 $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);
1014 $invoice->fetch($placeid);
1017 if ($action == "updateprice
") { // Test on permission is done later
1018 $customer = new Societe($db);
1019 $customer->fetch($invoice->socid);
1021 foreach ($invoice->lines as $line) {
1022 if ($line->id == $idline) {
1023 $prod = new Product($db);
1024 $prod->fetch($line->fk_product);
1025 $datapriceofproduct = $prod->getSellPrice($mysoc, $customer, 0);
1026 $price_min = $datapriceofproduct['price_min'];
1027 $usercanproductignorepricemin = ((getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !$user->hasRight('produit', 'ignore_price_min_advance')) || !getDolGlobalString('MAIN_USE_ADVANCED_PERMS'));
1028 $pu_ht = price2num($number / (1 + ($line->tva_tx / 100)), 'MU');
1030 if ($usercanproductignorepricemin && (!empty($price_min) && (price2num($pu_ht) * (1 - price2num($line->remise_percent) / 100) < price2num($price_min)))) {
1031 $langs->load("products
");
1032 dol_htmloutput_errors($langs->trans("CantBeLessThanMinPrice
", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, -1, $conf->currency)));
1033 //echo $langs->trans("CantBeLessThanMinPrice
");
1035 $permissiontoupdateline = ($user->hasRight('takepos', 'editlines') && ($user->hasRight('takepos', 'editorderedlines') || $line->special_code != "4
"));
1036 if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1037 if ($invoice->status == $invoice::STATUS_DRAFT && $invoice->pos_source && $invoice->module_source == 'takepos') {
1038 $permissiontoupdateline = true;
1039 // TODO Add also a test on $_SESSION('publicobjectid'] defined at creation of object
1040 // TODO Check also that invoice->ref is (PROV-POS1-2) with 1 = terminal and 2, the invoice ID
1044 $vatratecode = $line->tva_tx;
1045 if ($line->vat_src_code) {
1046 $vatratecode .= ' ('.$line->vat_src_code.')';
1049 if (!$permissiontoupdateline) {
1050 dol_htmloutput_errors($langs->trans("NotEnoughPermissions
", "TakePos
").' - No permission to updateprice', null, 1);
1051 } elseif (getDolGlobalInt('TAKEPOS_CHANGE_PRICE_HT') == 1) {
1052 $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);
1054 $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);
1061 $invoice->fetch($placeid);
1064 if ($action == "updatereduction
") { // Test on permission is done later
1065 $customer = new Societe($db);
1066 $customer->fetch($invoice->socid);
1068 foreach ($invoice->lines as $line) {
1069 if ($line->id == $idline) {
1070 dol_syslog("updatereduction Process line
".$line->id.' to apply discount of '.$number.'%');
1072 $prod = new Product($db);
1073 $prod->fetch($line->fk_product);
1075 $datapriceofproduct = $prod->getSellPrice($mysoc, $customer, 0);
1076 $price_min = $datapriceofproduct['price_min'];
1077 $usercanproductignorepricemin = ((getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !$user->hasRight('produit', 'ignore_price_min_advance')) || !getDolGlobalString('MAIN_USE_ADVANCED_PERMS'));
1079 $pu_ht = price2num($line->subprice / (1 + ($line->tva_tx / 100)), 'MU');
1082 if ($usercanproductignorepricemin && (!empty($price_min) && (price2num($line->subprice) * (1 - price2num($number) / 100) < price2num($price_min)))) {
1083 $langs->load("products
");
1084 dol_htmloutput_errors($langs->trans("CantBeLessThanMinPrice
", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, -1, $conf->currency)));
1086 $permissiontoupdateline = ($user->hasRight('takepos', 'editlines') && ($user->hasRight('takepos', 'editorderedlines') || $line->special_code != "4
"));
1087 if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1088 if ($invoice->status == $invoice::STATUS_DRAFT && $invoice->pos_source && $invoice->module_source == 'takepos') {
1089 $permissiontoupdateline = true;
1090 // TODO Add also a test on $_SESSION('publicobjectid'] defined at creation of object
1091 // TODO Check also that invoice->ref is (PROV-POS1-2) with 1 = terminal and 2, the invoice ID
1094 if (!$permissiontoupdateline) {
1095 dol_htmloutput_errors($langs->trans("NotEnoughPermissions
", "TakePos
"), null, 1);
1097 $vatratecode = $line->tva_tx;
1098 if ($line->vat_src_code) {
1099 $vatratecode .= ' ('.$line->vat_src_code.')';
1101 $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);
1108 $invoice->fetch($placeid);
1109 } elseif ($action == 'update_reduction_global' && $user->hasRight('takepos', 'editlines')) {
1110 foreach ($invoice->lines as $line) {
1111 $vatratecode = $line->tva_tx;
1112 if ($line->vat_src_code) {
1113 $vatratecode .= ' ('.$line->vat_src_code.')';
1115 $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);
1118 $invoice->fetch($placeid);
1121 if ($action == "setbatch
" && ($user->hasRight('takepos', 'run') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
1122 $constantforkey = 'CASHDESK_ID_WAREHOUSE'.$_SESSION["takeposterminal
"];
1123 $warehouseid = (GETPOSTINT('warehouseid') > 0 ? GETPOSTINT('warehouseid') : getDolGlobalInt($constantforkey)); // Get the warehouse id from GETPOSTINT('warehouseid'), otherwise use default setup.
1124 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet SET batch =
'".$db->escape($batch)."', fk_warehouse =
".((int) $warehouseid);
1125 $sql .= " WHERE
rowid=
".((int) $idoflineadded);
1129 if ($action == "order
" && $placeid != 0 && ($user->hasRight('takepos', 'run') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
1130 include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
1131 if ((isModEnabled('receiptprinter') && getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term) > 0) || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter
" || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector
") {
1132 require_once DOL_DOCUMENT_ROOT.'/core/class/dolreceiptprinter.class.php';
1133 $printer = new dolReceiptPrinter($db);
1136 $sql = "SELECT label FROM
".MAIN_DB_PREFIX."takepos_floor_tables where
rowid=
".((int) $place);
1137 $resql = $db->query($sql);
1138 $row = $db->fetch_object($resql);
1139 $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>';
1140 $footerorder = '</tbody></table>'.dol_print_date(dol_now(), 'dayhour').'<br></html>';
1141 $order_receipt_printer1 = "";
1142 $order_receipt_printer2 = "";
1143 $order_receipt_printer3 = "";
1144 $catsprinter1 = explode(';', getDolGlobalString('TAKEPOS_PRINTED_CATEGORIES_1'));
1145 $catsprinter2 = explode(';', getDolGlobalString('TAKEPOS_PRINTED_CATEGORIES_2'));
1146 $catsprinter3 = explode(';', getDolGlobalString('TAKEPOS_PRINTED_CATEGORIES_3'));
1148 foreach ($invoice->lines as $line) {
1149 if ($line->special_code == "4
") {
1152 $c = new Categorie($db);
1153 $existing = $c->containing($line->fk_product, Categorie::TYPE_PRODUCT, 'id');
1154 $result = array_intersect($catsprinter1, $existing);
1155 $count = count($result);
1156 if (!$line->fk_product) {
1157 $count++; // Print Free-text item (Unassigned printer) to Printer 1
1161 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet set special_code=
'1' where
rowid=
".$line->id; //Set to print on printer 1
1163 $order_receipt_printer1 .= '<tr><td class="left
">';
1164 if ($line->fk_product) {
1165 $order_receipt_printer1 .= $line->product_label;
1167 $order_receipt_printer1 .= $line->description;
1169 $order_receipt_printer1 .= '</td><td class="right
">'.$line->qty;
1170 if (!empty($line->array_options['options_order_notes'])) {
1171 $order_receipt_printer1 .= "<br>(
".$line->array_options['options_order_notes'].")
";
1173 $order_receipt_printer1 .= '</td></tr>';
1176 if (((isModEnabled('receiptprinter') && getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term) > 0) || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter
" || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector
") && $linestoprint > 0) {
1177 $invoice->fetch($placeid); //Reload object before send to printer
1178 $printer->orderprinter = 1;
1180 echo "var orderprinter1esc=
'";
1181 $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
1184 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet
set special_code=
'4' where special_code=
'1' and fk_facture=
".$invoice->id; // Set as printed
1186 $invoice->fetch($placeid); //Reload object after set lines as printed
1189 foreach ($invoice->lines as $line) {
1190 if ($line->special_code == "4
") {
1193 $c = new Categorie($db);
1194 $existing = $c->containing($line->fk_product, Categorie::TYPE_PRODUCT, 'id');
1195 $result = array_intersect($catsprinter2, $existing);
1196 $count = count($result);
1199 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet
set special_code=
'2' where
rowid=
".$line->id; //Set to print on printer 2
1201 $order_receipt_printer2 .= '<tr>'.$line->product_label.'<td class="right
">'.$line->qty;
1202 if (!empty($line->array_options['options_order_notes'])) {
1203 $order_receipt_printer2 .= "<br>(
".$line->array_options['options_order_notes'].")
";
1205 $order_receipt_printer2 .= '</td></tr>';
1208 if (((isModEnabled('receiptprinter') && getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term) > 0) || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter
" || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector
") && $linestoprint > 0) {
1209 $invoice->fetch($placeid); //Reload object before send to printer
1210 $printer->orderprinter = 2;
1212 echo "var orderprinter2esc=
'";
1213 $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
1216 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet
set special_code=
'4' where special_code=
'2' and fk_facture=
".$invoice->id; // Set as printed
1218 $invoice->fetch($placeid); //Reload object after set lines as printed
1221 foreach ($invoice->lines as $line) {
1222 if ($line->special_code == "4
") {
1225 $c = new Categorie($db);
1226 $existing = $c->containing($line->fk_product, Categorie::TYPE_PRODUCT, 'id');
1227 $result = array_intersect($catsprinter3, $existing);
1228 $count = count($result);
1231 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet
set special_code=
'3' where
rowid=
".$line->id; //Set to print on printer 3
1233 $order_receipt_printer3 .= '<tr>'.$line->product_label.'<td class="right
">'.$line->qty;
1234 if (!empty($line->array_options['options_order_notes'])) {
1235 $order_receipt_printer3 .= "<br>(
".$line->array_options['options_order_notes'].")
";
1237 $order_receipt_printer3 .= '</td></tr>';
1240 if (((isModEnabled('receiptprinter') && getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term) > 0) || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter
" || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector
") && $linestoprint > 0) {
1241 $invoice->fetch($placeid); //Reload object before send to printer
1242 $printer->orderprinter = 3;
1244 echo "var orderprinter3esc=
'";
1245 $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
1248 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet
set special_code=
'4' where special_code=
'3' and fk_facture=
".$invoice->id; // Set as printed
1250 $invoice->fetch($placeid); //Reload object after set lines as printed
1253 $sectionwithinvoicelink = '';
1254 if (($action == "valid
" || $action == "history
" || $action == 'creditnote') && $user->hasRight('takepos', 'run')) {
1255 $sectionwithinvoicelink .= '<!-- Section with invoice link -->'."\n
";
1256 $sectionwithinvoicelink .= '<span style="font-size:120%;
" class="center
">';
1257 $sectionwithinvoicelink .= $invoice->getNomUrl(1, '', 0, 0, '', 0, 0, -1, '_backoffice')." -
";
1258 $remaintopay = $invoice->getRemainToPay();
1259 if ($remaintopay > 0) {
1260 $sectionwithinvoicelink .= $langs->trans('RemainToPay').': <span class="amountremaintopay
" style="font-size: unset
">'.price($remaintopay, 1, $langs, 1, -1, -1, $conf->currency).'</span>';
1262 if ($invoice->paye) {
1263 $sectionwithinvoicelink .= '<span class="amountpaymentcomplete
" style="font-size: unset
">'.$langs->trans("Paid
").'</span>';
1265 $sectionwithinvoicelink .= $langs->trans('BillShortStatusValidated');
1269 $sectionwithinvoicelink .= '</span><br>';
1270 if (getDolGlobalInt('TAKEPOS_PRINT_INVOICE_DOC_INSTEAD_OF_RECEIPT')) {
1271 $sectionwithinvoicelink .= ' <a target="_blank
" class="button" href="' . DOL_URL_ROOT . '/document.php?token=
' . newToken() . '&modulepart=facture&file=
' . $invoice->ref . '/
' . $invoice->ref . '.pdf
">Invoice</a>';
1272 } elseif (getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector
") {
1273 if (getDolGlobalString('TAKEPOS_PRINT_SERVER') && filter_var($conf->global->TAKEPOS_PRINT_SERVER, FILTER_VALIDATE_URL) == true) {
1274 $sectionwithinvoicelink .= ' <button id="buttonprint
" type="button" onclick="TakeposConnector(
'.$placeid.')
">'.$langs->trans('PrintTicket').'</button>';
1276 $sectionwithinvoicelink .= ' <button id="buttonprint
" type="button" onclick="TakeposPrinting(
'.$placeid.')
">'.$langs->trans('PrintTicket').'</button>';
1278 } elseif ((isModEnabled('receiptprinter') && getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term) > 0) || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter
") {
1279 $sectionwithinvoicelink .= ' <button id="buttonprint
" type="button" onclick="DolibarrTakeposPrinting(
'.$placeid.')
">'.$langs->trans('PrintTicket').'</button>';
1281 $sectionwithinvoicelink .= ' <button id="buttonprint
" type="button" onclick="Print(
'.$placeid.')
">'.$langs->trans('PrintTicket').'</button>';
1282 if (getDolGlobalString('TAKEPOS_PRINT_WITHOUT_DETAILS')) {
1283 $sectionwithinvoicelink .= ' <button id="buttonprint
" type="button" onclick="PrintBox(
'.$placeid.', \
'without_details\')">'.$langs->trans(
'PrintWithoutDetails').
'</button>';
1286 $sectionwithinvoicelink .=
' <button id="buttonprint" type="button" onclick="Print('.$placeid.
', 1)">'.$langs->trans(
'GiftReceipt').
'</button>';
1290 $sectionwithinvoicelink .=
' <button id="buttonsend" type="button" onclick="SendTicket('.$placeid.
')">'.$langs->trans(
'SendTicket').
'</button>';
1293 if ($remaintopay <= 0 &&
getDolGlobalString(
'TAKEPOS_AUTO_PRINT_TICKETS') && $action !=
"history") {
1294 $sectionwithinvoicelink .=
'<script type="text/javascript">$("#buttonprint").click();</script>';
1304$form =
new Form($db);
1307if ((
getDolGlobalString(
'TAKEPOS_PHONE_BASIC_LAYOUT') == 1 && $conf->browser->layout ==
'phone') || defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1308 $title =
'TakePOS - Dolibarr '.DOL_VERSION;
1312 $head =
'<meta name="apple-mobile-web-app-title" content="TakePOS"/>
1313 <meta name="apple-mobile-web-app-capable" content="yes">
1314 <meta name="mobile-web-app-capable" content="yes">
1315 <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>';
1316 $arrayofcss = array(
1317 '/takepos/css/pos.css.php',
1319 $arrayofjs = array(
'/takepos/js/jquery.colorbox-min.js');
1322 top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss);
1324 print
'<body>'.
"\n";
1331<script
type=
"text/javascript">
1334<?php
if ($action ==
"valid") {
1335 echo
"var place=0;";
1337var placeid=<?php echo($placeid > 0 ? $placeid : 0); ?>;
1338$(document).ready(
function() {
1339 var idoflineadded = <?php echo(empty($idoflineadded) ? 0 : $idoflineadded); ?>;
1341 $(
'.posinvoiceline').click(
function(){
1342 console.log(
"Click done on "+this.
id);
1343 $(
'.posinvoiceline').removeClass(
"selected");
1344 $(
this).addClass(
"selected");
1348 if (selectedline == this.
id) {
1351 selectedline = this.id;
1353 selectedtext=$(
'#'+selectedline).find(
"td:first").html();
1355 if (defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1356 print
'$("#phonediv1").load("'.DOL_URL_ROOT.
'/takepos/public/auto_order.php?action=editline&token='.
newToken().
'&placeid="+placeid+"&selectedline="+selectedline, function() {
1363 if (idoflineadded > 0)
1365 console.log(
"Auto select "+idoflineadded);
1366 $(
'.posinvoiceline#'+idoflineadded).click();
1370if ($action ==
"order" && !empty($order_receipt_printer1)) {
1371 if (filter_var($conf->global->TAKEPOS_PRINT_SERVER, FILTER_VALIDATE_URL) ==
true) {
1375 url:
'<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>/printer/index.php',
1376 data:
'invoice='+orderprinter1esc
1383 url:
'http://<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>:8111/print',
1385 print $headerorder.$order_receipt_printer1.$footerorder; ?>'
1391if ($action ==
"order" && !empty($order_receipt_printer2)) {
1392 if (filter_var($conf->global->TAKEPOS_PRINT_SERVER, FILTER_VALIDATE_URL) ==
true) {
1396 url:
'<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>/printer/index.php?printer=2',
1397 data:
'invoice='+orderprinter2esc
1404 url:
'http://<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>:8111/print2',
1406 print $headerorder.$order_receipt_printer2.$footerorder; ?>'
1412if ($action ==
"order" && !empty($order_receipt_printer3)) {
1413 if (filter_var($conf->global->TAKEPOS_PRINT_SERVER, FILTER_VALIDATE_URL) ==
true) {
1417 url:
'<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>/printer/index.php?printer=3',
1418 data:
'invoice='+orderprinter3esc
1425if ($action ==
"search" || $action ==
"valid") {
1427 parent.ClearSearch(
true);
1432if ($action ==
"temp" && !empty($ticket_printer1)) {
1436 url:
'http://<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>:8111/print',
1438 print $header_soc.$header_ticket.$body_ticket.$ticket_printer1.$ticket_total.$footer_ticket; ?>'
1443if ($action ==
"search") {
1445 $(
'#search').focus();
1453function SendTicket(
id)
1455 console.log(
"Open box to select the Print/Send form");
1456 $.colorbox({href:
"send.php?facid="+id, width:
"70%", height:
"30%", transition:
"none", iframe:
"true", title:
'<?php echo dol_escape_js($langs->trans("SendTicket")); ?>'});
1460function PrintBox(
id, action) {
1461 console.log(
"Open box before printing");
1462 $.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
"); ?>"});
1466function Print(
id, gift){
1467 console.log(
"Call Print() to generate the receipt.");
1468 $.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")); ?>'});
1472function TakeposPrinting(
id){
1474 console.log(
"TakeposPrinting" +
id);
1475 $.get(
"receipt.php?facid="+
id,
function(data,
status) {
1476 receipt=data.replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g,
'');
1479 url:
'http://<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER
'); ?>:8111/print',
1486function TakeposConnector(
id){
1487 console.log(
"TakeposConnector" +
id);
1488 $.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) {
1491 url:
'<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER
'); ?>/printer/index.php',
1492 data:
'invoice='+data
1500function DolibarrTakeposPrinting(
id) {
1501 console.log(
"DolibarrTakeposPrinting Printing invoice ticket " +
id);
1504 data: { token:
'<?php echo currentToken(); ?>' },
1505 url:
"<?php print DOL_URL_ROOT.'/takepos/ajax/ajax.php?action=printinvoiceticket&token='.newToken().'&term='.urlencode(isset($_SESSION["takeposterminal
"]) ? $_SESSION["takeposterminal
"] : '').'&id='; ?>" + id,
1512function CreditNote() {
1513 $(
"#poslines").load(
"<?php print DOL_URL_ROOT; ?>/takepos/invoice.php?action=creditnote&token=<?php echo newToken() ?>&invoiceid="+placeid,
function() { });
1519 $(
"#poslines").load(
"<?php print DOL_URL_ROOT; ?>/takepos/invoice.php?action=addnote&token=<?php echo newToken() ?>&invoiceid="+placeid+
"&idline="+selectedline, {
"addnote": $(
"#textinput").val() });
1524$( document ).ready(
function() {
1525 console.log(
"Set customer info and sales in header placeid=<?php echo $placeid; ?> status=<?php echo $invoice->statut; ?>");
1528 $s = $langs->trans(
"Customer");
1529 if ($invoice->id > 0 && ($invoice->socid !=
getDolGlobalString($constforcompanyid))) {
1532 $contactids = $invoice->getIdContact(
'external',
'BILLING');
1533 $contactid = $contactids[0];
1534 if ($contactid > 0) {
1536 $contact->fetch($contactid);
1537 $s .=
" - " . $contact->getFullName($langs);
1543 $(
"#customerandsales").html(
'');
1544 $(
"#shoppingcart").html(
'');
1547 $(
"#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>');
1549 $(
"#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>');
1553 $sql =
"SELECT rowid, datec, ref FROM ".MAIN_DB_PREFIX.
"facture";
1554 $sql .=
" WHERE entity IN (".getEntity(
'invoice').
")";
1557 $sql .=
" AND ref LIKE '(PROV-POS".$db->escape(isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'').
"-0%'";
1560 $sql .=
" AND pos_source = '".$db->escape($_SESSION[
"takeposterminal"]).
"'";
1561 $sql .=
" AND module_source = 'takepos'";
1564 $sql .= $db->order(
'datec',
'ASC');
1565 $resql = $db->query($sql);
1568 while ($obj = $db->fetch_object($resql)) {
1569 echo
'$("#shoppingcart").append(\'';
1570 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=\\\'';
1571 $num_sale = str_replace(
")",
"", str_replace(
"(PROV-POS".$_SESSION[
"takeposterminal"].
"-",
"", $obj->ref));
1573 if (str_replace(
"-",
"", $num_sale) > $max_sale) {
1574 $max_sale = str_replace(
"-",
"", $num_sale);
1576 echo
'\\\'; invoiceid=\\\'';
1578 echo
'\\\'; Refresh();">';
1579 if ($placeid == $obj->rowid) {
1580 echo
'<span class="basketselected">';
1582 echo
'<span class="basketnotselected">';
1584 echo
'<span class="fa fa-shopping-cart paddingright"></span>'.dol_print_date($db->jdate($obj->datec),
'%H:%M',
'tzuser');
1588 echo
'$("#shoppingcart").append(\'<a onclick="place=\\\'0-';
1590 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>\');';
1598 $constantforkey =
'CASHDESK_NO_DECREASE_STOCK'. (isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
1599 if (isModEnabled(
'stock')) {
1601 $constantforkey =
'CASHDESK_ID_WAREHOUSE'. (isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
1603 if ($idwarehouse > 0) {
1604 $s =
'<span class="small">';
1606 $warehouse->fetch($idwarehouse);
1607 $s .=
'<span class="hideonsmartphone">'.$langs->trans(
"Warehouse").
'<br></span>'.$warehouse->ref;
1609 $s .=
' ('.$langs->trans(
"Closed").
')';
1612 print
"$('#infowarehouse').html('".dol_escape_js($s).
"');";
1613 print
'$("#infowarehouse").css("display", "inline-block");';
1615 $s =
'<span class="small hideonsmartphone">';
1616 $s .= $langs->trans(
"StockChangeDisabled").
'<br>'.$langs->trans(
"NoWarehouseDefinedForTerminal");
1618 print
"$('#infowarehouse').html('".dol_escape_js($s).
"');";
1619 if (!empty($conf->dol_optimize_smallscreen)) {
1620 print
'$("#infowarehouse").css("display", "none");';
1624 $s =
'<span class="small hideonsmartphone">'.$langs->trans(
"StockChangeDisabled").
'</span>';
1625 print
"$('#infowarehouse').html('".dol_escape_js($s).
"');";
1626 if (!empty($conf->dol_optimize_smallscreen)) {
1627 print
'$("#infowarehouse").css("display", "none");';
1635 if (isModEnabled(
'member') && $invoice->socid > 0 && $invoice->socid !=
getDolGlobalInt($constforcompanyid)) {
1636 $s =
'<span class="small">';
1637 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
1638 $langs->load(
"members");
1639 $s .= $langs->trans(
"Member").
': ';
1641 $result = $adh->fetch(
'',
'', $invoice->socid);
1643 $adh->ref = $adh->getFullName($langs);
1647 $s .= $adh->getFullName($langs);
1648 $s .=
' - '.$adh->type;
1649 if ($adh->datefin) {
1650 $s .=
'<br>'.$langs->trans(
"SubscriptionEndDate").
': '.
dol_print_date($adh->datefin,
'day');
1651 if ($adh->hasDelay()) {
1652 $s .=
" ".img_warning($langs->trans(
"Late"));
1655 $s .=
'<br>'.$langs->trans(
"SubscriptionNotReceived");
1656 if ($adh->statut > 0) {
1657 $s .=
" ".img_warning($langs->trans(
"Late"));
1664 $s .=
'<br>'.$langs->trans(
"ThirdpartyNotLinkedToMember");
1669 $(
"#moreinfo").html(
'<?php print dol_escape_js($s); ?>');
1676 echo
"function CustomerDisplay(){";
1677 echo
"var line1='".$CUSTOMER_DISPLAY_line1.
"'.substring(0,20);";
1678 echo
"line1=line1.padEnd(20);";
1679 echo
"var line2='".$CUSTOMER_DISPLAY_line2.
"'.substring(0,20);";
1680 echo
"line2=line2.padEnd(20);";
1683 data: { text: line1+line2 },
1684 url: '".getDolGlobalString(
'TAKEPOS_PRINT_SERVER').
"/display/index.php',
1695if (!empty($conf->use_javascript_ajax)) {
1696 print
"\n".
'<!-- Includes JS Footer of Dolibarr -->'.
"\n";
1697 print
'<script src="'.DOL_URL_ROOT.
'/core/js/lib_foot.js.php?lang='.$langs->defaultlang.
'"></script>'.
"\n";