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

manage the list of operation when we need several ledger with a different type or from Misceleaneous ledger More...

+ Inheritance diagram for Acc_Ledger_History_Generic:
+ Collaboration diagram for Acc_Ledger_History_Generic:

Public Member Functions

 __construct (Database $cn, $pa_ledger, $p_from, $p_to, $p_mode)
 
 export_accounting_html ()
 display in html the accounting of the list of operations More...
 
 export_csv ()
 export CSV More...
 
 export_detail_html ()
 display in html the detail the list of operation More...
 
 export_extended_html ()
 display in html with extended detail the list of operation More...
 
 export_html ()
 depending on the mode will call the right function More...
 
 export_oneline_html ()
 list operation on one line per operation More...
 
 get_data ()
 To get data. More...
 
 get_detail (&$p_array, $p_jrn_type, $trunc=0, $a_TVA=null, $a_ParmCode=null)
 get_detail gives the detail of row this array must contains at least the field More...
 
 get_row ($p_limit=-1, $p_offset=-1)
 set $this->data with the array of rows More...
 
 get_rowSimple ($trunc=0, $p_limit=-1, $p_offset=-1)
 Get simplified row from ledger. More...
 
- 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 Attributes

 $data
 array of rows 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

manage the list of operation when we need several ledger with a different type or from Misceleaneous ledger

<?php
/*
* This file is part of NOALYSS.
*
* PhpCompta is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* NOALYSS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PhpCompta; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
// Copyright (2018) Author Dany De Bontridder <dany@alchimerys.be>
/**
* @file
* @brief Test of ledger_history
*/
require_once NOALYSS_INCLUDE."/class/acc_ledger_history.class.php";
$ledger=[1,2,3,4];
$ledger_history=Acc_Ledger_History::factory($cn, $ledger, $min, $max, "E","all");
echo h1("Detailled Accounting");
echo h2(_("export detail html all ledgers result = Detailled Accounting from Acc_Ledger_History_Generic"));
$ledger_history->export_detail_html();
echo h2(_("Set mode to D etailled all_ledgers result = Detailled Accounting from Acc_Ledger_History_Generic" ));
$ledger_history->set_m_mode("D");
$ledger_history->export_html();
echo h1(_("Only VEN from Acc_Ledger_History_Sale"));
$ledger_history=Acc_Ledger_History::factory($cn, [2], $min , $max , "L","all");
$ledger_history->export_detail_html();
echo h2(_("Only VEN one line"));
$ledger_history->set_a_ledger([2]);
$ledger_history->set_m_mode("L");
$ledger_history->export_html();
echo h2(_("Only VEN Detailled"));
$ledger_history->set_a_ledger([2]);
$ledger_history->set_m_mode("D");
$ledger_history->export_html();
echo h2(_("Only VEN Extended"));
$ledger_history->set_a_ledger([2]);
$ledger_history->set_m_mode("E");
$ledger_history->export_html();
echo h2("VEN + ACH");
$ledger_history=Acc_Ledger_History::factory($cn, [3,2], $min, $max , "L","all");
$ledger_history->export_oneline_html();
echo h1("ACH from Acc_Ledger_History_Purchase");
echo h2("Detailled accouting");
$ledger_history=new Acc_Ledger_History_Purchase($cn,[3],$max,$min,"A","all");
$ledger_history->export_html();
echo h2("Ach one line");
$ledger_history->set_m_mode("L");
$ledger_history->export_html();
echo h2("Ach Detail");
$ledger_history->set_m_mode("D");
$ledger_history->export_html();
echo h2("Ach Extended");
$ledger_history->set_m_mode("E");
$ledger_history->export_html();
echo h1("FIN from Acc_Ledger_History_Financial");
echo h2("Detailled accouting");
$ledger_history=new Acc_Ledger_History_Financial($cn,[11,16],$min,$max,"A","all");
$ledger_history->export_html();
echo h2("FIN one line");
$ledger_history->set_m_mode("L");
$ledger_history->export_html();
echo h2(">FIN Detail");
$ledger_history->set_m_mode("D");
$ledger_history->export_html();
echo h2("FIN Extended");
$ledger_history->set_m_mode("E");
$ledger_history->export_html();
h2($p_string, $p_class="", $raw="")
Definition: ac_common.php:68
h1($p_string, $p_class="")
Definition: ac_common.php:72
global $g_user
if no group available , then stop
display financial operations in HTML , PDF or CSV
Display the operations for Purchase.
static factory(Database $cn, $pa_ledger, $p_from, $p_to, $p_mode, $p_paid)
Build the right object.
static hidden()
return a string to set gDossier into a FORM
static connect()
global $g_failed
global $g_succeed

Definition at line 33 of file acc_ledger_history_generic.class.php.

Constructor & Destructor Documentation

◆ __construct()

Acc_Ledger_History_Generic::__construct ( Database  $cn,
  $pa_ledger,
  $p_from,
  $p_to,
  $p_mode 
)
Parameters
Database$cn
array$pa_ledgerarray of jrn_def.jrn_def_id
integer$p_fromperiode
integer$p_to
char$p_modeE D L or A , for Extended ,Detail , Listing , Accounting
Exceptions
Exceptionif $pa_ledger is not an array

Reimplemented from Acc_Ledger_History.

Definition at line 48 of file acc_ledger_history_generic.class.php.

49 {
50 parent::__construct($cn, $pa_ledger, $p_from, $p_to, $p_mode);
51 $this->data=[];
52 $this->ledger_type='ODS';
53 }

References $cn.

Member Function Documentation

◆ export_accounting_html()

Acc_Ledger_History_Generic::export_accounting_html ( )

display in html the accounting of the list of operations

Reimplemented from Acc_Ledger_History.

Definition at line 656 of file acc_ledger_history_generic.class.php.

657 {
658
659 $this->get_row();
660 echo '<TABLE class="result">';
661 // detailled printing
662 //---
663 if ( empty ($this->data)) return;
664 foreach ($this->data[0] as $op)
665 {
666 $class="";
667 if ($op['j_date']!='')
668 {
669 $class="odd";
670 }
671
672 echo "<TR class=\"$class\">";
673
674 echo "<TD>".$op['j_date']."</TD>";
675 echo "<TD >".$op['jr_pj_number']."</TD>";
676
677
678 if ($op['internal']!='')
679 echo "<TD>".HtmlInput::detail_op($op['jr_id'], $op['internal'])."</TD>";
680 else
681 echo td();
682
683 echo "<TD >".$op['poste']."</TD>".
684 "<TD >".$op['description']."</TD>".
685 "<TD style=\"text-align:right\">".nbm($op['deb_montant'])."</TD>".
686 "<TD style=\"text-align:right\">".nbm($op['cred_montant'])."</TD>".
687 "</TR>";
688 }// end loop
689 echo "</table>";
690
691// show the saldo
692//@todo use <li> instead of <br>
693 echo _("solde débiteur:").$this->data[1]."<br>";
694 echo _("solde créditeur:").$this->data[2];
695 }
td($p_string='', $p_extra='')
surround the string with td
Definition: ac_common.php:83
$op
Definition: ajax_admin.php:38
$class
get_row($p_limit=-1, $p_offset=-1)
set $this->data with the array of rows

References $class, $op, get_row(), and td().

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

+ Here is the call graph for this function:

◆ export_csv()

Acc_Ledger_History_Generic::export_csv ( )

export CSV

Definition at line 791 of file acc_ledger_history_generic.class.php.

792 {
793 $export=new Noalyss_Csv(_('journal'));
794 $export->send_header();
795
796 $this->get_row();
797 $title=array();
798 $title[]=_("operation");
799 $title[]=_("N° Pièce");
800 $title[]=_("Interne");
801 $title[]=_("Date");
802 $title[]=_("Poste");
803 $title[]=_("QuickCode");
804 $title[]=_("Libellé");
805 $title[]=_("Débit");
806 $title[]=_("Crédit");
807 $export->write_header($title);
808 if (count($this->data)==0)
809 exit;
810 $old_id="";
811 foreach ($this->data[0] as $idx=>$op)
812 {
813 // should clean description : remove <b><i> tag and '; char
814 $desc=$op['description'];
815 $desc=noalyss_str_replace("<b>", "", $desc);
816 $desc=noalyss_str_replace("</b>", "", $desc);
817 $desc=noalyss_str_replace("<i>", "", $desc);
818 $desc=noalyss_str_replace("</i>", "", $desc);
819 if ($op['j_id']!="")
820 $old_id=$op['j_id'];
821
822 $export->add($old_id, "text");
823 $export->add($op['jr_pj_number']);
824 $export->add($op['internal']);
825 $export->add($op['j_date']);
826 $export->add($op['poste']);
827 $export->add($op['j_qcode']);
828 $export->add($desc);
829 $export->add($op['deb_montant'], "number");
830 $export->add($op['cred_montant'], "number");
831 $export->write();
832 }
833 }
noalyss_str_replace($search, $replace, $string)
Definition: ac_common.php:1553
$idx
Manage the CSV : manage files and write CSV record.
for($e=0; $e< count($afiche); $e++) exit

References $desc, $export, $idx, $op, $title, exit, get_row(), and noalyss_str_replace().

+ Here is the call graph for this function:

◆ export_detail_html()

Acc_Ledger_History_Generic::export_detail_html ( )

display in html the detail the list of operation

Reimplemented from Acc_Ledger_History.

Definition at line 640 of file acc_ledger_history_generic.class.php.

641 {
642 $this->export_accounting_html();
643 }
export_accounting_html()
display in html the accounting of the list of operations

References export_accounting_html().

+ Here is the call graph for this function:

◆ export_extended_html()

Acc_Ledger_History_Generic::export_extended_html ( )

display in html with extended detail the list of operation

Reimplemented from Acc_Ledger_History.

Definition at line 648 of file acc_ledger_history_generic.class.php.

649 {
650 $this->export_accounting_html();
651 }

References export_accounting_html().

+ Here is the call graph for this function:

◆ export_html()

Acc_Ledger_History_Generic::export_html ( )

depending on the mode will call the right function

  • export_oneline_html for one line (mode=L)
  • export_accounting_html for accounting (mode=A,D,E)

Reimplemented from Acc_Ledger_History.

Definition at line 384 of file acc_ledger_history_generic.class.php.

385 {
386 switch ($this->m_mode)
387 {
388 case "E":
389 $this->export_accounting_html();
390 break;
391 case "D":
392 $this->export_accounting_html();
393 break;
394 case "L":
395 $this->export_oneline_html();
396 break;
397 case "A":
398 $this->export_accounting_html();
399 break;
400 default:
401 break;
402 }
403 }
export_oneline_html()
list operation on one line per operation

References export_accounting_html(), and export_oneline_html().

+ Here is the call graph for this function:

◆ export_oneline_html()

Acc_Ledger_History_Generic::export_oneline_html ( )

list operation on one line per operation

Reimplemented from Acc_Ledger_History.

Definition at line 700 of file acc_ledger_history_generic.class.php.

701 {
702 $this->get_rowSimple();
703
704 echo \HtmlInput::filter_table("tb_print_ledger", "0,1,2,3,4,5,6", 1);
705 echo '<TABLE class="result" id="tb_print_ledger">';
706 echo "<TR>".
707 th(_("Date")).
708 th(_("n° pièce")).
709 th(_("internal")).
710 th(_("Tiers")).
711 th(_("Commentaire")).
712 th(_("Devise")).
713 th(_("Total opération")).
714 "</TR>";
715 // set a filter for the FIN
716 $i=0; $tot_amount=0;
717 bcscale(2);
718 foreach ($this->data as $line)
719 {
720 $i++;
721 $class=($i%2==0)?' class="even" ':' class="odd" ';
722 echo "<tr $class>";
723 echo "<TD>".$line['date']."</TD>";
724 echo "<TD>".h($line['jr_pj_number'])."</TD>";
725 echo "<TD>".HtmlInput::detail_op($line['jr_id'],
726 $line['jr_internal'])."</TD>";
727 $tiers=$this->get_tiers($line['jrn_def_type'], $line['jr_id']);
728 echo td($tiers);
729 echo "<TD>".h($line['comment'])."</TD>";
730 if ( $line['currency_id'] != 0) {
731 echo td(bcadd($line['sum_ocamount'],$line['sum_ocvat_amount'])." ".$line['cr_code_iso'],'class="num"');
732 } else {
733 echo td("");
734 }
735
736
737
738 // echo "<TD>".$line['pj']."</TD>";
739 // If the ledger is financial :
740 // the credit must be negative and written in red
741 // Get the jrn type
742 if ($line['jrn_def_type']=='FIN')
743 {
744 $positive=$this->db->get_value("select qf_amount from quant_fin where jr_id=$1",
745 array($line['jr_id']));
746 if ($this->db->count()==0)
747 $positive=1;
748 else
749 $positive=($positive>0)?1:0;
750
751 echo "<TD align=\"right\">";
752 echo ( $positive==0 )?"<font color=\"red\"> - ".nbm($line['montant'])."</font>":nbm($line['montant']);
753 echo "</TD>";
754 if ($positive==1)
755 {
756 $tot_amount=bcadd($tot_amount, $line['montant']);
757 }
758 else
759 {
760 $tot_amount=bcsub($tot_amount, $line['montant']);
761 }
762 }
763 else
764 {
765 echo "<TD align=\"right\">".nbm($line['montant'])."</TD>";
766 $tot_amount=bcadd($tot_amount, $line['montant']);
767 }
768
769 echo "</tr>";
770 }
771 echo '<tr class="highlight">';
772 echo '<td>'._('Totaux').'</td>';
773 echo td().td().td().td().td();
774 echo '<td class="num">'.nbm($tot_amount).'</td>';
775 echo '</tr>';
776 echo "</table>";
777 }
th($p_string, $p_extra='', $raw='')
Definition: ac_common.php:58
nbm($p_number, $p_dec=2)
format the number with a sep.
Definition: ac_common.php:137
get_rowSimple($trunc=0, $p_limit=-1, $p_offset=-1)
Get simplified row from ledger.
get_tiers($p_jrn_type, $jr_id)
Retrieve the third : supplier for purchase, customer for sale, bank for fin,.
$SecUser db

References $class, $i, $line, $tiers, $tot_amount, db, get_rowSimple(), Acc_Ledger_History\get_tiers(), nbm(), td(), and th().

Referenced by export_html().

+ Here is the call graph for this function:

◆ get_data()

Acc_Ledger_History_Generic::get_data ( )

To get data.

Returns
array of rows

Definition at line 783 of file acc_ledger_history_generic.class.php.

784 {
785 return $this->data;
786 }

References $data.

◆ get_detail()

Acc_Ledger_History_Generic::get_detail ( $p_array,
  $p_jrn_type,
  $trunc = 0,
  $a_TVA = null,
  $a_ParmCode = null 
)

get_detail gives the detail of row this array must contains at least the field

  • montant
  • grpt_id

the following field will be added

  • HTVA
  • TVAC
  • TVA array with
    • field 0 idx
    • array containing tva_id,tva_label and tva_amount

@paramp_array the structure is set in get_rowSimple, this array is modified,

jrn.jr_id as jr_id ,
jrn.jr_id as num ,
jrn.jr_def_id as jr_def_id,
jrn.jr_montant as montant,
substr(jrn.jr_comment,1,35) as comment,
to_char(jrn.jr_date,'DD-MM-YYYY') as date,
to_char(jrn.jr_date_paid,'DD-MM-YYYY') as date_paid,
jr_pj_number,
jr_internal,
jrn.jr_grpt_id as grpt_id,
jrn.jr_pj_name as pj,
jrn_def_type,
jrn.jr_tech_per
Parameters
$truncif the data must be truncated, usefull for pdf export @paramp_jrn_type is the type of the ledger (ACH or VEN)
$a_TVATVA Array (default null)
$a_ParmCodeArray (default null)
Todo:
useless since only 2 modes are supported : oneline and extended (accounting writing) but can be used for ledger before 2007
Returns
p_array

Definition at line 100 of file acc_ledger_history_generic.class.php.

102 {
103 bcscale(2);
104
105 if ($a_TVA==null)
106 {
107 //Load TVA array
108 $a_TVA=$this->db->get_array('select tva_id,tva_label,tva_poste
109 from tva_rate where tva_rate != 0 order by tva_rate,tva_label,tva_id');
110 }
111 if ($a_ParmCode==null)
112 {
113 //Load Parm_code
114 $a_ParmCode=$this->db->get_array('select p_code,p_value from parm_code');
115 }
116 // init
117 $p_array['client']="";
118 $p_array['TVAC']=0;
119 $p_array['HTVA']=0;
120 $p_array['TVA']=array();
121 $p_array['AMOUNT_TVA']=0.0;
122 $p_array['dep_priv']=0;
123 $p_array['dna']=0;
124 $p_array['tva_dna']=0;
125 $p_array['tva_np']=0;
126 $dep_priv=0.0;
127
128
129 // if using the QUANT_* tables then get there the needed info
130 //
131 if ($this->use_quant_table($p_array['grpt_id'], $p_array['jrn_def_type'])
132 ==TRUE)
133 {
134 // Initialize amount for VAT
135 $nb_tva=count($a_TVA);
136 for ($i=0; $i<$nb_tva; $i++)
137 {
138 $p_array['TVA'][$i]=array($i,
139 array(
140 $a_TVA[$i]['tva_id'],
141 $a_TVA[$i]['tva_label'],
142 0)
143 );
144 }
145 switch ($p_array['jrn_def_type'])
146 {
147 case "ACH":
148 $sql="select
149 sum(coalesce(qp_price,0)) as htva,
150 sum(coalesce(qp_vat)) as vat,
151 sum(coalesce(qp_nd_tva)) as nd_tva,
152 sum(coalesce(qp_nd_tva_recup)) as nd_tva_recup,
153 sum(coalesce(qp_dep_priv)) as dep_priv,
154 qp_vat_code as tva_code,
155 qp_supplier as fiche_id,
156 qp_vat_sided as tva_sided
157 from
158 quant_purchase
159 where
160 qp_internal=$1
161 group by qp_supplier,qp_vat_code,qp_vat_sided ";
162 break;
163 case "VEN":
164 $sql="select
165 sum(coalesce(qs_price,0)) as htva,
166 sum(coalesce(qs_vat)) as vat,
167 sum(0) as nd_tva,
168 sum(0) as nd_tva_recup,
169 sum(0) as dep_priv,
170 qs_vat_code as tva_code,
171 qs_client as fiche_id,
172 qs_vat_sided as tva_sided
173 from
174 quant_sold
175 where
176 qs_internal=$1
177 group by qs_client,qs_vat_code,qs_vat_sided ";
178 break;
179
180 default:
181 break;
182 }
183 $a_detail=$this->db->get_array($sql, array($p_array['jr_internal']));
184 $nb_detail=count($a_detail);
185 for ($x=0; $x<$nb_detail; $x++)
186 {
187 $p_array['HTVA']=bcadd($p_array['HTVA'], $a_detail[$x]['htva']);
188 $p_array['tva_dna']=bcadd($p_array['tva_dna'],
189 $a_detail[$x]['nd_tva_recup']);
190 $p_array['tva_dna']=bcadd($p_array['tva_dna'],
191 $a_detail[$x]['nd_tva']);
192 $p_array['TVAC']=bcadd($p_array['TVAC'], $a_detail[$x]['htva']);
193 if ($a_detail[$x]['tva_sided']==0)
194 $p_array['TVAC']=bcadd($p_array['TVAC'],
195 $a_detail[$x]['vat']);
196 $p_array['TVAC']=bcadd($p_array['TVAC'], $a_detail[$x]['nd_tva']);
197 $p_array['TVAC']=bcadd($p_array['TVAC'],
198 $a_detail[$x]['nd_tva_recup']);
199 $p_array['dep_priv']=bcadd($p_array['dep_priv'],
200 $a_detail[$x]['dep_priv']);
201 $xdx=$a_detail[$x]['tva_code'];
202 // $p_array['TVA'][$xdx]=bcadd($p_array['TVA'][$xdx],$a_detail[$x]['vat']);
203 //--- Put VAT in the right place in the array $a_TVA
204 $nb_tva=count($a_TVA);
205 for ($j=0; $j<$nb_tva; $j++)
206 {
207 if ($xdx==$p_array['TVA'][$j][1][0])
208 {
209 $p_array['TVA'][$j][1][2]=bcadd($p_array['TVA'][$j][1][2],
210 $a_detail[$x]['vat']);
211 }
212 }
213 }
214 $fiche=new Fiche($this->db, $a_detail[0]['fiche_id']);
215 $p_array['client']=($trunc==0)?$fiche->getName():mb_substr($fiche->getName(),
216 0, 20);
217 return $p_array;
218 }
219 //
220 // Retrieve data from jrnx
221 // Order is important for TVA autoreversed
222 $sql="select j_id,j_poste,j_montant, j_debit,j_qcode from jrnx where ".
223 " j_grpt=$1 order by 1 desc";
224 $Res2=$this->db->exec_sql($sql, array($p_array['grpt_id']));
225 $data_jrnx=Database::fetch_all($Res2);
226 $c=0;
227
228 // Parse data from jrnx and fill diff. field
229 if ( $data_jrnx == FALSE ){
230 $data_jrnx=[];
231 }
232 foreach ($data_jrnx as $code)
233 {
234 $idx_tva=0;
235 $poste=new Acc_Account_Ledger($this->db, $code['j_poste']);
236
237 // if card retrieve name if the account is not a VAT account
238 if (noalyss_strlentrim($code['j_qcode'])!=0&&$poste->isTva()==0)
239 {
240 $fiche=new Fiche($this->db);
241 $fiche->get_by_qcode(trim($code['j_qcode']), false);
242 $fiche_def_id=$fiche->get_fiche_def_ref_id();
243 // Customer or supplier
244 if ($fiche_def_id==FICHE_TYPE_CLIENT||
245 $fiche_def_id==FICHE_TYPE_FOURNISSEUR||$fiche_def_id==FICHE_TYPE_ADM_TAX)
246 {
247 $p_array['TVAC']=$code['j_montant'];
248
249 $p_array['client']=($trunc==0)?$fiche->getName():mb_substr($fiche->getName(),
250 0, 20);
251 $p_array['reversed']=false;
252 if ($fiche_def_id==FICHE_TYPE_CLIENT&&$code['j_debit']=='f')
253 {
254 $p_array['reversed']=true;
255 $p_array['TVAC']*=-1;
256 }
257 if ($fiche_def_id==FICHE_TYPE_ADM_TAX&&$code['j_debit']=='f')
258 {
259 $p_array['reversed']=true;
260 $p_array['TVAC']*=-1;
261 }
262 if ($fiche_def_id==FICHE_TYPE_FOURNISSEUR&&$code['j_debit']=='t')
263 {
264 $p_array['reversed']=true;
265 $p_array['TVAC']*=-1;
266 }
267 }
268 else
269 {
270 // if we use the ledger ven / ach for others card than supplier and customer
271 if ($fiche_def_id!=FICHE_TYPE_VENTE&&
272 $fiche_def_id!=FICHE_TYPE_ACH_MAR&&
273 $fiche_def_id!=FICHE_TYPE_ACH_SER&&
274 $fiche_def_id!=FICHE_TYPE_ACH_MAT
275 )
276 {
277 $p_array['TVAC']=$code['j_montant'];
278
279 $p_array['client']=($trunc==0)?$fiche->getName():mb_substr($fiche->getName(),
280 0, 20);
281 $p_array['reversed']=false;
282 if ($p_jrn_type=='ACH'&&$code['j_debit']=='t')
283 {
284 $p_array['reversed']=true;
285 $p_array['TVAC']*=-1;
286 }
287 if ($p_jrn_type=='VEN'&&$code['j_debit']=='f')
288 {
289 $p_array['reversed']=true;
290 $p_array['TVAC']*=-1;
291 }
292 }
293 }
294 }
295 // if TVA, load amount, tva id and rate in array
296 foreach ($a_TVA as $line_tva)
297 {
298 list($tva_deb, $tva_cred)=explode(',', $line_tva['tva_poste']);
299 if ($code['j_poste']==$tva_deb||
300 $code['j_poste']==$tva_cred)
301 {
302
303 // For the reversed operation
304 if ($p_jrn_type=='ACH'&&$code['j_debit']=='f')
305 {
306 $code['j_montant']=-1*$code['j_montant'];
307 }
308 if ($p_jrn_type=='VEN'&&$code['j_debit']=='t')
309 {
310 $code['j_montant']=-1*$code['j_montant'];
311 }
312
313 $p_array['AMOUNT_TVA']+=$code['j_montant'];
314
315 $p_array['TVA'][$c]=array($idx_tva, array($line_tva['tva_id'],
316 $line_tva['tva_label'], $code['j_montant']));
317 $c++;
318
319 $idx_tva++;
320 }
321 }
322
323 // isDNA
324 // If operation is reversed then amount are negatif
325 /* if ND */
326 if ($p_array['jrn_def_type']=='ACH')
327 {
328 $qp_id=$this->get_value("select qp_id from quant_purchase where j_id=$1",[$code['j_id']]);
329 $purchase=new Quant_Purchase_SQL($this->db,$qp_id);
330
331 $dep_priv=bcadd ($dep_priv,$purchase->qp_dep_priv);
332 $p_array['dep_priv']=$dep_priv;
333 $p_array['dna']=bcadd($p_array['dna'], $purchase->qp_nd_amount);
334 $p_array['tva_dna']=bcadd($p_array['tva_dna'],
335 bcadd($purchase->qp_nd_tva, $purchase->qp_nd_tva_recup));
336 $p_array['tva_np']=bcadd($purchase->qp_vat_sided,
337 $p_array['tva_np']);
338 }
339 if ($p_array['jrn_def_type']=='VEN')
340 {
341 $qs_id=$this->db->get_value("select qs_id from quant_sold where j_id=$1",array($code['j_id']));
342 $sold=new Quant_Sold_SQL($this->db,$qs_id);
343 $p_array['tva_np']=bcadd($sold->qs_vat_sided, $p_array['tva_np']);
344 }
345 }
346 $p_array['TVAC']=sprintf('% 10.2f', $p_array['TVAC']);
347 $p_array['HTVA']=sprintf('% 10.2f',
348 $p_array['TVAC']-$p_array['AMOUNT_TVA']-$p_array['tva_dna']);
349 $r="";
350 $a_tva_amount=array();
351 // inline TVA (used for the PDF)
352 foreach ($p_array['TVA'] as $linetva)
353 {
354 foreach ($a_TVA as $tva)
355 {
356 if ($tva['tva_id']==$linetva[1][0])
357 {
358 $a=$tva['tva_id'];
359 $a_tva_amount[$a]=$linetva[1][2];
360 }
361 }
362 }
363 foreach ($a_TVA as $line_tva)
364 {
365 $a=$line_tva['tva_id'];
366 if (isset($a_tva_amount[$a]))
367 {
368 $tmp=sprintf("% 10.2f", $a_tva_amount[$a]);
369 $r.="$tmp";
370 }
371 else
372 $r.=sprintf("% 10.2f", 0);
373 }
374 $p_array['TVA_INLINE']=$r;
375
376 return $p_array;
377 }
noalyss_strlentrim($p_string)
Definition: ac_common.php:1549
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
$code
Manage the account from the table jrn, jrnx or tmp_pcmn.
static fetch_all($ret)
wrapper for the function pg_fetch_all
define Class fiche and fiche def, those class are using class attribut. When adding or modifing new c...
Definition: fiche.class.php:38
ORM of the table public.quant_purchase.
ORM of the table public.quant_sold.
const FICHE_TYPE_ACH_SER
Definition: constant.php:255
const FICHE_TYPE_ACH_MAR
Definition: constant.php:254
const FICHE_TYPE_VENTE
Definition: constant.php:248
const FICHE_TYPE_ADM_TAX
Definition: constant.php:253
const FICHE_TYPE_CLIENT
Definition: constant.php:247
const FICHE_TYPE_ACH_MAT
Definition: constant.php:256
const FICHE_TYPE_FOURNISSEUR
Definition: constant.php:249

References $a, $a_detail, $code, $fiche, $i, $nb_detail, $p_array, $poste, $r, $sql, $tmp, db, DatabaseCore\fetch_all(), FICHE_TYPE_ACH_MAR, FICHE_TYPE_ACH_MAT, FICHE_TYPE_ACH_SER, FICHE_TYPE_ADM_TAX, FICHE_TYPE_CLIENT, FICHE_TYPE_FOURNISSEUR, FICHE_TYPE_VENTE, and noalyss_strlentrim().

+ Here is the call graph for this function:

◆ get_row()

Acc_Ledger_History_Generic::get_row (   $p_limit = -1,
  $p_offset = -1 
)

set $this->data with the array of rows

Parameters
p_limitstarting line
p_offsetnumber of lines
Returns
nb of rows found

Reimplemented from Acc_Ledger_History.

Definition at line 504 of file acc_ledger_history_generic.class.php.

505 {
506 global $g_user;
507 $periode=sql_filter_per($this->db, $this->m_from, $this->m_to, 'p_id',
508 'jr_tech_per');
509
510 $cond_limite=($p_limit!=-1)?" limit ".$p_limit." offset ".$p_offset:"";
511
512 $ledger_list=join( ",",$this->ma_ledger);
513// Grand livre == 0
514 $Res=$this->db->exec_sql("select jr_id,j_id,j_id as int_j_id,to_char(j_date,'DD.MM.YYYY') as j_date,
515 jr_internal,
516 case j_debit when 't' then j_montant else 0 end as deb_montant,
517 case j_debit when 'f' then j_montant else 0 end as cred_montant,
518 j_debit as debit,j_poste as poste,j_qcode,jr_montant , ".
519 "case when j_text='' or j_text is null then pcm_lib else j_text end as description,j_grpt as grp,
520 jr_comment||' ('||jr_internal||')' as jr_comment,
521 jr_pj_number,
522 j_qcode,
523 jrn_def_type,
524 jr_rapt as oc, j_tech_per as periode,
525 j_id,
526 jrn.currency_id,
527 jrn.currency_rate,
528 jrn.currency_rate_ref,
529 operation_currency.oc_amount,
530 operation_currency.oc_vat_amount
531 from jrnx
532 join jrn on (jr_grpt_id=j_grpt )
533 left join operation_currency using (j_id)
534 left join tmp_pcmn on pcm_val=j_poste
535 join jrn_def on (jrn_def_id=jr_def_id)
536 where j_jrn_def in (".$ledger_list.")
537 and ".$periode."
538 order by j_date::date asc,substring(jr_pj_number,'[0-9]+$')::numeric asc,j_grpt,j_debit desc ".
539 $cond_limite);
540
541 $array=array();
543 if ($Max==0)
544 return array();
545 $case="";
546 $tot_deb=0;
547 $tot_cred=0;
549 bcscale(2);
550 for ($i=0; $i<$Max; $i++)
551 {
552
553 $line=$row[$i];
554 $tot_deb=bcadd($tot_deb, $line['deb_montant']);
555 $tot_cred=bcadd($tot_cred, $line['cred_montant']);
556 $tot_op=$line['jr_montant'];
557
558 /* Check first if there is a quickcode */
559 if (noalyss_strlentrim($line['description'])==0&&noalyss_strlentrim($line['j_qcode'])
560 !=0)
561 {
562 $fiche=new Fiche($this->db);
563 if ($fiche->get_by_qcode($line['j_qcode'], false)==0)
564 {
565 $line['description']=$fiche->strAttribut(ATTR_DEF_NAME);
566 }
567 }
568 if ($case!=$line['grp'])
569 {
570 $case=$line['grp'];
571 // for financial, we show if the amount is or not in negative
572 if ($line['jrn_def_type']=='FIN')
573 {
574 $amount=$this->db->get_value('select qf_amount from quant_fin where jr_id=$1',
575 array($line['jr_id']));
576 /* if nothing is found */
577 if ($this->db->count()==0)
578 $tot_op=$line['jr_montant'];
579 else if ($amount<0)
580 {
581 $tot_op=$amount;
582 }
583 }
584 $array[]=array(
585 'jr_id'=>$line['jr_id'],
586 'int_j_id'=>$line['int_j_id'],
587 'j_id'=>$line['j_id'],
588 'j_date'=>$line['j_date'],
589 'internal'=>$line['jr_internal'],
590 'deb_montant'=>'',
591 'cred_montant'=>' ',
592 'description'=>'<b><i>'.h($line['jr_comment']).' ['.$tot_op.'] </i></b>',
593 'poste'=>$line['oc'],
594 'j_qcode'=>$line['j_qcode'],
595 'periode'=>$line['periode'],
596 'jr_pj_number'=>$line ['jr_pj_number'],
597 "ledger_type"=>$line['jrn_def_type']);
598
599 $array[]=array(
600 'jr_id'=>'',
601 'int_j_id'=>$line['int_j_id'],
602 'j_id'=>'',
603 'j_date'=>'',
604 'internal'=>'',
605 'deb_montant'=>$line['deb_montant'],
606 'cred_montant'=>$line['cred_montant'],
607 'description'=>$line['description'],
608 'poste'=>$line['poste'],
609 'j_qcode'=>$line['j_qcode'],
610 'periode'=>$line['periode'],
611 'jr_pj_number'=>'',
612 "ledger_type"=>$line['jrn_def_type']
613 );
614 }
615 else
616 {
617 $array[]=array(
618 'jr_id'=>$line['jr_id'],
619 'int_j_id'=>$line['int_j_id'],
620 'j_id'=>'',
621 'j_date'=>'',
622 'internal'=>'',
623 'deb_montant'=>$line['deb_montant'],
624 'cred_montant'=>$line['cred_montant'],
625 'description'=>$line['description'],
626 'poste'=>$line['poste'],
627 'j_qcode'=>$line['j_qcode'],
628 'periode'=>$line['periode'],
629 'jr_pj_number'=>'',
630 "ledger_type"=>$line['jrn_def_type']);
631 }
632 }
633 $this->data=array($array, $tot_deb, $tot_cred);
634 return $Max;
635 }
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
h( $row[ 'oa_description'])
static num_row($ret)
wrapper for the function pg_num_rows
const ATTR_DEF_NAME
Definition: constant.php:216
$Res

References $amount, $array, $fiche, $g_user, $i, $line, $Max, $periode, $Res, $row, $tot_cred, $tot_deb, ATTR_DEF_NAME, db, DatabaseCore\fetch_all(), h, noalyss_strlentrim(), DatabaseCore\num_row(), and sql_filter_per().

Referenced by export_accounting_html(), and export_csv().

+ Here is the call graph for this function:

◆ get_rowSimple()

Acc_Ledger_History_Generic::get_rowSimple (   $trunc = 0,
  $p_limit = -1,
  $p_offset = -1 
)

Get simplified row from ledger.

Parameters
p_fromperiode
p_toperiode
p_limitstarting line
p_offsetnumber of lines
truncif data must be truncated (pdf export)
Todo:
Prévoir aussi les journaux sans tables quant < 2007
Returns
numbe of rows found

Definition at line 416 of file acc_ledger_history_generic.class.php.

417 {
418 global $g_user;
419 $jrn=" jrn_def_id in (".join(',',$this->ma_ledger).")";
420
421 $periode=sql_filter_per($this->db, $this->m_from, $this->m_to, 'p_id',
422 'jr_tech_per');
423
424 $cond_limite=($p_limit!=-1)?" limit ".$p_limit." offset ".$p_offset:"";
425 //---
426 $sql="
427 SELECT jrn.jr_id as jr_id ,
428 jrn.jr_id as num ,
429 jrn.jr_def_id as jr_def_id,
430 jrn.jr_montant as montant,
431 substr(jrn.jr_comment,1,35) as comment,
432 to_char(jrn.jr_date,'DD-MM-YYYY') as date,
433 to_char(jrn.jr_date_paid,'DD-MM-YYYY') as date_paid,
434 jr_pj_number,
435 jr_internal,
436 jrn.jr_grpt_id as grpt_id,
437 jrn.jr_pj_name as pj,
438 jrn_def_type,
439 jrn.jr_tech_per,
440 jrn.currency_id,
441 jrn.currency_rate,
442 jrn.currency_rate_ref,
443 currency.cr_code_iso,
444 coalesce(sum_ocamount,0) as sum_ocamount,
445 coalesce(sum_ocvat_amount,0) as sum_ocvat_amount
446 FROM jrn join jrn_def on (jrn_def_id=jr_def_id)
447 join currency on (currency.id=jrn.currency_id)
448 left join (
449 select jrn2.jr_id , sum(coalesce(oc_amount,0)) as sum_ocamount,sum(coalesce(oc_vat_amount,0)) as sum_ocvat_amount
450 from operation_currency
451 join jrnx using (j_id)
452 join jrn as jrn2 on (j_grpt=jrn2.jr_grpt_Id)
453 where
454 j_id in (select j_id from jrnx where j_grpt=jrn2.jr_grpt_id)
455 group by jr_id
456 ) as OC1 using (jr_id)
457 WHERE $periode and $jrn order by jr_date,substring(jrn.jr_pj_number,'[0-9]+$')::numeric asc $cond_limite";
458 $Res=$this->db->exec_sql($sql);
460 if ($Max==0)
461 {
462 return 0;
463 }
464// @todo Pas nécessaire puisqu'on ne traite que les journaux d'opération diverses,
465// Il faudrait p-e prévoir un système pour les journaux avant 2007 qui n'utilisaient
466// pas les tables quant
467//
468// $type=$this->get_type();
469// // for type ACH and Ven we take more info
470// if ($type=='ACH'||$type=='VEN')
471// {
472// $a_ParmCode=$this->db->get_array('select p_code,p_value from parm_code');
473// $a_TVA=$this->db->get_array('select tva_id,tva_label,tva_poste
474// from tva_rate where tva_rate != 0 order by tva_rate,tva_label,tva_id ');
475// for ($i=0; $i<$Max; $i++)
476// {
477// $array[$i]=Database::fetch_array($Res, $i);
478// $p=$this->get_detail($array[$i], $type, $trunc, $a_TVA,
479// $a_ParmCode);
480// if ($array[$i]['dep_priv']!=0.0)
481// {
482// $array[$i]['comment'].="(priv. ".$array[$i]['dep_priv'].")";
483// }
484// }
485// }
486// else
487// {
489// }
490
491 $this->data=$array;
492 return $Max;
493 }

References $array, $g_user, $jrn, $Max, $periode, $Res, $sql, db, DatabaseCore\fetch_all(), DatabaseCore\num_row(), and sql_filter_per().

Referenced by export_oneline_html().

+ Here is the call graph for this function:

Field Documentation

◆ $data

Acc_Ledger_History_Generic::$data
private

array of rows

Definition at line 36 of file acc_ledger_history_generic.class.php.

Referenced by get_data().


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