noalyss Version-10
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
Acc_Ledger_History_Purchase Class Reference

Display the operations for Purchase. More...

+ Inheritance diagram for Acc_Ledger_History_Purchase:
+ Collaboration diagram for Acc_Ledger_History_Purchase:

Public Member Functions

 __construct (\Database $cn, $pa_ledger, $p_from, $p_to, $p_mode)
 
 export_accounting_html ()
 display the accounting
 
 export_csv ()
 export Purchase in CSV
 
 export_detail_html ()
 display detail of operations m_mode=D
 
 export_extended_html ()
 display extended details of operation m_mode=E
 
 export_html ()
 display in HTML following the mode
 
 export_oneline_html ()
 display in HTML one operation by line
 
 get_data ()
 To get data.
 
 get_filter_operation ()
 Filter operation.
 
 get_row ($p_limit=-1, $p_offset="")
 Get the rows from jrnx and quant* tables.
 
 set_data ($data)
 
- Public Member Functions inherited from Acc_Ledger_History
 __construct (Database $cn, $pa_ledger, $p_from, $p_to, $p_mode)
 
 get_from ()
 setter / getter
 
 get_ledger ()
 setter / getter
 
 get_ledger_type ()
 
 get_mode ()
 setter / getter
 
 get_tiers ($p_jrn_type, $jr_id)
 Retrieve the third : supplier for purchase, customer for sale, bank for fin,.
 
 get_tiers_id ($p_jrn_type, $jr_id)
 Return the f_id of the tiers , called by get_tiers.
 
 get_to ()
 setter / getter
 
 has_other_tax ()
 count the number of addition tax for the ledger
 
 set_a_ledger ($ma_ledger)
 setter ma_ledger (array of jrn_def_id)
 
 set_filter_operation ($filter_operation)
 Filter operation ,.
 
 set_from ($m_from)
 setter m_from (periode id)
 
 set_ledger_type ($ledger_type)
 
 set_m_mode ($m_mode)
 Setter.
 
 set_to ($m_to)
 setter m_to (periode id)
 

Private Member Functions

 add_vat_info ()
 preprare the query for fetching the detailed VAT of an operation
 
 prepare_detail ()
 Prepare the query for fetching detail of an operation.
 

Additional Inherited Members

- Static Public Member Functions inherited from Acc_Ledger_History
static factory (Database $cn, $pa_ledger, $p_from, $p_to, $p_mode, $p_paid)
 Build the right object.
 
- Data Fields inherited from Acc_Ledger_History
 $db
 database connx
 
- Protected Member Functions inherited from Acc_Ledger_History
 add_additional_tax_info ()
 add additional info about additional tax.
 
 build_filter_operation ()
 Build a SQL clause to filter operation depending if they are paid, unpaid or no filter.
 
 prepare_reconcile_date ()
 Prepare the query for fetching the linked operation @staticvar int $prepare.
 
- Protected Attributes inherited from Acc_Ledger_History
 $data
 Contains data see acc_ledger_history_financial->get_row.
 
 $filter_operation
 type of ledger VEN , ACH , ODS, FIN
 
 $ledger_type
 
 $m_from
 Starting Periode : periode.p_id.
 
 $m_mode
 mode of export L : one line, E accounting writing , D : Detail
 
 $m_to
 Ending Periode : periode.p_id.
 
 $ma_ledger
 Array of ledger id : jrn_def.jrn_def_id.
 

Detailed Description

Display the operations for Purchase.

See also
acc_ledger_historyTest.php
Examples
acc_ledger_historyTest.php.

Definition at line 32 of file acc_ledger_history_purchase.class.php.

Constructor & Destructor Documentation

◆ __construct()

Acc_Ledger_History_Purchase::__construct ( \Database $cn,
$pa_ledger,
$p_from,
$p_to,
$p_mode )

Definition at line 45 of file acc_ledger_history_purchase.class.php.

47 {
48 parent::__construct($cn, $pa_ledger, $p_from, $p_to, $p_mode);
49 $this->filter_operation='all';
50 $this->ledger_type='ACH';
51 }

References $cn.

Member Function Documentation

◆ add_vat_info()

Acc_Ledger_History_Purchase::add_vat_info ( )
private

preprare the query for fetching the detailed VAT of an operation

Definition at line 216 of file acc_ledger_history_purchase.class.php.

217 {
218 $prepare=$this->db->is_prepare("vat_infop");
219 if ($prepare==FALSE)
220 {
221 $this->db->prepare("vat_infop",
222 "
223 select
224 sum(qp_vat) vat_amount ,
225 qp_vat_code
226 from
227 quant_purchase
228 where
229 qp_internal = $1
230 group by qp_vat_code order by qp_vat_code");
231 }
232
233 $nb_row=count($this->data);
234 for ($i=0; $i<$nb_row; $i++)
235 {
236 $ret=$this->db->execute("vat_infop",
237 array($this->data[$i]["jr_internal"]));
239 $this->data[$i]["detail_vat"]=$array;
240 }
241 }
static fetch_all($ret, $p_mode=PGSQL_ASSOC)
wrapper for the function pg_fetch_all
$SecUser db

References $array, $i, $nb_row, $ret, db, and DatabaseCore\fetch_all().

Referenced by export_csv(), export_detail_html(), and export_extended_html().

+ Here is the call graph for this function:

◆ export_accounting_html()

Acc_Ledger_History_Purchase::export_accounting_html ( )

display the accounting

Reimplemented from Acc_Ledger_History.

Definition at line 61 of file acc_ledger_history_purchase.class.php.

62 {
63 $ledger_history=new Acc_Ledger_History_Generic($this->db,
64 $this->ma_ledger, $this->m_from, $this->m_to, $this->m_mode);
65 $ledger_history->export_accounting_html();
66 }

References db.

Referenced by export_html().

◆ export_csv()

Acc_Ledger_History_Purchase::export_csv ( )

export Purchase in CSV

Add currency info

Retrieve payment if any

Definition at line 285 of file acc_ledger_history_purchase.class.php.

286 {
287 // Prepare the query for reconcile date
288 $prepared_query=new Prepared_Query($this->db);
289 $prepared_query->prepare_reconcile_date();
290 $nb_other_tax=$this->has_other_tax();
291
292 $export=new Noalyss_Csv(_('journal'));
293 $export->send_header();
294
295 $this->get_row();
296 $this->prepare_reconcile_date();
297 $this->add_vat_info();
298
299 $own=new Noalyss_Parameter_Folder($this->db);
300 $title=array();
301 $title[]=_('Date');
302 $title[]=_("Paiement");
303 $title[]=_("operation");
304 $title[]=_("Pièce");
305 $title[]=_("Fournisseur");
306 $title[]=_("Note");
307 $title[]=_("interne");
308 $title[]=_("HTVA");
309 $title[]=_("privé");
310 $title[]=_("DNA");
311 $title[]=_("tva non ded.");
312 $title[]=_("TVA NP");
313
314
315
316 if ( $own->MY_TVA_USE=='Y')
317 {
318 $a_Tva=$this->db->get_array("select tva_id,tva_label from tva_rate order by tva_rate,tva_label,tva_id");
319 foreach($a_Tva as $line_tva)
320 {
321 $title[]="Tva ".$line_tva['tva_label'];
322 }
323 }
324 if ($nb_other_tax>0) {
325 $title[]=_("Autre taxe");
326 }
327 $title[]=_("TVAC/TTC");
328 $title[]=_("Devise");
329 $title[]=_("Devise HTVA");
330 $title[]=_("Devise TVA");
331 $title[]=_("Taux ref");
332 $title[]=_("Taux utilisé");
333 $title[]=_("Date paiement");
334 $title[]=_("Code paiement");
335 $title[]=_("Méthode paiement");
336 $title[]=_("Montant paiement");
337 $title[]=_("n° opération");
338 $export->write_header($title);
339
340 foreach ($this->data as $line)
341 {
342 $export->add($line['str_date']);
343 $export->add($line['str_date_paid']);
344 $export->add($line['jr_id']);
345 $export->add($line['jr_pj_number']);
346 $export->add($line['name']." ".
347 $line["first_name"]." ".
348 $line["qcode"]); // qp_supplier
349 $export->add($line['jr_comment']);
350 $export->add($line['jr_internal']);
351 $export->add($line['novat'],"number");
352 $export->add($line['private_amount'],"number");
353 $export->add($line['noded_amount'],"number");
354 $export->add($line['noded_vat'],"number");
355 $export->add($line['tva_sided'],"number");
356
357 $a_tva_amount=array();
358 if ($own->MY_TVA_USE=='Y')
359 {
360 //- set all TVA to 0
361 foreach ($a_Tva as $l)
362 {
363 $t_id=$l["tva_id"];
364 $a_tva_amount[$t_id]=0;
365 }
366 foreach ($line['detail_vat'] as $lineTVA)
367 {
368 $idx_tva=$lineTVA['qp_vat_code'];
369 $a_tva_amount[$idx_tva]=$lineTVA['vat_amount'];
370 }
371
372 foreach ($a_Tva as $line_tva)
373 {
374 $a=$line_tva['tva_id'];
375 $export->add($a_tva_amount[$a], "number");
376 }
377 }
378 if ( $nb_other_tax > 0)
379 {
380 $export->add($line['other_tax_amount'],"number");
381 }
382 $export->add(bcadd($line['other_tax_amount'],$line['tvac'],2),"number");
383 /**
384 * Add currency info
385 */
386 $export->add($line['cr_code_iso']);
387 $export->add($line['sum_oc_amount'],'number');
388 $export->add($line['sum_oc_vat_amount'],'number');
389 $export->add($line['currency_rate'],'number');
390 $export->add($line['currency_rate_ref'],'number');
391
392 /**
393 * Retrieve payment if any
394 */
395 $ret_reconcile=$this->db->execute('reconcile_date',array($line['jr_id']));
397 if ($max > 0) {
398 for ($e=0;$e<$max;$e++) {
400 $export->add($row['jr_date']);
401 $export->add($row['qcode_bank']);
402 $export->add($row['qcode_name']);
403 $export->add($row['jr_montant'],"number");
404 $export->add($row['jr_internal']);
405 }
406 }
407 $export->write();
408
409 }
410
411 }
_("actif, passif,charge,...")
add_vat_info()
preprare the query for fetching the detailed VAT of an operation
get_row($p_limit=-1, $p_offset="")
Get the rows from jrnx and quant* tables.
has_other_tax()
count the number of addition tax for the ledger
prepare_reconcile_date()
Prepare the query for fetching the linked operation @staticvar int $prepare.
static fetch_array($ret, $p_indice=0, $p_mode=PGSQL_ASSOC)
wrapper for the function pg_fetch_array
static num_row($ret)
wrapper for the function pg_num_rows

References $a, $e, $export, $l, $line, $max, $own, $ret_reconcile, $row, $title, _, add_vat_info(), db, DatabaseCore\fetch_array(), get_row(), Acc_Ledger_History\has_other_tax(), DatabaseCore\num_row(), and Acc_Ledger_History\prepare_reconcile_date().

+ Here is the call graph for this function:

◆ export_detail_html()

Acc_Ledger_History_Purchase::export_detail_html ( )

display detail of operations m_mode=D

Reimplemented from Acc_Ledger_History.

Definition at line 68 of file acc_ledger_history_purchase.class.php.

69 {
70 $own=new Noalyss_Parameter_Folder($this->db);
71
72 $this->get_row();
73 $this->add_vat_info();
75 include NOALYSS_TEMPLATE."/acc_ledger_history_purchase_detail.php";
76 }

References $own, add_vat_info(), db, get_row(), and Acc_Ledger_History\prepare_reconcile_date().

Referenced by export_html().

+ Here is the call graph for this function:

◆ export_extended_html()

Acc_Ledger_History_Purchase::export_extended_html ( )

display extended details of operation m_mode=E

Reimplemented from Acc_Ledger_History.

Definition at line 78 of file acc_ledger_history_purchase.class.php.

79 {
80 $this->get_row();
81 $this->add_vat_info();
83 $this->prepare_detail();
85 include NOALYSS_TEMPLATE."/acc_ledger_history_purchase_extended.php";
86 }
prepare_detail()
Prepare the query for fetching detail of an operation.
add_additional_tax_info()
add additional info about additional tax.

References Acc_Ledger_History\add_additional_tax_info(), add_vat_info(), get_row(), prepare_detail(), and Acc_Ledger_History\prepare_reconcile_date().

Referenced by export_html().

+ Here is the call graph for this function:

◆ export_html()

Acc_Ledger_History_Purchase::export_html ( )

display in HTML following the mode

Reimplemented from Acc_Ledger_History.

Definition at line 91 of file acc_ledger_history_purchase.class.php.

92 {
93 switch ($this->m_mode)
94 {
95 case "E":
96 $this->export_extended_html();
97 break;
98 case "D":
99 $this->export_detail_html();
100 break;
101 case "L":
102 $this->export_oneline_html();
103 break;
104 case "A":
105 $this->export_accounting_html();
106 break;
107 default:
108 break;
109 }
110 }
export_oneline_html()
display in HTML one operation by line
export_detail_html()
display detail of operations m_mode=D
export_extended_html()
display extended details of operation m_mode=E

References export_accounting_html(), export_detail_html(), export_extended_html(), and export_oneline_html().

+ Here is the call graph for this function:

◆ export_oneline_html()

Acc_Ledger_History_Purchase::export_oneline_html ( )

display in HTML one operation by line

Reimplemented from Acc_Ledger_History.

Definition at line 115 of file acc_ledger_history_purchase.class.php.

116 {
117 $this->get_row();
118 $this->prepare_reconcile_date();
119 $nb_other_tax=$this->has_other_tax();
120 require_once NOALYSS_TEMPLATE.'/acc_ledger_history_purchase_oneline.php';
121 }

References get_row(), Acc_Ledger_History\has_other_tax(), and Acc_Ledger_History\prepare_reconcile_date().

Referenced by export_html().

+ Here is the call graph for this function:

◆ get_data()

Acc_Ledger_History_Purchase::get_data ( )

To get data.

Returns
array of rows

Definition at line 277 of file acc_ledger_history_purchase.class.php.

278 {
279 return $this->data;
280 }
$data
Contains data see acc_ledger_history_financial->get_row.

References Acc_Ledger_History\$data.

◆ get_filter_operation()

Acc_Ledger_History_Purchase::get_filter_operation ( )

Filter operation.

Reimplemented from Acc_Ledger_History.

Definition at line 52 of file acc_ledger_history_purchase.class.php.

53 {
55 }
$filter_operation
type of ledger VEN , ACH , ODS, FIN

References Acc_Ledger_History\$filter_operation.

◆ get_row()

Acc_Ledger_History_Purchase::get_row ( $p_limit = -1,
$p_offset = "" )

Get the rows from jrnx and quant* tables.

Parameters
int$p_limitmax of rows to returns
int$p_offsetthe number of rows to skip

Reimplemented from Acc_Ledger_History.

Definition at line 128 of file acc_ledger_history_purchase.class.php.

129 {
130 $periode=sql_filter_per($this->db, $this->m_from, $this->m_to, 'p_id',
131 'jr_tech_per');
132
133 $cond_limite=($p_limit!=-1)?" limit ".$p_limit." offset ".$p_offset:"";
135 $ledger_list=join(",", $this->ma_ledger);
136 $sql="
137 with row_purchase as
138 (select qp_internal,
139 qp_supplier,sum(qp_price) as novat,
140 sum(qp_vat) as vat ,
141 sum(qp_vat_sided) as tva_sided ,
142 sum(qp_nd_amount) as noded_amount,
143 sum(qp_nd_tva) as noded_vat,
144 sum(qp_dep_priv) as private_amount
145 from
146 quant_purchase group by qp_supplier,qp_internal),
147 supplier_detail as (
148 select x.f_id as f_id,
149 (select ad_value from fiche_detail where ad_id=1 and f_id=x.f_id) as name,
150 (select ad_value from fiche_detail where ad_id=32 and f_id=x.f_id) as first_name,
151 (select ad_value from fiche_detail where ad_id=23 and f_id=x.f_id) as qcode
152 from
153 fiche as x) ,
154 row_currency as (
155 select sum(oc_amount) as sum_oc_amount,sum(oc_vat_amount) as sum_oc_vat_amount,jrnx.j_grpt
156 from
157 operation_currency
158 join jrnx using (j_id)
159 join quant_purchase qp using (j_id)
160 group by j_grpt
161 ),
162 other_tax as (select sum(case when j_debit is true
163 then j_montant else 0-j_montant end) other_tax_amount
164 ,j_grpt
165 from jrnx j1
166 join jrn_tax jt2 on (j1.j_id=jt2.j_id) group by j_grpt)
167 select
168 name,
169 first_name,
170 qcode,
171 jrn.jr_id,
172 jr_pj_number,
173 to_char(jr_date,'DD.MM.YYYY') as str_date,
174 to_char(jr_date,'DDMMYY') as str_date_short,
175 to_char(jr_date_paid,'DD.MM.YYYY') as str_date_paid,
176 jr_internal,
177 qp_supplier,
178 jrn.jr_comment,
179 jr_pj_name,
180 vat,
181 tva_sided,
182 novat,
183 noded_amount,
184 noded_vat,
185 private_amount,
186 novat+vat-tva_sided as tvac,
187 n_text,
188 jr_grpt_id,
189 jrn.currency_id,
190 jrn.currency_rate,
191 jrn.currency_rate_ref,
192 sum_oc_amount,
193 sum_oc_vat_amount,
194 cr_code_iso,
195 coalesce (other_tax_amount,0) other_tax_amount
196 from
197 jrn
198 join row_purchase on (qp_internal=jr_internal)
199 join supplier_detail on (qp_supplier=f_id)
200 left join jrn_note using (jr_id)
201 left join row_currency as rc on (rc.j_grpt = jrn.jr_grpt_id)
202 left join currency as c on (c.id=jrn.currency_id)
203 left join other_tax as ot on (ot.j_grpt=jrn.jr_grpt_id)
204 where
205 jr_def_id in ({$ledger_list})
206 {$sql_filter}
207 and {$periode}
208 {$cond_limite}
209 order by jrn.jr_date, substring(jr_pj_number,'[0-9]+$')::numeric ";
210 $this->data=$this->db->get_array($sql);
211 }
sql_filter_per($p_cn, $p_from, $p_to, $p_form='p_id', $p_field='jr_tech_per')
Create the condition to filter on the j_tech_per thanks a from and to date.
build_filter_operation()
Build a SQL clause to filter operation depending if they are paid, unpaid or no filter.
$sql_filter
Definition preod.inc.php:43

References $periode, $sql, $sql_filter, Acc_Ledger_History\build_filter_operation(), db, and sql_filter_per().

Referenced by export_csv(), export_detail_html(), export_extended_html(), and export_oneline_html().

+ Here is the call graph for this function:

◆ prepare_detail()

Acc_Ledger_History_Purchase::prepare_detail ( )
private

Prepare the query for fetching detail of an operation.

Definition at line 246 of file acc_ledger_history_purchase.class.php.

247 {
248
249 if ($this->db->is_prepare("detail_purchase")==FALSE)
250 {
251 $this->db->prepare("detail_purchase",
252 "
253 with card_name as
254 (select f_id,ad_value as name
255 from fiche_detail where ad_id=1),
256 card_qcode as
257 (select f_id,ad_value as qcode
258 from fiche_detail where ad_id=23)
259 select qp_price,qp_quantite,qp_vat,qp_vat_code,qp_unit,qp_vat_sided,name,qcode,tva_label,
260 qp_price+qp_vat-qp_vat_sided as tvac
261 from
262 quant_purchase
263 join jrnx using (j_id)
264 join card_name on (card_name.f_id=qp_fiche)
265 join card_qcode on (card_qcode.f_id=qp_fiche)
266 left join tva_rate on ( qp_vat_code=tva_id)
267 where
268 qp_internal=$1
269
270 ");
271 }
272 }

References db.

Referenced by export_extended_html().

◆ set_data()

Acc_Ledger_History_Purchase::set_data ( $data)
Parameters
mixed$data

< Contains rows from SQL

Definition at line 38 of file acc_ledger_history_purchase.class.php.

39 {
40 //!< Contains rows from SQL
41 $this->data = $data;
42 return $this;
43 }

References Acc_Ledger_History\$data.


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