import { GRID_TYPE } from "./global.const"; declare var CONFIG: any; const moment = require('moment').default || require('moment'); export class AgGridUtils { static anomalyIconSets(params) { switch (params.value) { case '1': return ''; case '0': return ``; default: return ``; } } static anomalyIconSetsDetails(params) { return ' '; } // Below is not used anymore, but leaving this commented out in code // May be we might need it in future. // static calculateAutoHeightForDetails(params, timePeriodLength) { // if (params.node && params.node.detail) { // const offset = 0; // const sizes = params.api.getSizesForCurrentTheme(); // const totalNumberOfRows = params.node.data.period_weekly.length; // const allDetailRowHeight = totalNumberOfRows * sizes.rowHeight + offset; // return allDetailRowHeight; // } // } static setDomLayout(params) { params.api.setDomLayout('autoHeight'); } static getDetailedRowData(params, data, columnDefs, gridApi?) { data.forEach(element => { // Hack Below to Remove Accuracy and Bias from Toggled Children Periods // Have to do this post Rules Filter Application to avoid System Crash element[columnDefs[11].field] = ''; element[columnDefs[12].field] = ''; }); params.data.period_weekly = data; params.successCallback(params.data.period_weekly); } static flagsIconSets(params, config, i18n) { switch (params.data.measure) { // changed img path as /home to utilise the image from different apps case 'Planner Code Flag': if (params.value > 1) { return ''; } else if (params.value === '1') { return ''; } else if (params.value === '0') { return ''; } else { return ''; } case 'Promo Flag': if (params.value === '') { return ''; } else if (params.value === '0') { return ''; } else if (params.value === undefined) { return ''; } else { return ''; } case 'Anomaly Flag': if (params.value === '1') { return ''; } else { return ''; } break; case 'Imputed Flag': if (params.value === '1') { return ''; } else { return ''; } default: return params.value; } } static cellStyle(params) { if (params.data.type === 'number' && params.data.edit) { return { 'justify-content': 'flex-end', textAlign: 'right', background: '#f2f4f5bf', height: '3.4rem', bottom: '0.5rem', 'line-height': '2', }; } else if (params.data.type === 'number' && !params.data.edit) { return { 'justify-content': 'flex-end', textAlign: 'right' }; } else { return { 'justify-content': 'center', textAlign: 'center' }; } } static editableCell(params) { return params.data.edit; } static orderingGridHasValue(params) { const colDefKey = params.colDef.field; // HardCoding Below please remove if (colDefKey === 'Order' || colDefKey === 'Diff' || colDefKey === 'Display' || colDefKey === 'Plan') { return 'ag-ordering-cell-white ag-cell-override-normal'; } const rowId = params.data.Customer; if (colDefKey === 'Final1' || colDefKey === 'Final2' || colDefKey === 'Final3') { return 'ag-ordering-cell-white ag-cell-override-bold ag-border-week-separator'; } if (rowId === '' || rowId === 'TOTAL' || colDefKey === 'Final4') { return 'ag-ordering-cell-white ag-cell-override-bold'; } // HardCoding Ends switch (params.data[colDefKey].status) { case 'normal': return 'ag-normal ag-cell-override-normal'; case 'late': return 'ag-late ag-cell-override-normal'; case 'changed': return 'ag-changed ag-cell-override-normal'; case 'edited': return 'ag-edited ag-cell-override-normal'; case 'edited late': return 'ag-late ag-edited ag-cell-override-normal'; case 'edited normal': case 'edited edited normal': return 'ag-normal ag-edited ag-cell-override-normal'; case 'archived': return 'ag-archive ag-cell-override-italic'; case 'locked': return 'ag-ordering-cell-grey ag-cell-override-normal'; case 'totals': return 'ag-ordering-cell-white ag-cell-override-bold'; case 'total': return 'ag-ordering-cell-white ag-cell-override-bold'; } return 'ag-ordering-cell-white ag-cell-override-normal'; } static orderingGridDayAvailableForOrder(params) { const currentDate = moment().format('MM/D/YYYY'); if (params.colDef.field === 'Final1' || params.colDef.field === 'Final2' || params.colDef.field === 'Final3') { return 'ag-enabled ag-border-week-separator ' + (params.colDef.field === currentDate ? 'ag-current-date' : ''); } if (!params.colDef.available && params.colDef.field === currentDate) { return 'ag-current-date ag-disable'; } else if (!params.colDef.available) { return 'ag-disable'; } else { if (params.colDef.field === currentDate) { return 'ag-current-date ag-enabled'; } else { return 'ag-enabled'; } } } static isOverThreshold(threshold, orderThreshold, newValue, oldValue): boolean { // Below is to handle situations where 0 is treated as 1 to handle the threshold pop up oldValue === 0 ? (oldValue = 1) : (oldValue = oldValue); const maxValueAdd = oldValue * (threshold / 100); const maxValueThreshold = maxValueAdd; if ((maxValueAdd !== 0 && newValue > maxValueThreshold) || newValue >= orderThreshold) { return true; } else { return false; } } static orderDiffCellRender(params) { const colDefKey = params.colDef.field; const value = params.data[colDefKey].value; const status = params.data[colDefKey].status; if (value === 0) { return value; } if (status === 'up') { return '▲' + value; } else { return '▽' + Math.abs(value); } } static orderingGridCellRender(params) { const cofDef = params.colDef.field; const promo = params.colDef.promoKey ? params.data[params.colDef.promoKey] : params.data.activePromotion[cofDef]; const comment = params.colDef.commentKey ? params.data[params.colDef.commentKey] : params.data.activeComment[cofDef]; const error = params.colDef.notificationKey ? params.data[params.colDef.notificationKey] : params.data.activeAlert[cofDef]; const gridValue = (params.value === null) ? '' : params.value; let icons = ''; if (promo) { icons = icons + ''; } if (comment) { icons = icons + ''; } if (error) { if (params.data.customers === 'Total') { icons = icons + ''; } else { icons = icons + ''; } } return icons + gridValue; } static orderingGridCellRenderNonOrders(params) { const comment = params.data[params.colDef.commentKey] ; const gridValue = (params.value === null) ? '' : params.value; let icons = ''; if (comment) { icons = icons + ''; } return icons + gridValue; } static orderingGridCustomerRender(params) { const colId = params.colDef.field; const paramsValue = params.value; // HardCoding below Please remove if (colId !== 'Customer') { return paramsValue; } if (colId === 'Customer' && (paramsValue === '' || paramsValue === 'TOTAL')) { return paramsValue; } if (params.data.activeCustomerPromotion && params.data.activeCustomerComment) { return ( '' + paramsValue ); } if (params.data.activeCustomerPromotion) { return '' + paramsValue; } if (params.data.activeCustomerComment) { return '' + paramsValue; } else { return paramsValue; } } static customersCellClass(params) { if (params.value === 'TOTAL') { return 'ag-cell-override-bold'; } else { return 'ag-cell-override-normal'; } } static getStatusIcon(arg) { let iconClass = ''; switch (arg.value) { case 'fa-check': iconClass = 'success'; break; case 'fa-clock': iconClass = 'blue-clock'; break; case 'fa-times-circle': iconClass = 'danger'; break; case 'fa-exclamation-triangle': iconClass = 'warning'; break; default: break; } return arg.value !== '' ? `` : ``; } static doTransformationCalculation( selectionType: string, transformValue: number, oldValue: number, status?: string ): {} { switch (selectionType) { case 'Multiply': return { value: Math.round(oldValue * transformValue), status: 'edited' + ' ' + status, }; case 'Divide': if (transformValue === 0) { return { value: Math.round(oldValue), status: 'edited' + ' ' + status, }; } else { return { value: Math.round(oldValue / transformValue), status: 'edited' + ' ' + status, }; } case 'Add': return { value: Math.round(oldValue + transformValue), status: 'edited' + ' ' + status, }; case 'Subtract': const newValue = Math.round(oldValue - transformValue); return { value: newValue < 0 ? Math.round(oldValue) : Math.round(oldValue - transformValue), status: newValue < 0 ? status : 'edited' + ' ' + status, newValue, }; case 'Set Value': return { value: Math.round(transformValue), status: 'edited' + ' ' + status, }; } } static doTransformationCalculationForTotals( oldValue: number, oldValueTotals: number, newOrder: number, oldValueRow: number, oldValueRowTotals: number ): {} { return { newOrderTotals: { value: Math.round(oldValueTotals - oldValue + newOrder), status: 'totals', }, newOrderRow: { value: Math.round(oldValueRow - oldValue + newOrder), status: 'totals', }, newOrderRowTotals: { value: Math.round(oldValueRowTotals - oldValueTotals + (oldValueTotals - oldValue) + newOrder), status: 'totals', }, }; } static isEditableCell(params, capabilities, activeTab): boolean { // HardCoding Below please remove const userCapabilityEditKey = 'EDIT_SUGGESTED_ORDER'; const routeCapabilityKey = 'EDIT_ROUTE_BY_MATERIAL'; const colDefKey = params.colDef.field; const status = params.data[colDefKey].status; const rowTotalsKey = params.data.Customer; const nonEditableColDefKeys = ['Final1', 'Final2', 'Final3', 'Final4', 'Order', 'Diff']; const nonEditableStatusKeys = ['archived', 'locked']; if (activeTab === 2) { if (capabilities.indexOf(routeCapabilityKey) < 0) { return false; } } if (capabilities.indexOf(userCapabilityEditKey) < 0) { return false; } if ( nonEditableColDefKeys.indexOf(colDefKey) >= 0 || rowTotalsKey === 'TOTAL' || rowTotalsKey === '' || nonEditableStatusKeys.indexOf(status) >= 0 ) { return false; } else { return true; } } static isEditableForecastCell(params): boolean { const customerKey = params.data.Customer; if (customerKey === 'TOTAL' || customerKey === '') { return false; } else { return true; } } static valueResolver(params) { const colDefKey = params.colDef.field; const value = params.data[colDefKey].value; if (value !== null) { return value; } else { return ''; } } static getParsedInlineEditingNewOrder(params, colId, newValue, status, oldValue?): {} { const dayIndex = params.data[colId].dayIndex; const suggested_ord = params.data[colId].suggested_ord; const weekId = params.data[colId].weekId; return { value: Number(newValue), status: 'edited' + ' ' + status, dayIndex, suggested_ord, weekId, }; } static getParsedInlineEditingNewOrderForDisplay(params): {} { const colId = params.colDef.field; const displayId = params.data[colId].displayId; const weekId = params.data[colId].weekId; return { value: params.newValue, status: 'edited', displayId, weekId, }; } static getStatusForTransformation(rowNode, colId): string { return rowNode.data[colId].status; } static valueSetterForUndoRedo(params) { if (params.newValue.status) { params.data[params.colDef.field] = params.newValue; return true; } else if (!params.newValue.status) { let index; if (params.data[params.colDef.field].status.indexOf('n') >= 0) { index = 'normal'; } else { index = 'late'; } params.data[params.colDef.field] = { value: params.newValue, status: index, }; return true; } else { return false; } } static runLogIconSet(params) { if (params.value) { return `
\`;`; } } static getHeaderComponentParams(day) { // HardCoding Below Please Remove Later const totalKeys = ['Total', 'Final', 'Sugg', 'Order', 'Plan', 'Display']; const cssItalicStyle = 'font-weight-normal font-italic'; const cssTextCenterStyle = 'font-weight-semibold text-center'; const cssTotalsStyle = 'nunito font-size-16 title-color font-weight-bold'; return { headerTitle: day.headerTitle, headerSubTitle: day.headerTitle === 'Final' ? 'Order' : day.headerSubTitle, headerSubTitleStyle: totalKeys.indexOf(day.headerTitle) >= 0 ? cssTotalsStyle : cssItalicStyle, headerTitleStyle: totalKeys.indexOf(day.headerTitle) >= 0 ? cssTotalsStyle : cssTextCenterStyle, }; } static getHeaderComponentKPISParams(kpi) { const cssStyle = 'nunito font-size-16 title-color font-weight-semibold'; return { headerTitle: kpi.headerTitle, headerSubTitle: kpi.headerSubTitle, headerSubTitleStyle: cssStyle, headerTitleStyle: cssStyle, }; } static getIsCustomerCommentsOrPromo(data: []) { return data.length > 0 ? true : false; } static getCustomerCommentsOrPromo(data = [], title) { if (data.length === 1) { return { id: data[0].id, name: data[0].content || '', title, createdAt: data[0].createdAt, createdBy: `${data[0].user.firstName} ${data[0].user.lastName}`, user: { userId: data[0].user.userId, }, }; } else { return data.map(instance => { return { id: instance.id, name: instance.content || '', title, createdAt: instance.createdAt, createdBy: `${instance.user.firstName} ${instance.user.lastName}`, user: { userId: instance.user.userId, }, }; }); } } static getStatusOfOrders(week, orderIndex, tableMeasure) { // HardCoding if and else Please remove if (week['orders'][orderIndex] === null) { return 'locked'; } const archived = week['ordersArchived'][orderIndex]; const late = week['ordersLate'][orderIndex]; const locked = week['ordersLocked'][orderIndex]; const order = week['orders'][orderIndex]; const suggested_order = week['measures'][tableMeasure.measure_name][orderIndex]; if (!archived && !late && !locked) { if (order !== suggested_order) { return 'edited normal'; } else { return 'normal'; } } if (archived) { return 'archived'; } if (late) { if (order !== suggested_order) { return 'edited late'; } else { return 'late'; } } if (locked) { return 'locked'; } } static getDataForComments(week, orderIndex, title, key) { if (week[key][orderIndex].length > 1) { const isPresent = true; const multipleData = week[key][orderIndex].map(instance => { return { id: instance.id, name: instance.content || '', title, createdAt: instance.createdAt, createdBy: `${instance.user.firstName} ${instance.user.lastName}`, user: { userId: instance.user.userId, }, }; }); return { isPresent, data: multipleData, }; } else { return { isPresent: true, data: { id: week[key][orderIndex][0].id, name: week[key][orderIndex][0].content, title, createdAt: week[key][orderIndex][0].createdAt, createdBy: `${week[key][orderIndex][0].user.firstName} ${week[key][orderIndex][0].user.lastName}`, user: { userId: week[key][orderIndex][0].user.userId, }, }, }; } } static getDataForPromos(week, orderIndex, title, key) { if (week[key][orderIndex].length > 1) { const isPresent = true; const multipleData = week[key][orderIndex].map(instance => { return { name: instance, title, }; }); return { isPresent, data: multipleData, }; } else { return { isPresent: true, data: { name: week[key][orderIndex][0], title, }, }; } } static getDataForAlerts(week, orderIndex, title, key, i18n) { if (week[key][orderIndex].length > 1) { const isPresent = true; const multipleData = week[key][orderIndex].map(instance => { return { name: i18n[instance.notificationType], title, }; }); return { isPresent, data: multipleData, }; } else { return { isPresent: true, data: { name: i18n[week[key][orderIndex][0].notificationType], title, }, }; } } static dropDownIndicationRendered(params) { if (params.data.Customer !== 'TOTAL' && params.data.externalId !== 'TOTAL' && params.data.Customer !== '') { return params.value + ''; } } static getKPICellClass(params) { return params.data.Customer === 'TOTAL' || params.data.externalId === 'TOTAL' || params.data.locationName === 'TOTAL' ? 'ag-ordering-cell-white ag-cell-override-bold' : 'ag-ordering-cell-white ag-cell-override-normal'; } static cpCellClass(params) { if (params.value === 'Sell-Thru' || params.value === 'Sell-Thru Forecast') { return 'ag-cell-override-bold notosans-overwrite '; } if ( params.data.driversPath[0] === 'Sell Thru' || (params.data.driversPath[0] === 'Sell Thru LY' && params.data.driversPath.length === 1) ) { return 'ag-cell-override-bold notosans-overwrite'; } if (params.value === 'Display' || params.value === 'Feature' || params.value === 'TPR') { return 'ag-cell-bordered-left-promotional-events '; } else if (params.value === 'Discontinuation' || params.value === 'Innovation') { return 'ag-cell-bordered-left-lifecycle-events'; } else if (params.value === 'Planning Events' || params.value === 'Local Events') { return 'ag-cell-bordered-left-manual-events'; } else if (params.value === 'A&C') { return 'ag-cell-bordered-left-miscelleneous-events'; } else { return 'ag-cell-override-normal notosans-overwrite'; } } static pbCellClass(params) { return 'ag-background-gradient '; } static cpCellClassForUplift(params, colDef) { if (colDef === '0' || colDef === 0) return 'ag-cell-override-normal ag-cell-background-editable'; else return 'ag-cell-override-normal ag-cell-background-locked'; } static cpGridValueFormatter(params) { if (params.value < 0) { const absValue = Math.abs(params.value); return '(' + Number(absValue).toLocaleString('en-GB') + ')'; } else if (params.value >= 0 && params.value !== "") { return Number(params.value).toLocaleString('en-GB'); } else return ' '; // return params.value ? Number(params.value).toLocaleString('en-GB') : ' '; } static cpGridValueGetter(params) { const colDef = params.colDef.field; return Number(params.data[colDef]); } static evGridValueFormatter(params) { return params.value ? Number(params.value) + '%' : ' '; } static evGridUpliftValueSort(params) { return Number(params.data.uplift); } static evGridValueGetter(params) { const colDef = params.colDef.field; return Math.round(params.data[colDef] * 100) / 100; } static pbGridValueFormatter(params) { return params.value ? Number(params.value).toLocaleString('en-GB') : params.value; } static pbGridValueGetter(params) { const colDef = params.colDef.field; if (params.data[colDef] !== undefined) { if (colDef === 'YOY % change' || colDef === 'Category' || colDef === 'subCategory') { return params.data[colDef]; } else { const dataString = params.data[colDef].toString(); const dataStringReplace = dataString.replace(/[^\d\.\-]/g, ''); const data = parseFloat(dataStringReplace); return data; } } } static eventTitle(params) { if (params.value === 'Display' || params.value === 'Feature' || params.value === 'TPR') { return 'Temorary Price Reduction Events'; } return ''; } // Collaborative Planning Ag Grid Utils Start here static setCellClassForPlanningWorkBook(params) { // Hard coding Below, please remove const colDef = params.colDef['field']; const colHeader = params.colDef['headerName']; let cellClass = ''; colDef === 'Month' || colDef === 'Category' || colHeader === 'Category' || colHeader === 'Product' || colDef === 'Brand' ? (cellClass = 'ag-left-align notosans-overwrite') : (cellClass = 'ag-right-align notosans-overwrite data-cell-color-overwrite'); if (colDef === 'AI Total Forecast Previous' || colDef === 'AI Total Forecast') { if (params.data !== undefined && params.data[colDef]) { const dataString = params.data[colDef].toString(); const dataStringReplace = dataString.replace(/[^\d\.\-]/g, ''); const data = parseFloat(dataStringReplace); if (data <= 0) { cellClass = `${cellClass} ag-bg-new-red`; } else if (data >= 8000000) { cellClass = `${cellClass} ag-bg-new-green`; } } } return cellClass; } static setCellStyleForPlanningWorkBook(params, time) { if (params.value === time) { return { 'border-left': 'thick solid #993399', 'padding-left': '7px' }; } } static cellStylePlanningHub() { return { 'font-family': 'NotosansFont', color: '#000000' }; } static cellStylePlanningHubAllWB() { return { 'font-family': 'NotosansFont', color: '#000000', 'text-align': 'left', 'padding-top': '0.8rem' }; } static setClassEventScope(params) { if (params.colDef['field'] === 'Event Type' || params.colDef['field'] === 'Key Figures') { return 'ag-left-align'; } return 'ag-right-align'; } static autoSizeAll(columnApi, skipHeader) { const allColumnIds = []; columnApi.getAllColumns()?.forEach(column => { allColumnIds.push(column.colId); }); columnApi.autoSizeColumns(allColumnIds, skipHeader); } static cellStyleForDriverAnalyis(params, editableRowsId, editedDriversData) { if (editableRowsId.includes(params.node.rowIndex)) { if (params.colDef.isEdit === '1' || params.colDef.isEdit === 1) return { backgroundColor: params.colDef.nonEditableCellColor }; else { if(params.colDef.field in params.data.lockChildMeasures && params.data.lockChildMeasures[params.colDef.field] === params.data['measure_name']) { params.colDef.editable = false; return { backgroundColor: params.colDef.nonEditableCellColor }; } else return { backgroundColor: params.colDef.editableCellColor }; } } } static cellEditableDrivers(params, editableRowsId) { if (editableRowsId.includes(params.node.rowIndex)) { if (params.colDef.isEdit === '1' || params.colDef.isEdit === 1) return false; else return true; } } static setEditable(params, tab) { if (params.data && (params.data.isEdit === '0' || params.data.isEdit === 0) && tab === 0) { return true; } else if (params.data && (params.data.isEdit === '1' || params.data.isEdit === 1) && tab === 0) { return false; } else { return true; } } static cellStylePlanningWorkBook(params, tab) { if (params.data && (params.data.isEdit === '0' || params.data.isEdit === 0) && tab === 0) { return { backgroundColor: '#E0EEFC' }; } else if (params.data && (params.data.isEdit === '1' || params.data.isEdit === 1) && tab === 0) { return { backgroundColor: '#F2F3F6' }; } else { return { backgroundColor: '#E0EEFC' }; } } static isEditableCellPlanningWorkBook(params, monthRightClicked, tab) { // Some HardCoding Below please fix if (tab === 0) { if (params.data) { if ( params.data.id === '20-Dec' || params.data.id === '21-Jan' || params.data.id === '21-Feb' || params.data.id === '21-Mar' ) { return true; } else { return false; } } } else { if (monthRightClicked.length === 0) { return false; } else { return true; } } } static isEditableCellEventConsole(params, colDef) { if (colDef === '0' || colDef === 0) return true; else return false; } static fitToGrid(params, appConfig) { if (params.api.columnController.columnDefs.length <= 9) { return params.api.sizeColumnsToFit(); } else { return AgGridUtils.autoSizeAll(params.columnApi, false); } } static rightAlignNumbers(params, config, isGreyRows?) { let cellClass = ''; if (isGreyRows) { cellClass = 'grey-rows '; } if (config['textAlign']) { cellClass += config['textAlign']; } else { if ( params.data?.measure === 'Planner Code Flag' || params.data?.measure === 'Promo Flag' || params.data?.measure === 'Anomaly Flag' || params.data?.measure === 'Imputed Flag' ) { cellClass += ' ag-center-align'; } else { cellClass += ' ag-right-align'; } } return cellClass; } static highlightingSenseCheck(params, config?) { const colDef = params.colDef['field']; let measureToUseForHighlight; let refMeasureToUseForHighlight; let valueForMeasure; let refValueForMeasure; let exceedValue; let maxPercent; if (config[7].detail && colDef === config[7].measure) { maxPercent = Number(config[7].detail['max-percent']); measureToUseForHighlight = config[7].measure; refMeasureToUseForHighlight = config[7].detail['ref-measure']; valueForMeasure = params.data?.measureToUseForHighlight ? parseFloat(params.data[measureToUseForHighlight].replace(/,/g, '')) : ''; refValueForMeasure = params.data?.refMeasureToUseForHighlight ? parseFloat(params.data[refMeasureToUseForHighlight].replace(/,/g, '')) : ''; if (!isNaN(valueForMeasure) && !isNaN(refValueForMeasure)) { if (refValueForMeasure !== 0) { const subtractedMeasure = (valueForMeasure - refValueForMeasure) * 100; const dividedMeasure = subtractedMeasure / refValueForMeasure; exceedValue = Math.abs(dividedMeasure); } } } if (exceedValue >= maxPercent) return { 'background-color': config[7].detail.highlight }; } static isEditableSenseCheckDetailsGrid(params, selectedVersion, latestVersion, forecastBeginsWeek, forecastLastWeek) { const isEdit = params.data.edit; const colDef = params.colDef.field; const measureName = params.data.measure_name; if ( isEdit && selectedVersion === latestVersion && measureName !== 'agg_planner_code' && colDef !== 'measure' && Number(colDef) >= Number(forecastBeginsWeek.id) && Number(colDef) <= Number(forecastLastWeek.id) ) { return true; } else { return false; } } static cellStyleForSenseCheckDetails(params, selectedVersion, latestVersion, forecastBeginsWeek, forecastLastWeek, color, editedForecastData) { const isEdit = params.data.edit; const colDef = params.colDef.field; if ( isEdit && selectedVersion === latestVersion && colDef !== 'measure' && Number(colDef) < Number(forecastBeginsWeek.id) && params.data.measure === 'Planner Code Flag' ) { if(editedForecastData.find(data => data.rowIndex === params.rowIndex && data.field === params.colDef.field)) return { backgroundColor: color, border: `1px solid ${params.colDef.editedCellBorderColor}` }; return { backgroundColor: color}; } else if ( isEdit && selectedVersion === latestVersion && colDef !== 'measure' && Number(colDef) >= Number(forecastBeginsWeek.id) && Number(colDef) <= Number(forecastLastWeek.id) && params.data.measure !== 'Planner Code Flag' ) { if(editedForecastData.find(data => data.rowIndex === params.rowIndex && data.field === params.colDef.field)) return { backgroundColor: color, border: `1px solid ${params.colDef.editedCellBorderColor}` }; return { backgroundColor: color}; } } static indentSubMeasures(params) { // HardCoding Bind with Config Later if ( params.value === 'Base Override' || params.value === 'Promo Override' || params.value === 'Base Forecast' || params.value === 'Promo Forecast' ) { return `
${params.value}
`; } else { return `
${params.value}
`; } } static senseCheckDetailsHeaderClass(params, forecastBeginsOnWeekFirstEdge, lag) { const colDef = params.colDef['field']; const colDefOrderWeek = Number(forecastBeginsOnWeekFirstEdge.id) + lag; if (colDef === forecastBeginsOnWeekFirstEdge.id) { return 'ag-header-bottom-dark-border ag-current-date'; } else if (Number(colDef) === colDefOrderWeek) { return 'ag-header-bottom-dark-border ag-current-order-date'; } else { return 'ag-header-bottom-dark-border'; } } static planningHubIconRenderer(params,iconConfig) { const selectedIcon = iconConfig.find(item=>item.title === params.value); return `
${params.value}
`; } static planningHubNameRenderer(params,columnsConfig,i18n) { const showLastModified = params.data['last_modified'] ? 'block' : 'none'; let lastModified= columnsConfig.find(item=>item.field === 'last_modified'); return `
${params.data.name}
${i18n[lastModified?.headerName] || lastModified?.headerName}: ${params.data['last_modified']}
`; } static checkCellEditable(params) { return (params?.data?.isCellEditable)? true : false; } static editedCellRender(params) { let gridValue = params.valueFormatted; const comments = params.data.comments.filter(column => column.measureName === params.colDef.field); let icons = ''; if (comments?.length && comments[0].comment.isCommentAvailable) { icons = icons + ''; if(!(comments[0].comment.isRecalculated) && comments[0].comment.value !== null){ gridValue = comments[0].comment.value === 0 ? "" : comments[0].comment.value; params.data[comments[0].measureName] = gridValue; } } return icons + gridValue; } static cellStyleForHighlight(params, tab, editedData, config, rowDataList) { const cellStyle = AgGridUtils.highlightRowColumn(params, config, rowDataList, true); return cellStyle; } static highlightRowColumn(params, config, rowData, rowGrid, editableRowsId?, editedDriversData?) { if (editableRowsId && editableRowsId.includes(params.node.rowIndex)) { if (params.colDef.isEdit === '1' || params.colDef.isEdit === 1) return { backgroundColor: '#F2F3F6' }; else { if(editedDriversData.length && editedDriversData.find(data => data.currentCell.rowIndex === params.rowIndex && data.currentCell.col === params.colDef.field)) return { backgroundColor: '#E0EEFC', border: `1px solid ${params.colDef.editedCellBorderColor}` }; return { backgroundColor: '#E0EEFC' }; } } else { const colDef = params.colDef['field']; const rowIndex = params.rowIndex; let refMeasureToUseForHighlight; let valueForMeasure; let refValueForMeasure; let refDataToUseForHighlight; let exceedValue; let maxPercent; let minPercent; let maxValue; let minValue; let forecastMeasureConfig; if (params.data.hasOwnProperty('measure_name')) { forecastMeasureConfig = config.find(item => item.measure === params.data['measure_name'] || item['measureName'] === params.data['measure_name']); } else { forecastMeasureConfig = config.find(item => item.measure === colDef || item['measureName'] === colDef); } if (forecastMeasureConfig?.['highlightDetails'] && (colDef === forecastMeasureConfig.measure || colDef === forecastMeasureConfig['measureName'] || rowIndex === params.data.id)) { maxPercent = Number(forecastMeasureConfig['highlightDetails']['maxPercent']); minPercent = Number(forecastMeasureConfig['highlightDetails']['minPercent']); maxValue = Number(forecastMeasureConfig['highlightDetails']['maxValue']); minValue = Number(forecastMeasureConfig['highlightDetails']['minValue']); refMeasureToUseForHighlight = forecastMeasureConfig['highlightDetails']['refMeasure']; refDataToUseForHighlight = rowData.find(row => rowGrid ? (row['id'] === params.data.id || row['rowId'] === params.data.rowId) : (row['measure_name'] === refMeasureToUseForHighlight)) valueForMeasure = params.data?.[colDef] ? parseFloat(params.data[colDef].toString().replace(/,/g, '')) : ''; const refValue = rowGrid ? refDataToUseForHighlight?.[refMeasureToUseForHighlight] : refDataToUseForHighlight?.[params.colDef['field']] refValueForMeasure = refValue ? parseFloat(refValue.toString().replace(/,/g, '')) : ''; if (!isNaN(valueForMeasure) && !isNaN(refValueForMeasure)) { if (refValueForMeasure !== 0) { const subtractedMeasure = (valueForMeasure - refValueForMeasure) * 100; const dividedMeasure = subtractedMeasure / refValueForMeasure; exceedValue = dividedMeasure; } } let bgColor = {}; if (exceedValue >= maxPercent || valueForMeasure >= maxValue) { bgColor = { 'background-color': forecastMeasureConfig['highlightDetails']['maxHighlightColor'] }; } else if (exceedValue <= minPercent || valueForMeasure <= minValue) { bgColor = { 'background-color': forecastMeasureConfig['highlightDetails']['minHighlightColor'] }; } return bgColor; } } } static editableCellStyleForGrid(params,timedata,filterScope,editedData=[],gridConfig, columnConfig?,rowDataList?){ if ((params.data['grid-type'] && params.data.editable) || (params.data['grid-type'] === undefined && params.colDef.editable)) { let isCellEditable = false; if (timedata) { const id = params.data['grid-type'] === GRID_TYPE.COLUMN_DIMENSIONAL || params.data['grid-type'] === GRID_TYPE.MULTI_DIMENSIONAL ? params.colDef.field : params.data.id let dimensionLevel = ''; if(params.data['grid-type'] === GRID_TYPE.COLUMN_DIMENSIONAL){ dimensionLevel = params.colDef.dimensionLevel; }else if (params.data['grid-type'] === GRID_TYPE.MULTI_DIMENSIONAL){ dimensionLevel = params.data.columnDimensionLevel; }else{ dimensionLevel = params.data.dimensionLevel } const currentTime = timedata.find(time=> time.currentTime === 1); const data = timedata.find(time => time.id === id && time.dimensionLevel === dimensionLevel); if (data) { const { pastEdit, futureEdit } = params.data['grid-type'] === GRID_TYPE.COLUMN_DIMENSIONAL ? params.data : params.colDef; isCellEditable = pastEdit && futureEdit ? true : pastEdit && data.id < currentTime.id ? true : data.edit === 1 ? true : false; } else if (filterScope) { const matchedAccordion = filterScope?.dimensionFilters.find(accordian=>accordian.dimensionColumnName === 'time'); if(matchedAccordion){ let matchedSubAccordion = matchedAccordion.and.find(subAccordian=>subAccordian.dimensionLevelColumnName === timedata[0].dimensionLevel); if(matchedSubAccordion && matchedSubAccordion.values.length > 0) { const { pastEdit, futureEdit } = params.data['grid-type'] === GRID_TYPE.COLUMN_DIMENSIONAL ? params.data : params.colDef; const isFutureTime = timedata.find(time => time.id === matchedSubAccordion.values[0] && time.edit === 1) isCellEditable = pastEdit && futureEdit ? true : pastEdit && matchedSubAccordion.values[0] < currentTime.id ? true : isFutureTime?.edit === 1 ? true : false; // we have start date and end date in pln and store details. if (matchedSubAccordion.values?.length === 2 && isCellEditable) { if(matchedSubAccordion.values[0] === matchedSubAccordion.values[1]){ isCellEditable = true; } else { isCellEditable = pastEdit && futureEdit ? true : pastEdit && matchedSubAccordion.values[1] < currentTime.id ? true : false; } } } } } } else { isCellEditable = params.colDef.editable } let commentData: any = []; if (params.data['grid-type'] === GRID_TYPE.COLUMN_DIMENSIONAL || params.data['grid-type'] === GRID_TYPE.MULTI_DIMENSIONAL) { if (params.colDef.field in params.data.lockChildMeasures && params.data.lockChildMeasures[params.colDef.field] === params.data['measure_name']) { isCellEditable = false; } if (params.colDef.field in params.data.comments) { commentData.push(params.data.comments[params.colDef.field]); } } else { if(params.data.lockChildMeasures?.includes(params.colDef.field)) { isCellEditable = false; } commentData = params.data.comments?.filter(column => column.measureName === params.colDef.field); } const isCellEdited = commentData?.length > 0 && (commentData[0]?.comment.isCommentAvailable === true) && !(commentData[0]?.comment.isRecalculated)? true : false; // check is cell edited if(params.data['grid-type'] === GRID_TYPE.COLUMN_DIMENSIONAL || params.data['grid-type'] === GRID_TYPE.MULTI_DIMENSIONAL){ params.colDef['editable'] = isCellEditable; } params.colDef['isCellEditable'] = isCellEditable; params.data.isCellEditable = isCellEditable; // set cell edtiable return isCellEditable ? { backgroundColor: gridConfig.editableCellColor, border: isCellEdited ? `1px solid ${gridConfig.editedCellBorderColor}` : '' } : { backgroundColor: gridConfig.nonEditableCellColor, pointerEvents: 'none' } } else if(columnConfig && rowDataList) { const cellStyle = this.cellStyleForHighlight(params, null, null, columnConfig,rowDataList); return cellStyle; } } static setGridHeight(minHeight: number, rowHeight: number, totalRows: number) { const MIN_HEIGHT = '150px'; const HEADER_HEIGHT = 48; let gridHeight = ''; if (totalRows) { if (totalRows * rowHeight < minHeight) { gridHeight = minHeight + HEADER_HEIGHT + 'px'; } else { gridHeight = (totalRows + 1) * rowHeight + HEADER_HEIGHT + 'px'; } } else { gridHeight = MIN_HEIGHT; } return gridHeight; } static isCellEditable(params, editableRowsId ,cellEditableDrivers?) { //cellEditableDrivers is used only for driver workbook if (editableRowsId.includes(params.node.rowIndex)) { let isCellEditable = true; if(cellEditableDrivers?.length){ if (cellEditableDrivers.includes(params.node.data['measure_name'])){ isCellEditable = false; } } // bellow code is used for column dimensional grid cell edit(segway) if (!cellEditableDrivers && (params.colDef.isEdit === '1' || params.colDef.isEdit === 1)){ isCellEditable = false; } return isCellEditable; } } static columnDimGridCellRender(params) { let gridValue = params.valueFormatted; let icons = ''; if(params.colDef.field in params.data.comments){ const comment = params.data.comments[params.colDef.field].comment; if(comment.isCommentAvailable){ icons = icons + ''; if (!(comment.isRecalculated) && comment.value !== null) { gridValue = comment.value === 0 ? "" : comment.value; params.data[params.colDef.field] = gridValue; } } } return icons + gridValue; } static cpDashboardChartValueFormatter(value: any, config: any, formCol: any) { if (formCol.config.chartFormat.decimal.includes(config.name)) { if (value < 0) { return Number(value).toFixed(2); } else if (value) { return Number(Math.round(value * 100) / 100); } else return; } else { if (value < 0) { return Number(Math.round(value)); } else if (value) { return Number(Math.round(value)); } else return; } } static cpDashboardGridValueFormatter(params, formCol) { if (formCol.config.cellFormat.decimal.includes(params.data.measure)) { if (params.value < 0) { const absValue = Math.abs(params.value); return formCol.config.cellFormat.percent.includes(params.data.measure) ? '(' + Number(Math.round(absValue * 100) / 100).toLocaleString('en-GB') + '%)' : '(' + Number(Math.round(absValue * 100) / 100).toLocaleString('en-GB') + ')'; } else if (params.value) { return formCol.config.cellFormat.percent.includes(params.data.measure) ? Number(Math.round(params.value * 100) / 100).toLocaleString('en-GB') + '%' : Number(Math.round(params.value * 100) / 100).toLocaleString('en-GB'); } else return ' '; } else { if (params.value < 0) { const absValue = Math.abs(params.value); return formCol.config.cellFormat.percent.includes(params.data.measure) ? '(' + Number(Math.round(absValue)).toLocaleString('en-GB') + '%)' : '(' + Number(Math.round(absValue)).toLocaleString('en-GB') + ')'; } else if (params.value) { return formCol.config.cellFormat.percent.includes(params.data.measure) ? Number(Math.round(params.value)).toLocaleString('en-GB') + '%' : Number(Math.round(params.value)).toLocaleString('en-GB'); } else return ' '; } } static dashboardCellStyle(params, config) { if (config !== undefined && config.options) { for (const element of config.options) { if (element.label === params.data.measure && (element.minValue || element.maxValue) && params.value) { if (element.minValue && params.value < element.minValue) { return { backgroundColor: element.minColor }; } if (element.maxValue && params.value > element.maxValue) { return { backgroundColor: element.maxColor }; } } } } } }