Beispiel #1
0
 public function save(PropelPDO $con = null)
 {
     $BitacoraCambios = new BitacoraCambios();
     $BitacoraCambios->setModelo('Proveedor');
     $BitacoraCambios->setIp(sfContext::getInstance()->getRequest()->getRemoteAddress());
     if ($this->isNew()) {
         $BitacoraCambios->setDescripcion('Creacion de Proveedor: ' . $this->getNombre());
     } else {
         $BitacoraCambios->setDescripcion('Modificacion de Proveedor: ' . $this->getNombre());
     }
     $Usuario = UsuarioQuery::create()->findOneById(sfContext::getInstance()->getUser()->getAttribute('usuario', null, 'seguridad'));
     if ($Usuario) {
         $BitacoraCambios->setCreatedBy($Usuario->getUsuario());
     }
     $BitacoraCambios->save();
     return parent::save($con);
 }
Beispiel #2
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();
 }
 /**
  * Adds an object to the instance pool.
  *
  * Propel keeps cached copies of objects in an instance pool when they are retrieved
  * from the database.  In some cases -- especially when you override doSelect*()
  * methods in your stub classes -- you may need to explicitly add objects
  * to the cache in order to ensure that the same objects are always returned by doSelect*()
  * and retrieveByPK*() calls.
  *
  * @param      BitacoraCambios $obj A BitacoraCambios object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool($obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = (string) $obj->getId();
         }
         // if key === null
         BitacoraCambiosPeer::$instances[$key] = $obj;
     }
 }
 /**
  * Exclude object from result
  *
  * @param   BitacoraCambios $bitacoraCambios Object to remove from the list of results
  *
  * @return BitacoraCambiosQuery The current query, for fluid interface
  */
 public function prune($bitacoraCambios = null)
 {
     if ($bitacoraCambios) {
         $this->addUsingAlias(BitacoraCambiosPeer::ID, $bitacoraCambios->getId(), Criteria::NOT_EQUAL);
     }
     return $this;
 }
Beispiel #5
0
 public function executeConfirmar(sfWebRequest $request)
 {
     $Factura = FacturaQuery::create()->findOneById($request->getParameter('id'));
     $Detalles = FacturaDetalleQuery::create()->findByFacturaId($request->getParameter('id'));
     if (sizeof($Detalles) == 0) {
         $this->getUser()->setFlash('error', 'No existen productos ingresados en esta factura.');
         $this->redirect('venta/detalle?id=' . $request->getParameter('id'));
     }
     if ($Factura->getActivo()) {
         foreach ($Detalles as $detalle) {
             $fecha = date("d/m/Y");
             $Promocion = PromocionQuery::create()->filterByProductoId($detalle->getProductoId())->where("fecha_inicio <= '{$fecha}' and fecha_fin >= '{$fecha}'")->findOne();
             $descuento = 1;
             if ($Promocion) {
                 $descuento = 1 - $Promocion->getDescuento() / 100;
             }
             $Movimiento = new Movimiento();
             $Movimiento->setTipoMovimiento('-');
             $Movimiento->setClienteId($Factura->getClienteId());
             $Movimiento->setProductoId($detalle->getProductoId());
             $Movimiento->setCantidad($detalle->getCantidad());
             $Movimiento->setProveedorId($detalle->getProveedorId());
             $Movimiento->setPrecio($detalle->getPrecioUnitario() * $descuento);
             $Movimiento->setFecha(date('Y-m-d'));
             $Movimiento->save();
         }
         $BitacoraCambios = new BitacoraCambios();
         $BitacoraCambios->setModelo('Factura');
         $BitacoraCambios->setIp(sfContext::getInstance()->getRequest()->getRemoteAddress());
         $BitacoraCambios->setDescripcion('Creacion de Factura con id: ' . sprintf("%05d", $Factura->getId()));
         $Usuario = UsuarioQuery::create()->findOneById(sfContext::getInstance()->getUser()->getAttribute('usuario', null, 'seguridad'));
         if ($Usuario) {
             $Factura->setCreatedBy($Usuario->getUsuario());
             $BitacoraCambios->setCreatedBy($Usuario->getUsuario());
         }
         $BitacoraCambios->save();
         $Cliente = ClienteQuery::create()->findOneById($Factura->getClienteId());
         if (Factura::obtenerTotal($request->getParameter('id')) >= 200) {
             $Cliente->setPuntos($Cliente->getPuntos() + 10);
             $Cliente->save();
         }
     }
     $Factura->setActivo(false);
     $Factura->save();
     $pdf = new sfTCPDF("P", "mm", "Letter");
     $this->id = $request->getParameter("id");
     $pdf->SetCreator(PDF_CREATOR);
     $pdf->SetAuthor('SALUD_INTEGRAL');
     $pdf->SetTitle('Factura');
     $pdf->SetSubject('Factura');
     $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();
     $html = '';
     $detalles = FacturaDetalleQuery::create()->findByFacturaId($Factura->getId());
     $html = $this->getPartial('venta/soporteTabla', array("factura" => $Factura, "detalles" => $detalles));
     $pdf->writeHTML($html);
     $pdf->Output('Factura.pdf', 'D');
 }
Beispiel #6
0
 public function executeEdita(sfWebRequest $request)
 {
     $this->id = $request->getParameter('id');
     $iddet = $request->getParameter('det');
     $dets = DetallePedidoProveedorQuery::create()->filterById($iddet)->findOne();
     $this->form = new IngresoDetallePedidoProveedorForm(array("Producto" => $dets->getProducto(), "Cantidad" => $dets->getCantidad(), "Precio" => $dets->getPrecio()));
     if ($request->isMethod('POST')) {
         $this->form->bind($request->getParameter('ingreso_detpedprov'));
         if ($this->form->isValid()) {
             $valores = $this->form->getValues();
             $BitacoraCambios = new BitacoraCambios();
             $BitacoraCambios->setModelo('Detalle Pedido Proveedores');
             $BitacoraCambios->setDescripcion('Edicion de Detalle de  Pedido a Proveedor con id :' . $iddet);
             $BitacoraCambios->setIp($request->getRemoteAddress());
             $pedido = $dets;
             $Usuario = UsuarioQuery::create()->findOneById(sfContext::getInstance()->getUser()->getAttribute('usuario', null, 'seguridad'));
             $pedido->setProductoId($valores['Producto']);
             $pedido->setCantidad($valores['Cantidad']);
             $pedido->setPrecio($valores['Precio']);
             $pedido->save();
             $url = 'pedido_proveedor/detalle?id=' . $this->id;
             $this->redirect($url);
         }
     }
 }