namespace AccountsDAL.CustomCode.AccountReports { // Maps a GroupType to VoucherReportQB.GET_VOUCHER_SUMMARY_REPORT's {GroupBySelect}/ // {GroupByColumns} placeholders — collapses legacy's 4 near-identical // VOUCHER_{GROUPWISE,ACCOUNTWISE,SUBACCOUNTWISE,GROUP_SUBACCOUNT}_SUMMARY_REPORT SQL constants // (which differed ONLY in this GROUP BY key) into one query + this allow-listed builder — the // single biggest concrete duplication the legacy research found. Same // "allow-listed, never string-interpolated from caller input" discipline as // AccountOutstandingGroupByBuilder/AccountAgeingGroupByBuilder. // // GroupType: AccountGroup(0, default)/Account(1)/ControlAccount-collapse(2)/ // ControlAccount+Account pair(3) — matches legacy's own Type 0-3 semantics exactly. public static class VoucherSummaryGroupByBuilder { public static (string select, string groupBy) Build(int groupType) => groupType switch { 1 => ( "VD.VOUCHERACCOUNTID AS Id, ACC.ACCOUNTCODE AS Code, ACC.ACCOUNTNAME AS Name", "VD.VOUCHERACCOUNTID, ACC.ACCOUNTCODE, ACC.ACCOUNTNAME"), 2 => ( "CASE WHEN ACC.CONTROLACCOUNTID = -1 THEN VD.VOUCHERACCOUNTID ELSE ACC.CONTROLACCOUNTID END AS Id, " + "COALESCE(CTRL.ACCOUNTCODE, ACC.ACCOUNTCODE) AS Code, COALESCE(CTRL.ACCOUNTNAME, ACC.ACCOUNTNAME) AS Name", "CASE WHEN ACC.CONTROLACCOUNTID = -1 THEN VD.VOUCHERACCOUNTID ELSE ACC.CONTROLACCOUNTID END, " + "COALESCE(CTRL.ACCOUNTCODE, ACC.ACCOUNTCODE), COALESCE(CTRL.ACCOUNTNAME, ACC.ACCOUNTNAME)"), 3 => ( "CASE WHEN ACC.CONTROLACCOUNTID = -1 THEN VD.VOUCHERACCOUNTID ELSE ACC.CONTROLACCOUNTID END AS Id, " + "COALESCE(CTRL.ACCOUNTCODE, ACC.ACCOUNTCODE) AS Code, COALESCE(CTRL.ACCOUNTNAME, ACC.ACCOUNTNAME) AS Name, " + "VD.VOUCHERACCOUNTID AS SubAccountId, ACC.ACCOUNTCODE AS SubAccountCode, ACC.ACCOUNTNAME AS SubAccountName", "CASE WHEN ACC.CONTROLACCOUNTID = -1 THEN VD.VOUCHERACCOUNTID ELSE ACC.CONTROLACCOUNTID END, " + "COALESCE(CTRL.ACCOUNTCODE, ACC.ACCOUNTCODE), COALESCE(CTRL.ACCOUNTNAME, ACC.ACCOUNTNAME), " + "VD.VOUCHERACCOUNTID, ACC.ACCOUNTCODE, ACC.ACCOUNTNAME"), _ => ( "ACC.ACCOUNTGROUPID AS Id, AG.ACCOUNTGROUPCODE AS Code, AG.ACCOUNTGROUPNAME AS Name", "ACC.ACCOUNTGROUPID, AG.ACCOUNTGROUPCODE, AG.ACCOUNTGROUPNAME"), }; } }