393 lines
16 KiB
JavaScript
393 lines
16 KiB
JavaScript
// 1 => LOADING
|
|
// 2 => DONE
|
|
// 3 => ERROR
|
|
// is add kalau true maka add baru kalau false maka sispkan ke header yang sudah ada
|
|
|
|
import * as api from "../api/handover.js"
|
|
|
|
export default {
|
|
namespaced: true,
|
|
state: {
|
|
isAdd: true,
|
|
loading: false,
|
|
errorMsg: '',
|
|
snackbarSuccess: false,
|
|
snackbarError: false,
|
|
successMsg: '',
|
|
setupList: [],
|
|
selectedSetup: {},
|
|
startDateHeader: moment(new Date()).format('YYYY-MM-DD'),
|
|
endDateHeader: moment(new Date()).format('YYYY-MM-DD'),
|
|
startDateDetail: moment(new Date()).format('YYYY-MM-DD'),
|
|
endDateDetail: moment(new Date()).format('YYYY-MM-DD'),
|
|
searchDetail: "",
|
|
statusDetail: [{ 'text': "Semua", "value": "A" }, { 'text': "Sudah Diserahkan", "value": "Y" }, { 'text': "Belum Diserahkan", "value": "N" }],
|
|
selectedStatusDetail: 'A',
|
|
handoverHeader: [],
|
|
handoverDetail: [],
|
|
selectedHandover: {},
|
|
headerPage: 1,
|
|
headerTotal: 1,
|
|
detailPage: 1,
|
|
detailTotal: 1,
|
|
selectedData: [],
|
|
dialogAdd: false,
|
|
receiver: '',
|
|
note: '',
|
|
totalData: 0,
|
|
totalHandover: 0,
|
|
totalNotHandover: 0,
|
|
},
|
|
mutations: {
|
|
update_totalNotHandover(state, val) {
|
|
state.totalNotHandover = val
|
|
},
|
|
update_totalHandover(state, val) {
|
|
state.totalHandover = val
|
|
},
|
|
update_totalData(state, val) {
|
|
state.totalData = val
|
|
},
|
|
update_receiver(state, val) {
|
|
state.receiver = val
|
|
},
|
|
update_note(state, val) {
|
|
state.note = val
|
|
},
|
|
update_dialogAdd(state, val) {
|
|
state.dialogAdd = val
|
|
},
|
|
update_selectedData(state, val) {
|
|
state.selectedData = val
|
|
},
|
|
update_errorMsg(state, val) {
|
|
state.errorMsg = val
|
|
},
|
|
update_isAdd(state, val) {
|
|
state.isAdd = val
|
|
},
|
|
update_snackbarSuccess(state, val) {
|
|
state.snackbarSuccess = val
|
|
},
|
|
update_snackbarError(state, val) {
|
|
state.snackbarError = val
|
|
},
|
|
update_successMsg(state, val) {
|
|
state.successMsg = val
|
|
},
|
|
update_loading(state, val) {
|
|
state.loading = val
|
|
},
|
|
update_startDateHeader(state, val) {
|
|
state.startDateHeader = val
|
|
},
|
|
update_endDateHeader(state, val) {
|
|
state.endDateHeader = val
|
|
},
|
|
update_startDateDetail(state, val) {
|
|
state.startDateDetail = val
|
|
},
|
|
update_endDateDetail(state, val) {
|
|
state.endDateDetail = val
|
|
},
|
|
update_selectedSetup(state, val) {
|
|
state.selectedSetup = val
|
|
},
|
|
update_setupList(state, val) {
|
|
state.setupList = val
|
|
},
|
|
update_handoverHeader(state, val) {
|
|
state.handoverHeader = val
|
|
},
|
|
update_handoverDetail(state, val) {
|
|
state.handoverDetail = val
|
|
},
|
|
update_selectedHandover(state, val) {
|
|
state.selectedHandover = val
|
|
},
|
|
update_headerTotal(state, val) {
|
|
state.headerTotal = val
|
|
},
|
|
update_headerPage(state, val) {
|
|
state.headerPage = val
|
|
},
|
|
update_detailTotal(state, val) {
|
|
state.detailTotal = val
|
|
},
|
|
update_detailPage(state, val) {
|
|
state.detailPage = val
|
|
},
|
|
update_searchDetail(state, val) {
|
|
state.searchDetail = val
|
|
},
|
|
update_selectedStatusDetail(state, val) {
|
|
state.selectedStatusDetail = val
|
|
},
|
|
},
|
|
actions: {
|
|
async getsetup(context) {
|
|
context.commit("update_loading", true)
|
|
try {
|
|
let prm = {
|
|
token: one_token(),
|
|
}
|
|
let resp = await api.getsetup(prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_loading", false)
|
|
context.commit("update_errorMsg", resp.message)
|
|
context.commit("update_snackbarError", true)
|
|
} else {
|
|
|
|
context.commit("update_errorMsg", '')
|
|
context.commit("update_loading", false)
|
|
|
|
let data = {
|
|
records: resp.data.records,
|
|
}
|
|
if (resp.data.records.length > 0) {
|
|
context.commit("update_selectedSetup", resp.data.records[0])
|
|
context.commit("update_startDateHeader", resp.data.records[0].Mgm_McuStartDate)
|
|
context.commit("update_endDateHeader", resp.data.records[0].Mgm_McuEndDate)
|
|
context.commit("update_startDateDetail", resp.data.records[0].Mgm_McuStartDate)
|
|
context.commit("update_endDateDetail", resp.data.records[0].Mgm_McuEndDate)
|
|
|
|
context.dispatch("search")
|
|
context.dispatch("getdetail", 0)
|
|
}
|
|
context.commit("update_setupList", resp.data.records)
|
|
}
|
|
} catch (e) {
|
|
console.log(e)
|
|
context.commit("update_loading", false)
|
|
context.commit("update_errorMsg", e)
|
|
context.commit("update_snackbarError", true)
|
|
}
|
|
},
|
|
async search(context) {
|
|
context.commit("update_loading", true)
|
|
try {
|
|
let prm = {
|
|
token: one_token(),
|
|
startDate: context.state.startDateHeader,
|
|
endDate: context.state.endDateHeader,
|
|
setupID: context.state.selectedSetup.Mgm_McuID,
|
|
page: context.state.headerPage,
|
|
}
|
|
let resp = await api.search(prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_loading", false)
|
|
context.commit("update_errorMsg", resp.message)
|
|
context.commit("update_snackbarError", true)
|
|
} else {
|
|
|
|
context.commit("update_errorMsg", '')
|
|
context.commit("update_loading", false)
|
|
|
|
let data = {
|
|
records: resp.data.records,
|
|
}
|
|
|
|
context.commit("update_handoverHeader", resp.data.records)
|
|
context.commit("update_headerTotal", resp.data.total)
|
|
}
|
|
} catch (e) {
|
|
console.log(e)
|
|
context.commit("update_loading", false)
|
|
context.commit("update_errorMsg", e)
|
|
context.commit("update_snackbarError", true)
|
|
}
|
|
},
|
|
async getdetail(context) {
|
|
context.commit("update_loading", true)
|
|
try {
|
|
|
|
let prm = {
|
|
token: one_token(),
|
|
startDate: context.state.startDateDetail,
|
|
endDate: context.state.endDateDetail,
|
|
status: context.state.selectedStatusDetail,
|
|
search: context.state.searchDetail,
|
|
setupID: context.state.selectedSetup.Mgm_McuID,
|
|
page: context.state.detailPage,
|
|
}
|
|
let resp = await api.getdetail(prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_loading", false)
|
|
context.commit("update_errorMsg", resp.message)
|
|
context.commit("update_snackbarError", true)
|
|
} else {
|
|
|
|
context.commit("update_errorMsg", '')
|
|
context.commit("update_loading", false)
|
|
|
|
let data = {
|
|
records: resp.data.records,
|
|
}
|
|
|
|
context.commit("update_emailList", resp.data.records)
|
|
context.commit("update_detailTotal", resp.data.total)
|
|
context.commit("update_totalData", resp.data.totalAll)
|
|
context.commit("update_totalHandover", resp.data.totalHandover)
|
|
context.commit("update_totalNotHandover", resp.data.totalNotHandover)
|
|
}
|
|
} catch (e) {
|
|
console.log(e)
|
|
context.commit("update_loading", false)
|
|
context.commit("update_errorMsg", e)
|
|
context.commit("update_snackbarError", true)
|
|
}
|
|
},
|
|
async savehandover(context) {
|
|
context.commit("update_loading", true)
|
|
try {
|
|
let handover = 0;
|
|
if (
|
|
!(Object.keys(context.state.selectedHandover).length === 0 &&
|
|
context.state.selectedHandover.constructor === Object)
|
|
) {
|
|
handover = context.state.selectedHandover.handoverID;
|
|
}
|
|
let prm = {
|
|
token: one_token(),
|
|
data: context.state.selectedData,
|
|
receiver: context.state.receiver,
|
|
note: context.state.note,
|
|
setupID: context.state.selectedSetup.Mgm_McuID,
|
|
handoverID: handover,
|
|
}
|
|
let resp = await api.savehandover(prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_loading", false)
|
|
context.commit("update_errorMsg", resp.message)
|
|
context.commit("update_snackbarError", true)
|
|
} else {
|
|
context.commit("update_selectedStatusDetail", 'Y')
|
|
context.dispatch("search")
|
|
context.dispatch("getdetail", 0)
|
|
context.commit("update_errorMsg", '')
|
|
context.commit("update_loading", false)
|
|
context.commit("update_successMsg", 'Berhasil menyerahkan hasil')
|
|
context.commit("update_snackbarSuccess", true)
|
|
context.commit("update_dialogAdd", false)
|
|
context.commit("update_isAdd", false)
|
|
context.commit("update_receiver", '')
|
|
context.commit("update_note", '')
|
|
context.commit("update_selectedData", [])
|
|
|
|
}
|
|
} catch (e) {
|
|
console.log(e)
|
|
context.commit("update_loading", false)
|
|
context.commit("update_errorMsg", e)
|
|
context.commit("update_snackbarError", true)
|
|
}
|
|
},
|
|
async deletehandoverdetail(context, id) {
|
|
context.commit("update_loading", true)
|
|
try {
|
|
|
|
let prm = {
|
|
token: one_token(),
|
|
detailID: id,
|
|
}
|
|
let resp = await api.deletehandoverdetail(prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_loading", false)
|
|
context.commit("update_errorMsg", resp.message)
|
|
context.commit("update_snackbarError", true)
|
|
} else {
|
|
context.commit("update_selectedStatusDetail", 'Y')
|
|
context.dispatch("search")
|
|
context.dispatch("getdetail", 0)
|
|
context.commit("update_errorMsg", '')
|
|
context.commit("update_loading", false)
|
|
context.commit("update_successMsg", 'Berhasil Hapus hasil')
|
|
context.commit("update_snackbarSuccess", true)
|
|
context.commit("update_dialogAdd", false)
|
|
context.commit("update_isAdd", false)
|
|
context.commit("update_receiver", '')
|
|
context.commit("update_note", '')
|
|
context.commit("update_selectedData", [])
|
|
|
|
}
|
|
} catch (e) {
|
|
console.log(e)
|
|
context.commit("update_loading", false)
|
|
context.commit("update_errorMsg", e)
|
|
context.commit("update_snackbarError", true)
|
|
}
|
|
},
|
|
async lookup_type(context) {
|
|
context.commit("update_lookup_status", 1)
|
|
try {
|
|
let resp = await api.lookup_type(one_token())
|
|
if (resp.status != "OK") {
|
|
context.commit("update_lookup_status", 3)
|
|
context.commit("update_lookup_error_message", resp.message)
|
|
} else {
|
|
context.commit("update_lookup_status", 2)
|
|
context.commit("update_lookup_error_message", "")
|
|
let data = {
|
|
records: resp.data.records,
|
|
total: resp.data.total
|
|
}
|
|
context.commit("update_types", data)
|
|
}
|
|
} catch (e) {
|
|
context.commit("update_lookup_status", 3)
|
|
context.commit("update_lookup_error_message", e.message)
|
|
}
|
|
},
|
|
async pay(context, prm) {
|
|
context.commit("update_lookup_status", 1)
|
|
try {
|
|
prm.token = one_token()
|
|
let resp = await api.pay(prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_lookup_status", 3)
|
|
context.commit("update_lookup_error_message", resp.message)
|
|
} else {
|
|
context.commit("update_lookup_status", 2)
|
|
context.commit("update_lookup_error_message", "")
|
|
let data = {
|
|
records: resp.data.records.types,
|
|
total: resp.data.total
|
|
}
|
|
let xnumber = resp.data.records.data.numberx
|
|
let id = resp.data.records.data.idx
|
|
context.commit("update_types", data)
|
|
context.commit("update_last_payments", prm.payments)
|
|
context.commit("update_idx", id)
|
|
context.commit("update_total_payment", 0)
|
|
context.commit("update_paynumber", "Pembayaran nomor <span style='color:red'>" + xnumber + "</span> telah berhasil")
|
|
context.commit("update_dialog_pay_success", true)
|
|
}
|
|
} catch (e) {
|
|
context.commit("update_lookup_status", 3)
|
|
context.commit("update_lookup_error_message", e.message)
|
|
}
|
|
},
|
|
async delete_note(context, prm) {
|
|
context.commit("update_lookup_status", 1)
|
|
try {
|
|
prm.token = one_token()
|
|
let resp = await api.delete_note(prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_lookup_status", 3)
|
|
context.commit("update_lookup_error_message", resp.message)
|
|
} else {
|
|
context.commit("update_lookup_status", 2)
|
|
context.commit("update_lookup_error_message", "")
|
|
let xmsg = "Nota nomor <span style='color:red'>" + prm.nota.note_number + "</span> telah dihapus"
|
|
context.commit("update_msg_delete", xmsg)
|
|
context.commit("update_note_delete", '')
|
|
context.commit("update_nota_delete", {})
|
|
}
|
|
} catch (e) {
|
|
context.commit("update_lookup_status", 3)
|
|
context.commit("update_lookup_error_message", e.message)
|
|
}
|
|
}
|
|
}
|
|
}
|