351 lines
13 KiB
JavaScript
351 lines
13 KiB
JavaScript
// 1 => LOADING
|
|
// 2 => DONE
|
|
// 3 => ERROR
|
|
import * as api from "../api/close.js"
|
|
|
|
export default {
|
|
namespaced: true,
|
|
state: {
|
|
search_close: 0,
|
|
search_error_message: '',
|
|
start_date:moment().startOf('month').format('YYYY-MM-DD'),
|
|
end_date:moment().endOf('month').format('YYYY-MM-DD'),
|
|
datestart:moment(new Date()).format('YYYY-MM-DD'),
|
|
dateend:moment(new Date()).format('YYYY-MM-DD'),
|
|
search:'',
|
|
searchnolab:'',
|
|
closes: [],
|
|
voucher_header_options: [],
|
|
voucher_header_loading: false,
|
|
voucher_header_search: '',
|
|
selected_voucher_header: null,
|
|
detail_filter_voucher_id: 0,
|
|
selected_voucher_label: '',
|
|
detail_statuses: [
|
|
{ name: 'Semua', value: '' },
|
|
{ name: 'Belum dipakai', value: 'N' },
|
|
{ name: 'Sudah dipakai', value: 'Y' }
|
|
],
|
|
selected_detail_status: { name: 'Semua', value: '' },
|
|
detail_status_value: '', // '' | 'N' | 'Y' untuk API
|
|
xvouchersdetails:[],
|
|
total_close: 0,
|
|
selected_close: {},
|
|
open_print_note:false,
|
|
save_error_message: '',
|
|
statuses:[{name:'Belum Diterima',value:'N'},{name:'Diterima',value:'Y'}],
|
|
selected_status:{name:'Belum Diterima',value:'N'},
|
|
open_alert_no_pay: false,
|
|
msg_alert_no_pay: "Loh ... Gak jadi bayar dong ?",
|
|
current_page:1,
|
|
current_page_detail:1,
|
|
total_page:0,
|
|
total_page_detail:0,
|
|
update_save_status:0,
|
|
selected_paymentkasir_id:0,
|
|
act: 'edit',
|
|
dialog_add:false,
|
|
dialog_edit:false,
|
|
dialog_success: false,
|
|
dialog_error: false,
|
|
dialog_confirmation_delete: false,
|
|
msg_success: '',
|
|
msg_error: '',
|
|
msg_confirmation_delete: '',
|
|
inp_VoucherHeaderName: '',
|
|
inp_VoucherHeaderPrefix: '',
|
|
inp_VoucherHeaderAmount: '',
|
|
inp_VoucherHeaderQty: '',
|
|
inp_VoucherHeaderNote: '',
|
|
xid: 0
|
|
|
|
},
|
|
mutations: {
|
|
update_searchnolab(state, val) {
|
|
state.searchnolab = val
|
|
},
|
|
update_voucher_header_options(state, val) {
|
|
state.voucher_header_options = val || []
|
|
},
|
|
update_detail_filter_voucher_id(state, val) {
|
|
state.detail_filter_voucher_id = val || 0
|
|
},
|
|
update_selected_voucher_label(state, val) {
|
|
state.selected_voucher_label = val || ''
|
|
},
|
|
update_voucher_header_loading(state, val) {
|
|
state.voucher_header_loading = val
|
|
},
|
|
update_voucher_header_search(state, val) {
|
|
state.voucher_header_search = val == null ? '' : String(val)
|
|
},
|
|
update_selected_voucher_header(state, val) {
|
|
state.selected_voucher_header = val || null
|
|
if (val && val.VoucherHeaderID) {
|
|
state.detail_filter_voucher_id = Number(val.VoucherHeaderID)
|
|
state.selected_voucher_label = val.displayLabel || ''
|
|
} else {
|
|
state.detail_filter_voucher_id = 0
|
|
state.selected_voucher_label = ''
|
|
}
|
|
},
|
|
update_selected_detail_status(state, val) {
|
|
state.selected_detail_status = val || { name: 'Semua', value: '' }
|
|
},
|
|
update_detail_status_value(state, val) {
|
|
state.detail_status_value = (val === 'Y' || val === 'N') ? val : ''
|
|
},
|
|
update_xid(state, val) {
|
|
state.xid = val
|
|
},
|
|
update_inp_VoucherHeaderName(state, val) {
|
|
state.inp_VoucherHeaderName = val
|
|
},
|
|
update_inp_VoucherHeaderPrefix(state, val) {
|
|
state.inp_VoucherHeaderPrefix = val
|
|
},
|
|
update_inp_VoucherHeaderAmount(state, val) {
|
|
state.inp_VoucherHeaderAmount = val
|
|
},
|
|
update_inp_VoucherHeaderQty(state, val) {
|
|
state.inp_VoucherHeaderQty = val
|
|
},
|
|
update_inp_VoucherHeaderNote(state, val) {
|
|
state.inp_VoucherHeaderNote = val
|
|
},
|
|
update_datestart(state, val) {
|
|
state.datestart = val
|
|
},
|
|
update_dateend(state, val) {
|
|
state.dateend = val
|
|
},
|
|
update_dialog_error(state, val) {
|
|
state.dialog_error = val
|
|
},
|
|
update_dialog_confirmation_delete(state, val) {
|
|
state.dialog_confirmation_delete = val
|
|
},
|
|
update_dialog_success(state, val) {
|
|
state.dialog_success = val
|
|
},
|
|
update_act(state, val) {
|
|
state.act = val
|
|
},
|
|
update_dialog_add(state, val) {
|
|
state.dialog_add = val
|
|
},
|
|
update_dialog_edit(state, val) {
|
|
state.dialog_edit = val
|
|
},
|
|
update_total_page(state, val) {
|
|
state.total_page = val
|
|
},
|
|
update_total_page_detail(state, val) {
|
|
state.total_page_detail = val
|
|
},
|
|
update_current_page(state, val) {
|
|
state.current_page = val
|
|
},
|
|
update_current_page_detail(state, val) {
|
|
state.current_page_detail = val
|
|
},
|
|
update_search_error_message(state, close) {
|
|
state.search_error_message = close
|
|
},
|
|
update_search_close(state, close) {
|
|
state.search_close = close
|
|
},
|
|
update_closes(state, data) {
|
|
state.closes = data.records
|
|
state.total_close = data.total
|
|
state.total_page = data.total
|
|
},
|
|
update_xvouchersdetails(state, val) {
|
|
state.xvouchersdetails = val
|
|
},
|
|
update_selected_close(state, val) {
|
|
state.selected_close = val
|
|
},
|
|
update_start_date(state, val) {
|
|
state.start_date = val
|
|
},
|
|
update_end_date(state, val) {
|
|
state.end_date = val
|
|
},
|
|
update_search(state, val) {
|
|
state.search = val
|
|
},
|
|
update_save_error_message(state, val) {
|
|
state.save_error_message = val
|
|
},
|
|
update_alert_success(state, val) {
|
|
state.alert_success = val
|
|
},
|
|
update_msg_success(state, val) {
|
|
state.msg_success = val
|
|
},
|
|
update_msg_error(state, val) {
|
|
state.msg_error = val || ''
|
|
},
|
|
update_msg_confirmation_delete(state, val) {
|
|
state.msg_confirmation_delete = val || ''
|
|
},
|
|
|
|
update_save_status(state, val) {
|
|
state.save_status = val
|
|
},
|
|
update_selected_status(state, val) {
|
|
state.selected_status = val
|
|
},
|
|
update_selected_paymentkasir_id(state, val) {
|
|
state.selected_paymentkasir_id = val
|
|
},
|
|
update_open_print_note(state,val) {
|
|
state.open_print_note=val
|
|
},
|
|
update_no_save(state,val) {
|
|
state.no_save=val
|
|
},
|
|
update_open_alert_no_pay(state, val) {
|
|
state.open_alert_no_pay = val
|
|
},
|
|
update_msg_alert_no_pay(state, val) {
|
|
state.msg_alert_no_pay = val
|
|
}
|
|
},
|
|
actions: {
|
|
async search(context, prm) {
|
|
context.commit("update_search_close", 1)
|
|
try {
|
|
prm.token = one_token()
|
|
let resp = await api.search(prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_search_close", 3)
|
|
context.commit("update_search_error_message", resp.message)
|
|
} else {
|
|
context.commit("update_search_close", 2)
|
|
context.commit("update_search_error_message", "")
|
|
let data = {
|
|
records: resp.data.records,
|
|
total: resp.data.total
|
|
}
|
|
context.commit("update_closes", data)
|
|
context.commit("update_total_page", data.total)
|
|
if(prm.lastidx === 0){
|
|
context.commit("update_selected_close", data.records[0])
|
|
if(!_.isEmpty(data.records[0]))
|
|
context.commit("payment/update_notes",data.records[0].notes,{root:true})
|
|
else
|
|
context.commit("payment/update_notes",[],{root:true})
|
|
}
|
|
else{
|
|
context.commit("update_selected_close", data.records[prm.lastidx])
|
|
context.commit("payment/update_notes",data.records[prm.lastidx].notes,{root:true})
|
|
}
|
|
|
|
}
|
|
} catch (e) {
|
|
context.commit("update_search_close", 3)
|
|
context.commit("update_search_error_message", e.message)
|
|
console.log(e)
|
|
}
|
|
},
|
|
async searchVoucherHeaders(context, prm) {
|
|
context.commit("update_voucher_header_loading", true)
|
|
try {
|
|
prm.token = one_token()
|
|
let resp = await api.search(prm)
|
|
if (resp.status === "OK" && resp.data && resp.data.records) {
|
|
const records = (resp.data.records || []).map(r => ({
|
|
...r,
|
|
displayLabel: (r.VoucherHeaderName || '') + ' (' + (r.VoucherHeaderPrefix || '') + ')'
|
|
}))
|
|
context.commit("update_voucher_header_options", records)
|
|
} else {
|
|
context.commit("update_voucher_header_options", [])
|
|
}
|
|
} catch (e) {
|
|
context.commit("update_voucher_header_options", [])
|
|
}
|
|
context.commit("update_voucher_header_loading", false)
|
|
},
|
|
async searchdetail(context, prm) {
|
|
context.commit("update_search_close", 1)
|
|
try {
|
|
prm.token = one_token()
|
|
let resp = await api.searchdetail(prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_search_close", 3)
|
|
context.commit("update_search_error_message", resp.message)
|
|
} else {
|
|
context.commit("update_search_close", 2)
|
|
context.commit("update_search_error_message", "")
|
|
let data = {
|
|
records: resp.data.records,
|
|
total: resp.data.total
|
|
}
|
|
context.commit("update_xvouchersdetails", data.records)
|
|
context.commit("update_total_page_detail", data.total)
|
|
|
|
}
|
|
} catch (e) {
|
|
context.commit("update_search_close", 3)
|
|
context.commit("update_search_error_message", e.message)
|
|
console.log(e)
|
|
}
|
|
},
|
|
async savetutup(context, prm) {
|
|
context.commit("update_save_status", 1)
|
|
try {
|
|
prm.token = one_token()
|
|
let resp = await api.savetutup(prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_save_status", 3)
|
|
context.commit("update_save_error_message", resp.message)
|
|
} else {
|
|
context.commit("update_save_status", 2)
|
|
context.commit("update_save_error_message", resp.message)
|
|
context.commit("update_alert_success", true)
|
|
var msg = "Perubahan data sudah disimpan dong"
|
|
context.commit("update_msg_success", msg)
|
|
context.commit("update_alert_success", true)
|
|
|
|
}
|
|
} catch (e) {
|
|
context.commit("update_save_status", 3)
|
|
console.log(e)
|
|
}
|
|
},
|
|
async saveData(context, prm) {
|
|
context.commit("update_save_status", 1)
|
|
try {
|
|
prm.token = one_token()
|
|
let resp = await api.saveData(prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_save_status", 3)
|
|
context.commit("update_save_error_message", resp.message)
|
|
} else {
|
|
context.commit("update_save_status", 2)
|
|
context.commit("update_save_error_message", resp.message)
|
|
context.commit("update_alert_success", true)
|
|
var msg = "Pembuatan voucher " + prm.VoucherHeaderName + " sudah berhasil"
|
|
context.commit("update_msg_success", msg)
|
|
context.commit("update_alert_success", true)
|
|
context.commit("update_dialog_add", false)
|
|
var xprm = {}
|
|
xprm.startdate = context.state.start_date
|
|
xprm.enddate = context.state.end_date
|
|
xprm.search = context.state.search
|
|
xprm.current_page = context.state.current_page
|
|
xprm.lastidx = 0
|
|
context.dispatch("search",xprm)
|
|
|
|
}
|
|
} catch (e) {
|
|
context.commit("update_save_status", 3)
|
|
console.log(e)
|
|
}
|
|
}
|
|
}
|
|
}
|