Advertisement
vitareinforce

draft fungsi simpan pas edit untuk mendeteksi ada perubahan di jumlah bundle atau tidak

Aug 31st, 2021 (edited)
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.88 KB | None | 0 0
  1. save: async function() {
  2.  
  3. console.log(this.checkInventory)
  4. console.log(this.bundle)
  5.  
  6. // Fungsi Save Data
  7. if(this.selectedMaintenance == 'Ya') {
  8. this.bundle.IsMaintenance = 1
  9. }
  10. if(this.selectedMaintenance == 'Tidak') {
  11. this.bundle.IsMaintenance = 0
  12. }
  13.  
  14. if(this.selectedDeposit == 'Ya') {
  15. this.bundle.IsDeposit = 1
  16. }
  17. if(this.selectedDeposit == 'Tidak') {
  18. this.bundle.IsDeposit = 0
  19. }
  20.  
  21. // if(this.selectedDeposit == 'Tidak') {
  22. // this.bundle.IsDeposit = 0
  23. // }
  24. // if(this.selectedDeposit == 'Ya') {
  25. // this.bundle.IsAssembly = 0
  26. // }
  27.  
  28. try {
  29. let result
  30.  
  31. let bundleChange
  32.  
  33. if(this.$route.params.id) {
  34.  
  35. // ambil bundle lama sebelum diupdate dari inventory (masih ragu apa hrs dr inventory cabang atau dr bundle aj)
  36. let existingBundleRequest = await Inventories.detail(this.bundle.ItemId)
  37. let existingBundle = existingBundleRequest.data
  38.  
  39. // ini yg dr bundle langsung
  40. // let existingBundleRequest = await Bundle.detail(this.bundle.Id)
  41. // let existingBundle = existingBundleRequest.data
  42.  
  43. // siapin variable bundle as inventory nya dulu
  44. let bundleAsInventory = {
  45. inventory: {
  46. LegalEntityId: this.userData.LegalEntityId,
  47. BranchId: this.userData.BranchId,
  48. Name: this.bundle.Name,
  49. Code: 'BDL/' + moment().format('DD') + moment().format('MM') + moment().format('YY') + "/" + moment().format('HH') + moment().format('mm') + moment().format('ss'),
  50. Category: "Bundle - " + this.bundle.Category,
  51. Identifier: "Bundle",
  52. Point: this.bundle.Point,
  53. BuyingPrice: 0,
  54. IsBundle: true,
  55. WarehouseCategory: this.bundle.WarehouseCategory,
  56. IsRefurbish: 1,
  57. IsMaintenance: this.bundle.IsMaintenance,
  58. IsDeposit: this.bundle.IsDeposit,
  59. ItemMasterId: null,
  60. SupplierId: this.selectedSupplier1.Id,
  61. SupplierId2: this.selectedSupplier2.Id,
  62. SupplierId3: this.selectedSupplier3.Id,
  63. HistoryQuantity: this.bundle.TotalQuantity,
  64. EmployeeId: this.userData.EmployeeId,
  65. Position: 'Tambah - Barang Bundle',
  66. BundleId: this.bundle.Id,
  67. Price100: this.bundle.BundlePrice100 || 0,
  68. Price90: this.bundle.BundlePrice90 || 0,
  69. Price60: this.bundle.BundlePrice60 || 0,
  70. Price30: this.bundle.BundlePrice30 || 0,
  71. ExtraPrice100: this.bundle.OwnerPrice100 || 0,
  72. ExtraPrice90: this.bundle.OwnerPrice90 || 0,
  73. ExtraPrice60: this.bundle.OwnerPrice60 || 0,
  74. ExtraPrice30: this.bundle.OwnerPrice30 || 0,
  75. BazaarPrice100: this.bundle.Bazaar100 || 0,
  76. BazaarPrice90: this.bundle.Bazaar90 || 0,
  77. BazaarPrice60: this.bundle.Bazaar60 || 0,
  78. BazaarPrice30: this.bundle.Bazaar30 || 0,
  79. BuyingPrice100: this.bundle.BuyingPrice100 || 0,
  80. BuyingPrice90: this.bundle.BuyingPrice90 || 0,
  81. BuyingPrice60: this.bundle.BuyingPrice60 || 0,
  82. BuyingPrice30: this.bundle.BuyingPrice30 || 0,
  83. SpecialPrice100: this.bundle.SpecialPrice100 || 0,
  84. SpecialPrice90: this.bundle.SpecialPrice90 || 0,
  85. SpecialPrice60: this.bundle.SpecialPrice60 || 0,
  86. SpecialPrice30: this.bundle.SpecialPrice30 || 0,
  87. PromoPrice100: this.bundle.PromoPrice100 || 0,
  88. PromoPrice90: this.bundle.PromoPrice90 || 0,
  89. PromoPrice60: this.bundle.PromoPrice60 || 0,
  90. PromoPrice30: this.bundle.PromoPrice30 || 0,
  91. ComboPrice100: this.bundle.ComboPrice100 || 0,
  92. ComboPrice90: this.bundle.ComboPrice90 || 0,
  93. ComboPrice60: this.bundle.ComboPrice60 || 0,
  94. ComboPrice30: this.bundle.ComboPrice30 || 0,
  95. CipenRegularPrice100: this.bundle.CipenRegularPrice100 || 0,
  96. CipenRegularPrice90: this.bundle.CipenRegularPrice90 || 0,
  97. CipenRegularPrice60: this.bundle.CipenRegularPrice60 || 0,
  98. CipenRegularPrice30: this.bundle.CipenRegularPrice30 || 0,
  99. CipenSpecialPrice100: this.bundle.CipenSpecialPrice100 || 0,
  100. CipenSpecialPrice90: this.bundle.CipenSpecialPrice90 || 0,
  101. CipenSpecialPrice60: this.bundle.CipenSpecialPrice60 || 0,
  102. CipenSpecialPrice30: this.bundle.CipenSpecialPrice30 || 0,
  103. CipenPromoPrice100: this.bundle.CipenPromoPrice100 || 0,
  104. CipenPromoPrice90: this.bundle.CipenPromoPrice90 || 0,
  105. CipenPromoPrice60: this.bundle.CipenPromoPrice60 || 0,
  106. CipenPromoPrice30: this.bundle.CipenPromoPrice30 || 0,
  107. CipenComboPrice100: this.bundle.CipenComboPrice100 || 0,
  108. CipenComboPrice90: this.bundle.CipenComboPrice90 || 0,
  109. CipenComboPrice60: this.bundle.CipenComboPrice60 || 0,
  110. CipenComboPrice30: this.bundle.CipenComboPrice30 || 0,
  111. CikenRegularPrice100: this.bundle.CikenRegularPrice100 || 0,
  112. CikenRegularPrice90: this.bundle.CikenRegularPrice90 || 0,
  113. CikenRegularPrice60: this.bundle.CikenRegularPrice60 || 0,
  114. CikenRegularPrice30: this.bundle.CikenRegularPrice30 || 0,
  115. CikenSpecialPrice100: this.bundle.CikenSpecialPrice100 || 0,
  116. CikenSpecialPrice90: this.bundle.CikenSpecialPrice90 || 0,
  117. CikenSpecialPrice60: this.bundle.CikenSpecialPrice60 || 0,
  118. CikenSpecialPrice30: this.bundle.CikenSpecialPrice30 || 0,
  119. CikenPromoPrice100: this.bundle.CikenPromoPrice100 || 0,
  120. CikenPromoPrice90: this.bundle.CikenPromoPrice90 || 0,
  121. CikenPromoPrice60: this.bundle.CikenPromoPrice60 || 0,
  122. CikenPromoPrice30: this.bundle.CikenPromoPrice30 || 0,
  123. CikenComboPrice100: this.bundle.CikenComboPrice100 || 0,
  124. CikenComboPrice90: this.bundle.CikenComboPrice90 || 0,
  125. CikenComboPrice60: this.bundle.CikenComboPrice60 || 0,
  126. CikenComboPrice30: this.bundle.CikenComboPrice30 || 0,
  127. CimenRegularPrice100: this.bundle.CimenRegularPrice100 || 0,
  128. CimenRegularPrice90: this.bundle.CimenRegularPrice90 || 0,
  129. CimenRegularPrice60: this.bundle.CimenRegularPrice60 || 0,
  130. CimenRegularPrice30: this.bundle.CimenRegularPrice30 || 0,
  131. CimenSpecialPrice100: this.bundle.CimenSpecialPrice100 || 0,
  132. CimenSpecialPrice90: this.bundle.CimenSpecialPrice90 || 0,
  133. CimenSpecialPrice60: this.bundle.CimenSpecialPrice60 || 0,
  134. CimenSpecialPrice30: this.bundle.CimenSpecialPrice30 || 0,
  135. CimenPromoPrice100: this.bundle.CimenPromoPrice100 || 0,
  136. CimenPromoPrice90: this.bundle.CimenPromoPrice90 || 0,
  137. CimenPromoPrice60: this.bundle.CimenPromoPrice60 || 0,
  138. CimenPromoPrice30: this.bundle.CimenPromoPrice30 || 0,
  139. CimenComboPrice100: this.bundle.CimenComboPrice100 || 0,
  140. CimenComboPrice90: this.bundle.CimenComboPrice90 || 0,
  141. CimenComboPrice60: this.bundle.CimenComboPrice60 || 0,
  142. CimenComboPrice30: this.bundle.CimenComboPrice30 || 0,
  143. Quantity100: this.bundle.QuantityBundle100 || 0,
  144. Quantity90: this.bundle.QuantityBundle90 || 0,
  145. Quantity60: this.bundle.QuantityBundle60 || 0,
  146. Quantity30: this.bundle.QuantityBundle30 || 0,
  147. ProcurementType: this.bundle.ProcurementType,
  148. SNI1: this.bundle.SNI1,
  149. SNI2: this.bundle.SNI2,
  150. SNI3: this.bundle.SNI3,
  151. },
  152. LegalEntityId: this.userData.LegalEntityId,
  153. BranchId: this.userData.BranchId,
  154. TotalQuantity: this.bundle.TotalQuantity,
  155. Quantity100: this.bundle.QuantityBundle100 || 0,
  156. Quantity90: this.bundle.QuantityBundle90 || 0,
  157. Quantity60: this.bundle.QuantityBundle60 || 0,
  158. Quantity30: this.bundle.QuantityBundle30 || 0,
  159. Price100: this.bundle.BundlePrice100 || 0,
  160. Price90: this.bundle.BundlePrice90 || 0,
  161. Price60: this.bundle.BundlePrice60 || 0,
  162. Price30: this.bundle.BundlePrice30 || 0,
  163. ExtraPrice100: this.bundle.OwnerPrice100 || 0,
  164. ExtraPrice90: this.bundle.OwnerPrice90 || 0,
  165. ExtraPrice60: this.bundle.OwnerPrice60 || 0,
  166. ExtraPrice30: this.bundle.OwnerPrice30 || 0,
  167. BazaarPrice100: this.bundle.Bazaar100 || 0,
  168. BazaarPrice90: this.bundle.Bazaar90 || 0,
  169. BazaarPrice60: this.bundle.Bazaar60 || 0,
  170. BazaarPrice30: this.bundle.Bazaar30 || 0,
  171. Picture1: this.bundle.Picture1 || null,
  172. BuyingPrice100: this.bundle.BuyingPrice100 || 0,
  173. BuyingPrice90: this.bundle.BuyingPrice90 || 0,
  174. BuyingPrice60: this.bundle.BuyingPrice60 || 0,
  175. BuyingPrice30: this.bundle.BuyingPrice30 || 0,
  176. SpecialPrice100: this.bundle.SpecialPrice100 || 0,
  177. SpecialPrice90: this.bundle.SpecialPrice90 || 0,
  178. SpecialPrice60: this.bundle.SpecialPrice60 || 0,
  179. SpecialPrice30: this.bundle.SpecialPrice30 || 0,
  180. PromoPrice100: this.bundle.PromoPrice100 || 0,
  181. PromoPrice90: this.bundle.PromoPrice90 || 0,
  182. PromoPrice60: this.bundle.PromoPrice60 || 0,
  183. PromoPrice30: this.bundle.PromoPrice30 || 0,
  184. ComboPrice100: this.bundle.ComboPrice100 || 0,
  185. ComboPrice90: this.bundle.ComboPrice90 || 0,
  186. ComboPrice60: this.bundle.ComboPrice60 || 0,
  187. ComboPrice30: this.bundle.ComboPrice30 || 0,
  188. CipenRegularPrice100: this.bundle.CipenRegularPrice100 || 0,
  189. CipenRegularPrice90: this.bundle.CipenRegularPrice90 || 0,
  190. CipenRegularPrice60: this.bundle.CipenRegularPrice60 || 0,
  191. CipenRegularPrice30: this.bundle.CipenRegularPrice30 || 0,
  192. CipenSpecialPrice100: this.bundle.CipenSpecialPrice100 || 0,
  193. CipenSpecialPrice90: this.bundle.CipenSpecialPrice90 || 0,
  194. CipenSpecialPrice60: this.bundle.CipenSpecialPrice60 || 0,
  195. CipenSpecialPrice30: this.bundle.CipenSpecialPrice30 || 0,
  196. CipenPromoPrice100: this.bundle.CipenPromoPrice100 || 0,
  197. CipenPromoPrice90: this.bundle.CipenPromoPrice90 || 0,
  198. CipenPromoPrice60: this.bundle.CipenPromoPrice60 || 0,
  199. CipenPromoPrice30: this.bundle.CipenPromoPrice30 || 0,
  200. CipenComboPrice100: this.bundle.CipenComboPrice100 || 0,
  201. CipenComboPrice90: this.bundle.CipenComboPrice90 || 0,
  202. CipenComboPrice60: this.bundle.CipenComboPrice60 || 0,
  203. CipenComboPrice30: this.bundle.CipenComboPrice30 || 0,
  204. CikenRegularPrice100: this.bundle.CikenRegularPrice100 || 0,
  205. CikenRegularPrice90: this.bundle.CikenRegularPrice90 || 0,
  206. CikenRegularPrice60: this.bundle.CikenRegularPrice60 || 0,
  207. CikenRegularPrice30: this.bundle.CikenRegularPrice30 || 0,
  208. CikenSpecialPrice100: this.bundle.CikenSpecialPrice100 || 0,
  209. CikenSpecialPrice90: this.bundle.CikenSpecialPrice90 || 0,
  210. CikenSpecialPrice60: this.bundle.CikenSpecialPrice60 || 0,
  211. CikenSpecialPrice30: this.bundle.CikenSpecialPrice30 || 0,
  212. CikenPromoPrice100: this.bundle.CikenPromoPrice100 || 0,
  213. CikenPromoPrice90: this.bundle.CikenPromoPrice90 || 0,
  214. CikenPromoPrice60: this.bundle.CikenPromoPrice60 || 0,
  215. CikenPromoPrice30: this.bundle.CikenPromoPrice30 || 0,
  216. CikenComboPrice100: this.bundle.CikenComboPrice100 || 0,
  217. CikenComboPrice90: this.bundle.CikenComboPrice90 || 0,
  218. CikenComboPrice60: this.bundle.CikenComboPrice60 || 0,
  219. CikenComboPrice30: this.bundle.CikenComboPrice30 || 0,
  220. CimenRegularPrice100: this.bundle.CimenRegularPrice100 || 0,
  221. CimenRegularPrice90: this.bundle.CimenRegularPrice90 || 0,
  222. CimenRegularPrice60: this.bundle.CimenRegularPrice60 || 0,
  223. CimenRegularPrice30: this.bundle.CimenRegularPrice30 || 0,
  224. CimenSpecialPrice100: this.bundle.CimenSpecialPrice100 || 0,
  225. CimenSpecialPrice90: this.bundle.CimenSpecialPrice90 || 0,
  226. CimenSpecialPrice60: this.bundle.CimenSpecialPrice60 || 0,
  227. CimenSpecialPrice30: this.bundle.CimenSpecialPrice30 || 0,
  228. CimenPromoPrice100: this.bundle.CimenPromoPrice100 || 0,
  229. CimenPromoPrice90: this.bundle.CimenPromoPrice90 || 0,
  230. CimenPromoPrice60: this.bundle.CimenPromoPrice60 || 0,
  231. CimenPromoPrice30: this.bundle.CimenPromoPrice30 || 0,
  232. CimenComboPrice100: this.bundle.CimenComboPrice100 || 0,
  233. CimenComboPrice90: this.bundle.CimenComboPrice90 || 0,
  234. CimenComboPrice60: this.bundle.CimenComboPrice60 || 0,
  235. CimenComboPrice30: this.bundle.CimenComboPrice30 || 0,
  236. ProcurementType: this.bundle.ProcurementType,
  237. SNI1: this.bundle.SNI1,
  238. SNI2: this.bundle.SNI2,
  239. SNI3: this.bundle.SNI3,
  240. SafetyStockLimit: this.bundle.SafetyStockLimit,
  241. Location: this.bundle.Location,
  242. SellingPrice: this.bundle.Price,
  243. RefurbishQuantity: 0,
  244. SupplierId: null,
  245. HistoryQuantity: this.bundle.TotalQuantity,
  246. EmployeeId: this.userData.EmployeeId,
  247. IsRefurbish: 1,
  248. Position: 'Bundle - Tambah Bundle',
  249. BundleId: this.bundle.Id
  250. }
  251.  
  252. //IF inventory untuk bundle ini belum ada -- START
  253. if(this.checkInventory == false) {
  254. let inv = await Inventories.create(bundleAsInventory)
  255. let ItemId = inv.data.itemBranchId
  256. console.log(inv.status == 200)
  257.  
  258. this.bundle.ItemId = ItemId
  259.  
  260. bundleAsInventory.BundleId = this.bundle.Id
  261. await Inventories.edit(ItemId, bundleAsInventory)
  262. //IF inventory untuk bundle ini belum ada -- END
  263. }
  264. else if(this.checkInventory == true) {
  265. /**
  266. * Get ItemId (variable boleh diganti)
  267. */
  268. await Inventories.edit(this.getInventory[0].Id, bundleAsInventory)
  269. }
  270.  
  271. // check ad perubahan di bundlenya atau tidak
  272. if(existingBundle.Quantity100 == bundleAsInventory.Quantity100) {
  273. bundleAsInventory.Quantity100 = existingBundle.Quantity100
  274. bundleChange = true
  275. }
  276.  
  277. // check ad perubahan di bundlenya atau tidak
  278. if(existingBundle.Quantity90 == bundleAsInventory.Quantity90) {
  279. bundleAsInventory.Quantity90 = existingBundle.Quantity90
  280. bundleChange = true
  281. }
  282.  
  283. // check ad perubahan di bundlenya atau tidak
  284. if(existingBundle.Quantity60 == bundleAsInventory.Quantity60) {
  285. bundleAsInventory.Quantity60 = existingBundle.Quantity60
  286. bundleChange = true
  287. }
  288.  
  289. // check ad perubahan di bundlenya atau tidak
  290. if(existingBundle.Quantity30 == bundleAsInventory.Quantity30) {
  291. bundleAsInventory.Quantity30 = existingBundle.Quantity30
  292. bundleChange = true
  293. }
  294.  
  295.  
  296. this.bundle.DeliveryStatus = 'Final'
  297. this.bundle.SafetyStockLimit = this.bundle.SafetyStockLimit
  298. console.log(JSON.parse(JSON.stringify(this.itemdetails)).length)
  299.  
  300. result = await Bundle.edit(this.$route.params.id, bundleAsInventory)
  301.  
  302. }
  303.  
  304. if(result.status == 200) {
  305. this.$fire({
  306. title: 'Sukses',
  307. text: 'Data Telah diupdate',
  308. icon: 'info',
  309. type: 'success',
  310. showConfirmButton: false
  311. })
  312. this.$router.push({ name: 'BundleManagement.index' })
  313. location.reload()
  314. } else {
  315. this.$fire({
  316. title: 'Error',
  317. text: 'Input Data Gagal',
  318. icon: 'error',
  319. type: 'error',
  320. showConfirmButton: false,
  321. })
  322. console.log(result)
  323. }
  324. } catch (error) {
  325. alert("Error : " + error.response.data.message)
  326. }
  327. },
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement