@driveup/schema 0.1.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/README.md +174 -0
- package/lib/catalog/addon/addon.entity.d.ts +109 -0
- package/lib/catalog/addon/addon.entity.js +260 -0
- package/lib/catalog/addon/addon.entity.js.map +1 -0
- package/lib/catalog/addon/country.entity.d.ts +112 -0
- package/lib/catalog/addon/country.entity.js +246 -0
- package/lib/catalog/addon/country.entity.js.map +1 -0
- package/lib/catalog/driving/category.entity.d.ts +122 -0
- package/lib/catalog/driving/category.entity.js +217 -0
- package/lib/catalog/driving/category.entity.js.map +1 -0
- package/lib/catalog/driving/vehicle.entity.d.ts +49 -0
- package/lib/catalog/driving/vehicle.entity.js +97 -0
- package/lib/catalog/driving/vehicle.entity.js.map +1 -0
- package/lib/catalog/priceplan/priceplan.entity.d.ts +123 -0
- package/lib/catalog/priceplan/priceplan.entity.js +288 -0
- package/lib/catalog/priceplan/priceplan.entity.js.map +1 -0
- package/lib/catalog/product/country.entity.d.ts +109 -0
- package/lib/catalog/product/country.entity.js +233 -0
- package/lib/catalog/product/country.entity.js.map +1 -0
- package/lib/catalog/product/priceplan.entity.d.ts +113 -0
- package/lib/catalog/product/priceplan.entity.js +251 -0
- package/lib/catalog/product/priceplan.entity.js.map +1 -0
- package/lib/catalog/product/product.entity.d.ts +104 -0
- package/lib/catalog/product/product.entity.js +262 -0
- package/lib/catalog/product/product.entity.js.map +1 -0
- package/lib/catalog/program/program.entity.d.ts +107 -0
- package/lib/catalog/program/program.entity.js +247 -0
- package/lib/catalog/program/program.entity.js.map +1 -0
- package/lib/catalog/seed/assets/asset.entity.d.ts +68 -0
- package/lib/catalog/seed/assets/asset.entity.js +163 -0
- package/lib/catalog/seed/assets/asset.entity.js.map +1 -0
- package/lib/catalog/seed/courses/course.entity.d.ts +98 -0
- package/lib/catalog/seed/courses/course.entity.js +216 -0
- package/lib/catalog/seed/courses/course.entity.js.map +1 -0
- package/lib/catalog/seed/courses/lesson.entity.d.ts +90 -0
- package/lib/catalog/seed/courses/lesson.entity.js +214 -0
- package/lib/catalog/seed/courses/lesson.entity.js.map +1 -0
- package/lib/catalog/seed/courses/topic.entity.d.ts +77 -0
- package/lib/catalog/seed/courses/topic.entity.js +185 -0
- package/lib/catalog/seed/courses/topic.entity.js.map +1 -0
- package/lib/catalog/seed/expense/category.entity.d.ts +61 -0
- package/lib/catalog/seed/expense/category.entity.js +153 -0
- package/lib/catalog/seed/expense/category.entity.js.map +1 -0
- package/lib/index.d.ts +67 -0
- package/lib/index.js +89 -0
- package/lib/index.js.map +1 -0
- package/lib/profile/agent/agent.entity.d.ts +95 -0
- package/lib/profile/agent/agent.entity.js +223 -0
- package/lib/profile/agent/agent.entity.js.map +1 -0
- package/lib/profile/agent/payout.entity.d.ts +70 -0
- package/lib/profile/agent/payout.entity.js +160 -0
- package/lib/profile/agent/payout.entity.js.map +1 -0
- package/lib/profile/agent/promotion.entity.d.ts +82 -0
- package/lib/profile/agent/promotion.entity.js +174 -0
- package/lib/profile/agent/promotion.entity.js.map +1 -0
- package/lib/profile/company/company.entity.d.ts +234 -0
- package/lib/profile/company/company.entity.js +558 -0
- package/lib/profile/company/company.entity.js.map +1 -0
- package/lib/profile/company/course/appointment.entity.d.ts +111 -0
- package/lib/profile/company/course/appointment.entity.js +240 -0
- package/lib/profile/company/course/appointment.entity.js.map +1 -0
- package/lib/profile/company/course/course.entity.d.ts +156 -0
- package/lib/profile/company/course/course.entity.js +365 -0
- package/lib/profile/company/course/course.entity.js.map +1 -0
- package/lib/profile/company/course/lesson.entity.d.ts +123 -0
- package/lib/profile/company/course/lesson.entity.js +288 -0
- package/lib/profile/company/course/lesson.entity.js.map +1 -0
- package/lib/profile/company/course/topic.entity.d.ts +55 -0
- package/lib/profile/company/course/topic.entity.js +147 -0
- package/lib/profile/company/course/topic.entity.js.map +1 -0
- package/lib/profile/company/finances/billing/bill.entity.d.ts +145 -0
- package/lib/profile/company/finances/billing/bill.entity.js +338 -0
- package/lib/profile/company/finances/billing/bill.entity.js.map +1 -0
- package/lib/profile/company/finances/billing/item.entity.d.ts +75 -0
- package/lib/profile/company/finances/billing/item.entity.js +219 -0
- package/lib/profile/company/finances/billing/item.entity.js.map +1 -0
- package/lib/profile/company/finances/billing/transaction.entity.d.ts +44 -0
- package/lib/profile/company/finances/billing/transaction.entity.js +158 -0
- package/lib/profile/company/finances/billing/transaction.entity.js.map +1 -0
- package/lib/profile/company/finances/expense/category.entity.d.ts +55 -0
- package/lib/profile/company/finances/expense/category.entity.js +117 -0
- package/lib/profile/company/finances/expense/category.entity.js.map +1 -0
- package/lib/profile/company/finances/expense/expense.entity.d.ts +48 -0
- package/lib/profile/company/finances/expense/expense.entity.js +171 -0
- package/lib/profile/company/finances/expense/expense.entity.js.map +1 -0
- package/lib/profile/company/finances/handover/handover.entity.d.ts +44 -0
- package/lib/profile/company/finances/handover/handover.entity.js +202 -0
- package/lib/profile/company/finances/handover/handover.entity.js.map +1 -0
- package/lib/profile/company/finances/invoice/invoice.entity.d.ts +65 -0
- package/lib/profile/company/finances/invoice/invoice.entity.js +296 -0
- package/lib/profile/company/finances/invoice/invoice.entity.js.map +1 -0
- package/lib/profile/company/finances/invoice/item.entity.d.ts +25 -0
- package/lib/profile/company/finances/invoice/item.entity.js +148 -0
- package/lib/profile/company/finances/invoice/item.entity.js.map +1 -0
- package/lib/profile/company/finances/payment/method.entity.d.ts +35 -0
- package/lib/profile/company/finances/payment/method.entity.js +143 -0
- package/lib/profile/company/finances/payment/method.entity.js.map +1 -0
- package/lib/profile/company/finances/peyment/method.entity.d.ts +35 -0
- package/lib/profile/company/finances/peyment/method.entity.js +143 -0
- package/lib/profile/company/finances/peyment/method.entity.js.map +1 -0
- package/lib/profile/company/finances/peyment-method/payment-method.d.ts +34 -0
- package/lib/profile/company/finances/peyment-method/payment-method.js +118 -0
- package/lib/profile/company/finances/peyment-method/payment-method.js.map +1 -0
- package/lib/profile/company/instructor/instructor.entity.d.ts +85 -0
- package/lib/profile/company/instructor/instructor.entity.js +254 -0
- package/lib/profile/company/instructor/instructor.entity.js.map +1 -0
- package/lib/profile/company/instructor/task.entity.d.ts +60 -0
- package/lib/profile/company/instructor/task.entity.js +133 -0
- package/lib/profile/company/instructor/task.entity.js.map +1 -0
- package/lib/profile/company/medical/examination.entity.d.ts +59 -0
- package/lib/profile/company/medical/examination.entity.js +175 -0
- package/lib/profile/company/medical/examination.entity.js.map +1 -0
- package/lib/profile/company/medical/product.entity.d.ts +99 -0
- package/lib/profile/company/medical/product.entity.js +270 -0
- package/lib/profile/company/medical/product.entity.js.map +1 -0
- package/lib/profile/company/metrics/company.metric.d.ts +21 -0
- package/lib/profile/company/metrics/company.metric.js +122 -0
- package/lib/profile/company/metrics/company.metric.js.map +1 -0
- package/lib/profile/company/product/addon.entity.d.ts +93 -0
- package/lib/profile/company/product/addon.entity.js +234 -0
- package/lib/profile/company/product/addon.entity.js.map +1 -0
- package/lib/profile/company/product/priceplan.entity.d.ts +57 -0
- package/lib/profile/company/product/priceplan.entity.js +167 -0
- package/lib/profile/company/product/priceplan.entity.js.map +1 -0
- package/lib/profile/company/product/product.entity.d.ts +171 -0
- package/lib/profile/company/product/product.entity.js +383 -0
- package/lib/profile/company/product/product.entity.js.map +1 -0
- package/lib/profile/company/product/vehicle.entity.d.ts +46 -0
- package/lib/profile/company/product/vehicle.entity.js +144 -0
- package/lib/profile/company/product/vehicle.entity.js.map +1 -0
- package/lib/profile/instructor/instructor.entity.d.ts +80 -0
- package/lib/profile/instructor/instructor.entity.js +186 -0
- package/lib/profile/instructor/instructor.entity.js.map +1 -0
- package/lib/profile/student/program/licence/licence.entity.d.ts +66 -0
- package/lib/profile/student/program/licence/licence.entity.js +187 -0
- package/lib/profile/student/program/licence/licence.entity.js.map +1 -0
- package/lib/profile/student/program/medical/certificate.entity.d.ts +84 -0
- package/lib/profile/student/program/medical/certificate.entity.js +244 -0
- package/lib/profile/student/program/medical/certificate.entity.js.map +1 -0
- package/lib/profile/student/program/medical/examination.model.d.ts +65 -0
- package/lib/profile/student/program/medical/examination.model.js +209 -0
- package/lib/profile/student/program/medical/examination.model.js.map +1 -0
- package/lib/profile/student/program/program.entity.d.ts +78 -0
- package/lib/profile/student/program/program.entity.js +225 -0
- package/lib/profile/student/program/program.entity.js.map +1 -0
- package/lib/profile/student/program/training/appointment.entity.d.ts +151 -0
- package/lib/profile/student/program/training/appointment.entity.js +441 -0
- package/lib/profile/student/program/training/appointment.entity.js.map +1 -0
- package/lib/profile/student/program/training/exam.entity.d.ts +41 -0
- package/lib/profile/student/program/training/exam.entity.js +141 -0
- package/lib/profile/student/program/training/exam.entity.js.map +1 -0
- package/lib/profile/student/program/training/lesson.entity.d.ts +84 -0
- package/lib/profile/student/program/training/lesson.entity.js +221 -0
- package/lib/profile/student/program/training/lesson.entity.js.map +1 -0
- package/lib/profile/student/program/training/request.entity.d.ts +56 -0
- package/lib/profile/student/program/training/request.entity.js +159 -0
- package/lib/profile/student/program/training/request.entity.js.map +1 -0
- package/lib/profile/student/program/training/topic.entity.d.ts +109 -0
- package/lib/profile/student/program/training/topic.entity.js +255 -0
- package/lib/profile/student/program/training/topic.entity.js.map +1 -0
- package/lib/profile/student/program/training/training.entity.d.ts +167 -0
- package/lib/profile/student/program/training/training.entity.js +501 -0
- package/lib/profile/student/program/training/training.entity.js.map +1 -0
- package/lib/profile/student/program/training/transaction.entity.d.ts +111 -0
- package/lib/profile/student/program/training/transaction.entity.js +266 -0
- package/lib/profile/student/program/training/transaction.entity.js.map +1 -0
- package/lib/profile/student/student.entity.d.ts +89 -0
- package/lib/profile/student/student.entity.js +183 -0
- package/lib/profile/student/student.entity.js.map +1 -0
- package/lib/system/campaign/campaign.entity.d.ts +68 -0
- package/lib/system/campaign/campaign.entity.js +150 -0
- package/lib/system/campaign/campaign.entity.js.map +1 -0
- package/lib/system/campaign/gifcode.entity.d.ts +14 -0
- package/lib/system/campaign/gifcode.entity.js +77 -0
- package/lib/system/campaign/gifcode.entity.js.map +1 -0
- package/lib/system/campaigne/campaign.entity.d.ts +69 -0
- package/lib/system/campaigne/campaign.entity.js +179 -0
- package/lib/system/campaigne/campaign.entity.js.map +1 -0
- package/lib/system/campaigne/gifcode.entity.d.ts +54 -0
- package/lib/system/campaigne/gifcode.entity.js +126 -0
- package/lib/system/campaigne/gifcode.entity.js.map +1 -0
- package/lib/system/country/country.entity.d.ts +121 -0
- package/lib/system/country/country.entity.js +284 -0
- package/lib/system/country/country.entity.js.map +1 -0
- package/lib/system/country/country.metric.d.ts +12 -0
- package/lib/system/country/country.metric.js +68 -0
- package/lib/system/country/country.metric.js.map +1 -0
- package/lib/system/currency/currency.entity.d.ts +46 -0
- package/lib/system/currency/currency.entity.js +112 -0
- package/lib/system/currency/currency.entity.js.map +1 -0
- package/lib/system/driving/category.entity.d.ts +146 -0
- package/lib/system/driving/category.entity.js +321 -0
- package/lib/system/driving/category.entity.js.map +1 -0
- package/lib/system/driving/vehicle.entity.d.ts +54 -0
- package/lib/system/driving/vehicle.entity.js +130 -0
- package/lib/system/driving/vehicle.entity.js.map +1 -0
- package/lib/system/event/business.entity.d.ts +75 -0
- package/lib/system/event/business.entity.js +170 -0
- package/lib/system/event/business.entity.js.map +1 -0
- package/lib/system/event/log.entity.d.ts +103 -0
- package/lib/system/event/log.entity.js +202 -0
- package/lib/system/event/log.entity.js.map +1 -0
- package/lib/system/policy/policy.entity.d.ts +90 -0
- package/lib/system/policy/policy.entity.js +226 -0
- package/lib/system/policy/policy.entity.js.map +1 -0
- package/lib/system/staff/staff.entity.d.ts +72 -0
- package/lib/system/staff/staff.entity.js +186 -0
- package/lib/system/staff/staff.entity.js.map +1 -0
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/lib/user/alert.entity.d.ts +95 -0
- package/lib/user/alert.entity.js +223 -0
- package/lib/user/alert.entity.js.map +1 -0
- package/lib/user/blocked.entity.d.ts +42 -0
- package/lib/user/blocked.entity.js +83 -0
- package/lib/user/blocked.entity.js.map +1 -0
- package/lib/user/device.entity.d.ts +72 -0
- package/lib/user/device.entity.js +182 -0
- package/lib/user/device.entity.js.map +1 -0
- package/lib/user/notification.entity.d.ts +87 -0
- package/lib/user/notification.entity.js +219 -0
- package/lib/user/notification.entity.js.map +1 -0
- package/lib/user/ticket.entity.d.ts +85 -0
- package/lib/user/ticket.entity.js +231 -0
- package/lib/user/ticket.entity.js.map +1 -0
- package/lib/user/user.entity.d.ts +235 -0
- package/lib/user/user.entity.js +573 -0
- package/lib/user/user.entity.js.map +1 -0
- package/lib/user/verification.entity.d.ts +75 -0
- package/lib/user/verification.entity.js +142 -0
- package/lib/user/verification.entity.js.map +1 -0
- package/lib/utils/activity.helper.d.ts +26 -0
- package/lib/utils/activity.helper.js +39 -0
- package/lib/utils/activity.helper.js.map +1 -0
- package/lib/utils/index.d.ts +4 -0
- package/lib/utils/index.js +21 -0
- package/lib/utils/index.js.map +1 -0
- package/lib/utils/json-metrics.transform.d.ts +35 -0
- package/lib/utils/json-metrics.transform.js +83 -0
- package/lib/utils/json-metrics.transform.js.map +1 -0
- package/lib/utils/numeric.transform.d.ts +38 -0
- package/lib/utils/numeric.transform.js +74 -0
- package/lib/utils/numeric.transform.js.map +1 -0
- package/lib/utils/trackable.entity.d.ts +82 -0
- package/lib/utils/trackable.entity.js +100 -0
- package/lib/utils/trackable.entity.js.map +1 -0
- package/package.json +49 -0
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.CompanyBillEntity = void 0;
|
|
13
|
+
const typeorm_1 = require("typeorm");
|
|
14
|
+
const common_1 = require("@driveup/common");
|
|
15
|
+
const company_entity_1 = require("../../company.entity");
|
|
16
|
+
const transaction_entity_1 = require("./transaction.entity");
|
|
17
|
+
const item_entity_1 = require("./item.entity");
|
|
18
|
+
const utils_1 = require("../../../../utils");
|
|
19
|
+
/**
|
|
20
|
+
* Entity representing a company's billing statement for a specific period.
|
|
21
|
+
*
|
|
22
|
+
* @extends TrackableEntity<Bill>
|
|
23
|
+
*/
|
|
24
|
+
let CompanyBillEntity = class CompanyBillEntity extends utils_1.TrackableEntity {
|
|
25
|
+
/**
|
|
26
|
+
* The ID of the company this bill belongs to
|
|
27
|
+
*/
|
|
28
|
+
companyId;
|
|
29
|
+
/**
|
|
30
|
+
* Current status of the bill
|
|
31
|
+
* @type {BillStatus}
|
|
32
|
+
* @default BillStatus.Open
|
|
33
|
+
*/
|
|
34
|
+
status;
|
|
35
|
+
/**
|
|
36
|
+
* Billing period start date
|
|
37
|
+
*/
|
|
38
|
+
startDate;
|
|
39
|
+
/**
|
|
40
|
+
* Billing period end date
|
|
41
|
+
*/
|
|
42
|
+
endDate;
|
|
43
|
+
/**
|
|
44
|
+
* - Total price of all items before promotion code discount, and taxes (excluded the free benefits)
|
|
45
|
+
*
|
|
46
|
+
* - If billItem.freeBenefit = true, then that item's price is not included in this subTotalPrice
|
|
47
|
+
*/
|
|
48
|
+
subtotalPrice;
|
|
49
|
+
// TODO:
|
|
50
|
+
// what if the company submits a gift code
|
|
51
|
+
// he can submit a gift code inside the bill's period, or in the next month (in case the first payment attempt failed)
|
|
52
|
+
// either way, the amount that he should pay is reduced by the gift code amount
|
|
53
|
+
/**
|
|
54
|
+
* - Total price of all items after all discounts (from agent promotion code) and taxes
|
|
55
|
+
*
|
|
56
|
+
* - Steps:
|
|
57
|
+
* As default the totalPrice is equal to subTotalPrice, then we apply the following changes:
|
|
58
|
+
*
|
|
59
|
+
* - 1. get available amount from the credit, and store this in creditAmount.
|
|
60
|
+
* this.creditAmount = company.credit >= this.subTotalPrice ? this.subTotalPrice : company.credit
|
|
61
|
+
* // TODO: reduce company.credit by this.creditAmount
|
|
62
|
+
*
|
|
63
|
+
* - 2. reduce the totalPrice by creditAmount.
|
|
64
|
+
* this.totalPrice = this.subTotalPrice - this.creditAmount
|
|
65
|
+
*
|
|
66
|
+
* - 4. calculate agent payout amount.
|
|
67
|
+
* this.agentAmount = (this.totalPrice * agentCode.agentPercentage) / 100
|
|
68
|
+
*
|
|
69
|
+
* - 6. calculate taxAmount.
|
|
70
|
+
* this.taxAmount = (this.totalPrice * product.vat) / 100
|
|
71
|
+
*
|
|
72
|
+
* - 7. increase totalPrice by taxAmount.
|
|
73
|
+
* this.totalPrice = this.totalPrice + this.taxAmount
|
|
74
|
+
*
|
|
75
|
+
* - 8. if the amount is more than 0, go to stripe and submit the payment
|
|
76
|
+
*/
|
|
77
|
+
totalPrice;
|
|
78
|
+
/**
|
|
79
|
+
* The total tax amount for this bill
|
|
80
|
+
*/
|
|
81
|
+
taxAmount;
|
|
82
|
+
/**
|
|
83
|
+
* The amount that was taken from company's credit balance for this bill
|
|
84
|
+
*/
|
|
85
|
+
creditAmount;
|
|
86
|
+
/**
|
|
87
|
+
* The product balance after this bill is calculated before sending the payment to the provider
|
|
88
|
+
* @type {number}
|
|
89
|
+
* @default 0
|
|
90
|
+
*/
|
|
91
|
+
productBalance;
|
|
92
|
+
/**
|
|
93
|
+
* Total number of trainings that were covered by free benefits
|
|
94
|
+
* @type {number | null}
|
|
95
|
+
* @default null
|
|
96
|
+
*/
|
|
97
|
+
freeBenefitItems;
|
|
98
|
+
/**
|
|
99
|
+
* Total amount of the trainings that was covered by free benefits
|
|
100
|
+
* @type {number | null}
|
|
101
|
+
* @default null
|
|
102
|
+
*/
|
|
103
|
+
freeBenefitAmount;
|
|
104
|
+
/**
|
|
105
|
+
* Total amount that was reducted from credit or was covered by free benefits
|
|
106
|
+
* @type {number | null}
|
|
107
|
+
* @default null
|
|
108
|
+
*/
|
|
109
|
+
fromCreditOrFreeBenefits;
|
|
110
|
+
/**
|
|
111
|
+
* The amount that goes to the agent for this bill
|
|
112
|
+
*
|
|
113
|
+
* - This number is updated after bill's payment is confirmed (25% of totalPrice goes to agent)
|
|
114
|
+
* @type {number}
|
|
115
|
+
* @default 0
|
|
116
|
+
*/
|
|
117
|
+
agentProfit;
|
|
118
|
+
/**
|
|
119
|
+
* The company this bill belongs to
|
|
120
|
+
*/
|
|
121
|
+
company;
|
|
122
|
+
/**
|
|
123
|
+
* Line items included in this bill
|
|
124
|
+
*/
|
|
125
|
+
items;
|
|
126
|
+
/**
|
|
127
|
+
* Payment transactions associated with this bill
|
|
128
|
+
*/
|
|
129
|
+
transactions;
|
|
130
|
+
/**
|
|
131
|
+
* Creates a new CompanyBillEntity instance
|
|
132
|
+
* @param {Partial<CompanyBillEntity>} [props] - Optional initial properties
|
|
133
|
+
*/
|
|
134
|
+
constructor(props) {
|
|
135
|
+
super();
|
|
136
|
+
Object.assign(this, props);
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Converts the entity to a Bill model
|
|
140
|
+
* @returns {Bill} The Bill model representation
|
|
141
|
+
*/
|
|
142
|
+
toModel() {
|
|
143
|
+
return new common_1.Bill({
|
|
144
|
+
id: this.id,
|
|
145
|
+
status: this.status,
|
|
146
|
+
startDate: this.startDate,
|
|
147
|
+
endDate: this.endDate,
|
|
148
|
+
subtotalPrice: this.subtotalPrice,
|
|
149
|
+
totalPrice: this.totalPrice,
|
|
150
|
+
taxAmount: this.taxAmount,
|
|
151
|
+
creditAmount: this.creditAmount,
|
|
152
|
+
productBalance: this.productBalance,
|
|
153
|
+
agentProfit: this.agentProfit,
|
|
154
|
+
freeBenefitItems: this.freeBenefitItems,
|
|
155
|
+
freeBenefitAmount: this.freeBenefitAmount,
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Converts the entity to a Bill model
|
|
160
|
+
* @returns {Bill} The Bill model representation
|
|
161
|
+
*/
|
|
162
|
+
toSummary() {
|
|
163
|
+
return new common_1.Bill({
|
|
164
|
+
id: this.id,
|
|
165
|
+
status: this.status,
|
|
166
|
+
startDate: this.startDate,
|
|
167
|
+
endDate: this.endDate,
|
|
168
|
+
totalPrice: this.totalPrice,
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Calculates the subtotal price by summing all non-free-benefit items
|
|
173
|
+
* @returns {Promise<number>} The subtotal price
|
|
174
|
+
*/
|
|
175
|
+
async getSubtotalPrice() {
|
|
176
|
+
const items = await item_entity_1.CompanyBillItemEntity.findBy({
|
|
177
|
+
billId: this.id,
|
|
178
|
+
freeBenefit: false
|
|
179
|
+
});
|
|
180
|
+
if (!items?.length) {
|
|
181
|
+
return 0;
|
|
182
|
+
}
|
|
183
|
+
const sum = items.map(item => Number(item.price));
|
|
184
|
+
return common_1.ArrayHelper.getSum(sum);
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Calculates the total tax amount for all non-free-benefit items
|
|
188
|
+
* Tax is calculated on the price after credit is applied
|
|
189
|
+
* @returns {Promise<number>} The total tax amount
|
|
190
|
+
*/
|
|
191
|
+
async getTotalTaxAmount() {
|
|
192
|
+
const items = await item_entity_1.CompanyBillItemEntity.findBy({
|
|
193
|
+
billId: this.id,
|
|
194
|
+
freeBenefit: false
|
|
195
|
+
});
|
|
196
|
+
if (!items?.length) {
|
|
197
|
+
return 0;
|
|
198
|
+
}
|
|
199
|
+
const sum = items.map(item => {
|
|
200
|
+
const price = Number(item.price) - Number(item.fromCredit);
|
|
201
|
+
return (price * Number(item.vat)) / 100;
|
|
202
|
+
});
|
|
203
|
+
return common_1.ArrayHelper.getSum(sum);
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Retrieves activity log entries for this bill
|
|
207
|
+
* Includes creation and update timestamps and user information
|
|
208
|
+
* @returns {Promise<Activity[]>} Array of activity entries (filtered to remove null values)
|
|
209
|
+
*/
|
|
210
|
+
async getActivities() {
|
|
211
|
+
const activities = [];
|
|
212
|
+
activities.push(await (0, utils_1.toActivity)(this.createdBy, common_1.ActivityType.createdBy));
|
|
213
|
+
activities.push(await (0, utils_1.toActivity)(this.createdOn, common_1.ActivityType.createdOn));
|
|
214
|
+
activities.push(await (0, utils_1.toActivity)(this.updatedBy, common_1.ActivityType.updatedBy));
|
|
215
|
+
activities.push(await (0, utils_1.toActivity)(this.updatedOn, common_1.ActivityType.updatedOn));
|
|
216
|
+
return activities.filter(a => a);
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
exports.CompanyBillEntity = CompanyBillEntity;
|
|
220
|
+
__decorate([
|
|
221
|
+
(0, typeorm_1.Column)(),
|
|
222
|
+
__metadata("design:type", Number)
|
|
223
|
+
], CompanyBillEntity.prototype, "companyId", void 0);
|
|
224
|
+
__decorate([
|
|
225
|
+
(0, typeorm_1.Column)({
|
|
226
|
+
type: 'enum',
|
|
227
|
+
enum: common_1.BillStatus,
|
|
228
|
+
default: common_1.BillStatus.Open,
|
|
229
|
+
nullable: false
|
|
230
|
+
}),
|
|
231
|
+
__metadata("design:type", String)
|
|
232
|
+
], CompanyBillEntity.prototype, "status", void 0);
|
|
233
|
+
__decorate([
|
|
234
|
+
(0, typeorm_1.Column)(),
|
|
235
|
+
__metadata("design:type", Date)
|
|
236
|
+
], CompanyBillEntity.prototype, "startDate", void 0);
|
|
237
|
+
__decorate([
|
|
238
|
+
(0, typeorm_1.Column)(),
|
|
239
|
+
__metadata("design:type", Date)
|
|
240
|
+
], CompanyBillEntity.prototype, "endDate", void 0);
|
|
241
|
+
__decorate([
|
|
242
|
+
(0, typeorm_1.Column)({
|
|
243
|
+
type: 'decimal',
|
|
244
|
+
precision: 10,
|
|
245
|
+
scale: 2,
|
|
246
|
+
nullable: false,
|
|
247
|
+
default: 0
|
|
248
|
+
}),
|
|
249
|
+
__metadata("design:type", Number)
|
|
250
|
+
], CompanyBillEntity.prototype, "subtotalPrice", void 0);
|
|
251
|
+
__decorate([
|
|
252
|
+
(0, typeorm_1.Column)({
|
|
253
|
+
type: 'decimal',
|
|
254
|
+
precision: 10,
|
|
255
|
+
scale: 2,
|
|
256
|
+
nullable: false,
|
|
257
|
+
default: 0
|
|
258
|
+
}),
|
|
259
|
+
__metadata("design:type", Number)
|
|
260
|
+
], CompanyBillEntity.prototype, "totalPrice", void 0);
|
|
261
|
+
__decorate([
|
|
262
|
+
(0, typeorm_1.Column)({
|
|
263
|
+
type: 'decimal',
|
|
264
|
+
precision: 10,
|
|
265
|
+
scale: 2,
|
|
266
|
+
nullable: false,
|
|
267
|
+
default: 0
|
|
268
|
+
}),
|
|
269
|
+
__metadata("design:type", Number)
|
|
270
|
+
], CompanyBillEntity.prototype, "taxAmount", void 0);
|
|
271
|
+
__decorate([
|
|
272
|
+
(0, typeorm_1.Column)({
|
|
273
|
+
type: 'decimal',
|
|
274
|
+
precision: 10,
|
|
275
|
+
scale: 2,
|
|
276
|
+
nullable: false,
|
|
277
|
+
default: 0
|
|
278
|
+
}),
|
|
279
|
+
__metadata("design:type", Number)
|
|
280
|
+
], CompanyBillEntity.prototype, "creditAmount", void 0);
|
|
281
|
+
__decorate([
|
|
282
|
+
(0, typeorm_1.Column)({
|
|
283
|
+
type: 'decimal',
|
|
284
|
+
precision: 12,
|
|
285
|
+
scale: 2,
|
|
286
|
+
nullable: false,
|
|
287
|
+
default: 0
|
|
288
|
+
}),
|
|
289
|
+
__metadata("design:type", Number)
|
|
290
|
+
], CompanyBillEntity.prototype, "productBalance", void 0);
|
|
291
|
+
__decorate([
|
|
292
|
+
(0, typeorm_1.Column)({
|
|
293
|
+
nullable: true,
|
|
294
|
+
default: null
|
|
295
|
+
}),
|
|
296
|
+
__metadata("design:type", Number)
|
|
297
|
+
], CompanyBillEntity.prototype, "freeBenefitItems", void 0);
|
|
298
|
+
__decorate([
|
|
299
|
+
(0, typeorm_1.Column)({
|
|
300
|
+
nullable: true,
|
|
301
|
+
default: null
|
|
302
|
+
}),
|
|
303
|
+
__metadata("design:type", Number)
|
|
304
|
+
], CompanyBillEntity.prototype, "freeBenefitAmount", void 0);
|
|
305
|
+
__decorate([
|
|
306
|
+
(0, typeorm_1.Column)({
|
|
307
|
+
nullable: true,
|
|
308
|
+
default: null
|
|
309
|
+
}),
|
|
310
|
+
__metadata("design:type", Number)
|
|
311
|
+
], CompanyBillEntity.prototype, "fromCreditOrFreeBenefits", void 0);
|
|
312
|
+
__decorate([
|
|
313
|
+
(0, typeorm_1.Column)({
|
|
314
|
+
type: 'decimal',
|
|
315
|
+
precision: 8,
|
|
316
|
+
scale: 2,
|
|
317
|
+
nullable: false,
|
|
318
|
+
default: 0
|
|
319
|
+
}),
|
|
320
|
+
__metadata("design:type", Number)
|
|
321
|
+
], CompanyBillEntity.prototype, "agentProfit", void 0);
|
|
322
|
+
__decorate([
|
|
323
|
+
(0, typeorm_1.ManyToOne)(() => company_entity_1.CompanyEntity, company => company.bills),
|
|
324
|
+
__metadata("design:type", Promise)
|
|
325
|
+
], CompanyBillEntity.prototype, "company", void 0);
|
|
326
|
+
__decorate([
|
|
327
|
+
(0, typeorm_1.OneToMany)(() => item_entity_1.CompanyBillItemEntity, item => item.bill),
|
|
328
|
+
__metadata("design:type", Promise)
|
|
329
|
+
], CompanyBillEntity.prototype, "items", void 0);
|
|
330
|
+
__decorate([
|
|
331
|
+
(0, typeorm_1.OneToMany)(() => transaction_entity_1.CompanyBillTransactionEntity, payment => payment.bill),
|
|
332
|
+
__metadata("design:type", Promise)
|
|
333
|
+
], CompanyBillEntity.prototype, "transactions", void 0);
|
|
334
|
+
exports.CompanyBillEntity = CompanyBillEntity = __decorate([
|
|
335
|
+
(0, typeorm_1.Entity)('companyBills'),
|
|
336
|
+
__metadata("design:paramtypes", [Object])
|
|
337
|
+
], CompanyBillEntity);
|
|
338
|
+
//# sourceMappingURL=bill.entity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bill.entity.js","sourceRoot":"","sources":["../../../../../src/profile/company/finances/billing/bill.entity.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qCAA+D;AAC/D,4CAAwF;AACxF,yDAAqD;AACrD,6DAAoE;AACpE,+CAAsD;AACtD,6CAAgE;AAEhE;;;;GAIG;AAEI,IAAM,iBAAiB,GAAvB,MAAM,iBAAkB,SAAQ,uBAAqB;IAE3D;;OAEG;IAEH,SAAS,CAAS;IAElB;;;;OAIG;IAOH,MAAM,CAAa;IAEnB;;OAEG;IAEH,SAAS,CAAO;IAEhB;;OAEG;IAEH,OAAO,CAAO;IAEd;;;;OAIG;IAQH,aAAa,CAAS;IAEtB,QAAQ;IACR,0CAA0C;IAC1C,sHAAsH;IACtH,+EAA+E;IAE/E;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IAQH,UAAU,CAAS;IAEnB;;OAEG;IAQH,SAAS,CAAS;IAElB;;OAEG;IAQH,YAAY,CAAS;IAErB;;;;OAIG;IAQH,cAAc,CAAS;IAEvB;;;;OAIG;IAKH,gBAAgB,CAAS;IAEzB;;;;OAIG;IAKH,iBAAiB,CAAS;IAE1B;;;;OAIG;IAKH,wBAAwB,CAAS;IAEjC;;;;;;OAMG;IAQH,WAAW,CAAS;IAEpB;;OAEG;IAEH,OAAO,CAAyB;IAEhC;;OAEG;IAEH,KAAK,CAAmC;IAExC;;OAEG;IAEH,YAAY,CAA0C;IAEtD;;;OAGG;IACH,YAAY,KAAkC;QAC7C,KAAK,EAAE,CAAC;QACR,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC5B,CAAC;IAED;;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AAO,EAAE,IAAI;KACb,CAAC;;2DACuB;AAWzB;IAJC,IAAA,gBAAM,EAAC;QACP,QAAQ,EAAE,IAAI;QACd,OAAO,EAAE,IAAI;KACb,CAAC;;4DACwB;AAW1B;IAJC,IAAA,gBAAM,EAAC;QACP,QAAQ,EAAE,IAAI;QACd,OAAO,EAAE,IAAI;KACb,CAAC;;mEAC+B;AAgBjC;IAPC,IAAA,gBAAM,EAAC;QACP,IAAI,EAAE,SAAS;QACf,SAAS,EAAE,CAAC;QACZ,KAAK,EAAE,CAAC;QACR,QAAQ,EAAE,KAAK;QACf,OAAO,EAAE,CAAC;KACV,CAAC;;sDACkB;AAMpB;IADC,IAAA,mBAAS,EAAC,GAAG,EAAE,CAAC,8BAAa,EAAE,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC;;kDACzB;AAMhC;IADC,IAAA,mBAAS,EAAC,GAAG,EAAE,CAAC,mCAAqB,EAAE,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC;;gDAClB;AAMxC;IADC,IAAA,mBAAS,EAAC,GAAG,EAAE,CAAC,iDAA4B,EAAE,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC;;uDACjB;4BA5L1C,iBAAiB;IAD7B,IAAA,gBAAM,EAAC,cAAc,CAAC;;GACV,iBAAiB,CA8R7B"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { Activity, BillItem } from '@driveup/common';
|
|
2
|
+
import { CompanyBillEntity } from './bill.entity';
|
|
3
|
+
import { CompanyCourseEntity } from '../../course/course.entity';
|
|
4
|
+
import { CompanyProductAddonEntity } from '../../product/addon.entity';
|
|
5
|
+
import { TrackableEntity } from '../../../../utils';
|
|
6
|
+
export declare class CompanyBillItemEntity extends TrackableEntity<BillItem> {
|
|
7
|
+
billId: number;
|
|
8
|
+
/**
|
|
9
|
+
* Company course, if applicable
|
|
10
|
+
*/
|
|
11
|
+
courseId: number;
|
|
12
|
+
/**
|
|
13
|
+
* Company product addon, if applicable
|
|
14
|
+
*/
|
|
15
|
+
addonId: number;
|
|
16
|
+
/**
|
|
17
|
+
* Bill item name
|
|
18
|
+
* Generic name based on the item type (e.g. "Enterprise Plan - Monthly Subscription")
|
|
19
|
+
* or specific name like student training John Doe - Category B
|
|
20
|
+
*/
|
|
21
|
+
title: string;
|
|
22
|
+
/**
|
|
23
|
+
* Bill item description
|
|
24
|
+
*/
|
|
25
|
+
description: string;
|
|
26
|
+
/**
|
|
27
|
+
* Price per unit before tax
|
|
28
|
+
*/
|
|
29
|
+
price: number;
|
|
30
|
+
/**
|
|
31
|
+
* VAT percentage applied to this item
|
|
32
|
+
*/
|
|
33
|
+
vat: number;
|
|
34
|
+
/**
|
|
35
|
+
* Price per unit after tax
|
|
36
|
+
* If a portion of the price is deducted from company credit,
|
|
37
|
+
* the tax is calculated only on the remaining amount,
|
|
38
|
+
* and is not calculated on the part that is taken from credit
|
|
39
|
+
* * totalPrice = (price - fromCredit) + ((price - fromCredit) * vat) / 100
|
|
40
|
+
*/
|
|
41
|
+
totalPrice: number;
|
|
42
|
+
/**
|
|
43
|
+
* Wether or not this item is a free benefit
|
|
44
|
+
* (i.e. free training included in the free plan)
|
|
45
|
+
*/
|
|
46
|
+
freeBenefit: boolean;
|
|
47
|
+
/**
|
|
48
|
+
* The amount that is deducted from product's credit
|
|
49
|
+
*/
|
|
50
|
+
fromCredit: number;
|
|
51
|
+
/**
|
|
52
|
+
* Wether or not this item is out of enterprise plan's scope
|
|
53
|
+
* (new instructors with which the seats limit is exceeded)
|
|
54
|
+
*/
|
|
55
|
+
outOfPlan: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* A snapshot of the entity item at the time of billing
|
|
58
|
+
*/
|
|
59
|
+
metadata: {
|
|
60
|
+
[key: string | number]: any;
|
|
61
|
+
};
|
|
62
|
+
bill: Promise<CompanyBillEntity>;
|
|
63
|
+
/**
|
|
64
|
+
* Company course, if applicable
|
|
65
|
+
*/
|
|
66
|
+
course: Promise<CompanyCourseEntity>;
|
|
67
|
+
/**
|
|
68
|
+
* Company product addon, if applicable
|
|
69
|
+
*/
|
|
70
|
+
addon: Promise<CompanyProductAddonEntity>;
|
|
71
|
+
constructor(props?: Partial<CompanyBillItemEntity>);
|
|
72
|
+
toModel(): BillItem;
|
|
73
|
+
toSummary(): BillItem;
|
|
74
|
+
getActivities(): Promise<Activity[]>;
|
|
75
|
+
}
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.CompanyBillItemEntity = void 0;
|
|
13
|
+
const typeorm_1 = require("typeorm");
|
|
14
|
+
const common_1 = require("@driveup/common");
|
|
15
|
+
const bill_entity_1 = require("./bill.entity");
|
|
16
|
+
const course_entity_1 = require("../../course/course.entity");
|
|
17
|
+
const addon_entity_1 = require("../../product/addon.entity");
|
|
18
|
+
const utils_1 = require("../../../../utils");
|
|
19
|
+
let CompanyBillItemEntity = class CompanyBillItemEntity extends utils_1.TrackableEntity {
|
|
20
|
+
billId;
|
|
21
|
+
/**
|
|
22
|
+
* Company course, if applicable
|
|
23
|
+
*/
|
|
24
|
+
courseId;
|
|
25
|
+
/**
|
|
26
|
+
* Company product addon, if applicable
|
|
27
|
+
*/
|
|
28
|
+
addonId;
|
|
29
|
+
/**
|
|
30
|
+
* Bill item name
|
|
31
|
+
* Generic name based on the item type (e.g. "Enterprise Plan - Monthly Subscription")
|
|
32
|
+
* or specific name like student training John Doe - Category B
|
|
33
|
+
*/
|
|
34
|
+
title;
|
|
35
|
+
/**
|
|
36
|
+
* Bill item description
|
|
37
|
+
*/
|
|
38
|
+
description;
|
|
39
|
+
/**
|
|
40
|
+
* Price per unit before tax
|
|
41
|
+
*/
|
|
42
|
+
price;
|
|
43
|
+
/**
|
|
44
|
+
* VAT percentage applied to this item
|
|
45
|
+
*/
|
|
46
|
+
vat;
|
|
47
|
+
/**
|
|
48
|
+
* Price per unit after tax
|
|
49
|
+
* If a portion of the price is deducted from company credit,
|
|
50
|
+
* the tax is calculated only on the remaining amount,
|
|
51
|
+
* and is not calculated on the part that is taken from credit
|
|
52
|
+
* * totalPrice = (price - fromCredit) + ((price - fromCredit) * vat) / 100
|
|
53
|
+
*/
|
|
54
|
+
totalPrice;
|
|
55
|
+
/**
|
|
56
|
+
* Wether or not this item is a free benefit
|
|
57
|
+
* (i.e. free training included in the free plan)
|
|
58
|
+
*/
|
|
59
|
+
freeBenefit;
|
|
60
|
+
/**
|
|
61
|
+
* The amount that is deducted from product's credit
|
|
62
|
+
*/
|
|
63
|
+
fromCredit;
|
|
64
|
+
/**
|
|
65
|
+
* Wether or not this item is out of enterprise plan's scope
|
|
66
|
+
* (new instructors with which the seats limit is exceeded)
|
|
67
|
+
*/
|
|
68
|
+
outOfPlan;
|
|
69
|
+
/**
|
|
70
|
+
* A snapshot of the entity item at the time of billing
|
|
71
|
+
*/
|
|
72
|
+
metadata;
|
|
73
|
+
bill;
|
|
74
|
+
/**
|
|
75
|
+
* Company course, if applicable
|
|
76
|
+
*/
|
|
77
|
+
course;
|
|
78
|
+
/**
|
|
79
|
+
* Company product addon, if applicable
|
|
80
|
+
*/
|
|
81
|
+
addon;
|
|
82
|
+
constructor(props) {
|
|
83
|
+
super();
|
|
84
|
+
Object.assign(this, props);
|
|
85
|
+
}
|
|
86
|
+
toModel() {
|
|
87
|
+
return new common_1.BillItem({
|
|
88
|
+
id: this.id,
|
|
89
|
+
title: this.title,
|
|
90
|
+
description: this.description,
|
|
91
|
+
price: this.price,
|
|
92
|
+
vat: this.vat,
|
|
93
|
+
totalPrice: this.totalPrice,
|
|
94
|
+
freeBenefit: this.freeBenefit,
|
|
95
|
+
fromCredit: this.fromCredit,
|
|
96
|
+
outOfPlan: this.outOfPlan,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
toSummary() {
|
|
100
|
+
return this.toModel();
|
|
101
|
+
}
|
|
102
|
+
async getActivities() {
|
|
103
|
+
const activities = [];
|
|
104
|
+
activities.push(await (0, utils_1.toActivity)(this.createdBy, common_1.ActivityType.createdBy));
|
|
105
|
+
activities.push(await (0, utils_1.toActivity)(this.createdOn, common_1.ActivityType.createdOn));
|
|
106
|
+
activities.push(await (0, utils_1.toActivity)(this.updatedBy, common_1.ActivityType.updatedBy));
|
|
107
|
+
activities.push(await (0, utils_1.toActivity)(this.updatedOn, common_1.ActivityType.updatedOn));
|
|
108
|
+
return activities.filter(a => a);
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
exports.CompanyBillItemEntity = CompanyBillItemEntity;
|
|
112
|
+
__decorate([
|
|
113
|
+
(0, typeorm_1.Column)(),
|
|
114
|
+
__metadata("design:type", Number)
|
|
115
|
+
], CompanyBillItemEntity.prototype, "billId", void 0);
|
|
116
|
+
__decorate([
|
|
117
|
+
(0, typeorm_1.Column)({
|
|
118
|
+
nullable: true,
|
|
119
|
+
default: null
|
|
120
|
+
}),
|
|
121
|
+
__metadata("design:type", Number)
|
|
122
|
+
], CompanyBillItemEntity.prototype, "courseId", void 0);
|
|
123
|
+
__decorate([
|
|
124
|
+
(0, typeorm_1.Column)({
|
|
125
|
+
nullable: true,
|
|
126
|
+
default: null
|
|
127
|
+
}),
|
|
128
|
+
__metadata("design:type", Number)
|
|
129
|
+
], CompanyBillItemEntity.prototype, "addonId", void 0);
|
|
130
|
+
__decorate([
|
|
131
|
+
(0, typeorm_1.Column)(),
|
|
132
|
+
__metadata("design:type", String)
|
|
133
|
+
], CompanyBillItemEntity.prototype, "title", void 0);
|
|
134
|
+
__decorate([
|
|
135
|
+
(0, typeorm_1.Column)({
|
|
136
|
+
nullable: true,
|
|
137
|
+
default: null
|
|
138
|
+
}),
|
|
139
|
+
__metadata("design:type", String)
|
|
140
|
+
], CompanyBillItemEntity.prototype, "description", void 0);
|
|
141
|
+
__decorate([
|
|
142
|
+
(0, typeorm_1.Column)({
|
|
143
|
+
type: 'decimal',
|
|
144
|
+
precision: 10,
|
|
145
|
+
scale: 2,
|
|
146
|
+
nullable: false,
|
|
147
|
+
default: 0
|
|
148
|
+
}),
|
|
149
|
+
__metadata("design:type", Number)
|
|
150
|
+
], CompanyBillItemEntity.prototype, "price", void 0);
|
|
151
|
+
__decorate([
|
|
152
|
+
(0, typeorm_1.Column)({
|
|
153
|
+
type: 'decimal',
|
|
154
|
+
precision: 8,
|
|
155
|
+
scale: 2,
|
|
156
|
+
nullable: false,
|
|
157
|
+
default: 0
|
|
158
|
+
}),
|
|
159
|
+
__metadata("design:type", Number)
|
|
160
|
+
], CompanyBillItemEntity.prototype, "vat", void 0);
|
|
161
|
+
__decorate([
|
|
162
|
+
(0, typeorm_1.Column)({
|
|
163
|
+
type: 'decimal',
|
|
164
|
+
precision: 10,
|
|
165
|
+
scale: 2,
|
|
166
|
+
nullable: false,
|
|
167
|
+
default: 0
|
|
168
|
+
}),
|
|
169
|
+
__metadata("design:type", Number)
|
|
170
|
+
], CompanyBillItemEntity.prototype, "totalPrice", void 0);
|
|
171
|
+
__decorate([
|
|
172
|
+
(0, typeorm_1.Column)({
|
|
173
|
+
nullable: false,
|
|
174
|
+
default: false
|
|
175
|
+
}),
|
|
176
|
+
__metadata("design:type", Boolean)
|
|
177
|
+
], CompanyBillItemEntity.prototype, "freeBenefit", void 0);
|
|
178
|
+
__decorate([
|
|
179
|
+
(0, typeorm_1.Column)({
|
|
180
|
+
type: 'decimal',
|
|
181
|
+
precision: 8,
|
|
182
|
+
scale: 2,
|
|
183
|
+
nullable: false,
|
|
184
|
+
default: 0
|
|
185
|
+
}),
|
|
186
|
+
__metadata("design:type", Number)
|
|
187
|
+
], CompanyBillItemEntity.prototype, "fromCredit", void 0);
|
|
188
|
+
__decorate([
|
|
189
|
+
(0, typeorm_1.Column)({
|
|
190
|
+
nullable: false,
|
|
191
|
+
default: false
|
|
192
|
+
}),
|
|
193
|
+
__metadata("design:type", Boolean)
|
|
194
|
+
], CompanyBillItemEntity.prototype, "outOfPlan", void 0);
|
|
195
|
+
__decorate([
|
|
196
|
+
(0, typeorm_1.Column)({
|
|
197
|
+
type: 'simple-json',
|
|
198
|
+
nullable: true,
|
|
199
|
+
default: null
|
|
200
|
+
}),
|
|
201
|
+
__metadata("design:type", Object)
|
|
202
|
+
], CompanyBillItemEntity.prototype, "metadata", void 0);
|
|
203
|
+
__decorate([
|
|
204
|
+
(0, typeorm_1.ManyToOne)(() => bill_entity_1.CompanyBillEntity, bill => bill.items),
|
|
205
|
+
__metadata("design:type", Promise)
|
|
206
|
+
], CompanyBillItemEntity.prototype, "bill", void 0);
|
|
207
|
+
__decorate([
|
|
208
|
+
(0, typeorm_1.ManyToOne)(() => course_entity_1.CompanyCourseEntity, course => course.billItems),
|
|
209
|
+
__metadata("design:type", Promise)
|
|
210
|
+
], CompanyBillItemEntity.prototype, "course", void 0);
|
|
211
|
+
__decorate([
|
|
212
|
+
(0, typeorm_1.ManyToOne)(() => addon_entity_1.CompanyProductAddonEntity, addon => addon.billItems),
|
|
213
|
+
__metadata("design:type", Promise)
|
|
214
|
+
], CompanyBillItemEntity.prototype, "addon", void 0);
|
|
215
|
+
exports.CompanyBillItemEntity = CompanyBillItemEntity = __decorate([
|
|
216
|
+
(0, typeorm_1.Entity)('companyBillItems'),
|
|
217
|
+
__metadata("design:paramtypes", [Object])
|
|
218
|
+
], CompanyBillItemEntity);
|
|
219
|
+
//# sourceMappingURL=item.entity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"item.entity.js","sourceRoot":"","sources":["../../../../../src/profile/company/finances/billing/item.entity.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qCAAoD;AACpD,4CAAmE;AACnE,+CAAkD;AAClD,8DAAiE;AACjE,6DAAuE;AACvE,6CAAgE;AAGzD,IAAM,qBAAqB,GAA3B,MAAM,qBAAsB,SAAQ,uBAAyB;IAGnE,MAAM,CAAS;IAEf;;OAEG;IAKH,QAAQ,CAAS;IAEjB;;OAEG;IAKH,OAAO,CAAS;IAEhB;;;;OAIG;IAEH,KAAK,CAAS;IAEd;;OAEG;IAKH,WAAW,CAAS;IAEpB;;OAEG;IAQH,KAAK,CAAS;IAEd;;OAEG;IAQH,GAAG,CAAS;IAEZ;;;;;;OAMG;IAQH,UAAU,CAAS;IAEnB;;;OAGG;IAKH,WAAW,CAAU;IAErB;;OAEG;IAQH,UAAU,CAAS;IAEnB;;;OAGG;IAKH,SAAS,CAAU;IAEnB;;OAEG;IAMH,QAAQ,CAAkC;IAG1C,IAAI,CAA6B;IAEjC;;OAEG;IAEH,MAAM,CAA+B;IAErC;;OAEG;IAEH,KAAK,CAAqC;IAE1C,YAAY,KAAsC;QACjD,KAAK,EAAE,CAAC;QACR,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC5B,CAAC;IAED,OAAO;QACN,OAAO,IAAI,iBAAQ,CAAC;YACnB,EAAE,EAAE,IAAI,CAAC,EAAE;YACX,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,GAAG,EAAE,IAAI,CAAC,GAAG;YACb,UAAU,EAAE,IAAI,CA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IADC,IAAA,mBAAS,EAAC,GAAG,EAAE,CAAC,wCAAyB,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,SAAS,CAAC;;oDAC3B;gCAvI9B,qBAAqB;IADjC,IAAA,gBAAM,EAAC,kBAAkB,CAAC;;GACd,qBAAqB,CAwKjC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Activity, BillTransaction, PaymentProvider, StatusType } from '@driveup/common';
|
|
2
|
+
import { AgentPayoutEntity } from '../../../agent/payout.entity';
|
|
3
|
+
import { CompanyBillEntity } from './bill.entity';
|
|
4
|
+
import { CompanyPaymentMethodEntity } from '../payment/method.entity';
|
|
5
|
+
import { TrackableEntity } from '../../../../utils';
|
|
6
|
+
export declare class CompanyBillTransactionEntity extends TrackableEntity<BillTransaction> {
|
|
7
|
+
billId: number;
|
|
8
|
+
paymentMethodId: number;
|
|
9
|
+
status: StatusType;
|
|
10
|
+
amount: number;
|
|
11
|
+
provider: PaymentProvider;
|
|
12
|
+
/**
|
|
13
|
+
* Provider payment method id
|
|
14
|
+
*/
|
|
15
|
+
providerId: number;
|
|
16
|
+
providerResponse: any;
|
|
17
|
+
/**
|
|
18
|
+
* Payment confirmed by job task
|
|
19
|
+
*/
|
|
20
|
+
paidOn: Date;
|
|
21
|
+
/**
|
|
22
|
+
* Payment failed on date
|
|
23
|
+
*/
|
|
24
|
+
failedOn: Date;
|
|
25
|
+
/**
|
|
26
|
+
* Company bill associated with this transaction
|
|
27
|
+
*/
|
|
28
|
+
bill: Promise<CompanyBillEntity>;
|
|
29
|
+
/**
|
|
30
|
+
* Payment method used for this transaction
|
|
31
|
+
*/
|
|
32
|
+
paymentMethod: Promise<CompanyPaymentMethodEntity>;
|
|
33
|
+
/**
|
|
34
|
+
* Agent promotion associated with this transaction
|
|
35
|
+
* The agent earns profit from this transaction based on his percentage
|
|
36
|
+
* The earning period is limited to the promotion start (company created date)
|
|
37
|
+
* and driveup promotion requirements (12 months)
|
|
38
|
+
*/
|
|
39
|
+
agentPromotion: Promise<AgentPayoutEntity>;
|
|
40
|
+
constructor(props?: Partial<CompanyBillTransactionEntity>);
|
|
41
|
+
toModel(): Promise<BillTransaction>;
|
|
42
|
+
toSummary(): BillTransaction;
|
|
43
|
+
getActivities(): Promise<Activity[]>;
|
|
44
|
+
}
|