automaticEmailBuilder = $this->loadService(AutomaticEmailBuilder::class); $this->emailGenerator = $this->loadService(EmailGenerator::class); } public function createAutomaticEmail( Producer $producer, string $subject, string $message, int $day = null, PointSale $pointSale = null, int $delayBeforeDistribution = null, int $sendingDay = null, int $sendingHour = null, bool $integrateProductList = null ): AutomaticEmail { $automaticEmail = $this->automaticEmailBuilder->instanciateAutomaticEmail($producer); if($day) { $automaticEmail->setDay($day); $automaticEmail->setSendingDay(null); $automaticEmail->setDelayBeforeDistribution($delayBeforeDistribution); } else { $automaticEmail->setSendingDay($sendingDay); $automaticEmail->setDelayBeforeDistribution(null); } if($pointSale) { $automaticEmail->setPointSale($pointSale); } $automaticEmail->setSendingHour($sendingHour); $automaticEmail->setSubject($subject); $automaticEmail->setMessage($message); $automaticEmail->setIntegrateProductList($integrateProductList); $automaticEmail->save(); return $automaticEmail; } public function createEmailFromAutomaticEmail(AutomaticEmail $automaticEmail, Distribution $distribution = null): Email { return $this->emailGenerator->createEmail( $automaticEmail->getSubject(), $automaticEmail->getMessage(), $automaticEmail->getIntegrateProductList(), $automaticEmail->getProducer(), $distribution, true ); } }