public static function IncrementarDeAlmacenes($d_producto, $id_sucursal)
 {
     //busquemos el primer lote de esa sucursal
     $l = LoteDAO::getAll();
     $l = $l[0];
     //busquemos la unidad que nos mandaron
     $uResults = UnidadMedidaDAO::getByPK($d_producto["id_unidad"]);
     if (is_null($uResults)) {
         throw new InvalidDataException("La unidad de medida `" . $d_producto["id_unidad"] . "` no existe, o no esta activa.");
     }
     //busequemos si este producto ya existe en este lote
     $lp = LoteProductoDAO::getByPK($l->getIdLote(), $d_producto["id_producto"]);
     if (is_null($lp)) {
         //no existe, insertar
         $loteProducto = new LoteProducto(array("id_lote" => $l->getIdLote(), "id_producto" => $d_producto["id_producto"], "cantidad" => $d_producto["cantidad"], "id_unidad" => $d_producto["id_unidad"]));
         LoteProductoDAO::save($loteProducto);
     } else {
         //ya existe, sumar
         //revisemos si es de la misma unidad
         if ($lp->getIdUnidad() == $d_producto["id_unidad"]) {
             //es igual, solo hay que sumar
             $lp->setCantidad($lp->getCantidad() + $d_producto["cantidad"]);
         } else {
             //no es igual, hay que convertir
             try {
                 $r = UnidadMedidaDAO::convertir($d_producto["id_unidad"], $lp->getIdUnidad(), $d_producto["cantidad"]);
             } 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::Actual();
     $loteEntrada = new LoteEntrada(array("id_lote" => $l->getIdLote(), "id_usuario" => 1, "fecha_registro" => time(), "motivo" => "Compra a Proveedor"));
     LoteEntradaDAO::save($loteEntrada);
     LoteEntradaProductoDAO::save(new LoteEntradaProducto(array("id_lote_entrada" => $loteEntrada->getIdLoteEntrada(), "id_producto" => $d_producto["id_producto"], "id_unidad" => $d_producto["id_unidad"], "cantidad" => $d_producto["cantidad"])));
 }
Example #2
0
{
    $ll = UnidadMedidaDAO::GetByPK($l);
    if (is_null($ll)) {
        return "ERROR";
    }
    return $ll->getAbreviacion();
}
$page->addComponent($table_e);
$table_e->addColRender("id_lote", "lotename");
$table_e->addColRender("id_unidad", "unidadname");
$page->addComponent("<hr>");
$page->addComponent(new TitleComponent("Nueva entrada", 2));
$entrada_lote = new FormComponent();
$entrada_lote->addField("id_lote", "Lote", "combobox");
//$entrada_lote->createComboBoxJoin("id_lote", "id_lote", LoteDAO::getAll(   ) );
$entrada_lote->createComboBoxJoinDistintName("id_lote", "id_lote", "folio", LoteDAO::getAll());
$entrada_lote->setHelp("id_lote", "Lote a donde se insertara este arrivo");
$entrada_lote->addField("cantidad", "Cantidad", "text");
$este_producto = ProductoDAO::GetByPK($_GET["pid"]);
$um = UnidadMedidaDAO::getByPK($este_producto->getIdUnidad());
if (!is_null($um)) {
    $entrada_lote->setHelp("cantidad", "Cantidad en " . $um->getDescripcion());
} else {
    $entrada_lote->setHelp("cantidad", "Error!");
}
$entrada_lote->addField("productos", "", "text", "\"   [ { \\\"id_producto\\\" : " . $_GET["pid"] . ", \\\"cantidad\\\"    : 0 } ]   \"");
$entrada_lote->sendHidden("productos");
$entrada_lote->makeObligatory(array("id_lote", "cantidad"));
$entrada_lote->beforeSend("beforeSendNuevaEntrada");
$entrada_lote->addApiCall("api/almacen/lote/entrada", "POST");
$page->addComponent("<script> function beforeSendNuevaEntrada(a){ \n\t\t\t\t\tconsole.log('beforeSend(' + a + ')');\n\t\t\t\t\tvar aPdec = Ext.JSON.decode(a.productos);\n\t\t\t\t\tconsole.log(aPdec);\n\t\t\t\t\taPdec[0].cantidad = a.cantidad;\n\t\t\t\t\ta.productos = Ext.JSON.encode(aPdec);\n\t\t\t\t\treturn a;\n\t\t\t\t}</script>");
Example #3
0
 /**
  *
  *buscar entre todos los lotes del sistema
  *
  * @return resultados json 
  * @return numero_de_resultados int 
  **/
 static function BuscarLote()
 {
     $lotes = LoteDAO::getAll();
     return array("resultados" => $lotes, "numero_de_resultados" => sizeof($lotes));
 }