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 $result = $payment->create($user);
303 $res = $payment->addPaymentToBank($user,
'payment',
'(CustomerInvoicePayment)', $bankaccount,
'',
'');
309 $remaintopay = $invoice->getRemainToPay();
315 if ($remaintopay == 0) {
316 dol_syslog(
"Invoice is paid, so we set it to status Paid");
317 $result = $invoice->setPaid($user);
322 $invoice->setPaymentMethods($paiementid);
324 dol_syslog(
"Invoice is not paid, remain to pay = ".$remaintopay);
331 if (!$error && $res >= 0) {
332 if (isModEnabled(
'stock') && isModEnabled(
'productbatch')) {
333 require_once DOL_DOCUMENT_ROOT .
"/product/stock/class/mouvementstock.class.php";
334 $constantforkey =
'CASHDESK_ID_WAREHOUSE'.$_SESSION[
"takeposterminal"];
336 $labeltakeposmovement =
'TakePOS - '.$langs->trans(
"Invoice").
' '.$invoice->ref;
338 foreach ($invoice->lines as $line) {
339 $warehouseid = ($line->fk_warehouse ? $line->fk_warehouse :
getDolGlobalInt($constantforkey));
342 if ($line->batch !=
'' && $warehouseid > 0) {
344 $prod_batch->find(0,
'',
'', $line->batch, $warehouseid);
346 $mouvP->origin = $invoice;
347 $res = $mouvP->livraison($user, $line->fk_product, $warehouseid, $line->qty, $line->price, $labeltakeposmovement,
'',
'',
'', $prod_batch->batch, $prod_batch->id, $inventorycode);
354 $mouvP->origin = $invoice;
355 $res = $mouvP->livraison($user, $line->fk_product, $warehouseid, $line->qty, $line->price, $labeltakeposmovement,
'',
'',
'',
'', 0, $inventorycode);
365 if (!$error && $res >= 0) {
371 if ($action ==
'creditnote' && $user->hasRight(
'facture',
'creer')) {
374 $creditnote =
new Facture($db);
375 $creditnote->socid = $invoice->socid;
377 $creditnote->module_source =
'takepos';
378 $creditnote->pos_source = isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'' ;
380 $creditnote->fk_facture_source = $placeid;
383 $creditnote->create($user);
385 foreach ($invoice->lines as $line) {
387 if (method_exists($line,
'fetch_optionals')) {
389 $line->fetch_optionals();
392 if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) {
397 if (!empty($invoice->situation_counter)) {
398 $source_fk_prev_id = $line->fk_prev_id;
399 $line->fk_prev_id = $line->id;
400 if (!empty($invoice->tab_previous_situation_invoice)) {
403 $tab_jumped_credit_notes = array();
404 $lineIndex = count($invoice->tab_previous_situation_invoice) - 1;
405 $searchPreviousInvoice =
true;
406 while ($searchPreviousInvoice) {
407 if ($invoice->tab_previous_situation_invoice[$lineIndex]->situation_cycle_ref || $lineIndex < 1) {
408 $searchPreviousInvoice =
false;
412 $tab_jumped_credit_notes[$lineIndex] = $invoice->tab_previous_situation_invoice[$lineIndex]->id;
418 $maxPrevSituationPercent = 0;
419 foreach ($invoice->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine) {
420 if ($prevLine->id == $source_fk_prev_id) {
421 $maxPrevSituationPercent = max($maxPrevSituationPercent, $prevLine->situation_percent);
424 $line->total_ht = $line->total_ht - $prevLine->total_ht;
425 $line->total_tva = $line->total_tva - $prevLine->total_tva;
426 $line->total_ttc = $line->total_ttc - $prevLine->total_ttc;
427 $line->total_localtax1 = $line->total_localtax1 - $prevLine->total_localtax1;
428 $line->total_localtax2 = $line->total_localtax2 - $prevLine->total_localtax2;
430 $line->multicurrency_subprice = $line->multicurrency_subprice - $prevLine->multicurrency_subprice;
431 $line->multicurrency_total_ht = $line->multicurrency_total_ht - $prevLine->multicurrency_total_ht;
432 $line->multicurrency_total_tva = $line->multicurrency_total_tva - $prevLine->multicurrency_total_tva;
433 $line->multicurrency_total_ttc = $line->multicurrency_total_ttc - $prevLine->multicurrency_total_ttc;
438 $line->situation_percent = $maxPrevSituationPercent - $line->situation_percent;
443 $maxPrevSituationPercent = 0;
444 foreach ($tab_jumped_credit_notes as $index => $creditnoteid) {
445 foreach ($invoice->tab_previous_situation_invoice[$index]->lines as $prevLine) {
446 if ($prevLine->fk_prev_id == $source_fk_prev_id) {
447 $maxPrevSituationPercent = $prevLine->situation_percent;
449 $line->total_ht -= $prevLine->total_ht;
450 $line->total_tva -= $prevLine->total_tva;
451 $line->total_ttc -= $prevLine->total_ttc;
452 $line->total_localtax1 -= $prevLine->total_localtax1;
453 $line->total_localtax2 -= $prevLine->total_localtax2;
455 $line->multicurrency_subprice -= $prevLine->multicurrency_subprice;
456 $line->multicurrency_total_ht -= $prevLine->multicurrency_total_ht;
457 $line->multicurrency_total_tva -= $prevLine->multicurrency_total_tva;
458 $line->multicurrency_total_ttc -= $prevLine->multicurrency_total_ttc;
464 $line->situation_percent += $maxPrevSituationPercent;
471 $line->fk_facture = $creditnote->id;
472 $line->fk_parent_line = $fk_parent_line;
474 $line->subprice = -$line->subprice;
475 $line->pa_ht = $line->pa_ht;
476 $line->total_ht = -$line->total_ht;
477 $line->total_tva = -$line->total_tva;
478 $line->total_ttc = -$line->total_ttc;
479 $line->total_localtax1 = -$line->total_localtax1;
480 $line->total_localtax2 = -$line->total_localtax2;
482 $line->multicurrency_subprice = -$line->multicurrency_subprice;
483 $line->multicurrency_total_ht = -$line->multicurrency_total_ht;
484 $line->multicurrency_total_tva = -$line->multicurrency_total_tva;
485 $line->multicurrency_total_ttc = -$line->multicurrency_total_ttc;
487 $result = $line->insert(0, 1);
489 $creditnote->lines[] = $line;
492 if ($result > 0 && $line->product_type == 9) {
493 $fk_parent_line = $result;
496 $creditnote->update_price(1);
498 $constantforkey =
'CASHDESK_NO_DECREASE_STOCK'.(isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
500 $savconst = $conf->global->STOCK_CALCULATE_ON_BILL;
501 $conf->global->STOCK_CALCULATE_ON_BILL = 1;
502 $constantforkey =
'CASHDESK_ID_WAREHOUSE'.(isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
503 dol_syslog(
"Validate invoice with stock change into warehouse defined into constant ".$constantforkey.
" = ".
getDolGlobalString($constantforkey));
505 if (isModEnabled(
'productbatch') &&
getDolGlobalString(
'CASHDESK_FORCE_DECREASE_STOCK')) {
506 require_once DOL_DOCUMENT_ROOT.
'/product/class/productbatch.class.php';
509 $res = $creditnote->validate($user,
'',
getDolGlobalString($constantforkey), 0, $batch_rule);
510 $conf->global->STOCK_CALCULATE_ON_BILL = $savconst;
512 $res = $creditnote->validate($user);
515 if (!$error && $res >= 0) {
522 if (($action ==
'history' || $action ==
'creditnote') && $user->hasRight(
'takepos',
'run')) {
523 if ($action ==
'creditnote') {
524 $placeid = $creditnote->id;
526 $placeid = (int)
GETPOST(
'placeid',
'int');
529 $invoice->fetch($placeid);
533 if (($action ==
"addline" || $action ==
"freezone") && $placeid == 0 && ($user->hasRight(
'takepos',
'run') || defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
536 include_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
539 $invoice->module_source =
'takepos';
540 $invoice->pos_source = isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'' ;
541 $invoice->entity = !empty($_SESSION[
"takeposinvoiceentity"]) ? $_SESSION[
"takeposinvoiceentity"] : $conf->entity;
543 if ($invoice->socid <= 0) {
544 $langs->load(
'errors');
550 $placeid = $invoice->create($user);
554 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facture set ref='(PROV-POS".$_SESSION[
"takeposterminal"].
"-".$place.
")' where rowid = ".((int) $placeid);
555 $resql = $db->query($sql);
569 if ($action ==
"addline" && ($user->hasRight(
'takepos',
'run') || defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
571 $prod->fetch($idproduct);
574 $customer->fetch($invoice->socid);
576 $datapriceofproduct = $prod->getSellPrice($mysoc, $customer, 0);
578 $qty = GETPOSTISSET(
'qty') ?
GETPOST(
'qty',
'int') : 1;
579 $price = $datapriceofproduct[
'pu_ht'];
580 $price_ttc = $datapriceofproduct[
'pu_ttc'];
582 $price_base_type = empty($datapriceofproduct[
'price_base_type']) ?
'HT' : $datapriceofproduct[
'price_base_type'];
583 $tva_tx = $datapriceofproduct[
'tva_tx'];
584 $tva_npr = $datapriceofproduct[
'tva_npr'];
587 $localtax1_tx =
get_localtax($tva_tx, 1, $customer, $mysoc, $tva_npr);
588 $localtax2_tx =
get_localtax($tva_tx, 2, $customer, $mysoc, $tva_npr);
591 if (isModEnabled(
'productbatch') && isModEnabled(
'stock')) {
592 $batch =
GETPOST(
'batch',
'alpha');
594 if (!empty($batch)) {
595 $action =
"setbatch";
596 } elseif ($prod->status_batch > 0) {
601 $prod->load_stock(
'warehouseopen');
603 $constantforkey =
'CASHDESK_ID_WAREHOUSE'.$_SESSION[
"takeposterminal"];
607 foreach ($prod->stock_warehouse as $tmpwarehouseid => $tmpval) {
612 if (!empty($prod->stock_warehouse[$tmpwarehouseid]) && is_array($prod->stock_warehouse[$tmpwarehouseid]->detail_batch)) {
613 if (is_object($prod->stock_warehouse[$tmpwarehouseid]) && count($prod->stock_warehouse[$tmpwarehouseid]->detail_batch)) {
614 foreach ($prod->stock_warehouse[$tmpwarehouseid]->detail_batch as $dbatch) {
623 echo
"function addbatch(batch, warehouseid) {\n";
624 echo
"console.log('We add batch '+batch+' from warehouse id '+warehouseid);\n";
625 echo
'$("#poslines").load("invoice.php?action=addline&batch="+batch+"&warehouseid="+warehouseid+"&place='.$place.
'&idproduct='.$idproduct.
'&token='.newToken().
'", function() {});'.
"\n";
630 echo
"<center>".$langs->trans(
"SearchIntoBatch").
": <b> $nbofsuggested </b></center><br><table>";
631 foreach ($prod->stock_warehouse as $tmpwarehouseid => $tmpval) {
636 if (!empty($prod->stock_warehouse[$tmpwarehouseid]) && is_array($prod->stock_warehouse[$tmpwarehouseid]->detail_batch)) {
637 foreach ($prod->stock_warehouse[$tmpwarehouseid]->detail_batch as $dbatch) {
638 $batchStock = + $dbatch->qty;
639 $quantityToBeDelivered = 1;
640 $deliverableQty = min($quantityToBeDelivered, $batchStock);
642 print
'<!-- subj='.$suggestednb.
'/'.$nbofsuggested.
' -->';
643 print
'<!-- Show details of lot -->';
644 print
'<td class="left">';
646 $detail .=
'<span class="opacitymedium">'.$langs->trans(
"LotSerial").
':</span> '.$dbatch->batch;
653 $detail .=
'</td><td>';
654 $detail .=
'<span class="opacitymedium">'.$langs->trans(
"Qty").
':</span> '.$dbatch->qty;
655 $detail .=
'</td><td>';
656 $detail .=
' <button class="marginleftonly" onclick="addbatch(\''.dol_escape_js($dbatch->batch).
'\',
'.$tmpwarehouseid.')
">'.$langs->trans("Select
")."</
button>
";
660 $quantityToBeDelivered -= $deliverableQty;
661 if ($quantityToBeDelivered < 0) {
662 $quantityToBeDelivered = 0;
671 print '</body></html>';
677 if (getDolGlobalString('TAKEPOS_SUPPLEMENTS')) {
678 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
679 $cat = new Categorie($db);
680 $categories = $cat->containing($idproduct, 'product');
681 $found = (array_search(getDolGlobalInt('TAKEPOS_SUPPLEMENTS_CATEGORY'), array_column($categories, 'id')));
682 if ($found !== false) { // If this product is a supplement
683 $sql = "SELECT fk_parent_line FROM
".MAIN_DB_PREFIX."facturedet where
rowid =
".((int) $selectedline);
684 $resql = $db->query($sql);
685 $row = $db->fetch_array($resql);
686 if ($row[0] == null) {
687 $parent_line = $selectedline;
689 $parent_line = $row[0]; //If the parent line is already a supplement, add the supplement to the main product
696 // Group if enabled. Skip group if line already sent to the printer
697 if (getDolGlobalString('TAKEPOS_GROUP_SAME_PRODUCT')) {
698 foreach ($invoice->lines as $line) {
699 if ($line->product_ref == $prod->ref) {
700 if ($line->special_code==4) {
702 } // If this line is sended to printer create new line
703 // check if qty in stock
704 if (getDolGlobalString('TAKEPOS_QTY_IN_STOCK') && (($line->qty + $qty) > $prod->stock_reel)) {
705 $invoice->error = $langs->trans('NotEnoughInStock');
706 dol_htmloutput_errors($invoice->error, $invoice->errors, 1);
710 $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);
712 dol_htmloutput_errors($invoice->error, $invoice->errors, 1);
714 $idoflineadded = $line->id;
720 if ($idoflineadded <= 0 && empty($err)) {
721 $invoice->fetch_thirdparty();
722 $array_options = array();
724 $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);
726 /* setup of margin calculation */
727 if (isset($conf->global->MARGIN_TYPE)) {
728 if (getDolGlobalString('MARGIN_TYPE') == 'pmp' && !empty($prod->pmp)) {
729 $line['fk_fournprice'] = null;
730 $line['pa_ht'] = $prod->pmp;
731 } elseif (getDolGlobalString('MARGIN_TYPE') == 'costprice' && !empty($prod->cost_price)) {
732 $line['fk_fournprice'] = null;
733 $line['pa_ht'] = $prod->cost_price;
735 // default is fournprice
736 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
737 $pf = new ProductFournisseur($db);
738 if ($pf->find_min_price_product_fournisseur($idproduct, $qty) > 0) {
739 $line['fk_fournprice'] = $pf->product_fourn_price_id;
740 $line['pa_ht'] = $pf->fourn_unitprice_with_discount;
741 if (getDolGlobalString('PRODUCT_CHARGES') && $pf->fourn_charges > 0) {
742 $line['pa_ht'] += $pf->fourn_charges / $pf->fourn_qty;
748 // complete line by hook
749 $parameters = array('prod' => $prod, 'line' => $line);
750 $reshook=$hookmanager->executeHooks('completeTakePosAddLine', $parameters, $invoice, $action); // Note that $action and $line may have been modified by some hooks
752 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
756 if (empty($reshook)) {
757 if (!empty($hookmanager->resArray)) {
758 $line = $hookmanager->resArray;
761 // check if qty in stock
762 if (getDolGlobalString('TAKEPOS_QTY_IN_STOCK') && $qty > $prod->stock_reel) {
763 $invoice->error = $langs->trans('NotEnoughInStock');
764 dol_htmloutput_errors($invoice->error, $invoice->errors, 1);
769 $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);
773 if (getDolGlobalString('TAKEPOS_CUSTOMER_DISPLAY')) {
774 $CUSTOMER_DISPLAY_line1 = $prod->label;
775 $CUSTOMER_DISPLAY_line2 = price($price_ttc);
779 $invoice->fetch($placeid);
782 // If we add a line by submitting freezone form (invoice exists here because it was created juste before if it didn't exists)
783 if ($action == "freezone
" && $user->hasRight('takepos', 'run')) {
784 $customer = new Societe($db);
785 $customer->fetch($invoice->socid);
787 $tva_tx = GETPOST('tva_tx', 'alpha');
789 if (!preg_match('/\((.*)\)/', $tva_tx)) {
790 $tva_tx = price2num($tva_tx);
793 $tva_tx = get_default_tva($mysoc, $customer);
797 $localtax1_tx = get_localtax($tva_tx, 1, $customer, $mysoc, $tva_npr);
798 $localtax2_tx = get_localtax($tva_tx, 2, $customer, $mysoc, $tva_npr);
800 $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);
802 dol_htmloutput_errors($invoice->error, $invoice->errors, 1);
804 $invoice->fetch($placeid);
807 if ($action == "addnote
" && ($user->hasRight('takepos', 'run') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
808 $desc = GETPOST('addnote', 'alpha');
810 $invoice->update_note($desc, '_public');
812 foreach ($invoice->lines as $line) {
813 if ($line->id == $idline) {
814 $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);
818 $invoice->fetch($placeid);
821 if ($action == "deleteline
" && ($user->hasRight('takepos', 'run') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
823 $permissiontoupdateline = ($user->hasRight('takepos', 'editlines') && ($user->hasRight('takepos', 'editorderedlines') || $line->special_code != "4
"));
824 if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
825 if ($invoice->status == $invoice::STATUS_DRAFT && $invoice->pos_source && $invoice->module_source == 'takepos') {
826 $permissiontoupdateline = true;
827 // TODO Add also a test on $_SESSION('publicobjectid'] defined at creation of object
828 // TODO Check also that invoice->ref is (PROV-POS1-2) with 1 = terminal and 2, the invoice ID
832 if ($idline > 0 && $placeid > 0) { // If invoice exists and line selected. To avoid errors if deleted from another device or no line selected.
833 $invoice->deleteline($idline);
834 $invoice->fetch($placeid);
835 } elseif ($placeid > 0) { // If invoice exists but no line selected, proceed to delete last line.
836 $sql = "SELECT
rowid FROM
".MAIN_DB_PREFIX."facturedet where fk_facture =
".((int) $placeid)." ORDER BY
rowid DESC
";
837 $resql = $db->query($sql);
838 $row = $db->fetch_array($resql);
839 $deletelineid = $row[0];
840 $invoice->deleteline($deletelineid);
841 $invoice->fetch($placeid);
844 if (count($invoice->lines) == 0) {
845 $invoice->delete($user);
847 if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
848 header("Location:
".DOL_URL_ROOT."/takepos/public/auto_order.php
");
850 header("Location:
".DOL_URL_ROOT."/takepos/invoice.php
");
856 // Action to delete or discard an invoice
857 if ($action == "delete
" && ($user->hasRight('takepos', 'run') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
858 // $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.
860 $result = $invoice->fetch($placeid);
862 if ($result > 0 && $invoice->statut == Facture::STATUS_DRAFT) {
865 // We delete the lines
867 foreach ($invoice->lines as $line) {
868 $tmpres = $invoice->deleteline($line->id);
875 $sql = "UPDATE
".MAIN_DB_PREFIX."facture
";
876 $varforconst = 'CASHDESK_ID_THIRDPARTY'.$_SESSION["takeposterminal
"];
877 $sql .= " SET fk_soc =
".((int) getDolGlobalString($varforconst)).",
";
878 $sql .= " datec =
'".$db->idate(dol_now())."'";
879 $sql .= " WHERE entity IN (
".getEntity('invoice').")
";
880 $sql .= " AND
ref =
'(PROV-POS".$db->escape($_SESSION["takeposterminal"]."-".$place).")'";
881 $resql1 = $db->query($sql);
883 if ($resdeletelines && $resql1) {
889 $invoice->fetch($placeid);
894 if ($action == "updateqty
") { // Test on permission is done later
895 foreach ($invoice->lines as $line) {
896 if ($line->id == $idline) {
897 $permissiontoupdateline = ($user->hasRight('takepos', 'editlines') && ($user->hasRight('takepos', 'editorderedlines') || $line->special_code != "4
"));
898 if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
899 if ($invoice->status == $invoice::STATUS_DRAFT && $invoice->pos_source && $invoice->module_source == 'takepos') {
900 $permissiontoupdateline = true;
901 // TODO Add also a test on $_SESSION('publicobjectid'] defined at creation of object
902 // TODO Check also that invoice->ref is (PROV-POS1-2) with 1 = terminal and 2, the invoice ID
905 if (!$permissiontoupdateline) {
906 dol_htmloutput_errors($langs->trans("NotEnoughPermissions
", "TakePos
").' - No permission to updateqty', null, 1);
908 $vatratecode = $line->tva_tx;
909 if ($line->vat_src_code) {
910 $vatratecode .= ' ('.$line->vat_src_code.')';
913 $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);
918 $invoice->fetch($placeid);
921 if ($action == "updateprice
") { // Test on permission is done later
922 $customer = new Societe($db);
923 $customer->fetch($invoice->socid);
925 foreach ($invoice->lines as $line) {
926 if ($line->id == $idline) {
927 $prod = new Product($db);
928 $prod->fetch($line->fk_product);
929 $datapriceofproduct = $prod->getSellPrice($mysoc, $customer, 0);
930 $price_min = $datapriceofproduct['price_min'];
931 $usercanproductignorepricemin = ((getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && empty($user->rights->produit->ignore_price_min_advance)) || !getDolGlobalString('MAIN_USE_ADVANCED_PERMS'));
932 $pu_ht = price2num($number / (1 + ($line->tva_tx / 100)), 'MU');
934 if ($usercanproductignorepricemin && (!empty($price_min) && (price2num($pu_ht) * (1 - price2num($line->remise_percent) / 100) < price2num($price_min)))) {
935 $langs->load("products
");
936 dol_htmloutput_errors($langs->trans("CantBeLessThanMinPrice
", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, -1, $conf->currency)));
937 //echo $langs->trans("CantBeLessThanMinPrice
");
939 $permissiontoupdateline = ($user->hasRight('takepos', 'editlines') && ($user->hasRight('takepos', 'editorderedlines') || $line->special_code != "4
"));
940 if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
941 if ($invoice->status == $invoice::STATUS_DRAFT && $invoice->pos_source && $invoice->module_source == 'takepos') {
942 $permissiontoupdateline = true;
943 // TODO Add also a test on $_SESSION('publicobjectid'] defined at creation of object
944 // TODO Check also that invoice->ref is (PROV-POS1-2) with 1 = terminal and 2, the invoice ID
948 $vatratecode = $line->tva_tx;
949 if ($line->vat_src_code) {
950 $vatratecode .= ' ('.$line->vat_src_code.')';
953 if (!$permissiontoupdateline) {
954 dol_htmloutput_errors($langs->trans("NotEnoughPermissions
", "TakePos
").' - No permission to updateprice', null, 1);
955 } elseif (getDolGlobalInt('TAKEPOS_CHANGE_PRICE_HT') == 1) {
956 $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);
958 $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);
965 $invoice->fetch($placeid);
968 if ($action == "updatereduction
") { // Test on permission is done later
969 $customer = new Societe($db);
970 $customer->fetch($invoice->socid);
972 foreach ($invoice->lines as $line) {
973 if ($line->id == $idline) {
974 dol_syslog("updatereduction Process line
".$line->id.' to apply discount of '.$number.'%');
976 $prod = new Product($db);
977 $prod->fetch($line->fk_product);
979 $datapriceofproduct = $prod->getSellPrice($mysoc, $customer, 0);
980 $price_min = $datapriceofproduct['price_min'];
981 $usercanproductignorepricemin = ((getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && empty($user->rights->produit->ignore_price_min_advance)) || !getDolGlobalString('MAIN_USE_ADVANCED_PERMS'));
983 $pu_ht = price2num($line->subprice / (1 + ($line->tva_tx / 100)), 'MU');
986 if ($usercanproductignorepricemin && (!empty($price_min) && (price2num($line->subprice) * (1 - price2num($number) / 100) < price2num($price_min)))) {
987 $langs->load("products
");
988 dol_htmloutput_errors($langs->trans("CantBeLessThanMinPrice
", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, -1, $conf->currency)));
990 $permissiontoupdateline = ($user->hasRight('takepos', 'editlines') && ($user->hasRight('takepos', 'editorderedlines') || $line->special_code != "4
"));
991 if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
992 if ($invoice->status == $invoice::STATUS_DRAFT && $invoice->pos_source && $invoice->module_source == 'takepos') {
993 $permissiontoupdateline = true;
994 // TODO Add also a test on $_SESSION('publicobjectid'] defined at creation of object
995 // TODO Check also that invoice->ref is (PROV-POS1-2) with 1 = terminal and 2, the invoice ID
998 if (!$permissiontoupdateline) {
999 dol_htmloutput_errors($langs->trans("NotEnoughPermissions
", "TakePos
"), null, 1);
1001 $vatratecode = $line->tva_tx;
1002 if ($line->vat_src_code) {
1003 $vatratecode .= ' ('.$line->vat_src_code.')';
1005 $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);
1012 $invoice->fetch($placeid);
1013 } elseif ($action == 'update_reduction_global' && $user->hasRight('takepos', 'editlines')) {
1014 foreach ($invoice->lines as $line) {
1015 $vatratecode = $line->tva_tx;
1016 if ($line->vat_src_code) {
1017 $vatratecode .= ' ('.$line->vat_src_code.')';
1019 $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);
1022 $invoice->fetch($placeid);
1025 if ($action=="setbatch
" && ($user->hasRight('takepos', 'run') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
1026 $constantforkey = 'CASHDESK_ID_WAREHOUSE'.$_SESSION["takeposterminal
"];
1027 $warehouseid = getDolGlobalInt($constantforkey); // TODO Get the wrehouse id from GETPOSTINT('warehouseid');
1028 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet SET batch =
'".$db->escape($batch)."', fk_warehouse =
".((int) $warehouseid);
1029 $sql .= " WHERE
rowid=
".((int) $idoflineadded);
1033 if ($action == "order
" && $placeid != 0 && ($user->hasRight('takepos', 'run') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
1034 include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
1035 if ((isModEnabled('receiptprinter') && getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term) > 0) || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter
" || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector
") {
1036 require_once DOL_DOCUMENT_ROOT.'/core/class/dolreceiptprinter.class.php';
1037 $printer = new dolReceiptPrinter($db);
1040 $sql = "SELECT label FROM
".MAIN_DB_PREFIX."takepos_floor_tables where
rowid=
".((int) $place);
1041 $resql = $db->query($sql);
1042 $row = $db->fetch_object($resql);
1043 $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>';
1044 $footerorder = '</tbody></table>'.dol_print_date(dol_now(), 'dayhour').'<br></html>';
1045 $order_receipt_printer1 = "";
1046 $order_receipt_printer2 = "";
1047 $order_receipt_printer3 = "";
1048 $catsprinter1 = explode(';', getDolGlobalString('TAKEPOS_PRINTED_CATEGORIES_1'));
1049 $catsprinter2 = explode(';', getDolGlobalString('TAKEPOS_PRINTED_CATEGORIES_2'));
1050 $catsprinter3 = explode(';', getDolGlobalString('TAKEPOS_PRINTED_CATEGORIES_3'));
1052 foreach ($invoice->lines as $line) {
1053 if ($line->special_code == "4
") {
1056 $c = new Categorie($db);
1057 $existing = $c->containing($line->fk_product, Categorie::TYPE_PRODUCT, 'id');
1058 $result = array_intersect($catsprinter1, $existing);
1059 $count = count($result);
1060 if (!$line->fk_product) {
1061 $count++; // Print Free-text item (Unassigned printer) to Printer 1
1065 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet set special_code=
'1' where
rowid=
".$line->id; //Set to print on printer 1
1067 $order_receipt_printer1 .= '<tr><td class="left
">';
1068 if ($line->fk_product) {
1069 $order_receipt_printer1 .= $line->product_label;
1071 $order_receipt_printer1 .= $line->description;
1073 $order_receipt_printer1 .= '</td><td class="right
">'.$line->qty;
1074 if (!empty($line->array_options['options_order_notes'])) {
1075 $order_receipt_printer1 .= "<br>(
".$line->array_options['options_order_notes'].")
";
1077 $order_receipt_printer1 .= '</td></tr>';
1080 if (((isModEnabled('receiptprinter') && getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term) > 0) || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter
" || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector
") && $linestoprint > 0) {
1081 $invoice->fetch($placeid); //Reload object before send to printer
1082 $printer->orderprinter = 1;
1084 echo "var orderprinter1esc=
'";
1085 $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
1088 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet
set special_code=
'4' where special_code=
'1' and fk_facture=
".$invoice->id; // Set as printed
1090 $invoice->fetch($placeid); //Reload object after set lines as printed
1093 foreach ($invoice->lines as $line) {
1094 if ($line->special_code == "4
") {
1097 $c = new Categorie($db);
1098 $existing = $c->containing($line->fk_product, Categorie::TYPE_PRODUCT, 'id');
1099 $result = array_intersect($catsprinter2, $existing);
1100 $count = count($result);
1103 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet
set special_code=
'2' where
rowid=
".$line->id; //Set to print on printer 2
1105 $order_receipt_printer2 .= '<tr>'.$line->product_label.'<td class="right
">'.$line->qty;
1106 if (!empty($line->array_options['options_order_notes'])) {
1107 $order_receipt_printer2 .= "<br>(
".$line->array_options['options_order_notes'].")
";
1109 $order_receipt_printer2 .= '</td></tr>';
1112 if (((isModEnabled('receiptprinter') && getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term) > 0) || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter
" || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector
") && $linestoprint > 0) {
1113 $invoice->fetch($placeid); //Reload object before send to printer
1114 $printer->orderprinter = 2;
1116 echo "var orderprinter2esc=
'";
1117 $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
1120 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet
set special_code=
'4' where special_code=
'2' and fk_facture=
".$invoice->id; // Set as printed
1122 $invoice->fetch($placeid); //Reload object after set lines as printed
1125 foreach ($invoice->lines as $line) {
1126 if ($line->special_code == "4
") {
1129 $c = new Categorie($db);
1130 $existing = $c->containing($line->fk_product, Categorie::TYPE_PRODUCT, 'id');
1131 $result = array_intersect($catsprinter3, $existing);
1132 $count = count($result);
1135 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet
set special_code=
'3' where
rowid=
".$line->id; //Set to print on printer 3
1137 $order_receipt_printer3 .= '<tr>'.$line->product_label.'<td class="right
">'.$line->qty;
1138 if (!empty($line->array_options['options_order_notes'])) {
1139 $order_receipt_printer3 .= "<br>(
".$line->array_options['options_order_notes'].")
";
1141 $order_receipt_printer3 .= '</td></tr>';
1144 if (((isModEnabled('receiptprinter') && getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term) > 0) || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter
" || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector
") && $linestoprint > 0) {
1145 $invoice->fetch($placeid); //Reload object before send to printer
1146 $printer->orderprinter = 3;
1148 echo "var orderprinter3esc=
'";
1149 $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
1152 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet
set special_code=
'4' where special_code=
'3' and fk_facture=
".$invoice->id; // Set as printed
1154 $invoice->fetch($placeid); //Reload object after set lines as printed
1157 $sectionwithinvoicelink = '';
1158 if (($action == "valid
" || $action == "history
" || $action == 'creditnote') && $user->hasRight('takepos', 'run')) {
1159 $sectionwithinvoicelink .= '<!-- Section with invoice link -->'."\n
";
1160 $sectionwithinvoicelink .= '<span style="font-size:120%;
" class="center
">';
1161 $sectionwithinvoicelink .= $invoice->getNomUrl(1, '', 0, 0, '', 0, 0, -1, '_backoffice')." -
";
1162 $remaintopay = $invoice->getRemainToPay();
1163 if ($remaintopay > 0) {
1164 $sectionwithinvoicelink .= $langs->trans('RemainToPay').': <span class="amountremaintopay
" style="font-size: unset
">'.price($remaintopay, 1, $langs, 1, -1, -1, $conf->currency).'</span>';
1166 if ($invoice->paye) {
1167 $sectionwithinvoicelink .= '<span class="amountpaymentcomplete
" style="font-size: unset
">'.$langs->trans("Paid
").'</span>';
1169 $sectionwithinvoicelink .= $langs->trans('BillShortStatusValidated');
1173 $sectionwithinvoicelink .= '</span><br>';
1174 if (getDolGlobalInt('TAKEPOS_PRINT_INVOICE_DOC_INSTEAD_OF_RECEIPT')) {
1175 $sectionwithinvoicelink .= ' <a target="_blank
" class="button" href="' . DOL_URL_ROOT . '/document.php?token=
' . newToken() . '&modulepart=facture&file=
' . $invoice->ref . '/
' . $invoice->ref . '.pdf
">Invoice</a>';
1176 } elseif (getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector
") {
1177 if (getDolGlobalString('TAKEPOS_PRINT_SERVER') && filter_var($conf->global->TAKEPOS_PRINT_SERVER, FILTER_VALIDATE_URL) == true) {
1178 $sectionwithinvoicelink .= ' <button id="buttonprint
" type="button" onclick="TakeposConnector(
'.$placeid.')
">'.$langs->trans('PrintTicket').'</button>';
1180 $sectionwithinvoicelink .= ' <button id="buttonprint
" type="button" onclick="TakeposPrinting(
'.$placeid.')
">'.$langs->trans('PrintTicket').'</button>';
1182 } elseif ((isModEnabled('receiptprinter') && getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term) > 0) || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter
") {
1183 $sectionwithinvoicelink .= ' <button id="buttonprint
" type="button" onclick="DolibarrTakeposPrinting(
'.$placeid.')
">'.$langs->trans('PrintTicket').'</button>';
1185 $sectionwithinvoicelink .= ' <button id="buttonprint
" type="button" onclick="Print(
'.$placeid.')
">'.$langs->trans('PrintTicket').'</button>';
1186 if (getDolGlobalString('TAKEPOS_PRINT_WITHOUT_DETAILS')) {
1187 $sectionwithinvoicelink .= ' <button id="buttonprint
" type="button" onclick="PrintBox(
'.$placeid.', \
'without_details\')">'.$langs->trans(
'PrintWithoutDetails').
'</button>';
1190 $sectionwithinvoicelink .=
' <button id="buttonprint" type="button" onclick="Print('.$placeid.
', 1)">'.$langs->trans(
'GiftReceipt').
'</button>';
1194 $sectionwithinvoicelink .=
' <button id="buttonsend" type="button" onclick="SendTicket('.$placeid.
')">'.$langs->trans(
'SendTicket').
'</button>';
1197 if ($remaintopay <= 0 &&
getDolGlobalString(
'TAKEPOS_AUTO_PRINT_TICKETS') && $action !=
"history") {
1198 $sectionwithinvoicelink .=
'<script type="text/javascript">$("#buttonprint").click();</script>';
1208$form =
new Form($db);
1211if ((
getDolGlobalString(
'TAKEPOS_PHONE_BASIC_LAYOUT') == 1 && $conf->browser->layout ==
'phone') || defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1212 $title =
'TakePOS - Dolibarr '.DOL_VERSION;
1216 $head =
'<meta name="apple-mobile-web-app-title" content="TakePOS"/>
1217 <meta name="apple-mobile-web-app-capable" content="yes">
1218 <meta name="mobile-web-app-capable" content="yes">
1219 <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>';
1220 $arrayofcss = array(
1221 '/takepos/css/pos.css.php',
1223 $arrayofjs = array(
'/takepos/js/jquery.colorbox-min.js');
1226 top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss);
1228 print
'<body>'.
"\n";
1235<script
type=
"text/javascript">
1238<?php
if ($action==
"valid") {
1239 echo
"var place=0;";
1241var placeid=<?php echo($placeid > 0 ? $placeid : 0); ?>;
1242$(document).ready(
function() {
1243 var idoflineadded = <?php echo(empty($idoflineadded) ? 0 : $idoflineadded); ?>;
1245 $(
'.posinvoiceline').click(
function(){
1246 console.log(
"Click done on "+this.
id);
1247 $(
'.posinvoiceline').removeClass(
"selected");
1248 $(
this).addClass(
"selected");
1252 if (selectedline == this.
id) {
1255 selectedline = this.id;
1257 selectedtext=$(
'#'+selectedline).find(
"td:first").html();
1259 if (defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1260 print
'$("#phonediv1").load("'.DOL_URL_ROOT.
'/takepos/public/auto_order.php?action=editline&token='.newToken().
'&placeid="+placeid+"&selectedline="+selectedline, function() {
1267 if (idoflineadded > 0)
1269 console.log(
"Auto select "+idoflineadded);
1270 $(
'.posinvoiceline#'+idoflineadded).click();
1274if ($action ==
"order" && !empty($order_receipt_printer1)) {
1275 if (filter_var($conf->global->TAKEPOS_PRINT_SERVER, FILTER_VALIDATE_URL) ==
true) {
1279 url:
'<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>/printer/index.php',
1280 data:
'invoice='+orderprinter1esc
1287 url:
'http://<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>:8111/print',
1289 print $headerorder.$order_receipt_printer1.$footerorder; ?>'
1295if ($action ==
"order" && !empty($order_receipt_printer2)) {
1296 if (filter_var($conf->global->TAKEPOS_PRINT_SERVER, FILTER_VALIDATE_URL) ==
true) {
1300 url:
'<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>/printer/index.php?printer=2',
1301 data:
'invoice='+orderprinter2esc
1308 url:
'http://<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>:8111/print2',
1310 print $headerorder.$order_receipt_printer2.$footerorder; ?>'
1316if ($action ==
"order" && !empty($order_receipt_printer3)) {
1317 if (filter_var($conf->global->TAKEPOS_PRINT_SERVER, FILTER_VALIDATE_URL) ==
true) {
1321 url:
'<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>/printer/index.php?printer=3',
1322 data:
'invoice='+orderprinter3esc
1329if ($action ==
"search" || $action ==
"valid") {
1331 parent.setFocusOnSearchField();
1336if ($action ==
"temp" && !empty($ticket_printer1)) {
1340 url:
'http://<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>:8111/print',
1342 print $header_soc.$header_ticket.$body_ticket.$ticket_printer1.$ticket_total.$footer_ticket; ?>'
1347if ($action ==
"search") {
1349 $(
'#search').focus();
1357function SendTicket(
id)
1359 console.log(
"Open box to select the Print/Send form");
1360 $.colorbox({href:
"send.php?facid="+id, width:
"70%", height:
"30%", transition:
"none", iframe:
"true", title:
'<?php echo dol_escape_js($langs->trans("SendTicket")); ?>'});
1364function PrintBox(
id, action) {
1365 console.log(
"Open box before printing");
1366 $.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
"); ?>"});
1370function Print(
id, gift){
1371 console.log(
"Call Print() to generate the receipt.");
1372 $.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")); ?>'});
1376function TakeposPrinting(
id){
1378 console.log(
"TakeposPrinting" +
id);
1379 $.get(
"receipt.php?facid="+
id,
function(data,
status) {
1380 receipt=data.replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g,
'');
1383 url:
'http://<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER
'); ?>:8111/print',
1390function TakeposConnector(
id){
1391 console.log(
"TakeposConnector" +
id);
1392 $.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) {
1395 url:
'<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER
'); ?>/printer/index.php',
1396 data:
'invoice='+data
1402function DolibarrTakeposPrinting(
id) {
1403 console.log(
"DolibarrTakeposPrinting Printing invoice ticket " +
id)
1406 data: { token:
'<?php echo currentToken(); ?>' },
1407 url:
"<?php print DOL_URL_ROOT.'/takepos/ajax/ajax.php?action=printinvoiceticket&token='.newToken().'&term='.urlencode(isset($_SESSION["takeposterminal
"]) ? $_SESSION["takeposterminal
"] : '').'&id='; ?>" + id,
1412function CreditNote() {
1413 $(
"#poslines").load(
"invoice.php?action=creditnote&token=<?php echo newToken() ?>&invoiceid="+placeid,
function() { });
1418 $(
"#poslines").load(
"invoice.php?action=addnote&token=<?php echo newToken() ?>&invoiceid="+placeid+
"&idline="+selectedline, {
"addnote": $(
"#textinput").val() });
1423$( document ).ready(
function() {
1424 console.log(
"Set customer info and sales in header placeid=<?php echo $placeid; ?> status=<?php echo $invoice->statut; ?>");
1427 $s = $langs->trans(
"Customer");
1428 if ($invoice->id > 0 && ($invoice->socid !=
getDolGlobalString($constforcompanyid))) {
1431 $contactids = $invoice->getIdContact(
'external',
'BILLING');
1432 $contactid = $contactids[0];
1433 if ($contactid > 0) {
1435 $contact->fetch($contactid);
1436 $s .=
" - " . $contact->getFullName($langs);
1442 $(
"#customerandsales").html(
'');
1443 $(
"#shoppingcart").html(
'');
1446 $(
"#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>');
1448 $(
"#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>');
1452 $sql =
"SELECT rowid, datec, ref FROM ".MAIN_DB_PREFIX.
"facture";
1453 $sql .=
" WHERE entity IN (".getEntity(
'invoice').
")";
1456 $sql .=
" AND ref LIKE '(PROV-POS".$db->escape(isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'').
"-0%'";
1459 $sql .=
" AND pos_source = '".$db->escape($_SESSION[
"takeposterminal"]).
"'";
1460 $sql .=
" AND module_source = 'takepos'";
1463 $sql .= $db->order(
'datec',
'ASC');
1464 $resql = $db->query($sql);
1467 while ($obj = $db->fetch_object($resql)) {
1468 echo
'$("#shoppingcart").append(\'';
1469 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=\\\'';
1470 $num_sale = str_replace(
")",
"", str_replace(
"(PROV-POS".$_SESSION[
"takeposterminal"].
"-",
"", $obj->ref));
1472 if (str_replace(
"-",
"", $num_sale) > $max_sale) {
1473 $max_sale = str_replace(
"-",
"", $num_sale);
1475 echo
'\\\'; invoiceid=\\\'';
1477 echo
'\\\'; Refresh();">';
1478 if ($placeid == $obj->rowid) {
1479 echo
'<span class="basketselected">';
1481 echo
'<span class="basketnotselected">';
1483 echo
'<span class="fa fa-shopping-cart paddingright"></span>'.dol_print_date($db->jdate($obj->datec),
'%H:%M',
'tzuser');
1487 echo
'$("#shoppingcart").append(\'<a onclick="place=\\\'0-';
1489 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>\');';
1497 $constantforkey =
'CASHDESK_NO_DECREASE_STOCK'. (isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
1498 if (isModEnabled(
'stock')) {
1500 $constantforkey =
'CASHDESK_ID_WAREHOUSE'. (isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
1502 if ($idwarehouse > 0) {
1503 $s =
'<span class="small">';
1505 $warehouse->fetch($idwarehouse);
1506 $s .=
'<span class="hideonsmartphone">'.$langs->trans(
"Warehouse").
'<br></span>'.$warehouse->ref;
1508 $s .=
' ('.$langs->trans(
"Closed").
')';
1511 print
"$('#infowarehouse').html('".dol_escape_js($s).
"');";
1512 print
'$("#infowarehouse").css("display", "inline-block");';
1514 $s =
'<span class="small hideonsmartphone">';
1515 $s .= $langs->trans(
"StockChangeDisabled").
'<br>'.$langs->trans(
"NoWarehouseDefinedForTerminal");
1517 print
"$('#infowarehouse').html('".dol_escape_js($s).
"');";
1518 if (!empty($conf->dol_optimize_smallscreen)) {
1519 print
'$("#infowarehouse").css("display", "none");';
1523 $s =
'<span class="small hideonsmartphone">'.$langs->trans(
"StockChangeDisabled").
'</span>';
1524 print
"$('#infowarehouse').html('".dol_escape_js($s).
"');";
1525 if (!empty($conf->dol_optimize_smallscreen)) {
1526 print
'$("#infowarehouse").css("display", "none");';
1534 if (isModEnabled(
'adherent') && $invoice->socid > 0 && $invoice->socid !=
getDolGlobalInt($constforcompanyid)) {
1535 $s =
'<span class="small">';
1536 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
1537 $langs->load(
"members");
1538 $s .= $langs->trans(
"Member").
': ';
1540 $result = $adh->fetch(
'',
'', $invoice->socid);
1542 $adh->ref = $adh->getFullName($langs);
1546 $s .= $adh->getFullName($langs);
1547 $s .=
' - '.$adh->type;
1548 if ($adh->datefin) {
1549 $s .=
'<br>'.$langs->trans(
"SubscriptionEndDate").
': '.
dol_print_date($adh->datefin,
'day');
1550 if ($adh->hasDelay()) {
1551 $s .=
" ".img_warning($langs->trans(
"Late"));
1554 $s .=
'<br>'.$langs->trans(
"SubscriptionNotReceived");
1555 if ($adh->statut > 0) {
1556 $s .=
" ".img_warning($langs->trans(
"Late"));
1563 $s .=
'<br>'.$langs->trans(
"ThirdpartyNotLinkedToMember");
1568 $(
"#moreinfo").html(
'<?php print dol_escape_js($s); ?>');
1575 echo
"function CustomerDisplay(){";
1576 echo
"var line1='".$CUSTOMER_DISPLAY_line1.
"'.substring(0,20);";
1577 echo
"line1=line1.padEnd(20);";
1578 echo
"var line2='".$CUSTOMER_DISPLAY_line2.
"'.substring(0,20);";
1579 echo
"line2=line2.padEnd(20);";
1582 data: { text: line1+line2 },
1583 url: '".getDolGlobalString(
'TAKEPOS_PRINT_SERVER').
"/display/index.php',
1594if (!empty($conf->use_javascript_ajax)) {
1595 print
"\n".
'<!-- Includes JS Footer of Dolibarr -->'.
"\n";
1596 print
'<script src="'.DOL_URL_ROOT.
'/core/js/lib_foot.js.php?lang='.$langs->defaultlang.
'"></script>'.
"\n";