コード例 #1
0
ファイル: actions.class.php プロジェクト: kcornejo/usac
 public function executeDetalle(sfWebRequest $request)
 {
     $Factura = FacturaQuery::create()->findOneById($request->getParameter('id'));
     if (!$Factura->getActivo()) {
         $this->getUser()->setFlash('error', 'Factura cerrada');
         $this->redirect('inicio/index');
     }
     $this->form = new VentaDetalleForm();
     if ($request->isMethod('POST')) {
         $this->form->bind($request->getParameter('venta_detalle'));
         if ($this->form->isValid()) {
             $valores = $this->form->getValues();
             $FacturaDetalle = FacturaDetalleQuery::create()->filterByProductoId($valores['Producto'])->filterByFacturaId($request->getParameter('id'))->findOne();
             $Factura = FacturaQuery::create()->findOneById($request->getParameter('id'));
             $cantidad = 0;
             $Producto = InventarioQuery::create()->filterByProductoId($valores['Producto'])->findOne();
             $fecha = date('d/m/Y');
             $Promocion = PromocionQuery::create()->filterByProductoId($valores['Producto'])->where("fecha_inicio <= '{$fecha}' and fecha_fin >= '{$fecha}'")->findOne();
             $descuento = 1;
             if ($Promocion) {
                 $descuento = 1 - $Promocion->getDescuento() / 100;
             }
             if ($FacturaDetalle) {
                 $FacturaDetalle->setCantidad($valores['Cantidad'] + $FacturaDetalle->getCantidad());
                 $cantidad = $valores['Cantidad'];
             } else {
                 $FacturaDetalle = new FacturaDetalle();
                 $FacturaDetalle->setProveedorId($Producto->getProveedorId());
                 $FacturaDetalle->setFacturaId($request->getParameter('id'));
                 $FacturaDetalle->setProductoId($valores['Producto']);
                 $FacturaDetalle->setCantidad($valores['Cantidad']);
                 $cantidad = $valores['Cantidad'];
                 $FacturaDetalle->setPrecioUnitario($Producto->getPrecioCompra() * 1.2 * $descuento);
             }
             if ($cantidad <= $Producto->getCantidad()) {
                 $Producto->setCantidad($Producto->getCantidad() - $cantidad);
                 $Producto->save();
                 $FacturaDetalle->save();
             } else {
                 $this->getUser()->setFlash('error', 'Cantidad solicitada supera a la cantidad en existencia');
             }
             $this->redirect('venta/detalle?id=' . $request->getParameter('id'));
         }
     }
     $this->id = $request->getParameter('id');
     $this->detalles = FacturaDetalleQuery::create()->findByFacturaId($this->id);
     $this->factura = FacturaQuery::create()->findOneById($this->id);
 }
コード例 #2
0
ファイル: BaseProveedor.php プロジェクト: kcornejo/usac
 /**
  * @param	FacturaDetalle $facturaDetalle The facturaDetalle object to add.
  */
 protected function doAddFacturaDetalle($facturaDetalle)
 {
     $this->collFacturaDetalles[] = $facturaDetalle;
     $facturaDetalle->setProveedor($this);
 }
コード例 #3
0
 /**
  * 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      FacturaDetalle $obj A FacturaDetalle 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
         FacturaDetallePeer::$instances[$key] = $obj;
     }
 }
コード例 #4
0
ファイル: BaseProveedorQuery.php プロジェクト: kcornejo/usac
 /**
  * Filter the query by a related FacturaDetalle object
  *
  * @param   FacturaDetalle|PropelObjectCollection $facturaDetalle  the related object to use as filter
  * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @return   ProveedorQuery The current query, for fluid interface
  * @throws   PropelException - if the provided filter is invalid.
  */
 public function filterByFacturaDetalle($facturaDetalle, $comparison = null)
 {
     if ($facturaDetalle instanceof FacturaDetalle) {
         return $this->addUsingAlias(ProveedorPeer::ID, $facturaDetalle->getProveedorId(), $comparison);
     } elseif ($facturaDetalle instanceof PropelObjectCollection) {
         return $this->useFacturaDetalleQuery()->filterByPrimaryKeys($facturaDetalle->getPrimaryKeys())->endUse();
     } else {
         throw new PropelException('filterByFacturaDetalle() only accepts arguments of type FacturaDetalle or PropelCollection');
     }
 }
コード例 #5
0
 /**
  * Exclude object from result
  *
  * @param   FacturaDetalle $facturaDetalle Object to remove from the list of results
  *
  * @return FacturaDetalleQuery The current query, for fluid interface
  */
 public function prune($facturaDetalle = null)
 {
     if ($facturaDetalle) {
         $this->addUsingAlias(FacturaDetallePeer::ID, $facturaDetalle->getId(), Criteria::NOT_EQUAL);
     }
     return $this;
 }