From 51b1978eb8cf2bebeb77df7355571ea404a78393 Mon Sep 17 00:00:00 2001 From: Dany De Bontridder Date: Tue, 23 Jan 2018 22:09:17 +0100 Subject: [PATCH] =?UTF-8?q?Task=20#0001530:=20R=C3=A9=C3=A9criture=20PRINT?= =?UTF-8?q?JRN=20:=20export=20CSV?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/class/acc_ledger.class.php | 7 +- .../acc_ledger_history_generic.class.php | 65 +++- .../class/acc_ledger_history_sale.class.php | 88 ++++++ include/export/export_ledger_csv.php | 298 +++++++++++------- 4 files changed, 337 insertions(+), 121 deletions(-) diff --git a/include/class/acc_ledger.class.php b/include/class/acc_ledger.class.php index 5000ce72b..8e5982b52 100644 --- a/include/class/acc_ledger.class.php +++ b/include/class/acc_ledger.class.php @@ -2629,9 +2629,12 @@ class Acc_Ledger extends jrn_def_sql * * \return an Array with the asked data */ - function get_rowSimple($p_from, $p_to, $trunc=0, $p_limit=-1, $p_offset=-1) + function get_rowSimple($p_from, $p_to, $pa_ledger=[],$trunc=0,$p_limit=-1,$p_offset=-1) { - $alh_generic=new Acc_Ledger_History_Generic($this->db, [$this->id], $p_from, $p_to, "A"); + if ( empty($pa_ledger) ) { + $pa_ledger=[$this->id]; + } + $alh_generic=new Acc_Ledger_History_Generic($this->db, $pa_ledger, $p_from, $p_to, "A"); $alh_generic->get_rowSimple($trunc,$p_limit,$p_offset); $data=$alh_generic->get_data(); return $data; diff --git a/include/class/acc_ledger_history_generic.class.php b/include/class/acc_ledger_history_generic.class.php index 8b8a5ce76..15bd2e664 100644 --- a/include/class/acc_ledger_history_generic.class.php +++ b/include/class/acc_ledger_history_generic.class.php @@ -34,6 +34,7 @@ class Acc_Ledger_History_Generic extends Acc_Ledger_History { private $data; //!< array of rows + /** * Constructor * @param Database $cn @@ -43,6 +44,7 @@ class Acc_Ledger_History_Generic extends Acc_Ledger_History * @param type $p_mode * @example acc_ledger_historyTest.php */ + function __construct(Database $cn, $pa_ledger, $p_from, $p_to, $p_mode) { parent::__construct($cn, $pa_ledger, $p_from, $p_to, $p_mode); @@ -411,7 +413,7 @@ class Acc_Ledger_History_Generic extends Acc_Ledger_History function get_rowSimple($trunc=0, $p_limit=-1, $p_offset=-1) { global $g_user; - $jrn=" jrn_def_id in (".join($this->ma_ledger, ",").")" ; + $jrn=" jrn_def_id in (".join($this->ma_ledger, ",").")"; $periode=sql_filter_per($this->db, $this->m_from, $this->m_to, 'p_id', 'jr_tech_per'); @@ -500,7 +502,8 @@ class Acc_Ledger_History_Generic extends Acc_Ledger_History jr_pj_number, j_qcode, jrn_def_type, - jr_rapt as oc, j_tech_per as periode + jr_rapt as oc, j_tech_per as periode, + j_id from jrnx left join jrn on jr_grpt_id=j_grpt left join tmp_pcmn on pcm_val=j_poste @@ -605,6 +608,7 @@ class Acc_Ledger_History_Generic extends Acc_Ledger_History $this->data=array($array, $tot_deb, $tot_cred); return $Max; } + /** * display in html the detail the list of operation */ @@ -612,6 +616,7 @@ class Acc_Ledger_History_Generic extends Acc_Ledger_History { $this->export_accounting_html(); } + /** * display in html with extended detail the list of operation */ @@ -619,12 +624,13 @@ class Acc_Ledger_History_Generic extends Acc_Ledger_History { $this->export_accounting_html(); } + /** * display in html the accounting of the list of operations */ public function export_accounting_html() { - + $this->get_row(); echo ''; // detailled printing @@ -661,6 +667,7 @@ class Acc_Ledger_History_Generic extends Acc_Ledger_History echo _("solde débiteur:").$this->data[1]."
"; echo _("solde créditeur:").$this->data[2]; } + /** * @brief list operation on one line per operation */ @@ -733,6 +740,7 @@ class Acc_Ledger_History_Generic extends Acc_Ledger_History echo ''; echo "
"; } + /** * To get data * @return array of rows @@ -741,4 +749,55 @@ class Acc_Ledger_History_Generic extends Acc_Ledger_History { return $this->data; } + + /** + * export CSV + */ + function export_csv() + { + $export=new Noalyss_Csv(_('journal')); + $export->send_header(); + + $this->get_row(); + $title=array(); + $title[]=_("operation"); + $title[]=_("N° Pièce"); + $title[]=_("Interne"); + $title[]=_("Date"); + $title[]=_("Poste"); + $title[]=_("QuickCode"); + $title[]=_("Libellé"); + $title[]=_("Débit"); + $title[]=_("Crédit"); + $export->write_header($title); + if (count($this->data)==0) + exit; + $old_id=""; + /** + * @todo add table headers + */ + foreach ($this->data[0] as $idx=>$op) + { + // should clean description : remove tag and '; char + $desc=$op['description']; + $desc=str_replace("", "", $desc); + $desc=str_replace("", "", $desc); + $desc=str_replace("", "", $desc); + $desc=str_replace("", "", $desc); + if ($op['j_id']!="") + $old_id=$op['j_id']; + + $export->add($old_id, "text"); + $export->add($op['jr_pj_number']); + $export->add($op['internal']); + $export->add($op['j_date']); + $export->add($op['poste']); + $export->add($op['j_qcode']); + $export->add($desc); + $export->add($op['deb_montant'], "number"); + $export->add($op['cred_montant'], "number"); + $export->write(); + } + } } + \ No newline at end of file diff --git a/include/class/acc_ledger_history_sale.class.php b/include/class/acc_ledger_history_sale.class.php index d75aa317f..aed349554 100644 --- a/include/class/acc_ledger_history_sale.class.php +++ b/include/class/acc_ledger_history_sale.class.php @@ -224,5 +224,93 @@ class Acc_Ledger_History_Sale extends Acc_Ledger_History { return $this->data; } + /** + * export in csv with detail VAT + */ + function export_csv() + { + $export=new Noalyss_Csv(_('journal')); + $export->send_header(); + + $this->get_row(); + $this->prepare_reconcile_date(); + $this->add_vat_info(); + + $own=new Noalyss_Parameter_Folder($this->db); + $title=array(); + $title[]=_('Date'); + $title[]=_("Paiement"); + $title[]=_("operation"); + $title[]=_("Pièce"); + $title[]=_("Fournisseur"); + $title[]=_("Note"); + $title[]=_("interne"); + $title[]=_("HTVA"); + $title[]=_("TVA"); + $title[]=_("TVA annulée"); + + if ( $own->MY_TVA_USE=='Y') + { + $a_Tva=$this->db->get_array("select tva_id,tva_label from tva_rate order by tva_rate,tva_label,tva_id"); + foreach($a_Tva as $line_tva) + { + $title[]="Tva ".$line_tva['tva_label']; + } + } + $title[]=_("TVAC/TTC"); + $title[]=_("opérations liées"); + $export->write_header($title); + + foreach ($this->data as $line) + { + $export->add($line['jr_date']); + $export->add($line['jr_date_paid']); + $export->add($line['jr_id']); + $export->add($line['jr_pj_number']); + $export->add($line['name']." ". + $line["first_name"]." ". + $line["qcode"]); // qp_supplier + $export->add($line['jr_comment']); + $export->add($line['jr_internal']); + $export->add($line['novat'],"number"); + $export->add($line['vat'],"number"); + $export->add($line['tva_sided'],"number"); + + $a_tva_amount=array(); + //- set all TVA to 0 + foreach ($a_Tva as $l) { + $t_id=$l["tva_id"]; + $a_tva_amount[$t_id]=0; + } + foreach ($line['detail_vat'] as $lineTVA) + { + $idx_tva=$lineTVA['qs_vat_code']; + $a_tva_amount[$idx_tva]=$lineTVA['vat_amount']; + } + if ($own->MY_TVA_USE == 'Y' ) + { + foreach ($a_Tva as $line_tva) + { + $a=$line_tva['tva_id']; + $export->add($a_tva_amount[$a],"number"); + } + } + $export->add($line['tvac'],"number"); + /** + * Retrieve payment if any + */ + $ret_reconcile=$this->db->execute('reconcile_date',array($line['jr_id'])); + $max=Database::num_row($ret_reconcile); + if ($max > 0) { + for ($e=0;$e<$max;$e++) { + $row=Database::fetch_array($ret_reconcile, $e); + $export->add($row['jr_date']); + $export->add($row['jr_internal']); + } + } + $export->write(); + + } + } } diff --git a/include/export/export_ledger_csv.php b/include/export/export_ledger_csv.php index 0c1107aab..36689fbda 100644 --- a/include/export/export_ledger_csv.php +++ b/include/export/export_ledger_csv.php @@ -1,4 +1,5 @@ send_header(); */ try { - $get_jrn=$http->get('jrn_id',"number"); - $get_option=$http->get('p_simple',"string"); - $get_from_periode= $http->get('from_periode'); - $get_to_periode=$http->get('to_periode'); - + $get_jrn=$http->get('jrn_id', "number"); + $get_option=$http->get('p_simple', "string"); + $get_from_periode=$http->get('from_periode', 'number'); + $get_to_periode=$http->get('to_periode', 'number'); } catch (Exception $exc) { @@ -58,7 +64,7 @@ catch (Exception $exc) throw $exc; } -require_once NOALYSS_INCLUDE.'/class/user.class.php'; +require_once NOALYSS_INCLUDE.'/class/user.class.php'; $g_user->Check(); $g_user->check_dossier($gDossier); @@ -66,63 +72,121 @@ $g_user->check_dossier($gDossier); // $get_jrn == 0 when request for all ledger, in that case, we must filter // the legder with the security in Acc_Ledger::get_row //---------------------------------------------------------------------------- -if ($get_jrn!=0 && $g_user->check_jrn($get_jrn) =='X') +if ($get_jrn!=0&&$g_user->check_jrn($get_jrn)=='X') { NoAccess(); exit(); } +global $g_user; +/** + * for all ledgers + */ +if ($get_jrn==0) +{ + // Find periode + $periode=new Periode($cn, $get_from_periode); + $exercice=$periode->get_exercice($get_from_periode); -$Jrn=new Acc_Ledger($cn,$get_jrn); + if ($g_user->Admin()==0&&$g_user->is_local_admin()==0&&$g_user->get_status_security_ledger() + ==1) + { + $sql="select jrn_def_id + from jrn_def join jrn_type on jrn_def_type=jrn_type_id + join user_sec_jrn on uj_jrn_id=jrn_def_id + where + uj_login=$1 + and uj_priv in ('R','W') + order by jrn_def_name + and ( jrn_enable=1 + or + exists (select 1 from jrn where jr_tech_per in (select p_id from parm_periode where p_exercice=$2)) + "; + $a_jrn=$cn->get_array($sql, array($g_user->login, $exercice)); + } + else + { + $a_jrn=$cn->get_array("select jrn_def_id + from jrn_def join jrn_type on jrn_def_type=jrn_type_id + where + jrn_enable=1 or exists(select 1 from jrn where jr_tech_per in (select p_id from parm_periode where p_exercice=$1)) + order by jrn_def_name + ", [$exercice]); + } + $a=[]; + $nb_jrn=count($a_jrn); + for ($i=0;$i< $nb_jrn;$i++){ + $a[]=$a_jrn[$i]['jrn_def_id']; + } + $a_jrn=$a; +} +else +{ + $a_jrn=$Jrn->id; +} +$Jrn=new Acc_Ledger($cn, $get_jrn); $Jrn->get_name(); $jrn_type=$Jrn->get_type(); // // With Detail per item which is possible only for VEN or ACH +// For Detailled VAT for ACH or VEN +// ODS or all ledgers becomes A +// Extended but no FIN becomes L // -if ($get_option == 'D') +if ($get_option=='D'||($jrn_type=='ODS'||$Jrn->id==0)&&$get_option=="E") { - if ($jrn_type != 'ACH' && $jrn_type != 'VEN' || $Jrn->id == 0) + if ($jrn_type=='FIN') { - $get_option = 'A'; + $get_option='L'; + } + elseif ($jrn_type=='ODS'||$Jrn->id==0) + { + $get_option='A'; } else { switch ($jrn_type) { case 'VEN': - $ledger = new Acc_Ledger_Sold($cn, $get_jrn); - $ret_detail = $ledger->get_detail_sale($get_from_periode, $get_to_periode); - $a_heading= Acc_Ledger_Sold::heading_detail_sale(); - + $ledger=new Acc_Ledger_Sold($cn, $get_jrn); + $ret_detail=$ledger->get_detail_sale($get_from_periode, + $get_to_periode); + $a_heading=Acc_Ledger_Sold::heading_detail_sale(); + break; case 'ACH': - $ledger = new Acc_Ledger_Purchase($cn, $get_jrn); - $ret_detail = $ledger->get_detail_purchase($get_from_periode, $get_to_periode); - $a_heading= Acc_Ledger_Purchase::heading_detail_purchase(); + $ledger=new Acc_Ledger_Purchase($cn, $get_jrn); + $ret_detail=$ledger->get_detail_purchase($get_from_periode, + $get_to_periode); + $a_heading=Acc_Ledger_Purchase::heading_detail_purchase(); break; default: - die(__FILE__ . ":" . __LINE__ . 'Journal invalide'); + die(__FILE__.":".__LINE__.'Journal invalide'); break; } - if ($ret_detail == null) + if ($ret_detail==null) return; - $nb = Database::num_row($ret_detail); + $nb=Database::num_row($ret_detail); $title=array(); foreach ($a_heading as $key=> $value) { $title[]=$value; } - for ($i = 0;$i < $nb ; $i++) { + for ($i=0; $i<$nb; $i++) + { $row=Database::fetch_array($ret_detail, $i); - if ( $i == 0 ) { + if ($i==0) + { $export->write_header($title); } $a_row=array(); $type="text"; - for ($j=0;$j < count($row) / 2;$j++) { - if ( $j > 18 ) $type="number"; - $export->add($row[$j],$type); + for ($j=0; $j18) + $type="number"; + $export->add($row[$j], $type); } $export->write(); } @@ -132,47 +196,12 @@ if ($get_option == 'D') // Detailled printing // For miscellaneous legder or all ledgers //----------------------------------------------------------------------------- -if ( $get_option == 'A' ) +if ($get_option=='A') { - $Jrn->get_row( $get_from_periode, $get_to_periode ); - $title=array(); - $title[]=_("operation"); - $title[]=_("N° Pièce"); - $title[]=_("Interne"); - $title[]=_("Date"); - $title[]=_("Poste"); - $title[]=_("QuickCode"); - $title[]=_("Libellé"); - $title[]=_("Débit"); - $title[]=_("Crédit"); - $export->write_header($title); - if ( count($Jrn->row) == 0) - exit; - $old_id=""; - /** - * @todo add table headers - */ - foreach ( $Jrn->row as $op ) - { - // should clean description : remove tag and '; char - $desc=$op['description']; - $desc=str_replace("","",$desc); - $desc=str_replace("","",$desc); - $desc=str_replace("","",$desc); - $desc=str_replace("","",$desc); - if ( $op['j_id'] != "") $old_id=$op['j_id']; - - $export->add($old_id,"text"); - $export->add($op['jr_pj_number']); - $export->add($op['internal']); - $export->add($op['j_date']); - $export->add($op['poste']); - $export->add($op['j_qcode']); - $export->add($desc); - $export->add($op['deb_montant'],"number"); - $export->add($op['cred_montant'],"number"); - $export->write(); - } + + $acc_ledger_history=new Acc_Ledger_History_Generic($cn, $a_jrn, + $get_from_periode, $get_to_periode, 'A'); + $acc_ledger_history->export_csv(); exit; } //----------------------------------------------------------------------------- @@ -180,15 +209,33 @@ if ( $get_option == 'A' ) // for Misc the amount // For Financial only the tiers and the sign of the amount //----------------------------------------------------------------------------- -if ($get_option == "L") +if ($get_option=="L") { - + //----------------------------------------------------- - if ( $jrn_type == 'ODS' || $jrn_type == 'FIN' || $jrn_type=='GL') - { - $Row=$Jrn->get_rowSimple($get_from_periode, - $get_to_periode, - 0); + if ($jrn_type=='ODS'||$jrn_type=='FIN'||$jrn_type=='GL') + { + if ( $get_jrn==0) { + $Row=$Jrn->get_rowSimple($get_from_periode, $get_to_periode, $a_jrn); + }else { + $Row=$Jrn->get_rowSimple($get_from_periode, $get_to_periode); + } + $cn->prepare('reconcile_date_csv', + 'select * + from + jrn + where + jr_id in + (select + jra_concerned + from + jrn_rapt + where jr_id = $1 + union all + select + jr_id + from jrn_rapt + where jra_concerned=$1)'); $title=array(); $title[]=_("operation"); $title[]=_("Date"); @@ -199,50 +246,69 @@ if ($get_option == "L") $title[]=_("internal"); $title[]=_("montant"); $export->write_header($title); - foreach ($Row as $line) - { - $tiers_id=$Jrn->get_tiers_id($line['jrn_def_type'],$line['jr_id']); - $fiche_tiers=new Fiche($cn,$tiers_id); - $tiers=$fiche_tiers->strAttribut(ATTR_DEF_NAME,0)." ".$fiche_tiers->strAttribut(ATTR_DEF_FIRST_NAME,0); - - $export->add( $line['num']); - $export->add($line['date']); - $export->add($line['jr_pj_number']); - $export->add($fiche_tiers->get_quick_code()); - $export->add($tiers); - $export->add($line['comment']); - $export->add($line['jr_internal']); - // echo "".$line['pj'].";"; - // If the ledger is financial : - // the credit must be negative and written in red - // Get the jrn type - if ( $line['jrn_def_type'] == 'FIN' ) { - $positive = $cn->get_value("select qf_amount from quant_fin ". - " where jr_id=$1",array($line['jr_id'])); + foreach ($Row as $line) + { + $tiers_id=$Jrn->get_tiers_id($line['jrn_def_type'], $line['jr_id']); + $fiche_tiers=new Fiche($cn, $tiers_id); + $tiers=$fiche_tiers->strAttribut(ATTR_DEF_NAME, 0)." ".$fiche_tiers->strAttribut(ATTR_DEF_FIRST_NAME, + 0); - $export->add($positive,"number"); - $export->add(""); - } - else - { - $export->add($line['montant'],"number"); - } + $export->add($line['num']); + $export->add($line['date']); + $export->add($line['jr_pj_number']); + $export->add($fiche_tiers->get_quick_code()); + $export->add($tiers); + $export->add($line['comment']); + $export->add($line['jr_internal']); + // echo "".$line['pj'].";"; + // If the ledger is financial : + // the credit must be negative and written in red + // Get the jrn type + if ($line['jrn_def_type']=='FIN') + { + $positive=$cn->get_value("select qf_amount from quant_fin ". + " where jr_id=$1", array($line['jr_id'])); - $export->write(); - } - } + $export->add($positive, "number"); + $export->add(""); + } + else + { + $export->add($line['montant'], "number"); + } + //------ Add reconcilied operation --------------- + $ret_reconcile=$cn->execute('reconcile_date_csv', + array($line['jr_id'])); + $max=Database::num_row($ret_reconcile); + if ($max>0) + { + for ($e=0; $e<$max; $e++) + { + $row=Database::fetch_array($ret_reconcile, $e); + $export->add($row['jr_date']); + $export->add($row['jr_internal']); + $export->add($row['jr_pj_number']); + } + } + $export->write(); + } + } //------------------------------------------------------------------------------ // One line summary with tiers, amount VAT, DNA, tva code .... // //------------------------------------------------------------------------------ - if ( $jrn_type == "ACH") { - $acc_ledger_history=new Acc_Ledger_History_Purchase($cn,[$Jrn->id],$get_from_periode,$get_to_periode,'D'); - $acc_ledger_history->export_csv(); - } - if ( $jrn_type == "VEN") { - $acc_ledger_history=new Acc_Ledger_History_Sale($cn,[$Jrn->id],$get_from_periode,$get_to_periode,'D'); - //@todo to implement $acc_ledger_history->export_csv(); - } + if ($jrn_type=="ACH") + { + $acc_ledger_history=new Acc_Ledger_History_Purchase($cn, [$Jrn->id], + $get_from_periode, $get_to_periode, 'D'); + $acc_ledger_history->export_csv(); + } + if ($jrn_type=="VEN") + { + $acc_ledger_history=new Acc_Ledger_History_Sale($cn, [$Jrn->id], + $get_from_periode, $get_to_periode, 'D'); + $acc_ledger_history->export_csv(); + } } ?>