Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagedelphi
procedure AddEveryOtherDiscount(DiscCode: integer);

var i, j, k: integer;

it, CurItem: TCheckItem;

SL: TStringList;

a, q, Price: double;

d: TDish;

CheckView: TCheckView;

Categ: TClassificatorGroup;

begin

CheckView := TCheckView(GUI.FindComponentByName('CheckView'));

if CheckView = Nil then Exit;

CurItem := RKCheck.CurrentCheckItem;

SL := TStringList.Create;

try

// Create list of the dishes, as is

SL.Sorted := False;

for i := 0 to RKCheck.CurrentOrder.Sessions.LinesCount - 1 do

begin

it := RKCheck.CurrentOrder.Sessions.Lines[i];

Categ := TClassificatorGroup(getitemBycodeNum('ClassificatorGroups', 5)); //5 - category code

if SYS.ObjectInheritsFrom(TObject(it), 'TDish') then //Check dish lines only

if Categ.IsChild(it.RefItem) then //Check category of the dish

if ((it.State = disOpened) or (it.State = disPrinted)) then

begin

if (TDish(it).Quantity = 0) or (TDish(it).PRListSum = 0) then Price := TDish(it).Price

else Price := TDish(it).PRListSum/TDish(it).Quantity;

SL.AddObject(FormatFloat('00000000.00', Price) + IntToStr(TDish(it).UNI),

TObject(it));

end;

end;

//Magic

k:= -1;

q:=0;

for i:= 0 to SL.Count - 1 do

begin

d:= TDish(SL.Objects[i]);

a:= 0;

q:=q+ d.Quantity;

if (d.Quantity = 0) or (d.PRListSum = 0) then Price := d.Price

else Price := d.PRListSum/d.Quantity;

if q + 0.0001 > 2 then

if k = -1 then

begin

a:= a + Price*0.15; //0.15=15% discount

k:= 0;

end;

// Delete discount, if a sum changed

for j := RKCheck.CheckItemCount(TObject(d.Discounts)) - 1 downto 0 do

begin

it := RKCheck.CheckItemByNumber(TObject(d.Discounts), j);

if (it.Code = DiscCode) then

begin

if abs(TDiscountItem(it).SrcAmount) = a then a := 0

else RKCheck.DeleteCheckItem(it);

break;

end;

end;

// Create discount to a dish

if a > 0 then

begin

CheckView.GotoItem(TObject(d));

RKCheck.CreateCheckItem(rkrefDiscounts, IntToStr(DiscCode), FloatToStr(a));

end;

end;

finally

SL.Free();

if CurItem <> Nil then CheckView.GotoItem(CurItem);

end;

RKCheck.CurrentOrder.Recalc();

end;

A script to add a 100% discount on dishes of a certain category, if there is a dish with the code

...

«N»

When a dish with the code "N" «N» is added to a new order, a 100% discount is assigned to dishes of a certain category. If a dish with the "N" «N» code is deleted, the free dishes are deleted as well.

...

Note

The script only works with the input of dishes in a separate line. It is configured in the properties of the dish: Servings — Add to order = "Separate line for each serving". The discount should be applied to a dish only.

A script for the promotion

...

«Second course at a lower (or the same) price with a 50%

...

discount»

Code Block
languagedelphi
procedure AddEveryOtherDiscount(DiscCode: integer);
 
var i, j, k: integer;
 
it, CurItem: TCheckItem;
 
SL: TStringList;
 
a, q, Price: double;
 
d: TDish;
 
CheckView: TCheckView;
 
Categ: TClassificatorGroup;
 
begin
 
CheckView := TCheckView(GUI.FindComponentByName('CheckView'));
 
if CheckView = Nil then Exit;
 
CurItem := RKCheck.CurrentCheckItem;
 
SL := TStringList.Create;
 
try
 
// Create list of the dishes, sorted by price
 
SL.Sorted := True;
 
for i := 0 to RKCheck.CurrentOrder.Sessions.LinesCount - 1 do
 
begin
 
it := RKCheck.CurrentOrder.Sessions.Lines\[i\];
 
Categ := TClassificatorGroup(getitemBycodeNum('ClassificatorGroups', 44)); //44 - category code
 
if SYS.ObjectInheritsFrom(TObject(it), 'TDish') then //Check dish lines only
 
if Categ.IsChild(it.RefItem) then //Check category of the dish
 
if TDish(it).Quantity > 0 then
 
// if ((it.State = disOpened) or (it.State = disPrinted)) then
 
begin
 
if (TDish(it).Quantity = 0) or (TDish(it).PRListSum = 0) then Price := TDish(it).Price
 
else Price := TDish(it).PRListSum/TDish(it).Quantity;
 
SL.AddObject(FormatFloat('00000000.00', 100000000-Price) + IntToStr(TDish(it).UNI),
 
TObject(it));
 
end;
 
end;
 
//Magic
 
k:= 0; / / -1 to start with the first course
 
q:=0;
 
for i:= 0 to SL.Count - 1 do
 
begin
 
d:= TDish(SL.Objects\[i\]);
 
a:= 0;
 
q:=q+ d.Quantity;
 
if (d.Quantity = 0) or (d.PRListSum = 0) then Price := d.Price
 
else Price := d.PRListSum/d.Quantity;
 
if k = -1 then
 
begin
 
a:= a + Price*0.5; //0.5=50% discount
 
k:= 0;
 
end
 
else k := -1;
 
// Delete discount, if a sum changed
 
for j := RKCheck.CheckItemCount(TObject(d.Discounts)) - 1 downto 0 do
 
begin
 
it := RKCheck.CheckItemByNumber(TObject(d.Discounts), j);
 
if (it.Code = DiscCode) then
 
begin
 
if abs(TDiscountItem(it).SrcAmount) = a then a := 0
 
else RKCheck.DeleteCheckItem(it);
 
break;
 
end;
 
end;
 
// Create discount to a dish
 
if a > 0 then
 
begin
 
CheckView.GotoItem(TObject(d));
 
RKCheck.CreateCheckItem(rkrefDiscounts, IntToStr(DiscCode), FloatToStr(a));
 
end;
 
end;
 
finally
 
SL.Free();
 
if CurItem <> Nil then CheckView.GotoItem(CurItem);
 
end;
 
RKCheck.CurrentOrder.Recalc();
 
end;
 
procedure CheckViewCurItemChangedScript(Sender: TObject);
 
begin
 
AddEveryOtherDiscount(15);
 
end;
 
 
procedure CheckViewOnAfterCheckViewEdit(Sender: TObject; AEditType: TEditType; AObjectBef, AObjectAft: TObject);
 
begin
 
AddEveryOtherDiscount(15);
 
end;
 
 
procedure userTimer1OnTimer(Sender: TObject);
 
var CheckView: TCheckView;
 
begin
 
// Checking valid check
 
CheckView := TCheckView(GUI.FindComponentByName('CheckView'));
 
if CheckView = Nil then Exit;
 
if not RKCheck.Valid then Exit;
 
if (GUI.CheckFormInPayMode) then exit;
 
AddEveryOtherDiscount(22);
 
end;

...