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
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.transformCreditNoteToG2Order = exports.transformAddioCartToG2Order = exports.getDefaultG2OrderItem = void 0;
7
7
  const G2OrderSlip_1 = __importDefault(require("./G2OrderSlip"));
8
8
  const logs_1 = require("../logs");
9
+ // Utils
9
10
  const round_1 = __importDefault(require("lodash/round"));
10
11
  const products_1 = require("../../rules/GR/constants/products");
11
12
  const cart_1 = require("../../rules/GR/utils/cart");
@@ -21,9 +22,14 @@ const services_1 = require("../../utils/services");
21
22
  const context_1 = require("../../utils/context");
22
23
  const string_1 = require("../../utils/string");
23
24
  const __1 = require("../..");
25
+ // Interfaces and Enums
24
26
  const Cart_1 = require("../../Interfaces/Cart");
25
27
  const cart_3 = require("../../rules/GR/interfaces/cart");
26
28
  const refunds_1 = require("../../utils/refunds");
29
+ /**
30
+ * Creates a partial G2OrderItem with all non-nullable properties with default values
31
+ * @param noArticle Optionnal. If not provided, sets noArticle as an empty string.
32
+ */
27
33
  const getDefaultG2OrderItem = (noArticle) => ({
28
34
  noArticle: noArticle || '',
29
35
  libreNum1: 0,
@@ -37,19 +43,29 @@ const getDefaultG2OrderItem = (noArticle) => ({
37
43
  coutdeVenteUnitaire: 0
38
44
  });
39
45
  exports.getDefaultG2OrderItem = getDefaultG2OrderItem;
46
+ /**
47
+ * Creates a G2OrderSlip object from provided Addio cart data. Only works if provided space has G2 set in external_services.
48
+ * @param addioCart
49
+ * @param space
50
+ * @param orgId
51
+ */
40
52
  const transformAddioCartToG2Order = async (addioCart, space, orgId, isTest, creditNote) => {
53
+ // Check if cart to transform is higher status than 5 (CartStatusEnum.CHECKOUT_PAYMENT_SUCCESS)
41
54
  if (addioCart.status < Cart_1.CartStatusEnum.CHECKOUT_PAYMENT_SUCCESS) {
42
55
  console.error("can't create an order slip for a non-paid cart. Returning!");
43
56
  return;
44
57
  }
58
+ // Check if space has G2 set
45
59
  const g2Service = space.services({ field: 'external_service_name', value: 'G2' });
46
60
  if (!!!g2Service.length ||
47
61
  !!!(0, object_1.recursiveCheckObject)(g2Service[0], 'external_service_infos.specific_actions.save_order_to_g2')) {
48
62
  console.error('space does not have G2 in external_services or does not save order property. Returning!');
49
63
  return;
50
64
  }
65
+ // Create base g2OrderSlip obj
51
66
  const g2OrderObj = new G2OrderSlip_1.default(space, orgId);
52
67
  const data = { addioCart, creditNote, g2OrderObj, space, orgId };
68
+ // Update with Addio cart values
53
69
  try {
54
70
  await _constructGeneralData(data, isTest);
55
71
  _constructBillingData(data);
@@ -65,6 +81,8 @@ const transformAddioCartToG2Order = async (addioCart, space, orgId, isTest, cred
65
81
  }
66
82
  };
67
83
  exports.transformAddioCartToG2Order = transformAddioCartToG2Order;
84
+ // =================================================================
85
+ // #region GENERAL FUNCTIONS FOR DATA
68
86
  const _getCustomerData = (addioCart, dataToReturn, space) => {
69
87
  switch (dataToReturn) {
70
88
  case 'id':
@@ -87,6 +105,7 @@ const _getCustomerData = (addioCart, dataToReturn, space) => {
87
105
  : (0, object_1.recursiveCheckObject)(addioCart, 'customer_info.previous_terms_code') ||
88
106
  (0, object_1.recursiveCheckObject)(addioCart, 'customer_info.terms_code') ||
89
107
  'P.S.L.';
108
+ //TODO - Attendre confirmation de la facturation qu'on envoie P.S.L. pour tous les clients où la valeur n'est pas définie (même les clients au détail)
90
109
  }
91
110
  };
92
111
  const _getTransformCartProps = (addioCart) => {
@@ -98,9 +117,15 @@ const _getTransformCartProps = (addioCart) => {
98
117
  isPickup: !!(0, object_1.recursiveCheckObject)(addioCart, 'is_pickup')
99
118
  };
100
119
  };
120
+ // #endregion
121
+ // =================================================================
122
+ // #region CONSTRUCT SPECIFIC G2 ORDER DATA SECTIONS
123
+ // ----------------------
124
+ // General data
101
125
  const _constructGeneralData = async (data, _isTest) => {
102
126
  const { addioCart, g2OrderObj, space, creditNote } = data;
103
127
  const isWebCart = addioCart.cart_type == Cart_1.CartTypeEnum.WEB;
128
+ // A. Tax province
104
129
  let taxProvince = 'QC';
105
130
  const cartShippingAddress = (0, object_1.recursiveCheckObject)(addioCart, 'shipping_address.address');
106
131
  if (!!cartShippingAddress && cartShippingAddress.state != taxProvince) {
@@ -108,21 +133,28 @@ const _constructGeneralData = async (data, _isTest) => {
108
133
  if (!!shortCartShippingState)
109
134
  taxProvince = shortCartShippingState;
110
135
  }
136
+ // B. Rep. number
111
137
  const repNumber = !!isWebCart ? 'WEB' : (0, object_1.recursiveCheckObject)(addioCart, 'created_by.user_external_id') || 'NOUVEAU';
138
+ // C. All default data for G2Order
112
139
  g2OrderObj.setNoClient(_getCustomerData(addioCart, 'id', space));
113
140
  g2OrderObj.setNoProvinceTaxation(taxProvince);
114
141
  g2OrderObj.setCondition(_getCustomerData(addioCart, 'termsCode', space));
115
142
  g2OrderObj.setNoRepresentant(repNumber);
116
143
  g2OrderObj.setDate(!!addioCart.paid_at ? (0, data_1.formatDate)(addioCart.paid_at) : null);
117
144
  const cartRef = addioCart.ref || '';
118
- const cartInvoice = addioCart.invoice_ref || '';
145
+ const cartInvoice = addioCart.invoice_ref || ''; // Replace - in invoice_ref so it can be searched for in G2
119
146
  g2OrderObj.setNoCommDuClient(`${cartRef}${!!cartInvoice && !!cartRef ? '/' : ''}${cartInvoice.replace('-', '')}`);
147
+ // C. Description
148
+ // For description, always contains order number. If non-pro customer, add customer name too.
149
+ // NOTE - Check if full name + order ref is longer thant limit (25 characters). If so, use only lastname. If still too long, only use order ref.
120
150
  let customerName = !(0, cart_1.isPro)(addioCart) ? _getCustomerData(addioCart, 'fullname', space) : '';
151
+ // Check if higher than 24 caracters (which is the max of 25 - the space in between sections)
121
152
  if (customerName.length + cartRef.length > 24) {
122
153
  const customerLastName = _getCustomerData(addioCart, 'lastname', space);
123
154
  customerName = customerLastName.length + cartRef.length <= 24 ? customerLastName : '';
124
155
  }
125
156
  g2OrderObj.setDescription(`${!!customerName ? customerName + ' ' : ''}${addioCart.ref || ''}`);
157
+ // D. Commandé par
126
158
  let name = (0, object_1.recursiveCheckObject)(addioCart, 'billing_address.expedition_recipient_name') || '';
127
159
  name = name.replace('%', ' ').slice(0, 50);
128
160
  let tel = (0, object_1.recursiveCheckObject)(addioCart, 'billing_address.expedition_recipient_phone') || '';
@@ -130,12 +162,15 @@ const _constructGeneralData = async (data, _isTest) => {
130
162
  const fullLength = name.length + tel.length;
131
163
  let orderedByValue = `${name}${!!name && !!tel && fullLength <= 49 ? ' ' : ''}${fullLength <= 49 ? tel : ''}`;
132
164
  g2OrderObj.setCommandePar(orderedByValue || null);
165
+ // E. Refund data
133
166
  if (!!creditNote) {
134
167
  g2OrderObj.setNoteDeCredit(true);
135
168
  g2OrderObj.setNoCommDuClient(`${(0, refunds_1.formatRefundInvoiceRef)(creditNote.ref, space, creditNote.groupCode).replace('-', '')}${!!creditNote.ref && !!cartRef ? '/' : ''}${cartRef}`);
169
+ // Add #memo
136
170
  if (!!creditNote.secondaryRef) {
137
171
  g2OrderObj.setNotes(`# mémo de retour: ${creditNote.secondaryRef}` + '\r\n');
138
172
  }
173
+ // Add notes
139
174
  if (!!creditNote.notes) {
140
175
  g2OrderObj.setNotes(creditNote.notes.replace('\n\n', '\r\n') + '\r\n');
141
176
  }
@@ -149,9 +184,11 @@ const _constructGeneralData = async (data, _isTest) => {
149
184
  }
150
185
  }
151
186
  if ((0, cart_1.checkIfCartContainsType)(cart_3.CartGeneralTypeEnum.RETURN_PALLETS, addioCart)) {
187
+ // Add #memo
152
188
  if (!!addioCart.shipping_payload.pallet_return_memo_ref) {
153
189
  g2OrderObj.setNotes(`# mémo de retour: ${addioCart.shipping_payload.pallet_return_memo_ref}` + '\r\n');
154
190
  }
191
+ // Add notes
155
192
  if (!!addioCart.message) {
156
193
  g2OrderObj.setNotes(addioCart.message.replace('\n\n', '\r\n') + '\r\n');
157
194
  }
@@ -164,6 +201,7 @@ const _constructExtraData = (data) => {
164
201
  if (!!cancelledDate)
165
202
  g2OrderObj.setDateAnnulation((0, data_1.formatDate)(cancelledDate));
166
203
  }
204
+ // TODO - Vérifier si autres valeurs à pousser ici?
167
205
  if (!!addioCart.payment_reference && !creditNote) {
168
206
  g2OrderObj.setNotes(`#ref. paiement : ${addioCart.payment_reference}\r\n`);
169
207
  }
@@ -171,6 +209,8 @@ const _constructExtraData = (data) => {
171
209
  g2OrderObj.setNotes(`code postal de la carte de crédit : ${(0, object_1.recursiveCheckObject)(addioCart, 'shipping_payload.credit_card_postal_code')}\r\n`);
172
210
  }
173
211
  };
212
+ // ----------------------
213
+ // Expedition data
174
214
  const _constructBillingData = (data) => {
175
215
  const { addioCart, g2OrderObj, space } = data;
176
216
  const cartBillingInfo = addioCart.billing_address;
@@ -203,6 +243,7 @@ const _constructShippingData = (data) => {
203
243
  const { addioCart, g2OrderObj, space, creditNote } = data;
204
244
  const cartRef = addioCart.ref || '';
205
245
  const invoiceRef = addioCart.invoice_ref || '';
246
+ // A. Set address data
206
247
  if (!!creditNote) {
207
248
  const refundStore = space.preferences.stores.get().find((s) => s.id == creditNote.groupCode);
208
249
  g2OrderObj.setLivreaNom(`RETOUR${!!refundStore ? ' ' + refundStore.name : ''}`);
@@ -214,7 +255,7 @@ const _constructShippingData = (data) => {
214
255
  const sameStore = space.preferences.stores.get().find((s) => s.id == pickupStoreID);
215
256
  g2OrderObj.setLivreaNom(`PICK UP${!!sameStore ? ' ' + sameStore.name : ''}`);
216
257
  g2OrderObj.setLivreaDepartement(`${cartRef}${!!cartRef && !!invoiceRef ? '/' : ''}${invoiceRef.replace('-', '')}`);
217
- g2OrderObj.setTransport('PICK-UP');
258
+ g2OrderObj.setTransport('PICK-UP'); // TODO - Vérifier avec G2 les valeurs, semble être un enum/select dans les captures de la facturation?
218
259
  }
219
260
  else {
220
261
  const cartShippingInfo = addioCart.shipping_address;
@@ -228,8 +269,9 @@ const _constructShippingData = (data) => {
228
269
  g2OrderObj.setLivreaCodePostal(cartShippingInfo.address.postal_code);
229
270
  g2OrderObj.setLivreaPays(cartShippingInfo.address.country);
230
271
  }
231
- g2OrderObj.setTransport('LIVRAISON');
272
+ g2OrderObj.setTransport('LIVRAISON'); // TODO - Vérifier avec G2 les valeurs, semble être un enum/select dans les captures de la facturation?
232
273
  }
274
+ // B. Date expected for order
233
275
  if (!creditNote) {
234
276
  const cartForDate = (0, object_1.recursiveCheckObject)(addioCart, 'shipping_payload.delivery_or_pickup_date');
235
277
  const timeOfDay = (0, object_1.recursiveCheckObject)(addioCart, 'shipping_payload.delivery_period');
@@ -253,6 +295,8 @@ const _constructShippingData = (data) => {
253
295
  }
254
296
  }
255
297
  };
298
+ // ----------------------
299
+ // Customer data
256
300
  const _constructCustomerData = async (data) => {
257
301
  const { addioCart, g2OrderObj, space, orgId } = data;
258
302
  let joursEcheance = null;
@@ -271,6 +315,7 @@ const _constructCustomerData = async (data) => {
271
315
  joursEcheance = sameCustomer.conditionsReglements.conditionReglement.joursÉchéance;
272
316
  joursReglementAnticipe = sameCustomer.conditionsReglements.conditionReglement.joursRèglementAnticipé;
273
317
  pourcEscReglementAnticipe = sameCustomer.conditionsReglements.conditionReglement.pourcEscRèglementAnticipé;
318
+ // If commandePar props is still empty here, set with G2 value by default
274
319
  if (!!!g2OrderObj.data().commandePar && (0, cart_1.isPro)(addioCart)) {
275
320
  let valueToUse = sameCustomer.client.personneRessourceVentes || '';
276
321
  valueToUse = valueToUse.slice(0, 50);
@@ -285,18 +330,22 @@ const _constructCustomerData = async (data) => {
285
330
  g2OrderObj.setJoursReglementAnticipe(joursReglementAnticipe);
286
331
  g2OrderObj.setPourcEscReglementAnticipe(pourcEscReglementAnticipe);
287
332
  };
333
+ // ----------------------
334
+ // Items (including promos and extra items)
288
335
  const _constructAllItems = async (data) => {
289
336
  var _a;
290
337
  if (!!!data.addioCart)
291
338
  return;
292
339
  const allOptions = _getTransformCartProps(data.addioCart);
293
340
  let subtotalToUse = 0;
341
+ // 1. Add all cart items
294
342
  try {
295
343
  subtotalToUse = await _constructProductItems(allOptions, data);
296
344
  }
297
345
  catch (e) {
298
346
  console.error('error on transforming items for G2: ', e.toString());
299
347
  }
348
+ // 2. Add all cart promos applied as items
300
349
  if (!!subtotalToUse) {
301
350
  try {
302
351
  subtotalToUse = await _constructPromoItems(subtotalToUse, allOptions, data);
@@ -305,6 +354,7 @@ const _constructAllItems = async (data) => {
305
354
  console.error('error on transforming promos for G2: ', e.toString());
306
355
  }
307
356
  }
357
+ // 3. Add refund item if defined in credit note
308
358
  if (!!data.creditNote && !!data.creditNote.refundFeesAmount) {
309
359
  try {
310
360
  await _constructRefundFeeItem(data);
@@ -313,6 +363,7 @@ const _constructAllItems = async (data) => {
313
363
  console.error('error on adding refund fee item to G2 order: ', e.toString());
314
364
  }
315
365
  }
366
+ // 4. If cart is shipping to Ontario, add Ontario Tax product
316
367
  if (allOptions.shippingToOntario) {
317
368
  try {
318
369
  await _constructOntarioTaxItem(subtotalToUse, data);
@@ -321,10 +372,13 @@ const _constructAllItems = async (data) => {
321
372
  console.error('error on adding Ontario tax item to G2 order: ', e.toString());
322
373
  }
323
374
  }
375
+ // 4. Add specific line for cart type
324
376
  if (!data.creditNote) {
325
377
  _constructCartTypeItem(data);
378
+ // 5. Add specific line for person on site
326
379
  _constructPersonOnSiteItem(data);
327
380
  }
381
+ // Last check : if subtotal is not the same at the end, log error
328
382
  if (subtotalToUse.toFixed(2) !== data.addioCart.subtotal.toFixed(2)) {
329
383
  const logTxt = `Something went wrong! Subtotals don't match... calculated subtotal: ${subtotalToUse.toFixed(2)}, cart subtotal: ${data.addioCart.subtotal.toFixed(2)}`;
330
384
  if (!__1.isTestEnv) {
@@ -347,6 +401,7 @@ const _constructProductItems = async (allOptions, data) => {
347
401
  try {
348
402
  const { g2Item, internalMsgForItem } = await _transformCartItemToPartialG2Item(item, data.space, data.orgId, allOptions);
349
403
  data.g2OrderObj.addItemLineToOrder(g2Item, internalMsgForItem);
404
+ // Calculate new subtotal by adding item amount
350
405
  const escompteApplied = !!g2Item.pourcEscompte ? (100 - g2Item.pourcEscompte) / 100 : 1;
351
406
  calculatedSubtotal += (g2Item.prixUnitaire || 0) * escompteApplied * (g2Item.quantite || 0);
352
407
  }
@@ -361,6 +416,7 @@ const _constructPromoItems = async (subtotalToUse, allOptions, data) => {
361
416
  if (!!!data.addioCart)
362
417
  return 0;
363
418
  let allPromos = (0, discount_1.getCartPromo)(data.addioCart) || [];
419
+ // 1. Check for non incentive promos
364
420
  let allNonIncentivePromos = allPromos.filter((p) => p.applies_to !== Cart_1.CartPromoAppliesToEnum.TOTAL_AFTER_TAXES);
365
421
  let promoAmountData = (0, cart_2.getAllPromoAppliedPrices)(allNonIncentivePromos, subtotalToUse, data.addioCart.items, data.space, !!data.creditNote);
366
422
  let calculatedSubtotal = subtotalToUse;
@@ -372,15 +428,18 @@ const _constructPromoItems = async (subtotalToUse, allOptions, data) => {
372
428
  console.error('could not find corresponding cart promo for id: ', promoAmounts.id);
373
429
  continue;
374
430
  }
431
+ // A. Find same discount_rule for data
375
432
  const sameDiscountRule = data.addioCart.discount_rules.find((d) => d.id == promoToCheckID);
376
433
  const externalValueForG2 = !!sameDiscountRule
377
434
  ? (0, object_1.recursiveCheckObject)(sameDiscountRule, 'external_values.noArticle')
378
435
  : undefined;
436
+ // B. Find entry in calculated amounts and check which value to use for promo quantity in G2 order
379
437
  const amountToUseForQuantity = [Cart_1.CartPromoAppliesToEnum.PRODUCT, Cart_1.CartPromoAppliesToEnum.ITEMS].includes(promoAmounts.appliesTo)
380
438
  ? promoAmounts.productTotalAmount
381
439
  : samePromoInCartApplied.amount_unit && samePromoInCartApplied.amount_unit.includes('amount')
382
440
  ? 1
383
441
  : promoAmounts.subtotalBefore;
442
+ // C. Transform promo to g2 item
384
443
  const { g2Item, internalMsgForItem } = await _transformCartPromoToPartialG2Item(samePromoInCartApplied, externalValueForG2, amountToUseForQuantity, data.space, data.orgId, allOptions);
385
444
  data.g2OrderObj.addItemLineToOrder(g2Item, internalMsgForItem);
386
445
  }
@@ -388,15 +447,19 @@ const _constructPromoItems = async (subtotalToUse, allOptions, data) => {
388
447
  console.error('error on transforming item to G2 item: ', e.toString());
389
448
  }
390
449
  }
450
+ // update subtotal with all promos applied by using last promo applied subtotalAfter
391
451
  if (promoAmountData.length >= 1) {
392
452
  calculatedSubtotal = promoAmountData[promoAmountData.length - 1].subtotalAfter;
393
453
  }
454
+ // 2. Check for incentive promos
394
455
  let incentive = allPromos.find((p) => p.applies_to === Cart_1.CartPromoAppliesToEnum.TOTAL_AFTER_TAXES);
395
456
  if (!!incentive) {
457
+ // A. Find same discount_rule for data
396
458
  const sameDiscountRule = data.addioCart.discount_rules.find((d) => d.id == incentive.discount_id);
397
459
  const externalValueForG2 = !!sameDiscountRule
398
460
  ? (0, object_1.recursiveCheckObject)(sameDiscountRule, 'external_values.noArticle')
399
461
  : undefined;
462
+ // B. Transform promo to g2 item
400
463
  const { g2Item, internalMsgForItem } = await _transformCartPromoToPartialG2Item(incentive, externalValueForG2, calculatedSubtotal, data.space, data.orgId, allOptions);
401
464
  data.g2OrderObj.addItemLineToOrder(g2Item, internalMsgForItem);
402
465
  }
@@ -441,12 +504,14 @@ const _constructCartTypeItem = (data) => {
441
504
  let calculatedPalQty = (0, expedition_1.getPalletQty)(allItems, cartProps.cartType == cart_3.CartGeneralTypeEnum.BETON ? 'concrete' : 'grass');
442
505
  let itemMsgStr = '';
443
506
  if (cartProps.cartType == cart_3.CartGeneralTypeEnum.BETON) {
507
+ // NEW [12-11-2025] - Set concrete order pal quantity to pallet fee quantity (or calculated qty if not found)
444
508
  let concretePalQty = calculatedPalQty;
445
509
  const palletFeeProd = allItems.find((i) => i.parent_slug == 'frais-palette');
446
510
  if (!!palletFeeProd) {
447
511
  concretePalQty = palletFeeProd.qte;
448
512
  }
449
513
  itemMsgStr += `${concretePalQty} BETON`;
514
+ // Check for accessories in order, and add then to item message
450
515
  let allAccessories = allItems.filter((i) => {
451
516
  const cat2 = (0, object_1.recursiveCheckObject)(i, 'external_values.catégorie2') || '';
452
517
  return !!cat2.includes('ACC') && !!(0, object_1.recursiveCheckObject)(i, 'external_values.catégorie1') && !i.is_service;
@@ -455,10 +520,12 @@ const _constructCartTypeItem = (data) => {
455
520
  itemMsgStr += ` + ${(0, object_1.recursiveCheckObject)(acc, 'external_values.catégorie1')}`;
456
521
  }
457
522
  else {
523
+ // NEW [12-11-2025] - For grass order pal quantity always use calculated pal quantity
458
524
  itemMsgStr += `${calculatedPalQty % 1 != 0 ? Math.floor(calculatedPalQty) + '½' : calculatedPalQty} GAZON`;
459
525
  const principalGrassItem = allItems.find((i) => (0, products_2.checkIfProductIsOfType)(i, 'gazon', true) && !i.is_service && i.sku !== products_1.kentucky);
460
526
  if (!!principalGrassItem)
461
527
  itemMsgStr += ` ${(0, locale_1.getLocaleOfDictionnary)(principalGrassItem.name, addioCart.locale).toUpperCase()}`;
528
+ // Check for installation specifics
462
529
  if ((0, cart_1.checkIfCartContainsType)(cart_3.CartGeneralTypeEnum.INSTALLATION, addioCart)) {
463
530
  itemMsgStr += ' EN INSTALLATION';
464
531
  if (allItems.some((i) => i.parent_slug == 'installation-fertilisation'))
@@ -491,6 +558,7 @@ const _constructCartTypeItem = (data) => {
491
558
  itemMsgStr += ` + ${installAddOnStr.join(' | ')}`;
492
559
  }
493
560
  }
561
+ // Create item with only message
494
562
  const constructedItem = Object.assign(Object.assign({}, (0, exports.getDefaultG2OrderItem)()), { message: itemMsgStr, quantite: null, prixUnitaire: null, pourcEscompte: 0, taxableTPS: true, taxableTVQ: true });
495
563
  g2OrderObj.addItemLineToOrder(constructedItem);
496
564
  };
@@ -503,12 +571,25 @@ const _constructPersonOnSiteItem = (data) => {
503
571
  const personOnSitePhone = (0, object_1.recursiveCheckObject)(addioCart, 'shipping_payload.personOnSitePhone');
504
572
  if (!!!personOnSiteName && !!!personOnSitePhone)
505
573
  return;
574
+ // Create item with only message + generic sku
506
575
  const constructedItem = Object.assign(Object.assign({}, (0, exports.getDefaultG2OrderItem)()), { noArticle: 'APPEL', message: `* APPELER 30 MIN AVANT ${personOnSiteName.trim()} ${(0, data_1.formatPhoneNumberPrint)(personOnSitePhone).trim()}`, quantite: 0, prixUnitaire: 0, pourcEscompte: 0, taxableTPS: true, taxableTVQ: true });
507
576
  g2OrderObj.addItemLineToOrder(constructedItem);
508
577
  };
578
+ // #endregion
579
+ // =================================================================
580
+ // #region TRANSFORM EXISTING ADDIO DATA
581
+ /**
582
+ * Creates a G2 compatible item from a dashboard item, excluding index properties. Also consults G2 prod for certain props if found with provided item.sku
583
+ * @param item
584
+ * @param space
585
+ * @param org
586
+ * @param options
587
+ */
509
588
  const _transformCartItemToPartialG2Item = async (item, space, orgId, options) => {
510
589
  var _a;
511
590
  let extraMsg = [];
591
+ // --------------------------------
592
+ //#region CONSTANTS
512
593
  const isCustomProd = !!item.is_temp_prod;
513
594
  const isEscSuppItem = (0, g2_1.isEscompteSuppItem)(item.sku);
514
595
  const updatedPriceMsg = !!(0, cart_2.priceWasOverridden)(item)
@@ -517,21 +598,40 @@ const _transformCartItemToPartialG2Item = async (item, space, orgId, options) =>
517
598
  const updatedEscompteMsg = !!(0, cart_2.priceWasOverridden)(item)
518
599
  ? (0, object_1.recursiveCheckObject)(item, 'promo_price.authorization.note')
519
600
  : '';
601
+ //#endregion
602
+ // --------------------------------
603
+ //#region MINIMAL INFOS
520
604
  let defaultSku = (0, object_1.recursiveCheckObject)(item, 'external_values.noArticle') || item.sku;
605
+ // If is PA supp item, split sku to keep only "real" sku for item
521
606
  if (isEscSuppItem)
522
607
  defaultSku = (0, string_1.splitFromFirstChar)('-', defaultSku)[0];
608
+ // If is custom prod item, set default sku to "empty"
609
+ // else if (isCustomProd) defaultSku = ''
523
610
  let transG2Item = (0, exports.getDefaultG2OrderItem)(defaultSku);
611
+ //#endregion
612
+ // --------------------------------
613
+ //#region DESC. INFOS
524
614
  transG2Item.description = (_a = (0, locale_1.getLocaleOfDictionnary)(item.name, options.cartLocale)) !== null && _a !== void 0 ? _a : null;
525
615
  transG2Item.quantite = isEscSuppItem ? (0, round_1.default)(item.qte, 2) : item.qte;
526
616
  transG2Item.prixUnitaire = (0, cart_1.getAppliedPrice)(item, {
527
617
  isBookingBeton: options.cartType == cart_3.CartGeneralTypeEnum.BOOKING_BETON
528
618
  });
619
+ // ** If esc does not exist, send 0 instead of null (causes errors on G2's end)
529
620
  transG2Item.pourcEscompte = (0, cart_1.getPercentFromReducedPrice)(item, !!options.isPro) || 0;
621
+ //#endregion
622
+ // --------------------------------
623
+ //#region CONDITIONAL INFOS
624
+ // A. Add props if product's price or escomptes were manually updated
530
625
  transG2Item.prixModifieUtilisateur = !!updatedPriceMsg || (isCustomProd && !isEscSuppItem);
531
626
  transG2Item.escompteModifieUtilisateur = !!updatedEscompteMsg || (isCustomProd && !isEscSuppItem);
627
+ // B. Add tax applicable props (check if product is tax exempt or shipping to ontario)
532
628
  const prodIsTaxExempt = !!item.tax_exemption || options.shippingToOntario;
533
629
  transG2Item.taxableTPS = !prodIsTaxExempt;
534
630
  transG2Item.taxableTVQ = !prodIsTaxExempt;
631
+ //#endregion
632
+ // --------------------------------
633
+ //#region G2 PROD DATA
634
+ // Fetch item from G2. If found, use to set certain variables.
535
635
  try {
536
636
  transG2Item = await _updateItemWithG2Prod(defaultSku, transG2Item, options, space, orgId, {
537
637
  noArticle: true,
@@ -542,6 +642,10 @@ const _transformCartItemToPartialG2Item = async (item, space, orgId, options) =>
542
642
  catch (e) {
543
643
  console.error(`error on fetching prod from G2 for sku ${defaultSku}: `, e.toString());
544
644
  }
645
+ //#endregion
646
+ // --------------------------------
647
+ // #region MESSAGES
648
+ // Add custom message to order if product is custom prod, or product price/escompte were manually updated
545
649
  if (!!isCustomProd && !isEscSuppItem)
546
650
  extraMsg.push(`Produit ajouté manuellement`);
547
651
  else {
@@ -553,17 +657,32 @@ const _transformCartItemToPartialG2Item = async (item, space, orgId, options) =>
553
657
  if (allMsgs.length)
554
658
  extraMsg.push(allMsgs.join(' | '));
555
659
  }
660
+ //#endregion
556
661
  return {
557
662
  g2Item: transG2Item,
558
663
  internalMsgForItem: !!extraMsg.length ? `${extraMsg.join(', ')}` : ''
559
664
  };
560
665
  };
666
+ /**
667
+ * Creates a G2 compatible item from a promo applied to a cart (ICartPromoApplied), excluding index properties. Also consults G2 prod for certain props if found with constructed sku for promo.
668
+ * @param promo The Cart Promo to transform
669
+ * @param associatedNoArticle The noArticle associated to G2, used to generate sku
670
+ * @param quantityToUse For promos, corresponds to the amount on which the promo is applied. Ex. if promo applied to subtotal, should be subtotal, or if applied to specific product, specific product's price * qte
671
+ * @param space
672
+ * @param org
673
+ * @param options
674
+ */
561
675
  const _transformCartPromoToPartialG2Item = async (promo, associatedNoArticle, quantityToUse, space, orgId, options) => {
562
676
  let extraMsg = [];
677
+ // --------------------------------
678
+ //#region MINIMAL INFOS
563
679
  let defaultSku = associatedNoArticle || '';
564
680
  if (!!!defaultSku && !!promo.promo_code)
565
681
  defaultSku = promo.promo_code;
566
682
  let transG2Item = (0, exports.getDefaultG2OrderItem)(defaultSku);
683
+ //#endregion
684
+ // --------------------------------
685
+ //#region DESC. INFOS
567
686
  transG2Item.description = promo.promo_name;
568
687
  transG2Item.quantite = quantityToUse;
569
688
  let promoResultAmountRemoved = 0;
@@ -577,9 +696,17 @@ const _transformCartPromoToPartialG2Item = async (promo, associatedNoArticle, qu
577
696
  }
578
697
  transG2Item.prixUnitaire = promoResultAmountRemoved * -1;
579
698
  transG2Item.pourcEscompte = 0;
699
+ //#endregion
700
+ // --------------------------------
701
+ //#region CONDITIONAL INFOS
702
+ // A. If promo is payment incentive promo, or shipping to Ontario, flag no taxes applied props
580
703
  const shouldRemoveTaxes = promo.applies_to == Cart_1.CartPromoAppliesToEnum.TOTAL_AFTER_TAXES || options.shippingToOntario;
581
704
  transG2Item.taxableTPS = !shouldRemoveTaxes;
582
705
  transG2Item.taxableTVQ = !shouldRemoveTaxes;
706
+ //#endregion
707
+ // --------------------------------
708
+ //#region G2 PROD DATA
709
+ // Fetch item from G2 if sku defined. If found, use to set certain variables.
583
710
  if (!!defaultSku) {
584
711
  try {
585
712
  transG2Item = await _updateItemWithG2Prod(defaultSku, transG2Item, options, space, orgId, {
@@ -595,25 +722,40 @@ const _transformCartPromoToPartialG2Item = async (promo, associatedNoArticle, qu
595
722
  transG2Item.noArticle = '999999999-1';
596
723
  transG2Item.pourcEscompte = 0;
597
724
  }
725
+ // If sku not found in G2, add price and escompte modified props so G2 does not override them
598
726
  if (transG2Item.noArticle == '999999999-1') {
599
727
  transG2Item.prixModifieUtilisateur = true;
600
728
  transG2Item.escompteModifieUtilisateur = true;
601
729
  }
730
+ //#endregion
602
731
  return {
603
732
  g2Item: transG2Item,
604
733
  internalMsgForItem: !!extraMsg.length ? `${extraMsg.join(', ')}` : ''
605
734
  };
606
735
  };
736
+ /**
737
+ * Fetch product fron G2 with sku provided, then update new G2 item with provided props.
738
+ * @param sku
739
+ * @param transG2Item
740
+ * @param options
741
+ * @param space
742
+ * @param org
743
+ * @param valuesToUpdate
744
+ * @param addMessageToG2Order
745
+ */
607
746
  const _updateItemWithG2Prod = async (sku, transG2Item, options, space, orgId, valuesToUpdate, addMessageToG2Order) => {
608
747
  var _a;
609
748
  const g2Prod = await (0, g2_1.fetchProductFromG2WithSku)(sku, space, orgId);
610
749
  if (!!g2Prod) {
750
+ // TODO - Vérifier les prix ici aussi?
751
+ // A.Check if G2 sku different from dash sku. If so, use G2.
611
752
  if (valuesToUpdate.noArticle) {
612
753
  if (!!g2Prod.noArticle && g2Prod.noArticle !== sku) {
613
754
  transG2Item.noArticle = g2Prod.noArticle;
614
755
  transG2Item.sku = sku;
615
756
  }
616
757
  }
758
+ // B. Check if G2 name is different from dash name
617
759
  if (valuesToUpdate.description) {
618
760
  const g2Description = options.cartLocale == 'en' && !!g2Prod.article.description2
619
761
  ? g2Prod.article.description2
@@ -622,12 +764,47 @@ const _updateItemWithG2Prod = async (sku, transG2Item, options, space, orgId, va
622
764
  transG2Item.description = g2Prod.article.description;
623
765
  }
624
766
  }
767
+ // C. Generate message tp show under item based on G2 props
768
+ // ** NOTE - Finalement, les messages issus des articles G2 seront générés du côté de G2 directement!
769
+ // if (valuesToUpdate.message) {
770
+ // let underItemMessage = ''
771
+ // if (g2Prod.article.catégorie2 == 'NET') underItemMessage += '***net***'
772
+ // if (g2Prod.messages && !!g2Prod.messages.length) {
773
+ // for (let msg of g2Prod.messages) {
774
+ // switch (msg.codeMessage) {
775
+ // case 'RETOUR':
776
+ // underItemMessage += translateILang({
777
+ // fr: '***Aucun retour/échange sur ce matériel***',
778
+ // en: '***Aucun retour/échange sur ce matériel***'
779
+ // })
780
+ // break
781
+ // case 'BETON':
782
+ // underItemMessage += translateILang({
783
+ // fr: '***applicable à toutes les commandes***',
784
+ // en: '***applicable à toutes les commandes***'
785
+ // })
786
+ // break
787
+ // case 'ENGRAIS':
788
+ // if (!options.isPickup)
789
+ // underItemMessage += translateILang({
790
+ // fr: '****Attention engrais****',
791
+ // en: '****Attention engrais****'
792
+ // })
793
+ // break
794
+ // }
795
+ // }
796
+ // }
797
+ // transG2Item.message = underItemMessage || null
798
+ // }
625
799
  }
626
800
  else {
801
+ // Reset noArticle value to default sku. Billing departement will know to verify & add correct sku afterwards
627
802
  if (valuesToUpdate.noArticle) {
628
803
  transG2Item.noArticle = '999999999-1';
629
804
  transG2Item.sku = sku;
630
805
  transG2Item.pourcEscompte = 0;
806
+ // TODO - Should we set prixModifieUtilisateur & escompteModifieUtilisateur when sku not found in G2?
807
+ // Add message to notes in order
631
808
  if (!!addMessageToG2Order)
632
809
  addMessageToG2Order(`Sku non-trouvé dans G2 : ${sku}`);
633
810
  }
@@ -641,13 +818,16 @@ const _updateItemWithG2Prod = async (sku, transG2Item, options, space, orgId, va
641
818
  }
642
819
  return transG2Item;
643
820
  };
821
+ // #endregion
644
822
  const transformCreditNoteToG2Order = async (creditNote, cartId, space, orgId, isTest) => {
823
+ // Check if space has G2 set
645
824
  const g2Service = space.services({ field: 'external_service_name', value: 'G2' });
646
825
  if (!!!g2Service.length ||
647
826
  !!!(0, object_1.recursiveCheckObject)(g2Service[0], 'external_service_infos.specific_actions.save_order_to_g2')) {
648
827
  console.error('space does not have G2 in external_services or does not save order property. Returning!');
649
828
  return;
650
829
  }
830
+ // Fetch corresponding cart from database
651
831
  let correspondingCart;
652
832
  try {
653
833
  const cartQuery = await space.carts.get({ query: [{ field: 'id', operator: '==', value: cartId }] });
@@ -661,10 +841,13 @@ const transformCreditNoteToG2Order = async (creditNote, cartId, space, orgId, is
661
841
  console.log("couldn't find cart! returning");
662
842
  return;
663
843
  }
844
+ // Update cart with credit note
845
+ // 1. Ajust date
664
846
  correspondingCart.paid_at = creditNote.createdAt;
665
847
  if (!!correspondingCart.processed_by) {
666
848
  correspondingCart.processed_by = Object.assign(Object.assign({}, correspondingCart.processed_by), { date: creditNote.createdAt });
667
849
  }
850
+ // 2. Ajust items
668
851
  correspondingCart.items = correspondingCart.items
669
852
  .map((i) => {
670
853
  const sameInRefund = creditNote.items.find((refItem) => refItem.itemId === i.parent_product_id && refItem.variantId === i.sku);
@@ -674,12 +857,14 @@ const transformCreditNoteToG2Order = async (creditNote, cartId, space, orgId, is
674
857
  return i;
675
858
  })
676
859
  .filter((i) => !!i);
860
+ // 3. Ajust totals
677
861
  correspondingCart.subtotal = creditNote.subtotal * -1;
678
862
  correspondingCart.total = creditNote.total * -1;
679
863
  correspondingCart.taxes = creditNote.taxes.map((t) => (Object.assign(Object.assign({}, t), { taxes: t.taxes.map((tax) => (Object.assign(Object.assign({}, tax), { amount: (tax.amount || 0) * -1 }))) })));
680
864
  if (!!correspondingCart.subtotalWithoutPromotions) {
681
865
  correspondingCart.subtotalWithoutPromotions = creditNote.subtotalWithoutPromotions * -1;
682
866
  }
867
+ // 4. Ajust cart promos
683
868
  const currentCartPromos = (0, discount_1.getCartPromo)(Object.assign({}, correspondingCart)) || [];
684
869
  correspondingCart.promo_after_taxes_amount = creditNote.promoAfterTaxesAmount;
685
870
  correspondingCart.cart_promos_applied = (creditNote.promos || [])
@@ -697,6 +882,7 @@ const transformCreditNoteToG2Order = async (creditNote, cartId, space, orgId, is
697
882
  return sameInCreditNote;
698
883
  })
699
884
  .filter((p) => !!p);
885
+ // Call create g2OrderSlip function
700
886
  let transformedG2Order = await (0, exports.transformAddioCartToG2Order)(correspondingCart, space, orgId, isTest, creditNote);
701
887
  return transformedG2Order;
702
888
  };