<template>
      <v-layout column>
            <v-layout>

                  <v-flex xs12 class="right">
                        <v-card class=" mb-2 pa-3 searchbox">
                              <v-layout>
                                    <v-flex xs12 class="right">
                                          <v-btn @click="refreshLog()" color="green">REFRESH
                                          </v-btn>
                                    </v-flex>
                              </v-layout>
                        </v-card>
                  </v-flex>
                  <v-spacer></v-spacer>
            </v-layout>


      </v-layout>



</template>



<style scoped>
      span.xtd {
            margin-right: 10px;
      }

      .searchbox .v-input.v-text-field .v-input__slot {
            min-height: 40px;
      }

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

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

      table.v-table thead tr {
            height: 40px;
      }

      .v-messages {
            min-height: 0px !important;
      }
</style>

<script>
      module.exports = {
            components: {

            },
            mounted() {},
            methods: {


                  selectMe(pat) {
                        this.$store.commit("close/update_selected_close", pat)
                  },

                  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')}`
                  },
                  isSelected(p) {
                        return p.T_OrderHeaderID == this.$store.state.close.selected_close.T_OrderHeaderID
                  },
                  searchClose() {
                        this.$store.dispatch("close/search", {
                              startdate: this.xstartdate,
                              enddate: this.xenddate,
                              search: this.searchnamelab,
                              status: this.status.value,
                              current_page: 1,
                              lastidx: 0
                        })
                  },
                  refreshLog() {
                        this.$store.dispatch("info/lookupbyname")
                        this.$store.dispatch("register/lookupbyname")
                  },
                  printControlCard(value) {
                        this.printwidth = "800"
                        this.printtitle = ""
                        let user = one_user()
                        var tm = new Date()
                        var formatrpt = "pdf"
                        var branchid = this.selected_filter_branch.M_BranchID
                        this.xurl =
                              "https://regonline.pramita.co.id/birt/run?__report=report/one/fo/rpt_onlite_002.rptdesign&__format=" +
                              formatrpt + "&PStartDate=" + this.xstartdate + "&PEndDate=" + this.xenddate +
                              "&PBranchID=" + branchid + "&username=" + user.M_UserUsername + ""
                  }
            },
            computed: {


                  xstartdate: {
                        get() {
                              return this.$store.state.close.start_date
                        },
                        set(val) {
                              this.$store.commit("close/update_start_date", val)
                        }
                  },
                  xenddate: {
                        get() {
                              return this.$store.state.close.end_date
                        },
                        set(val) {
                              this.$store.commit("close/update_end_date", val)
                        }
                  },
                  selected_filter_branch: {
                        get() {
                              return this.$store.state.close.selected_filter_branch
                        },
                        set(val) {
                              this.$store.commit("close/update_selected_filter_branch", val)
                        }
                  },
                  branchs: {
                        get() {
                              return this.$store.state.close.branchs
                        },
                        set(val) {
                              this.$store.commit("close/update_branchs", val)
                        }
                  },
                  searchnamelab: {
                        get() {
                              return this.$store.state.close.search
                        },
                        set(val) {
                              this.$store.commit("close/update_search", val)
                        }
                  },
                  statuses() {
                        return this.$store.state.close.statuses
                  },
                  status: {
                        get() {
                              return this.$store.state.close.selected_status
                        },
                        set(val) {
                              this.$store.commit("close/update_selected_status", val)
                        }
                  },
                  openprintnote: {
                        get() {
                              return this.$store.state.close.open_print_note
                        },
                        set(val) {
                              this.$store.commit("close/update_open_print_note", false)
                        }
                  },
                  selpat() {
                        return this.$store.state.close.selected_close
                  },
                  startDateFormatted() {
                        return this.formatDate(this.xstartdate)
                  },
                  endDateFormatted() {
                        return this.formatDate(this.xenddate)
                  },
                  isLoading() {
                        return this.$store.state.close.search_status == 1
                  },
                  closes() {
                        return this.$store.state.close.closes
                  },

                  curr_page: {
                        get() {
                              return this.$store.state.close.current_page
                        },
                        set(val) {
                              this.$store.commit("close/update_current_page", val)
                              this.$store.dispatch("close/search", {
                                    startdate: this.xstartdate,
                                    enddate: this.xenddate,
                                    search: this.searchnamelab,
                                    status: this.status.value,
                                    current_page: val,
                                    lastidx: 0
                              })
                        }
                  },
                  xtotal_page: {
                        get() {
                              return this.$store.state.close.total_page
                        },
                        set(val) {
                              this.$store.commit("close/update_total_page", val)
                        }
                  },
            },
            data() {
                  return {
                        xheight: '600',
                        xurl: '',
                        items: [],
                        menustartdate: false,
                        menuenddate: false,
                        dialog: false,
                        urlprintnote: '',
                        printtitle: '',
                        formatreport: 'pdf',
                        printwidth: '100%',
                        headers: [{
                                    text: "TANGGAL",
                                    align: "left",
                                    sortable: false,
                                    value: "mr",
                                    width: "15%",
                                    class: "pa-2 blue lighten-3 white--text"
                              },
                              {
                                    text: "NO TRX",
                                    align: "left",
                                    sortable: false,
                                    value: "lab",
                                    width: "10%",
                                    class: "pa-2 blue lighten-3 white--text"
                              },

                              {
                                    text: "NAMA FO",
                                    align: "left",
                                    sortable: false,
                                    value: "name",
                                    width: "15%",
                                    class: "pa-2 blue lighten-3 white--text"
                              },
                              {
                                    text: "ACTION",
                                    align: "left",
                                    sortable: false,
                                    value: "name",
                                    width: "10%",
                                    class: "pa-2 blue lighten-3 white--text"
                              }
                        ],
                  }
            }
      }
</script>