<template>
    <div style="width: 100%;">

        <!-- SNACKBAR -->
        <v-snackbar v-model="snackbar" :timeout="5000" :multi-line="false" :vertical="false" :top="true">
            {{ msgSnackbar }}
            <v-btn flat @click="updateAlertSuccess(false)"> Tutup </v-btn>
        </v-snackbar>

        <!-- ERROR DIALOG -->
        <v-dialog v-model="dialog_error" max-width="500px">
            <v-card>
                <v-card-title>
                    <span>ERROR !</span>
                    <v-spacer></v-spacer>
                </v-card-title>
                <v-divider></v-divider>
                <div class="ma-3 red--text">{{ msgError }}</div>
                <v-divider></v-divider>
                <v-card-actions>
                    <v-spacer></v-spacer>
                    <v-btn color="primary" flat @click="dialog_error = false">Tutup</v-btn>
                </v-card-actions>
            </v-card>
        </v-dialog>
        <!-- END ERROR DIALOG -->

        <!-- table list start -->
        <v-toolbar color="primary" dark>
            <v-toolbar-title class="white--text">NATIONAL SUB GROUP COA MAPPING</v-toolbar-title>
            <v-spacer></v-spacer>
            <v-btn icon @click="openDialogAdd()">
                <v-icon>add_box</v-icon>
            </v-btn>
        </v-toolbar>
        <v-card class="pa-2">
            <v-layout row>
                <v-flex xs2 pl-2>
                    <v-text-field v-model="xsearch" label="Cari" outline hide-details></v-text-field>
                </v-flex>
                <v-flex pl-2>
                    <v-btn class="ml-2" dark color="primary" style="min-width: 50px; height: 50px; margin: 0;"
                        @click="searchCoa()">
                        <v-icon>search</v-icon>
                    </v-btn>
                </v-flex>
            </v-layout>
        </v-card>
        <v-card class="pa-2 mt-2">
            <v-layout row wrap class="scroll-container" style="max-height: 600px; overflow: auto;">
                <v-flex xs12 pl-2 pr-2 pt-2 pb-2>
                    <v-data-table :headers="headers" :items="xcoas" :loading="isLoading" hide-actions
                        class="elevation-1">
                        <template slot="items" slot-scope="props">
                            <td class="text-xs-left pa-2" v-bind:class="{ 'amber lighten-4': isSelected(props.item) }"
                                @click="selectMe(props.item)">
                                <!-- <span class="font-weight-bold">
                                    {{ props.item.Nat_GroupCode }}
                                </span>
                                <br /> -->
                                {{ props.item.Nat_GroupName }}
                            </td>
                            <td class="text-xs-left pa-2" v-bind:class="{ 'amber lighten-4': isSelected(props.item) }"
                                @click="selectMe(props.item)">
                                <!-- <span class="font-weight-bold">
                                    {{ props.item.Nat_GroupCode }}
                                </span>
                                <br /> -->
                                {{ props.item.Nat_GroupName }} - {{ props.item.Nat_SubGroupName }}
                            </td>

                            <td class="text-xs-left pa-2" v-bind:class="{ 'amber lighten-4': isSelected(props.item) }"
                                @click="selectMe(props.item)">
                                <span class="font-weight-bold">
                                    {{ props.item.MapNatSub_PendapatanCoaAccountNo }}
                                </span>
                                <br />
                                {{ props.item.MapNatSub_PendapatanCoaDescription }}
                            </td>
                            <td class="text-xs-left pa-2" v-bind:class="{ 'amber lighten-4': isSelected(props.item) }"
                                @click="selectMe(props.item)">
                                <span class="font-weight-bold">
                                    {{ props.item.MapNatSub_BiayaCoaAccountNo }}
                                </span>
                                <br />
                                {{ props.item.MapNatSub_BiayaCoaDescription }}
                            </td>
                            <td class="text-xs-left pa-2" v-bind:class="{ 'amber lighten-4': isSelected(props.item) }"
                                @click="selectMe(props.item)">
                                <span class="font-weight-bold">
                                    {{ props.item.MapNatSub_PersediaanCoaAccountNo }}
                                </span>
                                <br />
                                {{ props.item.MapNatSub_PersediaanCoaDescription }}
                            </td>
                            <td class="text-xs-right pa-2" v-bind:class="{ 'amber lighten-4': isSelected(props.item) }"
                                @click="selectMe(props.item)">
                                <v-tooltip bottom>
                                    <template v-slot:activator="{ on, attrs }">
                                        <v-icon v-bind="attrs" v-on="on" small
                                            @click="openDeleteCoa(props.item)">delete</v-icon>
                                    </template>
                                    <span>Hapus</span>
                                </v-tooltip>
                                <v-tooltip bottom>
                                    <template v-slot:activator="{ on, attrs }">
                                        <v-icon v-bind="attrs" v-on="on" small
                                            @click="openEditFormCoa(props.item)">edit</v-icon>
                                    </template>
                                    <span>Edit</span>
                                </v-tooltip>
                                <!-- <v-tooltip bottom>
                                    <template v-slot:activator="{ on, attrs }">
                                        <v-icon v-bind="attrs" v-on="on" color="red" small
                                            @click="doPrintVoucher(props.item)">picture_as_pdf</v-icon>
                                    </template>
                                    <span>Voucher</span>
                                </v-tooltip> -->
                            </td>
                        </template>
                    </v-data-table>
                </v-flex>
            </v-layout>
            <v-divider></v-divider>
            <v-pagination style="margin-top: 10px; margin-bottom: 10px;" v-model="curr_page"
                :length="xtotal_page"></v-pagination>
        </v-card>
        <!-- table list end -->

        <!-- edit form dialog start -->
        <template>
            <v-layout row justify-center>
                <v-dialog v-model="dialog_edit_coa" persistent max-width="550px">
                    <v-toolbar dark class="blue lighten-3 white--text">
                        <v-toolbar-title class="white--text">EDIT FORM</v-toolbar-title>
                        <v-spacer></v-spacer>
                    </v-toolbar>
                    <v-card>
                        <v-card-text class="pt-4 pb-2">
                            <v-layout wrap>
                                <v-flex xs12>
                                    <!-- Group -->
                                    <v-select v-model="e_nat_group" :items="e_nat_group_list" item-text="Nat_GroupName"
                                        item-value="Nat_GroupID" label="Group" outlined dense return-object></v-select>
                                    <!-- Sub Group -->
                                    <v-select v-model="e_nat_subgroup" :items="e_nat_subgroup_list" item-text="display"
                                        item-value="Nat_SubGroupID" label="Sub Group" outlined dense return-object>
                                    </v-select>
                                    <!-- Sub Group -->
                                    <!-- Ac Pendapatan -->
                                    <v-autocomplete label="Acc Pendapatan" :items="e_coa_pendapatan_list"
                                        v-model="e_coa_pendapatan" :search-input.sync="e_coa_search_pendapatan"
                                        hide-details auto-select-first no-filter item-text="coaDescription" outline
                                        return-object no-data-text="Pilih Acc Pendapatan">
                                        <template slot="item" slot-scope="{ item }">
                                            <v-list-tile-content>
                                                <v-list-tile-title v-text="item.coaDescription"></v-list-tile-title>
                                                <v-list-tile-sub-title
                                                    v-text="item.coaAccountNo"></v-list-tile-sub-title>
                                            </v-list-tile-content>
                                        </template>
                                    </v-autocomplete>
                                    <!-- Ac Pendapatan -->
                                    <!-- Ac Biaya -->
                                    <v-autocomplete class="mt-3" label="Acc Biaya" :items="e_coa_biaya_list"
                                        v-model="e_coa_biaya" :search-input.sync="e_coa_search_biaya" hide-details
                                        auto-select-first no-filter item-text="coaDescription" outline return-object
                                        no-data-text="Pilih Acc Biaya">
                                        <template slot="item" slot-scope="{ item }">
                                            <v-list-tile-content>
                                                <v-list-tile-title v-text="item.coaDescription"></v-list-tile-title>
                                                <v-list-tile-sub-title
                                                    v-text="item.coaAccountNo"></v-list-tile-sub-title>
                                            </v-list-tile-content>
                                        </template>
                                    </v-autocomplete>
                                    <!-- Ac Biaya -->
                                    <!-- Ac Persediaan -->
                                    <v-autocomplete class="mt-3" label="Acc Persediaan" :items="e_coa_persediaan_list"
                                        v-model="e_coa_persediaan" :search-input.sync="e_coa_search_persediaan"
                                        hide-details auto-select-first no-filter item-text="coaDescription" outline
                                        return-object no-data-text="Pilih Acc Persediaan">
                                        <template slot="item" slot-scope="{ item }">
                                            <v-list-tile-content>
                                                <v-list-tile-title v-text="item.coaDescription"></v-list-tile-title>
                                                <v-list-tile-sub-title
                                                    v-text="item.coaAccountNo"></v-list-tile-sub-title>
                                            </v-list-tile-content>
                                        </template>
                                    </v-autocomplete>
                                    <!-- Ac Persediaan -->
                                </v-flex>
                            </v-layout>
                        </v-card-text>
                        <v-card-actions class="pr-3">
                            <v-spacer></v-spacer>
                            <v-btn color="error" flat @click="closeDialogEditCoa()">TUTUP</v-btn>
                            <v-btn color="primary" @click="saveFormEdit()">SIMPAN</v-btn>
                        </v-card-actions>
                    </v-card>
                </v-dialog>
            </v-layout>
        </template>

        <!-- edit form dialog end -->

        <!-- dialog delete start -->
        <template>
            <v-dialog v-model="dialogdeletealecoa" max-width="30%">
                <v-card>
                    <v-card-title class="headline grey lighten-2 pt-2 pb-2" primary-title>
                        Peringatan !
                    </v-card-title>
                    <v-card-text class="pt-2 pb-2">
                        <v-layout row>
                            <v-flex xs12 d-flex>
                                <v-layout row>
                                    <v-flex pb-1 xs12>
                                        <v-layout row>
                                            <v-flex pt-2 pr-2 xs12>
                                                {{ msgalertcoa }}
                                            </v-flex>
                                        </v-layout>
                                    </v-flex>
                                </v-layout>
                            </v-flex>
                        </v-layout>
                    </v-card-text>
                    <v-divider></v-divider>
                    <v-card-actions>
                        <v-spacer></v-spacer>
                        <v-btn color="error" flat @click="dialogdeletealecoa = false">
                            Tutup
                        </v-btn>
                        <v-btn color="primary" @click="closeDeleteAlertCoa()">
                            Ya
                        </v-btn>
                    </v-card-actions>
                </v-card>
            </v-dialog>
        </template>
        <!-- dialog delete end -->

        <!-- add form dialog start -->
        <template>
            <v-layout row justify-center>
                <v-dialog v-model="dialog_add_coa" persistent max-width="550px">
                    <v-toolbar dark class="blue lighten-3 white--text">
                        <v-toolbar-title class="white--text">ADD FORM</v-toolbar-title>
                        <v-spacer></v-spacer>
                    </v-toolbar>
                    <v-card>
                        <v-card-text class="pt-4 pb-2">
                            <v-layout wrap>
                                <v-flex xs12>
                                    <!-- Group -->
                                    <v-select v-model="a_nat_group" :items="a_nat_group_list" item-text="Nat_GroupName"
                                        item-value="Nat_GroupID" label="Group" outlined dense return-object></v-select>
                                    <!-- Group -->
                                    <!-- Sub Group -->
                                    <v-select v-model="a_nat_subgroup" :items="a_nat_subgroup_list" item-text="display"
                                        item-value="Nat_SubGroupID" label="Sub Group" outlined dense return-object>
                                    </v-select>
                                    <!-- Sub Group -->
                                    <!-- Ac Pendapatan -->
                                    <v-autocomplete label="Acc Pendapatan" :items="a_coa_pendapatan_list"
                                        v-model="a_coa_pendapatan" :search-input.sync="a_coa_search_pendapatan"
                                        hide-details auto-select-first no-filter item-text="coaDescription" outline
                                        return-object no-data-text="Pilih Acc Pendapatan">
                                        <template slot="item" slot-scope="{ item }">
                                            <v-list-tile-content>
                                                <v-list-tile-title v-text="item.coaDescription"></v-list-tile-title>
                                                <v-list-tile-sub-title
                                                    v-text="item.coaAccountNo"></v-list-tile-sub-title>
                                            </v-list-tile-content>
                                        </template>
                                    </v-autocomplete>
                                    <!-- Ac Pendapatan -->
                                    <!-- Ac Biaya -->
                                    <v-autocomplete class="mt-3" label="Acc Biaya" :items="a_coa_biaya_list"
                                        v-model="a_coa_biaya" :search-input.sync="a_coa_search_biaya" hide-details
                                        auto-select-first no-filter item-text="coaDescription" outline return-object
                                        no-data-text="Pilih Acc Biaya">
                                        <template slot="item" slot-scope="{ item }">
                                            <v-list-tile-content>
                                                <v-list-tile-title v-text="item.coaDescription"></v-list-tile-title>
                                                <v-list-tile-sub-title
                                                    v-text="item.coaAccountNo"></v-list-tile-sub-title>
                                            </v-list-tile-content>
                                        </template>
                                    </v-autocomplete>
                                    <!-- Ac Biaya -->
                                    <!-- Ac Persediaan -->
                                    <v-autocomplete class="mt-3" label="Acc Persediaan" :items="a_coa_persediaan_list"
                                        v-model="a_coa_persediaan" :search-input.sync="a_coa_search_persediaan"
                                        hide-details auto-select-first no-filter item-text="coaDescription" outline
                                        return-object no-data-text="Pilih Acc Persediaan">
                                        <template slot="item" slot-scope="{ item }">
                                            <v-list-tile-content>
                                                <v-list-tile-title v-text="item.coaDescription"></v-list-tile-title>
                                                <v-list-tile-sub-title
                                                    v-text="item.coaAccountNo"></v-list-tile-sub-title>
                                            </v-list-tile-content>
                                        </template>
                                    </v-autocomplete>
                                    <!-- Ac Persediaan -->
                                </v-flex>
                            </v-layout>
                        </v-card-text>
                        <v-card-actions class="pr-3">
                            <v-spacer></v-spacer>
                            <v-btn color="error" flat @click="closeDialogAddCoa()">TUTUP</v-btn>
                            <v-btn color="primary" @click="saveFormAdd()">SIMPAN</v-btn>
                        </v-card-actions>
                    </v-card>
                </v-dialog>
            </v-layout>
        </template>
        <!-- add form dialog end -->

        <template>
            <one-dialog-info :status="opendialoginfo" :msg="msginfo"
                @close-dialog-info="opendialoginfo = false"></one-dialog-info>
        </template>
    </div>
</template>

<style scoped>
table.v-table tbody td,
table.v-table tbody th {
    height: 40px;
}

table.v-table thead tr {
    height: 40px;
}

.textinput {
    -webkit-transition: width 0.4s ease-in-out;
    transition: width 0.4s ease-in-out;
    background-color: white;
    background-position: 10px 10px;
    background-repeat: no-repeat;
    padding-left: 40px;
    width: 100%;
    padding: 8px 10px;
    margin-bottom: 5px;
    box-sizing: border-box;
    border: 1px solid #607d8b;
}

.textinput:focus {
    width: 100%;
}

.textinput:focus::-webkit-input-placeholder {
    color: transparent;
}

.textinput:focus::-moz-placeholder {
    color: transparent;
}

.textinput:-moz-placeholder {
    color: transparent;
}

.scroll-container {
    scroll-padding: 50px 0 0 50px;
}
</style>

<script>
module.exports = {
    components: {
        "one-dialog-info": httpVueLoader("../../common/oneDialogInfo.vue"),
        "one-dialog-alert": httpVueLoader("../../common/oneDialogAlert.vue"),
        "one-dialog-error": httpVueLoader("../../common/oneDialogError.vue"),
        "one-dialog-print": httpVueLoader("../../common/oneDialogPrintX.vue"),
    },
    data() {
        return {
            formatreport: "pdf",
            urlprint: "",
            printtitle: "",
            printwidth: "100%",
            page: 1,
            MapNatSub_ID: 0,
            Nat_GroupName: "",
            headers: [
                {
                    text: "GROUP NAME",
                    align: "center",
                    sortable: false,
                    value: "date",
                    width: "10%",
                    class: "blue lighten-3 white--text",
                },
                {
                    text: "SUB GROUP",
                    align: "center",
                    sortable: false,
                    value: "jurnal",
                    width: "20%",
                    class: "blue lighten-3 white--text",
                },
                {
                    text: "ACC PENDAPATAN",
                    align: "center",
                    sortable: false,
                    value: "location",
                    width: "20%",
                    class: "blue lighten-3 white--text",
                },
                {
                    text: "ACC BIAYA",
                    align: "center",
                    sortable: false,
                    value: "info",
                    width: "15%",
                    class: "blue lighten-3 white--text",
                },
                {
                    text: "ACC PERSEDIAAN",
                    align: "center",
                    sortable: false,
                    value: "info",
                    width: "15%",
                    class: "blue lighten-3 white--text",
                },
                {
                    text: "AKSI",
                    align: "center",
                    sortable: false,
                    value: "status",
                    width: "5%",
                    class: "blue lighten-3 white--text",
                },
            ],
            dialogdeletealecoa: false,
            msgalertcoa: "",

            // edit
            e_coa_search_pendapatan: '',
            e_coa_search_biaya: '',
            e_coa_search_persediaan: ''
        }
    },
    mounted() {
        this.$store.dispatch("natsubgroup/open_add_nat_group");
        this.$store.dispatch("natsubgroup/open_add_nat_subgroup");
        this.$store.dispatch("natsubgroup/search", {
            current_page: this.$store.state.natsubgroup.a_current_page,
            search: this.$store.state.natsubgroup.a_x_search,
            last_id: -1,
        });
    },
    computed: {
        // edit
        dialog_edit_coa: {
            get() {
                return this.$store.state.natsubgroup.dialog_edit_coa;
            },
            set(val) {
                this.$store.commit("natsubgroup/update_dialog_edit_coa", val);
            },
        },
        opendialoginfo: {
            get() {
                return this.$store.state.natsubgroup.a_open_dialog_info;
            },
            set(val) {
                this.$store.commit("natsubgroup/update_a_open_dialog_info", false);
            },
        },
        msginfo: {
            get() {
                return this.$store.state.natsubgroup.a_msg_info;
            },
            set(val) {
                this.$store.commit("natsubgroup/update_a_msg_info", false);
            },
        },
        snackbar: {
            get() {
                return this.$store.state.natsubgroup.a_alert_success;
            },
            set(val) {
                this.$store.commit("natsubgroup/update_a_alert_success", val);
            },
        },
        msgSnackbar() {
            return this.$store.state.natsubgroup.a_msg_success;
        },
        dialog_error: {
            get() {
                return this.$store.state.natsubgroup.a_alert_error;
            },
            set(val) {
                this.$store.commit("natsubgroup/update_a_alert_error", val);
            },
        },
        msgError() {
            return this.$store.state.natsubgroup.a_save_error_message;
        },

        // search table start
        xcoas() {
            return this.$store.state.natsubgroup.a_coas;
        },
        isLoading() {
            return this.$store.state.natsubgroup.a_search_status === 1;
        },
        xsearch: {
            get() {
                return this.$store.state.natsubgroup.a_x_search;
            },
            set(val) {
                this.$store.commit("natsubgroup/update_a_x_search", val);
            },
        },
        curr_page: {
            get() {
                return this.$store.state.natsubgroup.a_current_page;
            },
            set(val) {
                this.$store.commit("natsubgroup/update_a_current_page", val);
                this.$store.commit("natsubgroup/update_a_last_id", -1);
                this.searchCoa();
            },
        },
        xtotal_page: {
            get() {
                return this.$store.state.natsubgroup.a_total_coa;
            },
            set(val) {
                this.$store.commit("natsubgroup/update_a_total_coa", val);
            },
        },
        // search table end

        // dialog add
        dialog_add_coa: {
            get() {
                return this.$store.state.natsubgroup.dialog_add_coa;
            },
            set(val) {
                this.$store.commit("natsubgroup/update_dialog_add_coa", val);
            },
        },

        dialog_edit_coa: {
            get() {
                return this.$store.state.natsubgroup.dialog_edit_coa;
            },
            set(val) {
                this.$store.commit("natsubgroup/update_dialog_edit_coa", val);
            },
        },

        // dropdown nat_group start
        a_nat_group_list() {
            return this.$store.state.natsubgroup.a_nat_group_list;
        },
        a_nat_group: {
            get() {
                return this.$store.state.natsubgroup.a_nat_group;
            },
            set(val) {
                this.$store.commit("natsubgroup/update_a_nat_group", val);
            },
        },

        e_nat_group_list() {
            return this.$store.state.natsubgroup.e_nat_group_list;
        },
        e_nat_group: {
            get() {
                return this.$store.state.natsubgroup.e_nat_group;
            },
            set(val) {
                this.$store.commit("natsubgroup/update_e_nat_group", val);
            },
        },

        // dropdown nat_subgroup
        a_nat_subgroup_list() {
            return this.$store.state.natsubgroup.a_nat_subgroup_list;
        },
        a_nat_subgroup: {
            get() {
                return this.$store.state.natsubgroup.a_nat_subgroup;
            },
            set(val) {
                this.$store.commit("natsubgroup/update_a_nat_subgroup", val);
            },
        },

        e_nat_subgroup_list() {
            return this.$store.state.natsubgroup.e_nat_subgroup_list;
        },
        e_nat_subgroup: {
            get() {
                return this.$store.state.natsubgroup.e_nat_subgroup;
            },
            set(val) {
                this.$store.commit("natsubgroup/update_e_nat_subgroup", val);
            },
        },

        // ac pendapatan start
        a_coa_pendapatan_list() {
            return this.$store.state.natsubgroup.a_coa_pendapatan_list;
        },
        a_coa_pendapatan: {
            get() {
                return this.$store.state.natsubgroup.a_coa_pendapatan;
            },
            set(val) {
                this.$store.commit("natsubgroup/update_a_coa_pendapatan", val);
            },
        },
        a_loading_coa_pendapatan: {
            get() {
                return this.$store.state.natsubgroup.a_loading_coa_pendapatan;
            },
            set(val) {
                this.$store.commit("natsubgroup/update_a_loading_coa_pendapatan", val);
            },
        },
        a_coa_search_pendapatan: {
            get() {
                return this.$store.state.natsubgroup.a_coa_search_pendapatan
            },

            set(val) {
                this.$store.commit("natsubgroup/update_a_coa_search_pendapatan", val);
                this.aSearchAcCoaPendapatan(val)
            }
        },

        // edit
        e_coa_pendapatan_list() {
            return this.$store.state.natsubgroup.e_coa_pendapatan_list;
        },
        e_coa_pendapatan: {
            get() {
                return this.$store.state.natsubgroup.e_coa_pendapatan;
            },
            set(val) {
                this.$store.commit("natsubgroup/update_e_coa_pendapatan", val);
            },
        },
        e_loading_coa_pendapatan: {
            get() {
                return this.$store.state.natsubgroup.e_loading_coa_pendapatan;
            },
            set(val) {
                this.$store.commit("natsubgroup/update_e_loading_coa_pendapatan", val);
            },
        },

        // ac biaya start
        a_coa_biaya_list() {
            return this.$store.state.natsubgroup.a_coa_biaya_list;
        },
        a_coa_biaya: {
            get() {
                return this.$store.state.natsubgroup.a_coa_biaya;
            },
            set(val) {
                this.$store.commit("natsubgroup/update_a_coa_biaya", val);
            },
        },
        a_loading_coa_biaya: {
            get() {
                return this.$store.state.natsubgroup.a_loading_coa_biaya;
            },
            set(val) {
                this.$store.commit("natsubgroup/update_a_loading_coa_biaya", val);
            },
        },

        a_coa_search_biaya: {
            get() {
                return this.$store.state.natsubgroup.a_coa_search_biaya
            },

            set(val) {
                this.$store.commit("natsubgroup/update_a_coa_search_biaya", val);
                this.aSearchAcCoaBiaya(val)
            }
        },

        e_coa_biaya_list() {
            return this.$store.state.natsubgroup.e_coa_biaya_list;
        },
        e_coa_biaya: {
            get() {
                return this.$store.state.natsubgroup.e_coa_biaya;
            },
            set(val) {
                this.$store.commit("natsubgroup/update_e_coa_biaya", val);
            },
        },
        e_loading_coa_biaya: {
            get() {
                return this.$store.state.natsubgroup.e_loading_coa_biaya;
            },
            set(val) {
                this.$store.commit("natsubgroup/update_e_loading_coa_biaya", val);
            },
        },

        // ac persediaan start
        a_coa_persediaan_list() {
            return this.$store.state.natsubgroup.a_coa_persediaan_list;
        },
        a_coa_persediaan: {
            get() {
                return this.$store.state.natsubgroup.a_coa_persediaan;
            },
            set(val) {
                this.$store.commit("natsubgroup/update_a_coa_persediaan", val);
            },
        },
        a_loading_coa_persediaan: {
            get() {
                return this.$store.state.natsubgroup.a_loading_coa_persediaan;
            },
            set(val) {
                this.$store.commit("natsubgroup/update_a_loading_coa_persediaan", val);
            },
        },
        a_coa_search_persediaan: {
            get() {
                return this.$store.state.natsubgroup.a_coa_search_persediaan
            },

            set(val) {
                this.$store.commit("natsubgroup/update_a_coa_search_persediaan", val);
                this.aSearchAcCoaPersediaan(val)
            }
        },

        e_coa_persediaan_list() {
            return this.$store.state.natsubgroup.e_coa_persediaan_list;
        },
        e_coa_persediaan: {
            get() {
                return this.$store.state.natsubgroup.e_coa_persediaan;
            },
            set(val) {
                this.$store.commit("natsubgroup/update_e_coa_persediaan", val);
            },
        },
        e_loading_coa_persediaan: {
            get() {
                return this.$store.state.natsubgroup.e_loading_coa_persediaan;
            },
            set(val) {
                this.$store.commit("natsubgroup/update_e_loading_coa_persediaan", val);
            },
        },
    },
    methods: {
        closeDialogEditCoa() {
            this.e_coa_search_pendapatan = ""
            this.e_coa_search_biaya = ""
            this.e_coa_search_persediaan = ""

            this.$store.commit("natsubgroup/update_dialog_edit_coa", false);
            this.$store.commit("natsubgroup/update_e_nat_group", {});
            this.$store.commit("natsubgroup/update_e_nat_group_list", []);

            this.$store.commit("natsubgroup/update_e_nat_subgroup", {});
            this.$store.commit("natsubgroup/update_e_nat_subgroup_list", []);

            this.$store.commit("natsubgroup/update_e_coa_pendapatan", {});
            this.$store.commit("natsubgroup/update_e_coa_pendapatan_list", []);

            this.$store.commit("natsubgroup/update_e_coa_biaya", {});
            this.$store.commit("natsubgroup/update_e_coa_biaya_list", []);

            this.$store.commit("natsubgroup/update_e_coa_persediaan", {});
            this.$store.commit("natsubgroup/update_e_coa_persediaan_list", []);
        },
        saveFormEdit() {
            var paramEdit = {
                MapNatSub_ID: this.$store.state.natsubgroup.MapNatSub_ID,
                e_nat_group_param: this.e_nat_group,
                e_nat_subgroup_param: this.e_nat_subgroup,
                e_coa_pendapatan_param: this.e_coa_pendapatan,
                e_coa_biaya_param: this.e_coa_biaya,
                e_coa_persediaan_param: this.e_coa_persediaan,
            };

            console.log('param edit', paramEdit);

            this.$store.dispatch("natsubgroup/edit_data", paramEdit);
        },
        openDeleteCoa(val) {
            console.log(val);
            this.MapNatSub_ID = val.MapNatSub_ID;
            this.Nat_GroupName = val.Nat_GroupName;

            this.msgalertcoa =
                "Yakin, mau hapus map coa [" +
                val.Nat_GroupName +
                "] ?";
            this.dialogdeletealecoa = true;
        },
        closeDeleteAlertCoa() {
            let prm = {
                MapNatSub_ID: this.MapNatSub_ID,
                Nat_GroupName: this.Nat_GroupName,
                current_page: this.$store.state.natsubgroup.a_current_page,
                search: this.$store.state.natsubgroup.a_x_search,
                last_id: -1,
            };
            this.dialogdeletealecoa = false;
            this.$store.dispatch("natsubgroup/delete_data", prm);
        },
        openEditFormCoa(val) {
            this.$store.dispatch("natsubgroup/get_by_id", val);
        },
        openDialogAdd() {
            this.$store.commit("natsubgroup/update_dialog_add_coa", true);
        },
        searchCoa() {
            this.$store.dispatch("natsubgroup/search", {
                current_page: this.$store.state.natsubgroup.a_current_page,
                search: this.$store.state.natsubgroup.a_x_search,
                last_id: -1,
            });
        },
        isSelected(p) {
            return p.MapNatSub_ID == this.$store.state.natsubgroup.a_selected_a_coa.MapNatSub_ID;
        },
        selectMe(sc) {
            this.$store.commit("natsubgroup/update_a_selected_a_coa", sc);
        },
        closeDialogAddCoa() {
            this.$store.commit("natsubgroup/update_dialog_add_coa", false);
            this.$store.commit("natsubgroup/update_a_nat_group", {});
            this.$store.commit("natsubgroup/update_a_nat_subgroup", {});
            this.$store.commit("natsubgroup/update_a_coa_pendapatan", {});
            this.$store.commit("natsubgroup/update_a_coa_biaya", {});
            this.$store.commit("natsubgroup/update_a_coa_persediaan", {});
        },
        saveFormAdd() {
            var paramAdd = {
                a_nat_group_param: this.a_nat_group,
                a_nat_subgroup_param: this.a_nat_subgroup,
                a_coa_pendapatan_param: this.a_coa_pendapatan,
                a_coa_biaya_param: this.a_coa_biaya,
                a_coa_persediaan_param: this.a_coa_persediaan,
            };

            // console.log('param add', paramAdd);

            this.$store.dispatch("natsubgroup/add_data", paramAdd);
        },
        async aSearchAcCoaPendapatan(query) {
            if (!query) return;
            this.a_loading_coa_pendapatan = true;
            await this.$store.dispatch("natsubgroup/open_add_coa_pendapatan", { search: query });
            this.a_loading_coa_pendapatan = false;
        },
        async eSearchAcCoaPendapatan(query) {
            if (!query) return;
            this.e_loading_coa_pendapatan = true;
            await this.$store.dispatch("natsubgroup/open_edit_coa_pendapatan", { search: query });
            this.e_loading_coa_pendapatan = false;
        },
        async aSearchAcCoaBiaya(query) {
            if (!query) return;
            this.a_loading_coa_biaya = true;
            await this.$store.dispatch("natsubgroup/open_add_coa_biaya", { search: query });
            this.a_loading_coa_biaya = false;
        },
        async eSearchAcCoaBiaya(query) {
            if (!query) return;
            this.e_loading_coa_biaya = true;
            await this.$store.dispatch("natsubgroup/open_edit_coa_biaya", { search: query });
            this.e_loading_coa_biaya = false;
        },
        async aSearchAcCoaPersediaan(query) {
            if (!query) return;
            this.a_loading_coa_persediaan = true;
            await this.$store.dispatch("natsubgroup/open_add_coa_persediaan", { search: query });
            this.a_loading_coa_persediaan = false;
        },
        async eSearchAcCoaPersediaan(query) {
            if (!query) return;
            this.e_loading_coa_persediaan = true;
            await this.$store.dispatch("natsubgroup/open_edit_coa_persediaan", { search: query });
            this.e_loading_coa_persediaan = false;
        },
    },
    watch: {
        e_coa_search_pendapatan(val) {
            this.eSearchAcCoaPendapatan(val)
        },
        e_coa_search_biaya(val) {
            this.eSearchAcCoaBiaya(val)
        },
        e_coa_search_persediaan(val) {
            this.eSearchAcCoaPersediaan(val)
        }
    },
}