From 5d732844fbc90cd3aa152776f3591a017feaa393 Mon Sep 17 00:00:00 2001 From: 18alantom <2.alan.tom@gmail.com> Date: Mon, 21 Nov 2022 12:05:05 +0530 Subject: [PATCH] incr: add ledger links - fix sidebar issue - show grand total --- models/helpers.ts | 22 ++++++++++++++++----- models/inventory/StockMovement.ts | 10 ++++++++-- models/inventory/StockTransfer.ts | 14 ++++++++----- reports/GeneralLedger/GeneralLedger.ts | 26 +++++++++++++++++-------- reports/inventory/StockLedger.ts | 25 +++++++++++++++++++++--- src/components/Sidebar.vue | 15 ++++++++++---- src/pages/GeneralForm.vue | 27 ++++++++++++++++++++------ 7 files changed, 106 insertions(+), 33 deletions(-) diff --git a/models/helpers.ts b/models/helpers.ts index 9c954c9c..7fe46ed3 100644 --- a/models/helpers.ts +++ b/models/helpers.ts @@ -7,11 +7,11 @@ import { safeParseFloat } from 'utils/index'; import { Router } from 'vue-router'; import { AccountRootType, - AccountRootTypeEnum + AccountRootTypeEnum, } from './baseModels/Account/types'; import { Defaults, - numberSeriesDefaultsMap + numberSeriesDefaultsMap, } from './baseModels/Defaults/Defaults'; import { InvoiceStatus, ModelNameEnum } from './types'; @@ -60,15 +60,27 @@ export function getInvoiceActions( ]; } -export function getLedgerLinkAction(fyo: Fyo): Action { +export function getLedgerLinkAction( + fyo: Fyo, + isStock: boolean = false +): Action { + + let label = fyo.t`Ledger Entries`; + let reportClassName = 'GeneralLedger'; + + if (isStock) { + label = fyo.t`Stock Entries`; + reportClassName = 'StockLedger'; + } + return { - label: fyo.t`Ledger Entries`, + label, condition: (doc: Doc) => doc.isSubmitted, action: async (doc: Doc, router: Router) => { router.push({ name: 'Report', params: { - reportClassName: 'GeneralLedger', + reportClassName, defaultFilters: JSON.stringify({ referenceType: doc.schemaName, referenceName: doc.name, diff --git a/models/inventory/StockMovement.ts b/models/inventory/StockMovement.ts index 44eec5e0..3bdb744a 100644 --- a/models/inventory/StockMovement.ts +++ b/models/inventory/StockMovement.ts @@ -1,10 +1,12 @@ +import { Fyo } from 'fyo'; import { + Action, DefaultMap, FiltersMap, FormulaMap, - ListViewSettings, + ListViewSettings } from 'fyo/model/types'; -import { getDocStatusListColumn } from 'models/helpers'; +import { getDocStatusListColumn, getLedgerLinkAction } from 'models/helpers'; import { LedgerPosting } from 'models/Transactional/LedgerPosting'; import { ModelNameEnum } from 'models/types'; import { Money } from 'pesa'; @@ -63,4 +65,8 @@ export class StockMovement extends Transfer { toLocation: row.toLocation, })); } + + static getActions(fyo: Fyo): Action[] { + return [getLedgerLinkAction(fyo, true)]; + } } diff --git a/models/inventory/StockTransfer.ts b/models/inventory/StockTransfer.ts index 800882f8..a0cbe88d 100644 --- a/models/inventory/StockTransfer.ts +++ b/models/inventory/StockTransfer.ts @@ -1,10 +1,10 @@ -import { t } from 'fyo'; +import { Fyo, t } from 'fyo'; import { Attachment } from 'fyo/core/types'; import { Doc } from 'fyo/model/doc'; -import { DefaultMap, FiltersMap, FormulaMap } from 'fyo/model/types'; -import { NotFoundError, ValidationError } from 'fyo/utils/errors'; +import { Action, DefaultMap, FiltersMap, FormulaMap } from 'fyo/model/types'; +import { ValidationError } from 'fyo/utils/errors'; import { Defaults } from 'models/baseModels/Defaults/Defaults'; -import { getNumberSeries } from 'models/helpers'; +import { getLedgerLinkAction, getNumberSeries } from 'models/helpers'; import { LedgerPosting } from 'models/Transactional/LedgerPosting'; import { ModelNameEnum } from 'models/types'; import { Money } from 'pesa'; @@ -100,7 +100,7 @@ export abstract class StockTransfer extends Transfer { await posting.credit(stockReceivedButNotBilled, amount); } - await posting.makeRoundOffEntry() + await posting.makeRoundOffEntry(); return posting; } @@ -133,4 +133,8 @@ export abstract class StockTransfer extends Transfer { throw new ValidationError(messages.join(' ')); } } + + static getActions(fyo: Fyo): Action[] { + return [getLedgerLinkAction(fyo, false), getLedgerLinkAction(fyo, true)]; + } } diff --git a/reports/GeneralLedger/GeneralLedger.ts b/reports/GeneralLedger/GeneralLedger.ts index bb6f122a..1cb54f88 100644 --- a/reports/GeneralLedger/GeneralLedger.ts +++ b/reports/GeneralLedger/GeneralLedger.ts @@ -17,6 +17,8 @@ type ReferenceType = | ModelNameEnum.PurchaseInvoice | ModelNameEnum.Payment | ModelNameEnum.JournalEntry + | ModelNameEnum.Shipment + | ModelNameEnum.PurchaseReceipt | 'All'; export class GeneralLedger extends LedgerReport { @@ -272,17 +274,25 @@ export class GeneralLedger extends LedgerReport { } getFilters() { + const refTypeOptions = [ + { label: t`All`, value: 'All' }, + { label: t`Sales Invoices`, value: 'SalesInvoice' }, + { label: t`Purchase Invoices`, value: 'PurchaseInvoice' }, + { label: t`Payments`, value: 'Payment' }, + { label: t`Journal Entries`, value: 'JournalEntry' }, + ]; + + if (this.fyo.store.appFlags.isInventoryEnabled) { + refTypeOptions.push( + { label: t`Shipment`, value: 'Shipment' }, + { label: t`Purchase Receipt`, value: 'PurchaseReceipt' } + ); + } + return [ { fieldtype: 'Select', - options: [ - { label: t`All`, value: 'All' }, - { label: t`Sales Invoices`, value: 'SalesInvoice' }, - { label: t`Purchase Invoices`, value: 'PurchaseInvoice' }, - { label: t`Payments`, value: 'Payment' }, - { label: t`Journal Entries`, value: 'JournalEntry' }, - ], - + options: refTypeOptions, label: t`Ref Type`, fieldname: 'referenceType', placeholder: t`Ref Type`, diff --git a/reports/inventory/StockLedger.ts b/reports/inventory/StockLedger.ts index 0f170bf7..1c14348d 100644 --- a/reports/inventory/StockLedger.ts +++ b/reports/inventory/StockLedger.ts @@ -11,6 +11,12 @@ import { isNumeric } from 'src/utils'; import { getRawStockLedgerEntries, getStockLedgerEntries } from './helpers'; import { ComputedStockLedgerEntry } from './types'; +type ReferenceType = + | ModelNameEnum.StockMovement + | ModelNameEnum.Shipment + | ModelNameEnum.PurchaseReceipt + | 'All'; + export class StockLedger extends Report { static title = t`Stock Ledger`; static reportName = 'stock-ledger'; @@ -25,6 +31,9 @@ export class StockLedger extends Report { fromDate?: string; toDate?: string; ascending?: boolean; + referenceType?: ReferenceType = 'All'; + referenceName?: string; + groupBy: 'none' | 'item' | 'location' = 'none'; constructor(fyo: Fyo) { @@ -101,6 +110,17 @@ export class StockLedger extends Report { continue; } + if ( + this.referenceType !== 'All' && + row.referenceType !== this.referenceType + ) { + continue; + } + + if (this.referenceName && row.referenceName !== this.referenceName) { + continue; + } + row.name = ++i; filteredRawData.push(row); } @@ -265,14 +285,14 @@ export class StockLedger extends Report { getFilters(): Field[] { return [ - /* { fieldtype: 'Select', options: [ { label: t`All`, value: 'All' }, { label: t`Stock Movements`, value: 'StockMovement' }, + { label: t`Shipment`, value: 'Shipment' }, + { label: t`Purchase Receipt`, value: 'PurchaseReceipt' }, ], - label: t`Ref Type`, fieldname: 'referenceType', placeholder: t`Ref Type`, @@ -285,7 +305,6 @@ export class StockLedger extends Report { emptyMessage: t`Change Ref Type`, fieldname: 'referenceName', }, - */ { fieldtype: 'Link', target: 'Item', diff --git a/src/components/Sidebar.vue b/src/components/Sidebar.vue index db4a424d..e5431a4d 100644 --- a/src/components/Sidebar.vue +++ b/src/components/Sidebar.vue @@ -208,11 +208,18 @@ export default { } }, isItemActive(item) { - let { path: currentRoute, params } = this.$route; - let routeMatch = currentRoute === item.route; - let schemaNameMatch = + const { path: currentRoute, params } = this.$route; + const routeMatch = currentRoute === item.route; + + const schemaNameMatch = item.schemaName && params.schemaName === item.schemaName; - return routeMatch || schemaNameMatch; + + const isMatch = routeMatch || schemaNameMatch; + if (params.name && item.schemaName && !isMatch) { + return currentRoute.includes(`${item.schemaName}/${params.name}`); + } + + return isMatch; }, isGroupActive(group) { return this.activeGroup && group.label === this.activeGroup.label; diff --git a/src/pages/GeneralForm.vue b/src/pages/GeneralForm.vue index 10e2f5ad..5f472c81 100644 --- a/src/pages/GeneralForm.vue +++ b/src/pages/GeneralForm.vue @@ -28,7 +28,7 @@