Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- save: async function() {
- console.log(this.checkInventory)
- console.log(this.bundle)
- // Fungsi Save Data
- if(this.selectedMaintenance == 'Ya') {
- this.bundle.IsMaintenance = 1
- }
- if(this.selectedMaintenance == 'Tidak') {
- this.bundle.IsMaintenance = 0
- }
- if(this.selectedDeposit == 'Ya') {
- this.bundle.IsDeposit = 1
- }
- if(this.selectedDeposit == 'Tidak') {
- this.bundle.IsDeposit = 0
- }
- // if(this.selectedDeposit == 'Tidak') {
- // this.bundle.IsDeposit = 0
- // }
- // if(this.selectedDeposit == 'Ya') {
- // this.bundle.IsAssembly = 0
- // }
- try {
- let result
- let bundleChange
- if(this.$route.params.id) {
- // ambil bundle lama sebelum diupdate dari inventory (masih ragu apa hrs dr inventory cabang atau dr bundle aj)
- let existingBundleRequest = await Inventories.detail(this.bundle.ItemId)
- let existingBundle = existingBundleRequest.data
- // ini yg dr bundle langsung
- // let existingBundleRequest = await Bundle.detail(this.bundle.Id)
- // let existingBundle = existingBundleRequest.data
- // siapin variable bundle as inventory nya dulu
- let bundleAsInventory = {
- inventory: {
- LegalEntityId: this.userData.LegalEntityId,
- BranchId: this.userData.BranchId,
- Name: this.bundle.Name,
- Code: 'BDL/' + moment().format('DD') + moment().format('MM') + moment().format('YY') + "/" + moment().format('HH') + moment().format('mm') + moment().format('ss'),
- Category: "Bundle - " + this.bundle.Category,
- Identifier: "Bundle",
- Point: this.bundle.Point,
- BuyingPrice: 0,
- IsBundle: true,
- WarehouseCategory: this.bundle.WarehouseCategory,
- IsRefurbish: 1,
- IsMaintenance: this.bundle.IsMaintenance,
- IsDeposit: this.bundle.IsDeposit,
- ItemMasterId: null,
- SupplierId: this.selectedSupplier1.Id,
- SupplierId2: this.selectedSupplier2.Id,
- SupplierId3: this.selectedSupplier3.Id,
- HistoryQuantity: this.bundle.TotalQuantity,
- EmployeeId: this.userData.EmployeeId,
- Position: 'Tambah - Barang Bundle',
- BundleId: this.bundle.Id,
- Price100: this.bundle.BundlePrice100 || 0,
- Price90: this.bundle.BundlePrice90 || 0,
- Price60: this.bundle.BundlePrice60 || 0,
- Price30: this.bundle.BundlePrice30 || 0,
- ExtraPrice100: this.bundle.OwnerPrice100 || 0,
- ExtraPrice90: this.bundle.OwnerPrice90 || 0,
- ExtraPrice60: this.bundle.OwnerPrice60 || 0,
- ExtraPrice30: this.bundle.OwnerPrice30 || 0,
- BazaarPrice100: this.bundle.Bazaar100 || 0,
- BazaarPrice90: this.bundle.Bazaar90 || 0,
- BazaarPrice60: this.bundle.Bazaar60 || 0,
- BazaarPrice30: this.bundle.Bazaar30 || 0,
- BuyingPrice100: this.bundle.BuyingPrice100 || 0,
- BuyingPrice90: this.bundle.BuyingPrice90 || 0,
- BuyingPrice60: this.bundle.BuyingPrice60 || 0,
- BuyingPrice30: this.bundle.BuyingPrice30 || 0,
- SpecialPrice100: this.bundle.SpecialPrice100 || 0,
- SpecialPrice90: this.bundle.SpecialPrice90 || 0,
- SpecialPrice60: this.bundle.SpecialPrice60 || 0,
- SpecialPrice30: this.bundle.SpecialPrice30 || 0,
- PromoPrice100: this.bundle.PromoPrice100 || 0,
- PromoPrice90: this.bundle.PromoPrice90 || 0,
- PromoPrice60: this.bundle.PromoPrice60 || 0,
- PromoPrice30: this.bundle.PromoPrice30 || 0,
- ComboPrice100: this.bundle.ComboPrice100 || 0,
- ComboPrice90: this.bundle.ComboPrice90 || 0,
- ComboPrice60: this.bundle.ComboPrice60 || 0,
- ComboPrice30: this.bundle.ComboPrice30 || 0,
- CipenRegularPrice100: this.bundle.CipenRegularPrice100 || 0,
- CipenRegularPrice90: this.bundle.CipenRegularPrice90 || 0,
- CipenRegularPrice60: this.bundle.CipenRegularPrice60 || 0,
- CipenRegularPrice30: this.bundle.CipenRegularPrice30 || 0,
- CipenSpecialPrice100: this.bundle.CipenSpecialPrice100 || 0,
- CipenSpecialPrice90: this.bundle.CipenSpecialPrice90 || 0,
- CipenSpecialPrice60: this.bundle.CipenSpecialPrice60 || 0,
- CipenSpecialPrice30: this.bundle.CipenSpecialPrice30 || 0,
- CipenPromoPrice100: this.bundle.CipenPromoPrice100 || 0,
- CipenPromoPrice90: this.bundle.CipenPromoPrice90 || 0,
- CipenPromoPrice60: this.bundle.CipenPromoPrice60 || 0,
- CipenPromoPrice30: this.bundle.CipenPromoPrice30 || 0,
- CipenComboPrice100: this.bundle.CipenComboPrice100 || 0,
- CipenComboPrice90: this.bundle.CipenComboPrice90 || 0,
- CipenComboPrice60: this.bundle.CipenComboPrice60 || 0,
- CipenComboPrice30: this.bundle.CipenComboPrice30 || 0,
- CikenRegularPrice100: this.bundle.CikenRegularPrice100 || 0,
- CikenRegularPrice90: this.bundle.CikenRegularPrice90 || 0,
- CikenRegularPrice60: this.bundle.CikenRegularPrice60 || 0,
- CikenRegularPrice30: this.bundle.CikenRegularPrice30 || 0,
- CikenSpecialPrice100: this.bundle.CikenSpecialPrice100 || 0,
- CikenSpecialPrice90: this.bundle.CikenSpecialPrice90 || 0,
- CikenSpecialPrice60: this.bundle.CikenSpecialPrice60 || 0,
- CikenSpecialPrice30: this.bundle.CikenSpecialPrice30 || 0,
- CikenPromoPrice100: this.bundle.CikenPromoPrice100 || 0,
- CikenPromoPrice90: this.bundle.CikenPromoPrice90 || 0,
- CikenPromoPrice60: this.bundle.CikenPromoPrice60 || 0,
- CikenPromoPrice30: this.bundle.CikenPromoPrice30 || 0,
- CikenComboPrice100: this.bundle.CikenComboPrice100 || 0,
- CikenComboPrice90: this.bundle.CikenComboPrice90 || 0,
- CikenComboPrice60: this.bundle.CikenComboPrice60 || 0,
- CikenComboPrice30: this.bundle.CikenComboPrice30 || 0,
- CimenRegularPrice100: this.bundle.CimenRegularPrice100 || 0,
- CimenRegularPrice90: this.bundle.CimenRegularPrice90 || 0,
- CimenRegularPrice60: this.bundle.CimenRegularPrice60 || 0,
- CimenRegularPrice30: this.bundle.CimenRegularPrice30 || 0,
- CimenSpecialPrice100: this.bundle.CimenSpecialPrice100 || 0,
- CimenSpecialPrice90: this.bundle.CimenSpecialPrice90 || 0,
- CimenSpecialPrice60: this.bundle.CimenSpecialPrice60 || 0,
- CimenSpecialPrice30: this.bundle.CimenSpecialPrice30 || 0,
- CimenPromoPrice100: this.bundle.CimenPromoPrice100 || 0,
- CimenPromoPrice90: this.bundle.CimenPromoPrice90 || 0,
- CimenPromoPrice60: this.bundle.CimenPromoPrice60 || 0,
- CimenPromoPrice30: this.bundle.CimenPromoPrice30 || 0,
- CimenComboPrice100: this.bundle.CimenComboPrice100 || 0,
- CimenComboPrice90: this.bundle.CimenComboPrice90 || 0,
- CimenComboPrice60: this.bundle.CimenComboPrice60 || 0,
- CimenComboPrice30: this.bundle.CimenComboPrice30 || 0,
- Quantity100: this.bundle.QuantityBundle100 || 0,
- Quantity90: this.bundle.QuantityBundle90 || 0,
- Quantity60: this.bundle.QuantityBundle60 || 0,
- Quantity30: this.bundle.QuantityBundle30 || 0,
- ProcurementType: this.bundle.ProcurementType,
- SNI1: this.bundle.SNI1,
- SNI2: this.bundle.SNI2,
- SNI3: this.bundle.SNI3,
- },
- LegalEntityId: this.userData.LegalEntityId,
- BranchId: this.userData.BranchId,
- TotalQuantity: this.bundle.TotalQuantity,
- Quantity100: this.bundle.QuantityBundle100 || 0,
- Quantity90: this.bundle.QuantityBundle90 || 0,
- Quantity60: this.bundle.QuantityBundle60 || 0,
- Quantity30: this.bundle.QuantityBundle30 || 0,
- Price100: this.bundle.BundlePrice100 || 0,
- Price90: this.bundle.BundlePrice90 || 0,
- Price60: this.bundle.BundlePrice60 || 0,
- Price30: this.bundle.BundlePrice30 || 0,
- ExtraPrice100: this.bundle.OwnerPrice100 || 0,
- ExtraPrice90: this.bundle.OwnerPrice90 || 0,
- ExtraPrice60: this.bundle.OwnerPrice60 || 0,
- ExtraPrice30: this.bundle.OwnerPrice30 || 0,
- BazaarPrice100: this.bundle.Bazaar100 || 0,
- BazaarPrice90: this.bundle.Bazaar90 || 0,
- BazaarPrice60: this.bundle.Bazaar60 || 0,
- BazaarPrice30: this.bundle.Bazaar30 || 0,
- Picture1: this.bundle.Picture1 || null,
- BuyingPrice100: this.bundle.BuyingPrice100 || 0,
- BuyingPrice90: this.bundle.BuyingPrice90 || 0,
- BuyingPrice60: this.bundle.BuyingPrice60 || 0,
- BuyingPrice30: this.bundle.BuyingPrice30 || 0,
- SpecialPrice100: this.bundle.SpecialPrice100 || 0,
- SpecialPrice90: this.bundle.SpecialPrice90 || 0,
- SpecialPrice60: this.bundle.SpecialPrice60 || 0,
- SpecialPrice30: this.bundle.SpecialPrice30 || 0,
- PromoPrice100: this.bundle.PromoPrice100 || 0,
- PromoPrice90: this.bundle.PromoPrice90 || 0,
- PromoPrice60: this.bundle.PromoPrice60 || 0,
- PromoPrice30: this.bundle.PromoPrice30 || 0,
- ComboPrice100: this.bundle.ComboPrice100 || 0,
- ComboPrice90: this.bundle.ComboPrice90 || 0,
- ComboPrice60: this.bundle.ComboPrice60 || 0,
- ComboPrice30: this.bundle.ComboPrice30 || 0,
- CipenRegularPrice100: this.bundle.CipenRegularPrice100 || 0,
- CipenRegularPrice90: this.bundle.CipenRegularPrice90 || 0,
- CipenRegularPrice60: this.bundle.CipenRegularPrice60 || 0,
- CipenRegularPrice30: this.bundle.CipenRegularPrice30 || 0,
- CipenSpecialPrice100: this.bundle.CipenSpecialPrice100 || 0,
- CipenSpecialPrice90: this.bundle.CipenSpecialPrice90 || 0,
- CipenSpecialPrice60: this.bundle.CipenSpecialPrice60 || 0,
- CipenSpecialPrice30: this.bundle.CipenSpecialPrice30 || 0,
- CipenPromoPrice100: this.bundle.CipenPromoPrice100 || 0,
- CipenPromoPrice90: this.bundle.CipenPromoPrice90 || 0,
- CipenPromoPrice60: this.bundle.CipenPromoPrice60 || 0,
- CipenPromoPrice30: this.bundle.CipenPromoPrice30 || 0,
- CipenComboPrice100: this.bundle.CipenComboPrice100 || 0,
- CipenComboPrice90: this.bundle.CipenComboPrice90 || 0,
- CipenComboPrice60: this.bundle.CipenComboPrice60 || 0,
- CipenComboPrice30: this.bundle.CipenComboPrice30 || 0,
- CikenRegularPrice100: this.bundle.CikenRegularPrice100 || 0,
- CikenRegularPrice90: this.bundle.CikenRegularPrice90 || 0,
- CikenRegularPrice60: this.bundle.CikenRegularPrice60 || 0,
- CikenRegularPrice30: this.bundle.CikenRegularPrice30 || 0,
- CikenSpecialPrice100: this.bundle.CikenSpecialPrice100 || 0,
- CikenSpecialPrice90: this.bundle.CikenSpecialPrice90 || 0,
- CikenSpecialPrice60: this.bundle.CikenSpecialPrice60 || 0,
- CikenSpecialPrice30: this.bundle.CikenSpecialPrice30 || 0,
- CikenPromoPrice100: this.bundle.CikenPromoPrice100 || 0,
- CikenPromoPrice90: this.bundle.CikenPromoPrice90 || 0,
- CikenPromoPrice60: this.bundle.CikenPromoPrice60 || 0,
- CikenPromoPrice30: this.bundle.CikenPromoPrice30 || 0,
- CikenComboPrice100: this.bundle.CikenComboPrice100 || 0,
- CikenComboPrice90: this.bundle.CikenComboPrice90 || 0,
- CikenComboPrice60: this.bundle.CikenComboPrice60 || 0,
- CikenComboPrice30: this.bundle.CikenComboPrice30 || 0,
- CimenRegularPrice100: this.bundle.CimenRegularPrice100 || 0,
- CimenRegularPrice90: this.bundle.CimenRegularPrice90 || 0,
- CimenRegularPrice60: this.bundle.CimenRegularPrice60 || 0,
- CimenRegularPrice30: this.bundle.CimenRegularPrice30 || 0,
- CimenSpecialPrice100: this.bundle.CimenSpecialPrice100 || 0,
- CimenSpecialPrice90: this.bundle.CimenSpecialPrice90 || 0,
- CimenSpecialPrice60: this.bundle.CimenSpecialPrice60 || 0,
- CimenSpecialPrice30: this.bundle.CimenSpecialPrice30 || 0,
- CimenPromoPrice100: this.bundle.CimenPromoPrice100 || 0,
- CimenPromoPrice90: this.bundle.CimenPromoPrice90 || 0,
- CimenPromoPrice60: this.bundle.CimenPromoPrice60 || 0,
- CimenPromoPrice30: this.bundle.CimenPromoPrice30 || 0,
- CimenComboPrice100: this.bundle.CimenComboPrice100 || 0,
- CimenComboPrice90: this.bundle.CimenComboPrice90 || 0,
- CimenComboPrice60: this.bundle.CimenComboPrice60 || 0,
- CimenComboPrice30: this.bundle.CimenComboPrice30 || 0,
- ProcurementType: this.bundle.ProcurementType,
- SNI1: this.bundle.SNI1,
- SNI2: this.bundle.SNI2,
- SNI3: this.bundle.SNI3,
- SafetyStockLimit: this.bundle.SafetyStockLimit,
- Location: this.bundle.Location,
- SellingPrice: this.bundle.Price,
- RefurbishQuantity: 0,
- SupplierId: null,
- HistoryQuantity: this.bundle.TotalQuantity,
- EmployeeId: this.userData.EmployeeId,
- IsRefurbish: 1,
- Position: 'Bundle - Tambah Bundle',
- BundleId: this.bundle.Id
- }
- //IF inventory untuk bundle ini belum ada -- START
- if(this.checkInventory == false) {
- let inv = await Inventories.create(bundleAsInventory)
- let ItemId = inv.data.itemBranchId
- console.log(inv.status == 200)
- this.bundle.ItemId = ItemId
- bundleAsInventory.BundleId = this.bundle.Id
- await Inventories.edit(ItemId, bundleAsInventory)
- //IF inventory untuk bundle ini belum ada -- END
- }
- else if(this.checkInventory == true) {
- /**
- * Get ItemId (variable boleh diganti)
- */
- await Inventories.edit(this.getInventory[0].Id, bundleAsInventory)
- }
- // check ad perubahan di bundlenya atau tidak
- if(existingBundle.Quantity100 != bundleAsInventory.Quantity100) {
- bundleAsInventory.Quantity100 = existingBundle.Quantity100
- bundleChange = true
- }
- // check ad perubahan di bundlenya atau tidak
- if(existingBundle.Quantity90 != bundleAsInventory.Quantity90) {
- bundleAsInventory.Quantity90 = existingBundle.Quantity90
- bundleChange = true
- }
- // check ad perubahan di bundlenya atau tidak
- if(existingBundle.Quantity60 != bundleAsInventory.Quantity60) {
- bundleAsInventory.Quantity60 = existingBundle.Quantity60
- bundleChange = true
- }
- // check ad perubahan di bundlenya atau tidak
- if(existingBundle.Quantity30 != bundleAsInventory.Quantity30) {
- bundleAsInventory.Quantity30 = existingBundle.Quantity30
- bundleChange = true
- }
- if(bundleChange == true) {
- // ambil seisi item details di bundle
- // akses langsung this.itemDetails
- // loop item details
- for(let id = 0; id < this.itemDetails.length; id++) {
- let itemDetailsBefore = null;
- if(id > 0) {
- itemDetailsBefore = this.itemDetails[id - 1]
- }
- let itemInventoryRequest = await Inventories.detail(this.itemDetails[id].ItemId)
- if(itemInventoryRequest.status == 200) {
- let itemInventory = itemInventoryRequest.data
- // cek dulu apa barangnya dengan barang sebelumnya sama?
- if(itemDetailsBefore.ItemId == this.itemDetails[id].ItemId) {
- // jumlahkan nominalnya disini
- itemDetailsBefore.Quantity100 += this.itemDetails.Quantity100
- itemDetailsBefore.Quantity90 += this.itemDetails.Quantity90
- itemDetailsBefore.Quantity60 += this.itemDetails.Quantity60
- itemDetailsBefore.Quantity30 += this.itemDetails.Quantity30
- // jika item tidak sama maka langsung eksekusi akhir
- } else {
- // eksekusi akhir disini, cm sy msh blum kebayang full apa aja yg hrs dilakukan disini
- // sy kebayangnya update inventory disini
- }
- }
- }
- }
- this.bundle.DeliveryStatus = 'Final'
- this.bundle.SafetyStockLimit = this.bundle.SafetyStockLimit
- console.log(JSON.parse(JSON.stringify(this.itemdetails)).length)
- result = await Bundle.edit(this.$route.params.id, this.bundle)
- }
- if(result.status == 200) {
- this.$fire({
- title: 'Sukses',
- text: 'Data Telah diupdate',
- icon: 'info',
- type: 'success',
- showConfirmButton: false
- })
- this.$router.push({ name: 'BundleManagement.index' })
- location.reload()
- } else {
- this.$fire({
- title: 'Error',
- text: 'Input Data Gagal',
- icon: 'error',
- type: 'error',
- showConfirmButton: false,
- })
- console.log(result)
- }
- } catch (error) {
- alert("Error : " + error.response.data.message)
- }
- },
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement