noalyss Version-9
data_currency_operation.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 (2002-2020) Author Dany De Bontridder <danydb@noalyss.eu>
21
22/**
23 * @file
24 * @brief build the SQL and fetch data currency operation from database ,
25 */
26
27/**
28 * @class Data_Currency_Operation
29 * @brief build the SQL and fetch data of data currency operation from database ,
30 */
32{
33
34 private $dbconx;
35 private $currency_id;
36 private $from_date;
37 private $to_date;
38
40 {
41 global $g_user;
42 $this->dbconx=$cn;
43 $this->currency_id=$currency_id;
44
45 $periode_limit=$g_user->get_limit_current_exercice();
46 $this->from_date=($from_date=="")?$periode_limit[0]:$from_date;
47 $this->to_date=($to_date=="")?$periode_limit[1]:$to_date;
48 }
49 /**
50 * @brief retrieve the currency code
51 * @return string ISO CODE
52 */
53 public function to_currency_code()
54 {
55 $currency_code=$this->dbconx->get_value("select cr_code_iso from currency where id=$1",[$this->currency_id]);
56 return $currency_code;
57 }
58 /**
59 * @brief retrieve currency.od
60 */
61 public function getCurrency_id()
62 {
63 return $this->currency_id;
64 }
65
66 public function getFrom_date()
67 {
68 return $this->from_date;
69 }
70
71 public function getTo_date()
72 {
73 return $this->to_date;
74 }
75
76 public function setFrom_date($from_date)
77 {
78 $this->from_date=$from_date;
79 }
80
81 public function setTo_date($to_date)
82 {
83 $this->to_date=$to_date;
84 }
85 /**
86 * @brief retrieve currency.od
87 */
88
90 {
91 $this->currency_id=$currency_id;
92 }
93 /**
94 * Database connection
95 */
96 public function getDbconx()
97 {
98 return $this->dbconx;
99 }
100
101 public function setDbconx($dbconx)
102 {
103 $this->dbconx=$dbconx;
104 return $this;
105 }
106
107 /**
108 * @brief build the SQL to execute
109 */
110 function build_SQL()
111 {
112 $sql=" select jr_id,
113 j_date,
114 j_montant,
115 coalesce(oc_amount,0) oc_amount,
116 j_poste,
117 jr_comment,
118 jr_internal,
119 jr_pj_number,
120 jrn.currency_id,
121 (select cr_code_iso from currency c where c.id=jrn.currency_id) as currency_code_iso,
122 coalesce (currency_rate,1) currency_rate,
123 coalesce (currency_rate_ref,1) currency_rate_ref,
124 f_id,
125 (select ad_value from fiche_detail fd1 where fd1.f_id=jrnx.f_id and ad_id=23) as fiche_qcode
126 from jrnx
127 join jrn on (jr_grpt_id=jrnx.j_grpt)
128 join operation_currency oc using (j_id)
129 join jrn_def on (jr_def_id=jrn_def.jrn_def_id)
130 ";
131 $sql.=$this->SQL_Condition();
132
133 $sql.=" order by j_poste,j_date ";
134
135 return $sql;
136 }
137 /**
138 *
139 * @brief build the SQL condition
140 * @return SQL condition
141 */
142 function SQL_Condition()
143 {
144 global $g_user;
145
146 return " where jrn.currency_id = $1 and ".$g_user->get_ledger_sql('ALL', 3)
147 ." and jr_date >= to_date($2,'DD.MM.YYYY')"
148 ." and jr_date <= to_date($3,'DD.MM.YYYY')"
149 ;
150 }
151 /**
152 * @brief returns data
153 * @return array
154 */
155 function get_data()
156 {
157 $sql=$this->build_SQL();
158 $aArray=$this->dbconx->get_array($sql, [$this->getCurrency_id(), $this->getFrom_date(),$this->getTo_date()]);
159
160 return $aArray;
161 }
162
163}
164
165?>
global $g_user
if no group available , then stop
build the SQL and fetch data of data currency operation from database ,
build_SQL()
build the SQL to execute
SQL_Condition()
build the SQL condition
__construct($cn, $from_date="", $to_date="", $currency_id=0)
to_currency_code()
retrieve the currency code
setCurrency_id($currency_id)
retrieve currency.od