Exemple #1
0
 /**
  * Returns a new PromocionQuery object.
  *
  * @param     string $modelAlias The alias of a model in the query
  * @param     PromocionQuery|Criteria $criteria Optional Criteria to build the query from
  *
  * @return PromocionQuery
  */
 public static function create($modelAlias = null, $criteria = null)
 {
     if ($criteria instanceof PromocionQuery) {
         return $criteria;
     }
     $query = new PromocionQuery();
     if (null !== $modelAlias) {
         $query->setModelAlias($modelAlias);
     }
     if ($criteria instanceof Criteria) {
         $query->mergeWith($criteria);
     }
     return $query;
 }
 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]');
 }
Exemple #3
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');
 }
Exemple #4
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(PromocionPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     }
     $con->beginTransaction();
     try {
         $deleteQuery = PromocionQuery::create()->filterByPrimaryKey($this->getPrimaryKey());
         $ret = $this->preDelete($con);
         // symfony_behaviors behavior
         foreach (sfMixer::getCallables('BasePromocion: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('BasePromocion: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;
     }
 }
Exemple #5
0
 /**
  * Returns the number of related Promocion objects.
  *
  * @param Criteria $criteria
  * @param boolean $distinct
  * @param PropelPDO $con
  * @return int             Count of related Promocion objects.
  * @throws PropelException
  */
 public function countPromocions(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
 {
     $partial = $this->collPromocionsPartial && !$this->isNew();
     if (null === $this->collPromocions || null !== $criteria || $partial) {
         if ($this->isNew() && null === $this->collPromocions) {
             return 0;
         } else {
             if ($partial && !$criteria) {
                 return count($this->getPromocions());
             }
             $query = PromocionQuery::create(null, $criteria);
             if ($distinct) {
                 $query->distinct();
             }
             return $query->filterByProducto($this)->count($con);
         }
     } else {
         return count($this->collPromocions);
     }
 }