let claimEditor = function( _claimEditorOptions ) { const claimEditorOptions = $.extend( { readOnly: false, mode : "prepare" }, _claimEditorOptions ); const subClaimDetailsContentURLBase = Fse.Util.updateURL2( $("#PortalDocRootURL").attr( "href" ) + "/apps/TPM/index.cfm", { ajax : "subClaimDetailsContent", mode : "direct", readOnly : claimEditorOptions.readOnly, allowAudit : claimEditorOptions.allowAudit, claimId : claimEditorOptions.claimId } ); const subClaimURLBase = Fse.Util.updateURL2( $("#PortalDocRootURL").attr( "href" ) + "/apps/TPM/index.cfm", { view : "claim", claimId : claimEditorOptions.claimId, returnURL : claimEditorOptions.returnURL } ); const claimId = claimEditorOptions.claimId; const handlerURL = $("link#PortalDocRootURL").attr("href") + "/apps/TPM/index.cfm"; let dataURL = Fse.Util.updateURL2( handlerURL, { ajax : "data", mode : "direct", claimId : claimId }); if( claimEditorOptions.contractNbr ) { dataURL = Fse.Util.updateURL2( dataURL, { contractNbr : claimEditorOptions.contractNbr }); } const claimContractsDataSource = Fse.Data.createDataSource( { paginate : false, customStore : { dataURL : dataURL, object : "claimContracts", key : "claimContractId" }} ); if( claimEditorOptions.contractNbr ) { claimContractsDataSource.on( "loadingChanged", function( isLoading ) { if( ! isLoading ) { showSubClaim( this.items()[0] ); } } ); claimContractsDataSource.load(); } let subClaimsGrid = null; let claimStatusForm = null; let claimEditToolbar = null; let subClaimDetailsForm = null; let proofOfDeliveryGrid = null; // make all urlParams lower case let newURLParams = {}; for( p in claimEditorOptions.urlParams ) { newURLParams[p.toLowerCase()] = claimEditorOptions.urlParams[p]; } claimEditorOptions.urlParams = newURLParams; if( claimEditorOptions.mode == "prepare" ) { subClaimsGrid = $("
").dxDataGrid( { elementAttr : { class : "claimEditor-subClaimsDataGrid" }, columns : [ { dataField : "claimId" ,visible : false }, { dataField : "contractNbr", caption : "Contract Ref.", cellTemplate : function( container, options ) { if( options.data.contractNbr != '$MISCELLANEOUS' ) { $("").attr( "href", Fse.Util.updateURL2( subClaimURLBase, { contractNbr : options.data.contractNbr } ) ).append( options.data.contractNbr ).appendTo( container ) } else { container.append( options.data.contractNbr ); } } }, { dataField : "beneficiaryName", visible : false, caption : "Beneficiary" }, { name : "contractDescription", cellTemplate : function( container, options ) { if( options.data.requestId ) { $("
").append( $("").append( options.data.beneficiaryName ).attr( "href", "javascript:Fse.TPM.viewRequest(" + options.data.requestId + ")" ) ).appendTo( container ) let part1 = $("
").append( $("").append( options.data.assignedContractNbr + " " + options.data.requestDescription ).attr( "href", "javascript:Fse.TPM.viewRequest(" + options.data.requestId + ")" ) ).appendTo( container ); let changeHref = ""; if( options.data.volumeBased == "N" || options.data.claimPartnerType == "OPR" ) { changeHref = "javascript:Fse.TPM.contractSearchAndSelect({payableToAllowed:'" + options.data.claimPartnerType + "',partnerId:" + options.data.claimPartnerId + ",partnerType:'" + options.data.claimPartnerType + "',payableTo:'" + options.data.claimPartnerType + "',startDate:'" + options.data.firstDateFormatted + "',endDate:'" + options.data.lastDateFormatted + "'}, function(o){Fse.TPM.changeClaimContract(" + options.data.claimId + ",'" + options.data.contractNbr + "',o.REQUESTID )})"; } else { changeHref = "javascript:Fse.TPM.contractSearchAndSelect({payableToAllowed:'" + options.data.claimPartnerType + "',payableTo:'" + options.data.claimPartnerType + "',startDate:'" + options.data.firstDateFormatted + "',endDate:'" + options.data.lastDateFormatted + "'}, function(o){Fse.TPM.changeClaimContract(" + options.data.claimId + ",'" + options.data.contractNbr + "',o.REQUESTID )})"; } part1.append( $("
" ) ).append( $("
").attr( "href", changeHref ).append( "change" ) ); if( options.data.payableTo != options.data.claimPartnerType ) { let displayPartnerType = "Operator" if( options.data.claimPartnerType == "CDR" ) { displayPartnerType = "Distributor" } $("
").css( "color", "red" ).append( "Agreement not payable to " + displayPartnerType ).appendTo( container ); } } if( options.data.reconciled == "Y" ) { $("
").css( { "color" : "red", "font-weight" : "bold" } ).append( "CLEARED " + reconciledDate ).appendTo( container ); } } }, { dataField : "subClaimAmount", dataType : "number", format : { type : "fixedPoint", precision : 2 }}, { dataField : "status" } ], dataSource : claimContractsDataSource, height : "auto", scrolling : { mode : "none" }, pager : { showInfo : false, showNavigationButtons : true, showPageSizeSelector : true }, paging : { enabled : true, xpageSize : 3 }, selection : { xmode : "single", mode : "none" }, summary : { totalItems : [ { column : "subClaimAmount", summaryType : "sum", displayFormat : "Claim Total: {0}", valueFormat : { type : "currency", precision : 2 } }, { summaryType : "count", showInColumn : "contractNbr", displayFormat : "Sub-Claims: {0}" } ] }, xonRowClick : function( e ) { if( e.rowType != "data" ) { return; } let currentKey = e.component.option( "fseCurrentKey" ); if( e.key == currentKey ) { return; } else { e.component.option( "fseCurrentKey", e.key ); } showSubClaim( e.data ); }, }).appendTo( "#claimEditor" ).dxDataGrid( "instance" ); } let claimStatusReasonsDataSource = new DevExpress.data.DataSource( Fse.Util.updateURL2( dataURL, { object : "claimStatusReasons" } )); // let claimStatusReasonsDataSource = Fse.Data.createDataSource( { paginate : false, customStore : { dataURL : dataURL, object : "claimStatusReasons", key : "reasonId" }} ); if( claimEditorOptions.mode == "prepare" ) { claimStatusForm = $("
" ).dxForm( { readOnly : claimEditorOptions.readOnly, elementAttr : { class : "claimEditor-claimStatusForm" }, items : [ { itemType : "group", colCount: 3, items : [ { dataField : "claimStatus", editorType : "dxSelectBox", editorOptions : { items : [ "HOLD", "OPEN", "APPROVED", "DENY" ] }, label : { text : "Status" }}, { dataField : "statusReasonId", editorType : "dxSelectBox", editorOptions : { disabled: true, //dataSource : claimStatusReasonsDataSource, valueExpr : "reasonId", displayExpr : "reasonName" }, label : { visible : false } }, { dataField : "newClaimStatusReason", editorType : "dxTextBox", editorOptions : { disabled : true, placeholder : "New Reason" }, label : { visible : false } } ] }, { itemType : "group", colCount : 1, items : [ { dataField : "claimStatusComment", editorType : "dxTextArea", editorOptions : { maxLength : 500, height : "4em" }, label : { text : "Comment" } } ] } ], onFieldDataChanged : function( e ) { let statusReasonSB = e.component.getEditor( "statusReasonId"); let newClaimStatusReasonTB = e.component.getEditor( "newClaimStatusReason"); if( e.dataField == "claimStatus" ) { if( e.value == "HOLD" ) { statusReasonSB.option( "disabled", false ); if( statusReasonSB.option( "value" ) == "0" ) { newClaimStatusReasonTB.option( "disabled", false ); } else { newClaimStatusReasonTB.option( "disabled", true ); } } else { statusReasonSB.option( "disabled", true ); newClaimStatusReasonTB.option( "disabled", true ); } } else if ( e.dataField == "statusReasonId" ) { if( e.value == "0" ) { newClaimStatusReasonTB.option( "disabled", false ); } else { newClaimStatusReasonTB.option( "disabled", true ); } } } }).appendTo( $("#claimEditor") ).dxForm( "instance" ); // this is where we need to load the claim form let claimDataSource = new DevExpress.data.DataSource( Fse.Util.updateURL2( dataURL, { object : "claim" } )); claimStatusReasonsDataSource.load().done( function( data ) { data.push( { reasonId : 0, reasonName : '-- new reason --' } ); claimStatusForm.getEditor( "statusReasonId" ).option( "items", data ); }) claimDataSource.load().done( function( data ) { data[0].keepInPrepare = true; claimStatusForm.option( "formData", data[0] ); } ); } let toolBarItems = []; if( ! claimEditorOptions.readOnly ) { toolBarItems.push( { location : "before", widget : "dxButton", options : { text : "Confirm", onClick : function( e ) { if( claimEditorOptions.mode == "audit" ) { saveSubClaim(); } else { saveClaim(); } } } }); if( claimEditorOptions.mode == "prepare" ) { toolBarItems.push ( { location : "before", widget : "dxCheckBox", options : { text : "Keep in Prepare", value : true, onValueChanged : function( e ) { claimStatusForm.option( "formData" ).keepInPrepare = e.value; } } } ); } } claimEditToolbar = $("
").dxToolbar( { elementAttr : { class : "claimEditor-toolbar" }, items : toolBarItems, }).appendTo( $("#claimEditor" )).dxToolbar( "instance" ); subClaimDetailsForm = $("
").dxForm( { elementAttr : { class : "claimEditor-subClaimForm" }, visible : false, readOnly : claimEditorOptions.readOnly ? true : ( claimEditorOptions.mode != "audit" ? true : false ), formData : { claimId : null, payableTo : null, claimType : null, clearingTs : null, claimContractId : null, claimTotal : null, verifiedAmount : null, variance : null, firstDate : null, lastDate : null, message : null, status : null, podChanges : null, claimContractStatusComment : null, claimContractPrepareComment : null }, items : [ { itemType : "group", colCount : 3, items : [ { itemType : "group", template : function( options ) { let c = $("
"); options.component.on( "fieldDataChanged", function( e ) { if( e.dataField == "claimContractId" ) { if( e.value ) { c.html( "Loading..." ); let subClaimDetailsContentURL = Fse.Util.updateURL2( subClaimDetailsContentURLBase, { claimContractId : e.value, contentType : "claimContract" } ); $.ajax( { dataType : "html", url : subClaimDetailsContentURL, success : function( data, textStatus, jqXHR ) { c.html( data ); } }) } else { c.html( "" ); } } } ); return c; } }, { itemType : "group", template : function( options ) { let c = $("
"); options.component.on( "fieldDataChanged", function( e ) { if( e.dataField == "claimContractId" ) { if( e.value ) { c.html( "Loading..." ); let subClaimDetailsContentURL = Fse.Util.updateURL2( subClaimDetailsContentURLBase, { claimContractId : e.value, contentType : "criticalIssues" } ); $.ajax( { dataType : "html", url : subClaimDetailsContentURL, success : function( data, textStatus, jqXHR ) { c.html( data ); } }) } else { c.html( "" ); } } } ); return c; } }, { itemType : "group", items : [ { colSpan : 1, colCount : 2, alignItemLabels : false, itemType : "group", items : [ { dataField : "firstDate", editorType : "dxDateBox", label : { text : "Period From" } }, { dataField : "lastDate", editorType : "dxDateBox", label : { text : "Period To" } }, ] }, { dataField : "status", label : { text : "Payment Status" }, editorType : "dxSelectBox", editorOptions : { displayExpr : "display", valueExpr : "value", items : [ { value : "OPEN", display : "In Process" } ] } }, { dataField : "claimTotal", editorType : "dxNumberBox", editorOptions : { inputAttr: { style : "text-align:right" }, readOnly : true, format : { type : "fixedPoint", precision : 2 } }, label : { text : "Claimed Amount" } }, { dataField : "verifiedTotal", editorType : "dxNumberBox", editorOptions : { inputAttr: { style : "text-align:right" }, readOnly : true, format : { type : "fixedPoint", precision : 2 } }, label : { text : "Verified Amount" } }, { dataField : "variance", editorType : "dxNumberBox", editorOptions : { inputAttr: { style : "text-align:right" }, readOnly : true, format : { type : "fixedPoint", precision : 2 } }, label : { text : "Variance" } } ] } ] }, { itemType : "group", items : [ { dataField : "claimContractPrepareComment", label : { text : "Prepare Comments", location: "top" }}, { dataField : "claimContractStatusComment", label : { text : "Audit Comments", location: "top" }}, { template : function( options ) { let claimTagsURL = Fse.Util.updateURL2( $("#PortalDocRootURL").attr( "href" ) + "/apps/TPM/index.cfm", { ajax : "claimTags", mode : "direct", claimId : claimEditorOptions.claimId, contractNbr : claimEditorOptions.contractNbr } ); let c = $("
") .attr( "id", "claimTagsSocket" ) .attr( "fse:src", claimTagsURL ) .html( "Loading..."); $.ajax( { dataType : "html", url : c.attr( "fse:src" ), success : function( data, textStatus, jqXHR ) { c.html( data ); } }) return c; }, label : { text : "Tags", location: "top" }} ] } ] }).appendTo( $("#claimEditor") ).dxForm( "instance" ); // javascript:Fse.TPM.editClaimTags(336786,'Foodbuy Members') let processResult = function( result ) { let notifyOptions = { message : result.message, closeOnClick : true, closeOnClickOutside : false, onHidden : function( e ) { if( result.go == "reload" ) { DevExpress.ui.notify( "Reloading...", "info", 4000 ); window.location.reload(); } else if ( result.go == "returnURL" ) { window.location.href = claimEditorOptions.returnURL; } else if( result.go != "" ){ if( ! result.success ) { DevExpress.ui.notify( "Redirecting...", "info", 4000 ); } window.location.href = result.go; } } }; if( result.success ) { DevExpress.ui.notify( notifyOptions, "info", 3000 ) } else { DevExpress.ui.notify( notifyOptions, "warning", 3000 ) } } let saveClaim = function() { let claimStatusFormData = claimStatusForm.option( "formData" ); let method = "POST"; let url = Fse.Util.updateURL2( handlerURL, { "do" : "saveClaimEditor", savePart : "claim", claimId : claimStatusFormData.claimId, clearingTs : claimStatusFormData.clearingTs } ); let d = $.Deferred(); $.ajax(url, { method: "POST", data: { claim : JSON.stringify( claimStatusFormData ) }, cache: false }).then(function (result) { processResult( result ); // success d.resolve(method === "GET" ? result.data : result); }, function (xhr) { alert( "error occurred" ); // failure d.reject(xhr.responseJSON ? xhr.responseJSON.Message : xhr.statusText); }); $.when( d.promise() , function( ) { alert( "All Done!!" ); } ); } let saveSubClaim = function() { let podGrid = proofOfDeliveryGrid; let changes = podGrid.option( "editing" ).changes; subClaimDetailsForm.updateData( "podChanges", changes ); let formData = subClaimDetailsForm.option( "formData" ); let method = "POST"; let url = Fse.Util.updateURL2( handlerURL, { "do" : "saveClaimEditor", savePart : "subClaim", claimId : formData.claimId, clearingTs : formData.clearingTs } ); let d = $.Deferred(); $.ajax(url, { method: "POST", data: { subClaim : JSON.stringify( formData ) }, cache: false }).then(function (result) { // success // podGrid.cancelEditData(); // claimContractsDataSource.load(); podGrid.refresh(true).done(function() { podGrid.cancelEditData(); }); processResult( result ); d.resolve(method === "GET" ? result.data : result); }, function (xhr) { alert( "error occurred" ); // failure d.reject(xhr.responseJSON ? xhr.responseJSON.Message : xhr.statusText); }); $.when( d.promise() , function( ) { alert( "All Done!!" ); } ); }; let showSubClaim = function( subClaimData ) { let formData = { claimId : null, payableTo : null, claimType : null, clearingTs : null, claimContractId : null, contractNbr : null, firstDate : null, lastDate : null, status : null, claimTotal : 0.0, verifiedAmount : 0.0, variance : 0.0, purchasingMonthStart : null, purchasingMonthEnd : null, purchasingMonths : null } let contractNbr = 'WILL NOT FIND'; if( subClaimData.claimContractId ) { contractNbr = subClaimData.contractNbr; formData.claimId = subClaimData.claimId; formData.claimContractId = subClaimData.claimContractId; formData.contractNbr = subClaimData.contractNbr; formData.firstDate = subClaimData.firstDate; formData.lastDate = subClaimData.lastDate; formData.status = subClaimData.status; formData.payableTo = subClaimData.claimPartnerType, formData.claimType = subClaimData.claimType, formData.clearingTs = subClaimData.clearingTs, formData.requestId = subClaimData.requestId, formData.claimContractStatusComment = subClaimData.claimContractStatusComment, formData.claimContractPrepareComment = subClaimData.claimContractPrepareComment } if( subClaimDetailsForm ) { subClaimDetailsForm.option( "visible", true ); subClaimDetailsForm.updateData( formData ); } // let proofOfDeliveryGrid = $("#proofOfDeliveryGrid").dxDataGrid( "instance" ); if( proofOfDeliveryGrid ) { proofOfDeliveryGrid.option( "visible", true ); let proofOfDeliveryURL = Fse.Util.updateURL2( dataURL, { contractNbr : contractNbr } ); let proofOfDeliveryDataSource = Fse.Data.createDataSource( { paginate : false, customStore : { dataURL : proofOfDeliveryURL, object : "proofOfDelivery", key : "proofOfDeliveryId" }, onLoadingChanged : function( isLoading ) { if( ! isLoading ) { updateClaimTotals();// alert( this.isLoaded() ); } } } ); proofOfDeliveryGrid.option( "dataSource", proofOfDeliveryDataSource ); } }; let updateClaimTotals = function() { let g = proofOfDeliveryGrid; // $("#proofOfDeliveryGrid").dxDataGrid("instance"); if( ! g ) { return; } //let claimedTotal = g.getTotalSummaryValue("claimedTotal"); //let contractTotal = g.getTotalSummaryValue("contractTotal"); let verifiedTotal = g.getTotalSummaryValue("approvedAmount"); let totalClaim = g.getTotalSummaryValue( "totalRebate" ); let variance = totalClaim - verifiedTotal;// g.getTotalSummaryValue( "varianceAmount" ) subClaimDetailsForm.updateData( { claimTotal : totalClaim, verifiedTotal : verifiedTotal, variance : variance } ); } proofOfDeliveryGrid = $("
").dxDataGrid( { editing : { allowUpdating : claimEditorOptions.readOnly ? false : claimEditorOptions.mode == "audit" ? true : false, mode : "batch" }, elementAttr : { class : "claimEditor-proofOfDeliveryDataGrid" }, visible : false, height : 600, scrolling : { mode : "virtual" }, headerFilter : { visible : false }, filterRow : { visible : false }, columns : [ { dataField : "distributorName", allowEditing : false, allowHeaderFiltering : true, caption : "Distributor", dataType : "string" }, { dataField : "operatorName", allowEditing : false, allowHeaderFiltering : false, caption : "Operator Location", dataType : "string" }, { dataField : "itemCode", allowEditing : false, allowHeaderFiltering : true, caption : "Item Code", dataType : "string" }, { dataField : "itemDescription", allowEditing : false, allowHeaderFiltering : false, caption : "Item Description", dataType : "string" }, { dataField : "itemQty", dataType : "number", allowEditing : false, format : { type : "fixedPoint", precision : 4 }, allowHeaderFiltering : false, caption : "Claimed Qty" }, { dataField : "rebateUnitPrice", caption : "Claimed Rate", dataType : "number", allowEditing : false, format : { type : "fixedPoint", precision : 4 }, allowHeaderFiltering : false }, { dataField : "totalRebate", caption : "Claimed Amt", dataType : "number", allowEditing : false, format : { type : "fixedPoint", precision : 4 }, allowHeaderFiltering : false, cellTemplate : function( container, cellOptions ) { container.append( cellOptions.text ); if( cellOptions.data.status == "CLAIM" ) { container.css( "color", "blue" ); } else if ( cellOptions.data.status == "DENIED" ) { container.css( "color", "red" ); } else { container.css( "color", "initial" ); } } }, { dataField : "perContractRate", caption : "Qualified Rate", dataType : "number", allowEditing : false, format : { type : "fixedPoint", precision : 4 }, allowHeaderFiltering : false }, { dataField : "perContractQualifiedAmount", caption : "Qualified Amt", dataType : "number", allowEditing : false, format : { type : "fixedPoint", precision : 4 }, allowHeaderFiltering : false, cellTemplate : function( container, cellOptions ) { container.append( cellOptions.text ); if( cellOptions.data.status == "CONTRACT" ) { container.css( "color", "blue" ); } else if ( cellOptions.data.status == "DENIED" ) { container.css( "color", "red" ); } else { container.css( "color", "initial" ); } } }, { name : "varianceAmount", caption : "Variance", calculateCellValue : function( rowData ) { return rowData.totalRebate - rowData.perContractQualifiedAmount; }, format : { type : "fixedPoint", precision : 4 }, allowHeaderFiltering : false }, { dataField : "status", dataType : "string", allowEditing : true, lookup : { dataSource : [ { value : "CLAIM", display : "CLAIM" }, { value : "CONTRACT", display : "CONTRACT" }, { value : "DENIED", display : "DENY" } ], displayExpr : "display", valueExpr : "value" }, allowHeaderFiltering : true, allowFiltering : false }, { name : "approvedAmount", caption : "Approved", calculateCellValue : function( rowData ) { if( rowData.status == "CLAIM" ) { return rowData.totalRebate; } else if ( rowData.status == "CONTRACT" ) { return rowData.perContractQualifiedAmount; } else { return 0.0; } }, format : { type : "fixedPoint", precision : 4 }, allowHeaderFiltering : false }, { dataField : "flagComment", caption : "Critical Issue", allowHeaderFiltering : true, allowFiltering : true } ], summary : { recalculateWhileEditing : true, calculateCustomSummary : function ( summaryOptions ) { if( summaryOptions.name == "claimedTotal" ) { switch( summaryOptions.summaryProcess ) { case "start" : summaryOptions.totalValue = 0.0; break; case "calculate" : if( summaryOptions.value.status == "CLAIM" ) { summaryOptions.totalValue = summaryOptions.totalValue + summaryOptions.value.totalRebate; } break; case "finalize" : updateClaimTotals(); break; } } }, totalItems : [ { column : "itemQty", summaryType : "sum", displayFormat : "{0}", valueFormat : { type : "fixedPoint", precision : 4 } }, { column : "totalRebate", summaryType : "sum", displayFormat : "{0}", valueFormat : { type : "fixedPoint", precision : 4 } }, { column : "perContractQualifiedAmount", summaryType : "sum", displayFormat : "{0}", valueFormat : { type : "fixedPoint", precision : 4 } }, { column : "varianceAmount", summaryType : "sum", displayFormat : "{0}", valueFormat : { type : "fixedPoint", precision : 4 } }, { column : "approvedAmount", summaryType : "sum", displayFormat : "{0}", valueFormat : { type : "fixedPoint", precision : 4 } }, // this custom total drives the update of the claim totals in the sub-claim portion of the screen { name : "claimedTotal", summaryType : "custom", displayFormat : "{0}", valueFormat : { type : "fixedPoint", precision : 4 } } ] }, //dataSource : proofOfDeliveryDataSource, onToolbarPreparing : function( e ) { let toolbarItems = e.toolbarOptions.items; toolbarItems.forEach(function(item) { if (item.name === "saveButton") { item.options = { visible : false, icon: "save", onClick: function(e) { // Implement custom save logic here } } } }); /* toolbarItems.push( { location : "before", widget : "dxButton", options : { text : "Edit Claim Tags", onClick : function( e ) { Fse.TPM.editClaimTags(claimId,claimEditorOptions.contractNbr) } }}); */ toolbarItems.push( { location : "after", disabled : claimEditorOptions.readOnly ? true : claimEditorOptions.mode != "audit" ? true : false, widget : "dxSelectBox", options : { items : [ "CLAIM", "CONTRACT", "DENIED" ], placeholder : "Change Status for All", onValueChanged : function( e ) { if( ! proofOfDeliveryGrid ) { return; } if( ! e.value ) { return; } if( ! confirm( "Change All Proof of Delivery records to '" + e.value + "', changes cannot be undone?" )) { e.component.option( "value", null ); return; } /* changing through the grid doesn't work well let currentPageIndex = proofOfDeliveryGrid.pageIndex(); let pageCount = proofOfDeliveryGrid.pageCount(); // for this to work, scrolling mode must not be infinite let totalCount = proofOfDeliveryGrid.totalCount(); proofOfDeliveryGrid.beginUpdate(); for( p = 0; p < pageCount; p++ ) { proofOfDeliveryGrid.pageIndex( p ).done ( function () { let rows = proofOfDeliveryGrid.getVisibleRows(); rows.forEach( function ( row ) { proofOfDeliveryGrid.cellValue( row.rowIndex, "status", e.value ); } ); } ); } proofOfDeliveryGrid.pageIndex( currentPageIndex ).done( function() { proofOfDeliveryGrid.endUpdate(); }); */ e.component.option( "value", null ); } } }); toolbarItems.push ( { location : "after", disabled : false, // claimEditorOptions.readOnly ? true : claimEditorOptions.mode != "audit" ? true : false, widget : "dxButton", options : { text : "Create Task", onClick : function( e ) { Fse.WRK.addTask(claimId,'TMC',null,null,81,{contractNbr:claimEditorOptions.contractNbr}); } } }); }, xonSaving: function(e) { if (e.changes[0]) { e.cancel = true; e.promise = saveChanges( e.changes) .always(function() { alert( "Finished") }) .then(function(data) { e.component.refresh(true).done(function() { e.component.cancelEditData(); }); /* var orders = e.component.option("dataSource"); if(change.type === "insert") { change.data = data; } orders = DevExpress.data.applyChanges(orders, [change], { keyExpr: "OrderID" }); e.component.option({ dataSource: orders, editing: { editRowKey: null, changes: [] } }); */ }); } } }).appendTo( "#claimEditor" ).dxDataGrid( "instance" ); xsaveChanges = function( changes ) { let d = $.Deferred(); let method = "POST"; let url = Fse.Util.updateURL2( handlerURL, { "do" : "epodTest", claimId : claimId } ); $.ajax(url, { method: "POST", data: { data : JSON.stringify(changes) }, cache: false }).then(function (result) { d.resolve(method === "GET" ? result.data : result); }, function (xhr) { d.reject(xhr.responseJSON ? xhr.responseJSON.Message : xhr.statusText); }); return d.promise(); } junk = function() { proofOfDeliveryGrid.beginUpdate(); let currentPageIndex = proofOfDeliveryGrid.pageIndex(); let pageCount = proofOfDeliveryGrid.pageCount(); // for this to work, scrolling mode must not be infinite /* proofOfDeliveryGrid.pageIndex( pageCount - 1 ).done( function() { alert( "On Page " + proofOfDeliveryGrid.pageIndex() ); }) */ let workers = []; for( p = 0; p < pageCount; p++ ) { let px = p; let startRow = px * proofOfDeliveryGrid.pageSize(); let worker = function( ) { let dfd = $.Deferred(); proofOfDeliveryGrid.pageIndex( px ).done ( function () { for( r = 0; r < proofOfDeliveryGrid.pageSize(); r++ ) { proofOfDeliveryGrid.cellValue( startRow + r, "status", e.value ); } alert( "Page Idx: " + proofOfDeliveryGrid.pageIndex() + " is done!" ); dfd.resolve(); } ); return dfd.promise(); } workers.push( worker ); if( workers.length == 5 ) { break; } } workers.push( function() { let dfd = $.Deferred(); proofOfDeliveryGrid.pageIndex( currentPageIndex ).done( function() { proofOfDeliveryGrid.endUpdate(); alert( "all done" ); dfd.resolve(); }) return dfd.promise(); }); // $.sequence( workers ) // let _sequence = function (chain, continueOnFailure) { var handleStep, handleResult, steps = chain, def = new $.Deferred(), defs = [], results = []; handleStep = function () { if (!steps.length) { def.resolveWith(defs, [ results ]); return; } var step = steps.shift(), result = step(); handleResult( $.when(result).always(function () { defs.push(this); }).done(function () { results.push({ resolved: arguments }); }).fail(function () { results.push({ rejected: arguments }); }) ); }; handleResult = continueOnFailure ? function (result) { result.always(function () { handleStep(); }); } : function (result) { result.done(handleStep) .fail(function () { def.rejectWith(defs, [ results ]); }); }; handleStep(); return def.promise(); }; // _sequence( workers, true ); /* let d = $.deferred(); for( p = 0; p < pageCount; p++ ) { proofOfDeliveryGrid.pageIndex( p ).done ( function () { for( r = 0; r < proofOfDeliveryGrid.pageSize(); r++ ) { proofOfDeliveryGrid.cellValue( r, "status", e.value ); } } ); } proofOfDeliveryGrid.pageIndex( currentPageIndex ).done( function() { proofOfDeliveryGrid.endUpdate(); }); */ /* let items = proofOfDeliveryGrid.getDataSource().items(); items.forEach( function( d ) { let rx = proofOfDeliveryGrid.getRowIndexByKey( d.proofOfDeliveryId ); if( rx != -1 ) { proofOfDeliveryGrid.cellValue( rx, "status", e.value ); } }) */; /* let totalCount = proofOfDeliveryGrid.totalCount() alert( totalCount ); for( x = 0; x < totalCount; x++ ) { proofOfDeliveryGrid.cellValue( x, "status", e.value ); } */ // put it back on the correct page // proofOfDeliveryGrid.pageIndex( currentPageIndex ); // proofOfDeliveryGrid.endUpdate(); } window._test = function() { let g = $("#proofOfDeliveryGrid").dxDataGrid("instance"); /* let totalCount = g.totalCount() g.beginUpdate(); for( x = 0; x < totalCount; x++ ) { g.cellValue( x, "status", "DENIED" ); } g.endUpdate(); */ /* //alert( g.getTotalSummaryValue("claimedTotal") ); //alert( g.getTotalSummaryValue("contractTotal") ); //alert( g.getTotalSummaryValue("deniedTotal") ); // let g = $("#proofOfDeliveryGrid").dxDataGrid("instance"); let claimedTotal = g.getTotalSummaryValue("claimedTotal"); let contractTotal = g.getTotalSummaryValue("contractTotal"); let verifiedTotal = g.getTotalSummaryValue("approvedAmount"); // let deniedTotal = g.getTotalSummaryValue("deniedTotal"); let totalClaim = g.getTotalSummaryValue( "totalRebate" ); let variance = totalClaim - verifiedTotal;// g.getTotalSummaryValue( "varianceAmount" ) $("#claimTotal").html( totalClaim ); $("#verifiedTotal").html( verifiedTotal ); $("#variance").html( variance ); //http://dev.fsenablers.com/fse/salesteamportal/starkist/apps/TPM/index.cfm?view=claim&claimId=288487&contractNbr=T1Z00MGY%5FEDI279238&returnURL= */ } }