276 lines
11 KiB
JavaScript
276 lines
11 KiB
JavaScript
// 1 => LOADING
|
|
// 2 => DONE
|
|
// 3 => ERROR
|
|
import * as api from "../api/kapus.js"
|
|
|
|
export default {
|
|
namespaced: true,
|
|
state: {
|
|
act: 'new',
|
|
loading: false,
|
|
error: '',
|
|
deliveryorders: [],
|
|
total: 0,
|
|
total_filter: 0,
|
|
totalkapus: 0,
|
|
totalkacab: 0,
|
|
totalkacab_only : 0,
|
|
avgkapus: 0,
|
|
avgkacab: 0,
|
|
show_all: false,
|
|
last_id: -1,
|
|
selected_deliveryorder: {
|
|
name: ""
|
|
},
|
|
loading_details: false,
|
|
error_details: '',
|
|
details:[],
|
|
total_details : 0,
|
|
total_details_filter : 0,
|
|
show_all_details: false,
|
|
last_id_details: -1,
|
|
x_search: '',
|
|
init_date: moment().format("YYYY-MM-DD"),
|
|
xcek: 0,
|
|
monthes:[],
|
|
selected_month:{},
|
|
get_data_status:0,
|
|
alert_success: false,
|
|
msg_success: "",
|
|
xyear:""
|
|
},
|
|
mutations: {
|
|
update_xyear(state, val) {
|
|
state.xyear = val
|
|
},
|
|
update_monthes(state, val) {
|
|
state.monthes = val
|
|
},
|
|
update_selected_month(state, val) {
|
|
state.selected_month = val
|
|
},
|
|
update_xcek(state, val) {
|
|
state.xcek = val
|
|
},
|
|
update_alert_success(state, val) {
|
|
state.alert_success = val
|
|
},
|
|
update_msg_success(state, val) {
|
|
state.msg_success = val
|
|
},
|
|
update_init_date(state, val) {
|
|
state.init_date = val
|
|
},
|
|
update_x_search(state, val) {
|
|
state.x_search = val
|
|
},
|
|
update_last_id(state, val) {
|
|
state.last_id = val
|
|
},
|
|
update_show_all(state, val) {
|
|
state.show_all = val
|
|
},
|
|
update_error(state, val) {
|
|
state.error = val
|
|
},
|
|
update_loading(state, val) {
|
|
state.loading = val
|
|
},
|
|
update_totalkapus(state, val) {
|
|
state.totalkapus = val
|
|
},
|
|
update_totalkacab(state, val) {
|
|
state.totalkacab = val
|
|
},
|
|
update_totalkacab_only(state, val) {
|
|
state.totalkacab_only = val
|
|
},
|
|
update_avgkapus(state, val) {
|
|
state.avgkapus = val
|
|
},
|
|
update_avgkacab(state, val) {
|
|
state.avgkacab = val
|
|
},
|
|
update_deliveryorders(state, data) {
|
|
state.deliveryorders = data.records
|
|
state.total= data.total
|
|
state.total_filter= data.total_filter
|
|
},
|
|
|
|
update_error_details(state, val) {
|
|
state.error_details = val
|
|
},
|
|
update_last_id_details(state, val) {
|
|
state.last_id_details = val
|
|
},
|
|
update_show_all_details(state, val) {
|
|
state.show_all_details = val
|
|
},
|
|
update_error_details(state, val) {
|
|
state.error_details = val
|
|
},
|
|
update_loading_detail(state, val) {
|
|
state.loading = val
|
|
},
|
|
update_selected_deliveryorder(state, val) {
|
|
state.selected_deliveryorder = val
|
|
},
|
|
update_get_data_status(state, val) {
|
|
state.get_data_status = val
|
|
}
|
|
},
|
|
actions: {
|
|
async lookup(context, prm) {
|
|
context.commit("update_loading", true)
|
|
try {
|
|
prm.token = one_token()
|
|
let resp = await api.lookup(prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_loading", false)
|
|
context.commit("update_error", resp.message)
|
|
} else {
|
|
context.commit("update_loading", false)
|
|
context.commit("update_error", "")
|
|
let data = {
|
|
records: resp.data.records,
|
|
total: resp.data.total,
|
|
total_filter: resp.data.total_filter,
|
|
totalkapus: resp.data.totalkapus,
|
|
totalkacab: resp.data.totalkacab,
|
|
totalkacab_only : resp.data.totalkacab_only,
|
|
avgkapus: resp.data.avgkapus,
|
|
avgkacab: resp.data.avgkacab
|
|
}
|
|
if (prm.lastid === -1) {
|
|
var pat = data.records[0]
|
|
context.commit("update_selected_deliveryorder", pat)
|
|
context.commit("update_deliveryorders", data)
|
|
context.dispatch("box/selected", {id: pat.id},{root: true})
|
|
context.dispatch("box/selected2", {id: pat.id},{root: true})
|
|
context.commit("update_totalkapus", data.totalkapus)
|
|
context.commit("update_totalkacab", data.totalkacab)
|
|
context.commit("update_totalkacab_only", data.totalkacab_only)
|
|
context.commit("update_avgkapus", data.avgkapus)
|
|
context.commit("update_avgkacab", data.avgkacab)
|
|
// context.dispatch("deliveryorderdetail/lookup", {id: pat.id, current_page : 1},{root: true})
|
|
} else {
|
|
var pat = data.records[prm.lastid]
|
|
context.commit("update_selected_deliveryorder", pat)
|
|
context.commit("update_deliveryorders", data)
|
|
context.dispatch("box/selected", {id: pat.id},{root: true})
|
|
context.dispatch("box/selected2", {id: pat.id},{root: true})
|
|
context.commit("update_totalkapus", data.totalkapus)
|
|
context.commit("update_totalkacab", data.totalkacab)
|
|
context.commit("update_avgkapus", data.avgkapus)
|
|
context.commit("update_avgkacab", data.avgkacab)
|
|
// context.dispatch("deliveryorderdetail/lookup", {id: pat.id, current_page : 1},{root: true})
|
|
}
|
|
}
|
|
} catch (e) {
|
|
context.commit("update_loading", false)
|
|
context.commit("update_error", e.message)
|
|
}
|
|
},
|
|
async lookupbybarcode(context, prm) {
|
|
context.commit("update_loading", true)
|
|
try {
|
|
prm.token = one_token()
|
|
let resp = await api.lookupbybarcode(prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_loading", false)
|
|
context.commit("update_error", resp.message)
|
|
} else {
|
|
context.commit("update_loading", false)
|
|
context.commit("update_error", "")
|
|
let data = {
|
|
records: resp.data.records,
|
|
total: resp.data.total,
|
|
total_filter: resp.data.total_filter
|
|
}
|
|
if (prm.lastid === -1) {
|
|
var pat = data.records[0]
|
|
context.commit("update_selected_deliveryorder", pat)
|
|
var cek = context.state.xcek
|
|
console.log('cek di modules')
|
|
console.log(cek)
|
|
if(cek === 0){
|
|
context.dispatch("box/selected", {
|
|
id: pat.id,
|
|
barcode: prm.search
|
|
}, {
|
|
root: true
|
|
})
|
|
context.dispatch("box/selected2", {
|
|
id: pat.id,
|
|
barcode: prm.search
|
|
}, {
|
|
root: true
|
|
})
|
|
}
|
|
// context.dispatch("deliveryorderdetail/lookup", {id: pat.id, current_page : 1},{root: true})
|
|
|
|
} else {
|
|
var pat = data.records[prm.lastid]
|
|
context.commit("update_selected_deliveryorder", pat)
|
|
context.dispatch("box/selected", {id: pat.id, barcode: prm.search},{root: true})
|
|
context.dispatch("box/selected2", {id: pat.id, barcode: prm.search},{root: true})
|
|
// context.dispatch("deliveryorderdetail/lookup", {id: pat.id, current_page : 1},{root: true})
|
|
}
|
|
}
|
|
} catch (e) {
|
|
context.commit("update_loading", false)
|
|
context.commit("update_error", e.message)
|
|
}
|
|
},
|
|
async detail(context, prm) {
|
|
context.commit("update_loading_details", true)
|
|
try {
|
|
prm.token = one_token()
|
|
let resp = await api.detail(prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_loading_details", false)
|
|
context.commit("update_lookup_error_details", resp.message)
|
|
} else {
|
|
context.commit("update_loading_details", false)
|
|
context.commit("update_lookup_error_details", "")
|
|
let data = {
|
|
records: resp.data.records,
|
|
total: resp.data.total,
|
|
total_filter: resp.data.total_filter
|
|
}
|
|
context.commit("update_details", data)
|
|
}
|
|
} catch (e) {
|
|
context.commit("update_lookup_details", false)
|
|
context.commit("update_lookup_error_details", e.message)
|
|
}
|
|
},
|
|
async getmonth(context,prm) {
|
|
context.commit("update_get_data_status",1)
|
|
try {
|
|
let resp= await api.getmonth(one_token())
|
|
if (resp.status != "OK") {
|
|
context.commit("update_get_data_status",3)
|
|
} else {
|
|
context.commit("update_get_data_status",2)
|
|
let data = {
|
|
records : resp.data.records,
|
|
total: resp.data.total,
|
|
idmonth: resp.data.idmonth,
|
|
namemonth: resp.data.namemonth,
|
|
syear: resp.data.syear,
|
|
xyear: resp.data.year
|
|
}
|
|
context.commit("update_monthes",data.records.months)
|
|
context.commit("update_selected_month",{id:data.idmonth,name:data.namemonth})
|
|
context.commit("update_xyear",data.xyear)
|
|
// prm.staff = data.records.staffs[0].M_StaffID
|
|
// context.dispatch("search",prm)
|
|
}
|
|
} catch(e) {
|
|
context.commit("update_get_data_status",3)
|
|
}
|
|
}
|
|
}
|
|
}
|