예제 #1
0
 /**
  * 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();
 }
예제 #2
0
 /**
  * Get the associated Producto object
  *
  * @param      PropelPDO Optional Connection object.
  * @return     Producto The associated Producto object.
  * @throws     PropelException
  */
 public function getProducto(PropelPDO $con = null)
 {
     if ($this->aProducto === null && $this->idproducto !== null) {
         $this->aProducto = ProductoQuery::create()->findPk($this->idproducto, $con);
         /* The following can be used additionally to
         			guarantee the related object contains a reference
         			to this object.  This level of coupling may, however, be
         			undesirable since it could result in an only partially populated collection
         			in the referenced object.
         			$this->aProducto->addVentas($this);
         		 */
     }
     return $this->aProducto;
 }
예제 #3
0
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
 public function executeIndex(sfWebRequest $request)
 {
     $defaults = array('Inicio' => date('d/m/Y'), 'Fin' => date('d/m/Y'));
     $this->form = new ReporteForm($defaults);
     $html = '';
     $datos = array();
     if ($request->isMethod('POST')) {
         $this->form->bind($request->getParameter('reporte'));
         if ($this->form->isValid()) {
             $valores = $this->form->getValues();
             $inicio = $valores['Inicio'];
             $inicio = explode('/', $inicio);
             $inicio = $inicio[2] . '-' . $inicio[1] . '-' . $inicio[0];
             $fin = $valores['Fin'];
             $fin = explode('/', $fin);
             $fin = $fin[2] . '-' . $fin[1] . '-' . $fin[0];
             switch ($valores['Tipo']) {
                 case '0':
                     $string = 'Estado Actual de Producto';
                     $datos = ProductoQuery::create()->find();
                     $html = $this->getPartial('reporte/reporteCero', array('datos' => $datos));
                     break;
                 case '1':
                     $string = 'Productos por Debajo de Minimo';
                     $productos = ProductoQuery::create()->find();
                     $datos = new PropelArrayCollection();
                     foreach ($productos as $fila) {
                         if ($fila->getCantidadMinima() >= Producto::obtenerExistencia($fila->getId())) {
                             $datos[] = $fila;
                         }
                     }
                     $html = $this->getPartial('reporte/reporteUno', array('datos' => $datos));
                     break;
                 case '2':
                     $string = '5 Maximos Clientes';
                     $listadoUno = array();
                     $listadoDos = array();
                     $listadoTres = array();
                     $MasCompras = FacturaDetalleQuery::create()->useFacturaQuery()->where("created_at <= '{$fin} 23:59:59' and created_at >= '{$inicio} 00:00:00'")->groupByClienteId()->endUse()->withColumn('Count(*)', 'Contador')->orderBy('Contador', 'Desc')->limit(5)->find();
                     foreach ($MasCompras as $mc) {
                         if ($mc->getFactura()) {
                             $Cliente = ClienteQuery::create()->findOneById($mc->getFactura()->getClienteId());
                             $fila = array();
                             $fila['Maximo'] = $mc->getContador();
                             $fila['Cliente'] = $Cliente->getNombre();
                             $listadoUno[] = $fila;
                         }
                     }
                     //
                     $masFacturas = FacturaQuery::create()->where("created_at <= '{$fin} 23:59:59' and created_at >= '{$inicio} 00:00:00'")->groupByClienteId()->withColumn('Count(*)', 'Contador')->orderBy('Contador', 'Desc')->limit(5)->find();
                     foreach ($masFacturas as $mc) {
                         $fila = array();
                         $fila['Maximo'] = $mc->getContador();
                         $fila['Cliente'] = $mc->getCliente()->getNombre();
                         $listadoDos[] = $fila;
                     }
                     //
                     $monto = FacturaDetalleQuery::create()->withColumn('SUM(cantidad * precio_unitario)', 'Total')->useFacturaQuery()->groupByClienteId()->where("created_at <= '{$fin} 23:59:59' and created_at >= '{$inicio} 00:00:00'")->endUse()->orderBy('Total', 'Desc')->limit(5)->find();
                     foreach ($monto as $mc) {
                         $fila = array();
                         $Cliente = ClienteQuery::create()->findOneById($mc->getFactura()->getClienteId());
                         $fila['Monto'] = $mc->getTotal();
                         $fila['Cliente'] = $Cliente->getNombre();
                         $listadoTres[] = $fila;
                     }
                     $datos['listadoUno'] = $listadoUno;
                     $datos['listadoDos'] = $listadoDos;
                     $datos['listadoTres'] = $listadoTres;
                     $html = $this->getPartial('reporte/reporteDos', array('listadoUno' => $listadoUno, 'listadoDos' => $listadoDos, 'listadoTres' => $listadoTres));
                     break;
                 case '3':
                     $Proveedores = MovimientoQuery::create()->where("fecha <= '{$fin}' and fecha >= '{$inicio}'")->filterByTipoMovimiento('+')->groupByProveedorId()->withColumn('count(id)', 'Total')->orderBy('Total')->limit(5)->find();
                     $string = 'Reporte de Proveedores';
                     $html = $this->getPartial('reporte/reporteTres', array('datos' => $Proveedores));
                     break;
                 case '4':
                     $movimientos = MovimientoQuery::create()->where("fecha <= '{$fin}' and fecha >= '{$inicio}'")->filterByTipoMovimiento('-')->groupByProductoId()->withColumn('count(cantidad)', 'Total')->orderBy('Total')->limit(5)->find();
                     $string = 'Reporte de Productos mas Vendidos';
                     $html = $this->getPartial('reporte/reporteCuatro', array('datos' => $movimientos));
                     break;
                 case '5':
                     $movimientos = MovimientoQuery::create()->where("fecha <= '{$fin}' and fecha >= '{$inicio}'")->filterByTipoMovimiento('-')->groupByProductoId()->withColumn('count(cantidad)', 'Total')->orderBy('Total', 'desc')->limit(5)->find();
                     $string = 'Reporte de Productos menos Vendidos';
                     $html = $this->getPartial('reporte/reporteCinco', array('datos' => $movimientos));
                     break;
                 case '6':
                     $Facturas = FacturaQuery::create()->where("created_at <= '{$fin} 23:59:59' and created_at >= '{$inicio} 00:00:00'")->groupByCreatedBy()->withColumn('count(id)', 'Suma')->orderBy('Suma')->limit(1)->find();
                     $string = 'Empleado con mas Venta';
                     $html = $this->getPartial('reporte/reporteSeis', array('datos' => $Facturas));
                     break;
                 case '7':
                     $Facturas = FacturaQuery::create()->where("created_at <= '{$fin} 23:59:59' and created_at >= '{$inicio} 00:00:00'")->groupByCreatedBy()->withColumn('count(id)', 'Suma')->orderBy('Suma')->find();
                     $string = 'Empleados con mas Ventas';
                     $html = $this->getPartial('reporte/reporteSeis', array('datos' => $Facturas));
                     break;
                 case '8':
                     $Producto = MovimientoQuery::create()->where("fecha <= '{$fin}' and fecha >= '{$inicio}'")->groupByProductoId()->withColumn('count(id)', 'Suma')->find();
                     $Marca = MovimientoQuery::create()->joinWith('Producto')->joinWith('Producto.Marca')->where("movimiento.fecha <= '{$fin}' and movimiento.fecha >= '{$inicio}'")->withColumn('count(marca.id)', 'Suma')->find();
                     $tipo = MovimientoQuery::create()->joinWith('Producto')->joinWith('Producto.TipoProducto')->where("movimiento.fecha <= '{$fin}' and movimiento.fecha >= '{$inicio}'")->withColumn('count(TipoProducto.id)', 'Suma')->find();
                     $presentacion = MovimientoQuery::create()->joinWith('Producto')->joinWith('Producto.TipoPresentacion')->where("movimiento.fecha <= '{$fin}' and movimiento.fecha >= '{$inicio}'")->withColumn('count(TipoPresentacion.id)', 'Suma')->find();
                     $string = 'Resumen de Ventas';
                     $html = $this->getPartial('reporte/reporteOcho', array('productos' => $Producto, 'marcas' => $Marca, 'tipos' => $tipo, 'presentacion' => $presentacion));
                     break;
                 case '9':
                     $Pedido = PedidoProveedorQuery::create()->where("estado <> 'Entregado' ")->find();
                     $string = 'Pedidos en Transito';
                     $html = $this->getPartial('reporte/reporteNueve', array('datos' => $Pedido));
                     break;
             }
             if ($request->hasParameter('pdf')) {
                 $htmlBase = '<img src="/vendor/dist/img/logo_farmacia.png" style="width:150px"/><br/><h3>' . $string . '</h3><br/>';
                 $html = $htmlBase . $html;
                 $pdf = new TCPDF("P", "mm", "Letter");
                 $pdf->SetCreator(PDF_CREATOR);
                 $pdf->SetAuthor('SALUD_INTEGRAL');
                 $pdf->SetTitle('Reporte');
                 $pdf->SetSubject('Reporte');
                 $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
                 // set margins
                 $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
                 $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
                 $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
                 $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
                 $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
                 $pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
                 $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);
                 $pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
                 $pdf->SetHeaderMargin(0.1);
                 $pdf->SetFooterMargin(0.1);
                 $pdf->setPrintHeader(false);
                 $pdf->setPrintFooter(false);
                 $pdf->SetFont('dejavusans', '', 7);
                 $pdf->AddPage();
                 $pdf->writeHTML($html);
                 $pdf->Output('Reporte.pdf', 'D');
                 die;
             }
         }
     }
     $this->html = $html;
 }
예제 #4
0
 /**
  * If this collection has already been initialized with
  * an identical criteria, it returns the collection.
  * Otherwise if this TipoPresentacion is new, it will return
  * an empty collection; or if this TipoPresentacion has previously
  * been saved, it will retrieve related Productos 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 TipoPresentacion.
  *
  * @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|Producto[] List of Producto objects
  */
 public function getProductosJoinTipoProducto($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
 {
     $query = ProductoQuery::create(null, $criteria);
     $query->joinWith('TipoProducto', $join_behavior);
     return $this->getProductos($query, $con);
 }
 /**
  * Returns a new ProductoQuery object.
  *
  * @param     string $modelAlias The alias of a model in the query
  * @param     Criteria $criteria Optional Criteria to build the query from
  *
  * @return    ProductoQuery
  */
 public static function create($modelAlias = null, $criteria = null)
 {
     if ($criteria instanceof ProductoQuery) {
         return $criteria;
     }
     $query = new ProductoQuery();
     if (null !== $modelAlias) {
         $query->setModelAlias($modelAlias);
     }
     if ($criteria instanceof Criteria) {
         $query->mergeWith($criteria);
     }
     return $query;
 }
예제 #6
0
 public function eliminarAction()
 {
     $id = (int) $this->params()->fromRoute('id', 0);
     if (!$id) {
         return $this->redirect()->toRoute('producto');
     }
     $request = $this->getRequest();
     if ($request->isPost()) {
         $del = $request->getPost('del', 'No');
         if ($del == 'Yes') {
             $id = (int) $request->getPost('id');
             $ProductoQuery = ProductoQuery::create()->filterByIdproducto($id)->findOne();
             // Almacenamos la ruta en donde se encuentra el archivo que remplasaremos.
             $dirFile = '/Applications/AMPPS/www/Project/HVA/public' . $ProductoQuery->getProductoImagen();
             if (unlink($dirFile)) {
                 //El archivo fue borrado.
                 ProductoQuery::create()->filterByIdproducto($id)->delete();
             } else {
                 ProductoQuery::create()->filterByIdproducto($id)->delete();
             }
         }
         // Redireccionamos a los provedores
         return $this->redirect()->toRoute('producto');
     }
     $provedorEntity = ProductoQuery::create()->filterByIdproducto($id)->findOne();
     return array('id' => $id, 'producto' => $provedorEntity->toArray(BasePeer::TYPE_FIELDNAME));
 }
예제 #7
0
 /**
  * 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;
 }
예제 #8
0
<?php

$url = $_SERVER['REQUEST_URI'];
$url = explode('/', $url);
$valor = 0;
foreach ($url as $fila) {
    if (is_numeric($fila)) {
        $valor = $fila;
    }
}
$imagen = null;
if ($valor) {
    $imagen = ProductoQuery::create()->findOneById($valor);
    if ($imagen) {
        $imagen = $imagen->getImagen();
    }
}
if (sfConfig::get('sf_upload_dir') . DIRECTORY_SEPARATOR . 'carga' . DIRECTORY_SEPARATOR . $imagen) {
    ?>
    <div class="row">
        <div class="col-md-3">

        </div>
        <div class="col-md-9">
            <img src="<?php 
    echo '/web/uploads/' . 'carga/' . $imagen;
    ?>
" style="width:100px"/>
        </div>
    </div>
<?php 
예제 #9
0
 /**
  * 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(ProductoPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     }
     $con->beginTransaction();
     try {
         $deleteQuery = ProductoQuery::create()->filterByPrimaryKey($this->getPrimaryKey());
         $ret = $this->preDelete($con);
         // symfony_behaviors behavior
         foreach (sfMixer::getCallables('BaseProducto: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('BaseProducto: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;
     }
 }