<?php
namespace App\Controller;
use App\Entity\Address;
use App\Entity\Billing;
use App\Entity\BillingItem;
use App\Entity\Client;
use App\Entity\Company;
use App\Entity\Intervenant;
use App\Entity\Parameter;
use App\Entity\Product;
use App\Entity\RDV;
use App\Entity\RDVBilling;
use App\Entity\RDVProduct;
use App\Entity\Reglement;
use App\Entity\Salon;
use App\Entity\Session;
use App\Entity\Site;
use App\Entity\User;
use App\Form\Billing\ContencieuxType;
use App\Form\Billing\EasyCollect;
use App\Form\Billing\LotType;
use App\Form\Billing\RelanceType;
use App\Form\Billing\SendType;
use App\Form\Billing\ValidateType;
use App\Form\BillingType;
use App\Form\CompanyType;
use App\Form\Billing\GenerateType;
use App\Form\RDVType;
use App\Form\ReplanningType;
use App\Manager\BillingItemManager;
use App\Manager\BillingManager;
use App\Manager\RDVBillingManager;
use App\Manager\ReglementManager;
use App\Repository\BillingItemsRepository;
use App\Repository\BillingRepository;
use App\Repository\ClientRepository;
use App\Repository\CompanyRepository;
use App\Repository\ProductRepository;
use App\Repository\RDVProductRepository;
use App\Repository\RDVRepository;
use App\Repository\SiteRepository;
use App\Service\FileUploader;
use App\Service\MailService;
use App\Service\PaytweakService;
use App\Service\SepaService;
use App\Traits\MailServiceTrait;
use App\Traits\ManagerTrait;
use App\Traits\PdfServiceTrait;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\ManagerRegistry;
use Knp\Bundle\SnappyBundle\Snappy\Response\PdfResponse;
use Knp\Snappy\Pdf;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\StreamedResponse;
use Symfony\Component\Routing\Annotation\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
use Symfony\Component\Serializer\Serializer;
use Symfony\Component\Serializer\SerializerInterface;
use Digitick\Sepa\TransferFile\Factory\TransferFileFacadeFactory;
use Digitick\Sepa\PaymentInformation;
/**
* @Route("/facturation")
*/
class BillingController extends AbstractController
{
private $billingItemManager;
/** @var BillingManager $billingManager */
private $billingManager;
use ManagerTrait;
use MailServiceTrait;
use PdfServiceTrait;
/**
* BillingController constructor.
* @param BillingItemManager $billingItemManager
*/
public function __construct(BillingManager $billingManager, BillingItemManager $billingItemManager)
{
$this->billingItemManager = $billingItemManager;
$this->billingManager = $billingManager;
}
/**
* @Route("/testSepa", methods={"GET","POST"})
*/
public function testSepa(
Request $request,
BillingRepository $billingRepository,
SepaService $sepaService,
CompanyRepository $companyRepository
): Response
{
$entityManager = $this->getDoctrine()->getManager();
$billings = $billingRepository->findBy([],null,20);
$company = $companyRepository->find(1);
$directDebit = $sepaService->generate($company);
foreach($billings as $billing){
$directDebit = $sepaService->addTransaction($directDebit, $billing);
}
//dd(count($billings));
return new Response($directDebit->asXML(), Response::HTTP_OK, [
'Content-Type' => 'application/octect-stream',
'Content-Transfer-Encoding' => 'Binary',
'Content-disposition' => 'attachment; filename="sepa.xml"'
]);
}
/**
* @Route("/billing/rendrecontencieux", name="app_billing_rendrecontencieux", methods={"POST"})
*/
public function rendreContencieux(Request $request, BillingRepository $billingRepository, EntityManagerInterface $entityManager): JsonResponse
{
// Get the 'ids' from the AJAX request
$selectedIds = $request->request->get('ids', []);
if (!empty($selectedIds)) {
foreach ($selectedIds as $id) {
$billing = $billingRepository->find($id);
if ($billing) {
$billing->setStatus('contentieux');
$entityManager->persist($billing);
}
}
$entityManager->flush();
// Return a JSON response indicating success
return new JsonResponse(['message' => 'Factures marquées comme contentieuses avec succès.'], 200);
} else {
// Return a JSON response indicating an error
return new JsonResponse(['message' => 'Aucune facture sélectionnée.'], 400);
}
}
/**
* @Route("/liste", methods={"GET","POST"})
* @Template()
* @return array|RedirectResponse
*/
public function index(
Request $request,
CompanyRepository $companyRepository,
SiteRepository $siteRepository,
BillingRepository $billingRepository,
MailService $mailService,
PaytweakService $paytweakService,
SepaService $sepaService,
Pdf $knpSnappyPdf,
ReglementManager $reglementManager,
ManagerRegistry $em,
ParameterBagInterface $parameterBag
)
{
$sites = $siteRepository->findAll();
$compagnies = $companyRepository->findAll();
$form = $this->createForm(GenerateType::class);
$validateForm = $this->createForm(ValidateType::class);
$sendForm = $this->createForm(SendType::class);
$relanceForm = $this->createForm(RelanceType::class);
$lotForm = $this->createForm(LotType::class);
$easyCollect = $this->createForm(EasyCollect::class);
$billingsSEPA = [];
$company = null;
$filterForm = $this->createForm(\App\Form\Billing\FilterType::class, null, ['company' => $companyRepository->find(2)]);
$form->handleRequest($request);
$filterForm->handleRequest($request);
$sendForm->handleRequest($request);
$validateForm->handleRequest($request);
$relanceForm->handleRequest($request);
$easyCollect->handleRequest($request);
$lotForm->handleRequest($request);
// FILTER FORM
if ($filterForm->isSubmitted() && $filterForm->isValid()) {
$site = $filterForm['site']->getData();
$statusSite = $filterForm['statusSite']->getData();
$company = $filterForm['company']->getData();
$numFacture = $filterForm['numFacture']->getData();
$client = $filterForm['client']->getData();
$dateDebut = $filterForm['dateDebut']->getData();
$dateFin = $filterForm['dateFin']->getData();
$status = $filterForm['status']->getData();
$billings = $billingRepository->filter($site, $client, $dateDebut,$dateFin, $status, $company, $numFacture, false, null, $statusSite);
$billingsSEPA = $billingRepository->findBy(['company' => $company]);
$billingsEncaissement = $billingRepository->searchForEncaissement($site, $client, $dateDebut,$dateFin, $company, $numFacture);
}
else {
$billings = $billingRepository->findBy([],['code' => 'DESC'],200);
$billingsEncaissement = $billingRepository->searchForEncaissement();
}
// VALIDATE
if ($validateForm->isSubmitted() ) {
$site = $validateForm['site']->getData();
$company = $validateForm['company']->getData();
$start = $validateForm['start']->getData();
$end = $validateForm['end']->getData();
$dateBillingStr = $validateForm['dateBilling']->getData();
$dateBilling = null;
if($dateBillingStr){
$dateBilling = date_create_from_format('Y-m-d', $dateBillingStr);
}
$billings = $billingRepository->searchForValidate($site, $company, $start, $end);
/** @var Billing $billing */
$i = 0;
$lastCode = null;
foreach($billings as $billing) {
if($i === 0){
$code = $this->billingManager->getCodeBilling($company, $billing, $dateBilling);
}
else {
$code = $this->billingManager->getCodeBillingByLastCode($company, $billing, $lastCode, $dateBilling);
}
$billing->setCode($code);
$billing->setStatus(Billing::STATUS_VALIDE);
if($billing->getHt() <= 0 || $billing->getSolde() < 0){
$billing->setStatus(Billing::STATUS_REGLEE);
}
$em->getManager()->persist($billing);
$lastCode = $code;
$i++;
}
$em->getManager()->flush();
return $this->redirectToRoute('app_billing_index');
}
// HANDLE encaissement
if($request->isMethod(Request::METHOD_POST) && $request->request->get('payment-method')) {
$paymentMethod = $request->request->get('payment-method');
$reference = $request->request->get('reference');
$companyKey = $request->request->get('company');
$date = $request->request->get('date');
$encaissementDate = $request->request->get('date');
$client = $request->request->get('client');
$encaissements = $request->request->get('encaissement');
if($encaissementDate) {
$encaissementDate = date_create_from_format('Y-m-d', $encaissementDate);
}
else {
$encaissementDate = new \DateTime();
}
if(!$date) {
$date = new \DateTime('now');
} else {
$dateObj = date_create_from_format('d-m-Y', $date);
$date = ($dateObj !== false) ? $dateObj : new \DateTime('now');
}
$company = null;
if($companyKey) {
$company = $companyRepository->find($companyKey);
}
// SEPA
if(( $paymentMethod === Reglement::MODE_SEPA && $company)) {
$directDebit = $sepaService->generate($company);
if(!$encaissements){
$this->addFlash('error','Pas d\'encaissements selectionés');
}
if($encaissements){
// generare onereglement per billing
foreach($encaissements as $key => $solde) {
if(!$solde || $solde == 0) {
continue;
}
$billing = $billingRepository->findOneBy(['id'=> $key]);
$clientBilling = $billing->getClient();
$oldSolde = $billing->getSolde();
$newSolde = $oldSolde - $solde;
$billing->setSolde(number_format($newSolde, 2));
if($newSolde <= 0){
$billing->setStatus(Billing::STATUS_REGLEE);
}
$reglementManager->create($date, $billing, $billing->getTtc(),$reference, $clientBilling, $paymentMethod);
$em->getManager()->persist($billing);
$directDebit = $sepaService->addTransaction($directDebit, $billing);
}
$em->getManager()->flush();
try {
$xml = $directDebit->asXML();
return new Response($xml, Response::HTTP_OK, [
'Content-Type' => 'application/octect-stream',
'Content-Transfer-Encoding' => 'Binary',
'Content-disposition' => 'attachment; filename="sepa.xml"'
]);
} catch (\Exception $exception){
$this->addFlash('error', 'Manquement des informations bancaires, ICS, IBAN...');
}
}
}
// OTHERS PAYMENT METHODS
if($company) {
$billings = [];
$sumSolde = 0;
// generare one reglement per billing
foreach($encaissements as $key => $encaissement) {
//if it's checked
if(!isset($encaissement['value'])){
continue;
}
$solde = $encaissement['solde'];
if(!$solde || $solde == 0) {
continue;
}
$billing = $billingRepository->findOneBy(['id'=> $key]);
$oldSolde = $billing->getSolde();
$newSolde = $oldSolde - $solde;
$billing->setSolde($newSolde);
if($newSolde <= 0){
$billing->setStatus(Billing::STATUS_REGLEE);
}
$clientBilling = $billing->getClient();
$em->getManager()->persist($billing);
$isDuplicate = false;
foreach ($billings as $existingBilling) {
if ($existingBilling->getId() === $billing->getId()) {
$isDuplicate = true;
break;
}
}
if (!$isDuplicate) {
$billings[] = $billing;
}
$sumSolde+= $solde;
}
$reglementManager->createByBillings($encaissementDate, $billings, $sumSolde, $reference, $billings[0]->getClient(), $paymentMethod , $company);
}
$em->getManager()->flush();
}
// facture
if ($form->isSubmitted() && $form->isValid()) {
$this->generateBilling($form->getData());
return $this->redirectToRoute('app_billing_index');
}
/***********
* SEND FORM
************/
if($sendForm->isSubmitted() && $sendForm->isValid()){
$pdfBillings = [];
$modeEnvoi = $sendForm->getData()['modeEnvoi'];
$start = $sendForm->getData()['start'];
$end = $sendForm->getData()['end'];
$company = $sendForm->getData()['company'];
$site = $sendForm->getData()['site'];
// $start = \DateTime::createFromFormat('Y-m-d',$start)->format('Y-m-d');
// $end = \DateTime::createFromFormat('d-m-Y', $end)->format('Y-m-d');
$billings = $billingRepository->searchForSend($site, $company, $start, $end);
//dd($billings);
/** @var Billing $billing */
foreach($billings as $billing) {
/** @var Client $client */
$client = $billing->getClient();
$payMode = $client->getBillingInfos()->getPayMode();
$sendMode = $client->getBillingInfos()->getSendMode();
// mail + SEPA
if($modeEnvoi === 'mail' && $sendMode === Client\BillingInfos::SEND_MODE_EMAIL &&
($payMode == Client\BillingInfos::PAY_MODE_SEPA) ) {
if($billing->getClient()->getBillingInfos()->getEmail()){
$html = $this->renderView('billing/pdf.html.twig',[
'billings' => [$billing],
'company' => $billing->getCompany()
]);
$knpSnappyPdf->setOption('enable-local-file-access', true);
$pdf= $knpSnappyPdf->getOutputFromHtml($html, ['encoding' => 'utf-8']);
if($billing->getClient()->getBillingInfos()->getEmail()){
try {
$mailService->sent(new \Symfony\Component\Mime\Address( 'comptabilite@silverbeaute.com', 'Comptabilité Silver Beauté'), $billing->getClient()->getBillingInfos()->getEmail(), $company,$pdf, $billing );
$billing->setStatus(Billing::STATUS_SENT);
$billing->setSendingDate(new \DateTime());
$em->getManager()->persist($billing);
}
catch (\Exception $exception){
}
}
}
}
elseif($modeEnvoi === 'courrier' && $sendMode === Client\BillingInfos::SEND_MODE_COURRIER ){
$pdfBillings[] = $billing;
$billing->setStatus(Billing::STATUS_SENT);
$billing->setSendingDate(new \DateTime());
$em->getManager()->persist($billing);
}
elseif (
$modeEnvoi === 'mail' &&
$billing->getSolde() > 0 && (
(
$sendMode === Client\BillingInfos::SEND_MODE_EMAIL &&
($payMode == Client\BillingInfos::PAY_MODE_CB
|| $payMode == Client\BillingInfos::PAY_MODE_CHEQUES
|| $payMode == Client\BillingInfos::PAY_MODE_VIREMENT)
)
||
($sendMode === Client\BillingInfos::SEND_MODE_COURRIER && $payMode == Client\BillingInfos::PAY_MODE_CB )
|| ( $sendMode === Client\BillingInfos::SEND_MODE_EMAIL && $payMode === null)
)
)
{
$invoice = $paytweakService->createInvoiceFromClient($client, $billing);
$call = $paytweakService->createBilling($invoice, $company);
if($call['code'] == 'OK') {
$billing->setStatus(Billing::STATUS_SENT);
if(isset($call['link_id'] )){
$billing->setLinkPaytweak($call['link_id']);
}
$billing->setSendingDate(new \DateTime());
$em->getManager()->persist($billing);
}
else {
$mailService->sentErrorPaytweak($billing, $call['code'], $call['message']);
}
}
}
$em->getManager()->flush();
if(count($pdfBillings) > 0){
$html = $this->renderView('billing/pdf.html.twig',[
'billings' => $pdfBillings,
'company' => $billing->getCompany()
]);
$knpSnappyPdf->setOption('enable-local-file-access', true);
return new PdfResponse(
$knpSnappyPdf->getOutputFromHtml($html, ['encoding' => 'utf-8']),
'file.pdf'
);
}
$em->getManager()->flush();
}
/***********
* SEND FORM
************/
if($easyCollect->isSubmitted() && $easyCollect->isValid()){
$modeEnvoi = $easyCollect->getData()['modeEnvoi'];
$start = $easyCollect->getData()['start'];
$end = $easyCollect->getData()['end'];
$company = $easyCollect->getData()['company'];
$site = $easyCollect->getData()['site'];
// $start = \DateTime::createFromFormat('Y-m-d',$start)->format('Y-m-d');
// $end = \DateTime::createFromFormat('d-m-Y', $end)->format('Y-m-d');
$billings = $billingRepository->searchForSend($site, $company, $start, $end);
//dd($billings);
/** @var Billing $billing */
foreach($billings as $billing) {
/** @var Client $client */
$client = $billing->getClient();
$payMode = $client->getBillingInfos()->getPayMode();
$sendMode = $client->getBillingInfos()->getSendMode();
$hasSigned = !!$client->isHasSignedEasyCollect();
if (
$modeEnvoi === 'mail' &&
$billing->getSolde() > 0 && $sendMode === Client\BillingInfos::SEND_MODE_EMAIL
&& !$hasSigned
)
{
$amount = $billing->getSolde();
// PDF
$invoice = $paytweakService->createInvoiceFromClient($client, $billing);
//$call = $paytweakService->createBilling($invoice, $company);
//if($call['code'] == 'OK') {
if(!$client->isHasSignedEasyCollect()) {
$paytweakService->createLinkScenario($billing->getCompany(),null, 'BhaXARK', $amount,
$client->getBillingInfos() ? $client->getBillingInfos()->getEmail() : $client->getEmail(),
$client->getFirstname(),
$client->getLastname(),
$client->getGender(),
$billing->getCode(),
null,
'B7EV3PN'
);
$billing->setStatus(Billing::STATUS_SENT);
$billing->setSendingDate(new \DateTime());
$em->getManager()->persist($billing);
}
else {
// email
// TODO: rappel endpoint email
$paytweakService->createLinkScenario($billing->getCompany(),null, 'BhaXARK', $amount,
$client->getBillingInfos() ? $client->getBillingInfos()->getEmail() : $client->getEmail(),
$client->getFirstname(),
$client->getLastname(),
$client->getGender(),
$billing->getCode(),
$client->getBillingInfos() ? $client->getBillingInfos()->getRum() : null,
'HURNEAN'
);
$billing->setStatus(Billing::STATUS_SENT);
$billing->setSendingDate(new \DateTime());
$em->getManager()->persist($billing);
}
}
}
$em->getManager()->flush();
}
/***********
* RELANCE FORM
************/
if($relanceForm->isSubmitted() && $relanceForm->isValid()){
$start = $relanceForm->getData()['start'];
$end = $relanceForm->getData()['end'];
$company = $relanceForm->getData()['company'];
$site = $relanceForm->getData()['site'];
$modeEnvoi = $relanceForm->getData()['modeEnvoi'];
$pdfBillings = [];
$billings = $billingRepository->searchForRelance($site, $company, $start, $end);
foreach($billings as $billing) {
/** @var Client $client */
$client = $billing->getClient();
$payMode = $client->getBillingInfos()->getPayMode();
$sendMode = $client->getBillingInfos()->getSendMode();
if (
$modeEnvoi === 'mail' &&
$billing->getSolde() > 0 && (
(
$sendMode === Client\BillingInfos::SEND_MODE_EMAIL &&
($payMode == Client\BillingInfos::PAY_MODE_CB
|| $payMode == Client\BillingInfos::PAY_MODE_CHEQUES
|| $payMode == Client\BillingInfos::PAY_MODE_VIREMENT)
)
||
($sendMode === Client\BillingInfos::SEND_MODE_COURRIER &&
($payMode == Client\BillingInfos::PAY_MODE_CB
|| $payMode == Client\BillingInfos::PAY_MODE_CHEQUES
|| $payMode == null
|| $payMode == Client\BillingInfos::PAY_MODE_VIREMENT) )
|| ( $sendMode === Client\BillingInfos::SEND_MODE_EMAIL && $payMode === null)
)
)
{
$email = $billing->getClient()->getBillingInfos() ? $billing->getClient()->getBillingInfos()->getEmail(): null;
if($email){
$senderAdress = new \Symfony\Component\Mime\Address( 'comptabilite@silverbeaute.com', 'Comptabilité Silver Beauté');
$html = $this->renderView('billing/pdf.html.twig',[
'billings' => [$billing],
'company' => $billing->getCompany()
]);
$this->pdfService->setTimeout(120);
$this->pdfService->setOption('enable-local-file-access', true);
$pdf = $this->pdfService->getOutputFromHtml($html);
//$call = $paytweakService->reSend($company, $billing->getCode(), $email);
$res = $paytweakService->getLink($company, $billing->getCode());
if($res['code'] === PaytweakService::CODE_OK) {
$link = reset($res);
if($link["paid"] == "1"){
continue;
}
try {
$this->mailService->sentRelance($senderAdress,$email, $company, $pdf, $billing, $link["link_url"]);
}
catch (\Exception $exception){
}
}
elseif($res['code'] === PaytweakService::CODE_NOT_FOUND){
$invoice = $paytweakService->createInvoiceFromClient($client, $billing);
$call = $paytweakService->createBilling($invoice, $company);
if($call['code'] == 'OK') {
$billing->setStatus(Billing::STATUS_SENT);
$billing->setSendingDate(new \DateTime());
$em->getManager()->persist($billing);
}
else {
$mailService->sentErrorPaytweak($billing, $call['code'], $call['message']);
}
}
else {
//$mailService->sentErrorPaytweak($billing, $call['code'], $call['message']);
}
}
}
elseif($modeEnvoi === 'courrier' && $sendMode === Client\BillingInfos::SEND_MODE_COURRIER ){
$pdfBillings[] = $billing;
$billing->setStatus(Billing::STATUS_SENT);
$billing->setSendingDate(new \DateTime());
$em->getManager()->persist($billing);
}
}
$em->getManager()->flush();
if(count($pdfBillings) > 0){
$html = $this->renderView('billing/pdf.html.twig',[
'billings' => $pdfBillings,
'company' => $billing->getCompany()
]);
$knpSnappyPdf->setOption('enable-local-file-access', true);
return new PdfResponse(
$knpSnappyPdf->getOutputFromHtml($html, ['encoding' => 'utf-8']),
'file.pdf'
);
}
}
/***********
* LOT FORM
************/
if($lotForm->isSubmitted() && $lotForm->isValid()) {
$start = $lotForm->getData()['start'];
$company = $lotForm->getData()['company'];
$end = $lotForm->getData()['end'];
$site = $lotForm->getData()['site'];
$modeEnvoi = $lotForm->getData()['modeEnvoi'];
$status = $lotForm->getData()['status'];
$clientFilter = $lotForm->getData()['client'];
$pdfBillings = [];
$billings = $billingRepository->searchForLot($site, $company, $start, $end, $status, $modeEnvoi, $clientFilter);
foreach($billings as $billing) {
/** @var Client $client */
$client = $billing->getClient();
$pdfBillings[] = $billing;
}
$em->getManager()->flush();
if(count($pdfBillings) > 0){
$html = $this->renderView('billing/pdf.html.twig',[
'billings' => $pdfBillings,
'company' => $billing->getCompany()
]);
$knpSnappyPdf->setOption('enable-local-file-access', true);
$knpSnappyPdf->setTimeout(600);
return new PdfResponse(
$knpSnappyPdf->getOutputFromHtml($html, ['encoding' => 'utf-8']),
'file.pdf'
);
}
}
return [
'billings' => $billings,
'billingsEncaissement' => $billingsEncaissement,
'billingsSEPA' => $billingsSEPA,
'compagnies' => $compagnies,
'company' => $company,
'sites' => $sites,
'generateForm' => $form->createView(),
'formFilter' => $filterForm->createView(),
'validateForm' => $validateForm->createView(),
'easycollect' => $easyCollect->createView(),
'sendForm' => $sendForm->createView(),
'lotForm' => $lotForm->createView(),
'relanceForm' => $relanceForm->createView()
];
}
/**
* @Route("/new/rdv/{id}", name="billing_new_rdv", methods={"GET","POST"})
*/
public function new(
RDV $RDV,
Request $request,
BillingRepository $billingRepository,
BillingItemManager $billingItemManager,
RDVBillingManager $RDVBillingManager,
CsrfTokenManagerInterface $csrfTokenManager,
PaytweakService $paytweakService,
MailService $mailService
): Response
{
if($RDV->getStatus() === RDV::STATUS_FACTURER){
return $this->redirectToRoute('app_planning_coiffeurliste');
}
$entityManager = $this->getDoctrine()->getManager();
/** @var Parameter $setting */
$setting = $this->getDoctrine()->getRepository(Parameter::class)->find(1);
$tva = $setting->getTva();
$billing = new Billing();
$codePromo = $RDV->getCodePromo();
$promoPercentage = 0;
if ($codePromo) {
// Assuming a method exists to retrieve the percentage associated with the promo code
$promoPercentage = $codePromo->getPurcent(); // e.g., returns 10 for 10%
}
$billing->setDateBilling(new \DateTime());
$total = 0;
$total_ht = 0;
/** @var RDVProduct $rdvProduct */
foreach($RDV->getRdvProducts() as $rdvProduct){
$product = $rdvProduct->getProduct();
$billingItem = $billingItemManager->create($product, $billing, 1, $tva);
// date du jour du rdv pour facturer immadialite
$billingItem->setDateRDV($RDV->getStart());
$gridPrice = null;
$salon = $RDV->getSalon();
if($salon) {
$gridPrice = $RDV->getSalon()->getGridPrice();
}
$price = null;
if($gridPrice) {
switch ($gridPrice->getId()) {
case 1:
$price = $product->getPriceHtA();
break;
case 2:
$price = $product->getPriceHtB();
break;
case 3:
$price = $product->getPriceHtC();
break;
case 4:
$price = $product->getPriceHtD();
break;
}
}
else {
$price = $product->getPriceHtA();
}
$billingItem->setPrice($price);
// protect
$remise = $RDV->getClient()->getBillingInfos()->getDiscount();
if($product->getRemiseGenerale() > $remise ){
$remise = $product->getRemiseGenerale();
}
if($remise){
$billingItem->setDiscount(floatval($remise));
}
if ($promoPercentage) {
$price *= (1 - $promoPercentage / 100);
$billingItem->setDiscount($promoPercentage);
}
$remisePurcent = $remise ? (1 - $remise / 100) : 0;
if($remisePurcent != 0){
$price = $price * $remisePurcent;
}
$calcultHt = number_format((float)$price, 2);
if($tva <= 0) {
$tva = 20;
}
$ttc = (float) number_format($price * (1 + $tva / 100),2);
$billingItem->setRefProduct($product->getReference());
$billingItem->setTtc($ttc);
$billing->getBillingItems()->add($billingItem);
$total += $ttc;
$total_ht += $calcultHt;
}
$billing->setHt(number_format((float)$total_ht, 2, ".", ""));
$billing->setTtc(number_format((float)$total, 2, ".", ""));
$billing->setSolde(number_format($billing->getTtc(),2, ".", ""));
$form = $this->createForm(BillingType::class, $billing);
$form->handleRequest($request);
if($form->isSubmitted() && !$form->isValid()) {
$submittedToken = $request->request->get('token');
if (!$this->isCsrfTokenValid('token_id', $submittedToken)) {
return $this->redirectToRoute('app_planning_coiffeurliste');
}
}
if ($form->isSubmitted() && $form->isValid()) {
// FLAGGER ICI le loading comme ca pas de doublon
$billingsRDV = $RDV->getRDVBillings();
$count = 0;
if($billingsRDV->count() > 0){
foreach ($billingsRDV as $itemBilling) {
if ($itemBilling->getBilling() && $itemBilling->getBilling()->getStatus() !== Billing::STATUS_SOLDE_AVOIR && $itemBilling->getBilling()->getStatus() !== Billing::STATUS_SOLDE) {
$count++;
}
}
if($count > 0){
$this->addFlash('error', 'RDV déjà facturé');
return $this->redirectToRoute('app_planning_coiffeurliste');
}
}
$csrfTokenManager->refreshToken("form_intention");
$company = null;
$date = $form['dateBilling']->getData();
$billing->setDateBilling($date);
$total = 0;
$totalHt = 0;
$calcultHt = 0;
/** @var BillingItem $billingItem */
foreach($form['billingItems']->getData() as $billingItem) {
$date = $billingItem->getDateRDV();
$billingItem->setDateRDV($date);
$billingItem->setQuantity($billingItem->getQuantity());
$billingItem->setRefProduct($billingItem->getRefProduct());
$billingItem->setTtc($billingItem->getTtc());
$remise = $billingItem->getDiscount() ?: 0;
$price = $billingItem->getPrice();
if($remise && $remise != 0){
$calcul = (floatval($price) * $billingItem->getQuantity() * (1 - $remise / 100 )) * (1 + $billingItem->getTva() / 100);
$calcultHt = (floatval($price)* $billingItem->getQuantity() * ( 1 - $remise / 100 ));
}
else {
$calcul = floatval($price)* $billingItem->getQuantity() * (1 + $billingItem->getTva() / 100);
$calcultHt = floatval($price) * $billingItem->getQuantity();
}
$total += $calcul;
$totalHt += $calcultHt;
$billingItem->setDateRDV($date);
$entityManager->persist($billingItem);
}
$billing->setClient($RDV->getClient());
//retrive company
if($RDV->getClient()) {
$billingInfos = $RDV->getClient()->getBillingInfos();
if ($billingInfos) {
$company = $billingInfos->getCompany();
$billing->setCompany($company);
}
}
$code = $this->billingManager->getCodeBilling($company, $billing);
$billing->setCode($code);
$billing->setTtc(number_format((float) $total, 2,".", ""));
$billing->setHt(number_format($totalHt, 2,".", ""));
$billing->setStatus(Billing::STATUS_VALIDE);
if($billing->getHt() <= 0 || $billing->getSolde() <= 0){
$billing->setStatus(Billing::STATUS_REGLEE);
}
$billing->setCreator($this->getUser());
$billing->setModeFacturation(Billing::MODE_FRDV);
//$this->persistBillingItems($RDV, $billing);
$rdvBilling = $RDVBillingManager->create($billing, $RDV);
$billing->addRDVBilling($rdvBilling);
$RDV->addRDVBilling($rdvBilling);
$RDV->setStatus(RDV::STATUS_FACTURER);
$entityManager->persist($RDV);
$entityManager->persist($billing);
$entityManager->flush();
// TODO fix product list in invoice
$invoice = $paytweakService->createInvoiceFromClient($RDV->getClient(), $billing);
$call = $paytweakService->createBilling($invoice, $company);
if($call['code'] == 'OK') {
if($billing->getHt() <= 0 || $billing->getSolde() <= 0){
$billing->setStatus(Billing::STATUS_REGLEE);
}
else {
$billing->setStatus(Billing::STATUS_SENT);
}
if(isset($call['link_id'] )){
$billing->setLinkPaytweak($call['link_id']);
}
$billing->setSendingDate(new \DateTime());
$entityManager->persist($billing);
}
else {
$mailService->sentErrorPaytweak($billing, $call['code'], $call['message']);
}
$entityManager->flush();
return $this->redirectToRoute('app_planning_coiffeurliste');
}
return $this->render('billing/new_rdv.html.twig', [
'billing' => $billing,
'rdv' => $RDV,
'tva' => $tva,
'form' => $form->createView(),
]);
}
/**
* @Route("/edit/{id}", name="billing_edit", methods={"GET","POST"})
*/
public function edit(Request $request, Billing $billing, Pdf $knpSnappyPdf): Response
{
$entityManager = $this->getDoctrine()->getManager();
// if($billing->getDateBilling()){
// $billing->setDateBilling($billing->getDateBilling()->format('d/m/Y'));
// }
//dd($billing->getDateBilling());
/** @var BillingItem $billingItem */
foreach($billing->getBillingItems() as $billingItem) {
if($billingItem->getDateRDV()){
$billingItem->setDateRDV($billingItem->getDateRDV());
}
}
$form = $this->createForm(BillingType::class, $billing);
$contencieux = $this->createForm(ContencieuxType::class, $billing);
$client = $billing->getClient();
/** @var Parameter $setting */
$setting = $this->getDoctrine()->getRepository(Parameter::class)->find(1);
$tva = $setting->getTva();
// SET FIELD ICI A FAIRE
$pdf = $request->request->get('pdf');
if($pdf){
$html = $this->renderView('billing/pdf.html.twig',[
'billings' => [$billing],
'company' => $billing->getCompany()
]);
$knpSnappyPdf->setOption('enable-local-file-access', true);
return new PdfResponse(
$knpSnappyPdf->getOutputFromHtml($html, ['encoding' => 'utf-8']),
'file.pdf'
);
}
$form->handleRequest($request);
//dump($form->getErrors());die;
if ($form->isSubmitted() && $form->isValid()) {
$total = 0;
$totalHt = 0;
$calcultHt = 0;
$date = $form['dateBilling']->getData();
$billing->setDateBilling($date);
foreach($form['billingItems']->getData() as $billingItem) {
$date = $billingItem->getDateRDV();
$price = $billingItem->getPrice();
$remise = $billingItem->getDiscount() ?: 0;
if($remise && $remise != 0){
$calculationTtc = ($price * $billingItem->getQuantity() * (1 - $remise / 100)) * (1 + $tva / 100);
$calcul = (floatval($price) * $billingItem->getQuantity() * (1 - $remise / 100 )) * (1 + $billingItem->getTva() / 100);
$calcultHt = (floatval($price)* $billingItem->getQuantity() * ( 1 - $remise / 100 ));
}
else {
$calculationTtc = $price * $billingItem->getQuantity() * (1 + $tva / 100);
$calcul = floatval($price)* $billingItem->getQuantity() * (1 + $billingItem->getTva() / 100);
$calcultHt = floatval($price) * $billingItem->getQuantity();
}
$billingItem->setQuantity($billingItem->getQuantity());
$calculationTtc = number_format((float) $calculationTtc, 2,".", "");
$billingItem->setTtc($calculationTtc);
$total += $calcul;
$totalHt += $calcultHt;
$billingItem->setDateRDV($date);
$entityManager->persist($billingItem);
}
$billing->setTtc(number_format($total, 2,".", ""));
$billing->setHt(number_format($totalHt, 2,".", ""));
//$billing->setSolde(number_format($billing->getTtc(), 2));s
if($billing->getHt() <= 0 || $billing->getSolde() < 0){
$billing->setStatus(Billing::STATUS_REGLEE);
}
$billing->setCreator($this->getUser());
$billing->setMaj($this->getUser());
$entityManager->persist($billing);
$entityManager->flush();
return $this->redirectToRoute('app_billing_index');
}
$contencieux->handleRequest($request);
if ($contencieux->isSubmitted() && $contencieux->isValid()) {
$billing->setStatus(Billing::STATUS_CONTENTIEUX);
$entityManager->persist($billing);
$entityManager->flush();
}
return $this->render('billing/edit.html.twig', [
'billing' => $billing,
'client' => $client,
'tva' => $tva,
'form' => $form->createView(),
'contencieuxForm' => $contencieux->createView(),
]);
}
/**
* @Route("/cancel/{id}/{date}", name="billing_cancel", methods={"GET","POST"})
*/
public function cancel(Request $request, Billing $billing, BillingRepository $billingRepository, BillingItemManager $billingItemManager, $date): Response
{
$em = $this->getDoctrine()->getManager();
if($billing->getStatus() === Billing::STATUS_EN_COURS){
foreach ($billing->getRDVBillings() as $RDVBilling){
$rdv = $RDVBilling->getRDV();
if($rdv && $rdv->getId()){
$rdv->setStatus(RDV::STATUS_VALIDATED);
$em->persist($rdv);
}
$em->remove($RDVBilling);
}
$em->remove($billing);
$em->flush();
return $this->redirectToRoute('app_billing_index');
}
$dateObject = new \DateTime($date);
$this->billingManager->createAvoir($billing, $this->getUser(), $dateObject);
$em->flush();
return $this->redirectToRoute('app_billing_index');
}
/**
* @Route("/import-ajax", name="billing_importajax")
*/
public function importajax(Request $request, FileUploader $fileUploader){
$path = $this->getParameter('updatebilling_import_directory');
$file = $request->files->get('file');
if($file) {
try {
$resp = $fileUploader->upload($request->files->get('file'), $path);
return new JsonResponse(['filename' => $resp ]);
}catch (\Exception $e) {
}
}
return new JsonResponse(['error' => '' ]);
}
/**
* @Route("/importCSV", name="import_csv", methods={"GET","POST"})
*/
public function importCSV(Request $request, BillingRepository $billingRepository, EntityManagerInterface $entityManager){
$path = $this->getParameter('updatebilling_import_directory');
if($request->isMethod(Request::METHOD_POST)) {
$files = $request->request->get('files');
$path_file = $path . '/' . $files[0];
if(file_exists($path_file)) {
try {
/** Identify the type of $inputFileName **/
$inputFileType = \PhpOffice\PhpSpreadsheet\IOFactory::identify($path_file);
/** Create a new Reader of the type defined in $inputFileType **/
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
/** Advise the Reader that we only want to load cell data **/
$reader->setReadDataOnly(true);
$spreadsheet = $reader->load($path_file);
$worksheet = $spreadsheet->getActiveSheet();
//$lines = $spreadsheet->getActiveSheet()->toArray();
foreach ($worksheet->getRowIterator() as $key => $row) {
$cellIterator = $row->getCellIterator();
$cellIterator->setIterateOnlyExistingCells(FALSE); // This loops through all cells,
$billingfound = null;
foreach ($cellIterator as $key2 => $cell) {
$value = $cell->getValue();
switch ($key2) {
case 'A':
{
$billingfound = $billingRepository->findOneBy(['id' => (int) $value]);
break;
}
case 'B':
{
if($billingfound) {
$billingfound->setCode($value);
$entityManager->persist($billingfound);
}
break;
}
default:
break;
}
}
}
}
catch (\Exception $exception) {
dump($exception);die;
}
$entityManager->flush();
}
$this->addFlash('success', 'Fichier importé');
}
return $this->render('billing/import.html.twig', [
]);
}
/**
* @Route("/downloadExcel")
*/
public function downloadExcel(Request $request, BillingRepository $repository) {
$date_debut = $request->request->get('date_debut') ?? null;
$date_fin = $request->request->get('date_fin') ?? null;
$entities = new ArrayCollection($repository->filter(null,null , $date_debut,$date_fin));
$response = new StreamedResponse();
$columns = $this->getColumnsForEntity(Billing::class);
$billingItemColumns = $this->getColumnsForEntity(BillingItem::class);
$response->setCallback(function () use ($entities, $columns, $billingItemColumns) {
$handle = fopen('php://output', 'w+');
// Add header
fputcsv($handle, array_keys($columns));
/** @var Billing $entity */
while ($entity = $entities->current()) {
$values = [];
foreach ($columns as $column => $callback) {
$value = $callback;
if (is_callable($callback)) {
$value = $callback($entity);
}
$values[] = $value;
}
fputcsv($handle, $values);
// fputcsv($handle, array_keys($billingItemColumns));
// $values = [];
// foreach ($entity->getBillingItems() as $billingItem) {
// foreach ($billingItemColumns as $column => $callback) {
// $value = $callback;
// if (is_callable($callback)) {
// $value = $callback($billingItem);
// }
// $values[] = $value;
// }
// }
//
// fputcsv($handle, $values);
$entities->next();
}
fclose($handle);
});
$filename = 'billing.csv';
$response->headers->set('Content-Type', 'text/csv; charset=utf-8');
$response->headers->set('Content-Disposition', 'attachment; filename="' . $filename . '"');
return $response;
}
/**
* @Route("/downloadItemsExcel")
*/
public function downloadItemsExcel(BillingItemsRepository $repository) {
$entities = new ArrayCollection($repository->findAll());
$response = new StreamedResponse();
$columns = $this->getColumnsForEntity(BillingItem::class);
$response->setCallback(function () use ($entities, $columns) {
$handle = fopen('php://output', 'w+');
// Add header
fputcsv($handle, array_keys($columns));
while ($entity = $entities->current()) {
$values = [];
foreach ($columns as $column => $callback) {
$value = $callback;
if (is_callable($callback)) {
$value = $callback($entity);
}
$values[] = $value;
}
fputcsv($handle, $values);
$entities->next();
}
fclose($handle);
});
$filename = 'billing_items.csv';
$response->headers->set('Content-Type', 'text/csv; charset=utf-8');
$response->headers->set('Content-Disposition', 'attachment; filename="' . $filename . '"');
return $response;
}
/**
* @param RDV $RDV
* @param Billing $billing
*/
private function persistBillingItems(RDV $RDV, Billing $billing)
{
$em = $this->getDoctrine()->getManager();
/** @var RR $rdvProduct */
foreach ($RDV->getRdvProducts() as $rdvProduct) {
$product = $rdvProduct->getProduct();
// Fetch products to add billings..
$billingItem = new BillingItem();
$billingItem->setBilling($billing);
$billingItem->setRefProduct($product->getReference());
$billingItem->setLibelleProduct($product->getName());
$billingItem->setProduct($product);
$em->persist($billingItem);
}
}
/**
* @param array $data
* @throws \Exception
*/
private function generateBilling(array $data)
{
$em = $this->managerRegistry;
/** @var RDVRepository $repository */
$repository = $em->getRepository(RDV::class);
/** @var ClientRepository $clientRepository */
$clientRepository = $em->getRepository(Client::class);
/** @var SiteRepository $siteRepository */
$siteRepository = $em->getRepository(Site::class);
/** @var ProductRepository $productRepository */
$productRepository = $em->getRepository(Product::class);
/** @var BillingRepository $billingRepository */
$billingRepository = $em->getRepository(Billing::class);
$typeBilling = $data['typeBilling'];
$start = $data['start'];
$end = $data['end'];
$company = $data['company'];
$site = $data['site'];
/** @var Parameter $setting */
$setting = $this->managerRegistry->getRepository(Parameter::class)->find(1);
$tva = $setting->getTva();
$billing_added = 0;
//dump($company);die;
$rdvs = $repository->findForBilling($start, $end, RDV::STATUS_VALIDATED, $company, $site);
//$company = $companyRepository->find
$merge_rdv = [];
/** @var RDV $rdv */
foreach ($rdvs as $rdv) {
if ($typeBilling === 'client') {
$client_id = $rdv['client_id'];
$merge_rdv[$client_id][] = $rdv;
} else {
$site_id = $rdv['site_id'];
$merge_rdv[$site_id][] = $rdv;
}
}
// Merge contiient tout les rdvs trié soit pppar client_id soit par site_id
//dump($merge_rdv);die;
// pour chaque site ou client
foreach ($merge_rdv as $key => $rdvs) {
$billing = new Billing();
$billing->setCreator($this->getUser());
$client = null;
if ($typeBilling === 'client') {
$client = $clientRepository->find($key);
$billing->setClient($client);
} elseif ($typeBilling === 'site') {
$site = $siteRepository->find($key);
$billing->setSite($site);
}
if($company) {
$billing->setCompany($company);
}
$total = 0;
$totalHt = 0;
foreach ($rdvs as $rdv) {
$rdv_id = $rdv['id'];
// get the rdv
$rdvObj = $repository->findOneBy(['id' => $rdv_id]);
$dateRdv = $rdvObj->getEnd();
// if we bill from site take client from rdv because it will be null
if(!$client){
$client = $rdvObj->getClient();
}
// GET PRODUCT OF RDV
$rdvProducts = $rdvObj->getRdvProducts();
$products = [];
/** @var RDVProduct $rdvProduct */
foreach ($rdvProducts as $rdvProduct) {
$product = $rdvProduct->getProduct();
if(array_key_exists($product->getId(),$products)) {
$products[$product->getId()] = $products[$product->getId()]++;
}
else {
$products[$product->getId()] = 1;
}
}
foreach ($products as $key => $productQuantity) {
$product = $productRepository->find($key);
// Fetch products to add billings..
$billingItem = $this->billingItemManager->create($product, $billing, $productQuantity, $tva, $rdvObj);
//date fin de RDV
//$castedDate = new \DateTime($end);
$billingItem->setDateRDV($dateRdv);
$em->getManager()->persist($billingItem);
$gridPrice = null;
$salon = $rdvObj->getSalon();
if($salon) {
$gridPrice = $rdvObj->getSalon()->getGridPrice();
}
$price = null;
if($gridPrice) {
switch ($gridPrice->getId()) {
case 1:
$price = $product->getPriceHtA();
break;
case 2:
$price = $product->getPriceHtB();
break;
case 3:
$price = $product->getPriceHtC();
break;
case 4:
$price = $product->getPriceHtD();
break;
}
}
else {
$price = $product->getPriceHtA();
}
/**
*
*/
// protect
$remiseClient = $client->getBillingInfos()->getDiscount() ?: 0;
$remise = $remiseClient;
if($product->getRemiseGenerale() && $product->getRemiseGenerale() > $remiseClient ){
$remise = $product->getRemiseGenerale() ?: 0;
}
if($tva <= 0) {
$tva = 20;
}
if($remise && $remise != 0){
$calcul = (floatval($price) * (1 - $remise / 100 )) * (1 + $tva / 100) * $billingItem->getQuantity();
$calcultHt = (floatval($price) * ( 1 - $remise / 100 ) ) * $billingItem->getQuantity() ;
}
else {
$calcul = floatval($price) * (1 + $tva / 100) * $billingItem->getQuantity();
$calcultHt = floatval($price) * $billingItem->getQuantity();
}
$ttc = number_format($calcul, 2, ".", "");
if($remise){
$billingItem->setDiscount(floatval($remise));
}
$billingItem->setPrice(floatval($price));
$billingItem->setTtc($ttc);
// ADD ITEM
$billing->addBillingItem($billingItem);
$total += $billingItem->getTtc();
$totalHt += $calcultHt;
}
//UPDATE RDV
$rdvObj->setStatus(RDV::STATUS_FACTURER);
// LINK TO BILLING / RDV
$rdvBilling = new RDVBilling();
$rdvBilling->setBilling($billing);
$rdvBilling->setRDV($rdvObj);
$em->getManager()->persist($rdvBilling);
$billing->addRDVBilling($rdvBilling);
$rdvObj->addRDVBilling($rdvBilling);
$em->getManager()->persist($rdvObj);
}
// facture need to be in brouillon
//$code = $this->billingManager->getCodeBilling($company);
//$billing->setCode($code);
$billing->setModeFacturation(Billing::MODE_FFDP);
// set billing to total of all RDV
$billing->setTtc(number_format((float)$total, 2, ".", ""));
$billing->setHt($totalHt);
$ttc = str_replace(array(".", ","), array(",", "."), $billing->getTtc());
$billing->setSolde(number_format((float)$ttc, 2, ".", ""));
// UPDTAE BILLING
$billing->setStatus(Billing::STATUS_EN_COURS);
// if($billing->getHt() <= 0 || $billing->getSolde() < 0){
// $billing->setStatus(Billing::STATUS_REGLEE);
// }
$billing->setCreator($this->getUser());
$billing->setMaj($this->getUser());
// set end of period to billing date
$date = date_create_from_format('Y-m-d', $end);
$billing->setDateBilling($date);
$em->getManager()->persist($billing);
$billing_added++;
}
$em->getManager()->flush();
}
/**
* @param $class
* @return mixed
*/
private function getColumnsForEntity($class)
{
$columns[Billing::class] = [
'Id' => function (Billing $billing) {
return (string) $billing->getId();
},
'Date' => function (Billing $billing) {
return $billing->getDateBilling() ? $billing->getDateBilling()->format('d-m-Y H:i:s') : '';
},
'Mode de facturation' => function (Billing $billing) {
return $billing->getModeFacturation();
},
'Code' => function (Billing $billing) {
return $billing->getCode();
},
'Comment' => function (Billing $billing) {
return $billing->getComment();
},
'Ttc' => function (Billing $billing) {
return (string) $billing->getTtc();
},
'Solde' => function (Billing $billing) {
return (string) $billing->getSolde();
},
'Status' => function (Billing $billing) {
return $billing->getStatus();
},
'Accompte' => function (Billing $billing) {
return $billing->getAccompte();
},
'Type' => function (Billing $billing) {
return $billing->getType();
},
'Site' => function (Billing $billing) {
return $billing->getClient() && $billing->getClient()->getSite() ? $billing->getClient()->getSite()->getName() : "";
},
'Status Site' => function (Billing $billing) {
return $billing->getClient() && $billing->getClient()->getSite() ? $billing->getClient()->getSite()->getStatus() : "";
},
'ID client' => function (Billing $billing) {
return $billing->getClient() ? $billing->getClient()->getId(): "";
},
'Civilité' => function (Billing $billing) {
return $billing->getClient() ? $billing->getClient()->getCivilite(): "";
},
'Client' => function (Billing $billing) {
return (string) $billing->getClient();
},
'Statut Client' => function (Billing $billing) {
return (string) $billing->getClient() ? $billing->getClient()->getStatusProspect() : null;
},
'Tel facturation' => function (Billing $billing) {
return $billing->getClient() && $billing->getClient()->getBillingInfos() ? $billing->getClient()->getBillingInfos()->getPhone(): "";
},
'Adresse email facturation' => function (Billing $billing) {
return (string) $billing->getClient() && $billing->getClient()->getBillingInfos() ? $billing->getClient()->getBillingInfos()->getEmail() : "";
},
'Adresse facturation' => function (Billing $billing) {
return (string) $billing->getClient() ? $billing->getClient()->getAddressFacturation(): "";
},
'Adresse complément facturation' => function (Billing $billing) {
return (string) $billing->getClient() ? $billing->getClient()->getComplementAdresseFacturation(): "";
},
'Ville facturation' => function (Billing $billing) {
return (string) $billing->getClient() ? $billing->getClient()->getVilleFacturation(): "";
},
'Code postal facturation' => function (Billing $billing) {
return (string) $billing->getClient() ? $billing->getClient()->getCodePostalFacturation(): "";
},
'Mode envoi facturation' => function (Billing $billing) {
return $billing->getClient() && $billing->getClient()->getBillingInfos() ? $billing->getClient()->getBillingInfos()->getSendMode() : "";
},
];
$columns[BillingItem::class] = [
'Id' => function (BillingItem $billing) {
return $billing->getId();
},
'ReferenceFacture' => function (BillingItem $billing) {
return $billing->getBilling()->getCode();
},
'Date' => function (BillingItem $billing) {
return $billing->getDateRDV() ? $billing->getDateRDV()->format('d-m-Y H:i:s') : '';
},
'Réf product' => function (BillingItem $billing) {
return $billing->getRefProduct();
},
'Price' => function (BillingItem $billing) {
return (string) $billing->getPrice();
},
'Discount' => function (BillingItem $billing) {
return (string) $billing->getDiscount();
},
'Ttc' => function (BillingItem $billing) {
return (string) $billing->getTtc();
},
'Quantity' => function (BillingItem $billing) {
return (string) $billing->getQuantity();
},
'Libelle Produit' => function (BillingItem $billing) {
return $billing->getLibelleProduct();
},
];
if (array_key_exists($class, $columns)) {
return $columns[$class];
}
throw new \InvalidArgumentException(sprintf(
'No columns set for "%s" entity',
$class
));
}
}