protected static function _pembelian($tanggal1, $tanggal2)
 {
     return \App\PembelianDetail::join('produks', 'pembelian_details.relation_id', '=', 'produks.id')->join('pembelians', 'pembelian_details.pembelian_id', '=', 'pembelians.id')->whereBetween('pembelians.tanggal', [$tanggal1, $tanggal2])->where('pembelian_details.type', 'produk')->groupBy('produks.id')->select(['produks.id', 'produks.nama', DB::raw('SUM(pembelian_details.stok)qty')])->get()->toArray();
 }
 public function bayar($id)
 {
     if (Gate::denies('pembelian.bayar')) {
         return view(config('app.template') . '.error.403');
     }
     $data = ['id' => $id, 'total' => PembelianDetail::where('pembelian_id', $id)->get()->sum('harga'), 'bayars' => PembelianBayar::with('karyawan')->where('pembelian_id', $id)->orderBy('tanggal')->get()];
     return view(config('app.template') . '.pembelian.table-bayar', $data);
 }
 protected function _purchasedItemBahanPertahun(Request $request)
 {
     $tahun = $request->get('tahun') ? $request->get('tahun') : date('Y');
     $bahans = \App\PembelianDetail::join('bahans', 'pembelian_details.relation_id', '=', 'bahans.id')->join('pembelians', 'pembelian_details.pembelian_id', '=', 'pembelians.id')->where(DB::raw('SUBSTRING(pembelians.tanggal, 1, 4)'), $tahun)->where('type', 'bahan')->select(['bahans.nama', DB::raw('SUM(pembelian_details.qty)qty'), 'pembelian_details.satuan', DB::raw('ROUND(SUM(pembelian_details.harga)/SUM(pembelian_details.stok))harga_per_stok'), DB::raw('SUM(pembelian_details.stok)stok'), DB::raw('SUM(pembelian_details.harga)total')])->groupBy('bahans.id')->get();
     return ['tanggal' => Carbon::createFromFormat('Y', $tahun), 'bahans' => $bahans];
 }