Exemple #1
0
 public function post_savePayment()
 {
     Log::write('info', Request::ip() . ' User : '******' Event: Save Setoran', true);
     $jsondata = Input::json();
     //lihat KS
     $tabungan_pengemudi = 0;
     $ks_pengemudi = 0;
     if ((int) $jsondata->ks > 0) {
         $tabungan_pengemudi = (int) $jsondata->ks;
     } else {
         $ks_pengemudi = abs((int) $jsondata->ks);
     }
     $setoran = array();
     $setoran['1'] = (int) $jsondata->setoran_wajib;
     $setoran['2'] = (int) $jsondata->tab_sp;
     $setoran['3'] = (int) $jsondata->denda;
     $setoran['4'] = (int) $jsondata->pot;
     $setoran['5'] = (int) $jsondata->tag_spart;
     $setoran['6'] = (int) $jsondata->tag_ks;
     $setoran['7'] = (int) $jsondata->biaya_tc;
     $setoran['8'] = (int) $jsondata->iuran_laka;
     $setoran['9'] = (int) $jsondata->tag_cicilan_dp;
     $setoran['10'] = (int) $jsondata->tag_hut_lama;
     $setoran['11'] = (int) $ks_pengemudi;
     $setoran['12'] = (int) $jsondata->tag_other;
     $setoran['13'] = (int) $jsondata->tag_dp_spart;
     $setoran['20'] = (int) $jsondata->setoran_cash;
     $setoran['21'] = (int) $tabungan_pengemudi;
     try {
         foreach ($setoran as $key => $value) {
             $payment = Checkinfinancial::create(array('checkin_id' => $jsondata->checkin_id, 'financial_type_id' => $key, 'amount' => $value));
         }
         $checkin = Checkin::find($jsondata->checkin_id);
         /*
         /* membuat super block berdasarkan parameter ini
         /* 1. KS Pengemudi Melebihi atau sama dengan 500.000,- dalam bulan berjalan
         /* 2. Belum di devinisikan ( besar akumulasi batas KS ) 
         */
         $finandriver = DB::table('financial_report_monthly_driver_status')->where('month', '=', date('n', strtotime($checkin->operasi_time)))->where('year', '=', date('Y', strtotime($checkin->operasi_time)))->where('driver_id', '=', $checkin->driver_id)->where('operasi_status_id', '=', 1)->order_by('id', 'desc')->first();
         if ($setoran['11'] > 0) {
             Blocked::create(array('driver_id' => $checkin->driver_id, 'fleet_id' => $checkin->fleet_id, 'std_bap_id' => 4, 'checkin_id' => $checkin->id, 'date' => date('Y-m-d H:i:s', Myfungsi::sysdate())));
             $block = Driver::find($checkin->driver_id);
             $block->fg_blocked = 1;
             /*super block melebihi ks 500000*/
             if ($finandriver) {
                 if ($finandriver->selisi_ks < -500000) {
                     //$block->fg_super_blocked = 1;
                 }
             }
             $block->save();
         }
         //update status checkin
         //informasi siapa yang menerima setoran dan waktu setoran
         $checkin->checkin_step_id = 3;
         $checkin->finance_check_user_id = Auth::user()->id;
         $checkin->finance_time = date('Y-m-d H:i:s', Myfungsi::sysdate());
         $checkin->save();
         $pothutanglama = Driverfinancial::where_driver_id($checkin->driver_id)->where_financial_type_id(18)->first();
         if ($pothutanglama) {
             $pothutanglama->amount = $pothutanglama->amount - $jsondata->tag_hut_lama;
         }
         $tabunganpengemudi = Driverfinancial::where_driver_id($checkin->driver_id)->where_financial_type_id(21)->first();
         if ($tabunganpengemudi) {
             $tabunganpengemudi->amount = $tabunganpengemudi->amount + $tabungan_pengemudi;
         } else {
             Driverfinancial::create(array('driver_id' => $checkin->driver_id, 'financial_type_id' => 21, 'amount' => $tabungan_pengemudi));
         }
         $ks = Kewajiban::where_fleet_id($checkin->fleet_id)->where_driver_id($checkin->driver_id)->where_financial_type_id(6)->first();
         if ($ks) {
             $ks->total_amount = $ks->total_amount + $setoran['11'] - $setoran['6'];
         } else {
             Kewajiban::create(array('fleet_id' => $checkin->fleet_id, 'driver_id' => $checkin->driver_id, 'financial_type_id' => 6, 'amount' => 0, 'total_amount' => $setoran['11']));
         }
         $setor = Fleet::find($checkin->fleet_id);
         $setor->fg_setor = 0;
         $setor->save();
         /*
         if((int)$jsondata->denda > 10000)
         {
           Blocked::create(array(
                               'driver_id'=>$checkin->driver_id, 
                               'fleet_id' => $checkin->fleet_id , 
                               'blocked_status_id' => 6,
                               'checkin_id' => $checkin->id,  
                               'date'=> date('Y-m-d H:i:s') ));
         
           $block = Driver::find($checkin->driver_id);
           $block->fg_blocked = 1;
           $block->save();
         }
         */
         return json_encode(array('id' => $jsondata->checkin_id, 'msg' => 'Setoran berhasil di simpan'));
     } catch (Exception $e) {
         return json_encode(array('id' => $jsondata->checkin_id, 'msg' => 'Setoran Sudah pernah di input'));
     }
 }