@undp/carbon-library 1.0.135-ghg-inventory.12.19 → 1.0.135-ghg-inventory.12.21

Sign up to get free protection for your applications and to get access to all the features.
package/dist/cjs/index.js CHANGED
@@ -28910,6 +28910,48 @@ var totalProjectionFields = [
28910
28910
  'Total National Emission and Removals - Conditional NDC',
28911
28911
  'Total National Emission and Removals - Unconditional NDC',
28912
28912
  ];
28913
+ var excelFields = [
28914
+ "Energy",
28915
+ "Fuel Combustion Activities",
28916
+ "Energy Industries",
28917
+ "Manufacturing Industries and Construction",
28918
+ "Transport",
28919
+ "Other Sectors",
28920
+ "Non-Specified",
28921
+ "Fugitive emissions from fuels",
28922
+ "Solid Fuels",
28923
+ "Oil and Natural Gas",
28924
+ "Other emissions from Energy Production",
28925
+ "Carbon dioxide Transport and Storage",
28926
+ "Transport of CO2",
28927
+ "Injection and Storage",
28928
+ "Other (Carbon dioxide Transport and Storage)",
28929
+ "Industrial Processes & Product Use",
28930
+ "Mineral Industry",
28931
+ "Chemical Industry",
28932
+ "Metal Industry",
28933
+ "Non-Energy Products from Fuels and Solvent Use",
28934
+ "Electronics Industry",
28935
+ "Product Uses as Substitutes for Ozone Depleting Substances",
28936
+ "Other Product Manufacture and Use",
28937
+ "Other (Industrial Processes & Product Use)",
28938
+ "Agriculture, Forestry, and Other Land Use",
28939
+ "Livestock",
28940
+ "Land",
28941
+ "Aggregate sources and non-CO2 emissions sources on land",
28942
+ "Other (Agriculture, Forestry, and Other Land Use)",
28943
+ "Waste",
28944
+ "Solid Waste Disposal",
28945
+ "Biological Treatment of Solid Waste",
28946
+ "Incineration and Open Burning of Waste",
28947
+ "Wastewater Treatment and Discharge",
28948
+ "Other (Waste)",
28949
+ "Other",
28950
+ "Indirect N2O emissions from the atmospheric deposition of nitrogen in NOx and NH3",
28951
+ "Other",
28952
+ "Total CO2 equivalent emissions without land use, land-use change and forestry",
28953
+ "Total CO2 equivalent emissions with land use, land-use change and forestry",
28954
+ ];
28913
28955
 
28914
28956
  antd.Input.TextArea;
28915
28957
  var DiscardChangesConfirmationModel = function (props) {
@@ -29029,22 +29071,32 @@ var GHGEmissionsComponent = function (props) {
29029
29071
  for (var category in energyEmissionsSub) {
29030
29072
  var subcategory = energyEmissionsSub[category];
29031
29073
  for (var gas in subcategory) {
29032
- result["".concat(key, "_").concat(category, "_").concat(gas)] = subcategory[gas];
29074
+ result["".concat(key, "_").concat(category, "_").concat(gas)] = !isNaN(subcategory[gas]) ? subcategory[gas] : 0;
29033
29075
  }
29034
29076
  }
29035
29077
  }
29036
29078
  else {
29037
29079
  for (var gas in energyEmissionsSub) {
29038
- result["".concat(objName, "_").concat(key, "_").concat(gas)] = energyEmissionsSub[gas];
29080
+ result["".concat(objName, "_").concat(key, "_").concat(gas)] = !isNaN(energyEmissionsSub[gas]) ? energyEmissionsSub[gas] : 0;
29039
29081
  }
29040
29082
  }
29041
29083
  }
29042
29084
  }
29043
29085
  return result;
29044
29086
  };
29045
- var validateExcelDataFormat = function (sheetHeadings) {
29087
+ var validateExcelDataFormat = function (sheet, excelData) {
29088
+ var sheetHeadings = XLSX__namespace.utils.sheet_to_json(sheet, {
29089
+ header: 1,
29090
+ })[0];
29046
29091
  var columnHeadings = ['Sector', 'CO2', 'CH4', 'N2O', 'CO2-eq'];
29047
- return sheetHeadings.every(function (element) { return columnHeadings.includes(element); });
29092
+ if (!columnHeadings.every(function (element) { return sheetHeadings.includes(element); })) {
29093
+ return false;
29094
+ }
29095
+ var sectorValues = excelData.map(function (excelDataObj) { return excelDataObj.Sector; });
29096
+ if (!excelFields.every(function (element) { return sectorValues.includes(element); })) {
29097
+ return false;
29098
+ }
29099
+ return true;
29048
29100
  };
29049
29101
  var populateFormWithUploadedFile = function (excelData, keyPrefix) {
29050
29102
  var emissions = {};
@@ -29124,12 +29176,13 @@ var GHGEmissionsComponent = function (props) {
29124
29176
  var sum = 0;
29125
29177
  for (var key in obj) {
29126
29178
  if (key === gasType) {
29127
- sum += obj[key];
29179
+ sum += Number.isInteger(obj[key]) ? obj[key] : 0;
29128
29180
  }
29129
29181
  else if (typeof obj[key] === 'object' &&
29130
29182
  key !== 'totalCo2WithLand' &&
29131
29183
  key !== 'totalCo2WithoutLand') {
29132
- sum += calculateSumEmissionView(obj[key], gasType);
29184
+ var calculatedSum = calculateSumEmissionView(obj[key], gasType);
29185
+ sum += Number.isInteger(calculatedSum) ? calculatedSum : 0;
29133
29186
  }
29134
29187
  }
29135
29188
  return sum;
@@ -29447,19 +29500,6 @@ var GHGEmissionsComponent = function (props) {
29447
29500
  setOpenResetFormModal(false);
29448
29501
  };
29449
29502
  var onOpenResetFormModel = function () {
29450
- setActionInfo({
29451
- action: "".concat(t('ghgInventory:proceed')),
29452
- headerText: "".concat(t('ghgInventory:discardHeaderText')),
29453
- type: 'danger',
29454
- icon: React.createElement(icons.CloseCircleOutlined, null),
29455
- });
29456
- setErrorMsg('');
29457
- setOpenResetFormModal(true);
29458
- };
29459
- var onSaveFormCanceled = function () {
29460
- setOpenSaveFormModal(false);
29461
- };
29462
- var onOpenSaveFormModel = function () {
29463
29503
  if (!isFormChanged) {
29464
29504
  antd.message.open({
29465
29505
  type: 'error',
@@ -29470,34 +29510,98 @@ var GHGEmissionsComponent = function (props) {
29470
29510
  }
29471
29511
  else {
29472
29512
  setActionInfo({
29473
- action: "".concat(t("ghgInventory:submit")),
29474
- headerText: "".concat(t("ghgInventory:submitModelHeader")),
29475
- type: "primary",
29476
- icon: React.createElement(icons.CheckCircleOutlined, null),
29513
+ action: "".concat(t('ghgInventory:proceed')),
29514
+ headerText: "".concat(t('ghgInventory:discardHeaderText')),
29515
+ type: 'danger',
29516
+ icon: React.createElement(icons.CloseCircleOutlined, null),
29477
29517
  });
29478
29518
  setErrorMsg('');
29479
- setOpenSaveFormModal(true);
29519
+ setOpenResetFormModal(true);
29480
29520
  }
29481
29521
  };
29522
+ var onSaveFormCanceled = function () {
29523
+ setOpenSaveFormModal(false);
29524
+ };
29525
+ var onOpenSaveFormModel = function () {
29526
+ var _a = form.getFieldsValue(true); _a.year; var rest = __rest(_a, ["year"]);
29527
+ var otherFieldsNegativeValue = Object.values(rest).some(function (value) {
29528
+ return typeof value === 'number' && value < 0;
29529
+ });
29530
+ form
29531
+ .validateFields()
29532
+ .then(function (values) {
29533
+ if (!isFormChanged) {
29534
+ antd.message.open({
29535
+ type: 'error',
29536
+ content: t('ghgInventory:formNotChanged'),
29537
+ duration: 4,
29538
+ style: { textAlign: 'right', marginRight: 15, marginTop: 10 },
29539
+ });
29540
+ }
29541
+ else {
29542
+ setActionInfo({
29543
+ action: "".concat(t("ghgInventory:submit")),
29544
+ headerText: "".concat(t("ghgInventory:submitModelHeader")),
29545
+ type: "primary",
29546
+ icon: React.createElement(icons.CheckCircleOutlined, null),
29547
+ });
29548
+ setErrorMsg('');
29549
+ setOpenSaveFormModal(true);
29550
+ }
29551
+ })
29552
+ .catch(function (errorInfo) {
29553
+ if (otherFieldsNegativeValue) {
29554
+ antd.message.open({
29555
+ type: 'error',
29556
+ content: t('ghgInventory:negativeValuesNotAllowed'),
29557
+ duration: 4,
29558
+ style: { textAlign: 'right', marginRight: 15, marginTop: 10 },
29559
+ });
29560
+ }
29561
+ });
29562
+ };
29482
29563
  var onFinalizeFormCanceled = function () {
29483
29564
  setOpenFinalizeFormModal(false);
29484
29565
  };
29485
29566
  var onOpenFinalizeFormModel = function () {
29567
+ var _a = form.getFieldsValue(true); _a.year; var rest = __rest(_a, ["year"]);
29568
+ var otherFieldsEmpty = Object.values(rest).every(function (value) { return !value; });
29569
+ var otherFieldsNegativeValue = Object.values(rest).some(function (value) {
29570
+ return typeof value === 'number' && value < 0;
29571
+ });
29486
29572
  form
29487
29573
  .validateFields()
29488
29574
  .then(function (values) {
29489
29575
  // Validation successful, set ActionInfo and open the form modal
29490
- setActionInfo({
29491
- action: "".concat(t("ghgInventory:finalize")),
29492
- headerText: "".concat(t("ghgInventory:finalizeModelHeader")),
29493
- type: "primary",
29494
- icon: React.createElement(Icon.ClipboardCheck, null),
29495
- });
29496
- setErrorMsg('');
29497
- setOpenFinalizeFormModal(true);
29576
+ if (otherFieldsEmpty) {
29577
+ antd.message.open({
29578
+ type: 'error',
29579
+ content: t('ghgInventory:cannotFinaliseEmpty'),
29580
+ duration: 4,
29581
+ style: { textAlign: 'right', marginRight: 15, marginTop: 10 },
29582
+ });
29583
+ }
29584
+ else {
29585
+ setActionInfo({
29586
+ action: "".concat(t("ghgInventory:finalize")),
29587
+ headerText: "".concat(t("ghgInventory:finalizeModelHeader")),
29588
+ type: "primary",
29589
+ icon: React.createElement(Icon.ClipboardCheck, null),
29590
+ });
29591
+ setErrorMsg('');
29592
+ setOpenFinalizeFormModal(true);
29593
+ }
29498
29594
  })
29499
29595
  .catch(function (errorInfo) {
29500
29596
  // Validation failed
29597
+ if (otherFieldsNegativeValue) {
29598
+ antd.message.open({
29599
+ type: 'error',
29600
+ content: t('ghgInventory:negativeValuesNotAllowed'),
29601
+ duration: 4,
29602
+ style: { textAlign: 'right', marginRight: 15, marginTop: 10 },
29603
+ });
29604
+ }
29501
29605
  console.log('Validation failed:', errorInfo);
29502
29606
  });
29503
29607
  };
@@ -29513,7 +29617,7 @@ var GHGEmissionsComponent = function (props) {
29513
29617
  setLoading(true);
29514
29618
  _a.label = 2;
29515
29619
  case 2:
29516
- _a.trys.push([2, 6, 9, 10]);
29620
+ _a.trys.push([2, 6, 11, 12]);
29517
29621
  return [4 /*yield*/, post('national/emissions', payload)];
29518
29622
  case 3:
29519
29623
  response = _a.sent();
@@ -29540,7 +29644,7 @@ var GHGEmissionsComponent = function (props) {
29540
29644
  case 4:
29541
29645
  _a.sent();
29542
29646
  _a.label = 5;
29543
- case 5: return [3 /*break*/, 10];
29647
+ case 5: return [3 /*break*/, 12];
29544
29648
  case 6:
29545
29649
  error_1 = _a.sent();
29546
29650
  console.log('Error in emission creation - ', error_1);
@@ -29552,19 +29656,31 @@ var GHGEmissionsComponent = function (props) {
29552
29656
  duration: 4,
29553
29657
  style: { textAlign: 'right', marginRight: 15, marginTop: 10 },
29554
29658
  });
29555
- if (!(error_1.statusCode == axios.HttpStatusCode.Conflict)) return [3 /*break*/, 8];
29659
+ if (!(error_1.status === axios.HttpStatusCode.Conflict.valueOf())) return [3 /*break*/, 8];
29556
29660
  return [4 /*yield*/, getEmissionData()];
29557
29661
  case 7:
29558
29662
  _a.sent();
29663
+ setIsSavedFormDataSet(false);
29664
+ clearUploadDoc();
29665
+ if (!isPendingFinalization) {
29666
+ clearForm();
29667
+ }
29668
+ return [3 /*break*/, 10];
29669
+ case 8:
29670
+ if (!(error_1.status === axios.HttpStatusCode.Forbidden.valueOf())) return [3 /*break*/, 10];
29559
29671
  clearUploadDoc();
29560
- _a.label = 8;
29561
- case 8: return [3 /*break*/, 10];
29672
+ clearForm();
29673
+ return [4 /*yield*/, getEmissionData()];
29562
29674
  case 9:
29675
+ _a.sent();
29676
+ _a.label = 10;
29677
+ case 10: return [3 /*break*/, 12];
29678
+ case 11:
29563
29679
  // eslint-disable-next-line no-use-before-define, @typescript-eslint/no-use-before-define
29564
29680
  setIsFormChanged(false);
29565
29681
  setLoading(false);
29566
29682
  return [7 /*endfinally*/];
29567
- case 10: return [2 /*return*/];
29683
+ case 12: return [2 /*return*/];
29568
29684
  }
29569
29685
  });
29570
29686
  }); };
@@ -29802,7 +29918,6 @@ var GHGEmissionsComponent = function (props) {
29802
29918
  (formValues.fuelCombustionActivities_transport_co2 || 0) +
29803
29919
  (formValues.fuelCombustionActivities_otherSectors_co2 || 0) +
29804
29920
  (formValues.fuelCombustionActivities_nonSpecified_co2 || 0);
29805
- console.log('sum triggered', sum);
29806
29921
  setFuelCombustionActivitiesCo2(sum);
29807
29922
  }
29808
29923
  if (panelHeading === 'fugitiveEmissionsFromFuels') {
@@ -30134,17 +30249,61 @@ var GHGEmissionsComponent = function (props) {
30134
30249
  React.createElement(antd.Col, { xl: 9, md: 9 },
30135
30250
  React.createElement(antd.Row, { gutter: 16, className: "panel-content-input-box-row" },
30136
30251
  React.createElement(antd.Col, { xl: 6 },
30137
- React.createElement(antd.Form.Item, { name: panelHeading + '_' + item + '_co2' },
30138
- React.createElement(antd.InputNumber, { onChange: function (event) { return calculateSumCo2(event, panelHeading); } }))),
30252
+ React.createElement(antd.Form.Item, { name: panelHeading + '_' + item + '_co2', rules: [
30253
+ {
30254
+ validator: function (rule, value) { return __awaiter(void 0, void 0, void 0, function () {
30255
+ return __generator(this, function (_a) {
30256
+ if (value && value < 0) {
30257
+ throw new Error();
30258
+ }
30259
+ return [2 /*return*/];
30260
+ });
30261
+ }); },
30262
+ },
30263
+ ] },
30264
+ React.createElement(antd.InputNumber, { onChange: function (event) { return calculateSumCo2(event, panelHeading); }, disabled: (userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.userRole) === exports.Role.ViewOnly }))),
30139
30265
  React.createElement(antd.Col, { xl: 6 },
30140
- React.createElement(antd.Form.Item, { name: panelHeading + '_' + item + '_ch4' },
30141
- React.createElement(antd.InputNumber, { onChange: function (event) { return calculateSumCh4(event, panelHeading); } }))),
30266
+ React.createElement(antd.Form.Item, { name: panelHeading + '_' + item + '_ch4', rules: [
30267
+ {
30268
+ validator: function (rule, value) { return __awaiter(void 0, void 0, void 0, function () {
30269
+ return __generator(this, function (_a) {
30270
+ if (value && value < 0) {
30271
+ throw new Error();
30272
+ }
30273
+ return [2 /*return*/];
30274
+ });
30275
+ }); },
30276
+ },
30277
+ ] },
30278
+ React.createElement(antd.InputNumber, { onChange: function (event) { return calculateSumCh4(event, panelHeading); }, disabled: (userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.userRole) === exports.Role.ViewOnly }))),
30142
30279
  React.createElement(antd.Col, { xl: 6 },
30143
- React.createElement(antd.Form.Item, { name: panelHeading + '_' + item + '_n2o' },
30144
- React.createElement(antd.InputNumber, { onChange: function (event) { return calculateSumN2o(event, panelHeading); } }))),
30280
+ React.createElement(antd.Form.Item, { name: panelHeading + '_' + item + '_n2o', rules: [
30281
+ {
30282
+ validator: function (rule, value) { return __awaiter(void 0, void 0, void 0, function () {
30283
+ return __generator(this, function (_a) {
30284
+ if (value && value < 0) {
30285
+ throw new Error();
30286
+ }
30287
+ return [2 /*return*/];
30288
+ });
30289
+ }); },
30290
+ },
30291
+ ] },
30292
+ React.createElement(antd.InputNumber, { onChange: function (event) { return calculateSumN2o(event, panelHeading); }, disabled: (userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.userRole) === exports.Role.ViewOnly }))),
30145
30293
  React.createElement(antd.Col, { xl: 6 },
30146
- React.createElement(antd.Form.Item, { name: panelHeading + '_' + item + '_co2eq' },
30147
- React.createElement(antd.InputNumber, { onChange: function (event) { return calculateSumCo2Eq(event, panelHeading); } }))))))); };
30294
+ React.createElement(antd.Form.Item, { name: panelHeading + '_' + item + '_co2eq', rules: [
30295
+ {
30296
+ validator: function (rule, value) { return __awaiter(void 0, void 0, void 0, function () {
30297
+ return __generator(this, function (_a) {
30298
+ if (value && value < 0) {
30299
+ throw new Error();
30300
+ }
30301
+ return [2 /*return*/];
30302
+ });
30303
+ }); },
30304
+ },
30305
+ ] },
30306
+ React.createElement(antd.InputNumber, { onChange: function (event) { return calculateSumCo2Eq(event, panelHeading); }, disabled: (userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.userRole) === exports.Role.ViewOnly }))))))); };
30148
30307
  var renderPanelContentView = function (co2, ch4, n2o, co2eq, item, index) {
30149
30308
  return (React.createElement(antd.Row, { gutter: 16, key: index, className: "panel-content-row" },
30150
30309
  React.createElement(antd.Col, { xl: 12, md: 12, className: "panel-content-title" },
@@ -30206,7 +30365,7 @@ var GHGEmissionsComponent = function (props) {
30206
30365
  var encodedUri = encodeURI("data:text/csv;charset=utf-8,".concat(csvContent));
30207
30366
  var link = document.createElement('a');
30208
30367
  link.setAttribute('href', encodedUri);
30209
- link.setAttribute('download', "GHG-Reporting Emissions_".concat(dataToDownload.year, "_V").concat(dataToDownload.version, ".csv"));
30368
+ link.setAttribute('download', "GHG-Reporting-Emissions_".concat(dataToDownload.year, "_V").concat(dataToDownload.version, ".csv"));
30210
30369
  document.body.appendChild(link);
30211
30370
  link.click();
30212
30371
  };
@@ -30229,6 +30388,17 @@ var GHGEmissionsComponent = function (props) {
30229
30388
  }
30230
30389
  return false;
30231
30390
  };
30391
+ var canViewForm = function () {
30392
+ if ((userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.companyRole) === exports.CompanyRole.GOVERNMENT || (userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.companyRole) === exports.CompanyRole.MINISTRY) {
30393
+ if ((userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.userRole) === exports.Role.ViewOnly && data.some(function (item) { return item.state === 'SAVED'; })) {
30394
+ return true;
30395
+ }
30396
+ else if ((userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.userRole) !== exports.Role.ViewOnly) {
30397
+ return true;
30398
+ }
30399
+ }
30400
+ return false;
30401
+ };
30232
30402
  return (React.createElement("div", null,
30233
30403
  React.createElement("div", { className: "content-container emission-tab-container" },
30234
30404
  React.createElement("div", { className: "emission-title-bar" },
@@ -30237,8 +30407,7 @@ var GHGEmissionsComponent = function (props) {
30237
30407
  React.createElement("div", { className: "body-sub-title" }, t("ghgInventory:totalNationalEmissionSubTitle")))),
30238
30408
  React.createElement("div", { className: "content-card add-emission" },
30239
30409
  React.createElement(antd.Tabs, { defaultActiveKey: "Add New", centered: true },
30240
- ((userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.companyRole) === exports.CompanyRole.GOVERNMENT ||
30241
- (userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.companyRole) === exports.CompanyRole.MINISTRY) && (React.createElement(antd.Tabs.TabPane, { key: "Add New", tab: t("ghgInventory:addNew") },
30410
+ (canViewForm()) && (React.createElement(antd.Tabs.TabPane, { key: "Add New", tab: t("ghgInventory:addNew") },
30242
30411
  React.createElement("div", null,
30243
30412
  React.createElement(antd.Form, { labelCol: { span: 20 }, wrapperCol: { span: 24 }, name: "add-emission", className: "programme-details-form", layout: "vertical", requiredMark: true, form: form, onValuesChange: onValuesChange, onFinish: onOpenSaveFormModel },
30244
30413
  React.createElement(antd.Row, null,
@@ -30289,10 +30458,8 @@ var GHGEmissionsComponent = function (props) {
30289
30458
  var workbook = XLSX__namespace.read(xldata, { type: 'array' });
30290
30459
  var sheetName = workbook.SheetNames[0];
30291
30460
  var sheet = workbook.Sheets[sheetName];
30292
- var firstRow = XLSX__namespace.utils.sheet_to_json(sheet, {
30293
- header: 1,
30294
- })[0];
30295
- if (!validateExcelDataFormat(firstRow)) {
30461
+ var excelData = XLSX__namespace.utils.sheet_to_json(sheet);
30462
+ if (!validateExcelDataFormat(sheet, excelData)) {
30296
30463
  antd.message.open({
30297
30464
  type: 'error',
30298
30465
  content: t('ghgInventory:invalidDataInExcel'),
@@ -30305,7 +30472,6 @@ var GHGEmissionsComponent = function (props) {
30305
30472
  });
30306
30473
  return false;
30307
30474
  }
30308
- var excelData = XLSX__namespace.utils.sheet_to_json(sheet);
30309
30475
  handleFileUploadData(excelData);
30310
30476
  setUploadedFileName(file.name);
30311
30477
  }
@@ -30318,9 +30484,9 @@ var GHGEmissionsComponent = function (props) {
30318
30484
  // Prevent upload
30319
30485
  return false;
30320
30486
  } },
30321
- React.createElement(antd.Button, { icon: React.createElement(icons.UploadOutlined, null) }, t("ghgInventory:upload"))))),
30487
+ React.createElement(antd.Button, { icon: React.createElement(icons.UploadOutlined, null), disabled: (userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.userRole) === exports.Role.ViewOnly }, t("ghgInventory:upload"))))),
30322
30488
  React.createElement(antd.Col, { xl: 16, md: 16, className: "add-new-upload-file-name-input" },
30323
- React.createElement(antd.Input, { value: uploadedFileName, readOnly: true, suffix: uploadedFileName && (React.createElement(antd.Button, { onClick: clearUploadDoc, icon: React.createElement(icons.DeleteOutlined, null), style: { marginRight: '-10px', padding: '0px 6px' } })) }))))),
30489
+ React.createElement(antd.Input, { value: uploadedFileName, disabled: (userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.userRole) === exports.Role.ViewOnly, readOnly: true, suffix: uploadedFileName && (React.createElement(antd.Button, { onClick: clearUploadDoc, icon: React.createElement(icons.DeleteOutlined, null), style: { marginRight: '-10px', padding: '0px 6px' } })) }))))),
30324
30490
  React.createElement(antd.Row, { gutter: 16 },
30325
30491
  React.createElement(antd.Col, { span: 9, offset: 12 },
30326
30492
  React.createElement(antd.Row, { gutter: 16, className: "table-heading-row" },
@@ -30375,39 +30541,129 @@ var GHGEmissionsComponent = function (props) {
30375
30541
  React.createElement(antd.Col, { xl: 9, md: 9 },
30376
30542
  React.createElement(antd.Row, { gutter: 16, className: "panel-content-input-box-row total-co2-land-input-box-row" },
30377
30543
  React.createElement(antd.Col, { xl: 6 },
30378
- React.createElement(antd.Form.Item, { name: "totalCo2WithoutLand_co2" },
30379
- React.createElement(antd.InputNumber, null))),
30544
+ React.createElement(antd.Form.Item, { name: "totalCo2WithoutLand_co2", rules: [
30545
+ {
30546
+ validator: function (rule, value) { return __awaiter(void 0, void 0, void 0, function () {
30547
+ return __generator(this, function (_a) {
30548
+ if (value && value < 0) {
30549
+ throw new Error();
30550
+ }
30551
+ return [2 /*return*/];
30552
+ });
30553
+ }); },
30554
+ },
30555
+ ] },
30556
+ React.createElement(antd.InputNumber, { disabled: (userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.userRole) === exports.Role.ViewOnly }))),
30380
30557
  React.createElement(antd.Col, { xl: 6 },
30381
- React.createElement(antd.Form.Item, { name: "totalCo2WithoutLand_ch4" },
30382
- React.createElement(antd.InputNumber, null))),
30558
+ React.createElement(antd.Form.Item, { name: "totalCo2WithoutLand_ch4", rules: [
30559
+ {
30560
+ validator: function (rule, value) { return __awaiter(void 0, void 0, void 0, function () {
30561
+ return __generator(this, function (_a) {
30562
+ if (value && value < 0) {
30563
+ throw new Error();
30564
+ }
30565
+ return [2 /*return*/];
30566
+ });
30567
+ }); },
30568
+ },
30569
+ ] },
30570
+ React.createElement(antd.InputNumber, { disabled: (userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.userRole) === exports.Role.ViewOnly }))),
30383
30571
  React.createElement(antd.Col, { xl: 6 },
30384
- React.createElement(antd.Form.Item, { name: "totalCo2WithoutLand_n2o" },
30385
- React.createElement(antd.InputNumber, null))),
30572
+ React.createElement(antd.Form.Item, { name: "totalCo2WithoutLand_n2o", rules: [
30573
+ {
30574
+ validator: function (rule, value) { return __awaiter(void 0, void 0, void 0, function () {
30575
+ return __generator(this, function (_a) {
30576
+ if (value && value < 0) {
30577
+ throw new Error();
30578
+ }
30579
+ return [2 /*return*/];
30580
+ });
30581
+ }); },
30582
+ },
30583
+ ] },
30584
+ React.createElement(antd.InputNumber, { disabled: (userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.userRole) === exports.Role.ViewOnly }))),
30386
30585
  React.createElement(antd.Col, { xl: 6 },
30387
- React.createElement(antd.Form.Item, { name: "totalCo2WithoutLand_co2eq" },
30388
- React.createElement(antd.InputNumber, null)))))),
30586
+ React.createElement(antd.Form.Item, { name: "totalCo2WithoutLand_co2eq", rules: [
30587
+ {
30588
+ validator: function (rule, value) { return __awaiter(void 0, void 0, void 0, function () {
30589
+ return __generator(this, function (_a) {
30590
+ if (value && value < 0) {
30591
+ throw new Error();
30592
+ }
30593
+ return [2 /*return*/];
30594
+ });
30595
+ }); },
30596
+ },
30597
+ ] },
30598
+ React.createElement(antd.InputNumber, { disabled: (userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.userRole) === exports.Role.ViewOnly })))))),
30389
30599
  React.createElement(antd.Row, { gutter: 16, key: 'totalCo2WithLand', className: "total-co2-with-land-row" },
30390
30600
  React.createElement(antd.Col, { xl: 12, md: 12, className: "total-co2-with-land-title" },
30391
30601
  React.createElement("span", null, t("ghgInventory:totalCo2WithLand"))),
30392
30602
  React.createElement(antd.Col, { xl: 9, md: 9 },
30393
30603
  React.createElement(antd.Row, { gutter: 16, className: "panel-content-input-box-row total-co2-land-input-box-row" },
30394
30604
  React.createElement(antd.Col, { xl: 6 },
30395
- React.createElement(antd.Form.Item, { name: "totalCo2WithLand_co2" },
30396
- React.createElement(antd.InputNumber, null))),
30605
+ React.createElement(antd.Form.Item, { name: "totalCo2WithLand_co2", rules: [
30606
+ {
30607
+ validator: function (rule, value) { return __awaiter(void 0, void 0, void 0, function () {
30608
+ return __generator(this, function (_a) {
30609
+ if (value && value < 0) {
30610
+ throw new Error();
30611
+ }
30612
+ return [2 /*return*/];
30613
+ });
30614
+ }); },
30615
+ },
30616
+ ] },
30617
+ React.createElement(antd.InputNumber, { disabled: (userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.userRole) === exports.Role.ViewOnly }))),
30397
30618
  React.createElement(antd.Col, { xl: 6 },
30398
- React.createElement(antd.Form.Item, { name: "totalCo2WithLand_ch4" },
30399
- React.createElement(antd.InputNumber, null))),
30619
+ React.createElement(antd.Form.Item, { name: "totalCo2WithLand_ch4", rules: [
30620
+ {
30621
+ validator: function (rule, value) { return __awaiter(void 0, void 0, void 0, function () {
30622
+ return __generator(this, function (_a) {
30623
+ if (value && value < 0) {
30624
+ throw new Error();
30625
+ }
30626
+ return [2 /*return*/];
30627
+ });
30628
+ }); },
30629
+ },
30630
+ ] },
30631
+ React.createElement(antd.InputNumber, { disabled: (userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.userRole) === exports.Role.ViewOnly }))),
30400
30632
  React.createElement(antd.Col, { xl: 6 },
30401
- React.createElement(antd.Form.Item, { name: "totalCo2WithLand_n2o" },
30402
- React.createElement(antd.InputNumber, null))),
30633
+ React.createElement(antd.Form.Item, { name: "totalCo2WithLand_n2o", rules: [
30634
+ {
30635
+ validator: function (rule, value) { return __awaiter(void 0, void 0, void 0, function () {
30636
+ return __generator(this, function (_a) {
30637
+ if (value && value < 0) {
30638
+ throw new Error();
30639
+ }
30640
+ return [2 /*return*/];
30641
+ });
30642
+ }); },
30643
+ },
30644
+ ] },
30645
+ React.createElement(antd.InputNumber, { disabled: (userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.userRole) === exports.Role.ViewOnly }))),
30403
30646
  React.createElement(antd.Col, { xl: 6 },
30404
- React.createElement(antd.Form.Item, { name: "totalCo2WithLand_co2eq" },
30405
- React.createElement(antd.InputNumber, null)))))),
30406
- React.createElement("div", { className: "steps-actions" },
30407
- (userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.companyRole) === exports.CompanyRole.GOVERNMENT &&
30408
- (React.createElement(antd.Button, { className: "finalize-btn", type: "primary", loading: loading, onClick: onOpenFinalizeFormModel }, "Finalise")),
30409
- React.createElement(antd.Button, { className: "submit-btn", type: "primary", htmlType: "submit", loading: loading }, "Submit"),
30410
- React.createElement(antd.Button, { className: "back-btn", onClick: onOpenResetFormModel, loading: loading }, "Cancel")))))),
30647
+ React.createElement(antd.Form.Item, { name: "totalCo2WithLand_co2eq", rules: [
30648
+ {
30649
+ validator: function (rule, value) { return __awaiter(void 0, void 0, void 0, function () {
30650
+ return __generator(this, function (_a) {
30651
+ if (value && value < 0) {
30652
+ throw new Error();
30653
+ }
30654
+ return [2 /*return*/];
30655
+ });
30656
+ }); },
30657
+ },
30658
+ ] },
30659
+ React.createElement(antd.InputNumber, { disabled: (userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.userRole) === exports.Role.ViewOnly })))))),
30660
+ (((userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.companyRole) === exports.CompanyRole.GOVERNMENT || (userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.companyRole) === exports.CompanyRole.MINISTRY)
30661
+ && ((userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.userRole) !== exports.Role.ViewOnly)) &&
30662
+ (React.createElement("div", { className: "steps-actions" },
30663
+ (userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.companyRole) === exports.CompanyRole.GOVERNMENT &&
30664
+ (React.createElement(antd.Button, { className: "finalize-btn", type: "primary", loading: loading, onClick: onOpenFinalizeFormModel }, "Finalise")),
30665
+ React.createElement(antd.Button, { className: "submit-btn", type: "primary", onClick: onOpenSaveFormModel, loading: loading }, "Submit"),
30666
+ React.createElement(antd.Button, { className: "back-btn", onClick: onOpenResetFormModel, loading: loading }, "Cancel"))))))),
30411
30667
  data.map(function (tabData) {
30412
30668
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z;
30413
30669
  return tabData.state === 'FINALIZED' && (React.createElement(antd.Tabs.TabPane, { className: 'view-data-panel', key: tabData.id.toString(), tab: React.createElement("span", null,
@@ -30423,7 +30679,7 @@ var GHGEmissionsComponent = function (props) {
30423
30679
  React.createElement(antd.Row, { className: "add-new-upload-file-label" }, t("ghgInventory:emissionRemovalDocument")),
30424
30680
  React.createElement(antd.Row, null,
30425
30681
  React.createElement(antd.Col, { xl: 15, md: 15, className: "view-download-file-name-input" },
30426
- React.createElement(antd.Input, { value: "GHG-Reporting Emissions_".concat(tabData.year, "_V").concat(tabData.version, ".csv"), disabled: true })),
30682
+ React.createElement(antd.Input, { value: "GHG-Reporting-Emissions_".concat(tabData.year, "_V").concat(tabData.version, ".csv"), disabled: true })),
30427
30683
  React.createElement(antd.Col, { xl: 5, md: 5, className: "view-download-file-inner-col" },
30428
30684
  React.createElement(antd.Button, { icon: React.createElement(icons.DownloadOutlined, null), onClick: function () { downloadCSV(tabData); } }, t("ghgInventory:download")))))),
30429
30685
  React.createElement(antd.Row, { gutter: 16 },
@@ -30612,31 +30868,38 @@ var GHGProjectionsComponent = function (props) {
30612
30868
  var createSetFieldObject = function (obj, objName) {
30613
30869
  var result = {};
30614
30870
  for (var key in obj) {
30615
- console.log('key', key);
30616
30871
  var energyEmissionsSub = obj[key];
30617
30872
  for (var childKey in energyEmissionsSub) {
30618
30873
  if (typeof energyEmissionsSub[childKey] === 'object') {
30619
- console.log('energyEmissionsSub', energyEmissionsSub);
30620
30874
  for (var category in energyEmissionsSub) {
30621
- console.log('category', category);
30622
30875
  var subcategory = energyEmissionsSub[category];
30623
30876
  for (var gas in subcategory) {
30624
- result["".concat(key, "_").concat(category, "_").concat(gas)] = subcategory[gas];
30877
+ result["".concat(key, "_").concat(category, "_").concat(gas)] = !isNaN(subcategory[gas]) ? subcategory[gas] : 0;
30625
30878
  }
30626
30879
  }
30627
30880
  }
30628
30881
  else {
30629
30882
  for (var gas in energyEmissionsSub) {
30630
- result["".concat(objName, "_").concat(key, "_").concat(gas)] = energyEmissionsSub[gas];
30883
+ result["".concat(objName, "_").concat(key, "_").concat(gas)] = !isNaN(energyEmissionsSub[gas]) ? energyEmissionsSub[gas] : 0;
30631
30884
  }
30632
30885
  }
30633
30886
  }
30634
30887
  }
30635
30888
  return result;
30636
30889
  };
30637
- var validateExcelDataFormat = function (sheetHeadings) {
30890
+ var validateExcelDataFormat = function (sheet, excelData) {
30891
+ var sheetHeadings = XLSX__namespace.utils.sheet_to_json(sheet, {
30892
+ header: 1,
30893
+ })[0];
30638
30894
  var columnHeadings = ['Sector', 'Business As Usual', 'Conditional NDC', 'Unconditional NDC'];
30639
- return sheetHeadings.every(function (element) { return columnHeadings.includes(element); });
30895
+ if (!columnHeadings.every(function (element) { return sheetHeadings.includes(element); })) {
30896
+ return false;
30897
+ }
30898
+ var sectorValues = excelData.map(function (excelDataObj) { return excelDataObj.Sector; });
30899
+ if (!excelFields.every(function (element) { return sectorValues.includes(element); })) {
30900
+ return false;
30901
+ }
30902
+ return true;
30640
30903
  };
30641
30904
  var populateFormWithUploadedFile = function (excelData, keyPrefix) {
30642
30905
  var emissions = {};
@@ -30713,12 +30976,13 @@ var GHGProjectionsComponent = function (props) {
30713
30976
  var sum = 0;
30714
30977
  for (var key in obj) {
30715
30978
  if (key === conditionType) {
30716
- sum += obj[key];
30979
+ sum += Number.isInteger(obj[key]) ? obj[key] : 0;
30717
30980
  }
30718
30981
  else if (typeof obj[key] === 'object' &&
30719
30982
  key !== 'totalCo2WithLand' &&
30720
30983
  key !== 'totalCo2WithoutLand') {
30721
- sum += calculateSumEmissionView(obj[key], conditionType);
30984
+ var calculatedSum = calculateSumEmissionView(obj[key], conditionType);
30985
+ sum += Number.isInteger(calculatedSum) ? calculatedSum : 0;
30722
30986
  }
30723
30987
  }
30724
30988
  return sum;
@@ -30996,19 +31260,6 @@ var GHGProjectionsComponent = function (props) {
30996
31260
  setOpenResetFormModal(false);
30997
31261
  };
30998
31262
  var onOpenResetFormModel = function () {
30999
- setActionInfo({
31000
- action: "".concat(t('ghgInventory:proceed')),
31001
- headerText: "".concat(t('ghgInventory:discardHeaderText')),
31002
- type: 'danger',
31003
- icon: React.createElement(icons.CloseCircleOutlined, null),
31004
- });
31005
- setErrorMsg('');
31006
- setOpenResetFormModal(true);
31007
- };
31008
- var onSaveFormCanceled = function () {
31009
- setOpenSaveFormModal(false);
31010
- };
31011
- var onOpenSaveFormModel = function () {
31012
31263
  if (!isFormChanged) {
31013
31264
  antd.message.open({
31014
31265
  type: 'error',
@@ -31019,34 +31270,98 @@ var GHGProjectionsComponent = function (props) {
31019
31270
  }
31020
31271
  else {
31021
31272
  setActionInfo({
31022
- action: "".concat(t("ghgInventory:submit")),
31023
- headerText: "".concat(t("ghgInventory:submitModelHeader")),
31024
- type: "primary",
31025
- icon: React.createElement(icons.CheckCircleOutlined, null),
31273
+ action: "".concat(t('ghgInventory:proceed')),
31274
+ headerText: "".concat(t('ghgInventory:discardHeaderText')),
31275
+ type: 'danger',
31276
+ icon: React.createElement(icons.CloseCircleOutlined, null),
31026
31277
  });
31027
31278
  setErrorMsg('');
31028
- setOpenSaveFormModal(true);
31279
+ setOpenResetFormModal(true);
31029
31280
  }
31030
31281
  };
31282
+ var onSaveFormCanceled = function () {
31283
+ setOpenSaveFormModal(false);
31284
+ };
31285
+ var onOpenSaveFormModel = function () {
31286
+ var _a = form.getFieldsValue(true); _a.year; var rest = __rest(_a, ["year"]);
31287
+ var otherFieldsNegativeValue = Object.values(rest).some(function (value) {
31288
+ return typeof value === 'number' && value < 0;
31289
+ });
31290
+ form
31291
+ .validateFields()
31292
+ .then(function (values) {
31293
+ if (!isFormChanged) {
31294
+ antd.message.open({
31295
+ type: 'error',
31296
+ content: t('ghgInventory:formNotChanged'),
31297
+ duration: 4,
31298
+ style: { textAlign: 'right', marginRight: 15, marginTop: 10 },
31299
+ });
31300
+ }
31301
+ else {
31302
+ setActionInfo({
31303
+ action: "".concat(t("ghgInventory:submit")),
31304
+ headerText: "".concat(t("ghgInventory:submitModelHeader")),
31305
+ type: "primary",
31306
+ icon: React.createElement(icons.CheckCircleOutlined, null),
31307
+ });
31308
+ setErrorMsg('');
31309
+ setOpenSaveFormModal(true);
31310
+ }
31311
+ })
31312
+ .catch(function (errorInfo) {
31313
+ if (otherFieldsNegativeValue) {
31314
+ antd.message.open({
31315
+ type: 'error',
31316
+ content: t('ghgInventory:negativeValuesNotAllowed'),
31317
+ duration: 4,
31318
+ style: { textAlign: 'right', marginRight: 15, marginTop: 10 },
31319
+ });
31320
+ }
31321
+ });
31322
+ };
31031
31323
  var onFinalizeFormCanceled = function () {
31032
31324
  setOpenFinalizeFormModal(false);
31033
31325
  };
31034
31326
  var onOpenFinalizeFormModel = function () {
31327
+ var _a = form.getFieldsValue(true); _a.year; var rest = __rest(_a, ["year"]);
31328
+ var otherFieldsEmpty = Object.values(rest).every(function (value) { return !value; });
31329
+ var otherFieldsNegativeValue = Object.values(rest).some(function (value) {
31330
+ return typeof value === 'number' && value < 0;
31331
+ });
31035
31332
  form
31036
31333
  .validateFields()
31037
31334
  .then(function (values) {
31038
31335
  // Validation successful, set ActionInfo and open the form modal
31039
- setActionInfo({
31040
- action: "".concat(t("ghgInventory:finalize")),
31041
- headerText: "".concat(t("ghgInventory:finalizeModelHeader")),
31042
- type: "primary",
31043
- icon: React.createElement(Icon.ClipboardCheck, null),
31044
- });
31045
- setErrorMsg('');
31046
- setOpenFinalizeFormModal(true);
31336
+ if (otherFieldsEmpty) {
31337
+ antd.message.open({
31338
+ type: 'error',
31339
+ content: t('ghgInventory:cannotFinaliseEmpty'),
31340
+ duration: 4,
31341
+ style: { textAlign: 'right', marginRight: 15, marginTop: 10 },
31342
+ });
31343
+ }
31344
+ else {
31345
+ setActionInfo({
31346
+ action: "".concat(t("ghgInventory:finalize")),
31347
+ headerText: "".concat(t("ghgInventory:finalizeModelHeader")),
31348
+ type: "primary",
31349
+ icon: React.createElement(Icon.ClipboardCheck, null),
31350
+ });
31351
+ setErrorMsg('');
31352
+ setOpenFinalizeFormModal(true);
31353
+ }
31047
31354
  })
31048
31355
  .catch(function (errorInfo) {
31049
31356
  // Validation failed
31357
+ if (otherFieldsNegativeValue) {
31358
+ antd.message.open({
31359
+ type: 'error',
31360
+ content: t('ghgInventory:negativeValuesNotAllowed'),
31361
+ duration: 4,
31362
+ style: { textAlign: 'right', marginRight: 15, marginTop: 10 },
31363
+ });
31364
+ }
31050
31365
  console.log('Validation failed:', errorInfo);
31051
31366
  });
31052
31367
  };
@@ -31110,7 +31425,7 @@ var GHGProjectionsComponent = function (props) {
31110
31425
  setLoading(true);
31111
31426
  _a.label = 2;
31112
31427
  case 2:
31113
- _a.trys.push([2, 6, 9, 10]);
31428
+ _a.trys.push([2, 6, 11, 12]);
31114
31429
  return [4 /*yield*/, post('national/projections', payload)];
31115
31430
  case 3:
31116
31431
  response = _a.sent();
@@ -31137,7 +31452,7 @@ var GHGProjectionsComponent = function (props) {
31137
31452
  case 4:
31138
31453
  _a.sent();
31139
31454
  _a.label = 5;
31140
- case 5: return [3 /*break*/, 10];
31455
+ case 5: return [3 /*break*/, 12];
31141
31456
  case 6:
31142
31457
  error_2 = _a.sent();
31143
31458
  console.log('Error in projection creation - ', error_2);
@@ -31149,19 +31464,31 @@ var GHGProjectionsComponent = function (props) {
31149
31464
  duration: 4,
31150
31465
  style: { textAlign: 'right', marginRight: 15, marginTop: 10 },
31151
31466
  });
31152
- if (!(error_2.statusCode == axios.HttpStatusCode.Conflict)) return [3 /*break*/, 8];
31467
+ if (!(error_2.status === axios.HttpStatusCode.Conflict.valueOf())) return [3 /*break*/, 8];
31153
31468
  return [4 /*yield*/, getProjectionData()];
31154
31469
  case 7:
31155
31470
  _a.sent();
31471
+ setIsSavedFormDataSet(false);
31472
+ clearUploadDoc();
31473
+ if (!isPendingFinalization) {
31474
+ clearForm();
31475
+ }
31476
+ return [3 /*break*/, 10];
31477
+ case 8:
31478
+ if (!(error_2.status === axios.HttpStatusCode.Forbidden.valueOf())) return [3 /*break*/, 10];
31156
31479
  clearUploadDoc();
31157
- _a.label = 8;
31158
- case 8: return [3 /*break*/, 10];
31480
+ clearForm();
31481
+ return [4 /*yield*/, getProjectionData()];
31159
31482
  case 9:
31483
+ _a.sent();
31484
+ _a.label = 10;
31485
+ case 10: return [3 /*break*/, 12];
31486
+ case 11:
31160
31487
  // eslint-disable-next-line no-use-before-define, @typescript-eslint/no-use-before-define
31161
31488
  setIsFormChanged(false);
31162
31489
  setLoading(false);
31163
31490
  return [7 /*endfinally*/];
31164
- case 10: return [2 /*return*/];
31491
+ case 12: return [2 /*return*/];
31165
31492
  }
31166
31493
  });
31167
31494
  }); };
@@ -31590,14 +31917,47 @@ var GHGProjectionsComponent = function (props) {
31590
31917
  React.createElement(antd.Col, { xl: 9, md: 9 },
31591
31918
  React.createElement(antd.Row, { gutter: 16, className: "panel-content-input-box-row" },
31592
31919
  React.createElement(antd.Col, { xl: 7 },
31593
- React.createElement(antd.Form.Item, { name: panelHeading + '_' + item + '_bau' },
31594
- React.createElement(antd.InputNumber, { onChange: function (event) { return calculateSumBau(event, panelHeading); } }))),
31920
+ React.createElement(antd.Form.Item, { name: panelHeading + '_' + item + '_bau', rules: [
31921
+ {
31922
+ validator: function (rule, value) { return __awaiter(void 0, void 0, void 0, function () {
31923
+ return __generator(this, function (_a) {
31924
+ if (value && value < 0) {
31925
+ throw new Error();
31926
+ }
31927
+ return [2 /*return*/];
31928
+ });
31929
+ }); },
31930
+ },
31931
+ ] },
31932
+ React.createElement(antd.InputNumber, { onChange: function (event) { return calculateSumBau(event, panelHeading); }, disabled: (userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.userRole) === exports.Role.ViewOnly }))),
31595
31933
  React.createElement(antd.Col, { xl: 7 },
31596
- React.createElement(antd.Form.Item, { name: panelHeading + '_' + item + '_conditionalNdc' },
31597
- React.createElement(antd.InputNumber, { onChange: function (event) { return calculateSumConditionalNdc(event, panelHeading); } }))),
31934
+ React.createElement(antd.Form.Item, { name: panelHeading + '_' + item + '_conditionalNdc', rules: [
31935
+ {
31936
+ validator: function (rule, value) { return __awaiter(void 0, void 0, void 0, function () {
31937
+ return __generator(this, function (_a) {
31938
+ if (value && value < 0) {
31939
+ throw new Error();
31940
+ }
31941
+ return [2 /*return*/];
31942
+ });
31943
+ }); },
31944
+ },
31945
+ ] },
31946
+ React.createElement(antd.InputNumber, { onChange: function (event) { return calculateSumConditionalNdc(event, panelHeading); }, disabled: (userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.userRole) === exports.Role.ViewOnly }))),
31598
31947
  React.createElement(antd.Col, { xl: 7 },
31599
- React.createElement(antd.Form.Item, { name: panelHeading + '_' + item + '_unconditionalNdc' },
31600
- React.createElement(antd.InputNumber, { onChange: function (event) { return calculateSumUnconditionalNdc(event, panelHeading); } }))))))); };
31948
+ React.createElement(antd.Form.Item, { name: panelHeading + '_' + item + '_unconditionalNdc', rules: [
31949
+ {
31950
+ validator: function (rule, value) { return __awaiter(void 0, void 0, void 0, function () {
31951
+ return __generator(this, function (_a) {
31952
+ if (value && value < 0) {
31953
+ throw new Error();
31954
+ }
31955
+ return [2 /*return*/];
31956
+ });
31957
+ }); },
31958
+ },
31959
+ ] },
31960
+ React.createElement(antd.InputNumber, { onChange: function (event) { return calculateSumUnconditionalNdc(event, panelHeading); }, disabled: (userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.userRole) === exports.Role.ViewOnly }))))))); };
31601
31961
  var renderPanelContentView = function (bau, conditionalNdc, unconditionalNdc, item, index) {
31602
31962
  return (React.createElement(antd.Row, { gutter: 16, key: index, className: "panel-content-row" },
31603
31963
  React.createElement(antd.Col, { xl: 12, md: 12, className: "panel-content-title" },
@@ -31656,7 +32016,7 @@ var GHGProjectionsComponent = function (props) {
31656
32016
  var encodedUri = encodeURI("data:text/csv;charset=utf-8,".concat(csvContent));
31657
32017
  var link = document.createElement('a');
31658
32018
  link.setAttribute('href', encodedUri);
31659
- link.setAttribute('download', "GHG-Reporting Projections_".concat(dataToDownload.year, "_V").concat(dataToDownload.version, ".csv"));
32019
+ link.setAttribute('download', "GHG-Reporting-Projections_".concat(dataToDownload.year, "_V").concat(dataToDownload.version, ".csv"));
31660
32020
  document.body.appendChild(link);
31661
32021
  link.click();
31662
32022
  };
@@ -31678,6 +32038,17 @@ var GHGProjectionsComponent = function (props) {
31678
32038
  }
31679
32039
  return false;
31680
32040
  };
32041
+ var canViewForm = function () {
32042
+ if ((userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.companyRole) === exports.CompanyRole.GOVERNMENT || (userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.companyRole) === exports.CompanyRole.MINISTRY) {
32043
+ if ((userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.userRole) === exports.Role.ViewOnly && data.some(function (item) { return item.state === 'SAVED'; })) {
32044
+ return true;
32045
+ }
32046
+ else if ((userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.userRole) !== exports.Role.ViewOnly) {
32047
+ return true;
32048
+ }
32049
+ }
32050
+ return false;
32051
+ };
31681
32052
  return (React.createElement("div", null,
31682
32053
  React.createElement("div", { className: "content-container projection-tab-container" },
31683
32054
  React.createElement("div", { className: "projection-title-bar" },
@@ -31686,8 +32057,7 @@ var GHGProjectionsComponent = function (props) {
31686
32057
  React.createElement("div", { className: "body-sub-title" }, t("ghgInventory:totalNationalEmissionSubTitle")))),
31687
32058
  React.createElement("div", { className: "content-card add-projection" },
31688
32059
  React.createElement(antd.Tabs, { defaultActiveKey: "Add New", centered: true },
31689
- ((userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.companyRole) === exports.CompanyRole.GOVERNMENT ||
31690
- (userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.companyRole) === exports.CompanyRole.MINISTRY) && (React.createElement(antd.Tabs.TabPane, { key: "Add New", tab: t("ghgInventory:addNew") },
32060
+ (canViewForm()) && (React.createElement(antd.Tabs.TabPane, { key: "Add New", tab: t("ghgInventory:addNew") },
31691
32061
  React.createElement("div", null,
31692
32062
  React.createElement(antd.Form, { labelCol: { span: 20 }, wrapperCol: { span: 24 }, name: "add-projection", className: "programme-details-form", layout: "vertical", requiredMark: true, form: form, onValuesChange: onValuesChange, onFinish: onOpenSaveFormModel },
31693
32063
  React.createElement(antd.Row, null,
@@ -31737,10 +32107,8 @@ var GHGProjectionsComponent = function (props) {
31737
32107
  var workbook = XLSX__namespace.read(xldata, { type: 'array' });
31738
32108
  var sheetName = workbook.SheetNames[0];
31739
32109
  var sheet = workbook.Sheets[sheetName];
31740
- var firstRow = XLSX__namespace.utils.sheet_to_json(sheet, {
31741
- header: 1,
31742
- })[0];
31743
- if (!validateExcelDataFormat(firstRow)) {
32110
+ var excelData = XLSX__namespace.utils.sheet_to_json(sheet);
32111
+ if (!validateExcelDataFormat(sheet, excelData)) {
31744
32112
  antd.message.open({
31745
32113
  type: 'error',
31746
32114
  content: t('ghgInventory:invalidDataInExcel'),
@@ -31753,7 +32121,6 @@ var GHGProjectionsComponent = function (props) {
31753
32121
  });
31754
32122
  return false;
31755
32123
  }
31756
- var excelData = XLSX__namespace.utils.sheet_to_json(sheet);
31757
32124
  handleFileUploadData(excelData);
31758
32125
  setUploadedFileName(file.name);
31759
32126
  }
@@ -31766,9 +32133,9 @@ var GHGProjectionsComponent = function (props) {
31766
32133
  // Prevent upload
31767
32134
  return false;
31768
32135
  } },
31769
- React.createElement(antd.Button, { icon: React.createElement(icons.UploadOutlined, null) }, t("ghgInventory:upload"))))),
32136
+ React.createElement(antd.Button, { icon: React.createElement(icons.UploadOutlined, null), disabled: (userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.userRole) === exports.Role.ViewOnly }, t("ghgInventory:upload"))))),
31770
32137
  React.createElement(antd.Col, { xl: 16, md: 16, className: "add-new-upload-file-name-input" },
31771
- React.createElement(antd.Input, { value: uploadedFileName, readOnly: true, suffix: uploadedFileName && (React.createElement(antd.Button, { onClick: clearUploadDoc, icon: React.createElement(icons.DeleteOutlined, null), style: { marginRight: '-10px', padding: '0px 6px' } })) }))))),
32138
+ React.createElement(antd.Input, { value: uploadedFileName, disabled: (userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.userRole) === exports.Role.ViewOnly, readOnly: true, suffix: uploadedFileName && (React.createElement(antd.Button, { onClick: clearUploadDoc, icon: React.createElement(icons.DeleteOutlined, null), style: { marginRight: '-10px', padding: '0px 6px' } })) }))))),
31772
32139
  React.createElement(antd.Row, { gutter: 16 },
31773
32140
  React.createElement(antd.Col, { span: 9, offset: 12 },
31774
32141
  React.createElement(antd.Row, { gutter: 16, className: "table-heading-row" },
@@ -31812,33 +32179,101 @@ var GHGProjectionsComponent = function (props) {
31812
32179
  React.createElement(antd.Col, { xl: 9, md: 9 },
31813
32180
  React.createElement(antd.Row, { gutter: 16, className: "panel-content-input-box-row total-co2-land-input-box-row" },
31814
32181
  React.createElement(antd.Col, { xl: 7 },
31815
- React.createElement(antd.Form.Item, { name: "totalCo2WithoutLand_bau" },
31816
- React.createElement(antd.InputNumber, null))),
32182
+ React.createElement(antd.Form.Item, { name: "totalCo2WithoutLand_bau", rules: [
32183
+ {
32184
+ validator: function (rule, value) { return __awaiter(void 0, void 0, void 0, function () {
32185
+ return __generator(this, function (_a) {
32186
+ if (value && value < 0) {
32187
+ throw new Error();
32188
+ }
32189
+ return [2 /*return*/];
32190
+ });
32191
+ }); },
32192
+ },
32193
+ ] },
32194
+ React.createElement(antd.InputNumber, { disabled: (userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.userRole) === exports.Role.ViewOnly }))),
31817
32195
  React.createElement(antd.Col, { xl: 7 },
31818
- React.createElement(antd.Form.Item, { name: "totalCo2WithoutLand_conditionalNdc" },
31819
- React.createElement(antd.InputNumber, null))),
32196
+ React.createElement(antd.Form.Item, { name: "totalCo2WithoutLand_conditionalNdc", rules: [
32197
+ {
32198
+ validator: function (rule, value) { return __awaiter(void 0, void 0, void 0, function () {
32199
+ return __generator(this, function (_a) {
32200
+ if (value && value < 0) {
32201
+ throw new Error();
32202
+ }
32203
+ return [2 /*return*/];
32204
+ });
32205
+ }); },
32206
+ },
32207
+ ] },
32208
+ React.createElement(antd.InputNumber, { disabled: (userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.userRole) === exports.Role.ViewOnly }))),
31820
32209
  React.createElement(antd.Col, { xl: 7 },
31821
- React.createElement(antd.Form.Item, { name: "totalCo2WithoutLand_unconditionalNdc" },
31822
- React.createElement(antd.InputNumber, null)))))),
32210
+ React.createElement(antd.Form.Item, { name: "totalCo2WithoutLand_unconditionalNdc", rules: [
32211
+ {
32212
+ validator: function (rule, value) { return __awaiter(void 0, void 0, void 0, function () {
32213
+ return __generator(this, function (_a) {
32214
+ if (value && value < 0) {
32215
+ throw new Error();
32216
+ }
32217
+ return [2 /*return*/];
32218
+ });
32219
+ }); },
32220
+ },
32221
+ ] },
32222
+ React.createElement(antd.InputNumber, { disabled: (userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.userRole) === exports.Role.ViewOnly })))))),
31823
32223
  React.createElement(antd.Row, { gutter: 16, key: 'totalCo2WithLand', className: "total-co2-with-land-row" },
31824
32224
  React.createElement(antd.Col, { xl: 12, md: 12, className: "total-co2-with-land-title" },
31825
32225
  React.createElement("span", null, t("ghgInventory:totalCo2WithLand"))),
31826
32226
  React.createElement(antd.Col, { xl: 9, md: 9 },
31827
32227
  React.createElement(antd.Row, { gutter: 16, className: "panel-content-input-box-row total-co2-land-input-box-row" },
31828
32228
  React.createElement(antd.Col, { xl: 7 },
31829
- React.createElement(antd.Form.Item, { name: "totalCo2WithLand_bau" },
31830
- React.createElement(antd.InputNumber, null))),
32229
+ React.createElement(antd.Form.Item, { name: "totalCo2WithLand_bau", rules: [
32230
+ {
32231
+ validator: function (rule, value) { return __awaiter(void 0, void 0, void 0, function () {
32232
+ return __generator(this, function (_a) {
32233
+ if (value && value < 0) {
32234
+ throw new Error();
32235
+ }
32236
+ return [2 /*return*/];
32237
+ });
32238
+ }); },
32239
+ },
32240
+ ] },
32241
+ React.createElement(antd.InputNumber, { disabled: (userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.userRole) === exports.Role.ViewOnly }))),
31831
32242
  React.createElement(antd.Col, { xl: 7 },
31832
- React.createElement(antd.Form.Item, { name: "totalCo2WithLand_conditionalNdc" },
31833
- React.createElement(antd.InputNumber, null))),
32243
+ React.createElement(antd.Form.Item, { name: "totalCo2WithLand_conditionalNdc", rules: [
32244
+ {
32245
+ validator: function (rule, value) { return __awaiter(void 0, void 0, void 0, function () {
32246
+ return __generator(this, function (_a) {
32247
+ if (value && value < 0) {
32248
+ throw new Error();
32249
+ }
32250
+ return [2 /*return*/];
32251
+ });
32252
+ }); },
32253
+ },
32254
+ ] },
32255
+ React.createElement(antd.InputNumber, { disabled: (userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.userRole) === exports.Role.ViewOnly }))),
31834
32256
  React.createElement(antd.Col, { xl: 7 },
31835
- React.createElement(antd.Form.Item, { name: "totalCo2WithLand_unconditionalNdc" },
31836
- React.createElement(antd.InputNumber, null)))))),
31837
- React.createElement("div", { className: "steps-actions" },
31838
- (userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.companyRole) === exports.CompanyRole.GOVERNMENT &&
31839
- (React.createElement(antd.Button, { className: "finalize-btn", type: "primary", loading: loading, onClick: onOpenFinalizeFormModel }, "Finalise")),
31840
- React.createElement(antd.Button, { className: "submit-btn", type: "primary", htmlType: "submit", loading: loading }, "Submit"),
31841
- React.createElement(antd.Button, { className: "back-btn", onClick: onOpenResetFormModel, loading: loading }, "Cancel")))))),
32257
+ React.createElement(antd.Form.Item, { name: "totalCo2WithLand_unconditionalNdc", rules: [
32258
+ {
32259
+ validator: function (rule, value) { return __awaiter(void 0, void 0, void 0, function () {
32260
+ return __generator(this, function (_a) {
32261
+ if (value && value < 0) {
32262
+ throw new Error();
32263
+ }
32264
+ return [2 /*return*/];
32265
+ });
32266
+ }); },
32267
+ },
32268
+ ] },
32269
+ React.createElement(antd.InputNumber, { disabled: (userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.userRole) === exports.Role.ViewOnly })))))),
32270
+ (((userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.companyRole) === exports.CompanyRole.GOVERNMENT || (userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.companyRole) === exports.CompanyRole.MINISTRY)
32271
+ && ((userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.userRole) !== exports.Role.ViewOnly)) &&
32272
+ (React.createElement("div", { className: "steps-actions" },
32273
+ (userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.companyRole) === exports.CompanyRole.GOVERNMENT &&
32274
+ (React.createElement(antd.Button, { className: "finalize-btn", type: "primary", loading: loading, onClick: onOpenFinalizeFormModel }, "Finalise")),
32275
+ React.createElement(antd.Button, { className: "submit-btn", type: "primary", onClick: onOpenSaveFormModel, loading: loading }, "Submit"),
32276
+ React.createElement(antd.Button, { className: "back-btn", onClick: onOpenResetFormModel, loading: loading }, "Cancel"))))))),
31842
32277
  data.map(function (tabData) {
31843
32278
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
31844
32279
  return tabData.state === 'FINALIZED' && (React.createElement(antd.Tabs.TabPane, { className: 'view-data-panel', key: tabData.id.toString(), tab: React.createElement("span", null,
@@ -31858,7 +32293,7 @@ var GHGProjectionsComponent = function (props) {
31858
32293
  React.createElement(antd.Row, { className: "add-new-upload-file-label" }, t("ghgInventory:emissionRemovalDocument")),
31859
32294
  React.createElement(antd.Row, null,
31860
32295
  React.createElement(antd.Col, { xl: 15, md: 15, className: "view-download-file-name-input" },
31861
- React.createElement(antd.Input, { value: "GHG-Reporting Projections_".concat(tabData.year, "_V").concat(tabData.version, ".csv"), disabled: true })),
32296
+ React.createElement(antd.Input, { value: "GHG-Reporting-Projections_".concat(tabData.year, "_V").concat(tabData.version, ".csv"), disabled: true })),
31862
32297
  React.createElement(antd.Col, { xl: 5, md: 5, className: "view-download-file-inner-col" },
31863
32298
  React.createElement(antd.Button, { icon: React.createElement(icons.DownloadOutlined, null), onClick: function () { downloadCSV(tabData); } }, t("ghgInventory:download")))))),
31864
32299
  React.createElement(antd.Row, { gutter: 16 },