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