noalyss Version-9
Public Member Functions
Currency_MTable Class Reference

Manage the configuration of currency , add currency, rate, remove and update Concerned tables are v_currency_last_value_SQL , Currency_SQL , Currency_History_SQL currency_id = 0 for the default currency , -1 for a new one. More...

+ Inheritance diagram for Currency_MTable:
+ Collaboration diagram for Currency_MTable:

Public Member Functions

 __construct (V_Currency_Last_Value_SQL $p_table)
 
 check ()
 Check that the value are correct : More...
 
 delete ()
 Delete after checking the currency is not used. More...
 
 display_row ($p_row)
 We cannot modify the default currency (id := 0) More...
 
 from_request ()
 Fill the object from request parameters : More...
 
 input ()
 Box to enter either a new currency or update a existing one. More...
 
 is_currency_used ($p_id)
 returns TRUE the currency is used otherwise FALSE. More...
 
 save ()
 Either insert a new currency + one rate or add a rate to an existing currency. More...
 
- Public Member Functions inherited from Manage_Table_SQL
 __construct (Data_SQL $p_table)
 
 add_json_param ($p_attribute, $p_value)
 Add json parameter to the current one. More...
 
 ajax_delete ()
 Delete a record and return an XML answer for ajax. More...
 
 ajax_input ($p_status="OK")
 send an xml with input of the object, create an xml answer. More...
 
 ajax_save ()
 Save the record from Request into the DB and returns an XML to update the Html Element. More...
 
 can_append_row ()
 return false if the append of the row is forbidden More...
 
 can_delete_row ()
 return false if the delete of the row is forbidden More...
 
 can_update_row ()
 return false if the update of the row is forbidden More...
 
 check ()
 
 count_error ()
 returns the nb of errors found More...
 
 create_js_script ()
 we must create first the javascript if we want to update, insert or delete rows. More...
 
 delete ()
 delete a datarow , the id must be have set before More...
 
 display_error ()
 Display a list of the error collected. More...
 
 display_icon_custom ($p_row)
 usually contain a link and calls another page, it must be overriden More...
 
 display_icon_del ($p_row)
 
 display_icon_mod ($p_row)
 
 display_row ($p_row)
 display a data row in the table, with the order defined in a_order and depending of the visibility of the column, all the rows contains the attribute ctl_pk_id , to retrieve in javascript , ie with the function afterSaveFct (see managetable.js) More...
 
 display_row_custom ($p_key, $p_value, $p_id=0)
 When displaying a row, if a column has the type "custom" , we can call this function to display properly the value including the tag "<td>". More...
 
 display_table ($p_order="", $p_array=NULL)
 display the data of the table More...
 
 display_table_header ()
 display the column header excepted the not visible one and in the order defined with $this->a_order More...
 
 execute_query ($p_order="", $p_array=NULL)
 execute the query (Data_SQL.seek), called by display_table More...
 
 from_request ()
 get the data from http request strip the not update or not visible data to their initial value. More...
 
 get_button_add_top ()
 
 get_col_option ($p_key)
 add extra to column, normally class , javascript or style More...
 
 get_col_sort ()
 When adding an element , it is column we checked to insert before,. More...
 
 get_col_type ($p_key)
 return the type of a column More...
 
 get_current_pos ($p_key)
 get the position of a column More...
 
 get_current_row ()
 Return the current row printed in display_row. More...
 
 get_dialog_box ()
 
 get_dialogbox_style ()
 return the db_style More...
 
 get_error ($p_col)
 retrieve the error message More...
 
 get_header_option ($p_key)
 add extra to column Header, normally class , javascript or style More...
 
 get_icon_del ()
 
 get_icon_mod ()
 
 get_js_variable ()
 Get the object name. More...
 
 get_json ()
 
 get_object_name ()
 
 get_order ()
 
 get_property_updatable ($p_key)
 return True if the column is updatable otherwise false More...
 
 get_property_visible ($p_key)
 return True if the column is visible otherwise false More...
 
 get_search_table ()
 Get if we can search in the table. More...
 
 get_sort_column ()
 return the column to sort More...
 
 get_table ()
 
 getCssClass ()
 
 getTitle ()
 
 input ()
 display into a dialog box the datarow in order to be appended or modified. More...
 
 input_custom ($p_key, $p_value)
 this function let you create your own input , for example for a ITEXT , a IRADIO , ... it must be override , there is not default More...
 
 insert ()
 insert a new value More...
 
 move ($p_key, $p_idx)
 if we change a column order , the order of the other columns is impacted. More...
 
 param_set ($p_json)
 Set the parameter of the object (gDossier, ac, plugin_code...) @detail By default , only gDossier will be set . More...
 
 save ()
 save the Data_SQL Object The noalyss_SQL is not empty More...
 
 send_header ()
 send the XML headers for the ajax call More...
 
 set_append_row ($p_value)
 Enable or disable the appending of rows. More...
 
 set_button_add_top ($button_add_top)
 
 set_callback ($p_file)
 set the callback function that is passed to javascript More...
 
 set_col_label ($p_key, $p_display)
 set the name to display for a column More...
 
 set_col_option ($p_key, $p_value)
 add extra to column, normally class or style More...
 
 set_col_sort ($p_num)
 When adding an element ,we place it thanks the DOM Attribute sort_value set it to -1 if you want one to append. More...
 
 set_col_tips ($p_key, $p_comment)
 Set the info for a column, use Icon_Action::infobulle the message are in message_javascript.php. More...
 
 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 possible values [val=> , label=>] with the variable $this->key_name->a_value More...
 
 set_current_row ($current_row)
 set the current row printed in display_row More...
 
 set_delete_row ($p_value)
 Enable or disable the deletion of rows. More...
 
 set_dialog_box ($dialog_box)
 
 set_dialogbox_style ($db_style)
 Dialog box style , by default {position: "fixed", top: '15', width: "auto", "margin-left": "20%"}. More...
 
 set_error ($p_col, $p_message)
 set the error message for a wrong input More...
 
 set_header_option ($p_key, $p_value)
 add extra to column Header, normally class or style More...
 
 set_icon_del ($pString)
 Set the icon to delete at the right or left of the row. More...
 
 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 , you have to override the function display_icon_custom. More...
 
 set_json ($p_json)
 Set the parameter of the object (gDossier, ac, plugin_code...) @detail By default , only gDossier will be set . More...
 
 set_object_name ($p_object_name)
 Set the object_name. More...
 
 set_order ($p_order)
 
 set_pk ($p_id)
 set the id value of a data row and load from the db More...
 
 set_property_updatable ($p_key, $p_value)
 set a column of the data row updatable or not More...
 
 set_property_visible ($p_key, $p_value)
 set a column of the data row visible or not More...
 
 set_search_table ($search_table)
 Set the table searchable or not. More...
 
 set_sort_column ($p_col)
 set the column to sort by default More...
 
 set_table (Data_SQL $p_noalyss_sql)
 
 set_update_row ($p_value)
 Enable or disable the updating of rows. More...
 
 set_value ($p_key, $p_value)
 
 setCssClass ($p_class)
 
 setTitle ($p_title)
 Set the title of the diabox , default is Donnée. More...
 
 show_error ($p_col)
 
 update ()
 

Additional Inherited Members

- Data Fields inherited from Manage_Table_SQL
const UPDATABLE =1
 
const VISIBLE =2
 
- Protected Attributes inherited from Manage_Table_SQL
 $a_col_option
 in display_row and display_custom_row, it is the current row which is used More...
 
 $a_header_option
 Extra to add to the column Header : CSS Style , CSS class, javascript ,... More...
 
 $a_info
 Array with the infotip. More...
 
 $a_label_displaid
 Label of the col. of the datarow. More...
 
 $a_order
 order of the col More...
 
 $a_prop
 property for each col. More...
 
 $a_select
 Possible value if a_type is a SELECT. More...
 
 $a_type
 Type of the column : date , select ... Only in input. More...
 
 $aerror
 Array containing the error of the input data. More...
 
 $button_add_top
 place of the button add on the top, by default true More...
 
 $callback
 Callback function. More...
 
 $col_sort
 when inserting, it is the column to sort,-1 to disable it and append only More...
 
 $cssclass
 < give the title of the diabox , default is Data More...
 
 $current_row
 CSS class for the dialog box. More...
 
 $dialog_box
 ID of the dialog box which display the result of the ajax calls. More...
 
 $dialogbox_style
 style of the dialog box More...
 
 $icon_del
 place of right or left the icon update or mod, default right, accepted value=left,right More...
 
 $icon_mod
 place of right or left the icon update or mod, default right, accepted value=left,right,first,custom column for mod More...
 
 $json_parameter
 Default parameter to add (gDossier...), sent to the ajax callback. More...
 
 $object_name
 Object_name is used for the javascript , it is the row id to update or delete. More...
 
 $row_append
 Flag to indicate if rows can be added. More...
 
 $row_delete
 Flag to indicate if rows can be deleted. More...
 
 $row_update
 Flag to indicate if rows can be updated. More...
 
 $search_table
 boolean , by default true ,it is possible to search in the table, More...
 
 $sort_column
 javascript sort on this column , if empty there is no js sort More...
 
 $table
 Object Data_SQL. More...
 
 $title
 

Detailed Description

Manage the configuration of currency , add currency, rate, remove and update Concerned tables are v_currency_last_value_SQL , Currency_SQL , Currency_History_SQL currency_id = 0 for the default currency , -1 for a new one.

Examples
test_currency_mtable.php.

Definition at line 34 of file currency_mtable.class.php.

Constructor & Destructor Documentation

◆ __construct()

Currency_MTable::__construct ( V_Currency_Last_Value_SQL  $p_table)

Definition at line 42 of file currency_mtable.class.php.

43 {
44 parent::__construct($p_table);
45
46 // If currency , cannot be deleted
47 if ($this->is_currency_used($p_table->currency_id)==TRUE)
48 {
49 $this->set_delete_row(FALSE);
50 }
51 else
52 {
53 $this->set_delete_row(TRUE);
54 }
55 $this->set_property_visible("currency_id", FALSE);
56 $this->set_property_visible("currency_history_id", FALSE);
57 $this->set_col_label("cr_code_iso", "ISO");
58 $this->set_col_label("cr_name", _("Nom"));
59 $this->set_col_label('ch_value', _("Valeur"));
60 $this->set_col_label('str_from', _("Date"));
61 $this->set_col_type("str_from", "date");
62 $this->a_order=array("cr_code_iso", "currency_id", "currency_history_id", "cr_name", "ch_value", "str_from");
63 $this->set_icon_mod("first");
64 $this->set_sort_column("cr_code_iso");
65 }
is_currency_used($p_id)
returns TRUE the currency is used otherwise FALSE.
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_delete_row($p_value)
Enable or disable the deletion of rows.
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...
set_sort_column($p_col)
set the column to sort by default
set_property_visible($p_key, $p_value)
set a column of the data row visible or not
set_col_label($p_key, $p_display)
set the name to display for a column

References is_currency_used(), Manage_Table_SQL\set_col_label(), Manage_Table_SQL\set_col_type(), Manage_Table_SQL\set_delete_row(), Manage_Table_SQL\set_icon_mod(), Manage_Table_SQL\set_property_visible(), and Manage_Table_SQL\set_sort_column().

+ Here is the call graph for this function:

Member Function Documentation

◆ check()

Currency_MTable::check ( )

Check that the value are correct :

  • Code iso must be unique
  • Name cannot be empty
  • At least one rate
  • Date of the rate
  • code iso is max 10 char
  • name is max 80 Default currency (id=0) cannot be changed

Reimplemented from Manage_Table_SQL.

Definition at line 121 of file currency_mtable.class.php.

122 {
123 global $cn;
124 $table=$this->get_table();
125 $is_error=0;
126 if ( $table->currency_id == 0) {
127 $is_error++;
128 $this->set_error("cr_code_iso", _("Devise par défaut ne peut être changée"));
129 }
130 // ------ cr_code_iso can not be empty
131 if (trim($table->cr_code_iso)=="")
132 {
133 $is_error++;
134 $this->set_error("cr_code_iso", _("Code iso ne peut pas être vide"));
135 }
136 // ------ cr_name can not be empty
137 if (trim($table->cr_name)=="")
138 {
139 $is_error++;
140 $this->set_error("cr_name", _("Nom ne peut pas être vide"));
141 }
142 // ----- for new record than we need at leat a date + value
143 if ($table->currency_id==-1)
144 {
145 // -- for new record , we need a date + value
146 if (isDate($table->str_from)==0||trim($table->str_from)=="")
147 {
148 $is_error++;
149 $this->set_error("str_from", _("Date incorrecte, il faut au moins une valeur"));
150 }
151 if (isNumber($table->ch_value)==0||trim($table->ch_value)=="")
152 {
153 $is_error++;
154 $this->set_error("ch_value", _("Valeur incorrecte, il faut au moins une valeur"));
155 }
156 }
157 else
158 {
159 if (trim($table->str_from) =="" && trim($table->ch_value)=="")
160 {
161 // we don't add any new date
162
163 }
164 // -- for update, the date and value must be valid
165 elseif (trim($table->str_from)!=""&&trim($table->ch_value)!="")
166 {
167 if (isDate($table->str_from)==0)
168 {
169 $is_error++;
170 $this->set_error("str_from", _("Date incorrecte"));
171 }
172 if (isNumber($table->ch_value)==0)
173 {
174 $is_error++;
175 $this->set_error("ch_value", _("Valeur incorrecte"));
176 }
177 // Date must be the greatest
178 $count=$cn->get_value("select count(*)
179 from
180 currency_history
181 where
182 currency_id =$1
183 and ch_from >= to_date($2,'DD.MM.YYYY') ", array($table->currency_id, $table->str_from));
184 if ($count>0)
185 {
186 $is_error++;
187 $this->set_error("str_from", _("Date doit être après la dernière valeur"));
188 }
189 }
190 elseif (trim($table->str_from)!=""||trim($table->ch_value)!="")
191 {
192 $is_error++;
193 $this->set_error("str_from", _("Valeur manquante"));
194 }
195 }
196 //-- duplicate iso code
197 $cnt=$cn->get_value("select count(*) from currency where id != $1 and cr_code_iso=$2",
198 array($table->currency_id, $table->cr_code_iso));
199 if ($cnt>0)
200 {
201 $is_error++;
202 $this->set_error("cr_code_iso", _("Code ISO existe déjà"));
203 }
204 // - check size
205 if ( trim(mb_strlen($table->cr_code_iso))>10)
206 {
207 $is_error++;
208 $this->set_error("cr_code_iso", _("Code ISO trop long max = 10"));
209 }
210 // - check size
211 if ( trim(mb_strlen($table->cr_name))>80)
212 {
213 $is_error++;
214 $this->set_error("cr_name", _("Nom trop long max=80"));
215 }
216 if ( $table->ch_value != "" && ($table->ch_value < 0 || $table->ch_value == 0)) {
217 $is_error++;
218 $this->set_error("ch_value", _("Valeur incorrecte"));
219 }
220 if ($is_error==0)
221 {
222 return TRUE;
223 }
224
225 return FALSE;
226 }
isNumber($p_int)
Definition: ac_common.php:215
isDate($p_date)
Definition: ac_common.php:236
set_error($p_col, $p_message)
set the error message for a wrong input
$count
if( $delta< 0) elseif( $delta==0)

References $cn, $count, Manage_Table_SQL\$table, elseif, Manage_Table_SQL\get_table(), isDate(), isNumber(), and Manage_Table_SQL\set_error().

+ Here is the call graph for this function:

◆ delete()

Currency_MTable::delete ( )

Delete after checking the currency is not used.

Reimplemented from Manage_Table_SQL.

Definition at line 327 of file currency_mtable.class.php.

328 {
329 $id=$this->get_table()->currency_id;
330 if ( $this->is_currency_used($id) == FALSE) $this->table->delete();
331 }
$all table

References $id, Manage_Table_SQL\get_table(), is_currency_used(), and table.

+ Here is the call graph for this function:

◆ display_row()

Currency_MTable::display_row (   $p_row)

We cannot modify the default currency (id := 0)

Reimplemented from Manage_Table_SQL.

Definition at line 304 of file currency_mtable.class.php.

305 {
306 if ($p_row['currency_id']==0)
307 {
308 $this->set_update_row(FALSE);
309 $this->set_delete_row(FALSE);
310 parent::display_row($p_row);
311 return;
312 }
313 if ($this->is_currency_used($p_row['currency_id'])==TRUE)
314 {
315 $this->set_delete_row(FALSE);
316 } else {
317 $this->set_delete_row(TRUE);
318
319 }
320
321 $this->set_update_row(TRUE);
322 parent::display_row($p_row);
323 }
set_update_row($p_value)
Enable or disable the updating of rows.

References is_currency_used(), Manage_Table_SQL\set_delete_row(), and Manage_Table_SQL\set_update_row().

+ Here is the call graph for this function:

◆ from_request()

Currency_MTable::from_request ( )

Fill the object from request parameters :

  • cr_code_iso
  • cr_name
  • p_id
  • new_rate_date
  • new_rate_value

Reimplemented from Manage_Table_SQL.

Definition at line 291 of file currency_mtable.class.php.

292 {
293 $http=new HttpInput();
294 $this->table->cr_code_iso=mb_strtoupper($http->request("cr_code_iso"));
295 $this->table->cr_name=$http->request("cr_name");
296 $this->table->currency_id=$http->request("p_id", "number");
297 $this->table->ch_value=$http->request("new_rate_value");
298 $this->table->str_from=$http->request("new_rate_date");
299 }
manage the http input (get , post, request) and extract from an array

References $http, and table.

◆ input()

Currency_MTable::input ( )

Box to enter either a new currency or update a existing one.

Reimplemented from Manage_Table_SQL.

Definition at line 86 of file currency_mtable.class.php.

87 {
88 $record=$this->get_table();
89 $cr_code_iso=new IText("cr_code_iso", $record->cr_code_iso);
90 $cr_code_iso->size=10;
91 $cr_name=new IText("cr_name", $record->cr_name);
92 $cr_name->size=50;
93 $a_histo=$record->cn->get_array("select id,to_char(ch_from,'DD.MM.YYYY') as str_from,ch_value
94 from
95 currency_history
96 where
97 currency_id=$1", array($record->currency_id));
98 $new_rate_date=new IDate("new_rate_date");
99 $new_rate_value=new INum("new_rate_value");
100 $new_rate_value->prec=6;
101 if ($record->currency_id!=-1)
102 {
103 require NOALYSS_TEMPLATE."/currency_mtable_input.php";
104 }
105 else
106 {
107 require NOALYSS_TEMPLATE."/currency_mtable_input_new.php";
108 }
109 }
Html Input : Input a date format dd.mm.yyyy The property title should be set to indicate what it is e...
Definition: idate.class.php:34
This class handles only the numeric input, the input will call a javascript to change comma to period...
Definition: inum.class.php:42
Html Input.
Definition: itext.class.php:30

References Manage_Table_SQL\get_table().

+ Here is the call graph for this function:

◆ is_currency_used()

Currency_MTable::is_currency_used (   $p_id)

returns TRUE the currency is used otherwise FALSE.

We cannot delete a currency which is used in a operation

Parameters
integer$p_idcurrency_id
Returns
boolean true if currency is used

Definition at line 73 of file currency_mtable.class.php.

74 {
75 global $cn;
76 $cnt_used=$cn->get_value(" select count(*) from jrn where currency_id=$1",[$p_id]);
77 if ($cnt_used > 0)
78 {
79 return TRUE;
80 }
81 return FALSE;
82 }

References $cn, and $p_id.

Referenced by __construct(), delete(), and display_row().

◆ save()

Currency_MTable::save ( )

Either insert a new currency + one rate or add a rate to an existing currency.

Reimplemented from Manage_Table_SQL.

Definition at line 231 of file currency_mtable.class.php.

232 {
234 try
235 {
236 $cn->start();
237 $record=$this->get_table();
238
239 if ($record->currency_id==-1)
240 {
241 // Append a new currency and a default value
243 $currency->setp("cr_code_iso", mb_strtoupper($record->cr_code_iso));
244 $currency->setp("cr_name", $record->cr_name);
245 $currency->insert();
246
247 $currency_history=new Currency_history_SQL($cn);
248 $currency_history->setp("ch_value", $record->ch_value);
249 $currency_history->setp("ch_from", $record->str_from);
250 $currency_history->setp("currency_id", $currency->id);
251 $currency_history->insert();
252
253 $this->table->currency_id=$currency->id;
254 $this->table->load();
255 }
256 else
257 {
258 // append a value in currency_historique and update currency
259 $currency=new Currency_SQL($cn, $record->currency_id);
260 $currency->setp("cr_code_iso", mb_strtoupper($record->cr_code_iso));
261 $currency->setp("cr_name", $record->cr_name);
262 $currency->update();
263
264 if ($record->str_from!="")
265 {
266 $currency_history=new Currency_history_SQL($cn);
267 $currency_history->setp("ch_value", $record->ch_value);
268 $currency_history->setp("ch_from", $record->str_from);
269 $currency_history->setp("currency_id", $currency->id);
270 $currency_history->insert();
271 }
272 }
273 $cn->commit();
274 }
275 catch (Exception $ex)
276 {
277 $cn->rollback();
278 throw ($ex);
279 }
280 }
$ex
Definition: balance.inc.php:45
abstract of the table public.currency
abstract of the table public.currency_history
static connect()

References $cn, $currency, $ex, Dossier\connect(), Manage_Table_SQL\get_table(), and table.

+ Here is the call graph for this function:

The documentation for this class was generated from the following file: