noalyss Version-9
v_currency_last_value_sql.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 (2018) Author Dany De Bontridder <dany@alchimerys.be>
21
22
23/**
24 * class_currency_history_sql.php
25 *
26 * @file
27 * @brief abstract of the view public.v_currency_last_value
28 */
29
30/**
31 * class_currency_history_sql.php
32 *
33 * @class V_Currency_Last_Value_SQL
34 * @brief abstract of the view public.v_currency_last_value
35 */
37{
38
39 function __construct(Database $p_cn, $p_id=-1)
40 {
41 $this->table="public.v_currency_last_value";
42 $this->primary_key="currency_id";
43 /*
44 * List of columns
45 */
46 $this->name=array(
47 "currency_id"=>"currency_id"
48 , "cr_name"=>"cr_name"
49 , "cr_code_iso"=>"cr_code_iso"
50 , "currency_history_id"=>"currency_history_id"
51 , "ch_value"=>"ch_value"
52 , "str_from"=>"str_from"
53 );
54 /*
55 * Type of columns
56 */
57 $this->type=array(
58 "currency_id"=>"numeric"
59 , "cr_name"=>"text"
60 , "cr_code_iso"=>"text"
61 , "currency_history_id"=>"numeric"
62 , "ch_value"=>"numeric"
63 , "str_from"=>"text"
64 );
65
66
67 $this->default=array(
68 "currency_id"=>"auto"
69 );
70
71 $this->date_format="DD.MM.YYYY";
72 parent::__construct($p_cn, $p_id);
73 }
74
75 public function count($p_where="", $p_array=null)
76 {
77 $count=$this->cn->get_value("select count(*) from $this->table ".$p_where, $p_array);
78 return $count;
79 }
80
81 public function delete()
82 {
83 /* check if currency is used */
84 $is_used = $this->cn->get_value("select count(*) from jrn where currency_id=$1",[$this->currency_id]);
85
86 /* if not used , we can delete it */
87 if ( $is_used <> 0 ) { throw new Exception (_("Devise utilisée")); }
88
89 // We cannot delete EUR
90 if ( $this->currency_id == -1 ) {
91 throw new Exception(_("EUR ne peut pas être effacé"));
92 }
93 $this->cn->exec_sql("delete from currency_history where currency_id=$1",[$this->currency_id]);
94 $this->cn->exec_sql("delete from currency where id=$1",[$this->currency_id]);
95
96 }
97
98 public function exist()
99 {
101 $count=$this->cn->get_value("select count(*) from ".$this->table." where ".$this->primary_key."=$1",
102 array($this->$pk));
103 return $count;
104 }
105
106 public function insert()
107 {
108
109 }
110
111 public function load():bool
112 {
113 $sql=" select ";
114 $sep="";
115 foreach ($this->name as $key)
116 {
117 switch ($this->type[$key])
118 {
119 case "date":
120 $sql.=$sep.'to_char('.$key.",'".$this->date_format."') as ".$key;
121 break;
122 default:
123 $sql.=$sep.$key;
124 }
125 $sep=",";
126 }
128 $sql.=" from ".$this->table;
129
130 $sql.=" where ".$this->primary_key." = $1";
131
132 $result=$this->cn->get_array($sql, array($this->$pk));
133 if ($this->cn->count()==0)
134 {
135 $this->$pk=-1;
136 return false;
137 }
138
139 foreach ($result[0] as $key=> $value)
140 {
141 $this->$key=$value;
142 }
143 return true;
144 }
145
146 function seek($cond='', $p_array=null)
147 {
148 $sql="select * from ".$this->table." $cond";
149 $ret=$this->cn->exec_sql($sql, $p_array);
150 return $ret;
151 }
152
153 public function update()
154 {
155
156 }
157
158}
$input_from cn
Definition: balance.inc.php:66
$from_poste name
$input_from type
Definition: balance.inc.php:65
this an abstract class , all the SQL class, like noalyss_sql (table), Acc_Plan_SQL (based on a SQL no...
$primary_key
Array of logical and real name.
contains the class for connecting to Noalyss
class_currency_history_sql.php
exist()
Count the number of record with the id ,.
load()
Load the current row return false if not found.
seek($cond='', $p_array=null)
retrieve array of object thanks a condition
$all table
$count