<commit_before><?php
/**
 * SEPA file parser.
 *
 * @copyright © Gemabit <www.gemabit.com> 2014
 * @license Apache License, Version 2.0
 *
 *  Copyright 2014 Gemabit
 * 
 * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

namespace Gemabit\Sepa\DomParser;

use Gemabit\Sepa\OriginalGroupInformation;
use Gemabit\Sepa\OriginalPaymentInformation;
use Gemabit\Sepa\TransactionInformation\DirectDebitTransactionInformation;
use Gemabit\Sepa\TransactionInformation\PaymentTypeInformation\DirectDebitPaymentTypeInformation;
//use Gemabit\Sepa\TransactionInformation;

/**
 * Used to parse the Dom-structure for the Direct Debit Return File
 *
 * Class DirectDebitReturnDomParser
 * @package Gemabit\Sepa
 * @subpackage Gemabit\Sepa\DomParser
 */
class DirectDebitReturnDomParser extends BaseDomParser
{
	protected $originalGroupInformation;

	protected $originalPaymentInformation;

	function __construct($filepath) {
		parent::__construct($filepath);

        $originalGroupInformationElement = $this->doc->getElementsByTagName('OrgnlGrpInfAndSts')->item(0);
        $originalPaymentInformation      = $this->doc->getElementsByTagName('OrgnlPmtInfAndSts')->item(0);

        $this->fillOriginalGroupInformation($originalGroupInformationElement);
        $this->fillOriginalPaymentInformation($originalPaymentInformation);
    }

    /**
     * Fills up the OriginalGroupInformation with the given DOMElement
     */
    protected function fillOriginalGroupInformation(\DOMElement $DOMOriginalGroupInformation)
    {
        $originalMessageIdentification         = $this->getValue($DOMOriginalGroupInformation, 'OrgnlMsgId');
        $originalMessageNameIdentification     = $this->getValue($DOMOriginalGroupInformation, 'OrgnlMsgNmId');
        $originalNumberOfTransactions          = $this->getValue($DOMOriginalGroupInformation, 'OrgnlNbOfTxs');
        $originalControlSum                    = $this->getValue($DOMOriginalGroupInformation, 'OrgnlCtrlSum');
        $statusReasonInformationProprietary    = $this->getValue($DOMOriginalGroupInformation, 'StsRsnInf.Rsn.Prtry');
        //@todo Map the following fileds
        $detailedControlSum                    = '';
        $detailedNumberOfTransactionsPerStatus = '';
        $detailedStatus                        = '';

    	$this->originalGroupInformation = new OriginalGroupInformation();

        $this->originalGroupInformation->setOriginalMessageIdentification($originalMessageIdentification);
        $this->originalGroupInformation->setOriginalMessageNameIdentification($originalMessageNameIdentification);
        $this->originalGroupInformation->setOriginalNumberOfTransactions($originalNumberOfTransactions);
        $this->originalGroupInformation->setOriginalControlSum($originalControlSum);
        $this->originalGroupInformation->setStatusReasonInformationProprietary($statusReasonInformationProprietary);
        $this->originalGroupInformation->setDetailedControlSum($detailedControlSum);
        $this->originalGroupInformation->setDetailedNumberOfTransactionsPerStatus($detailedNumberOfTransactionsPerStatus);
        $this->originalGroupInformation->setDetailedStatus($detailedStatus);
    }

    /**<commit_msg>Completed the Original Group Information data mapping<commit_after><?php
/**
 * SEPA file parser.
 *
 * @copyright © Gemabit <www.gemabit.com> 2014
 * @license Apache License, Version 2.0
 *
 *  Copyright 2014 Gemabit
 * 
 * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

namespace Gemabit\Sepa\DomParser;

use Gemabit\Sepa\OriginalGroupInformation;
use Gemabit\Sepa\OriginalPaymentInformation;
use Gemabit\Sepa\TransactionInformation\DirectDebitTransactionInformation;
use Gemabit\Sepa\TransactionInformation\PaymentTypeInformation\DirectDebitPaymentTypeInformation;
//use Gemabit\Sepa\TransactionInformation;

/**
 * Used to parse the Dom-structure for the Direct Debit Return File
 *
 * Class DirectDebitReturnDomParser
 * @package Gemabit\Sepa
 * @subpackage Gemabit\Sepa\DomParser
 */
class DirectDebitReturnDomParser extends BaseDomParser
{
    /**
     * @var OriginalGroupInformation
     */
	protected $originalGroupInformation;

    /**
     * @var OriginalPaymentInformation
     */
	protected $originalPaymentInformation;

    /**
     * Parses Pain.002.001.03 format files
     * 
     * @param string $filepath
     */
	public function __construct($filepath) {
		parent::__construct($filepath);

        $originalGroupInformationElement = $this->doc->getElementsByTagName('OrgnlGrpInfAndSts')->item(0);
        $originalPaymentInformation      = $this->doc->getElementsByTagName('OrgnlPmtInfAndSts')->item(0);

        $this->fillOriginalGroupInformation($originalGroupInformationElement);
        $this->fillOriginalPaymentInformation($originalPaymentInformation);
    }

    /**
     * Fills up the OriginalGroupInformation with the given DOMElement
     */
    protected function fillOriginalGroupInformation(\DOMElement $DOMOriginalGroupInformation)
    {
        $originalMessageIdentification         = $this->getValue($DOMOriginalGroupInformation, 'OrgnlMsgId');
        $originalMessageNameIdentification     = $this->getValue($DOMOriginalGroupInformation, 'OrgnlMsgNmId');
        $originalNumberOfTransactions          = $this->getValue($DOMOriginalGroupInformation, 'OrgnlNbOfTxs');
        $originalControlSum                    = $this->getValue($DOMOriginalGroupInformation, 'OrgnlCtrlSum');
        $statusReasonInformationProprietary    = $this->getValue($DOMOriginalGroupInformation, 'StsRsnInf.Rsn.Prtry');
        
        $detailedNumberOfTransactionsPerStatus = $this->getValue($DOMOriginalGroupInformation, 'NbOfTxsPerSts.DtldNbOfTxs');
        $detailedStatus                        = $this->getValue($DOMOriginalGroupInformation, 'NbOfTxsPerSts.DtldSts');
        $detailedControlSum                    = $this->getValue($DOMOriginalGroupInformation, 'NbOfTxsPerSts.DtldCtrlSum');

    	$this->originalGroupInformation = new OriginalGroupInformation();

        $this->originalGroupInformation->setOriginalMessageIdentification($originalMessageIdentification);
        $this->originalGroupInformation->setOriginalMessageNameIdentification($originalMessageNameIdentification);
        $this->originalGroupInformation->setOriginalNumberOfTransactions($originalNumberOfTransactions);
        $this->originalGroupInformation->setOriginalControlSum($originalControlSum);
        $this->originalGroupInformation->setStatusReasonInformationProprietary($statusReasonInformationProprietary);
        $this->originalGroupInformation->setDetailedNumberOfTransactionsPerStatus($detailedNumberOfTransactionsPerStatus);
        $this->originalGroupInformation->setDetailedStatus($detailedStatus);
        $this->originalGroupInformation->setDetailedControlSum($detailedControlSum);
    }

    /**
{'fraction_non_alphanumeric': 0.0921976759034606, 'fraction_numerical': 0.005107904482186183, 'mean_word_length': 4.527170077628793, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 68, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4261404', 'n_tokens_mistral': 2027, 'n_tokens_neox': 1940, 'n_words': 393}