Advertisement
vitareinforce

daftar inventory

Aug 10th, 2020
1,230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <template>
  2.     <div v-if="userData.RoleDetails.IsReadInventory" class="dashboard-contents">
  3.         <div class="row">
  4.             <div class="col-lg-4" style="margin-top: 20px;">
  5.                 <h2 style="padding:15px; margin-top:10px;">Daftar Inventory</h2>
  6.             </div>
  7.             <div class="col-lg-8" style="padding-top: 15px; margin-top: 20px;">
  8.                 <div class="row">
  9.                     <div class="col-lg-3"></div>
  10.                     <div class="col-lg-3">
  11.                         <!-- <router-link v-if="userData.RoleDetails.IsCreateInventory" :to="{name: 'InventoryManagement.import'}" type="button" class="btn btn-info waves-effect waves-circle waves-float pull-right button-import">
  12.                             <img src="@/assets/images/file-import-solid.svg" style="width: 10%; height: 100%;" alt="Alternate Text" /> Import
  13.                         </router-link> -->
  14.                     </div>
  15.                     <div class="col-lg-3">
  16.                         <download-excel v-if="userData.RoleDetails.IsExportInventory" class="btn waves-effect waves-circle waves-float pull-right button-export"
  17.                             worksheet = "Daftar Inventory"
  18.                             name = "data_inventory.xls"
  19.                             :data = "exportData"
  20.                             :fields = "fieldsData">
  21.                             <img src="@/assets/images/file-text.png" alt="Alternate Text" /> Export
  22.                         </download-excel>
  23.                     </div>
  24.                     <div class="col-lg-3">
  25.                         <router-link v-if="userData.RoleDetails.IsCreateInventory" :to="{name: 'InventoryManagement.create'}" type="button" class="btn waves-effect waves-circle waves-float pull-right button-create">
  26.                             <img src="@/assets/images/plus-circle.png" alt="Alternate Text" /> Tambah
  27.                         </router-link>
  28.                     </div>
  29.                 </div>
  30.             </div>
  31.         </div>
  32.        
  33.         <div class="row">
  34.             <div class="col-lg-4"></div>
  35.             <div class="col-lg-8">
  36.                 <div class="row">
  37.                     <div class="col-lg-6"></div>
  38.                     <div class="col-lg-3">
  39.                         <!-- <select class="select-dropdown" name="" id="">
  40.                             <option value="" disabled selected>Pilih bendera...</option>
  41.                             <option value="Semua cabang">Semua bendera</option>
  42.                             <option value="Cabang A">Bendera A</option>
  43.                             <option value="Cabang B">Bendera B</option>
  44.                         </select> -->
  45.                         <vue-select v-if="userData.RoleId != 1" :disabled="$route.name.includes('.detail')" v-model="selectedLegalEntity" class="vue-select2" name="role" :options="userData.AccessSettings.filter(x => x.IsSelected == true)" label="Name"></vue-select>
  46.                         <vue-select v-if="userData.RoleId == 1" :disabled="$route.name.includes('.detail')" v-model="selectedLegalEntity" class="vue-select2" name="role" :options="legalEntity" label="Name"></vue-select>
  47.                     </div>
  48.                     <div class="col-lg-3">
  49.                         <!-- <select class="select-dropdown" name="" id="">
  50.                             <option value="" disabled selected>Pilih cabang...</option>
  51.                             <option value="Semua cabang">Semua cabang</option>
  52.                             <option value="Cabang A">Cabang A</option>
  53.                             <option value="Cabang B">Cabang B</option>
  54.                         </select> -->
  55.                         <vue-select v-if="selectedLegalEntity" :disabled="$route.name.includes('.detail')" v-model="selectedBranch" class="vue-select2" name="role" :options="selectedLegalEntity.branches" label="Name"></vue-select>
  56.                     </div>
  57.                 </div>
  58.             </div>
  59.         </div>
  60.  
  61.         <div class="row">
  62.             <div class="col-lg-12 second-row">
  63.  
  64.                 <hr/>
  65.                 <div class="row">
  66.                     <div class="col-lg-6">
  67.                         <div class="row">
  68.                             <div class="col-lg-10 search-div">
  69.                                 <input type="text" name="permission" placeholder="Cari inventory..." v-model="key" value="" style="width: 100%; height: 38px; float: right; margin-bottom: 10px; border: 1px solid rgba(184, 55, 62, 0.5); background-color: white; border-radius: 5px; padding: 5px; margin-bottom: 24px;" />
  70.                             </div>
  71.                             <div class="col-lg-1 search-div">
  72.                                 <button class="btn btn-primary" @click="search(key)"><span class="fa fa-search"></span></button>
  73.                             </div>
  74.                             <div class="col-lg-1 search-div">
  75.                                 <button v-if="key != ''" class="btn btn-erase" @click="deleteSearch()"><span class="fa fa-times"></span></button>
  76.                             </div>
  77.                         </div>
  78.                     </div>
  79.                    
  80.                 </div>
  81.             </div>
  82.         </div>
  83.  
  84.         <div class="row">
  85.             <div class="col-lg-12">
  86.                 <div class="table-div" style="height: 530px !important;">
  87.                     <b-table striped sticky-header hover
  88.                         id="inventoryTable"
  89.                         :items="inventory"
  90.                         :fields="inventoryField"
  91.                         :filter="query"
  92.                         class="table table-hover table-striped"
  93.                         style="margin-top: 10px; max-height: 500px !important">
  94.                         <template v-slot:cell(Actions)="data">
  95.                             <b-dropdown text="Action" variant="primary" style="width: 120px;" v-if="!data.item.Category.includes('Bundle')">
  96.                                 <b-dropdown-item v-if="userData.RoleDetails.IsUpdateInventory" @click="edit(filterBarangCabang(data.item.inventory_branches, selectorLegalEntity, selectorBranch)[0].Id)">Edit</b-dropdown-item>
  97.                                 <b-dropdown-item v-if="userData.RoleDetails.IsDeleteInventory" @click="del(data.item, data.item.Id)">Delete</b-dropdown-item>
  98.                             </b-dropdown>
  99.                         </template>
  100.                         <template v-slot:cell(Code)="data">
  101.                             <a v-if="userData.RoleDetails.IsReadInventory && filterPosisiBenderaCabangSaatIni(data.item.inventory_branches, selectorLegalEntity, selectorBranch)" @click="detail(filterBarangCabang(data.item.inventory_branches, selectorLegalEntity, selectorBranch)[0].Id)" style="color: #0059aa; cursor: pointer; font-weight: 700;">{{ data.item.Code }}</a>
  102.                             <div v-if="userData.RoleDetails.IsReadInventory && !filterPosisiBenderaCabangSaatIni(data.item.inventory_branches, selectorLegalEntity, selectorBranch)">{{ data.item.Code }}</div>
  103.                         </template>
  104.                         <template v-slot:cell(Price100)="data">
  105.                             {{ data.item.Price100 | currency }}
  106.                         </template>
  107.                         <template v-slot:cell(Price90)="data">
  108.                             {{ data.item.Price90 | currency }}
  109.                         </template>
  110.                         <template v-slot:cell(Price60)="data">
  111.                             {{ data.item.Price60 | currency }}
  112.                         </template>
  113.                         <template v-slot:cell(Price30)="data">
  114.                             {{ data.item.Price30 | currency }}
  115.                         </template>
  116.                         <template v-if="userData.RoleDetails.IsReadBuyingPriceInventory" v-slot:cell(BuyingPrice100)="data">
  117.                             {{ data.item.BuyingPrice100 | currency }}
  118.                         </template>
  119.                         <template v-if="userData.RoleDetails.IsReadBuyingPriceInventory" v-slot:cell(BuyingPrice90)="data">
  120.                             {{ data.item.BuyingPrice90 | currency }}
  121.                         </template>
  122.                         <template v-if="userData.RoleDetails.IsReadBuyingPriceInventory" v-slot:cell(BuyingPrice60)="data">
  123.                             {{ data.item.BuyingPrice60 | currency }}
  124.                         </template>
  125.                         <template v-if="userData.RoleDetails.IsReadBuyingPriceInventory" v-slot:cell(BuyingPrice30)="data">
  126.                             {{ data.item.BuyingPrice30 | currency }}
  127.                         </template>
  128.                         <template v-slot:cell(Point)="data">
  129.                             {{ data.item.Point | currency({ symbol: '', thousandsSeparator: '.', fractionCount: '', fractionSeparator: '', symbolPosition: '', symbolSpacing: '' }) }}
  130.                         </template>
  131.                         <template v-slot:cell(LegalEntityId)="data">
  132.                             <div v-if="filterBarangCabang(data.item.inventory_branches, selectorLegalEntity, selectorBranch)[0] !== undefined">{{ filterBarangCabang(data.item.inventory_branches, selectorLegalEntity, selectorBranch)[0].legal_entity.Name }}</div>
  133.                         </template>
  134.                         <template v-slot:cell(BranchId)="data">
  135.                             <div v-if="filterBarangCabang(data.item.inventory_branches, selectorLegalEntity, selectorBranch)[0] !== undefined">{{ filterBarangCabang(data.item.inventory_branches, selectorLegalEntity, selectorBranch)[0].branch.Name }}</div>
  136.                         </template>
  137.                         <template v-slot:cell(Location)="data">
  138.                             <div v-if="filterBarangCabang(data.item.inventory_branches, selectorLegalEntity, selectorBranch)[0] !== undefined">{{ filterBarangCabang(data.item.inventory_branches, selectorLegalEntity, selectorBranch)[0].Location }}</div>
  139.                         </template>
  140.                         <template v-slot:cell(RefurbishQuantity)="data">
  141.                             <div v-if="filterBarangCabang(data.item.inventory_branches, selectorLegalEntity, selectorBranch)[0] !== undefined">{{ filterBarangCabang(data.item.inventory_branches, selectorLegalEntity, selectorBranch)[0].RefurbishQuantity }}</div>
  142.                         </template>
  143.                         <template v-slot:cell(Quantity100)="data">
  144.                             <div v-if="filterBarangCabang(data.item.inventory_branches, selectorLegalEntity, selectorBranch)[0] !== undefined">{{ filterBarangCabang(data.item.inventory_branches, selectorLegalEntity, selectorBranch)[0].Quantity100  | currency({ symbol: '', thousandsSeparator: '.', fractionCount: '', fractionSeparator: '', symbolPosition: '', symbolSpacing: '' }) }}</div>
  145.                         </template>
  146.                         <template v-slot:cell(Quantity90)="data">
  147.                             <div v-if="filterBarangCabang(data.item.inventory_branches, selectorLegalEntity, selectorBranch)[0] !== undefined">{{ filterBarangCabang(data.item.inventory_branches, selectorLegalEntity, selectorBranch)[0].Quantity90  | currency({ symbol: '', thousandsSeparator: '.', fractionCount: '', fractionSeparator: '', symbolPosition: '', symbolSpacing: '' }) }}</div>
  148.                         </template>
  149.                         <template v-slot:cell(Quantity60)="data">
  150.                             <div v-if="filterBarangCabang(data.item.inventory_branches, selectorLegalEntity, selectorBranch)[0] !== undefined">{{ filterBarangCabang(data.item.inventory_branches, selectorLegalEntity, selectorBranch)[0].Quantity60  | currency({ symbol: '', thousandsSeparator: '.', fractionCount: '', fractionSeparator: '', symbolPosition: '', symbolSpacing: '' }) }}</div>
  151.                         </template>
  152.                         <template v-slot:cell(Quantity30)="data">
  153.                             <div v-if="filterBarangCabang(data.item.inventory_branches, selectorLegalEntity, selectorBranch)[0] !== undefined">{{ filterBarangCabang(data.item.inventory_branches, selectorLegalEntity, selectorBranch)[0].Quantity30  | currency({ symbol: '', thousandsSeparator: '.', fractionCount: '', fractionSeparator: '', symbolPosition: '', symbolSpacing: '' }) }}</div>
  154.                         </template>
  155.                         <template v-slot:cell(TotalQuantityC)="data">
  156.                             <div v-if="filterBarangCabang(data.item.inventory_branches, selectorLegalEntity, selectorBranch)[0] !== undefined">{{ calculateTotal(filterBarangCabang(data.item.inventory_branches, selectorLegalEntity, selectorBranch)[0])  | currency({ symbol: '', thousandsSeparator: '.', fractionCount: '', fractionSeparator: '', symbolPosition: '', symbolSpacing: '' }) }}</div>
  157.                         </template>
  158.                         <template v-slot:cell(SafetyStockStatus)="data">
  159.                             <div v-if="filterBarangCabang(data.item.inventory_branches, selectorLegalEntity, selectorBranch)[0] !== undefined">
  160.                                 <div v-if="parseInt(calculateTotal(filterBarangCabang(data.item.inventory_branches, selectorLegalEntity, selectorBranch)[0])) > parseInt(filterBarangCabang(data.item.inventory_branches, selectorLegalEntity, selectorBranch)[0].SafetyStockLimit)">
  161.                                     <button type="button" class="btn btn-success">Stock Aman</button>
  162.                                 </div>
  163.                                 <div v-if="(parseInt(calculateTotal(filterBarangCabang(data.item.inventory_branches, selectorLegalEntity, selectorBranch)[0])) <= parseInt(filterBarangCabang(data.item.inventory_branches, selectorLegalEntity, selectorBranch)[0].SafetyStockLimit)) && (parseInt(calculateTotal(filterBarangCabang(data.item.inventory_branches, selectorLegalEntity, selectorBranch)[0])) > 0)">
  164.                                     <button type="button" class="btn btn-warning">Restock</button>
  165.                                 </div>
  166.                                 <div v-if="parseInt(calculateTotal(filterBarangCabang(data.item.inventory_branches, selectorLegalEntity, selectorBranch)[0])) <= 0">
  167.                                     <button type="button" class="btn btn-danger">Stock Habis</button>
  168.                                 </div>
  169.                             </div>
  170.                         </template>
  171.                     </b-table>
  172.                     <div v-if="loading" class="d-flex justify-content-center mb-3">
  173.                         <b-spinner label="Loading..."></b-spinner>
  174.                     </div>
  175.                 </div>
  176.             </div>
  177.         </div>
  178.     </div>
  179. </template>
  180.  
  181. <script>
  182. import moment from 'moment'
  183. import $ from 'jquery'
  184. import DownloadExcel from 'vue-json-excel'
  185. import VueSelect from 'vue-select'
  186. import 'vue-select/dist/vue-select.css'
  187.  
  188. import Inventories from '@/services/Inventories/Inventory'
  189. import LegalEntities from '@/services/Companies/LegalEntities'
  190. import Branches from '@/services/Companies/Branches'
  191.  
  192. export default {
  193.   name: 'InventoryManagement.index',
  194.   components: {
  195.     DownloadExcel,
  196.     VueSelect
  197.   },
  198.   computed: {
  199.     rows () {
  200.       //hitung panjang data Inventory
  201.       return this.inventory.length
  202.     },
  203.     filtered: function () {
  204.  
  205.         // Rule 1, Bundle untuk cabang, pusat all
  206.         // if((this.userData.LegalEntityId == 1) && (this.userData.BranchId == 1)) {
  207.         //     return this.inventory
  208.         // } else {
  209.         //     return this.inventory.filter(i => i.IsBundle == 1)
  210.         // }
  211.  
  212.         // // Rule 2, Bundle + satuan punya cabang itu sendiri, pusat all
  213.         // if((this.userData.LegalEntityId == 1) && (this.userData.BranchId == 1)) {
  214.         //     return this.inventory
  215.         // } else {
  216.         //     return this.inventory.filter(i => i.BranchId == this.userData.BranchId)
  217.         // }
  218.  
  219.        
  220.        
  221.        
  222.         // Case 1
  223.         // if (this.userData.AccessSettings.branches) {
  224.         //     console.log("ga masuk")
  225.         //     return this.inventory
  226.         // } else {
  227.         //     console.log("masuk")
  228.         //     return this.inventory.filter(i => i.BranchId == this.userData.AccessSettings[i].branches)
  229.         // }
  230.  
  231.         // Case 2
  232.         // return this.inventory.filter(i => i.BranchId == this.userData.BranchId)
  233.  
  234.         // Case 3
  235.         // return this.inventory.filter(i => i.BranchId == JSON.parse(this.userData.AccessSettings.branches.Id))
  236.  
  237.         // let arrayToString = JSON.stringify(Object.assign({}, this.userData.AccessSettings))
  238.         // let jsonObject = JSON.parse(arrayToString)
  239.         // console.log(JSON.parse(JSON.stringify(Object.assign({}, this.userData.AccessSettings))))
  240.         // console.log(JSON.parse(JSON.stringify(Object.assign({}, this.userData.AccessSettings.branches))))
  241.  
  242.        
  243.         // Case 4
  244.         // for (var i = 0; i < this.inventory.length; i++) {
  245.         //     for (var j = 0; j < this.userData.AccessSettings.length; j++) {
  246.         //         if ((this.inventory[i].LegalEntityId == this.userData.AccessSettings[j].Id) && (this.inventory[i].BranchId == this.userData.AccessSettings[j].Branches.Id)) {
  247.         //             return this.inventory.filter(this.inventory[i].BranchId == this.userData.AccessSettings[j].Branches.Id)
  248.         //         }
  249.         //     }
  250.         // }
  251.  
  252.         // Case 5
  253.         // for (var i = 0; i < this.inventory.length; i++) {
  254.         //     for (var j = 0; j < this.userData.AccessSettings.length-1; j++) {
  255.         //         if ((this.inventory[i].LegalEntityId == this.userData.AccessSettings[j].Id) && (this.inventory[i].BranchId == this.userData.AccessSettings[j].Branches.Id)) {
  256.         //             console.log(this.inventory[i].LegalEntityId)
  257.         //             return null
  258.         //         }
  259.         //     }
  260.         // }
  261.  
  262.         return null
  263.  
  264.     }
  265.   },
  266.   data () {
  267.     return {
  268.         key: '',
  269.         query: '',
  270.         //Loading
  271.         loading: true,
  272.         //definisikan per page dan halaman current isi 1 untuk awal
  273.         perPage: 10,
  274.         currentPage: 1,
  275.         //selesai
  276.         inventoryField: this.fieldLookup(),
  277.         exportData: [],
  278.         fieldsData: {
  279.             'Kode': 'Code',
  280.             'Nama Bendera': 'LegalEntityId',
  281.             'Nama Cabang': 'BranchId',
  282.             'Name Barang': 'Name',
  283.             'Lokasi': 'Location',
  284.             'Kategori': 'Category',
  285.             'Jumlah Barang': 'TotalQuantity',
  286.             'Jumlah Barang Rekondisi': 'RefurbishQuantity',
  287.             'Jumlah Barang Kondisi 100%': 'Quantity100',
  288.             'Jumlah Barang Kondisi 90%': 'Quantity90',
  289.             'Jumlah Barang Kondisi 60%': 'Quantity60',
  290.             'Jumlah Barang Kondisi 30%': 'Quantity30',
  291.             'Safety Stock Limit': 'SafetyStockStatus',
  292.             'Harga Jual 100%': 'Price90',
  293.             'Harga Jual 90%': 'Price90',
  294.             'Harga Jual 60%': 'Price60',
  295.             'Harga Jual 30%': 'Price30',
  296.             'Harga Jual Owner 100%': 'ExtraPrice90',
  297.             'Harga Jual Owner 90%': 'ExtraPrice90',
  298.             'Harga Jual Owner 60%': 'ExtraPrice60',
  299.             'Harga Jual Owner 30%': 'ExtraPrice30',
  300.             'Harga Beli 100%': 'BuyingPrice90',
  301.             'Harga Beli 90%': 'BuyingPrice90',
  302.             'Harga Beli 60%': 'BuyingPrice60',
  303.             'Harga Beli 30%': 'BuyingPrice30',
  304.             'Point': 'Point',
  305.         },
  306.         userData: {},
  307.         inventory: [],
  308.         roles: [],
  309.         selectedLegalEntity: {"Name" : "Pilih bendera..."},
  310.         selectedBranch: {"Name" : "Pilih cabang..."},
  311.         legalEntity: [],
  312.         branch: [],
  313.         dismissSecs: 5,
  314.         dismissCountDown: 0,
  315.         deleted: [],
  316.         selectorLegalEntity: 0,
  317.         selectorBranch: 0,
  318.         buyingPriceAccess: 0,
  319.     }
  320.   },
  321.   beforeUpdate: function() {
  322.     if(this.selectedLegalEntity.Name != 'Pilih bendera...') {
  323.         //this.query = this.selectedLegalEntity.Name
  324.         this.selectorLegalEntity = this.selectedLegalEntity.Id
  325.     } else {
  326.         this.selectorLegalEntity = this.userData.LegalEntityId
  327.     }
  328.  
  329.     if(this.selectedBranch.Name != 'Pilih cabang...') {
  330.         //this.query = this.selectedBranch.Name
  331.         this.selectorBranch = this.selectedBranch.Id
  332.     } else {
  333.         this.selectorBranch = this.userData.BranchId
  334.  
  335.     }
  336.     this.buyingPriceAccess = this.userData.RoleDetails.IsReadBuyingPriceInventory
  337.   },
  338.   created: function () {
  339.       this.init()
  340.   },
  341.   mounted: function () {
  342.     window.$ = $
  343.     if(localStorage.userData !== undefined) {
  344.       this.userData = JSON.parse(localStorage.userData)
  345.     } else {
  346.       this.$router.push({ name: 'home' })
  347.       location.reload()
  348.     }
  349.   },
  350.   methods: {
  351.     init: async function () {
  352.         let result = await Inventories.index()
  353.         let legalEntity = await LegalEntities.index()
  354.         let branch = await Branches.index()
  355.        
  356.         this.inventory = result.data
  357.         this.legalEntity = legalEntity.data
  358.         this.branch = branch.data
  359.         //fungsi export
  360.         this.exportData = this.filterExport(result.data)
  361.         this.loading = false
  362.     },
  363.     fieldLookup() {
  364.         let field = [
  365.             { key: 'Actions', label: 'Actions' },
  366.             { key: 'Code', label: 'Nomor Barang', sortable: true },
  367.             { key: 'LegalEntityId', label: 'Nama Bendera', sortable: true },
  368.             { key: 'BranchId', label: 'Nama Cabang', sortable: true },
  369.             { key: 'Name', label: 'Nama Barang', sortable: true },
  370.             { key: 'Category', label: 'Kategori Barang', sortable: true },
  371.             { key: 'WarehouseCategory', label: 'Kategori Gudang', sortable: true },
  372.             { key: 'Location', label: 'Lokasi', sortable: true },
  373.             { key: 'Point', label: 'Points', sortable: true },
  374.             { key: 'SafetyStockStatus', label: 'Status Stock', sortable: true },
  375.             { key: 'TotalQuantityC', label: 'Jumlah Barang', sortable: true },
  376.             { key: 'Quantity100', label: 'Kondisi 100%', sortable: true },
  377.             { key: 'Quantity90', label: 'Kondisi 90%', sortable: true },
  378.             { key: 'Quantity60', label: 'Kondisi 60%', sortable: true },
  379.             { key: 'Quantity30', label: 'Kondisi dibawah 30%', sortable: true },
  380.             { key: 'RefurbishQuantity', label: 'Jumlah Barang Rekondisi', sortable: true },
  381.             { key: 'Price100', label: 'Harga Jual Kondisi 100%', sortable: true },
  382.             { key: 'Price90', label: 'Harga Jual Kondisi 90%', sortable: true },
  383.             { key: 'Price60', label: 'Harga Jual Kondisi 60%', sortable: true },
  384.             { key: 'Price30', label: 'Harga Jual Kondisi 30%', sortable: true },
  385.         ]
  386.         if(this.buyingPriceAccess == 1) {
  387.             field.push(
  388.                 { key: 'BuyingPrice100', label: 'Harga Beli Kondisi 100%', sortable: true },
  389.                 { key: 'BuyingPrice90', label: 'Harga Beli Kondisi 90%', sortable: true },
  390.                 { key: 'BuyingPrice60', label: 'Harga Beli Kondisi 60%', sortable: true },
  391.                 { key: 'BuyingPrice30', label: 'Harga Beli Kondisi 30%', sortable: true }
  392.             )
  393.         }
  394.         return field
  395.     },
  396.     calculateTotal: function(json) {
  397.         let total = parseInt(
  398.             parseInt(json.Quantity100) +
  399.             parseInt(json.Quantity90) +
  400.             parseInt(json.Quantity60) +
  401.             parseInt(json.Quantity30)
  402.         )
  403.         return total
  404.     },
  405.     search: function(key) {
  406.         this.query = key
  407.     },
  408.     deleteSearch: function() {
  409.         this.query = ''
  410.         this.key = ''
  411.     },
  412.     // cekSafetyStock: function(safetyStock, legalEntityId, branchId) {
  413.        
  414.     // },
  415.     filterBarangCabang: function(json, legalEntityId, branchId) {
  416.         let data = []
  417.         for(var i = 0; i < json.length; i++) {
  418.             if((json[i].LegalEntityId == legalEntityId) && (json[i].BranchId == branchId)) {
  419.                 data.push(json[i])
  420.             }
  421.         }
  422.         return data
  423.     },
  424.     filterPosisiBenderaCabangSaatIni: function(json, legalEntityId, branchId) {
  425.         for(var i = 0; i < json.length; i++) {
  426.             if((json[i].LegalEntityId == legalEntityId) && (json[i].BranchId == branchId)) {
  427.                 return true
  428.             } else {
  429.                 return false
  430.             }
  431.         }
  432.     },
  433.     //Filter data yang mau di export
  434.     filterExport: function (json) {
  435.         let data = []
  436.         for(var i = 0; i< json.length; i++) {
  437.             //Tentukan Kolom Yang Mau Dimasukin Disini
  438.             data.push({
  439.                 'Code': json[i].Code,
  440.                 'LegalEntityId': json[i].legal_entity ? json[i].legal_entity.Name : '-',
  441.                 'BranchId': json[i].branch ? json[i].branch.Name : '-',
  442.                 'Name': json[i].Name,
  443.                 'Location': json[i].Location,
  444.                 'Category': json[i].Category,
  445.                 'TotalQuantity': this.calculateTotal(this.filterBarangCabang(json[i].inventory_branches, this.selectorLegalEntity, this.selectorBranch)[0]),
  446.                 'RefurbishQuantity': this.filterBarangCabang(json[i].inventory_branches, this.selectorLegalEntity, this.selectorBranch)[0].RefurbishQuantity,
  447.                 'Quantity100': this.filterBarangCabang(json[i].inventory_branches, this.selectorLegalEntity, this.selectorBranch)[0].Quantity100,
  448.                 'Quantity90': this.filterBarangCabang(json[i].inventory_branches, this.selectorLegalEntity, this.selectorBranch)[0].Quantity90,
  449.                 'Quantity60': this.filterBarangCabang(json[i].inventory_branches, this.selectorLegalEntity, this.selectorBranch)[0].Quantity60,
  450.                 'Quantity30': this.filterBarangCabang(json[i].inventory_branches, this.selectorLegalEntity, this.selectorBranch)[0].Quantity30,
  451.                 'SafetyStockStatus': this.filterBarangCabang(json[i].inventory_branches, this.selectorLegalEntity, this.selectorBranch)[0].SafetyStockLimit,
  452.                 'Price100': json[i].Price100,
  453.                 'Price90': json[i].Price90,
  454.                 'Price60': json[i].Price60,
  455.                 'Price30': json[i].Price30,
  456.                 'BuyingPrice100': json[i].BuyingPrice100,
  457.                 'BuyingPrice90': json[i].BuyingPrice90,
  458.                 'BuyingPrice60': json[i].BuyingPrice60,
  459.                 'BuyingPrice30': json[i].BuyingPrice30,
  460.                 'ExtraPrice100': json[i].ExtraPrice100,
  461.                 'ExtraPrice90': json[i].ExtraPrice90,
  462.                 'ExtraPrice60': json[i].ExtraPrice60,
  463.                 'ExtraPrice30': json[i].ExtraPrice30,
  464.                 'Point': json[i].Point,
  465.             })
  466.         }
  467.         return data
  468.     },
  469.     itemLookup: function (json) {
  470.         let data = []
  471.         for(var i = 0; i< json.length; i++) {
  472.             data[json[i].Id] = json[i]
  473.         }
  474.         return data
  475.     },
  476.     formatDate(time) {
  477.       var formattedTime = moment(time).format('DD MMMM YYYY HH:mm')
  478.       if(formattedTime == 'Invalid date') {
  479.         formattedTime = '-'
  480.       }
  481.       return formattedTime
  482.     },
  483.     detail: function (id) {
  484.         this.$router.push({ name: 'InventoryManagement.detail', params: { id: id } })
  485.     },
  486.     edit: function (id) {
  487.         this.$router.push({ name: 'InventoryManagement.edit', params: { id: id } })
  488.     },
  489.     del: async function (json, id) {
  490.         let ini = this
  491.         ini.$fire({
  492.             text: "Apakah anda yakin ingin menghapus " + json.Name + "?",
  493.             type: "warning",
  494.             showCancelButton: true,
  495.             confirmButtonText: 'Ya',
  496.             cancelButtonText: 'Tidak',
  497.             showCloseButton: true,
  498.             showLoaderOnConfirm: true,
  499.         }).then(function(isConfirm) {
  500.             if (isConfirm.value) {
  501.                 ini.$fire({
  502.                     text: "Peringatan terakhir! Apakah anda yakin ingin menghapus " + json.Name + "?",
  503.                     type: "warning",
  504.                     showCancelButton: true,
  505.                     confirmButtonText: 'Ya',
  506.                     cancelButtonText: 'Tidak',
  507.                     showCloseButton: true,
  508.                     showLoaderOnConfirm: true,
  509.                 }).then(async function(isConfirm) {
  510.                     if (isConfirm.value) {
  511.                         json.LoggedUserLegalEntityId = ini.userData.LegalEntityId
  512.                         json.LoggedUserBranchId = ini.userData.BranchId
  513.                         let result = await Inventories.delete(id, json)
  514.                         if(result.status == 200) {
  515.                             ini.$fire({
  516.                                 title: 'Sukses',
  517.                                 text: 'Hapus Data Sukses',
  518.                                 //   icon: 'info',
  519.                                 //   type: 'success',
  520.                                 showConfirmButton: false
  521.                             })
  522.                             ini.$router.push({ name: 'InventoryManagement.index' })
  523.                             location.reload()
  524.                         } else {
  525.                             alert("Delete Gagal")
  526.                             location.reload()
  527.                         }
  528.                         console.log('Keluar')
  529.                     }
  530.                 })
  531.             } else {
  532.                 console.log('cancel')
  533.             }
  534.         })
  535.     },
  536.     countDownChanged(dismissCountDown) {
  537.         this.dismissCountDown = dismissCountDown
  538.     },
  539.   }
  540. }
  541. </script>
  542.  
  543. <style>
  544. .table-div {
  545.     height: 500px;
  546.     padding-left: 30px;
  547.     margin-left: 0px !important;
  548.     overflow-x: auto;
  549.     overflow-y: auto;
  550. }
  551.  
  552. .second-row {
  553.     margin-top: 30px;
  554.     padding-left: 30px;
  555. }
  556.  
  557. .select-dropdown {
  558.     width: 100%;
  559.     height: 45px;
  560.     border-color: #0059aa;
  561.     border-radius: 5px;
  562. }
  563.  
  564. .button-export {
  565.     width: 100%;
  566.     height: 45px;
  567.     background-color: #0059aa;
  568.     color:white;
  569.     border-radius: 5px;
  570. }
  571.  
  572. .button-create {
  573.     width: 100%;
  574.     height: 45px;
  575.     background-color: #20c197;
  576.     color:white;
  577.     border-radius: 5px;
  578. }
  579.  
  580. .btn-warning {
  581.     width: 132px;
  582. }
  583.  
  584. .btn-danger {
  585.     margin-left: 0px !important;
  586. }
  587.  
  588. .btn-default {
  589.     width: 132px;
  590.     height: 36px;
  591.     margin-left: 15px;
  592.     margin-right: 15px;
  593.     color: white;
  594.     background-color: red;
  595. }
  596.  
  597. .btn-default:hover {
  598.     color: white;
  599.     background-color: rgb(185, 0, 0);
  600. }
  601.  
  602. .pagination {
  603.     padding: 15px;
  604. }
  605. </style>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement