use SL::DBUtils;
use SL::DB::AccTransaction;
use SL::DB::Invoice;
+use SL::DB::Order;
use SL::DB;
__PACKAGE__->run_before('check_auth');
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 {
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 ($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} || {};
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 = <<SQL;
+SELECT CONCAT(EXTRACT (MONTH FROM transdate),'/',EXTRACT (YEAR FROM transdate)) AS date_part,
count(id) as count,
sum(amount) as amount,
sum(netamount) as netamount,
sum(paid) as paid
- FROM ar WHERE customer_id = $cv
+ FROM $db WHERE $cv_type = $cv
GROUP BY EXTRACT (YEAR FROM transdate), EXTRACT (MONTH FROM transdate)
- ORDER BY EXTRACT (YEAR FROM transdate) DESC, EXTRACT (MONTH FROM transdate) DESC";
-
+ ORDER BY EXTRACT (YEAR FROM transdate) DESC, EXTRACT (MONTH FROM transdate) DESC
+SQL
$self->{turnover_statistic} = selectall_hashref_query($::form, $dbh, $query);
$self->render('customer_vendor_turnover/count_turnover', { layout => 0 });
}
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 = <<SQL;
+SELECT EXTRACT (YEAR FROM transdate) as date_part,
count(id) as count,
sum(amount) as amount,
sum(netamount) as netamount,
sum(paid) as paid
- FROM ar WHERE customer_id = $cv
+ FROM $db WHERE $cv_type = $cv
GROUP BY date_part
- ORDER BY date_part DESC";
-
+ ORDER BY date_part DESC
+SQL
$self->{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 _list_articles_by_invoice {
}
sub _list_count_articles_by_year {
--- /dev/null
+[%- USE T8 %]
+[%- USE LxERP %]
+[%- USE L %]
+[%- USE HTML %]
+
+<div id="orders_report">
+ <table width="100%">
+ <caption class="listtop">[%- HTML.escape(title) %]</caption>
+ <tbody>
+ <tr>
+ <td class="listheading">[% 'Type' | $T8 %]</td>
+ <td class="listheading">[% 'Order/RFQ Number' | $T8 %]</td>
+ <td class="listheading">[% 'Date' | $T8 %]</td>
+ <td class="listheading">[% 'Amount' | $T8 %]</td>
+ <td class="listheading">[% 'Saleman' | $T8 %]</td>
+ <td class="listheading">[% 'Transaction description' | $T8 %]</td>
+ </tr>
+
+ [%- FOREACH row = orders %]
+ <tr class="listrow[% loop.count % 2 %]">
+ <td>[% IF row.quotation %]
+ [% IF FORM.db == 'customer' %][% 'Sales quotation' | $T8 %][% ELSE %][% 'RFQ' | $T8 %][% END %]</td>
+ [%- IF INSTANCE_CONF.get_feature_experimental -%]
+ <td>[% IF row.id %]<a href='controller.pl?action=Order/edit&type=[% IF SELF.is_customer %]sales_quotation[% ELSE %]request_quotation[% END %]&id=[% HTML.escape(row.id) %]'>[% END %][% HTML.escape(row.quonumber) || ' ' %][% IF row.id %]</a>[% END %]</td>
+ [%- ELSE -%]
+ <td>[% IF row.id %]<a href='oe.pl?action=edit&type=[% IF SELF.is_customer %]sales_quotation[% ELSE %]request_quotation[% END %]&vc=customer&id=[% HTML.escape(row.oe_id) %]'>[% END %][% HTML.escape(row.quonumber) || ' ' %][% IF row.id %]</a>[% END %]</td>
+ [%- END -%]
+ [% ELSE %]
+ [% IF FORM.db == 'customer' %][% 'Sales Order' | $T8 %][% ELSE %][% 'Purchase Order' | $T8 %][% END %]</td>
+ [%- IF INSTANCE_CONF.get_feature_experimental -%]
+ <td>[% IF row.id %]<a href='controller.pl?action=Order/edit&type=[% IF SELF.is_customer %]sales_order[% ELSE %]purchase_order[% END %]&id=[% HTML.escape(row.id) %]'>[% END %][% HTML.escape(row.ordnumber) || ' ' %][% IF row.id %]</a>[% END %]</td>
+ [%- ELSE -%]
+ <td>[% IF row.id %]<a href='oe.pl?action=edit&type=[% IF SELF.is_customer %]sales_order[% ELSE %]purchase_order[% END %]&vc=customer&id=[% HTML.escape(row.oe_id) %]'>[% END %][% HTML.escape(row.ordnumber) || ' ' %][% IF row.id %]</a>[% END %]</td>
+ [%- END -%]
+ [% END %]
+ <td>[% row.transdate.to_kivitendo | html %]</td>
+ <td>[%- LxERP.format_amount(row.amount, 2) %]</td>
+ <td>[% row.employee.name | html %]</td>
+ <td>[% row.transaction_description | html %]</td>
+ </tr>
+ [% END %]
+ </tbody>
+ </table>
+</div>
$ ( "#statistic_tabs" ).tabs();
});
function get_invoices() {
- var url = 'controller.pl?action=CustomerVendorTurnover/get_invoices&id=' + $('#cv_id').val();
+ var url = 'controller.pl?action=CustomerVendorTurnover/get_invoices&id=' + $('#cv_id').val() + '&db=' + $('#db').val();
$('#invoices').load(url);
}
+ function get_sales_quotations() {
+ var url = 'controller.pl?action=CustomerVendorTurnover/get_orders&id=' + $('#cv_id').val() + '&db=' + $('#db').val() + '&type=quotation';
+ $('#quotations').load(url);
+ }
+ function get_orders() {
+ var url = 'controller.pl?action=CustomerVendorTurnover/get_orders&id=' + $('#cv_id').val() + '&db=' + $('#db').val() + '&type=order';
+ $('#orders').load(url);
+ }
+ function get_letters() {
+ var url = 'controller.pl?action=CustomerVendorTurnover/get_letters&id=' + $('#cv_id').val() + '&db=' + $('#db').val();;
+ $('#letters').load(url);
+ }
+ function get_mails() {
+ var url = 'controller.pl?action=CustomerVendorTurnover/get_mails&id=' + $('#cv_id').val() + '&db=' + $('#db').val();;
+ $('#mails').load(url);
+ }
</script>
<div class="tabwidget" id="statistic_tabs">
<ul>
<li><a href="#turnover_stat">[% 'Turnoverstatistic' | $T8 %]</a></li>
- <li><a href="#dun_stat">[% 'Dunningstatistic' | $T8 %]</a></li>
+ [% IF FORM.db == "customer" %]<li><a href="#dun_stat">[% 'Dunningstatistic' | $T8 %]</a></li>[% END %]
+ <li><a href="#quotations" onclick="get_sales_quotations();">[% IF FORM.db == "customer" %][% 'Sales Quotations' | $T8 %][% ELSE %][% 'Request Quotations' | $T8 %][% END %]</a></li>
+ <li><a href="#orders" onclick="get_orders();">[% 'Orders' | $T8 %]</a></li>
<li><a href="#invoices" onclick="get_invoices();">[% 'Invoices' | $T8 %]</a></li>
+ <li><a href="#mails" onclick="get_mails();">[% 'Mails' | $T8 %]</a></li>
+ <li><a href="#letters" onclick="get_letters();">[% 'Letters' | $T8 %]</a></li>
</ul>
<div id="turnover_stat">[% PROCESS "customer_vendor_turnover/turnover_statistic.html" %]</div>
<div id="dun_stat">[% PROCESS "customer_vendor_turnover/dun_statistic.html" %]</div>
+ <div id="quotations"></div>
+ <div id="orders"></div>
<div id="invoices"></div>
+ <div id="mails"></div>
+ <div id="letters"></div>
</div>