dolibarr 21.0.0-alpha
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';
45
46$langs->loadLangs(array("main", "bills", "cashdesk", "banks"));
47
48$action = GETPOST('action', 'aZ09');
49$place = (GETPOST('place', 'aZ09') ? GETPOST('place', 'aZ09') : 0);
50
51if (!$user->hasRight('takepos', 'run')) {
53}
54
55
56/*
57 * Actions
58 */
59
60if ($action=="split" && $user->hasRight('takepos', 'run')) {
61 $line = GETPOSTINT('line');
62 $split = GETPOSTINT('split');
63 if ($split==1) { // Split line
64 $invoice = new Facture($db);
65 $ret = $invoice->fetch('', '(PROV-POS'.$_SESSION["takeposterminal"].'-SPLIT)');
66 if ($ret > 0) {
67 $placeid = $invoice->id;
68 } else {
69 $constforcompanyid = 'CASHDESK_ID_THIRDPARTY'.$_SESSION["takeposterminal"];
70 $invoice->socid =getDolGlobalInt($constforcompanyid);
71 $invoice->date = dol_now();
72 $invoice->module_source = 'takepos';
73 $invoice->pos_source = $_SESSION["takeposterminal"];
74 $invoice->entity = !empty($_SESSION["takeposinvoiceentity"]) ? $_SESSION["takeposinvoiceentity"] : $conf->entity;
75 if ($invoice->socid <= 0) {
76 $langs->load('errors');
77 dol_htmloutput_errors($langs->trans("ErrorModuleSetupNotComplete", "TakePos"), [], 1);
78 } else {
79 $placeid = $invoice->create($user);
80 if ($placeid < 0) {
81 dol_htmloutput_errors($invoice->error, $invoice->errors, 1);
82 }
83 $sql = "UPDATE ".MAIN_DB_PREFIX."facture set ref='(PROV-POS".$_SESSION["takeposterminal"]."-SPLIT)' where rowid=".$placeid;
84 $db->query($sql);
85 }
86 }
87 $sql = "UPDATE ".MAIN_DB_PREFIX."facturedet set fk_facture=".$placeid." where rowid=".$line;
88 $db->query($sql);
89 } elseif ($split==0) { // Unsplit line
90 $invoice = new Facture($db);
91 if ($place=="SPLIT") {
92 $place="0";
93 } // Avoid move line to the same place (from SPLIT to SPLIT place)
94 $ret = $invoice->fetch('', '(PROV-POS'.$_SESSION["takeposterminal"].'-'.$place.')');
95 if ($ret > 0) {
96 $placeid = $invoice->id;
97 } else {
98 $constforcompanyid = 'CASHDESK_ID_THIRDPARTY'.$_SESSION["takeposterminal"];
99 $invoice->socid = getDolGlobalInt($constforcompanyid);
100 $invoice->date = dol_now();
101 $invoice->module_source = 'takepos';
102 $invoice->pos_source = $_SESSION["takeposterminal"];
103 $invoice->entity = !empty($_SESSION["takeposinvoiceentity"]) ? $_SESSION["takeposinvoiceentity"] : $conf->entity;
104 if ($invoice->socid <= 0) {
105 $langs->load('errors');
106 dol_htmloutput_errors($langs->trans("ErrorModuleSetupNotComplete", "TakePos"), [], 1);
107 } else {
108 $placeid = $invoice->create($user);
109 if ($placeid < 0) {
110 dol_htmloutput_errors($invoice->error, $invoice->errors, 1);
111 }
112 $sql = "UPDATE ".MAIN_DB_PREFIX."facture set ref='(PROV-POS".$_SESSION["takeposterminal"]."-".$place.")' where rowid=".$placeid;
113 $db->query($sql);
114 }
115 }
116 $sql = "UPDATE ".MAIN_DB_PREFIX."facturedet set fk_facture=".$placeid." where rowid=".$line;
117 $db->query($sql);
118 }
119 $invoice->fetch('', '(PROV-POS'.$_SESSION["takeposterminal"].'-SPLIT)');
120 $invoice->update_price();
121 $invoice->fetch('', '(PROV-POS'.$_SESSION["takeposterminal"].'-'.$place.')');
122 $invoice->update_price();
123}
124
125
126/*
127 * View
128 */
129
130$invoice = new Facture($db);
131if (isset($invoiceid) && $invoiceid > 0) {
132 $invoice->fetch($invoiceid);
133} else {
134 $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."facture where ref='(PROV-POS".$_SESSION["takeposterminal"]."-".$place.")'";
135 $resql = $db->query($sql);
136 $obj = $db->fetch_object($resql);
137 if ($obj) {
138 $invoiceid = $obj->rowid;
139 }
140 if (!isset($invoiceid)) {
141 $invoiceid = 0; // Invoice does not exist yet
142 } else {
143 $invoice->fetch($invoiceid);
144 }
145}
146
147$arrayofcss = array('/takepos/css/pos.css.php');
148if (getDolGlobalInt('TAKEPOS_COLOR_THEME') == 1) {
149 $arrayofcss[] = '/takepos/css/colorful.css';
150}
151$arrayofjs = array();
152
153$head = '';
154$title = '';
155$disablejs = 0;
156$disablehead = 0;
157
158top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss);
159
160// Define list of possible payments
161$arrayOfValidPaymentModes = array();
162$arrayOfValidBankAccount = array();
163
164?>
165<body class="takepossplitphp">
166
167<script>
168function Split(selectedline, split) {
169 $.ajax({
170 url: "split.php?action=split&token=<?php echo newToken(); ?>&line="+selectedline+"&split="+split+"&place=<?php echo $place;?>",
171 context: document.body
172 }).done(function() {
173 $("#currentplace").load("invoice.php?place="+parent.place+"&invoiceid="+parent.invoiceid, function() {
174 $('#currentplace').find('.posinvoiceline').click(function(){
175 Split(this.id, 1);
176 });
177 });
178 $("#splitplace").load("invoice.php?place=SPLIT", function() {
179 $('#splitplace').find('.posinvoiceline').click(function(){
180 Split(this.id, 0);
181 });
182 });
183 });
184}
185
186$( document ).ready(function() {
187 if (parent.place=='SPLIT') {
188 parent.place=0;
189 parent.invoiceid=0;
190 parent.Refresh();
191 }
192 $("#currentplace").load("invoice.php?place="+parent.place+"&invoiceid="+parent.invoiceid, function() {
193 $('#currentplace').find('.posinvoiceline')
194 .click(function(){
195 Split(this.id, 1);
196 });
197 });
198
199 $("#splitplace").load("invoice.php?place=SPLIT", function() {
200 $('#splitplace').find('.posinvoiceline').click(function(){
201 Split(this.id, 0);
202 });
203 });
204
205
206
207 $("#headersplit1").html("<?php echo $langs->trans("Place");?> "+parent.place);
208 $("#headersplit2").html("<?php echo $langs->trans("SplitSale");?>");
209
210});
211</script>
212
213<div class="headersplit">
214 <a href="#" onclick="top.location.href='index.php?place='+parent.place"><div class="headercontent" id="headersplit1"></div></a>
215</div>
216
217<div class="rowsplit">
218 <div class="splitsale" id="currentplace"></div>
219</div>
220
221<div class="headersplit">
222 <a href="#" onclick="top.location.href='index.php?place=SPLIT'"><div class="headercontent" id="headersplit2"></div></a>
223</div>
224
225<div class="rowsplit">
226 <div class="splitsale" id="splitplace"></div>
227</div>
228
229</body>
230</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.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.