OnTimer
A script to create a pre-order discount
On the order editing form, insert the script in the OnTimer event:
procedure userTimer1OnTimer(Sender: TObject);
var CheckView: TCheckView;
begin
// Checking for correct receipt
CheckView := TCheckView(GUI.FindComponentByName('CheckView'));
if CheckView = Nil then Exit;
if not RKCheck.Valid then Exit;
if (GUI.CheckFormInPayMode) then exit;
if RKCheck.CurrentOrder.IsEmpty then exit;
AddEveryOtherDiscount(10); // specify the code of open amount discount for the order
end;
Above this script, place the function for recalculating the previously created open amount discount for the order:
procedure AddEveryOtherDiscount(DiscCode: integer);
var i, j: integer;
it, CurItem: TCheckItem;
a, BaseSum, discsum, DiscPerc: double;
d: TDish;
CheckView: TCheckView;
ed: TObject;
Time1: TDateTime;
begin
//************************** Set parameters **********************************//
DiscPerc := 10; // %
//************************** Set parameters **********************************//
discsum := 0;
BaseSum := 0;
CheckView := TCheckView(GUI.FindComponentByName('CheckView'));
if CheckView = Nil then Exit;
CurItem := RKCheck.CurrentCheckItem;
try
for i := 0 to RKCheck.CurrentOrder.Sessions.LinesCount - 1 do
begin
it := RKCheck.CurrentOrder.Sessions.Lines[i];
if SYS.ObjectInheritsFrom(TObject(it), 'TDish') then //Check dish lines only
if (RKCheck.CurrentOrder.StartService >= (TDish(it).Session.StartService)) then
// if ((it.State = disOpened) or (it.State = disPrinted)) then
begin
if (TDish(it).Quantity > 0) then
begin
BaseSum := BaseSum + TDish(it).PRListSum;
end;
end;
end;
begin
a:= BaseSum*DiscPerc/100;
// Delete discount, if a sum changed
for j := RKCheck.CurrentOrder.Sessions.LinesCount - 1 downto 0 do
begin
it := RKCheck.CurrentOrder.Sessions.Lines[j];
if SYS.ObjectInheritsFrom(TObject(it), 'TDiscountItem') then //Check dish lines only
if (it.Code = DiscCode) then
begin
if abs(TDiscountItem(it).SrcAmount) = a then a := 0
else
begin
if not(TDiscountItem(it).State = disOpened) then
begin
RKCheck.DeleteCheckItem(it); // Delete discount, if a sum changed
end
else
begin
if it <> Nil then CheckView.GotoItem(it);
ed := TObject(gui.FindComponentByName('Editor'));
TNumEditor(ed).Text := FloatToStr(a);
RK7.PerformOperation(rkoEditOpenPrice, 0); // change discount, if a sum changed
a := 0;
end;
end
break;
end;
end;
// Create discount to a dish
if a > 0 then
begin
RKCheck.CreateCheckItem(rkrefDiscounts, IntToStr(DiscCode), FloatToStr(a));
end;
end;
finally
if CurItem <> Nil then CheckView.GotoItem(CurItem);
end;
RKCheck.CurrentOrder.Recalc();
end;
A script to add modifiers automatically
Place a timer on the receipt editing form and specify it in its OnTimer event:
procedure userTimer1OnTimer(Sender: TObject);
But above this procedure insert the following:
procedure SliceStrToStrings(StrIn,marker:String; var StringsOut:TStringList);
As a result, you should get the following listing:
procedure SliceStrToStrings(StrIn,marker:String; var StringsOut:TStringList);
var s,s1:string; i:Integer;
begin
s:=StrIn;
while length(s)<>0 do begin
i:=pos(marker,s);
if i=0 then begin
s1:=s;
delete(s,1,length(s1));
StringsOut.Add(s1);
end
else begin
s1:=copy(s,1,i-1);
delete(s,1,i);
StringsOut.Add(s1)
end;
end;
end;
procedure userTimer1OnTimer(Sender: TObject);
var i, j, k, z, p, linenum: integer;
it,it2,CurItem: TCheckItem;
CheckView: TCheckView;
SL,SLtmp: TStringList;
str: string;
ModifPresent: boolean;
begin
// Checking for correct receipt
CheckView := TCheckView(GUI.FindComponentByName('CheckView'));
if CheckView = Nil then Exit;
if not RKCheck.Valid then Exit;
if (GUI.CheckFormInPayMode) then exit;
if SYS.ObjectInheritsFrom(RKCheck.CurrentCheckItem, 'TPrintCheckItem') then Exit;
CurItem := RKCheck.CurrentCheckItem;
SL := TStringList.Create;
SL.Clear;
SL.Sorted := false;
// serch and remember modificators
for i := 0 to RKCheck.CurrentOrder.Sessions.LinesCount - 1 do
begin
it := RKCheck.CurrentOrder.Sessions.Lines[i];
if SYS.ObjectInheritsFrom(it, 'TDish') then
if TDish(it).Modifiers.Count > 0 then
begin
str := inttostr(i)+'=';
for j := 0 to TDish(it).Modifiers.Count - 1 do // checking by modifier
begin
str := str+IntToStr(TDish(it).Modifiers.Items[j].Code)+';';
end;
SL.Add(str);
end;
end;
// adding modificators
for i := 0 to SL.Count - 1 do
begin
SLtmp := TStringList.Create;
SLtmp.Clear;
SLtmp.Sorted := false;
p := pos('=',SL.strings[i]);
linenum := StrToInt(copy(SL.strings[i],1,p-1));
SliceStrToStrings(copy(SL.strings[i],p+1,length(SL.strings[i])-p),';',SLtmp);
//dbg.dbgprint(' '+SL.strings[i]+' '+IntToStr(linenum)+ ' ' +copy(SL.strings[i],p+1,length(SL.strings[i])-p));
// cycle for dish
for j := 0 to RKCheck.CurrentOrder.Sessions.LinesCount - 1 do
if linenum <= j then
begin
it2 := RKCheck.CurrentOrder.Sessions.Lines[j];
if SYS.ObjectInheritsFrom(it2, 'TDish') then
begin
// cycle for remember modifiers
for k := 0 to SLtmp.Count - 1 do
begin
ModifPresent := False;
// cycle for dish modifiers
for z := 0 to TDish(it2).Modifiers.Count - 1 do // checking by modifier
begin
if TDish(it2).Modifiers.Items[z].Code = StrToInt(SLtmp.strings[k]) then
ModifPresent := True;
end;
if not(ModifPresent) then
begin
//dbg.dbgprint('add modif '+SLtmp.strings[k]+' to dish '+TDish(it2).Name);
CheckView.GotoItem(it2);
RKCheck.CreateCheckItem(rkrefModifiers, SLtmp.strings[k], '1'); // add modificator
end;
end;
end;
end;
SLtmp.Free();
end;
SL.Free();
if CurItem <> Nil then CheckView.GotoItem(CurItem);
end;
The previous script, which does not add all the modifiers of the previous dish but only the last modifier within the range of codes from 46 to 53.
procedure SliceStrToStrings(StrIn,marker:String; var StringsOut:TStringList);
var s,s1:string; i:Integer;
begin
s:=StrIn;
while length(s)<>0 do begin
i:=pos(marker,s);
if i=0 then begin
s1:=s;
delete(s,1,length(s1));
StringsOut.Add(s1);
end
else begin
s1:=copy(s,1,i-1);
delete(s,1,i);
StringsOut.Add(s1)
end;
end;
end;
procedure userTimer1OnTimer(Sender: TObject);
var i, j, k, z, p, linenum1,linenum2, ModifCodeLimit1,ModifCodeLimit2: integer;
it,it2,CurItem: TCheckItem;
CheckView: TCheckView;
SL,SLtmp: TStringList;
str: string;
ModifPresent: boolean;
begin
ModifCodeLimit1 := 1; //46;
ModifCodeLimit2 := 53;
// Ïðîâåðêà íà êîððåêòíûé ÷åê
CheckView := TCheckView(GUI.FindComponentByName('CheckView'));
if CheckView = Nil then Exit;
if not RKCheck.Valid then Exit;
if (GUI.CheckFormInPayMode) then exit;
if SYS.ObjectInheritsFrom(RKCheck.CurrentCheckItem, 'TPrintCheckItem') then Exit;
CurItem := RKCheck.CurrentCheckItem;
SL := TStringList.Create;
SL.Clear;
SL.Sorted := false;
// serch and remember modificators
for i := 0 to RKCheck.CurrentOrder.Sessions.LinesCount - 1 do
begin
it := RKCheck.CurrentOrder.Sessions.Lines[i];
if SYS.ObjectInheritsFrom(it, 'TDish') then
if TDish(it).Modifiers.Count > 0 then
begin
str := inttostr(i)+'=';
for j := TDish(it).Modifiers.Count - 1 downto 0 do // checking by modifier
if (TDish(it).Modifiers.Items[j].Code >= ModifCodeLimit1)and(TDish(it).Modifiers.Items[j].Code <= ModifCodeLimit2) then // select range code
begin
str := str+IntToStr(TDish(it).Modifiers.Items[j].Code)+';';
SL.Add(str);
break;
end;
end;
end;
// adding modificators
for i := 0 to SL.Count - 1 do
begin
SLtmp := TStringList.Create;
SLtmp.Clear;
SLtmp.Sorted := false;
p := pos('=',SL.strings[i]);
linenum1 := StrToInt(copy(SL.strings[i],1,p-1));
if i+1 > SL.Count - 1 then
linenum2 := RKCheck.CurrentOrder.Sessions.LinesCount - 1
else
linenum2 := StrToInt(copy(SL.strings[i+1],1,p-1));
SliceStrToStrings(copy(SL.strings[i],p+1,length(SL.strings[i])-p),';',SLtmp);
// cycle for dish
for j := linenum1 to linenum2 do
// if linenum1 <= j then
begin
it2 := RKCheck.CurrentOrder.Sessions.Lines[j];
if SYS.ObjectInheritsFrom(it2, 'TDish') then
begin
// cycle for remember modifiers
for k := 0 to SLtmp.Count - 1 do
begin
ModifPresent := False;
// cycle for dish modifiers
for z := TDish(it2).Modifiers.Count - 1 downto 0 do // checking by modifier
begin
if (TDish(it2).Modifiers.Items[z].Code >= ModifCodeLimit1)and(TDish(it2).Modifiers.Items[z].Code <= ModifCodeLimit2) then
ModifPresent := True;
end;
if not(ModifPresent) then
begin
CheckView.GotoItem(it2);
RKCheck.CreateCheckItem(rkrefModifiers, SLtmp.strings[k], '1'); // add modificator
end;
end;
end;
end;
SLtmp.Free();
end;
SL.Free();
if CurItem <> Nil then CheckView.GotoItem(CurItem);
end;
When adding one modifier of the specified range of codes, the script removes all other current dish modifiers from this range:
procedure CheckViewOnBeforeCheckViewEdit(Sender: TObject; AEditType: TEditType; AObjectBef, AObjectAft: TObject; var AAllow: boolean; var AMessage: string);
var j,ModifCodeLimit1,ModifCodeLimit2: integer;
begin
ModifCodeLimit1 := 46;
ModifCodeLimit2 := 53;
if SYS.ObjectInheritsFrom(AObjectAft, 'TModiItem') then
if (TModiItem(AObjectAft).code >= ModifCodeLimit1)and(TModiItem(AObjectAft).code <= ModifCodeLimit2) then
begin
for j := TDish(RKCheck.CurrentCheckItem).Modifiers.Count - 1 downto 0 do // checking by modifier
if (TDish(RKCheck.CurrentCheckItem).Modifiers.Items[j].Code >= ModifCodeLimit1)and(TDish(RKCheck.CurrentCheckItem).Modifiers.Items[j].Code <= ModifCodeLimit2) then // select range code
RKCheck.DeleteCheckItem(TModiItem(TDish(RKCheck.CurrentCheckItem).Modifiers.Items[j]));
end;
end;
A script to add dishes for a certain type of order
On the order editing form, add a timer and specify a script for it:
procedure userTimer1OnTimer(Sender: TObject);
var i,CntDish1,OrderTypeCode,DishCode:integer;
it: TCheckItem;
begin
//************************** Set parameters **********************************//
DishCode := 220;
OrderTypeCode := 1; // order type code
//************************** Set parameters **********************************//
// Checking for correct receipt
if not RKCheck.Valid then Exit;
if (GUI.CheckFormInPayMode) then exit;
if SYS.ObjectInheritsFrom(RKCheck.CurrentCheckItem, 'TPrintCheckItem') then Exit;
if (RKCheck.CurrentOrder.OrderTypeCode = OrderTypeCode) then // for different OrderTypeCode
if RKCheck.CurrentOrder.UserTag1 = 0 then
begin
CntDish1 := 0;
for i := 0 to RKCheck.CurrentOrder.Sessions.LinesCount - 1 do
begin
it := RKCheck.CurrentOrder.Sessions.Lines[i];
if SYS.ObjectInheritsFrom(it, 'TDish') then
if (TDish(it).quantity > 0) then
CntDish1 := CntDish1 + trunc(TDish(it).Quantity);
end;
if CntDish1<>0 then RKCheck.CurrentOrder.UserTag1 := 2;
if CntDish1=0 then
begin
RKCheck.CurrentOrder.UserTag1 := 1;
RKCheck.CreateCheckItem(rkrefMenuItems, IntToStr(DishCode), inttostr(1)); // add dish
end;
end;
end;
A script to track receipt totals within money ranges
It is necessary to display a message every time the limit is exceeded and not to display it again until the next limit is exceeded.
The following script works correctly until the receipt is printed. At this moment, untimely messages begin to appear.
procedure userTimerSumLimitOnTimer(Sender: TObject);
var ToPaySum, SumInterval : double;
tt : TTimer;
begin
//14-09-16 Show message and open selector when order reaches every 200 rubles
//if (TRK7Restaurant(RK7.CashGroup.MainParent).Code = 6)
if not RKCheck.Valid then Exit;
if (GUI.CheckFormInPayMode) then
exit;
if SYS.ObjectInheritsFrom(RKCheck.CurrentCheckItem, 'TPrintCheckItem') then Exit;
begin
if (TRK7Restaurant(RK7.CashGroup.MainParent).Code <> 294)
and (TRK7Restaurant(RK7.CashGroup.MainParent).Code <> 293)
and (TRK7Restaurant(RK7.CashGroup.MainParent).Code <> 172)
and (TRK7Restaurant(RK7.CashGroup.MainParent).Code <> 9053)
and (TRK7Restaurant(RK7.CashGroup.MainParent).Code <> 240)
and (TRK7Restaurant(RK7.CashGroup.MainParent).Code <> 190)
and (TRK7Restaurant(RK7.CashGroup.MainParent).Code <> 116)
and (TRK7Restaurant(RK7.CashGroup.MainParent).Code <> 113)
and (TRK7Restaurant(RK7.CashGroup.MainParent).Code <> 9017)
and (TRK7Restaurant(RK7.CashGroup.MainParent).Code <> 67)
and (TRK7Restaurant(RK7.CashGroup.MainParent).Code <> 24)
then
begin
SumInterval := 200;
ToPaySum := RKCheck.CurrentOrder.ToPaySum;
if RKCheck.CurrentOrder.UserTag1 = 0 then
RKCheck.CurrentOrder.UserTag1 := trunc(SumInterval);
if (ToPaySum >= RKCheck.CurrentOrder.UserTag1) and (RKCheck.CurrentOrder.UserTag1 >= SumInterval) then
begin
RKCheck.CurrentOrder.UserTag1 := trunc(ToPaySum / SumInterval)*SumInterval +SumInterval;
gui.ShowMessage(' «Take a snack/dessert at a special price! (49 rub.)» ');
RK7.PostOperation(rkoTableSelector, 147);
end;
if (ToPaySum <= (RKCheck.CurrentOrder.UserTag1)) and (RKCheck.CurrentOrder.UserTag1 >= SumInterval) then // ???? ????? ???? ?????????? ???? ??????
begin
RKCheck.CurrentOrder.UserTag1 := trunc(ToPaySum / SumInterval)*SumInterval +SumInterval;
end;
end;
end;
//14-09-16 Show message and open selector when order reaches every 200 rubles
end;
A script to add or remove dishes at a certain order amount
On the order editing form, place the "TTimer?" object, naming it "userTimerSumLimit". In the properties of this object, set the trigger interval (1000 is set by default, which corresponds to 1 second). In the OnTimer event, specify the script:
procedure userTimerSumLimitOnTimer(Sender: TObject);
var ToPaySum, SumInterval : double;
tt : TTimer;
i, j: integer;
it: TCheckItem;
DiscCode, DishCode, CntDish1: integer;
begin
SumInterval := 700; // limit receipt total upon reaching which the dish is added automatically
DishCode := 43; // special dish code automatically added dish code
CntDish1 := 0;
if not RKCheck.Valid then Exit;
if (GUI.CheckFormInPayMode) then exit;
if SYS.ObjectInheritsFrom(RKCheck.CurrentCheckItem, 'TPrintCheckItem') then Exit;
begin
ToPaySum := RKCheck.CurrentOrder.ToPaySum;
for i := 0 to RKCheck.CurrentOrder.Sessions.LinesCount - 1 do
begin
it := RKCheck.CurrentOrder.Sessions.Lines[i];
if SYS.ObjectInheritsFrom(it, 'TDish') then
if (TDish(it).Code = DishCode) then
CntDish1 := CntDish1 + trunc(TDish(it).Quantity);
end;
if ToPaySum < SumInterval then // deleting a dish when the receipt total is less than specified
if CntDish1 > 0 then
begin
for j := RKCheck.CurrentOrder.Sessions.LinesCount - 1 downto 0 do begin
it := RKCheck.CurrentOrder.Sessions.Lines[j];
if SYS.ObjectInheritsFrom(it, 'TDish') then
if (TDish(it).Code = DishCode) then
RKCheck.DeleteCheckItem(it);
end;
end;
if ToPaySum >= SumInterval then // check limit exceed adding a dish when the receipt total is more than specified
if CntDish1 = 0 then
RKCheck.CreateCheckItem(rkrefMenuItems, IntToStr(DishCode), '1');
end;
end;
Set the required values for SumInterval and DishCode in the script.
A script to add or remove dishes at a certain amount of the saved order
procedure userTimerSumLimitOnTimer(Sender: TObject);
var ToPaySum, SumInterval : double;
tt : TTimer;
i, j: integer;
it,CurItem: TCheckItem;
DiscCode, DishCode, CntDish1: integer;
CheckView:TCheckView;
begin
SumInterval := 700; // limit receipt total upon reaching which the dish is added automatically
DishCode := 43; // special dish code automatically added dish code
CntDish1 := 0;
CheckView := TCheckView(GUI.FindComponentByName('CheckView'));
if CheckView = Nil then Exit;
if not RKCheck.Valid then Exit;
if (GUI.CheckFormInPayMode) then exit;
if SYS.ObjectInheritsFrom(RKCheck.CurrentCheckItem, 'TPrintCheckItem') then Exit;
CurItem := RKCheck.CurrentCheckItem;
begin
ToPaySum := RKCheck.CurrentOrder.ToPaySum;
for i := 0 to RKCheck.CurrentOrder.Sessions.LinesCount - 1 do
begin
it := RKCheck.CurrentOrder.Sessions.Lines[i];
if SYS.ObjectInheritsFrom(it, 'TDish') then
if (TDish(it).Code = DishCode) then
CntDish1 := CntDish1 + trunc(TDish(it).Quantity);
end;
if ToPaySum < SumInterval then // deleting a dish when the receipt total is less than specified
if CntDish1 > 0 then
begin
for j := RKCheck.CurrentOrder.Sessions.LinesCount - 1 downto 0 do begin
it := RKCheck.CurrentOrder.Sessions.Lines[j];
if SYS.ObjectInheritsFrom(it, 'TDish') then
if (TDish(it).Code = DishCode) then
begin
CheckView.GotoItem(TObject(it));
if it.State = disOpened then begin
RK7.PerformOperation(rkoDeleteLine, 1); // deletion
continue;
end else
RKCheck.CreateCheckItem(rkrefOrderVoids, '1', FloatToStr(TDish(it).Quantity)); // write-off
end;
end;
end;
if ToPaySum >= SumInterval then // check limit exceed adding a dish when the receipt total is more than specified
if CntDish1 = 0 then
RKCheck.CreateCheckItem(rkrefMenuItems, IntToStr(DishCode), '1');
end;
if CurItem <> Nil then CheckView.GotoItem(CurItem);
end;
A script for the «Gift dish for an order amount of 1300 rubles with a discount» promotion
During the period Mon-Fri from 10:00 till 18:00 one specified dish is added manually to the order with the amount 1300 rub (with a discount). This dish should appear in the list only if the order amount is greater than or equal to 1300 rub.
Place a timer (TTimer) on the receipt editing form and specify a script in its event:
procedure userTimer1OnTimer(Sender: TObject);
var ToPaySum : double;
i, DishCode1: integer;
qnt, qntMax: double;
LimitSum1: double;
it: TCheckItem;
CurrTime, Time1, Time2: TDateTime;
tt : TTimer;
begin
qnt := 0;
DishCode1 := 25; // special dish code
qntMax := 1; // special dish max quantity for the order
Time1 := EncodeTime(10,00,00,00); // promotion period start
Time2 := EncodeTime(18,00,00,00); // promotion period end
LimitSum1 := 1300; // the receipt total over which the bonus dish will be allowed to be added
CurrTime := Time; //1 = Sunday
//2 = Monday
//3 = Tuesday
//4 = Wednesday
//5 = Thursday
//6 = Friday
//7 = Saturday
if not RKCheck.Valid then Exit;
if (GUI.CheckFormInPayMode) then
exit;
if SYS.ObjectInheritsFrom(RKCheck.CurrentCheckItem, 'TPrintCheckItem') then Exit;
if (DayOfWeek(Now)>=2)and(DayOfWeek(Now)<=6) then // week day check
if (Time1<=CurrTime) and(CurrTime<=Time2) then
begin
ToPaySum := RKCheck.CurrentOrder.ToPaySum;
for i := 0 to RKCheck.CurrentOrder.Sessions.LinesCount - 1 do
begin
it := RKCheck.CurrentOrder.Sessions.Lines[i];
if SYS.ObjectInheritsFrom(it, 'TDish') then
if TDish(it).code = DishCode1 then
qnt := qnt + TDish(it).Quantity;
end;
if (ToPaySum <= LimitSum1)and(qnt>0) then
begin
RK7.PerformOperation(rkoHome, 0);
while True do begin
it := RKCheck.CurrentCheckItem;
if TObject(it) = Nil then break;
if SYS.ObjectInheritsFrom(TObject(it), 'TPrintCheckItem') then break;
if SYS.ObjectInheritsFrom(TObject(it), 'TDish') then
if (TDish(it).Code = DishCode1) then begin
if it.State = disOpened then begin
RK7.PerformOperation(rkoDeleteLine, 1); // deletion
continue;
end else
RKCheck.CreateCheckItem(rkrefOrderVoids, '1', FloatToStr(TDish(it).Quantity)); // write-off
end;
RK7.PerformOperation(rkoDown, 0);
end;
end;
end;
end;
A script for the OnBeforeCheckViewEdit event of the CheckView object located on the check editing form:
procedure CheckViewOnBeforeCheckViewEdit(Sender: TObject; AEditType: TEditType; AObjectBef, AObjectAft: TObject; var AAllow: boolean; var AMessage: string);
var i, DishCode1: integer;
qnt, qntMax: double;
checksum, LimitSim1: double;
it: TCheckItem;
CurrTime, Time1, Time2: TDateTime;
begin
qnt := 0;
DishCode1 := 25; // special dish code
qntMax := 1; // special dish max quantity for the order.
Time1 := EncodeTime(10,00,00,00); / / promotion period start
Time2 := EncodeTime(18,00,00,00); / / promotion period end
LimitSim1: = 1300; / / the receipt total over which the bonus dish will be allowed to be added
CurrTime := Time;
checksum := 0;
/ /1 = Sunday
/ /2 = Monday
/ /3 = Tuesday
/ /4 = Wednesday
/ /5 = Thursday
/ /6 = Friday
/ /7 = Saturday
if SYS.ObjectInheritsFrom(AObjectAft, 'TDish') then
if TDish(AObjectAft).code = DishCode1 then
if not(AEditType = etRemove) then
begin
AAllow := false;
AMessage := 'Access denied';
if (DayOfWeek(Now)>=2)and(DayOfWeek(Now)<=6) then // week day check
if (Time1<=CurrTime)and(CurrTime<=Time2) then
begin
// gui.showmessage(Timetostr(time1)+' '+Timetostr(currtime)+' '+Timetostr(time2));
AAllow := true;
AMessage := '';
checksum := RKCheck.CurrentOrder.ToPaySum;
qnt := TDish(AObjectAft).Quantity;
for i := 0 to RKCheck.CurrentOrder.Sessions.LinesCount - 1 do
begin
it := RKCheck.CurrentOrder.Sessions.Lines[i];
if SYS.ObjectInheritsFrom(it, 'TDish') then
if TDish(it).code = DishCode1 then
qnt := qnt + TDish(it).Quantity;
end;
if (qnt > qntMax)or(LimitSim1>checksum) then // check limit exceed
begin
AAllow := false;
AMessage := 'Quantity exceeded the permitted limit ';
end;
end;
end;
end;
A script to print the percentage of the variable discount in the bill
At the request of the client, the «Discount equal to the age» was created, which has a variable value from 0 to 60%.
The script displays the discount in the bill.
On the edit form, place the timer, and specify the script in its OnTimer event:
procedure userTimer1OnTimer(Sender: TObject);
var i,discCode:integer;
it: TCheckItem;
begin
discCode := 10;
// Проверка на корректный чек
if not RKCheck.Valid then Exit;
if (GUI.CheckFormInPayMode) then exit;
if SYS.ObjectInheritsFrom(RKCheck.CurrentCheckItem, 'TPrintCheckItem') then Exit;
for i := 0 to RKCheck.CurrentOrder.Sessions.LinesCount - 1 do
begin
it := RKCheck.CurrentOrder.Sessions.Lines[i];
if SYS.ObjectInheritsFrom(it, 'TDiscountItem') then
if (it.code = discCode) and (TDiscountItem(it).State <> disDeleted) then
RKCheck.UpdateVisitComment(FloatToStr(abs(TDiscountItem(it).CalcPercent/100))+'%', '');
end;
end;
A script to implement the «Buy a movie ticket and make an order from 600 rubles in the bar — and choose 1 free dish» promotion
On the check editing form of the CheckView object, insert the script in the OnBeforeCheckViewEdit event (controls the manual addition of the bonus dish):
procedure CheckViewOnBeforeCheckViewEdit(Sender: TObject; AEditType: TEditType; AObjectBef, AObjectAft: TObject; var AAllow: boolean; var AMessage: string);
var i, DishCode1, DishCode2: integer;
qnt, qntMax: double;
checksum, LimitSim1: double;
it: TCheckItem;
begin
DishCode1 := 45; // special dish code
DishCode2 := 46; // special dish code
qntMax := 1; // special dish max quantity for the order.
LimitSum1 := 600; // the receipt total over which the bonus dish will be allowed to be added.
qnt := 0;
checksum := 0;
if SYS.ObjectInheritsFrom(AObjectAft, 'TDish') then
if (TDish(AObjectAft).code = DishCode1)or(TDish(AObjectAft).code = DishCode2) then
if not(AEditType = etRemove) then
begin
AAllow := false;
AMessage := 'Access denied';
begin
AAllow := true;
AMessage := '';
checksum := RKCheck.CurrentOrder.ToPaySum;
qntMax := trunc(checksum / LimitSim1);
if qntMax >= 1 then qntMax := 1;
if TDish(AObjectAft).Quantity<>0 then
qnt := 1;
for i := 0 to RKCheck.CurrentOrder.Sessions.LinesCount - 1 do
begin
it := RKCheck.CurrentOrder.Sessions.Lines[i];
if SYS.ObjectInheritsFrom(it, 'TDish') then
if (TDish(it).code = DishCode1)or(TDish(it).code = DishCode2) then
qnt := qnt + TDish(it).Quantity;
end;
if (qnt > qntMax) then // check limit exceed
begin
AAllow := false;
AMessage := 'Quantity exceeded the permitted limit ';
end;
end;
end;
end;
A script for the timer placed on the receipt editing form (controls the automatic addition or deletion of the bonus dish):
procedure userTimer1OnTimer(Sender: TObject);
var ToPaySum : double;
i, DishCode1, DishCode2: integer;
qnt, qnt_temp, qnt_temp2, qntMax: double;
LimitSum1: double;
it: TCheckItem;
tt : TTimer;
ed: TObject;
begin
DishCode1 := 45; // special dish code
DishCode2 := 46; // special dish code
qntMax := 1; // special dish max quantity for the order.
LimitSum1 := 600; // the receipt total over which the bonus dish will be allowed to be added.
qnt := 0;
if not RKCheck.Valid then Exit;
if (GUI.CheckFormInPayMode) then exit;
if SYS.ObjectInheritsFrom(RKCheck.CurrentCheckItem, 'TPrintCheckItem') then Exit;
if (RKCheck.CurrentOrder.ToPaySum < LimitSum1)and(RKCheck.CurrentOrder.UserTag1 > 0) then
RKCheck.CurrentOrder.UserTag1 := 0;
if (RKCheck.CurrentOrder.ToPaySum >= LimitSum1)and(RKCheck.CurrentOrder.UserTag1 = 0) then
begin
RKCheck.CurrentOrder.UserTag1 := 1;
if GUI.RKMessageDlg('Does the client have a receipt with the promotion? ', 0, 3, 100000) = 6 then
if GUI.RKMessageDlg('Add dish №1?', 0, 3, 100000) = 6 then
RKCheck.CreateCheckItem(rkrefMenuItems, IntToStr(DishCode1), FloatToStr(1)) // adding dish 1
else
RKCheck.CreateCheckItem(rkrefMenuItems, IntToStr(DishCode2), FloatToStr(1)); // adding dish 2
end;
begin
ToPaySum := RKCheck.CurrentOrder.ToPaySum;
qntMax := trunc(ToPaySum / LimitSum1);
if qntMax >= 1 then qntMax := 1;
for i := 0 to RKCheck.CurrentOrder.Sessions.LinesCount - 1 do
begin
it := RKCheck.CurrentOrder.Sessions.Lines[i];
if SYS.ObjectInheritsFrom(it, 'TDish') then
if (TDish(it).code = DishCode1)or(TDish(it).code = DishCode2) then
qnt := qnt + TDish(it).Quantity;
end;
if (qnt > qntMax) then
begin
RK7.PerformOperation(rkoHome, 0);
while True do begin
qnt_temp := 0;
it := RKCheck.CurrentCheckItem;
if TObject(it) = Nil then break;
if SYS.ObjectInheritsFrom(TObject(it), 'TPrintCheckItem') then break;
if SYS.ObjectInheritsFrom(TObject(it), 'TDish') then
if (TDish(it).code = DishCode1)or(TDish(it).code = DishCode2) then begin
if (TDish(it).Quantity) > 0 then
if it.State = disOpened then begin
if (qnt-TDish(it).Quantity) >= qntmax then
begin
qnt := qnt - TDish(it).Quantity;
RK7.PerformOperation(rkoDeleteLine, 1); // deletion
continue;
end
else
begin
qnt_temp := qntmax-(qnt-TDish(it).Quantity);
qnt_temp2 := TDish(it).Quantity;
ed := TObject(gui.FindComponentByName('Editor'));
if SYS.ObjectInheritsFrom(TObject(ed), 'TNumEditor') then
begin
TNumEditor(ed).Text := IntToStr(trunc(qnt_temp));
RK7.PerformOperation(rkoEditAmount, 0);
TNumEditor(ed).Text := '';
qnt := qnt -(qnt_temp2-qnt_temp);
end;
end
end else
begin
qnt := qnt - TDish(it).Quantity;
RKCheck.CreateCheckItem(rkrefOrderVoids, '1', FloatToStr(TDish(it).Quantity)); // ????????
end;
end;
RK7.PerformOperation(rkoDown, 0);
if (qnt <= qntMax) then break;
end;
end;
end;
end;
A script to add a dish:
procedure CheckViewOnBeforeCheckViewEdit(Sender: TObject; AEditType: TEditType; AObjectBef, AObjectAft: TObject; var AAllow: boolean; var AMessage: string);
var i, DishCode1, DishCode2: integer;
qnt, qntMax: double;
checksum, LimitSim1: double;
it: TCheckItem;
begin
DishCode1 := 45; // special dish code
DishCode2 := 46; // special dish code
qntMax := 1; // special dish max quantity for the order.
LimitSum1 := 600; // the receipt total over which the bonus dish will be allowed to be added.
qnt := 0;
checksum := 0;
if SYS.ObjectInheritsFrom(AObjectAft, 'TDish') then
if (TDish(AObjectAft).code = DishCode1)or(TDish(AObjectAft).code = DishCode2) then
if not(AEditType = etRemove) then
begin
AAllow := false;
AMessage := 'Access denied';
begin
AAllow := true;
AMessage := '';
checksum := RKCheck.CurrentOrder.ToPaySum;
qntMax := trunc(checksum / LimitSim1);
if qntMax >= 1 then qntMax := 1;
if TDish(AObjectAft).Quantity<>0 then
qnt := 1;
for i := 0 to RKCheck.CurrentOrder.Sessions.LinesCount - 1 do
begin
it := RKCheck.CurrentOrder.Sessions.Lines[i];
if SYS.ObjectInheritsFrom(it, 'TDish') then
if (TDish(it).code = DishCode1)or(TDish(it).code = DishCode2) then
qnt := qnt + TDish(it).Quantity;
end;
if (RKCheck.CurrentOrder.UserTag1 > 0) then // check limit exceed
begin
AAllow := false;
AMessage := 'You can''t add dish manually';
end;
if (qnt > qntMax) then // check limit exceed
begin
AAllow := false;
AMessage := 'Quantity exceeded the permitted limit ';
end;
end;
end;
end;
A script for the timer:
procedure userTimer1OnTimer(Sender: TObject);
var ToPaySum : double;
i, DishCode1, DishCode2: integer;
qnt, qnt_temp, qnt_temp2, qntMax: double;
LimitSum1: double;
it: TCheckItem;
tt : TTimer;
ed: TObject;
begin
DishCode1 := 45; // special dish code
DishCode2 := 46; // special dish code
qntMax := 1; // special dish max quantity for the order.
LimitSum1 := 600; // the receipt total over which the bonus dish will be allowed to be added.
qnt := 0;
if not RKCheck.Valid then Exit;
if (GUI.CheckFormInPayMode) then exit;
if SYS.ObjectInheritsFrom(RKCheck.CurrentCheckItem, 'TPrintCheckItem') then Exit;
if (RKCheck.CurrentOrder.ToPaySum < LimitSum1)and(RKCheck.CurrentOrder.UserTag1 > 0) then
RKCheck.CurrentOrder.UserTag1 := 0;
if (RKCheck.CurrentOrder.ToPaySum >= LimitSum1)and(RKCheck.CurrentOrder.UserTag1 = 0) then
begin
RK7.PerformOperation(rkoUser07, 0);
{
if GUI.RKMessageDlg('Does the client have a receipt with the promotion? ', 0, 3, 100000) = 6 then
if GUI.RKMessageDlg('Add dish №1?', 0, 3, 100000) = 6 then
RKCheck.CreateCheckItem(rkrefMenuItems, IntToStr(DishCode1), FloatToStr(1)) // adding dish 1
else
RKCheck.CreateCheckItem(rkrefMenuItems, IntToStr(DishCode2), FloatToStr(1)); // adding dish 2
}
RKCheck.CurrentOrder.UserTag1 := 1;
end;
begin
ToPaySum := RKCheck.CurrentOrder.ToPaySum;
qntMax := trunc(ToPaySum / LimitSum1);
if qntMax >= 1 then qntMax := 1;
for i := 0 to RKCheck.CurrentOrder.Sessions.LinesCount - 1 do
begin
it := RKCheck.CurrentOrder.Sessions.Lines[i];
if SYS.ObjectInheritsFrom(it, 'TDish') then
if (TDish(it).code = DishCode1)or(TDish(it).code = DishCode2) then
qnt := qnt + TDish(it).Quantity;
end;
if (qnt > qntMax) then
begin
RK7.PerformOperation(rkoHome, 0);
while True do begin
qnt_temp := 0;
it := RKCheck.CurrentCheckItem;
if TObject(it) = Nil then break;
if SYS.ObjectInheritsFrom(TObject(it), 'TPrintCheckItem') then break;
if SYS.ObjectInheritsFrom(TObject(it), 'TDish') then
if (TDish(it).code = DishCode1)or(TDish(it).code = DishCode2) then begin
if (TDish(it).Quantity) > 0 then
if it.State = disOpened then begin
if (qnt-TDish(it).Quantity) >= qntmax then
begin
qnt := qnt - TDish(it).Quantity;
RK7.PerformOperation(rkoDeleteLine, 1); // deletion
continue;
end
else
begin
qnt_temp := qntmax-(qnt-TDish(it).Quantity);
qnt_temp2 := TDish(it).Quantity;
ed := TObject(gui.FindComponentByName('Editor'));
if SYS.ObjectInheritsFrom(TObject(ed), 'TNumEditor') then
begin
TNumEditor(ed).Text := IntToStr(trunc(qnt_temp));
RK7.PerformOperation(rkoEditAmount, 0);
TNumEditor(ed).Text := '';
qnt := qnt -(qnt_temp2-qnt_temp);
end;
end
end else
begin
qnt := qnt - TDish(it).Quantity;
RKCheck.CreateCheckItem(rkrefOrderVoids, '1', FloatToStr(TDish(it).Quantity)); // write-off
end;
end;
RK7.PerformOperation(rkoDown, 0);
if (qnt <= qntMax) then break;
end;
end;
end;
end;
A script for a custom operation:
procedure ProcessOperation1001832(Parameter: integer);
var DishCode1, DishCode2: integer;
begin
DishCode1 := 45; // special dish code
DishCode2 := 46; // special dish code
if GUI.RKMessageDlg('Does the client have a receipt with the promotion? ', 0, 3, 100000) = 6 then
if GUI.RKMessageDlg('Add dish №1?', 0, 3, 100000) = 6 then
RKCheck.CreateCheckItem(rkrefMenuItems, IntToStr(DishCode1), FloatToStr(1)) // adding dish 1
else
RKCheck.CreateCheckItem(rkrefMenuItems, IntToStr(DishCode2), FloatToStr(1)); // adding dish 2
end;
Assign the last script to the user procedure and check the box «Access control» — «Restrict access to the user operation» in the properties.
In the cash rights of users, the corresponding item «Cash rights of the employee» will appear.
A script for the «Get a gift for every three dishes from the list» promotion
Place a timer on the receipt editing form. Set the interval equal to 200 (this is the timer triggering time). In the OnTimer event, specify the following script:
procedure userTimer1OnTimer(Sender: TObject);
var ToPaySum, quantity : double;
tt : TTimer;
i, j, every: integer;
it: TCheckItem;
BonusDishCode, DishCode1, DishCode2, DishCode3, DishCode4, DishCode5, DishCode6, DishCode7, DishCode8, DishCode9, CntDish, CntBonusDish: integer;
begin
DishCode1 := 23; // special dish code
DishCode2 := 24; // special dish code
DishCode3 := 25; // special dish code
DishCode4 := 47; // special dish code
DishCode5 := 4; // special dish code
DishCode6 := 14; // special dish code
DishCode7 := 43; // special dish code
DishCode8 := 43; // special dish code
DishCode9 := 43; // special dish code
BonusDishCode := 45; // bonus dish code automatically added dish code
CntDish := 0;
CntBonusDish := 0;
every := 3; // bonus for every dish quantity
if not RKCheck.Valid then Exit;
if (GUI.CheckFormInPayMode) then exit;
if SYS.ObjectInheritsFrom(RKCheck.CurrentCheckItem, 'TPrintCheckItem') then Exit;
begin
for i := 0 to RKCheck.CurrentOrder.Sessions.LinesCount - 1 do
begin
it := RKCheck.CurrentOrder.Sessions.Lines[i];
if SYS.ObjectInheritsFrom(it, 'TDish') then
begin
if (TDish(it).Code = DishCode1)
or (TDish(it).Code = DishCode2)
or (TDish(it).Code = DishCode3)
or (TDish(it).Code = DishCode4)
or (TDish(it).Code = DishCode5)
or (TDish(it).Code = DishCode6)
or (TDish(it).Code = DishCode7)
or (TDish(it).Code = DishCode8)
or (TDish(it).Code = DishCode9)
then
CntDish := CntDish + trunc(TDish(it).Quantity);
if (TDish(it).Code = BonusDishCode) then
CntBonusDish := CntBonusDish + trunc(TDish(it).Quantity);
end;
end;
if trunc(CntDish / every)<>CntBonusDish then // deleting a dish if the required number of bonus dishes does not match
if CntBonusDish > 0 then
begin
for j := RKCheck.CurrentOrder.Sessions.LinesCount - 1 downto 0 do begin
it := RKCheck.CurrentOrder.Sessions.Lines[j];
if SYS.ObjectInheritsFrom(it, 'TDish') then
if (TDish(it).Code = BonusDishCode) then
RKCheck.DeleteCheckItem(it);
end;
end;
if trunc(CntDish / every) > 0 then
if trunc(CntDish / every) >= CntBonusDish then // checking the need to check the dish
if CntBonusDish = 0 then
RKCheck.CreateCheckItem(rkrefMenuItems, IntToStr(BonusDishCode), IntToStr(trunc(CntDish / every)));
end;
end;
A script for the «Make an order for 1300 rubles and choose gift dishes during a certain period» promotion
During the period Mon-Fri from 18:01 to 03:00 and Sat-Sun from 10:00 to 03:00, either one of two specified dishes is added manually to the order with the amount 1300 rub (with a discount) or a 10% discount is applied.
The script prohibits to display these dishes at the cash register until the order amount is equal to 1300 rubles.
On the check editing form of the CheckView object, insert the script in the OnBeforeCheckViewEdit event:
procedure CheckViewOnBeforeCheckViewEdit(Sender: TObject; AEditType: TEditType; AObjectBef, AObjectAft: TObject; var AAllow: boolean; var AMessage: string);
var i, DishCode1, DishCode2, cntDisk, DiscountCode: integer;
qnt, qntMax: double;
checksum, LimitSim1: double;
it: TCheckItem;
CurrTime, Time1, Time2: TDateTime;
begin
qnt := 0;
DiscountCode := 2; // promotional discount code
DishCode1 := 45; // special dish code
DishCode2 := 46; // special dish code
qntMax := 1; // controlled dish max quantity in the order.
Time1 := EncodeTime(10,00,00,00); // promotion period start
Time2 := EncodeTime(18,00,00,00); // promotion period end
LimitSim1 := 1300; // the receipt total over which the bonus dish will be allowed to be added.
CurrTime := Time;
checksum := 0;
cntDisk := 0;
//1 = Sunday
//2 = Monday
//3 = Tuesday
//4 = Wednesday
//5 = Thursday
//6 = Friday
//7 = Saturday
if SYS.ObjectInheritsFrom(AObjectAft, 'TDish') then
if (TDish(AObjectAft).code = DishCode1)or(TDish(AObjectAft).code = DishCode2) then
if not(AEditType = etRemove) then
begin
AAllow := false;
AMessage := 'Access denied';
if (DayOfWeek(Now)>=2)and(DayOfWeek(Now)<=6) then // week day check
if (Time1<=CurrTime)and(CurrTime<=Time2) then
begin
AAllow := true;
AMessage := '';
checksum := RKCheck.CurrentOrder.ToPaySum;
qntMax := trunc(checksum / LimitSim1);
// qnt := TDish(AObjectAft).Quantity; // displays the quantity incorrectly
if TDish(AObjectAft).Quantity<>0 then
qnt := 1;
for i := 0 to RKCheck.CurrentOrder.Sessions.LinesCount - 1 do
begin
it := RKCheck.CurrentOrder.Sessions.Lines[i];
if SYS.ObjectInheritsFrom(it, 'TDiscountItem') then
if (TDiscountItem(it).Code = DiscountCode) then
cntDisk := cntDisk + 1; // promotional discount registered
if SYS.ObjectInheritsFrom(it, 'TDish') then
if (TDish(it).code = DishCode1)or(TDish(it).code = DishCode2) then
qnt := qnt + TDish(it).Quantity;
end;
qnt := qnt + cntDisk;
if (qnt > qntMax) then // check limit exceed
begin
// gui.showmessage('qnt='+inttostr(qnt)+'qntMax='+inttostr(qntMax));
AAllow := false;
AMessage := 'Quantity exceeded the permitted limit ';
end;
end;
end;
end;
A script for the timer placed on the receipt editing form:
procedure userTimer1OnTimer(Sender: TObject);
var ToPaySum : double;
i, DishCode1, DishCode2, cntDisk, DiscountCode: integer;
qnt, qnt_temp, qnt_temp2, qntMax: double;
LimitSum1: double;
it: TCheckItem;
CurrTime, Time1, Time2: TDateTime;
tt : TTimer;
ed: TObject;
begin
qnt := 0;
DiscountCode := 2; // promotional discount code
DishCode1 := 45; // special dish code
DishCode2 := 46; // special dish code
qntMax := 1; // special dish max quantity for the order.
Time1 := EncodeTime(10,00,00,00); // promotion period start
Time2 := EncodeTime(18,00,00,00); // promotion period end
LimitSum1 := 1300; // receipt total upon reaching which the dish is added automatically.
CurrTime := Time;
cntDisk := 0;
//1 = Sunday
//2 = Monday
//3 = Tuesday
//4 = Wednesday
//5 = Thursday
//6 = Friday
//7 = Saturday
if not RKCheck.Valid then Exit;
if (GUI.CheckFormInPayMode) then exit;
if SYS.ObjectInheritsFrom(RKCheck.CurrentCheckItem, 'TPrintCheckItem') then Exit;
if (DayOfWeek(Now)>=2)and(DayOfWeek(Now)<=6) then // week day check
if (Time1<=CurrTime) and(CurrTime<=Time2) then
begin
ToPaySum := RKCheck.CurrentOrder.ToPaySum;
qntMax := trunc(ToPaySum / LimitSum1);
for i := 0 to RKCheck.CurrentOrder.Sessions.LinesCount - 1 do
begin
it := RKCheck.CurrentOrder.Sessions.Lines[i];
if SYS.ObjectInheritsFrom(it, 'TDiscountItem') then
if (TDiscountItem(it).Code = DiscountCode) then
cntDisk := cntDisk + 1; // promotional discount registered
if SYS.ObjectInheritsFrom(it, 'TDish') then
if (TDish(it).code = DishCode1)or(TDish(it).code = DishCode2) then
qnt := qnt + TDish(it).Quantity;
end;
qnt := qnt + cntDisk;
if (qnt > qntMax)and(cntDisk<>trunc(qnt)) then
begin
RK7.PerformOperation(rkoHome, 0);
while True do begin
qnt_temp := 0;
it := RKCheck.CurrentCheckItem;
if TObject(it) = Nil then break;
if SYS.ObjectInheritsFrom(TObject(it), 'TPrintCheckItem') then break;
if SYS.ObjectInheritsFrom(TObject(it), 'TDish') then
if (TDish(it).code = DishCode1)or(TDish(it).code = DishCode2) then begin
if (TDish(it).Quantity) > 0 then
if it.State = disOpened then begin
if (qnt-TDish(it).Quantity) >= qntmax then
begin
qnt := qnt - TDish(it).Quantity;
RK7.PerformOperation(rkoDeleteLine, 1); // deletion
continue;
end
else
begin
qnt_temp := qntmax-(qnt-TDish(it).Quantity);
qnt_temp2 := TDish(it).Quantity;
ed := TObject(gui.FindComponentByName('Editor'));
if SYS.ObjectInheritsFrom(TObject(ed), 'TNumEditor') then
begin
TNumEditor(ed).Text := IntToStr(trunc(qnt_temp));
RK7.PerformOperation(rkoEditAmount, 0);
TNumEditor(ed).Text := '';
qnt := qnt -(qnt_temp2-qnt_temp);
end;
end
end else
begin
qnt := qnt - TDish(it).Quantity;
RKCheck.CreateCheckItem(rkrefOrderVoids, '1', FloatToStr(TDish(it).Quantity)); // write-off
end;
end;
RK7.PerformOperation(rkoDown, 0);
if (qnt <= qntMax) then break;
end;
end;
end;
end;
A script to apply the discount:
procedure DiscountUsage1001717(UsageParameters: TDiscountUsageParameters);
var i, DishCode1, DishCode2, cntDisk, DiscountCode: integer;
it: TCheckItem;
CurrTime, Time1, Time2: TDateTime;
qnt, qnt_temp, qnt_temp2, qntMax, ToPaySum, LimitSum1: double;
begin
qnt := 0;
DiscountCode := 2; // promotional discount code
DishCode1 := 45; // special dish code
DishCode2 := 46; // special dish code
qntMax := 1; // special dish max quantity for the order.
Time1 := EncodeTime(10,00,00,00); // promotion period start
Time2 := EncodeTime(18,00,00,00); // promotion period end
LimitSum1 := 1300; // receipt total over which the dish is added automatically.
CurrTime := Time;
cntDisk := 0;
//1 = Sunday
//2 = Monday
//3 = Tuesday
//4 = Wednesday
//5 = Thursday
//6 = Friday
//7 = Saturday
if not RKCheck.Valid then
exit //important checking
else
if (DayOfWeek(Now)>=2)and(DayOfWeek(Now)<=6) then // week day check
if (Time1<=CurrTime) and(CurrTime<=Time2) then
begin
ToPaySum := RKCheck.CurrentOrder.ToPaySum;
qntMax := trunc(ToPaySum / LimitSum1);
for i := 0 to RKCheck.CurrentOrder.Sessions.LinesCount - 1 do
begin
it := RKCheck.CurrentOrder.Sessions.Lines[i];
if SYS.ObjectInheritsFrom(it, 'TDiscountItem') then
if (TDiscountItem(it).Code = DiscountCode) then
cntDisk := cntDisk + 1; // promotional discount registered
if SYS.ObjectInheritsFrom(it, 'TDish') then
if (TDish(it).code = DishCode1)or(TDish(it).code = DishCode2) then
qnt := qnt + TDish(it).Quantity;
end;
qnt := qnt + cntDisk;
begin
if (qnt < qntMax) then
UsageParameters.UsageMode := umAllow
else
UsageParameters.UsageMode := umDeny;
end;
end;
end;
A script to automatically add additional dishes (packaging for takeout orders)
All scripts are specified on the receipt editing form.
Declaring a global variable in the receipt editing form. An array is declared in which basic dishes and related packaging items will be entered:
var ModifArr: array of string;
A script to add dishes for the specified main dish:
procedure AddSpecDish(Dish:TDish);
var
j,p1,p2: integer;
s, dcode, AddCode, q: string;
begin
for j := 0 to GetArrayLength(ModifArr)-1 do
begin
s := ModifArr[j];
p1 := pos(';',s);
p2 := p1+pos(';',copy(s,p1+1, length(s)-p1));
dcode := copy(s,1,p1-1);
AddCode := copy(s,p1+1,p2-p1-1);
q := copy(s,p2+1, length(s)-p2);
if (Dish.Code = StrToInt(dcode) ) then
begin
RKCheck.CreateCheckItem(rkrefMenuItems, AddCode, FloatToStr(StrToFloat(q)*TDish(Dish).Quantity)); // adding a dish considering the amount of the main dish
end;
end;
end;
A script to add dishes to all previously added to the order before adding the nominal takeout dish:
procedure AddSpecDishBefore;
var i: integer;
it: TCheckItem;
begin
for i := 0 to RKCheck.CurrentOrder.Sessions.LinesCount - 1 do
begin
it := RKCheck.CurrentOrder.Sessions.Lines[i];
if SYS.ObjectInheritsFrom(it, 'TDish') then
AddSpecDish(TDish(it));
end;
end;
In the OnAfterCheckViewEdit procedure of the CheckView component, the added dish is checked. If it is specified in the array, the specified packaging items are added to it. Each added dish is checked.
procedure CheckViewOnAfterCheckViewEdit(Sender: TObject; AEditType: TEditType; AObjectBef, AObjectAft: TObject);
var i,j,p1,p2: integer;
it: TCheckItem;
s, dcode, AddCode, q: string;
begin
if (RKCheck.CurrentOrder.TableCode >= 0)and(RKCheck.CurrentOrder.TableCode < 500) then // check condition to add pack dishes
if SYS.ObjectInheritsFrom(AObjectAft, 'TDish') then
if TDish(AObjectAft).Code = 20874 then // 20874 - nominal takeout dish code
begin
RKCheck.CurrentOrder.UserTag1 := 30;
// add dishes for order
for j := 0 to GetArrayLength(ModifArr)-1 do
begin
s := ModifArr[j];
p1 := pos(';',s);
p2 := p1+pos(';',copy(s,p1+1, length(s)-p1));
dcode := copy(s,1,p1-1);
AddCode := copy(s,p1+1,p2-p1-1);
q := copy(s,p2+1, length(s)-p2);
if (0 = StrToInt(dcode) ) then
RKCheck.CreateCheckItem(rkrefMenuItems, AddCode, FloatToStr(StrToFloat(q)*1));
end;
// add dishes for order
AddSpecDishBefore; // adding packaging dishes for all items previously added to the order
end;
if (RKCheck.CurrentOrder.UserTag1 = 30) then // check condition to add pack dishes
begin
if SYS.ObjectInheritsFrom(AObjectAft, 'TDish') then
AddSpecDish(TDish(AObjectAft));
end;
// checking by modifier
{ for i := 0 to RKCheck.CurrentOrder.Sessions.LinesCount - 1 do
begin
it := RKCheck.CurrentOrder.Sessions.Lines[i];
if SYS.ObjectInheritsFrom(it, 'TDish') then
begin
for j := 0 to TDish(it).Modifiers.Count - 1 do
begin
gui.showmessage('step 2 '+inttostr(TDish(it).Modifiers.Items[j].Code));
if (TDish(it).Modifiers.Items[j].Code=20) then
RKCheck.CurrentOrder.UserTag1 := 30;
end;
end;
end; }
end;
Place a timer on the form and specify a script in the timer event that tracks the moment when the nominal takeout dish is deleted to disable the packing mode:
procedure userTimer1OnTimer(Sender: TObject);
var i,j, cnt: integer;
it: TCheckItem;
begin
cnt := 0;
if not RKCheck.Valid then
exit //important checking
else
if (RKCheck.CurrentOrder.TableCode >= 0)and(RKCheck.CurrentOrder.TableCode < 500) then // different discounts for different tables
begin
// serch special dishes
for i := 0 to RKCheck.CurrentOrder.Sessions.LinesCount - 1 do
begin
it := RKCheck.CurrentOrder.Sessions.Lines[i];
if SYS.ObjectInheritsFrom(it, 'TDish') then
if TDish(it).Code = 20874 then
cnt := cnt + 1;
{ serch special modificator
for j := 0 to TDish(it).Modifiers.Count - 1 do
if (TDish(it).Modifiers.Items[j].Code=20) then }
end;
// remove tag for autoadding dishes
if cnt = 0 then
RKCheck.CurrentOrder.UserTag1 := 0;
end;
end;
A script for the OnShowScript event of the CheckView component. It sets a group of bounds of packaging dishes to the main ones:
procedure userTimer1OnTimer(Sender: TObject);
var i,j, cnt: integer;
it: TCheckItem;
begin
cnt := 0;
if not RKCheck.Valid then
exit //important checking
else
if (RKCheck.CurrentOrder.TableCode >= 0)and(RKCheck.CurrentOrder.TableCode < 500) then // different discounts for different tables
begin
// serch special dishes
for i := 0 to RKCheck.CurrentOrder.Sessions.LinesCount - 1 do
begin
it := RKCheck.CurrentOrder.Sessions.Lines[i];
if SYS.ObjectInheritsFrom(it, 'TDish') then
if TDish(it).Code = 20874 then
cnt := cnt + 1;
{ serch special modificator
for j := 0 to TDish(it).Modifiers.Count - 1 do
if (TDish(it).Modifiers.Items[j].Code=20) then }
end;
// remove tag for autoadding dishes
if cnt = 0 then
RKCheck.CurrentOrder.UserTag1 := 0;
end;
end;
A script to automatically add dish serving sequences to a new order
Place a timer on the order editing form and insert a script in its event:
procedure userTimer1OnTimer(Sender: TObject);
var i,CntDish1:integer;
it: TCheckItem;
begin
// Checking for correct receipt
if not RKCheck.Valid then Exit;
if (GUI.CheckFormInPayMode) then exit;
if SYS.ObjectInheritsFrom(RKCheck.CurrentCheckItem, 'TPrintCheckItem') then Exit;
if RKCheck.CurrentOrder.UserTag1 = 0 then
begin
CntDish1 := 0;
for i := 0 to RKCheck.CurrentOrder.Sessions.LinesCount - 1 do
begin
it := RKCheck.CurrentOrder.Sessions.Lines[i];
if SYS.ObjectInheritsFrom(it, 'TDish') then
if (TDish(it).quantity > 0) then
CntDish1 := CntDish1 + trunc(TDish(it).Quantity);
end;
if CntDish1<>0 then RKCheck.CurrentOrder.UserTag1 := 2;
if CntDish1=0 then
begin
RKCheck.CurrentOrder.UserTag1 := 1;
RK7.PerformOperation(rkoServLineSelector, 0);
RK7.PerformRefObject(RK7.FindItemByCode(rkrefKurses, 4)); // serving sequence code
RK7.PerformOperation(rkoDown, 0);
RK7.PerformOperation(rkoServLineSelector, 0);
RK7.PerformRefObject(RK7.FindItemByCode(rkrefKurses, 1)); // serving sequence code
RK7.PerformOperation(rkoDown, 0);
RK7.PerformOperation(rkoServLineSelector, 0);
RK7.PerformRefObject(RK7.FindItemByCode(rkrefKurses, 3)); // serving sequence code
RK7.PerformOperation(rkoDown, 0);
end;
end;
end;
A script to automatically add a dish to an empty order and exit from the order saving it
Place a timer on the receipt editing form, assign a 2 seconds period to it, and insert the script in the OnTimer event:
procedure userTimer1OnTimer(Sender: TObject);
var i,CntDish1:integer;
it: TCheckItem;
begin
// Checking for correct receipt
if not RKCheck.Valid then Exit;
if (GUI.CheckFormInPayMode) then exit;
if SYS.ObjectInheritsFrom(RKCheck.CurrentCheckItem, 'TPrintCheckItem') then Exit;
if RKCheck.CurrentOrder.UserTag1 = 0 then
begin
CntDish1 := 0;
for i := 0 to RKCheck.CurrentOrder.Sessions.LinesCount - 1 do
begin
it := RKCheck.CurrentOrder.Sessions.Lines[i];
if SYS.ObjectInheritsFrom(it, 'TDish') then
if (TDish(it).quantity > 0) then
CntDish1 := CntDish1 + trunc(TDish(it).Quantity);
end;
if CntDish1<>0 then RKCheck.CurrentOrder.UserTag1 := 2;
if CntDish1=0 then
begin
RKCheck.CurrentOrder.UserTag1 := 1;
RKCheck.CreateCheckItem(rkrefMenuItems, IntToStr(15304), inttostr(RKCheck.CurrentOrder.Visit.GuestCnt))// here insert code of free dish
RK7.PerformOperation(rkoSaveOrder, 0);
end;
end;
end;
A script to automatically add a dish when registering a PDS card (assigning a specified discount)
On the form for editing the receipt, place a timer and specify the script in its event:
procedure userTimer1OnTimer(Sender: TObject);
var limit : double;
i, j: integer;
it: TCheckItem;
BonusDishCode, DiscountCode, CntDiscount, CntBonusDish, BonusDishQnt: integer;
begin
DiscountCode := 33; // special dish code
BonusDishCode := 45; // bonus dish code
BonusDishQnt := 3; // bonus dish quantity
limit := 1000;
CntDiscount := 0;
CntBonusDish := 0;
if not RKCheck.Valid then Exit;
if (GUI.CheckFormInPayMode) then exit;
if SYS.ObjectInheritsFrom(RKCheck.CurrentCheckItem, 'TPrintCheckItem') then Exit;
begin
for i := 0 to RKCheck.CurrentOrder.Sessions.LinesCount - 1 do
begin
it := RKCheck.CurrentOrder.Sessions.Lines[i];
if SYS.ObjectInheritsFrom(it, 'TDish') then
begin
if (TDish(it).Code = BonusDishCode) then
CntBonusDish := CntBonusDish + trunc(TDish(it).Quantity);
end;
if SYS.ObjectInheritsFrom(it, 'TDiscountItem') then
begin
if (TDiscountItem(it).Code = DiscountCode) then
CntDiscount := CntDiscount + 1;
end;
end;
if CntDiscount > 0 then // deleting a dish if the required number of bonus dishes does not match
if CntBonusDish > 0 then
if RKCheck.CurrentOrder.ToPaySum < limit then
begin
for j := RKCheck.CurrentOrder.Sessions.LinesCount - 1 downto 0 do begin
it := RKCheck.CurrentOrder.Sessions.Lines[j];
if SYS.ObjectInheritsFrom(it, 'TDish') then
if (TDish(it).Code = BonusDishCode) then
RKCheck.DeleteCheckItem(it);
end;
end;
if RKCheck.CurrentOrder.ToPaySum >= limit then // checking the need to check the dish
if CntDiscount > 0 then
if CntBonusDish = 0 then
RKCheck.CreateCheckItem(rkrefMenuItems, IntToStr(BonusDishCode), IntToStr(BonusDishQnt));
end;
end;