Настройка акций в Кассире
Материал из wiki.standart-n.ru
Версия от 18:02, 9 марта 2016; BeTePoK (обсуждение | вклад)
Содержание
Настройка ТМС в кассире
Начало
В ТМС -305 "После добавления позиции в чек" создаем скрипт. Начало скрипта будет таким:
uses
Graphics, Controls, Forms, Dialogs, StdCtrls,
ComCtrls, ExtCtrls, ibquery, DB, ChequeList, FR,
ScriptRes, Barcode,ZKassa, StrUtils, Windows, Classes,
IBDataBase, SysUtils, DateUtils, chequelist;
var iq: tibquery;
dsc, part_id: integer;
discount: float;
begin
Try
iq := tibquery.create(nil);
iq.transaction := CreateRT(CurrDB);
iq.transaction.starttransaction;
iq.active := False;
Примеры акций
Далее пишем скрипты акций.
Пример №1
- скидка 20% на группу "Акция"
- акция действует с 31.07.2015 по 23.08.2015
if ((date() >= StrToDate('31.07.2015')) and (date() <= StrToDate('23.08.2015'))) Then
Begin
part_id := ChequeList.ActivePID;
//запросик к базе
iq.sql.text := 'select abs(price) as price, abs(quant) as quant from vw_doc_detail_active where UPPER(mmbsh) containing ''АКЦИЯ'' and doc_id='+inttostr(ChequeList.Active.ID)+' and part_id = '+inttostr(part_id) ;
iq.active := True;
//забираем данные
if not(iq.Eof) then
begin
dsc := -0.20;
ChequeList.Active.P_Index:= ChequeList.Active.IndexByPartID(part_id);
ChequeList.Active.P_SetDiscount(abs(iq.FieldByName('price').AsFloat*iq.FieldByName('quant').AsFloat)*dsc);
end;
end;
Пример №2
- акция действует с 01.02.2016 по 29.02.2016
- Эссенциале форте Н №30 - скидка 150р. за каждую проданную упаковку
- Магне В6 форте №30 - скидка 150 р. за каждую проданную упаковку
- Фестал №40 - скидка 32 руб. за каждую проданную упаковку
- Но-Шпа № 24 - скидка 50р. за каждую проданную упаковку
- Бронхикум сироп - скидка 59 руб. за каждую проданную упаковку
- Терафлекс №100- скидка 300 руб. за каждую проданную упаковку
- Терафлекс №60 - скидка 200 руб. за каждую проданную упаковку
- Эмолиум (все формы выпуска) - скидка 350р. на каждую вторую упаковку Эмолиум в чеке.
if ((date() >= StrToDate('01.02.2016')) and (date() <= StrToDate('29.02.2016'))) Then
Begin
part_id := ChequeList.ActivePID;
//запросик к базе
iq.sql.text :=
'select UPPER(sname) as sname, quant,'+
'iif(upper(sname) containing ''ЭССЕНЦИАЛ'' and UPPER(sname) containing ''ФОРТ'' and UPPER(sname) containing ''№30'', 150*abs(quant),'+
'iif(upper(sname) containing ''МАГНЕ'' and UPPER(sname) containing ''6'' and UPPER(sname) containing ''ФОРТ'' and UPPER(sname) containing ''№30'', 150*abs(quant),'+
'iif(upper(sname) containing ''ФЕСТАЛ'' and UPPER(sname) containing ''№40'', 32*abs(quant),'+
'iif(upper(sname) containing ''ШПА'' and UPPER(sname) containing ''НО'' and UPPER(sname) containing ''№24'', 50*abs(quant),'+
'iif(upper(sname) containing ''БРОНХИКУМ'' and UPPER(sname) containing ''СИР'', 59*abs(quant),'+
'iif(upper(sname) containing ''ТЕРАФЛЕКС'' and UPPER(sname) containing ''№100'', 300*abs(quant),'+
'iif(upper(sname) containing ''ТЕРАФЛЕКС'' and UPPER(sname) containing ''№60'', 200*abs(quant),'+
'iif(upper(sname) containing ''ЭМОЛИУМ'', (SELECT 350*Iif(abs(SUM(quant)) < 2, 0, Trunc(abs(Sum(quant))/2)) from vw_doc_detail_active where upper(sname) containing ''ЭМОЛИУМ'' and doc_id='+inttostr(ChequeList.Active.ID)+') ,'+
'0)))))))) as dop_dsc '+
'from vw_doc_detail_active where '+
'((upper(sname) containing ''ЭССЕНЦИАЛ'' and UPPER(sname) containing ''ФОРТ'' and UPPER(sname) containing ''№30'') or '+
' (upper(sname) containing ''МАГНЕ'' and UPPER(sname) containing ''6'' and UPPER(sname) containing ''ФОРТ'' and UPPER(sname) containing ''№30'') or '+
' (upper(sname) containing ''ФЕСТАЛ'' and UPPER(sname) containing ''№40'') or '+
' (upper(sname) containing ''ШПА'' and UPPER(sname) containing ''НО'' and UPPER(sname) containing ''№24'') or '+
' (upper(sname) containing ''БРОНХИКУМ'' and UPPER(sname) containing ''СИР'') or '+
' (upper(sname) containing ''ТЕРАФЛЕКС'' and UPPER(sname) containing ''№100'') or '+
' (upper(sname) containing ''ТЕРАФЛЕКС'' and UPPER(sname) containing ''№60'') or '+
' (upper(sname) containing ''ЭМОЛИУМ'') ) and '+
' doc_id='+inttostr(ChequeList.Active.ID)+' and part_id = '+inttostr(part_id) ;
iq.active := True;
//забираем данные
if not(iq.Eof) then
begin
If (POS('ЭМОЛИУМ',iq.FieldByName('sname').AsString) <> 0) Then
Begin
for I := 0 to chequelist.count - 1 do
for j := 0 to chequelist.items[i].count - 1 do
begin
chequelist.items[i].p_index := j;
if (POS('ЭМОЛИУМ',AnsiUpperCase(chequelist.items[i].p_name)) <> 0) then
chequelist.items[i].P_SetDiscount(0);
end;
End;
ChequeList.Active.P_Index:= ChequeList.Active.IndexByPartID(part_id);
ChequeList.Active.P_SetDiscount(-1*iq.FieldByName('dop_dsc').AsFloat)
end;
end;
Пример 3
- акция действует с 01.03.2016 по 31.12.2016
- Магне В6 форте розн цена 849р, скидка150р
- Эссенциале форте №30 розн цена 798р, скидка 150р
- Фестал тб №40 розн цена 252р, скидка 32руб
if ((date() >= StrToDate('01.03.2016')) and (date() <= StrToDate('31.12.2016'))) Then
Begin
part_id := ChequeList.ActivePID;
//запросик к базе
iq.sql.text := 'select UPPER(sname) as SNAME, abs(quant) as quant from vw_doc_detail_active where'+
'( ((UPPER(sname) containing ''МАГНЕ'' and UPPER(sname) containing ''6'' and UPPER(sname) containing ''ФОРТ'') and abs(price - 849) <= 10 ) or '+
' ((UPPER(sname) containing ''ЭССЕНЦИАЛЕ'' and UPPER(sname) containing ''30'' and UPPER(sname) containing ''ФОРТ'') and abs(price - 798) <= 10 ) or '+
' ((UPPER(sname) containing ''ФЕСТАЛ'' and UPPER(sname) containing ''40'') and abs(price - 252) <= 10 ) )'+
' and doc_id='+inttostr(ChequeList.Active.ID)+' and part_id = '+inttostr(part_id) ;
iq.active := True;
//забираем данные
if not(iq.Eof) then
begin
ChequeList.Active.P_Index:= ChequeList.Active.IndexByPartID(part_id);
If (POS('ФЕСТАЛ',iq.FieldByName('sname').AsString) = 0) Then ChequeList.Active.P_SetDiscount(-1*150*iq.FieldByName('quant').AsFloat)
Else ChequeList.Active.P_SetDiscount(-1*32*iq.FieldByName('quant').AsFloat);
end;
end;
Пример №4
- акция действует всегда пока включен переключатель в параметрах системы
INSERT INTO PARAMS ( PARENT_ID, PARAM_ID, PARAM_CAPTION, PARAM_TYPE, PARAM_VALUE, AUDIT_ID, IMAGEINDEX,
STATUS, INSERTDT, SORTING, PARAM_TYPE_DATA, PACKET) VALUES ( -30, 'AKCCII_TOGGLE', 'Включение акций', 14, '0', 3229, NULL, 0, '19-DEC-2015 10:45:34.828', NULL, 'FIXEDITEMS SHOWONLYVALUES RETURNNAME
0=выключено
1=включено');
<\PRE>
* если переключатель включен - в кассире при продаже активируется скидка = разнице между заполненными колонками price и ещё одной ценовой колонкой, ниже использована PRICE_R
<PRE>
iq.sql.text := 'select wb.part_id,wb.PRICE_R,(select p.param_value from params p where p.param_id = ''AKCCII_TOGGLE'') from vw_warebase wb where wb.part_id = '+
IntToStr(ChequeList.ActivePID);
iq.active := True;
if not(iq.Eof) then
if ( not iq.FieldByName('param_value').AsInteger=0 )then
if ( not iq.FieldByName('PRICE_R').isNull )then
if (iq.FieldByName('PRICE_R').AsFloat>0) then begin
ChequeList.Active.P_Index := ChequeList.Active.IndexByPartID(iq.FieldByName('part_id').AsInteger);
temp := -(ChequeList.Active.P_Price - iq.FieldByName('PRICE_R').AsFloat);
ChequeList.Active.P_SetDiscount(temp);
end;
Конец
Весь сркипт заканчивается так:
finally iq.active := False; iq.transaction.free; iq.free; end; end;
Отправка ТМС по синхронизации
Выгружаем тмс из базы из blob поля в файл
Тмс можно найти спомощью запроса:
select * from groups g where g.id=-305
Затем сохраняем на жесткий диск тмс из поля data.
Загружаем ТМС в серверную базу
- В таблице g$profiles выбираем blob поле, которое будем использовать для отправки, например TMP_BLOB1.
- Убеждаемся, что данная таблица синхронизируется в двухстороннем направлении.
- Загружаем в это поле например первому профилю наш ТМС скрипт.
- Ждем когда это обновление придет всем по синхронизации.
Применяем всем ТМС
По g$tasks отправляем запрос нужным профилям:
update groups gp set gp.data = (select g.tmp_blob1 from G$PROFILES g where g.id = 1) where gp.id = -305;