Tengo estas tablas:
CREATE TABLE ticket(
idticket INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
numero INTEGER,
importe DECIMAL(10,2),
fechae DATE,
horae TIME,
idsucursal INTEGER,
FOREIGN KEY (idsucursal) REFERENCES sucursal(idsucursal)
);
CREATE TABLE categoria(
idcategoria INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
descripcion VARCHAR(100)
);
CREATE TABLE marca(
idmarca INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
descripcion VARCHAR(100)
);
CREATE TABLE producto(
idproducto INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
stock INTEGER,
idmarca INTEGER,
medida VARCHAR(20),
nombre VARCHAR(100),
preciou DECIMAL(10,2),
iva DECIMAL(3,2),
idcategoria INTEGER,
pedir bool,
FOREIGN KEY (idcategoria) REFERENCES categoria(idcategoria),
FOREIGN KEY (idmarca) REFERENCES marca(idmarca)
);
CREATE TABLE clientes(
idcliente INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
idpersona INTEGER,
CUIT INTEGER,
CUIL INTEGER,
FOREIGN KEY (idpersona) REFERENCES persona(idpersona)
);
CREATE TABLE cliticket(
idcliente INTEGER,
idticket INTEGER,
FOREIGN KEY (idticket) REFERENCES ticket(idticket),
FOREIGN KEY (idcliente) REFERENCES clientes(idcliente)
);
CREATE TABLE ventas(
idticket INTEGER,
idproducto INTEGER,
cantidad DECIMAL(10,2),
FOREIGN KEY (idproducto) REFERENCES producto(idproducto),
FOREIGN KEY (idticket) REFERENCES ticket(idticket)
);
Ticket tiene los datos unicos del ticket: numero importe, etc;
ventas tendra un registro para cada producto con su id de ticket,
y cliticket tiene el cliente asociado.
Y en el boton hacer ticket(cuando ya lo vamos a emitir tengo.)
procedure TForm3.Button4Click(Sender: TObject);
var
ticket:Isucursales1.Tticket;
venta:Isucursales1.Tventa;
begin
ticket:=Isucursales1.Tticket.Create;
venta:=Isucursales1.Tventa.Create;
with ticket do
begin
numero:=ClientDataSet1.FieldByName('numero').AsInteger;
importe:=StrToFloat(StringGrid1.Cells[1,0]);
fechae:=DateToStr(Now());
horae:=TimeToStr(Now());
idsucursal:=1;
end;
GetIsucursales.hacerticket(ticket);
while not Grillaticket.DataSource.DataSet.Eof do
begin
with venta do
begin
idproducto:=Grillaticket.DataSource.DataSet['idproducto'];
cantidad:=Grillaticket.DataSource.DataSet['cantidad'];
GetIsucursales.ventas(venta);
end;
end;
end;
Porque un error que me da esto es que me inserta un registro en la tabla productos..