noalyss Version-9
forecast_item_mtable.class.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
20// Copyright Author Dany De Bontridder danydb@noalyss.eu
21
22/**
23 * @file
24 * @brief display the item for forecast
25 */
26
27
28/**
29 * @file
30 * @brief display the item for forecast
31 */
32/**
33 * @class Forecast_Item_MTable
34 * @brief display the item for forecast
35 */
36require_once NOALYSS_INCLUDE . "/database/forecast_item_sql.class.php";
37require_once NOALYSS_INCLUDE . "/database/forecast_sql.class.php";
38
40{
41 private $forecast_id;
42
43 public function __construct(Data_SQL $p_table)
44 {
45 parent::__construct($p_table);
46 $this->forecast_id = -1;
47 }
48
49 static function build($p_id = -1)
50 {
54 $forecast_item->add_json_param('ac', 'FORECAST');
55 $forecast_item->add_json_param("op", "forecast_item");
56 $forecast_item->set_callback("ajax_misc.php");
57 if ( $p_id != -1 ) {
58 $forecast_id=$cn->get_value("select f_id
59 from forecast_item fi
60 join forecast_category fc on (fi.fc_id=fc.fc_id)
61 where
62 fi_id=$1",array($p_id));
63 $forecast_item->set_forecast_id($forecast_id);
64 }
65 return $forecast_item;
66
67 }
68
69 /**
70 * @return int
71 */
72 public function get_forecast_id(): int
73 {
74 return $this->forecast_id;
75 }
76
77 /**
78 * @param int $forecast_id
79 */
80 public function set_forecast_id(int $forecast_id)
81 {
82 $this->forecast_id = $forecast_id;
83 $this->add_json_param("forecast_id", $forecast_id);
84 }
85 function count_category()
86 {
87 $object=$this->get_table();
88 $nCategory = $object->cn->get_value("select count(*) from forecast_category where f_id=$1",[$this->forecast_id]);
89 return $nCategory;
90
91 }
92 /**
93 * Display list of items, if there is no category the list is empty and you cannot add new ones
94 * @param type $p_string
95 * @param type $p_array
96 */
97 public function display_table($p_string = "", $p_array = NULL)
98 {
99
100 $sql = "select fi_id,fi_text,fi_account,
101 fi_account str_account_card,
102 fc_desc,
103 fi.fi_amount ,
104 (select p_start from parm_periode pp where pp.p_id=fi.fi_pid) as str_periode
105 from forecast_item fi join forecast_category fc on (fi.fc_id=fc.fc_id)
106 where fc.f_id =$1
107 order by fc_desc,fi_text ";
108 $a_row = $this->get_table()->cn->get_array($sql, array($this->forecast_id));
109 require_once NOALYSS_TEMPLATE . "/forecast_item_mtable-display_table.php";
110 }
111
112 public function display_row($p_row)
113 {
114 if ( ! isset($p_row['fc_desc'])) {
115 $cn=$this->get_table()->cn;
116 $sql= "select fi_id,fi_text,fi_account,
117 fi_account str_account_card,
118 fc_desc,
119 fi.fi_amount ,
120 (select p_start from parm_periode pp where pp.p_id=fi.fi_pid) as str_periode
121 from forecast_item fi join forecast_category fc on (fi.fc_id=fc.fc_id)
122 where fi_id=$1";
123 $p_row=$cn->get_row($sql,[$p_row['fi_id']]);
124
125 }
126 if ( ! isset ($p_row['str_account_card'])) {
127 $p_row['str_account_card']="";
128 }
129 if ( !isset ($p_row['str_periode'])){
130 $p_row['str_periode']="";
131 }
132 printf('<tr id="%s_%s">', $this->object_name, $p_row['fi_id']);
133 print td($p_row['fc_desc']);
134 print td($p_row['fi_text']);
135 print td($p_row['str_account_card']);
136 print td(nbm($p_row['fi_amount']));
137 print td($p_row['str_periode']);
138
139
140 $jsdel = sprintf("%s.remove('%s','%s');",
141 $this->object_name,
142 $p_row['fi_id'],
143 $this->object_name
144 );
145 $jsupd = sprintf("%s.input('%s','%s');",
146 $this->object_name,
147 $p_row['fi_id'],
148 $this->object_name
149 );
150 echo '<td>' . Icon_Action::modify(uniqid(), $jsupd);
151 echo '</td>';
152 echo '<td>';
153 echo Icon_Action::trash(uniqid(), $jsdel);
154 echo '</td>';
155 echo '</tr>';
156
157 }
158
159 public function input()
160 {
161 $object=$this->get_table();
162 if ( $this->count_category() == 0 ) {
163 echo span(_("Sans catégorie il n'est pas possible d'ajouter de nouveaux éléments"),'class="notice"');
164 return false;
165 }
166
167 require_once NOALYSS_TEMPLATE."/forecast_item_mtable-input.php";
168 return true;
169 }
170
171 /**
172 * forecast_id: 14
173 p_id: 143
174 action: save
175 ctl: tbl6058da883ded6
176 fc_id: 88
177 fi_text: Gérant
178 fi_account: [4160%]-[4890%]
179 fi_amount: 3000.0000
180 fi_pid: 0
181 */
182 public function from_request()
183 {
184 $http=new HttpInput();
185 $this->set_forecast_id($http->post("forecast_id","number"));
186 $object_sql=$this->get_table();
187 $object_sql->setp("fi_text",$http->post("fi_text"));
188 $object_sql->setp("fc_id",$http->post('fc_id',"number"));
189 $object_sql->setp("fi_account",$http->post('fi_account'));
190 $object_sql->setp("fi_amount",$http->post('fi_amount',"number"));
191 $object_sql->setp("fi_pid",$http->post('fi_pid',"number"));
192 $object_sql->setp("fi_amount_initial",$http->post("fi_amount_initial","number"));
193
194
195
196 }
197 function check()
198 {
199 $object=$this->get_table();
200 if ( trim($object->getp("fi_text") ) == "") {
201 $this->set_error("fi_text", _("Intitulé est vide"));
202 }
203 if ( trim ($object->getp("fi_account"))=="") {
204 $this->set_error("fi_account", _("Formule est vide"));
205 }
206 if ( trim ($object->getp("fi_account"))=="") {
207 $this->set_error("fi_account", _("Formule est vide"));
208 }
209 if ( ! Impress::check_formula($object->getp("fi_account"))) {
210 $this->set_error("fi_account", _("Formule invalide"));
211 }
212 if ( $this->count_error()==0) return true;
213 return false;
214 }
215}
span($p_string, $p_extra='')
Definition: ac_common.php:43
td($p_string='', $p_extra='')
surround the string with td
Definition: ac_common.php:83
nbm($p_number, $p_dec=2)
format the number with a sep.
Definition: ac_common.php:137
catch(Exception $e) $forecast_item
catch(Exception $e) $object
this an abstract class , all the SQL class, like noalyss_sql (table), Acc_Plan_SQL (based on a SQL no...
static connect()
display the item for forecast
from_request()
forecast_id: 14 p_id: 143 action: save ctl: tbl6058da883ded6 fc_id: 88 fi_text: Gérant fi_account: [4...
display_row($p_row)
display a data row in the table, with the order defined in a_order and depending of the visibility of...
input()
display into a dialog box the datarow in order to be appended or modified.
display_table($p_string="", $p_array=NULL)
Display list of items, if there is no category the list is empty and you cannot add new ones.
ORM abstract of the table public.forecast_item.
manage the http input (get , post, request) and extract from an array
static modify($p_id, $p_javascript)
Display the icon to modify a idem.
static trash($p_id, $p_javascript)
Display the icon of a trashbin.
static check_formula($p_string)
Purpose is to propose a librairy to display a table content and allow to update and delete row ,...
count_error()
returns the nb of errors found
add_json_param($p_attribute, $p_value)
Add json parameter to the current one.
set_error($p_col, $p_message)
set the error message for a wrong input
print
Type of printing.