package Ernad::Indat::Vypot; use strict; use warnings; use base 'Ernad::Indat'; use Carp qw(confess); use Clone 'clone'; use Data::Dumper; use Ernad::Dates; use Ernad::FileInfo; use Ernad::Indat::Add; use Ernad::Indat::Issue; use Ernad::Indat::Sborn; use Ernad::Store; use Krichel::Shoti; use Ernad::Repis; our $e=$main::e; ## called by vypot_indat sub add { my $i=shift; my $e=$i->{'e'}; my $repcode=shift // $main::repcode; if(not $repcode) { confess "I need an repcode here."; } my $issuedate=shift // $main::issuedate; if(not $issuedate) { confess "I need an issuedate here."; } if(not &Ernad::Dates::is($issuedate)) { confess "You issuedate $issuedate is not a date."; } my $complete_dir=$i->{'dir'}->{'complete'}; my $complete_json="$complete_dir/$issuedate.json"; if(-f $complete_json) { if(not $e->{'testing'}) { confess "Delete $complete_json before You ask me to add an issue of $repcode for $issuedate."; } } my $r=Ernad::Repis->new({'impna'=> $main::impna, 'verbose'=>3}); my $files=[]; $files=$r->get_files($repcode,$issuedate,'array'); if(not $files) { confess "I have no files $repcode at $issuedate."; } if(not scalar @{$files}) { confess "I don't have any files to add for $repcode at $issuedate."; } my $ia=Ernad::Indat::Add->new(); my $do_save=0; foreach my $file (@$files) { $e->echo(__LINE__,"I call Indat::Add->file on $file with do_keep_load."); $do_save+=$ia->file($file,'do_keep_load'); } if($do_save) { $e->echo(__LINE__,"I save."); $ia->save(); } else { $e->echo(__LINE__,"I don't save."); } } sub list { my $i=shift; my $repcode=shift // "I need a recpode here."; my $dir=$i->{'dir'}->{'vypot'}."/$repcode"; my $glob="$dir/*.json"; my $count=0; my $out=[]; foreach my $file (glob($glob)) { $out->[$count++]=$file; } return $out; } sub get { my $i=shift; my $repcode=shift // "I need a recpode here."; my $dir=$i->{'dir'}->{'vypot'}."/$repcode"; my $glob="$dir/*.json"; my $out={}; foreach my $file (glob($glob)) { $out->{$file}=&Ernad::Dates::mshoti($file); } return $out; } sub postpare { my $i=shift; my $issuedate=shift // $main::issuedate // confess "I need an issuedate here."; my $e=$i->{'e'}; $e->echo(__LINE__,"I start with the issue data for $issuedate."); my $ii=Ernad::Indat::Issue->new(); $ii->compile($issuedate); ## Sborn part foreach my $what ('in_labor','complete') { $e->echo(__LINE__,"I do sborn for $what."); my $s=Ernad::Indat::Sborn->new(); $s->compile($what); $s->load($what); $s->to_xml($what); $s->show($what); } } ## this is a function I forgot about. Specific to do that now in vypot_indat ## but it is still used by vypot_indat to do general updates ## This adds to the vypot files. It's not the opposite of what remove does ## It uses find, which is a bit inefficient sub add_old { my $i=shift; my $e=$i->{'e'}; my $repcode=shift // confess "I need a recode here."; ## an optional limitation to an issuedate ## this way to add was keep the json file loaded my $given_issuedate=shift // ''; my @stages=('source/ps', 'source/us','created','filtered', 'ordered', 'selected', 'sent'); my $do_save=0; my $ia=Ernad::Indat::Add->new(); foreach my $stage (@stages) { my $dir=$e->{'dir'}->{'reports'}.'/'.$repcode.'/'.$stage; if(not -d $dir) { next; } foreach my $file (`find $dir -type f`) { chomp $file; if(not $e->{'f'}->is($file)) { $e->echo(__LINE__,"I skip non-rif file $file"); next; } $e->echo(__LINE__,"I look at $file",10); my $issuedate=&Ernad::FileInfo::issuedate($file,'do_strict'); if(not $issuedate) { $e->echo(__LINE__,"I skip the file $file without issuedate",10); next; } if($given_issuedate and not $issuedate eq $given_issuedate) { $e->echo(__LINE__,"I skip the file $file dated $issuedate != to $issuedate.",10); next; } ## check there is a JSON for the namf at least on disk my $namf_json=$i->{'dir'}->{'namf'}."/$issuedate.json"; if(not -f $namf_json) { $e->echo(__LINE__,"I don't see a namf file for the $issuedate, I skip $file"); next; } $e->echo(__LINE__,"I file $file.",2); my $do_keep_load=0; if($given_issuedate) { $do_keep_load=1; } else { $ia->clear(); } $do_save+=$ia->file($file,$do_keep_load); if(not $given_issuedate) { $ia->save(); } } } } 1; 1;