dolibarr 24.0.0-beta
split.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2021 Andreu Bisquerra <jove@bisquerra.com>
3 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
4 * Copyright (C) 2025 MDW <mdeweerd@users.noreply.github.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
26//if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER', '1'); // Not disabled cause need to load personalized language
27//if (! defined('NOREQUIREDB')) define('NOREQUIREDB', '1'); // Not disabled cause need to load personalized language
28//if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1');
29//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN', '1');
30if (!defined('NOTOKENRENEWAL')) {
31 define('NOTOKENRENEWAL', '1');
32}
33if (!defined('NOREQUIREMENU')) {
34 define('NOREQUIREMENU', '1');
35}
36if (!defined('NOREQUIREHTML')) {
37 define('NOREQUIREHTML', '1');
38}
39if (!defined('NOREQUIREAJAX')) {
40 define('NOREQUIREAJAX', '1');
41}
42
43// Load Dolibarr environment
44require '../main.inc.php'; // Load $user and permissions
45require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
52$langs->loadLangs(array("main", "bills", "cashdesk", "banks"));
53
54$action = GETPOST('action', 'aZ09');
55$place = (GETPOST('place', 'aZ09') ? GETPOST('place', 'aZ09') : 0);
56
57if (!$user->hasRight('takepos', 'run')) {
59}
60
61
62/*
63 * Actions
64 */
65
66if ($action == "split" && $user->hasRight('takepos', 'run')) {
67 $line = GETPOSTINT('line');
68 $split = GETPOSTINT('split');
69 $invoice = null;
70 $placeid = 0;
71 if ($split == 1) { // Split line
72 $invoice = new Facture($db);
73 $ret = $invoice->fetch(0, '(PROV-POS'.$_SESSION["takeposterminal"].'-SPLIT)');
74 if ($ret > 0) {
75 $placeid = $invoice->id;
76 } else {
77 $constforcompanyid = 'CASHDESK_ID_THIRDPARTY'.$_SESSION["takeposterminal"];
78 $invoice->socid = getDolGlobalInt($constforcompanyid);
79 $invoice->date = dol_now();
80 $invoice->module_source = 'takepos';
81 $invoice->pos_source = $_SESSION["takeposterminal"];
82 $invoice->entity = !empty($_SESSION["takeposinvoiceentity"]) ? $_SESSION["takeposinvoiceentity"] : $conf->entity;
83 if ($invoice->socid <= 0) {
84 $langs->load('errors');
85 dol_htmloutput_errors($langs->trans("ErrorModuleSetupNotComplete", "TakePos"), [], 1);
86 } else {
87 $placeid = $invoice->create($user);
88 if ($placeid < 0) {
89 dol_htmloutput_errors($invoice->error, $invoice->errors, 1);
90 }
91
92 $sql = "UPDATE ".MAIN_DB_PREFIX."facture SET ref='(PROV-POS".$_SESSION["takeposterminal"]."-SPLIT)'";
93 $sql .= " WHERE rowid = ".((int) $placeid);
94 $db->query($sql);
95 }
96 }
97 $sql = "UPDATE ".MAIN_DB_PREFIX."facturedet SET fk_facture = ".((int) $placeid)." WHERE rowid = ".((int) $line);
98 $db->query($sql);
99 } elseif ($split == 0) { // Unsplit line
100 $invoice = new Facture($db);
101 if ($place == "SPLIT") {
102 $place = "0";
103 } // Avoid move line to the same place (from SPLIT to SPLIT place)
104 $ret = $invoice->fetch(0, '(PROV-POS'.$_SESSION["takeposterminal"].'-'.$place.')');
105 if ($ret > 0) {
106 $placeid = $invoice->id;
107 } else {
108 $constforcompanyid = 'CASHDESK_ID_THIRDPARTY'.$_SESSION["takeposterminal"];
109 $invoice->socid = getDolGlobalInt($constforcompanyid);
110 $invoice->date = dol_now();
111 $invoice->module_source = 'takepos';
112 $invoice->pos_source = $_SESSION["takeposterminal"];
113 $invoice->entity = !empty($_SESSION["takeposinvoiceentity"]) ? $_SESSION["takeposinvoiceentity"] : $conf->entity;
114 if ($invoice->socid <= 0) {
115 $langs->load('errors');
116 dol_htmloutput_errors($langs->trans("ErrorModuleSetupNotComplete", "TakePos"), [], 1);
117 } else {
118 $placeid = $invoice->create($user);
119 if ($placeid < 0) {
120 dol_htmloutput_errors($invoice->error, $invoice->errors, 1);
121 }
122
123 $sql = "UPDATE ".MAIN_DB_PREFIX."facture SET ref='(PROV-POS".$_SESSION["takeposterminal"]."-".$place.")'";
124 $sql .= " WHERE rowid = ".((int) $placeid);
125 $db->query($sql);
126 }
127 }
128 $sql = "UPDATE ".MAIN_DB_PREFIX."facturedet set fk_facture = ".((int) $placeid)." where rowid = ".((int) $line);
129 $db->query($sql);
130 }
131 if ($invoice !== null) {
132 $invoice->fetch(0, '(PROV-POS'.$_SESSION["takeposterminal"].'-SPLIT)');
133 $invoice->update_price();
134
135 $invoice->fetch(0, '(PROV-POS'.$_SESSION["takeposterminal"].'-'.$place.')');
136 $invoice->update_price();
137 }
138}
139
140
141/*
142 * View
143 */
144
145$invoice = new Facture($db);
146if (isset($invoiceid) && $invoiceid > 0) {
147 $invoice->fetch($invoiceid);
148} else {
149 $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."facture where ref = '".$db->escape("(PROV-POS".$_SESSION["takeposterminal"]."-".$place.")")."'";
150 $resql = $db->query($sql);
151 $obj = $db->fetch_object($resql);
152 if ($obj) {
153 $invoiceid = $obj->rowid;
154 }
155 if (!isset($invoiceid)) {
156 $invoiceid = 0; // Invoice does not exist yet
157 } else {
158 $invoice->fetch($invoiceid);
159 }
160}
161
162$arrayofcss = array('/takepos/css/pos.css.php');
163if (getDolGlobalInt('TAKEPOS_COLOR_THEME') == 1) {
164 $arrayofcss[] = '/takepos/css/colorful.css';
165}
166$arrayofjs = array();
167
168$head = '';
169$title = '';
170$disablejs = 0;
171$disablehead = 0;
172
173top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss);
174
175// Define list of possible payments
176$arrayOfValidPaymentModes = array();
177$arrayOfValidBankAccount = array();
178
179?>
180<body class="takepossplitphp">
181
182<script>
183function Split(selectedline, split) {
184 $.ajax({
185 url: "split.php?action=split&token=<?php echo newToken(); ?>&line="+selectedline+"&split="+split+"&place=<?php echo $place;?>",
186 context: document.body
187 }).done(function() {
188 $("#currentplace").load("invoice.php?place="+parent.place+"&invoiceid="+parent.invoiceid, function() {
189 $('#currentplace').find('.posinvoiceline').click(function(){
190 Split(this.id, 1);
191 });
192 });
193 $("#splitplace").load("invoice.php?place=SPLIT", function() {
194 $('#splitplace').find('.posinvoiceline').click(function(){
195 Split(this.id, 0);
196 });
197 });
198 });
199}
200
201$( document ).ready(function() {
202 if (parent.place=='SPLIT') {
203 parent.place=0;
204 parent.invoiceid=0;
205 parent.Refresh();
206 }
207 $("#currentplace").load("invoice.php?place="+parent.place+"&invoiceid="+parent.invoiceid, function() {
208 $('#currentplace').find('.posinvoiceline')
209 .click(function(){
210 Split(this.id, 1);
211 });
212 });
213
214 $("#splitplace").load("invoice.php?place=SPLIT", function() {
215 $('#splitplace').find('.posinvoiceline').click(function(){
216 Split(this.id, 0);
217 });
218 });
219
220
221
222 $("#headersplit1").html("<?php echo $langs->trans("Place");?> "+parent.place);
223 $("#headersplit2").html("<?php echo $langs->trans("SplitSale");?>");
224
225});
226</script>
227
228<div class="headersplit">
229 <a href="#" onclick="top.location.href='index.php?place='+parent.place"><div class="headercontent" id="headersplit1"></div></a>
230</div>
231
232<div class="rowsplit">
233 <div class="splitsale" id="currentplace"></div>
234</div>
235
236<div class="headersplit">
237 <a href="#" onclick="top.location.href='index.php?place=SPLIT'"><div class="headercontent" id="headersplit2"></div></a>
238</div>
239
240<div class="rowsplit">
241 <div class="splitsale" id="splitplace"></div>
242</div>
243
244</body>
245</html>
Class to manage invoices.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
dol_now($mode='gmt')
Return date for now.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
getDolGlobalInt($key, $default=0)
Return a 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 formatted error messages to output (Used to show messages on html output).
top_htmlhead($head, $title='', $disablejs=0, $disablehead=0, $arrayofjs=array(), $arrayofcss=array(), $disableforlogin=0, $disablenofollow=0, $disablenoindex=0)
Output html header of a page.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.