From 453ca5b180fa07856c945952f563bfdfa0c95e78 Mon Sep 17 00:00:00 2001 From: Nabeel Shahzad Date: Tue, 6 Mar 2018 06:17:45 -0600 Subject: [PATCH] Cleanup the transaction memos --- ...018_02_26_185121_create_expenses_table.php | 14 +++---------- ...1807_create_journal_transactions_table.php | 6 +++--- .../Controllers/Admin/FinanceController.php | 1 + app/Services/Finance/PirepFinanceService.php | 13 ++++++++++-- config/cron.php | 8 +++++++ .../views/admin/finances/table.blade.php | 18 +++++++++------- .../views/admin/pireps/scripts.blade.php | 21 ++++++++++++------- .../views/admin/pireps/transactions.blade.php | 6 ++++-- 8 files changed, 53 insertions(+), 34 deletions(-) create mode 100644 config/cron.php diff --git a/app/Database/migrations/2018_02_26_185121_create_expenses_table.php b/app/Database/migrations/2018_02_26_185121_create_expenses_table.php index 1a6b58c2..3628407a 100644 --- a/app/Database/migrations/2018_02_26_185121_create_expenses_table.php +++ b/app/Database/migrations/2018_02_26_185121_create_expenses_table.php @@ -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'); diff --git a/app/Database/migrations/2018_02_28_231807_create_journal_transactions_table.php b/app/Database/migrations/2018_02_28_231807_create_journal_transactions_table.php index 33409ee4..5588a2cc 100644 --- a/app/Database/migrations/2018_02_28_231807_create_journal_transactions_table.php +++ b/app/Database/migrations/2018_02_28_231807_create_journal_transactions_table.php @@ -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'); diff --git a/app/Http/Controllers/Admin/FinanceController.php b/app/Http/Controllers/Admin/FinanceController.php index 2a52c057..1628888e 100644 --- a/app/Http/Controllers/Admin/FinanceController.php +++ b/app/Http/Controllers/Admin/FinanceController.php @@ -23,6 +23,7 @@ class FinanceController extends BaseController $journalRepo; /** + * @param AirlineRepository $airlineRepo * @param PirepFinanceService $financeSvc * @param JournalRepository $journalRepo */ diff --git a/app/Services/Finance/PirepFinanceService.php b/app/Services/Finance/PirepFinanceService.php index ff0323eb..93ac067d 100644 --- a/app/Services/Finance/PirepFinanceService.php +++ b/app/Services/Finance/PirepFinanceService.php @@ -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 ); diff --git a/config/cron.php b/config/cron.php new file mode 100644 index 00000000..02f408e7 --- /dev/null +++ b/config/cron.php @@ -0,0 +1,8 @@ + 'UTC', +]; diff --git a/resources/views/admin/finances/table.blade.php b/resources/views/admin/finances/table.blade.php index 00e560bd..b31a4f83 100644 --- a/resources/views/admin/finances/table.blade.php +++ b/resources/views/admin/finances/table.blade.php @@ -1,9 +1,13 @@ @foreach($transaction_groups as $group) -

{!! $group['airline']->icao !!} - {!! $group['airline']->name !!}

+

{!! $group['airline']->icao !!} - {!! $group['airline']->name !!}

+ + -
@@ -18,15 +22,11 @@ @@ -39,14 +39,16 @@ {!! $group['credits'] !!} {{-- final total --}} - + diff --git a/resources/views/admin/pireps/scripts.blade.php b/resources/views/admin/pireps/scripts.blade.php index 90deee67..2d94d9ee 100644 --- a/resources/views/admin/pireps/scripts.blade.php +++ b/resources/views/admin/pireps/scripts.blade.php @@ -71,14 +71,14 @@ $(document).ready(() => { }); $(document).on('submit', 'form.pirep_submit_status', (event) => { - console.log(event); - event.preventDefault(); const values = { - pirep_id: $(this).attr('pirep_id'), - new_status: $(this).attr('new_status') + pirep_id: $(event.currentTarget).attr('pirep_id'), + new_status: $(event.currentTarget).attr('new_status') }; + console.log('change status', values); + changeStatus(values, (data) => { const destContainer = '#pirep_' + values.pirep_id + '_actionbar'; $(destContainer).html(data); @@ -87,10 +87,15 @@ $(document).ready(() => { $(document).on('submit', 'form.pirep_change_status', (event) => { event.preventDefault(); - changeStatus({ - pirep_id: $(this).attr('pirep_id'), - new_status: $(this).attr('new_status') - }, (data) => { + + const values = { + pirep_id: $(event.currentTarget).attr('pirep_id'), + new_status: $(event.currentTarget).attr('new_status') + }; + + console.log('change status', values); + + changeStatus(values, (data) => { location.reload(); }); }); diff --git a/resources/views/admin/pireps/transactions.blade.php b/resources/views/admin/pireps/transactions.blade.php index 0c0d5162..d82052fa 100644 --- a/resources/views/admin/pireps/transactions.blade.php +++ b/resources/views/admin/pireps/transactions.blade.php @@ -25,14 +25,16 @@ {!! $journal['credits'] !!} {{-- final total --}} - +
Expenses Credit @if($ta->sum_credits) {!! money($ta->sum_credits, $ta->currency) !!} - @else - - @endif @if($ta->sum_debits) {!! money($ta->sum_debits, $ta->currency) !!} - @else - - @endif
- ({!! $group['debits'] !!}) + {!! $group['debits'] !!}
Total + Total + {!! $group['credits']->subtract($group['debits']) !!} - ({!! $journal['debits'] !!}) + {!! $journal['debits'] !!}
Total + Total + {!! $journal['credits']->subtract($journal['debits']) !!}