Remove subfleet_expenses and combine into main expenses table; select expense type on subfleet #130 #136

This commit is contained in:
Nabeel Shahzad
2018-03-05 21:24:49 -06:00
parent 8c05ad134e
commit 88a8fd2bbd
20 changed files with 160 additions and 138 deletions

View File

@@ -24,20 +24,39 @@ class ExpenseRepository extends BaseRepository implements CacheableInterface
* Get all of the expenses for a given type, and also
* include expenses for a given airline ID
* @param $type
* @param null $airline_id
* @param null $ref_class
* @return Collection
*/
public function getAllForType($type, $airline_id=null)
public function getAllForType($type, $airline_id=null, $ref_class=null)
{
$expenses = $this->findWhere([
$where = [
'type' => $type,
['airline_id', '=', null]
]);
];
if($ref_class) {
$where['ref_class'] = $ref_class;
} else {
$where[] = ['ref_class', '=', null];
}
$expenses = $this->findWhere($where);
if($airline_id) {
$airline_expenses = $this->findWhere([
$where = [
'type' => $type,
'airline_id' => $airline_id
]);
];
if ($ref_class) {
$where['ref_class'] = $ref_class;
} else {
$where[] = ['ref_class', '=', null];
}
$airline_expenses = $this->findWhere($where);
$expenses = $expenses->concat($airline_expenses);
}

View File

@@ -61,6 +61,7 @@ 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) {
@@ -68,11 +69,6 @@ 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) {