Example #1
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();
 }
Example #2
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();
 }
Example #3
0
 protected function prepareData()
 {
     parent::prepareData();
     $em = $this->em();
     $attachments = $em->getRepository('\\ru\\nazarov\\crm\\entities\\Attachment')->findBy(array('owner' => $this->_item->getId(), 'type' => $em->getRepository('\\ru\\nazarov\\crm\\entities\\AttachmentType')->findBy(array('code' => 'offer'))));
     $this->view()->set('apps', \ru\nazarov\sitebase\Facade::getAppsSelectDp())->set('attachment_key', AddAppAction::ATTACHMENT_KEY)->set('attachments', array_map(function ($a) {
         return (object) array('name' => $a->getName(), 'id' => $a->getId());
     }, $attachments));
 }
Example #4
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);
         }
     }
 }
Example #5
0
 public function execute()
 {
     $em = $this->em();
     $form = $this->prepareForm(new \ru\nazarov\crm\forms\PersonForm('person-form', 'Add person', '/?action=add_person', \ru\nazarov\crm\forms\Form::METHOD_POST));
     if (!$form->isEmpty() && $form->validate()) {
         $p = new \ru\nazarov\crm\entities\Person();
         $p->setName($form->get('name'));
         $p->setOrganization($em->find('\\ru\\nazarov\\crm\\entities\\Organization', $form->get('org')));
         $p->setPosition($form->get('pos'));
         $p->setComment($form->get('comment'));
         $p->setLegalEntity($_SESSION['le']);
         $em->persist($p);
         $contacts = $form->get(self::CONTACT_VALUES_KEY);
         if ($contacts != null) {
             foreach ($form->get(self::CONTACT_TYPES_KEY) as $i => $type) {
                 $c = new \ru\nazarov\crm\entities\Contact();
                 $c->setPerson($p);
                 $c->setType($em->find('\\ru\\nazarov\\crm\\entities\\ContactType', $type));
                 $c->setValue($contacts[$i]);
                 $em->persist($c);
             }
         }
         $em->flush();
         $form->clean();
     }
     $view = $this->view();
     $view->set('form', $form)->set('contact_types_key', self::CONTACT_TYPES_KEY)->set('contact_ids_key', self::CONTACT_ID_KEY)->set('contact_values_key', self::CONTACT_VALUES_KEY);
     $form->setFieldVals('org', \ru\nazarov\sitebase\Facade::getPersonFormOrgsSelectDp());
     if ($form->get('org') == null) {
         $form->set('org', 'undef');
     }
     if (count($types = $form->get(self::CONTACT_TYPES_KEY)) > 0) {
         $view->set('contacts', array_map(function ($type, $val) {
             return (object) array('type' => $type, 'val' => $val);
         }, $types, $form->get(self::CONTACT_VALUES_KEY)));
     }
     parent::execute();
 }
Example #6
0
 public function execute()
 {
     $em = $this->em();
     $form = $this->prepareForm(new \ru\nazarov\crm\forms\ReportForm('report-form', 'Add report', '/?action=add_report', \ru\nazarov\crm\forms\Form::METHOD_POST));
     if (!$form->isEmpty() && $form->validate()) {
         $r = new \ru\nazarov\crm\entities\Report();
         $r->setComment($form->get('comment'));
         $r->setContact($em->find('\\ru\\nazarov\\crm\\entities\\Contact', $form->get('contact')));
         $r->setDate(new \DateTime($form->get('date')));
         $r->setLegalEntity($_SESSION['le']);
         $r->setApp($em->find('\\ru\\nazarov\\crm\\entities\\Application', $form->get('app')));
         $em->persist($r);
         $em->flush();
         \ru\nazarov\sitebase\Facade::notifyHeads('New report.', 'New report added.', '/?action=edit_report&id=' . $r->getId());
         $form->clean();
     }
     $types = array_map(function ($type) {
         return (object) array('label' => $type->getCode(), 'val' => $type->getId());
     }, $em->getRepository('\\ru\\nazarov\\crm\\entities\\OrganizationType')->findAll());
     //$form->setFieldVals('type', $types);
     $this->view()->set('form', $form)->set('types', $types);
     parent::execute();
 }
Example #7
0
 protected function prepareData()
 {
     parent::prepareData();
     $selectsDp = \ru\nazarov\sitebase\Facade::getReportSelectsDps();
     $this->view()->set('content', 'report_form.tpl')->set('orgs', $selectsDp->orgs)->set('persons', $selectsDp->persons)->set('contacts', $selectsDp->contacts)->set('apps', $selectsDp->apps)->set('date', $this->_item->getDate());
 }
Example #8
0
 protected function fillSelects()
 {
     $this->_form->setFieldVals('org', \ru\nazarov\sitebase\Facade::getPersonFormOrgsSelectDp());
 }