private static function GetCerrarVentaParams($id_venta)
 {
     $ventaVo = VentaDAO::getByPK($id_venta);
     $resultArray = $ventaVo->asArray();
     //buscar su cliente
     $result["cliente"] = self::GetUsuarioArray($ventaVo->getIdCompradorVenta());
     //agente de venta
     $result["agente"] = self::GetUsuarioArray($ventaVo->getIdUsuario());
     //buscar sus productos y ordenes
     $result["contenido"] = array_merge(VentaProductoDAO::search(new VentaProducto(array("id_venta" => $id_venta))), VentaOrdenDAO::search(new VentaOrden(array("id_venta" => $id_venta))));
     //direccion
     //buscar su agente
     //buscar sucursal
     //buscar empresa
     return $result;
 }
 public static function Venta($id_venta)
 {
     $ventaDao = VentaDAO::getByPK($id_venta);
     if ($ventaDao === null) {
         throw new InvalidDataException("Esta venta no existe");
     }
     $clienteDao = UsuarioDAO::getByPK($ventaDao->getIdCompradorVenta());
     $agenteDao = UsuarioDAO::getByPK($ventaDao->getIdUsuario());
     if ($ventaDao->getEsCotizacion()) {
         $pdf = self::createPdf("Cotizacion");
     } else {
         $pdf = self::createPdf("Nota de venta");
     }
     $opciones_tabla = array();
     $opciones_tabla['showLines'] = 0;
     $opciones_tabla['showHeadings'] = 0;
     $opciones_tabla['shaded'] = 0;
     $opciones_tabla['fontSize'] = 8;
     $opciones_tabla['xOrientation'] = 'right';
     $opciones_tabla['xPos'] = self::puntos_cm(7.5);
     $opciones_tabla['width'] = self::puntos_cm(11);
     $opciones_tabla['textCol'] = array(0, 0, 0);
     $opciones_tabla['titleFontSize'] = 12;
     $opciones_tabla['rowGap'] = 3;
     $opciones_tabla['colGap'] = 3;
     $f = date("d/m/y", $ventaDao->getFecha()) . " " . date("H:i:s", $ventaDao->getFecha());
     if ($ventaDao->getEsCotizacion()) {
         $datos = array(array("col" => "<b>Cotizacion</b>"), array("col" => $ventaDao->getIdVenta()), array("col" => "<b>Numero de orden</b>"), array("col" => ""), array("col" => "<b>Fecha de venta</b>"), array("col" => $f), array("col" => "<b>Agente que cotizo</b>"), array("col" => self::readableText($agenteDao->getNombre())));
     } else {
         $datos = array(array("col" => "<b>Venta</b>"), array("col" => $ventaDao->getIdVenta()), array("col" => "<b></b>"), array("col" => ""), array("col" => "<b>Fecha de venta</b>"), array("col" => $f), array("col" => "<b>Agente de venta</b>"), array("col" => self::readableText($agenteDao->getNombre())));
     }
     $pdf->ezSetY(self::puntos_cm(26.8));
     $opciones_tabla['xPos'] = self::puntos_cm(14.2);
     $opciones_tabla['width'] = self::puntos_cm(4);
     $opciones_tabla['showLines'] = 0;
     $opciones_tabla['shaded'] = 2;
     $opciones_tabla['shadeCol'] = array(1, 1, 1);
     $opciones_tabla['shadeCol2'] = array(0.8984375, 0.95703125, 0.99609375);
     $pdf->ezTable($datos, "", "", $opciones_tabla);
     $ventaProducto = VentaProductoDAO::search(new VentaProducto(array("id_venta" => $id_venta)));
     $ventaOrden = VentaOrdenDAO::search(new VentaOrden(array("id_venta" => $id_venta)));
     $prods = array_merge($ventaProducto, $ventaOrden);
     array_push($prods, $ventaDao);
     self::printProducts($pdf, $prods);
     self::printClient($pdf, $clienteDao);
     self::drawBasicGuide($pdf);
     $pdf->ezStream();
 }
Example #3
0
$esta_venta->setSaldo(FormatMoney($esta_venta->getSaldo()));
$esta_venta->setTotal(FormatMoney($esta_venta->getTotal()));
$esta_venta->setSubtotal(FormatMoney($esta_venta->getSubtotal()));
$esta_venta->setFecha(FormatTime($esta_venta->getFecha(), "SUPLEMENTARY"));
$form = new DAOFormComponent($esta_venta);
$form->setEditable(false);
$form->hideField(array("id_venta", "id_caja", "id_venta_caja", "id_comprador_venta", "id_sucursal", "id_usuario", "impuesto", "retencion", "es_cotizacion", "cancelada", "tipo_de_pago"));
if ($esta_venta->getTipoDeVenta() == "contado") {
    $form->hideField("saldo");
}
$page->addComponent($form);
function function_importe($foo, $obj)
{
    return FormatMoney((double) $obj["precio"] * (double) $obj["cantidad"]);
}
if (sizeof($productos = VentaProductoDAO::search(new VentaProducto(array("id_venta" => $_GET["vid"])))) > 0) {
    $page->addComponent(new TitleComponent("Productos en esta venta", 3));
    $tabla = new TableComponent(array("id_producto" => "Producto", "cantidad" => "Cantidad", "precio" => "Precio Unitario", "id_unidad" => "Importe"), $productos);
    $tabla->addColRender("id_unidad", "function_importe");
    $tabla->addColRender("id_producto", "funcion_producto");
    //$tabla->addColRender("cantidad", 		"FormatMoney");
    $tabla->addColRender("precio", "FormatMoney");
    $page->addComponent($tabla);
}
if (sizeof($v = VentaOrdenDAO::search(new VentaOrden(array("id_venta" => $_GET["vid"])))) > 0) {
    $page->addComponent(new TitleComponent("Ordenes de servicio de esta venta", 3));
    $tabla = new TableComponent(array("id_orden_de_servicio" => "Orden de Servicio", "precio" => "Precio", "descuento" => "Descuento"), $v);
    $tabla->addColRender("id_orden_de_servicio", "funcion_orden_de_servicio");
    $page->addComponent($tabla);
}
$page->addComponent(new TitleComponent("Abonos a esta venta", 3));
Example #4
0
 /**
  *
  *Metodo que cancela una venta
  *
  * @param id_venta string Id de la venta a cancelar
  **/
 public static function Cancelar($id_venta, $billetes = null, $id_caja = null)
 {
     Logger::log("======= Cancenlando venta " . $id_venta . " ===========");
     //valida que la venta exista y que este activa
     $venta = VentaDAO::getByPK($id_venta);
     if ($venta == null) {
         Logger::error("La venta con id: " . $id_venta . " no existe");
         throw new Exception("La venta con id: " . $id_venta . " no existe");
     }
     if ($venta->getCancelada()) {
         Logger::warn("La venta ya ha sido cancelada");
         return;
     }
     //Deja la venta como cancelada y la guarda.
     $venta->setCancelada(1);
     //Obtiene al usuario al que se le vendio
     $usuario = UsuarioDAO::getByPK($venta->getIdCompradorVenta());
     if ($usuario == null) {
         Logger::error("FATAL!!! Esta venta apunta a un usuario que no existe");
         throw new Exception("FATAL!!! Esta venta apunta a un usuario que no existe");
     }
     DAO::transBegin();
     // regresar de almacenes
     // obtener los productos que se vendieron
     // insertalos como neuvo ingreso
     $detalle = VentaProductoDAO::search(new VentaProducto(array("id_venta" => $id_venta)));
     for ($detalleIterator = 0; $detalleIterator < sizeof($detalle); $detalleIterator++) {
         //por cada producto
         //  --- procesos ---
         //  -insertar en productoempresa
         //  -insertar en loteproducto
         //  -insertar en entradalote
         //  -si el tipo de precio de venta es costo, actualizar
         //  -insertar compra producto
         $p = $detalle[$detalleIterator];
         try {
             /*
             ProductoEmpresaDAO::save( new ProductoEmpresa( array(
                     "id_empresa" => $id_empresa,
                     "id_producto" => $p->getIdProducto()
                 ) ) );
                 
             
             if(is_null($p->lote)){
                 throw new InvalidDataException("No selecciono a que lote ira el producto " . $p->id_producto);
             }
             
             
             if(strlen($p->lote) == 0){
                 throw new InvalidDataException("No selecciono a que lote ira el producto " . $p->id_producto);
             }
             */
             //busquemos el id del lote
             $l = LoteDAO::getByPk(1);
             //busquemos la unidad que nos mandaron
             $uResults = UnidadMedidaDAO::search(new UnidadMedida(array("id_unidad_medida" => $p->getIdUnidad(), "activa" => 1)));
             if (sizeof($uResults) != 1) {
                 throw new InvalidDataException("La unidad de medida `" . $p->id_unidad . "` no existe, o no esta activa.");
             }
             //busequemos si este producto ya existe en este lote
             $lp = LoteProductoDAO::getByPK($l->getIdLote(), $p->getIdProducto());
             if (is_null($lp)) {
                 //no existe, insertar
                 $loteProducto = new LoteProducto(array("id_lote" => $l->getIdLote(), "id_producto" => $p->getIdProducto(), "cantidad" => $p->getCantidad(), "id_unidad" => $p->getIdUnidad()));
                 LoteProductoDAO::save($loteProducto);
             } else {
                 //ya existe, sumar
                 //revisemos si es de la misma unidad
                 if ($lp->getIdUnidad() == $p->getIdUnidad()) {
                     //es igual, solo hay que sumar
                     $lp->setCantidad($lp->getCantidad() + $p->getCantidad());
                 } else {
                     //no es igual, hay que convertir
                     try {
                         $r = UnidadMedidaDAO::convertir($p->getIdUnidad(), $lp->getIdUnidad(), $p->getCantidad());
                     } catch (BusinessLogicException $ide) {
                         //no se pudo convertir porque son de
                         //diferentes categorias
                         throw $ide;
                         //mostrar una excpetion mas fresona
                     }
                     $lp->setCantidad($lp->getCantidad() + $r);
                 }
                 //$lp->setCantidad( $lp->getCantidad() + $p->cantidad );
                 LoteProductoDAO::save($lp);
             }
             $s = SesionController::getCurrentUser();
             $loteEntrada = new LoteEntrada(array("id_lote" => $l->getIdLote(), "id_usuario" => $s->getIdUsuario(), "fecha_registro" => time(), "motivo" => "Venta (" . $id_venta . ") Cancelada"));
             LoteEntradaDAO::save($loteEntrada);
             LoteEntradaProductoDAO::save(new LoteEntradaProducto(array("id_lote_entrada" => $loteEntrada->getIdLoteEntrada(), "id_producto" => $p->getIdProducto(), "id_unidad" => $p->getIdUnidad(), "cantidad" => $p->getCantidad())));
             /*
             $compraProducto = new CompraProducto(array(
                     "id_compra"         => $compra->getIdCompra(),
                     "id_producto"       => $p->id_producto,
                     "cantidad"          => $p->cantidad,
                     "precio"            => $p->precio,
                     "descuento"         => 0,
                     "impuesto"          => 0,
                     "id_unidad"         => $p->id_unidad,
                     "retencion"         => 0
                 ) );
             
             CompraProductoDAO::save ( $compraProducto);
             */
         } catch (InvalidDataException $e) {
             Logger::error($e);
             DAO::transRollback();
             throw $e;
         } catch (exception $e) {
             Logger::error($e);
             DAO::transRollback();
             throw new InvalidDatabaseOperationException($e);
         }
     }
     try {
         VentaDAO::save($venta);
         //Si la venta fue a credito, se cancelan todos los abonos hechos al mismo y el dinero se queda a cuenta del usuario.
         if ($venta->getTipoDeVenta() == "credito") {
             $abono_venta = new AbonoVenta();
             $abono_venta->setIdVenta($id_venta);
             $abonos = AbonoVentaDAO::search($abono_venta);
             foreach ($abonos as $abono) {
                 if (!$abono->getCancelado()) {
                     CargosYAbonosController::EliminarAbono($abono->getIdAbonoVenta(), "Venta cancelada", 0, 1, 0, null, null);
                 }
             }
             $usuario->setSaldoDelEjercicio($usuario->getSaldoDelEjercicio() + $venta->getTotal());
             UsuarioDAO::save($usuario);
         } else {
             if ($venta->getTipoDeVenta() == "contado" && !is_null($id_caja)) {
                 CajasController::modificarCaja($id_caja, 1, $billetes, $venta->getTotal());
             }
         }
     } catch (Exception $e) {
         DAO::transRollback();
         Logger::error("No se pudo cancelar la venta: " . $e);
         throw new Exception("No se pudo cancelar la venta");
     }
     DAO::transEnd();
     Logger::log("Venta cancelada exitosamente");
 }
Example #5
0
$compras = CompraDAO::getAll();
for ($i = 0; $i < sizeof($compras); $i++) {
    //buscar sus productos
    $productos = CompraProductoDAO::search(new CompraProducto(array("id_compra" => $compras[$i]->getIdCompra())));
    for ($p = 0; $p < sizeof($productos); $p++) {
        $d_producto = $productos[$p]->asArray();
        $id_sucursal = 7;
        echo ".";
        try {
            SucursalesController::IncrementarDeAlmacenes($d_producto, $id_sucursal);
        } catch (Exception $e) {
            echo "e";
        }
    }
}
$ventas = VentaDAO::getAll();
for ($i = 0; $i < sizeof($ventas); $i++) {
    //buscar sus productos
    $productos = VentaProductoDAO::search(new VentaProducto(array("id_venta" => $ventas[$i]->getIdVenta())));
    if (sizeof($productos) == 0) {
        e("NO HAY PRODUCTOS, WTF");
    }
    for ($p = 0; $p < sizeof($productos); $p++) {
        echo ".";
        try {
            SucursalesController::DescontarDeAlmacenes($productos[$p], $id_sucursal);
        } catch (Exception $e) {
            echo "e";
        }
    }
}