takepos.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  1. <?php
  2. /* Copyright (C) 2018 Andreu Bisquerra <jove@bisquerra.com>
  3. * Copyright (C) 2019 Josep Lluís Amador <joseplluis@lliuretic.cat>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. //if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1'); // Not disabled cause need to load personalized language
  19. //if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1'); // Not disabled cause need to load personalized language
  20. //if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
  21. //if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1');
  22. if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK','1');
  23. if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1');
  24. if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1');
  25. if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1');
  26. if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1');
  27. $_GET['theme']="md"; // Force theme. MD theme provides better look and feel to TakePOS
  28. require '../main.inc.php'; // Load $user and permissions
  29. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  31. require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
  33. $place = GETPOST('place','int');
  34. if ($place=="") $place="0";
  35. $action = GETPOST('action','alpha');
  36. $langs->loadLangs(array("bills","orders","commercial","cashdesk","receiptprinter"));
  37. /*
  38. * View
  39. */
  40. // Title
  41. $title='TakePOS - Dolibarr '.DOL_VERSION;
  42. if (! empty($conf->global->MAIN_APPLICATION_TITLE)) $title='TakePOS - '.$conf->global->MAIN_APPLICATION_TITLE;
  43. $head='<meta name="apple-mobile-web-app-title" content="TakePOS"/>
  44. <meta name="apple-mobile-web-app-capable" content="yes">
  45. <meta name="mobile-web-app-capable" content="yes">
  46. <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>';
  47. top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss);
  48. ?>
  49. <link rel="stylesheet" href="css/pos.css">
  50. <script type="text/javascript" src="js/takepos.js" ></script>
  51. <link rel="stylesheet" href="css/colorbox.css" type="text/css" media="screen" />
  52. <script type="text/javascript" src="js/jquery.colorbox-min.js"></script>
  53. <script language="javascript">
  54. <?php
  55. $categorie = new Categorie($db);
  56. $categories = $categorie->get_full_arbo('product');
  57. ?>
  58. var categories = <?php echo json_encode($categories); ?>;
  59. var currentcat;
  60. var pageproducts=0;
  61. var pagecategories=0;
  62. var pageactions=0;
  63. var place="<?php echo $place;?>";
  64. var editaction="qty";
  65. var editnumber="";
  66. function PrintCategories(first){
  67. for (i = 0; i < 14; i++) {
  68. if (typeof (categories[parseInt(i)+parseInt(first)]) == "undefined") break;
  69. $("#catdesc"+i).text(categories[parseInt(i)+parseInt(first)]['label']);
  70. $("#catimg"+i).attr("src","genimg/?query=cat&w=55&h=50&id="+categories[parseInt(i)+parseInt(first)]['rowid']);
  71. $("#catdiv"+i).data("rowid",categories[parseInt(i)+parseInt(first)]['rowid']);
  72. }
  73. }
  74. function MoreCategories(moreorless){
  75. if (moreorless=="more"){
  76. $('#catimg15').animate({opacity: '0.5'}, 1);
  77. $('#catimg15').animate({opacity: '1'}, 100);
  78. pagecategories=pagecategories+1;
  79. }
  80. if (moreorless=="less"){
  81. $('#catimg14').animate({opacity: '0.5'}, 1);
  82. $('#catimg14').animate({opacity: '1'}, 100);
  83. if (pagecategories==0) return; //Return if no less pages
  84. pagecategories=pagecategories-1;
  85. }
  86. if (typeof (categories[14*pagecategories] && moreorless=="more") == "undefined"){ // Return if no more pages
  87. pagecategories=pagecategories-1;
  88. return;
  89. }
  90. for (i = 0; i < 14; i++) {
  91. if (typeof (categories[i+(14*pagecategories)]) == "undefined"){
  92. $("#catdesc"+i).text("");
  93. $("#catimg"+i).attr("src","");
  94. continue;
  95. }
  96. $("#catdesc"+i).text(categories[i+(14*pagecategories)]['label']);
  97. $("#catimg"+i).attr("src","genimg/?query=cat&w=55&h=50&id="+categories[i+(14*pagecategories)]['rowid']);
  98. $("#catdiv"+i).data("rowid",categories[i+(14*pagecategories)]['rowid']);
  99. }
  100. }
  101. function LoadProducts(position){
  102. $('#catimg'+position).animate({opacity: '0.5'}, 1);
  103. $('#catimg'+position).animate({opacity: '1'}, 100);
  104. currentcat=$('#catdiv'+position).data('rowid');
  105. if (currentcat=="") return;
  106. pageproducts=0;
  107. $.getJSON('./ajax.php?action=getProducts&category='+currentcat, function(data) {
  108. idata=0; //product data counter
  109. ishow=0; //product to show counter
  110. while (idata < 30) {
  111. if (typeof (data[idata]) == "undefined") {
  112. $("#prodesc"+ishow).text("");
  113. $("#proimg"+ishow).attr("src","");
  114. $("#prodiv"+ishow).data("rowid","");
  115. ishow++; //Next product to show after print data product
  116. }
  117. else if ((data[idata]['status']) == "1") {
  118. //Only show products with status=1 (for sell)
  119. $("#prodesc"+ishow).text(data[parseInt(idata)]['label']);
  120. $("#proimg"+ishow).attr("src","genimg/?query=pro&w=55&h=50&id="+data[idata]['id']);
  121. $("#prodiv"+ishow).data("rowid",data[idata]['id']);
  122. ishow++; //Next product to show after print data product
  123. }
  124. idata++; //Next data everytime
  125. }
  126. });
  127. }
  128. function MoreProducts(moreorless){
  129. if (moreorless=="more"){
  130. $('#proimg31').animate({opacity: '0.5'}, 1);
  131. $('#proimg31').animate({opacity: '1'}, 100);
  132. pageproducts=pageproducts+1;
  133. }
  134. if (moreorless=="less"){
  135. $('#proimg30').animate({opacity: '0.5'}, 1);
  136. $('#proimg30').animate({opacity: '1'}, 100);
  137. if (pageproducts==0) return; //Return if no less pages
  138. pageproducts=pageproducts-1;
  139. }
  140. $.getJSON('./ajax.php?action=getProducts&category='+currentcat, function(data) {
  141. if (typeof (data[(30*pageproducts)]) == "undefined" && moreorless=="more"){ // Return if no more pages
  142. pageproducts=pageproducts-1;
  143. return;
  144. }
  145. idata=30*pageproducts; //product data counter
  146. ishow=0; //product to show counter
  147. while (idata < 30) {
  148. if (typeof (data[idata]) == "undefined") {
  149. $("#prodesc"+ishow).text("");
  150. $("#proimg"+ishow).attr("src","");
  151. $("#prodiv"+ishow).data("rowid","");
  152. ishow++; //Next product to show after print data product
  153. }
  154. else if ((data[idata]['status']) == "1") {
  155. //Only show products with status=1 (for sell)
  156. $("#prodesc"+ishow).text(data[parseInt(idata)]['label']);
  157. $("#proimg"+ishow).attr("src","genimg/?query=pro&w=55&h=50&id="+data[idata]['id']);
  158. $("#prodiv"+ishow).data("rowid",data[idata]['id']);
  159. ishow++; //Next product to show after print data product
  160. }
  161. idata++; //Next data everytime
  162. }
  163. });
  164. }
  165. function ClickProduct(position){
  166. $('#proimg'+position).animate({opacity: '0.5'}, 1);
  167. $('#proimg'+position).animate({opacity: '1'}, 100);
  168. idproduct=$('#prodiv'+position).data('rowid');
  169. if (idproduct=="") return;
  170. $("#poslines").load("invoice.php?action=addline&place="+place+"&idproduct="+idproduct, function() {
  171. $('#poslines').scrollTop($('#poslines')[0].scrollHeight);
  172. });
  173. }
  174. function deleteline(){
  175. $("#poslines").load("invoice.php?action=deleteline&place="+place+"&idline="+selectedline, function() {
  176. $('#poslines').scrollTop($('#poslines')[0].scrollHeight);
  177. });
  178. }
  179. function Customer(){
  180. $.colorbox({href:"customers.php?nomassaction=1&place="+place, width:"90%", height:"80%", transition:"none", iframe:"true", title:"<?php echo $langs->trans("Customer");?>"});
  181. }
  182. function CloseBill(){
  183. $.colorbox({href:"pay.php?place="+place, width:"80%", height:"90%", transition:"none", iframe:"true", title:"<?php echo $langs->trans("CloseBill");?>"});
  184. }
  185. function Floors(){
  186. $.colorbox({href:"floors.php?place="+place, width:"90%", height:"90%", transition:"none", iframe:"true", title:"<?php echo $langs->trans("Floors");?>"});
  187. }
  188. function FreeZone(){
  189. $.colorbox({href:"freezone.php?place="+place, onClosed: function () { Refresh(); },width:"80%", height:"30%", transition:"none", iframe:"true", title:"<?php echo $langs->trans("FreeZone");?>"});
  190. }
  191. function Refresh(){
  192. $("#poslines").load("invoice.php?place="+place, function() {
  193. $('#poslines').scrollTop($('#poslines')[0].scrollHeight);
  194. });
  195. }
  196. function Search(){
  197. $("#poslines").load("invoice.php?action=search&place="+place, function() {
  198. $('#poslines').scrollTop($('#poslines')[0].scrollHeight);
  199. });
  200. }
  201. function Search2(){
  202. pageproducts=0;
  203. $.getJSON('./ajax.php?action=search&term='+$('#search').val(), function(data) {
  204. for (i = 0; i < 30; i++) {
  205. if (typeof (data[i]) == "undefined"){
  206. $("#prodesc"+i).text("");
  207. $("#proimg"+i).attr("src","");
  208. $("#prodiv"+i).data("rowid","");
  209. continue;
  210. }
  211. $("#prodesc"+i).text(data[parseInt(i)]['label']);
  212. $("#proimg"+i).attr("src","genimg/?query=pro&w=55&h=50&id="+data[i]['rowid']);
  213. $("#prodiv"+i).data("rowid",data[i]['rowid']);
  214. }
  215. });
  216. }
  217. function Edit(number){
  218. var text=selectedtext+"<br> ";
  219. if (number=='c'){
  220. editnumber="";
  221. Refresh();
  222. return;
  223. }
  224. else if (number=='qty'){
  225. if (editaction=='qty' && editnumber!=""){
  226. $("#poslines").load("invoice.php?action=updateqty&place="+place+"&idline="+selectedline+"&number="+editnumber, function() {
  227. editnumber="";
  228. $('#poslines').scrollTop($('#poslines')[0].scrollHeight);
  229. $("#qty").html("<?php echo $langs->trans("Qty"); ?>");
  230. });
  231. return;
  232. }
  233. else {
  234. editaction="qty";
  235. }
  236. }
  237. else if (number=='p'){
  238. if (editaction=='p' && editnumber!=""){
  239. $("#poslines").load("invoice.php?action=updateprice&place="+place+"&idline="+selectedline+"&number="+editnumber, function() {
  240. editnumber="";
  241. $('#poslines').scrollTop($('#poslines')[0].scrollHeight);
  242. $("#price").html("<?php echo $langs->trans("Price"); ?>");
  243. });
  244. return;
  245. }
  246. else {
  247. editaction="p";
  248. }
  249. }
  250. else if (number=='r'){
  251. if (editaction=='r' && editnumber!=""){
  252. $("#poslines").load("invoice.php?action=updatereduction&place="+place+"&idline="+selectedline+"&number="+editnumber, function() {
  253. editnumber="";
  254. $('#poslines').scrollTop($('#poslines')[0].scrollHeight);
  255. $("#reduction").html("<?php echo $langs->trans("ReductionShort"); ?>");
  256. });
  257. return;
  258. }
  259. else {
  260. editaction="r";
  261. }
  262. }
  263. else {
  264. editnumber=editnumber+number;
  265. }
  266. if (editaction=='qty'){
  267. text=text+"<?php echo $langs->trans("Modify")." -> ".$langs->trans("Qty").": "; ?>";
  268. $("#qty").html("OK");
  269. $("#price").html("<?php echo $langs->trans("Price"); ?>");
  270. $("#reduction").html("<?php echo $langs->trans("ReductionShort"); ?>");
  271. }
  272. if (editaction=='p'){
  273. text=text+"<?php echo $langs->trans("Modify")." -> ".$langs->trans("Price").": "; ?>";
  274. $("#qty").html("<?php echo $langs->trans("Qty"); ?>");
  275. $("#price").html("OK");
  276. $("#reduction").html("<?php echo $langs->trans("ReductionShort"); ?>");
  277. }
  278. if (editaction=='r'){
  279. text=text+"<?php echo $langs->trans("Modify")." -> ".$langs->trans("ReductionShort").": "; ?>";
  280. $("#qty").html("<?php echo $langs->trans("Qty"); ?>");
  281. $("#price").html("<?php echo $langs->trans("Price"); ?>");
  282. $("#reduction").html("OK");
  283. }
  284. $('#'+selectedline).find("td:first").html(text+editnumber);
  285. }
  286. function TakeposPrintingOrder(){
  287. $("#poslines").load("invoice.php?action=order&place="+place, function() {
  288. $('#poslines').scrollTop($('#poslines')[0].scrollHeight);
  289. });
  290. }
  291. function TakeposPrintingTemp(){
  292. $("#poslines").load("invoice.php?action=temp&place="+place, function() {
  293. $('#poslines').scrollTop($('#poslines')[0].scrollHeight);
  294. });
  295. }
  296. function OpenDrawer(){
  297. $.ajax({
  298. type: "POST",
  299. url: 'http://<?php print $conf->global->TAKEPOS_PRINT_SERVER;?>:8111/print',
  300. data: "opendrawer"
  301. });
  302. }
  303. function MoreActions(totalactions){
  304. if (pageactions==0){
  305. pageactions=1;
  306. for (i = 0; i <= totalactions; i++){
  307. if (i<9) $("#action"+i).hide();
  308. else $("#action"+i).show();
  309. }
  310. }
  311. else if (pageactions==1){
  312. pageactions=0;
  313. for (i = 0; i <= totalactions; i++){
  314. if (i<9) $("#action"+i).show();
  315. else $("#action"+i).hide();
  316. }
  317. }
  318. }
  319. $( document ).ready(function() {
  320. PrintCategories(0);
  321. LoadProducts(0);
  322. Refresh();
  323. });
  324. </script>
  325. <body style="overflow: hidden; background-color:#E8E8E8;">
  326. <div class="container">
  327. <div class="row1">
  328. <div id="poslines" class="div1" style="overflow: auto;">
  329. </div>
  330. <div class="div2">
  331. <button type="button" class="calcbutton" onclick="Edit(7);">7</button>
  332. <button type="button" class="calcbutton" onclick="Edit(8);">8</button>
  333. <button type="button" class="calcbutton" onclick="Edit(9);">9</button>
  334. <button type="button" id="qty" class="calcbutton2" onclick="Edit('qty');"><?php echo $langs->trans("Qty"); ?></button>
  335. <button type="button" class="calcbutton" onclick="Edit(4);">4</button>
  336. <button type="button" class="calcbutton" onclick="Edit(5);">5</button>
  337. <button type="button" class="calcbutton" onclick="Edit(6);">6</button>
  338. <button type="button" id="price" class="calcbutton2" onclick="Edit('p');"><?php echo $langs->trans("Price"); ?></button>
  339. <button type="button" class="calcbutton" onclick="Edit(1);">1</button>
  340. <button type="button" class="calcbutton" onclick="Edit(2);">2</button>
  341. <button type="button" class="calcbutton" onclick="Edit(3);">3</button>
  342. <button type="button" id="reduction" class="calcbutton2" onclick="Edit('r');"><?php echo $langs->trans("ReductionShort"); ?></button>
  343. <button type="button" class="calcbutton" onclick="Edit(0);">0</button>
  344. <button type="button" class="calcbutton" onclick="Edit('.');">.</button>
  345. <button type="button" class="calcbutton" onclick="Edit('c');">C</button>
  346. <button type="button" class="calcbutton2" id="delete" style="color: red;" onclick="deleteline();"><b>X</b></button>
  347. </div>
  348. <?php
  349. // User menu and external TakePOS modules
  350. $menus = array();
  351. $r=0;
  352. $menus[$r++]=array('title'=>$langs->trans("SearchProduct"),
  353. 'action'=>'Search();');
  354. $menus[$r++]=array('title'=>$langs->trans("FreeZone"),
  355. 'action'=>'FreeZone();');
  356. $menus[$r++]=array('title'=>$langs->trans("Customer"),
  357. 'action'=>'Customer();');
  358. $menus[$r++]=array('title'=>$langs->trans("BackOffice"),
  359. 'action'=>'window.open(\''.DOL_URL_ROOT.'\', \'backoffice\');');
  360. $menus[$r++]=array('title'=>$langs->trans("ValidateBill"),
  361. 'action'=>'CloseBill();');
  362. $menus[$r++]=array('title'=>$langs->trans("Logout"),
  363. 'action'=>'window.location.href=\''.DOL_URL_ROOT.'/user/logout.php\';');
  364. //BAR RESTAURANT specified menu
  365. if($conf->global->TAKEPOS_BAR_RESTAURANT){
  366. $menus[$r++]=array('title'=>$langs->trans("Floors"),
  367. 'action'=>'Floors();');
  368. if ($conf->global->TAKEPOS_ORDER_PRINTERS){
  369. $menus[$r++]=array('title'=>$langs->trans("Order"),
  370. 'action'=>'TakeposPrintingOrder();');
  371. }
  372. //add temp ticket button
  373. if ($conf->global->TAKEPOS_BAR_RESTAURANT){
  374. if ($conf->global->TAKEPOSCONNECTOR) $menus[$r++]=array('title'=>$langs->trans("Receipt"),'action'=>'TakeposPrinting(placeid);');
  375. else $menus[$r++]=array('title'=>$langs->trans("Receipt"),'action'=>'Print(placeid);');
  376. }
  377. }
  378. if ($conf->global->TAKEPOSCONNECTOR){
  379. $menus[$r++]=array('title'=>$langs->trans("DOL_OPEN_DRAWER"),
  380. 'action'=>'OpenDrawer();');
  381. }
  382. $hookmanager->initHooks(array('takeposfrontend'));
  383. $reshook=$hookmanager->executeHooks('ActionButtons');
  384. if (!empty($reshook))
  385. {
  386. $menus[$r++]=$reshook;
  387. }
  388. ?>
  389. <div class="div3">
  390. <?php
  391. $i = 0;
  392. foreach($menus as $menu) {
  393. $i++;
  394. if (count($menus)>9 and $i==9)
  395. {
  396. echo '<button type="button" id="actionnext" class="actionbutton" onclick="MoreActions('.count($menus).');">'.$langs->trans("Next").'</button>';
  397. echo '<button style="display: none;" type="button" id="action'.$i.'" class="actionbutton" onclick="'.$menu['action'].'">'.$menu['title'].'</button>';
  398. }
  399. elseif ($i>9) echo '<button style="display: none;" type="button" id="action'.$i.'" class="actionbutton" onclick="'.$menu['action'].'">'.$menu['title'].'</button>';
  400. else echo '<button type="button" id="action'.$i.'" class="actionbutton" onclick="'.$menu['action'].'">'.$menu['title'].'</button>';
  401. }
  402. ?>
  403. </div>
  404. </div>
  405. <div class="row2">
  406. <div class="div4">
  407. <?php
  408. $count=0;
  409. while ($count<16)
  410. {
  411. ?>
  412. <div class='wrapper' <?php if ($count==14) echo 'onclick="MoreCategories(\'less\');"'; else if ($count==15) echo 'onclick="MoreCategories(\'more\');"'; else echo 'onclick="LoadProducts('.$count.');"';?> id='catdiv<?php echo $count;?>'>
  413. <img class='imgwrapper' <?php if ($count==14) echo 'src="img/arrow-prev-top.png"'; if ($count==15) echo 'src="img/arrow-next-top.png"';?> width="98%" id='catimg<?php echo $count;?>'/>
  414. <div class='description'>
  415. <div class='description_content' id='catdesc<?php echo $count;?>'></div>
  416. </div>
  417. </div>
  418. <?php
  419. $count++;
  420. }
  421. ?>
  422. </div>
  423. <div class="div5">
  424. <?php
  425. $count=0;
  426. while ($count<32)
  427. {
  428. ?>
  429. <div class='wrapper2' id='prodiv<?php echo $count;?>' <?php if ($count==30) {?> onclick="MoreProducts('less');" <?php } if ($count==31) {?> onclick="MoreProducts('more');" <?php } else echo 'onclick="ClickProduct('.$count.');"';?>>
  430. <img class='imgwrapper' <?php if ($count==30) echo 'src="img/arrow-prev-top.png"'; if ($count==31) echo 'src="img/arrow-next-top.png"';?> width="95%" id='proimg<?php echo $count;?>'/>
  431. <div class='description'>
  432. <div class='description_content' id='prodesc<?php echo $count;?>'></div>
  433. </div>
  434. </div>
  435. <?php
  436. $count++;
  437. }
  438. ?>
  439. </div>
  440. </div>
  441. </div>
  442. </body>
  443. <?php
  444. llxFooter();
  445. $db->close();