* Refactor and add importer to Installer module #443 * Refactor for finances to use in import * Import groups into roles * Formatting * Formatting * Add interface in installer for import * Notes about importing * Check for installer folder * Formatting * Fix pirep->user mapping * Unused import * Formatting
This commit is contained in:
@@ -11,17 +11,16 @@ use App\Models\Pirep;
|
||||
use App\Repositories\ExpenseRepository;
|
||||
use App\Repositories\JournalRepository;
|
||||
use App\Services\FareService;
|
||||
use App\Services\FinanceService;
|
||||
use App\Support\Math;
|
||||
use App\Support\Money;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
/**
|
||||
* Class FinanceService
|
||||
*/
|
||||
class PirepFinanceService extends Service
|
||||
{
|
||||
private $expenseRepo;
|
||||
private $fareSvc;
|
||||
private $financeSvc;
|
||||
private $journalRepo;
|
||||
|
||||
/**
|
||||
@@ -30,15 +29,18 @@ class PirepFinanceService extends Service
|
||||
* @param ExpenseRepository $expenseRepo
|
||||
* @param FareService $fareSvc
|
||||
* @param JournalRepository $journalRepo
|
||||
* @param FinanceService $financeSvc
|
||||
*/
|
||||
public function __construct(
|
||||
ExpenseRepository $expenseRepo,
|
||||
FareService $fareSvc,
|
||||
FinanceService $financeSvc,
|
||||
JournalRepository $journalRepo
|
||||
) {
|
||||
$this->expenseRepo = $expenseRepo;
|
||||
$this->fareSvc = $fareSvc;
|
||||
$this->journalRepo = $journalRepo;
|
||||
$this->financeSvc = $financeSvc;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -149,13 +151,11 @@ class PirepFinanceService extends Service
|
||||
Log::info('Finance: Fuel cost, (fuel='.$fuel_used.', cost='.$ap->fuel_jeta_cost.') D='
|
||||
.$debit->getAmount());
|
||||
|
||||
$this->journalRepo->post(
|
||||
$this->financeSvc->debitFromJournal(
|
||||
$pirep->airline->journal,
|
||||
null,
|
||||
$debit,
|
||||
$pirep,
|
||||
'Fuel Cost ('.$ap->fuel_jeta_cost.'/'.config('phpvms.internal_units.fuel').')',
|
||||
null,
|
||||
'Fuel',
|
||||
'fuel'
|
||||
);
|
||||
@@ -194,13 +194,11 @@ class PirepFinanceService extends Service
|
||||
$debit = Money::createFromAmount($cost_per_min * $block_time);
|
||||
Log::info('Finance: Subfleet Block Hourly, D='.$debit->getAmount());
|
||||
|
||||
$this->journalRepo->post(
|
||||
$this->financeSvc->debitFromJournal(
|
||||
$pirep->airline->journal,
|
||||
null,
|
||||
$debit,
|
||||
$pirep,
|
||||
'Subfleet '.$sf->type.': Block Time Cost',
|
||||
null,
|
||||
'Subfleet '.$sf->type,
|
||||
'subfleet'
|
||||
);
|
||||
@@ -265,13 +263,11 @@ class PirepFinanceService extends Service
|
||||
$journal = $pirep->user->journal;
|
||||
}
|
||||
|
||||
$this->journalRepo->post(
|
||||
$this->financeSvc->debitFromJournal(
|
||||
$journal,
|
||||
null,
|
||||
$debit,
|
||||
$pirep,
|
||||
$memo,
|
||||
null,
|
||||
$transaction_group,
|
||||
strtolower($klass)
|
||||
);
|
||||
@@ -320,13 +316,11 @@ class PirepFinanceService extends Service
|
||||
|
||||
$debit = Money::createFromAmount($expense->amount);
|
||||
|
||||
$this->journalRepo->post(
|
||||
$this->financeSvc->debitFromJournal(
|
||||
$pirep->airline->journal,
|
||||
null,
|
||||
$debit,
|
||||
$pirep,
|
||||
'Expense: '.$expense->name,
|
||||
null,
|
||||
$expense->transaction_group ?? 'Expenses',
|
||||
'expense'
|
||||
);
|
||||
@@ -347,13 +341,12 @@ class PirepFinanceService extends Service
|
||||
{
|
||||
$ground_handling_cost = $this->getGroundHandlingCost($pirep);
|
||||
Log::info('Finance: PIREP: '.$pirep->id.'; ground handling: '.$ground_handling_cost);
|
||||
$this->journalRepo->post(
|
||||
|
||||
$this->financeSvc->debitFromJournal(
|
||||
$pirep->airline->journal,
|
||||
null,
|
||||
Money::createFromAmount($ground_handling_cost),
|
||||
$pirep,
|
||||
'Ground Handling',
|
||||
null,
|
||||
'Ground Handling',
|
||||
'ground_handling'
|
||||
);
|
||||
@@ -378,24 +371,20 @@ class PirepFinanceService extends Service
|
||||
Log::info('Finance: PIREP: '.$pirep->id
|
||||
.'; pilot pay: '.$pilot_pay_rate.', total: '.$pilot_pay);
|
||||
|
||||
$this->journalRepo->post(
|
||||
$this->financeSvc->debitFromJournal(
|
||||
$pirep->airline->journal,
|
||||
null,
|
||||
$pilot_pay,
|
||||
$pirep,
|
||||
$memo,
|
||||
null,
|
||||
'Pilot Pay',
|
||||
'pilot_pay'
|
||||
);
|
||||
|
||||
$this->journalRepo->post(
|
||||
$this->financeSvc->creditToJournal(
|
||||
$pirep->user->journal,
|
||||
$pilot_pay,
|
||||
null,
|
||||
$pirep,
|
||||
$memo,
|
||||
null,
|
||||
'Pilot Pay',
|
||||
'pilot_pay'
|
||||
);
|
||||
|
||||
@@ -8,23 +8,22 @@ use App\Models\Enums\ExpenseType;
|
||||
use App\Models\Expense;
|
||||
use App\Models\JournalTransaction;
|
||||
use App\Repositories\JournalRepository;
|
||||
use App\Services\FinanceService;
|
||||
use App\Support\Money;
|
||||
use Log;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
/**
|
||||
* Process all of the daily expenses and charge them
|
||||
*/
|
||||
class RecurringFinanceService extends Service
|
||||
{
|
||||
private $financeSvc;
|
||||
private $journalRepo;
|
||||
|
||||
/**
|
||||
* RecurringFinanceService constructor.
|
||||
*
|
||||
* @param JournalRepository $journalRepo
|
||||
*/
|
||||
public function __construct(JournalRepository $journalRepo)
|
||||
public function __construct(JournalRepository $journalRepo, FinanceService $financeSvc)
|
||||
{
|
||||
$this->financeSvc = $financeSvc;
|
||||
$this->journalRepo = $journalRepo;
|
||||
}
|
||||
|
||||
@@ -87,10 +86,8 @@ class RecurringFinanceService extends Service
|
||||
/**
|
||||
* Run all of the daily expense/financials
|
||||
*
|
||||
* @param int $type
|
||||
* @param string $type
|
||||
*
|
||||
* @throws \UnexpectedValueException
|
||||
* @throws \InvalidArgumentException
|
||||
* @throws \Prettus\Validator\Exceptions\ValidatorException
|
||||
*/
|
||||
public function processExpenses($type = ExpenseType::DAILY): void
|
||||
@@ -101,7 +98,7 @@ class RecurringFinanceService extends Service
|
||||
if ($type === ExpenseType::DAILY) {
|
||||
$tag = 'expenses_daily';
|
||||
} elseif ($type === ExpenseType::MONTHLY) {
|
||||
$tag === 'expenses_monthly';
|
||||
$tag = 'expenses_monthly';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -122,7 +119,7 @@ class RecurringFinanceService extends Service
|
||||
];
|
||||
|
||||
$found = JournalTransaction::where($w)
|
||||
->whereDate('post_date', '=', \Carbon::now('UTC')->toDateString())
|
||||
->whereDate('post_date', '=', Carbon::now('UTC')->toDateString())
|
||||
->count(['id']);
|
||||
|
||||
if ($found > 0) {
|
||||
@@ -132,13 +129,11 @@ class RecurringFinanceService extends Service
|
||||
|
||||
[$memo, $ta_group] = $this->getMemoAndGroup($expense);
|
||||
|
||||
$this->journalRepo->post(
|
||||
$this->financeSvc->debitFromJournal(
|
||||
$journal,
|
||||
null,
|
||||
Money::createFromAmount($amount),
|
||||
$expense,
|
||||
$memo,
|
||||
null,
|
||||
$ta_group,
|
||||
$tag
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user