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
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 $entityManager, Log $log, ServiceFactory $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 GroupHeader( date('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);
}
}
Comment