public function store()
 {
     $vs = new Versheet();
     $vs->no_invoice = Input::get('invoice');
     $vs->user_id = Input::get('supplier');
     $vs->untuk_pembayaran = Input::get('pembayaran');
     $vs->jumlah_pembayaran = Input::get('jumlah');
     $vs->trxid == Input::get('trxid');
     $vs->cost_centre = Input::get('cost_centre');
     $vs->budget_account = Input::get('budget_account');
     $vs->activity_code = Input::get('activity_code');
     $vs->user_menyetujui = Input::get('menyetujui');
     $vs->kepada_nama = Input::get('kepada_nama');
     $vs->kepada_bank = Input::get('kepada_bank');
     $vs->kepada_rekening = Input::get('kepada_rekening');
     $vs->save();
     foreach (Input::get('docs') as $doc) {
         $vd = new VersheetDocs();
         $vd->versheet_id = $vs->id;
         $vd->docs = $doc;
         $vd->save();
     }
     Session::flash('success', 'Data telah dibuat.');
     return Redirect::to('/' . Auth::user()->role . '/versheet');
 }
 public function store()
 {
     $ext = Input::file('file')->getClientOriginalExtension();
     $validator = Validator::make(array('ext' => $ext), array('ext' => 'in:pdf'));
     if ($validator->fails()) {
         Session::flash('error', 'File format tidak di dukung');
         return Redirect::to('/' . Auth::user()->role . '/perjalanandinas');
     } else {
         $pj = new PerjalananDinas();
         $pj->user_id = Input::get('nama');
         $pj->kota_tujuan = Input::get('tujuan');
         $pj->kegiatan = Input::get('kegiatan');
         $pj->tanggal_berangkat = Carbon::parse(Input::get('pergi'));
         $pj->tanggal_kembali = Carbon::parse(Input::get('kembali'));
         $pj->kendaraan = Input::get('kendaraan');
         $pj->jenis_uhpd = Input::get('jenis_uhpd');
         if (Input::get('trans_bandara') != '') {
             $pj->transport_bandara = Input::get('trans_bandara');
         }
         if (Input::get('hotel_hari') != '') {
             $pj->hari_hotel = Input::get('hotel_hari');
         }
         if (Input::get('hotel_perhari') != '') {
             $pj->biaya_hotel = Input::get('hotel_perhari');
         }
         if (Input::get('pesawat_biaya') != '') {
             $pj->biaya_pesawat = Input::get('pesawat_biaya');
         }
         if (Input::get('pesawat_kota') != '') {
             $pj->tujuan_pesawat = Input::get('pesawat_kota');
         }
         $pj->save();
         //file nodin
         Input::file('file')->move(public_path(), 'nodin-' . $pj->id . '.pdf');
         $pj->nodin = '/nodin-' . $pj->id . '.pdf';
         $pj->save();
         $listlain = Input::get('ids_lain');
         if ($listlain != '') {
             $listlain = substr($listlain, 0, -1);
             $lain = explode(",", $listlain);
             if (count($lain > 0)) {
                 for ($i = 0; $i < count($lain); $i++) {
                     $pjlain = PJLain::find($lain[$i]);
                     $pjlain->pj_id = $pj->id;
                     $pjlain->save();
                 }
             }
         }
         //create STPD
         $stpd = new STPD();
         $stpd->user_id = Input::get('nama');
         $stpd->tujuan_penugasan = Input::get('tujuan');
         $stpd->tanggal_berangkat = Carbon::parse(Input::get('pergi'));
         $stpd->tanggal_kembali = Carbon::parse(Input::get('kembali'));
         $stpd->kendaraan = Input::get('kendaraan');
         $stpd->kegiatan = Input::get('kegiatan');
         $stpd->jenis_uhpd = Input::get('jenis_uhpd');
         if (Input::get('trans_bandara') != '') {
             $stpd->trans_bandara = Input::get('trans_bandara');
         }
         $stpd->tanggal_stpd = Carbon::parse(Input::get('pergi'));
         $stpd->pd_id = $pj->id;
         $stpd->user_menugaskan = Input::get('menugaskan');
         $stpd->user_mengetahui = Input::get('mengetahui');
         $stpd->save();
         //hitung jumlah
         $harian = 0;
         if ($stpd->user->level_jabatan == 'manager') {
             if ($stpd->jenis_uhpd == 'darat') {
                 $harian = 290000;
             } elseif ($stpd->jenis_uhpd == 'udara') {
                 $harian = 420000;
             } else {
                 $harian = 230000;
             }
         } elseif ($stpd->user->level_jabatan == 'spv') {
             if ($stpd->jenis_uhpd == 'darat') {
                 $harian = 275000;
             } elseif ($stpd->jenis_uhpd == 'udara') {
                 $harian = 395000;
             } else {
                 $harian = 215000;
             }
         } elseif ($stpd->user->level_jabatan == 'staff') {
             if ($stpd->jenis_uhpd == 'darat') {
                 $harian = 260000;
             } elseif ($stpd->jenis_uhpd == 'udara') {
                 $harian = 370000;
             } else {
                 $harian = 200000;
             }
         } else {
             $harian = 0;
         }
         $berangkat = Carbon::parse(Input::get('pergi'));
         $kembali = Carbon::parse(Input::get('kembali'));
         $day = $kembali->diffInDays($berangkat) + 1;
         $jumlah = $harian * $day + $stpd->trans_bandara;
         $stpd->jumlah = $jumlah;
         $stpd->save();
         //Buat Versheet
         $vs = new Versheet();
         $vs->user_id = Input::get('nama');
         $vs->untuk_pembayaran = Input::get('kegiatan');
         $vs->jumlah_pembayaran = $stpd->jumlah;
         $vs->kepada_nama = $pj->user->nama;
         $vs->kepada_bank = $pj->user->bank;
         $vs->pd_id = $pj->id;
         $vs->kepada_rekening = $pj->user->no_rekening;
         $vs->save();
         $vd = new VersheetDocs();
         $vd->versheet_id = $vs->id;
         $vd->docs = 'FPJP';
         $vd->save();
         //Buat FPJP
         $fpjp = new FPJP();
         $fpjp->user_id = Input::get('nama');
         $fpjp->pd_id = $pj->id;
         $fpjp->tanggal = Carbon::parse(Input::get('kembali'));
         $fpjp->user_mengetahui = Input::get('mengetahui');
         $fpjp->save();
         //Biaya UHPD
         $ur = new FPJPUraian();
         $ur->uraian = 'UHPD ke ' . $pj->kota_tujuan . ' dalam rangka ' . $pj->kegiatan;
         $ur->jumlah = $pj->stpd->jumlah;
         $ur->fpjp_id = $fpjp->id;
         $ur->save();
         //Biaya Pesawat
         if ($pj->biaya_pesawat != 0) {
             $ur = new FPJPUraian();
             $ur->uraian = 'Biaya tiket';
             $ur->jumlah = $pj->biaya_pesawat;
             $ur->fpjp_id = $fpjp->id;
             $ur->save();
         }
         //Biaya Hotel
         if ($pj->biaya_hotel != 0) {
             $ur = new FPJPUraian();
             $ur->uraian = 'Biaya hotel ' . $pj->hari_hotel . ' hari x Rp ' . number_format($pj->biaya_hotel);
             $ur->jumlah = $pj->hari_hotel * $pj->biaya_hotel;
             $ur->fpjp_id = $fpjp->id;
             $ur->save();
         }
         //PJ Lain
         $lain2 = PJLain::where('pj_id', '=', $pj->id)->get();
         foreach ($lain2 as $l) {
             $ur = new FPJPUraian();
             $ur->uraian = $l->detail;
             $ur->jumlah = $l->jumlah;
             $ur->fpjp_id = $fpjp->id;
             $ur->save();
         }
         //Total Uraian
         $turai = FPJPUraian::where('fpjp_id', '=', $fpjp->id)->get();
         $jum_fpjp = 0;
         foreach ($turai as $tu) {
             $jum_fpjp += $tu->jumlah;
         }
         $fpjp->total = $jum_fpjp;
         $fpjp->save();
         $vs->jumlah_pembayaran = $fpjp->total;
         $vs->save();
         Session::flash('success', 'Data telah dibuat.');
         return Redirect::to('/' . Auth::user()->role . '/perjalanandinas');
     }
 }