From 569fbfa8f4733b87a49f740e6dd819c9627cf0ff Mon Sep 17 00:00:00 2001 From: sparkyx Date: Fri, 20 Jun 2025 10:34:19 +0200 Subject: [PATCH] STOCK : improve export CSV STOCK_HISTO --- include/class/stock.class.php | 45 ++++++++++++++--------- include/export/export_stock_histo_csv.php | 12 +++++- 2 files changed, 39 insertions(+), 18 deletions(-) diff --git a/include/class/stock.class.php b/include/class/stock.class.php index 2d8ac6530..e46b1637a 100644 --- a/include/class/stock.class.php +++ b/include/class/stock.class.php @@ -162,27 +162,38 @@ class Stock extends Stock_Sql global $cn,$g_user; $profile=$g_user->get_profile(); $sql = " - select sg_id, - sg.f_id, - (select ad_value from fiche_Detail as fd1 where ad_id=1 and fd1.f_id=jx.f_id) as fname, - (select ad_value from fiche_Detail as fd1 where ad_id=23 and fd1.f_id=jx.f_id) as qcode, - sg_code, - coalesce(sg_comment,jr_comment) as ccomment, - sg_exercice, - r_name, - sg.r_id, - j_montant, - jr_date, - sg_quantity, - case when sg_type='c' then 'OUT' when sg_type='d' then 'IN' end as direction, - jr_internal, - jr_id, - coalesce(sg_date,jr_date) as real_date, - to_char(coalesce(sg_date,jr_date),'DD.MM.YY') as cdate + with tiers_id as ( + select qp_supplier as f_tiers, j_id + from quant_purchase + union all + select qs_client , j_id + from quant_sold) + select sg_id, + sg.f_id, + (select ad_value from fiche_Detail as fd1 where ad_id=1 and fd1.f_id=jx.f_id) as fname, + (select ad_value from fiche_Detail as fd1 where ad_id=23 and fd1.f_id=jx.f_id) as qcode, + (select ad_value from fiche_Detail as fd3 where fd3.ad_id=1 and fd3.f_id=tier1.f_tiers) as fname_tiers, + (select ad_value from fiche_Detail as fd4 where fd4.ad_id=23 and fd4.f_id=tier1.f_tiers) as qcode_tiers, + sg_code, + coalesce(sg_comment,jr_comment) as ccomment, + sg_exercice, + r_name, + sg.r_id, + j_montant, + jr_date, + sg_quantity, + case when sg_type='c' then 'OUT' when sg_type='d' then 'IN' end as direction, + jr_internal, + jr_id, + coalesce(sg_date,jr_date) as real_date, + to_char(coalesce(sg_date,jr_date),'DD.MM.YY') as cdate, + tier1.f_tiers, + j.jr_pj_number from stock_goods as sg join stock_repository as sr on (sg.r_id=sr.r_id) left join jrnx as jx on (sg.j_id=jx.j_id) left join jrn as j on (j.jr_grpt_id=jx.j_grpt) + left join tiers_id as tier1 on (tier1.j_id=sg.j_id) where sg.r_id in (select r_id from profile_sec_repository where p_id = $profile)"; $and = " and "; diff --git a/include/export/export_stock_histo_csv.php b/include/export/export_stock_histo_csv.php index 5e6dc64e4..16066b8e6 100644 --- a/include/export/export_stock_histo_csv.php +++ b/include/export/export_stock_histo_csv.php @@ -36,23 +36,33 @@ $max_row=Database::num_row($res); $export->send_header(); $export->write_header(array(_("Date"), + _("N° pièce"), _('Code Stock'), _('Depot'), - _('Fiche'), + _('Code Stock'), + _('Nom Stock'), + _("Code Tiers"), + _("Nom Tiers"), _('Commentaire'), _('Quantité'), + _('Prix unitaire'), _('IN/OUT'))); for ($i=0;$i<$max_row;$i++) { $row=Database::fetch_array($res,$i); $export->add($row['cdate']); + $export->add($row['jr_pj_number']); $export->add($row['sg_code']); $export->add($row['r_name']); $export->add($row['qcode']); + $export->add($row['fname']); + $export->add($row['qcode_tiers']); + $export->add($row['fname_tiers']); $row['ccomment']=noalyss_str_replace('"','',$row['ccomment']); $export->add($row['ccomment']); $export->add($row['sg_quantity'],"number"); + $export->add($row['j_montant'],"number"); $export->add($row['direction']); $export->write();