show transactions in pirep

This commit is contained in:
Nabeel Shahzad 2018-03-02 16:09:48 -06:00
parent 9d65515290
commit 2df09c533b
5 changed files with 77 additions and 5 deletions

View File

@ -12,6 +12,7 @@ use App\Models\PirepComment;
use App\Repositories\AircraftRepository;
use App\Repositories\AirlineRepository;
use App\Repositories\AirportRepository;
use App\Repositories\JournalRepository;
use App\Repositories\PirepFieldRepository;
use App\Repositories\PirepRepository;
use App\Repositories\SubfleetRepository;
@ -33,6 +34,7 @@ class PirepController extends BaseController
$airlineRepo,
$aircraftRepo,
$fareSvc,
$journalRepo,
$pirepSvc,
$pirepRepo,
$pirepFieldRepo,
@ -44,7 +46,10 @@ class PirepController extends BaseController
* @param AirportRepository $airportRepo
* @param AirlineRepository $airlineRepo
* @param AircraftRepository $aircraftRepo
* @param FareService $fareSvc
* @param JournalRepository $journalRepo
* @param PirepRepository $pirepRepo
* @param PirepFieldRepository $pirepFieldRepo
* @param PIREPService $pirepSvc
* @param SubfleetRepository $subfleetRepo
* @param UserService $userSvc
@ -54,6 +59,7 @@ class PirepController extends BaseController
AirlineRepository $airlineRepo,
AircraftRepository $aircraftRepo,
FareService $fareSvc,
JournalRepository $journalRepo,
PirepRepository $pirepRepo,
PirepFieldRepository $pirepFieldRepo,
PIREPService $pirepSvc,
@ -64,6 +70,7 @@ class PirepController extends BaseController
$this->airlineRepo = $airlineRepo;
$this->aircraftRepo = $aircraftRepo;
$this->fareSvc = $fareSvc;
$this->journalRepo = $journalRepo;
$this->pirepRepo = $pirepRepo;
$this->pirepFieldRepo = $pirepFieldRepo;
$this->pirepSvc = $pirepSvc;
@ -266,6 +273,7 @@ class PirepController extends BaseController
* Show the form for editing the specified Pirep.
* @param int $id
* @return Response
* @throws \InvalidArgumentException
*/
public function edit($id)
{
@ -293,6 +301,8 @@ class PirepController extends BaseController
$pirep->{$field_name} = $fare->count;
}
$journal = $this->journalRepo->getAllForObject($pirep, $pirep->airline->journal);
return view('admin.pireps.edit', [
'pirep' => $pirep,
'read_only' => $read_only,
@ -300,6 +310,7 @@ class PirepController extends BaseController
'aircraft_list' => $this->aircraftList(),
'airports_list' => $this->airportRepo->selectBoxList(),
'airlines_list' => $this->airlineRepo->selectBoxList(),
'journal' => $journal,
]);
}

View File

@ -318,6 +318,12 @@ class Pirep extends BaseModel
->latest();
}
public function transactions()
{
return $this->hasMany(JournalTransaction::class, 'ref_class_id')
->where('ref_class', __CLASS__);
}
public function user()
{
return $this->belongsTo(User::class, 'user_id');

View File

@ -171,16 +171,21 @@ class JournalRepository extends BaseRepository implements CacheableInterface
/**
* Return all transactions for a given object
* @param $object
* @param null $journal
* @return array
* @throws \UnexpectedValueException
* @throws \InvalidArgumentException
*/
public function getAllForObject($object)
public function getAllForObject($object, $journal=null)
{
$transactions = $this->findWhere([
$where = [
'ref_class' => \get_class($object),
'ref_class_id' => $object->id,
]);
];
if($journal) {
$where['journal_id'] = $journal->id;
}
$transactions = $this->findWhere($where);
return [
'credits' => new Money($transactions->sum('credit')),

View File

@ -42,6 +42,13 @@
</div>
</div>
<div class="card border-blue-bottom">
<div class="content">
<h4>transactions</h4>
@include('admin.pireps.transactions')
</div>
</div>
</div>
@endsection

View File

@ -0,0 +1,43 @@
@if(count($journal['transactions']) > 0)
<div class="col-12">
<table class="table table-hover" id="users-table">
<tbody>
@foreach($journal['transactions'] as $entry)
<tr>
<td>{!! $entry->memo !!}</td>
<td>
@if($entry->credit)
{!! money($entry->credit, config('phpvms.currency')) !!}
@endif
</td>
<td>
@if($entry->debit)
{!! money($entry->debit, config('phpvms.currency')) !!}
@endif
</td>
</tr>
@endforeach
{{-- show sums --}}
<tr>
<td></td>
<td>
{!! $journal['credits'] !!}
</td>
<td>
({!! $journal['debits'] !!})
</td>
</tr>
{{-- final total --}}
<tr>
<td></td>
<td><b>Total</b></td>
<td>
{!! $journal['credits']->subtract($journal['debits']) !!}
</td>
</tr>
</tbody>
</table>
</div>
@endif