-
Notifications
You must be signed in to change notification settings - Fork 696
Expand file tree
/
Copy pathLibraryAssembly.Codeunit.al
More file actions
3299 lines (3013 loc) · 174 KB
/
LibraryAssembly.Codeunit.al
File metadata and controls
3299 lines (3013 loc) · 174 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
/// <summary>
/// Provides utility functions for creating and managing assembly-related entities in test scenarios, including assembly orders, BOMs, and assembly items.
/// </summary>
codeunit 132207 "Library - Assembly"
{
Subtype = Normal;
trigger OnRun()
begin
end;
var
LibraryUtility: Codeunit "Library - Utility";
LibraryCosting: Codeunit "Library - Costing";
LibraryPurchase: Codeunit "Library - Purchase";
LibraryInventory: Codeunit "Library - Inventory";
LibraryERM: Codeunit "Library - ERM";
LibraryDimension: Codeunit "Library - Dimension";
LibraryResource: Codeunit "Library - Resource";
LibraryWarehouse: Codeunit "Library - Warehouse";
Assert: Codeunit Assert;
LibraryRandom: Codeunit "Library - Random";
ChangeType: Option " ",Add,Replace,Delete,Edit,"Delete all","Edit cards";
ErrorZeroQty: Label 'Quantity must have a value in Assembly Header: Document Type=Order, No.=%1. It cannot be zero or empty.';
ErrorStdCost: Label 'Changing Unit Cost or Cost Amount is not allowed when Costing Method is Standard.';
BlockType: Option Dimension,"Dimension Value","Dimension Combination","None";
ClearType: Option "Posting Group","Location Posting Setup","Posting Group Setup";
AdjSource: Option Purchase,Revaluation,"Item Card","Order Lines",Resource,"None";
ErrorDimCombination: Label 'The combination of dimensions used in Order %1%2 is blocked. Dimensions %3 and %4 can''t be used concurrently.', Comment = '%1=OrderNo, %2=LineNo, %3=DimensionCode[1], %4=DimensionCode[2]';
ErrorPostingSetup: Label 'The General Posting Setup does not exist. ';
ErrorInvtPostingSetup: Label 'The Inventory Posting Setup does not exist.';
procedure AddCompInventory(AssemblyHeader: Record "Assembly Header"; PostingDate: Date; QtySupplement: Decimal)
var
AssemblyLine: Record "Assembly Line";
Item: Record Item;
begin
AssemblyLine.Reset();
AssemblyLine.SetRange("Document Type", AssemblyHeader."Document Type");
AssemblyLine.SetRange("Document No.", AssemblyHeader."No.");
AssemblyLine.SetRange(Type, AssemblyLine.Type::Item);
if AssemblyLine.FindSet() then
repeat
Item.Get(AssemblyLine."No.");
if Item.IsInventoriableType() then
AddItemInventory(
AssemblyLine, PostingDate, AssemblyLine."Location Code", AssemblyLine."Bin Code", AssemblyLine.Quantity + QtySupplement);
until AssemblyLine.Next() = 0;
end;
procedure AddCompInventoryToBin(AssemblyHeader: Record "Assembly Header"; PostingDate: Date; QtySupplement: Decimal; LocationCode: Code[10]; BinCode: Code[20])
var
AssemblyLine: Record "Assembly Line";
Bin: Record Bin;
Location: Record Location;
ItemJournalTemplate: Record "Item Journal Template";
ItemJournalBatch: Record "Item Journal Batch";
ItemJournalLine: Record "Item Journal Line";
WarehouseJournalTemplate: Record "Warehouse Journal Template";
WarehouseJournalBatch: Record "Warehouse Journal Batch";
WarehouseJournalLine: Record "Warehouse Journal Line";
Item: Record Item;
isDirected: Boolean;
begin
isDirected := false;
if BinCode <> '' then begin
Bin.SetRange(Code, BinCode);
Bin.SetRange("Location Code", LocationCode);
Bin.FindFirst();
Location.Get(LocationCode);
if Location."Directed Put-away and Pick" then
isDirected := true;
end;
SetupItemJournal(ItemJournalTemplate, ItemJournalBatch);
if isDirected then begin
LibraryWarehouse.WarehouseJournalSetup(LocationCode, WarehouseJournalTemplate, WarehouseJournalBatch);
AssemblyLine.Reset();
AssemblyLine.SetRange("Document Type", AssemblyHeader."Document Type");
AssemblyLine.SetRange("Document No.", AssemblyHeader."No.");
AssemblyLine.SetRange(Type, AssemblyLine.Type::Item);
if AssemblyLine.FindSet() then
repeat
LibraryWarehouse.CreateWhseJournalLine(WarehouseJournalLine, WarehouseJournalTemplate.Name, WarehouseJournalBatch.Name,
LocationCode, Bin."Zone Code", BinCode,
WarehouseJournalLine."Entry Type"::"Positive Adjmt.", AssemblyLine."No.", AssemblyLine.Quantity + QtySupplement);
until AssemblyLine.Next() = 0;
LibraryWarehouse.RegisterWhseJournalLine(WarehouseJournalTemplate.Name, WarehouseJournalBatch.Name, LocationCode,
true);
// Add to inventory
Item.SetRange("Location Filter", LocationCode);
LibraryWarehouse.CalculateWhseAdjustment(Item, ItemJournalBatch);
end else begin
AssemblyLine.Reset();
AssemblyLine.SetRange("Document Type", AssemblyHeader."Document Type");
AssemblyLine.SetRange("Document No.", AssemblyHeader."No.");
AssemblyLine.SetRange(Type, AssemblyLine.Type::Item);
if AssemblyLine.FindSet() then
repeat
LibraryInventory.CreateItemJournalLine(ItemJournalLine, ItemJournalTemplate.Name, ItemJournalBatch.Name,
ItemJournalLine."Entry Type"::"Positive Adjmt.", AssemblyLine."No.", AssemblyLine.Quantity + QtySupplement);
ItemJournalLine.Validate("Posting Date", CalcDate('<-1D>', PostingDate));
ItemJournalLine.Validate("Document Date", CalcDate('<-1D>', ItemJournalLine."Posting Date"));
ItemJournalLine.Validate("Unit of Measure Code", AssemblyLine."Unit of Measure Code");
ItemJournalLine.Validate("Variant Code", AssemblyLine."Variant Code");
ItemJournalLine.Validate("Unit Cost", LibraryRandom.RandDec(50, 2));
ItemJournalLine.Validate("Location Code", LocationCode);
ItemJournalLine.Validate("Bin Code", BinCode);
ItemJournalLine.Modify(true);
until AssemblyLine.Next() = 0;
end;
LibraryInventory.PostItemJournalLine(ItemJournalTemplate.Name, ItemJournalBatch.Name);
end;
procedure AddItemInventory(AssemblyLine: Record "Assembly Line"; PostingDate: Date; LocationCode: Code[10]; BinCode: Code[20]; Qty: Decimal)
var
ItemJournalLine: Record "Item Journal Line";
ItemJournalTemplate: Record "Item Journal Template";
ItemJournalBatch: Record "Item Journal Batch";
Location: Record Location;
Bin: Record Bin;
WarehouseJournalLine: Record "Warehouse Journal Line";
WarehouseJournalTemplate: Record "Warehouse Journal Template";
WarehouseJournalBatch: Record "Warehouse Journal Batch";
Item: Record Item;
isDirected: Boolean;
begin
isDirected := false;
if BinCode <> '' then begin
Bin.SetRange(Code, BinCode);
Bin.SetRange("Location Code", LocationCode);
Bin.FindFirst();
Location.Get(LocationCode);
if Location."Directed Put-away and Pick" then
isDirected := true;
end;
SetupItemJournal(ItemJournalTemplate, ItemJournalBatch);
if isDirected then begin
LibraryWarehouse.WarehouseJournalSetup(LocationCode, WarehouseJournalTemplate, WarehouseJournalBatch);
LibraryWarehouse.CreateWhseJournalLine(WarehouseJournalLine, WarehouseJournalTemplate.Name, WarehouseJournalBatch.Name,
LocationCode, Bin."Zone Code", BinCode,
WarehouseJournalLine."Entry Type"::"Positive Adjmt.", AssemblyLine."No.", Qty);
LibraryWarehouse.RegisterWhseJournalLine(WarehouseJournalTemplate.Name, WarehouseJournalBatch.Name, LocationCode,
true);
// Add to inventory
Item.SetRange("No.", AssemblyLine."No.");
Item.SetRange("Location Filter", LocationCode);
LibraryWarehouse.CalculateWhseAdjustment(Item, ItemJournalBatch);
end else begin
LibraryInventory.CreateItemJournalLine(ItemJournalLine, ItemJournalTemplate.Name, ItemJournalBatch.Name,
ItemJournalLine."Entry Type"::"Positive Adjmt.", AssemblyLine."No.", Qty);
ItemJournalLine.Validate("Posting Date", CalcDate('<-1D>', PostingDate));
ItemJournalLine.Validate("Document Date", CalcDate('<-1D>', ItemJournalLine."Posting Date"));
ItemJournalLine.Validate("Unit of Measure Code", AssemblyLine."Unit of Measure Code");
ItemJournalLine.Validate("Variant Code", AssemblyLine."Variant Code");
ItemJournalLine.Validate("Unit Cost", LibraryRandom.RandDec(50, 2));
ItemJournalLine.Validate("Location Code", LocationCode);
ItemJournalLine.Validate("Bin Code", BinCode);
ItemJournalLine.Modify(true);
end;
LibraryInventory.PostItemJournalLine(ItemJournalTemplate.Name, ItemJournalBatch.Name);
end;
procedure AddAssemblyHeaderComment(AssemblyHeader: Record "Assembly Header"; AssemblyLineNo: Integer)
var
AssemblyCommentLine: Record "Assembly Comment Line";
begin
Clear(AssemblyCommentLine);
AssemblyCommentLine.Init();
AssemblyCommentLine.Validate("Document Type", AssemblyHeader."Document Type");
AssemblyCommentLine.Validate("Document No.", AssemblyHeader."No.");
AssemblyCommentLine.Validate("Document Line No.", AssemblyLineNo);
AssemblyCommentLine.Validate(Comment, 'Order:' + AssemblyHeader."No." + ', Line:' + Format(AssemblyLineNo));
AssemblyCommentLine.Insert(true);
end;
procedure AddAssemblyLineComment(var AssemblyCommentLine: Record "Assembly Comment Line"; DocType: Option; DocumentNo: Code[20]; DocumentLineNo: Integer; Date: Date; Comment: Text[80])
var
RecRef: RecordRef;
begin
Clear(AssemblyCommentLine);
AssemblyCommentLine.Validate("Document Type", DocType);
AssemblyCommentLine.Validate("Document No.", DocumentNo);
AssemblyCommentLine.Validate("Document Line No.", DocumentLineNo);
RecRef.GetTable(AssemblyCommentLine);
AssemblyCommentLine.Validate("Line No.", LibraryUtility.GetNewLineNo(RecRef, AssemblyCommentLine.FieldNo("Line No.")));
AssemblyCommentLine.Insert(true);
AssemblyCommentLine.Validate(Date, Date);
AssemblyCommentLine.Validate(Comment, Comment);
AssemblyCommentLine.Modify(true);
end;
procedure AddEntityDimensions(Type: Enum "BOM Component Type"; No: Code[20])
var
TempDimension: Record Dimension temporary;
TempDimensionValue: Record "Dimension Value" temporary;
DefaultDimension: Record "Default Dimension";
AssemblyLine: Record "Assembly Line";
begin
CreateDimensionSetup(TempDimension, TempDimensionValue);
TempDimension.FindSet();
TempDimensionValue.FindSet();
repeat
case Type of
AssemblyLine.Type::Item:
LibraryDimension.CreateDefaultDimensionItem(DefaultDimension, No, TempDimension.Code, TempDimensionValue.Code);
AssemblyLine.Type::Resource:
LibraryDimension.CreateDefaultDimensionResource(DefaultDimension, No, TempDimension.Code, TempDimensionValue.Code);
end;
TempDimensionValue.Next();
until TempDimension.Next() = 0;
end;
procedure BatchPostAssemblyHeaders(var AssemblyHeader: Record "Assembly Header"; PostingDate: Date; ReplacePostingDate: Boolean; ExpectedError: Text[1024])
var
BatchPostAssemblyOrders: Report "Batch Post Assembly Orders";
begin
BatchPostAssemblyOrders.UseRequestPage(false);
BatchPostAssemblyOrders.InitializeRequest(PostingDate, ReplacePostingDate);
BatchPostAssemblyOrders.SetTableView(AssemblyHeader);
if ExpectedError = '' then
BatchPostAssemblyOrders.RunModal()
else begin
asserterror BatchPostAssemblyOrders.RunModal();
Assert.IsTrue(StrPos(GetLastErrorText, ExpectedError) > 0, 'Actual:' + GetLastErrorText);
ClearLastError();
end;
end;
procedure BlockDimensions(TableID: Integer; DimBlockType: Option; EntityNo: Code[20]; OrderNo: Code[20]; LineNo: Text[30]): Text[1024]
var
Dimension: Record Dimension;
DimensionValue: Record "Dimension Value";
DimensionCombination: Record "Dimension Combination";
DefaultDimension: Record "Default Dimension";
DimensionCode: array[5] of Code[20];
"Count": Integer;
ExpectedError: Text[1024];
begin
LibraryDimension.FindDefaultDimension(DefaultDimension, TableID, EntityNo);
DefaultDimension.FindSet();
for Count := 1 to DefaultDimension.Count do begin
DimensionCode[Count] := DefaultDimension."Dimension Code";
DefaultDimension.Next();
end;
ExpectedError := '';
case DimBlockType of
BlockType::Dimension:
begin
Dimension.Get(DefaultDimension."Dimension Code");
Dimension.Validate(Blocked, true);
Dimension.Modify(true);
ExpectedError := 'Dimension ' + Dimension.Code + ' is blocked.';
end;
BlockType::"Dimension Value":
begin
DimensionValue.Get(DefaultDimension."Dimension Code", DefaultDimension."Dimension Value Code");
DimensionValue.Validate(Blocked, true);
DimensionValue.Modify(true);
ExpectedError := 'Dimension Value ' + DimensionValue."Dimension Code" + ' - ' + DimensionValue.Code + ' is blocked.';
end;
BlockType::"Dimension Combination":
begin
DimensionCombination.Get(DimensionCode[1], DimensionCode[2]);
DimensionCombination.Validate("Combination Restriction", DimensionCombination."Combination Restriction"::Blocked);
DimensionCombination.Modify(true);
ExpectedError := StrSubstNo(ErrorDimCombination, OrderNo, LineNo, DimensionCode[1], DimensionCode[2]);
end;
end;
exit(ExpectedError);
end;
procedure BlockOrderDimensions(AssemblyHeader: Record "Assembly Header"; HeaderBlockType: Option; CompBlockType: Option): Text[1024]
var
AssemblyLine: Record "Assembly Line";
TableID: Integer;
HeaderError: Text[1024];
CompError: Text[1024];
begin
AssemblyLine.SetRange("Document Type", AssemblyHeader."Document Type");
AssemblyLine.SetRange("Document No.", AssemblyHeader."No.");
if AssemblyLine.FindFirst() then begin
case AssemblyLine.Type of
AssemblyLine.Type::Item:
TableID := 27;
AssemblyLine.Type::Resource:
TableID := 156;
AssemblyLine.Type::" ":
begin
TableID := 0;
AssemblyLine.TestField("Dimension Set ID", 0);
end;
end;
CompError := BlockDimensions(TableID, CompBlockType, AssemblyLine."No.",
AssemblyLine."Document No.", ', line no. ' + Format(AssemblyLine."Line No."));
end;
HeaderError := BlockDimensions(27, HeaderBlockType, AssemblyHeader."Item No.", AssemblyHeader."No.", '');
if HeaderError <> '' then
exit(HeaderError);
if CompError <> '' then
exit(CompError);
exit('');
end;
procedure CalcExpectedStandardCost(var MaterialCost: Decimal; var CapacityCost: Decimal; var CapOverhead: Decimal; ParentItemNo: Code[20]): Decimal
var
BOMComponent: Record "BOM Component";
Item: Record Item;
Item1: Record Item;
Resource: Record Resource;
ItemUnitOfMeasure: Record "Item Unit of Measure";
ResourceUnitOfMeasure: Record "Resource Unit of Measure";
ExpectedCost: Decimal;
LotSize: Decimal;
LineCost: Decimal;
begin
ExpectedCost := 0;
MaterialCost := 0;
CapacityCost := 0;
CapOverhead := 0;
BOMComponent.SetRange("Parent Item No.", ParentItemNo);
Item.Get(ParentItemNo);
if BOMComponent.FindSet() then
repeat
case BOMComponent.Type of
BOMComponent.Type::Item:
begin
Item1.Get(BOMComponent."No.");
ItemUnitOfMeasure.Get(Item1."No.", BOMComponent."Unit of Measure Code");
LineCost := Item1."Unit Cost" * BOMComponent."Quantity per" * ItemUnitOfMeasure."Qty. per Unit of Measure";
ExpectedCost += LineCost;
MaterialCost += LineCost;
end;
BOMComponent.Type::Resource:
begin
Resource.Get(BOMComponent."No.");
ResourceUnitOfMeasure.Get(Resource."No.", BOMComponent."Unit of Measure Code");
if (BOMComponent."Resource Usage Type" = BOMComponent."Resource Usage Type"::Direct) or (Item."Lot Size" = 0) then
LotSize := 1
else
LotSize := Item."Lot Size";
LineCost := (Resource."Unit Cost" * BOMComponent."Quantity per" * ResourceUnitOfMeasure."Qty. per Unit of Measure"
) / LotSize;
CapOverhead += LineCost - Resource."Direct Unit Cost" *
BOMComponent."Quantity per" * ResourceUnitOfMeasure."Qty. per Unit of Measure" / LotSize;
CapacityCost += LineCost;
ExpectedCost += LineCost;
end
end;
until BOMComponent.Next() = 0;
if ExpectedCost = 0 then
exit(Item."Standard Cost");
ExpectedCost := ExpectedCost * (1 + Item."Indirect Cost %" / 100) + Item."Overhead Rate";
MaterialCost := Round(MaterialCost, LibraryERM.GetUnitAmountRoundingPrecision());
CapacityCost := Round(CapacityCost, LibraryERM.GetUnitAmountRoundingPrecision());
CapOverhead := Round(CapOverhead, LibraryERM.GetUnitAmountRoundingPrecision());
exit(Round(ExpectedCost, LibraryERM.GetUnitAmountRoundingPrecision()));
end;
procedure CalcExpectedPrice(ParentItemNo: Code[20]): Decimal
var
Item: Record Item;
BOMComponent: Record "BOM Component";
ItemUnitOfMeasure: Record "Item Unit of Measure";
Resource: Record Resource;
ResUnitOfMeasure: Record "Resource Unit of Measure";
ExpectedPrice: Decimal;
begin
ExpectedPrice := 0;
BOMComponent.SetRange("Parent Item No.", ParentItemNo);
BOMComponent.SetRange(Type, BOMComponent.Type::Item);
if BOMComponent.FindSet() then
repeat
Item.Get(BOMComponent."No.");
ItemUnitOfMeasure.Get(Item."No.", BOMComponent."Unit of Measure Code");
ExpectedPrice += Item."Unit Price" * BOMComponent."Quantity per" * ItemUnitOfMeasure."Qty. per Unit of Measure";
until BOMComponent.Next() = 0;
Item.Get(ParentItemNo);
BOMComponent.SetRange(Type, BOMComponent.Type::Resource);
if BOMComponent.FindSet() then
repeat
Resource.Get(BOMComponent."No.");
ResUnitOfMeasure.Get(Resource."No.", BOMComponent."Unit of Measure Code");
ExpectedPrice += Resource."Unit Price" * BOMComponent."Quantity per" * ResUnitOfMeasure."Qty. per Unit of Measure"
until BOMComponent.Next() = 0;
if ExpectedPrice = 0 then
exit(Item."Unit Price");
exit(Round(ExpectedPrice, LibraryERM.GetUnitAmountRoundingPrecision()));
end;
procedure CalcOrderCostAmount(var MaterialCost: Decimal; var ResourceCost: Decimal; var ResourceOvhd: Decimal; var AssemblyOvhd: Decimal; AssemblyHeaderNo: Code[20]): Decimal
var
Item: Record Item;
AssemblyLine: Record "Assembly Line";
AssemblyHeader: Record "Assembly Header";
ExpectedCost: Decimal;
Overhead: Decimal;
IndirectCost: Decimal;
UnitCost: Decimal;
LineCost: Decimal;
LineOverhead: Decimal;
begin
ExpectedCost := 0;
MaterialCost := 0;
ResourceCost := 0;
ResourceOvhd := 0;
AssemblyLine.SetCurrentKey("Document Type", "Document No.", Type);
AssemblyLine.SetRange("Document Type", AssemblyLine."Document Type"::Order);
AssemblyLine.SetRange("Document No.", AssemblyHeaderNo);
AssemblyLine.SetFilter(Type, '<>%1', AssemblyLine.Type::" ");
if AssemblyLine.FindSet() then
repeat
GetCostInformation(UnitCost, Overhead, IndirectCost, AssemblyLine.Type, AssemblyLine."No.", '', '');
LineOverhead := Overhead * AssemblyLine.Quantity * AssemblyLine."Qty. per Unit of Measure";
LineCost := AssemblyLine."Unit Cost" * AssemblyLine.Quantity;
if AssemblyLine.Type = AssemblyLine.Type::Item then
MaterialCost += LineCost
else begin
ResourceCost += LineCost;
ResourceOvhd += LineOverhead;
end
until AssemblyLine.Next() = 0;
AssemblyHeader.Get(AssemblyHeader."Document Type"::Order, AssemblyHeaderNo);
Item.Get(AssemblyHeader."Item No.");
AssemblyOvhd := Item."Indirect Cost %" / 100 * (MaterialCost + ResourceCost + ResourceOvhd) +
Item."Overhead Rate" * AssemblyHeader.Quantity * AssemblyHeader."Qty. per Unit of Measure";
if Item."Costing Method" = Item."Costing Method"::Standard then
exit((Item."Standard Cost" * (100 + Item."Indirect Cost %") / 100 + Item."Overhead Rate") *
AssemblyHeader.Quantity * AssemblyHeader."Qty. per Unit of Measure");
MaterialCost := Round(MaterialCost, LibraryERM.GetAmountRoundingPrecision());
ResourceCost := Round(ResourceCost, LibraryERM.GetAmountRoundingPrecision());
ResourceOvhd := Round(ResourceOvhd, LibraryERM.GetAmountRoundingPrecision());
AssemblyOvhd := Round(AssemblyOvhd, LibraryERM.GetAmountRoundingPrecision());
ExpectedCost := MaterialCost + ResourceCost + ResourceOvhd + AssemblyOvhd;
exit(Round(ExpectedCost, LibraryERM.GetAmountRoundingPrecision()));
end;
procedure ChangeResourceUsage(AssemblyHeaderNo: Code[20])
var
AssemblyLine: Record "Assembly Line";
begin
AssemblyLine.SetCurrentKey("Document Type", "Document No.", Type);
AssemblyLine.SetRange("Document Type", AssemblyLine."Document Type"::Order);
AssemblyLine.SetRange("Document No.", AssemblyHeaderNo);
AssemblyLine.SetRange(Type, AssemblyLine.Type::Resource);
AssemblyLine.Next(LibraryRandom.RandInt(AssemblyLine.Count));
if AssemblyLine."Resource Usage Type" = AssemblyLine."Resource Usage Type"::Fixed then
AssemblyLine.Validate("Resource Usage Type", AssemblyLine."Resource Usage Type"::Direct)
else
AssemblyLine.Validate("Resource Usage Type", AssemblyLine."Resource Usage Type"::Fixed)
end;
procedure ClearOrderPostingSetup(OrderClearType: Option; InvtPostingGroup: Code[20]; GenProdPostingGroup: Code[20]; LocationCode: Code[10]): Text[1024]
var
InventoryPostingSetup: Record "Inventory Posting Setup";
GeneralPostingSetup: Record "General Posting Setup";
ExpectedError: Text[1024];
begin
ExpectedError := '';
case OrderClearType of
ClearType::"Posting Group Setup":
begin
InventoryPostingSetup.SetRange("Invt. Posting Group Code", InvtPostingGroup);
if InventoryPostingSetup.FindFirst() then
InventoryPostingSetup.DeleteAll();
GeneralPostingSetup.SetRange("Gen. Prod. Posting Group", GenProdPostingGroup);
if GeneralPostingSetup.FindFirst() then
GeneralPostingSetup.DeleteAll();
ExpectedError := ErrorPostingSetup;
end;
ClearType::"Location Posting Setup":
begin
InventoryPostingSetup.SetRange("Location Code", LocationCode);
InventoryPostingSetup.SetRange("Invt. Posting Group Code", InvtPostingGroup);
if InventoryPostingSetup.FindFirst() then
InventoryPostingSetup.DeleteAll();
ExpectedError := ErrorInvtPostingSetup;
end;
end;
exit(ExpectedError);
end;
local procedure CreateAssemblyHeaderLocal(var AssemblyHeader: Record "Assembly Header"; DueDate: Date; ParentItemNo: Code[20]; LocationCode: Code[10]; Quantity: Decimal; DocumentType: Enum "Assembly Document Type"; VariantCode: Code[10]): Code[20]
begin
Clear(AssemblyHeader);
AssemblyHeader."Document Type" := DocumentType;
AssemblyHeader.Insert(true);
AssemblyHeader.Validate("Item No.", ParentItemNo);
AssemblyHeader.Validate("Location Code", LocationCode);
AssemblyHeader.Validate("Due Date", DueDate);
AssemblyHeader.Validate(Quantity, Quantity);
if VariantCode <> '' then
AssemblyHeader.Validate("Variant Code", VariantCode);
AssemblyHeader.Modify(true);
exit(AssemblyHeader."No.");
end;
procedure CreateAssemblyHeader(var AssemblyHeader: Record "Assembly Header"; DueDate: Date; ParentItemNo: Code[20]; LocationCode: Code[10]; Quantity: Decimal; VariantCode: Code[10]): Code[20]
begin
exit(
CreateAssemblyHeaderLocal(
AssemblyHeader, DueDate, ParentItemNo, LocationCode, Quantity, AssemblyHeader."Document Type"::Order, VariantCode));
end;
procedure CreateAssemblyQuote(var AssemblyHeader: Record "Assembly Header"; DueDate: Date; ParentItemNo: Code[20]; LocationCode: Code[10]; Quantity: Decimal; VariantCode: Code[10]): Code[20]
begin
exit(
CreateAssemblyHeaderLocal(
AssemblyHeader, DueDate, ParentItemNo, LocationCode, Quantity, AssemblyHeader."Document Type"::Quote, VariantCode));
end;
procedure CreateAssemblyLine(AssemblyHeader: Record "Assembly Header"; var AssemblyLine: Record "Assembly Line"; Type: Enum "BOM Component Type"; No: Code[20]; UOMCode: Code[10]; Quantity: Decimal; QtyPer: Decimal; Desc: Text[100])
var
RecRef: RecordRef;
begin
Clear(AssemblyLine);
AssemblyLine."Document Type" := AssemblyHeader."Document Type";
AssemblyLine."Document No." := AssemblyHeader."No.";
RecRef.GetTable(AssemblyLine);
AssemblyLine.Validate("Line No.", LibraryUtility.GetNewLineNo(RecRef, AssemblyLine.FieldNo("Line No.")));
AssemblyLine.Insert(true);
AssemblyLine.Validate(Type, Type);
AssemblyLine.Validate("No.", No);
if AssemblyHeader.Quantity <> 0 then
AssemblyLine."Quantity per" := AssemblyLine.CalcQuantityPer(Quantity);
AssemblyLine.Validate(Quantity, Quantity);
AssemblyLine.Validate("Unit of Measure Code", UOMCode);
if QtyPer <> 0 then
AssemblyLine.Validate("Quantity per", QtyPer);
AssemblyLine.Validate(Description, Desc);
AssemblyLine.Modify(true);
end;
procedure CreateAssemblyLines(CostingMethod: Enum "Costing Method"; AssemblyHeaderNo: Code[20]; NoOfItems: Integer; NoOfResources: Integer)
var
AssemblyHeader: Record "Assembly Header";
TempItem: Record Item temporary;
TempResource: Record Resource temporary;
AssemblyLine: Record "Assembly Line";
begin
SetupComponents(TempItem, TempResource, CostingMethod, NoOfItems, NoOfResources, '', '');
AssemblyHeader.Get(AssemblyHeader."Document Type"::Order, AssemblyHeaderNo);
if TempItem.FindSet() then
repeat
CreateAssemblyLine(AssemblyHeader, AssemblyLine, "BOM Component Type"::Item, TempItem."No.",
GetUnitOfMeasureCode("BOM Component Type"::Item, TempItem."No.", true), LibraryRandom.RandDec(20, 2), 0, '');
until TempItem.Next() = 0;
if TempResource.FindSet() then
repeat
CreateAssemblyLine(AssemblyHeader, AssemblyLine, "BOM Component Type"::Resource, TempResource."No.",
GetUnitOfMeasureCode("BOM Component Type"::Resource, TempResource."No.", true), LibraryRandom.RandDec(20, 2), 0, '');
until TempResource.Next() = 0;
end;
procedure CreateAssemblyList(CostingMethod: Enum "Costing Method"; ParentItemNo: Code[20]; UseBaseUnitOfMeasure: Boolean; NoOfItems: Integer; NoOfResources: Integer; NoOfTexts: Integer; QtyPerFactor: Integer; GenProdPostingGroup: Code[20]; InventoryPostingGroup: Code[20])
var
BOMComponent: Record "BOM Component";
TempItem: Record Item temporary;
TempResource: Record Resource temporary;
CompCount: Integer;
begin
SetupComponents(TempItem, TempResource, CostingMethod, NoOfItems, NoOfResources, GenProdPostingGroup, InventoryPostingGroup);
if TempItem.FindSet() then
repeat
CreateAssemblyListComponent(BOMComponent.Type::Item, TempItem."No.", ParentItemNo, '',
BOMComponent."Resource Usage Type"::Direct, QtyPerFactor * LibraryRandom.RandDec(20, 5), UseBaseUnitOfMeasure);
until TempItem.Next() = 0;
CompCount := 1;
if TempResource.FindSet() then
repeat
if CompCount mod 2 = 0 then
CreateAssemblyListComponent(BOMComponent.Type::Resource, TempResource."No.", ParentItemNo, '',
BOMComponent."Resource Usage Type"::Direct, QtyPerFactor * LibraryRandom.RandDec(20, 5), UseBaseUnitOfMeasure)
else
CreateAssemblyListComponent(BOMComponent.Type::Resource, TempResource."No.", ParentItemNo, '',
BOMComponent."Resource Usage Type"::Fixed, QtyPerFactor * LibraryRandom.RandDec(20, 5), UseBaseUnitOfMeasure);
CompCount += 1;
until TempResource.Next() = 0;
for CompCount := 1 to NoOfTexts do
CreateAssemblyListComponent(BOMComponent.Type::" ", '', ParentItemNo, '',
BOMComponent."Resource Usage Type"::Direct, 0, UseBaseUnitOfMeasure);
Commit();
end;
procedure CreateAssemblyListComponent(ComponentType: Enum "BOM Component Type"; ComponentNo: Code[20]; ParentItemNo: Code[20]; VariantCode: Code[10]; ResourceUsage: Option; Qty: Decimal; UseBaseUnitOfMeasure: Boolean)
var
BOMComponent: Record "BOM Component";
begin
LibraryInventory.CreateBOMComponent(
BOMComponent, ParentItemNo, ComponentType, ComponentNo, Qty, GetUnitOfMeasureCode(ComponentType, ComponentNo, UseBaseUnitOfMeasure));
if ComponentType = BOMComponent.Type::Resource then
BOMComponent.Validate("Resource Usage Type", ResourceUsage);
BOMComponent.Validate("Variant Code", VariantCode);
BOMComponent.Validate(
Description, LibraryUtility.GenerateRandomCode(BOMComponent.FieldNo(Description), DATABASE::"BOM Component"));
BOMComponent.Modify(true);
Commit();
end;
procedure CreateAssemblySetup(var AssemblySetup: Record "Assembly Setup"; LocationCode: Code[10]; DimensionsFrom: Option; PostedOrdersNo: Code[20])
begin
if AssemblySetup."Assembly Order Nos." = '' then
AssemblySetup.Validate("Assembly Order Nos.",
LibraryUtility.GetGlobalNoSeriesCode());
if AssemblySetup."Posted Assembly Order Nos." = '' then
AssemblySetup.Validate("Posted Assembly Order Nos.", LibraryUtility.GetGlobalNoSeriesCode());
if AssemblySetup."Assembly Quote Nos." = '' then
AssemblySetup.Validate("Assembly Quote Nos.", LibraryUtility.GetGlobalNoSeriesCode());
if AssemblySetup."Blanket Assembly Order Nos." = '' then
AssemblySetup.Validate("Blanket Assembly Order Nos.", LibraryUtility.GetGlobalNoSeriesCode());
AssemblySetup.Validate("Default Location for Orders", LocationCode);
AssemblySetup.Validate("Copy Component Dimensions from", DimensionsFrom);
AssemblySetup.Validate("Posted Assembly Order Nos.", PostedOrdersNo);
AssemblySetup.Modify(true);
end;
#if not CLEAN26
[Obsolete('Moved to codeunit Library Manufacturing as CreateProductionBOM', '26.0')]
procedure CreateBOM(var Item: Record Item; NoOfComps: Integer)
var
LibraryManufacturing: Codeunit "Library - Manufacturing";
begin
LibraryManufacturing.CreateProductionBOM(Item, NoOfComps);
end;
#endif
#if not CLEAN26
[Obsolete('Moved to codeunit Library Manufacturing as CreateProductionRouting', '26.0')]
procedure CreateRouting(var Item: Record Item; NoOfLines: Integer)
var
LibraryManufacturing: Codeunit "Library - Manufacturing";
begin
LibraryManufacturing.CreateProductionRouting(Item, NoOfLines);
end;
#endif
procedure CreateDimensionSetup(var TempDimension: Record Dimension temporary; var TempDimensionValue: Record "Dimension Value" temporary)
var
DimensionValue: Record "Dimension Value";
DimensionCombination: Record "Dimension Combination";
Dimension: Record Dimension;
"Count": Integer;
DimensionCode: array[5] of Code[20];
begin
for Count := 1 to 2 do begin
LibraryDimension.CreateDimension(Dimension);
DimensionCode[Count] := Dimension.Code;
TempDimension := Dimension;
TempDimension.Insert();
LibraryDimension.CreateDimensionValue(DimensionValue, Dimension.Code);
TempDimensionValue := DimensionValue;
TempDimensionValue.Insert();
end;
LibraryDimension.CreateDimensionCombination(DimensionCombination, DimensionCode[1], DimensionCode[2]);
end;
procedure CreateGLAccount(var GLAccount: Record "G/L Account"; IncomeBalance: Enum "G/L Account Report Type"; Name: Text[30])
begin
LibraryERM.CreateGLAccount(GLAccount);
GLAccount.Validate("Income/Balance", IncomeBalance);
GLAccount.Validate("Debit/Credit", GLAccount."Debit/Credit"::Both);
GLAccount.Validate("Account Type", GLAccount."Account Type"::Posting);
GLAccount.Validate(Name, Name);
GLAccount.Modify(true);
end;
procedure CreateItem(var Item: Record Item; CostingMethod: Enum "Costing Method"; ReplenishmentMethod: Enum "Replenishment System"; GenProdPostingGroup: Code[20]; InventoryPostingGroup: Code[20]): Code[20]
var
GeneralPostingSetup: Record "General Posting Setup";
ItemUnitOfMeasure: Record "Item Unit of Measure";
UnitOfMeasure: Record "Unit of Measure";
VATPostingSetup: Record "VAT Posting Setup";
begin
LibraryInventory.CreateItem(Item);
Item.Validate("Replenishment System", ReplenishmentMethod);
Item.Validate("Costing Method", CostingMethod);
if ReplenishmentMethod <> Item."Replenishment System"::Assembly then begin
if CostingMethod = Item."Costing Method"::Standard then
Item.Validate("Standard Cost", LibraryRandom.RandDec(25, 2))
else
Item.Validate("Unit Cost", LibraryRandom.RandDec(25, 2));
Item.Validate("Unit Price", Item."Unit Cost" + LibraryRandom.RandDec(25, 2));
end else begin
Item.Validate("Standard Cost", 0);
Item.Validate("Unit Cost", 0);
Item.Validate("Unit Price", 0);
end;
Item.Validate("Last Direct Cost", Item."Unit Cost");
if InventoryPostingGroup <> '' then
Item.Validate("Inventory Posting Group", InventoryPostingGroup);
if GenProdPostingGroup = '' then begin
LibraryERM.FindGeneralPostingSetupInvtToGL(GeneralPostingSetup);
GenProdPostingGroup := GeneralPostingSetup."Gen. Prod. Posting Group";
end;
Item.Validate("Gen. Prod. Posting Group", GenProdPostingGroup);
Clear(VATPostingSetup);
LibraryERM.FindVATPostingSetup(VATPostingSetup, VATPostingSetup."VAT Calculation Type"::"Normal VAT");
Item.Validate("VAT Prod. Posting Group", VATPostingSetup."VAT Prod. Posting Group");
Item.Modify(true);
UnitOfMeasure.SetFilter(Code, '<>%1', Item."Base Unit of Measure");
UnitOfMeasure.FindFirst();
LibraryInventory.CreateItemUnitOfMeasure(
ItemUnitOfMeasure, Item."No.", UnitOfMeasure.Code, LibraryRandom.RandInt(10));
exit(Item."No.");
end;
procedure CreateInvtPostingSetup(var InventoryPostingSetup: Record "Inventory Posting Setup"; LocationCode: Code[10]; InvtPostingGroupCode: Code[20]; InvtAccount: Code[20]; MatVarAccount: Code[20]; CapVarAcc: Code[20]; CapOvhdVarAcc: Code[20]; MfgOvhdVarAcc: Code[20]; InvtAccInterim: Code[20])
var
GLAccount: Record "G/L Account";
begin
Clear(InventoryPostingSetup);
InventoryPostingSetup.Init();
InventoryPostingSetup.Validate("Location Code", LocationCode);
InventoryPostingSetup.Validate("Invt. Posting Group Code", InvtPostingGroupCode);
InventoryPostingSetup.Validate("Inventory Account", InvtAccount);
InventoryPostingSetup.Validate("Material Variance Account", MatVarAccount);
InventoryPostingSetup.Validate("Capacity Variance Account", CapVarAcc);
InventoryPostingSetup.Validate("Cap. Overhead Variance Account", CapOvhdVarAcc);
InventoryPostingSetup.Validate("Mfg. Overhead Variance Account", MfgOvhdVarAcc);
InventoryPostingSetup.Validate("Inventory Account (Interim)", InvtAccInterim);
LibraryERM.CreateGLAccount(GLAccount);
InventoryPostingSetup.Validate("WIP Account", GLAccount."No.");
OnBeforeInsertInventoryPostingSetup(InventoryPostingSetup);
InventoryPostingSetup.Insert(true);
end;
procedure CreateInvtMovement(AssemblyHeaderNo: Code[20]; NewCreateInvtPutAway: Boolean; NewCreateInvtPick: Boolean; NewCreateInvtMovement: Boolean)
var
TmpWarehouseRequest: Record "Warehouse Request";
WarehouseRequest: Record "Warehouse Request";
CreateInvtPutAwayPick: Report "Create Invt Put-away/Pick/Mvmt";
begin
WarehouseRequest.SetCurrentKey("Source Document", "Source No.");
WarehouseRequest.SetRange("Source Document", WarehouseRequest."Source Document"::"Assembly Consumption");
WarehouseRequest.SetRange("Source No.", AssemblyHeaderNo);
Commit();
CreateInvtPutAwayPick.InitializeRequest(
NewCreateInvtPutAway, NewCreateInvtPick, NewCreateInvtMovement, false, false);
if WarehouseRequest.HasFilter then
TmpWarehouseRequest.CopyFilters(WarehouseRequest)
else begin
WarehouseRequest.Get(WarehouseRequest.Type,
WarehouseRequest."Location Code",
WarehouseRequest."Source Type",
WarehouseRequest."Source Subtype",
WarehouseRequest."Source No.");
TmpWarehouseRequest.SetRange(Type, WarehouseRequest.Type);
TmpWarehouseRequest.SetRange("Location Code", WarehouseRequest."Location Code");
TmpWarehouseRequest.SetRange("Source Type", WarehouseRequest."Source Type");
TmpWarehouseRequest.SetRange("Source Subtype", WarehouseRequest."Source Subtype");
TmpWarehouseRequest.SetRange("Source No.", WarehouseRequest."Source No.");
end;
CreateInvtPutAwayPick.SetTableView(TmpWarehouseRequest);
CreateInvtPutAwayPick.UseRequestPage(false);
CreateInvtPutAwayPick.RunModal();
end;
procedure AsmOrder_CreateInvtMovement(var WarehouseRequest: Record "Warehouse Request"; NewCreateInvtPutAway: Boolean; NewCreateInvtPick: Boolean; NewCreateInvtMovement: Boolean; NewPrintDocument: Boolean; NewShowError: Boolean)
var
TmpWarehouseRequest: Record "Warehouse Request";
CreateInvtPutAwayPick: Report "Create Invt Put-away/Pick/Mvmt";
begin
Commit();
CreateInvtPutAwayPick.InitializeRequest(
NewCreateInvtPutAway, NewCreateInvtPick, NewCreateInvtMovement, NewPrintDocument, NewShowError);
if WarehouseRequest.HasFilter then
TmpWarehouseRequest.CopyFilters(WarehouseRequest)
else begin
WarehouseRequest.Get(WarehouseRequest.Type,
WarehouseRequest."Location Code",
WarehouseRequest."Source Type",
WarehouseRequest."Source Subtype",
WarehouseRequest."Source No.");
TmpWarehouseRequest.SetRange(Type, WarehouseRequest.Type);
TmpWarehouseRequest.SetRange("Location Code", WarehouseRequest."Location Code");
TmpWarehouseRequest.SetRange("Source Type", WarehouseRequest."Source Type");
TmpWarehouseRequest.SetRange("Source Subtype", WarehouseRequest."Source Subtype");
TmpWarehouseRequest.SetRange("Source No.", WarehouseRequest."Source No.");
end;
CreateInvtPutAwayPick.SetTableView(TmpWarehouseRequest);
CreateInvtPutAwayPick.UseRequestPage(false);
CreateInvtPutAwayPick.RunModal();
end;
procedure CreateWhsePick(AssemblyHeader: Record "Assembly Header"; AssignedUserID: Code[50]; SortingMethod: Option; SetBreakBulkFilter: Boolean; DoNotFillQtyToHandle: Boolean; PrintDocument: Boolean)
begin
AssemblyHeader.CreatePick(false, AssignedUserID, SortingMethod, SetBreakBulkFilter, DoNotFillQtyToHandle, PrintDocument);
end;
procedure CreateMultipleLvlTree(var Item: Record Item; var Item1: Record Item; ReplenishmentMethod: Enum "Replenishment System"; CostingMethod: Enum "Costing Method"; TreeDepth: Integer; NoOfComps: Integer)
var
BOMComponent: Record "BOM Component";
Item2: Record Item;
Depth: Integer;
BOMCreated: Boolean;
begin
CreateItem(Item, CostingMethod, ReplenishmentMethod, '', '');
BOMCreated := false;
OnCreateMultipleLvlTreeOnCreateBOM(Item, NoOfComps, BOMCreated);
if not BOMCreated then
CreateAssemblyList(Item."Costing Method"::Standard, Item."No.", true, NoOfComps, NoOfComps, NoOfComps, 1, '', '');
CreateItem(Item1, Item."Costing Method"::Standard, Item."Replenishment System"::Assembly, '', '');
CreateAssemblyList(Item."Costing Method"::Standard, Item1."No.", true, 2, 1, 0, 1, '', '');
CreateAssemblyListComponent(
BOMComponent.Type::Item, Item."No.", Item1."No.", '', BOMComponent."Resource Usage Type"::Direct,
LibraryRandom.RandDec(20, 2), true);
for Depth := 2 to TreeDepth do begin
CreateItem(Item2, Item."Costing Method"::Standard, Item."Replenishment System"::Assembly, '', '');
CreateAssemblyList(Item."Costing Method"::Standard, Item2."No.", true, 2, 1, 0, 1, '', '');
CreateAssemblyListComponent(BOMComponent.Type::Item, Item1."No.", Item2."No.", '', BOMComponent."Resource Usage Type"::Direct,
LibraryRandom.RandDec(20, 2), true);
Item := Item1;
Item1 := Item2;
Item.Find();
Item.Validate("Replenishment System", ReplenishmentMethod);
Item.Modify(true);
OnCreateMultipleLvlTreeOnCreateBOM(Item, NoOfComps, BOMCreated);
end;
Commit();
end;
procedure CreateItemSubstitution(var ItemSubstitution: Record "Item Substitution"; ItemNo: Code[20])
var
Item1: Record Item;
begin
CreateItem(Item1, Item1."Costing Method"::Standard, Item1."Replenishment System"::Purchase, '', '');
Clear(ItemSubstitution);
ItemSubstitution.Init();
ItemSubstitution.Validate(Type, ItemSubstitution.Type::Item);
ItemSubstitution.Validate("No.", ItemNo);
ItemSubstitution.Validate("Substitute Type", ItemSubstitution."Substitute Type"::Item);
ItemSubstitution.Validate("Substitute No.", Item1."No.");
ItemSubstitution.Insert();
end;
procedure CreateAdjustmentSource(AssemblyHeader: Record "Assembly Header"; PostingDate: Date; AdjustHeader: Boolean; AdjustmentSource: Option; ItemNo: Code[20]; ResourceNo: Code[20])
var
PurchaseHeader: Record "Purchase Header";
PurchaseLine: Record "Purchase Line";
Item: Record Item;
ItemJournalLine: Record "Item Journal Line";
Resource: Record Resource;
begin
if AdjustHeader then
ItemNo := AssemblyHeader."Item No.";
Item.Get(ItemNo);
case AdjustmentSource of
AdjSource::Purchase:
begin
LibraryPurchase.CreatePurchHeader(
PurchaseHeader, PurchaseHeader."Document Type"::Order, '');
LibraryPurchase.CreatePurchaseLine(
PurchaseLine, PurchaseHeader, PurchaseLine.Type::Item, ItemNo, LibraryRandom.RandInt(10));
PurchaseHeader.Validate(
"Vendor Invoice No.", LibraryUtility.GenerateRandomCode(PurchaseHeader.FieldNo("Vendor Invoice No."),
DATABASE::"Purchase Header"));
PurchaseHeader.Modify(true);
LibraryPurchase.PostPurchaseDocument(PurchaseHeader, true, true);
end;
AdjSource::Revaluation:
begin
RevaluateItem(Item, ItemJournalLine, Item."Unit Cost", PostingDate);
LibraryInventory.PostItemJournalLine(ItemJournalLine."Journal Template Name", ItemJournalLine."Journal Batch Name");
end;
AdjSource::"Item Card":
begin
Item."Unit Cost" := Item."Unit Cost" + LibraryRandom.RandDec(10, 2);
if Item."Costing Method" = Item."Costing Method"::Standard then
Item."Standard Cost" := Item."Standard Cost" + LibraryRandom.RandDec(10, 2);
Item.Modify(true);
end;
AdjSource::"Order Lines":
begin
ResourceNo := CreateResource(Resource, true, Item."Gen. Prod. Posting Group");
EditAssemblyLines(ChangeType::Add, "BOM Component Type"::Resource, "BOM Component Type"::Resource, ResourceNo,
AssemblyHeader."No.", true);
end;
AdjSource::Resource:
begin
Resource.Get(ResourceNo);
Resource."Unit Cost" := Resource."Unit Cost" + LibraryRandom.RandDec(10, 2);
Resource.Modify(true);
end
end;
end;
procedure CreateItemWithSKU(var Item: Record Item; CostingMethod: Enum "Costing Method"; ReplenishmentSystem: Enum "Replenishment System"; CreatePer: Enum "SKU Creation Method"; GenProdPostingGr: Code[20]; InvtPostingGr: Code[20]; LocationCode: Code[10])
var
ItemVariant: Record "Item Variant";
begin
CreateItem(Item, CostingMethod, ReplenishmentSystem, GenProdPostingGr, InvtPostingGr);
if CreatePer <> CreatePer::Location then
LibraryInventory.CreateVariant(ItemVariant, Item);
Item."Location Filter" := LocationCode;
Item.Modify();
Item.SetRange("Location Filter", LocationCode);
Item.SetRecFilter();
LibraryInventory.CreateStockKeepingUnit(Item, CreatePer, false, true);
UpdateSKUCards(Item);
end;
procedure CheckOrderDimensions(AssemblyHeader: Record "Assembly Header"; DimensionsFrom: Option)
var
AssemblyLine: Record "Assembly Line";
AssemblySetup: Record "Assembly Setup";
TableID: Integer;
begin
VerifyEntityDimensions(
DATABASE::Item, AssemblyHeader."Item No.", AssemblyHeader."Item No.", true, AssemblyHeader."Dimension Set ID");
AssemblyLine.SetRange("Document Type", AssemblyHeader."Document Type");
AssemblyLine.SetRange("Document No.", AssemblyHeader."No.");
if AssemblyLine.FindSet() then
repeat
case AssemblyLine.Type of
AssemblyLine.Type::Item:
TableID := DATABASE::Item;
AssemblyLine.Type::Resource:
TableID := DATABASE::Resource;
AssemblyLine.Type::" ":
begin
TableID := 0;
AssemblyLine.TestField("Dimension Set ID", 0);
end;
end;
VerifyEntityDimensions(
TableID, AssemblyLine."No.", AssemblyHeader."Item No.",
DimensionsFrom = AssemblySetup."Copy Component Dimensions from"::"Order Header",
AssemblyLine."Dimension Set ID");
until AssemblyLine.Next() = 0;
end;
procedure CreateResource(var Resource: Record Resource; UseRelatedUnitOfMeasure: Boolean; GenProdPostingGroup: Code[20]): Code[20]
var
GeneralPostingSetup: Record "General Posting Setup";
ResourceUnitOfMeasure: Record "Resource Unit of Measure";
UnitOfMeasure: Record "Unit of Measure";
VATPostingSetup: Record "VAT Posting Setup";
begin
LibraryERM.FindVATPostingSetup(VATPostingSetup, VATPostingSetup."VAT Calculation Type"::"Normal VAT");
LibraryResource.CreateResource(Resource, VATPostingSetup."VAT Bus. Posting Group");
UnitOfMeasure.SetFilter(Code, '<>%1', Resource."Base Unit of Measure");
UnitOfMeasure.FindFirst();
// Add a second non-base unit of measure.
Clear(ResourceUnitOfMeasure);
ResourceUnitOfMeasure.Init();
ResourceUnitOfMeasure.Validate("Resource No.", Resource."No.");
ResourceUnitOfMeasure.Validate(Code, UnitOfMeasure.Code);
ResourceUnitOfMeasure.Insert(true);
ResourceUnitOfMeasure.Validate("Qty. per Unit of Measure", LibraryRandom.RandInt(10));
ResourceUnitOfMeasure.Validate("Related to Base Unit of Meas.", UseRelatedUnitOfMeasure);
ResourceUnitOfMeasure.Modify(true);
if GenProdPostingGroup = '' then begin
LibraryERM.FindGeneralPostingSetupInvtToGL(GeneralPostingSetup);
GenProdPostingGroup := GeneralPostingSetup."Gen. Prod. Posting Group";
end;