Added refresh finances button to transactions list #130

This commit is contained in:
Nabeel Shahzad 2018-03-05 13:07:10 -06:00
parent 96e8fbfa78
commit a7a70ce423
6 changed files with 95 additions and 10 deletions

View File

@ -13,6 +13,7 @@ use App\Http\Requests\Acars\PrefileRequest;
use App\Http\Requests\Acars\RouteRequest; use App\Http\Requests\Acars\RouteRequest;
use App\Http\Requests\Acars\UpdateRequest; use App\Http\Requests\Acars\UpdateRequest;
use App\Http\Resources\AcarsRoute as AcarsRouteResource; use App\Http\Resources\AcarsRoute as AcarsRouteResource;
use App\Http\Resources\JournalTransaction as JournalTransactionResource;
use App\Http\Resources\Pirep as PirepResource; use App\Http\Resources\Pirep as PirepResource;
use App\Http\Resources\PirepComment as PirepCommentResource; use App\Http\Resources\PirepComment as PirepCommentResource;
use App\Models\Acars; use App\Models\Acars;
@ -23,7 +24,9 @@ use App\Models\Enums\PirepStatus;
use App\Models\Pirep; use App\Models\Pirep;
use App\Models\PirepComment; use App\Models\PirepComment;
use App\Repositories\AcarsRepository; use App\Repositories\AcarsRepository;
use App\Repositories\JournalRepository;
use App\Repositories\PirepRepository; use App\Repositories\PirepRepository;
use App\Services\FinanceService;
use App\Services\GeoService; use App\Services\GeoService;
use App\Services\PIREPService; use App\Services\PIREPService;
use App\Services\UserService; use App\Services\UserService;
@ -33,29 +36,37 @@ use Log;
class PirepController extends RestController class PirepController extends RestController
{ {
protected $acarsRepo, private $acarsRepo,
$geoSvc, $financeSvc,
$pirepRepo, $geoSvc,
$pirepSvc, $journalRepo,
$userSvc; $pirepRepo,
$pirepSvc,
$userSvc;
/** /**
* PirepController constructor. * PirepController constructor.
* @param AcarsRepository $acarsRepo * @param AcarsRepository $acarsRepo
* @param FinanceService $financeSvc
* @param GeoService $geoSvc * @param GeoService $geoSvc
* @param JournalRepository $journalRepo
* @param PirepRepository $pirepRepo * @param PirepRepository $pirepRepo
* @param PIREPService $pirepSvc * @param PIREPService $pirepSvc
* @param UserService $userSvc * @param UserService $userSvc
*/ */
public function __construct( public function __construct(
AcarsRepository $acarsRepo, AcarsRepository $acarsRepo,
FinanceService $financeSvc,
GeoService $geoSvc, GeoService $geoSvc,
JournalRepository $journalRepo,
PirepRepository $pirepRepo, PirepRepository $pirepRepo,
PIREPService $pirepSvc, PIREPService $pirepSvc,
UserService $userSvc UserService $userSvc
) { ) {
$this->acarsRepo = $acarsRepo; $this->acarsRepo = $acarsRepo;
$this->financeSvc = $financeSvc;
$this->geoSvc = $geoSvc; $this->geoSvc = $geoSvc;
$this->journalRepo = $journalRepo;
$this->pirepRepo = $pirepRepo; $this->pirepRepo = $pirepRepo;
$this->pirepSvc = $pirepSvc; $this->pirepSvc = $pirepSvc;
$this->userSvc = $userSvc; $this->userSvc = $userSvc;
@ -436,6 +447,37 @@ class PirepController extends RestController
return new PirepCommentResource($comment); return new PirepCommentResource($comment);
} }
/**
* @param $id
* @param Request $request
* @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection
*/
public function finances_get($id, Request $request)
{
$pirep = $this->pirepRepo->find($id);
$transactions = $this->journalRepo->getAllForObject($pirep);
return JournalTransactionResource::collection($transactions);
}
/**
* @param $id
* @param Request $request
* @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection
* @throws \UnexpectedValueException
* @throws \InvalidArgumentException
* @throws \Exception
* @throws \Prettus\Validator\Exceptions\ValidatorException
*/
public function finances_recalculate($id, Request $request)
{
$pirep = $this->pirepRepo->find($id);
$this->financeSvc->processFinancesForPirep($pirep);
$pirep->refresh();
$transactions = $this->journalRepo->getAllForObject($pirep);
return JournalTransactionResource::collection($transactions['transactions']);
}
/** /**
* @param $id * @param $id
* @param Request $request * @param Request $request

View File

@ -0,0 +1,14 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\Resource;
class JournalTransaction extends Resource
{
public function toArray($request)
{
$transaction = parent::toArray($request);
return $transaction;
}
}

View File

@ -45,6 +45,9 @@ Route::group(['middleware' => ['api.auth']], function ()
Route::post('pireps/{pirep_id}/comments', 'PirepController@comments_post'); Route::post('pireps/{pirep_id}/comments', 'PirepController@comments_post');
Route::delete('pireps/{pirep_id}/cancel', 'PirepController@cancel'); Route::delete('pireps/{pirep_id}/cancel', 'PirepController@cancel');
Route::get('pireps/{pirep_id}/finances', 'PirepController@finances_get');
Route::post('pireps/{pirep_id}/finances/recalculate', 'PirepController@finances_recalculate');
Route::get('pireps/{pirep_id}/route', 'PirepController@route_get'); Route::get('pireps/{pirep_id}/route', 'PirepController@route_get');
Route::post('pireps/{pirep_id}/route', 'PirepController@route_post'); Route::post('pireps/{pirep_id}/route', 'PirepController@route_post');
Route::delete('pireps/{pirep_id}/route', 'PirepController@route_delete'); Route::delete('pireps/{pirep_id}/route', 'PirepController@route_delete');

View File

@ -44,6 +44,11 @@
<div class="card border-blue-bottom"> <div class="card border-blue-bottom">
<div class="content"> <div class="content">
<div class="pull-right">
<button id="recalculate-finances"
class="btn btn-success"
data-pirep-id="{!! $pirep->id !!}">Recalcuate Finances</button>
</div>
<h4>transactions</h4> <h4>transactions</h4>
@include('admin.pireps.transactions') @include('admin.pireps.transactions')
</div> </div>

View File

@ -15,7 +15,7 @@ const changeStatus = (values, fn) => {
}); });
}; };
$(document).ready(function() { $(document).ready(() => {
const select_id = "select#aircraft_select"; const select_id = "select#aircraft_select";
const destContainer = $('#fares_container'); const destContainer = $('#fares_container');
@ -40,7 +40,7 @@ $(document).ready(function() {
}); });
}); });
$(document).on('submit', 'form.pjax_form', function (event) { $(document).on('submit', 'form.pjax_form', (event) => {
event.preventDefault(); event.preventDefault();
$.pjax.submit(event, '#pirep_comments_wrapper', {push: false}); $.pjax.submit(event, '#pirep_comments_wrapper', {push: false});
}); });
@ -49,7 +49,28 @@ $(document).ready(function() {
$(".select2").select2(); $(".select2").select2();
}); });
$(document).on('submit', 'form.pirep_submit_status', function (event) { /**
* Recalculate finances button is clicked
*/
$('button#recalculate-finances').on('click', (event) => {
event.preventDefault();
console.log('Sending recalculate finances request');
const pirep_id = $(event.currentTarget).attr('data-pirep-id');
$.ajax({
url: BASE_URL + '/api/pireps/' + pirep_id + '/finances/recalculate',
type: 'POST',
headers: {
'x-api-key': PHPVMS_USER_API_KEY
},
success: (data) => {
console.log(data);
//location.reload();
}
});
});
$(document).on('submit', 'form.pirep_submit_status', (event) => {
console.log(event); console.log(event);
event.preventDefault(); event.preventDefault();
@ -64,7 +85,7 @@ $(document).ready(function() {
}); });
}); });
$(document).on('submit', 'form.pirep_change_status', function(event) { $(document).on('submit', 'form.pirep_change_status', (event) => {
event.preventDefault(); event.preventDefault();
changeStatus({ changeStatus({
pirep_id: $(this).attr('pirep_id'), pirep_id: $(this).attr('pirep_id'),

View File

@ -1,5 +1,5 @@
@if(count($journal['transactions']) > 0)
<div class="col-12"> <div class="col-12">
@if(count($journal['transactions']) > 0)
<table class="table table-hover" id="users-table"> <table class="table table-hover" id="users-table">
<tbody> <tbody>
@foreach($journal['transactions'] as $entry) @foreach($journal['transactions'] as $entry)