Merge branch 'sepa-in'
authorMoritz Bunkus <m.bunkus@linet-services.de>
Fri, 3 Dec 2010 14:35:41 +0000 (15:35 +0100)
committerMoritz Bunkus <m.bunkus@linet-services.de>
Fri, 3 Dec 2010 14:35:41 +0000 (15:35 +0100)
17 files changed:
SL/SEPA.pm
SL/SEPA/XML.pm
SL/SEPA/XML/Transaction.pm
SL/User.pm
bin/mozilla/sepa.pl
locale/de/all
menu.ini
sql/Pg-upgrade2/sepa_in.sql [new file with mode: 0644]
templates/webpages/admin/edit_user.html
templates/webpages/am/config.html
templates/webpages/sepa/bank_transfer_add.html
templates/webpages/sepa/bank_transfer_create.html
templates/webpages/sepa/bank_transfer_created.html
templates/webpages/sepa/bank_transfer_edit.html
templates/webpages/sepa/bank_transfer_list_bottom.html
templates/webpages/sepa/bank_transfer_mark_as_closed_step1.html
templates/webpages/sepa/bank_transfer_search.html

index a5fd4e1..38341ec 100644 (file)
@@ -16,28 +16,31 @@ sub retrieve_open_invoices {
   my $form     = $main::form;
 
   my $dbh      = $params{dbh} || $form->get_standard_dbh($myconfig);
+  my $arap     = $params{vc} eq 'customer' ? 'ar'       : 'ap';
+  my $vc       = $params{vc} eq 'customer' ? 'customer' : 'vendor';
 
   my $query =
     qq|
-       SELECT ap.id, ap.invnumber, ap.vendor_id, ap.amount AS invoice_amount, ap.invoice,
-         v.name AS vendorname, ap.duedate as duedate,
+       SELECT ${arap}.id, ${arap}.invnumber, ${arap}.${vc}_id, ${arap}.amount AS invoice_amount, ${arap}.invoice,
+         vc.name AS vcname, ${arap}.duedate as duedate,
 
-         COALESCE(v.iban, '') <> '' AND COALESCE(v.bic, '') <> '' AS vendor_bank_info_ok,
+         COALESCE(vc.iban, '') <> '' AND COALESCE(vc.bic, '') <> '' AS vc_bank_info_ok,
 
-         ap.amount - ap.paid - COALESCE(open_transfers.amount, 0) AS open_amount
+         ${arap}.amount - ${arap}.paid - COALESCE(open_transfers.amount, 0) AS open_amount
 
-       FROM ap
-       LEFT JOIN vendor v ON (ap.vendor_id = v.id)
+       FROM ${arap}
+       LEFT JOIN ${vc} vc ON (${arap}.${vc}_id = vc.id)
        LEFT JOIN (SELECT sei.ap_id, SUM(sei.amount) AS amount
                   FROM sepa_export_items sei
                   LEFT JOIN sepa_export se ON (sei.sepa_export_id = se.id)
                   WHERE NOT se.closed
+                    AND (se.vc = '${vc}')
                   GROUP BY sei.ap_id)
-         AS open_transfers ON (ap.id = open_transfers.ap_id)
+         AS open_transfers ON (${arap}.id = open_transfers.ap_id)
 
-       WHERE ap.amount > (COALESCE(open_transfers.amount, 0) + ap.paid)
+       WHERE ${arap}.amount > (COALESCE(open_transfers.amount, 0) + ${arap}.paid)
 
-       ORDER BY lower(v.name) ASC, lower(ap.invnumber) ASC
+       ORDER BY lower(vc.name) ASC, lower(${arap}.invnumber) ASC
 |;
 
   my $results = selectall_hashref_query($form, $dbh, $query);
@@ -53,46 +56,49 @@ sub create_export {
   my $self     = shift;
   my %params   = @_;
 
-  Common::check_params(\%params, qw(employee bank_transfers));
+  Common::check_params(\%params, qw(employee bank_transfers vc));
 
   my $myconfig = \%main::myconfig;
   my $form     = $main::form;
+  my $arap     = $params{vc} eq 'customer' ? 'ar'       : 'ap';
+  my $vc       = $params{vc} eq 'customer' ? 'customer' : 'vendor';
+  my $ARAP     = uc $arap;
 
   my $dbh      = $params{dbh} || $form->get_standard_dbh($myconfig);
 
   my ($export_id) = selectfirst_array_query($form, $dbh, qq|SELECT nextval('sepa_export_id_seq')|);
   my $query       =
-    qq|INSERT INTO sepa_export (id, employee_id)
+    qq|INSERT INTO sepa_export (id, employee_id, vc)
        VALUES (?, (SELECT id
                    FROM employee
-                   WHERE login = ?))|;
-  do_query($form, $dbh, $query, $export_id, $params{employee});
+                   WHERE login = ?), ?)|;
+  do_query($form, $dbh, $query, $export_id, $params{employee}, $vc);
 
   my $q_item_id = qq|SELECT nextval('id')|;
   my $h_item_id = prepare_query($form, $dbh, $q_item_id);
 
   my $q_insert =
-    qq|INSERT INTO sepa_export_items (id,          sepa_export_id,           ap_id,       chart_id,
+    qq|INSERT INTO sepa_export_items (id,          sepa_export_id,           ${arap}_id,  chart_id,
                                       amount,      requested_execution_date, reference,   end_to_end_id,
-                                      our_iban,    our_bic,                  vendor_iban, vendor_bic)
+                                      our_iban,    our_bic,                  vc_iban,     vc_bic)
        VALUES                        (?,           ?,                        ?,           ?,
                                       ?,           ?,                        ?,           ?,
                                       ?,           ?,                        ?,           ?)|;
   my $h_insert = prepare_query($form, $dbh, $q_insert);
 
   my $q_reference =
-    qq|SELECT ap.invnumber,
+    qq|SELECT arap.invnumber,
          (SELECT COUNT(at.*)
           FROM acc_trans at
           LEFT JOIN chart c ON (at.chart_id = c.id)
           WHERE (at.trans_id = ?)
-            AND (c.link LIKE '%AP_paid%'))
+            AND (c.link LIKE '%${ARAP}_paid%'))
          +
          (SELECT COUNT(sei.*)
           FROM sepa_export_items sei
           WHERE (sei.ap_id = ?))
          AS num_payments
-       FROM ap
+       FROM ${arap} arap
        WHERE id = ?|;
   my $h_reference = prepare_query($form, $dbh, $q_reference);
 
@@ -100,7 +106,7 @@ sub create_export {
 
   foreach my $transfer (@{ $params{bank_transfers} }) {
     if (!$transfer->{reference}) {
-      do_statement($form, $h_reference, $q_reference, (conv_i($transfer->{ap_id})) x 3);
+      do_statement($form, $h_reference, $q_reference, (conv_i($transfer->{"${arap}_id"})) x 3);
 
       my ($invnumber, $num_payments) = $h_reference->fetchrow_array();
       $num_payments++;
@@ -118,11 +124,11 @@ sub create_export {
     $end_to_end_id    .= $item_id;
     $end_to_end_id     = substr $end_to_end_id, 0, 35;
 
-    my @values = ($item_id,                   $export_id,
-                  conv_i($transfer->{ap_id}), conv_i($transfer->{chart_id}),
-                  $transfer->{amount},        conv_date($transfer->{requested_execution_date}),
-                  $transfer->{reference},     $end_to_end_id,
-                  map { my $pfx = $_; map { $transfer->{"${pfx}_${_}"} } qw(iban bic) } qw(our vendor));
+    my @values = ($item_id,                          $export_id,
+                  conv_i($transfer->{"${arap}_id"}), conv_i($transfer->{chart_id}),
+                  $transfer->{amount},               conv_date($transfer->{requested_execution_date}),
+                  $transfer->{reference},            $end_to_end_id,
+                  map { my $pfx = $_; map { $transfer->{"${pfx}_${_}"} } qw(iban bic) } qw(our vc));
 
     do_statement($form, $h_insert, $q_insert, @values);
   }
@@ -143,18 +149,20 @@ sub retrieve_export {
   my $self     = shift;
   my %params   = @_;
 
-  Common::check_params(\%params, qw(id));
+  Common::check_params(\%params, qw(id vc));
 
   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);
 
   my ($joins, $columns);
 
   if ($params{details}) {
-    $columns = ', ap.invoice';
-    $joins   = 'LEFT JOIN ap ON (se.ap_id = ap.id)';
+    $columns = ', arap.invoice';
+    $joins   = "LEFT JOIN ${arap} arap ON (se.${arap}_id = arap.id)";
   }
 
   my $query =
@@ -170,10 +178,10 @@ sub retrieve_export {
     my ($columns, $joins);
 
     if ($params{details}) {
-      $columns = qq|, ap.invnumber, ap.invoice, v.name AS vendor_name, c.accno AS chart_accno, c.description AS chart_description|;
-      $joins   = qq|LEFT JOIN ap       ON (sei.ap_id    = ap.id)
-                    LEFT JOIN vendor v ON (ap.vendor_id = v.id)
-                    LEFT JOIN chart c  ON (sei.chart_id = c.id)|;
+      $columns = qq|, arap.invnumber, arap.invoice, arap.transdate AS reference_date, vc.name AS vc_name, c.accno AS chart_accno, c.description AS chart_description|;
+      $joins   = qq|LEFT JOIN ${arap} arap ON (sei.${arap}_id = arap.id)
+                    LEFT JOIN ${vc} vc     ON (arap.${vc}_id  = vc.id)
+                    LEFT JOIN chart c      ON (sei.chart_id   = c.id)|;
     }
 
     $query = qq|SELECT sei.*
@@ -181,6 +189,7 @@ sub retrieve_export {
                 FROM sepa_export_items sei
                 $joins
                 WHERE sei.sepa_export_id = ?|;
+
     $export->{items} = selectall_hashref_query($form, $dbh, $query, conv_i($params{id}));
 
   } else {
@@ -224,6 +233,8 @@ sub list_exports {
 
   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);
 
@@ -255,16 +266,16 @@ sub list_exports {
   }
 
   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)) {
@@ -277,8 +288,8 @@ sub list_exports {
 
   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);
 
@@ -291,6 +302,9 @@ sub list_exports {
     push @values, @values_sub;
   }
 
+  push @where,  'se.vc = ?';
+  push @values, $vc;
+
   my $where = ' WHERE ' . join(' AND ', map { "(${_})" } @where) if (@where);
 
   my $query =
@@ -322,6 +336,10 @@ sub post_payment {
 
   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 $mult     = $params{vc} eq 'customer' ? -1         : 1;
+  my $ARAP     = uc $arap;
 
   my $dbh      = $params{dbh} || $form->get_standard_dbh($myconfig);
 
@@ -332,17 +350,17 @@ sub post_payment {
                              FROM sepa_export_items sei
                              WHERE sei.id = ?| ],
 
-    'get_ap'         => [ qq|SELECT at.chart_id
+    'get_arap'       => [ qq|SELECT at.chart_id
                              FROM acc_trans at
                              LEFT JOIN chart c ON (at.chart_id = c.id)
                              WHERE (trans_id = ?)
-                               AND ((c.link LIKE '%:AP') OR (c.link LIKE 'AP:%') OR (c.link = 'AP'))
+                               AND ((c.link LIKE '%:${ARAP}') OR (c.link LIKE '${ARAP}:%') OR (c.link = '${ARAP}'))
                              LIMIT 1| ],
 
     'add_acc_trans'  => [ qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, gldate,       source, memo)
                              VALUES                (?,        ?,        ?,      ?,         current_date, ?,      '')| ],
 
-    'update_ap'      => [ qq|UPDATE ap
+    'update_arap'    => [ qq|UPDATE ${arap}
                              SET paid = paid + ?
                              WHERE id = ?| ],
 
@@ -374,16 +392,16 @@ sub post_payment {
 
     next if (!$orig_item);
 
-    # Retrieve the invoice's AP chart ID.
-    do_statement($form, @{ $handles{get_ap} }, $orig_item->{ap_id});
-    my ($ap_chart_id) = $handles{get_ap}->[0]->fetchrow_array();
+    # Retrieve the invoice's AR/AP chart ID.
+    do_statement($form, @{ $handles{get_arap} }, $orig_item->{"${arap}_id"});
+    my ($arap_chart_id) = $handles{get_arap}->[0]->fetchrow_array();
 
-    # Record the payment in acc_trans offsetting AP.
-    do_statement($form, @{ $handles{add_acc_trans} }, $orig_item->{ap_id}, $ap_chart_id,           -1 * $orig_item->{amount}, $item->{execution_date}, '');
-    do_statement($form, @{ $handles{add_acc_trans} }, $orig_item->{ap_id}, $orig_item->{chart_id},      $orig_item->{amount}, $item->{execution_date}, $orig_item->{reference});
+    # Record the payment in acc_trans offsetting AR/AP.
+    do_statement($form, @{ $handles{add_acc_trans} }, $orig_item->{"${arap}_id"}, $arap_chart_id,         -1 * $mult * $orig_item->{amount}, $item->{execution_date}, '');
+    do_statement($form, @{ $handles{add_acc_trans} }, $orig_item->{"${arap}_id"}, $orig_item->{chart_id},      $mult * $orig_item->{amount}, $item->{execution_date}, $orig_item->{reference});
 
     # Update the invoice to reflect the new paid amount.
-    do_statement($form, @{ $handles{update_ap} }, $orig_item->{amount}, $orig_item->{ap_id});
+    do_statement($form, @{ $handles{update_arap} }, $orig_item->{amount}, $orig_item->{"${arap}_id"});
 
     # Update the item to reflect that it has been posted.
     do_statement($form, @{ $handles{finish_item} }, $item->{execution_date}, $item_id);
index ddac25e..2c7f632 100644 (file)
@@ -32,14 +32,15 @@ sub _init {
   $self->{src_charset}  = 'UTF-8';
   $self->{grouped}      = 0;
 
-  map { $self->{$_} = $params{$_} if (exists $params{$_}) } qw(src_charset company message_id grouped);
+  map { $self->{$_} = $params{$_} if (exists $params{$_}) } qw(src_charset company creditor_id message_id grouped collection);
 
   $self->{iconv} = SL::Iconv->new($self->{src_charset}, "UTF-8") || croak "Unsupported source charset $self->{src_charset}.";
 
   my $missing_parameter = first { !$self->{$_} } qw(company message_id);
   croak "Missing parameter: $missing_parameter" if ($missing_parameter);
+  croak "Missing parameter: creditor_id"        if !$self->{creditor_id} && $self->{collection};
 
-  map { $self->{$_} = $self->_replace_special_chars($self->{iconv}->convert($self->{$_})) } qw(company message_id);
+  map { $self->{$_} = $self->_replace_special_chars($self->{iconv}->convert($self->{$_})) } qw(company message_id creditor_id);
 }
 
 sub add_transaction {
@@ -77,7 +78,7 @@ sub _format_amount {
   my $self   = shift;
   my $amount = shift;
 
-  return sprintf '%d.%02d', int($amount), int($amount * 100) % 100;
+  return sprintf '%.02f', $amount;
 }
 
 sub _group_transactions {
@@ -116,19 +117,27 @@ sub to_xml {
                                 DATA_INDENT => 2,
                                 ENCODING    => 'utf-8');
 
-  my @now        = localtime;
-  my $time_zone  = strftime "%z", @now;
-  my $now_str    = strftime('%Y-%m-%dT%H:%M:%S', @now) . substr($time_zone, 0, 3) . ':' . substr($time_zone, 3, 2);
+  my @now       = localtime;
+  my $time_zone = strftime "%z", @now;
+  my $now_str   = strftime('%Y-%m-%dT%H:%M:%S', @now) . substr($time_zone, 0, 3) . ':' . substr($time_zone, 3, 2);
+
+  my $is_coll   = $self->{collection};
+  my $cd_src    = $is_coll ? 'Cdtr' : 'Dbtr';
+  my $cd_dst    = $is_coll ? 'Dbtr' : 'Cdtr';
+  my $pain_id   = $is_coll ? 'pain.008.002.01' : 'pain.001.001.02';
+  my $pain_elmt = $is_coll ? 'pain.008.001.01' : 'pain.001.001.02';
+  my @pii_base  = (strftime('PII%Y%m%d%H%M%S', @now), rand(1000000000));
 
   my $grouped_transactions = $self->_group_transactions();
 
   $xml->xmlDecl();
+
   $xml->startTag('Document',
-                 'xmlns'              => 'urn:sepade:xsd:pain.001.001.02.grp',
+                 'xmlns'              => "urn:swift:xsd:\$${pain_id}",
                  'xmlns:xsi'          => 'http://www.w3.org/2001/XMLSchema-instance',
-                 'xsi:schemaLocation' => 'urn:sepade:xsd:pain.001.001.02.grp pain.001.001.02.grp.xsd');
+                 'xsi:schemaLocation' => "urn:swift:xsd:\$${pain_id} ${pain_id}.xsd");
 
-  $xml->startTag('pain.001.001.02');
+  $xml->startTag($pain_elmt);
 
   $xml->startTag('GrpHdr');
   $xml->dataElement('MsgId', encode('UTF-8', substr($self->{message_id}, 0, 35)));
@@ -148,73 +157,111 @@ sub to_xml {
     my $master_transaction = $transaction_group->{transactions}->[0];
 
     $xml->startTag('PmtInf');
-    $xml->dataElement('PmtMtd', 'TRF');
+    if ($is_coll) {
+      $xml->dataElement('PmtInfId', sprintf('%s%010d', @pii_base));
+      $pii_base[1]++;
+    }
+    $xml->dataElement('PmtMtd', $is_coll ? 'DD' : 'TRF');
 
     $xml->startTag('PmtTpInf');
     $xml->startTag('SvcLvl');
     $xml->dataElement('Cd', 'SEPA');
     $xml->endTag('SvcLvl');
+
+    if ($is_coll) {
+      $xml->startTag('LclInstrm');
+      $xml->dataElement('Cd', 'CORE');
+      $xml->endTag('LclInstrm');
+      $xml->dataElement('SeqTp', 'OOFF');
+    }
     $xml->endTag('PmtTpInf');
 
-    $xml->dataElement('ReqdExctnDt', $master_transaction->get('execution_date'));
-    $xml->startTag('Dbtr');
+    $xml->dataElement($is_coll ? 'ReqdColltnDt' : 'ReqdExctnDt', $master_transaction->get('execution_date'));
+    $xml->startTag($cd_src);
     $xml->dataElement('Nm', encode('UTF-8', substr($self->{company}, 0, 70)));
-    $xml->endTag('Dbtr');
+    $xml->endTag($cd_src);
 
-    $xml->startTag('DbtrAcct');
+    $xml->startTag($cd_src . 'Acct');
     $xml->startTag('Id');
     $xml->dataElement('IBAN', $master_transaction->get('src_iban', 34));
     $xml->endTag('Id');
-    $xml->endTag('DbtrAcct');
+    $xml->endTag($cd_src . 'Acct');
 
-    $xml->startTag('DbtrAgt');
+    $xml->startTag($cd_src . 'Agt');
     $xml->startTag('FinInstnId');
     $xml->dataElement('BIC', $master_transaction->get('src_bic', 20));
     $xml->endTag('FinInstnId');
-    $xml->endTag('DbtrAgt');
+    $xml->endTag($cd_src . 'Agt');
 
     $xml->dataElement('ChrgBr', 'SLEV');
 
     foreach my $transaction (@{ $transaction_group->{transactions} }) {
-      $xml->startTag('CdtTrfTxInf');
+      $xml->startTag($is_coll ? 'DrctDbtTxInf' : 'CdtTrfTxInf');
 
       $xml->startTag('PmtId');
       $xml->dataElement('EndToEndId', $transaction->get('end_to_end_id', 35));
       $xml->endTag('PmtId');
 
-      $xml->startTag('Amt');
-      $xml->startTag('InstdAmt', 'Ccy' => 'EUR');
-      $xml->characters($self->_format_amount($transaction->{amount}));
-      $xml->endTag('InstdAmt');
-      $xml->endTag('Amt');
-
-      $xml->startTag('CdtrAgt');
+      if ($is_coll) {
+        $xml->startTag('InstdAmt', 'Ccy' => 'EUR');
+        $xml->characters($self->_format_amount($transaction->{amount}));
+        $xml->endTag('InstdAmt');
+
+        $xml->startTag('DrctDbtTx');
+
+        $xml->startTag('MndtRltdInf');
+        $xml->dataElement('MndtId', $transaction->get('reference', 35));
+        $xml->dataElement('DtOfSgntr', $transaction->get('reference_date', 2010-12-02));
+        $xml->endTag('MndtRltdInf');
+
+        $xml->startTag('CdtrSchmeId');
+        $xml->startTag('Id');
+        $xml->startTag('PrvtId');
+        $xml->startTag('OthrId');
+        $xml->dataElement('Id', encode('UTF-8', substr($self->{creditor_id}, 0, 35)));
+        $xml->dataElement('IdTp', 'SEPA');
+        $xml->endTag('OthrId');
+        $xml->endTag('PrvtId');
+        $xml->endTag('Id');
+        $xml->endTag('CdtrSchmeId');
+
+        $xml->endTag('DrctDbtTx');
+
+      } else {
+        $xml->startTag('Amt');
+        $xml->startTag('InstdAmt', 'Ccy' => 'EUR');
+        $xml->characters($self->_format_amount($transaction->{amount}));
+        $xml->endTag('InstdAmt');
+        $xml->endTag('Amt');
+      }
+
+      $xml->startTag("${cd_dst}Agt");
       $xml->startTag('FinInstnId');
       $xml->dataElement('BIC', $transaction->get('dst_bic', 20));
       $xml->endTag('FinInstnId');
-      $xml->endTag('CdtrAgt');
+      $xml->endTag("${cd_dst}Agt");
 
-      $xml->startTag('Cdtr');
-      $xml->dataElement('Nm', $transaction->get('recipient', 70));
-      $xml->endTag('Cdtr');
+      $xml->startTag("${cd_dst}");
+      $xml->dataElement('Nm', $transaction->get('company', 70));
+      $xml->endTag("${cd_dst}");
 
-      $xml->startTag('CdtrAcct');
+      $xml->startTag("${cd_dst}Acct");
       $xml->startTag('Id');
       $xml->dataElement('IBAN', $transaction->get('dst_iban', 34));
       $xml->endTag('Id');
-      $xml->endTag('CdtrAcct');
+      $xml->endTag("${cd_dst}Acct");
 
       $xml->startTag('RmtInf');
       $xml->dataElement('Ustrd', $transaction->get('reference', 140));
       $xml->endTag('RmtInf');
 
-      $xml->endTag('CdtTrfTxInf');
+      $xml->endTag($is_coll ? 'DrctDbtTxInf' : 'CdtTrfTxInf');
     }
 
     $xml->endTag('PmtInf');
   }
 
-  $xml->endTag('pain.001.001.02');
+  $xml->endTag($pain_elmt);
   $xml->endTag('Document');
 
   return $output;
index be444af..83a749e 100644 (file)
@@ -25,7 +25,7 @@ sub _init {
   $self->{sepa}  = $params{sepa};
   delete $params{sepa};
 
-  my $missing_parameter = first { !$params{$_} } qw(src_iban src_bic dst_iban dst_bic recipient reference amount end_to_end_id);
+  my $missing_parameter = first { !$params{$_} } qw(src_iban src_bic dst_iban dst_bic company reference amount end_to_end_id);
   croak "Missing parameter: $missing_parameter" if ($missing_parameter);
 
   $params{end_to_end_id}  ||= 'NOTPROVIDED';
@@ -35,7 +35,7 @@ sub _init {
 
   map { $self->{$_} = $self->{sepa}->{iconv}->convert($params{$_})       } keys %params;
   map { $self->{$_} =~ s/\s+//g                                          } qw(src_iban src_bic dst_iban dst_bic);
-  map { $self->{$_} = $self->{sepa}->_replace_special_chars($self->{$_}) } qw(recipient reference end_to_end_id);
+  map { $self->{$_} = $self->{sepa}->_replace_special_chars($self->{$_}) } qw(company reference end_to_end_id);
 }
 
 sub get {
index 46fe855..b1a904a 100644 (file)
@@ -1000,7 +1000,8 @@ sub config_vars {
     bestellungen rechnungen anfragen lieferantenbestellungen einkaufsrechnungen
     taxnumber co_ustid duns menustyle template_format default_media
     default_printer_id copies show_form_details favorites
-    pdonumber sdonumber hide_cvar_search_options mandatory_departments);
+    pdonumber sdonumber hide_cvar_search_options mandatory_departments
+    sepa_creditor_id);
 
   $main::lxdebug->leave_sub();
 
index bf220e3..7971b7d 100755 (executable)
@@ -20,8 +20,9 @@ sub bank_transfer_add {
 
   my $form          = $main::form;
   my $locale        = $main::locale;
+  my $vc            = $form->{vc} eq 'customer' ? 'customer' : 'vendor';
 
-  $form->{title}    = $locale->text('Prepare bank transfer via SEPA XML');
+  $form->{title}    = $vc eq 'customer' ? $::locale->text('Prepare bank collection via SEPA XML') : $locale->text('Prepare bank transfer via SEPA XML');
 
   my $bank_accounts = SL::BankAccount->list();
 
@@ -29,7 +30,7 @@ sub bank_transfer_add {
     $form->error($locale->text('You have not added bank accounts yet.'));
   }
 
-  my $invoices = SL::SEPA->retrieve_open_invoices();
+  my $invoices = SL::SEPA->retrieve_open_invoices(vc => $vc);
 
   if (!scalar @{ $invoices }) {
     $form->show_generic_information($locale->text('Either there are no open invoices, or you have already initiated bank transfers ' .
@@ -44,7 +45,9 @@ sub bank_transfer_add {
   print $form->parse_html_template('sepa/bank_transfer_add',
                                    { 'INVOICES'           => $invoices,
                                      'BANK_ACCOUNTS'      => $bank_accounts,
-                                     'bank_account_label' => $bank_account_label_sub, });
+                                     'bank_account_label' => $bank_account_label_sub,
+                                     'vc'                 => $vc,
+                                   });
 
   $main::lxdebug->leave_sub();
 }
@@ -55,8 +58,9 @@ sub bank_transfer_create {
   my $form          = $main::form;
   my $locale        = $main::locale;
   my $myconfig      = \%main::myconfig;
+  my $vc            = $form->{vc} eq 'customer' ? 'customer' : 'vendor';
 
-  $form->{title}    = $locale->text('Create bank transfer via SEPA XML');
+  $form->{title}    = $vc eq 'customer' ? $::locale->text('Create bank collection via SEPA XML') : $locale->text('Create bank transfer via SEPA XML');
 
   my $bank_accounts = SL::BankAccount->list();
 
@@ -70,11 +74,13 @@ sub bank_transfer_create {
     $form->error($locale->text('The selected bank account does not exist anymore.'));
   }
 
-  my $invoices       = SL::SEPA->retrieve_open_invoices();
+  my $arap_id        = $vc eq 'customer' ? 'ar_id' : 'ap_id';
+  my $invoices       = SL::SEPA->retrieve_open_invoices(vc => $vc);
+
   my %invoices_map   = map { $_->{id} => $_ } @{ $invoices };
   my @bank_transfers =
-    map  +{ %{ $invoices_map{ $_->{ap_id} } }, %{ $_ } },
-    grep  { $_->{selected} && (0 < $_->{amount}) && $invoices_map{ $_->{ap_id} } }
+    map  +{ %{ $invoices_map{ $_->{$arap_id} } }, %{ $_ } },
+    grep  { $_->{selected} && (0 < $_->{amount}) && $invoices_map{ $_->{$arap_id} } }
     map   { $_->{amount} = $form->parse_amount($myconfig, $_->{amount}); $_ }
           @{ $form->{bank_transfers} || [] };
 
@@ -82,13 +88,13 @@ sub bank_transfer_create {
     $form->error($locale->text('You have selected none of the invoices.'));
   }
 
-  my ($vendor_bank_info);
+  my ($vc_bank_info);
   my $error_message;
 
   if ($form->{confirmation}) {
-    $vendor_bank_info = { map { $_->{id} => $_ } @{ $form->{vendor_bank_info} || [] } };
+    $vc_bank_info = { map { $_->{id} => $_ } @{ $form->{vc_bank_info} || [] } };
 
-    foreach my $info (values %{ $vendor_bank_info }) {
+    foreach my $info (values %{ $vc_bank_info }) {
       if (any { !$info->{$_} } qw(iban bic)) {
         $error_message = $locale->text('The bank information must not be empty.');
         last;
@@ -97,10 +103,10 @@ sub bank_transfer_create {
   }
 
   if ($error_message || !$form->{confirmation}) {
-    my @vendor_ids             = uniq map { $_->{vendor_id} } @bank_transfers;
-    $vendor_bank_info        ||= CT->get_bank_info('vc' => 'vendor',
-                                                   'id' => \@vendor_ids);
-    my @vendor_bank_info       = sort { lc $a->{name} cmp lc $b->{name} } values %{ $vendor_bank_info };
+    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 };
 
     my $bank_account_label_sub = sub { $locale->text('Account number #1, bank code #2, #3', $_[0]->{account_number}, $_[0]->{bank_code}, $_[0]->{bank}) };
 
@@ -110,27 +116,29 @@ sub bank_transfer_create {
     print $form->parse_html_template('sepa/bank_transfer_create',
                                      { 'BANK_TRANSFERS'     => \@bank_transfers,
                                        'BANK_ACCOUNTS'      => $bank_accounts,
-                                       'VENDOR_BANK_INFO'   => \@vendor_bank_info,
+                                       'VC_BANK_INFO'       => \@vc_bank_info,
                                        'bank_account'       => $bank_account,
                                        'bank_account_label' => $bank_account_label_sub,
                                        'error_message'      => $error_message,
+                                       'vc'                 => $vc,
                                      });
 
   } else {
     foreach my $bank_transfer (@bank_transfers) {
       foreach (qw(iban bic)) {
-        $bank_transfer->{"vendor_${_}"} = $vendor_bank_info->{ $bank_transfer->{vendor_id} }->{$_};
-        $bank_transfer->{"our_${_}"}    = $bank_account->{$_};
+        $bank_transfer->{"vc_${_}"}  = $vc_bank_info->{ $bank_transfer->{"${vc}_id"} }->{$_};
+        $bank_transfer->{"our_${_}"} = $bank_account->{$_};
       }
 
       $bank_transfer->{chart_id} = $bank_account->{chart_id};
     }
 
     my $id = SL::SEPA->create_export('employee'       => $form->{login},
-                                     'bank_transfers' => \@bank_transfers);
+                                     'bank_transfers' => \@bank_transfers,
+                                     'vc'             => $vc);
 
     $form->header();
-    print $form->parse_html_template('sepa/bank_transfer_created', { 'id' => $id });
+    print $form->parse_html_template('sepa/bank_transfer_created', { 'id' => $id, 'vc' => $vc });
   }
 
   $main::lxdebug->leave_sub();
@@ -141,12 +149,13 @@ sub bank_transfer_search {
 
   my $form   = $main::form;
   my $locale = $main::locale;
+  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->{jsscript} = 1;
 
   $form->header();
-  print $form->parse_html_template('sepa/bank_transfer_search');
+  print $form->parse_html_template('sepa/bank_transfer_search', { vc => $vc });
 
   $main::lxdebug->leave_sub();
 }
@@ -158,17 +167,18 @@ sub bank_transfer_list {
   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});
@@ -176,13 +186,14 @@ sub bank_transfer_list {
 
   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);
 
@@ -202,12 +213,12 @@ sub bank_transfer_list {
     $column_defs{$name}->{link} = $href . "&sort=$name&sortdir=$sortdir";
   }
 
-  $column_defs{selected}->{visible} = $open_available                                ? 1 : 0;
+  $column_defs{selected}->{visible} = $open_available                                ? 'HTML' : 0;
   $column_defs{executed}->{visible} = $form->{l_executed} && $form->{l_not_executed} ? 1 : 0;
   $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});
@@ -220,7 +231,7 @@ sub bank_transfer_list {
 
   $report->set_options('top_info_text'         => join("\n", @options),
                        'raw_top_info_text'     => $form->parse_html_template('sepa/bank_transfer_list_top'),
-                       'raw_bottom_info_text'  => $form->parse_html_template('sepa/bank_transfer_list_bottom', { 'show_buttons' => $open_available }),
+                       'raw_bottom_info_text'  => $form->parse_html_template('sepa/bank_transfer_list_bottom', { 'show_buttons' => $open_available, vc => $vc }),
                        'std_column_visibility' => 1,
                        'output_format'         => 'HTML',
                        'title'                 => $form->{title},
@@ -240,7 +251,7 @@ sub bank_transfer_list {
 
     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} =
@@ -261,6 +272,7 @@ sub bank_transfer_edit {
 
   my $form   = $main::form;
   my $locale = $main::locale;
+  my $vc     = $form->{vc} eq 'customer' ? 'customer' : 'vendor';
 
   my @ids    = ();
   if (!$form->{mode} || ($form->{mode} eq 'single')) {
@@ -276,7 +288,7 @@ sub bank_transfer_edit {
   my $export;
 
   foreach my $id (@ids) {
-    my $curr_export = SL::SEPA->retrieve_export('id' => $id, 'details' => 1);
+    my $curr_export = SL::SEPA->retrieve_export('id' => $id, 'details' => 1, 'vc' => $vc);
 
     foreach my $item (@{ $curr_export->{items} }) {
       map { $item->{"export_${_}"} = $curr_export->{$_} } grep { !ref $curr_export->{$_} } keys %{ $curr_export };
@@ -318,6 +330,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} || [] };
 
@@ -325,7 +338,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) {
@@ -343,7 +356,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.'));
 
@@ -356,13 +369,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) {
@@ -375,25 +389,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);
@@ -411,6 +425,7 @@ sub bank_transfer_payment_list_as_pdf {
   $main::lxdebug->leave_sub();
 }
 
+# TODO
 sub bank_transfer_download_sepa_xml {
   $main::lxdebug->enter_sub();
 
@@ -418,11 +433,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} || [] };
@@ -438,7 +458,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});
   }
 
@@ -449,9 +469,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},
+                                      'creditor_id' => $myconfig->{sepa_creditor_id},
                                       'src_charset' => $main::dbcharset || 'ISO-8859-15',
                                       'message_id'  => $message_id,
                                       'grouped'     => 1,
+                                      'collection'  => $vc eq 'customer',
     );
 
   foreach my $item (@items) {
@@ -461,13 +483,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} });
   }
@@ -475,7 +503,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;
 
@@ -487,6 +515,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} || [] };
 
@@ -496,7 +525,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});
   }
 
@@ -506,7 +535,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();
 }
index 1affa31..55eb698 100644 (file)
@@ -197,6 +197,7 @@ $self->{texts} = {
   'Are you sure you want to update the prices' => 'Sind Sie sicher, dass Sie die Preise aktualisieren wollen?',
   'Article Code'                => 'Artikelkürzel',
   'Article Code missing!'       => 'Artikelkürzel fehlt',
+  'Artikel'                     => '',
   'As a result, the saved onhand values of the present goods can be stored into a warehouse designated by you, or will be reset for a proper warehouse tracking' => 'Als Konsequenz k&ouml;nnen die gespeicherten Mengen entweder in ein Lager &uuml;berf&uuml;hrt werden, oder f&uuml;r eine frische Lagerverwaltung resettet werden.',
   'Assemblies'                  => 'Erzeugnisse',
   'Assembly Description'        => 'Erzeugnis-Beschreibung',
@@ -242,6 +243,10 @@ $self->{texts} = {
   'Bank Connections'            => 'Bankverbindungen',
   'Bank accounts'               => 'Bankkonten',
   'Bank code'                   => 'Bankleitzahl',
+  'Bank collection amount'      => 'Einzugsbetrag',
+  'Bank collection payment list for export #1' => 'Bankeinzugszahlungsliste für SEPA-Export #1',
+  'Bank collection via SEPA'    => 'Bankeinzug via SEPA',
+  'Bank collections via SEPA'   => 'Bankeinzüge via SEPA',
   'Bank transfer amount'        => 'Ãœberweisungssumme',
   'Bank transfer payment list for export #1' => 'Ãœberweisungszahlungsliste für SEPA-Export #1',
   'Bank transfer via SEPA'      => 'Ãœberweisung via SEPA',
@@ -416,6 +421,8 @@ $self->{texts} = {
   'Create and edit sales orders' => 'Auftragsbest&auml;tigungen erfassen und bearbeiten',
   'Create and edit sales quotations' => 'Angebote erfassen und bearbeiten',
   'Create and edit vendor invoices' => 'Eingangsrechnungen erfassen und bearbeiten',
+  'Create bank collection'      => 'Bankeinzug erstellen',
+  'Create bank collection via SEPA XML' => 'Bankeinzug via SEPA XML erstellen',
   'Create bank transfer'        => 'Ãœberweisung erstellen',
   'Create bank transfer via SEPA XML' => 'Ãœberweisung via SEPA XML erzeugen',
   'Create invoice?'             => 'Rechnung erstellen?',
@@ -550,6 +557,7 @@ $self->{texts} = {
   'Display'                     => 'Anzeigen',
   'Display file'                => 'Datei anzeigen',
   'Display options'             => 'Anzeigeoptionen',
+  'Do you really want to close the following SEPA exports? No payment will be recorded for bank collections that haven\'t been marked as executed yet.' => 'Wollen Sie wirklich die folgenden SEPA-Exporte abschließen? Für Ãœberweisungen, die noch nicht gebucht wurden, werden dann keine Zahlungen verbucht.',
   'Do you really want to close the following SEPA exports? No payment will be recorded for bank transfers that haven\'t been marked as executed yet.' => 'Wollen Sie wirklich die folgenden SEPA-Exporte abschließen? Für Ãœberweisungen, die noch nicht gebucht wurden, werden dann keine Zahlungen verbucht.',
   'Do you really want to delete AP transaction #1?' => 'Wollen Sie wirklich die Kreditorenbuchung #1 löschen?',
   'Do you really want to delete AR transaction #1?' => 'Wollen Sie wirklich die Debitorenbuchung #1 löschen?',
@@ -595,7 +603,6 @@ $self->{texts} = {
   'EAN-Code'                    => 'EAN-Code',
   'EB-Wert'                     => 'EB-Wert',
   'EK'                          => 'EK',
-  'EK-Preis'                    => 'Purchase price',
   'ELSE'                        => 'Zusatz',
   'ELSTER Export (Taxbird)'     => 'ELSTER-Export nach Taxbird',
   'ELSTER Export (Winston)'     => 'ELSTER Export nach Winston',
@@ -952,6 +959,7 @@ $self->{texts} = {
   'List bank accounts'          => 'Bankkonten anzeigen',
   'List export'                 => 'Export anzeigen',
   'List of bank accounts'       => 'Liste der Bankkonten',
+  'List of bank collections'    => 'Bankeinzugsliste',
   'List of bank transfers'      => 'Ãœberweisungsliste',
   'List of custom variables'    => 'Liste der benutzerdefinierten Variablen',
   'List open SEPA exports'      => 'Noch nicht ausgeführte SEPA-Exporte anzeigen',
@@ -1061,6 +1069,7 @@ $self->{texts} = {
   'No Vendor was found matching the search parameters.' => 'Zu dem Suchbegriff wurde kein Händler gefunden',
   'No action defined.'          => 'Keine Aktion definiert.',
   'No backup file has been uploaded.' => 'Es wurde keine Sicherungsdatei hochgeladen.',
+  'No bank information has been entered in this customer\'s master data entry. You cannot create bank collections unless you enter bank information.' => 'Für diesen Kunden wurden in seinen Stammdaten keine Kontodaten hinterlegt. Solange dies nicht geschehen ist, können Sie keine Ãœberweisungen für den Lieferanten anlegen.',
   'No bank information has been entered in this vendor\'s master data entry. You cannot create bank transfers unless you enter bank information.' => 'Für diesen Lieferanten wurden in seinen Stammdaten keine Kontodaten hinterlegt. Solange dies nicht geschehen ist, können Sie keine Ãœberweisungen für den Lieferanten anlegen.',
   'No bins have been added to this warehouse yet.' => 'Es wurden zu diesem Lager noch keine Lagerpl&auml;tze angelegt.',
   'No customer has been selected yet.' => 'Es wurde noch kein Kunde ausgewählt.',
@@ -1198,6 +1207,7 @@ $self->{texts} = {
   'Phone1'                      => 'Telefon 1 ',
   'Phone2'                      => 'Telefon 2',
   'Pick List'                   => 'Sammelliste',
+  'Please Check the bank information for each customer:' => 'Bitte Ã¼berprüfen Sie die Bankinformationen der Kunden:',
   'Please Check the bank information for each vendor:' => 'Bitte Ã¼berprüfen Sie die Kontoinformationen der Lieferanten:',
   'Please ask your administrator to create warehouses and bins.' => 'Bitten Sie Ihren Administrator, dass er Lager und Lagerpl&auml;tze anlegt.',
   'Please enter a license key.' => 'Bitte geben Sie einen Lizenzschlüssel an.',
@@ -1219,6 +1229,7 @@ $self->{texts} = {
   'Please select a vendor from the list below.' => 'Bitte einen Händler aus der Liste auswählen',
   'Please select the chart of accounts this installation is using from the list below.' => 'Bitte w&auml;hlen Sie den Kontenrahmen aus, der bei dieser Installation verwendet wird.',
   'Please select the database you want to backup' => 'Bitte w&auml;hlen Sie die zu sichernde Datenbank gefunden',
+  'Please select the destination bank account for the collections:' => 'Bitte wählen Sie das Bankkonto als Ziel für die Einzüge aus:',
   'Please select the source bank account for the transfers:' => 'Bitte wählen Sie das Bankkonto als Quelle für die Ãœberweisungen aus:',
   'Please seletct the dataset you want to delete:' => 'Bitte w&auml;hlen Sie die zu l&ouml;schende Datenbank aus:',
   'Please specify a description for the warehouse designated for these goods.' => 'Bitte geben Sie den Namen des Ziellagers f&uuml;r die &uuml;bernommenen Daten ein.',
@@ -1236,6 +1247,7 @@ $self->{texts} = {
   'Preis'                       => 'Preis',
   'Preisgruppe'                 => 'Preisgruppe',
   'Preisklasse'                 => 'Preisgruppe',
+  'Prepare bank collection via SEPA XML' => 'Einzug via SEPA XML vorbereiten',
   'Prepare bank transfer via SEPA XML' => 'Ãœberweisung via SEPA XML vorbereiten',
   'Prepayment'                  => 'Vorauszahlung',
   'Preview'                     => 'Druckvorschau',
@@ -1372,6 +1384,7 @@ $self->{texts} = {
   'SAVED FOR DUNNING'           => 'Gespeichert',
   'SCREENED'                    => 'Angezeigt',
   'SEPA XML download'           => 'SEPA-XML-Download',
+  'SEPA creditor ID'            => 'SEPA-Kreditoren-Identifikation',
   'SEPA exports:'               => 'SEPA-Exporte:',
   'Saldo Credit'                => 'Saldo Haben',
   'Saldo Debit'                 => 'Saldo Soll',
@@ -1910,6 +1923,7 @@ $self->{texts} = {
   'You have to create at least one group, grant it access to Lx-Office\'s functions and assign users to it.' => 'Sie m&uuml;ssen mindestens eine Benutzergruppe anlegen, ihr Zugriff auf die verschiedenen Funktionsbereiche von Lx-Office gew&auml;hren und Benutzer dieser Gruppe zuordnen.',
   'You have to create new Buchungsgruppen for all the combinations of inventory, income and expense accounts that have been used already.' => 'Sie m&uuml;ssen neue Buchungsgruppen f&uuml;r alle Kombinationen aus Inventar-, Erl&ouml;s- und Aufwandskonto, die bereits benutzt wurden.',
   'You have to enter a company name in your user preferences (see the "Program" menu, "Preferences").' => 'Sie müssen einen Firmennamen in Ihren Einstellungen angeben (siehe Menü "Programm", "Einstellungen").',
+  'You have to enter the SEPA creditor ID in your user preferences (see the "Program" menu, "Preferences").' => 'Sie müssen die SEPA-Kreditoren-Identifikation in Ihren Einstellungen angeben (siehe Menü "Programm", "Einstellungen").',
   'You have to fill in at least an account number, the bank code, the IBAN and the BIC.' => 'Sie müssen zumindest die Kontonummer, die Bankleitzahl, die IBAN und den BIC angeben.',
   'You have to specify a department.' => 'Sie müssen eine Abteilung wählen.',
   'You have to specify an execution date for each antry.' => 'Sie müssen für jeden zu buchenden Eintrag ein Ausführungsdatum angeben.',
@@ -1937,7 +1951,8 @@ $self->{texts} = {
   'as at'                       => 'zum Stand',
   'assembly_list'               => 'erzeugnisliste',
   'back'                        => 'zurück',
-  'bank_transfer_payment_list_#1' => 'ueberweisungs_zahlungsliste_#1',
+  'bank_collection_payment_list_#1' => 'bankeinzugszahlungsliste_#1',
+  'bank_transfer_payment_list_#1' => 'ueberweisungszahlungsliste_#1',
   'bankaccounts'                => 'Bankkonten',
   'banktransfers'               => 'ueberweisungen',
   'bestbefore #1'               => 'Mindesthaltbarkeit #1',
index ffb523f..dd763b2 100644 (file)
--- a/menu.ini
+++ b/menu.ini
@@ -345,9 +345,15 @@ ACCESS=cash
 module=rc.pl
 action=reconciliation
 
+[Cash--Bank collection via SEPA]
+module=sepa.pl
+action=bank_transfer_add
+vc=customer
+
 [Cash--Bank transfer via SEPA]
 module=sepa.pl
 action=bank_transfer_add
+vc=vendor
 
 [Cash--Reports]
 module=menu.pl
@@ -365,9 +371,15 @@ module=rp.pl
 action=report
 report=payments
 
+[Cash--Reports--Bank collections via SEPA]
+module=sepa.pl
+action=bank_transfer_search
+vc=customer
+
 [Cash--Reports--Bank transfers via SEPA]
 module=sepa.pl
 action=bank_transfer_search
+vc=vendor
 
 [Reports]
 
diff --git a/sql/Pg-upgrade2/sepa_in.sql b/sql/Pg-upgrade2/sepa_in.sql
new file mode 100644 (file)
index 0000000..6373b8f
--- /dev/null
@@ -0,0 +1,12 @@
+-- @tag: sepa_in
+-- @description: Erweiterung SEPA für Kontoeinzüge
+-- @depends: release_2_6_1
+-- @charset: utf-8
+ALTER TABLE sepa_export ADD COLUMN vc varchar(10);
+UPDATE sepa_export SET vc = 'vendor';
+
+ALTER TABLE sepa_export_items ALTER COLUMN ap_id DROP NOT NULL;
+ALTER TABLE sepa_export_items ADD COLUMN ar_id integer;
+ALTER TABLE sepa_export_items ADD FOREIGN KEY (ar_id) REFERENCES ar (id);
+ALTER TABLE sepa_export_items RENAME vendor_iban TO vc_iban;
+ALTER TABLE sepa_export_items RENAME vendor_bic TO vc_bic;
index 4cd24ca..161c5d2 100644 (file)
        <th align="right">[% 'DUNS-Nr' | $T8 %]</th>
        <td><input name="duns" size="14" value="[% HTML.escape(myc_duns) %]"></td>
       </tr>
+
+      <tr>
+       <th align="right">[% 'SEPA creditor ID' | $T8 %]</th>
+       <td><input name="sepa_creditor_id" size="35" maxlength="35" value="[% HTML.escape(myc_sepa_creditor_id) %]"></td>
+      </tr>
      </table>
     </td>
 
index 3d5aba2..4ed5a07 100644 (file)
       <th align="right">[% 'Address' | $T8 %]</th>
       <td><textarea name="address" rows="4" cols="50">[% HTML.escape(myconfig_address) %]</textarea></td>
      </tr>
+     <tr>
+      <th align="right">[% 'SEPA creditor ID' | $T8 %]</th>
+      <td><input name="sepa_creditor_id" size="30" maxlength="35" value="[% HTML.escape(myconfig_sepa_creditor_id) %]"></td>
+     </tr>
     </table>
 
     <br style="clear: left" />
index 1eb34be..0954d1d 100644 (file)
@@ -1,12 +1,25 @@
 [%- USE T8 %]
 [% USE HTML %][% USE LxERP %]
+[% IF vc == 'vendor' %]
+ [% SET is_vendor = 1 %]
+ [% SET arap = 'ap' %]
+ [% SET iris = 'ir' %]
+[% ELSE %]
+ [% SET is_vendor = 0 %]
+ [% SET arap = 'ar' %]
+ [% SET iris = 'is' %]
+[%- END %]
 <body>
 
  <p><div class="listtop">[% title %]</div></p>
 
  <form action="sepa.pl" method="post">
   <p>
-   [% 'Please select the source bank account for the transfers:' | $T8 %]
+   [%- IF is_vendor %]
+    [% 'Please select the source bank account for the transfers:' | $T8 %]
+   [%- ELSE %]
+    [% 'Please select the destination bank account for the collections:' | $T8 %]
+   [%- END %]
    <br>
    [%- INCLUDE generic/multibox.html
          name      = 'bank_account.id',
@@ -20,7 +33,7 @@
    <table border="0">
     <tr>
      <th class="listheading" align="center"><input type="checkbox" id="select_all"></th>
-     <th class="listheading">[% 'Vendor' | $T8 %]</th>
+     <th class="listheading">[% IF is_vendor %][% 'Vendor' | $T8 %][%- ELSE %][%- LxERP.t8('Customer') %][%- END %]</th>
      <th class="listheading">[% 'Invoice' | $T8 %]</th>
      <th class="listheading" align="right">[% 'Amount' | $T8 %]</th>
      <th class="listheading" align="right">[% 'Open amount' | $T8 %]</th>
     </tr>
 
     [%- FOREACH invoice = INVOICES %]
-     <input type="hidden" name="bank_transfers[+].ap_id" value="[% HTML.escape(invoice.id) %]">
+     <input type="hidden" name="bank_transfers[+].[% arap %]_id" value="[% HTML.escape(invoice.id) %]">
 
      <tr class="listrow[% loop.count % 2 %]">
       <td align="center">
-       [%- IF invoice.vendor_bank_info_ok %]
+       [%- IF invoice.vc_bank_info_ok %]
         <input type="checkbox" name="bank_transfers[].selected" value="1">
        [%- END %]
       </td>
       <td>
-       [%- IF loop.first || (previous_vendorname != invoice.vendorname) %]
-        <a href="ct.pl?action=edit&db=vendor&id=[% HTML.url(invoice.vendor_id) %]&callback=[% HTML.url('sepa.pl?action=bank_transfer_add') %]">
-         [%- GET HTML.escape(invoice.vendorname);
-             SET previous_vendorname = invoice.vendorname;
-             IF !invoice.vendor_bank_info_ok;
+       [%- IF loop.first || (previous_vcname != invoice.vcname) %]
+        <a href="ct.pl?action=edit&db=[% vc %]&id=[% HTML.url(invoice.vc_id) %]&callback=[% HTML.url('sepa.pl?action=bank_transfer_add&vc=' _ vc) %]">
+         [%- GET HTML.escape(invoice.vcname);
+             SET previous_vcname = invoice.vcname;
+             IF !invoice.vc_bank_info_ok;
                GET ' <sup>(1)</sup>';
-               SET show_vendor_bank_info_footnote = '1';
+               SET show_vc_bank_info_footnote = '1';
              END; -%]
         </a>
        [%- END -%]
       </td>
 
       <td>
-       <a href="[% IF invoice.invoice %]ir[% ELSE %]ap[% END %].pl?action=edit&id=[% HTML.escape(invoice.id) %]">
+       <a href="[% IF invoice.invoice %][% iris %][% ELSE %][% arap %][% END %].pl?action=edit&id=[% HTML.escape(invoice.id) %]">
         [% HTML.escape(invoice.invnumber) %]
        </a>
       </td>
    </table>
   </p>
 
-  [%- IF show_vendor_bank_info_footnote %]
+  [%- IF show_vc_bank_info_footnote %]
    <p>
-    <sup>(1)</sup> [%- 'No bank information has been entered in this vendor\'s master data entry. You cannot create bank transfers unless you enter bank information.' | $T8 %]
+    <sup>(1)</sup>
+    [%- IF is_vendor %]
+     [%- 'No bank information has been entered in this vendor\'s master data entry. You cannot create bank transfers unless you enter bank information.' | $T8 %]
+    [%- ELSE %]
+     [%- 'No bank information has been entered in this customer\'s master data entry. You cannot create bank collections unless you enter bank information.' | $T8 %]
+    [%- END %]
    </p>
   [%- END %]
 
@@ -80,6 +98,7 @@
   </p>
 
   <input type="hidden" name="action" value="dispatcher">
+  <input type="hidden" name="vc" value="[%- HTML.escape(vc) %]">
  </form>
 
  <script type="text/javascript" src="js/jquery.js"></script>
index 06bbea8..0a5059a 100644 (file)
@@ -1,5 +1,14 @@
 [%- USE T8 %]
 [% USE HTML %][% USE LxERP %]
+[% IF vc == 'vendor' %]
+ [% SET is_vendor = 1 %]
+ [% SET arap = 'ap' %]
+ [% SET iris = 'ir' %]
+[% ELSE %]
+ [% SET is_vendor = 0 %]
+ [% SET arap = 'ar' %]
+ [% SET iris = 'is' %]
+[%- END %]
 <body>
 
  [%- IF error_message %]
@@ -9,7 +18,12 @@
  <p><div class="listtop">[% title %]</div></p>
 
  <form action="sepa.pl" method="post">
-  <p>1. [% 'Please select the source bank account for the transfers:' | $T8 %]
+  <p>1.
+   [%- IF is_vendor %]
+    [% 'Please select the source bank account for the transfers:' | $T8 %]
+   [%- ELSE %]
+    [% 'Please select the destination bank account for the collections:' | $T8 %]
+   [%- END %]
    <br>
    [%- INCLUDE generic/multibox.html
          name      = 'bank_account.id',
   </p>
 
   <p>
-   2. [% 'Please Check the bank information for each vendor:' | $T8 %]
+   2.
+   [%- IF is_vendor %]
+    [% 'Please Check the bank information for each vendor:' | $T8 %]
+   [%- ELSE %]
+    [% 'Please Check the bank information for each customer:' | $T8 %]
+   [%- END %]
    <br>
    <table>
     <tr>
-     <th class="listheading">[% 'Vendor' | $T8 %]</th>
+     <th class="listheading">[%- IF is_vendor %][% 'Vendor' | $T8 %][%- ELSE %][%- LxERP.t8('Customer') %][%- END %]</th>
      <th class="listheading">[% 'IBAN' | $T8 %]</th>
      <th class="listheading">[% 'BIC' | $T8 %]</th>
      <th class="listheading">[% 'Bank' | $T8 %]</th>
     </tr>
 
-    [%- FOREACH vbi = VENDOR_BANK_INFO %]
+    [%- FOREACH vbi = VC_BANK_INFO %]
     <tr class="listrow[% loop.count % 1 %]">
      <td>
-      <input type="hidden" name="vendor_bank_info[+].id" value="[% HTML.escape(vbi.id) %]">
-      <input type="hidden" name="vendor_bank_info[].name" value="[% HTML.escape(vbi.name) %]">
+      <input type="hidden" name="vc_bank_info[+].id" value="[% HTML.escape(vbi.id) %]">
+      <input type="hidden" name="vc_bank_info[].name" value="[% HTML.escape(vbi.name) %]">
       [% HTML.escape(vbi.name) %]
      </td>
-     <td><input name="vendor_bank_info[].iban" size="20" value="[% HTML.escape(vbi.iban) %]"></td>
-     <td><input name="vendor_bank_info[].bic" size="20" value="[% HTML.escape(vbi.bic) %]"></td>
-     <td><input name="vendor_bank_info[].bank" size="30" value="[% HTML.escape(vbi.bank) %]"></td>
+     <td><input name="vc_bank_info[].iban" size="20" value="[% HTML.escape(vbi.iban) %]"></td>
+     <td><input name="vc_bank_info[].bic" size="20" value="[% HTML.escape(vbi.bic) %]"></td>
+     <td><input name="vc_bank_info[].bank" size="30" value="[% HTML.escape(vbi.bank) %]"></td>
     </tr>
     [%- END %]
    </table>
    <br>
    <table>
     <tr>
-     <th class="listheading">[% 'Vendor' | $T8 %]</th>
+     <th class="listheading">[%- IF is_vendor %][% 'Vendor' | $T8 %][%- ELSE %][%- LxERP.t8('Customer') %][%- END %]</th>
      <th class="listheading">[% 'Invoice' | $T8 %]</th>
      <th class="listheading" align="right">[% 'Amount' | $T8 %]</th>
      <th class="listheading" align="right">[% 'Open amount' | $T8 %]</th>
      <th class="listheading">[% 'Purpose' | $T8 %]</th>
-     <th class="listheading" align="right">[% 'Bank transfer amount' | $T8 %]</th>
+     <th class="listheading" align="right">[%- IF is_vendor %][% 'Bank transfer amount' | $T8 %][%- ELSE %][%- LxERP.t8('Bank collection amount') %][%- END %]</th>
      <th class="listheading">[% 'Execution date' | $T8 %]</th>
     </tr>
 
     [%- FOREACH bank_transfer = BANK_TRANSFERS %]
-     <input type="hidden" name="bank_transfers[+].ap_id" value="[% HTML.escape(bank_transfer.id) %]">
-     <input type="hidden" name="bank_transfers[].vendor_id" value="[% HTML.escape(bank_transfer.vendor_id) %]">
+     <input type="hidden" name="bank_transfers[+].[% arap %]_id" value="[% HTML.escape(bank_transfer.id) %]">
+     <input type="hidden" name="bank_transfers[].vc_id" value="[% HTML.escape(bank_transfer.vc_id) %]">
      <input type="hidden" name="bank_transfers[].selected" value="1">
 
      <tr class="listrow[% loop.count % 2 %]">
       <td>
-       [%- IF loop.first || (previous_vendorname != bank_transfer.vendorname) %]
-        <a href="ct.pl?action=edit&db=vendor&id=[% HTML.url(bank_transfer.vendor_id) %]&callback=[% HTML.url('sepa.pl?action=bank_transfer_add') %]">
-         [%- GET HTML.escape(bank_transfer.vendorname);
-             SET previous_vendorname = bank_transfer.vendorname; -%]
+       [%- IF loop.first || (previous_vcname != bank_transfer.vcname) %]
+        <a href="ct.pl?action=edit&db=[% vc %]&id=[% HTML.url(bank_transfer.vc_id) %]&callback=[% HTML.url('sepa.pl?action=bank_transfer_add&vc=' _ vc) %]">
+         [%- GET HTML.escape(bank_transfer.vcname);
+             SET previous_vcname = bank_transfer.vcname; -%]
         </a>
        [%- END -%]
       </td>
 
       <td>
-       <a href="[% IF bank_transfer.invoice %]ir[% ELSE %]ap[% END %].pl?action=edit&id=[% HTML.escape(bank_transfer.id) %]">
+       <a href="[% IF bank_transfer.invoice %][% iris %][% ELSE %][% arap %][% END %].pl?action=edit&id=[% HTML.escape(bank_transfer.id) %]">
         [% HTML.escape(bank_transfer.invnumber) %]
        </a>
       </td>
   </p>
 
   <p>
-   <input type="submit" class="submit" name="action_bank_transfer_create" value="[% 'Create bank transfer' | $T8 %]">
+   [%- IF is_vendor %]
+    <input type="submit" class="submit" name="action_bank_transfer_create" value="[% 'Create bank transfer' | $T8 %]">
+   [%- ELSE %]
+    <input type="submit" class="submit" name="action_bank_transfer_create" value="[% 'Create bank collection' | $T8 %]">
+   [%- END %]
   </p>
 
   <input type="hidden" name="action" value="dispatcher">
+  <input type="hidden" name="vc" value="[%- HTML.escape(vc) %]">
   <input type="hidden" name="confirmation" value="1">
  </form>
 
index d71ae55..6740ba1 100644 (file)
  <p>
   <ul>
    <li>
-    <a href="sepa.pl?action=bank_transfer_download_sepa_xml&id=[% HTML.url(id) %]">
+    <a href="sepa.pl?action=bank_transfer_download_sepa_xml&id=[% HTML.url(id) %]&vc=[% HTML.url(vc) %]">
      [% 'Download SEPA XML export file' | $T8 %]
     </a>
    </li>
 
    <li>
-    <a href="sepa.pl?action=bank_transfer_list&l_open=1&l_not_executed=1">
+    <a href="sepa.pl?action=bank_transfer_list&l_open=1&l_not_executed=1&vc=[% HTML.url(vc) %]">
      [% 'List open SEPA exports' | $T8 %]
     </a>
    </li>
index 28b17ed..a534d1a 100644 (file)
@@ -1,6 +1,15 @@
 [%- USE T8 %]
 [% USE HTML %]
 [% USE LxERP %]
+[% IF vc == 'vendor' %]
+ [% SET is_vendor = 1 %]
+ [% SET arap = 'ap' %]
+ [% SET iris = 'ir' %]
+[% ELSE %]
+ [% SET is_vendor = 0 %]
+ [% SET arap = 'ar' %]
+ [% SET iris = 'is' %]
+[%- END %]
 <body>
 
  <p><div class="listtop">[% title %]: [% HTML.escape(export.ids.join(', ')) %]</div></p>
       <th class="listheading" align="center"><input type="checkbox" id="select_all"></th>
      [%- END %]
      <th class="listheading">[% 'Invoice' | $T8 %]</th>
-     <th class="listheading">[% 'Vendor' | $T8 %]</th>
-     <th class="listheading" colspan="2">[% 'Source bank account' | $T8 %]</th>
-     <th class="listheading" colspan="2">[% 'Target bank account' | $T8 %]</th>
+     <th class="listheading">[%- IF is_vendor %][% 'Vendor' | $T8 %][%- ELSE %][%- LxERP.t8('Customer') %][%- END %]</th>
+     [%- IF is_vendor %]
+      <th class="listheading" colspan="2">[% 'Source bank account' | $T8 %]</th>
+      <th class="listheading" colspan="2">[% 'Target bank account' | $T8 %]</th>
+     [%- ELSE %]
+      <th class="listheading" colspan="2">[% 'Target bank account' | $T8 %]</th>
+      <th class="listheading" colspan="2">[% 'Source bank account' | $T8 %]</th>
+     [%- END %]
      <th class="listheading" align="right">[% 'Amount' | $T8 %]</th>
      <th class="listheading">[% 'Reference' | $T8 %]</th>
      <th class="listheading" align="right">[% 'Requested execution date' | $T8 %]</th>
        </td>
       [%- END %]
       <td>
-       <a href="[% IF item.invoice %]ir[% ELSE %]ap[% END %].pl?action=edit&type=invoice&id=[% HTML.url(item.ap_id) %]">[% HTML.escape(item.invnumber) %]</a>
+       <a href="[% IF item.invoice %][% iris %][% ELSE %][% arap %][% END %].pl?action=edit&type=invoice&id=[% IF is_vendor %][% HTML.url(item.ap_id) %][% ELSE %][% HTML.url(item.ar_id) %][% END %]">[% HTML.escape(item.invnumber) %]</a>
       </td>
-      <td>[% HTML.escape(item.vendor_name) %]</td>
+      <td>[% HTML.escape(item.vc_name) %]</td>
       <td>[% HTML.escape(item.our_iban) %]</td>
       <td>[% HTML.escape(item.our_bic) %]</td>
-      <td>[% HTML.escape(item.vendor_iban) %]</td>
-      <td>[% HTML.escape(item.vendor_bic) %]</td>
+      <td>[% HTML.escape(item.vc_iban) %]</td>
+      <td>[% HTML.escape(item.vc_bic) %]</td>
       <td align="right">[% HTML.escape(LxERP.format_amount(item.amount, 2)) %]</td>
       <td>[% HTML.escape(item.reference) %]</td>
       <td align="right">[% HTML.escape(item.requested_execution_date) %]</td>
     [%- END %]
    [%- END %]
   [%- END %]
+
+     <input type="hidden" name="vc" value="[% HTML.escape(vc) %]">
  </form>
 
 </body>
index 79f373f..1eab32b 100644 (file)
@@ -4,6 +4,7 @@
 [%- IF show_buttons %]
  <input type="hidden" name="action" value="dispatcher">
  <input type="hidden" name="mode" value="multi">
+ <input type="hidden" name="vc" value="[%- HTML.escape(vc) %]">
 
  <p>
   <input type="submit" class="submit" name="action_bank_transfer_download_sepa_xml" value="[% 'SEPA XML download' | $T8 %]">
index 4d1a6dc..063b4ee 100644 (file)
@@ -6,7 +6,11 @@
 
  <form action="sepa.pl" method="post">
   <p>
-   [%- 'Do you really want to close the following SEPA exports? No payment will be recorded for bank transfers that haven\'t been marked as executed yet.' | $T8 %]
+   [%- IF vc == 'vendor' %]
+    [%- 'Do you really want to close the following SEPA exports? No payment will be recorded for bank transfers that haven\'t been marked as executed yet.' | $T8 %]
+   [%- ELSE %]
+    [%- 'Do you really want to close the following SEPA exports? No payment will be recorded for bank collections that haven\'t been marked as executed yet.' | $T8 %]
+   [%- END %]
   </p>
 
   <p>
@@ -14,7 +18,7 @@
    [%- FOREACH id = OPEN_EXPORT_IDS %]
     [%- UNLESS loop.first %], [%- END %]
     <input type="hidden" name="open_export_ids[]" value="[% HTML.escape(id) %]">
-    <a href="sepa.pl?action=bank_transfer_edit&id=[% HTML.url(id) %]">[% HTML.escape(id) %]</a>
+    <a href="sepa.pl?action=bank_transfer_edit&id=[% HTML.url(id) %]&vc=[% HTML.url(vc) %]">[% HTML.escape(id) %]</a>
    [%- END %]
   </p>
 
@@ -24,6 +28,7 @@
   </p>
 
   <input type="hidden" name="action" value="dispatcher">
+  <input type="hidden" name="vc" value="[%- HTML.escape(vc) %]">
  </form>
 
 </body>
index 306179f..bc60d88 100644 (file)
@@ -1,5 +1,5 @@
 [%- USE T8 %]
-[% USE HTML %]
+[% USE HTML %][% USE LxERP %]
 <body>
 
  <p><div class="listtop">[% title %]</div></p>
@@ -8,8 +8,8 @@
   <p>
    <table>
     <tr>
-     <td align="right">[% 'Vendor' | $T8 %]</td>
-     <td><input name="f_vendor"></td>
+     <td align="right">[%- IF vc == 'vendor' %][% 'Vendor' | $T8 %][%- ELSE %][%- LxERP.t8('Customer') %][%- END %]</td>
+     <td><input name="f_vc"></td>
     </tr>
 
     <tr>
@@ -86,6 +86,7 @@
 
   <p>
    <input type="hidden" name="action" value="dispatcher">
+   <input type="hidden" name="vc" value="[%- HTML.escape(vc) %]">
    <input type="submit" class="submit" name="action_bank_transfer_list" value="[% 'Continue' | $T8 %]">
   </p>
  </form>