Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Http\Controllers\OperationActivities;
- use App\command_area;
- use Illuminate\Support\Facades\Auth;
- use App\Http\Controllers\CommonController;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\Input;
- use App\Http\Controllers\Controller;
- use App\OperationJatka;
- use App\ship;
- use DB;
- use App\album;
- use Yajra\Datatables\Facades\Datatables;
- use DateTime;
- class OperationJatkaController extends Controller
- {
- public function __construct()
- {
- $this->middleware('auth');
- }
- public function index()
- {
- /*$operationJatkas = OperationJatka::orderBy('id', 'desc')
- ->where('visible', 1)
- ->get();*/
- $ship_dropdown = ship::select('id', 'ship_name')
- ->where('commissioned', 1)
- ->where('office_type', 'Ship')
- ->get();
- $is_year_view = 'no';
- $f_year = '-'; $t_year='-';
- return view('OperationActivities.operationJatka.index', compact('operationJatkas', 'ship_dropdown', 'is_year_view', 'f_year', 't_year'));
- }
- public function anyData(Request $request)
- {
- $operationJatkas = Datatables::of(OperationJatka::with('getShipName', 'getCommandAreaName')->where('visible', 1))
- ->addColumn('action', function ($row) {
- $album = album::where('type', 'jatka')->where('type_id', $row->id)->first();
- if($album && \Illuminate\Support\Facades\Auth::User()->user_type == 'admin')
- return '<a href="/operationJatka/'.$row->id.'" class="btn btn-edit btn-xs" style="margin-Bottom:5px;"><i class="fa fa-eye"></i> View </a>
- <a href="/operationJatka/'.$row->id.'/edit" class="btn btn-edit btn-xs"><i class="fa fa-edit"></i> Edit </a>
- <button onclick="confirmDelete(this);" type="button" class="btn btn-danger"><i class="fa fa-trash" aria-hidden="true"></i> Delete</button>
- <a href="imageGallery/' .$album->id . '"><button class="btn btn-edit"><i class="fa fa-image"></i>View Gallery</button></a>';
- if($album && \Illuminate\Support\Facades\Auth::User()->user_type != 'admin')
- return '<a href="/operationJatka/'.$row->id.'" class="btn btn-edit btn-xs" style="margin-Bottom:5px;"><i class="fa fa-eye"></i> View </a>
- <a href="imageGallery/' .$album->id . '"><button class="btn btn-edit"><i class="fa fa-image"></i>View Gallery</button></a>';
- if(\Illuminate\Support\Facades\Auth::User()->user_type == 'admin')
- return '<a href="/operationJatka/'.$row->id.'" class="btn btn-edit btn-xs" style="margin-Bottom:5px;"><i class="fa fa-eye"></i> View </a>
- <a href="/operationJatka/'.$row->id.'/edit" class="btn btn-edit btn-xs"><i class="fa fa-edit"></i> Edit </a>
- <button onclick="confirmDelete(this);" type="button" class="btn btn-danger"><i class="fa fa-trash" aria-hidden="true"></i> Delete</button>';
- elseif(\Illuminate\Support\Facades\Auth::User()->user_type != 'admin')
- return '<a href="/operationJatka/'.$row->id.'" class="btn btn-edit btn-xs" style="margin-Bottom:5px;"><i class="fa fa-eye"></i> View </a>';
- })
- ->addColumn('ship_name', function($m){
- return $m->ship_id ? $m->getShipName->ship_name : '';
- })
- ->addColumn('command_area', function($m){
- return $m->command_area_id ? $m->getCommandAreaName->command_area_short_name : '';
- })
- ->editColumn('from_date', function($m){
- return $m->from_date ? date_format(new DateTime($m->from_date), "d M Y") : '';
- })
- ->editColumn('to_date', function($m){
- return $m->to_date ? date_format(new DateTime($m->to_date), "d M Y") : '';
- });
- return $operationJatkas->addIndexColumn()
- ->filter(function ($query) use ($request) {
- if ($request->has('from_date')) {
- $query->whereDate('from_date', '>=', date('Y-m-d', strtotime($request->from_date)) );
- }
- if ($request->has('to_date')) {
- $query->whereDate('to_date', '<=', date('Y-m-d', strtotime($request->to_date)) );
- }
- if ($request->has('ship_id')) {
- $query->where('ship_id', '=', $request->get('ship_id'));
- }
- if ($request->has('from_year')) {
- $query->select(DB::raw('YEAR(from_date) year') )
- ->groupBy('year')
- ->whereYear('from_date', '>=' , $request->get('from_year') )
- ->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 ');;
- }
- if ($request->has('to_year')) {
- $query->select(DB::raw('YEAR(to_date) year') )
- ->groupBy('year')
- ->whereYear('to_date', '<=' , $request->get('to_year') )
- ->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' );
- }
- }, true)
- ->make(true);
- }
- /* public function search(Request $request){
- $q = OperationJatka::query();
- $q->where('visible', 1);
- $from_year = $request->input('from_year');
- $to_year = $request->input('to_year');
- $is_year_view = 'no';
- if(!empty($from_year) || !empty($to_year) ){
- $is_year_view = 'yes';
- }
- $f_year = '-';
- $t_year='-';
- if(!empty($from_year)){
- $f_year = $from_year;
- }
- if(!empty($to_year)){
- $t_year = $to_year;
- }
- if(Input::has('from_year')){
- $q->select(DB::raw('YEAR(from_date) year') )
- ->groupBy('year')
- ->whereYear('from_date', '>=' , $request->from_year )
- //->whereYear('from_date', '<=' , $request->to_year )
- ->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 ');
- }
- if(Input::has('to_year')){
- $q->select(DB::raw('YEAR(to_date) year') )
- ->groupBy('year')
- //->whereYear('to_date', '>=' , $request->from_year )
- ->whereYear('to_date', '<=' , $request->to_year )
- ->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 ');
- }
- if(Input::has('from_date')){
- $q->whereDate('from_date', '>=', $request->from_date);
- }
- if(Input::has('to_date')){
- $q->whereDate('to_date', '<=', $request->to_date);
- }
- if(Input::has('ship_id')){
- $q->where('ship_id', '=', $request->ship_id);
- }
- // $q->groupBy('price_of_boat');
- $operationJatkas = $q->where('visible', 1)->get();
- $ship_dropdown = ship::select('id', 'ship_name')
- ->where('visible', 1)
- ->where('commissioned', 1)
- ->where('office_type', 'Ship')
- ->get();
- return view('OperationActivities.operationJatka.index', compact('operationJatkas', 'ship_dropdown', 'from_year', 'to_year', 'is_year_view', 'f_year', 't_year'));
- }*/
- public function create()
- {
- if(Auth::User()->user_type != 'admin'){
- return redirect()->back();
- }
- $ship_dropdown = ship::orderBy('ship_name', 'asc')
- ->where('commissioned', 1)
- ->where('visible', 1)
- ->where('office_type', 'Ship')
- ->get();
- $command_areas = command_area::all();
- $ship_id = '';
- if (isset($_GET['ship_id'])) {
- $ship_id = $_GET['ship_id'];
- }
- //dd($ship_id);
- return view('OperationActivities.operationJatka.create', compact('ship_dropdown', 'command_areas', 'ship_id'));
- }
- public function store(Request $request)
- {
- if(Auth::User()->user_type != 'admin'){
- return redirect()->back();
- }
- $OperationJatka = OperationJatka::create($request->all());
- if(Input::has('from_date')){
- $OperationJatka->from_date = date('Y-m-d', strtotime($request->from_date));
- }
- if(Input::has('to_date')){
- $OperationJatka->to_date = date('Y-m-d', strtotime($request->to_date));
- }
- if(Input::has('number_of_boat')){
- $OperationJatka->number_of_boat = str_replace(',', '',$request->number_of_boat);
- }
- if(Input::has('command_area_id')){
- $OperationJatka->command_area_id = $request->command_area_id;
- }
- if(Input::has('number_of_fmen_or_crew')){
- $OperationJatka->number_of_fmen_or_crew = str_replace(',', '',$request->number_of_fmen_or_crew);
- }
- if(Input::has('amount_of_jatka')){
- $OperationJatka->amount_of_jatka = str_replace(',', '',$request->amount_of_jatka);
- }
- if(Input::has('price_of_boat')){
- $OperationJatka->price_of_boat = str_replace(',', '',$request->price_of_boat);
- }
- if(Input::has('price_of_jatka')){
- $OperationJatka->price_of_jatka = str_replace(',', '',$request->price_of_jatka);
- }
- if(Input::has('duration')){
- $OperationJatka->duration = $request->duration;
- }
- if(Input::has('price_of_other_product')){
- $OperationJatka->price_of_other_product = str_replace(',', '',$request->price_of_other_product);
- }
- if(Input::has('deployment_area')){
- $OperationJatka->deployment_area = $request->deployment_area;
- }
- if(Input::has('total_price')){
- $OperationJatka->total_price = str_replace(',', '',$request->total_price);
- }
- $OperationJatka->save();
- if(isset($request->img)){
- CommonController::createActivityAlbum('jatka', $OperationJatka->id, $request->file('img'), $OperationJatka->from_date, NULL);
- }
- session()->flash('success', 'Successfully Submitted.');
- return redirect('operationJatka');
- }
- public function show($id)
- {
- $operationJatka = OperationJatka::find($id);
- return view('OperationActivities.operationJatka.show', compact('operationJatka'));
- }
- public function edit($id)
- {
- if(Auth::User()->user_type != 'admin'){
- return redirect()->back();
- }
- $operationJatka = OperationJatka::find($id);
- $ship_dropdown = ship::orderBy('ship_name', 'asc')
- ->where('commissioned', 1)
- ->where('visible', 1)
- ->where('office_type', 'Ship')
- ->get();
- $command_areas = command_area::all();
- return view('OperationActivities.operationJatka.edit', compact('operationJatka', 'ship_dropdown', 'command_areas'));
- }
- public function update(Request $request, $id)
- {
- if(Auth::User()->user_type != 'admin'){
- return redirect()->back();
- }
- $OperationJatka = OperationJatka::find($id);
- if(Input::has('from_date')){
- $OperationJatka->from_date = date('Y-m-d', strtotime($request->from_date));
- }
- if(Input::has('to_date')){
- $OperationJatka->to_date = date('Y-m-d', strtotime($request->to_date));
- }
- if(Input::has('number_of_boat')){
- $OperationJatka->number_of_boat = str_replace(',', '', $request->number_of_boat);
- }
- if(Input::has('command_area_id')){
- $OperationJatka->command_area_id = $request->command_area_id;
- }
- if(Input::has('number_of_fmen_or_crew')){
- $OperationJatka->number_of_fmen_or_crew = str_replace(',', '', $request->number_of_fmen_or_crew);
- }
- if(Input::has('amount_of_jatka')){
- $OperationJatka->amount_of_jatka = str_replace(',', '', $request->amount_of_jatka);
- }
- if(Input::has('price_of_boat')){
- $OperationJatka->price_of_boat = str_replace(',', '', $request->price_of_boat);
- }
- if(Input::has('price_of_jatka')){
- $OperationJatka->price_of_jatka = str_replace(',', '', $request->price_of_jatka);
- }
- if(Input::has('duration')){
- $OperationJatka->duration = $request->duration;
- }
- if(Input::has('price_of_other_product')){
- $OperationJatka->price_of_other_product = str_replace(',', '', $request->price_of_other_product);
- }
- if(Input::has('deployment_area')){
- $OperationJatka->deployment_area = $request->deployment_area;
- }
- if(Input::has('total_price')){
- $OperationJatka->total_price = str_replace(',', '', $request->total_price);
- }
- $OperationJatka->update($request->all());
- $OperationJatka->save();
- if(isset($request->img)){
- CommonController::createActivityAlbum('jatka', $OperationJatka->id, $request->file('img'), $OperationJatka->from_date, NULL);
- }
- session()->flash('success', 'Successfully Updated.');
- return redirect('operationJatka');
- }
- public function destroy($id)
- {
- if(Auth::User()->user_type != 'admin'){
- return redirect()->back();
- }
- $OperationJatka = OperationJatka::find($id);
- $OperationJatka->visible = 0;
- $OperationJatka->save();
- return redirect()->back();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement