Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initial from template #8

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified .editorconfig
100644 → 100755
Empty file.
44 changes: 0 additions & 44 deletions .env.example

This file was deleted.

Empty file modified .gitattributes
100644 → 100755
Empty file.
Empty file modified .gitignore
100644 → 100755
Empty file.
Empty file modified README.md
100644 → 100755
Empty file.
5 changes: 5 additions & 0 deletions app/Appointment.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,9 @@ public function services()
{
return $this->belongsToMany(Service::class);
}

public function products()
{
return $this->belongsToMany(Product::class);
}
}
Empty file modified app/Client.php
100644 → 100755
Empty file.
Empty file modified app/Console/Kernel.php
100644 → 100755
Empty file.
5 changes: 5 additions & 0 deletions app/Employee.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,9 @@ public function services()
{
return $this->belongsToMany(Service::class);
}

public function products()
{
return $this->belongsToMany(Product::class);
}
}
Empty file modified app/Exceptions/Handler.php
100644 → 100755
Empty file.
128 changes: 119 additions & 9 deletions app/Http/Controllers/Admin/AppointmentsController.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,21 @@
use App\Http\Requests\StoreAppointmentRequest;
use App\Http\Requests\UpdateAppointmentRequest;
use App\Service;
use App\Product;
use Gate;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
use Yajra\DataTables\Facades\DataTables;
use Illuminate\Support\Facades\Validator;
use DateTime;
use DateTimeZone;

class AppointmentsController extends Controller
{
public function index(Request $request)
{
if ($request->ajax()) {
$query = Appointment::with(['client', 'employee', 'services'])->select(sprintf('%s.*', (new Appointment)->table));
$query = Appointment::with(['client', 'employee', 'services', 'products'])->select(sprintf('%s.*', (new Appointment)->table));
$table = Datatables::of($query);

$table->addColumn('placeholder', ' ');
Expand Down Expand Up @@ -68,7 +72,17 @@ public function index(Request $request)
return implode(' ', $labels);
});

$table->rawColumns(['actions', 'placeholder', 'client', 'employee', 'services']);
$table->editColumn('products', function ($row) {
$labels = [];

foreach ($row->products as $product) {
$labels[] = sprintf('<span class="label label-info label-many">%s</span>', $product->name);
}

return implode(' ', $labels);
});

$table->rawColumns(['actions', 'placeholder', 'client', 'employee', 'services', 'products']);

return $table->make(true);
}
Expand All @@ -86,15 +100,65 @@ public function create()

$services = Service::all()->pluck('name', 'id');

return view('admin.appointments.create', compact('clients', 'employees', 'services'));
$products = Product::all()->pluck('name', 'id');

return view('admin.appointments.create', compact('clients', 'employees', 'services', 'products'));
}

public function store(StoreAppointmentRequest $request)
{
$appointment = Appointment::create($request->all());
$appointment->services()->sync($request->input('services', []));
if(!empty($request)){

return redirect()->route('admin.appointments.index');
$now = new DateTime('NOW', new DateTimeZone('Africa/Johannesburg'));
$date1 = new DateTime($request->start_time, new DateTimeZone('Africa/Johannesburg'));
$date2 = new DateTime($request->finish_time, new DateTimeZone('Africa/Johannesburg'));

$date1 = $date1->format('Y-m-d H:i:s');
$date2 = $date2->format('Y-m-d H:i:s');
$now = $now->format('Y-m-d H:i:s');

$validator = Validator::make($request->all(), $request->rules());

if(!$this->isDoctorBooked($request->employee_id, $now, $date1, $date2)) {

if($date1 < $now) {
$validator->errors()->add('start_time', 'Start Time Cannot be in the past!');
}

if($date1 >= $date2) {
$validator->errors()->add('start_time', 'Start time must be before the end date!');
}

$errors = $validator->errors();

if($errors->any()) {
return redirect()->back()->withInput()->withErrors($errors);
}


$appointment = Appointment::create($request->all());
$appointment->services()->sync($request->input('services', []));
$appointment->products()->sync($request->input('products', []));

return redirect()->route('admin.appointments.index');
}else {

$validator->errors()->add('start_time', 'Doctor is busy during this slot');
$errors = $validator->errors();

if($errors->any()) {
return redirect()->back()->withInput()->withErrors($errors);
}
}

} else {

$appointment = Appointment::create($request->all());
$appointment->services()->sync($request->input('services', []));
$appointment->products()->sync($request->input('products', []));

return redirect()->route('admin.appointments.index');
}
}

public function edit(Appointment $appointment)
Expand All @@ -107,15 +171,18 @@ public function edit(Appointment $appointment)

$services = Service::all()->pluck('name', 'id');

$appointment->load('client', 'employee', 'services');
$products = Product::all()->pluck('name', 'id');

return view('admin.appointments.edit', compact('clients', 'employees', 'services', 'appointment'));
$appointment->load('client', 'employee', 'services', 'products');

return view('admin.appointments.edit', compact('clients', 'employees', 'services', 'products', 'appointment'));
}

public function update(UpdateAppointmentRequest $request, Appointment $appointment)
{
$appointment->update($request->all());
$appointment->services()->sync($request->input('services', []));
$appointment->products()->sync($request->input('products', []));

return redirect()->route('admin.appointments.index');
}
Expand All @@ -124,7 +191,7 @@ public function show(Appointment $appointment)
{
abort_if(Gate::denies('appointment_show'), Response::HTTP_FORBIDDEN, '403 Forbidden');

$appointment->load('client', 'employee', 'services');
$appointment->load('client', 'employee', 'services', 'products');

return view('admin.appointments.show', compact('appointment'));
}
Expand All @@ -144,4 +211,47 @@ public function massDestroy(MassDestroyAppointmentRequest $request)

return response(null, Response::HTTP_NO_CONTENT);
}

public function isDoctorBooked($employeeId, $now, $startTime, $finishTime)
{
$appointments = Appointment::where('employee_id',$employeeId)->get();

foreach ($appointments as $appointment) {

if($startTime >= $appointment->start_time && $startTime <= $appointment->finish_time ) {
return true;
} elseif ($finishTime >= $appointment->start_time && $finishTime <= $appointment->finish_time) {
return true;
}
}

return false;
// ->where(function ($query) use($startTime, $finishTime){
// $query->whereBetween('start_time',[$startTime, $finishTime])
// ->orWhereBetween('finish_time',[$startTime, $finishTime]);
// })
// ->Where(function($query) use($startTime, $finishTime){
// $query->where('start_time','<=',$startTime)
// ->where('finish_time','>=',$finishTime);
// })->exists();

// if($appointmentExists) {
// return true;
// } else {
// return false;
// }


// $date1 = new DateTime($startDate);
// $date2 = new DateTime($endDate);

// $diff = $date2->diff($date1);
// $hours = $diff->h;
// $hours = $hours + ($diff->days*24);
// var_dump($hours);
// die;



}
}
Empty file modified app/Http/Controllers/Admin/ClientsController.php
100644 → 100755
Empty file.
25 changes: 20 additions & 5 deletions app/Http/Controllers/Admin/EmployeesController.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class EmployeesController extends Controller
public function index(Request $request)
{
if ($request->ajax()) {
$query = Employee::with(['services'])->select(sprintf('%s.*', (new Employee)->table));
$query = Employee::with(['services','products'])->select(sprintf('%s.*', (new Employee)->table));
$table = Datatables::of($query);

$table->addColumn('placeholder', '&nbsp;');
Expand Down Expand Up @@ -75,7 +75,18 @@ public function index(Request $request)
return implode(' ', $labels);
});

$table->rawColumns(['actions', 'placeholder', 'photo', 'services']);
$table->editColumn('products', function ($row) {
$labels = [];

foreach ($row->products as $product) {
$labels[] = sprintf('<span class="label label-info label-many">%s</span>', $product->name);
}

return implode(' ', $labels);
});


$table->rawColumns(['actions', 'placeholder', 'photo', 'services', 'products']);

return $table->make(true);
}
Expand All @@ -88,14 +99,16 @@ public function create()
abort_if(Gate::denies('employee_create'), Response::HTTP_FORBIDDEN, '403 Forbidden');

$services = Service::all()->pluck('name', 'id');
$products = Product::all()->pluck('name', 'id');

return view('admin.employees.create', compact('services'));
return view('admin.employees.create', compact('services', 'products'));
}

public function store(StoreEmployeeRequest $request)
{
$employee = Employee::create($request->all());
$employee->services()->sync($request->input('services', []));
$employee->products()->sync($request->input('products', []));

if ($request->input('photo', false)) {
$employee->addMedia(storage_path('tmp/uploads/' . $request->input('photo')))->toMediaCollection('photo');
Expand All @@ -109,16 +122,18 @@ public function edit(Employee $employee)
abort_if(Gate::denies('employee_edit'), Response::HTTP_FORBIDDEN, '403 Forbidden');

$services = Service::all()->pluck('name', 'id');
$products = Product::all()->pluck('name', 'id');

$employee->load('services');
$employee->load('services','products');

return view('admin.employees.edit', compact('services', 'employee'));
return view('admin.employees.edit', compact('services','products','employee'));
}

public function update(UpdateEmployeeRequest $request, Employee $employee)
{
$employee->update($request->all());
$employee->services()->sync($request->input('services', []));
$employee->products()->sync($request->input('products', []));

if ($request->input('photo', false)) {
if (!$employee->photo || $request->input('photo') !== $employee->photo->file_name) {
Expand Down
20 changes: 19 additions & 1 deletion app/Http/Controllers/Admin/HomeController.php
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,11 +1,29 @@
<?php

namespace App\Http\Controllers\Admin;
use App\Appointment;
use App\Http\Controllers\Controller;

class HomeController
{
public function index()
{
return view('home');
$events = [];

$appointments = Appointment::with(['client', 'employee'])->get();

foreach ($appointments as $appointment) {
if (!$appointment->start_time) {
continue;
}

$events[] = [
'title' => $appointment->client->name . ' ('.$appointment->employee->name.')',
'start' => $appointment->start_time,
'url' => route('admin.appointments.edit', $appointment->id),
];
}

return view('admin.calendar.calendar', compact('events'));
}
}
Empty file modified app/Http/Controllers/Admin/PermissionsController.php
100644 → 100755
Empty file.
Loading