dolibarr  16.0.1
split.php
Go to the documentation of this file.
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 
24 //if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER', '1'); // Not disabled cause need to load personalized language
25 //if (! defined('NOREQUIREDB')) define('NOREQUIREDB', '1'); // Not disabled cause need to load personalized language
26 //if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1');
27 //if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN', '1');
28 if (!defined('NOCSRFCHECK')) {
29  define('NOCSRFCHECK', '1');
30 }
31 if (!defined('NOTOKENRENEWAL')) {
32  define('NOTOKENRENEWAL', '1');
33 }
34 if (!defined('NOREQUIREMENU')) {
35  define('NOREQUIREMENU', '1');
36 }
37 if (!defined('NOREQUIREHTML')) {
38  define('NOREQUIREHTML', '1');
39 }
40 if (!defined('NOREQUIREAJAX')) {
41  define('NOREQUIREAJAX', '1');
42 }
43 
44 require '../main.inc.php'; // Load $user and permissions
45 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
46 
47 $langs->loadLangs(array("main", "bills", "cashdesk", "banks"));
48 
49 $action = GETPOST('action', 'aZ09');
50 $place = (GETPOST('place', 'aZ09') ? GETPOST('place', 'aZ09') : 0);
51 
52 if (empty($user->rights->takepos->run)) {
54 }
55 
56 if ($action=="split") {
57  $line = GETPOST('line', 'int');
58  $split = GETPOST('split', 'int');
59  if ($split==1) { // Split line
60  $invoice = new Facture($db);
61  $ret = $invoice->fetch('', '(PROV-POS'.$_SESSION["takeposterminal"].'-SPLIT)');
62  if ($ret > 0) {
63  $placeid = $invoice->id;
64  } else {
65  $constforcompanyid = 'CASHDESK_ID_THIRDPARTY'.$_SESSION["takeposterminal"];
66  $invoice->socid = $conf->global->$constforcompanyid;
67  $invoice->date = dol_now();
68  $invoice->module_source = 'takepos';
69  $invoice->pos_source = $_SESSION["takeposterminal"];
70  $invoice->entity = !empty($_SESSION["takeposinvoiceentity"]) ? $_SESSION["takeposinvoiceentity"] : $conf->entity;
71  if ($invoice->socid <= 0) {
72  $langs->load('errors');
73  dol_htmloutput_errors($langs->trans("ErrorModuleSetupNotComplete", "TakePos"), null, 1);
74  } else {
75  $placeid = $invoice->create($user);
76  if ($placeid < 0) {
77  dol_htmloutput_errors($invoice->error, $invoice->errors, 1);
78  }
79  $sql = "UPDATE ".MAIN_DB_PREFIX."facture set ref='(PROV-POS".$_SESSION["takeposterminal"]."-SPLIT)' where rowid=".$placeid;
80  $db->query($sql);
81  }
82  }
83  $sql = "UPDATE ".MAIN_DB_PREFIX."facturedet set fk_facture=".$placeid." where rowid=".$line;
84  $db->query($sql);
85  } elseif ($split==0) { // Unsplit line
86  $invoice = new Facture($db);
87  if ($place=="SPLIT") $place="0"; // Avoid move line to the same place (from SPLIT to SPLIT place)
88  $ret = $invoice->fetch('', '(PROV-POS'.$_SESSION["takeposterminal"].'-'.$place.')');
89  if ($ret > 0) {
90  $placeid = $invoice->id;
91  } else {
92  $constforcompanyid = 'CASHDESK_ID_THIRDPARTY'.$_SESSION["takeposterminal"];
93  $invoice->socid = $conf->global->$constforcompanyid;
94  $invoice->date = dol_now();
95  $invoice->module_source = 'takepos';
96  $invoice->pos_source = $_SESSION["takeposterminal"];
97  $invoice->entity = !empty($_SESSION["takeposinvoiceentity"]) ? $_SESSION["takeposinvoiceentity"] : $conf->entity;
98  if ($invoice->socid <= 0) {
99  $langs->load('errors');
100  dol_htmloutput_errors($langs->trans("ErrorModuleSetupNotComplete", "TakePos"), null, 1);
101  } else {
102  $placeid = $invoice->create($user);
103  if ($placeid < 0) {
104  dol_htmloutput_errors($invoice->error, $invoice->errors, 1);
105  }
106  $sql = "UPDATE ".MAIN_DB_PREFIX."facture set ref='(PROV-POS".$_SESSION["takeposterminal"]."-".$place.")' where rowid=".$placeid;
107  $db->query($sql);
108  }
109  }
110  $sql = "UPDATE ".MAIN_DB_PREFIX."facturedet set fk_facture=".$placeid." where rowid=".$line;
111  $db->query($sql);
112  }
113  $invoice->fetch('', '(PROV-POS'.$_SESSION["takeposterminal"].'-SPLIT)');
114  $invoice->update_price();
115  $invoice->fetch('', '(PROV-POS'.$_SESSION["takeposterminal"].'-'.$place.')');
116  $invoice->update_price();
117 }
118 
119 
120 /*
121  * View
122  */
123 
124 $invoice = new Facture($db);
125 if ($invoiceid > 0) {
126  $invoice->fetch($invoiceid);
127 } else {
128  $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."facture where ref='(PROV-POS".$_SESSION["takeposterminal"]."-".$place.")'";
129  $resql = $db->query($sql);
130  $obj = $db->fetch_object($resql);
131  if ($obj) {
132  $invoiceid = $obj->rowid;
133  }
134  if (!$invoiceid) {
135  $invoiceid = 0; // Invoice does not exist yet
136  } else {
137  $invoice->fetch($invoiceid);
138  }
139 }
140 
141 $arrayofcss = array('/takepos/css/pos.css.php');
142 $arrayofjs = array();
143 
144 $head = '';
145 $title = '';
146 $disablejs = 0;
147 $disablehead = 0;
148 
149 top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss);
150 
151 // Define list of possible payments
152 $arrayOfValidPaymentModes = array();
153 $arrayOfValidBankAccount = array();
154 
155 
156 ?>
157 <link rel="stylesheet" href="css/pos.css.php">
158 <?php
159 if ($conf->global->TAKEPOS_COLOR_THEME == 1) {
160  print '<link rel="stylesheet" href="css/colorful.css">';
161 }
162 ?>
163 </head>
164 <body class="takepossplitphp">
165 
166 <script>
167 function Split(selectedline, split) {
168  $.ajax({
169  url: "split.php?action=split&line="+selectedline+"&split="+split+"&place=<?php echo $place;?>",
170  context: document.body
171  }).done(function() {
172  $("#currentplace").load("invoice.php?place="+parent.place+"&invoiceid="+parent.invoiceid, function() {
173  $('#currentplace').find('.posinvoiceline').click(function(){
174  Split(this.id, 1);
175  });
176  });
177  $("#splitplace").load("invoice.php?place=SPLIT", function() {
178  $('#splitplace').find('.posinvoiceline').click(function(){
179  Split(this.id, 0);
180  });
181  });
182  });
183 }
184 
185 $( document ).ready(function() {
186  if (parent.place=='SPLIT') {
187  parent.place=0;
188  parent.invoiceid=0;
189  parent.Refresh();
190  }
191  $("#currentplace").load("invoice.php?place="+parent.place+"&invoiceid="+parent.invoiceid, function() {
192  $('#currentplace').find('.posinvoiceline')
193  .click(function(){
194  Split(this.id, 1);
195  });
196  });
197 
198  $("#splitplace").load("invoice.php?place=SPLIT", function() {
199  $('#splitplace').find('.posinvoiceline').click(function(){
200  Split(this.id, 0);
201  });
202  });
203 
204 
205 
206  $("#headersplit1").html("<?php echo $langs->trans("Place");?> "+parent.place);
207  $("#headersplit2").html("<?php echo $langs->trans("SplitSale");?>");
208 
209 });
210 </script>
211 
212 <div class="headersplit">
213  <a href="#" onclick="top.location.href='index.php?place='+parent.place"><div class="headercontent" id="headersplit1"></div></a>
214 </div>
215 
216 <div class="rowsplit">
217  <div class="splitsale" id="currentplace"></div>
218 </div>
219 
220 <div class="headersplit">
221  <a href="#" onclick="top.location.href='index.php?place=SPLIT'"><div class="headercontent" id="headersplit2"></div></a>
222 </div>
223 
224 <div class="rowsplit">
225  <div class="splitsale" id="splitplace"></div>
226 </div>
227 
228 </body>
229 </html>
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_now($mode= 'auto')
Return date for now.
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
if(isModEnabled('facture')&&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur')&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)&&$user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice')&&$user->rights->supplier_invoice->lire)) if(isModEnabled('don')&&!empty($user->rights->don->lire)) if(isModEnabled('tax')&&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture')&&isModEnabled('commande')&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
top_htmlhead($head, $title= '', $disablejs=0, $disablehead=0, $arrayofjs= '', $arrayofcss= '', $disableforlogin=0, $disablenofollow=0, $disablenoindex=0)
Ouput html header of a page.
Definition: main.inc.php:1478
Class to manage invoices.
dol_htmloutput_errors($mesgstring= '', $mesgarray=array(), $keepembedded=0)
Print formated error messages to output (Used to show messages on html output).