<template>
    <div class="col-md-12"> 
              <div class="card">
                  <div class="card-header">
                      <div class="md:flex md:justify-between">
                      <div class="md:flex">
                        <div class="sm:w-auto md:w-40 mb-2">
                        ເລືອກລາຍງານ: 
                        <div class="input-group" >
                            <select class="form-control" v-model="reportCode">
                            <option value="rp-pom">ລາຍງານ ຜົນດຳເນີນງານ</option>
                            <option value="rp-sub">ລາຍງານ ຖານະການເງິນ - ຊັບສິນ</option>
                            <option value="rp-nee">ລາຍງານ ຖານະການເງິນ - ໜີ້ສິນ</option>
                        </select>

                        </div>
                        </div>
                        <div class="sm:w-auto md:w-80 px-4   flex justify-center">
                            <div class="grid grid-rows-2 "> {{chdatere}} 
                            <div class="btn-group h-9 w-auto mb-2" role="group" aria-label="Basic example" >
                                <button type="button" class="btn btn-info btn-outline btn-sm" :class="sem" @click="selectdtype('m')">ເດືອນ</button>
                                <button type="button" class="btn btn-info btn-outline btn-sm" :class="se3" @click="selectdtype('m1-3')">ງວດ1</button>
                                <button type="button" class="btn btn-info btn-outline btn-sm" :class="se6" @click="selectdtype('m4-6')">ງວດ2</button>
                                <button type="button" class="btn btn-info btn-outline btn-sm" :class="se9" @click="selectdtype('m7-9')">ງວດ3</button>
                                <button type="button" class="btn btn-info btn-outline btn-sm" :class="se12" @click="selectdtype('m10-12')">ງວດ4</button>
                                <button type="button" class="btn btn-info btn-outline btn-sm" :class="sey" @click="selectdtype('y')">ປີ</button>
                                </div> 
                                <flat-pickr :config="config" v-model="dmy" class="form-control form-control-sm w-auto mb-2" placeholder="ເລືອກວັນທີ່" />
                                </div>
                        </div>
                      </div>
                      <div class=" h-auto flex justify-center">
                          <div class="">
                          <button type="button" class="btn btn-success btn-sm" @click="CreateReport"><i class="fas fa-file-alt"></i> ສ້າງໃບລາຍງານ</button>
                          </div>
                      </div>
                      </div>
                  </div>
              </div>

              <div class="card mt--4">

                  <div class="h-auto flex justify-end mt-4 pr-4">
                      
                          <button type="button" class="btn btn-danger btn-sm" > <i class="fas fa-print"></i> ພິມ</button>
                          <button type="button" class="btn btn-primary btn-sm" @click="DownloadPDF()"> <i class="fas fa-file-pdf"></i> ດາວໂຫຼດ </button>
                  </div>
                        <div class="card-body"  v-if="ShChart">
                        <div class="card p-4 mb--4 " style="width:100%">
                            <monthchart :chartData="chdata" :chartOptions="chdataop" :update="update_chart" :key="key" />
                        </div></div>

                  <div v-if="loading" class=" pt-4 text-primary container d-flex justify-content-center "> <div class=""><i class="fas fa-sync-alt fa-spin fa-1x"></i> ກຳລັງຄຳນວນ...</div> </div>
                  <div class="card-body" v-if="reportCode=='rp-pom'">
                       <vue3-simple-html2pdf
                                ref="vue3SimpleHtml2pdf"
                                :options="pdfOptions"
                                :filename="exportFilename"
                            >
                     <div class="table-responsive ">
                         <div class="text-center"> <h2>ໃບລາຍງານຜົນດຳເນີນງານ</h2></div>
                        
                        <div class="mt-4 text-center table680" style="font-size:14px;">ປະຈຳ: {{report_data.date_type}} ແຕ່: {{date(report_data.date_start)}} ເຖິງ: {{date(report_data.date_end)}}</div>
                        <div class="text-right table680 pb-2" style="font-size:14px;">ຫົວໜ່ວຍ: ກີບ</div>
                        <table class="table align-items-center table-flush border2 table680">
                             
                        <tbody>

                            <tr style="background-color: #e9e9eb;">
                                <td class="text-center" > <strong>ເນື້ອໃນລາຍການ</strong> </td>
                                <td class="text-center" width="80" ><strong> ໝາຍເຫດ</strong> </td>
                                <td class="text-center " width="150" ><strong> ປະຈຳ{{date_type_re}}ນີ້</strong> </td>
                                <td class="text-center" width="150" ><strong> ປະຈຳ{{date_type_re}}ກ່ອນ</strong> </td>
                            </tr>
                      
                        
                            <tr style="background-color: #e9e9eb;">
                                <td class="text-center"><strong> ລາຍຮັບຈາກກິດຈະການ</strong> </td>
                                <td></td>
                                <td class="text-right"></td>
                                <td class="text-right"></td>
                            </tr>
                            <tr >
                                <td class="">ລາຍຮັບຈາກກິດຈະການປົກກະຕິ</td>
                                <td></td>
                                <td class="text-right">{{formatPrice(report_data.revenue_this_month)}}</td>
                                <td class="text-right">{{formatPrice(report_data.revenue_this_lastmonth)}}</td>
                            </tr>
                            <tr >
                                <td class="">ຕົ້ນທຶນການຂາຍ/ບໍລິການ</td>
                                <td></td>
                                <td class="text-right">{{formatPrice(report_data.cap_this_month)}}</td>
                                <td class="text-right">{{formatPrice(report_data.cap_this_lastmonth)}}</td>
                            </tr>
                            <tr style="background-color: #e9e9eb;">
                                <td class="text-center"><strong>ຜົນໄດ້ຮັບເບື້ອງຕົ້ນ</strong></td>
                                <td></td>
                                <td class="text-right">{{formatPrice(report_data.revenue_this_month-report_data.cap_this_month)}}</td>
                                <td class="text-right">{{formatPrice(report_data.revenue_this_lastmonth-report_data.cap_this_lastmonth)}}</td>
                            </tr>
                            <tr>
                                <td>ລາຍຮັບອື່ນໆ</td>
                                <td></td>
                                <td class="text-right">{{formatPrice(report_data.other_expense_this_month)}}</td>
                                <td class="text-right">{{formatPrice(report_data.other_expense_this_lastmonth)}}</td>
                            </tr>
                            <tr >
                                <td>ລາຍຈ່າຍບໍລິຫານ</td>
                                <td></td>
                                <td class="text-right">{{formatPrice(report_data.manager_expense_this_month)}}</td>
                                <td class="text-right">{{formatPrice(report_data.manager_expense_this_lastmonth)}}</td>
                            </tr>
                            <tr >
                                <td>ລາຍຈ່າຍທາງການເງິນ</td>
                                <td></td>
                                <td class="text-right">{{formatPrice(report_data.financial_expense_this_month)}}</td>
                                <td class="text-right">{{formatPrice(report_data.financial_expense_this_lastmonth)}}</td>
                            </tr>
                            <tr >
                                <td>ລາຍຈ່າຍອາກອນ, ຄ່າທຳນຽມ ແລະລາຍຈ່າຍປະເພດດຽວກັນ</td>
                                <td></td>
                                <td class="text-right">{{formatPrice(report_data.fee_expense_this_month)}}</td>
                                <td class="text-right">{{formatPrice(report_data.fee_expense_this_lastmonth)}}</td>
                            </tr>
                            <tr >
                                <td>ລາຍຈ່າຍໃຫ້ພະນັກງານ</td>
                                <td></td>
                                <td class="text-right">{{formatPrice(report_data.staff_expense_this_month)}}</td>
                                <td class="text-right">{{formatPrice(report_data.staff_expense_this_lastmonth)}}</td>
                            </tr>
                            <tr >
                                <td>ລາຍຈ່າຍອື່ນໆ</td>
                                <td></td>
                                <td class="text-right">{{formatPrice(report_data.other_expense_this_month)}}</td>
                                <td class="text-right">{{formatPrice(report_data.other_expense_this_lastmonth)}}</td>
                            </tr>
                            <tr style="background-color: #e9e9eb;">
                                <td class="text-center">ຜົນໄດ້ຮັບກ່ອນເສຍອາກອນ</td>
                                <td></td>
                                <td class="text-right">{{formatPrice(phondaihub_this_month)}}</td>
                                <td class="text-right">{{formatPrice(phondaihub_this_lastmonth)}}</td>
                            </tr>
                            <tr >
                                <td>ອາກອນຕ້ອງຈ່າຍ</td>
                                <td></td>
                                <td class="text-right">{{formatPrice(report_data.tax_expense_this_month)}}</td>
                                <td class="text-right">{{formatPrice(report_data.tax_expense_this_lastmonth)}}</td>
                            </tr>
                            <tr >
                                <td>ອາກອນເຍື້ອນຊຳລະ</td>
                                <td></td>
                                <td class="text-right">0</td>
                                <td class="text-right" >0</td>
                            </tr>
                            <tr style="background-color: #e9e9eb;">
                                <td class="text-center">ຜົນໄດ້ຮັບສຸດທິ ຈາກການດຳເນີນງານ</td>
                                <td></td>
                                <td class="text-right">0</td>
                                <td class="text-right" >0</td>
                            </tr>
                            <tr >
                                <td>ລາຍຮັບສັງລວມອື່ນໆ</td>
                                <td></td>
                                <td class="text-right">0</td>
                                <td class="text-right" >0</td>
                            </tr>
                            <tr >
                                <td>ລາຍຮັບອື່ນໆ</td>
                                <td></td>
                                <td class="text-right">0</td>
                                <td class="text-right" >0</td>
                            </tr>
                           
                        </tbody>
                        <tfoot>
                            <tr style="background-color: #e9e9eb;">
                                <td class="text-center">ຜົນໄດ້ຮັບສັງລວມອື່ນໆ ຫຼັງອາກອນ</td>
                                <td></td>
                                <td class="text-right">0</td>
                                <td class="text-right" >0</td>
                            </tr>
                            <tr style="background-color: #e9e9eb;">
                                <td class="text-center">ຜົນໄດ້ຮັບ ສຸດທິໃນ{{date_type_re}}</td>
                                <td></td>
                                <td class="text-right">{{formatPrice(phondaihub_this_month)}}</td>
                                <td class="text-right">{{formatPrice(phondaihub_this_lastmonth)}}</td>
                            </tr>
                        </tfoot>
                        </table>

                  </div>
                  </vue3-simple-html2pdf>
                  </div>

                  <div class="card-body" v-if="reportCode=='rp-sub'">
                     <vue3-simple-html2pdf
                                ref="vue3SimpleHtml2pdf"
                                :options="pdfOptions"
                                :filename="exportFilename"
                            >
                     <div class="table-responsive ">
                         <div class="text-center"> <h2>ໃບລາຍງານຖານະການເງິນ ຊັບສິນ </h2></div>
                        
                        <div class="mt-4 text-center table680" style="font-size:14px;">ປະຈຳ: {{report_data.date_type}} ແຕ່: {{date(report_data.date_start)}} ເຖິງ: {{date(report_data.date_end)}}</div>
                        <div class="text-right table680 pb-2" style="font-size:14px;">ຫົວໜ່ວຍ: ກີບ</div>
                        <table class="table align-items-center table-flush border2 table680">
                             
                        <tbody>

                            <tr style="background-color: #e9e9eb;">
                                <td class="text-center" > <strong>ຊັບສິນ</strong> </td>
                                <td class="text-center" width="80" ><strong> ໝາຍເຫດ</strong> </td>
                                <td class="text-center " width="150" ><strong> ປະຈຳ{{date_type_re}}ນີ້</strong> </td>
                                <td class="text-center" width="150" ><strong> ປະຈຳ{{date_type_re}}ກ່ອນ</strong> </td>
                            </tr>
                      
                        
                            <tr style="background-color: #e9e9eb;">
                                <td class="text-left"><strong>I. ຊັບສິນໝູນວຽນ</strong> </td>
                                <td></td>
                                <td class="text-right"></td>
                                <td class="text-right"></td>
                            </tr>
                            <tr >
                                <td class="">ເງິນສົດ ແລະ ສີ່ງທຽບເທົ່າເງິນສົດ</td>
                                <td></td>
                                <td class="text-right">{{formatPrice(report_data.curr_this_month)}}</td>
                                <td class="text-right">{{formatPrice(report_data.curr_last_month)}}</td>
                            </tr>
                            <tr >
                                <td class="">ໜີ້ຕ້ອງຮັບໃນທຸລະກິດ ແລະ ໜີ້ຕ້ອງຮັບອື່ນໆ</td>
                                <td></td>
                                <td class="text-right">{{formatPrice(report_data.neehub_this_month)}}</td>
                                <td class="text-right">{{formatPrice(report_data.neehub_last_month)}}</td>
                            </tr>
                            <tr >
                                <td class="">ເຄື່ອງໃນສາງ</td>
                                <td></td>
                                <td class="text-right">{{formatPrice(report_data.instore_this_month)}}</td>
                                <td class="text-right">{{formatPrice(report_data.instore_last_month)}}</td>
                            </tr>
                            <tr >
                                <td class="">ຊັບສິນໝູນວຽນອື່ນໆ</td>
                                <td></td>
                                <td class="text-right">{{formatPrice(report_data.assetsother_this_month)}}</td>
                                <td class="text-right">{{formatPrice(report_data.assetsother_last_month)}}</td>
                            </tr>
                          
                            <tr style="background-color: #e9e9eb;">
                                <td class="text-left"><strong>ລວມຊັບສິນໝຸນວຽນ</strong></td>
                                <td></td>
                                <td class="text-right">{{formatPrice(subsin_mounvian_this_month)}}</td>
                                <td class="text-right">{{formatPrice(subsin_mounvian_last_month)}}</td>
                            </tr>
                            <tr >
                                <td colspan="4"></td>
                            </tr>
                            <tr style="background-color: #e9e9eb;">
                                <td class="text-left"><strong>II. ຊັບສິນບໍ່ໝຸນວຽນ</strong></td>
                                <td></td>
                                <td class="text-right"></td>
                                <td class="text-right"></td>
                            </tr>
                            <tr>
                                <td>ຊັບສິນຄົງທີ່ມີຕົວຕົນ</td>
                                <td></td>
                                <td class="text-right">{{formatPrice(report_data.assetin_this_month)}}</td>
                                <td class="text-right">{{formatPrice(report_data.assetin_last_month)}}</td>
                            </tr>
                            <tr>
                                <td>ຊັບສິນບໍ່ມີຕົວຕົນ (No Acc)</td>
                                <td></td>
                                <td class="text-right">0</td>
                                <td class="text-right">0</td>
                            </tr>
                            <tr>
                                <td>ຊັບສິນຊີວະພາບ (No Acc)</td>
                                <td></td>
                                <td class="text-right">0</td>
                                <td class="text-right">0</td>
                            </tr>
                            <tr>
                                <td>ຊັບສິນຄົງທີ່ອື່ນໆ (No Acc)</td>
                                <td></td>
                                <td class="text-right">0</td>
                                <td class="text-right">0</td>
                            </tr>
                            <tr style="background-color: #e9e9eb;">
                                <td class="text-left"><strong>ລວມຊັບສິນບໍ່ໝຸນວຽນ</strong></td>
                                <td></td>
                                <td class="text-right">{{formatPrice(report_data.assetin_this_month)}}</td>
                                <td class="text-right">{{formatPrice(report_data.assetin_last_month)}}</td>
                            </tr>
                           <tr >
                                <td colspan="4"></td>
                            </tr>
                    
                           
                        </tbody>
                        <tfoot>
                            <tr style="background-color: #e9e9eb;">
                                <td class="text-center">ລວມຊັບສິນທັງໝົດ ( I + II )</td>
                                <td></td>
                                <td class="text-right">{{formatPrice(subsin_mounvian_this_month+report_data.assetin_this_month)}}</td>
                                <td class="text-right">{{formatPrice(subsin_mounvian_last_month+report_data.assetin_last_month)}}</td>
                            </tr>
                        </tfoot>
                        </table>

                  </div>
                  </vue3-simple-html2pdf>
                  </div>


                  <div class="card-body" v-if="reportCode=='rp-nee'">
                     <vue3-simple-html2pdf
                                ref="vue3SimpleHtml2pdf"
                                :options="pdfOptions"
                                :filename="exportFilename"
                            >
                     <div class="table-responsive ">
                         <div class="text-center"> <h2>ໃບລາຍງານຖານະການເງິນ ໜີ້ສິນ ແລະ ທຶນ</h2></div>
                        
                        <div class="mt-4 text-center table680" style="font-size:14px;">ປະຈຳ: {{report_data.date_type}} ແຕ່: {{date(report_data.date_start)}} ເຖິງ: {{date(report_data.date_end)}}</div>
                        <div class="text-right table680 pb-2" style="font-size:14px;">ຫົວໜ່ວຍ: ກີບ</div>
                        <table class="table align-items-center table-flush border2 table680">
                             
                        <tbody>

                            <tr style="background-color: #e9e9eb;">
                                <td class="text-center" > <strong>ໜີ້ສິນ</strong> </td>
                                <td class="text-center" width="80" ><strong> ໝາຍເຫດ</strong> </td>
                                <td class="text-center " width="150" ><strong> ປະຈຳ{{date_type_re}}ນີ້</strong> </td>
                                <td class="text-center" width="150" ><strong> ປະຈຳ{{date_type_re}}ກ່ອນ</strong> </td>
                            </tr>
                      
                        
                            <tr style="background-color: #e9e9eb;">
                                <td class="text-left"><strong>I. ໜີ້ສິນໝູນວຽນ</strong> </td>
                                <td></td>
                                <td class="text-right"></td>
                                <td class="text-right"></td>
                            </tr>
                            <tr >
                                <td class="">ໜີ້ຕ້ອງສົ່ງໃນທຸລະກິດ ແລະ ໜີ້ຕ້ອງສົ່ງອື່ນໆ</td>
                                <td></td>
                                <td class="text-right">{{formatPrice(report_data.neesentother_this_month)}}</td>
                                <td class="text-right">{{formatPrice(report_data.neesentother_last_month)}}</td>
                            </tr>
                            <tr >
                                <td class="">ດອກເບ້ຍເງິນກູ້ຕ້ອງສົ່ງ</td>
                                <td></td>
                                <td class="text-right">{{formatPrice(report_data.intsent_this_month)}}</td>
                                <td class="text-right">{{formatPrice(report_data.intsent_last_month)}}</td>
                            </tr>
                            <tr >
                                <td class="">ໜີ້ຕ້ອງສົ່ງອາກອນ</td>
                                <td></td>
                                <td class="text-right">{{formatPrice(report_data.taxsent_this_month)}}</td>
                                <td class="text-right">{{formatPrice(report_data.taxsent_last_month)}}</td>
                            </tr>
                            <tr >
                                <td class="">ເງິນແຮ</td>
                                <td></td>
                                <td class="text-right">{{formatPrice(report_data.currh_this_month)}}</td>
                                <td class="text-right">{{formatPrice(report_data.currh_last_month)}}</td>
                            </tr>
                            <tr >
                                <td class="">ໜີ້ສິນໝູນວຽນອື່ນໆ</td>
                                <td></td>
                                <td class="text-right">{{formatPrice(report_data.neesinother_this_month)}}</td>
                                <td class="text-right">{{formatPrice(report_data.neesinother_last_month)}}</td>
                            </tr>
                          
                            <tr style="background-color: #e9e9eb;">
                                <td class="text-left"><strong>ລວມໜີ້ສິນໝຸນວຽນ</strong></td>
                                <td></td>
                                <td class="text-right">{{formatPrice(neesin_mounvien_this_month)}}</td>
                                <td class="text-right">{{formatPrice(neesin_mounvien_last_month)}}</td>
                            </tr>
                            <tr >
                                <td colspan="4"></td>
                            </tr>
                            <tr style="background-color: #e9e9eb;">
                                <td class="text-left"><strong>II. ໜີ້ສິນບໍ່ໝຸນວຽນ</strong></td>
                                <td></td>
                                <td class="text-right"></td>
                                <td class="text-right"></td>
                            </tr>
                            <tr>
                                <td>ເງິນກູ້ທະນາຄານ</td>
                                <td></td>
                                <td class="text-right">{{formatPrice(report_data.loan_this_month)}}</td>
                                <td class="text-right">{{formatPrice(report_data.loan_last_month)}}</td>
                            </tr>
                            <tr>
                                <td>ເງິນແຮ</td>
                                <td></td>
                                <td class="text-right">{{formatPrice(report_data.currh2_this_month)}}</td>
                                <td class="text-right">{{formatPrice(report_data.currh2_last_month)}}</td>
                            </tr>
                            <tr>
                                <td>ໜີ້ສິນໄລຍະຍາວອື່ນໆ</td>
                                <td></td>
                                <td class="text-right">{{formatPrice(report_data.neesinlong_this_month)}}</td>
                                <td class="text-right">{{formatPrice(report_data.neesinlong_last_month)}}</td>
                            </tr>
                          
                            <tr style="background-color: #e9e9eb;">
                                <td class="text-left"><strong>ລວມໜີ້ສິນບໍ່ໝຸນວຽນ</strong></td>
                                <td></td>
                                <td class="text-right">{{formatPrice(neesin_bormounvien_this_month)}}</td>
                                <td class="text-right">{{formatPrice(neesin_bormounvien_last_month)}}</td>
                            </tr>
                            <tr style="background-color: #e9e9eb;">
                                <td class="text-left"><strong>ລວມໜີ້ສິນທັງໝົດ ( I + II )</strong></td>
                                <td></td>
                                <td class="text-right">{{formatPrice(neesin_mounvien_this_month+neesin_bormounvien_this_month)}}</td>
                                <td class="text-right">{{formatPrice(neesin_mounvien_last_month+neesin_bormounvien_last_month)}}</td>
                            </tr>
                            <tr >
                                <td colspan="4"></td>
                            </tr>
                            <tr style="background-color: #e9e9eb;">
                                <td class="text-left"><strong>III. ທຶນ</strong></td>
                                <td></td>
                                <td class="text-right"></td>
                                <td class="text-right"></td>
                            </tr>
                            <tr>
                                <td>ທຶນຈົດທະບຽນ</td>
                                <td></td>
                                <td class="text-right">{{formatPrice(report_data.standset_all)}}</td>
                                <td class="text-right">{{formatPrice(report_data.standset_all)}}</td>
                            </tr>
                            <tr>
                                <td>ທຶນເຈົ້າຂອງທຸລະກິດ</td>
                                <td></td>
                                <td class="text-right">{{formatPrice(report_data.stand_all)}}</td>
                                <td class="text-right">{{formatPrice(report_data.stand_all)}}</td>
                            </tr>
                            <tr>
                                <td>ກຳໄລໃນປີ</td>
                                <td></td>
                                <td class="text-right">{{formatPrice(report_data.profityear)}}</td>
                                <td class="text-right">{{formatPrice(report_data.profityear)}}</td>
                            </tr>
                          
                            <tr style="background-color: #e9e9eb;">
                                <td class="text-left"><strong>ລວມທຶນຂອງເຈົ້າຂອງທຸລະກິດ</strong></td>
                                <td></td>
                                <td class="text-right">{{formatPrice(standall_this_month)}}</td>
                                <td class="text-right">{{formatPrice(standall_last_month)}}</td>
                            </tr>
                           <tr >
                                <td colspan="4"></td>
                            </tr>
                    
                           
                        </tbody>
                        <tfoot>
                            <tr style="background-color: #e9e9eb;">
                                <td class="text-center">ລວມໜີ້ສິນທັງໝົດ ແລະ ທຶນຂອງເຈົ້າຂອງທຸລະກິດ <br> ( I + II + III )</td>
                                <td></td>
                                <td class="text-right">{{formatPrice(neesin_mounvien_this_month+neesin_bormounvien_this_month+standall_this_month)}}</td>
                                <td class="text-right">{{formatPrice(neesin_mounvien_last_month+neesin_bormounvien_last_month+standall_last_month)}}</td>
                            </tr>
                        </tfoot>
                        </table>

                  </div>
                  </vue3-simple-html2pdf>
                  </div>

                  

                  
              </div>
          </div>
</template>

<script>
import chartline from './ChartLineReport.vue';
import moment from "moment";
import monthchart from './LineChart.vue'



export default {
    name: 'Reportcomponent',
    props: {
    report: {
      type: Object,
      required: true,
    },
  },
  components:{chartline,moment,monthchart},
  
    data() {
        return {
            re:null,
            ex:null,
            ShChart:false,
            key:0,
            charh_label:null,
            update_chart:null,
            chdata:null,
            chdataop:{
                responsive: true,
                maintainAspectRatio: false,
                scales: {
                    yAxes: [{
                        ticks: {
                            display: true,
                            beginAtZero: false,
                            callback: function (value, index, values) {
                                        return Number(value).toFixed(0).replace(/./g, function(c, i, a) { return i > 0 && c !== "," && (a.length - i) % 3 === 0 ? "," + c : c; })+" ກີບ";
                                    }
                                },
                                gridLines: {
                                    show: true,}
                                }]
                },
                tooltips: {
                callbacks: {
                    label: function(tooltipItem, data) {
                        return Number(tooltipItem.yLabel).toFixed(0).replace(/./g, function(c, i, a) { return i > 0 && c !== "," && (a.length - i) % 3 === 0 ? "," + c : c; })+" ກີບ";
                    }
                },
                mode: 'index',
                intersect: false,
               
            }
            },

            isLoggedIn: false,
            loading:false,
            dmy:'',
            reportCode:'rp-pom',
            datere:'m',
            
            currentDate() {
                const current = new Date();
                const date = current.getFullYear()+'-'+(current.getMonth()+1)+'-'+current.getDate();
                const time = current.getHours() + ":" + current.getMinutes() + ":" + current.getSeconds();
                const dateTime = date +' '+ time;
                return date;
            },
             config:{
                wrap: true, // set wrap to true only when using 'input-group'
                altFormat: 'd/m/Y',
                altInput: true,
                dateFormat: 'Y-m-d',
                allowInput: true,
            },
            datareport:[],
            dataInEx:[],
            dataInExB:[],
            dataInExSB:[],
            data_chart:null,
            report_data:{
                cap_all:'',
                cap_this_lastmonth:'',
                cap_this_month:'',
                revenue_all:'',
                revenue_this_lastmonth:'',
                revenue_this_month:'',
                manager_expense_all:'',
                manager_expense_this_lastmonth:'',
                manager_expense_this_month:'',
                financial_expense_all:'',
                financial_expense_this_lastmonth:'',
                financial_expense_this_month:'',
                fee_expense_all:'',
                fee_expense_this_lastmonth:'',
                fee_expense_this_month:'',
                staff_expense_all:'',
                staff_expense_this_lastmonth:'',
                staff_expense_this_month:'',
                other_expense_all:'',
                other_expense_this_lastmonth:'',
                other_expense_this_month:'',
                tax_expense_all:'',
                tax_expense_this_lastmonth:'',
                tax_expense_this_month:'',
                date_type:'',
                date_start:'',
                date_end:'',
                /// ຊັບສິນ
                curr_all:'',            // ເງິນສົດ ແລະ ສີ່ງທຽບເທົ່າເງິນສົດ
                curr_last_month:'',
                curr_this_month:'',
                neehub_all:'',          // ໜີ້ຕ້ອງຮັບໃນທຸລະກິດ ແລະ ໜີ້ຕ້ອງຮັບອື່ນໆ
                neehub_last_month:'',
                neehub_this_month:'',
                instore_all:'',         // ເຄື່ອງໃນສາງ
                instore_last_month:'',
                instore_this_month:'',
                assetsother_all:'',     // ຊັບສິນໝຸນວຽນອື່ນໆ
                assetsother_last_month:'',
                assetsother_this_month:'',
                assetin_all:'',         // ຊັບສິນຄົງທີ່ມີຕົວຕົນ
                assetin_last_month:'',
                assetin_this_month:'',
                assetout_all:'',        // ຊັບສິນຄົງທີ່ບໍ່ມີຕົວຕົນ
                assetout_last_month:'',
                assetout_this_month:'',
                assetsee_all:'',        // ຊັບສິນຊີວະພາບ
                assetsee_last_month:'',
                assetsee_this_month:'',
                assetinother_all:'',    // ຊັບສິນຄົງທີ່ອື່ນໆ
                assetinother_last_month:'',
                assetinother_this_month:'',

                // ໜີ້ສິນ ແລະ ທຶນ 
                neesentother_all:'',        // ໜີ້ຕ້ອງສົ່ງໃນທຸລະກິດ ແລະ ໜີ້ຕ້ອງສົ່ງອື່ນໆ
                neesentother_last_month:'',
                neesentother_this_month:'',
                intsent_all:'',             // ດອກເບ້ຍເງິນກູ້ຕ້ອງສົ່ງ
                intsent_last_month:'',
                intsent_this_month:'',
                taxsent_all:'',             // ໜີ້ຕ້ອງສົ່ງອາກອນ
                taxsent_last_month:'',
                taxsent_this_month:'',
                currh_all:'',               // ເງິນແຮ
                currh_last_month:'',
                currh_this_month:'',
                neesinother_all:'',         // ໜີ້ສິນໝຸນວຽນອື່ນໆ
                neesinother_last_month:'',        
                neesinother_this_month:'',         
                loan_all:'',                // ເງິນກູ້ທະນາຄານ
                loan_last_month:'',
                loan_this_month:'',
                currh2_all:'',              // ເງິນແຮ
                currh2_last_month:'',
                currh2_this_month:'',
                neesinlong_all:'',          // ນີ້ສິນອື່ນໆ
                neesinlong_last_month:'',
                neesinlong_this_month:'',
                standset_all:'',            // ທຶນຈົດທະບຽນ
                standset_last_month:'',
                standset_this_month:'',
                stand_all:'',               // ທຶນເຈົ້າຂອງທຸລະກິດ
                stand_last_month:'',
                stand_this_month:'',
                profityear:'',              // ກຳໄລປີ
            },
        pdfOptions:{
            margin: 15,
            image: {
              type: 'jpeg',
              quality: 1,
            },
        html2canvas: { scale: 3 },
            jsPDF: {
              unit: 'mm',
              format: 'a4',
              orientation: 'p',
            },
          },
          exportFilename: 'ບົດລາຍງານຜົນໄດ້ຮັບ.pdf',
        };
    },

    mounted() {
        
    },
    computed:{
      date_type_re(){
          switch (this.datere) {
              case 'm':
                  return 'ເດືອນ'
                  break;
             case 'm1-3':
                  return 'ງວດ'
                  break;
            case 'm4-6':
                  return 'ງວດ'
                  break;
            case 'm7-9':
                  return 'ງວດ'
                  break;
            case 'm10-12':
                  return 'ງວດ'
                  break;
            case 'y':
                  return 'ປີ'
                  break;
    
          }
      },
       AllSum(){
           return this.datareport.reduce((num, item) => num + parseInt(item.sum), 0 );
       },
       SumIncome(){
           let db = this.dataInEx.filter((e) => e.trn_type == 'income')
           return db.reduce((num, item) => num + parseInt(item.sum), 0 );
       },
       SumExpense(){
           let db = this.dataInEx.filter((e) => e.trn_type == 'expense')
           return db.reduce((num, item) => num + parseInt(item.sum), 0 );
       },
       SumIncomeB(){
           let db = this.dataInExB.filter((e) => e.trn_type == 'income')
           return db.reduce((num, item) => num + parseInt(item.sum), 0 );
       },
       SumExpenseB(){
           let db = this.dataInExB.filter((e) => e.trn_type == 'expense')
           return db.reduce((num, item) => num + parseInt(item.sum), 0 );
       },
       SumIncomeSB(){
           let db = this.dataInExSB.filter((e) => e.trn_type == 'income')
           return db.reduce((num, item) => num + parseInt(item.sum), 0 );
       },
       SumExpenseSB(){
           let db = this.dataInExSB.filter((e) => e.trn_type == 'expense')
           return db.reduce((num, item) => num + parseInt(item.sum), 0 );
       },
        chdatere(){
            if(this.datere=='m'){ this.sem = 'active'; this.se3=''; this.se6=''; this.se9=''; this.se12=''; this.sey=''; } else {  
                if(this.datere=='m1-3'){ this.sem = ''; this.se3='active'; this.se6=''; this.se9=''; this.se12=''; this.sey=''; } else {  
                if(this.datere=='m4-6'){ this.sem = ''; this.se3=''; this.se6='active'; this.se9=''; this.se12=''; this.sey='';  } else { 
                    if(this.datere=='m7-9'){ this.sem = ''; this.se3=''; this.se6=''; this.se9='active'; this.se12=''; this.sey=''; } else {  
                        if(this.datere=='m10-12'){ this.sem = ''; this.se3=''; this.se6=''; this.se9=''; this.se12='active'; this.sey=''; } else {  
                            if(this.datere=='y'){ this.sem = ''; this.se3=''; this.se6=''; this.se9=''; this.se12=''; this.sey='active'; }
                            }
                        }
                    }
                }
            }

            return null
            
            
        },
        phondaihub_this_month(){
            return parseInt(this.report_data.revenue_this_month)-parseInt(this.report_data.cap_this_month)-parseInt(this.report_data.other_expense_this_month)-parseInt(this.report_data.manager_expense_this_month)-parseInt(this.report_data.financial_expense_this_month)-parseInt(this.report_data.fee_expense_this_month)-parseInt(this.report_data.staff_expense_this_month)-parseInt(this.report_data.other_expense_this_month)|0;
        },
        phondaihub_this_lastmonth(){
            return parseInt(this.report_data.revenue_this_lastmonth)-parseInt(this.report_data.cap_this_lastmonth)-parseInt(this.report_data.other_expense_this_lastmonth)-parseInt(this.report_data.manager_expense_this_lastmonth)-parseInt(this.report_data.financial_expense_this_lastmonth)-parseInt(this.report_data.fee_expense_this_lastmonth)-parseInt(this.report_data.staff_expense_this_lastmonth)-parseInt(this.report_data.other_expense_this_lastmonth)|0;
        },
        subsin_mounvian_this_month(){
            return parseInt(this.report_data.curr_this_month)+parseInt(this.report_data.neehub_this_month)+parseInt(this.report_data.instore_this_month)+parseInt(this.report_data.assetsother_this_month) |0
        },
        subsin_mounvian_last_month(){
            return parseInt(this.report_data.curr_last_month)+parseInt(this.report_data.neehub_last_month)+parseInt(this.report_data.instore_last_month)+parseInt(this.report_data.assetsother_last_month)|0
        },

        neesin_mounvien_this_month(){
            return parseInt(this.report_data.neesentother_this_month)+parseInt(this.report_data.intsent_this_month)+parseInt(this.report_data.taxsent_this_month)+parseInt(this.report_data.currh_this_month)|0
        },
        neesin_mounvien_last_month(){
            return parseInt(this.report_data.neesentother_last_month)+parseInt(this.report_data.intsent_last_month)+parseInt(this.report_data.taxsent_last_month)+parseInt(this.report_data.currh_last_month)+parseInt(this.report_data.neesinother_last_month)|0
        },

        neesin_bormounvien_this_month(){
            return parseInt(this.report_data.loan_this_month)+parseInt(this.report_data.currh2_this_month)+parseInt(this.report_data.neesinlong_this_month)|0
        },
        neesin_bormounvien_last_month(){
            return parseInt(this.report_data.loan_last_month)+parseInt(this.report_data.currh2_last_month)+parseInt(this.report_data.neesinlong_last_month)|0
        },

        standall_this_month()
        {
            return parseInt(this.report_data.standset_all)+parseInt(this.report_data.stand_all)+parseInt(this.report_data.profityear)
        },
        standall_last_month()
        {
            return parseInt(this.report_data.standset_all)+parseInt(this.report_data.stand_all)+parseInt(this.report_data.profityear)
        }

    },
    methods: {
        DownloadPDF(){
          this.$refs.vue3SimpleHtml2pdf.download()
        },
        shuffleData() {
      dataValues.value = shuffle(dataValues.value);
      console.log(doughnutChartRef.value.chartInstance);
    },
    switchLegend() {
      toggleLegend.value = !toggleLegend.value;
    },
         date(value) {
             if(value){
                 return moment(value).format("DD/MM/YYYY");
             }else { return '' }
         
        },
        Getday(value) {
         return moment(value).format("DD");
        },
        Getmonth(value) {
         return moment(value).format("MM");
        },
        Getyear(value) {
         return moment(value).format("YYYY");
        },
        formatPrice(value) {
            let val = (value / 1).toFixed(0).replace(".", ",");
            return val.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
        },
        selectdtype(type){
            this.datere = type
        },
        CreateReport(){
            this.ShChart = false

            // sent report
            if(this.reportCode=='rp-pom'){
                    this.loading = true
                    this.$Progress.start();
                    this.$axios.get("/sanctum/csrf-cookie").then((response) => {
                        axios
                        .post("/api/create_report/reportfinancial",{
                                reportcode: this.reportCode,
                                datere: this.datere,
                                dmy:this.dmy
                        }).then((response) => {
                            if(response.data.success){
                                
                            this.loading =false

                            this.report_data.cap_all = response.data.cap_all;
                            this.report_data.cap_this_lastmonth = response.data.cap_this_lastmonth;
                            this.report_data.cap_this_month = response.data.cap_this_month;
                            this.report_data.revenue_all = response.data.revenue_all;
                            this.report_data.revenue_this_lastmonth = response.data.revenue_this_lastmonth;
                            this.report_data.revenue_this_month = response.data.revenue_this_month;
                            this.report_data.manager_expense_all = response.data.manager_expense_all;
                            this.report_data.manager_expense_this_lastmonth = response.data.manager_expense_this_lastmonth;
                            this.report_data.manager_expense_this_month = response.data.manager_expense_this_month;
                            this.report_data.financial_expense_all = response.data.financial_expense_all;
                            this.report_data.financial_expense_this_lastmonth = response.data.financial_expense_this_lastmonth;
                            this.report_data.financial_expense_this_month = response.data.financial_expense_this_month;
                            this.report_data.fee_expense_all = response.data.fee_expense_all;
                            this.report_data.fee_expense_this_lastmonth = response.data.fee_expense_this_lastmonth;
                            this.report_data.fee_expense_this_month = response.data.fee_expense_this_month;
                            this.report_data.staff_expense_all = response.data.staff_expense_all;
                            this.report_data.staff_expense_this_lastmonth = response.data.staff_expense_this_lastmonth;
                            this.report_data.staff_expense_this_month = response.data.staff_expense_this_month;
                            this.report_data.other_expense_all = response.data.other_expense_all;
                            this.report_data.other_expense_this_lastmonth = response.data.other_expense_this_lastmonth;
                            this.report_data.other_expense_this_month = response.data.other_expense_this_month;
                            this.report_data.tax_expense_all = response.data.tax_expense_all;
                            this.report_data.tax_expense_this_lastmonth = response.data.tax_expense_this_lastmonth;
                            this.report_data.tax_expense_this_month = response.data.tax_expense_this_month;
                            this.report_data.date_type = response.data.report_date_type;
                            this.report_data.date_start = response.data.report_date_start;
                            this.report_data.date_end = response.data.report_date_end;


                            this.$Progress.finish();
                            } else {
                                this.loading =false  
                            this.$notify( { group: "error", title: "ບໍ່ສຳເລັດ!", text: "ຜິດຜາດ: " + response.data.message, }, 4000 );
                            this.$Progress.fail();
                            }
                        })
                        .catch((error) => {
                            this.loading =false
                            this.$Progress.fail();
                            this.$notify( { group: "error", title: "ບໍ່ສຳເລັດ!", text: "ຜິດຜາດ: " + error.message, }, 4000 );
                        });
                    });
                }
                else if(this.reportCode=='rp-sub'){
                    this.loading = true
                    this.$Progress.start();
                    this.$axios.get("/sanctum/csrf-cookie").then((response) => {
                        axios
                        .post("/api/create_report/reportfinancial_subsin",{
                                reportcode: this.reportCode,
                                datere: this.datere,
                                dmy:this.dmy
                        }).then((response) => {
                            if(response.data.success){
                                
                            this.loading =false

                            this.report_data.curr_all = response.data.curr_all;
                            this.report_data.curr_last_month = response.data.curr_last_month;
                            this.report_data.curr_this_month = response.data.curr_this_month;
                            this.report_data.neehub_all = response.data.neehub_all;
                            this.report_data.neehub_last_month = response.data.neehub_last_month;
                            this.report_data.neehub_this_month = response.data.neehub_this_month;
                            this.report_data.instore_all = response.data.instore_all;
                            this.report_data.instore_last_month = response.data.instore_last_month;
                            this.report_data.instore_this_month = response.data.instore_this_month;
                            this.report_data.assetsother_all = response.data.assetsother_all;
                            this.report_data.assetsother_last_month = response.data.assetsother_last_month;
                            this.report_data.assetsother_this_month = response.data.assetsother_this_month;
                            this.report_data.assetin_all = response.data.assetin_all;
                            this.report_data.assetin_last_month = response.data.assetin_last_month;
                            this.report_data.assetin_this_month = response.data.assetin_this_month;
                            
                            this.report_data.assetout_all = response.data.assetout_all;
                            this.report_data.assetout_last_month = response.data.assetout_last_month;
                            this.report_data.assetout_this_month = response.data.assetout_this_month;
                            this.report_data.assetsee_all = response.data.assetsee_all;
                            this.report_data.assetsee_last_month = response.data.assetsee_last_month;
                            this.report_data.assetsee_this_month = response.data.assetsee_this_month;
                            this.report_data.assetinother_all = response.data.assetinother_all;
                            this.report_data.assetinother_last_month = response.data.assetinother_last_month;
                            this.report_data.assetinother_this_month = response.data.assetinother_this_month;
                            this.report_data.date_type = response.data.report_date_type;
                            this.report_data.date_start = response.data.report_date_start;
                            this.report_data.date_end = response.data.report_date_end;


                            this.$Progress.finish();
                            } else {
                                this.loading =false  
                            this.$notify( { group: "error", title: "ບໍ່ສຳເລັດ!", text: "ຜິດຜາດ: " + response.data.message, }, 4000 );
                            this.$Progress.fail();
                            }
                        })
                        .catch((error) => {
                            this.loading =false
                            this.$Progress.fail();
                            this.$notify( { group: "error", title: "ບໍ່ສຳເລັດ!", text: "ຜິດຜາດ: " + error.message, }, 4000 );
                        });
                    });
                }

                else if(this.reportCode=='rp-nee'){
                    this.loading = true
                    this.$Progress.start();
                    this.$axios.get("/sanctum/csrf-cookie").then((response) => {
                        axios
                        .post("/api/create_report/reportfinancial_neesin",{
                                reportcode: this.reportCode,
                                datere: this.datere,
                                dmy:this.dmy
                        }).then((response) => {
                            if(response.data.success){
                                
                            this.loading =false

                            this.report_data.neesentother_all = response.data.neesentother_all;
                            this.report_data.neesentother_last_month = response.data.neesentother_last_month;
                            this.report_data.neesentother_this_month = response.data.neesentother_this_month;
                            this.report_data.intsent_all = response.data.intsent_all;
                            this.report_data.intsent_last_month = response.data.intsent_last_month;
                            this.report_data.intsent_this_month = response.data.intsent_this_month;
                            this.report_data.taxsent_all = response.data.taxsent_all;
                            this.report_data.taxsent_last_month = response.data.taxsent_last_month;
                            this.report_data.taxsent_this_month = response.data.taxsent_this_month;
                            this.report_data.currh_all = response.data.currh_all;
                            this.report_data.currh_last_month = response.data.currh_last_month;
                            this.report_data.currh_this_month = response.data.currh_this_month;
                            this.report_data.neesinother_all = response.data.neesinother_all;
                            this.report_data.neesinother_last_month = response.data.neesinother_last_month;
                            this.report_data.neesinother_this_month = response.data.neesinother_this_month;
                            this.report_data.loan_all = response.data.loan_all;
                            this.report_data.loan_last_month = response.data.loan_last_month;
                            this.report_data.loan_this_month = response.data.loan_this_month;
                            this.report_data.currh2_all = response.data.currh2_all;
                            this.report_data.currh2_last_month = response.data.currh2_last_month;
                            this.report_data.currh2_this_month = response.data.currh2_this_month;
                            this.report_data.neesinlong_all = response.data.neesinlong_all;
                            this.report_data.neesinlong_last_month = response.data.neesinlong_last_month;
                            this.report_data.neesinlong_this_month = response.data.neesinlong_this_month;
                            this.report_data.standset_all = response.data.standset_all;
                            this.report_data.standset_last_month = response.data.standset_last_month;
                            this.report_data.standset_this_month = response.data.standset_this_month;
                            this.report_data.stand_all = response.data.stand_all;
                            this.report_data.stand_last_month = response.data.stand_last_month;
                            this.report_data.stand_this_month = response.data.stand_this_month;
                            this.report_data.profityear = response.data.profityear;

                            this.report_data.date_type = response.data.report_date_type;
                            this.report_data.date_start = response.data.report_date_start;
                            this.report_data.date_end = response.data.report_date_end;


                            this.$Progress.finish();
                            } else {
                                this.loading =false  
                            this.$notify( { group: "error", title: "ບໍ່ສຳເລັດ!", text: "ຜິດຜາດ: " + response.data.message, }, 4000 );
                            this.$Progress.fail();
                            }
                        })
                        .catch((error) => {
                            this.loading =false
                            this.$Progress.fail();
                            this.$notify( { group: "error", title: "ບໍ່ສຳເລັດ!", text: "ຜິດຜາດ: " + error.message, }, 4000 );
                        });
                    });
                }
            // end send report rp-sub


        },
        GenGrap_acc(){
            this.ShChart = true
            this.key++ 
            if(this.reportCode=='racc'){
                if(this.datere == 'm'){
                    let y = this.dmy.split('-')[0]
                    let m = this.dmy.split('-')[1]
                    let lastday = this.Getlastday(y,m)
                    
                    let db_income = this.GetIncome(lastday,this.datareport)
                    let db_cincome = this.GetCIncome(lastday,this.datareport)
                    let db_expense = this.GetExpense(lastday,this.datareport)

                    console.log(db_cincome)
                   // console.log(db_expense)
                }
            }
        },
        GenGrap(){
            this.ShChart = true
            this.key++ 
            if(this.reportCode=='racc'){
                // console.log(this.Getlastday(2021,10))
                this.chdata = null
                let db_income = this.datareport.filter((i)=>i.trn_type == 'income')
                let db_expense = this.datareport.filter((i)=>i.trn_type == 'expense')
                let db_cexpense = this.datareport.filter((i)=>i.trn_type == 'cexpense')
                let db_cincome = this.datareport.filter((i)=>i.trn_type == 'cincome')
                let db_capital = this.datareport.filter((i)=>i.trn_type == 'capital')

                let re_income = []
                let re_expense = []
                let re_cincome = []
                let re_cexpense = []
                let re_capital = []

                if(this.datere == 'm'){
                    //console.log(this.chdata)
                    let y = this.dmy.split('-')[0]
                    let m = this.dmy.split('-')[1]
                    let lastday = this.Getlastday(y,m)
                    let chart_label = []
                    re_income = this.Get_data_chart(lastday,db_income) || 0
                    re_expense = this.Get_data_chart(lastday,db_expense) || 0
                    re_cincome = this.Get_data_chart(lastday,db_cincome) || 0
                    re_cexpense = this.Get_data_chart(lastday,db_cexpense) || 0
                    re_capital = this.Get_data_chart(lastday,db_capital) || 0

                    for (let i = 0; i < lastday; i++) { chart_label.push('ວັນທີ່ '+(i+1)) }
                        // Blue #3366CC
                        // Red #DC3912
                        // Yellow #FF9900
                        // Green #109618
                        // Purple #990099
                        // Sea blue #0099C6
                        // Pastel pink #DD4477
                    this.chdata = {
                            labels: chart_label,
                            datasets: [
                                {
                                    label: 'ລາຍຮັບ',
                                    fill: false,
                                    borderColor: '#3366CC',
                                    data: re_income
                                },
                                {
                                    label: 'ລາຍຈ່າຍ',
                                    fill: false,
                                    borderColor: '#DC3912',
                                    data: re_expense
                                },
                                {
                                    label: 'ໜີ້ຕ້ອງຮັບ',
                                    fill: false,
                                    borderColor: '#FF9900',
                                    data: re_cincome
                                },
                                {
                                    label: 'ໜີ້ຕ້ອງສົ່ງ',
                                    fill: false,
                                    borderColor: '#990099',
                                    data: re_cexpense
                                },
                                {
                                    label: 'ລົງທຶນ',
                                    fill: false,
                                    borderColor: '#109618',
                                    data: re_capital
                                }
                                ]}
                        this.update_chart = Math.floor(Math.random() * 100);

                } else if(this.datere == 'm1-3' || this.datere == 'm1-6' || this.datere == 'm1-9' || this.datere == 'y'){
                    let y = this.dmy.split('-')[0]
                    let m = this.dmy.split('-')[1]
                    let lastday = this.Getlastday(y,m)
                    let chart_label = null
                    let minth_chart = null
                    if(this.datere == 'm1-3'){ chart_label = ['ເດືອນ 1','ເດືອນ 2','ເດືອນ 3']; minth_chart=3 }
                    else if(this.datere == 'm1-6'){ chart_label = ['ເດືອນ 1','ເດືອນ 2','ເດືອນ 3','ເດືອນ 4','ເດືອນ 5','ເດືອນ 6']; minth_chart=6}
                    else if(this.datere == 'm1-9'){ chart_label = ['ເດືອນ 1','ເດືອນ 2','ເດືອນ 3','ເດືອນ 4','ເດືອນ 5','ເດືອນ 6','ເດືອນ 7','ເດືອນ 8','ເດືອນ 9']; minth_chart=9}
                    else if(this.datere == 'y'){ chart_label = ['ເດືອນ 1','ເດືອນ 2','ເດືອນ 3','ເດືອນ 4','ເດືອນ 5','ເດືອນ 6','ເດືອນ 7','ເດືອນ 8','ເດືອນ 9','ເດືອນ 10','ເດືອນ 11','ເດືອນ 12']; minth_chart=12}
                    

                    re_income = this.Get_data_chart_m3(minth_chart,db_income) || 0
                    re_expense = this.Get_data_chart_m3(minth_chart,db_expense) || 0
                    re_cincome = this.Get_data_chart_m3(minth_chart,db_cincome) || 0
                    re_cexpense = this.Get_data_chart_m3(minth_chart,db_cexpense) || 0
                    re_capital = this.Get_data_chart_m3(minth_chart,db_capital) || 0

                    //for (let i = 0; i < lastday; i++) { chart_label.push('ວັນທີ່ '+(i+1)) }

                    this.chdata = {
                            labels: chart_label,
                            datasets: [
                                {
                                    label: 'ລາຍຮັບ',
                                    fill: false,
                                    borderColor: '#3366CC',
                                    data: re_income
                                },
                                {
                                    label: 'ລາຍຈ່າຍ',
                                    fill: false,
                                    borderColor: '#DC3912',
                                    data: re_expense
                                },
                                {
                                    label: 'ໜີ້ຕ້ອງຮັບ',
                                    fill: false,
                                    borderColor: '#FF9900',
                                    data: re_cincome
                                },
                                {
                                    label: 'ໜີ້ຕ້ອງສົ່ງ',
                                    fill: false,
                                    borderColor: '#990099',
                                    data: re_cexpense
                                },
                                {
                                    label: 'ລົງທຶນ',
                                    fill: false,
                                    borderColor: '#109618',
                                    data: re_capital
                                }
                                ]}
                        this.update_chart = Math.floor(Math.random() * 100);

                } 
                
            } else if(this.reportCode=='raccs' || this.reportCode=='raccb' || this.reportCode=='raccsb'){
                // console.log(this.Getlastday(2021,10))
                let alldb = null
                if(this.reportCode=='raccs'){ alldb = this.dataInEx }
                else if(this.reportCode=='raccb'){ alldb = this.dataInExB }
                else if(this.reportCode=='raccsb'){ alldb = this.dataInExSB }
                this.chdata = null
                let db_income = alldb.filter((i)=>i.trn_type == 'income')
                let db_expense = alldb.filter((i)=>i.trn_type == 'expense')
                // let db_cexpense = this.datareport.filter((i)=>i.trn_type == 'cexpense')
                // let db_cincome = this.datareport.filter((i)=>i.trn_type == 'cincome')
                // let db_capital = this.datareport.filter((i)=>i.trn_type == 'capital')

                let re_income = []
                let re_expense = []
                // let re_cincome = []
                // let re_cexpense = []
                // let re_capital = []

                if(this.datere == 'm'){
                    //console.log(this.chdata)
                    let y = this.dmy.split('-')[0]
                    let m = this.dmy.split('-')[1]
                    let lastday = this.Getlastday(y,m)
                    let chart_label = []
                    re_income = this.Get_data_chart(lastday,db_income) || 0
                    re_expense = this.Get_data_chart(lastday,db_expense) || 0
                    // re_cincome = this.Get_data_chart(lastday,db_cincome) || 0
                    // re_cexpense = this.Get_data_chart(lastday,db_cexpense) || 0
                    // re_capital = this.Get_data_chart(lastday,db_capital) || 0

                    for (let i = 0; i < lastday; i++) { chart_label.push('ວັນທີ່ '+(i+1)) }
                        // Blue #3366CC
                        // Red #DC3912
                        // Yellow #FF9900
                        // Green #109618
                        // Purple #990099
                        // Sea blue #0099C6
                        // Pastel pink #DD4477
                    this.chdata = {
                            labels: chart_label,
                            datasets: [
                                {
                                    label: 'ລາຍຮັບ',
                                    fill: false,
                                    borderColor: '#3366CC',
                                    data: re_income
                                },
                                {
                                    label: 'ລາຍຈ່າຍ',
                                    fill: false,
                                    borderColor: '#DC3912',
                                    data: re_expense
                                },
                                // {
                                //     label: 'ໜີ້ຕ້ອງຮັບ',
                                //     fill: false,
                                //     borderColor: '#FF9900',
                                //     data: re_cincome
                                // },
                                // {
                                //     label: 'ໜີ້ຕ້ອງສົ່ງ',
                                //     fill: false,
                                //     borderColor: '#990099',
                                //     data: re_cexpense
                                // },
                                // {
                                //     label: 'ລົງທຶນ',
                                //     fill: false,
                                //     borderColor: '#109618',
                                //     data: re_capital
                                // }
                                ]}
                        this.update_chart = Math.floor(Math.random() * 100);

                } else if(this.datere == 'm1-3' || this.datere == 'm1-6' || this.datere == 'm1-9' || this.datere == 'y'){
                    let y = this.dmy.split('-')[0]
                    let m = this.dmy.split('-')[1]
                    let lastday = this.Getlastday(y,m)
                    let chart_label = null
                    let minth_chart = null
                    if(this.datere == 'm1-3'){ chart_label = ['ເດືອນ 1','ເດືອນ 2','ເດືອນ 3']; minth_chart=3 }
                    else if(this.datere == 'm1-6'){ chart_label = ['ເດືອນ 1','ເດືອນ 2','ເດືອນ 3','ເດືອນ 4','ເດືອນ 5','ເດືອນ 6']; minth_chart=6}
                    else if(this.datere == 'm1-9'){ chart_label = ['ເດືອນ 1','ເດືອນ 2','ເດືອນ 3','ເດືອນ 4','ເດືອນ 5','ເດືອນ 6','ເດືອນ 7','ເດືອນ 8','ເດືອນ 9']; minth_chart=9}
                    else if(this.datere == 'y'){ chart_label = ['ເດືອນ 1','ເດືອນ 2','ເດືອນ 3','ເດືອນ 4','ເດືອນ 5','ເດືອນ 6','ເດືອນ 7','ເດືອນ 8','ເດືອນ 9','ເດືອນ 10','ເດືອນ 11','ເດືອນ 12']; minth_chart=12}
                    

                    re_income = this.Get_data_chart_m3(minth_chart,db_income) || 0
                    re_expense = this.Get_data_chart_m3(minth_chart,db_expense) || 0
                    // re_cincome = this.Get_data_chart_m3(minth_chart,db_cincome) || 0
                    // re_cexpense = this.Get_data_chart_m3(minth_chart,db_cexpense) || 0
                    // re_capital = this.Get_data_chart_m3(minth_chart,db_capital) || 0

                    //for (let i = 0; i < lastday; i++) { chart_label.push('ວັນທີ່ '+(i+1)) }

                    this.chdata = {
                            labels: chart_label,
                            datasets: [
                                {
                                    label: 'ລາຍຮັບ',
                                    fill: false,
                                    borderColor: '#3366CC',
                                    data: re_income
                                },
                                {
                                    label: 'ລາຍຈ່າຍ',
                                    fill: false,
                                    borderColor: '#DC3912',
                                    data: re_expense
                                },
                                // {
                                //     label: 'ໜີ້ຕ້ອງຮັບ',
                                //     fill: false,
                                //     borderColor: '#FF9900',
                                //     data: re_cincome
                                // },
                                // {
                                //     label: 'ໜີ້ຕ້ອງສົ່ງ',
                                //     fill: false,
                                //     borderColor: '#990099',
                                //     data: re_cexpense
                                // },
                                // {
                                //     label: 'ລົງທຶນ',
                                //     fill: false,
                                //     borderColor: '#109618',
                                //     data: re_capital
                                // }
                                ]}
                        this.update_chart = Math.floor(Math.random() * 100);

                } 
                
            }
        },
        GetIncome(day,data){
                    //let day = 31
                    let db_income_cr = []
                    let re_income = []
                    let db = data
                    let re = this.re
                    for (let i = 0; i < db.length; i++) {
                        if(re.includes(db[i].cr) && db[i].dr!='411'){
                            db_income_cr.push({'day':this.Getday(db[i].created_at),'cr':db[i].cr,'price':db[i].sum})
                        }
                    }

                    let update_db_in = db_income_cr.reduce((a, c) => {
                                let filtered = a.filter(el => el.day === c.day);
                                if(filtered.length > 0){
                                    a[a.indexOf(filtered[0])].price =parseInt(a[a.indexOf(filtered[0])].price) + parseInt(c.price);
                                }else{
                                    a.push(c);
                                }
                                return a;
                            }, []);

                    for (let i = 0; i < day; i++) {
                            let type = true
                            for (let k = 0; k < update_db_in.length; k++) {
                              if(update_db_in[k].day==i+1){
                                  if(type){
                                      re_income.push(update_db_in[k].price)
                                      type = false
                                  }
                              } 
                            }
                            if(type){ re_income.push(0); type = false }
                    }
                    return re_income
        },
        GetCIncome(day,data){
            let db_income_cr = []
                    let re_income = []
                    let db = data
                    let ex = this.ex
                    for (let i = 0; i < db.length; i++) {
                        if(db[i].cr=='411' || db[i].dr=='411'){   /// ຍັງໜີ້ຕ້ອງສົ່ງ
                            // let dr =null
                            // let cr =null
                            // if(db[i].cr=='411'){ cr = db[i].sum }
                            // if(db[i].dr=='411'){ dr = db[i].sum }

                            db_income_cr.push({'day':this.Getday(db[i].created_at),'dr':db[i].dr,'price':dr-cr})
                        }
                    }

                    let update_db_in = db_income_cr.reduce((a, c) => {
                                let filtered = a.filter(el => el.day === c.day);
                                if(filtered.length > 0){
                                    a[a.indexOf(filtered[0])].price =parseInt(a[a.indexOf(filtered[0])].price) + parseInt(c.price);
                                }else{
                                    a.push(c);
                                }
                                return a;
                            }, []);

                    for (let i = 0; i < day; i++) {
                            let type = true
                            for (let k = 0; k < update_db_in.length; k++) {
                              if(update_db_in[k].day==i+1){
                                  if(type){
                                      re_income.push(update_db_in[k].price)
                                      type = false
                                  }
                              } 
                            }
                            if(type){ re_income.push(0); type = false }
                    }
                    return re_income
        },
        GetExpense(day,data){
                    let db_income_cr = []
                    let re_income = []
                    let db = data
                    let ex = this.ex
                    for (let i = 0; i < db.length; i++) {
                        if(ex.includes(db[i].dr)){   /// ຍັງໜີ້ຕ້ອງສົ່ງ
                            db_income_cr.push({'day':this.Getday(db[i].created_at),'dr':db[i].dr,'price':db[i].sum})
                        }
                    }

                    let update_db_in = db_income_cr.reduce((a, c) => {
                                let filtered = a.filter(el => el.day === c.day);
                                if(filtered.length > 0){
                                    a[a.indexOf(filtered[0])].price =parseInt(a[a.indexOf(filtered[0])].price) + parseInt(c.price);
                                }else{
                                    a.push(c);
                                }
                                return a;
                            }, []);

                    for (let i = 0; i < day; i++) {
                            let type = true
                            for (let k = 0; k < update_db_in.length; k++) {
                              if(update_db_in[k].day==i+1){
                                  if(type){
                                      re_income.push(update_db_in[k].price)
                                      type = false
                                  }
                              } 
                            }
                            if(type){ re_income.push(0); type = false }
                    }
                    return re_income
        },
        Get_data_chart(day,data){

                 let new_db_in = []
                 let re_income =[]
                for (let y = 0; y < data.length; y++) {
                                if(data[y]!=''){
                                let day = this.Getday(data[y].created_at)
                                new_db_in.push({'price':data[y].sum,'day':day})
                                }
                }
                       let update_db_in = new_db_in.reduce((a, c) => {
                                let filtered = a.filter(el => el.day === c.day);
                                if(filtered.length > 0){
                                    a[a.indexOf(filtered[0])].price =parseInt(a[a.indexOf(filtered[0])].price) + parseInt(c.price);
                                }else{
                                    a.push(c);
                                }
                                return a;
                            }, []);
                    for (let i = 0; i < day; i++) {
                            let type = true
                            for (let k = 0; k < update_db_in.length; k++) {
                              if(update_db_in[k].day==i+1){
                                  if(type){
                                      re_income.push(update_db_in[k].price)
                                      type = false
                                  }
                              } 
                            }
                            if(type){ re_income.push(0); type = false }
                    }
                    return re_income
        },
        Get_data_chart_m3(minth_chart,data){
                let new_db_in = []
                 let re_income =[]
                for (let y = 0; y < data.length; y++) {
                                if(data[y]!=''){
                                let month = this.Getmonth(data[y].created_at)
                                new_db_in.push({'price':data[y].sum,'month':month})
                                }
                }

                let update_db_in = new_db_in.reduce((a, c) => {
                                let filtered = a.filter(el => el.month == c.month);
                                if(filtered.length > 0){
                                    a[a.indexOf(filtered[0])].price =parseInt(a[a.indexOf(filtered[0])].price) + parseInt(c.price);
                                }else{
                                    a.push(c);
                                }
                                return a;
                            }, []);
                    // for (let i = 0; i < update_db_in.length; i++) {
                    //    if(update_db_in[i]!=''){
                    //        re_income.push(update_db_in[i].price)
                    //    }
                    // }

                    for (let i = 0; i < minth_chart; i++) {
                            let type = true
                            for (let k = 0; k < update_db_in.length; k++) {
                              if(update_db_in[k].month==i+1){
                                  if(type){
                                      re_income.push(update_db_in[k].price)
                                      type = false
                                  }
                              } 
                            }
                            if(type){ re_income.push(0); type = false }
                    }

                    return re_income
        },
      
        Getlastday(y,m){
            return  new Date(y, m , 0).getDate();
            }
    },
    created(){
        this.dmy = this.currentDate()
    },


//     mounted() {
//     new Chart(this.$refs.myChart, {
//       type: 'line',
//       data: {
//       labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
//       datasets: [
//         {
//           label: 'Data One',
//           backgroundColor: '#f87979',
//           data: [40, 39, 10, 40, 39, 80, 40]
//         }
//       ]
//     }
//     });
//   }
};
</script>

<style lang="scss" scoped>
    table td, .table th {
    padding: 4px;
    }
    .table680{
            max-width: 680px;
            margin: auto;
    }
    table thead, table tr td{
        padding-bottom: 15px;
    }
  
    table, th, td {
         border: 1px solid rgb(121, 120, 120);
    }
//     table thead, table tr td{
//     padding-bottom: 0px
// }
</style>