public function export()
 {
     Excel::create('Penjualan', function ($excel) {
         $excel->sheet('Penjualan', function ($sheet) {
             $penjualans = Penjualan::whereBetween('tgl_transfer', [$_POST['tgl_mulai'], $_POST['tgl_selesai']])->get();
             $details = Penjualan::with('detailPenjualan')->whereBetween('tgl_transfer', [$_POST['tgl_mulai'], $_POST['tgl_selesai']])->get();
             $tChemical = [1, 2, 3, 4, 8];
             $tBb = [6, 7];
             $chemical = 0;
             $perlengkapan = 0;
             $bb = 0;
             foreach ($details as $key => $row) {
                 foreach ($row->detailPenjualan as $key => $d) {
                     if (in_array(Helpers::tipe($d->barang_id), $tChemical)) {
                         $chemical += $d->total;
                     } elseif (in_array(Helpers::tipe($d->barang_id), $tBb)) {
                         $bb += $d->total;
                     } else {
                         $perlengkapan += $d->total;
                     }
                 }
             }
             $sheet->loadView('admin.penjualans.csv', ['penjualans' => $penjualans, 'details' => $details, 'bb' => $bb, 'perlengkapan' => $perlengkapan, 'chemical' => $chemical]);
         });
     })->download('xls');
 }
 public function printChart()
 {
     $penjualans = Penjualan::orderBy('tgl_transfer', 'DESC')->take(7)->get();
     $barangs = Barang::orderBy('id', 'DESC')->take(4)->get();
     $customers = Penjualan::with('customer')->orderBy('tgl_transfer', 'DESC')->take(8)->get();
     $baru = Penjualan::where('status', 1)->count();
     $orders = Order::where('status', 1)->count();
     $poBaru = Penjualan::where('tgl_transfer', '>=', '2015-11-01')->count();
     $okt = Penjualan::whereBetween('tgl_transfer', ['2015-10-01', '2015-10-31'])->get();
     $sep = Penjualan::whereBetween('tgl_transfer', ['2015-09-01', '2015-09-30'])->get();
     $okts['dates'] = $okt->lists('tgl_transfer');
     $okts['totals'] = $okt->lists('nominal');
     $seps['dates'] = $sep->lists('tgl_transfer');
     $seps['totals'] = $sep->lists('nominal');
     $sumO = 0;
     foreach ($okts['totals'] as $t) {
         $sumO += $t;
     }
     $sumS = 0;
     foreach ($seps['totals'] as $t) {
         $sumS += $t;
     }
     $mar = Penjualan::whereBetween('tgl_transfer', ['2015-03-19', '2015-03-31'])->lists('nominal');
     $apr = Penjualan::whereBetween('tgl_transfer', ['2015-04-01', '2015-04-31'])->lists('nominal');
     $may = Penjualan::whereBetween('tgl_transfer', ['2015-05-01', '2015-05-31'])->lists('nominal');
     $jun = Penjualan::whereBetween('tgl_transfer', ['2015-06-01', '2015-06-31'])->lists('nominal');
     $jul = Penjualan::whereBetween('tgl_transfer', ['2015-07-01', '2015-07-31'])->lists('nominal');
     $aug = Penjualan::whereBetween('tgl_transfer', ['2015-08-01', '2015-08-31'])->lists('nominal');
     $nov = Penjualan::where('tgl_transfer', '>=', Carbon::now()->startOfMonth())->lists('nominal');
     $lap['maret'] = 0;
     $lap['april'] = 0;
     $lap['mei'] = 0;
     $lap['juni'] = 0;
     $lap['juli'] = 0;
     $lap['agustus'] = 0;
     $lap['sept'] = $sumS;
     $lap['okt'] = $sumO;
     $lap['nov'] = 0;
     foreach ($mar as $m) {
         $lap['maret'] += $m;
     }
     foreach ($apr as $m) {
         $lap['april'] += $m;
     }
     foreach ($may as $m) {
         $lap['mei'] += $m;
     }
     foreach ($jun as $m) {
         $lap['juni'] += $m;
     }
     foreach ($jul as $m) {
         $lap['juli'] += $m;
     }
     foreach ($aug as $m) {
         $lap['agustus'] += $m;
     }
     foreach ($nov as $m) {
         $lap['nov'] += $m;
     }
     return View::make('admin/charts.linePoChart', compact('penjualans', 'barangs', 'customers', 'baru', 'poBaru', 'okts', 'seps', 'sumO', 'sumS', 'orders', 'lap'));
 }