-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCodeunit_0000000090.txt
6729 lines (6337 loc) · 347 KB
/
Codeunit_0000000090.txt
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
OBJECT Codeunit 90 Purch.-Post
{
OBJECT-PROPERTIES
{
Date=04/01/14;
Time=12:00:00 PM;
Version List=NAVW17.10.00.36366,NAVNA7.10.00.36366;
}
PROPERTIES
{
TableNo=38;
Permissions=TableData 36=m,
TableData 37=m,
TableData 39=imd,
TableData 49=imd,
TableData 93=imd,
TableData 94=imd,
TableData 110=imd,
TableData 111=imd,
TableData 120=imd,
TableData 121=imd,
TableData 122=imd,
TableData 123=imd,
TableData 124=imd,
TableData 125=imd,
TableData 223=imd,
TableData 357=imd,
TableData 359=imd,
TableData 6507=ri,
TableData 6508=rid,
TableData 6650=imd,
TableData 6651=imd;
OnRun=VAR
ItemEntryRelation@1007 : Record 6507;
TempInvoicingSpecification@1013 : TEMPORARY Record 336;
DummyTrackingSpecification@1014 : Record 336;
Vendor@1016 : Record 23;
ICHandledInboxTransaction@1015 : Record 420;
ICPartner@1017 : Record 413;
SalesSetup@1019 : Record 311;
SalesCommentLine@1018 : Record 44;
PurchInvHdr@1006 : Record 122;
PurchHeader2@1011 : Record 38;
ICInboxPurchHdr@1012 : Record 436;
SalesHeader@1041 : Record 36;
UpdateAnalysisView@1002 : Codeunit 410;
UpdateItemAnalysisView@1008 : Codeunit 7150;
CostBaseAmount@1003 : Decimal;
TrackingSpecificationExists@1010 : Boolean;
EndLoop@1009 : Boolean;
GLEntryNo@1005 : Integer;
BiggestLineNo@1021 : Integer;
PrevStatus@1020 : Option;
BEGIN
IF PostingDateExists AND (ReplacePostingDate OR ("Posting Date" = 0D)) THEN BEGIN
"Posting Date" := PostingDate;
VALIDATE("Currency Code");
END;
IF PostingDateExists AND (ReplaceDocumentDate OR ("Document Date" = 0D)) THEN
VALIDATE("Document Date",PostingDate);
CLEARALL;
PurchHeader.COPY(Rec);
WITH PurchHeader DO BEGIN
TESTFIELD("Document Type");
TESTFIELD("Buy-from Vendor No.");
TESTFIELD("Pay-to Vendor No.");
TESTFIELD("Posting Date");
TESTFIELD("Document Date");
IF GenJnlCheckLine.DateNotAllowed("Posting Date") THEN
FIELDERROR("Posting Date",Text045);
IF "Tax Area Code" = '' THEN
SalesTaxCountry := SalesTaxCountry::NoTax
ELSE BEGIN
TaxArea.GET("Tax Area Code");
SalesTaxCountry := TaxArea.Country;
UseExternalTaxEngine := TaxArea."Use External Tax Engine";
END;
CASE "Document Type" OF
"Document Type"::Order:
Ship := FALSE;
"Document Type"::Invoice:
BEGIN
Receive := TRUE;
Invoice := TRUE;
Ship := FALSE;
END;
"Document Type"::"Return Order":
Receive := FALSE;
"Document Type"::"Credit Memo":
BEGIN
Receive := FALSE;
Invoice := TRUE;
Ship := TRUE;
END;
END;
IF NOT (Receive OR Invoice OR Ship) THEN
ERROR(
Text025,
FIELDCAPTION(Receive),FIELDCAPTION(Invoice),FIELDCAPTION(Ship));
WhseReference := "Posting from Whse. Ref.";
"Posting from Whse. Ref." := 0;
IF Invoice THEN
CreatePrepmtLines(PurchHeader,TempPrepmtPurchLine,TRUE);
CheckDim;
CopyAprvlToTempApprvl;
Vend.GET("Buy-from Vendor No.");
Vend.CheckBlockedVendOnDocs(Vend,TRUE);
IF "Pay-to Vendor No." <> "Buy-from Vendor No." THEN BEGIN
Vend.GET("Pay-to Vendor No.");
Vend.CheckBlockedVendOnDocs(Vend,TRUE);
END;
IF "Send IC Document" AND ("IC Direction" = "IC Direction"::Outgoing) AND
("Document Type" IN ["Document Type"::Order,"Document Type"::"Return Order"])
THEN
IF NOT CONFIRM(Text058) THEN
ERROR('');
IF Invoice AND ("IC Direction" = "IC Direction"::Incoming) THEN BEGIN
IF "Document Type" = "Document Type"::Order THEN BEGIN
PurchHeader2.SETRANGE("Document Type","Document Type"::Invoice);
PurchHeader2.SETRANGE("Vendor Order No.","Vendor Order No.");
IF PurchHeader2.FINDFIRST THEN
IF NOT CONFIRM(Text052,TRUE,"No.",PurchHeader2."No.") THEN
ERROR('');
ICInboxPurchHdr.SETRANGE("Document Type","Document Type"::Invoice);
ICInboxPurchHdr.SETRANGE("Vendor Order No.","Vendor Order No.");
IF ICInboxPurchHdr.FINDFIRST THEN
IF NOT CONFIRM(Text053,TRUE,"No.",ICInboxPurchHdr."No.") THEN
ERROR('');
PurchInvHdr.SETRANGE("Vendor Order No.","Vendor Order No.");
IF PurchInvHdr.FINDFIRST THEN
IF NOT CONFIRM(Text054,FALSE,PurchInvHdr."No.","No.") THEN
ERROR('');
END;
IF ("Document Type" = "Document Type"::Invoice) AND ("Vendor Order No." <> '') THEN BEGIN
PurchHeader2.SETRANGE("Document Type","Document Type"::Order);
PurchHeader2.SETRANGE("Vendor Order No.","Vendor Order No.");
IF PurchHeader2.FINDFIRST THEN
IF NOT CONFIRM(Text055,TRUE,PurchHeader2."No.","No.") THEN
ERROR('');
ICInboxPurchHdr.SETRANGE("Document Type","Document Type"::Order);
ICInboxPurchHdr.SETRANGE("Vendor Order No.","Vendor Order No.");
IF ICInboxPurchHdr.FINDFIRST THEN
IF NOT CONFIRM(Text056,TRUE,"No.",ICInboxPurchHdr."No.") THEN
ERROR('');
PurchInvHdr.SETRANGE("Vendor Order No.","Vendor Order No.");
IF PurchInvHdr.FINDFIRST THEN
IF NOT CONFIRM(Text057,FALSE,PurchInvHdr."No.","No.") THEN
ERROR('');
END;
END;
IF Invoice THEN BEGIN
PurchLine.RESET;
PurchLine.SETRANGE("Document Type","Document Type");
PurchLine.SETRANGE("Document No.","No.");
PurchLine.SETFILTER(Quantity,'<>0');
IF "Document Type" IN ["Document Type"::Order,"Document Type"::"Return Order"] THEN
PurchLine.SETFILTER("Qty. to Invoice",'<>0');
Invoice := NOT PurchLine.ISEMPTY;
IF Invoice AND (NOT Receive) AND
("Document Type" = "Document Type"::Order)
THEN BEGIN
Invoice := FALSE;
PurchLine.FINDSET;
REPEAT
Invoice := (PurchLine."Quantity Received" - PurchLine."Quantity Invoiced") <> 0;
UNTIL Invoice OR (PurchLine.NEXT = 0);
END ELSE
IF Invoice AND (NOT Ship) AND
("Document Type" = "Document Type"::"Return Order")
THEN BEGIN
Invoice := FALSE;
PurchLine.FINDSET;
REPEAT
Invoice := (PurchLine."Return Qty. Shipped" - PurchLine."Quantity Invoiced") <> 0;
UNTIL Invoice OR (PurchLine.NEXT = 0);
END;
END;
IF Invoice THEN
CopyAndCheckItemCharge(PurchHeader);
IF Invoice AND NOT ("Document Type" IN ["Document Type"::"Return Order","Document Type"::"Credit Memo"]) THEN
TESTFIELD("Due Date");
IF Receive THEN BEGIN
PurchLine.RESET;
PurchLine.SETRANGE("Document Type","Document Type");
PurchLine.SETRANGE("Document No.","No.");
PurchLine.SETFILTER(Quantity,'<>0');
IF "Document Type" = "Document Type"::Order THEN
PurchLine.SETFILTER("Qty. to Receive",'<>0');
PurchLine.SETRANGE("Receipt No.",'');
Receive := PurchLine.FINDFIRST;
WhseReceive := TempWhseRcptHeader.FINDFIRST;
WhseShip := TempWhseShptHeader.FINDFIRST;
InvtPickPutaway := WhseReference <> 0;
IF Receive THEN
CheckTrackingSpecification(PurchLine);
IF Receive AND NOT (WhseReceive OR WhseShip OR InvtPickPutaway) THEN
CheckWarehouse(PurchLine);
END;
IF Ship THEN BEGIN
PurchLine.RESET;
PurchLine.SETRANGE("Document Type","Document Type");
PurchLine.SETRANGE("Document No.","No.");
PurchLine.SETFILTER(Quantity,'<>0');
PurchLine.SETFILTER("Return Qty. to Ship",'<>0');
PurchLine.SETRANGE("Return Shipment No.",'');
Ship := PurchLine.FINDFIRST;
WhseReceive := TempWhseRcptHeader.FINDFIRST;
WhseShip := TempWhseShptHeader.FINDFIRST;
InvtPickPutaway := WhseReference <> 0;
IF Ship THEN
CheckTrackingSpecification(PurchLine);
IF Ship AND NOT (WhseShip OR WhseReceive OR InvtPickPutaway) THEN
CheckWarehouse(PurchLine);
END;
IF NOT (Receive OR Invoice OR Ship) THEN
IF NOT OnlyAssgntPosting THEN
ERROR(Text001);
IF Invoice THEN BEGIN
PurchLine.RESET;
PurchLine.SETRANGE("Document Type","Document Type");
PurchLine.SETRANGE("Document No.","No.");
PurchLine.SETFILTER("Sales Order Line No.",'<>0');
IF PurchLine.FINDSET THEN
REPEAT
SalesOrderLine.GET(
SalesOrderLine."Document Type"::Order,
PurchLine."Sales Order No.",PurchLine."Sales Order Line No.");
IF Receive AND
Invoice AND
(PurchLine."Qty. to Invoice" <> 0) AND
(PurchLine."Qty. to Receive" <> 0)
THEN
ERROR(Text002);
IF ABS(PurchLine."Quantity Received" - PurchLine."Quantity Invoiced") <
ABS(PurchLine."Qty. to Invoice")
THEN BEGIN
PurchLine."Qty. to Invoice" := PurchLine."Quantity Received" - PurchLine."Quantity Invoiced";
PurchLine."Qty. to Invoice (Base)" := PurchLine."Qty. Received (Base)" - PurchLine."Qty. Invoiced (Base)";
END;
IF ABS(PurchLine.Quantity - (PurchLine."Qty. to Invoice" + PurchLine."Quantity Invoiced")) <
ABS(SalesOrderLine.Quantity - SalesOrderLine."Quantity Invoiced")
THEN
ERROR(
Text003 +
Text004,
PurchLine."Sales Order No.");
UNTIL PurchLine.NEXT = 0;
END;
InitProgressWindow(PurchHeader);
GetGLSetup;
PurchSetup.GET;
GetCurrency;
IF Invoice AND PurchSetup."Ext. Doc. No. Mandatory" THEN
IF "Document Type" IN ["Document Type"::Order,"Document Type"::Invoice] THEN
TESTFIELD("Vendor Invoice No.")
ELSE
TESTFIELD("Vendor Cr. Memo No.");
IF Receive AND ("Receiving No." = '') THEN
IF ("Document Type" = "Document Type"::Order) OR
(("Document Type" = "Document Type"::Invoice) AND PurchSetup."Receipt on Invoice")
THEN BEGIN
TESTFIELD("Receiving No. Series");
"Receiving No." := NoSeriesMgt.GetNextNo("Receiving No. Series","Posting Date",TRUE);
ModifyHeader := TRUE;
END;
IF Ship AND ("Return Shipment No." = '') THEN
IF ("Document Type" = "Document Type"::"Return Order") OR
(("Document Type" = "Document Type"::"Credit Memo") AND PurchSetup."Return Shipment on Credit Memo")
THEN BEGIN
TESTFIELD("Return Shipment No. Series");
"Return Shipment No." := NoSeriesMgt.GetNextNo("Return Shipment No. Series","Posting Date",TRUE);
ModifyHeader := TRUE;
END;
IF Invoice AND ("Posting No." = '') THEN BEGIN
IF ("No. Series" <> '') OR
("Document Type" IN ["Document Type"::Order,"Document Type"::"Return Order"])
THEN
TESTFIELD("Posting No. Series");
IF ("No. Series" <> "Posting No. Series") OR
("Document Type" IN ["Document Type"::Order,"Document Type"::"Return Order"])
THEN BEGIN
"Posting No." := NoSeriesMgt.GetNextNo("Posting No. Series","Posting Date",TRUE);
ModifyHeader := TRUE;
END;
END;
IF NOT ItemChargeAssgntOnly THEN BEGIN
PurchLine.RESET;
PurchLine.SETRANGE("Document Type","Document Type");
PurchLine.SETRANGE("Document No.","No.");
PurchLine.SETFILTER("Sales Order Line No.",'<>0');
IF PurchLine.FINDSET THEN BEGIN
DropShipOrder := TRUE;
IF Receive THEN
REPEAT
IF SalesOrderHeader."No." <> PurchLine."Sales Order No." THEN BEGIN
SalesOrderHeader.GET(
SalesOrderHeader."Document Type"::Order,
PurchLine."Sales Order No.");
SalesOrderHeader.TESTFIELD("Bill-to Customer No.");
SalesOrderHeader.Ship := TRUE;
CODEUNIT.RUN(CODEUNIT::"Release Sales Document",SalesOrderHeader);
IF SalesOrderHeader."Shipping No." = '' THEN BEGIN
SalesOrderHeader.TESTFIELD("Shipping No. Series");
SalesOrderHeader."Shipping No." :=
NoSeriesMgt.GetNextNo(SalesOrderHeader."Shipping No. Series","Posting Date",TRUE);
SalesOrderHeader.MODIFY;
ModifyHeader := TRUE;
END;
END;
UNTIL PurchLine.NEXT = 0;
END;
END;
IF ModifyHeader THEN BEGIN
MODIFY;
COMMIT;
END;
IF PurchSetup."Calc. Inv. Discount" AND
(Status <> Status::Open) AND
NOT ItemChargeAssgntOnly
THEN BEGIN
PurchLine.RESET;
PurchLine.SETRANGE("Document Type","Document Type");
PurchLine.SETRANGE("Document No.","No.");
PurchLine.FINDFIRST;
TempInvoice := Invoice;
TempRcpt := Receive;
TempReturn := Ship;
PurchCalcDisc.RUN(PurchLine);
GET("Document Type","No.");
Invoice := TempInvoice;
Receive := TempRcpt;
Ship := TempReturn;
COMMIT;
END;
IF (Status = Status::Open) OR (Status = Status::"Pending Prepayment") THEN BEGIN
TempInvoice := Invoice;
TempRcpt := Receive;
TempReturn := Ship;
PrevStatus := Status;
CODEUNIT.RUN(CODEUNIT::"Release Purchase Document",PurchHeader);
TESTFIELD(Status,Status::Released);
Status := PrevStatus;
Invoice := TempInvoice;
Receive := TempRcpt;
Ship := TempReturn;
MODIFY;
COMMIT;
Status := Status::Released;
END;
IF Receive OR Ship THEN
ArchiveUnpostedOrder; // has a COMMIT;
IF ("Buy-from IC Partner Code" <> '') AND ICPartner.GET("Buy-from IC Partner Code") THEN
ICPartner.TESTFIELD(Blocked,FALSE);
IF ("Pay-to IC Partner Code" <> '') AND ICPartner.GET("Pay-to IC Partner Code") THEN
ICPartner.TESTFIELD(Blocked,FALSE);
IF "Send IC Document" AND ("IC Status" = "IC Status"::New) AND ("IC Direction" = "IC Direction"::Outgoing) AND
("Document Type" IN ["Document Type"::Order,"Document Type"::"Return Order"])
THEN BEGIN
ICInOutBoxMgt.SendPurchDoc(Rec,TRUE);
"IC Status" := "IC Status"::Pending;
ModifyHeader := TRUE;
END;
IF "IC Direction" = "IC Direction"::Incoming THEN BEGIN
CASE "Document Type" OF
"Document Type"::Invoice:
ICHandledInboxTransaction.SETRANGE("Document No.","Vendor Invoice No.");
"Document Type"::Order:
ICHandledInboxTransaction.SETRANGE("Document No.","Vendor Order No.");
"Document Type"::"Credit Memo":
ICHandledInboxTransaction.SETRANGE("Document No.","Vendor Cr. Memo No.");
"Document Type"::"Return Order":
ICHandledInboxTransaction.SETRANGE("Document No.","Vendor Order No.");
END;
Vendor.GET("Buy-from Vendor No.");
ICHandledInboxTransaction.SETRANGE("IC Partner Code",Vendor."IC Partner Code");
ICHandledInboxTransaction.LOCKTABLE;
IF ICHandledInboxTransaction.FINDFIRST THEN BEGIN
ICHandledInboxTransaction.Status := ICHandledInboxTransaction.Status::Posted;
ICHandledInboxTransaction.MODIFY;
END;
END;
LockTables;
SourceCodeSetup.GET;
SrcCode := SourceCodeSetup.Purchases;
// Insert receipt header
IF Receive THEN BEGIN
IF ("Document Type" = "Document Type"::Order) OR
(("Document Type" = "Document Type"::Invoice) AND PurchSetup."Receipt on Invoice")
THEN BEGIN
IF DropShipOrder THEN BEGIN
PurchRcptHeader.LOCKTABLE;
PurchRcptLine.LOCKTABLE;
SalesShptHeader.LOCKTABLE;
SalesShptLine.LOCKTABLE;
END;
PurchRcptHeader.INIT;
PurchRcptHeader.TRANSFERFIELDS(PurchHeader);
PurchRcptHeader."No." := "Receiving No.";
IF "Document Type" = "Document Type"::Order THEN BEGIN
PurchRcptHeader."Order No. Series" := "No. Series";
PurchRcptHeader."Order No." := "No.";
END;
PurchRcptHeader."No. Printed" := 0;
PurchRcptHeader."Source Code" := SrcCode;
PurchRcptHeader."User ID" := USERID;
PurchRcptHeader.INSERT;
ApprovalMgt.MoveApprvalEntryToPosted(TempApprovalEntry,DATABASE::"Purch. Rcpt. Header",PurchRcptHeader."No.");
IF PurchSetup."Copy Comments Order to Receipt" THEN BEGIN
CopyCommentLines(
"Document Type",PurchCommentLine."Document Type"::Receipt,
"No.",PurchRcptHeader."No.");
PurchRcptHeader.COPYLINKS(Rec);
END;
IF WhseReceive THEN BEGIN
WhseRcptHeader.GET(TempWhseRcptHeader."No.");
WhsePostRcpt.CreatePostedRcptHeader(PostedWhseRcptHeader,WhseRcptHeader,"Receiving No.","Posting Date");
END;
IF WhseShip THEN BEGIN
WhseShptHeader.GET(TempWhseShptHeader."No.");
WhsePostShpt.CreatePostedShptHeader(PostedWhseShptHeader,WhseShptHeader,"Receiving No.","Posting Date");
END;
END;
IF SalesHeader.GET("Document Type",PurchLine."Sales Order No.") THEN
ServItemMgt.CopyReservationEntry(SalesHeader);
END;
// Insert return shipment header
IF Ship THEN
IF ("Document Type" = "Document Type"::"Return Order") OR
(("Document Type" = "Document Type"::"Credit Memo") AND PurchSetup."Return Shipment on Credit Memo")
THEN BEGIN
ReturnShptHeader.INIT;
ReturnShptHeader.TRANSFERFIELDS(PurchHeader);
ReturnShptHeader."No." := "Return Shipment No.";
IF "Document Type" = "Document Type"::"Return Order" THEN BEGIN
ReturnShptHeader."Return Order No. Series" := "No. Series";
ReturnShptHeader."Return Order No." := "No.";
END;
ReturnShptHeader."No. Series" := "Return Shipment No. Series";
ReturnShptHeader."No. Printed" := 0;
ReturnShptHeader."Source Code" := SrcCode;
ReturnShptHeader."User ID" := USERID;
ReturnShptHeader.INSERT;
ApprovalMgt.MoveApprvalEntryToPosted(TempApprovalEntry,DATABASE::"Return Shipment Header",ReturnShptHeader."No.");
IF PurchSetup."Copy Cmts Ret.Ord. to Ret.Shpt" THEN BEGIN
CopyCommentLines(
"Document Type",PurchCommentLine."Document Type"::"Posted Return Shipment",
"No.",ReturnShptHeader."No.");
ReturnShptHeader.COPYLINKS(Rec);
END;
IF WhseShip THEN BEGIN
WhseShptHeader.GET(TempWhseShptHeader."No.");
WhsePostShpt.CreatePostedShptHeader(PostedWhseShptHeader,WhseShptHeader,"Return Shipment No.","Posting Date");
END;
IF WhseReceive THEN BEGIN
WhseRcptHeader.GET(TempWhseRcptHeader."No.");
WhsePostRcpt.CreatePostedRcptHeader(PostedWhseRcptHeader,WhseRcptHeader,"Return Shipment No.","Posting Date");
END;
END;
// Insert invoice header or credit memo header
IF Invoice THEN
IF "Document Type" IN ["Document Type"::Order,"Document Type"::Invoice] THEN BEGIN
PurchInvHeader.INIT;
PurchInvHeader.TRANSFERFIELDS(PurchHeader);
IF "Document Type" = "Document Type"::Order THEN BEGIN
PurchInvHeader."Pre-Assigned No. Series" := '';
PurchInvHeader."No." := "Posting No.";
PurchInvHeader."Order No. Series" := "No. Series";
PurchInvHeader."Order No." := "No.";
IF GUIALLOWED THEN
Window.UPDATE(1,STRSUBSTNO(Text010,"Document Type","No.",PurchInvHeader."No."));
END ELSE BEGIN
IF "Posting No." <> '' THEN BEGIN
PurchInvHeader."No." := "Posting No.";
IF GUIALLOWED THEN
Window.UPDATE(1,STRSUBSTNO(Text010,"Document Type","No.",PurchInvHeader."No."));
END;
PurchInvHeader."Pre-Assigned No. Series" := "No. Series";
PurchInvHeader."Pre-Assigned No." := "No.";
END;
PurchInvHdr."Creditor No." := "Creditor No.";
PurchInvHdr."Payment Reference" := "Payment Reference";
PurchInvHdr."Payment Method Code" := "Payment Method Code";
PurchInvHeader."Source Code" := SrcCode;
PurchInvHeader."User ID" := USERID;
PurchInvHeader."No. Printed" := 0;
PurchInvHeader.INSERT;
ApprovalMgt.MoveApprvalEntryToPosted(TempApprovalEntry,DATABASE::"Purch. Inv. Header",PurchInvHeader."No.");
IF PurchSetup."Copy Comments Order to Invoice" THEN BEGIN
CopyCommentLines(
"Document Type",PurchCommentLine."Document Type"::"Posted Invoice",
"No.",PurchInvHeader."No.");
PurchInvHeader.COPYLINKS(Rec);
END;
IF SalesTaxCountry <> SalesTaxCountry::NoTax THEN
TaxAmountDifference.CopyTaxDifferenceRecords(
TaxAmountDifference."Document Product Area"::Purchase,"Document Type","No.",
TaxAmountDifference."Document Product Area"::"Posted Purchase",
TaxAmountDifference."Document Type"::Invoice,PurchInvHeader."No.");
GenJnlLineDocType := GenJnlLine."Document Type"::Invoice;
GenJnlLineDocNo := PurchInvHeader."No.";
GenJnlLineExtDocNo := "Vendor Invoice No.";
END ELSE BEGIN // Credit Memo
PurchCrMemoHeader.INIT;
PurchCrMemoHeader.TRANSFERFIELDS(PurchHeader);
IF "Document Type" = "Document Type"::"Return Order" THEN BEGIN
PurchCrMemoHeader."No." := "Posting No.";
PurchCrMemoHeader."Pre-Assigned No. Series" := '';
PurchCrMemoHeader."Return Order No. Series" := "No. Series";
PurchCrMemoHeader."Return Order No." := "No.";
IF GUIALLOWED THEN
Window.UPDATE(1,STRSUBSTNO(Text011,"Document Type","No.",PurchCrMemoHeader."No."));
END ELSE BEGIN
PurchCrMemoHeader."Pre-Assigned No. Series" := "No. Series";
PurchCrMemoHeader."Pre-Assigned No." := "No.";
IF "Posting No." <> '' THEN BEGIN
PurchCrMemoHeader."No." := "Posting No.";
IF GUIALLOWED THEN
Window.UPDATE(1,STRSUBSTNO(Text011,"Document Type","No.",PurchCrMemoHeader."No."));
END;
END;
PurchCrMemoHeader."Source Code" := SrcCode;
PurchCrMemoHeader."User ID" := USERID;
PurchCrMemoHeader."No. Printed" := 0;
PurchCrMemoHeader.INSERT(TRUE);
ApprovalMgt.MoveApprvalEntryToPosted(TempApprovalEntry,DATABASE::"Purch. Cr. Memo Hdr.",PurchCrMemoHeader."No.");
IF PurchSetup."Copy Cmts Ret.Ord. to Cr. Memo" THEN BEGIN
CopyCommentLines(
"Document Type",PurchCommentLine."Document Type"::"Posted Credit Memo",
"No.",PurchCrMemoHeader."No.");
PurchCrMemoHeader.COPYLINKS(Rec);
END;
IF SalesTaxCountry <> SalesTaxCountry::NoTax THEN
TaxAmountDifference.CopyTaxDifferenceRecords(
TaxAmountDifference."Document Product Area"::Purchase,"Document Type","No.",
TaxAmountDifference."Document Product Area"::"Posted Purchase",
TaxAmountDifference."Document Type"::"Credit Memo",PurchCrMemoHeader."No.");
GenJnlLineDocType := GenJnlLine."Document Type"::"Credit Memo";
GenJnlLineDocNo := PurchCrMemoHeader."No.";
GenJnlLineExtDocNo := "Vendor Cr. Memo No.";
END;
UpdateIncomingDocument("Incoming Document Entry No.","Posting Date",GenJnlLineDocNo);
// Lines
InvPostingBuffer[1].DELETEALL;
DropShptPostBuffer.DELETEALL;
EverythingInvoiced := TRUE;
PurchLine.RESET;
PurchLine.SETRANGE("Document Type","Document Type");
PurchLine.SETRANGE("Document No.","No.");
LineCount := 0;
RoundingLineInserted := FALSE;
MergePurchLines(PurchHeader,PurchLine,TempPrepmtPurchLine,CombinedPurchLineTemp);
AdjustFinalInvWith100PctPrepmt(CombinedPurchLineTemp);
TaxOption := 0;
IF Invoice THEN BEGIN
PurchLine.SETFILTER("Qty. to Invoice",'<>0');
IF PurchLine.FIND('-') THEN
REPEAT
IF PurchLine."VAT Calculation Type" = PurchLine."VAT Calculation Type"::"Sales Tax" THEN BEGIN
IF PurchLine."Tax Area Code" <> '' THEN BEGIN
IF SalesTaxCountry = SalesTaxCountry::NoTax THEN
ERROR(USText001,
TABLECAPTION,FIELDCAPTION("Tax Area Code"),
PurchLine.TABLECAPTION,PurchLine.FIELDCAPTION("Tax Area Code"));
TaxArea.GET(PurchLine."Tax Area Code");
IF TaxArea.Country <> SalesTaxCountry THEN
ERROR(USText002,
TABLECAPTION,FIELDCAPTION("Tax Area Code"),TaxArea.FIELDCAPTION(Country),SalesTaxCountry,
PurchLine.TABLECAPTION,PurchLine.FIELDCAPTION("Tax Area Code"));
IF TaxArea."Use External Tax Engine" <> UseExternalTaxEngine THEN
ERROR(USText002,
TABLECAPTION,FIELDCAPTION("Tax Area Code"),TaxArea.FIELDCAPTION("Use External Tax Engine"),
UseExternalTaxEngine,PurchLine.TABLECAPTION,PurchLine.FIELDCAPTION("Tax Area Code"));
END;
IF TaxOption = 0 THEN BEGIN
TaxOption := TaxOption::SalesTax;
IF PurchLine."Tax Area Code" <> '' THEN
AddSalesTaxLineToSalesTaxCalc(PurchLine,TRUE);
END ELSE
IF TaxOption = TaxOption::VAT THEN
ERROR(USText000,
PurchLine.TABLECAPTION,PurchLine.FIELDCAPTION("VAT Calculation Type"),TaxOption)
ELSE
IF PurchLine."Tax Area Code" <> '' THEN
AddSalesTaxLineToSalesTaxCalc(PurchLine,FALSE);
END ELSE BEGIN
IF TaxOption = 0 THEN
TaxOption := TaxOption::VAT
ELSE
IF TaxOption = TaxOption::SalesTax THEN
ERROR(USText000,PurchLine.TABLECAPTION,PurchLine.FIELDCAPTION("VAT Calculation Type"),TaxOption);
END;
UNTIL PurchLine.NEXT = 0;
PurchLine.SETRANGE("Qty. to Invoice");
END;
IF TaxOption = TaxOption::SalesTax THEN BEGIN
IF "Tax Area Code" <> '' THEN BEGIN
IF UseExternalTaxEngine THEN
SalesTaxCalculate.CallExternalTaxEngineForPurch(PurchHeader,FALSE)
ELSE
SalesTaxCalculate.EndSalesTaxCalculation("Posting Date");
SalesTaxCalculate.GetSalesTaxAmountLineTable(TempSalesTaxAmtLine);
SalesTaxCalculate.DistTaxOverPurchLines(TempPurchLineForSalesTax);
RemSalesTaxAmt := 0;
RemSalesTaxAmtACY := 0;
CalcProvincialSalesTax;
END;
END ELSE BEGIN
TempVATAmountLineRemainder.DELETEALL;
PurchLine.CalcVATAmountLines(1,PurchHeader,CombinedPurchLineTemp,TempVATAmountLine);
END;
SortLines(PurchLine);
PurchaseLinesProcessed := FALSE;
IF PurchLine.FINDSET THEN
REPEAT
IF PurchLine.Type = PurchLine.Type::Item THEN
DummyTrackingSpecification.CheckItemTrackingQuantity(
DATABASE::"Purchase Line",PurchLine."Document Type",PurchLine."Document No.",PurchLine."Line No.",
PurchLine."Qty. to Receive (Base)",PurchLine."Qty. to Invoice (Base)",Receive,Invoice);
IF PurchLine."Job No." <> '' THEN
PurchLine.TESTFIELD("Job Task No.");
ItemJnlRollRndg := FALSE;
LineCount := LineCount + 1;
IF GUIALLOWED THEN
Window.UPDATE(2,LineCount);
IF PurchLine.Type = PurchLine.Type::"Charge (Item)" THEN BEGIN
PurchLine.TESTFIELD(Amount);
PurchLine.TESTFIELD("Job No.",'');
END;
IF PurchLine.Type = PurchLine.Type::Item THEN
CostBaseAmount := PurchLine."Line Amount";
UpdateQtyPerUnitOfMeasure(PurchLine);
IF PurchLine.Type = PurchLine.Type::"Fixed Asset" THEN BEGIN
PurchLine.TESTFIELD("Job No.",'');
PurchLine.TESTFIELD("Depreciation Book Code");
PurchLine.TESTFIELD("FA Posting Type");
FA.GET(PurchLine."No.");
DeprBook.GET(PurchLine."Depreciation Book Code");
FA.TESTFIELD("Budgeted Asset",FALSE);
IF PurchLine."Budgeted FA No." <> '' THEN BEGIN
FA.GET(PurchLine."Budgeted FA No.");
FA.TESTFIELD("Budgeted Asset",TRUE);
END;
IF PurchLine."FA Posting Type" = PurchLine."FA Posting Type"::Maintenance THEN BEGIN
PurchLine.TESTFIELD("Insurance No.",'');
PurchLine.TESTFIELD("Depr. until FA Posting Date",FALSE);
PurchLine.TESTFIELD("Depr. Acquisition Cost",FALSE);
DeprBook.TESTFIELD("G/L Integration - Maintenance",TRUE);
END;
IF PurchLine."FA Posting Type" = PurchLine."FA Posting Type"::"Acquisition Cost" THEN BEGIN
PurchLine.TESTFIELD("Maintenance Code",'');
DeprBook.TESTFIELD("G/L Integration - Acq. Cost",TRUE);
END;
IF PurchLine."Insurance No." <> '' THEN BEGIN
FASetup.GET;
FASetup.TESTFIELD("Insurance Depr. Book",PurchLine."Depreciation Book Code");
END;
END ELSE BEGIN
PurchLine.TESTFIELD("Depreciation Book Code",'');
PurchLine.TESTFIELD("FA Posting Type",0);
PurchLine.TESTFIELD("Maintenance Code",'');
PurchLine.TESTFIELD("Insurance No.",'');
PurchLine.TESTFIELD("Depr. until FA Posting Date",FALSE);
PurchLine.TESTFIELD("Depr. Acquisition Cost",FALSE);
PurchLine.TESTFIELD("Budgeted FA No.",'');
PurchLine.TESTFIELD("FA Posting Date",0D);
PurchLine.TESTFIELD("Salvage Value",0);
PurchLine.TESTFIELD("Duplicate in Depreciation Book",'');
PurchLine.TESTFIELD("Use Duplication List",FALSE);
END;
CASE "Document Type" OF
"Document Type"::Order:
PurchLine.TESTFIELD("Return Qty. to Ship",0);
"Document Type"::Invoice:
BEGIN
IF PurchLine."Receipt No." = '' THEN
PurchLine.TESTFIELD("Qty. to Receive",PurchLine.Quantity);
PurchLine.TESTFIELD("Return Qty. to Ship",0);
PurchLine.TESTFIELD("Qty. to Invoice",PurchLine.Quantity);
END;
"Document Type"::"Return Order":
PurchLine.TESTFIELD("Qty. to Receive",0);
"Document Type"::"Credit Memo":
BEGIN
IF PurchLine."Return Shipment No." = '' THEN
PurchLine.TESTFIELD("Return Qty. to Ship",PurchLine.Quantity);
PurchLine.TESTFIELD("Qty. to Receive",0);
PurchLine.TESTFIELD("Qty. to Invoice",PurchLine.Quantity);
END;
END;
IF NOT (Receive OR RoundingLineInserted) THEN BEGIN
PurchLine."Qty. to Receive" := 0;
PurchLine."Qty. to Receive (Base)" := 0;
END;
IF NOT (Ship OR RoundingLineInserted) THEN BEGIN
PurchLine."Return Qty. to Ship" := 0;
PurchLine."Return Qty. to Ship (Base)" := 0;
END;
IF ("Document Type" = "Document Type"::Invoice) AND (PurchLine."Receipt No." <> '') THEN BEGIN
PurchLine."Quantity Received" := PurchLine.Quantity;
PurchLine."Qty. Received (Base)" := PurchLine."Quantity (Base)";
PurchLine."Qty. to Receive" := 0;
PurchLine."Qty. to Receive (Base)" := 0;
END;
IF ("Document Type" = "Document Type"::"Credit Memo") AND (PurchLine."Return Shipment No." <> '')
THEN BEGIN
PurchLine."Return Qty. Shipped" := PurchLine.Quantity;
PurchLine."Return Qty. Shipped (Base)" := PurchLine."Quantity (Base)";
PurchLine."Return Qty. to Ship" := 0;
PurchLine."Return Qty. to Ship (Base)" := 0;
END;
IF Invoice THEN BEGIN
IF ABS(PurchLine."Qty. to Invoice") > ABS(PurchLine.MaxQtyToInvoice) THEN
PurchLine.InitQtyToInvoice;
END ELSE BEGIN
PurchLine."Qty. to Invoice" := 0;
PurchLine."Qty. to Invoice (Base)" := 0;
END;
IF PurchLine."Qty. to Invoice" + PurchLine."Quantity Invoiced" <> PurchLine.Quantity THEN
EverythingInvoiced := FALSE;
IF NOT GLSetup."VAT in Use" THEN BEGIN
IF (PurchLine.Type >= PurchLine.Type::"G/L Account") AND
((PurchLine."Qty. to Invoice" <> 0) OR (PurchLine."Qty. to Receive" <> 0))
THEN
IF (PurchLine.Type IN [PurchLine.Type::"G/L Account",PurchLine.Type::"Fixed Asset"]) THEN
IF (((PurchSetup."Discount Posting" = PurchSetup."Discount Posting"::"Invoice Discounts") AND
(PurchLine."Inv. Discount Amount" <> 0)) OR
((PurchSetup."Discount Posting" = PurchSetup."Discount Posting"::"Line Discounts") AND
(PurchLine."Line Discount Amount" <> 0)) OR
((PurchSetup."Discount Posting" = PurchSetup."Discount Posting"::"All Discounts") AND
((PurchLine."Inv. Discount Amount" <> 0) OR (PurchLine."Line Discount Amount" <> 0))))
THEN BEGIN
IF NOT GenPostingSetup.GET(PurchLine."Gen. Bus. Posting Group",PurchLine."Gen. Prod. Posting Group") THEN
IF PurchLine."Gen. Prod. Posting Group" = '' THEN
ERROR(
'You must enter a value in %1 for %2 %3 if you want to post discounts for that line.',
PurchLine.FIELDNAME("Gen. Prod. Posting Group"),PurchLine.FIELDNAME("Line No."),PurchLine."Line No.")
ELSE
GenPostingSetup.GET(PurchLine."Gen. Bus. Posting Group",PurchLine."Gen. Prod. Posting Group");
END ELSE
CLEAR(GenPostingSetup)
ELSE
GenPostingSetup.GET(PurchLine."Gen. Bus. Posting Group",PurchLine."Gen. Prod. Posting Group");
END;
IF PurchLine.Quantity <> 0 THEN BEGIN
PurchLine.TESTFIELD("No.");
PurchLine.TESTFIELD(Type);
IF GLSetup."VAT in Use" THEN BEGIN
PurchLine.TESTFIELD("Gen. Bus. Posting Group");
PurchLine.TESTFIELD("Gen. Prod. Posting Group");
END;
DivideAmount(1,PurchLine."Qty. to Invoice");
END ELSE
PurchLine.TESTFIELD(Amount,0);
IF (PurchLine."Prepayment Line") AND (PurchHeader."Prepmt. Include Tax") THEN BEGIN
PurchLine.Amount := PurchLine.Amount + (PurchLine."VAT Base Amount" * PurchLine."VAT %" / 100);
PurchLine."Amount Including VAT" := PurchLine.Amount;
END;
CheckItemReservDisruption;
RoundAmount(PurchLine."Qty. to Invoice");
IF "Document Type" IN ["Document Type"::"Return Order","Document Type"::"Credit Memo"] THEN BEGIN
ReverseAmount(PurchLine);
ReverseAmount(PurchLineACY);
IF TaxOption = TaxOption::SalesTax THEN
IF TempPurchLineForSalesTax.GET(PurchLine."Document Type",PurchLine."Document No.",PurchLine."Line No.") THEN BEGIN
ReverseAmount(TempPurchLineForSalesTax);
TempPurchLineForSalesTax.MODIFY;
END;
END;
IF PurchLine."IRS 1099 Liable" THEN
IF "Document Type" IN ["Document Type"::"Return Order","Document Type"::"Credit Memo"] THEN
TotalAmount1099 :=
TotalAmount1099 - (TempPurchLine."Amount Including VAT" - TempPrepmtPurchLine."Amount Including VAT")
ELSE
TotalAmount1099 :=
TotalAmount1099 + (TempPurchLine."Amount Including VAT" + TempPrepmtPurchLine."Amount Including VAT");
RemQtyToBeInvoiced := PurchLine."Qty. to Invoice";
RemQtyToBeInvoicedBase := PurchLine."Qty. to Invoice (Base)";
// Job Credit Memo Item Qty Check
IF "Document Type" IN ["Document Type"::"Return Order","Document Type"::"Credit Memo"] THEN
IF (PurchLine."Job No." <> '') AND (PurchLine.Type = PurchLine.Type::Item) AND
(PurchLine."Qty. to Invoice" <> 0)
THEN
JobPostLine.CheckItemQuantityPurchCredit(Rec,PurchLine);
// Item Tracking:
IF NOT PurchLine."Prepayment Line" THEN BEGIN
IF Invoice THEN
IF PurchLine."Qty. to Invoice" = 0 THEN
TrackingSpecificationExists := FALSE
ELSE
TrackingSpecificationExists :=
ReservePurchLine.RetrieveInvoiceSpecification(PurchLine,TempInvoicingSpecification);
EndLoop := FALSE;
IF "Document Type" IN ["Document Type"::"Return Order","Document Type"::"Credit Memo"] THEN BEGIN
IF ABS(RemQtyToBeInvoiced) > ABS(PurchLine."Return Qty. to Ship") THEN BEGIN
ReturnShptLine.RESET;
CASE "Document Type" OF
"Document Type"::"Return Order":
BEGIN
ReturnShptLine.SETCURRENTKEY("Return Order No.","Return Order Line No.");
ReturnShptLine.SETRANGE("Return Order No.",PurchLine."Document No.");
ReturnShptLine.SETRANGE("Return Order Line No.",PurchLine."Line No.");
END;
"Document Type"::"Credit Memo":
BEGIN
ReturnShptLine.SETRANGE("Document No.",PurchLine."Return Shipment No.");
ReturnShptLine.SETRANGE("Line No.",PurchLine."Return Shipment Line No.");
END;
END;
ReturnShptLine.SETFILTER("Return Qty. Shipped Not Invd.",'<>0');
IF ReturnShptLine.FINDSET(TRUE,FALSE) THEN BEGIN
ItemJnlRollRndg := TRUE;
REPEAT
IF TrackingSpecificationExists THEN BEGIN // Item Tracking
ItemEntryRelation.GET(TempInvoicingSpecification."Item Ledger Entry No.");
ReturnShptLine.GET(ItemEntryRelation."Source ID",ItemEntryRelation."Source Ref. No.");
END ELSE
ItemEntryRelation."Item Entry No." := ReturnShptLine."Item Shpt. Entry No.";
ReturnShptLine.TESTFIELD("Buy-from Vendor No.",PurchLine."Buy-from Vendor No.");
ReturnShptLine.TESTFIELD(Type,PurchLine.Type);
ReturnShptLine.TESTFIELD("No.",PurchLine."No.");
ReturnShptLine.TESTFIELD("Gen. Bus. Posting Group",PurchLine."Gen. Bus. Posting Group");
ReturnShptLine.TESTFIELD("Gen. Prod. Posting Group",PurchLine."Gen. Prod. Posting Group");
ReturnShptLine.TESTFIELD("Job No.",PurchLine."Job No.");
ReturnShptLine.TESTFIELD("Unit of Measure Code",PurchLine."Unit of Measure Code");
ReturnShptLine.TESTFIELD("Variant Code",PurchLine."Variant Code");
ReturnShptLine.TESTFIELD("Prod. Order No.",PurchLine."Prod. Order No.");
IF PurchLine."Qty. to Invoice" * ReturnShptLine.Quantity > 0 THEN
PurchLine.FIELDERROR("Qty. to Invoice",Text028);
IF TrackingSpecificationExists THEN BEGIN // Item Tracking
QtyToBeInvoiced := TempInvoicingSpecification."Qty. to Invoice";
QtyToBeInvoicedBase := TempInvoicingSpecification."Qty. to Invoice (Base)";
END ELSE BEGIN
QtyToBeInvoiced := RemQtyToBeInvoiced - PurchLine."Return Qty. to Ship";
QtyToBeInvoicedBase := RemQtyToBeInvoicedBase - PurchLine."Return Qty. to Ship (Base)";
END;
IF ABS(QtyToBeInvoiced) >
ABS(ReturnShptLine.Quantity - ReturnShptLine."Quantity Invoiced")
THEN BEGIN
QtyToBeInvoiced := ReturnShptLine."Quantity Invoiced" - ReturnShptLine.Quantity;
QtyToBeInvoicedBase := ReturnShptLine."Qty. Invoiced (Base)" - ReturnShptLine."Quantity (Base)";
END;
IF TrackingSpecificationExists THEN
ItemTrackingMgt.AdjustQuantityRounding(
RemQtyToBeInvoiced,QtyToBeInvoiced,
RemQtyToBeInvoicedBase,QtyToBeInvoicedBase);
RemQtyToBeInvoiced := RemQtyToBeInvoiced - QtyToBeInvoiced;
RemQtyToBeInvoicedBase := RemQtyToBeInvoicedBase - QtyToBeInvoicedBase;
ReturnShptLine."Quantity Invoiced" :=
ReturnShptLine."Quantity Invoiced" - QtyToBeInvoiced;
ReturnShptLine."Qty. Invoiced (Base)" :=
ReturnShptLine."Qty. Invoiced (Base)" - QtyToBeInvoicedBase;
ReturnShptLine."Return Qty. Shipped Not Invd." :=
ReturnShptLine.Quantity - ReturnShptLine."Quantity Invoiced";
ReturnShptLine.MODIFY;
IF PurchLine.Type = PurchLine.Type::Item THEN
PostItemJnlLine(
PurchLine,
0,0,
QtyToBeInvoiced,QtyToBeInvoicedBase,
ItemEntryRelation."Item Entry No.",'',TempInvoicingSpecification);
IF TrackingSpecificationExists THEN
EndLoop := (TempInvoicingSpecification.NEXT = 0)
ELSE
EndLoop :=
(ReturnShptLine.NEXT = 0) OR (ABS(RemQtyToBeInvoiced) <= ABS(PurchLine."Return Qty. to Ship"));
UNTIL EndLoop;
END ELSE
ERROR(
Text029,
PurchLine."Return Shipment Line No.",PurchLine."Return Shipment No.");
END;
IF ABS(RemQtyToBeInvoiced) > ABS(PurchLine."Return Qty. to Ship") THEN BEGIN
IF "Document Type" = "Document Type"::"Credit Memo" THEN
ERROR(
Text039,
ReturnShptLine."Document No.");
ERROR(Text040);
END;
END ELSE BEGIN
IF ABS(RemQtyToBeInvoiced) > ABS(PurchLine."Qty. to Receive") THEN BEGIN
PurchRcptLine.RESET;
CASE "Document Type" OF
"Document Type"::Order:
BEGIN
PurchRcptLine.SETCURRENTKEY("Order No.","Order Line No.");
PurchRcptLine.SETRANGE("Order No.",PurchLine."Document No.");
PurchRcptLine.SETRANGE("Order Line No.",PurchLine."Line No.");
END;
"Document Type"::Invoice:
BEGIN
PurchRcptLine.SETRANGE("Document No.",PurchLine."Receipt No.");
PurchRcptLine.SETRANGE("Line No.",PurchLine."Receipt Line No.");
END;
END;
PurchRcptLine.SETFILTER("Qty. Rcd. Not Invoiced",'<>0');
IF PurchRcptLine.FINDSET(TRUE,FALSE) THEN BEGIN
ItemJnlRollRndg := TRUE;
REPEAT
IF TrackingSpecificationExists THEN BEGIN
ItemEntryRelation.GET(TempInvoicingSpecification."Item Ledger Entry No.");
PurchRcptLine.GET(ItemEntryRelation."Source ID",ItemEntryRelation."Source Ref. No.");
END ELSE
ItemEntryRelation."Item Entry No." := PurchRcptLine."Item Rcpt. Entry No.";
PurchRcptLine.TESTFIELD("Buy-from Vendor No.",PurchLine."Buy-from Vendor No.");
PurchRcptLine.TESTFIELD(Type,PurchLine.Type);
PurchRcptLine.TESTFIELD("No.",PurchLine."No.");
PurchRcptLine.TESTFIELD("Gen. Bus. Posting Group",PurchLine."Gen. Bus. Posting Group");
PurchRcptLine.TESTFIELD("Gen. Prod. Posting Group",PurchLine."Gen. Prod. Posting Group");
PurchRcptLine.TESTFIELD("Job No.",PurchLine."Job No.");
PurchRcptLine.TESTFIELD("Unit of Measure Code",PurchLine."Unit of Measure Code");
PurchRcptLine.TESTFIELD("Variant Code",PurchLine."Variant Code");
PurchRcptLine.TESTFIELD("Prod. Order No.",PurchLine."Prod. Order No.");
IF PurchLine."Qty. to Invoice" * PurchRcptLine.Quantity < 0 THEN
PurchLine.FIELDERROR("Qty. to Invoice",Text012);
IF TrackingSpecificationExists THEN BEGIN
QtyToBeInvoiced := TempInvoicingSpecification."Qty. to Invoice";
QtyToBeInvoicedBase := TempInvoicingSpecification."Qty. to Invoice (Base)";
END ELSE BEGIN
QtyToBeInvoiced := RemQtyToBeInvoiced - PurchLine."Qty. to Receive";
QtyToBeInvoicedBase := RemQtyToBeInvoicedBase - PurchLine."Qty. to Receive (Base)";
END;
IF ABS(QtyToBeInvoiced) >
ABS(PurchRcptLine.Quantity - PurchRcptLine."Quantity Invoiced")
THEN BEGIN
QtyToBeInvoiced := PurchRcptLine.Quantity - PurchRcptLine."Quantity Invoiced";
QtyToBeInvoicedBase := PurchRcptLine."Quantity (Base)" - PurchRcptLine."Qty. Invoiced (Base)";
END;
IF TrackingSpecificationExists THEN
ItemTrackingMgt.AdjustQuantityRounding(
RemQtyToBeInvoiced,QtyToBeInvoiced,
RemQtyToBeInvoicedBase,QtyToBeInvoicedBase);
RemQtyToBeInvoiced := RemQtyToBeInvoiced - QtyToBeInvoiced;