phone.php 14 KB

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