push(@apvalues, '%' . $form->{source} . '%');
}
+ # default Datumseinschränkung falls nicht oder falsch übergeben (sollte nie passieren)
+ $form->{datesort} = 'transdate' unless $form->{datesort} =~ /^(transdate|gldate)$/;
+
if ($form->{datefrom}) {
- $glwhere .= " AND ac.transdate >= ?";
- $arwhere .= " AND ac.transdate >= ?";
- $apwhere .= " AND ac.transdate >= ?";
+ $glwhere .= " AND ac.$form->{datesort} >= ?";
+ $arwhere .= " AND ac.$form->{datesort} >= ?";
+ $apwhere .= " AND ac.$form->{datesort} >= ?";
push(@glvalues, $form->{datefrom});
push(@arvalues, $form->{datefrom});
push(@apvalues, $form->{datefrom});
}
if ($form->{dateto}) {
- $glwhere .= " AND ac.transdate <= ?";
- $arwhere .= " AND ac.transdate <= ?";
- $apwhere .= " AND ac.transdate <= ?";
+ $glwhere .= " AND ac.$form->{datesort} <= ?";
+ $arwhere .= " AND ac.$form->{datesort} <= ?";
+ $apwhere .= " AND ac.$form->{datesort} <= ?";
push(@glvalues, $form->{dateto});
push(@arvalues, $form->{dateto});
push(@apvalues, $form->{dateto});
push(@arvalues, '%' . $form->{description} . '%');
push(@apvalues, '%' . $form->{description} . '%');
}
+
+ if ($form->{employee} =~ /--/) {
+ ($form->{employee_id},$form->{employee_name}) = split(/--/,$form->{employee});
+ $query .= " AND o.employee_id = ?";
+ push @values, conv_i($form->{employee_id});
+ #if ($form->{employee_id}) {
+ $glwhere .= " AND g.employee_id = ? ";
+ $arwhere .= " AND a.employee_id = ? ";
+ $apwhere .= " AND a.employee_id = ? ";
+ push(@glvalues, conv_i($form->{employee_id}));
+ push(@arvalues, conv_i($form->{employee_id}));
+ push(@apvalues, conv_i($form->{employee_id}));
+ }
if ($form->{notes}) {
$glwhere .= " AND g.notes ILIKE ?";
qq|SELECT SUM(ac.amount)
FROM acc_trans ac
LEFT JOIN chart c ON (ac.chart_id = c.id)
- WHERE (c.accno = ?) AND (ac.transdate < ?)|;
+ WHERE (c.accno = ?) AND (ac.$form->{datesort} < ?)|;
($form->{balance}) = selectrow_query($form, $dbh, $query, $form->{accno}, conv_date($form->{datefrom}));
}
}
my %sort_columns = (
'id' => [ qw(id) ],
'transdate' => [ qw(transdate id) ],
+ 'gldate' => [ qw(gldate id) ],
'reference' => [ qw(lower_reference id) ],
'description' => [ qw(lower_description id) ],
'accno' => [ qw(accno transdate id) ],
'source' => { 'gl' => 'ac.source', 'arap' => 'ac.source', },
'description' => { 'gl' => 'g.description', 'arap' => 'ct.name', },
);
-
+
+ # sortdir = sort direction (ascending or descending)
my $sortdir = !defined $form->{sortdir} ? 'ASC' : $form->{sortdir} ? 'ASC' : 'DESC';
- my $sortkey = $sort_columns{$form->{sort}} ? $form->{sort} : 'transdate';
+ my $sortkey = $sort_columns{$form->{sort}} ? $form->{sort} : $form->{datesort}; # default used to be transdate
my $sortorder = join ', ', map { "$_ $sortdir" } @{ $sort_columns{$sortkey} };
my %columns_for_sorting = ( 'gl' => '', 'arap' => '', );
$query =
qq|SELECT
ac.acc_trans_id, g.id, 'gl' AS type, $false AS invoice, g.reference, ac.taxkey, c.link,
- g.description, ac.transdate, ac.source, ac.trans_id,
- ac.amount, c.accno, g.notes, t.chart_id
+ g.description, ac.transdate, ac.gldate, ac.source, ac.trans_id,
+ ac.amount, c.accno, g.notes, t.chart_id,
+ CASE WHEN (COALESCE(e.name, '') = '') THEN e.login ELSE e.name END AS employee
$project_columns
$columns_for_sorting{gl}
FROM gl g, acc_trans ac $project_join, chart c
UNION
SELECT ac.acc_trans_id, a.id, 'ar' AS type, a.invoice, a.invnumber, ac.taxkey, c.link,
- ct.name, ac.transdate, ac.source, ac.trans_id,
- ac.amount, c.accno, a.notes, t.chart_id
+ ct.name, ac.transdate, ac.gldate, ac.source, ac.trans_id,
+ ac.amount, c.accno, a.notes, t.chart_id,
+ CASE WHEN (COALESCE(e.name, '') = '') THEN e.login ELSE e.name END AS employee
$project_columns
$columns_for_sorting{arap}
FROM ar a, acc_trans ac $project_join, customer ct, chart c
UNION
SELECT ac.acc_trans_id, a.id, 'ap' AS type, a.invoice, a.invnumber, ac.taxkey, c.link,
- ct.name, ac.transdate, ac.source, ac.trans_id,
- ac.amount, c.accno, a.notes, t.chart_id
+ ct.name, ac.transdate, ac.gldate, ac.source, ac.trans_id,
+ ac.amount, c.accno, a.notes, t.chart_id,
+ CASE WHEN (COALESCE(e.name, '') = '') THEN e.login ELSE e.name END AS employee
$project_columns
$columns_for_sorting{arap}
FROM ap a, acc_trans ac $project_join, vendor ct, chart c
AND (a.id = ac.trans_id)
ORDER BY $sortorder, acc_trans_id $sortdir|;
+# ORDER BY gldate DESC, id DESC, acc_trans_id DESC
my @values = (@glvalues, @arvalues, @apvalues);
| if $form->{selectdepartment};
$form->get_lists("projects" => { "key" => "ALL_PROJECTS",
- "all" => 1 });
+ "all" => 1},
+ "employees" => "ALL_EMPLOYEES" );
my %project_labels = ();
my @project_values = ("");
'-values' => \@project_values,
'-labels' => \%project_labels));
+ my %employee_labels = ();
+ my @employee_values = ("");
+ foreach my $item (@{ $form->{"ALL_EMPLOYEES"} }) {
+ # value in Form "1234--Name" übergeben
+ my $id = "$item->{'id'}--$item->{'name'}";
+ push(@employee_values, "$id");
+ $employee_labels{$id} = $item->{"name"};
+ }
+
+ my $employeenumber =
+ NTI($cgi->popup_menu('-name' => "employee",
+ '-values' => \@employee_values,
+ '-labels' => \%employee_labels));
+
# use JavaScript Calendar or not
$form->{jsscript} = 1;
my $jsscript = "";
<form method=post action=gl.pl>
-<input type=hidden name=sort value=transdate>
+<input type=hidden name=sort value=datesort>
<table width=100%>
<tr>
</tr>
<tr>
<th align=right>| . $locale->text('From') . qq|</th>
+ <tr>
+ <th align=right>| . $locale->text('Employee') . qq|</th>
+ <td colspan=3>$employeenumber</td>
+ </tr>
+ <tr>
+ <th align=right>| . $locale->text('Date Sorting') . qq|</th>
+ <td colspan=3>
+ <input name=datesort class=radio type=radio value=gldate checked> | . $locale->text('Booking Date') . qq|
+ <input name=datesort class=radio type=radio value=transdate> | . $locale->text('Invoice Date') . qq|
+ </td>
+ </tr>
+ <tr>
+ <th align=right>| . $locale->text('From') . qq|</th>
$button1
<th align=right>| . $locale->text('To (time)') . qq|</th>
$button2
<td align=right><input name="l_id" class=checkbox type=checkbox value=Y></td>
<td>| . $locale->text('ID') . qq|</td>
<td align=right><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
- <td>| . $locale->text('Date') . qq|</td>
+ <td>| . $locale->text('Invoice Date') . qq|</td>
+ <td align=right><input name="l_gldate" class=checkbox type=checkbox value=Y checked></td>
+ <td>| . $locale->text('Booking Date') . qq|</td>
<td align=right><input name="l_reference" class=checkbox type=checkbox value=Y checked></td>
<td>| . $locale->text('Reference') . qq|</td>
<td align=right><input name="l_description" class=checkbox type=checkbox value=Y checked></td>
<td>| . $locale->text('Subtotal') . qq|</td>
<td align=right><input name="l_projectnumbers" class=checkbox type=checkbox value=Y></td>
<td>| . $locale->text('Project Number') . qq|</td>
+ <td align=right><input name="l_employee" class=checkbox type=checkbox value=Y></td>
+ <td>| . $locale->text('Employee') . qq|</td>
</tr>
</table>
</tr>
my %myconfig = %main::myconfig;
my $locale = $main::locale;
- report_generator_set_default_sort('transdate', 1);
+ # generate_report wird beim ersten Aufruf per Weiter-Knopf und POST mit der hidden Variablen sort mit Wert "datesort" (früher "transdate" als Defaultsortiervariable) übertragen
+
+ # <form method=post action=gl.pl>
+ # <input type=hidden name=sort value=datesort> # form->{sort} setzen
+ # <input type=hidden name=nextsub value=generate_report>
+
+ # anhand von neuer Variable datesort wird jetzt $form->{sort} auf transdate oder gldate gesetzt
+ # damit ist die Hidden Variable "sort" wahrscheinlich sogar überflüssig
+
+ # ändert man die Sortierreihenfolge per Klick auf eine der Überschriften wird die Variable "sort" per GET übergeben, z.B. id,transdate, gldate, ...
+ # gl.pl?action=generate_report&employee=18383--Jan%20B%c3%bcren&datesort=transdate&category=X&l_transdate=Y&l_gldate=Y&l_id=Y&l_reference=Y&l_description=Y&l_source=Y&l_debit=Y&l_credit=Y&sort=gldate&sortdir=0
+
+ if ( $form->{sort} eq 'datesort' ) { # sollte bei einem Post (Aufruf aus Suchmaske) immer wahr sein
+ # je nachdem ob in Suchmaske "transdate" oder "gldate" ausgesucht wurde erstes Suchergebnis entsprechend sortieren
+ $form->{sort} = $form->{datesort};
+ };
+
+ # was passiert hier?
+ report_generator_set_default_sort("$form->{datesort}", 1);
+# report_generator_set_default_sort('transdate', 1);
GL->all_transactions(\%myconfig, \%$form);
my $ml = ($form->{ml} =~ /(A|E|Q)/) ? -1 : 1;
my @columns = qw(
- transdate id reference description
- notes source debit debit_accno
+ gldate transdate id reference description
+ notes source debit debit_accno
credit credit_accno debit_tax debit_tax_accno
credit_tax credit_tax_accno projectnumbers balance
);
- my @hidden_variables = qw(accno source reference department description notes project_id datefrom dateto category l_subtotal);
+ # add employee here, so that variable is still known and passed in url when choosing a different sort order in resulting table
+ my @hidden_variables = qw(accno source reference department description notes project_id datefrom dateto employee datesort category l_subtotal);
push @hidden_variables, map { "l_${_}" } @columns;
+ foreach ( @hidden_variables ) {
+ print URL "$_\n";
+ };
my (@options, @date_options);
push @options, $locale->text('Account') . " : $form->{accno} $form->{account_description}" if ($form->{accno});
push @options, $locale->text('Reference') . " : $form->{reference}" if ($form->{reference});
push @options, $locale->text('Description') . " : $form->{description}" if ($form->{description});
push @options, $locale->text('Notes') . " : $form->{notes}" if ($form->{notes});
-
+ push @options, $locale->text('Employee') . " : $form->{employee_name}" if ($form->{employee_name});
+ my $datesorttext = $form->{datesort} eq 'transdate' ? $locale->text('Invoice Date') : $locale->text('Booking Date');
+ push @date_options, "$datesorttext" if ($form->{datesort} and ($form->{datefrom} or $form->{dateto}));
push @date_options, $locale->text('From'), $locale->date(\%myconfig, $form->{datefrom}, 1) if ($form->{datefrom});
push @date_options, $locale->text('Bis'), $locale->date(\%myconfig, $form->{dateto}, 1) if ($form->{dateto});
push @options, join(' ', @date_options) if (scalar @date_options);
my $callback = build_std_url('action=generate_report', grep { $form->{$_} } @hidden_variables);
+ print URL $callback;
+ close URL;
$form->{l_credit_accno} = 'Y';
$form->{l_debit_accno} = 'Y';
$form->{l_credit_tax} = 'Y';
$form->{l_debit_tax} = 'Y';
+# $form->{l_gldate} = 'Y'; # Spalte mit gldate immer anzeigen
$form->{l_credit_tax_accno} = 'Y';
+ $form->{l_datesort} = 'Y';
$form->{l_debit_tax_accno} = 'Y';
$form->{l_balance} = $form->{accno} ? 'Y' : '';
my %column_defs = (
'id' => { 'text' => $locale->text('ID'), },
- 'transdate' => { 'text' => $locale->text('Date'), },
+ 'transdate' => { 'text' => $locale->text('Invoice Date'), },
+ 'gldate' => { 'text' => $locale->text('Booking Date'), },
'reference' => { 'text' => $locale->text('Reference'), },
'source' => { 'text' => $locale->text('Source'), },
'description' => { 'text' => $locale->text('Description'), },
'credit_tax_accno' => { 'text' => $locale->text('Credit Tax Account'), },
'balance' => { 'text' => $locale->text('Balance'), },
'projectnumbers' => { 'text' => $locale->text('Project Numbers'), },
+ 'employee' => { 'text' => $locale->text('Employee'), },
);
- foreach my $name (qw(id transdate reference description debit_accno credit_accno debit_tax_accno credit_tax_accno)) {
+ foreach my $name (qw(id transdate gldate reference description debit_accno credit_accno debit_tax_accno credit_tax_accno)) {
my $sortname = $name =~ m/accno/ ? 'accno' : $name;
my $sortdir = $sortname eq $form->{sort} ? 1 - $form->{sortdir} : $form->{sortdir};
$column_defs{$name}->{link} = $callback . "&sort=$sortname&sortdir=$sortdir";
my %column_alignment;
map { $column_alignment{$_} = 'right' } qw(balance id debit credit debit_tax credit_tax balance);
- map { $column_alignment{$_} = 'center' } qw(reference debit_accno credit_accno debit_tax_accno credit_tax_accno);
+ map { $column_alignment{$_} = 'center' } qw(transdate gldate reference debit_accno credit_accno debit_tax_accno credit_tax_accno);
map { $column_alignment{$_} = 'left' } qw(description source notes);
map { $column_defs{$_}->{align} = $column_alignment{$_} } keys %column_alignment;
map { $row->{$_}->{data} = $ref->{$_} } qw(id reference description notes);
- map { $row->{$_}->{data} = \@{ $rows{$_} }; } qw(transdate debit credit debit_accno credit_accno debit_tax_accno credit_tax_accno source);
+ map { $row->{$_}->{data} = \@{ $rows{$_} }; } qw(transdate gldate debit credit debit_accno credit_accno debit_tax_accno credit_tax_accno source);
foreach my $col (qw(debit_accno credit_accno debit_tax_accno credit_tax_accno)) {
$row->{$col}->{link} = [ map { "${callback}&accno=" . E($_) } @{ $rows{$col} } ];