Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision c1716dbd

Von Moritz Bunkus vor fast 14 Jahren hinzugefügt

  • ID c1716dbdeb0ba6d2cd9c708a2c54b9845e9532b4
  • Vorgänger 56a7606e
  • Nachfolger 39d61f60

Unterstützung für die XML-Ausgabe von Lastschriften

Unterschiede anzeigen:

SL/SEPA/XML.pm
32 32
  $self->{src_charset}  = 'UTF-8';
33 33
  $self->{grouped}      = 0;
34 34

  
35
  map { $self->{$_} = $params{$_} if (exists $params{$_}) } qw(src_charset company message_id grouped);
35
  map { $self->{$_} = $params{$_} if (exists $params{$_}) } qw(src_charset company creditor_id message_id grouped collection);
36 36

  
37 37
  $self->{iconv} = SL::Iconv->new($self->{src_charset}, "UTF-8") || croak "Unsupported source charset $self->{src_charset}.";
38 38

  
39 39
  my $missing_parameter = first { !$self->{$_} } qw(company message_id);
40 40
  croak "Missing parameter: $missing_parameter" if ($missing_parameter);
41
  croak "Missing parameter: creditor_id"        if !$self->{creditor_id} && $self->{collection};
41 42

  
42
  map { $self->{$_} = $self->_replace_special_chars($self->{iconv}->convert($self->{$_})) } qw(company message_id);
43
  map { $self->{$_} = $self->_replace_special_chars($self->{iconv}->convert($self->{$_})) } qw(company message_id creditor_id);
43 44
}
44 45

  
45 46
sub add_transaction {
......
77 78
  my $self   = shift;
78 79
  my $amount = shift;
79 80

  
80
  return sprintf '%d.%02d', int($amount), int($amount * 100) % 100;
81
  return sprintf '%.02f', $amount;
81 82
}
82 83

  
83 84
sub _group_transactions {
......
116 117
                                DATA_INDENT => 2,
117 118
                                ENCODING    => 'utf-8');
118 119

  
119
  my @now        = localtime;
120
  my $time_zone  = strftime "%z", @now;
121
  my $now_str    = strftime('%Y-%m-%dT%H:%M:%S', @now) . substr($time_zone, 0, 3) . ':' . substr($time_zone, 3, 2);
120
  my @now       = localtime;
121
  my $time_zone = strftime "%z", @now;
122
  my $now_str   = strftime('%Y-%m-%dT%H:%M:%S', @now) . substr($time_zone, 0, 3) . ':' . substr($time_zone, 3, 2);
123

  
124
  my $is_coll   = $self->{collection};
125
  my $cd_src    = $is_coll ? 'Cdtr' : 'Dbtr';
126
  my $cd_dst    = $is_coll ? 'Dbtr' : 'Cdtr';
127
  my $pain_id   = $is_coll ? 'pain.008.002.01' : 'pain.001.001.02';
128
  my $pain_elmt = $is_coll ? 'pain.008.001.01' : 'pain.001.001.02';
129
  my @pii_base  = (strftime('PII%Y%m%d%H%M%S', @now), rand(1000000000));
122 130

  
123 131
  my $grouped_transactions = $self->_group_transactions();
124 132

  
125 133
  $xml->xmlDecl();
134

  
126 135
  $xml->startTag('Document',
127
                 'xmlns'              => 'urn:sepade:xsd:pain.001.001.02.grp',
136
                 'xmlns'              => "urn:swift:xsd:\$${pain_id}",
128 137
                 'xmlns:xsi'          => 'http://www.w3.org/2001/XMLSchema-instance',
129
                 'xsi:schemaLocation' => 'urn:sepade:xsd:pain.001.001.02.grp pain.001.001.02.grp.xsd');
138
                 'xsi:schemaLocation' => "urn:swift:xsd:\$${pain_id} ${pain_id}.xsd");
130 139

  
131
  $xml->startTag('pain.001.001.02');
140
  $xml->startTag($pain_elmt);
132 141

  
133 142
  $xml->startTag('GrpHdr');
134 143
  $xml->dataElement('MsgId', encode('UTF-8', substr($self->{message_id}, 0, 35)));
......
148 157
    my $master_transaction = $transaction_group->{transactions}->[0];
149 158

  
150 159
    $xml->startTag('PmtInf');
151
    $xml->dataElement('PmtMtd', 'TRF');
160
    if ($is_coll) {
161
      $xml->dataElement('PmtInfId', sprintf('%s%010d', @pii_base));
162
      $pii_base[1]++;
163
    }
164
    $xml->dataElement('PmtMtd', $is_coll ? 'DD' : 'TRF');
152 165

  
153 166
    $xml->startTag('PmtTpInf');
154 167
    $xml->startTag('SvcLvl');
155 168
    $xml->dataElement('Cd', 'SEPA');
156 169
    $xml->endTag('SvcLvl');
170

  
171
    if ($is_coll) {
172
      $xml->startTag('LclInstrm');
173
      $xml->dataElement('Cd', 'CORE');
174
      $xml->endTag('LclInstrm');
175
      $xml->dataElement('SeqTp', 'OOFF');
176
    }
157 177
    $xml->endTag('PmtTpInf');
158 178

  
159
    $xml->dataElement('ReqdExctnDt', $master_transaction->get('execution_date'));
160
    $xml->startTag('Dbtr');
179
    $xml->dataElement($is_coll ? 'ReqdColltnDt' : 'ReqdExctnDt', $master_transaction->get('execution_date'));
180
    $xml->startTag($cd_src);
161 181
    $xml->dataElement('Nm', encode('UTF-8', substr($self->{company}, 0, 70)));
162
    $xml->endTag('Dbtr');
182
    $xml->endTag($cd_src);
163 183

  
164
    $xml->startTag('DbtrAcct');
184
    $xml->startTag($cd_src . 'Acct');
165 185
    $xml->startTag('Id');
166 186
    $xml->dataElement('IBAN', $master_transaction->get('src_iban', 34));
167 187
    $xml->endTag('Id');
168
    $xml->endTag('DbtrAcct');
188
    $xml->endTag($cd_src . 'Acct');
169 189

  
170
    $xml->startTag('DbtrAgt');
190
    $xml->startTag($cd_src . 'Agt');
171 191
    $xml->startTag('FinInstnId');
172 192
    $xml->dataElement('BIC', $master_transaction->get('src_bic', 20));
173 193
    $xml->endTag('FinInstnId');
174
    $xml->endTag('DbtrAgt');
194
    $xml->endTag($cd_src . 'Agt');
175 195

  
176 196
    $xml->dataElement('ChrgBr', 'SLEV');
177 197

  
178 198
    foreach my $transaction (@{ $transaction_group->{transactions} }) {
179
      $xml->startTag('CdtTrfTxInf');
199
      $xml->startTag($is_coll ? 'DrctDbtTxInf' : 'CdtTrfTxInf');
180 200

  
181 201
      $xml->startTag('PmtId');
182 202
      $xml->dataElement('EndToEndId', $transaction->get('end_to_end_id', 35));
183 203
      $xml->endTag('PmtId');
184 204

  
185
      $xml->startTag('Amt');
186
      $xml->startTag('InstdAmt', 'Ccy' => 'EUR');
187
      $xml->characters($self->_format_amount($transaction->{amount}));
188
      $xml->endTag('InstdAmt');
189
      $xml->endTag('Amt');
190

  
191
      $xml->startTag('CdtrAgt');
205
      if ($is_coll) {
206
        $xml->startTag('InstdAmt', 'Ccy' => 'EUR');
207
        $xml->characters($self->_format_amount($transaction->{amount}));
208
        $xml->endTag('InstdAmt');
209

  
210
        $xml->startTag('DrctDbtTx');
211

  
212
        $xml->startTag('MndtRltdInf');
213
        $xml->dataElement('MndtId', $transaction->get('reference', 35));
214
        $xml->dataElement('DtOfSgntr', $transaction->get('reference_date', 2010-12-02));
215
        $xml->endTag('MndtRltdInf');
216

  
217
        $xml->startTag('CdtrSchmeId');
218
        $xml->startTag('Id');
219
        $xml->startTag('PrvtId');
220
        $xml->startTag('OthrId');
221
        $xml->dataElement('Id', encode('UTF-8', substr($self->{creditor_id}, 0, 35)));
222
        $xml->dataElement('IdTp', 'SEPA');
223
        $xml->endTag('OthrId');
224
        $xml->endTag('PrvtId');
225
        $xml->endTag('Id');
226
        $xml->endTag('CdtrSchmeId');
227

  
228
        $xml->endTag('DrctDbtTx');
229

  
230
      } else {
231
        $xml->startTag('Amt');
232
        $xml->startTag('InstdAmt', 'Ccy' => 'EUR');
233
        $xml->characters($self->_format_amount($transaction->{amount}));
234
        $xml->endTag('InstdAmt');
235
        $xml->endTag('Amt');
236
      }
237

  
238
      $xml->startTag("${cd_dst}Agt");
192 239
      $xml->startTag('FinInstnId');
193 240
      $xml->dataElement('BIC', $transaction->get('dst_bic', 20));
194 241
      $xml->endTag('FinInstnId');
195
      $xml->endTag('CdtrAgt');
242
      $xml->endTag("${cd_dst}Agt");
196 243

  
197
      $xml->startTag('Cdtr');
198
      $xml->dataElement('Nm', $transaction->get('recipient', 70));
199
      $xml->endTag('Cdtr');
244
      $xml->startTag("${cd_dst}");
245
      $xml->dataElement('Nm', $transaction->get('company', 70));
246
      $xml->endTag("${cd_dst}");
200 247

  
201
      $xml->startTag('CdtrAcct');
248
      $xml->startTag("${cd_dst}Acct");
202 249
      $xml->startTag('Id');
203 250
      $xml->dataElement('IBAN', $transaction->get('dst_iban', 34));
204 251
      $xml->endTag('Id');
205
      $xml->endTag('CdtrAcct');
252
      $xml->endTag("${cd_dst}Acct");
206 253

  
207 254
      $xml->startTag('RmtInf');
208 255
      $xml->dataElement('Ustrd', $transaction->get('reference', 140));
209 256
      $xml->endTag('RmtInf');
210 257

  
211
      $xml->endTag('CdtTrfTxInf');
258
      $xml->endTag($is_coll ? 'DrctDbtTxInf' : 'CdtTrfTxInf');
212 259
    }
213 260

  
214 261
    $xml->endTag('PmtInf');
215 262
  }
216 263

  
217
  $xml->endTag('pain.001.001.02');
264
  $xml->endTag($pain_elmt);
218 265
  $xml->endTag('Document');
219 266

  
220 267
  return $output;

Auch abrufbar als: Unified diff