dolibarr 19.0.3
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');
28if (!defined('NOTOKENRENEWAL')) {
29 define('NOTOKENRENEWAL', '1');
30}
31if (!defined('NOREQUIREMENU')) {
32 define('NOREQUIREMENU', '1');
33}
34if (!defined('NOREQUIREHTML')) {
35 define('NOREQUIREHTML', '1');
36}
37if (!defined('NOREQUIREAJAX')) {
38 define('NOREQUIREAJAX', '1');
39}
40
41// Load Dolibarr environment
42require '../main.inc.php'; // Load $user and permissions
43require_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
50if (!$user->hasRight('takepos', 'run')) {
52}
53
54
55/*
56 * Actions
57 */
58
59if ($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 =getDolGlobalInt($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") {
91 $place="0";
92 } // Avoid move line to the same place (from SPLIT to SPLIT place)
93 $ret = $invoice->fetch('', '(PROV-POS'.$_SESSION["takeposterminal"].'-'.$place.')');
94 if ($ret > 0) {
95 $placeid = $invoice->id;
96 } else {
97 $constforcompanyid = 'CASHDESK_ID_THIRDPARTY'.$_SESSION["takeposterminal"];
98 $invoice->socid = getDolGlobalInt($constforcompanyid);
99 $invoice->date = dol_now();
100 $invoice->module_source = 'takepos';
101 $invoice->pos_source = $_SESSION["takeposterminal"];
102 $invoice->entity = !empty($_SESSION["takeposinvoiceentity"]) ? $_SESSION["takeposinvoiceentity"] : $conf->entity;
103 if ($invoice->socid <= 0) {
104 $langs->load('errors');
105 dol_htmloutput_errors($langs->trans("ErrorModuleSetupNotComplete", "TakePos"), null, 1);
106 } else {
107 $placeid = $invoice->create($user);
108 if ($placeid < 0) {
109 dol_htmloutput_errors($invoice->error, $invoice->errors, 1);
110 }
111 $sql = "UPDATE ".MAIN_DB_PREFIX."facture set ref='(PROV-POS".$_SESSION["takeposterminal"]."-".$place.")' where rowid=".$placeid;
112 $db->query($sql);
113 }
114 }
115 $sql = "UPDATE ".MAIN_DB_PREFIX."facturedet set fk_facture=".$placeid." where rowid=".$line;
116 $db->query($sql);
117 }
118 $invoice->fetch('', '(PROV-POS'.$_SESSION["takeposterminal"].'-SPLIT)');
119 $invoice->update_price();
120 $invoice->fetch('', '(PROV-POS'.$_SESSION["takeposterminal"].'-'.$place.')');
121 $invoice->update_price();
122}
123
124
125/*
126 * View
127 */
128
129$invoice = new Facture($db);
130if (isset($invoiceid) && $invoiceid > 0) {
131 $invoice->fetch($invoiceid);
132} else {
133 $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."facture where ref='(PROV-POS".$_SESSION["takeposterminal"]."-".$place.")'";
134 $resql = $db->query($sql);
135 $obj = $db->fetch_object($resql);
136 if ($obj) {
137 $invoiceid = $obj->rowid;
138 }
139 if (!isset($invoiceid)) {
140 $invoiceid = 0; // Invoice does not exist yet
141 } else {
142 $invoice->fetch($invoiceid);
143 }
144}
145
146$arrayofcss = array('/takepos/css/pos.css.php');
147if (getDolGlobalInt('TAKEPOS_COLOR_THEME') == 1) {
148 $arrayofcss[] = '/takepos/css/colorful.css';
149}
150$arrayofjs = array();
151
152$head = '';
153$title = '';
154$disablejs = 0;
155$disablehead = 0;
156
157top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss);
158
159// Define list of possible payments
160$arrayOfValidPaymentModes = array();
161$arrayOfValidBankAccount = array();
162
163?>
164<body class="takepossplitphp">
165
166<script>
167function Split(selectedline, split) {
168 $.ajax({
169 url: "split.php?action=split&token=<?php echo newToken(); ?>&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>
Class to manage invoices.
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 formated 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)
Ouput 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.