X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Fsepa.pl;h=9f9f31a222044a0a79999df11ff855f41ef25622;hb=89c9ff022d3f13e27ba6bda085df15707fcfb0eb;hp=6cdc35f949f2bd6942c827aabeaddb071a901ae7;hpb=cb4a0a39b022a04ee9c610c7c01dde47ce958ecd;p=kivitendo-erp.git diff --git a/bin/mozilla/sepa.pl b/bin/mozilla/sepa.pl index 6cdc35f94..9f9f31a22 100755 --- a/bin/mozilla/sepa.pl +++ b/bin/mozilla/sepa.pl @@ -8,6 +8,7 @@ use SL::BankAccount; use SL::Chart; use SL::CT; use SL::Form; +use SL::GenericTranslations; use SL::ReportGenerator; use SL::SEPA; use SL::SEPA::XML; @@ -41,6 +42,15 @@ sub bank_transfer_add { 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, @@ -238,6 +248,7 @@ sub bank_transfer_list { '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); @@ -330,6 +341,7 @@ sub bank_transfer_post_payments { my $form = $main::form; my $locale = $main::locale; + my $vc = $form->{vc} eq 'customer' ? 'customer' : 'vendor'; my @items = grep { $_->{selected} } @{ $form->{items} || [] }; @@ -337,7 +349,7 @@ sub bank_transfer_post_payments { $form->show_generic_error($locale->text('You have not selected any item.'), 'back_button' => 1); } my @export_ids = uniq map { $_->{sepa_export_id} } @items; - my %exports = map { $_ => SL::SEPA->retrieve_export('id' => $_, 'details' => 1) } @export_ids; + my %exports = map { $_ => SL::SEPA->retrieve_export('id' => $_, 'details' => 1, vc => $vc) } @export_ids; my @items_to_post = (); foreach my $item (@items) { @@ -355,7 +367,7 @@ sub bank_transfer_post_payments { $form->show_generic_error($locale->text('You have to specify an execution date for each antry.'), 'back_button' => 1); } - SL::SEPA->post_payment('items' => \@items_to_post); + SL::SEPA->post_payment('items' => \@items_to_post, vc => $vc); $form->show_generic_information($locale->text('The payments have been posted.')); @@ -368,13 +380,14 @@ sub bank_transfer_payment_list_as_pdf { my $form = $main::form; my %myconfig = %main::myconfig; my $locale = $main::locale; + my $vc = $form->{vc} eq 'customer' ? 'customer' : 'vendor'; my @ids = @{ $form->{items} || [] }; my @export_ids = uniq map { $_->{export_id} } @ids; $form->show_generic_error($locale->text('Multi mode not supported.'), 'back_button' => 1) if 1 != scalar @export_ids; - my $export = SL::SEPA->retrieve_export('id' => $export_ids[0], 'details' => 1); + my $export = SL::SEPA->retrieve_export('id' => $export_ids[0], 'details' => 1, vc => $vc); my @items = (); foreach my $id (@ids) { @@ -387,25 +400,25 @@ sub bank_transfer_payment_list_as_pdf { my $report = SL::ReportGenerator->new(\%main::myconfig, $form); my %column_defs = ( - 'invnumber' => { 'text' => $locale->text('Invoice'), }, - 'vendor_name' => { 'text' => $locale->text('Vendor'), }, - 'our_iban' => { 'text' => $locale->text('Source IBAN'), }, - 'our_bic' => { 'text' => $locale->text('Source BIC'), }, - 'vendor_iban' => { 'text' => $locale->text('Destination IBAN'), }, - 'vendor_bic' => { 'text' => $locale->text('Destination BIC'), }, - 'amount' => { 'text' => $locale->text('Amount'), }, - 'reference' => { 'text' => $locale->text('Reference'), }, - 'execution_date' => { 'text' => $locale->text('Execution date'), }, + 'invnumber' => { 'text' => $locale->text('Invoice'), }, + 'vc_name' => { 'text' => $vc eq 'customer' ? $locale->text('Customer') : $locale->text('Vendor'), }, + 'our_iban' => { 'text' => $vc eq 'customer' ? $locale->text('Destination IBAN') : $locale->text('Source IBAN'), }, + 'our_bic' => { 'text' => $vc eq 'customer' ? $locale->text('Destination BIC') : $locale->text('Source BIC'), }, + 'vc_iban' => { 'text' => $vc eq 'customer' ? $locale->text('Source IBAN') : $locale->text('Destination IBAN'), }, + 'vc_bic' => { 'text' => $vc eq 'customer' ? $locale->text('Source BIC') : $locale->text('Destination BIC'), }, + 'amount' => { 'text' => $locale->text('Amount'), }, + 'reference' => { 'text' => $locale->text('Reference'), }, + 'execution_date' => { 'text' => $locale->text('Execution date'), }, ); map { $column_defs{$_}->{align} = 'right' } qw(amount execution_date); - my @columns = qw(invnumber vendor_name our_iban our_bic vendor_iban vendor_bic amount reference execution_date); + my @columns = qw(invnumber vc_name our_iban our_bic vc_iban vc_bic amount reference execution_date); $report->set_options('std_column_visibility' => 1, 'output_format' => 'PDF', - 'title' => $locale->text('Bank transfer payment list for export #1', $export->{id}), - 'attachment_basename' => $locale->text('bank_transfer_payment_list_#1', $export->{id}) . strftime('_%Y%m%d', localtime time), + 'title' => $vc eq 'customer' ? $locale->text('Bank collection payment list for export #1', $export->{id}) : $locale->text('Bank transfer payment list for export #1', $export->{id}), + 'attachment_basename' => ($vc eq 'customer' ? $locale->text('bank_collection_payment_list_#1', $export->{id}) : $locale->text('bank_transfer_payment_list_#1', $export->{id})) . strftime('_%Y%m%d', localtime time), ); $report->set_columns(%column_defs); @@ -423,6 +436,7 @@ sub bank_transfer_payment_list_as_pdf { $main::lxdebug->leave_sub(); } +# TODO sub bank_transfer_download_sepa_xml { $main::lxdebug->enter_sub(); @@ -430,11 +444,16 @@ sub bank_transfer_download_sepa_xml { my $myconfig = \%main::myconfig; my $locale = $main::locale; my $cgi = $main::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} || [] }; @@ -450,7 +469,7 @@ sub bank_transfer_download_sepa_xml { 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}); } @@ -461,9 +480,11 @@ sub bank_transfer_download_sepa_xml { 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) { @@ -473,13 +494,19 @@ sub bank_transfer_download_sepa_xml { $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} }); } @@ -487,7 +514,7 @@ sub bank_transfer_download_sepa_xml { 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; @@ -499,6 +526,7 @@ sub bank_transfer_mark_as_closed_step1 { my $form = $main::form; my $locale = $main::locale; + my $vc = $form->{vc} eq 'customer' ? 'customer' : 'vendor'; my @export_ids = map { $_->{id} } grep { $_->{selected} } @{ $form->{exports} || [] }; @@ -508,7 +536,7 @@ sub bank_transfer_mark_as_closed_step1 { my @open_export_ids = (); foreach my $id (@export_ids) { - my $export = SL::SEPA->retrieve_export('id' => $id); + my $export = SL::SEPA->retrieve_export('id' => $id, vc => $vc); push @open_export_ids, $id if (!$export->{closed}); } @@ -518,7 +546,7 @@ sub bank_transfer_mark_as_closed_step1 { $form->{title} = $locale->text('Close SEPA exports'); $form->header(); - print $form->parse_html_template('sepa/bank_transfer_mark_as_closed_step1', { 'OPEN_EXPORT_IDS' => \@open_export_ids }); + print $form->parse_html_template('sepa/bank_transfer_mark_as_closed_step1', { 'OPEN_EXPORT_IDS' => \@open_export_ids, vc => $vc }); $main::lxdebug->leave_sub(); }