invoice.php 72 KB

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