Location: PHPKode > projects > crVCL PHP Framework > dta.lib.php
<?php

/* 

The contents of this file are subject to the Mozilla Public License
Version 1.1 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/MPL-1.1.html or see MPL-1.1.txt in directory "license"

Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for
the specific language governing rights and limitations under the License.

The Initial Developers of the Original Code are: 
Copyright (c) 2003-2012, CR-Solutions (http://www.cr-solutions.net), Ricardo Cescon
All Rights Reserved.

Contributor(s): Ricardo Cescon

crVCL PHP Framework Version 2.4
*/


############################################################
if(!defined("DTA_LIB")){
   define ("DTA_LIB", 1);
############################################################
require("define.lib.php");
require("tools.lib.php");

/**
 * basic class for DAT files
 *
 */
class DTA{
// private
    var $m_type;
    var $m_validChars;
    var $m_exchanges;

// public
    /**
     * sender's account number
     *
     * @var stirng
     */
    var $m_accountnum = "";
    /**
     * sender's bank code
     *
     * @var string
     */
    var $m_bankcode = "";
//-------------------------------------------------------------------------------------------------------------------------------------
// private
    function transString($str){
         $ret = "";

         $str = strtoupper($str);

         if(strlen($str) > 0){
            $search = array(
                "'Ä'",
                "'Ö'",
                "'Ü'",
                "'ä'", // also check low chars for UTF-8 Bug in function strtoupper
                "'ö'",
                "'ü'",
                "'ß'"
            );

            $replace = array(
                "AE",
                "OE",
                "UE",
                "AE",
                "OE",
                "UE",
                "SS"
            );

            $ret = preg_replace($search, $replace, $str);

            for($i = 0; $i < strlen($ret); $i++){
                if(!in_array(ord(substr($ret, $i, 1)), $this->m_validChars)){
                    $ret[$i] = " ";
                }
            }
         }

         return $ret;
    }
//-------------------------------------------------------------------------------------------------------------------------------------
// public
   /**
    * save to file
    *
    * @param  string $filename
    * @access public
    * @return int
    */
    function save($filename) {
        $fbuf = $this->getFileContent();

        $f = @fopen($filename, "w");
        if(!f){
            $ret = false;
        }else{
            $ret = @fwrite($f, $fbuf);
            @fclose($f);
        }
        return $ret;
    }
//-------------------------------------------------------------------------------------------------------------------------------------
}
//-------------------------------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------------------------------
/**
* DTAUS class provides functions to create DTAUS files
* used in Germany to exchange informations about money transactions with
* banks or online banking programs
* to test the DTAUS file see: https://www.xpecto.de/dtauschecker/
*/
class DTAUS extends DTA{

// public
   /**
    * sender's name, max. 27 chars are allowed
    *
    * @var string
    */
    var $m_sender_name = "";
    /**
     * additional name, maximally 27 chars.
     *
     * @var string
     */
    var $m_additional_name = "";
//-------------------------------------------------------------------------------------------------------------------------------------
// constructor
    /**
    * @param  int $type DTA_CREDIT or DTA_DEBIT
    * @access public
    */
    function DTAUS($type){
        $this->m_type = $type;

        $this->m_validChars = array(32, 36, 37, 38, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 196, 214, 220, 223);

        $this->m_exchanges = array();
    }
//-------------------------------------------------------------------------------------------------------------------------------------
// public
    /**
    * add an exchange
    *
    * @param  array $receiver_data receiver account data, possible keys: name, bankcode, accountnum, additional_name
    * @param  double $amount
    * @param  int $amount (euro cents)
    * @param  mixed $purpose string or array of up to 15 lines (maximally 27 chars each) for description of the exchange
    * @param  array $account_sender  optional sender's account data, by default set by public memvars
    * @access public
    * @return boolean
    */
    function addExchange($receiver_data, $amount, $purpose, $account_sender = array()){
         if (empty($receiver_data['additional_name'])) {
            $receiver_data['additional_name'] = "";
         }
         if (empty($account_sender['name'])) {
            $account_sender['name'] = $this->m_sender_name;
         }
         if (empty($account_sender['bankcode'])) {
            $account_sender['bankcode'] = $this->m_bankcode;
         }
         if (empty($account_sender['accountnum'])) {
            $account_sender['accountnum'] = $this->m_accountnum;
         }
         if (empty($account_sender['additional_name'])) {
            $account_sender['additional_name'] = $this->m_additional_name;
         }

         if(is_string($purpose)) {
            $purpose = array($purpose);
         }

         for($i = 0; $i < count($purpose); $i++){
             $purpose[$i] = substr($this->transString($purpose[$i]), 0, 27);
         }

         if(!is_numeric($account_sender['accountnum']) || !is_numeric($account_sender['bankcode'])
         || !is_numeric($receiver_data['accountnum']) || !is_numeric($receiver_data['bankcode'])
         || !is_numeric($amount) || !is_int($amount)){

            return false;
         }

         $this->m_exchanges[] = array(
             "sender_name"               => substr($this->transString($account_sender['name']), 0, 27),
             "sender_bankcode"           => $account_sender['bankcode'],
             "sender_accountnum"         => $account_sender['accountnum'],
             "sender_additional_name"    => substr($this->transString($account_sender['additional_name']), 0, 27),
             "receiver_name"             => substr($this->transString($receiver_data['name']), 0, 27),
             "receiver_bankcode"         => $receiver_data['bankcode'],
             "receiver_accountnum"       => $receiver_data['accountnum'],
             "receiver_additional_name"  => substr($this->transString($receiver_data['additional_name']), 0, 27),
             "amount"                    => $amount,
             "purpose"                   => $purpose
         );
         return true;
    }
//-------------------------------------------------------------------------------------------------------------------------------------
    /**
    * returns the full content of the generated DTA file
    *
    * @access public
    * @return string
    */
    function getFileContent(){
        $fbuf = "";

        $sum_account_numbers = 0;
        $sum_bank_codes = 0;
        $sum_amounts = 0;


        /**
         * data record A
         */

        // record length (128 Bytes)
        $fbuf .= str_pad("128", 4, "0", STR_PAD_LEFT);
        // record type
        $fbuf .= "A";
        // file mode (credit or debit)
        $fbuf .= ($this->m_type == DTA_CREDIT) ? "G" : "L";
        // Customer File ("K") / Bank File ("B")
        $fbuf .= "K";
        // sender's bank code
        $fbuf .= str_pad($this->m_bankcode, 8, "0", STR_PAD_LEFT);
        // only used if bank file, otherwise NULL
        $fbuf .= str_repeat("0", 8);
        // sender's name
        $fbuf .= str_pad($this->transString($this->m_sender_name), 27, " ", STR_PAD_RIGHT);
        // date of file creation
        $fbuf .= strftime("%d%m%y", time());
        // free (bank internal)
        $fbuf .= str_repeat(" ", 4);
        // sender's account number
        $fbuf .= str_pad($this->m_accountnum, 10, "0", STR_PAD_LEFT);
        // sender's reference number (optional)
        $fbuf .= str_repeat("0", 10);
        // free (reserve)
        $fbuf .= str_repeat(" ", 15);
        // execution date "DDMMYYYY", optional
        $fbuf .= str_repeat(" ", 8);
        // free (reserve)
        $fbuf .= str_repeat(" ", 24);
        // currency (1 = Euro)
        $fbuf .= "1";


        /**
         * data record(s) C
         */

        foreach($this->m_exchanges as $exchange){
            $sum_account_numbers += $exchange['receiver_accountnum'];
            $sum_bank_codes += $exchange['receiver_bankcode'];
            $sum_amounts += $exchange['amount'];

            $additional_purposes = $exchange['purpose'];

            $first_purpose = array_shift($additional_purposes);

            $additional_parts = array();

            if (strlen($exchange['receiver_additional_name']) > 0) {
                $additional_parts[] = array("type" => "01",
                    "content" => $exchange['receiver_additional_name']
                    );
            }

            foreach ($additional_purposes as $additional_purpose) {
               if(trim($additional_purpose) != ""){
                   $additional_parts[] = array("type" => "02",
                       "content" => $additional_purpose
                       );
               }
            }

            if (strlen($exchange['sender_additional_name']) > 0) {
                $additional_parts[] = array("type" => "03",
                    "content" => $exchange['sender_additional_name']
                    );
            }

            $additional_parts_number = count($additional_parts);
            // record length (187 Bytes + 29 Bytes for each additional part)
            $fbuf .= str_pad(187 + $additional_parts_number * 29, 4, "0", STR_PAD_LEFT);
            // record type
            $fbuf .= "C";
            // first involved bank
            $fbuf .= str_pad($exchange['sender_bankcode'], 8, "0", STR_PAD_LEFT);
            // receiver's bank code
            $fbuf .= str_pad($exchange['receiver_bankcode'], 8, "0", STR_PAD_LEFT);
            // receiver's account number
            $fbuf .= str_pad($exchange['receiver_accountnum'], 10, "0", STR_PAD_LEFT);
            // internal customer number (11 chars) or NULL
            $fbuf .= "0" . str_repeat("0", 11) . "0";
            // payment mode (text key)
            $fbuf .= ($this->m_type == DTA_CREDIT) ? "51" : "05";
            // additional text key
            $fbuf .= "000";
            // bank internal
            $fbuf .= " ";
            // free (reserve)
            $fbuf .= str_repeat("0", 11);
            // sender's bank code
            $fbuf .= str_pad($exchange['sender_bankcode'], 8, "0", STR_PAD_LEFT);
            // sender's account number
            $fbuf .= str_pad($exchange['sender_accountnum'], 10, "0", STR_PAD_LEFT);
            // amount
            $fbuf .= str_pad($exchange['amount'], 11, "0", STR_PAD_LEFT);
            // free (reserve)
            $fbuf .= str_repeat(" ", 3);
            // receiver's name
            $fbuf .= str_pad($exchange['receiver_name'], 27, " ", STR_PAD_RIGHT);
            // delimitation
            $fbuf .= str_repeat(" ", 8);
            // sender's name
            $fbuf .= str_pad($exchange['sender_name'], 27, " ", STR_PAD_RIGHT);
            // first line of purposes
            $fbuf .= str_pad($first_purpose, 27, " ", STR_PAD_RIGHT);
            // currency (1 = Euro)
            $fbuf .= "1";
            // free (reserve)
            $fbuf .= str_repeat(" ", 2);
            // amount of additional parts
            $fbuf .= str_pad($additional_parts_number, 2, "0", STR_PAD_LEFT);

            if (count($additional_parts) > 0) {
                for ($index = 1;$index <= 2;$index++) {
                    if (count($additional_parts) > 0) {
                        $additional_part = array_shift($additional_parts);
                    } else {
                        $additional_part = array("type" => "  ",
                            "content" => ""
                            );
                    }
                    // type of addional part
                    $fbuf .= $additional_part['type'];
                    // additional part content
                    $fbuf .= str_pad($additional_part['content'], 27, " ", STR_PAD_RIGHT);
                }
                // delimitation
                $fbuf .= str_repeat(" ", 11);
            }


            for ($part = 3;$part <= 5;$part++) {
                if (count($additional_parts) > 0) {
                    for ($index = 1;$index <= 4;$index++) {
                        if (count($additional_parts) > 0) {
                            $additional_part = array_shift($additional_parts);
                        } else {
                            $additional_part = array("type" => "  ",
                                "content" => ""
                                );
                        }
                        // type of addional part
                        $fbuf .= $additional_part['type'];
                        // additional part content
                        $fbuf .= str_pad($additional_part['content'], 27, " ", STR_PAD_RIGHT);
                    }
                    // delimitation
                    $fbuf .= str_repeat(" ", 12);
                }
            }

            // add spaces for a content length that is a multiple of 128
    		   if(strlen($fbuf) % 128 != 0)
	      	   $fbuf .= str_repeat(" ", 128-strlen($fbuf) % 128);

        } // foreach exchange


        /**
         * data record E
         */

        // record length (128 bytes)
        $fbuf .= str_pad("128", 4, "0", STR_PAD_LEFT);
        // record type
        $fbuf .= "E";
        // free (reserve)
        $fbuf .= str_repeat(" ", 5);
        // number of records type C
        $fbuf .= str_pad(count($this->m_exchanges), 7, "0", STR_PAD_LEFT);
        // free (reserve)
        $fbuf .= str_repeat("0", 13);
        // sum of account numbers
        $fbuf .= str_pad($sum_account_numbers, 17, "0", STR_PAD_LEFT);
        // sum of bank codes
        $fbuf .= str_pad($sum_bank_codes, 17, "0", STR_PAD_LEFT);
        // sum of amounts
        $fbuf .= str_pad($sum_amounts, 13, "0", STR_PAD_LEFT);
        // delimitation
        $fbuf .= str_repeat(" ", 51);

        return $fbuf;
    }
//-------------------------------------------------------------------------------------------------------------------------------------
}
//-------------------------------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------------------------------
/**
* DTAZV class provides functions to create DTAZV files
* used in Germany to exchange informations about money transactions with
* banks or online banking programs
*/
class DTAZV extends DTA{
// private
    var $m_consecutive_number = 1;
    var $m_validCountrys = array();

// public
   /**
    * sender's name, max. 35 chars are allowed
    *
    * @var string
    */
    var $m_sender_name = "";
    /**
    * sender's name 2, max. 35 chars are allowed
    *
    * @var string
    */
    var $m_sender_name2 = "";
    /**
    * sender's street, max. 35 chars are allowed
    *
    * @var string
    */
    var $m_sender_str = "";
    /**
    * sender's city, max. 35 chars are allowed
    *
    * @var string
    */
    var $m_sender_city = "";
    /**
     *  notify central bank (if true province code and company number must be set)
     * @var bool
     */
     var $m_notify_central_bank = false;
     /**
      * province code
      *
      * @var string
      */
     var $m_province_code = "";
     /**
      * company number
      *
      * @var string
      */
     var $m_company_number = "";
     /**
      * fee regulation   00 => standard, 01 => sender pay, 02 => receiver pay
      *
      * @var string
      */
     var $m_fee_regulation = "00";

//-------------------------------------------------------------------------------------------------------------------------------------
// constructor
    /**
    * @param  int $type DTA_SWIFT, DTA_SWIFT_FAST, DTA_EU_STANDARD or DTA_MIXED (try EU_STANDARD else SWIFT)
    * @param  int $consecutive_number max. 99
    * @access public
    */
    function DTAZV($type, $consecutive_number=1){
        $this->m_type = $type;

        $this->m_validChars = array(32, 36, 37, 38, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 196, 214, 220, 223);

        $this->m_validCountrys = array("DE", "BE", "DK", "EE", "FI", "FR", "GF", "GI", "GR", "GP", "IE", "IT", "LV", "LT", "LU", "MT", "MQ", "NL", "AT", "PL", "PT", "RE", "SE", "SK", "SI", "ES", "CZ", "HU", "GB", "CY");

        $this->m_exchanges = array();

        $this->m_consecutive_number = $consecutive_number;
    }
//-------------------------------------------------------------------------------------------------------------------------------------
// public
    /**
    * add an exchange
    *
    * @param  array $receiver_data receiver account data, possible keys: name, name2, str, city, bankcode, accountnum
    * @param  double $amount
    * @param  int $amount (euro cents)
    * @param  mixed $purpose string or array of up to 15 lines (maximally 35 chars each) for description of the exchange
    * @param  array $account_sender  optional sender's account data, by default set by public memvars
    * @access public
    * @return boolean
    */
    function addExchange($receiver_data, $amount, $purpose, $account_sender = array()){

         if (empty($account_sender['name'])) {
            $account_sender['name'] = $this->m_sender_name;
         }
         if (empty($account_sender['name2'])) {
            $account_sender['name2'] = $this->m_sender_name2;
         }
         if (empty($account_sender['str'])) {
            $account_sender['str'] = $this->m_sender_str;
         }
         if (empty($account_sender['city'])) {
            $account_sender['city'] = $this->m_sender_city;
         }
         if (empty($account_sender['bankcode'])) {
            $account_sender['bankcode'] = $this->m_bankcode;
         }
         if (empty($account_sender['accountnum'])) {
            $account_sender['accountnum'] = $this->m_accountnum;
         }

         if(is_string($purpose)) {
            $purpose = array($purpose);
         }

         for($i = 0; $i < count($purpose); $i++){
             $purpose[$i] = substr($this->transString($purpose[$i]), 0, 35);
         }

         if(!is_numeric($receiver_data['accountnum']) && !is_numeric($receiver_data['bankcode'])){
            $bic_country = strtoupper(substr($receiver_data['bankcode'],4,2));
            $iban_country = strtoupper(substr($receiver_data['accountnum'],0,2));
            if($bic_country != $iban_country || ($this->m_type == DTA_EU_STANDARD && in_array($bic_country, $this->m_validCountrys) === false)){
               return false;
            }
         }

         if(!is_numeric($account_sender['accountnum']) || !is_numeric($account_sender['bankcode'])
         || strlen($receiver_data['accountnum']) < 5 || strlen($receiver_data['bankcode']) < 8
         || !is_numeric($amount) || !is_int($amount)){
            return false;
         }

         if($amount > 12500*100 && empty($this->m_company_number)){
            return false;
         }

         $this->m_exchanges[] = array(
             "sender_name"               => substr($this->transString($account_sender['name']), 0, 35),
             "sender_name2"              => substr($this->transString($account_sender['name2']), 0, 35),
             "sender_str"                => substr($this->transString($account_sender['str']), 0, 35),
             "sender_city"               => substr($this->transString($account_sender['city']), 0, 35),
             "sender_bankcode"           => $account_sender['bankcode'],
             "sender_accountnum"         => $account_sender['accountnum'],
             "receiver_name"             => substr($this->transString($receiver_data['name']), 0, 35),
             "receiver_name2"            => substr($this->transString($receiver_data['name2']), 0, 35),
             "receiver_str"              => substr($this->transString($receiver_data['str']), 0, 35),
             "receiver_city"             => substr($this->transString($receiver_data['city']), 0, 35),
             "receiver_bankcode"         => $receiver_data['bankcode'],
             "receiver_accountnum"       => $receiver_data['accountnum'],
             "amount"                    => $amount,
             "purpose"                   => $purpose
         );
         return true;
    }
//-------------------------------------------------------------------------------------------------------------------------------------
    /**
    * returns the full content of the generated DTA file
    *
    * @access public
    * @return string
    */
    function getFileContent(){
        $fbuf = "";

        $sum_amounts = 0;

        /**
         * data record Q
         */

        // record length (256 Bytes)
        $fbuf .= str_pad("256", 4, "0", STR_PAD_LEFT);
        // record type
        $fbuf .= "Q";
        // senders's bank code
        $fbuf .= str_pad($this->m_bankcode, 8, "0", STR_PAD_LEFT);
        // sender's account number
        $fbuf .= str_pad($this->m_accountnum, 10, "0", STR_PAD_LEFT);
        // sender's name / street / city
        $fbuf .= str_pad($this->transString($this->m_sender_name), 35, " ", STR_PAD_RIGHT);
        $fbuf .= str_pad($this->transString($this->m_sender_name2), 35, " ", STR_PAD_RIGHT);
        $fbuf .= str_pad($this->transString($this->m_sender_str), 35, " ", STR_PAD_RIGHT);
        $fbuf .= str_pad($this->transString($this->m_sender_city), 35, " ", STR_PAD_RIGHT);
        // date of file creation
        $fbuf .= strftime("%y%m%d", time());
        // consecutive number
        $fbuf .= str_pad($this->m_consecutive_number, 2, "0", STR_PAD_LEFT);
        // file execution date
        $fbuf .= strftime("%y%m%d", time());
        // notify central bank
        $fbuf .= ($this->m_notify_central_bank == true ? "J" : "N");
        // province code
        $fbuf .= str_pad($this->m_province_code, 2, "0", STR_PAD_LEFT);
        // senders's company number / bank code
        $fbuf .= str_pad(($this->m_company_number == "" ? $exchange['sender_bankcode'] : $this->m_company_number), 8, "0", STR_PAD_LEFT);
        // free (reserve)
        $fbuf .= str_repeat(" ", 68);

        /**
         * data record(s) T
         */

        foreach($this->m_exchanges as $exchange){
            $bic_country = strtoupper(substr($exchange['receiver_bankcode'],4,2));
            
            $type = $this->m_type;
            if($type == DTA_MIXED){
               $type = DTA_EU_STANDARD;               
               if(in_array($bic_country, $this->m_validCountrys) === false){
                  $type = DTA_SWIFT;   
               }
            }
           
            // record length (768 Bytes)
            $fbuf .= str_pad("768", 4, "0", STR_PAD_LEFT);
            // record type
            $fbuf .= "T";
            // sender's bankcode
            $fbuf .= str_pad($exchange['sender_bankcode'], 8, "0", STR_PAD_LEFT);
            // currency ISO (EUR = Euro)
            $fbuf .= "EUR";
            // sender's account number
            $fbuf .= str_pad($exchange['sender_accountnum'], 10, "0", STR_PAD_LEFT);
            // execution date "YYMMDD"
            $fbuf .= strftime("%y%m%d", time());
            // sernder's main account bankcode, optional
            $fbuf .= str_repeat("0", 8);
            // sernder's main account currency ISO, optional
            $fbuf .= str_repeat(" ", 3);
            // sernder's main account number, optional
            $fbuf .= str_repeat("0", 10);
            // receiver's bank code (bic) and ISO country code (country code optional)
            if(is_numeric($exchange['receiver_bankcode'])){
               $fbuf .= "///".str_pad($exchange['receiver_bankcode'], 8, "0", STR_PAD_LEFT);
               $fbuf .= str_repeat(" ", 3);
            }else{
               $fbuf .= str_pad($exchange['receiver_bankcode'], 11, " ", STR_PAD_RIGHT);
               if($type == DTA_EU_STANDARD){
                  $fbuf .= str_pad(" ", 3, " ", STR_PAD_RIGHT);
               }else{
                  $fbuf .= str_pad(substr($exchange['receiver_bankcode'],4,2), 3, " ", STR_PAD_RIGHT);
               }   
            }
            // receiver's bank adress
            if($bic_country == "DE"){
               $fbuf .= str_pad("UNBEKANNT", 35, " ", STR_PAD_RIGHT);
            }else{
               $fbuf .= str_pad(" ", 35, " ", STR_PAD_RIGHT);
            }
            $fbuf .= str_repeat(" ", 35);
            $fbuf .= str_repeat(" ", 35);
            $fbuf .= str_repeat(" ", 35);
            // receiver's ISO country code
            if($type == DTA_EU_STANDARD){
               $fbuf .= str_pad("", 3, " ", STR_PAD_RIGHT);  
            }else{
               $fbuf .= str_pad(substr($exchange['receiver_bankcode'],4,2), 3, " ", STR_PAD_RIGHT);
            }   
            
            if($type == DTA_EU_STANDARD){
               //$exchange['receiver_name'] = "";
               $exchange['receiver_name2'] = "";
               $exchange['receiver_str'] = "";
               $exchange['receiver_city'] = "";
            }
            
            // receiver's adress
            $fbuf .= str_pad($exchange['receiver_name'], 35, " ", STR_PAD_RIGHT);
            $fbuf .= str_pad($exchange['receiver_name2'], 35, " ", STR_PAD_RIGHT);
            $fbuf .= str_pad($exchange['receiver_str'], 35, " ", STR_PAD_RIGHT);
            $fbuf .= str_pad($exchange['receiver_city'], 35, " ", STR_PAD_RIGHT);
            // optional, only for check
            $fbuf .= str_repeat(" ", 35);
            $fbuf .= str_repeat(" ", 35);
            // receiver's account number
            $fbuf .= str_pad("/".$exchange['receiver_accountnum'], 35, " ", STR_PAD_RIGHT);
            // currency ISO (EUR = Euro)
            $fbuf .= "EUR";
            // amount
            $amount = $exchange['amount'];
            $amount = str_pad($amount, 3, "0");
            $decimal = substr($amount, -2);
            $amount = substr($amount, 0, -2);

            $fbuf .= str_pad($amount, 14, "0", STR_PAD_LEFT);
            $fbuf .= str_pad($decimal, 3, "0", STR_PAD_RIGHT);
            $sum_amounts += $amount;
            // purpose
            $purpose = $exchange['purpose'];
            for($i = 0; $i < 4; $i++){
               $part = array_shift($purpose);
               if($part === null){
                  $part = "";
               }
               $fbuf .= str_pad($part, 35, " ", STR_PAD_RIGHT);
            }
                                    
            // instruction key 1
            $fbuf .= "00";
            // instruction key 2
            $fbuf .= "00";
            // instruction key 3
            $fbuf .= "00";
            // instruction key 4
            $fbuf .= "00";
            // optional info
            $fbuf .= str_repeat(" ", 25);
                                    
            $fee = $this->m_fee_regulation;
            if($type == DTA_EU_STANDARD){
               $fee = "00";
            }
            
            // fee regulation
            $fbuf .= str_pad(substr($fee,0,2), 2, "0", STR_PAD_LEFT);                               
            
            // payment mode (text key)                                 
            if($type == DTA_EU_STANDARD){
               $fbuf .= "13";
            }else if($type == DTA_SWIFT_FAST){
               $fbuf .= "10";
            }else{
               $fbuf .= "00";
            }
            // optional referenz
            $fbuf .= str_repeat(" ", 27);
            // optional contac person
            $fbuf .= str_repeat(" ", 35);
            // use informations only for statistic of central bank
            $fbuf .= ($this->m_notify_central_bank == true ? "1" : "0");
            // free (reserve)
            $fbuf .= str_repeat(" ", 51);
            // additional part
            $fbuf .= "00";

        } // foreach exchange

        /**
         * data record Z
         */

        // record length (256 bytes)
        $fbuf .= str_pad("256", 4, "0", STR_PAD_LEFT);
        // record type
        $fbuf .= "Z";
        // sum of amounts
        $fbuf .= str_pad($sum_amounts, 15, "0", STR_PAD_LEFT);
        // sum of T records
        $fbuf .= str_pad(count($this->m_exchanges), 15, "0", STR_PAD_LEFT);
        // free (reserve)
        $fbuf .= str_repeat(" ", 221);

        return $fbuf;
    }
//-------------------------------------------------------------------------------------------------------------------------------------
}
############################################################
}
############################################################
/*
$dta = new DTAUS(DTA_CREDIT);
$dta->m_sender_name = "Ricardo Cescon";
$dta->m_accountnum = "123456";
$dta->m_bankcode = "76010085";

$recv = array(
   "name" => "Maier",
   "accountnum" => "66666",
   "bankcode" => "76010085"
);


$dta->addExchange($recv, "1000", "Test");

$dta->save("C:/Programme/Apache Software Foundation/Apache2.2/htdocs/test.net/dtaus");
*/
?>
Return current item: crVCL PHP Framework