Payment_Clieop
[ class tree: Payment_Clieop ] [ index: Payment_Clieop ] [ all elements ]

Source for file clieop.php

Documentation is available at clieop.php

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. // +----------------------------------------------------------------------+
  4. // | PHP Version 4                                                        |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2003 The PHP Group                                |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 2.0 of the PHP license,       |
  9. // | that is bundled with this package in the file LICENSE, and is        |
  10. // | available at through the world-wide-web at                           |
  11. // | http://www.php.net/license/2_02.txt.                                 |
  12. // | If you did not receive a copy of the PHP license and are unable to   |
  13. // | obtain it through the world-wide-web, please send a note to          |
  14. // | license@php.net so we can mail you a copy immediately.               |
  15. // +----------------------------------------------------------------------+
  16. // | Authors: Dave Mertens <dmertens@zyprexia.com>                        |
  17. // +----------------------------------------------------------------------+
  18. //
  19. // $Id: clieop.php,v 1.16 2007/03/13 03:52:01 cellog Exp $
  20. /*
  21.  Please note that public function names are partly in Dutch. This is because 
  22.  also the clieop data strings has a dutch names. (batchvoorloopinfo, transactieinfo, etc).
  23.  */
  24.  
  25. /**
  26. * Main clieop class
  27. *
  28. @version $Revision: 1.16 $
  29. @access public
  30. @author Dave Mertens <dmertens@zyprexia.com>
  31. @package Payment_Clieop
  32. */
  33. class ClieopPayment extends clieop_baseobject
  34. {
  35.     /**
  36.     * @var string 
  37.     * @access private
  38.     */
  39.     var $_SenderIdent;
  40.  
  41.     /**
  42.     * @var string 
  43.     * @access private
  44.     */
  45.     var $_FileIdent;
  46.  
  47.     /**
  48.     * @var string 
  49.     * @access private
  50.     */
  51.     var $_TransactionType;
  52.  
  53.     /**
  54.     * @var string 
  55.     * @access private
  56.     */
  57.     var $_ClieopText;
  58.  
  59.     /**
  60.     * @var string 
  61.     * @access private
  62.     */
  63.     var $_PrincipalAccountNumber;
  64.  
  65.     /**
  66.     * @var string 
  67.     * @access private
  68.     */
  69.     var $_PrincipalName;
  70.  
  71.     /**
  72.     * @var integer 
  73.     * @access private
  74.     */
  75.     var $_BatchNumber;
  76.  
  77.     /**
  78.     * @var integer 
  79.     * @access private
  80.     */
  81.     var $_TransactionCount;
  82.  
  83.     /**
  84.     * @var integer 
  85.     * @access private
  86.     */
  87.     var $_TotalAmount;
  88.  
  89.     /**
  90.     * @var string 
  91.     * @access private
  92.     */
  93.     var $_AccountChecksum;
  94.  
  95.     /**
  96.     * @var string 
  97.     * @access private
  98.     */
  99.     var $_Description;
  100.  
  101.     /**
  102.     * @var int 
  103.     * @access private
  104.     */
  105.     var $_NumberOfTransactions = 0;
  106.  
  107.     /**
  108.     * @var date (in DDMMYY format)
  109.     * @access private
  110.     */
  111.     var $_ProcessDate;
  112.  
  113.     /**
  114.     * @var boolean 
  115.     * @access private
  116.     */
  117.     var $_Test;
  118.  
  119.     /**
  120.     * @var string 
  121.     * @access private
  122.     */
  123.     var $_TransactionText;
  124.  
  125.     /**
  126.     * Constructor for class
  127.     * @return void 
  128.     * @access public
  129.     */
  130.     function clieopPayment()
  131.     {
  132.         //init vars
  133.         $this->_ProcessDate "000000";    //process ASAP
  134.         $this->_BatchNumber = 1;
  135.         $this->_Test "T";
  136.         return 1;
  137.     }
  138.  
  139.     /**
  140.     * Adds a payment record to the clieop file
  141.     * @param object paymentObject    - Instance of transactionPayment
  142.     * @access public
  143.     * @return void 
  144.     */
  145.     function addPayment($paymentObject)
  146.     {
  147.         //Only one type of transaction is allowed in a clieop
  148.         if ($this->_TransactionType == $paymentObject->getPaymentType())
  149.         {
  150.             //transactieinfo (0100)
  151.             $text $this->writeTransactieInfo($paymentObject->getTransactionType(),
  152.                 $paymentObject->getAmount(),
  153.                 $paymentObject->getAccountNumberSource(),
  154.                 $paymentObject->getAccountNumberDest());
  155.                 
  156.             // Debtor name ans city
  157.             if (strtoupper($this->_TransactionType== "DEBTOR")
  158.             {
  159.                 //name of debtor (0110)
  160.                 $text .= $this->writeNaambetalerInfo($paymentObject->getName());
  161.  
  162.                 //city of debtor (0113)
  163.                 $text .= $this->writeWoonplaatsbetalerInfo($paymentObject->getCity());
  164.             }
  165.             
  166.             //betalings kenmerk (0150)
  167.             $text .= $this->writeBetalingskenmerkInfo($paymentObject->getInvoiceReference());
  168.             
  169.             //maximum 4 description lines (0160)
  170.             $descArray $paymentObject->getDescription();
  171.             while(list($id,$desceach($descArray))
  172.             {    
  173.                 $text .= $this->writeOmschrijvingInfo($desc);    
  174.             }
  175.             
  176.             //routine splits here into creditor and debtor
  177.             if (strtoupper($this->_TransactionType== "CREDITOR")
  178.             {
  179.                     //name of creditor (0170)
  180.                     $text .= $this->writeNaambegunstigdeInfo($paymentObject->getName());
  181.             
  182.                     //city of creditor (0173)
  183.                     $text .= $this->writeWoonplaatsbegunstigdeInfo($paymentObject->getCity());
  184.             }
  185.             
  186.             //do some calculations
  187.             $this->_NumberOfTransactions++;
  188.             //accoutnumber checksum
  189.             $this->_AccountChecksum += (int)$paymentObject->getAccountNumberSource(+ (int)$paymentObject->getAccountNumberDest();
  190.             $this->_TotalAmount += $paymentObject->getAmount();
  191.         }
  192.         $this->_TransactionText .= $text;
  193.     }
  194.     
  195.     /**
  196.     * Writes complete clieop file
  197.     * @access public
  198.     * @return string 
  199.     */
  200.     function writeClieop()
  201.     {
  202.         $text  $this->writeBestandsvoorloopInfo($this->_SenderIdent$this->_BatchNumber);
  203.         $text .= $this->writeBatchvoorloopInfo($this->_PrincipalAccountNumber$this->_BatchNumber);
  204.         $text .= $this->writeVasteomschrijvingInfo($this->_FixedDescription);
  205.         $text .= $this->writeOpdrachtgeverInfo($this->_ProcessDate$this->_PrincipalName);
  206.         $text .= $this->_TransactionText;
  207.         $text .= $this->writeBatchsluitInfo();
  208.         $text .= $this->writeBestandssluitInfo();
  209.         
  210.         //return clieop file
  211.         return $text;
  212.     }
  213.     
  214.     /**
  215.     * property BatchNumber
  216.     * @param integer Value    - Number of batches send to day (including this one)
  217.     * @return string 
  218.     * @access public
  219.     */
  220.     function getBatchNumber()
  221.     {
  222.         return $this->_BatchNumber;
  223.     }
  224.     function setBatchNumber($Value)
  225.     {
  226.         $this->_BatchNumber $Value;
  227.     }
  228.     
  229.     /**
  230.     * property FixedDescription
  231.     * @param string Value    - Description which will be added to each transaction payment
  232.     * @return string 
  233.     * @access public
  234.     */
  235.     function getFixedDescription()
  236.     {
  237.         return $this->_FixedDescription;
  238.     }
  239.     function setFixedDescription($Value)
  240.     {
  241.         $this->_FixedDescription $Value;
  242.     }
  243.     
  244.     /**
  245.     * property SenderIdentification
  246.     * @param string Value    - Identification of sender, free of choice
  247.     * @return string 
  248.     * @access public
  249.     */
  250.     function getSenderIdentification()
  251.     {
  252.         return $this->_SenderIdent;
  253.     }
  254.     function setSenderIdentification($Value)
  255.     {
  256.         $this->_SenderIdent $Value;
  257.     }
  258.     
  259.     /**
  260.     * property PrincipalName
  261.     * @param string Value    - Name of principal
  262.     * @return string 
  263.     * @access public
  264.     */
  265.     function getPrincipalName()
  266.     {
  267.         return $this->_PrincipalName;
  268.     }
  269.     function setPrincipalName($Value)
  270.     {
  271.         $this->_PrincipalName $Value;
  272.     }
  273.     
  274.     /**
  275.     * property PrincipalAccountNumber
  276.     * @param string Value    - Account number of principal
  277.     * @return string 
  278.     * @access public
  279.     */
  280.     function getPrincipalAccountNumber()
  281.     {
  282.         return $this->_PrincipalAccountNumber;
  283.     }
  284.     function setPrincipalAccountNumber($Value)
  285.     {
  286.         $this->_PrincipalAccountNumber $Value;
  287.     }
  288.     
  289.     /**
  290.     * property TransactionType
  291.     * @param string Value    - transaction type
  292.     * @return string 
  293.     * @access public
  294.     */
  295.     function getTransactionType()
  296.     {
  297.         return $this->_TransactionType;
  298.     }
  299.     function setTransactionType($Value)
  300.     {
  301.         switch($Value)
  302.         {
  303.             case "00":    //BETALING
  304.                 $this->_TransactionType "CREDITOR";
  305.                 $this->_TransactionCode "00";
  306.                 break;
  307.             case "10":    //INCASSO
  308.                 $this->_TransactionType "DEBTOR";
  309.                 $this->_TransactionCode "10";
  310.                 break;
  311.         }
  312.     }
  313.     
  314.     /**
  315.     * property Test
  316.     * @param boolean Value    - true = test clieop, false = production clieop
  317.     * @return string 
  318.     * @access public
  319.     */
  320.     function getTest()
  321.     {
  322.         return $this->_Test;
  323.     }
  324.     function setTest($Value)
  325.     {
  326.         if ($Value == false)
  327.             $this->_Test "P";    //production clieop
  328.         else
  329.             $this->_Test "T";    //test clieop
  330.     }
  331.         
  332.     
  333.     /**
  334.     * INFOCODE: 0100
  335.     * Writes transaction header
  336.     * @param string transType            - Type of transaction ('0000' for betaling, '1002' for incasso)
  337.     * @param integer amount                - Payment amount in Eurocents
  338.     * @param string accountNumberSource    - Source bankaccount number
  339.     * @param string accountNumberDest    - Destination bankaccount number
  340.     * @access private
  341.     * @return string 
  342.     */
  343.     function writeTransactieInfo($transType$amount$accountNumberSource$accountNumberDest)
  344.     {
  345.         $text  "0100";                                        //infocode
  346.         $text .= "A";                                            //variantcode
  347.         $text .= $this->numFiller($transType4);                //transactiesoort
  348.         $text .= $this->numFiller($amount12);                    //Bedrag
  349.         $text .= $this->numFiller($accountNumberSource10);    //Reknr betaler
  350.         $text .= $this->numFiller($accountNumberDest10);        //Reknr begunstigde
  351.         $text .= $this->filler(9);
  352.         
  353.         //return clieop line
  354.         return $text;
  355.     }
  356.     
  357.     /**
  358.     * INFOCODE: 0150
  359.     * Writes invoice reference clieop line
  360.     * @param string invoiceReference    - Reference of invoice
  361.     * @access private
  362.     * @return string 
  363.     */
  364.     function  writeBetalingskenmerkInfo($invoiceReference)
  365.     {
  366.         $text  "0150";                                    //infocode
  367.         $text .= "A";                                        //variantcode
  368.         $text .= $this->alfaFiller($invoiceReference16);    //betalings kenmerk
  369.         $text .= $this->filler(29);
  370.         
  371.         //return clieop line
  372.         if (strlen($invoiceReference> 0return $text;    //only return string if there's really a value
  373.     }    
  374.  
  375.     /**
  376.     * INFOCODE: 0160
  377.     * Writes an description for the clieop file
  378.     * @param string description    - Description of payment (Can be called maximum 4 times!)
  379.     * @access private
  380.     * @return string 
  381.     */
  382.     function writeOmschrijvingInfo($description)
  383.     {
  384.         $text  "0160";                                    //infocode
  385.         $text .= "A";                                        //variantcode
  386.         $text .= $this->alfaFiller($description32);        //omschrijving van post
  387.         $text .= $this->filler(13);
  388.         
  389.         //return clieop line
  390.         return $text;
  391.     }
  392.     
  393.     /**
  394.     * INFOCODE: 0170
  395.     * Write the creditor name record
  396.     * @param string name     - Name of creditor
  397.     * @access private
  398.     * @return string 
  399.     */
  400.     function writeNaambegunstigdeInfo($name)
  401.     {
  402.         $text  "0170";                                    //infocode
  403.         $text .= "B";                                        //variantcode
  404.         $text .= $this->alfaFiller($name35);                //naam begunstigde
  405.         $text .= $this->filler(10);
  406.         
  407.         //reurn clieop line
  408.         return $text;
  409.     }
  410.  
  411.     /**
  412.     * INFOCODE: 0173
  413.     * Write the creditor city record
  414.     * @param string city     - City of creditor
  415.     * @access private
  416.     * @return string 
  417.     */
  418.     function writeWoonplaatsbegunstigdeInfo($city)
  419.     {
  420.         $text  "0173";                                    //infocode
  421.         $text .= "B";                                        //variantcode
  422.         $text .= $this->alfaFiller($city35);                //woonplaats begunstigde
  423.         $text .= $this->filler(10);
  424.         
  425.         //reurn clieop line
  426.         return $text;
  427.     }
  428.     /**
  429.     * INFOCODE: 0110
  430.     * Write the debtor name record
  431.     * @param string name     - Name of debtor
  432.     * @access private
  433.     * @return string 
  434.     */
  435.     function writeNaambetalerInfo($name)
  436.     {
  437.         $text  "0110";                                    //infocode
  438.         $text .= "B";                                        //variantcode
  439.         $text .= $this->alfaFiller($name35);                //naam betaler
  440.         $text .= $this->filler(10);
  441.         
  442.         //reurn clieop line
  443.         return $text;
  444.     }
  445.  
  446.     /**
  447.     * INFOCODE: 0113
  448.     * Write the debtor city record
  449.     * @param string city     - City of debtor
  450.     * @access private
  451.     * @return string 
  452.     */
  453.     function writeWoonplaatsbetalerInfo($city)
  454.     {
  455.         $text  "0113";                                    //infocode
  456.         $text .= "B";                                        //variantcode
  457.         $text .= $this->alfaFiller($city35);                //woonplaats betaler
  458.         $text .= $this->filler(10);
  459.         
  460.         //reurn clieop line
  461.         return $text;
  462.     }
  463.     
  464.     /**
  465.     * INFOCODE: 0001
  466.     * Write clieop header
  467.     * @param string identifier    - 5 char sender identification (free of choice)
  468.     * @param integer batchCount    - Numbers of clieop batches send today + 1
  469.     * @access private
  470.     * @return string 
  471.     */
  472.     function writeBestandsvoorloopInfo($identifier$batchCount)
  473.     {
  474.         $text  "0001";                                        //infocode
  475.         $text .= "A";                                            //variantcode
  476.         $text .= date("dmy");                                    //aanmaak datum
  477.         $text .= "CLIEOP03";                                    //bestands naam
  478.         $text .= $this->alfaFiller($identifier5);                //afzender identificatie
  479.         $text .= date("d"$this->numFiller($batchCount2);    //bestands identificatie 
  480.         $text .= "1";                                            //duplicaat code
  481.         $text .= $this->filler(21);    
  482.         
  483.         //return cliep line
  484.         return $text;
  485.     }
  486.     
  487.     /**
  488.     * INFOCODE: 9999
  489.     * Write clieop footer
  490.     * @access private
  491.     * @return string 
  492.     */
  493.     function writeBestandssluitInfo()
  494.     {
  495.         $text  "9999";                                    //infocode
  496.         $text .= "A";                                        //variantcode
  497.         $text .= $this->filler(45);
  498.         
  499.         //return cleip line
  500.         return $text;
  501.     }
  502.     
  503.     /**
  504.     * INFOCODE: 0010
  505.     * Write clieop batchvoorloopinfo
  506.     * @param string principalAccountNumber    - Account number of principal
  507.     * @param integer batchCount                - Number of batches send this month (including this one)
  508.     * @access private
  509.     * @return string 
  510.     */
  511.     function writeBatchvoorloopInfo($principalAccountNumber$batchCount)
  512.     {    
  513.         $text  "0010";                                        //infocode
  514.         $text .= "B";                                            //variantcode
  515.         $text .= $this->numFiller($this->_TransactionCode2);    //transactiegroep (00 = betaling, 10 = incasso)
  516.         $text .= $this->numFiller($principalAccountNumber10);    //rekening nummer opdrachtgever
  517.         $text .= $this->numFiller($batchCount4);                //batch volgnummer
  518.         $text .= "EUR";                                            //aanlevering muntsoort
  519.         $text .= $this->filler(26);
  520.         
  521.         //return clieop line
  522.         return $text;
  523.     }
  524.     
  525.     /**
  526.     * INFOCODE: 0020
  527.     * Write clieop batchvoorloopinfo
  528.     * @access string description    - Fixed description for all payments
  529.     * @access private
  530.     * @return string 
  531.     */
  532.     function writeVasteomschrijvingInfo($description)
  533.     {
  534.         $text  "0020";                                        //infocode
  535.         $text .= "A";                                            //variantcode
  536.         $text .= $this->alfaFiller($description32);            //vaste omschrijving
  537.         $text .= $this->filler(13);
  538.         
  539.         //return clieop line
  540.         if (strlen($description> 0return $text;                //only return string if there is REALLY a description
  541.     }
  542.  
  543.     /**
  544.     * INFOCODE: 0030
  545.     * Write opdrachtegever clieop line
  546.     * @param date processDate        - Process date in DDMMYY-format
  547.     * @param string principalName    - Name of pricipal
  548.     * @access private
  549.     * @return string 
  550.     */
  551.     function writeOpdrachtgeverInfo($processDate$principalName)
  552.     {
  553.         $text  "0030";                                        //infocode
  554.         $text .= "B";                                            //variantcode
  555.         $text .= "1";                                            //NAWcode
  556.         $text .= $this->numFiller($processDate6);                //verwerkings datum
  557.         $text .= $this->alfaFiller($principalName35);            //naam opdracht gever
  558.         $text .= $this->_Test;                                    //TESTcode (T = Test, P = Productie)
  559.         $text .= $this->filler(2);
  560.         
  561.         //return clieop line
  562.         return $text;
  563.     }
  564.     
  565.     /**
  566.     * INFOCODE: 9990
  567.     * Write clieop batchsluitinfo
  568.     * @access private
  569.     * @return string 
  570.     */
  571.     function writeBatchsluitInfo()
  572.     {
  573.         $text  "9990";                                            //infocode
  574.         $text .= "A";                                                //variantcode
  575.         $text .= $this->numFiller($this->_TotalAmount18);            //Totaalbedrag clieop
  576.         $text .= $this->numFiller($this->_AccountChecksum10);        //checksum van rekeningnummers
  577.         $text .= $this->numFiller($this->_NumberOfTransactions7);    //Aantal transactie posten
  578.         $text .= $this->filler(10);
  579.         
  580.         //return clieop line
  581.         return $text;
  582.     }
  583. }
  584.  
  585.  
  586. /**
  587. *    master object for clieop objects
  588. *
  589. @version $Revision: 1.16 $
  590. @access private
  591. @author Dave Mertens <dmertens@zyprexia.com>
  592. @package Payment_Clieop
  593. */
  594. class clieop_baseobject
  595. {
  596.  
  597.     /**
  598.     * Alfa numeric filler
  599.     * @param string text    - Text which needs to filled up
  600.     * @param integer length    - The length of the required text
  601.     * @return string 
  602.     * @access public
  603.     */
  604.     function alfaFiller($text$length)
  605.     {
  606.         //how many spaces do we need?
  607.         $alfaLength abs($length strlen($text));
  608.         
  609.         //return string with spaces on right side
  610.         return substr($text str_repeat(" "$alfaLength)0$length);
  611.     }
  612.     
  613.     /**
  614.     * Numeric filler
  615.     * @param string number    - number which needs to filled up (Will be converted to a string)
  616.     * @param integer length    - The length of the required number
  617.     * @return string 
  618.     * @access public
  619.     */
  620.     function numFiller($number$length)
  621.     {
  622.         //how many zeros do we need
  623.         settype($number"string");        //We need to be sure that number is a string. 001 will otherwise be parsed as 1
  624.         $numberLength abs($length strlen($number));
  625.         
  626.         //return original number woth zeros on the left
  627.         return substr(str_repeat("0"$numberLength$number-$length);
  628.     }
  629.     
  630.     /**
  631.     * filler
  632.     * @param integer length    - How many filler spaces do we need
  633.     * @return string 
  634.     * @access public
  635.     */
  636.     function filler($Length)
  637.     {
  638.         return str_repeat(" "$Length"\n";
  639.     }
  640. }
  641.  
  642. ?>

Documentation generated on Mon, 11 Mar 2019 14:57:20 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.