-
Notifications
You must be signed in to change notification settings - Fork 402
Expand file tree
/
Copy pathServDocumentsMgt.Codeunit.al
More file actions
3064 lines (2681 loc) · 147 KB
/
Copy pathServDocumentsMgt.Codeunit.al
File metadata and controls
3064 lines (2681 loc) · 147 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// ------------------------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
// ------------------------------------------------------------------------------------------------
namespace Microsoft.Service.Posting;
using Microsoft.CRM.Team;
using Microsoft.EServices.EDocument;
using Microsoft.Finance.Dimension;
using Microsoft.Finance.GeneralLedger.Journal;
using Microsoft.Finance.GeneralLedger.Setup;
using Microsoft.Finance.ReceivablesPayables;
using Microsoft.Finance.VAT.Calculation;
using Microsoft.Finance.VAT.Setup;
using Microsoft.Foundation.AuditCodes;
using Microsoft.Foundation.NoSeries;
using Microsoft.Inventory.Costing;
using Microsoft.Inventory.Item;
using Microsoft.Inventory.Ledger;
using Microsoft.Inventory.Location;
using Microsoft.Inventory.Setup;
using Microsoft.Inventory.Tracking;
using Microsoft.Projects.Project.Job;
using Microsoft.Sales.Customer;
using Microsoft.Sales.Setup;
using Microsoft.Service.Comment;
using Microsoft.Service.Contract;
using Microsoft.Service.Document;
using Microsoft.Service.History;
using Microsoft.Service.Item;
using Microsoft.Service.Ledger;
using Microsoft.Service.Pricing;
using Microsoft.Service.Setup;
using Microsoft.Utilities;
using System.Utilities;
codeunit 5988 "Serv-Documents Mgt."
{
Permissions = TableData "Service Header" = rimd,
TableData "Service Item Line" = rimd,
TableData "Service Line" = rimd,
TableData "Service Ledger Entry" = rm,
TableData "Warranty Ledger Entry" = rm,
TableData "Service Shipment Item Line" = rimd,
TableData "Service Shipment Header" = rimd,
TableData "Service Shipment Line" = rimd,
TableData "Service Invoice Header" = rimd,
TableData "Service Invoice Line" = rimd,
TableData "Service Cr.Memo Header" = rimd,
TableData "Service Cr.Memo Line" = rimd;
trigger OnRun()
begin
end;
var
GLSetup: Record "General Ledger Setup";
ServHeader: Record "Service Header" temporary;
ServLine: Record "Service Line" temporary;
TempServiceLine: Record "Service Line" temporary;
ServItemLine: Record "Service Item Line" temporary;
ServShptHeader: Record "Service Shipment Header" temporary;
ServShptItemLine: Record "Service Shipment Item Line" temporary;
ServShptLine: Record "Service Shipment Line" temporary;
ServInvHeader: Record "Service Invoice Header" temporary;
ServInvLine: Record "Service Invoice Line" temporary;
ServCrMemoHeader: Record "Service Cr.Memo Header" temporary;
ServCrMemoLine: Record "Service Cr.Memo Line" temporary;
PServLine: Record "Service Line";
PServItemLine: Record "Service Item Line";
TempHandlingSpecification: Record "Tracking Specification" temporary;
TempInvoicingSpecification: Record "Tracking Specification" temporary;
TempTrackingSpecification: Record "Tracking Specification" temporary;
TempTrackingSpecificationInv: Record "Tracking Specification" temporary;
TempValueEntryRelation: Record "Value Entry Relation" temporary;
InvoicePostingParameters: Record "Invoice Posting Parameters";
SalesSetup: Record "Sales & Receivables Setup";
ServMgtSetup: Record "Service Mgt. Setup";
ServDocReg: Record "Service Document Register";
ServiceCommentLine: Record "Service Comment Line";
TempWarrantyLedgerEntry: Record "Warranty Ledger Entry" temporary;
ServPostingJnlsMgt: Codeunit "Serv-Posting Journals Mgt.";
ServAmountsMgt: Codeunit "Serv-Amounts Mgt.";
ServITRMgt: Codeunit "Serv-Item Tracking Rsrv. Mgt.";
ServCalcDisc: Codeunit "Service-Calc. Discount";
ServOrderMgt: Codeunit ServOrderManagement;
ServLogMgt: Codeunit ServLogManagement;
DimMgt: Codeunit DimensionManagement;
ServDimMgt: Codeunit "Serv. Dimension Management";
ServAllocMgt: Codeunit ServAllocationManagement;
DocumentErrorsMgt: Codeunit "Document Errors Mgt.";
ErrorMessageMgt: Codeunit "Error Message Management";
InvoicePostingInterface: Interface "Invoice Posting";
IsInterfaceInitialized: Boolean;
GenJnlLineExtDocNo: Code[35];
GenJnlLineDocNo: Code[20];
SrcCode: Code[10];
GenJnlLineDocType: Enum "Gen. Journal Document Type";
ItemLedgShptEntryNo: Integer;
NextServLedgerEntryNo: Integer;
NextWarrantyLedgerEntryNo: Integer;
Ship: Boolean;
Consume: Boolean;
Invoice: Boolean;
#pragma warning disable AA0074
#pragma warning disable AA0470
Text007: Label '%1 %2 -> Invoice %3';
Text008: Label '%1 %2 -> Credit Memo %3';
#pragma warning restore AA0470
Text011: Label 'must have the same sign as the shipment.';
Text013: Label 'The shipment lines have been deleted.';
#pragma warning disable AA0470
Text014: Label 'You cannot invoice more than you have shipped for order %1.';
Text015: Label 'The %1 you are going to invoice has a %2 entered.\You may need to run price adjustment. Do you want to continue posting? ';
#pragma warning restore AA0470
Text023: Label 'This order must be a complete Shipment.';
#pragma warning disable AA0470
Text026: Label 'Line %1 of the shipment %2, which you are attempting to invoice, has already been invoiced.';
Text027: Label 'The quantity you are attempting to invoice is greater than the quantity in shipment %1.';
Text028: Label 'The combination of dimensions used in %1 %2 is blocked. %3';
Text029: Label 'The combination of dimensions used in %1 %2, line no. %3 is blocked. %4';
Text030: Label 'The dimensions used in %1 %2 are invalid. %3';
Text031: Label 'The dimensions used in %1 %2, line no. %3 are invalid. %4';
#pragma warning restore AA0470
#pragma warning restore AA0074
CloseCondition: Boolean;
ServLinesPassed: Boolean;
#pragma warning disable AA0074
#pragma warning disable AA0470
Text035: Label 'The %1 %2 relates to the same %3 as %1 %4.';
Text039: Label '%1 %2 on %3 %4 relates to a %5 that has already been invoiced.';
Text041: Label 'Old %1 service ledger entries have been found for service contract %2.\You must close them by posting the old service invoices.';
#pragma warning restore AA0470
#pragma warning restore AA0074
TrackingSpecificationExists: Boolean;
ServLineInvoicedConsumedQty: Decimal;
ServLedgEntryNo: Integer;
procedure Initialize(var PassedServiceHeader: Record "Service Header"; var PassedServiceLine: Record "Service Line")
var
SrcCodeSetup: Record "Source Code Setup";
begin
CloseCondition := true;
OnBeforeInitialize(PassedServiceHeader, PassedServiceLine, CloseCondition);
Clear(ServPostingJnlsMgt);
Clear(ServAmountsMgt);
CheckServiceDocument(PassedServiceHeader, PassedServiceLine);
ServMgtSetup.Get();
GetInvoicePostingSetup();
SalesSetup.Get();
SrcCodeSetup.Get();
SrcCode := SrcCodeSetup."Service Management";
ServPostingJnlsMgt.Initialize(ServHeader, Consume, Invoice);
ServAmountsMgt.Initialize(ServHeader."Currency Code"); // roundingLineInserted is set to FALSE;
TrackingSpecificationExists := false;
OnAfterInitialize(PassedServiceHeader, PassedServiceLine, CloseCondition, Ship, Consume, Invoice);
end;
procedure CheckServiceDocument(var PassedServiceHeader: Record "Service Header"; var PassedServiceLine: Record "Service Line")
begin
PrepareDocument(PassedServiceHeader, PassedServiceLine);
PassedServiceHeader.ValidateSalesPersonOnServiceHeader(PassedServiceHeader, true, true);
CheckSysCreatedEntry();
CheckShippingAdvice();
CheckDimensions();
GetAndCheckCustomer();
CheckServiceItemBlockedForAll();
CheckVATDate(PassedServiceHeader);
end;
local procedure GetInvoicePostingSetup()
var
IsHandled: Boolean;
begin
if IsInterfaceInitialized then
exit;
IsHandled := false;
OnBeforeGetInvoicePostingSetup(InvoicePostingInterface, IsHandled);
if not IsHandled then
InvoicePostingInterface := "Service Invoice Posting"::"Invoice Posting (v.19)";
InvoicePostingInterface.Check(Database::"Service Header");
IsInterfaceInitialized := true;
end;
local procedure GetInvoicePostingParameters()
begin
Clear(InvoicePostingParameters);
InvoicePostingParameters."Document Type" := GenJnlLineDocType;
InvoicePostingParameters."Document No." := GenJnlLineDocNo;
InvoicePostingParameters."External Document No." := GenJnlLineExtDocNo;
InvoicePostingParameters."Source Code" := SrcCode;
OnAfterGetInvoicePostingParameters(InvoicePostingParameters, ServInvHeader);
end;
procedure CalcInvDiscount()
begin
if SalesSetup."Calc. Inv. Discount" then begin
ServLine.Find('-');
ServCalcDisc.CalculateWithServHeader(ServHeader, PServLine, ServLine);
end;
end;
procedure PostDocumentLines(var Window: Dialog)
var
ServiceLineACY: Record "Service Line";
TotalServiceLine: Record "Service Line";
TotalServiceLineLCY: Record "Service Line";
ServLineOld: Record "Service Line";
TempServLine2: Record "Service Line" temporary;
TempVATAmountLine: Record "VAT Amount Line" temporary;
TempVATAmountLineForSLE: Record "VAT Amount Line" temporary;
TempVATAmountLineRemainder: Record "VAT Amount Line" temporary;
DummyTrackingSpecification: Record "Tracking Specification";
Item: Record Item;
ServItemMgt: Codeunit ServItemManagement;
ErrorContextElementProcessLine: Codeunit "Error Context Element";
ErrorContextElementPostLine: Codeunit "Error Context Element";
ZeroServiceLineRecID: RecordId;
RemQtyToBeInvoiced: Decimal;
RemQtyToBeInvoicedBase: Decimal;
RemQtyToBeConsumed: Decimal;
RemQtyToBeConsumedBase: Decimal;
TotalAmount: Decimal;
LineCount: Integer;
ApplToServEntryNo: Integer;
WarrantyNo: Integer;
BiggestLineNo: Integer;
LastLineRetrieved: Boolean;
ShouldPostShipmentServiceEntry: Boolean;
IsHandled: Boolean;
PostDocumentLinesMsg: Label 'Post document lines.';
begin
LineCount := 0;
OnBeforePostDocumentLines(ServHeader, ServLine, Ship, Consume, Invoice);
// init cu for posting SLE type Usage
ServPostingJnlsMgt.InitServiceRegister(NextServLedgerEntryNo, NextWarrantyLedgerEntryNo);
OnPostDocumentLinesOnBeforeFilterServiceLine(ServHeader, ServLine);
if ServHeader."Tax System Type" = ServHeader."Tax System Type"::VAT then begin
ServLine.CalcVATAmountLines(1, ServHeader, ServLine, TempVATAmountLine, Ship);
ServLine.CalcVATAmountLines(2, ServHeader, ServLine, TempVATAmountLineForSLE, Ship);
end;
GetZeroServiceLineRecID(ServHeader, ZeroServiceLineRecID);
ErrorMessageMgt.PushContext(ErrorContextElementProcessLine, ZeroServiceLineRecID, 0, PostDocumentLinesMsg);
ServLine.Reset();
SortLines(ServLine);
OnPostDocumentLinesOnAfterSortLines(ServHeader, ServLine, TempVATAmountLine, TempVATAmountLineForSLE);
ServLedgEntryNo := FindFirstServLedgEntry(ServLine);
if ServLine.Find('-') then
repeat
ErrorMessageMgt.PushContext(ErrorContextElementPostLine, ServLine.RecordId, 0, PostDocumentLinesMsg);
ServPostingJnlsMgt.SetItemJnlRollRndg(false);
if ServLine.Type = ServLine.Type::Item then
DummyTrackingSpecification.CheckItemTrackingQuantity(
Database::"Service Line", ServLine."Document Type".AsInteger(), ServLine."Document No.", ServLine."Line No.",
ServLine."Qty. to Ship (Base)", ServLine."Qty. to Invoice (Base)", Ship, Invoice);
LineCount += 1;
if GuiAllowed() then
Window.Update(2, LineCount);
IsHandled := false;
OnPostDocumentLinesOnBeforeCheckServLine(ServHeader, ServLine, Ship, Invoice, ServItemLine, IsHandled);
if not IsHandled then
if Ship and (ServLine."Qty. to Ship" <> 0) or Invoice and (ServLine."Qty. to Invoice" <> 0) then
ServOrderMgt.CheckServItemRepairStatus(ServHeader, ServItemLine, ServLine);
OnPostDocumentLinesOnAfterCheckServItemRepairStatus(ServLine);
ServLineOld := ServLine;
if ServLine."Spare Part Action" in
[ServLine."Spare Part Action"::"Component Replaced",
ServLine."Spare Part Action"::Permanent,
ServLine."Spare Part Action"::"Temporary"]
then begin
ServLine."Spare Part Action" := ServLine."Spare Part Action"::"Component Installed";
ServLine.Modify();
end;
// post Service Ledger Entry of type Usage, on shipment
ShouldPostShipmentServiceEntry :=
(Ship and (ServLine."Document Type" = ServLine."Document Type"::Order) or
(ServLine."Document Type" = ServLine."Document Type"::Invoice)) and
(ServLine."Qty. to Ship" <> 0) and not ServAmountsMgt.RoundingLineInserted();
OnPostDocumentLinesOnAfterCalcShouldPostShipmentServiceEntry(ServHeader, ServLine, Ship, ApplToServEntryNo, NextServLedgerEntryNo, ShouldPostShipmentServiceEntry);
if ShouldPostShipmentServiceEntry then begin
TempServLine2 := ServLine;
ServPostingJnlsMgt.CalcSLEDivideAmount(ServLine."Qty. to Ship", ServHeader, TempServLine2, TempVATAmountLineForSLE);
ApplToServEntryNo :=
ServPostingJnlsMgt.InsertServLedgerEntry(
NextServLedgerEntryNo, ServHeader, TempServLine2, ServItemLine, ServLine."Qty. to Ship", ServHeader."Shipping No.");
OnPostDocumentLinesOnAfterAssignApplToServEntryNo(ServHeader, ApplToServEntryNo);
if ServLine."Appl.-to Service Entry" = 0 then
ServLine."Appl.-to Service Entry" := ApplToServEntryNo;
end;
if (ServLine.Type = ServLine.Type::Item) and (ServLine."No." <> '') then begin
GetServLineItem(ServLine, Item);
if (Item."Costing Method" = Item."Costing Method"::Standard) and not ServLine.IsShipment() then
ServLine.GetUnitCost();
if Item.IsVariantMandatory() then
ServLine.TestField("Variant Code");
end;
if not CheckCloseCondition(
ServLine.Quantity, ServLine."Qty. to Invoice", ServLine."Qty. to Consume", ServLine."Quantity Invoiced", ServLine."Quantity Consumed")
then
CloseCondition := false;
OnPostDocumentLinesOnAfterCheckCloseCondition(ServHeader, ServLine, ServItemLine);
if ServLine.Quantity = 0 then
ServLine.TestField("Line Amount", 0)
else begin
ServLine.TestBinCode();
ServLine.TestField("No.");
ServLine.TestField(Type);
if GLSetup.UseVat() then begin
ServLine.TestField("Gen. Bus. Posting Group");
ServLine.TestField("Gen. Prod. Posting Group");
end;
ServAmountsMgt.DivideAmount(1, ServLine."Qty. to Invoice", ServHeader, ServLine,
TempVATAmountLine, TempVATAmountLineRemainder);
end;
OnPostDocumentLinesOnBeforeRoundAmount(ServLine);
ServAmountsMgt.RoundAmount(ServLine."Qty. to Invoice", ServHeader, ServLine,
TempServiceLine, TotalServiceLine, TotalServiceLineLCY, ServiceLineACY);
if ServLine."Document Type" <> ServLine."Document Type"::"Credit Memo" then begin
ServAmountsMgt.ReverseAmount(ServLine);
ServAmountsMgt.ReverseAmount(ServiceLineACY);
OnPostDocumentLinesOnAfterReverseAmount(ServHeader, ServLine);
end;
// post Service Ledger Entry of type Sale, on invoice
if ServLine."Document Type" = ServLine."Document Type"::"Credit Memo" then begin
CheckIfServDuplicateLine(ServLine);
IsHandled := false;
OnPostDocumentLinesOnBeforeCreateCreditEntry(ServHeader, ServLine, GenJnlLineDocNo, IsHandled);
if not IsHandled then
ServPostingJnlsMgt.CreateCreditEntry(NextServLedgerEntryNo,
ServHeader, ServLine, GenJnlLineDocNo);
OnPostDocumentLinesOnAfterServPostingJnlsMgtCreateCreditEntry(NextServLedgerEntryNo, ApplToServEntryNo, ServHeader, ServLine);
end else
if (Invoice or (ServLine."Document Type" = ServLine."Document Type"::Invoice)) and
(ServLine."Qty. to Invoice" <> 0) and not ServAmountsMgt.RoundingLineInserted()
then begin
CheckIfServDuplicateLine(ServLine);
ServPostingJnlsMgt.InsertServLedgerEntrySale(NextServLedgerEntryNo,
ServHeader, ServLine, ServItemLine, ServLine."Qty. to Invoice", ServLine."Qty. to Invoice", GenJnlLineDocNo, ServLine."Line No.");
OnPostDocumentLinesOnAfterServPostingJnlsMgtInsertServLedgerEntrySaleInvoice(NextServLedgerEntryNo);
end;
InsertServLedgerEntrySaleConsume();
RemQtyToBeInvoiced := ServLine."Qty. to Invoice";
RemQtyToBeConsumed := ServLine."Qty. to Consume";
RemQtyToBeInvoicedBase := ServLine."Qty. to Invoice (Base)";
RemQtyToBeConsumedBase := ServLine."Qty. to Consume (Base)";
if Invoice then
if ServLine."Qty. to Invoice" = 0 then
TrackingSpecificationExists := false
else
TrackingSpecificationExists :=
ServITRMgt.RetrieveInvoiceSpecification(ServLine, TempInvoicingSpecification, false);
if Consume then
if ServLine."Qty. to Consume" = 0 then
TrackingSpecificationExists := false
else
TrackingSpecificationExists :=
ServITRMgt.RetrieveInvoiceSpecification(ServLine, TempInvoicingSpecification, true);
// update previously shipped lines with invoicing information.
if ServLine."Document Type" = ServLine."Document Type"::"Credit Memo" then
UpdateRcptLinesOnInv()
else
// Order or Invoice
UpdateShptLinesOnInv(ServLine,
RemQtyToBeInvoiced, RemQtyToBeInvoicedBase,
RemQtyToBeConsumed, RemQtyToBeConsumedBase);
if TrackingSpecificationExists then
ServITRMgt.SaveInvoiceSpecification(TempInvoicingSpecification, TempTrackingSpecification);
// post service line via journals
case ServLine.Type of
ServLine.Type::Item:
PostServiceItemLine(
ServHeader, ServLine, RemQtyToBeInvoicedBase, RemQtyToBeInvoiced, RemQtyToBeConsumedBase, RemQtyToBeConsumed,
WarrantyNo);
ServLine.Type::Resource:
PostServiceResourceLine(ServLine, WarrantyNo);
end;
if Consume and (ServLine."Document Type" = ServLine."Document Type"::Order) then begin
OnPostDocumentLinesOnBeforePostRemQtyToBeConsumed(ServHeader, ServLine);
if ServPostingJnlsMgt.PostJobJnlLine(ServHeader, ServLine, RemQtyToBeConsumed) then
UpdateServiceLedgerEntry(NextServLedgerEntryNo - 1)
else
if (ServLine.Type = ServLine.Type::Resource) and (RemQtyToBeConsumed <> 0) then
ServPostingJnlsMgt.PostResJnlLineConsume(ServLine, ServShptHeader);
end;
if Ship and (ServLine."Document Type" = ServLine."Document Type"::Order) then begin
// component spare part action
ServItemMgt.AddOrReplaceSIComponent(ServLineOld, ServHeader,
ServHeader."Shipping No.", ServLineOld."Line No.", TempTrackingSpecification);
// allocations
ServAllocMgt.SetServLineAllocStatus(TempServiceLine);
end;
if (ServLine.Type <> ServLine.Type::" ") and (ServLine."Qty. to Invoice" <> 0) then
InvoicePostingInterface.PrepareLine(ServHeader, ServLine, ServiceLineACY);
OnPostDocumentLinesOnAfterFillInvPostingBuffer(ServHeader, ServLine, TempServiceLine, ServiceLineACY, ServInvHeader, ServCrMemoHeader, ServShptHeader);
// prepare posted document lines
if Ship then
PrepareShipmentLine(TempServiceLine, WarrantyNo);
if Invoice then
if ServLine."Document Type" in [ServLine."Document Type"::Order, ServLine."Document Type"::Invoice] then
PrepareInvoiceLine(TempServiceLine)
else
PrepareCrMemoLine(TempServiceLine);
OnPostDocumentLinesOnAfterPrepareLine(ServHeader, ServLine, ServInvHeader, ServCrMemoHeader, ServShptHeader);
if Invoice or Consume then
CollectValueEntryRelation();
if ServAmountsMgt.RoundingLineInserted() then
LastLineRetrieved := true
else begin
BiggestLineNo := ServAmountsMgt.MAX(ServAmountsMgt.GetLastLineNo(ServLine), ServLine."Line No.");
LastLineRetrieved := ServLine.Next() = 0;
// ServLine
IsHandled := false;
OnPostDocumentLinesOnBeforeInvoiceRounding(ServHeader, ServLine, TotalServiceLine, ServAmountsMgt, LastLineRetrieved, BiggestLineNo, IsHandled);
if not IsHandled then
if LastLineRetrieved and SalesSetup."Invoice Rounding" then
ServAmountsMgt.InvoiceRounding(ServHeader, ServLine, TotalServiceLine,
LastLineRetrieved, false, BiggestLineNo);
end;
ServAmountsMgt.RunOnAfterUpdateInvoiceRounding(ServHeader, ServLine, TotalServiceLine, false, BiggestLineNo, LastLineRetrieved);
ErrorMessageMgt.PopContext(ErrorContextElementPostLine);
until LastLineRetrieved;
ErrorMessageMgt.PopContext(ErrorContextElementProcessLine);
ErrorMessageMgt.Finish(ZeroServiceLineRecID);
// again reverse amount
if ServHeader."Document Type" <> ServHeader."Document Type"::"Credit Memo" then begin
ServAmountsMgt.ReverseAmount(TotalServiceLine);
ServAmountsMgt.ReverseAmount(TotalServiceLineLCY);
TotalServiceLineLCY."Unit Cost (LCY)" := -TotalServiceLineLCY."Unit Cost (LCY)";
end;
ServPostingJnlsMgt.FinishServiceRegister(NextServLedgerEntryNo, NextWarrantyLedgerEntryNo);
OnPostDocumentLinesOnAfterFinishServiceRegister(ServLine);
if Invoice or (ServHeader."Document Type" = ServHeader."Document Type"::Invoice) then begin
Clear(ServDocReg);
// fake service register entry to be used in the following PostServSalesDocument()
if Invoice and (ServHeader."Document Type" = ServHeader."Document Type"::Order) and (ServLine."Contract No." <> '') then
ServDocReg.InsertServiceSalesDocument(
ServDocReg."Source Document Type"::Contract, ServLine."Contract No.",
ServDocReg."Destination Document Type"::Invoice, ServLine."Document No.");
ServDocReg.PostServiceSalesDocument(
ServDocReg."Destination Document Type"::Invoice,
ServLine."Document No.", ServInvHeader."No.");
end;
if Invoice or (ServHeader."Document Type" = ServHeader."Document Type"::"Credit Memo") then begin
Clear(ServDocReg);
ServDocReg.PostServiceSalesDocument(
ServDocReg."Destination Document Type"::"Credit Memo",
ServLine."Document No.", ServCrMemoHeader."No.");
end;
// Post sales and VAT to G/L entries from posting buffer
if Invoice then begin
GetInvoicePostingParameters();
InvoicePostingInterface.SetParameters(InvoicePostingParameters);
InvoicePostingInterface.SetTotalLines(TotalServiceLine, TotalServiceLineLCY);
ServPostingJnlsMgt.PostLines(ServHeader, InvoicePostingInterface, Window, TotalAmount);
ServPostingJnlsMgt.PostSalesTaxLines(ServHeader, TotalServiceLineLCY, InvoicePostingParameters);
// Post customer entry
if GuiAllowed() then
Window.Update(4, 1);
GetInvoicePostingParameters();
InvoicePostingInterface.SetParameters(InvoicePostingParameters);
InvoicePostingInterface.SetTotalLines(TotalServiceLine, TotalServiceLineLCY);
ServPostingJnlsMgt.PostLedgerEntry(ServHeader, InvoicePostingInterface);
// post Balancing account
IsHandled := false;
OnPostDocumentLinesOnBeforePostBalancingEntry(ServHeader, ServLine, TotalServiceLine, ServPostingJnlsMgt, GenJnlLineDocType, GenJnlLineDocNo, GenJnlLineExtDocNo, InvoicePostingInterface, Window, IsHandled);
if not IsHandled then
if ServHeader."Bal. Account No." <> '' then begin
if GuiAllowed() then
Window.Update(5, 1);
InvoicePostingInterface.SetParameters(InvoicePostingParameters);
InvoicePostingInterface.SetTotalLines(TotalServiceLine, TotalServiceLineLCY);
ServPostingJnlsMgt.PostBalancingEntry(ServHeader, InvoicePostingInterface);
end;
OnPostDocumentLinesOnAfterPostSalesAndVAT(ServHeader, TotalServiceLine, Window, GenJnlLineDocNo, GenJnlLineExtDocNo, Invoice);
end;
MakeInvtAdjustment();
if Ship then begin
ServHeader."Last Shipping No." := ServHeader."Shipping No.";
ServHeader."Shipping No." := '';
end;
if Invoice then begin
ServHeader."Last Posting No." := ServHeader."Posting No.";
ServHeader."Posting No." := '';
end;
ServHeader.Modify();// with header
OnAfterPostDocumentLines(ServHeader, ServInvHeader, ServInvLine, ServCrMemoHeader, ServCrMemoLine, GenJnlLineDocType, GenJnlLineDocNo);
end;
local procedure InsertServLedgerEntrySaleConsume()
var
IsHandled: Boolean;
begin
IsHandled := false;
OnBeforeInsertServLedgerEntrySaleConsume(ServHeader, ServLine, ServItemLine, ServMgtSetup, NextServLedgerEntryNo, GenJnlLineDocNo, Consume, IsHandled);
if not IsHandled then
if Consume and (ServLine."Document Type" = ServLine."Document Type"::Order) and
(ServLine."Qty. to Consume" <> 0)
then
ServPostingJnlsMgt.InsertServLedgerEntrySale(NextServLedgerEntryNo,
ServHeader, ServLine, ServItemLine, ServLine."Qty. to Consume", 0, ServHeader."Shipping No.", ServLine."Line No.");
OnAfterInsertServLedgerEntrySaleConsume(NextServLedgerEntryNo);
end;
local procedure PostServiceItemLine(ServHeader: Record "Service Header"; var ServLine: Record "Service Line"; RemQtyToBeInvoicedBase: Decimal; RemQtyToBeInvoiced: Decimal; RemQtyToBeConsumedBase: Decimal; RemQtyToBeConsumed: Decimal; var WarrantyNo: Integer)
var
TempServLine: Record "Service Line" temporary;
TempVATAmountLineForSLE: Record "VAT Amount Line" temporary;
DummyTrackingSpecification: Record "Tracking Specification";
begin
OnBeforePostServiceItemLine(ServLine);
if Ship and (ServLine."Document Type" = ServLine."Document Type"::Order) then begin
TempServLine := ServLine;
ServPostingJnlsMgt.CalcSLEDivideAmount(ServLine."Qty. to Ship", ServHeader, TempServLine, TempVATAmountLineForSLE);
WarrantyNo :=
ServPostingJnlsMgt.InsertWarrantyLedgerEntry(
NextWarrantyLedgerEntryNo, ServHeader, TempServLine, ServItemLine, ServLine."Qty. to Ship", ServHeader."Shipping No.");
end;
if Invoice and (RemQtyToBeInvoiced <> 0) then
ItemLedgShptEntryNo :=
ServPostingJnlsMgt.PostItemJnlLine(
ServLine,
RemQtyToBeInvoiced, RemQtyToBeInvoicedBase, 0, 0, RemQtyToBeInvoiced, RemQtyToBeInvoicedBase, 0,
DummyTrackingSpecification, TempTrackingSpecificationInv, TempHandlingSpecification, TempTrackingSpecification,
ServShptHeader, '');
if Consume and (RemQtyToBeConsumed <> 0) then
ItemLedgShptEntryNo :=
ServPostingJnlsMgt.PostItemJnlLine(
ServLine,
RemQtyToBeConsumed, RemQtyToBeConsumedBase, RemQtyToBeConsumed, RemQtyToBeConsumedBase, 0, 0, 0,
DummyTrackingSpecification, TempTrackingSpecificationInv, TempHandlingSpecification, TempTrackingSpecification,
ServShptHeader, '');
if not (ServLine."Document Type" in [ServLine."Document Type"::"Credit Memo"]) then
if ((Abs(ServLine."Qty. to Ship") - Abs(ServLine."Qty. to Consume") - Abs(ServLine."Qty. to Invoice")) > Abs(RemQtyToBeConsumed)) or
((Abs(ServLine."Qty. to Ship") - Abs(ServLine."Qty. to Consume") - Abs(ServLine."Qty. to Invoice")) > Abs(RemQtyToBeInvoiced))
then
ItemLedgShptEntryNo :=
ServPostingJnlsMgt.PostItemJnlLine(
ServLine,
ServLine."Qty. to Ship" - RemQtyToBeInvoiced - RemQtyToBeConsumed,
ServLine."Qty. to Ship (Base)" - RemQtyToBeInvoicedBase - RemQtyToBeConsumedBase,
0, 0, 0, 0, 0, DummyTrackingSpecification, TempTrackingSpecificationInv,
TempHandlingSpecification, TempTrackingSpecification, ServShptHeader, '');
end;
local procedure PostServiceResourceLine(var ServLine: Record "Service Line"; var WarrantyNo: Integer)
var
TempServLine: Record "Service Line" temporary;
TempVATAmountLineForSLE: Record "VAT Amount Line" temporary;
begin
TempServLine := ServLine;
OnPostServiceResourceLineOnBeforeCalcSLEDivideAmount(ServLine);
ServPostingJnlsMgt.CalcSLEDivideAmount(ServLine."Qty. to Ship", ServHeader, TempServLine, TempVATAmountLineForSLE);
if Ship and (ServLine."Document Type" = ServLine."Document Type"::Order) then
WarrantyNo :=
ServPostingJnlsMgt.InsertWarrantyLedgerEntry(
NextWarrantyLedgerEntryNo, ServHeader, TempServLine, ServItemLine, ServLine."Qty. to Ship", ServHeader."Shipping No.");
if ServLine."Document Type" = ServLine."Document Type"::"Credit Memo" then
ServPostingJnlsMgt.PostResJnlLineUndoUsage(ServLine, GenJnlLineDocNo, GenJnlLineExtDocNo)
else
PostResourceUsage(TempServLine);
if ServLine."Qty. to Invoice" <> 0 then
ServPostingJnlsMgt.PostResJnlLineSale(ServLine, GenJnlLineDocNo, GenJnlLineExtDocNo);
OnAfterPostServiceResourceLine(ServHeader, ServLine, ServMgtSetup, TempServLine, GenJnlLineDocNo, GenJnlLineExtDocNo, Ship, Invoice, Consume);
end;
local procedure MakeInvtAdjustment()
var
InvtSetup: Record "Inventory Setup";
InvtAdjmtHandler: Codeunit "Inventory Adjustment Handler";
begin
InvtSetup.Get();
if InvtSetup.AutomaticCostAdjmtRequired() then
InvtAdjmtHandler.MakeInventoryAdjustment(true, InvtSetup."Automatic Cost Posting");
OnAfterMakeInvtAdjustment(InvtSetup, ServHeader);
end;
procedure UpdateDocumentLines()
var
IsHandled: Boolean;
begin
IsHandled := false;
OnBeforeUpdateDocumentLines(ServHeader, CloseCondition, ServLinesPassed, IsHandled);
if IsHandled then
exit;
ServHeader.Modify();
if (ServHeader."Document Type" = ServHeader."Document Type"::Order) and not CloseCondition then begin
ServITRMgt.InsertTrackingSpecification(ServHeader, TempTrackingSpecification);
// update service line quantities according to posted values
UpdateServLinesOnPostOrder();
end else begin
// close condition met for order, or we post Invoice or CrMemo
if ServLinesPassed then
UpdateServLinesOnPostOrder();
case ServHeader."Document Type" of
ServHeader."Document Type"::Invoice:
UpdateServLinesOnPostInvoice();
ServHeader."Document Type"::"Credit Memo":
UpdateServLinesOnPostCrMemo();
end;// case
ServAllocMgt.SetServOrderAllocStatus(ServHeader);
end; // End CloseConditionMet
end;
local procedure PrepareDocument(var ServiceHeader2: Record "Service Header"; var ServiceLine2: Record "Service Line")
var
IsHandled: Boolean;
begin
// fill ServiceHeader we will work with (tempTable)
ServHeader.DeleteAll();
ServHeader.Copy(ServiceHeader2);
ServHeader.Insert();
// Fetch persistent Service Lines and Service Item Lines bound to Service Header.
// Copy persistent records to temporary.
ServLine.DeleteAll();
ServiceLine2.Reset();
// collect passed lines
OnPrepareDocumentOnBeforePassedServLineFind(ServiceLine2, ServHeader);
if ServiceLine2.Find('-') then begin
repeat
IsHandled := false;
OnPrepareDocumentOnServLineInsert(ServiceHeader2, ServLine, ServiceLine2, IsHandled);
if not IsHandled then begin
ServLine.Copy(ServiceLine2);
ServLine.Insert();
end;
until ServiceLine2.Next() = 0;
ServLinesPassed := true;
// indicate either we collect passed or all SLs.
end else begin
// collect persistent lines related to ServHeader
PServLine.Reset();
PServLine.SetRange("Document Type", ServHeader."Document Type");
PServLine.SetRange("Document No.", ServHeader."No.");
OnPrepareDocumentOnAfterSetPServLineFilters(PServLine);
if PServLine.Find('-') then
repeat
ServLine.Copy(PServLine);
ServLine."Posting Date" := ServHeader."Posting Date";
OnPrepareDocumentOnPServLineLoopOnBeforeServLineInsert(ServLine, PServLine);
ServLine.Insert();
// temptable
until PServLine.Next() = 0;
ServLinesPassed := false;
end;
RemoveLinesNotSatisfyPosting();
ServItemLine.DeleteAll();
PServItemLine.Reset();
PServItemLine.SetRange("Document Type", ServHeader."Document Type");
PServItemLine.SetRange("Document No.", ServHeader."No.");
OnPrepareDocumentOnAfterSetPServItemLineFilters(PServItemLine);
if PServItemLine.Find('-') then
repeat
ServItemLine.Copy(PServItemLine);
ServItemLine.Insert();
// temptable
until PServItemLine.Next() = 0;
OnAfterPrepareDocument(ServiceHeader2, ServiceLine2);
end;
procedure PrepareShipmentHeader(): Code[20]
var
ServiceShipmentHeader2: Record "Service Shipment Header";
ServiceShipmentLine2: Record "Service Shipment Line";
ServItemManagement: Codeunit ServItemManagement;
RecordLinkManagement: Codeunit "Record Link Management";
IsHandled: Boolean;
begin
if (ServHeader."Document Type" = ServHeader."Document Type"::Order) or
((ServHeader."Document Type" = ServHeader."Document Type"::Invoice) and ServMgtSetup."Shipment on Invoice")
then begin
ServiceShipmentHeader2.LockTable();
ServiceShipmentLine2.LockTable();
ServShptHeader.Init();
ServHeader.CalcFields("Work Description");
ServShptHeader.TransferFields(ServHeader);
ServShptHeader."No." := ServHeader."Shipping No.";
if ServHeader."Document Type" = ServHeader."Document Type"::Order then begin
ServShptHeader."Order No. Series" := ServHeader."No. Series";
ServShptHeader."Order No." := ServHeader."No.";
if ServMgtSetup."Ext. Doc. No. Mandatory" then
ServHeader.TestField(ServHeader."External Document No.");
end;
if ServMgtSetup."Copy Comments Order to Shpt." then
RecordLinkManagement.CopyLinks(ServHeader, ServShptHeader);
ServShptHeader."Source Code" := SrcCode;
ServShptHeader."User ID" := CopyStr(UserId(), 1, MaxStrLen(ServShptHeader."User ID"));
ServShptHeader."No. Printed" := 0;
OnBeforeServShptHeaderInsert(ServShptHeader, ServHeader);
ServShptHeader.Insert();
OnAfterServShptHeaderInsert(ServShptHeader, ServHeader);
Clear(ServLogMgt);
ServLogMgt.ServOrderShipmentPost(ServHeader."No.", ServShptHeader."No.");
if (ServHeader."Document Type" = ServHeader."Document Type"::Order) and ServMgtSetup."Copy Comments Order to Shpt." then
ServOrderMgt.CopyCommentLines(
"Service Comment Table Name"::"Service Header".AsInteger(),
"Service Comment Table Name"::"Service Shipment Header".AsInteger(),
ServHeader."No.", ServShptHeader."No.");
// create Service Shipment Item Lines
ServItemLine.Reset();
if ServItemLine.Find('-') then
repeat
IsHandled := false;
OnPrepareShipmentHeaderOnBeforeCreateServiceShipmentItemLine(ServHeader, ServItemLine, IsHandled);
if not IsHandled then begin
// create SSIL
ServShptItemLine.TransferFields(ServItemLine);
ServShptItemLine."No." := ServShptHeader."No.";
OnBeforeServShptItemLineInsert(ServShptItemLine, ServItemLine);
ServShptItemLine.Insert();
OnAfterServShptItemLineInsert(ServShptItemLine, ServItemLine);
end;
// set mgt. date and service dates
CalcContractDates();
IsHandled := false;
OnPrepareShipmentHeaderOnBeforeCalcServItemDates(ServHeader, ServItemLine, IsHandled);
if not IsHandled then
ServOrderMgt.CalcServItemDates(ServHeader, ServItemLine."Service Item No.");
until ServItemLine.Next() = 0
else begin
ServShptItemLine.Init();
ServShptItemLine."No." := ServShptHeader."No.";
ServShptItemLine."Line No." := 10000;
ServShptItemLine.Description := Format(ServHeader."Document Type") + ' ' + ServHeader."No.";
ServShptItemLine.Insert();
end;
end;
ServItemManagement.CopyReservationEntryService(ServHeader);
OnAfterPrepareShipmentHeader(ServShptHeader, ServHeader);
exit(ServShptHeader."No.");
end;
local procedure CalcContractDates()
var
ServLineLocal: Record "Service Line";
IsHandled: Boolean;
begin
IsHandled := false;
OnBeforeCalcContractDates(ServItemLine, IsHandled);
if IsHandled then
exit;
if (ServItemLine."Contract No." <> '') and (ServItemLine."Contract Line No." <> 0) and
(ServHeader."Contract No." <> '')
then begin
ServLineLocal.SetRange("Document Type", ServHeader."Document Type");
ServLineLocal.SetRange("Document No.", ServHeader."No.");
ServLineLocal.SetFilter("Quantity Shipped", '>%1', 0);
if ServLineLocal.IsEmpty() then
ServOrderMgt.CalcContractDates(ServHeader, ServItemLine);
end;
end;
local procedure PrepareShipmentLine(var PassedServLine: Record "Service Line"; passedWarrantyNo: Integer)
var
WarrantyLedgerEntry: Record "Warranty Ledger Entry";
begin
if (ServShptHeader."No." <> '') and (PassedServLine."Shipment No." = '') and not ServAmountsMgt.RoundingLineInserted() then begin
// Insert shipment line
ServShptLine.Init();
ServShptLine.TransferFields(PassedServLine);
ServShptLine."Document No." := ServShptHeader."No.";
ServShptLine.Quantity := PassedServLine."Qty. to Ship";
ServShptLine."Quantity (Base)" := PassedServLine."Qty. to Ship (Base)";
ServShptLine."Appl.-to Warranty Entry" := passedWarrantyNo;
if Abs(PassedServLine."Qty. to Consume") > Abs(PassedServLine."Qty. to Ship" - PassedServLine."Qty. to Invoice") then begin
ServShptLine."Quantity Consumed" := PassedServLine."Qty. to Ship" - PassedServLine."Qty. to Invoice";
ServShptLine."Qty. Consumed (Base)" := PassedServLine."Qty. to Ship (Base)" - PassedServLine."Qty. to Invoice (Base)";
end else begin
ServShptLine."Quantity Consumed" := PassedServLine."Qty. to Consume";
ServShptLine."Qty. Consumed (Base)" := PassedServLine."Qty. to Consume (Base)";
end;
if Abs(PassedServLine."Qty. to Invoice") > Abs(PassedServLine."Qty. to Ship" - PassedServLine."Qty. to Consume") then begin
ServShptLine."Quantity Invoiced" := PassedServLine."Qty. to Ship" - PassedServLine."Qty. to Consume";
ServShptLine."Qty. Invoiced (Base)" := PassedServLine."Qty. to Ship (Base)" - PassedServLine."Qty. to Consume (Base)";
end else begin
ServShptLine."Quantity Invoiced" := PassedServLine."Qty. to Invoice";
ServShptLine."Qty. Invoiced (Base)" := PassedServLine."Qty. to Invoice (Base)";
end;
ServShptLine."Qty. Shipped Not Invoiced" := ServShptLine.Quantity -
ServShptLine."Quantity Invoiced" - ServShptLine."Quantity Consumed";
ServShptLine."Qty. Shipped Not Invd. (Base)" := ServShptLine."Quantity (Base)" -
ServShptLine."Qty. Invoiced (Base)" - ServShptLine."Qty. Consumed (Base)";
if PassedServLine."Document Type" = PassedServLine."Document Type"::Order then begin
ServShptLine."Order No." := PassedServLine."Document No.";
ServShptLine."Order Line No." := PassedServLine."Line No.";
ServShptLine."External Document No." := ServShptHeader."External Document No.";
ServShptLine."Your Reference" := ServShptHeader."Your Reference";
end;
if (PassedServLine.Type = PassedServLine.Type::Item) and (PassedServLine."Qty. to Ship" <> 0) then
ServShptLine."Item Shpt. Entry No." :=
ServITRMgt.InsertShptEntryRelation(ServShptLine,
TempHandlingSpecification, TempTrackingSpecificationInv, ItemLedgShptEntryNo);
PassedServLine.CalcFields(PassedServLine."Service Item Line Description");
ServShptLine."Service Item Line Description" := PassedServLine."Service Item Line Description";
OnBeforeServShptLineInsert(ServShptLine, ServLine, ServShptHeader);
ServShptLine.Insert();
OnAfterServShptLineInsert(ServShptLine, ServLine, ServShptHeader, ServInvHeader, PassedServLine, ServHeader);
CheckCertificateOfSupplyStatus(ServShptHeader, ServShptLine);
end;
// end inserting Service Shipment Line
if Invoice and Ship then begin
WarrantyLedgerEntry.Reset();
WarrantyLedgerEntry.SetCurrentKey("Service Order No.", "Posting Date", "Document No.");
WarrantyLedgerEntry.SetRange("Service Order No.", ServShptLine."Order No.");
WarrantyLedgerEntry.SetRange("Document No.", ServShptLine."Document No.");
WarrantyLedgerEntry.SetRange(Type, ServShptLine.Type);
WarrantyLedgerEntry.SetRange("No.", ServShptLine."No.");
WarrantyLedgerEntry.SetRange(Open, true);
WarrantyLedgerEntry.ModifyAll(Open, false);
OnPrepareShipmentLineOnAfterWarrantyLedgerEntryModify(ServShptLine);
end;
end;
procedure PrepareInvoiceHeader(var Window: Dialog): Code[20]
var
RecordLinkManagement: Codeunit "Record Link Management";
UseAsExternalDocumentNo: Code[35];
begin
ServInvHeader.Init();
ServHeader.CalcFields("Work Description");
ServInvHeader.TransferFields(ServHeader);
OnPrepareInvoiceHeaderOnAfterServInvHeaderTransferFields(ServHeader, ServInvHeader);
if ServHeader."Document Type" = ServHeader."Document Type"::Order then begin
ServInvHeader."No." := ServHeader."Posting No.";
ServInvHeader."Pre-Assigned No. Series" := '';
ServInvHeader."Order No. Series" := ServHeader."No. Series";
ServInvHeader."Order No." := ServHeader."No.";
if GuiAllowed() then
Window.Update(1, StrSubstNo(Text007, ServHeader."Document Type", ServHeader."No.", ServInvHeader."No."));
end else begin
ServInvHeader."Pre-Assigned No. Series" := ServHeader."No. Series";
ServInvHeader."Pre-Assigned No." := ServHeader."No.";
OnPrepareInvoiceHeaderOnBeforeCheckPostingNo(ServHeader, ServInvHeader);
if ServHeader."Posting No." <> '' then begin
ServInvHeader."No." := ServHeader."Posting No.";
if GuiAllowed() then
Window.Update(1, StrSubstNo(Text007, ServHeader."Document Type", ServHeader."No.", ServInvHeader."No."));
end;
end;
if ServMgtSetup."Ext. Doc. No. Mandatory" then
ServHeader.TestField(ServHeader."External Document No.");
if ServMgtSetup."Copy Comments Order to Invoice" then
RecordLinkManagement.CopyLinks(ServHeader, ServInvHeader);
ServInvHeader."Source Code" := SrcCode;
ServInvHeader."User ID" := CopyStr(UserId(), 1, MaxStrLen(ServInvHeader."User ID"));
ServInvHeader."No. Printed" := 0;
OnBeforeServInvHeaderInsert(ServInvHeader, ServHeader);
ServInvHeader.Insert();
OnAfterServInvHeaderInsert(ServInvHeader, ServHeader);
Clear(ServLogMgt);
case ServHeader."Document Type" of
ServHeader."Document Type"::Invoice:
ServLogMgt.ServInvoicePost(ServHeader."No.", ServInvHeader."No.");
ServHeader."Document Type"::Order:
ServLogMgt.ServOrderInvoicePost(ServHeader."No.", ServInvHeader."No.");
end;
UseAsExternalDocumentNo := ServInvHeader."External Document No.";
if (UseAsExternalDocumentNo = '') and ServMgtSetup."Ext. Doc. No. Mandatory" then
UseAsExternalDocumentNo := ServHeader."No.";
SetGenJnlLineDocNos(GenJnlLineDocType::Invoice, ServInvHeader."No.", UseAsExternalDocumentNo);
if (ServHeader."Document Type" = ServHeader."Document Type"::Invoice) or
(ServHeader."Document Type" = ServHeader."Document Type"::Order) and ServMgtSetup."Copy Comments Order to Invoice"
then
ServOrderMgt.CopyCommentLinesWithSubType(
"Service Comment Table Name"::"Service Header".AsInteger(),
"Service Comment Table Name"::"Service Invoice Header".AsInteger(),
ServHeader."No.", ServInvHeader."No.", ServHeader."Document Type".AsInteger());
OnAfterPrepareInvoiceHeader(ServInvHeader, ServHeader, ServItemLine);
exit(ServInvHeader."No.");
end;
local procedure PrepareInvoiceLine(var PassedServLine: Record "Service Line")
begin
ServInvLine.Init();
ServInvLine.TransferFields(PassedServLine);
ServInvLine."Document No." := ServInvHeader."No.";
ServInvLine.Quantity := PassedServLine."Qty. to Invoice";
ServInvLine."Quantity (Base)" := PassedServLine."Qty. to Invoice (Base)";
PassedServLine.CalcFields(PassedServLine."Service Item Line Description");
ServInvLine."Service Item Line Description" := PassedServLine."Service Item Line Description";
if PassedServLine."Document Type" = PassedServLine."Document Type"::Order then
ServInvLine."Order No." := PassedServLine."Document No.";
OnBeforeServInvLineInsert(ServInvLine, PassedServLine, ServLine);
ServInvLine.Insert();
OnAfterServInvLineInsert(ServInvLine, PassedServLine);
end;
procedure PrepareCrMemoHeader(var Window: Dialog): Code[20]
var
RecordLinkManagement: Codeunit "Record Link Management";
UseAsExternalDocumentNo: Code[35];
begin
ServCrMemoHeader.Init();
ServHeader.CalcFields("Work Description");
ServCrMemoHeader.TransferFields(ServHeader);
ServCrMemoHeader."Pre-Assigned No. Series" := ServHeader."No. Series";
ServCrMemoHeader."Pre-Assigned No." := ServHeader."No.";
if ServHeader."Posting No." <> '' then begin
ServCrMemoHeader."No." := ServHeader."Posting No.";
if GuiAllowed() then
Window.Update(1, StrSubstNo(Text008, ServHeader."Document Type", ServHeader."No.", ServCrMemoHeader."No."));
end;
if ServMgtSetup."Ext. Doc. No. Mandatory" then
ServHeader.TestField(ServHeader."External Document No.");
RecordLinkManagement.CopyLinks(ServHeader, ServCrMemoHeader);
ServCrMemoHeader."Source Code" := SrcCode;
ServCrMemoHeader."User ID" := CopyStr(UserId(), 1, MaxStrLen(ServCrMemoHeader."User ID"));
ServCrMemoHeader."No. Printed" := 0;
OnBeforeServCrMemoHeaderInsert(ServCrMemoHeader, ServHeader);
ServCrMemoHeader.Insert();
OnAfterServCrMemoHeaderInsert(ServCrMemoHeader, ServHeader);
Clear(ServLogMgt);
ServLogMgt.ServCrMemoPost(ServHeader."No.", ServCrMemoHeader."No.");
UseAsExternalDocumentNo := ServCrMemoHeader."External Document No.";
if (UseAsExternalDocumentNo = '') and ServMgtSetup."Ext. Doc. No. Mandatory" then