package Ernad::Export; use strict; use warnings; use Carp qw(confess); use Data::Dumper; use Getopt::Std; use List::Util qw(shuffle); use Ernad::Common; use Ernad::Constant; use Ernad::Email; use Ernad::Erimp; use Ernad::Files; use Krichel::File; ## invocation ## &Ernad::Export::public_amf_from_rix($rif,$rix,$repcode,$issuedate,$e); sub public_amf_from_rix { my $rif=shift // confess "I need a rif here."; my $rix=shift; if(not $rix) { $rix= Krichel::File::load($rif); } my $impna; my $e=$main::e // confess "Where is my erimp?"; #if(not $e) { # $impna=&Ernad::Common::find_impna_from_file($rif) # or confess "I can't get the impna from the file $rif"; # $e=Ernad::Erimp->new({'impna'=> $impna, 'verbose'=>1}); #} my $repcode=shift; if(not $repcode) { # $repcode=$e->find_repcode_from_file($rif,$impna) $repcode=$e->{'f'}->repcode($rif) or confess "I can't get the repcode from the file $rif."; } my $issuedate=shift; if(not $issuedate) { $issuedate=$e->{'f'}->issuedate($rif); } my $export_dir=$e->{'dir'}->{'export'} // confess "I need an export dir defined"; my $year=substr($issuedate,0,4); my $out_file_bana="$issuedate.amf.xml"; my $out_file="$export_dir/issues/$repcode/$year/$out_file_bana"; my $export_doc=$e->{'t'}->transform($rix,'public_amf'); &Krichel::File::prepare($out_file); ## save unconditinally $export_doc->toFile($out_file); my $target_file="$out_file.gz"; ## bims-cameni 2018-11-04 problem if(-f $target_file) { $e->echo(__LINE__,"I did not renew $target_file."); return 0; } if(-f $out_file and not -f "$out_file.gz") { system("/bin/gzip -f $out_file"); } $e->echo(__LINE__,"I wrote $target_file."); } 1;