public function delete($id)
 {
     $quote = quote::find($id);
     if (!$quote->status) {
         //cek apakah detail sudah terhapus
         $dquote = dquote::where('idquote', '=', $quote->id)->delete();
         //hapus quote
         $quote->delete();
         $errors = 'Nota Quote No.' . $id . ' sudah dihapus';
     }
     $quotes = quote::where('status', '=', '0')->get();
     return view('world.dashboard.order')->with('quotes', $quotes)->withErrors($errors);
 }
 /**
  * Bootstrap any application services.
  *
  * @return void
  */
 public function boot()
 {
     date_default_timezone_set('Asia/Jakarta');
     $abouts = array();
     $news = array();
     $memo = array();
     Config::set('registered', false);
     $articles = \App\article::select('article.*', 'users.first_name', 'users.last_name')->leftJoin('users', 'article.user', '=', 'users.id')->get();
     foreach ($articles as $article) {
         switch ($article->type) {
             case 'about':
                 $abouts[] = $article;
                 break;
             case 'news':
                 $news[] = $article;
                 break;
             case 'memo':
                 $memo[] = $article;
                 break;
         }
     }
     $kota = \App\kota::all();
     foreach ($kota as $v) {
         $dkota[$v->idkota] = $v->nmkota;
     }
     $satuan = \App\satuan::all();
     foreach ($satuan as $v) {
         $dsatuan[$v->idsatuan] = $v->namasatuan;
     }
     $cabang = \App\cabang::all();
     foreach ($cabang as $v) {
         $dcabang[$v->idcabang] = $v->nama;
     }
     $dcabang = \App\Helpers::assoc_merge([0 => '--Daftar Cabang--'], $dcabang);
     //Hitung total quote yang baru
     $quotes = \App\quote::where('status', '=', '0');
     $quotesData['all'] = $quotes->limit(3)->get();
     $quotesData['count'] = $quotes->count();
     //Hitung total SJT yang belum tiba
     $sjt = \App\berangkat::where('status', '<', '3');
     $sjtData['all'] = $sjt->limit(3)->get();
     $sjtData['count'] = $sjt->count();
     //Hitung total tagihan yang belum terbayar
     $totNotification = $quotes->count() + $sjt->count();
     $notification = ['all' => $totNotification, 'quote' => $quotesData, 'sjt' => $sjtData];
     $data = array('abouts' => $abouts, 'news' => $news, 'memo' => $memo, 'kota' => $dkota, 'satuan' => $dsatuan, 'cabang' => $dcabang, 'nquotes' => $quotes, 'notification' => $notification);
     return View::share($data);
 }
 public function generateId()
 {
     $tmp = 'QTE' . Date('ymd' . '.');
     $quotes = \App\quote::select('id')->whereRaw('id like "' . $tmp . '%"')->get();
     $res = \App\quote::selectRaw('MAX(CAST(RIGHT(id,POSITION("." IN REVERSE(id))-1) AS SIGNED)) AS id')->whereRaw('id LIKE "' . $tmp . '%"')->first();
     $max = $res->id;
     if ($max) {
         if ($max < 9) {
             $max++;
             return $tmp . '0' . $max;
         } else {
             $max++;
             return $tmp . $max;
         }
     }
     return $tmp . '01';
 }