<template>
    <v-dialog v-model="dialog_verifikasi" persistent width="90vw">
        <v-card>
            <v-card-title class="headline grey lighten-2" primary-title>
                VERIFIKASI PERUBAHAN ACCOUNT JURNAL
            </v-card-title>
            <v-card-text style="max-height: 80vh;">
                <v-layout row wrap>
                    <v-flex xs6 pa-1 pr-3>
                        <div class="font-weight-bold">Company Name</div>
                        <div class="pa-2 grey lighten-2">
                            {{ selected_jurnal.M_BranchCompanyName  }}
                        </div>
                    </v-flex>
                    <v-flex xs6 pa-1 pl-3>
                        <div class="font-weight-bold">Journal</div>
                        <div class="pa-2 grey lighten-2">
                            {{ selected_jurnal.jurnalTitle  }}
                        </div>
                    </v-flex>
                    <v-flex xs6 pa-1 pr-3>
                        <div class="font-weight-bold">Regional</div>
                        <div class="pa-2 grey lighten-2">
                            {{ selected_jurnal.S_RegionalName  }}
                        </div>
                    </v-flex>
                    <v-flex xs6 pa-1 pl-3>
                        <div class="font-weight-bold">Journal Date</div>
                        <div class="pa-2 grey lighten-2">
                            {{ selected_jurnal.jurnalDate  }}
                        </div>
                    </v-flex>
                    <v-flex xs6 pa-1 pr-3>
                        <div class="font-weight-bold">Branch</div>
                        <div class="pa-2 grey lighten-2">
                            {{ selected_jurnal.M_BranchName }}
                        </div>
                    </v-flex>
                    <v-flex xs6 pa-1 pl-3>
                        <div class="font-weight-bold">Journal Type</div>
                        <div class="pa-2 grey lighten-2">
                            {{ selected_jurnal.JurnalTypeName }}
                        </div>
                    </v-flex>
                </v-layout>
                <v-divider class="my-2"></v-divider>
                <v-layout row wrap class="mt-2">
                    <v-flex xs6 pr-1>
                        <h4>Detail Account Sebelum Diubah</h4>
                        <v-data-table
                            :headers="headers" hide-actions class="elevation-1"
                            :items="selected_jurnal_detail.changeBefore"
                        >
                            <template slot="items" slot-scope="props">
                                <tr>
                                    <td class="text-xs-center pa-2">
                                        {{ props.item.coaAccountNo }}
                                    </td>
                                    <td class="text-xs-left pa-2">
                                        {{ props.item.coaDescription }}
                                    </td>
                                    <td class="text-xs-left pa-2">
                                        {{ props.item.jurnalAddOnValue }}
                                    </td>
                                    <td class="text-xs-right pa-2">
                                        {{ formatCurrency(props.item.jurnalTxDebit) }}
                                    </td>
                                    <td class="text-xs-right pa-2">
                                        {{ formatCurrency(props.item.jurnalTxCredit) }}
                                    </td>
                                </tr>
                            </template>
                            <template v-slot:footer>
                                <tr>
                                    <td colspan="3" class="font-weight-bold pa-2">TOTAL</td>
                                    <td class="text-xs-right pa-2 font-weight-bold">
                                        {{ formatCurrency(summary_jurnal_detail.total_debit) }}
                                    </td>
                                    <td class="text-xs-right pa-2 font-weight-bold">
                                        {{ formatCurrency(summary_jurnal_detail.total_kredit) }}
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="4" class="font-weight-bold pa-2">BALANCE</td>
                                    <td class="text-xs-right pa-2 font-weight-bold">
                                        {{ formatCurrency(summary_jurnal_detail.balance) }}
                                    </td>
                                </tr>
                            </template>
                        </v-data-table>
                    </v-flex>
                    <v-flex xs6 pl-1>
                        <h4>Detail Account Setelah Diubah</h4>
                        <v-data-table
                            :headers="headers" hide-actions class="elevation-1"
                            :items="selected_jurnal_detail.changeAfter"
                        >
                            <template slot="items" slot-scope="props">
                                <tr>
                                    <td class="text-xs-center pa-2">
                                        {{ props.item.coaAccountNo }}
                                    </td>
                                    <td class="text-xs-left pa-2">
                                        {{ props.item.coaDescription }}
                                    </td>
                                    <td class="text-xs-left pa-2">
                                        {{ props.item.jurnalAddOnValue }}
                                    </td>
                                    <td class="text-xs-right pa-2">
                                        {{ formatCurrency(props.item.jurnalTxDebit) }}
                                    </td>
                                    <td class="text-xs-right pa-2">
                                        {{ formatCurrency(props.item.jurnalTxCredit) }}
                                    </td>
                                </tr>
                            </template>
                            <template v-slot:footer>
                                <tr>
                                    <td colspan="3" class="font-weight-bold pa-2">TOTAL</td>
                                    <td class="text-xs-right pa-2 font-weight-bold">
                                        {{ formatCurrency(summary_jurnal_detail.total_debit) }}
                                    </td>
                                    <td class="text-xs-right pa-2 font-weight-bold">
                                        {{ formatCurrency(summary_jurnal_detail.total_kredit) }}
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="4" class="font-weight-bold pa-2">BALANCE</td>
                                    <td class="text-xs-right pa-2 font-weight-bold">
                                        {{ formatCurrency(summary_jurnal_detail.balance) }}
                                    </td>
                                </tr>
                            </template>
                        </v-data-table>
                    </v-flex>
                </v-layout>
            </v-card-text>
            <v-card-actions>
                <v-spacer></v-spacer>
                <v-btn 
                    dark small color="error"
                    @click="batalVerifikasi()"
                >BATAL</v-btn>
                <v-btn
                    v-if="selected_jurnal.JurnalRequestEditStatusEdit != 'approved'"
                    dark small color="primary"
                    @click="verifikasi()"
                >VERIFIKASI</v-btn>
            </v-card-actions>
        </v-card>
    </v-dialog>
</template>

<script>
module.exports = {
    mounted() {},
    data() {
        return {
            headers: [
                {
                    text: "AKUN", align: "center", sortable: false,
                    value: "action", width: "15%", class: "pa-2 pl-2 blue lighten-3 white--text",
                },
                {
                    text: "DESKRIPSI", align: "center", sortable: false,
                    value: "mr", width: "30%", class: "pa-2 blue lighten-3 white--text",
                },
                {
                    text: "INFO", align: "center", sortable: false,
                    value: "lab", width: "15%", class: "pa-2  blue lighten-3 white--text",
                },
                {
                    text: "DEBIT", align: "center", sortable: false,
                    value: "lab", width: "20%", class: "pa-2 blue lighten-3 white--text",
                },
                {
                    text: "CREDIT", align: "center", sortable: false,
                    value: "lab", width: "20%", class: "pa-2 blue lighten-3 white--text",
                }
            ]
        }
    },
    computed: {
        dialog_verifikasi: {
            get() {
                return this.$store.state.journal.dialog_verifikasi
            },
            set(val) {
                this.$store.commit("journal/update_dialog_verifikasi", val)
            }
        },
        selected_jurnal: {
            get() {
                return this.$store.state.journal.selected_jurnal
            },
            set(val) {
                this.$store.commit("journal/update_selected_jurnal", val)
            }
        },
        selected_jurnal_detail: {
            get() {
                return this.$store.state.journal.selected_jurnal_detail
            },
            set(val) {
                this.$store.commit("journal/update_selected_jurnal_detail", val)
            }
        },
        summary_jurnal_detail: {
            get() {
                return this.$store.state.journal.summary_jurnal_detail
            },
            set(val) {
                this.$store.commit("journal/update_summary_jurnal_detail", val)
            }
        }
    },
    methods: {
        formatCurrency(amount) {
            const price = parseFloat(amount)
            const IDR = new Intl.NumberFormat("id-ID", {
                style: "currency",
                currency: "IDR"
            })
            return `${IDR.format(price)}`
        },
        batalVerifikasi() {
            this.summary_jurnal_detail = {
                total_debit: 0,
                total_kredit: 0,
                balance: 0
            }
            this.selected_jurnal = {}
            this.selected_jurnal_detail = {}
            this.dialog_verifikasi = false
        },
        verifikasi() {
            this.$store.dispatch("journal/verifEditJurnal", 'approved')
        }
    },
    watch: {
        
    },
}
</script>