On the order editing form, insert the script in the OnTimer event:
procedure userTimer1OnTimer(Sender: TObject); var CheckView: TCheckView; begin // Checking for a 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 // Проверка на корректный чек 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; |
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 a 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; |
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; |
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.
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; |
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 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; // controlled dish code qntMax := 1; // controlled dish max quantity for the order Time1 := EncodeTime(10,00,00,00); // special offer start Time2 := EncodeTime(18,00,00,00); // special offer 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; // controlled dish code qntMax := 1; // controlled dish max quantity for the order. Time1 := EncodeTime(10,00,00,00); / / special offer start Time2 := EncodeTime(18,00,00,00); / / special offer 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; |
Создали по желанию клиента "скидку равную возрасту", которая имеет изменяемое значение от 0 до 60%.
Скрипт отображает скидку в пречеке.
На форме редактирования разместите таймер, а в его событии OnTimer указать скрипт:
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;
На форме редактирования чека у объекта CheckView в событии OnBeforeCheckViewEdit указать скрипт (контролирует ручное добавление бонусного блюда):
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; // код контролируемого блюда DishCode2 := 46; // код контролируемого блюда qntMax := 1; // максимальное количество контролируемого блюда в заказе. LimitSum1 := 600; // сумма чека превысив которую будет разрешено добавить бонусное блюдо. 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;
Скрипт для таймера, размещаемого на форме редактирования чека (контролирует автоматическое добавление/удаление бонусного блюда):
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; // код контролируемого блюда DishCode2 := 46; // код контролируемого блюда qntMax := 1; // максимальное количество контролируемого блюда в заказе. LimitSum1 := 600; // сумма чека превысив которую будет разрешено добавить бонусное блюдо. 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('Есть ли у клиента чек с АКЦИЕЙ? ', 0, 3, 100000) = 6 then if GUI.RKMessageDlg('Добавить блюдо №1?', 0, 3, 100000) = 6 then RKCheck.CreateCheckItem(rkrefMenuItems, IntToStr(DishCode1), FloatToStr(1)) // добавление блюда 1 else RKCheck.CreateCheckItem(rkrefMenuItems, IntToStr(DishCode2), FloatToStr(1)); // добавление блюда 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); // удаление 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;
Скрипт на добавление блюда.
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; // код контролируемого блюда DishCode2 := 46; // код контролируемого блюда qntMax := 1; // максимальное количество контролируемого блюда в заказе. LimitSum1 := 600; // сумма чека превысив которую будет разрешено добавить бонусное блюдо. 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;
Скрипт для таймера:
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; // код контролируемого блюда DishCode2 := 46; // код контролируемого блюда qntMax := 1; // максимальное количество контролируемого блюда в заказе. LimitSum1 := 600; // сумма чека превысив которую будет разрешено добавить бонусное блюдо. 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('Есть ли у клиента чек с АКЦИЕЙ? ', 0, 3, 100000) = 6 then if GUI.RKMessageDlg('Добавить блюдо №1?', 0, 3, 100000) = 6 then RKCheck.CreateCheckItem(rkrefMenuItems, IntToStr(DishCode1), FloatToStr(1)) // добавление блюда 1 else RKCheck.CreateCheckItem(rkrefMenuItems, IntToStr(DishCode2), FloatToStr(1)); // добавление блюда 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); // удаление 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;
Скрипт для пользовательской операции:
procedure ProcessOperation1001832(Parameter: integer); var DishCode1, DishCode2: integer; begin DishCode1 := 45; // код контролируемого блюда DishCode2 := 46; // код контролируемого блюда if GUI.RKMessageDlg('Есть ли у клиента чек с АКЦИЕЙ? ', 0, 3, 100000) = 6 then if GUI.RKMessageDlg('Добавить блюдо №1?', 0, 3, 100000) = 6 then RKCheck.CreateCheckItem(rkrefMenuItems, IntToStr(DishCode1), FloatToStr(1)) // добавление блюда 1 else RKCheck.CreateCheckItem(rkrefMenuItems, IntToStr(DishCode2), FloatToStr(1)); // добавление блюда 2 end;
Последний скрипт необходимо назначить пользовательской процедуре и в свойствах выставить галочку «Контроль доступа» — «ограничение доступа к пользовательской операции»
В кассовых правах пользователей появится соответствующий пункт: «кассовые права работника»
На форме редактирования чека разместить таймер. Задать ему интервал равным 200 (это время срабатывания таймера). В событии OnTimer указать скрипт:
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 код автоматически добавляемого блюда 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 // удаление блюда при несоответствии требуемого количества бонусных блюд 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 // проверка необходимости добавления блюда if CntBonusDish = 0 then RKCheck.CreateCheckItem(rkrefMenuItems, IntToStr(BonusDishCode), IntToStr(trunc(CntDish / every))); end; end;
В период Пн-Пт с 18:01 до 03:00 и Сб-Вс с 10:00 до 03:00, при сумме заказа 1300 руб. (со скидкой), в заказ, вручную, будет на выбор добавляться одно из двух блюд, либо делаться скидка 10%.
Скрипт запрещает показ эти блюд на кассе, пока сумма заказа не будет равна 1300 руб.
На форме редактирования чека у объекта CheckView в событии OnBeforeCheckViewEdit указать скрипт:
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; // код акционной скидки DishCode1 := 45; // код контролируемого блюда DishCode2 := 46; // код контролируемого блюда qntMax := 1; // максимальное количество контролируемого блюда в заказе. Time1 := EncodeTime(10,00,00,00); // начало периода акции Time2 := EncodeTime(18,00,00,00); // конец периода акции LimitSim1 := 1300; // сумма чека превысив которую будет разрешено добавить бонусное блюдо. CurrTime := Time; checksum := 0; cntDisk := 0; //1 = воскресенье //2 = понедельник //3 = вторник //4 = среда //5 = четверг //6 = пятница //7 = суббота 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 // проверка дня недели if (Time1<=CurrTime)and(CurrTime<=Time2) then begin AAllow := true; AMessage := ''; checksum := RKCheck.CurrentOrder.ToPaySum; qntMax := trunc(checksum / LimitSim1); // qnt := TDish(AObjectAft).Quantity; // неверно отображает количество 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; // учёт акционной скидки 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;
Скрипт для таймера, размещаемого на форме редактирования чека:
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; // код акционной скидки DishCode1 := 45; // код контролируемого блюда DishCode2 := 46; // код контролируемого блюда qntMax := 1; // максимальное количество контролируемого блюда в заказе. Time1 := EncodeTime(10,00,00,00); // начало периода акции Time2 := EncodeTime(18,00,00,00); // конец периода акции LimitSum1 := 1300; // сумма чека превысив которую будет разрешено добавить бонусное блюдо. CurrTime := Time; cntDisk := 0; //1 = воскресенье //2 = понедельник //3 = вторник //4 = среда //5 = четверг //6 = пятница //7 = суббота 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 // проверка дня недели 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; // учёт акционной скидки 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); // удаление 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;
Скрипт для применения скидки:
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; // код акционной скидки DishCode1 := 45; // код контролируемого блюда DishCode2 := 46; // код контролируемого блюда qntMax := 1; // максимальное количество контролируемого блюда в заказе. Time1 := EncodeTime(10,00,00,00); // начало периода акции Time2 := EncodeTime(18,00,00,00); // конец периода акции LimitSum1 := 1300; // сумма чека превысив которую будет разрешено добавить бонусное блюдо. CurrTime := Time; cntDisk := 0; //1 = воскресенье //2 = понедельник //3 = вторник //4 = среда //5 = четверг //6 = пятница //7 = суббота if not RKCheck.Valid then exit //important checking else if (DayOfWeek(Now)>=2)and(DayOfWeek(Now)<=6) then // проверка дня недели 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; // учёт акционной скидки 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;
Все скрипты добавляются на форме редактирования чека
Объявление глобальной переменной в форме редактирования чека. Объявляется массив в который будут заноситься базовые блюда и идущие к ним упаковочные блюда:
var ModifArr: array of string;
Скрипт по добавлению блюд для указанного основного блюда.
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)); // добавление блюда с учётом количества основного блюда end; end; end;
Скрипт для добавления блюд всем ранее добавленным в заказ до добавления условного блюда «с собой»
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;
В процедуре OnAfterCheckViewEdit компонента CheckView проверяется добавляемое блюдо. Если оно указано в массиве, то к нему добавляются заданные упаковочные блюда. Проверка каждого добавляемого блюда.
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 - это код условного блюда "с собой" 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; // добавление паковочных блюд для всех ранее добавленных в заказ позиций 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;
На форме разместить таймер и в событии таймера указать скрипт, отслеживающий момент удаления условного блюда «с собой» для отключения режима паковки:
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;
Скрипт на событие OnShowScript компонента CheckView задаёт набор привязок упаковочных блюд к основным:
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;
На форме редактирования заказа разместить таймер и в его событии указать скрипт:
procedure userTimer1OnTimer(Sender: TObject); var i,CntDish1:integer; it: TCheckItem; begin // Проверка на корректный чек 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)); // код курса подачи RK7.PerformOperation(rkoDown, 0); RK7.PerformOperation(rkoServLineSelector, 0); RK7.PerformRefObject(RK7.FindItemByCode(rkrefKurses, 1)); // код курса подачи RK7.PerformOperation(rkoDown, 0); RK7.PerformOperation(rkoServLineSelector, 0); RK7.PerformRefObject(RK7.FindItemByCode(rkrefKurses, 3)); // код курса подачи RK7.PerformOperation(rkoDown, 0); end; end; end;
На форме редактирования чека разместить таймер, задать ему период 2 секунды и в событии OnTimer указать скрипт:
procedure userTimer1OnTimer(Sender: TObject); var i,CntDish1:integer; it: TCheckItem; begin // Проверка на корректный чек 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;
На форме редактироования чека разместить таймер, в событии которого указать скрипт:
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 // удаление блюда при несоответствии требуемого количества бонусных блюд 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 // проверка необходимости добавления блюда if CntDiscount > 0 then if CntBonusDish = 0 then RKCheck.CreateCheckItem(rkrefMenuItems, IntToStr(BonusDishCode), IntToStr(BonusDishQnt)); end; end;