109 header($_SERVER[
'SERVER_PROTOCOL'].
' 500 Internal Server Error',
true, 500);
115$number =
GETPOST(
'number',
'alpha');
116$idline =
GETPOST(
'idline',
'int');
117$selectedline =
GETPOST(
'selectedline',
'int');
118$desc =
GETPOST(
'desc',
'alphanohtml');
122$invoiceid =
GETPOST(
'invoiceid',
'int');
131if ($pay ==
'cheque') {
138 $sql =
"SELECT id FROM ".MAIN_DB_PREFIX.
"c_paiement";
139 $sql .=
" WHERE entity IN (".getEntity(
'c_paiement').
")";
140 $sql .=
" AND code = '".$db->escape($paycode).
"'";
141 $resql = $db->query($sql);
143 $obj = $db->fetch_object($resql);
145 $paiementid = $obj->id;
152 $ret = $invoice->fetch($invoiceid);
154 $ret = $invoice->fetch(
'',
'(PROV-POS'. (isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'') .
'-'.$place.
')');
157 $placeid = $invoice->id;
160$constforcompanyid =
'CASHDESK_ID_THIRDPARTY'. (isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
163if ($invoice->socid > 0) {
164 $soc->fetch($invoice->socid);
170if (isModEnabled(
'multicurrency') && !empty($_SESSION[
"takeposcustomercurrency"])) {
171 if ($invoice->multicurrency_code != $_SESSION[
"takeposcustomercurrency"]) {
172 $invoice->setMulticurrencyCode($_SESSION[
"takeposcustomercurrency"]);
176$term = empty($_SESSION[
"takeposterminal"]) ? 1 : $_SESSION[
"takeposterminal"];
184$reshook=$hookmanager->executeHooks(
'doActions', $parameters, $invoice, $action);
189if (empty($reshook)) {
191 if ($action ==
'valid' && $user->hasRight(
'facture',
'creer')) {
196 $bankaccount =
GETPOST(
'accountid',
'int');
199 $bankaccount =
getDolGlobalString(
'CASHDESK_ID_BANKACCOUNT_CASH'.$_SESSION[
"takeposterminal"]);
200 } elseif ($pay ==
"CHQ") {
201 $bankaccount =
getDolGlobalString(
'CASHDESK_ID_BANKACCOUNT_CHEQUE'.$_SESSION[
"takeposterminal"]);
203 $accountname =
"CASHDESK_ID_BANKACCOUNT_".$pay.$_SESSION[
"takeposterminal"];
208 if ($bankaccount <= 0 && $pay !=
"delayed" && isModEnabled(
"banque")) {
209 $errormsg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"BankAccount"));
217 $invoice->fetch($placeid);
221 if ($invoice->total_ttc < 0) {
222 $invoice->type = $invoice::TYPE_CREDIT_NOTE;
224 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"facture";
225 $sql .=
" WHERE entity IN (".getEntity(
'invoice').
")";
226 $sql .=
" AND fk_soc = ".((int) $invoice->socid);
227 $sql .=
" AND type <> ".Facture::TYPE_CREDIT_NOTE;
228 $sql .=
" AND fk_statut >= ".$invoice::STATUS_VALIDATED;
229 $sql .=
" ORDER BY rowid DESC";
231 $resql = $db->query($sql);
233 $obj = $db->fetch_object($resql);
234 $fk_source = $obj->rowid;
235 if ($fk_source ==
null) {
236 fail($langs->transnoentitiesnoconv(
"NoPreviousBillForCustomer"));
239 fail($langs->transnoentitiesnoconv(
"NoPreviousBillForCustomer"));
241 $invoice->fk_facture_source = $fk_source;
242 $invoice->update($user);
245 $constantforkey =
'CASHDESK_NO_DECREASE_STOCK'.(isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
250 if ($invoice->getRemainToPay() > 0) {
256 } elseif (count($invoice->lines) == 0) {
260 } elseif (isModEnabled(
'stock') && !isModEnabled(
'productbatch') &&
getDolGlobalString($constantforkey) !=
"1") {
263 $savconst = $conf->global->STOCK_CALCULATE_ON_BILL;
265 if (isModEnabled(
'productbatch') && !
getDolGlobalInt(
'CASHDESK_FORCE_DECREASE_STOCK')) {
266 $conf->global->STOCK_CALCULATE_ON_BILL = 0;
269 $conf->global->STOCK_CALCULATE_ON_BILL = 1;
272 $constantforkey =
'CASHDESK_ID_WAREHOUSE'.$_SESSION[
"takeposterminal"];
273 dol_syslog(
"Validate invoice with stock change into warehouse defined into constant ".$constantforkey.
" = ".
getDolGlobalString($constantforkey));
276 if (isModEnabled(
'productbatch') &&
getDolGlobalString(
'CASHDESK_FORCE_DECREASE_STOCK')) {
277 require_once DOL_DOCUMENT_ROOT.
'/product/class/productbatch.class.php';
280 $res = $invoice->validate($user,
'',
getDolGlobalInt($constantforkey), 0, $batch_rule);
282 $conf->global->STOCK_CALCULATE_ON_BILL = $savconst;
285 $res = $invoice->validate($user);
288 $langs->load(
"admin");
289 dol_htmloutput_errors($invoice->error ==
'NotConfigured' ? $langs->trans(
"NotConfigured").
' (TakePos numbering module)' : $invoice->error, $invoice->errors, 1);
294 if (!$error && $res >= 0) {
295 $remaintopay = $invoice->getRemainToPay();
296 if ($remaintopay > 0) {
298 $payment->datepaye = $now;
299 $payment->fk_account = $bankaccount;
300 $payment->amounts[$invoice->id] = $amountofpayment;
307 if ($amountofpayment <= 0 || $amountofpayment > $remaintopay) {
308 $payment->amounts[$invoice->id] = $remaintopay;
311 $payment->paiementid = $paiementid;
312 $payment->num_payment = $invoice->ref;
314 if ($pay !=
"delayed") {
315 $result = $payment->create($user);
320 $res = $payment->addPaymentToBank($user,
'payment',
'(CustomerInvoicePayment)', $bankaccount,
'',
'');
326 $remaintopay = $invoice->getRemainToPay();
332 if ($remaintopay == 0) {
333 dol_syslog(
"Invoice is paid, so we set it to status Paid");
334 $result = $invoice->setPaid($user);
339 $invoice->setPaymentMethods($paiementid);
341 dol_syslog(
"Invoice is not paid, remain to pay = ".$remaintopay);
348 if (!$error && $res >= 0) {
349 if (isModEnabled(
'stock') && isModEnabled(
'productbatch')) {
350 require_once DOL_DOCUMENT_ROOT .
"/product/stock/class/mouvementstock.class.php";
351 $constantforkey =
'CASHDESK_ID_WAREHOUSE'.$_SESSION[
"takeposterminal"];
353 $labeltakeposmovement =
'TakePOS - '.$langs->trans(
"Invoice").
' '.$invoice->ref;
355 foreach ($invoice->lines as $line) {
356 $warehouseid = ($line->fk_warehouse ? $line->fk_warehouse :
getDolGlobalInt($constantforkey));
359 if ($line->batch !=
'' && $warehouseid > 0) {
361 $prod_batch->find(0,
'',
'', $line->batch, $warehouseid);
363 $mouvP->origin = $invoice;
364 $res = $mouvP->livraison($user, $line->fk_product, $warehouseid, $line->qty, $line->price, $labeltakeposmovement,
'',
'',
'', $prod_batch->batch, $prod_batch->id, $inventorycode);
371 $mouvP->origin = $invoice;
372 $res = $mouvP->livraison($user, $line->fk_product, $warehouseid, $line->qty, $line->price, $labeltakeposmovement,
'',
'',
'',
'', 0, $inventorycode);
382 if (!$error && $res >= 0) {
388 if ($action ==
'creditnote' && $user->hasRight(
'facture',
'creer')) {
391 $creditnote =
new Facture($db);
392 $creditnote->socid = $invoice->socid;
394 $creditnote->module_source =
'takepos';
395 $creditnote->pos_source = isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'' ;
397 $creditnote->fk_facture_source = $placeid;
400 $creditnote->create($user);
402 foreach ($invoice->lines as $line) {
404 if (method_exists($line,
'fetch_optionals')) {
406 $line->fetch_optionals();
409 if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) {
414 if (!empty($invoice->situation_counter)) {
415 $source_fk_prev_id = $line->fk_prev_id;
416 $line->fk_prev_id = $line->id;
417 if (!empty($invoice->tab_previous_situation_invoice)) {
420 $tab_jumped_credit_notes = array();
421 $lineIndex = count($invoice->tab_previous_situation_invoice) - 1;
422 $searchPreviousInvoice =
true;
423 while ($searchPreviousInvoice) {
424 if ($invoice->tab_previous_situation_invoice[$lineIndex]->situation_cycle_ref || $lineIndex < 1) {
425 $searchPreviousInvoice =
false;
429 $tab_jumped_credit_notes[$lineIndex] = $invoice->tab_previous_situation_invoice[$lineIndex]->id;
435 $maxPrevSituationPercent = 0;
436 foreach ($invoice->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine) {
437 if ($prevLine->id == $source_fk_prev_id) {
438 $maxPrevSituationPercent = max($maxPrevSituationPercent, $prevLine->situation_percent);
441 $line->total_ht = $line->total_ht - $prevLine->total_ht;
442 $line->total_tva = $line->total_tva - $prevLine->total_tva;
443 $line->total_ttc = $line->total_ttc - $prevLine->total_ttc;
444 $line->total_localtax1 = $line->total_localtax1 - $prevLine->total_localtax1;
445 $line->total_localtax2 = $line->total_localtax2 - $prevLine->total_localtax2;
447 $line->multicurrency_subprice = $line->multicurrency_subprice - $prevLine->multicurrency_subprice;
448 $line->multicurrency_total_ht = $line->multicurrency_total_ht - $prevLine->multicurrency_total_ht;
449 $line->multicurrency_total_tva = $line->multicurrency_total_tva - $prevLine->multicurrency_total_tva;
450 $line->multicurrency_total_ttc = $line->multicurrency_total_ttc - $prevLine->multicurrency_total_ttc;
455 $line->situation_percent = $maxPrevSituationPercent - $line->situation_percent;
460 $maxPrevSituationPercent = 0;
461 foreach ($tab_jumped_credit_notes as $index => $creditnoteid) {
462 foreach ($invoice->tab_previous_situation_invoice[$index]->lines as $prevLine) {
463 if ($prevLine->fk_prev_id == $source_fk_prev_id) {
464 $maxPrevSituationPercent = $prevLine->situation_percent;
466 $line->total_ht -= $prevLine->total_ht;
467 $line->total_tva -= $prevLine->total_tva;
468 $line->total_ttc -= $prevLine->total_ttc;
469 $line->total_localtax1 -= $prevLine->total_localtax1;
470 $line->total_localtax2 -= $prevLine->total_localtax2;
472 $line->multicurrency_subprice -= $prevLine->multicurrency_subprice;
473 $line->multicurrency_total_ht -= $prevLine->multicurrency_total_ht;
474 $line->multicurrency_total_tva -= $prevLine->multicurrency_total_tva;
475 $line->multicurrency_total_ttc -= $prevLine->multicurrency_total_ttc;
481 $line->situation_percent += $maxPrevSituationPercent;
488 $line->fk_facture = $creditnote->id;
489 $line->fk_parent_line = $fk_parent_line;
491 $line->subprice = -$line->subprice;
492 $line->pa_ht = $line->pa_ht;
493 $line->total_ht = -$line->total_ht;
494 $line->total_tva = -$line->total_tva;
495 $line->total_ttc = -$line->total_ttc;
496 $line->total_localtax1 = -$line->total_localtax1;
497 $line->total_localtax2 = -$line->total_localtax2;
499 $line->multicurrency_subprice = -$line->multicurrency_subprice;
500 $line->multicurrency_total_ht = -$line->multicurrency_total_ht;
501 $line->multicurrency_total_tva = -$line->multicurrency_total_tva;
502 $line->multicurrency_total_ttc = -$line->multicurrency_total_ttc;
504 $result = $line->insert(0, 1);
506 $creditnote->lines[] = $line;
509 if ($result > 0 && $line->product_type == 9) {
510 $fk_parent_line = $result;
513 $creditnote->update_price(1);
515 $constantforkey =
'CASHDESK_NO_DECREASE_STOCK'.(isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
517 $savconst = $conf->global->STOCK_CALCULATE_ON_BILL;
518 $conf->global->STOCK_CALCULATE_ON_BILL = 1;
519 $constantforkey =
'CASHDESK_ID_WAREHOUSE'.(isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
520 dol_syslog(
"Validate invoice with stock change into warehouse defined into constant ".$constantforkey.
" = ".
getDolGlobalString($constantforkey));
522 if (isModEnabled(
'productbatch') &&
getDolGlobalString(
'CASHDESK_FORCE_DECREASE_STOCK')) {
523 require_once DOL_DOCUMENT_ROOT.
'/product/class/productbatch.class.php';
526 $res = $creditnote->validate($user,
'',
getDolGlobalString($constantforkey), 0, $batch_rule);
527 $conf->global->STOCK_CALCULATE_ON_BILL = $savconst;
529 $res = $creditnote->validate($user);
532 if (!$error && $res >= 0) {
539 if (($action ==
'history' || $action ==
'creditnote') && $user->hasRight(
'takepos',
'run')) {
540 if ($action ==
'creditnote') {
541 $placeid = $creditnote->id;
543 $placeid = (int)
GETPOST(
'placeid',
'int');
546 $invoice->fetch($placeid);
550 if (($action ==
"addline" || $action ==
"freezone") && $placeid == 0 && ($user->hasRight(
'takepos',
'run') || defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
553 include_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
556 $invoice->module_source =
'takepos';
557 $invoice->pos_source = isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'' ;
558 $invoice->entity = !empty($_SESSION[
"takeposinvoiceentity"]) ? $_SESSION[
"takeposinvoiceentity"] : $conf->entity;
560 if ($invoice->socid <= 0) {
561 $langs->load(
'errors');
567 $placeid = $invoice->create($user);
571 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facture set ref='(PROV-POS".$_SESSION[
"takeposterminal"].
"-".$place.
")' where rowid = ".((int) $placeid);
572 $resql = $db->query($sql);
586 if ($action ==
"addline" && ($user->hasRight(
'takepos',
'run') || defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
588 $prod->fetch($idproduct);
591 $customer->fetch($invoice->socid);
593 $datapriceofproduct = $prod->getSellPrice($mysoc, $customer, 0);
595 $qty = GETPOSTISSET(
'qty') ?
GETPOST(
'qty',
'int') : 1;
596 $price = $datapriceofproduct[
'pu_ht'];
597 $price_ttc = $datapriceofproduct[
'pu_ttc'];
599 $price_base_type = empty($datapriceofproduct[
'price_base_type']) ?
'HT' : $datapriceofproduct[
'price_base_type'];
600 $tva_tx = $datapriceofproduct[
'tva_tx'];
601 $tva_npr = $datapriceofproduct[
'tva_npr'];
604 $localtax1_tx =
get_localtax($tva_tx, 1, $customer, $mysoc, $tva_npr);
605 $localtax2_tx =
get_localtax($tva_tx, 2, $customer, $mysoc, $tva_npr);
608 if (isModEnabled(
'productbatch') && isModEnabled(
'stock')) {
609 $batch =
GETPOST(
'batch',
'alpha');
611 if (!empty($batch)) {
612 $action =
"setbatch";
613 } elseif ($prod->status_batch > 0) {
618 $prod->load_stock(
'warehouseopen');
620 $constantforkey =
'CASHDESK_ID_WAREHOUSE'.$_SESSION[
"takeposterminal"];
624 foreach ($prod->stock_warehouse as $tmpwarehouseid => $tmpval) {
629 if (!empty($prod->stock_warehouse[$tmpwarehouseid]) && is_array($prod->stock_warehouse[$tmpwarehouseid]->detail_batch)) {
630 if (is_object($prod->stock_warehouse[$tmpwarehouseid]) && count($prod->stock_warehouse[$tmpwarehouseid]->detail_batch)) {
631 foreach ($prod->stock_warehouse[$tmpwarehouseid]->detail_batch as $dbatch) {
640 echo
"function addbatch(batch, warehouseid) {\n";
641 echo
"console.log('We add batch '+batch+' from warehouse id '+warehouseid);\n";
642 echo
'$("#poslines").load("invoice.php?action=addline&batch="+batch+"&warehouseid="+warehouseid+"&place='.$place.
'&idproduct='.$idproduct.
'&token='.newToken().
'", function() {});'.
"\n";
647 echo
"<center>".$langs->trans(
"SearchIntoBatch").
": <b> $nbofsuggested </b></center><br><table>";
648 foreach ($prod->stock_warehouse as $tmpwarehouseid => $tmpval) {
653 if (!empty($prod->stock_warehouse[$tmpwarehouseid]) && is_array($prod->stock_warehouse[$tmpwarehouseid]->detail_batch)) {
654 foreach ($prod->stock_warehouse[$tmpwarehouseid]->detail_batch as $dbatch) {
655 $batchStock = + $dbatch->qty;
656 $quantityToBeDelivered = 1;
657 $deliverableQty = min($quantityToBeDelivered, $batchStock);
659 print
'<!-- subj='.$suggestednb.
'/'.$nbofsuggested.
' -->';
660 print
'<!-- Show details of lot -->';
661 print
'<td class="left">';
663 $detail .=
'<span class="opacitymedium">'.$langs->trans(
"LotSerial").
':</span> '.$dbatch->batch;
670 $detail .=
'</td><td>';
671 $detail .=
'<span class="opacitymedium">'.$langs->trans(
"Qty").
':</span> '.$dbatch->qty;
672 $detail .=
'</td><td>';
673 $detail .=
' <button class="marginleftonly" onclick="addbatch(\''.dol_escape_js($dbatch->batch).
'\',
'.$tmpwarehouseid.')
">'.$langs->trans("Select
")."</
button>
";
677 $quantityToBeDelivered -= $deliverableQty;
678 if ($quantityToBeDelivered < 0) {
679 $quantityToBeDelivered = 0;
688 print '</body></html>';
694 if (getDolGlobalString('TAKEPOS_SUPPLEMENTS')) {
695 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
696 $cat = new Categorie($db);
697 $categories = $cat->containing($idproduct, 'product');
698 $found = (array_search(getDolGlobalInt('TAKEPOS_SUPPLEMENTS_CATEGORY'), array_column($categories, 'id')));
699 if ($found !== false) { // If this product is a supplement
700 $sql = "SELECT fk_parent_line FROM
".MAIN_DB_PREFIX."facturedet where
rowid =
".((int) $selectedline);
701 $resql = $db->query($sql);
702 $row = $db->fetch_array($resql);
703 if ($row[0] == null) {
704 $parent_line = $selectedline;
706 $parent_line = $row[0]; //If the parent line is already a supplement, add the supplement to the main product
713 // Group if enabled. Skip group if line already sent to the printer
714 if (getDolGlobalString('TAKEPOS_GROUP_SAME_PRODUCT')) {
715 foreach ($invoice->lines as $line) {
716 if ($line->product_ref == $prod->ref) {
717 if ($line->special_code==4) {
719 } // If this line is sended to printer create new line
720 // check if qty in stock
721 if (getDolGlobalString('TAKEPOS_QTY_IN_STOCK') && (($line->qty + $qty) > $prod->stock_reel)) {
722 $invoice->error = $langs->trans('NotEnoughInStock');
723 dol_htmloutput_errors($invoice->error, $invoice->errors, 1);
727 $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);
729 dol_htmloutput_errors($invoice->error, $invoice->errors, 1);
731 $idoflineadded = $line->id;
737 if ($idoflineadded <= 0 && empty($err)) {
738 $invoice->fetch_thirdparty();
739 $array_options = array();
741 $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);
743 /* setup of margin calculation */
744 if (isset($conf->global->MARGIN_TYPE)) {
745 if (getDolGlobalString('MARGIN_TYPE') == 'pmp' && !empty($prod->pmp)) {
746 $line['fk_fournprice'] = null;
747 $line['pa_ht'] = $prod->pmp;
748 } elseif (getDolGlobalString('MARGIN_TYPE') == 'costprice' && !empty($prod->cost_price)) {
749 $line['fk_fournprice'] = null;
750 $line['pa_ht'] = $prod->cost_price;
752 // default is fournprice
753 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
754 $pf = new ProductFournisseur($db);
755 if ($pf->find_min_price_product_fournisseur($idproduct, $qty) > 0) {
756 $line['fk_fournprice'] = $pf->product_fourn_price_id;
757 $line['pa_ht'] = $pf->fourn_unitprice_with_discount;
758 if (getDolGlobalString('PRODUCT_CHARGES') && $pf->fourn_charges > 0) {
759 $line['pa_ht'] += $pf->fourn_charges / $pf->fourn_qty;
765 // complete line by hook
766 $parameters = array('prod' => $prod, 'line' => $line);
767 $reshook=$hookmanager->executeHooks('completeTakePosAddLine', $parameters, $invoice, $action); // Note that $action and $line may have been modified by some hooks
769 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
773 if (empty($reshook)) {
774 if (!empty($hookmanager->resArray)) {
775 $line = $hookmanager->resArray;
778 // check if qty in stock
779 if (getDolGlobalString('TAKEPOS_QTY_IN_STOCK') && $qty > $prod->stock_reel) {
780 $invoice->error = $langs->trans('NotEnoughInStock');
781 dol_htmloutput_errors($invoice->error, $invoice->errors, 1);
786 $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);
790 if (getDolGlobalString('TAKEPOS_CUSTOMER_DISPLAY')) {
791 $CUSTOMER_DISPLAY_line1 = $prod->label;
792 $CUSTOMER_DISPLAY_line2 = price($price_ttc);
796 $invoice->fetch($placeid);
799 // If we add a line by submitting freezone form (invoice exists here because it was created juste before if it didn't exists)
800 if ($action == "freezone
" && $user->hasRight('takepos', 'run')) {
801 $customer = new Societe($db);
802 $customer->fetch($invoice->socid);
804 $tva_tx = GETPOST('tva_tx', 'alpha');
806 if (!preg_match('/\((.*)\)/', $tva_tx)) {
807 $tva_tx = price2num($tva_tx);
810 $tva_tx = get_default_tva($mysoc, $customer);
814 $localtax1_tx = get_localtax($tva_tx, 1, $customer, $mysoc, $tva_npr);
815 $localtax2_tx = get_localtax($tva_tx, 2, $customer, $mysoc, $tva_npr);
817 $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);
819 dol_htmloutput_errors($invoice->error, $invoice->errors, 1);
821 $invoice->fetch($placeid);
824 if ($action == "addnote
" && ($user->hasRight('takepos', 'run') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
825 $desc = GETPOST('addnote', 'alpha');
827 $invoice->update_note($desc, '_public');
829 foreach ($invoice->lines as $line) {
830 if ($line->id == $idline) {
831 $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);
835 $invoice->fetch($placeid);
838 if ($action == "deleteline
" && ($user->hasRight('takepos', 'run') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
840 $permissiontoupdateline = ($user->hasRight('takepos', 'editlines') && ($user->hasRight('takepos', 'editorderedlines') || $line->special_code != "4
"));
841 if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
842 if ($invoice->status == $invoice::STATUS_DRAFT && $invoice->pos_source && $invoice->module_source == 'takepos') {
843 $permissiontoupdateline = true;
844 // TODO Add also a test on $_SESSION('publicobjectid'] defined at creation of object
845 // TODO Check also that invoice->ref is (PROV-POS1-2) with 1 = terminal and 2, the invoice ID
849 if ($idline > 0 && $placeid > 0) { // If invoice exists and line selected. To avoid errors if deleted from another device or no line selected.
850 $invoice->deleteline($idline);
851 $invoice->fetch($placeid);
852 } elseif ($placeid > 0) { // If invoice exists but no line selected, proceed to delete last line.
853 $sql = "SELECT
rowid FROM
".MAIN_DB_PREFIX."facturedet where fk_facture =
".((int) $placeid)." ORDER BY
rowid DESC
";
854 $resql = $db->query($sql);
855 $row = $db->fetch_array($resql);
856 $deletelineid = $row[0];
857 $invoice->deleteline($deletelineid);
858 $invoice->fetch($placeid);
861 if (count($invoice->lines) == 0) {
862 $invoice->delete($user);
864 if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
865 header("Location:
".DOL_URL_ROOT."/takepos/public/auto_order.php
");
867 header("Location:
".DOL_URL_ROOT."/takepos/invoice.php
");
873 // Action to delete or discard an invoice
874 if ($action == "delete
" && ($user->hasRight('takepos', 'run') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
875 // $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.
877 $result = $invoice->fetch($placeid);
879 if ($result > 0 && $invoice->statut == Facture::STATUS_DRAFT) {
882 // We delete the lines
884 foreach ($invoice->lines as $line) {
885 $tmpres = $invoice->deleteline($line->id);
892 $sql = "UPDATE
".MAIN_DB_PREFIX."facture
";
893 $varforconst = 'CASHDESK_ID_THIRDPARTY'.$_SESSION["takeposterminal
"];
894 $sql .= " SET fk_soc =
".((int) getDolGlobalString($varforconst)).",
";
895 $sql .= " datec =
'".$db->idate(dol_now())."'";
896 $sql .= " WHERE entity IN (
".getEntity('invoice').")
";
897 $sql .= " AND
ref =
'(PROV-POS".$db->escape($_SESSION["takeposterminal"]."-".$place).")'";
898 $resql1 = $db->query($sql);
900 if ($resdeletelines && $resql1) {
906 $invoice->fetch($placeid);
911 if ($action == "updateqty
") { // Test on permission is done later
912 foreach ($invoice->lines as $line) {
913 if ($line->id == $idline) {
914 $permissiontoupdateline = ($user->hasRight('takepos', 'editlines') && ($user->hasRight('takepos', 'editorderedlines') || $line->special_code != "4
"));
915 if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
916 if ($invoice->status == $invoice::STATUS_DRAFT && $invoice->pos_source && $invoice->module_source == 'takepos') {
917 $permissiontoupdateline = true;
918 // TODO Add also a test on $_SESSION('publicobjectid'] defined at creation of object
919 // TODO Check also that invoice->ref is (PROV-POS1-2) with 1 = terminal and 2, the invoice ID
922 if (!$permissiontoupdateline) {
923 dol_htmloutput_errors($langs->trans("NotEnoughPermissions
", "TakePos
").' - No permission to updateqty', null, 1);
925 $vatratecode = $line->tva_tx;
926 if ($line->vat_src_code) {
927 $vatratecode .= ' ('.$line->vat_src_code.')';
930 $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);
935 $invoice->fetch($placeid);
938 if ($action == "updateprice
") { // Test on permission is done later
939 $customer = new Societe($db);
940 $customer->fetch($invoice->socid);
942 foreach ($invoice->lines as $line) {
943 if ($line->id == $idline) {
944 $prod = new Product($db);
945 $prod->fetch($line->fk_product);
946 $datapriceofproduct = $prod->getSellPrice($mysoc, $customer, 0);
947 $price_min = $datapriceofproduct['price_min'];
948 $usercanproductignorepricemin = ((getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && empty($user->rights->produit->ignore_price_min_advance)) || !getDolGlobalString('MAIN_USE_ADVANCED_PERMS'));
949 $pu_ht = price2num($number / (1 + ($line->tva_tx / 100)), 'MU');
951 if ($usercanproductignorepricemin && (!empty($price_min) && (price2num($pu_ht) * (1 - price2num($line->remise_percent) / 100) < price2num($price_min)))) {
952 $langs->load("products
");
953 dol_htmloutput_errors($langs->trans("CantBeLessThanMinPrice
", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, -1, $conf->currency)));
954 //echo $langs->trans("CantBeLessThanMinPrice
");
956 $permissiontoupdateline = ($user->hasRight('takepos', 'editlines') && ($user->hasRight('takepos', 'editorderedlines') || $line->special_code != "4
"));
957 if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
958 if ($invoice->status == $invoice::STATUS_DRAFT && $invoice->pos_source && $invoice->module_source == 'takepos') {
959 $permissiontoupdateline = true;
960 // TODO Add also a test on $_SESSION('publicobjectid'] defined at creation of object
961 // TODO Check also that invoice->ref is (PROV-POS1-2) with 1 = terminal and 2, the invoice ID
965 $vatratecode = $line->tva_tx;
966 if ($line->vat_src_code) {
967 $vatratecode .= ' ('.$line->vat_src_code.')';
970 if (!$permissiontoupdateline) {
971 dol_htmloutput_errors($langs->trans("NotEnoughPermissions
", "TakePos
").' - No permission to updateprice', null, 1);
972 } elseif (getDolGlobalInt('TAKEPOS_CHANGE_PRICE_HT') == 1) {
973 $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);
975 $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);
982 $invoice->fetch($placeid);
985 if ($action == "updatereduction
") { // Test on permission is done later
986 $customer = new Societe($db);
987 $customer->fetch($invoice->socid);
989 foreach ($invoice->lines as $line) {
990 if ($line->id == $idline) {
991 dol_syslog("updatereduction Process line
".$line->id.' to apply discount of '.$number.'%');
993 $prod = new Product($db);
994 $prod->fetch($line->fk_product);
996 $datapriceofproduct = $prod->getSellPrice($mysoc, $customer, 0);
997 $price_min = $datapriceofproduct['price_min'];
998 $usercanproductignorepricemin = ((getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && empty($user->rights->produit->ignore_price_min_advance)) || !getDolGlobalString('MAIN_USE_ADVANCED_PERMS'));
1000 $pu_ht = price2num($line->subprice / (1 + ($line->tva_tx / 100)), 'MU');
1003 if ($usercanproductignorepricemin && (!empty($price_min) && (price2num($line->subprice) * (1 - price2num($number) / 100) < price2num($price_min)))) {
1004 $langs->load("products
");
1005 dol_htmloutput_errors($langs->trans("CantBeLessThanMinPrice
", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, -1, $conf->currency)));
1007 $permissiontoupdateline = ($user->hasRight('takepos', 'editlines') && ($user->hasRight('takepos', 'editorderedlines') || $line->special_code != "4
"));
1008 if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1009 if ($invoice->status == $invoice::STATUS_DRAFT && $invoice->pos_source && $invoice->module_source == 'takepos') {
1010 $permissiontoupdateline = true;
1011 // TODO Add also a test on $_SESSION('publicobjectid'] defined at creation of object
1012 // TODO Check also that invoice->ref is (PROV-POS1-2) with 1 = terminal and 2, the invoice ID
1015 if (!$permissiontoupdateline) {
1016 dol_htmloutput_errors($langs->trans("NotEnoughPermissions
", "TakePos
"), null, 1);
1018 $vatratecode = $line->tva_tx;
1019 if ($line->vat_src_code) {
1020 $vatratecode .= ' ('.$line->vat_src_code.')';
1022 $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);
1029 $invoice->fetch($placeid);
1030 } elseif ($action == 'update_reduction_global' && $user->hasRight('takepos', 'editlines')) {
1031 foreach ($invoice->lines as $line) {
1032 $vatratecode = $line->tva_tx;
1033 if ($line->vat_src_code) {
1034 $vatratecode .= ' ('.$line->vat_src_code.')';
1036 $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);
1039 $invoice->fetch($placeid);
1042 if ($action=="setbatch
" && ($user->hasRight('takepos', 'run') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
1043 $constantforkey = 'CASHDESK_ID_WAREHOUSE'.$_SESSION["takeposterminal
"];
1044 $warehouseid = getDolGlobalInt($constantforkey); // TODO Get the wrehouse id from GETPOSTINT('warehouseid');
1045 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet SET batch =
'".$db->escape($batch)."', fk_warehouse =
".((int) $warehouseid);
1046 $sql .= " WHERE
rowid=
".((int) $idoflineadded);
1050 if ($action == "order
" && $placeid != 0 && ($user->hasRight('takepos', 'run') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
1051 include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
1052 if ((isModEnabled('receiptprinter') && getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term) > 0) || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter
" || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector
") {
1053 require_once DOL_DOCUMENT_ROOT.'/core/class/dolreceiptprinter.class.php';
1054 $printer = new dolReceiptPrinter($db);
1057 $sql = "SELECT label FROM
".MAIN_DB_PREFIX."takepos_floor_tables where
rowid=
".((int) $place);
1058 $resql = $db->query($sql);
1059 $row = $db->fetch_object($resql);
1060 $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>';
1061 $footerorder = '</tbody></table>'.dol_print_date(dol_now(), 'dayhour').'<br></html>';
1062 $order_receipt_printer1 = "";
1063 $order_receipt_printer2 = "";
1064 $order_receipt_printer3 = "";
1065 $catsprinter1 = explode(';', getDolGlobalString('TAKEPOS_PRINTED_CATEGORIES_1'));
1066 $catsprinter2 = explode(';', getDolGlobalString('TAKEPOS_PRINTED_CATEGORIES_2'));
1067 $catsprinter3 = explode(';', getDolGlobalString('TAKEPOS_PRINTED_CATEGORIES_3'));
1069 foreach ($invoice->lines as $line) {
1070 if ($line->special_code == "4
") {
1073 $c = new Categorie($db);
1074 $existing = $c->containing($line->fk_product, Categorie::TYPE_PRODUCT, 'id');
1075 $result = array_intersect($catsprinter1, $existing);
1076 $count = count($result);
1077 if (!$line->fk_product) {
1078 $count++; // Print Free-text item (Unassigned printer) to Printer 1
1082 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet set special_code=
'1' where
rowid=
".$line->id; //Set to print on printer 1
1084 $order_receipt_printer1 .= '<tr><td class="left
">';
1085 if ($line->fk_product) {
1086 $order_receipt_printer1 .= $line->product_label;
1088 $order_receipt_printer1 .= $line->description;
1090 $order_receipt_printer1 .= '</td><td class="right
">'.$line->qty;
1091 if (!empty($line->array_options['options_order_notes'])) {
1092 $order_receipt_printer1 .= "<br>(
".$line->array_options['options_order_notes'].")
";
1094 $order_receipt_printer1 .= '</td></tr>';
1097 if (((isModEnabled('receiptprinter') && getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term) > 0) || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter
" || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector
") && $linestoprint > 0) {
1098 $invoice->fetch($placeid); //Reload object before send to printer
1099 $printer->orderprinter = 1;
1101 echo "var orderprinter1esc=
'";
1102 $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
1105 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet
set special_code=
'4' where special_code=
'1' and fk_facture=
".$invoice->id; // Set as printed
1107 $invoice->fetch($placeid); //Reload object after set lines as printed
1110 foreach ($invoice->lines as $line) {
1111 if ($line->special_code == "4
") {
1114 $c = new Categorie($db);
1115 $existing = $c->containing($line->fk_product, Categorie::TYPE_PRODUCT, 'id');
1116 $result = array_intersect($catsprinter2, $existing);
1117 $count = count($result);
1120 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet
set special_code=
'2' where
rowid=
".$line->id; //Set to print on printer 2
1122 $order_receipt_printer2 .= '<tr>'.$line->product_label.'<td class="right
">'.$line->qty;
1123 if (!empty($line->array_options['options_order_notes'])) {
1124 $order_receipt_printer2 .= "<br>(
".$line->array_options['options_order_notes'].")
";
1126 $order_receipt_printer2 .= '</td></tr>';
1129 if (((isModEnabled('receiptprinter') && getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term) > 0) || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter
" || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector
") && $linestoprint > 0) {
1130 $invoice->fetch($placeid); //Reload object before send to printer
1131 $printer->orderprinter = 2;
1133 echo "var orderprinter2esc=
'";
1134 $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
1137 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet
set special_code=
'4' where special_code=
'2' and fk_facture=
".$invoice->id; // Set as printed
1139 $invoice->fetch($placeid); //Reload object after set lines as printed
1142 foreach ($invoice->lines as $line) {
1143 if ($line->special_code == "4
") {
1146 $c = new Categorie($db);
1147 $existing = $c->containing($line->fk_product, Categorie::TYPE_PRODUCT, 'id');
1148 $result = array_intersect($catsprinter3, $existing);
1149 $count = count($result);
1152 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet
set special_code=
'3' where
rowid=
".$line->id; //Set to print on printer 3
1154 $order_receipt_printer3 .= '<tr>'.$line->product_label.'<td class="right
">'.$line->qty;
1155 if (!empty($line->array_options['options_order_notes'])) {
1156 $order_receipt_printer3 .= "<br>(
".$line->array_options['options_order_notes'].")
";
1158 $order_receipt_printer3 .= '</td></tr>';
1161 if (((isModEnabled('receiptprinter') && getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term) > 0) || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter
" || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector
") && $linestoprint > 0) {
1162 $invoice->fetch($placeid); //Reload object before send to printer
1163 $printer->orderprinter = 3;
1165 echo "var orderprinter3esc=
'";
1166 $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
1169 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet
set special_code=
'4' where special_code=
'3' and fk_facture=
".$invoice->id; // Set as printed
1171 $invoice->fetch($placeid); //Reload object after set lines as printed
1174 $sectionwithinvoicelink = '';
1175 if (($action == "valid
" || $action == "history
" || $action == 'creditnote') && $user->hasRight('takepos', 'run')) {
1176 $sectionwithinvoicelink .= '<!-- Section with invoice link -->'."\n
";
1177 $sectionwithinvoicelink .= '<span style="font-size:120%;
" class="center
">';
1178 $sectionwithinvoicelink .= $invoice->getNomUrl(1, '', 0, 0, '', 0, 0, -1, '_backoffice')." -
";
1179 $remaintopay = $invoice->getRemainToPay();
1180 if ($remaintopay > 0) {
1181 $sectionwithinvoicelink .= $langs->trans('RemainToPay').': <span class="amountremaintopay
" style="font-size: unset
">'.price($remaintopay, 1, $langs, 1, -1, -1, $conf->currency).'</span>';
1183 if ($invoice->paye) {
1184 $sectionwithinvoicelink .= '<span class="amountpaymentcomplete
" style="font-size: unset
">'.$langs->trans("Paid
").'</span>';
1186 $sectionwithinvoicelink .= $langs->trans('BillShortStatusValidated');
1190 $sectionwithinvoicelink .= '</span><br>';
1191 if (getDolGlobalInt('TAKEPOS_PRINT_INVOICE_DOC_INSTEAD_OF_RECEIPT')) {
1192 $sectionwithinvoicelink .= ' <a target="_blank
" class="button" href="' . DOL_URL_ROOT . '/document.php?token=
' . newToken() . '&modulepart=facture&file=
' . $invoice->ref . '/
' . $invoice->ref . '.pdf
">Invoice</a>';
1193 } elseif (getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector
") {
1194 if (getDolGlobalString('TAKEPOS_PRINT_SERVER') && filter_var($conf->global->TAKEPOS_PRINT_SERVER, FILTER_VALIDATE_URL) == true) {
1195 $sectionwithinvoicelink .= ' <button id="buttonprint
" type="button" onclick="TakeposConnector(
'.$placeid.')
">'.$langs->trans('PrintTicket').'</button>';
1197 $sectionwithinvoicelink .= ' <button id="buttonprint
" type="button" onclick="TakeposPrinting(
'.$placeid.')
">'.$langs->trans('PrintTicket').'</button>';
1199 } elseif ((isModEnabled('receiptprinter') && getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term) > 0) || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter
") {
1200 $sectionwithinvoicelink .= ' <button id="buttonprint
" type="button" onclick="DolibarrTakeposPrinting(
'.$placeid.')
">'.$langs->trans('PrintTicket').'</button>';
1202 $sectionwithinvoicelink .= ' <button id="buttonprint
" type="button" onclick="Print(
'.$placeid.')
">'.$langs->trans('PrintTicket').'</button>';
1203 if (getDolGlobalString('TAKEPOS_PRINT_WITHOUT_DETAILS')) {
1204 $sectionwithinvoicelink .= ' <button id="buttonprint
" type="button" onclick="PrintBox(
'.$placeid.', \
'without_details\')">'.$langs->trans(
'PrintWithoutDetails').
'</button>';
1207 $sectionwithinvoicelink .=
' <button id="buttonprint" type="button" onclick="Print('.$placeid.
', 1)">'.$langs->trans(
'GiftReceipt').
'</button>';
1211 $sectionwithinvoicelink .=
' <button id="buttonsend" type="button" onclick="SendTicket('.$placeid.
')">'.$langs->trans(
'SendTicket').
'</button>';
1214 if ($remaintopay <= 0 &&
getDolGlobalString(
'TAKEPOS_AUTO_PRINT_TICKETS') && $action !=
"history") {
1215 $sectionwithinvoicelink .=
'<script type="text/javascript">$("#buttonprint").click();</script>';
1225$form =
new Form($db);
1228if ((
getDolGlobalString(
'TAKEPOS_PHONE_BASIC_LAYOUT') == 1 && $conf->browser->layout ==
'phone') || defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1229 $title =
'TakePOS - Dolibarr '.DOL_VERSION;
1233 $head =
'<meta name="apple-mobile-web-app-title" content="TakePOS"/>
1234 <meta name="apple-mobile-web-app-capable" content="yes">
1235 <meta name="mobile-web-app-capable" content="yes">
1236 <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>';
1237 $arrayofcss = array(
1238 '/takepos/css/pos.css.php',
1240 $arrayofjs = array(
'/takepos/js/jquery.colorbox-min.js');
1243 top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss);
1245 print
'<body>'.
"\n";
1252<script
type=
"text/javascript">
1255<?php
if ($action==
"valid") {
1256 echo
"var place=0;";
1258var placeid=<?php echo($placeid > 0 ? $placeid : 0); ?>;
1259$(document).ready(
function() {
1260 var idoflineadded = <?php echo(empty($idoflineadded) ? 0 : $idoflineadded); ?>;
1262 $(
'.posinvoiceline').click(
function(){
1263 console.log(
"Click done on "+this.
id);
1264 $(
'.posinvoiceline').removeClass(
"selected");
1265 $(
this).addClass(
"selected");
1269 if (selectedline == this.
id) {
1272 selectedline = this.id;
1274 selectedtext=$(
'#'+selectedline).find(
"td:first").html();
1276 if (defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1277 print
'$("#phonediv1").load("'.DOL_URL_ROOT.
'/takepos/public/auto_order.php?action=editline&token='.newToken().
'&placeid="+placeid+"&selectedline="+selectedline, function() {
1284 if (idoflineadded > 0)
1286 console.log(
"Auto select "+idoflineadded);
1287 $(
'.posinvoiceline#'+idoflineadded).click();
1291if ($action ==
"order" && !empty($order_receipt_printer1)) {
1292 if (filter_var($conf->global->TAKEPOS_PRINT_SERVER, FILTER_VALIDATE_URL) ==
true) {
1296 url:
'<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>/printer/index.php',
1297 data:
'invoice='+orderprinter1esc
1304 url:
'http://<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>:8111/print',
1306 print $headerorder.$order_receipt_printer1.$footerorder; ?>'
1312if ($action ==
"order" && !empty($order_receipt_printer2)) {
1313 if (filter_var($conf->global->TAKEPOS_PRINT_SERVER, FILTER_VALIDATE_URL) ==
true) {
1317 url:
'<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>/printer/index.php?printer=2',
1318 data:
'invoice='+orderprinter2esc
1325 url:
'http://<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>:8111/print2',
1327 print $headerorder.$order_receipt_printer2.$footerorder; ?>'
1333if ($action ==
"order" && !empty($order_receipt_printer3)) {
1334 if (filter_var($conf->global->TAKEPOS_PRINT_SERVER, FILTER_VALIDATE_URL) ==
true) {
1338 url:
'<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>/printer/index.php?printer=3',
1339 data:
'invoice='+orderprinter3esc
1346if ($action ==
"search" || $action ==
"valid") {
1348 parent.setFocusOnSearchField();
1353if ($action ==
"temp" && !empty($ticket_printer1)) {
1357 url:
'http://<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>:8111/print',
1359 print $header_soc.$header_ticket.$body_ticket.$ticket_printer1.$ticket_total.$footer_ticket; ?>'
1364if ($action ==
"search") {
1366 $(
'#search').focus();
1374function SendTicket(
id)
1376 console.log(
"Open box to select the Print/Send form");
1377 $.colorbox({href:
"send.php?facid="+id, width:
"70%", height:
"30%", transition:
"none", iframe:
"true", title:
'<?php echo dol_escape_js($langs->trans("SendTicket")); ?>'});
1381function PrintBox(
id, action) {
1382 console.log(
"Open box before printing");
1383 $.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
"); ?>"});
1387function Print(
id, gift){
1388 console.log(
"Call Print() to generate the receipt.");
1389 $.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")); ?>'});
1393function TakeposPrinting(
id){
1395 console.log(
"TakeposPrinting" +
id);
1396 $.get(
"receipt.php?facid="+
id,
function(data,
status) {
1397 receipt=data.replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g,
'');
1400 url:
'http://<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER
'); ?>:8111/print',
1407function TakeposConnector(
id){
1408 console.log(
"TakeposConnector" +
id);
1409 $.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) {
1412 url:
'<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER
'); ?>/printer/index.php',
1413 data:
'invoice='+data
1419function DolibarrTakeposPrinting(
id) {
1420 console.log(
"DolibarrTakeposPrinting Printing invoice ticket " +
id)
1423 data: { token:
'<?php echo currentToken(); ?>' },
1424 url:
"<?php print DOL_URL_ROOT.'/takepos/ajax/ajax.php?action=printinvoiceticket&token='.newToken().'&term='.urlencode(isset($_SESSION["takeposterminal
"]) ? $_SESSION["takeposterminal
"] : '').'&id='; ?>" + id,
1429function CreditNote() {
1430 $(
"#poslines").load(
"invoice.php?action=creditnote&token=<?php echo newToken() ?>&invoiceid="+placeid,
function() { });
1435 $(
"#poslines").load(
"invoice.php?action=addnote&token=<?php echo newToken() ?>&invoiceid="+placeid+
"&idline="+selectedline, {
"addnote": $(
"#textinput").val() });
1440$( document ).ready(
function() {
1441 console.log(
"Set customer info and sales in header placeid=<?php echo $placeid; ?> status=<?php echo $invoice->statut; ?>");
1444 $s = $langs->trans(
"Customer");
1445 if ($invoice->id > 0 && ($invoice->socid !=
getDolGlobalString($constforcompanyid))) {
1448 $contactids = $invoice->getIdContact(
'external',
'BILLING');
1449 $contactid = $contactids[0];
1450 if ($contactid > 0) {
1452 $contact->fetch($contactid);
1453 $s .=
" - " . $contact->getFullName($langs);
1459 $(
"#customerandsales").html(
'');
1460 $(
"#shoppingcart").html(
'');
1463 $(
"#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>');
1465 $(
"#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>');
1469 $sql =
"SELECT rowid, datec, ref FROM ".MAIN_DB_PREFIX.
"facture";
1470 $sql .=
" WHERE entity IN (".getEntity(
'invoice').
")";
1473 $sql .=
" AND ref LIKE '(PROV-POS".$db->escape(isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'').
"-0%'";
1476 $sql .=
" AND pos_source = '".$db->escape($_SESSION[
"takeposterminal"]).
"'";
1477 $sql .=
" AND module_source = 'takepos'";
1480 $sql .= $db->order(
'datec',
'ASC');
1481 $resql = $db->query($sql);
1484 while ($obj = $db->fetch_object($resql)) {
1485 echo
'$("#shoppingcart").append(\'';
1486 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=\\\'';
1487 $num_sale = str_replace(
")",
"", str_replace(
"(PROV-POS".$_SESSION[
"takeposterminal"].
"-",
"", $obj->ref));
1489 if (str_replace(
"-",
"", $num_sale) > $max_sale) {
1490 $max_sale = str_replace(
"-",
"", $num_sale);
1492 echo
'\\\'; invoiceid=\\\'';
1494 echo
'\\\'; Refresh();">';
1495 if ($placeid == $obj->rowid) {
1496 echo
'<span class="basketselected">';
1498 echo
'<span class="basketnotselected">';
1500 echo
'<span class="fa fa-shopping-cart paddingright"></span>'.dol_print_date($db->jdate($obj->datec),
'%H:%M',
'tzuser');
1504 echo
'$("#shoppingcart").append(\'<a onclick="place=\\\'0-';
1506 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>\');';
1514 $constantforkey =
'CASHDESK_NO_DECREASE_STOCK'. (isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
1515 if (isModEnabled(
'stock')) {
1517 $constantforkey =
'CASHDESK_ID_WAREHOUSE'. (isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
1519 if ($idwarehouse > 0) {
1520 $s =
'<span class="small">';
1522 $warehouse->fetch($idwarehouse);
1523 $s .=
'<span class="hideonsmartphone">'.$langs->trans(
"Warehouse").
'<br></span>'.$warehouse->ref;
1525 $s .=
' ('.$langs->trans(
"Closed").
')';
1528 print
"$('#infowarehouse').html('".dol_escape_js($s).
"');";
1529 print
'$("#infowarehouse").css("display", "inline-block");';
1531 $s =
'<span class="small hideonsmartphone">';
1532 $s .= $langs->trans(
"StockChangeDisabled").
'<br>'.$langs->trans(
"NoWarehouseDefinedForTerminal");
1534 print
"$('#infowarehouse').html('".dol_escape_js($s).
"');";
1535 if (!empty($conf->dol_optimize_smallscreen)) {
1536 print
'$("#infowarehouse").css("display", "none");';
1540 $s =
'<span class="small hideonsmartphone">'.$langs->trans(
"StockChangeDisabled").
'</span>';
1541 print
"$('#infowarehouse').html('".dol_escape_js($s).
"');";
1542 if (!empty($conf->dol_optimize_smallscreen)) {
1543 print
'$("#infowarehouse").css("display", "none");';
1551 if (isModEnabled(
'adherent') && $invoice->socid > 0 && $invoice->socid !=
getDolGlobalInt($constforcompanyid)) {
1552 $s =
'<span class="small">';
1553 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
1554 $langs->load(
"members");
1555 $s .= $langs->trans(
"Member").
': ';
1557 $result = $adh->fetch(
'',
'', $invoice->socid);
1559 $adh->ref = $adh->getFullName($langs);
1563 $s .= $adh->getFullName($langs);
1564 $s .=
' - '.$adh->type;
1565 if ($adh->datefin) {
1566 $s .=
'<br>'.$langs->trans(
"SubscriptionEndDate").
': '.
dol_print_date($adh->datefin,
'day');
1567 if ($adh->hasDelay()) {
1568 $s .=
" ".img_warning($langs->trans(
"Late"));
1571 $s .=
'<br>'.$langs->trans(
"SubscriptionNotReceived");
1572 if ($adh->statut > 0) {
1573 $s .=
" ".img_warning($langs->trans(
"Late"));
1580 $s .=
'<br>'.$langs->trans(
"ThirdpartyNotLinkedToMember");
1585 $(
"#moreinfo").html(
'<?php print dol_escape_js($s); ?>');
1592 echo
"function CustomerDisplay(){";
1593 echo
"var line1='".$CUSTOMER_DISPLAY_line1.
"'.substring(0,20);";
1594 echo
"line1=line1.padEnd(20);";
1595 echo
"var line2='".$CUSTOMER_DISPLAY_line2.
"'.substring(0,20);";
1596 echo
"line2=line2.padEnd(20);";
1599 data: { text: line1+line2 },
1600 url: '".getDolGlobalString(
'TAKEPOS_PRINT_SERVER').
"/display/index.php',
1611if (!empty($conf->use_javascript_ajax)) {
1612 print
"\n".
'<!-- Includes JS Footer of Dolibarr -->'.
"\n";
1613 print
'<script src="'.DOL_URL_ROOT.
'/core/js/lib_foot.js.php?lang='.$langs->defaultlang.
'"></script>'.
"\n";