예제 #1
0
 public function actionEditarTarifa()
 {
     $id = Yii::app()->request->getParam('id');
     $vigencia = ProgramaCombinacionVigencia::model()->findByPk($id);
     $combi = ProgramaCombinacion::model()->findByPk($vigencia->programa_combinacion_id);
     $tarifas = $vigencia->tarifas;
     if (isset($_POST['ProgramaCombinacionVigencia'])) {
         $vigencia->attributes = $_POST['ProgramaCombinacionVigencia'];
         $vigencia->comentario = $_POST['ProgramaCombinacionVigencia']['comentario'];
         $error = false;
         if (isset($_POST['Tarifa'])) {
             foreach ($_POST['Tarifa'] as $index => $tarifa) {
                 $int = Tarifa::model()->findByPk($tarifa['id']);
                 $int->attributes = $tarifa;
                 $int->validate();
                 $tarifas[$index] = $int;
                 if (count($int->getErrors()) > 0) {
                     $error = true;
                 }
             }
         }
         if ($vigencia->validate() && $error == false) {
             $vigencia->save();
             foreach ($tarifas as $tarifa) {
                 $tarifa->programa_combinacion_vigencia_id = $vigencia->id;
                 $tarifa->save();
             }
             /* Actualiar Precio desde Combinacion */
             $menorCombi = 0;
             foreach ($combi->programaCombinacionVigencias as $vigencias) {
                 foreach ($vigencias->tarifas as $tarifa) {
                     if ($tarifa->nombre == '') {
                         if ($menorCombi == 0) {
                             $menorCombi = $tarifa->dbl;
                         } else {
                             if ($tarifa->dbl < $menorCombi) {
                                 $menorCombi = $tarifa->dbl;
                             }
                         }
                     }
                 }
             }
             $menor = 0;
             foreach ($combi->programa->programaCombinacions as $combinacion) {
                 foreach ($combinacion->programaCombinacionVigencias as $vigencias) {
                     foreach ($vigencias->tarifas as $tarifa) {
                         if ($tarifa->nombre == '') {
                             if ($menor == 0) {
                                 $menor = $tarifa->dbl;
                             } else {
                                 if ($tarifa->dbl < $menor) {
                                     $menor = $tarifa->dbl;
                                 }
                             }
                         }
                     }
                 }
             }
             $combi->precio_desde = $menorCombi;
             $combi->update();
             $programa = Programa::model()->findByPk($combi->programa_id);
             $programa->precio_desde = $menor;
             $programa->update();
             $this->actionGeneratePdf($programa->id);
             /*fin Precio desde Combinacion*/
             Yii::app()->clientScript->scriptMap['jquery.js'] = false;
             Yii::app()->clientScript->scriptMap['jquery.min.js'] = false;
             header("Content-type: application/json");
             echo CJSON::encode(array('status' => 'success', 'div' => $this->renderPartial('_tarifa', array('vigencia' => $vigencia), true, true), 'id' => $id, 'message' => 'Guardado con Exito'));
             exit;
         }
     }
     Yii::app()->clientScript->scriptMap['jquery.js'] = false;
     Yii::app()->clientScript->scriptMap['jquery.min.js'] = false;
     header("Content-type: application/json");
     echo CJSON::encode(array('status' => 'false', 'div' => $this->renderPartial('_formTarifa', array('combi' => $combi, 'tarifas' => $tarifas, 'vigencia' => $vigencia, 'id' => $id), true, true)));
     exit;
 }
예제 #2
0
 /**
  * OK: Guarda los datos de un remito en la bd
  * usado por nuevoAction
  * @return bool
  */
 public function guardarNuevoAction()
 {
     if (!$this->request->isPost()) {
         return $this->dispatcher->forward(array("controller" => "remito", "action" => "index"));
     }
     $planilla_id = $this->request->getPost("remito_planillaId");
     //Controlamos el formulario
     $data = $this->request->getPost();
     $remitoForm = new RemitoForm(null, array('required' => ''));
     if (!$remitoForm->isValid($data, new Remito())) {
         foreach ($remitoForm->getMessages() as $message) {
             $this->flash->error($message);
         }
         return $this->dispatcher->forward(array("controller" => "remito", "action" => "nuevo", "params" => array($planilla_id)));
     }
     $clienteForm = new ClienteNewForm(null, array('required' => ''));
     if (!$clienteForm->isValid($data, new Cliente())) {
         foreach ($clienteForm->getMessages() as $message) {
             $this->flash->error($message);
         }
         return $this->dispatcher->forward(array("controller" => "remito", "action" => "nuevo", "params" => array($planilla_id)));
     }
     //Controlamos que exista la planilla
     $planilla = Planilla::findFirst(array('planilla_id=:planilla_id: AND planilla_finalizada=0 AND planilla_habilitado=1 AND planilla_armada=1', 'bind' => array('planilla_id' => $planilla_id)));
     if (!$planilla) {
         $this->flash->error('Hubo un problema, la planilla no permite agregar más remitos.');
         return $this->dispatcher->forward(array("controller" => "remito", "action" => "nuevo", "params" => array($planilla_id)));
     }
     /*==================== Generar Ultimo Nro de Remito ===============================*/
     $this->db->begin();
     $nuevoRemito = new Remito();
     $ultimoRemito = Remito::findFirst(array("remito_ultima = 1 AND remito_habilitado=1 AND remito_planillaId = :planilla_id:", 'bind' => array('planilla_id' => $planilla_id)));
     if (!$ultimoRemito) {
         $nuevoRemito->setRemitoUltima(1);
         $nuevoRemito->setRemitoNroOrden(1);
     } else {
         $nuevoRemito->setRemitoUltima(1);
         $ultimoRemito->setRemitoUltima(0);
         $nuevoRemito->setRemitoNroOrden($ultimoRemito->getRemitoNroOrden() + 1);
         if (!$ultimoRemito->update()) {
             $this->flash->error('Hubo un problema con la conexion, intenteló nuevamente');
             $this->db->rollback();
             return $this->dispatcher->forward(array("controller" => "remito", "action" => "nuevo", "params" => array($planilla_id)));
         }
     }
     /*==================== Guardando Datos del Remito ===============================*/
     $nuevoRemito->setRemitoPlanillaId($planilla_id);
     $nuevoRemito->setRemitoFechaCreacion(date('Y-m-d'));
     $nuevoRemito->setRemitoCreadoPor($this->session->get('auth')['usuario_nick']);
     $nuevoRemito->setRemitoHabilitado(1);
     $nuevoRemito->setRemitoFecha($this->request->getPost('remito_fecha'));
     $nuevoRemito->setRemitoNro($this->request->getPost('remito_nro'));
     $nuevoRemito->setRemitoPeriodo(date('m', date(strtotime(date($this->request->getPost("remito_fecha"))))));
     if ($this->request->hasFiles() && $this->request->getUploadedFiles()[0] != NULL) {
         var_dump($this->request->getUploadedFiles());
         $upload = $this->guardarPDF($this->request->getUploadedFiles(), $planilla->getPlanillaClienteId(), $planilla->getPlanillaFecha());
         if (!$upload['success']) {
             $this->flash->error($upload['mensaje']);
             $this->db->rollback();
             return $this->dispatcher->forward(array("controller" => "remito", "action" => "nuevo", "params" => array($planilla_id)));
         }
         $nuevoRemito->setRemitoPdf($upload['path']);
     }
     $nuevoRemito->setRemitoObservacion($this->request->getPost('remito_observacion'));
     $nuevoRemito->setRemitoConformidad($this->request->getPost('remito_conformidad'));
     $nuevoRemito->setRemitoNoConformidad($this->request->getPost('remito_noConformidad'));
     /* ==================== ==================== ==================== ==================== */
     $nuevoRemito->setRemitoTransporteId($this->request->getPost('remito_transporteId'));
     $nuevoRemito->setRemitoTipoEquipoId($this->request->getPost('remito_tipoEquipoId'));
     $nuevoRemito->setRemitoTipoCargaId($this->request->getPost('remito_tipoCargaId'));
     $nuevoRemito->setRemitoChoferId($this->request->getPost('remito_choferId'));
     /* ==================== ==================== ==================== ==================== */
     $nuevoRemito->setRemitoClienteId($planilla->getPlanillaClienteId());
     $nuevoRemito->setRemitoCentroCostoId($this->request->getPost('centroCosto_id'));
     $nuevoRemito->setRemitoEquipoPozoId($this->request->getPost('equipoPozo_id'));
     $nuevoRemito->setRemitoOperadoraId($this->request->getPost('operadora_id'));
     /* ==================== ==================== ==================== ==================== */
     $nuevoRemito->setRemitoViajeId($this->request->getPost('remito_viajeId'));
     $nuevoRemito->setRemitoConcatenadoId($this->request->getPost('remito_concatenadoId'));
     /* ==================== ==================== ==================== ==================== */
     $tarifa = new Tarifa();
     $tarifa->setTarifaHoraInicial($this->request->getPost("tarifa_horaInicial"));
     $tarifa->setTarifaHoraFinal($this->request->getPost("tarifa_horaFinal"));
     $tarifa->setTarifaHsServicio($this->request->getPost("tarifa_hsServicio"));
     $tarifa->setTarifaHsHidro($this->request->getPost("tarifa_hsHidro"));
     $tarifa->setTarifaHsMalacate($this->request->getPost("tarifa_hsMalacate"));
     $tarifa->setTarifaHsStand($this->request->getPost("tarifa_hsStand"));
     $tarifa->setTarifaKm($this->request->getPost("tarifa_km"));
     if (!$tarifa->save()) {
         foreach ($tarifa->getMessages() as $mensaje) {
             $this->flash->error($mensaje);
         }
         $this->db->rollback();
         return $this->dispatcher->forward(array("controller" => "remito", "action" => "nuevo", "params" => array($planilla_id)));
     }
     $nuevoRemito->setRemitoTarifaId($tarifa->getTarifaId());
     /* ==================== ==================== ==================== ==================== */
     $planilla = Planilla::findFirstByPlanilla_id($planilla_id);
     $columnas = Columna::find(array("columna_cabeceraId=:cabecera_id: AND columna_habilitado = 1 AND columna_extra = 1", 'bind' => array('cabecera_id' => $planilla->getPlanillaCabeceraid())));
     if (count($columnas) != 0) {
         foreach ($columnas as $col) {
             $contenidoExtra = new Contenidoextra();
             $contenidoExtra->setContenidoExtraHabilitado(1);
             $contenidoExtra->setContenidoExtraColumnaId($col->getColumnaId());
             echo "<br> COl NOmbre" . $col->getColumnaClave();
             echo "<br> getPOst" . $this->request->getPost($col->getColumnaClave());
             $contenidoExtra->setContenidoExtraDescripcion($this->request->getPost($col->getColumnaClave()));
             if (!$contenidoExtra->save()) {
                 foreach ($contenidoExtra->getMessages() as $mensaje) {
                     $this->flash->error($mensaje);
                 }
                 $this->db->rollback();
                 return $this->dispatcher->forward(array("controller" => "remito", "action" => "nuevo", "params" => array($planilla_id)));
             }
         }
     }
     /* ==================== ==================== ==================== ==================== */
     if (!$nuevoRemito->save()) {
         foreach ($nuevoRemito->getMessages() as $mensaje) {
             $this->flash->error($mensaje);
         }
         $this->db->rollback();
         return $this->dispatcher->forward(array("controller" => "remito", "action" => "nuevo", "params" => array($planilla_id)));
     }
     $this->db->commit();
     $this->flash->success('Remito creado satisfactoriamente');
     return $this->dispatcher->forward(array("controller" => "remito", "action" => "finaliza", "params" => array($planilla_id)));
 }
예제 #3
0
 /**
  * Creates a new orden
  */
 public function createAction()
 {
     if (!$this->request->isPost()) {
         return $this->dispatcher->forward(array("controller" => "orden", "action" => "index"));
     }
     $orden = new Orden();
     //Buscar la ultima orden habilitada de la planilla
     $ultimaOrden = Orden::findFirst(array("orden_ultima = 1 AND orden_habilitado=1 AND orden_planillaId = :orden_planillaId:", 'bind' => array('orden_planillaId' => $this->request->getPost("orden_planillaId"))));
     if (!$ultimaOrden) {
         $orden->setOrdenNro(1);
         $orden->setOrdenUltima(1);
     } else {
         $orden->setOrdenNro($ultimaOrden->getOrdenNro() + 1);
         $orden->setOrdenUltima(1);
         $ultimaOrden->setOrdenUltima(0);
         $ultimaOrden->update();
     }
     $orden->setOrdenPlanillaId($this->request->getPost("orden_planillaId"));
     //FIXME: obtener el mes dese orden_fecha
     $orden->setOrdenPeriodo(date('d/m/Y', date(strtotime(date($this->request->getPost("orden_fecha"))))));
     $orden->setOrdenRemito($this->request->getPost("orden_remito"));
     $orden->setOrdenFecha($this->request->getPost("orden_fecha"));
     $orden->setOrdenTransporteId($this->request->getPost("orden_transporteId"));
     $orden->setOrdenTipoEquipoId($this->request->getPost("orden_tipoEquipoId"));
     $orden->setOrdenTipoCargaId($this->request->getPost("orden_tipoCargaId"));
     $orden->setOrdenChoferId($this->request->getPost("orden_choferId"));
     /*Busco los nombre de los clientes, */
     $orden->setOrdenClienteId($this->request->getPost("cliente_id"));
     $orden->setOrdenFrsId($this->request->getPost("frs_id"));
     $orden->setOrdenCentroCostoId($this->request->getPost("centroCosto_id"));
     $orden->setOrdenEquipoPozoId($this->request->getPost("equipoPozo_id"));
     $orden->setOrdenViajeId($this->request->getPost("orden_viajeId"));
     $orden->setOrdenConcatenadoId($this->request->getPost("orden_concatenadoId"));
     $tarifa = new Tarifa();
     $tarifa->setTarifaHoraInicial($this->request->getPost("tarifa_horaInicial"));
     $tarifa->setTarifaHoraFinal($this->request->getPost("tarifa_horaFinal"));
     $tarifa->setTarifaHsServicio($this->request->getPost("tarifa_hsServicio"));
     $tarifa->setTarifaHsHidro($this->request->getPost("tarifa_hsHidro"));
     $tarifa->setTarifaHsMalacate($this->request->getPost("tarifa_hsMalacate"));
     $tarifa->setTarifaHsStand($this->request->getPost("tarifa_hsStand"));
     $tarifa->setTarifaKm($this->request->getPost("tarifa_km"));
     if (!$tarifa->save()) {
         foreach ($tarifa->getMessages() as $mensaje) {
             $this->flash->error($mensaje);
         }
         return $this->dispatcher->forward(array("controller" => "orden", "action" => "index"));
     }
     $orden->setOrdenTarifaId($tarifa->getTarifaId());
     $orden->setOrdenObservacion($this->request->getPost("orden_observacion"));
     $orden->setOrdenConformidad($this->request->getPost("orden_conformidad"));
     $orden->setOrdenNoconformidad($this->request->getPost("orden_noConformidad"));
     $orden->setOrdenFechacreacion(date('Y-m-d'));
     $orden->setOrdenCreadoPor($this->session->get('auth')['usuario_nick']);
     $orden->setOrdenHabilitado(1);
     if (!$orden->save()) {
         //FIXME: ROLLBACK!! para que ultimaOrden vuelva a estar como antes.
         foreach ($orden->getMessages() as $message) {
             $this->flash->error('HUBO UN PROBLEMA AL GENERAR LA ORDEN. <br> <ins>Detalles:</ins><br>' . $message);
         }
         return $this->dispatcher->forward(array("controller" => "orden", "action" => "new"));
     }
     $this->flash->success("La orden se creó correctamente");
     return $this->dispatcher->forward(array("controller" => "orden", "action" => "index"));
 }
예제 #4
0
 /**
  * Deletes a tarifa
  *
  * @param string $tarifa_id
  */
 public function deleteAction($tarifa_id)
 {
     $tarifa = Tarifa::findFirstBytarifa_id($tarifa_id);
     if (!$tarifa) {
         $this->flash->error("tarifa was not found");
         return $this->dispatcher->forward(array("controller" => "tarifa", "action" => "index"));
     }
     if (!$tarifa->delete()) {
         foreach ($tarifa->getMessages() as $message) {
             $this->flash->error($message);
         }
         return $this->dispatcher->forward(array("controller" => "tarifa", "action" => "search"));
     }
     $this->flash->success("tarifa was deleted successfully");
     return $this->dispatcher->forward(array("controller" => "tarifa", "action" => "index"));
 }
예제 #5
0
파일: tarifa.php 프로젝트: agldiego/salud
<?php

include_once realpath(dirname(__FILE__) . '/Tarifa.class.php');
$Tarifa = new Tarifa();
switch ($_REQUEST['a']) {
    case 'listar':
        permisos(CONFIGURACION, 'r');
        $Tarifa->listar();
        break;
    case 'ingresarForm':
        permisos(CONFIGURACION, 'w');
        $Tarifa->ingresarForm();
        break;
    case 'ingresar':
        permisos(CONFIGURACION, 'w');
        $Tarifa->ingresar();
        break;
    case 'actualizarForm':
        permisos(CONFIGURACION, 'u');
        $Tarifa->actualizarForm();
        break;
    case 'actualizar':
        permisos(CONFIGURACION, 'u');
        $Tarifa->actualizarDatos();
        break;
    case 'eliminar':
        permisos(CONFIGURACION, 'd');
        $Tarifa->borrar($_REQUEST['id']);
        break;
}