Skip to content

Instantly share code, notes, and snippets.

@chriscooning
Created June 27, 2018 22:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chriscooning/2c7f3c7d426410dae8a71af796a1b25f to your computer and use it in GitHub Desktop.
Save chriscooning/2c7f3c7d426410dae8a71af796a1b25f to your computer and use it in GitHub Desktop.
//Name: BurnRateProjectSummary.js
//Date: 7/7/2015
//Company: Paxton Tait
//Description: new burn rate section which pulls from latest project commitment and allows spreadsheet burn rate calculations for user
function Form_OnSave() {
}
function Form_OnLoad() {
var chkFieldvalue = Xrm.Page.data.entity.attributes.get('mck_latestprojectitem');
//alertOnLoad();
//collapseOpporBusinessProcess();
// setTimeout(collapseOpporBusinessProcessDelay, 1000);
// if latest project commitment field is filled then execute burn rate project summary tab
if (chkFieldvalue.getValue() != null) {
//ForcedSubmitDisableFields();
//getRecordDetails_XMLHttpRequest();
//CHKgetRecordDetails();
// Projecton_Budget_Schedule();
HideShowtab("tab_14", true);
} else {
HideShowtab("tab_14", false);
}
}
//function collapseOpporBusinessProcess(){setTimeout(collapseOpporBusinessProcessDelay,800)}
//function collapseOpporBusinessProcessDelay() {
// //Xrm.Page.ui.process != null &&
// //Xrm.Page.ui.process.setDisplayState("collapsed");
// //Xrm.Page.ui.process.setVisible(false);
//}
function BurnRateProjectSummary_TabStateChange() {
var chkFieldvalue = Xrm.Page.data.entity.attributes.get('mck_latestprojectitem');
if (chkFieldvalue.getValue() != null) {
ForcedSubmitDisableFields();
CHKgetRecordDetails();
}
}
function ProjectOverview_TabStateChange() {
var chkFieldvalue = Xrm.Page.data.entity.attributes.get('mck_latestprojectitem');
if (chkFieldvalue.getValue() != null) {
Projecton_Budget_Schedule();
}
}
function HideShowtab(tabName, visible) {
try {
Xrm.Page.ui.tabs.get(tabName).setVisible(visible);
}
catch (err) { }
}
function CHKgetRecordDetails() {
//only run when tab 14 is expanded
var tabState = Xrm.Page.ui.tabs.get("tab_14").getDisplayState();
//alert(tabState);
if (tabState == "expanded") {
var CHKdetail = Xrm.Page.getAttribute('pt_commitmentstate').getValue();
var a = WF.Xrm.Shared.getFieldValue("pt_quotedmaterialcostshidden", 0);
var b = WF.Xrm.Shared.getFieldValue("pt_quotedlaborcostshidden", 0);
var c = WF.Xrm.Shared.getFieldValue("pt_quotedsubcontractorcostshidden", 0);
var d = WF.Xrm.Shared.getFieldValue("pt_quotedtravelcostshidden", 0);
var e = WF.Xrm.Shared.getFieldValue("pt_quotedinboundfreightcostshidden", 0);
var f = WF.Xrm.Shared.getFieldValue("pt_quotedoverheadcostshidden", 0);
var g = WF.Xrm.Shared.getFieldValue("pt_quotedtotalprojectcosthidden", 0);
var h = WF.Xrm.Shared.getFieldValue("pt_quotedgrossprofithidden", 0);
var i = WF.Xrm.Shared.getFieldValue("pt_quotedlastentrydatehidden", 0);
var j = WF.Xrm.Shared.getFieldValue("pt_quotedpromiseshipdatehidden", 0);
var k = WF.Xrm.Shared.getFieldValue("mck_contractprice", 0);
//alert(CHKdetail+ " and freight costs "+ e);
//if latest project commitment is committed or revision type
if (CHKdetail != 803990002) {
WF.Xrm.Shared.setFieldValue("pt_quotedmaterialcosts", a);
WF.Xrm.Shared.setFieldValue("pt_quotedlaborcosts", b);
WF.Xrm.Shared.setFieldValue("pt_quotedsubcontractorcosts", c);
WF.Xrm.Shared.setFieldValue("pt_quotedtravelcosts", d);
WF.Xrm.Shared.setFieldValue("pt_quotedinboundfreightcosts", e);
WF.Xrm.Shared.setFieldValue("pt_quotedoverhead", f);
WF.Xrm.Shared.setFieldValue("pt_quotedtotalprojectcosts", g);
WF.Xrm.Shared.setFieldValue("pt_quotedgrossprofit", h);
WF.Xrm.Shared.setFieldValue("pt_quotedlastentrydate", i);
WF.Xrm.Shared.setFieldValue("pt_quotedpromiseshipdate", j);
WF.Xrm.Shared.setFieldValue("pt_quotedcontractpricehidden", k);// set to save most recent revision/committed contract proice (PO Amount)
if (CHKdetail == 803990000) WF.Xrm.Shared.setSectionLabel("tab_14", "tab_14_section_6", "Quoted Committed (Latest Project Commitment)");
else if (CHKdetail == 803990001) WF.Xrm.Shared.setSectionLabel("tab_14", "tab_14_section_6", "Quoted Revision (Latest Project Commitment)");
//clear field if latest project commitment moves out of actual
WF.Xrm.Shared.setFieldValue("pt_actualpromiseshipdate", "");
remainingbalance_calc();
surplusdeficit_calc();
} else { //if actual type
//WF.Xrm.Shared.setTabDisabled("tab_14", true);
WF.Xrm.Shared.setFieldValue("pt_costtodatematerial", a);
WF.Xrm.Shared.setFieldValue("pt_costtodatelabor", b);
WF.Xrm.Shared.setFieldValue("pt_costtodatesubcontractor", c);
WF.Xrm.Shared.setFieldValue("pt_costtodatetravel", d);
WF.Xrm.Shared.setFieldValue("pt_costtodateinboundfreight", e);
WF.Xrm.Shared.setFieldValue("pt_costtodateoverhead", f);
WF.Xrm.Shared.setFieldValue("pt_costtodatetotalprojectcosts", g);
WF.Xrm.Shared.setFieldValue("pt_costtodatelastentrydate", i);
//Promise Ship Date field only updated if lastest project commitment is actual only
WF.Xrm.Shared.setFieldValue("pt_actualpromiseshipdate", j);
// Xrm.Page.getControl('pt_costtodatematerial').setLabel('Actual Cost to Date'); //moved functionality to web resource "pt_project_BurnRateProjectSummary_header_ActualCosttoDate.html"
WF.Xrm.Shared.setSectionLabel("tab_14", "tab_14_section_6", "Quoted (Latest Project Commitment)");
Xrm.Page.ui.controls.get("pt_costtodatematerial").setDisabled(true);
Xrm.Page.ui.controls.get("pt_costtodatelabor").setDisabled(true);
Xrm.Page.ui.controls.get("pt_costtodatesubcontractor").setDisabled(true);
Xrm.Page.ui.controls.get("pt_costtodatetravel").setDisabled(true);
Xrm.Page.ui.controls.get("pt_costtodateinboundfreight").setDisabled(true);
Xrm.Page.ui.controls.get("pt_costtodateoverhead").setDisabled(true);
Xrm.Page.ui.setFormNotification('Information: Latest Project Commitment is set as an Actual Project Commitment. Only Expected Future Costs section is editable in Burn Rate Project Summary tab.', 'INFORMATION', '4');
//60 sec delay notification removal
setTimeout(function () { Xrm.Page.ui.clearFormNotification('4'); }, 60000);
remainingbalance_calc();
surplusdeficit_calc();
Xrm.Page.data.save();
}
}
}
function Project_summary_rounded() {
var chkFieldvalue = WF.Xrm.Shared.getFieldValue("mck_latestprojectitem", 0);
var chkFieldvalue2 = WF.Xrm.Shared.getFieldValue("pt_projectduration");
if (chkFieldvalue2 != null) {
var d = WF.Xrm.Shared.getFieldValue("pt_projectduration");
//alert(d + ' calc: '+ (Math.round((d/1440)))*1440);
WF.Xrm.Shared.setFieldValue("pt_projectduration", (Math.round((d / 1440))) * 1440);
}
if (chkFieldvalue != null) {
var a = WF.Xrm.Shared.getFieldValue("mck_contractprice", 0);
var b = WF.Xrm.Shared.getFieldValue("pt_quotedtotalprojectcosthidden", 0);
var c = WF.Xrm.Shared.getFieldValue("pt_quotedgrossprofithidden", 0);
WF.Xrm.Shared.setFieldValue("pt_contractpricerounded", a);
WF.Xrm.Shared.setFieldValue("pt_quotedtotalprojectcostsrounded", b);
WF.Xrm.Shared.setFieldValue("pt_quotedgrossprofitrounded", c);
}
}
function Projecton_Budget_Schedule() {
var a = Xrm.Page.data.entity.attributes.get('pt_surplusdeficitdollarstotalprojectcosts').getValue();
//alert(a);
if (a >= 0) {
Xrm.Page.getAttribute('pt_projectonbudget').setValue(true);
} else {
Xrm.Page.getAttribute('pt_projectonbudget').setValue(false);
//send user a notification record is saved
//Xrm.Page.ui.setFormNotification('Warning! Project Burn Rate is not On Target. See Burn Rate Project Summary Section: Surplus Deficit Total Project Costs field.', 'WARNING', '2');
////60 sec delay notification removal
//setTimeout(function () { Xrm.Page.ui.clearFormNotification('2'); }, 60000);
}
//var Date1 = Xrm.Page.getAttribute('pt_quotedpromiseshipdate').getValue();
//var Date2 = Xrm.Page.getAttribute('pt_originalpromiseshipdate').getValue();
//////set original promise ship date once
////// alert(OriginalPromiseShipDate + '<original...prom var:' + promiseshipdate);
////if (Date2 == null) {
//// //set value in current project record
//// Xrm.Page.data.entity.attributes.get('pt_originalpromiseshipdate').setValue(Date1);
//// //WF.Xrm.Shared.setFieldValue("pt_originalpromiseshipdate", Date1);
////}
//if (Date1 != null && Date2 != null) {
// if (Date1.setHours(0, 0, 0, 0) <= Date2.setHours(0, 0, 0, 0)) {
// Xrm.Page.getAttribute('pt_projectonschedule').setValue(true);
// Xrm.Page.getAttribute('pt_communicatedtocustomer').setValue(true);//default user modifable boolean field
// } else {
// Xrm.Page.getAttribute('pt_projectonschedule').setValue(false);
// Xrm.Page.getAttribute('pt_communicatedtocustomer').setValue(false);//default user modifable boolean field
// //send user a notification record is saved
// //Xrm.Page.ui.setFormNotification('Warning! Project Promise Ship Date is not On Schedule. Latest Project Commitment Promise Ship Date is ' + Date1 + ' and the Original Project Promise Ship Date is ' + Date2, 'WARNING', '3');
// ////70 sec delay notification removal
// //setTimeout(function () { Xrm.Page.ui.clearFormNotification('3'); }, 70000);
// }
//}
//do surplus deficit promise ship date duration and update project summary booleans
//var endate = Xrm.Page.getAttribute('pt_quotedpromiseshipdate').getValue();
//var stdate = Xrm.Page.getAttribute('pt_expectedfuturepromiseshipdate').getValue();
var endate = Xrm.Page.getAttribute('pt_quotedpromiseshipdate').getValue();
var stdate = Xrm.Page.getAttribute('pt_expectedfuturepromiseshipdate').getValue();
var p = "";
if (stdate != null && endate != null) {
var st = stdate.getTime();
var ed = endate.getTime();
var sdiff = (ed - st);
var h = (sdiff / 60 / 1000);
p = parseInt(h);
}
if (p >= 0 || p == null) {
Xrm.Page.getAttribute('pt_projectonschedule').setValue(true);
} else if (p < 0) {
Xrm.Page.getAttribute('pt_projectonschedule').setValue(false);
}
}
//user modifable optionset field to but upon field change update to "NO"
function pt_expectedfuturepromiseshipdate_onChange(){
Xrm.Page.data.entity.attributes.get('pt_communicatedtocustomer').setValue(false);
}
//save read only fields
function ForcedSubmitDisableFields() {
//dates
Xrm.Page.data.entity.attributes.get("pt_costtodatelastentrydate").setSubmitMode("always");
Xrm.Page.data.entity.attributes.get("pt_expectedfuturelastentrydate").setSubmitMode("always");
Xrm.Page.data.entity.attributes.get("pt_quotedlastentrydate").setSubmitMode("always");
Xrm.Page.data.entity.attributes.get("pt_quotedpromiseshipdate").setSubmitMode("always");
Xrm.Page.data.entity.attributes.get("pt_expectedfuturepromiseshipdate").setSubmitMode("always");
Xrm.Page.data.entity.attributes.get("pt_actualpromiseshipdate").setSubmitMode("always");
//cost to date
Xrm.Page.data.entity.attributes.get("pt_costtodatetotalprojectcosts").setSubmitMode("always");
Xrm.Page.data.entity.attributes.get("pt_costtodateoverhead").setSubmitMode("always");
//balance remaining
Xrm.Page.data.entity.attributes.get("pt_balanceremainingsubcontractorcosts").setSubmitMode("always");
Xrm.Page.data.entity.attributes.get("pt_balanceremainingmaterialcosts").setSubmitMode("always");
Xrm.Page.data.entity.attributes.get("pt_balanceremaininglaborcosts").setSubmitMode("always");
Xrm.Page.data.entity.attributes.get("pt_balanceremainingtravelcosts").setSubmitMode("always");
Xrm.Page.data.entity.attributes.get("pt_balanceremaininginboundfreightcosts").setSubmitMode("always");
Xrm.Page.data.entity.attributes.get("pt_balanceremainingoverhead").setSubmitMode("always");
Xrm.Page.data.entity.attributes.get("pt_balanceremainingtotalprojectcosts").setSubmitMode("always");
//expected future costs
Xrm.Page.data.entity.attributes.get("pt_expectedfutureoverhead").setSubmitMode("always");
Xrm.Page.data.entity.attributes.get("pt_expectedfuturetotalprojectcosts").setSubmitMode("always");
Xrm.Page.data.entity.attributes.get("pt_surplusdeficitpromiseshipdatedifference").setSubmitMode("always");
//surplus deficit
Xrm.Page.data.entity.attributes.get("pt_surplusdeficitdollarssubcontractorcosts").setSubmitMode("always");
Xrm.Page.data.entity.attributes.get("pt_surplusdeficitdollarsmaterialcosts").setSubmitMode("always");
Xrm.Page.data.entity.attributes.get("pt_surplusdeficitdollarslaborcosts").setSubmitMode("always");
Xrm.Page.data.entity.attributes.get("pt_surplusdeficitdollarstravelcosts").setSubmitMode("always");
Xrm.Page.data.entity.attributes.get("pt_surplusdeficitdollarsinboundfreightcosts").setSubmitMode("always");
Xrm.Page.data.entity.attributes.get("pt_surplusdeficitdollarsoverhead").setSubmitMode("always");
Xrm.Page.data.entity.attributes.get("pt_surplusdeficitdollarstotalprojectcosts").setSubmitMode("always");
Xrm.Page.data.entity.attributes.get("pt_surplusdeficitpercentsubcontractorcosts").setSubmitMode("always");
Xrm.Page.data.entity.attributes.get("pt_surplusdeficitpercentmaterialcosts").setSubmitMode("always");
Xrm.Page.data.entity.attributes.get("pt_surplusdeficitpercentlaborcosts").setSubmitMode("always");
Xrm.Page.data.entity.attributes.get("pt_surplusdeficitpercenttravelcosts").setSubmitMode("always");
Xrm.Page.data.entity.attributes.get("pt_surplusdeficitpercentinboundfreightcosts").setSubmitMode("always");
Xrm.Page.data.entity.attributes.get("pt_surplusdeficitpercentoverhead").setSubmitMode("always");
Xrm.Page.data.entity.attributes.get("pt_surplusdeficitpercenttotalprojectcosts").setSubmitMode("always");
Xrm.Page.data.entity.attributes.get("pt_surplusdeficitdollarstotalprojectcosts").setSubmitMode("always");
//project PO Amount (contract price) for project gross profit calc
Xrm.Page.data.entity.attributes.get("pt_projectedgrossprofit").setSubmitMode("always");
Xrm.Page.data.entity.attributes.get("pt_projectgrossprofitpercent").setSubmitMode("always");
//project on schedule fields
Xrm.Page.data.entity.attributes.get("pt_projectonbudget").setSubmitMode("always");
Xrm.Page.data.entity.attributes.get("pt_projectonschedule").setSubmitMode("always");
//project summary fields
//Xrm.Page.data.entity.attributes.get("pt_projectonbudget").setSubmitMode("always");
//Xrm.Page.data.entity.attributes.get("pt_projectonschedule").setSubmitMode("always");
//Xrm.Page.data.entity.attributes.get("pt_projectduration").setSubmitMode("always");
Xrm.Page.data.entity.attributes.get("pt_contractpricerounded").setSubmitMode("always");
Xrm.Page.data.entity.attributes.get("pt_quotedtotalprojectcostsrounded").setSubmitMode("always");
Xrm.Page.data.entity.attributes.get("pt_quotedgrossprofitrounded").setSubmitMode("always");
Xrm.Page.data.entity.attributes.get("pt_quotedpromiseshipdate").setSubmitMode("always");
//quoted
Xrm.Page.data.entity.attributes.get('pt_quotedmaterialcosts').setSubmitMode("always");
Xrm.Page.data.entity.attributes.get('pt_quotedlaborcosts').setSubmitMode("always");
Xrm.Page.data.entity.attributes.get('pt_quotedsubcontractorcosts').setSubmitMode("always");
Xrm.Page.data.entity.attributes.get('pt_quotedtravelcosts').setSubmitMode("always");
Xrm.Page.data.entity.attributes.get('pt_quotedinboundfreightcosts').setSubmitMode("always");
Xrm.Page.data.entity.attributes.get('pt_quotedoverhead').setSubmitMode("always");
Xrm.Page.data.entity.attributes.get('pt_quotedtotalprojectcosts').setSubmitMode("always");
Xrm.Page.data.entity.attributes.get('pt_quotedgrossprofit').setSubmitMode("always");
Xrm.Page.data.entity.attributes.get('pt_quotedlastentrydate').setSubmitMode("always");
Xrm.Page.data.entity.attributes.get('pt_quotedpromiseshipdate').setSubmitMode("always");
Xrm.Page.data.entity.attributes.get('pt_quotedcontractpricehidden').setSubmitMode("always");
//fields updated from real time workflow
Xrm.Page.data.entity.attributes.get('pt_quotedpromiseshipdatehidden').setSubmitMode("always");
Xrm.Page.data.entity.attributes.get('pt_originalpromiseshipdate').setSubmitMode("always");
Xrm.Page.data.entity.attributes.get('pt_quotedmaterialcostshidden').setSubmitMode("always");
Xrm.Page.data.entity.attributes.get('pt_quotedlaborcostshidden').setSubmitMode("always");
Xrm.Page.data.entity.attributes.get('pt_quotedsubcontractorcostshidden').setSubmitMode("always");
Xrm.Page.data.entity.attributes.get('pt_quotedsubcontractorcostshidden').setSubmitMode("always");
Xrm.Page.data.entity.attributes.get('pt_quotedinboundfreightcostshidden').setSubmitMode("always");
Xrm.Page.data.entity.attributes.get('pt_quotedoverheadcostshidden').setSubmitMode("always");
Xrm.Page.data.entity.attributes.get('pt_quotedtotalprojectcosthidden').setSubmitMode("always");
Xrm.Page.data.entity.attributes.get('pt_quotedlastentrydatehidden').setSubmitMode("always");
Xrm.Page.data.entity.attributes.get('pt_quotedgrossprofithidden').setSubmitMode("always");
Xrm.Page.data.entity.attributes.get('pt_originalpromiseshipdate').setSubmitMode("always");
Xrm.Page.data.entity.attributes.get('pt_commitmentstate').setSubmitMode("always");
Xrm.Page.data.entity.attributes.get('pt_quotedpromiseshipdatehidden').setSubmitMode("always");
//Expected Future
Xrm.Page.data.entity.attributes.get('pt_expectedfuturematerialcosts').setSubmitMode("always");
Xrm.Page.data.entity.attributes.get('pt_expectedfuturelaborcosts').setSubmitMode("always");
Xrm.Page.data.entity.attributes.get('pt_expectedfuturesubcontractorcosts').setSubmitMode("always");
Xrm.Page.data.entity.attributes.get('pt_expectedfuturetravelcosts').setSubmitMode("always");
Xrm.Page.data.entity.attributes.get('pt_expectedfutureinboundfreightcosts').setSubmitMode("always");
Xrm.Page.data.entity.attributes.get('pt_expectedfutureoverhead').setSubmitMode("always");
}
//'save revised project adjustments?' boolean field
function check_ReviseProjectAdjust() {
var chkBooleanvalue = Xrm.Page.data.entity.attributes.get("pt_reviseprojectadjustment").getValue();
//alert(chkBooleanvalue);
if (chkBooleanvalue == true) {
Xrm.Page.getAttribute('pt_reviseprojectadjustment').setValue(false);
var today = new Date();
Xrm.Page.data.entity.save();
//send user a notification record is saved
Xrm.Page.ui.setFormNotification('Information: Revised Project Burn Rate Saved at ' + today, 'INFORMATION', '1');
//10 sec delay notification removal
setTimeout(function () { Xrm.Page.ui.clearFormNotification('1'); }, 10000);
}
}
//calculation for burn rate project summary tab: Cost to Date section
function costtodate_calc() {
var a = WF.Xrm.Shared.getFieldValue("pt_costtodatesubcontractor", 0);
var b = WF.Xrm.Shared.getFieldValue("pt_costtodatematerial", 0);
var c = WF.Xrm.Shared.getFieldValue("pt_costtodatelabor", 0);
var d = WF.Xrm.Shared.getFieldValue("pt_costtodatetravel", 0);
var e = WF.Xrm.Shared.getFieldValue("pt_costtodateinboundfreight", 0);
//WF.Xrm.Shared.setFieldValue("pt_costtodateoverhead", ((a + b + c + d + e) * 0.025));
var f = WF.Xrm.Shared.getFieldValue("pt_costtodateoverhead", 0);
WF.Xrm.Shared.setFieldValue("pt_costtodatetotalprojectcosts", a + b + c + d + e + f);
//set date field to now (works on date and date time fields)
Xrm.Page.data.entity.attributes.get("pt_costtodatelastentrydate").setValue(new Date());
remainingbalance_calc();
surplusdeficit_calc();
}
// begin chris edits
function grossprofit_calc() {
// Calculation for Project Financials
var ica = WF.Xrm.Shared.getFieldValue("mck_initialcontractamount", 0);
var ice = WF.Xrm.Shared.getFieldValue("mck_initialcostestimate", 0);
// hide for now
var lca = WF.Xrm.Shared.getFieldValue("mck_latestcontractamount", 0);
var lce = WF.Xrm.Shared.getFieldValue("mck_latestcostestimate", 0);
// Calculate initial gross profit
WF.Xrm.Shared.setFieldValue("mck_initialgrossprofit", ica - ice);
// Calculate latest gross profit
WF.Xrm.Shared.setFieldValue("mck_latestgrossprofit", lca - lce);
}
// end chris edits
//calculation for burn rate project summary tab: Remaining Balance section
function remainingbalance_calc() {
var aq = WF.Xrm.Shared.getFieldValue("pt_quotedsubcontractorcosts", 0);
var aq1 = WF.Xrm.Shared.getFieldValue("pt_costtodatesubcontractor", 0);
var bq = WF.Xrm.Shared.getFieldValue("pt_quotedmaterialcosts", 0);
var bq1 = WF.Xrm.Shared.getFieldValue("pt_costtodatematerial", 0);
var cq = WF.Xrm.Shared.getFieldValue("pt_quotedlaborcosts", 0);
var cq1 = WF.Xrm.Shared.getFieldValue("pt_costtodatelabor", 0);
var dq = WF.Xrm.Shared.getFieldValue("pt_quotedtravelcosts", 0);
var dq1 = WF.Xrm.Shared.getFieldValue("pt_costtodatetravel", 0);
var eq = WF.Xrm.Shared.getFieldValue("pt_quotedinboundfreightcosts", 0);
var eq1 = WF.Xrm.Shared.getFieldValue("pt_costtodateinboundfreight", 0);
var fq = WF.Xrm.Shared.getFieldValue("pt_quotedoverhead", 0);
var fq1 = WF.Xrm.Shared.getFieldValue("pt_costtodateoverhead", 0);
var gq = WF.Xrm.Shared.getFieldValue("pt_quotedtotalprojectcosts", 0);
var gq1 = WF.Xrm.Shared.getFieldValue("pt_costtodatetotalprojectcosts", 0);
//calculate difference between cost to date and remaining balance
if (aq != null || aq1 != null) { // do not update if fields are null
WF.Xrm.Shared.setFieldValue("pt_balanceremainingsubcontractorcosts", aq - aq1);
}
if (bq != null || bq1 != null) {
WF.Xrm.Shared.setFieldValue("pt_balanceremainingmaterialcosts", bq - bq1);
}
if (cq != null || cq1 != null) {
WF.Xrm.Shared.setFieldValue("pt_balanceremaininglaborcosts", cq - cq1);
}
if (dq != null || dq1 != null) {
WF.Xrm.Shared.setFieldValue("pt_balanceremainingtravelcosts", dq - dq1);
}
if (eq != null || eq1 != null) {
WF.Xrm.Shared.setFieldValue("pt_balanceremaininginboundfreightcosts", eq - eq1);
}
if (fq != null || fq1 != null) {
WF.Xrm.Shared.setFieldValue("pt_balanceremainingoverhead", fq - fq1);
}
if (gq != null || gq1 != null) {
WF.Xrm.Shared.setFieldValue("pt_balanceremainingtotalprojectcosts", gq - gq1);
}
surplusdeficit_calc();
}
//calculation for burn rate project summary tab: Expected Future Costs section
function expectedfuture_calc() {
var a3 = WF.Xrm.Shared.getFieldValue("pt_expectedfuturesubcontractorcosts", 0);
var b3 = WF.Xrm.Shared.getFieldValue("pt_expectedfuturematerialcosts", 0);
var c3 = WF.Xrm.Shared.getFieldValue("pt_expectedfuturelaborcosts", 0);
var d3 = WF.Xrm.Shared.getFieldValue("pt_expectedfuturetravelcosts", 0);
var e3 = WF.Xrm.Shared.getFieldValue("pt_expectedfutureinboundfreightcosts", 0);
//WF.Xrm.Shared.setFieldValue("pt_expectedfutureoverhead", ((a3 + b3 + c3 + d3 + e3) * 0.025));
var f3 = WF.Xrm.Shared.getFieldValue("pt_expectedfutureoverhead", 0);
WF.Xrm.Shared.setFieldValue("pt_expectedfuturetotalprojectcosts", a3 + b3 + c3 + d3 + e3 + f3);
//set date field to now (works on date and date time fields)
Xrm.Page.data.entity.attributes.get("pt_expectedfuturelastentrydate").setValue(new Date());
remainingbalance_calc();
surplusdeficit_calc();
Projecton_Budget_Schedule();
}
//calculation for burn rate project summary tab: Surplus Deficit Section
function surplusdeficit_calc() {
var a_sd = WF.Xrm.Shared.getFieldValue("pt_quotedsubcontractorcosts", 0);
var a1_sd = WF.Xrm.Shared.getFieldValue("pt_costtodatesubcontractor", 0);
var a2_sd = WF.Xrm.Shared.getFieldValue("pt_expectedfuturesubcontractorcosts", 0);
var b_sd = WF.Xrm.Shared.getFieldValue("pt_quotedmaterialcosts", 0);
var b1_sd = WF.Xrm.Shared.getFieldValue("pt_costtodatematerial", 0);
var b2_sd = WF.Xrm.Shared.getFieldValue("pt_expectedfuturematerialcosts", 0);
var c_sd = WF.Xrm.Shared.getFieldValue("pt_quotedlaborcosts", 0);
var c1_sd = WF.Xrm.Shared.getFieldValue("pt_costtodatelabor", 0);
var c2_sd = WF.Xrm.Shared.getFieldValue("pt_expectedfuturelaborcosts", 0);
var d_sd = WF.Xrm.Shared.getFieldValue("pt_quotedtravelcosts", 0);
var d1_sd = WF.Xrm.Shared.getFieldValue("pt_costtodatetravel", 0);
var d2_sd = WF.Xrm.Shared.getFieldValue("pt_expectedfuturetravelcosts", 0);
var e_sd = WF.Xrm.Shared.getFieldValue("pt_quotedinboundfreightcosts", 0);
var e1_sd = WF.Xrm.Shared.getFieldValue("pt_costtodateinboundfreight", 0);
var e2_sd = WF.Xrm.Shared.getFieldValue("pt_expectedfutureinboundfreightcosts", 0);
var f_sd = WF.Xrm.Shared.getFieldValue("pt_quotedoverhead", 0);
var f1_sd = WF.Xrm.Shared.getFieldValue("pt_costtodateoverhead", 0);
var f2_sd = WF.Xrm.Shared.getFieldValue("pt_expectedfutureoverhead", 0);
var g_sd = WF.Xrm.Shared.getFieldValue("pt_quotedtotalprojectcosts", 0);
var g1_sd = WF.Xrm.Shared.getFieldValue("pt_costtodatetotalprojectcosts", 0);
var g2_sd = WF.Xrm.Shared.getFieldValue("pt_expectedfuturetotalprojectcosts", 0);
//calculate difference between quoted and user entries in cost to date and expected future costs in dollars
WF.Xrm.Shared.setFieldValue("pt_surplusdeficitdollarssubcontractorcosts", a_sd - (a1_sd + a2_sd));
WF.Xrm.Shared.setFieldValue("pt_surplusdeficitdollarsmaterialcosts", b_sd - (b1_sd + b2_sd));
WF.Xrm.Shared.setFieldValue("pt_surplusdeficitdollarslaborcosts", c_sd - (c1_sd + c2_sd));
WF.Xrm.Shared.setFieldValue("pt_surplusdeficitdollarstravelcosts", d_sd - (d1_sd + d2_sd));
WF.Xrm.Shared.setFieldValue("pt_surplusdeficitdollarsinboundfreightcosts", e_sd - (e1_sd + e2_sd));
WF.Xrm.Shared.setFieldValue("pt_surplusdeficitdollarsoverhead", f_sd - (f1_sd + f2_sd));
WF.Xrm.Shared.setFieldValue("pt_surplusdeficitdollarstotalprojectcosts", g_sd - (g1_sd + g2_sd));
//get surplus deficit in dollars
var a3_sd = WF.Xrm.Shared.getFieldValue("pt_surplusdeficitdollarssubcontractorcosts", 0);
var b3_sd = WF.Xrm.Shared.getFieldValue("pt_surplusdeficitdollarsmaterialcosts", 0);
var c3_sd = WF.Xrm.Shared.getFieldValue("pt_surplusdeficitdollarslaborcosts", 0);
var d3_sd = WF.Xrm.Shared.getFieldValue("pt_surplusdeficitdollarstravelcosts", 0);
var e3_sd = WF.Xrm.Shared.getFieldValue("pt_surplusdeficitdollarsinboundfreightcosts", 0);
var f3_sd = WF.Xrm.Shared.getFieldValue("pt_surplusdeficitdollarsoverhead", 0);
var g3_sd = WF.Xrm.Shared.getFieldValue("pt_surplusdeficitdollarstotalprojectcosts", 0);
//calculate difference between quoted and user entries in cost to date and expected future costs in percent
if (a_sd == null || a_sd == 0) { a_sd = 1; } //divide by 0
WF.Xrm.Shared.setFieldValue("pt_surplusdeficitpercentsubcontractorcosts", (a3_sd / a_sd) * 100);
if (b_sd == null || b_sd == 0) { b_sd = 1; }
WF.Xrm.Shared.setFieldValue("pt_surplusdeficitpercentmaterialcosts", (b3_sd / b_sd) * 100);
if (c_sd == null || c_sd == 0) { c_sd = 1; }
WF.Xrm.Shared.setFieldValue("pt_surplusdeficitpercentlaborcosts", (c3_sd / c_sd) * 100);
if (d_sd == null || d_sd == 0) { d_sd = 1; }
WF.Xrm.Shared.setFieldValue("pt_surplusdeficitpercenttravelcosts", (d3_sd / d_sd) * 100);
if (e_sd == null || e_sd == 0) { e_sd = 1; }
WF.Xrm.Shared.setFieldValue("pt_surplusdeficitpercentinboundfreightcosts", (e3_sd / e_sd) * 100);
if (f_sd == null || f_sd == 0) { f_sd = 1; }
WF.Xrm.Shared.setFieldValue("pt_surplusdeficitpercentoverhead", (f3_sd / f_sd) * 100);
if (g_sd == null || g_sd == 0) { g_sd = 1; }
WF.Xrm.Shared.setFieldValue("pt_surplusdeficitpercenttotalprojectcosts", (g3_sd / g_sd) * 100);
//grab project PO Amount (contract price) for project gross profit calc
var gp = WF.Xrm.Shared.getFieldValue("mck_contractprice", 0);
WF.Xrm.Shared.setFieldValue("pt_projectedgrossprofit", gp - (g1_sd + g2_sd));
//grab quoted gp and project gp for project gross profit calc percent
var pgp = WF.Xrm.Shared.getFieldValue("pt_projectedgrossprofit", 0);
var qgp = WF.Xrm.Shared.getFieldValue("pt_quotedgrossprofit", 0);
WF.Xrm.Shared.setFieldValue("pt_projectgrossprofitpercent", (pgp / qgp) * 100);
//do surplus deficit promise ship date duration comparsion
var endate = Xrm.Page.getAttribute('pt_quotedpromiseshipdate').getValue();
var stdate = Xrm.Page.getAttribute('pt_expectedfuturepromiseshipdate').getValue();
if (stdate != null && endate != null) {
var st = stdate.getTime();
var ed = endate.getTime();
var sdiff = (ed - st);
var h = (sdiff / 60 / 1000);
var p = (parseInt(h) / 60) / 24;
var day = " days";
if (p == 1 || p == -1) day = " day";
var tm = p.toString() + day;
//alert(" h:"+h+" p:"+p+" tm:"+tm);
Xrm.Page.getAttribute('pt_surplusdeficitpromiseshipdatedifference').setValue(tm);
}
Xrm.Page.data.save();
}
//****************************************************** Fix auto save issues and form load/save tracking
function preventAutoSave(econtext) {
var eventArgs = econtext.getEventArgs();
if (eventArgs.getSaveMode() == 70 || eventArgs.getSaveMode() == 2) {
eventArgs.preventDefault();
}
}
//var FORMLOADED = false;
//function alertOnLoad() {
// if (!FORMLOADED) {
// //alert("The form has been loaded.");
// }
// FORMLOADED = true;
//}
//function alertOnSave(eventArgs) {
// var saveType = eventArgs.getEventArgs().getSaveMode();
// if (saveType == 70) { //AutoSave
// Xrm.Page.data.setFormDirty(true);
// }
// else {
// //alert("The form has been saved.");
// }
//}
function mgrProjectCostReset_Button() {
var r = confirm("Do you want to Reset the Project's previous Project Commitments?\n\nThe previous Project Commitments will remain for history but the Project Costs in the Burn Rate Project Summary tables will be erased. (Project Manager only)");
if (r == true) {
ForcedSubmitDisableFields();
//Reset contract price from original contract price
//mck_originalcontractprice--> mck_contractprice
var mck_originalcontractprice = Xrm.Page.data.entity.attributes.get("mck_originalcontractprice").getValue();
Xrm.Page.data.entity.attributes.get("mck_contractprice").setValue(mck_originalcontractprice);
//mck_originalcontractprice-->pt_contractpricerounded
Xrm.Page.data.entity.attributes.get("pt_contractpricerounded").setValue(mck_originalcontractprice);
//clear fields
Xrm.Page.data.entity.attributes.get("pt_quotedtotalprojectcostsrounded").setValue(null);
Xrm.Page.data.entity.attributes.get("mck_latestprojectitem").setValue(null);
Xrm.Page.data.entity.attributes.get("pt_costtodatelastentrydate").setValue(null);
Xrm.Page.data.entity.attributes.get("pt_expectedfuturelastentrydate").setValue(null);
Xrm.Page.data.entity.attributes.get("pt_quotedlastentrydate").setValue(null);
Xrm.Page.data.entity.attributes.get("pt_quotedpromiseshipdate").setValue(null);
Xrm.Page.data.entity.attributes.get("pt_expectedfuturepromiseshipdate").setValue(null);
Xrm.Page.data.entity.attributes.get("pt_actualpromiseshipdate").setValue(null);
//cost to date
Xrm.Page.data.entity.attributes.get("pt_costtodatetotalprojectcosts").setValue(null);
Xrm.Page.data.entity.attributes.get("pt_costtodateoverhead").setValue(null);
Xrm.Page.data.entity.attributes.get("pt_costtodatematerial").setValue(null);
Xrm.Page.data.entity.attributes.get("pt_costtodatelabor").setValue(null);
Xrm.Page.data.entity.attributes.get("pt_costtodatesubcontractor").setValue(null);
Xrm.Page.data.entity.attributes.get("pt_costtodatetravel").setValue(null);
Xrm.Page.data.entity.attributes.get("pt_costtodateinboundfreight").setValue(null);
Xrm.Page.data.entity.attributes.get("pt_costtodatelastentrydate").setValue(null);
//balance remaining
Xrm.Page.data.entity.attributes.get("pt_balanceremainingsubcontractorcosts").setValue(null);
Xrm.Page.data.entity.attributes.get("pt_balanceremainingmaterialcosts").setValue(null);
Xrm.Page.data.entity.attributes.get("pt_balanceremaininglaborcosts").setValue(null);
Xrm.Page.data.entity.attributes.get("pt_balanceremainingtravelcosts").setValue(null);
Xrm.Page.data.entity.attributes.get("pt_balanceremaininginboundfreightcosts").setValue(null);
Xrm.Page.data.entity.attributes.get("pt_balanceremainingoverhead").setValue(null);
Xrm.Page.data.entity.attributes.get("pt_balanceremainingtotalprojectcosts").setValue(null);
//expected future costs
Xrm.Page.data.entity.attributes.get("pt_expectedfutureoverhead").setValue(null);
Xrm.Page.data.entity.attributes.get("pt_expectedfuturetotalprojectcosts").setValue(null);
Xrm.Page.data.entity.attributes.get("pt_surplusdeficitpromiseshipdatedifference").setValue(null);
//surplus deficit
Xrm.Page.data.entity.attributes.get("pt_surplusdeficitdollarssubcontractorcosts").setValue(null);
Xrm.Page.data.entity.attributes.get("pt_surplusdeficitdollarsmaterialcosts").setValue(null);
Xrm.Page.data.entity.attributes.get("pt_surplusdeficitdollarslaborcosts").setValue(null);
Xrm.Page.data.entity.attributes.get("pt_surplusdeficitdollarstravelcosts").setValue(null);
Xrm.Page.data.entity.attributes.get("pt_surplusdeficitdollarsinboundfreightcosts").setValue(null);
Xrm.Page.data.entity.attributes.get("pt_surplusdeficitdollarsoverhead").setValue(null);
Xrm.Page.data.entity.attributes.get("pt_quotedgrossprofitrounded").setValue(null);
Xrm.Page.data.entity.attributes.get("pt_surplusdeficitpercentsubcontractorcosts").setValue(null);
Xrm.Page.data.entity.attributes.get("pt_surplusdeficitpercentmaterialcosts").setValue(null);
Xrm.Page.data.entity.attributes.get("pt_surplusdeficitpercentlaborcosts").setValue(null);
Xrm.Page.data.entity.attributes.get("pt_surplusdeficitpercenttravelcosts").setValue(null);
Xrm.Page.data.entity.attributes.get("pt_surplusdeficitpercentinboundfreightcosts").setValue(null);
Xrm.Page.data.entity.attributes.get("pt_surplusdeficitpercentoverhead").setValue(null);
Xrm.Page.data.entity.attributes.get("pt_surplusdeficitpercenttotalprojectcosts").setValue(null);
Xrm.Page.data.entity.attributes.get("pt_surplusdeficitdollarstotalprojectcosts").setValue(null);
Xrm.Page.getAttribute('pt_surplusdeficitpromiseshipdatedifference').setValue(null);
//project PO Amount (contract price) for project gross profit calc
Xrm.Page.data.entity.attributes.get("pt_projectedgrossprofit").setValue(null);
Xrm.Page.data.entity.attributes.get("pt_projectgrossprofitpercent").setValue(null);
//project on schedule fields
Xrm.Page.data.entity.attributes.get('pt_projectonbudget').setValue(null);
Xrm.Page.data.entity.attributes.get('pt_projectonschedule').setValue(null);
//quoted
Xrm.Page.data.entity.attributes.get('pt_quotedmaterialcosts').setValue(null);
Xrm.Page.data.entity.attributes.get('pt_quotedlaborcosts').setValue(null);
Xrm.Page.data.entity.attributes.get('pt_quotedsubcontractorcosts').setValue(null);
Xrm.Page.data.entity.attributes.get('pt_quotedtravelcosts').setValue(null);
Xrm.Page.data.entity.attributes.get('pt_quotedinboundfreightcosts').setValue(null);
Xrm.Page.data.entity.attributes.get('pt_quotedoverhead').setValue(null);
Xrm.Page.data.entity.attributes.get('pt_quotedtotalprojectcosts').setValue(null);
Xrm.Page.data.entity.attributes.get('pt_quotedgrossprofit').setValue(null);
Xrm.Page.data.entity.attributes.get('pt_quotedlastentrydate').setValue(null);
Xrm.Page.data.entity.attributes.get('pt_quotedpromiseshipdate').setValue(null);
Xrm.Page.data.entity.attributes.get('pt_quotedcontractpricehidden').setValue(null);
//fields updated from real time workflow
Xrm.Page.data.entity.attributes.get('pt_quotedpromiseshipdatehidden').setValue(null);
Xrm.Page.data.entity.attributes.get('pt_originalpromiseshipdate').setValue(null);
Xrm.Page.data.entity.attributes.get('pt_quotedmaterialcostshidden').setValue(null);
Xrm.Page.data.entity.attributes.get('pt_quotedlaborcostshidden').setValue(null);
Xrm.Page.data.entity.attributes.get('pt_quotedsubcontractorcostshidden').setValue(null);
Xrm.Page.data.entity.attributes.get('pt_quotedsubcontractorcostshidden').setValue(null);
Xrm.Page.data.entity.attributes.get('pt_quotedinboundfreightcostshidden').setValue(null);
Xrm.Page.data.entity.attributes.get('pt_quotedoverheadcostshidden').setValue(null);
Xrm.Page.data.entity.attributes.get('pt_quotedtotalprojectcosthidden').setValue(null);
Xrm.Page.data.entity.attributes.get('pt_quotedlastentrydatehidden').setValue(null);
Xrm.Page.data.entity.attributes.get('pt_quotedgrossprofithidden').setValue(null);
Xrm.Page.data.entity.attributes.get('pt_originalpromiseshipdate').setValue(null);
Xrm.Page.data.entity.attributes.get('pt_commitmentstate').setValue(null);
Xrm.Page.data.entity.attributes.get('pt_quotedpromiseshipdatehidden').setValue(null);
//Expected Future
Xrm.Page.data.entity.attributes.get('pt_expectedfuturematerialcosts').setValue(null);
Xrm.Page.data.entity.attributes.get('pt_expectedfuturelaborcosts').setValue(null);
Xrm.Page.data.entity.attributes.get('pt_expectedfuturesubcontractorcosts').setValue(null);
Xrm.Page.data.entity.attributes.get('pt_expectedfuturetravelcosts').setValue(null);
Xrm.Page.data.entity.attributes.get('pt_expectedfutureinboundfreightcosts').setValue(null);
Xrm.Page.data.entity.attributes.get('pt_expectedfutureoverhead').setValue(null);
Xrm.Page.data.entity.save();
Xrm.Page.ui.setFormNotification('Information: Manager Project Cost Reset Completed. Now a new Project Commitment can be created as the first. Previous Latest Project Commitments are still available in history.', 'INFORMATION', '5');
//60 sec delay notification removal
setTimeout(function () { Xrm.Page.ui.clearFormNotification('5'); }, 60000);
} else {
return;
}
}
//******************************************************
//****************************************************** Replaced with real time workflow "Project - update project costs from lastest project commitment for burn rate project summary"
//fix burn rate project tab auto expanding
//replaced with oData rest call
////populates burn rate project summary section column quoted from last project commitment related record
//function getRecordDetails() {
// var EntityName, EntityId, LookupFieldObject;
// var Name = "";
// var resultXml;
// var quotedpromiseshipdate = Xrm.Page.getAttribute('pt_quotedpromiseshipdatehidden').getValue();
// var originalpromiseshipdate = Xrm.Page.getAttribute('pt_originalpromiseshipdate').getValue();
// LookupFieldObject = Xrm.Page.data.entity.attributes.get('mck_latestprojectitem');
// if (LookupFieldObject.getValue() != null) {
// EntityId = LookupFieldObject.getValue()[0].id;
// EntityName = LookupFieldObject.getValue()[0].entityType;
// resultXml = getDetails(EntityName, EntityId);
// // Retrieve value and set the value to current record field.
// if (resultXml != null && resultXml.attributes['mck_materialcosts'] != null) {
// //retrieve from latest project (commitment) item
// var materialcosts = resultXml.attributes['mck_materialcosts'].value;
// //set value in current project record
// Xrm.Page.data.entity.attributes.get('pt_quotedmaterialcostshidden').setValue(materialcosts);
// }
// else
// XXrm.Page.data.entity.attributes.get('pt_quotedmaterialcostshidden').setValue(0);
// // Retrieve value and set the value to current record field.
// if (resultXml != null && resultXml.attributes['pt_laborcosts'] != null) {
// //retrieve from latest project (commitment) item
// var laborcosts = resultXml.attributes['pt_laborcosts'].value;
// //set value in current project record
// Xrm.Page.data.entity.attributes.get('pt_quotedlaborcostshidden').setValue(laborcosts);
// }
// else
// Xrm.Page.data.entity.attributes.get('pt_quotedlaborcostshidden').setValue(0);
// // Retrieve text field value and set the value to current record field.
// if (resultXml != null && resultXml.attributes['mck_subcontractorcosts'] != null) {
// //retrieve from latest project (commitment) item
// var subcontractorcosts = resultXml.attributes['mck_subcontractorcosts'].value;
// //set value in current project record
// Xrm.Page.data.entity.attributes.get('pt_quotedsubcontractorcostshidden').setValue(subcontractorcosts);
// }
// else
// Xrm.Page.data.entity.attributes.get('pt_quotedsubcontractorcostshidden').setValue(0);
// // Retrieve text field value and set the value to current record field.
// if (resultXml != null && resultXml.attributes['pt_travelcosts'] != null) {
// //retrieve from latest project (commitment) item
// var travelcosts = resultXml.attributes['pt_travelcosts'].value;
// //set value in current project record
// Xrm.Page.data.entity.attributes.get('pt_quotedtravelcostshidden').setValue(travelcosts);
// }
// else
// Xrm.Page.data.entity.attributes.get('pt_quotedtravelcostshidden').setValue(0);
// // Retrieve text field value and set the value to current record field.
// if (resultXml != null && resultXml.attributes['pt_inboundfreightcosts_prj_summary'] != null) {
// //retrieve from latest project (commitment) item
// var inboundfreightcosts = resultXml.attributes['pt_inboundfreightcosts_prj_summary'].value;
// //set value in current project record
// //alert(inboundfreightcosts);
// Xrm.Page.data.entity.attributes.get('pt_quotedinboundfreightcostshidden').setValue(inboundfreightcosts);
// }
// else
// Xrm.Page.data.entity.attributes.get('pt_quotedinboundfreightcostshidden').setValue(0);
// // Retrieve text field value and set the value to current record field.
// if (resultXml != null && resultXml.attributes['pt_overheadcosts'] != null) {
// //retrieve from latest project (commitment) item
// var overheadcosts = resultXml.attributes['pt_overheadcosts'].value;
// //set value in current project record
// Xrm.Page.data.entity.attributes.get('pt_quotedoverheadcostshidden').setValue(overheadcosts);
// }
// else
// Xrm.Page.data.entity.attributes.get('pt_quotedoverheadcostshidden').setValue(0);
// // Retrieve text field value and set the value to current record field.
// if (resultXml != null && resultXml.attributes['mck_totalprojectcosts'] != null) {
// //retrieve from latest project (commitment) item
// var totalprojectcosts = resultXml.attributes['mck_totalprojectcosts'].value;
// //set value in current project record
// Xrm.Page.data.entity.attributes.get('pt_quotedtotalprojectcosthidden').setValue(totalprojectcosts);
// }
// else
// Xrm.Page.data.entity.attributes.get('pt_quotedtotalprojectcosthidden').setValue(0);
// // Retrieve text field value and set the value to current record field.
// if (resultXml != null && resultXml.attributes['createdon'] != null) {
// //retrieve from latest project (commitment) item
// var createdon = resultXml.attributes['createdon'].value;
// // createdon = HandleODataDate(createdon);
// //set value in current project record
// Xrm.Page.data.entity.attributes.get('pt_quotedlastentrydatehidden').setValue(createdon);
// }
// else
// Xrm.Page.data.entity.attributes.get('pt_quotedlastentrydatehidden').setValue(null);
// // Retrieve text field value and set the value to current record field.
// if (resultXml != null && resultXml.attributes['mck_grossprofitdollars'] != null && resultXml.attributes['mck_commitmentstate'] != 803990002) {
// //retrieve from latest project (commitment) item
// var grossprofit = resultXml.attributes['mck_grossprofitdollars'].value;
// //set value in current project record
// Xrm.Page.data.entity.attributes.get('pt_quotedgrossprofithidden').setValue(grossprofit);
// }
// else
// Xrm.Page.data.entity.attributes.get('pt_quotedgrossprofithidden').setValue(0);
// // Retrieve value to verify if its an actual latest project commitment
// if (resultXml != null && resultXml.attributes['mck_commitmentstate'] != null) {
// //retrieve from latest project (commitment) item
// var commitmentstate = resultXml.attributes['mck_commitmentstate'].value;
// //alert(commitmentstate);
// Xrm.Page.getAttribute('pt_commitmentstate').setValue(commitmentstate);
// //alert("CHKgetRecordDetails: pt: " + pt_commitmentstate + ". mck: " + commitmentstate);
// } else Xrm.Page.getAttribute('pt_commitmentstate').setValue(null);
// // Verify its the first time populating the Original promise ship date
// if (originalpromiseshipdate == null) {
// if (resultXml != null && resultXml.attributes['mck_promiseshipdate'] != null) {
// //retrieve from latest project (commitment) item
// var promiseshipdate = resultXml.attributes['mck_promiseshipdate'].value;
// //set value in current project record
// Xrm.Page.data.entity.attributes.get('pt_originalpromiseshipdate').setValue(promiseshipdate);
// }
// else
// Xrm.Page.data.entity.attributes.get('pt_originalpromiseshipdate').setValue(0);
// }
// // Verify its not the first time populating the Original promise ship date and committed type latest project commitment and Changed by Promise Ship date is MCKCO
// if (originalpromiseshipdate != null && resultXml.attributes['mck_commitmentstate'] == 803990000 && resultXml.attributes['mck_changedbypromiseshipdate'] == 803990002) {
// if (resultXml != null && resultXml.attributes['mck_promiseshipdate'] != null) {
// //retrieve from latest project (commitment) item
// var promiseshipdate = resultXml.attributes['mck_promiseshipdate'].value;
// //set value in current project record
// Xrm.Page.data.entity.attributes.get('pt_originalpromiseshipdate').setValue(promiseshipdate);
// }
// else
// Xrm.Page.data.entity.attributes.get('pt_originalpromiseshipdate').setValue(0);
// }
// // Retrieve value from latest project commitment
// if (resultXml != null && resultXml.attributes['mck_promiseshipdate'] != null) {
// //retrieve from latest project (commitment) item
// var quotedpromiseshipdate = resultXml.attributes['mck_promiseshipdate'].value;
// Xrm.Page.getAttribute('pt_quotedpromiseshipdatehidden').setValue(quotedpromiseshipdate);
// } else Xrm.Page.getAttribute('pt_quotedpromiseshipdatehidden').setValue(null);
// }
//}
////uses xrmservicekit soap message to retrieve values in getrecorddetails
//function getDetails(EntityName, EntityId) {
// var cols = ["mck_materialcosts", "pt_laborcosts", "mck_changedbypromiseshipdate", "mck_subcontractorcosts", "mck_subcontractorcosts", "pt_travelcosts", "pt_inboundfreightcosts_prj_summary", "pt_overheadcosts", "mck_totalprojectcosts", "createdon", "mck_grossprofitdollars", "mck_promiseshipdate", "mck_commitmentstate"];
// var retrievedResult = XrmServiceToolkit.Soap.Retrieve(EntityName, EntityId, cols);
// return retrievedResult;
//}
////oData rest call
////replaced Soap Xrmservicetoolkit
//function getRecordDetails_XMLHttpRequest() {
// var EntityName, EntityId, LookupFieldObject;
// var Name = "";
// var result;
// //var quotedpromiseshipdate = Xrm.Page.getAttribute('pt_quotedpromiseshipdatehidden').getValue();
// //var originalpromiseshipdate = Xrm.Page.getAttribute('pt_originalpromiseshipdate').getValue();
// //debugger;
// LookupFieldObject = Xrm.Page.data.entity.attributes.get('mck_latestprojectitem');
// if (LookupFieldObject.getValue() != null) {
// EntityId = LookupFieldObject.getValue()[0].id;
// // EntityName = LookupFieldObject.getValue()[0].entityType;
// //OData URI to get address information from parent account record
// var oDataURI = Xrm.Page.context.getClientUrl()
// + "/XRMServices/2011/OrganizationData.svc/"
// + "mck_projectitemSet(guid'" + EntityId + "')"
// + "?$select="
// + "mck_MaterialCosts,"
// + "pt_LaborCosts,"
// + "mck_SubcontractorCosts,"
// + "pt_TravelCosts,"
// + "pt_InboundFreightCosts_prj_summary,"
// + "pt_OverheadCosts,"
// + "CreatedOn,"
// + "mck_CommitmentState,"
// + "mck_PromiseShipDate,"
// + "mck_ChangedByPromiseShipDate,"
// + "mck_GrossProfitDollars,"
// + "mck_TotalProjectCosts";
// // prompt(oDataURI, oDataURI);
// //Asynchronous XMLHttpRequest to retrieve account record
// var req = new XMLHttpRequest();
// req.open("GET", encodeURI(oDataURI), true);
// req.setRequestHeader("Accept", "application/json");
// req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
// req.onreadystatechange = function () {
// //debugger;
// if (this.readyState == 4 /* complete */) {
// req.onreadystatechange = null; //avoids memory leaks
// if (this.status == 200) {
// //parse the response string as a JSON object into the successCallback method.
// successCallback_XMLHttpRequest(JSON.parse(this.responseText).d);
// }
// else {
// errorCallback_XMLHttpRequest(EntityId);
// }
// }
// };
// req.send();
// }
//}
////populates burn rate project summary section column quoted from last project commitment related record
////certain conidtions may or may not populate fields depending on project commitment status
//function successCallback_XMLHttpRequest(resultXml) {
// var quotedpromiseshipdate = Xrm.Page.getAttribute('pt_quotedpromiseshipdatehidden').getValue();
// var originalpromiseshipdate = Xrm.Page.getAttribute('pt_originalpromiseshipdate').getValue();
// //Set project cost information
// // Retrieve value and set the value to current record field.
// if (resultXml != null && resultXml.mck_MaterialCosts.Value != null) {
// //retrieve from latest project (commitment) item
// var materialcosts = resultXml.mck_MaterialCosts.Value;
// //set value in current project record
// Xrm.Page.data.entity.attributes.get('pt_quotedmaterialcostshidden').setValue(parseFloat(eval(materialcosts)));//parse oData Money data type correctly
// }
// else
// Xrm.Page.data.entity.attributes.get('pt_quotedmaterialcostshidden').setValue(0);
// // Retrieve value and set the value to current record field.
// if (resultXml != null && resultXml.pt_LaborCosts.Value != null) {
// //retrieve from latest project (commitment) item
// var laborcosts = resultXml.pt_LaborCosts.Value;
// //set value in current project record
// Xrm.Page.data.entity.attributes.get('pt_quotedlaborcostshidden').setValue(parseFloat(eval(laborcosts)));//parse oData Money data type correctly
// }
// else
// Xrm.Page.data.entity.attributes.get('pt_quotedlaborcostshidden').setValue(0);
// // Retrieve text field value and set the value to current record field.
// if (resultXml != null && resultXml.mck_SubcontractorCosts.Value != null) {
// //retrieve from latest project (commitment) item
// var subcontractorcosts = resultXml.mck_SubcontractorCosts.Value;
// //set value in current project record
// Xrm.Page.data.entity.attributes.get('pt_quotedsubcontractorcostshidden').setValue(parseFloat(eval(subcontractorcosts)));//parse oData Money data type correctly
// }
// else
// Xrm.Page.data.entity.attributes.get('pt_quotedsubcontractorcostshidden').setValue(0);
// // Retrieve text field value and set the value to current record field.
// if (resultXml != null && resultXml.pt_TravelCosts.Value != null) {
// //retrieve from latest project (commitment) item
// var travelcosts = resultXml.pt_TravelCosts.Value;
// //set value in current project record
// Xrm.Page.data.entity.attributes.get('pt_quotedtravelcostshidden').setValue(parseFloat(eval(travelcosts)));//parse oData Money data type correctly
// }
// else
// Xrm.Page.data.entity.attributes.get('pt_quotedsubcontractorcostshidden').setValue(0);
// // Retrieve text field value and set the value to current record field.
// if (resultXml != null && resultXml.pt_InboundFreightCosts_prj_summary.Value != null) {
// //retrieve from latest project (commitment) item
// var inboundfreightcosts = resultXml.pt_InboundFreightCosts_prj_summary.Value;
// //set value in current project record
// //alert(inboundfreightcosts);
// Xrm.Page.data.entity.attributes.get('pt_quotedinboundfreightcostshidden').setValue(parseFloat(eval(inboundfreightcosts)));//parse oData Money data type correctly
// }
// else
// Xrm.Page.data.entity.attributes.get('pt_quotedinboundfreightcostshidden').setValue(0);
// // Retrieve text field value and set the value to current record field.
// if (resultXml != null && resultXml.pt_OverheadCosts.Value != null) {
// //retrieve from latest project (commitment) item
// var overheadcosts = resultXml.pt_OverheadCosts.Value;
// //set value in current project record
// Xrm.Page.data.entity.attributes.get('pt_quotedoverheadcostshidden').setValue(parseFloat(eval(overheadcosts)));//parse oData Money data type correctly
// }
// else
// Xrm.Page.data.entity.attributes.get('pt_quotedoverheadcostshidden').setValue(0);
// // Retrieve text field value and set the value to current record field.
// if (resultXml != null && resultXml.mck_TotalProjectCosts.Value != null) {
// //retrieve from latest project (commitment) item
// var totalprojectcosts = resultXml.mck_TotalProjectCosts.Value;
// //set value in current project record
// Xrm.Page.data.entity.attributes.get('pt_quotedtotalprojectcosthidden').setValue(parseFloat(eval(totalprojectcosts)));//parse oData Money data type correctly
// }
// else
// Xrm.Page.data.entity.attributes.get('pt_quotedtotalprojectcosthidden').setValue(0);
// // Retrieve text field value and set the value to current record field.
// if (resultXml != null && resultXml.CreatedOn != null) {
// //retrieve from latest project (commitment) item
// //parse oData date
// var dt = resultXml.CreatedOn;
// dt = dt.replace("/Date(", "");
// dt = dt.replace(")/", "");
// var createdon = new Date(parseInt(dt, 10));
// createdon.setDate(createdon.getDate());
// //set value in current project record
// Xrm.Page.data.entity.attributes.get('pt_quotedlastentrydatehidden').setValue(createdon);
// }
// else
// Xrm.Page.data.entity.attributes.get('pt_quotedlastentrydatehidden').setValue(null);
// // Retrieve text field value and set the value to current record field.
// if (resultXml != null && resultXml.mck_GrossProfitDollars.Value != null && resultXml.mck_CommitmentState.Value != 803990002) {
// //retrieve from latest project (commitment) item
// var grossprofit = resultXml.mck_GrossProfitDollars.Value;
// //set value in current project record
// Xrm.Page.data.entity.attributes.get('pt_quotedgrossprofithidden').setValue(parseFloat(eval(grossprofit)));//parse oData Money data type correctly
// }
// else
// Xrm.Page.data.entity.attributes.get('pt_quotedgrossprofithidden').setValue(0);
// // Retrieve value to verify if its an actual latest project commitment
// if (resultXml != null && resultXml.mck_CommitmentState.Value != null) {
// //retrieve from latest project (commitment) item
// var commitmentstate = resultXml.mck_CommitmentState.Value;
// Xrm.Page.getAttribute('pt_commitmentstate').setValue(commitmentstate);
// } else Xrm.Page.getAttribute('pt_commitmentstate').setValue(null);
// // Verify its the first time populating the Original promise ship date
// if (originalpromiseshipdate == null) {
// if (resultXml != null && resultXml.mck_PromiseShipDate != null) {
// //retrieve from latest project (commitment) item
// //parse oData date
// var dt = resultXml.mck_PromiseShipDate;
// dt = dt.replace("/Date(", "");
// dt = dt.replace(")/", "");
// var promiseshipdate = new Date(parseInt(dt, 10));
// promiseshipdate.setDate(promiseshipdate.getDate());
// //set value in current project record
// Xrm.Page.data.entity.attributes.get('pt_originalpromiseshipdate').setValue(promiseshipdate);
// }
// else
// Xrm.Page.data.entity.attributes.get('pt_originalpromiseshipdate').setValue(0);
// }
// // Verify its not the first time populating the Original promise ship date and committed type latest project commitment and Changed by Promise Ship date is MCKCO
// if (originalpromiseshipdate != null && resultXml.mck_CommitmentState.Value == 803990000 && resultXml.mck_ChangedByPromiseShipDate.Value == 803990002) {
// if (resultXml != null && resultXml.mck_PromiseShipDate != null) {
// //retrieve from latest project (commitment) item
// //parse oData date
// var dt = resultXml.mck_PromiseShipDate;
// dt = dt.replace("/Date(", "");
// dt = dt.replace(")/", "");
// var promiseshipdate2 = new Date(parseInt(dt, 10));
// promiseshipdate2.setDate(promiseshipdate2.getDate());
// //set value in current project record
// Xrm.Page.data.entity.attributes.get('pt_originalpromiseshipdate').setValue(promiseshipdate2);
// }
// else
// Xrm.Page.data.entity.attributes.get('pt_originalpromiseshipdate').setValue(0);
// }
// // Retrieve value from latest project commitment
// if (resultXml != null && resultXml.mck_PromiseShipDate != null) {
// //retrieve from latest project (commitment) item
// //parse oData date
// var dt = resultXml.mck_PromiseShipDate;
// dt = dt.replace("/Date(", "");
// dt = dt.replace(")/", "");
// var quotedpromiseshipdate = new Date(parseInt(dt, 10));
// quotedpromiseshipdate.setDate(quotedpromiseshipdate.getDate());
// //set value in current project record
// Xrm.Page.getAttribute('pt_quotedpromiseshipdatehidden').setValue(quotedpromiseshipdate);
// } else Xrm.Page.getAttribute('pt_quotedpromiseshipdatehidden').setValue(null);
//}
//function errorCallback_XMLHttpRequest(id) {
// var msg1 = "Customization Error: unable to retrieve Latest Project Commitments fields with recordId = " + id + ".";
// //display a non-blocking alert dialog
// Xrm.Utility.alertDialog(msg1, function () { });
//}
//********************************************************** End of replacement to real time workflow "Project - update project costs from lastest project commitment for burn rate project summary"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment