bueno como comente hace unos dias estoy en actualizacion de un pequeño punto de venta y quiero actualizar el form de facturacion, para ello utilizo un TStringGrid como detalle de factura pero la verdad es engorroso mostrar informacion en el ya lo he hecho de hecho funciona, pero he oido que todo este codigo se podria evitar si pudiera crear una tabla temporal con el componente JVMemorydataset de l aJEDi, ya logre crear la tabla y agregar elementos, pero no se como interactuar con ellos y como afectaria a mi base de produstos.
ongo el codigo que utilizo para llegar en Tsgrind Grid espero algun consejo pero de antamno muchas gracias
Código Delphi
[-]procedure TFfactura.txtcodigoExit(Sender: TObject);
var
wprecio_total:Double;
i:Integer;
wcodigomodificar,wdescripcionmodificar:string;
wventa_totalmodificada:Double;
wdescuentomodificar,wpreciomodificar:Double;
wtotalmodificar:Double;
wOK:Boolean;
begin
wcodigobarras:=Trim(Ffactura.txtcodigo.Text);
if wcodigobarras<>'' then
begin
For i:=1 to Ffactura.SGFact.RowCount-1 do
if Ffactura.SGFact.Cells[0,i] = Trim(wcodigobarras) then
begin
wOK:=True;
if wOK=True then
begin
wcantidadmodificar:=StrToFloat(SGFact.Cells[2,i]); wpreciomodificar:=StrToFloat(Ffactura.SGFact.Cells[3,i]); wcodigomodificar:=Ffactura.SGFact.Cells[0,i]; wdescripcionmodificar:=Ffactura.SGFact.Cells[1,i];
if (wcantidadmodificar<=0) and (wdescuento_considerar=0) then
begin
Ffactura.SGFact.Cells[0,cuenta] := wcodigobarras; Ffactura.SGFact.Cells[1,Cuenta]:=wdescripcionmodificar;
Ffactura.wprecio_venta:=wprecio_venta; Ffactura.SGFact.Cells[2,Cuenta]:=FloatToStr(wcantidad_venta+1);
Ffactura.SGFact.Cells[3,Cuenta]:=FloatToStr(Ffactura.wprecio_venta); Ffactura.SGFact.Cells[4,Cuenta]:='0.00'; wcantidad_venta:=1;
wdescuento_considerar:=0;
wimporte_del_descuento:=((wprecio_venta*wdescuento_considerar)/100);
wprecio_con_descuento:=(wprecio_venta-wimporte_del_descuento);
wventa_total_importe:=(wcantidad_venta * wprecio_con_descuento);
SGFact.Cells[5,Cuenta]:=FloatToStr(wventa_total_importe);
calcula_totales;
wcantidad_venta:=0;
wdescuento_considerar:=0;
Ffactura.txtcodigo.Text:='';
ffactura.txtcodigo.SetFocus;
Cuenta:=Cuenta+1;
exit;
end;
if (wcantidad_venta>=1) and (wdescuento_considerar=0) then
begin
Ffactura.SGFact.Cells[0,cuenta] := wcodigobarras; Ffactura.SGFact.Cells[1,Cuenta]:=wdescripcionmodificar; Ffactura.wprecio_venta:=wprecio_venta; Ffactura.SGFact.Cells[2,Cuenta]:=FloatToStr(wcantidad_venta+1);
Ffactura.SGFact.Cells[3,Cuenta]:=FloatToStr(Ffactura.wprecio_venta); Ffactura.SGFact.Cells[4,Cuenta]:='0.00'; wdescuento_considerar:=0;
wimporte_del_descuento:=((wprecio_venta*wdescuento_considerar)/100);
wprecio_con_descuento:=(wprecio_venta-wimporte_del_descuento);
wventa_total_importe:=(wcantidad_venta * wprecio_con_descuento);
SGFact.Cells[5,Cuenta]:=FloatToStr(wventa_total_importe);
calcula_totales;
wcantidad_venta:=0;
wdescuento_considerar:=0;
Ffactura.txtcodigo.Text:='';
ffactura.txtcodigo.SetFocus;
Cuenta:=Cuenta+1;
exit;
end;
if (wcantidad_venta>=1) and (wdescuento_considerar>0) then
begin
Ffactura.SGFact.Cells[0,cuenta] := wcodigobarras; Ffactura.SGFact.Cells[1,Cuenta]:=wdescripcionmodificar; Ffactura.wprecio_venta:=wprecio_venta; Ffactura.SGFact.Cells[2,Cuenta]:=FloatToStr(wcantidad_venta);
Ffactura.SGFact.Cells[3,Cuenta]:=FloatToStr(Ffactura.wprecio_venta); Ffactura.SGFact.Cells[4,Cuenta]:=FloatToStr(wdescuento_considerar);
wimporte_del_descuento:=((wprecio_venta*wdescuento_considerar)/100);
wprecio_con_descuento:=(wprecio_venta-wimporte_del_descuento);
wventa_total_importe:=(wcantidad_venta * wprecio_con_descuento);
SGFact.Cells[5,Cuenta]:=FloatToStr(wventa_total_importe);
calcula_totales;
wcantidad_venta:=0;
wdescuento_considerar:=0;
Ffactura.txtcodigo.Text:='';
ffactura.txtcodigo.SetFocus;
Cuenta:=Cuenta+1;
exit;
end;
Exit;
end;
end;
if wOK=False then
begin
if wcodigobarras<>'' then
begin
with Fmodulo.Qry_Temp do
begin
Close;
sql.clear;
SQL.Add('select * from articulo');
SQL.Add('where codigobarras=:Pcodigobarras');
Parameters.ParamByName('pcodigobarras').Value:=Trim(wcodigobarras);
try
open;
if not Fmodulo.Qry_Temp.IsEmpty then
begin
while not Fmodulo.Qry_Temp.Eof do
begin
If Cuenta > 1 then SGFact.RowCount := SGFact.RowCount + 1;
if (wcantidad_venta<=0) and (wdescuento_considerar=0) then
begin
Ffactura.SGFact.Cells[0,cuenta] := wcodigobarras; Ffactura.SGFact.Cells[1,Cuenta]:=(FieldByname('nombre').AsString); Ffactura.wprecio_venta:=StrToFloat(FieldByname('precioventa').AsVariant); Ffactura.SGFact.Cells[2,Cuenta]:='1';
Ffactura.SGFact.Cells[3,Cuenta]:=FloatToStr(Ffactura.wprecio_venta); Ffactura.SGFact.Cells[4,Cuenta]:='0.00'; wcantidad_venta:=1;
wdescuento_considerar:=0;
wimporte_del_descuento:=((wprecio_venta*wdescuento_considerar)/100);
wprecio_con_descuento:=(wprecio_venta-wimporte_del_descuento);
wventa_total_importe:=(wcantidad_venta * wprecio_con_descuento);
SGFact.Cells[5,Cuenta]:=FloatToStr(wventa_total_importe);
calcula_totales;
wcantidad_venta:=0;
wdescuento_considerar:=0;
Ffactura.txtcodigo.Text:='';
ffactura.txtcodigo.SetFocus;
Cuenta:=Cuenta+1;
exit;
end;
if (wcantidad_venta>=1) and (wdescuento_considerar=0) then
begin
Ffactura.SGFact.Cells[0,cuenta] := wcodigobarras; Ffactura.SGFact.Cells[1,Cuenta]:=(FieldByname('nombre').AsString); Ffactura.wprecio_venta:=StrToFloat(FieldByname('precioventa').AsVariant); Ffactura.SGFact.Cells[2,Cuenta]:=FloatToStr(wcantidad_venta);
Ffactura.SGFact.Cells[3,Cuenta]:=FloatToStr(Ffactura.wprecio_venta); Ffactura.SGFact.Cells[4,Cuenta]:='0.00'; wdescuento_considerar:=0;
wimporte_del_descuento:=((wprecio_venta*wdescuento_considerar)/100);
wprecio_con_descuento:=(wprecio_venta-wimporte_del_descuento);
wventa_total_importe:=(wcantidad_venta * wprecio_con_descuento);
SGFact.Cells[5,Cuenta]:=FloatToStr(wventa_total_importe);
calcula_totales;
wcantidad_venta:=0;
wdescuento_considerar:=0;
Ffactura.txtcodigo.Text:='';
ffactura.txtcodigo.SetFocus;
Cuenta:=Cuenta+1;
exit;
end;
if (wcantidad_venta>=1) and (wdescuento_considerar>0) then
begin
Ffactura.SGFact.Cells[0,cuenta] := wcodigobarras; Ffactura.SGFact.Cells[1,Cuenta]:=(FieldByname('nombre').AsString); Ffactura.wprecio_venta:=StrToFloat(FieldByname('precioventa').AsVariant); Ffactura.SGFact.Cells[2,Cuenta]:=FloatToStr(wcantidad_venta);
Ffactura.SGFact.Cells[3,Cuenta]:=FloatToStr(Ffactura.wprecio_venta); Ffactura.SGFact.Cells[4,Cuenta]:=FloatToStr(wdescuento_considerar);
wimporte_del_descuento:=((wprecio_venta*wdescuento_considerar)/100);
wprecio_con_descuento:=(wprecio_venta-wimporte_del_descuento);
wventa_total_importe:=(wcantidad_venta * wprecio_con_descuento);
SGFact.Cells[5,Cuenta]:=FloatToStr(wventa_total_importe);
calcula_totales;
wcantidad_venta:=0;
wdescuento_considerar:=0;
Ffactura.txtcodigo.Text:='';
ffactura.txtcodigo.SetFocus;
Cuenta:=Cuenta+1;
exit;
end;
Next;
end;
end
else
begin
Application.MessageBox('No existe Producto en almacén'+CHR(13)+'con el Código de Barras proporcionado.','Error de Búsqueda',MB_TASKMODAL+ MB_ICONERROR);
Ffactura.txtcodigo.Text:='';
Ffactura.txtcodigo.SetFocus;
Exit;
end;
except
on E:EOleException do
begin
MessageDlg(Format('Error: %s Codigo: %d', [E.Message, E.ErrorCode]), mtError, [mbOK], 0);
end;
end;
end;
end;
Exit;
end;
end;
end;