2
0
mirror of https://github.com/frappe/books.git synced 2024-12-23 03:19:01 +00:00
books/reports/inventory/StockBalance.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

164 lines
3.8 KiB
TypeScript
Raw Normal View History

2022-11-25 09:21:58 +00:00
import { t } from 'fyo';
import { RawValueMap } from 'fyo/core/types';
import { Action } from 'fyo/model/types';
import getCommonExportActions from 'reports/commonExporter';
import { ColumnField, ReportData } from 'reports/types';
import { Field } from 'schemas/types';
import { getStockBalanceEntries } from './helpers';
import { StockLedger } from './StockLedger';
import { ReferenceType } from './types';
export class StockBalance extends StockLedger {
static title = t`Stock Balance`;
static reportName = 'stock-balance';
static isInventory = true;
override ascending = true;
2022-11-25 09:21:58 +00:00
override referenceType: ReferenceType = 'All';
override referenceName = '';
2022-11-25 09:21:58 +00:00
override async _getReportData(force?: boolean): Promise<ReportData> {
if (this.shouldRefresh || force || !this._rawData?.length) {
await this._setRawData();
}
const filters = {
item: this.item,
location: this.location,
batch: this.batch,
2022-11-25 09:21:58 +00:00
fromDate: this.fromDate,
toDate: this.toDate,
};
2022-11-25 09:21:58 +00:00
const rawData = getStockBalanceEntries(this._rawData ?? [], filters);
return rawData.map((sbe, i) => {
const row = { ...sbe, name: i + 1 } as RawValueMap;
return this._convertRawDataRowToReportRow(row, {
incomingQuantity: 'green',
outgoingQuantity: 'red',
balanceQuantity: null,
});
});
}
getFilters(): Field[] {
const filters = [
2022-11-25 09:21:58 +00:00
{
fieldtype: 'Link',
target: 'Item',
placeholder: t`Item`,
label: t`Item`,
fieldname: 'item',
},
{
fieldtype: 'Link',
target: 'Location',
placeholder: t`Location`,
label: t`Location`,
fieldname: 'location',
},
...(this.hasBatches
? [
{
fieldtype: 'Link',
2023-02-28 06:01:04 +00:00
target: 'Batch',
placeholder: t`Batch`,
label: t`Batch`,
fieldname: 'batch',
},
]
: []),
2022-11-25 09:21:58 +00:00
{
fieldtype: 'Date',
placeholder: t`From Date`,
label: t`From Date`,
fieldname: 'fromDate',
},
{
fieldtype: 'Date',
placeholder: t`To Date`,
label: t`To Date`,
fieldname: 'toDate',
},
] as Field[];
return filters;
2022-11-25 09:21:58 +00:00
}
getColumns(): ColumnField[] {
return [
{
fieldname: 'name',
label: '#',
fieldtype: 'Int',
width: 0.5,
},
{
fieldname: 'item',
label: 'Item',
fieldtype: 'Link',
},
{
fieldname: 'location',
label: 'Location',
fieldtype: 'Link',
},
...(this.hasBatches
? ([
{ fieldname: 'batch', label: 'Batch', fieldtype: 'Link' },
] as ColumnField[])
: []),
2022-11-25 09:21:58 +00:00
{
fieldname: 'balanceQuantity',
label: 'Balance Qty.',
fieldtype: 'Float',
},
{
fieldname: 'balanceValue',
label: 'Balance Value',
fieldtype: 'Float',
},
{
fieldname: 'openingQuantity',
label: 'Opening Qty.',
fieldtype: 'Float',
},
{
fieldname: 'openingValue',
label: 'Opening Value',
fieldtype: 'Float',
},
{
fieldname: 'incomingQuantity',
label: 'In Qty.',
fieldtype: 'Float',
},
{
fieldname: 'incomingValue',
label: 'In Value',
fieldtype: 'Currency',
},
{
fieldname: 'outgoingQuantity',
label: 'Out Qty.',
fieldtype: 'Float',
},
{
fieldname: 'outgoingValue',
label: 'Out Value',
fieldtype: 'Currency',
},
{
fieldname: 'valuationRate',
label: 'Valuation rate',
fieldtype: 'Currency',
},
];
}
getActions(): Action[] {
return getCommonExportActions(this);
}
}