Formatting
[memberdb.git] / include / directdebit.php
index d3d5d6c..5243e37 100644 (file)
@@ -1,34 +1,46 @@
 <?php
 
+use MemberDB\Config\Config;
 
-function action_directdebit() {
+function action_directdebit()
+{
+    $config = Config::getInstance();
+    $bank = $config['bank'];
 
     $debittype = array(
         1 => 'DTAUS',
         2 => 'FRST',
         3 => 'RCUR'
-    ); 
+    );
 
     $members = db_get_members();
-    if (empty($members)) return;
+    if (empty($members)) {
+        return;
+    }
 
     $debits = array();
     $cash_payments = array();
     foreach ($members as $member) {
-               if (empty($member['directdebit'])) {
-                       // Barzahler
-                       $open = bcsub(fees_sum_for_member($member['id'], time()), bcadd(finance_get_paid_fees_for_member($member['id']), finance_get_paid_fees_for_member($member['id'], true)));
-                       if (bccomp($open, 0) != 1) continue;
-                       $cash_payments[] = array(
-                               'member_id'     => $member['id'],
-                               'member_number' => $member['number'],
-                               'nickname'      => $member['nickname'],
-                               'amount'        => $open
-                       );
-                       continue;
-               }
+        if (empty($member['directdebit'])) {
+            // Barzahler
+            $open = bcsub(fees_sum_for_member($member['id'], time()),
+                bcadd(finance_get_paid_fees_for_member($member['id']),
+                    finance_get_paid_fees_for_member($member['id'], true)));
+            if (bccomp($open, 0) != 1) {
+                continue;
+            }
+            $cash_payments[] = array(
+                'member_id'     => $member['id'],
+                'member_number' => $member['number'],
+                'nickname'      => $member['nickname'],
+                'amount'        => $open
+            );
+            continue;
+        }
         $info = fee_next_directdebit_for_member($member['id'], time());
-        if (empty($info)) continue;
+        if (empty($info)) {
+            continue;
+        }
         $debits[] = array(
             'member_id'        => $member['id'],
             'member_number'    => $member['number'],
@@ -36,7 +48,7 @@ function action_directdebit() {
             'accountholder'    => $member['accountholder'],
             'accountnumber'    => $member['accountnumber'],
             'bankcode'         => $member['bankcode'],
-//          'bankname'         => $member['bankname'],
+            //          'bankname'         => $member['bankname'],
             'amount'           => $info['value'],
             'amountcent'       => '' . (int)round(bcmul($info['value'], 100)),
             'purpose'          => $info['info'],
@@ -47,254 +59,258 @@ function action_directdebit() {
 
     js_modal_windows();
     js_get_master_key();
-
-?>
+    ?>
     <noscript>
         <p class="error">
             <strong>Achtung:</strong> Ohne JavaScript geht hier gar nichts. Bitte aktivieren!
         </p>
     </noscript>
-<?php if (!empty($cash_payments)) : ?>
-<h2>Barzahler</h2>
-<table>
-    <tr>
-        <th>Mitgliedsnummer</th>
-        <th>Nickname</th>
-        <th style="text-align: right;">Betrag</th>
-               <th></th>
-       </tr>
-<?php foreach ($cash_payments as $payment) : ?>
-    <tr>
-        <td><a href="<?=html_escape(link_to('fees', array('member_id'=> $payment['member_id'])))?>"><?=html_escape($payment['member_number'])?></a></td>
-        <td><?=html_escape($payment['nickname'])?></td>
-        <td style="text-align: right;"><?=html_escape(format_money($payment['amount']))?></td>
-               <td>
-                       <form action="<?=link_to('create_earning')?>" method="post" class="clearfix">
-                               <?=html_hidden_field('date', format_date(time()))?>
-                               <?=html_hidden_field('type', 'fee')?>
-                               <?=html_hidden_field('status', 'paid')?>
-                               <?=html_hidden_field('value', format_money($payment['amount']))?>
-                               <?=html_hidden_field('member_id', $payment['member_id'])?>
-                               <?=html_hidden_field('description', '')?>
-                               <?=html_hidden_field('account', 'cash')?>
-                               <input class="submit" type="submit" name="submit" value="Einnahme verbuchen"/>
-                       </form>
-               </td>
-    </tr>
-<?php endforeach ?>
-</table>
+    <?php if (!empty($cash_payments)) : ?>
+    <h2>Barzahler</h2>
+    <table>
+        <tr>
+            <th>Mitgliedsnummer</th>
+            <th>Nickname</th>
+            <th style="text-align: right;">Betrag</th>
+            <th></th>
+        </tr>
+        <?php foreach ($cash_payments as $payment) : ?>
+            <tr>
+                <td><a href="<?php echo html_escape(link_to('fees',
+                        array('member_id' => $payment['member_id']))) ?>"><?php echo html_escape($payment['member_number']) ?></a>
+                </td>
+                <td><?php echo html_escape($payment['nickname']) ?></td>
+                <td style="text-align: right;"><?php echo html_escape(format_money($payment['amount'])) ?></td>
+                <td>
+                    <form action="<?php echo link_to('create_earning') ?>" method="post" class="clearfix">
+                        <?php echo html_hidden_field('date', format_date(time())) ?>
+                        <?php echo html_hidden_field('type', 'fee') ?>
+                        <?php echo html_hidden_field('status', 'paid') ?>
+                        <?php echo html_hidden_field('value', format_money($payment['amount'])) ?>
+                        <?php echo html_hidden_field('member_id', $payment['member_id']) ?>
+                        <?php echo html_hidden_field('description', '') ?>
+                        <?php echo html_hidden_field('account', 'cash') ?>
+                        <input class="submit" type="submit" name="submit" value="Einnahme verbuchen"/>
+                    </form>
+                </td>
+            </tr>
+        <?php endforeach ?>
+    </table>
 <?php endif ?>
 
-<h2>Bankeinzug</h2>
-<table>
-    <tr>
-        <th>Mitgliedsnummer</th>
-        <th>Nickname</th>
-        <th>Verwendungszweck</th>
-        <th>Einzugstyp</th>
-        <th style="text-align: right;">Betrag</th>
-    </tr>
-<?php $total = 0; ?>
-<?php foreach ($debits as $debit) : ?>
-    <tr>
-        <td><a href="<?=html_escape(link_to('fees', array('member_id'=> $debit['member_id'])))?>"><?=html_escape($debit['member_number'])?></a></td>
-        <td><?=html_escape($debit['nickname'])?></td>
-        <td><?=html_escape($debit['purpose'])?></td>
-        <td><?=html_escape($debit['debittype'])?></td>
-        <td style="text-align: right;"><?=html_escape(format_money($debit['amount']))?></td>
-    </tr>
-    <?php $total = bcadd($total, $debit['amount']); ?>
-<?php endforeach ?>
-    <tr class="total">
-        <td>Gesamt</td>
-        <td></td>
-        <td></td>
-        <td></td>
-        <td style="text-align: right;"><?=html_escape(format_money($total))?></td>
-    </tr>
-</table>
-
-<!-- ?=html_hidden_field('directdebittype', 'pain')? -->
-<?=html_list_box('Dateiformat', 'directdebittype', array('dtaus' => 'DTAUS', 'pain' => 'PAIN'), 'pain');?>
-<input class="submit" type="button" name="btn_directdebit" value="Datei erzeugen" onclick="ask_for_password()" id="btn_directdebit"/>
-<br/>
-<br/>
-<form action="<?=link_to('create_earnings')?>" method="post" class="clearfix">
-<?php $count = 0; ?>
-<?php foreach ($debits as $debit) : ?>
-    <?=html_hidden_field(sprintf('earnings[%d][date]',        $count), format_date(time()))?>
-    <?=html_hidden_field(sprintf('earnings[%d][type]',        $count), 'fee')?>
-    <?=html_hidden_field(sprintf('earnings[%d][status]',      $count), 'paid')?>
-    <?=html_hidden_field(sprintf('earnings[%d][value]',       $count), $debit['amount'])?>
-    <?=html_hidden_field(sprintf('earnings[%d][member_id]',   $count), $debit['member_id'])?>
-    <?=html_hidden_field(sprintf('earnings[%d][description]', $count), $debit['purpose'])?>
-    <?php $count++; ?>
-<?php endforeach ?>
-<input class="submit" type="submit" name="btn_create_earnings" value="Einnahmen verbuchen"/>
-</form>
-
-<a href="<?=link_to('export_ibanhin')?>">IBAN-hin Export</a>
-
-<div id="password_popup" class="modal_window">
-    <fieldset>
-        <legend>Passwortabfrage</legend>
-        <?=html_password_field('Passwort', 'password')?>
-        <input class="submit" type="button" name="btn_generate_directdebit" value="Datei erzeugen" onclick="generate_directdebit()"/>
-        <input class="submit" type="button" name="btn_cancel" value="Abbrechen" onclick="cancel_ask_for_password()"/>
-    </fieldset>
-</div>
-<div id="directdebit_popup" class="modal_window">
-    <fieldset>
-        <legend>DTAUS / SEPA PAIN FRST</legend>
+    <h2>Bankeinzug</h2>
+    <table>
+        <tr>
+            <th>Mitgliedsnummer</th>
+            <th>Nickname</th>
+            <th>Verwendungszweck</th>
+            <th>Einzugstyp</th>
+            <th style="text-align: right;">Betrag</th>
+        </tr>
+        <?php $total = 0; ?>
+        <?php foreach ($debits as $debit) : ?>
+            <tr>
+                <td><a href="<?php echo html_escape(link_to('fees',
+                        array('member_id' => $debit['member_id']))) ?>"><?php echo html_escape($debit['member_number']) ?></a>
+                </td>
+                <td><?php echo html_escape($debit['nickname']) ?></td>
+                <td><?php echo html_escape($debit['purpose']) ?></td>
+                <td><?php echo html_escape($debit['debittype']) ?></td>
+                <td style="text-align: right;"><?php echo html_escape(format_money($debit['amount'])) ?></td>
+            </tr>
+            <?php $total = bcadd($total, $debit['amount']); ?>
+        <?php endforeach ?>
+        <tr class="total">
+            <td>Gesamt</td>
+            <td></td>
+            <td></td>
+            <td></td>
+            <td style="text-align: right;"><?php echo html_escape(format_money($total)) ?></td>
+        </tr>
+    </table>
+
+    <?php echo html_list_box('Dateiformat', 'directdebittype', array('dtaus' => 'DTAUS', 'pain' => 'PAIN'), 'pain'); ?>
+    <input class="submit" type="button" name="btn_directdebit" value="Datei erzeugen" onclick="ask_for_password()"
+           id="btn_directdebit"/>
+    <br/>
+    <br/>
+    <form action="<?php echo link_to('create_earnings') ?>" method="post" class="clearfix">
+        <?php $count = 0; ?>
+        <?php foreach ($debits as $debit) : ?>
+            <?php echo html_hidden_field(sprintf('earnings[%d][date]', $count), format_date(time())) ?>
+            <?php echo html_hidden_field(sprintf('earnings[%d][type]', $count), 'fee') ?>
+            <?php echo html_hidden_field(sprintf('earnings[%d][status]', $count), 'paid') ?>
+            <?php echo html_hidden_field(sprintf('earnings[%d][value]', $count), $debit['amount']) ?>
+            <?php echo html_hidden_field(sprintf('earnings[%d][member_id]', $count), $debit['member_id']) ?>
+            <?php echo html_hidden_field(sprintf('earnings[%d][description]', $count), $debit['purpose']) ?>
+            <?php $count++; ?>
+        <?php endforeach ?>
+        <input class="submit" type="submit" name="btn_create_earnings" value="Einnahmen verbuchen"/>
+    </form>
+    <hr/>
+    <form action="<?php echo link_to('export_ibanhin') ?>" method="POST" class="clearfix">
+        <input class="submit" type="submit" name="btn_export_ibanhin" value="IBAN-hin Export"/>
+    </form>
+
+    <div id="password_popup" class="modal_window">
+        <fieldset>
+            <legend>Passwortabfrage</legend>
+            <?php echo html_password_field('Passwort', 'password') ?>
+            <input class="submit" type="button" name="btn_generate_directdebit" value="Datei erzeugen"
+                   onclick="generate_directdebit()"/>
+            <input class="submit" type="button" name="btn_cancel" value="Abbrechen"
+                   onclick="cancel_ask_for_password()"/>
+        </fieldset>
+    </div>
+    <div id="directdebit_popup" class="modal_window">
+        <fieldset>
+            <legend>DTAUS / SEPA PAIN FRST</legend>
             <textarea id="directdebit_content" style="width: 100%" rows="15" readonly="readonly"></textarea>
-        <legend>SEPA PAIN RCUR</legend>
+            <legend>SEPA PAIN RCUR</legend>
             <textarea id="directdebit_content2" style="width: 100%" rows="15" readonly="readonly"></textarea>
-            <input class="submit" type="button" name="btn_directdebit_close" value="Schließen" onclick="directdebit_close()"/>
-    </fieldset>
-</div>
-
-<script type="text/javascript">
-
-var debits = new Array(
-    <?=join(",\n", array_map('json_encode', $debits)) ?>
-);
-
-
-$(document).ready(function(){  
-    $('#password').keypress( function(event) { if (event.keyCode == '13') { generate_directdebit(); } });
-    $('#btn_directdebit').focus();
-});  
-
-
-function ask_for_password() {/*{{{*/
-    modal_window_show($("#password_popup"));
-    $("#password").focus();
-    return;
-}/*}}}*/
-
-function cancel_ask_for_password() {/*{{{*/
-    modal_window_hide();
-    $("#btn_directdebit").focus();
-    return;
-}/*}}}*/
-
-
-function generate_directdebit() {/*{{{*/
-
-    var password = $('#password').val();
-    var directdebitcontent = "";
-    var directdebitcontent2 = "Wird nur bei SEPA verwendet.";
-    $("#password").val('');
-
-    // We pass a closure so that get_master_key may defer execution
-    get_master_key(password, function(masterkey) {
-
-        modal_window_replace($("#directdebit_popup"));
-
-    switch ($('#directdebittype').val()) {
-        case "dtaus":
-           if (!DTAUS.setAccountFileSender('<?=dtaus_string(ACCOUNT_HOLDER)?>', '<?=BANK_CODE?>', '<?=ACCOUNT_NUMBER?>')) {
-               $('#directdebit_content').val(DTAUS.errormsg);
-               return;
-           }
-
-           for (var i = 0; i < debits.length; i++) {
-           
-               if (debits[i]['debittype'] != 'DTAUS' ) {
-                 continue;
-               }
-               
-               var accountholder = debits[i]['accountholder'];
-               var accountnumber = debits[i]['accountnumber'];
-               var bankcode      = debits[i]['bankcode'];
-
-               // Encrypt/Decrypt data using AES with masterkey
-               if (accountholder != "") accountholder = Crypto.charenc.UTF8.bytesToString(Crypto.AES.decrypt(accountholder, masterkey));
-               if (accountnumber != "") accountnumber = Crypto.charenc.UTF8.bytesToString(Crypto.AES.decrypt(accountnumber, masterkey));
-               if (bankcode      != "") bankcode      = Crypto.charenc.UTF8.bytesToString(Crypto.AES.decrypt(bankcode,      masterkey));
-
-               accountholder = DTAUS.prepareString(accountholder);
-
-               if (!DTAUS.addExchange(accountholder, bankcode, accountnumber, '', debits[i]['amountcent'], debits[i]['purpose'])) {
-                   $('#directdebit_content').val('Mitglied ' + debits[i]['member_number'] + ' ' + accountholder + '\n' + DTAUS.errormsg);
-                   return;
-               }
-           }
-           directdebitcontent = DTAUS.getFileContent();
-           break;
-           
-       case "pain":
-
-           <?php $bic = (USE_BIC == 1)?'\''.BIC.'\'':'null'; ?>    
-           
-           // datejs.com MAGIC
-           var jetzt = new Date.today();
-           var collectiondate = new Date.parse('15'); //new Date(jetzt.getFullYear(), jetzt.getMonth(), <?=DIRECTDEBIT_DAY_OF_MONTH?>);
-           if (jetzt.getDate() < <?=DIRECTDEBIT_DAY_OF_MONTH?>) {
-             collectiondate = collectiondate.add(1).month();
-           }
-
-           if (!SEPACORE.init(collectiondate, '<?=CREDITOR_IDENTIFIER?>', '<?=ACCOUNT_HOLDER?>', '<?=IBAN?>', <?=$bic?>)) {
-               $('#directdebit_content').val(DTAUS.errormsg);
-               return;
-           }
-
-           for (var i = 0; i < debits.length; i++) {
-           
-               if (debits[i]['debittype'] != 'FRST' && debits[i]['debittype'] != 'RCUR' ) {
-                 continue;
-               }
-               
-               var accountholder = debits[i]['accountholder'];
-               var accountnumber = debits[i]['accountnumber'];
-               var bankcode      = debits[i]['bankcode'];
-
-               // Encrypt/Decrypt data using AES with masterkey
-               if (accountholder != "") accountholder = Crypto.charenc.UTF8.bytesToString(Crypto.AES.decrypt(accountholder, masterkey));
-               if (accountnumber != "") accountnumber = Crypto.charenc.UTF8.bytesToString(Crypto.AES.decrypt(accountnumber, masterkey));
-               if (bankcode      != "") bankcode      = Crypto.charenc.UTF8.bytesToString(Crypto.AES.decrypt(bankcode,      masterkey));
-               
-               // Mandatsreferenz '/V1/M:n/'; z.B. /V:1/M:2/
-               var mandateref = '/V:1/M:' + debits[i]['member_number'] + '/';
-               var e2eid = mandateref + 'E2E:' + parseInt(SEPACORE.creationdate.getTime()/1000) + '/S:' + debits[i]['debittype'][0] + '/';
-               if (!SEPACORE.addDDTx(debits[i]['debittype'], accountholder, accountnumber, bankcode, mandateref, debits[i]['ddmandatesigdate'].substring(0, 10), debits[i]['amountcent'], debits[i]['purpose'], e2eid)) {
-                   $('#directdebit_content').val('Mitglied ' + debits[i]['member_number'] + ' ' + accountholder + '\n' + SEPACORE.errormsg);
-                   return;
-               }
-           }
-           
-           directdebitcontent = SEPACORE.getXMLContent('FRST');
-            directdebitcontent2 = SEPACORE.getXMLContent('RCUR');
-            
-           if (SEPACORE.errormsg.lenght > 0) {
-               $('#directdebit_content').val(SEPACORE.errormsg);
-               return;
-           }
-            break;
-        }
-        $('#directdebit_content').val(directdebitcontent);
-        $('#directdebit_content2').val(directdebitcontent2);
-        $('#directdebit_content').focus();
-        $('#directdebit_content').select();
-    });
+            <input class="submit" type="button" name="btn_directdebit_close" value="Schließen"
+                   onclick="directdebit_close()"/>
+        </fieldset>
+    </div>
+
+    <script type="text/javascript">
+        var debits = new Array(
+            <?php echo join(",\n", array_map('json_encode', $debits)) ?>
+        );
 
-}/*}}}*/
+        $(document).ready(function () {
+            $('#password').keypress(function (event) {
+                if (event.keyCode == '13') {
+                    generate_directdebit();
+                }
+            });
+            $('#btn_directdebit').focus();
+        });
+
+        function ask_for_password() {
+            modal_window_show($("#password_popup"));
+            $("#password").focus();
+            return;
+        }
 
-function directdebit_close() {/*{{{*/
-    modal_window_hide();
-    $("#directdebit_content").val('');
-    $("#directdebit_content2").val('');
-}/*}}}*/
+        function cancel_ask_for_password() {
+            modal_window_hide();
+            $("#btn_directdebit").focus();
+            return;
+        }
 
+        function generate_directdebit() {
+            var password = $('#password').val();
+            var directdebitcontent = "";
+            var directdebitcontent2 = "Wird nur bei SEPA verwendet.";
+            $("#password").val('');
+
+            // We pass a closure so that get_master_key may defer execution
+            get_master_key(password, function (masterkey) {
+
+                modal_window_replace($("#directdebit_popup"));
+
+                switch ($('#directdebittype').val()) {
+                    case "dtaus":
+                        if (!DTAUS.setAccountFileSender('<?php echo dtaus_string($bank['holder']); ?>', '<?php echo $bank['code']; ?>', '<?php echo $bank['number']; ?>')) {
+                            $('#directdebit_content').val(DTAUS.errormsg);
+                            return;
+                        }
+
+                        for (var i = 0; i < debits.length; i++) {
+
+                            if (debits[i]['debittype'] != 'DTAUS') {
+                                continue;
+                            }
+
+                            var accountholder = debits[i]['accountholder'];
+                            var accountnumber = debits[i]['accountnumber'];
+                            var bankcode = debits[i]['bankcode'];
+
+                            // Encrypt/Decrypt data using AES with masterkey
+                            if (accountholder != "") accountholder = Crypto.charenc.UTF8.bytesToString(Crypto.AES.decrypt(accountholder, masterkey));
+                            if (accountnumber != "") accountnumber = Crypto.charenc.UTF8.bytesToString(Crypto.AES.decrypt(accountnumber, masterkey));
+                            if (bankcode != "") bankcode = Crypto.charenc.UTF8.bytesToString(Crypto.AES.decrypt(bankcode, masterkey));
+
+                            accountholder = DTAUS.prepareString(accountholder);
+
+                            if (!DTAUS.addExchange(accountholder, bankcode, accountnumber, '', debits[i]['amountcent'], debits[i]['purpose'])) {
+                                $('#directdebit_content').val('Mitglied ' + debits[i]['member_number'] + ' ' + accountholder + '\n' + DTAUS.errormsg);
+                                return;
+                            }
+                        }
+                        directdebitcontent = DTAUS.getFileContent();
+                        break;
+
+                    case "pain":
+                        // datejs.com MAGIC
+                        var jetzt = new Date.today();
+                        var collectiondate = new Date.parse('<?php echo $config->get('direct_debit')['day']; ?>');
+                        if (jetzt.getDate() > <?php echo $config->get('direct_debit')['day']; ?>) {
+                            collectiondate = collectiondate.add(1).month();
+                        }
+
+                        if (!SEPACORE.init(collectiondate, '<?php echo $bank['creditor_id']; ?>', '<?php echo $bank['holder']; ?>', '<?php echo $bank['iban']; ?>', '<?php echo $bank['bic']; ?>'')) {
+                        $('#directdebit_content').val(DTAUS.errormsg);
+                        return;
+                }
+
+                for (var i = 0; i < debits.length; i++) {
+
+                    if (debits[i]['debittype'] != 'FRST' && debits[i]['debittype'] != 'RCUR') {
+                        continue;
+                    }
+
+                    var accountholder = debits[i]['accountholder'];
+                    var accountnumber = debits[i]['accountnumber'];
+                    var bankcode = debits[i]['bankcode'];
+
+                    // Encrypt/Decrypt data using AES with masterkey
+                    if (accountholder != "") accountholder = Crypto.charenc.UTF8.bytesToString(Crypto.AES.decrypt(accountholder, masterkey));
+                    if (accountnumber != "") accountnumber = Crypto.charenc.UTF8.bytesToString(Crypto.AES.decrypt(accountnumber, masterkey));
+                    if (bankcode != "") bankcode = Crypto.charenc.UTF8.bytesToString(Crypto.AES.decrypt(bankcode, masterkey));
+
+                    // Mandatsreferenz '/V1/M:n/'; z.B. /V:1/M:2/
+                    var mandateref = '/V:1/M:' + debits[i]['member_number'] + '/';
+                    var e2eid = '/V:1/E2E:' + parseInt(SEPACORE.creationdate.getTime() / 1000) + '/S:' + debits[i]['debittype'][0] + '/I:' + i + '/';
+                    if (!SEPACORE.addDDTx(debits[i]['debittype'], accountholder, accountnumber, bankcode, mandateref, debits[i]['ddmandatesigdate'].substring(0, 10), debits[i]['amountcent'], debits[i]['purpose'], e2eid)) {
+                        $('#directdebit_content').val('Mitglied ' + debits[i]['member_number'] + ' ' + accountholder + '\n' + SEPACORE.errormsg);
+                        return;
+                    }
+                }
+
+                directdebitcontent = SEPACORE.getXMLContent('FRST');
+                directdebitcontent2 = SEPACORE.getXMLContent('RCUR');
+
+                if (SEPACORE.errormsg.lenght > 0) {
+                    $('#directdebit_content').val(SEPACORE.errormsg);
+                    return;
+                }
+            };
+            $('#directdebit_content').val(directdebitcontent);
+            $('#directdebit_content2').val(directdebitcontent2);
+            $('#directdebit_content').focus();
+            $('#directdebit_content').select();
+        }
 
+        )
+        }
 
-</script>
-<?
+        function directdebit_close() {
+            modal_window_hide();
+            $("#directdebit_content").val('');
+            $("#directdebit_content2").val('');
+        }
+    </script>
+    <?php
 }
 
 // borrowed from PEARs Payment_DTA
-function dtaus_string($string) {
-    if (strlen($string) == 0) return '';
+function dtaus_string($string)
+{
+    if (strlen($string) == 0) {
+        return '';
+    }
     $special_chars = array(
         'á' => 'a',
         'à' => 'a',
@@ -369,7 +385,6 @@ function dtaus_string($string) {
         'Ĥ' => 'H',
         'Ħ' => 'H',
         'ì' => 'i',
-        'ì' => 'i',
         'î' => 'i',
         'ï' => 'i',
         'ĩ' => 'i',
@@ -506,7 +521,6 @@ function dtaus_string($string) {
         'Ž' => 'Z',
     );
 
-
     $result = strtr($string, $special_chars);   // replace known special chars
     $result = strtoupper($result);                  // upper case
     // make sure every special char is replaced by one space, not two or three
@@ -515,4 +529,3 @@ function dtaus_string($string) {
 
     return $result;
 }
-