Skip to content

KVSKBAServicePriceLib#

Procedures#

ShowServicePriceDiscCalcLines(Record Service Line, Enum KVSKBAPriceDiscLineType) :#

Summary: Displays and allows editing of price or discount calculation lines for a service line.

procedure ShowServicePriceDiscCalcLines(var ServiceLine: Record "Service Line"; PriceDiscLineLineType: Enum "KVSKBAPriceDiscLineType"): 

Parameters:

  • ServiceLine: Service Line for which to display calculation lines.
  • PriceDiscLineLineType: Type of calculation to display (Price or Line Discount).

Remarks: This procedure opens an interactive page showing the detailed price or discount calculation breakdown for a service line. Users can view and manually edit the calculation steps that determine the final unit price or line discount percentage.

         Functionality:
         - Opens the KVSKBAServicePriceDiscCalc page in lookup mode
         - Integration event OnBeforeShowServicePriceDiscCalcLines allows bypassing standard behavior
         - If user confirms changes (LookupOK action):
           * Retrieves modified calculation lines from the page
           * Deletes existing calculation lines in the database
           * Suspends automatic price/discount updates on the service line
           * Updates the service line's Unit Price or Line Discount % with the calculated result
           * Sets the origin to Manual for price or Line Discount Origin accordingly
           * Deletes any calculation lines created by the validation (to avoid duplicates)
           * Inserts the user-modified calculation lines from the page

         Special handling:
         - KVSKBASuspendUpdateServicePriceDiscountLine prevents the Validate triggers from recreating
           calculation lines, which would overwrite the manual calculations
         - Integration event OnShowServicePriceDiscCalcLinesOnbeforeCaseLineTypePrice allows customization
           before setting price origin to Manual

         This enables users to understand, verify, and override automatic price calculations with manual
         adjustments while maintaining a documented calculation trail.

ShowServicePriceDiscCalcLinesArchive(Record Service Line Archive, Enum KVSKBAPriceDiscLineType) :#

Summary: Displays price or discount calculation lines from an archived service document.

procedure ShowServicePriceDiscCalcLinesArchive(ServiceLineArchive: Record "Service Line Archive"; PriceDiscLineLineType: Enum "KVSKBAPriceDiscLineType"): 

Parameters:

  • ServiceLineArchive: Archived Service Line for which to display calculation lines.
  • PriceDiscLineLineType: Type of calculation to display (Price or Line Discount).

Remarks: This procedure opens a read-only page showing the historical price or discount calculation breakdown for an archived service line. It allows users to review how prices and discounts were calculated at the time the document was archived.

         The page displays archived calculation lines that were copied during the document archiving process.
         These lines are stored separately in the KVSKBASrvPriceDiscCalcLArchive table to preserve the
         calculation history.

         Unlike ShowServicePriceDiscCalcLines, this is for viewing only - no editing is possible since
         the lines represent historical data from an archived document.

         This is useful for:
         - Auditing historical pricing decisions
         - Understanding why a particular price was used in the past
         - Comparing archived prices with current pricing
         - Troubleshooting price discrepancies

ShowPostServicePriceDiscCalcLines(Record Service Header, Record Service Line, Enum KVSKBAPostedServiceDocType, Code[20], Integer, Enum KVSKBAPriceDiscLineType) :#

Summary: Displays price or discount calculation lines from a posted service document.

procedure ShowPostServicePriceDiscCalcLines(PostedServiceHeader: Record "Service Header"; PostedServiceLine: Record "Service Line"; PostedServiceDocType: Enum "KVSKBAPostedServiceDocType"; DocumentNo: Code[20]; DocumentLineNo: Integer; PriceDiscLineLineType: Enum "KVSKBAPriceDiscLineType"): 

Parameters:

  • PostedServiceHeader: Service Header copied from posted document header.
  • PostedServiceLine: Service Line copied from posted document line.
  • PostedServiceDocType: Type of posted service document (Shipment, Invoice, Credit Memo).
  • DocumentNo: Posted document number.
  • DocumentLineNo: Posted document line number.
  • PriceDiscLineLineType: Type of calculation to display (Price or Line Discount).

Remarks: This procedure opens a read-only page showing the price or discount calculation breakdown for a posted service document line. It retrieves calculation lines from the KVSKBAPostedServPriceDiscLine table which stores the calculation history for posted documents.

         The page displays how the final unit price or line discount percentage was calculated at the time
         of posting, including all graduated pricing steps, special conditions, and discounts that were applied.

         Parameters PostedServiceHeader and PostedServiceLine are temporary records created by copying data
         from the posted document tables to standard Service Header/Line structures for display purposes.

         This is useful for:
         - Reviewing how posted prices were calculated
         - Auditing pricing decisions for completed transactions
         - Resolving customer inquiries about invoiced prices
         - Verifying compliance with pricing agreements
         - Understanding historical pricing for analytics

         The calculation lines are read-only as they represent historical data that cannot be changed
         after posting.

DeleteServicePriceDiscCalcfromServiceLineArchiv(Record Service Line Archive) :#

Summary: Deletes all price and discount calculation lines from an archived service line.

procedure DeleteServicePriceDiscCalcfromServiceLineArchiv(ServiceLineArchive: Record "Service Line Archive"): 

Parameters:

  • ServiceLineArchive: Archived Service Line whose calculation lines should be deleted.

Remarks: This procedure removes all price and discount calculation lines associated with a specific archived service line from the KVSKBASrvPriceDiscCalcLArchive table.

         The procedure filters by:
         - Document Type
         - Document No.
         - Doc. No. Occurrence (for handling multiple archives of the same document number)
         - Version No. (archive version)
         - Document Line No.

         This is typically called when:
         - An archived service line is being deleted
         - An entire archived document version is being removed
         - Cleaning up old archive data

         The deletion removes both price and line discount calculation lines for the specified archived line,
         as they are stored together in the same table differentiated by Line Type field.

DeleteServicePriceDiscCalcfromServiceLine(Record Service Line, Enum KVSKBAPriceDiscLineType, Boolean, Decimal, Boolean) :#

Summary: Deletes price or discount calculation lines from a service line with optional validation.

procedure DeleteServicePriceDiscCalcfromServiceLine(ServiceLine: Record "Service Line"; PriceDiscLineLineType: Enum "KVSKBAPriceDiscLineType"; Unconditional: Boolean; ComparativeValue: Decimal; HideConfirm: Boolean): 

Parameters:

  • ServiceLine: Service Line whose calculation lines should be deleted.
  • PriceDiscLineLineType: Type of calculation lines to delete (Price or Line Discount).
  • Unconditional: If TRUE, deletes without validation; if FALSE, validates before deleting.
  • ComparativeValue: Value to compare against calculated result when validating.
  • HideConfirm: If TRUE, suppresses confirmation dialog; if FALSE, shows confirmation.

Remarks: This procedure removes price or discount calculation lines from a service line, with optional validation to ensure the deletion is intentional when values differ from calculated results.

         Operation modes:

         1. Unconditional deletion (Unconditional = TRUE):
            - Deletes all matching calculation lines immediately
            - No validation or confirmation

         2. Conditional deletion (Unconditional = FALSE):
            - Compares ComparativeValue with the last calculation line's result
            - For Price: Compares with "Result (Doc. Line)" field
            - For Line Discount: Compares with "Discount % (Doc. Line)" field
            - If values differ and HideConfirm = FALSE:
              * Shows detailed message indicating the discrepancy
              * Asks user to confirm deletion with warning
              * Errors if user cancels (ActivityHasBrokenErr)
            - Only deletes if values differ (no action if they match)

         This validation prevents accidental loss of calculation data when the service line's unit price
         or line discount % still matches the calculated result. It alerts users when manual changes
         would lose the documented calculation trail.

         Typical usage scenarios:
         - User manually changes unit price → warns before deleting calculation
         - Automated price update → deletes silently with HideConfirm = TRUE
         - Field validation that changes pricing → conditional deletion with validation

CopyServicePriceDiscCalcLinefromServiceLinetoServiceLine(Record Service Line, Record Service Line) :#

Summary: Copies all price and discount calculation lines from one service line to another.

procedure CopyServicePriceDiscCalcLinefromServiceLinetoServiceLine(FromServiceLine: Record "Service Line"; ToServiceLine: Record "Service Line"): 

Parameters:

  • FromServiceLine: Source Service Line from which to copy calculation lines.
  • ToServiceLine: Target Service Line to which calculation lines will be copied.

Remarks: This procedure duplicates all price and discount calculation lines from a source service line to a target service line. Both price and line discount calculations are copied, maintaining the detailed calculation breakdown.

         The copy process:
         - Retrieves all calculation lines (both price and discount types) from the source line
         - For each calculation line:
           * Creates a new line with the same field values
           * Updates Document Type, Document No., and Document Line No. to match the target line
           * Inserts the new calculation line

         This is typically used when:
         - Copying a service line within the same document (e.g., duplicate line function)
         - Copying lines between service documents
         - Creating a new line based on an existing line's pricing
         - Maintaining calculation history during line modifications

         The procedure preserves the complete calculation trail, ensuring the target line has the same
         documented pricing logic as the source line. All calculation steps, discounts, and pricing
         conditions are maintained.

Events#

OnBeforeShowServicePriceDiscCalcLines(Record Service Line, Enum KVSKBAPriceDiscLineType, Boolean) :#

Summary: Integration event that fires before displaying the price/discount calculation lines page.

[IntegrationEvent(false, false)]
local procedure OnBeforeShowServicePriceDiscCalcLines(var ServiceLine: Record "Service Line"; KVSKBAPriceDiscLineLineType: Enum "KVSKBAPriceDiscLineType"; var IsHandled: Boolean): 
[EventSubscriber(ObjectType::Codeunit, Codeunit::"KVSKBAServicePriceLib", 'OnBeforeShowServicePriceDiscCalcLines', '', false, false)]
local procedure DoSomethingOnBeforeShowServicePriceDiscCalcLines(var ServiceLine: Record "Service Line"; KVSKBAPriceDiscLineLineType: Enum "KVSKBAPriceDiscLineType"; var IsHandled: Boolean)
begin
end;

Parameters:

  • ServiceLine: Service Line for which calculation lines would be displayed.
  • KVSKBAPriceDiscLineLineType: Type of calculation to display (Price or Line Discount).
  • IsHandled: Set to TRUE to bypass standard page display logic.

Remarks: This event fires at the beginning of ShowServicePriceDiscCalcLines, allowing subscribers to intercept the request to display calculation lines and implement custom behavior.

         Subscribers can:
         - Show a custom page or UI instead of the standard calculation page
         - Add validation or security checks before allowing access
         - Log when users view calculation lines
         - Redirect to alternative functionality based on custom logic
         - Prevent display under certain conditions

         If IsHandled is set to TRUE, the standard ShowServicePriceDiscCalcLines logic is completely
         bypassed and the procedure exits immediately. The subscriber takes full responsibility for
         handling the request.

         If IsHandled remains FALSE (default), standard processing continues and the KVSKBAServicePriceDiscCalc
         page is displayed normally.

OnShowServicePriceDiscCalcLinesOnbeforeCaseLineTypePrice(Record Service Line, Enum KVSKBAPriceDiscLineType, Boolean) :#

Summary: Integration event that fires before setting price origin to Manual when price calculation is confirmed.

[IntegrationEvent(false, false)]
local procedure OnShowServicePriceDiscCalcLinesOnbeforeCaseLineTypePrice(var ServiceLine: Record "Service Line"; KVSKBAPriceDiscLineLineType: Enum "KVSKBAPriceDiscLineType"; var IsHandled: Boolean): 
[EventSubscriber(ObjectType::Codeunit, Codeunit::"KVSKBAServicePriceLib", 'OnShowServicePriceDiscCalcLinesOnbeforeCaseLineTypePrice', '', false, false)]
local procedure DoSomethingOnShowServicePriceDiscCalcLinesOnbeforeCaseLineTypePrice(var ServiceLine: Record "Service Line"; KVSKBAPriceDiscLineLineType: Enum "KVSKBAPriceDiscLineType"; var IsHandled: Boolean)
begin
end;

Parameters:

  • ServiceLine: Service Line being updated with calculated price.
  • KVSKBAPriceDiscLineLineType: Type of calculation (Price or Line Discount).
  • IsHandled: Set to TRUE to skip setting KVSKBAPriceOrigin to Manual.

Remarks: This event fires in ShowServicePriceDiscCalcLines after the user confirms changes and the unit price has been validated, but before the price origin is set to Manual. It only fires for Price type calculations (not for Line Discount).

         At this point:
         - User has edited calculation lines in the page and clicked OK
         - Unit Price has been validated with the calculated result
         - Price update suspension is active to prevent calculation line recreation

         Subscribers can:
         - Set IsHandled = TRUE to prevent automatic setting of price origin to Manual
         - Implement custom logic for determining price origin
         - Set a different price origin value based on custom rules
         - Add logging or validation before marking price as manual

         If IsHandled is set to TRUE, the standard logic that sets KVSKBAPriceOrigin to Manual is skipped.
         The subscriber can then set the price origin to any appropriate value based on custom business logic.

         Note: For Line Discount type, the origin is always set to Manual without an event, as this event
         only applies to price calculations.