Skip to content

Commit

Permalink
#1 booking approval process done
Browse files Browse the repository at this point in the history
booking approvement, assigning car and driver, rejection of booking is done.
  • Loading branch information
div100 committed Feb 16, 2019
1 parent 712b69c commit dd597bc
Show file tree
Hide file tree
Showing 17 changed files with 398 additions and 166 deletions.
42 changes: 42 additions & 0 deletions app/Http/Controllers/bookVehicalController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace App\Http\Controllers;
use DB;
use App\booking;
use App\bookVehical;
use Validator;
use Illuminate\Http\Request;
use illuminate\Http\QueryException;

class bookVehicalController extends Controller

{
public function index(){
$rows = DB::table('bookVehicals')->get();
return view('bookings/book vehical')->with('rows',$rows);

}
//
public function sendData(Request $request){

$destination= $request->input('destination');
$description= $request->input('description');
$pickup_time = $request->input('pickup_time');
$return_time = $request->input('return_time');
$count = $request->input('count');

try {

DB::table('bookVehicals')->insert(
['pickup_time' => $pickup_time, 'return_time' => $return_time, 'user_id' =>1,
'count'=>$count,'destination' =>$destination,'description'=>$description]
);
return "your request for car is wait for approval of admin ";
}
catch(QueryException $ex){
print($ex->getMessage());
}
}


}
47 changes: 0 additions & 47 deletions app/Http/Controllers/book_a_car.php

This file was deleted.

59 changes: 56 additions & 3 deletions app/Http/Controllers/bookingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,33 @@

use Illuminate\Http\Request;
use App\booking;
use DB;
use illuminate\Http\QueryException;
class bookingController extends Controller
{

/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$rows = DB::table('bookVehicals')->get();
$countOfRows = DB::table('bookVehicals')->count();
// return view('bookings/index')->with('rows',$rows);

$bookingsData = Booking::all();
return view('/bookings/index')->with('bookingsData',$bookingsData);
return view('/bookings/index')->with(['bookingsData'=>$bookingsData,'rows'=>$rows,'countOfRows'=>$countOfRows]);

}

public function reject(Request $request){
$insertQuery = DB::table('bookings')->insert(['pickup_time'=>$request->input('pickup_time'),
'return_time'=>$request->input('return_time'),'count'=>$request->input('count'),
'description'=>$request->input('description'),'destination'=>$request->input('destination'),'approval'=>false,'driver_id'=>null,'car_id'=>null,
'user_id'=>$request->input('user_id')]);

}
/**
* Show the form for creating a new resource.
*
Expand All @@ -36,7 +49,47 @@ public function create()
*/
public function store(Request $request)
{
//
$bookRows = DB::table('bookVehicals')->get();

$pickupt_time = $request->input('pickup_time');
$return_time = $request->input('return_time');
$count = $request->input('count');
$description = $request->input('description');
$destination = $request->input('destination');
$approval = $request->input('approval');
$driver_id = $request->input('driver_id');
$car_id = $request->input('car_id');
$user_id = $request->input('user_id');

// return $pickupt_time . " " .$return_time . " " .$count . " " .$description . " " .$destination . " " .$driver_id . " " .
// $car_id . " " .$user_id;

try{

// $insertQuery = Booking::create($request->all());
if($request->input('approval')=='false' OR $request->input('approval') === false){
$insertQuery = DB::table('bookings')->insert(['pickup_time'=>$pickupt_time,'return_time'=>$return_time,'count'=>$count,
'description'=>$description,'destination'=>$destination,'approval'=>$approval,'driver_id'=>null,'car_id'=>null,
'user_id'=>$user_id]);
return "Please select true for approval field";
}
else{
if(!($car_id)||!($driver_id) || $car_id ==null ||$driver_id ==null){return "driver ID and car ID is required";}
$insertQuery = DB::table('bookings')->insert(['pickup_time'=>$pickupt_time,'return_time'=>$return_time,'count'=>$count,
'description'=>$description,'destination'=>$destination,'approval'=>$approval,'driver_id'=>$driver_id,'car_id'=>$car_id,
'user_id'=>$user_id]);
$del = DB::table('bookVehicals')->where('pickup_time',$pickupt_time)->where('return_time',$return_time)->where('count',$count)->
where('destination',$destination)->where('description',$description)->delete();

return "Approved!" . " driver ID ".$driver_id . " and Car ID: " .$car_id;
}

}
catch(QueryException $ex){
print_r($ex->getMessage());
}


}

/**
Expand Down
11 changes: 11 additions & 0 deletions app/bookVehical.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class bookVehical extends Model
{
//
protected $fillable = ['pickup_time','return_time', 'destination','description'];
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ public function up()
{
Schema::create('bookings', function (Blueprint $table) {
$table->increments('booking_id');
$table->dateTime('start_time');
$table->dateTime('end_time');
$table->string('list_of_persons',255);
$table->dateTime('pickup_time');
$table->dateTime('return_time');
$table->tinyInteger('count');
$table->longText('description');
$table->string('destination');
$table->boolean('approval');
$table->timestamps();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ class AddForeignKeysToBookingsTable extends Migration
public function up()
{
Schema::table('bookings', function (Blueprint $table) {
$table->integer('driver_id')->unsigned();
$table->integer('driver_id')->unsigned()->nullable();
$table->foreign('driver_id')->references('driver_id')->on('drivers')->onDelete('no action');

});

Schema::table('bookings',function (Blueprint $table){
$table->integer('car_id')->unsigned();
$table->integer('car_id')->unsigned()->nullable();
$table->foreign('car_id')->references('car_id')->on('cars')->onDelete('no action');
});

Expand Down

This file was deleted.

39 changes: 39 additions & 0 deletions database/migrations/2019_02_12_050329_book_vehicals.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class BookVehicals extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
//
Schema::create('bookVehicals', function (Blueprint $table) {
$table->integer('user_id');
$table->tinyInteger('count');
$table->dateTime('pickup_time');
$table->dateTime('return_time');
$table->longText('description');
$table->string('destination',255);
$table->timestamps();
});
}


/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
Schema::dropIfExists('bookACar');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class AddNullConditionalConstraint extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('bookings', function (Blueprint $table) {
//
DB::statement("ALTER TABLE bookings ADD CONSTRAINT null_for_driverID_and_carID_booking CHECK
(approval = false or (car_id is not null and driver_id is not null))" );
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('booking', function (Blueprint $table) {
//
DB::statement("ALTER TABLE bookings DROP CONSTRAINT null_for_driverID_and_carID_booking");
});
}
}
44 changes: 35 additions & 9 deletions public/js/crud.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,38 @@ $("#insertButton, .updateBtn").click(function(){
});
//load update data and validation of insert and update form
var loc = window.location.href;
$("#carBookingForm").submit(function(e){

ApprovalBooking();
function ApprovalBooking(){
$(".pending_table").submit(function(e){
e.preventDefault();

var dataForm = ($(this).serialize());
var element =$(this);
$.ajax({
method: "post",
url: "/bookings/",
data: dataForm,
success:function(data){
if(data.indexOf('Approved')>=0){
element.fadeOut(1000);
$("#errDiv").fadeOut();$("#sucDiv").html(data); $("#sucDiv").fadeIn();
}
else{
$("#sucDiv").fadeOut(); $("#errDiv").html(data); $("#errDiv").fadeIn();
}

}
});
});
}
$("#bookACar").submit(function(e){
e.preventDefault();
var data= $(this).serialize();

$.ajax({
method: 'POST',
url: "/car booking",
url: "/book vehical",
data: data,
success: function(data){
$("#carBooking").modal('hide');
Expand All @@ -33,7 +58,8 @@ $("#carBookingForm").submit(function(e){
$("#sucDiv").fadeOut(2000);
}
});
console.log(data);

console.log(data);

});
if(loc.indexOf('driver')>=0){
Expand Down Expand Up @@ -333,15 +359,15 @@ function loadUpdatingData(urlN,inp1,inp2,inp3,inp4,inp5,inp6,inp7,inp8,inp9,inp1
$("#updateModal").modal('show');
});
}
validateCarBooking();
function validateCarBooking(){
var validator = $("#carBookingForm").validate({
validateVehicalBook();
function validateVehicalBook(){
var validator = $("#bookACar").validate({
rules:{
destination: {required:true},
pickup_time: {required:true,regex:/[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1]) (2[0-3]|[01][0-9]):[0-5][0-9]/},
return_time:{required:true,regex:/[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1]) (2[0-3]|[01][0-9]):[0-5][0-9]/},
open_drivers:{required:true},
open_cars:{required:true}
description:{required:true},

},
messages:{
pickup_time:{
Expand Down
Loading

0 comments on commit dd597bc

Please sign in to comment.