Announcement

Collapse
No announcement yet.

How to Sepa Bank

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to Sepa Bank

    Hello,

    it's a job, but you can adapt get sepa.xml for bank. (work on belgium with 2 different bank so i imagine with other!? )
    there are 2 think important : (sorry my english explain so )
    1) sepa is grouped => accounting see only total amount
    2) sepa is not grouped => accounting see all different amount for all different acount

    in the past i have used : \Sepa\CreditTransfer (github)
    now i use : \Digitick\Sepa. (github)

    here my sample : not grouped amount, so each transaction is individual in one xml

    PHP Code:
    <?php

    namespace Espo\Custom\Jobs;

    use 
    Espo\Core\Job\Job;
    use 
    Espo\Core\Job\Job\Data;
    use 
    Espo\Core\ORM\EntityManager;
    use 
    Espo\Core\Utils\Log;
    use 
    Espo\Core\ServiceFactory;

    use 
    \Sepa\CreditTransfer;
    use 
    \ZipArchive;
    use 
    \Digitick\Sepa\TransferFile\Factory\TransferFileFacadeFactory as TransferFileFacadeFactory;
    use 
    \Digitick\Sepa\PaymentInformation as PaymentInformation;
    use 
    \Digitick\Sepa\GroupHeader as GroupHeader;

    class 
    ConventionJobs implements Job
    {
        private 
    $em;
        private 
    $log;
        private 
    $serviceFactory;

        public function 
    __construct(EntityManager $entityManagerLog $logServiceFactory $serviceFactory)
        {
            
    $this->em $entityManager;
            
    $this->log $log;
            
    $this->serviceFactory $serviceFactory;
        }

        private function 
    createSEPA($conventionId) : void
        
    {  


            
    $convention $this->em->getEntity('Convention'$conventionId);

            
    $fileId "data/upload/" .$convention->get('file')->id;
            
    $integration $this->em->getEntity('Integration''XXXXX');
            
    $transferList $this->em->getRepository('Transfer')->where([
                [
                    
    'AND' => [
                    
    'status' => 'New',
                    
    'amount>' => 0,
                    
    'conventionId' => $conventionId
                    
    ]
                ]
            ])->
    find();


            
    $header = new GroupHeaderdate('Y-m-d-H-i-s'), 'XXX-' .$conventionId);
            
    $customerCredit TransferFileFacadeFactory::createCustomerCredit($convention->id'XXXXX''pain.001.001.03');


            
    $executionDate $convention->get('executionDate');

            
    $nbPayment 1;
            
    $i 1;
            
    $total 0.0;

            foreach(
    $transferList as $transfer){
                if (
    $transfer->get('status') == 'Closed') continue;

                
    $amount floatval(number_format($transfer->get('amount') ,2));
                
    $ibanNumber preg_replace'/[\W]/'''$transfer->get('ibanNumber'));
                
    $bic $transfer->get('bic');
                
    $name $transfer->get('name');

                
    $total += $amount;

                
    $customerCredit->addPaymentInfo$transfer->id .'-' .$i, [
                    
    'id'                      => $transfer->id .'-' .$i,
                    
    'debtorName'              => $integration->get('entreprise'),
                    
    'debtorAccountIBAN'       => $integration->get('ibanNumber'),
                    
    'debtorAgentBIC'          => $integration->get('bic'),
                    
    'batchBooking'            => false,
                    
    'dueDate'                 => new \DateTime$executionDate )
                ])->
    setBatchBooking(false);

                
    $customerCredit->addTransfer($transfer->id .'-' .$i, [
                    
    'amount'                  => $amount 100,
                    
    'creditorIban'            => $ibanNumber,
                    
    'creditorBic'             => $bic,
                    
    'creditorName'            => $name,
                    
    'remittanceInformation'   => 'XXX ' .$convention->get('name')
                ]);

                
    $transfer->set([
                    
    'status' => 'Closed',
                    
    'executionDate' => $executionDate,
                    
    'xmlNumber' => $convention->get('name') .'-' .$i,
                ]);
                
    $this->em->saveEntity($transfer);
                
    $nbPayment++;
                
    $i++;

            }

            
    $xml $customerCredit->asXML();

            
    $attachmentId $this->saveAttachment($xml,  'Sepa.xml'$conventionId'Convention' 'bank');
            
    $convention->set(['bankId' => $attachmentId]);
            
    $this->em->saveEntity($convention);

        }

    }
    Last edited by item; 11-23-2022, 05:54 PM.

  • #2
    Hello Item

    Thank You very much for sharing your working Model. I am novice in this field and like to ask you some base questions.
    1. What is the source for this script. Is this some custom Entity in Espocrm.
    2- What are steeps to follow up to get this script to work


    Can you pleas give some additional explanations what are fundation for this script (entities, job...)
    In my case I have two lines of data in EspoCRM (one for Receiver and other for Sender) table and I must transform it into sepa UPn payment Order - xml file and save it in custom folder. I do understand this script does work like I wish. I am also EU area so this script should be fine for me to

    Thanks&Regards

    Comment


    • #3
      Hello,
      my english is poor so i will try to explain ours situation :
      we need pay ours "nurses" (+-200) each month... so i have create a custom entity "Convention", each month = one Convention.
      all Payroll of the month is related to one Convention of the month. (of course)
      after that, in Convention i have a enum field and a sepa as file type..
      when user set enum field to ready in Convention Entity, job search all related Payroll to the convention .. and create sepa.xml and put in sepa field in convention.
      after that, user can download the sepa.xml (and we have a backup in Convention) and import to bank.

      you need to install \Digitick\Sepa library from github, see Emillod how to Video in this forum, he have make a video how make custom extention vendor library
      SEPA file generator in PHP. Contribute to php-sepa-xml/php-sepa-xml development by creating an account on GitHub.

      you have sample there

      PHP Code:
      <?php

      use \Digitick\Sepa\TransferFile\Factory\TransferFileFacadeFactory as TransferFileFacadeFactory;
      use 
      \Digitick\Sepa\PaymentInformation as PaymentInformation;
      use 
      \Digitick\Sepa\GroupHeader as GroupHeader;


              
      $header = new GroupHeaderdate('Y-m-d-H-i-s'), 'JAKOV-' .$conventionId);
              
      $customerCredit TransferFileFacadeFactory::createCustomerCredit($convention->id'JAKOB''pain.001.001.03');
      ​​$i 1;
      $customerCredit->addPaymentInfo$transfer->id .'-' .$i, [
                      
      'id'                      => $transfer->id .'-' .$i,
                      
      'debtorName'              => 'JAKOV',
                      
      'debtorAccountIBAN'       => 'JAKOV IBAN',
                      
      'debtorAgentBIC'          => 'JAKOV BIC',
                      
      'batchBooking'            => false,
                      
      'dueDate'                 => new \DateTime'PAYEMENT DATE' )
                  ])->
      setBatchBooking(false);

                  
      $customerCredit->addTransfer('oneUniqueIdSoYouCanCheckInFuturIfProblem' .'-' .$i, [
                      
      'amount'                  => $amount 100// need always 2 decimal in sepa, else bank not import
                      
      'creditorIban'            => $ibanNumber,  // iban who you pay
                      
      'creditorBic'             => $bic// bic who you pay, not required, can be blank i think,
                      
      'creditorName'            => $name// the name of the personne
                      
      'remittanceInformation'   => 'JAKOB ' .$convention->get('name')  // it's communication .. so as convention is the month for us, 202211 for sample
                  
      ]);
      $xml 
      $customerCredit->asXML();
      So with this sample, you have one sepa file with one amount for one person

      2- What are steeps to follow up to get this script to work ?

      all depand how you will work, you can put this script in a controller, custom button.. and get sepa.. i have choose to have always the file in crm, so if in futur problem.. i see to my boss -> look the file in crm !
      Last edited by item; 11-23-2022, 10:06 PM. Reason: githib link

      Comment


      • #4
        From reading this and understand our country banking system I try to give an alternative uses case below (example only).

        1) EspoCRM get add with the Employee Pay Hour and Work Hours.
        2) End of the Month, this code get use by CRON
        3) This code create a new file with all these data (Bank account details, how much is being paid and the employee name, etc)
        4) The Accountant (or the person doing payment), download this XML file.
        5) They log in their bank account (SEPA) and upload this XML file (the XML must follow the bank guidelines which I am assuming it does) to make mass payment.
        6) They check if they have enough money and click Submit. All Employee get paid.

        ---

        In our country we also support CSV so we don't need a complex XML file. And we don't have 200 employee to worry about either.

        Comment


        • #5
          Thank you item for a new custom code. I can understand all your Logic. I think your case is also usable for my purposes. In my Case I will also create custom entity Payment order with all field, that are needet in xml code. If I understand your code gets this date out from Entity "Convention". When user/workflow fill populate specific Status Enum Field, code for xml file generation is triggered an xml is saved in specific Folder. Then this file will be manualy imported to the Bank or bank Client automatisation will do it automaticali (this is payable service in our Country). I understand espocrm in his country is workflow a bit different. In our Countri (SI). There is push in all areas to go digital via .xml (eInvoice.xml and sepa payment orders.xml are the mainstream in this Field

          Comment


          • espcrm
            espcrm commented
            Editing a comment
            Maybe you can adopt to your system and share your version.

            Also, you pinged wrong person. espocrm is the official (dead) account. I'm just another user like you.

        • #6
          Hello

          Sorry for late response... In order to create any kind of XML files Digitick\Sepa. library have to be installed. I have now installed composer (on linux apt-get install composer) and then create composer.json file (run composer init in linux distro). Take care not to be root. My project is to create SEPA xml Bank payment order and save them in target folder. I create Entity payment Order with Fields that are needed for Payment order, Like item suggest I have created additional Field status (enum field with This list: Prepare, Pay Now, Pay Later), Custom Field Dates for scheduled Dates, XML Payment Order Field as file Type type (document folder for created XML files) and Payment Approval Form as file Type type (document folder for auto created pdf payment Approval Forms).
          Based on purpose of this entity I need solution, that will be trigered many time per day. It seams workflow would be more convinient, but I am not sure if php scrips can be easy trigered via workflow. Like to ask item and espocrm where to save this php file and how to create job that can be executed with enum field status

          workflow. variants One for instance payment and other for scheduled
          Worflow1 Target Entity=Payment Orders, Trigger Type=Scheduled, Conditions (status=PayNow),Action
          Worflow2 Target Entity=Payment Orders, Trigger Type=Scheduled, Conditions (status=PayLater),Action

          Thank you for your help

          I wish all forum member a blessing New Year

          Comment

          Working...
          X