# connect to database
my $dbh = $form->dbconnect($myconfig);
- my ($invoice, $arap, $buysell, $ct, $ct_id);
+ my ($invoice, $arap, $buysell, $ct, $ct_id, $ml);
if ($form->{ct} eq "customer") {
$invoice = "is";
$arap = "ar";
$buysell = "buy";
$ct = "customer";
+ $ml = -1;
} else {
$invoice = "ir";
$arap = "ap";
$buysell = "sell";
$ct = "vendor";
+ $ml = 1;
}
$ct_id = "${ct}_id";
street, zipcode, city, country, contact, email,
phone as customerphone, fax as customerfax, ${ct}number,
"invnumber", "transdate",
- (amount - paid) as "c0", 0.00 as "c30", 0.00 as "c60", 0.00 as "c90",
- "duedate", invoice, ${arap}.id,
- (SELECT $buysell
- FROM exchangerate
- WHERE (${arap}.curr = exchangerate.curr)
- AND (exchangerate.transdate = ${arap}.transdate)) AS exchangerate
- FROM ${arap}, ${ct}
- WHERE (paid != amount)
- AND (${arap}.storno IS FALSE)
- AND (${arap}.${ct}_id = ${ct}.id)
- AND (${ct}.id = ?)
- AND (transdate <= (date $todate - interval '0 days'))
- AND (transdate >= (date $todate - interval '30 days'))
-
- UNION
-
- -- between 31-60 days
-
- SELECT ${ct}.id AS ctid, ${ct}.name,
- street, zipcode, city, country, contact, email,
- phone as customerphone, fax as customerfax, ${ct}number,
- "invnumber", "transdate",
- 0.00 as "c0", (amount - paid) as "c30", 0.00 as "c60", 0.00 as "c90",
- "duedate", invoice, ${arap}.id,
- (SELECT $buysell
- FROM exchangerate
- WHERE (${arap}.curr = exchangerate.curr)
- AND (exchangerate.transdate = ${arap}.transdate)) AS exchangerate
- FROM ${arap}, ${ct}
- WHERE (paid != amount)
- AND (${arap}.storno IS FALSE)
- AND (${arap}.${ct}_id = ${ct}.id)
- AND (${ct}.id = ?)
- AND (transdate < (date $todate - interval '30 days'))
- AND (transdate >= (date $todate - interval '60 days'))
-
- UNION
-
- -- between 61-90 days
-
- SELECT ${ct}.id AS ctid, ${ct}.name,
- street, zipcode, city, country, contact, email,
- phone as customerphone, fax as customerfax, ${ct}number,
- "invnumber", "transdate",
- 0.00 as "c0", 0.00 as "c30", (amount - paid) as "c60", 0.00 as "c90",
+ (amount - COALESCE((SELECT sum(amount)*$ml FROM acc_trans LEFT JOIN chart ON (acc_trans.chart_id=chart.id) WHERE link ilike '%paid%' AND acc_trans.trans_id=${arap}.id AND acc_trans.transdate <= (date $todate)),0)) as "open", "amount",
"duedate", invoice, ${arap}.id,
(SELECT $buysell
FROM exchangerate
WHERE (${arap}.curr = exchangerate.curr)
AND (exchangerate.transdate = ${arap}.transdate)) AS exchangerate
FROM ${arap}, ${ct}
- WHERE (paid != amount)
- AND (${arap}.storno IS FALSE)
- AND (${arap}.${ct}_id = ${ct}.id)
- AND (${ct}.id = ?)
- AND (transdate < (date $todate - interval '60 days'))
- AND (transdate >= (date $todate - interval '90 days'))
-
- UNION
-
- -- over 90 days
-
- SELECT ${ct}.id AS ctid, ${ct}.name,
- street, zipcode, city, country, contact, email,
- phone as customerphone, fax as customerfax, ${ct}number,
- "invnumber", "transdate",
- 0.00 as "c0", 0.00 as "c30", 0.00 as "c60", (amount - paid) as "c90",
- "duedate", invoice, ${arap}.id,
- (SELECT $buysell
- FROM exchangerate
- WHERE (${arap}.curr = exchangerate.curr)
- AND (exchangerate.transdate = ${arap}.transdate)) AS exchangerate
- FROM ${arap}, ${ct}
- WHERE (paid != amount)
+ WHERE ((paid != amount) OR (datepaid > (date $todate) AND datepaid is not null))
AND (${arap}.storno IS FALSE)
AND (${arap}.${ct}_id = ${ct}.id)
AND (${ct}.id = ?)
- AND (transdate < (date $todate - interval '90 days'))
+ AND (transdate <= (date $todate))
ORDER BY ctid, transdate, invnumber |;
$form->{AG} = [];
# for each company that has some stuff outstanding
while (my ($id) = $sth->fetchrow_array) {
- do_statement($form, $sth_details, $q_details, $id, $id, $id, $id);
+ do_statement($form, $sth_details, $q_details, $id);
while (my $ref = $sth_details->fetchrow_hashref(NAME_lc)) {
$ref->{module} = ($ref->{invoice}) ? $invoice : $arap;
$auth->assert('report');
- $form->{padding} = " ";
- $form->{bold} = "<b>";
- $form->{endbold} = "</b>";
- $form->{br} = "<br>";
-
RP->balance_sheet(\%myconfig, \%$form);
$form->{asofdate} = $form->current_date(\%myconfig) unless $form->{asofdate};
$form->{last_period} =
$locale->date(\%myconfig, $form->{compareasofdate}, 0);
- $form->{IN} = "balance_sheet.html";
+ my $attachment_basename;
- # setup company variables for the form
- map { $form->{$_} = $myconfig{$_}; } (qw(company address businessnumber nativecurr));
+ my $report = SL::ReportGenerator->new(\%myconfig, $form);
- $form->{templates} = $myconfig{templates};
+ my @hidden_variables = ();
+ push @hidden_variables, qw(fromdate todate year cash );
+
+ my $href = build_std_url('action=orders', grep { $form->{$_} } @hidden_variables);
+
+ my %column_defs = (
+ 'accno' => { 'text' => $locale->text('Account Number'), },
+ 'description' => { 'text' => $locale->text('Description'), },
+ 'last_transaction' => { 'text' => $locale->text('Last Transaction'), },
+ 'soll_eb' => { 'text' => $locale->text('Debit Starting Balance'), },
+ 'haben_eb' => { 'text' => $locale->text('Credit Starting Balance'), },
+ 'soll' => { 'text' => $locale->text('Debit'), },
+ 'haben' => { 'text' => $locale->text('Credit'), },
+ 'soll_kumuliert' => { 'text' => $locale->text('Sum Debit'), },
+ 'haben_kumuliert' => { 'text' => $locale->text('Sum Credit'), },
+ 'soll_saldo' => { 'text' => $locale->text('Saldo Debit'), },
+ 'haben_saldo' => { 'text' => $locale->text('Saldo Credit'), }
+ );
+
+
+
+ my %column_alignment = map { $_ => 'right' } qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
+
+ map { $column_defs{$_}->{visible} = 1 } @columns;
+
+ $report->set_columns(%column_defs);
+ $report->set_column_order(@columns);
+
+ $report->set_export_options('trial_balance', @hidden_variables);
+
+ $report->set_sort_indicator($form->{sort}, 1);
+
+ my @options;
+
+
+ $form->{template_fromto} = $locale->date(\%myconfig, $form->{fromdate}, 0) . " - " . $locale->date(\%myconfig, $form->{todate}, 0);
+ $form->{template_to} = $locale->date(\%myconfig, $form->{todate}, 0);
+
+ $report->set_options('output_format' => 'HTML',
+ 'title' => $form->{title},
+ 'attachment_basename' => $attachment_basename . strftime('_%Y%m%d', localtime time),
+ );
+ $report->set_options_from_form();
+ # $form->parse_html_template('report_generator/html_report_bilanz', $variables));
+ $form->{report_template} = 'report_generator/html_report_bilanz';
+ # add sort and escape callback, this one we use for the add sub
+ $form->{callback} = $href .= "&sort=$form->{sort}";
+
+ # escape callback for href
+ $callback = $form->escape($href);
+
+ my @subtotal_columns = qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
+
+ my %totals = map { $_ => 0 } @subtotal_columns;
+
+ my $edit_url = build_std_url('action=edit', 'type', 'vc');
+
+# foreach $accno (@{ $form->{TB} }) {
+#
+# $accno->{soll} = $accno->{debit};
+# $accno->{haben} = $accno->{credit};
+# map { $totals{$_} += $accno->{$_} } @subtotal_columns;
+#
+# map { $accno->{$_} = $form->format_amount(\%myconfig, $accno->{$_}, 2) } qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
+#
+# map { $accno->{$_} = ($accno->{$_} == 0) ? '' : $accno->{$_} } qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
+#
+# my $row = { };
+#
+# foreach my $column (@columns) {
+# $row->{$column} = {
+# 'data' => $accno->{$column},
+# 'align' => $column_alignment{$column},
+# };
+# }
+#
+#
+# $row->{$ordnumber}->{link} = $edit_url . "&id=" . E($oe->{id}) . "&callback=${callback}";
+#
+# my $row_set = [ $row ];
+#
+#
+# $report->add_data($row_set);
+#
+# $idx++;
+# }
+#
+# $report->add_separator();
+#
+# $report->add_data(create_subtotal_row(\%totals, \@columns, \%column_alignment, \@subtotal_columns, 'listtotal'));
+
+ $report->generate_with_headers();
- $form->parse_template;
$lxdebug->leave_sub();
}
my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => 'right' } } @{ $columns } };
foreach (@{ $periods }) {
- $row->{"c$_"}->{data} = $subtotals->{$_} != 0 ? $form->format_amount(\%myconfig, $subtotals->{$_}, 2) : '';
+ $row->{"$_"}->{data} = $subtotals->{$_} != 0 ? $form->format_amount(\%myconfig, $subtotals->{$_}, 2) : '';
$subtotals->{$_} = 0;
}
my $report = SL::ReportGenerator->new(\%myconfig, $form);
- my @columns = qw(statement ct invnumber transdate duedate c0 c30 c60 c90);
+ my @columns = qw(statement ct invnumber transdate duedate amount open);
my %column_defs = (
'statement' => { 'text' => '', 'visible' => $form->{ct} eq 'customer' ? 'HTML' : 0, },
'invnumber' => { 'text' => $locale->text('Invoice'), },
'transdate' => { 'text' => $locale->text('Date'), },
'duedate' => { 'text' => $locale->text('Due'), },
- 'c0' => { 'text' => $locale->text('Current'), },
- 'c30' => { 'text' => '30', },
- 'c60' => { 'text' => '60', },
- 'c90' => { 'text' => '90', },
+ 'amount' => { 'text' => $locale->text('Amount'), },
+ 'open' => { 'text' => $locale->text('Open'), },
);
my %column_alignment = ('statement' => 'center',
- map { $_ => 'right' } qw(c0 c30 c60 c90));
+ map { $_ => 'right' } qw(open amount));
$report->set_options('std_column_visibility' => 1);
$report->set_columns(%column_defs);
my $previous_ctid = 0;
my $row_idx = 0;
- my @periods = qw(0 30 60 90);
+ my @periods = qw(open amount);
my %subtotals = map { $_ => 0 } @periods;
my %totals = map { $_ => 0 } @periods;
}
foreach my $key (@periods) {
- $subtotals{$key} += $ref->{"c${key}"};
- $totals{$key} += $ref->{"c${key}"};
- $ref->{"c${key}"} = $ref->{"c${key}"} != 0 ? $form->format_amount(\%myconfig, $ref->{"c${key}"}, 2) : '';
+ $subtotals{$key} += $ref->{"$key"};
+ $totals{$key} += $ref->{"$key"};
+ $ref->{"$key"} = $ref->{"$key"} != 0 ? $form->format_amount(\%myconfig, $ref->{"$key"}, 2) : '';
}
my $row = { };