Решил "через сидячее место", но работает.
Правда, записей пока мало, и что будет дальше - неизвестно.
Создал таблицу
Код:
CREATE TABLE `ploskie_ch` (
`store` varchar(100) NOT NULL DEFAULT '',
`cash_number` int(11) NOT NULL DEFAULT '0',
`cash_id` int(11) NOT NULL DEFAULT '0',
`local_number` bigint(20) unsigned NOT NULL DEFAULT '0',
`type` bigint(20) unsigned DEFAULT NULL,
`date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`result` bigint(20) unsigned DEFAULT NULL,
`link_receipt` bigint(20) unsigned DEFAULT NULL,
`link_cash_id` bigint(20) unsigned DEFAULT NULL,
`id_ch` bigint(20) unsigned NOT NULL DEFAULT '0',
`item` varchar(40) NOT NULL DEFAULT '',
`name` varchar(100) NOT NULL DEFAULT '',
`quantity` decimal(20,4) DEFAULT NULL,
`price` decimal(20,4) NOT NULL DEFAULT '0.0000',
`id_item` bigint(20) unsigned NOT NULL DEFAULT '0',
`skid_r` decimal(20,4) NOT NULL DEFAULT '0.0000',
`fio` varchar(40) NOT NULL DEFAULT '',
PRIMARY KEY (`cash_id`,`id_ch`,`id_item`),
KEY `idx1` (`store`),
KEY `idx2` (`cash_number`),
KEY `idx3` (`type`),
KEY `idx4` (`date`),
KEY `idx5` (`result`),
KEY `idx6` (`id_item`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AVG_ROW_LENGTH=76;
На receipt_item подвесил триггер:
Код:
CREATE DEFINER = 'root'@'%' TRIGGER `receipt_item_after_ins_tr` AFTER INSERT ON `receipt_item`
FOR EACH ROW
BEGIN
set @r_cash_number := (select r.cash_number from `receipt` r where r.cash_id=NEW.cash_id and r.id=NEW.receipt_header);
set @r_local_number := (select r.local_number from `receipt` r where r.cash_id=NEW.cash_id and r.id=NEW.receipt_header);
set @r_type := (select r.type from `receipt` r where r.cash_id=NEW.cash_id and r.id=NEW.receipt_header);
set @r_date := (select r.date from `receipt` r where r.cash_id=NEW.cash_id and r.id=NEW.receipt_header);
set @r_result := (select r.result from `receipt` r where r.cash_id=NEW.cash_id and r.id=NEW.receipt_header);
set @r_link_receipt := (select r.link_receipt from `receipt` r where r.cash_id=NEW.cash_id and r.id=NEW.receipt_header);
set @r_link_cash_id := (select r.link_cash_id from `receipt` r where r.cash_id=NEW.cash_id and r.id=NEW.receipt_header);
insert into ploskie_ch (store,cash_number,cash_id,local_number,type,date,result,link_receipt,link_cash_id,
id_ch,item,name,quantity,price,id_item) values (NEW.store,@r_cash_number,NEW.cash_id,@r_local_number,
@r_type,@r_date,@r_result,@r_link_receipt,@r_link_cash_id,NEW.receipt_header,NEW.item,NEW.name,
NEW.quantity,NEW.price,NEW.id);
END;
и на receipt_item_discount:
Код:
CREATE DEFINER = 'root'@'%' TRIGGER `receipt_item_discount_after_ins_tr` AFTER INSERT ON `receipt_item_discount`
FOR EACH ROW
BEGIN
if NEW.increment<>0 then
update ploskie_ch pp set pp.skid_r=NEW.increment where
pp.`cash_id` = NEW.cash_id and
pp.`id_item` = NEW.receipt_item;
end if;
END;
и на receipt_item_properties:
Код:
CREATE DEFINER = 'root'@'%' TRIGGER `receipt_item_properties_after_ins_tr` AFTER INSERT ON `receipt_item_properties`
FOR EACH ROW
BEGIN
if NEW.display_name="Консультант" then
update ploskie_ch pp set pp.`fio`=NEW.value where
pp.`cash_id` = NEW.cash_id and
pp.`id_item` = NEW.receipt_item;
end if;
END;
Не самое изящное решение, но пока работает!!!