From 0d3e9950a2e19ab17ba1e7831ae6d2a97c6adb9c Mon Sep 17 00:00:00 2001 From: SnehaRH <77656297+snehar-nd@users.noreply.github.com> Date: Wed, 23 Sep 2026 15:01:40 +0530 Subject: [PATCH] fix: correct one-day-early date in report Criteria sheet exports Several inventory report exports (daily stock detail, daily stock summary, short expiry, transit, inward stock, expiry, beneficiary drug issue, consumption) push a raw JS Date object (from the Material datepicker, set at local midnight) directly into the ExcelJS "Criteria" worksheet row. ExcelJS's dateToExcel() serializes Date cells using the absolute UTC epoch with no timezone correction, so a Date built at local midnight in IST (UTC+5:30) lands on the previous UTC day once written to the sheet - the Criteria tab shows a date one day earlier than what was selected. Monthly and Yearly reports were unaffected because they never carry a Date object in their criteria (only a month name / year number). Fix: format the date into a plain dd-mm-yyyy string using local getters (not toISOString(), which reintroduces the same UTC shift) before pushing it into the criteria row. This matches a fix already present, but never committed, in daily-stock-details-report. --- .../beneficiary-drug-issue-report.component.ts | 17 +++++++++++++++-- .../consumption-report.component.ts | 17 +++++++++++++++-- .../daily-stock-details-report.component.ts | 17 +++++++++++++++-- .../daily-stock-summary-report.component.ts | 17 +++++++++++++++-- .../expiry-report/expiry-report.component.ts | 17 +++++++++++++++-- .../inward-stock-report.component.ts | 17 +++++++++++++++-- .../short-expiry-report.component.ts | 12 +++++++++++- .../transit-report/transit-report.component.ts | 17 +++++++++++++++-- 8 files changed, 116 insertions(+), 15 deletions(-) diff --git a/src/app/app-modules/inventory/reports/beneficiary-drug-issue-report/beneficiary-drug-issue-report.component.ts b/src/app/app-modules/inventory/reports/beneficiary-drug-issue-report/beneficiary-drug-issue-report.component.ts index 499298b..b72a693 100644 --- a/src/app/app-modules/inventory/reports/beneficiary-drug-issue-report/beneficiary-drug-issue-report.component.ts +++ b/src/app/app-modules/inventory/reports/beneficiary-drug-issue-report/beneficiary-drug-issue-report.component.ts @@ -153,8 +153,21 @@ export class BeneficiaryDrugIssueReportComponent implements OnInit, DoCheck { getResponseOfSearchThenDo() { const criteria: any = []; - criteria.push({ Filter_Name: 'Start_Date', value: this.startDate }); - criteria.push({ Filter_Name: 'End_Date', value: this.endDate }); + const formatLocalDate = (d: any) => { + const dt = new Date(d); + const dd = String(dt.getDate()).padStart(2, '0'); + const mm = String(dt.getMonth() + 1).padStart(2, '0'); + const yyyy = dt.getFullYear(); + return `${dd}-${mm}-${yyyy}`; + }; + criteria.push({ + Filter_Name: 'Start_Date', + value: formatLocalDate(this.startDate), + }); + criteria.push({ + Filter_Name: 'End_Date', + value: formatLocalDate(this.endDate), + }); this.exportToxlsx(criteria); } exportToxlsx(criteria: any) { diff --git a/src/app/app-modules/inventory/reports/consumption-report/consumption-report.component.ts b/src/app/app-modules/inventory/reports/consumption-report/consumption-report.component.ts index 8744184..060e2d3 100644 --- a/src/app/app-modules/inventory/reports/consumption-report/consumption-report.component.ts +++ b/src/app/app-modules/inventory/reports/consumption-report/consumption-report.component.ts @@ -166,8 +166,21 @@ export class ConsumptionReportComponent implements OnInit, DoCheck { getResponseOfSearchThenDo() { const criteria: any = []; - criteria.push({ Filter_Name: 'Start_Date', value: this.startDate }); - criteria.push({ Filter_Name: 'End_Date', value: this.endDate }); + const formatLocalDate = (d: any) => { + const dt = new Date(d); + const dd = String(dt.getDate()).padStart(2, '0'); + const mm = String(dt.getMonth() + 1).padStart(2, '0'); + const yyyy = dt.getFullYear(); + return `${dd}-${mm}-${yyyy}`; + }; + criteria.push({ + Filter_Name: 'Start_Date', + value: formatLocalDate(this.startDate), + }); + criteria.push({ + Filter_Name: 'End_Date', + value: formatLocalDate(this.endDate), + }); this.exportToxlsx(criteria); } exportToxlsx(criteria: any) { diff --git a/src/app/app-modules/inventory/reports/daily-stock-details-report/daily-stock-details-report.component.ts b/src/app/app-modules/inventory/reports/daily-stock-details-report/daily-stock-details-report.component.ts index 1da4760..7909587 100644 --- a/src/app/app-modules/inventory/reports/daily-stock-details-report/daily-stock-details-report.component.ts +++ b/src/app/app-modules/inventory/reports/daily-stock-details-report/daily-stock-details-report.component.ts @@ -165,8 +165,21 @@ export class DailyStockDetailsReportComponent implements OnInit, DoCheck { getResponseOfSearchThenDo() { const criteria: any = []; - criteria.push({ Filter_Name: 'Start_Date', value: this.startDate }); - criteria.push({ Filter_Name: 'End_Date', value: this.endDate }); + const formatLocalDate = (d: any) => { + const dt = new Date(d); + const dd = String(dt.getDate()).padStart(2, '0'); + const mm = String(dt.getMonth() + 1).padStart(2, '0'); + const yyyy = dt.getFullYear(); + return `${dd}-${mm}-${yyyy}`; + }; + criteria.push({ + Filter_Name: 'Start_Date', + value: formatLocalDate(this.startDate), + }); + criteria.push({ + Filter_Name: 'End_Date', + value: formatLocalDate(this.endDate), + }); this.exportToxlsx(criteria); } exportToxlsx(criteria: any) { diff --git a/src/app/app-modules/inventory/reports/daily-stock-summary-report/daily-stock-summary-report.component.ts b/src/app/app-modules/inventory/reports/daily-stock-summary-report/daily-stock-summary-report.component.ts index ba55130..b3e91da 100644 --- a/src/app/app-modules/inventory/reports/daily-stock-summary-report/daily-stock-summary-report.component.ts +++ b/src/app/app-modules/inventory/reports/daily-stock-summary-report/daily-stock-summary-report.component.ts @@ -165,8 +165,21 @@ export class DailyStockSummaryReportComponent implements OnInit, DoCheck { getResponseOfSearchThenDo() { const criteria: any = []; - criteria.push({ Filter_Name: 'Start_Date', value: this.startDate }); - criteria.push({ Filter_Name: 'End_Date', value: this.endDate }); + const formatLocalDate = (d: any) => { + const dt = new Date(d); + const dd = String(dt.getDate()).padStart(2, '0'); + const mm = String(dt.getMonth() + 1).padStart(2, '0'); + const yyyy = dt.getFullYear(); + return `${dd}-${mm}-${yyyy}`; + }; + criteria.push({ + Filter_Name: 'Start_Date', + value: formatLocalDate(this.startDate), + }); + criteria.push({ + Filter_Name: 'End_Date', + value: formatLocalDate(this.endDate), + }); this.exportToxlsx(criteria); } exportToxlsx(criteria: any) { diff --git a/src/app/app-modules/inventory/reports/expiry-report/expiry-report.component.ts b/src/app/app-modules/inventory/reports/expiry-report/expiry-report.component.ts index 03dda08..7b6cdbe 100644 --- a/src/app/app-modules/inventory/reports/expiry-report/expiry-report.component.ts +++ b/src/app/app-modules/inventory/reports/expiry-report/expiry-report.component.ts @@ -142,8 +142,21 @@ export class ExpiryReportComponent implements OnInit, DoCheck { getResponseOfSearchThenDo() { const criteria: any = []; - criteria.push({ Filter_Name: 'Start_Date', value: this.startDate }); - criteria.push({ Filter_Name: 'End_Date', value: this.endDate }); + const formatLocalDate = (d: any) => { + const dt = new Date(d); + const dd = String(dt.getDate()).padStart(2, '0'); + const mm = String(dt.getMonth() + 1).padStart(2, '0'); + const yyyy = dt.getFullYear(); + return `${dd}-${mm}-${yyyy}`; + }; + criteria.push({ + Filter_Name: 'Start_Date', + value: formatLocalDate(this.startDate), + }); + criteria.push({ + Filter_Name: 'End_Date', + value: formatLocalDate(this.endDate), + }); this.exportToxlsx(criteria); } exportToxlsx(criteria: any) { diff --git a/src/app/app-modules/inventory/reports/inward-stock-report/inward-stock-report.component.ts b/src/app/app-modules/inventory/reports/inward-stock-report/inward-stock-report.component.ts index de44dca..5f11054 100644 --- a/src/app/app-modules/inventory/reports/inward-stock-report/inward-stock-report.component.ts +++ b/src/app/app-modules/inventory/reports/inward-stock-report/inward-stock-report.component.ts @@ -168,8 +168,21 @@ export class InwardStockReportComponent implements OnInit, DoCheck { getResponseOfSearchThenDo() { const criteria: any = []; - criteria.push({ Filter_Name: 'Start_Date', value: this.startDate }); - criteria.push({ Filter_Name: 'End_Date', value: this.endDate }); + const formatLocalDate = (d: any) => { + const dt = new Date(d); + const dd = String(dt.getDate()).padStart(2, '0'); + const mm = String(dt.getMonth() + 1).padStart(2, '0'); + const yyyy = dt.getFullYear(); + return `${dd}-${mm}-${yyyy}`; + }; + criteria.push({ + Filter_Name: 'Start_Date', + value: formatLocalDate(this.startDate), + }); + criteria.push({ + Filter_Name: 'End_Date', + value: formatLocalDate(this.endDate), + }); this.exportToxlsx(criteria); } exportToxlsx(criteria: any) { diff --git a/src/app/app-modules/inventory/reports/short-expiry-report/short-expiry-report.component.ts b/src/app/app-modules/inventory/reports/short-expiry-report/short-expiry-report.component.ts index d36eab4..79a118b 100644 --- a/src/app/app-modules/inventory/reports/short-expiry-report/short-expiry-report.component.ts +++ b/src/app/app-modules/inventory/reports/short-expiry-report/short-expiry-report.component.ts @@ -118,7 +118,17 @@ export class ShortExpiryReportComponent implements OnInit, DoCheck { getResponseOfSearchThenDo() { const criteria: any = []; - criteria.push({ Filter_Name: 'Start_Date', value: this.startDate }); + const formatLocalDate = (d: any) => { + const dt = new Date(d); + const dd = String(dt.getDate()).padStart(2, '0'); + const mm = String(dt.getMonth() + 1).padStart(2, '0'); + const yyyy = dt.getFullYear(); + return `${dd}-${mm}-${yyyy}`; + }; + criteria.push({ + Filter_Name: 'Start_Date', + value: formatLocalDate(this.startDate), + }); this.exportToxlsx(criteria); } exportToxlsx(criteria: any) { diff --git a/src/app/app-modules/inventory/reports/transit-report/transit-report.component.ts b/src/app/app-modules/inventory/reports/transit-report/transit-report.component.ts index c18e289..3dca64e 100644 --- a/src/app/app-modules/inventory/reports/transit-report/transit-report.component.ts +++ b/src/app/app-modules/inventory/reports/transit-report/transit-report.component.ts @@ -143,8 +143,21 @@ export class TransitReportComponent implements OnInit, DoCheck { getResponseOfSearchThenDo() { const criteria: any = []; - criteria.push({ Filter_Name: 'Start_Date', value: this.startDate }); - criteria.push({ Filter_Name: 'End_Date', value: this.endDate }); + const formatLocalDate = (d: any) => { + const dt = new Date(d); + const dd = String(dt.getDate()).padStart(2, '0'); + const mm = String(dt.getMonth() + 1).padStart(2, '0'); + const yyyy = dt.getFullYear(); + return `${dd}-${mm}-${yyyy}`; + }; + criteria.push({ + Filter_Name: 'Start_Date', + value: formatLocalDate(this.startDate), + }); + criteria.push({ + Filter_Name: 'End_Date', + value: formatLocalDate(this.endDate), + }); this.exportToxlsx(criteria); } exportToxlsx(criteria: any) {