Advertisement
Guest User

Untitled

a guest
Jan 21st, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 14.51 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Http\Controllers\OperationActivities;
  4. use App\command_area;
  5. use Illuminate\Support\Facades\Auth;
  6. use App\Http\Controllers\CommonController;
  7. use Illuminate\Http\Request;
  8. use Illuminate\Support\Facades\Input;
  9. use App\Http\Controllers\Controller;
  10.  
  11. use App\OperationJatka;
  12. use App\ship;
  13. use DB;
  14. use App\album;
  15. use Yajra\Datatables\Facades\Datatables;
  16. use DateTime;
  17.  
  18.  
  19. class OperationJatkaController extends Controller
  20. {
  21.     public function __construct()
  22.     {
  23.         $this->middleware('auth');
  24.     }
  25.     public function index()
  26.     {
  27.         /*$operationJatkas = OperationJatka::orderBy('id', 'desc')
  28.             ->where('visible', 1)
  29.             ->get();*/
  30.         $ship_dropdown = ship::select('id', 'ship_name')
  31.             ->where('commissioned', 1)
  32.             ->where('office_type', 'Ship')
  33.             ->get();
  34.         $is_year_view = 'no';
  35.         $f_year = '-'; $t_year='-';
  36.         return view('OperationActivities.operationJatka.index', compact('operationJatkas', 'ship_dropdown', 'is_year_view', 'f_year', 't_year'));
  37.     }
  38.  
  39.     public function anyData(Request $request)
  40.     {
  41.      $operationJatkas = Datatables::of(OperationJatka::with('getShipName', 'getCommandAreaName')->where('visible', 1))
  42.             ->addColumn('action', function ($row) {
  43.             $album = album::where('type', 'jatka')->where('type_id', $row->id)->first();
  44.                 if($album && \Illuminate\Support\Facades\Auth::User()->user_type == 'admin')
  45.                  return '<a href="/operationJatka/'.$row->id.'" class="btn btn-edit btn-xs" style="margin-Bottom:5px;"><i class="fa fa-eye"></i> View </a>
  46.                       <a href="/operationJatka/'.$row->id.'/edit" class="btn btn-edit btn-xs"><i class="fa fa-edit"></i> Edit </a>
  47.                       <button onclick="confirmDelete(this);" type="button" class="btn btn-danger"><i class="fa fa-trash" aria-hidden="true"></i> Delete</button>
  48.                        <a href="imageGallery/' .$album->id . '"><button class="btn btn-edit"><i class="fa fa-image"></i>View Gallery</button></a>';
  49.  
  50.                 if($album && \Illuminate\Support\Facades\Auth::User()->user_type != 'admin')
  51.                  return '<a href="/operationJatka/'.$row->id.'" class="btn btn-edit btn-xs" style="margin-Bottom:5px;"><i class="fa fa-eye"></i> View </a>
  52.                        <a href="imageGallery/' .$album->id . '"><button class="btn btn-edit"><i class="fa fa-image"></i>View Gallery</button></a>';    
  53.  
  54.                 if(\Illuminate\Support\Facades\Auth::User()->user_type == 'admin')
  55.                 return '<a href="/operationJatka/'.$row->id.'" class="btn btn-edit btn-xs" style="margin-Bottom:5px;"><i class="fa fa-eye"></i> View </a>
  56.                       <a href="/operationJatka/'.$row->id.'/edit" class="btn btn-edit btn-xs"><i class="fa fa-edit"></i> Edit </a>
  57.                       <button onclick="confirmDelete(this);" type="button" class="btn btn-danger"><i class="fa fa-trash" aria-hidden="true"></i> Delete</button>';
  58.                
  59.                 elseif(\Illuminate\Support\Facades\Auth::User()->user_type != 'admin')
  60.                    return '<a href="/operationJatka/'.$row->id.'" class="btn btn-edit btn-xs" style="margin-Bottom:5px;"><i class="fa fa-eye"></i> View </a>';
  61.                  
  62.  
  63.             })
  64.             ->addColumn('ship_name', function($m){
  65.                 return $m->ship_id ? $m->getShipName->ship_name : '';
  66.             })
  67.             ->addColumn('command_area', function($m){
  68.                 return $m->command_area_id ? $m->getCommandAreaName->command_area_short_name : '';
  69.             })
  70.             ->editColumn('from_date', function($m){
  71.                 return $m->from_date ? date_format(new DateTime($m->from_date), "d M Y") : '';
  72.             })
  73.             ->editColumn('to_date', function($m){
  74.                 return $m->to_date ? date_format(new DateTime($m->to_date), "d M Y") : '';
  75.             });
  76.  
  77.             return $operationJatkas->addIndexColumn()
  78.                                    ->filter(function ($query) use ($request) {
  79.             if ($request->has('from_date')) {
  80.                 $query->whereDate('from_date', '>=', date('Y-m-d', strtotime($request->from_date)) );
  81.             }
  82.             if ($request->has('to_date')) {
  83.                 $query->whereDate('to_date', '<=', date('Y-m-d', strtotime($request->to_date)) );
  84.             }
  85.             if ($request->has('ship_id')) {
  86.                 $query->where('ship_id', '=', $request->get('ship_id'));
  87.             }
  88.             if ($request->has('from_year')) {
  89.                 $query->select(DB::raw('YEAR(from_date) year') )
  90.                 ->groupBy('year')
  91.                 ->whereYear('from_date', '>='  , $request->get('from_year')  )
  92.                 ->selectRaw('count(DISTINCT ship_id) as total_ship_id, sum(duration) as duration, sum(number_of_boat) as number_of_boat, sum(number_of_fmen_or_crew) as number_of_fmen_or_crew, sum(price_of_boat) as price_of_boat, sum(price_of_jatka) as price_of_jatka, sum(price_of_other_product) as price_of_other_product, sum(total_price) as total_price ');;
  93.             }
  94.             if ($request->has('to_year')) {
  95.                 $query->select(DB::raw('YEAR(to_date) year') )
  96.                 ->groupBy('year')
  97.                 ->whereYear('to_date', '<='  , $request->get('to_year')  )
  98.                 ->selectRaw('count(DISTINCT ship_id) as total_ship_id, sum(duration) as duration, sum(number_of_boat) as number_of_boat, sum(number_of_fmen_or_crew) as number_of_fmen_or_crew, sum(price_of_boat) as price_of_boat, sum(price_of_jatka) as price_of_jatka, sum(price_of_other_product) as price_of_other_product, sum(total_price) as total_price' );
  99.             }
  100.  
  101.         }, true)
  102.         ->make(true);
  103.     }
  104.  
  105.  
  106.  
  107. /*    public function search(Request $request){
  108.         $q = OperationJatka::query();
  109.         $q->where('visible', 1);
  110.         $from_year = $request->input('from_year');
  111.         $to_year = $request->input('to_year');
  112.  
  113.         $is_year_view = 'no';
  114.         if(!empty($from_year) || !empty($to_year) ){
  115.             $is_year_view = 'yes';
  116.         }
  117.          $f_year = '-';
  118.          $t_year='-';
  119.         if(!empty($from_year)){
  120.             $f_year = $from_year;
  121.         }
  122.         if(!empty($to_year)){
  123.             $t_year = $to_year;
  124.         }
  125.  
  126.         if(Input::has('from_year')){
  127.             $q->select(DB::raw('YEAR(from_date) year') )
  128.                 ->groupBy('year')
  129.                 ->whereYear('from_date', '>='  , $request->from_year  )
  130.                 //->whereYear('from_date', '<=' , $request->to_year  )
  131.                 ->selectRaw('count(DISTINCT ship_id) as total_ship_id, sum(duration) as duration, sum(number_of_boat) as number_of_boat, sum(number_of_fmen_or_crew) as number_of_fmen_or_crew, sum(price_of_boat) as price_of_boat, sum(price_of_jatka) as price_of_jatka, sum(price_of_other_product) as price_of_other_product, sum(total_price) as total_price ');
  132.  
  133.         }
  134.  
  135.         if(Input::has('to_year')){
  136.             $q->select(DB::raw('YEAR(to_date) year') )
  137.                 ->groupBy('year')
  138.                 //->whereYear('to_date', '>=' , $request->from_year  )
  139.                 ->whereYear('to_date',  '<=' , $request->to_year  )
  140.                 ->selectRaw('count(DISTINCT ship_id) as total_ship_id, sum(duration) as duration, sum(number_of_boat) as number_of_boat, sum(number_of_fmen_or_crew) as number_of_fmen_or_crew, sum(price_of_boat) as price_of_boat, sum(price_of_jatka) as price_of_jatka, sum(price_of_other_product) as price_of_other_product, sum(total_price) as total_price ');
  141.  
  142.         }
  143.  
  144.         if(Input::has('from_date')){
  145.             $q->whereDate('from_date', '>=', $request->from_date);
  146.         }
  147.         if(Input::has('to_date')){
  148.             $q->whereDate('to_date', '<=', $request->to_date);
  149.         }
  150.  
  151.         if(Input::has('ship_id')){
  152.             $q->where('ship_id', '=', $request->ship_id);
  153.         }
  154.  
  155.         // $q->groupBy('price_of_boat');
  156.         $operationJatkas = $q->where('visible', 1)->get();
  157.         $ship_dropdown = ship::select('id', 'ship_name')
  158.             ->where('visible', 1)
  159.             ->where('commissioned', 1)
  160.             ->where('office_type', 'Ship')
  161.             ->get();
  162.         return view('OperationActivities.operationJatka.index', compact('operationJatkas', 'ship_dropdown', 'from_year', 'to_year', 'is_year_view', 'f_year', 't_year'));
  163.  
  164.     }*/
  165.  
  166.     public function create()
  167.     {
  168.         if(Auth::User()->user_type != 'admin'){
  169.             return redirect()->back();
  170.         }
  171.         $ship_dropdown = ship::orderBy('ship_name', 'asc')
  172.             ->where('commissioned', 1)
  173.             ->where('visible', 1)
  174.             ->where('office_type', 'Ship')
  175.             ->get();
  176.         $command_areas = command_area::all();
  177.         $ship_id = '';
  178.         if (isset($_GET['ship_id'])) {
  179.             $ship_id = $_GET['ship_id'];
  180.         }
  181.         //dd($ship_id);
  182.         return view('OperationActivities.operationJatka.create', compact('ship_dropdown', 'command_areas', 'ship_id'));
  183.     }
  184.  
  185.  
  186.     public function store(Request $request)
  187.     {
  188.         if(Auth::User()->user_type != 'admin'){
  189.             return redirect()->back();
  190.         }
  191.         $OperationJatka = OperationJatka::create($request->all());
  192.  
  193.         if(Input::has('from_date')){
  194.             $OperationJatka->from_date = date('Y-m-d', strtotime($request->from_date));
  195.         }
  196.         if(Input::has('to_date')){
  197.             $OperationJatka->to_date = date('Y-m-d', strtotime($request->to_date));
  198.         }
  199.         if(Input::has('number_of_boat')){
  200.             $OperationJatka->number_of_boat = str_replace(',', '',$request->number_of_boat);
  201.         }
  202.         if(Input::has('command_area_id')){
  203.             $OperationJatka->command_area_id = $request->command_area_id;
  204.         }
  205.         if(Input::has('number_of_fmen_or_crew')){
  206.             $OperationJatka->number_of_fmen_or_crew = str_replace(',', '',$request->number_of_fmen_or_crew);
  207.         }
  208.         if(Input::has('amount_of_jatka')){
  209.             $OperationJatka->amount_of_jatka = str_replace(',', '',$request->amount_of_jatka);
  210.         }
  211.         if(Input::has('price_of_boat')){
  212.             $OperationJatka->price_of_boat = str_replace(',', '',$request->price_of_boat);
  213.         }
  214.         if(Input::has('price_of_jatka')){
  215.             $OperationJatka->price_of_jatka = str_replace(',', '',$request->price_of_jatka);
  216.         }
  217.         if(Input::has('duration')){
  218.             $OperationJatka->duration = $request->duration;
  219.         }
  220.         if(Input::has('price_of_other_product')){
  221.             $OperationJatka->price_of_other_product = str_replace(',', '',$request->price_of_other_product);
  222.         }
  223.         if(Input::has('deployment_area')){
  224.             $OperationJatka->deployment_area = $request->deployment_area;
  225.         }
  226.         if(Input::has('total_price')){
  227.             $OperationJatka->total_price = str_replace(',', '',$request->total_price);
  228.         }
  229.         $OperationJatka->save();
  230.         if(isset($request->img)){
  231.             CommonController::createActivityAlbum('jatka', $OperationJatka->id, $request->file('img'), $OperationJatka->from_date, NULL);
  232.         }
  233.         session()->flash('success', 'Successfully Submitted.');
  234.  
  235.         return redirect('operationJatka');
  236.     }
  237.  
  238.     public function show($id)
  239.     {
  240.         $operationJatka = OperationJatka::find($id);
  241.         return view('OperationActivities.operationJatka.show', compact('operationJatka'));
  242.     }
  243.  
  244.     public function edit($id)
  245.     {
  246.         if(Auth::User()->user_type != 'admin'){
  247.             return redirect()->back();
  248.         }
  249.         $operationJatka = OperationJatka::find($id);
  250.         $ship_dropdown = ship::orderBy('ship_name', 'asc')
  251.             ->where('commissioned', 1)
  252.             ->where('visible', 1)
  253.             ->where('office_type', 'Ship')
  254.             ->get();
  255.         $command_areas = command_area::all();
  256.         return view('OperationActivities.operationJatka.edit', compact('operationJatka', 'ship_dropdown', 'command_areas'));
  257.     }
  258.  
  259.     public function update(Request $request, $id)
  260.     {
  261.         if(Auth::User()->user_type != 'admin'){
  262.             return redirect()->back();
  263.         }
  264.         $OperationJatka = OperationJatka::find($id);
  265.         if(Input::has('from_date')){
  266.             $OperationJatka->from_date = date('Y-m-d', strtotime($request->from_date));
  267.         }
  268.         if(Input::has('to_date')){
  269.             $OperationJatka->to_date = date('Y-m-d', strtotime($request->to_date));
  270.         }
  271.         if(Input::has('number_of_boat')){
  272.             $OperationJatka->number_of_boat = str_replace(',', '', $request->number_of_boat);
  273.         }
  274.         if(Input::has('command_area_id')){
  275.             $OperationJatka->command_area_id = $request->command_area_id;
  276.         }
  277.         if(Input::has('number_of_fmen_or_crew')){
  278.             $OperationJatka->number_of_fmen_or_crew = str_replace(',', '', $request->number_of_fmen_or_crew);
  279.         }
  280.         if(Input::has('amount_of_jatka')){
  281.             $OperationJatka->amount_of_jatka = str_replace(',', '', $request->amount_of_jatka);
  282.         }
  283.         if(Input::has('price_of_boat')){
  284.             $OperationJatka->price_of_boat = str_replace(',', '', $request->price_of_boat);
  285.         }
  286.         if(Input::has('price_of_jatka')){
  287.             $OperationJatka->price_of_jatka = str_replace(',', '', $request->price_of_jatka);
  288.         }
  289.         if(Input::has('duration')){
  290.             $OperationJatka->duration = $request->duration;
  291.         }
  292.         if(Input::has('price_of_other_product')){
  293.             $OperationJatka->price_of_other_product = str_replace(',', '', $request->price_of_other_product);
  294.         }
  295.         if(Input::has('deployment_area')){
  296.             $OperationJatka->deployment_area = $request->deployment_area;
  297.         }
  298.         if(Input::has('total_price')){
  299.             $OperationJatka->total_price = str_replace(',', '', $request->total_price);
  300.         }
  301.         $OperationJatka->update($request->all());
  302.         $OperationJatka->save();
  303.         if(isset($request->img)){
  304.             CommonController::createActivityAlbum('jatka', $OperationJatka->id, $request->file('img'), $OperationJatka->from_date, NULL);
  305.         }
  306.         session()->flash('success', 'Successfully Updated.');
  307.         return redirect('operationJatka');
  308.     }
  309.  
  310.  
  311.     public function destroy($id)
  312.     {
  313.         if(Auth::User()->user_type != 'admin'){
  314.             return redirect()->back();
  315.         }
  316.         $OperationJatka = OperationJatka::find($id);
  317.         $OperationJatka->visible = 0;
  318.         $OperationJatka->save();
  319.         return redirect()->back();
  320.     }
  321. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement