split.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. <?php
  2. /* Copyright (C) 2021 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/split.php
  19. * \ingroup takepos
  20. * \brief Page with the content of the popup to split sale
  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. require '../main.inc.php'; // Load $user and permissions
  42. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  43. $langs->loadLangs(array("main", "bills", "cashdesk", "banks"));
  44. $action = GETPOST('action', 'aZ09');
  45. $place = (GETPOST('place', 'aZ09') ? GETPOST('place', 'aZ09') : 0);
  46. if (empty($user->rights->takepos->run)) {
  47. accessforbidden();
  48. }
  49. if ($action=="split") {
  50. $line = GETPOST('line', 'int');
  51. $split = GETPOST('split', 'int');
  52. if ($split==1) { // Split line
  53. $invoice = new Facture($db);
  54. $ret = $invoice->fetch('', '(PROV-POS'.$_SESSION["takeposterminal"].'-SPLIT)');
  55. if ($ret > 0) {
  56. $placeid = $invoice->id;
  57. } else {
  58. $constforcompanyid = 'CASHDESK_ID_THIRDPARTY'.$_SESSION["takeposterminal"];
  59. $invoice->socid = $conf->global->$constforcompanyid;
  60. $invoice->date = dol_now();
  61. $invoice->module_source = 'takepos';
  62. $invoice->pos_source = $_SESSION["takeposterminal"];
  63. $invoice->entity = !empty($_SESSION["takeposinvoiceentity"]) ? $_SESSION["takeposinvoiceentity"] : $conf->entity;
  64. if ($invoice->socid <= 0) {
  65. $langs->load('errors');
  66. dol_htmloutput_errors($langs->trans("ErrorModuleSetupNotComplete", "TakePos"), null, 1);
  67. } else {
  68. $placeid = $invoice->create($user);
  69. if ($placeid < 0) {
  70. dol_htmloutput_errors($invoice->error, $invoice->errors, 1);
  71. }
  72. $sql = "UPDATE ".MAIN_DB_PREFIX."facture set ref='(PROV-POS".$_SESSION["takeposterminal"]."-SPLIT)' where rowid=".$placeid;
  73. $db->query($sql);
  74. }
  75. }
  76. $sql = "UPDATE ".MAIN_DB_PREFIX."facturedet set fk_facture=".$placeid." where rowid=".$line;
  77. $db->query($sql);
  78. } elseif ($split==0) { // Unsplit line
  79. $invoice = new Facture($db);
  80. if ($place=="SPLIT") $place="0"; // Avoid move line to the same place (from SPLIT to SPLIT place)
  81. $ret = $invoice->fetch('', '(PROV-POS'.$_SESSION["takeposterminal"].'-'.$place.')');
  82. if ($ret > 0) {
  83. $placeid = $invoice->id;
  84. } else {
  85. $constforcompanyid = 'CASHDESK_ID_THIRDPARTY'.$_SESSION["takeposterminal"];
  86. $invoice->socid = $conf->global->$constforcompanyid;
  87. $invoice->date = dol_now();
  88. $invoice->module_source = 'takepos';
  89. $invoice->pos_source = $_SESSION["takeposterminal"];
  90. $invoice->entity = !empty($_SESSION["takeposinvoiceentity"]) ? $_SESSION["takeposinvoiceentity"] : $conf->entity;
  91. if ($invoice->socid <= 0) {
  92. $langs->load('errors');
  93. dol_htmloutput_errors($langs->trans("ErrorModuleSetupNotComplete", "TakePos"), null, 1);
  94. } else {
  95. $placeid = $invoice->create($user);
  96. if ($placeid < 0) {
  97. dol_htmloutput_errors($invoice->error, $invoice->errors, 1);
  98. }
  99. $sql = "UPDATE ".MAIN_DB_PREFIX."facture set ref='(PROV-POS".$_SESSION["takeposterminal"]."-".$place.")' where rowid=".$placeid;
  100. $db->query($sql);
  101. }
  102. }
  103. $sql = "UPDATE ".MAIN_DB_PREFIX."facturedet set fk_facture=".$placeid." where rowid=".$line;
  104. $db->query($sql);
  105. }
  106. $invoice->fetch('', '(PROV-POS'.$_SESSION["takeposterminal"].'-SPLIT)');
  107. $invoice->update_price();
  108. $invoice->fetch('', '(PROV-POS'.$_SESSION["takeposterminal"].'-'.$place.')');
  109. $invoice->update_price();
  110. }
  111. /*
  112. * View
  113. */
  114. $invoice = new Facture($db);
  115. if ($invoiceid > 0) {
  116. $invoice->fetch($invoiceid);
  117. } else {
  118. $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."facture where ref='(PROV-POS".$_SESSION["takeposterminal"]."-".$place.")'";
  119. $resql = $db->query($sql);
  120. $obj = $db->fetch_object($resql);
  121. if ($obj) {
  122. $invoiceid = $obj->rowid;
  123. }
  124. if (!$invoiceid) {
  125. $invoiceid = 0; // Invoice does not exist yet
  126. } else {
  127. $invoice->fetch($invoiceid);
  128. }
  129. }
  130. $arrayofcss = array('/takepos/css/pos.css.php');
  131. $arrayofjs = array();
  132. $head = '';
  133. $title = '';
  134. $disablejs = 0;
  135. $disablehead = 0;
  136. top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss);
  137. // Define list of possible payments
  138. $arrayOfValidPaymentModes = array();
  139. $arrayOfValidBankAccount = array();
  140. ?>
  141. <link rel="stylesheet" href="css/pos.css.php">
  142. <?php
  143. if ($conf->global->TAKEPOS_COLOR_THEME == 1) {
  144. print '<link rel="stylesheet" href="css/colorful.css">';
  145. }
  146. ?>
  147. </head>
  148. <body class="takepossplitphp">
  149. <script>
  150. function Split(selectedline, split) {
  151. $.ajax({
  152. url: "split.php?action=split&line="+selectedline+"&split="+split+"&place=<?php echo $place;?>",
  153. context: document.body
  154. }).done(function() {
  155. $("#currentplace").load("invoice.php?place="+parent.place+"&invoiceid="+parent.invoiceid, function() {
  156. $('#currentplace').find('.posinvoiceline').click(function(){
  157. Split(this.id, 1);
  158. });
  159. });
  160. $("#splitplace").load("invoice.php?place=SPLIT", function() {
  161. $('#splitplace').find('.posinvoiceline').click(function(){
  162. Split(this.id, 0);
  163. });
  164. });
  165. });
  166. }
  167. $( document ).ready(function() {
  168. if (parent.place=='SPLIT') {
  169. parent.place=0;
  170. parent.invoiceid=0;
  171. parent.Refresh();
  172. }
  173. $("#currentplace").load("invoice.php?place="+parent.place+"&invoiceid="+parent.invoiceid, function() {
  174. $('#currentplace').find('.posinvoiceline')
  175. .click(function(){
  176. Split(this.id, 1);
  177. });
  178. });
  179. $("#splitplace").load("invoice.php?place=SPLIT", function() {
  180. $('#splitplace').find('.posinvoiceline').click(function(){
  181. Split(this.id, 0);
  182. });
  183. });
  184. $("#headersplit1").html("<?php echo $langs->trans("Place");?> "+parent.place);
  185. $("#headersplit2").html("<?php echo $langs->trans("SplitSale");?>");
  186. });
  187. </script>
  188. <div class="headersplit">
  189. <a href="#" onclick="top.location.href='index.php?place='+parent.place"><div class="headercontent" id="headersplit1"></div></a>
  190. </div>
  191. <div class="rowsplit">
  192. <div class="splitsale" id="currentplace"></div>
  193. </div>
  194. <div class="headersplit">
  195. <a href="#" onclick="top.location.href='index.php?place=SPLIT'"><div class="headercontent" id="headersplit2"></div></a>
  196. </div>
  197. <div class="rowsplit">
  198. <div class="splitsale" id="splitplace"></div>
  199. </div>
  200. </body>
  201. </html>