<template>
   <v-layout column pb-2>
      <!--<one-fo-registration-patient-order></one-fo-registration-patient-order>-->
     <v-flex xs12>
      <v-card>
         <v-layout row>
            <v-flex md6>
               <v-layout row pl-2>
                     <v-flex md5>
                        <div class="font-weight-bold text-fajrihm">No Reg</div>
                     </v-flex>
                     <v-flex md7>
                        <div class="font-weight-regular text-fajrihm text-md-right">{{ selected_order.order_no }}</div>
                     </v-flex>
               </v-layout>
               <v-layout row pl-2>
                     <v-flex md5>
                        <div class="font-weight-bold text-fajrihm">Tangal Periksa</div>
                     </v-flex>
                     <v-flex md7>
                        <div class="font-weight-regular text-fajrihm text-md-right">{{ selected_order.order_date }}</div>
                     </v-flex>
               </v-layout>
            </v-flex>
            <v-flex md6>
               <v-layout row pl-2>
                     <v-flex md5>
                        <div class="font-weight-bold text-fajrihm">PID</div>
                     </v-flex>
                     <v-flex md7>
                        <div class="font-weight-regular text-fajrihm text-md-right">{{ selected_order.patient_mr }}</div>
                     </v-flex>
               </v-layout>
               <v-layout row pl-2>
                     <v-flex md5>
                        <div class="font-weight-bold text-fajrihm">Nama Pasien</div>
                     </v-flex>
                     <v-flex md7>
                        <div class="font-weight-regular text-fajrihm text-md-right">{{ selected_order.patient_name }}</div>
                     </v-flex>
               </v-layout>
            </v-flex>
         </v-layout>
         <v-layout row>
            <v-flex md6>
               <v-layout row pl-2>
                     <v-flex md5>
                        <div class="font-weight-bold text-fajrihm">Kel. Pelanggan</div>
                     </v-flex>
                     <v-flex md7>
                        <div class="font-weight-regular text-fajrihm text-md-right">{{ selected_order.order_company }}</div>
                     </v-flex>
               </v-layout>
            </v-flex>
            <v-flex md6>
               <v-layout row pl-2>
                     <v-flex md5>
                        <div class="font-weight-bold text-fajrihm">Agreement</div>
                     </v-flex>
                     <v-flex md7>
                        <div class="font-weight-regular text-fajrihm text-md-right">{{ selected_order.order_mou }}</div>
                     </v-flex>
               </v-layout>
            </v-flex>
         </v-layout>
         <v-layout row mb-2>
            <v-flex md6>
               <v-layout row pl-2>
                     <v-flex md5>
                        <div class="font-weight-bold text-fajrihm">Pengirim</div>
                     </v-flex>
                     <v-flex md7>
                        <div class="font-weight-regular text-fajrihm text-md-right">{{ selected_order.doctor_sender }}</div>
                     </v-flex>
               </v-layout>
            </v-flex>
            <v-flex md6>
               <v-layout row pl-2>
                     <v-flex md5>
                        <div class="font-weight-bold text-fajrihm">Alamat Pengirim</div>
                     </v-flex>
                     <v-flex md7>
                        <div class="font-weight-regular text-fajrihm text-md-right">{{ selected_order.doctor_sender_address }}</div>
                     </v-flex>
               </v-layout>
            </v-flex>
         </v-layout>
         <v-layout style="border-top:1px dashed rgb(221,221,221)" row mt-1 mb-1></v-layout>
         <v-layout row mb-2 wrap>
            <v-flex v-for="(dlv, n) in order_delivery" xs6 v-bind:key="n">
               <v-layout row wrap pl-2>
                     <v-flex xs12 class="text-delivery text-xs-right">
                        <p class="mb-1">{{ dlv.label }} : {{ dlv.description }}</p>
                        <p class="mb-1 mono red--text caption">catatan : <span v-if="dlv.note === ''">-</span> <span v-if="dlv.note !== ''">{{ dlv.note }}</span></p>
                     </v-flex>
               </v-layout>
            </v-flex>
         </v-layout>
         <v-layout row mb-2 wrap>
            <v-flex xs12>
               <v-layout row wrap pl-2>
                  <v-flex xs12>
                     <div class="font-weight-bold text-fajrihm">Janji Hasil</div>
                  </v-flex>
               </v-layout>
               <v-layout row wrap pl-2>
                  <v-flex xs12 v-for="p in promises" >
                     <div class="font-weight-bold text-fajrihm">{{ p.T_OrderPromiseDateTime_ina }}</div>
                  </v-flex>
               </v-layout>
            </v-flex>
         </v-layout>
         <v-layout style="border-top:1px dashed rgb(221,221,221)" row mt-1 mb-1></v-layout>
         <v-layout row pa-2>
            <v-flex xs12>

               <table>
                     <tr style="background:#ffeaa5">
                     
                     <th style="width:42%;font-weight:bold;font-size:12px;" class="text-md-center pt-2 pb-2">PEMERIKSAAN</th>
                     <th style="width:12%;font-weight:bold;font-size:12px;" class="text-md-center pt-2 pb-2">BRUTO</th>
                     <th style="width:12%;font-weight:bold;font-size:12px;" class="text-md-center pt-2 pb-2">DISKON</th>
                     <th style="width:12%;font-weight:bold;font-size:12px;" class="text-md-center pt-2 pb-2">TOTAL</th>
                     </tr>
                  
                     <tr style="font-size:12px" v-for="t in selected_test" v-bind:key="t.T_OrderDetailID">
      
                     <td class="text-md-left pl-3">
                        <p class="mb-1">{{ t.T_OrderDetailT_TestName}}</p>
                        <!----<p class="mb-0 caption" v-show="child_test_show(t)">{{child_test(t.child_test)}}</p>-->
                     </td>
                     <td class="text-md-right mono pr-2">{{ one_money(t.T_OrderDetailPrice) }}</td>
                     <td class="text-md-right mono pr-2">{{ one_money(t.T_OrderDetailDiscTotal)  }}</td>
                     <td class="text-md-right mono font-weight-black pr-2">{{ one_money(t.T_OrderDetailTotal) }}</td>
                     </tr>

                     
               
                     <!--/ TEST PANEL -->

                     <tfoot>
                     <tr>
                        <th style="background:#e16262;color:#fff"  class="text-md-left pl-3 pt-2 pb-2">TOTAL</th>
                        <th style="background:#e16262;color:#fff" class="text-md-right pr-2 pt-2 pb-2">{{ one_money(bruto_total)  }}</th>
                        <th style="background:#e16262;color:#fff" class="text-md-right pr-2 pt-2 pb-2">{{ one_money(diskon_total)  }}</th>
                        <th style="background:#e16262;color:#fff" class="text-md-right pr-2 pt-2 pb-2" >{{ one_money(sub_total)  }}</th>
                     </tr>
                     
                     </tfoot>
               </table>
            </v-flex>
         </v-layout>
         <v-layout style="border-top:1px dashed rgb(221,221,221)" row mt-2 mb-2></v-layout>
      </v-card>
     </v-flex>
     
   </v-layout>
</template>

<style scoped>

.v-input--selection-controls {
    margin-top: 0px;
    padding-top: 0px;
}
.text-fajrihm{
    padding: 3px 20px 3px 0;
    text-align:left;
    font-size: 13px;
    font-family: open sans, tahoma, sans-serif;
}

.label-delivery{
     font-size: 11px;
     padding: 3px 20px 3px 0;
     font-family: open sans, tahoma, sans-serif;
}
.text-delivery{
     font-size: 12px;
     padding: 3px 20px 3px 0;
     font-family: open sans, tahoma, sans-serif;
}

.nota {
   font-size: 2em;
   font-weight: bold;
   text-align: left;
}
.total {
   min-height:76px;
}
table {
   font-family: arial, sans-serif;
   border-collapse: collapse;
   width: 100%;
   background:white;
   border: 0px;
}

th, td {
   border: 1px solid black;
   border-collapse: collapse;
   padding-top: 2px;
   padding-bottom: 2px;
}
table>tr>td {
   padding: 8px;
}
table>tr>td:first {
   padding-left:15px!important;
}
.nota {
   font-size: 2em;
   font-weight: bold;
   text-align: left;
}
.total {
   min-height:76px;
}
table {
   font-family: arial, sans-serif;
   border-collapse: collapse;
   width: 100%;
   background:white;
   border: 0px;
}

th, td {
   border: 1px solid black;
   border-collapse: collapse;
   padding-top: 2px;
   padding-bottom: 2px;
}
table>tr>td {
   padding: 8px;
}
table>tr>td:first {
   padding-left:15px!important;
}

.vintage-text{
   text-shadow: 0px -2px 0px #fff, 0px 2px 3px #fff;
}

</style>
<script>
module.exports = {
   computed: {

      promises() {
         return this.$store.state.payment.promises
      },
      selected_order() {
         return this.$store.state.patient.selected_patient
      },
      order_delivery() {
         var dlvr = this.$store.state.payment.order_delivery
         
         return dlvr
      },
      selected_test() {
         return this.$store.state.payment.order_detail
      },
      selected_panel() {
         return this.$store.state.px.selected_panel
      },
      discount_pembulatan() {
         //sipe : set to 0
         return 0
      },
      grand_total() {
    
         return this.sub_total
      },
      sub_total() {
         let tests = this.selected_test
         sub_total = 0
         tests.forEach(function(t,idx) {
            let price = parseInt(t.T_OrderDetailTotal)
            sub_total +=  price
         })
     
         return sub_total
      },
      bruto_total() {
         let tests = this.selected_test
         bruto_total = 0
         tests.forEach(function(t,idx) {
            //console.log(t.T_PriceAmount)
            bruto_total +=  parseInt(t.T_OrderDetailPrice)
            //console.log(bruto_total)
         })
         
         return bruto_total
      },
      diskon_total() {
         let tests = this.selected_test
         diskon_total = 0
         tests.forEach(function(t,idx) {
            let price = parseInt(t.T_OrderDetailDiscTotal)
            diskon_total +=  price
         })
         
         return diskon_total
      },
      
   },
   methods : {
      one_money(p) {
         return window.one_money(p)
      },
      child_test(x) {
         let y = []
         for (let i in x)
               y.push(x[i].T_TestName)
         return y.join(', ')
      },
      child_test_show(t) {
         if (!t.child_test)
               return false

         if (t.child_test.length < 1)
               return false

         if (t.px_type != 'PN')
               return false

         return true
      },
      calc_netto(t) {
            return one_float(t.T_PriceAmount) - one_float(t.T_PriceDisc) / 100 * one_float(t.T_PriceAmount)
            - one_float(t.T_PriceDiscRp)
      },

      calc_discount(t) {
      return ( one_float(t.T_PriceDisc) / 100 * one_float(t.T_PriceAmount) )
         + one_float(t.T_PriceDiscRp)
      },
   }
}
</script>
