Skip to content

Commit

Permalink
CRUD BALANZA INSUMOS RECETAS DTRECETAS
Browse files Browse the repository at this point in the history
  • Loading branch information
DanyVillaltaS committed Nov 7, 2022
1 parent 0627db8 commit d4b9bc5
Show file tree
Hide file tree
Showing 27 changed files with 3,322 additions and 2,172 deletions.
2 changes: 1 addition & 1 deletion Common.iri
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
procedure pMostrarYLimpiar(valor : string);
begin
DisplayStatus(valor);
SetTimer(1, 400);
SetTimer(1, 300);
SetTimerMode(1, TimerOneShot);
StartTimer(1);
end;
Expand Down
3 changes: 3 additions & 0 deletions Constantes.iri
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
CONST_MAX_DB_RECETA: integer := 1000;
CONST_MAX_DB_INSUMO: integer := 1000;
CONST_MAX_DB_PESAJE: integer := 1000;
CONST_MAX_DB_BALANZA: integer := 100;
CONST_MAX_DB_DETALLERECETA: integer := 1000;


CONST_RECETA_LABEL : string := "Receta";
CONST_INSUMO_LABEL : string := "Insumo";
CONST_BALANZA_LABEL : string := "Balanza";
CONST_DTRECETA_LABEL : string := "DtReceta";
136 changes: 136 additions & 0 deletions Database/Balanza.iri
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
procedure pPostBalanza(entidad : TypMantGenerico);
sql : string;
conexion : integer;
sResultado : SysCode;
id : integer;
l_Nombretabla:string:="Balanza";
begin
id := fGetNextId(l_Nombretabla,CONST_MAX_DB_BALANZA);
sql := "Insert into Balanza (Id, Numero, Nombre) values (";
sql := sql + IntegerToString(id, 0) + ",";
sql := sql + "'"+ entidad.Codigo + "', ";
sql := sql + "'" +entidad.Nombre + "')";

sResultado := DbExec(sql, conexion);
if (sResultado <> SysOk) then
pLoggerDB("pPostBalanza",DBErrMsg);
return;
end if;
--pMostrarYLimpiar("Se agrego correctamente");
end;

procedure pPutBalanza(entidad : TypMantGenerico);
sql : string;
conexion : integer;
sResultado : SysCode;

begin
sql:="Update Balanza set ";
sql:=sql + "Numero='" + entidad.Codigo+ "',";
sql:=sql + "nombre='" + entidad.Nombre + "' ";
sql:=sql + "where id="+IntegerToString(g_IdItemActual,0);

sResultado := DbExec(sql, conexion);
if (sResultado <> SysOk) then
pLoggerDB("pPutBalanza",DBErrMsg);
return;
end if;

pMostrarYLimpiar("Se actualizo con Éxito");
end;

function fGetBalanza(Id : integer) : TypBalanza;
sql : string;
conexion : integer;
sResultado : SysCode;
Balanza : TypBalanza;
begin
sql:="select * from Balanza where id = ";
sql:=sql + IntegerToString(Id, 0);

sResultado := DbExec(sql, conexion);
--Primero verificamos que la consulta sea diferente de OK. Esto es error
if(sResultado<>SysOk) then
pLoggerDB("fGetBalanza",DBErrMsg);
return Balanza;
end if;

-- Luego verificamos que la conexión sea = 0. Eso quiere decir que no hay datos para recuperar
if (conexion=0) then
return Balanza;
end if;

-- Caso contrario, tomamos los datos y los leemos.
DbColumnInt(conexion, 1, Balanza.Id);
DbColumnString(conexion, 2, Balanza.Numero);
DbColumnString(conexion, 3, Balanza.Nombre);
sResultado := DbNext(conexion);
DbFinalize(conexion);
pMostrarYLimpiar("Se obtuvo correctamente");
return Balanza;
end;



function fListaBalanza : TypArrayBalanza;
sql : string;
conexion : integer;
sResultado : SysCode;
listado : TypArrayBalanza;
indice : integer;
begin
sql := "select * from Balanza order by Id asc limit "+IntegerToString(g_ItemsPorPagina,0);
sql :=sql + " Offset "+IntegerToString(g_PaginaActual - 1, 0);

sResultado := DbExec(sql, conexion);
--Primero verificamos que la consulta sea diferente de OK. Esto es error
if(sResultado<>SysOk) then
pLoggerDB("fListaBalanza",DBErrMsg);
return listado;
end if;

-- Luego verificamos que la conexión sea = 0. Eso quiere decir que no hay datos para recuperar
if (conexion=0) then
return listado;
end if;

-- Caso contrario, tomamos los datos y los leemos.

indice := 0;
while sResultado = SysOk
loop
indice := indice +1;
DbColumnInt(conexion, 1, listado[indice].Id);
DbColumnString(conexion, 2, listado[indice].Numero);
DbColumnString(conexion, 3, listado[indice].Nombre);
sResultado := DbNext(conexion);
end loop;

DbFinalize(conexion);
--pMostrarYLimpiar("Se listo correctamente");

return listado;
end;

function fExisteCodigoBalanza (Numero:string) : BooleanType;
sql : string;
conexion : integer;
sResultado : SysCode;
cantidad :integer;
begin
sql:="select count(1) from Balanza where Numero='"+Numero+"' ";
sResultado := DbExec(sql, conexion);
if (sResultado <> SysOk or conexion = 0) then
pLoggerDB("fExisteCodigoBalanza",DBErrMsg);
return BoolTrue;

end if;

DbColumnInt(conexion,1,cantidad);
DbFinalize(conexion);
if (cantidad=0) then
return BoolFalse;
else
return BoolTrue;
end if;
end;
13 changes: 7 additions & 6 deletions Database/DtReceta.iri
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ sResultado : SysCode;
listado : TypArrayDtReceta;
indice : integer;
begin
sql := "SELECT Insumo.Codigo,Receta.Codigo, Insumo.Nombre, DtReceta.Peso, DtReceta.Activo ";
sql := "SELECT DtReceta.Id,Insumo.Codigo,Receta.Codigo, Insumo.Nombre, DtReceta.Peso, DtReceta.Activo ";
sql := sql + "FROM DtReceta INNER JOIN ";
sql := sql + "Insumo ON DtReceta.IdInsumo = Insumo.Id INNER JOIN ";
sql := sql + "Receta ON DtReceta.IdReceta = receta.Id ";
Expand All @@ -111,11 +111,12 @@ begin
while sResultado = SysOk
loop
indice := indice +1;
DbColumnString(conexion, 1, listado[indice].CodInsumo);
DbColumnString(conexion, 2, listado[indice].CodReceta);
DbColumnString(conexion, 3, listado[indice].NombreInsumo);
DbColumnReal(conexion, 4, listado[indice].Peso);
DbColumnInt(conexion, 5, listado[indice].Activo);
DbColumnInt(conexion, 1, listado[indice].Id);
DbColumnString(conexion, 2, listado[indice].CodInsumo);
DbColumnString(conexion, 3, listado[indice].CodReceta);
DbColumnString(conexion, 4, listado[indice].NombreInsumo);
DbColumnReal(conexion, 5, listado[indice].Peso);
DbColumnInt(conexion, 6, listado[indice].Activo);
sResultado := DbNext(conexion);
end loop;

Expand Down
23 changes: 20 additions & 3 deletions Database/FuncionesDB.iri
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,20 @@ begin
sql:=sql + " where id="+ IntegerToString(id,0);

sResultado := DbExec(sql, conexion);
if (sResultado <> SysOk or conexion = 0) then
if (sResultado <> SysOk) then
pLoggerDB("pDeleteItemTabla",DBErrMsg);
return;
end if;

if (conexion=0) then
pMostrarYLimpiar("No hay Datos para Mostrar");
end if;


pMostrarYLimpiar("Se eliminó con éxito el registro con Id "+IntegerToString(id,0));
end;


function fExisteDatosEnTabla (NombreTabla:string) : BooleanType;
sql : string;
conexion : integer;
Expand Down Expand Up @@ -143,12 +149,23 @@ sql : string;
conexion : integer;
sResultado : SysCode;
cantidad :integer;
campoSql : string;
l_activo : string;
begin
sql:="select count(1) from "+ NombreTabla+" where Codigo='"+Codigo+"' ";
if g_NombreMenuMantto = CONST_BALANZA_LABEL then
campoSql:="Numero";
l_activo:=" activo=1 and ";
else
campoSql:="Codigo";
l_activo:=" ";
end if;

sql:="select count(1) from "+ NombreTabla+" where" +l_activo+" "+campoSql+"='"+Codigo+"' ";
sResultado := DbExec(sql, conexion);
if (sResultado <> SysOk or conexion = 0) then
pLoggerDB("fExisteCodigoEnTabla",DBErrMsg);
--return BoolTrue;
return BoolTrue;

end if;

DbColumnInt(conexion,1,cantidad);
Expand Down
30 changes: 24 additions & 6 deletions Database/Insumo.iri
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ id : integer;
l_Nombretabla:string:="Insumo";
begin
id := fGetNextId(l_Nombretabla,CONST_MAX_DB_INSUMO);
sql := "Insert into Insumo (Id, Codigo, Nombre) values (";
sql := "Insert into Insumo (Id, Codigo, Nombre, Activo) values (";
sql := sql + IntegerToString(id, 0) + ",";
sql := sql + "'"+ entidad.Codigo + "', ";
sql := sql + "'" +entidad.Nombre + "')";
sql := sql + "'" +entidad.Nombre + "',1)";

sResultado := DbExec(sql, conexion);
if (sResultado <> SysOk) then
Expand All @@ -28,7 +28,7 @@ begin
sql:="Update Insumo set ";
sql:=sql + "codigo='" + entidad.Codigo+ "',";
sql:=sql + "nombre='" + entidad.Nombre + "' ";
sql:=sql + "where id="+IntegerToString(entidad.Id,0);
sql:=sql + "where id="+IntegerToString(g_IdItemActual,0);

sResultado := DbExec(sql, conexion);
if (sResultado <> SysOk) then
Expand Down Expand Up @@ -79,7 +79,7 @@ sResultado : SysCode;
listado : TypArrayInsumo;
indice : integer;
begin
sql := "select * from Insumo order by Id asc limit "+IntegerToString(g_ItemsPorPagina,0);
sql := "select * from Insumo where activo=1 order by Id asc limit "+IntegerToString(g_ItemsPorPagina,0);
sql :=sql + " Offset "+IntegerToString(g_PaginaActual - 1, 0);

sResultado := DbExec(sql, conexion);
Expand Down Expand Up @@ -145,7 +145,7 @@ conexion : integer;
sResultado : SysCode;
IdInsumo : integer:=0;
begin
sql:="select Id from Insumo where Codigo='"+Codigo+"' limit 1";
sql:="select Id from Insumo where Activo=1 and Codigo='"+Codigo+"' limit 1";
sResultado := DbExec(sql, conexion);
--Primero verificamos que la consulta sea diferente de OK. Esto es error
if(sResultado<>SysOk) then
Expand All @@ -164,4 +164,22 @@ begin
DbFinalize(conexion);
pMostrarYLimpiar("Se obtuvo correctamente");
return IdInsumo;
end;
end;

procedure pDesactivarItemInsumo(id:integer);
sql : string;
conexion : integer;
sResultado : SysCode;

begin
sql:="Update Insumo set Activo=0 ";
sql:=sql + " where id="+ IntegerToString(id,0);

sResultado := DbExec(sql, conexion);
if (sResultado <> SysOk or conexion = 0) then
pLoggerDB("pDesactivarItemInsumo",DBErrMsg);
return;
end if;

pMostrarYLimpiar("Se Desactivo con éxito el registro con Id "+IntegerToString(id,0));
end;
40 changes: 33 additions & 7 deletions Database/ModificacionesDB.iri
Original file line number Diff line number Diff line change
@@ -1,16 +1,42 @@
Procedure pMuestraPromptEliminar;
begin
if (g_TipoMant = tipoMantEliminar) then
if g_NombreMenuMantto = CONST_INSUMO_LABEL then
PromptUser("¿Desea Desctivar el Insumo? ");
else
PromptUser("¿Desea eliminar el registro?");
end if;
end if;
end;

Procedure pMuestraPromptEliminarItemReceta;
begin
if (g_TipoMant = tipoMantEliminarItemReceta) then
PromptUser("¿Desea eliminar el Item de la Receta?");
end if;
end;



procedure pEliminarRegistroDB(id:integer);
begin
if (g_TipoMant = tipoMantEliminar) then
PromptUser("¿Esta seguro de eliminar el registro?");
if EventKey = EnterKey then
if (g_NombreMenuMantto = CONST_RECETA_LABEL) then
if (g_NombreMenuMantto = CONST_RECETA_LABEL) then
if fCantidadItemsEnDtReceta(Id)=0 then
pDeleteItemTabla("Receta",id);
pMuestraReceta;
elsif (g_NombreMenuMantto = CONST_INSUMO_LABEL) then
pDeleteItemTabla("Insumo",id);
pMuestraInsumo;
else
pMostrarYLimpiar("Debe eliminar los Items Primero");
end if;
--pDeleteItemTabla("Receta",id);
--pMuestraReceta;
elsif (g_NombreMenuMantto = CONST_INSUMO_LABEL) then
pDesactivarItemInsumo(id);
pMuestraInsumo;
elsif (g_NombreMenuMantto = CONST_BALANZA_LABEL) then
pDeleteItemTabla("Balanza",id);
pMuestraBalanza;
end if;
end if;
end;

end;
2 changes: 1 addition & 1 deletion Database/Receta.iri
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ begin
sql:="Update Receta set ";
sql:=sql + "codigo='" + entidad.Codigo+ "',";
sql:=sql + "nombre='" + entidad.Nombre + "' ";
sql:=sql + "where id="+IntegerToString(entidad.Id,0);
sql:=sql + "where id="+IntegerToString(g_IdItemActual,0);

sResultado := DbExec(sql, conexion);
if (sResultado <> SysOk) then
Expand Down
18 changes: 18 additions & 0 deletions DatosPorDefecto.iri
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,29 @@ begin

end;

procedure pAlmacenarDatosInicialBalanza;
hayDatos: BooleanType;
begin
hayDatos:=fExisteDatosEnTabla("Balanza");
if (hayDatos=BoolTrue) then
return;
end if;
t_MantGenerico.Codigo:="B001";
t_MantGenerico.Nombre:="BALANZA GRAMERA";
pPostBalanza(t_MantGenerico);
t_MantGenerico.Codigo:="B002";
t_MantGenerico.Nombre:="BALANZA PRECISA";
pPostBalanza(t_MantGenerico);
t_MantGenerico.Codigo:="B003";
t_MantGenerico.Nombre:="BALANZA PREMIUM";
pPostBalanza(t_MantGenerico);
end;


procedure pAlmacenarDatosInicial;
begin
pAlmacenarDatosInicialReceta;
pAlmacenarDatosInicialInsumo;
pAlmacenarDatosInicialDtReceta;
pAlmacenarDatosInicialBalanza;
end;
Loading

0 comments on commit d4b9bc5

Please sign in to comment.