show transactions in pirep
This commit is contained in:
parent
9d65515290
commit
2df09c533b
@ -12,6 +12,7 @@ use App\Models\PirepComment;
|
|||||||
use App\Repositories\AircraftRepository;
|
use App\Repositories\AircraftRepository;
|
||||||
use App\Repositories\AirlineRepository;
|
use App\Repositories\AirlineRepository;
|
||||||
use App\Repositories\AirportRepository;
|
use App\Repositories\AirportRepository;
|
||||||
|
use App\Repositories\JournalRepository;
|
||||||
use App\Repositories\PirepFieldRepository;
|
use App\Repositories\PirepFieldRepository;
|
||||||
use App\Repositories\PirepRepository;
|
use App\Repositories\PirepRepository;
|
||||||
use App\Repositories\SubfleetRepository;
|
use App\Repositories\SubfleetRepository;
|
||||||
@ -33,6 +34,7 @@ class PirepController extends BaseController
|
|||||||
$airlineRepo,
|
$airlineRepo,
|
||||||
$aircraftRepo,
|
$aircraftRepo,
|
||||||
$fareSvc,
|
$fareSvc,
|
||||||
|
$journalRepo,
|
||||||
$pirepSvc,
|
$pirepSvc,
|
||||||
$pirepRepo,
|
$pirepRepo,
|
||||||
$pirepFieldRepo,
|
$pirepFieldRepo,
|
||||||
@ -44,7 +46,10 @@ class PirepController extends BaseController
|
|||||||
* @param AirportRepository $airportRepo
|
* @param AirportRepository $airportRepo
|
||||||
* @param AirlineRepository $airlineRepo
|
* @param AirlineRepository $airlineRepo
|
||||||
* @param AircraftRepository $aircraftRepo
|
* @param AircraftRepository $aircraftRepo
|
||||||
|
* @param FareService $fareSvc
|
||||||
|
* @param JournalRepository $journalRepo
|
||||||
* @param PirepRepository $pirepRepo
|
* @param PirepRepository $pirepRepo
|
||||||
|
* @param PirepFieldRepository $pirepFieldRepo
|
||||||
* @param PIREPService $pirepSvc
|
* @param PIREPService $pirepSvc
|
||||||
* @param SubfleetRepository $subfleetRepo
|
* @param SubfleetRepository $subfleetRepo
|
||||||
* @param UserService $userSvc
|
* @param UserService $userSvc
|
||||||
@ -54,6 +59,7 @@ class PirepController extends BaseController
|
|||||||
AirlineRepository $airlineRepo,
|
AirlineRepository $airlineRepo,
|
||||||
AircraftRepository $aircraftRepo,
|
AircraftRepository $aircraftRepo,
|
||||||
FareService $fareSvc,
|
FareService $fareSvc,
|
||||||
|
JournalRepository $journalRepo,
|
||||||
PirepRepository $pirepRepo,
|
PirepRepository $pirepRepo,
|
||||||
PirepFieldRepository $pirepFieldRepo,
|
PirepFieldRepository $pirepFieldRepo,
|
||||||
PIREPService $pirepSvc,
|
PIREPService $pirepSvc,
|
||||||
@ -64,6 +70,7 @@ class PirepController extends BaseController
|
|||||||
$this->airlineRepo = $airlineRepo;
|
$this->airlineRepo = $airlineRepo;
|
||||||
$this->aircraftRepo = $aircraftRepo;
|
$this->aircraftRepo = $aircraftRepo;
|
||||||
$this->fareSvc = $fareSvc;
|
$this->fareSvc = $fareSvc;
|
||||||
|
$this->journalRepo = $journalRepo;
|
||||||
$this->pirepRepo = $pirepRepo;
|
$this->pirepRepo = $pirepRepo;
|
||||||
$this->pirepFieldRepo = $pirepFieldRepo;
|
$this->pirepFieldRepo = $pirepFieldRepo;
|
||||||
$this->pirepSvc = $pirepSvc;
|
$this->pirepSvc = $pirepSvc;
|
||||||
@ -266,6 +273,7 @@ class PirepController extends BaseController
|
|||||||
* Show the form for editing the specified Pirep.
|
* Show the form for editing the specified Pirep.
|
||||||
* @param int $id
|
* @param int $id
|
||||||
* @return Response
|
* @return Response
|
||||||
|
* @throws \InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
public function edit($id)
|
public function edit($id)
|
||||||
{
|
{
|
||||||
@ -293,6 +301,8 @@ class PirepController extends BaseController
|
|||||||
$pirep->{$field_name} = $fare->count;
|
$pirep->{$field_name} = $fare->count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$journal = $this->journalRepo->getAllForObject($pirep, $pirep->airline->journal);
|
||||||
|
|
||||||
return view('admin.pireps.edit', [
|
return view('admin.pireps.edit', [
|
||||||
'pirep' => $pirep,
|
'pirep' => $pirep,
|
||||||
'read_only' => $read_only,
|
'read_only' => $read_only,
|
||||||
@ -300,6 +310,7 @@ class PirepController extends BaseController
|
|||||||
'aircraft_list' => $this->aircraftList(),
|
'aircraft_list' => $this->aircraftList(),
|
||||||
'airports_list' => $this->airportRepo->selectBoxList(),
|
'airports_list' => $this->airportRepo->selectBoxList(),
|
||||||
'airlines_list' => $this->airlineRepo->selectBoxList(),
|
'airlines_list' => $this->airlineRepo->selectBoxList(),
|
||||||
|
'journal' => $journal,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -318,6 +318,12 @@ class Pirep extends BaseModel
|
|||||||
->latest();
|
->latest();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function transactions()
|
||||||
|
{
|
||||||
|
return $this->hasMany(JournalTransaction::class, 'ref_class_id')
|
||||||
|
->where('ref_class', __CLASS__);
|
||||||
|
}
|
||||||
|
|
||||||
public function user()
|
public function user()
|
||||||
{
|
{
|
||||||
return $this->belongsTo(User::class, 'user_id');
|
return $this->belongsTo(User::class, 'user_id');
|
||||||
|
@ -171,16 +171,21 @@ class JournalRepository extends BaseRepository implements CacheableInterface
|
|||||||
/**
|
/**
|
||||||
* Return all transactions for a given object
|
* Return all transactions for a given object
|
||||||
* @param $object
|
* @param $object
|
||||||
|
* @param null $journal
|
||||||
* @return array
|
* @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' => \get_class($object),
|
||||||
'ref_class_id' => $object->id,
|
'ref_class_id' => $object->id,
|
||||||
]);
|
];
|
||||||
|
|
||||||
|
if($journal) {
|
||||||
|
$where['journal_id'] = $journal->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
$transactions = $this->findWhere($where);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'credits' => new Money($transactions->sum('credit')),
|
'credits' => new Money($transactions->sum('credit')),
|
||||||
|
@ -42,6 +42,13 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="card border-blue-bottom">
|
||||||
|
<div class="content">
|
||||||
|
<h4>transactions</h4>
|
||||||
|
@include('admin.pireps.transactions')
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
@endsection
|
@endsection
|
||||||
|
|
||||||
|
43
resources/views/admin/pireps/transactions.blade.php
Normal file
43
resources/views/admin/pireps/transactions.blade.php
Normal 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
|
Loading…
Reference in New Issue
Block a user