-
Notifications
You must be signed in to change notification settings - Fork 324
[Shopify] Automatic Transaction Posting #6515
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Tautvydas-Labarauskas
wants to merge
2
commits into
microsoft:main
Choose a base branch
from
GediminasGaubys:dev/tla/transactions_auto_post
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/Apps/W1/Shopify/App/src/Transactions/Codeunits/ShpfyAutoGenJnlPost.Codeunit.al
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| // ------------------------------------------------------------------------------------------------ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. See License.txt in the project root for license information. | ||
| // ------------------------------------------------------------------------------------------------ | ||
|
|
||
| namespace Microsoft.Integration.Shopify; | ||
|
|
||
| using Microsoft.Finance.GeneralLedger.Journal; | ||
| using Microsoft.Finance.GeneralLedger.Posting; | ||
|
|
||
| /// <summary> | ||
| /// Codeunit Shpfy Auto Gen. Jnl.-Post (ID 30422). | ||
| /// </summary> | ||
| codeunit 30422 "Shpfy Auto Gen. Jnl.-Post" | ||
| { | ||
| EventSubscriberInstance = Manual; | ||
|
|
||
| [EventSubscriber(ObjectType::Codeunit, Codeunit::"Gen. Jnl.-Post", 'OnBeforeCode', '', false, false)] | ||
| local procedure OnBeforeCode(var GenJournalLine: Record "Gen. Journal Line"; var HideDialog: Boolean) | ||
| begin | ||
| HideDialog := true; | ||
| end; | ||
|
|
||
| [EventSubscriber(ObjectType::Codeunit, Codeunit::"Gen. Jnl.-Post", 'OnBeforeShowPostResultMessage', '', false, false)] | ||
| local procedure OnBeforeShowPostResultMessage(var GenJnlLine: Record "Gen. Journal Line"; TempJnlBatchName: Code[10]; var IsHandled: Boolean) | ||
| begin | ||
| IsHandled := true; | ||
| end; | ||
| } |
105 changes: 105 additions & 0 deletions
105
src/Apps/W1/Shopify/App/src/Transactions/Codeunits/ShpfyAutoPostTransactions.Codeunit.al
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| // ------------------------------------------------------------------------------------------------ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. See License.txt in the project root for license information. | ||
| // ------------------------------------------------------------------------------------------------ | ||
|
|
||
| namespace Microsoft.Integration.Shopify; | ||
|
|
||
| using Microsoft.Finance.GeneralLedger.Journal; | ||
| using Microsoft.Finance.GeneralLedger.Posting; | ||
| using Microsoft.Sales.History; | ||
|
|
||
| /// <summary> | ||
| /// Codeunit Shpfy Auto Post Transactions (ID 30236). | ||
| /// </summary> | ||
| codeunit 30236 "Shpfy Auto Post Transactions" | ||
| { | ||
| Access = Internal; | ||
|
|
||
| internal procedure AutoPostTransactions(SalesInvoiceHeaderNo: Code[20]; SalesCrMemoHeaderNo: Code[20]) | ||
| begin | ||
| if SalesInvoiceHeaderNo <> '' then | ||
| PostOrderTransaction(SalesInvoiceHeaderNo); | ||
| if SalesCrMemoHeaderNo <> '' then | ||
| PostRefundTransaction(SalesCrMemoHeaderNo); | ||
| end; | ||
|
|
||
| local procedure PostOrderTransaction(SalesInvoiceHeaderNo: Code[20]) | ||
| var | ||
| SalesInvoiceHeader: Record "Sales Invoice Header"; | ||
| OrderTransaction: Record "Shpfy Order Transaction"; | ||
| begin | ||
| if not SalesInvoiceHeader.Get(SalesInvoiceHeaderNo) then | ||
| exit; | ||
|
|
||
| if SalesInvoiceHeader."Shpfy Order Id" = 0 then | ||
| exit; | ||
|
|
||
| OrderTransaction.SetRange("Shopify Order Id", SalesInvoiceHeader."Shpfy Order Id"); | ||
| OrderTransaction.SetFilter(Type, '%1|%2', OrderTransaction.Type::Capture, OrderTransaction.Type::Sale); | ||
| PostTransaction(OrderTransaction, SalesInvoiceHeader."Posting Date"); | ||
| end; | ||
|
|
||
| local procedure PostRefundTransaction(SalesCrMemoHeaderNo: Code[20]) | ||
| var | ||
| SalesCrMemoHeader: Record "Sales Cr.Memo Header"; | ||
| OrderTransaction: Record "Shpfy Order Transaction"; | ||
| begin | ||
| if not SalesCrMemoHeader.Get(SalesCrMemoHeaderNo) then | ||
| exit; | ||
|
|
||
| if SalesCrMemoHeader."Shpfy Refund Id" = 0 then | ||
| exit; | ||
|
|
||
| OrderTransaction.SetRange("Refund Id", SalesCrMemoHeader."Shpfy Refund Id"); | ||
| OrderTransaction.SetRange(Type, OrderTransaction.Type::Refund); | ||
| PostTransaction(OrderTransaction, SalesCrMemoHeader."Posting Date"); | ||
| end; | ||
|
|
||
| local procedure PostTransaction(var OrderTransaction: Record "Shpfy Order Transaction"; PostingDate: Date) | ||
| begin | ||
| OrderTransaction.SetRange(Status, OrderTransaction.Status::Success); | ||
| OrderTransaction.SetRange(Used, false); | ||
| if OrderTransaction.FindSet() then | ||
| repeat | ||
| if ShouldAutoPost(OrderTransaction) then | ||
| CreateAndPostJournalLine(OrderTransaction, PostingDate); | ||
| until OrderTransaction.Next() = 0; | ||
| end; | ||
|
|
||
| local procedure ShouldAutoPost(OrderTransaction: Record "Shpfy Order Transaction"): Boolean | ||
| var | ||
| PaymentMethodMapping: Record "Shpfy Payment Method Mapping"; | ||
| begin | ||
| if not PaymentMethodMapping.Get(OrderTransaction.Shop, OrderTransaction.Gateway, OrderTransaction."Credit Card Company") then | ||
| exit(false); | ||
|
|
||
| if not PaymentMethodMapping."Post Automatically" then | ||
| exit(false); | ||
|
|
||
| if (PaymentMethodMapping."Auto-Post Jnl. Template" = '') or | ||
| (PaymentMethodMapping."Auto-Post Jnl. Batch" = '') then | ||
| exit(false); | ||
|
|
||
| exit(true); | ||
| end; | ||
|
|
||
| local procedure CreateAndPostJournalLine(var OrderTransaction: Record "Shpfy Order Transaction"; PostingDate: Date) | ||
| var | ||
| GenJournalLine: Record "Gen. Journal Line"; | ||
| PaymentMethodMapping: Record "Shpfy Payment Method Mapping"; | ||
| SuggestPayments: Report "Shpfy Suggest Payments"; | ||
| AutoGenJnlPost: Codeunit "Shpfy Auto Gen. Jnl.-Post"; | ||
| begin | ||
| PaymentMethodMapping.Get(OrderTransaction.Shop, OrderTransaction.Gateway, OrderTransaction."Credit Card Company"); | ||
| SuggestPayments.SetJournalParameters(PaymentMethodMapping."Auto-Post Jnl. Template", PaymentMethodMapping."Auto-Post Jnl. Batch", PostingDate); | ||
| SuggestPayments.GetOrderTransactions(OrderTransaction); | ||
| SuggestPayments.CreateGeneralJournalLines(); | ||
| GenJournalLine.SetRange("Shpfy Transaction Id", OrderTransaction."Shopify Transaction Id"); | ||
| if GenJournalLine.FindFirst() then begin | ||
| BindSubscription(AutoGenJnlPost); | ||
| GenJournalLine.SendToPosting(Codeunit::"Gen. Jnl.-Post"); | ||
| UnbindSubscription(AutoGenJnlPost); | ||
| end; | ||
| end; | ||
| } | ||
67 changes: 67 additions & 0 deletions
67
src/Apps/W1/Shopify/App/src/Transactions/Pages/ShpfyFilterTransactions.Page.al
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| // ------------------------------------------------------------------------------------------------ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. See License.txt in the project root for license information. | ||
| // ------------------------------------------------------------------------------------------------ | ||
|
|
||
| namespace Microsoft.Integration.Shopify; | ||
|
|
||
| /// <summary> | ||
| /// Page Shpfy Filter Transactions (ID 30176). | ||
| /// </summary> | ||
| page 30176 "Shpfy Filter Transactions" | ||
| { | ||
| Caption = 'Filter Postable Transactions'; | ||
| PageType = StandardDialog; | ||
| ApplicationArea = All; | ||
|
|
||
| layout | ||
| { | ||
| area(Content) | ||
| { | ||
| field(Gateway; Gateway) | ||
| { | ||
| Caption = 'Gateway'; | ||
| ToolTip = 'Specifies the transaction gateway to filter transactions by. Leave blank to include all gateways.'; | ||
| Editable = false; | ||
|
|
||
| trigger OnAssistEdit() | ||
| var | ||
| PaymentMethodMapping: Record "Shpfy Payment Method Mapping"; | ||
| begin | ||
| PaymentMethodMapping.SetRange("Post Automatically", true); | ||
| if Page.RunModal(0, PaymentMethodMapping) = Action::LookupOK then begin | ||
| ShopCode := PaymentMethodMapping."Shop Code"; | ||
| Gateway := PaymentMethodMapping.Gateway; | ||
| CreditCardCompany := PaymentMethodMapping."Credit Card Company"; | ||
| end; | ||
| end; | ||
| } | ||
| field(StartDate; StartDate) | ||
| { | ||
| Caption = 'Start Date'; | ||
| ToolTip = 'Specifies the earliest transaction creation date to include in the filter. Leave blank to include all transactions from the beginning.'; | ||
| } | ||
| field(EndDate; EndDate) | ||
| { | ||
| Caption = 'End Date'; | ||
| ToolTip = 'Specifies the latest transaction creation date to include in the filter. Leave blank to include all transactions.'; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| var | ||
| ShopCode: Code[20]; | ||
| Gateway: Text[30]; | ||
| CreditCardCompany: Text[50]; | ||
| StartDate: Date; | ||
| EndDate: Date; | ||
|
|
||
| internal procedure GetParameters(var NewShopCode: Code[20]; var NewGateway: Text[30]; var NewCreditCardCompany: Text[50]; var NewStartDate: DateTime; var NewEndDate: DateTime) | ||
| begin | ||
| NewShopCode := ShopCode; | ||
| NewGateway := Gateway; | ||
| NewCreditCardCompany := CreditCardCompany; | ||
| NewStartDate := CreateDateTime(StartDate, 0T); | ||
| NewEndDate := CreateDateTime(EndDate, 0T); | ||
| end; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If Post with Job Queue is enabled on the GLSetup then the lines won't be posted directly and the lines might be deleted before the actual posting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, changed that not used lines (appears if error occurs during posting) would be deleted before generating new ones in "Suggest Shopify Payments" report.





What this changes, previously each time "Suggest Shopify Payments" report would be executed but lines not posted new gen journal line would be created
Executed first time:
Executed second time:
After this change old ones will always be removed, hope that is acceptable