Настройка акций в Кассире

Материал из wiki.standart-n.ru
Перейти к: навигация, поиск

Начало

В ТМС -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;

Конец

Весь сркипт заканчивается так:

  finally
   iq.active := False;
   iq.transaction.free;
   iq.free;
  end;

end;