takepos.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  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 <http://www.gnu.org/licenses/>.
  16. */
  17. //if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1'); // Not disabled cause need to load personalized language
  18. //if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1'); // Not disabled cause need to load personalized language
  19. //if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
  20. //if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1');
  21. if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK','1');
  22. if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1');
  23. if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1');
  24. if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1');
  25. if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1');
  26. $_GET['theme']="md"; // Force theme. MD theme provides better look and feel to TakePOS
  27. require '../main.inc.php'; // Load $user and permissions
  28. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  30. require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php';
  31. $place = GETPOST('place','int');
  32. if ($place=="") $place="0";
  33. $action = GETPOST('action','alpha');
  34. $langs->loadLangs(array("bills","orders","commercial","cashdesk","receiptprinter"));
  35. /*
  36. * View
  37. */
  38. // Title
  39. $title='TakePOS - Dolibarr '.DOL_VERSION;
  40. if (! empty($conf->global->MAIN_APPLICATION_TITLE)) $title='TakePOS - '.$conf->global->MAIN_APPLICATION_TITLE;
  41. top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss);
  42. ?>
  43. <link rel="stylesheet" href="css/pos.css?a=xxx">
  44. <script type="text/javascript" src="js/takepos.js" ></script>
  45. <link rel="stylesheet" href="css/colorbox.css" type="text/css" media="screen" />
  46. <script type="text/javascript" src="js/jquery.colorbox-min.js"></script>
  47. <script language="javascript">
  48. <?php
  49. $categorie = new Categorie($db);
  50. $categories = $categorie->get_full_arbo('product');
  51. ?>
  52. var categories = <?php echo json_encode($categories); ?>;
  53. var currentcat;
  54. var pageproducts=0;
  55. var pagecategories=0;
  56. var place="<?php echo $place;?>";
  57. var editaction="qty";
  58. var editnumber="";
  59. function PrintCategories(first){
  60. for (i = 0; i < 14; i++) {
  61. if (typeof (categories[parseInt(i)+parseInt(first)]) == "undefined") break;
  62. $("#catdesc"+i).text(categories[parseInt(i)+parseInt(first)]['label']);
  63. $("#catimg"+i).attr("src","genimg/?query=cat&w=55&h=50&id="+categories[parseInt(i)+parseInt(first)]['rowid']);
  64. $("#catdiv"+i).data("rowid",categories[parseInt(i)+parseInt(first)]['rowid']);
  65. }
  66. }
  67. function MoreCategories(moreorless){
  68. if (moreorless=="more"){
  69. $('#catimg15').animate({opacity: '0.5'}, 100);
  70. $('#catimg15').animate({opacity: '1'}, 100);
  71. pagecategories=pagecategories+1;
  72. }
  73. if (moreorless=="less"){
  74. $('#catimg14').animate({opacity: '0.5'}, 100);
  75. $('#catimg14').animate({opacity: '1'}, 100);
  76. if (pagecategories==0) return; //Return if no less pages
  77. pagecategories=pagecategories-1;
  78. }
  79. if (typeof (categories[14*pagecategories] && moreorless=="more") == "undefined"){ // Return if no more pages
  80. pagecategories=pagecategories-1;
  81. return;
  82. }
  83. for (i = 0; i < 14; i++) {
  84. if (typeof (categories[i+(14*pagecategories)]) == "undefined"){
  85. $("#catdesc"+i).text("");
  86. $("#catimg"+i).attr("src","");
  87. continue;
  88. }
  89. $("#catdesc"+i).text(categories[i+(14*pagecategories)]['label']);
  90. $("#catimg"+i).attr("src","genimg/?query=cat&w=55&h=50&id="+categories[i+(14*pagecategories)]['rowid']);
  91. $("#catdiv"+i).data("rowid",categories[i+(14*pagecategories)]['rowid']);
  92. }
  93. }
  94. function LoadProducts(position){
  95. $('#catimg'+position).animate({opacity: '0.5'}, 100);
  96. $('#catimg'+position).animate({opacity: '1'}, 100);
  97. currentcat=$('#catdiv'+position).data('rowid');
  98. if (currentcat=="") return;
  99. pageproducts=0;
  100. $.getJSON('./ajax.php?action=getProducts&category='+currentcat, function(data) {
  101. for (i = 0; i < 30; i++) {
  102. if (typeof (data[i]) == "undefined"){
  103. $("#prodesc"+i).text("");
  104. $("#proimg"+i).attr("src","");
  105. $("#prodiv"+i).data("rowid","");
  106. continue;
  107. }
  108. $("#prodesc"+i).text(data[parseInt(i)]['label']);
  109. $("#proimg"+i).attr("src","genimg/?query=pro&w=55&h=50&id="+data[i]['id']);
  110. $("#prodiv"+i).data("rowid",data[i]['id']);
  111. }
  112. });
  113. }
  114. function MoreProducts(moreorless){
  115. if (moreorless=="more"){
  116. $('#proimg31').animate({opacity: '0.5'}, 100);
  117. $('#proimg31').animate({opacity: '1'}, 100);
  118. pageproducts=pageproducts+1;
  119. }
  120. if (moreorless=="less"){
  121. $('#proimg30').animate({opacity: '0.5'}, 100);
  122. $('#proimg30').animate({opacity: '1'}, 100);
  123. if (pageproducts==0) return; //Return if no less pages
  124. pageproducts=pageproducts-1;
  125. }
  126. $.getJSON('./ajax.php?action=getProducts&category='+currentcat, function(data) {
  127. if (typeof (data[(30*pageproducts)]) == "undefined" && moreorless=="more"){ // Return if no more pages
  128. pageproducts=pageproducts-1;
  129. return;
  130. }
  131. for (i = 0; i < 30; i++) {
  132. if (typeof (data[i+(30*pageproducts)]) == "undefined"){
  133. $("#prodesc"+i).text("");
  134. $("#proimg"+i).attr("src","");
  135. $("#prodiv"+i).data("rowid","");
  136. continue;
  137. }
  138. $("#prodesc"+i).text(data[parseInt(i+(30*pageproducts))]['label']);
  139. $("#proimg"+i).attr("src","genimg/?query=pro&w=55&h=50&id="+data[i+(30*pageproducts)]['id']);
  140. $("#prodiv"+i).data("rowid",data[i+(30*pageproducts)]['id']);
  141. }
  142. });
  143. }
  144. function ClickProduct(position){
  145. $('#proimg'+position).animate({opacity: '0.5'}, 100);
  146. $('#proimg'+position).animate({opacity: '1'}, 100);
  147. idproduct=$('#prodiv'+position).data('rowid');
  148. if (idproduct=="") return;
  149. $("#poslines").load("invoice.php?action=addline&place="+place+"&idproduct="+idproduct, function() {
  150. $('#poslines').scrollTop($('#poslines')[0].scrollHeight);
  151. });
  152. }
  153. function deleteline(){
  154. $("#poslines").load("invoice.php?action=deleteline&place="+place+"&idline="+selectedline, function() {
  155. $('#poslines').scrollTop($('#poslines')[0].scrollHeight);
  156. });
  157. }
  158. function Customer(){
  159. $.colorbox({href:"customers.php?nomassaction=1&place="+place, width:"90%", height:"80%", transition:"none", iframe:"true", title:"<?php echo $langs->trans("Customer");?>"});
  160. }
  161. function CloseBill(){
  162. $.colorbox({href:"pay.php?place="+place, width:"80%", height:"90%", transition:"none", iframe:"true", title:"<?php echo $langs->trans("CloseBill");?>"});
  163. }
  164. function Floors(){
  165. $.colorbox({href:"floors.php?place="+place, width:"90%", height:"90%", transition:"none", iframe:"true", title:"<?php echo $langs->trans("Floors");?>"});
  166. }
  167. function FreeZone(){
  168. $.colorbox({href:"freezone.php?place="+place, onClosed: function () { Refresh(); },width:"80%", height:"30%", transition:"none", iframe:"true", title:"<?php echo $langs->trans("FreeZone");?>"});
  169. }
  170. function Refresh(){
  171. $("#poslines").load("invoice.php?place="+place, function() {
  172. $('#poslines').scrollTop($('#poslines')[0].scrollHeight);
  173. });
  174. }
  175. function Search(){
  176. $("#poslines").load("invoice.php?action=search&place="+place, function() {
  177. $('#poslines').scrollTop($('#poslines')[0].scrollHeight);
  178. });
  179. }
  180. function Search2(){
  181. pageproducts=0;
  182. $.getJSON('./ajax.php?action=search&term='+$('#search').val(), function(data) {
  183. for (i = 0; i < 30; i++) {
  184. if (typeof (data[i]) == "undefined"){
  185. $("#prodesc"+i).text("");
  186. $("#proimg"+i).attr("src","");
  187. $("#prodiv"+i).data("rowid","");
  188. continue;
  189. }
  190. $("#prodesc"+i).text(data[parseInt(i)]['label']);
  191. $("#proimg"+i).attr("src","genimg/?query=pro&w=55&h=50&id="+data[i]['rowid']);
  192. $("#prodiv"+i).data("rowid",data[i]['rowid']);
  193. }
  194. });
  195. }
  196. function Edit(number){
  197. var text=selectedtext+"<br> ";
  198. if (number=='c'){
  199. editnumber="";
  200. Refresh();
  201. return;
  202. }
  203. else if (number=='qty'){
  204. if (editaction=='qty' && editnumber!=""){
  205. $("#poslines").load("invoice.php?action=updateqty&place="+place+"&idline="+selectedline+"&number="+editnumber, function() {
  206. editnumber="";
  207. $('#poslines').scrollTop($('#poslines')[0].scrollHeight);
  208. $("#qty").html("<?php echo $langs->trans("Qty"); ?>");
  209. });
  210. return;
  211. }
  212. else {
  213. editaction="qty";
  214. }
  215. }
  216. else if (number=='p'){
  217. if (editaction=='p' && editnumber!=""){
  218. $("#poslines").load("invoice.php?action=updateprice&place="+place+"&idline="+selectedline+"&number="+editnumber, function() {
  219. editnumber="";
  220. $('#poslines').scrollTop($('#poslines')[0].scrollHeight);
  221. $("#price").html("<?php echo $langs->trans("Price"); ?>");
  222. });
  223. return;
  224. }
  225. else {
  226. editaction="p";
  227. }
  228. }
  229. else if (number=='r'){
  230. if (editaction=='r' && editnumber!=""){
  231. $("#poslines").load("invoice.php?action=updatereduction&place="+place+"&idline="+selectedline+"&number="+editnumber, function() {
  232. editnumber="";
  233. $('#poslines').scrollTop($('#poslines')[0].scrollHeight);
  234. $("#reduction").html("<?php echo $langs->trans("ReductionShort"); ?>");
  235. });
  236. return;
  237. }
  238. else {
  239. editaction="r";
  240. }
  241. }
  242. else {
  243. editnumber=editnumber+number;
  244. }
  245. if (editaction=='qty'){
  246. text=text+"<?php echo $langs->trans("Modify")." -> ".$langs->trans("Qty").": "; ?>";
  247. $("#qty").html("OK");
  248. $("#price").html("<?php echo $langs->trans("Price"); ?>");
  249. $("#reduction").html("<?php echo $langs->trans("ReductionShort"); ?>");
  250. }
  251. if (editaction=='p'){
  252. text=text+"<?php echo $langs->trans("Modify")." -> ".$langs->trans("Price").": "; ?>";
  253. $("#qty").html("<?php echo $langs->trans("Qty"); ?>");
  254. $("#price").html("OK");
  255. $("#reduction").html("<?php echo $langs->trans("ReductionShort"); ?>");
  256. }
  257. if (editaction=='r'){
  258. text=text+"<?php echo $langs->trans("Modify")." -> ".$langs->trans("ReductionShort").": "; ?>";
  259. $("#qty").html("<?php echo $langs->trans("Qty"); ?>");
  260. $("#price").html("<?php echo $langs->trans("Price"); ?>");
  261. $("#reduction").html("OK");
  262. }
  263. $('#'+selectedline).find("td:first").html(text+editnumber);
  264. }
  265. function TakeposPrintingOrder(){
  266. $("#poslines").load("invoice.php?action=order&place="+place, function() {
  267. $('#poslines').scrollTop($('#poslines')[0].scrollHeight);
  268. });
  269. }
  270. function OpenDrawer(){
  271. $.ajax({
  272. type: "POST",
  273. url: 'http://<?php print $conf->global->TAKEPOS_PRINT_SERVER;?>:8111/print',
  274. data: "opendrawer"
  275. });
  276. }
  277. $( document ).ready(function() {
  278. PrintCategories(0);
  279. LoadProducts(0);
  280. Refresh();
  281. });
  282. </script>
  283. <body style="overflow: hidden; background-color:#E8E8E8;">
  284. <div id="poslines" style="position:absolute; top:2%; left:0.5%; height:36%; width:31%; overflow: auto;">
  285. </div>
  286. <div style="position:absolute; top:1%; left:32.5%; height:37%; width:32.5%;">
  287. <button type="button" class="calcbutton" onclick="Edit(7);">7</button>
  288. <button type="button" class="calcbutton" onclick="Edit(8);">8</button>
  289. <button type="button" class="calcbutton" onclick="Edit(9);">9</button>
  290. <button type="button" id="qty" class="calcbutton2" onclick="Edit('qty');"><?php echo $langs->trans("Qty"); ?></button>
  291. <button type="button" class="calcbutton" onclick="Edit(4);">4</button>
  292. <button type="button" class="calcbutton" onclick="Edit(5);">5</button>
  293. <button type="button" class="calcbutton" onclick="Edit(6);">6</button>
  294. <button type="button" id="price" class="calcbutton2" onclick="Edit('p');"><?php echo $langs->trans("Price"); ?></button>
  295. <button type="button" class="calcbutton" onclick="Edit(1);">1</button>
  296. <button type="button" class="calcbutton" onclick="Edit(2);">2</button>
  297. <button type="button" class="calcbutton" onclick="Edit(3);">3</button>
  298. <button type="button" id="reduction" class="calcbutton2" onclick="Edit('r');"><?php echo $langs->trans("ReductionShort"); ?></button>
  299. <button type="button" class="calcbutton" onclick="Edit(0);">0</button>
  300. <button type="button" class="calcbutton" onclick="Edit('.');">.</button>
  301. <button type="button" class="calcbutton" onclick="Edit('c');">C</button>
  302. <button type="button" class="calcbutton2" id="delete" style="color: red;" onclick="deleteline();"><b>X</b></button>
  303. </div>
  304. <?php
  305. // User menu and external TakePOS modules
  306. $menus = array();
  307. $r=0;
  308. $menus[$r++]=array('title'=>$langs->trans("SearchProduct"),
  309. 'action'=>'Search();');
  310. $menus[$r++]=array('title'=>$langs->trans("FreeZone"),
  311. 'action'=>'FreeZone();');
  312. $menus[$r++]=array('title'=>$langs->trans("Customer"),
  313. 'action'=>'Customer();');
  314. $menus[$r++]=array('title'=>$langs->trans("BackOffice"),
  315. 'action'=>'window.open(\''.DOL_URL_ROOT.'\', \'backoffice\');');
  316. $menus[$r++]=array('title'=>$langs->trans("ValidateBill"),
  317. 'action'=>'CloseBill();');
  318. $menus[$r++]=array('title'=>$langs->trans("Logout"),
  319. 'action'=>'window.location.href=\''.DOL_URL_ROOT.'/user/logout.php\';');
  320. if($conf->global->TAKEPOS_BAR_RESTAURANT){
  321. $menus[$r++]=array('title'=>$langs->trans("Floors"),
  322. 'action'=>'Floors();');
  323. if ($conf->global->TAKEPOS_ORDER_PRINTERS){
  324. $menus[$r++]=array('title'=>$langs->trans("Order"),
  325. 'action'=>'TakeposPrintingOrder();');
  326. }
  327. }
  328. if ($conf->global->TAKEPOSCONNECTOR){
  329. $menus[$r++]=array('title'=>$langs->trans("DOL_OPEN_DRAWER"),
  330. 'action'=>'OpenDrawer();');
  331. }
  332. ?>
  333. <div style="position:absolute; top:1%; left:65.5%; height:37%; width:32.5%;">
  334. <?php
  335. foreach($menus as $menu) {
  336. echo '<button type="button" class="actionbutton" onclick="'.$menu['action'].'">'.$menu['title'].'</button>';
  337. }
  338. ?>
  339. </div>
  340. <div style="position:absolute; top:39%; left:0.3%; height:59%; width:32%;">
  341. <?php
  342. $count=0;
  343. while ($count<16)
  344. {
  345. ?>
  346. <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;?>'>
  347. <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;?>'/>
  348. <div class='description'>
  349. <div class='description_content' id='catdesc<?php echo $count;?>'></div>
  350. </div>
  351. </div>
  352. <?php
  353. $count++;
  354. }
  355. ?>
  356. </div>
  357. <div style="position:absolute; top:39%; left:32%; height:58%; width:72%;">
  358. <?php
  359. $count=0;
  360. while ($count<32)
  361. {
  362. ?>
  363. <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.');"';?>>
  364. <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;?>'/>
  365. <div class='description'>
  366. <div class='description_content' id='prodesc<?php echo $count;?>'></div>
  367. </div>
  368. </div>
  369. <?php
  370. $count++;
  371. }
  372. ?>
  373. </div>
  374. </body>
  375. <?php
  376. llxFooter();
  377. $db->close();