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

Sign up to get free protection for your applications and to get access to all the features.
package/dist/esm/index.js CHANGED
@@ -28889,6 +28889,48 @@ var totalProjectionFields = [
28889
28889
  'Total National Emission and Removals - Conditional NDC',
28890
28890
  'Total National Emission and Removals - Unconditional NDC',
28891
28891
  ];
28892
+ var excelFields = [
28893
+ "Energy",
28894
+ "Fuel Combustion Activities",
28895
+ "Energy Industries",
28896
+ "Manufacturing Industries and Construction",
28897
+ "Transport",
28898
+ "Other Sectors",
28899
+ "Non-Specified",
28900
+ "Fugitive emissions from fuels",
28901
+ "Solid Fuels",
28902
+ "Oil and Natural Gas",
28903
+ "Other emissions from Energy Production",
28904
+ "Carbon dioxide Transport and Storage",
28905
+ "Transport of CO2",
28906
+ "Injection and Storage",
28907
+ "Other (Carbon dioxide Transport and Storage)",
28908
+ "Industrial Processes & Product Use",
28909
+ "Mineral Industry",
28910
+ "Chemical Industry",
28911
+ "Metal Industry",
28912
+ "Non-Energy Products from Fuels and Solvent Use",
28913
+ "Electronics Industry",
28914
+ "Product Uses as Substitutes for Ozone Depleting Substances",
28915
+ "Other Product Manufacture and Use",
28916
+ "Other (Industrial Processes & Product Use)",
28917
+ "Agriculture, Forestry, and Other Land Use",
28918
+ "Livestock",
28919
+ "Land",
28920
+ "Aggregate sources and non-CO2 emissions sources on land",
28921
+ "Other (Agriculture, Forestry, and Other Land Use)",
28922
+ "Waste",
28923
+ "Solid Waste Disposal",
28924
+ "Biological Treatment of Solid Waste",
28925
+ "Incineration and Open Burning of Waste",
28926
+ "Wastewater Treatment and Discharge",
28927
+ "Other (Waste)",
28928
+ "Other",
28929
+ "Indirect N2O emissions from the atmospheric deposition of nitrogen in NOx and NH3",
28930
+ "Other",
28931
+ "Total CO2 equivalent emissions without land use, land-use change and forestry",
28932
+ "Total CO2 equivalent emissions with land use, land-use change and forestry",
28933
+ ];
28892
28934
 
28893
28935
  Input.TextArea;
28894
28936
  var DiscardChangesConfirmationModel = function (props) {
@@ -29008,22 +29050,32 @@ var GHGEmissionsComponent = function (props) {
29008
29050
  for (var category in energyEmissionsSub) {
29009
29051
  var subcategory = energyEmissionsSub[category];
29010
29052
  for (var gas in subcategory) {
29011
- result["".concat(key, "_").concat(category, "_").concat(gas)] = subcategory[gas];
29053
+ result["".concat(key, "_").concat(category, "_").concat(gas)] = !isNaN(subcategory[gas]) ? subcategory[gas] : 0;
29012
29054
  }
29013
29055
  }
29014
29056
  }
29015
29057
  else {
29016
29058
  for (var gas in energyEmissionsSub) {
29017
- result["".concat(objName, "_").concat(key, "_").concat(gas)] = energyEmissionsSub[gas];
29059
+ result["".concat(objName, "_").concat(key, "_").concat(gas)] = !isNaN(energyEmissionsSub[gas]) ? energyEmissionsSub[gas] : 0;
29018
29060
  }
29019
29061
  }
29020
29062
  }
29021
29063
  }
29022
29064
  return result;
29023
29065
  };
29024
- var validateExcelDataFormat = function (sheetHeadings) {
29066
+ var validateExcelDataFormat = function (sheet, excelData) {
29067
+ var sheetHeadings = XLSX.utils.sheet_to_json(sheet, {
29068
+ header: 1,
29069
+ })[0];
29025
29070
  var columnHeadings = ['Sector', 'CO2', 'CH4', 'N2O', 'CO2-eq'];
29026
- return sheetHeadings.every(function (element) { return columnHeadings.includes(element); });
29071
+ if (!columnHeadings.every(function (element) { return sheetHeadings.includes(element); })) {
29072
+ return false;
29073
+ }
29074
+ var sectorValues = excelData.map(function (excelDataObj) { return excelDataObj.Sector; });
29075
+ if (!excelFields.every(function (element) { return sectorValues.includes(element); })) {
29076
+ return false;
29077
+ }
29078
+ return true;
29027
29079
  };
29028
29080
  var populateFormWithUploadedFile = function (excelData, keyPrefix) {
29029
29081
  var emissions = {};
@@ -29103,12 +29155,13 @@ var GHGEmissionsComponent = function (props) {
29103
29155
  var sum = 0;
29104
29156
  for (var key in obj) {
29105
29157
  if (key === gasType) {
29106
- sum += obj[key];
29158
+ sum += Number.isInteger(obj[key]) ? obj[key] : 0;
29107
29159
  }
29108
29160
  else if (typeof obj[key] === 'object' &&
29109
29161
  key !== 'totalCo2WithLand' &&
29110
29162
  key !== 'totalCo2WithoutLand') {
29111
- sum += calculateSumEmissionView(obj[key], gasType);
29163
+ var calculatedSum = calculateSumEmissionView(obj[key], gasType);
29164
+ sum += Number.isInteger(calculatedSum) ? calculatedSum : 0;
29112
29165
  }
29113
29166
  }
29114
29167
  return sum;
@@ -29426,19 +29479,6 @@ var GHGEmissionsComponent = function (props) {
29426
29479
  setOpenResetFormModal(false);
29427
29480
  };
29428
29481
  var onOpenResetFormModel = function () {
29429
- setActionInfo({
29430
- action: "".concat(t('ghgInventory:proceed')),
29431
- headerText: "".concat(t('ghgInventory:discardHeaderText')),
29432
- type: 'danger',
29433
- icon: React.createElement(CloseCircleOutlined, null),
29434
- });
29435
- setErrorMsg('');
29436
- setOpenResetFormModal(true);
29437
- };
29438
- var onSaveFormCanceled = function () {
29439
- setOpenSaveFormModal(false);
29440
- };
29441
- var onOpenSaveFormModel = function () {
29442
29482
  if (!isFormChanged) {
29443
29483
  message.open({
29444
29484
  type: 'error',
@@ -29449,34 +29489,98 @@ var GHGEmissionsComponent = function (props) {
29449
29489
  }
29450
29490
  else {
29451
29491
  setActionInfo({
29452
- action: "".concat(t("ghgInventory:submit")),
29453
- headerText: "".concat(t("ghgInventory:submitModelHeader")),
29454
- type: "primary",
29455
- icon: React.createElement(CheckCircleOutlined, null),
29492
+ action: "".concat(t('ghgInventory:proceed')),
29493
+ headerText: "".concat(t('ghgInventory:discardHeaderText')),
29494
+ type: 'danger',
29495
+ icon: React.createElement(CloseCircleOutlined, null),
29456
29496
  });
29457
29497
  setErrorMsg('');
29458
- setOpenSaveFormModal(true);
29498
+ setOpenResetFormModal(true);
29459
29499
  }
29460
29500
  };
29501
+ var onSaveFormCanceled = function () {
29502
+ setOpenSaveFormModal(false);
29503
+ };
29504
+ var onOpenSaveFormModel = function () {
29505
+ var _a = form.getFieldsValue(true); _a.year; var rest = __rest(_a, ["year"]);
29506
+ var otherFieldsNegativeValue = Object.values(rest).some(function (value) {
29507
+ return typeof value === 'number' && value < 0;
29508
+ });
29509
+ form
29510
+ .validateFields()
29511
+ .then(function (values) {
29512
+ if (!isFormChanged) {
29513
+ message.open({
29514
+ type: 'error',
29515
+ content: t('ghgInventory:formNotChanged'),
29516
+ duration: 4,
29517
+ style: { textAlign: 'right', marginRight: 15, marginTop: 10 },
29518
+ });
29519
+ }
29520
+ else {
29521
+ setActionInfo({
29522
+ action: "".concat(t("ghgInventory:submit")),
29523
+ headerText: "".concat(t("ghgInventory:submitModelHeader")),
29524
+ type: "primary",
29525
+ icon: React.createElement(CheckCircleOutlined, null),
29526
+ });
29527
+ setErrorMsg('');
29528
+ setOpenSaveFormModal(true);
29529
+ }
29530
+ })
29531
+ .catch(function (errorInfo) {
29532
+ if (otherFieldsNegativeValue) {
29533
+ message.open({
29534
+ type: 'error',
29535
+ content: t('ghgInventory:negativeValuesNotAllowed'),
29536
+ duration: 4,
29537
+ style: { textAlign: 'right', marginRight: 15, marginTop: 10 },
29538
+ });
29539
+ }
29540
+ });
29541
+ };
29461
29542
  var onFinalizeFormCanceled = function () {
29462
29543
  setOpenFinalizeFormModal(false);
29463
29544
  };
29464
29545
  var onOpenFinalizeFormModel = function () {
29546
+ var _a = form.getFieldsValue(true); _a.year; var rest = __rest(_a, ["year"]);
29547
+ var otherFieldsEmpty = Object.values(rest).every(function (value) { return !value; });
29548
+ var otherFieldsNegativeValue = Object.values(rest).some(function (value) {
29549
+ return typeof value === 'number' && value < 0;
29550
+ });
29465
29551
  form
29466
29552
  .validateFields()
29467
29553
  .then(function (values) {
29468
29554
  // Validation successful, set ActionInfo and open the form modal
29469
- setActionInfo({
29470
- action: "".concat(t("ghgInventory:finalize")),
29471
- headerText: "".concat(t("ghgInventory:finalizeModelHeader")),
29472
- type: "primary",
29473
- icon: React.createElement(ClipboardCheck, null),
29474
- });
29475
- setErrorMsg('');
29476
- setOpenFinalizeFormModal(true);
29555
+ if (otherFieldsEmpty) {
29556
+ message.open({
29557
+ type: 'error',
29558
+ content: t('ghgInventory:cannotFinaliseEmpty'),
29559
+ duration: 4,
29560
+ style: { textAlign: 'right', marginRight: 15, marginTop: 10 },
29561
+ });
29562
+ }
29563
+ else {
29564
+ setActionInfo({
29565
+ action: "".concat(t("ghgInventory:finalize")),
29566
+ headerText: "".concat(t("ghgInventory:finalizeModelHeader")),
29567
+ type: "primary",
29568
+ icon: React.createElement(ClipboardCheck, null),
29569
+ });
29570
+ setErrorMsg('');
29571
+ setOpenFinalizeFormModal(true);
29572
+ }
29477
29573
  })
29478
29574
  .catch(function (errorInfo) {
29479
29575
  // Validation failed
29576
+ if (otherFieldsNegativeValue) {
29577
+ message.open({
29578
+ type: 'error',
29579
+ content: t('ghgInventory:negativeValuesNotAllowed'),
29580
+ duration: 4,
29581
+ style: { textAlign: 'right', marginRight: 15, marginTop: 10 },
29582
+ });
29583
+ }
29480
29584
  console.log('Validation failed:', errorInfo);
29481
29585
  });
29482
29586
  };
@@ -29492,7 +29596,7 @@ var GHGEmissionsComponent = function (props) {
29492
29596
  setLoading(true);
29493
29597
  _a.label = 2;
29494
29598
  case 2:
29495
- _a.trys.push([2, 6, 9, 10]);
29599
+ _a.trys.push([2, 6, 11, 12]);
29496
29600
  return [4 /*yield*/, post('national/emissions', payload)];
29497
29601
  case 3:
29498
29602
  response = _a.sent();
@@ -29519,7 +29623,7 @@ var GHGEmissionsComponent = function (props) {
29519
29623
  case 4:
29520
29624
  _a.sent();
29521
29625
  _a.label = 5;
29522
- case 5: return [3 /*break*/, 10];
29626
+ case 5: return [3 /*break*/, 12];
29523
29627
  case 6:
29524
29628
  error_1 = _a.sent();
29525
29629
  console.log('Error in emission creation - ', error_1);
@@ -29531,19 +29635,31 @@ var GHGEmissionsComponent = function (props) {
29531
29635
  duration: 4,
29532
29636
  style: { textAlign: 'right', marginRight: 15, marginTop: 10 },
29533
29637
  });
29534
- if (!(error_1.statusCode == HttpStatusCode.Conflict)) return [3 /*break*/, 8];
29638
+ if (!(error_1.status === HttpStatusCode.Conflict.valueOf())) return [3 /*break*/, 8];
29535
29639
  return [4 /*yield*/, getEmissionData()];
29536
29640
  case 7:
29537
29641
  _a.sent();
29642
+ setIsSavedFormDataSet(false);
29643
+ clearUploadDoc();
29644
+ if (!isPendingFinalization) {
29645
+ clearForm();
29646
+ }
29647
+ return [3 /*break*/, 10];
29648
+ case 8:
29649
+ if (!(error_1.status === HttpStatusCode.Forbidden.valueOf())) return [3 /*break*/, 10];
29538
29650
  clearUploadDoc();
29539
- _a.label = 8;
29540
- case 8: return [3 /*break*/, 10];
29651
+ clearForm();
29652
+ return [4 /*yield*/, getEmissionData()];
29541
29653
  case 9:
29654
+ _a.sent();
29655
+ _a.label = 10;
29656
+ case 10: return [3 /*break*/, 12];
29657
+ case 11:
29542
29658
  // eslint-disable-next-line no-use-before-define, @typescript-eslint/no-use-before-define
29543
29659
  setIsFormChanged(false);
29544
29660
  setLoading(false);
29545
29661
  return [7 /*endfinally*/];
29546
- case 10: return [2 /*return*/];
29662
+ case 12: return [2 /*return*/];
29547
29663
  }
29548
29664
  });
29549
29665
  }); };
@@ -29781,7 +29897,6 @@ var GHGEmissionsComponent = function (props) {
29781
29897
  (formValues.fuelCombustionActivities_transport_co2 || 0) +
29782
29898
  (formValues.fuelCombustionActivities_otherSectors_co2 || 0) +
29783
29899
  (formValues.fuelCombustionActivities_nonSpecified_co2 || 0);
29784
- console.log('sum triggered', sum);
29785
29900
  setFuelCombustionActivitiesCo2(sum);
29786
29901
  }
29787
29902
  if (panelHeading === 'fugitiveEmissionsFromFuels') {
@@ -30113,16 +30228,72 @@ var GHGEmissionsComponent = function (props) {
30113
30228
  React.createElement(Col, { xl: 9, md: 9 },
30114
30229
  React.createElement(Row, { gutter: 16, className: "panel-content-input-box-row" },
30115
30230
  React.createElement(Col, { xl: 6 },
30116
- React.createElement(Form.Item, { name: panelHeading + '_' + item + '_co2' },
30231
+ React.createElement(Form.Item, { name: panelHeading + '_' + item + '_co2', rules: [
30232
+ {
30233
+ validator: function (rule, value) { return __awaiter(void 0, void 0, void 0, function () {
30234
+ return __generator(this, function (_a) {
30235
+ if (value && value < 0) {
30236
+ throw new Error();
30237
+ }
30238
+ if (value && !Number.isInteger(value)) {
30239
+ throw new Error();
30240
+ }
30241
+ return [2 /*return*/];
30242
+ });
30243
+ }); },
30244
+ },
30245
+ ] },
30117
30246
  React.createElement(InputNumber, { onChange: function (event) { return calculateSumCo2(event, panelHeading); } }))),
30118
30247
  React.createElement(Col, { xl: 6 },
30119
- React.createElement(Form.Item, { name: panelHeading + '_' + item + '_ch4' },
30248
+ React.createElement(Form.Item, { name: panelHeading + '_' + item + '_ch4', rules: [
30249
+ {
30250
+ validator: function (rule, value) { return __awaiter(void 0, void 0, void 0, function () {
30251
+ return __generator(this, function (_a) {
30252
+ if (value && value < 0) {
30253
+ throw new Error();
30254
+ }
30255
+ if (value && !Number.isInteger(value)) {
30256
+ throw new Error();
30257
+ }
30258
+ return [2 /*return*/];
30259
+ });
30260
+ }); },
30261
+ },
30262
+ ] },
30120
30263
  React.createElement(InputNumber, { onChange: function (event) { return calculateSumCh4(event, panelHeading); } }))),
30121
30264
  React.createElement(Col, { xl: 6 },
30122
- React.createElement(Form.Item, { name: panelHeading + '_' + item + '_n2o' },
30265
+ React.createElement(Form.Item, { name: panelHeading + '_' + item + '_n2o', rules: [
30266
+ {
30267
+ validator: function (rule, value) { return __awaiter(void 0, void 0, void 0, function () {
30268
+ return __generator(this, function (_a) {
30269
+ if (value && value < 0) {
30270
+ throw new Error();
30271
+ }
30272
+ if (value && !Number.isInteger(value)) {
30273
+ throw new Error();
30274
+ }
30275
+ return [2 /*return*/];
30276
+ });
30277
+ }); },
30278
+ },
30279
+ ] },
30123
30280
  React.createElement(InputNumber, { onChange: function (event) { return calculateSumN2o(event, panelHeading); } }))),
30124
30281
  React.createElement(Col, { xl: 6 },
30125
- React.createElement(Form.Item, { name: panelHeading + '_' + item + '_co2eq' },
30282
+ React.createElement(Form.Item, { name: panelHeading + '_' + item + '_co2eq', rules: [
30283
+ {
30284
+ validator: function (rule, value) { return __awaiter(void 0, void 0, void 0, function () {
30285
+ return __generator(this, function (_a) {
30286
+ if (value && value < 0) {
30287
+ throw new Error();
30288
+ }
30289
+ if (value && !Number.isInteger(value)) {
30290
+ throw new Error();
30291
+ }
30292
+ return [2 /*return*/];
30293
+ });
30294
+ }); },
30295
+ },
30296
+ ] },
30126
30297
  React.createElement(InputNumber, { onChange: function (event) { return calculateSumCo2Eq(event, panelHeading); } }))))))); };
30127
30298
  var renderPanelContentView = function (co2, ch4, n2o, co2eq, item, index) {
30128
30299
  return (React.createElement(Row, { gutter: 16, key: index, className: "panel-content-row" },
@@ -30185,7 +30356,7 @@ var GHGEmissionsComponent = function (props) {
30185
30356
  var encodedUri = encodeURI("data:text/csv;charset=utf-8,".concat(csvContent));
30186
30357
  var link = document.createElement('a');
30187
30358
  link.setAttribute('href', encodedUri);
30188
- link.setAttribute('download', "GHG-Reporting Emissions_".concat(dataToDownload.year, "_V").concat(dataToDownload.version, ".csv"));
30359
+ link.setAttribute('download', "GHG-Reporting-Emissions_".concat(dataToDownload.year, "_V").concat(dataToDownload.version, ".csv"));
30189
30360
  document.body.appendChild(link);
30190
30361
  link.click();
30191
30362
  };
@@ -30208,6 +30379,17 @@ var GHGEmissionsComponent = function (props) {
30208
30379
  }
30209
30380
  return false;
30210
30381
  };
30382
+ var canViewForm = function () {
30383
+ if ((userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.companyRole) === CompanyRole.GOVERNMENT || (userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.companyRole) === CompanyRole.MINISTRY) {
30384
+ if ((userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.userRole) === Role.ViewOnly && data.some(function (item) { return item.state === 'SAVED'; })) {
30385
+ return true;
30386
+ }
30387
+ else if ((userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.userRole) !== Role.ViewOnly) {
30388
+ return true;
30389
+ }
30390
+ }
30391
+ return false;
30392
+ };
30211
30393
  return (React.createElement("div", null,
30212
30394
  React.createElement("div", { className: "content-container emission-tab-container" },
30213
30395
  React.createElement("div", { className: "emission-title-bar" },
@@ -30216,8 +30398,7 @@ var GHGEmissionsComponent = function (props) {
30216
30398
  React.createElement("div", { className: "body-sub-title" }, t("ghgInventory:totalNationalEmissionSubTitle")))),
30217
30399
  React.createElement("div", { className: "content-card add-emission" },
30218
30400
  React.createElement(Tabs, { defaultActiveKey: "Add New", centered: true },
30219
- ((userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.companyRole) === CompanyRole.GOVERNMENT ||
30220
- (userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.companyRole) === CompanyRole.MINISTRY) && (React.createElement(Tabs.TabPane, { key: "Add New", tab: t("ghgInventory:addNew") },
30401
+ (canViewForm()) && (React.createElement(Tabs.TabPane, { key: "Add New", tab: t("ghgInventory:addNew") },
30221
30402
  React.createElement("div", null,
30222
30403
  React.createElement(Form, { labelCol: { span: 20 }, wrapperCol: { span: 24 }, name: "add-emission", className: "programme-details-form", layout: "vertical", requiredMark: true, form: form, onValuesChange: onValuesChange, onFinish: onOpenSaveFormModel },
30223
30404
  React.createElement(Row, null,
@@ -30268,10 +30449,8 @@ var GHGEmissionsComponent = function (props) {
30268
30449
  var workbook = XLSX.read(xldata, { type: 'array' });
30269
30450
  var sheetName = workbook.SheetNames[0];
30270
30451
  var sheet = workbook.Sheets[sheetName];
30271
- var firstRow = XLSX.utils.sheet_to_json(sheet, {
30272
- header: 1,
30273
- })[0];
30274
- if (!validateExcelDataFormat(firstRow)) {
30452
+ var excelData = XLSX.utils.sheet_to_json(sheet);
30453
+ if (!validateExcelDataFormat(sheet, excelData)) {
30275
30454
  message.open({
30276
30455
  type: 'error',
30277
30456
  content: t('ghgInventory:invalidDataInExcel'),
@@ -30284,7 +30463,6 @@ var GHGEmissionsComponent = function (props) {
30284
30463
  });
30285
30464
  return false;
30286
30465
  }
30287
- var excelData = XLSX.utils.sheet_to_json(sheet);
30288
30466
  handleFileUploadData(excelData);
30289
30467
  setUploadedFileName(file.name);
30290
30468
  }
@@ -30354,16 +30532,72 @@ var GHGEmissionsComponent = function (props) {
30354
30532
  React.createElement(Col, { xl: 9, md: 9 },
30355
30533
  React.createElement(Row, { gutter: 16, className: "panel-content-input-box-row total-co2-land-input-box-row" },
30356
30534
  React.createElement(Col, { xl: 6 },
30357
- React.createElement(Form.Item, { name: "totalCo2WithoutLand_co2" },
30535
+ React.createElement(Form.Item, { name: "totalCo2WithoutLand_co2", rules: [
30536
+ {
30537
+ validator: function (rule, value) { return __awaiter(void 0, void 0, void 0, function () {
30538
+ return __generator(this, function (_a) {
30539
+ if (value && value < 0) {
30540
+ throw new Error();
30541
+ }
30542
+ if (value && !Number.isInteger(value)) {
30543
+ throw new Error();
30544
+ }
30545
+ return [2 /*return*/];
30546
+ });
30547
+ }); },
30548
+ },
30549
+ ] },
30358
30550
  React.createElement(InputNumber, null))),
30359
30551
  React.createElement(Col, { xl: 6 },
30360
- React.createElement(Form.Item, { name: "totalCo2WithoutLand_ch4" },
30552
+ React.createElement(Form.Item, { name: "totalCo2WithoutLand_ch4", rules: [
30553
+ {
30554
+ validator: function (rule, value) { return __awaiter(void 0, void 0, void 0, function () {
30555
+ return __generator(this, function (_a) {
30556
+ if (value && value < 0) {
30557
+ throw new Error();
30558
+ }
30559
+ if (value && !Number.isInteger(value)) {
30560
+ throw new Error();
30561
+ }
30562
+ return [2 /*return*/];
30563
+ });
30564
+ }); },
30565
+ },
30566
+ ] },
30361
30567
  React.createElement(InputNumber, null))),
30362
30568
  React.createElement(Col, { xl: 6 },
30363
- React.createElement(Form.Item, { name: "totalCo2WithoutLand_n2o" },
30569
+ React.createElement(Form.Item, { name: "totalCo2WithoutLand_n2o", rules: [
30570
+ {
30571
+ validator: function (rule, value) { return __awaiter(void 0, void 0, void 0, function () {
30572
+ return __generator(this, function (_a) {
30573
+ if (value && value < 0) {
30574
+ throw new Error();
30575
+ }
30576
+ if (value && !Number.isInteger(value)) {
30577
+ throw new Error();
30578
+ }
30579
+ return [2 /*return*/];
30580
+ });
30581
+ }); },
30582
+ },
30583
+ ] },
30364
30584
  React.createElement(InputNumber, null))),
30365
30585
  React.createElement(Col, { xl: 6 },
30366
- React.createElement(Form.Item, { name: "totalCo2WithoutLand_co2eq" },
30586
+ React.createElement(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
+ if (value && !Number.isInteger(value)) {
30594
+ throw new Error();
30595
+ }
30596
+ return [2 /*return*/];
30597
+ });
30598
+ }); },
30599
+ },
30600
+ ] },
30367
30601
  React.createElement(InputNumber, null)))))),
30368
30602
  React.createElement(Row, { gutter: 16, key: 'totalCo2WithLand', className: "total-co2-with-land-row" },
30369
30603
  React.createElement(Col, { xl: 12, md: 12, className: "total-co2-with-land-title" },
@@ -30371,22 +30605,80 @@ var GHGEmissionsComponent = function (props) {
30371
30605
  React.createElement(Col, { xl: 9, md: 9 },
30372
30606
  React.createElement(Row, { gutter: 16, className: "panel-content-input-box-row total-co2-land-input-box-row" },
30373
30607
  React.createElement(Col, { xl: 6 },
30374
- React.createElement(Form.Item, { name: "totalCo2WithLand_co2" },
30608
+ React.createElement(Form.Item, { name: "totalCo2WithLand_co2", rules: [
30609
+ {
30610
+ validator: function (rule, value) { return __awaiter(void 0, void 0, void 0, function () {
30611
+ return __generator(this, function (_a) {
30612
+ if (value && value < 0) {
30613
+ throw new Error();
30614
+ }
30615
+ if (value && !Number.isInteger(value)) {
30616
+ throw new Error();
30617
+ }
30618
+ return [2 /*return*/];
30619
+ });
30620
+ }); },
30621
+ },
30622
+ ] },
30375
30623
  React.createElement(InputNumber, null))),
30376
30624
  React.createElement(Col, { xl: 6 },
30377
- React.createElement(Form.Item, { name: "totalCo2WithLand_ch4" },
30625
+ React.createElement(Form.Item, { name: "totalCo2WithLand_ch4", rules: [
30626
+ {
30627
+ validator: function (rule, value) { return __awaiter(void 0, void 0, void 0, function () {
30628
+ return __generator(this, function (_a) {
30629
+ if (value && value < 0) {
30630
+ throw new Error();
30631
+ }
30632
+ if (value && !Number.isInteger(value)) {
30633
+ throw new Error();
30634
+ }
30635
+ return [2 /*return*/];
30636
+ });
30637
+ }); },
30638
+ },
30639
+ ] },
30378
30640
  React.createElement(InputNumber, null))),
30379
30641
  React.createElement(Col, { xl: 6 },
30380
- React.createElement(Form.Item, { name: "totalCo2WithLand_n2o" },
30642
+ React.createElement(Form.Item, { name: "totalCo2WithLand_n2o", rules: [
30643
+ {
30644
+ validator: function (rule, value) { return __awaiter(void 0, void 0, void 0, function () {
30645
+ return __generator(this, function (_a) {
30646
+ if (value && value < 0) {
30647
+ throw new Error();
30648
+ }
30649
+ if (value && !Number.isInteger(value)) {
30650
+ throw new Error();
30651
+ }
30652
+ return [2 /*return*/];
30653
+ });
30654
+ }); },
30655
+ },
30656
+ ] },
30381
30657
  React.createElement(InputNumber, null))),
30382
30658
  React.createElement(Col, { xl: 6 },
30383
- React.createElement(Form.Item, { name: "totalCo2WithLand_co2eq" },
30659
+ React.createElement(Form.Item, { name: "totalCo2WithLand_co2eq", rules: [
30660
+ {
30661
+ validator: function (rule, value) { return __awaiter(void 0, void 0, void 0, function () {
30662
+ return __generator(this, function (_a) {
30663
+ if (value && value < 0) {
30664
+ throw new Error();
30665
+ }
30666
+ if (value && !Number.isInteger(value)) {
30667
+ throw new Error();
30668
+ }
30669
+ return [2 /*return*/];
30670
+ });
30671
+ }); },
30672
+ },
30673
+ ] },
30384
30674
  React.createElement(InputNumber, null)))))),
30385
- React.createElement("div", { className: "steps-actions" },
30386
- (userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.companyRole) === CompanyRole.GOVERNMENT &&
30387
- (React.createElement(Button, { className: "finalize-btn", type: "primary", loading: loading, onClick: onOpenFinalizeFormModel }, "Finalise")),
30388
- React.createElement(Button, { className: "submit-btn", type: "primary", htmlType: "submit", loading: loading }, "Submit"),
30389
- React.createElement(Button, { className: "back-btn", onClick: onOpenResetFormModel, loading: loading }, "Cancel")))))),
30675
+ (((userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.companyRole) === CompanyRole.GOVERNMENT || (userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.companyRole) === CompanyRole.MINISTRY)
30676
+ && ((userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.userRole) !== Role.ViewOnly)) &&
30677
+ (React.createElement("div", { className: "steps-actions" },
30678
+ (userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.companyRole) === CompanyRole.GOVERNMENT &&
30679
+ (React.createElement(Button, { className: "finalize-btn", type: "primary", loading: loading, onClick: onOpenFinalizeFormModel }, "Finalise")),
30680
+ React.createElement(Button, { className: "submit-btn", type: "primary", onClick: onOpenSaveFormModel, loading: loading }, "Submit"),
30681
+ React.createElement(Button, { className: "back-btn", onClick: onOpenResetFormModel, loading: loading }, "Cancel"))))))),
30390
30682
  data.map(function (tabData) {
30391
30683
  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;
30392
30684
  return tabData.state === 'FINALIZED' && (React.createElement(Tabs.TabPane, { className: 'view-data-panel', key: tabData.id.toString(), tab: React.createElement("span", null,
@@ -30402,7 +30694,7 @@ var GHGEmissionsComponent = function (props) {
30402
30694
  React.createElement(Row, { className: "add-new-upload-file-label" }, t("ghgInventory:emissionRemovalDocument")),
30403
30695
  React.createElement(Row, null,
30404
30696
  React.createElement(Col, { xl: 15, md: 15, className: "view-download-file-name-input" },
30405
- React.createElement(Input, { value: "GHG-Reporting Emissions_".concat(tabData.year, "_V").concat(tabData.version, ".csv"), disabled: true })),
30697
+ React.createElement(Input, { value: "GHG-Reporting-Emissions_".concat(tabData.year, "_V").concat(tabData.version, ".csv"), disabled: true })),
30406
30698
  React.createElement(Col, { xl: 5, md: 5, className: "view-download-file-inner-col" },
30407
30699
  React.createElement(Button, { icon: React.createElement(DownloadOutlined, null), onClick: function () { downloadCSV(tabData); } }, t("ghgInventory:download")))))),
30408
30700
  React.createElement(Row, { gutter: 16 },
@@ -30591,31 +30883,38 @@ var GHGProjectionsComponent = function (props) {
30591
30883
  var createSetFieldObject = function (obj, objName) {
30592
30884
  var result = {};
30593
30885
  for (var key in obj) {
30594
- console.log('key', key);
30595
30886
  var energyEmissionsSub = obj[key];
30596
30887
  for (var childKey in energyEmissionsSub) {
30597
30888
  if (typeof energyEmissionsSub[childKey] === 'object') {
30598
- console.log('energyEmissionsSub', energyEmissionsSub);
30599
30889
  for (var category in energyEmissionsSub) {
30600
- console.log('category', category);
30601
30890
  var subcategory = energyEmissionsSub[category];
30602
30891
  for (var gas in subcategory) {
30603
- result["".concat(key, "_").concat(category, "_").concat(gas)] = subcategory[gas];
30892
+ result["".concat(key, "_").concat(category, "_").concat(gas)] = !isNaN(subcategory[gas]) ? subcategory[gas] : 0;
30604
30893
  }
30605
30894
  }
30606
30895
  }
30607
30896
  else {
30608
30897
  for (var gas in energyEmissionsSub) {
30609
- result["".concat(objName, "_").concat(key, "_").concat(gas)] = energyEmissionsSub[gas];
30898
+ result["".concat(objName, "_").concat(key, "_").concat(gas)] = !isNaN(energyEmissionsSub[gas]) ? energyEmissionsSub[gas] : 0;
30610
30899
  }
30611
30900
  }
30612
30901
  }
30613
30902
  }
30614
30903
  return result;
30615
30904
  };
30616
- var validateExcelDataFormat = function (sheetHeadings) {
30905
+ var validateExcelDataFormat = function (sheet, excelData) {
30906
+ var sheetHeadings = XLSX.utils.sheet_to_json(sheet, {
30907
+ header: 1,
30908
+ })[0];
30617
30909
  var columnHeadings = ['Sector', 'Business As Usual', 'Conditional NDC', 'Unconditional NDC'];
30618
- return sheetHeadings.every(function (element) { return columnHeadings.includes(element); });
30910
+ if (!columnHeadings.every(function (element) { return sheetHeadings.includes(element); })) {
30911
+ return false;
30912
+ }
30913
+ var sectorValues = excelData.map(function (excelDataObj) { return excelDataObj.Sector; });
30914
+ if (!excelFields.every(function (element) { return sectorValues.includes(element); })) {
30915
+ return false;
30916
+ }
30917
+ return true;
30619
30918
  };
30620
30919
  var populateFormWithUploadedFile = function (excelData, keyPrefix) {
30621
30920
  var emissions = {};
@@ -30692,12 +30991,13 @@ var GHGProjectionsComponent = function (props) {
30692
30991
  var sum = 0;
30693
30992
  for (var key in obj) {
30694
30993
  if (key === conditionType) {
30695
- sum += obj[key];
30994
+ sum += Number.isInteger(obj[key]) ? obj[key] : 0;
30696
30995
  }
30697
30996
  else if (typeof obj[key] === 'object' &&
30698
30997
  key !== 'totalCo2WithLand' &&
30699
30998
  key !== 'totalCo2WithoutLand') {
30700
- sum += calculateSumEmissionView(obj[key], conditionType);
30999
+ var calculatedSum = calculateSumEmissionView(obj[key], conditionType);
31000
+ sum += Number.isInteger(calculatedSum) ? calculatedSum : 0;
30701
31001
  }
30702
31002
  }
30703
31003
  return sum;
@@ -30975,19 +31275,6 @@ var GHGProjectionsComponent = function (props) {
30975
31275
  setOpenResetFormModal(false);
30976
31276
  };
30977
31277
  var onOpenResetFormModel = function () {
30978
- setActionInfo({
30979
- action: "".concat(t('ghgInventory:proceed')),
30980
- headerText: "".concat(t('ghgInventory:discardHeaderText')),
30981
- type: 'danger',
30982
- icon: React.createElement(CloseCircleOutlined, null),
30983
- });
30984
- setErrorMsg('');
30985
- setOpenResetFormModal(true);
30986
- };
30987
- var onSaveFormCanceled = function () {
30988
- setOpenSaveFormModal(false);
30989
- };
30990
- var onOpenSaveFormModel = function () {
30991
31278
  if (!isFormChanged) {
30992
31279
  message.open({
30993
31280
  type: 'error',
@@ -30998,34 +31285,98 @@ var GHGProjectionsComponent = function (props) {
30998
31285
  }
30999
31286
  else {
31000
31287
  setActionInfo({
31001
- action: "".concat(t("ghgInventory:submit")),
31002
- headerText: "".concat(t("ghgInventory:submitModelHeader")),
31003
- type: "primary",
31004
- icon: React.createElement(CheckCircleOutlined, null),
31288
+ action: "".concat(t('ghgInventory:proceed')),
31289
+ headerText: "".concat(t('ghgInventory:discardHeaderText')),
31290
+ type: 'danger',
31291
+ icon: React.createElement(CloseCircleOutlined, null),
31005
31292
  });
31006
31293
  setErrorMsg('');
31007
- setOpenSaveFormModal(true);
31294
+ setOpenResetFormModal(true);
31008
31295
  }
31009
31296
  };
31297
+ var onSaveFormCanceled = function () {
31298
+ setOpenSaveFormModal(false);
31299
+ };
31300
+ var onOpenSaveFormModel = function () {
31301
+ var _a = form.getFieldsValue(true); _a.year; var rest = __rest(_a, ["year"]);
31302
+ var otherFieldsNegativeValue = Object.values(rest).some(function (value) {
31303
+ return typeof value === 'number' && value < 0;
31304
+ });
31305
+ form
31306
+ .validateFields()
31307
+ .then(function (values) {
31308
+ if (!isFormChanged) {
31309
+ message.open({
31310
+ type: 'error',
31311
+ content: t('ghgInventory:formNotChanged'),
31312
+ duration: 4,
31313
+ style: { textAlign: 'right', marginRight: 15, marginTop: 10 },
31314
+ });
31315
+ }
31316
+ else {
31317
+ setActionInfo({
31318
+ action: "".concat(t("ghgInventory:submit")),
31319
+ headerText: "".concat(t("ghgInventory:submitModelHeader")),
31320
+ type: "primary",
31321
+ icon: React.createElement(CheckCircleOutlined, null),
31322
+ });
31323
+ setErrorMsg('');
31324
+ setOpenSaveFormModal(true);
31325
+ }
31326
+ })
31327
+ .catch(function (errorInfo) {
31328
+ if (otherFieldsNegativeValue) {
31329
+ message.open({
31330
+ type: 'error',
31331
+ content: t('ghgInventory:negativeValuesNotAllowed'),
31332
+ duration: 4,
31333
+ style: { textAlign: 'right', marginRight: 15, marginTop: 10 },
31334
+ });
31335
+ }
31336
+ });
31337
+ };
31010
31338
  var onFinalizeFormCanceled = function () {
31011
31339
  setOpenFinalizeFormModal(false);
31012
31340
  };
31013
31341
  var onOpenFinalizeFormModel = function () {
31342
+ var _a = form.getFieldsValue(true); _a.year; var rest = __rest(_a, ["year"]);
31343
+ var otherFieldsEmpty = Object.values(rest).every(function (value) { return !value; });
31344
+ var otherFieldsNegativeValue = Object.values(rest).some(function (value) {
31345
+ return typeof value === 'number' && value < 0;
31346
+ });
31014
31347
  form
31015
31348
  .validateFields()
31016
31349
  .then(function (values) {
31017
31350
  // Validation successful, set ActionInfo and open the form modal
31018
- setActionInfo({
31019
- action: "".concat(t("ghgInventory:finalize")),
31020
- headerText: "".concat(t("ghgInventory:finalizeModelHeader")),
31021
- type: "primary",
31022
- icon: React.createElement(ClipboardCheck, null),
31023
- });
31024
- setErrorMsg('');
31025
- setOpenFinalizeFormModal(true);
31351
+ if (otherFieldsEmpty) {
31352
+ message.open({
31353
+ type: 'error',
31354
+ content: t('ghgInventory:cannotFinaliseEmpty'),
31355
+ duration: 4,
31356
+ style: { textAlign: 'right', marginRight: 15, marginTop: 10 },
31357
+ });
31358
+ }
31359
+ else {
31360
+ setActionInfo({
31361
+ action: "".concat(t("ghgInventory:finalize")),
31362
+ headerText: "".concat(t("ghgInventory:finalizeModelHeader")),
31363
+ type: "primary",
31364
+ icon: React.createElement(ClipboardCheck, null),
31365
+ });
31366
+ setErrorMsg('');
31367
+ setOpenFinalizeFormModal(true);
31368
+ }
31026
31369
  })
31027
31370
  .catch(function (errorInfo) {
31028
31371
  // Validation failed
31372
+ if (otherFieldsNegativeValue) {
31373
+ message.open({
31374
+ type: 'error',
31375
+ content: t('ghgInventory:negativeValuesNotAllowed'),
31376
+ duration: 4,
31377
+ style: { textAlign: 'right', marginRight: 15, marginTop: 10 },
31378
+ });
31379
+ }
31029
31380
  console.log('Validation failed:', errorInfo);
31030
31381
  });
31031
31382
  };
@@ -31089,7 +31440,7 @@ var GHGProjectionsComponent = function (props) {
31089
31440
  setLoading(true);
31090
31441
  _a.label = 2;
31091
31442
  case 2:
31092
- _a.trys.push([2, 6, 9, 10]);
31443
+ _a.trys.push([2, 6, 11, 12]);
31093
31444
  return [4 /*yield*/, post('national/projections', payload)];
31094
31445
  case 3:
31095
31446
  response = _a.sent();
@@ -31116,7 +31467,7 @@ var GHGProjectionsComponent = function (props) {
31116
31467
  case 4:
31117
31468
  _a.sent();
31118
31469
  _a.label = 5;
31119
- case 5: return [3 /*break*/, 10];
31470
+ case 5: return [3 /*break*/, 12];
31120
31471
  case 6:
31121
31472
  error_2 = _a.sent();
31122
31473
  console.log('Error in projection creation - ', error_2);
@@ -31128,19 +31479,31 @@ var GHGProjectionsComponent = function (props) {
31128
31479
  duration: 4,
31129
31480
  style: { textAlign: 'right', marginRight: 15, marginTop: 10 },
31130
31481
  });
31131
- if (!(error_2.statusCode == HttpStatusCode.Conflict)) return [3 /*break*/, 8];
31482
+ if (!(error_2.status === HttpStatusCode.Conflict.valueOf())) return [3 /*break*/, 8];
31132
31483
  return [4 /*yield*/, getProjectionData()];
31133
31484
  case 7:
31134
31485
  _a.sent();
31486
+ setIsSavedFormDataSet(false);
31487
+ clearUploadDoc();
31488
+ if (!isPendingFinalization) {
31489
+ clearForm();
31490
+ }
31491
+ return [3 /*break*/, 10];
31492
+ case 8:
31493
+ if (!(error_2.status === HttpStatusCode.Forbidden.valueOf())) return [3 /*break*/, 10];
31135
31494
  clearUploadDoc();
31136
- _a.label = 8;
31137
- case 8: return [3 /*break*/, 10];
31495
+ clearForm();
31496
+ return [4 /*yield*/, getProjectionData()];
31138
31497
  case 9:
31498
+ _a.sent();
31499
+ _a.label = 10;
31500
+ case 10: return [3 /*break*/, 12];
31501
+ case 11:
31139
31502
  // eslint-disable-next-line no-use-before-define, @typescript-eslint/no-use-before-define
31140
31503
  setIsFormChanged(false);
31141
31504
  setLoading(false);
31142
31505
  return [7 /*endfinally*/];
31143
- case 10: return [2 /*return*/];
31506
+ case 12: return [2 /*return*/];
31144
31507
  }
31145
31508
  });
31146
31509
  }); };
@@ -31569,13 +31932,55 @@ var GHGProjectionsComponent = function (props) {
31569
31932
  React.createElement(Col, { xl: 9, md: 9 },
31570
31933
  React.createElement(Row, { gutter: 16, className: "panel-content-input-box-row" },
31571
31934
  React.createElement(Col, { xl: 7 },
31572
- React.createElement(Form.Item, { name: panelHeading + '_' + item + '_bau' },
31935
+ React.createElement(Form.Item, { name: panelHeading + '_' + item + '_bau', rules: [
31936
+ {
31937
+ validator: function (rule, value) { return __awaiter(void 0, void 0, void 0, function () {
31938
+ return __generator(this, function (_a) {
31939
+ if (value && value < 0) {
31940
+ throw new Error();
31941
+ }
31942
+ if (value && !Number.isInteger(value)) {
31943
+ throw new Error();
31944
+ }
31945
+ return [2 /*return*/];
31946
+ });
31947
+ }); },
31948
+ },
31949
+ ] },
31573
31950
  React.createElement(InputNumber, { onChange: function (event) { return calculateSumBau(event, panelHeading); } }))),
31574
31951
  React.createElement(Col, { xl: 7 },
31575
- React.createElement(Form.Item, { name: panelHeading + '_' + item + '_conditionalNdc' },
31952
+ React.createElement(Form.Item, { name: panelHeading + '_' + item + '_conditionalNdc', rules: [
31953
+ {
31954
+ validator: function (rule, value) { return __awaiter(void 0, void 0, void 0, function () {
31955
+ return __generator(this, function (_a) {
31956
+ if (value && value < 0) {
31957
+ throw new Error();
31958
+ }
31959
+ if (value && !Number.isInteger(value)) {
31960
+ throw new Error();
31961
+ }
31962
+ return [2 /*return*/];
31963
+ });
31964
+ }); },
31965
+ },
31966
+ ] },
31576
31967
  React.createElement(InputNumber, { onChange: function (event) { return calculateSumConditionalNdc(event, panelHeading); } }))),
31577
31968
  React.createElement(Col, { xl: 7 },
31578
- React.createElement(Form.Item, { name: panelHeading + '_' + item + '_unconditionalNdc' },
31969
+ React.createElement(Form.Item, { name: panelHeading + '_' + item + '_unconditionalNdc', rules: [
31970
+ {
31971
+ validator: function (rule, value) { return __awaiter(void 0, void 0, void 0, function () {
31972
+ return __generator(this, function (_a) {
31973
+ if (value && value < 0) {
31974
+ throw new Error();
31975
+ }
31976
+ if (value && !Number.isInteger(value)) {
31977
+ throw new Error();
31978
+ }
31979
+ return [2 /*return*/];
31980
+ });
31981
+ }); },
31982
+ },
31983
+ ] },
31579
31984
  React.createElement(InputNumber, { onChange: function (event) { return calculateSumUnconditionalNdc(event, panelHeading); } }))))))); };
31580
31985
  var renderPanelContentView = function (bau, conditionalNdc, unconditionalNdc, item, index) {
31581
31986
  return (React.createElement(Row, { gutter: 16, key: index, className: "panel-content-row" },
@@ -31635,7 +32040,7 @@ var GHGProjectionsComponent = function (props) {
31635
32040
  var encodedUri = encodeURI("data:text/csv;charset=utf-8,".concat(csvContent));
31636
32041
  var link = document.createElement('a');
31637
32042
  link.setAttribute('href', encodedUri);
31638
- link.setAttribute('download', "GHG-Reporting Projections_".concat(dataToDownload.year, "_V").concat(dataToDownload.version, ".csv"));
32043
+ link.setAttribute('download', "GHG-Reporting-Projections_".concat(dataToDownload.year, "_V").concat(dataToDownload.version, ".csv"));
31639
32044
  document.body.appendChild(link);
31640
32045
  link.click();
31641
32046
  };
@@ -31657,6 +32062,17 @@ var GHGProjectionsComponent = function (props) {
31657
32062
  }
31658
32063
  return false;
31659
32064
  };
32065
+ var canViewForm = function () {
32066
+ if ((userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.companyRole) === CompanyRole.GOVERNMENT || (userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.companyRole) === CompanyRole.MINISTRY) {
32067
+ if ((userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.userRole) === Role.ViewOnly && data.some(function (item) { return item.state === 'SAVED'; })) {
32068
+ return true;
32069
+ }
32070
+ else if ((userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.userRole) !== Role.ViewOnly) {
32071
+ return true;
32072
+ }
32073
+ }
32074
+ return false;
32075
+ };
31660
32076
  return (React.createElement("div", null,
31661
32077
  React.createElement("div", { className: "content-container projection-tab-container" },
31662
32078
  React.createElement("div", { className: "projection-title-bar" },
@@ -31665,8 +32081,7 @@ var GHGProjectionsComponent = function (props) {
31665
32081
  React.createElement("div", { className: "body-sub-title" }, t("ghgInventory:totalNationalEmissionSubTitle")))),
31666
32082
  React.createElement("div", { className: "content-card add-projection" },
31667
32083
  React.createElement(Tabs, { defaultActiveKey: "Add New", centered: true },
31668
- ((userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.companyRole) === CompanyRole.GOVERNMENT ||
31669
- (userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.companyRole) === CompanyRole.MINISTRY) && (React.createElement(Tabs.TabPane, { key: "Add New", tab: t("ghgInventory:addNew") },
32084
+ (canViewForm()) && (React.createElement(Tabs.TabPane, { key: "Add New", tab: t("ghgInventory:addNew") },
31670
32085
  React.createElement("div", null,
31671
32086
  React.createElement(Form, { labelCol: { span: 20 }, wrapperCol: { span: 24 }, name: "add-projection", className: "programme-details-form", layout: "vertical", requiredMark: true, form: form, onValuesChange: onValuesChange, onFinish: onOpenSaveFormModel },
31672
32087
  React.createElement(Row, null,
@@ -31716,10 +32131,8 @@ var GHGProjectionsComponent = function (props) {
31716
32131
  var workbook = XLSX.read(xldata, { type: 'array' });
31717
32132
  var sheetName = workbook.SheetNames[0];
31718
32133
  var sheet = workbook.Sheets[sheetName];
31719
- var firstRow = XLSX.utils.sheet_to_json(sheet, {
31720
- header: 1,
31721
- })[0];
31722
- if (!validateExcelDataFormat(firstRow)) {
32134
+ var excelData = XLSX.utils.sheet_to_json(sheet);
32135
+ if (!validateExcelDataFormat(sheet, excelData)) {
31723
32136
  message.open({
31724
32137
  type: 'error',
31725
32138
  content: t('ghgInventory:invalidDataInExcel'),
@@ -31732,7 +32145,6 @@ var GHGProjectionsComponent = function (props) {
31732
32145
  });
31733
32146
  return false;
31734
32147
  }
31735
- var excelData = XLSX.utils.sheet_to_json(sheet);
31736
32148
  handleFileUploadData(excelData);
31737
32149
  setUploadedFileName(file.name);
31738
32150
  }
@@ -31791,13 +32203,55 @@ var GHGProjectionsComponent = function (props) {
31791
32203
  React.createElement(Col, { xl: 9, md: 9 },
31792
32204
  React.createElement(Row, { gutter: 16, className: "panel-content-input-box-row total-co2-land-input-box-row" },
31793
32205
  React.createElement(Col, { xl: 7 },
31794
- React.createElement(Form.Item, { name: "totalCo2WithoutLand_bau" },
32206
+ React.createElement(Form.Item, { name: "totalCo2WithoutLand_bau", rules: [
32207
+ {
32208
+ validator: function (rule, value) { return __awaiter(void 0, void 0, void 0, function () {
32209
+ return __generator(this, function (_a) {
32210
+ if (value && value < 0) {
32211
+ throw new Error();
32212
+ }
32213
+ if (value && !Number.isInteger(value)) {
32214
+ throw new Error();
32215
+ }
32216
+ return [2 /*return*/];
32217
+ });
32218
+ }); },
32219
+ },
32220
+ ] },
31795
32221
  React.createElement(InputNumber, null))),
31796
32222
  React.createElement(Col, { xl: 7 },
31797
- React.createElement(Form.Item, { name: "totalCo2WithoutLand_conditionalNdc" },
32223
+ React.createElement(Form.Item, { name: "totalCo2WithoutLand_conditionalNdc", rules: [
32224
+ {
32225
+ validator: function (rule, value) { return __awaiter(void 0, void 0, void 0, function () {
32226
+ return __generator(this, function (_a) {
32227
+ if (value && value < 0) {
32228
+ throw new Error();
32229
+ }
32230
+ if (value && !Number.isInteger(value)) {
32231
+ throw new Error();
32232
+ }
32233
+ return [2 /*return*/];
32234
+ });
32235
+ }); },
32236
+ },
32237
+ ] },
31798
32238
  React.createElement(InputNumber, null))),
31799
32239
  React.createElement(Col, { xl: 7 },
31800
- React.createElement(Form.Item, { name: "totalCo2WithoutLand_unconditionalNdc" },
32240
+ React.createElement(Form.Item, { name: "totalCo2WithoutLand_unconditionalNdc", rules: [
32241
+ {
32242
+ validator: function (rule, value) { return __awaiter(void 0, void 0, void 0, function () {
32243
+ return __generator(this, function (_a) {
32244
+ if (value && value < 0) {
32245
+ throw new Error();
32246
+ }
32247
+ if (value && !Number.isInteger(value)) {
32248
+ throw new Error();
32249
+ }
32250
+ return [2 /*return*/];
32251
+ });
32252
+ }); },
32253
+ },
32254
+ ] },
31801
32255
  React.createElement(InputNumber, null)))))),
31802
32256
  React.createElement(Row, { gutter: 16, key: 'totalCo2WithLand', className: "total-co2-with-land-row" },
31803
32257
  React.createElement(Col, { xl: 12, md: 12, className: "total-co2-with-land-title" },
@@ -31805,19 +32259,63 @@ var GHGProjectionsComponent = function (props) {
31805
32259
  React.createElement(Col, { xl: 9, md: 9 },
31806
32260
  React.createElement(Row, { gutter: 16, className: "panel-content-input-box-row total-co2-land-input-box-row" },
31807
32261
  React.createElement(Col, { xl: 7 },
31808
- React.createElement(Form.Item, { name: "totalCo2WithLand_bau" },
32262
+ React.createElement(Form.Item, { name: "totalCo2WithLand_bau", rules: [
32263
+ {
32264
+ validator: function (rule, value) { return __awaiter(void 0, void 0, void 0, function () {
32265
+ return __generator(this, function (_a) {
32266
+ if (value && value < 0) {
32267
+ throw new Error();
32268
+ }
32269
+ if (value && !Number.isInteger(value)) {
32270
+ throw new Error();
32271
+ }
32272
+ return [2 /*return*/];
32273
+ });
32274
+ }); },
32275
+ },
32276
+ ] },
31809
32277
  React.createElement(InputNumber, null))),
31810
32278
  React.createElement(Col, { xl: 7 },
31811
- React.createElement(Form.Item, { name: "totalCo2WithLand_conditionalNdc" },
32279
+ React.createElement(Form.Item, { name: "totalCo2WithLand_conditionalNdc", rules: [
32280
+ {
32281
+ validator: function (rule, value) { return __awaiter(void 0, void 0, void 0, function () {
32282
+ return __generator(this, function (_a) {
32283
+ if (value && value < 0) {
32284
+ throw new Error();
32285
+ }
32286
+ if (value && !Number.isInteger(value)) {
32287
+ throw new Error();
32288
+ }
32289
+ return [2 /*return*/];
32290
+ });
32291
+ }); },
32292
+ },
32293
+ ] },
31812
32294
  React.createElement(InputNumber, null))),
31813
32295
  React.createElement(Col, { xl: 7 },
31814
- React.createElement(Form.Item, { name: "totalCo2WithLand_unconditionalNdc" },
32296
+ React.createElement(Form.Item, { name: "totalCo2WithLand_unconditionalNdc", rules: [
32297
+ {
32298
+ validator: function (rule, value) { return __awaiter(void 0, void 0, void 0, function () {
32299
+ return __generator(this, function (_a) {
32300
+ if (value && value < 0) {
32301
+ throw new Error();
32302
+ }
32303
+ if (value && !Number.isInteger(value)) {
32304
+ throw new Error();
32305
+ }
32306
+ return [2 /*return*/];
32307
+ });
32308
+ }); },
32309
+ },
32310
+ ] },
31815
32311
  React.createElement(InputNumber, null)))))),
31816
- React.createElement("div", { className: "steps-actions" },
31817
- (userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.companyRole) === CompanyRole.GOVERNMENT &&
31818
- (React.createElement(Button, { className: "finalize-btn", type: "primary", loading: loading, onClick: onOpenFinalizeFormModel }, "Finalise")),
31819
- React.createElement(Button, { className: "submit-btn", type: "primary", htmlType: "submit", loading: loading }, "Submit"),
31820
- React.createElement(Button, { className: "back-btn", onClick: onOpenResetFormModel, loading: loading }, "Cancel")))))),
32312
+ (((userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.companyRole) === CompanyRole.GOVERNMENT || (userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.companyRole) === CompanyRole.MINISTRY)
32313
+ && ((userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.userRole) !== Role.ViewOnly)) &&
32314
+ (React.createElement("div", { className: "steps-actions" },
32315
+ (userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.companyRole) === CompanyRole.GOVERNMENT &&
32316
+ (React.createElement(Button, { className: "finalize-btn", type: "primary", loading: loading, onClick: onOpenFinalizeFormModel }, "Finalise")),
32317
+ React.createElement(Button, { className: "submit-btn", type: "primary", onClick: onOpenSaveFormModel, loading: loading }, "Submit"),
32318
+ React.createElement(Button, { className: "back-btn", onClick: onOpenResetFormModel, loading: loading }, "Cancel"))))))),
31821
32319
  data.map(function (tabData) {
31822
32320
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
31823
32321
  return tabData.state === 'FINALIZED' && (React.createElement(Tabs.TabPane, { className: 'view-data-panel', key: tabData.id.toString(), tab: React.createElement("span", null,
@@ -31837,7 +32335,7 @@ var GHGProjectionsComponent = function (props) {
31837
32335
  React.createElement(Row, { className: "add-new-upload-file-label" }, t("ghgInventory:emissionRemovalDocument")),
31838
32336
  React.createElement(Row, null,
31839
32337
  React.createElement(Col, { xl: 15, md: 15, className: "view-download-file-name-input" },
31840
- React.createElement(Input, { value: "GHG-Reporting Projections_".concat(tabData.year, "_V").concat(tabData.version, ".csv"), disabled: true })),
32338
+ React.createElement(Input, { value: "GHG-Reporting-Projections_".concat(tabData.year, "_V").concat(tabData.version, ".csv"), disabled: true })),
31841
32339
  React.createElement(Col, { xl: 5, md: 5, className: "view-download-file-inner-col" },
31842
32340
  React.createElement(Button, { icon: React.createElement(DownloadOutlined, null), onClick: function () { downloadCSV(tabData); } }, t("ghgInventory:download")))))),
31843
32341
  React.createElement(Row, { gutter: 16 },