phone.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. <?php
  2. /* Copyright (C) 2018 Andreu Bisquerra <jove@bisquerra.com>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. */
  17. /**
  18. * \file htdocs/takepos/phone.php
  19. * \ingroup takepos
  20. * \brief TakePOS Phone screen
  21. */
  22. //if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1'); // Not disabled cause need to load personalized language
  23. //if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1'); // Not disabled cause need to load personalized language
  24. //if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
  25. //if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1');
  26. if (!defined('NOTOKENRENEWAL')) {
  27. define('NOTOKENRENEWAL', '1');
  28. }
  29. if (!defined('NOREQUIREMENU')) {
  30. define('NOREQUIREMENU', '1');
  31. }
  32. if (!defined('NOREQUIREHTML')) {
  33. define('NOREQUIREHTML', '1');
  34. }
  35. if (!defined('NOREQUIREAJAX')) {
  36. define('NOREQUIREAJAX', '1');
  37. }
  38. if (!defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
  39. require '../main.inc.php';
  40. }
  41. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  42. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  43. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  44. require_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
  45. if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
  46. // Decode place if it is an order from a customer phone
  47. $place = GETPOSTISSET("key") ? dol_decode(GETPOST('key')) : GETPOST('place', 'aZ09');
  48. } else {
  49. $place = (GETPOST('place', 'aZ09') ? GETPOST('place', 'aZ09') : 0); // $place is id of table for Ba or Restaurant
  50. }
  51. $action = GETPOST('action', 'aZ09');
  52. $setterminal = GETPOST('setterminal', 'int');
  53. $idproduct = GETPOST('idproduct', 'int');
  54. $mobilepage = GETPOST('mobilepage', 'alphanohtml'); // Set when page is loaded by a js .load()
  55. if ($setterminal > 0) {
  56. $_SESSION["takeposterminal"] = $setterminal;
  57. }
  58. $langs->loadLangs(array("bills", "orders", "commercial", "cashdesk", "receiptprinter"));
  59. if (!$user->hasRight('takepos', 'run') && !defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
  60. accessforbidden('No permission to run the takepos');
  61. }
  62. /*
  63. * View
  64. */
  65. $title = 'TakePOS - Dolibarr '.DOL_VERSION;
  66. if (getDolGlobalString('MAIN_APPLICATION_TITLE')) {
  67. $title = 'TakePOS - ' . getDolGlobalString('MAIN_APPLICATION_TITLE');
  68. }
  69. // llxHeader
  70. if (empty($mobilepage) && (empty($action) || ((getDolGlobalString('TAKEPOS_PHONE_BASIC_LAYOUT') == 1 && $conf->browser->layout == 'phone') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')))) {
  71. $head = '<meta name="apple-mobile-web-app-title" content="TakePOS"/>
  72. <meta name="apple-mobile-web-app-capable" content="yes">
  73. <meta name="mobile-web-app-capable" content="yes">
  74. <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>';
  75. $arrayofcss = array(
  76. '/takepos/css/phone.css',
  77. );
  78. $arrayofjs = array('/takepos/js/jquery.colorbox-min.js');
  79. $disablejs = 0;
  80. $disablehead = 0;
  81. top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss);
  82. print '<body style="background-color:#D1D1D1;">'."\n";
  83. } else {
  84. top_htmlhead('', $title);
  85. print '<body>'."\n";
  86. }
  87. if ($action == "productinfo") {
  88. $prod = new Product($db);
  89. $prod->fetch($idproduct);
  90. print '<button type="button" class="publicphonebutton2 phoneblue total" onclick="AddProductConfirm(place, '.$idproduct.')">'.$langs->trans('Add').'</button>';
  91. print "<br><b>".$prod->label."</b><br>";
  92. print '<img class="imgwrapper" width="60%" src="'.DOL_URL_ROOT.'/takepos/public/auto_order.php?genimg=pro&query=pro&id='.$idproduct.'">';
  93. print "<br>".$prod->description;
  94. print "<br><b>".price($prod->price_ttc, 1, $langs, 1, -1, -1, $conf->currency)."</b>";
  95. print '<br>';
  96. } elseif ($action == "publicpreorder") {
  97. print '<button type="button" class="publicphonebutton2 phoneblue total" onclick="TakeposPrintingOrder();">'.$langs->trans('Confirm').'</button>';
  98. print "<br><br>";
  99. print '<div class="comment">
  100. <textarea class="textinput " placeholder="'.$langs->trans('Note').'"></textarea>
  101. </div>';
  102. print '<br>';
  103. } elseif ($action == "publicpayment") {
  104. $langs->loadLangs(array("orders"));
  105. print '<h1>'.$langs->trans('Ordered').'</h1>';
  106. print '<button type="button" class="publicphonebutton2 phoneblue total" onclick="CheckPlease();">'.$langs->trans('Payment').'</button>';
  107. print '<br>';
  108. } elseif ($action == "checkplease") {
  109. if (GETPOSTISSET("payment")) {
  110. print '<h1>'.$langs->trans('Ordered').'</h1>';
  111. require_once DOL_DOCUMENT_ROOT.'/core/class/dolreceiptprinter.class.php';
  112. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  113. $printer = new dolReceiptPrinter($db);
  114. $printer->initPrinter(getDolGlobalString('TAKEPOS_PRINTER_TO_USE'.$_SESSION["takeposterminal"]));
  115. if ($printer->getPrintConnector()) {
  116. if (!is_null($printer->printer)) {
  117. $printer->printer->feed();
  118. $printer->printer->feed();
  119. $printer->printer->text($langs->trans('IM'));
  120. $printer->printer->feed();
  121. $printer->printer->text($langs->trans('Place').": ".$place);
  122. $printer->printer->feed();
  123. $printer->printer->text($langs->trans('Payment').": ".$langs->trans(GETPOST('payment', 'alpha')));
  124. $printer->printer->feed();
  125. $printer->printer->feed();
  126. $printer->printer->feed();
  127. $printer->printer->feed();
  128. $printer->printer->feed();
  129. }
  130. $printer->close();
  131. }
  132. } else {
  133. print '<button type="button" class="publicphonebutton2 phoneblue total marginbottomonly" onclick="CheckPlease(\'Cash\')">'.$langs->trans('Cash').'</button>';
  134. print '<button type="button" class="publicphonebutton2 phoneblue total marginbottomonly" onclick="CheckPlease(\'CreditCard\')">'.$langs->trans('CreditCard').'</button>';
  135. print '<br>';
  136. }
  137. } elseif ($action == "editline") {
  138. $placeid = GETPOST('placeid', 'int');
  139. $selectedline = GETPOST('selectedline', 'int');
  140. $invoice = new Facture($db);
  141. $invoice->fetch($placeid);
  142. foreach ($invoice->lines as $line) {
  143. if ($line->id == $selectedline) {
  144. $prod = new Product($db);
  145. $prod->fetch($line->fk_product);
  146. print "<b>".$prod->label."</b><br>";
  147. print '<img class="imgwrapper" width="60%" src="'.DOL_URL_ROOT.'/takepos/public/auto_order.php?genimg=pro&query=pro&id='.$line->fk_product.'">';
  148. print "<br>".$prod->description;
  149. print "<br><b>".price($prod->price_ttc, 1, $langs, 1, -1, -1, $conf->currency)."</b>";
  150. print '<br>';
  151. print '<button type="button" class="publicphonebutton2 phonered width24" onclick="SetQty(place, '.$selectedline.', '.($line->qty - 1).')">-</button>';
  152. print '<button type="button" class="publicphonebutton2 phonegreen width24" onclick="SetQty(place, '.$selectedline.', '.($line->qty + 1).')">+</button>';
  153. print '<button type="button" class="publicphonebutton2 phoneblue width24" onclick="SetNote(place, '.$selectedline.')">'.$langs->trans('Note').'</button>';
  154. }
  155. }
  156. } else {
  157. ?>
  158. <div class="container">
  159. <div class="phonebuttonsrow center">
  160. <?php
  161. if (!defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
  162. print '<button type="button" class="phonebutton uppercase" onclick="LoadPlacesList();">'.dol_trunc($langs->trans('Floors'), 5, 'right', 'UTF-8').'</button>';
  163. print '<button type="button" class="phonebutton uppercase" onclick="LoadCats();">'.dol_trunc($langs->trans('Categories'), 5, 'right', 'UTF-8').'</button>';
  164. print '<button type="button" class="phonebutton uppercase" onclick="TakeposPrintingOrder();">'.dol_trunc($langs->trans('Order'), 5, 'right', 'UTF-8').'</button>';
  165. print '<button type="button" class="phonebutton uppercase" onclick="CheckPlease();">'.dol_trunc($langs->trans('Payment'), 5, 'right', 'UTF-8').'</button>';
  166. print '<button type="button" class="phonebutton uppercase" onclick="Exit();">'.dol_trunc($langs->trans('Logout'), 5, 'right', 'UTF-8').'</button>';
  167. } else {
  168. print '<button type="button" class="publicphonebutton phoneblue uppercase" onclick="LoadCats();">'.dol_trunc($langs->trans('Categories'), 8, 'right', 'UTF-8').'</button>';
  169. print '<button type="button" class="publicphonebutton phoneorange uppercase" onclick="PublicPreOrder();">'.dol_trunc($langs->trans('Order'), 8, 'right', 'UTF-8').'</button>';
  170. // Do not show the payment link when order done from public page (a customer must not be able to set its order to paid himself)
  171. //print '<button type="button" class="publicphonebutton phonegreen uppercase" onclick="CheckPlease();">'.dol_trunc($langs->trans('Payment'), 8, 'right', 'UTF-8').'</button>';
  172. }
  173. ?>
  174. </div>
  175. <div class="phonerow2">
  176. <div id="phonediv2" class="phonediv2"></div>
  177. </div>
  178. <div class="phonerow1">
  179. <div id="phonediv1" class="phonediv1"></div>
  180. </div>
  181. </div>
  182. <script type="text/javascript">
  183. <?php
  184. $categorie = new Categorie($db);
  185. $categories = $categorie->get_full_arbo('product', ((getDolGlobalInt('TAKEPOS_ROOT_CATEGORY_ID') > 0) ? $conf->global->TAKEPOS_ROOT_CATEGORY_ID : 0), 1);
  186. // Search root category to know its level
  187. //$conf->global->TAKEPOS_ROOT_CATEGORY_ID=0;
  188. $levelofrootcategory = 0;
  189. if (getDolGlobalInt('TAKEPOS_ROOT_CATEGORY_ID') > 0) {
  190. foreach ($categories as $key => $categorycursor) {
  191. if ($categorycursor['id'] == $conf->global->TAKEPOS_ROOT_CATEGORY_ID) {
  192. $levelofrootcategory = $categorycursor['level'];
  193. break;
  194. }
  195. }
  196. }
  197. $levelofmaincategories = $levelofrootcategory + 1;
  198. $maincategories = array();
  199. $subcategories = array();
  200. foreach ($categories as $key => $categorycursor) {
  201. if ($categorycursor['level'] == $levelofmaincategories) {
  202. $maincategories[$key] = $categorycursor;
  203. } else {
  204. $subcategories[$key] = $categorycursor;
  205. }
  206. }
  207. sort($maincategories);
  208. sort($subcategories);
  209. ?>
  210. var categories = <?php echo json_encode($maincategories); ?>;
  211. var subcategories = <?php echo json_encode($subcategories); ?>;
  212. var currentcat;
  213. var pageproducts=0;
  214. var pagecategories=0;
  215. var pageactions=0;
  216. var place="<?php echo $place; ?>";
  217. var editaction="qty";
  218. var editnumber="";
  219. $( document ).ready(function() {
  220. console.log("Refresh");
  221. LoadPlace(place);
  222. });
  223. function LoadPlace(placeid){
  224. place=placeid;
  225. <?php
  226. if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
  227. echo '$("#phonediv2").load("'.DOL_URL_ROOT.'/takepos/public/auto_order.php?mobilepage=invoice&place="+place+" #tablelines", function() {
  228. });';
  229. } else {
  230. echo '$("#phonediv2").load("'.DOL_URL_ROOT.'/takepos/invoice.php?mobilepage=invoice&place="+place+" #tablelines", function() {
  231. });';
  232. }
  233. ?>
  234. LoadCats();
  235. }
  236. function AddProduct(placeid, productid){
  237. <?php
  238. // If is a public terminal first show product information
  239. if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
  240. print 'place=placeid;
  241. $("#phonediv1").load("'.DOL_URL_ROOT.'/takepos/public/auto_order.php?action=productinfo&token='.newToken().'&place="+place+"&idproduct="+productid, function() {
  242. });';
  243. } else {
  244. print 'AddProductConfirm(placeid, productid);';
  245. } ?>
  246. }
  247. function PublicPreOrder(){
  248. $("#phonediv1").load("'.DOL_URL_ROOT.'/takepos/public/auto_order.php?action=publicpreorder&token=<?php echo newToken(); ?>&place="+place, function() {
  249. });
  250. }
  251. function AddProductConfirm(placeid, productid){
  252. place=placeid;
  253. <?php
  254. if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
  255. echo '$("#phonediv2").load("'.DOL_URL_ROOT.'/takepos/public/auto_order.php?mobilepage=invoice&action=addline&token='.newToken().'&place="+place+"&idproduct="+productid, function() {
  256. });';
  257. } else {
  258. echo '$("#phonediv2").load("'.DOL_URL_ROOT.'/takepos/invoice.php?mobilepage=invoice&action=addline&token='.newToken().'&place="+place+"&idproduct="+productid, function() {
  259. });';
  260. } ?>
  261. return true;
  262. }
  263. function SetQty(place, selectedline, qty){
  264. console.log("We click on SetQty()");
  265. <?php
  266. if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
  267. ?>
  268. if (qty==0){
  269. $("#phonediv2").load("<?php echo DOL_URL_ROOT ?>/takepos/public/auto_order.php?mobilepage=invoice&action=deleteline&token=<?php echo newToken(); ?>&place="+place+"&idline="+selectedline, function() {
  270. });
  271. }
  272. else{
  273. $("#phonediv2").load("<?php echo DOL_URL_ROOT ?>/takepos/public/auto_order.php?mobilepage=invoice&action=updateqty&token=<?php echo newToken(); ?>&place="+place+"&idline="+selectedline+"&number="+qty, function() {
  274. });
  275. }
  276. <?php
  277. } else {
  278. ?>
  279. if (qty==0){
  280. $("#phonediv2").load("<?php echo DOL_URL_ROOT ?>/takepos/invoice.php?mobilepage=invoice&action=deleteline&token=<?php echo newToken(); ?>&place="+place+"&idline="+selectedline, function() {
  281. });
  282. }
  283. else{
  284. $("#phonediv2").load("<?php echo DOL_URL_ROOT ?>/takepos/invoice.php?mobilepage=invoice&action=updateqty&token=<?php echo newToken(); ?>&place="+place+"&idline="+selectedline+"&number="+qty, function() {
  285. });
  286. }
  287. <?php
  288. } ?>
  289. LoadCats();
  290. return true;
  291. }
  292. function SetNote(place, selectedline){
  293. console.log("We click on SetNote()");
  294. var note = prompt("<?php dol_escape_js($langs->trans('Note')); ?>", "");
  295. $("#phonediv2").load("<?php echo DOL_URL_ROOT ?>/takepos/public/auto_order.php?mobilepage=invoice&action=updateqty&token=<?php echo newToken(); ?>&place="+place+"&idline="+selectedline+"&number="+qty, function() {
  296. });
  297. LoadCats();
  298. }
  299. function LoadCats(){
  300. console.log("We click on LoadCats()");
  301. <?php
  302. if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
  303. // Load invoice.php to get categories by using auto_order so it will define INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE
  304. echo '$("#phonediv1").load("'.DOL_URL_ROOT.'/takepos/public/auto_order.php?format=div&mobilepage=cats&place="+place+" #tablelines", function() {
  305. });';
  306. } else {
  307. echo '$("#phonediv1").load("'.DOL_URL_ROOT.'/takepos/invoice.php?mobilepage=cats&place="+place+"", function() {
  308. });';
  309. }
  310. ?>
  311. }
  312. function LoadProducts(idcat) {
  313. console.log("We click on LoadProducts()");
  314. <?php
  315. if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
  316. echo '$("#phonediv1").load("'.DOL_URL_ROOT.'/takepos/public/auto_order.php?format=div&mobilepage=products&catid="+idcat+"&place="+place+"", function() {
  317. });';
  318. } else {
  319. echo '$("#phonediv1").load("'.DOL_URL_ROOT.'/takepos/invoice.php?mobilepage=products&catid="+idcat+"&place="+place+"", function() {
  320. });';
  321. } ?>
  322. }
  323. function LoadPlacesList(){
  324. $("#phonediv1").load("invoice.php?mobilepage=places", function() {
  325. });
  326. }
  327. function TakeposPrintingOrder(){
  328. console.log("TakeposPrintingOrder");
  329. <?php
  330. if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
  331. echo '$("#phonediv2").load("'.DOL_URL_ROOT.'/takepos/public/auto_order.php?action=order&token='.newToken().'&mobilepage=order&place="+place, function() {
  332. });';
  333. echo '$("#phonediv1").load("'.DOL_URL_ROOT.'/takepos/public/auto_order.php?action=publicpayment&token='.newToken().'&place="+place, function() {
  334. });';
  335. } else {
  336. echo '$("#phonediv2").load("'.DOL_URL_ROOT.'/takepos/invoice.php?action=order&token='.newToken().'&place="+place, function() {
  337. });';
  338. } ?>
  339. }
  340. function Exit(){
  341. console.log("Click on Exit");
  342. window.location.href='<?php echo DOL_URL_ROOT ?>/user/logout.php?token=<?php echo newToken(); ?>';
  343. }
  344. function CheckPlease(payment){
  345. console.log("Click on CheckPlease");
  346. if (payment==undefined){
  347. $("#phonediv1").load("<?php echo DOL_URL_ROOT ?>/takepos/public/auto_order.php?action=checkplease&token=<?php echo newToken(); ?>&place="+place, function() {
  348. });
  349. }
  350. else{
  351. console.log("Request the check to the waiter");
  352. $("#phonediv1").load("<?php echo DOL_URL_ROOT ?>/takepos/public/auto_order.php?action=checkplease&token=<?php echo newToken(); ?>&place=<?php echo urlencode($place); ?>&payment="+payment, function() {
  353. });
  354. }
  355. }
  356. </script>
  357. <?php
  358. if (getDolGlobalString('TAKEPOS_NUM_TERMINALS') != "1" && $_SESSION["takeposterminal"] == "") {
  359. print '<div class="dialog-info-takepos-terminal" id="dialog-info" title="TakePOS">'.$langs->trans('TerminalSelect').'</div>';
  360. }
  361. }
  362. print '</body>';
  363. print '</html>';
  364. $db->close();