<?php
namespace App\Service\Finance;
use Symfony\Contracts\Translation\TranslatorInterface;
use App\Service\Kernel\KernelService;
use DateTime;
use Doctrine\ORM\EntityManagerInterface;
use App\Entity\Finance\Lead;
use App\Entity\CMS\CMSVacancy;
use App\Service\Kernel\DMSService;
use App\Entity\Finance\SalesCondition;
/**
* Description of LeadService
*
* @author SebastiaanVanHerbrug
*/
// WERKT NIET
class LeadService {
private $TranslatorInterface;
private $entityManager;
private $kernel_service;
private $dMSService;
public function __construct(TranslatorInterface $translator, EntityManagerInterface $entityManager,
KernelService $kernel_service,
DMSService $dMSService) {
$this->TranslatorInterface = $translator;
$this->entityManager = $entityManager;
$this->kernel_service = $kernel_service;
$this->dMSService = $dMSService;
}
public function checkBetween0and100(float $chance, TranslatorInterface $translator){
if($chance > 1 || $chance<0){
$this->TranslatorInterface->get('session')->getFlashBag()->add('error', $translator->trans('Lead.valuemustbebetween0and100'));
return false;
}else{
return true;
}
}
public function createLead($subject, $details, $client, $endClient, $function, $technology, $language, $chance, $open, $owner, $externalId=null, $created = null, $organization)
{
$entityManager = $this->entityManager;
$dmsservice = $this->dMSService;
//$date = new DateTime($dateString);
$lead = new Lead();
$lead->setOrganization($organization);
$lead->setSubject($subject);
$lead->setDetails($details);
$lead->setClient($client);
$lead->setEndClient($endClient);
//Opzoeken
$lead->setFunction($function);
$lead->setTechnology($technology);
$lead->setLanguage($language);
$lead->setChance($chance);
$lead->setOwner($owner);
$lead->setExternalid($externalId);
$lead->setState(0);
$lead->setOpen($open);
$typeListItem = $this->kernel_service->getListItem("Finance.LeadType", "LeadType.Resource", $organization);
$lead->setType($typeListItem);
if ($created != null)
{
$lead->setCreated($created);
$entityManager->persist($lead);
$entityManager->flush();
}
/*
$cmsvacancy = new CMSVacancy();
$cmsvacancy->setLead($lead);
$cmsvacancy->setWebsite($website);
$cmsvacancy->setSubject($subject);
$cmsvacancy->setLocation($location);
$cmsvacancy->setDetails($details);
*
*/
return $lead;
/*$invoice->setClient($entityManager->getRepository(Client::class)->findOneById($clientid));
$invoice->setAbout($about);
$invoice->setNote($note);
$invoice->setInvoiceDate($date);
$invoice->setOrganization($organization);
if (!$invoiceNumber) {
$invoiceNumber = $this->nextInvoiceNumber($date, $organization);
}
$invoice->setInvoiceNumber($invoiceNumber);
// Currency auto
$invoice->setCurrency($this->kernel_service->getApplicationInfoValue('Kernel.DefaultCurrency'));
$invoice->setLanguage($language);
$salesCondition = $entityManager->getRepository(SalesCondition::class)->findOneById($salesConditionId);
$invoice->setSalesCondition($salesCondition);
$invoice->setSalesConditionText($salesCondition->getTranslatedDescription($language));
$invoice->setState(0);
$this->copyFieldsFromClientToInvoice($invoice);
if ($this->checkForDuplicates($invoice)) {
$entityManager->persist($invoice);
$entityManager->flush();
if ($createPDF == true)
{
$this->updatePDF($invoice);
}
$this->createFolderIfNeeded($invoice);
return $invoice;
} else {
return -1;
}*/
}
}