From 4c5fa7ebeaff7bb92b182ec77bc598c5c01fa427 Mon Sep 17 00:00:00 2001 From: sparkyx Date: Tue, 30 Sep 2025 15:48:05 +0200 Subject: [PATCH] E-INVOICE : export XML if exists from ledger_detail_bottom --- include/class/acc_operation.class.php | 1 + include/export/export_xml-invoice.php | 122 ++++++++++++++++++++++ include/template/ledger_detail_bottom.php | 46 +++++++- sql/upgrade.sql | 10 +- 4 files changed, 172 insertions(+), 7 deletions(-) create mode 100644 include/export/export_xml-invoice.php diff --git a/include/class/acc_operation.class.php b/include/class/acc_operation.class.php index b8ba94391..e4175573b 100644 --- a/include/class/acc_operation.class.php +++ b/include/class/acc_operation.class.php @@ -1109,6 +1109,7 @@ class Acc_Detail extends Acc_Operation ,currency_id ,currency_rate ,currency_rate_ref + ,jr_document_xml FROM jrn where jr_id=$1"; $array=$this->db->get_array($sql,array($this->jr_id)); if ( count($array) == 0 ) throw new Exception('Aucune ligne trouvée'); diff --git a/include/export/export_xml-invoice.php b/include/export/export_xml-invoice.php new file mode 100644 index 000000000..b02ac65f3 --- /dev/null +++ b/include/export/export_xml-invoice.php @@ -0,0 +1,122 @@ +get('jr_id',"number"); +} +catch (Exception $exc) +{ + record_log($exc); + return; +} + +$cn=Dossier::connect(); + +$r=$cn->exec_sql("select jr_def_id from jrn where jr_id=$1",array($jr_id)); + +if ( Database::num_row($r) == 0 ) +{ + echo_error("Invalid operation id jr_id=$jr_id"); + exit; +} +$a=Database::fetch_array($r,0); +$jrn=$a['jr_def_id']; +global $g_user; +if ($g_user->check_jrn($jrn) == 'X' ) +{ + /* Cannot Access */ + NoAccess(); + exit -1; +} + +$ret=$cn->exec_sql("select jr_pj_name,jr_pj_number ,jr_document_xml from jrn where jr_id=$1", + array($jr_id)); + +if ( Database::num_row ($ret) == 0 ) + return; + +$row=Database::fetch_array($ret,0); + +if ( $row['jr_document_xml']==null ) +{ + ini_set('zlib.output_compression','Off'); + header("Pragma: public"); + header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); + header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); + header("Cache-Control: must-revalidate"); + header('Content-type: '.'text/plain'); + header('Content-Disposition: attachment;filename=vide.txt',FALSE); + header("Accept-Ranges: bytes"); + echo "******************"; + echo _("Fichier effacé"); + echo "******************"; + exit(); +} +$tmp=tempnam($_ENV['TMP'],'document_'); + +$new_name=$row['jr_pj_name']; +$receipt_number=clean_filename($row['jr_pj_number']); +$receipt_number=noalyss_str_replace('.','-',$receipt_number); +if ( ! empty($receipt_number) && strpos($new_name,$receipt_number) === false ) { + + $new_name=$receipt_number.'-'.$new_name; +} +// replace extension by xml (normally a PDF) +//@var $pos_ext (int) where is the last dot +$pos_ext=strrpos($new_name,'.'); +if ( $pos_ext == 0) +{ + // there is no extension + $new_name.='.xml'; +}else { + $new_name=substr_replace($new_name,'.xml',$pos_ext); +} +$cn->start(); + +$cn->lo_export($row['jr_document_xml'],$tmp); +$cn->commit(); + +ini_set('zlib.output_compression','Off'); +header("Pragma: public"); +header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); +header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); +header("Cache-Control: must-revalidate"); +header('Content-type: application/xml'); +header('Content-Disposition: attachment;filename="'.$new_name.'"',FALSE); +header("Accept-Ranges: bytes"); + +$file=fopen($tmp,'r'); +while ( !feof ($file) ) + echo fread($file,8192); + +fclose($file); + +unlink ($tmp); diff --git a/include/template/ledger_detail_bottom.php b/include/template/ledger_detail_bottom.php index 3cd985c44..afd7307d8 100644 --- a/include/template/ledger_detail_bottom.php +++ b/include/template/ledger_detail_bottom.php @@ -9,7 +9,7 @@ * @brief show the common parts of operation details * * Variables : $div = popup or box (det[0-9] - * + *@var $obj = Acc_Operation */ bcscale(2); \Noalyss\Dbg::echo_file(__FILE__); @@ -44,13 +44,28 @@ $a_tab['linked_operation_div']=array('id'=>'linked_operation_div'.$div,'label'=> $a_tab['document_operation_div']=array('id'=>'document_operation_div'.$div,'label'=>_('Document').'('.$nb_document.')','display'=>'block'); $a_tab['linked_action_div']=array('id'=>'linked_action_div'.$div,'label'=>_('Actions Gestion').'('.count($a_followup).')','display'=>'none'); $a_tab['analytic_div']=array('id'=>'analytic_div'.$div,'label'=>_('Comptabilité Analytique'),'display'=>'none'); - +//var $g_parameter \Noalyss_Parameter_Folder +global $g_parameter; +// if using the XML Belgian format, add a tab for showing it +if ($obj->det->jr_document_xml != "") +{ + $a_tab['xml_document_div']= + [ + "id"=>"xml_document_div".$div + , "label"=>_("XML - UBL21") + , "display"=>'none' + ]; + +} // show tabs if ( $div != "popup") : $a_tab['document_operation_div']['display']='block'; + $tabs=array_column($a_tab,"id"); + ?> +"> @@ -317,7 +332,28 @@ require_once NOALYSS_TEMPLATE.'/ledger_detail_file.php'; - +det->jr_document_xml != "") { + printf ('
',$div,$a_tab['xml_document_div']['display']); + $url= "export.php?".http_build_query( + [ + "gDossier"=>$gDossier, + "jr_id"=>$jr_id, + "act"=>'RAW:xml-invoice' + ]); + printf('',$url); + print '' + ._("XML") + .''; + print ''; + + echo '
'; +}?>
'; @@ -408,4 +444,4 @@ echo ''; }else { echo '

'; } -?> + diff --git a/sql/upgrade.sql b/sql/upgrade.sql index 07909a1b4..1c58add80 100644 --- a/sql/upgrade.sql +++ b/sql/upgrade.sql @@ -295,8 +295,14 @@ insert into "parameter" values ('MY_INVOICE_FORMAT','BASIC'); alter table jrn add jr_document_xml oid; -comment on column jrn.jr_document_xml is 'OID of the XML files (e-invoice)'; +comment on column jrn.jr_document_xml is 'OID of the XML files (e-invoice) used only for XML'; create sequence seq_doc_type_stdinv; -comment on sequence seq_doc_type_stdinv is 'Sequence for standard invoice'; \ No newline at end of file +comment on sequence seq_doc_type_stdinv is 'Sequence for standard invoice'; + + +INSERT INTO public.menu_ref (me_code, me_menu, me_file, me_url, me_description, me_parameter, me_javascript, me_type, me_description_etendue) +VALUES('RAW:xml-invoice', 'Exporte la facture XML', 'export_xml-invoice.php', NULL, 'export la facture électronique en XML', NULL, NULL, 'PR', NULL); + +insert into profile_menu (me_code,p_id, p_type_display) select 'RAW:xml-invoice',p_id,'P' from profile; \ No newline at end of file