noalyss Version-10
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
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 :
 
 delete ()
 Delete after checking the currency is not used.
 
 display_row ($p_row)
 We cannot modify the default currency (id := 0)
 
 from_request ()
 Fill the object from request parameters :
 
 input ()
 Box to enter either a new currency or update a existing one.
 
 is_currency_used ($p_id)
 returns TRUE the currency is used otherwise FALSE.
 
 save ()
 Either insert a new currency + one rate or add a rate to an existing currency.
 
- 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.
 
 ajax_delete ()
 Delete a record and return an XML answer for ajax.
 
 ajax_input ($p_status="OK")
 send an xml with input of the object, create an xml answer.
 
 ajax_save ()
 Save the record from Request into the DB and returns an XML to update the Html Element.
 
 can_append_row ()
 return false if the append of the row is forbidden
 
 can_delete_row ()
 return false if the delete of the row is forbidden
 
 can_update_row ()
 return false if the update of the row is forbidden
 
 count_error ()
 returns the nb of errors found
 
 create_js_script ()
 we must create first the javascript if we want to update, insert or delete rows.
 
 display_error ()
 Display a list of the error collected.
 
 display_icon_custom ($p_row)
 usually contain a link and calls another page, it must be overriden
 
 display_icon_del ($p_row)
 
 display_icon_mod ($p_row)
 
 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>".
 
 display_table ($p_order="", $p_array=NULL)
 display the data of the table
 
 display_table_header ()
 display the column header excepted the not visible one and in the order defined with $this->a_order
 
 execute_query ($p_order="", $p_array=NULL)
 execute the query (Data_SQL.seek), called by display_table
 
 get_button_add_top ()
 
 get_col_option ($p_key)
 add extra to column, normally class , javascript or style
 
 get_col_sort ()
 When adding an element , it is column we checked to insert before,.
 
 get_col_type ($p_key)
 return the type of a column
 
 get_current_pos ($p_key)
 get the position of a column
 
 get_current_row ()
 Return the current row printed in display_row.
 
 get_dialog_box ()
 
 get_dialogbox_style ()
 return the db_style
 
 get_error ($p_col)
 retrieve the error message
 
 get_header_option ($p_key)
 add extra to column Header, normally class , javascript or style
 
 get_icon_del ()
 
 get_icon_mod ()
 
 get_js_variable ()
 Get the object name.
 
 get_json ()
 
 get_object_name ()
 
 get_order ()
 
 get_property_updatable ($p_key)
 return True if the column is updatable otherwise false
 
 get_property_visible ($p_key)
 return True if the column is visible otherwise false
 
 get_search_table ()
 Get if we can search in the table.
 
 get_sort_column ()
 return the column to sort
 
 get_table ()
 
 getCssClass ()
 
 getTitle ()
 
 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
 
 insert ()
 insert a new value
 
 move ($p_key, $p_idx)
 if we change a column order , the order of the other columns is impacted.
 
 param_set ($p_json)
 Set the parameter of the object (gDossier, ac, plugin_code...) @detail By default , only gDossier will be set .
 
 send_header ()
 send the XML headers for the ajax call
 
 set_append_row ($p_value)
 Enable or disable the appending of rows.
 
 set_button_add_top ($button_add_top)
 
 set_callback ($p_file)
 set the callback function that is passed to javascript
 
 set_col_label ($p_key, $p_display)
 set the name to display for a column
 
 set_col_option ($p_key, $p_value)
 add extra to column, normally class or style
 
 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.
 
 set_col_tips ($p_key, $p_comment)
 Set the info for a column, use Icon_Action\infobulle the message are in message_javascript.php.
 
 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
 
 set_current_row ($current_row)
 set the current row printed in display_row
 
 set_delete_row ($p_value)
 Enable or disable the deletion of rows.
 
 set_dialog_box ($dialog_box)
 
 set_dialogbox_style ($db_style)
 Dialog box style , by default {position: "fixed", top: '15', width: "auto", "margin-left": "20%"}.
 
 set_error ($p_col, $p_message)
 set the error message for a wrong input
 
 set_header_option ($p_key, $p_value)
 add extra to column Header, normally class or style
 
 set_icon_del ($pString)
 Set the icon to delete at the right or left of the 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 , you have to override the function display_icon_custom.
 
 set_json ($p_json)
 Set the parameter of the object (gDossier, ac, plugin_code...) @detail By default , only gDossier will be set .
 
 set_object_name ($p_object_name)
 Set the object_name.
 
 set_order ($p_order)
 
 set_pk ($p_id)
 set the id value of a data row and load from the db
 
 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_search_table ($search_table)
 Set the table searchable or not.
 
 set_sort_column ($p_col)
 set the column to sort by default
 
 set_table (Data_SQL $p_noalyss_sql)
 
 set_update_row ($p_value)
 Enable or disable the updating of rows.
 
 set_value ($p_key, $p_value)
 
 setCssClass ($p_class)
 
 setTitle ($p_title)
 Set the title of the diabox , default is Donnée.
 
 show_error ($p_col)
 
 update ()
 

Additional Inherited Members

- Static Public Member Functions inherited from Manage_Table_SQL
static ajax_error ($p_message)
 returns an XML object for error message as unauthorized access.
 
- 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
 
 $a_header_option
 Extra to add to the column Header : CSS Style , CSS class, javascript ,...
 
 $a_info
 Array with the infotip.
 
 $a_label_displaid
 Label of the col. of the datarow.
 
 $a_order
 order of the col
 
 $a_prop
 property for each col.
 
 $a_select
 Possible value if a_type is a SELECT.
 
 $a_type
 Type of the column : date , select ... Only in input.
 
 $aerror
 Array containing the error of the input data.
 
 $button_add_top
 place of the button add on the top, by default true
 
 $callback
 Callback function.
 
 $col_sort
 when inserting, it is the column to sort,-1 to disable it and append only
 
 $cssclass
 < give the title of the diabox , default is Data
 
 $current_row
 CSS class for the dialog box.
 
 $dialog_box
 ID of the dialog box which display the result of the ajax calls.
 
 $dialogbox_style
 style of the dialog box
 
 $icon_del
 place of right or left the icon update or mod, default right, accepted value=left,right
 
 $icon_mod
 place of right or left the icon update or mod, default right, accepted value=left,right,first,custom column for mod
 
 $json_parameter
 Default parameter to add (gDossier...), sent to the ajax callback.
 
 $object_name
 Object_name is used for the javascript , it is the row id to update or delete.
 
 $row_append
 Flag to indicate if rows can be added.
 
 $row_delete
 Flag to indicate if rows can be deleted.
 
 $row_update
 Flag to indicate if rows can be updated.
 
 $search_table
 boolean , by default true ,it is possible to search in the table,
 
 $sort_column
 javascript sort on this column , if empty there is no js sort
 
 $table
 Object Data_SQL.
 
 $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 $this->setCssClass("inner_box2");
66 }
_("actif, passif,charge,...")
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(), Manage_Table_SQL\set_sort_column(), and Manage_Table_SQL\setCssClass().

+ 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 122 of file currency_mtable.class.php.

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

References $cn, $cnt, $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 328 of file currency_mtable.class.php.

329 {
330 $id=$this->get_table()->currency_id;
331 if ( $this->is_currency_used($id) == FALSE) $this->table->delete();
332 }
$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 305 of file currency_mtable.class.php.

306 {
307 if ($p_row['currency_id']==0)
308 {
309 $this->set_update_row(FALSE);
310 $this->set_delete_row(FALSE);
311 parent::display_row($p_row);
312 return;
313 }
314 if ($this->is_currency_used($p_row['currency_id'])==TRUE)
315 {
316 $this->set_delete_row(FALSE);
317 } else {
318 $this->set_delete_row(TRUE);
319
320 }
321
322 $this->set_update_row(TRUE);
323 parent::display_row($p_row);
324 }
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 292 of file currency_mtable.class.php.

293 {
294 $http=new HttpInput();
295 $this->table->cr_code_iso=mb_strtoupper($http->request("cr_code_iso"));
296 $this->table->cr_name=$http->request("cr_name");
297 $this->table->currency_id=$http->request("p_id", "number");
298 $this->table->ch_value=$http->request("new_rate_value");
299 $this->table->str_from=$http->request("new_rate_date");
300 }

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 87 of file currency_mtable.class.php.

88 {
89 $record=$this->get_table();
90 $cr_code_iso=new IText("cr_code_iso", $record->cr_code_iso);
91 $cr_code_iso->size=10;
92 $cr_name=new IText("cr_name", $record->cr_name);
93 $cr_name->size=50;
94 $a_histo=$record->cn->get_array("select id,to_char(ch_from,'DD.MM.YYYY') as str_from,ch_value
95 from
96 currency_history
97 where
98 currency_id=$1", array($record->currency_id));
99 $new_rate_date=new IDate("new_rate_date");
100 $new_rate_value=new INum("new_rate_value");
101 $new_rate_value->prec=6;
102 if ($record->currency_id!=-1)
103 {
104 require NOALYSS_TEMPLATE."/currency_mtable_input.php";
105 }
106 else
107 {
108 require NOALYSS_TEMPLATE."/currency_mtable_input_new.php";
109 }
110 }

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 74 of file currency_mtable.class.php.

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

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 232 of file currency_mtable.class.php.

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

References $cn, $currency, $ex, 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: