Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
mauryparra committed Nov 12, 2017
2 parents e0d51e1 + 28596fe commit 9e3c680
Show file tree
Hide file tree
Showing 39 changed files with 924 additions and 76 deletions.
7 changes: 6 additions & 1 deletion app/Http/Controllers/Auth/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Http\Controllers\Auth;

use App\Role;
use App\User;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Validator;
Expand Down Expand Up @@ -62,10 +63,14 @@ protected function validator(array $data)
*/
protected function create(array $data)
{
return User::create([
$user = User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
]);

$user->toggleRole('user');

return $user;
}
}
1 change: 1 addition & 0 deletions app/Http/Controllers/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public function index(Request $request)
else {
$reporteT = ReporteTrimestral::latest()
->with('trimestre', 'seccional', 'ingreso', 'egreso')
->orderBy('fecha', 'desc')
->paginate(6);
}

Expand Down
1 change: 1 addition & 0 deletions app/Http/Controllers/ReporteEgresoController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public function index()
{
$reportesEgresos = ReporteEgreso::latest()
->with('reporteTrimestral.trimestre', 'reporteTrimestral.seccional')
->orderBy('created_at', 'desc')
->paginate(6);

return view('egresos.index', compact('reportesEgresos'));
Expand Down
1 change: 1 addition & 0 deletions app/Http/Controllers/ReporteIngresoController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public function index()
{
$reportesIngresos = ReporteIngreso::latest()
->with('reporteTrimestral.trimestre', 'reporteTrimestral.seccional')
->orderBy('created_at', 'desc')
->paginate(6);

return view('ingresos.index', compact('reportesIngresos'));
Expand Down
8 changes: 5 additions & 3 deletions app/Http/Controllers/ReporteTrimestralController.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public function index(Request $request)
else {
$reporteT = ReporteTrimestral::latest()
->with('trimestre', 'seccional', 'ingreso', 'egreso')
->orderBy('fecha', 'desc')
->paginate(6);
}

Expand Down Expand Up @@ -99,11 +100,12 @@ public function update(Request $request, $id)
/**
* Remove the specified resource from storage.
*
* @param int $id
* @param \App\ReporteTrimestral $reporteT
* @return \Illuminate\Http\Response
*/
public function destroy($id)
public function destroy(ReporteTrimestral $reporteT)
{
//
$reporteT->delete();
return redirect(route('reportes.index'));
}
}
131 changes: 131 additions & 0 deletions app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
<?php

namespace App\Http\Controllers;

use App\User;
use Illuminate\Http\Request;
use Illuminate\Validation\Rule;

class UserController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth');
}

/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$users = User::latest()->with('roles')->paginate(6);

return view('users.index', compact('users'));
}

/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
return view('users.create');
}

/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$this->validate($request, [
'name' => 'required|max:255',
'email' => 'required|email|max:255|unique:users',
'password' => 'required|min:6|confirmed',
'roles' => 'required',
]);

$user = User::create([
'name' => $request->get('name'),
'email' => $request->get('email'),
'password' => bcrypt($request->get('password')),
]);

foreach ($request->get('roles') as $role => $id) {
$user->toggleRole($role);
}

return redirect(route('usuarios.index'));
}

/**
* Display the specified resource.
*
* @param \App\User $user
* @return \Illuminate\Http\Response
*/
public function show(User $user)
{
//
}

/**
* Show the form for editing the specified resource.
*
* @param \App\User $userEdit
* @return \Illuminate\Http\Response
*/
public function edit(User $userEdit)
{
return view('users.edit', compact('userEdit'));
}

/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\User $userEdit
* @return \Illuminate\Http\Response
*/
public function update(Request $request, User $userEdit)
{
$this->validate($request, [
'name' => 'required|max:255',
'email' => ['required', 'email', 'max:255', Rule::unique('users')->ignore($userEdit->email, 'email')],
'password' => 'sometimes|nullable|min:6|confirmed',
'roles' => 'required',
]);

$userEdit->name = $request->get('name');
$userEdit->email = $request->get('email');
$request->get('password') ? $userEdit->password = bcrypt($request->get('password')) : '';

$userEdit->assignRoles(array_keys($request->get('roles')));

$userEdit->save();

return redirect(route('usuarios.index'));
}

/**
* Remove the specified resource from storage.
*
* @param \App\User $usuario
* @return \Illuminate\Http\Response
*/
public function destroy(User $usuario)
{
$usuario->delete();
return redirect(route('usuarios.index'));
}
}
59 changes: 59 additions & 0 deletions app/Policies/ReporteTrimestralPolicy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

namespace App\Policies;

use App\User;
use App\ReporteTrimestral;
use Illuminate\Auth\Access\HandlesAuthorization;

class ReporteTrimestralPolicy
{
use HandlesAuthorization;

/**
* Determine whether the user can view the reporteTrimestral.
*
* @param \App\User $user
* @param \App\ReporteTrimestral $reporteTrimestral
* @return mixed
*/
public function view(User $user, ReporteTrimestral $reporteTrimestral)
{
//
}

/**
* Determine whether the user can create reporteTrimestrals.
*
* @param \App\User $user
* @return mixed
*/
public function create(User $user)
{
//
}

/**
* Determine whether the user can update the reporteTrimestral.
*
* @param \App\User $user
* @param \App\ReporteTrimestral $reporteTrimestral
* @return mixed
*/
public function update(User $user, ReporteTrimestral $reporteTrimestral)
{
//
}

/**
* Determine whether the user can delete the reporteTrimestral.
*
* @param \App\User $user
* @param \App\ReporteTrimestral $reporteTrimestral
* @return mixed
*/
public function delete(User $user, ReporteTrimestral $reporteTrimestral)
{
return $user->hasRole('admin');
}
}
70 changes: 70 additions & 0 deletions app/Policies/UserPolicy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

namespace App\Policies;

use App\User;
use Illuminate\Auth\Access\HandlesAuthorization;

class UserPolicy
{
use HandlesAuthorization;

/**
* Determine whether the user can access index method.
*
* @param \App\User $user
* @return mixed
*/
public function index(User $user)
{
return $user->hasRole('admin');
}


/**
* Determine whether the user can view the user.
*
* @param \App\User $user
* @param \App\User $userEdit
* @return mixed
*/
public function view(User $user, User $userEdit)
{
return $user->hasRole('admin') || $user->id == $userEdit->id;
}

/**
* Determine whether the user can create users.
*
* @param \App\User $user
* @return mixed
*/
public function create(User $user)
{
return $user->hasRole('admin');
}

/**
* Determine whether the user can update the user.
*
* @param \App\User $user
* @param \App\User $userEdit
* @return mixed
*/
public function update(User $user, User $userEdit)
{
return $user->hasRole('admin') || $user->id == $userEdit->id;
}

/**
* Determine whether the user can delete the user.
*
* @param \App\User $user
* @param \App\User $userEdit
* @return mixed
*/
public function delete(User $user, User $userEdit)
{
return $user->hasRole('admin') || $user->id == $userEdit->id;
}
}
4 changes: 2 additions & 2 deletions app/Presenters/GraficoPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function setChart($parameters)

switch ($parameters['grafico']) {
case "ingreso/egreso":
$data = ReporteTrimestral::getIngresosEgresos($parameters['seccional'], $fechaDesde, $fechaHasta);
$data = ReporteTrimestral::getReportes($parameters['seccional'], $fechaDesde, $fechaHasta);

if ( count($data) == 0 )
break;
Expand Down Expand Up @@ -132,7 +132,7 @@ public function setChart($parameters)
return $charts;

case "saldos":
$data = ReporteTrimestral::getSaldos($parameters['seccional'], $fechaDesde, $fechaHasta);
$data = ReporteTrimestral::getReportes($parameters['seccional'], $fechaDesde, $fechaHasta);

if ( count($data) == 0 )
break;
Expand Down
2 changes: 2 additions & 0 deletions app/Providers/AuthServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class AuthServiceProvider extends ServiceProvider
*/
protected $policies = [
'App\Model' => 'App\Policies\ModelPolicy',
'App\User' => 'App\Policies\UserPolicy',
'App\ReporteTrimestral' => 'App\Policies\ReporteTrimestralPolicy',
];

/**
Expand Down
1 change: 1 addition & 0 deletions app/ReporteIngresoMensual.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public static function getIngresos($seccional, $fechaDesde, $fechaHasta)
->where('fecha', '<=', $fechaHasta);
})
->with('reporteIngreso.reporteTrimestral.seccional')
->orderBy('mes', 'asc')
->get();
}
}
14 changes: 3 additions & 11 deletions app/ReporteTrimestral.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,25 +77,17 @@ public function path()
public function scopeSearch($query, $parameters)
{
return $query->where('trimestre_id', $parameters['trimestre'])
->where('fecha', 'LIKE', $parameters['año'].'-%') // TODO Check
->where('fecha', 'LIKE', $parameters['año'].'-%')
->where('seccional_id', $parameters['seccional']);
}

public static function getIngresosEgresos($seccional, $fechaDesde, $fechaHasta)
{
return self::where('seccional_id', $seccional)
->where('fecha', '>=', $fechaDesde)
->where('fecha', '<=', $fechaHasta)
->with('trimestre', 'seccional')
->get();
}

public static function getSaldos($seccional, $fechaDesde, $fechaHasta)
public static function getReportes($seccional, $fechaDesde, $fechaHasta)
{
return self::where('seccional_id', $seccional)
->where('fecha', '>=', $fechaDesde)
->where('fecha', '<=', $fechaHasta)
->with('trimestre', 'seccional')
->orderBy('fecha', 'asc')
->get();
}
}
Loading

0 comments on commit 9e3c680

Please sign in to comment.