noalyss Version-9
action_document_type_mtable.class.php
Go to the documentation of this file.
1<?php
2
3/*
4 * This file is part of NOALYSS.
5 *
6 * PhpCompta 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 2 of the License, or
9 * (at your option) any later version.
10 *
11 * PhpCompta 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 PhpCompta; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20// Copyright (2002-2019) Author Dany De Bontridder <danydb@noalyss.eu>
21
22/* @file
23 * @brief display and allow to update , add , delete document_type for the follow up
24 *
25 */
26require_once NOALYSS_INCLUDE."/database/document_type_sql.class.php";
27
28/**
29 * @class Action_Document_Type_MTable
30 * @brief display , modify and add document_type for follow up
31 * @see include/ajax/ajax_cfgaction.php
32 * @see include/cfg_action.inc.php
33 */
35{
36
37 private $other; //!< Other value
38
40 {
41 parent::__construct($doc_type);
42 $this->set_order(["dt_id", "dt_prefix", "dt_value",]);
43 $this->set_property_updatable("dt_id", false);
44 $this->set_property_visible("dt_id", false);
45 $this->set_property_updatable("dt_value", true);
46 $this->set_property_updatable("dt_prefix", true);
47 $this->set_col_label("dt_value", _("Nom"));
48 $this->set_col_label("dt_prefix", _("Préfixe document"));
49 $this->other=array();
50 }
51
52 /**
53 *
54 @code
55 table "public.document_type"
56 ctl_id "dtr"
57 gDossier "74"
58 op "cfgaction"
59 p_id "28"
60 action "save"
61 ctl "tbl5f785d403b123"
62 dt_prefix "ABO.HEB"
63 dt_value "Abonnements+PhpCompta"
64 seq "0"
65 det_op "1"
66 det_contact_mul "1"
67 update "OK"
68 @endcode
69 *
70 *
71 *
72 */
73 public function from_request()
74 {
75 $http=new HttpInput();
76 $this->table->dt_value=$http->request('dt_value');
77 $this->table->dt_prefix=$http->request('dt_prefix');
78 $this->other['detail_operation']=$http->request("detail_operation", "string", 0);
79 $this->other['contact_multiple']=$http->request("det_contact_mul", "string", 0);
80 $this->other['make_invoice']=$http->request("make_invoice", "string", 0);
81 $this->other['make_feenote']=$http->request("make_feenote", "string", 0);
82 $this->other['followup_comment']=$http->request("followup_comment", "string", 0);
83 $this->other['editable_description']=$http->request("editable_description", "string", 0);
84 $this->other['enable_followup']=$http->request("enable_followup", "string", 0);
85 $this->other['seq']=$http->request("seq", "string", 0);
86 $this->other['select_option_operation']=$http->request("select_option_operation", "string", null);
87 $this->other['select_comment']=$http->request("select_comment", "string", null);
88 $this->other['videoconf_server']=$http->request('videoconf_server',"string",0);
89 $this->other['videoconf_server_url']=$http->request('videoconf_server_url',"string",DEFAULT_SERVER_VIDEO_CONF);
90 $this->other["cor_id"]=$http->request("cor_id","array",[]);
91 $nb_corid=count($this->other["cor_id"]);
92 $http->set_empty(0);
93 for ($i=0;$i<$nb_corid;$i++) {
94 $this->other["contact_option$i"]=$http->request("contact_option".$i,"number",0);
95 }
96
97 }
98
99 /**
100 *
101 */
102 public function check()
103 {
104 $table=$this->get_table();
105 $error=0;
106 if (empty(trim($table->dt_value)))
107 {
108 $this->set_error("dt_value", _("Nom ne peut être vide"));
109 $error++;
110 }
111 if (empty(trim($table->dt_prefix)))
112 {
113 $this->set_error("dt_prefix", _("Préfixe ne peut être vide"));
114 $error++;
115 }
116 // Check doublon
117 if ($table->cn->get_value('select count(*) from document_type where upper(dt_value)=upper($1) and dt_id <> $2',
118 [$table->dt_value, $table->dt_id])>0)
119 {
120 $this->set_error("dt_value", _("Doublon, ce nom existe déjà "));
121 $error++;
122 }
123 // Check doublon
124 if ($table->cn->get_value('select count(*) from document_type where upper(dt_prefix)=upper($1) and dt_id <> $2',
125 [$table->dt_prefix, $table->dt_id])>0)
126 {
127 $this->set_error("dt_value", _("Doublon, ce préfixe existe déjà "));
128 $error++;
129 }
130 if ($error>0)
131 {
132 return false;
133 }
134 return true;
135 }
136
137 /**
138 *
139 * @throws Exception
140 */
141 function delete()
142 {
143 $table=$this->get_table();
144 try
145 {
146 // remove the cat if no action
147 $count_md=$table->cn->get_value('select count(*) from document_modele where md_type=$1',
148 array($table->dt_id));
149 $count_a=$table->cn->get_value('select count(*) from action_gestion where ag_type=$1', array($table->dt_id));
150
151 if ($count_md!=0||$count_a!=0)
152 {
153 throw new Exception(_('Des actions dépendent de cette catégorie'), 1300);
154 }
155 $table->delete();
156 }
157 catch (Exception $exc)
158 {
159 if ($exc->getCode()!=1300)
160 {
161 record_log("ADTM01".$exc->getTrace());
162 }
163 throw new Exception($exc->getMessage());
164 }
165 }
166
167 /**
168 * @brief display the box for adding, the name for p_id , are in the form
169 */
170 function input()
171 {
172 parent::input();
173
174
175
176 // Detail option contact
177 $table=$this->get_table();
178 $cn=$table->cn;
179 try
180 {
181 $cn->start();
182 if ( $table->dt_id == -1 ){
183 $aOption=$cn->get_array("select cor_id,cor_label,cor_type,-1 document_type_id,0 jdoc_enable
184 from
185 contact_option_ref cor
186 order by cor_label");
187
188 } else {
189 // insert new contact options
190 $cn->exec_sql("insert into jnt_document_option_contact (jdoc_enable,document_type_id,
191 contact_option_ref_id)
192 select 0 , $1, cor_id
193 from contact_option_ref
194 where
195 cor_id not in (select cor_id from
196 jnt_document_option_contact a
197 where a.document_type_id=$1)", [$table->dt_id]);
198
199 // Select all
200 $aOption=$cn->get_array("select cor_id,cor_label,cor_type,document_type_id ,coalesce(jdoc_enable,0) jdoc_enable
201 from
202 contact_option_ref cor
203 left join jnt_document_option_contact jdoc on (cor_id=contact_option_ref_id)
204 where
205 document_type_id is null
206 or document_type_id = $1
207 order by cor_label", [$this->table->dt_id]);
208
209 // delete unused option by the action_person_
210 $cn->exec_sql("delete from action_person_option where ap_id in (select apo.ap_id
211 from action_person a
212 left join action_person_option apo ON (a.ap_id=apo.action_person_id)
213 left join contact_option_ref cor on (apo.contact_option_ref_id=cor.cor_id)
214 join action_gestion ag on (a.ag_id=ag.ag_id)
215 where
216 cor.cor_id not in (select jdoc2.contact_option_ref_id
217 from jnt_document_option_contact jdoc2
218 where jdoc2.document_type_id =$1
219 and jdoc2.jdoc_enable =1));
220 ",[$table->dt_id]);
221 }
222
223 // Detail option
224 require NOALYSS_TEMPLATE."/action_document_type_mtable_input.php";
225 $cn->commit();
226 }
227 catch (Exception $exc)
228 {
229 $cn->rollback();
230
231 echo $exc->getMessage();
232 error_log($exc->getTraceAsString());
233 }
234
235 }
236
237 /**
238 * save
239 */
240 function save()
241 {
242 parent::save();
244 $object_sql=$this->get_table();
245 // restart sequence
246 if ($this->other['seq']!=0)
247 {
248 $doc_type=new Document_type($cn, $object_sql->dt_id);
249 $doc_type->set_number($this->other['seq']);
250 }
251 // Save detail operation
252 $cn->exec_sql("insert into document_option (do_code,document_type_id,do_enable,do_option) values ($1,$2,$3,$4)
253 on conflict on constraint document_option_un
254 do update set do_enable=$3,do_option=$4",
255 [ "detail_operation",
256 $object_sql->dt_id,
257 $this->other['detail_operation'],
258 $this->other['select_option_operation']
259 ]);
260
261 // Save contact_multiple
262 $cn->exec_sql("insert into document_option (do_code,document_type_id,do_enable) values ($1,$2,$3)
263 on conflict on constraint document_option_un
264 do update set do_enable=$3 ", ["contact_multiple", $object_sql->dt_id, $this->other['contact_multiple']]);
265
266 // Save editable description
267 $cn->exec_sql("insert into document_option (do_code,document_type_id,do_enable) values ($1,$2,$3)
268 on conflict on constraint document_option_un
269 do update set do_enable=$3 ", ["editable_description", $object_sql->dt_id
270 , $this->other['editable_description']]);
271
272 // Save make invoice
273 $cn->exec_sql("insert into document_option (do_code,document_type_id,do_enable) values ($1,$2,$3)
274 on conflict on constraint document_option_un
275 do update set do_enable=$3 ", ["make_invoice", $object_sql->dt_id, $this->other['make_invoice']]);
276
277 // Save make feenote
278 $cn->exec_sql("insert into document_option (do_code,document_type_id,do_enable) values ($1,$2,$3)
279 on conflict on constraint document_option_un
280 do update set do_enable=$3 ", ["make_feenote", $object_sql->dt_id, $this->other['make_feenote']]);
281
282 // Option for comments
283 $cn->exec_sql("insert into document_option (do_code,document_type_id,do_enable,do_option) values ($1,$2,$3,$4)
284 on conflict on constraint document_option_un
285 do update set do_enable=$3,do_option=$4 ",
286 [ "followup_comment",
287 $object_sql->dt_id,
288 $this->other['followup_comment'],
289 $this->other['select_comment']
290 ]);
291
292 // Save videoconf setting
293 if ( $this->other['videoconf_server'] == 1 && trim($this->other['videoconf_server_url'])=="") {
294 $this->other['videoconf_server_url']=DEFAULT_SERVER_VIDEO_CONF;
295 }
296 $cn->exec_sql("insert into document_option (do_code,document_type_id,do_enable,do_option) values ($1,$2,$3,$4)
297 on conflict on constraint document_option_un
298 do update set do_enable=$3,do_option=$4 ",
299 [ "videoconf_server",
300 $object_sql->dt_id,
301 $this->other['videoconf_server'],
302 $this->other['videoconf_server_url']
303 ]);
304
305 // Option contact to save
306 $cn->exec_sql("delete from jnt_document_option_contact where document_type_id=$1",[$object_sql->dt_id]);
307 $nb_contact_option=count($this->other["cor_id"]);
308 $aOption=$this->other["cor_id"];
309 for ( $e=0;$e<$nb_contact_option;$e++) {
310 $option_id=$aOption[$e];
311 if ( isset($this->other["contact_option".$e]) ) {
312 $cn->exec_sql("insert into jnt_document_option_contact
313 (jdoc_enable,document_type_id,contact_option_ref_id)
314 values ($1,$2,$3)",[$this->other["contact_option".$e],$object_sql->dt_id,$option_id]);
315 }
316 }
317
318
319 }
320
321}
record_log($p_message)
Record an error message into the log file of the server.
Definition: ac_common.php:1342
catch(Exception $ex) $doc_type
display , modify and add document_type for follow up
input()
display the box for adding, the name for p_id , are in the form
abstract of the table public.document_type
static connect()
manage the http input (get , post, request) and extract from an array
Purpose is to propose a librairy to display a table content and allow to update and delete row ,...
set_property_updatable($p_key, $p_value)
set a column of the data row updatable or not
set_property_visible($p_key, $p_value)
set a column of the data row visible or not
set_error($p_col, $p_message)
set the error message for a wrong input
set_col_label($p_key, $p_display)
set the name to display for a column
$all table
for($i=0;$i< $nb;$i++) $aOption