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