noalyss Version-9
ajax_operation_exercice.php
Go to the documentation of this file.
1<?php
2/*
3 * This file is part of NOALYSS.
4 *
5 * NOALYSS 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 2 of the License, or
8 * (at your option) any later version.
9 *
10 * NOALYSS 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 NOALYSS; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18*/
19// Copyright Author Dany De Bontridder danydb@aevalys.eu 6/01/24
20/*!
21 * \file
22 * \brief display the possible value of exercice
23 */
24global $http, $g_user;
25if ($g_user->check_module("OPCL") == 0) throw new \Exception(EXC_FORBIDDEN);
26
27//-------------------------------------------------------------------------------------------
28// Update the periode of the selected folder
29//-------------------------------------------------------------------------------------------
30if ($op == "operation_exercice+update_periode") {
31
32 try {
33 $folder_id = $http->get("folder", "number");
34 if ($g_user->check_dossier($folder_id, true) == 'X') throw new \Exception(EXC_FORBIDDEN);
35
36 } catch (\Exception $e) {
37
38 return;
39 }
40
41 $conx = new Database($folder_id);
42 $periode = $conx->make_array("select distinct p_exercice,p_exercice from parm_periode order by p_exercice desc");
43 $sExercice = new ISelect("exercice");
44 $sExercice->id = "select_exercice_id";
45 $sExercice->value = $periode;
46 echo $sExercice->input();
47 return;
48}
49//-------------------------------------------------------------------------------------------
50// Display a detail operation_exercice to modify or add id
51//-------------------------------------------------------------------------------------------
52if ($op == "operation_exercice+modify_row") {
53 try {
54 $row_id = $http->post("row_id", "number", -1);
55 $oe_id = $http->post("oe_id", "number");
56 } catch (\Exception $e) {
57 echo $e->getMessage();
58 return;
59 }
60 $operation_detail_sql = new Operation_Exercice_Detail_SQL($cn, $row_id);
61 $operation_detail_sql->oe_id = $oe_id;
62 if ($row_id == -1) $operation_detail_sql->oed_debit = 'f';
63 Operation_Exercice::input_row($operation_detail_sql);
64
65 return;
66}
67//-------------------------------------------------------------------------------------------
68// save a row
69//-------------------------------------------------------------------------------------------
70if ($op == "operation_exercice+save_row") {
71 try {
72 $row_id = $http->post("row_id", "number");
73 $oe_id = $http->post("oe_id", "number");
74 $oe_poste = $http->post("oe_poste", "text");
75 $qcode = $http->post("qcode", "text");
76 $label = $http->post("label", "text");
77 $amount = $http->post("amount", "number");
78 $debit = $http->post("debit", "text", 'f');
79 } catch (\Exception $e) {
80 echo $e->getMessage();
81 return;
82 }
83 $operation_detail_sql = new Operation_Exercice_Detail_SQL($cn, $row_id);
84
85 $operation_detail_sql->setp("oed_poste", $oe_poste)
86 ->setp("oed_qcode", $qcode)
87 ->setp("oed_label", $label)
88 ->setp("oed_amount", $amount)
89 ->setp("oe_id", $oe_id)
90 ->setp("oed_debit", $debit);
91 try {
92 $operation_detail_sql->save();
93 $data = $operation_detail_sql->to_array();
94
95 ob_start();
96 $operation_exercice = new Operation_Exercice();
97 if ($row_id == -1) {
98 $operation_exercice->display_row($data, true);
99 } else {
100
101 $operation_exercice->display_row($data, false);
102 }
103 $str = ob_get_contents();
104 ob_end_clean();
105
106 $answer = [];
107 $answer["status"] = "OK";
108 $answer['row_id'] = $operation_detail_sql->oed_id;
109 $answer['oe_id'] = $operation_detail_sql->oe_id;
110 $answer['content'] = $str;
112 } catch (\Exception $e) {
113 echo $e->getMessage();
114 return;
115 }
116}
117//-------------------------------------------------------------------------------------------
118// Compute the balance, we receive only the OED_ID , then we must find out what was the complete
119// OPERATION_EXERCICE
120//-------------------------------------------------------------------------------------------
121if ($op == "operation_exercice+display_total") {
122 try {
123 $row_id = $http->get("row_id", "number");
124 $operation_detail_sql = new Operation_Exercice_Detail_SQL($cn, $row_id);
125 if ($operation_detail_sql->getp("oe_id") == "") {
126 throw new Exception("AOE-113:not existing line");
127 }
128 $operation_exercice = new Operation_Exercice($operation_detail_sql->oe_id);
129 $operation_exercice->display_total(false);
130
131 } catch (\Exception $e) {
132 echo $e->getMessage();
133 return;
134 }
135}
136//-------------------------------------------------------------------------------------------
137//delete a row OPERATION_EXERCICE
138//-------------------------------------------------------------------------------------------
139if ($op == "operation_exercice+delete_row") {
140 try {
141 $row_id = $http->get("row_id", "number");
142 $operation_detail_sql = new Operation_Exercice_Detail_SQL($cn, $row_id);
143 $oe_id = $operation_detail_sql->oe_id;
144 $other_row = $cn->get_value("select oed_id from operation_exercice_detail where oe_id=$1 limit 1 ",
145 [$oe_id]);
146
147 $operation_detail_sql->delete();
148 echo json_response(array("status" => "OK", "row_id" => $other_row));
149 } catch (\Exception $e) {
150 echo $e->getMessage();
151 return;
152 }
153}
154//-------------------------------------------------------------------------------------------
155// Change the date
156//-------------------------------------------------------------------------------------------
157if ($op == "operation_exercice+date") {
158 try {
159 $oe_id = $http->request("oe_id", "number");
160 } catch (\Exception $e) {
161 echo $e->getMessage();
162 }
163 $input = $http->request("input");
164 $action = $http->request("ieaction", "string", "display");
165 $ajax_date = Inplace_Edit::build($input);
166 $ajax_date->add_json_param("op", "operation_exercice+date");
167 $ajax_date->add_json_param("gDossier", Dossier::id());
168 $ajax_date->add_json_param("oe_id", $oe_id);
169 $ajax_date->set_callback("ajax_misc.php");
170
171 if ($action == "display") {
172
173 echo $ajax_date->ajax_input();
174 }
175 if ($action == "ok") {
176 $value = $http->request("value");
177 $cn->exec_sql("update operation_exercice set oe_date=to_date($1,'DD.MM.YYYY') where oe_id=$2", [$value, $oe_id]);
178 $ajax_date->set_value($value);
179 echo $ajax_date->value();
180 }
181 if ($action == "cancel") {
182
183 echo $ajax_date->value();
184 }
185 return;
186}
187//-------------------------------------------------------------------------------------------
188// Change the text
189//-------------------------------------------------------------------------------------------
190if ($op == "operation_exercice+text") {
191 try {
192 $oe_id = $http->request("oe_id", "number");
193 } catch (\Exception $e) {
194 echo $e->getMessage();
195 }
196 $input = $http->request("input");
197 $action = $http->request("ieaction", "string", "display");
198 $ajax_text = Inplace_Edit::build($input);
199 $ajax_text->add_json_param("op", "operation_exercice+text");
200 $ajax_text->add_json_param("gDossier", Dossier::id());
201 $ajax_text->add_json_param("oe_id", $oe_id);
202 $ajax_text->set_callback("ajax_misc.php");
203
204 if ($action == "display") {
205
206 echo $ajax_text->ajax_input();
207 }
208 if ($action == "ok") {
209 $value = $http->request("value");
210 $cn->exec_sql("update operation_exercice set oe_text=$1 where oe_id=$2", [$value, $oe_id]);
211 $ajax_text->set_value($value);
212 echo $ajax_text->value();
213 }
214 if ($action == "cancel") {
215
216 echo $ajax_text->value();
217 }
218 return;
219}
220//-------------------------------------------------------------------------------------------
221// Check and transfer to accountancy if OK
222//-------------------------------------------------------------------------------------------
223if ($op == "operation_exercice+transfer") {
224 try {
225 $operation_exercice_id = $http->request("oe_id", "number");
226 $ledger_id = $http->request('p_jrn', "number");
227 if ($g_user->check_jrn($ledger_id) == "X") throw new \Exception (EXC_FORBIDDEN);
228 } catch (\Exception $e) {
229 echo $e->getMessage();
230 return;
231 }
232 // first , check that everything is ok
233 $operation_exercice = new Operation_Exercice($operation_exercice_id);
234
235 global $oe_result, $oe_status;
236 $answer = array();
237 $operation_exercice->submit_transfer($ledger_id);
238 $answer['status'] = $oe_status;
239 if ($answer['status'] == 'NOK') {
240 $answer['content'] = span($oe_result, 'class=warning');
241 }else {
242 $answer['content'] = span($oe_result);
243
244 }
246 return;
247}
span($p_string, $p_extra='')
Definition: ac_common.php:43
$action
$op
Definition: ajax_admin.php:38
$input
$answer
global $http
global $g_user
$ledger_id
contains the class for connecting to Noalyss
static id()
return the 'gDossier' value after a check
Html Input , create a tag <SELECT> ... </SELECT> if readonly == true then display the label correspon...
static build($p_serialize)
build a Inplace_Edit object from a serialized string (ajax json parameter = input)
static input_row(Operation_Exercice_Detail_SQL $operation_detail_sql)
input one row of operation_exercice
const EXC_FORBIDDEN
Definition: constant.php:347
$str
Definition: fiche.inc.php:91
json_response($p_answer)
Send header and json object.