@bizmap/sdk 0.0.100 → 0.0.101

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/dist/main.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as z from 'zod';
2
- import { SafeOmit } from '@wavy/util';
2
+ import { SafeOmit, Prettify } from '@wavy/util';
3
3
 
4
4
  declare const companyUserRoles: z.ZodEnum<{
5
5
  doc: "doc";
@@ -956,7 +956,7 @@ declare const Reason: z.ZodObject<{
956
956
  declare const Version: z.ZodInt;
957
957
  declare const AlphaNumeric: z.ZodString;
958
958
 
959
- declare const PriceAdjustment: z.ZodObject<{
959
+ declare const PriceMod: z.ZodObject<{
960
960
  createdAt: z.ZodReadonly<z.ZodISODateTime>;
961
961
  lastModified: z.ZodOptional<z.ZodNullable<z.ZodISODateTime>>;
962
962
  description: z.ZodString;
@@ -969,7 +969,21 @@ declare const PriceAdjustment: z.ZodObject<{
969
969
  percentage: z.ZodNumber;
970
970
  isOptional: z.ZodBoolean;
971
971
  }, z.core.$strip>;
972
- type PriceAdjustment = z.infer<typeof PriceAdjustment>;
972
+ type PriceMod = z.infer<typeof PriceMod>;
973
+ declare const PriceModList: z.ZodRecord<z.ZodUUID, z.ZodObject<{
974
+ createdAt: z.ZodReadonly<z.ZodISODateTime>;
975
+ lastModified: z.ZodOptional<z.ZodNullable<z.ZodISODateTime>>;
976
+ description: z.ZodString;
977
+ fixedAmount: z.ZodObject<{
978
+ value: z.ZodNumber;
979
+ currency: z.ZodEnum<{
980
+ JMD: "JMD";
981
+ }>;
982
+ }, z.core.$strip>;
983
+ percentage: z.ZodNumber;
984
+ isOptional: z.ZodBoolean;
985
+ }, z.core.$strip>>;
986
+ type PriceModList = z.infer<typeof PriceModList>;
973
987
  declare const PriceTag: z.ZodObject<{
974
988
  createdAt: z.ZodReadonly<z.ZodISODateTime>;
975
989
  lastModified: z.ZodOptional<z.ZodNullable<z.ZodISODateTime>>;
@@ -1131,6 +1145,20 @@ declare const MiniAppointmentDetails: z.ZodObject<{
1131
1145
  percentage: z.ZodNumber;
1132
1146
  isOptional: z.ZodBoolean;
1133
1147
  }, z.core.$strip>>>>;
1148
+ payments: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodObject<{
1149
+ createdAt: z.ZodReadonly<z.ZodISODateTime>;
1150
+ lastModified: z.ZodOptional<z.ZodNullable<z.ZodISODateTime>>;
1151
+ uid: z.ZodUUID;
1152
+ method: z.ZodEnum<{
1153
+ cash: "cash";
1154
+ card: "card";
1155
+ insurance: "insurance";
1156
+ }>;
1157
+ currency: z.ZodEnum<{
1158
+ JMD: "JMD";
1159
+ }>;
1160
+ amount: z.ZodNumber;
1161
+ }, z.core.$strip>>>>;
1134
1162
  clientUid: z.ZodUUID;
1135
1163
  payload: z.ZodOptional<z.ZodNullable<z.ZodObject<{
1136
1164
  lastModified: z.ZodNullable<z.ZodNumber>;
@@ -1175,20 +1203,6 @@ declare const MiniAppointmentDetails: z.ZodObject<{
1175
1203
  physAsst: "physAsst";
1176
1204
  }>;
1177
1205
  }, z.core.$strip>>;
1178
- payments: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodObject<{
1179
- createdAt: z.ZodReadonly<z.ZodISODateTime>;
1180
- lastModified: z.ZodOptional<z.ZodNullable<z.ZodISODateTime>>;
1181
- uid: z.ZodUUID;
1182
- method: z.ZodEnum<{
1183
- cash: "cash";
1184
- card: "card";
1185
- insurance: "insurance";
1186
- }>;
1187
- currency: z.ZodEnum<{
1188
- JMD: "JMD";
1189
- }>;
1190
- amount: z.ZodNumber;
1191
- }, z.core.$strip>>>>;
1192
1206
  lockedBy: z.ZodOptional<z.ZodUUID>;
1193
1207
  timeline: z.ZodObject<{
1194
1208
  scheduler: z.ZodObject<{
@@ -1304,17 +1318,6 @@ declare const AppointmentDetails: z.ZodObject<{
1304
1318
  item: z.ZodString;
1305
1319
  cost: z.ZodNumber;
1306
1320
  }, z.core.$strip>>>>;
1307
- cancelled: z.ZodOptional<z.ZodObject<{
1308
- doneAt: z.ZodISODateTime;
1309
- reason: z.ZodObject<{
1310
- value: z.ZodString;
1311
- lastModified: z.ZodISODateTime;
1312
- }, z.core.$strip>;
1313
- doneBy: z.ZodEnum<{
1314
- doc: "doc";
1315
- physAsst: "physAsst";
1316
- }>;
1317
- }, z.core.$strip>>;
1318
1321
  payments: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodObject<{
1319
1322
  createdAt: z.ZodReadonly<z.ZodISODateTime>;
1320
1323
  lastModified: z.ZodOptional<z.ZodNullable<z.ZodISODateTime>>;
@@ -1329,6 +1332,17 @@ declare const AppointmentDetails: z.ZodObject<{
1329
1332
  }>;
1330
1333
  amount: z.ZodNumber;
1331
1334
  }, z.core.$strip>>>>;
1335
+ cancelled: z.ZodOptional<z.ZodObject<{
1336
+ doneAt: z.ZodISODateTime;
1337
+ reason: z.ZodObject<{
1338
+ value: z.ZodString;
1339
+ lastModified: z.ZodISODateTime;
1340
+ }, z.core.$strip>;
1341
+ doneBy: z.ZodEnum<{
1342
+ doc: "doc";
1343
+ physAsst: "physAsst";
1344
+ }>;
1345
+ }, z.core.$strip>>;
1332
1346
  lockedBy: z.ZodOptional<z.ZodUUID>;
1333
1347
  timeline: z.ZodObject<{
1334
1348
  scheduler: z.ZodObject<{
@@ -1483,17 +1497,6 @@ declare const MutableAppointmentDetails: z.ZodObject<{
1483
1497
  item: z.ZodString;
1484
1498
  cost: z.ZodNumber;
1485
1499
  }, z.core.$strip>>>>;
1486
- cancelled: z.ZodOptional<z.ZodObject<{
1487
- doneAt: z.ZodISODateTime;
1488
- reason: z.ZodObject<{
1489
- value: z.ZodString;
1490
- lastModified: z.ZodISODateTime;
1491
- }, z.core.$strip>;
1492
- doneBy: z.ZodEnum<{
1493
- doc: "doc";
1494
- physAsst: "physAsst";
1495
- }>;
1496
- }, z.core.$strip>>;
1497
1500
  payments: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodObject<{
1498
1501
  createdAt: z.ZodReadonly<z.ZodISODateTime>;
1499
1502
  lastModified: z.ZodOptional<z.ZodNullable<z.ZodISODateTime>>;
@@ -1508,6 +1511,17 @@ declare const MutableAppointmentDetails: z.ZodObject<{
1508
1511
  }>;
1509
1512
  amount: z.ZodNumber;
1510
1513
  }, z.core.$strip>>>>;
1514
+ cancelled: z.ZodOptional<z.ZodObject<{
1515
+ doneAt: z.ZodISODateTime;
1516
+ reason: z.ZodObject<{
1517
+ value: z.ZodString;
1518
+ lastModified: z.ZodISODateTime;
1519
+ }, z.core.$strip>;
1520
+ doneBy: z.ZodEnum<{
1521
+ doc: "doc";
1522
+ physAsst: "physAsst";
1523
+ }>;
1524
+ }, z.core.$strip>>;
1511
1525
  lockedBy: z.ZodOptional<z.ZodUUID>;
1512
1526
  timeline: z.ZodObject<{
1513
1527
  scheduler: z.ZodObject<{
@@ -1830,14 +1844,6 @@ declare function scheduleAppointment(request: RequestParameter): Promise<{
1830
1844
  cost: number;
1831
1845
  lastModified?: string | null | undefined;
1832
1846
  }> | null | undefined;
1833
- cancelled?: {
1834
- doneAt: string;
1835
- reason: {
1836
- value: string;
1837
- lastModified: string;
1838
- };
1839
- doneBy: "doc" | "physAsst";
1840
- } | undefined;
1841
1847
  payments?: {
1842
1848
  createdAt: string;
1843
1849
  uid: string;
@@ -1846,12 +1852,23 @@ declare function scheduleAppointment(request: RequestParameter): Promise<{
1846
1852
  amount: number;
1847
1853
  lastModified?: string | null | undefined;
1848
1854
  }[] | null | undefined;
1855
+ cancelled?: {
1856
+ doneAt: string;
1857
+ reason: {
1858
+ value: string;
1859
+ lastModified: string;
1860
+ };
1861
+ doneBy: "doc" | "physAsst";
1862
+ } | undefined;
1849
1863
  lockedBy?: string | undefined;
1850
1864
  };
1851
1865
  }>;
1852
1866
 
1853
1867
  /** @disclaimer This doesn't handle currency conversion */
1854
- declare function calcAppointmentFee(appointment: Pick<AppointmentDetails, "charges" | "discounts" | "additionalFees" | "prepayments">): number;
1868
+ declare function calcBalance(components: Prettify<Partial<Pick<AppointmentDetails, "charges" | "discounts" | "additionalFees" | "prepayments" | "payments">>>, options?: {
1869
+ logger?: boolean;
1870
+ }): number;
1871
+ declare const calcPriceMod: (mods: PriceModList | null | undefined, subtotal: number) => number;
1855
1872
 
1856
1873
  /**
1857
1874
  * @param {CompanyUserRole} role The role used to filter the staff members
@@ -1914,4 +1931,4 @@ declare function createNotifId(options?: {
1914
1931
  to: string;
1915
1932
  }): string;
1916
1933
 
1917
- export { type AcceptedCurrency, AlphaNumeric, AppointmentDetails, type AppointmentDistAlg, ClientForm, ClientIdentity, CompanyBilling, CompanyDetails, CompanyIdentity, CompanyInviteList, CompanyNotifications, type CompanyPartnerRole, CompanyPreferences, type CompanyServiceSelector, CompanyStaff, CompanyState, CompanyUser, type CompanyUserRole, CompanyUserSession, type CompanyUserStatus, CreateCompanyForm, CreditCurrency, type EmployeeRole, type Gender, type HealthcareProviderRole, type Industry, InviteResponse, InvoiceNo, MedicalDetails, Medicine, MiniAppointmentDetails, MiniCompanyUser, MutableAppointmentDetails, MutableCompanyBilling, MutableCompanyDetails, MutableCompanyIdentity, MutableCompanyPreferences, Notification, PaymentDetails, type PaymentMethod, PriceAdjustment, PriceTag, Reason, Receipts, ScheduleAppointmentForm, StandardTime, TicketNo, type Tier, TierList, TimeLog, Timestamp, Trn, UserDetails, Version, Vitals, acceptedCurrencies, adminRoles, appointmentDistAlgs, calcAppointmentFee, companyPartnerRoles, companyServiceSelectors, companyUserRoles, companyUserStatus, createNotifId, employeeRoles, findAvailableStaff, findConflictingPartners, findNextAvailableStaff, genders, getCompatibleRoles, healthcareProviderRoles, industries, normalizeCompanyId, normalizeNidKey, parseClientName, paymentMethods, scheduleAppointment, serviceProviders, tiers, vitalKeys };
1934
+ export { type AcceptedCurrency, AlphaNumeric, AppointmentDetails, type AppointmentDistAlg, ClientForm, ClientIdentity, CompanyBilling, CompanyDetails, CompanyIdentity, CompanyInviteList, CompanyNotifications, type CompanyPartnerRole, CompanyPreferences, type CompanyServiceSelector, CompanyStaff, CompanyState, CompanyUser, type CompanyUserRole, CompanyUserSession, type CompanyUserStatus, CreateCompanyForm, CreditCurrency, type EmployeeRole, type Gender, type HealthcareProviderRole, type Industry, InviteResponse, InvoiceNo, MedicalDetails, Medicine, MiniAppointmentDetails, MiniCompanyUser, MutableAppointmentDetails, MutableCompanyBilling, MutableCompanyDetails, MutableCompanyIdentity, MutableCompanyPreferences, Notification, PaymentDetails, type PaymentMethod, PriceMod, PriceModList, PriceTag, Reason, Receipts, ScheduleAppointmentForm, StandardTime, TicketNo, type Tier, TierList, TimeLog, Timestamp, Trn, UserDetails, Version, Vitals, acceptedCurrencies, adminRoles, appointmentDistAlgs, calcBalance, calcPriceMod, companyPartnerRoles, companyServiceSelectors, companyUserRoles, companyUserStatus, createNotifId, employeeRoles, findAvailableStaff, findConflictingPartners, findNextAvailableStaff, genders, getCompatibleRoles, healthcareProviderRoles, industries, normalizeCompanyId, normalizeNidKey, parseClientName, paymentMethods, scheduleAppointment, serviceProviders, tiers, vitalKeys };
package/dist/main.js CHANGED
@@ -104,7 +104,7 @@ var AlphaNumeric = z5.string().trim().superRefine((data, ctx) => {
104
104
  });
105
105
 
106
106
  // src/schemas/utils/billing.ts
107
- var PriceAdjustment = z6.object({
107
+ var PriceMod = z6.object({
108
108
  description: z6.string().trim().min(3, "A description must have atleast (3) characters.").max(25, "A description can't have more that (25) characters.").superRefine((data, ctx) => {
109
109
  const invalidCharIdx = data.search(/[^a-zA-Z0-9-\.:\(\)]/);
110
110
  if (invalidCharIdx > -1) {
@@ -119,6 +119,7 @@ var PriceAdjustment = z6.object({
119
119
  isOptional: z6.boolean(),
120
120
  ...TimeLog.shape
121
121
  });
122
+ var PriceModList = z6.record(z6.uuidv4(), PriceMod);
122
123
  var PriceTag = z6.object({
123
124
  uid: z6.uuidv4(),
124
125
  /**The name of the item that's being priced */
@@ -178,16 +179,16 @@ var CompanyState = z7.object({
178
179
  });
179
180
 
180
181
  // src/schemas/company/components/Billing.ts
181
- var createAdjustments = (resource) => z8.record(z8.uuidv4(), PriceAdjustment).refine(
182
+ var createMod = (resource) => PriceModList.refine(
182
183
  (d) => Object.values(d).length <= 100,
183
184
  `Adding more than 100 ${resource}s is prohibited.`
184
185
  );
185
186
  var CompanyBilling = z8.object({
186
187
  _id: CompanyState.shape._id,
187
- additionalFees: createAdjustments("additional fee"),
188
- discounts: createAdjustments("discount"),
188
+ additionalFees: createMod("additional fee"),
189
+ discounts: createMod("discount"),
189
190
  /** Optionally deductable from bills */
190
- prepayments: createAdjustments("pre-payment"),
191
+ prepayments: createMod("pre-payment"),
191
192
  offeredServices: z8.record(z8.uuidv4(), PriceTag.omit({ uid: true })).superRefine((data, ctx) => {
192
193
  const services = Object.entries(data);
193
194
  if (services.length > 150) {
@@ -777,21 +778,25 @@ var MedicalDetails = z20.object({
777
778
  import { sumOf as sumOf2 } from "@wavy/fn";
778
779
  import * as z21 from "zod";
779
780
 
780
- // src/functions/calcAppointmentFee.ts
781
+ // src/functions/calculations.ts
781
782
  import { sumOf } from "@wavy/fn";
782
- function calcAppointmentFee(appointment) {
783
+ function calcBalance(components, options) {
783
784
  const subtotal = sumOf(
784
- Object.values(appointment.charges || {})?.map((c) => c.cost)
785
+ Object.values(components.charges || {})?.map((c) => c.cost)
785
786
  );
786
- const discount = calcAdjustment(appointment.discounts, subtotal);
787
- const additionalFees = calcAdjustment(appointment.additionalFees, subtotal);
788
- const prepayments = calcAdjustment(appointment.prepayments, subtotal);
789
- console.log({ subtotal, discount, additionalFees, prepayments });
790
- return subtotal + additionalFees - (discount + prepayments);
787
+ const discount = calcPriceMod(components.discounts, subtotal);
788
+ const additionalFees = calcPriceMod(components.additionalFees, subtotal);
789
+ const prepayments = calcPriceMod(components.prepayments, subtotal);
790
+ const payments = sumOf(components.payments?.map((p) => p.amount) ?? []);
791
+ const result = subtotal + additionalFees - (discount + prepayments + payments);
792
+ if (options?.logger) {
793
+ console.log({ subtotal, discount, additionalFees, prepayments, result });
794
+ }
795
+ return result;
791
796
  }
792
- var calcAdjustment = (adjustments, subtotal) => {
793
- const castedAdjustments = !adjustments ? [] : Object.values(adjustments);
794
- if (!adjustments || castedAdjustments.length < 1) return 0;
797
+ var calcPriceMod = (mods, subtotal) => {
798
+ const castedAdjustments = !mods ? [] : Object.values(mods);
799
+ if (!mods || castedAdjustments.length < 1) return 0;
795
800
  return sumOf(
796
801
  castedAdjustments?.map(
797
802
  (d) => (d.fixedAmount?.value || 0) + (d.percentage ? d.percentage * 0.01 * subtotal : 0)
@@ -835,6 +840,7 @@ var MiniAppointmentDetails = z21.object({
835
840
  /**Required to calculate the accurate grandTotal of the charges */
836
841
  discounts: CompanyBilling.shape.discounts.nullish(),
837
842
  prepayments: CompanyBilling.shape.prepayments.nullish(),
843
+ payments: z21.array(PaymentDetails).max(100).nullish(),
838
844
  /** The client's identity */
839
845
  clientUid: ClientIdentity.shape._id,
840
846
  /**
@@ -852,9 +858,8 @@ var MiniAppointmentDetails = z21.object({
852
858
  reason: Reason,
853
859
  doneBy: companyUserRoles.extract(["doc", "physAsst"])
854
860
  }).optional(),
855
- /** Add this after consulting with company owners about payment expectations */
861
+ //** Add this after consulting with company owners about payment expectations */
856
862
  // paymentDueDate: Timestamp.nullish(),
857
- payments: z21.array(PaymentDetails).max(100).nullish(),
858
863
  // The user that is currently modifying the appointment
859
864
  lockedBy: UserDetails.shape._id.optional(),
860
865
  timeline: z21.object({
@@ -872,7 +877,7 @@ var MiniAppointmentDetails = z21.object({
872
877
  }),
873
878
  ...TimeLog.shape
874
879
  }).superRefine((data, ctx) => {
875
- if (data.payments && data.charges && sumOf2(data.payments.map((p) => p.amount)) >= calcAppointmentFee(data)) {
880
+ if (data.payments && data.charges && sumOf2(data.payments.map((p) => p.amount)) >= calcBalance(data)) {
876
881
  const untrackedPayment = data.payments.find(
877
882
  (p) => !data.timeline.debtCollector?.some(
878
883
  (d) => p.uid in d.collectedPayments
@@ -1133,7 +1138,8 @@ export {
1133
1138
  MutableCompanyPreferences,
1134
1139
  Notification,
1135
1140
  PaymentDetails,
1136
- PriceAdjustment,
1141
+ PriceMod,
1142
+ PriceModList,
1137
1143
  PriceTag,
1138
1144
  Reason,
1139
1145
  Receipts,
@@ -1150,7 +1156,8 @@ export {
1150
1156
  acceptedCurrencies,
1151
1157
  adminRoles,
1152
1158
  appointmentDistAlgs,
1153
- calcAppointmentFee,
1159
+ calcBalance,
1160
+ calcPriceMod,
1154
1161
  companyPartnerRoles,
1155
1162
  companyServiceSelectors,
1156
1163
  companyUserRoles,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bizmap/sdk",
3
- "version": "0.0.100",
3
+ "version": "0.0.101",
4
4
  "main": "./dist/main.js",
5
5
  "types": "./dist/main.d.ts",
6
6
  "type": "module",