lib/Jejik/MT940/Parser/AbstractParser.php
protected function transaction(array $lines)
    {
        if (!preg_match('/(\d{6})((\d{2})(\d{2}))?(C|D)([A-Z]?)([0-9,]{1,15})/', $lines[0], $match)) {
            throw new \RuntimeException(sprintf('Could not parse transaction line "%s"', $lines[0]));
        }

        // Parse the amount
        $amount = (float) str_replace(',', '.', $match[7]);
        if ($match[5] === 'D') {
            $amount *= -1;
        }

        // Parse dates
        $valueDate = \DateTime::createFromFormat('ymd', $match[1]);
        $valueDate->setTime(0, 0, 0);

        $bookDate = null;

        if ($match[2]) {
            // Construct book date from the month and day provided by adding the year of the value date as best guess.
            $month = intval($match[3]);
            $day = intval($match[4]);
            $bookDate = $this->getNearestDateTimeFromDayAndMonth($valueDate, $day, $month);
        }

        $description = isset($lines[1]) ? $lines[1] : null;
        $transaction = $this->reader->createTransaction();
        $transaction->setAmount($amount)
                    ->setContraAccount($this->contraAccount($lines))
                    ->setValueDate($valueDate)
                    ->setBookDate($bookDate)
                    ->setDescription($this->description($description));

        return $transaction;
    }
protected function transaction(array $lines)
    {
        if (!preg_match('/(\d{6})((\d{2})(\d{2}))?(C|D)([A-Z]?)([0-9,]{1,15})/', $lines[0], $match)) {
            throw new \RuntimeException(sprintf('Could not parse transaction line "%s"', $lines[0]));
        }

        // Parse the amount
        $amount = (float) str_replace(',', '.', $match[7]);
        if ($match[5] === 'D') {
            $amount *= -1;
        }

        // Parse dates
        $valueDate = \DateTime::createFromFormat('ymd', $match[1]);
        $valueDate->setTime(0, 0, 0);

        $bookDate = null;

        if ($match[2]) {
            // Construct book date from the month and day provided by adding the year of the value date as best guess.
            $month = intval($match[3]);
            $day = intval($match[4]);
            $bookDate = $this->getNearestDateTimeFromDayAndMonth($valueDate, $day, $month);
        }

        $description = isset($lines[1]) ? $lines[1] : null;
        $transaction = $this->reader->createTransaction();
        $transaction->setAmount($amount)
                    ->setContraAccount($this->contraAccount($lines))
                    ->setValueDate($valueDate)
                    ->setBookDate($bookDate)
                    ->setDescription($this->description($description));

        return $transaction;
    }
protected function transaction ( array $ lines ) { if ( ! preg_match ( '/(\d{6})((\d{2})(\d{2}))?(C|D)([A-Z]?)([0-9,]{1,15})/' , $ lines [ 0 ] , $ match ) ) { throw new \ RuntimeException ( sprintf ( 'Could not parse transaction line "%s"' , $ lines [ 0 ] ) ) ; } // Parse the amount $ amount = ( float ) str_replace ( ',' , '.' , $ match [ 7 ] ) ; if ( $ match [ 5 ] === 'D' ) { $ amount *= - 1 ; } // Parse dates $ valueDate = \ DateTime :: createFromFormat ( 'ymd' , $ match [ 1 ] ) ; $ valueDate -> setTime ( 0 , 0 , 0 ) ; $ bookDate = null ; if ( $ match [ 2 ] ) { // Construct book date from the month and day provided by adding the year of the value date as best guess. $ month = intval ( $ match [ 3 ] ) ; $ day = intval ( $ match [ 4 ] ) ; $ bookDate = $ this -> getNearestDateTimeFromDayAndMonth ( $ valueDate , $ day , $ month ) ; } $ description = isset ( $ lines [ 1 ] ) ? $ lines [ 1 ] : null ; $ transaction = $ this -> reader -> createTransaction ( ) ; $ transaction -> setAmount ( $ amount ) -> setContraAccount ( $ this -> contraAccount ( $ lines ) ) -> setValueDate ( $ valueDate ) -> setBookDate ( $ bookDate ) -> setDescription ( $ this -> description ( $ description ) ) ; return $ transaction ; }
Create a Transaction from MT940 transaction text lines

@param array $lines The transaction text at offset 0 and the description at offset 1
@return \Jejik\MT940\Transaction
Create a Transaction from MT940 transaction text lines