예제 #1
0
 public function execute()
 {
     $em = $this->em();
     $form = $this->prepareForm(new \ru\nazarov\crm\forms\AppForm('app-form', 'Add request', '/?action=add_app', \ru\nazarov\crm\forms\Form::METHOD_POST, 'multipart/form-data'));
     if (!$form->isEmpty() && $form->validate()) {
         $app = new \ru\nazarov\crm\entities\Application();
         $app->setClient($em->find('\\ru\\nazarov\\crm\\entities\\Organization', $form->get('client')));
         $app->setSupplier($em->find('\\ru\\nazarov\\crm\\entities\\Organization', $form->get('supplier')));
         $app->setDate(new \DateTime($form->get('date')));
         $app->setComment($form->get('comment'));
         $app->setLegalEntity($_SESSION['le']);
         $em->persist($app);
         $em->flush();
         \ru\nazarov\sitebase\Facade::notifyHeads('New request.', 'New request added.', '/?action=edit_app&id=' . $app->getId());
         if (($attachments = $form->get(self::ATTACHMENT_KEY)) != null) {
             \ru\nazarov\sitebase\Facade::saveAttachments($app->getId(), 'application', $attachments);
             $em->flush();
         }
         $form->clean();
     }
     $form->setFieldVals('supplier', array_map(function ($org) {
         return (object) array('label' => htmlspecialchars($org->getName()), 'val' => $org->getId());
     }, $em->getRepository('\\ru\\nazarov\\crm\\entities\\Organization')->findBy(array('type' => 1), array('name' => 'ASC'))))->setFieldVals('client', array_map(function ($org) {
         return (object) array('label' => htmlspecialchars($org->getName()), 'val' => $org->getId());
     }, $em->getRepository('\\ru\\nazarov\\crm\\entities\\Organization')->findBy(array('type' => 2), array('name' => 'ASC'))));
     $view = $this->view();
     $view->set('form', $form);
     parent::execute();
 }
예제 #2
0
 public function execute()
 {
     $em = $this->em();
     $form = $this->prepareForm(new \ru\nazarov\crm\forms\OfferForm('offer-form', 'Add offer', '/?action=add_offer', \ru\nazarov\crm\forms\Form::METHOD_POST, 'multipart/form-data'));
     if (!$form->isEmpty() && $form->validate()) {
         //$offerId = $em->getRepository('\ru\nazarov\crm\entities\OfferId')->findOneBy(array());
         $offer = new \ru\nazarov\crm\entities\Offer();
         $offer->setOrg($em->find('\\ru\\nazarov\\crm\\entities\\Organization', $form->get('org')));
         $offer->setApp($em->find('\\ru\\nazarov\\crm\\entities\\Application', $form->get('app')));
         $offer->setDate(new \DateTime($form->get('date')));
         $offer->setComment($form->get('comment'));
         $offer->setLegalEntity($_SESSION['le']);
         $offer->setOfferId($form->get('offer_id'));
         //$offer->setOfferId($offerId->getPrefix() . str_pad($offerId->getNextId(), 4, '0', STR_PAD_LEFT));
         $em->persist($offer);
         //$offerId->setNextId($offerId->getNextId() + 1);
         $em->flush();
         if (($attachments = $form->get(AddAppAction::ATTACHMENT_KEY)) != null) {
             \ru\nazarov\sitebase\Facade::saveAttachments($offer->getId(), 'offer', $attachments);
             $em->flush();
         }
         $form->clean();
     }
     if ($form->get('org') == null) {
         $form->set('org', 'undef');
     }
     $form->setFieldVals('org', \ru\nazarov\sitebase\Facade::getPersonFormOrgsSelectDp());
     $this->view()->set('form', $form)->set('apps', \ru\nazarov\sitebase\Facade::getAppsSelectDp());
     parent::execute();
 }
예제 #3
0
 protected function setItemFields()
 {
     $form = $this->_form;
     $item = $this->_item;
     $em = $this->em();
     $item->setClient($em->find('\\ru\\nazarov\\crm\\entities\\Organization', $form->get('client')));
     $item->setSupplier($em->find('\\ru\\nazarov\\crm\\entities\\Organization', $form->get('supplier')));
     $item->setDate(new \DateTime($form->get('date')));
     $item->setComment($form->get('comment'));
     if (($attachments = $form->get(AddAppAction::ATTACHMENT_KEY)) != null) {
         \ru\nazarov\sitebase\Facade::saveAttachments($item->getId(), 'application', $attachments);
     }
     if (($rmAttachments = $form->get('rm-attachment')) != null) {
         foreach ($rmAttachments as $a) {
             $attachment = $em->find('\\ru\\nazarov\\crm\\entities\\Attachment', $a);
             unlink($_SERVER['DOCUMENT_ROOT'] . $attachment->getPath());
             $em->remove($attachment);
         }
     }
 }