Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Sep 25, 2015
2 parents fc7f15f + 627d8bb commit 1b06f14
Show file tree
Hide file tree
Showing 14 changed files with 927 additions and 603 deletions.
2 changes: 1 addition & 1 deletion app/Http/Controllers/ClientController.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public function getView($id)
$services = DB::table('service_client')
->join('service', 'service.id', '=', 'service_client.fk_service')
->where('service_client.fk_client','=',$model->id)
->select('service_client.id','service.id as serviceId', 'service.name', 'service_client.created_at')->get();
->select('service_client.id','service.id as serviceId', 'service.name', 'service_client.created_at', 'service_client.active','service_client.reason','service_client.date_to')->get();
//Get the client last invoices
$invoices = Invoice::where('fk_client', '=', $model->id)->orderBy('date_creation', 'asc')->get();

Expand Down
328 changes: 166 additions & 162 deletions app/Http/Controllers/IncidenceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,178 +12,182 @@
use App\Models\ServiceClient;
use App\Http\Controllers\Controller;
use App\Http\Controllers\InvoiceController;

use App\Http\Controllers\SMSController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

use App\Helpers\AngularHelper;

use Validator;
use DB;

/*
* Aglutinates the assistance, incidence and report functions of the ERP
*/
class IncidenceController extends Controller
{
/*
* This function returns if the client has his assistance checked in or not for today
*
* @param {Integer} $id - The id of the client to check for
* @param {Integer} $fk_room_reserve - The id of the reserve
*
* @return {Boolean/Null} true if yes or false if not, also null if it's not given
*/
public static function isChekedIn($id, $fk_room_reserve)
{
$assistance = Assistance::whereRaw('fk_client = '.$id.' AND fk_room_reserve = '.$fk_room_reserve.' AND date(created_at) = "'.date('Y-m-d').'"')->first();
if($assistance)
return $assistance->assist;
else
return null;
}

/*
* This function check's in the client
*/
public function checkIn(Request $request)
{
$data = $request->all();
//First of all check if exists the checkin
$checkIn = Assistance::whereRaw('fk_client = '.$data['fk_client'].' AND fk_room_reserve = '.$data['fk_room_reserve'].' AND date(created_at) = "'.date('Y-m-d').'"')->first();
if($checkIn){
//Update
$checkIn->assist = $data['assist'];
//Save
if($checkIn->save())
echo 'ok';
else
echo 'ko';
}else {
//Create and save
$assistance = new Assistance;
$assistance->fk_user = Auth::user()->id;
$assistance->fk_company = Auth::user()->fk_company;
$assistance->fk_room_reserve = $data['fk_room_reserve'];
$assistance->fk_client = $data['fk_client'];
$assistance->assist = $data['assist'];
//Save
if($assistance->save())
echo 'ok';
else
echo 'ko';

class IncidenceController extends Controller {
/*
* This function returns if the client has his assistance checked in or not for today
*
* @param {Integer} $id - The id of the client to check for
* @param {Integer} $fk_room_reserve - The id of the reserve
*
* @return {Boolean/Null} true if yes or false if not, also null if it's not given
*/

public static function isChekedIn($id, $fk_room_reserve) {
$assistance = Assistance::whereRaw('fk_client = ' . $id . ' AND fk_room_reserve = ' . $fk_room_reserve . ' AND date(created_at) = "' . date('Y-m-d') . '"')->first();
if ($assistance)
return $assistance->assist;
else
return null;
}

/*
* This function check's in the client
*/

public function checkIn(Request $request) {
$data = $request->all();
//First of all check if exists the checkin
$checkIn = Assistance::whereRaw('fk_client = ' . $data['fk_client'] . ' AND fk_room_reserve = ' . $data['fk_room_reserve'] . ' AND date(created_at) = "' . date('Y-m-d') . '"')->first();
if ($checkIn) {
//Update
$checkIn->assist = $data['assist'];
//Save
if ($checkIn->save())
echo 'ok';
else
echo 'ko';
}else {
//Create and save
$assistance = new Assistance;
$assistance->fk_user = Auth::user()->id;
$assistance->fk_company = Auth::user()->fk_company;
$assistance->fk_room_reserve = $data['fk_room_reserve'];
$assistance->fk_client = $data['fk_client'];
$assistance->assist = $data['assist'];
if ($data['assist'] == 0) {
//FUTURE!!
//$client = Client::find($assistance->fk_client);
//SMSController::sendAssistanceSms($client->phone_parents, $client->name);
}
//Save
if ($assistance->save())
echo 'ok';
else
echo 'ko';
}
}

/*
* This function creates a incidence for the client
*/

public function createClientIncidence(Request $request) {
$data = $request->all();
$incidence = new ClientIncidence;
//Set basic fk's
$incidence->fk_client = $data['fk_client'];
$incidence->fk_user = Auth::user()->id;
$incidence->fk_company = Auth::user()->fk_company;
//Other data
$incidence->concept = $data['concept'];
$incidence->observations = $data['description'];
//Save
if ($incidence->save())
echo 'ok';
else
echo 'ko';
}
}

/*
* This function creates a incidence for the client
*/
public function createClientIncidence(Request $request)
{
$data = $request->all();
$incidence = new ClientIncidence;
//Set basic fk's
$incidence->fk_client = $data['fk_client'];
$incidence->fk_user = Auth::user()->id;
$incidence->fk_company = Auth::user()->fk_company;
//Other data
$incidence->concept = $data['concept'];
$incidence->observations = $data['description'];
//Save
if($incidence->save())
echo 'ok';
else
echo 'ko';
}

/*
* This function returns the client report
*/
public function getClientReport(Request $request)
{
$data = $request->all();
//Get the service
$roomReserve = RoomReserve::find($data['fk_service']);
$roomService = RoomService::find($roomReserve->fk_room_service);
//Execute final query
$reports = ClientReport::whereRaw('fk_client = '.$data['fk_client'].' AND fk_service = '.$roomService->fk_service)->get();
//Print return
print_r(json_encode($reports));
}

/*
* This function creates a client report
*/
public function crateClientReport(Request $request)
{
$data = $request->all();
//Create model and fill it
$report = new ClientReport;
$report->fk_user = Auth::user()->id;
$report->fk_company = Auth::user()->fk_company;
$report->fk_client = $data['fk_client'];
//Get the service

/*
* This function returns the client report
*/

public function getClientReport(Request $request) {
$data = $request->all();
//Get the service
$roomReserve = RoomReserve::find($data['fk_service']);
$roomService = RoomService::find($roomReserve->fk_room_service);
//Execute final query
$reports = ClientReport::whereRaw('fk_client = ' . $data['fk_client'] . ' AND fk_service = ' . $roomService->fk_service)->get();
//Print return
print_r(json_encode($reports));
}

/*
* This function creates a client report
*/

public function crateClientReport(Request $request) {
$data = $request->all();
//Create model and fill it
$report = new ClientReport;
$report->fk_user = Auth::user()->id;
$report->fk_company = Auth::user()->fk_company;
$report->fk_client = $data['fk_client'];
//Get the service
$roomReserve = RoomReserve::find($data['fk_service']);
$roomService = RoomService::find($roomReserve->fk_room_service);
//
$report->fk_service = $roomService->fk_service;
$report->concept = $data['concept'];
$report->observations = $data['observations'];
if($report->save())
return 'ok';
else
return 'ko';
}

/*
* This function get's all the client incidencies
*/
public function getClientIncidences()
{
$incidences = ClientIncidence::whereRaw('fk_company = '.Auth::user()->fk_company.' AND seen IS NULL')->get();
return view('client.incidences',['incidences' => $incidences]);
}

/*
* This function completes the incidence
*/
public function completeIncidence($id)
{
//Load the incidence
$incidence = ClientIncidence::find($id);
//Update the user and seen values
$incidence->seen = 1;
$incidence->fk_user = Auth::user()->id;
//Save
$incidence->save();
//Redirect to the list
return redirect('/incidence/client');
}

/*
* This function returns an array with the client incidences
*/
public static function fetchClientIncidences($fk_client)
{
$incidences = ClientIncidence::where('fk_client', '=', $fk_client)->get();
return $incidences;
}

/*
* This function renders the client assistance list view
*/
public function getAssitanceList()
{
$assistance = Assistance::whereRaw('fk_company = '. Auth::user()->fk_company.' AND assist = 0')->get();
return view('client.assistance',['incidences' => $assistance]);
}

/*
* This function fetchs the list of assistances
*/
public static function fetchAssitanceList($fk_client)
{
$assistance = Assistance::whereRaw('fk_client = '. $fk_client.' AND assist = 0')->get();
return $assistance;
}
//
$report->fk_service = $roomService->fk_service;
$report->concept = $data['concept'];
$report->observations = $data['observations'];
if ($report->save())
return 'ok';
else
return 'ko';
}

/*
* This function get's all the client incidencies
*/

public function getClientIncidences() {
$incidences = ClientIncidence::whereRaw('fk_company = ' . Auth::user()->fk_company . ' AND seen IS NULL')->get();
return view('client.incidences', ['incidences' => $incidences]);
}

/*
* This function completes the incidence
*/

public function completeIncidence($id) {
//Load the incidence
$incidence = ClientIncidence::find($id);
//Update the user and seen values
$incidence->seen = 1;
$incidence->fk_user = Auth::user()->id;
//Save
$incidence->save();
//Redirect to the list
return redirect('/incidence/client');
}

/*
* This function returns an array with the client incidences
*/

public static function fetchClientIncidences($fk_client) {
$incidences = ClientIncidence::where('fk_client', '=', $fk_client)->get();
return $incidences;
}

/*
* This function renders the client assistance list view
*/

public function getAssitanceList() {
$assistance = Assistance::whereRaw('fk_company = ' . Auth::user()->fk_company . ' AND assist = 0')->get();
return view('client.assistance', ['incidences' => $assistance]);
}

/*
* This function fetchs the list of assistances
*/

public static function fetchAssitanceList($fk_client) {
$assistance = Assistance::whereRaw('fk_client = ' . $fk_client . ' AND assist = 0')->get();
return $assistance;
}

}
44 changes: 44 additions & 0 deletions app/Http/Controllers/SMSController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace App\Http\Controllers;

use App\User;
use App\Models\SMS;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Validator;
use DB;

class SMSController extends Controller {

public $sid = "AC113689b3ade38f49b712aa925d17dffd";
public $token = "d36d960a6b5b01908d6ce1f02354ee95";
public $limit = 20;

/*
* This function send's a sms to the clientphone
*/

public static function sendAssistanceSms($phone, $clientName) {
var_dump($phone, $clientName);die;
//First get how much sms have sended yet
$sends = SMS::whereRaw('DATE(created_at) = "' . date('Y-m-d') . '"')->count();
//If not sended up to the limit, continue
if ($sends < self::limit) {
$client = new Services_Twilio(self::account_sid, self::auth_token);
//Send the message
$client->account->messages->create(array(
'To' => "637107315",
'From' => "637107315",
'Body' => "preuba",
));
if ($client->id != null) {
return true;
}
} else {
return false;
}
}

}
Loading

0 comments on commit 1b06f14

Please sign in to comment.