From 33d3d45ae41c1158dbed3f8cc3bbfcd9224847b6 Mon Sep 17 00:00:00 2001 From: Irina Peshinskaya Date: Tue, 17 Jun 2014 09:22:46 +0300 Subject: [PATCH] MT#5879 Add prevmonth option to ease prev month invoices generation. Additionally to strict stime and etime. --- share/tools/generate_invoices.pl | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/share/tools/generate_invoices.pl b/share/tools/generate_invoices.pl index 5216f6a905..4968906a7b 100644 --- a/share/tools/generate_invoices.pl +++ b/share/tools/generate_invoices.pl @@ -54,22 +54,28 @@ my $dbh = DBI->connect('dbi:mysql:billing;host=localhost', $dbuser, $dbpass) my $opt = {}; -Getopt::Long::GetOptions($opt, 'reseller_id:i@', 'client_contact_id:i@', 'client_contract_id:i@', 'stime:s', 'etime:s', 'send!','sendonly!','resend','regenerate!','help|?') +Getopt::Long::GetOptions($opt, 'reseller_id:i@', 'client_contact_id:i@', 'client_contract_id:i@', 'stime:s', 'etime:s', 'send!','sendonly!','resend','regenerate!','prevmonth','help|?') or die 'could not process command-line options'; print Dumper $opt; -my $stime = $opt->{stime} - ? NGCP::Panel::Utils::DateTime::from_string($opt->{stime}) - : NGCP::Panel::Utils::DateTime::current_local()->truncate( to => 'month' ); -my $etime = $opt->{etime} - ? NGCP::Panel::Utils::DateTime::from_string($opt->{etime}) - : $stime->clone->add( months => 1 )->subtract( seconds => 1 ); +my ($stime,$etime); +if($opt->{prevmonth}){ + $stime = NGCP::Panel::Utils::DateTime::current_local()->truncate( to => 'month' )->subtract(months => 1); + $etime = $stime->clone->add( months => 1 )->subtract( seconds => 1 ); +}else{ + $stime = $opt->{stime} + ? NGCP::Panel::Utils::DateTime::from_string($opt->{stime}) + : NGCP::Panel::Utils::DateTime::current_local()->truncate( to => 'month' ); + $etime = $opt->{etime} + ? NGCP::Panel::Utils::DateTime::from_string($opt->{etime}) + : $stime->clone->add( months => 1 )->subtract( seconds => 1 ); +} if( $opt->{client_contract_id} ){ $opt->{reseller_id} = [$dbh->selectrow_array('select distinct contacts.reseller_id from contracts inner join contacts on contracts.contact_id=contacts.id '.ify(' where contracts.id', @{$opt->{client_contract_id}}), undef, @{$opt->{client_contract_id}} )]; $opt->{client_contact_id} = [$dbh->selectrow_array('select distinct contracts.contact_id from contracts '.ify(' where contracts.id', @{$opt->{client_contract_id}}), undef, @{$opt->{client_contract_id}} )]; } print Dumper $opt; - +print "stime=$stime; etime=$etime;\n"; process_invoices();