noalyss Version-9
acc_plan_mtable.class.php
Go to the documentation of this file.
1<?php
2
3/*
4 * Copyright (C) 2017 Dany De Bontridder <dany@alchimerys.be>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program 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 this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20
21
22/***
23 * @file
24 * @brief class Acc_Plan_MTabme
25 * @see Acc_Plan_MTabme
26 *
27 */
28require_once NOALYSS_INCLUDE.'/database/acc_plan_sql.class.php';
29/**
30 * @brief this instance extends Manage_Table_SQL and aims to manage
31 * the Table tmp_pcmn thanks a web interface (add , delete, display...)
32 *
33 * @see Acc_Plan_SQL
34 */
36{
37 function __construct(Acc_Plan_SQL $p_table)
38 {
39 $this->table = $p_table;
40 parent::__construct($p_table);
41 //--------------------------------------------------------------
42 //Set the table header
43 //--------------------------------------------------------------
44 $this->set_col_label("pcm_val", _("Poste Comptable"));
45 $this->set_col_label("pcm_type", _("Type"));
46 $this->set_col_label("pcm_lib", _("Libellé"));
47 $this->set_col_label("parent_accounting", _("Dépend"));
48 $this->set_col_label("fiche_qcode", _("Fiche"));
49 $this->set_col_label("pcm_direct_use", _("Utilisation directe"));
50 //--------------------------------------------------------------
51 $this->set_property_visible("id", FALSE);
52 $this->set_property_updatable("fiche_qcode", FALSE);
53 $this->set_col_type("pcm_type", "select", [
54 ["label"=>_("Actif"),"value"=>"ACT"],
55 ["label"=>_("Actif inversé"),"value"=>"ACTINV"],
56 ["label"=>_("Passif"),"value"=>"PAS"],
57 ["label"=>_("Passif Inversé"),"value"=>"PASINV"],
58 ["label"=>_("Charge"),"value"=>"CHA"],
59 ["label"=>_("Charge inversé"),"value"=>"CHAINV"],
60 ["label"=>_("Produit"),"value"=>"PRO"],
61 ["label"=>_("Produit inversé"),"value"=>"PROINV"],
62 ["label"=>_("Contexte"),"value"=>"CON"]
63 ]);
64 $this->set_col_type("pcm_direct_use", "select",
65 array(["label" => _("Oui"), "value" => "Y"], ["label" => "Non", "value" => "N"]));
66 $this->set_col_type("pcm_val", "custom");
67 $this->a_order = ["pcm_val", "pcm_lib", "parent_accounting", "pcm_direct_use", "pcm_type", "fiche_qcode"];
68 $this->set_icon_mod("first");
69 $this->set_dialogbox_style(["width"=>"auto"]);
70 }
71
72 /**
73 * @brief Display a row
74 * @param type $p_row array of value key column=>value
75 */
76 function display_row($p_row)
77 {
78 printf('<tr id="%s_%s">',
79 $this->object_name,
80 $p_row[$this->table->primary_key])
81 ;
82
84 $nb_order=count($this->a_order);
85 for ($i=0; $i<$nb_order; $i++)
86 {
87 $v=$this->a_order[$i];
88 $nb=0;
90 $nb_used=$cn->get_value("select count(*) from jrnx where j_poste=$1",[$p_row['pcm_val']]);
91 $nb_plan=$cn->get_value("select count(*) from tmp_pcmn where pcm_val_parent=$1",[$p_row['pcm_val']]);
92 $nb=$nb_used+$nb_plan;
93 if ($v=="pcm_val")
94 {
95 $js=sprintf("onclick=\"%s.input('%s','%s');\"", $this->object_name,
96 $p_row[$this->table->primary_key], $this->object_name);
97 echo sprintf('<td sort_type="text" sort_value="X%s">%s',
98 htmlspecialchars($p_row[$v]),
99 HtmlInput::anchor($p_row[$v], "", $js)).
100 '</td>';
101 }
102 elseif ($v == "fiche_qcode") {
103 $count=$this->table->cn->get_value("select count(*) from fiche_detail where ad_id=5 and ad_value=$1"
104 ,array($p_row['pcm_val']));
105 if ($count == 0) echo td("");
106 elseif ($count == 1 ) {
107 echo '<td>';
108 echo HtmlInput::card_detail($p_row[$v]) ;
109 echo '</td>';
110
111 }
112 elseif ($count > 1) {
113 echo '<td>';
114 $a_code=explode(",",$p_row[$v]);
115 $nb_code=count($a_code);
116 for ($xx = 0;$xx < $nb_code;$xx++)
117 {
118 echo HtmlInput::card_detail($a_code[$xx],'','style="display:inline"')."," ;
119 }
120 echo " ($count) ";
121 echo Icon_Action::more(uniqid(), sprintf("display_all_card('%s','%s')",
122 $dossier_id,$p_row["pcm_val"]));
123 echo '</td>';
124
125 }
126 }
127 elseif ($v=="pcm_lib")
128 {
129
130 if ( $nb >0){
131 echo "<td>";
132 if ($nb_used > 0) {
133 $used=sprintf (' (%s)',$nb_used);
134 echo HtmlInput::history_account($p_row['pcm_val'],h($p_row["pcm_lib"].$used));
135 } else {
136 echo h($p_row["pcm_lib"]);
137 }
138 echo "</td>";
139 } else {
140 echo td($p_row[$v]);
141 }
142
143 }
144 else
145 {
146 if ( ! $this->get_property_visible($v)) continue;
147 echo td($p_row[$v]);
148 }
149 }
150 if ( $nb == 0 ) $this->display_icon_del($p_row);
151 else echo td("&nbsp;");
152
153
154 echo '</tr>';
155 }
156
157 /**
158 * @brief Check that the entered data are valid before recording them into
159 * tmp_pcmn, the errors are stored into this->a_error and if someting wrong
160 * is found it returns false, if the data can be saved it returns true
161 * @return return false if an error is found,
162 */
163 function check()
164 {
166 $count=$cn->get_value("select count(*) from tmp_pcmn where pcm_val = $1 and id <> $2",
167 array($this->table->pcm_val,$this->table->id));
168 if ($count > 0 ) {
169 $this->set_error("pcm_val", _("Poste comptable est unique"));
170 }
171 if ( trim($this->table->pcm_val) == "") {
172 $this->set_error("pcm_val", _("Poste comptable ne peut être vide"));
173 }
174 // Check size
175 if ( noalyss_strlentrim($this->table->pcm_val) > 40) {
176 $this->set_error("pcm_val", _("Poste comptable trop long"));
177 }
178 if ( trim($this->table->parent_accounting) == "") {
179 $this->set_error("parent_accounting", _("Poste comptable dépendant ne peut pas être vide"));
180 }
181 /**
182 * Check that the parent accounting does exist
183 */
184 $exist_parent=$cn->get_value("select count(*) from tmp_pcmn where pcm_val = $1 ",
185 array($this->table->parent_accounting));
186 if ($exist_parent == 0) {
187 $this->set_error("parent_accounting", _("Compte parent n'existe pas"));
188 }
189 /**
190 * check that accounting is not already used
191 */
192 $old_accounting = $cn->get_value("select pcm_val from tmp_pcmn where id = $1",
193 array($this->table->id));
194 // it is not a new accounting and is different
195 if ($old_accounting != "" && $old_accounting != $this->table->pcm_val) {
196 // count it is used
197 if ($cn->get_value("select count(*) from jrnx where j_poste=$1",
198 [$old_accounting]) > 0) {
199 $this->set_error("pcm_val", _("Poste utilisé"));
200 }
201 }
202 if (count($this->aerror) > 0) return false;
203 return true;
204 }
205
206 /**
207 * @brief display into a dialog box the datarow in order
208 * to be appended or modified. Can be override if you need
209 * a more complex form
210 */
211 function input()
212 {
213 parent::input();
215 echo HtmlInput::button_action(_("Toutes les fiches") , sprintf("display_all_card('%s','%s')",$dossier_id,$this->table->pcm_val));
216 }
217
218 /**
219 * if pcm_val already used then it cannot be modified
220 *
221 * @param $p_key always pcm_val
222 * @param $p_value current value of pcm_val
223 * @return nothing|void
224 */
225 function input_custom($p_key, $p_value)
226 {
227 $readonly=true;
229 if (
230 $p_value == "" ||
231 ($p_value !="" && $cn->get_value("select count(*) from jrnx where j_poste=$1",[$p_value]) == 0 )
232 )
233 {
234 $readonly=false;
235 }
236 $text=new IText($p_key);
237 $text->setReadOnly($readonly);
238 $text->value=$p_value;
239 $min_size=(strlen($p_value)<30)?30:strlen($p_value)+5;
240 $text->size=$min_size;
241 echo $text->input();
242 }
243
244}
noalyss_strlentrim($p_string)
Definition: ac_common.php:1549
td($p_string='', $p_extra='')
surround the string with td
Definition: ac_common.php:83
h( $row[ 'oa_description'])
$dossier_id
Definition: ajax_poste.php:43
this instance extends Manage_Table_SQL and aims to manage the Table tmp_pcmn thanks a web interface (...
check()
Check that the entered data are valid before recording them into tmp_pcmn, the errors are stored into...
input()
display into a dialog box the datarow in order to be appended or modified.
input_custom($p_key, $p_value)
if pcm_val already used then it cannot be modified
display_row($p_row)
Display a row.
__construct(Acc_Plan_SQL $p_table)
this class is above tmp_pcmn_sql and is a view of tmp_pcmn
static id()
return the 'gDossier' value after a check
static connect()
static history_account($p_account, $p_mesg, $p_style="", $p_exercice="")
display a div with the history of the account
static card_detail($p_qcode, $pname='', $p_style="", $p_nohistory=false, $nofollowup=false)
show the detail of a card
static anchor($p_text, $p_url="", $p_js="", $p_style=' class="line" ', $p_title="click", array $p_attribute=[])
Return a simple anchor with a url or a javascript if $p_js is not null then p_url will be javascript:...
static button_action($action, $javascript, $id=NULL, $p_class="button", $p_symbole="")
button Html with javascript
Html Input.
Definition: itext.class.php:30
static more($p_id, $p_javascript)
Purpose is to propose a librairy to display a table content and allow to update and delete row ,...
set_icon_mod($pString)
Set the icon to modify at the right ,the first col or left of the row, if the mod if custom ,...
set_property_updatable($p_key, $p_value)
set a column of the data row updatable or not
set_col_type($p_key, $p_value, $p_array=NULL)
set the type of a column , it will change in the input db box , the select must supply an array of po...
get_property_visible($p_key)
return True if the column is visible otherwise false
set_dialogbox_style($db_style)
Dialog box style , by default {position: "fixed", top: '15', width: "auto", "margin-left": "20%"}.
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
$count
if( $delta< 0) elseif( $delta==0)