<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-layout row>
                                            <v-flex xs12 pa-1>
                                                <v-textarea v-model="xcancelnote" label="Alasan Batal"></v-textarea>
                                                <p v-if="checkError('requirecancelnote')" class="error pl-2 pr-2" style="color:#fff">Wajib Diisi</p>

                                            </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" success-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-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">
                                KONFIRMASI
                            </v-btn>
                        </v-card-actions>
                </v-card>
            </v-dialog>

            <v-dialog v-model="dialogsendalert" max-width="30%">
                <v-card>
                    <v-card-title class="headline grey lighten-2 pt-2 pb-2" success-title>
                        Kirim
                    </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-divider></v-divider>
                        <v-card-actions>
                            <v-spacer></v-spacer>
                            <v-btn color="primary" flat @click="dialogsendalert = false">
                                TUTUP
                            </v-btn>
                            <v-btn color="primary" flat @click="closeSendAlert">
                                KIRIM
                            </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-dialog v-model="dialogmou" persistent max-width="900">
            <v-card>
                <v-layout row class="scroll-container" style="max-height:600px;overflow: auto;">
                    <v-flex xs12 pl-2 pr-2 pt-2 pb-2>
                        <v-data-table :headers="headersmou" :items="listmous" :loading="isLoading" :pagination.sync="pagination" class="elevation-1">
                            <template slot="items" slot-scope="props">
                                <td class="text-xs-left pa-2">{{ props.item.T_OrderNumber}}</td>
                                <td class="text-xs-left pa-2">{{ props.item.pasienname}}</td>
                                <td class="text-xs-center pa-2">{{ props.item.waktu}}</td>
                                <td class="text-xs-center pa-2">{{ props.item.testname}}</td>
                                <td class="text-xs-center pa-2">{{ props.item.total}}</td>

                            </template>
                            <template>
                            </template>
                        </v-data-table>
                    </v-flex>
                </v-layout>
                <v-card-actions>
                    <v-spacer></v-spacer>
                    <v-btn color="green darken-1" flat @click="dialogmou = false">TUTUP</v-btn>
                </v-card-actions>
            </v-card>

        </v-dialog>
        <v-card class="mb-2 pa-2 searchbox">
            <v-layout>
                <v-menu class="xs3 pr-2" v-model="menufilterdatestart" :close-on-content-click="false" :nudge-right="40" lazy transition="scale-transition"
                    offset-y full-width max-width="290px" min-width="290px">
                    <template v-slot:activator="{ on }">
                        <v-text-field class="mt-1" v-model="filterComputedDateFormattedStart" label="Tanggal Awal" outline readonly v-on="on" @blur="date = deFormatedDate(filterComputedDateFormattedStart)"></v-text-field>
                    </template>
                    <v-date-picker v-model="init_sdate" @change="searchPatient" no-title @input="menufilterdatestart = false"></v-date-picker>
                </v-menu>
                <v-menu class="xs3 pl-2" v-model="menufilterdateend" :close-on-content-click="false" :nudge-right="40" lazy transition="scale-transition"
                    offset-y full-width max-width="290px" min-width="290px">
                    <template v-slot:activator="{ on }">
                        <v-text-field class="mt-1" v-model="filterComputedDateFormattedEnd" label="Tanggal Akhir" outline readonly v-on="on" @blur="date = deFormatedDate(filterComputedDateFormattedEnd)"></v-text-field>
                    </template>
                    <v-date-picker v-model="init_edate" @change="searchPatient" no-title @input="menufilterdateend = false"></v-date-picker>
                </v-menu>

                <v-text-field class="xs4 ma-1" label="Nama / Nomor" @change="searchPatient" placeholder="Cari..." outline v-model="name" 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>
            </v-layout>
        </v-card>
        <v-card>
            <v-layout row 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="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.hsdate}}
                            </td>
                            <td class="text-xs-left pa-2" v-bind:class="{'amber lighten-4':isSelected(props.item)}" @click="selectMe(props.item)">
                                {{ props.item.T_TransactionNumbering}}
                                <p style="color:#800000" class="mb-0 font-weight-bold caption">Nomor SJ : {{ props.item.HS_DeliveryOrderNumber}}</p>
                                <p style="color:#800000" class="mb-0 font-weight-bold caption">Petugas : {{ props.item.M_StaffName}}</p>
                            </td>
                            <td class="text-xs-center pa-2" v-bind:class="{'amber lighten-4':isSelected(props.item)}" @click="selectMe(props.item)">{{ props.item.pasienname}}
                            </td>
                            <td class="text-xs-center pa-2" v-bind:class="{'amber lighten-4':isSelected(props.item)}" @click="selectMe(props.item)">{{ props.item.address}}
                            </td>
                            <td class="text-xs-center pa-2" v-bind:class="{'amber lighten-4':isSelected(props.item)}" @click="selectMe(props.item)">{{ convertMoney(props.item.total)}}</td>
                            <td class="text-xs-center pa-2" v-bind:class="{'amber lighten-4':isSelected(props.item)}" @click="selectMe(props.item)">
                            <v-btn class="xs3 ma-1" v-if="props.item.status !== ''" color="green">{{ props.item.status}}</v-btn></td>
                            
                            <td class="text-xs-left pa-2" v-bind:class="{'amber lighten-4':isSelected(props.item)}" @click="selectMe(props.item)">
                            <v-btn class="xs3 ma-1" v-if="props.item.HS_DeliveryOrderDetailStatus === 'N' && props.item.HS_DeliveryOrderStatus !== 'S'" @click="viewBill(props.item)" color="info">OPER</v-btn>
                            <v-btn class="xs3 ma-1" v-if="props.item.T_TransactionIsDeliveryOrder === 'N'" @click="addBill(props.item)" color="info">TAMBAHKAN KE SJ</v-btn>
                            <v-btn class="xs3 ma-1" v-if="props.item.T_TransactionIsDeliveryOrder === 'N'" @click="updateBill(props.item)" color="orange">UBAH JADWAL</v-btn>
                            <v-btn class="xs3 ma-1" v-if="props.item.T_TransactionIsDeliveryOrder === 'N'" @click="deleteBill(props.item)" color="red">BATAL</v-btn>
                            <v-btn class="xs3 ma-1" @click="viewDetail(props.item)" color="grey">INFO</v-btn>
                            </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="dialogformorder" persistent max-width="600px">
                    <v-card>
                        <v-card-title>
                            <span class="headline">Surat Jalan HS [ {{this.xno}} ]</span>
                        </v-card-title>
                        <v-card-text class="pt-0 pb-0">
                            <v-form ref="formstaff">
                                <v-layout row wrap>
                                    <v-flex xs12 pa-2>
                                        <v-layout row>
                                            <v-flex xs12 pa-1>
                                                <v-menu class="xs3 pr-2" v-model="menudatestart" :close-on-content-click="false" :nudge-right="40" lazy transition="scale-transition"
                                                    offset-y full-width max-width="290px" min-width="290px">
                                                    <template v-slot:activator="{ on }">
                                                        <v-text-field class="mt-1" v-model="ComputedDateFormattedStart" label="Tanggal Home Service" readonly v-on="on" @blur="date = deFormatedDate(ComputedDateFormattedStart)"></v-text-field>
                                                    </template>
                                                    <v-date-picker v-model="init_idate" no-title @input="menudatestart = false"></v-date-picker>
                                                </v-menu>
                                                <p v-if="checkError('requirexsdate')" class="error pl-2 pr-2" style="color:#fff">Pilih Tanggal HS dulu dooong</p>
                                            </v-flex>
                                        </v-layout>
                                        <v-layout row>
                                            <v-flex xs12 pa-1>
                                                <v-autocomplete :readonly="xact === 'edit' || xact === 'view'" label="Petugas Lama*" v-model="xstaff" :items="xcompanies" :search-input.sync="search_staff"
                                                    auto-select-first no-filter item-text="M_StaffName" return-object :loading="isLoading"
                                                    no-data-text="Pilih Petugas">
                                                    <template slot="item" slot-scope="{ item }">
                                                        <v-list-tile-content>
                                                            <v-list-tile-title v-text="item.M_StaffName"></v-list-tile-title>
                                                        </v-list-tile-content>
                                                    </template>
                                                </v-autocomplete>
                                                <p v-if="checkError('requirexstaff')" class="error pl-2 pr-2" style="color:#fff">Pilih Petugas dulu dong</p>
                                            </v-flex>
                                        </v-layout>
                                    <v-layout row>
                                            <v-flex xs12 pa-1>
                                                <v-autocomplete label="Petugas & SJ Baru*" v-model="xdeliveryorder" :items="xdeliveryorders" :search-input.sync="search_deliveryorder"
                                                    auto-select-first no-filter item-text="HS_DeliveryOrderNumber" return-object :loading="isLoading"
                                                    no-data-text="Pilih Petugas">
                                                    <template slot="item" slot-scope="{ item }">
                                                        <v-list-tile-content>
                                                            <v-list-tile-title v-text="item.HS_DeliveryOrderNumber"></v-list-tile-title>
                                                        </v-list-tile-content>
                                                    </template>
                                                </v-autocomplete>
                                                <p v-if="checkError('requirexdeliveryorder')" class="error pl-2 pr-2" style="color:#fff">Pilih Petugas  & SJ dulu dong</p>
                                            </v-flex>
                                        </v-layout>
                                        <v-layout row>
                                            <v-flex xs12 pa-1>

                                                <v-card-actions>
                                                    <v-spacer></v-spacer>
                                                    <v-btn color="teal darken-1" flat @click="updateDialogFormOrder()">Tutup</v-btn>
                                                    <v-btn v-if="xact === 'new'" :disabled="in_saving" color="teal darken-1" flat @click="saveFormPerusahaan()">Simpan</v-btn>
                                                    <v-btn v-if="xact === 'view'" color="teal darken-1" flat @click="updateFormPerusahaan()">Simpan Perubahan</v-btn>
                                                </v-card-actions>
                            </v-form>
                    </v-card>
                </v-dialog>
                </v-layout>
        </template>

        <template>
            <v-layout row justify-center>
                <v-dialog v-model="dialogformadd" persistent max-width="600px">
                    <v-card>
                        <v-card-title>
                            <span class="headline"></span>
                        </v-card-title>
                        <v-card-text class="pt-0 pb-0">
                            <v-form ref="formstaff">
                                <v-layout row wrap>
                                    <v-flex xs12 pa-2>
                                        <v-layout row>
                                            <v-flex xs12 pa-1>
                                                <v-menu class="xs3 pr-2" v-model="menudatestart" :close-on-content-click="false" :nudge-right="40" lazy transition="scale-transition"
                                                    offset-y full-width max-width="290px" min-width="290px">
                                                    <template v-slot:activator="{ on }">
                                                        <v-text-field class="mt-1" v-model="ComputedDateFormattedStart" label="Tanggal Home Service" readonly v-on="on" @blur="date = deFormatedDate(ComputedDateFormattedStart)"></v-text-field>
                                                    </template>
                                                    <v-date-picker v-model="init_idate" no-title @input="menudatestart = false"></v-date-picker>
                                                </v-menu>
                                                <p v-if="checkError('requirexsdate')" class="error pl-2 pr-2" style="color:#fff">Pilih Tanggal HS dulu dooong</p>
                                            </v-flex>
                                        </v-layout>
                                    <v-layout row>
                                            <v-flex xs12 pa-1>
                                                <v-autocomplete label="Petugas & SJ*" v-model="xdeliveryorder" :items="xdeliveryorders" :search-input.sync="search_deliveryorder"
                                                    auto-select-first no-filter item-text="HS_DeliveryOrderNumber" return-object :loading="isLoading"
                                                    no-data-text="Pilih Petugas">
                                                    <template slot="item" slot-scope="{ item }">
                                                        <v-list-tile-content>
                                                            <v-list-tile-title v-text="item.HS_DeliveryOrderNumber"></v-list-tile-title>
                                                        </v-list-tile-content>
                                                    </template>
                                                </v-autocomplete>
                                                <p v-if="checkError('requirexdeliveryorder')" class="error pl-2 pr-2" style="color:#fff">Pilih Petugas  & SJ dulu dong</p>
                                            </v-flex>
                                        </v-layout>
                                        <v-layout row>
                                            <v-flex xs12 pa-1>

                                                <v-card-actions>
                                                    <v-spacer></v-spacer>
                                                    <v-btn color="teal darken-1" flat @click="updateDialogFormAdd()">Tutup</v-btn>
                                                    <v-btn color="teal darken-1" flat @click="addFormBill()">Simpan</v-btn>
                                                </v-card-actions>
                            </v-form>
                    </v-card>
                </v-dialog>
                </v-layout>
        </template>

        <template>
            <v-layout row justify-center>
                <v-dialog v-model="dialogformupdate" persistent max-width="600px">
                    <v-card>
                        <v-card-title>
                            <span class="headline"></span>
                        </v-card-title>
                        <v-card-text class="pt-0 pb-0">
                            <v-form ref="formstaff">
                                <v-layout row wrap>
                                    <v-flex xs12 pa-2>
                                        <v-layout row>
                                            <v-flex xs6 pa-1>
                                                <v-text-field label="Tanggal Home Service (Baru)" v-model="xdate"
                            style="font-size:12px;padding:4px 0"></v-text-field></v-flex>
                                            <v-flex xs6 pa-1>
                                            <v-text-field label="Jam Home Service" v-model="xtime"
                            style="font-size:12px;padding:4px 0"></v-text-field>
                                                </v-flex>
                                        </v-layout>
                                    <v-layout row>
                                            <v-flex xs12 pa-1>
                                            <v-layout row>
                                            <v-flex xs6 pa-1>
                                                <v-menu class="xs3 pr-2" v-model="menudatestart" :close-on-content-click="false" :nudge-right="40" lazy transition="scale-transition"
                                                    offset-y full-width max-width="290px" min-width="290px">
                                                    <template v-slot:activator="{ on }">
                                                        <v-text-field class="mt-1" v-model="ComputedDateFormattedStart" label="Tanggal Home Service (Baru)" readonly v-on="on" @blur="date = deFormatedDate(ComputedDateFormattedStart)"></v-text-field>
                                                    </template>
                                                    <v-date-picker v-model="init_idate" no-title @input="menudatestart = false"></v-date-picker>
                                                </v-menu>
                                                <p v-if="checkError('requirexsdate')" class="error pl-2 pr-2" style="color:#fff">Pilih Tanggal HS dulu dooong</p>
                                            </v-flex>
                                            <v-flex xs6 pa-1>
                                            <v-text-field label="Jam Home Service (Baru)" v-model="xnewtime" mask="##:##"
                            style="font-size:12px;padding:4px 0" placeholder="hh:mm"></v-text-field>
                                                </v-flex>
                                        </v-layout
                                                </v-flex>
                                        </v-layout>
                                        <v-layout row>
                                            <v-flex xs12 pa-1>

                                                <v-card-actions>
                                                    <v-spacer></v-spacer>
                                                    <v-btn color="teal darken-1" flat @click="updateDialogFormUpdate()">Tutup</v-btn>
                                                    <v-btn color="teal darken-1" flat @click="updateFormBill()">Simpan</v-btn>
                                                </v-card-actions>
                            </v-form>
                    </v-card>
                </v-dialog>
                </v-layout>
        </template>

        <template>
            <v-layout row justify-center>
                <v-dialog v-model="dialogformprint" persistent max-width="600px">
                    <v-card>
                        <v-card-title>
                            <span class="headline">Cetak Penagihan [ {{this.xno}} ]</span>
                        </v-card-title>
                        <v-card-text class="pt-0 pb-0">
                            <v-form ref="formprint">
                                <v-layout row wrap>
                                    <v-flex xs12 pa-2>
                                        <v-layout row>
                                            <v-flex xs12 pa-1>
                                                <v-select item-text="rname" return-object :items="reports" v-model="selected_report" label="Kode Laporan"></v-select>
                                            </v-flex>
                                        </v-layout>

                                    </v-flex>
                                </v-layout>
                        </v-card-text>
                        <v-card-actions>
                            <v-spacer></v-spacer>
                            <v-btn color="teal darken-1" flat @click="updateDialogFormPrint()">Tutup</v-btn>
                            <v-btn color="teal darken-1" flat @click="printBill()">Cetak</v-btn>
                        </v-card-actions>
                        </v-form>
                    </v-card>
                </v-dialog>
            </v-layout>
        </template>

        <template>
            <v-layout row justify-center>
                <v-dialog v-model="dialogformprinttagihan" persistent max-width="600px">
                    <v-card>
                        <v-card-title>
                            <span class="headline">Cetak Lampiran Penagihan [ {{this.xno}} ]</span>
                        </v-card-title>
                        <v-card-text class="pt-0 pb-0">
                            <v-form ref="formprint">
                                <v-layout row wrap>
                                    <v-flex xs12 pa-2>
                                        <v-layout row>
                                            <v-flex xs12 pa-1>
                                                <v-select item-text="t_name" return-object :items="cetaks" v-model="selected_cetak" label="Tipe Lampiran"></v-select>
                                            </v-flex>
                                        </v-layout>

                                    </v-flex>
                                </v-layout>
                        </v-card-text>
                        <v-card-actions>
                            <v-spacer></v-spacer>
                            <v-btn color="teal darken-1" flat @click="updateDialogFormPrintTagihan()">Tutup</v-btn>
                            <v-btn color="teal darken-1" flat @click="printFinalTagihan()">Cetak</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;
    }

    .scroll-container {
        scroll-padding: 50px 0 0 50px;
    }

    ::-webkit-scrollbar {
        width: 7px;
    }

    /* this targets the default scrollbar (compulsory) */

    ::-webkit-scrollbar-track {
        background-color: #73baf3;
    }

    /* the new scrollbar will have a flat appearance with the set background color */

    ::-webkit-scrollbar-thumb {
        background-color: #2196f3;
    }

    /* this will style the thumb, ignoring the track */

    ::-webkit-scrollbar-button {
        background-color: #0079da;
    }

    /* optionally, you can style the top and the bottom buttons (left and right for horizontal bars) */

    ::-webkit-scrollbar-corner {
        background-color: black;
    }
</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/getnomor")
            this.$store.dispatch("receivereference/search", {
                name: this.name,
                snorm: this.snorm,
                startdate: this.init_sdate,
                enddate: this.init_edate,
                status: this.status.value,
                lastid: -1
            })
        },
        methods: {
            cancelOpenUpload() {
                this.close_image_url = false
                this.$store.state.receivereference.selected_receivereference.receive_date = this.$store.state.receivereference
                    .selected_receivereference.HS_DeliveryOrderConfirmIssueReceiveDate
            },
            changeUpdateReceive() {
                console.log(this.$store.state.receivereference.selected_receivereference.receive_date)
                var aDOB = moment(this.$store.state.receivereference.selected_receivereference.receive_date,
                    'DDMMYYYYHHmm', true)
                var isValidDOB = aDOB.isValid()
                console.log(isValidDOB)
                var xrdate = this.$store.state.receivereference.selected_receivereference.receive_date
                var rdate = xrdate.substr(0, 2) + "-" + xrdate.substr(2, 2) + "-" + xrdate.substr(4, 4) + " " +
                    xrdate.substr(8, 2) + ":" + xrdate.substr(10, 2)
                console.log(xrdate.substr(0, 2))
                console.log(xrdate.substr(2, 2))
                console.log(xrdate.substr(4, 4))
                console.log(xrdate.substr(8, 2))
                console.log(xrdate.substr(10, 2))
                if (!isValidDOB) {
                    this.$store.state.receivereference.selected_receivereference.receive_date = ''
                } else {
                    var tanggal = xrdate.substr(4, 4) + "-" + xrdate.substr(2, 2) + "-" + xrdate.substr(0, 2)
                    console.log(xrdate.substr(4, 4) + "-" + xrdate.substr(2, 2) + "-" + xrdate.substr(0, 2))
                    var dueDate = moment(new Date(new Date(tanggal).getTime() + (this.xdueday * 24 * 60 * 60 * 1000)))
                        .format(
                            'YYYY-MM-DD')
                    this.xsdate = dueDate
                }



            },
            openUploadImage() {
                this.imageName = ''
                this.$store.state.receivereference.selected_receivereference.receive_date = ''
                this.$store.commit("receivereference/update_close_image_url", true)
            },
            openUploadImageSend() {
                this.imageNameSend = ''
                this.$store.state.receivereference.selected_receivereference.send_date = ''
                this.$store.commit("receivereference/update_close_image_url_send", true)
            },
            upload() {
                var xrdate = this.$store.state.receivereference.selected_receivereference.receive_date
                var rdate = xrdate.substr(0, 2) + "-" + xrdate.substr(2, 2) + "-" + xrdate.substr(4, 4) + " " +
                    xrdate.substr(8, 2) + ":" + xrdate.substr(10, 2)
                console.log(xrdate.substr(0, 2))
                console.log(xrdate.substr(2, 2))
                console.log(xrdate.substr(4, 4))
                console.log(xrdate.substr(8, 2))
                console.log(xrdate.substr(10, 2))
                var rtanggal = xrdate.substr(4, 4) + "-" + xrdate.substr(2, 2) + "-" + xrdate.substr(0, 2) + " " +
                    xrdate.substr(8, 2) + ":" + xrdate.substr(10, 2) + ":00"
                this.$store.dispatch('receivereference/upload', {
                    rdate: rdate,
                    img: this.imageUrl,
                    idx: this.$store.state.receivereference.selected_receivereference.HS_DeliveryOrderConfirmIssueID,
                    billNo: this.$store.state.receivereference.selected_receivereference.HS_DeliveryOrderNumber,
                    idbill: this.$store.state.receivereference.selected_receivereference.HS_DeliveryOrderConfirmIssueHS_DeliveryOrderID,
                    sdate: this.xsdate,
                    rtanggal: rtanggal
                })
            },
            uploadSend() {
                var xrdate = this.$store.state.receivereference.selected_receivereference.send_date
                var rdate = xrdate.substr(0, 2) + "-" + xrdate.substr(2, 2) + "-" + xrdate.substr(4, 4) + " " +
                    xrdate.substr(8, 2) + ":" + xrdate.substr(10, 2)
                console.log(xrdate.substr(0, 2))
                console.log(xrdate.substr(2, 2))
                console.log(xrdate.substr(4, 4))
                console.log(xrdate.substr(8, 2))
                console.log(xrdate.substr(10, 2))
                var rtanggal = xrdate.substr(4, 4) + "-" + xrdate.substr(2, 2) + "-" + xrdate.substr(0, 2) + " " +
                    xrdate.substr(8, 2) + ":" + xrdate.substr(10, 2) + ":00"
                this.$store.dispatch('receivereference/uploadsend', {
                    rdate: rdate,
                    img: this.imageUrlSend,
                    idx: this.$store.state.receivereference.selected_receivereference.HS_DeliveryOrderConfirmIssueID,
                    billNo: this.$store.state.receivereference.selected_receivereference.HS_DeliveryOrderNumber,
                    idbill: this.$store.state.receivereference.selected_receivereference.HS_DeliveryOrderConfirmIssueHS_DeliveryOrderID,
                    sdate: this.xsdate,
                    rtanggal: rtanggal
                })
            },
            pickFile() {
                console.log('PicFile', this.$refs);
                this.$refs.image.click()
            },
            pickFileSend() {
                console.log('PicFileSend', this.$refs);
                this.$refs.imageSend.click()
            },
            onFilePicked(e) {
                const files = e.target.files
                console.log(files);
                if (files[0] !== undefined) {
                    this.imageName = files[0].name
                    if (this.imageName.lastIndexOf('.') <= 0) {
                        return
                    }
                    const fr = new FileReader()
                    fr.readAsDataURL(files[0])
                    fr.addEventListener('load', () => {
                        this.imageUrl = fr.result
                        this.imageFile = files[0] // this is an image file that can be sent to server...
                    })


                } else {
                    this.imageName = ''
                    this.imageFile = ''
                    this.imageUrl = ''
                }
            },
            onFilePickedSend(e) {
                const files = e.target.files
                console.log(files);

                if (files[0] !== undefined) {
                    this.imageNameSend = files[0].name
                    if (this.imageNameSend.lastIndexOf('.') <= 0) {
                        return
                    }
                    const fr = new FileReader()
                    fr.readAsDataURL(files[0])
                    fr.addEventListener('load', () => {
                        this.imageUrlSend = fr.result
                        this.imageFileSend = files[0] // this is an image file that can be sent to server...
                    })


                } else {
                    this.imageNameSend = ''
                    this.imageFileSend = ''
                    this.imageUrlSend = ''
                }
            },
            checkError(value) {
                var errors = this.$store.state.receivereference.errors
                if (errors.includes(value)) {
                    return true
                } else {
                    return false
                }
            },
            isSelected(p) {
                return p.T_TransactionID == this.$store.state.receivereference.selected_receivereference
                    .T_TransactionID
            },
            convertMoney(money) {
                return one_money(money)
            },
            printNote(val) {
                this.printwidth = 1200
                this.printtitle = ""
                let user = one_user()
                var rpt = 'rpt_tagihan_001'
                if (val.note_amount < 0)
                    rpt = 'rpt_t_009'
                this.urlprintnote = "/birt/run?__report=report/one/fo/" + rpt + ".rptdesign&__format=pdf&username=" +
                    user.M_UserUsername + "&PID=" + val.HS_DeliveryOrderConfirmIssueID
                this.$store.commit("receivereference/update_open_print_note", true)
            },
            printBill() {
                this.printwidth = 1200
                this.printtitle = ""
                let user = one_user()
                var rpt = this.$store.state.receivereference.selected_report.R_ReportUrl
                var xrpt = rpt.replace("rpt", "bill_rpt")
                var id = this.$store.state.receivereference.selected_receivereference.HS_DeliveryOrderID
                this.urlprintnote = xrpt + "&__format=pdf&username=" +
                    user.M_UserUsername + "&PID=" + id
                this.$store.commit("receivereference/update_open_print_note", true)
            },
            printTagihan(data) {
                this.$store.commit("receivereference/update_dialog_form_print_tagihan", true)
                this.xno = data.HS_DeliveryOrderNumber
            },
            printFinalTagihan() {
                this.printwidth = 1200
                this.printtitle = ""
                let user = one_user()
                var rpt = this.$store.state.receivereference.selected_cetak.t_url
                var id = this.$store.state.receivereference.selected_receivereference.HS_DeliveryOrderID
                this.urlprintnote = rpt + "&__format=pdf&username=" +
                    user.M_UserUsername + "&PID=" + id
                this.$store.commit("receivereference/update_open_print_note", true)
            },

            searchPatient() {
                this.$store.dispatch("receivereference/search", {
                    name: this.name,
                    snorm: this.snorm,
                    startdate: this.init_sdate,
                    enddate: this.init_edate,
                    status: this.status.value,
                    lastid: -1
                })
            },

            selectMe(pat) {
                this.$store.commit("receivereference/update_close_image_url", false)
                this.$store.commit("receivereference/update_image_url", 'empty')
                if (pat.HS_DeliveryOrderConfirmIssueImg) {
                    this.$store.commit("receivereference/update_image_url", pat.HS_DeliveryOrderConfirmIssueImg)
                }

                this.$store.commit("receivereference/update_close_image_url_send", false)
                this.$store.commit("receivereference/update_image_url_send", 'empty')
                /* if (pat.HS_DeliveryOrderConfirmIssueImgSend) {
                    this.$store.commit("receivereference/update_image_url_send", pat.HS_DeliveryOrderConfirmIssueImgSend)
                }
                */
                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.dispatch("receivereference/getpatient", {
                        id: pat.HS_DeliveryOrderID,
                        startdate: pat.HS_DeliveryOrderDateHS,
                        userid: pat.M_UserID
                    })
                    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() {
                let arrreceivereference = this.$store.state.receivereference.receivereferences
                var idx = _.findIndex(arrreceivereference, item => item.HS_DeliveryOrderID === this.$store.state
                    .receivereference.last_id)
                console.log(idx)
                this.$store.dispatch("receivereference/search", {
                    name: this.name,
                    snorm: this.snorm,
                    startdate: this.init_sdate,
                enddate: this.init_edate,
                    status: this.status.value,
                    lastid: idx
                })
                this.$store.commit("receivereference/update_dialog_form_order", false)
                this.$store.dispatch("receivereference/getnomor")
                this.$store.commit("receivereference/update_close_image_url", false)
                this.$store.commit("receivereference/update_image_url", 'empty')

            },
            updateDialogFormAdd() {
                let arrreceivereference = this.$store.state.receivereference.receivereferences
                var idx = _.findIndex(arrreceivereference, item => item.HS_DeliveryOrderID === this.$store.state
                    .receivereference.last_id)
                console.log(idx)
                this.$store.dispatch("receivereference/search", {
                    name: this.name,
                    snorm: this.snorm,
                    startdate: this.init_sdate,
                enddate: this.init_edate,
                    status: this.status.value,
                    lastid: idx
                })
                this.$store.commit("receivereference/update_dialog_form_add", false)

            },
            updateDialogFormPrint() {
                this.$store.commit("receivereference/update_dialog_form_print", false)
            },
            updateDialogFormPrintTagihan() {
                this.$store.commit("receivereference/update_dialog_form_print_tagihan", false)
            },
            updateDialogStatusOrder() {
                this.$store.commit("receivereference/update_dialog_status_order", false)
            },
            changeAllMou() {
                if (this.isallmou) {
                    this.dialogmou = true
                }
            },
            viewDetail(data){
                let id = data.T_TransactionID
            this.$store.dispatch("receivereference/listmou", id)
            this.dialogmou = true
            },
            setNewOrder() {
                this.$store.commit("receivereference/update_close_image_url", false)
                this.$store.commit("receivereference/update_image_url", 'empty')
                this.$store.commit("receivereference/update_close_image_url_send", false)
                this.$store.commit("receivereference/update_image_url_send", 'empty')
                this.$store.dispatch("receivereference/searchbank", '')
                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.xnoref = ''
                this.xno = ''
                this.xtotal = 0
                this.xstaff = ''
                this.isallmou = false
                this.xbank = {}
                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,
                    startdate: ''
                })
                console.log(this.xstaff)
            },
            changeDueDay() {
                var start = moment(new Date()).format('YYYY-MM-DD');
                var end = moment(this.xsdate);
                var xday = end.diff(start, "days")
                this.xdueday = xday
            },
            changeDueDate() {
                var dueDate = moment(new Date(new Date().getTime() + (this.xdueday * 24 * 60 * 60 * 1000))).format(
                    'YYYY-MM-DD')
                this.xsdate = dueDate
            },
            setStatusOrder() {
                this.$store.commit("receivereference/update_selected_receivereference", {})
                this.$store.commit("receivereference/update_dialog_status_order", true)
                this.search_staff = ''
                this.search_bank = ''
            },
            saveFormPerusahaan() {
                this.$store.commit("receivereference/update_errors", [])
                var errors = this.$store.state.receivereference.errors
                if (_.isEmpty(this.xstaff)) {
                    errors.push("requirexstaff")
                }
                if (_.isEmpty(this.init_idate)) {
                    errors.push("requirexsdate")
                }

                if (errors.length === 0) {
                    if (this.in_saving) return;
                    this.in_saving = true;
                    this.$store.dispatch("receivereference/newreceivereference", {
                        staffid: this.xstaff.M_StaffID,
                        sdate: this.init_idate,
                        note: this.xnote
                    })
                }

            },
            pilihmou(data) {
                this.xmou = {
                    M_MouID: data.M_MouID,
                    M_MouDesc: data.M_MouDesc,
                    M_BranchID: data.M_BranchID
                }
                this.xpicname = data.M_MouFinanceName
                this.xpicemail = data.M_MouFinanceEmail
                this.xpichp = data.M_MouFinanceHandphone
                this.xdueday = data.M_MouAgingDay
                this.xsdate = data.duedate

                this.dialogmou = false
            },
            ediitBill(data) {
                this.xid = data.HS_DeliveryOrderID
                this.xno = data.HS_DeliveryOrderNumber
                this.xpicname = data.HS_DeliveryOrderConfirmIssuePIC
                this.xnoref = data.HS_DeliveryOrderConfirmIssueRefNumber
                this.xpichp = data.HS_DeliveryOrderConfirmIssuePICHP
                this.xpicemail = data.HS_DeliveryOrderConfirmIssuePICEmail
                this.xtotal = data.HS_DeliveryOrderTotal
                this.$store.commit("receivereference/update_companies", [{
                    M_StaffID: data.M_StaffID,
                    M_StaffName: data.M_StaffName
                }])
                this.xstaff = {
                    M_StaffID: data.M_StaffID,
                    M_StaffName: data.M_StaffName
                }

                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.$store.commit("receivereference/update_banks", [{
                    M_BankAccountID: data.M_BankAccountID,
                    M_BankAccountName: data.M_BankAccountName
                }])
                this.xbank = {
                    M_BankAccountID: data.M_BankAccountID,
                    M_BankAccountName: data.M_BankAccountName
                }
                this.xdueday = data.HS_DeliveryOrderDueDateDay
                this.xsdate = data.sdate
                this.xnote = data.HS_DeliveryOrderNumberte
                this.$store.commit("receivereference/update_act_comp", 'edit')
                this.$store.commit("receivereference/update_dialog_form_order", true)
            },
            viewBill(data) {
                this.xid = data.HS_DeliveryOrderDetailID
                this.xdoid = data.HS_DeliveryOrderID
                this.xno = data.HS_DeliveryOrderNumber
                this.init_idate = data.T_OrderDate
                this.tid = data.T_TransactionID
                this.$store.commit("receivereference/update_companies", [{
                    M_StaffID: data.M_StaffID,
                    M_StaffName: data.M_StaffName
                }])
                this.xstaff = {
                    M_StaffID: data.M_StaffID,
                    M_StaffName: data.M_StaffName
                }

                this.$store.commit("receivereference/update_deliveryorders", [])
                this.xdelivery = ''
                this.$store.commit("receivereference/update_act_comp", 'view')
                this.$store.commit("receivereference/update_dialog_form_order", true)
            },
            updateFormPerusahaan() {
                this.$store.commit("receivereference/update_errors", [])
                var errors = this.$store.state.receivereference.errors
                if (_.isEmpty(this.xstaff)) {
                    errors.push("requirexstaff")
                }
                if (_.isEmpty(this.xdeliveryorder)) {
                    errors.push("requirexdeliveryorder")
                }
                if (errors.length === 0) {
                    this.$store.dispatch("receivereference/editbill", {
                        id: this.xid,
                        doid: this.xdoid,
                        sdate: this.xsdate,
                        tid: this.tid,
                        idnew : this.xdeliveryorder.HS_DeliveryOrderID,
                        useridnew : this.xdeliveryorder.HS_DeliveryOrderM_UserID
                    })
                }
            },
            addBill(data) {
                this.xid = data.HS_DeliveryOrderDetailID
                this.xdoid = data.HS_DeliveryOrderID
                this.xno = data.HS_DeliveryOrderNumber
                this.init_idate = data.T_OrderDate
                this.tid = data.T_TransactionID
                this.$store.commit("receivereference/update_companies", [{
                    M_StaffID: data.M_StaffID,
                    M_StaffName: data.M_StaffName
                }])
                this.xstaff = {
                    M_StaffID: data.M_StaffID,
                    M_StaffName: data.M_StaffName
                }

                this.$store.commit("receivereference/update_deliveryorders", [])
                this.xdelivery = ''
                this.$store.commit("receivereference/update_dialog_form_add", true)
            },
            addFormBill() {
                this.$store.commit("receivereference/update_errors", [])
                var errors = this.$store.state.receivereference.errors
                if (_.isEmpty(this.xstaff)) {
                    errors.push("requirexstaff")
                }
                if (_.isEmpty(this.xdeliveryorder)) {
                    errors.push("requirexdeliveryorder")
                }
                if (errors.length === 0) {
                    this.$store.dispatch("receivereference/addbill", {
                        id: this.xid,
                        doid: this.xdoid,
                        sdate: this.xsdate,
                        tid: this.tid,
                        idnew : this.xdeliveryorder.HS_DeliveryOrderID,
                        useridnew : this.xdeliveryorder.HS_DeliveryOrderM_UserID
                    })
                }
            },
            updateBill(data) {
                this.xid = data.HS_DeliveryOrderDetailID
                this.xdoid = data.HS_DeliveryOrderID
                this.tid = data.T_TransactionID
                this.xno = data.HS_DeliveryOrderNumber
                this.init_idate = data.T_OrderDate
                this.xdate = data.orderdate
                this.xtime = data.T_OrderTime
                this.$store.commit("receivereference/update_companies", [{
                    M_StaffID: data.M_StaffID,
                    M_StaffName: data.M_StaffName
                }])
                this.xstaff = {
                    M_StaffID: data.M_StaffID,
                    M_StaffName: data.M_StaffName
                }

                this.$store.commit("receivereference/update_deliveryorders", [])
                this.xdelivery = ''
                this.$store.commit("receivereference/update_dialog_form_update", true)
            },
            updateFormBill() {
                this.$store.commit("receivereference/update_errors", [])
                var errors = this.$store.state.receivereference.errors
                if (_.isEmpty(this.xstaff)) {
                    errors.push("requirexstaff")
                }
                if (errors.length === 0) {
                    this.$store.dispatch("receivereference/updatebill", {
                        id: this.tid,
                        doid: this.xdoid,
                        sdate: this.xsdate,
                        tid: this.tid,
                        idnew : this.xdeliveryorder.HS_DeliveryOrderID,
                        useridnew : this.xdeliveryorder.HS_DeliveryOrderM_UserID,
                        newdate: this.init_idate,
                        newtime: this.xnewtime,
                    })
                }
            },
            deleteBill(data) {
                this.tid = data.T_TransactionID
                this.xcancelnote = ''
                var xdata = {
                    id: data.T_TransactionID,
                    name: data.T_TransactionNumbering
                }
                this.msgalert = "Yakin, mau membatalkan " + data.T_TransactionNumbering + "  ?"
                this.dialogdeletealert = true
            },
            notifBill(data) {
                this.xid = data.HS_DeliveryOrderID
                var xdata = {
                    id: data.HS_DeliveryOrderID,
                    name: data.HS_DeliveryOrderConfirmIssueNumber
                }
                this.msgalert = "Konfirmasi No. Penagihan Pusat " + data.HS_DeliveryOrderNumber + " ke cabang " + data.M_BranchName
                this.stattusnotif = data.HS_DeliveryOrderConfirmIssueIsConfirm
                this.dialognotifalert = true
            },
            sendBill(data) {
                this.xid = data.HS_DeliveryOrderConfirmIssueID
                var xdata = {
                    id: data.HS_DeliveryOrderConfirmIssueID,
                    name: data.HS_DeliveryOrderConfirmIssueNumber
                }
                this.msgalert = "Yakin Kirim No. Penagihan Pusat " + data.HS_DeliveryOrderNumber + " ke cabang " + data.M_BranchName
                this.stattussend = data.HS_DeliveryOrderConfirmIssueIsDownload
                this.dialogsendalert = true
            },
            closeDeleteAlert() {
                this.$store.commit("receivereference/update_errors", [])
                var errors = this.$store.state.receivereference.errors
                if (_.isEmpty(this.xcancelnote)) {
                    errors.push("requirecancelnote")
                }
                if (errors.length === 0) {
                this.$store.dispatch("receivereference/deletebill", {
                    id: this.tid,
                    note: this.xcancelnote
                })

                this.dialogdeletealert = false
                }
            },
            closeNotifAlert() {
                this.$store.dispatch("receivereference/notifbill", {
                    id: this.xid
                })
                this.dialognotifalert = false
            },
            closeSendAlert() {
                this.$store.dispatch("receivereference/sendbill", {
                    id: this.xid
                })
                this.dialogsendalert = false
            },
            thr_search_staff: _.debounce(function () {
                this.$store.dispatch("receivereference/searchstaff", this.search_staff)
            }, 2000),
            thr_search_deliveryorder: _.debounce(function () {
                this.$store.dispatch("receivereference/searchdeliveryorder", {search:this.search_deliveryorder,idate:this.init_idate,no:this.xno})
            }, 2000),
            thr_search_bank: _.debounce(function () {
                this.$store.dispatch("receivereference/searchbank", this.search_bank)
            }, 2000),
            closeDialogSuccess() {
                let arrreceivereference = this.$store.state.receivereference.receivereferences
                var idx = _.findIndex(arrreceivereference, item => item.HS_DeliveryOrderID === this.$store.state
                    .receivereference.last_id)
                console.log(idx)
                this.$store.dispatch("receivereference/search", {
                    name: this.name,
                    snorm: this.snorm,
                    startdate: this.init_sdate,
                enddate: this.init_edate,
                    status: this.status.value,
                    lastid: idx
                })
                this.$store.commit("receivereference/update_dialog_success", 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')}`
            }
        },
        computed: {
            selected_receivereference: {
                get() {
                    return this.$store.state.receivereference.selected_receivereference
                },
                set(val) {
                    this.$store.commit("receivereference/update_selected_receivereference", val)
                }
            },
            image_url: {
                get() {
                    return this.$store.state.receivereference.image_url
                },
                set(val) {
                    this.$store.commit("receivereference/update_image_url", val)
                }
            },
            xerrors() {
                return this.$store.state.receivereference.errors
            },
            ComputedDateFormattedStart() {
                return this.formatDate(this.init_idate)
            },
            filterComputedDateFormattedStart() {
                return this.formatDate(this.init_sdate)
            },
            filterComputedDateFormattedEnd() {
                return this.formatDate(this.init_edate)
            },
            init_idate: {
                get() {
                    return this.$store.state.receivereference.init_idate
                },
                set(val) {
                    this.$store.commit("receivereference/update_init_idate", val)
                }
            },
            init_sdate: {
                get() {
                    return this.$store.state.receivereference.init_sdate
                },
                set(val) {
                    this.$store.commit("receivereference/update_init_sdate", val)
                }
            },
            init_edate: {
                get() {
                    return this.$store.state.receivereference.init_edate
                },
                set(val) {
                    this.$store.commit("receivereference/update_init_edate", val)
                }
            },
            close_image_url: {
                get() {
                    return this.$store.state.receivereference.close_image_url
                },
                set(val) {
                    this.$store.commit("receivereference/update_close_image_url", val)
                }
            },
            image_url_send: {
                get() {
                    return this.$store.state.receivereference.image_url_send
                },
                set(val) {
                    this.$store.commit("receivereference/update_image_url_send", val)
                }
            },
            close_image_url_send: {
                get() {
                    return this.$store.state.receivereference.close_image_url_send
                },
                set(val) {
                    this.$store.commit("receivereference/update_close_image_url_send", val)
                }
            },
            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)
                    this.$store.dispatch("receivereference/search", {
                name: this.name,
                snorm: this.snorm,
                startdate: this.init_sdate,
                enddate: this.init_edate,
                status: val.value,
                lastid: -1
            })
                }
            },
            xact() {
                return this.$store.state.receivereference.act_comp
            },
            receivereferences() {
                return this.$store.state.receivereference.receivereferences
            },
            listmous() {
                return this.$store.state.receivereference.listmous
            },
            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
            },
            dialogformadd() {
                return this.$store.state.receivereference.dialog_form_add
            },
            dialogformupdate() {
                return this.$store.state.receivereference.dialog_form_update
            },
            dialogformprint() {
                return this.$store.state.receivereference.dialog_form_print
            },
            dialogformprinttagihan() {
                return this.$store.state.receivereference.dialog_form_print_tagihan
            },
            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)
                }
            },
            xdueday: {
                get() {
                    return this.$store.state.receivereference.dueday
                },
                set(val) {
                    this.$store.commit("receivereference/update_dueday", val)
                }
            },
            xnoref: {
                get() {
                    return this.$store.state.receivereference.noref
                },
                set(val) {
                    this.$store.commit("receivereference/update_noref", 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)
                }
            },
            xpicemail: {
                get() {
                    return this.$store.state.receivereference.picemail
                },
                set(val) {
                    this.$store.commit("receivereference/update_picemail", val)
                }
            },
            xcompanies() {
                return this.$store.state.receivereference.companies
            },
            xstaff: {
                get() {
                    return this.$store.state.receivereference.staff
                },
                set(val) {
                    this.$store.commit("receivereference/update_staff", val)
                }
            },
            xdeliveryorders() {
                return this.$store.state.receivereference.deliveryorders
            },
            xdeliveryorder: {
                get() {
                    return this.$store.state.receivereference.deliveryorder
                },
                set(val) {
                    this.$store.commit("receivereference/update_deliveryorder", val)
                }
            },
            isallmou: {
                get() {
                    return this.$store.state.receivereference.isallmou
                },
                set(val) {
                    this.$store.commit("receivereference/update_isallmou", val)
                    if (val === 'true') {
                        this.dialogmou = true
                    }
                }
            },
            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)
                    if (this.xno === '') {
                        this.$store.commit("receivereference/update_picname", val.M_MouFinanceName)
                        this.$store.commit("receivereference/update_pichp", val.M_MouFinanceHandphone)
                        this.$store.commit("receivereference/update_picemail", val.M_MouFinanceEmail)

                        var dueDate = moment(new Date(new Date().getTime() + (val.M_MouAgingDay * 24 * 60 * 60 *
                            1000))).format(
                            'YYYY-MM-DD')
                        this.xsdate = dueDate
                    }

                }
            },
            xbanks() {
                return this.$store.state.receivereference.banks
            },
            xbank: {
                get() {
                    return this.$store.state.receivereference.bank
                },
                set(val) {
                    this.$store.commit("receivereference/update_bank", val)
                }
            },
            reports() {
                return this.$store.state.receivereference.reports
            },
            selected_report: {
                get() {
                    return this.$store.state.receivereference.selected_report
                },
                set(val) {
                    this.$store.commit("receivereference/update_selected_report", val)
                }
            },
            cetaks() {
                return this.$store.state.receivereference.cetaks
            },
            selected_cetak: {
                get() {
                    return this.$store.state.receivereference.selected_cetak
                },
                set(val) {
                    this.$store.commit("receivereference/update_selected_cetak", 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 {
                menufilterdatestart: false,
            menufilterdateend: false,
            menudatestart: false,
                imageName: '',
                imageUrl: '',
                imageFile: '',
                imageNameSend: '',
                imageUrlSend: '',
                imageFileSend: '',
                msgalertconfirmation: "Perubahan yang telah dilakukan belum disimpan dong !",
                items: [],
                xid: 0,
                tid: 0,
                xdoid: 0,
                xno: '',
                xtime:'',
                xnewtime:'',
                xdate:'',
                xtotal: 0,
                xcancelnote: '',
                name: '',
                snorm: '',
                msgalert: "",
                stattusnotif: "N",
                stattussend: "N",
                dialogdeletealert: false,
                dialognotifalert: false,
                dialogsendalert: false,
                dialogmou: false,
                search_staff: '',
                search_deliveryorder: '',
                search_bank: '',
                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,
                headers: [{
                        text: "TANGGAL HOME SERVICE",
                        align: "center",
                        sortable: false,
                        value: "mr",
                        width: "10%",
                        class: "pa-2 teal lighten-3 white--text"
                    },
                    {
                        text: "NOMOR",
                        align: "center",
                        sortable: false,
                        value: "mr",
                        width: "10%",
                        class: "pa-2 teal lighten-3 white--text"
                    },
                    {
                        text: "NAMA",
                        align: "center",
                        sortable: false,
                        value: "mr",
                        width: "15%",
                        class: "pa-2 teal lighten-3 white--text"
                    },
                    
                    {
                        text: "ALAMAT",
                        align: "center",
                        sortable: false,
                        value: "mr",
                        width: "15%",
                        class: "pa-2 teal lighten-3 white--text"
                    },
                    {
                        text: "TOTAL",
                        align: "center",
                        sortable: false,
                        value: "lab",
                        width: "10%",
                        class: "pa-2 teal lighten-3 white--text"
                    },
                    {
                        text: "STATUS",
                        align: "center",
                        sortable: false,
                        value: "name",
                        width: "10%",
                        class: "pa-2 teal lighten-3 white--text"
                    },
                    {
                        text: "AKSI",
                        align: "center",
                        sortable: false,
                        value: "name",
                        width: "15%",
                        class: "pa-2 teal lighten-3 white--text"
                    }
                ],
                headersmou: [{
                        text: "NOMOR",
                        align: "center",
                        sortable: false,
                        value: "mr",
                        width: "7%",
                        class: "pa-2 teal lighten-3 white--text"
                    },
                    {
                        text: "NAMA",
                        align: "center",
                        sortable: false,
                        value: "mr",
                        width: "20%",
                        class: "pa-2 teal lighten-3 white--text"
                    },
                    {
                        text: "WAKTU",
                        align: "center",
                        sortable: false,
                        value: "mr",
                        width: "10%",
                        class: "pa-2 teal lighten-3 white--text"
                    },
                    {
                        text: "PEMERIKSAAN",
                        align: "center",
                        sortable: false,
                        value: "mr",
                        width: "15%",
                        class: "pa-2 teal lighten-3 white--text"
                    },
                    {
                        text: "TOTAL",
                        align: "center",
                        sortable: false,
                        value: "lab",
                        width: "12%",
                        class: "pa-2 teal lighten-3 white--text"
                    }
                ],
                pagination: {
                    descending: true,
                    page: 1,
                    rowsPerPage: 5,
                    sortBy: 'HS_DeliveryOrderConfirmIssueNumber',
                    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_staff(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_staff()
            },
            search_deliveryorder(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_deliveryorder()
            },
            search_bank(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_bank()
            }
        }
    }
</script>