@mody-park-cha-raja/finance_common 4.29.1-beta.9 → 4.30.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -918,6 +918,26 @@ type FlatScopeRow = {
918
918
  declare function getWingSelectionLabel(selection: string, specials?: readonly string[]): string;
919
919
  declare function getWingSelectionSlug(selection: string, specials?: readonly string[]): string;
920
920
  declare function buildWingWiseCollectionReport(donations: WingCollectionDonationLike[], year: number, selection: string, flats?: readonly FlatScopeRow[]): WingCollectionReport;
921
+ /** Donation shape matched by flat entity id (flatId-only reads). */
922
+ interface WingCollectionDonationByIdLike {
923
+ flatId?: Nullable<number>;
924
+ amount: number;
925
+ receiptNumber?: string;
926
+ paymentType?: string;
927
+ createdOn?: number;
928
+ }
929
+ type FlatIdScopeRow = {
930
+ id: number;
931
+ wing?: string | null;
932
+ unitNumber: string;
933
+ };
934
+ /**
935
+ * flatId-keyed variant of buildWingWiseCollectionReport — donations are
936
+ * grouped by their flat ENTITY id and labels derive from the flat itself.
937
+ * Donations without a resolvable flat are silently excluded. The flats list
938
+ * is required (ids cannot be inferred from statics).
939
+ */
940
+ declare function buildWingWiseCollectionReportByFlatId(donations: WingCollectionDonationByIdLike[], year: number, selection: string, flats: readonly FlatIdScopeRow[]): WingCollectionReport;
921
941
  declare function buildWingWiseCollectionWorkbook(report: WingCollectionReport): XLSX.WorkBook;
922
942
 
923
943
  type XlsxSerializationType = 'base64' | 'array' | 'binary';
@@ -1127,4 +1147,4 @@ declare function isSpecialFlatLabel(label: string): boolean;
1127
1147
  declare function getFlatValidationErrors(input: Partial<IFlatEntity>): FlatValidationError[];
1128
1148
  declare function validateFlatOrThrow(input: Partial<IFlatEntity>): void;
1129
1149
 
1130
- export { ALL_WINGS_SELECTION, BadRequestException, BaseEntityModel, ConfigurationKey, ConfigurationModel, ConfigurationType, DateCodeUtils, DateUtil, DonationHistoryModel, DonationModel, EntityFilterDataHelper, EntityHistoryOperation, EntityList, type EntityListEntityModelMap, type EntityModelType, EntityStatus, type EntityType, ExpenseHeadHistoryModel, ExpenseHeadModel, ExpenseHistoryModel, ExpenseModel, FLATS_BY_WING, FLAT_DONATION_RELATION_CONFIG, FLAT_NUMBERS, FLAT_UNIT_NUMBER_PATTERN, FLAT_WING_PATTERN, type FlatCollectionEntry, type FlatCollectionStatus, type FlatDonationLike, FlatHistoryModel, type FlatIdDonationLike, FlatModel, type FlatOption, type FlatParseResult, type FlatValidationError, ForbiddenException, HttpException, type IAuditColumnEntity, type IBaseHistoryEntity, type ICashBookEntry, type IConfigurationCreateDto, type IConfigurationEntity, type IConfigurationSearchDto, type IConfigurationUpdateDto, type IDonationCreateDto, type IDonationEntity, type IDonationHistoryEntity, type IDonationSearchDto, type IDonationUpdateDto, type IDtoValidationError, type IEntityCreateDto, type IEntityFilterData, type IEntityFilterSearchData, type IEntityFilterSearchDataV2, type IEntityUpdateDto, type IExpenseCreateDto, type IExpenseEntity, type IExpenseHeadCreateDto, type IExpenseHeadEntity, type IExpenseHeadHistoryEntity, type IExpenseHeadSearchDto, type IExpenseHeadUpdateDto, type IExpenseHistoryEntity, type IExpenseSearchDto, type IExpenseUpdateDto, type IFlatCreateDto, type IFlatEntity, type IFlatHistoryEntity, type IFlatSearchDto, type IFlatUpdateDto, type IMappingPropertyEntry, type IModelRelationConfig, type ISearchV2Response, type ISponsorCreateDto, type ISponsorEntity, type ISponsorHistoryEntity, type ISponsorSearchDto, type ISponsorUpdateDto, type ITransactionCreateDto, type ITransactionEntity, type ITransactionHistoryEntity, type ITransactionSearchDto, type ITransactionUpdateDto, type IUserCreateDto, type IUserEntity, type IUserHistoryEntity, type IUserSearchDto, type IUserUpdateDto, type IVendorCreateDto, type IVendorEntity, type IVendorHistoryEntity, type IVendorSearchDto, type IVendorUpdateDto, NotFoundException, type Nullable, OrderByDirection, PAYMENT_OPTIONS, PaymentType, ReferenceIdPrefix, RelationType, SHOP_UNIT_NUMBER_PATTERN, SHOP_WING, SPECIAL_FLATS, SPECIAL_FLAT_LABELS, SponsorHistoryModel, SponsorModel, SponsorTier, TransactionEntityType, TransactionHistoryModel, TransactionModel, TransactionType, USER_RELATION_CONFIG, UnauthorizedException, type UserExpenseReport, type UserExpenseReportTotals, type UserExpenseRow, UserHistoryModel, UserModel, VendorHistoryModel, VendorModel, VendorType, WINGS, WING_ALPHABETS, type WingCollectionDonationLike, type WingCollectionReport, type WingCollectionRow, type WingCollectionTotals, type XlsxCellAddress, type XlsxMergeRange, type XlsxSerializationType, type XlsxSheetInput, type XlsxSheetOptions, buildUserExpenseReport, buildUserExpenseWorkbook, buildWingWiseCollectionReport, buildWingWiseCollectionWorkbook, buildXlsxWorkbook, convertNumberToWords, definedValues, diffArrays, entityListEntityModelMap, epochToReadableDate, getFlatValidationErrors, getObjectDiffingKeys, getWingSelectionLabel, getWingSelectionSlug, groupBy, isSpecialFlatLabel, isValidFlatWing, roundToTwoDecimals, serializeXlsx, validateFlatOrThrow };
1150
+ export { ALL_WINGS_SELECTION, BadRequestException, BaseEntityModel, ConfigurationKey, ConfigurationModel, ConfigurationType, DateCodeUtils, DateUtil, DonationHistoryModel, DonationModel, EntityFilterDataHelper, EntityHistoryOperation, EntityList, type EntityListEntityModelMap, type EntityModelType, EntityStatus, type EntityType, ExpenseHeadHistoryModel, ExpenseHeadModel, ExpenseHistoryModel, ExpenseModel, FLATS_BY_WING, FLAT_DONATION_RELATION_CONFIG, FLAT_NUMBERS, FLAT_UNIT_NUMBER_PATTERN, FLAT_WING_PATTERN, type FlatCollectionEntry, type FlatCollectionStatus, type FlatDonationLike, FlatHistoryModel, type FlatIdDonationLike, FlatModel, type FlatOption, type FlatParseResult, type FlatValidationError, ForbiddenException, HttpException, type IAuditColumnEntity, type IBaseHistoryEntity, type ICashBookEntry, type IConfigurationCreateDto, type IConfigurationEntity, type IConfigurationSearchDto, type IConfigurationUpdateDto, type IDonationCreateDto, type IDonationEntity, type IDonationHistoryEntity, type IDonationSearchDto, type IDonationUpdateDto, type IDtoValidationError, type IEntityCreateDto, type IEntityFilterData, type IEntityFilterSearchData, type IEntityFilterSearchDataV2, type IEntityUpdateDto, type IExpenseCreateDto, type IExpenseEntity, type IExpenseHeadCreateDto, type IExpenseHeadEntity, type IExpenseHeadHistoryEntity, type IExpenseHeadSearchDto, type IExpenseHeadUpdateDto, type IExpenseHistoryEntity, type IExpenseSearchDto, type IExpenseUpdateDto, type IFlatCreateDto, type IFlatEntity, type IFlatHistoryEntity, type IFlatSearchDto, type IFlatUpdateDto, type IMappingPropertyEntry, type IModelRelationConfig, type ISearchV2Response, type ISponsorCreateDto, type ISponsorEntity, type ISponsorHistoryEntity, type ISponsorSearchDto, type ISponsorUpdateDto, type ITransactionCreateDto, type ITransactionEntity, type ITransactionHistoryEntity, type ITransactionSearchDto, type ITransactionUpdateDto, type IUserCreateDto, type IUserEntity, type IUserHistoryEntity, type IUserSearchDto, type IUserUpdateDto, type IVendorCreateDto, type IVendorEntity, type IVendorHistoryEntity, type IVendorSearchDto, type IVendorUpdateDto, NotFoundException, type Nullable, OrderByDirection, PAYMENT_OPTIONS, PaymentType, ReferenceIdPrefix, RelationType, SHOP_UNIT_NUMBER_PATTERN, SHOP_WING, SPECIAL_FLATS, SPECIAL_FLAT_LABELS, SponsorHistoryModel, SponsorModel, SponsorTier, TransactionEntityType, TransactionHistoryModel, TransactionModel, TransactionType, USER_RELATION_CONFIG, UnauthorizedException, type UserExpenseReport, type UserExpenseReportTotals, type UserExpenseRow, UserHistoryModel, UserModel, VendorHistoryModel, VendorModel, VendorType, WINGS, WING_ALPHABETS, type WingCollectionDonationByIdLike, type WingCollectionDonationLike, type WingCollectionReport, type WingCollectionRow, type WingCollectionTotals, type XlsxCellAddress, type XlsxMergeRange, type XlsxSerializationType, type XlsxSheetInput, type XlsxSheetOptions, buildUserExpenseReport, buildUserExpenseWorkbook, buildWingWiseCollectionReport, buildWingWiseCollectionReportByFlatId, buildWingWiseCollectionWorkbook, buildXlsxWorkbook, convertNumberToWords, definedValues, diffArrays, entityListEntityModelMap, epochToReadableDate, getFlatValidationErrors, getObjectDiffingKeys, getWingSelectionLabel, getWingSelectionSlug, groupBy, isSpecialFlatLabel, isValidFlatWing, roundToTwoDecimals, serializeXlsx, validateFlatOrThrow };
package/dist/index.d.ts CHANGED
@@ -918,6 +918,26 @@ type FlatScopeRow = {
918
918
  declare function getWingSelectionLabel(selection: string, specials?: readonly string[]): string;
919
919
  declare function getWingSelectionSlug(selection: string, specials?: readonly string[]): string;
920
920
  declare function buildWingWiseCollectionReport(donations: WingCollectionDonationLike[], year: number, selection: string, flats?: readonly FlatScopeRow[]): WingCollectionReport;
921
+ /** Donation shape matched by flat entity id (flatId-only reads). */
922
+ interface WingCollectionDonationByIdLike {
923
+ flatId?: Nullable<number>;
924
+ amount: number;
925
+ receiptNumber?: string;
926
+ paymentType?: string;
927
+ createdOn?: number;
928
+ }
929
+ type FlatIdScopeRow = {
930
+ id: number;
931
+ wing?: string | null;
932
+ unitNumber: string;
933
+ };
934
+ /**
935
+ * flatId-keyed variant of buildWingWiseCollectionReport — donations are
936
+ * grouped by their flat ENTITY id and labels derive from the flat itself.
937
+ * Donations without a resolvable flat are silently excluded. The flats list
938
+ * is required (ids cannot be inferred from statics).
939
+ */
940
+ declare function buildWingWiseCollectionReportByFlatId(donations: WingCollectionDonationByIdLike[], year: number, selection: string, flats: readonly FlatIdScopeRow[]): WingCollectionReport;
921
941
  declare function buildWingWiseCollectionWorkbook(report: WingCollectionReport): XLSX.WorkBook;
922
942
 
923
943
  type XlsxSerializationType = 'base64' | 'array' | 'binary';
@@ -1127,4 +1147,4 @@ declare function isSpecialFlatLabel(label: string): boolean;
1127
1147
  declare function getFlatValidationErrors(input: Partial<IFlatEntity>): FlatValidationError[];
1128
1148
  declare function validateFlatOrThrow(input: Partial<IFlatEntity>): void;
1129
1149
 
1130
- export { ALL_WINGS_SELECTION, BadRequestException, BaseEntityModel, ConfigurationKey, ConfigurationModel, ConfigurationType, DateCodeUtils, DateUtil, DonationHistoryModel, DonationModel, EntityFilterDataHelper, EntityHistoryOperation, EntityList, type EntityListEntityModelMap, type EntityModelType, EntityStatus, type EntityType, ExpenseHeadHistoryModel, ExpenseHeadModel, ExpenseHistoryModel, ExpenseModel, FLATS_BY_WING, FLAT_DONATION_RELATION_CONFIG, FLAT_NUMBERS, FLAT_UNIT_NUMBER_PATTERN, FLAT_WING_PATTERN, type FlatCollectionEntry, type FlatCollectionStatus, type FlatDonationLike, FlatHistoryModel, type FlatIdDonationLike, FlatModel, type FlatOption, type FlatParseResult, type FlatValidationError, ForbiddenException, HttpException, type IAuditColumnEntity, type IBaseHistoryEntity, type ICashBookEntry, type IConfigurationCreateDto, type IConfigurationEntity, type IConfigurationSearchDto, type IConfigurationUpdateDto, type IDonationCreateDto, type IDonationEntity, type IDonationHistoryEntity, type IDonationSearchDto, type IDonationUpdateDto, type IDtoValidationError, type IEntityCreateDto, type IEntityFilterData, type IEntityFilterSearchData, type IEntityFilterSearchDataV2, type IEntityUpdateDto, type IExpenseCreateDto, type IExpenseEntity, type IExpenseHeadCreateDto, type IExpenseHeadEntity, type IExpenseHeadHistoryEntity, type IExpenseHeadSearchDto, type IExpenseHeadUpdateDto, type IExpenseHistoryEntity, type IExpenseSearchDto, type IExpenseUpdateDto, type IFlatCreateDto, type IFlatEntity, type IFlatHistoryEntity, type IFlatSearchDto, type IFlatUpdateDto, type IMappingPropertyEntry, type IModelRelationConfig, type ISearchV2Response, type ISponsorCreateDto, type ISponsorEntity, type ISponsorHistoryEntity, type ISponsorSearchDto, type ISponsorUpdateDto, type ITransactionCreateDto, type ITransactionEntity, type ITransactionHistoryEntity, type ITransactionSearchDto, type ITransactionUpdateDto, type IUserCreateDto, type IUserEntity, type IUserHistoryEntity, type IUserSearchDto, type IUserUpdateDto, type IVendorCreateDto, type IVendorEntity, type IVendorHistoryEntity, type IVendorSearchDto, type IVendorUpdateDto, NotFoundException, type Nullable, OrderByDirection, PAYMENT_OPTIONS, PaymentType, ReferenceIdPrefix, RelationType, SHOP_UNIT_NUMBER_PATTERN, SHOP_WING, SPECIAL_FLATS, SPECIAL_FLAT_LABELS, SponsorHistoryModel, SponsorModel, SponsorTier, TransactionEntityType, TransactionHistoryModel, TransactionModel, TransactionType, USER_RELATION_CONFIG, UnauthorizedException, type UserExpenseReport, type UserExpenseReportTotals, type UserExpenseRow, UserHistoryModel, UserModel, VendorHistoryModel, VendorModel, VendorType, WINGS, WING_ALPHABETS, type WingCollectionDonationLike, type WingCollectionReport, type WingCollectionRow, type WingCollectionTotals, type XlsxCellAddress, type XlsxMergeRange, type XlsxSerializationType, type XlsxSheetInput, type XlsxSheetOptions, buildUserExpenseReport, buildUserExpenseWorkbook, buildWingWiseCollectionReport, buildWingWiseCollectionWorkbook, buildXlsxWorkbook, convertNumberToWords, definedValues, diffArrays, entityListEntityModelMap, epochToReadableDate, getFlatValidationErrors, getObjectDiffingKeys, getWingSelectionLabel, getWingSelectionSlug, groupBy, isSpecialFlatLabel, isValidFlatWing, roundToTwoDecimals, serializeXlsx, validateFlatOrThrow };
1150
+ export { ALL_WINGS_SELECTION, BadRequestException, BaseEntityModel, ConfigurationKey, ConfigurationModel, ConfigurationType, DateCodeUtils, DateUtil, DonationHistoryModel, DonationModel, EntityFilterDataHelper, EntityHistoryOperation, EntityList, type EntityListEntityModelMap, type EntityModelType, EntityStatus, type EntityType, ExpenseHeadHistoryModel, ExpenseHeadModel, ExpenseHistoryModel, ExpenseModel, FLATS_BY_WING, FLAT_DONATION_RELATION_CONFIG, FLAT_NUMBERS, FLAT_UNIT_NUMBER_PATTERN, FLAT_WING_PATTERN, type FlatCollectionEntry, type FlatCollectionStatus, type FlatDonationLike, FlatHistoryModel, type FlatIdDonationLike, FlatModel, type FlatOption, type FlatParseResult, type FlatValidationError, ForbiddenException, HttpException, type IAuditColumnEntity, type IBaseHistoryEntity, type ICashBookEntry, type IConfigurationCreateDto, type IConfigurationEntity, type IConfigurationSearchDto, type IConfigurationUpdateDto, type IDonationCreateDto, type IDonationEntity, type IDonationHistoryEntity, type IDonationSearchDto, type IDonationUpdateDto, type IDtoValidationError, type IEntityCreateDto, type IEntityFilterData, type IEntityFilterSearchData, type IEntityFilterSearchDataV2, type IEntityUpdateDto, type IExpenseCreateDto, type IExpenseEntity, type IExpenseHeadCreateDto, type IExpenseHeadEntity, type IExpenseHeadHistoryEntity, type IExpenseHeadSearchDto, type IExpenseHeadUpdateDto, type IExpenseHistoryEntity, type IExpenseSearchDto, type IExpenseUpdateDto, type IFlatCreateDto, type IFlatEntity, type IFlatHistoryEntity, type IFlatSearchDto, type IFlatUpdateDto, type IMappingPropertyEntry, type IModelRelationConfig, type ISearchV2Response, type ISponsorCreateDto, type ISponsorEntity, type ISponsorHistoryEntity, type ISponsorSearchDto, type ISponsorUpdateDto, type ITransactionCreateDto, type ITransactionEntity, type ITransactionHistoryEntity, type ITransactionSearchDto, type ITransactionUpdateDto, type IUserCreateDto, type IUserEntity, type IUserHistoryEntity, type IUserSearchDto, type IUserUpdateDto, type IVendorCreateDto, type IVendorEntity, type IVendorHistoryEntity, type IVendorSearchDto, type IVendorUpdateDto, NotFoundException, type Nullable, OrderByDirection, PAYMENT_OPTIONS, PaymentType, ReferenceIdPrefix, RelationType, SHOP_UNIT_NUMBER_PATTERN, SHOP_WING, SPECIAL_FLATS, SPECIAL_FLAT_LABELS, SponsorHistoryModel, SponsorModel, SponsorTier, TransactionEntityType, TransactionHistoryModel, TransactionModel, TransactionType, USER_RELATION_CONFIG, UnauthorizedException, type UserExpenseReport, type UserExpenseReportTotals, type UserExpenseRow, UserHistoryModel, UserModel, VendorHistoryModel, VendorModel, VendorType, WINGS, WING_ALPHABETS, type WingCollectionDonationByIdLike, type WingCollectionDonationLike, type WingCollectionReport, type WingCollectionRow, type WingCollectionTotals, type XlsxCellAddress, type XlsxMergeRange, type XlsxSerializationType, type XlsxSheetInput, type XlsxSheetOptions, buildUserExpenseReport, buildUserExpenseWorkbook, buildWingWiseCollectionReport, buildWingWiseCollectionReportByFlatId, buildWingWiseCollectionWorkbook, buildXlsxWorkbook, convertNumberToWords, definedValues, diffArrays, entityListEntityModelMap, epochToReadableDate, getFlatValidationErrors, getObjectDiffingKeys, getWingSelectionLabel, getWingSelectionSlug, groupBy, isSpecialFlatLabel, isValidFlatWing, roundToTwoDecimals, serializeXlsx, validateFlatOrThrow };
package/dist/index.js CHANGED
@@ -86,6 +86,7 @@ __export(index_exports, {
86
86
  buildUserExpenseReport: () => buildUserExpenseReport,
87
87
  buildUserExpenseWorkbook: () => buildUserExpenseWorkbook,
88
88
  buildWingWiseCollectionReport: () => buildWingWiseCollectionReport,
89
+ buildWingWiseCollectionReportByFlatId: () => buildWingWiseCollectionReportByFlatId,
89
90
  buildWingWiseCollectionWorkbook: () => buildWingWiseCollectionWorkbook,
90
91
  buildXlsxWorkbook: () => buildXlsxWorkbook,
91
92
  convertNumberToWords: () => convertNumberToWords,
@@ -1918,7 +1919,8 @@ function resolveScopeSpecials(flats) {
1918
1919
  }
1919
1920
  function getWingSelectionLabel(selection, specials) {
1920
1921
  if (selection === ALL_WINGS_SELECTION) return "All Wings";
1921
- if ((specials ?? FlatModel.SPECIAL_FLATS).includes(selection)) return selection;
1922
+ if ((specials ?? FlatModel.SPECIAL_FLATS).includes(selection))
1923
+ return selection;
1922
1924
  return `Wing ${selection}`;
1923
1925
  }
1924
1926
  function getWingSelectionSlug(selection, specials) {
@@ -1955,27 +1957,29 @@ function buildWingWiseCollectionReport(donations, year, selection, flats) {
1955
1957
  donationsByFlat.set(d.flatNo, list);
1956
1958
  }
1957
1959
  const scope = getFlatNumbersInScope(selection, flats);
1958
- const rows = scope.map(
1959
- (flatNo) => {
1960
- const flatDonations = donationsByFlat.get(flatNo) ?? [];
1961
- const amount = flatDonations.reduce((sum, d) => sum + d.amount, 0);
1962
- const latest = flatDonations.reduce(
1963
- (acc, d) => !acc || (d.createdOn ?? 0) > (acc.createdOn ?? 0) ? d : acc,
1964
- null
1965
- );
1966
- return {
1967
- flatNo,
1968
- status: amount > 0 ? "Paid" : "Pending",
1969
- amount,
1970
- count: flatDonations.length,
1971
- receiptNumber: latest?.receiptNumber ?? "",
1972
- paymentType: latest?.paymentType ?? "",
1973
- donationDate: latest?.createdOn ? epochToReadableDate(latest.createdOn, "short") : ""
1974
- };
1975
- }
1976
- );
1960
+ const rows = scope.map((flatNo) => {
1961
+ const flatDonations = donationsByFlat.get(flatNo) ?? [];
1962
+ const amount = flatDonations.reduce((sum, d) => sum + d.amount, 0);
1963
+ const latest = flatDonations.reduce(
1964
+ (acc, d) => !acc || (d.createdOn ?? 0) > (acc.createdOn ?? 0) ? d : acc,
1965
+ null
1966
+ );
1967
+ return {
1968
+ flatNo,
1969
+ status: amount > 0 ? "Paid" : "Pending",
1970
+ amount,
1971
+ count: flatDonations.length,
1972
+ receiptNumber: latest?.receiptNumber ?? "",
1973
+ paymentType: latest?.paymentType ?? "",
1974
+ donationDate: latest?.createdOn ? epochToReadableDate(latest.createdOn, "short") : ""
1975
+ };
1976
+ });
1977
1977
  rows.sort(
1978
- (a, b) => FlatModel.compareFlatNumbers(a.flatNo, b.flatNo, resolveScopeSpecials(flats))
1978
+ (a, b) => FlatModel.compareFlatNumbers(
1979
+ a.flatNo,
1980
+ b.flatNo,
1981
+ resolveScopeSpecials(flats)
1982
+ )
1979
1983
  );
1980
1984
  const totals = rows.reduce(
1981
1985
  (acc, r) => ({
@@ -1987,7 +1991,15 @@ function buildWingWiseCollectionReport(donations, year, selection, flats) {
1987
1991
  upi: acc.upi,
1988
1992
  bankTransfer: acc.bankTransfer
1989
1993
  }),
1990
- { flats: 0, paid: 0, pending: 0, amount: 0, cash: 0, upi: 0, bankTransfer: 0 }
1994
+ {
1995
+ flats: 0,
1996
+ paid: 0,
1997
+ pending: 0,
1998
+ amount: 0,
1999
+ cash: 0,
2000
+ upi: 0,
2001
+ bankTransfer: 0
2002
+ }
1991
2003
  );
1992
2004
  for (const [flatNo, flatDonations] of donationsByFlat) {
1993
2005
  if (!scope.includes(flatNo)) continue;
@@ -2003,6 +2015,66 @@ function buildWingWiseCollectionReport(donations, year, selection, flats) {
2003
2015
  }
2004
2016
  return { year, selection, label, rows, totals };
2005
2017
  }
2018
+ function buildWingWiseCollectionReportByFlatId(donations, year, selection, flats) {
2019
+ const specials = FlatModel.getSpecialsFromFlats(flats);
2020
+ const label = getWingSelectionLabel(selection, specials);
2021
+ const scopeFlats = selection === ALL_WINGS_SELECTION ? [...flats] : specials.includes(selection) ? flats.filter((f) => !f.wing && f.unitNumber === selection) : flats.filter((f) => f.wing === selection);
2022
+ const scopeIds = new Set(scopeFlats.map((f) => f.id));
2023
+ const scopedDonations = donations.filter(
2024
+ (d) => d.flatId != null && scopeIds.has(d.flatId)
2025
+ );
2026
+ const rows = scopeFlats.map((flat) => {
2027
+ const flatNo = FlatModel.getFlatLabel(flat);
2028
+ const flatDonations = scopedDonations.filter((d) => d.flatId === flat.id);
2029
+ const amount = flatDonations.reduce((sum, d) => sum + d.amount, 0);
2030
+ const latest = flatDonations.reduce(
2031
+ (acc, d) => !acc || (d.createdOn ?? 0) > (acc.createdOn ?? 0) ? d : acc,
2032
+ null
2033
+ );
2034
+ return {
2035
+ flatNo,
2036
+ status: amount > 0 ? "Paid" : "Pending",
2037
+ amount,
2038
+ count: flatDonations.length,
2039
+ receiptNumber: latest?.receiptNumber ?? "",
2040
+ paymentType: latest?.paymentType ?? "",
2041
+ donationDate: latest?.createdOn ? epochToReadableDate(latest.createdOn, "short") : ""
2042
+ };
2043
+ });
2044
+ rows.sort(
2045
+ (a, b) => FlatModel.compareFlatNumbers(a.flatNo, b.flatNo, specials)
2046
+ );
2047
+ const totals = rows.reduce(
2048
+ (acc, r) => ({
2049
+ flats: acc.flats + 1,
2050
+ paid: acc.paid + (r.status === "Paid" ? 1 : 0),
2051
+ pending: acc.pending + (r.status === "Pending" ? 1 : 0),
2052
+ amount: acc.amount + r.amount,
2053
+ cash: acc.cash,
2054
+ upi: acc.upi,
2055
+ bankTransfer: acc.bankTransfer
2056
+ }),
2057
+ {
2058
+ flats: 0,
2059
+ paid: 0,
2060
+ pending: 0,
2061
+ amount: 0,
2062
+ cash: 0,
2063
+ upi: 0,
2064
+ bankTransfer: 0
2065
+ }
2066
+ );
2067
+ for (const d of scopedDonations) {
2068
+ if (d.paymentType === "Cash" /* CASH */) {
2069
+ totals.cash += d.amount;
2070
+ } else if (d.paymentType === "UPI" /* UPI */) {
2071
+ totals.upi += d.amount;
2072
+ } else {
2073
+ totals.bankTransfer += d.amount;
2074
+ }
2075
+ }
2076
+ return { year, selection, label, rows, totals };
2077
+ }
2006
2078
  function buildWingWiseCollectionWorkbook(report) {
2007
2079
  const aoa = [
2008
2080
  [
@@ -2297,6 +2369,7 @@ function validateFlatOrThrow(input) {
2297
2369
  buildUserExpenseReport,
2298
2370
  buildUserExpenseWorkbook,
2299
2371
  buildWingWiseCollectionReport,
2372
+ buildWingWiseCollectionReportByFlatId,
2300
2373
  buildWingWiseCollectionWorkbook,
2301
2374
  buildXlsxWorkbook,
2302
2375
  convertNumberToWords,