Table 174 Standard Purchase Line
- App
- Base Application
- Namespace
- Microsoft.Purchases.Document
- Versions
- 17-28
Fields, 12Keys, 1Procedures, 7Events, 11
Versions171819202122232425262728
Source29
Source in 29
src/Layers/W1/BaseApp/Purchases/Document/StandardPurchaseLine.Table.al431 lines, Copyright (c) Microsoft Corporation. MIT
// ------------------------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
// ------------------------------------------------------------------------------------------------
namespace Microsoft.Purchases.Document;
using Microsoft.Finance.AllocationAccount;
using Microsoft.Finance.Dimension;
using Microsoft.Finance.GeneralLedger.Account;
using Microsoft.FixedAssets.FixedAsset;
using Microsoft.Foundation.UOM;
using Microsoft.Inventory.Item;
using Microsoft.Projects.Resources.Resource;
using Microsoft.Utilities;
table 174 "Standard Purchase Line"
{
Caption = 'Standard Purchase Line';
DataClassification = CustomerContent;
fields
{
field(1; "Standard Purchase Code"; Code[10])
{
Caption = 'Standard Purchase Code';
Editable = false;
TableRelation = "Standard Purchase Code";
}
field(2; "Line No."; Integer)
{
Caption = 'Line No.';
Editable = false;
}
field(3; Type; Enum "Purchase Line Type")
{
Caption = 'Type';
ToolTip = 'Specifies whether the line is for a general ledger account, item, fixed asset or item charge.';
trigger OnValidate()
var
OldType: Enum "Purchase Line Type";
begin
OldType := Type;
Init();
Type := OldType;
end;
}
field(4; "No."; Code[20])
{
Caption = 'No.';
ToolTip = 'Specifies the number of a general ledger account, item, resource, additional cost, or fixed asset, depending on the contents of the Type field.';
TableRelation = if (Type = const(" ")) "Standard Text"
else
if (Type = const("G/L Account")) "G/L Account"
else
if (Type = const(Item)) Item where(Blocked = const(false))
else
if (Type = const("Fixed Asset")) "Fixed Asset"
else
if (Type = const("Charge (Item)")) "Item Charge"
else
if (Type = const("Allocation Account")) "Allocation Account"
else
if (Type = const(Resource)) Resource;
trigger OnValidate()
var
GLAcc: Record "G/L Account";
Item: Record Item;
ItemCharge: Record "Item Charge";
FA: Record "Fixed Asset";
StdTxt: Record "Standard Text";
StdPurchCode: Record "Standard Purchase Code";
Resource: Record Resource;
begin
Quantity := 0;
"Amount Excl. VAT" := 0;
"Unit of Measure Code" := '';
Description := '';
if "No." = '' then
exit;
StdPurchCode.Get("Standard Purchase Code");
case Type of
Type::" ":
begin
StdTxt.Get("No.");
Description := StdTxt.Description;
end;
Type::"G/L Account":
begin
GLAcc.Get("No.");
GLAcc.CheckGLAcc();
GLAcc.TestField("Direct Posting", true);
Description := GLAcc.Name;
OnAfterValidateGLAccountNo(Rec, GLAcc);
end;
Type::Item:
begin
Item.Get("No.");
Item.TestField(Blocked, false);
Item.TestField("Gen. Prod. Posting Group");
if Item.Type = Item.Type::Inventory then
Item.TestField("Inventory Posting Group");
"Unit of Measure Code" := Item."Purch. Unit of Measure";
Description := Item.Description;
"Variant Code" := '';
OnAfterValidateItemNo(Rec, Item);
end;
Type::Resource:
begin
Resource.Get("No.");
Resource.TestField(Blocked, false);
Resource.TestField("Gen. Prod. Posting Group");
Description := Resource.Name;
"Unit of Measure Code" := Resource."Base Unit of Measure";
OnAfterValidateResourceNo(Rec, Resource);
end;
Type::"Fixed Asset":
begin
FA.Get("No.");
FA.TestField(Inactive, false);
FA.TestField(Blocked, false);
Description := FA.Description;
OnAfterValidateFANo(Rec, FA);
end;
Type::"Charge (Item)":
begin
ItemCharge.Get("No.");
Description := ItemCharge.Description;
OnAfterValidateItemChargeNo(Rec, ItemCharge);
end;
end;
end;
}
field(5; Description; Text[100])
{
Caption = 'Description';
ToolTip = 'Specifies a description of the entry, which is based on the contents of the Type and No. fields.';
}
field(6; Quantity; Decimal)
{
AutoFormatType = 0;
BlankZero = true;
Caption = 'Quantity';
ToolTip = 'Specifies the number of units of the item on the line.';
DecimalPlaces = 0 : 5;
trigger OnValidate()
begin
TestField(Type);
end;
}
field(7; "Amount Excl. VAT"; Decimal)
{
AutoFormatExpression = GetCurrency();
AutoFormatType = 2;
BlankZero = true;
Caption = 'Amount Excl. VAT';
ToolTip = 'Specifies the net amount for the standard purchase line. This field only applies to lines of type G/L Account and Charge (Item).';
trigger OnValidate()
var
IsHandled: Boolean;
begin
IsHandled := false;
OnBeforeValidateAmountExclVAT(Rec, IsHandled);
if IsHandled then
exit;
if (Type <> Type::"G/L Account") and (Type <> Type::"Charge (Item)") then
Error(Text002, FieldCaption(Type), Type);
end;
}
field(8; "Unit of Measure Code"; Code[10])
{
Caption = 'Unit of Measure Code';
ToolTip = 'Specifies how each unit of the item or resource is measured, such as in pieces or hours. By default, the value in the Base Unit of Measure field on the item or resource card is inserted.';
TableRelation = if (Type = const(Item)) "Item Unit of Measure".Code where("Item No." = field("No."))
else
if (Type = const(Resource)) "Resource Unit of Measure".Code where("Resource No." = field("No."))
else
"Unit of Measure";
trigger OnValidate()
var
IsHandled: Boolean;
begin
IsHandled := false;
OnBeforeValidateUnitOfMeasureCode(Rec, IsHandled);
if IsHandled then
exit;
TestField(Type);
end;
}
field(9; "Shortcut Dimension 1 Code"; Code[20])
{
CaptionClass = '1,2,1';
Caption = 'Shortcut Dimension 1 Code';
ToolTip = 'Specifies the code for Shortcut Dimension 1, which is one of two global dimension codes that you set up in the General Ledger Setup window.';
TableRelation = "Dimension Value".Code where("Global Dimension No." = const(1),
Blocked = const(false));
trigger OnValidate()
begin
Rec.ValidateShortcutDimCode(1, "Shortcut Dimension 1 Code");
end;
}
field(10; "Shortcut Dimension 2 Code"; Code[20])
{
CaptionClass = '1,2,2';
Caption = 'Shortcut Dimension 2 Code';
ToolTip = 'Specifies the code for Shortcut Dimension 2, which is one of two global dimension codes that you set up in the General Ledger Setup window.';
TableRelation = "Dimension Value".Code where("Global Dimension No." = const(2),
Blocked = const(false));
trigger OnValidate()
begin
Rec.ValidateShortcutDimCode(2, "Shortcut Dimension 2 Code");
end;
}
field(11; "Variant Code"; Code[10])
{
Caption = 'Variant Code';
ToolTip = 'Specifies the variant of the item on the line.';
TableRelation = if (Type = const(Item)) "Item Variant".Code where("Item No." = field("No."), Blocked = const(false));
trigger OnValidate()
var
Item: Record Item;
ItemVariant: Record "Item Variant";
begin
if Rec."Variant Code" = '' then begin
if Type = Type::Item then begin
Item.Get("No.");
Description := Item.Description;
end;
exit;
end;
TestField(Type, Type::Item);
ItemVariant.SetLoadFields(Description, Blocked);
ItemVariant.Get("No.", "Variant Code");
ItemVariant.TestField(Blocked, false);
Description := ItemVariant.Description;
end;
}
field(480; "Dimension Set ID"; Integer)
{
Caption = 'Dimension Set ID';
Editable = false;
TableRelation = "Dimension Set Entry";
trigger OnLookup()
begin
Rec.ShowDimensions();
end;
trigger OnValidate()
begin
DimMgt.UpdateGlobalDimFromDimSetID("Dimension Set ID", "Shortcut Dimension 1 Code", "Shortcut Dimension 2 Code");
end;
}
}
keys
{
key(Key1; "Standard Purchase Code", "Line No.")
{
Clustered = true;
}
}
fieldgroups
{
}
trigger OnInsert()
begin
LockTable();
StdPurchCode.Get("Standard Purchase Code");
end;
trigger OnRename()
begin
Error(Text000, TableCaption);
end;
var
StdPurchCode: Record "Standard Purchase Code";
DimMgt: Codeunit DimensionManagement;
#pragma warning disable AA0074
#pragma warning disable AA0470
Text000: Label 'You cannot rename a %1.';
Text002: Label '%1 must not be %2.';
#pragma warning restore AA0470
#pragma warning restore AA0074
CommentLbl: Label 'Comment', MaxLength = 30;
procedure EmptyLine(): Boolean
begin
exit(("No." = '') and (Quantity = 0))
end;
procedure InsertLine(): Boolean
begin
exit((Type = Type::" ") or (not EmptyLine()));
end;
local procedure GetCurrency(): Code[10]
var
StdPurchCode: Record "Standard Purchase Code";
begin
if StdPurchCode.Get("Standard Purchase Code") then
exit(StdPurchCode."Currency Code");
exit('');
end;
procedure ShowDimensions()
begin
"Dimension Set ID" :=
DimMgt.EditDimensionSet("Dimension Set ID", StrSubstNo('%1 %2', "Standard Purchase Code", "Line No."));
DimMgt.UpdateGlobalDimFromDimSetID("Dimension Set ID", "Shortcut Dimension 1 Code", "Shortcut Dimension 2 Code");
OnAfterShowDimensions(Rec, DimMgt);
end;
procedure ValidateShortcutDimCode(FieldNumber: Integer; var ShortcutDimCode: Code[20])
begin
OnBeforeValidateShortcutDimCode(Rec, xRec, FieldNumber, ShortcutDimCode);
DimMgt.ValidateShortcutDimValues(FieldNumber, ShortcutDimCode, "Dimension Set ID");
OnAfterValidateShortcutDimCode(Rec, xRec, FieldNumber, ShortcutDimCode);
end;
procedure LookupShortcutDimCode(FieldNumber: Integer; var ShortcutDimCode: Code[20])
var
IsHandled: Boolean;
begin
IsHandled := false;
OnBeforeLookupShortcutDimCode(Rec, xRec, FieldNumber, ShortcutDimCode, IsHandled);
if IsHandled then
exit;
DimMgt.LookupDimValueCode(FieldNumber, ShortcutDimCode);
DimMgt.ValidateShortcutDimValues(FieldNumber, ShortcutDimCode, "Dimension Set ID");
end;
procedure ShowShortcutDimCode(var ShortcutDimCode: array[8] of Code[20])
begin
DimMgt.GetShortcutDimensions(Rec."Dimension Set ID", ShortcutDimCode);
end;
#if not CLEAN29
[Obsolete('Use FormatTypeAsText() instead.', '29.0')]
procedure FormatType(): Text[20]
begin
exit(CopyStr(FormatTypeAsText(), 1, 20));
end;
#endif
/// <summary>
/// Formats the line type for display, returning 'Comment' for blank types.
/// </summary>
/// <returns>The formatted type text.</returns>
procedure FormatTypeAsText(): Text[30]
begin
if Type = Type::" " then
exit(CommentLbl);
exit(Format(Type));
end;
[IntegrationEvent(false, false)]
local procedure OnBeforeLookupShortcutDimCode(var StandardPurchaseLine: Record "Standard Purchase Line"; var xStandardPurchaseLine: Record "Standard Purchase Line"; FieldNumber: Integer; var ShortcutDimCode: Code[20]; var IsHandled: Boolean)
begin
end;
[IntegrationEvent(false, false)]
local procedure OnAfterShowDimensions(var StandardPurchaseLine: Record "Standard Purchase Line"; var DimMgt: Codeunit DimensionManagement)
begin
end;
[IntegrationEvent(false, false)]
local procedure OnAfterValidateGLAccountNo(var StandardPurchaseLine: Record "Standard Purchase Line"; GLAccount: Record "G/L Account")
begin
end;
[IntegrationEvent(false, false)]
local procedure OnAfterValidateItemNo(var StandardPurchaseLine: Record "Standard Purchase Line"; Item: Record "Item")
begin
end;
[IntegrationEvent(false, false)]
local procedure OnAfterValidateResourceNo(var StandardPurchaseLine: Record "Standard Purchase Line"; Resource: Record "Resource")
begin
end;
[IntegrationEvent(false, false)]
local procedure OnAfterValidateFANo(var StandardPurchaseLine: Record "Standard Purchase Line"; FixedAsset: Record "Fixed Asset")
begin
end;
[IntegrationEvent(false, false)]
local procedure OnAfterValidateItemChargeNo(var StandardPurchaseLine: Record "Standard Purchase Line"; ItemCharge: Record "Item Charge")
begin
end;
[IntegrationEvent(false, false)]
local procedure OnAfterValidateShortcutDimCode(var StandardPurchaseLine: Record "Standard Purchase Line"; xStandardPurchaseLine: Record "Standard Purchase Line"; FieldNumber: Integer; var ShortcutDimCode: Code[20])
begin
end;
[IntegrationEvent(false, false)]
local procedure OnBeforeValidateShortcutDimCode(var StandardPurchaseLine: Record "Standard Purchase Line"; xStandardPurchaseLine: Record "Standard Purchase Line"; FieldNumber: Integer; var ShortcutDimCode: Code[20])
begin
end;
[IntegrationEvent(false, false)]
local procedure OnBeforeValidateAmountExclVAT(var StandardPurchaseLine: Record "Standard Purchase Line"; var IsHandled: Boolean)
begin
end;
[IntegrationEvent(false, false)]
local procedure OnBeforeValidateUnitOfMeasureCode(var StandardPurchaseLine: Record "Standard Purchase Line"; var IsHandled: Boolean)
begin
end;
}