{
  "apiVersion": 64,
  "label": "OpportunityLineItem Expansion Auto-Stamp",
  "description": "For Opportunities with RecordType=Expansion and OriginalOrder__c populated, auto-stamp Term_Mounths__c (prorated months between Service Start/End dates) on the OpportunityLineItem before save. Ports OpportunityProductBeforeTriggerHandler.UpdateOppProductTermMonth from SFDC Apex.\n\nThe Net_Fees_Total__c write was removed in the #4838 cleanup: that field is no longer read by anything (Net_fees__c is derived from Unit_Net_Price__c / Quantity / Term, and the Quote header rollups sum Net_fees__c), so stamping it only produced a value nothing consumed. Its RawTotal formula went with it - evaluateFlowFormulas evaluates every declared formula eagerly, so a dead formula costs a computation on every save.",
  "status": "Active",
  "processType": "AutoLaunchedFlow",
  "runAtomically": true,
  "start": {
    "triggerOrder": 100,
    "locationX": 0,
    "locationY": 0,
    "object": "OpportunityLineItem",
    "triggerType": "RecordBeforeSave",
    "recordTriggerType": "CreateAndUpdate",
    "connector": {
      "targetReference": "Get_Parent_Opportunity"
    }
  },
  "recordLookups": [
    {
      "name": "Get_Parent_Opportunity",
      "label": "Get Parent Opportunity",
      "locationX": 0,
      "locationY": 0,
      "assignNullValuesIfNoRecordsFound": false,
      "connector": {
        "targetReference": "Get_Parent_Opportunity_RecordType"
      },
      "filterLogic": "and",
      "filters": [
        {
          "field": "Id",
          "operator": "EqualTo",
          "value": {
            "elementReference": "$Record.OpportunityId"
          }
        }
      ],
      "getFirstRecordOnly": true,
      "object": "Opportunity",
      "storeOutputAutomatically": true
    },
    {
      "name": "Get_Parent_Opportunity_RecordType",
      "label": "Get Parent Opportunity RecordType",
      "locationX": 0,
      "locationY": 120,
      "assignNullValuesIfNoRecordsFound": false,
      "connector": {
        "targetReference": "Is_Expansion_With_OriginalOrder"
      },
      "filterLogic": "and",
      "filters": [
        {
          "field": "Id",
          "operator": "EqualTo",
          "value": {
            "elementReference": "Get_Parent_Opportunity.RecordTypeId"
          }
        }
      ],
      "getFirstRecordOnly": true,
      "object": "_System_RecordType",
      "storeOutputAutomatically": true
    }
  ],
  "decisions": [
    {
      "name": "Is_Expansion_With_OriginalOrder",
      "label": "Is Expansion With OriginalOrder",
      "locationX": 0,
      "locationY": 0,
      "defaultConnectorLabel": "Default Outcome",
      "rules": [
        {
          "name": "Yes",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "Get_Parent_Opportunity_RecordType.Name",
              "operator": "EqualTo",
              "rightValue": {
                "stringValue": "Expansion"
              }
            },
            {
              "leftValueReference": "Get_Parent_Opportunity.OriginalOrder__c",
              "operator": "IsNull",
              "rightValue": {
                "booleanValue": false
              }
            },
            {
              "leftValueReference": "$Record.Service_Start_Date__c",
              "operator": "IsNull",
              "rightValue": {
                "booleanValue": false
              }
            },
            {
              "leftValueReference": "$Record.Service_End_Date__c",
              "operator": "IsNull",
              "rightValue": {
                "booleanValue": false
              }
            }
          ],
          "connector": {
            "targetReference": "Stamp_Term"
          },
          "label": "Yes"
        }
      ]
    }
  ],
  "formulas": [
    {
      "name": "DaysInStartMonth",
      "dataType": "Number",
      "expression": "CASE(MONTH({!$Record.Service_Start_Date__c}), 1, 31, 2, IF(AND(MOD(YEAR({!$Record.Service_Start_Date__c}), 4) = 0, OR(MOD(YEAR({!$Record.Service_Start_Date__c}), 100) <> 0, MOD(YEAR({!$Record.Service_Start_Date__c}), 400) = 0)), 29, 28), 3, 31, 4, 30, 5, 31, 6, 30, 7, 31, 8, 31, 9, 30, 10, 31, 11, 30, 12, 31, 0)"
    },
    {
      "name": "DaysInEndMonth",
      "dataType": "Number",
      "expression": "CASE(MONTH({!$Record.Service_End_Date__c}), 1, 31, 2, IF(AND(MOD(YEAR({!$Record.Service_End_Date__c}), 4) = 0, OR(MOD(YEAR({!$Record.Service_End_Date__c}), 100) <> 0, MOD(YEAR({!$Record.Service_End_Date__c}), 400) = 0)), 29, 28), 3, 31, 4, 30, 5, 31, 6, 30, 7, 31, 8, 31, 9, 30, 10, 31, 11, 30, 12, 31, 0)"
    },
    {
      "name": "MonthsBetween",
      "dataType": "Number",
      "scale": 2,
      "expression": "((YEAR({!$Record.Service_End_Date__c}) - YEAR({!$Record.Service_Start_Date__c})) * 12 + (MONTH({!$Record.Service_End_Date__c}) - MONTH({!$Record.Service_Start_Date__c})) - 1) + ({!DaysInStartMonth} - DAY({!$Record.Service_Start_Date__c})) / {!DaysInStartMonth} + DAY({!$Record.Service_End_Date__c}) / {!DaysInEndMonth}"
    }
  ],
  "assignments": [
    {
      "name": "Stamp_Term",
      "label": "Stamp Term",
      "locationX": 0,
      "locationY": 0,
      "assignmentItems": [
        {
          "assignToReference": "$Record.Term_Mounths__c",
          "operator": "Assign",
          "value": {
            "elementReference": "MonthsBetween"
          }
        }
      ]
    }
  ]
}
