A script to create a markup on an order with a discount

You need to set up a service markup that will be applied to the discounted order amount.

On the receipt editing form, specify the script in the OnOperation event:

procedure DesignFormOnOperation(Sender: TBasePanel; Operation, Param: integer; var res: integer);

And insert the following script above it:

procedure AddEveryOtherDiscount(DiscCode: integer);

var i, j: integer;

    it, CurItem: TCheckItem;

    a, PriceSum, DiscountSum, DiscPerc: double;

    CheckView: TCheckView;

begin

  DiscPerc := 10; // 10%

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

  if CheckView = Nil then Exit;

  CurItem   := RKCheck.CurrentCheckItem;

  try

    PriceSum := 0;

    DiscountSum := 0;

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

    begin

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

      if SYS.ObjectInheritsFrom(TObject(it), 'TDiscountItem') then

        if TDiscountItem(it).code <> DiscCode then

          DiscountSum := DiscountSum + TDiscountItem(it).CalcAmount;

    end;

    PriceSum := RKCheck.CurrentOrder.PriceListSum;


    a:= (PriceSum + DiscountSum)*DiscPerc/100;      // "+" because the discount amount with the "-" sign

    // 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

          if TDiscountItem(it).code = DiscCode then

          begin

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

            else

            begin

              RKCheck.DeleteCheckItem(it);

            end

            break;

          end;

      end;


    // Create discount to a dish

    if a > 0 then

    begin

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

    end;

  finally

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

  end;

  RKCheck.CurrentOrder.Recalc();

end;


procedure DesignFormOnOperation(Sender: TBasePanel; Operation, Param: integer; var res: integer);

begin

  if (operation = 420)  // 420 - Calculate a check

   or(operation = 455)  // 455 - Pay a check

  then  

  begin

    AddEveryOtherDiscount(14);  //  markup code

end;

A script to divide the receipt by currency, depending on the dishes classification

Insert the script on the order editing form in the OnOperation event of the DesignForm object

procedure DesignFormOnOperation(Sender: TBasePanel; Operation, Param: integer; var res: integer);

var i, CurrencyCodeForChange,CurrencyCode1,CurrencyCode2, CategCode1,CategCode2: integer;

    CurrencyCodeForChangeSum,CurrencyCode1Sum,CurrencyCode2Sum, Categ1Sum,Categ2Sum: double;

    it: TCheckItem;

    Categ1, Categ2: TClassificatorGroup;

begin

  //********** Set parameters  ***********//

  CurrencyCodeForChange := 1;   // currency code for change

  CurrencyCode1 := 18;   // currency code(category 1)

  CurrencyCode2 := 17;   // currency code(category 2)

  CategCode1 := 1;     // category 1 code

  CategCode2 := 8;     // category 2 code

  //********** Set parameters  ***********//


  CurrencyCodeForChangeSum := 0;

  CurrencyCode1Sum := 0;

  CurrencyCode2Sum := 0;

  Categ1Sum := 0;

  Categ2Sum := 0;

  Categ1 := TClassificatorGroup(getitemBycodeNum('ClassificatorGroups', CategCode1));

  Categ2 := TClassificatorGroup(getitemBycodeNum('ClassificatorGroups', CategCode2));


  if operation = 459 then

    begin

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

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

        if SYS.ObjectInheritsFrom(TObject(it), 'TPayLine') then

          if (it.Code = CurrencyCodeForChange) then

            CurrencyCodeForChangeSum := CurrencyCodeForChangeSum + TPayLine(it).NationalSum;

        if SYS.ObjectInheritsFrom(TObject(it), 'TPayLine') then

          if (it.Code = CurrencyCode1) then

            CurrencyCode1Sum := CurrencyCode1Sum + TPayLine(it).NationalSum;           

        if SYS.ObjectInheritsFrom(TObject(it), 'TPayLine') then

          if (it.Code = CurrencyCode2) then

            CurrencyCode2Sum := CurrencyCode2Sum + TPayLine(it).NationalSum;           

        if SYS.ObjectInheritsFrom(TObject(it), 'TDish') then

          if Categ1.IsChild(it.RefItem) then

            if (TDish(it).Quantity > 0) then

              Categ1Sum := Categ1Sum + TDish(it).PRListSum;

        if SYS.ObjectInheritsFrom(TObject(it), 'TDish') then

          if Categ2.IsChild(it.RefItem) then

            if (TDish(it).Quantity > 0) then

              Categ2Sum := Categ2Sum + TDish(it).PRListSum;

      end;

    end;

  if (CurrencyCode1Sum=0.0) and (CurrencyCode2Sum=0.0) then

    if (CurrencyCodeForChangeSum>0) and (CurrencyCodeForChangeSum=(Categ1Sum+Categ2Sum)) then

    begin

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

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

        if SYS.ObjectInheritsFrom(TObject(it), 'TPayLine') then

          if (it.Code = CurrencyCodeForChange) then

            RKCheck.DeleteCheckItem(it);

      end;

      if Categ1Sum>0 then

        RKCheck.CreateCheckItem(rkrefCurrencies, inttostr(CurrencyCode1), floattoStr(Categ1Sum));

      if Categ2Sum>0 then

        RKCheck.CreateCheckItem(rkrefCurrencies, inttostr(CurrencyCode2), floattoStr(Categ2Sum));

    end;

end;

A script to make the "Prepayment" button temporarily inactive

Insert the script in the OnOperation property of the form:

procedure DesignFormOnOperation(Sender: TBasePanel; Operation, Param: integer; var res: integer);

var   ed: TObject;

begin

  if (Operation=rkoPrepaySelector) then

  begin

    ed := TObject(gui.FindComponentByName('Editor'));

    if SYS.ObjectInheritsFrom(TObject(ed), 'TNumEditor') then

      if 0.0 >= StrToFloat(TNumEditor(ed).Text) then  

        gui.showmessage('Amount is not specified!!!');

    end;

end;

A warning will be displayed when you click the «Prepayment» button.

Скрипт, измененяющий логику пожертвований

It is necessary to add the following functionality for accepting donations:

  1. When you click the «Pay» button, a pop-up appears asking if the guest wants to donate money. Answer options — «Yes» or «No».
  2. When you click «Yes», you will be redirected to the menu catalog with the donation.
  3. When you click «No», you will switch to the payment mode.

A script for the OnOperation event of the main screen form:

procedure DesignFormOnOperation(Sender: TBasePanel; Operation, Param: integer; var res: integer);

begin

  if Operation = 455 then  //   operation code verification - payment  {455 420}

    if RKCheck.CurrentOrder.UserTag1 <> 1 then  // verification if this dialog has been shown before

    begin

      if GUI.RKMessageDlg('Is the guest willing to donate?', 0, 3, 100000) = 6 then

      begin

        RK7.PerformRefObject(RK7.FindItemByCode(rkrefCategList, 22));  // {Menu group code}

        res := 1;

      end;

      RKCheck.CurrentOrder.UserTag1 := 1;  // tag to avoid dialog reopening

    end; 

end;

A script to create a discount on each first course in the receipt for a certain period of time

On the receipt editing form of the main form, insert the script in the OnOperation event:

procedure DesignFormOnOperation(Sender: TBasePanel; Operation, Param: integer; var res: integer);

begin

  dbg.dbgprint('Operation '+IntToStr(Operation));

  if Operation = 459 then   // payment operation code

    AddEveryOtherDiscount(11);   // calling the procedure for calculating the discount with the indicated code of the open fixed amount discount for the dish

end;

But before this script, insert the procedure:

procedure AddEveryOtherDiscount(DiscCode: integer);

var

    i, j, k, PresentCnt: integer;

    it, CurItem: TCheckItem;

    SL: TStringList;

    a, CalcDiscount, q, Price, DiscPrc: double;

    d: TDish;

    CheckView: TCheckView;

    CurrTime, Time1, Time2: TDateTime; 

begin

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

  if CheckView = Nil then Exit;

//********** Set parameters  ***********//

  DiscPrc := 0.5;    // discount percentage in shares

  Time1 := EncodeTime(10,00,00,00);  // promotion period beginning

  Time2 := EncodeTime(18,00,00,00);  // promotion period ending

//********** Set parameters  ***********//

  CurrTime := Time;

//1 = Sunday

//2 = Monday

//3 = Tuesday

//4 = Wednesday

//5 = Thursday

//6 = Friday

//7 = Saturday

  CurItem   := RKCheck.CurrentCheckItem;

  if (DayOfWeek(Now)>=2)and(DayOfWeek(Now)<=6) then                                // week day check

  if (Time1<=CurrTime) and(CurrTime<=Time2) then                                   // time check

  begin

      SL        := TStringList.Create;

      try

        // Create list of the dishes, as is

        SL.Sorted := True;

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

        begin

          PresentCnt := 0;

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

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

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

          begin

            for j:= 0 to SL.Count - 1 do  // cheking present dish in list

            begin 

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

              if (TDish(it).Code = TDish(d).Code) then

                PresentCnt := PresentCnt + 1;

            end;

            if PresentCnt = 0 then       // adding dish to list`

            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;

        end;

      //Magic

        k:= -1;

        q:=0;

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

        begin

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

          CalcDiscount:= 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

              CalcDiscount:= CalcDiscount + Price*DiscPrc; // DiscPrc % discount

            end;

        // Delete discount, if CalcDiscount 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) = CalcDiscount then CalcDiscount := 0

              else RKCheck.DeleteCheckItem(it);

                break;

            end;

          end;

        // Create discount to CalcDiscount dish

          if CalcDiscount > 0 then

          begin

            CheckView.GotoItem(TObject(d));

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

          end;

        end;

      finally

        SL.Free();

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

      end;

  end;

  RKCheck.CurrentOrder.Recalc();

end;

  • No labels