<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 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.MapNatGroup_Dp_coaAccNo }}
                                </span>
                                <br />
                                {{ props.item.MapNatGroup_Dp_coaDesc }}
                            </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.MapNatGroup_Debt_coaAccNo }}
                                </span>
                                <br />
                                {{ props.item.MapNatGroup_Debt_coaDesc }}
                            </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.MapNatGroup_Disc_coaAccNo }}
                                </span>
                                <br />
                                {{ props.item.MapNatGroup_Disc_coaDesc }}
                            </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.MapNatGroup_Retur_coaAccNo }}
                                </span>
                                <br />
                                {{ props.item.MapNatGroup_Retur_coaDesc }}
                            </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 -->

        <!-- 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 -->
                                    <!-- Ac Uang Muka -->
                                    <!-- <v-autocomplete v-model="a_coa_uang_muka" :items="a_coa_uang_muka_list"
                                        :search-input.sync="a_coa_search_uang_muka" hide-no-data hide-selected
                                        item-text="coaDescription" label="Acc Uang Muka Pembayaran" hide-details outline
                                        return-object></v-autocomplete> -->

                                    <v-autocomplete label="Acc Uang Muka Pembayaran" :items="a_coa_uang_muka_list"
                                        v-model="a_coa_uang_muka" :search-input.sync="a_coa_search_uang_muka"
                                        hide-details auto-select-first no-filter item-text="coaDescription" outline
                                        return-object no-data-text="Pilih Acc Uang Muka Pembayaran">
                                        <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 Uang Muka -->
                                    <!-- Ac Hutang -->
                                    <!-- <v-autocomplete class="mt-3" v-model="a_coa_hutang" :items="a_coa_hutang_list"
                                        :search-input.sync="a_coa_search_hutang" hide-no-data hide-selected
                                        item-text="coaDescription" label="Acc Hutang Pembelian Persediaan" hide-details
                                        outline return-object></v-autocomplete> -->

                                    <v-autocomplete class="mt-3" label="Acc Hutang Pembelian Persediaan"
                                        :items="a_coa_hutang_list" v-model="a_coa_hutang"
                                        :search-input.sync="a_coa_search_hutang" hide-details auto-select-first
                                        no-filter item-text="coaDescription" outline return-object
                                        no-data-text="Pilih Acc Hutang Pembelian 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 Hutang -->
                                    <!-- Ac Disc Pendapatan -->
                                    <!-- <v-autocomplete class="mt-3" v-model="a_coa_disc_pendapatan"
                                        :items="a_coa_disc_pendapatan_list"
                                        :search-input.sync="a_coa_search_disc_pendapatan" hide-no-data hide-selected
                                        item-text="coaDescription" label="Acc Discount Pendapatan" hide-details outline
                                        return-object></v-autocomplete> -->

                                    <v-autocomplete class="mt-3" label="Acc Discount Pendapatan"
                                        :items="a_coa_disc_pendapatan_list" v-model="a_coa_disc_pendapatan"
                                        :search-input.sync="a_coa_search_disc_pendapatan" hide-details auto-select-first
                                        no-filter item-text="coaDescription" outline return-object
                                        no-data-text="Pilih Acc Discount 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 Disc Pendapatan -->
                                    <!-- Ac Retur Pendapatan -->
                                    <!-- <v-autocomplete class="mt-3" v-model="a_coa_retur_pendapatan"
                                        :items="a_coa_retur_pendapatan_list"
                                        :search-input.sync="a_coa_search_retur_pendapatan" hide-no-data hide-selected
                                        item-text="coaDescription" label="Acc Retur Pendapatan" hide-details outline
                                        return-object></v-autocomplete> -->

                                    <v-autocomplete class="mt-3" label="Acc Retur Pendapatan"
                                        :items="a_coa_retur_pendapatan_list" v-model="a_coa_retur_pendapatan"
                                        :search-input.sync="a_coa_search_retur_pendapatan" hide-details
                                        auto-select-first no-filter item-text="coaDescription" outline return-object
                                        no-data-text="Pilih Acc Retur 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 Retur Pendapatan -->
                                </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 -->

        <!-- 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>
                                    <!-- Group -->
                                    <!-- Ac Uang Muka -->
                                    <!-- <v-autocomplete v-model="e_coa_uang_muka" :items="e_coa_uang_muka_list"
                                        :search-input.sync="e_coa_search_uang_muka" hide-no-data hide-selected
                                        item-text="coaDescription" label="Acc Uang Muka Pembayaran" hide-details outline
                                        return-object></v-autocomplete> -->

                                    <v-autocomplete label="Acc Uang Muka Pembayaran" :items="e_coa_uang_muka_list"
                                        v-model="e_coa_uang_muka" :search-input.sync="e_coa_search_uang_muka"
                                        hide-details auto-select-first no-filter item-text="coaDescription" outline
                                        return-object no-data-text="Pilih Acc Uang Muka Pembayaran">
                                        <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 Uang Muka -->

                                    <!-- Ac Hutang -->
                                    <!-- <v-autocomplete class="mt-3" v-model="e_coa_hutang" :items="e_coa_hutang_list"
                                        :search-input.sync="e_coa_search_hutang" hide-no-data hide-selected
                                        item-text="coaDescription" label="Acc Hutang Pembelian Persediaan" hide-details
                                        outline return-object></v-autocomplete> -->


                                    <v-autocomplete class="mt-3" label="Acc Hutang Pembelian Persediaan"
                                        :items="e_coa_hutang_list" v-model="e_coa_hutang"
                                        :search-input.sync="e_coa_search_hutang" hide-details auto-select-first
                                        no-filter item-text="coaDescription" outline return-object
                                        no-data-text="Pilih Acc Hutang Pembelian 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 Hutang -->
                                    <!-- Ac Disc Pendapatan -->
                                    <!-- <v-autocomplete class="mt-3" v-model="e_coa_disc_pendapatan"
                                        :items="e_coa_disc_pendapatan_list"
                                        :search-input.sync="e_coa_search_disc_pendapatan" hide-no-data hide-selected
                                        item-text="coaDescription" label="Acc Discount Pendapatan" hide-details outline
                                        return-object></v-autocomplete> -->

                                    <v-autocomplete class="mt-3" label="Acc Discount Pendapatan"
                                        :items="e_coa_disc_pendapatan_list" v-model="e_coa_disc_pendapatan"
                                        :search-input.sync="e_coa_search_disc_pendapatan" hide-details auto-select-first
                                        no-filter item-text="coaDescription" outline return-object
                                        no-data-text="Pilih Acc Discount 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 Disc Pendapatan -->
                                    <!-- Ac Retur Pendapatan -->
                                    <!-- <v-autocomplete class="mt-3" v-model="e_coa_retur_pendapatan"
                                        :items="e_coa_retur_pendapatan_list"
                                        :search-input.sync="e_coa_search_retur_pendapatan" hide-no-data hide-selected
                                        item-text="coaDescription" label="Acc Retur Pendapatan" hide-details outline
                                        return-object></v-autocomplete> -->

                                    <v-autocomplete class="mt-3" label="Acc Retur Pendapatan"
                                        :items="e_coa_retur_pendapatan_list" v-model="e_coa_retur_pendapatan"
                                        :search-input.sync="e_coa_search_retur_pendapatan" hide-details
                                        auto-select-first no-filter item-text="coaDescription" outline return-object
                                        no-data-text="Pilih Acc Retur 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 Retur Pendapatan -->

                                </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 -->

        <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,
            MapNatGroup_ID: 0,
            Nat_GroupName: "",
            headers: [
                {
                    text: "GROUP NAME",
                    align: "center",
                    sortable: false,
                    value: "date",
                    width: "10%",
                    class: "blue lighten-3 white--text",
                },
                {
                    text: "UANG MUKA PEMBY",
                    align: "center",
                    sortable: false,
                    value: "jurnal",
                    width: "20%",
                    class: "blue lighten-3 white--text",
                },
                {
                    text: "HUTANG PEMBELIAN",
                    align: "center",
                    sortable: false,
                    value: "location",
                    width: "20%",
                    class: "blue lighten-3 white--text",
                },
                {
                    text: "DISC. PEND",
                    align: "center",
                    sortable: false,
                    value: "info",
                    width: "15%",
                    class: "blue lighten-3 white--text",
                },
                {
                    text: "RETUR. PEND",
                    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: "",

            // search edit ac
            e_coa_search_uang_muka: "",
            e_coa_search_hutang: "",
            e_coa_search_disc_pendapatan: "",
            e_coa_search_retur_pendapatan: "",
        }
    },
    mounted() {
        this.$store.dispatch("a_coa/search", {
            current_page: this.$store.state.a_coa.a_current_page,
            search: this.$store.state.a_coa.a_x_search,
            last_id: -1,
        });

        this.$store.dispatch("a_coa/open_add_nat_group");
        // this.$store.dispatch("a_coa/open_add_coa_uang_muka", { searchUangMuka: "" });
    },
    computed: {
        // edit
        dialog_edit_coa: {
            get() {
                return this.$store.state.a_coa.dialog_edit_coa;
            },
            set(val) {
                this.$store.commit("a_coa/update_dialog_edit_coa", val);
            },
        },
        // edit
        dialog_add_coa: {
            get() {
                return this.$store.state.a_coa.dialog_add_coa;
            },
            set(val) {
                this.$store.commit("a_coa/update_dialog_add_coa", val);
            },
        },
        opendialoginfo: {
            get() {
                return this.$store.state.a_coa.a_open_dialog_info;
            },
            set(val) {
                this.$store.commit("a_coa/update_a_open_dialog_info", false);
            },
        },
        msginfo: {
            get() {
                return this.$store.state.a_coa.a_msg_info;
            },
            set(val) {
                this.$store.commit("a_coa/update_a_msg_info", false);
            },
        },
        snackbar: {
            get() {
                return this.$store.state.a_coa.a_alert_success;
            },
            set(val) {
                this.$store.commit("a_coa/update_a_alert_success", val);
            },
        },
        msgSnackbar() {
            return this.$store.state.a_coa.a_msg_success;
        },
        dialog_error: {
            get() {
                return this.$store.state.a_coa.a_alert_error;
            },
            set(val) {
                this.$store.commit("a_coa/update_a_alert_error", val);
            },
        },
        msgError() {
            return this.$store.state.a_coa.a_save_error_message;
        },

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

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

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

        // ac uang muka start
        a_coa_uang_muka_list() {
            return this.$store.state.a_coa.a_coa_uang_muka_list;
        },
        a_coa_uang_muka: {
            get() {
                return this.$store.state.a_coa.a_coa_uang_muka;
            },
            set(val) {
                this.$store.commit("a_coa/update_a_coa_uang_muka", val);
            },
        },
        a_loading_coa_uang_muka: {
            get() {
                return this.$store.state.a_coa.a_loading_coa_uang_muka;
            },
            set(val) {
                this.$store.commit("a_coa/update_a_loading_coa_uang_muka", val);
            },
        },
        a_coa_search_uang_muka: {
            get() {
                return this.$store.state.a_coa.a_coa_search_uang_muka
            },

            set(val) {
                this.$store.commit("a_coa/update_a_coa_search_uang_muka", val);
                this.aSearchAcCoaUangMuka(val)
            }
        },

        // 
        e_coa_uang_muka_list() {
            return this.$store.state.a_coa.e_coa_uang_muka_list;
        },
        e_coa_uang_muka: {
            get() {
                return this.$store.state.a_coa.e_coa_uang_muka;
            },
            set(val) {
                this.$store.commit("a_coa/update_e_coa_uang_muka", val);
            },
        },
        e_loading_coa_uang_muka: {
            get() {
                return this.$store.state.a_coa.e_loading_coa_uang_muka;
            },
            set(val) {
                this.$store.commit("a_coa/update_e_loading_coa_uang_muka", val);
            },
        },
        // ac uang muka end

        // ac hutang start
        a_coa_hutang_list() {
            return this.$store.state.a_coa.a_coa_hutang_list;
        },
        a_coa_hutang: {
            get() {
                return this.$store.state.a_coa.a_coa_hutang;
            },
            set(val) {
                this.$store.commit("a_coa/update_a_coa_hutang", val);
            },
        },
        a_loading_coa_hutang: {
            get() {
                return this.$store.state.a_coa.a_loading_coa_hutang;
            },
            set(val) {
                this.$store.commit("a_coa/update_a_loading_coa_hutang", val);
            },
        },
        a_coa_search_hutang: {
            get() {
                return this.$store.state.a_coa.a_coa_search_hutang
            },

            set(val) {
                this.$store.commit("a_coa/update_a_coa_search_hutang", val);
                this.aSearchAcCoaHutang(val)
            }
        },

        e_coa_hutang_list() {
            return this.$store.state.a_coa.e_coa_hutang_list;
        },
        e_coa_hutang: {
            get() {
                return this.$store.state.a_coa.e_coa_hutang;
            },
            set(val) {
                this.$store.commit("a_coa/update_e_coa_hutang", val);
            },
        },
        e_loading_coa_hutang: {
            get() {
                return this.$store.state.a_coa.e_loading_coa_hutang;
            },
            set(val) {
                this.$store.commit("a_coa/update_e_loading_coa_hutang", val);
            },
        },
        // ac hutang end

        // ac disc pendapatan start
        a_coa_disc_pendapatan_list() {
            return this.$store.state.a_coa.a_coa_disc_pendapatan_list;
        },
        a_coa_disc_pendapatan: {
            get() {
                return this.$store.state.a_coa.a_coa_disc_pendapatan;
            },
            set(val) {
                this.$store.commit("a_coa/update_a_coa_disc_pendapatan", val);
            },
        },
        a_loading_coa_disc_pendapatan: {
            get() {
                return this.$store.state.a_coa.a_loading_coa_disc_pendapatan;
            },
            set(val) {
                this.$store.commit("a_coa/update_a_loading_coa_disc_pendapatan", val);
            },
        },
        a_coa_search_disc_pendapatan: {
            get() {
                return this.$store.state.a_coa.a_coa_search_disc_pendapatan
            },

            set(val) {
                this.$store.commit("a_coa/update_a_coa_search_disc_pendapatan", val);
                this.aSearchAcCoaDiscPendapatan(val)
            }
        },

        // 
        e_coa_disc_pendapatan_list() {
            return this.$store.state.a_coa.e_coa_disc_pendapatan_list;
        },
        e_coa_disc_pendapatan: {
            get() {
                return this.$store.state.a_coa.e_coa_disc_pendapatan;
            },
            set(val) {
                this.$store.commit("a_coa/update_e_coa_disc_pendapatan", val);
            },
        },
        e_loading_coa_disc_pendapatan: {
            get() {
                return this.$store.state.a_coa.e_loading_coa_disc_pendapatan;
            },
            set(val) {
                this.$store.commit("a_coa/update_e_loading_coa_disc_pendapatan", val);
            },
        },

        // ac disc pendapatan end
        // ac retur pendapatan start
        a_coa_retur_pendapatan_list() {
            return this.$store.state.a_coa.a_coa_retur_pendapatan_list;
        },
        a_coa_retur_pendapatan: {
            get() {
                return this.$store.state.a_coa.a_coa_retur_pendapatan;
            },
            set(val) {
                this.$store.commit("a_coa/update_a_coa_retur_pendapatan", val);
            },
        },
        a_loading_coa_retur_pendapatan: {
            get() {
                return this.$store.state.a_coa.a_loading_coa_retur_pendapatan;
            },
            set(val) {
                this.$store.commit("a_coa/update_a_loading_coa_retur_pendapatan", val);
            },
        },
        a_coa_search_retur_pendapatan: {
            get() {
                return this.$store.state.a_coa.a_coa_search_retur_pendapatan
            },

            set(val) {
                this.$store.commit("a_coa/update_a_coa_search_retur_pendapatan", val);
                this.aSearchAcCoaReturPendapatan(val)
            }
        },

        e_coa_retur_pendapatan_list() {
            return this.$store.state.a_coa.e_coa_retur_pendapatan_list;
        },
        e_coa_retur_pendapatan: {
            get() {
                return this.$store.state.a_coa.e_coa_retur_pendapatan;
            },
            set(val) {
                this.$store.commit("a_coa/update_e_coa_retur_pendapatan", val);
            },
        },
        e_loading_coa_retur_pendapatan: {
            get() {
                return this.$store.state.a_coa.e_loading_coa_retur_pendapatan;
            },
            set(val) {
                this.$store.commit("a_coa/update_e_loading_coa_retur_pendapatan", val);
            },
        },
        // ac retur pendapatan end
    },
    methods: {
        openEditFormCoa(val) {
            // this.$store.dispatch("a_coa/update_e_nat_group",{});
            console.log('edit data ', val)
            this.$store.dispatch("a_coa/get_by_id", val);
        },
        closeDialogEditCoa() {
            this.e_coa_search_uang_muka = ""
            this.e_coa_search_hutang = ""
            this.e_coa_search_disc_pendapatan = ""
            this.e_coa_search_retur_pendapatan = ""


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

            this.$store.commit("a_coa/update_e_coa_uang_muka_list", []);
            this.$store.commit("a_coa/update_e_coa_uang_muka", {});

            this.$store.commit("a_coa/update_e_coa_hutang_list", []);
            this.$store.commit("a_coa/update_e_coa_hutang", {});

            this.$store.commit("a_coa/update_e_coa_disc_pendapatan_list", []);
            this.$store.commit("a_coa/update_e_coa_disc_pendapatan", {});

            this.$store.commit("a_coa/update_e_coa_retur_pendapatan_list", []);
            this.$store.commit("a_coa/update_e_coa_retur_pendapatan", {});

            this.$store.commit("a_coa/update_dialog_edit_coa", false);
        },
        saveFormEdit() {
            var paramEdit = {
                MapNatGroup_ID: this.$store.state.a_coa.MapNatGroup_ID,
                e_nat_group_param: this.e_nat_group,
                e_coa_uang_muka_param: this.e_coa_uang_muka,
                e_coa_hutang_param: this.e_coa_hutang,
                e_coa_disc_pendapatan_param: this.e_coa_disc_pendapatan,
                e_coa_retur_pendapatan_param: this.e_coa_retur_pendapatan,
            };

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

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

            this.msgalertcoa =
                "Yakin, mau hapus map coa [" +
                val.Nat_GroupName +
                "] ?";
            this.dialogdeletealecoa = true;
        },
        closeDeleteAlertCoa() {
            let prm = {
                MapNatGroup_ID: this.MapNatGroup_ID,
                Nat_GroupName: this.Nat_GroupName,
                current_page: this.$store.state.a_coa.a_current_page,
                search: this.$store.state.a_coa.a_x_search,
                last_id: -1,
            };
            this.dialogdeletealecoa = false;
            this.$store.dispatch("a_coa/delete_data", prm);
        },
        searchCoa() {
            this.$store.dispatch("a_coa/search", {
                current_page: this.$store.state.a_coa.a_current_page,
                search: this.$store.state.a_coa.a_x_search,
                last_id: -1,
            });
        },
        updateAlertSuccess(val) {
            this.$store.commit("a_coa/update_a_alert_success", val);
        },
        isSelected(p) {
            return p.MapNatGroup_ID == this.$store.state.a_coa.a_selected_a_coa.MapNatGroup_ID;
        },
        selectMe(sc) {
            this.$store.commit("a_coa/update_a_selected_a_coa", sc);
        },
        // check inputan yg ada object nya {}
        isObjectEmpty(obj) {
            return Object.keys(obj).length === 0 && obj.constructor === Object;
        },
        saveFormAdd() {
            var paramAdd = {
                a_nat_group_param: this.a_nat_group,
                a_coa_uang_muka_param: this.a_coa_uang_muka,
                a_coa_hutang_param: this.a_coa_hutang,
                a_coa_disc_pendapatan_param: this.a_coa_disc_pendapatan,
                a_coa_retur_pendapatan_param: this.a_coa_retur_pendapatan,
            };

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

            this.$store.dispatch("a_coa/add_data", paramAdd);
        },
        openDialogAdd() {
            this.$store.commit("a_coa/update_dialog_add_coa", true);
        },
        closeDialogAddCoa() {
            this.$store.commit("a_coa/update_dialog_add_coa", false);
            this.$store.commit("a_coa/update_a_nat_group", {});
            this.$store.commit("a_coa/update_a_coa_uang_muka", {});
            this.$store.commit("a_coa/update_a_coa_hutang", {});
            this.$store.commit("a_coa/update_a_coa_disc_pendapatan", {});
            this.$store.commit("a_coa/update_a_coa_retur_pendapatan", {});
        },
        async aSearchAcCoaUangMuka(query) {
            if (!query) return;
            this.a_loading_coa_uang_muka = true;
            await this.$store.dispatch("a_coa/open_add_coa_uang_muka", { search: query });
            this.a_loading_coa_uang_muka = false;
        },
        async eSearchAcCoaUangMuka(query) {
            if (!query) return;
            this.e_loading_coa_uang_muka = true;
            await this.$store.dispatch("a_coa/open_edit_coa_uang_muka", { search: query });
            this.e_loading_coa_uang_muka = false;
        },
        async aSearchAcCoaHutang(query) {
            if (!query) return;
            this.a_loading_coa_hutang = true;
            await this.$store.dispatch("a_coa/open_add_coa_hutang", { search: query });
            this.a_loading_coa_hutang = false;
        },
        async eSearchAcCoaHutang(query) {
            if (!query) return;
            this.e_loading_coa_hutang = true;
            await this.$store.dispatch("a_coa/open_edit_coa_hutang", { search: query });
            this.e_loading_coa_hutang = false;
        },
        async aSearchAcCoaDiscPendapatan(query) {
            if (!query) return;
            this.a_loading_coa_disc_pendapatan = true;
            await this.$store.dispatch("a_coa/open_add_coa_disc_pendapatan", { search: query });
            this.a_loading_coa_disc_pendapatan = false;
        },
        async eSearchAcCoaDiscPendapatan(query) {
            if (!query) return;
            this.e_loading_coa_disc_pendapatan = true;
            await this.$store.dispatch("a_coa/open_edit_coa_disc_pendapatan", { search: query });
            this.e_loading_coa_disc_pendapatan = false;
        },
        async aSearchAcCoaReturPendapatan(query) {
            if (!query) return;
            this.a_loading_coa_retur_pendapatan = true;
            await this.$store.dispatch("a_coa/open_add_coa_retur_pendapatan", { search: query });
            this.a_loading_coa_retur_pendapatan = false;
        },
        async eSearchAcCoaReturPendapatan(query) {
            if (!query) return;
            this.e_loading_coa_retur_pendapatan = true;
            await this.$store.dispatch("a_coa/open_edit_coa_retur_pendapatan", { search: query });
            this.e_loading_coa_retur_pendapatan = false;
        },
    },
    watch: {
        e_coa_search_uang_muka(val) {
            this.eSearchAcCoaUangMuka(val)
        },

        e_coa_search_hutang(val) {
            this.eSearchAcCoaHutang(val)
        },

        e_coa_search_disc_pendapatan(val) {
            this.eSearchAcCoaDiscPendapatan(val)
        },

        e_coa_search_retur_pendapatan(val) {
            this.eSearchAcCoaReturPendapatan(val)
        },
    },
}