phone.php 14 KB

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