addio-admin-sdk 1.7.103 → 1.7.104

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.
Files changed (323) hide show
  1. package/dist/Interfaces/Attribute/index.d.ts +1 -0
  2. package/dist/Interfaces/CMS/index.d.ts +3 -0
  3. package/dist/Interfaces/CMS/index.js +3 -0
  4. package/dist/Interfaces/CMS/index.js.map +1 -1
  5. package/dist/Interfaces/Cart/index.js +6 -2
  6. package/dist/Interfaces/Cart/index.js.map +1 -1
  7. package/dist/Interfaces/CartReservedQuantities/index.d.ts +2 -0
  8. package/dist/Interfaces/Customer/IStoreCredit.d.ts +1 -0
  9. package/dist/Interfaces/Customer/index.d.ts +7 -0
  10. package/dist/Interfaces/Customer/index.js +7 -0
  11. package/dist/Interfaces/Customer/index.js.map +1 -1
  12. package/dist/Interfaces/Declination/index.js +8 -2
  13. package/dist/Interfaces/Declination/index.js.map +1 -1
  14. package/dist/Interfaces/Email/IEmail.js +7 -3
  15. package/dist/Interfaces/Email/IEmail.js.map +1 -1
  16. package/dist/Interfaces/G2/index.js +2 -0
  17. package/dist/Interfaces/G2/index.js.map +1 -1
  18. package/dist/Interfaces/Indexed/Product/index.d.ts +3 -0
  19. package/dist/Interfaces/Indexed/Product/index.js +43 -2
  20. package/dist/Interfaces/Indexed/Product/index.js.map +1 -1
  21. package/dist/Interfaces/Menu/index.d.ts +11 -0
  22. package/dist/Interfaces/Product/IImportProduct.js +94 -3
  23. package/dist/Interfaces/Product/IImportProduct.js.map +1 -1
  24. package/dist/Interfaces/Product/IInventoryItem.d.ts +11 -27
  25. package/dist/Interfaces/Product/IInventoryItem.js +13 -4
  26. package/dist/Interfaces/Product/IInventoryItem.js.map +1 -1
  27. package/dist/Interfaces/Product/IPricing.js +6 -0
  28. package/dist/Interfaces/Product/IPricing.js.map +1 -1
  29. package/dist/Interfaces/Product/index.d.ts +8 -0
  30. package/dist/Interfaces/Product/index.js +8 -0
  31. package/dist/Interfaces/Product/index.js.map +1 -1
  32. package/dist/Interfaces/PromiseToPurchase/IIndexedBankUsed.js +1 -1
  33. package/dist/Interfaces/PromiseToPurchase/IIndexedBankUsed.js.map +1 -1
  34. package/dist/Interfaces/Rules/IDiscountRule.d.ts +18 -0
  35. package/dist/Interfaces/Rules/IDiscountRule.js +19 -0
  36. package/dist/Interfaces/Rules/IDiscountRule.js.map +1 -1
  37. package/dist/Interfaces/Services/IService.d.ts +4 -0
  38. package/dist/Interfaces/Shipping/Shiptime/order.js +23 -0
  39. package/dist/Interfaces/Shipping/Shiptime/order.js.map +1 -1
  40. package/dist/Interfaces/Space/index.d.ts +8 -0
  41. package/dist/Interfaces/Space/index.js +9 -0
  42. package/dist/Interfaces/Space/index.js.map +1 -1
  43. package/dist/Interfaces/TCG/index.d.ts +12 -1
  44. package/dist/Interfaces/TCG/index.js +11 -0
  45. package/dist/Interfaces/TCG/index.js.map +1 -1
  46. package/dist/Interfaces/TransferRequest/index.js +3 -0
  47. package/dist/Interfaces/TransferRequest/index.js.map +1 -1
  48. package/dist/constants/services.js +1 -0
  49. package/dist/constants/services.js.map +1 -1
  50. package/dist/index.d.ts +18 -0
  51. package/dist/index.js +24 -0
  52. package/dist/index.js.map +1 -1
  53. package/dist/lib/Attribute/index.js +43 -0
  54. package/dist/lib/Attribute/index.js.map +1 -1
  55. package/dist/lib/BGJob/index.js +5 -1
  56. package/dist/lib/BGJob/index.js.map +1 -1
  57. package/dist/lib/Booking/index.d.ts +15 -0
  58. package/dist/lib/Booking/index.js +20 -0
  59. package/dist/lib/Booking/index.js.map +1 -1
  60. package/dist/lib/Brand/index.d.ts +9 -0
  61. package/dist/lib/Brand/index.js +18 -0
  62. package/dist/lib/Brand/index.js.map +1 -1
  63. package/dist/lib/Cart/index.d.ts +99 -0
  64. package/dist/lib/Cart/index.js +498 -9
  65. package/dist/lib/Cart/index.js.map +1 -1
  66. package/dist/lib/CartReservedQuantities/index.d.ts +29 -0
  67. package/dist/lib/CartReservedQuantities/index.js +41 -0
  68. package/dist/lib/CartReservedQuantities/index.js.map +1 -1
  69. package/dist/lib/Catalogue/index.d.ts +6 -0
  70. package/dist/lib/Catalogue/index.js +9 -0
  71. package/dist/lib/Catalogue/index.js.map +1 -1
  72. package/dist/lib/Category/index.d.ts +6 -0
  73. package/dist/lib/Category/index.js +15 -0
  74. package/dist/lib/Category/index.js.map +1 -1
  75. package/dist/lib/Class/index.d.ts +4 -0
  76. package/dist/lib/Class/index.js +8 -0
  77. package/dist/lib/Class/index.js.map +1 -1
  78. package/dist/lib/Customer/index.d.ts +12 -0
  79. package/dist/lib/Customer/index.js +13 -0
  80. package/dist/lib/Customer/index.js.map +1 -1
  81. package/dist/lib/Declination/index.js +2 -0
  82. package/dist/lib/Declination/index.js.map +1 -1
  83. package/dist/lib/Discount/index.d.ts +9 -0
  84. package/dist/lib/Discount/index.js +23 -0
  85. package/dist/lib/Discount/index.js.map +1 -1
  86. package/dist/lib/ElasticSearch/index.d.ts +5 -0
  87. package/dist/lib/ElasticSearch/index.js +5 -0
  88. package/dist/lib/ElasticSearch/index.js.map +1 -1
  89. package/dist/lib/Elavon/index.js +5 -0
  90. package/dist/lib/Elavon/index.js.map +1 -1
  91. package/dist/lib/Email/AbandonedCartEmail.d.ts +8 -0
  92. package/dist/lib/Email/AbandonedCartEmail.js +8 -0
  93. package/dist/lib/Email/AbandonedCartEmail.js.map +1 -1
  94. package/dist/lib/Email/AccountConfirmationEmail.d.ts +8 -0
  95. package/dist/lib/Email/AccountConfirmationEmail.js +8 -0
  96. package/dist/lib/Email/AccountConfirmationEmail.js.map +1 -1
  97. package/dist/lib/Email/AdminOrderConfirmationEmail.d.ts +8 -0
  98. package/dist/lib/Email/AdminOrderConfirmationEmail.js +8 -0
  99. package/dist/lib/Email/AdminOrderConfirmationEmail.js.map +1 -1
  100. package/dist/lib/Email/ApplicationEmail.d.ts +8 -0
  101. package/dist/lib/Email/ApplicationEmail.js +8 -0
  102. package/dist/lib/Email/ApplicationEmail.js.map +1 -1
  103. package/dist/lib/Email/BackInStockEmail.d.ts +8 -0
  104. package/dist/lib/Email/BackInStockEmail.js +8 -0
  105. package/dist/lib/Email/BackInStockEmail.js.map +1 -1
  106. package/dist/lib/Email/ContactEmail.d.ts +8 -0
  107. package/dist/lib/Email/ContactEmail.js +8 -0
  108. package/dist/lib/Email/ContactEmail.js.map +1 -1
  109. package/dist/lib/Email/CustomerBookingAdminEmail.d.ts +8 -0
  110. package/dist/lib/Email/CustomerBookingAdminEmail.js +8 -0
  111. package/dist/lib/Email/CustomerBookingAdminEmail.js.map +1 -1
  112. package/dist/lib/Email/CustomerBookingEmail.d.ts +8 -0
  113. package/dist/lib/Email/CustomerBookingEmail.js +8 -0
  114. package/dist/lib/Email/CustomerBookingEmail.js.map +1 -1
  115. package/dist/lib/Email/OrderConfirmationEmail.d.ts +8 -0
  116. package/dist/lib/Email/OrderConfirmationEmail.js +8 -0
  117. package/dist/lib/Email/OrderConfirmationEmail.js.map +1 -1
  118. package/dist/lib/Email/OrderDenounciationEmail.d.ts +8 -0
  119. package/dist/lib/Email/OrderDenounciationEmail.js +8 -0
  120. package/dist/lib/Email/OrderDenounciationEmail.js.map +1 -1
  121. package/dist/lib/Email/OrderSampleEmail.d.ts +8 -0
  122. package/dist/lib/Email/OrderSampleEmail.js +8 -0
  123. package/dist/lib/Email/OrderSampleEmail.js.map +1 -1
  124. package/dist/lib/Email/OtherTypeEmails.d.ts +8 -0
  125. package/dist/lib/Email/OtherTypeEmails.js +8 -0
  126. package/dist/lib/Email/OtherTypeEmails.js.map +1 -1
  127. package/dist/lib/Email/PasswordResetEmail.d.ts +8 -0
  128. package/dist/lib/Email/PasswordResetEmail.js +8 -0
  129. package/dist/lib/Email/PasswordResetEmail.js.map +1 -1
  130. package/dist/lib/Email/PhotoShootEmail.d.ts +8 -0
  131. package/dist/lib/Email/PhotoShootEmail.js +8 -0
  132. package/dist/lib/Email/PhotoShootEmail.js.map +1 -1
  133. package/dist/lib/Email/PickUpConfirmation.d.ts +8 -0
  134. package/dist/lib/Email/PickUpConfirmation.js +8 -0
  135. package/dist/lib/Email/PickUpConfirmation.js.map +1 -1
  136. package/dist/lib/Email/ShippingConfirmation.d.ts +8 -0
  137. package/dist/lib/Email/ShippingConfirmation.js +8 -0
  138. package/dist/lib/Email/ShippingConfirmation.js.map +1 -1
  139. package/dist/lib/Email/WelcomeEmail.d.ts +8 -0
  140. package/dist/lib/Email/WelcomeEmail.js +8 -0
  141. package/dist/lib/Email/WelcomeEmail.js.map +1 -1
  142. package/dist/lib/Email/index.d.ts +8 -0
  143. package/dist/lib/Email/index.js +8 -0
  144. package/dist/lib/Email/index.js.map +1 -1
  145. package/dist/lib/ExternalService/Ebay.d.ts +12 -0
  146. package/dist/lib/ExternalService/Ebay.js +22 -0
  147. package/dist/lib/ExternalService/Ebay.js.map +1 -1
  148. package/dist/lib/Indexed/IndexedCart.js +5 -0
  149. package/dist/lib/Indexed/IndexedCart.js.map +1 -1
  150. package/dist/lib/Indexed/Product.js +50 -0
  151. package/dist/lib/Indexed/Product.js.map +1 -1
  152. package/dist/lib/Inventory/index.d.ts +59 -0
  153. package/dist/lib/Inventory/index.js +157 -9
  154. package/dist/lib/Inventory/index.js.map +1 -1
  155. package/dist/lib/Invoice/index.d.ts +11 -0
  156. package/dist/lib/Invoice/index.js +11 -0
  157. package/dist/lib/Invoice/index.js.map +1 -1
  158. package/dist/lib/MarketplacePublication/index.js +308 -0
  159. package/dist/lib/MarketplacePublication/index.js.map +1 -1
  160. package/dist/lib/Menu/index.js +2 -0
  161. package/dist/lib/Menu/index.js.map +1 -1
  162. package/dist/lib/Order/index.d.ts +20 -0
  163. package/dist/lib/Order/index.js +23 -0
  164. package/dist/lib/Order/index.js.map +1 -1
  165. package/dist/lib/Org/index.d.ts +41 -0
  166. package/dist/lib/Org/index.js +41 -0
  167. package/dist/lib/Org/index.js.map +1 -1
  168. package/dist/lib/PandaPay/index.js +6 -0
  169. package/dist/lib/PandaPay/index.js.map +1 -1
  170. package/dist/lib/Paysafe/index.js +1 -0
  171. package/dist/lib/Paysafe/index.js.map +1 -1
  172. package/dist/lib/Product/index.d.ts +25 -0
  173. package/dist/lib/Product/index.js +55 -1
  174. package/dist/lib/Product/index.js.map +1 -1
  175. package/dist/lib/PromiseToPurchase/index.d.ts +72 -0
  176. package/dist/lib/PromiseToPurchase/index.js +79 -0
  177. package/dist/lib/PromiseToPurchase/index.js.map +1 -1
  178. package/dist/lib/PurchaseOrder/index.d.ts +11 -0
  179. package/dist/lib/PurchaseOrder/index.js +12 -0
  180. package/dist/lib/PurchaseOrder/index.js.map +1 -1
  181. package/dist/lib/Service/index.d.ts +8 -0
  182. package/dist/lib/Service/index.js +8 -0
  183. package/dist/lib/Service/index.js.map +1 -1
  184. package/dist/lib/Shipment/index.js +13 -0
  185. package/dist/lib/Shipment/index.js.map +1 -1
  186. package/dist/lib/Slider/index.d.ts +6 -0
  187. package/dist/lib/Slider/index.js +6 -0
  188. package/dist/lib/Slider/index.js.map +1 -1
  189. package/dist/lib/Space/index.d.ts +178 -0
  190. package/dist/lib/Space/index.js +495 -6
  191. package/dist/lib/Space/index.js.map +1 -1
  192. package/dist/lib/Supplier/index.js +5 -0
  193. package/dist/lib/Supplier/index.js.map +1 -1
  194. package/dist/lib/Tags/index.js +5 -0
  195. package/dist/lib/Tags/index.js.map +1 -1
  196. package/dist/lib/TransferRequest/index.d.ts +178 -0
  197. package/dist/lib/TransferRequest/index.js +236 -4
  198. package/dist/lib/TransferRequest/index.js.map +1 -1
  199. package/dist/lib/User/index.d.ts +54 -0
  200. package/dist/lib/User/index.js +101 -21
  201. package/dist/lib/User/index.js.map +1 -1
  202. package/dist/lib/baseService.js +26 -0
  203. package/dist/lib/baseService.js.map +1 -1
  204. package/dist/rules/GR/constants/data.js +22 -0
  205. package/dist/rules/GR/constants/data.js.map +1 -1
  206. package/dist/rules/GR/constants/products.d.ts +3 -0
  207. package/dist/rules/GR/constants/products.js +16 -0
  208. package/dist/rules/GR/constants/products.js.map +1 -1
  209. package/dist/rules/GR/interfaces/data.js +7 -1
  210. package/dist/rules/GR/interfaces/data.js.map +1 -1
  211. package/dist/rules/GR/utils/cart.d.ts +41 -0
  212. package/dist/rules/GR/utils/cart.js +107 -1
  213. package/dist/rules/GR/utils/cart.js.map +1 -1
  214. package/dist/rules/GR/utils/data.js +4 -1
  215. package/dist/rules/GR/utils/data.js.map +1 -1
  216. package/dist/rules/GR/utils/expedition.d.ts +69 -0
  217. package/dist/rules/GR/utils/expedition.js +399 -11
  218. package/dist/rules/GR/utils/expedition.js.map +1 -1
  219. package/dist/rules/GR/utils/g2.d.ts +33 -0
  220. package/dist/rules/GR/utils/g2.js +135 -3
  221. package/dist/rules/GR/utils/g2.js.map +1 -1
  222. package/dist/rules/GR/utils/invoices.d.ts +27 -0
  223. package/dist/rules/GR/utils/invoices.js +41 -0
  224. package/dist/rules/GR/utils/invoices.js.map +1 -1
  225. package/dist/rules/GR/utils/products.d.ts +161 -0
  226. package/dist/rules/GR/utils/products.js +272 -1
  227. package/dist/rules/GR/utils/products.js.map +1 -1
  228. package/dist/rules/GR/utils/upsells.d.ts +32 -0
  229. package/dist/rules/GR/utils/upsells.js +32 -0
  230. package/dist/rules/GR/utils/upsells.js.map +1 -1
  231. package/dist/services/database/DatabaseService.d.ts +84 -0
  232. package/dist/services/database/DatabaseService.js +85 -0
  233. package/dist/services/database/DatabaseService.js.map +1 -1
  234. package/dist/services/database/FirebaseProvider.js +17 -0
  235. package/dist/services/database/FirebaseProvider.js.map +1 -1
  236. package/dist/services/database/NotFirebaseProvider.d.ts +14 -0
  237. package/dist/services/database/NotFirebaseProvider.js +19 -0
  238. package/dist/services/database/NotFirebaseProvider.js.map +1 -1
  239. package/dist/services/g2/G2OrderSlip.d.ts +7 -0
  240. package/dist/services/g2/G2OrderSlip.js +18 -0
  241. package/dist/services/g2/G2OrderSlip.js.map +1 -1
  242. package/dist/services/g2/utils.d.ts +10 -0
  243. package/dist/services/g2/utils.js +189 -3
  244. package/dist/services/g2/utils.js.map +1 -1
  245. package/dist/services/logs/index.d.ts +3 -0
  246. package/dist/services/logs/index.js +6 -1
  247. package/dist/services/logs/index.js.map +1 -1
  248. package/dist/services/products/BaseClass.js +2 -0
  249. package/dist/services/products/BaseClass.js.map +1 -1
  250. package/dist/services/products/TCGService.js +17 -1
  251. package/dist/services/products/TCGService.js.map +1 -1
  252. package/dist/services/products/utils.d.ts +22 -0
  253. package/dist/services/products/utils.js +50 -0
  254. package/dist/services/products/utils.js.map +1 -1
  255. package/dist/utils/anonymisation.d.ts +24 -0
  256. package/dist/utils/anonymisation.js +30 -0
  257. package/dist/utils/anonymisation.js.map +1 -1
  258. package/dist/utils/aws.d.ts +22 -0
  259. package/dist/utils/aws.js +28 -0
  260. package/dist/utils/aws.js.map +1 -1
  261. package/dist/utils/booking.d.ts +8 -0
  262. package/dist/utils/booking.js +9 -0
  263. package/dist/utils/booking.js.map +1 -1
  264. package/dist/utils/cart.d.ts +81 -0
  265. package/dist/utils/cart.js +172 -9
  266. package/dist/utils/cart.js.map +1 -1
  267. package/dist/utils/context.js +2 -2
  268. package/dist/utils/context.js.map +1 -1
  269. package/dist/utils/currency.js +31 -1
  270. package/dist/utils/currency.js.map +1 -1
  271. package/dist/utils/data.js +2 -0
  272. package/dist/utils/data.js.map +1 -1
  273. package/dist/utils/discount.d.ts +118 -0
  274. package/dist/utils/discount.js +178 -1
  275. package/dist/utils/discount.js.map +1 -1
  276. package/dist/utils/file-admin.js +1 -0
  277. package/dist/utils/file-admin.js.map +1 -1
  278. package/dist/utils/file.js +9 -1
  279. package/dist/utils/file.js.map +1 -1
  280. package/dist/utils/firebase-admin.d.ts +9 -0
  281. package/dist/utils/firebase-admin.js +12 -0
  282. package/dist/utils/firebase-admin.js.map +1 -1
  283. package/dist/utils/firebase.d.ts +17 -0
  284. package/dist/utils/firebase.js +17 -0
  285. package/dist/utils/firebase.js.map +1 -1
  286. package/dist/utils/inventories.d.ts +52 -0
  287. package/dist/utils/inventories.js +77 -2
  288. package/dist/utils/inventories.js.map +1 -1
  289. package/dist/utils/locale.d.ts +9 -0
  290. package/dist/utils/locale.js +9 -0
  291. package/dist/utils/locale.js.map +1 -1
  292. package/dist/utils/mailchimp.js +36 -0
  293. package/dist/utils/mailchimp.js.map +1 -1
  294. package/dist/utils/mathUtils.js +9 -0
  295. package/dist/utils/mathUtils.js.map +1 -1
  296. package/dist/utils/object.d.ts +19 -0
  297. package/dist/utils/object.js +21 -3
  298. package/dist/utils/object.js.map +1 -1
  299. package/dist/utils/products.d.ts +7 -0
  300. package/dist/utils/products.js +9 -0
  301. package/dist/utils/products.js.map +1 -1
  302. package/dist/utils/promiseToPurchase.d.ts +32 -0
  303. package/dist/utils/promiseToPurchase.js +34 -0
  304. package/dist/utils/promiseToPurchase.js.map +1 -1
  305. package/dist/utils/prosprsearch.d.ts +15 -0
  306. package/dist/utils/prosprsearch.js +15 -0
  307. package/dist/utils/prosprsearch.js.map +1 -1
  308. package/dist/utils/sdc.js +7 -0
  309. package/dist/utils/sdc.js.map +1 -1
  310. package/dist/utils/searchIndexes.d.ts +37 -0
  311. package/dist/utils/searchIndexes.js +37 -0
  312. package/dist/utils/searchIndexes.js.map +1 -1
  313. package/dist/utils/string.js +7 -6
  314. package/dist/utils/string.js.map +1 -1
  315. package/dist/utils/tools.d.ts +4 -0
  316. package/dist/utils/tools.js +4 -0
  317. package/dist/utils/tools.js.map +1 -1
  318. package/dist/utils/transferRequests.d.ts +24 -0
  319. package/dist/utils/transferRequests.js +24 -0
  320. package/dist/utils/transferRequests.js.map +1 -1
  321. package/dist/utils/update.js +12 -0
  322. package/dist/utils/update.js.map +1 -1
  323. package/package.json +1 -1
@@ -11,19 +11,25 @@ const floor_1 = __importDefault(require("lodash/floor"));
11
11
  const round_1 = __importDefault(require("lodash/round"));
12
12
  const sumBy_1 = __importDefault(require("lodash/sumBy"));
13
13
  const toNumber_1 = __importDefault(require("lodash/toNumber"));
14
+ // Rule specific interfaces
14
15
  const products_1 = require("../interfaces/products");
16
+ // Rule specific functions/constants
15
17
  const data_1 = require("./data");
16
18
  const products_2 = require("./products");
17
19
  const cart_1 = require("./cart");
18
20
  const g2_1 = require("./g2");
19
21
  const data_2 = require("../constants/data");
22
+ // General interfaces
20
23
  const Cart_1 = require("../../../Interfaces/Cart");
24
+ // General utils
21
25
  const data_3 = require("../../../utils/data");
22
26
  const products_3 = require("../../../utils/products");
23
27
  const cart_2 = require("../interfaces/cart");
24
28
  const data_4 = require("../interfaces/data");
25
29
  const products_4 = require("../constants/products");
26
30
  const object_1 = require("../../../utils/object");
31
+ // ------------------------------------------------------------------------------------------
32
+ // #region HOURS
27
33
  const getDefaultTimeValues = () => {
28
34
  let values = ['AM', 'PM'];
29
35
  return values.map((v) => ({ label: v, value: v }));
@@ -38,6 +44,7 @@ const getAvailableHours = (minDeliveryDate, selectedDate, grassProduct, concrete
38
44
  ? (0, moment_1.default)(testDate).toDate()
39
45
  : (0, moment_1.default)(testDate).set('hours', (0, moment_1.default)().hours()).toDate()
40
46
  : (0, moment_1.default)().toDate();
47
+ // If concreteOrder and product in stock and is pickup, can select 'now' (AM if before noon, PM if after)
41
48
  if (!!concreteOrder && !!concreteOrder.inStock && expeditionMethod === 'pickup') {
42
49
  const isPM = today.getHours() >= 12;
43
50
  if (!!isPM) {
@@ -48,6 +55,8 @@ const getAvailableHours = (minDeliveryDate, selectedDate, grassProduct, concrete
48
55
  newSelectedDeliveryTime: !!isPM ? { label: 'PM', value: 'PM' } : undefined
49
56
  };
50
57
  }
58
+ // ------------------------------------------------------------------------------------------------------
59
+ // enable all hours in selection
51
60
  const resetHours = (d) => {
52
61
  d.setHours(0);
53
62
  d.setMinutes(0);
@@ -69,34 +78,51 @@ const getAvailableHours = (minDeliveryDate, selectedDate, grassProduct, concrete
69
78
  }
70
79
  deliveryTimes = ['PM'];
71
80
  };
81
+ // EDIT - Ajusted logic that excluded saturdays from time selection if not pro to make available if expeditionMethod = shipping [ 03-10-2022 ]
72
82
  if (selectedDateDay === 0 || (selectedDateDay === 6 && !!!isPro && expeditionMethod === 'pickup')) {
73
83
  deliveryTimes = [];
74
84
  newSelectedDeliveryTime = undefined;
75
85
  }
76
- else if (!(!!concreteOrder && concreteOrder.type == 'green' && (!concreteOrder.inStock || expeditionMethod == 'delivery'))) {
86
+ else if (
87
+ // Bug GR-I505 - AM / PM toujours disponnible pour Beton Vert en livraison
88
+ // Bug GR-I511 - Pickup for concrete not in stock only change de available day
89
+ !(!!concreteOrder && concreteOrder.type == 'green' && (!concreteOrder.inStock || expeditionMethod == 'delivery'))) {
77
90
  if (isSelectedSameAsTarget) {
78
91
  if (!!grassProduct || (!!concreteOrder && concreteOrder.type === 'green')) {
79
92
  let todayReset = !!testDate ? (0, moment_1.default)(testDate).toDate() : (0, moment_1.default)().toDate();
80
93
  resetHours(todayReset);
94
+ // If today is either saturday of sunday
81
95
  if (!![6, 0].includes(todayReset.getDay())) {
96
+ // Two options :
97
+ // - is non-speciality grass OR [ concrete + type green + pickup + not in stock ] and target day is NOT a tuesday
98
+ // - is any other kind of grass and target day is NOT a wednesday or thursday
82
99
  if ((![2].includes(targetDateDay) &&
83
100
  (!!isNonSpecialityGrass ||
84
101
  (!!concreteOrder && !concreteOrder.inStock && expeditionMethod === 'pickup'))) ||
85
102
  (![3, 4].includes(targetDateDay) && !!!isNonSpecialityGrass)) {
103
+ // EDIT - Ajusted logic that excluded saturdays from time selection if not pro to make available if expeditionMethod = shipping [ 03-10-2022 ]
86
104
  if (targetDateDay === 6 && !!!isPro && expeditionMethod === 'pickup') {
87
105
  newSelectedDeliveryTime = undefined;
88
106
  deliveryTimes = [];
89
107
  }
90
108
  else {
91
109
  const amTimeToCheck = !!grassProduct && expeditionMethod == 'pickup' ? 12 : 10;
110
+ // Logic ajusted on 08-05-2025 (task #GR-I377 in Sprint) - If grass & pickup, first check starts at noon. If not, at 10am.
111
+ // Check if later than specific AM time
92
112
  if (today.getHours() >= amTimeToCheck) {
93
113
  onlyPm();
94
114
  }
95
115
  }
96
116
  }
117
+ // If none of the above options are true, both time periods are available to the user
97
118
  }
98
119
  else {
120
+ // Today is any other day than the weekend
121
+ // Check if later than target hour
122
+ // Logic updated on 08-05-2025, #GR-I377 in Sprint
99
123
  let targetHour = !!grassProduct && expeditionMethod == 'pickup' ? 12 : 10;
124
+ // If grass or green concrete pickup, and today is Friday, AM stays available until after 16h
125
+ // Logic updated on 17-02-2025, GR-I150 dans Zoho Sprint
100
126
  if (todayDay == 5 &&
101
127
  (!!grassProduct || (!!concreteOrder && concreteOrder.type == 'green' && expeditionMethod == 'pickup'))) {
102
128
  targetHour = 16;
@@ -106,7 +132,9 @@ const getAvailableHours = (minDeliveryDate, selectedDate, grassProduct, concrete
106
132
  }
107
133
  }
108
134
  }
135
+ // If order contains samples or is of any other type than grass or concrete
109
136
  if ((!!!grassProduct && !!!concreteOrder) || !!isSample || !!isAccessoriesOnly) {
137
+ // Check if later than 10 AM
110
138
  if (today.getHours() > 10) {
111
139
  onlyPm();
112
140
  }
@@ -119,10 +147,15 @@ const getAvailableHours = (minDeliveryDate, selectedDate, grassProduct, concrete
119
147
  };
120
148
  };
121
149
  exports.getAvailableHours = getAvailableHours;
150
+ // Date de dégel (hardcodée, sera modifiée directement dans le code à la demande des clients)
122
151
  const isDegel = (dateToCheck) => {
123
152
  let date = !!dateToCheck ? (0, moment_1.default)(dateToCheck) : (0, moment_1.default)();
124
153
  return date.isBetween('2024-03-04 00:00:01', '2024-04-15 23:59:59', undefined, '[]');
125
154
  };
155
+ /**
156
+ * Function getMinDatePicker
157
+ * @description Sets the minimum shipping day for delivery
158
+ */
126
159
  const getMinDatePicker = (cartData, grassProduct, concreteOrder, expeditionMethod, isPro, testDate, blockedShippingDates, vracType, isPOS, spaceSchedule) => {
127
160
  const cartContainsInstallation = (0, cart_1.checkIfCartContainsType)(cart_2.CartGeneralTypeEnum.INSTALLATION, cartData);
128
161
  const cartContainsVrac = (0, cart_1.checkIfCartContainsType)(cart_2.CartGeneralTypeEnum.VRAC, cartData);
@@ -133,7 +166,13 @@ const getMinDatePicker = (cartData, grassProduct, concreteOrder, expeditionMetho
133
166
  }
134
167
  let now = testDate || (0, moment_1.default)().toDate();
135
168
  let min_date = testDate || (0, moment_1.default)().toDate();
169
+ // =======================================================================================
170
+ // #region MIN DATE OFFSET
136
171
  const nbDaysOffset = (0, exports.getMinDateOffset)(now, cartContainsInstallation, cartContainsVrac, cartData, grassProduct, concreteOrder, isAccessoriesOnly, expeditionMethod, vracType);
172
+ // #endregion
173
+ // =======================================================================================
174
+ // =======================================================================================
175
+ // #region BLOCKED DAYS/DATES
137
176
  const typeToCheck = !!concreteOrder
138
177
  ? 'beton'
139
178
  : !!grassProduct
@@ -144,6 +183,9 @@ const getMinDatePicker = (cartData, grassProduct, concreteOrder, expeditionMetho
144
183
  let dateToCheck = new Date(min_date);
145
184
  dateToCheck.setDate(min_date.getDate() + nbDaysOffset);
146
185
  let pickupDateSameAsNewDate = false;
186
+ // ---------------------------------------------------------------------------------------
187
+ // Check if space has blocked days
188
+ // NEW!!! - For now, blocked days are hardcoded here. Will be moved to space eventually.
147
189
  const blockedDays = {
148
190
  vrac: [0],
149
191
  beton: [0],
@@ -152,6 +194,7 @@ const getMinDatePicker = (cartData, grassProduct, concreteOrder, expeditionMetho
152
194
  const getNextAvailableDay = (type) => {
153
195
  const dayToCheck = dateToCheck.getDay();
154
196
  if (!!blockedDays[type]) {
197
+ // Right now we ignore blocked days on pickup because we check the schedules in the space. If days are added to the blockedDays dictionnary, validate that they still shouldn't apply on pickup
155
198
  if (blockedDays[type].includes(dayToCheck) && expeditionMethod !== 'pickup') {
156
199
  dateToCheck.setDate(dateToCheck.getDate() + 1);
157
200
  return getNextAvailableDay(type);
@@ -175,6 +218,8 @@ const getMinDatePicker = (cartData, grassProduct, concreteOrder, expeditionMetho
175
218
  pickupDateSameAsNewDate = true;
176
219
  }
177
220
  }
221
+ // ---------------------------------------------------------------------------------------
222
+ // Check if space has blocked dates
178
223
  if (!!blockedShippingDates && blockedShippingDates.length && !!typeToCheck && expeditionMethod === 'delivery') {
179
224
  const blockedDatesToCheck = blockedShippingDates.find((blockedDate) => blockedDate.cart_type === typeToCheck);
180
225
  if (!!blockedDatesToCheck && !!blockedDatesToCheck.dates && !!blockedDatesToCheck.dates.length) {
@@ -194,6 +239,8 @@ const getMinDatePicker = (cartData, grassProduct, concreteOrder, expeditionMetho
194
239
  }
195
240
  }
196
241
  }
242
+ // #endregion
243
+ // =======================================================================================
197
244
  if (!!!concreteOrder || concreteOrder.type !== 'yellow') {
198
245
  min_date.setDate(dateToCheck.getDate());
199
246
  min_date.setHours(0);
@@ -211,8 +258,10 @@ exports.getMinDatePicker = getMinDatePicker;
211
258
  const getSamplesMinDateOffset = () => {
212
259
  const now = new Date();
213
260
  const year = now.getFullYear();
214
- const startWinterPeriod = new Date(year, 11, 1);
215
- const endWinterPeriod = new Date(year + 1, 2, 1);
261
+ // December 1st
262
+ const startWinterPeriod = new Date(year, 11, 1); // December == 11
263
+ // March 1st
264
+ const endWinterPeriod = new Date(year + 1, 2, 1); // March == 2
216
265
  const isWinterPeriod = (0, moment_1.default)().isBetween((0, moment_1.default)(startWinterPeriod), (0, moment_1.default)(endWinterPeriod), 'day', '[]');
217
266
  return isWinterPeriod ? 14 : 7;
218
267
  };
@@ -221,8 +270,25 @@ const getMinDateOffset = (now, cartContainsInstallation, cartContainsVrac, cartD
221
270
  const current_hour = now.getHours();
222
271
  const current_day = now.getDay();
223
272
  let nb_days_offset = 1;
273
+ // Variable to set all grass delays the same as non-speciality grasses (as of now, Kentucky and Prestige).
274
+ // Use this instead of changing all values, in case our clients change their mind later!
224
275
  const allGrassDelaysSameAsNonSpecialityGrasses = true;
276
+ // ========================
277
+ // IF INSTALL
278
+ // Install logic adjusted on 01-05-2024 (task #GR7-T429)
225
279
  if (!!cartContainsInstallation) {
280
+ // --------------------
281
+ // "Low staff" logic = 96hours delay for first available date
282
+ // switch (current_day) {
283
+ // case 3:
284
+ // nb_days_offset = 5
285
+ // break
286
+ // default:
287
+ // nb_days_offset = 4
288
+ // break
289
+ // }
290
+ // --------------------
291
+ // "Medium staff" logic = 48hours delay for first available date
226
292
  switch (current_day) {
227
293
  case 5:
228
294
  nb_days_offset = 3;
@@ -231,7 +297,23 @@ const getMinDateOffset = (now, cartContainsInstallation, cartContainsVrac, cartD
231
297
  nb_days_offset = 2;
232
298
  break;
233
299
  }
300
+ // --------------------
301
+ // Regular logic (if fee applies for current year) = 24 hour delay for first available date
302
+ // switch (current_day) {
303
+ // case 5:
304
+ // nb_days_offset = current_hour < 10 ? 1 : 3
305
+ // break
306
+ // case 6:
307
+ // case 0:
308
+ // nb_days_offset = 2
309
+ // break
310
+ // default:
311
+ // nb_days_offset = 1
312
+ // break
313
+ // }
234
314
  }
315
+ // ========================
316
+ // IF SAMPLE OR ACCESSORIES ONLY
235
317
  else if (cartData.items.find((item) => item.is_sample) || !!isAccessoriesOnly) {
236
318
  if (expeditionMethod === 'delivery') {
237
319
  nb_days_offset = !!isAccessoriesOnly ? 7 : (0, exports.getSamplesMinDateOffset)();
@@ -255,33 +337,42 @@ const getMinDateOffset = (now, cartContainsInstallation, cartContainsVrac, cartD
255
337
  }
256
338
  }
257
339
  }
340
+ // ========================
341
+ // IF VRAC PRODUCTS WITH DELIVERY
258
342
  else if (expeditionMethod === 'delivery' &&
259
343
  !!cartContainsVrac &&
260
344
  !!(0, object_1.recursiveCheckObject)(vracType, 'vrac_type') &&
261
345
  [products_1.VracTypeEnum.AUTRE_TONNE, products_1.VracTypeEnum.NOBEL_TONNE].includes(vracType.vrac_type)) {
262
346
  nb_days_offset = 1;
263
347
  }
348
+ // ========================
349
+ // IF BASE GRASS / ALL GRASSES ARE SAME
264
350
  else if (!!grassProduct &&
265
351
  ([products_4.kentucky, products_4.prestige].includes(grassProduct.sku) || !!allGrassDelaysSameAsNonSpecialityGrasses)) {
266
352
  const amTimeToCheck = !!grassProduct && expeditionMethod == 'pickup' ? 12 : 10;
353
+ // Logic ajusted on 08-05-2025 (task #GR-I377 in Sprint) - If grass & pickup, first check starts at noon. If not, at 10am.
267
354
  switch (current_day) {
268
355
  case 5:
269
- nb_days_offset = current_hour < amTimeToCheck ? 1 : current_hour < 16 ? 3 : 3;
356
+ nb_days_offset = current_hour < amTimeToCheck ? 1 : current_hour < 16 ? 3 : 3; // earliest is tomorrow if before 10AM, else after tomorrow, not counting the weekend (on fridays)
357
+ // Logic ajusted on 14-02-2025 (task #GR-I151 in Sprint) - New check for between 10h (or 12h if grass&pickup) and 16h
270
358
  break;
271
359
  case 6:
272
- nb_days_offset = 3;
360
+ nb_days_offset = 3; // earliest is after tomorrow, not counting the weekend (on fridays or saturdays)
273
361
  break;
274
362
  case 0:
275
- nb_days_offset = 2;
363
+ nb_days_offset = 2; // earliest is after tomorrow, not counting the weekend (on sundays)
276
364
  break;
277
365
  default:
278
- nb_days_offset = 1;
366
+ nb_days_offset = 1; // earliest is tomorrow
279
367
  }
280
368
  }
369
+ // ========================
370
+ // IF CONCRETE WITH PICKUP | UNAVAILABLE PRODUCT
281
371
  else if (!!concreteOrder &&
282
372
  concreteOrder.type === 'green' &&
283
373
  !concreteOrder.inStock &&
284
374
  expeditionMethod === 'pickup') {
375
+ // 13-08-2025 : Bug GR-I511 - Pickup for concrete not in stock only change the available day
285
376
  const amTimeToCheck = 10;
286
377
  switch (current_day) {
287
378
  case 0:
@@ -300,23 +391,29 @@ const getMinDateOffset = (now, cartContainsInstallation, cartContainsVrac, cartD
300
391
  nb_days_offset = current_hour < amTimeToCheck ? 1 : 2;
301
392
  }
302
393
  }
394
+ // ========================
395
+ // IF CONCRETE WITH PICKUP | ONLY AVAILABLE PRODUCTS
303
396
  else if (!!concreteOrder &&
304
397
  concreteOrder.type === 'green' &&
305
398
  concreteOrder.inStock &&
306
399
  expeditionMethod === 'pickup') {
307
400
  nb_days_offset = 0;
308
401
  }
402
+ // ========================
403
+ // IF SPECIALITY GRASS
309
404
  else if (!!grassProduct && !!![products_4.kentucky, products_4.prestige].includes(grassProduct.sku)) {
310
405
  switch (current_day) {
311
406
  case 5:
312
407
  case 6:
313
408
  case 0:
314
- nb_days_offset = 4;
409
+ nb_days_offset = 4; // if we are on friday and it's earlier than 10
315
410
  break;
316
411
  default:
317
- nb_days_offset = 2;
412
+ nb_days_offset = 2; // earliest is after tomorrow
318
413
  }
319
414
  }
415
+ // ========================
416
+ // IF CONCRETE WITH DELIVERY | ONLY AVAILABLE PRODUCTS
320
417
  else if (!!concreteOrder && concreteOrder.type === 'green' && expeditionMethod === 'delivery') {
321
418
  switch (current_day) {
322
419
  case 0:
@@ -329,9 +426,11 @@ const getMinDateOffset = (now, cartContainsInstallation, cartContainsVrac, cartD
329
426
  break;
330
427
  case 4:
331
428
  nb_days_offset = current_hour < 10 ? 2 : current_hour < 16 ? 4 : 5;
429
+ // Logic ajusted on 14-02-2025 (task #GR-I151 in Sprint) - New check for between 10h and 16h
332
430
  break;
333
431
  case 5:
334
432
  nb_days_offset = current_hour < 16 ? 4 : 5;
433
+ // Logic ajusted on 14-02-2025 (task #GR-I151 in Sprint) - New check for 16h instead of 10h
335
434
  break;
336
435
  case 6:
337
436
  nb_days_offset = 4;
@@ -340,6 +439,8 @@ const getMinDateOffset = (now, cartContainsInstallation, cartContainsVrac, cartD
340
439
  break;
341
440
  }
342
441
  }
442
+ // ========================
443
+ // IF ANY PRODUCT WITH DELIVERY THAT DID NOT FIT IN PREVIOUS CATEGORIES
343
444
  else if (expeditionMethod === 'delivery') {
344
445
  switch (current_day) {
345
446
  case 0:
@@ -366,10 +467,21 @@ const getMinDateOffset = (now, cartContainsInstallation, cartContainsVrac, cartD
366
467
  return nb_days_offset;
367
468
  };
368
469
  exports.getMinDateOffset = getMinDateOffset;
470
+ /**
471
+ * Function shouldDisableDate
472
+ * @description compares date with blockedDates from DB and blocked days (currently hardcoded in function)
473
+ * @param date - Date to check
474
+ * @param blockedDates - Blocked dates from DB
475
+ * @param expeditionMethod - pickup or shipping
476
+ * @param cartData
477
+ */
369
478
  const shouldDisableDate = (date, blockedDates, expeditionMethod, cartData, schedule, selectedStore) => {
370
479
  if (!!!cartData)
371
480
  return false;
372
481
  const typeToCheck = (0, cart_1.getCartType)(cartData);
482
+ // ---------------------------------------------------------------------------------------
483
+ // Blocked days check
484
+ // NEW!!! - For now, blocked days are hardcoded here. Will be moved to space eventually.
373
485
  const blockedDays = {
374
486
  vrac: [0],
375
487
  beton: [0],
@@ -381,6 +493,8 @@ const shouldDisableDate = (date, blockedDates, expeditionMethod, cartData, sched
381
493
  (!!blockedDays[typeToCheck] && !!blockedDays[typeToCheck].includes(date.getDay()) && expeditionMethod !== 'pickup')) {
382
494
  return true;
383
495
  }
496
+ // ---------------------------------------------------------------------------------------
497
+ // Blocked dates checks
384
498
  if (expeditionMethod !== 'pickup' && !!typeToCheck && !!blockedDates) {
385
499
  const sameType = blockedDates.find((blocked) => blocked.cart_type === typeToCheck);
386
500
  if (!!sameType && !!sameType.dates) {
@@ -404,8 +518,10 @@ const dateIsClosedInSchedule = (storeId, dateToCheck, spaceSchedule) => {
404
518
  const weekdayIndex = dateToCheck.getDay();
405
519
  const storeSchedules = spaceSchedule.store_schedules[storeId];
406
520
  let isExternal = false;
521
+ // If store schedule exists, check it, if not, set min date to dateToCheck.
407
522
  if (!!storeSchedules) {
408
523
  let selectedDaySchedule;
524
+ // If periods are activated for the space, check the specific period schedule, if not check the general schedule
409
525
  if (!!spaceSchedule.space_periods_active) {
410
526
  const year = dateToCheck.getFullYear().toString();
411
527
  const periods = (_a = spaceSchedule.year_periods[year]) !== null && _a !== void 0 ? _a : [];
@@ -423,6 +539,9 @@ const dateIsClosedInSchedule = (storeId, dateToCheck, spaceSchedule) => {
423
539
  }
424
540
  }
425
541
  }
542
+ // If no schedule found for that day in active period, or periods aren't activated for that space, fall back to general schedule
543
+ // A closed day should NOT enter this if
544
+ // A period with an external schedule should NOT enter this if
426
545
  if (!!!isExternal &&
427
546
  (!!!selectedDaySchedule ||
428
547
  (!!selectedDaySchedule.schedule &&
@@ -437,11 +556,13 @@ const dateIsClosedInSchedule = (storeId, dateToCheck, spaceSchedule) => {
437
556
  selectedDaySchedule = generalSchedule.weekly_schedule[weekdayIndex];
438
557
  }
439
558
  }
559
+ // NEW - Returns true here even if isExternal
440
560
  if (!!selectedDaySchedule && selectedDaySchedule.open === false) {
441
561
  return true;
442
562
  }
443
563
  }
444
564
  let allClosedDays = spaceSchedule.common_closed_days;
565
+ // If schedule for period is external, filter out all common dates since they do not apply
445
566
  if (!!isExternal)
446
567
  allClosedDays = allClosedDays.filter((d) => d.type != 'common');
447
568
  const isClosed = allClosedDays.some((c) => {
@@ -457,6 +578,12 @@ const dateIsClosedInSchedule = (storeId, dateToCheck, spaceSchedule) => {
457
578
  return isClosed;
458
579
  };
459
580
  exports.dateIsClosedInSchedule = dateIsClosedInSchedule;
581
+ /**
582
+ * Function checkIfCartTypeHasBlockedDates
583
+ * @description checks if type of cart corresponds to a blockedDates array and if array has dates defined
584
+ * @param cartData
585
+ * @param blockedDates
586
+ */
460
587
  const checkIfCartTypeHasBlockedDates = (cartData, blockedDates) => {
461
588
  if (!!!cartData || !!!blockedDates || !!!blockedDates.length)
462
589
  return false;
@@ -467,6 +594,10 @@ const checkIfCartTypeHasBlockedDates = (cartData, blockedDates) => {
467
594
  return !!sameType.dates && !!sameType.dates.length;
468
595
  };
469
596
  exports.checkIfCartTypeHasBlockedDates = checkIfCartTypeHasBlockedDates;
597
+ // #endregion
598
+ // ------------------------------------------------------------------------------------------
599
+ // ------------------------------------------------------------------------------------------
600
+ // #region FEES
470
601
  exports.slugsToCheckFromExpeditionFees = {
471
602
  pickup: ['frais-preparation-general-beton', 'frais-palette', 'minimum-facturable-commande'],
472
603
  shipping: [
@@ -499,9 +630,11 @@ const getPalletQty = (items, orderType, minQteGrassOrder = 0) => {
499
630
  if (!!!typeAttr || !!!typeAttr.length) {
500
631
  return 0;
501
632
  }
633
+ // If item is an accessory
502
634
  if (!!typeAttr && !typeAttr.includes('gazon') && !typeAttr.includes('beton')) {
503
635
  return (0, floor_1.default)((item.qte * sellUnit) / paletteUnit.fitting_unit);
504
636
  }
637
+ // If is grass and minQteGrassOrder is defined
505
638
  if (!!typeAttr.includes('gazon') && !!minQteGrassOrder && item.qte < minQteGrassOrder) {
506
639
  return minQteGrassOrder / paletteUnit.fitting_unit;
507
640
  }
@@ -513,8 +646,11 @@ const getPalletQty = (items, orderType, minQteGrassOrder = 0) => {
513
646
  return total;
514
647
  };
515
648
  exports.getPalletQty = getPalletQty;
649
+ // Retourne un nombre de frais de palettes à ajouter au panier selon la vraie quantité de palettes calculées pour les produits de gazon
516
650
  const getGrassRoundedPickupPalletFees = (realPalletNumber) => {
651
+ // More than 400 square feet of grass needs another pallet
517
652
  const ratio = (0, round_1.default)(400 / 740, 3);
653
+ // Get only the decimals from the real calculated pallet number, if the decimal is bigger than 400 / 740, round up
518
654
  const fraction = (0, round_1.default)(realPalletNumber % 1, 3);
519
655
  if (fraction >= ratio)
520
656
  return (0, ceil_1.default)(realPalletNumber);
@@ -524,6 +660,7 @@ exports.getGrassRoundedPickupPalletFees = getGrassRoundedPickupPalletFees;
524
660
  const getPalletQtyPalletFee = (items, expeditionMethod, isGrass, isMixed) => {
525
661
  let totalPalletGrass = 0;
526
662
  let totalPalletOther = 0;
663
+ // For this fee specifically, remove all accessories before calculating palQty
527
664
  items = items.filter((i) => !(0, products_2.checkIfProductIsOfType)(i, 'accessoire'));
528
665
  if (!!isGrass) {
529
666
  const grassItemsToCheck = !!isMixed ? items.filter((i) => !!(0, products_2.checkIfProductIsOfType)(i, 'gazon', true)) : items;
@@ -576,14 +713,19 @@ const calculatePalFeeForOtherThanGrass = (items) => {
576
713
  sellUnit = !!sellUnitCheck.fitting_unit ? sellUnitCheck.fitting_unit : 1;
577
714
  }
578
715
  const typeAttr = item.attributes[data_4.AttributesIdEnumGR.TYPE];
716
+ // --------------------------------------------------
717
+ // 1. If not all units are defined
718
+ // if no palUnit or no typeAttr
579
719
  if (!!!palUnit || !!!palUnit.fitting_unit || !!!typeAttr || !!!typeAttr.length) {
580
720
  if (!!itemIsException)
581
721
  return 1;
722
+ // if no rgUnit, can't calculate pallet amount
582
723
  if (!!!rgUnit || !!!rgUnit.fitting_unit) {
583
724
  return 0;
584
725
  }
585
726
  else {
586
727
  const nbRang = (item.qte * sellUnit) / rgUnit.fitting_unit;
728
+ // if has quantities but rang amount is lower than 1, return 0
587
729
  if (nbRang > 0 && nbRang <= 1) {
588
730
  return 0;
589
731
  }
@@ -592,29 +734,47 @@ const calculatePalFeeForOtherThanGrass = (items) => {
592
734
  }
593
735
  }
594
736
  }
737
+ // --------------------------------------------------
738
+ // 2. If is accessory
595
739
  if (!!typeAttr && !typeAttr.includes('gazon') && !typeAttr.includes('beton')) {
596
740
  return (0, floor_1.default)((item.qte * sellUnit) / palUnit.fitting_unit);
597
741
  }
598
742
  const palQty = (item.qte * sellUnit) / (palUnit.fitting_unit || 1);
599
743
  const rgQty = !!rgUnit ? (item.qte * sellUnit) / (rgUnit.fitting_unit || 1) : 0;
600
744
  const unitQty = !!unitUnit ? (item.qte * sellUnit) / (unitUnit.fitting_unit || 1) : !!sellUnit ? item.qte : 0;
745
+ // --------------------------------------------------
746
+ // 3. Calculate pal quantities
747
+ // RULES:
748
+ // - 1 pal = 1 pal
749
+ // - 1 pal + 1 rang = 1 pal
750
+ // - 1 pal + 2 rang = 2 pal
751
+ // - 1 pal + 1 rang + 1 unité = 2 pals
752
+ // - 1 pal + 1 unité = 1 pal
753
+ // - 0 pal :
754
+ // - If less than or equals 1 rang (or equivalent in units) = 0 pal (excluding exceptions)
755
+ // - More thant 1 rang (or equivalent in units) = 1 pal
601
756
  let totalPal = (0, floor_1.default)(palQty);
602
757
  const unitsInRg = !!rgUnit ? rgUnit.fitting_unit || 0 : 0;
603
758
  const unitsInPal = palUnit.fitting_unit || 0;
759
+ // if qte gives round number of pallets, return totalPal
604
760
  if (item.qte / unitsInPal === totalPal)
605
761
  return totalPal;
762
+ // if rgQty and rgUnit are defined
606
763
  if (!!rgQty && !!rgUnit) {
607
764
  const rgInPal = (palUnit.fitting_unit || 1) / (rgUnit.fitting_unit || 1);
765
+ // if palQty is higher than 1 and at least 2 rang extra
608
766
  if (palQty >= 1 && (0, ceil_1.default)(rgQty % rgInPal) >= 2) {
609
767
  totalPal += 1;
610
768
  }
611
769
  else {
612
770
  if (palQty < 1) {
613
771
  if (!!unitQty) {
772
+ // if item is in exception list and at least 1 unit extra
614
773
  if (!!itemIsException && unitQty % unitsInPal !== 0) {
615
774
  totalPal += 1;
616
775
  }
617
776
  else if (!!unitsInRg && unitQty > unitsInRg && unitQty / unitsInRg > 1) {
777
+ // if unit count does not equal rang count and total unit count is higher than rang count
618
778
  totalPal += 1;
619
779
  }
620
780
  }
@@ -635,13 +795,29 @@ const calculatePalFeeForOtherThanGrass = (items) => {
635
795
  exports.calculatePalFeeForOtherThanGrass = calculatePalFeeForOtherThanGrass;
636
796
  const getMinGrassQte = (_grassProduct, expeditionMethod, _isPro) => {
637
797
  let minQteGrassOrder = 0;
798
+ // if (!![kentucky, prestige].includes(grassProduct.sku)) {
799
+ // if (expeditionMethod !== 'pickup') {
800
+ // minQteGrassOrder = !!isPro ? 1480 : 740
801
+ // }
802
+ // } else {
803
+ // // Grass product is Speciality Grass
804
+ // if (expeditionMethod === 'pickup') {
805
+ // minQteGrassOrder = 740
806
+ // } else {
807
+ // minQteGrassOrder = !!isPro ? 1480 : 740
808
+ // }
809
+ // }
810
+ // MODIF AVEC FRAIS 2024 - Même minimum facturable pour tous les gazons, et tous les clients
811
+ // Toujours 0 pour la cueillette (pas de minimum), et 740 en livraison
638
812
  if (expeditionMethod != 'pickup') {
639
- minQteGrassOrder = 740;
813
+ minQteGrassOrder = 740; // 1 pallet
640
814
  }
641
815
  return minQteGrassOrder;
642
816
  };
643
817
  exports.getMinGrassQte = getMinGrassQte;
644
818
  const getMinQteInstall = (_isPro) => {
819
+ // return !!isPro ? 2220 : 740
820
+ // MODIF AVEC FRAIS 2024 - Même minimum facturable pour tous les clients pour l'installation
645
821
  return 740;
646
822
  };
647
823
  exports.getMinQteInstall = getMinQteInstall;
@@ -667,12 +843,20 @@ const resetAllFeesIfAccessoriesOnly = (currentItems) => {
667
843
  }
668
844
  return itemsToDelete;
669
845
  };
670
- const checkIfShouldApplySameDayGrassFee = (firstDayForExpedition, expeditionMethod, selectedExpeditionDate, testDate) => {
846
+ const checkIfShouldApplySameDayGrassFee = (firstDayForExpedition, expeditionMethod, selectedExpeditionDate, testDate // for unit test. To test holiday + hour after 4PM
847
+ ) => {
848
+ // a. Check min date for expedition type (for POS carts)
671
849
  const dateToCheck = expeditionMethod === 'pickup' ? firstDayForExpedition.min_pickup : firstDayForExpedition.min_delivery;
672
850
  const dateSelectedIsBeforeFirstCalculatedDay = !!dateToCheck && (0, moment_1.default)((0, data_3.formatDate)(selectedExpeditionDate)).isBefore((0, moment_1.default)(dateToCheck), 'date');
851
+ // b. Check if current day is a holiday
673
852
  const isHoliday = (0, data_1.getHolidays)().some((h) => (0, moment_1.default)(h).isSame(testDate ? (0, moment_1.default)(testDate) : (0, moment_1.default)(), 'date'));
853
+ // c. Check if current time is after 4PM
674
854
  const isAfter4PM = (!!testDate ? (0, moment_1.default)(testDate) : (0, moment_1.default)()).hour() >= 16;
855
+ // d. Check if date selected is tomorrow
675
856
  const dateSelectedForExpeditionIsTomorrowOrToday = (0, moment_1.default)(selectedExpeditionDate).isSameOrBefore((0, moment_1.default)().add(1, 'day'), 'date');
857
+ // If date selected is before first calculated date for expedition,
858
+ // or order was created after 4PM/on a holiday and selected date for expedition is the next day,
859
+ // apply fees
676
860
  return (!!dateSelectedIsBeforeFirstCalculatedDay ||
677
861
  ((!!isHoliday || !!isAfter4PM) && !!dateSelectedForExpeditionIsTomorrowOrToday));
678
862
  };
@@ -683,17 +867,51 @@ const checkForSameGrassDayFee = (isPOS, isPro, totalPallet, grassProduct, select
683
867
  return !!selectedExepeditionDate && !!grassProduct && totalPallet >= 4 && (!!isPOS || !!isPro);
684
868
  };
685
869
  exports.checkForSameGrassDayFee = checkForSameGrassDayFee;
870
+ // Correspond to the qte after which the expedition or installation fee should be reapplied
871
+ // Eg. For each group of 24 pallets of a product, an expedition fee is added to the cart
686
872
  exports.expeditionFeePalletTier = 24;
687
873
  exports.installationFeePalletTier = 48;
874
+ /**
875
+ * Calculates fees that should be applied to provided cart, and fetches them from database or fee array if provided.
876
+ * Returns the items to add, update and delete, as well as other cart info to set after fees.
877
+ * ** Optimized version possible, where address zones and distance are calculated before and properties are sent directly to function
878
+ * ** Optimized version reverted, logic found in commit here : [#2087b32]{@link https://github.com/ciaoqc/gng-tb-admin-sdk/commit/2087b3207df9e5916a979b8bb255abc2a4c1dac6}
879
+ * @async
880
+ * @param fetchProduct
881
+ * @param getIfAddressIsInsideZones
882
+ * @param getDistanceFromAddress
883
+ * @param cart
884
+ * @param expeditionMethod
885
+ * @param grassProduct
886
+ * @param concreteOrder
887
+ * @param cartContainsInstallation
888
+ * @param cartContainsVrac
889
+ * @param availableVracStoreIDs
890
+ * @param isPro
891
+ * @param addOnePalletToPickup
892
+ * @param cartContainsSample
893
+ * @param saveToShippingPayload
894
+ * @param deliveryAddress
895
+ * @param locale
896
+ * @param expeditionDate
897
+ * @param equipmentPickupOnSite
898
+ * @param cartContainsOnlyAccessories
899
+ * @param pickupStore
900
+ * @param allStores
901
+ * @param customPriceList
902
+ * @param useFeeArray
903
+ */
688
904
  const applyFeesToCart = async (fetchProduct, getIfAddressIsInsideZones, getDistanceFromAddress, cart, expeditionMethod, grassProduct, concreteOrder, cartContainsInstallation, cartContainsVrac, availableVracStoreIDs, isPro, addOnePalletToPickup, cartContainsSample, saveToShippingPayload, deliveryAddress, locale, expeditionDate, equipmentPickupOnSite, cartContainsOnlyAccessories, pickupStore, allStores, customPriceList, useFeeArray) => {
689
905
  let itemsToAdd = [];
690
906
  let itemsToDelete = [];
691
907
  let itemsToUpdate = [];
692
908
  let newShippingPayload = cart.shipping_payload || {};
909
+ // Pour le minimum facturable de la livraison
693
910
  let minQteGrassOrder = 0;
694
911
  if (!!grassProduct) {
695
912
  minQteGrassOrder = (0, exports.getMinGrassQte)(grassProduct, expeditionMethod, isPro);
696
913
  }
914
+ // Vérification du type du cart
697
915
  const isPOS = [Cart_1.CartTypeEnum.POS, Cart_1.CartTypeEnum.POS_TRANSACTIONNAL].includes(cart.cart_type);
698
916
  const isMixed = cart.cart_content_type === Cart_1.CartContentTypeEnum.MIXED;
699
917
  let totalPalletOther = 0;
@@ -710,9 +928,14 @@ const applyFeesToCart = async (fetchProduct, getIfAddressIsInsideZones, getDista
710
928
  }
711
929
  const totalPallet = totalPalletGrass + totalPalletOther;
712
930
  const totalPalletMinQte = (0, exports.getPalletQty)(cart.items, !!concreteOrder ? 'concrete' : !!grassProduct ? 'grass' : undefined, minQteGrassOrder);
931
+ // Pour le minimum facturable de l'installation
713
932
  const minQteInstall = (0, exports.getMinQteInstall)(!!isPro);
933
+ // Type de cart (en ligne, en magasin, avec un commis, etc...)
714
934
  const cartType = !!isPOS ? 'in_store' : !!cart.clerk_id ? 'with_clerk' : 'online';
715
935
  const installAllInclusiveActive = (0, products_2.isInstallAllInclusiveActive)(cartContainsInstallation, isPro, customPriceList);
936
+ // --------------------------------------------------------------------------------------------------
937
+ // #region FRAIS PALETTE
938
+ // --------------------------------------------------------------------------------------------------
716
939
  const shouldAddPaletFees = !!!cartContainsInstallation && !!!cartContainsSample && !!!cartContainsVrac;
717
940
  if ((!!isMixed || !!shouldAddPaletFees) && (!!isPro || !!!grassProduct) && !!!cartContainsOnlyAccessories) {
718
941
  let qtyOfSkuNeeded = (0, exports.getPalletQtyPalletFee)(cart.items, expeditionMethod, !!(0, cart_1.checkIfCartContainsType)(cart_2.CartGeneralTypeEnum.GRASS, cart), isMixed);
@@ -733,6 +956,10 @@ const applyFeesToCart = async (fetchProduct, getIfAddressIsInsideZones, getDista
733
956
  }
734
957
  }
735
958
  }
959
+ // #endregion FRAIS PALETTE
960
+ // --------------------------------------------------------------------------------------------------
961
+ // #region COMMANDE GAZON - FRAIS DE LIVRAISON
962
+ // --------------------------------------------------------------------------------------------------
736
963
  if (!!grassProduct) {
737
964
  if (expeditionMethod === 'delivery') {
738
965
  const parentProduct = await fetchProduct('livraison-gazon', locale, !!useFeeArray, true);
@@ -786,6 +1013,10 @@ const applyFeesToCart = async (fetchProduct, getIfAddressIsInsideZones, getDista
786
1013
  return;
787
1014
  });
788
1015
  }
1016
+ // #endregion COMMANDE GAZON - FRAIS DE LIVRAISON
1017
+ // --------------------------------------------------------------------------------------------------
1018
+ // #region COMMANDE BETON - FRAIS DE LIVRAISON
1019
+ // --------------------------------------------------------------------------------------------------
789
1020
  if (!!!cartContainsVrac && !!!cartContainsSample && !!!grassProduct && !!!cartContainsOnlyAccessories) {
790
1021
  if (expeditionMethod === 'delivery') {
791
1022
  const parentProduct = await fetchProduct('livraison-beton-accessoires', locale, !!useFeeArray, true);
@@ -841,7 +1072,12 @@ const applyFeesToCart = async (fetchProduct, getIfAddressIsInsideZones, getDista
841
1072
  return;
842
1073
  });
843
1074
  }
1075
+ // #endregion COMMANDE BETON - FRAIS DE LIVRAISON
1076
+ // --------------------------------------------------------------------------------------------------
1077
+ // #region COMMANDE GAZON - MINIMUM FACTURABLE
1078
+ // --------------------------------------------------------------------------------------------------
844
1079
  if (!!grassProduct) {
1080
+ // In this case, prestige is included in speciality grasses, since the fee must include kentucky price too
845
1081
  const isSpecialityGrass = !!grassProduct && !!![products_4.kentucky].includes(grassProduct.sku);
846
1082
  const qtyToAdd = minQteGrassOrder - grassProduct.qte;
847
1083
  if (qtyToAdd > 0) {
@@ -867,13 +1103,19 @@ const applyFeesToCart = async (fetchProduct, getIfAddressIsInsideZones, getDista
867
1103
  itemsToDelete.push(minimumBillable.sku);
868
1104
  }
869
1105
  }
1106
+ // #endregion COMMANDE GAZON - MINIMUM FACTURABLE
1107
+ // --------------------------------------------------------------------------------------------------
1108
+ // #region COMMANDE GAZON - SURCHARGE JOUR MÊME
1109
+ // --------------------------------------------------------------------------------------------------
870
1110
  const sameDayGrassFee = await fetchProduct('surcharge-jour-meme-gazon', locale, !!useFeeArray, true);
871
1111
  let decli;
872
1112
  if (!!sameDayGrassFee) {
873
1113
  decli = sameDayGrassFee.declinations.find((d) => d.sku === '000010990');
874
1114
  }
875
1115
  if (!!(0, exports.checkForSameGrassDayFee)(isPOS, isPro, totalPalletGrass, grassProduct, expeditionDate, (0, object_1.recursiveCheckObject)(cart.shipping_payload, 'is_reserved'))) {
1116
+ // a. Fetch min date for expedition type (for POS carts)
876
1117
  const firstDayForExpedition = (0, exports.getMinDatePicker)(cart, grassProduct, undefined, expeditionMethod || 'delivery', !!isPro, !!cart.created_by ? (0, data_3.formatDate)(cart.created_by.date) : undefined, undefined, undefined, isPOS);
1118
+ // b. Call function to get if fee should be applied
877
1119
  const shouldApplySameDayFee = (0, exports.checkIfShouldApplySameDayGrassFee)(firstDayForExpedition, expeditionMethod, expeditionDate);
878
1120
  if (!!sameDayGrassFee && !!decli) {
879
1121
  if (!!shouldApplySameDayFee) {
@@ -886,6 +1128,10 @@ const applyFeesToCart = async (fetchProduct, getIfAddressIsInsideZones, getDista
886
1128
  itemsToDelete.push(decli.sku);
887
1129
  }
888
1130
  }
1131
+ // #endregion COMMANDE GAZON - SURCHARGE JOUR MÊME
1132
+ // --------------------------------------------------------------------------------------------------
1133
+ // #region LIVRAISON ÉCHANTILLONS
1134
+ // --------------------------------------------------------------------------------------------------
889
1135
  if (!!cartContainsSample) {
890
1136
  let removeShippingFee = false;
891
1137
  if (expeditionMethod === 'delivery') {
@@ -908,9 +1154,15 @@ const applyFeesToCart = async (fetchProduct, getIfAddressIsInsideZones, getDista
908
1154
  itemsToDelete.push(sampleDeliveryFee.sku);
909
1155
  }
910
1156
  }
1157
+ // #endregion LIVRAISON ÉCHANTILLONS
1158
+ // --------------------------------------------------------------------------------------------------
1159
+ // #region LIVRAISON ACCESSOIRES
1160
+ // --------------------------------------------------------------------------------------------------
911
1161
  const cartAccessoriesDeliveryFee = cart.items.find((i) => i.parent_slug === 'livraison-accessoires');
912
1162
  if (!!cartContainsOnlyAccessories) {
1163
+ // reset all service fees associated to grass or beton carts, if found
913
1164
  itemsToDelete = resetAllFeesIfAccessoriesOnly(cart.items);
1165
+ // check to add delivery fee
914
1166
  if (expeditionMethod === 'delivery') {
915
1167
  const productToAdd = await fetchProduct('livraison-accessoires', locale, !!useFeeArray, true);
916
1168
  if (!!productToAdd && !!productToAdd.declinations) {
@@ -926,6 +1178,11 @@ const applyFeesToCart = async (fetchProduct, getIfAddressIsInsideZones, getDista
926
1178
  itemsToDelete.push(cartAccessoriesDeliveryFee.sku);
927
1179
  }
928
1180
  }
1181
+ // #endregion LIVRAISON ACCESSOIRES
1182
+ // --------------------------------------------------------------------------------------------------
1183
+ // #region COMMANDE GAZON - SURCHARGE DE PRIX DE GAZON
1184
+ // --------------------------------------------------------------------------------------------------
1185
+ // Les surcharges sur le gazon s'appliquent toujours pour les pros, ou juste dans le cas de commandes d'une palette ou plus pour les clients au détail
929
1186
  const shouldApplyFees = !!isPro || totalPalletGrass >= 1;
930
1187
  if (!!grassProduct) {
931
1188
  const feesToAdd = [];
@@ -1004,7 +1261,10 @@ const applyFeesToCart = async (fetchProduct, getIfAddressIsInsideZones, getDista
1004
1261
  let allOrderFees = [];
1005
1262
  let allInstallationFees = [];
1006
1263
  if (!!shouldApplyFees) {
1264
+ // ---------------------------------------------------
1265
+ // #region Si la date de la commande est ...
1007
1266
  if (!!surchargesCommandesGazon) {
1267
+ // ... un samedi et que la commande est en livraison OU en pickup dans un magasin qui n'est pas rattaché à uen gazonnière
1008
1268
  if (orderDate.getDay() === 6) {
1009
1269
  if (expeditionMethod === 'delivery') {
1010
1270
  allOrderFees.push(['000010400', surchargesCommandesGazon]);
@@ -1015,57 +1275,75 @@ const applyFeesToCart = async (fetchProduct, getIfAddressIsInsideZones, getDista
1015
1275
  }
1016
1276
  }
1017
1277
  }
1278
+ // ... un dimanche ou jours fériés officiels
1279
+ // NOTE: seulement pour le frais gazon, celui d'installation s'applique indépendemment plus bas dans la logique
1018
1280
  if ((0, moment_1.default)(orderDate).day() === 0 ||
1019
1281
  (0, data_1.getHolidays)().some((date) => (0, moment_1.default)(date).isSame((0, moment_1.default)(orderDate), 'day'))) {
1020
1282
  allOrderFees = [...allOrderFees, ['000010850', surchargesCommandesGazon]];
1021
1283
  }
1284
+ // ... dans les vacances de construction
1022
1285
  const cd = (0, data_1.getContructionHolidays)();
1023
1286
  if ((0, moment_1.default)(orderDate).isBetween((0, moment_1.default)(cd[0]), (0, moment_1.default)(cd[1]), 'day', '[]')) {
1024
1287
  allOrderFees = [...allOrderFees, ['000010860', surchargesCommandesGazon]];
1025
1288
  }
1289
+ // ... en été
1026
1290
  const summer = (0, data_1.getSummerDate)();
1027
1291
  if ((0, moment_1.default)(orderDate).isBetween((0, moment_1.default)(summer[0]), (0, moment_1.default)(summer[1]), 'day', '[]')) {
1028
1292
  allOrderFees = [...allOrderFees, ['000010300', surchargesCommandesGazon]];
1029
1293
  }
1030
1294
  }
1295
+ // #endregion
1296
+ // ---------------------------------------------------
1297
+ // ---------------------------------------------------
1298
+ // #region Si la date de commande se trouve entre (inclusif)...
1299
+ // NOTE : les frais d'installation ne doivent seulement s'appliquer pour les clients pros (POS et WEB)
1031
1300
  const shouldAddGrassSeasonFee = !!surchargesCommandesGazonDebutFinSaison;
1032
1301
  const shouldAddInstallSeasonFee = !!cartContainsInstallation && !!isPro && !!surchargesInstallationGazonDebutFinSaison;
1302
+ // ...début de la saison au 30 avril
1033
1303
  if ((0, moment_1.default)(orderDate).isBetween(`${(0, moment_1.default)().format('YYYY')}-03-01`, `${(0, moment_1.default)().format('YYYY')}-04-30`, 'day', '[]')) {
1034
1304
  if (shouldAddGrassSeasonFee)
1035
1305
  allOrderFees = [...allOrderFees, ['000010100', surchargesCommandesGazonDebutFinSaison]];
1036
1306
  if (shouldAddInstallSeasonFee)
1037
1307
  allInstallationFees.push(['000010600', surchargesInstallationGazonDebutFinSaison]);
1038
1308
  }
1309
+ // ...15 oct. au 31 oct.
1039
1310
  if ((0, moment_1.default)(orderDate).isBetween(`${(0, moment_1.default)().format('YYYY')}-10-15`, `${(0, moment_1.default)().format('YYYY')}-10-31`, 'day', '[]')) {
1040
1311
  if (shouldAddGrassSeasonFee)
1041
1312
  allOrderFees = [...allOrderFees, ['000010840', surchargesCommandesGazonDebutFinSaison]];
1042
1313
  if (shouldAddInstallSeasonFee)
1043
1314
  allInstallationFees.push(['000010940', surchargesInstallationGazonDebutFinSaison]);
1044
1315
  }
1316
+ //...1er nov. au 14 nov.
1045
1317
  if ((0, moment_1.default)(orderDate).isBetween(`${(0, moment_1.default)().format('YYYY')}-11-01`, `${(0, moment_1.default)().format('YYYY')}-11-14`, 'day', '[]')) {
1046
1318
  if (shouldAddGrassSeasonFee)
1047
1319
  allOrderFees = [...allOrderFees, ['000010700', surchargesCommandesGazonDebutFinSaison]];
1048
1320
  if (shouldAddInstallSeasonFee)
1049
1321
  allInstallationFees.push(['000010800', surchargesInstallationGazonDebutFinSaison]);
1050
1322
  }
1323
+ // ...15 nov. à la fin de la saison
1051
1324
  if ((0, moment_1.default)(orderDate).isBetween(`${(0, moment_1.default)().format('YYYY')}-11-15`, `${(0, moment_1.default)().format('YYYY')}-12-31`, 'day', '[]')) {
1052
1325
  if (shouldAddGrassSeasonFee)
1053
1326
  allOrderFees = [...allOrderFees, ['000010900', surchargesCommandesGazonDebutFinSaison]];
1054
1327
  if (shouldAddInstallSeasonFee)
1055
1328
  allInstallationFees.push(['000010950', surchargesInstallationGazonDebutFinSaison]);
1056
1329
  }
1330
+ // #endregion
1331
+ // ---------------------------------------------------
1332
+ // Si la commande est en pick-up et le magazin n'est pas une gazonnière
1057
1333
  if (expeditionMethod === 'pickup' && !!surchargesGazonPickupHorsFerme) {
1058
1334
  if (!!!data_2.grassFarmStores.includes(pickupStoreId)) {
1059
1335
  allOrderFees = [...allOrderFees, ['000012500', surchargesGazonPickupHorsFerme]];
1060
1336
  }
1061
1337
  }
1062
1338
  }
1339
+ // Si la commande a de l'installation et la date de la commande est un dimanche ou un jour férié
1063
1340
  if (!!surchargesInstallationGazon &&
1064
1341
  !!cartContainsInstallation &&
1065
1342
  ((0, moment_1.default)(orderDate).day() === 0 ||
1066
1343
  (0, data_1.getHolidays)().some((date) => (0, moment_1.default)(date).isSame((0, moment_1.default)(orderDate), 'day')))) {
1067
1344
  allInstallationFees.push(['000010750', surchargesInstallationGazon]);
1068
1345
  }
1346
+ // Si la commande a été faite autrement qu'en ligne ET ne contient pas d'installation (PROS ONLY)
1069
1347
  if (!!fraisSiCommandePasEnLigne && !!!cartContainsInstallation && !!isPro) {
1070
1348
  allOrderFees = [...allOrderFees, ['FRSGAZON', fraisSiCommandePasEnLigne]];
1071
1349
  }
@@ -1093,7 +1371,15 @@ const applyFeesToCart = async (fetchProduct, getIfAddressIsInsideZones, getDista
1093
1371
  }
1094
1372
  });
1095
1373
  }
1374
+ // #endregion SURCHARGE DE PRIX DE GAZON
1375
+ // --------------------------------------------------------------------------------------------------
1376
+ // #region COMMANDE BÉTON - FRAIS DE PRÉPARATION
1377
+ // --------------------------------------------------------------------------------------------------
1096
1378
  if (!!concreteOrder && !!!cartContainsSample && !!!cartContainsOnlyAccessories) {
1379
+ // ----------------------------------------------------------------------------------------------
1380
+ // Frais de préparation général
1381
+ // MODIF FRAIS 2024 - Ajout du frais FP-1 seulement si le panier contient un minimum de 1 palette de produits de béton
1382
+ // Vérifie vraiment que les produits de béton pour la quantité
1097
1383
  const fraisPreparationGeneralBeton = await fetchProduct('frais-preparation-general-beton', locale, !!useFeeArray, true);
1098
1384
  const onlyConcretePalQty = (0, exports.getPalletQty)(cart.items.filter((i) => (0, products_2.checkIfProductIsOfType)(i, 'beton', true)));
1099
1385
  if (!!fraisPreparationGeneralBeton && onlyConcretePalQty >= 1) {
@@ -1102,8 +1388,12 @@ const applyFeesToCart = async (fetchProduct, getIfAddressIsInsideZones, getDista
1102
1388
  itemsToAdd.push(Object.assign(Object.assign({}, decli), { qte: 1, is_upsell_of_sku: 'summary', parent_slug: fraisPreparationGeneralBeton.slug, categories: fraisPreparationGeneralBeton.categories }));
1103
1389
  }
1104
1390
  }
1391
+ // ----------------------------------------------------------------------------------------------
1392
+ // Frais si commande pas en ligne/par un commis
1105
1393
  if (expeditionMethod !== 'pickup' && cartType !== 'online' && !!isPro) {
1106
1394
  const getFeeAmount = (decli) => {
1395
+ // fee is a percentage of price for each item that isn't a service or fee
1396
+ // percentage is determined by FRSBETON regular_price.value
1107
1397
  const percent = (0, toNumber_1.default)(decli.regular_price.amount);
1108
1398
  let amount = 0;
1109
1399
  for (let item of cart.items) {
@@ -1130,6 +1420,8 @@ const applyFeesToCart = async (fetchProduct, getIfAddressIsInsideZones, getDista
1130
1420
  itemsToDelete.push('FRSBETON');
1131
1421
  }
1132
1422
  }
1423
+ // ----------------------------------------------------------------------------------------------
1424
+ // Frais de préparation si commande contient 4 palettes incomplètes
1133
1425
  const concreteItems = cart.items.filter((i) => i.attributes[data_4.AttributesIdEnumGR.TYPE] && i.attributes[data_4.AttributesIdEnumGR.TYPE].includes('beton'));
1134
1426
  let numberOfIncompletePallets = 0;
1135
1427
  for (const item of concreteItems) {
@@ -1169,6 +1461,10 @@ const applyFeesToCart = async (fetchProduct, getIfAddressIsInsideZones, getDista
1169
1461
  itemsToDelete.push('FRSBETON');
1170
1462
  }
1171
1463
  }
1464
+ // #endregion COMMANDE BÉTON - FRAIS DE PRÉPARATION
1465
+ // --------------------------------------------------------------------------------------------------
1466
+ // #region FRAIS LIVRAISON SELON L'EMPLACEMENT
1467
+ // --------------------------------------------------------------------------------------------------
1172
1468
  let isOutOfArea = false;
1173
1469
  if (expeditionMethod === 'delivery' && !!deliveryAddress) {
1174
1470
  let insideZones = undefined;
@@ -1180,6 +1476,9 @@ const applyFeesToCart = async (fetchProduct, getIfAddressIsInsideZones, getDista
1180
1476
  }
1181
1477
  if (!!insideZones && !!Array.isArray(insideZones)) {
1182
1478
  if (!!insideZones.length && insideZones.includes('zone-gr')) {
1479
+ // =============================================================================================
1480
+ // TOUS TYPES DE COMMANDE
1481
+ // Si une ou plusieurs zones correspondent
1183
1482
  let productInstallToAdd;
1184
1483
  if (!!grassProduct) {
1185
1484
  productInstallToAdd = !!cartContainsInstallation
@@ -1194,6 +1493,7 @@ const applyFeesToCart = async (fetchProduct, getIfAddressIsInsideZones, getDista
1194
1493
  itemsToAdd.push(Object.assign(Object.assign({}, mtl), { qte: (0, ceil_1.default)((0, ceil_1.default)(totalPallet) / exports.expeditionFeePalletTier), is_upsell_of_sku: 'summary', parent_slug: 'surcharges-commandes-gazon', categories: productToAdd.categories }));
1195
1494
  }
1196
1495
  }
1496
+ // If Installation ...
1197
1497
  if (!!grassProduct && !!productInstallToAdd) {
1198
1498
  const mtlInstall = productInstallToAdd.declinations.find((i) => i.sku === '170055500');
1199
1499
  if (!!mtlInstall) {
@@ -1208,6 +1508,7 @@ const applyFeesToCart = async (fetchProduct, getIfAddressIsInsideZones, getDista
1208
1508
  itemsToAdd.push(Object.assign(Object.assign({}, ontario), { qte: (0, ceil_1.default)((0, ceil_1.default)(totalPallet) / exports.expeditionFeePalletTier), is_upsell_of_sku: 'summary', parent_slug: 'surcharges-commandes-gazon', categories: productToAdd.categories }));
1209
1509
  }
1210
1510
  }
1511
+ // If Installation ...
1211
1512
  if (!!grassProduct && !!productInstallToAdd) {
1212
1513
  const ontarioInstall = productInstallToAdd.declinations.find((i) => i.sku === '170033ONT');
1213
1514
  if (!!ontarioInstall) {
@@ -1223,11 +1524,18 @@ const applyFeesToCart = async (fetchProduct, getIfAddressIsInsideZones, getDista
1223
1524
  }
1224
1525
  }
1225
1526
  }
1527
+ // }
1528
+ // =============================================================================================
1529
+ // COMMANDES VRAC
1530
+ // Infos pour la livraison du vrac, vérification faite maintenant dans deux zones
1226
1531
  if (!!cartContainsVrac) {
1227
1532
  if (insideZones.includes('zone-vrac') || insideZones.includes('zone-vrac-les-coteaux')) {
1228
1533
  const deliveryTruckProduct = await fetchProduct('frais-de-livraison-vrac', locale, !!useFeeArray, true);
1534
+ // Fetch de l'adresse du magasin de la zone concernée, pour calculer le prix du frais de livraison
1229
1535
  const storeIDToCheck = insideZones.includes('zone-vrac') ? 'sainte-julie-nobel' : 'default';
1230
1536
  const storeAddress = getStoreAddressByID(allStores, storeIDToCheck);
1537
+ // Si le magasin de la zone ne se trouve pas dans le array de magasins disponibles pour les produits de vrac de la commande,
1538
+ // mettre la commande comme hors-zone automatiquement
1231
1539
  if (!!availableVracStoreIDs && !availableVracStoreIDs.includes(storeIDToCheck)) {
1232
1540
  isOutOfArea = true;
1233
1541
  }
@@ -1265,8 +1573,16 @@ const applyFeesToCart = async (fetchProduct, getIfAddressIsInsideZones, getDista
1265
1573
  itemsToDelete.push(i.sku);
1266
1574
  }
1267
1575
  });
1576
+ // #endregion FRAIS LIVRAISON SELON L'EMPLACEMENT
1577
+ // --------------------------------------------------------------------------------------------------
1578
+ // #region RAMASSAGE D'ÉQUIPEMENT SUR LE CHANTIER
1579
+ // --------------------------------------------------------------------------------------------------
1268
1580
  if (!!equipmentPickupOnSite) {
1581
+ // consoleLog({ equipmentPickupOnSite: 'true' })
1269
1582
  }
1583
+ // #endregion RAMASSAGE D'ÉQUIPEMENT SUR LE CHANTIER
1584
+ // --------------------------------------------------------------------------------------------------
1585
+ // #region FRAIS EXTRA LIVRAISON EN PÉRIODE DE DÉGEL
1270
1586
  const degelFeeSku = '170000018';
1271
1587
  if (!!isPro &&
1272
1588
  expeditionMethod === 'delivery' &&
@@ -1287,6 +1603,9 @@ const applyFeesToCart = async (fetchProduct, getIfAddressIsInsideZones, getDista
1287
1603
  itemsToDelete.push(degelFeeSku);
1288
1604
  }
1289
1605
  }
1606
+ // #endregion
1607
+ // --------------------------------------------------------------------------------------------------
1608
+ // #region Gestion d'ajout / delete des frais
1290
1609
  itemsToDelete = itemsToDelete.filter((i) => !itemsToAdd.map((add) => add.sku).includes(i));
1291
1610
  itemsToAdd = itemsToAdd
1292
1611
  .map((item) => {
@@ -1301,14 +1620,17 @@ const applyFeesToCart = async (fetchProduct, getIfAddressIsInsideZones, getDista
1301
1620
  }
1302
1621
  }
1303
1622
  else {
1623
+ // If fee regular price is 0.00$ and item fits criteria, do not add to cart
1304
1624
  if (!!item.parent_slug &&
1305
1625
  (0, products_2.shouldHideItemIfRegPriceIs0)(item, item.parent_slug, !!item.is_upsell_of_sku && item.parent_slug.includes('installation'))) {
1306
1626
  return;
1307
1627
  }
1308
1628
  }
1629
+ // When installation all-inclusive, force frais de livraison to 0$
1309
1630
  return installAllInclusiveActive ? (0, products_2.applyAllInclusiveOverrides)(item) : item;
1310
1631
  })
1311
1632
  .filter((i) => !!i);
1633
+ // #endregion Gestion d'ajout / delete des frais
1312
1634
  return {
1313
1635
  newCart: Object.assign(Object.assign({}, cart), { shipping_payload: newShippingPayload }),
1314
1636
  itemsToDelete,
@@ -1319,6 +1641,19 @@ const applyFeesToCart = async (fetchProduct, getIfAddressIsInsideZones, getDista
1319
1641
  };
1320
1642
  };
1321
1643
  exports.applyFeesToCart = applyFeesToCart;
1644
+ // #endregion
1645
+ // ------------------------------------------------------------------------------------------
1646
+ // ------------------------------------------------------------------------------------------
1647
+ // #region SHIPPING
1648
+ /**
1649
+ * Checks if sample shipping fee should be removed from cart depending on cart items found in cart.
1650
+ * ** Optimized version possible using brand name instead of brand id, removing async check.
1651
+ * ** Optimized version reverted, logic found in commit here : [#2087b32]{@link https://github.com/ciaoqc/gng-tb-admin-sdk/commit/2087b3207df9e5916a979b8bb255abc2a4c1dac6}
1652
+ * @param fetchProduct
1653
+ * @param cart
1654
+ * @param locale
1655
+ * @param useFeeArray
1656
+ */
1322
1657
  const checkIfShouldRemoveSampleShippingFee = async (fetchProduct, cart, locale, useFeeArray) => {
1323
1658
  if (!!!cart.items)
1324
1659
  return false;
@@ -1327,13 +1662,16 @@ const checkIfShouldRemoveSampleShippingFee = async (fetchProduct, cart, locale,
1327
1662
  for (let item of currentItems) {
1328
1663
  if (!!!item.parent_slug)
1329
1664
  continue;
1665
+ // 1. Get parent product for brand ID
1330
1666
  const parentProd = await fetchProduct(item.parent_slug, locale, !!useFeeArray, true);
1331
1667
  if (!!!parentProd)
1332
1668
  continue;
1333
1669
  const brand = parentProd.brand;
1670
+ // 2. Check if item.attributes contains FAMILY attribute with value Tena
1334
1671
  const isTena = !!item.attributes &&
1335
1672
  !!item.attributes[data_4.AttributesIdEnumGR.FAMILY] &&
1336
1673
  !!item.attributes[data_4.AttributesIdEnumGR.FAMILY].includes('tena');
1674
+ // 3. Check if item.attributes.TYPE is grass and is not Kentucky or Prestige
1337
1675
  const excludedGrass = [`${products_4.kentucky}-e`, `${products_4.prestige}-e`];
1338
1676
  const hasGrassType = (0, products_2.checkIfProductIsOfType)(item, 'gazon');
1339
1677
  const isExcludedGrass = excludedGrass.includes(item.sku);
@@ -1348,10 +1686,14 @@ const checkIfShouldRemoveSampleShippingFee = async (fetchProduct, cart, locale,
1348
1686
  if (!!currentItemsChecked.length) {
1349
1687
  const allIncludedBrandsNoTena = currentItemsChecked.filter((item) => !!item.brand && !!data_2.includedFreeShippingBrands.includes(item.brand) && !!!item.isTena);
1350
1688
  const allGrass = currentItemsChecked.filter((item) => !!item.isGrass);
1689
+ // 3. count all items with included brands and check if length === currentItems.length
1690
+ // if true, remove shipping cost (set productToAdd undefined)
1351
1691
  if (currentItems.length === allIncludedBrandsNoTena.length || currentItems.length === allGrass.length) {
1352
1692
  return true;
1353
1693
  }
1354
1694
  else {
1695
+ // 4. add IncludedBrandsNoTena + isGrass lengths and check if equals currentItems.length
1696
+ // if true, remove shipping cost (set productToAdd undefined)
1355
1697
  const added = allIncludedBrandsNoTena.length + allGrass.length;
1356
1698
  if (added === currentItems.length) {
1357
1699
  return true;
@@ -1497,22 +1839,66 @@ const getStoreAddressByID = (allStores, storeID) => {
1497
1839
  const sameStore = allStores.find((s) => s.id == storeID);
1498
1840
  return !!sameStore ? sameStore.address : undefined;
1499
1841
  };
1842
+ // #endregion
1843
+ // ------------------------------------------------------------------------------------------
1844
+ // ------------------------------------------------------------------------------------------
1845
+ // #region VALIDATION
1846
+ /**
1847
+ * Function checkIfCartExpired
1848
+ * @description checks if cart expired using the updated_at date stored in the shipping_payload
1849
+ * @param cartData
1850
+ * @param grassProduct
1851
+ * @param concreteOrder
1852
+ * @param isPro
1853
+ * @param options.blocked_shipping_dates
1854
+ * @param options.vracType
1855
+ * @param options.chosenPaymentType
1856
+ * @param options.forceCheckForCartTypes
1857
+ */
1500
1858
  const checkIfCartExpired = (cartData, grassProduct, concreteOrder, isPro, options = {}) => {
1859
+ // ######################################################################################
1860
+ // #region TESTS
1861
+ // ----------------------------------------------------------
1862
+ // 1) Is same day after 10
1863
+ // const test1 = {
1864
+ // now: moment().set('hours', 11).toDate(),
1865
+ // updated_last: moment().set('hours', 9).toDate(),
1866
+ // time: 'AM',
1867
+ // selected_date: moment().add(4, 'day').toDate()
1868
+ // }
1869
+ // 2) Is same day after 10 but with AM still possible
1870
+ // const test2 = {
1871
+ // now: moment().set({ day: 6, hours: 11 }).toDate(),
1872
+ // updated_last: moment().set({ day: 6, hours: 9 }).toDate(),
1873
+ // time: 'AM',
1874
+ // selected_date: moment().set('day', 9).toDate()
1875
+ // }
1876
+ // const now = test2.now
1877
+ // const updated_last = test2.updated_last
1878
+ // const time = test2.time
1879
+ // const selected_date = test2.selected_date
1880
+ //
1881
+ // #endregion
1882
+ // ######################################################################################
1501
1883
  const isPOS = Cart_1.CartTypeEnum.WEB != cartData.cart_type;
1502
1884
  const isSample = (0, cart_1.checkIfCartContainsType)(cart_2.CartGeneralTypeEnum.SAMPLE, cartData);
1503
1885
  const isAccessoriesOnly = (0, cart_1.checkIfCartContainsType)(cart_2.CartGeneralTypeEnum.ONLY_ACCESSORIES, cartData);
1886
+ // const cartContainsInstallation = checkIfCartContainsType(CartGeneralTypeEnum.INSTALLATION, cartData)
1887
+ // 1. Check if it is normal for selected date to be undefined / expired
1504
1888
  const selectedDate = !!cartData.shipping_payload && !!cartData.shipping_payload.delivery_or_pickup_date
1505
1889
  ? (0, data_3.formatDate)(cartData.shipping_payload.delivery_or_pickup_date)
1506
1890
  : undefined;
1507
1891
  const noDeliveryDateIsNormal = (0, exports.checkIfNoDeliveryDateIsNormal)(cartData, concreteOrder) ||
1508
1892
  (!!options.chosenPaymentType && ['depot'].includes(options.chosenPaymentType));
1509
1893
  const shouldForceCheck = (options.forceCheckForCartTypes || []).some((t) => (0, cart_1.checkIfCartContainsType)(t, cartData));
1894
+ // If force check property sent, check event if !!noDeliveryDateIsNormal
1510
1895
  if (!!noDeliveryDateIsNormal && !shouldForceCheck) {
1511
1896
  return false;
1512
1897
  }
1513
1898
  else if (!!!selectedDate) {
1514
1899
  return true;
1515
1900
  }
1901
+ // 2. Check date depending on when cart was last updated
1516
1902
  const now = (0, moment_1.default)().toDate();
1517
1903
  const updated_last = !!cartData.shipping_payload && !!cartData.shipping_payload.updated_at
1518
1904
  ? (0, data_3.formatDate)(cartData.shipping_payload.updated_at)
@@ -1541,4 +1927,6 @@ const checkIfNoDeliveryDateIsNormal = (cartData, concreteOrder, checkForInputSho
1541
1927
  ((!!isAccessoriesOnly || !!isSample) && !!!cartData.is_pickup));
1542
1928
  };
1543
1929
  exports.checkIfNoDeliveryDateIsNormal = checkIfNoDeliveryDateIsNormal;
1930
+ // #endregion
1931
+ // ------------------------------------------------------------------------------------------
1544
1932
  //# sourceMappingURL=expedition.js.map