<template>
    <v-layout class="fill-height" column>
        <template>
            <v-dialog v-model="dialogprogress" persistent max-width="350">
            <v-card>
                <v-card-title color="warning" class="headline">Proses sedang berjalan</v-card-title>
                <v-card-text>
                    <v-layout row>
                        <v-flex xs12>
                            <v-progress-linear :indeterminate="true"></v-progress-linear>
                        </v-flex>
                    </v-layout>
                    <v-layout row>
                        <v-flex xs12>
                            <p>Mohon menunggu, penyimpanan data membutuhkan waktu lebih</p>
                            <p>...</p>
                        </v-flex>
                    </v-layout>
                </v-card-text>
                <v-card-actions>
                    <v-spacer></v-spacer>
                    <!--<v-btn color="green darken-1" flat @click="dialogprogress">OK</v-btn>-->
                </v-card-actions>
            </v-card>
        </v-dialog>
            <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" 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="dialognotifalertold" max-width="60%">
                <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-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>
                                                <v-card elevation="11">
                                                    <v-card-text>
                                                        <v-layout row>
                                                            <v-flex xs12 pa-1>
                                                                <v-text-field label="Pilih Gambar" hide-details @click='pickFileSend' v-model='imageNameSend' prepend-icon='attach_file'
                                                                    class="mt-2"></v-text-field>
                                                                <input type="file" style="display: none" ref="imageSend" accept="image/*" @change="onFilePickedSend">
                                                            </v-flex>

                                                        </v-layout>
                                                    </v-card-text>
                                                    <v-card-actions>
                                                        <v-btn dark color="red" block @click="cancelOpenUploadSend()">batal</v-btn>
                                                        <v-btn color="success" v-if="selected_receivereference.receive_date !== ''" block @click="uploadSend">Upload</v-btn>
                                                    </v-card-actions>
                                                </v-card>
                                            </v-flex>

                                        </v-layout>
                    </v-card-text>
                    </v-flex>
                    </v-layout>
                    </v-flex>
                    </v-layout>
                    <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>
                                            <v-card-text>
                                                <v-img v-if="image_url_send !== 'empty'" :src="image_url_send" aspect-ratio="1.34" class="grey lighten-2 elevation-2" contain></v-img>

                                                <p v-if="image_url_send == 'empty'">BELUM ADA IMAGE</p>
                                            </v-card-text>
                                        </v-flex>
                                    </v-layout>
                                </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 v-if="image_url_send !== 'empty'" color="primary" flat @click="closeNotifAlert">
            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" hide-actions class="elevation-1">
                    <template slot="items" slot-scope="props">
                        <td class="text-xs-left pa-2">{{ props.item.M_MouDesc}}</td>
                        <td class="text-xs-center pa-2">{{ props.item.M_MouAgingDay}}</td>
                        <td class="text-xs-center pa-2">{{ props.item.duedateina}}</td>
                        <td class="text-xs-center pa-2">{{ props.item.M_MouFinanceName}}</td>
                        <td class="text-xs-center pa-2">{{ props.item.M_MouFinanceEmail}}</td>
                        <td class="text-xs-left pa-2">
                        <v-btn color="blue darken-1" @click="pilihmou(props.item)">Pilih</v-btn>
                        </td>

                    </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-text-field class="xs4 ma-1" label="Corporate/Project" placeholder="Cari..." outline v-model="name" hide-details></v-text-field>
            <v-text-field class="xs4 ma-1" label="No. 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>
            <span @click="setNewOrder" class="icon-medium-fill-base xs1 white--text primary  ml-1 icon-add"></span>
        </v-layout>
    </v-card>
<v-card>
        <v-layout row class="scroll-container" style="max-height:500px;overflow: auto;">
            <v-flex xs12 pl-2 pr-2 pt-2 pb-2>
                <v-data-table :headers="headers" :items="receivereferences" :loading="isLoading" hide-actions class="elevation-1">
                    <template slot="items" slot-scope="props">
                        <td class="text-xs-left pa-2" v-bind:class="{'amber lighten-4':isSelected(props.item)}" @click="selectMe(props.item)">{{ props.item.F_BillNo}}
                        </td>
                        <td class="text-xs-left pa-2" v-bind:class="{'amber lighten-4':isSelected(props.item)}" @click="selectMe(props.item)">{{ props.item.F_BillCreated}}
                        </td>
                        <td class="text-xs-left pa-2" v-bind:class="{'amber lighten-4':isSelected(props.item)}" @click="selectMe(props.item)">{{ props.item.F_BillDueDate}}</td>
                        <td class="text-xs-center pa-2" v-bind:class="{'amber lighten-4':isSelected(props.item)}" @click="selectMe(props.item)">{{ props.item.CorporateName}}</td>
                        <td class="text-xs-center pa-2" v-bind:class="{'amber lighten-4':isSelected(props.item)}" @click="selectMe(props.item)">{{ props.item.Mgm_McuLabel}}</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_BillTotal)}}</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:blue" title="edit" v-if="props.item.F_BillIsNotif === 'N'" class="text-sm-right" @click="viewBill(props.item)">edit</v-icon>
                            <v-icon style="color:green" title="revisi" v-if="props.item.F_BillTotal === props.item.F_BillUnpaid" class="text-sm-right" @click="viewBillRevisi(props.item)">update</v-icon>
                            <v-icon style="color:red" title="hapus" v-if="props.item.F_BillTotal === props.item.F_BillUnpaid" class="text-sm-right" @click="deleteBill(props.item)">delete</v-icon>
                            <v-icon style="color:#757575" title="cetak" class="text-sm-right" @click="openprintformat(props.item)">print</v-icon>
                            <v-icon style="color:grey" title="belum kirim" v-if="props.item.statusnotif === 'N' && !props.item.F_BillXEmailOutboxID && props.item.F_BillTotal !== '0'"
                                class="text-sm-right" @click="notifBill(props.item)">send</v-icon>
                                <v-icon style="color:orange" title="proses kirim" v-if="props.item.F_BillXEmailOutboxID && props.item.statusnotif === 'N'" class="text-sm-right">send</v-icon>
                            <v-icon style="color:green" title="notif telah terkirim" v-if="props.item.statusnotif === 'Y'" class="text-sm-right">send</v-icon>
                            <v-icon style="color:red" title="gagal terkirim" v-if="props.item.statusnotif === 'E'" class="text-sm-right" @click="notifBill(props.item)">send</v-icon>
                        </td>

                    </template>
                </v-data-table>
            </v-flex>
        </v-layout>
        
        <v-divider></v-divider>
                <v-pagination style="margin-top:10px;margin-bottom:10px" v-model="curr_page" :length="xtotal_page"></v-pagination>

    </v-card>
<v-card>
                <v-card-text class="pa-0">
                    <v-layout row wrap>

                        <v-flex xs12>
                            <one-bill-detail></one-bill-detail>
                        </v-flex>
                        <v-divider></v-divider>
                    </v-layout>
                </v-card-text>

                
            </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="100%">
                
                <v-card>
                    <v-card-title>
                        <span class="headline">Form 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>
                                            <p v-for="(xerror,idx) in xerrors" class="error pl-2 pr-2" style="color:#fff">{{xerror.msg}}</p>
                                        </v-flex>
                                    </v-layout>
                                    <v-layout row>
                                        <v-flex xs12 pa-1>
                                            <v-select :readonly="xact === 'view'" class="xs3 mini-select ma-1" :items="xbanks" item-text="M_BankAccountName" return-object v-model="xbank" label="Nomor Rekening*"
                hide-details></v-select>
</v-autocomplete>
<p v-if="checkError('requirexbank')" class="error pl-2 pr-2" style="color:#fff">Pilih Nomor Rekening dulu dong</p>
</v-flex>
</v-layout>
<v-layout row>
    <v-flex xs4 pa-1>
        <v-autocomplete label="Corporate*" v-model="xcompany"
            :items="xcompanies" :search-input.sync="search_company" auto-select-first no-filter
            item-text="CorporateName" :readonly="xact === 'edit' || xact === 'view'" return-object :loading="isLoading" no-data-text="Pilih Project">
            <template slot="item" slot-scope="{ item }">
                                                    <v-list-tile-content>
                                                        <v-list-tile-title v-text="item.CorporateName"></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 Corporate dulu dong</p>
</v-flex>
<v-flex xs4 pa-1>
    <v-select v-if="xact === 'new'" :readonly="xact === 'edit' || xact === 'view'" class="xs3 mini-select ma-1"
        :items="xprojects" item-text="Mgm_McuLabel" return-object v-model="xproject" label="Project*"
        hide-details></v-select>
</v-flex>
<v-flex xs4 pa-1>
    <v-btn small v-if="xact === 'new'" color="blue" class="white--text ma-1" @click="addProject()">Tambah
        Project</v-btn>
</v-flex>
</v-layout>

<v-layout row v-for="(vst,idx) in xordertests" :key="vst.Mgm_McuID" class="pr-2 pb-1">
    <v-flex xs12>
        <v-layout row>
            <v-flex xs10>
                <p class="mb-0">
                    <v-btn v-if="xact === 'edit' || xact === 'view'" color="blue" class="white--text ma-1" small
                        style="margin:0px;min-width:20px">{{vst.Mgm_McuLabel}}</v-btn>
                    <v-btn v-if="xact == 'new'" color="blue" class="white--text ma-1" @click="deleteDataPx(idx)" small
                        style="margin:0px;min-width:20px"><v-icon left>close</v-icon>{{vst.Mgm_McuLabel}}</v-btn>

                </p>
            </v-flex>
        </v-layout>
    </v-flex>
</v-layout>
<v-layout row>
    <v-flex xs12 pa-1>
        <v-select :readonly="xact === 'edit' || xact === 'view'" class="xs3 mini-select ma-1" :items="xbranchs"
            item-text="M_BranchName" return-object v-model="xbranch" label="Cabang Penagihan*" hide-details></v-select>
        <p v-if="checkError('requirexbranch')" class="error pl-2 pr-2" style="color:#fff">Pilih Cabang dulu dong</p>
    </v-flex>
</v-layout>
<v-layout row>
    <v-flex xs12 pa-1>
        <v-layout>
            <v-flex xs4>
                <v-text-field :readonly="xact === 'view'" v-model="xdueday" @change="changeDueDate()"
                    label="Jatuh Tempo (Hari)"></v-text-field>
            </v-flex>
            <v-flex xs2>
            </v-flex>
            <v-flex xs6>
                <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 :readonly="xact === 'view'" v-model="startComputedDateFormatted"  label="Tgl. Jatuh Tempo*" readonly v-on="on" @blur="date = deFormatedDate(startComputedDateFormatted)"></v-text-field>
                                                        </template>
                    <v-date-picker :readonly="xact === 'view'" 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-layout>
    </v-flex>
</v-layout>
<v-layout row>
    <v-flex xs12 pa-1>
        <v-layout>
            <v-flex xs4>
                <v-text-field :readonly="xact === 'view'" v-model="xpicname" label="PIC Corporate"></v-text-field>
            </v-flex>
            <v-flex xs2>
            </v-flex>
            <v-flex xs6>
                <v-text-field :readonly="xact === 'view'" v-model="xpichp" label="No. HP PIC Corporate"></v-text-field>
            </v-flex>
        </v-layout>
    </v-flex>
</v-layout>
<v-layout row>
    <v-flex xs12 pa-1>
        <v-text-field :readonly="act === 'view'" v-model="xpicemail" label="Email PIC Corporate"></v-text-field>
    </v-flex>
</v-layout>
<v-layout row>
    <v-flex xs12 pa-1>
        <v-text-field v-model="xnote" label="Catatan"></v-text-field>
    </v-flex>
</v-layout>
<v-layout row>
    <v-flex xs12 pa-1>
        <v-text-field :readonly="xact === 'view'" v-model="xnoref" label="Nomor Referensi"></v-text-field>
    </v-flex>
</v-layout>

<!--  <v-layout v-if="!close_image_url" row>
                                        <v-flex xs12 pa-1>
                                            <v-card elevation="11">


                                                <v-card-title primary-title>
                                                    <div>
                                                        <h3 class="subheader mb-0">BUKTI</h3>
                                                    </div>
                                                </v-card-title>
                                                <v-card-text>
                                                    <p v-if="image_url !== 'empty' && selected_receivereference">TANGGAL PENERIMAAN : {{selected_receivereference.F_BillReceiveDate}}</p>
                                                    <v-img v-if="image_url !== 'empty'" :src="image_url" aspect-ratio="1.34" class="grey lighten-2 elevation-2" contain></v-img>

                                                    <p v-if="image_url == 'empty'">BELUM ADA IMAGE</p>
                                                </v-card-text>
                                                <v-card-actions>
                                                    <v-btn dark v-if="image_url == 'empty'" @click="openUploadImage()" color="orange">upload bukti</v-btn>
                                                    <v-btn dark v-if="image_url !== 'empty'" @click="openUploadImage()" flat color="orange">ganti</v-btn>
                                                </v-card-actions>
                                            </v-card>


                                        </v-flex>
                                    </v-layout> 
                                    <v-card elevation="11" v-if="close_image_url && selected_receivereference">

                                        <v-card-text>
                                            <v-layout row>
                                                <v-flex xs12>
                                                    <v-text-field label="Tanggal Penerimaan" mask="##-##-#### ##:##" v-model="selected_receivereference.receive_date" @blur="changeUpdateReceive()"
                                                        class="pb-1" hide-details></v-text-field>
                                                    <p class="warning--text caption" v-if="selected_receivereference.receive_date == ''">Harus diisi, format : (DD-MM-YYY HH:MM)</p>

                                                </v-flex>
                                            </v-layout>
                                            <v-layout row>
                                                <v-flex xs12 pa-1>
                                                    <v-text-field label="Pilih Gambar" hide-details @click='pickFile' v-model='imageName' prepend-icon='attach_file' class="mt-2"></v-text-field>
                                                    <input type="file" style="display: none" ref="image" accept="image/*" @change="onFilePicked">
                                                </v-flex>

                                            </v-layout>
                                        </v-card-text>
                                        <v-card-actions>
                                            <v-btn dark color="red" block @click="cancelOpenUpload()">batal</v-btn>
                                            <v-btn color="success" v-if="selected_receivereference.receive_date !== ''" block @click="upload">Upload</v-btn>
                                        </v-card-actions>
                                    </v-card> -->

</v-flex>
</v-layout>
</v-card-text>
<v-card-actions>
    <v-spacer></v-spacer>
    <v-btn v-if="xact === 'new'" :disabled="in_saving" color="blue" class="white--text ma-1"
        @click="saveFormPerusahaan()">Simpan</v-btn>
    <v-btn v-if="xact === 'edit'" color="blue" class="white--text ma-1" @click="saveMouDetail()">Simpan
        Perubahan</v-btn>
    <!-- <v-btn v-if="xact === 'edit'" color="blue" class="white--text ma-1" @click="updateFormPerusahaan()">Simpan Perubahan</v-btn>-->
    <v-btn v-if="xact === 'view'" color="blue" class="white--text ma-1" @click="revisiFormPerusahaan()">Buat
        Revisi</v-btn>
</v-card-actions>

</v-form>

</v-card>
<v-card>
            <v-layout row v-if="this.selected_receivereference.F_BillID">
                <v-flex xs12  pa-1>
                    <v-subheader red--text text--lighten-1>
                        <p class="mb-0"> Daftar Nota Penagihan No.</p>
                        <p class="mb-0"> {{ this.$store.state.receivereference.selected_receivereference.F_BillNumber }}
                            [ {{ this.$store.state.receivereference.selected_receivereference.CorporateName }} ]</p>
                        <v-flex text-md-right>
                          <!-- <v-btn :disabled="in_saving" color="blue" class="white--text ma-1"
                                @click="saveMouDetail()">
                                Simpan
                                <v-icon right dark>save_alt</v-icon>
                            --> 
                            </v-btn>
                        </v-flex>
                    </v-subheader>

                    <v-divider></v-divider>
                    <v-layout row>
                        <v-flex xs12  pa-1>
                            <v-layout row>
                                <v-flex class="text-sm-left" xs4 pl-1 pr-1 pt-1 pb-1>
                                    <v-text-field class="xs4 ma-1" label="Project" placeholder="Project"
                                        outline v-model="agreementProjectkeyword" hide-details></v-text-field>
                                </v-flex>
                                <v-flex class="text-sm-left" xs4 pl-1 pr-1 pt-1 pb-1>
                                    <v-text-field class="xs4 ma-1" label="No. Reg / Nama" placeholder="No. Reg / Nama"
                                        outline v-model="agreementDetailkeyword" hide-details></v-text-field>
                                </v-flex>
                                
                                <v-flex class="text-sm-left" xs4 pl-1 pr-1 pt-1 pb-1>                              
                                <v-select outline class="xs3 mini-select ma-1" :items="packets" item-text="T_PacketName" return-object v-model="selected_packet" label="Paket" outline
                hide-details></v-select>
            </v-flex>
                                <v-flex class="text-sm-left" xs4 pl-1 pr-1 pt-1 pb-1>
                                    <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="Filter Tanggal Awal" outline readonly v-on="on"
                                                @blur="date = deFormatedDate(filterComputedDateFormattedStart)"></v-text-field>
                                        </template>
                                        <v-date-picker v-model="init_sdate" no-title
                                            @input="menufilterdatestart = false"></v-date-picker>
                                    </v-menu>
                                </v-flex>
                                <v-flex class="text-sm-left" xs4 pl-1 pr-1 pt-1 pb-1>
                                    <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="Filter Tanggal Akhir" outline readonly v-on="on"
                                                @blur="date = deFormatedDate(filterComputedDateFormattedEnd)"></v-text-field>
                                        </template>
                                        <v-date-picker v-model="init_edate" no-title
                                            @input="menufilterdateend = false"></v-date-picker>
                                    </v-menu>
                                </v-flex>
                            </v-layout row>
                        </v-flex>
                    </v-layout row>
                    <v-layout row>
                        <v-flex xs12  pa-1>
                            <v-layout row>
                                <v-flex class="text-sm-left" xs6 pl-1 pr-1 pt-1 pb-1>
                                    <div class="pa-2" style="font-weight: bold; font-style: italic; color: chocolate;">
                                        <h2>Jumlah Pasien Terpilih: {{ selectedAgreementDetailList.length }}</h2>
                                    </div>
                                </v-flex>
                                <v-flex xs6  pa-1>
                                    <div class="text-tagihan text-xs-right"><h2>Jumlah Nominal Terpilih: {{ convertMoney(sum_total) }}</h2>
                                    </div>
                                </v-flex>
                            </v-layout row>
                        </v-flex>
                    </v-layout row>
                 <!--   <v-layout row v-if="is_having_detail && this.selected_receivereference.F_BillID">
                        <v-flex xs12>
                            <v-layout row>
                                <v-flex class="text-sm-left" xs4 pl-1 pr-1 pt-1 pb-1>
                                    <div class="pa-2" style="font-weight: bold; font-style: italic; color: chocolate;">
                                        Jumlah Pasien : {{ selectedAgreementDetailList.length }}
                                    </div>
                                </v-flex>
                                <v-flex class="text-sm-left" xs4 pl-1 pr-1 pt-1 pb-1>
                                </v-flex>
                                <v-flex xs4>
                                    <div class="text-tagihan text-xs-right"><kbd>{{ convertMoney(this.$store.state.receivereference.selected_receivereference.F_BillTotal) }}</kbd>
                                    </div>
                                </v-flex>
                            </v-layout row>
                        </v-flex>
                    </v-layout row>
                    -->
                    <v-layout row class="scroll-container" style="max-height:400px;max-width:100%;overflow: auto;">
                        <v-flex xs12 pl-2 pr-2 pt-2 pb-2 pa-1>

                            <v-data-table v-model="selectedAgreementDetailList" :headers="headers_detail" hide-actions
                                :items="agreementDetailListFilter" item-key="numberingx" select-all class="elevation-1">

                                <template v-slot:headers="props">
                                    <tr>
                                        <th style="width:5px" class="text-xs-left blue lighten-3 white--text">
                                            <v-checkbox  color="success" :input-value="props.all"
                                                :indeterminate="props.indeterminate" primary hide-details
                                                @click.stop="selectedAll()"></v-checkbox>
                                        </th>
                                        <th v-for="header in props.headers" :key="header.text" :class="header.class"
                                            :width="header.width">
                                            {{ header.text }}
                                        </th>
                                    </tr>
                                </template>

                                <template v-slot:items="props">
                                    <tr :active="props.selected" @click="props.selected = !props.selected">
                                        <td @click="selectMe(props.item)"
                                            v-bind:class="{ 'amber lighten-4': isSelected(props.item.numberingx) }">
                                            <v-checkbox :input-value="props.selected" primary hide-details></v-checkbox>
                                        </td>
                                        <td @click="selectMe(props.item)"
                                            v-bind:class="{ 'amber lighten-4': isSelected(props.item.numberingx) }">{{ props.item.T_OrderHeaderDate }}
                                        </td>
                                        <td @click="selectMe(props.item)"
                                            v-bind:class="{ 'amber lighten-4': isSelected(props.item.numberingx) }">{{props.item.Mgm_McuLabel }}
                                        </td>
                                        <td @click="selectMe(props.item)"
                                            v-bind:class="{ 'amber lighten-4': isSelected(props.item.numberingx) }">{{props.item.T_OrderHeaderLabNumber }}
                                        </td>
                                        <td @click="selectMe(props.item)"
                                            v-bind:class="{ 'amber lighten-4': isSelected(props.item.numberingx) }">{{ props.item.pasienname }}</td>
                                            <td @click="selectMe(props.item)"
                                            v-bind:class="{ 'amber lighten-4': isSelected(props.item.numberingx) }">{{ props.item.M_PatientNIP }}</td>
        <td @click="selectMe(props.item)" v-bind:class="{ 'amber lighten-4': isSelected(props.item.numberingx) }">{{ props.item.M_PatientDepartement }}</td>
        <td @click="selectMe(props.item)" v-bind:class="{ 'amber lighten-4': isSelected(props.item.numberingx) }">{{ props.item.M_PatientDivisi }}</td>
        <td @click="selectMe(props.item)" v-bind:class="{ 'amber lighten-4': isSelected(props.item.numberingx) }">{{ props.item.packetname}}</td>
                                        <td @click="selectMe(props.item)"
                                            v-bind:class="{ 'amber lighten-4': isSelected(props.item.numberingx) }">{{
                                            convertMoney(props.item.total) }}</td>
                                    </tr>
                                </template>
                            </v-data-table>

                        </v-flex>
                    </v-layout>
                    <v-layout row>
                        <v-flex xs12  pa-1>
                            <v-layout row>
                                <v-flex class="text-sm-left" xs6 pl-1 pr-1 pt-1 pb-1>
                                    <div class="pa-2" style="font-weight: bold; font-style: italic; color: chocolate;">
                                        <h2>Jumlah Pasien Paket {{ selected_packet.T_PacketName }} : {{ pasien_total_packet }}</h2>
                                    </div>
                                </v-flex>
                                <v-flex xs6  pa-1>
                                    <div class="text-tagihan text-xs-right"><h2> Jumlah Nominal Paket  {{ selected_packet.T_PacketName }}: {{ convertMoney(sum_total_packet) }}</h2>
                                    </div>
                                </v-flex>
                            </v-layout row>
                        </v-flex>
                    </v-layout row>
                    <v-layout row>
                        <v-flex xs12  pa-1>
                            <v-layout row>
                                <v-flex class="text-sm-left" xs6 pl-1 pr-1 pt-1 pb-1>
                                    <div class="pa-2" style="font-weight: bold; font-style: italic; color: chocolate;">
                                        <h2>Jumlah Semua Pasien : {{ agreementDetailList.length }}</h2>
                                    </div>
                                </v-flex>
                                <v-flex xs6  pa-1>
                                    <div class="text-tagihan text-xs-right"><h2>Jumlah Semua Nominal :{{ convertMoney(sum_total_all) }}</h2>
                                    </div>
                                </v-flex>
                            </v-layout row>
                        </v-flex>
                    </v-layout row>
                </v-flex>
            </v-layout>
            
        <v-card-actions>
    <v-spacer></v-spacer>
    <v-btn color="blue darken-1" flat @click="updateDialogFormOrder()">Tutup</v-btn>
   </v-card-actions>
        </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="blue darken-1" flat @click="updateDialogFormPrint()">Tutup</v-btn>
                        <v-btn color="blue darken-1" flat @click="printBill()">Cetak</v-btn>
                    </v-card-actions>
                    </v-form>
                </v-card>
            </v-dialog>
            <v-dialog v-model="dialogchooseprint" persistent max-width="40%">
            <v-card>
                <v-card-title class="headline white--text grey darken-1 pt-2 pb-2" primary-title style="color:white">
                    <h4>Pilih Format Laporan</h4>
                </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="Pilih Laporan"></v-select>
                                    </v-flex>
                                </v-layout>

                            </v-flex>
                        </v-layout>
                </v-card-text>
                <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>
                                            <v-radio-group v-model="formatreport" row>
                                                <v-radio color="grey" label="PDF" value="pdf"></v-radio>
                                                <v-radio color="grey" label="EXCEL" value="xls"></v-radio>
                                            </v-radio-group>
                                        </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="black" flat @click="dialogchooseprint = false">
                        Tutup
                    </v-btn>
                    <v-btn color="grey" 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="blue darken-1" flat @click="updateDialogFormPrintTagihan()">Tutup</v-btn>
                    <v-btn color="blue 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'),
        'one-bill-detail': httpVueLoader('./components/oneBillDetail.vue')
    },
    mounted() {
        this.$store.dispatch("receivereference/getsexreg")
        this.$store.dispatch("receivereference/getnomor")
        this.$store.dispatch("receivereference/search", {
            name: this.name,
            snorm: this.snorm,
            status: this.status.value,
            current_page: 1,
            lastid: -1
        })
    },
    methods: {
        cancelOpenUpload() {
            this.close_image_url = false
            this.$store.state.receivereference.selected_receivereference.receive_date = this.$store.state.receivereference
                .selected_receivereference.F_BillReceiveDate
        },
        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.F_BillID,
                billNo: this.$store.state.receivereference.selected_receivereference.F_BillNo,
                idbill: this.$store.state.receivereference.selected_receivereference.F_BillF_BillID,
                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.F_BillID,
                billNo: this.$store.state.receivereference.selected_receivereference.F_BillNo,
                idbill: this.$store.state.receivereference.selected_receivereference.F_BillF_BillID,
                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.F_BillID == this.$store.state.receivereference.selected_receivereference
                .F_BillID
        },
        convertMoney(money) {
            return one_money(money)
        },
        printNote(data) {
            this.$store.commit("receivereference/update_dialog_form_print", true)
            this.xno = data.F_BillNo
        },
        openprintformat(data) {
            this.xid = data.F_BillID
            this.formatreport = 'pdf'
            this.dialogchooseprint = true
        },
        printBill() {
            this.printwidth = 1200
            this.printtitle = ""
            var formatrpt = this.formatreport
            var tm = new Date()
            let user = one_user()
            var rpt = this.$store.state.receivereference.selected_cetak.t_url
            // console.log('rpt', rpt)
            // var xrpt = rpt.replace("rpt", "bill_rpt")
            var id = this.xid
            this.urlprintnote = rpt + "&__format=" + formatrpt + "&username=" +
                user.M_UserUsername + "&PID=" + id + "&tm=" + tm 
            this.$store.commit("receivereference/update_open_print_note", true)
        },
        printTagihan(data) {
            this.$store.commit("receivereference/update_dialog_form_print_tagihan", true)
            this.xno = data.F_BillNo
        },
        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.F_BillID
            this.urlprintnote = "/birt/run?__report=report/one/fo/rpt_t_009.rptdesign&__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,
                status: this.status.value,
                current_page: 1,
                lastid: -1
            })
        },

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

            this.$store.commit("receivereference/update_close_image_url_send", false)
            this.$store.commit("receivereference/update_image_url_send", 'empty')
            /* if (pat.F_BillImgSend) {
                this.$store.commit("receivereference/update_image_url_send", pat.F_BillImgSend)
            }
            */
            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_BillID,
                    mgmmcuid: pat.F_BillMgm_McuID,
                    packetid: this.selected_packet.T_PacketID,
                    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)
            }
            this.selectedAgreementDetailList = [];

        },
        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.F_BillID === this.$store.state
                .receivereference.last_id)
            console.log(idx)
            this.$store.dispatch("receivereference/search", {
                name: this.name,
                snorm: this.snorm,
                status: this.status.value,
                current_page: 1,
                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')

        },
        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
            }
        },
        setNewOrder() {
            this.$store.commit("receivereference/update_ordertests", [])
            this.$store.commit("receivereference/update_companies", [])
            this.$store.commit("receivereference/update_company", {})
            this.$store.commit("receivereference/update_branchs", [])
            this.$store.commit("receivereference/update_branch", {})
            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.xcompany = ''
            this.xproject = ''
            this.xbranch = ''
            this.xordertests = {}
            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,
                mgmmcuid: 0,
                packetid: 0,
                mouid: 0
            })
            console.log(this.xcompany)
        },
        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_company = ''
            this.search_bank = ''
        },
        saveFormPerusahaan() {
            this.$store.commit("receivereference/update_errors", [])
            var errors = this.$store.state.receivereference.errors
            if (_.isEmpty(this.xcompany)) {
                errors.push("requirexcompany")
            }
            if (_.isEmpty(this.xbranch)) {
                errors.push("requirexbranch")
            }
            if (_.isEmpty(this.xsdate)) {
                errors.push("requirexsdate")
            }
            var xrdate = this.$store.state.receivereference.selected_receivereference.receive_date
            if (this.imageUrl !== '') {
                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"

            } else {
                var rtanggal = '0000-00-00 00:00:00'
            }


            if (errors.length === 0) {
                if (this.in_saving) return;
                this.in_saving = true;
                this.$store.dispatch("receivereference/newreceivereference", {
                    priceheaderid: this.priceheaderid,
                    mgmmcuid: this.mcuIDs,
                    companyid: this.xcompany.CorporateID,
                    branchid: this.xbranch.M_BranchID,
                    branchcode: this.xbranch.M_BranchCodeLab,
                    bankid: this.xbank.M_BankAccountID,
                    sdate: this.xsdate,
                    note: this.xnote,
                    day: this.xdueday,
                    picname: this.xpicname,
                    pichp: this.xpichp,
                    picemail: this.xpicemail,
                    noref: this.xnoref,
                    img: this.imageUrl,
                    rdate: rdate,
                    rtanggal: rtanggal,
                    startdate: this.init_sdate,
                    enddate: this.init_edate,
                    isallmou: this.isallmou === true ? "Y" : "N"
                })
            }

        },
        updateFormPerusahaan() {
            this.$store.commit("receivereference/update_errors", [])
            var errors = this.$store.state.receivereference.errors
            if (_.isEmpty(this.xcompany)) {
                errors.push("requirexcompany")
            }
            if (_.isEmpty(this.xsdate)) {
                errors.push("requirexsdate")
            }
            if (errors.length === 0) {
                this.$store.dispatch("receivereference/editbill", {
                    id: this.xid,
                    sdate: this.xsdate,
                    note: this.xnote,
                    day: this.xdueday,
                    bankid: this.xbank.M_BankAccountID
                })
            }
        },
        revisiFormPerusahaan() {
            this.dialogprogress = true
            this.$store.commit("receivereference/update_errors", [])
            var errors = this.$store.state.receivereference.errors
            if (errors.length === 0) {
                this.$store.dispatch("receivereference/save_revisi", {
                    billID: this.xid,
                    branchcode: this.$store.state.receivereference.selected_receivereference.M_BranchCodeLab,
                    CorporateName: this.$store.state.receivereference.selected_receivereference.CorporateName
                })
            }
        },
        pilihmou(data) {
            this.xmou = {
                M_MouID: data.M_MouID,
                M_MouDesc: data.M_MouDesc
            }
            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.F_BillID
            this.xno = data.F_BillNo
            this.xpicname = data.F_BillPIC
            this.xnoref = data.F_BillRefNumber
            this.xpichp = data.F_BillPICHP
            this.xpicemail = data.F_BillPICEmail
            this.xtotal = data.F_BillTotal
            this.$store.commit("receivereference/update_companies", [{
                CorporateID: data.CorporateID,
                CorporateName: data.CorporateName
            }])
            this.xcompany = {
                CorporateID: data.CorporateID,
                CorporateName: data.CorporateName
            }

            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.F_BillDueDateDay
            this.xsdate = data.sdate
            this.xnote = data.F_BillNote
            this.$store.commit("receivereference/update_act_comp", 'edit')
            this.$store.commit("receivereference/update_dialog_form_order", true)
        },
        viewBill(data) {
            this.xid = data.F_BillID
            this.xno = data.F_BillNo
            this.xnoref = data.F_BillRefNumber
            this.xpicname = data.F_BillPIC
            this.xpichp = data.F_BillPICHP
            this.xpicemail = data.F_BillPICEmail
            this.$store.commit("receivereference/update_ordertests", data.projects)
            this.$store.commit("receivereference/update_companies", [{
                CorporateID: data.CorporateID,
                CorporateName: data.CorporateName
            }])
            this.$store.commit("receivereference/update_init_sdate", data.startdate)
            this.xcompany = {
                CorporateID: data.CorporateID,
                CorporateName: data.CorporateName
            }
            this.xdueday = data.F_BillDueDateDay
            this.xsdate = data.sdate
            this.xnote = data.F_BillNote
            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.$store.commit("receivereference/update_branchs", [{
                M_BranchID: data.M_BranchID,
                M_BranchCodeLab: data.M_BranchCodeLab,
                M_BranchName: data.M_BranchName
            }])
            this.xbranch = {
                M_BranchID: data.M_BranchID,
                M_BranchCodeLab: data.M_BranchCodeLab,
                M_BranchName: data.M_BranchName
            }
            this.$store.dispatch("receivereference/getpatient", {
                id: data.F_BillID,
                packetid: 0,
                mgmmcuid: data.F_BillMgm_McuID,
                startdate: data.init_sdate,
                enddate: this.init_edate,
                search: this.xsearch
            })

            this.$store.dispatch("receivereference/getpacket", { id: data.priceheaderid })
            this.$store.dispatch("receivereference/searchbank", '')
            this.$store.commit("receivereference/update_act_comp", 'edit')
            this.$store.commit("receivereference/update_dialog_form_order", true)
        },
        viewBillRevisi(data) {
            this.xid = data.F_BillID
            this.xno = data.F_BillNo
            this.xnoref = data.F_BillRefNumber
            this.xpicname = data.F_BillPIC
            this.xpichp = data.F_BillPICHP
            this.xpicemail = data.F_BillPICEmail
            this.$store.commit("receivereference/update_ordertests", data.projects)
            this.$store.commit("receivereference/update_companies", [{
                CorporateID: data.CorporateID,
                CorporateName: data.CorporateName
            }])

            this.xcompany = {
                CorporateID: data.CorporateID,
                CorporateName: data.CorporateName
            }
            this.xdueday = data.F_BillDueDateDay
            this.xsdate = data.sdate
            this.xnote = data.F_BillNote
            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.$store.commit("receivereference/update_branchs", [{
                M_BranchID: data.M_BranchID,
                M_BranchCodeLab: data.M_BranchCodeLab,
                M_BranchName: data.M_BranchName
            }])
            this.xbranch = {
                M_BranchID: data.M_BranchID,
                M_BranchCodeLab: data.M_BranchCodeLab,
                M_BranchName: data.M_BranchName
            }
            this.$store.dispatch("receivereference/getpatient", {
                id: data.F_BillID,
                packetid: 0,
                mgmmcuid: data.F_BillMgm_McuID,
                startdate: this.init_sdate,
                enddate: this.init_edate,
                search: this.xsearch
            })

            this.$store.dispatch("receivereference/getpacket", { id: data.priceheaderid })
            this.$store.commit("receivereference/update_act_comp", 'view')
            this.$store.commit("receivereference/update_dialog_form_order", true)
        },
        deleteBill(data) {
            this.xid = data.F_BillID
            var xdata = {
                id: data.F_BillID,
                name: data.F_BillNumber
            }
            this.msgalert = "Yakin, Mau Hapus No. Penagihan " + data.F_BillNo + "  ?"
            this.dialogdeletealert = true
        },
        notifBill(data) {
            this.xid = data.F_BillID
            var xdata = {
                id: data.F_BillID,
                name: data.F_BillNumber
            }
            this.msgalert = "Kirim Notifikasi No. Penagihan " + data.F_BillNo + " ke  " + data.F_BillPIC +
                " [" + data.F_BillPICEmail + "]"
            this.stattusnotif = data.statusnotif
            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),
        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.F_BillID === this.$store.state
                .receivereference.last_id)
            console.log(idx)
            this.$store.dispatch("receivereference/search", {
                name: this.name,
                snorm: this.snorm,
                status: this.status.value,
                current_page: 1,
                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')}`
        },
        // detail
        async save_patient() {
            let pat = this.$store.state.receivereference.selected_patient
            let billID = this.$store.state.receivereference.selected_receivereference.F_BillID
            let prm = {
                token: window.one_token(),
                billID: billID,
                patients: pat
            }
            await this.$store.dispatch("receivereference/save_patient", prm)
        },
        selectMe(item) {
            this.selectedAgreementDetail = item;
            console.log('selectMe')
            console.log(item)
        },
        isSelected(id) {
            if (this.selectedAgreementDetail.numberingx === id) {
                return true;
            } else {
                return false;
            }
        },
        selectedAll() {
            if (this.selectedAgreementDetailList.length)
        this.selectedAgreementDetailList = [];
      else
        this.selectedAgreementDetailList = this.agreementDetailListFilter.slice();
          /*  if (this.agreementDetailListFilter.length) {
                this.selectedAgreementDetailList = [];
            }
            else {
                //let filter = this.agreementDetailListFilter;
                let a = JSON.stringify(this.agreementDetailListFilter);
                let b = JSON.parse(a);
                const filter = b.filter(
                    (e) =>
                        e.F_BillID == null
                );
                
                console.log(filter);
                //this.agreementDetailListFilter = filter;
                this.selectedAgreementDetailList = filter.slice();

            }
                */
        },
        saveMouDetail() {
            this.dialogprogress = true
            let billID = this.xid
            let CorporateName = this.$store.state.receivereference.selected_receivereference.CorporateName
            let prm = {
                token: window.one_token(),
                billID: billID,
                CorporateName: CorporateName,
                data_insert: this.selectedAgreementDetailList,
                sdate: this.xsdate,
                note: this.xnote,
                day: this.xdueday,
                picname: this.xpicname,
                pichp: this.xpichp,
                picemail: this.xpicemail,
                bankid: this.xbank.M_BankAccountID
            }

            if (this.in_saving) return;
            this.in_saving = true;
            this.$store.dispatch(
                "receivereference/save_patient", prm
            );
        },
        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')}`
        },
        convertMoney(money) {
            return one_money(money)
        },
        thr_search: _.debounce(function () {
            this.$store.dispatch("receivereference/getpatient", {
                id: this.$store.state.receivereference.selected_receivereference.F_BillID,
                mgmmcuid: this.mcuIDs,
                packetid: this.selected_packet.T_PacketID,
                mouid: this.$store.state.receivereference.selected_receivereference.F_BillIsAllMou === "Y" ? "0" : this.$store.state.receivereference.selected_receivereference.F_BillM_MouID,
                startdate: this.init_sdate,
                enddate: this.init_edate,
                search: this.xsearch
            })
        }, 200),
        searchPacket() {
            /* this.$store.dispatch("receivereference/getpatient", {
                 id: this.$store.state.receivereference.selected_receivereference.F_BillID,
                 mgmmcuid: this.mcuIDs,
                 packetid: this.selected_packet.T_PacketID,
                 mouid: this.$store.state.receivereference.selected_receivereference.F_BillIsAllMou === "Y" ? "0" : this.$store.state.receivereference.selected_receivereference.F_BillM_MouID,
                 startdate: this.init_sdate,
                 enddate: this.init_edate,
                 search: this.xsearch
             })
                 */
        },
        searchBillStart() {
            /*  this.$store.dispatch("receivereference/getpatient", {
                  id: this.$store.state.receivereference.selected_receivereference.F_BillID,
                  mgmmcuid: this.mcuIDs,
                  packetid: this.selected_packet.T_PacketID,
                  mouid: this.$store.state.receivereference.selected_receivereference.F_BillIsAllMou === "Y" ? "0" : this.$store.state.receivereference.selected_receivereference.F_BillM_MouID,
                  startdate: this.init_sdate,
                  enddate: this.init_edate,
                  search: this.xsearch
              })
                  */
        },
        searchBillEnd() {
            /* this.$store.dispatch("receivereference/getpatient", {
                 id: this.$store.state.receivereference.selected_receivereference.F_BillID,
                 mgmmcuid: this.mcuIDs,
                 packetid: this.selected_packet.T_PacketID,
                 mouid: this.$store.state.receivereference.selected_receivereference.F_BillIsAllMou === "Y" ? "0" : this.$store.state.receivereference.selected_receivereference.F_BillM_MouID,
                 startdate: this.init_sdate,
                 enddate: this.init_edate,
                 search: this.xsearch
             })
                 */
        },
        async saveNewPatient() {
            if (this.in_saving) return;
            this.in_saving = true;
            this.$store.dispatch("receivereference/getpatientbeforesave", {
                id: this.$store.state.receivereference.selected_receivereference.F_BillID,
                mouid: this.$store.state.receivereference.selected_receivereference.F_BillIsAllMou === 'Y' ? 0 : this.$store.state.receivereference.selected_receivereference.F_BillM_MouID,
                startdate: this.init_sdate,
                enddate: this.init_edate,
                search: '',
                company: this.$store.state.receivereference.selected_receivereference.CorporateName
            })
            /*      
            let patients = this.$store.state.receivereference.patients
            let pat = _.filter(patients, function (it) {
                return it.checx == 'Y'
            })
            var prm = {}
            prm.billID = this.$store.state.receivereference.selected_receivereference.F_BillID
            prm.CorporateName = this.$store.state.receivereference.selected_receivereference.CorporateName
            prm.patients = pat
            this.$store.dispatch("receivereference/savenewpatient", prm)
            */

        },
        changeCbxAllold(value) {
            var arr = this.agreementDetailListFilter
            this.indeterminatex = false
            arr.forEach((el) => {
                el.chex = value
            })
            var selected = _.filter(arr, function (o) {
                return o.chex;
            })
            this.$store.commit("receivereference/update_selected_patient", selected)

        },
        checkTopold(pat) {
            let patients = this.$store.state.receivereference.patients
            let idx = _.findIndex(patients, function (p) {
                return p.T_OrderHeaderID == pat.T_OrderHeaderID
            });
            patients[idx].checx = !patients[idx].chex
            var selected = _.filter(patients, function (o) {
                return o.chex;
            })

            console.log(selected)
            this.$store.commit("receivereference/update_selected_patient", selected)
        },
        changeCbxAlloldold(value) {

            var chx_all = value === false ? true : false
            this.$store.commit("receivereference/update_bar_chx_all", chx_all)

            if (this.in_saving) return;
            this.in_saving = true;
            let patients = this.$store.state.receivereference.patients
            let pat = _.filter(patients, function (it) {
                return it.isbill == 'N'
            })
            var prm = {}
            prm.billID = this.$store.state.receivereference.selected_receivereference.F_BillID
            prm.status = value === false ? 'Y' : 'N'
            prm.patients = pat
            prm.isallmou = this.$store.state.receivereference.selected_receivereference.F_BillIsAllMou
            prm.mouID = this.$store.state.receivereference.selected_receivereference.F_BillM_MouID
            prm.startdate = this.init_sdate
            prm.enddate = this.init_edate
            prm.search = this.xsearch
            this.$store.dispatch("receivereference/saveall_tempbill", prm)


        },
        changeCbxAll() {
        },
        checkTop(pat) {
            pat.checx === 'N' ? 'Y' : 'N'
            this.selectedAgreementDetail = pat;
            /*  var newval = pat.checx === 'N' ? 'Y' : 'N'
              var prm = pat
              prm.checx = newval
              prm.billid = this.$store.state.receivereference.selected_receivereference.F_BillID
              prm.isallmou = this.$store.state.receivereference.selected_receivereference.F_BillIsAllMou
              prm.mouid = pat.M_MouID
              prm.headerid = pat.T_OrderHeaderID
              prm.id = pat.Temp_BillID
              prm.total = pat.total
              prm.startdate = this.init_sdate
              prm.enddate = this.init_edate
              prm.search = this.xsearch
  
              this.$store.dispatch("receivereference/save_tempbill", prm)
              */
        },
        createNewPatient() {
            this.$store.commit("receivereference/update_act_pat", 'new')
            this.xnoref = ''
            this.namapasien = ''
            this.$store.commit("receivereference/update_selected_sex", [])
            this.xdob = ''
            this.$store.commit("receivereference/update_ordertests", [])
            this.$store.commit("receivereference/update_dialog_form_patient", true)
        },
        checkError(value) {
            var errors = this.$store.state.receivereference.errors
            if (errors.includes(value)) {
                return true
            } else {
                return false
            }
        },
        thr_search_test: _.debounce(function () {
            this.$store.dispatch("receivereference/searchtest", {
                tes: this.search_test,
                mouid: this.$store.state.receivereference.selected_receivereference.T_ReceiveReferenceHeaderM_MouID
            })
        }, 2000),
        doDeletePat() {
            var prm = {}
            prm.T_ReceiveReferencePatientT_ReceiveReferenceHeaderID = this.$store.state.receivereference.selected_receivereference
                .T_ReceiveReferenceHeaderID
            prm.T_ReceiveReferencePatientID = this.$store.state.receivereference.x_pat_id
            prm.T_ReceiveReferencePatientName = this.namapasien
            prm.CorporateName = this.$store.state.receivereference.selected_receivereference.CorporateName
            this.$store.dispatch("receivereference/deletepatient", prm)
        },
        sendOrderPatient(value) {
            let msg = "Yakin, akan mengirim permintaan nomor " + this.$store.state.receivereference.selected_receivereference
                .T_ReceiveReferenceHeaderNumber + " ?"
            this.$store.commit("receivereference/update_msg_confirmation_send", msg)
            this.$store.commit("receivereference/update_dialog_confirmation_send", true)
        },
        doOrderPatient() {
            var prm = {}
            prm.T_ReceiveReferenceHeaderID = this.$store.state.receivereference.selected_receivereference
                .T_ReceiveReferenceHeaderID
            prm.T_ReceiveReferenceHeaderNumber = this.$store.state.receivereference.selected_receivereference
                .T_ReceiveReferenceHeaderNumber
            this.$store.dispatch("receivereference/sendorder", prm)
        },
        convertMoney(money) {
            return one_money(money)
        },
        addProject() {
            var oldArr = this.$store.state.receivereference.ordertests
            oldArr.push(this.$store.state.receivereference.project)
            this.$store.commit("receivereference/update_project", {})
            var mcuIDs = oldArr.map(function (item) {
                return item.Mgm_McuID;
            }).join(',');
            this.$store.dispatch("receivereference/getbranch", { id: mcuIDs })
            console.log(mcuIDs)
            this.mcuIDs = mcuIDs

            var priceheaderid = oldArr.map(function (item) {
                return item.Mgm_McuT_PriceHeaderID;
            }).join(',');
            this.priceheaderid = priceheaderid
            this.$store.dispatch("receivereference/getpacket", { id: priceheaderid })
        },
        deleteDataPx(idx) {
            var inx = parseInt(idx);
            var xrow = this.$store.state.receivereference.ordertests[inx]
            if (parseInt(xrow.xid) !== 0) {
                var xdeltest = this.$store.state.receivereference.deleted_ordertests
                xdeltest.push(xrow)
                this.$store.commit("receivereference/update_deleted_ordertests", xdeltest)
            }
            var oldArr = this.$store.state.receivereference.ordertests
            oldArr.splice(inx, 1)
            this.$store.commit("receivereference/update_ordertests", oldArr)
        },

    },
    computed: {
        dialogprogress: {
            get() {
                return this.$store.state.receivereference.dialog_progress
            },
            set(v) {
                this.$store.commit("receivereference/update_dialog_progress", v)
            }
        },
        mcuIDs: {
            get() {
                return this.$store.state.receivereference.mcuIDs
            },
            set(val) {
                this.$store.commit("receivereference/update_mcuIDs", val)
            }
        },
        priceheaderid: {
            get() {
                return this.$store.state.receivereference.priceheaderid
            },
            set(val) {
                this.$store.commit("receivereference/update_priceheaderid", val)
            }
        },
        selected_receivereference: {
            get() {
                return this.$store.state.receivereference.selected_receivereference
            },
            set(val) {
                this.$store.commit("receivereference/update_selected_receivereference", val)
            }
        },
        selectedAgreementDetailList: {
            get() {
                return this.$store.state.receivereference.selectedAgreementDetailList;
            },
            set(val) {
                this.$store.commit("receivereference/update_selectedAgreementDetailList", val);
            },
        },
        curr_page: {
            get() {
                return this.$store.state.receivereference.current_page
            },
            set(val) {
                this.$store.commit("receivereference/update_current_page", val)
                this.$store.dispatch("receivereference/search", {
            name: this.name,
            snorm: this.snorm,
            status: this.status.value,
            current_page: val,
            lastid: -1
        })
            }
        },
        xtotal_page: {
            get() {
                return this.$store.state.receivereference.total_data
            },
            set(val) {
                this.$store.commit("receivereference/update_total_data", 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
        },
        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)
            }
        },
        packets() {
            return this.$store.state.receivereference.packets
        },
        selected_packet: {
            get() {
                return this.$store.state.receivereference.selected_packet
            },
            set(val) {
                this.$store.commit("receivereference/update_selected_packet", val)
                /* this.$store.dispatch("receivereference/getpatient", {
                 id: this.$store.state.receivereference.selected_receivereference.F_BillID,
                 packetid: val.T_PacketID,
                 mouid: this.$store.state.receivereference.selected_receivereference.F_BillIsAllMou === "Y" ? "0" : this.$store.state.receivereference.selected_receivereference.F_BillM_MouID,
                 startdate: this.init_sdate,
                 enddate: this.init_edate,
                 search: this.xsearch
             })
                 */

            }
        },
        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
        },
        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
        },
        xcompany: {
            get() {
                return this.$store.state.receivereference.company
            },
            set(val) {
                this.$store.commit("receivereference/update_company", val)
                if (this.xid == 0) {
                    this.$store.commit("receivereference/update_picname", val.CorporatePICBillName)
                    this.$store.commit("receivereference/update_pichp", val.CorporatePICBillPhone)
                    this.$store.commit("receivereference/update_picemail", val.CorporatePICBillEmail)
                    this.$store.commit("receivereference/update_dueday", val.CorporateDueDate)
                    var dueDate = moment(new Date(new Date().getTime() + (val.CorporateDueDate * 24 * 60 * 60 * 1000))).format(
                        'YYYY-MM-DD')
                    this.$store.commit("receivereference/update_sdate", dueDate)
                    this.$store.dispatch("receivereference/searchproject", { id: val.CorporateID })
                    // this.$store.dispatch("receivereference/getpacket", { id: val.Mgm_McuT_PriceHeaderID })
                }

            }
        },
        xprojects() {
            return this.$store.state.receivereference.projects
        },
        xproject: {
            get() {
                return this.$store.state.receivereference.project
            },
            set(val) {
                this.$store.commit("receivereference/update_project", val)
                // this.$store.dispatch("receivereference/getpacket", { id: val.Mgm_McuT_PriceHeaderID })

            }
        },
        xbranchs() {
            return this.$store.state.receivereference.branchs
        },
        xbranch: {
            get() {
                return this.$store.state.receivereference.branch
            },
            set(val) {
                this.$store.commit("receivereference/update_branch", 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)
            }
        },
        // detail
        sumtotal: {
            get() {
                return this.$store.state.receivereference.sumtotal
            },
            set(val) {
                this.$store.commit("receivereference/update_sumtotal", val)
            }
        },
        sum_total() {
            let tests = this.selectedAgreementDetailList
            console.log(tests)
            sum_total = 0
            tests.forEach(function (t, idx) {
                let total = parseInt(t.total)
                sum_total += total
            })

            return sum_total
        },
        sum_total_all() {
            let tests = this.agreementDetailList
            console.log(tests)
            sum_total_all = 0
            tests.forEach(function (t, idx) {
                let total = parseInt(t.total)
                sum_total_all += total
            })

            return sum_total_all
        },
        sum_total_packet() {
            let tests = this.agreementDetailList
            let packetid = this.$store.state.receivereference.selected_packet.T_PacketID
            console.log(packetid)
            sum_total_packet = 0
            if (packetid == 0) {
                sum_total_packet = 0
                tests.forEach(function (t, idx) {
                    let total = parseInt(t.total)
                    sum_total_packet += total
                })
                return sum_total_packet
            } else {
                sum_total_packet = 0
                tests.forEach(function (t, idx) {
                    if (t.T_PacketID == packetid) {
                        let total = parseInt(t.total)
                        sum_total_packet += total
                    }

                })

                return sum_total_packet
            }

        },
        pasien_total_packet() {
            //  let tests = this.agreementDetailList
            let packetid = this.$store.state.receivereference.selected_packet
            //  let pasien_total_packet = tests.filter(item => item.T_PacketID == packetid).length

            let a = JSON.stringify(this.agreementDetailList);
            let b = JSON.parse(a);
            const pasien_total_packet = b.filter(
                (e) => (packetid.T_PacketID == 0 || (packetid.T_PacketID > 0 && e.T_PacketID == packetid.T_PacketID))
            ).length;
            console.log(pasien_total_packet);
            return pasien_total_packet
            // this.agreementDetailListFilter = filter;

            /*  if (packetid == 0) {
                  let pasien_total_packet = this.agreementDetailList.length
                  return pasien_total_packet
              } else {
                  let pasien_total_packet = tests.filter(item => item.T_PacketID == packetid).length
                  return pasien_total_packet
              }
                  */
            return pasien_total_packet

        },
        sum_total_filter() {
            let tests = this.agreementDetailListFilter
            console.log(tests)
            sum_total_filter = 0
            tests.forEach(function (t, idx) {
                let total = parseInt(t.total)
                sum_total_filter += total
            })

            return sum_total_filter
        },
        ctotal: {
            get() {
                return this.$store.state.receivereference.ctotal
            },
            set(val) {
                this.$store.commit("receivereference/update_ctotal", val)
            }
        },
        bar_chx_all: {
            get() {
                return this.$store.state.receivereference.bar_chx_all
            },
            set(val) {
                this.$store.commit("receivereference/update_bar_chx_all", val)
            }
        },
        indeterminatex: {
            get() {
                return this.$store.state.receivereference.indeterminatex
            },
            set(val) {
                this.$store.commit("receivereference/update_indeterminatex", val)
            }
        },
        selectedAgreementDetailList: {
            get() {
                return this.$store.state.receivereference.selectedAgreementDetailList;
            },
            set(val) {
                console.log("change selectedAgreementDetailList");
                this.$store.commit("receivereference/update_selectedAgreementDetailList", val);
            },
        },
        selectedAgreementDetail: {
            get() {
                return this.$store.state.receivereference.selectedAgreementDetail;
            },
            set(val) {
                this.$store.commit("receivereference/update_selectedAgreementDetail", val);
            },
        },
        dialogconfirmationdeletepat: {
            get() {
                return this.$store.state.receivereference.dialog_confirmation_delete_pat
            },
            set(val) {
                this.$store.commit("receivereference/update_dialog_confirmation_delete_pat", val)
            }
        },
        msgconfirmationdeletepat() {
            return this.$store.state.receivereference.msg_confirmation_delete_pat
        },
        dialogconfirmationsend: {
            get() {
                return this.$store.state.receivereference.dialog_confirmation_send
            },
            set(val) {
                this.$store.commit("receivereference/update_dialog_confirmation_send", val)
            }
        },
        msgconfirmationsend() {
            return this.$store.state.receivereference.msg_confirmation_send
        },
        xactpat() {
            return this.$store.state.receivereference.act_pat
        },
        xactsend() {
            return this.$store.state.receivereference.act_send
        },

        dialogformpatient: {
            get() {
                return this.$store.state.receivereference.dialog_form_patient
            },
            set(val) {
                this.$store.commit("receivereference/update_dialog_form_patient", val)
            }
        },
        isLoading() {
            return this.$store.state.receivereference.search_status == 1
        },
        agreementDetailList: {
            get() {
                return this.$store.state.receivereference.agreementDetailList;
            },
            set(val) {
                console.log("change agreementDetailList");
                this.$store.commit("receivereference/update_agreementDetailList", val);
            },
        },
        agreementDetailListFilter: {
            get() {
                return this.$store.state.receivereference.agreementDetailListFilter;
            },
            set(val) {
                console.log("change agreementDetailListFilter");
                this.$store.commit("receivereference/update_agreementDetailListFilter", val);
            },
        },
        agreementDetailkeyword: {
            get() {
                return this.$store.state.receivereference.agreementDetailkeyword;
            },
            set(val) {
                this.$store.commit("receivereference/update_agreementDetailkeyword", val);
            },
        },
        agreementProjectkeyword: {
            get() {
                return this.$store.state.receivereference.agreementProjectkeyword;
            },
            set(val) {
                this.$store.commit("receivereference/update_agreementProjectkeyword", val);
            },
        },
        filterComputedDateFormattedStart() {
            return this.formatDate(this.init_sdate)
        },
        filterComputedDateFormattedEnd() {
            return this.formatDate(this.init_edate)
        },
        xsearch: {
            get() {
                return this.$store.state.receivereference.xsearch
            },
            set(val) {
                this.$store.commit("receivereference/update_xsearch", 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)
            }
        },
        xnoref: {
            get() {
                return this.$store.state.receivereference.noref
            },
            set(val) {
                this.$store.commit("receivereference/update_noref", val)
            }
        },
        namapasien: {
            get() {
                return this.$store.state.receivereference.namapasien
            },
            set(val) {
                this.$store.commit("receivereference/update_nama_pasien", val)
            }
        },
        xdob: {
            get() {
                return this.$store.state.receivereference.dob
            },
            set(val) {
                this.$store.commit("receivereference/update_dob", val)
            }
        },
        xsexes() {
            return this.$store.state.receivereference.sexes
        },
        xsex: {
            get() {
                return this.$store.state.receivereference.selected_sex
            },
            set(val) {
                this.$store.commit("receivereference/update_selected_sex", val)
            }
        },
        xorderautotests() {
            return this.$store.state.receivereference.orderautotests
        },
        xorderautotest: {
            get() {
                return this.$store.state.receivereference.orderautotest
            },
            set(val) {
                this.$store.commit("receivereference/update_orderautotest", val)
            }
        },
        xordertests() {
            return this.$store.state.receivereference.ordertests
        },
        sub_total() {
            let tests = this.xordertests
            sub_total = 0
            tests.forEach(function (vpx, idx) {
                let total = parseInt(vpx.total)
                sub_total = sub_total + total
            })
            return sub_total
        },
        dp() {
            let mindp = this.$store.state.receivereference.selected_receivereference.M_MouMinDP
            let dp = mindp / 100 * this.sub_total
            return dp
        },
        isbill() {
            let isbill = this.$store.state.receivereference.selected_receivereference.M_MouIsBill
            return isbill
        },
        isagingonhold() {
            let isagingonhold = this.$store.state.receivereference.selected_receivereference.M_MouIsAgingOnHold
            return isagingonhold
        },
        agingonhold() {
            let agingonhold = this.$store.state.receivereference.selected_receivereference.M_MouIsAgingOnHoldNote
            return agingonhold
        },
        is_having_detail() {
            if (this.$store.state.receivereference.selected_receivereference.haveDetail == 'Y') return true
            return false
        },
        in_saving: {
            get() {
                return this.$store.state.receivereference.in_saving
            },
            set(val) {
                this.$store.commit("receivereference/update_in_saving", val)
            }
        }
    },
    data() {
        return {
            imageName: '',
            imageUrl: '',
            imageFile: '',
            imageNameSend: '',
            imageUrlSend: '',
            imageFileSend: '',
            msgalertconfirmation: "Perubahan yang telah dilakukan belum disimpan dong !",
            items: [],
            xid: 0,
            xno: '',
            xtotal: 0,
            name: '',
            snorm: '',
            msgalert: "",
            stattusnotif: "N",
            dialogdeletealert: false,
            dialognotifalert: false,
            dialogmou: false,
            search_company: '',
            search_bank: '',
            menusdate: false,
            urlprintnote: '',
            printtitle: '',
            printwidth: '80%',
            dialogchooseprint: false,
            formatreport: 'pdf',
            ndate: moment(new Date()).format('YYYY-MM-DD'),
            date: new Date().toISOString().substr(0, 10),
            disabledDates: {
                to: new Date(Date.now() - 8640000)
            },
            page: 1,
            oldlabel: '',
            search_test: '',
            menufilterdatestart: false,
            menufilterdateend: false,
            headers_detail: [{
                text: "TGL",
                align: "left",
                sortable: false,
                value: "lab",
                width: "10%",
                class: "pa-1 blue lighten-3 white--text"
            },
            {
                text: "PROJECT",
                align: "left",
                sortable: false,
                value: "mr",
                width: "20%",
                class: "pa-1 blue lighten-3 white--text"
            },
            {
                text: "NO. REG",
                align: "left",
                sortable: false,
                value: "mr",
                width: "5%",
                class: "pa-1 blue lighten-3 white--text"
            },
            {
                text: "NAMA",
                align: "left",
                sortable: false,
                value: "lab",
                width: "20%",
                class: "pa-1 blue lighten-3 white--text"
            },
            {
                text: "NIP",
                align: "left",
                sortable: false,
                value: "lab",
                width: "5%",
                class: "pa-1 blue lighten-3 white--text"
            },
            {
                text: "DEPARTEMEN",
                align: "left",
                sortable: false,
                value: "lab",
                width: "10%",
                class: "pa-1 blue lighten-3 white--text"
            },
            {
                text: "DIVISI",
                align: "left",
                sortable: false,
                value: "lab",
                width: "5%",
                class: "pa-1 blue lighten-3 white--text"
            },
            {
                text: "PAKET",
                align: "left",
                sortable: false,
                value: "lab",
                width: "20%",
                class: "pa-1 blue lighten-3 white--text"
            },
            {
                text: "TOTAL",
                align: "left",
                sortable: false,
                value: "lab",
                width: "5%",
                class: "pa-1 blue lighten-3 white--text"
            }
            ],
            headers: [{
                text: "NO. PENAGIHAN",
                align: "center",
                sortable: false,
                value: "mr",
                width: "10%",
                class: "pa-2 blue lighten-3 white--text"
            },
            {
                text: "TGL. PENAGIHAN",
                align: "center",
                sortable: false,
                value: "mr",
                width: "10%",
                class: "pa-2 blue lighten-3 white--text"
            },
            {
                text: "JATUH TEMPO",
                align: "center",
                sortable: false,
                value: "mr",
                width: "10%",
                class: "pa-2 blue lighten-3 white--text"
            },

            {
                text: "CORPORATE",
                align: "center",
                sortable: false,
                value: "lab",
                width: "20%",
                class: "pa-2 blue lighten-3 white--text"
            },
            {
                text: "PROJECT",
                align: "center",
                sortable: false,
                value: "lab",
                width: "20%",
                class: "pa-2 blue lighten-3 white--text"
            },
            {
                text: "TOTAL PENAGIHAN",
                align: "center",
                sortable: false,
                value: "name",
                width: "10%",
                class: "pa-2 blue lighten-3 white--text"
            },
            {
                text: "AKSI",
                align: "center",
                sortable: false,
                value: "name",
                width: "10%",
                class: "pa-2 blue lighten-3 white--text"
            }
            ],
            headersmou: [{
                text: "NAMA AGREEMENT",
                align: "center",
                sortable: false,
                value: "mr",
                width: "7%",
                class: "pa-2 blue lighten-3 white--text"
            },
            {
                text: "JATUH TEMPO (HARI)",
                align: "center",
                sortable: false,
                value: "mr",
                width: "15%",
                class: "pa-2 blue lighten-3 white--text"
            },
            {
                text: "TGL JATUH TEMPO",
                align: "center",
                sortable: false,
                value: "mr",
                width: "7%",
                class: "pa-2 blue lighten-3 white--text"
            },
            {
                text: "NAMA PIC",
                align: "center",
                sortable: false,
                value: "lab",
                width: "12%",
                class: "pa-2 blue lighten-3 white--text"
            },
            {
                text: "EMAIL PIC",
                align: "center",
                sortable: false,
                value: "name",
                width: "7%",
                class: "pa-2 blue lighten-3 white--text"
            },
            {
                text: "AKSI",
                align: "center",
                sortable: false,
                value: "name",
                width: "15%",
                class: "pa-2 blue lighten-3 white--text"
            }
            ],
            pagination: {
                descending: true,
                page: 1,
                rowsPerPage: 5,
                sortBy: 'F_BillNumber',
                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()
        },
        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()
        },
        // detail
        agreementDetailkeyword(val, old) {

            let s_date = moment(this.init_sdate).format('DD-MM-YYYY');
            let e_date = moment(this.init_edate).format('DD-MM-YYYY');
            let mculabel = this.$store.state.receivereference.agreementProjectkeyword;
            let packet = this.$store.state.receivereference.selected_packet;
            //alert(packet.T_PacketName)
            let a = JSON.stringify(this.agreementDetailList);
            let b = JSON.parse(a);
            const parseDate = (dateStr) => {
    const [day, month, year] = dateStr.split('-');
    return new Date(`${year}-${month}-${day}`);
};
            const filter = b.filter(
                (e) =>
                    (e.pasienname.toLowerCase().includes(val) || e.T_OrderHeaderLabNumber.includes(val)) &&
                    (parseDate(e.T_OrderHeaderDate) >= parseDate(s_date) && parseDate(e.T_OrderHeaderDate) <= parseDate(e_date)) &&
                    (mculabel === '' || e.Mgm_McuLabel.toLowerCase().includes(mculabel)) &&
                    (packet.T_PacketID == 0 || (packet.T_PacketID > 0 && e.T_PacketID == packet.T_PacketID))

            );
            console.log(filter);
            this.agreementDetailListFilter = filter;
        },
        agreementProjectkeyword(val, old) {
            let pat = this.$store.state.receivereference.agreementDetailkeyword;
            let s_date = moment(this.init_sdate).format('DD-MM-YYYY');
            let e_date = moment(this.init_edate).format('DD-MM-YYYY');
            let packet = this.$store.state.receivereference.selected_packet;
            let a = JSON.stringify(this.agreementDetailList);
            let b = JSON.parse(a);
            const parseDate = (dateStr) => {
    const [day, month, year] = dateStr.split('-');
    return new Date(`${year}-${month}-${day}`);
};
            const filter = b.filter(
                (e) =>
                    (e.pasienname.toLowerCase().includes(pat) || e.T_OrderHeaderLabNumber.includes(pat)) &&
                    (parseDate(e.T_OrderHeaderDate) >= parseDate(s_date) && parseDate(e.T_OrderHeaderDate) <= parseDate(e_date)) &&
                    (val === '' || e.Mgm_McuLabel.toLowerCase().includes(val)) &&
                    (packet.T_PacketID == 0 || (packet.T_PacketID > 0 && e.T_PacketID == packet.T_PacketID))
            );
            console.log(filter);
            this.agreementDetailListFilter = filter;
        },
        selected_packet(val, old) {
            // alert(val.T_PacketName)
            let pat = this.$store.state.receivereference.agreementDetailkeyword;
            let s_date = moment(this.init_sdate).format('DD-MM-YYYY');
            let e_date = moment(this.init_edate).format('DD-MM-YYYY');
            let mculabel = this.$store.state.receivereference.agreementProjectkeyword;
            let a = JSON.stringify(this.agreementDetailList);
            let b = JSON.parse(a);
            const parseDate = (dateStr) => {
    const [day, month, year] = dateStr.split('-');
    return new Date(`${year}-${month}-${day}`);
};
            const filter = b.filter(
                    (e) =>
                        (pat === '' || e.pasienname.toLowerCase().includes(pat) || e.T_OrderHeaderLabNumber.includes(pat)) &&
                        (parseDate(e.T_OrderHeaderDate) >= parseDate(s_date) && parseDate(e.T_OrderHeaderDate) <= parseDate(e_date)) &&
                        (mculabel === '' || e.Mgm_McuLabel.toLowerCase().includes(mculabel)) &&
                        (val.T_PacketID == 0 || e.T_PacketID == val.T_PacketID)
                );
                console.log('selected_packet')
                console.log(filter);
                this.agreementDetailListFilter = filter;
            
            
        },
        init_sdate(val, old) {
            let pat = this.$store.state.receivereference.agreementDetailkeyword;
            let s_date = moment(val).format('DD-MM-YYYY');
            let mculabel = this.$store.state.receivereference.agreementProjectkeyword;
            let packet = this.$store.state.receivereference.selected_packet;
            console.log(s_date)
            let a = JSON.stringify(this.agreementDetailList);
            let b = JSON.parse(a);
            let xdate = moment(this.init_edate).format('DD-MM-YYYY');
            const parseDate = (dateStr) => {
    const [day, month, year] = dateStr.split('-');
    return new Date(`${year}-${month}-${day}`);
};
            const filter = b.filter(
                (e) =>
                    (e.pasienname.toLowerCase().includes(pat) || e.T_OrderHeaderLabNumber.includes(pat)) &&
                    (parseDate(e.T_OrderHeaderDate) >= parseDate(s_date) && parseDate(e.T_OrderHeaderDate) <= parseDate(xdate)) &&
                    (mculabel === '' || e.Mgm_McuLabel.toLowerCase().includes(mculabel)) &&
                    (packet.T_PacketID == 0 || (packet.T_PacketID > 0 && e.T_PacketID == packet.T_PacketID))

            );
            console.log(filter);
            this.agreementDetailListFilter = filter;
        },
        init_edate(val, old) {
            let pat = this.$store.state.receivereference.agreementDetailkeyword;
            let e_date = moment(val).format('DD-MM-YYYY');
            let mculabel = this.$store.state.receivereference.agreementProjectkeyword;
            let packet = this.$store.state.receivereference.selected_packet;
            console.log(e_date)

            let a = JSON.stringify(this.agreementDetailList);
            let b = JSON.parse(a);
            let xdate = moment(this.init_sdate).format('DD-MM-YYYY');
            const parseDate = (dateStr) => {
    const [day, month, year] = dateStr.split('-');
    return new Date(`${year}-${month}-${day}`);
};
            const filter = b.filter(
                (e) =>
                    (e.pasienname.toLowerCase().includes(pat) || e.T_OrderHeaderLabNumber.includes(pat)) &&
                    (parseDate(e.T_OrderHeaderDate) >= parseDate(xdate) && parseDate(e.T_OrderHeaderDate) <= parseDate(e_date)) &&
                    (mculabel === '' || e.Mgm_McuLabel.toLowerCase().includes(mculabel)) &&
                    (packet.T_PacketID == 0 || (packet.T_PacketID > 0 && e.T_PacketID == packet.T_PacketID))
            );
            console.log(filter);
            this.agreementDetailListFilter = filter;
        },
        agreementDetailListFilter(val, old) {
            console.log(val);
            // let tmp = this.agreementDetailList;
            // val.forEach((e) => {
            //   tmp.forEach((f) => {
            //     if (e.numberingx === f.numberingx) {
            //       f = e;
            //     }
            //   });
            // });
            // this.agreementDetailList = tmp;
        },
        xsearch(val, old) {
            console.log(val)
            this.xsearch = val
            this.thr_search()
        },
        search_city(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_city()
        },
        search_test(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_test()
        }
    }
}
</script>
