<template>
    <v-layout class="fill-height" column>
        <template>

            <v-dialog v-model="dialogdeletealert" 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>
                                                {{msgalert}}
                                            </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="primary" flat @click="dialogdeletealert = false">
                            Tutup
                        </v-btn>
                        <v-btn color="primary" flat @click="closeDeleteAlert()">
                            Yakin lah
                        </v-btn>
                    </v-card-actions>
                </v-card>
            </v-dialog>

            <v-dialog v-model="dialognotifalert" max-width="30%">
                <v-card>
                    <v-card-title class="headline grey lighten-2 pt-2 pb-2" primary-title>
                        Konfirmasi
                    </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>
                                                {{msgalert}}
                                            </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="primary" flat @click="dialognotifalert = false">
                            Tutup
                        </v-btn>
                        <v-btn color="primary" flat @click="closeNotifAlert()">
                            Yakin lah
                        </v-btn>
                    </v-card-actions>
                </v-card>
            </v-dialog>

        </template>
        <v-dialog v-model="dialogsuccess" persistent max-width="290">
            <v-card>
                <v-card-title color="success" class="headline">Berhasil !</v-card-title>
                <v-card-text>
                    {{msgsuccess}}
                </v-card-text>
                <v-card-actions>
                    <v-spacer></v-spacer>
                    <v-btn color="green darken-1" flat @click="closeDialogSuccess">OK</v-btn>
                </v-card-actions>
            </v-card>
        </v-dialog>
        <v-card class="mb-2 pa-2 searchbox">
            <v-layout>
                <v-text-field class="xs4 ma-1" label="Kel. Pelanggan" placeholder="Cari..." outline v-model="name" hide-details></v-text-field>
                <v-text-field class="xs4 ma-1" label="No. Isu Penagihan" placeholder="Cari..." outline v-model="snorm" hide-details></v-text-field>
                <v-select class="xs3 mini-select ma-1" :items="statuses" item-text="name" return-object v-model="status" label="Status" outline
                    hide-details></v-select>
                <span @click="searchPatient" class="icon-medium-fill-base xs1 white--text success iconsearch-search"></span>
            </v-layout>
        </v-card>
        <v-card>
            <v-layout row>
                <v-flex xs12 pl-2 pr-2 pt-2 pb-2>
                    <v-data-table :headers="headers" :items="receivereferences" :loading="isLoading" :pagination.sync="pagination" 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.F_BillIssuePusatCreated}}</td>
                            <td class="text-xs-left pa-2" v-bind:class="{'amber lighten-4':isSelected(props.item)}" @click="selectMe(props.item)">
                                {{ props.item.F_BillIssuePusatNumber}}
                                <p style="color:#800000" class="mb-0 font-weight-bold caption">{{props.item.F_BillIssuePusatRefNumber}}</p>
                            </td>
                            <td class="text-xs-left pa-2" v-bind:class="{'amber lighten-4':isSelected(props.item)}" @click="selectMe(props.item)">{{ props.item.F_BillIssuePusatDueDate}}
                            <p style="color:#800000" class="mb-0 font-weight-bold caption"> + 7 Hari {{props.item.exduedatex}}</p></td>
                            <td class="text-xs-left pa-2" v-bind:class="{'amber lighten-4':isSelected(props.item)}" @click="selectMe(props.item)">
                            {{props.item.extenddate}}</td>
                            <td class="text-xs-left pa-2" v-bind:class="{'amber lighten-4':isSelected(props.item)}" @click="selectMe(props.item)">
                                {{ props.item.F_BillIssuePusatPIC}}
                                <p style="color:#800000" class="mb-0 font-weight-bold caption">{{props.item.F_BillIssuePusatPICHP}}</p>
                            </td>
                            <td class="text-xs-center pa-2" v-bind:class="{'amber lighten-4':isSelected(props.item)}" @click="selectMe(props.item)">{{ props.item.M_CompanyName}} : {{ props.item.moudesc}}</td>
                            <td class="text-xs-center pa-2" v-bind:class="{'amber lighten-4':isSelected(props.item)}" @click="selectMe(props.item)">{{ convertMoney(props.item.F_BillIssuePusatTotal)}}</td>
                            <td class="text-xs-left pa-2" v-bind:class="{'amber lighten-4':isSelected(props.item)}" @click="selectMe(props.item)">
                                <v-icon style="color:green" title="histori extend" class="text-sm-right" @click="viewBill(props.item)">more_vert</v-icon>
                                <v-icon style="color:#757575" title="cetak" class="text-sm-right" @click="printNote(props.item)">print</v-icon>
                            </td>

                        </template>
                        <template>
                            <div class="text-xs-center">
                                <v-pagination v-model="page" :length="15" :total-visible="7"></v-pagination>
                            </div>
                        </template>
                    </v-data-table>
                </v-flex>
            </v-layout>
        </v-card>
        <one-dialog-alert :status="openalertconfirmation" :msg="msgalertconfirmation" @forget-dialog-alert="forgetAlertConfirmation()"
            @close-dialog-alert="closeAlertConfirmation()"></one-dialog-alert>

        <template>
            <v-layout row justify-center>
                <v-dialog v-model="dialoghistory" persistent max-width="1050px">
                    <v-card>
                        <v-card-title>
                            <span class="headline">HISTORI EXTEND</span><span> &nbsp;[ <span style="color:#2196F3;font-weight: 900;">{{name}} </span>&nbsp;]
                        </v-card-title>
                        <v-layout row wrap>
                            <v-flex xs12 pl-2 pr-2 pt-2 pb-2>
                                <v-data-table :headers="headerhistory" :items="histories" hide-actions class="elevation-1">
                                    <template slot="items" slot-scope="props">
                                        <td class="text-xs-left pa-2" v-html="props.item.tanggal">
                                        </td>
                                        <td class="text-xs-left pa-2" v-html="props.item.F_BillIssuePusatExtendDay">
                                        </td>
                                        <td class="text-xs-left pa-2" v-html="props.item.duedate">
                                        </td>
                                        <td class="text-xs-left pa-2" v-html="props.item.M_StaffName">
                                        </td>
                                        <td class="text-xs-left pa-2" v-html="props.item.F_BillIssuePusatExtendNote">
                                        </td>
                                    </template>
                                </v-data-table>
                            </v-flex>
                        </v-layout>
                        <v-card-actions>
                            <v-spacer></v-spacer>
                            <v-btn color="primary" flat @click="closeViewHistory()">
                                Tutup
                            </v-btn>
                        </v-card-actions>
                    </v-card>
                </v-dialog>
            </v-layout>
        </template>

        <template>
            <v-layout row justify-center>
                <v-dialog v-model="dialogformorder" persistent max-width="600px">
                    <v-card>
                        <v-card-title>
                            <span class="headline">Extend Penagihan [ {{this.xno}} ]</span>
                        </v-card-title>
                        <v-card-text class="pt-0 pb-0">
                            <v-form ref="formcompany">
                                <v-layout row wrap>
                                    <v-flex xs12 pa-2>
                                        <v-layout row>
                                            <v-flex xs12 pa-1>
                                                <v-autocomplete :readonly="xact === 'edit' || xact === 'view'" label="Kelompok Pelanggan*" v-model="xcompany" :items="xcompanies"
                                                    :search-input.sync="search_company" auto-select-first no-filter item-text="M_CompanyName"
                                                    return-object :loading="isLoading" no-data-text="Pilih Kel. Pelanggan">
                                                    <template slot="item" slot-scope="{ item }">
                                                        <v-list-tile-content>
                                                            <v-list-tile-title v-text="item.M_CompanyName"></v-list-tile-title>
                                                        </v-list-tile-content>
                                                    </template>
                                                </v-autocomplete>
                                                <p v-if="checkError('requirexcompany')" class="error pl-2 pr-2" style="color:#fff">Pilih Kel. Pelanggan dulu dong</p>
                                            </v-flex>
                                        </v-layout>
                                        <v-layout row>
                                            <v-flex xs12 pa-1>
                                                <v-select :readonly="xact === 'edit' || xact === 'view'" item-text="M_MouDesc" return-object :items="xmous" v-model="xmou"
                                                    label="Agreement*"></v-select>
                                                <p v-if="checkError('requirexmou')" class="error pl-2 pr-2" style="color:#fff">Pilih Agreement dulu dong</p>
                                            </v-flex>
                                        </v-layout>
                                        <v-layout row>
                                            <v-flex xs12 pa-1>
                                                <v-layout>
                                                    <v-flex xs4>
                                                    <v-text-field readonly v-model="filterComputedDateFormattedStart" @blur="date = deFormatedDate(filterComputedDateFormattedStart)" label="Tgl. Jatuh Tempo + 7 Hari "></v-text-field>
                                                    </v-flex>
                                                    <v-flex xs2>
                                                    </v-flex>
                                                    <v-flex xs4>
                                                        <v-text-field v-model="xextenddueday" @change="changeDueDate()" type="number" label="Extend Jatuh Tempo (Hari)"></v-text-field>
                                                        <p v-if="checkError('requirxextenddueday')" class="error pl-2 pr-2" style="color:#fff">Wajib Diisi</p>
                                                    </v-flex>
                                                </v-layout>
                                            </v-flex>
                                        </v-layout>
                                        <v-layout row>
                                            <v-flex xs12 pa-1>
                                                <v-layout>
                                                    <v-flex xs4>
                                                     <v-menu ref="menusdate" v-model="menusdate" :close-on-content-click="false" :nudge-right="0"
                                                            lazy transition="scale-transition" offset-y full-width max-width="290px"
                                                            min-width="290px">
                                                            <template v-slot:activator="{ on }">
                                                                <v-text-field v-model="startComputedDateFormatted" label="Tgl. Jatuh Tempo Extend" readonly v-on="on"
                                                                    @blur="date = deFormatedDate(startComputedDateFormatted)"></v-text-field>
                                                            </template>
                                                            <v-date-picker :min="new Date().toISOString().substr(0, 10)" v-model="xsdate" no-title @change="changeDueDay()" @input="menusdate = false"></v-date-picker>
                                                            <p v-if="checkError('requirexsdate')" class="error pl-2 pr-2" style="color:#fff">Tanggal jatuh tempo</p>
                                                    
                                                    </v-flex>
                                                    <v-flex xs2>
                                                    </v-flex>
                                                    <v-flex xs4>
                                                      </v-flex>
                                                </v-layout>
                                            </v-flex>
                                        </v-layout>
                                        <v-layout row>
                                            <v-flex xs12 pa-1>
                                                <v-textarea v-model="xextendnote" label="Alasan Extend"></v-textarea>
                                                <p v-if="checkError('requirxextendnote')" class="error pl-2 pr-2" style="color:#fff">Wajib Diisi</p>

                                            </v-flex>
                                        </v-layout>
                                    </v-flex>
                                </v-layout>
                        </v-card-text>
                        <v-card-actions>
                            <v-spacer></v-spacer>
                            <v-btn color="orange darken-1" flat @click="updateDialogFormOrder()">Tutup</v-btn>
                            <v-btn v-if="xact === 'edit'" color="orange darken-1" flat @click="updateFormPerusahaan()">Simpan Extend</v-btn>
                        </v-card-actions>
                        </v-form>
                    </v-card>
                </v-dialog>
            </v-layout>
        </template>

        <one-dialog-print :title="printtitle" :width="printwidth" :height="550" :status="openprintnote" :urlprint="urlprintnote"
            @close-dialog-print="openprintnote = false"></one-dialog-print>

    </v-layout>
</template>

<style scoped>
    .searchbox .v-input.v-text-field .v-input__slot {
        min-height: 60px;
    }

    .searchbox .v-btn {
        min-height: 60px;
    }

    table.v-table tbody td,
    table.v-table tbody th {
        height: 40px;
    }

    table.v-table thead tr {
        height: 40px;
    }
</style>

<script>
    module.exports = {
        components: {
            'one-dialog-info': httpVueLoader('../../common/oneDialogInfo.vue'),
            'one-dialog-alert': httpVueLoader('../../common/oneDialogAlert.vue'),
            'one-dialog-print': httpVueLoader('../../common/oneDialogPrintX.vue')
        },
        mounted() {
            this.$store.dispatch("receivereference/getsexreg")
            this.$store.dispatch("receivereference/search", {
                name: this.name,
                snorm: this.snorm,
                status: this.status.value,
                lastid: -1
            })
        },
        methods: {
            checkError(value) {
                var errors = this.$store.state.receivereference.errors
                if (errors.includes(value)) {
                    return true
                } else {
                    return false
                }
            },
            isSelected(p) {
                return p.F_BillIssuePusatID == this.$store.state.receivereference.selected_receivereference
                    .F_BillIssuePusatID
            },
            convertMoney(money) {
                return one_money(money)
            },
            printNote(val) {
                this.printwidth = 600
                this.printtitle = ""
                let user = one_user()
                var rpt = 'rpt_t_009_pusat'
                if (val.note_amount < 0)
                    rpt = 'rpt_t_009_pusat'
                this.urlprintnote = "/birt/run?__report=report/one/fo/" + rpt + ".rptdesign&__format=pdf&username=" +
                    user.M_UserUsername + "&PID=" + val.F_BillIssuePusatID
                this.$store.commit("receivereference/update_open_print_note", true)
            },
            searchPatient() {
                this.$store.dispatch("receivereference/search", {
                    name: this.name,
                    snorm: this.snorm,
                    status: this.status.value,
                    lastid: -1
                })
            },

            selectMe(pat) {
                if (this.$store.state.receivereference.no_save == 0) {
                    this.$store.commit("receivereference/update_selected_receivereference", pat)
                    this.$store.commit("receivereference/update_act_send", pat.T_ReceiveReferenceHeaderIsSent)
                    this.$store.commit("receivereference/update_init_sdate", pat.startdate)
                    this.$store.dispatch("receivereference/getpatient", {
                        id: pat.F_BillIssuePusatID,
                        mouid: pat.F_BillIssuePusatM_MouID,
                        startdate: pat.startdate,
                        enddate: moment().format("YYYY-MM-DD")
                    })
                    this.$store.commit("receivereference/update_statuss", pat.statuss)
                } else {
                    this.$store.commit("receivereference/update_open_alert_confirmation", true)
                }

            },
            closeAlertConfirmation() {
                this.$store.commit("receivereference/update_open_alert_confirmation", false)
            },
            forgetAlertConfirmation() {
                this.$store.commit("receivereference/update_no_save", 0)
                this.$store.commit("receivereference/update_open_alert_confirmation", false)
            },
            updateAlert_success(val) {
                this.$store.commit("receivereference/update_alert_success", val)
            },
            updateDialogFormOrder() {
                this.$store.commit("receivereference/update_dialog_form_order", false)
            },
            updateDialogStatusOrder() {
                this.$store.commit("receivereference/update_dialog_status_order", false)
            },
            setNewOrder() {
                this.$store.commit("receivereference/update_selected_receivereference", {})
                this.$store.commit("receivereference/update_act_comp", 'new')
                this.$store.commit("receivereference/update_dialog_form_order", true)
                this.xid = 0
                this.xno = ''
                this.xtotal = 0
                this.xcompany = {}

                this.$store.commit("receivereference/update_mous", [{}])
                this.xmou = {}
                this.xdueday = 0
                var dueDate = moment(new Date(new Date().getTime() + (this.xdueday * 24 * 60 * 60 * 1000))).format(
                    'YYYY-MM-DD')
                this.xsdate = dueDate
                this.xnote = ''
                this.$store.dispatch("receivereference/getpatient", {
                    id: 0,
                    mouid: 0
                })
            },
            changeDueDay() {
                var start = moment(this.xduedate).format('YYYY-MM-DD');
                var end = moment(this.xsdate);
                var xday = end.diff(start, "days")
                this.xextenddueday = xday
                if(xday < 1){
                    alert('Tanggal extend kurang dari tanggal jatuh tempo')
                    this.xextenddueday = 0
                    this.xsdate = ''
                }
            },
            changeDueDate() { 
                var tanggal = new Date(this.billcreated)
                var hari = parseInt(this.xdueday) + parseInt(this.xextenddueday) + 7
                //alert(hari)
                var dueDate = moment(new Date(new Date(tanggal).getTime() + (hari * 24 * 60 * 60 * 1000))).format(
                    'YYYY-MM-DD')
                var nDate = moment(new Date()).format('YYYY-MM-DD')
                if(dueDate < nDate){
                    alert('tanggal masih kurang hari ini')
                    this.xextenddueday = 0
                    this.xsdate = ''
                }else{    
                this.xsdate = dueDate
                } 
                 
                //alert(dueDate)
            },
            setStatusOrder() {
                this.$store.commit("receivereference/update_selected_receivereference", {})
                this.$store.commit("receivereference/update_dialog_status_order", true)
                this.search_company = ''
            },
            saveFormPerusahaan() {
                this.$store.commit("receivereference/update_errors", [])
                var errors = this.$store.state.receivereference.errors
                if (this.xextenddueday == 0) {
                    errors.push("requirxextenddueday")
                }
                if (_.isEmpty(this.xextendnote)) {
                    errors.push("requirxextendnote")
                }

                if (errors.length === 0) {
                    if (this.in_saving) return;
                    this.in_saving = true;
                    this.$store.dispatch("receivereference/newreceivereference", {
                        companyid: this.xcompany.M_CompanyID,
                        mouid: this.xmou.M_MouID,
                        sdate: this.xsdate,
                        note: this.xnote,
                        day: this.xdueday,
                        picname: this.xpicname,
                        pichp: this.xpichp
                    })
                }
            },
            editBill(data) {
                this.xextenddueday = 0
                this.xextendnote = ''
                this.xid = data.F_BillIssuePusatID
                this.xmouid = data.mouid
                this.xno = data.F_BillIssuePusatNumber
                this.xpicname = data.F_BillIssuePusatPIC
                this.xpichp = data.F_BillIssuePusatPICHP
                this.xtotal = data.F_BillIssuePusatTotal
                //this.xduedate = data.duedatex
                this.$store.commit("receivereference/update_companies", [{
                    M_CompanyID: data.M_CompanyID,
                    M_CompanyName: data.M_CompanyName
                }])
                this.xcompany = {
                    M_CompanyID: data.M_CompanyID,
                    M_CompanyName: data.M_CompanyName
                }

                this.$store.commit("receivereference/update_mous", [{
                    M_MouID: data.M_MouID,
                    M_MouDesc: data.M_MouDesc
                }])
                this.xmou = {
                    M_MouID: data.M_MouID,
                    M_MouDesc: data.M_MouDesc
                }
                this.xdueday = data.F_BillIssuePusatAgingDay
                this.xsdate = data.sdate
                this.xnote = data.F_BillIssuePusatNote
                
                this.billcreated = moment(data.billcreated).format('YYYY-MM-DD')
                //var tanggal = moment(data.billcreated).format('YYYY-MM-DD')
                //var hari = parseInt(this.xdueday) + 7
                //var createDate = moment(new Date(new Date(tanggal).getTime() + (hari * 24 * 60 * 60 * 1000))).format(
                 //   'YYYY-MM-DD')
                   
                this.xduedate = data.exduedate
                
                this.$store.commit("receivereference/update_act_comp", 'edit')
                this.$store.commit("receivereference/update_dialog_form_order", true)
            },
            viewBill(data) {
                this.$store.dispatch("receivereference/history", {
                    id: data.F_BillIssuePusatID
                })
                this.$store.commit("receivereference/update_dialog_history", true)
            },
            updateFormPerusahaan() {
                this.$store.commit("receivereference/update_errors", [])
                var errors = this.$store.state.receivereference.errors
                if (this.xextenddueday == 0) {
                    errors.push("requirxextenddueday")
                }
                if (_.isEmpty(this.xextendnote)) {
                    errors.push("requirxextendnote")
                }
                if (errors.length === 0) {
                    this.$store.dispatch("receivereference/editbill", {
                        id: this.xid,
                        note: this.xextendnote,
                        day: this.xextenddueday,
                        mouid: this.xmouid,
                        duedate: this.xsdate
                    })
                }
            },
            deleteBill(data) {
                this.xid = data.F_BillIssuePusatID
                var xdata = {
                    id: data.F_BillIssuePusatID,
                    name: data.F_BillIssuePusatNumber
                }
                this.msgalert = "Yakin, Mau Hapus No. Isu Penagihan " + data.F_BillIssuePusatNumber + "  ?"
                this.dialogdeletealert = true
            },
            notifBill(data) {
                this.xid = data.F_BillIssuePusatID
                var xdata = {
                    id: data.F_BillIssuePusatID,
                    name: data.F_BillIssuePusatNumber
                }
                this.msgalert = "Yakin, Mau Kirim Notifikasi No. Isu Penagihan " + data.F_BillIssuePusatNumber +
                    " ke  " +
                    data.F_BillIssuePusatPIC + " [" + data.F_BillIssuePusatPICHP + "]"
                this.dialognotifalert = true
            },
            closeDeleteAlert() {
                this.$store.dispatch("receivereference/deletebill", {
                    id: this.xid
                })
                this.dialogdeletealert = false
            },
            closeNotifAlert() {
                this.$store.dispatch("receivereference/notifbill", {
                    id: this.xid
                })
                this.dialognotifalert = false
            },
            thr_search_company: _.debounce(function () {
                this.$store.dispatch("receivereference/searchcompany", this.search_company)
            }, 2000),
            closeDialogSuccess() {
                let arrreceivereference = this.$store.state.receivereference.receivereferences
                var idx = _.findIndex(arrreceivereference, item => item.F_BillIssuePusatID === this.$store.state
                    .receivereference.last_id)
                console.log(idx)
                this.$store.dispatch("receivereference/search", {
                    name: this.name,
                    snorm: this.snorm,
                    status: this.status.value,
                    lastid: -1
                })
                this.$store.commit("receivereference/update_dialog_success", false)
            },
            closeViewHistory() {
                this.$store.commit("receivereference/update_dialog_history", false)
            },
            formatDate(date) {
                if (!date) return null

                const [year, month, day] = date.split('-')
                return `${day}-${month}-${year}`
            },
            deFormatedDate(date) {
                if (!date) return null

                const [day, month, year] = date.split('-')
                return `${year}-${month.padStart(2, '0')}-${day.padStart(2, '0')}`
            },
            formatDueDate(date) {
                if (!date) return null

                const [year, month, day] = date.split('-')
                return `${day}-${month}-${year}`
            },
            deFormatedDueDate(date) {
                if (!date) return null

                const [day, month, year] = date.split('-')
                return `${year}-${month.padStart(2, '0')}-${day.padStart(2, '0')}`
            }
        },
        computed: {
            dialogsuccess: {
                get() {
                    return this.$store.state.receivereference.dialog_success
                },
                set(val) {
                    this.$store.commit("receivereference/update_dialog_success", val)
                }
            },
            msgsuccess() {
                return this.$store.state.receivereference.msg_success
            },
            snackbar: {
                get() {
                    return this.$store.state.receivereference.alert_success
                },
                set(val) {
                    this.$store.commit("receivereference/update_alert_success", val)
                }
            },
            openprintnote: {
                get() {
                    return this.$store.state.receivereference.open_print_note
                },
                set(val) {
                    this.$store.commit("receivereference/update_open_print_note", false)
                }
            },
            isLoading() {
                return this.$store.state.receivereference.search_status == 1
            },
            statuses() {
                return this.$store.state.receivereference.statuses
            },
            status: {
                get() {
                    return this.$store.state.receivereference.selected_status
                },
                set(val) {
                    this.$store.commit("receivereference/update_selected_status", val)
                }
            },
            xact() {
                return this.$store.state.receivereference.act_comp
            },
            receivereferences() {
                return this.$store.state.receivereference.receivereferences
            },
            histories() {
                return this.$store.state.receivereference.histories
            },
            openalertconfirmation: {
                get() {
                    return this.$store.state.receivereference.open_alert_confirmation
                },
                set(val) {
                    this.$store.commit("receivereference/update_open_alert_confirmation", val)
                }
            },
            dialogformorder() {
                return this.$store.state.receivereference.dialog_form_order
            },
            dialoghistory() {
                return this.$store.state.receivereference.dialog_history
            },
            dialogstatusorder() {
                return this.$store.state.receivereference.dialog_status_order
            },
            xdate: {
                get() {
                    return this.$store.state.receivereference.date
                },
                set(val) {
                    this.$store.commit("receivereference/update_date", val)
                }
            },
            xnote: {
                get() {
                    return this.$store.state.receivereference.note
                },
                set(val) {
                    this.$store.commit("receivereference/update_note", val)
                }
            },
            xextendnote: {
                get() {
                    return this.$store.state.receivereference.extendnote
                },
                set(val) {
                    this.$store.commit("receivereference/update_extendnote", val)
                }
            },
            xdueday: {
                get() {
                    return this.$store.state.receivereference.dueday
                },
                set(val) {
                    this.$store.commit("receivereference/update_dueday", val)
                }
            },
            xextenddueday: {
                get() {
                    return this.$store.state.receivereference.extenddueday
                },
                set(val) {
                    this.$store.commit("receivereference/update_extenddueday", val)
                }
            },
            xpicname: {
                get() {
                    return this.$store.state.receivereference.picname
                },
                set(val) {
                    this.$store.commit("receivereference/update_picname", val)
                }
            },
            xpichp: {
                get() {
                    return this.$store.state.receivereference.pichp
                },
                set(val) {
                    this.$store.commit("receivereference/update_pichp", val)
                }
            },
            xcompanies() {
                return this.$store.state.receivereference.companies
            },
            xcompany: {
                get() {
                    return this.$store.state.receivereference.company
                },
                set(val) {
                    this.$store.commit("receivereference/update_company", val)
                    this.$store.dispatch("receivereference/getmou", this.$store.state.receivereference.company)
                }
            },
            xmous() {
                return this.$store.state.receivereference.mous
            },
            xmou: {
                get() {
                    return this.$store.state.receivereference.mou
                },
                set(val) {
                    this.$store.commit("receivereference/update_mou", val)
                    this.$store.commit("receivereference/update_dueday", val.M_MouAgingDay)
                    this.$store.commit("receivereference/update_picname", val.M_MouPicBillName)
                    this.$store.commit("receivereference/update_pichp", val.M_MouPicBillHandphone)
                }
            },
            filterComputedDateFormattedStart() {
                return this.formatDueDate(this.xduedate)
            },
            xduedate: {
                get() {
                    return this.$store.state.receivereference.duedate
                },
                set(val) {
                    this.$store.commit("receivereference/update_duedate", val)
                }
            },
            startComputedDateFormatted() {
                return this.formatDate(this.xsdate)
            },
            xsdate: {
                get() {
                    return this.$store.state.receivereference.sdate
                },
                set(val) {
                    this.$store.commit("receivereference/update_sdate", val)
                }
            },
            xstatuss() {
                return this.$store.state.receivereference.statuss
            },
            in_saving: {
                get() {
                    return this.$store.state.receivereference.in_saving
                },
                set(val) {
                    this.$store.commit("receivereference/update_in_saving", val)
                }
            }
        },
        data() {
            return {
                msgalertconfirmation: "Perubahan yang telah dilakukan belum disimpan dong !",
                items: [],
                xid: 0,
                xmouid: 0,
                xno: '',
                xtotal: 0,
                name: '',
                snorm: '',
                msgalert: "",
                billcreated: '',
                dialogdeletealert: false,
                dialognotifalert: false,
                search_company: '',
                menusdate: false,
                urlprintnote: '',
                printtitle: '',
                printwidth: '80%',
                ndate: moment(new Date()).format('YYYY-MM-DD'),
                date: new Date().toISOString().substr(0, 10),
                disabledDates: {
                    to: new Date(Date.now() - 8640000)
                },
                page: 1,
                headerhistory: [{
                        text: "WAKTU EXTEND",
                        align: "center",
                        sortable: false,
                        value: "mr",
                        width: "7%",
                        class: "pa-2 orange lighten-3 white--text"
                    },
                    {
                        text: "EXTEND JATUH TEMPO (HARI)",
                        align: "center",
                        sortable: false,
                        value: "mr",
                        width: "7%",
                        class: "pa-2 orange lighten-3 white--text"
                    },
                    {
                        text: "TANGGAL JATUH TEMPO",
                        align: "center",
                        sortable: false,
                        value: "mr",
                        width: "10%",
                        class: "pa-2 orange lighten-3 white--text"
                    },
                    {
                        text: "STAFF",
                        align: "center",
                        sortable: false,
                        value: "mr",
                        width: "15%",
                        class: "pa-2 orange lighten-3 white--text"
                    },
                    {
                        text: "ALASAN EXTEND",
                        align: "center",
                        sortable: false,
                        value: "mr",
                        width: "20%",
                        class: "pa-2 orange lighten-3 white--text"
                    }
                ],
                headers: [{
                        text: "TGL. PENERIMAAN",
                        align: "center",
                        sortable: false,
                        value: "mr",
                        width: "7%",
                        class: "pa-2 orange lighten-3 white--text"
                    },
                    {
                        text: "NO. PENAGIHAN",
                        align: "center",
                        sortable: false,
                        value: "mr",
                        width: "7%",
                        class: "pa-2 orange lighten-3 white--text"
                    },
                    {
                        text: "TGL. JATUH TEMPO",
                        align: "center",
                        sortable: false,
                        value: "mr",
                        width: "10%",
                        class: "pa-2 orange lighten-3 white--text"
                    }, 
                    {
                        text: "TGL. JATUH TEMPO (EXTEND)",
                        align: "center",
                        sortable: false,
                        value: "mr",
                        width: "10%",
                        class: "pa-2 orange lighten-3 white--text"
                    },
                    {
                        text: "PIC",
                        align: "center",
                        sortable: false,
                        value: "mr",
                        width: "10%",
                        class: "pa-2 orange lighten-3 white--text"
                    },
                    {
                        text: "KEL.PELANGGAN/AGREEMENT",
                        align: "center",
                        sortable: false,
                        value: "lab",
                        width: "40%",
                        class: "pa-2 orange lighten-3 white--text"
                    },
                    {
                        text: "TOTAL PENAGIHAN",
                        align: "center",
                        sortable: false,
                        value: "name",
                        width: "7%",
                        class: "pa-2 orange lighten-3 white--text"
                    },
                    {
                        text: "AKSI",
                        align: "center",
                        sortable: false,
                        value: "name",
                        width: "15%",
                        class: "pa-2 orange lighten-3 white--text"
                    }
                ],
                pagination: {
                    descending: true,
                    page: 1,
                    rowsPerPage: 5,
                    sortBy: 'F_BillIssuePusatNumber',
                    totalItems: this.$store.state.receivereference.total_receivereferences
                },
                statuss: [{
                        waktu: '16-07-2019 10:00',
                        status: 'Order Dibuat',
                        user: 'Nagita Slavina'
                    },
                    {
                        waktu: '16-07-2019 11:00',
                        status: 'Order Dikirim',
                        user: 'Nagita Slavina'
                    },
                    {
                        waktu: '16-07-2019 12:00',
                        status: 'Order dikonfirmasi',
                        user: 'Chacha Frederica'
                    },
                    {
                        waktu: '16-07-2019 13:00',
                        status: 'Telah dibuat Surat Jalan',
                        user: 'Chacha Frederica'
                    },
                    {
                        waktu: '16-07-2019 14:00',
                        status: 'Kurir akan mengambil sampel',
                        user: 'Satria Subiantoro'
                    }
                ]
            };
        },
        watch: {
            search_company(val, old) {
                if (val == old) return
                if (!val) return
                if (val.length < 1) return
                if (this.$store.state.receivereference.update_autocomplete_status == 1) return
                this.thr_search_company()
            }
        }
    }
</script>