33 if (!defined(
'NOTOKENRENEWAL')) {
34 define(
'NOTOKENRENEWAL',
'1');
36 if (!defined(
'NOREQUIREMENU')) {
37 define(
'NOREQUIREMENU',
'1');
39 if (!defined(
'NOREQUIREHTML')) {
40 define(
'NOREQUIREHTML',
'1');
42 if (!defined(
'NOREQUIREAJAX')) {
43 define(
'NOREQUIREAJAX',
'1');
47 if (!defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
48 require
'../main.inc.php';
50 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
51 require_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
52 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
53 require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
54 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
56 $hookmanager->initHooks(array(
'takeposinvoice'));
58 $langs->loadLangs(array(
"companies",
"commercial",
"bills",
"cashdesk",
"stocks",
"banks"));
60 $action =
GETPOST(
'action',
'aZ09');
62 $place = (
GETPOST(
'place',
'aZ09') ?
GETPOST(
'place',
'aZ09') : 0);
64 $mobilepage =
GETPOST(
'mobilepage',
'alpha');
68 if (!$user->hasRight(
'takepos',
'run') && !defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
72 if ((
getDolGlobalString(
'TAKEPOS_PHONE_BASIC_LAYOUT') == 1 && $conf->browser->layout ==
'phone') || defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
74 if ($_SESSION[
"takeposterminal"] ==
"") {
76 $_SESSION[
"takeposterminal"] = 1;
78 header(
"Location: ".DOL_URL_ROOT.
"/takepos/index.php");
84 $takeposterminal = isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'';
94 header($_SERVER[
'SERVER_PROTOCOL'].
' 500 Internal Server Error',
true, 500);
100 $number =
GETPOST(
'number',
'alpha');
103 $desc =
GETPOST(
'desc',
'alphanohtml');
110 if ($pay ==
'cash') {
113 if ($pay ==
'card') {
116 if ($pay ==
'cheque') {
123 $sql =
"SELECT id FROM ".MAIN_DB_PREFIX.
"c_paiement";
124 $sql .=
" WHERE entity IN (".getEntity(
'c_paiement').
")";
125 $sql .=
" AND code = '".$db->escape($paycode).
"'";
126 $resql = $db->query(
$sql);
128 $obj = $db->fetch_object($resql);
130 $paiementid = $obj->id;
136 if ($invoiceid > 0) {
137 $ret = $invoice->fetch($invoiceid);
139 $ret = $invoice->fetch(
'',
'(PROV-POS'.$takeposterminal.
'-'.$place.
')');
142 $placeid = $invoice->id;
145 $constforcompanyid =
'CASHDESK_ID_THIRDPARTY'.$takeposterminal;
148 if ($invoice->socid > 0) {
149 $soc->fetch($invoice->socid);
156 $invoice->fk_project =
getDolGlobalInt(
"CASHDESK_ID_PROJECT".$takeposterminal);
160 if (
isModEnabled(
'multicurrency') && !empty($_SESSION[
"takeposcustomercurrency"])) {
161 if ($invoice->multicurrency_code != $_SESSION[
"takeposcustomercurrency"]) {
162 $invoice->setMulticurrencyCode($_SESSION[
"takeposcustomercurrency"]);
166 $term = empty($_SESSION[
"takeposterminal"]) ? 1 : $_SESSION[
"takeposterminal"];
173 $parameters = array();
174 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $invoice, $action);
179 if (empty($reshook)) {
181 if ($action ==
'valid' && $user->hasRight(
'facture',
'creer')) {
189 $bankaccount =
getDolGlobalInt(
'CASHDESK_ID_BANKACCOUNT_CASH'.$_SESSION[
"takeposterminal"]);
190 } elseif ($pay ==
"CHQ") {
191 $bankaccount =
getDolGlobalInt(
'CASHDESK_ID_BANKACCOUNT_CHEQUE'.$_SESSION[
"takeposterminal"]);
193 $accountname =
"CASHDESK_ID_BANKACCOUNT_".$pay.$_SESSION[
"takeposterminal"];
198 if ($bankaccount <= 0 && $pay !=
"delayed" &&
isModEnabled(
"bank")) {
199 $errormsg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"BankAccount"));
207 $invoice->fetch($placeid);
211 if ($invoice->total_ttc < 0) {
212 $invoice->type = $invoice::TYPE_CREDIT_NOTE;
214 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"facture";
215 $sql .=
" WHERE entity IN (".getEntity(
'invoice').
")";
216 $sql .=
" AND fk_soc = ".((int) $invoice->socid);
217 $sql .=
" AND type <> ".Facture::TYPE_CREDIT_NOTE;
218 $sql .=
" AND fk_statut >= ".$invoice::STATUS_VALIDATED;
219 $sql .=
" ORDER BY rowid DESC";
221 $resql = $db->query(
$sql);
223 $obj = $db->fetch_object($resql);
224 $fk_source = $obj->rowid;
225 if ($fk_source ==
null) {
226 fail($langs->transnoentitiesnoconv(
"NoPreviousBillForCustomer"));
229 fail($langs->transnoentitiesnoconv(
"NoPreviousBillForCustomer"));
231 $invoice->fk_facture_source = $fk_source;
232 $invoice->update($user);
235 $constantforkey =
'CASHDESK_NO_DECREASE_STOCK'.(isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
240 if ($invoice->getRemainToPay() > 0) {
246 } elseif (count($invoice->lines) == 0) {
256 $conf->global->STOCK_CALCULATE_ON_BILL = 0;
259 $conf->global->STOCK_CALCULATE_ON_BILL = 1;
262 $constantforkey =
'CASHDESK_ID_WAREHOUSE'.$_SESSION[
"takeposterminal"];
263 dol_syslog(
"Validate invoice with stock change into warehouse defined into constant ".$constantforkey.
" = ".
getDolGlobalString($constantforkey));
267 require_once DOL_DOCUMENT_ROOT.
'/product/class/productbatch.class.php';
270 $res = $invoice->validate($user,
'',
getDolGlobalInt($constantforkey), 0, $batch_rule);
272 $conf->global->STOCK_CALCULATE_ON_BILL = $savconst;
275 $res = $invoice->validate($user);
278 $langs->load(
"admin");
279 dol_htmloutput_errors($invoice->error ==
'NotConfigured' ? $langs->trans(
"NotConfigured").
' (TakePos numbering module)' : $invoice->error, $invoice->errors, 1);
284 if (!$error && $res >= 0) {
285 $remaintopay = $invoice->getRemainToPay();
286 if ($remaintopay > 0) {
288 $payment->datepaye = $now;
289 $payment->fk_account = $bankaccount;
290 $payment->amounts[$invoice->id] = $amountofpayment;
297 if ($amountofpayment <= 0 || $amountofpayment > $remaintopay) {
298 $payment->amounts[$invoice->id] = $remaintopay;
301 $payment->paiementid = $paiementid;
302 $payment->num_payment = $invoice->ref;
304 if ($pay !=
"delayed") {
305 $payment->create($user);
306 $res = $payment->addPaymentToBank($user,
'payment',
'(CustomerInvoicePayment)', $bankaccount,
'',
'');
311 $remaintopay = $invoice->getRemainToPay();
317 if ($remaintopay == 0) {
318 dol_syslog(
"Invoice is paid, so we set it to status Paid");
319 $result = $invoice->setPaid($user);
324 $invoice->setPaymentMethods($paiementid);
326 dol_syslog(
"Invoice is not paid, remain to pay = ".$remaintopay);
333 if (!$error && $res >= 0) {
335 require_once DOL_DOCUMENT_ROOT .
"/product/stock/class/mouvementstock.class.php";
336 $constantforkey =
'CASHDESK_ID_WAREHOUSE'.$_SESSION[
"takeposterminal"];
338 $labeltakeposmovement =
'TakePOS - '.$langs->trans(
"Invoice").
' '.$invoice->ref;
340 foreach ($invoice->lines as $line) {
341 $warehouseid = ($line->fk_warehouse ? $line->fk_warehouse :
getDolGlobalInt($constantforkey));
344 if ($line->batch !=
'' && $warehouseid > 0) {
346 $prod_batch->find(0,
'',
'', $line->batch, $warehouseid);
348 $mouvP->origin = $invoice;
349 $res = $mouvP->livraison($user, $line->fk_product, $warehouseid, $line->qty, $line->price, $labeltakeposmovement,
'',
'',
'', $prod_batch->batch, $prod_batch->id, $inventorycode);
356 $mouvP->origin = $invoice;
357 $res = $mouvP->livraison($user, $line->fk_product, $warehouseid, $line->qty, $line->price, $labeltakeposmovement,
'',
'',
'',
'', 0, $inventorycode);
367 if (!$error && $res >= 0) {
373 if ($action ==
'creditnote' && $user->hasRight(
'facture',
'creer')) {
376 $creditnote =
new Facture($db);
377 $creditnote->socid = $invoice->socid;
379 $creditnote->module_source =
'takepos';
380 $creditnote->pos_source = isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'' ;
382 $creditnote->fk_facture_source = $placeid;
385 $creditnote->create($user);
387 foreach ($invoice->lines as $line) {
389 if (method_exists($line,
'fetch_optionals')) {
391 $line->fetch_optionals();
394 if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) {
399 if (!empty($invoice->situation_counter)) {
400 $source_fk_prev_id = $line->fk_prev_id;
401 $line->fk_prev_id = $line->id;
402 if (!empty($invoice->tab_previous_situation_invoice)) {
405 $tab_jumped_credit_notes = array();
406 $lineIndex = count($invoice->tab_previous_situation_invoice) - 1;
407 $searchPreviousInvoice =
true;
408 while ($searchPreviousInvoice) {
409 if ($invoice->tab_previous_situation_invoice[$lineIndex]->situation_cycle_ref || $lineIndex < 1) {
410 $searchPreviousInvoice =
false;
414 $tab_jumped_credit_notes[$lineIndex] = $invoice->tab_previous_situation_invoice[$lineIndex]->id;
420 $maxPrevSituationPercent = 0;
421 foreach ($invoice->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine) {
422 if ($prevLine->id == $source_fk_prev_id) {
423 $maxPrevSituationPercent = max($maxPrevSituationPercent, $prevLine->situation_percent);
426 $line->total_ht = $line->total_ht - $prevLine->total_ht;
427 $line->total_tva = $line->total_tva - $prevLine->total_tva;
428 $line->total_ttc = $line->total_ttc - $prevLine->total_ttc;
429 $line->total_localtax1 = $line->total_localtax1 - $prevLine->total_localtax1;
430 $line->total_localtax2 = $line->total_localtax2 - $prevLine->total_localtax2;
432 $line->multicurrency_subprice = $line->multicurrency_subprice - $prevLine->multicurrency_subprice;
433 $line->multicurrency_total_ht = $line->multicurrency_total_ht - $prevLine->multicurrency_total_ht;
434 $line->multicurrency_total_tva = $line->multicurrency_total_tva - $prevLine->multicurrency_total_tva;
435 $line->multicurrency_total_ttc = $line->multicurrency_total_ttc - $prevLine->multicurrency_total_ttc;
440 $line->situation_percent = $maxPrevSituationPercent - $line->situation_percent;
445 $maxPrevSituationPercent = 0;
446 foreach ($tab_jumped_credit_notes as $index => $creditnoteid) {
447 foreach ($invoice->tab_previous_situation_invoice[$index]->lines as $prevLine) {
448 if ($prevLine->fk_prev_id == $source_fk_prev_id) {
449 $maxPrevSituationPercent = $prevLine->situation_percent;
451 $line->total_ht -= $prevLine->total_ht;
452 $line->total_tva -= $prevLine->total_tva;
453 $line->total_ttc -= $prevLine->total_ttc;
454 $line->total_localtax1 -= $prevLine->total_localtax1;
455 $line->total_localtax2 -= $prevLine->total_localtax2;
457 $line->multicurrency_subprice -= $prevLine->multicurrency_subprice;
458 $line->multicurrency_total_ht -= $prevLine->multicurrency_total_ht;
459 $line->multicurrency_total_tva -= $prevLine->multicurrency_total_tva;
460 $line->multicurrency_total_ttc -= $prevLine->multicurrency_total_ttc;
466 $line->situation_percent += $maxPrevSituationPercent;
473 $line->fk_facture = $creditnote->id;
474 $line->fk_parent_line = $fk_parent_line;
476 $line->subprice = -$line->subprice;
478 $line->total_ht = -$line->total_ht;
479 $line->total_tva = -$line->total_tva;
480 $line->total_ttc = -$line->total_ttc;
481 $line->total_localtax1 = -$line->total_localtax1;
482 $line->total_localtax2 = -$line->total_localtax2;
484 $line->multicurrency_subprice = -$line->multicurrency_subprice;
485 $line->multicurrency_total_ht = -$line->multicurrency_total_ht;
486 $line->multicurrency_total_tva = -$line->multicurrency_total_tva;
487 $line->multicurrency_total_ttc = -$line->multicurrency_total_ttc;
489 $result = $line->insert(0, 1);
491 $creditnote->lines[] = $line;
494 if ($result > 0 && $line->product_type == 9) {
495 $fk_parent_line = $result;
498 $creditnote->update_price(1);
500 $constantforkey =
'CASHDESK_NO_DECREASE_STOCK'.(isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
503 $conf->global->STOCK_CALCULATE_ON_BILL = 1;
504 $constantforkey =
'CASHDESK_ID_WAREHOUSE'.(isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
505 dol_syslog(
"Validate invoice with stock change into warehouse defined into constant ".$constantforkey.
" = ".
getDolGlobalString($constantforkey));
508 require_once DOL_DOCUMENT_ROOT.
'/product/class/productbatch.class.php';
511 $res = $creditnote->validate($user,
'',
getDolGlobalString($constantforkey), 0, $batch_rule);
512 $conf->global->STOCK_CALCULATE_ON_BILL = $savconst;
514 $res = $creditnote->validate($user);
517 if (!$error && $res >= 0) {
524 if (($action ==
'history' || $action ==
'creditnote') && $user->hasRight(
'takepos',
'run')) {
525 if ($action ==
'creditnote') {
526 $placeid = $creditnote->id;
531 $invoice->fetch($placeid);
535 if (($action ==
"addline" || $action ==
"freezone") && $placeid == 0 && ($user->hasRight(
'takepos',
'run') || defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
537 $invoice->date =
dol_now(
'tzuserrel');
538 $invoice->module_source =
'takepos';
539 $invoice->pos_source = isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'' ;
540 $invoice->entity = !empty($_SESSION[
"takeposinvoiceentity"]) ? $_SESSION[
"takeposinvoiceentity"] : $conf->entity;
542 if ($invoice->socid <= 0) {
543 $langs->load(
'errors');
549 $placeid = $invoice->create($user);
553 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facture set ref='(PROV-POS".$_SESSION[
"takeposterminal"].
"-".$place.
")' where rowid = ".((int) $placeid);
554 $resql = $db->query(
$sql);
568 if ($action ==
"addline" && ($user->hasRight(
'takepos',
'run') || defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
570 $prod->fetch($idproduct);
573 $customer->fetch($invoice->socid);
575 $datapriceofproduct = $prod->getSellPrice($mysoc, $customer, 0);
578 $price = $datapriceofproduct[
'pu_ht'];
579 $price_ttc = $datapriceofproduct[
'pu_ttc'];
581 $price_base_type = empty($datapriceofproduct[
'price_base_type']) ?
'HT' : $datapriceofproduct[
'price_base_type'];
582 $tva_tx = $datapriceofproduct[
'tva_tx'];
583 $tva_npr = $datapriceofproduct[
'tva_npr'];
586 $localtax1_tx =
get_localtax($tva_tx, 1, $customer, $mysoc, $tva_npr);
587 $localtax2_tx =
get_localtax($tva_tx, 2, $customer, $mysoc, $tva_npr);
591 $batch =
GETPOST(
'batch',
'alpha');
593 if (!empty($batch)) {
594 $action =
"setbatch";
595 } elseif ($prod->status_batch > 0) {
600 $prod->load_stock(
'warehouseopen');
602 $constantforkey =
'CASHDESK_ID_WAREHOUSE'.$_SESSION[
"takeposterminal"];
606 foreach ($prod->stock_warehouse as $tmpwarehouseid => $tmpval) {
611 if (!empty($prod->stock_warehouse[$tmpwarehouseid]) && is_array($prod->stock_warehouse[$tmpwarehouseid]->detail_batch)) {
612 if (is_object($prod->stock_warehouse[$tmpwarehouseid]) && count($prod->stock_warehouse[$tmpwarehouseid]->detail_batch)) {
613 foreach ($prod->stock_warehouse[$tmpwarehouseid]->detail_batch as $dbatch) {
622 echo
"function addbatch(batch, warehouseid) {\n";
623 echo
"console.log('We add batch '+batch+' from warehouse id '+warehouseid);\n";
624 echo
'$("#poslines").load("invoice.php?action=addline&batch="+batch+"&warehouseid="+warehouseid+"&place='.$place.
'&idproduct='.$idproduct.
'&token='.
newToken().
'", function() {});'.
"\n";
629 echo
"<center>".$langs->trans(
"SearchIntoBatch").
": <b> $nbofsuggested </b></center><br><table>";
630 foreach ($prod->stock_warehouse as $tmpwarehouseid => $tmpval) {
635 if (!empty($prod->stock_warehouse[$tmpwarehouseid]) && is_array($prod->stock_warehouse[$tmpwarehouseid]->detail_batch)) {
636 foreach ($prod->stock_warehouse[$tmpwarehouseid]->detail_batch as $dbatch) {
637 $batchStock = + $dbatch->qty;
638 $quantityToBeDelivered = 1;
639 $deliverableQty = min($quantityToBeDelivered, $batchStock);
641 print
'<!-- subj='.$suggestednb.
'/'.$nbofsuggested.
' -->';
642 print
'<!-- Show details of lot -->';
643 print
'<td class="left">';
645 $detail .=
'<span class="opacitymedium">'.$langs->trans(
"LotSerial").
':</span> '.$dbatch->batch;
652 $detail .=
'</td><td>';
653 $detail .=
'<span class="opacitymedium">'.$langs->trans(
"Qty").
':</span> '.$dbatch->qty;
654 $detail .=
'</td><td>';
655 $detail .=
' <button class="marginleftonly" onclick="addbatch(\''.dol_escape_js($dbatch->batch).
'\',
'.$tmpwarehouseid.')
">'.$langs->trans("Select
")."</
button>
";
659 $quantityToBeDelivered -= $deliverableQty;
660 if ($quantityToBeDelivered < 0) {
661 $quantityToBeDelivered = 0;
670 print '</body></html>';
676 if (getDolGlobalString('TAKEPOS_SUPPLEMENTS')) {
677 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
678 $cat = new Categorie($db);
679 $categories = $cat->containing($idproduct, 'product');
680 $found = (array_search(getDolGlobalInt('TAKEPOS_SUPPLEMENTS_CATEGORY'), array_column($categories, 'id')));
681 if ($found !== false) { // If this product is a supplement
682 $sql = "SELECT fk_parent_line FROM
".MAIN_DB_PREFIX."facturedet where
rowid =
".((int) $selectedline);
683 $resql = $db->query($sql);
684 $row = $db->fetch_array($resql);
685 if ($row[0] == null) {
686 $parent_line = $selectedline;
688 $parent_line = $row[0]; //If the parent line is already a supplement, add the supplement to the main product
695 // Group if enabled. Skip group if line already sent to the printer
696 if (getDolGlobalString('TAKEPOS_GROUP_SAME_PRODUCT')) {
697 foreach ($invoice->lines as $line) {
698 if ($line->product_ref == $prod->ref) {
699 if ($line->special_code == 4) {
701 } // If this line is sended to printer create new line
702 // check if qty in stock
703 if (getDolGlobalString('TAKEPOS_QTY_IN_STOCK') && (($line->qty + $qty) > $prod->stock_reel)) {
704 $invoice->error = $langs->trans("ErrorStockIsNotEnough
");
705 dol_htmloutput_errors($invoice->error, $invoice->errors, 1);
709 $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);
711 dol_htmloutput_errors($invoice->error, $invoice->errors, 1);
713 $idoflineadded = $line->id;
719 if ($idoflineadded <= 0 && empty($err)) {
720 $invoice->fetch_thirdparty();
721 $array_options = array();
723 $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);
725 /* setup of margin calculation */
726 if (isset($conf->global->MARGIN_TYPE)) {
727 if (getDolGlobalString('MARGIN_TYPE') == 'pmp' && !empty($prod->pmp)) {
728 $line['fk_fournprice'] = null;
729 $line['pa_ht'] = $prod->pmp;
730 } elseif (getDolGlobalString('MARGIN_TYPE') == 'costprice' && !empty($prod->cost_price)) {
731 $line['fk_fournprice'] = null;
732 $line['pa_ht'] = $prod->cost_price;
734 // default is fournprice
735 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
736 $pf = new ProductFournisseur($db);
737 if ($pf->find_min_price_product_fournisseur($idproduct, $qty) > 0) {
738 $line['fk_fournprice'] = $pf->product_fourn_price_id;
739 $line['pa_ht'] = $pf->fourn_unitprice_with_discount;
740 if (getDolGlobalString('PRODUCT_CHARGES') && $pf->fourn_charges > 0) {
741 $line['pa_ht'] += $pf->fourn_charges / $pf->fourn_qty;
747 // complete line by hook
748 $parameters = array('prod' => $prod, 'line' => $line);
749 $reshook = $hookmanager->executeHooks('completeTakePosAddLine', $parameters, $invoice, $action); // Note that $action and $line may have been modified by some hooks
751 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
755 if (empty($reshook)) {
756 if (!empty($hookmanager->resArray)) {
757 $line = $hookmanager->resArray;
760 // check if qty in stock
761 if (getDolGlobalString('TAKEPOS_QTY_IN_STOCK') && $qty > $prod->stock_reel) {
762 $invoice->error = $langs->trans("ErrorStockIsNotEnough
");
763 dol_htmloutput_errors($invoice->error, $invoice->errors, 1);
768 $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);
772 if (getDolGlobalString('TAKEPOS_CUSTOMER_DISPLAY')) {
773 $CUSTOMER_DISPLAY_line1 = $prod->label;
774 $CUSTOMER_DISPLAY_line2 = price($price_ttc);
778 $invoice->fetch($placeid);
781 // If we add a line by submitting freezone form (invoice exists here because it was created juste before if it didn't exists)
782 if ($action == "freezone
" && $user->hasRight('takepos', 'run')) {
783 $customer = new Societe($db);
784 $customer->fetch($invoice->socid);
786 $tva_tx = GETPOST('tva_tx', 'alpha');
788 if (!preg_match('/\((.*)\)/', $tva_tx)) {
789 $tva_tx = price2num($tva_tx);
792 $tva_tx = get_default_tva($mysoc, $customer);
796 $localtax1_tx = get_localtax($tva_tx, 1, $customer, $mysoc, $tva_npr);
797 $localtax2_tx = get_localtax($tva_tx, 2, $customer, $mysoc, $tva_npr);
799 $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);
801 dol_htmloutput_errors($invoice->error, $invoice->errors, 1);
803 $invoice->fetch($placeid);
806 if ($action == "addnote
" && ($user->hasRight('takepos', 'run') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
807 $desc = GETPOST('addnote', 'alpha');
809 $invoice->update_note($desc, '_public');
811 foreach ($invoice->lines as $line) {
812 if ($line->id == $idline) {
813 $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);
817 $invoice->fetch($placeid);
820 if ($action == "deleteline
" && ($user->hasRight('takepos', 'run') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
822 $permissiontoupdateline = ($user->hasRight('takepos', 'editlines') && ($user->hasRight('takepos', 'editorderedlines') || $line->special_code != "4
"));
823 if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
824 if ($invoice->status == $invoice::STATUS_DRAFT && $invoice->pos_source && $invoice->module_source == 'takepos') {
825 $permissiontoupdateline = true;
826 // TODO Add also a test on $_SESSION('publicobjectid'] defined at creation of object
827 // TODO Check also that invoice->ref is (PROV-POS1-2) with 1 = terminal and 2, the invoice ID
831 if ($idline > 0 && $placeid > 0) { // If invoice exists and line selected. To avoid errors if deleted from another device or no line selected.
832 $invoice->deleteLine($idline);
833 $invoice->fetch($placeid);
834 } elseif ($placeid > 0) { // If invoice exists but no line selected, proceed to delete last line.
835 $sql = "SELECT
rowid FROM
".MAIN_DB_PREFIX."facturedet where fk_facture =
".((int) $placeid)." ORDER BY
rowid DESC
";
836 $resql = $db->query($sql);
837 $row = $db->fetch_array($resql);
838 $deletelineid = $row[0];
839 $invoice->deleteLine($deletelineid);
840 $invoice->fetch($placeid);
843 if (count($invoice->lines) == 0) {
844 $invoice->delete($user);
846 if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
847 header("Location:
".DOL_URL_ROOT."/takepos/
public/auto_order.php
");
849 header("Location:
".DOL_URL_ROOT."/takepos/invoice.php
");
855 // Action to delete or discard an invoice
856 if ($action == "delete" && ($user->hasRight('takepos', 'run') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
857 // $placeid is the invoice id (it differs from place) and is defined if the place is set and the ref of invoice is '(PROV-POS'.$_SESSION["takeposterminal
"].'-'.$place.')', so the fetch at beginning of page works.
859 $result = $invoice->fetch($placeid);
861 if ($result > 0 && $invoice->statut == Facture::STATUS_DRAFT) {
864 // We delete the lines
866 foreach ($invoice->lines as $line) {
867 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
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 $result = $invoice->updateline($line->id, $line->desc, $line->subprice, $number, $line->remise_percent, $line->date_start, $line->date_end, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, 'HT', $line->info_bits, $line->product_type, $line->fk_parent_line, 0, $line->fk_fournprice, $line->pa_ht, $line->label, $line->special_code, $line->array_options, $line->situation_percent, $line->fk_unit);
913 $invoice->fetch($placeid);
916 if ($action == "updateprice
") { // Test on permission is done later
917 $customer = new Societe($db);
918 $customer->fetch($invoice->socid);
920 foreach ($invoice->lines as $line) {
921 if ($line->id == $idline) {
922 $prod = new Product($db);
923 $prod->fetch($line->fk_product);
924 $datapriceofproduct = $prod->getSellPrice($mysoc, $customer, 0);
925 $price_min = $datapriceofproduct['price_min'];
926 $usercanproductignorepricemin = ((getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !$user->hasRight('produit', 'ignore_price_min_advance')) || !getDolGlobalString('MAIN_USE_ADVANCED_PERMS'));
927 $pu_ht = price2num($number / (1 + ($line->tva_tx / 100)), 'MU');
929 if ($usercanproductignorepricemin && (!empty($price_min) && (price2num($pu_ht) * (1 - price2num($line->remise_percent) / 100) < price2num($price_min)))) {
930 $langs->load("products
");
931 dol_htmloutput_errors($langs->trans("CantBeLessThanMinPrice
", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, -1, $conf->currency)));
932 //echo $langs->trans("CantBeLessThanMinPrice
");
934 $permissiontoupdateline = ($user->hasRight('takepos', 'editlines') && ($user->hasRight('takepos', 'editorderedlines') || $line->special_code != "4
"));
935 if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
936 if ($invoice->status == $invoice::STATUS_DRAFT && $invoice->pos_source && $invoice->module_source == 'takepos') {
937 $permissiontoupdateline = true;
938 // TODO Add also a test on $_SESSION('publicobjectid'] defined at creation of object
939 // TODO Check also that invoice->ref is (PROV-POS1-2) with 1 = terminal and 2, the invoice ID
942 if (!$permissiontoupdateline) {
943 dol_htmloutput_errors($langs->trans("NotEnoughPermissions
", "TakePos
").' - No permission to updateprice', null, 1);
944 } elseif (getDolGlobalInt('TAKEPOS_CHANGE_PRICE_HT') == 1) {
945 $result = $invoice->updateline($line->id, $line->desc, $number, $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);
947 $result = $invoice->updateline($line->id, $line->desc, $number, $line->qty, $line->remise_percent, $line->date_start, $line->date_end, $line->tva_tx, $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);
954 $invoice->fetch($placeid);
957 if ($action == "updatereduction
") { // Test on permission is done later
958 $customer = new Societe($db);
959 $customer->fetch($invoice->socid);
961 foreach ($invoice->lines as $line) {
962 if ($line->id == $idline) {
963 dol_syslog("updatereduction Process line
".$line->id.' to apply discount of '.$number.'%');
965 $prod = new Product($db);
966 $prod->fetch($line->fk_product);
968 $datapriceofproduct = $prod->getSellPrice($mysoc, $customer, 0);
969 $price_min = $datapriceofproduct['price_min'];
970 $usercanproductignorepricemin = ((getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !$user->hasRight('produit', 'ignore_price_min_advance')) || !getDolGlobalString('MAIN_USE_ADVANCED_PERMS'));
972 $pu_ht = price2num($line->subprice / (1 + ($line->tva_tx / 100)), 'MU');
975 if ($usercanproductignorepricemin && (!empty($price_min) && (price2num($line->subprice) * (1 - price2num($number) / 100) < price2num($price_min)))) {
976 $langs->load("products
");
977 dol_htmloutput_errors($langs->trans("CantBeLessThanMinPrice
", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, -1, $conf->currency)));
979 $permissiontoupdateline = ($user->hasRight('takepos', 'editlines') && ($user->hasRight('takepos', 'editorderedlines') || $line->special_code != "4
"));
980 if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
981 if ($invoice->status == $invoice::STATUS_DRAFT && $invoice->pos_source && $invoice->module_source == 'takepos') {
982 $permissiontoupdateline = true;
983 // TODO Add also a test on $_SESSION('publicobjectid'] defined at creation of object
984 // TODO Check also that invoice->ref is (PROV-POS1-2) with 1 = terminal and 2, the invoice ID
987 if (!$permissiontoupdateline) {
988 dol_htmloutput_errors($langs->trans("NotEnoughPermissions
", "TakePos
"), null, 1);
990 $result = $invoice->updateline($line->id, $line->desc, $line->subprice, $line->qty, $number, $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);
997 $invoice->fetch($placeid);
998 } elseif ($action == 'update_reduction_global' && $user->hasRight('takepos', 'editlines')) {
999 foreach ($invoice->lines as $line) {
1000 $result = $invoice->updateline($line->id, $line->desc, $line->subprice, $line->qty, $number, $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);
1003 $invoice->fetch($placeid);
1006 if ($action == "setbatch
" && ($user->hasRight('takepos', 'run') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
1007 $constantforkey = 'CASHDESK_ID_WAREHOUSE'.$_SESSION["takeposterminal
"];
1008 $warehouseid = getDolGlobalInt($constantforkey); // TODO Get the wrehouse id from GETPOSTINT('warehouseid');
1009 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet SET batch =
'".$db->escape($batch)."', fk_warehouse =
".((int) $warehouseid);
1010 $sql .= " WHERE
rowid=
".((int) $idoflineadded);
1014 if ($action == "order
" && $placeid != 0 && ($user->hasRight('takepos', 'run') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
1015 include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
1016 if ((isModEnabled('receiptprinter') && getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term) > 0) || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter
" || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector
") {
1017 require_once DOL_DOCUMENT_ROOT.'/core/class/dolreceiptprinter.class.php';
1018 $printer = new dolReceiptPrinter($db);
1021 $sql = "SELECT label FROM
".MAIN_DB_PREFIX."takepos_floor_tables where
rowid=
".((int) $place);
1022 $resql = $db->query($sql);
1023 $row = $db->fetch_object($resql);
1024 $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>';
1025 $footerorder = '</tbody></table>'.dol_print_date(dol_now(), 'dayhour').'<br></html>';
1026 $order_receipt_printer1 = "";
1027 $order_receipt_printer2 = "";
1028 $order_receipt_printer3 = "";
1029 $catsprinter1 = explode(';', getDolGlobalString('TAKEPOS_PRINTED_CATEGORIES_1'));
1030 $catsprinter2 = explode(';', getDolGlobalString('TAKEPOS_PRINTED_CATEGORIES_2'));
1031 $catsprinter3 = explode(';', getDolGlobalString('TAKEPOS_PRINTED_CATEGORIES_3'));
1033 foreach ($invoice->lines as $line) {
1034 if ($line->special_code == "4
") {
1037 $c = new Categorie($db);
1038 $existing = $c->containing($line->fk_product, Categorie::TYPE_PRODUCT, 'id');
1039 $result = array_intersect($catsprinter1, $existing);
1040 $count = count($result);
1041 if (!$line->fk_product) {
1042 $count++; // Print Free-text item (Unassigned printer) to Printer 1
1046 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet
set special_code=
'1' where
rowid=
".$line->id; //Set to print on printer 1
1048 $order_receipt_printer1 .= '<tr><td class="left
">';
1049 if ($line->fk_product) {
1050 $order_receipt_printer1 .= $line->product_label;
1052 $order_receipt_printer1 .= $line->description;
1054 $order_receipt_printer1 .= '</td><td class="right
">'.$line->qty;
1055 if (!empty($line->array_options['options_order_notes'])) {
1056 $order_receipt_printer1 .= "<br>(
".$line->array_options['options_order_notes'].")
";
1058 $order_receipt_printer1 .= '</td></tr>';
1061 if (((isModEnabled('receiptprinter') && getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term) > 0) || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter
" || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector
") && $linestoprint > 0) {
1062 $invoice->fetch($placeid); //Reload object before send to printer
1063 $printer->orderprinter = 1;
1065 echo "var orderprinter1esc=
'";
1066 $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
1069 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet
set special_code=
'4' where special_code=
'1' and fk_facture=
".$invoice->id; // Set as printed
1071 $invoice->fetch($placeid); //Reload object after set lines as printed
1074 foreach ($invoice->lines as $line) {
1075 if ($line->special_code == "4
") {
1078 $c = new Categorie($db);
1079 $existing = $c->containing($line->fk_product, Categorie::TYPE_PRODUCT, 'id');
1080 $result = array_intersect($catsprinter2, $existing);
1081 $count = count($result);
1084 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet
set special_code=
'2' where
rowid=
".$line->id; //Set to print on printer 2
1086 $order_receipt_printer2 .= '<tr>'.$line->product_label.'<td class="right
">'.$line->qty;
1087 if (!empty($line->array_options['options_order_notes'])) {
1088 $order_receipt_printer2 .= "<br>(
".$line->array_options['options_order_notes'].")
";
1090 $order_receipt_printer2 .= '</td></tr>';
1093 if (((isModEnabled('receiptprinter') && getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term) > 0) || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter
" || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector
") && $linestoprint > 0) {
1094 $invoice->fetch($placeid); //Reload object before send to printer
1095 $printer->orderprinter = 2;
1097 echo "var orderprinter2esc=
'";
1098 $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
1101 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet
set special_code=
'4' where special_code=
'2' and fk_facture=
".$invoice->id; // Set as printed
1103 $invoice->fetch($placeid); //Reload object after set lines as printed
1106 foreach ($invoice->lines as $line) {
1107 if ($line->special_code == "4
") {
1110 $c = new Categorie($db);
1111 $existing = $c->containing($line->fk_product, Categorie::TYPE_PRODUCT, 'id');
1112 $result = array_intersect($catsprinter3, $existing);
1113 $count = count($result);
1116 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet
set special_code=
'3' where
rowid=
".$line->id; //Set to print on printer 3
1118 $order_receipt_printer3 .= '<tr>'.$line->product_label.'<td class="right
">'.$line->qty;
1119 if (!empty($line->array_options['options_order_notes'])) {
1120 $order_receipt_printer3 .= "<br>(
".$line->array_options['options_order_notes'].")
";
1122 $order_receipt_printer3 .= '</td></tr>';
1125 if (((isModEnabled('receiptprinter') && getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term) > 0) || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter
" || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector
") && $linestoprint > 0) {
1126 $invoice->fetch($placeid); //Reload object before send to printer
1127 $printer->orderprinter = 3;
1129 echo "var orderprinter3esc=
'";
1130 $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
1133 $sql = "UPDATE
".MAIN_DB_PREFIX."facturedet
set special_code=
'4' where special_code=
'3' and fk_facture=
".$invoice->id; // Set as printed
1135 $invoice->fetch($placeid); //Reload object after set lines as printed
1138 $sectionwithinvoicelink = '';
1139 if (($action == "valid
" || $action == "history
" || $action == 'creditnote') && $user->hasRight('takepos', 'run')) {
1140 $sectionwithinvoicelink .= '<!-- Section with invoice link -->'."\n
";
1141 $sectionwithinvoicelink .= '<span style="font-size:120%;
" class="center
">';
1142 $sectionwithinvoicelink .= $invoice->getNomUrl(1, '', 0, 0, '', 0, 0, -1, '_backoffice')." -
";
1143 $remaintopay = $invoice->getRemainToPay();
1144 if ($remaintopay > 0) {
1145 $sectionwithinvoicelink .= $langs->trans('RemainToPay').': <span class="amountremaintopay
" style="font-size: unset
">'.price($remaintopay, 1, $langs, 1, -1, -1, $conf->currency).'</span>';
1147 if ($invoice->paye) {
1148 $sectionwithinvoicelink .= '<span class="amountpaymentcomplete
" style="font-size: unset
">'.$langs->trans("Paid
").'</span>';
1150 $sectionwithinvoicelink .= $langs->trans('BillShortStatusValidated');
1154 $sectionwithinvoicelink .= '</span><br>';
1155 if (getDolGlobalInt('TAKEPOS_PRINT_INVOICE_DOC_INSTEAD_OF_RECEIPT')) {
1156 $sectionwithinvoicelink .= ' <a target="_blank
" class="button" href="' . DOL_URL_ROOT . '/document.php?token=
' . newToken() . '&modulepart=facture&file=
' . $invoice->ref . '/
' . $invoice->ref . '.pdf
">Invoice</a>';
1157 } elseif (getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector
") {
1158 if (getDolGlobalString('TAKEPOS_PRINT_SERVER') && filter_var($conf->global->TAKEPOS_PRINT_SERVER, FILTER_VALIDATE_URL) == true) {
1159 $sectionwithinvoicelink .= ' <button id="buttonprint
" type="button" onclick="TakeposConnector(
'.$placeid.')
">'.$langs->trans('PrintTicket').'</button>';
1161 $sectionwithinvoicelink .= ' <button id="buttonprint
" type="button" onclick="TakeposPrinting(
'.$placeid.')
">'.$langs->trans('PrintTicket').'</button>';
1163 } elseif ((isModEnabled('receiptprinter') && getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term) > 0) || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter
") {
1164 $sectionwithinvoicelink .= ' <button id="buttonprint
" type="button" onclick="DolibarrTakeposPrinting(
'.$placeid.')
">'.$langs->trans('PrintTicket').'</button>';
1166 $sectionwithinvoicelink .= ' <button id="buttonprint
" type="button" onclick="Print(
'.$placeid.')
">'.$langs->trans('PrintTicket').'</button>';
1167 if (getDolGlobalString('TAKEPOS_PRINT_WITHOUT_DETAILS')) {
1168 $sectionwithinvoicelink .= ' <button id="buttonprint
" type="button" onclick="PrintBox(
'.$placeid.', \
'without_details\')">'.$langs->trans(
'PrintWithoutDetails').
'</button>';
1171 $sectionwithinvoicelink .=
' <button id="buttonprint" type="button" onclick="Print('.$placeid.
', 1)">'.$langs->trans(
'GiftReceipt').
'</button>';
1175 $sectionwithinvoicelink .=
' <button id="buttonsend" type="button" onclick="SendTicket('.$placeid.
')">'.$langs->trans(
'SendTicket').
'</button>';
1178 if ($remaintopay <= 0 &&
getDolGlobalString(
'TAKEPOS_AUTO_PRINT_TICKETS') && $action !=
"history") {
1179 $sectionwithinvoicelink .=
'<script type="text/javascript">$("#buttonprint").click();</script>';
1189 $form =
new Form($db);
1192 if ((
getDolGlobalString(
'TAKEPOS_PHONE_BASIC_LAYOUT') == 1 && $conf->browser->layout ==
'phone') || defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1193 $title =
'TakePOS - Dolibarr '.DOL_VERSION;
1197 $head =
'<meta name="apple-mobile-web-app-title" content="TakePOS"/>
1198 <meta name="apple-mobile-web-app-capable" content="yes">
1199 <meta name="mobile-web-app-capable" content="yes">
1200 <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>';
1201 $arrayofcss = array(
1202 '/takepos/css/pos.css.php',
1204 $arrayofjs = array(
'/takepos/js/jquery.colorbox-min.js');
1207 top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss);
1209 print
'<body>'.
"\n";
1215 <!-- invoice.php -->
1216 <script
type=
"text/javascript">
1218 var selectedtext=
"";
1219 <?php
if ($action ==
"valid") {
1220 echo
"var place=0;";
1222 var placeid=<?php echo($placeid > 0 ? $placeid : 0); ?>;
1223 $(document).ready(
function() {
1224 var idoflineadded = <?php echo(empty($idoflineadded) ? 0 : $idoflineadded); ?>;
1226 $(
'.posinvoiceline').click(
function(){
1227 console.log(
"Click done on "+this.
id);
1228 $(
'.posinvoiceline').removeClass(
"selected");
1229 $(
this).addClass(
"selected");
1233 if (selectedline == this.
id) {
1236 selectedline = this.id;
1238 selectedtext=$(
'#'+selectedline).find(
"td:first").html();
1240 if (defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1241 print
'$("#phonediv1").load("'.DOL_URL_ROOT.
'/takepos/public/auto_order.php?action=editline&token='.
newToken().
'&placeid="+placeid+"&selectedline="+selectedline, function() {
1248 if (idoflineadded > 0)
1250 console.log(
"Auto select "+idoflineadded);
1251 $(
'.posinvoiceline#'+idoflineadded).click();
1255 if ($action ==
"order" && !empty($order_receipt_printer1)) {
1256 if (filter_var($conf->global->TAKEPOS_PRINT_SERVER, FILTER_VALIDATE_URL) ==
true) {
1260 url:
'<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>/printer/index.php',
1261 data:
'invoice='+orderprinter1esc
1268 url:
'http://<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>:8111/print',
1270 print $headerorder.$order_receipt_printer1.$footerorder; ?>'
1276 if ($action ==
"order" && !empty($order_receipt_printer2)) {
1277 if (filter_var($conf->global->TAKEPOS_PRINT_SERVER, FILTER_VALIDATE_URL) ==
true) {
1281 url:
'<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>/printer/index.php?printer=2',
1282 data:
'invoice='+orderprinter2esc
1289 url:
'http://<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>:8111/print2',
1291 print $headerorder.$order_receipt_printer2.$footerorder; ?>'
1297 if ($action ==
"order" && !empty($order_receipt_printer3)) {
1298 if (filter_var($conf->global->TAKEPOS_PRINT_SERVER, FILTER_VALIDATE_URL) ==
true) {
1302 url:
'<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>/printer/index.php?printer=3',
1303 data:
'invoice='+orderprinter3esc
1310 if ($action ==
"search" || $action ==
"valid") {
1312 parent.ClearSearch(
true);
1317 if ($action ==
"temp" && !empty($ticket_printer1)) {
1321 url:
'http://<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>:8111/print',
1323 print $header_soc.$header_ticket.$body_ticket.$ticket_printer1.$ticket_total.$footer_ticket; ?>'
1328 if ($action ==
"search") {
1330 $(
'#search').focus();
1338 function SendTicket(
id)
1340 console.log(
"Open box to select the Print/Send form");
1341 $.colorbox({href:
"send.php?facid="+id, width:
"70%", height:
"30%", transition:
"none", iframe:
"true", title:
'<?php echo dol_escape_js($langs->trans("SendTicket")); ?>'});
1345 function PrintBox(
id, action) {
1346 console.log(
"Open box before printing");
1347 $.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
"); ?>"});
1351 function Print(
id, gift){
1352 console.log(
"Call Print() to generate the receipt.");
1353 $.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")); ?>'});
1357 function TakeposPrinting(
id){
1359 console.log(
"TakeposPrinting" +
id);
1360 $.get(
"receipt.php?facid="+
id,
function(data,
status) {
1361 receipt=data.replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g,
'');
1364 url:
'http://<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER
'); ?>:8111/print',
1371 function TakeposConnector(
id){
1372 console.log(
"TakeposConnector" +
id);
1373 $.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) {
1376 url:
'<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER
'); ?>/printer/index.php',
1377 data:
'invoice='+data
1385 function DolibarrTakeposPrinting(
id) {
1386 console.log(
"DolibarrTakeposPrinting Printing invoice ticket " +
id);
1389 data: { token:
'<?php echo currentToken(); ?>' },
1390 url:
"<?php print DOL_URL_ROOT.'/takepos/ajax/ajax.php?action=printinvoiceticket&token='.newToken().'&term='.urlencode(isset($_SESSION["takeposterminal
"]) ? $_SESSION["takeposterminal
"] : '').'&id='; ?>" + id,
1396 function CreditNote() {
1397 $(
"#poslines").load(
"invoice.php?action=creditnote&token=<?php echo newToken() ?>&invoiceid="+placeid,
function() { });
1401 function SetNote() {
1402 $(
"#poslines").load(
"invoice.php?action=addnote&token=<?php echo newToken() ?>&invoiceid="+placeid+
"&idline="+selectedline, {
"addnote": $(
"#textinput").val() });
1407 $( document ).ready(
function() {
1408 console.log(
"Set customer info and sales in header placeid=<?php echo $placeid; ?> status=<?php echo $invoice->statut; ?>");
1411 $s = $langs->trans(
"Customer");
1412 if ($invoice->id > 0 && ($invoice->socid !=
getDolGlobalString($constforcompanyid))) {
1415 $contactids = $invoice->getIdContact(
'external',
'BILLING');
1416 $contactid = $contactids[0];
1417 if ($contactid > 0) {
1419 $contact->fetch($contactid);
1420 $s .=
" - " . $contact->getFullName($langs);
1426 $(
"#customerandsales").html(
'');
1427 $(
"#shoppingcart").html(
'');
1430 $(
"#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>');
1432 $(
"#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>');
1436 $sql =
"SELECT rowid, datec, ref FROM ".MAIN_DB_PREFIX.
"facture";
1437 $sql .=
" WHERE entity IN (".getEntity(
'invoice').
")";
1440 $sql .=
" AND ref LIKE '(PROV-POS".$db->escape(isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'').
"-0%'";
1443 $sql .=
" AND pos_source = '".$db->escape($_SESSION[
"takeposterminal"]).
"'";
1444 $sql .=
" AND module_source = 'takepos'";
1447 $sql .= $db->order(
'datec',
'ASC');
1448 $resql = $db->query(
$sql);
1451 while ($obj = $db->fetch_object($resql)) {
1452 echo
'$("#shoppingcart").append(\'';
1453 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=\\\'';
1454 $num_sale = str_replace(
")",
"", str_replace(
"(PROV-POS".$_SESSION[
"takeposterminal"].
"-",
"", $obj->ref));
1456 if (str_replace(
"-",
"", $num_sale) > $max_sale) {
1457 $max_sale = str_replace(
"-",
"", $num_sale);
1459 echo
'\\\'; invoiceid=\\\'';
1461 echo
'\\\'; Refresh();">';
1462 if ($placeid == $obj->rowid) {
1463 echo
'<span class="basketselected">';
1465 echo
'<span class="basketnotselected">';
1467 echo
'<span class="fa fa-shopping-cart paddingright"></span>'.dol_print_date($db->jdate($obj->datec),
'%H:%M',
'tzuser');
1471 echo
'$("#shoppingcart").append(\'<a onclick="place=\\\'0-';
1473 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>\');';
1481 $constantforkey =
'CASHDESK_NO_DECREASE_STOCK'. (isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
1484 $constantforkey =
'CASHDESK_ID_WAREHOUSE'. (isset($_SESSION[
"takeposterminal"]) ? $_SESSION[
"takeposterminal"] :
'');
1486 if ($idwarehouse > 0) {
1487 $s =
'<span class="small">';
1489 $warehouse->fetch($idwarehouse);
1490 $s .=
'<span class="hideonsmartphone">'.$langs->trans(
"Warehouse").
'<br></span>'.$warehouse->ref;
1492 $s .=
' ('.$langs->trans(
"Closed").
')';
1495 print
"$('#infowarehouse').html('".dol_escape_js($s).
"');";
1496 print
'$("#infowarehouse").css("display", "inline-block");';
1498 $s =
'<span class="small hideonsmartphone">';
1499 $s .= $langs->trans(
"StockChangeDisabled").
'<br>'.$langs->trans(
"NoWarehouseDefinedForTerminal");
1501 print
"$('#infowarehouse').html('".dol_escape_js($s).
"');";
1502 if (!empty($conf->dol_optimize_smallscreen)) {
1503 print
'$("#infowarehouse").css("display", "none");';
1507 $s =
'<span class="small hideonsmartphone">'.$langs->trans(
"StockChangeDisabled").
'</span>';
1508 print
"$('#infowarehouse').html('".dol_escape_js($s).
"');";
1509 if (!empty($conf->dol_optimize_smallscreen)) {
1510 print
'$("#infowarehouse").css("display", "none");';
1519 $s =
'<span class="small">';
1520 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
1521 $langs->load(
"members");
1522 $s .= $langs->trans(
"Member").
': ';
1524 $result = $adh->fetch(
'',
'', $invoice->socid);
1526 $adh->ref = $adh->getFullName($langs);
1530 $s .= $adh->getFullName($langs);
1531 $s .=
' - '.$adh->type;
1532 if ($adh->datefin) {
1533 $s .=
'<br>'.$langs->trans(
"SubscriptionEndDate").
': '.
dol_print_date($adh->datefin,
'day');
1534 if ($adh->hasDelay()) {
1535 $s .=
" ".img_warning($langs->trans(
"Late"));
1538 $s .=
'<br>'.$langs->trans(
"SubscriptionNotReceived");
1539 if ($adh->statut > 0) {
1540 $s .=
" ".img_warning($langs->trans(
"Late"));
1547 $s .=
'<br>'.$langs->trans(
"ThirdpartyNotLinkedToMember");
1552 $(
"#moreinfo").html(
'<?php print dol_escape_js($s); ?>');
1559 echo
"function CustomerDisplay(){";
1560 echo
"var line1='".$CUSTOMER_DISPLAY_line1.
"'.substring(0,20);";
1561 echo
"line1=line1.padEnd(20);";
1562 echo
"var line2='".$CUSTOMER_DISPLAY_line2.
"'.substring(0,20);";
1563 echo
"line2=line2.padEnd(20);";
1566 data: { text: line1+line2 },
1567 url: '".getDolGlobalString(
'TAKEPOS_PRINT_SERVER').
"/display/index.php',
1578 if (!empty($conf->use_javascript_ajax)) {
1579 print
"\n".
'<!-- Includes JS Footer of Dolibarr -->'.
"\n";
1580 print
'<script src="'.DOL_URL_ROOT.
'/core/js/lib_foot.js.php?lang='.$langs->defaultlang.
'"></script>'.
"\n";
1583 $usediv = (
GETPOST(
'format') ==
'div');
1585 print
'<!-- invoice.php place='.(int) $place.
' invoice='.$invoice->ref.
' usediv='.json_encode($usediv).
', mobilepage='.(empty($mobilepage) ?
'' : $mobilepage).
' $_SESSION["basiclayout"]='.(empty($_SESSION[
"basiclayout"]) ?
'' : $_SESSION[
"basiclayout"]).
' conf TAKEPOS_BAR_RESTAURANT='.
getDolGlobalString(
'TAKEPOS_BAR_RESTAURANT').
' -->'.
"\n";
1586 print
'<div class="div-table-responsive-no-min invoice">';
1588 print
'<div id="tablelines">';
1590 print
'<table id="tablelines" class="noborder noshadow postablelines centpercent">';
1592 if ($sectionwithinvoicelink && ($mobilepage ==
"invoice" || $mobilepage ==
"")) {
1594 print
'<tr><td colspan="5">'.$sectionwithinvoicelink.
'</td></tr>';
1596 print
'<tr><td colspan="4">'.$sectionwithinvoicelink.
'</td></tr>';
1602 print
'<tr class="liste_titre nodrag nodrop">';
1603 print
'<td class="linecoldescription">';
1606 if (empty($mobilepage) || $mobilepage ==
"invoice") {
1607 print
'<!-- hidden var used by some js functions -->';
1608 print
'<input type="hidden" name="invoiceid" id="invoiceid" value="'.$invoice->id.
'">';
1609 print
'<input type="hidden" name="thirdpartyid" id="thirdpartyid" value="'.$invoice->socid.
'">';
1613 $sql =
"SELECT floor, label FROM ".MAIN_DB_PREFIX.
"takepos_floor_tables where rowid=".((int) $place);
1614 $resql = $db->query(
$sql);
1615 $obj = $db->fetch_object($resql);
1617 $label = $obj->label;
1618 $floor = $obj->floor;
1620 if ($mobilepage ==
"invoice" || $mobilepage ==
"") {
1623 print
'<span class="opacitymedium">'.$langs->trans(
'Place').
"</span> <b>".(empty($label) ?
'?' : $label).
"</b><br>";
1624 print
'<span class="opacitymedium">'.$langs->trans(
'Floor').
"</span> <b>".(empty($floor) ?
'?' : $floor).
"</b>";
1631 $parameters = array();
1632 $reshook = $hookmanager->executeHooks(
'completeTakePosInvoiceHeader', $parameters, $invoice, $action);
1636 print $hookmanager->resPrint;
1638 if (empty($_SESSION[
"basiclayout"]) || $_SESSION[
"basiclayout"] != 1) {
1640 print
'<td class="linecolqty right">'.$langs->trans(
'PriceUHT').
'</td>';
1642 print
'<td class="linecolqty right">'.$langs->trans(
'ReductionShort').
'</td>';
1643 print
'<td class="linecolqty right">'.$langs->trans(
'Qty').
'</td>';
1645 print
'<td class="linecolht right nowraponall">';
1646 print
'<span class="opacitymedium small">' . $langs->trans(
'TotalHTShort') .
'</span><br>';
1648 if (empty($mobilepage) || $mobilepage ==
"invoice") {
1649 print
'<span id="linecolht-span-total" style="font-size:1.3em; font-weight: bold;">' .
price($invoice->total_ht, 1,
'', 1, -1, -1, $conf->currency) .
'</span>';
1650 if (
isModEnabled(
'multicurrency') && !empty($_SESSION[
"takeposcustomercurrency"]) && $conf->currency != $_SESSION[
"takeposcustomercurrency"]) {
1652 include_once DOL_DOCUMENT_ROOT .
'/multicurrency/class/multicurrency.class.php';
1654 $multicurrency->fetch(0, $_SESSION[
"takeposcustomercurrency"]);
1655 print
'<br><span id="linecolht-span-total" style="font-size:0.9em; font-style:italic;">(' .
price($invoice->total_ht * $multicurrency->rate->rate) .
' ' . $_SESSION[
"takeposcustomercurrency"] .
')</span>';
1660 print
'<td class="linecolht right nowraponall">';
1661 print
'<span class="opacitymedium small">'.$langs->trans(
'TotalTTCShort').
'</span><br>';
1663 if (empty($mobilepage) || $mobilepage ==
"invoice") {
1664 print
'<span id="linecolht-span-total" style="font-size:1.3em; font-weight: bold;">'.price($invoice->total_ttc, 1,
'', 1, -1, -1, $conf->currency).
'</span>';
1665 if (
isModEnabled(
'multicurrency') && !empty($_SESSION[
"takeposcustomercurrency"]) && $conf->currency != $_SESSION[
"takeposcustomercurrency"]) {
1667 include_once DOL_DOCUMENT_ROOT.
'/multicurrency/class/multicurrency.class.php';
1669 $multicurrency->fetch(0, $_SESSION[
"takeposcustomercurrency"]);
1670 print
'<br><span id="linecolht-span-total" style="font-size:0.9em; font-style:italic;">('.price($invoice->total_ttc * $multicurrency->rate->rate).
' '.$_SESSION[
"takeposcustomercurrency"].
')</span>';
1674 } elseif ($mobilepage ==
"invoice") {
1675 print
'<td class="linecolqty right">'.$langs->trans(
'Qty').
'</td>';
1681 if (!empty($_SESSION[
"basiclayout"]) && $_SESSION[
"basiclayout"] == 1) {
1682 if ($mobilepage ==
"cats") {
1683 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1685 $categories = $categorie->get_full_arbo(
'product');
1687 foreach ($categories as $row) {
1688 if (defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1689 $htmlforlines .=
'<div class="leftcat"';
1691 $htmlforlines .=
'<tr class="drag drop oddeven posinvoiceline"';
1693 $htmlforlines .=
' onclick="LoadProducts('.$row[
'id'].
');">';
1694 if (defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1695 $htmlforlines .=
'<img class="imgwrapper" width="33%" src="'.DOL_URL_ROOT.
'/takepos/public/auto_order.php?genimg=cat&query=cat&id='.$row[
'id'].
'"><br>';
1697 $htmlforlines .=
'<td class="left">';
1699 $htmlforlines .= $row[
'label'];
1700 if (defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1701 $htmlforlines .=
'</div>'.
"\n";
1703 $htmlforlines .=
'</td></tr>'.
"\n";
1706 print $htmlforlines;
1709 if ($mobilepage ==
"products") {
1710 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1713 $result =
$object->fetch($catid);
1714 $prods =
$object->getObjectsInCateg(
"product");
1716 foreach ($prods as $row) {
1717 if (defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1718 $htmlforlines .=
'<div class="leftcat"';
1720 $htmlforlines .=
'<tr class="drag drop oddeven posinvoiceline"';
1722 $htmlforlines .=
' onclick="AddProduct(\''.$place.
'\',
'.$row->id.')
"';
1723 $htmlforlines .= '>';
1724 if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
1725 $htmlforlines .= '<img class="imgwrapper
" width="33%
" src="'.DOL_URL_ROOT.'/takepos/
public/auto_order.php?genimg=pro&query=pro&
id=
'.$row->id.'"><br>';
1726 $htmlforlines .= $row->label.' '.price($row->price_ttc, 1, $langs, 1, -1, -1, $conf->currency);
1727 $htmlforlines .= '</div>'."\n
";
1729 $htmlforlines .= '<td class="left
">';
1730 $htmlforlines .= $row->label;
1731 $htmlforlines .= '<div class="right
">'.price($row->price_ttc, 1, $langs, 1, -1, -1, $conf->currency).'</div>';
1732 $htmlforlines .= '</td>';
1733 $htmlforlines .= '</tr>'."\n
";
1736 print $htmlforlines;
1739 if ($mobilepage == "places
") {
1740 $sql = "SELECT
rowid, entity, label, leftpos, toppos, floor FROM
".MAIN_DB_PREFIX."takepos_floor_tables
";
1741 $resql = $db->query($sql);
1744 while ($row = $db->fetch_array($resql)) {
1746 $htmlforlines .= '<tr class="drag drop oddeven posinvoiceline
';
1747 $htmlforlines .= '" onclick="LoadPlace(\
''.$row[
'label'].
'\')
">';
1748 $htmlforlines .= '<td class="left
">';
1749 $htmlforlines .= $row['label'];
1750 $htmlforlines .= '</td>';
1751 $htmlforlines .= '</tr>'."\n
";
1753 print $htmlforlines;
1758 //In Phone basic layout hide some content depends situation
1759 if (!empty($_SESSION["basiclayout
"]) && $_SESSION["basiclayout
"] == 1 && $mobilepage != "invoice
" && $action != "order
") {
1763 // Loop on each lines on invoice
1764 if (is_array($invoice->lines) && count($invoice->lines)) {
1765 print '<!-- invoice.php show lines of invoices -->'."\n
";
1766 $tmplines = array_reverse($invoice->lines);
1767 $htmlsupplements = array();
1768 foreach ($tmplines as $line) {
1769 if ($line->fk_parent_line != false) {
1770 $htmlsupplements[$line->fk_parent_line] .= '<tr class="drag drop oddeven posinvoiceline
';
1771 if ($line->special_code == "4") {
1772 $htmlsupplements[$line->fk_parent_line] .= ' order
';
1774 $htmlsupplements[$line->fk_parent_line] .= '" id="'.$line->id.'"';
1775 if ($line->special_code == "4
") {
1776 $htmlsupplements[$line->fk_parent_line] .= ' title="'.dol_escape_htmltag($langs->trans("AlreadyPrinted")).'"';
1778 $htmlsupplements[$line->fk_parent_line] .= '>';
1779 $htmlsupplements[$line->fk_parent_line] .= '<td class="left
">';
1780 $htmlsupplements[$line->fk_parent_line] .= img_picto('', 'rightarrow');
1781 if ($line->product_label) {
1782 $htmlsupplements[$line->fk_parent_line] .= $line->product_label;
1784 if ($line->product_label && $line->desc) {
1785 $htmlsupplements[$line->fk_parent_line] .= '<br>';
1787 if ($line->product_label != $line->desc) {
1788 $firstline = dolGetFirstLineOfText($line->desc);
1789 if ($firstline != $line->desc) {
1790 $htmlsupplements[$line->fk_parent_line] .= $form->textwithpicto(dolGetFirstLineOfText($line->desc), $line->desc);
1792 $htmlsupplements[$line->fk_parent_line] .= $line->desc;
1795 $htmlsupplements[$line->fk_parent_line] .= '</td>';
1797 // complete line by hook
1798 $parameters = array('line' => $line);
1799 $reshook = $hookmanager->executeHooks('completeTakePosInvoiceParentLine', $parameters, $invoice, $action); // Note that $action and $object may have been modified by some hooks
1801 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1803 $htmlsupplements[$line->fk_parent_line] .= $hookmanager->resPrint;
1805 if (empty($_SESSION["basiclayout
"]) || $_SESSION["basiclayout
"] != 1) {
1806 $htmlsupplements[$line->fk_parent_line] .= '<td class="right
">'.vatrate($line->remise_percent, true).'</td>';
1807 $htmlsupplements[$line->fk_parent_line] .= '<td class="right
">'.$line->qty.'</td>';
1808 $htmlsupplements[$line->fk_parent_line] .= '<td class="right
">'.price($line->total_ttc).'</td>';
1810 $htmlsupplements[$line->fk_parent_line] .= '</tr>'."\n
";
1815 $htmlforlines .= '<tr class="drag drop oddeven posinvoiceline
';
1816 if ($line->special_code == "4") {
1817 $htmlforlines .= ' order
';
1819 $htmlforlines .= '" id="'.$line->id.'"';
1820 if ($line->special_code == "4
") {
1821 $htmlforlines .= ' title="'.dol_escape_htmltag($langs->trans("AlreadyPrinted")).'"';
1823 $htmlforlines .= '>';
1824 $htmlforlines .= '<td class="left
">';
1825 if (!empty($_SESSION["basiclayout
"]) && $_SESSION["basiclayout
"] == 1) {
1826 $htmlforlines .= '<span class="phoneqty
">'.$line->qty."</span> x
";
1828 if (isset($line->product_type)) {
1829 if (empty($line->product_type)) {
1830 $htmlforlines .= img_object('', 'product').' ';
1832 $htmlforlines .= img_object('', 'service').' ';
1836 if (!getDolGlobalString('TAKEPOS_SHOW_N_FIRST_LINES')) {
1837 if ($line->product_ref) {
1838 $tooltiptext .= '<b>'.$langs->trans("Ref
").'</b> : '.$line->product_ref.'<br>';
1839 $tooltiptext .= '<b>'.$langs->trans("Label
").'</b> : '.$line->product_label.'<br>';
1840 if (!empty($line->batch)) {
1841 $tooltiptext .= '<br><b>'.$langs->trans("LotSerial
").'</b> : '.$line->batch.'<br>';
1843 if (!empty($line->fk_warehouse)) {
1844 $tooltiptext .= '<b>'.$langs->trans("Warehouse
").'</b> : '.$line->fk_warehouse.'<br>';
1846 if ($line->product_label != $line->desc) {
1848 $tooltiptext .= '<br>';
1850 $tooltiptext .= $line->desc;
1853 if (getDolGlobalInt('TAKEPOS_SHOW_PRODUCT_REFERENCE') == 1) {
1854 $htmlforlines .= $form->textwithpicto($line->product_label ? '<b>' . $line->product_ref . '</b> - ' . $line->product_label : dolGetFirstLineOfText($line->desc, 1), $tooltiptext);
1855 } elseif (getDolGlobalInt('TAKEPOS_SHOW_PRODUCT_REFERENCE') == 2) {
1856 $htmlforlines .= $form->textwithpicto($line->product_ref ? '<b>'.$line->product_ref.'<b>' : dolGetFirstLineOfText($line->desc, 1), $tooltiptext);
1858 $htmlforlines .= $form->textwithpicto($line->product_label ? $line->product_label : ($line->product_ref ? $line->product_ref : dolGetFirstLineOfText($line->desc, 1)), $tooltiptext);
1861 if ($line->product_ref) {
1862 $tooltiptext .= '<b>'.$langs->trans("Ref
").'</b> : '.$line->product_ref.'<br>';
1863 $tooltiptext .= '<b>'.$langs->trans("Label
").'</b> : '.$line->product_label.'<br>';
1865 if (!empty($line->batch)) {
1866 $tooltiptext .= '<br><b>'.$langs->trans("LotSerial
").'</b> : '.$line->batch.'<br>';
1868 if (!empty($line->fk_warehouse)) {
1869 $tooltiptext .= '<b>'.$langs->trans("Warehouse
").'</b> : '.$line->fk_warehouse.'<br>';
1872 if ($line->product_label) {
1873 $htmlforlines .= $line->product_label;
1875 if ($line->product_label != $line->desc) {
1876 if ($line->product_label && $line->desc) {
1877 $htmlforlines .= '<br>';
1879 $firstline = dolGetFirstLineOfText($line->desc, $conf->global->TAKEPOS_SHOW_N_FIRST_LINES);
1880 if ($firstline != $line->desc) {
1881 $htmlforlines .= $form->textwithpicto(dolGetFirstLineOfText($line->desc), $line->desc);
1883 $htmlforlines .= $line->desc;
1887 if (!empty($line->array_options['options_order_notes'])) {
1888 $htmlforlines .= "<br>(
".$line->array_options['options_order_notes'].")
";
1890 if (!empty($_SESSION["basiclayout
"]) && $_SESSION["basiclayout
"] == 1) {
1891 $htmlforlines .= '</td><td class="right phonetable
"><button type="button" onclick="SetQty(place,
'.$line->rowid.',
'.($line->qty - 1).');
" class="publicphonebutton2 phonered
">-</button> <button type="button" onclick="SetQty(place,
'.$line->rowid.',
'.($line->qty + 1).');
" class="publicphonebutton2 phonegreen
">+</button>';
1893 if (empty($_SESSION["basiclayout
"]) || $_SESSION["basiclayout
"] != 1) {
1895 $moreinfo .= $langs->transcountry("TotalHT
", $mysoc->country_code).': '.price($line->total_ht);
1896 if ($line->vat_src_code) {
1897 $moreinfo .= '<br>'.$langs->trans("VATCode
").': '.$line->vat_src_code;
1899 $moreinfo .= '<br>'.$langs->transcountry("TotalVAT
", $mysoc->country_code).': '.price($line->total_tva);
1900 $moreinfo .= '<br>'.$langs->transcountry("TotalLT1
", $mysoc->country_code).': '.price($line->total_localtax1);
1901 $moreinfo .= '<br>'.$langs->transcountry("TotalLT2
", $mysoc->country_code).': '.price($line->total_localtax2);
1902 $moreinfo .= '<hr>';
1903 $moreinfo .= $langs->transcountry("TotalTTC
", $mysoc->country_code).': '.price($line->total_ttc);
1904 //$moreinfo .= $langs->trans("TotalHT
").': '.$line->total_ht;
1905 if ($line->date_start || $line->date_end) {
1906 $htmlforlines .= '<br><div class="clearboth nowraponall
">'.get_date_range($line->date_start, $line->date_end).'</div>';
1908 $htmlforlines .= '</td>';
1910 // complete line by hook
1911 $parameters = array('line' => $line);
1912 $reshook = $hookmanager->executeHooks('completeTakePosInvoiceLine', $parameters, $invoice, $action); // Note that $action and $object may have been modified by some hooks
1914 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1916 $htmlforlines .= $hookmanager->resPrint;
1918 if (getDolGlobalInt("TAKEPOS_SHOW_SUBPRICE
")) {
1919 $htmlforlines .= '<td class="right
">'.price($line->subprice).'</td>';
1921 $htmlforlines .= '<td class="right
">'.vatrate($line->remise_percent, true).'</td>';
1922 $htmlforlines .= '<td class="right
">';
1923 if (isModEnabled('stock') && $user->hasRight('stock', 'mouvement', 'lire')) {
1924 $constantforkey = 'CASHDESK_ID_WAREHOUSE'.$_SESSION["takeposterminal
"];
1925 if (getDolGlobalString($constantforkey) && $line->fk_product > 0 && !getDolGlobalString('TAKEPOS_HIDE_STOCK_ON_LINE')) {
1926 $sql = "SELECT e.rowid, e.ref, e.lieu, e.fk_parent, e.statut, ps.reel, ps.rowid as product_stock_id, p.pmp
";
1927 $sql .= " FROM
".MAIN_DB_PREFIX."entrepot as e,
";
1928 $sql .= " ".MAIN_DB_PREFIX."product_stock as ps
";
1929 $sql .= " LEFT JOIN
".MAIN_DB_PREFIX."product as p ON p.rowid = ps.fk_product
";
1930 $sql .= " WHERE ps.reel != 0
";
1931 $sql .= " AND ps.fk_entrepot =
".((int) getDolGlobalString($constantforkey));
1932 $sql .= " AND e.entity IN (
".getEntity('stock').")
";
1933 $sql .= " AND ps.fk_product =
".((int) $line->fk_product);
1934 $resql = $db->query($sql);
1937 $obj = $db->fetch_object($resql);
1939 $stock_real = price2num($obj->reel, 'MS');
1941 $htmlforlines .= $line->qty;
1942 if ($line->qty && $line->qty > $stock_real) {
1943 $htmlforlines .= '<span style="color: var(--amountremaintopaycolor)
">';
1945 $htmlforlines .= ' <span class="posstocktoolow
">('.$langs->trans("Stock
").' '.$stock_real.')</span>';
1946 if ($line->qty && $line->qty > $stock_real) {
1947 $htmlforlines .= "</span>
";
1950 dol_print_error($db);
1953 $htmlforlines .= $line->qty;
1956 $htmlforlines .= $line->qty;
1959 $htmlforlines .= '</td>';
1960 if (getDolGlobalInt('TAKEPOS_SHOW_HT')) {
1961 $htmlforlines .= '<td class="right classfortooltip
" title="'.$moreinfo.'">';
1962 $htmlforlines .= price($line->total_ht, 1, '', 1, -1, -1, $conf->currency);
1963 if (isModEnabled('multicurrency') && !empty($_SESSION["takeposcustomercurrency
"]) && $conf->currency != $_SESSION["takeposcustomercurrency
"]) {
1964 //Only show customer currency if multicurrency module is enabled, if currency selected and if this currency selected is not the same as main currency
1965 include_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php';
1966 $multicurrency = new MultiCurrency($db);
1967 $multicurrency->fetch(0, $_SESSION["takeposcustomercurrency
"]);
1968 $htmlforlines .= '<br><span id="linecolht-span-total
" style="font-size:0.9em; font-style:italic;
">('.price($line->total_ht * $multicurrency->rate->rate).' '.$_SESSION["takeposcustomercurrency
"].')</span>';
1970 $htmlforlines .= '</td>';
1972 $htmlforlines .= '<td class="right classfortooltip
" title="'.$moreinfo.'">';
1973 $htmlforlines .= price($line->total_ttc, 1, '', 1, -1, -1, $conf->currency);
1974 if (isModEnabled('multicurrency') && !empty($_SESSION["takeposcustomercurrency
"]) && $conf->currency != $_SESSION["takeposcustomercurrency
"]) {
1975 //Only show customer currency if multicurrency module is enabled, if currency selected and if this currency selected is not the same as main currency
1976 include_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php';
1977 $multicurrency = new MultiCurrency($db);
1978 $multicurrency->fetch(0, $_SESSION["takeposcustomercurrency
"]);
1979 $htmlforlines .= '<br><span id="linecolht-span-total
" style="font-size:0.9em; font-style:italic;
">('.price($line->total_ttc * $multicurrency->rate->rate).' '.$_SESSION["takeposcustomercurrency
"].')</span>';
1981 $htmlforlines .= '</td>';
1983 $htmlforlines .= '</tr>'."\n
";
1984 $htmlforlines .= empty($htmlsupplements[$line->id]) ? '' : $htmlsupplements[$line->id];
1986 print $htmlforlines;
1989 print '<tr class="drag drop oddeven
"><td class="left
"><span class="opacitymedium
">'.$langs->trans("Empty
").'</span></td><td></td>';
1990 if (empty($_SESSION["basiclayout
"]) || $_SESSION["basiclayout
"] != 1) {
1991 print '<td></td><td></td>';
1992 if (getDolGlobalString('TAKEPOS_SHOW_HT')) {
1998 } else { // No invoice generated yet
1999 print '<tr class="drag drop oddeven
"><td class="left
"><span class="opacitymedium
">'.$langs->trans("Empty
").'</span></td><td></td>';
2000 if (empty($_SESSION["basiclayout
"]) || $_SESSION["basiclayout
"] != 1) {
2001 print '<td></td><td></td>';
2002 if (getDolGlobalString('TAKEPOS_SHOW_HT')) {
2015 if (($action == "valid
" || $action == "history
") && $invoice->type != Facture::TYPE_CREDIT_NOTE && !getDolGlobalString('TAKEPOS_NO_CREDITNOTE')) {
2016 print '<button id="buttonprint
" type="button" onclick="ModalBox(\
'ModalCreditNote\')">'.$langs->trans(
'CreateCreditNote').
'</button>';
2018 print
' <a target="_blank" class="button" href="' . DOL_URL_ROOT .
'/document.php?token=' .
newToken() .
'&modulepart=facture&file=' . $invoice->ref .
'/' . $invoice->ref .
'.pdf">Invoice</a>';
2023 if ($action ==
"search") {
2025 <input type="text" id="search" class="input-nobottom" name="search" onkeyup="Search2(\'\', null);" style="width: 80%; font-size: 150%;" placeholder="'.dol_escape_htmltag($langs->trans(
'Search')).
'">
2032 if ((
getDolGlobalString(
'TAKEPOS_PHONE_BASIC_LAYOUT') == 1 && $conf->browser->layout ==
'phone') || defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
2033 print
'</body></html>';
if($user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Class to manage members of a foundation.
const STATUS_EXCLUDED
Excluded.
Class to manage categories.
Class to manage warehouses.
const STATUS_CLOSED
Warehouse closed, inactive.
Class to manage invoices.
const STATUS_DRAFT
Draft status.
const TYPE_CREDIT_NOTE
Credit note invoice.
Class to manage stock movements.
Class to manage payments of customer invoices.
Class to manage products or services.
Manage record for batch number management.
const BATCH_RULE_SELLBY_EATBY_DATES_FIRST
Batches rules.
Class to manage third parties objects (customers, suppliers, prospects...)
if(isModEnabled('invoice') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&!getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') && $user->hasRight('tax', 'charges', 'lire')) if(isModEnabled('invoice') &&isModEnabled('order') && $user->hasRight("commande", "lire") &&!getDolGlobalString('WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER')) $sql
Social contributions to pay.
print *****$script_file(".$version.") pid c cd cd cd description as p label as s rowid
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
GETPOSTFLOAT($paramname, $rounding='')
Return the value of a $_GET or $_POST supervariable, converted into float.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_htmloutput_errors($mesgstring='', $mesgarray=array(), $keepembedded=0)
Print formatted error messages to output (Used to show messages on html output).
get_localtax($vatrate, $local, $thirdparty_buyer=null, $thirdparty_seller=null, $vatnpr=0)
Return localtax rate for a particular vat, when selling a product with vat $vatrate,...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
treeview li table
No Email.
if(!defined( 'CSRFCHECK_WITH_TOKEN'))
top_htmlhead($head, $title='', $disablejs=0, $disablehead=0, $arrayofjs=array(), $arrayofcss=array(), $disableforlogin=0, $disablenofollow=0, $disablenoindex=0)
Output html header of a page.
if(!defined('NOREQUIREMENU')) if(!empty(GETPOST('seteventmessages', 'alpha'))) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
table tableforfield button
0 = Do not include form tag and submit button -1 = Do not include form tag but include submit button
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.
fail($message)
Abort invoice creation with a given error message.