Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Http\Controllers\OperationActivities;
- 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\AntiSmugling;
- use App\ship;
- use App\AntiSmuglingCell;
- use App\country;
- use App\album;
- use Yajra\Datatables\Facades\Datatables;
- use DateTime;
- class AntiSmuglingController extends Controller
- {
- public function __construct()
- {
- $this->middleware('auth');
- }
- public function index()
- {
- $antiSmuglings = AntiSmugling::where('visible', 1)
- ->orderBy('id', 'desc')
- ->get();
- $ship_cell_dropdown = AntiSmugling::groupBy('ship_cell')->orderBy('ship_cell', 'asc')->get();
- $countrys = country::orderBy('country_name', 'asc')->get();
- return view('OperationActivities.antiSmugling.index', compact('antiSmuglings', 'ship_cell_dropdown', 'countrys'));
- }
- public function anyData(Request $request)
- {
- $antiSmuglings = Datatables::of(AntiSmugling::with('getCountryInfoRow')
- ->where('visible', 1)
- ->orderBy('id', 'desc'))
- ->addColumn('action', function ($row) {
- $album = album::where('type', 'smuggling')->where('type_id', $row->id)->first();
- if($album && \Illuminate\Support\Facades\Auth::User()->user_type == 'admin')
- return '<a href="/antiSmugling/'.$row->id.'" class="btn btn-edit btn-xs" style="margin-Bottom:5px;"><i class="fa fa-eye"></i> View </a>
- <a href="/antiSmugling/'.$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="/antiSmugling/'.$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="/antiSmugling/'.$row->id.'" class="btn btn-edit btn-xs" style="margin-Bottom:5px;"><i class="fa fa-eye"></i> View </a>
- <a href="/antiSmugling/'.$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="/antiSmugling/'.$row->id.'" class="btn btn-edit btn-xs" style="margin-Bottom:5px;"><i class="fa fa-eye"></i> View </a>';
- })
- ->addColumn('country', function($m){
- return $m->country ? $m->getCountryInfoRow->country_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") : '';
- })
- ->editColumn('date', function($m){
- return $m->date ? date_format(new DateTime($m->date), "d M Y") : '';
- });
- return $antiSmuglings->addIndexColumn()
- ->filter(function ($query) use ($request) {
- if ($request->has('ship_cell')) {
- $query->where('ship_cell', 'like', "%{$request->get('ship_cell')}%");
- }
- if ($request->has('operation_name')) {
- $query->where('operation_name', 'like', "%{$request->get('operation_name')}%");
- }
- if ($request->has('country')) {
- $query->where('country', '=', $request->get('country'));
- }
- 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('date')) {
- $query->whereDate('date', '=', date('Y-m-d', strtotime($request->date)) );
- }
- }, true)
- ->make(true);
- }
- public function search(Request $request){
- $q = AntiSmugling::query();
- $q->where('visible', 1);
- if(Input::has('ship_cell')){
- $q->where('ship_cell', 'LIKE', '%' . Input::get('ship_cell') . '%');
- }
- if(Input::has('operation_name')){
- $q->where('operation_name', 'LIKE', '%' . Input::get('operation_name') . '%');
- }
- if(Input::has('from_date')){
- $q->whereDate('from_date', '>=', $request->from_date);
- //$q->whereDate('to_date', '>=', $request->from_date);
- }
- if(Input::has('to_date')){
- //$q->whereDate('from_date', '<=', $request->to_date);
- $q->whereDate('to_date', '<=', $request->to_date);
- }
- if(Input::has('date')){
- //$q->whereDate('from_date', '<=', $request->to_date);
- $q->whereDate('date', '=', $request->date);
- }
- if(Input::has('country')){
- //$q->whereDate('from_date', '<=', $request->to_date);
- $q->where('country', '=', $request->country);
- }
- $antiSmuglings = $q->get();
- $ship_cell_dropdown = AntiSmugling::groupBy('ship_cell')->orderBy('ship_cell', 'asc')->get();
- $countrys = country::orderBy('country_name', 'asc')->get();
- return view('OperationActivities.antiSmugling.index', compact('antiSmuglings', 'ship_cell_dropdown', 'countrys'));
- }
- public function create()
- {
- if(Auth::User()->user_type != 'admin'){
- return redirect()->back();
- }
- $ship_dropdown = ship::orderBy('ship_name', 'asc')
- ->where('commissioned', 1)
- ->where('office_type', 'Ship')
- //->where('is_active', 1)
- ->where('visible', 1)
- ->get();
- $countrys = country::all();
- $cell_dropdown = AntiSmuglingCell::all();
- $ship_id = '';
- if (isset($_GET['ship_id'])) {
- $ship_id = $_GET['ship_id'];
- }
- return view('OperationActivities.antiSmugling.create', compact('ship_dropdown', 'cell_dropdown', 'countrys', 'ship_id'));
- }
- public function store(Request $request)
- {
- if(Auth::User()->user_type != 'admin'){
- return redirect()->back();
- }
- $response= AntiSmugling::create($request->all());
- if(Input::has('from_date')){
- $response->from_date = date('Y-m-d', strtotime($request->from_date));
- }
- if(Input::has('to_date')){
- $response->to_date = date('Y-m-d', strtotime($request->to_date));
- }
- if(Input::has('date')){
- $response->date = date('Y-m-d', strtotime($request->date));
- }
- if(Input::has('duration')){
- $response->duration = $request->duration;
- }
- if(Input::has('number_of_pirates')){
- $response->number_of_pirates = str_replace(',', '', $request->number_of_pirates);
- }
- if(Input::has('number_of_boats')){
- $response->number_of_boats = str_replace(',', '', $request->number_of_boats);
- }
- if(Input::has('number_of_smuggler')){
- $response->number_of_smuggler = str_replace(',', '', $request->number_of_smuggler);
- }
- if(Input::has('quantity_of_product')){
- $response->quantity_of_product = str_replace(',', '', $request->quantity_of_product);
- }
- if(Input::has('estimated_value_product')){
- $response->estimated_value_product = str_replace(',', '', $request->estimated_value_product);
- }
- if(Input::has('name_of_other_product')){
- $response->name_of_other_product = $request->name_of_other_product;
- }
- $response->save();
- if(isset($request->img)){
- CommonController::createActivityAlbum('smuggling', $response->id, $request->file('img'), $response->from_date, NULL);
- }
- session()->flash('success', 'Successfully Submitted.');
- return redirect('antiSmugling');
- }
- public function show($id)
- {
- $antiSmugling = AntiSmugling::find($id);
- // $ship_dropdown = ship::select('id', 'ship_name')->where('commissioned', 1)->get();
- // $cell_dropdown = AntiSmuglingCell::all();
- // $countrys = country::all();
- return view('OperationActivities.antiSmugling.show', compact('antiSmugling'));
- }
- public function edit($id)
- {
- if(Auth::User()->user_type != 'admin'){
- return redirect()->back();
- }
- $antiSmugling = AntiSmugling::find($id);
- $ship_dropdown = ship::orderBy('ship_name', 'asc')
- ->where('commissioned', 1)
- ->where('office_type', 'Ship')
- //->where('is_active', 1)
- ->where('visible', 1)
- ->get();
- $cell_dropdown = AntiSmuglingCell::all();
- $countrys = country::all();
- return view('OperationActivities.antiSmugling.edit', compact('antiSmugling', 'ship_dropdown', 'cell_dropdown', 'countrys'));
- }
- public function update(Request $request, $id)
- {
- if(Auth::User()->user_type != 'admin'){
- return redirect()->back();
- }
- $response = AntiSmugling::find($id);
- if(Input::has('from_date')){
- $response->from_date = date('Y-m-d', strtotime($request->from_date));
- }
- if(Input::has('to_date')){
- $response->to_date = date('Y-m-d', strtotime($request->to_date));
- }
- if(Input::has('date')){
- $response->date = date('Y-m-d', strtotime($request->date));
- }
- if(Input::has('duration')){
- $response->duration = $request->duration;
- }
- if(Input::has('number_of_smuggler')){
- $response->number_of_smuggler = str_replace(',', '', $request->number_of_smuggler);
- }
- if(Input::has('number_of_pirates')){
- $response->number_of_pirates = str_replace(',', '', $request->number_of_pirates);
- }
- if(Input::has('number_of_boats')){
- $response->number_of_boats = str_replace(',', '', $request->number_of_boats);
- }
- if(Input::has('quantity_of_product')){
- $response->quantity_of_product = str_replace(',', '', $request->quantity_of_product);
- }
- if(Input::has('estimated_value_product')){
- $response->estimated_value_product = str_replace(',', '', $request->estimated_value_product);
- }
- if(Input::has('name_of_other_product')){
- $response->name_of_other_product = $request->name_of_other_product;
- }
- $response->update($request->all());
- $response->save();
- if(isset($request->img)){
- CommonController::createActivityAlbum('smuggling', $response->id, $request->file('img'), $response->from_date, NULL);
- }
- session()->flash('success', 'Successfully Updated.');
- return redirect('antiSmugling');
- }
- public function destroy($id)
- {
- if(Auth::User()->user_type != 'admin'){
- return redirect()->back();
- }
- $response = AntiSmugling::find($id);
- $response ->visible = 0;
- $response ->save();
- return redirect()->back();
- }
- public function getShipCell(Request $request)
- {
- $value = $request->input('value');
- if($value == 'ship')
- {
- $getShip = ship::orderBy('ship_name', 'asc')
- ->where('commissioned', 1)
- ->where('office_type', 'Ship')
- ->get();
- echo '<option value="">---Please Select---</option>';
- foreach ( $getShip as $dropdown ):
- $val = $dropdown->ship_name;
- $name = $dropdown->ship_name;
- echo '<option value="' . $val . '">' . $name . '</option>';
- endforeach;
- }
- else if($value == 'cell')
- {
- $getCell = AntiSmuglingCell::all();
- echo '<option value="">---Please Select---</option>';
- foreach ( $getCell as $dropdown ):
- $val = $dropdown->name;
- $name = $dropdown->name;
- echo '<option value="' . $val . '">' . $name . '</option>';
- endforeach;
- }
- else {
- echo '<option value = "">No data found</option>';
- }
- echo '</select>';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement