<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">REGISTER FIXED ASSET</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.Fa_ItemNumber }}
                            </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.Fa_ItemNote}}
                      </span>
                      <p>{{props.item.M_ItemDesc}}
                      </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.Fa_ItemQty }}
                            </td>
                            <td class="text-xs-left pa-2" v-bind:class="{ 'amber lighten-4': isSelected(props.item) }"
                                @click="selectMe(props.item)">
                                {{ props.item.ClassCoaDescription }}
                            </td>
                            <td class="text-xs-left pa-2" v-bind:class="{ 'amber lighten-4': isSelected(props.item) }"
                                @click="selectMe(props.item)">
                                {{ props.item.AccumDepreCoaDescription }}
                            </td>
                            <td class="text-xs-left pa-2" v-bind:class="{ 'amber lighten-4': isSelected(props.item) }"
                                @click="selectMe(props.item)">
                                {{ props.item.AcquisitionCoaDescription }}
                            </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">FIX ASSET REGISTER {{xnumber}}</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" 
                  v-model="xRegional"
                  label="Regional"
                  menu-icon="mdi-chevron-down"
                  :items="regionalOptions"
                  item-text="S_RegionalName"
                  item-value="S_RegionalID" hide-details
                                        outline>
                  </v-autocomplete>
              </v-flex>
              <v-flex xs12>
                <v-autocomplete class="mt-3" 
                  v-model="xBranch"
                  label="Cabang"
                  menu-icon="mdi-chevron-down"
                  :items="branchOptions"
                  item-text="M_BranchName"
                  item-value="M_BranchCode"
                  :rules="branchRules"
                  required
                hide-details
                                        outline></v-autocomplete>
              </v-flex>
                                <v-flex xs12>
                                <v-text-field class="mt-3" label="No. Inventaris" v-model="a_inventaris" hide-details
                                        outline></v-text-field>
                                <v-text-field class="mt-3" label="Catatan" v-model="a_note" hide-details
                                        outline></v-text-field>
                                        <p v-if="checkErrorForm('requireNote')" class="error pl-2 pr-2" style="color:#fff">Catatan harus diisi</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="Jumlah" type="number" v-model="a_qty" hide-details
                                        outline></v-text-field>
                                        <v-text-field class="mt-3" label="Harga Perolehan" type="number" v-model="a_acquisition_price" hide-details
                                        outline></v-text-field>
                                        <p v-if="checkErrorForm('requirePrice')" class="error pl-2 pr-2" style="color:#fff">Harga perolehan harus diisi</p>
                                        <v-text-field class="mt-3" label="Nilai Buku Saat Ini" type="number" v-model="a_book_value" hide-details
                                        outline></v-text-field>
                                        <p v-if="checkErrorForm('requireBook')" class="error pl-2 pr-2" style="color:#fff">Nilai Buku Saat Ini harus diisi</p>
                                         <v-text-field class="mt-3" label="Umur Asset (Bulan)" readonly v-model="a_fa_age" hide-details
                                        outline></v-text-field>
                                        <v-text-field class="mt-3" label="Depresiasi Per Bulan" readonly v-model="a_fa_depresiasi_bulan" hide-details
                                        outline></v-text-field>
                                         <v-text-field class="mt-3" label="FA Account" readonly v-model="a_fa_account_name" hide-details
                                        outline></v-text-field>
                                        <v-text-field class="mt-3" label="Accum Depre Account" readonly v-model="a_accum_depre_account_name" hide-details
                                        outline></v-text-field>
                                    <v-autocomplete class="mt-3" label="Account Perolehan" :items="a_coa_list" v-model="a_coa"
                                        :search-input.sync="a_coa_search" hide-details auto-select-first no-filter
                                        item-text="coaDescription" outline return-object no-data-text="Cari Account Perolehan">
                                        <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>
                                    <v-autocomplete class="mt-3" label="Presentase Cabang" :items="a_presentase_list" v-model="a_presentase"
                                        :search-input.sync="a_presentase_search" hide-details auto-select-first no-filter
                                        item-text="BranchFaPercentType" outline return-object no-data-text="Cari Presentase Cabang">
                                        <template slot="item" slot-scope="{ item }">
                                            <v-list-tile-content>
                                                <v-list-tile-title v-text="item.BranchFaPercentType"></v-list-tile-title>

                                            </v-list-tile-content>
                                        </template>
                                    </v-autocomplete>
                                    <v-autocomplete class="mt-3" label="Departement" :items="a_department_list" v-model="a_department"
                                        :search-input.sync="a_department_search" hide-details auto-select-first no-filter
                                        item-text="M_DepartmentName" outline return-object no-data-text="Cari Department">
                                        <template slot="item" slot-scope="{ item }">
                                            <v-list-tile-content>
                                                <v-list-tile-title v-text="item.M_DepartmentName"></v-list-tile-title>
                                                <v-list-tile-sub-title
                                                    v-text="item.M_DepartmentCode"></v-list-tile-sub-title>
                                            </v-list-tile-content>
                                        </template>
                                    </v-autocomplete>
                                </v-flex>
                                

                            </v-layout>
                            </v-form>
                        </v-card-text>
                        <v-card-text>
                        <v-layout>
                        <v-flex xs12> <span class="font-weight-bold">Nilai saat ini : 0 </span></v-flex>
                                <v-flex xs12> <span class="font-weight-bold"> Accum Depre : 0 </span></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" 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 -->

        <!-- 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>
                                    <!-- Class Name -->
                                    <v-text-field label="CLASS NAME" v-model="e_classname" hide-details
                                        outline></v-text-field>
                                    <!-- Ac coa -->
                                    <v-autocomplete class="mt-3" label="Acc Coa" :items="e_coa_list" v-model="e_coa"
                                        :search-input.sync="e_coa_search" hide-details auto-select-first no-filter
                                        item-text="coaDescription" outline return-object no-data-text="Pilih Acc Coa">
                                        <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 coa -->
                                    <!-- depre corpd -->
                                    <v-text-field class="mt-3" label="DEPRE CORP" v-model="e_deprecorp" hide-details
                                        outline></v-text-field>
                                    <!-- Ac accum depre -->
                                    <v-autocomplete class="mt-3" label="Acc Accum Depre" :items="e_coa_accum_depre_list"
                                        v-model="e_coa_accum_depre" :search-input.sync="e_coa_search_accum_depre"
                                        hide-details auto-select-first no-filter item-text="coaDescription" outline
                                        return-object no-data-text="Pilih Acc Accum Depre">
                                        <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 accum depre -->
                                    <!-- Accum Note -->
                                    <v-textarea class="mt-3" label="NOTE" v-model="e_note" hide-details rows="3"
                                        outline></v-textarea>
                                </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 {
            a_noteRules: [(v) => !!v || "Catatan harus diisi"],
            a_itemRules: [(v) => !!v || "Item 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,
            Fa_ItemID: 0,
            Fa_ClassName: "",
            headers: [
                {
                    text: "NO. ASSET",
                    align: "center",
                    sortable: false,
                    value: "date",
                    width: "5%",
                    class: "blue lighten-3 white--text",
                },
                {
                    text: "ITEM",
                    align: "center",
                    sortable: false,
                    value: "jurnal",
                    width: "20%",
                    class: "blue lighten-3 white--text",
                },
                {
                    text: "JUMLAH",
                    align: "right",
                    sortable: false,
                    value: "location",
                    width: "10%",
                    class: "blue lighten-3 white--text",
                },
                {
                    text: "FA ACCOUNT",
                    align: "center",
                    sortable: false,
                    value: "info",
                    width: "20%",
                    class: "blue lighten-3 white--text",
                },
                {
                    text: "ACCUM DEPRE ACCOUNT",
                    align: "left",
                    sortable: false,
                    value: "info",
                    width: "20%",
                    class: "blue lighten-3 white--text",
                },
                {
                    text: "ACCOUNT PEROLEHAN",
                    align: "left",
                    sortable: false,
                    value: "info",
                    width: "20%",
                    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: "",

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

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

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

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

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

            set(val) {
                this.$store.commit("fixedasset/update_a_coa_search", val);
                //this.aSearchAcCoa(val)
            }
        },
        // ac item start
        a_item_list() {
            return this.$store.state.fixedasset.a_item_list;
        },
        a_item: {
            get() {
                return this.$store.state.fixedasset.a_item;
            },
            set(val) {
                this.$store.commit("fixedasset/update_a_item", val);
                this.$store.commit("fixedasset/update_a_fa_account_id", val.Fa_ClassCoaID);
                this.$store.commit("fixedasset/update_a_fa_account_name", val.Fa_ClassCoaDesc);
                this.$store.commit("fixedasset/update_a_fa_age", val.Fa_ClassAgeAsset);
                this.$store.commit("fixedasset/update_a_accum_depre_account_id", val.Fa_ClassAccumDepreCoaID);
                this.$store.commit("fixedasset/update_a_accum_depre_account_name", val.Fa_ClassAccumDepreCoaDesc);
                this.$store.commit("fixedasset/update_a_depre_account_id", val.Fa_ClassDepreCoaID);
                this.$store.commit("fixedasset/update_a_depre_account_name", val.Fa_ClassDepreCoaDesc);
            },
        },
        a_fa_age: {
            get() {
                return this.$store.state.fixedasset.a_fa_age;
            },
            set(val) {
                this.$store.commit("fixedasset/update_a_fa_age", val);
            },
        },
        a_fa_depresiasi_bulan: {
            get() {
                return this.$store.state.fixedasset.a_fa_depresiasi_bulan;
            },
            set(val) {
                this.$store.commit("fixedasset/update_a_fa_depresiasi_bulan", val);
            },
        },
        a_loading_item: {
            get() {
                return this.$store.state.fixedasset.a_loading_item;
            },
            set(val) {
                this.$store.commit("fixedasset/update_a_loading_item", val);
            },
        },
        a_item_search: {
            get() {
                return this.$store.state.fixedasset.a_item_search
            },

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

            set(val) {
                this.$store.commit("fixedasset/update_a_department_search", val);
                //this.aSearchDepartment(val)
            }
        },
        // ac presentase start
        a_presentase_list() {
            return this.$store.state.fixedasset.a_presentase_list;
        },
        a_presentase: {
            get() {
                return this.$store.state.fixedasset.a_presentase;
            },
            set(val) {
                this.$store.commit("fixedasset/update_a_presentase", val);
            },
        },
        a_loading_presentase: {
            get() {
                return this.$store.state.fixedasset.a_loading_presentase;
            },
            set(val) {
                this.$store.commit("fixedasset/update_a_loading_presentase", val);
            },
        },
        a_presentase_search: {
            get() {
                return this.$store.state.fixedasset.a_presentase_search
            },

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

        },
        async aSearchAcCoa(query) {
            if (!query) return;
            this.a_loading_coa = true;
            await this.$store.dispatch("fixedasset/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("fixedasset/open_add_item", { search: query });
            this.a_loading_item = false;
        },
        async aSearchDepartment(query) {
            if (!query) return;
            this.a_loading_department = true;
            await this.$store.dispatch("fixedasset/open_add_department", { search: query });
            this.a_loading_department = false;
        },
        async aSearchPresentase(query) {
            if (!query) return;
            this.a_loading_presentase = true;
            await this.$store.dispatch("fixedasset/open_add_presentase", { search: query });
            this.a_loading_presentase = false;
        },
        // add data
        openDialogAdd() {
            let user = one_user()
      console.log('user')
      console.log(user)
      this.$store.commit("fixedasset/updateRegionalOptions", user);
      this.$store.commit("fixedasset/updateXRegional", user);
      this.$store.commit("fixedasset/updateBranchOptions", user);
      this.$store.commit("fixedasset/updateXBranch", user);

            this.$refs.formRequest.resetValidation();
            this.$store.commit("fixedasset/update_xid", 0);
            this.$store.commit("fixedasset/update_dialog_add_coa", true);
            
            this.$store.commit("fixedasset/update_xnumber", '');
            this.$store.commit("fixedasset/update_a_inventaris", '');
            this.$store.commit("fixedasset/update_a_note", '');
            this.$store.commit("fixedasset/update_a_item", {});
            this.$store.commit("fixedasset/update_a_item_list", {});
            this.$store.commit("fixedasset/update_a_qty", 1);
            this.$store.commit("fixedasset/update_a_acquisition_price", 0);
            this.$store.commit("fixedasset/update_a_fa_depresiasi_bulan", 0);
            this.$store.commit("fixedasset/update_a_book_value", 0);
            this.$store.commit("fixedasset/update_a_fa_account_id", 0);
                this.$store.commit("fixedasset/update_a_fa_account_name", '');
                this.$store.commit("fixedasset/update_a_accum_depre_account_id", 0);
                this.$store.commit("fixedasset/update_a_accum_depre_account_name", '');
                this.$store.commit("fixedasset/update_a_depre_account_id", 0);
                this.$store.commit("fixedasset/update_a_depre_account_name", '');
            
             this.$store.commit("fixedasset/update_a_coa", {});

            this.$store.commit("fixedasset/update_a_department", {});
            this.$store.commit("fixedasset/update_a_department_list", {});

            this.$store.commit("fixedasset/update_a_presentase", {});
            this.$store.commit("fixedasset/update_a_presentase_list", {});

            
        },
        saveFormAdd() {
            
            var paramAdd = {
                Fa_ItemM_DepartmentID : this.a_department.M_DepartmentID,
                Fa_ItemBranchFaPercentID : this.a_presentase.BranchFaPercentID,
        Fa_ItemM_ItemID : this.a_item.M_ItemID,
        Fa_ItemQty : this.a_qty,
        Fa_ItemPurchasePrice : 0,
        Fa_ItemAcquisitionPrice : this.a_acquisition_price,
        Fa_ItemNetBookValue : this.a_book_value,
        Fa_ItemDeprePerMonth : this.a_fa_depresiasi_bulan,
        Fa_ItemFa_ClassCoaID : this.a_fa_account_id,
        Fa_ItemInventarisNumber : this.a_inventaris,
        Fa_ItemNote : this.a_note,
        Fa_ItemFa_ClassAccumDepreCoaID : this.a_accum_depre_account_id,
        Fa_ItemFa_ClassDepreCoaID : this.a_depre_account_id,
        Fa_ItemAcquisitionCoaID : this.a_coa.coaID,
        Fa_ItemCurrentValue : 0,
        Fa_ItemAccumDepre : 0,
        Fa_ItemS_RegionalID : this.xRegional.S_RegionalID,
        Fa_ItemM_BranchCode : this.xBranch.M_BranchCode
            };

            console.log('param add', paramAdd);
            this.$store.commit("fixedasset/update_errors", []);
            var errors = this.$store.state.fixedasset.errors;
            if (_.isEmpty(this.a_note)) {
                errors.push("requireNote");
            }
            if (_.isEmpty(this.a_item)) {
                errors.push("requireItem");
            }
            if (_.isEmpty(this.a_acquisition_price)) {
                errors.push("requirePrice");
            }
            if (_.isEmpty(this.a_book_value)) {
                errors.push("requireBook");
            }
            if (errors.length === 0) {
            this.$store.dispatch("fixedasset/add_data", paramAdd);
            }
        },
        // edit
        closeDialogEditCoa() {
            this.e_coa_search = ""
            this.e_coa_search_accum_depre = ""

            this.$store.commit("fixedasset/update_dialog_edit_coa", false);
            this.$store.commit("fixedasset/update_e_classname", "");
            this.$store.commit("fixedasset/update_e_coa", {});
            this.$store.commit("fixedasset/update_e_deprecorp", "");
            this.$store.commit("fixedasset/update_e_coa_accum_depre", {});
            this.$store.commit("fixedasset/update_e_note", "");
        },
        saveFormEdit() {
            var paramEdit = {
                Fa_ItemID: this.xid,
                Fa_ItemM_DepartmentID : this.a_department.M_DepartmentID,
                Fa_ItemBranchFaPercentID : this.a_presentase.BranchFaPercentID,
        Fa_ItemM_ItemID : this.a_item.M_ItemID,
        Fa_ItemQty : this.a_qty,
        Fa_ItemPurchasePrice : 0,
        Fa_ItemAcquisitionPrice : this.a_acquisition_price,
        Fa_ItemNetBookValue : this.a_book_value,
        Fa_ItemDeprePerMonth : this.a_fa_depresiasi_bulan,
        Fa_ItemFa_ClassCoaID : this.a_fa_account_id,
        Fa_ItemInventarisNumber : this.a_inventaris,
        Fa_ItemNote : this.a_note,
        Fa_ItemFa_ClassAccumDepreCoaID : this.a_accum_depre_account_id,
        Fa_ItemFa_ClassDepreCoaID : this.a_depre_account_id,
        Fa_ItemAcquisitionCoaID : this.a_coa.coaID,
        Fa_ItemCurrentValue : 0,
        Fa_ItemAccumDepre : 0,
        Fa_ItemS_RegionalID : this.xRegional.S_RegionalID,
        Fa_ItemM_BranchCode : this.xBranch.M_BranchCode
            };

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

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

            this.msgalertcoa =
                "Yakin, mau hapus data [" +
                val.Fa_ItemNote +
                "] ?";
            this.dialogdeletealecoa = true;
        },
        closeDeleteAlertCoa() {
            let prm = {
                Fa_ItemID: this.Fa_ItemID,
                Fa_ItemNote: this.Fa_ItemNote,
                current_page: this.$store.state.fixedasset.a_current_page,
                search: this.$store.state.fixedasset.a_x_search,
                last_id: -1,
            };
            this.dialogdeletealecoa = false;
            this.$store.dispatch("fixedasset/delete_data", prm);
        },
        // edit data
        openEditFormCoa(val) {
            this.$store.dispatch("fixedasset/get_by_id", val);
            this.$store.commit("fixedasset/update_xid", val.Fa_ItemID);
            this.$store.commit("fixedasset/update_xnumber", val.Fa_ItemNumber);
            this.$store.commit("fixedasset/update_a_inventaris", val.Fa_ItemInventarisNumber);
            this.$store.commit("fixedasset/update_a_note", val.Fa_ItemNote);
            this.$store.commit("fixedasset/update_a_item", {M_ItemID : val.M_ItemID,
                M_ItemCode : val.M_ItemCode, M_ItemDesc : val.M_ItemDesc,
                Fa_ClassCoaID : val.Fa_ClassCoaID, Fa_ClassCoaDesc : val.Fa_ClassCoaDesc,
                Fa_ClassAccumDepreCoaID : val.Fa_ClassAccumDepreCoaID, Fa_ClassAccumDepreCoaDesc : val.Fa_ClassAccumDepreCoaDesc,
                Fa_ClassDepreCoaID : val.Fa_ClassDepreCoaID, Fa_ClassDepreCoaDesc : val.Fa_ClassDepreCoaDesc});
            this.$store.commit("fixedasset/update_a_item_list", {M_ItemID : val.M_ItemID,
                M_ItemCode : val.M_ItemCode, M_ItemDesc : val.M_ItemDesc,
                Fa_ClassCoaID : val.Fa_ClassCoaID, Fa_ClassCoaDesc : val.Fa_ClassCoaDesc,
                Fa_ClassAccumDepreCoaID : val.Fa_ClassAccumDepreCoaID, Fa_ClassAccumDepreCoaDesc : val.Fa_ClassAccumDepreCoaDesc,
                Fa_ClassDepreCoaID : val.Fa_ClassDepreCoaID, Fa_ClassDepreCoaDesc : val.Fa_ClassDepreCoaDesc});
            this.a_loading_item = false;
            this.$store.commit("fixedasset/update_a_qty", val.Fa_ItemQty);
            this.$store.commit("fixedasset/update_a_acquisition_price", val.Fa_ItemAcquisitionPrice);
            this.$store.commit("fixedasset/update_a_book_value", val.Fa_ItemNetBookValue);
            this.$store.commit("fixedasset/update_a_fa_depresiasi_bulan", val.Fa_ItemDeprePerMonth);
            this.$store.commit("fixedasset/update_a_fa_account_id", val.Fa_ClassCoaID);
                this.$store.commit("fixedasset/update_a_fa_account_name", val.Fa_ClassCoaDesc);
                this.$store.commit("fixedasset/update_a_accum_depre_account_id", val.Fa_ClassAccumDepreCoaID);
                this.$store.commit("fixedasset/update_a_accum_depre_account_name", val.Fa_ClassAccumDepreCoaDesc);
                this.$store.commit("fixedasset/update_a_depre_account_id", val.Fa_ClassDepreCoaID);
                this.$store.commit("fixedasset/update_a_depre_account_name", val.Fa_ClassDepreCoaDesc);
            
             this.$store.commit("fixedasset/update_a_coa", {coaID : val.AcquisitionCoaID,
                coaDescription : val.AcquisitionCoaDescription, coaAccountNo : val.AcquisitionCoaAccountNo});
                this.$store.commit("fixedasset/update_a_coa_list", {coaID : val.AcquisitionCoaID,
                coaDescription : val.AcquisitionCoaDescription, coaAccountNo : val.AcquisitionCoaAccountNo});

            this.$store.commit("fixedasset/update_a_department", {M_DepartmentID : val.M_DepartmentID,
                M_DepartmentCode : val.M_DepartmentCode, M_DepartmentName : val.M_DepartmentName});
            this.$store.commit("fixedasset/update_a_department_list", {M_DepartmentID : val.M_DepartmentID,
                M_DepartmentCode : val.M_DepartmentCode, M_DepartmentName : val.M_DepartmentName});

                this.$store.commit("fixedasset/update_a_presentase", {BranchFaPercentID : val.BranchFaPercentID,
                BranchFaPercentType : val.BranchFaPercentType});
            this.$store.commit("fixedasset/update_a_presentase_list", {BranchFaPercentID : val.BranchFaPercentID,BranchFaPercentType : val.BranchFaPercentType});

                this.$store.commit("fixedasset/update_a_fa_age", val.Fa_ClassAgeAsset);


                this.$store.commit("fixedasset/updateRegionalOptions", {S_RegionalID : val.S_RegionalID,S_RegionalName : val.S_RegionalName});
                this.$store.commit("fixedasset/updateXRegional", {S_RegionalID : val.S_RegionalID,S_RegionalName : val.S_RegionalName});
                this.$store.commit("fixedasset/updateBranchOptions", {M_BranchID : val.M_BranchID,M_BranchCode : val.M_BranchCode,M_BranchName : val.M_BranchName});
                this.$store.commit("fixedasset/updateXBranch", {M_BranchID : val.M_BranchID,M_BranchCode : val.M_BranchCode,M_BranchName : val.M_BranchName});

           

        
            this.$store.commit("fixedasset/update_dialog_add_coa", true);
        },
    },
    watch: {
        a_item_search(val) {
            this.aSearchItem(val)
        },
        a_coa_search(val) {
            this.aSearchAcCoa(val)
        },
        a_department_search(val) {
            this.aSearchDepartment(val)
        },
        a_presentase_search(val) {
            this.aSearchPresentase(val)
        },
        e_coa_search_accum_depre(val) {
            this.eSearchAcCoaAccumDepre(val)
        },
    },
};
</script>
