noalyss Version-9
acc_currency.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
22require_once NOALYSS_INCLUDE."/database/v_currency_last_value_sql.class.php";
23/**
24 * @file
25 * @brief display currency , convert to euro , and save them if used
26 */
27
28/**
29 * @class Acc_Currency
30 * @brief display currency , convert to euro , and save them if used. The default currency has the id 0 and is
31 * normally EUR
32 */
34{
35
36 private $cn; //!< database conx
37 private $currency; //!< v_currency_last_value_sql
38
39 function __construct(Database $p_cn, $p_id=-1)
40 {
41 $this->cn=$p_cn;
42 $this->currency=new V_Currency_Last_Value_SQL($p_cn, $p_id);
43 }
44
45 public function __toString(): string
46 {
47 return "Acc_Currency [".$this->currency->__toString()."]";
48 }
49
50 /**
51 * Retrieve a V_Currency_Last_Value_SQL thanks its iso_code
52 * @param string $p_iso
53 */
54 function get_by_iso($p_iso)
55 {
56 $p_iso=trim(strtoupper($p_iso));
57 $id=$this->cn->get_value("select currency_id from v_currency_last_value where cr_code_iso=$1", [$p_iso]);
58 if ($id!="")
59 {
60 $this->currency->setp("currency_id", $id);
61 $this->currency->load();
62 }
63 }
64
65 /**
66 * Retrieve a V_Currency_Last_Value_SQL thanks its id
67 * @param number $p_id
68 */
69 function set_id($p_id)
70 {
71 $this->currency->setp("currency_id", $p_id);
72 $this->currency->load();
73 }
74 /**
75 * Check if the record is found
76 * @return boolean
77 */
78 function is_found() {
79 if ($this->currency->currency_id==-1)
80 {
81 return FALSE;
82 }
83 return TRUE;
84 }
85 /**
86 * return the rate of the currency
87 */
88 function get_rate()
89 {
90 return $this->currency->getp("ch_value");
91
92 }
93 /**
94 * return the iso code of the currency
95 */
96 function get_code()
97 {
98 return $this->currency->getp("cr_code_iso");
99
100
101 }
102 /**
103 * return the id of the currency
104 */
105 function get_id()
106 {
107 return $this->currency->getp("currency_id");
108
109 }
110 /**
111 * Create an object iselect to select the currency,
112 * @return \ISelect
113 */
115 {
116 $select=new ISelect('p_currency_code');
117 $a_currency=$this->cn->make_array("select currency_id,cr_code_iso from v_currency_last_value order by cr_code_iso");
118 $select->value=$a_currency;
119 $select->selected=$this->currency->cr_code_iso;
120
121 return $select;
122 }
123 /**
124 * Return sum of the w/o VAT and VAT or an operation
125 */
126 function sum_amount($p_jr_id)
127 {
128 $sql = "
129 select sum(round(oc_amount,2)) +
130 sum(round(oc_vat_amount,2))
131 from operation_currency
132 where
133 j_id in (
134 select j_id
135 from jrnx
136 where
137 j_grpt in ( select jr_grpt_id from jrn where jr_id=$1))";
138 $sum=$this->cn->get_value($sql, [$p_jr_id]);
139 return $sum;
140
141 }
142 /**
143 * Return the rate used at a certain date or -1 if date if not in the format DD.MM.YYYY or -2 if no value is found
144 * @param date $p_date
145 */
147 {
148 if ( $this->get_id() == 0 ) { return 1;}
149
150 if (isDate($p_date) == null ) {
151 throw new Exception(_("Date invalide"));
152 }
153
154 $sql="select ch_value from currency_history
155 where
156 ch_from=(select max(ch_from) from currency_history where ch_from <= to_date($1,'DD.MM.YYYY') and currency_id=$2)
157 and currency_id=$2";
158 $value=$this->cn->get_value($sql,[$p_date,$this->get_id()]);
159 if ($value == "") {
160 throw new Exception(_("Aucun taux à cette date , aller sur CFGCURRENCY"));
161 }
162 return $value;
163 }
164
165
166}
isDate($p_date)
Definition: ac_common.php:236
$input_from cn
Definition: balance.inc.php:66
display currency , convert to euro , and save them if used.
get_code()
return the iso code of the currency
sum_amount($p_jr_id)
Return sum of the w/o VAT and VAT or an operation.
$currency
v_currency_last_value_sql
get_by_iso($p_iso)
Retrieve a V_Currency_Last_Value_SQL thanks its iso_code.
set_id($p_id)
Retrieve a V_Currency_Last_Value_SQL thanks its id.
get_rate()
return the rate of the currency
get_id()
return the id of the currency
$cn
database conx
get_rate_date($p_date)
Return the rate used at a certain date or -1 if date if not in the format DD.MM.YYYY or -2 if no valu...
__construct(Database $p_cn, $p_id=-1)
select_currency()
Create an object iselect to select the currency,.
is_found()
Check if the record is found.
contains the class for connecting to Noalyss
Html Input , create a tag <SELECT> ... </SELECT> if readonly == true then display the label correspon...
class_currency_history_sql.php