Skip to content

Commit

Permalink
Add rewards extension
Browse files Browse the repository at this point in the history
  • Loading branch information
blrobl committed Sep 12, 2024
1 parent 10632f8 commit d4698d2
Show file tree
Hide file tree
Showing 19 changed files with 1,154 additions and 0 deletions.
15 changes: 15 additions & 0 deletions LoyaltyRewards/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"configurations": [
{
"name": "AL: Generated Snapshot request",
"request": "snapshotInitialize",
"type": "al",
"environmentType": "Production",
"environmentName": "app54412_plat23769_US_26-0",
"sessionId": 4640,
"breakOnNext": "WebClient",
"executionContext": "DebugAndProfile",
"tenant": "ffa32acf-5c71-4055-a4fe-6ad1d3526060"
}
]
}
43 changes: 43 additions & 0 deletions LoyaltyRewards/AttachmentExtension.Codeunit.al
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
codeunit 50123 "Attachment Extension"
{
[EventSubscriber(ObjectType::Page, Page::"Document Attachment Factbox", 'OnBeforeDrillDown', '', true, true)]
local procedure OnBeforeDrillDown(DocumentAttachment: Record "Document Attachment"; var RecRef: RecordRef)
var
Reward: Record Reward;
begin
if DocumentAttachment."Table ID" <> Database::"Reward" then
exit;

RecRef.Open(Database::Reward);
if Reward.Get(DocumentAttachment."No.") then
RecRef.GetTable(Reward);
end;

[EventSubscriber(ObjectType::Page, Page::"Document Attachment Details", 'OnAfterOpenForRecRef', '', true, true)]
local procedure OnAfterOpenForRecRef(var DocumentAttachment: Record "Document Attachment"; var RecRef: RecordRef; var FlowFieldsEditable: Boolean)
var
FieldRef: FieldRef;
RecNo: Code[20];
begin
if RecRef.Number <> Database::"Reward" then
exit;

FieldRef := RecRef.Field(1);
RecNo := FieldRef.Value;
DocumentAttachment.SetRange("No.", RecNo);
end;

[EventSubscriber(ObjectType::Table, Database::"Document Attachment", 'OnAfterInitFieldsFromRecRef', '', true, true)]
local procedure OnAfterInitFieldsFromRecRef(var DocumentAttachment: Record "Document Attachment"; var RecRef: RecordRef)
var
FieldRef: FieldRef;
RecNo: Code[20];
begin
if RecRef.Number <> Database::"Reward" then
exit;

FieldRef := RecRef.Field(1);
RecNo := FieldRef.Value;
DocumentAttachment.Validate("No.", RecNo);
end;
}
93 changes: 93 additions & 0 deletions LoyaltyRewards/CardExtensionBackup.Codeunit.al
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// codeunit 50124 "Card Extension Backup"
// {
// [EventSubscriber(ObjectType::Codeunit, Codeunit::"Page Summary Provider", 'OnAfterGetSummaryFields', '', false, false)]
// local procedure OnAfterGetSummaryFields(PageId: Integer; RecId: RecordId; var FieldList: List of [Integer])
// var
// Customer: Record Customer;
// begin
// if PageId <> Page::"Customer Card" then
// exit;

// // Remove Balance details
// if (FieldList.Contains(Customer.FieldNo("Balance Due (LCY)"))) then
// FieldList.Remove(Customer.FieldNo("Balance Due (LCY)"));

// if (FieldList.Contains(Customer.FieldNo("Balance (LCY)"))) then
// FieldList.Remove(Customer.FieldNo("Balance (LCY)"));

// // Add RewardID
// FieldList.Add((Customer.FieldNo("Reward ID")));

// // Add City, Phone number and Email
// FieldList.Add(Customer.FieldNo("City"));
// FieldList.Add(Customer.FieldNo("Mobile Phone No."));
// FieldList.Add(Customer.FieldNo("E-Mail"));

// end;

// [EventSubscriber(ObjectType::Codeunit, Codeunit::"Page Summary Provider", 'OnBeforeGetPageSummary', '', false, false)]
// local procedure OnBeforeGetPageSummary(PageId: Integer; RecId: RecordId; FieldsJsonArray: JsonArray; var Handled: Boolean)
// var
// Customer: Record Customer;
// begin
// if PageId <> Page::"Customer Card" then
// exit;

// if not Customer.Get(RecId) then
// exit;

// AddField(FieldsJsonArray, 'Name', Customer.Name, 'Text');
// AddField(FieldsJsonArray, 'Phone No.', Customer."Phone No.", 'Text');
// If Customer."Reward ID" = 'Gold' then
// AddField(FieldsJsonArray, 'Priority', 'Very High', 'Text');
// AddField(FieldsJsonArray, 'Address', Customer.Address, 'Text');

// Handled := true;
// end;

// [EventSubscriber(ObjectType::Codeunit, Codeunit::"Page Summary Provider", 'OnAfterGetPageSummary', '', false, false)]
// local procedure OnAfterGetPageSummary(PageId: Integer; RecId: RecordId; var FieldsJsonArray: JsonArray)
// var
// FieldJsonToken: JsonToken;
// CaptionToken: JsonToken;
// ValueToken: JsonToken;
// RewardID: Code[50];
// fieldNo: Integer;
// begin
// if PageId <> Page::"Customer Card" then
// exit;

// // find Reward Id and change it to corresponding discount percentage
// for fieldNo := 0 to FieldsJsonArray.Count() - 1 do begin
// FieldsJsonArray.Get(fieldNo, FieldJsonToken);
// FieldJsonToken.AsObject().Get('caption', CaptionToken);
// if CaptionToken.AsValue().AsText() = 'Reward ID' then begin
// FieldJsonToken.AsObject().Get('fieldValue', ValueToken);
// RewardID := ValueToken.AsValue().AsText();
// AddDiscountPercentage(FieldJsonToken, RewardID);
// exit;
// end;
// end;
// end;

// local procedure AddDiscountPercentage(var FieldJsonToken: JsonToken; RewardID: Code[30])
// var
// Reward: Record Reward;
// begin
// if not Reward.Get(RewardID) then
// exit;

// FieldJsonToken.AsObject().Replace('caption', 'Loyalty Discount %');
// FieldJsonToken.AsObject().Replace('fieldValue', Reward."Discount Percentage");
// end;

// local procedure AddField(var FieldsJsonArray: JsonArray; Caption: Text; FieldValue: Text; FieldType: Text)
// var
// FieldsJsonObject: JsonObject;
// begin
// FieldsJsonObject.Add('caption', Caption);
// FieldsJsonObject.Add('fieldValue', FieldValue);
// FieldsJsonObject.Add('fieldType', FieldType);
// FieldsJsonArray.Add(FieldsJsonObject);
// end;
// }
93 changes: 93 additions & 0 deletions LoyaltyRewards/CardExtensionBackup.al
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// codeunit 50124 "Card Extension Backup"
// {
// [EventSubscriber(ObjectType::Codeunit, Codeunit::"Page Summary Provider", 'OnAfterGetSummaryFields', '', false, false)]
// local procedure OnAfterGetSummaryFields(PageId: Integer; RecId: RecordId; var FieldList: List of [Integer])
// var
// Customer: Record Customer;
// begin
// if PageId <> Page::"Customer Card" then
// exit;

// // Remove Balance details
// if (FieldList.Contains(Customer.FieldNo("Balance Due (LCY)"))) then
// FieldList.Remove(Customer.FieldNo("Balance Due (LCY)"));

// if (FieldList.Contains(Customer.FieldNo("Balance (LCY)"))) then
// FieldList.Remove(Customer.FieldNo("Balance (LCY)"));

// // Add RewardID
// FieldList.Add((Customer.FieldNo("Reward ID")));

// // Add City, Phone number and Email
// FieldList.Add(Customer.FieldNo("City"));
// FieldList.Add(Customer.FieldNo("Mobile Phone No."));
// FieldList.Add(Customer.FieldNo("E-Mail"));

// end;

// [EventSubscriber(ObjectType::Codeunit, Codeunit::"Page Summary Provider", 'OnBeforeGetPageSummary', '', false, false)]
// local procedure OnBeforeGetPageSummary(PageId: Integer; RecId: RecordId; FieldsJsonArray: JsonArray; var Handled: Boolean)
// var
// Customer: Record Customer;
// begin
// if PageId <> Page::"Customer Card" then
// exit;

// if not Customer.Get(RecId) then
// exit;

// AddField(FieldsJsonArray, 'Name', Customer.Name, 'Text');
// AddField(FieldsJsonArray, 'Phone No.', Customer."Phone No.", 'Text');
// If Customer."Reward ID" = 'Gold' then
// AddField(FieldsJsonArray, 'Priority', 'Very High', 'Text');
// AddField(FieldsJsonArray, 'Address', Customer.Address, 'Text');

// Handled := true;
// end;

// [EventSubscriber(ObjectType::Codeunit, Codeunit::"Page Summary Provider", 'OnAfterGetPageSummary', '', false, false)]
// local procedure OnAfterGetPageSummary(PageId: Integer; RecId: RecordId; var FieldsJsonArray: JsonArray)
// var
// FieldJsonToken: JsonToken;
// CaptionToken: JsonToken;
// ValueToken: JsonToken;
// RewardID: Code[50];
// fieldNo: Integer;
// begin
// if PageId <> Page::"Customer Card" then
// exit;

// // find Reward Id and change it to corresponding discount percentage
// for fieldNo := 0 to FieldsJsonArray.Count() - 1 do begin
// FieldsJsonArray.Get(fieldNo, FieldJsonToken);
// FieldJsonToken.AsObject().Get('caption', CaptionToken);
// if CaptionToken.AsValue().AsText() = 'Reward ID' then begin
// FieldJsonToken.AsObject().Get('fieldValue', ValueToken);
// RewardID := ValueToken.AsValue().AsText();
// AddDiscountPercentage(FieldJsonToken, RewardID);
// exit;
// end;
// end;
// end;

// local procedure AddDiscountPercentage(var FieldJsonToken: JsonToken; RewardID: Code[30])
// var
// Reward: Record Reward;
// begin
// if not Reward.Get(RewardID) then
// exit;

// FieldJsonToken.AsObject().Replace('caption', 'Loyalty Discount %');
// FieldJsonToken.AsObject().Replace('fieldValue', Reward."Discount Percentage");
// end;

// local procedure AddField(var FieldsJsonArray: JsonArray; Caption: Text; FieldValue: Text; FieldType: Text)
// var
// FieldsJsonObject: JsonObject;
// begin
// FieldsJsonObject.Add('caption', Caption);
// FieldsJsonObject.Add('fieldValue', FieldValue);
// FieldsJsonObject.Add('fieldType', FieldType);
// FieldsJsonArray.Add(FieldsJsonObject);
// end;
// }
29 changes: 29 additions & 0 deletions LoyaltyRewards/Customer.TableExt.al
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
tableextension 50103 "Customer Ext" extends Customer
{
fields
{
field(50100; "Reward ID"; Code[30])
{
TableRelation = Reward."Reward ID";
ToolTip = 'Specifies the level of reward that the customer has at this point.';

trigger OnValidate();
begin
// If the "Reward ID" changed and the new record is blocked, an error is thrown.
if (Rec."Reward ID" <> xRec."Reward ID") and
(Rec.Blocked <> Blocked::" ") then begin
Error('Cannot update the rewards status of a blocked customer.')
end;
end;
}
}

fieldgroups
{
// The Brick field group specifies which fields of the table will display in a Teams card.
// Except media data type fields, the order of fields on the teams card is determined by the field order in the Brick field group
// addlast(Brick; "Reward ID")
// {
// }
}
}
41 changes: 41 additions & 0 deletions LoyaltyRewards/CustomerCard.PageExt.al
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
pageextension 50104 "Customer Card Ext" extends "Customer Card"
{
layout
{
addlast(General)
{
field("Reward ID"; Rec."Reward ID")
{
ApplicationArea = All;
Lookup = true;
ToolTip = 'Specifies the level of reward that the customer has at this point.';
LookupPageId = "Reward List";
trigger OnValidate()
begin
If Rec."Reward ID" = 'GOLD' then
OnCustomerReachedGoldLevel(Rec);
end;
}
}
}

actions
{
addfirst(Navigation)
{
action("Rewards")
{
ApplicationArea = All;
RunObject = page "Reward List";
}
}
}

[IntegrationEvent(false, false)]
local procedure OnCustomerReachedGoldLevel(Customer: Record Customer)
begin
end;


}

16 changes: 16 additions & 0 deletions LoyaltyRewards/CustomerExt.PageExt.al
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
pageextension 50107 "Customer Page Ext" extends "Customer List"
{
layout
{
addlast(Control1)
{
field("Reward ID"; Rec."Reward ID")
{
ApplicationArea = All;
Lookup = true;
ToolTip = 'Specifies the level of reward that the customer has at this point.';
LookupPageId = "Reward List";
}
}
}
}
Loading

0 comments on commit d4698d2

Please sign in to comment.