E-INVOICE : export XML if exists from ledger_detail_bottom

This commit is contained in:
sparkyx 2025-09-30 15:48:05 +02:00
parent 497a544433
commit 4c5fa7ebea
4 changed files with 172 additions and 7 deletions

View file

@ -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');

View file

@ -0,0 +1,122 @@
<?php
/*
* This file is part of NOALYSS.
*
* NOALYSS 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 NOALYSS; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
// Copyright Author Dany De Bontridder danydb@aevalys.eu 22/10/23
/**
* @file
* @brief export the XML invoice from JRN.JR_DOCUMENT_XML
*/
if ( ! defined ('ALLOWED')) die (_('Non autorisé'));
$http=new HttpInput();
try
{
$jr_id=$http->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);

View file

@ -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");
?>
<input type="hidden" id="<?=$div?>tab" value="<?=join(",",$tabs)?>">
<ul class="tabs">
<?php foreach ($a_tab as $idx=>$a_value): ?>
<?php
@ -58,7 +73,7 @@ if ( $div != "popup") :
?>
<li class="<?php echo $class?>">
<?php $div_tab_id=$a_value['id'];?>
<a href="javascript:void(0)" onclick="unselect_other_tab(this.parentNode.parentNode);var tab=Array('writing_div<?php echo $div?>','info_operation_div<?php echo $div?>','linked_operation_div<?php echo $div?>','document_operation_div<?php echo $div?>','linked_action_div<?php echo $div?>','analytic_div<?php echo $div?>');this.parentNode.className='tabs_selected' ;show_tabs(tab,'<?php echo $div_tab_id; ?>');"><?php echo _($a_value['label'])?></a>
<a href="javascript:void(0)" onclick="unselect_other_tab(this.parentNode.parentNode);this.parentNode.className='tabs_selected' ;show_tabs($F('<?=$div?>tab').split(','),'<?php echo $div_tab_id; ?>');"><?php echo _($a_value['label'])?></a>
</li>
<?php endforeach; ?>
</ul>
@ -317,7 +332,28 @@ require_once NOALYSS_TEMPLATE.'/ledger_detail_file.php';
</span>
<?php endif;?>
</div>
<?php
//------------------------------------------------
// TAB XML
//------------------------------------------------
if ($obj->det->jr_document_xml != "") {
printf ('<div id="xml_document_div%s"
class="myfieldset" style="display:%s;"
>',$div,$a_tab['xml_document_div']['display']);
$url= "export.php?".http_build_query(
[
"gDossier"=>$gDossier,
"jr_id"=>$jr_id,
"act"=>'RAW:xml-invoice'
]);
printf('<a href="%s">',$url);
print '<i class="icon-download">'
._("XML")
.'</i>';
print '</a>';
echo '</div>';
}?>
<hr>
<?php
echo '<p style="text-align:center">';
@ -408,4 +444,4 @@ echo '</form>';
}else {
echo '</p>';
}
?>

View file

@ -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';
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;