92 header($_SERVER[
'SERVER_PROTOCOL'].
' 500 Internal Server Error',
true, 500);
98$number =
GETPOST(
'number',
'alpha');
99$idline =
GETPOST(
'idline',
'int');
100$selectedline =
GETPOST(
'selectedline',
'int');
101$desc =
GETPOST(
'desc',
'alphanohtml');
105$invoiceid =
GETPOST(
'invoiceid',
'int');
114if ($pay ==
'cheque') {
121 $sql =
"SELECT id FROM ".MAIN_DB_PREFIX.
"c_paiement";
122 $sql .=
" WHERE entity IN (".getEntity(
'c_paiement').
")";
123 $sql .=
" AND code = '".$db->escape($paycode).
"'";
124 $resql = $db->query($sql);
126 $obj = $db->fetch_object($resql);
128 $paiementid = $obj->id;
135 $ret = $invoice->fetch($invoiceid);
137 $ret = $invoice->fetch(
'',
'(PROV-POS'. (isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'') .
'-'.$place.
')');
140 $placeid = $invoice->id;
143$constforcompanyid =
'CASHDESK_ID_THIRDPARTY'. (isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
146if ($invoice->socid > 0) {
147 $soc->fetch($invoice->socid);
153if (isModEnabled(
'multicurrency') && !empty($_SESSION[
"takeposcustomercurrency"])) {
154 if ($invoice->multicurrency_code != $_SESSION[
"takeposcustomercurrency"]) {
155 $invoice->setMulticurrencyCode($_SESSION[
"takeposcustomercurrency"]);
159$term = empty($_SESSION[
"takeposterminal"]) ? 1 : $_SESSION[
"takeposterminal"];
167$reshook=$hookmanager->executeHooks(
'doActions', $parameters, $invoice, $action);
172if (empty($reshook)) {
174 if ($action ==
'valid' && $user->hasRight(
'facture',
'creer')) {
179 $bankaccount =
GETPOST(
'accountid',
'int');
182 $bankaccount =
getDolGlobalString(
'CASHDESK_ID_BANKACCOUNT_CASH'.$_SESSION[
"takeposterminal"]);
183 } elseif ($pay ==
"CHQ") {
184 $bankaccount =
getDolGlobalString(
'CASHDESK_ID_BANKACCOUNT_CHEQUE'.$_SESSION[
"takeposterminal"]);
186 $accountname =
"CASHDESK_ID_BANKACCOUNT_".$pay.$_SESSION[
"takeposterminal"];
191 if ($bankaccount <= 0 && $pay !=
"delayed" && isModEnabled(
"banque")) {
192 $errormsg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"BankAccount"));
200 $invoice->fetch($placeid);
204 if ($invoice->total_ttc < 0) {
205 $invoice->type = $invoice::TYPE_CREDIT_NOTE;
207 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"facture";
208 $sql .=
" WHERE entity IN (".getEntity(
'invoice').
")";
209 $sql .=
" AND fk_soc = ".((int) $invoice->socid);
210 $sql .=
" AND type <> ".Facture::TYPE_CREDIT_NOTE;
211 $sql .=
" AND fk_statut >= ".$invoice::STATUS_VALIDATED;
212 $sql .=
" ORDER BY rowid DESC";
214 $resql = $db->query($sql);
216 $obj = $db->fetch_object($resql);
217 $fk_source = $obj->rowid;
218 if ($fk_source ==
null) {
219 fail($langs->transnoentitiesnoconv(
"NoPreviousBillForCustomer"));
222 fail($langs->transnoentitiesnoconv(
"NoPreviousBillForCustomer"));
224 $invoice->fk_facture_source = $fk_source;
225 $invoice->update($user);
228 $constantforkey =
'CASHDESK_NO_DECREASE_STOCK'.(isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
233 if ($invoice->getRemainToPay() > 0) {
239 } elseif (count($invoice->lines) == 0) {
243 } elseif (isModEnabled(
'stock') && !isModEnabled(
'productbatch') &&
getDolGlobalString($constantforkey) !=
"1") {
246 $savconst = $conf->global->STOCK_CALCULATE_ON_BILL;
248 if (isModEnabled(
'productbatch') && !
getDolGlobalInt(
'CASHDESK_FORCE_DECREASE_STOCK')) {
249 $conf->global->STOCK_CALCULATE_ON_BILL = 0;
252 $conf->global->STOCK_CALCULATE_ON_BILL = 1;
255 $constantforkey =
'CASHDESK_ID_WAREHOUSE'.$_SESSION[
"takeposterminal"];
256 dol_syslog(
"Validate invoice with stock change into warehouse defined into constant ".$constantforkey.
" = ".
getDolGlobalString($constantforkey));
259 if (isModEnabled(
'productbatch') &&
getDolGlobalString(
'CASHDESK_FORCE_DECREASE_STOCK')) {
260 require_once DOL_DOCUMENT_ROOT.
'/product/class/productbatch.class.php';
263 $res = $invoice->validate($user,
'',
getDolGlobalInt($constantforkey), 0, $batch_rule);
265 $conf->global->STOCK_CALCULATE_ON_BILL = $savconst;
268 $res = $invoice->validate($user);
271 $langs->load(
"admin");
272 dol_htmloutput_errors($invoice->error ==
'NotConfigured' ? $langs->trans(
"NotConfigured").
' (TakePos numbering module)' : $invoice->error, $invoice->errors, 1);
277 if (!$error && $res >= 0) {
278 $remaintopay = $invoice->getRemainToPay();
279 if ($remaintopay > 0) {
281 $payment->datepaye = $now;
282 $payment->fk_account = $bankaccount;
283 $payment->amounts[$invoice->id] = $amountofpayment;
290 if ($amountofpayment <= 0 || $amountofpayment > $remaintopay) {
291 $payment->amounts[$invoice->id] = $remaintopay;
294 $payment->paiementid = $paiementid;
295 $payment->num_payment = $invoice->ref;
297 if ($pay !=
"delayed") {
298 $payment->create($user);
299 $res = $payment->addPaymentToBank($user,
'payment',
'(CustomerInvoicePayment)', $bankaccount,
'',
'');
304 $remaintopay = $invoice->getRemainToPay();
310 if ($remaintopay == 0) {
311 dol_syslog(
"Invoice is paid, so we set it to status Paid");
312 $result = $invoice->setPaid($user);
317 $invoice->setPaymentMethods($paiementid);
319 dol_syslog(
"Invoice is not paid, remain to pay = ".$remaintopay);
326 if (!$error && $res >= 0) {
327 if (isModEnabled(
'stock') && isModEnabled(
'productbatch')) {
328 require_once DOL_DOCUMENT_ROOT .
"/product/stock/class/mouvementstock.class.php";
329 $constantforkey =
'CASHDESK_ID_WAREHOUSE'.$_SESSION[
"takeposterminal"];
331 $labeltakeposmovement =
'TakePOS - '.$langs->trans(
"Invoice").
' '.$invoice->ref;
333 foreach ($invoice->lines as $line) {
334 $warehouseid = ($line->fk_warehouse ? $line->fk_warehouse :
getDolGlobalInt($constantforkey));
337 if ($line->batch !=
'' && $warehouseid > 0) {
339 $prod_batch->find(0,
'',
'', $line->batch, $warehouseid);
341 $mouvP->origin = $invoice;
342 $res = $mouvP->livraison($user, $line->fk_product, $warehouseid, $line->qty, $line->price, $labeltakeposmovement,
'',
'',
'', $prod_batch->batch, $prod_batch->id, $inventorycode);
349 $mouvP->origin = $invoice;
350 $res = $mouvP->livraison($user, $line->fk_product, $warehouseid, $line->qty, $line->price, $labeltakeposmovement,
'',
'',
'',
'', 0, $inventorycode);
360 if (!$error && $res >= 0) {
366 if ($action ==
'creditnote' && $user->hasRight(
'facture',
'creer')) {
369 $creditnote =
new Facture($db);
370 $creditnote->socid = $invoice->socid;
372 $creditnote->module_source =
'takepos';
373 $creditnote->pos_source = isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'' ;
375 $creditnote->fk_facture_source = $placeid;
378 $creditnote->create($user);
380 foreach ($invoice->lines as $line) {
382 if (method_exists($line,
'fetch_optionals')) {
384 $line->fetch_optionals();
387 if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) {
392 if (!empty($invoice->situation_counter)) {
393 $source_fk_prev_id = $line->fk_prev_id;
394 $line->fk_prev_id = $line->id;
395 if (!empty($invoice->tab_previous_situation_invoice)) {
398 $tab_jumped_credit_notes = array();
399 $lineIndex = count($invoice->tab_previous_situation_invoice) - 1;
400 $searchPreviousInvoice =
true;
401 while ($searchPreviousInvoice) {
402 if ($invoice->tab_previous_situation_invoice[$lineIndex]->situation_cycle_ref || $lineIndex < 1) {
403 $searchPreviousInvoice =
false;
407 $tab_jumped_credit_notes[$lineIndex] = $invoice->tab_previous_situation_invoice[$lineIndex]->id;
413 $maxPrevSituationPercent = 0;
414 foreach ($invoice->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine) {
415 if ($prevLine->id == $source_fk_prev_id) {
416 $maxPrevSituationPercent = max($maxPrevSituationPercent, $prevLine->situation_percent);
419 $line->total_ht = $line->total_ht - $prevLine->total_ht;
420 $line->total_tva = $line->total_tva - $prevLine->total_tva;
421 $line->total_ttc = $line->total_ttc - $prevLine->total_ttc;
422 $line->total_localtax1 = $line->total_localtax1 - $prevLine->total_localtax1;
423 $line->total_localtax2 = $line->total_localtax2 - $prevLine->total_localtax2;
425 $line->multicurrency_subprice = $line->multicurrency_subprice - $prevLine->multicurrency_subprice;
426 $line->multicurrency_total_ht = $line->multicurrency_total_ht - $prevLine->multicurrency_total_ht;
427 $line->multicurrency_total_tva = $line->multicurrency_total_tva - $prevLine->multicurrency_total_tva;
428 $line->multicurrency_total_ttc = $line->multicurrency_total_ttc - $prevLine->multicurrency_total_ttc;
433 $line->situation_percent = $maxPrevSituationPercent - $line->situation_percent;
438 $maxPrevSituationPercent = 0;
439 foreach ($tab_jumped_credit_notes as $index => $creditnoteid) {
440 foreach ($invoice->tab_previous_situation_invoice[$index]->lines as $prevLine) {
441 if ($prevLine->fk_prev_id == $source_fk_prev_id) {
442 $maxPrevSituationPercent = $prevLine->situation_percent;
444 $line->total_ht -= $prevLine->total_ht;
445 $line->total_tva -= $prevLine->total_tva;
446 $line->total_ttc -= $prevLine->total_ttc;
447 $line->total_localtax1 -= $prevLine->total_localtax1;
448 $line->total_localtax2 -= $prevLine->total_localtax2;
450 $line->multicurrency_subprice -= $prevLine->multicurrency_subprice;
451 $line->multicurrency_total_ht -= $prevLine->multicurrency_total_ht;
452 $line->multicurrency_total_tva -= $prevLine->multicurrency_total_tva;
453 $line->multicurrency_total_ttc -= $prevLine->multicurrency_total_ttc;
459 $line->situation_percent += $maxPrevSituationPercent;
466 $line->fk_facture = $creditnote->id;
467 $line->fk_parent_line = $fk_parent_line;
469 $line->subprice = -$line->subprice;
470 $line->pa_ht = $line->pa_ht;
471 $line->total_ht = -$line->total_ht;
472 $line->total_tva = -$line->total_tva;
473 $line->total_ttc = -$line->total_ttc;
474 $line->total_localtax1 = -$line->total_localtax1;
475 $line->total_localtax2 = -$line->total_localtax2;
477 $line->multicurrency_subprice = -$line->multicurrency_subprice;
478 $line->multicurrency_total_ht = -$line->multicurrency_total_ht;
479 $line->multicurrency_total_tva = -$line->multicurrency_total_tva;
480 $line->multicurrency_total_ttc = -$line->multicurrency_total_ttc;
482 $result = $line->insert(0, 1);
484 $creditnote->lines[] = $line;
487 if ($result > 0 && $line->product_type == 9) {
488 $fk_parent_line = $result;
491 $creditnote->update_price(1);
493 $constantforkey =
'CASHDESK_NO_DECREASE_STOCK'.(isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
495 $savconst = $conf->global->STOCK_CALCULATE_ON_BILL;
496 $conf->global->STOCK_CALCULATE_ON_BILL = 1;
497 $constantforkey =
'CASHDESK_ID_WAREHOUSE'.(isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
498 dol_syslog(
"Validate invoice with stock change into warehouse defined into constant ".$constantforkey.
" = ".
getDolGlobalString($constantforkey));
500 if (isModEnabled(
'productbatch') &&
getDolGlobalString(
'CASHDESK_FORCE_DECREASE_STOCK')) {
501 require_once DOL_DOCUMENT_ROOT.
'/product/class/productbatch.class.php';
504 $res = $creditnote->validate($user,
'',
getDolGlobalString($constantforkey), 0, $batch_rule);
505 $conf->global->STOCK_CALCULATE_ON_BILL = $savconst;
507 $res = $creditnote->validate($user);
510 if (!$error && $res >= 0) {
517 if (($action ==
'history' || $action ==
'creditnote') && $user->hasRight(
'takepos',
'run')) {
518 if ($action ==
'creditnote') {
519 $placeid = $creditnote->id;
521 $placeid = (int)
GETPOST(
'placeid',
'int');
524 $invoice->fetch($placeid);
528 if (($action ==
"addline" || $action ==
"freezone") && $placeid == 0 && ($user->hasRight(
'takepos',
'run') || defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
531 include_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
534 $invoice->module_source =
'takepos';
535 $invoice->pos_source = isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'' ;
536 $invoice->entity = !empty($_SESSION[
"takeposinvoiceentity"]) ? $_SESSION[
"takeposinvoiceentity"] : $conf->entity;
538 if ($invoice->socid <= 0) {
539 $langs->load(
'errors');
545 $placeid = $invoice->create($user);
549 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facture set ref='(PROV-POS".$_SESSION[
"takeposterminal"].
"-".$place.
")' where rowid = ".((int) $placeid);
550 $resql = $db->query($sql);
564 if ($action ==
"addline" && ($user->hasRight(
'takepos',
'run') || defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
566 $prod->fetch($idproduct);
569 $customer->fetch($invoice->socid);
571 $datapriceofproduct = $prod->getSellPrice($mysoc, $customer, 0);
573 $qty = GETPOSTISSET(
'qty') ?
GETPOST(
'qty',
'int') : 1;
574 $price = $datapriceofproduct[
'pu_ht'];
575 $price_ttc = $datapriceofproduct[
'pu_ttc'];
577 $price_base_type = empty($datapriceofproduct[
'price_base_type']) ?
'HT' : $datapriceofproduct[
'price_base_type'];
578 $tva_tx = $datapriceofproduct[
'tva_tx'];
579 $tva_npr = $datapriceofproduct[
'tva_npr'];
582 $localtax1_tx =
get_localtax($tva_tx, 1, $customer, $mysoc, $tva_npr);
583 $localtax2_tx =
get_localtax($tva_tx, 2, $customer, $mysoc, $tva_npr);
586 if (isModEnabled(
'productbatch') && isModEnabled(
'stock')) {
587 $batch =
GETPOST(
'batch',
'alpha');
589 if (!empty($batch)) {
590 $action =
"setbatch";
591 } elseif ($prod->status_batch > 0) {
596 $prod->load_stock(
'warehouseopen');
598 $constantforkey =
'CASHDESK_ID_WAREHOUSE'.$_SESSION[
"takeposterminal"];
602 foreach ($prod->stock_warehouse as $tmpwarehouseid => $tmpval) {
607 if (!empty($prod->stock_warehouse[$tmpwarehouseid]) && is_array($prod->stock_warehouse[$tmpwarehouseid]->detail_batch)) {
608 if (is_object($prod->stock_warehouse[$tmpwarehouseid]) && count($prod->stock_warehouse[$tmpwarehouseid]->detail_batch)) {
609 foreach ($prod->stock_warehouse[$tmpwarehouseid]->detail_batch as $dbatch) {
618 echo
"function addbatch(batch, warehouseid) {\n";
619 echo
"console.log('We add batch '+batch+' from warehouse id '+warehouseid);\n";
620 echo
'$("#poslines").load("invoice.php?action=addline&batch="+batch+"&warehouseid="+warehouseid+"&place='.$place.
'&idproduct='.$idproduct.
'&token='.newToken().
'", function() {});'.
"\n";
625 echo
"<center>".$langs->trans(
"SearchIntoBatch").
": <b> $nbofsuggested </b></center><br><table>";
626 foreach ($prod->stock_warehouse as $tmpwarehouseid => $tmpval) {
631 if (!empty($prod->stock_warehouse[$tmpwarehouseid]) && is_array($prod->stock_warehouse[$tmpwarehouseid]->detail_batch)) {
632 foreach ($prod->stock_warehouse[$tmpwarehouseid]->detail_batch as $dbatch) {
633 $batchStock = + $dbatch->qty;
634 $quantityToBeDelivered = 1;
635 $deliverableQty = min($quantityToBeDelivered, $batchStock);
637 print
'<!-- subj='.$suggestednb.
'/'.$nbofsuggested.
' -->';
638 print
'<!-- Show details of lot -->';
639 print
'<td class="left">';
641 $detail .=
'<span class="opacitymedium">'.$langs->trans(
"LotSerial").
':</span> '.$dbatch->batch;
648 $detail .=
'</td><td>';
649 $detail .=
'<span class="opacitymedium">'.$langs->trans(
"Qty").
':</span> '.$dbatch->qty;
650 $detail .=
'</td><td>';
651 $detail .=
' <button class="marginleftonly" onclick="addbatch(\''.dol_escape_js($dbatch->batch).
'\',
'.$tmpwarehouseid.')
">'.$langs->trans("Select
")."</
button>
";
655 $quantityToBeDelivered -= $deliverableQty;
656 if ($quantityToBeDelivered < 0) {
657 $quantityToBeDelivered = 0;
666 print '</body></html>';
672 if (getDolGlobalString('TAKEPOS_SUPPLEMENTS')) {
673 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
674 $cat = new Categorie($db);
675 $categories = $cat->containing($idproduct, 'product');
676 $found = (array_search(getDolGlobalInt('TAKEPOS_SUPPLEMENTS_CATEGORY'), array_column($categories, 'id')));
677 if ($found !== false) { // If this product is a supplement
678 $sql = "SELECT fk_parent_line FROM
".MAIN_DB_PREFIX."facturedet where
rowid =
".((int) $selectedline);
679 $resql = $db->query($sql);
680 $row = $db->fetch_array($resql);
681 if ($row[0] == null) {
682 $parent_line = $selectedline;
684 $parent_line = $row[0]; //If the parent line is already a supplement, add the supplement to the main product
691 // Group if enabled. Skip group if line already sent to the printer
692 if (getDolGlobalString('TAKEPOS_GROUP_SAME_PRODUCT')) {
693 foreach ($invoice->lines as $line) {
694 if ($line->product_ref == $prod->ref) {
695 if ($line->special_code==4) {
697 } // If this line is sended to printer create new line
698 // check if qty in stock
699 if (getDolGlobalString('TAKEPOS_QTY_IN_STOCK') && (($line->qty + $qty) > $prod->stock_reel)) {
700 $invoice->error = $langs->trans('NotEnoughInStock');
701 dol_htmloutput_errors($invoice->error, $invoice->errors, 1);
705 $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);
707 dol_htmloutput_errors($invoice->error, $invoice->errors, 1);
709 $idoflineadded = $line->id;
715 if ($idoflineadded <= 0 && empty($err)) {
716 $invoice->fetch_thirdparty();
717 $array_options = array();
719 $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);
721 /* setup of margin calculation */
722 if (isset($conf->global->MARGIN_TYPE)) {
723 if (getDolGlobalString('MARGIN_TYPE') == 'pmp' && !empty($prod->pmp)) {
724 $line['fk_fournprice'] = null;
725 $line['pa_ht'] = $prod->pmp;
726 } elseif (getDolGlobalString('MARGIN_TYPE') == 'costprice' && !empty($prod->cost_price)) {
727 $line['fk_fournprice'] = null;
728 $line['pa_ht'] = $prod->cost_price;
730 // default is fournprice
731 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
732 $pf = new ProductFournisseur($db);
733 if ($pf->find_min_price_product_fournisseur($idproduct, $qty) > 0) {
734 $line['fk_fournprice'] = $pf->product_fourn_price_id;
735 $line['pa_ht'] = $pf->fourn_unitprice_with_discount;
736 if (getDolGlobalString('PRODUCT_CHARGES') && $pf->fourn_charges > 0) {
737 $line['pa_ht'] += $pf->fourn_charges / $pf->fourn_qty;
743 // complete line by hook
744 $parameters = array('prod' => $prod, 'line' => $line);
745 $reshook=$hookmanager->executeHooks('completeTakePosAddLine', $parameters, $invoice, $action); // Note that $action and $line may have been modified by some hooks
747 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
751 if (empty($reshook)) {
752 if (!empty($hookmanager->resArray)) {
753 $line = $hookmanager->resArray;
756 // check if qty in stock
757 if (getDolGlobalString('TAKEPOS_QTY_IN_STOCK') && $qty > $prod->stock_reel) {
758 $invoice->error = $langs->trans('NotEnoughInStock');
759 dol_htmloutput_errors($invoice->error, $invoice->errors, 1);
764 $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);
768 if (getDolGlobalString('TAKEPOS_CUSTOMER_DISPLAY')) {
769 $CUSTOMER_DISPLAY_line1 = $prod->label;
770 $CUSTOMER_DISPLAY_line2 = price($price_ttc);
774 $invoice->fetch($placeid);
777 // If we add a line by submitting freezone form (invoice exists here because it was created juste before if it didn't exists)
778 if ($action == "freezone
" && $user->hasRight('takepos', 'run')) {
779 $customer = new Societe($db);
780 $customer->fetch($invoice->socid);
782 $tva_tx = GETPOST('tva_tx', 'alpha');
784 if (!preg_match('/\((.*)\)/', $tva_tx)) {
785 $tva_tx = price2num($tva_tx);
788 $tva_tx = get_default_tva($mysoc, $customer);
792 $localtax1_tx = get_localtax($tva_tx, 1, $customer, $mysoc, $tva_npr);
793 $localtax2_tx = get_localtax($tva_tx, 2, $customer, $mysoc, $tva_npr);
795 $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);
797 dol_htmloutput_errors($invoice->error, $invoice->errors, 1);
799 $invoice->fetch($placeid);
802 if ($action == "addnote
" && ($user->hasRight('takepos', 'run') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
803 $desc = GETPOST('addnote', 'alpha');
805 $invoice->update_note($desc, '_public');
807 foreach ($invoice->lines as $line) {
808 if ($line->id == $idline) {
809 $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);
813 $invoice->fetch($placeid);
816 if ($action == "deleteline
" && ($user->hasRight('takepos', 'run') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
818 $permissiontoupdateline = ($user->hasRight('takepos', 'editlines') && ($user->hasRight('takepos', 'editorderedlines') || $line->special_code != "4
"));
819 if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
820 if ($invoice->status == $invoice::STATUS_DRAFT && $invoice->pos_source && $invoice->module_source == 'takepos') {
821 $permissiontoupdateline = true;
822 // TODO Add also a test on $_SESSION('publicobjectid'] defined at creation of object
823 // TODO Check also that invoice->ref is (PROV-POS1-2) with 1 = terminal and 2, the invoice ID
827 if ($idline > 0 && $placeid > 0) { // If invoice exists and line selected. To avoid errors if deleted from another device or no line selected.
828 $invoice->deleteline($idline);
829 $invoice->fetch($placeid);
830 } elseif ($placeid > 0) { // If invoice exists but no line selected, proceed to delete last line.
831 $sql = "SELECT
rowid FROM
".MAIN_DB_PREFIX."facturedet where fk_facture =
".((int) $placeid)." ORDER BY
rowid DESC
";
832 $resql = $db->query($sql);
833 $row = $db->fetch_array($resql);
834 $deletelineid = $row[0];
835 $invoice->deleteline($deletelineid);
836 $invoice->fetch($placeid);
839 if (count($invoice->lines) == 0) {
840 $invoice->delete($user);
842 if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
843 header("Location:
".DOL_URL_ROOT."/takepos/public/auto_order.php
");
845 header("Location:
".DOL_URL_ROOT."/takepos/invoice.php
");
851 // Action to delete or discard an invoice
852 if ($action == "delete
" && ($user->hasRight('takepos', 'run') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
853 // $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.
855 $result = $invoice->fetch($placeid);
857 if ($result > 0 && $invoice->statut == Facture::STATUS_DRAFT) {
860 // We delete the lines
862 foreach ($invoice->lines as $line) {
863 $tmpres = $invoice->deleteline($line->id);
870 $sql = "UPDATE
".MAIN_DB_PREFIX."facture
";
871 $varforconst = 'CASHDESK_ID_THIRDPARTY'.$_SESSION["takeposterminal
"];
872 $sql .= " SET fk_soc =
".((int) getDolGlobalString($varforconst)).",
";
873 $sql .= " datec =
'".$db->idate(dol_now())."'";
874 $sql .= " WHERE entity IN (
".getEntity('invoice').")
";
875 $sql .= " AND
ref =
'(PROV-POS".$db->escape($_SESSION["takeposterminal"]."-".$place).")'";
876 $resql1 = $db->query($sql);
878 if ($resdeletelines && $resql1) {
884 $invoice->fetch($placeid);
889 if ($action == "updateqty
") { // Test on permission is done later
890 foreach ($invoice->lines as $line) {
891 if ($line->id == $idline) {
892 $permissiontoupdateline = ($user->hasRight('takepos', 'editlines') && ($user->hasRight('takepos', 'editorderedlines') || $line->special_code != "4
"));
893 if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
894 if ($invoice->status == $invoice::STATUS_DRAFT && $invoice->pos_source && $invoice->module_source == 'takepos') {
895 $permissiontoupdateline = true;
896 // TODO Add also a test on $_SESSION('publicobjectid'] defined at creation of object
897 // TODO Check also that invoice->ref is (PROV-POS1-2) with 1 = terminal and 2, the invoice ID
900 if (!$permissiontoupdateline) {
901 dol_htmloutput_errors($langs->trans("NotEnoughPermissions
", "TakePos
").' - No permission to updateqty', null, 1);
903 $vatratecode = $line->tva_tx;
904 if ($line->vat_src_code) {
905 $vatratecode .= ' ('.$line->vat_src_code.')';
908 $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);
913 $invoice->fetch($placeid);
916 if ($action == "updateprice
") { // Test on permission is done later
917 $customer = new Societe($db);
918 $customer->fetch($invoice->socid);
920 foreach ($invoice->lines as $line) {
921 if ($line->id == $idline) {
922 $prod = new Product($db);
923 $prod->fetch($line->fk_product);
924 $datapriceofproduct = $prod->getSellPrice($mysoc, $customer, 0);
925 $price_min = $datapriceofproduct['price_min'];
926 $usercanproductignorepricemin = ((getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && empty($user->rights->produit->ignore_price_min_advance)) || !getDolGlobalString('MAIN_USE_ADVANCED_PERMS'));
927 $pu_ht = price2num($number / (1 + ($line->tva_tx / 100)), 'MU');
929 if ($usercanproductignorepricemin && (!empty($price_min) && (price2num($pu_ht) * (1 - price2num($line->remise_percent) / 100) < price2num($price_min)))) {
930 $langs->load("products
");
931 dol_htmloutput_errors($langs->trans("CantBeLessThanMinPrice
", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, -1, $conf->currency)));
932 //echo $langs->trans("CantBeLessThanMinPrice
");
934 $permissiontoupdateline = ($user->hasRight('takepos', 'editlines') && ($user->hasRight('takepos', 'editorderedlines') || $line->special_code != "4
"));
935 if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
936 if ($invoice->status == $invoice::STATUS_DRAFT && $invoice->pos_source && $invoice->module_source == 'takepos') {
937 $permissiontoupdateline = true;
938 // TODO Add also a test on $_SESSION('publicobjectid'] defined at creation of object
939 // TODO Check also that invoice->ref is (PROV-POS1-2) with 1 = terminal and 2, the invoice ID
943 $vatratecode = $line->tva_tx;
944 if ($line->vat_src_code) {
945 $vatratecode .= ' ('.$line->vat_src_code.')';
948 if (!$permissiontoupdateline) {
949 dol_htmloutput_errors($langs->trans("NotEnoughPermissions
", "TakePos
").' - No permission to updateprice', null, 1);
950 } elseif (getDolGlobalInt('TAKEPOS_CHANGE_PRICE_HT') == 1) {
951 $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);
953 $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);
960 $invoice->fetch($placeid);
963 if ($action == "updatereduction
") { // Test on permission is done later
964 $customer = new Societe($db);
965 $customer->fetch($invoice->socid);
967 foreach ($invoice->lines as $line) {
968 if ($line->id == $idline) {
969 dol_syslog("updatereduction Process line
".$line->id.' to apply discount of '.$number.'%');
971 $prod = new Product($db);
972 $prod->fetch($line->fk_product);
974 $datapriceofproduct = $prod->getSellPrice($mysoc, $customer, 0);
975 $price_min = $datapriceofproduct['price_min'];
976 $usercanproductignorepricemin = ((getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && empty($user->rights->produit->ignore_price_min_advance)) || !getDolGlobalString('MAIN_USE_ADVANCED_PERMS'));
978 $pu_ht = price2num($line->subprice / (1 + ($line->tva_tx / 100)), 'MU');
981 if ($usercanproductignorepricemin && (!empty($price_min) && (price2num($line->subprice) * (1 - price2num($number) / 100) < price2num($price_min)))) {
982 $langs->load("products
");
983 dol_htmloutput_errors($langs->trans("CantBeLessThanMinPrice
", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, -1, $conf->currency)));
985 $permissiontoupdateline = ($user->hasRight('takepos', 'editlines') && ($user->hasRight('takepos', 'editorderedlines') || $line->special_code != "4
"));
986 if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
987 if ($invoice->status == $invoice::STATUS_DRAFT && $invoice->pos_source && $invoice->module_source == 'takepos') {
988 $permissiontoupdateline = true;
989 // TODO Add also a test on $_SESSION('publicobjectid'] defined at creation of object
990 // TODO Check also that invoice->ref is (PROV-POS1-2) with 1 = terminal and 2, the invoice ID
993 if (!$permissiontoupdateline) {
994 dol_htmloutput_errors($langs->trans("NotEnoughPermissions
", "TakePos
"), null, 1);
996 $vatratecode = $line->tva_tx;
997 if ($line->vat_src_code) {
998 $vatratecode .= ' ('.$line->vat_src_code.')';
1000 $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);
1007 $invoice->fetch($placeid);
1008 } elseif ($action == 'update_reduction_global' && $user->hasRight('takepos', 'editlines')) {
1009 foreach ($invoice->lines as $line) {
1010 $vatratecode = $line->tva_tx;
1011 if ($line->vat_src_code) {
1012 $vatratecode .= ' ('.$line->vat_src_code.')';
1014 $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);
1017 $invoice->fetch($placeid);
1020 if ($action=="setbatch
" && ($user->hasRight('takepos', 'run') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
1021 $constantforkey = 'CASHDESK_ID_WAREHOUSE'.$_SESSION["takeposterminal
"];
1022 $warehouseid = getDolGlobalInt($constantforkey); // TODO Get the wrehouse id from GETPOSTINT('warehouseid');
1023 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet SET batch =
'".$db->escape($batch)."', fk_warehouse =
".((int) $warehouseid);
1024 $sql .= " WHERE
rowid=
".((int) $idoflineadded);
1028 if ($action == "order
" && $placeid != 0 && ($user->hasRight('takepos', 'run') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
1029 include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
1030 if ((isModEnabled('receiptprinter') && getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term) > 0) || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter
" || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector
") {
1031 require_once DOL_DOCUMENT_ROOT.'/core/class/dolreceiptprinter.class.php';
1032 $printer = new dolReceiptPrinter($db);
1035 $sql = "SELECT label FROM
".MAIN_DB_PREFIX."takepos_floor_tables where
rowid=
".((int) $place);
1036 $resql = $db->query($sql);
1037 $row = $db->fetch_object($resql);
1038 $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>';
1039 $footerorder = '</tbody></table>'.dol_print_date(dol_now(), 'dayhour').'<br></html>';
1040 $order_receipt_printer1 = "";
1041 $order_receipt_printer2 = "";
1042 $order_receipt_printer3 = "";
1043 $catsprinter1 = explode(';', getDolGlobalString('TAKEPOS_PRINTED_CATEGORIES_1'));
1044 $catsprinter2 = explode(';', getDolGlobalString('TAKEPOS_PRINTED_CATEGORIES_2'));
1045 $catsprinter3 = explode(';', getDolGlobalString('TAKEPOS_PRINTED_CATEGORIES_3'));
1047 foreach ($invoice->lines as $line) {
1048 if ($line->special_code == "4
") {
1051 $c = new Categorie($db);
1052 $existing = $c->containing($line->fk_product, Categorie::TYPE_PRODUCT, 'id');
1053 $result = array_intersect($catsprinter1, $existing);
1054 $count = count($result);
1055 if (!$line->fk_product) {
1056 $count++; // Print Free-text item (Unassigned printer) to Printer 1
1060 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet set special_code=
'1' where
rowid=
".$line->id; //Set to print on printer 1
1062 $order_receipt_printer1 .= '<tr><td class="left
">';
1063 if ($line->fk_product) {
1064 $order_receipt_printer1 .= $line->product_label;
1066 $order_receipt_printer1 .= $line->description;
1068 $order_receipt_printer1 .= '</td><td class="right
">'.$line->qty;
1069 if (!empty($line->array_options['options_order_notes'])) {
1070 $order_receipt_printer1 .= "<br>(
".$line->array_options['options_order_notes'].")
";
1072 $order_receipt_printer1 .= '</td></tr>';
1075 if (((isModEnabled('receiptprinter') && getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term) > 0) || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter
" || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector
") && $linestoprint > 0) {
1076 $invoice->fetch($placeid); //Reload object before send to printer
1077 $printer->orderprinter = 1;
1079 echo "var orderprinter1esc=
'";
1080 $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
1083 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet
set special_code=
'4' where special_code=
'1' and fk_facture=
".$invoice->id; // Set as printed
1085 $invoice->fetch($placeid); //Reload object after set lines as printed
1088 foreach ($invoice->lines as $line) {
1089 if ($line->special_code == "4
") {
1092 $c = new Categorie($db);
1093 $existing = $c->containing($line->fk_product, Categorie::TYPE_PRODUCT, 'id');
1094 $result = array_intersect($catsprinter2, $existing);
1095 $count = count($result);
1098 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet
set special_code=
'2' where
rowid=
".$line->id; //Set to print on printer 2
1100 $order_receipt_printer2 .= '<tr>'.$line->product_label.'<td class="right
">'.$line->qty;
1101 if (!empty($line->array_options['options_order_notes'])) {
1102 $order_receipt_printer2 .= "<br>(
".$line->array_options['options_order_notes'].")
";
1104 $order_receipt_printer2 .= '</td></tr>';
1107 if (((isModEnabled('receiptprinter') && getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term) > 0) || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter
" || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector
") && $linestoprint > 0) {
1108 $invoice->fetch($placeid); //Reload object before send to printer
1109 $printer->orderprinter = 2;
1111 echo "var orderprinter2esc=
'";
1112 $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
1115 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet
set special_code=
'4' where special_code=
'2' and fk_facture=
".$invoice->id; // Set as printed
1117 $invoice->fetch($placeid); //Reload object after set lines as printed
1120 foreach ($invoice->lines as $line) {
1121 if ($line->special_code == "4
") {
1124 $c = new Categorie($db);
1125 $existing = $c->containing($line->fk_product, Categorie::TYPE_PRODUCT, 'id');
1126 $result = array_intersect($catsprinter3, $existing);
1127 $count = count($result);
1130 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet
set special_code=
'3' where
rowid=
".$line->id; //Set to print on printer 3
1132 $order_receipt_printer3 .= '<tr>'.$line->product_label.'<td class="right
">'.$line->qty;
1133 if (!empty($line->array_options['options_order_notes'])) {
1134 $order_receipt_printer3 .= "<br>(
".$line->array_options['options_order_notes'].")
";
1136 $order_receipt_printer3 .= '</td></tr>';
1139 if (((isModEnabled('receiptprinter') && getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term) > 0) || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter
" || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector
") && $linestoprint > 0) {
1140 $invoice->fetch($placeid); //Reload object before send to printer
1141 $printer->orderprinter = 3;
1143 echo "var orderprinter3esc=
'";
1144 $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
1147 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet
set special_code=
'4' where special_code=
'3' and fk_facture=
".$invoice->id; // Set as printed
1149 $invoice->fetch($placeid); //Reload object after set lines as printed
1152 $sectionwithinvoicelink = '';
1153 if (($action == "valid
" || $action == "history
" || $action == 'creditnote') && $user->hasRight('takepos', 'run')) {
1154 $sectionwithinvoicelink .= '<!-- Section with invoice link -->'."\n
";
1155 $sectionwithinvoicelink .= '<span style="font-size:120%;
" class="center
">';
1156 $sectionwithinvoicelink .= $invoice->getNomUrl(1, '', 0, 0, '', 0, 0, -1, '_backoffice')." -
";
1157 $remaintopay = $invoice->getRemainToPay();
1158 if ($remaintopay > 0) {
1159 $sectionwithinvoicelink .= $langs->trans('RemainToPay').': <span class="amountremaintopay
" style="font-size: unset
">'.price($remaintopay, 1, $langs, 1, -1, -1, $conf->currency).'</span>';
1161 if ($invoice->paye) {
1162 $sectionwithinvoicelink .= '<span class="amountpaymentcomplete
" style="font-size: unset
">'.$langs->trans("Paid
").'</span>';
1164 $sectionwithinvoicelink .= $langs->trans('BillShortStatusValidated');
1168 $sectionwithinvoicelink .= '</span><br>';
1169 if (getDolGlobalInt('TAKEPOS_PRINT_INVOICE_DOC_INSTEAD_OF_RECEIPT')) {
1170 $sectionwithinvoicelink .= ' <a target="_blank
" class="button" href="' . DOL_URL_ROOT . '/document.php?token=
' . newToken() . '&modulepart=facture&file=
' . $invoice->ref . '/
' . $invoice->ref . '.pdf
">Invoice</a>';
1171 } elseif (getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector
") {
1172 if (getDolGlobalString('TAKEPOS_PRINT_SERVER') && filter_var($conf->global->TAKEPOS_PRINT_SERVER, FILTER_VALIDATE_URL) == true) {
1173 $sectionwithinvoicelink .= ' <button id="buttonprint
" type="button" onclick="TakeposConnector(
'.$placeid.')
">'.$langs->trans('PrintTicket').'</button>';
1175 $sectionwithinvoicelink .= ' <button id="buttonprint
" type="button" onclick="TakeposPrinting(
'.$placeid.')
">'.$langs->trans('PrintTicket').'</button>';
1177 } elseif ((isModEnabled('receiptprinter') && getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term) > 0) || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter
") {
1178 $sectionwithinvoicelink .= ' <button id="buttonprint
" type="button" onclick="DolibarrTakeposPrinting(
'.$placeid.')
">'.$langs->trans('PrintTicket').'</button>';
1180 $sectionwithinvoicelink .= ' <button id="buttonprint
" type="button" onclick="Print(
'.$placeid.')
">'.$langs->trans('PrintTicket').'</button>';
1181 if (getDolGlobalString('TAKEPOS_PRINT_WITHOUT_DETAILS')) {
1182 $sectionwithinvoicelink .= ' <button id="buttonprint
" type="button" onclick="PrintBox(
'.$placeid.', \
'without_details\')">'.$langs->trans(
'PrintWithoutDetails').
'</button>';
1185 $sectionwithinvoicelink .=
' <button id="buttonprint" type="button" onclick="Print('.$placeid.
', 1)">'.$langs->trans(
'GiftReceipt').
'</button>';
1189 $sectionwithinvoicelink .=
' <button id="buttonsend" type="button" onclick="SendTicket('.$placeid.
')">'.$langs->trans(
'SendTicket').
'</button>';
1192 if ($remaintopay <= 0 &&
getDolGlobalString(
'TAKEPOS_AUTO_PRINT_TICKETS') && $action !=
"history") {
1193 $sectionwithinvoicelink .=
'<script type="text/javascript">$("#buttonprint").click();</script>';
1203$form =
new Form($db);
1206if ((
getDolGlobalString(
'TAKEPOS_PHONE_BASIC_LAYOUT') == 1 && $conf->browser->layout ==
'phone') || defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1207 $title =
'TakePOS - Dolibarr '.DOL_VERSION;
1211 $head =
'<meta name="apple-mobile-web-app-title" content="TakePOS"/>
1212 <meta name="apple-mobile-web-app-capable" content="yes">
1213 <meta name="mobile-web-app-capable" content="yes">
1214 <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>';
1215 $arrayofcss = array(
1216 '/takepos/css/pos.css.php',
1218 $arrayofjs = array(
'/takepos/js/jquery.colorbox-min.js');
1221 top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss);
1223 print
'<body>'.
"\n";
1230<script
type=
"text/javascript">
1233<?php
if ($action==
"valid") {
1234 echo
"var place=0;";
1236var placeid=<?php echo($placeid > 0 ? $placeid : 0); ?>;
1237$(document).ready(
function() {
1238 var idoflineadded = <?php echo(empty($idoflineadded) ? 0 : $idoflineadded); ?>;
1240 $(
'.posinvoiceline').click(
function(){
1241 console.log(
"Click done on "+this.
id);
1242 $(
'.posinvoiceline').removeClass(
"selected");
1243 $(
this).addClass(
"selected");
1247 if (selectedline == this.
id) {
1250 selectedline = this.id;
1252 selectedtext=$(
'#'+selectedline).find(
"td:first").html();
1254 if (defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1255 print
'$("#phonediv1").load("'.DOL_URL_ROOT.
'/takepos/public/auto_order.php?action=editline&token='.newToken().
'&placeid="+placeid+"&selectedline="+selectedline, function() {
1262 if (idoflineadded > 0)
1264 console.log(
"Auto select "+idoflineadded);
1265 $(
'.posinvoiceline#'+idoflineadded).click();
1269if ($action ==
"order" && !empty($order_receipt_printer1)) {
1270 if (filter_var($conf->global->TAKEPOS_PRINT_SERVER, FILTER_VALIDATE_URL) ==
true) {
1274 url:
'<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>/printer/index.php',
1275 data:
'invoice='+orderprinter1esc
1282 url:
'http://<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>:8111/print',
1284 print $headerorder.$order_receipt_printer1.$footerorder; ?>'
1290if ($action ==
"order" && !empty($order_receipt_printer2)) {
1291 if (filter_var($conf->global->TAKEPOS_PRINT_SERVER, FILTER_VALIDATE_URL) ==
true) {
1295 url:
'<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>/printer/index.php?printer=2',
1296 data:
'invoice='+orderprinter2esc
1303 url:
'http://<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>:8111/print2',
1305 print $headerorder.$order_receipt_printer2.$footerorder; ?>'
1311if ($action ==
"order" && !empty($order_receipt_printer3)) {
1312 if (filter_var($conf->global->TAKEPOS_PRINT_SERVER, FILTER_VALIDATE_URL) ==
true) {
1316 url:
'<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>/printer/index.php?printer=3',
1317 data:
'invoice='+orderprinter3esc
1324if ($action ==
"search" || $action ==
"valid") {
1326 parent.setFocusOnSearchField();
1331if ($action ==
"temp" && !empty($ticket_printer1)) {
1335 url:
'http://<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>:8111/print',
1337 print $header_soc.$header_ticket.$body_ticket.$ticket_printer1.$ticket_total.$footer_ticket; ?>'
1342if ($action ==
"search") {
1344 $(
'#search').focus();
1352function SendTicket(
id)
1354 console.log(
"Open box to select the Print/Send form");
1355 $.colorbox({href:
"send.php?facid="+id, width:
"70%", height:
"30%", transition:
"none", iframe:
"true", title:
'<?php echo dol_escape_js($langs->trans("SendTicket")); ?>'});
1359function PrintBox(
id, action) {
1360 console.log(
"Open box before printing");
1361 $.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
"); ?>"});
1365function Print(
id, gift){
1366 console.log(
"Call Print() to generate the receipt.");
1367 $.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")); ?>'});
1371function TakeposPrinting(
id){
1373 console.log(
"TakeposPrinting" +
id);
1374 $.get(
"receipt.php?facid="+
id,
function(data,
status) {
1375 receipt=data.replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g,
'');
1378 url:
'http://<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER
'); ?>:8111/print',
1385function TakeposConnector(
id){
1386 console.log(
"TakeposConnector" +
id);
1387 $.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) {
1390 url:
'<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER
'); ?>/printer/index.php',
1391 data:
'invoice='+data
1397function DolibarrTakeposPrinting(
id) {
1398 console.log(
"DolibarrTakeposPrinting Printing invoice ticket " +
id)
1401 data: { token:
'<?php echo currentToken(); ?>' },
1402 url:
"<?php print DOL_URL_ROOT.'/takepos/ajax/ajax.php?action=printinvoiceticket&token='.newToken().'&term='.urlencode(isset($_SESSION["takeposterminal
"]) ? $_SESSION["takeposterminal
"] : '').'&id='; ?>" + id,
1407function CreditNote() {
1408 $(
"#poslines").load(
"invoice.php?action=creditnote&token=<?php echo newToken() ?>&invoiceid="+placeid,
function() { });
1413 $(
"#poslines").load(
"invoice.php?action=addnote&token=<?php echo newToken() ?>&invoiceid="+placeid+
"&idline="+selectedline, {
"addnote": $(
"#textinput").val() });
1418$( document ).ready(
function() {
1419 console.log(
"Set customer info and sales in header placeid=<?php echo $placeid; ?> status=<?php echo $invoice->statut; ?>");
1422 $s = $langs->trans(
"Customer");
1423 if ($invoice->id > 0 && ($invoice->socid !=
getDolGlobalString($constforcompanyid))) {
1426 $contactids = $invoice->getIdContact(
'external',
'BILLING');
1427 $contactid = $contactids[0];
1428 if ($contactid > 0) {
1430 $contact->fetch($contactid);
1431 $s .=
" - " . $contact->getFullName($langs);
1437 $(
"#customerandsales").html(
'');
1438 $(
"#shoppingcart").html(
'');
1441 $(
"#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>');
1443 $(
"#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>');
1447 $sql =
"SELECT rowid, datec, ref FROM ".MAIN_DB_PREFIX.
"facture";
1448 $sql .=
" WHERE entity IN (".getEntity(
'invoice').
")";
1451 $sql .=
" AND ref LIKE '(PROV-POS".$db->escape(isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'').
"-0%'";
1454 $sql .=
" AND pos_source = '".$db->escape($_SESSION[
"takeposterminal"]).
"'";
1455 $sql .=
" AND module_source = 'takepos'";
1458 $sql .= $db->order(
'datec',
'ASC');
1459 $resql = $db->query($sql);
1462 while ($obj = $db->fetch_object($resql)) {
1463 echo
'$("#shoppingcart").append(\'';
1464 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=\\\'';
1465 $num_sale = str_replace(
")",
"", str_replace(
"(PROV-POS".$_SESSION[
"takeposterminal"].
"-",
"", $obj->ref));
1467 if (str_replace(
"-",
"", $num_sale) > $max_sale) {
1468 $max_sale = str_replace(
"-",
"", $num_sale);
1470 echo
'\\\'; invoiceid=\\\'';
1472 echo
'\\\'; Refresh();">';
1473 if ($placeid == $obj->rowid) {
1474 echo
'<span class="basketselected">';
1476 echo
'<span class="basketnotselected">';
1478 echo
'<span class="fa fa-shopping-cart paddingright"></span>'.dol_print_date($db->jdate($obj->datec),
'%H:%M',
'tzuser');
1482 echo
'$("#shoppingcart").append(\'<a onclick="place=\\\'0-';
1484 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>\');';
1492 $constantforkey =
'CASHDESK_NO_DECREASE_STOCK'. (isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
1493 if (isModEnabled(
'stock')) {
1495 $constantforkey =
'CASHDESK_ID_WAREHOUSE'. (isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
1497 if ($idwarehouse > 0) {
1498 $s =
'<span class="small">';
1500 $warehouse->fetch($idwarehouse);
1501 $s .=
'<span class="hideonsmartphone">'.$langs->trans(
"Warehouse").
'<br></span>'.$warehouse->ref;
1503 $s .=
' ('.$langs->trans(
"Closed").
')';
1506 print
"$('#infowarehouse').html('".dol_escape_js($s).
"');";
1507 print
'$("#infowarehouse").css("display", "inline-block");';
1509 $s =
'<span class="small hideonsmartphone">';
1510 $s .= $langs->trans(
"StockChangeDisabled").
'<br>'.$langs->trans(
"NoWarehouseDefinedForTerminal");
1512 print
"$('#infowarehouse').html('".dol_escape_js($s).
"');";
1513 if (!empty($conf->dol_optimize_smallscreen)) {
1514 print
'$("#infowarehouse").css("display", "none");';
1518 $s =
'<span class="small hideonsmartphone">'.$langs->trans(
"StockChangeDisabled").
'</span>';
1519 print
"$('#infowarehouse').html('".dol_escape_js($s).
"');";
1520 if (!empty($conf->dol_optimize_smallscreen)) {
1521 print
'$("#infowarehouse").css("display", "none");';
1529 if (isModEnabled(
'adherent') && $invoice->socid > 0 && $invoice->socid !=
getDolGlobalInt($constforcompanyid)) {
1530 $s =
'<span class="small">';
1531 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
1532 $langs->load(
"members");
1533 $s .= $langs->trans(
"Member").
': ';
1535 $result = $adh->fetch(
'',
'', $invoice->socid);
1537 $adh->ref = $adh->getFullName($langs);
1541 $s .= $adh->getFullName($langs);
1542 $s .=
' - '.$adh->type;
1543 if ($adh->datefin) {
1544 $s .=
'<br>'.$langs->trans(
"SubscriptionEndDate").
': '.
dol_print_date($adh->datefin,
'day');
1545 if ($adh->hasDelay()) {
1546 $s .=
" ".img_warning($langs->trans(
"Late"));
1549 $s .=
'<br>'.$langs->trans(
"SubscriptionNotReceived");
1550 if ($adh->statut > 0) {
1551 $s .=
" ".img_warning($langs->trans(
"Late"));
1558 $s .=
'<br>'.$langs->trans(
"ThirdpartyNotLinkedToMember");
1563 $(
"#moreinfo").html(
'<?php print dol_escape_js($s); ?>');
1570 echo
"function CustomerDisplay(){";
1571 echo
"var line1='".$CUSTOMER_DISPLAY_line1.
"'.substring(0,20);";
1572 echo
"line1=line1.padEnd(20);";
1573 echo
"var line2='".$CUSTOMER_DISPLAY_line2.
"'.substring(0,20);";
1574 echo
"line2=line2.padEnd(20);";
1577 data: { text: line1+line2 },
1578 url: '".getDolGlobalString(
'TAKEPOS_PRINT_SERVER').
"/display/index.php',
1589if (!empty($conf->use_javascript_ajax)) {
1590 print
"\n".
'<!-- Includes JS Footer of Dolibarr -->'.
"\n";
1591 print
'<script src="'.DOL_URL_ROOT.
'/core/js/lib_foot.js.php?lang='.$langs->defaultlang.
'"></script>'.
"\n";