Cleanup the transaction memos

This commit is contained in:
Nabeel Shahzad
2018-03-06 06:17:45 -06:00
parent 9d3953f3ac
commit 453ca5b180
8 changed files with 53 additions and 34 deletions

View File

@@ -6,14 +6,10 @@ use Illuminate\Support\Facades\Schema;
class CreateExpensesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('expenses', function (Blueprint $table) {
$table->increments('id');
$table->unsignedInteger('airline_id')->nullable();
@@ -27,17 +23,13 @@ class CreateExpensesTable extends Migration
# EG, the airports has an internal expense for gate costs
$table->string('ref_class')->nullable();
$table->string('ref_class_id', 36)->nullable();
$table->index(['ref_class', 'ref_class_id']);
$table->timestamps();
$table->index(['ref_class', 'ref_class_id']);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('expenses');

View File

@@ -15,17 +15,17 @@ class CreateJournalTransactionsTable extends Migration
{
Schema::create('journal_transactions', function (Blueprint $table) {
$table->char('id', 36)->unique();
$table->char('transaction_group', 36)->nullable();
$table->string('transaction_group')->nullable();
$table->integer('journal_id');
$table->unsignedBigInteger('credit')->nullable();
$table->unsignedBigInteger('debit')->nullable();
$table->char('currency', 5);
$table->text('memo')->nullable();
$table->char('ref_class', 32)->nullable();
$table->string('tags')->nullable();
$table->string('ref_class', 50)->nullable();
$table->string('ref_class_id', 36)->nullable();
$table->timestamps();
$table->dateTime('post_date');
$table->softDeletes();
$table->primary('id');
$table->index('journal_id');

View File

@@ -23,6 +23,7 @@ class FinanceController extends BaseController
$journalRepo;
/**
* @param AirlineRepository $airlineRepo
* @param PirepFinanceService $financeSvc
* @param JournalRepository $journalRepo
*/

View File

@@ -145,7 +145,7 @@ class PirepFinanceService extends BaseService
# TODO: Modify the amount
}
Log::info('Finance: PIREP: ' . $pirep->id . ', expense:', $expense->toArray());
Log::info('Finance: PIREP: '.$pirep->id.', expense:', $expense->toArray());
# Get the transaction group name from the ref_class name
# This way it can be more dynamic and don't have to add special
@@ -156,13 +156,22 @@ class PirepFinanceService extends BaseService
$transaction_group = end($ref);
}
# Form the memo, with some specific ones depending on the group
if($transaction_group === 'Airport') {
$memo = "Airport Expense: {$expense->name} ({$expense->ref_class_id})";
$transaction_group = "Airport: {$expense->ref_class_id}";
} else {
$memo = 'Expense: ' . $expense->name;
$transaction_group = "Expense: {$expense->name}";
}
$debit = Money::createFromAmount($expense->amount);
$this->journalRepo->post(
$pirep->airline->journal,
null,
$debit,
$pirep,
'Expense: ' . $expense->name,
$memo,
null,
$transaction_group
);