217 lines
7.7 KiB
JavaScript
217 lines
7.7 KiB
JavaScript
// 1 => LOADING
|
|
// 2 => DONE
|
|
// 3 => ERROR
|
|
import * as api from "../api/patient.js"
|
|
|
|
export default {
|
|
namespaced: true,
|
|
state: {
|
|
search_patient: 0,
|
|
search_error_message: '',
|
|
start_date:moment(new Date()).format('YYYY-MM-DD'),
|
|
end_date:moment(new Date()).format('YYYY-MM-DD'),
|
|
search:'',
|
|
old_search:'',
|
|
patients: [],
|
|
old_patients: [],
|
|
total_patient: 0,
|
|
selected_patient: {totalbill:0,mindp_percent:0},
|
|
old_selected_patient: {totalbill:0,mindp_percent:0},
|
|
save_error_message: '',
|
|
statuses:[{name:'Belum Lunas',value:'N'},{name:'Lunas',value:'Y'}],
|
|
selected_status:{name:'Belum Lunas',value:'N'},
|
|
open_alert_no_pay: false,
|
|
msg_alert_no_pay: "Loh ... Gak jadi bayar dong ?",
|
|
current_page:1,
|
|
total_page:0,
|
|
old_current_page:1,
|
|
old_total_page:0,
|
|
pay_disabled:'Y',
|
|
autocomplete_status:0,
|
|
companies:[{id:0,name:'Semua'}],
|
|
selected_company:{id:0,name:'Semua'},
|
|
dialog_success:false,
|
|
dialog_alert:false,
|
|
msg_alert:'',
|
|
loading:false
|
|
},
|
|
mutations: {
|
|
update_loading(state,val){
|
|
state.loading = val
|
|
},
|
|
update_dialog_success(state,val){
|
|
state.dialog_success = val
|
|
},
|
|
update_dialog_alert(state,val){
|
|
state.dialog_alert = val
|
|
},
|
|
update_msg_alert(state,val){
|
|
state.msg_alert = val
|
|
},
|
|
update_autocomplete_status(state,val){
|
|
state.autocomplete_status = val
|
|
},
|
|
update_companies(state, val) {
|
|
state.companies = val
|
|
},
|
|
update_selected_company(state, val) {
|
|
state.selected_company = val
|
|
},
|
|
update_pay_disabled(state, val) {
|
|
state.pay_disabled = val
|
|
},
|
|
update_total_page(state, val) {
|
|
state.total_page = val
|
|
},
|
|
update_old_total_page(state, val) {
|
|
state.old_total_page = val
|
|
},
|
|
update_current_page(state, val) {
|
|
state.current_page = val
|
|
},
|
|
update_old_current_page(state, val) {
|
|
state.old_current_page = val
|
|
},
|
|
update_search_error_message(state, patient) {
|
|
state.search_error_message = patient
|
|
},
|
|
update_search_patient(state, patient) {
|
|
state.search_patient = patient
|
|
},
|
|
|
|
update_patients(state, data) {
|
|
state.patients = data.records
|
|
state.total_patient = data.total
|
|
state.total_page = data.total
|
|
},
|
|
update_old_patients(state, data) {
|
|
state.old_patients = data.records
|
|
state.old_total_patient = data.total
|
|
state.old_total_page = data.total
|
|
},
|
|
update_old_selected_patient(state, val) {
|
|
state.old_selected_patient = val
|
|
},
|
|
update_selected_patient(state, val) {
|
|
state.selected_patient = 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_old_search(state, val) {
|
|
state.old_search = val
|
|
},
|
|
update_selected_status(state, val) {
|
|
state.selected_status = 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_patient", 1)
|
|
try {
|
|
prm.token = one_token()
|
|
prm.company = context.state.selected_company.id
|
|
let resp = await api.search(prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_search_patient", 3)
|
|
context.commit("update_search_error_message", resp.message)
|
|
} else {
|
|
context.commit("update_search_patient", 2)
|
|
context.commit("update_search_error_message", "")
|
|
let data = {
|
|
records: resp.data.records,
|
|
total: resp.data.total
|
|
}
|
|
context.commit("update_patients", data)
|
|
context.commit("update_total_page", data.total)
|
|
if(prm.lastidx === 0){
|
|
context.commit("update_selected_patient", data.records[0])
|
|
|
|
}
|
|
else{
|
|
context.commit("update_selected_patient", data.records[prm.lastidx])
|
|
context.commit("paymentnew/update_notes",data.records[prm.lastidx].notes,{root:true})
|
|
}
|
|
|
|
}
|
|
} catch (e) {
|
|
context.commit("update_search_patient", 3)
|
|
context.commit("update_search_error_message", e.message)
|
|
console.log(e)
|
|
}
|
|
},
|
|
async search_old_patient(context, prm) {
|
|
context.commit("update_search_patient", 1)
|
|
try {
|
|
prm.token = one_token()
|
|
prm.company = context.state.selected_company.id
|
|
let resp = await api.search_old_patient(prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_search_patient", 3)
|
|
context.commit("update_search_error_message", resp.message)
|
|
} else {
|
|
context.commit("update_search_patient", 2)
|
|
context.commit("update_search_error_message", "")
|
|
let data = {
|
|
records: resp.data.records,
|
|
total: resp.data.total
|
|
}
|
|
context.commit("update_old_patients", data)
|
|
context.commit("update_old_total_page", data.total)
|
|
if(prm.lastidx === 0){
|
|
context.commit("update_old_selected_patient", data.records[0])
|
|
|
|
}
|
|
else{
|
|
context.commit("update_old_selected_patient", data.records[prm.lastidx])
|
|
|
|
}
|
|
|
|
}
|
|
} catch (e) {
|
|
context.commit("update_search_patient", 3)
|
|
context.commit("update_search_error_message", e.message)
|
|
console.log(e)
|
|
}
|
|
},
|
|
async gabungkan(context,prm) {
|
|
//context.commit("update_loading",1)
|
|
try {
|
|
prm.token = one_token()
|
|
|
|
let resp= await api.gabungkan(prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_msg_alert","Gagal menggabungkan")
|
|
context.commit("update_dialog_alert",false)
|
|
context.commit("update_loading",false)
|
|
} else {
|
|
context.commit("update_loading",false)
|
|
context.dispatch("search", {
|
|
startdate: context.state.start_date,
|
|
enddate: context.state.start_date,
|
|
search: context.state.search,
|
|
current_page: context.state.current_page,
|
|
lastidx: 0,
|
|
});
|
|
|
|
context.commit("update_dialog_success",true)
|
|
}
|
|
} catch(e) {
|
|
context.commit("update_msg_alert","Gagal menggabungkan")
|
|
context.commit("update_loading",false)
|
|
}
|
|
},
|
|
}
|
|
} |