Post fares/expenses on PIREP to Airline journal #130

This commit is contained in:
Nabeel Shahzad
2018-03-01 16:20:13 -06:00
parent f1b9ea94dc
commit 2c52a2f7e6
22 changed files with 625 additions and 85 deletions

View File

@@ -3,6 +3,7 @@
namespace App\Repositories;
use App\Models\Expense;
use Illuminate\Support\Collection;
use Prettus\Repository\Contracts\CacheableInterface;
use Prettus\Repository\Traits\CacheableRepository;
@@ -18,4 +19,28 @@ class ExpenseRepository extends BaseRepository implements CacheableInterface
{
return Expense::class;
}
/**
* Get all of the expenses for a given type, and also
* include expenses for a given airline ID
* @param $type
* @return Collection
*/
public function getAllForType($type, $airline_id=null)
{
$expenses = $this->findWhere([
'type' => $type,
]);
if($airline_id) {
$airline_expenses = $this->findWhere([
'type' => $type,
'airline_id' => $airline_id
]);
$expenses = $expenses->concat($airline_expenses);
}
return $expenses;
}
}

View File

@@ -31,24 +31,24 @@ class FlightRepository extends BaseRepository implements CacheableInterface
* Find a flight based on the given criterea
* @param $airline_id
* @param $flight_num
* @param null $flight_code
* @param null $flight_leg
* @param null $route_code
* @param null $route_leg
* @return mixed
*/
public function findFlight($airline_id, $flight_num, $flight_code=null, $flight_leg=null)
public function findFlight($airline_id, $flight_num, $route_code=null, $route_leg=null)
{
$where = [
'airline_id' => $airline_id,
'flight_num' => $flight_num,
'flight_number' => $flight_num,
'active' => true,
];
if(filled($flight_code)) {
$where['flight_code'] = $flight_code;
if(filled($route_code)) {
$where['route_code'] = $route_code;
}
if(filled('flight_leg')) {
$where['flight_leg'] = $flight_leg;
if(filled($route_leg)) {
$where['route_leg'] = $route_leg;
}
return $this->findWhere($where);

View File

@@ -19,6 +19,9 @@ class JournalRepository extends BaseRepository implements CacheableInterface
{
use CacheableRepository;
/**
* @return string
*/
public function model()
{
return JournalTransaction::class;
@@ -58,7 +61,6 @@ class JournalRepository extends BaseRepository implements CacheableInterface
'currency' => config('phpvms.currency'),
'memo' => $memo,
'post_date' => $post_date ?: Carbon::now(),
'transaction_group' => $transaction_group,
];
if($reference !== null) {
@@ -66,6 +68,11 @@ class JournalRepository extends BaseRepository implements CacheableInterface
$attrs['ref_class_id'] = $reference->id;
}
if($transaction_group) {
$transaction_group = str_replace(' ', '_', $transaction_group);
$attrs['transaction_group'] = $transaction_group;
}
try {
$transaction = $this->create($attrs);
} catch (ValidatorException $e) {