my $myconfig = \%main::myconfig;
my $form = $main::form;
+ my $vc = $params{vc} eq 'customer' ? 'customer' : 'vendor';
+ my $arap = $params{vc} eq 'customer' ? 'ar' : 'ap';
my $dbh = $params{dbh} || $form->get_standard_dbh($myconfig);
}
if ($filter->{invnumber}) {
- push @where_sub, "ap.invnumber ILIKE ?";
+ push @where_sub, "arap.invnumber ILIKE ?";
push @values_sub, '%' . $filter->{invnumber} . '%';
- $joins_sub{ap} = 1;
+ $joins_sub{$arap} = 1;
}
- if ($filter->{vendor}) {
- push @where_sub, "v.name ILIKE ?";
- push @values_sub, '%' . $filter->{vendor} . '%';
- $joins_sub{ap} = 1;
- $joins_sub{vendor} = 1;
+ if ($filter->{vc}) {
+ push @where_sub, "vc.name ILIKE ?";
+ push @values_sub, '%' . $filter->{vc} . '%';
+ $joins_sub{$arap} = 1;
+ $joins_sub{vc} = 1;
}
foreach my $type (qw(requested_execution execution)) {
if (@where_sub) {
my $joins_sub = '';
- $joins_sub .= ' LEFT JOIN ap ON (items.ap_id = ap.id)' if ($joins_sub{ap});
- $joins_sub .= ' LEFT JOIN vendor v ON (ap.vendor_id = v.id)' if ($joins_sub{vendor});
+ $joins_sub .= " LEFT JOIN ${arap} arap ON (items.${arap}_id = arap.id)" if ($joins_sub{$arap});
+ $joins_sub .= " LEFT JOIN ${vc} vc ON (arap.${vc}_id = vc.id)" if ($joins_sub{vc});
my $where_sub = join(' AND ', map { "(${_})" } @where_sub);
push @values, @values_sub;
}
+ push @where, 'se.vc = ?';
+ push @values, $vc;
+
my $where = ' WHERE ' . join(' AND ', map { "(${_})" } @where) if (@where);
my $query =
my $form = $main::form;
my $locale = $main::locale;
my $cgi = $main::cgi;
+ my $vc = $form->{vc} eq 'customer' ? 'customer' : 'vendor';
- $form->{title} = $locale->text('List of bank transfers');
+ $form->{title} = $vc eq 'customer' ? $::locale->text('List of bank collections') : $locale->text('List of bank transfers');
$form->{sort} ||= 'id';
$form->{sortdir} = '1' if (!defined $form->{sortdir});
- $form->{callback} = build_std_url('action=bank_transfer_list', 'sort', 'sortdir');
+ $form->{callback} = build_std_url('action=bank_transfer_list', 'sort', 'sortdir', 'vc');
my %filter = map +( $_ => $form->{"f_${_}"} ),
grep { $form->{"f_${_}"} }
- (qw(vendor invnumber),
+ (qw(vc invnumber),
map { ("${_}_date_from", "${_}_date_to") }
qw(export requested_execution execution));
$filter{executed} = $form->{l_executed} ? 1 : 0 if ($form->{l_executed} != $form->{l_not_executed});
my $exports = SL::SEPA->list_exports('filter' => \%filter,
'sortorder' => $form->{sort},
- 'sortdir' => $form->{sortdir});
+ 'sortdir' => $form->{sortdir},
+ 'vc' => $vc);
my $open_available = any { !$_->{closed} } @{ $exports };
my $report = SL::ReportGenerator->new(\%main::myconfig, $form);
- my @hidden_vars = grep { m/^[fl]_/ && $form->{$_} } keys %{ $form };
+ my @hidden_vars = ('vc', grep { m/^[fl]_/ && $form->{$_} } keys %{ $form });
my $href = build_std_url('action=bank_transfer_list', @hidden_vars);
$column_defs{closed}->{visible} = $form->{l_closed} && $form->{l_open} ? 1 : 0;
my @options = ();
- push @options, $locale->text('Vendor') . ' : ' . $form->{f_vendor} if ($form->{f_vendor});
+ push @options, ($vc eq 'customer' ? $::locale->text('Customer') : $locale->text('Vendor')) . ' : ' . $form->{f_vc} if ($form->{f_vc});
push @options, $locale->text('Invoice number') . ' : ' . $form->{f_invnumber} if ($form->{f_invnumber});
push @options, $locale->text('Export date from') . ' : ' . $form->{f_export_date_from} if ($form->{f_export_date_from});
push @options, $locale->text('Export date to') . ' : ' . $form->{f_export_date_to} if ($form->{f_export_date_to});
map { $row->{$_}->{data} = $export->{$_} ? $locale->text('yes') : $locale->text('no') } qw(executed closed);
- $row->{id}->{link} = $edit_url . '&id=' . E($export->{id});
+ $row->{id}->{link} = $edit_url . '&id=' . E($export->{id}) . '&vc=' . E($vc);
if (!$export->{closed}) {
$row->{selected}->{raw_data} =