Esempio n. 1
0
 public static function getCantidadDeRemitos($planilla_id)
 {
     $remitos = Remito::find(array('remito_planillaId =:planilla_id:', 'bind' => array('planilla_id' => $planilla_id)));
     return count($remitos);
 }
Esempio n. 2
0
 /**
  * Guarda un remito escaneado en el servidor. La peticion se hace a traves de un modal.
  * [AJAX]
  */
 public function guardarRemitoEscaneadoAction()
 {
     $this->view->disable();
     $retorno = array();
     $retorno['success'] = true;
     $retorno['mensaje'] = '';
     if ($this->request->isPost()) {
         $planilla = Planilla::findFirst(array('planilla_id=:planilla_id: AND planilla_habilitado=1 AND planilla_armada=1 AND planilla_finalizada=0', 'bind' => array('planilla_id' => $this->request->getPost('planilla_id'))));
         if (!$planilla) {
             $retorno['success'] = false;
             $retorno['mensaje'] = "NO SE ENCONTRO NINGUNA PLANILLA HABILITADA. ID: " . $this->request->getPost('planilla_id');
         } else {
             $nombreCarpeta = 'temp/' . $planilla->getCliente()->getClienteNombre() . '/' . $planilla->getPlanillaFecha();
             if (!file_exists($nombreCarpeta)) {
                 mkdir($nombreCarpeta, 0777, true);
             }
             $path = $nombreCarpeta . '/' . $_FILES['file']['name'];
             #move the file and simultaneously check if everything was ok
             move_uploaded_file($_FILES['file']['tmp_name'], $path) ? $retorno['success'] = true : ($retorno['success'] = false);
             if (!$retorno['success']) {
                 $retorno['success'] = false;
                 $retorno['mensaje'] = "Ocurrio un problema al guardar el archivo en el servidor. ";
             } else {
                 $remito = Remito::findFirst(array('remito_id=:remito_id:', 'bind' => array('remito_id' => $this->request->getPost('remito_id'))));
                 if (!$remito) {
                     $retorno['success'] = false;
                     $retorno['mensaje'] = "El Remito no se encontró ID:" . $this->request->getPost('remito_id');
                     echo json_encode($retorno);
                     return;
                 }
                 $remito->setRemitoPdf($path);
                 if (!$remito->update()) {
                     $retorno['success'] = false;
                     foreach ($remito->getMessages() as $mensaje) {
                         $retorno['mensaje'] .= $mensaje . "<br>";
                     }
                 } else {
                     $retorno['mensaje'] = "Operación Exitosa, el archivo se ha guardado en {$path}";
                 }
             }
         }
     }
     echo json_encode($retorno);
     return;
 }