<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">ITEM (REGIONAL)</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)">
                                {{ props.item.S_RegionalName }}
                            </td>
                            <td class="text-xs-left pa-2" v-bind:class="{ 'amber lighten-4': isSelected(props.item) }"
                                @click="selectMe(props.item)">
                                <div class="date-type-table">
                      <span>{{props.item.M_ItemDesc}}
                      </span>
                      <p>{{props.item.M_ItemCode}}
                      </p>
                    </div>
                            </td>
                            <td class="text-xs-right pa-2" v-bind:class="{ 'amber lighten-4': isSelected(props.item) }"
                                @click="selectMe(props.item)">
                                {{ props.item.M_ItemRegionalMinQty }}
                                <p>{{props.item.ItemUnitName}}
                      </p>
                            </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 -->

        <!-- 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">ITEM (REGIONAL)</v-toolbar-title>
                        <v-spacer></v-spacer>
                    </v-toolbar>
                    <v-card>
                        <v-card-text class="pt-4 pb-2">
                        <v-form ref="formRequest" v-model="validationForm" lazy-validtion>
                            <v-layout wrap>
                                <v-flex xs12>

                                <v-autocomplete class="mt-3" label="Regional" :items="a_regional_list" v-model="a_regional"
                                        :search-input.sync="a_regional_search" hide-details auto-select-first no-filter
                                        item-text="S_RegionalName" outline return-object no-data-text="Cari Regional">
                                        <template slot="item" slot-scope="{ item }">
                                            <v-list-tile-content>
                                                <v-list-tile-title v-text="item.S_RegionalName"></v-list-tile-title>
                                            </v-list-tile-content>
                                        </template>
                                    </v-autocomplete>
                                    <p v-if="checkErrorForm('requireRegional')" class="error pl-2 pr-2" style="color:#fff">Regional harus dipilih</p>

                                <v-autocomplete class="mt-3" label="Item" :items="a_item_list" v-model="a_item"
                                        :search-input.sync="a_item_search" hide-details auto-select-first no-filter
                                        item-text="M_ItemDesc" outline return-object no-data-text="Cari Item">
                                        <template slot="item" slot-scope="{ item }">
                                            <v-list-tile-content>
                                                <v-list-tile-title v-text="item.M_ItemDesc"></v-list-tile-title>
                                                <v-list-tile-sub-title
                                                    v-text="item.M_ItemCode"></v-list-tile-sub-title>
                                            </v-list-tile-content>
                                        </template>
                                    </v-autocomplete>
                                    <p v-if="checkErrorForm('requireItem')" class="error pl-2 pr-2" style="color:#fff">Item harus dipilih</p>
                                        <v-text-field class="mt-3" label="Min Qty" type="number" v-model="a_qty" hide-details
                                        outline></v-text-field>
                  <p v-if="checkErrorForm('requireQty')" class="error pl-2 pr-2" style="color:#fff">Min Qty harus diisi</p>
                  <v-autocomplete class="mt-3" label="Unit" :items="a_unit_list" v-model="a_unit"
                                        :search-input.sync="a_unit_search" hide-details auto-select-first no-filter
                                        item-text="ItemUnitName" outline return-object no-data-text="Cari Satuan">
                                        <template slot="item" slot-scope="{ item }">
                                            <v-list-tile-content>
                                                <v-list-tile-title v-text="item.ItemUnitName"></v-list-tile-title>
                                                <v-list-tile-sub-title
                                                    v-text="item.ItemUnitCode"></v-list-tile-sub-title>
                                            </v-list-tile-content>
                                        </template>
                                    </v-autocomplete>
                                    <p v-if="checkErrorForm('requireUnit')" class="error pl-2 pr-2" style="color:#fff">Satuan harus dipilih</p>
                                        
        
                                </v-flex>
                                

                            </v-layout>
                            </v-form>
                        </v-card-text>
                        <v-card-text>
                        <v-layout>
                                </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" v-if="this.xid == 0" @click="saveFormAdd()">SIMPAN</v-btn>
                            <v-btn color="primary" v-if="this.xid !== 0" @click="saveFormEdit()">SIMPAN PERUBAHAN</v-btn>
                        </v-card-actions>
                    </v-card>
                </v-dialog>
            </v-layout>
        </template>
        <!-- add 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 -->

        

        <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 {
            a_noteRules: [(v) => !!v || "Catatan harus diisi"],
            a_itemRules: [(v) => !!v || "Item harus dipilih"],
            a_regionalRules: [(v) => !!v || "Regional harus dipilih"],
            a_unitRules: [(v) => !!v || "Satuan harus dipilih"],
            a_qtyRules: [(v) => !!v || "Jumlah harus diisi"],
            a_acquisition_priceRules: [(v) => !!v || "Harga perolehan harus diisi"],
            a_coaRules: [(v) => !!v || "Account harus dipilih"],
            validationForm: false,
            formatreport: "pdf",
            urlprint: "",
            printtitle: "",
            printwidth: "100%",
            page: 1,
            M_ItemRegionalID: 0,
            Fa_ClassName: "",
            headers: [
                {
                    text: "REGIONAL",
                    align: "center",
                    sortable: false,
                    value: "jurnal",
                    width: "30%",
                    class: "blue lighten-3 white--text",
                },
                {
                    text: "ITEM",
                    align: "right",
                    sortable: false,
                    value: "location",
                    width: "30%",
                    class: "blue lighten-3 white--text",
                },
                {
                    text: "MIN QTY (UNIT)",
                    align: "center",
                    sortable: false,
                    value: "info",
                    width: "30%",
                    class: "blue lighten-3 white--text",
                },
                {
                    text: "AKSI",
                    align: "center",
                    sortable: false,
                    value: "status",
                    width: "10%",
                    class: "blue lighten-3 white--text",
                },
            ],
            dialogdeletealecoa: false,
            msgalertcoa: "",

            e_coa_search: '',
            e_coa_search_accum_depre: ''
        }
    },
    mounted() {
        this.$store.dispatch("itemregional/search", {
            current_page: this.$store.state.itemregional.a_current_page,
            search: this.$store.state.itemregional.a_x_search,
            last_id: -1,
        });
    },
    computed: {
        opendialoginfo: {
            get() {
                return this.$store.state.itemregional.a_open_dialog_info;
            },
            set(val) {
                this.$store.commit("itemregional/update_a_open_dialog_info", false);
            },
        },
        msginfo: {
            get() {
                return this.$store.state.itemregional.a_msg_info;
            },
            set(val) {
                this.$store.commit("itemregional/update_a_msg_info", false);
            },
        },
        snackbar: {
            get() {
                return this.$store.state.itemregional.a_alert_success;
            },
            set(val) {
                this.$store.commit("itemregional/update_a_alert_success", val);
            },
        },
        msgSnackbar() {
            return this.$store.state.itemregional.a_msg_success;
        },
        dialog_error: {
            get() {
                return this.$store.state.itemregional.a_alert_error;
            },
            set(val) {
                this.$store.commit("itemregional/update_a_alert_error", val);
            },
        },
        msgError() {
            return this.$store.state.itemregional.a_save_error_message;
        },
        // search table start
        xcoas() {
            return this.$store.state.itemregional.a_coas;
        },
        isLoading() {
            return this.$store.state.itemregional.a_search_status === 1;
        },
        xsearch: {
            get() {
                return this.$store.state.itemregional.a_x_search;
            },
            set(val) {
                this.$store.commit("itemregional/update_a_x_search", val);
            },
        },
        curr_page: {
            get() {
                return this.$store.state.itemregional.a_current_page;
            },
            set(val) {
                this.$store.commit("itemregional/update_a_current_page", val);
                this.$store.commit("itemregional/update_a_last_id", -1);
                this.searchCoa();
            },
        },
        xtotal_page: {
            get() {
                return this.$store.state.itemregional.a_total_coa;
            },
            set(val) {
                this.$store.commit("itemregional/update_a_total_coa", val);
            },
        },
        // search table end

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

        dialog_edit_coa: {
            get() {
                return this.$store.state.itemregional.dialog_edit_coa;
            },
            set(val) {
                this.$store.commit("itemregional/update_dialog_edit_coa", val);
            },
        },
        xid: {
            get() {
                return this.$store.state.itemregional.xid;
            },
            set(val) {
                this.$store.commit("itemregional/update_xid", val);
            },
        },
        xnumber: {
            get() {
                return this.$store.state.itemregional.xnumber;
            },
            set(val) {
                this.$store.commit("itemregional/update_xnumber", val);
            },
        },
        // text classname
        a_faname: {
            get() {
                return this.$store.state.itemregional.a_faname;
            },
            set(val) {
                this.$store.commit("itemregional/update_a_faname", val);
            },
        },

        e_classname: {
            get() {
                return this.$store.state.itemregional.e_classname;
            },
            set(val) {
                this.$store.commit("itemregional/update_e_classname", val);
            },
        },

        // ac coa start
        a_coa_list() {
            return this.$store.state.itemregional.a_coa_list;
        },
        a_coa: {
            get() {
                return this.$store.state.itemregional.a_coa;
            },
            set(val) {
                this.$store.commit("itemregional/update_a_coa", val);
            },
        },
        a_loading_coa: {
            get() {
                return this.$store.state.itemregional.a_loading_coa;
            },
            set(val) {
                this.$store.commit("itemregional/update_a_loading_coa", val);
            },
        },
        a_coa_search: {
            get() {
                return this.$store.state.itemregional.a_coa_search
            },

            set(val) {
                this.$store.commit("itemregional/update_a_coa_search", val);
                //this.aSearchAcCoa(val)
            }
        },
        // ac item start
        a_item_list() {
            return this.$store.state.itemregional.a_item_list;
        },
        a_item: {
            get() {
                return this.$store.state.itemregional.a_item;
            },
            set(val) {
                this.$store.commit("itemregional/update_a_item", val);
            },
        },
        a_loading_item: {
            get() {
                return this.$store.state.itemregional.a_loading_item;
            },
            set(val) {
                this.$store.commit("itemregional/update_a_loading_item", val);
            },
        },
        a_item_search: {
            get() {
                return this.$store.state.itemregional.a_item_search
            },

            set(val) {
                this.$store.commit("itemregional/update_a_item_search", val);
               // this.aSearchItem(val)
                
            }
        },
        a_regional_list() {
            return this.$store.state.itemregional.a_regional_list;
        },
        a_regional: {
            get() {
                return this.$store.state.itemregional.a_regional;
            },
            set(val) {
                this.$store.commit("itemregional/update_a_regional", val);
            },
        },
        a_loading_regional: {
            get() {
                return this.$store.state.itemregional.a_loading_regional;
            },
            set(val) {
                this.$store.commit("itemregional/update_a_loading_regional", val);
            },
        },
        a_regional_search: {
            get() {
                return this.$store.state.itemregional.a_regional_search
            },

            set(val) {
                this.$store.commit("itemregional/update_a_regional_search", val);
               // this.aSearchItem(val)
                
            }
        },
        a_unit_list() {
            return this.$store.state.itemregional.a_unit_list;
        },
        a_unit: {
            get() {
                return this.$store.state.itemregional.a_unit;
            },
            set(val) {
                this.$store.commit("itemregional/update_a_unit", val);
            },
        },
        a_loading_unit: {
            get() {
                return this.$store.state.itemregional.a_loading_unit;
            },
            set(val) {
                this.$store.commit("itemregional/update_a_loading_unit", val);
            },
        },
        a_unit_search: {
            get() {
                return this.$store.state.itemregional.a_unit_search
            },

            set(val) {
                this.$store.commit("itemregional/update_a_unit_search", val);
               // this.aSearchItem(val)
                
            }
        },
        // ac department start
        a_department_list() {
            return this.$store.state.itemregional.a_department_list;
        },
        a_department: {
            get() {
                return this.$store.state.itemregional.a_department;
            },
            set(val) {
                this.$store.commit("itemregional/update_a_department", val);
            },
        },
        a_loading_department: {
            get() {
                return this.$store.state.itemregional.a_loading_department;
            },
            set(val) {
                this.$store.commit("itemregional/update_a_loading_department", val);
            },
        },
        a_department_search: {
            get() {
                return this.$store.state.itemregional.a_department_search
            },

            set(val) {
                this.$store.commit("itemregional/update_a_department_search", val);
                //this.aSearchDepartment(val)
            }
        },
        a_qty: {
            get() {
                return this.$store.state.itemregional.a_qty;
            },
            set(val) {
                this.$store.commit("itemregional/update_a_qty", val);
            },
        },
        a_acquisition_price: {
            get() {
                return this.$store.state.itemregional.a_acquisition_price;
            },
            set(val) {
                this.$store.commit("itemregional/update_a_acquisition_price", val);
            },
        },
        a_inventaris: {
            get() {
                return this.$store.state.itemregional.a_inventaris;
            },
            set(val) {
                this.$store.commit("itemregional/update_a_inventaris", val);
            },
        },
        a_note: {
            get() {
                return this.$store.state.itemregional.a_note;
            },
            set(val) {
                this.$store.commit("itemregional/update_a_note", val);
            },
        },
        a_fa_account_id: {
            get() {
                return this.$store.state.itemregional.a_fa_account_id;
            },
            set(val) {
                this.$store.commit("itemregional/update_a_fa_account_id", val);
            },
        },
       a_fa_account_name: {
            get() {
                return this.$store.state.itemregional.a_fa_account_name;
            },
            set(val) {
                this.$store.commit("itemregional/update_a_fa_account_name", val);
            },
        },
        a_accum_depre_account_id: {
          get() {
                return this.$store.state.itemregional.a_accum_depre_account_id;
            },
            set(val) {
                this.$store.commit("itemregional/update_a_accum_depre_account_id", val);
            },      
        },
        a_accum_depre_account_name: {
          get() {
                return this.$store.state.itemregional.a_accum_depre_account_name;
            },
            set(val) {
                this.$store.commit("itemregional/update_a_accum_depre_account_name", val);
            },      
        },
        a_depre_account_id: {
          get() {
                return this.$store.state.itemregional.a_depre_account_id;
            },
            set(val) {
                this.$store.commit("itemregional/update_a_depre_account_id", val);
            },      
        },
        a_depre_account_name: {
          get() {
                return this.$store.state.itemregional.a_depre_account_name;
            },
            set(val) {
                this.$store.commit("itemregional/update_a_depre_account_name", val);
            },      
        }
        
    },
    methods: {
        searchCoa() {
            this.$store.dispatch("itemregional/search", {
                current_page: this.$store.state.itemregional.a_current_page,
                search: this.$store.state.itemregional.a_x_search,
                last_id: -1,
            });
        },
        checkErrorForm(val) {
            let errors = this.$store.state.itemregional.errors;
            if (errors.includes(val)) {
                return true;
            } else {
                return false;
            }
        },
        isSelected(p) {
            return p.M_ItemRegionalID == this.$store.state.itemregional.a_selected_a_coa.M_ItemRegionalID;
        },
        selectMe(sc) {
            this.$store.commit("itemregional/update_a_selected_a_coa", sc);
        },
        closeDialogAddCoa() {
            this.$store.commit("itemregional/update_dialog_add_coa", false);

        },
        async aSearchAcCoa(query) {
            if (!query) return;
            this.a_loading_coa = true;
            await this.$store.dispatch("itemregional/open_add_coa", { search: query });
            this.a_loading_coa = false;
        },
        async aSearchItem(query) {
            if (!query) return;
            this.a_loading_item = true;
            await this.$store.dispatch("itemregional/open_add_item", { search: query });
            this.a_loading_item = false;
        },
        async aSearchRegional(query) {
            if (!query) return;
            this.a_loading_regional = true;
            await this.$store.dispatch("itemregional/open_add_regional", { search: query });
            this.a_loading_regional = false;
        },
        async aSearchUnit(query) {
            if (!query) return;
            this.a_loading_unit = true;
            await this.$store.dispatch("itemregional/open_add_unit", { search: query });
            this.a_loading_unit = false;
        },
        async aSearchDepartment(query) {
            if (!query) return;
            this.a_loading_department = true;
            await this.$store.dispatch("itemregional/open_add_department", { search: query });
            this.a_loading_department = false;
        },
        // add data
        openDialogAdd() {
            this.$refs.formRequest.resetValidation();
            this.$store.commit("itemregional/update_xid", 0);
            this.$store.commit("itemregional/update_dialog_add_coa", true);
            
            this.$store.commit("itemregional/update_a_item", {});
            this.$store.commit("itemregional/update_a_item_list", {});
            this.$store.commit("itemregional/update_a_regional", {});
            this.$store.commit("itemregional/update_a_regional_list", {});
            this.$store.commit("itemregional/update_a_unit", {});
            this.$store.commit("itemregional/update_a_unit_list", {});

            this.$store.commit("itemregional/update_a_qty", 0);
            
        },
        saveFormAdd() {
            
            var paramAdd = {
        M_ItemRegionalM_ItemID : this.a_item.M_ItemID,
        M_ItemRegionalS_RegionalID : this.a_regional.S_RegionalID,
        M_ItemRegionalItemUnitID : this.a_unit.ItemUnitID,
        M_ItemRegionalQty : this.a_qty};

            console.log('param add', paramAdd);
            this.$store.commit("itemregional/update_errors", []);
            var errors = this.$store.state.itemregional.errors;
            
            if (_.isEmpty(this.a_item)) {
                errors.push("requireItem");
            }
            if (_.isEmpty(this.a_regional)) {
                errors.push("requireRegional");
            }
            if (_.isEmpty(this.a_unit)) {
                errors.push("requireUnit");
            }
            if (_.isEmpty(this.a_qty)) {
                errors.push("requireQty");
            }
            if (errors.length === 0) {
            this.$store.dispatch("itemregional/add_data", paramAdd);
            }
        },
        // edit
        closeDialogEditCoa() {
            this.e_coa_search = ""
            this.e_coa_search_accum_depre = ""

            this.$store.commit("itemregional/update_dialog_edit_coa", false);
            this.$store.commit("itemregional/update_e_classname", "");
            this.$store.commit("itemregional/update_e_coa", {});
            this.$store.commit("itemregional/update_e_deprecorp", "");
            this.$store.commit("itemregional/update_e_coa_accum_depre", {});
            this.$store.commit("itemregional/update_e_note", "");
        },
        saveFormEdit() {
            var paramEdit = {
                M_ItemRegionalID: this.xid,
                M_ItemRegionalM_DepartmentID : this.a_department.M_DepartmentID,
        M_ItemRegionalM_ItemID : this.a_item.M_ItemID,
        M_ItemRegionalS_RegionalID	 : this.a_regional.S_RegionalID	,
        M_ItemRegionalItemUnitID : this.a_unit.ItemUnitID,
        M_ItemRegionalQty : this.a_qty
            };

            console.log('paramEdit', paramEdit);
            if (this.$refs.formRequest.validate()) {
            this.$store.dispatch("itemregional/edit_data", paramEdit);
            }

        },
        // delete data
        openDeleteCoa(val) {
            console.log(val);
            this.M_ItemRegionalID = val.M_ItemRegionalID;

            this.msgalertcoa =
                "Yakin, mau hapus data " + val.S_RegionalName+ " [" +
                val.M_ItemDesc +
                "] ?";
            this.dialogdeletealecoa = true;
        },
        closeDeleteAlertCoa() {
            let prm = {
                M_ItemRegionalID: this.M_ItemRegionalID,
                M_ItemDesc: this.M_ItemDesc,
                current_page: this.$store.state.itemregional.a_current_page,
                search: this.$store.state.itemregional.a_x_search,
                last_id: -1,
            };
            this.dialogdeletealecoa = false;
            this.$store.dispatch("itemregional/delete_data", prm);
        },
        // edit data
        openEditFormCoa(val) {
            this.$store.dispatch("itemregional/get_by_id", val);
            this.$store.commit("itemregional/update_xid", val.M_ItemRegionalID);
            this.$store.commit("itemregional/update_a_item", {M_ItemID : val.M_ItemID,
                M_ItemCode : val.M_ItemCode, M_ItemDesc : val.M_ItemDesc});
            this.$store.commit("itemregional/update_a_item_list", {M_ItemID : val.M_ItemID,
                M_ItemCode : val.M_ItemCode, M_ItemDesc : val.M_ItemDesc});
            this.$store.commit("itemregional/update_a_regional", {S_RegionalID : val.S_RegionalID,S_RegionalName : val.S_RegionalName});
this.$store.commit("itemregional/update_a_regional_list", {S_RegionalID : val.S_RegionalID, S_RegionalName : val.S_RegionalName});
            this.$store.commit("itemregional/update_a_unit", {ItemUnitID : val.ItemUnitID,ItemUnitCode : val.ItemUnitCode, ItemUnitName : val.ItemUnitName});
this.$store.commit("itemregional/update_a_unit_list", {ItemUnitID : val.ItemUnitID, ItemUnitCode : val.ItemUnitCode, ItemUnitName : val.ItemUnitName});
            this.a_loading_item = false;
            this.a_loading_regional = false;
            this.a_loading_unit = false;
            this.$store.commit("itemregional/update_a_qty", val.M_ItemRegionalMinQty);    
            this.$store.commit("itemregional/update_dialog_add_coa", true);
        },
    },
    watch: {
        a_item_search(val) {
            this.aSearchItem(val)
        },
        a_regional_search(val) {
            this.aSearchRegional(val)
        },
        a_unit_search(val) {
            this.aSearchUnit(val)
        },
        a_coa_search(val) {
            this.aSearchAcCoa(val)
        },
        a_department_search(val) {
            this.aSearchDepartment(val)
        },
        e_coa_search_accum_depre(val) {
            this.eSearchAcCoaAccumDepre(val)
        },
    },
};
</script>
