noalyss Version-9
Public Member Functions | Private Member Functions | Private Attributes
Acc_Ledger_History_Sale Class Reference

Acc_Ledger_History : Manage the list (history) of operations for display. More...

+ Inheritance diagram for Acc_Ledger_History_Sale:
+ Collaboration diagram for Acc_Ledger_History_Sale:

Public Member Functions

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

Private Member Functions

 add_vat_info ()
 preprare the query for fetching the detailed VAT of an operation @staticvar int $prepare More...
 
 prepare_detail ()
 Prepare the query for fetching detail of an operation. More...
 

Private Attributes

 $data
 Contains rows from SQL. More...
 

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. More...
 
- Data Fields inherited from Acc_Ledger_History
 $db
 database connx More...
 
- Protected Member Functions inherited from Acc_Ledger_History
 add_additional_tax_info ()
 add additional info about additional tax. More...
 
 build_filter_operation ()
 Build a SQL clause to filter operation depending if they are paid, unpaid or no filter. More...
 
 prepare_reconcile_date ()
 Prepare the query for fetching the linked operation @staticvar int $prepare. More...
 
- Protected Attributes inherited from Acc_Ledger_History
 $filter_operation
 type of ledger VEN , ACH , ODS, FIN More...
 
 $ledger_type
 
 $m_from
 Starting Periode : periode.p_id. More...
 
 $m_mode
 mode of export L : one line, E accounting writing , D : Detail More...
 
 $m_to
 Ending Periode : periode.p_id. More...
 
 $ma_ledger
 Array of ledger id : jrn_def.jrn_def_id. More...
 

Detailed Description

Acc_Ledger_History : Manage the list (history) of operations for display.

Definition at line 31 of file acc_ledger_history_sale.class.php.

Constructor & Destructor Documentation

◆ __construct()

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

Definition at line 37 of file acc_ledger_history_sale.class.php.

39 {
40 parent::__construct($cn, $pa_ledger, $p_from, $p_to, $p_mode);
41 $this->filter_operation='all';
42 $this->ledger_type='VEN';
43 }

References $cn.

Member Function Documentation

◆ add_vat_info()

Acc_Ledger_History_Sale::add_vat_info ( )
private

preprare the query for fetching the detailed VAT of an operation @staticvar int $prepare

Definition at line 198 of file acc_ledger_history_sale.class.php.

199 {
200 $prepare=$this->db->is_prepare("vat_info");
201 if ( $prepare==FALSE) {
202 $this->db->prepare("vat_info","
203 select
204 sum(qs_vat) vat_amount ,
205 qs_vat_code
206 from
207 quant_sold
208 where
209 qs_internal = $1
210 group by qs_vat_code order by qs_vat_code");
211
212 }
213
214 $nb_row=count($this->data);
215 for ($i=0;$i<$nb_row;$i++)
216 {
217 $ret=$this->db->execute("vat_info",array($this->data[$i]["jr_internal"]));
219 $this->data[$i]["detail_vat"]=$array;
220 }
221 }
static fetch_all($ret)
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_Sale::export_accounting_html ( )

display the accounting

Reimplemented from Acc_Ledger_History.

Definition at line 59 of file acc_ledger_history_sale.class.php.

60 {
61 $ledger_history=new Acc_Ledger_History_Generic($this->db,
62 $this->ma_ledger, $this->m_from, $this->m_to, $this->m_mode);
63 $ledger_history->export_accounting_html();
64 }
manage the list of operation when we need several ledger with a different type or from Misceleaneous ...

References db.

Referenced by export_html().

◆ export_csv()

Acc_Ledger_History_Sale::export_csv ( )

export in csv with detail VAT

Add currency info

Retrieve payment if any

Definition at line 274 of file acc_ledger_history_sale.class.php.

275 {
276 $export=new Noalyss_Csv(_('journal'));
277 $export->send_header();
278 $nb_other_tax=$this->has_other_tax();
279
280 $this->get_row();
281 $this->prepare_reconcile_date();
282 $this->add_vat_info();
283
284 $own=new Noalyss_Parameter_Folder($this->db);
285 $title=array();
286 $title[]=_('Date');
287 $title[]=_("Paiement");
288 $title[]=_("operation");
289 $title[]=_("Pièce");
290 $title[]=_("Fournisseur");
291 $title[]=_("Note");
292 $title[]=_("interne");
293 $title[]=_("HTVA");
294 $title[]=_("TVA");
295 $title[]=_("TVA annulée");
296
297 if ( $own->MY_TVA_USE=='Y')
298 {
299 $a_Tva=$this->db->get_array("select tva_id,tva_label from tva_rate order by tva_rate,tva_label,tva_id");
300 foreach($a_Tva as $line_tva)
301 {
302 $title[]="Tva ".$line_tva['tva_label'];
303 }
304 }
305 if ($nb_other_tax>0) {
306 $title[]=_("Autre tx");
307 }
308 $title[]=_("TVAC/TTC");
309 $title[]=_("Devise");
310 $title[]=_("Devise HTVA");
311 $title[]=_("Devise TVA");
312 $title[]=_("Taux ref");
313 $title[]=_("Taux utilisé");
314 $title[]=_("Date paiement");
315 $title[]=_("Code paiement");
316 $title[]=_("Montant paiement");
317 $title[]=_("n° opération");
318
319 $export->write_header($title);
320
321 foreach ($this->data as $line)
322 {
323 $export->add($line['str_date']);
324 $export->add($line['str_date_paid']);
325 $export->add($line['jr_id']);
326 $export->add($line['jr_pj_number']);
327 $export->add($line['name']." ".
328 $line["first_name"]." ".
329 $line["qcode"]); // qp_supplier
330 $export->add($line['jr_comment']);
331 $export->add($line['jr_internal']);
332 $export->add($line['novat'],"number");
333 $export->add($line['vat'],"number");
334 $export->add($line['tva_sided'],"number");
335
336 $a_tva_amount=array();
337
338 if ($own->MY_TVA_USE == 'Y' )
339 {
340 //- set all TVA to 0
341 foreach ($a_Tva as $l) {
342 $t_id=$l["tva_id"];
343 $a_tva_amount[$t_id]=0;
344 }
345 foreach ($line['detail_vat'] as $lineTVA)
346 {
347 $idx_tva=$lineTVA['qs_vat_code'];
348 $a_tva_amount[$idx_tva]=$lineTVA['vat_amount'];
349 }
350 foreach ($a_Tva as $line_tva)
351 {
352 $a=$line_tva['tva_id'];
353 $export->add($a_tva_amount[$a],"number");
354 }
355 }
356 if ( $nb_other_tax > 0)
357 {
358 $export->add($line['other_tax_amount'],"number");
359 }
360 $export->add(bcadd($line['other_tax_amount'],$line['tvac'],2),"number");
361 /**
362 * Add currency info
363 */
364 $export->add($line['cr_code_iso']);
365 $export->add($line['sum_oc_amount'],'number');
366 $export->add($line['sum_oc_vat_amount'],'number');
367 $export->add($line['currency_rate'],'number');
368 $export->add($line['currency_rate_ref'],'number');
369
370 /**
371 * Retrieve payment if any
372 */
373 $ret_reconcile=$this->db->execute('reconcile_date',array($line['jr_id']));
375 if ($max > 0) {
376 for ($e=0;$e<$max;$e++) {
378 $export->add($row['jr_date']);
379 $export->add($row['qcode_bank']);
380 $export->add($row['qcode_name']);
381 $export->add($row['jr_montant'],"number");
382 $export->add($row['jr_internal']);
383
384 }
385 }
386 $export->write();
387
388 }
389 }
add_vat_info()
preprare the query for fetching the detailed VAT of an operation @staticvar int $prepare
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
Manage the CSV : manage files and write CSV record.
Class to manage the company parameter (address, name...)

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_Sale::export_detail_html ( )

Display the operation of sales with detailled VAT.

Reimplemented from Acc_Ledger_History.

Definition at line 47 of file acc_ledger_history_sale.class.php.

48 {
50
51 $this->get_row();
52 $this->add_vat_info();
54 include NOALYSS_TEMPLATE."/acc_ledger_history_sale_detail.php";
55 }

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_Sale::export_extended_html ( )

display the operation with detailled vat per item

Reimplemented from Acc_Ledger_History.

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

69 {
70 $this->get_row();
71 $this->add_vat_info();
73 $this->prepare_detail();
75 include NOALYSS_TEMPLATE."/acc_ledger_history_sale_extended.php";
76 }
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_Sale::export_html ( )

display in HTML following the mode

Reimplemented from Acc_Ledger_History.

Definition at line 226 of file acc_ledger_history_sale.class.php.

227 {
228 switch ($this->m_mode)
229 {
230 case "E":
231 $this->export_extended_html();
232 break;
233 case "D":
234 $this->export_detail_html();
235 break;
236 case "L":
237 $this->export_oneline_html();
238 break;
239 case "A":
240 $this->export_accounting_html();
241 break;
242 default:
243 break;
244 }
245 }
export_detail_html()
Display the operation of sales with detailled VAT.
export_extended_html()
display the operation with detailled vat per item
export_oneline_html()
display in HTML one operation by line
export_accounting_html()
display the accounting

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_Sale::export_oneline_html ( )

display in HTML one operation by line

Reimplemented from Acc_Ledger_History.

Definition at line 250 of file acc_ledger_history_sale.class.php.

251 {
252 $this->get_row();
253 $this->prepare_reconcile_date();
254 $nb_other_tax=$this->has_other_tax();
255 require_once NOALYSS_TEMPLATE.'/acc_ledger_history_sale_oneline.php';
256
257 }

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_Sale::get_data ( )

To get data.

Returns
array of rows

Definition at line 262 of file acc_ledger_history_sale.class.php.

263 {
264 return $this->data;
265 }

References $data.

◆ get_row()

Acc_Ledger_History_Sale::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 115 of file acc_ledger_history_sale.class.php.

116 {
117 $periode=sql_filter_per($this->db, $this->m_from, $this->m_to, 'p_id',
118 'jr_tech_per');
119
120 $cond_limite=($p_limit!=-1)?" limit ".$p_limit." offset ".$p_offset:"";
121
122 $sql_filter=$this->build_filter_operation();
123
124 $ledger_list=join(",", $this->ma_ledger);
125 $sql="
126 with row_sale as
127 (select qs_internal,
128 qs_client,sum(qs_price) as novat,
129 sum(qs_vat) as vat ,
130 sum(qs_vat_sided) as tva_sided
131 from
132 quant_sold group by qs_client,qs_internal),
133 client_detail as (
134 select x.f_id as f_id,
135 (select ad_value from fiche_detail where ad_id=1 and f_id=x.f_id) as name,
136 (select ad_value from fiche_detail where ad_id=32 and f_id=x.f_id) as first_name,
137 (select ad_value from fiche_detail where ad_id=23 and f_id=x.f_id) as qcode
138 from
139 fiche as x),
140 row_currency as (
141 select sum(oc_amount) as sum_oc_amount,sum(oc_vat_amount) as sum_oc_vat_amount,jrnx.j_grpt
142 from
143 operation_currency
144 join jrnx using (j_id)
145 join quant_sold using (j_id)
146 group by j_grpt
147 ),
148 other_tax as (select sum(case when j_debit is false
149 then j_montant else 0-j_montant end) as other_tax_amount,
150 j_grpt
151 from jrnx j1
152 join jrn_tax jt2 on (j1.j_id=jt2.j_id) group by j_grpt)
153 select
154 name,
155 first_name,
156 qcode,
157 jr_id,
158 jr_pj_number,
159 to_char(jr_date,'DD.MM.YYYY') as str_date,
160 to_char(jr_date_paid,'DD.MM.YYYY') as str_date_paid,
161 jr_internal,
162 qs_client,
163 jrn.jr_comment,
164 jr_pj_name,
165 vat,
166 tva_sided,
167 novat,
168 novat+vat-tva_sided as tvac,
169 to_char(jr_date,'DDMMYY') as str_date_short,
170 jr_grpt_id,
171 jrn.currency_id,
172 jrn.currency_rate,
173 jrn.currency_rate_ref,
174 sum_oc_amount,
175 sum_oc_vat_amount,
176 cr_code_iso,
177 coalesce (other_tax_amount,0) other_tax_amount
178 from
179 jrn
180 join row_sale on (qs_internal=jr_internal)
181 join client_detail on (qs_client=f_id)
182 left join row_currency as rc on (rc.j_grpt = jrn.jr_grpt_id)
183 left join currency as c on (c.id=jrn.currency_id)
184 left join other_tax as ot on (ot.j_grpt=jrn.jr_grpt_id)
185 where
186 jr_def_id in ({$ledger_list})
187 {$sql_filter}
188 and {$periode}
189 {$cond_limite}
190 order by jr_date, substring(jr_pj_number,'[0-9]+$')::numeric ";
191 $this->data=$this->db->get_array($sql);
192
193 }
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.
Definition: ac_common.php:682
$sql_filter
Definition: preod.inc.php:43

References $periode, $sql, $sql_filter, 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_Sale::prepare_detail ( )
private

Prepare the query for fetching detail of an operation.

Definition at line 80 of file acc_ledger_history_sale.class.php.

81 {
82
83 if ( $this->db->is_prepare("detail_sale")== FALSE)
84 {
85 $this->db->prepare("detail_sale","
86 with card_name as
87 (select f_id,ad_value as name
88 from fiche_detail where ad_id=1),
89 card_qcode as
90 (select f_id,ad_value as qcode
91 from fiche_detail where ad_id=23)
92 select qs_price,qs_quantite,qs_vat,qs_vat_code,qs_unit,qs_vat_sided,name,qcode,tva_label,
93 qs_price+qs_vat-qs_vat_sided as tvac,
94 oc_amount,
95 oc_vat_amount
96 from
97 quant_sold
98 join jrnx using (j_id)
99 join card_name on (card_name.f_id=qs_fiche)
100 join card_qcode on (card_qcode.f_id=qs_fiche)
101 left join tva_rate on ( qs_vat_code=tva_id)
102 left join operation_currency using (j_id)
103 where
104 qs_internal=$1
105
106 ");
107 }
108 }

References db.

Referenced by export_extended_html().

◆ set_data()

Acc_Ledger_History_Sale::set_data (   $p_data)

Definition at line 266 of file acc_ledger_history_sale.class.php.

267 {
268 $this->data=$p_data;
269 return $this;
270 }

Field Documentation

◆ $data

Acc_Ledger_History_Sale::$data
private

Contains rows from SQL.

Definition at line 34 of file acc_ledger_history_sale.class.php.

Referenced by get_data().


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