<commit_before><?php

namespace AppBundle\Tool;

use Digitick\Sepa\DomBuilder\DomBuilderFactory;
use Digitick\Sepa\GroupHeader;
use Digitick\Sepa\TransferFile\CustomerCreditTransferFile;
use Digitick\Sepa\TransferInformation\CustomerCreditTransferInformation;
use Digitick\Sepa\PaymentInformation;
use Digitick\Sepa\DomBuilder\CustomerCreditTransferDomBuilder;
use Digitick\Sepa\TransferFile\Factory\TransferFileFacadeFactory;


class PrelevementXml {

protected $banqueParameters;
protected $creditorId;
protected $creditorName;
protected $creditorAccountIBAN;
protected $creditorAgentBIC;

protected $factures;
protected $directDebit;
protected $xml;

    public function __construct($factures,$banqueParameters)
    {
        $this->factures = $factures;
        $this->banqueParameters = $banqueParameters;
        $this->creditorId = $banqueParameters['creditorId'];
        $this->creditorName = $banqueParameters['creditorName'];
        $this->creditorAccountIBAN = $banqueParameters['creditorAccountIBAN'];
        $this->creditorAgentBIC = $banqueParameters['creditorAgentBIC'];

    }

    public function createPrelevement(){
        $header = new GroupHeader(date('Y-m-d-H-i-s'), 'Aurouze');
        $header->setInitiatingPartyId($this->creditorAccountIBAN);

        $this->directDebit = TransferFileFacadeFactory::createDirectDebitWithGroupHeader($header, 'pain.008.001.02');

        $date = new \DateTime('now');
        $this->addTransferts($date);

        $this->xml = $this->directDebit->asXML();
        $nameXml = 'prelevements_'.$date->format("Ymd-His");
        file_put_contents(realpath('..').'/data/'.$nameXml.'.xml',$this->xml);
        return $nameXml;

    }

    public function getXml(){
        return $this->xml;
    }


    public function addTransferts($date){
        foreach ($this->factures as $key => $facture) {
            $idPrelevement = $this->createPrelevementId($facture,$date);
            $isFirst = $facture->getSociete()->isFirstPrelevement();
            $seqType = ($isFirst)? PaymentInformation::S_FIRST : PaymentInformation::S_RECURRING;

            $dateEmission = clone $facture->getDateEmission();
            if($dateEmission->format('m') > 20){
                $dateEmission->modify("+2 month");
            }else{
                $dateEmission->modify("+1 month");
            }
            $dueDate = \DateTime::createFromFormat("Ymd",$dateEmission->format("Y").$dateEmission->format("m")."20");
            $now = new \DateTime();
            if($dueDate < $now){
                if($now->format('m') > 20){
                    $now->modify("+1 month");
                }
                $dueDate = \DateTime::createFromFormat("Ymd",$now->format("Y").$now->format("m")."20");
            }
            
            $facture->setInPrelevement($dueDate);
            $this->directDebit->addPaymentInfo($idPrelevement, array(
                'id'                    => $idPrelevement,
                'dueDate'               => $dueDate,
                'creditorName'          => $this->creditorName,
                'creditorAccountIBAN'   => $this->creditorAccountIBAN,
                'creditorAgentBIC'      => $this->creditorAgentBIC,
                'seqType'               => $seqType,
                'creditorId'            => $this->creditorId,
                'localInstrumentCode'   => 'CORE'
            ));

            $this->directDebit->addTransfer($idPrelevement, array(
                'amount'                => ''.intval($facture->getMontantAPayer()*100),
                'debtorIban'            => str_ireplace(" ","",$facture->getSepa()->getIban()),
                'debtorBic'             => str_ireplace(" ","",$facture->getSepa()->getBic()),
                'debtorName'            => $facture->getSepa()->getNomBancaire(),
                'debtorMandate'         => str_ireplace(" ","",$facture->getSepa()->getRum()),
                'debtorMandateSignDate' => $facture->getSepa()->getDate(),
                'remittanceInformation' => 'FACT '.$facture->getNumeroFacture().' du '.$facture->getDateEmission()->format("d m Y").' '. str_ireplace(array(".",","),"EUR",sprintf("%0.2f",$facture->getMontantAPayer())),
                'endToEndId'            => 'Aurouze Facture'
            ));
        }
    }

    public function createPrelevementId($facture, $date){
        return 'prelevement_aurouze_'.$facture->getNumeroFacture().'_'.$date->format('Ymd-His');
    }


}<commit_msg>restriction longueur des Id bancaire<commit_after><?php

namespace AppBundle\Tool;

use Digitick\Sepa\DomBuilder\DomBuilderFactory;
use Digitick\Sepa\GroupHeader;
use Digitick\Sepa\TransferFile\CustomerCreditTransferFile;
use Digitick\Sepa\TransferInformation\CustomerCreditTransferInformation;
use Digitick\Sepa\PaymentInformation;
use Digitick\Sepa\DomBuilder\CustomerCreditTransferDomBuilder;
use Digitick\Sepa\TransferFile\Factory\TransferFileFacadeFactory;


class PrelevementXml {

protected $banqueParameters;
protected $creditorId;
protected $creditorName;
protected $creditorAccountIBAN;
protected $creditorAgentBIC;

protected $factures;
protected $directDebit;
protected $xml;

    public function __construct($factures,$banqueParameters)
    {
        $this->factures = $factures;
        $this->banqueParameters = $banqueParameters;
        $this->creditorId = $banqueParameters['creditorId'];
        $this->creditorName = $banqueParameters['creditorName'];
        $this->creditorAccountIBAN = $banqueParameters['creditorAccountIBAN'];
        $this->creditorAgentBIC = $banqueParameters['creditorAgentBIC'];

    }

    public function createPrelevement(){
        $header = new GroupHeader(date('Y-m-d-H-i-s'), 'Aurouze');
        $header->setInitiatingPartyId($this->creditorAccountIBAN);

        $this->directDebit = TransferFileFacadeFactory::createDirectDebitWithGroupHeader($header, 'pain.008.001.02');

        $date = new \DateTime('now');
        $this->addTransferts($date);

        $this->xml = $this->directDebit->asXML();
        $nameXml = 'prelevements_'.$date->format("Ymd-His");
        file_put_contents(realpath('..').'/data/'.$nameXml.'.xml',$this->xml);
        return $nameXml;

    }

    public function getXml(){
        return $this->xml;
    }


    public function addTransferts($date){
        foreach ($this->factures as $key => $facture) {
            $idPrelevement = $this->createPrelevementId($facture,$date);
            $isFirst = $facture->getSociete()->isFirstPrelevement();
            $seqType = ($isFirst)? PaymentInformation::S_FIRST : PaymentInformation::S_RECURRING;

            $dateEmission = clone $facture->getDateEmission();
            if($dateEmission->format('m') > 20){
                $dateEmission->modify("+2 month");
            }else{
                $dateEmission->modify("+1 month");
            }
            $dueDate = \DateTime::createFromFormat("Ymd",$dateEmission->format("Y").$dateEmission->format("m")."20");
            $now = new \DateTime();
            if($dueDate < $now){
                if($now->format('m') > 20){
                    $now->modify("+1 month");
                }
                $dueDate = \DateTime::createFromFormat("Ymd",$now->format("Y").$now->format("m")."20");
            }

            $facture->setInPrelevement($dueDate);
            $this->directDebit->addPaymentInfo($idPrelevement, array(
                'id'                    => $idPrelevement,
                'dueDate'               => $dueDate,
                'creditorName'          => $this->creditorName,
                'creditorAccountIBAN'   => $this->creditorAccountIBAN,
                'creditorAgentBIC'      => $this->creditorAgentBIC,
                'seqType'               => $seqType,
                'creditorId'            => $this->creditorId,
                'localInstrumentCode'   => 'CORE'
            ));

            $this->directDebit->addTransfer($idPrelevement, array(
                'amount'                => ''.intval($facture->getMontantAPayer()*100),
                'debtorIban'            => str_ireplace(" ","",$facture->getSepa()->getIban()),
                'debtorBic'             => str_ireplace(" ","",$facture->getSepa()->getBic()),
                'debtorName'            => $facture->getSepa()->getNomBancaire(),
                'debtorMandate'         => str_ireplace(" ","",$facture->getSepa()->getRum()),
                'debtorMandateSignDate' => $facture->getSepa()->getDate(),
                'remittanceInformation' => 'FACT '.$facture->getNumeroFacture().' du '.$facture->getDateEmission()->format("d m Y").' '. str_ireplace(array(".",","),"EUR",sprintf("%0.2f",$facture->getMontantAPayer())),
                'endToEndId'            => 'Aurouze Facture'
            ));
        }
    }

    public function createPrelevementId($facture, $date){
        return $facture->getNumeroFacture().'_'.$date->format('Ymd-His');
    }


}
{'fraction_non_alphanumeric': 0.15752351097178682, 'fraction_numerical': 0.005373936408419167, 'mean_word_length': 2.5561305732484074, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 153, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 10}, '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': '1075842', 'n_tokens_mistral': 2773, 'n_tokens_neox': 2633, 'n_words': 342}