109 header($_SERVER[
'SERVER_PROTOCOL'].
' 500 Internal Server Error',
true, 500);
115$number =
GETPOST(
'number',
'alpha');
116$idline =
GETPOST(
'idline',
'int');
117$selectedline =
GETPOST(
'selectedline',
'int');
118$desc =
GETPOST(
'desc',
'alphanohtml');
122$invoiceid =
GETPOST(
'invoiceid',
'int');
131if ($pay ==
'cheque') {
138 $sql =
"SELECT id FROM ".MAIN_DB_PREFIX.
"c_paiement";
139 $sql .=
" WHERE entity IN (".getEntity(
'c_paiement').
")";
140 $sql .=
" AND code = '".$db->escape($paycode).
"'";
141 $resql = $db->query($sql);
143 $obj = $db->fetch_object($resql);
145 $paiementid = $obj->id;
152 $ret = $invoice->fetch($invoiceid);
154 $ret = $invoice->fetch(
'',
'(PROV-POS'. (isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'') .
'-'.$place.
')');
157 $placeid = $invoice->id;
160$constforcompanyid =
'CASHDESK_ID_THIRDPARTY'. (isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
163if ($invoice->socid > 0) {
164 $soc->fetch($invoice->socid);
170if (isModEnabled(
'multicurrency') && !empty($_SESSION[
"takeposcustomercurrency"])) {
171 if ($invoice->multicurrency_code != $_SESSION[
"takeposcustomercurrency"]) {
172 $invoice->setMulticurrencyCode($_SESSION[
"takeposcustomercurrency"]);
176$term = empty($_SESSION[
"takeposterminal"]) ? 1 : $_SESSION[
"takeposterminal"];
184$reshook=$hookmanager->executeHooks(
'doActions', $parameters, $invoice, $action);
189if (empty($reshook)) {
191 if ($action ==
'valid' && $user->hasRight(
'facture',
'creer')) {
196 $bankaccount =
GETPOST(
'accountid',
'int');
199 $bankaccount =
getDolGlobalString(
'CASHDESK_ID_BANKACCOUNT_CASH'.$_SESSION[
"takeposterminal"]);
200 } elseif ($pay ==
"CHQ") {
201 $bankaccount =
getDolGlobalString(
'CASHDESK_ID_BANKACCOUNT_CHEQUE'.$_SESSION[
"takeposterminal"]);
203 $accountname =
"CASHDESK_ID_BANKACCOUNT_".$pay.$_SESSION[
"takeposterminal"];
208 if ($bankaccount <= 0 && $pay !=
"delayed" && isModEnabled(
"banque")) {
209 $errormsg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"BankAccount"));
217 $invoice->fetch($placeid);
221 if ($invoice->total_ttc < 0) {
222 $invoice->type = $invoice::TYPE_CREDIT_NOTE;
224 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"facture";
225 $sql .=
" WHERE entity IN (".getEntity(
'invoice').
")";
226 $sql .=
" AND fk_soc = ".((int) $invoice->socid);
227 $sql .=
" AND type <> ".Facture::TYPE_CREDIT_NOTE;
228 $sql .=
" AND fk_statut >= ".$invoice::STATUS_VALIDATED;
229 $sql .=
" ORDER BY rowid DESC";
231 $resql = $db->query($sql);
233 $obj = $db->fetch_object($resql);
234 $fk_source = $obj->rowid;
235 if ($fk_source ==
null) {
236 fail($langs->transnoentitiesnoconv(
"NoPreviousBillForCustomer"));
239 fail($langs->transnoentitiesnoconv(
"NoPreviousBillForCustomer"));
241 $invoice->fk_facture_source = $fk_source;
242 $invoice->update($user);
245 $constantforkey =
'CASHDESK_NO_DECREASE_STOCK'.(isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
250 if ($invoice->getRemainToPay() > 0) {
256 } elseif (count($invoice->lines) == 0) {
260 } elseif (isModEnabled(
'stock') && !isModEnabled(
'productbatch') &&
getDolGlobalString($constantforkey) !=
"1") {
263 $savconst = $conf->global->STOCK_CALCULATE_ON_BILL;
265 if (isModEnabled(
'productbatch') && !
getDolGlobalInt(
'CASHDESK_FORCE_DECREASE_STOCK')) {
266 $conf->global->STOCK_CALCULATE_ON_BILL = 0;
269 $conf->global->STOCK_CALCULATE_ON_BILL = 1;
272 $constantforkey =
'CASHDESK_ID_WAREHOUSE'.$_SESSION[
"takeposterminal"];
273 dol_syslog(
"Validate invoice with stock change into warehouse defined into constant ".$constantforkey.
" = ".
getDolGlobalString($constantforkey));
276 if (isModEnabled(
'productbatch') &&
getDolGlobalString(
'CASHDESK_FORCE_DECREASE_STOCK')) {
277 require_once DOL_DOCUMENT_ROOT.
'/product/class/productbatch.class.php';
280 $res = $invoice->validate($user,
'',
getDolGlobalInt($constantforkey), 0, $batch_rule);
282 $conf->global->STOCK_CALCULATE_ON_BILL = $savconst;
285 $res = $invoice->validate($user);
288 $langs->load(
"admin");
289 dol_htmloutput_errors($invoice->error ==
'NotConfigured' ? $langs->trans(
"NotConfigured").
' (TakePos numbering module)' : $invoice->error, $invoice->errors, 1);
294 if (!$error && $res >= 0) {
295 $remaintopay = $invoice->getRemainToPay();
296 if ($remaintopay > 0) {
298 $payment->datepaye = $now;
299 $payment->fk_account = $bankaccount;
300 $payment->amounts[$invoice->id] = $amountofpayment;
307 if ($amountofpayment <= 0 || $amountofpayment > $remaintopay) {
308 $payment->amounts[$invoice->id] = $remaintopay;
311 $payment->paiementid = $paiementid;
312 $payment->num_payment = $invoice->ref;
314 if ($pay !=
"delayed") {
315 $result = $payment->create($user);
320 $res = $payment->addPaymentToBank($user,
'payment',
'(CustomerInvoicePayment)', $bankaccount,
'',
'');
326 $remaintopay = $invoice->getRemainToPay();
332 if ($remaintopay == 0) {
333 dol_syslog(
"Invoice is paid, so we set it to status Paid");
334 $result = $invoice->setPaid($user);
339 $invoice->setPaymentMethods($paiementid);
341 dol_syslog(
"Invoice is not paid, remain to pay = ".$remaintopay);
348 if (!$error && $res >= 0) {
349 if (isModEnabled(
'stock') && isModEnabled(
'productbatch')) {
350 require_once DOL_DOCUMENT_ROOT .
"/product/stock/class/mouvementstock.class.php";
351 $constantforkey =
'CASHDESK_ID_WAREHOUSE'.$_SESSION[
"takeposterminal"];
353 $labeltakeposmovement =
'TakePOS - '.$langs->trans(
"Invoice").
' '.$invoice->ref;
355 foreach ($invoice->lines as $line) {
356 $warehouseid = ($line->fk_warehouse ? $line->fk_warehouse :
getDolGlobalInt($constantforkey));
359 if ($line->batch !=
'' && $warehouseid > 0) {
361 $prod_batch->find(0,
'',
'', $line->batch, $warehouseid);
363 $mouvP->origin = $invoice;
364 $res = $mouvP->livraison($user, $line->fk_product, $warehouseid, $line->qty, $line->price, $labeltakeposmovement,
'',
'',
'', $prod_batch->batch, $prod_batch->id, $inventorycode);
371 $mouvP->origin = $invoice;
372 $res = $mouvP->livraison($user, $line->fk_product, $warehouseid, $line->qty, $line->price, $labeltakeposmovement,
'',
'',
'',
'', 0, $inventorycode);
382 if (!$error && $res >= 0) {
388 if ($action ==
'creditnote' && $user->hasRight(
'facture',
'creer')) {
391 $creditnote =
new Facture($db);
392 $creditnote->socid = $invoice->socid;
394 $creditnote->module_source =
'takepos';
395 $creditnote->pos_source = isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'' ;
397 $creditnote->fk_facture_source = $placeid;
400 $creditnote->create($user);
402 foreach ($invoice->lines as $line) {
404 if (method_exists($line,
'fetch_optionals')) {
406 $line->fetch_optionals();
409 if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) {
414 if (!empty($invoice->situation_counter)) {
415 $source_fk_prev_id = $line->fk_prev_id;
416 $line->fk_prev_id = $line->id;
417 if (!empty($invoice->tab_previous_situation_invoice)) {
420 $tab_jumped_credit_notes = array();
421 $lineIndex = count($invoice->tab_previous_situation_invoice) - 1;
422 $searchPreviousInvoice =
true;
423 while ($searchPreviousInvoice) {
424 if ($invoice->tab_previous_situation_invoice[$lineIndex]->situation_cycle_ref || $lineIndex < 1) {
425 $searchPreviousInvoice =
false;
429 $tab_jumped_credit_notes[$lineIndex] = $invoice->tab_previous_situation_invoice[$lineIndex]->id;
435 $maxPrevSituationPercent = 0;
436 foreach ($invoice->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine) {
437 if ($prevLine->id == $source_fk_prev_id) {
438 $maxPrevSituationPercent = max($maxPrevSituationPercent, $prevLine->situation_percent);
441 $line->total_ht = $line->total_ht - $prevLine->total_ht;
442 $line->total_tva = $line->total_tva - $prevLine->total_tva;
443 $line->total_ttc = $line->total_ttc - $prevLine->total_ttc;
444 $line->total_localtax1 = $line->total_localtax1 - $prevLine->total_localtax1;
445 $line->total_localtax2 = $line->total_localtax2 - $prevLine->total_localtax2;
447 $line->multicurrency_subprice = $line->multicurrency_subprice - $prevLine->multicurrency_subprice;
448 $line->multicurrency_total_ht = $line->multicurrency_total_ht - $prevLine->multicurrency_total_ht;
449 $line->multicurrency_total_tva = $line->multicurrency_total_tva - $prevLine->multicurrency_total_tva;
450 $line->multicurrency_total_ttc = $line->multicurrency_total_ttc - $prevLine->multicurrency_total_ttc;
455 $line->situation_percent = $maxPrevSituationPercent - $line->situation_percent;
460 $maxPrevSituationPercent = 0;
461 foreach ($tab_jumped_credit_notes as $index => $creditnoteid) {
462 foreach ($invoice->tab_previous_situation_invoice[$index]->lines as $prevLine) {
463 if ($prevLine->fk_prev_id == $source_fk_prev_id) {
464 $maxPrevSituationPercent = $prevLine->situation_percent;
466 $line->total_ht -= $prevLine->total_ht;
467 $line->total_tva -= $prevLine->total_tva;
468 $line->total_ttc -= $prevLine->total_ttc;
469 $line->total_localtax1 -= $prevLine->total_localtax1;
470 $line->total_localtax2 -= $prevLine->total_localtax2;
472 $line->multicurrency_subprice -= $prevLine->multicurrency_subprice;
473 $line->multicurrency_total_ht -= $prevLine->multicurrency_total_ht;
474 $line->multicurrency_total_tva -= $prevLine->multicurrency_total_tva;
475 $line->multicurrency_total_ttc -= $prevLine->multicurrency_total_ttc;
481 $line->situation_percent += $maxPrevSituationPercent;
488 $line->fk_facture = $creditnote->id;
489 $line->fk_parent_line = $fk_parent_line;
491 $line->subprice = -$line->subprice;
492 $line->pa_ht = $line->pa_ht;
493 $line->total_ht = -$line->total_ht;
494 $line->total_tva = -$line->total_tva;
495 $line->total_ttc = -$line->total_ttc;
496 $line->total_localtax1 = -$line->total_localtax1;
497 $line->total_localtax2 = -$line->total_localtax2;
499 $line->multicurrency_subprice = -$line->multicurrency_subprice;
500 $line->multicurrency_total_ht = -$line->multicurrency_total_ht;
501 $line->multicurrency_total_tva = -$line->multicurrency_total_tva;
502 $line->multicurrency_total_ttc = -$line->multicurrency_total_ttc;
504 $result = $line->insert(0, 1);
506 $creditnote->lines[] = $line;
509 if ($result > 0 && $line->product_type == 9) {
510 $fk_parent_line = $result;
513 $creditnote->update_price(1);
515 $constantforkey =
'CASHDESK_NO_DECREASE_STOCK'.(isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
517 $savconst = $conf->global->STOCK_CALCULATE_ON_BILL;
518 $conf->global->STOCK_CALCULATE_ON_BILL = 1;
519 $constantforkey =
'CASHDESK_ID_WAREHOUSE'.(isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
520 dol_syslog(
"Validate invoice with stock change into warehouse defined into constant ".$constantforkey.
" = ".
getDolGlobalString($constantforkey));
522 if (isModEnabled(
'productbatch') &&
getDolGlobalString(
'CASHDESK_FORCE_DECREASE_STOCK')) {
523 require_once DOL_DOCUMENT_ROOT.
'/product/class/productbatch.class.php';
526 $res = $creditnote->validate($user,
'',
getDolGlobalString($constantforkey), 0, $batch_rule);
527 $conf->global->STOCK_CALCULATE_ON_BILL = $savconst;
529 $res = $creditnote->validate($user);
532 if (!$error && $res >= 0) {
539 if (($action ==
'history' || $action ==
'creditnote') && $user->hasRight(
'takepos',
'run')) {
540 if ($action ==
'creditnote') {
541 $placeid = $creditnote->id;
543 $placeid = (int)
GETPOST(
'placeid',
'int');
546 $invoice->fetch($placeid);
550 if (($action ==
"addline" || $action ==
"freezone") && $placeid == 0 && ($user->hasRight(
'takepos',
'run') || defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
553 $dolnowtzuserrel =
dol_now(
'tzuserrel');
557 $dateinvoice =
dol_mktime(0, 0, 0, (
int) $monthuser, (
int) $dayuser, (
int) $yearuser,
'tzserver');
559 include_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
560 $invoice->date = $dateinvoice;
562 $invoice->module_source =
'takepos';
563 $invoice->pos_source = isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'' ;
564 $invoice->entity = !empty($_SESSION[
"takeposinvoiceentity"]) ? $_SESSION[
"takeposinvoiceentity"] : $conf->entity;
566 if ($invoice->socid <= 0) {
567 $langs->load(
'errors');
573 $placeid = $invoice->create($user);
577 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facture set ref='(PROV-POS".$_SESSION[
"takeposterminal"].
"-".$place.
")' where rowid = ".((int) $placeid);
578 $resql = $db->query($sql);
592 if ($action ==
"addline" && ($user->hasRight(
'takepos',
'run') || defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
594 $prod->fetch($idproduct);
597 $customer->fetch($invoice->socid);
599 $datapriceofproduct = $prod->getSellPrice($mysoc, $customer, 0);
601 $qty = GETPOSTISSET(
'qty') ?
GETPOST(
'qty',
'int') : 1;
602 $price = $datapriceofproduct[
'pu_ht'];
603 $price_ttc = $datapriceofproduct[
'pu_ttc'];
605 $price_base_type = empty($datapriceofproduct[
'price_base_type']) ?
'HT' : $datapriceofproduct[
'price_base_type'];
606 $tva_tx = $datapriceofproduct[
'tva_tx'];
607 $tva_npr = $datapriceofproduct[
'tva_npr'];
610 $localtax1_tx =
get_localtax($tva_tx, 1, $customer, $mysoc, $tva_npr);
611 $localtax2_tx =
get_localtax($tva_tx, 2, $customer, $mysoc, $tva_npr);
614 if (isModEnabled(
'productbatch') && isModEnabled(
'stock')) {
615 $batch =
GETPOST(
'batch',
'alpha');
617 if (!empty($batch)) {
618 $action =
"setbatch";
619 } elseif ($prod->status_batch > 0) {
624 $prod->load_stock(
'warehouseopen');
626 $constantforkey =
'CASHDESK_ID_WAREHOUSE'.$_SESSION[
"takeposterminal"];
630 foreach ($prod->stock_warehouse as $tmpwarehouseid => $tmpval) {
635 if (!empty($prod->stock_warehouse[$tmpwarehouseid]) && is_array($prod->stock_warehouse[$tmpwarehouseid]->detail_batch)) {
636 if (is_object($prod->stock_warehouse[$tmpwarehouseid]) && count($prod->stock_warehouse[$tmpwarehouseid]->detail_batch)) {
637 foreach ($prod->stock_warehouse[$tmpwarehouseid]->detail_batch as $dbatch) {
646 echo
"function addbatch(batch, warehouseid) {\n";
647 echo
"console.log('We add batch '+batch+' from warehouse id '+warehouseid);\n";
648 echo
'$("#poslines").load("invoice.php?action=addline&batch="+batch+"&warehouseid="+warehouseid+"&place='.$place.
'&idproduct='.$idproduct.
'&token='.newToken().
'", function() {});'.
"\n";
653 echo
"<center>".$langs->trans(
"SearchIntoBatch").
": <b> $nbofsuggested </b></center><br><table>";
654 foreach ($prod->stock_warehouse as $tmpwarehouseid => $tmpval) {
659 if (!empty($prod->stock_warehouse[$tmpwarehouseid]) && is_array($prod->stock_warehouse[$tmpwarehouseid]->detail_batch)) {
660 foreach ($prod->stock_warehouse[$tmpwarehouseid]->detail_batch as $dbatch) {
661 $batchStock = + $dbatch->qty;
662 $quantityToBeDelivered = 1;
663 $deliverableQty = min($quantityToBeDelivered, $batchStock);
665 print
'<!-- subj='.$suggestednb.
'/'.$nbofsuggested.
' -->';
666 print
'<!-- Show details of lot -->';
667 print
'<td class="left">';
669 $detail .=
'<span class="opacitymedium">'.$langs->trans(
"LotSerial").
':</span> '.$dbatch->batch;
676 $detail .=
'</td><td>';
677 $detail .=
'<span class="opacitymedium">'.$langs->trans(
"Qty").
':</span> '.$dbatch->qty;
678 $detail .=
'</td><td>';
679 $detail .=
' <button class="marginleftonly" onclick="addbatch(\''.dol_escape_js($dbatch->batch).
'\',
'.$tmpwarehouseid.')
">'.$langs->trans("Select
")."</
button>
";
683 $quantityToBeDelivered -= $deliverableQty;
684 if ($quantityToBeDelivered < 0) {
685 $quantityToBeDelivered = 0;
694 print '</body></html>';
700 if (getDolGlobalString('TAKEPOS_SUPPLEMENTS')) {
701 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
702 $cat = new Categorie($db);
703 $categories = $cat->containing($idproduct, 'product');
704 $found = (array_search(getDolGlobalInt('TAKEPOS_SUPPLEMENTS_CATEGORY'), array_column($categories, 'id')));
705 if ($found !== false) { // If this product is a supplement
706 $sql = "SELECT fk_parent_line FROM
".MAIN_DB_PREFIX."facturedet where
rowid =
".((int) $selectedline);
707 $resql = $db->query($sql);
708 $row = $db->fetch_array($resql);
709 if ($row[0] == null) {
710 $parent_line = $selectedline;
712 $parent_line = $row[0]; //If the parent line is already a supplement, add the supplement to the main product
719 // Group if enabled. Skip group if line already sent to the printer
720 if (getDolGlobalString('TAKEPOS_GROUP_SAME_PRODUCT')) {
721 foreach ($invoice->lines as $line) {
722 if ($line->product_ref == $prod->ref) {
723 if ($line->special_code==4) {
725 } // If this line is sended to printer create new line
726 // check if qty in stock
727 if (getDolGlobalString('TAKEPOS_QTY_IN_STOCK') && (($line->qty + $qty) > $prod->stock_reel)) {
728 $invoice->error = $langs->trans('NotEnoughInStock');
729 dol_htmloutput_errors($invoice->error, $invoice->errors, 1);
733 $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);
735 dol_htmloutput_errors($invoice->error, $invoice->errors, 1);
737 $idoflineadded = $line->id;
743 if ($idoflineadded <= 0 && empty($err)) {
744 $invoice->fetch_thirdparty();
745 $array_options = array();
747 $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);
749 /* setup of margin calculation */
750 if (isset($conf->global->MARGIN_TYPE)) {
751 if (getDolGlobalString('MARGIN_TYPE') == 'pmp' && !empty($prod->pmp)) {
752 $line['fk_fournprice'] = null;
753 $line['pa_ht'] = $prod->pmp;
754 } elseif (getDolGlobalString('MARGIN_TYPE') == 'costprice' && !empty($prod->cost_price)) {
755 $line['fk_fournprice'] = null;
756 $line['pa_ht'] = $prod->cost_price;
758 // default is fournprice
759 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
760 $pf = new ProductFournisseur($db);
761 if ($pf->find_min_price_product_fournisseur($idproduct, $qty) > 0) {
762 $line['fk_fournprice'] = $pf->product_fourn_price_id;
763 $line['pa_ht'] = $pf->fourn_unitprice_with_discount;
764 if (getDolGlobalString('PRODUCT_CHARGES') && $pf->fourn_charges > 0) {
765 $line['pa_ht'] += $pf->fourn_charges / $pf->fourn_qty;
771 // complete line by hook
772 $parameters = array('prod' => $prod, 'line' => $line);
773 $reshook=$hookmanager->executeHooks('completeTakePosAddLine', $parameters, $invoice, $action); // Note that $action and $line may have been modified by some hooks
775 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
779 if (empty($reshook)) {
780 if (!empty($hookmanager->resArray)) {
781 $line = $hookmanager->resArray;
784 // check if qty in stock
785 if (getDolGlobalString('TAKEPOS_QTY_IN_STOCK') && $qty > $prod->stock_reel) {
786 $invoice->error = $langs->trans('NotEnoughInStock');
787 dol_htmloutput_errors($invoice->error, $invoice->errors, 1);
792 $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);
796 if (getDolGlobalString('TAKEPOS_CUSTOMER_DISPLAY')) {
797 $CUSTOMER_DISPLAY_line1 = $prod->label;
798 $CUSTOMER_DISPLAY_line2 = price($price_ttc);
802 $invoice->fetch($placeid);
805 // If we add a line by submitting freezone form (invoice exists here because it was created juste before if it didn't exists)
806 if ($action == "freezone
" && $user->hasRight('takepos', 'run')) {
807 $customer = new Societe($db);
808 $customer->fetch($invoice->socid);
810 $tva_tx = GETPOST('tva_tx', 'alpha');
812 if (!preg_match('/\((.*)\)/', $tva_tx)) {
813 $tva_tx = price2num($tva_tx);
816 $tva_tx = get_default_tva($mysoc, $customer);
820 $localtax1_tx = get_localtax($tva_tx, 1, $customer, $mysoc, $tva_npr);
821 $localtax2_tx = get_localtax($tva_tx, 2, $customer, $mysoc, $tva_npr);
823 $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);
825 dol_htmloutput_errors($invoice->error, $invoice->errors, 1);
827 $invoice->fetch($placeid);
830 if ($action == "addnote
" && ($user->hasRight('takepos', 'run') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
831 $desc = GETPOST('addnote', 'alpha');
833 $invoice->update_note($desc, '_public');
835 foreach ($invoice->lines as $line) {
836 if ($line->id == $idline) {
837 $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);
841 $invoice->fetch($placeid);
844 if ($action == "deleteline
" && ($user->hasRight('takepos', 'run') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
846 $permissiontoupdateline = ($user->hasRight('takepos', 'editlines') && ($user->hasRight('takepos', 'editorderedlines') || $line->special_code != "4
"));
847 if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
848 if ($invoice->status == $invoice::STATUS_DRAFT && $invoice->pos_source && $invoice->module_source == 'takepos') {
849 $permissiontoupdateline = true;
850 // TODO Add also a test on $_SESSION('publicobjectid'] defined at creation of object
851 // TODO Check also that invoice->ref is (PROV-POS1-2) with 1 = terminal and 2, the invoice ID
855 if ($idline > 0 && $placeid > 0) { // If invoice exists and line selected. To avoid errors if deleted from another device or no line selected.
856 $invoice->deleteline($idline);
857 $invoice->fetch($placeid);
858 } elseif ($placeid > 0) { // If invoice exists but no line selected, proceed to delete last line.
859 $sql = "SELECT
rowid FROM
".MAIN_DB_PREFIX."facturedet where fk_facture =
".((int) $placeid)." ORDER BY
rowid DESC
";
860 $resql = $db->query($sql);
861 $row = $db->fetch_array($resql);
862 $deletelineid = $row[0];
863 $invoice->deleteline($deletelineid);
864 $invoice->fetch($placeid);
867 if (count($invoice->lines) == 0) {
868 $invoice->delete($user);
870 if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
871 header("Location:
".DOL_URL_ROOT."/takepos/public/auto_order.php
");
873 header("Location:
".DOL_URL_ROOT."/takepos/invoice.php
");
879 // Action to delete or discard an invoice
880 if ($action == "delete
" && ($user->hasRight('takepos', 'run') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
881 // $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 begining of page works.
883 $result = $invoice->fetch($placeid);
885 if ($result > 0 && $invoice->statut == Facture::STATUS_DRAFT) {
888 // We delete the lines
890 foreach ($invoice->lines as $line) {
891 $tmpres = $invoice->deleteline($line->id);
898 $sql = "UPDATE
".MAIN_DB_PREFIX."facture
";
899 $varforconst = 'CASHDESK_ID_THIRDPARTY'.$_SESSION["takeposterminal
"];
900 $sql .= " SET fk_soc =
".((int) getDolGlobalString($varforconst)).",
";
901 $sql .= " datec =
'".$db->idate(dol_now())."'";
902 $sql .= " WHERE entity IN (
".getEntity('invoice').")
";
903 $sql .= " AND
ref =
'(PROV-POS".$db->escape($_SESSION["takeposterminal"]."-".$place).")'";
904 $resql1 = $db->query($sql);
906 if ($resdeletelines && $resql1) {
912 $invoice->fetch($placeid);
917 if ($action == "updateqty
") { // Test on permission is done later
918 foreach ($invoice->lines as $line) {
919 if ($line->id == $idline) {
920 $permissiontoupdateline = ($user->hasRight('takepos', 'editlines') && ($user->hasRight('takepos', 'editorderedlines') || $line->special_code != "4
"));
921 if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
922 if ($invoice->status == $invoice::STATUS_DRAFT && $invoice->pos_source && $invoice->module_source == 'takepos') {
923 $permissiontoupdateline = true;
924 // TODO Add also a test on $_SESSION('publicobjectid'] defined at creation of object
925 // TODO Check also that invoice->ref is (PROV-POS1-2) with 1 = terminal and 2, the invoice ID
928 if (!$permissiontoupdateline) {
929 dol_htmloutput_errors($langs->trans("NotEnoughPermissions
", "TakePos
").' - No permission to updateqty', null, 1);
931 $vatratecode = $line->tva_tx;
932 if ($line->vat_src_code) {
933 $vatratecode .= ' ('.$line->vat_src_code.')';
936 $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);
941 $invoice->fetch($placeid);
944 if ($action == "updateprice
") { // Test on permission is done later
945 $customer = new Societe($db);
946 $customer->fetch($invoice->socid);
948 foreach ($invoice->lines as $line) {
949 if ($line->id == $idline) {
950 $prod = new Product($db);
951 $prod->fetch($line->fk_product);
952 $datapriceofproduct = $prod->getSellPrice($mysoc, $customer, 0);
953 $price_min = $datapriceofproduct['price_min'];
954 $usercanproductignorepricemin = ((getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && empty($user->rights->produit->ignore_price_min_advance)) || !getDolGlobalString('MAIN_USE_ADVANCED_PERMS'));
955 $pu_ht = price2num($number / (1 + ($line->tva_tx / 100)), 'MU');
957 if ($usercanproductignorepricemin && (!empty($price_min) && (price2num($pu_ht) * (1 - price2num($line->remise_percent) / 100) < price2num($price_min)))) {
958 $langs->load("products
");
959 dol_htmloutput_errors($langs->trans("CantBeLessThanMinPrice
", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, -1, $conf->currency)));
960 //echo $langs->trans("CantBeLessThanMinPrice
");
962 $permissiontoupdateline = ($user->hasRight('takepos', 'editlines') && ($user->hasRight('takepos', 'editorderedlines') || $line->special_code != "4
"));
963 if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
964 if ($invoice->status == $invoice::STATUS_DRAFT && $invoice->pos_source && $invoice->module_source == 'takepos') {
965 $permissiontoupdateline = true;
966 // TODO Add also a test on $_SESSION('publicobjectid'] defined at creation of object
967 // TODO Check also that invoice->ref is (PROV-POS1-2) with 1 = terminal and 2, the invoice ID
971 $vatratecode = $line->tva_tx;
972 if ($line->vat_src_code) {
973 $vatratecode .= ' ('.$line->vat_src_code.')';
976 if (!$permissiontoupdateline) {
977 dol_htmloutput_errors($langs->trans("NotEnoughPermissions
", "TakePos
").' - No permission to updateprice', null, 1);
978 } elseif (getDolGlobalInt('TAKEPOS_CHANGE_PRICE_HT') == 1) {
979 $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);
981 $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);
988 $invoice->fetch($placeid);
991 if ($action == "updatereduction
") { // Test on permission is done later
992 $customer = new Societe($db);
993 $customer->fetch($invoice->socid);
995 foreach ($invoice->lines as $line) {
996 if ($line->id == $idline) {
997 dol_syslog("updatereduction Process line
".$line->id.' to apply discount of '.$number.'%');
999 $prod = new Product($db);
1000 $prod->fetch($line->fk_product);
1002 $datapriceofproduct = $prod->getSellPrice($mysoc, $customer, 0);
1003 $price_min = $datapriceofproduct['price_min'];
1004 $usercanproductignorepricemin = ((getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && empty($user->rights->produit->ignore_price_min_advance)) || !getDolGlobalString('MAIN_USE_ADVANCED_PERMS'));
1006 $pu_ht = price2num($line->subprice / (1 + ($line->tva_tx / 100)), 'MU');
1009 if ($usercanproductignorepricemin && (!empty($price_min) && (price2num($line->subprice) * (1 - price2num($number) / 100) < price2num($price_min)))) {
1010 $langs->load("products
");
1011 dol_htmloutput_errors($langs->trans("CantBeLessThanMinPrice
", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, -1, $conf->currency)));
1013 $permissiontoupdateline = ($user->hasRight('takepos', 'editlines') && ($user->hasRight('takepos', 'editorderedlines') || $line->special_code != "4
"));
1014 if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1015 if ($invoice->status == $invoice::STATUS_DRAFT && $invoice->pos_source && $invoice->module_source == 'takepos') {
1016 $permissiontoupdateline = true;
1017 // TODO Add also a test on $_SESSION('publicobjectid'] defined at creation of object
1018 // TODO Check also that invoice->ref is (PROV-POS1-2) with 1 = terminal and 2, the invoice ID
1021 if (!$permissiontoupdateline) {
1022 dol_htmloutput_errors($langs->trans("NotEnoughPermissions
", "TakePos
"), null, 1);
1024 $vatratecode = $line->tva_tx;
1025 if ($line->vat_src_code) {
1026 $vatratecode .= ' ('.$line->vat_src_code.')';
1028 $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);
1035 $invoice->fetch($placeid);
1036 } elseif ($action == 'update_reduction_global' && $user->hasRight('takepos', 'editlines')) {
1037 foreach ($invoice->lines as $line) {
1038 $vatratecode = $line->tva_tx;
1039 if ($line->vat_src_code) {
1040 $vatratecode .= ' ('.$line->vat_src_code.')';
1042 $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);
1045 $invoice->fetch($placeid);
1048 if ($action=="setbatch
" && ($user->hasRight('takepos', 'run') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
1049 $constantforkey = 'CASHDESK_ID_WAREHOUSE'.$_SESSION["takeposterminal
"];
1050 $warehouseid = getDolGlobalInt($constantforkey); // TODO Get the wrehouse id from GETPOSTINT('warehouseid');
1051 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet SET batch =
'".$db->escape($batch)."', fk_warehouse =
".((int) $warehouseid);
1052 $sql .= " WHERE
rowid=
".((int) $idoflineadded);
1056 if ($action == "order
" && $placeid != 0 && ($user->hasRight('takepos', 'run') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
1057 include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
1058 if ((isModEnabled('receiptprinter') && getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term) > 0) || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter
" || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector
") {
1059 require_once DOL_DOCUMENT_ROOT.'/core/class/dolreceiptprinter.class.php';
1060 $printer = new dolReceiptPrinter($db);
1063 $sql = "SELECT label FROM
".MAIN_DB_PREFIX."takepos_floor_tables where
rowid=
".((int) $place);
1064 $resql = $db->query($sql);
1065 $row = $db->fetch_object($resql);
1066 $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>';
1067 $footerorder = '</tbody></table>'.dol_print_date(dol_now(), 'dayhour').'<br></html>';
1068 $order_receipt_printer1 = "";
1069 $order_receipt_printer2 = "";
1070 $order_receipt_printer3 = "";
1071 $catsprinter1 = explode(';', getDolGlobalString('TAKEPOS_PRINTED_CATEGORIES_1'));
1072 $catsprinter2 = explode(';', getDolGlobalString('TAKEPOS_PRINTED_CATEGORIES_2'));
1073 $catsprinter3 = explode(';', getDolGlobalString('TAKEPOS_PRINTED_CATEGORIES_3'));
1075 foreach ($invoice->lines as $line) {
1076 if ($line->special_code == "4
") {
1079 $c = new Categorie($db);
1080 $existing = $c->containing($line->fk_product, Categorie::TYPE_PRODUCT, 'id');
1081 $result = array_intersect($catsprinter1, $existing);
1082 $count = count($result);
1083 if (!$line->fk_product) {
1084 $count++; // Print Free-text item (Unassigned printer) to Printer 1
1088 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet set special_code=
'1' where
rowid=
".$line->id; //Set to print on printer 1
1090 $order_receipt_printer1 .= '<tr><td class="left
">';
1091 if ($line->fk_product) {
1092 $order_receipt_printer1 .= $line->product_label;
1094 $order_receipt_printer1 .= $line->description;
1096 $order_receipt_printer1 .= '</td><td class="right
">'.$line->qty;
1097 if (!empty($line->array_options['options_order_notes'])) {
1098 $order_receipt_printer1 .= "<br>(
".$line->array_options['options_order_notes'].")
";
1100 $order_receipt_printer1 .= '</td></tr>';
1103 if (((isModEnabled('receiptprinter') && getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term) > 0) || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter
" || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector
") && $linestoprint > 0) {
1104 $invoice->fetch($placeid); //Reload object before send to printer
1105 $printer->orderprinter = 1;
1107 echo "var orderprinter1esc=
'";
1108 $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
1111 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet
set special_code=
'4' where special_code=
'1' and fk_facture=
".$invoice->id; // Set as printed
1113 $invoice->fetch($placeid); //Reload object after set lines as printed
1116 foreach ($invoice->lines as $line) {
1117 if ($line->special_code == "4
") {
1120 $c = new Categorie($db);
1121 $existing = $c->containing($line->fk_product, Categorie::TYPE_PRODUCT, 'id');
1122 $result = array_intersect($catsprinter2, $existing);
1123 $count = count($result);
1126 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet
set special_code=
'2' where
rowid=
".$line->id; //Set to print on printer 2
1128 $order_receipt_printer2 .= '<tr>'.$line->product_label.'<td class="right
">'.$line->qty;
1129 if (!empty($line->array_options['options_order_notes'])) {
1130 $order_receipt_printer2 .= "<br>(
".$line->array_options['options_order_notes'].")
";
1132 $order_receipt_printer2 .= '</td></tr>';
1135 if (((isModEnabled('receiptprinter') && getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term) > 0) || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter
" || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector
") && $linestoprint > 0) {
1136 $invoice->fetch($placeid); //Reload object before send to printer
1137 $printer->orderprinter = 2;
1139 echo "var orderprinter2esc=
'";
1140 $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
1143 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet
set special_code=
'4' where special_code=
'2' and fk_facture=
".$invoice->id; // Set as printed
1145 $invoice->fetch($placeid); //Reload object after set lines as printed
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($catsprinter3, $existing);
1155 $count = count($result);
1158 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet
set special_code=
'3' where
rowid=
".$line->id; //Set to print on printer 3
1160 $order_receipt_printer3 .= '<tr>'.$line->product_label.'<td class="right
">'.$line->qty;
1161 if (!empty($line->array_options['options_order_notes'])) {
1162 $order_receipt_printer3 .= "<br>(
".$line->array_options['options_order_notes'].")
";
1164 $order_receipt_printer3 .= '</td></tr>';
1167 if (((isModEnabled('receiptprinter') && getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term) > 0) || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter
" || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector
") && $linestoprint > 0) {
1168 $invoice->fetch($placeid); //Reload object before send to printer
1169 $printer->orderprinter = 3;
1171 echo "var orderprinter3esc=
'";
1172 $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
1175 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet
set special_code=
'4' where special_code=
'3' and fk_facture=
".$invoice->id; // Set as printed
1177 $invoice->fetch($placeid); //Reload object after set lines as printed
1180 $sectionwithinvoicelink = '';
1181 if (($action == "valid
" || $action == "history
" || $action == 'creditnote') && $user->hasRight('takepos', 'run')) {
1182 $sectionwithinvoicelink .= '<!-- Section with invoice link -->'."\n
";
1183 $sectionwithinvoicelink .= '<span style="font-size:120%;
" class="center
">';
1184 $sectionwithinvoicelink .= $invoice->getNomUrl(1, '', 0, 0, '', 0, 0, -1, '_backoffice')." -
";
1185 $remaintopay = $invoice->getRemainToPay();
1186 if ($remaintopay > 0) {
1187 $sectionwithinvoicelink .= $langs->trans('RemainToPay').': <span class="amountremaintopay
" style="font-size: unset
">'.price($remaintopay, 1, $langs, 1, -1, -1, $conf->currency).'</span>';
1189 if ($invoice->paye) {
1190 $sectionwithinvoicelink .= '<span class="amountpaymentcomplete
" style="font-size: unset
">'.$langs->trans("Paid
").'</span>';
1192 $sectionwithinvoicelink .= $langs->trans('BillShortStatusValidated');
1196 $sectionwithinvoicelink .= '</span><br>';
1197 if (getDolGlobalInt('TAKEPOS_PRINT_INVOICE_DOC_INSTEAD_OF_RECEIPT')) {
1198 $sectionwithinvoicelink .= ' <a target="_blank
" class="button" href="' . DOL_URL_ROOT . '/document.php?token=
' . newToken() . '&modulepart=facture&file=
' . $invoice->ref . '/
' . $invoice->ref . '.pdf
">Invoice</a>';
1199 } elseif (getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector
") {
1200 if (getDolGlobalString('TAKEPOS_PRINT_SERVER') && filter_var($conf->global->TAKEPOS_PRINT_SERVER, FILTER_VALIDATE_URL) == true) {
1201 $sectionwithinvoicelink .= ' <button id="buttonprint
" type="button" onclick="TakeposConnector(
'.$placeid.')
">'.$langs->trans('PrintTicket').'</button>';
1203 $sectionwithinvoicelink .= ' <button id="buttonprint
" type="button" onclick="TakeposPrinting(
'.$placeid.')
">'.$langs->trans('PrintTicket').'</button>';
1205 } elseif ((isModEnabled('receiptprinter') && getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term) > 0) || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter
") {
1206 $sectionwithinvoicelink .= ' <button id="buttonprint
" type="button" onclick="DolibarrTakeposPrinting(
'.$placeid.')
">'.$langs->trans('PrintTicket').'</button>';
1208 $sectionwithinvoicelink .= ' <button id="buttonprint
" type="button" onclick="Print(
'.$placeid.')
">'.$langs->trans('PrintTicket').'</button>';
1209 if (getDolGlobalString('TAKEPOS_PRINT_WITHOUT_DETAILS')) {
1210 $sectionwithinvoicelink .= ' <button id="buttonprint
" type="button" onclick="PrintBox(
'.$placeid.', \
'without_details\')">'.$langs->trans(
'PrintWithoutDetails').
'</button>';
1213 $sectionwithinvoicelink .=
' <button id="buttonprint" type="button" onclick="Print('.$placeid.
', 1)">'.$langs->trans(
'GiftReceipt').
'</button>';
1217 $sectionwithinvoicelink .=
' <button id="buttonsend" type="button" onclick="SendTicket('.$placeid.
')">'.$langs->trans(
'SendTicket').
'</button>';
1220 if ($remaintopay <= 0 &&
getDolGlobalString(
'TAKEPOS_AUTO_PRINT_TICKETS') && $action !=
"history") {
1221 $sectionwithinvoicelink .=
'<script type="text/javascript">$("#buttonprint").click();</script>';
1231$form =
new Form($db);
1234if ((
getDolGlobalString(
'TAKEPOS_PHONE_BASIC_LAYOUT') == 1 && $conf->browser->layout ==
'phone') || defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1235 $title =
'TakePOS - Dolibarr '.DOL_VERSION;
1239 $head =
'<meta name="apple-mobile-web-app-title" content="TakePOS"/>
1240 <meta name="apple-mobile-web-app-capable" content="yes">
1241 <meta name="mobile-web-app-capable" content="yes">
1242 <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>';
1243 $arrayofcss = array(
1244 '/takepos/css/pos.css.php',
1246 $arrayofjs = array(
'/takepos/js/jquery.colorbox-min.js');
1249 top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss);
1251 print
'<body>'.
"\n";
1258<script
type=
"text/javascript">
1261<?php
if ($action==
"valid") {
1262 echo
"var place=0;";
1264var placeid=<?php echo($placeid > 0 ? $placeid : 0); ?>;
1265$(document).ready(
function() {
1266 var idoflineadded = <?php echo(empty($idoflineadded) ? 0 : $idoflineadded); ?>;
1268 $(
'.posinvoiceline').click(
function(){
1269 console.log(
"Click done on "+this.
id);
1270 $(
'.posinvoiceline').removeClass(
"selected");
1271 $(
this).addClass(
"selected");
1275 if (selectedline == this.
id) {
1278 selectedline = this.id;
1280 selectedtext=$(
'#'+selectedline).find(
"td:first").html();
1282 if (defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1283 print
'$("#phonediv1").load("'.DOL_URL_ROOT.
'/takepos/public/auto_order.php?action=editline&token='.newToken().
'&placeid="+placeid+"&selectedline="+selectedline, function() {
1290 if (idoflineadded > 0)
1292 console.log(
"Auto select "+idoflineadded);
1293 $(
'.posinvoiceline#'+idoflineadded).click();
1297if ($action ==
"order" && !empty($order_receipt_printer1)) {
1298 if (filter_var($conf->global->TAKEPOS_PRINT_SERVER, FILTER_VALIDATE_URL) ==
true) {
1302 url:
'<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>/printer/index.php',
1303 data:
'invoice='+orderprinter1esc
1310 url:
'http://<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>:8111/print',
1312 print $headerorder.$order_receipt_printer1.$footerorder; ?>'
1318if ($action ==
"order" && !empty($order_receipt_printer2)) {
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?printer=2',
1324 data:
'invoice='+orderprinter2esc
1331 url:
'http://<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>:8111/print2',
1333 print $headerorder.$order_receipt_printer2.$footerorder; ?>'
1339if ($action ==
"order" && !empty($order_receipt_printer3)) {
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=3',
1345 data:
'invoice='+orderprinter3esc
1352if ($action ==
"search" || $action ==
"valid") {
1354 parent.setFocusOnSearchField();
1359if ($action ==
"temp" && !empty($ticket_printer1)) {
1363 url:
'http://<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>:8111/print',
1365 print $header_soc.$header_ticket.$body_ticket.$ticket_printer1.$ticket_total.$footer_ticket; ?>'
1370if ($action ==
"search") {
1372 $(
'#search').focus();
1380function SendTicket(
id)
1382 console.log(
"Open box to select the Print/Send form");
1383 $.colorbox({href:
"send.php?facid="+id, width:
"70%", height:
"30%", transition:
"none", iframe:
"true", title:
'<?php echo dol_escape_js($langs->trans("SendTicket")); ?>'});
1387function PrintBox(
id, action) {
1388 console.log(
"Open box before printing");
1389 $.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
"); ?>"});
1393function Print(
id, gift){
1394 console.log(
"Call Print() to generate the receipt.");
1395 $.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")); ?>'});
1399function TakeposPrinting(
id){
1401 console.log(
"TakeposPrinting" +
id);
1402 $.get(
"receipt.php?facid="+
id,
function(data,
status) {
1403 receipt=data.replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g,
'');
1406 url:
'http://<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER
'); ?>:8111/print',
1413function TakeposConnector(
id){
1414 console.log(
"TakeposConnector" +
id);
1415 $.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) {
1418 url:
'<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER
'); ?>/printer/index.php',
1419 data:
'invoice='+data
1425function DolibarrTakeposPrinting(
id) {
1426 console.log(
"DolibarrTakeposPrinting Printing invoice ticket " +
id)
1429 data: { token:
'<?php echo currentToken(); ?>' },
1430 url:
"<?php print DOL_URL_ROOT.'/takepos/ajax/ajax.php?action=printinvoiceticket&token='.newToken().'&term='.urlencode(isset($_SESSION["takeposterminal
"]) ? $_SESSION["takeposterminal
"] : '').'&id='; ?>" + id,
1435function CreditNote() {
1436 $(
"#poslines").load(
"invoice.php?action=creditnote&token=<?php echo newToken() ?>&invoiceid="+placeid,
function() { });
1441 $(
"#poslines").load(
"invoice.php?action=addnote&token=<?php echo newToken() ?>&invoiceid="+placeid+
"&idline="+selectedline, {
"addnote": $(
"#textinput").val() });
1446$( document ).ready(
function() {
1447 console.log(
"Set customer info and sales in header placeid=<?php echo $placeid; ?> status=<?php echo $invoice->statut; ?>");
1450 $s = $langs->trans(
"Customer");
1451 if ($invoice->id > 0 && ($invoice->socid !=
getDolGlobalString($constforcompanyid))) {
1454 $contactids = $invoice->getIdContact(
'external',
'BILLING');
1455 $contactid = $contactids[0];
1456 if ($contactid > 0) {
1458 $contact->fetch($contactid);
1459 $s .=
" - " . $contact->getFullName($langs);
1465 $(
"#customerandsales").html(
'');
1466 $(
"#shoppingcart").html(
'');
1469 $(
"#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>');
1471 $(
"#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>');
1475 $sql =
"SELECT rowid, datec, ref FROM ".MAIN_DB_PREFIX.
"facture";
1476 $sql .=
" WHERE entity IN (".getEntity(
'invoice').
")";
1479 $sql .=
" AND ref LIKE '(PROV-POS".$db->escape(isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'').
"-0%'";
1482 $sql .=
" AND pos_source = '".$db->escape($_SESSION[
"takeposterminal"]).
"'";
1483 $sql .=
" AND module_source = 'takepos'";
1486 $sql .= $db->order(
'datec',
'ASC');
1487 $resql = $db->query($sql);
1490 while ($obj = $db->fetch_object($resql)) {
1491 echo
'$("#shoppingcart").append(\'';
1492 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=\\\'';
1493 $num_sale = str_replace(
")",
"", str_replace(
"(PROV-POS".$_SESSION[
"takeposterminal"].
"-",
"", $obj->ref));
1495 if (str_replace(
"-",
"", $num_sale) > $max_sale) {
1496 $max_sale = str_replace(
"-",
"", $num_sale);
1498 echo
'\\\'; invoiceid=\\\'';
1500 echo
'\\\'; Refresh();">';
1501 if ($placeid == $obj->rowid) {
1502 echo
'<span class="basketselected">';
1504 echo
'<span class="basketnotselected">';
1506 echo
'<span class="fa fa-shopping-cart paddingright"></span>'.dol_print_date($db->jdate($obj->datec),
'%H:%M',
'tzuser');
1510 echo
'$("#shoppingcart").append(\'<a onclick="place=\\\'0-';
1512 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>\');';
1520 $constantforkey =
'CASHDESK_NO_DECREASE_STOCK'. (isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
1521 if (isModEnabled(
'stock')) {
1523 $constantforkey =
'CASHDESK_ID_WAREHOUSE'. (isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
1525 if ($idwarehouse > 0) {
1526 $s =
'<span class="small">';
1528 $warehouse->fetch($idwarehouse);
1529 $s .=
'<span class="hideonsmartphone">'.$langs->trans(
"Warehouse").
'<br></span>'.$warehouse->ref;
1531 $s .=
' ('.$langs->trans(
"Closed").
')';
1534 print
"$('#infowarehouse').html('".dol_escape_js($s).
"');";
1535 print
'$("#infowarehouse").css("display", "inline-block");';
1537 $s =
'<span class="small hideonsmartphone">';
1538 $s .= $langs->trans(
"StockChangeDisabled").
'<br>'.$langs->trans(
"NoWarehouseDefinedForTerminal");
1540 print
"$('#infowarehouse').html('".dol_escape_js($s).
"');";
1541 if (!empty($conf->dol_optimize_smallscreen)) {
1542 print
'$("#infowarehouse").css("display", "none");';
1546 $s =
'<span class="small hideonsmartphone">'.$langs->trans(
"StockChangeDisabled").
'</span>';
1547 print
"$('#infowarehouse').html('".dol_escape_js($s).
"');";
1548 if (!empty($conf->dol_optimize_smallscreen)) {
1549 print
'$("#infowarehouse").css("display", "none");';
1557 if (isModEnabled(
'adherent') && $invoice->socid > 0 && $invoice->socid !=
getDolGlobalInt($constforcompanyid)) {
1558 $s =
'<span class="small">';
1559 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
1560 $langs->load(
"members");
1561 $s .= $langs->trans(
"Member").
': ';
1563 $result = $adh->fetch(
'',
'', $invoice->socid);
1565 $adh->ref = $adh->getFullName($langs);
1569 $s .= $adh->getFullName($langs);
1570 $s .=
' - '.$adh->type;
1571 if ($adh->datefin) {
1572 $s .=
'<br>'.$langs->trans(
"SubscriptionEndDate").
': '.
dol_print_date($adh->datefin,
'day');
1573 if ($adh->hasDelay()) {
1574 $s .=
" ".img_warning($langs->trans(
"Late"));
1577 $s .=
'<br>'.$langs->trans(
"SubscriptionNotReceived");
1578 if ($adh->statut > 0) {
1579 $s .=
" ".img_warning($langs->trans(
"Late"));
1586 $s .=
'<br>'.$langs->trans(
"ThirdpartyNotLinkedToMember");
1591 $(
"#moreinfo").html(
'<?php print dol_escape_js($s); ?>');
1598 echo
"function CustomerDisplay(){";
1599 echo
"var line1='".$CUSTOMER_DISPLAY_line1.
"'.substring(0,20);";
1600 echo
"line1=line1.padEnd(20);";
1601 echo
"var line2='".$CUSTOMER_DISPLAY_line2.
"'.substring(0,20);";
1602 echo
"line2=line2.padEnd(20);";
1605 data: { text: line1+line2 },
1606 url: '".getDolGlobalString(
'TAKEPOS_PRINT_SERVER').
"/display/index.php',
1617if (!empty($conf->use_javascript_ajax)) {
1618 print
"\n".
'<!-- Includes JS Footer of Dolibarr -->'.
"\n";
1619 print
'<script src="'.DOL_URL_ROOT.
'/core/js/lib_foot.js.php?lang='.$langs->defaultlang.
'"></script>'.
"\n";