From c7a3bac44cad486107aad7ef6ce6b6c6e5e76013 Mon Sep 17 00:00:00 2001 From: Ahmed Bouhuolia Date: Sun, 27 Aug 2023 15:50:52 +0200 Subject: [PATCH 1/3] fix(server): change the default from/date date value of reports --- .../BalanceSheet/BalanceSheetService.ts | 2 +- .../CashFlow/CashFlowService.ts | 2 +- .../GeneralLedger/GeneralLedgerService.ts | 4 ++-- .../InventoryDetailsService.ts | 10 +++++----- .../InventoryValuationSheetService.ts | 2 +- .../JournalSheet/JournalSheetService.ts | 4 ++-- .../ProfitLossSheet/utils.ts | 2 +- .../PurchasesByItemsService.ts | 19 ++++++++----------- .../SalesByItems/SalesByItemsService.ts | 4 ++-- .../TransactionsByCustomersService.ts | 4 ++-- .../TransactionsByVendorService.ts | 2 +- .../TrialBalanceSheetService.ts | 2 +- .../APAgingSummary/APAgingSummaryTable.tsx | 4 ++-- .../VendorsBalanceSummaryTable.tsx | 5 ++--- .../VendorsTransactions/_utils.ts | 2 +- 15 files changed, 32 insertions(+), 36 deletions(-) diff --git a/packages/server/src/services/FinancialStatements/BalanceSheet/BalanceSheetService.ts b/packages/server/src/services/FinancialStatements/BalanceSheet/BalanceSheetService.ts index f674048bc..b0470c745 100644 --- a/packages/server/src/services/FinancialStatements/BalanceSheet/BalanceSheetService.ts +++ b/packages/server/src/services/FinancialStatements/BalanceSheet/BalanceSheetService.ts @@ -37,7 +37,7 @@ export default class BalanceSheetStatementService displayColumnsBy: 'month', fromDate: moment().startOf('year').format('YYYY-MM-DD'), - toDate: moment().endOf('year').format('YYYY-MM-DD'), + toDate: moment().format('YYYY-MM-DD'), numberFormat: { precision: 2, diff --git a/packages/server/src/services/FinancialStatements/CashFlow/CashFlowService.ts b/packages/server/src/services/FinancialStatements/CashFlow/CashFlowService.ts index 58fd5d2ad..09fdf91ca 100644 --- a/packages/server/src/services/FinancialStatements/CashFlow/CashFlowService.ts +++ b/packages/server/src/services/FinancialStatements/CashFlow/CashFlowService.ts @@ -40,7 +40,7 @@ export default class CashFlowStatementService displayColumnsType: 'total', displayColumnsBy: 'day', fromDate: moment().startOf('year').format('YYYY-MM-DD'), - toDate: moment().endOf('year').format('YYYY-MM-DD'), + toDate: moment().format('YYYY-MM-DD'), numberFormat: { precision: 2, divideOn1000: false, diff --git a/packages/server/src/services/FinancialStatements/GeneralLedger/GeneralLedgerService.ts b/packages/server/src/services/FinancialStatements/GeneralLedger/GeneralLedgerService.ts index 74633d81e..012a05b94 100644 --- a/packages/server/src/services/FinancialStatements/GeneralLedger/GeneralLedgerService.ts +++ b/packages/server/src/services/FinancialStatements/GeneralLedger/GeneralLedgerService.ts @@ -31,8 +31,8 @@ export default class GeneralLedgerService { */ get defaultQuery() { return { - fromDate: moment().startOf('year').format('YYYY-MM-DD'), - toDate: moment().endOf('year').format('YYYY-MM-DD'), + fromDate: moment().startOf('month').format('YYYY-MM-DD'), + toDate: moment().format('YYYY-MM-DD'), basis: 'cash', numberFormat: { noCents: false, diff --git a/packages/server/src/services/FinancialStatements/InventoryDetails/InventoryDetailsService.ts b/packages/server/src/services/FinancialStatements/InventoryDetails/InventoryDetailsService.ts index 7cc1d0667..cdeca4f39 100644 --- a/packages/server/src/services/FinancialStatements/InventoryDetails/InventoryDetailsService.ts +++ b/packages/server/src/services/FinancialStatements/InventoryDetails/InventoryDetailsService.ts @@ -16,13 +16,13 @@ import { Tenant } from '@/system/models'; @Service() export default class InventoryDetailsService extends FinancialSheet { @Inject() - tenancy: TenancyService; + private tenancy: TenancyService; @Inject() - reportRepo: InventoryDetailsRepository; + private reportRepo: InventoryDetailsRepository; @Inject() - inventoryService: InventoryService; + private inventoryService: InventoryService; /** * Defaults balance sheet filter query. @@ -30,8 +30,8 @@ export default class InventoryDetailsService extends FinancialSheet { */ private get defaultQuery(): IInventoryDetailsQuery { return { - fromDate: moment().startOf('year').format('YYYY-MM-DD'), - toDate: moment().endOf('year').format('YYYY-MM-DD'), + fromDate: moment().startOf('month').format('YYYY-MM-DD'), + toDate: moment().format('YYYY-MM-DD'), itemsIds: [], numberFormat: { precision: 2, diff --git a/packages/server/src/services/FinancialStatements/InventoryValuationSheet/InventoryValuationSheetService.ts b/packages/server/src/services/FinancialStatements/InventoryValuationSheet/InventoryValuationSheetService.ts index 41650ccde..75c871ce8 100644 --- a/packages/server/src/services/FinancialStatements/InventoryValuationSheet/InventoryValuationSheetService.ts +++ b/packages/server/src/services/FinancialStatements/InventoryValuationSheet/InventoryValuationSheetService.ts @@ -27,7 +27,7 @@ export default class InventoryValuationSheetService { */ get defaultQuery(): IInventoryValuationReportQuery { return { - asDate: moment().endOf('year').format('YYYY-MM-DD'), + asDate: moment().format('YYYY-MM-DD'), itemsIds: [], numberFormat: { precision: 2, diff --git a/packages/server/src/services/FinancialStatements/JournalSheet/JournalSheetService.ts b/packages/server/src/services/FinancialStatements/JournalSheet/JournalSheetService.ts index f932efd8c..fe0a071ff 100644 --- a/packages/server/src/services/FinancialStatements/JournalSheet/JournalSheetService.ts +++ b/packages/server/src/services/FinancialStatements/JournalSheet/JournalSheetService.ts @@ -25,8 +25,8 @@ export default class JournalSheetService { */ get defaultQuery() { return { - fromDate: moment().startOf('year').format('YYYY-MM-DD'), - toDate: moment().endOf('year').format('YYYY-MM-DD'), + fromDate: moment().startOf('month').format('YYYY-MM-DD'), + toDate: moment().format('YYYY-MM-DD'), fromRange: null, toRange: null, accountsIds: [], diff --git a/packages/server/src/services/FinancialStatements/ProfitLossSheet/utils.ts b/packages/server/src/services/FinancialStatements/ProfitLossSheet/utils.ts index 8f17be584..85663a0b8 100644 --- a/packages/server/src/services/FinancialStatements/ProfitLossSheet/utils.ts +++ b/packages/server/src/services/FinancialStatements/ProfitLossSheet/utils.ts @@ -8,7 +8,7 @@ import { IProfitLossSheetQuery } from '@/interfaces'; */ export const getDefaultPLQuery = (): IProfitLossSheetQuery => ({ fromDate: moment().startOf('year').format('YYYY-MM-DD'), - toDate: moment().endOf('year').format('YYYY-MM-DD'), + toDate: moment().format('YYYY-MM-DD'), numberFormat: { divideOn1000: false, diff --git a/packages/server/src/services/FinancialStatements/PurchasesByItems/PurchasesByItemsService.ts b/packages/server/src/services/FinancialStatements/PurchasesByItems/PurchasesByItemsService.ts index 4c226e48a..df4aee1ad 100644 --- a/packages/server/src/services/FinancialStatements/PurchasesByItems/PurchasesByItemsService.ts +++ b/packages/server/src/services/FinancialStatements/PurchasesByItems/PurchasesByItemsService.ts @@ -12,10 +12,7 @@ import { Tenant } from '@/system/models'; @Service() export default class InventoryValuationReportService { @Inject() - tenancy: TenancyService; - - @Inject('logger') - logger: any; + private tenancy: TenancyService; /** * Defaults balance sheet filter query. @@ -23,8 +20,8 @@ export default class InventoryValuationReportService { */ get defaultQuery(): IInventoryValuationReportQuery { return { - fromDate: moment().startOf('year').format('YYYY-MM-DD'), - toDate: moment().endOf('year').format('YYYY-MM-DD'), + fromDate: moment().startOf('month').format('YYYY-MM-DD'), + toDate: moment().format('YYYY-MM-DD'), itemsIds: [], numberFormat: { precision: 2, @@ -73,9 +70,9 @@ export default class InventoryValuationReportService { tenantId: number, query: IInventoryValuationReportQuery ): Promise<{ - data: IInventoryValuationStatement, - query: IInventoryValuationReportQuery, - meta: IInventoryValuationSheetMeta, + data: IInventoryValuationStatement; + query: IInventoryValuationReportQuery; + meta: IInventoryValuationSheetMeta; }> { const { Item, InventoryTransaction } = this.tenancy.models(tenantId); @@ -87,7 +84,7 @@ export default class InventoryValuationReportService { ...this.defaultQuery, ...query, }; - const inventoryItems = await Item.query().onBuild(q => { + const inventoryItems = await Item.query().onBuild((q) => { q.where('type', 'inventory'); if (filter.itemsIds.length > 0) { @@ -106,7 +103,7 @@ export default class InventoryValuationReportService { builder.whereIn('itemId', inventoryItemsIds); // Filter the date range of the sheet. - builder.modify('filterDateRange', filter.fromDate, filter.toDate) + builder.modify('filterDateRange', filter.fromDate, filter.toDate); } ); diff --git a/packages/server/src/services/FinancialStatements/SalesByItems/SalesByItemsService.ts b/packages/server/src/services/FinancialStatements/SalesByItems/SalesByItemsService.ts index 8d0032f7a..7570ef572 100644 --- a/packages/server/src/services/FinancialStatements/SalesByItems/SalesByItemsService.ts +++ b/packages/server/src/services/FinancialStatements/SalesByItems/SalesByItemsService.ts @@ -23,8 +23,8 @@ export default class SalesByItemsReportService { */ get defaultQuery(): ISalesByItemsReportQuery { return { - fromDate: moment().startOf('year').format('YYYY-MM-DD'), - toDate: moment().endOf('year').format('YYYY-MM-DD'), + fromDate: moment().startOf('month').format('YYYY-MM-DD'), + toDate: moment().format('YYYY-MM-DD'), itemsIds: [], numberFormat: { precision: 2, diff --git a/packages/server/src/services/FinancialStatements/TransactionsByCustomer/TransactionsByCustomersService.ts b/packages/server/src/services/FinancialStatements/TransactionsByCustomer/TransactionsByCustomersService.ts index 24723caaa..a6f56d9fe 100644 --- a/packages/server/src/services/FinancialStatements/TransactionsByCustomer/TransactionsByCustomersService.ts +++ b/packages/server/src/services/FinancialStatements/TransactionsByCustomer/TransactionsByCustomersService.ts @@ -31,8 +31,8 @@ export default class TransactionsByCustomersService */ get defaultQuery(): ITransactionsByCustomersFilter { return { - fromDate: moment().startOf('year').format('YYYY-MM-DD'), - toDate: moment().endOf('year').format('YYYY-MM-DD'), + fromDate: moment().startOf('month').format('YYYY-MM-DD'), + toDate: moment().format('YYYY-MM-DD'), numberFormat: { precision: 2, divideOn1000: false, diff --git a/packages/server/src/services/FinancialStatements/TransactionsByVendor/TransactionsByVendorService.ts b/packages/server/src/services/FinancialStatements/TransactionsByVendor/TransactionsByVendorService.ts index 18be5b7ed..c112a059a 100644 --- a/packages/server/src/services/FinancialStatements/TransactionsByVendor/TransactionsByVendorService.ts +++ b/packages/server/src/services/FinancialStatements/TransactionsByVendor/TransactionsByVendorService.ts @@ -32,7 +32,7 @@ export default class TransactionsByVendorsService */ get defaultQuery(): ITransactionsByVendorsFilter { return { - fromDate: moment().format('YYYY-MM-DD'), + fromDate: moment().startOf('month').format('YYYY-MM-DD'), toDate: moment().format('YYYY-MM-DD'), numberFormat: { precision: 2, diff --git a/packages/server/src/services/FinancialStatements/TrialBalanceSheet/TrialBalanceSheetService.ts b/packages/server/src/services/FinancialStatements/TrialBalanceSheet/TrialBalanceSheetService.ts index e06ed6b02..f22624a3e 100644 --- a/packages/server/src/services/FinancialStatements/TrialBalanceSheet/TrialBalanceSheetService.ts +++ b/packages/server/src/services/FinancialStatements/TrialBalanceSheet/TrialBalanceSheetService.ts @@ -27,7 +27,7 @@ export default class TrialBalanceSheetService extends FinancialSheet { get defaultQuery(): ITrialBalanceSheetQuery { return { fromDate: moment().startOf('year').format('YYYY-MM-DD'), - toDate: moment().endOf('year').format('YYYY-MM-DD'), + toDate: moment().format('YYYY-MM-DD'), numberFormat: { divideOn1000: false, negativeFormat: 'mines', diff --git a/packages/webapp/src/containers/FinancialStatements/APAgingSummary/APAgingSummaryTable.tsx b/packages/webapp/src/containers/FinancialStatements/APAgingSummary/APAgingSummaryTable.tsx index 96924e97b..115a8a887 100644 --- a/packages/webapp/src/containers/FinancialStatements/APAgingSummary/APAgingSummaryTable.tsx +++ b/packages/webapp/src/containers/FinancialStatements/APAgingSummary/APAgingSummaryTable.tsx @@ -20,7 +20,7 @@ export default function APAgingSummaryTable({ }) { // AP aging summary report content. const { - APAgingSummary: { table }, + APAgingSummary: { table, query }, isAPAgingLoading, } = useAPAgingSummaryContext(); @@ -31,7 +31,7 @@ export default function APAgingSummaryTable({ { * Retrieves the default query of vendors transactions. */ export const getVendorsTransactionsDefaultQuery = () => ({ - fromDate: moment().toDate(), + fromDate: moment().startOf('month').toDate(), toDate: moment().toDate(), vendorsIds: [], }); From 4df63561cf78691802da0b7cd580c5228c35dc68 Mon Sep 17 00:00:00 2001 From: Ahmed Bouhuolia Date: Sun, 27 Aug 2023 16:00:54 +0200 Subject: [PATCH 2/3] fix(webapp): change the default from/to date values of reports --- .../ARAgingSummary/ARAgingSummaryProvider.tsx | 8 +++++--- .../ARAgingSummary/ARAgingSummaryTable.tsx | 4 ++-- .../containers/FinancialStatements/BalanceSheet/utils.tsx | 2 +- .../FinancialStatements/CashFlowStatement/utils.tsx | 2 +- .../CustomersBalanceSummaryTable.tsx | 4 ++-- .../FinancialStatements/CustomersTransactions/_utils.ts | 2 +- .../FinancialStatements/GeneralLedger/common.tsx | 4 ++-- .../InventoryItemDetails/InventoryItemDetailsTable.tsx | 4 ++-- .../FinancialStatements/InventoryItemDetails/utils.tsx | 3 --- .../FinancialStatements/InventoryItemDetails/utils2.tsx | 4 ++-- .../InventoryValuation/InventoryValuationTable.tsx | 4 ++-- .../FinancialStatements/InventoryValuation/utils.tsx | 2 +- .../src/containers/FinancialStatements/Journal/utils.tsx | 7 +++---- .../FinancialStatements/ProfitLossSheet/utils.tsx | 2 +- .../FinancialStatements/PurchasesByItems/utils.tsx | 4 ++-- .../containers/FinancialStatements/SalesByItems/utils.tsx | 4 ++-- .../FinancialStatements/TrialBalanceSheet/utils.tsx | 2 +- 17 files changed, 30 insertions(+), 32 deletions(-) diff --git a/packages/webapp/src/containers/FinancialStatements/ARAgingSummary/ARAgingSummaryProvider.tsx b/packages/webapp/src/containers/FinancialStatements/ARAgingSummary/ARAgingSummaryProvider.tsx index c29e2a43d..1b9577900 100644 --- a/packages/webapp/src/containers/FinancialStatements/ARAgingSummary/ARAgingSummaryProvider.tsx +++ b/packages/webapp/src/containers/FinancialStatements/ARAgingSummary/ARAgingSummaryProvider.tsx @@ -11,7 +11,10 @@ const ARAgingSummaryContext = createContext(); */ function ARAgingSummaryProvider({ filter, ...props }) { // Transformes the filter from to the url query. - const query = useMemo(() => transformFilterFormToQuery(filter), [filter]); + const requestQuery = useMemo( + () => transformFilterFormToQuery(filter), + [filter], + ); // A/R aging summary sheet context. const { @@ -19,11 +22,10 @@ function ARAgingSummaryProvider({ filter, ...props }) { isLoading: isARAgingLoading, isFetching: isARAgingFetching, refetch, - } = useARAgingSummaryReport(query, { keepPreviousData: true }); + } = useARAgingSummaryReport(requestQuery, { keepPreviousData: true }); const provider = { ARAgingSummary, - isARAgingLoading, isARAgingFetching, refetch, diff --git a/packages/webapp/src/containers/FinancialStatements/ARAgingSummary/ARAgingSummaryTable.tsx b/packages/webapp/src/containers/FinancialStatements/ARAgingSummary/ARAgingSummaryTable.tsx index d2cdf5baa..2cde74a37 100644 --- a/packages/webapp/src/containers/FinancialStatements/ARAgingSummary/ARAgingSummaryTable.tsx +++ b/packages/webapp/src/containers/FinancialStatements/ARAgingSummary/ARAgingSummaryTable.tsx @@ -20,7 +20,7 @@ export default function ReceivableAgingSummaryTable({ }) { // AR aging summary report context. const { - ARAgingSummary: { table }, + ARAgingSummary: { table, query }, isARAgingLoading, } = useARAgingSummaryContext(); @@ -31,7 +31,7 @@ export default function ReceivableAgingSummaryTable({ ({ fromDate: moment().startOf('year').format('YYYY-MM-DD'), - toDate: moment().endOf('year').format('YYYY-MM-DD'), + toDate: moment().format('YYYY-MM-DD'), basis: 'cash', displayColumnsType: 'total', filterByOption: 'without-zero-balance', diff --git a/packages/webapp/src/containers/FinancialStatements/CashFlowStatement/utils.tsx b/packages/webapp/src/containers/FinancialStatements/CashFlowStatement/utils.tsx index ecad0760e..6606ce259 100644 --- a/packages/webapp/src/containers/FinancialStatements/CashFlowStatement/utils.tsx +++ b/packages/webapp/src/containers/FinancialStatements/CashFlowStatement/utils.tsx @@ -12,7 +12,7 @@ import { useAppQueryString } from '@/hooks'; export const getDefaultCashFlowSheetQuery = () => { return { fromDate: moment().startOf('year').format('YYYY-MM-DD'), - toDate: moment().endOf('year').format('YYYY-MM-DD'), + toDate: moment().format('YYYY-MM-DD'), basis: 'cash', displayColumnsType: 'total', filterByOption: 'with-transactions', diff --git a/packages/webapp/src/containers/FinancialStatements/CustomersBalanceSummary/CustomersBalanceSummaryTable.tsx b/packages/webapp/src/containers/FinancialStatements/CustomersBalanceSummary/CustomersBalanceSummaryTable.tsx index 729b04617..6957483bc 100644 --- a/packages/webapp/src/containers/FinancialStatements/CustomersBalanceSummary/CustomersBalanceSummaryTable.tsx +++ b/packages/webapp/src/containers/FinancialStatements/CustomersBalanceSummary/CustomersBalanceSummaryTable.tsx @@ -18,7 +18,7 @@ export default function CustomersBalanceSummaryTable({ companyName, }) { const { - CustomerBalanceSummary: { table }, + CustomerBalanceSummary: { table, query }, } = useCustomersBalanceSummaryContext(); // Retrieves the customers summary columns. @@ -28,7 +28,7 @@ export default function CustomersBalanceSummaryTable({ { }; export const getCustomersTransactionsDefaultQuery = () => ({ - fromDate: moment().toDate(), + fromDate: moment().startOf('month').toDate(), toDate: moment().toDate(), customersIds: [], }); diff --git a/packages/webapp/src/containers/FinancialStatements/GeneralLedger/common.tsx b/packages/webapp/src/containers/FinancialStatements/GeneralLedger/common.tsx index 7ca26c7a3..4f6c5a65c 100644 --- a/packages/webapp/src/containers/FinancialStatements/GeneralLedger/common.tsx +++ b/packages/webapp/src/containers/FinancialStatements/GeneralLedger/common.tsx @@ -28,8 +28,8 @@ export const filterAccountsOptions = [ * Retrieves the default general ledger query. */ export const getDefaultGeneralLedgerQuery = () => ({ - fromDate: moment().startOf('year').format('YYYY-MM-DD'), - toDate: moment().endOf('year').format('YYYY-MM-DD'), + fromDate: moment().startOf('month').format('YYYY-MM-DD'), + toDate: moment().format('YYYY-MM-DD'), basis: 'accrual', filterByOption: 'with-transactions', branchesIds: [], diff --git a/packages/webapp/src/containers/FinancialStatements/InventoryItemDetails/InventoryItemDetailsTable.tsx b/packages/webapp/src/containers/FinancialStatements/InventoryItemDetails/InventoryItemDetailsTable.tsx index 8171862f7..f8cd204cd 100644 --- a/packages/webapp/src/containers/FinancialStatements/InventoryItemDetails/InventoryItemDetailsTable.tsx +++ b/packages/webapp/src/containers/FinancialStatements/InventoryItemDetails/InventoryItemDetailsTable.tsx @@ -35,8 +35,8 @@ export function InventoryItemDetailsTable({ companyName={companyName} sheetType={intl.get('inventory_item_details')} loading={isInventoryItemDetailsLoading} - fromDate={query.from_date} - toDate={query.to_date} + fromDate={query.fromDate} + toDate={query.toDate} fullWidth={true} > ({ align: Align.Right, })); -/** - * columns mapper. - */ const columnsMapper = R.curry((data, index, column) => ({ id: column.key, key: column.key, diff --git a/packages/webapp/src/containers/FinancialStatements/InventoryItemDetails/utils2.tsx b/packages/webapp/src/containers/FinancialStatements/InventoryItemDetails/utils2.tsx index 02637e36e..4293cf610 100644 --- a/packages/webapp/src/containers/FinancialStatements/InventoryItemDetails/utils2.tsx +++ b/packages/webapp/src/containers/FinancialStatements/InventoryItemDetails/utils2.tsx @@ -12,8 +12,8 @@ import { transformToForm } from '@/utils'; * Retrieves inventory item details default query. */ export const getInventoryItemDetailsDefaultQuery = () => ({ - fromDate: moment().startOf('year').format('YYYY-MM-DD'), - toDate: moment().endOf('year').format('YYYY-MM-DD'), + fromDate: moment().startOf('month').format('YYYY-MM-DD'), + toDate: moment().format('YYYY-MM-DD'), itemsIds: [], warehousesIds: [], branchesIds: [], diff --git a/packages/webapp/src/containers/FinancialStatements/InventoryValuation/InventoryValuationTable.tsx b/packages/webapp/src/containers/FinancialStatements/InventoryValuation/InventoryValuationTable.tsx index 009832ebb..bada2a466 100644 --- a/packages/webapp/src/containers/FinancialStatements/InventoryValuation/InventoryValuationTable.tsx +++ b/packages/webapp/src/containers/FinancialStatements/InventoryValuation/InventoryValuationTable.tsx @@ -19,7 +19,7 @@ export default function InventoryValuationTable({ }) { // inventory valuation context. const { - inventoryValuation: { tableRows }, + inventoryValuation: { tableRows, query }, isLoading, } = useInventoryValuationContext(); @@ -30,7 +30,7 @@ export default function InventoryValuationTable({ { * Retrieves the inventory valuation sheet default query. */ export const getInventoryValuationQuery = () => ({ - asDate: moment().endOf('day').format('YYYY-MM-DD'), + asDate: moment().format('YYYY-MM-DD'), filterByOption: 'with-transactions', itemsIds: [], branchesIds: [], diff --git a/packages/webapp/src/containers/FinancialStatements/Journal/utils.tsx b/packages/webapp/src/containers/FinancialStatements/Journal/utils.tsx index bafa46384..f65f027ed 100644 --- a/packages/webapp/src/containers/FinancialStatements/Journal/utils.tsx +++ b/packages/webapp/src/containers/FinancialStatements/Journal/utils.tsx @@ -11,17 +11,16 @@ import { transformToForm } from '@/utils'; */ export const getDefaultJournalQuery = () => { return { - fromDate: moment().startOf('year').format('YYYY-MM-DD'), - toDate: moment().endOf('year').format('YYYY-MM-DD'), + fromDate: moment().startOf('month').format('YYYY-MM-DD'), + toDate: moment().format('YYYY-MM-DD'), basis: 'accrual', }; }; - /** * Parses balance sheet query. */ - const parseJournalQuery = (locationQuery) => { +const parseJournalQuery = (locationQuery) => { const defaultQuery = getDefaultJournalQuery(); return { diff --git a/packages/webapp/src/containers/FinancialStatements/ProfitLossSheet/utils.tsx b/packages/webapp/src/containers/FinancialStatements/ProfitLossSheet/utils.tsx index b6941a7fe..91ee66d4e 100644 --- a/packages/webapp/src/containers/FinancialStatements/ProfitLossSheet/utils.tsx +++ b/packages/webapp/src/containers/FinancialStatements/ProfitLossSheet/utils.tsx @@ -16,7 +16,7 @@ import { castArray } from 'lodash'; export const getDefaultProfitLossQuery = () => ({ basis: 'cash', fromDate: moment().startOf('year').format('YYYY-MM-DD'), - toDate: moment().endOf('year').format('YYYY-MM-DD'), + toDate: moment().format('YYYY-MM-DD'), displayColumnsType: 'total', filterByOption: 'with-transactions', diff --git a/packages/webapp/src/containers/FinancialStatements/PurchasesByItems/utils.tsx b/packages/webapp/src/containers/FinancialStatements/PurchasesByItems/utils.tsx index 6613e6255..51a2684c3 100644 --- a/packages/webapp/src/containers/FinancialStatements/PurchasesByItems/utils.tsx +++ b/packages/webapp/src/containers/FinancialStatements/PurchasesByItems/utils.tsx @@ -11,8 +11,8 @@ import { castArray } from 'lodash'; * Retrieves the purchases by items query. */ export const getDefaultPurchasesByItemsQuery = () => ({ - fromDate: moment().startOf('year').format('YYYY-MM-DD'), - toDate: moment().endOf('year').format('YYYY-MM-DD'), + fromDate: moment().startOf('month').format('YYYY-MM-DD'), + toDate: moment().format('YYYY-MM-DD'), filterByOption: 'with-transactions', itemsIds: [], }); diff --git a/packages/webapp/src/containers/FinancialStatements/SalesByItems/utils.tsx b/packages/webapp/src/containers/FinancialStatements/SalesByItems/utils.tsx index 461304506..b56536f33 100644 --- a/packages/webapp/src/containers/FinancialStatements/SalesByItems/utils.tsx +++ b/packages/webapp/src/containers/FinancialStatements/SalesByItems/utils.tsx @@ -25,8 +25,8 @@ export const getSalesByItemsQueryShema = () => { * Retrieves the default query. */ export const getDefaultSalesByItemsQuery = () => ({ - fromDate: moment().startOf('year').format('YYYY-MM-DD'), - toDate: moment().endOf('year').format('YYYY-MM-DD'), + fromDate: moment().startOf('month').format('YYYY-MM-DD'), + toDate: moment().format('YYYY-MM-DD'), filterByOption: 'with-transactions', itemsIds: [], }); diff --git a/packages/webapp/src/containers/FinancialStatements/TrialBalanceSheet/utils.tsx b/packages/webapp/src/containers/FinancialStatements/TrialBalanceSheet/utils.tsx index 6bbec6db7..62be9afa8 100644 --- a/packages/webapp/src/containers/FinancialStatements/TrialBalanceSheet/utils.tsx +++ b/packages/webapp/src/containers/FinancialStatements/TrialBalanceSheet/utils.tsx @@ -12,7 +12,7 @@ import { transformToForm } from '@/utils'; export function getDefaultTrialBalanceQuery() { return { fromDate: moment().startOf('year').format('YYYY-MM-DD'), - toDate: moment().endOf('year').format('YYYY-MM-DD'), + toDate: moment().format('YYYY-MM-DD'), basis: 'accrual', filterByOption: 'with-transactions', branchesIds: [], From a630e8a6129840f9885f97f786b5f9dec2435968 Mon Sep 17 00:00:00 2001 From: Ahmed Bouhuolia Date: Mon, 28 Aug 2023 20:53:52 +0200 Subject: [PATCH 3/3] fix: change the default from/to dates of customers/vendors transactions --- .../CustomersTransactions.tsx | 7 ++-- .../CustomersTransactionsProvider.tsx | 2 +- .../CustomersTransactions/_utils.ts | 33 +++++++++++++++-- .../ProfitLossSheet/ProfitLossSheetTable.tsx | 4 +-- .../VendorsTransactions.tsx | 7 ++-- .../VendorsTransactions/_utils.ts | 36 +++++++++++++++++-- 6 files changed, 72 insertions(+), 17 deletions(-) diff --git a/packages/webapp/src/containers/FinancialStatements/CustomersTransactions/CustomersTransactions.tsx b/packages/webapp/src/containers/FinancialStatements/CustomersTransactions/CustomersTransactions.tsx index b170cabe2..bd2d5bc52 100644 --- a/packages/webapp/src/containers/FinancialStatements/CustomersTransactions/CustomersTransactions.tsx +++ b/packages/webapp/src/containers/FinancialStatements/CustomersTransactions/CustomersTransactions.tsx @@ -13,6 +13,7 @@ import { CustomersTransactionsBody } from './CustomersTransactionsBody'; import { CustomersTransactionsProvider } from './CustomersTransactionsProvider'; import { compose } from '@/utils'; +import { useCustomersTransactionsQuery } from './_utils'; /** * Customers transactions. @@ -22,11 +23,7 @@ function CustomersTransactions({ toggleCustomersTransactionsFilterDrawer, }) { // filter - const [filter, setFilter] = useState({ - fromDate: moment().startOf('year').format('YYYY-MM-DD'), - toDate: moment().endOf('year').format('YYYY-MM-DD'), - filterByOption: 'with-transactions', - }); + const [filter, setFilter] = useCustomersTransactionsQuery(); const handleFilterSubmit = (filter) => { const _filter = { diff --git a/packages/webapp/src/containers/FinancialStatements/CustomersTransactions/CustomersTransactionsProvider.tsx b/packages/webapp/src/containers/FinancialStatements/CustomersTransactions/CustomersTransactionsProvider.tsx index 59079c1ef..ef7d69954 100644 --- a/packages/webapp/src/containers/FinancialStatements/CustomersTransactions/CustomersTransactionsProvider.tsx +++ b/packages/webapp/src/containers/FinancialStatements/CustomersTransactions/CustomersTransactionsProvider.tsx @@ -14,7 +14,7 @@ function CustomersTransactionsProvider({ filter, ...props }) { filter, ]); - // fetches the customers transactions. + // Fetches the customers transactions. const { data: customersTransactions, isFetching: isCustomersTransactionsFetching, diff --git a/packages/webapp/src/containers/FinancialStatements/CustomersTransactions/_utils.ts b/packages/webapp/src/containers/FinancialStatements/CustomersTransactions/_utils.ts index f416e7cbd..ba9e02a8f 100644 --- a/packages/webapp/src/containers/FinancialStatements/CustomersTransactions/_utils.ts +++ b/packages/webapp/src/containers/FinancialStatements/CustomersTransactions/_utils.ts @@ -1,6 +1,11 @@ +// @ts-nocheck import * as Yup from 'yup'; import intl from 'react-intl-universal'; import moment from 'moment'; +import { transformToForm } from '@/utils'; +import { castArray } from 'lodash'; +import { useMemo } from 'react'; +import { useAppQueryString } from '@/hooks'; export const getCustomersTransactionsQuerySchema = () => { return Yup.object().shape({ @@ -13,7 +18,31 @@ export const getCustomersTransactionsQuerySchema = () => { }; export const getCustomersTransactionsDefaultQuery = () => ({ - fromDate: moment().startOf('month').toDate(), - toDate: moment().toDate(), + fromDate: moment().startOf('month').format('YYYY-MM-DD'), + toDate: moment().format('YYYY-MM-DD'), customersIds: [], + filterByOption: 'with-transactions', }); + +const parseCustomersTransactionsQuery = (query) => { + const defaultQuery = getCustomersTransactionsDefaultQuery(); + + const transformedQuery = { + ...defaultQuery, + ...transformToForm(query, defaultQuery), + }; + return { + ...transformedQuery, + customersIds: castArray(transformedQuery.customersIds), + }; +}; + +export const useCustomersTransactionsQuery = () => { + const [locationQuery, setLocationQuery] = useAppQueryString(); + + const query = useMemo( + () => parseCustomersTransactionsQuery(locationQuery), + [locationQuery], + ); + return [query, setLocationQuery]; +}; diff --git a/packages/webapp/src/containers/FinancialStatements/ProfitLossSheet/ProfitLossSheetTable.tsx b/packages/webapp/src/containers/FinancialStatements/ProfitLossSheet/ProfitLossSheetTable.tsx index 0573e8e1a..933408534 100644 --- a/packages/webapp/src/containers/FinancialStatements/ProfitLossSheet/ProfitLossSheetTable.tsx +++ b/packages/webapp/src/containers/FinancialStatements/ProfitLossSheet/ProfitLossSheetTable.tsx @@ -23,7 +23,7 @@ export default function ProfitLossSheetTable({ } = useProfitLossSheetContext(); // Retrieves the profit/loss table columns. - const tableColumns = useProfitLossSheetColumns(); + const columns = useProfitLossSheetColumns(); // Retrieve default expanded rows of balance sheet. const expandedRows = React.useMemo( @@ -40,7 +40,7 @@ export default function ProfitLossSheetTable({ basis={query.basis} > { const _filter = { diff --git a/packages/webapp/src/containers/FinancialStatements/VendorsTransactions/_utils.ts b/packages/webapp/src/containers/FinancialStatements/VendorsTransactions/_utils.ts index 18f44e3f5..fc2cd02d8 100644 --- a/packages/webapp/src/containers/FinancialStatements/VendorsTransactions/_utils.ts +++ b/packages/webapp/src/containers/FinancialStatements/VendorsTransactions/_utils.ts @@ -1,6 +1,10 @@ +// @ts-nocheck import * as Yup from 'yup'; import intl from 'react-intl-universal'; import moment from 'moment'; +import { useMemo } from 'react'; +import { transformToForm } from '@/utils'; +import { useAppQueryString } from '@/hooks'; /** * The validation schema of vendors transactions. @@ -19,7 +23,35 @@ export const getVendorTransactionsQuerySchema = () => { * Retrieves the default query of vendors transactions. */ export const getVendorsTransactionsDefaultQuery = () => ({ - fromDate: moment().startOf('month').toDate(), - toDate: moment().toDate(), + fromDate: moment().startOf('month').format('YYYY-MM-DD'), + toDate: moment().format('YYYY-MM-DD'), vendorsIds: [], }); + +/** + * Parses the query of vendors transactions. + */ +const parseVendorsTransactionsQuery = (query) => { + const defaultQuery = getVendorsTransactionsDefaultQuery(); + const transformed = { + ...defaultQuery, + ...transformToForm(query, defaultQuery), + }; + return { + ...transformed, + vendorsIds: transformed.vendorsIds ? transformed.vendorsIds : [], + }; +}; + +/** + * Retrieves the query of vendors transactions. + */ +export const useVendorsTransactionsQuery = () => { + const [locationQuery, setLocationQuery] = useAppQueryString(); + + const query = useMemo( + () => parseVendorsTransactionsQuery(locationQuery), + [locationQuery], + ); + return [query, setLocationQuery]; +};