О как. Этот скрипт я давно уже переделывал под работу с наборами. Он где-то тут уже проскальзывал. Последняя версия такова:
Код:
-- !!!!!!!!!!!!!!!!!! ОБЯЗАТЕЛЬНО ДЕЛАЕМ БЭКАП БАЗЫ !!!!!!!!!!!!!!!!!!!!
declare
-- Номер места хранения. Берем из Разделы->Склады и магазины.
vLocID number := 2;
-- Номер кассы
vDeskNum number := 1;
-- Номер смены
vZNum number := 9999;
-- Дата закрытия смены. Заменить на нужную.
vCloseDate date := to_date('04.09.2006', 'DD.MM.YYYY');
-- Отдел. Берем из Разделы->Структура магазина/склада. Выбираем нужный отдел
-- (скорее всего это самообслуживание) и в правом окне смотрим параметр "Ид."
vDepartmentID number := 1;
i1 integer;
i2 integer;
begin
-- Чистим таблицы
delete from supermag.smcashz where locid = vLocID and desknum = vDeskNum and znum = vZNum;
delete from supermag.smcashdisccard where locid = vLocID and desknum = vDeskNum and znum = vZNum;
delete from supermag.smcashdisc where locid = vLocID and desknum = vDeskNum and znum = vZNum;
delete from supermag.smcashcredcardchecks where locid = vLocID and desknum = vDeskNum and znum = vZNum;
delete from supermag.smcashchecksprinted where locid = vLocID and desknum = vDeskNum and znum = vZNum;
delete from supermag.smcashcheckcomplexitems where locid = vLocID and desknum = vDeskNum and znum = vZNum;
delete from supermag.smcashcheckitems where locid = vLocID and desknum = vDeskNum and znum = vZNum;
delete from supermag.smcashchecks where locid = vLocID and desknum = vDeskNum and znum = vZNum;
delete from supermag.smcashcheckcomplexitems where locid = vLocID and desknum = vDeskNum and znum = vZnum;
delete from supermag.smdocprops where doctype = 'CS' and docid = 'CS' || to_char(vCloseDate, 'YYYYMMDD') || '@' || to_char(vLocID);
delete from supermag.smdocprops where doctype = 'CR' and docid = 'CR' || to_char(vCloseDate, 'YYYYMMDD') || '@' || to_char(vLocID);
-- Корректируем оперативные остатки
delete from supermag.smopergoods where locid = vLocID and desknum = vDeskNum and znum = vZNum and depid = vDepartmentID;
delete from supermag.smopergoodsscale where locid = vLocID and desknum = vDeskNum and znum = vZNum and depid = vDepartmentID;
-- Добавляем смену
insert into supermag.smcashz(locid, desknum, znum, closedate, zready, doccreated)
values (vLocID, vDeskNum, vZNum, vCloseDate, 1, 1);
-- Переносим оперативные чеки
insert into supermag.smcashchecks(locid, desknum, znum, checknum, printtime, cashier, totalsum, opcode, depid)
select o.locid, o.desknum, o.znum, o.checknum, o.printtime, o.cashier, o.totalsum, o.opcode, vDepartmentID
from supermag.smonlinechecks o
where o.locid = vLocID and o.desknum = vDeskNum and o.znum = vZNum;
-- Переносим товары из оперативных чеков
insert into supermag.smcashcheckitems(locid, desknum, znum, checknum, item, article, quantity, itemprice, totalsum, credcardbrand, seller, depid, subarticle)
select o.locid, o.desknum, o.znum, o.checknum, o.item, o.article, o.quantity, o.itemprice, o.totalsum, o.credcardbrand, o.seller, o.depid, o.subarticle
from supermag.smonlinecheckitems o
where o.locid = vLocID and o.desknum = vDeskNum and o.znum = vZNum;
-- "Разворачиваем" наборы
insert into supermag.smcashcheckcomplexitems (locid, desknum, znum, complexarticle, article, itemprice, amount, pricepercent, isdependent)
select distinct o.locid, o.desknum, o.znum, ca.complexarticle, ca.article,
-- supermag.yz.getpriceondatesm(o.locid, ca.article, vCloseDate),
(select his.price
from supermag.smpricehistory his, supermag.smlocprices prt
where his.storeloc = o.locid and his.article = ca.article
and his.pricetype = prt.pricetype and prt.locid = his.storeloc
and (bitand(prt.flags, 2) = 2)
and his.recid = (select max(h.recid)
from supermag.smpricehistory h
where h.storeloc = his.storeloc
and h.article = his.article
and h.pricetype = his.pricetype
and to_date(h.eventtime) <= vCloseDate)),
ca.amount, ca.pricepercent, ca.isdependent
from supermag.smcashcheckitems o, smcard c, supermag.smcomplexarticles ca
where o.locid = vLocID and o.desknum = vDeskNum and o.znum = vZNum and c.article = o.article and c.datatype = 5
and ca.complexarticle = c.article;
-- Ставим метку, указывающую на то, что кассовый документ не соответствует Z-отчетам
select count(*) into i1 from supermag.smdocuments d where d.doctype = 'CS' and d.id = 'CS' || to_char(vCloseDate, 'YYYYMMDD') || '@' || to_char(vLocID);
if i1 > 0 then
select count(*) into i2 from supermag.smdocprops d where d.doctype = 'CS' and d.docid = 'CS' || to_char(vCloseDate, 'YYYYMMDD') || '@' || to_char(vLocID) and d.paramname = 'Cash.Invalid';
if i2 > 0 then
update supermag.smdocprops set paramvalue = '*' where doctype = 'CS' and docid = 'CS' || to_char(vCloseDate, 'YYYYMMDD') || '@' || to_char(vLocID) and paramname = 'Cash.Invalid';
else
insert into smdocprops(doctype, docid, paramname, paramvalue) values ('CS', 'CS' || to_char(vCloseDate, 'YYYYMMDD') || '@' || to_char(vLocID), 'Cash.Invalid', '*');
end if;
end if;
select count(*) into i1 from supermag.smdocuments d where d.doctype = 'CR' and d.id = 'CR' || to_char(vCloseDate, 'YYYYMMDD') || '@' || to_char(vLocID);
if i1 > 0 then
select count(*) into i2 from supermag.smdocprops d where d.doctype = 'CR' and d.docid = 'CR' || to_char(vCloseDate, 'YYYYMMDD') || '@' || to_char(vLocID) and d.paramname = 'Cash.Invalid';
if i2 > 0 then
update supermag.smdocprops set paramvalue = '*' where doctype = 'CR' and docid = 'CR' || to_char(vCloseDate, 'YYYYMMDD') || '@' || to_char(vLocID) and paramname = 'Cash.Invalid';
else
insert into smdocprops(doctype, docid, paramname, paramvalue) values ('CR', 'CR' || to_char(vCloseDate, 'YYYYMMDD') || '@' || to_char(vLocID), 'Cash.Invalid', '*');
end if;
end if;
-- Удаляем оперативные чеки
delete from supermag.smonlinechecksprinted where locid = vLocID and desknum = vDeskNum and znum = vZNum;
delete from supermag.smonlinedisccard where locid = vLocID and desknum = vDeskNum and znum = vZNum;
delete from supermag.smonlinechecks where locid = vLocID and desknum = vDeskNum and znum = vZNum;
delete from supermag.smonlinecheckitems where locid = vLocID and desknum = vDeskNum and znum = vZNum;
commit;
commit;
end;
Прошу простить - делалось давно. Возможно чего-то еще не учел. Если надо, могу причесать и доделать.