noalyss Version-10
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
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
 
 export_csv ()
 export CSV
 
 export_detail_html ()
 display in html the detail the list of operation
 
 export_extended_html ()
 display in html with extended detail the list of operation
 
 export_html ()
 depending on the mode will call the right function
 
 export_oneline_html ()
 list operation on one line per operation
 
 get_data ()
 To get data.
 
 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
 
 get_row ($p_limit=-1, $p_offset=-1)
 set $this->data with the array of rows
 
 get_rowSimple ($trunc=0, $p_limit=-1, $p_offset=-1)
 Get simplified row from ledger.
 
- Public Member Functions inherited from Acc_Ledger_History
 get_filter_operation ()
 Filter operation.
 
 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)
 

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

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>
//@description:History : show different history : detail, list, ...
/**
* @file
* @brief Test of ledger_history show html
*/
require_once NOALYSS_INCLUDE."/class/acc_ledger_history.class.php";
$ledger=[1,2,3,4];
echo Dossier::hidden();
$cn=Dossier::connect();
$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"));
echo '<a href="#n1">Detailled Accounting</a>';
$ledger_history->export_detail_html();
echo h2(_("Set mode to D etailled all_ledgers result = Detailled Accounting from Acc_Ledger_History_Generic" )
,'id="n1"');
echo '<a href="#n2">Sale Listing</a>';
$ledger_history->set_m_mode("D");
$ledger_history->export_html();
echo h1(_("Only VEN from Acc_Ledger_History_Sale"),' id="n2"');
echo '<a href="#n3">Sale Detailed</a>';
$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"),'id="n3"');
echo '<a href="#n4">Sale Extended</a>';
$ledger_history->set_a_ledger([2]);
$ledger_history->set_m_mode("D");
$ledger_history->export_html();
echo h2(_("Only VEN Extended"),'id="n4"');
echo '<a href="#n5">Sale + Purchase</a>';
$ledger_history->set_a_ledger([2]);
$ledger_history->set_m_mode("E");
$ledger_history->export_html();
echo h2("VEN + ACH",'id="n5"');
echo '<a href="#n6">Purchase Detailed</a>';
$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",'id="n6"');
echo '<a href="#n7">Purchase listing</a>';
$ledger_history=new Acc_Ledger_History_Purchase($cn,[3],$max,$min,"A","all");
$ledger_history->export_html();
echo h2("Ach one line",'id="n7"');
echo '<a href="#n8">Purchase Detailed</a>';
$ledger_history->set_m_mode("L");
$ledger_history->export_html();
echo h2("Ach Detail" ,'id="n8"');
echo '<a href="#n9">Purchase Extended</a>';
$ledger_history->set_m_mode("D");
$ledger_history->export_html();
echo h2("Ach Extended" ,'id="n9"');
echo '<a href="#n10">Financial</a>';
$ledger_history->set_m_mode("E");
$ledger_history->export_html();
echo h1("FIN from Acc_Ledger_History_Financial");
echo h2("Detailled accouting",'id="n10"');
echo '<a href="#n11">Financial one line</a>';
$ledger_history=new Acc_Ledger_History_Financial($cn,[11,16],$min,$max,"A","all");
$ledger_history->export_html();
echo h2("FIN one line" ,'id="n11"');
echo '<a href="#n12">Financial Detailed</a>';
$ledger_history->set_m_mode("L");
$ledger_history->export_html();
echo h2(">FIN Detail", 'id="n12"');
echo '<a href="#n13">Financial extended</a>';
$ledger_history->set_m_mode("D");
$ledger_history->export_html();
echo h2("FIN Extended", 'id="n13"');
$ledger_history->set_m_mode("E");
$ledger_history->export_html();
h2($p_string, $p_class="", $raw="")
Definition ac_common.php:68
html_page_start($p_theme="", $p_script="", $p_script2="")
Default page header for each page.
h1($p_string, $p_class="")
Definition ac_common.php:72
global $g_user
if no group available , then stop
_("actif, passif,charge,...")
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.
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 46 of file acc_ledger_history_generic.class.php.

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

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 655 of file acc_ledger_history_generic.class.php.

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

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

640 {
641 $this->export_accounting_html();
642 }
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 647 of file acc_ledger_history_generic.class.php.

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

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 382 of file acc_ledger_history_generic.class.php.

383 {
384 switch ($this->m_mode)
385 {
386 case "E":
387 $this->export_accounting_html();
388 break;
389 case "D":
390 $this->export_accounting_html();
391 break;
392 case "L":
393 $this->export_oneline_html();
394 break;
395 case "A":
396 $this->export_accounting_html();
397 break;
398 default:
399 break;
400 }
401 }
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 699 of file acc_ledger_history_generic.class.php.

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

783 {
784 return $this->data;
785 }
$data
Contains data see acc_ledger_history_financial->get_row.

References Acc_Ledger_History\$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 98 of file acc_ledger_history_generic.class.php.

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

References $a, $a_detail, $c, $code, $fiche, $fiche_def_id, $i, $nb_detail, $p_array, $poste, $r, $sql, $tmp, $x, 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 503 of file acc_ledger_history_generic.class.php.

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

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 414 of file acc_ledger_history_generic.class.php.

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

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:

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