/**
  * [addPrice description]
  * @param Devis  $devis    [description]
  * @param [type] $duration [description]
  * @param [type] $price    [description]
  */
 public function create($comment, $price, Iban $iban, Prestation $prestation)
 {
     $transaction = new Transaction();
     $transaction->setPhotographer($prestation->getDevis()->getCompany()->getPhotographer());
     $transaction->setPrestation($prestation);
     $transaction->setPrice($price);
     $transaction->setIban($iban->getIban());
     $transaction->setComment($comment);
     try {
         $this->em->persist($transaction);
         $this->em->flush();
         $this->service->closePrestation($prestation);
         $this->session->successFlashMessage('flash.message.transaction.create');
         return true;
     } catch (\Exception $e) {
         $this->session->errorFlashMessage();
         $this->logger->error($e->getMessage());
         return false;
     }
 }
Esempio n. 2
0
 /**
  * Envoi de mail lors de la mise à jour du statut de la prestation
  * 
  * @param  Prestation $Prestation [description]
  * @return [type]                 [description]
  */
 public function prestationUpdateEmail(Prestation $prestation, $comments = null)
 {
     $status = $prestation->getStatus()->getId();
     $photographer = $prestation->getDevis()->getCompany()->getPhotographer();
     $emailPhotographer = $photographer->getEmail();
     $client = $prestation->getClient();
     $emailClient = $client->getEmail();
     $sendToPhotographer = $this->canReceiveEmails($photographer, 1);
     $sendToClient = $this->canReceiveEmails($client, 1);
     $templatePhotographer = null;
     $templateClient = null;
     switch ($status) {
         case 1:
             $templatePhotographer = 'MainCommonBundle:Emails\\Prestations\\Created:to_photographer.html.twig';
             $templateClient = 'MainCommonBundle:Emails\\Prestations\\Created:to_client.html.twig';
             $subjectPhotographer = $this->translator->trans('prestation.created.photographer.subject', array(), 'email');
             $subjectClient = $this->translator->trans('prestation.created.client.subject', array(), 'email');
             break;
         case 2:
             //PHOTOGRAPHER_OK
             $templatePhotographer = 'MainCommonBundle:Emails\\Prestations\\PreApproved:to_photographer.html.twig';
             $templateClient = 'MainCommonBundle:Emails\\Prestations\\PreApproved:to_client.html.twig';
             $subjectPhotographer = $this->translator->trans('prestation.preapproved.photographer.subject', array(), 'email');
             $subjectClient = $this->translator->trans('prestation.preapproved.client.subject', array(), 'email');
             break;
         case 3:
             //Refused-photographer
             $templatePhotographer = 'MainCommonBundle:Emails\\Prestations\\Refused:to_photographer.html.twig';
             $templateClient = 'MainCommonBundle:Emails\\Prestations\\Refused:to_client.html.twig';
             $subjectPhotographer = $this->translator->trans('prestation.refused.photographer.subject', array(), 'email');
             $subjectClient = $this->translator->trans('prestation.refused.client.subject', array(), 'email');
             break;
         case 4:
             //Cancel-Client
             $templatePhotographer = 'MainCommonBundle:Emails\\Prestations\\Abandonned:to_photographer.html.twig';
             $templateClient = 'MainCommonBundle:Emails\\Prestations\\Abandonned:to_client.html.twig';
             $subjectPhotographer = $this->translator->trans('prestation.abandoned.photographer.subject', array(), 'email');
             $subjectClient = $this->translator->trans('prestation.abandoned.client.subject', array(), 'email');
             break;
         case 5:
             //Valide
             $templatePhotographer = 'MainCommonBundle:Emails\\Prestations\\Confirmed:to_photographer.html.twig';
             $templateClient = 'MainCommonBundle:Emails\\Prestations\\Confirmed:to_client.html.twig';
             $subjectPhotographer = $this->translator->trans('prestation.confirmed.photographer.subject', array(), 'email');
             $subjectClient = $this->translator->trans('prestation.confirmed.client.subject', array(), 'email');
             break;
             /*
             case 6:
                 $to = '';
                 $subject = '';
                 $template = '';
                 $body = '';
                 break;
             case 7:
                 $to = '';
                 $subject = '';
                 $template = '';
                 $body = '';
                 break;
             case 8:
                 $to = '';
                 $subject = '';
                 $template = '';
                 $body = '';
                 break;
             */
         /*
         case 6:
             $to = '';
             $subject = '';
             $template = '';
             $body = '';
             break;
         case 7:
             $to = '';
             $subject = '';
             $template = '';
             $body = '';
             break;
         case 8:
             $to = '';
             $subject = '';
             $template = '';
             $body = '';
             break;
         */
         case 9:
             // Annulation photographer
             $templatePhotographer = 'MainCommonBundle:Emails\\Prestations\\Cancel\\Photographer:to_photographer.html.twig';
             $templateClient = 'MainCommonBundle:Emails\\Prestations\\Cancel\\Photographer:to_client.html.twig';
             $subjectPhotographer = $this->translator->trans('prestation.cancel.photographer.tophotographer.subject', array(), 'email');
             $subjectClient = $this->translator->trans('prestation.cancel.photographer.toclient.subject', array(), 'email');
             break;
         case 10:
             // Annulation client
             $templatePhotographer = 'MainCommonBundle:Emails\\Prestations\\Cancel\\Client:to_photographer.html.twig';
             $templateClient = 'MainCommonBundle:Emails\\Prestations\\Cancel\\Client:to_client.html.twig';
             $subjectPhotographer = $this->translator->trans('prestation.cancel.client.tophotographer.subject', array(), 'email');
             $subjectClient = $this->translator->trans('prestation.cancel.client.toclient.subject', array(), 'email');
             break;
         case 11:
             // Litige client
             $templatePhotographer = 'MainCommonBundle:Emails\\Prestations\\Litige\\Client:to_photographer.html.twig';
             $templateClient = 'MainCommonBundle:Emails\\Prestations\\Litige\\Client:to_client.html.twig';
             $subjectPhotographer = $this->translator->trans('prestation.litige.client.tophotographer.subject', array(), 'email');
             $subjectClient = $this->translator->trans('prestation.litige.client.toclient.subject', array(), 'email');
             break;
         case 12:
             // litige photographer
             $templatePhotographer = 'MainCommonBundle:Emails\\Prestations\\Litige\\Photographer:to_photographer.html.twig';
             $templateClient = 'MainCommonBundle:Emails\\Prestations\\Litige\\Photographer:to_client.html.twig';
             $subjectPhotographer = $this->translator->trans('prestation.litige.photographer.tophotographer.subject', array(), 'email');
             $subjectClient = $this->translator->trans('prestation.litige.photographer.toclient.subject', array(), 'email');
             break;
     }
     $from = self::EMAIL;
     if ($templatePhotographer && $sendToPhotographer) {
         $body = $this->templating->render($templatePhotographer, array('prestation' => $prestation, 'base_url' => $this->community));
         $this->sendMessage($from, $emailPhotographer, $subjectPhotographer, $body);
     }
     if ($templateClient && $sendToClient) {
         $body = $this->templating->render($templateClient, array('prestation' => $prestation, 'comments' => $comments, 'base_url' => $this->front));
         $this->sendMessage($from, $emailClient, $subjectClient, $body);
     }
 }
 public function updateAsPhotographer($params, Prestation $prestation, $slug)
 {
     if ($slug == 'price') {
         $prestation->setPrice($params['price']);
         $flashMessage = 'flash.message.prestation.edit.price';
     } elseif ($slug == 'duration') {
         $devisPrice = $this->em->getRepository('MainCommonBundle:Photographers\\DevisPrices')->findOneBy(array('devis' => $prestation->getDevis()->getId(), 'duration' => $params['duration']));
         $duration = $devisPrice->getDuration();
         $flashMessage = 'flash.message.prestation.edit.duration';
         $prestation->setDuration($duration);
     } elseif ($slug == 'date') {
         $start = str_replace('/', '-', $params['date']) . ' ' . $params['time'] . ':00';
         $startTime = new \DateTime($start);
         $flashMessage = 'flash.message.prestation.edit.date';
         $prestation->setStartTime($startTime);
     }
     $prestation->setUpdatedAt(new \DateTime('now'));
     try {
         $this->em->flush();
         //Envoi du mail
         //$this->notification->createPrestationNotification($prestation);
         $this->session->successFlashMessage($flashMessage);
         return true;
     } catch (\Exception $e) {
         $this->session->errorFlashMessage();
         $this->logger->error($e->getMessage());
         return false;
     }
 }
 public function createPrestationNotification(Prestation $prestation)
 {
     $status = $prestation->getStatus()->getId();
     $photographer = $prestation->getDevis()->getCompany()->getPhotographer();
     $client = $prestation->getClient();
     switch ($status) {
         case 1:
             $to = $photographer;
             $subject = self::PRESTATION_CREEE;
             break;
         case 2:
             //PHOTOGRAPHER_OK
             $to = $client;
             $subject = self::PHOTOGRAPHER_OK;
             break;
         case 3:
             //Cancel-photographer
             $to = $client;
             $subject = self::PHOTOGRAPHER_KO;
             break;
         case 4:
             //Cancel-Client
             $to = $photographer;
             $subject = self::CLIENT_KO;
             break;
         case 5:
             //Valide
             $to = $photographer;
             $subject = self::PRESTATION_OK;
             break;
         case 6:
             $to = $photographer;
             $subject = self::OLD_PRESTATION;
             break;
         case 7:
             $to = $photographer;
             $subject = self::PHOTOS_DELIVERED;
             break;
         case 8:
             $to = $photographer;
             $subject = self::CLOSED_PRESTATION;
             break;
         case 9:
             $to = $client;
             $subject = self::CANCELED_PHOTOGRAPHER;
             break;
         case 10:
             $to = $photographer;
             $subject = self::CANCELED_CLIENT;
             break;
         case 11:
             $to = $photographer;
             $subject = self::LITIGE_CLIENT;
             break;
         case 12:
             $to = $client;
             $subject = self::LITIGE_PHOTOGRAPHER;
             break;
     }
     $notification = new Notification();
     $notification->setType(1);
     $notification->setPrestation($prestation);
     $notification->setContent($subject);
     $notification->setReceiver($to);
     try {
         $this->em->persist($notification);
         $this->em->flush();
     } catch (\Exception $e) {
         $this->session->errorFlashMessage();
         $this->logger->error($e->getMessage());
     }
 }