static function obtenerExistencia($id) { $Inventario = InventarioQuery::create()->findByProductoId($id); $existencia = 0; foreach ($Inventario as $fila) { $existencia += $fila->getCantidad(); } return $existencia; }
/** * Executes index action * * @param sfRequest $request A request object */ public function executeIndex(sfWebRequest $request) { $this->form = new IngresoInventarioForm(); if ($request->isMethod('POST')) { $this->form->bind($request->getParameter('ingreso_inventario')); if ($this->form->isValid()) { $valores = $this->form->getValues(); $BitacoraCambios = new BitacoraCambios(); $BitacoraCambios->setModelo('Inventario'); $Producto = ProductoQuery::create()->findOneById($valores['Producto']); $BitacoraCambios->setDescripcion('Ingreso de Inventario de Producto: ' . $Producto->getDescripcion() . ' con cantidad ' . $valores['Cantidad']); $BitacoraCambios->setIp($request->getRemoteAddress()); $Usuario = UsuarioQuery::create()->findOneById(sfContext::getInstance()->getUser()->getAttribute('usuario', null, 'seguridad')); if ($Usuario) { $BitacoraCambios->setCreatedBy($Usuario->getUsuario()); } $Movimiento = new Movimiento(); $Movimiento->setTipoMovimiento('+'); $Movimiento->setProveedorId($valores['Proveedor']); $Movimiento->setProductoId($Producto->getId()); $Movimiento->setCantidad($valores['Cantidad']); $Movimiento->setPrecio($valores['Precio']); $Movimiento->save(); $BitacoraCambios->save(); $Comprobacion = InventarioQuery::create()->filterByProductoId($valores['Producto'])->filterByProveedorId($valores['Proveedor'])->findOne(); if ($Comprobacion) { $Comprobacion->setCantidad($Comprobacion->getCantidad() + $valores['Cantidad']); $anterior = $Comprobacion->getCantidad() * $Comprobacion->getPrecioCompra(); $actual = $valores['Cantidad'] * $valores['Precio']; $suma = ($anterior + $actual) / ($valores['Cantidad'] + $Comprobacion->getCantidad()); $Comprobacion->setPrecioCompra($suma); $Comprobacion->save(); } else { $Inventario = new Inventario(); $Inventario->setPrecioCompra($valores['Precio']); $Inventario->setProductoId($valores['Producto']); $Inventario->setProveedorId($valores['Proveedor']); $Inventario->setCantidad($valores['Cantidad']); $Inventario->save(); } $this->redirect('inventario/index'); } } $this->cinco = InventarioQuery::create()->orderById('DESC')->limit(5)->find(); }
public function configure() { $Inventario = InventarioQuery::create()->find(); $listaInventario = array(); foreach ($Inventario as $fila) { $fecha = date('d/m/Y'); $Promocion = PromocionQuery::create()->filterByProductoId($fila->getProductoId())->where("fecha_inicio <= '{$fecha}' and fecha_fin >= '{$fecha}'")->findOne(); $descuento = 1; if ($Promocion) { $descuento = 1 - $Promocion->getDescuento() / 100; } $listaInventario[$fila->getProductoId()] = "(" . $fila->getProveedor()->getNombre() . ") " . $fila->getProducto()->getDescripcion() . " " . $fila->getCantidad() . " x " . " -Q" . number_format($fila->getPrecioCompra() * 1.2 * $descuento, 2); } $this->setWidget('Producto', new sfWidgetFormChoice(array('choices' => $listaInventario), array('class' => 'form-control'))); $this->setWidget('Cantidad', new sfWidgetFormInputText(array(), array('class' => 'form-control'))); $this->setValidator('Producto', new sfValidatorString(array('required' => true))); $this->setValidator('Cantidad', new sfValidatorInteger(array('required' => true))); $this->widgetSchema->setNameFormat('venta_detalle[%s]'); }
public function executeEntregado(sfWebRequest $request) { $id = $request->getParameter('id'); $BitacoraCambios = new BitacoraCambios(); $BitacoraCambios->setModelo('Pedido Proveedores'); $Usuario = UsuarioQuery::create()->findOneById(sfContext::getInstance()->getUser()->getAttribute('usuario', null, 'seguridad')); $BitacoraCambios->setDescripcion('Cambio de estado de Pedido a Proveedor a Entregado con id : ' . $id . ' el usuario ' . $Usuario->getNombre()); $BitacoraCambios->setIp($request->getRemoteAddress()); $pedido = PedidoProveedorQuery::create()->findOneById($id); $pedido->setEstado('Entregado'); $pedido->save(); $detalle_pedido = DetallePedidoProveedorQuery::create()->filterByPedidoProveedor($pedido)->find(); foreach ($detalle_pedido as $det) { $Comprobacion = InventarioQuery::create()->filterByProductoId($det->getProductoId())->filterByProveedorId($pedido->getProveedorId())->findOne(); if ($Comprobacion) { $Comprobacion->setCantidad($Comprobacion->getCantidad() + $det->getCantidad()); $anterior = $det->getCantidad() * $Comprobacion->getPrecioCompra(); $actual = $det->getCantidad() * $det->getPrecio(); $suma = ($anterior + $actual) / ($det->getCantidad() + $Comprobacion->getCantidad()); $Comprobacion->setPrecioCompra($suma); $Comprobacion->save(); } else { $Inventario = new Inventario(); $Inventario->setPrecioCompra($det->getPrecio()); $Inventario->setProductoId($det->getProductoId()); $Inventario->setProveedorId($pedido->getProveedorId()); $Inventario->setCantidad($det->getCantidad()); $Inventario->save(); } $Movimiento = new Movimiento(); $Movimiento->setTipoMovimiento('+'); $Movimiento->setProveedorId($pedido->getProveedorId()); $Movimiento->setProductoId($det->getProductoId()); $Movimiento->setCantidad($det->getCantidad()); $Movimiento->setPrecio($det->getPrecio()); $Movimiento->save(); } $this->redirect('pedido_proveedor/index'); }
/** * If this collection has already been initialized with * an identical criteria, it returns the collection. * Otherwise if this Proveedor is new, it will return * an empty collection; or if this Proveedor has previously * been saved, it will retrieve related Inventarios from storage. * * This method is protected by default in order to keep the public * api reasonable. You can provide public methods for those you * actually need in Proveedor. * * @param Criteria $criteria optional Criteria object to narrow the query * @param PropelPDO $con optional connection object * @param string $join_behavior optional join type to use (defaults to Criteria::LEFT_JOIN) * @return PropelObjectCollection|Inventario[] List of Inventario objects */ public function getInventariosJoinProducto($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN) { $query = InventarioQuery::create(null, $criteria); $query->joinWith('Producto', $join_behavior); return $this->getInventarios($query, $con); }
/** * Removes this object from datastore and sets delete attribute. * * @param PropelPDO $con * @return void * @throws PropelException * @throws Exception * @see BaseObject::setDeleted() * @see BaseObject::isDeleted() */ public function delete(PropelPDO $con = null) { if ($this->isDeleted()) { throw new PropelException("This object has already been deleted."); } if ($con === null) { $con = Propel::getConnection(InventarioPeer::DATABASE_NAME, Propel::CONNECTION_WRITE); } $con->beginTransaction(); try { $deleteQuery = InventarioQuery::create()->filterByPrimaryKey($this->getPrimaryKey()); $ret = $this->preDelete($con); // symfony_behaviors behavior foreach (sfMixer::getCallables('BaseInventario:delete:pre') as $callable) { if (call_user_func($callable, $this, $con)) { $con->commit(); return; } } if ($ret) { $deleteQuery->delete($con); $this->postDelete($con); // symfony_behaviors behavior foreach (sfMixer::getCallables('BaseInventario:delete:post') as $callable) { call_user_func($callable, $this, $con); } $con->commit(); $this->setDeleted(true); } else { $con->commit(); } } catch (Exception $e) { $con->rollBack(); throw $e; } }
/** * Executes index action * * @param sfRequest $request A request object */ public function executeIndex(sfWebRequest $request) { $defaults = array('Fecha' => date('d/m/Y')); $this->form = new FinDiaForm($defaults); $datos = array(); if ($request->isMethod('POST')) { $this->form->bind($request->getParameter('fin_dia')); if ($this->form->isValid()) { $valores = $this->form->getValues(); $fechaArray = explode('/', $valores['Fecha']); $fecha = $fechaArray[2] . '-' . $fechaArray[1] . '-' . $fechaArray[0]; $valores['Fecha'] = $fecha; $ventas = MovimientoQuery::create()->filterByTipoMovimiento('-')->filterByFecha($valores['Fecha'])->find(); $listaCompras = array(); foreach ($ventas as $fila) { $lista = array(); $lista['Proveedor'] = $fila->getProveedor()->getNombre(); $lista['Producto'] = $fila->getProducto()->getDescripcion(); $lista['Cantidad'] = $fila->getCantidad(); $lista['Precio'] = $fila->getPrecio(); $lista['Total'] = $fila->getPrecio() * $fila->getCantidad(); $listaCompras[] = $lista; } $datos['ventas'] = $listaCompras; $compras = MovimientoQuery::create()->filterByTipoMovimiento('+')->filterByFecha($valores['Fecha'])->find(); $listaVentas = array(); foreach ($compras as $fila) { $lista = array(); $lista['Proveedor'] = $fila->getProveedor()->getNombre(); $lista['Producto'] = $fila->getProducto()->getDescripcion(); $lista['Cantidad'] = $fila->getCantidad(); $lista['Precio'] = $fila->getPrecio(); $lista['Total'] = $fila->getPrecio() * $fila->getCantidad(); $listaVentas[] = $lista; } $datos['compras'] = $listaVentas; $Productos = ProductoQuery::create()->find(); $listaProductos = array(); foreach ($Productos as $p) { $lista = array(); $lista['Producto'] = $p->getDescripcion(); $fecha = $valores['Fecha']; $suma = MovimientoQuery::create()->filterByTipoMovimiento('+')->filterByProductoId($p->getId())->where("fecha < '{$fecha}'")->withColumn('SUM(cantidad)', 'Total')->findOne(); if ($suma) { $suma = $suma->getTotal(); } else { $suma = 0; } $resta = MovimientoQuery::create()->filterByTipoMovimiento('-')->filterByProductoId($p->getId())->where("fecha < '{$fecha}'")->withColumn('SUM(cantidad)', 'Total')->findOne(); if ($resta) { $resta = $resta->getTotal(); } else { $resta = 0; } $lista['Inicio'] = $suma - $resta; $compras = MovimientoQuery::create()->filterByTipoMovimiento('+')->filterByFecha($valores['Fecha'])->filterByProductoId($p->getId())->withColumn('SUM(cantidad)', 'Total')->findOne(); if ($compras) { $compras = $compras->getTotal(); } else { $compras = 0; } $lista['Compra'] = $compras; $ventas = MovimientoQuery::create()->filterByTipoMovimiento('+')->filterByFecha($valores['Fecha'])->filterByProductoId($p->getId())->withColumn('SUM(cantidad)', 'Total')->findOne(); if ($ventas) { $ventas = $ventas->getTotal(); } else { $ventas = 0; } $lista['Ventas'] = $ventas; $inventario = InventarioQuery::create()->filterByProductoId($p->getId())->findOne(); if ($inventario) { $lista['Existencia'] = $inventario->getCantidad(); $lista['Precio'] = $inventario->getPrecioCompra(); } else { $lista['Existencia'] = 0; $lista['Precio'] = 0; } $listaProductos[] = $lista; } $datos["inventarios"] = $listaProductos; } } $this->datos = $datos; }
public function executeEliminar(sfWebRequest $request) { $Factura = FacturaQuery::create()->findOneById($request->getParameter('id')); if (!$Factura->getActivo()) { $this->getUser()->setFlash('error', 'Factura cerrada'); $this->redirect('inicio/index'); } $id = $request->getParameter('id'); $Detalles = FacturaDetalleQuery::create()->findByFacturaId($id); foreach ($Detalles as $detalle) { $Inventario = InventarioQuery::create()->filterByProductoId($detalle->getProductoId())->filterByProveedorId($detalle->getProveedorId())->findOne(); $Inventario->setCantidad($Inventario->getCantidad() + $detalle->getCantidad()); $Inventario->save(); } $Detalles->delete(); FacturaQuery::create()->findOneById($id)->delete(); $this->redirect('inicio/index'); }
/** * Returns a new InventarioQuery object. * * @param string $modelAlias The alias of a model in the query * @param InventarioQuery|Criteria $criteria Optional Criteria to build the query from * * @return InventarioQuery */ public static function create($modelAlias = null, $criteria = null) { if ($criteria instanceof InventarioQuery) { return $criteria; } $query = new InventarioQuery(); if (null !== $modelAlias) { $query->setModelAlias($modelAlias); } if ($criteria instanceof Criteria) { $query->mergeWith($criteria); } return $query; }