taxtank-core 0.3.0 → 0.3.1
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/bundles/taxtank-core.umd.js +102 -56
- package/bundles/taxtank-core.umd.js.map +1 -1
- package/esm2015/lib/collections/bank-account.collection.js +3 -3
- package/esm2015/lib/collections/bank-transaction.collection.js +3 -3
- package/esm2015/lib/collections/client-movement.collection.js +3 -3
- package/esm2015/lib/collections/client-portfolio-report.collection.js +3 -3
- package/esm2015/lib/collections/client.collection.js +3 -3
- package/esm2015/lib/collections/collection-dictionary.js +1 -1
- package/esm2015/lib/collections/collection.js +75 -0
- package/esm2015/lib/collections/depreciation-forecast.collection.js +5 -5
- package/esm2015/lib/collections/depreciation.collection.js +3 -3
- package/esm2015/lib/collections/employee.collection.js +3 -3
- package/esm2015/lib/collections/income-source.collection.js +3 -3
- package/esm2015/lib/collections/loan.collection.js +3 -3
- package/esm2015/lib/collections/message-document.collection.js +3 -3
- package/esm2015/lib/collections/message.collection.js +3 -3
- package/esm2015/lib/collections/property.collection.js +3 -3
- package/esm2015/lib/collections/service-price.collection.js +3 -3
- package/esm2015/lib/collections/service-subscription.collection.js +3 -3
- package/esm2015/lib/collections/tax-return-category-item.collection.js +3 -3
- package/esm2015/lib/collections/tax-review.collection.js +3 -3
- package/esm2015/lib/collections/transaction-allocation.collection.js +3 -3
- package/esm2015/lib/collections/transaction.collection.js +3 -3
- package/esm2015/lib/collections/user-event-setting.collection.js +3 -3
- package/esm2015/lib/models/data-table/data-table.js +6 -4
- package/esm2015/lib/models/logbook/vehicle-claim.js +7 -1
- package/esm2015/lib/models/transaction/transaction.js +7 -1
- package/esm2015/lib/services/pdf/pdf.service.js +39 -6
- package/esm2015/lib/services/xlsx/xlsx.service.js +1 -1
- package/esm2015/public-api.js +2 -2
- package/fesm2015/taxtank-core.js +79 -40
- package/fesm2015/taxtank-core.js.map +1 -1
- package/lib/collections/bank-account.collection.d.ts +2 -2
- package/lib/collections/bank-transaction.collection.d.ts +2 -2
- package/lib/collections/client-movement.collection.d.ts +2 -2
- package/lib/collections/client-portfolio-report.collection.d.ts +2 -2
- package/lib/collections/client.collection.d.ts +2 -2
- package/lib/collections/collection-dictionary.d.ts +2 -2
- package/lib/collections/{abstract.collection.d.ts → collection.d.ts} +3 -9
- package/lib/collections/depreciation-forecast.collection.d.ts +2 -2
- package/lib/collections/depreciation.collection.d.ts +2 -2
- package/lib/collections/employee.collection.d.ts +2 -2
- package/lib/collections/income-source.collection.d.ts +2 -2
- package/lib/collections/loan.collection.d.ts +2 -2
- package/lib/collections/message-document.collection.d.ts +2 -2
- package/lib/collections/message.collection.d.ts +2 -2
- package/lib/collections/property.collection.d.ts +2 -2
- package/lib/collections/service-price.collection.d.ts +2 -2
- package/lib/collections/service-subscription.collection.d.ts +2 -2
- package/lib/collections/tax-return-category-item.collection.d.ts +2 -2
- package/lib/collections/tax-review.collection.d.ts +2 -2
- package/lib/collections/transaction-allocation.collection.d.ts +2 -2
- package/lib/collections/transaction.collection.d.ts +2 -2
- package/lib/collections/user-event-setting.collection.d.ts +2 -2
- package/lib/models/data-table/data-table.d.ts +2 -2
- package/lib/models/logbook/vehicle-claim.d.ts +4 -0
- package/lib/models/transaction/transaction.d.ts +2 -0
- package/lib/services/pdf/pdf.service.d.ts +10 -1
- package/lib/services/xlsx/xlsx.service.d.ts +1 -1
- package/package.json +1 -1
- package/public-api.d.ts +1 -1
- package/esm2015/lib/collections/abstract.collection.js +0 -83
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Collection } from './collection';
|
|
2
2
|
import { BankAccountTypeEnum } from '../db/Enums/bank-account-type.enum';
|
|
3
3
|
import { TankTypeEnum } from '../db/Enums/tank-type.enum';
|
|
4
4
|
import { BankAccount } from '../models/bank/bank-account';
|
|
@@ -7,7 +7,7 @@ import { Property } from '../models/property/property';
|
|
|
7
7
|
/**
|
|
8
8
|
* Collection of bank accounts.
|
|
9
9
|
*/
|
|
10
|
-
export declare class BankAccountCollection extends
|
|
10
|
+
export declare class BankAccountCollection extends Collection<BankAccount> {
|
|
11
11
|
/**
|
|
12
12
|
* get list of bank accounts with passed types
|
|
13
13
|
*/
|
|
@@ -2,7 +2,7 @@ import { BankTransaction } from '../models/bank/bank-transaction';
|
|
|
2
2
|
import { MonthNumberEnum } from '../models/financial-year/month-number.enum';
|
|
3
3
|
import { IncomeSource } from '../models/income-source/income-source';
|
|
4
4
|
import { BankAccount } from '../models/bank/bank-account';
|
|
5
|
-
import {
|
|
5
|
+
import { Collection } from './collection';
|
|
6
6
|
import { CollectionDictionary } from './collection-dictionary';
|
|
7
7
|
import { TransactionAllocationCollection } from './transaction-allocation.collection';
|
|
8
8
|
/**
|
|
@@ -11,7 +11,7 @@ import { TransactionAllocationCollection } from './transaction-allocation.collec
|
|
|
11
11
|
* @TODO find way to accept interface with allocation instead of bankTransaction to prevent wrong usage
|
|
12
12
|
* because all amounts calculates with allocated amounts but not from bank transactions amounts.
|
|
13
13
|
*/
|
|
14
|
-
export declare class BankTransactionCollection extends
|
|
14
|
+
export declare class BankTransactionCollection extends Collection<BankTransaction> {
|
|
15
15
|
getAmount(): number;
|
|
16
16
|
/**
|
|
17
17
|
* Difference between total bank transactions amount and sum of allocations for passed bank transactions
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Collection } from './collection';
|
|
2
2
|
import { ClientMovement } from '../models/client/client-movement';
|
|
3
3
|
import { EmployeeCollection } from './employee.collection';
|
|
4
4
|
import { ClientCollection } from './client.collection';
|
|
@@ -6,7 +6,7 @@ import { FirmTypeEnum } from '../db/Enums/firm-type.enum';
|
|
|
6
6
|
/**
|
|
7
7
|
* Collection of tax review
|
|
8
8
|
*/
|
|
9
|
-
export declare class ClientMovementCollection extends
|
|
9
|
+
export declare class ClientMovementCollection extends Collection<ClientMovement> {
|
|
10
10
|
get active(): ClientMovementCollection;
|
|
11
11
|
get employees(): EmployeeCollection;
|
|
12
12
|
get clients(): ClientCollection;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Collection of employee clients tax summary information
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
4
|
+
import { Collection } from './collection';
|
|
5
5
|
import { ClientPortfolioReport } from '../models/client/client-portfolio-report';
|
|
6
|
-
export declare class ClientPortfolioReportCollection extends
|
|
6
|
+
export declare class ClientPortfolioReportCollection extends Collection<ClientPortfolioReport> {
|
|
7
7
|
get marketValue(): number;
|
|
8
8
|
get loanBalance(): number;
|
|
9
9
|
get equityPosition(): number;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Collection } from './collection';
|
|
2
2
|
import { User } from '../models/user/user';
|
|
3
|
-
export declare class ClientCollection extends
|
|
3
|
+
export declare class ClientCollection extends Collection<User> {
|
|
4
4
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Collection as BaseCollection } from './collection';
|
|
2
2
|
/**
|
|
3
3
|
* List of collections grouped by passed property
|
|
4
4
|
*/
|
|
5
|
-
export declare class CollectionDictionary<Collection extends
|
|
5
|
+
export declare class CollectionDictionary<Collection extends BaseCollection<object>> {
|
|
6
6
|
/**
|
|
7
7
|
* List of grouped collections
|
|
8
8
|
*/
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { CollectionDictionary } from './collection-dictionary';
|
|
2
2
|
/**
|
|
3
|
-
* collection
|
|
3
|
+
* Base collection class. Contains common properties and methods for all collections
|
|
4
4
|
*/
|
|
5
|
-
export declare
|
|
5
|
+
export declare class Collection<Model extends object> implements Iterable<Model> {
|
|
6
6
|
items: Model[];
|
|
7
7
|
constructor(items?: Model[]);
|
|
8
8
|
create(items?: Model[]): this;
|
|
9
9
|
getBy(field: string, value: any): this;
|
|
10
|
-
groupBy(path?: string): CollectionDictionary<
|
|
10
|
+
groupBy(path?: string): CollectionDictionary<Collection<Model>>;
|
|
11
11
|
indexBy(path: string): object;
|
|
12
12
|
/**
|
|
13
13
|
* Iterator that allow to iterate collection items
|
|
@@ -17,12 +17,6 @@ export declare abstract class AbstractCollection<Model extends object> implement
|
|
|
17
17
|
* get collection length
|
|
18
18
|
*/
|
|
19
19
|
get length(): number;
|
|
20
|
-
/**
|
|
21
|
-
* method returns amount of fields from passed items
|
|
22
|
-
* @param field Name of field for calculation
|
|
23
|
-
* @param items (optional) Array of items need to be calculated. All collection's items by default
|
|
24
|
-
*/
|
|
25
|
-
protected getSummary(field: string, items?: Model[]): number;
|
|
26
20
|
/**
|
|
27
21
|
* Get list of items ids
|
|
28
22
|
*/
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Collection } from './collection';
|
|
2
2
|
import { DepreciationForecast } from '../models/depreciation/depreciation-forecast';
|
|
3
3
|
/**
|
|
4
4
|
* Collection of depreciations
|
|
5
5
|
*/
|
|
6
|
-
export declare class DepreciationForecastCollection extends
|
|
6
|
+
export declare class DepreciationForecastCollection extends Collection<DepreciationForecast> {
|
|
7
7
|
filterByYear(financialYear: number): any;
|
|
8
8
|
getClaimAmountByMonth(month: number): number;
|
|
9
9
|
get amount(): number;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { TankTypeEnum } from '../db/Enums/tank-type.enum';
|
|
2
|
-
import {
|
|
2
|
+
import { Collection } from './collection';
|
|
3
3
|
import { Depreciation } from '../models/depreciation/depreciation';
|
|
4
4
|
import { DepreciationCapitalProject } from '../models/depreciation/depreciation-capital-project';
|
|
5
|
-
export declare class DepreciationCollection extends
|
|
5
|
+
export declare class DepreciationCollection extends Collection<Depreciation> {
|
|
6
6
|
/**
|
|
7
7
|
* Get total amount of all depreciations in the collection
|
|
8
8
|
*/
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Collection } from './collection';
|
|
2
2
|
import { User } from '../models/user/user';
|
|
3
|
-
export declare class EmployeeCollection extends
|
|
3
|
+
export declare class EmployeeCollection extends Collection<User> {
|
|
4
4
|
get accountant(): User;
|
|
5
5
|
get advisors(): User[];
|
|
6
6
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Collection } from './collection';
|
|
2
2
|
import { IncomeSource } from '../models/income-source/income-source';
|
|
3
3
|
import { TankTypeEnum } from '../db/Enums/tank-type.enum';
|
|
4
4
|
import { IncomeSourceTypeEnum } from '../db/Enums/income-source-type.enum';
|
|
@@ -6,7 +6,7 @@ import { ISalaryForecast } from '../interfaces/salary-forecast.interface';
|
|
|
6
6
|
/**
|
|
7
7
|
* Collection of income sources
|
|
8
8
|
*/
|
|
9
|
-
export declare class IncomeSourceCollection extends
|
|
9
|
+
export declare class IncomeSourceCollection extends Collection<IncomeSource> {
|
|
10
10
|
filterByTank(tank: TankTypeEnum): IncomeSource[];
|
|
11
11
|
/**
|
|
12
12
|
* Filter income sources by provided tyoes
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Collection } from './collection';
|
|
2
2
|
import { Loan } from '../models/loan/loan';
|
|
3
|
-
export declare class LoanCollection extends
|
|
3
|
+
export declare class LoanCollection extends Collection<Loan> {
|
|
4
4
|
/**
|
|
5
5
|
* Get new collection of loans filtered by bank accounts ids
|
|
6
6
|
* @param ids list of bank accounts ids for filter
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Collection } from './collection';
|
|
2
2
|
import { MessageDocument } from '../models/chat/message-document';
|
|
3
3
|
/**
|
|
4
4
|
* Collection of MessageDocument instances
|
|
5
5
|
*/
|
|
6
|
-
export declare class MessageDocumentCollection extends
|
|
6
|
+
export declare class MessageDocumentCollection extends Collection<MessageDocument> {
|
|
7
7
|
/**
|
|
8
8
|
* get list of documents which are not attached to any message
|
|
9
9
|
*/
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Collection } from './collection';
|
|
2
2
|
import { Message } from '../models/chat/message';
|
|
3
3
|
import { User } from '../models/user/user';
|
|
4
|
-
export declare class MessageCollection extends
|
|
4
|
+
export declare class MessageCollection extends Collection<Message> {
|
|
5
5
|
getFirstUnreadMessage(user: User): Message;
|
|
6
6
|
/**
|
|
7
7
|
* Get List of unread chats
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Collection } from './collection';
|
|
2
2
|
import { Property } from '../models/property/property';
|
|
3
3
|
import { PropertyCategory } from '../models/property/property-category';
|
|
4
|
-
export declare class PropertyCollection extends
|
|
4
|
+
export declare class PropertyCollection extends Collection<Property> {
|
|
5
5
|
/**
|
|
6
6
|
* Get new property collection filtered by category id
|
|
7
7
|
* @param id id of category for filter
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Collection } from './collection';
|
|
2
2
|
import { ServicePrice } from '../models/service-subscription/service-price';
|
|
3
|
-
export declare class ServicePriceCollection extends
|
|
3
|
+
export declare class ServicePriceCollection extends Collection<ServicePrice> {
|
|
4
4
|
get work(): ServicePrice;
|
|
5
5
|
get property(): ServicePrice;
|
|
6
6
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Collection } from './collection';
|
|
2
2
|
import { ServiceSubscription } from '../models/service-subscription/service-subscription';
|
|
3
|
-
export declare class ServiceSubscriptionCollection extends
|
|
3
|
+
export declare class ServiceSubscriptionCollection extends Collection<ServiceSubscription> {
|
|
4
4
|
get individual(): ServiceSubscription;
|
|
5
5
|
get investor(): ServiceSubscription;
|
|
6
6
|
get investorPlus(): ServiceSubscription;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Collection } from './collection';
|
|
2
2
|
import { TaxReturnCategoryItem } from '../models/tax-summary/tax-return-category-item';
|
|
3
3
|
import { TaxReturnCategorySectionEnum } from '../db/Enums/tax-return-category-section.enum';
|
|
4
4
|
/**
|
|
5
5
|
* collection for tax return category items
|
|
6
6
|
*/
|
|
7
|
-
export declare class TaxReturnCategoryItemCollection extends
|
|
7
|
+
export declare class TaxReturnCategoryItemCollection extends Collection<TaxReturnCategoryItem> {
|
|
8
8
|
/**
|
|
9
9
|
* Work income
|
|
10
10
|
*/
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Collection } from './collection';
|
|
2
2
|
import { TaxReview } from '../models/tax-review/tax-review';
|
|
3
3
|
import { TaxReviewStatusEnum } from '../db/Enums/tax-review-status.enum';
|
|
4
4
|
import { User } from '../models/user/user';
|
|
5
5
|
/**
|
|
6
6
|
* Collection of tax review
|
|
7
7
|
*/
|
|
8
|
-
export declare class TaxReviewCollection extends
|
|
8
|
+
export declare class TaxReviewCollection extends Collection<TaxReview> {
|
|
9
9
|
/**
|
|
10
10
|
* Get tax reviews items with SENT & COMPLETED statuses
|
|
11
11
|
*/
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Collection } from './collection';
|
|
2
2
|
import { TransactionAllocation } from '../models/transaction/transaction-allocation';
|
|
3
3
|
import { BankTransactionCollection } from './bank-transaction.collection';
|
|
4
4
|
import { CollectionDictionary } from './collection-dictionary';
|
|
5
5
|
import { Transaction } from '../models/transaction/transaction';
|
|
6
6
|
import { BankTransaction } from '../models/bank/bank-transaction';
|
|
7
|
-
export declare class TransactionAllocationCollection extends
|
|
7
|
+
export declare class TransactionAllocationCollection extends Collection<TransactionAllocation> {
|
|
8
8
|
get amount(): number;
|
|
9
9
|
getByTransactionsIds(ids: number[]): TransactionAllocationCollection;
|
|
10
10
|
getByBankTransactionsIds(ids: number[]): TransactionAllocationCollection;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Collection } from './collection';
|
|
2
2
|
import { Transaction } from '../models/transaction/transaction';
|
|
3
3
|
import { TransactionAllocationCollection } from './transaction-allocation.collection';
|
|
4
4
|
import { TankTypeEnum } from '../db/Enums/tank-type.enum';
|
|
@@ -6,7 +6,7 @@ import { ChartAccountsCategoryEnum } from '../db/Enums/chart-accounts-category.e
|
|
|
6
6
|
/**
|
|
7
7
|
* Collection of transactions
|
|
8
8
|
*/
|
|
9
|
-
export declare class TransactionCollection extends
|
|
9
|
+
export declare class TransactionCollection extends Collection<Transaction> {
|
|
10
10
|
/**
|
|
11
11
|
* Get total amount of all transactions in the collection
|
|
12
12
|
*/
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Collection } from './collection';
|
|
2
2
|
import { UserEventSetting } from '../models/user-event/user-event-setting';
|
|
3
3
|
/**
|
|
4
4
|
* Collection of user event settings
|
|
5
5
|
*/
|
|
6
|
-
export declare class UserEventSettingCollection extends
|
|
6
|
+
export declare class UserEventSettingCollection extends Collection<UserEventSetting> {
|
|
7
7
|
getConfigurableBy(field: string): UserEventSettingCollection;
|
|
8
8
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DataTableColumn } from "./data-table-column";
|
|
2
|
-
import {
|
|
2
|
+
import { Collection } from "../../collections/collection";
|
|
3
3
|
/**
|
|
4
4
|
* Class to generate data-table structure based on provided collection.
|
|
5
5
|
* Use to work with HTML/PDF/XLSX tables
|
|
@@ -18,7 +18,7 @@ export declare class DataTable<Model extends object> {
|
|
|
18
18
|
*/
|
|
19
19
|
rows: Array<string>[];
|
|
20
20
|
footerRow: string[];
|
|
21
|
-
constructor(collection:
|
|
21
|
+
constructor(collection: Collection<Model>, columns: DataTableColumn<Model>[], caption: string, footerCaption?: string);
|
|
22
22
|
private setRows;
|
|
23
23
|
private setFooterRow;
|
|
24
24
|
}
|
|
@@ -65,6 +65,8 @@ export declare class Transaction extends TransactionBase implements IReceipt, IT
|
|
|
65
65
|
* @TODO bad usage of get (and all is* methods), getter should sound like a noun
|
|
66
66
|
*/
|
|
67
67
|
get isTransfer(): boolean;
|
|
68
|
+
get debit(): number;
|
|
69
|
+
get credit(): number;
|
|
68
70
|
/**
|
|
69
71
|
* Get value of transaction metadata field
|
|
70
72
|
* @param field for which value should be returned
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DataTable } from
|
|
1
|
+
import { DataTable } from '../../models/data-table/data-table';
|
|
2
2
|
import * as i0 from "@angular/core";
|
|
3
3
|
export declare class PdfService {
|
|
4
4
|
/**
|
|
@@ -6,6 +6,15 @@ export declare class PdfService {
|
|
|
6
6
|
*/
|
|
7
7
|
download(tables: DataTable<any>[], title: string, fileName: string): void;
|
|
8
8
|
/**
|
|
9
|
+
* @Todo rename when all DataTable dependent methods will be cleared-up
|
|
10
|
+
*/
|
|
11
|
+
exportTables(tables: NodeListOf<HTMLTableElement>, title: string, fileName: string): void;
|
|
12
|
+
/**
|
|
13
|
+
* @Todo rename when all DataTable dependent methods will be cleared-up
|
|
14
|
+
*/
|
|
15
|
+
private generateFromTables;
|
|
16
|
+
/**
|
|
17
|
+
* @Todo remove/refactor when all DataTable dependent methods will be cleared-up
|
|
9
18
|
* Generate PDF file from provided data
|
|
10
19
|
*/
|
|
11
20
|
private generatePdfFile;
|
package/package.json
CHANGED
package/public-api.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export * from './lib/tt-core.module';
|
|
|
5
5
|
/**
|
|
6
6
|
* Collections
|
|
7
7
|
*/
|
|
8
|
-
export * from './lib/collections/
|
|
8
|
+
export * from './lib/collections/collection';
|
|
9
9
|
export * from './lib/collections/bank-account.collection';
|
|
10
10
|
export * from './lib/collections/bank-transaction.collection';
|
|
11
11
|
export * from './lib/collections/client.collection';
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { CollectionDictionary } from './collection-dictionary';
|
|
2
|
-
import first from 'lodash/first';
|
|
3
|
-
import last from 'lodash/last';
|
|
4
|
-
import get from 'lodash/get';
|
|
5
|
-
const DEFAULT_INDEX = 'other';
|
|
6
|
-
/**
|
|
7
|
-
* collection abstract class. Contains common properties and methods for all collections
|
|
8
|
-
*/
|
|
9
|
-
export class AbstractCollection {
|
|
10
|
-
constructor(items = []) {
|
|
11
|
-
this.items = items;
|
|
12
|
-
}
|
|
13
|
-
create(items = []) {
|
|
14
|
-
return new this.constructor(items);
|
|
15
|
-
}
|
|
16
|
-
getBy(field, value) {
|
|
17
|
-
return this.create(this.items.filter((item) => item[field] === value));
|
|
18
|
-
}
|
|
19
|
-
groupBy(path = '') {
|
|
20
|
-
return new CollectionDictionary(this, path);
|
|
21
|
-
}
|
|
22
|
-
indexBy(path) {
|
|
23
|
-
// Create empty initial object for groups
|
|
24
|
-
const result = {};
|
|
25
|
-
this.toArray().forEach((model) => {
|
|
26
|
-
result[get(model, path, DEFAULT_INDEX)] = model;
|
|
27
|
-
});
|
|
28
|
-
return result;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Iterator that allow to iterate collection items
|
|
32
|
-
*/
|
|
33
|
-
[Symbol.iterator]() {
|
|
34
|
-
// .values() returns Iterator instance for array
|
|
35
|
-
return this.items.values();
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* get collection length
|
|
39
|
-
*/
|
|
40
|
-
get length() {
|
|
41
|
-
return this.items.length;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* method returns amount of fields from passed items
|
|
45
|
-
* @param field Name of field for calculation
|
|
46
|
-
* @param items (optional) Array of items need to be calculated. All collection's items by default
|
|
47
|
-
*/
|
|
48
|
-
getSummary(field, items = this.toArray()) {
|
|
49
|
-
return items.reduce((sum, item) => sum += item[field], 0);
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Get list of items ids
|
|
53
|
-
*/
|
|
54
|
-
getIds() {
|
|
55
|
-
return this.items.map((item) => item['id']);
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Get single item by id
|
|
59
|
-
*/
|
|
60
|
-
getById(id) {
|
|
61
|
-
return this.items.find((item) => item['id'] === id);
|
|
62
|
-
}
|
|
63
|
-
getByIds(ids) {
|
|
64
|
-
return this.items.filter((item) => ids.includes(item['id']));
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Get total sum of items by field
|
|
68
|
-
* @param field Name of the field for sum
|
|
69
|
-
*/
|
|
70
|
-
sumBy(field) {
|
|
71
|
-
return +this.items.reduce((sum, item) => sum + Number(item[field]), 0).toFixed(2);
|
|
72
|
-
}
|
|
73
|
-
toArray() {
|
|
74
|
-
return [...this.items];
|
|
75
|
-
}
|
|
76
|
-
get first() {
|
|
77
|
-
return first(this.items);
|
|
78
|
-
}
|
|
79
|
-
get last() {
|
|
80
|
-
return last(this.items);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYWJzdHJhY3QuY29sbGVjdGlvbi5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uL3Byb2plY3RzL3R0LWNvcmUvc3JjL2xpYi9jb2xsZWN0aW9ucy9hYnN0cmFjdC5jb2xsZWN0aW9uLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxvQkFBb0IsRUFBRSxNQUFNLHlCQUF5QixDQUFDO0FBQy9ELE9BQU8sS0FBSyxNQUFNLGNBQWMsQ0FBQztBQUNqQyxPQUFPLElBQUksTUFBTSxhQUFhLENBQUM7QUFDL0IsT0FBTyxHQUFHLE1BQU0sWUFBWSxDQUFDO0FBRTdCLE1BQU0sYUFBYSxHQUFHLE9BQU8sQ0FBQztBQUU5Qjs7R0FFRztBQUNILE1BQU0sT0FBZ0Isa0JBQWtCO0lBSXRDLFlBQVksUUFBaUIsRUFBRTtRQUM3QixJQUFJLENBQUMsS0FBSyxHQUFHLEtBQUssQ0FBQztJQUNyQixDQUFDO0lBRUQsTUFBTSxDQUFDLFFBQWlCLEVBQUU7UUFDeEIsT0FBTyxJQUFLLElBQUksQ0FBQyxXQUFtQixDQUFDLEtBQUssQ0FBQyxD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