Untitled

mail@pastecode.io avatar
unknown
javascript
2 years ago
15 kB
4
Indexable
Never
if (typeof (quote) === "undefined") { quote = { __namespace: true }; }
if (typeof (quote.form) === "undefined") { quote.form = { __namespace: true }; }

quote.form.showEmbargoCodeAlert = function (exeContext) {
    

    var currentAttribute = exeContext.getEventSource().controls._values[0].getName();
    if (Globals.Crm.getValue(currentAttribute) == null)
        return;
    var customerId = Globals.Crm.getValue(currentAttribute)[0].id;

    var account = Globals.Utility.getCompanyCountryId(customerId);

    if (account._rms_countryid_value === undefined || account._rms_countryid_value === null)
        return;

    var alertMessage = "";
    if (currentAttribute == "customerid")
        alertMessage = "Country of Client";
    else if (currentAttribute == "rms_localrepresentativeid")
        alertMessage = "Country of Local Representative";
    else if (currentAttribute == "rms_enduserid")
        alertMessage = "Country of End User";

    Globals.Utility.showEmbargoCodeAlert(account._rms_countryid_value, alertMessage);
};

quote.form.showEmbargoCodeNotification = function () {
    

    Globals.Utility.showAccountEmbargoNotification("customerid", "Country of Client");
    Globals.Utility.showAccountEmbargoNotification("rms_localrepresentativeid", "Country of Local Representative");
    Globals.Utility.showAccountEmbargoNotification("rms_enduserid", "Country of End User");
};

quote.form.showHideTabPanels = function () {

    Xrm.Page.ui.tabs.get("tab_6").setVisible(false);//Proposal Content & Details
    Xrm.Page.ui.tabs.get("tab_5").setVisible(false);//Bid Summary Table
	Xrm.Page.ui.tabs.get("tab_winlossanalysis").setVisible(false);//Win & Loss Analysis
    setTimeout(function () {
        $(parent.window.document).find("#rel5").css("display", "none");
    }, 1000);

    if (Globals.Crm.getAttribute("rms_bidnobidvalidatecode").getValue() == 1) {
        Xrm.Page.ui.tabs.get("tab_6").setVisible(true);//Proposal Content & Details
    }

    if (Globals.Crm.getAttribute("rms_acceptedbidtypecode").getValue() == 1) {
        Xrm.Page.ui.tabs.get("tab_5").setVisible(true);//Bid Summary Table
    }
	
	// 1 - Win
	// 2 - Lost
	// 3 - Customer Assesment
	// 4 - Revision
    // 5 - Cancelled
    // 6 - Invalid
	if ([1, 2, 3, 4, 5, 6].includes(Globals.Crm.getAttribute("rms_bidresultcode").getValue())) { 
		Xrm.Page.ui.tabs.get("tab_winlossanalysis").setVisible(true); // Win & Loss Analysis Tab
		
		// SECTION VISIBILTY
		// 1 - Win
		// 2 - Lost
		if([1, 2].includes(Globals.Crm.getAttribute("rms_bidresultcode").getValue())){
			Xrm.Page.ui.tabs.get("tab_winlossanalysis").sections.get("tab_winlossanalysis_section_2").setVisible(true); // SHOW Win & Loss Analysis Section
		}else  {
            Xrm.Page.ui.tabs.get("tab_winlossanalysis").sections.get("tab_winlossanalysis_section_2").setVisible(false); // HIDE Win & Loss Analysis Section
        }
	}
    
    if (Xrm.Page.data.process.getSelectedStage() != null && Xrm.Page.data.process.getSelectedStage().getName().toLowerCase() == "proposal planning") {
        setTimeout(function () {
            
            if (parent.document.getElementById("MscrmControls.Containers.ProcessStageControl-nextButtonContainer") != null) {
                if ((Globals.Crm.getValue("rms_bidnobidvalidatecode") == null || Globals.Crm.getValue("rms_bidnobidvalidatecode") == 2) && parent.document.getElementById("MscrmControls.Containers.ProcessStageControl-nextButtonContainer") != null)
                    parent.document.getElementById("MscrmControls.Containers.ProcessStageControl-nextButtonContainer").style.display = "none";
                else
                    parent.document.getElementById("MscrmControls.Containers.ProcessStageControl-nextButtonContainer").style.display = "block";
            }

            if (parent.document.getElementById("MscrmControls.Containers.ProcessStageControl-previousButtonContainer") != null)
                parent.document.getElementById("MscrmControls.Containers.ProcessStageControl-previousButtonContainer").style.display = "none";
            if (parent.document.getElementById("MscrmControls.Containers.ProcessStageControl-setActiveButtonContainer") != null)
                parent.document.getElementById("MscrmControls.Containers.ProcessStageControl-setActiveButtonContainer").style.display = "none";
            if (parent.document.getElementById("MscrmControls.Containers.ProcessStageControl-previousButtonContainer") != null)
                parent.document.getElementById("MscrmControls.Containers.ProcessStageControl-previousButtonContainer").style.display = "none";

            if (parent.document.getElementById("MscrmControls.Containers.ProcessStageControl-stageDockModeButton1") != null)
                parent.document.getElementById("MscrmControls.Containers.ProcessStageControl-stageDockModeButton1").style.display = "none";
        }, 50);
    }
};

quote.form.saveFormAfterFieldChange = function () {
    Xrm.Page.data.entity.save();
};

quote.form.setLatestQuoteNumberOnLoad = function () {
    
    if (Globals.Crm.GetFormTypeCode() == 1) {
        var requestObject = {};

        requestObject.actionName = "new_TestOpp";
        requestObject.success = function (data) {
            if (data.latestQuoteNumber != null) {
                Globals.Crm.getAttribute("quotenumber").setValue(data.latestQuoteNumber);
                
                Globals.Crm.saveForm();
            }
        };

        Globals.Crm.Rest.ExecuteAction(requestObject);
    }
};

quote.form.hideNextStageButton = function () {
    
    if (Xrm.Page.data.process.getSelectedStage() == null)
        return;
    var runFunction = function () {
        if (Xrm.Page.data.process.getSelectedStage().getId() == Globals.Static.ProposalDevelopingStageId) {
            setTimeout(function () {
                
                if (parent.document.getElementById("MscrmControls.Containers.ProcessStageControl-nextButtonContainer") != null)
                    parent.document.getElementById("MscrmControls.Containers.ProcessStageControl-nextButtonContainer").style.display = "none";
                if (parent.document.getElementById("MscrmControls.Containers.ProcessStageControl-previousButtonContainer") != null)
                    parent.document.getElementById("MscrmControls.Containers.ProcessStageControl-previousButtonContainer").style.display = "none";
                if (parent.document.getElementById("MscrmControls.Containers.ProcessStageControl-setActiveButtonContainer") != null)
                    parent.document.getElementById("MscrmControls.Containers.ProcessStageControl-setActiveButtonContainer").style.display = "none";
                if (parent.document.getElementById("MscrmControls.Containers.ProcessStageControl-previousButtonContainer") != null)
                    parent.document.getElementById("MscrmControls.Containers.ProcessStageControl-previousButtonContainer").style.display = "none";

               if (parent.document.getElementById("MscrmControls.Containers.ProcessStageControl-stageDockModeButton1") != null)
                    parent.document.getElementById("MscrmControls.Containers.ProcessStageControl-stageDockModeButton1").style.display = "none";
            }, 50);
        }
        else if (Xrm.Page.data.process.getSelectedStage().getName().toLowerCase() == "proposal planning") {
            setTimeout(function () {
                
                if ((Globals.Crm.getValue("rms_bidnobidvalidatecode") == null || Globals.Crm.getValue("rms_bidnobidvalidatecode") == 2) && parent.document.getElementById("MscrmControls.Containers.ProcessStageControl-nextButtonContainer") != null)
                    parent.document.getElementById("MscrmControls.Containers.ProcessStageControl-nextButtonContainer").style.display = "none";
                if (parent.document.getElementById("MscrmControls.Containers.ProcessStageControl-previousButtonContainer") != null)
                    parent.document.getElementById("MscrmControls.Containers.ProcessStageControl-previousButtonContainer").style.display = "none";
                if (parent.document.getElementById("MscrmControls.Containers.ProcessStageControl-setActiveButtonContainer") != null)
                    parent.document.getElementById("MscrmControls.Containers.ProcessStageControl-setActiveButtonContainer").style.display = "none";
                if (parent.document.getElementById("MscrmControls.Containers.ProcessStageControl-previousButtonContainer") != null)
                    parent.document.getElementById("MscrmControls.Containers.ProcessStageControl-previousButtonContainer").style.display = "none";

                if (parent.document.getElementById("MscrmControls.Containers.ProcessStageControl-stageDockModeButton1") != null)
                    parent.document.getElementById("MscrmControls.Containers.ProcessStageControl-stageDockModeButton1").style.display = "none";
            }, 50);
        }
        else {
            setTimeout(function () {
                
                if (parent.document.getElementById("MscrmControls.Containers.ProcessStageControl-setActiveButtonContainer") != null)
                    parent.document.getElementById("MscrmControls.Containers.ProcessStageControl-setActiveButtonContainer").style.display = "none";
                if (parent.document.getElementById("MscrmControls.Containers.ProcessStageControl-stageDockModeButton1") != null)
                    parent.document.getElementById("MscrmControls.Containers.ProcessStageControl-stageDockModeButton1").style.display = "none";
                if (parent.document.getElementById("MscrmControls.Containers.ProcessStageControl-previousButtonContainer") != null)
                    parent.document.getElementById("MscrmControls.Containers.ProcessStageControl-previousButtonContainer").style.display = "none";
            }, 50);
        }
    };

    Globals.Crm.addStageSelectEvent(runFunction);
    Xrm.Page.ui.process.setVisible(false);
    setTimeout(function () {
        Xrm.Page.ui.process.setVisible(true);
        runFunction();
    }, 2000);
    
};

quote.form.showHideCreateContractButton = function () {
    var statecode = Xrm.Page.getAttribute("statecode").getValue();
    var isCreateContract = Xrm.Page.getAttribute("rms_iscreatecontract").getValue();

    if (statecode == 2 || statecode == 3)
        return false;
    else if(isCreateContract)
        return true;
    else
        return false;
};

quote.form.showStageWhenStageChange = function () {
    if (Xrm.Page.data.process.getActiveStage() == null)
        return;

    var activeStageName = Xrm.Page.data.process.getActiveStage().getName().toLowerCase();

     if (activeStageName == "proposal planning") {
        if(Xrm.Page.ui.tabs.getByName("Summary") != null)
            Xrm.Page.ui.tabs.getByName("Summary").setFocus(true);
    }
    else if (activeStageName == "proposal developing") {
        if(Xrm.Page.ui.tabs.getByName("tab_6") != null)
            Xrm.Page.ui.tabs.getByName("tab_6").setFocus(true);
    }
};

quote.form.CheckChangedApprovedStatusOnSave = function (context) {
    var saveEvent = context.getEventArgs();

    var isApprovalChanged = Globals.Crm.getAttribute("rms_issubmittomanagersapproval").getIsDirty();
    var approval = Globals.Crm.getValue("rms_issubmittomanagersapproval");

    if (isApprovalChanged && approval) {
        // var requestObject = {};
        // requestObject.entityName = "annotations";
        // requestObject.select = "annotationid";
        // requestObject.filter = "_objectid_value eq " + Globals.Crm.getId().replace("{", "").replace("}", "");

        // var result = Globals.Crm.Rest.RetrieveMultipleJquery(requestObject);
        // if (result.value.length != 0)
        //     return true;
        var documentCount = Globals.Crm.getValue("rms_documentcount");
        if(documentCount > 0)
            return true;

        Globals.Crm.alertDialog("Can Not Send To Manager's Approval Without Proposal Document.", null);
        saveEvent.preventDefault();
    }
    else {
        return true;
    }
};

quote.form.showRevisedButton = function () {
    var bidResultCode = Xrm.Page.getAttribute("rms_bidresultcode").getValue();
    var acceptedBidTypeCode = Xrm.Page.getAttribute("rms_acceptedbidtypecode").getValue();

    if (acceptedBidTypeCode == 1)//Accepted
    {
        if (bidResultCode == 4)//revizyon
            return true;
    }
    else if (acceptedBidTypeCode == 3)//revizyon
    {
        //if (bidResultCode == 4)//revizyon
        return true;
    }

    return false;
};

quote.form.checkDocumentCount = function (executionContext) {
    var formContext = executionContext.getFormContext();
    var documentCount = formContext.getAttribute('rms_documentcount').getValue() ?? 0;
    setInterval(function()  {
        var documentGrid = parent.document.querySelector("[wj-part='cells']")
        if(!!documentGrid){
            var label = documentGrid.getAttribute('aria-label');
            if(label == 'Document Associated Grid'){
                var documentLength = documentGrid.children.length - 1;
                if(documentLength != -1) {
                    if(documentLength > 0 && documentLength > documentCount){
                        console.log('#log - dokuman added')
                        documentCount++;
                        formContext.getAttribute('rms_documentcount').setValue(documentCount);
                        formContext.data.save();
                    }
                    else if(documentLength < documentCount){
                        console.log('#log - dokuman deleted')
                        documentCount--;
                        formContext.getAttribute('rms_documentcount').setValue(documentCount);
                        formContext.data.save();
                    }
                }
            }
        }
    },1500);
}

quote.form.alignDocumentsTab = async function (executionContext) {
    
    
    parent.document.getElementById("rel6").click()
    await new Promise(resolve => setTimeout(resolve, 500));
    parent.document.getElementById("navSPDocuments").click();
    await new Promise(resolve => setTimeout(() => {
        Xrm.Page.ui.tabs.getByName("Summary_tab").setFocus(true);
        var tabList = parent.document.getElementById("tablist");
        var elements = tabList.querySelectorAll("li");
        if(elements.length == 5){
            tabList.appendChild(elements[0]);
            tabList.appendChild(elements[3]);
            tabList.appendChild(elements[1]);
            tabList.appendChild(elements[2]);
            tabList.appendChild(elements[4]);
        }
        else if(elements.length == 6){
            tabList.appendChild(elements[0]);
            tabList.appendChild(elements[4]);
            tabList.appendChild(elements[1]);
            tabList.appendChild(elements[2]);
            tabList.appendChild(elements[3]);
            tabList.appendChild(elements[5]);
        }
    },500))
    document.getElementById("tablist").click()
}