{
  "apiVersion": 64,
  "label": "QuoteLineItem Net Fees Autocalc",
  "description": "Stamps QuoteLineItem.Net_fees__c on every Create/Update before save, computed directly from the sales-entered inputs:\n  - TiDB Enterprise Subscription: Net_fees__c = Unit_Net_Price__c * Quantity * Term_Months__c (unit price is a monthly rate)\n  - every other family:           Net_fees__c = Unit_Net_Price__c * Quantity              (unit price is the whole-engagement amount)\n\nMirrors the OpportunityLineItem Net Fees contract. Replaces the earlier annualize-passthrough variant, which read $Record.Net_Fees_Total__c - a hand-entered field with no writer that the Create-Quote copy always brought over empty, so the value carried from the source OpportunityLineItem was overwritten with null on 36 of 52 cloned rows (#4838).\n\nNo line-level annualization: the line stores the whole-term total and ACV is derived once at the parent by Quote.ACV_Amount__c. Salesforce has no line-level annualization either.\n\nA TiDB Enterprise Subscription line with no Term_Months__c is deliberately blanked rather than stamped as a single period - a blank value is visible, a silently-wrong one is not. Both incomplete-input paths (missing PricebookEntry/Unit_Net_Price/Quantity, and Subscription-without-Term) assign an empty value rather than falling through, so an update that clears an input clears the derived fee instead of leaving the previous calculation stored. Net_fees__c is not directly updateable, so this flow is its only writer and must own that reset. Resolves the Family via PricebookEntry -> Product2 lookups; formulas reference only $Record.* fields so the eager pass in evaluateFlowFormulas can resolve them without depending on lookup completion.\n\nRuns at triggerOrder 200, after the autofill chain (PricebookEntryId reverse-resolve 20, Currency 25, Product2 50, ListPrice 85).",
  "status": "Active",
  "processType": "AutoLaunchedFlow",
  "runAtomically": true,
  "start": {
    "triggerOrder": 200,
    "locationX": 0,
    "locationY": 0,
    "object": "QuoteLineItem",
    "triggerType": "RecordBeforeSave",
    "recordTriggerType": "CreateAndUpdate",
    "connector": {
      "targetReference": "Has_Required_Inputs"
    }
  },
  "decisions": [
    {
      "name": "Has_Required_Inputs",
      "label": "Has Required Inputs",
      "locationX": 0,
      "locationY": 0,
      "defaultConnectorLabel": "Default - incomplete inputs, clear derived value",
      "rules": [
        {
          "name": "Yes",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "$Record.PricebookEntryId",
              "operator": "IsNull",
              "rightValue": {
                "booleanValue": false
              }
            },
            {
              "leftValueReference": "$Record.Unit_Net_Price__c",
              "operator": "IsNull",
              "rightValue": {
                "booleanValue": false
              }
            },
            {
              "leftValueReference": "$Record.Quantity",
              "operator": "IsNull",
              "rightValue": {
                "booleanValue": false
              }
            }
          ],
          "connector": {
            "targetReference": "Get_PricebookEntry"
          },
          "label": "Yes"
        }
      ],
      "defaultConnector": {
        "targetReference": "Clear_Net_Fees"
      }
    },
    {
      "name": "Family_Is_Subscription",
      "label": "Family Is Subscription",
      "locationX": 0,
      "locationY": 0,
      "defaultConnector": {
        "targetReference": "Stamp_One_Period"
      },
      "defaultConnectorLabel": "Default - one period (UNP * Qty)",
      "rules": [
        {
          "name": "Subscription",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "Get_Product.Family",
              "operator": "EqualTo",
              "rightValue": {
                "stringValue": "TiDB Enterprise Subscription"
              }
            }
          ],
          "connector": {
            "targetReference": "Has_Term"
          },
          "label": "Subscription - needs term"
        }
      ]
    },
    {
      "name": "Has_Term",
      "label": "Has Term",
      "locationX": 0,
      "locationY": 0,
      "defaultConnectorLabel": "Default - incomplete inputs, clear derived value",
      "rules": [
        {
          "name": "Yes",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "$Record.Term_Months__c",
              "operator": "IsNull",
              "rightValue": {
                "booleanValue": false
              }
            }
          ],
          "connector": {
            "targetReference": "Stamp_Subscription"
          },
          "label": "Yes"
        }
      ],
      "defaultConnector": {
        "targetReference": "Clear_Net_Fees"
      }
    }
  ],
  "recordLookups": [
    {
      "name": "Get_PricebookEntry",
      "label": "Get Price Book Entry",
      "locationX": 0,
      "locationY": 0,
      "assignNullValuesIfNoRecordsFound": false,
      "connector": {
        "targetReference": "Get_Product"
      },
      "filterLogic": "and",
      "filters": [
        {
          "field": "Id",
          "operator": "EqualTo",
          "value": {
            "elementReference": "$Record.PricebookEntryId"
          }
        }
      ],
      "getFirstRecordOnly": true,
      "object": "PricebookEntry",
      "storeOutputAutomatically": true
    },
    {
      "name": "Get_Product",
      "label": "Get Product",
      "locationX": 0,
      "locationY": 0,
      "assignNullValuesIfNoRecordsFound": false,
      "connector": {
        "targetReference": "Family_Is_Subscription"
      },
      "filterLogic": "and",
      "filters": [
        {
          "field": "Id",
          "operator": "EqualTo",
          "value": {
            "elementReference": "Get_PricebookEntry.Product2Id"
          }
        }
      ],
      "getFirstRecordOnly": true,
      "object": "Product2",
      "storeOutputAutomatically": true
    }
  ],
  "formulas": [
    {
      "name": "NetFeesOnePeriod",
      "dataType": "Currency",
      "expression": "{!$Record.Unit_Net_Price__c} * {!$Record.Quantity}"
    },
    {
      "name": "NetFeesSubscription",
      "dataType": "Currency",
      "expression": "{!$Record.Unit_Net_Price__c} * {!$Record.Quantity} * {!$Record.Term_Months__c}"
    }
  ],
  "assignments": [
    {
      "name": "Stamp_One_Period",
      "label": "Stamp One-Period Net Fees",
      "locationX": 0,
      "locationY": 0,
      "assignmentItems": [
        {
          "assignToReference": "$Record.Net_fees__c",
          "operator": "Assign",
          "value": {
            "elementReference": "NetFeesOnePeriod"
          }
        }
      ]
    },
    {
      "name": "Stamp_Subscription",
      "label": "Stamp Subscription Net Fees",
      "locationX": 0,
      "locationY": 0,
      "assignmentItems": [
        {
          "assignToReference": "$Record.Net_fees__c",
          "operator": "Assign",
          "value": {
            "elementReference": "NetFeesSubscription"
          }
        }
      ]
    },
    {
      "name": "Clear_Net_Fees",
      "label": "Clear Net Fees (incomplete inputs)",
      "locationX": 0,
      "locationY": 0,
      "assignmentItems": [
        {
          "assignToReference": "$Record.Net_fees__c",
          "operator": "Assign",
          "value": null
        }
      ]
    }
  ]
}
