-
Notifications
You must be signed in to change notification settings - Fork 696
Expand file tree
/
Copy pathLibraryCashFlow.Codeunit.al
More file actions
159 lines (140 loc) · 6.46 KB
/
LibraryCashFlow.Codeunit.al
File metadata and controls
159 lines (140 loc) · 6.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/// <summary>
/// Provides utility functions for creating and managing cash flow forecasts and related test scenarios.
/// </summary>
codeunit 131331 "Library - Cash Flow"
{
trigger OnRun()
begin
end;
var
LibraryUtility: Codeunit "Library - Utility";
LibraryERM: Codeunit "Library - ERM";
LibrarySales: Codeunit "Library - Sales";
LibraryRandom: Codeunit "Library - Random";
procedure FindCashFlowCard(var CashFlowForecast: Record "Cash Flow Forecast")
begin
CashFlowForecast.FindFirst();
end;
procedure FindCashFlowAccount(var CashFlowAccount: Record "Cash Flow Account")
begin
CashFlowAccount.SetRange("Account Type", CashFlowAccount."Account Type"::Entry);
CashFlowAccount.FindFirst();
end;
procedure FindCashFlowAnalysisView(var AnalysisView: Record "Analysis View")
begin
AnalysisView.Reset();
AnalysisView.SetRange("Account Source", AnalysisView."Account Source"::"Cash Flow Account");
AnalysisView.FindFirst();
end;
procedure CreateJournalLine(var CFWorksheetLine: Record "Cash Flow Worksheet Line"; CFNo: Code[20]; CFAccountNo: Code[20])
var
LibraryUtility: Codeunit "Library - Utility";
RecRef: RecordRef;
begin
RecRef.GetTable(CFWorksheetLine);
CFWorksheetLine.Validate("Line No.", LibraryUtility.GetNewLineNo(RecRef, CFWorksheetLine.FieldNo("Line No.")));
CFWorksheetLine.Insert(true);
CFWorksheetLine.Validate("Cash Flow Forecast No.", CFNo);
CFWorksheetLine.Validate("Cash Flow Account No.", CFAccountNo);
CFWorksheetLine.Validate("Cash Flow Date", WorkDate()); // Defaults to work date.
CFWorksheetLine.Modify(true);
end;
procedure DeleteJournalLine()
begin
end;
procedure FillJournal(ConsiderSource: array[16] of Boolean; CFNo: Code[20]; GroupByDocumentType: Boolean)
var
CFWorksheetLine: Record "Cash Flow Worksheet Line";
SuggestWorksheetLines: Report "Suggest Worksheet Lines";
begin
CFWorksheetLine.Init();
SuggestWorksheetLines.InitializeRequest(ConsiderSource, CFNo, '', GroupByDocumentType);
SuggestWorksheetLines.UseRequestPage := false;
SuggestWorksheetLines.Run();
end;
procedure FillBudgetJournal(CFFunds: Boolean; CFNo: Code[20]; GLBudgetName: Code[10])
var
CFWorksheetLine: Record "Cash Flow Worksheet Line";
SuggestWorksheetLines: Report "Suggest Worksheet Lines";
ConsiderSource: array[16] of Boolean;
SourceType: Option ,Customer,Vendor,"Liquid Funds","Cash Flow Manual Expense","Cash Flow Manual Revenue","Sales Order","Purchase Order","Budgeted Fixed Asset","Sale of Fixed Asset","Service Order","G/L Budget",,,Jobs,Tax;
begin
CFWorksheetLine.Init();
ConsiderSource[SourceType::"Liquid Funds"] := CFFunds;
ConsiderSource[SourceType::"G/L Budget"] := true;
SuggestWorksheetLines.InitializeRequest(ConsiderSource, CFNo, GLBudgetName, false);
SuggestWorksheetLines.UseRequestPage := false;
SuggestWorksheetLines.Run();
end;
procedure ClearJournal()
var
CFWorksheetLine: Record "Cash Flow Worksheet Line";
begin
CFWorksheetLine.DeleteAll(true);
end;
procedure PostJournal()
var
CFWorksheetLine: Record "Cash Flow Worksheet Line";
begin
CODEUNIT.Run(CODEUNIT::"Cash Flow Wksh.-Register Batch", CFWorksheetLine);
end;
procedure PostJournalLines(var CFWorksheetLine: Record "Cash Flow Worksheet Line")
begin
CFWorksheetLine.FindSet();
CODEUNIT.Run(CODEUNIT::"Cash Flow Wksh.-Register Batch", CFWorksheetLine);
end;
procedure CreateManualLinePayment(var CFManualExpense: Record "Cash Flow Manual Expense"; CFAccountNo: Code[20])
begin
CFManualExpense.Init();
CFManualExpense.Validate("Cash Flow Account No.", CFAccountNo);
CFManualExpense.Validate(Code,
LibraryUtility.GenerateRandomCode(CFManualExpense.FieldNo(Code), DATABASE::"Cash Flow Manual Expense"));
CFManualExpense.Validate("Starting Date", WorkDate()); // Required field to post
CFManualExpense.Insert(true);
end;
procedure CreateManualLineRevenue(var CFManualRevenue: Record "Cash Flow Manual Revenue"; CFAccountNo: Code[20])
begin
CFManualRevenue.Init();
CFManualRevenue.Validate("Cash Flow Account No.", CFAccountNo);
CFManualRevenue.Validate(Code,
LibraryUtility.GenerateRandomCode(CFManualRevenue.FieldNo(Code), DATABASE::"Cash Flow Manual Revenue"));
CFManualRevenue.Validate("Starting Date", WorkDate()); // Required field to post
CFManualRevenue.Insert(true);
end;
procedure DeleteManualLine()
begin
end;
procedure CreateCashFlowCard(var CashFlowForecast: Record "Cash Flow Forecast")
begin
CashFlowForecast.Init();
CashFlowForecast.Validate(
"No.", LibraryUtility.GenerateRandomCode(CashFlowForecast.FieldNo("No."), DATABASE::"Cash Flow Forecast"));
CashFlowForecast.Insert(true);
end;
procedure CreateCashFlowAccount(var CashFlowAccount: Record "Cash Flow Account"; AccountType: Enum "Cash Flow Account Type")
begin
CashFlowAccount.Init();
CashFlowAccount.Validate("No.",
LibraryUtility.GenerateRandomCode(CashFlowAccount.FieldNo("No."), DATABASE::"Cash Flow Account"));
CashFlowAccount.Validate("Account Type", AccountType);
CashFlowAccount.Validate(Name,
LibraryUtility.GenerateRandomCode(CashFlowAccount.FieldNo(Name), DATABASE::"Cash Flow Account"));
CashFlowAccount.Insert(true);
end;
procedure MockCashFlowCustOverdueData()
var
GenJournalLine: Record "Gen. Journal Line";
GenJournalBatch: Record "Gen. Journal Batch";
begin
LibraryERM.SelectLastGenJnBatch(GenJournalBatch);
LibraryERM.ClearGenJournalLines(GenJournalBatch);
LibraryERM.CreateGeneralJnlLineWithBalAcc(
GenJournalLine, GenJournalBatch."Journal Template Name", GenJournalBatch.Name,
GenJournalLine."Document Type"::Invoice, GenJournalLine."Account Type"::Customer, LibrarySales.CreateCustomerNo(),
GenJournalLine."Bal. Account Type"::"G/L Account", LibraryERM.CreateGLAccountNo(),
LibraryRandom.RandDecInRange(100, 200, 2));
GenJournalLine."Due Date" := GenJournalLine."Posting Date" - 1;
GenJournalLine.Modify();
LibraryERM.PostGeneralJnlLine(GenJournalLine);
end;
}