Código Delphi [-]
fmodulo.tDetalle.Insert;
fmodulo.tDetalle['idventa']:= fmodulo.tVentas['idventa'];
fmodulo.tDetalle['idproducto'] := fmodulo.qProductos['idproducto'] ;
fmodulo.tDetalle['cantidad'] := StrToInt(self.eCantidad.Text);
fmodulo.tDetalle['precio'] := fmodulo.qProductos['precio_unit'] ;
fmodulo.tDetalle['subtotal'] := fmodulo.tDetalle['precio']*StrToInt(eCantidad.Text) ;
fmodulo.tDetalle.Post;
fmodulo.tVentas.Edit;
fmodulo.tVentas['total']:= fmodulo.tVentas['total'] + fmodulo.tDetalle['subtotal'];
fmodulo.tVentas.Post;
fmodulo.tVentas.Insert;
fmodulo.tVentas['total']:= 0;
fmodulo.tVentas.Post;
fmodulo.tDetalle['idventa']:= fmodulo.tVentas['idventa'];
fmodulo.tVentas.Insert;
fmodulo.tVentas['total']:= 0;
//aqui llenar los demas campos de tu tabla
//maxId debe tener el ultimo id de venta + 1
fmodulo.tVentas['idventa']:= maxId;
//fmodulo.tVentas['campo1']:= valor1;
//fmodulo.tVentas['campo2']:= valor2;
//asi con todos tus campos
fmodulo.tVentas.Post;
fmodulo.tVentas['total']:= 0;
//maxId debe tener el ultimo id de venta + 1
fmodulo.tVentas['idventa']:= maxId;
fmodulo.tDetalle['idventa']:= fmodulo.tVentas['idventa'];
fmodulo.tVentas.Insert;
fmodulo.tVentas['total']:= 0;
fmodulo.tVentas.Post;
fmodulo.tDetalle.Insert;
fmodulo.tDetalle['idventa']:= fmodulo.tVentas['idventa'];
showmessage(fmodulo.tVentas['idventa'].asstring);
fmodulo.tDetalle.Insert;
fmodulo.tDetalle['idventa']:= fmodulo.tVentas['idventa'];
fmodulo.tVentas.Insert;
fmodulo.tVentas['total']:= 0;
fmodulo.tVentas['idVenta']:= 1;
fmodulo.tVentas.Post;
fmodulo.tVentas['idVenta']:= 1;
procedure TfVentas.bNuevoClick(Sender: TObject);
begin
fmodulo.qProductos.Active:= true;
fmodulo.qProductos.ParamByName('razon').AsString := '%';
fmodulo.qProductos.Refresh;
tfListadosProductos.ShowForm(true);
end;
procedure TfPrincipal.Nueva1Click(Sender: TObject);
begin
fmodulo.deta.Active:=true;
fModulo.tVentas.Active:= true ;
fmodulo.tVentas.Insert;
fVentas := tfVentas.Create(self) ;
fmodulo.tVentas['totalventa'] :=0;
fVentas.ShowModal;
end;
procedure TfVentas.bAceptarClick(Sender: TObject);
begin
fmodulo.tVentas.Edit;
fmodulo.deta.Edit;
fmodulo.qFecha.Open;
fmodulo.tVentas['fechavent'] := fmodulo.qFecha['fecha'];
fmodulo.tVentas['horavent']:= fmodulo.qFecha['hora'] ;
fmodulo.tVentas['idcliente'] := idcliente;
fmodulo.deta.Post;
fmodulo.qFecha.Active := false;
fmodulo.tVentas.Post;
//self.close
end;
procedure TfPrincipal.Nueva1Click(Sender: TObject);
begin
fmodulo.deta.Active:=true;
fModulo.tVentas.Active:= true ;
fmodulo.tVentas.Insert;
fVentas := tfVentas.Create(self) ;
fmodulo.tVentas['totalventa'] :=0;
fmodulo.tVentas.Post;//<-----------------------------AQUI
fVentas.ShowModal;
end;
fmodulo.tVentas.Post;
self.close
procedure TfVentas.bAceptarClick(Sender: TObject);
begin
fmodulo.tVentas.Edit;
fmodulo.deta.Edit;
fmodulo.qFecha.Open;
fmodulo.tVentas['fechavent'] := fmodulo.qFecha['fecha'];
fmodulo.tVentas['horavent']:= fmodulo.qFecha['hora'] ;
fmodulo.tVentas['idcliente'] := idcliente;
fmodulo.deta.Post;
fmodulo.qFecha.Active := false;
fmodulo.tVentas.Post;;
procedure TfListadosProductos.bSeleccionarClick(Sender: TObject);
begin
if (self.eCantidad.Text= '') or (self.eCantidad.Text = '0') then
begin
application.MessageBox('debe selecionar una cantidad','Venta',MB_OK) ;
self.ModalResult:= mrNone;
end
else
fmodulo.qVentas.ApplyUpdates ;
fmodulo.qdetalle.ApplyUpdates ;
fmodulo.qdetalle.Insert;
fmodulo.qdetalle['idventa']:= fmodulo.qVentas['idventa'];
fmodulo.qdetalle['idproducto'] := fmodulo.qProductos['idproducto'] ;
fmodulo.qdetalle['cantvent'] := StrToInt(self.eCantidad.Text);
fmodulo.qdetalle['preciovent'] := fmodulo.qProductos['precio_unit'] ;
fmodulo.qdetalle['subtotalvent'] := fmodulo.qdetalle['preciovent']*StrToInt(eCantidad.Text) ;
//Tabla ventas
fmodulo.tVentas.Edit;
fmodulo.tVentas['totalventa']:= fmodulo.tVentas['totalventa'] + fmodulo.qdetalle['subtotalvent'];
fmodulo.qdetalle.Post;
fmodulo.tVentas.Post;
end;