phone.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  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 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. if ($setterminal > 0) {
  55. $_SESSION["takeposterminal"] = $setterminal;
  56. }
  57. $langs->loadLangs(array("bills", "orders", "commercial", "cashdesk", "receiptprinter"));
  58. if (!$user->hasRight('takepos', 'run') && !defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
  59. accessforbidden();
  60. }
  61. /*
  62. * View
  63. */
  64. if (empty($action)) {
  65. // Code for llxHeader()
  66. $title = 'TakePOS - Dolibarr '.DOL_VERSION;
  67. if (!empty($conf->global->MAIN_APPLICATION_TITLE)) {
  68. $title = 'TakePOS - ' . getDolGlobalString('MAIN_APPLICATION_TITLE');
  69. }
  70. $head = '<meta name="apple-mobile-web-app-title" content="TakePOS"/>
  71. <meta name="apple-mobile-web-app-capable" content="yes">
  72. <meta name="mobile-web-app-capable" content="yes">
  73. <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>';
  74. $arrayofcss = array('/takepos/css/phone.css');
  75. top_htmlhead($head, $title, 0, 0, '', $arrayofcss);
  76. } else {
  77. top_httphead('text/html', 1);
  78. }
  79. if ($action == "productinfo") {
  80. $prod = new Product($db);
  81. $prod->fetch($idproduct);
  82. print '<button type="button" class="publicphonebutton2 phoneblue total" onclick="AddProductConfirm(place, '.$idproduct.')">'.$langs->trans('Add').'</button>';
  83. print "<br><b>".$prod->label."</b><br>";
  84. print '<img class="imgwrapper" width="60%" src="'.DOL_URL_ROOT.'/takepos/public/auto_order.php?genimg=pro&query=pro&id='.$idproduct.'">';
  85. print "<br>".$prod->description;
  86. print "<br><b>".price($prod->price_ttc, 1, $langs, 1, -1, -1, $conf->currency)."</b>";
  87. print '<br>';
  88. } elseif ($action == "publicpreorder") {
  89. print '<button type="button" class="publicphonebutton2 phoneblue total" onclick="TakeposPrintingOrder();">'.$langs->trans('Confirm').'</button>';
  90. print "<br><br>";
  91. print '<div class="comment">
  92. <textarea class="textinput" placeholder="'.$langs->trans('Note').'"></textarea>
  93. </div>';
  94. print '<br>';
  95. } elseif ($action == "publicpayment") {
  96. $langs->loadLangs(array("orders"));
  97. print '<h1>'.$langs->trans('StatusOrderDelivered').'</h1>';
  98. print '<button type="button" class="publicphonebutton2 phoneblue total" onclick="CheckPlease();">'.$langs->trans('Payment').'</button>';
  99. print '<br>';
  100. } elseif ($action == "checkplease") {
  101. if (GETPOSTISSET("payment")) {
  102. print '<h1>'.$langs->trans('StatusOrderDelivered').'</h1>';
  103. require_once DOL_DOCUMENT_ROOT.'/core/class/dolreceiptprinter.class.php';
  104. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  105. $printer = new dolReceiptPrinter($db);
  106. $printer->initPrinter(getDolGlobalString('TAKEPOS_PRINTER_TO_USE'.$_SESSION["takeposterminal"]));
  107. $printer->printer->feed();
  108. $printer->printer->feed();
  109. $printer->printer->text($langs->trans('IM'));
  110. $printer->printer->feed();
  111. $printer->printer->text($langs->trans('Place').": ".$place);
  112. $printer->printer->feed();
  113. $printer->printer->text($langs->trans('Payment').": ".$langs->trans(GETPOST('payment', 'alpha')));
  114. $printer->printer->feed();
  115. $printer->printer->feed();
  116. $printer->printer->feed();
  117. $printer->printer->feed();
  118. $printer->printer->feed();
  119. $printer->close();
  120. } else {
  121. print '<button type="button" class="publicphonebutton2 phoneblue total" onclick="CheckPlease(\'Cash\')">'.$langs->trans('Cash').'</button>';
  122. print '<button type="button" class="publicphonebutton2 phoneblue total" onclick="CheckPlease(\'CreditCard\')">'.$langs->trans('CreditCard').'</button>';
  123. print '<br>';
  124. }
  125. } elseif ($action == "editline") {
  126. $placeid = GETPOST('placeid', 'int');
  127. $selectedline = GETPOST('selectedline', 'int');
  128. $invoice = new Facture($db);
  129. $invoice->fetch($placeid);
  130. foreach ($invoice->lines as $line) {
  131. if ($line->id == $selectedline) {
  132. $prod = new Product($db);
  133. $prod->fetch($line->fk_product);
  134. print "<b>".$prod->label."</b><br>";
  135. print '<img class="imgwrapper" width="60%" src="'.DOL_URL_ROOT.'/takepos/public/auto_order.php?genimg=pro&query=pro&id='.$line->fk_product.'">';
  136. print "<br>".$prod->description;
  137. print "<br><b>".price($prod->price_ttc, 1, $langs, 1, -1, -1, $conf->currency)."</b>";
  138. print '<br>';
  139. print '<button type="button" class="publicphonebutton2 phonered width24" onclick="SetQty(place, '.$selectedline.', '.($line->qty - 1).')">-</button>';
  140. print '<button type="button" class="publicphonebutton2 phonegreen width24" onclick="SetQty(place, '.$selectedline.', '.($line->qty + 1).')">+</button>';
  141. print '<button type="button" class="publicphonebutton2 phoneblue width24" onclick="SetNote(place, '.$selectedline.')">'.$langs->trans('Note').'</button>';
  142. }
  143. }
  144. } else {
  145. ?>
  146. <script type="text/javascript">
  147. <?php
  148. $categorie = new Categorie($db);
  149. $categories = $categorie->get_full_arbo('product', (($conf->global->TAKEPOS_ROOT_CATEGORY_ID > 0) ? $conf->global->TAKEPOS_ROOT_CATEGORY_ID : 0), 1);
  150. // Search root category to know its level
  151. //$conf->global->TAKEPOS_ROOT_CATEGORY_ID=0;
  152. $levelofrootcategory = 0;
  153. if ($conf->global->TAKEPOS_ROOT_CATEGORY_ID > 0) {
  154. foreach ($categories as $key => $categorycursor) {
  155. if ($categorycursor['id'] == $conf->global->TAKEPOS_ROOT_CATEGORY_ID) {
  156. $levelofrootcategory = $categorycursor['level'];
  157. break;
  158. }
  159. }
  160. }
  161. $levelofmaincategories = $levelofrootcategory + 1;
  162. $maincategories = array();
  163. $subcategories = array();
  164. foreach ($categories as $key => $categorycursor) {
  165. if ($categorycursor['level'] == $levelofmaincategories) {
  166. $maincategories[$key] = $categorycursor;
  167. } else {
  168. $subcategories[$key] = $categorycursor;
  169. }
  170. }
  171. sort($maincategories);
  172. sort($subcategories);
  173. ?>
  174. var categories = <?php echo json_encode($maincategories); ?>;
  175. var subcategories = <?php echo json_encode($subcategories); ?>;
  176. var currentcat;
  177. var pageproducts=0;
  178. var pagecategories=0;
  179. var pageactions=0;
  180. var place="<?php echo $place; ?>";
  181. var editaction="qty";
  182. var editnumber="";
  183. $( document ).ready(function() {
  184. console.log("Refresh");
  185. LoadPlace(place);
  186. });
  187. function LoadPlace(placeid){
  188. place=placeid;
  189. <?php
  190. if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
  191. echo '$("#phonediv2").load("auto_order.php?mobilepage=invoice&place="+place, function() {
  192. });';
  193. } else {
  194. echo '$("#phonediv2").load("invoice.php?mobilepage=invoice&place="+place, function() {
  195. });';
  196. }
  197. ?>
  198. LoadCats();
  199. }
  200. function AddProduct(placeid, productid){
  201. <?php
  202. // If is a public terminal first show product information
  203. if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
  204. print 'place=placeid;
  205. $("#phonediv1").load("auto_order.php?action=productinfo&token='.newToken().'&place="+place+"&idproduct="+productid, function() {
  206. });';
  207. } else {
  208. print 'AddProductConfirm(placeid, productid);';
  209. }
  210. ?>
  211. }
  212. function PublicPreOrder(){
  213. $("#phonediv1").load("auto_order.php?action=publicpreorder&token=<?php echo newToken(); ?>&place="+place, function() {
  214. });
  215. }
  216. function AddProductConfirm(placeid, productid){
  217. place=placeid;
  218. <?php
  219. if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
  220. echo '$("#phonediv2").load("auto_order.php?mobilepage=invoice&action=addline&token='.newToken().'&place="+place+"&idproduct="+productid, function() {
  221. });';
  222. } else {
  223. echo '$("#phonediv2").load("invoice.php?mobilepage=invoice&action=addline&token='.newToken().'&place="+place+"&idproduct="+productid, function() {
  224. });';
  225. }
  226. ?>
  227. return true;
  228. }
  229. function SetQty(place, selectedline, qty){
  230. <?php
  231. if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
  232. ?>
  233. if (qty==0){
  234. $("#phonediv2").load("auto_order.php?mobilepage=invoice&action=deleteline&token=<?php echo newToken(); ?>&place="+place+"&idline="+selectedline, function() {
  235. });
  236. }
  237. else{
  238. $("#phonediv2").load("auto_order.php?mobilepage=invoice&action=updateqty&token=<?php echo newToken(); ?>&place="+place+"&idline="+selectedline+"&number="+qty, function() {
  239. });
  240. }
  241. <?php
  242. } else {
  243. ?>
  244. if (qty==0){
  245. $("#phonediv2").load("invoice.php?mobilepage=invoice&action=deleteline&token=<?php echo newToken(); ?>&place="+place+"&idline="+selectedline, function() {
  246. });
  247. }
  248. else{
  249. $("#phonediv2").load("invoice.php?mobilepage=invoice&action=updateqty&token=<?php echo newToken(); ?>&place="+place+"&idline="+selectedline+"&number="+qty, function() {
  250. });
  251. }
  252. <?php
  253. }
  254. ?>
  255. LoadCats();
  256. return true;
  257. }
  258. function SetNote(place, selectedline){
  259. var note = prompt("<?php $langs->trans('Note'); ?>", "");
  260. $("#phonediv2").load("auto_order.php?mobilepage=invoice&action=updateqty&token=<?php echo newToken(); ?>&place="+place+"&idline="+selectedline+"&number="+qty, function() {
  261. });
  262. LoadCats();
  263. }
  264. function LoadCats(){
  265. <?php
  266. if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
  267. echo '$("#phonediv1").load("auto_order.php?mobilepage=cats&place="+place, function() {
  268. });';
  269. } else {
  270. echo '$("#phonediv1").load("invoice.php?mobilepage=cats&place="+place, function() {
  271. });';
  272. }
  273. ?>
  274. }
  275. function LoadProducts(idcat){
  276. <?php
  277. if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
  278. echo '$("#phonediv1").load("auto_order.php?mobilepage=products&catid="+idcat+"&place="+place, function() {
  279. });';
  280. } else {
  281. echo '$("#phonediv1").load("invoice.php?mobilepage=products&catid="+idcat+"&place="+place, function() {
  282. });';
  283. }
  284. ?>
  285. }
  286. function LoadPlacesList(){
  287. $("#phonediv1").load("invoice.php?mobilepage=places", function() {
  288. });
  289. }
  290. function TakeposPrintingOrder(){
  291. console.log("TakeposPrintingOrder");
  292. <?php
  293. if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
  294. echo '$("#phonediv2").load("auto_order.php?action=order&token='.newToken().'&mobilepage=order&place="+place, function() {
  295. });';
  296. echo '$("#phonediv1").load("auto_order.php?action=publicpayment&token='.newToken().'&place="+place, function() {
  297. });';
  298. } else {
  299. echo '$("#phonediv2").load("invoice.php?action=order&token='.newToken().'&place="+place, function() {
  300. });';
  301. }
  302. ?>
  303. }
  304. function Exit(){
  305. window.location.href='../user/logout.php?token=<?php echo newToken(); ?>';
  306. }
  307. function CheckPlease(payment){
  308. if (payment==undefined){
  309. $("#phonediv1").load("auto_order.php?action=checkplease&token=<?php echo newToken(); ?>&place="+place, function() {
  310. });
  311. }
  312. else{
  313. console.log("Request the check to the waiter");
  314. $("#phonediv1").load("auto_order.php?action=checkplease&token=<?php echo newToken(); ?>&place=<?php echo $place; ?>&payment="+payment, function() {
  315. });
  316. }
  317. }
  318. </script>
  319. <body style="background-color:#D1D1D1;">
  320. <?php
  321. if ($conf->global->TAKEPOS_NUM_TERMINALS != "1" && $_SESSION["takeposterminal"] == "") {
  322. print '<div class="dialog-info-takepos-terminal" id="dialog-info" title="TakePOS">'.$langs->trans('TerminalSelect').'</div>';
  323. }
  324. ?>
  325. <div class="container">
  326. <div class="phonebuttonsrow">
  327. <?php
  328. if (!defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
  329. print '<button type="button" class="phonebutton" onclick="LoadPlacesList();">'.strtoupper(substr($langs->trans('Floors'), 0, 3)).'</button>';
  330. print '<button type="button" class="phonebutton" onclick="LoadCats();">'.strtoupper(substr($langs->trans('Categories'), 0, 3)).'</button>';
  331. print '<button type="button" class="phonebutton" onclick="TakeposPrintingOrder();">'.strtoupper(substr($langs->trans('Order'), 0, 3)).'</button>';
  332. print '<button type="button" class="phonebutton" onclick="Exit();">'.strtoupper(substr($langs->trans('Logout'), 0, 3)).'</button>';
  333. } else {
  334. print '<button type="button" class="publicphonebutton phoneblue" onclick="LoadCats();">'.strtoupper(substr($langs->trans('Categories'), 0, 5)).'</button>';
  335. print '<button type="button" class="publicphonebutton phoneorange" onclick="PublicPreOrder();">'.strtoupper(substr($langs->trans('Order'), 0, 5)).'</button>';
  336. print '<button type="button" class="publicphonebutton phonegreen" onclick="CheckPlease();">'.strtoupper(substr($langs->trans('Payment'), 0, 5)).'</button>';
  337. }
  338. ?>
  339. </div>
  340. <div class="phonerow2">
  341. <div id="phonediv2" class="phonediv2"></div>
  342. </div>
  343. <div class="phonerow1">
  344. <div id="phonediv1" class="phonediv1"></div>
  345. </div>
  346. </div>
  347. </body>
  348. <?php
  349. }
  350. llxFooter();
  351. $db->close();