@jsdev_ninja/core 0.11.7 → 0.11.9

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.
@@ -836,6 +836,8 @@ export declare const OrderSchema: z.ZodObject<{
836
836
  apartmentNumber: string;
837
837
  } | undefined;
838
838
  }>;
839
+ nameOnInvoice: z.ZodOptional<z.ZodString>;
840
+ clientComment: z.ZodOptional<z.ZodString>;
839
841
  }, "strip", z.ZodTypeAny, {
840
842
  type: "Order";
841
843
  status: "draft" | "completed" | "pending" | "processing" | "in_delivery" | "delivered" | "cancelled" | "refunded";
@@ -973,6 +975,8 @@ export declare const OrderSchema: z.ZodObject<{
973
975
  actualAmount?: number | undefined;
974
976
  deliveryDate?: number | undefined;
975
977
  createdAt?: number | undefined;
978
+ nameOnInvoice?: string | undefined;
979
+ clientComment?: string | undefined;
976
980
  }, {
977
981
  type: "Order";
978
982
  status: "draft" | "completed" | "pending" | "processing" | "in_delivery" | "delivered" | "cancelled" | "refunded";
@@ -1110,6 +1114,8 @@ export declare const OrderSchema: z.ZodObject<{
1110
1114
  actualAmount?: number | undefined;
1111
1115
  deliveryDate?: number | undefined;
1112
1116
  createdAt?: number | undefined;
1117
+ nameOnInvoice?: string | undefined;
1118
+ clientComment?: string | undefined;
1113
1119
  }>;
1114
1120
  export type TOrder = z.infer<typeof OrderSchema>;
1115
1121
  //# sourceMappingURL=Order.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Order.d.ts","sourceRoot":"","sources":["../../lib/entities/Order.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAcxB,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAgCtB,CAAC;AAEH,MAAM,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,CAAC"}
@@ -38,4 +38,6 @@ export const OrderSchema = z.object({
38
38
  deliveryDate: z.coerce.number().optional(),
39
39
  createdAt: z.number().optional(),
40
40
  client: ProfileSchema.required({}),
41
+ nameOnInvoice: z.string().optional(),
42
+ clientComment: z.string().optional(),
41
43
  });
@@ -11,7 +11,8 @@ declare const StoreSchema: z.ZodObject<{
11
11
  isVatIncludedInPrice: z.ZodBoolean;
12
12
  clientTypes: z.ZodArray<z.ZodEnum<["individual", "company"]>, "many">;
13
13
  minimumOrder: z.ZodOptional<z.ZodNumber>;
14
- freeOrderPrice: z.ZodOptional<z.ZodNumber>;
14
+ freeDeliveryPrice: z.ZodOptional<z.ZodNumber>;
15
+ deliveryPrice: z.ZodOptional<z.ZodNumber>;
15
16
  }, "strip", z.ZodTypeAny, {
16
17
  id: string;
17
18
  companyId: string;
@@ -24,7 +25,8 @@ declare const StoreSchema: z.ZodObject<{
24
25
  isVatIncludedInPrice: boolean;
25
26
  clientTypes: ("company" | "individual")[];
26
27
  minimumOrder?: number | undefined;
27
- freeOrderPrice?: number | undefined;
28
+ freeDeliveryPrice?: number | undefined;
29
+ deliveryPrice?: number | undefined;
28
30
  }, {
29
31
  id: string;
30
32
  companyId: string;
@@ -37,7 +39,8 @@ declare const StoreSchema: z.ZodObject<{
37
39
  isVatIncludedInPrice: boolean;
38
40
  clientTypes: ("company" | "individual")[];
39
41
  minimumOrder?: number | undefined;
40
- freeOrderPrice?: number | undefined;
42
+ freeDeliveryPrice?: number | undefined;
43
+ deliveryPrice?: number | undefined;
41
44
  }>;
42
45
  export type TStore = z.infer<typeof StoreSchema>;
43
46
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"Store.d.ts","sourceRoot":"","sources":["../../lib/entities/Store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,QAAA,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAaf,CAAC;AACH,MAAM,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,CAAC"}
1
+ {"version":3,"file":"Store.d.ts","sourceRoot":"","sources":["../../lib/entities/Store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,QAAA,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAcf,CAAC;AACH,MAAM,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,CAAC"}
@@ -12,5 +12,6 @@ const StoreSchema = z.object({
12
12
  isVatIncludedInPrice: z.boolean(),
13
13
  clientTypes: z.array(clientTypesSchema),
14
14
  minimumOrder: z.number().optional(),
15
- freeOrderPrice: z.number().optional(),
15
+ freeDeliveryPrice: z.number().optional(),
16
+ deliveryPrice: z.number().optional(),
16
17
  });
@@ -8,6 +8,8 @@ export declare function getCartCost({ cart, discounts, store, }: {
8
8
  cost: number;
9
9
  finalCost: number;
10
10
  vat: number;
11
+ productsCost: number;
12
+ deliveryPrice: number;
11
13
  items: {
12
14
  amount: number;
13
15
  product: {
@@ -102,10 +104,4 @@ export declare function getCartCost({ cart, discounts, store, }: {
102
104
  finalDiscount: number;
103
105
  }[];
104
106
  };
105
- export declare function calculateCartPrice(items: TCart["items"]): {
106
- cost: number;
107
- discount: number;
108
- vat: number;
109
- finalCost: number;
110
- };
111
107
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,SAAS,EAAY,MAAM,EAAE,MAAM,aAAa,CAAC;AA6BjE,wBAAgB,WAAW,CAAC,EAC3B,IAAI,EACJ,SAAS,EACT,KAAK,GACL,EAAE;IACF,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;IACrB,SAAS,EAAE,SAAS,EAAE,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;CACd;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAyIA;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC;;;;;EA4BvD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,SAAS,EAAY,MAAM,EAAE,MAAM,aAAa,CAAC;AA6BjE,wBAAgB,WAAW,CAAC,EAC3B,IAAI,EACJ,SAAS,EACT,KAAK,GACL,EAAE;IACF,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;IACrB,SAAS,EAAE,SAAS,EAAE,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;CACd;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAmJA"}
@@ -81,6 +81,7 @@ export function getCartCost({ cart, discounts, store, }) {
81
81
  ...item,
82
82
  finalPrice: averagePrice,
83
83
  originalPrice: item.product.price,
84
+ discountPrice: price,
84
85
  finalDiscount: item.product.price - averagePrice,
85
86
  };
86
87
  }
@@ -114,36 +115,22 @@ export function getCartCost({ cart, discounts, store, }) {
114
115
  acc.cost += amount * finalPrice;
115
116
  acc.discount += finalDiscount ? amount * finalDiscount : finalDiscount;
116
117
  acc.finalCost += amount * finalPrice + (isVatIncludedInPrice ? 0 : productVatValue);
118
+ acc.productsCost += amount * finalPrice + (isVatIncludedInPrice ? 0 : productVatValue);
117
119
  return acc;
118
120
  }, {
119
121
  discount: 0,
120
122
  cost: 0,
121
123
  finalCost: 0,
122
124
  vat: 0,
125
+ productsCost: 0,
126
+ deliveryPrice: store?.deliveryPrice ?? 0,
123
127
  });
128
+ if (cartDetails.deliveryPrice && cartDetails.productsCost >= (store.freeDeliveryPrice ?? 0)) {
129
+ cartDetails.deliveryPrice = 0;
130
+ }
131
+ else {
132
+ cartDetails.finalCost += cartDetails.deliveryPrice;
133
+ }
124
134
  console.log("cartDetails", cartDetails);
125
135
  return { items: result, ...cartDetails };
126
136
  }
127
- export function calculateCartPrice(items) {
128
- return (items ?? []).reduce((acc, item) => {
129
- const { product, amount } = item;
130
- const productPrice = getPriceAfterDiscount(product);
131
- const discount = calculateDiscount(product);
132
- const realPrice = product.price - discount;
133
- let productVatValue = 0;
134
- if (product.vat) {
135
- productVatValue = (realPrice * CONFIG.VAT) / 100;
136
- productVatValue = productVatValue * amount;
137
- acc.vat += productVatValue;
138
- }
139
- acc.cost += amount * product.price;
140
- acc.discount += discount ? amount * discount : discount;
141
- acc.finalCost += amount * productPrice + productVatValue;
142
- return acc;
143
- }, {
144
- cost: 0,
145
- discount: 0,
146
- vat: 0,
147
- finalCost: 0,
148
- });
149
- }
@@ -42,6 +42,8 @@ export const OrderSchema = z.object({
42
42
  deliveryDate: z.coerce.number().optional(),
43
43
  createdAt: z.number().optional(),
44
44
  client: ProfileSchema.required({}),
45
+ nameOnInvoice: z.string().optional(),
46
+ clientComment: z.string().optional(),
45
47
  });
46
48
 
47
49
  export type TOrder = z.infer<typeof OrderSchema>;
@@ -13,6 +13,7 @@ const StoreSchema = z.object({
13
13
  isVatIncludedInPrice: z.boolean(),
14
14
  clientTypes: z.array(clientTypesSchema),
15
15
  minimumOrder: z.number().optional(),
16
- freeOrderPrice: z.number().optional(),
16
+ freeDeliveryPrice: z.number().optional(),
17
+ deliveryPrice: z.number().optional(),
17
18
  });
18
19
  export type TStore = z.infer<typeof StoreSchema>;
@@ -111,6 +111,7 @@ export function getCartCost({
111
111
  ...item,
112
112
  finalPrice: averagePrice,
113
113
  originalPrice: item.product.price,
114
+ discountPrice: price,
114
115
  finalDiscount: item.product.price - averagePrice,
115
116
  };
116
117
  }
@@ -158,6 +159,7 @@ export function getCartCost({
158
159
  acc.cost += amount * finalPrice;
159
160
  acc.discount += finalDiscount ? amount * finalDiscount : finalDiscount;
160
161
  acc.finalCost += amount * finalPrice + (isVatIncludedInPrice ? 0 : productVatValue);
162
+ acc.productsCost += amount * finalPrice + (isVatIncludedInPrice ? 0 : productVatValue);
161
163
 
162
164
  return acc;
163
165
  },
@@ -166,40 +168,18 @@ export function getCartCost({
166
168
  cost: 0,
167
169
  finalCost: 0,
168
170
  vat: 0,
171
+ productsCost: 0,
172
+ deliveryPrice: store?.deliveryPrice ?? 0,
169
173
  }
170
174
  );
171
175
 
176
+ if (cartDetails.deliveryPrice && cartDetails.productsCost >= (store.freeDeliveryPrice ?? 0)) {
177
+ cartDetails.deliveryPrice = 0;
178
+ } else {
179
+ cartDetails.finalCost += cartDetails.deliveryPrice;
180
+ }
181
+
172
182
  console.log("cartDetails", cartDetails);
173
183
 
174
184
  return { items: result, ...cartDetails };
175
185
  }
176
-
177
- export function calculateCartPrice(items: TCart["items"]) {
178
- return (items ?? []).reduce(
179
- (acc, item) => {
180
- const { product, amount } = item;
181
- const productPrice = getPriceAfterDiscount(product);
182
- const discount = calculateDiscount(product);
183
-
184
- const realPrice = product.price - discount;
185
-
186
- let productVatValue: number = 0;
187
- if (product.vat) {
188
- productVatValue = (realPrice * CONFIG.VAT) / 100;
189
- productVatValue = productVatValue * amount;
190
- acc.vat += productVatValue;
191
- }
192
- acc.cost += amount * product.price;
193
- acc.discount += discount ? amount * discount : discount;
194
- acc.finalCost += amount * productPrice + productVatValue;
195
-
196
- return acc;
197
- },
198
- {
199
- cost: 0,
200
- discount: 0,
201
- vat: 0,
202
- finalCost: 0,
203
- }
204
- );
205
- }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsdev_ninja/core",
3
- "version": "0.11.7",
3
+ "version": "0.11.9",
4
4
  "main": "dist/core.cjs.js",
5
5
  "module": "dist/core.es.js",
6
6
  "types": "dist/index.d.ts",