Zero Block
Click "Block Editor" to enter the edit mode. Use layers, shapes and customize adaptability. Everything is in your hands.
Tilda Publishing
create your own block from scratch
Zero Block
Click "Block Editor" to enter the edit mode. Use layers, shapes and customize adaptability. Everything is in your hands.
Tilda Publishing
create your own block from scratch
SQL. Запити, що стосуються касових змін
Будь-які запити щодо редагування, видалення, визначення дати та номеру касової зміни.
Задля видалення\закриття касових змін потрібно:
1. Створити завдання у ПФ та вказати (СБ) виконавцем за шаблоном Чергового.
2. У задачі вказати:
  • назва закладу
  • дату проблемної зміни
3. Перевірити з клієнтом:
  • чи є в основі пізніші зміни (якщо ні, що найімовірніше застрягла черга даних на фронті)
  • чи сума продажів у бекофісі за проблемною відкритою КС з друкованим звітом, який був надрукований під час закриття КС
Дата касової зміни
Дата останньої касової зміни:
select max(date) from UserActionEvent where dtype = 'CSE'
Список змін за період:
select *
from UserActionEvent
where UserActionEvent.dtype='CSE' and
UserActionEvent.date>='20200301' and UserActionEvent.date<='20201231'
Визначити ID касової зміни
select *
від UserActionEvent
where dtype = 'CSE' and
cashregnumber in ('7') and --НОМЕР ФР
session_number in ('749') and --НОМЕР ЗМІН
date in ('20220116', '20220116'); --ДАТА
Закриття касової зміни на сервері
Визначити ID відкритої зміни
select *
from UserActionEvent
where UserActionEvent.dtype='CSE' and
UserActionEvent.closeDate is null and
UserActionEvent.date>='20100101' and UserActionEvent.date<='20211231'
Закрити КЗ
update UserActionEvent
set UserActionEvent.closeDate='20180101 23:00:00.000' -- Дата та час закриття для незачиненої касової зміни
,UserActionEvent.responsibleUser = UserActionEvent.manager
--,UserActionEvent.cashRemain=0 -- тільки якщо потрібно прибрати залишок за касовою зміною
,UserActionEvent.revision=(Select revision from DBVersion) -- Необхідно, тільки якщо РМС підключений до Чейна, інакше не провантажиться. Якщо Чейну немає, то рядок можна забрати
where UserActionEvent.dtype='CSE' and
UserActionEvent.closeDate is null and
id='' -- вставити між апострофами ID, знайдений у першому запиті
Повернути ревізію, якщо обмін зламався, а відкрити період на чейні неможливо.
update UserActionEvent 
set revision=-revision 
where revision>0 and id=''
Масове закриття касових змін
Визначити ID відкритої зміни
- Закриття КС за часом закриття останнього чека в цій КС, Кс без чеків пропускається
DECLARE @CountSession INT, @SessionId uniqueidentifier ,@i int, @y int, @datetime datetime

set @CountSession = (select count (*) from UserActionEvent where dtype = 'CSE' and session_id in
(select uae.session_id як countSession from UserActionEvent як uae LEFT OUTER JOIN OrderPaymentEvent як OP ON uae.session_id = ope.session_id
  where dtype = 'CSE' і closeDate is null and (uae.date BETWEEN '20000101' and '20210723') group by uae.session_id having count(ope.session_id) >0 ));
 
set @ i = 0;

WHILE @CountSession > @i
begin
set @SessionId = (select TOP 1 uae.session_id як countSession від UserActionEvent як uae
where dtype = 'CSE' and closeDate is null and (uae.date BETWEEN '20000101' and '20210723') group by uae.session_id having count(ope.session_id) >0 )
set @datetime = (select top 1 closeTime from OrderPaymentEvent where session_id = @SessionId order by closetime desc)

update UserActionEvent set closeDate = @datetime, responsibleUser = manager,
--cashRemain = 0, --тільки якщо необхідно прибрати залишок за касовою зміною
revision = (Select revision from DBVersion) --Необхідно, тільки якщо РМС підключений до Чейна, інакше не провантажиться. Якщо Чейну немає, то рядок можна забрати
where dtype = 'CSE' and closeDate is null and id = (select id from UserActionEvent where session_id = @SessionId and dtype = 'CSE' )
set @i = @i +1
end
Видалення касової зміни
select session_id
into session_tmp
from UserActionEvent
where dtype = 'CSE' and
cashregnumber in ('999') and --НОМЕР ФР
session_number in ('1', '2', '3') and --НОМЕРИ ЗМІН
date in ('20210523', '20210524'); --ДАТА

delete from OrderPaymentEvent
where session_id in (select session_id from session_tmp);

delete from ItemSaleEvent
where session_id in (select session_id from session_tmp);

delete from AccountingTransaction
where session_id in (select session_id from session_tmp);

delete from SalesDocument
where sessionid in (select session_id from session_tmp);

delete from SalesDocumentItem
where invoice_id not in (select id from SalesDocument);

delete from WriteoffDocument
where sessionid in (select session_id from session_tmp);

delete from WriteoffDocumentItem
where writeoffDocument_id not in (select id from WriteoffDocument);

delete from UserActionEvent
where session_id in (select session_id from session_tmp);

drop table session_tmp;

delete from OrderBonusEvent
where order_id not in (select "order" from OrderPaymentEvent);

delete from SessionRevenueEntry
where closeEvent not in (select id from UserActionEvent where dtype = 'CSE');

truncate table ATransactionSum;
Видалення залишку за касовою зміною
Скрипт визначення зміни
select * from UserActionEvent
where date between '2022-08-15' and '2022-08-15'
and dtype='CSE'
Скрипт для видалення залишку
Update UserActionEvent
set revision=( select revision from dbversion)+1,
lastModifyNode=NULL,
cashRemain=0,
sessionStartCash =0
where dtype = 'CSE' and id='D434309D-CBD7-4296-9EAA-4E3A28937F0E'