invoice.php 72 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705
  1. <?php
  2. /**
  3. * Copyright (C) 2018 Andreu Bisquerra <jove@bisquerra.com>
  4. * Copyright (C) 2021 Nicolas ZABOURI <info@inovea-conseil.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/takepos/invoice.php
  21. * \ingroup takepos
  22. * \brief Page to generate section with list of lines
  23. */
  24. // if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER', '1'); // Not disabled cause need to load personalized language
  25. // if (! defined('NOREQUIREDB')) define('NOREQUIREDB', '1'); // Not disabled cause need to load personalized language
  26. // if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1');
  27. // if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN', '1');
  28. if (!defined('NOTOKENRENEWAL')) {
  29. define('NOTOKENRENEWAL', '1');
  30. }
  31. if (!defined('NOREQUIREMENU')) {
  32. define('NOREQUIREMENU', '1');
  33. }
  34. if (!defined('NOREQUIREHTML')) {
  35. define('NOREQUIREHTML', '1');
  36. }
  37. if (!defined('NOREQUIREAJAX')) {
  38. define('NOREQUIREAJAX', '1');
  39. }
  40. // Load Dolibarr environment
  41. if (!defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
  42. require '../main.inc.php';
  43. }
  44. require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
  45. require_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
  46. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  47. require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
  48. $hookmanager->initHooks(array('takeposinvoice'));
  49. $langs->loadLangs(array("companies", "commercial", "bills", "cashdesk", "stocks", "banks"));
  50. $id = GETPOST('id', 'int');
  51. $action = GETPOST('action', 'aZ09');
  52. $idproduct = GETPOST('idproduct', 'int');
  53. $place = (GETPOST('place', 'aZ09') ? GETPOST('place', 'aZ09') : 0); // $place is id of table for Bar or Restaurant
  54. $placeid = 0; // $placeid is ID of invoice
  55. $mobilepage = GETPOST('mobilepage', 'alpha');
  56. // Terminal is stored into $_SESSION["takeposterminal"];
  57. if (empty($user->rights->takepos->run) && !defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
  58. accessforbidden();
  59. }
  60. if ((getDolGlobalString('TAKEPOS_PHONE_BASIC_LAYOUT') == 1 && $conf->browser->layout == 'phone') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
  61. // DIRECT LINK TO THIS PAGE FROM MOBILE AND NO TERMINAL SELECTED
  62. if ($_SESSION["takeposterminal"] == "") {
  63. if (getDolGlobalString('TAKEPOS_NUM_TERMINALS') == "1") {
  64. $_SESSION["takeposterminal"] = 1;
  65. } else {
  66. header("Location: ".DOL_URL_ROOT."/takepos/index.php");
  67. exit;
  68. }
  69. }
  70. }
  71. /**
  72. * Abort invoice creationg with a given error message
  73. *
  74. * @param string $message Message explaining the error to the user
  75. * @return void
  76. */
  77. function fail($message)
  78. {
  79. header($_SERVER['SERVER_PROTOCOL'].' 500 Internal Server Error', true, 500);
  80. die($message);
  81. }
  82. $number = GETPOST('number', 'alpha');
  83. $idline = GETPOST('idline', 'int');
  84. $selectedline = GETPOST('selectedline', 'int');
  85. $desc = GETPOST('desc', 'alphanohtml');
  86. $pay = GETPOST('pay', 'aZ09');
  87. $amountofpayment = price2num(GETPOST('amount', 'alpha'));
  88. $invoiceid = GETPOST('invoiceid', 'int');
  89. $paycode = $pay;
  90. if ($pay == 'cash') {
  91. $paycode = 'LIQ'; // For backward compatibility
  92. }
  93. if ($pay == 'card') {
  94. $paycode = 'CB'; // For backward compatibility
  95. }
  96. if ($pay == 'cheque') {
  97. $paycode = 'CHQ'; // For backward compatibility
  98. }
  99. // Retrieve paiementid
  100. $paiementid = 0;
  101. if ($paycode) {
  102. $sql = "SELECT id FROM ".MAIN_DB_PREFIX."c_paiement";
  103. $sql .= " WHERE entity IN (".getEntity('c_paiement').")";
  104. $sql .= " AND code = '".$db->escape($paycode)."'";
  105. $resql = $db->query($sql);
  106. if ($resql) {
  107. $obj = $db->fetch_object($resql);
  108. if ($obj) {
  109. $paiementid = $obj->id;
  110. }
  111. }
  112. }
  113. $invoice = new Facture($db);
  114. if ($invoiceid > 0) {
  115. $ret = $invoice->fetch($invoiceid);
  116. } else {
  117. $ret = $invoice->fetch('', '(PROV-POS'. (isset($_SESSION["takeposterminal"]) ? $_SESSION["takeposterminal"] : '') .'-'.$place.')');
  118. }
  119. if ($ret > 0) {
  120. $placeid = $invoice->id;
  121. }
  122. $constforcompanyid = 'CASHDESK_ID_THIRDPARTY'. (isset($_SESSION["takeposterminal"]) ? $_SESSION["takeposterminal"] : '');
  123. $soc = new Societe($db);
  124. if ($invoice->socid > 0) {
  125. $soc->fetch($invoice->socid);
  126. } else {
  127. $soc->fetch(getDolGlobalString("$constforcompanyid"));
  128. }
  129. // Change the currency of invoice if it was modified
  130. if (isModEnabled('multicurrency') && !empty($_SESSION["takeposcustomercurrency"])) {
  131. if ($invoice->multicurrency_code != $_SESSION["takeposcustomercurrency"]) {
  132. $invoice->setMulticurrencyCode($_SESSION["takeposcustomercurrency"]);
  133. }
  134. }
  135. /*
  136. * Actions
  137. */
  138. $parameters=array();
  139. $reshook=$hookmanager->executeHooks('doActions', $parameters, $invoice, $action); // Note that $action and $object may have been modified by some hooks
  140. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  141. if (empty($reshook)) {
  142. // Action to record a payment on a TakePOS invoice
  143. if ($action == 'valid' && $user->rights->facture->creer) {
  144. $bankaccount = 0;
  145. $error = 0;
  146. if (!empty($conf->global->TAKEPOS_CAN_FORCE_BANK_ACCOUNT_DURING_PAYMENT)) {
  147. $bankaccount = GETPOST('accountid', 'int');
  148. } else {
  149. if ($pay == 'LIQ') {
  150. $bankaccount = getDolGlobalString('CASHDESK_ID_BANKACCOUNT_CASH'.$_SESSION["takeposterminal"]); // For backward compatibility
  151. } elseif ($pay == "CHQ") {
  152. $bankaccount = getDolGlobalString('CASHDESK_ID_BANKACCOUNT_CHEQUE'.$_SESSION["takeposterminal"]); // For backward compatibility
  153. } else {
  154. $accountname = "CASHDESK_ID_BANKACCOUNT_".$pay.$_SESSION["takeposterminal"];
  155. $bankaccount = getDolGlobalString($accountname);
  156. }
  157. }
  158. if ($bankaccount <= 0 && $pay != "delayed" && isModEnabled("banque")) {
  159. $errormsg = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("BankAccount"));
  160. $error++;
  161. }
  162. $now = dol_now();
  163. $res = 0;
  164. $invoice = new Facture($db);
  165. $invoice->fetch($placeid);
  166. if ($invoice->total_ttc < 0) {
  167. $invoice->type = $invoice::TYPE_CREDIT_NOTE;
  168. $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."facture WHERE";
  169. $sql .= " fk_soc = ".((int) $invoice->socid);
  170. $sql .= " AND type <> ".Facture::TYPE_CREDIT_NOTE;
  171. $sql .= " AND fk_statut >= ".$invoice::STATUS_VALIDATED;
  172. $sql .= " ORDER BY rowid DESC";
  173. $resql = $db->query($sql);
  174. if ($resql) {
  175. $obj = $db->fetch_object($resql);
  176. $fk_source = $obj->rowid;
  177. if ($fk_source == null) {
  178. fail($langs->transnoentitiesnoconv("NoPreviousBillForCustomer"));
  179. }
  180. } else {
  181. fail($langs->transnoentitiesnoconv("NoPreviousBillForCustomer"));
  182. }
  183. $invoice->fk_facture_source = $fk_source;
  184. $invoice->update($user);
  185. }
  186. //$sav_FACTURE_ADDON = '';
  187. //if (!empty($conf->global->TAKEPOS_ADDON)) {
  188. // $sav_FACTURE_ADDON = $conf->global->FACTURE_ADDON;
  189. // if ($conf->global->TAKEPOS_ADDON == "terminal") $conf->global->FACTURE_ADDON = $conf->global->{'TAKEPOS_ADDON'.$_SESSION["takeposterminal"]};
  190. // else $conf->global->FACTURE_ADDON = $conf->global->TAKEPOS_ADDON;
  191. //}
  192. $constantforkey = 'CASHDESK_NO_DECREASE_STOCK'.$_SESSION["takeposterminal"];
  193. if ($error) {
  194. dol_htmloutput_errors($errormsg, null, 1);
  195. } elseif ($invoice->statut != Facture::STATUS_DRAFT) {
  196. //If invoice is validated but it is not fully paid is not error and make the payment
  197. if ($invoice->getRemainToPay() > 0) {
  198. $res = 1;
  199. } else {
  200. dol_syslog("Sale already validated");
  201. dol_htmloutput_errors($langs->trans("InvoiceIsAlreadyValidated", "TakePos"), null, 1);
  202. }
  203. } elseif (count($invoice->lines) == 0) {
  204. $error++;
  205. dol_syslog('Sale without lines');
  206. dol_htmloutput_errors($langs->trans("NoLinesToBill", "TakePos"), null, 1);
  207. } elseif (isModEnabled('stock') && $conf->global->$constantforkey != "1") {
  208. $savconst = $conf->global->STOCK_CALCULATE_ON_BILL;
  209. $conf->global->STOCK_CALCULATE_ON_BILL = 1;
  210. $constantforkey = 'CASHDESK_ID_WAREHOUSE'.$_SESSION["takeposterminal"];
  211. dol_syslog("Validate invoice with stock change into warehouse defined into constant ".$constantforkey." = ".$conf->global->$constantforkey);
  212. $batch_rule = 0;
  213. if (isModEnabled('productbatch') && !empty($conf->global->CASHDESK_FORCE_DECREASE_STOCK)) {
  214. require_once DOL_DOCUMENT_ROOT.'/product/class/productbatch.class.php';
  215. $batch_rule = Productbatch::BATCH_RULE_SELLBY_EATBY_DATES_FIRST;
  216. }
  217. $res = $invoice->validate($user, '', $conf->global->$constantforkey, 0, $batch_rule);
  218. $conf->global->STOCK_CALCULATE_ON_BILL = $savconst;
  219. } else {
  220. $res = $invoice->validate($user);
  221. if ($res < 0) {
  222. $error++;
  223. $langs->load("admin");
  224. dol_htmloutput_errors($invoice->error == 'NotConfigured' ? $langs->trans("NotConfigured").' (TakePos numbering module)': $invoice->error, $invoice->errors, 1);
  225. }
  226. }
  227. // Restore save values
  228. //if (!empty($sav_FACTURE_ADDON))
  229. //{
  230. // $conf->global->FACTURE_ADDON = $sav_FACTURE_ADDON;
  231. //}
  232. // Add the payment
  233. if (!$error && $res >= 0) {
  234. $remaintopay = $invoice->getRemainToPay();
  235. if ($remaintopay > 0) {
  236. $payment = new Paiement($db);
  237. $payment->datepaye = $now;
  238. $payment->fk_account = $bankaccount;
  239. $payment->amounts[$invoice->id] = $amountofpayment;
  240. if ($pay == 'LIQ') {
  241. $payment->pos_change = price2num(GETPOST('excess', 'alpha'));
  242. }
  243. // If user has not used change control, add total invoice payment
  244. // Or if user has used change control and the amount of payment is higher than remain to pay, add the remain to pay
  245. if ($amountofpayment == 0 || $amountofpayment > $remaintopay) {
  246. $payment->amounts[$invoice->id] = $remaintopay;
  247. }
  248. $payment->paiementid = $paiementid;
  249. $payment->num_payment = $invoice->ref;
  250. if ($pay != "delayed") {
  251. $payment->create($user);
  252. $payment->addPaymentToBank($user, 'payment', '(CustomerInvoicePayment)', $bankaccount, '', '');
  253. $remaintopay = $invoice->getRemainToPay(); // Recalculate remain to pay after the payment is recorded
  254. }
  255. }
  256. if ($remaintopay == 0) {
  257. dol_syslog("Invoice is paid, so we set it to status Paid");
  258. $result = $invoice->setPaid($user);
  259. if ($result > 0) {
  260. $invoice->paye = 1;
  261. }
  262. // set payment method
  263. $invoice->setPaymentMethods($paiementid);
  264. } else {
  265. dol_syslog("Invoice is not paid, remain to pay = ".$remaintopay);
  266. }
  267. } else {
  268. dol_htmloutput_errors($invoice->error, $invoice->errors, 1);
  269. }
  270. }
  271. if ($action == 'creditnote' && $user->rights->facture->creer) {
  272. $creditnote = new Facture($db);
  273. $creditnote->socid = $invoice->socid;
  274. $creditnote->date = dol_now();
  275. $creditnote->module_source = 'takepos';
  276. $creditnote->pos_source = isset($_SESSION["takeposterminal"]) ? $_SESSION["takeposterminal"] : '' ;
  277. $creditnote->type = Facture::TYPE_CREDIT_NOTE;
  278. $creditnote->fk_facture_source = $placeid;
  279. $creditnote->remise_absolue = $invoice->remise_absolue;
  280. $creditnote->remise_percent = $invoice->remise_percent;
  281. $creditnote->create($user);
  282. foreach ($invoice->lines as $line) {
  283. // Extrafields
  284. if (method_exists($line, 'fetch_optionals')) {
  285. // load extrafields
  286. $line->fetch_optionals();
  287. }
  288. // Reset fk_parent_line for no child products and special product
  289. if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) {
  290. $fk_parent_line = 0;
  291. }
  292. if (getDolGlobalInt('INVOICE_USE_SITUATION')) {
  293. if (!empty($invoice->situation_counter)) {
  294. $source_fk_prev_id = $line->fk_prev_id; // temporary storing situation invoice fk_prev_id
  295. $line->fk_prev_id = $line->id; // The new line of the new credit note we are creating must be linked to the situation invoice line it is created from
  296. if (!empty($invoice->tab_previous_situation_invoice)) {
  297. // search the last standard invoice in cycle and the possible credit note between this last and invoice
  298. // TODO Move this out of loop of $invoice->lines
  299. $tab_jumped_credit_notes = array();
  300. $lineIndex = count($invoice->tab_previous_situation_invoice) - 1;
  301. $searchPreviousInvoice = true;
  302. while ($searchPreviousInvoice) {
  303. if ($invoice->tab_previous_situation_invoice[$lineIndex]->situation_cycle_ref || $lineIndex < 1) {
  304. $searchPreviousInvoice = false; // find, exit;
  305. break;
  306. } else {
  307. if ($invoice->tab_previous_situation_invoice[$lineIndex]->type == Facture::TYPE_CREDIT_NOTE) {
  308. $tab_jumped_credit_notes[$lineIndex] = $invoice->tab_previous_situation_invoice[$lineIndex]->id;
  309. }
  310. $lineIndex--; // go to previous invoice in cycle
  311. }
  312. }
  313. $maxPrevSituationPercent = 0;
  314. foreach ($invoice->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine) {
  315. if ($prevLine->id == $source_fk_prev_id) {
  316. $maxPrevSituationPercent = max($maxPrevSituationPercent, $prevLine->situation_percent);
  317. //$line->subprice = $line->subprice - $prevLine->subprice;
  318. $line->total_ht = $line->total_ht - $prevLine->total_ht;
  319. $line->total_tva = $line->total_tva - $prevLine->total_tva;
  320. $line->total_ttc = $line->total_ttc - $prevLine->total_ttc;
  321. $line->total_localtax1 = $line->total_localtax1 - $prevLine->total_localtax1;
  322. $line->total_localtax2 = $line->total_localtax2 - $prevLine->total_localtax2;
  323. $line->multicurrency_subprice = $line->multicurrency_subprice - $prevLine->multicurrency_subprice;
  324. $line->multicurrency_total_ht = $line->multicurrency_total_ht - $prevLine->multicurrency_total_ht;
  325. $line->multicurrency_total_tva = $line->multicurrency_total_tva - $prevLine->multicurrency_total_tva;
  326. $line->multicurrency_total_ttc = $line->multicurrency_total_ttc - $prevLine->multicurrency_total_ttc;
  327. }
  328. }
  329. // prorata
  330. $line->situation_percent = $maxPrevSituationPercent - $line->situation_percent;
  331. //print 'New line based on invoice id '.$invoice->tab_previous_situation_invoice[$lineIndex]->id.' fk_prev_id='.$source_fk_prev_id.' will be fk_prev_id='.$line->fk_prev_id.' '.$line->total_ht.' '.$line->situation_percent.'<br>';
  332. // If there is some credit note between last situation invoice and invoice used for credit note generation (note: credit notes are stored as delta)
  333. $maxPrevSituationPercent = 0;
  334. foreach ($tab_jumped_credit_notes as $index => $creditnoteid) {
  335. foreach ($invoice->tab_previous_situation_invoice[$index]->lines as $prevLine) {
  336. if ($prevLine->fk_prev_id == $source_fk_prev_id) {
  337. $maxPrevSituationPercent = $prevLine->situation_percent;
  338. $line->total_ht -= $prevLine->total_ht;
  339. $line->total_tva -= $prevLine->total_tva;
  340. $line->total_ttc -= $prevLine->total_ttc;
  341. $line->total_localtax1 -= $prevLine->total_localtax1;
  342. $line->total_localtax2 -= $prevLine->total_localtax2;
  343. $line->multicurrency_subprice -= $prevLine->multicurrency_subprice;
  344. $line->multicurrency_total_ht -= $prevLine->multicurrency_total_ht;
  345. $line->multicurrency_total_tva -= $prevLine->multicurrency_total_tva;
  346. $line->multicurrency_total_ttc -= $prevLine->multicurrency_total_ttc;
  347. }
  348. }
  349. }
  350. // prorata
  351. $line->situation_percent += $maxPrevSituationPercent;
  352. //print 'New line based on invoice id '.$invoice->tab_previous_situation_invoice[$lineIndex]->id.' fk_prev_id='.$source_fk_prev_id.' will be fk_prev_id='.$line->fk_prev_id.' '.$line->total_ht.' '.$line->situation_percent.'<br>';
  353. }
  354. }
  355. }
  356. $line->fk_facture = $creditnote->id;
  357. $line->fk_parent_line = $fk_parent_line;
  358. $line->subprice = -$line->subprice; // invert price for object
  359. $line->pa_ht = $line->pa_ht; // we choosed to have buy/cost price always positive, so no revert of sign here
  360. $line->total_ht = -$line->total_ht;
  361. $line->total_tva = -$line->total_tva;
  362. $line->total_ttc = -$line->total_ttc;
  363. $line->total_localtax1 = -$line->total_localtax1;
  364. $line->total_localtax2 = -$line->total_localtax2;
  365. $line->multicurrency_subprice = -$line->multicurrency_subprice;
  366. $line->multicurrency_total_ht = -$line->multicurrency_total_ht;
  367. $line->multicurrency_total_tva = -$line->multicurrency_total_tva;
  368. $line->multicurrency_total_ttc = -$line->multicurrency_total_ttc;
  369. $result = $line->insert(0, 1); // When creating credit note with same lines than source, we must ignore error if discount alreayd linked
  370. $creditnote->lines[] = $line; // insert new line in current object
  371. // Defined the new fk_parent_line
  372. if ($result > 0 && $line->product_type == 9) {
  373. $fk_parent_line = $result;
  374. }
  375. }
  376. $creditnote->update_price(1);
  377. $constantforkey = 'CASHDESK_NO_DECREASE_STOCK'.$_SESSION["takeposterminal"];
  378. if (isModEnabled('stock') && $conf->global->$constantforkey != "1") {
  379. $savconst = $conf->global->STOCK_CALCULATE_ON_BILL;
  380. $conf->global->STOCK_CALCULATE_ON_BILL = 1;
  381. $constantforkey = 'CASHDESK_ID_WAREHOUSE'.$_SESSION["takeposterminal"];
  382. dol_syslog("Validate invoice with stock change into warehouse defined into constant ".$constantforkey." = ".$conf->global->$constantforkey);
  383. $batch_rule = 0;
  384. if (isModEnabled('productbatch') && !empty($conf->global->CASHDESK_FORCE_DECREASE_STOCK)) {
  385. require_once DOL_DOCUMENT_ROOT.'/product/class/productbatch.class.php';
  386. $batch_rule = Productbatch::BATCH_RULE_SELLBY_EATBY_DATES_FIRST;
  387. }
  388. $res = $creditnote->validate($user, '', $conf->global->$constantforkey, 0, $batch_rule);
  389. $conf->global->STOCK_CALCULATE_ON_BILL = $savconst;
  390. } else {
  391. $res = $creditnote->validate($user);
  392. }
  393. }
  394. if ($action == 'history' || $action == 'creditnote') {
  395. if ($action == 'creditnote') {
  396. $placeid = $creditnote->id;
  397. } else {
  398. $placeid = (int) GETPOST('placeid', 'int');
  399. }
  400. $invoice = new Facture($db);
  401. $invoice->fetch($placeid);
  402. }
  403. if (($action == "addline" || $action == "freezone") && $placeid == 0) {
  404. $invoice->socid = getDolGlobalString("$constforcompanyid");
  405. $invoice->date = dol_now();
  406. $invoice->module_source = 'takepos';
  407. $invoice->pos_source = isset($_SESSION["takeposterminal"]) ? $_SESSION["takeposterminal"] : '' ;
  408. $invoice->entity = !empty($_SESSION["takeposinvoiceentity"]) ? $_SESSION["takeposinvoiceentity"] : $conf->entity;
  409. if ($invoice->socid <= 0) {
  410. $langs->load('errors');
  411. dol_htmloutput_errors($langs->trans("ErrorModuleSetupNotComplete", "TakePos"), null, 1);
  412. } else {
  413. $placeid = $invoice->create($user);
  414. if ($placeid < 0) {
  415. dol_htmloutput_errors($invoice->error, $invoice->errors, 1);
  416. }
  417. $sql = "UPDATE ".MAIN_DB_PREFIX."facture set ref='(PROV-POS".$_SESSION["takeposterminal"]."-".$place.")' where rowid = ".((int) $placeid);
  418. $db->query($sql);
  419. }
  420. }
  421. if ($action == "addline") {
  422. $prod = new Product($db);
  423. $prod->fetch($idproduct);
  424. $customer = new Societe($db);
  425. $customer->fetch($invoice->socid);
  426. $datapriceofproduct = $prod->getSellPrice($mysoc, $customer, 0);
  427. $qty = GETPOSTISSET('qty') ? GETPOST('qty', 'int') : 1;
  428. $price = $datapriceofproduct['pu_ht'];
  429. $price_ttc = $datapriceofproduct['pu_ttc'];
  430. //$price_min = $datapriceofproduct['price_min'];
  431. $price_base_type = $datapriceofproduct['price_base_type'];
  432. $tva_tx = $datapriceofproduct['tva_tx'];
  433. $tva_npr = $datapriceofproduct['tva_npr'];
  434. // Local Taxes
  435. $localtax1_tx = get_localtax($tva_tx, 1, $customer, $mysoc, $tva_npr);
  436. $localtax2_tx = get_localtax($tva_tx, 2, $customer, $mysoc, $tva_npr);
  437. if (!empty($conf->global->TAKEPOS_SUPPLEMENTS)) {
  438. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  439. $cat = new Categorie($db);
  440. $categories = $cat->containing($idproduct, 'product');
  441. $found = (array_search($conf->global->TAKEPOS_SUPPLEMENTS_CATEGORY, array_column($categories, 'id')));
  442. if ($found !== false) { // If this product is a supplement
  443. $sql = "SELECT fk_parent_line FROM ".MAIN_DB_PREFIX."facturedet where rowid=$selectedline";
  444. $resql = $db->query($sql);
  445. $row = $db->fetch_array($resql);
  446. if ($row[0] == null) {
  447. $parent_line = $selectedline;
  448. } else {
  449. $parent_line = $row[0]; //If the parent line is already a supplement, add the supplement to the main product
  450. }
  451. }
  452. }
  453. $idoflineadded = 0;
  454. // Group if enabled. Skip group if line already sent to the printer
  455. if (!empty($conf->global->TAKEPOS_GROUP_SAME_PRODUCT)) {
  456. foreach ($invoice->lines as $line) {
  457. if ($line->product_ref == $prod->ref) {
  458. if ($line->special_code==4) continue; // If this line is sended to printer create new line
  459. $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);
  460. if ($result < 0) {
  461. dol_htmloutput_errors($invoice->error, $invoice->errors, 1);
  462. } else {
  463. $idoflineadded = $line->id;
  464. }
  465. break;
  466. }
  467. }
  468. }
  469. if ($idoflineadded <= 0) {
  470. $invoice->fetch_thirdparty();
  471. $array_options = array();
  472. $line = array('description' => $prod->description, 'price' => $price, 'tva_tx' => $tva_tx, 'locatax1_tx' => $localtax1_tx, 'locatax2_tx' => $localtax2_tx, 'remise_percent' => $customer->remise_percent, 'price_ttc' => $price_ttc, 'array_options' => $array_options);
  473. /* setup of margin calculation */
  474. if (isset($conf->global->MARGIN_TYPE)) {
  475. if ($conf->global->MARGIN_TYPE == 'pmp' && !empty($prod->pmp)) {
  476. $line['fk_fournprice'] = null;
  477. $line['pa_ht'] = $prod->pmp;
  478. } elseif ($conf->global->MARGIN_TYPE == 'costprice' && !empty($prod->cost_price)) {
  479. $line['fk_fournprice'] = null;
  480. $line['pa_ht'] = $prod->cost_price;
  481. } else {
  482. // default is fournprice
  483. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
  484. $pf = new ProductFournisseur($db);
  485. if ($pf->find_min_price_product_fournisseur($idproduct, $qty) > 0) {
  486. $line['fk_fournprice'] = $pf->product_fourn_price_id;
  487. $line['pa_ht'] = $pf->fourn_unitprice_with_discount;
  488. if ($pf->fourn_charges > 0)
  489. $line['pa_ht'] += $pf->fourn_charges / $pf->fourn_qty;
  490. }
  491. }
  492. }
  493. // complete line by hook
  494. $parameters = array('prod' => $prod, 'line' => $line);
  495. $reshook=$hookmanager->executeHooks('completeTakePosAddLine', $parameters, $invoice, $action); // Note that $action and $line may have been modified by some hooks
  496. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  497. if (empty($reshook)) {
  498. if (!empty($hookmanager->resArray)) {
  499. $line = $hookmanager->resArray;
  500. }
  501. $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 : '', $line['fk_fournprice'], $line['pa_ht'], '', $line['array_options'], 100, '', null, 0);
  502. }
  503. if (!empty($conf->global->TAKEPOS_CUSTOMER_DISPLAY)) {
  504. $CUSTOMER_DISPLAY_line1 = $prod->label;
  505. $CUSTOMER_DISPLAY_line2 = price($price_ttc);
  506. }
  507. }
  508. $invoice->fetch($placeid);
  509. }
  510. if ($action == "freezone") {
  511. $customer = new Societe($db);
  512. $customer->fetch($invoice->socid);
  513. $tva_tx = GETPOST('tva_tx', 'alpha');
  514. if ($tva_tx != '') {
  515. if (!preg_match('/\((.*)\)/', $tva_tx)) {
  516. $tva_tx = price2num($tva_tx);
  517. }
  518. } else {
  519. $tva_tx = get_default_tva($mysoc, $customer);
  520. }
  521. // Local Taxes
  522. $localtax1_tx = get_localtax($tva_tx, 1, $customer, $mysoc, $tva_npr);
  523. $localtax2_tx = get_localtax($tva_tx, 2, $customer, $mysoc, $tva_npr);
  524. $invoice->addline($desc, $number, 1, $tva_tx, $localtax1_tx, $localtax2_tx, 0, 0, '', 0, 0, 0, '', getDolGlobalInt('TAKEPOS_CHANGE_PRICE_HT') ? 'HT' : 'TTC', $number, 0, -1, 0, '', 0, 0, null, '', '', 0, 100, '', null, 0);
  525. $invoice->fetch($placeid);
  526. }
  527. if ($action == "addnote") {
  528. $desc = GETPOST('addnote', 'alpha');
  529. if ($idline==0) {
  530. $invoice->update_note($desc, '_public');
  531. } else foreach ($invoice->lines as $line) {
  532. if ($line->id == $idline) {
  533. $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);
  534. }
  535. }
  536. $invoice->fetch($placeid);
  537. }
  538. if ($action == "deleteline") {
  539. if ($idline > 0 and $placeid > 0) { // If invoice exists and line selected. To avoid errors if deleted from another device or no line selected.
  540. $invoice->deleteline($idline);
  541. $invoice->fetch($placeid);
  542. } elseif ($placeid > 0) { // If invoice exists but no line selected, proceed to delete last line.
  543. $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."facturedet where fk_facture = ".((int) $placeid)." ORDER BY rowid DESC";
  544. $resql = $db->query($sql);
  545. $row = $db->fetch_array($resql);
  546. $deletelineid = $row[0];
  547. $invoice->deleteline($deletelineid);
  548. $invoice->fetch($placeid);
  549. }
  550. if (count($invoice->lines) == 0) {
  551. $invoice->delete($user);
  552. header("Location: ".DOL_URL_ROOT."/takepos/invoice.php");
  553. exit;
  554. }
  555. }
  556. // Action to delete or discard an invoice
  557. if ($action == "delete") {
  558. // $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.
  559. if ($placeid > 0) {
  560. $result = $invoice->fetch($placeid);
  561. if ($result > 0 && $invoice->statut == Facture::STATUS_DRAFT) {
  562. $db->begin();
  563. // We delete the lines
  564. $resdeletelines = 1;
  565. foreach ($invoice->lines as $line) {
  566. $tmpres = $invoice->deleteline($line->id);
  567. if ($tmpres < 0) {
  568. $resdeletelines = 0;
  569. break;
  570. }
  571. }
  572. $sql = "UPDATE ".MAIN_DB_PREFIX."facture";
  573. $varforconst = 'CASHDESK_ID_THIRDPARTY'.$_SESSION["takeposterminal"];
  574. $sql .= " SET fk_soc = ".((int) $conf->global->$varforconst).", ";
  575. $sql .= " datec = '".$db->idate(dol_now())."'";
  576. $sql .= " WHERE ref = '(PROV-POS".$db->escape($_SESSION["takeposterminal"]."-".$place).")'";
  577. $resql1 = $db->query($sql);
  578. if ($resdeletelines && $resql1) {
  579. $db->commit();
  580. } else {
  581. $db->rollback();
  582. }
  583. $invoice->fetch($placeid);
  584. }
  585. }
  586. }
  587. if ($action == "updateqty") {
  588. foreach ($invoice->lines as $line) {
  589. if ($line->id == $idline) {
  590. if (!$user->rights->takepos->editlines || (!$user->rights->takepos->editorderedlines && $line->special_code == "4")) {
  591. dol_htmloutput_errors($langs->trans("NotEnoughPermissions", "TakePos"), null, 1);
  592. } else {
  593. $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);
  594. }
  595. }
  596. }
  597. $invoice->fetch($placeid);
  598. }
  599. if ($action == "updateprice") {
  600. $customer = new Societe($db);
  601. $customer->fetch($invoice->socid);
  602. foreach ($invoice->lines as $line) {
  603. if ($line->id == $idline) {
  604. $prod = new Product($db);
  605. $prod->fetch($line->fk_product);
  606. $datapriceofproduct = $prod->getSellPrice($mysoc, $customer, 0);
  607. $price_min = $datapriceofproduct['price_min'];
  608. $usercanproductignorepricemin = ((!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->produit->ignore_price_min_advance)) || empty($conf->global->MAIN_USE_ADVANCED_PERMS));
  609. $pu_ht = price2num($number / (1 + ($line->tva_tx / 100)), 'MU');
  610. //Check min price
  611. if ($usercanproductignorepricemin && (!empty($price_min) && (price2num($pu_ht) * (1 - price2num($line->remise_percent) / 100) < price2num($price_min)))) {
  612. $langs->load("products");
  613. dol_htmloutput_errors($langs->trans("CantBeLessThanMinPrice", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, -1, $conf->currency)));
  614. //echo $langs->trans("CantBeLessThanMinPrice");
  615. } else {
  616. if (empty($user->rights->takepos->editlines) || (empty($user->rights->takepos->editorderedlines) && $line->special_code == "4")) {
  617. dol_htmloutput_errors($langs->trans("NotEnoughPermissions", "TakePos"), null, 1);
  618. } elseif (getDolGlobalInt('TAKEPOS_CHANGE_PRICE_HT') == 1) {
  619. $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);
  620. } else {
  621. $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);
  622. }
  623. }
  624. }
  625. }
  626. // Reload data
  627. $invoice->fetch($placeid);
  628. }
  629. if ($action == "updatereduction") {
  630. $customer = new Societe($db);
  631. $customer->fetch($invoice->socid);
  632. foreach ($invoice->lines as $line) {
  633. if ($line->id == $idline) {
  634. dol_syslog("updatereduction Process line ".$line->id.' to apply discount of '.$number.'%');
  635. $prod = new Product($db);
  636. $prod->fetch($line->fk_product);
  637. $datapriceofproduct = $prod->getSellPrice($mysoc, $customer, 0);
  638. $price_min = $datapriceofproduct['price_min'];
  639. $usercanproductignorepricemin = ((!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->produit->ignore_price_min_advance)) || empty($conf->global->MAIN_USE_ADVANCED_PERMS));
  640. $pu_ht = price2num($line->subprice / (1 + ($line->tva_tx / 100)), 'MU');
  641. // Check min price
  642. if ($usercanproductignorepricemin && (!empty($price_min) && (price2num($line->subprice) * (1 - price2num($number) / 100) < price2num($price_min)))) {
  643. $langs->load("products");
  644. dol_htmloutput_errors($langs->trans("CantBeLessThanMinPrice", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, -1, $conf->currency)));
  645. } else {
  646. if (empty($user->rights->takepos->editlines) || (empty($user->rights->takepos->editorderedlines) && $line->special_code == "4")) {
  647. dol_htmloutput_errors($langs->trans("NotEnoughPermissions", "TakePos"), null, 1);
  648. } else {
  649. $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);
  650. }
  651. }
  652. }
  653. }
  654. // Reload data
  655. $invoice->fetch($placeid);
  656. } elseif ($action == 'update_reduction_global') {
  657. foreach ($invoice->lines as $line) {
  658. $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);
  659. }
  660. $invoice->fetch($placeid);
  661. }
  662. if ($action == "order" and $placeid != 0) {
  663. include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  664. if ($conf->global->TAKEPOS_PRINT_METHOD == "receiptprinter" || $conf->global->TAKEPOS_PRINT_METHOD == "takeposconnector") {
  665. require_once DOL_DOCUMENT_ROOT.'/core/class/dolreceiptprinter.class.php';
  666. $printer = new dolReceiptPrinter($db);
  667. }
  668. $sql = "SELECT label FROM ".MAIN_DB_PREFIX."takepos_floor_tables where rowid=".((int) $place);
  669. $resql = $db->query($sql);
  670. $row = $db->fetch_object($resql);
  671. $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>';
  672. $footerorder = '</tbody></table>'.dol_print_date(dol_now(), 'dayhour').'<br></html>';
  673. $order_receipt_printer1 = "";
  674. $order_receipt_printer2 = "";
  675. $order_receipt_printer3 = "";
  676. $catsprinter1 = explode(';', $conf->global->TAKEPOS_PRINTED_CATEGORIES_1);
  677. $catsprinter2 = explode(';', $conf->global->TAKEPOS_PRINTED_CATEGORIES_2);
  678. $catsprinter3 = explode(';', $conf->global->TAKEPOS_PRINTED_CATEGORIES_3);
  679. $linestoprint = 0;
  680. foreach ($invoice->lines as $line) {
  681. if ($line->special_code == "4") {
  682. continue;
  683. }
  684. $c = new Categorie($db);
  685. $existing = $c->containing($line->fk_product, Categorie::TYPE_PRODUCT, 'id');
  686. $result = array_intersect($catsprinter1, $existing);
  687. $count = count($result);
  688. if (!$line->fk_product) {
  689. $count++; // Print Free-text item (Unassigned printer) to Printer 1
  690. }
  691. if ($count > 0) {
  692. $linestoprint++;
  693. $sql = "UPDATE ".MAIN_DB_PREFIX."facturedet set special_code='1' where rowid=".$line->id; //Set to print on printer 1
  694. $db->query($sql);
  695. $order_receipt_printer1 .= '<tr><td class="left">';
  696. if ($line->fk_product) {
  697. $order_receipt_printer1 .= $line->product_label;
  698. } else {
  699. $order_receipt_printer1 .= $line->description;
  700. }
  701. $order_receipt_printer1 .= '</td><td class="right">'.$line->qty;
  702. if (!empty($line->array_options['options_order_notes'])) {
  703. $order_receipt_printer1 .= "<br>(".$line->array_options['options_order_notes'].")";
  704. }
  705. $order_receipt_printer1 .= '</td></tr>';
  706. }
  707. }
  708. if (($conf->global->TAKEPOS_PRINT_METHOD == "receiptprinter" || $conf->global->TAKEPOS_PRINT_METHOD == "takeposconnector") && $linestoprint > 0) {
  709. $invoice->fetch($placeid); //Reload object before send to printer
  710. $printer->orderprinter = 1;
  711. echo "<script>";
  712. echo "var orderprinter1esc='";
  713. $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
  714. echo "';</script>";
  715. }
  716. $sql = "UPDATE ".MAIN_DB_PREFIX."facturedet set special_code='4' where special_code='1' and fk_facture=".$invoice->id; // Set as printed
  717. $db->query($sql);
  718. $invoice->fetch($placeid); //Reload object after set lines as printed
  719. $linestoprint = 0;
  720. foreach ($invoice->lines as $line) {
  721. if ($line->special_code == "4") {
  722. continue;
  723. }
  724. $c = new Categorie($db);
  725. $existing = $c->containing($line->fk_product, Categorie::TYPE_PRODUCT, 'id');
  726. $result = array_intersect($catsprinter2, $existing);
  727. $count = count($result);
  728. if ($count > 0) {
  729. $linestoprint++;
  730. $sql = "UPDATE ".MAIN_DB_PREFIX."facturedet set special_code='2' where rowid=".$line->id; //Set to print on printer 2
  731. $db->query($sql);
  732. $order_receipt_printer2 .= '<tr>'.$line->product_label.'<td class="right">'.$line->qty;
  733. if (!empty($line->array_options['options_order_notes'])) {
  734. $order_receipt_printer2 .= "<br>(".$line->array_options['options_order_notes'].")";
  735. }
  736. $order_receipt_printer2 .= '</td></tr>';
  737. }
  738. }
  739. if (($conf->global->TAKEPOS_PRINT_METHOD == "receiptprinter" || $conf->global->TAKEPOS_PRINT_METHOD == "takeposconnector") && $linestoprint > 0) {
  740. $invoice->fetch($placeid); //Reload object before send to printer
  741. $printer->orderprinter = 2;
  742. echo "<script>";
  743. echo "var orderprinter2esc='";
  744. $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
  745. echo "';</script>";
  746. }
  747. $sql = "UPDATE ".MAIN_DB_PREFIX."facturedet set special_code='4' where special_code='2' and fk_facture=".$invoice->id; // Set as printed
  748. $db->query($sql);
  749. $invoice->fetch($placeid); //Reload object after set lines as printed
  750. $linestoprint = 0;
  751. foreach ($invoice->lines as $line) {
  752. if ($line->special_code == "4") {
  753. continue;
  754. }
  755. $c = new Categorie($db);
  756. $existing = $c->containing($line->fk_product, Categorie::TYPE_PRODUCT, 'id');
  757. $result = array_intersect($catsprinter3, $existing);
  758. $count = count($result);
  759. if ($count > 0) {
  760. $linestoprint++;
  761. $sql = "UPDATE ".MAIN_DB_PREFIX."facturedet set special_code='3' where rowid=".$line->id; //Set to print on printer 3
  762. $db->query($sql);
  763. $order_receipt_printer3 .= '<tr>'.$line->product_label.'<td class="right">'.$line->qty;
  764. if (!empty($line->array_options['options_order_notes'])) {
  765. $order_receipt_printer3 .= "<br>(".$line->array_options['options_order_notes'].")";
  766. }
  767. $order_receipt_printer3 .= '</td></tr>';
  768. }
  769. }
  770. if (($conf->global->TAKEPOS_PRINT_METHOD == "receiptprinter" || $conf->global->TAKEPOS_PRINT_METHOD == "takeposconnector") && $linestoprint > 0) {
  771. $invoice->fetch($placeid); //Reload object before send to printer
  772. $printer->orderprinter = 3;
  773. echo "<script>";
  774. echo "var orderprinter3esc='";
  775. $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
  776. echo "';</script>";
  777. }
  778. $sql = "UPDATE ".MAIN_DB_PREFIX."facturedet set special_code='4' where special_code='3' and fk_facture=".$invoice->id; // Set as printed
  779. $db->query($sql);
  780. $invoice->fetch($placeid); //Reload object after set lines as printed
  781. }
  782. $sectionwithinvoicelink = '';
  783. if ($action == "valid" || $action == "history" || $action == 'creditnote') {
  784. $sectionwithinvoicelink .= '<!-- Section with invoice link -->'."\n";
  785. $sectionwithinvoicelink .= '<span style="font-size:120%;" class="center">';
  786. $sectionwithinvoicelink .= $invoice->getNomUrl(1, '', 0, 0, '', 0, 0, -1, '_backoffice')." - ";
  787. $remaintopay = $invoice->getRemainToPay();
  788. if ($remaintopay > 0) {
  789. $sectionwithinvoicelink .= $langs->trans('RemainToPay').': <span class="amountremaintopay" style="font-size: unset">'.price($remaintopay, 1, $langs, 1, -1, -1, $conf->currency).'</span>';
  790. } else {
  791. if ($invoice->paye) {
  792. $sectionwithinvoicelink .= '<span class="amountpaymentcomplete" style="font-size: unset">'.$langs->trans("Paid").'</span>';
  793. } else {
  794. $sectionwithinvoicelink .= $langs->trans('BillShortStatusValidated');
  795. }
  796. }
  797. $sectionwithinvoicelink .= '</span><br>';
  798. if (getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector") {
  799. if (getDolGlobalString('TAKEPOS_PRINT_SERVER') && filter_var($conf->global->TAKEPOS_PRINT_SERVER, FILTER_VALIDATE_URL) == true) {
  800. $sectionwithinvoicelink .= ' <button id="buttonprint" type="button" onclick="TakeposConnector('.$placeid.');">'.$langs->trans('PrintTicket').'</button>';
  801. } else {
  802. $sectionwithinvoicelink .= ' <button id="buttonprint" type="button" onclick="TakeposPrinting('.$placeid.');">'.$langs->trans('PrintTicket').'</button>';
  803. }
  804. } elseif (getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter") {
  805. $sectionwithinvoicelink .= ' <button id="buttonprint" type="button" onclick="DolibarrTakeposPrinting('.$placeid.');">'.$langs->trans('PrintTicket').'</button>';
  806. } else {
  807. $sectionwithinvoicelink .= ' <button id="buttonprint" type="button" onclick="Print('.$placeid.');">'.$langs->trans('PrintTicket').'</button>';
  808. if (getDolGlobalString('TAKEPOS_PRINT_WITHOUT_DETAILS')) {
  809. $sectionwithinvoicelink .= ' <button id="buttonprint" type="button" onclick="PrintBox('.$placeid.', \'without_details\');">'.$langs->trans('PrintWithoutDetails').'</button>';
  810. }
  811. if (getDolGlobalString('TAKEPOS_GIFT_RECEIPT')) {
  812. $sectionwithinvoicelink .= ' <button id="buttonprint" type="button" onclick="Print('.$placeid.', 1);">'.$langs->trans('GiftReceipt').'</button>';
  813. }
  814. }
  815. if (getDolGlobalString('TAKEPOS_EMAIL_TEMPLATE_INVOICE') && $conf->global->TAKEPOS_EMAIL_TEMPLATE_INVOICE > 0) {
  816. $sectionwithinvoicelink .= ' <button id="buttonsend" type="button" onclick="SendTicket('.$placeid.');">'.$langs->trans('SendTicket').'</button>';
  817. }
  818. if ($remaintopay <= 0 && getDolGlobalString('TAKEPOS_AUTO_PRINT_TICKETS') && $action != "history") {
  819. $sectionwithinvoicelink .= '<script type="text/javascript">$("#buttonprint").click();</script>';
  820. }
  821. }
  822. }
  823. /*
  824. * View
  825. */
  826. $form = new Form($db);
  827. // llxHeader
  828. if ((getDolGlobalString('TAKEPOS_PHONE_BASIC_LAYOUT') == 1 && $conf->browser->layout == 'phone') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
  829. $title = 'TakePOS - Dolibarr '.DOL_VERSION;
  830. if (!empty($conf->global->MAIN_APPLICATION_TITLE)) {
  831. $title = 'TakePOS - '.$conf->global->MAIN_APPLICATION_TITLE;
  832. }
  833. $head = '<meta name="apple-mobile-web-app-title" content="TakePOS"/>
  834. <meta name="apple-mobile-web-app-capable" content="yes">
  835. <meta name="mobile-web-app-capable" content="yes">
  836. <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>';
  837. $arrayofcss = array(
  838. '/takepos/css/pos.css.php',
  839. );
  840. $arrayofjs = array('/takepos/js/jquery.colorbox-min.js');
  841. $disablejs = 0;
  842. $disablehead = 0;
  843. top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss);
  844. print '<body>'."\n";
  845. } else {
  846. top_httphead('text/html', 1);
  847. }
  848. ?>
  849. <!-- invoice.php -->
  850. <script type="text/javascript">
  851. var selectedline=0;
  852. var selectedtext="";
  853. <?php if ($action=="valid") echo "var place=0;";?> // Set to default place after close sale
  854. var placeid=<?php echo ($placeid > 0 ? $placeid : 0); ?>;
  855. $(document).ready(function() {
  856. var idoflineadded = <?php echo (empty($idoflineadded) ? 0 : $idoflineadded); ?>;
  857. $('.posinvoiceline').click(function(){
  858. console.log("Click done on "+this.id);
  859. $('.posinvoiceline').removeClass("selected");
  860. $(this).addClass("selected");
  861. if (selectedline==this.id) return; // If is already selected
  862. else selectedline=this.id;
  863. selectedtext=$('#'+selectedline).find("td:first").html();
  864. <?php
  865. if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
  866. print '$("#phonediv1").load("auto_order.php?action=editline&token='.newToken().'&placeid="+placeid+"&selectedline="+selectedline, function() {
  867. });';
  868. }
  869. ?>
  870. });
  871. /* Autoselect the line */
  872. if (idoflineadded > 0)
  873. {
  874. console.log("Auto select "+idoflineadded);
  875. $('.posinvoiceline#'+idoflineadded).click();
  876. }
  877. <?php
  878. if ($action == "order" && !empty($order_receipt_printer1)) {
  879. if (filter_var($conf->global->TAKEPOS_PRINT_SERVER, FILTER_VALIDATE_URL) == true) {
  880. ?>
  881. $.ajax({
  882. type: "POST",
  883. url: '<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>/printer/index.php',
  884. data: 'invoice='+orderprinter1esc
  885. });
  886. <?php
  887. } else {
  888. ?>
  889. $.ajax({
  890. type: "POST",
  891. url: 'http://<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>:8111/print',
  892. data: '<?php
  893. print $headerorder.$order_receipt_printer1.$footerorder; ?>'
  894. });
  895. <?php
  896. }
  897. }
  898. if ($action == "order" && !empty($order_receipt_printer2)) {
  899. if (filter_var($conf->global->TAKEPOS_PRINT_SERVER, FILTER_VALIDATE_URL) == true) {
  900. ?>
  901. $.ajax({
  902. type: "POST",
  903. url: '<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>/printer/index.php?printer=2',
  904. data: 'invoice='+orderprinter2esc
  905. });
  906. <?php
  907. } else {
  908. ?>
  909. $.ajax({
  910. type: "POST",
  911. url: 'http://<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>:8111/print2',
  912. data: '<?php
  913. print $headerorder.$order_receipt_printer2.$footerorder; ?>'
  914. });
  915. <?php
  916. }
  917. }
  918. if ($action == "order" && !empty($order_receipt_printer3)) {
  919. if (filter_var($conf->global->TAKEPOS_PRINT_SERVER, FILTER_VALIDATE_URL) == true) {
  920. ?>
  921. $.ajax({
  922. type: "POST",
  923. url: '<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>/printer/index.php?printer=3',
  924. data: 'invoice='+orderprinter3esc
  925. });
  926. <?php
  927. }
  928. }
  929. // Set focus to search field
  930. if ($action == "search" || $action == "valid") {
  931. ?>
  932. parent.setFocusOnSearchField();
  933. <?php
  934. }
  935. if ($action == "temp" && !empty($ticket_printer1)) {
  936. ?>
  937. $.ajax({
  938. type: "POST",
  939. url: 'http://<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>:8111/print',
  940. data: '<?php
  941. print $header_soc.$header_ticket.$body_ticket.$ticket_printer1.$ticket_total.$footer_ticket; ?>'
  942. });
  943. <?php
  944. }
  945. if ($action == "search") {
  946. ?>
  947. $('#search').focus();
  948. <?php
  949. }
  950. ?>
  951. });
  952. function SendTicket(id)
  953. {
  954. console.log("Open box to select the Print/Send form");
  955. $.colorbox({href:"send.php?facid="+id, width:"70%", height:"30%", transition:"none", iframe:"true", title:'<?php echo dol_escape_js($langs->trans("SendTicket")); ?>'});
  956. }
  957. function PrintBox(id, action) {
  958. console.log("Open box before printing");
  959. $.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"); ?>"});
  960. }
  961. function Print(id, gift){
  962. console.log("Call Print() to generate the receipt.");
  963. $.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")); ?>'});
  964. }
  965. function TakeposPrinting(id){
  966. var receipt;
  967. console.log("TakeposPrinting" + id);
  968. $.get("receipt.php?facid="+id, function(data, status) {
  969. receipt=data.replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '');
  970. $.ajax({
  971. type: "POST",
  972. url: 'http://<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER'); ?>:8111/print',
  973. data: receipt
  974. });
  975. });
  976. }
  977. function TakeposConnector(id){
  978. console.log("TakeposConnector" + id);
  979. $.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) {
  980. $.ajax({
  981. type: "POST",
  982. url: '<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER'); ?>/printer/index.php',
  983. data: 'invoice='+data
  984. });
  985. });
  986. }
  987. function DolibarrTakeposPrinting(id) {
  988. console.log("DolibarrTakeposPrinting Printing invoice ticket " + id)
  989. $.ajax({
  990. type: "GET",
  991. data: { token: '<?php echo currentToken(); ?>' },
  992. url: "<?php print DOL_URL_ROOT.'/takepos/ajax/ajax.php?action=printinvoiceticket&token='.newToken().'&term='.urlencode(isset($_SESSION["takeposterminal"]) ? $_SESSION["takeposterminal"] : '').'&id='; ?>" + id,
  993. });
  994. }
  995. function CreditNote() {
  996. $("#poslines").load("invoice.php?action=creditnote&token=<?php echo newToken() ?>&invoiceid="+placeid, function() {
  997. });
  998. }
  999. function SetNote() {
  1000. $("#poslines").load("invoice.php?action=addnote&token=<?php echo newToken() ?>&invoiceid="+placeid+"&idline="+selectedline, { "addnote": $("#textinput").val() });
  1001. }
  1002. $( document ).ready(function() {
  1003. console.log("Set customer info and sales in header placeid=<?php echo $placeid; ?> status=<?php echo $invoice->statut; ?>");
  1004. <?php
  1005. $s = $langs->trans("Customer");
  1006. if ($invoice->id > 0 && ($invoice->socid != $conf->global->$constforcompanyid)) {
  1007. $s = $soc->name;
  1008. }
  1009. ?>
  1010. $("#customerandsales").html('');
  1011. $("#shoppingcart").html('');
  1012. $("#customerandsales").append('<a class="valignmiddle tdoverflowmax100 minwidth100" id="customer" onclick="Customer();" title="<?php print dol_escape_js($s); ?>"><span class="fas fa-building paddingrightonly"></span><?php print dol_escape_js($s); ?></a>');
  1013. <?php
  1014. $sql = "SELECT rowid, datec, ref FROM ".MAIN_DB_PREFIX."facture";
  1015. if (empty($conf->global->TAKEPOS_CAN_EDIT_IF_ALREADY_VALIDATED)) {
  1016. // By default, only invoices with a ref not already defined can in list of open invoice we can edit.
  1017. $sql .= " WHERE ref LIKE '(PROV-POS".$db->escape(isset($_SESSION["takeposterminal"]) ? $_SESSION["takeposterminal"] : '')."-0%' AND entity IN (".getEntity('invoice').")";
  1018. } else {
  1019. // If TAKEPOS_CAN_EDIT_IF_ALREADY_VALIDATED set, we show also draft invoice that already has a reference defined
  1020. $sql .= " WHERE pos_source = '".$db->escape($_SESSION["takeposterminal"])."'";
  1021. $sql .= " AND module_source = 'takepos'";
  1022. $sql .= " AND entity IN (".getEntity('invoice').")";
  1023. }
  1024. $sql .= $db->order('datec', 'ASC');
  1025. $resql = $db->query($sql);
  1026. if ($resql) {
  1027. $max_sale = 0;
  1028. while ($obj = $db->fetch_object($resql)) {
  1029. echo '$("#shoppingcart").append(\'';
  1030. 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=\\\'';
  1031. $num_sale = str_replace(")", "", str_replace("(PROV-POS".$_SESSION["takeposterminal"]."-", "", $obj->ref));
  1032. echo $num_sale;
  1033. if (str_replace("-", "", $num_sale) > $max_sale) {
  1034. $max_sale = str_replace("-", "", $num_sale);
  1035. }
  1036. echo '\\\'; invoiceid=\\\'';
  1037. echo $obj->rowid;
  1038. echo '\\\'; Refresh();">';
  1039. if ($placeid == $obj->rowid) {
  1040. echo '<span class="basketselected">';
  1041. } else {
  1042. echo '<span class="basketnotselected">';
  1043. }
  1044. echo '<span class="fa fa-shopping-cart paddingright"></span>'.dol_print_date($db->jdate($obj->datec), '%H:%M', 'tzuser');
  1045. echo '</span>';
  1046. echo '</a>\');';
  1047. }
  1048. echo '$("#shoppingcart").append(\'<a onclick="place=\\\'0-';
  1049. echo $max_sale + 1;
  1050. 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>\');';
  1051. } else {
  1052. dol_print_error($db);
  1053. }
  1054. $s = '';
  1055. $idwarehouse = 0;
  1056. $constantforkey = 'CASHDESK_NO_DECREASE_STOCK'. (isset($_SESSION["takeposterminal"]) ? $_SESSION["takeposterminal"] : '');
  1057. if (isModEnabled('stock')) {
  1058. if (getDolGlobalString("$constantforkey") != "1") {
  1059. $constantforkey = 'CASHDESK_ID_WAREHOUSE'. (isset($_SESSION["takeposterminal"]) ? $_SESSION["takeposterminal"] : '');
  1060. $idwarehouse = getDolGlobalString($constantforkey);
  1061. if ($idwarehouse > 0) {
  1062. $s = '<span class="small">';
  1063. $warehouse = new Entrepot($db);
  1064. $warehouse->fetch($idwarehouse);
  1065. $s .= '<span class="hideonsmartphone">'.$langs->trans("Warehouse").'<br></span>'.$warehouse->ref;
  1066. if ($warehouse->statut == Entrepot::STATUS_CLOSED) {
  1067. $s .= ' ('.$langs->trans("Closed").')';
  1068. }
  1069. $s .= '</span>';
  1070. print "$('#infowarehouse').html('".dol_escape_js($s)."');";
  1071. print '$("#infowarehouse").css("display", "inline-block");';
  1072. } else {
  1073. $s = '<span class="small hideonsmartphone">';
  1074. $s .= $langs->trans("StockChangeDisabled").'<br>'.$langs->trans("NoWarehouseDefinedForTerminal");
  1075. $s .= '</span>';
  1076. print "$('#infowarehouse').html('".dol_escape_js($s)."');";
  1077. if (!empty($conf->dol_optimize_smallscreen)) {
  1078. print '$("#infowarehouse").css("display", "none");';
  1079. }
  1080. }
  1081. } else {
  1082. $s = '<span class="small hideonsmartphone">'.$langs->trans("StockChangeDisabled").'</span>';
  1083. print "$('#infowarehouse').html('".dol_escape_js($s)."');";
  1084. if (!empty($conf->dol_optimize_smallscreen)) {
  1085. print '$("#infowarehouse").css("display", "none");';
  1086. }
  1087. }
  1088. }
  1089. // Module Adherent
  1090. $s = '';
  1091. if (isModEnabled('adherent') && $invoice->socid > 0 && $invoice->socid != $conf->global->$constforcompanyid) {
  1092. $s = '<span class="small">';
  1093. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
  1094. $langs->load("members");
  1095. $s .= $langs->trans("Member").': ';
  1096. $adh = new Adherent($db);
  1097. $result = $adh->fetch('', '', $invoice->socid);
  1098. if ($result > 0) {
  1099. $adh->ref = $adh->getFullName($langs);
  1100. if (empty($adh->statut) || $adh->statut == Adherent::STATUS_EXCLUDED ) {
  1101. $s .= "<s>";
  1102. }
  1103. $s .= $adh->getFullName($langs);
  1104. $s .= ' - '.$adh->type;
  1105. if ($adh->datefin) {
  1106. $s .= '<br>'.$langs->trans("SubscriptionEndDate").': '.dol_print_date($adh->datefin, 'day');
  1107. if ($adh->hasDelay()) {
  1108. $s .= " ".img_warning($langs->trans("Late"));
  1109. }
  1110. } else {
  1111. $s .= '<br>'.$langs->trans("SubscriptionNotReceived");
  1112. if ($adh->statut > 0) {
  1113. $s .= " ".img_warning($langs->trans("Late")); // displays delay Pictogram only if not a draft and not terminated
  1114. }
  1115. }
  1116. if (empty($adh->statut) || $adh->statut == Adherent::STATUS_EXCLUDED) {
  1117. $s .= "</s>";
  1118. }
  1119. } else {
  1120. $s .= '<br>'.$langs->trans("ThirdpartyNotLinkedToMember");
  1121. }
  1122. $s .= '</span>';
  1123. }
  1124. ?>
  1125. $("#moreinfo").html('<?php print dol_escape_js($s); ?>');
  1126. });
  1127. <?php
  1128. if (!empty($conf->global->TAKEPOS_CUSTOMER_DISPLAY)) {
  1129. echo "function CustomerDisplay(){";
  1130. echo "var line1='".$CUSTOMER_DISPLAY_line1."'.substring(0,20);";
  1131. echo "line1=line1.padEnd(20);";
  1132. echo "var line2='".$CUSTOMER_DISPLAY_line2."'.substring(0,20);";
  1133. echo "line2=line2.padEnd(20);";
  1134. echo "$.ajax({
  1135. type: 'GET',
  1136. data: { text: line1+line2 },
  1137. url: '".getDolGlobalString('TAKEPOS_PRINT_SERVER')."/display/index.php',
  1138. });";
  1139. echo "}";
  1140. }
  1141. ?>
  1142. </script>
  1143. <?php
  1144. // Add again js for footer because this content is injected into index.php page so all init
  1145. // for tooltip and other js beautifiers must be reexecuted too.
  1146. if (!empty($conf->use_javascript_ajax)) {
  1147. print "\n".'<!-- Includes JS Footer of Dolibarr -->'."\n";
  1148. print '<script src="'.DOL_URL_ROOT.'/core/js/lib_foot.js.php?lang='.$langs->defaultlang.'"></script>'."\n";
  1149. }
  1150. print '<!-- invoice.php place='.(int) $place.' invoice='.$invoice->ref.' mobilepage='.(empty($mobilepage) ? '' : $mobilepage).' $_SESSION["basiclayout"]='.(empty($_SESSION["basiclayout"])?'':$_SESSION["basiclayout"]).' conf->global->TAKEPOS_BAR_RESTAURANT='.getDolGlobalString('TAKEPOS_BAR_RESTAURANT').' -->'."\n";
  1151. print '<div class="div-table-responsive-no-min invoice">';
  1152. print '<table id="tablelines" class="noborder noshadow postablelines" width="100%">';
  1153. if ($sectionwithinvoicelink && ($mobilepage == "invoice" || $mobilepage == "")) {
  1154. if (!empty($conf->global->TAKEPOS_SHOW_HT)) {
  1155. print '<tr><td colspan="5">'.$sectionwithinvoicelink.'</td></tr>';
  1156. } else {
  1157. print '<tr><td colspan="4">'.$sectionwithinvoicelink.'</td></tr>';
  1158. }
  1159. }
  1160. print '<tr class="liste_titre nodrag nodrop">';
  1161. print '<td class="linecoldescription">';
  1162. // In phone version only show when it is invoice page
  1163. if (empty($mobilepage) || $mobilepage == "invoice") {
  1164. print '<input type="hidden" name="invoiceid" id="invoiceid" value="'.$invoice->id.'">';
  1165. }
  1166. if (getDolGlobalString('TAKEPOS_BAR_RESTAURANT')) {
  1167. $sql = "SELECT floor, label FROM ".MAIN_DB_PREFIX."takepos_floor_tables where rowid=".((int) $place);
  1168. $resql = $db->query($sql);
  1169. $obj = $db->fetch_object($resql);
  1170. if ($obj) {
  1171. $label = $obj->label;
  1172. $floor = $obj->floor;
  1173. }
  1174. if ($mobilepage == "invoice" || $mobilepage == "") {
  1175. // If not on smartphone version or if it is the invoice page
  1176. //print 'mobilepage='.$mobilepage;
  1177. print '<span class="opacitymedium">'.$langs->trans('Place')."</span> <b>".(empty($label) ? '?' : $label)."</b><br>";
  1178. print '<span class="opacitymedium">'.$langs->trans('Floor')."</span> <b>".(empty($floor) ? '?' : $floor)."</b>";
  1179. } elseif (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
  1180. print $mysoc->name;
  1181. } elseif ($mobilepage == "cats") {
  1182. print $langs->trans('Category');
  1183. } elseif ($mobilepage == "products") {
  1184. print $langs->trans('Label');
  1185. }
  1186. } else {
  1187. print $langs->trans("Products");
  1188. }
  1189. print '</td>';
  1190. // complete header by hook
  1191. $parameters=array();
  1192. $reshook=$hookmanager->executeHooks('completeTakePosInvoiceHeader', $parameters, $invoice, $action); // Note that $action and $object may have been modified by some hooks
  1193. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  1194. print $hookmanager->resPrint;
  1195. if (empty($_SESSION["basiclayout"]) || $_SESSION["basiclayout"] != 1) {
  1196. print '<td class="linecolqty right">'.$langs->trans('ReductionShort').'</td>';
  1197. print '<td class="linecolqty right">'.$langs->trans('Qty').'</td>';
  1198. if (getDolGlobalString('TAKEPOS_SHOW_HT')) {
  1199. print '<td class="linecolht right nowraponall">';
  1200. print '<span class="opacitymedium small">' . $langs->trans('TotalHTShort') . '</span><br>';
  1201. // In phone version only show when it is invoice page
  1202. if (empty($mobilepage) || $mobilepage == "invoice") {
  1203. 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>';
  1204. if (isModEnabled('multicurrency') && $_SESSION["takeposcustomercurrency"] != "" && $conf->currency != $_SESSION["takeposcustomercurrency"]) {
  1205. //Only show customer currency if multicurrency module is enabled, if currency selected and if this currency selected is not the same as main currency
  1206. include_once DOL_DOCUMENT_ROOT . '/multicurrency/class/multicurrency.class.php';
  1207. $multicurrency = new MultiCurrency($db);
  1208. $multicurrency->fetch(0, $_SESSION["takeposcustomercurrency"]);
  1209. 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>';
  1210. }
  1211. print '</td>';
  1212. }
  1213. print '</td>';
  1214. }
  1215. print '<td class="linecolht right nowraponall">';
  1216. print '<span class="opacitymedium small">'.$langs->trans('TotalTTCShort').'</span><br>';
  1217. // In phone version only show when it is invoice page
  1218. if (empty($mobilepage) || $mobilepage == "invoice") {
  1219. 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>';
  1220. if (isModEnabled('multicurrency') && !empty($_SESSION["takeposcustomercurrency"]) && $conf->currency != $_SESSION["takeposcustomercurrency"]) {
  1221. //Only show customer currency if multicurrency module is enabled, if currency selected and if this currency selected is not the same as main currency
  1222. include_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php';
  1223. $multicurrency = new MultiCurrency($db);
  1224. $multicurrency->fetch(0, $_SESSION["takeposcustomercurrency"]);
  1225. 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>';
  1226. }
  1227. print '</td>';
  1228. }
  1229. print '</td>';
  1230. } elseif ($mobilepage == "invoice") {
  1231. print '<td class="linecolqty right">'.$langs->trans('Qty').'</td>';
  1232. }
  1233. print "</tr>\n";
  1234. if (!empty($_SESSION["basiclayout"]) && $_SESSION["basiclayout"] == 1) {
  1235. if ($mobilepage == "cats") {
  1236. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  1237. $categorie = new Categorie($db);
  1238. $categories = $categorie->get_full_arbo('product');
  1239. $htmlforlines = '';
  1240. foreach ($categories as $row) {
  1241. if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
  1242. $htmlforlines .= '<div class="leftcat';
  1243. } else {
  1244. $htmlforlines .= '<tr class="drag drop oddeven posinvoiceline';
  1245. }
  1246. $htmlforlines .= '" onclick="LoadProducts('.$row['id'].');">';
  1247. if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
  1248. $htmlforlines .= '<img class="imgwrapper" width="33%" src="'.DOL_URL_ROOT.'/takepos/public/auto_order.php?genimg=cat&query=cat&id='.$row['id'].'"><br>';
  1249. } else {
  1250. $htmlforlines .= '<td class="left">';
  1251. }
  1252. $htmlforlines .= $row['label'];
  1253. if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
  1254. $htmlforlines .= '</div>'."\n";
  1255. } else {
  1256. $htmlforlines .= '</td></tr>'."\n";
  1257. }
  1258. }
  1259. $htmlforlines .= '</table>';
  1260. $htmlforlines .= '</table>';
  1261. print $htmlforlines;
  1262. }
  1263. if ($mobilepage == "products") {
  1264. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  1265. $object = new Categorie($db);
  1266. $catid = GETPOST('catid', 'int');
  1267. $result = $object->fetch($catid);
  1268. $prods = $object->getObjectsInCateg("product");
  1269. $htmlforlines = '';
  1270. foreach ($prods as $row) {
  1271. if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
  1272. $htmlforlines .= '<div class="leftcat';
  1273. } else {
  1274. $htmlforlines .= '<tr class="drag drop oddeven posinvoiceline';
  1275. }
  1276. $htmlforlines .= '" onclick="AddProduct(\''.$place.'\', '.$row->id.')">';
  1277. if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
  1278. $htmlforlines .= '<img class="imgwrapper" width="33%" src="'.DOL_URL_ROOT.'/takepos/public/auto_order.php?genimg=pro&query=pro&id='.$row->id.'"><br>';
  1279. $htmlforlines .= $row->label.''.price($row->price_ttc, 1, $langs, 1, -1, -1, $conf->currency);
  1280. $htmlforlines .= '</div>'."\n";
  1281. } else {
  1282. $htmlforlines .= '<td class="left">';
  1283. $htmlforlines .= $row->label;
  1284. $htmlforlines .= '<div class="right">'.price($row->price_ttc, 1, $langs, 1, -1, -1, $conf->currency).'</div>';
  1285. $htmlforlines .= '</tr>'."\n";
  1286. }
  1287. }
  1288. $htmlforlines .= '</table>';
  1289. print $htmlforlines;
  1290. }
  1291. if ($mobilepage == "places") {
  1292. $sql = "SELECT rowid, entity, label, leftpos, toppos, floor FROM ".MAIN_DB_PREFIX."takepos_floor_tables";
  1293. $resql = $db->query($sql);
  1294. $rows = array();
  1295. $htmlforlines = '';
  1296. while ($row = $db->fetch_array($resql)) {
  1297. $rows[] = $row;
  1298. $htmlforlines .= '<tr class="drag drop oddeven posinvoiceline';
  1299. $htmlforlines .= '" onclick="LoadPlace(\''.$row['label'].'\')">';
  1300. $htmlforlines .= '<td class="left">';
  1301. $htmlforlines .= $row['label'];
  1302. $htmlforlines .= '</td>';
  1303. $htmlforlines .= '</tr>'."\n";
  1304. }
  1305. $htmlforlines .= '</table>';
  1306. print $htmlforlines;
  1307. }
  1308. }
  1309. if ($placeid > 0) {
  1310. //In Phone basic layout hide some content depends situation
  1311. if (!empty($_SESSION["basiclayout"]) && $_SESSION["basiclayout"] == 1 && $mobilepage != "invoice" && $action != "order") {
  1312. return;
  1313. }
  1314. if (is_array($invoice->lines) && count($invoice->lines)) {
  1315. print '<!-- invoice.php show lines of invoices -->'."\n";
  1316. $tmplines = array_reverse($invoice->lines);
  1317. $htmlsupplements = array();
  1318. foreach ($tmplines as $line) {
  1319. if ($line->fk_parent_line != false) {
  1320. $htmlsupplements[$line->fk_parent_line] .= '<tr class="drag drop oddeven posinvoiceline';
  1321. if ($line->special_code == "4") {
  1322. $htmlsupplements[$line->fk_parent_line] .= ' order';
  1323. }
  1324. $htmlsupplements[$line->fk_parent_line] .= '" id="'.$line->id.'"';
  1325. if ($line->special_code == "4") {
  1326. $htmlsupplements[$line->fk_parent_line] .= ' title="'.dol_escape_htmltag($langs->trans("AlreadyPrinted")).'"';
  1327. }
  1328. $htmlsupplements[$line->fk_parent_line] .= '>';
  1329. $htmlsupplements[$line->fk_parent_line] .= '<td class="left">';
  1330. $htmlsupplements[$line->fk_parent_line] .= img_picto('', 'rightarrow');
  1331. if ($line->product_label) {
  1332. $htmlsupplements[$line->fk_parent_line] .= $line->product_label;
  1333. }
  1334. if ($line->product_label && $line->desc) {
  1335. $htmlsupplements[$line->fk_parent_line] .= '<br>';
  1336. }
  1337. if ($line->product_label != $line->desc) {
  1338. $firstline = dolGetFirstLineOfText($line->desc);
  1339. if ($firstline != $line->desc) {
  1340. $htmlsupplements[$line->fk_parent_line] .= $form->textwithpicto(dolGetFirstLineOfText($line->desc), $line->desc);
  1341. } else {
  1342. $htmlsupplements[$line->fk_parent_line] .= $line->desc;
  1343. }
  1344. }
  1345. $htmlsupplements[$line->fk_parent_line] .= '</td>';
  1346. // complete line by hook
  1347. $parameters=array('line' => $line);
  1348. $reshook=$hookmanager->executeHooks('completeTakePosInvoiceParentLine', $parameters, $invoice, $action); // Note that $action and $object may have been modified by some hooks
  1349. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  1350. $htmlsupplements[$line->fk_parent_line] .= $hookmanager->resPrint;
  1351. if (empty($_SESSION["basiclayout"]) || $_SESSION["basiclayout"] != 1) {
  1352. $htmlsupplements[$line->fk_parent_line] .= '<td class="right">'.vatrate($line->remise_percent, true).'</td>';
  1353. $htmlsupplements[$line->fk_parent_line] .= '<td class="right">'.$line->qty.'</td>';
  1354. $htmlsupplements[$line->fk_parent_line] .= '<td class="right">'.price($line->total_ttc).'</td>';
  1355. }
  1356. $htmlsupplements[$line->fk_parent_line] .= '</tr>'."\n";
  1357. continue;
  1358. }
  1359. $htmlforlines = '';
  1360. $htmlforlines .= '<tr class="drag drop oddeven posinvoiceline';
  1361. if ($line->special_code == "4") {
  1362. $htmlforlines .= ' order';
  1363. }
  1364. $htmlforlines .= '" id="'.$line->id.'"';
  1365. if ($line->special_code == "4") {
  1366. $htmlforlines .= ' title="'.dol_escape_htmltag($langs->trans("AlreadyPrinted")).'"';
  1367. }
  1368. $htmlforlines .= '>';
  1369. $htmlforlines .= '<td class="left">';
  1370. if (!empty($_SESSION["basiclayout"]) && $_SESSION["basiclayout"] == 1) {
  1371. $htmlforlines .= '<span class="phoneqty">'.$line->qty."</span> x ";
  1372. }
  1373. if (isset($line->product_type)) {
  1374. if (empty($line->product_type)) {
  1375. $htmlforlines .= img_object('', 'product').' ';
  1376. } else {
  1377. $htmlforlines .= img_object('', 'service').' ';
  1378. }
  1379. }
  1380. if (empty($conf->global->TAKEPOS_SHOW_N_FIRST_LINES)) {
  1381. $tooltiptext = '';
  1382. if ($line->product_ref) {
  1383. $tooltiptext .= '<b>'.$langs->trans("Ref").'</b> : '.$line->product_ref.'<br>';
  1384. $tooltiptext .= '<b>'.$langs->trans("Label").'</b> : '.$line->product_label.'<br>';
  1385. if ($line->product_label != $line->desc) {
  1386. if ($line->desc) {
  1387. $tooltiptext .= '<br>';
  1388. }
  1389. $tooltiptext .= $line->desc;
  1390. }
  1391. }
  1392. if (getDolGlobalInt('TAKEPOS_SHOW_PRODUCT_REFERENCE') == 1) {
  1393. $htmlforlines .= $form->textwithpicto($line->product_label ? '<b>' . $line->product_ref . '</b> - ' . $line->product_label : dolGetFirstLineOfText($line->desc, 1), $tooltiptext);
  1394. } else {
  1395. $htmlforlines .= $form->textwithpicto($line->product_label ? $line->product_label : ($line->product_ref ? $line->product_ref : dolGetFirstLineOfText($line->desc, 1)), $tooltiptext);
  1396. }
  1397. } else {
  1398. if ($line->product_label) {
  1399. $htmlforlines .= $line->product_label;
  1400. }
  1401. if ($line->product_label != $line->desc) {
  1402. if ($line->product_label && $line->desc) {
  1403. $htmlforlines .= '<br>';
  1404. }
  1405. $firstline = dolGetFirstLineOfText($line->desc, $conf->global->TAKEPOS_SHOW_N_FIRST_LINES);
  1406. if ($firstline != $line->desc) {
  1407. $htmlforlines .= $form->textwithpicto(dolGetFirstLineOfText($line->desc), $line->desc);
  1408. } else {
  1409. $htmlforlines .= $line->desc;
  1410. }
  1411. }
  1412. }
  1413. if (!empty($line->array_options['options_order_notes'])) {
  1414. $htmlforlines .= "<br>(".$line->array_options['options_order_notes'].")";
  1415. }
  1416. if (!empty($_SESSION["basiclayout"]) && $_SESSION["basiclayout"] == 1) {
  1417. $htmlforlines .= '</td><td class="right phonetable"><button type="button" onclick="SetQty(place, '.$line->rowid.', '.($line->qty - 1).');" class="publicphonebutton2 phonered">-</button>&nbsp;&nbsp;<button type="button" onclick="SetQty(place, '.$line->rowid.', '.($line->qty + 1).');" class="publicphonebutton2 phonegreen">+</button>';
  1418. }
  1419. if (empty($_SESSION["basiclayout"]) || $_SESSION["basiclayout"] != 1) {
  1420. $moreinfo = '';
  1421. $moreinfo .= $langs->transcountry("TotalHT", $mysoc->country_code).': '.price($line->total_ht);
  1422. if ($line->vat_src_code) {
  1423. $moreinfo .= '<br>'.$langs->trans("VATCode").': '.$line->vat_src_code;
  1424. }
  1425. $moreinfo .= '<br>'.$langs->transcountry("TotalVAT", $mysoc->country_code).': '.price($line->total_tva);
  1426. $moreinfo .= '<br>'.$langs->transcountry("TotalLT1", $mysoc->country_code).': '.price($line->total_localtax1);
  1427. $moreinfo .= '<br>'.$langs->transcountry("TotalLT2", $mysoc->country_code).': '.price($line->total_localtax2);
  1428. $moreinfo .= '<hr>';
  1429. $moreinfo .= $langs->transcountry("TotalTTC", $mysoc->country_code).': '.price($line->total_ttc);
  1430. //$moreinfo .= $langs->trans("TotalHT").': '.$line->total_ht;
  1431. if ($line->date_start || $line->date_end) {
  1432. $htmlforlines .= '<br><div class="clearboth nowraponall">'.get_date_range($line->date_start, $line->date_end).'</div>';
  1433. }
  1434. $htmlforlines .= '</td>';
  1435. // complete line by hook
  1436. $parameters=array('line' => $line);
  1437. $reshook=$hookmanager->executeHooks('completeTakePosInvoiceLine', $parameters, $invoice, $action); // Note that $action and $object may have been modified by some hooks
  1438. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  1439. $htmlforlines .= $hookmanager->resPrint;
  1440. $htmlforlines .= '<td class="right">'.vatrate($line->remise_percent, true).'</td>';
  1441. $htmlforlines .= '<td class="right">';
  1442. if (isModEnabled('stock') && !empty($user->rights->stock->mouvement->lire)) {
  1443. $constantforkey = 'CASHDESK_ID_WAREHOUSE'.$_SESSION["takeposterminal"];
  1444. if (!empty($conf->global->$constantforkey) && $line->fk_product > 0 && empty($conf->global->TAKEPOS_HIDE_STOCK_ON_LINE)) {
  1445. $sql = "SELECT e.rowid, e.ref, e.lieu, e.fk_parent, e.statut, ps.reel, ps.rowid as product_stock_id, p.pmp";
  1446. $sql .= " FROM ".MAIN_DB_PREFIX."entrepot as e,";
  1447. $sql .= " ".MAIN_DB_PREFIX."product_stock as ps";
  1448. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = ps.fk_product";
  1449. $sql .= " WHERE ps.reel != 0";
  1450. $sql .= " AND ps.fk_entrepot = ".((int) $conf->global->$constantforkey);
  1451. $sql .= " AND e.entity IN (".getEntity('stock').")";
  1452. $sql .= " AND ps.fk_product = ".((int) $line->fk_product);
  1453. $resql = $db->query($sql);
  1454. if ($resql) {
  1455. $obj = $db->fetch_object($resql);
  1456. $stock_real = price2num($obj->reel, 'MS');
  1457. $htmlforlines .= $line->qty;
  1458. if ($line->qty && $line->qty > $stock_real) {
  1459. $htmlforlines .= '<span style="color: var(--amountremaintopaycolor)">';
  1460. }
  1461. $htmlforlines .= ' <span class="posstocktoolow">('.$langs->trans("Stock").' '.$stock_real.')</span>';
  1462. if ($line->qty && $line->qty > $stock_real) {
  1463. $htmlforlines .= "</span>";
  1464. }
  1465. } else {
  1466. dol_print_error($db);
  1467. }
  1468. } else {
  1469. $htmlforlines .= $line->qty;
  1470. }
  1471. } else {
  1472. $htmlforlines .= $line->qty;
  1473. }
  1474. $htmlforlines .= '</td>';
  1475. if (getDolGlobalString('TAKEPOS_SHOW_HT')) {
  1476. $htmlforlines .= '<td class="right classfortooltip" title="'.$moreinfo.'">';
  1477. $htmlforlines .= price($line->total_ht, 1, '', 1, -1, -1, $conf->currency);
  1478. if (isModEnabled('multicurrency') && !empty($_SESSION["takeposcustomercurrency"]) && $conf->currency != $_SESSION["takeposcustomercurrency"]) {
  1479. //Only show customer currency if multicurrency module is enabled, if currency selected and if this currency selected is not the same as main currency
  1480. include_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php';
  1481. $multicurrency = new MultiCurrency($db);
  1482. $multicurrency->fetch(0, $_SESSION["takeposcustomercurrency"]);
  1483. $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>';
  1484. }
  1485. $htmlforlines .= '</td>';
  1486. }
  1487. $htmlforlines .= '<td class="right classfortooltip" title="'.$moreinfo.'">';
  1488. $htmlforlines .= price($line->total_ttc, 1, '', 1, -1, -1, $conf->currency);
  1489. if (isModEnabled('multicurrency') && !empty($_SESSION["takeposcustomercurrency"]) && $conf->currency != $_SESSION["takeposcustomercurrency"]) {
  1490. //Only show customer currency if multicurrency module is enabled, if currency selected and if this currency selected is not the same as main currency
  1491. include_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php';
  1492. $multicurrency = new MultiCurrency($db);
  1493. $multicurrency->fetch(0, $_SESSION["takeposcustomercurrency"]);
  1494. $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>';
  1495. }
  1496. $htmlforlines .= '</td>';
  1497. }
  1498. $htmlforlines .= '</tr>'."\n";
  1499. $htmlforlines .= empty($htmlsupplements[$line->id]) ? '' : $htmlsupplements[$line->id];
  1500. print $htmlforlines;
  1501. }
  1502. } else {
  1503. print '<tr class="drag drop oddeven"><td class="left"><span class="opacitymedium">'.$langs->trans("Empty").'</span></td><td></td><td></td><td></td>';
  1504. if (!empty($conf->global->TAKEPOS_SHOW_HT)) {
  1505. print '<td></td>';
  1506. }
  1507. print '</tr>';
  1508. }
  1509. } else { // No invoice generated yet
  1510. print '<tr class="drag drop oddeven"><td class="left"><span class="opacitymedium">'.$langs->trans("Empty").'</span></td><td></td><td></td><td></td>';
  1511. if (!empty($conf->global->TAKEPOS_SHOW_HT)) {
  1512. print '<td></td>';
  1513. }
  1514. print '</tr>';
  1515. }
  1516. print '</table>';
  1517. if (($action == "valid" || $action == "history") && $invoice->type != Facture::TYPE_CREDIT_NOTE) {
  1518. print '<button id="buttonprint" type="button" onclick="ModalBox(\'ModalCreditNote\')">'.$langs->trans('CreateCreditNote').'</button>';
  1519. }
  1520. if ($action == "search") {
  1521. print '<center>
  1522. <input type="text" id="search" class="input-search-takepos" name="search" onkeyup="Search2(\'\', null);" style="width: 80%; font-size: 150%;" placeholder="'.dol_escape_htmltag($langs->trans('Search')).'">
  1523. </center>';
  1524. }
  1525. print '</div>';
  1526. // llxFooter
  1527. if ((getDolGlobalString('TAKEPOS_PHONE_BASIC_LAYOUT') == 1 && $conf->browser->layout == 'phone') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
  1528. print '</body></html>';
  1529. }