public function importshoplists()
 {
     $ext = Input::file('file')->getClientOriginalExtension();
     $validator = Validator::make(array('ext' => $ext), array('ext' => 'in:xls,xlsx'));
     if ($validator->fails()) {
         Session::flash('error', 'File format tidak di dukung');
         return Redirect::to('/admin/import/shoplists');
     } else {
         if ($ext == 'xls') {
             Input::file('file')->move(public_path(), 'sl.xls');
             if (Input::get('replace') == 'on') {
                 DB::table('shoplist')->delete();
             } else {
             }
             try {
                 Excel::load('public/sl.xls', function ($r) {
                     $res = $r->all()->toArray();
                     foreach ($res as $data) {
                         $d = new Shoplist();
                         $d->kode = $data['kode_sl'];
                         $d->deskripsi = $data['deskripsi_pekerjaan'];
                         $d->satuan = $data['satuan'];
                         $d->harga = $data['harga'];
                         $d->save();
                     }
                 });
             } catch (Exception $e) {
                 Session::flash('error', 'File tidak sesuai format');
                 return Redirect::to('/admin/import/shoplists');
             }
         } elseif ($ext == 'xlsx') {
             Input::file('file')->move(public_path(), 'sl.xlsx');
             if (Input::get('replace') == 'on') {
                 DB::table('shoplist')->delete();
             } else {
             }
             try {
                 Excel::load('public/sl.xlsx', function ($r) {
                     $res = $r->all()->toArray();
                     foreach ($res as $data) {
                         $d = new Shoplist();
                         $d->kode = $data['kode_sl'];
                         $d->deskripsi = $data['deskripsi_pekerjaan'];
                         $d->satuan = $data['satuan'];
                         $d->harga = $data['harga'];
                         $d->save();
                     }
                 });
             } catch (Exception $e) {
                 Session::flash('error', 'File tidak sesuai format');
                 return Redirect::to('/admin/import/shoplists');
             }
         } else {
         }
         Session::flash('success', 'Data telah dibuat.');
         return Redirect::to('/admin/import/shoplists');
     }
 }
 public function storefromajax()
 {
     $shoplist = new Shoplist();
     $shoplist->kode = Input::get('kode');
     $shoplist->deskripsi = Input::get('deskripsi');
     $shoplist->satuan = Input::get('satuan');
     $shoplist->harga = Input::get('harga');
     $shoplist->save();
     return Response::json($shoplist);
 }
 public function storespj()
 {
     $oss = new OSS();
     $oss->oss_type = "spj";
     $oss->user_id = Auth::user()->id;
     $oss->tanggal = Carbon::parse(Input::get('tanggal'));
     $oss->bantek = Input::get('bantek');
     $oss->permasalahan = Input::get('permasalahan');
     $oss->action = Input::get('action');
     $oss->mulai = Carbon::parse(Input::get('mulai'));
     $oss->selesai = Carbon::parse(Input::get('selesai'));
     $oss->kode_rks = Input::get('kode_rks');
     $oss->deskripsi_rks = Input::get('deskripsi_rks');
     $oss->transport = Input::get('transport');
     $oss->user_mengerjakan = Input::get('mengerjakan');
     $oss->user_mengetahui = Input::get('mengetahui');
     $oss->save();
     $list_site = Input::get('namasite');
     for ($si = 0; $si < count($list_site); $si++) {
         $ns = new OSSBantekSite();
         $ns->oss_id = $oss->id;
         $ns->site_id = $list_site[$si];
         $ns->save();
     }
     $shopping_list = Input::get('shoplist');
     $harga = 0;
     for ($i = 0; $i < count($shopping_list); $i++) {
         $ss = new OSShop();
         $ss->oss_id = $oss->id;
         $ss->shoplist_id = $shopping_list[$i];
         $ss->save();
         $sl = Shoplist::find($shopping_list[$i]);
         $harga += $sl->harga;
     }
     $oss->harga = $harga;
     $oss->save();
     $menyetujui = Input::get('menyetujui');
     for ($j = 0; $j < count($menyetujui); $j++) {
         $stj = new MenyetujuiOSS();
         $stj->oss_id = $oss->id;
         $stj->user_id = $menyetujui[$j];
         $stj->save();
     }
     //perhitungan RKS
     $biaya_rks = 0;
     $st = new Carbon(Input::get('mulai'));
     $nd = new Carbon(Input::get('selesai'));
     $diff = $nd->diff($st)->days;
     if ($diff > 1) {
         $biaya_rks += 350000 * ($diff - 1);
         $biaya_rks += 150000;
     } else {
         if ($diff == 1) {
             $biaya_rks = 350000;
         } else {
             $biaya_rks = 150000;
         }
     }
     $oss->harga_rks = $biaya_rks;
     //biaya perjalanan
     $biayafee = 0;
     if (Input::get('transport') == 'no') {
         $oss->harga += $biaya_rks;
     } else {
         $shopl = new Shoplist();
         $shopl->kode = Input::get('kode_sl_trans');
         $shopl->deskripsi = Input::get('deskripsi_sl_trans');
         $shopl->satuan = Input::get('satuan_sl_trans');
         $shopl->harga = Input::get('harga_sl_trans');
         $shopl->type = 'transport';
         $shopl->save();
         $ss = new OSShop();
         $ss->oss_id = $oss->id;
         $ss->shoplist_id = $shopl->id;
         $ss->save();
         if ($shopl->harga <= 500000) {
             $biayafee = 15 / 100 * $shopl->harga;
         } else {
             $biayafee = 10 / 100 * $shopl->harga;
         }
         $oss->harga += $biaya_rks + $biayafee + $shopl->harga;
     }
     $oss->save();
     //no OSS
     $day = Carbon::parse($oss->tanggal);
     $year = $day->year;
     $noss = '';
     $romans = array(0 => '', 1 => 'I', 2 => 'II', 3 => 'III', 4 => 'IV', 5 => 'V', 6 => 'VI', 7 => 'VII', 8 => 'VIII', 9 => 'IX', 10 => 'X', 11 => 'XI', 12 => 'XII');
     if (Auth::user()->mitra == 1) {
         $noss = $oss->id . '/KISEL-TLI/' . $romans[$day->month] . '/' . $year;
     } else {
         $noss = $oss->id . '/PRIMATAMA-LWK/' . $romans[$day->month] . '/' . $year;
     }
     $oss->no_oss = $noss;
     $oss->save();
     Session::flash('success', 'Data telah dibuat.');
     return Redirect::to('/' . Auth::user()->role . '/oss/spj');
 }