<?xml version="1.0" encoding="UTF-8"?>
<Flow xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>64.0</apiVersion>
    <areMetricsLoggedToDataCloud>false</areMetricsLoggedToDataCloud>
    <assignments>
        <name>Assign_Confirmed_Synch</name>
        <label>Assign Confirmed Synch</label>
        <locationX>0</locationX>
        <locationY>0</locationY>
        <assignmentItems>
            <assignToReference>Loop_New_Confirmed_Synchs.ConfirmedSynchTarget__c</assignToReference>
            <operator>Assign</operator>
            <value>
                <elementReference>$Record.Id</elementReference>
            </value>
        </assignmentItems>
        <assignmentItems>
            <assignToReference>SynchDealtrackerstoUpdate</assignToReference>
            <operator>Add</operator>
            <value>
                <elementReference>Loop_New_Confirmed_Synchs</elementReference>
            </value>
        </assignmentItems>
        <connector>
            <targetReference>Loop_New_Confirmed_Synchs</targetReference>
        </connector>
    </assignments>
    <assignments>
        <name>Assign_Received_Synch</name>
        <label>Assign Received Synch</label>
        <locationX>0</locationX>
        <locationY>0</locationY>
        <assignmentItems>
            <assignToReference>Loop_New_Received_Synchs.PaymentReceivedTarget__c</assignToReference>
            <operator>Assign</operator>
            <value>
                <elementReference>$Record.Id</elementReference>
            </value>
        </assignmentItems>
        <assignmentItems>
            <assignToReference>SynchDealtrackerstoUpdate</assignToReference>
            <operator>Add</operator>
            <value>
                <elementReference>Loop_New_Received_Synchs</elementReference>
            </value>
        </assignmentItems>
        <connector>
            <targetReference>Loop_New_Received_Synchs</targetReference>
        </connector>
    </assignments>
    <assignments>
        <name>Unassign_Old_Confirmed_Target</name>
        <label>Unassign Old Confirmed Target</label>
        <locationX>0</locationX>
        <locationY>0</locationY>
        <assignmentItems>
            <assignToReference>Loop_Old_Confirmed.ConfirmedSynchTarget__c</assignToReference>
            <operator>Assign</operator>
            <value>
                <stringValue></stringValue>
            </value>
        </assignmentItems>
        <assignmentItems>
            <assignToReference>OldClearancesToUpdate</assignToReference>
            <operator>Add</operator>
            <value>
                <elementReference>Loop_Old_Confirmed</elementReference>
            </value>
        </assignmentItems>
        <connector>
            <targetReference>Loop_Old_Confirmed</targetReference>
        </connector>
    </assignments>
    <assignments>
        <name>Unassign_Old_Payment_Target</name>
        <label>Unassign Old Payment Target</label>
        <locationX>0</locationX>
        <locationY>0</locationY>
        <assignmentItems>
            <assignToReference>Loop_Old_Payments.PaymentReceivedTarget__c</assignToReference>
            <operator>Assign</operator>
            <value>
                <stringValue></stringValue>
            </value>
        </assignmentItems>
        <assignmentItems>
            <assignToReference>OldClearancesToUpdate</assignToReference>
            <operator>Add</operator>
            <value>
                <elementReference>Loop_Old_Payments</elementReference>
            </value>
        </assignmentItems>
        <connector>
            <targetReference>Loop_Old_Payments</targetReference>
        </connector>
    </assignments>
    <decisions>
        <name>Check_Operation_Type</name>
        <label>Check Operation Type</label>
        <locationX>0</locationX>
        <locationY>0</locationY>
        <defaultConnector>
            <targetReference>Get_Old_Confirmed</targetReference>
        </defaultConnector>
        <defaultConnectorLabel>Update</defaultConnectorLabel>
        <rules>
            <name>Insert</name>
            <conditionLogic>and</conditionLogic>
            <conditions>
                <leftValueReference>$Record__Prior.Id</leftValueReference>
                <operator>IsNull</operator>
                <rightValue>
                    <booleanValue>true</booleanValue>
                </rightValue>
            </conditions>
            <connector>
                <targetReference>Check_Synch_Target_Category</targetReference>
            </connector>
            <label>Insert</label>
        </rules>
    </decisions>
    <decisions>
        <name>Check_Synch_Target_Category</name>
        <label>Check Synch Target Category</label>
        <locationX>0</locationX>
        <locationY>0</locationY>
        <defaultConnector>
            <targetReference>Get_New_Received_Synchs</targetReference>
        </defaultConnector>
        <defaultConnectorLabel>Received</defaultConnectorLabel>
        <rules>
            <name>Confirmed2</name>
            <conditionLogic>and</conditionLogic>
            <conditions>
                <leftValueReference>$Record.Category__c</leftValueReference>
                <operator>EqualTo</operator>
                <rightValue>
                    <stringValue>Confirmed Synchs</stringValue>
                </rightValue>
            </conditions>
            <connector>
                <targetReference>Get_New_Confirmed_Synchs</targetReference>
            </connector>
            <label>Confirmed</label>
        </rules>
    </decisions>
    <environments>Default</environments>
    <formulas>
        <name>EndDate</name>
        <dataType>Date</dataType>
        <expression>ADDMONTHS({!StartDate}, 3)</expression>
    </formulas>
    <formulas>
        <name>OldEndDate</name>
        <dataType>Date</dataType>
        <expression>IF( ISBLANK({!OldStartDate}), NULL, ADDMONTHS({!OldStartDate}, 3) )</expression>
    </formulas>
    <interviewLabel>Synch Targed- Update {!$Flow.CurrentDateTime}</interviewLabel>
    <label>Synch Dealtracker - Link Targets</label>
    <loops>
        <name>Loop_New_Confirmed_Synchs</name>
        <label>Loop New Confirmed Synchs</label>
        <locationX>0</locationX>
        <locationY>0</locationY>
        <collectionReference>Get_New_Confirmed_Synchs</collectionReference>
        <iterationOrder>Asc</iterationOrder>
        <nextValueConnector>
            <targetReference>Assign_Confirmed_Synch</targetReference>
        </nextValueConnector>
        <noMoreValuesConnector>
            <targetReference>Update_Synch_Dealtrackers</targetReference>
        </noMoreValuesConnector>
    </loops>
    <loops>
        <name>Loop_New_Received_Synchs</name>
        <label>Loop New Received Synchs</label>
        <locationX>0</locationX>
        <locationY>0</locationY>
        <collectionReference>Get_New_Received_Synchs</collectionReference>
        <iterationOrder>Asc</iterationOrder>
        <nextValueConnector>
            <targetReference>Assign_Received_Synch</targetReference>
        </nextValueConnector>
        <noMoreValuesConnector>
            <targetReference>Update_Synch_Dealtrackers</targetReference>
        </noMoreValuesConnector>
    </loops>
    <loops>
        <name>Loop_Old_Confirmed</name>
        <label>Loop Old Confirmed</label>
        <locationX>0</locationX>
        <locationY>0</locationY>
        <collectionReference>Get_Old_Confirmed</collectionReference>
        <iterationOrder>Asc</iterationOrder>
        <nextValueConnector>
            <targetReference>Unassign_Old_Confirmed_Target</targetReference>
        </nextValueConnector>
        <noMoreValuesConnector>
            <targetReference>Get_Old_Payments</targetReference>
        </noMoreValuesConnector>
    </loops>
    <loops>
        <name>Loop_Old_Payments</name>
        <label>Loop Old Payments</label>
        <locationX>0</locationX>
        <locationY>0</locationY>
        <collectionReference>Get_Old_Payments</collectionReference>
        <iterationOrder>Asc</iterationOrder>
        <nextValueConnector>
            <targetReference>Unassign_Old_Payment_Target</targetReference>
        </nextValueConnector>
        <noMoreValuesConnector>
            <targetReference>Update_Old_Clearances</targetReference>
        </noMoreValuesConnector>
    </loops>
    <processMetadataValues>
        <name>BuilderType</name>
        <value>
            <stringValue>LightningFlowBuilder</stringValue>
        </value>
    </processMetadataValues>
    <processMetadataValues>
        <name>CanvasMode</name>
        <value>
            <stringValue>AUTO_LAYOUT_CANVAS</stringValue>
        </value>
    </processMetadataValues>
    <processMetadataValues>
        <name>OriginBuilderType</name>
        <value>
            <stringValue>LightningFlowBuilder</stringValue>
        </value>
    </processMetadataValues>
    <processType>AutoLaunchedFlow</processType>
    <recordLookups>
        <name>Get_New_Confirmed_Synchs</name>
        <label>Get New Confirmed Synchs</label>
        <locationX>0</locationX>
        <locationY>0</locationY>
        <assignNullValuesIfNoRecordsFound>false</assignNullValuesIfNoRecordsFound>
        <connector>
            <targetReference>Loop_New_Confirmed_Synchs</targetReference>
        </connector>
        <filterLogic>and</filterLogic>
        <filters>
            <field>DateOfConfirmation__c</field>
            <operator>GreaterThanOrEqualTo</operator>
            <value>
                <elementReference>StartDate</elementReference>
            </value>
        </filters>
        <filters>
            <field>DateOfConfirmation__c</field>
            <operator>LessThan</operator>
            <value>
                <elementReference>EndDate</elementReference>
            </value>
        </filters>
        <getFirstRecordOnly>false</getFirstRecordOnly>
        <object>SynchClearance__c</object>
        <storeOutputAutomatically>true</storeOutputAutomatically>
    </recordLookups>
    <recordLookups>
        <name>Get_New_Received_Synchs</name>
        <label>Get New Received Synchs</label>
        <locationX>0</locationX>
        <locationY>0</locationY>
        <assignNullValuesIfNoRecordsFound>false</assignNullValuesIfNoRecordsFound>
        <connector>
            <targetReference>Loop_New_Received_Synchs</targetReference>
        </connector>
        <filterLogic>and</filterLogic>
        <filters>
            <field>PaymentReceivedDate__c</field>
            <operator>GreaterThanOrEqualTo</operator>
            <value>
                <elementReference>StartDate</elementReference>
            </value>
        </filters>
        <filters>
            <field>PaymentReceivedDate__c</field>
            <operator>LessThan</operator>
            <value>
                <elementReference>EndDate</elementReference>
            </value>
        </filters>
        <getFirstRecordOnly>false</getFirstRecordOnly>
        <object>SynchClearance__c</object>
        <storeOutputAutomatically>true</storeOutputAutomatically>
    </recordLookups>
    <recordLookups>
        <name>Get_Old_Confirmed</name>
        <label>Get Old Confirmed</label>
        <locationX>0</locationX>
        <locationY>0</locationY>
        <assignNullValuesIfNoRecordsFound>false</assignNullValuesIfNoRecordsFound>
        <connector>
            <targetReference>Loop_Old_Confirmed</targetReference>
        </connector>
        <filterLogic>and</filterLogic>
        <filters>
            <field>ConfirmedSynchTarget__c</field>
            <operator>EqualTo</operator>
            <value>
                <elementReference>$Record.Id</elementReference>
            </value>
        </filters>
        <filters>
            <field>DateOfConfirmation__c</field>
            <operator>GreaterThanOrEqualTo</operator>
            <value>
                <elementReference>OldStartDate</elementReference>
            </value>
        </filters>
        <filters>
            <field>DateOfConfirmation__c</field>
            <operator>LessThan</operator>
            <value>
                <elementReference>OldEndDate</elementReference>
            </value>
        </filters>
        <getFirstRecordOnly>false</getFirstRecordOnly>
        <object>SynchClearance__c</object>
        <storeOutputAutomatically>true</storeOutputAutomatically>
    </recordLookups>
    <recordLookups>
        <name>Get_Old_Payments</name>
        <label>Get Old Payments</label>
        <locationX>0</locationX>
        <locationY>0</locationY>
        <assignNullValuesIfNoRecordsFound>false</assignNullValuesIfNoRecordsFound>
        <connector>
            <targetReference>Loop_Old_Payments</targetReference>
        </connector>
        <filterLogic>and</filterLogic>
        <filters>
            <field>PaymentReceivedTarget__c</field>
            <operator>EqualTo</operator>
            <value>
                <elementReference>$Record.Id</elementReference>
            </value>
        </filters>
        <filters>
            <field>PaymentReceivedDate__c</field>
            <operator>GreaterThanOrEqualTo</operator>
            <value>
                <elementReference>OldStartDate</elementReference>
            </value>
        </filters>
        <filters>
            <field>PaymentReceivedDate__c</field>
            <operator>LessThan</operator>
            <value>
                <elementReference>OldEndDate</elementReference>
            </value>
        </filters>
        <getFirstRecordOnly>false</getFirstRecordOnly>
        <object>SynchClearance__c</object>
        <storeOutputAutomatically>true</storeOutputAutomatically>
    </recordLookups>
    <recordUpdates>
        <name>Update_Old_Clearances</name>
        <label>Update Old Clearances</label>
        <locationX>0</locationX>
        <locationY>0</locationY>
        <connector>
            <targetReference>Check_Synch_Target_Category</targetReference>
        </connector>
        <inputReference>OldClearancesToUpdate</inputReference>
    </recordUpdates>
    <recordUpdates>
        <name>Update_Synch_Dealtrackers</name>
        <label>Update Synch Dealtrackers</label>
        <locationX>0</locationX>
        <locationY>0</locationY>
        <inputReference>SynchDealtrackerstoUpdate</inputReference>
    </recordUpdates>
    <start>
        <locationX>0</locationX>
        <locationY>0</locationY>
        <connector>
            <targetReference>Check_Operation_Type</targetReference>
        </connector>
        <filterFormula>ISNEW()
||
(
    TEXT({!$Record.Category__c}) &lt;&gt; TEXT({!$Record__Prior.Category__c})
    ||
    {!$Record.QuarterStartDate__c} &lt;&gt; {!$Record__Prior.QuarterStartDate__c}
)</filterFormula>
        <object>SynchTarget__c</object>
        <recordTriggerType>CreateAndUpdate</recordTriggerType>
        <triggerType>RecordAfterSave</triggerType>
    </start>
    <status>Active</status>
    <variables>
        <name>currentItem_Filter_Synchs</name>
        <dataType>SObject</dataType>
        <isCollection>false</isCollection>
        <isInput>false</isInput>
        <isOutput>false</isOutput>
        <objectType>SynchClearance__c</objectType>
    </variables>
    <variables>
        <name>OldClearancesToUpdate</name>
        <dataType>SObject</dataType>
        <isCollection>true</isCollection>
        <isInput>false</isInput>
        <isOutput>false</isOutput>
        <objectType>SynchClearance__c</objectType>
    </variables>
    <variables>
        <name>OldStartDate</name>
        <dataType>Date</dataType>
        <isCollection>false</isCollection>
        <isInput>false</isInput>
        <isOutput>false</isOutput>
        <value>
            <elementReference>$Record__Prior.QuarterStartDate__c</elementReference>
        </value>
    </variables>
    <variables>
        <name>StartDate</name>
        <dataType>Date</dataType>
        <isCollection>false</isCollection>
        <isInput>false</isInput>
        <isOutput>false</isOutput>
        <value>
            <elementReference>$Record.QuarterStartDate__c</elementReference>
        </value>
    </variables>
    <variables>
        <name>SynchDealtrackerstoUpdate</name>
        <dataType>SObject</dataType>
        <isCollection>true</isCollection>
        <isInput>false</isInput>
        <isOutput>false</isOutput>
        <objectType>SynchClearance__c</objectType>
    </variables>
</Flow>
