Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <template>
- <div class="row">
- <div class="col-lg-12">
- <b-tabs pills card>
- <b-tab title="Bundle" active>
- <div v-if="loading && !$route.name.includes('.create')" class="d-flex justify-content-center mb-3">
- <b-spinner label="Loading..."></b-spinner>
- </div>
- <div v-if="$route.name.includes('.detail')" class="row">
- <div class="col-lg-12 button-back-div">
- <router-link :to="{ name: 'BundleManagement.index' }" class="btn btn-primary">Kembali</router-link>
- </div>
- </div>
- <div class="row">
- <div class="col-lg-12" style="padding-left: 30px; padding-right: 40px;">
- <div class="row">
- <div class="col-lg-6">
- <div class="form-group form-float">
- <!-- Foto field -->
- <label class="form-label" style="color: black;">Lampiran</label>
- <img v-if="$route.name.includes('.detail')" :src="'data:image/jpeg;base64,' + bundle.Picture1" class="img-fluid img-thumbnail" style="width: 50% !important; height: 50% !important" />
- <base64-upload v-if="!$route.name.includes('.detail')" class="img-fluid" imageSrc="/img/uploads.png" @change="onChangeImage1" style="width: 50% !important; height: 50% !important" >Upload photo</base64-upload>
- </div>
- </div>
- </div>
- <div class="row">
- <!-- Kode Bundle field -->
- <div class="col-lg-6">
- <div class="form-group form-float">
- <label for="date" class="form-label" style="color: black;">Kode Bundle</label>
- <input :disabled="$route.name.includes('.detail')" placeholder="Ketik kode bundle..." id="date" type="text" v-model="bundle.Code" required maxlength="32" minlength="2" class="validate form-control" style="border: 1px solid black;">
- </div>
- </div>
- <!-- Nama Bundle field -->
- <div class="col-lg-6">
- <div class="form-group form-float">
- <label for="date" class="form-label" style="color: black;">Nama Bundle</label>
- <input :disabled="$route.name.includes('.detail')" placeholder="Ketik nama bundle..." id="date" type="text" v-model="bundle.Name" required maxlength="32" minlength="2" class="validate form-control" style="border: 1px solid black;">
- </div>
- </div>
- <!-- Kategori Barang field -->
- <div class="col-lg-6">
- <div class="form-group form-float">
- <label for="date" class="form-label" style="color: black;">Kategori Barang</label>
- <vue-select :disabled="$route.name.includes('.detail')" v-model="bundle.Category" class="vue-select2" name="role" :options="category" label="Name"></vue-select>
- </div>
- </div>
- <!-- Kategori Gudang field -->
- <div class="col-lg-6">
- <div class="form-group form-float">
- <label for="date" class="form-label" style="color: black;">Kategori Gudang</label>
- <vue-select :disabled="$route.name.includes('.detail')" v-model="bundle.WarehouseCategory" class="vue-select2" name="role" :options="warehouseCategory"></vue-select>
- </div>
- </div>
- <!-- Jumlah Bundle field -->
- <div class="col-lg-6">
- <div class="form-group form-float">
- <label for="flagName" class="form-label" style="color: black;">Jumlah Bundle</label>
- <input :disabled="$route.name.includes('.detail')" placeholder="Ketik nama bundle..." id="date" type="text" v-model="bundle.BundleQuantity" required maxlength="32" minlength="2" class="validate form-control" style="border: 1px solid black;">
- </div>
- </div>
- <div class="col-lg-6">
- <div class="form-group form-float">
- <label for="date" class="form-label" style="color: black;">Harga Bundle (Rp)</label>
- <input v-if="!$route.name.includes('.detail')" placeholder="Ketik harga bundle..." id="date" type="text" v-model="bundle.Price" required maxlength="32" minlength="2" class="validate form-control" style="border: 1px solid black;">
- <div v-if="$route.name.includes('.detail')" class="form-control disabled-field">{{ bundle.Price | currency }}</div>
- </div>
- </div>
- </div>
- <hr />
- <!-- Dynamic Row -->
- <div v-for="(item, index) in bundle.BundleItems" :key="index" class="row">
- <div class="col-lg-12" style="margin-top: 15px;">
- <div class="row">
- <!-- Nama Barang field -->
- <div class="col-lg-12">
- <div class="form-group form-float">
- <label for="flagName" class="form-label" style="color: black;">Nama Barang</label>
- <div class="form-group form-float">
- <vue-select :disabled="$route.name.includes('.detail')" v-model="selectedInventory[index]" class="vue-select2" name="role" :options="inventory" label="Name"></vue-select>
- </div>
- </div>
- </div>
- <!-- Nama Barang field -->
- <div class="col-lg-6">
- <div class="form-group form-float">
- <label for="productNumber" class="form-label" style="color: black;">Nama Barang</label>
- <input disabled placeholder="Auto generate..." id="productNumber" type="text" v-model="item.Name" required maxlength="32" minlength="2" class="validate form-control" style="border: 1px solid black;">
- </div>
- </div>
- <!-- Kode Barang field -->
- <div class="col-lg-6">
- <div class="form-group form-float">
- <label for="productNumber" class="form-label" style="color: black;">Kode Barang</label>
- <input disabled placeholder="Auto generate..." id="productNumber" type="text" v-model="item.Code" required maxlength="32" minlength="2" class="validate form-control" style="border: 1px solid black;">
- </div>
- </div>
- <!-- Kategori Barang field -->
- <div class="col-lg-6">
- <div class="form-group form-float">
- <label for="productNumber" class="form-label" style="color: black;">Kategori Barang</label>
- <input disabled placeholder="Auto generate..." id="productNumber" type="text" v-model="item.Category" required maxlength="32" minlength="2" class="validate form-control" style="border: 1px solid black;">
- </div>
- </div>
- <!-- Kategori Gudang field -->
- <div class="col-lg-6">
- <div class="form-group form-float">
- <label for="productNumber" class="form-label" style="color: black;">Kategori Gudang</label>
- <input disabled placeholder="Auto generate..." id="productNumber" type="text" v-model="item.WarehouseCategory" required maxlength="32" minlength="2" class="validate form-control" style="border: 1px solid black;">
- </div>
- </div>
- <!-- Jumlah Stock Opname field -->
- <div class="col-lg-6">
- <div class="form-group form-float">
- <label for="productNumber" class="form-label" style="color: black;">Jumlah Barang</label>
- <input disabled placeholder="Auto generate..." id="productNumber" type="text" v-model="item.TotalQuantity" required maxlength="32" minlength="2" class="validate form-control" style="border: 1px solid black;">
- </div>
- </div>
- <!-- Jumlah Bundle field -->
- <div class="col-lg-6">
- <div class="form-group form-float">
- <label for="productNumber" class="form-label" style="color: black;">Jumlah Barang Bundle</label>
- <input :disabled="$route.name.includes('.detail')" placeholder="Auto generate..." id="productNumber" type="text" v-model="item.TotalBundleQuantity" required maxlength="32" minlength="2" class="validate form-control" style="border: 1px solid black;">
- </div>
- </div>
- <!-- Harga Barang field -->
- <div class="col-lg-6">
- <div class="form-group form-float">
- <label for="productNumber" class="form-label" style="color: black;">Harga Barang</label>
- <!-- <input disabled placeholder="Auto generate..." id="productNumber" type="text" v-model="item.SellingPrice" required maxlength="32" minlength="2" class="validate form-control" style="border: 1px solid black;"> -->
- <div class="form-control disabled-field">{{ item.SellingPrice | currency }}</div>
- </div>
- </div>
- </div>
- <hr />
- </div>
- </div>
- <div v-if="!$route.name.includes('.detail')" class="row" style="padding-left: 0px;">
- <div class="col-lg-3">
- <button @click="add()" type="submit" class="btn waves-effect add-btn" style="width: 100%; background-color: #20c197; color: white; margin-top: 15px;">
- Tambah
- </button>
- </div>
- <div class="col-lg-3">
- <button v-show="bundle.BundleItems.length > 1" @click="del()" type="submit" class="btn btn-danger" style="width: 100%; background-color: #c52c46; color: white; margin-top: 15px; border-color: #c52c46;">
- Hapus
- </button>
- </div>
- </div>
- </div>
- </div>
- <div v-if="!$route.name.includes('.detail')" class="row">
- <div class="col-lg-12 button-div">
- <button v-on:click="save()" class="btn btn-success">Simpan</button>
- <router-link :to="{ name: 'BundleManagement.index' }" class="btn btn-default">Batal</router-link>
- </div>
- </div>
- </b-tab>
- </b-tabs>
- </div>
- </div>
- </template>
- <style>
- .card-header {
- width: 1620px;
- background-color: #20c197;
- border-radius: 0px !important;
- padding-left: 10px;
- padding-top: 0px;
- padding-right: 0px;
- padding-bottom: 0px;
- }
- .nav-pills .nav-link.active, .nav-pills .show>.nav-link {
- color: black;
- background-color: #f8f8ff;
- border-radius: 0px;
- border-bottom: 3px solid #0059aa;
- }
- .button-div {
- text-align: right;
- margin-top: 30px;
- }
- .btn-success {
- width: 132px;
- background-color: #20c197;
- border: none;
- }
- .btn-danger {
- width: 132px;
- margin-left: 15px;
- border: none;
- }
- .disabled-field {
- background-color: #E9ECEF;
- border: 1px solid black;
- }
- </style>
- <script>
- // Plugins
- import moment from 'moment'
- import $ from 'jquery'
- import VueSelect from 'vue-select'
- import 'vue-select/dist/vue-select.css'
- import Base64Upload from 'vue-base64-upload'
- // API
- // import LegalEntity from '@/services/Companies/LegalEntities'
- // import Branch from '@/services/Companies/Branches'
- import Bundle from '@/services/Inventories/Bundle'
- import Inventories from '@/services/Inventories/Inventory'
- export default {
- name: 'BundleManagement.create',
- components: {
- VueSelect,
- Base64Upload
- },
- data () {
- return {
- //Loading
- loading: true,
- // Scope, Sama kyk vm.users , vm.employee dkk
- userData: {},
- bundle: {
- BundleItems: [{
- "Id": null,
- "Name": null,
- "Code": null,
- "Category": null,
- "WarehouseCategory": null,
- "TotalQuantity": null,
- "SellingPrice": null,
- "TotalBundleQuantity": null
- }]
- },
- inventory: {},
- selectedInventory: [],
- category: ['-','Barang Inti','Barang Hadiah'],
- warehouseCategory: ['Alat Tulis','Barang Siap Jual'],
- // rawItemCollection: []
- }
- },
- beforeUpdate: function () {
- // Ngeassign variable pada saat proses update, misal kyk dropdown
- this.bundle.BundleItems[this.bundle.BundleItems.length - 1] = {
- "Id": this.selectedInventory[this.bundle.BundleItems.length - 1].Id,
- "Name": this.selectedInventory[this.bundle.BundleItems.length - 1].Name,
- "Code": this.selectedInventory[this.bundle.BundleItems.length - 1].Code,
- "Category": this.selectedInventory[this.bundle.BundleItems.length - 1].Category,
- "WarehouseCategory": this.selectedInventory[this.bundle.BundleItems.length - 1].WarehouseCategory,
- "TotalQuantity": this.selectedInventory[this.bundle.BundleItems.length - 1].TotalQuantity,
- "SellingPrice": this.selectedInventory[this.bundle.BundleItems.length - 1].SellingPrice,
- "TotalBundleQuantity": this.selectedInventory[this.bundle.BundleItems.length - 1].TotalBundleQuantity
- }
- },
- mounted: function () {
- // Sama dengan document.ready
- window.$ = $
- if(localStorage.userData !== undefined) {
- this.userData = JSON.parse(localStorage.userData)
- this.userData.Permissions = JSON.parse(this.userData.Permissions)
- } else {
- this.$router.push({ name: 'home' })
- location.reload()
- }
- this.init()
- },
- methods: {
- // Kumpulan Fungsi disini
- init: async function() {
- // Ngeload Data Dari API
- // let legalEntity = await LegalEntity.index()
- // let branch = await Branch.index()
- let inventory = await Inventories.index()
- // Assign data ke Scope
- // this.legalEntity = legalEntity.data
- // this.branch = branch.data
- this.inventory = this.filterInventoryPusat(inventory.data)
- //for edit mode
- if(this.$route.params.id) {
- let edit = await Bundle.detail(this.$route.params.id)
- this.bundle = edit.data
- this.bundle.BundleItems = JSON.parse(edit.data.BundleItems)
- }
- this.loading = false
- },
- save: async function() {
- // Fungsi Save Data
- console.log(this.bundle)
- this.bundle.IsDeleted = false
- this.bundle.CreationTime = new Date()
- this.bundle.CreatorUserId = this.userData.Id
- // let rawItemCollection = this.bundle.BundleItems
- this.bundle.BundleItems = JSON.stringify(this.bundle.BundleItems)
- try {
- let result
- if(this.$route.params.id) {
- result = await Bundle.edit(this.$route.params.id, this.bundle)
- }
- if(!this.$route.params.id) {
- console.log("create mode")
- result = await Bundle.create(this.bundle)
- console.log("berhasil menambahkan ke bundle")
- //Add Bundle to Inventory
- let bundleAsInventory = {
- Name: this.bundle.Name,
- LegalEntityId: 1,
- BranchId: 1,
- Code: this.bundle.Code,
- Category: "Bundle",
- TotalQuantity: this.bundle.BundleQuantity,
- Quantity100: this.bundle.BundleQuantity,
- Price100: this.bundle.Price,
- Quantity90: 0,
- Price90: 0,
- Quantity60: 0,
- Price60: 0,
- Quantity30: 0,
- SafetyStockLimit: 0,
- BuyingPrice: this.bundle.Price,
- IsDeleted: false,
- CreationTime: new Date(),
- CreatorUserId: this.bundle.CreatorUserId,
- UnasemblyQuantity: 0,
- AssemblyQuantity: 0,
- StockOpnameQuantity: 0,
- RefurbishQuantity: 0,
- isBundle: true
- }
- let resultBundleInventory = await Inventories.create(bundleAsInventory)
- if(resultBundleInventory.status == 200) {
- console.log("Input Bundle Ke Inventory Sukses")
- alert("Input Bundle ke Inventory Sukses")
- } else {
- console.log("Gagal Input Ke Inventory")
- alert("Input Bundle ke Inventory Gagal")
- }
- // console.log(rawItemCollection)
- // //Extract ke inventory di frontend
- // for(var i = 0; i < rawItemCollection.length; i++) {
- // Inventories.detail(rawItemCollection[i].Id).then(function (existingInventory) {
- // console.log(parseInt(existingInventory.data.TotalQuantity) - (parseInt(this.bundle.BundleQuantity) * (parseInt(rawItemCollection[i].TotalBundleQuantity))))
- // let inventoryItems = {
- // Id: existingInventory.data.Id,
- // Name: existingInventory.data.Name,
- // LegalEntityId: 1,
- // BranchId: 1,
- // Code: existingInventory.data.Code,
- // Category: existingInventory.data.Category,
- // TotalQuantity: parseInt(existingInventory.data.TotalQuantity) - (parseInt(this.bundle.BundleQuantity) * (parseInt(rawItemCollection[i].TotalBundleQuantity))),
- // Quantity100: parseInt(existingInventory.data.TotalQuantity) - (parseInt(this.bundle.BundleQuantity) * (parseInt(rawItemCollection[i].TotalBundleQuantity))),
- // Price100: existingInventory.data.Price100,
- // Quantity90: existingInventory.data.Quantity90,
- // Price90: existingInventory.data.Price90,
- // Quantity60: existingInventory.data.Quantity60,
- // Price60: existingInventory.data.Price60,
- // Quantity30: existingInventory.data.Quantity30,
- // SafetyStockLimit: existingInventory.data.SafetyStockLimit,
- // BuyingPrice: existingInventory.data.BuyingPrice,
- // IsDeleted: existingInventory.data.IsDeleted,
- // CreationTime: existingInventory.data.CreationTime,
- // CreatorUserId: this.bundle.CreatorUserId,
- // UnasemblyQuantity: existingInventory.data.UnasemblyQuantity,
- // AssemblyQuantity: existingInventory.data.AssemblyQuantity,
- // StockOpnameQuantity: existingInventory.data.StockOpnameQuantity,
- // RefurbishQuantity: existingInventory.data.RefurbishQuantity,
- // }
- // Inventories.edit(this.rawItemCollection[i].Id, inventoryItems).then(function(resultInventory) {
- // if(resultInventory.status == 200) {
- // console.log("Edit Inventory Sukses")
- // alert("Done Process")
- // } else {
- // console.log("Gagal Edit Inventory")
- // alert("Done Process fail")
- // }
- // })
- // })
- // }
- // alert("Done Process")
- }
- if(result.status == 200) {
- this.$fire({
- title: 'Sukses',
- text: 'Input Data Sukses',
- // icon: 'info',
- // type: 'success',
- showConfirmButton: false
- })
- this.$router.push({ name: 'BundleManagement.index' })
- location.reload()
- } else {
- this.$fire({
- title: 'Error',
- text: 'Input Data Gagal',
- showConfirmButton: false
- // icon: 'error'
- // type: 'error'
- })
- console.log(result)
- }
- } catch (error) {
- alert("Error : " + error)
- }
- },
- add: function () {
- this.bundle.BundleItems.push({
- "Id": null,
- "Name": null,
- "Code": null,
- "Category": null,
- "TotalQuantity": null,
- "SellingPrice": null,
- "TotalBundleQuantity": null
- })
- },
- del: function () {
- this.$delete(this.bundle.BundleItems, this.bundle.BundleItems.length - 1)
- // this.bundle.BundleItems.splice(this.bundle.BundleItems.length, 1)
- },
- onChangeImage1(file) {
- this.bundle.Picture1 = file.base64
- },
- lookupData (json, id) {
- let data = []
- for(var i = 0; i < json.length; i++) {
- data[json[i].Id] = json[i]
- }
- return data[id]
- },
- filterInventoryPusat (json) {
- let data = []
- for(var i = 0; i < json.length; i++) {
- if((json[i].LegalEntityId == 1) && (json[i].BranchId == 1)) {
- data.push(json[i])
- }
- }
- return data
- },
- formatDate(time) {
- // Format Tanggal
- var formattedTime = moment(time).format('DD MMMM YYYY HH:mm')
- if(formattedTime == 'Invalid date') {
- formattedTime = '-'
- }
- return formattedTime
- }
- }
- }
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement