gemcap-be-common 1.0.0
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/package.json +17 -0
- package/src/db/inventory-availability.ts +9 -0
- package/src/enum/inventory-availability-results.enum.ts +5 -0
- package/src/interfaces/collaterals.interface.ts +32 -0
- package/src/models/AccountPayableItem.model.ts +78 -0
- package/src/models/BBCDate.model.ts +31 -0
- package/src/models/BBCSheet.model.ts +73 -0
- package/src/models/InventoryAvailability.model.ts +167 -0
- package/src/models/InventoryItem.model.ts +137 -0
- package/src/models/ReceiavableItem.model.ts +97 -0
- package/src/plugins/id.plugin.ts +56 -0
- package/tsconfig.json +9 -0
package/package.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "gemcap-be-common",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
+
},
|
|
9
|
+
"author": "",
|
|
10
|
+
"license": "ISC",
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"mongoose": "^6.10.5"
|
|
13
|
+
},
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"typescript": "^5.1.6"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import InventoryAvailability, {
|
|
2
|
+
IInventoryAvailabilityDocument,
|
|
3
|
+
} from '../models/InventoryAvailability.model';
|
|
4
|
+
|
|
5
|
+
export const getInventoryAvailabilityByBBCDateId = async (bbcDateId: string): Promise<IInventoryAvailabilityDocument> => {
|
|
6
|
+
return InventoryAvailability
|
|
7
|
+
.findOne({ bbcDateId })
|
|
8
|
+
.lean();
|
|
9
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import mongoose from 'mongoose';
|
|
2
|
+
|
|
3
|
+
import { IReceivableItem } from '../models/ReceiavableItem.model';
|
|
4
|
+
import { IInventoryItem } from '../models/InventoryItem.model';
|
|
5
|
+
import { IAccountPayableItem } from '../models/AccountPayableItem.model';
|
|
6
|
+
|
|
7
|
+
export interface IUploadedItems<T extends IInventoryItem | IReceivableItem | IAccountPayableItem> {
|
|
8
|
+
_id?: string;
|
|
9
|
+
bbcDate: Date;
|
|
10
|
+
borrowerId: string;
|
|
11
|
+
fileName?: string;
|
|
12
|
+
sheetName?: string;
|
|
13
|
+
uploadUser?: string
|
|
14
|
+
fileHash?: string;
|
|
15
|
+
comment?: string;
|
|
16
|
+
items: T[];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface ICollateralItem {
|
|
20
|
+
bbcSheetId: mongoose.Types.ObjectId;
|
|
21
|
+
order: number;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface IPaginatorOptions {
|
|
25
|
+
pageIndex: number;
|
|
26
|
+
pageSize: number;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const DEFAULT_PAGINATOR: IPaginatorOptions = {
|
|
30
|
+
pageIndex: 0,
|
|
31
|
+
pageSize: 20,
|
|
32
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import mongoose, { Document } from 'mongoose';
|
|
2
|
+
|
|
3
|
+
import { ICollateralItem } from '../interfaces/collaterals.interface';
|
|
4
|
+
|
|
5
|
+
const mongooseLeanId = require('../plugins/id.plugin');
|
|
6
|
+
|
|
7
|
+
export const ACCOUNT_PAYABLE_FIELDS = [
|
|
8
|
+
'_id',
|
|
9
|
+
'apDate',
|
|
10
|
+
'poNumber',
|
|
11
|
+
'customerName',
|
|
12
|
+
'amount',
|
|
13
|
+
'otherInformation1',
|
|
14
|
+
'otherInformation2',
|
|
15
|
+
'otherInformation3',
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
export interface IAccountPayableItem extends ICollateralItem {
|
|
19
|
+
bbcDate: Date;
|
|
20
|
+
apDate: Date;
|
|
21
|
+
poNumber: string;
|
|
22
|
+
customerName: string;
|
|
23
|
+
amount: number;
|
|
24
|
+
otherInformation1: string;
|
|
25
|
+
otherInformation2: string;
|
|
26
|
+
otherInformation3: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface IAccountPayableItemDoc extends Document, IAccountPayableItem {
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const AccountPayableItemSchema = new mongoose.Schema(
|
|
33
|
+
{
|
|
34
|
+
bbcSheetId: {
|
|
35
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
36
|
+
ref: 'BBCSheets',
|
|
37
|
+
required: true,
|
|
38
|
+
},
|
|
39
|
+
order: {
|
|
40
|
+
type: Number,
|
|
41
|
+
required: true,
|
|
42
|
+
},
|
|
43
|
+
apDate: {
|
|
44
|
+
type: Date,
|
|
45
|
+
required: true,
|
|
46
|
+
},
|
|
47
|
+
poNumber: {
|
|
48
|
+
type: String,
|
|
49
|
+
trim: true,
|
|
50
|
+
},
|
|
51
|
+
customerName: {
|
|
52
|
+
type: String,
|
|
53
|
+
trim: true,
|
|
54
|
+
},
|
|
55
|
+
amount: {
|
|
56
|
+
type: Number,
|
|
57
|
+
required: true,
|
|
58
|
+
},
|
|
59
|
+
otherInformation1: {
|
|
60
|
+
type: String,
|
|
61
|
+
trim: true,
|
|
62
|
+
},
|
|
63
|
+
otherInformation2: {
|
|
64
|
+
type: String,
|
|
65
|
+
trim: true,
|
|
66
|
+
},
|
|
67
|
+
otherInformation3: {
|
|
68
|
+
type: String,
|
|
69
|
+
trim: true,
|
|
70
|
+
},
|
|
71
|
+
__v: { type: Number, select: false },
|
|
72
|
+
},
|
|
73
|
+
{ timestamps: true }
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
AccountPayableItemSchema.plugin(mongooseLeanId);
|
|
77
|
+
|
|
78
|
+
export default mongoose.model<IAccountPayableItemDoc>('AccountPayableItem', AccountPayableItemSchema);
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import mongoose, { Document } from 'mongoose';
|
|
2
|
+
|
|
3
|
+
const mongooseLeanId = require('../plugins/id.plugin');
|
|
4
|
+
|
|
5
|
+
export interface IBBCDate {
|
|
6
|
+
borrowerId: mongoose.Types.ObjectId;
|
|
7
|
+
bbcDate: Date;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface IBBCDateDoc extends IBBCDate, Document {
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const BBCDateSchema = new mongoose.Schema(
|
|
14
|
+
{
|
|
15
|
+
borrowerId: {
|
|
16
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
17
|
+
ref: 'borrowers',
|
|
18
|
+
required: true,
|
|
19
|
+
},
|
|
20
|
+
bbcDate: {
|
|
21
|
+
type: Date,
|
|
22
|
+
required: true,
|
|
23
|
+
},
|
|
24
|
+
__v: { type: Number, select: false },
|
|
25
|
+
},
|
|
26
|
+
{ timestamps: true }
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
BBCDateSchema.plugin(mongooseLeanId);
|
|
30
|
+
|
|
31
|
+
export default mongoose.model<IBBCDateDoc>('BBCDate', BBCDateSchema);
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import mongoose, { Document } from 'mongoose';
|
|
2
|
+
|
|
3
|
+
import InventoryItemModel from './InventoryItem.model';
|
|
4
|
+
import ReceivableItemModel from './ReceiavableItem.model';
|
|
5
|
+
import AccountPayableItemModel from './AccountPayableItem.model';
|
|
6
|
+
import { IBBCDate } from './BBCDate.model';
|
|
7
|
+
|
|
8
|
+
const mongooseLeanId = require('../plugins/id.plugin');
|
|
9
|
+
|
|
10
|
+
export interface IBBCSheet {
|
|
11
|
+
bbcDateId: mongoose.Types.ObjectId;
|
|
12
|
+
dataType: string;
|
|
13
|
+
uploadUser: mongoose.Types.ObjectId;
|
|
14
|
+
fileHash: string;
|
|
15
|
+
fileName: string;
|
|
16
|
+
sheetName: string;
|
|
17
|
+
comment: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface IBBCSheetDoc extends IBBCSheet, Document {
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface IBBCSheetWithBBCDate extends IBBCSheetDoc {
|
|
24
|
+
bbcDate: IBBCDate;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const BBCSheetSchema = new mongoose.Schema(
|
|
28
|
+
{
|
|
29
|
+
bbcDateId: {
|
|
30
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
31
|
+
ref: 'bbcDates',
|
|
32
|
+
required: true,
|
|
33
|
+
},
|
|
34
|
+
dataType: {
|
|
35
|
+
type: String,
|
|
36
|
+
required: true,
|
|
37
|
+
trim: true,
|
|
38
|
+
},
|
|
39
|
+
uploadUser: {
|
|
40
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
41
|
+
ref: 'users',
|
|
42
|
+
},
|
|
43
|
+
fileHash: {
|
|
44
|
+
type: String,
|
|
45
|
+
trim: true,
|
|
46
|
+
},
|
|
47
|
+
fileName: {
|
|
48
|
+
type: String,
|
|
49
|
+
trim: true,
|
|
50
|
+
},
|
|
51
|
+
sheetName: {
|
|
52
|
+
type: String,
|
|
53
|
+
trim: true,
|
|
54
|
+
},
|
|
55
|
+
comment: {
|
|
56
|
+
type: String,
|
|
57
|
+
trim: true,
|
|
58
|
+
},
|
|
59
|
+
__v: { type: Number, select: false },
|
|
60
|
+
},
|
|
61
|
+
{ timestamps: true }
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
BBCSheetSchema.plugin(mongooseLeanId);
|
|
65
|
+
|
|
66
|
+
BBCSheetSchema.pre('findOneAndDelete', function (next) {
|
|
67
|
+
const bbcSheetId = this.getQuery()['_id'];
|
|
68
|
+
InventoryItemModel.deleteMany({ bbcSheetId: bbcSheetId }, next);
|
|
69
|
+
ReceivableItemModel.deleteMany({ bbcSheetId: bbcSheetId }, next);
|
|
70
|
+
AccountPayableItemModel.deleteMany({ bbcSheetId: bbcSheetId }, next);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
export default mongoose.model<IBBCSheetDoc>('BBCSheet', BBCSheetSchema);
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import mongoose from 'mongoose';
|
|
2
|
+
|
|
3
|
+
import { IInventoryItemDocWithCalculation } from './InventoryItem.model';
|
|
4
|
+
import { EInventoryAvailabilityResults } from '../enum/inventory-availability-results.enum';
|
|
5
|
+
import { IPaginatorOptions } from '../interfaces/collaterals.interface';
|
|
6
|
+
|
|
7
|
+
const mongooseLeanId = require('../plugins/id.plugin');
|
|
8
|
+
|
|
9
|
+
export interface IInventoryQuery {
|
|
10
|
+
conjunction: string,
|
|
11
|
+
field: string,
|
|
12
|
+
filter: string,
|
|
13
|
+
filterValue: string | number | Date
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface IInventoryFilter {
|
|
17
|
+
active: boolean;
|
|
18
|
+
inventoryName: string;
|
|
19
|
+
advanceRate: number;
|
|
20
|
+
queries: IInventoryQuery[];
|
|
21
|
+
valid: boolean;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface IInventoryAvailabilitySummary {
|
|
25
|
+
order: number;
|
|
26
|
+
isGroup: boolean;
|
|
27
|
+
inventoryName: string;
|
|
28
|
+
totalQty: number;
|
|
29
|
+
totalValue: number;
|
|
30
|
+
advanceRate: number;
|
|
31
|
+
availability: number;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface IInventoryAvailabilityResultsView {
|
|
35
|
+
items: IInventoryItemDocWithCalculation[];
|
|
36
|
+
totalItems: number;
|
|
37
|
+
paginatorOptions?: IPaginatorOptions;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export type InventoryAvailabilityPaginators = {
|
|
41
|
+
[key in EInventoryAvailabilityResults]: IPaginatorOptions
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface IInventoryAvailabilityResults {
|
|
45
|
+
[EInventoryAvailabilityResults.UNIQ_ITEMS]: IInventoryAvailabilityResultsView;
|
|
46
|
+
[EInventoryAvailabilityResults.NON_UNIQ_ITEMS]: IInventoryAvailabilityResultsView;
|
|
47
|
+
[EInventoryAvailabilityResults.NOT_MATCHED_ITEMS]: IInventoryAvailabilityResultsView;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface IInventoryAvailability {
|
|
51
|
+
bbcDateId: mongoose.Types.ObjectId;
|
|
52
|
+
borrowerId: mongoose.Types.ObjectId;
|
|
53
|
+
options: {
|
|
54
|
+
maxAdvanceRatePriority: boolean;
|
|
55
|
+
}
|
|
56
|
+
filters: IInventoryFilter[];
|
|
57
|
+
summary: IInventoryAvailabilitySummary[];
|
|
58
|
+
results?: IInventoryAvailabilityResults;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface IInventoryAvailabilityDocument extends IInventoryAvailability, mongoose.Document {
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const InventoryAvailabilityScheme = new mongoose.Schema(
|
|
65
|
+
{
|
|
66
|
+
borrowerId: {
|
|
67
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
68
|
+
ref: 'borrowers',
|
|
69
|
+
required: true,
|
|
70
|
+
},
|
|
71
|
+
bbcDateId: {
|
|
72
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
73
|
+
ref: 'inventories',
|
|
74
|
+
required: true,
|
|
75
|
+
},
|
|
76
|
+
options: {
|
|
77
|
+
maxAdvanceRatePriority: {
|
|
78
|
+
type: Boolean,
|
|
79
|
+
required: true,
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
filters: [
|
|
83
|
+
{
|
|
84
|
+
active: {
|
|
85
|
+
type: Boolean,
|
|
86
|
+
required: true,
|
|
87
|
+
default: true,
|
|
88
|
+
},
|
|
89
|
+
inventoryName: {
|
|
90
|
+
type: String,
|
|
91
|
+
required: true,
|
|
92
|
+
trim: true,
|
|
93
|
+
},
|
|
94
|
+
advanceRate: {
|
|
95
|
+
type: Number,
|
|
96
|
+
required: true,
|
|
97
|
+
},
|
|
98
|
+
valid: {
|
|
99
|
+
type: Boolean,
|
|
100
|
+
required: true,
|
|
101
|
+
},
|
|
102
|
+
queries: [
|
|
103
|
+
{
|
|
104
|
+
conjunction: {
|
|
105
|
+
type: String,
|
|
106
|
+
required: true,
|
|
107
|
+
trim: true,
|
|
108
|
+
},
|
|
109
|
+
field: {
|
|
110
|
+
type: String,
|
|
111
|
+
required: true,
|
|
112
|
+
trim: true,
|
|
113
|
+
},
|
|
114
|
+
filter: {
|
|
115
|
+
type: String,
|
|
116
|
+
required: true,
|
|
117
|
+
trim: true,
|
|
118
|
+
},
|
|
119
|
+
filterValue: {
|
|
120
|
+
type: mongoose.Schema.Types.Mixed,
|
|
121
|
+
required: true,
|
|
122
|
+
trim: true,
|
|
123
|
+
},
|
|
124
|
+
}
|
|
125
|
+
],
|
|
126
|
+
},
|
|
127
|
+
],
|
|
128
|
+
summary: [
|
|
129
|
+
{
|
|
130
|
+
order: {
|
|
131
|
+
type: Number,
|
|
132
|
+
required: true,
|
|
133
|
+
},
|
|
134
|
+
isGroup: {
|
|
135
|
+
type: Boolean,
|
|
136
|
+
required: true,
|
|
137
|
+
},
|
|
138
|
+
inventoryName: {
|
|
139
|
+
type: String,
|
|
140
|
+
required: true,
|
|
141
|
+
},
|
|
142
|
+
totalQty: {
|
|
143
|
+
type: Number,
|
|
144
|
+
required: true,
|
|
145
|
+
},
|
|
146
|
+
totalValue: {
|
|
147
|
+
type: Number,
|
|
148
|
+
required: true,
|
|
149
|
+
},
|
|
150
|
+
advanceRate: {
|
|
151
|
+
type: Number,
|
|
152
|
+
required: true,
|
|
153
|
+
},
|
|
154
|
+
availability: {
|
|
155
|
+
type: Number,
|
|
156
|
+
required: true,
|
|
157
|
+
},
|
|
158
|
+
}
|
|
159
|
+
],
|
|
160
|
+
__v: { type: Number, select: false },
|
|
161
|
+
},
|
|
162
|
+
{ timestamps: true }
|
|
163
|
+
);
|
|
164
|
+
|
|
165
|
+
InventoryAvailabilityScheme.plugin(mongooseLeanId);
|
|
166
|
+
|
|
167
|
+
export default mongoose.model<IInventoryAvailabilityDocument>('inventoryAvailability', InventoryAvailabilityScheme);
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import mongoose, { Document } from 'mongoose';
|
|
2
|
+
|
|
3
|
+
import { ICollateralItem } from '../interfaces/collaterals.interface';
|
|
4
|
+
import { IBBCSheetDoc } from './BBCSheet.model';
|
|
5
|
+
import { IBBCDateDoc } from './BBCDate.model';
|
|
6
|
+
|
|
7
|
+
const mongooseLeanId = require('../plugins/id.plugin');
|
|
8
|
+
|
|
9
|
+
export const INVENTORY_FIELDS = [
|
|
10
|
+
'_id',
|
|
11
|
+
'skuDate',
|
|
12
|
+
'category',
|
|
13
|
+
'sku',
|
|
14
|
+
'qty',
|
|
15
|
+
'value',
|
|
16
|
+
'expiryDate',
|
|
17
|
+
'location',
|
|
18
|
+
'unitCost',
|
|
19
|
+
'skuDescription1',
|
|
20
|
+
'skuDescription2',
|
|
21
|
+
'skuDescription3',
|
|
22
|
+
'detail1',
|
|
23
|
+
'detail2',
|
|
24
|
+
'detail3',
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
export interface IInventoryItem extends ICollateralItem {
|
|
28
|
+
skuDate: Date;
|
|
29
|
+
category: string;
|
|
30
|
+
sku: string;
|
|
31
|
+
qty: number;
|
|
32
|
+
value: number;
|
|
33
|
+
expiryDate: Date;
|
|
34
|
+
location: string;
|
|
35
|
+
unitCost: number;
|
|
36
|
+
skuDescription1: string;
|
|
37
|
+
skuDescription2: string;
|
|
38
|
+
skuDescription3: string;
|
|
39
|
+
detail1: string;
|
|
40
|
+
detail2: string;
|
|
41
|
+
detail3: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface IInventoryItemDoc extends Document, IInventoryItem {
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface IInventoryItemDocWithCalculation extends IInventoryItemDoc {
|
|
48
|
+
bbcSheet: IBBCSheetDoc;
|
|
49
|
+
bbc: IBBCDateDoc;
|
|
50
|
+
expireDays: number;
|
|
51
|
+
skuDays: number;
|
|
52
|
+
sheetName: string;
|
|
53
|
+
inventoryName: string;
|
|
54
|
+
advanceRate: number;
|
|
55
|
+
availability: number;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const InventoryItemSchema = new mongoose.Schema(
|
|
59
|
+
{
|
|
60
|
+
bbcSheetId: {
|
|
61
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
62
|
+
ref: 'BBCSheets',
|
|
63
|
+
required: true,
|
|
64
|
+
},
|
|
65
|
+
order: {
|
|
66
|
+
type: Number,
|
|
67
|
+
required: true,
|
|
68
|
+
},
|
|
69
|
+
skuDate: {
|
|
70
|
+
type: Date,
|
|
71
|
+
required: true,
|
|
72
|
+
},
|
|
73
|
+
category: {
|
|
74
|
+
type: String,
|
|
75
|
+
trim: true,
|
|
76
|
+
default: 'NO CATEGORY',
|
|
77
|
+
},
|
|
78
|
+
sku: {
|
|
79
|
+
type: String,
|
|
80
|
+
trim: true,
|
|
81
|
+
required: true,
|
|
82
|
+
},
|
|
83
|
+
lotNumber: {
|
|
84
|
+
type: String,
|
|
85
|
+
trim: true,
|
|
86
|
+
required: false,
|
|
87
|
+
},
|
|
88
|
+
qty: {
|
|
89
|
+
type: Number,
|
|
90
|
+
required: true,
|
|
91
|
+
},
|
|
92
|
+
value: {
|
|
93
|
+
type: Number,
|
|
94
|
+
required: true,
|
|
95
|
+
},
|
|
96
|
+
expiryDate: {
|
|
97
|
+
type: Date,
|
|
98
|
+
},
|
|
99
|
+
location: {
|
|
100
|
+
type: String,
|
|
101
|
+
trim: true,
|
|
102
|
+
},
|
|
103
|
+
unitCost: {
|
|
104
|
+
type: Number,
|
|
105
|
+
},
|
|
106
|
+
skuDescription1: {
|
|
107
|
+
type: String,
|
|
108
|
+
trim: true,
|
|
109
|
+
},
|
|
110
|
+
skuDescription2: {
|
|
111
|
+
type: String,
|
|
112
|
+
trim: true,
|
|
113
|
+
},
|
|
114
|
+
skuDescription3: {
|
|
115
|
+
type: String,
|
|
116
|
+
trim: true,
|
|
117
|
+
},
|
|
118
|
+
detail1: {
|
|
119
|
+
type: String,
|
|
120
|
+
trim: true,
|
|
121
|
+
},
|
|
122
|
+
detail2: {
|
|
123
|
+
type: String,
|
|
124
|
+
trim: true,
|
|
125
|
+
},
|
|
126
|
+
detail3: {
|
|
127
|
+
type: String,
|
|
128
|
+
trim: true,
|
|
129
|
+
},
|
|
130
|
+
__v: { type: Number, select: false },
|
|
131
|
+
},
|
|
132
|
+
{ timestamps: true }
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
InventoryItemSchema.plugin(mongooseLeanId);
|
|
136
|
+
|
|
137
|
+
export default mongoose.model<IInventoryItemDoc>('InventoryItem', InventoryItemSchema);
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import mongoose, { Document } from 'mongoose';
|
|
2
|
+
|
|
3
|
+
import { ICollateralItem } from '../interfaces/collaterals.interface';
|
|
4
|
+
import { IBBCDateDoc } from './BBCDate.model';
|
|
5
|
+
import { IBBCSheetDoc } from './BBCSheet.model';
|
|
6
|
+
|
|
7
|
+
const mongooseLeanId = require('../plugins/id.plugin');
|
|
8
|
+
|
|
9
|
+
export const RECEIVABLE_FIELDS = [
|
|
10
|
+
'_id',
|
|
11
|
+
'invoiceDate',
|
|
12
|
+
'invoiceNumber',
|
|
13
|
+
'customerTitle',
|
|
14
|
+
'dueDate',
|
|
15
|
+
'invoiceAmount',
|
|
16
|
+
'originalAmount',
|
|
17
|
+
'invoiceDetail1',
|
|
18
|
+
'invoiceDetail2',
|
|
19
|
+
'invoiceDetail3',
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
export interface IReceivableItem extends ICollateralItem {
|
|
23
|
+
invoiceDate: Date;
|
|
24
|
+
invoiceNumber: string;
|
|
25
|
+
customerTitle: string;
|
|
26
|
+
dueDate: number;
|
|
27
|
+
invoiceAmount: number;
|
|
28
|
+
originalAmount: number;
|
|
29
|
+
invoiceDetail1: string;
|
|
30
|
+
invoiceDetail2: string;
|
|
31
|
+
invoiceDetail3: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface IReceivableItemDoc extends IReceivableItem, Document {
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface IReceivableItemDocPopulated extends IReceivableItemDoc {
|
|
38
|
+
bbc: IBBCDateDoc;
|
|
39
|
+
bbcSheet: IBBCSheetDoc;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const ReceivableItemSchema = new mongoose.Schema(
|
|
43
|
+
{
|
|
44
|
+
bbcSheetId: {
|
|
45
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
46
|
+
ref: 'BBCSheets',
|
|
47
|
+
required: true,
|
|
48
|
+
},
|
|
49
|
+
order: {
|
|
50
|
+
type: Number,
|
|
51
|
+
required: true,
|
|
52
|
+
},
|
|
53
|
+
invoiceNumber: {
|
|
54
|
+
type: String,
|
|
55
|
+
trim: true,
|
|
56
|
+
required: true,
|
|
57
|
+
},
|
|
58
|
+
invoiceDate: {
|
|
59
|
+
type: Date,
|
|
60
|
+
required: true,
|
|
61
|
+
},
|
|
62
|
+
customerTitle: {
|
|
63
|
+
type: String,
|
|
64
|
+
trim: true,
|
|
65
|
+
default: 'No Title',
|
|
66
|
+
},
|
|
67
|
+
invoiceAmount: {
|
|
68
|
+
type: Number,
|
|
69
|
+
required: true,
|
|
70
|
+
},
|
|
71
|
+
originalAmount: {
|
|
72
|
+
type: Number,
|
|
73
|
+
required: false,
|
|
74
|
+
},
|
|
75
|
+
dueDate: {
|
|
76
|
+
type: Date,
|
|
77
|
+
},
|
|
78
|
+
invoiceDetail1: {
|
|
79
|
+
type: String,
|
|
80
|
+
trim: true,
|
|
81
|
+
},
|
|
82
|
+
invoiceDetail2: {
|
|
83
|
+
type: String,
|
|
84
|
+
trim: true,
|
|
85
|
+
},
|
|
86
|
+
invoiceDetail3: {
|
|
87
|
+
type: String,
|
|
88
|
+
trim: true,
|
|
89
|
+
},
|
|
90
|
+
__v: { type: Number, select: false },
|
|
91
|
+
},
|
|
92
|
+
{ timestamps: true }
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
ReceivableItemSchema.plugin(mongooseLeanId);
|
|
96
|
+
|
|
97
|
+
export default mongoose.model<IReceivableItemDoc>('ReceivableItem', ReceivableItemSchema);
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
module.exports = function mongooseLeanId(schema) {
|
|
2
|
+
schema.post('find', attachId);
|
|
3
|
+
schema.post('findOne', attachId);
|
|
4
|
+
schema.post('findOneAndUpdate', attachId);
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
function attachId(res) {
|
|
8
|
+
if (res === null) {
|
|
9
|
+
return
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function replaceId(res) {
|
|
13
|
+
if (Array.isArray(res)) {
|
|
14
|
+
res.forEach(v => {
|
|
15
|
+
if (isObjectId(v)) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
if (v._id) {
|
|
19
|
+
v.id = v._id.toString();
|
|
20
|
+
}
|
|
21
|
+
Object.keys(v).map(k => {
|
|
22
|
+
if (Array.isArray(v[k])) {
|
|
23
|
+
replaceId(v[k]);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
} else {
|
|
28
|
+
if (isObjectId(res)) {
|
|
29
|
+
return res;
|
|
30
|
+
}
|
|
31
|
+
if (res._id) {
|
|
32
|
+
res.id = res._id.toString();
|
|
33
|
+
}
|
|
34
|
+
Object.keys(res).map(k => {
|
|
35
|
+
if (Array.isArray(res[k])) {
|
|
36
|
+
replaceId(res[k]);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (this._mongooseOptions.lean) {
|
|
43
|
+
replaceId(res);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function isObjectId(v) {
|
|
48
|
+
if (v == null) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
const proto = Object.getPrototypeOf(v);
|
|
52
|
+
if (proto == null || proto.constructor == null || proto.constructor.name !== 'ObjectID') {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
return v._bsontype === 'ObjectID';
|
|
56
|
+
}
|