/** * Display a listing of the resource. * * @return Response */ public function index($id, Request $request) { $date = $request->get('date', date('Y-m-d')); $ksos = $this->ksos->join('fleets', 'ksos.fleet_id', '=', 'fleets.id')->where('ksos.pool_id', Auth::user()->pool_id)->where('ksos.actived', 1)->orderBy('fleets.taxi_number')->get(['ksos.*', 'fleets.taxi_number']); $total = DB::table('checkins')->select(DB::raw('sum(if((checkin_financials.financial_type_id = 1),checkin_financials.amount,0)) AS setoran_wajib,sum(if((checkin_financials.financial_type_id = 2),checkin_financials.amount,0)) AS tabungan_sparepart,sum(if((checkin_financials.financial_type_id = 3),checkin_financials.amount,0)) AS denda,sum(if((checkin_financials.financial_type_id = 4),checkin_financials.amount,0)) AS potongan,sum(if((checkin_financials.financial_type_id = 5),checkin_financials.amount,0)) AS cicilan_sparepart,sum(if((checkin_financials.financial_type_id = 6),checkin_financials.amount,0)) AS cicilan_ks,sum(if((checkin_financials.financial_type_id = 7),checkin_financials.amount,0)) AS biaya_cuci,sum(if((checkin_financials.financial_type_id = 8),checkin_financials.amount,0)) AS iuran_laka,sum(if((checkin_financials.financial_type_id = 9),checkin_financials.amount,0)) AS cicilan_dp_kso,sum(if((checkin_financials.financial_type_id = 10),checkin_financials.amount,0)) AS cicilan_hutang_lama,sum(if((checkin_financials.financial_type_id = 11),checkin_financials.amount,0)) AS ks,sum(if((checkin_financials.financial_type_id = 12),checkin_financials.amount,0)) AS cicilan_lain,sum(if((checkin_financials.financial_type_id = 13),checkin_financials.amount,0)) AS hutang_dp_sparepart,sum(if((checkin_financials.financial_type_id = 20),checkin_financials.amount,0)) AS setoran_cash,sum(if((checkin_financials.financial_type_id = 21),checkin_financials.amount,0)) AS tabungan,(sum(if((checkin_financials.financial_type_id = 11),checkin_financials.amount,0)) - sum(if((checkin_financials.financial_type_id = 6),checkin_financials.amount,0))) AS selisi_ks '))->addSelect(DB::raw('checkins.id, checkins.operasi_time , checkins.pool_id, checkins.shift_id'))->leftJoin('checkin_financials', 'checkins.id', '=', 'checkin_financials.checkin_id')->where('checkins.kso_id', $id)->where('checkins.operasi_time', '<=', $date)->groupBy('checkins.kso_id')->first(); $sparepart = DB::table('work_orders')->select(DB::raw('work_orders.id AS id,work_orders.kso_id AS kso_id,work_orders.wo_number AS wo_number,work_orders.fleet_id AS fleet_id,work_orders.driver_id AS driver_id,work_orders.pool_id AS pool_id,work_orders.km AS km,work_orders.complaint AS complaint,work_orders.information_complaint AS information_complaint,work_orders.status AS status,work_orders.beban AS beban,work_orders.mechanic_id AS mechanic_id,work_orders.mechanic AS mechanic,work_orders.dp_sparepart AS dp_sparepart,work_orders.user_id AS user_id,work_orders.inserted_date_set AS inserted_date_set,work_orders.finished_date_set AS finished_date_set,work_orders.fg_part_approved AS fg_part_approved,work_orders.user_approved AS user_approved,sum((wo_part_items.qty * wo_part_items.price)) AS pemakaian_part'))->leftJoin('wo_part_items', 'work_orders.id', '=', 'wo_part_items.wo_id')->where('work_orders.status', 3)->where('wo_part_items.telah_dikeluarkan', 1)->where('work_orders.beban', 0)->where('work_orders.kso_id', $id)->where('work_orders.finished_date_set', '<=', $date)->groupBy('work_orders.kso_id')->first(); $total_pemakaian_part = 0; if ($sparepart) { $total_pemakaian_part = $sparepart->pemakaian_part; } $kso = $this->ksos->find($id); $fleet = $kso->fleet; return view('armada.dashboard', compact('ksos', 'kso', 'fleet', 'total', 'total_pemakaian_part', 'date')); }
/** * [scopeWithTags description] * * @param [type] $query [description] * @param array $tagIds Tag id's * @param boolean $and If `true` posts should have all the given tags * * @return [type] [description] */ public function scopeWithTags($query, $tagIds = [], $and = false) { if (!is_array($tagIds)) { $tagIds = [$tagIds]; } $query->join('blog_post_tag', 'blog_posts.id', '=', 'blog_post_tag.post_id')->whereIn('blog_post_tag.tag_id', $tagIds)->groupBy('blog_post_tag.post_id')->havingRaw('COUNT(DISTINCT `blog_post_tag`.`tag_id`) = ?', [count($tagIds)]); }