X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FController%2FCustomerVendorTurnover.pm;h=b0a7c655235d8a7d190bb7040b49bec3bb9e77c0;hb=e19609317e221f6b10cbe18a70b215d744736388;hp=bd327daa44be15863eb3135f28ccbd190716a96c;hpb=c092c963921436b418f42ed73bece53878a61bf0;p=kivitendo-erp.git diff --git a/SL/Controller/CustomerVendorTurnover.pm b/SL/Controller/CustomerVendorTurnover.pm index bd327daa4..b0a7c6552 100644 --- a/SL/Controller/CustomerVendorTurnover.pm +++ b/SL/Controller/CustomerVendorTurnover.pm @@ -4,6 +4,9 @@ use parent qw(SL::Controller::Base); use SL::DBUtils; use SL::DB::AccTransaction; use SL::DB::Invoice; +use SL::DB::Order; +use SL::DB::EmailJournal; +use SL::DB::Letter; use SL::DB; __PACKAGE__->run_before('check_auth'); @@ -15,18 +18,34 @@ sub action_list_turnover { my $cv = $::form->{id} || {}; my $open_invoices; + if ( $::form->{db} eq 'customer' ) { $open_invoices = SL::DB::Manager::Invoice->get_all( query => [customer_id => $cv, - paid => {lt_sql => 'amount'}, + or => [ + amount => { gt => \'paid'}, + amount => { lt => \'paid'}, + ], ], with_objects => ['dunnings'], ); + } else { + $open_invoices = SL::DB::Manager::PurchaseInvoice->get_all( + query => [ vendor_id => $cv, + or => [ + amount => { gt => \'paid'}, + amount => { lt => \'paid'}, + ], + ], + sort_by => 'invnumber DESC', + ); + } my $open_items; if (@{$open_invoices}) { return $self->render(\'', { type => 'json' }) unless scalar @{$open_invoices}; $open_items = $self->_list_open_items($open_invoices); } - return $self->render('customer_vendor_turnover/turnover', { header => 0 }, open_items => $open_items, id => $cv); + my $open_orders = $self->_get_open_orders(); + return $self->render('customer_vendor_turnover/turnover', { header => 0 }, open_orders => $open_orders, open_items => $open_items, id => $cv); } sub _list_open_items { @@ -39,7 +58,7 @@ sub action_count_open_items_by_year { my ($self) = @_; return $self->render('generic/error', { layout => 0 }, label_error => "list_transactions needs a trans_id") unless $::form->{id}; - my $dbh = SL::DB->client->dbh() + my $dbh = SL::DB->client->dbh; my $cv = $::form->{id} || {}; @@ -58,12 +77,13 @@ sub action_count_open_items_by_year { $self->{dun_statistic} = selectall_hashref_query($::form, $dbh, $query); $self->render('customer_vendor_turnover/count_open_items_by_year', { layout => 0 }); } + sub action_count_open_items_by_month { my ($self) = @_; return $self->render('generic/error', { layout => 0 }, label_error => "list_transactions needs a trans_id") unless $::form->{id}; - my $dbh = SL::DB->client->dbh() + my $dbh = SL::DB->client->dbh; my $cv = $::form->{id} || {}; @@ -82,58 +102,296 @@ sub action_count_open_items_by_month { $self->{dun_statistic} = selectall_hashref_query($::form, $dbh, $query); $self->render('customer_vendor_turnover/count_open_items_by_year', { layout => 0 }); } + sub action_turnover_by_month { my ($self) = @_; return $self->render('generic/error', { layout => 0 }, label_error => "list_transactions needs a trans_id") unless $::form->{id}; - my $dbh = SL::DB->client->dbh() + my $dbh = SL::DB->client->dbh; my $cv = $::form->{id} || {}; - my $query = "SELECT CONCAT(EXTRACT (MONTH FROM transdate),'/',EXTRACT (YEAR FROM transdate)) AS date_part, + my ($db, $cv_type); + if ($::form->{db} eq 'customer') { + $db = "ar"; + $cv_type = "customer_id"; + } else { + $db = "ap"; + $cv_type = "vendor_id"; + } + my $query = <{turnover_statistic} = selectall_hashref_query($::form, $dbh, $query); $self->render('customer_vendor_turnover/count_turnover', { layout => 0 }); } -sub action_turnover_by_year { +sub action_turnover_by_year { my ($self) = @_; return $self->render('generic/error', { layout => 0 }, label_error => "list_transactions needs a trans_id") unless $::form->{id}; - my $dbh = SL::DB->client->dbh() + my $dbh = SL::DB->client->dbh; my $cv = $::form->{id} || {}; - my $query = "SELECT EXTRACT (YEAR FROM transdate) as date_part, + my ($db, $cv_type); + if ($::form->{db} eq 'customer') { + $db = "ar"; + $cv_type = "customer_id"; + } else { + $db = "ap"; + $cv_type = "vendor_id"; + } + my $query = <{turnover_statistic} = selectall_hashref_query($::form, $dbh, $query); $self->render('customer_vendor_turnover/count_turnover', { layout => 0 }); } + sub action_get_invoices { my ($self) = @_; return $self->render('generic/error', { layout => 0 }, label_error => "list_transactions needs a trans_id") unless $::form->{id}; my $cv = $::form->{id} || {}; - my $invoices = SL::DB::Manager::Invoice->get_all( - query => [ customer_id => $cv, ], - sort_by => 'invnumber DESC', - ); + my $invoices; + if ( $::form->{db} eq 'customer' ) { + $invoices = SL::DB::Manager::Invoice->get_all( + query => [ customer_id => $cv, ], + sort_by => 'invnumber DESC', + ); + } else { + $invoices = SL::DB::Manager::PurchaseInvoice->get_all( + query => [ vendor_id => $cv, ], + sort_by => 'invnumber DESC', + ); + } $self->render('customer_vendor_turnover/invoices_statistic', { layout => 0 }, invoices => $invoices); } + +sub action_get_orders { + my ($self) = @_; + + return $self->render('generic/error', { layout => 0 }, label_error => "list_transactions needs a trans_id") unless $::form->{id}; + + my $cv = $::form->{id} || {}; + my $orders; + my $type = $::form->{type}; + if ( $::form->{db} eq 'customer' ) { + $orders = SL::DB::Manager::Order->get_all( + query => [ customer_id => $cv, + quotation => ($type eq 'quotation' ? 'T' : 'F') ], + sort_by => ( $type eq 'order' ? 'ordnumber DESC' : 'quonumber DESC'), + ); + } else { + $orders = SL::DB::Manager::Order->get_all( + query => [ vendor_id => $cv, + quotation => ($type eq 'quotation' ? 'T' : 'F') ], + sort_by => ( $type eq 'order' ? 'ordnumber DESC' : 'quonumber DESC'), + ); + } + if ( $type eq 'order') { + $self->render('customer_vendor_turnover/order_statistic', { layout => 0 }, orders => $orders); + } else { + $self->render('customer_vendor_turnover/quotation_statistic', { layout => 0 }, orders => $orders); + } +} + +sub _get_open_orders { + my ( $self ) = @_; + + return $self->render('generic/error', { layout => 0 }, label_error => "list_transactions needs a trans_id") unless $::form->{id}; + my $open_orders; + my $cv = $::form->{id} || {}; + + if ( $::form->{db} eq 'customer' ) { + $open_orders = SL::DB::Manager::Order->get_all( + query => [ customer_id => $cv, + closed => 'F', + ], + sort_by => 'ordnumber DESC', + ); + } else { + $open_orders = SL::DB::Manager::Order->get_all( + query => [ vendor_id => $cv, + closed => 'F', + ], + sort_by => 'ordnumber DESC', + ); + } + + return 0 unless scalar @{$open_orders}; + return $self->render('customer_vendor_turnover/_list_open_orders', { output => 0 }, orders => $open_orders, title => $::locale->text('Open Orders') ); +} + +sub action_get_mails { + my ( $self ) = @_; + + my $dbh = SL::DB->client->dbh; + my $query; + my $cv = $::form->{id}; + + if ( $::form->{db} eq 'customer') { + $query = <render('customer_vendor_turnover/email_statistic', { layout => 0 }, emails => $emails); +} + +sub action_get_letters { + my ($self) = @_; + + return $self->render('generic/error', { layout => 0 }, label_error => "list_transactions needs a trans_id") unless $::form->{id}; + + my $cv = $::form->{id} || {}; + my $letters; + my $type = $::form->{type}; + if ( $::form->{db} eq 'customer' ) { + $letters = SL::DB::Manager::Letter->get_all( + query => [ customer_id => $cv, ], + sort_by => 'date DESC', + ); + } else { + $letters = SL::DB::Manager::Letter->get_all( + query => [ vendor_id => $cv, ], + sort_by => 'date DESC', + ); + } + $self->render('customer_vendor_turnover/letter_statistic', { layout => 0 }, letters => $letters); +} + sub _list_articles_by_invoice { } sub _list_count_articles_by_year { @@ -142,3 +400,85 @@ sub check_auth { $::auth->assert('general_ledger'); } 1; + +__END__ + +=encoding utf-8 + +=head1 NAME + +SL::Controller::CustomerVendorTurnover + +=head1 DESCRIPTION + +Gets all kinds of records like orders, request orders, quotations, invoices, emails, letters + +wich belong to customer/vendor and displays them in an extra tab "Records". + +=back + +=head1 URL ACTIONS + +=over 4 + +=item C + +Basic action wich displays open invoices and open orders if there are any and shows the tab menu for the other actions + +=item C + +gets and shows a dunning statistic of the customer by month + +=item C + +gets and shows a dunning statistic of the customer by year + +=item C + +gets and shows an invoice statistic of customer/vendor by month + +=item C + +gets and shows an invoice statistic of customer/vendor by year + +=item C + +get and shows all invoices from the customer/vendor in an extra tab + +=item C + +get and shows all orders from the customer/vendor in an extra tab + +=item C + +get and shows all letters from the customer/vendor in an extra tab + +=item C + +get and shows all mails from the customer/vendor in an extra tab + +=back + +=head1 Functions + +=over 4 + +=item C<_get_open_orders> + +retrieves the open orders for customer/vendor to display them + +=item C<_list_open_items> + +retrieves open invoices with their dunnings to display them + +=back + +=head1 BUGS + +None yet. :) + +=head1 AUTHOR + +W. Hahn Ewh@futureworldsearch.netE + +=back