use SL::Chart;
use SL::CT;
use SL::Form;
+use SL::GenericTranslations;
use SL::ReportGenerator;
use SL::SEPA;
use SL::SEPA::XML;
my $bank_account_label_sub = sub { $locale->text('Account number #1, bank code #2, #3', $_[0]->{account_number}, $_[0]->{bank_code}, $_[0]->{bank}) };
+ my $translation_list = GenericTranslations->list(translation_type => 'sepa_remittance_info_pfx');
+ my %translations = map { ( ($_->{language_id} || 'default') => $_->{translation} ) } @{ $translation_list };
+
+ foreach my $invoice (@{ $invoices }) {
+ my $prefix = $translations{ $invoice->{language_id} } || $translations{default} || $::locale->text('Invoice');
+ $prefix .= ' ' unless $prefix =~ m/ $/;
+ $invoice->{reference_prefix} = $prefix;
+ }
+
$form->header();
print $form->parse_html_template('sepa/bank_transfer_add',
{ 'INVOICES' => $invoices,
}
if ($error_message || !$form->{confirmation}) {
- my @vc_ids = uniq map { $_->{"${vc}_id"} } @bank_transfers;
+ my @vc_ids = uniq map { $_->{vc_id} } @bank_transfers;
$vc_bank_info ||= CT->get_bank_info('vc' => $vc,
'id' => \@vc_ids);
my @vc_bank_info = sort { lc $a->{name} cmp lc $b->{name} } values %{ $vc_bank_info };
} else {
foreach my $bank_transfer (@bank_transfers) {
foreach (qw(iban bic)) {
- $bank_transfer->{"vc_${_}"} = $vc_bank_info->{ $bank_transfer->{"${vc}_id"} }->{$_};
+ $bank_transfer->{"vc_${_}"} = $vc_bank_info->{ $bank_transfer->{vc_id} }->{$_};
$bank_transfer->{"our_${_}"} = $bank_account->{$_};
}
my $form = $main::form;
my $locale = $main::locale;
- my $cgi = $main::cgi;
+ my $cgi = $::request->{cgi};
my $vc = $form->{vc} eq 'customer' ? 'customer' : 'vendor';
$form->{title} = $vc eq 'customer' ? $::locale->text('List of bank collections') : $locale->text('List of bank transfers');
'attachment_basename' => $locale->text('banktransfers') . strftime('_%Y%m%d', localtime time),
);
$report->set_options_from_form();
+ $locale->set_numberformat_wo_thousands_separator(\%::myconfig) if lc($report->{options}->{output_format}) eq 'csv';
$report->set_columns(%column_defs);
$report->set_column_order(@columns);
$main::lxdebug->leave_sub();
}
+# TODO
sub bank_transfer_download_sepa_xml {
$main::lxdebug->enter_sub();
my $form = $main::form;
my $myconfig = \%main::myconfig;
my $locale = $main::locale;
- my $cgi = $main::cgi;
+ my $cgi = $::request->{cgi};
+ my $vc = $form->{vc} eq 'customer' ? 'customer' : 'vendor';
if (!$myconfig->{company}) {
$form->show_generic_error($locale->text('You have to enter a company name in your user preferences (see the "Program" menu, "Preferences").'), 'back_button' => 1);
}
+ if (($vc eq 'customer') && !$myconfig->{sepa_creditor_id}) {
+ $form->show_generic_error($locale->text('You have to enter the SEPA creditor ID in your user preferences (see the "Program" menu, "Preferences").'), 'back_button' => 1);
+ }
+
my @ids;
if ($form->{mode} && ($form->{mode} eq 'multi')) {
@ids = map $_->{id}, grep { $_->{selected} } @{ $form->{exports} || [] };
my @items = ();
foreach my $id (@ids) {
- my $export = SL::SEPA->retrieve_export('id' => $id, 'details' => 1);
+ my $export = SL::SEPA->retrieve_export('id' => $id, 'details' => 1, vc => $vc);
push @items, grep { !$_->{executed} } @{ $export->{items} } if ($export && !$export->{closed});
}
my $message_id = strftime('MSG%Y%m%d%H%M%S', localtime) . sprintf('%06d', $$);
my $sepa_xml = SL::SEPA::XML->new('company' => $myconfig->{company},
- 'src_charset' => $main::dbcharset || 'ISO-8859-15',
+ 'creditor_id' => $myconfig->{sepa_creditor_id},
+ 'src_charset' => $::lx_office_conf{system}->{dbcharset} || 'ISO-8859-15',
'message_id' => $message_id,
'grouped' => 1,
+ 'collection' => $vc eq 'customer',
);
foreach my $item (@items) {
$requested_execution_date = sprintf '%04d-%02d-%02d', $yy, $mm, $dd;
}
+ if ($vc eq 'customer') {
+ my ($yy, $mm, $dd) = $locale->parse_date($myconfig, $item->{reference_date});
+ $item->{reference_date} = sprintf '%04d-%02d-%02d', $yy, $mm, $dd;
+ }
+
$sepa_xml->add_transaction({ 'src_iban' => $item->{our_iban},
'src_bic' => $item->{our_bic},
- 'dst_iban' => $item->{vendor_iban},
- 'dst_bic' => $item->{vendor_bic},
- 'recipient' => $item->{vendor_name},
+ 'dst_iban' => $item->{vc_iban},
+ 'dst_bic' => $item->{vc_bic},
+ 'company' => $item->{vc_name},
'amount' => $item->{amount},
'reference' => $item->{reference},
+ 'reference_date' => $item->{reference_date},
'execution_date' => $requested_execution_date,
'end_to_end_id' => $item->{end_to_end_id} });
}
my $xml = $sepa_xml->to_xml();
print $cgi->header('-type' => 'application/octet-stream',
- '-content-disposition' => 'attachment; filename="SEPA_' . $message_id . '.cct"',
+ '-content-disposition' => 'attachment; filename="SEPA_' . $message_id . ($vc eq 'customer' ? '.cdd' : '.cct') . '"',
'-content-length' => length $xml);
print $xml;