@intelact/driveup 2.4.8 → 2.5.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.
@@ -1,10 +1,26 @@
1
+ import { StatusType } from "@driveup/shared";
1
2
  import { CompanyPayment } from "./company-payment.model";
2
3
  import { Item } from "../item/item.model";
3
4
  export declare class CompanyPaymentMethod {
4
5
  id: number;
5
6
  name: string;
6
7
  icon: string;
8
+ /**
9
+ * Where the payment method stands
10
+ * - Pending: registered, still waiting for the provider to verify it
11
+ * - Active: verified by the provider, and the one the company is charged with
12
+ * - Inactive: verified by the provider, but replaced, deleted, expired or permanently declined
13
+ */
14
+ status: StatusType;
15
+ /**
16
+ * Whether this is the payment method the company is charged with
17
+ * @deprecated read {@link status} instead, this is kept for the clients that have not moved over yet
18
+ */
7
19
  active: boolean;
20
+ /**
21
+ * Whether the provider has yet to verify the payment method
22
+ * @deprecated read {@link status} instead, this is kept for the clients that have not moved over yet
23
+ */
8
24
  pending: boolean;
9
25
  details: Item[];
10
26
  warnings: string[];
@@ -11,6 +11,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.CompanyPaymentMethod = void 0;
13
13
  const class_transformer_1 = require("class-transformer");
14
+ const shared_1 = require("@driveup/shared");
14
15
  const company_payment_model_1 = require("./company-payment.model");
15
16
  const item_model_1 = require("../item/item.model");
16
17
  class CompanyPaymentMethod {
@@ -33,6 +34,10 @@ __decorate([
33
34
  (0, class_transformer_1.Expose)(),
34
35
  __metadata("design:type", String)
35
36
  ], CompanyPaymentMethod.prototype, "icon", void 0);
37
+ __decorate([
38
+ (0, class_transformer_1.Expose)(),
39
+ __metadata("design:type", String)
40
+ ], CompanyPaymentMethod.prototype, "status", void 0);
36
41
  __decorate([
37
42
  (0, class_transformer_1.Expose)(),
38
43
  (0, class_transformer_1.Type)(() => Boolean),
@@ -1 +1 @@
1
- {"version":3,"file":"payment-method.model.js","sourceRoot":"","sources":["../../src/finance/payment-method.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yDAAiD;AACjD,mEAAyD;AACzD,mDAA0C;AAE1C,MAAa,oBAAoB;IA0ChC,6DAA6D;IAE7D,YAAY,KAAqC;QAChD,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC5B,CAAC;CACD;AA/CD,oDA+CC;AA5CA;IAFC,IAAA,0BAAM,GAAE;IACR,IAAA,wBAAI,EAAC,GAAG,EAAE,CAAC,MAAM,CAAC;;gDACR;AAGX;IADC,IAAA,0BAAM,GAAE;;kDACI;AAGb;IADC,IAAA,0BAAM,GAAE;;kDACI;AAIb;IAFC,IAAA,0BAAM,GAAE;IACR,IAAA,wBAAI,EAAC,GAAG,EAAE,CAAC,OAAO,CAAC;;oDACJ;AAIhB;IAFC,IAAA,0BAAM,GAAE;IACR,IAAA,wBAAI,EAAC,GAAG,EAAE,CAAC,OAAO,CAAC;;qDACH;AAIjB;IAFC,IAAA,0BAAM,GAAE;IACR,IAAA,wBAAI,EAAC,GAAG,EAAE,CAAC,iBAAI,CAAC;;qDACD;AAGhB;IADC,IAAA,0BAAM,GAAE;;sDACU;AAInB;IAFC,IAAA,0BAAM,GAAE;IACR,IAAA,wBAAI,EAAC,GAAG,EAAE,CAAC,sCAAc,CAAC;;4DACM;AAMjC;IADC,IAAA,0BAAM,GAAE;;uEACyB;AAGlC;IADC,IAAA,0BAAM,GAAE;;qEACuB;AAGhC;IADC,IAAA,0BAAM,GAAE;;gEACkB"}
1
+ {"version":3,"file":"payment-method.model.js","sourceRoot":"","sources":["../../src/finance/payment-method.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yDAAiD;AACjD,4CAA6C;AAC7C,mEAAyD;AACzD,mDAA0C;AAE1C,MAAa,oBAAoB;IA2DhC,6DAA6D;IAE7D,YAAY,KAAqC;QAChD,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC5B,CAAC;CACD;AAhED,oDAgEC;AA7DA;IAFC,IAAA,0BAAM,GAAE;IACR,IAAA,wBAAI,EAAC,GAAG,EAAE,CAAC,MAAM,CAAC;;gDACR;AAGX;IADC,IAAA,0BAAM,GAAE;;kDACI;AAGb;IADC,IAAA,0BAAM,GAAE;;kDACI;AASb;IADC,IAAA,0BAAM,GAAE;;oDACU;AAQnB;IAFC,IAAA,0BAAM,GAAE;IACR,IAAA,wBAAI,EAAC,GAAG,EAAE,CAAC,OAAO,CAAC;;oDACJ;AAQhB;IAFC,IAAA,0BAAM,GAAE;IACR,IAAA,wBAAI,EAAC,GAAG,EAAE,CAAC,OAAO,CAAC;;qDACH;AAIjB;IAFC,IAAA,0BAAM,GAAE;IACR,IAAA,wBAAI,EAAC,GAAG,EAAE,CAAC,iBAAI,CAAC;;qDACD;AAGhB;IADC,IAAA,0BAAM,GAAE;;sDACU;AAInB;IAFC,IAAA,0BAAM,GAAE;IACR,IAAA,wBAAI,EAAC,GAAG,EAAE,CAAC,sCAAc,CAAC;;4DACM;AAMjC;IADC,IAAA,0BAAM,GAAE;;uEACyB;AAGlC;IADC,IAAA,0BAAM,GAAE;;qEACuB;AAGhC;IADC,IAAA,0BAAM,GAAE;;gEACkB"}
package/lib/index.d.ts CHANGED
@@ -113,6 +113,7 @@ export { IUserAgent } from "./user/agent.interface";
113
113
  export { ArrayHelper } from "./utils/array.helper";
114
114
  export { CompareWithEndDate } from "./utils/compare.validator";
115
115
  export { DateHelper } from "./utils/date.helper";
116
+ export { Money } from "./utils/money";
116
117
  export { PhoneHelper } from "./utils/phone.helper";
117
118
  export { EitherRequired, EitherRequiredConstraint, MutuallyRequired, MutuallyRequiredConstraint } from "./utils/required.validator";
118
119
  export { ToBoolean, ToEnum, ToEnumArray, ToNumber, ToNumberArray, ToStringArray, Trim } from "./utils/transformers.helper";
package/lib/index.js CHANGED
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CourseDefinitionCreateDto = exports.CourseCreateDto = exports.CourseAppointmentFilterDto = exports.CoursePartDefinition = exports.Course = exports.CourseAppointment = exports.Country = exports.CountryUpdateDto = exports.CountrySearchDto = exports.CountryCreateDto = exports.CompanyCloseProfileDependency = exports.Company = exports.CompanyDashboardWidgetModel = exports.UrlDto = exports.SortOrderDto = exports.SortListDto = exports.SocialLinksDto = exports.SocialLink = exports.PhraseSearchDto = exports.PromotionCodeDto = exports.ProfileDependency = exports.PriceDto = exports.PhoneDto = exports.LanguageDto = exports.IDsDto = exports.EmailDto = exports.TranslateDto = exports.TitleDto = exports.NameDto = exports.MessageDto = exports.DescriptionDto = exports.BooleanValueDto = exports.AppInfo = exports.WorkingHoursDto = exports.WorkdayDefinition = exports.HolidaysDto = exports.Period = exports.ObligationPeriodDto = exports.MonthYearDto = exports.DateDto = exports.Appointment = exports.CompanyBill = exports.CompanyBillItem = exports.SignupDto = exports.SigninDto = exports.UserAlert = exports.AgentCode = exports.AgentClient = exports.Agent = exports.AgentClientsFilterDto = void 0;
4
4
  exports.FinanceFilterDto = exports.CompanyStudentDebtFilterDto = exports.CompanyOnlineTransactionFilterDto = exports.CompanyOnlineTransactionBulkUpdateDto = exports.CompanyFinancialFlowFilterDto = exports.CompanyBankInfoSubmitDto = exports.Expense = exports.SystemExpenseTranslationDto = exports.ExpenseUpdateDto = exports.ExpenseCreateDto = exports.CompanyExpenseFilterDto = exports.ExpenseCategoryTranslation = exports.ExpenseCategory = exports.Event = exports.TaskUpdateDto = exports.TaskFilterDto = exports.TaskCreateDto = exports.DrivingTopic = exports.TopicsSortDto = exports.TopicSubmitDto = exports.DrivingTopicFilterDto = exports.DrivingSkill = exports.SkillScoreDto = exports.CompanySkillSubmitDto = exports.DrivingLesson = exports.DrivingExam = exports.ExamStatusDto = exports.ExamFeedbackDto = exports.DrivingCategory = exports.SystemDrivingCategoryTranslationCreateDto = exports.SystemDrivingCategoryMinAgeDto = exports.SystemDrivingCategoryCreateDto = exports.CompanySubmitCategoryDto = exports.CompanyCategoryPriceDto = exports.CompanyCategoryDurationDto = exports.CompanyCategoryAdministrationFeeDto = exports.CompanyActivateCategoryDto = exports.SubmitDiscountDto = exports.DeviceSignatureDto = exports.Device = exports.Currency = exports.CurrencyUpdateDto = exports.CurrencySearchDto = exports.CurrencyCreateDto = exports.Credit = exports.CoursePart = exports.CoursePartDurationDto = exports.CourseMaxStudentsDto = exports.CourseFilterDto = exports.CourseDefinitionUpdateDto = void 0;
5
5
  exports.SettingValueDto = exports.DrivingSessionTopic = exports.DrivingSessionSkill = exports.DrivingSession = exports.InstructorDrivingAppointmentUpdateDto = exports.InstructorDrivingAppointmentCreateDto = exports.RoleDto = exports.SubmitRefundDto = exports.CountrySupportRequestDto = exports.ContactSalesRequestDto = exports.ContactUsRequestDto = exports.PricePlan = exports.SystemPricePlanSubmitDto = exports.PricePlanFilterDto = exports.AgentPayout = exports.SubmitPaymentDto = exports.CompanyPaymentMethod = exports.CompanyPayment = exports.NotificationPreference = exports.NotificationPreferenceDto = exports.Notification = exports.Metric = exports.Log = exports.License = exports.Item = exports.InvoiceItem = exports.Invoice = exports.CompanyInvoiceFilterDto = exports.Instructor = exports.InstructorInviteDto = exports.InstructorFilterDto = exports.InstructorCalendarFilterDto = exports.Handover = exports.HandoverSubmitDto = exports.GiftCode = exports.SystemGiftCodeSubmitDto = exports.SystemGiftCodeGroupUpdateDto = exports.SystemGiftCodeGroupCreateDto = exports.CompanyGiftCodeSubmitDto = exports.GiftCodeGroup = exports.PickupLocationsDto = exports.PickupLocation = exports.ZipCodeDto = exports.LocationDto = exports.FullAddressDto = exports.AddressDto = exports.FreeBenefit = exports.Finance = exports.HandoverTransactionStatusDto = exports.FinanceSortDto = void 0;
6
- exports.Trim = exports.ToStringArray = exports.ToNumberArray = exports.ToNumber = exports.ToEnumArray = exports.ToEnum = exports.ToBoolean = exports.MutuallyRequiredConstraint = exports.MutuallyRequired = exports.EitherRequiredConstraint = exports.EitherRequired = exports.PhoneHelper = exports.DateHelper = exports.CompareWithEndDate = exports.ArrayHelper = exports.User = exports.CreateProfileDto = exports.CloseProfileDto = exports.ChangeProfileDto = exports.Training = exports.TrainingRatingDto = exports.InstructorTrainingFilterDto = exports.DrivingTransmissionDto = exports.DrivingTrainingFilterDto = exports.CreateTrainingDto = exports.CreateDrivingTrainingDto = exports.CourseTrainingFilterDto = exports.CompanyTrainingFilterDto = exports.TrainingActions = exports.TrainingRequest = exports.TrainingRequestFilterDto = exports.Ticket = exports.TicketSubmitDto = exports.TicketFilterDto = exports.Student = exports.SubmitStudentDto = exports.FilterStudentDto = exports.Signature = exports.Setting = void 0;
6
+ exports.Trim = exports.ToStringArray = exports.ToNumberArray = exports.ToNumber = exports.ToEnumArray = exports.ToEnum = exports.ToBoolean = exports.MutuallyRequiredConstraint = exports.MutuallyRequired = exports.EitherRequiredConstraint = exports.EitherRequired = exports.PhoneHelper = exports.Money = exports.DateHelper = exports.CompareWithEndDate = exports.ArrayHelper = exports.User = exports.CreateProfileDto = exports.CloseProfileDto = exports.ChangeProfileDto = exports.Training = exports.TrainingRatingDto = exports.InstructorTrainingFilterDto = exports.DrivingTransmissionDto = exports.DrivingTrainingFilterDto = exports.CreateTrainingDto = exports.CreateDrivingTrainingDto = exports.CourseTrainingFilterDto = exports.CompanyTrainingFilterDto = exports.TrainingActions = exports.TrainingRequest = exports.TrainingRequestFilterDto = exports.Ticket = exports.TicketSubmitDto = exports.TicketFilterDto = exports.Student = exports.SubmitStudentDto = exports.FilterStudentDto = exports.Signature = exports.Setting = void 0;
7
7
  var agent_dto_1 = require("./agent/agent.dto");
8
8
  Object.defineProperty(exports, "AgentClientsFilterDto", { enumerable: true, get: function () { return agent_dto_1.AgentClientsFilterDto; } });
9
9
  var agent_model_1 = require("./agent/agent.model");
@@ -291,6 +291,8 @@ var compare_validator_1 = require("./utils/compare.validator");
291
291
  Object.defineProperty(exports, "CompareWithEndDate", { enumerable: true, get: function () { return compare_validator_1.CompareWithEndDate; } });
292
292
  var date_helper_1 = require("./utils/date.helper");
293
293
  Object.defineProperty(exports, "DateHelper", { enumerable: true, get: function () { return date_helper_1.DateHelper; } });
294
+ var money_1 = require("./utils/money");
295
+ Object.defineProperty(exports, "Money", { enumerable: true, get: function () { return money_1.Money; } });
294
296
  var phone_helper_1 = require("./utils/phone.helper");
295
297
  Object.defineProperty(exports, "PhoneHelper", { enumerable: true, get: function () { return phone_helper_1.PhoneHelper; } });
296
298
  var required_validator_1 = require("./utils/required.validator");
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,+CAA0D;AAAjD,kHAAA,qBAAqB,OAAA;AAC9B,mDAA4C;AAAnC,oGAAA,KAAK,OAAA;AACd,qDAAmD;AAA1C,2GAAA,WAAW,OAAA;AACpB,iDAA+C;AAAtC,uGAAA,SAAS,OAAA;AAClB,mDAAgD;AAAvC,wGAAA,SAAS,OAAA;AAClB,gDAA8C;AAArC,uGAAA,SAAS,OAAA;AAClB,gDAA8C;AAArC,uGAAA,SAAS,OAAA;AAClB,0DAAyD;AAAhD,kHAAA,eAAe,OAAA;AACxB,gDAAgD;AAAvC,yGAAA,WAAW,OAAA;AACpB,sDAAqD;AAA5C,0GAAA,WAAW,OAAA;AACpB,wCAAqF;AAA5E,+FAAA,OAAO,OAAA;AAAE,oGAAA,YAAY,OAAA;AAAE,2GAAA,mBAAmB,OAAA;AAAE,8FAAA,MAAM,OAAA;AAC3D,8CAAiD;AAAxC,sGAAA,WAAW,OAAA;AAEpB,8CAAwE;AAA/D,4GAAA,iBAAiB,OAAA;AAAE,0GAAA,eAAe,OAAA;AAC3C,8CAA4C;AAAnC,mGAAA,OAAO,OAAA;AAChB,4CAAgH;AAAvG,0GAAA,eAAe,OAAA;AAAE,yGAAA,cAAc,OAAA;AAAE,qGAAA,UAAU,OAAA;AAAE,kGAAA,OAAO,OAAA;AAAE,mGAAA,QAAQ,OAAA;AAAE,uGAAA,Y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AAA;AACpB,+DAA+D;AAAtD,uHAAA,kBAAkB,OAAA;AAC3B,mDAAiD;AAAxC,yGAAA,UAAU,OAAA;AACnB,uCAAsC;AAA7B,8FAAA,KAAK,OAAA;AACd,qDAAmD;AAA1C,2GAAA,WAAW,OAAA;AACpB,iEAAoI;AAA3H,oHAAA,cAAc,OAAA;AAAE,8HAAA,wBAAwB,OAAA;AAAE,sHAAA,gBAAgB,OAAA;AAAE,gIAAA,0BAA0B,OAAA;AAC/F,mEAA2H;AAAlH,gHAAA,SAAS,OAAA;AAAE,6GAAA,MAAM,OAAA;AAAE,kHAAA,WAAW,OAAA;AAAE,+GAAA,QAAQ,OAAA;AAAE,oHAAA,aAAa,OAAA;AAAE,oHAAA,aAAa,OAAA;AAAE,2GAAA,IAAI,OAAA"}
@@ -0,0 +1,101 @@
1
+ /**
2
+ * Anything an amount of money can be read from. null and undefined read as 0
3
+ */
4
+ type Amount = number | string | Money;
5
+ /**
6
+ * An amount of money, and the rules amounts follow
7
+ * - Every calculation is done in decimal, never in binary: a JavaScript number cannot hold 0.1 + 0.2 or 30 / 28, and an
8
+ * amount rounded after such a calculation can land on the wrong side of a rounding step
9
+ * - Immutable: every operation returns a new Money. An amount becomes a number again at the end of the calculation,
10
+ * through `round`, `roundDown` or `toNumber`
11
+ * - Amounts are rounded at the end of a calculation, never per item along the way: the items of a bill or an invoice are
12
+ * added up as they are, and the total is rounded once
13
+ * - This class exists twice, identically: here in @intelact/driveup (used by driveup-api) and in @driveup/common
14
+ * (used by driveup-schema), because neither package may depend on the other. Change one, change the other
15
+ */
16
+ export declare class Money {
17
+ #private;
18
+ private readonly amount;
19
+ /**
20
+ * Every rounded total is a multiple of this step
21
+ */
22
+ static readonly step = "0.05";
23
+ /**
24
+ * The step an amount is kept to when it is stored per item rather than charged: a bill item, an invoice line. Money
25
+ * columns hold 2 decimals, so an amount has to land on a cent before it is saved, while the totals it adds up to are
26
+ * rounded to {@link step}
27
+ */
28
+ static readonly cent = "0.01";
29
+ /**
30
+ * The decimals a rounding looks at. Anything beyond is noise rather than money: our smallest real amount is a
31
+ * millionth (an amount of 2 decimals times a tax rate of 2 decimals), while the binary noise a JavaScript number
32
+ * carries into a calculation is never larger than a ten-billionth for amounts up to a million
33
+ */
34
+ private static readonly noiseFreeDecimals;
35
+ private constructor();
36
+ /**
37
+ * Reads an amount: a number, the string a DECIMAL column is read as, or another Money
38
+ * - A number is read to 15 significant digits, the precision a JavaScript number really has. What lies beyond is
39
+ * binary noise, and it must not survive: 0.1 + 0.2 is 0.30000000000000004, which would otherwise be rounded up a
40
+ * whole step. A string is read exactly, digit for digit
41
+ * - null, undefined and an empty string read as 0
42
+ * @param value Amount - The amount to read
43
+ * @returns Money - The amount
44
+ * @throws when the value is not a number, or is not finite: an amount is never NaN or Infinity
45
+ */
46
+ static of(value: Amount): Money;
47
+ /**
48
+ * @param value Amount - The amount to add
49
+ * @returns Money - This amount plus the given one
50
+ */
51
+ add(value: Amount): Money;
52
+ /**
53
+ * @param value Amount - The amount to subtract
54
+ * @returns Money - This amount minus the given one
55
+ */
56
+ subtract(value: Amount): Money;
57
+ /**
58
+ * @param value Amount - The factor: an amount, or a plain number such as days or a quantity
59
+ * @returns Money - This amount times the given one
60
+ */
61
+ multiply(value: Amount): Money;
62
+ /**
63
+ * @param value Amount - The divisor: an amount, or a plain number such as the days of a month
64
+ * @returns Money - This amount divided by the given one, to 40 significant digits
65
+ * @throws when the divisor is 0
66
+ */
67
+ divide(value: Amount): Money;
68
+ /**
69
+ * The tax due on this amount, unrounded
70
+ * - The tax of several items is calculated per item, added up, and rounded once at the end
71
+ * @param vat Amount - The tax rate in percent: 8.1 for 8.1%. null and undefined read as no tax
72
+ * @returns Money - The tax
73
+ */
74
+ tax(vat: Amount): Money;
75
+ /**
76
+ * The amount rounded up to the next multiple of 0.05
77
+ * - An amount above a multiple goes up to the next one: 0.06 becomes 0.10, 0.96 becomes 1.00 and 0.056 becomes 0.10.
78
+ * An amount that already is a multiple is kept. A negative amount is rounded away from zero
79
+ * - Only the first {@link noiseFreeDecimals} decimals decide: an amount is snapped to them first, so noise left by an
80
+ * earlier calculation cannot push an amount that sits on a multiple up a whole step
81
+ * @param step Amount - The step to round to, 0.05 by default. Pass {@link cent} for an amount stored per item
82
+ * @returns number - The amount, a multiple of the step
83
+ */
84
+ round(step?: Amount): number;
85
+ /**
86
+ * The amount rounded down to the multiple of 0.05 at or below it
87
+ * - The exception to rounding up, for an amount that is taken rather than charged: what a company pays is rounded up,
88
+ * but the credit taken from it is rounded down, so we never take credit it does not have. 12.29 of credit is taken
89
+ * as 12.25, and the 0.04 stays in the company's credit
90
+ * - A negative amount is rounded towards zero the same way, and noise is dropped first, as in {@link round}
91
+ * @param step Amount - The step to round to, 0.05 by default
92
+ * @returns number - The amount, a multiple of the step
93
+ */
94
+ roundDown(step?: Amount): number;
95
+ /**
96
+ * The amount as a number, unrounded
97
+ * @returns number - The amount
98
+ */
99
+ toNumber(): number;
100
+ }
101
+ export {};
@@ -0,0 +1,150 @@
1
+ "use strict";
2
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
5
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
6
+ };
7
+ var __importDefault = (this && this.__importDefault) || function (mod) {
8
+ return (mod && mod.__esModule) ? mod : { "default": mod };
9
+ };
10
+ var _Money_instances, _a, _Money_withoutNoise;
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.Money = void 0;
13
+ const decimal_js_1 = __importDefault(require("decimal.js"));
14
+ // 40 significant digits, far more than any amount needs: a division such as 30 / 28 keeps every digit that could
15
+ // still change a rounding step, and our amounts carry at most 15
16
+ decimal_js_1.default.set({ precision: 40, rounding: decimal_js_1.default.ROUND_HALF_UP });
17
+ /**
18
+ * An amount of money, and the rules amounts follow
19
+ * - Every calculation is done in decimal, never in binary: a JavaScript number cannot hold 0.1 + 0.2 or 30 / 28, and an
20
+ * amount rounded after such a calculation can land on the wrong side of a rounding step
21
+ * - Immutable: every operation returns a new Money. An amount becomes a number again at the end of the calculation,
22
+ * through `round`, `roundDown` or `toNumber`
23
+ * - Amounts are rounded at the end of a calculation, never per item along the way: the items of a bill or an invoice are
24
+ * added up as they are, and the total is rounded once
25
+ * - This class exists twice, identically: here in @intelact/driveup (used by driveup-api) and in @driveup/common
26
+ * (used by driveup-schema), because neither package may depend on the other. Change one, change the other
27
+ */
28
+ class Money {
29
+ constructor(amount) {
30
+ _Money_instances.add(this);
31
+ this.amount = amount;
32
+ }
33
+ /**
34
+ * Reads an amount: a number, the string a DECIMAL column is read as, or another Money
35
+ * - A number is read to 15 significant digits, the precision a JavaScript number really has. What lies beyond is
36
+ * binary noise, and it must not survive: 0.1 + 0.2 is 0.30000000000000004, which would otherwise be rounded up a
37
+ * whole step. A string is read exactly, digit for digit
38
+ * - null, undefined and an empty string read as 0
39
+ * @param value Amount - The amount to read
40
+ * @returns Money - The amount
41
+ * @throws when the value is not a number, or is not finite: an amount is never NaN or Infinity
42
+ */
43
+ static of(value) {
44
+ if (value instanceof _a) {
45
+ return value;
46
+ }
47
+ if (value === null || value === undefined || value === '') {
48
+ return new _a(new decimal_js_1.default(0));
49
+ }
50
+ const amount = new decimal_js_1.default(typeof value === 'number' ? value.toPrecision(15) : String(value).trim());
51
+ if (!amount.isFinite()) {
52
+ throw new Error(`Money: ${value} is not a finite amount`);
53
+ }
54
+ return new _a(amount);
55
+ }
56
+ /**
57
+ * @param value Amount - The amount to add
58
+ * @returns Money - This amount plus the given one
59
+ */
60
+ add(value) {
61
+ return new _a(this.amount.plus(_a.of(value).amount));
62
+ }
63
+ /**
64
+ * @param value Amount - The amount to subtract
65
+ * @returns Money - This amount minus the given one
66
+ */
67
+ subtract(value) {
68
+ return new _a(this.amount.minus(_a.of(value).amount));
69
+ }
70
+ /**
71
+ * @param value Amount - The factor: an amount, or a plain number such as days or a quantity
72
+ * @returns Money - This amount times the given one
73
+ */
74
+ multiply(value) {
75
+ return new _a(this.amount.times(_a.of(value).amount));
76
+ }
77
+ /**
78
+ * @param value Amount - The divisor: an amount, or a plain number such as the days of a month
79
+ * @returns Money - This amount divided by the given one, to 40 significant digits
80
+ * @throws when the divisor is 0
81
+ */
82
+ divide(value) {
83
+ const divisor = _a.of(value);
84
+ if (divisor.amount.isZero()) {
85
+ throw new Error('Money: cannot divide by 0');
86
+ }
87
+ return new _a(this.amount.dividedBy(divisor.amount));
88
+ }
89
+ /**
90
+ * The tax due on this amount, unrounded
91
+ * - The tax of several items is calculated per item, added up, and rounded once at the end
92
+ * @param vat Amount - The tax rate in percent: 8.1 for 8.1%. null and undefined read as no tax
93
+ * @returns Money - The tax
94
+ */
95
+ tax(vat) {
96
+ return this.multiply(vat).divide(100);
97
+ }
98
+ /**
99
+ * The amount rounded up to the next multiple of 0.05
100
+ * - An amount above a multiple goes up to the next one: 0.06 becomes 0.10, 0.96 becomes 1.00 and 0.056 becomes 0.10.
101
+ * An amount that already is a multiple is kept. A negative amount is rounded away from zero
102
+ * - Only the first {@link noiseFreeDecimals} decimals decide: an amount is snapped to them first, so noise left by an
103
+ * earlier calculation cannot push an amount that sits on a multiple up a whole step
104
+ * @param step Amount - The step to round to, 0.05 by default. Pass {@link cent} for an amount stored per item
105
+ * @returns number - The amount, a multiple of the step
106
+ */
107
+ round(step = _a.step) {
108
+ return __classPrivateFieldGet(this, _Money_instances, "m", _Money_withoutNoise).call(this).toNearest(_a.of(step).amount, decimal_js_1.default.ROUND_UP).toNumber();
109
+ }
110
+ /**
111
+ * The amount rounded down to the multiple of 0.05 at or below it
112
+ * - The exception to rounding up, for an amount that is taken rather than charged: what a company pays is rounded up,
113
+ * but the credit taken from it is rounded down, so we never take credit it does not have. 12.29 of credit is taken
114
+ * as 12.25, and the 0.04 stays in the company's credit
115
+ * - A negative amount is rounded towards zero the same way, and noise is dropped first, as in {@link round}
116
+ * @param step Amount - The step to round to, 0.05 by default
117
+ * @returns number - The amount, a multiple of the step
118
+ */
119
+ roundDown(step = _a.step) {
120
+ return __classPrivateFieldGet(this, _Money_instances, "m", _Money_withoutNoise).call(this).toNearest(_a.of(step).amount, decimal_js_1.default.ROUND_DOWN).toNumber();
121
+ }
122
+ /**
123
+ * The amount as a number, unrounded
124
+ * @returns number - The amount
125
+ */
126
+ toNumber() {
127
+ return this.amount.toNumber();
128
+ }
129
+ }
130
+ exports.Money = Money;
131
+ _a = Money, _Money_instances = new WeakSet(), _Money_withoutNoise = function _Money_withoutNoise() {
132
+ return this.amount.toDecimalPlaces(_a.noiseFreeDecimals, decimal_js_1.default.ROUND_HALF_UP);
133
+ };
134
+ /**
135
+ * Every rounded total is a multiple of this step
136
+ */
137
+ Money.step = '0.05';
138
+ /**
139
+ * The step an amount is kept to when it is stored per item rather than charged: a bill item, an invoice line. Money
140
+ * columns hold 2 decimals, so an amount has to land on a cent before it is saved, while the totals it adds up to are
141
+ * rounded to {@link step}
142
+ */
143
+ Money.cent = '0.01';
144
+ /**
145
+ * The decimals a rounding looks at. Anything beyond is noise rather than money: our smallest real amount is a
146
+ * millionth (an amount of 2 decimals times a tax rate of 2 decimals), while the binary noise a JavaScript number
147
+ * carries into a calculation is never larger than a ten-billionth for amounts up to a million
148
+ */
149
+ Money.noiseFreeDecimals = 7;
150
+ //# sourceMappingURL=money.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"money.js","sourceRoot":"","sources":["../../src/utils/money.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,4DAAiC;AAEjC,iHAAiH;AACjH,iEAAiE;AACjE,oBAAO,CAAC,GAAG,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE,QAAQ,EAAE,oBAAO,CAAC,aAAa,EAAE,CAAC,CAAC;AAOhE;;;;;;;;;;GAUG;AACH,MAAa,KAAK;IAoBjB,YAAqC,MAAe;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a,CAAC,CAAC;AACpF,CAAC;AApID;;GAEG;AACa,UAAI,GAAG,MAAM,AAAT,CAAU;AAE9B;;;;GAIG;AACa,UAAI,GAAG,MAAM,AAAT,CAAU;AAE9B;;;;GAIG;AACqB,uBAAiB,GAAG,CAAC,AAAJ,CAAK"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intelact/driveup",
3
- "version": "2.4.8",
3
+ "version": "2.5.0",
4
4
  "description": "Driveup Common",
5
5
  "author": "Intelact Solutions Ltd.",
6
6
  "main": "lib/index.js",
@@ -27,6 +27,7 @@
27
27
  "@driveup/shared": "^0.2.34",
28
28
  "class-transformer": "^0.5.1",
29
29
  "class-validator": "^0.14.1",
30
+ "decimal.js": "^10.6.0",
30
31
  "luxon": "^3.5.0",
31
32
  "reflect-metadata": "^0.2.2",
32
33
  "tslib": "^2.8.1"