/** * Crea un registro nuevo * * Si viene por GET muestra un template vacio * Si viene por POST crea un registro * * @return array con el template y valores a renderizar */ public function newAction() { if ($this->values['permisos']['permisosModulo']['IN']) { switch ($this->request["METHOD"]) { case 'GET': //MOSTRAR FORMULARIO VACIO $datos = new MvtosAlmacen(); $this->values['datos'] = $datos; $this->values['errores'] = array(); return array('template' => $this->entity . '/new.html.twig', 'values' => $this->values); break; case 'POST': //CREAR NUEVO REGISTRO $datosRequest = $this->request['MvtosAlmacen']; $valores = array('UM' => 'UMA', 'Reales' => $datosRequest['Unidades'], 'Pales' => $datosRequest['Pales'], 'Cajas' => $datosRequest['Cajas']); $tipoMvtos = new TiposMvtosAlmacen($datosRequest['IDTipo']); $signo = $tipoMvtos->getSigno()->getIDTipo(); $documento = $tipoMvtos->getTipoDocumento(); unset($tipoMvtos); $idAlmacen = $datosRequest['IDAlmacen']; $idArticulo = $datosRequest['IDArticulo']; $idLote = $datosRequest['IDLote']; $idUbicacion = $datosRequest['IDUbicacion']; $datos = new MvtosAlmacen(); $datos->setDescripcion($datosRequest['Descripcion']); $datos->setObservaciones($datosRequest['Observaciones']); if ($datos->genera($documento, $signo, 0, $idAlmacen, $idArticulo, $idLote, $idUbicacion, 0, $valores)) { $this->values['errores'] = $datos->getErrores(); $this->values['alertas'] = $datos->getAlertas(); //Recargo el objeto para refrescar las propiedas que //hayan podido ser objeto de algun calculo durante el proceso //de guardado. $datos = new MvtosAlmacen($datos->getPrimaryKeyValue()); $this->values['datos'] = $datos; if ($this->values['errores']) { return array('template' => $this->entity . '/new.html.twig', 'values' => $this->values); } else { return array('template' => $this->entity . '/edit.html.twig', 'values' => $this->values); } } else { $this->values['datos'] = $datos; $this->values['errores'] = $datos->getErrores(); $this->values['alertas'] = $datos->getAlertas(); return array('template' => $this->entity . '/new.html.twig', 'values' => $this->values); } break; } } else { return array('template' => '_global/forbiden.html.twig'); } }
/** * Devuelve los mvtos de almacén del artículo en curso para * el almacen y el periodo de fechas indicado. * * Los movimientos se ordenan por almacén y descendentemente por fecha y hora * * @param integer $idAlmacen Por defecto todos los almacenes * @param date $desdeFecha Por defecto todas * @param date $hastaFecha Por defecto todas * @return array */ public function getMvtosAlmacen($idAlmacen = 0, $desdeFecha = '', $hastaFecha = '') { $array = array(); $filtro = "(mv.IDArticulo='{$this->IDArticulo}')"; $filtro .= $idAlmacen <= 0 ? " and (1)" : " and (mv.IDAlmacen='{$idAlmacen}')"; $filtro .= $desdeFecha == '' ? " and (1)" : " and (mv.Fecha>='{$desdeFecha}')"; $filtro .= $hastaFecha == '' ? " and (1)" : " and (mv.Fecha<='{$hastaFecha}')"; $mvtosAlmacen = new MvtosAlmacen(); $tablaMvtos = $mvtosAlmacen->getDataBaseName() . "." . $mvtosAlmacen->getTableName(); $almacenes = new Almacenes(); $tablaAlmacenes = $almacenes->getDataBaseName() . "." . $almacenes->getTableName(); $tipos = new TiposMvtosAlmacen(); $tablaTipos = $tipos->getDataBaseName() . "." . $tipos->getTableName(); $em = new EntityManager($this->getConectionName()); if ($em->getDbLink()) { $query = "select\n al.Nombre as Almacen,\n ti.Descripcion,\n ti.Signo,\n ti.TipoDocumento,\n mv.Fecha,\n mv.Hora,\n mv.IDUbicacion,\n mv.IDLote,\n mv.IDDocumento,\n mv.UnidadesE,\n mv.UnidadesS\n from\n {$tablaMvtos} as mv\n left join {$tablaAlmacenes} as al on mv.IDAlmacen=al.IDAlmacen \n left join {$tablaTipos} as ti on mv.IDTipo=ti.Id \n where {$filtro}\n order by mv.IDAlmacen,mv.Fecha DESC,mv.Hora DESC"; $em->query($query); $array = $em->fetchResult(); $em->desConecta(); } unset($em); return $array; }
/** * Genera un movimiento de almacén y actualiza el stock * * No se creará movimiento de almacén y por lo tanto tampoco se actualizarán existencias: * * * si el artículo no está sujeto a control de inventario * * * si el almacén está sujeto a control de ubicaciones y no se ha indicado ninguna * * * si el artículo está sujeto a control de trazabilidad y no se ha indicado ningún lote * * * si no hay existencias suficientes y el artículo bloquea stock * * @param string $documento El literal que identifica el controlador que provoca el movimiento * @param string $signo El signo que tendrá el movimiento (E = Entrada, S = Salida) * @param integer $idDocumento El id del documento que provoca el movimiento (albaran, pedido, traspaso, inventario, etc) * @param integer $idAlmacen El id del almacén * @param integer $idArticulo El id del articulo * @param integer $idLote El id del lote * @param integer $idUbicacion El id de la ubicacion * @param integer $flagDeposito Indica si el movimineto se ha de realizar contra stock de deposito o no (0, 1) * @param array $valores Array con los valores a actualizar * @return boolean Si el artículo no está sujeto a inventario devuelve TRUE, en caso contrario devuelve TRUE o FALSE dependiendo del éxito de la operación */ public function genera($documento, $signo, $idDocumento, $idAlmacen, $idArticulo, $idLote, $idUbicacion, $flagDeposito, array $valores) { $ok = false; $articulo = new Articulos($idArticulo); // Si el artículo está sujeto a inventario if ($articulo->getInventario()->getIDTipo()) { $tipoMvto = new TiposMvtosAlmacen(); $row = $tipoMvto->cargaCondicion("Id,Signo", "TipoDocumento='{$documento}' and Signo='{$signo}'"); unset($tipoMvto); $idTipo = $row[0]['Id']; $signo = $row[0]['Signo']; if ($signo) { if ($valores['UM'] == '') { $valores['UM'] = 'UMA'; } $this->setIDTipo($idTipo); $this->setIDAlmacen($idAlmacen); $this->setIDArticulo($idArticulo); $this->setIDLote($idLote); $this->setIDUbicacion($idUbicacion); $this->setIDDocumento($idDocumento); switch ($signo) { case 'E': $this->setUnidadesE($articulo->convertUnit($valores['UM'], 'UMA', $valores['Reales'])); $this->setPalesE($valores['Pales']); $this->setCajasE($valores['Cajas']); break; case 'S': $this->setUnidadesS($articulo->convertUnit($valores['UM'], 'UMA', $valores['Reales'])); $this->setPalesS($valores['Pales']); $this->setCajasS($valores['Cajas']); break; } if ($this->validaMovimiento($signo)) { if (parent::create()) { if ($signo == 'S') { $valores['Reales'] = -1 * $valores['Reales']; $valores['Pales'] = -1 * $valores['Pales']; $valores['Cajas'] = -1 * $valores['Cajas']; } $ok = true; $exi = new Existencias(); $exi->actualiza($idAlmacen, $idArticulo, $idLote, $idUbicacion, $flagDeposito, $valores); $this->_errores = $exi->getErrores(); unset($exi); } else { print_r($this->_errores); } } else { print_r($this->_errores); } } else { "NO SE HA DEFINIDIO EL TIPO DE MOVIMIENTO DE ALMACEN"; } } else { $ok = true; } unset($articulo); return $ok; }