Пример #1
0
 public function nuevoAction()
 {
     $request = $this->getRequest();
     $idcliente = $this->params()->fromRoute('id');
     $cliente = \ClienteQuery::create()->findPk($idcliente);
     if ($request->isPost()) {
         $post_data = $request->getPost();
         $entity = new \Expediente();
         foreach ($post_data as $key => $value) {
             if (\ExpedientePeer::getTableMap()->hasColumn($key) && !empty($value) && $key != 'cliente_cumpleanios') {
                 $entity->setByName($key, $value, \BasePeer::TYPE_FIELDNAME);
             }
         }
         //LA FECHA DE APERTURA
         $entity->setExpedienteFechainicio(new \DateTime());
         //EL ESTATUS
         $entity->setExpedienteEstatus('abierto');
         $date = new \DateTime();
         $entity->save();
         //CREAMOS EL FOLIO
         $folio = 'ITR' . $date->format('m') . $date->format('y');
         if ((int) $entity->getIdexpediente() < 10) {
             $folio .= '0';
         }
         $folio .= $entity->getIdexpediente();
         $entity->setExpedienteFolio($folio);
         $entity->save();
         $mailer = new \Shared\GeneralFunction\Itrademailer();
         if ($mailer->newExpedienteEmail($cliente, $folio)) {
             $this->flashMessenger()->addSuccessMessage('Correo electronico enviado exitosamente!');
         }
         $this->flashMessenger()->addSuccessMessage('Registro guardado exitosamente!');
         //REDIRECCIONAMOS A LA ENTIDAD QUE ACABAMOS DE CREAR
         return $this->redirect()->toUrl('/clientes/ver/' . $idcliente . '/expedientes/ver/' . $entity->getIdexpediente());
     }
     $form = new \Admin\Clientes\Form\ExpedienteForm($idcliente);
     $view_model = new ViewModel();
     $view_model->setTemplate('admin/clientes/expedientes/nuevo');
     $view_model->setVariable('form', $form);
     $view_model->setVariable('cliente', $cliente);
     return $view_model;
 }