public function Chart()
 {
     $yesterday = Carbon::now();
     $start = $yesterday->copy()->addDays(-7);
     $end = $yesterday->copy();
     // for query
     $startBetween = $start->format('Y-m-d');
     $endBetween = $end->format('Y-m-d');
     $dates = [];
     while ($start->lte($end)) {
         $dates[] = $start->copy();
         $start->addDay();
     }
     $dates = collect($dates)->forPage(1, 7);
     $reports = \App\Order::ReportGroup("(orders.`tanggal` BETWEEN '{$startBetween}' AND '{$endBetween}')", "GROUP BY tanggal");
     $reports = ConvertRawQueryToArray($reports);
     $dataLastWeek = [];
     $dataLabelLastWeek = [];
     foreach ($dates as $date) {
         $idx = array_search($date->format("Y-m-d"), array_column($reports, "tanggal"));
         $val = 0;
         if (false !== $idx) {
             $d = $reports[$idx];
             $val = $d['jumlah'];
         }
         $dataLabelLastWeek[] = $date->format('d M Y');
         $dataLastWeek[] = $val;
     }
     return ['label' => $dataLabelLastWeek, 'data' => $dataLastWeek];
 }
 protected function _labaRugiPertahun(Request $request)
 {
     $tahun = $request->get('tahun') ? $request->get('tahun') : date('Y');
     $penjualans = Order::ReportGroup("SUBSTRING(orders.`tanggal`, 1, 4) = '{$tahun}'", "GROUP BY SUBSTRING(tanggal, 1, 4)");
     $penjualans = ConvertRawQueryToArray($penjualans);
     $accountSaldo = \App\AccountSaldo::join('accounts', 'account_saldos.account_id', '=', 'accounts.id')->leftJoin(DB::raw("(SELECT accounts.`id` AS account_id, accounts.`nama_akun`, reports.display\n                    FROM accounts\n                    INNER JOIN account_report ON accounts.`id` = account_report.`account_id`\n                    INNER JOIN reports ON account_report.`report_id` = reports.id\n                    WHERE reports.key = 'labarugi')temp_report"), function ($join) {
         $join->on('accounts.id', '=', 'temp_report.account_id');
     })->where(DB::raw('SUBSTRING(account_saldos.tanggal, 1, 4)'), $tahun)->whereNull('account_saldos.relation_id')->whereNotNull('temp_report.account_id')->groupBy('accounts.id')->select(['accounts.nama_akun', DB::raw('SUM(account_saldos.nominal)total'), 'account_saldos.type'])->get()->groupBy('type');
     $tableTemp = $this->buildLabaRugiTable(['penjualans' => $penjualans, 'account_saldo' => $accountSaldo]);
     return ['tanggal' => Carbon::createFromFormat('Y', $tahun), 'tableTemp' => $tableTemp];
 }