From ff2166e1c9ee6574927e02ae945b6cc40ba39cc4 Mon Sep 17 00:00:00 2001 From: Nafies Luthfi Date: Sun, 12 Nov 2017 21:41:58 +0800 Subject: [PATCH] Fix some scripts on report pages --- database/factories/PaymentFactory.php | 11 ++-- resources/views/reports/payments/daily.blade.php | 27 +++++----- resources/views/reports/payments/monthly.blade.php | 48 ++++++++---------- resources/views/reports/payments/yearly.blade.php | 58 +++++++++------------- tests/Unit/Models/PaymentTest.php | 18 +++---- 5 files changed, 73 insertions(+), 89 deletions(-) diff --git a/database/factories/PaymentFactory.php b/database/factories/PaymentFactory.php index a1cb02d..7f34824 100644 --- a/database/factories/PaymentFactory.php +++ b/database/factories/PaymentFactory.php @@ -15,7 +15,7 @@ $factory->define(Payment::class, function (Faker $faker) { }, 'amount' => 10000, 'in_out' => 1, - 'type_id' => rand(1, 3), + 'type_id' => 1, 'date' => $faker->dateTimeBetween('-1 year', '-1 month')->format('Y-m-d'), 'description' => $faker->paragraph, 'partner_type' => Customer::class, @@ -25,10 +25,15 @@ $factory->define(Payment::class, function (Faker $faker) { ]; }); +$factory->state(Payment::class, 'customer', function (Faker $faker) { + + return []; +}); + $factory->state(Payment::class, 'vendor', function (Faker $faker) { return [ - 'in_out' => 1, + 'in_out' => 0, 'type_id' => 1, 'partner_type' => Vendor::class, 'partner_id' => function () { @@ -40,7 +45,7 @@ $factory->state(Payment::class, 'vendor', function (Faker $faker) { $factory->state(Payment::class, 'fee', function (Faker $faker) { return [ - 'in_out' => 1, + 'in_out' => 0, 'type_id' => 1, 'partner_type' => User::class, 'partner_id' => function () { diff --git a/resources/views/reports/payments/daily.blade.php b/resources/views/reports/payments/daily.blade.php index c7c0cff..d820e9c 100755 --- a/resources/views/reports/payments/daily.blade.php +++ b/resources/views/reports/payments/daily.blade.php @@ -3,7 +3,7 @@ @section('title', 'Laporan Harian : ' . dateId($date)) @section('content') - + -

Laporan Harian : {{ dateId($date) }}

- -{!! Form::open(['method'=>'get','class'=>'form-inline well well-sm']) !!} -{!! Form::text('date', $date, ['class'=>'form-control','required','id'=>'date']) !!} -{!! Form::submit('Lihat Laporan', ['class'=>'btn btn-primary']) !!} -{!! link_to_route('reports.payments.daily', 'Hari Ini', [], ['class'=>'btn btn-default']) !!} -{!! link_to_route('reports.payments.monthly', 'Lihat Bulanan', ['month' => monthNumber($dt->month), 'year' => $dt->year], ['class'=>'btn btn-default']) !!} -{!! Form::close() !!} +{{ Form::open(['method' => 'get','class' => 'form-inline well well-sm']) }} +{{ Form::label('date', 'Laporan Harian per', ['class' => 'control-label']) }} +{{ Form::text('date', $date, ['class' => 'form-control','required','style' => 'width:100px']) }} +{{ Form::submit('Lihat Laporan', ['class' => 'btn btn-info btn-sm']) }} +{{ link_to_route('reports.payments.daily', 'Hari Ini', [], ['class' => 'btn btn-default btn-sm']) }} +{{ link_to_route('reports.payments.monthly', 'Lihat Bulanan', ['month' => monthNumber($dt->month), 'year' => $dt->year], ['class' => 'btn btn-default btn-sm']) }} +{{ Form::close() }} @@ -41,12 +40,12 @@ - in_out == 0 ? $total - $payment->amount : $total + $payment->amount?> + in_out == 0 ? $total - $payment->amount : $total + $payment->amount; ?> @empty - + @endforelse @@ -60,11 +59,11 @@ @endsection @section('ext_css') - {!! Html::style(url('assets/css/plugins/jquery.datetimepicker.css')) !!} + {{ Html::style(url('assets/css/plugins/jquery.datetimepicker.css')) }} @endsection @section('ext_js') - {!! Html::script(url('assets/js/plugins/jquery.datetimepicker.js')) !!} + {{ Html::script(url('assets/js/plugins/jquery.datetimepicker.js')) }} @endsection @section('script') diff --git a/resources/views/reports/payments/monthly.blade.php b/resources/views/reports/payments/monthly.blade.php index 6a63043..901484b 100755 --- a/resources/views/reports/payments/monthly.blade.php +++ b/resources/views/reports/payments/monthly.blade.php @@ -8,14 +8,14 @@
  • {{ $months[$month] }}
  • -{!! Form::open(['method' => 'get', 'class' => 'form-inline well well-sm']) !!} -{!! Form::label('month', 'Laporan Bulanan', ['class' => 'control-label']) !!} -{!! Form::select('month', $months, $month, ['class' => 'form-control']) !!} -{!! Form::select('year', $years, $year, ['class' => 'form-control']) !!} -{!! Form::submit('Lihat Laporan', ['class' => 'btn btn-info btn-sm']) !!} -{!! link_to_route('reports.payments.monthly', 'Bulan ini', [], ['class' => 'btn btn-default btn-sm']) !!} -{!! link_to_route('reports.payments.yearly', 'Lihat Tahunan', ['year' => $year], ['class' => 'btn btn-default btn-sm']) !!} -{!! Form::close() !!} +{{ Form::open(['method' => 'get', 'class' => 'form-inline well well-sm']) }} +{{ Form::label('month', 'Laporan Bulanan per', ['class' => 'control-label']) }} +{{ Form::select('month', $months, $month, ['class' => 'form-control']) }} +{{ Form::select('year', $years, $year, ['class' => 'form-control']) }} +{{ Form::submit('Lihat Laporan', ['class' => 'btn btn-info btn-sm']) }} +{{ link_to_route('reports.payments.monthly', 'Bulan ini', [], ['class' => 'btn btn-default btn-sm']) }} +{{ link_to_route('reports.payments.yearly', 'Lihat Tahunan', ['year' => $year], ['class' => 'btn btn-default btn-sm']) }} +{{ Form::close() }}

    Grafik Profit {{ $months[$month] }} {{ $year }}

    @@ -38,29 +38,21 @@
    - + @foreach(monthDateArray($year, $month) as $dateNumber) count : 0; - $cashin = $any ? $reports[$dateNumber]->cashin : 0; - $cashout = $any ? $reports[$dateNumber]->cashout : 0; $profit = $any ? $reports[$dateNumber]->profit : 0; + if ($any): ?> - - - + + + $dateNumber, 'value' => ($profit)]; ?> @endforeach @@ -92,12 +85,12 @@ @endsection @section('ext_css') - {!! Html::style(url('assets/css/plugins/morris.css')) !!} + {{ Html::style(url('assets/css/plugins/morris.css')) }} @endsection @section('ext_js') - {!! Html::script(url('assets/js/plugins/morris/raphael.min.js')) !!} - {!! Html::script(url('assets/js/plugins/morris/morris.min.js')) !!} + {{ Html::script(url('assets/js/plugins/morris/raphael.min.js')) }} + {{ Html::script(url('assets/js/plugins/morris/morris.min.js')) }} @endsection @section('script') @@ -111,6 +104,9 @@ labels: ['Profit Rp'], parseTime:false, xLabelAngle: 30, + goals: [0], + goalLineColors : ['red'], + smooth: false, }); })(); diff --git a/resources/views/reports/payments/yearly.blade.php b/resources/views/reports/payments/yearly.blade.php index 2531b63..2ac8641 100755 --- a/resources/views/reports/payments/yearly.blade.php +++ b/resources/views/reports/payments/yearly.blade.php @@ -8,13 +8,12 @@
  • Laporan Tahunan
  • -

    Laporan Tahunan : {{ $year }}

    - -{!! Form::open(['method'=>'get','class'=>'form-inline well well-sm']) !!} -{!! Form::select('year', $years, $year, ['class'=>'form-control']) !!} -{!! Form::submit('Lihat Laporan', ['class'=>'btn btn-info']) !!} -{!! link_to_route('reports.payments.yearly','Tahun ini',[],['class'=>'btn btn-default']) !!} -{!! Form::close() !!} +{{ Form::open(['method' => 'get', 'class' => 'form-inline well well-sm']) }} +{{ Form::label('year', 'Laporan Tahunan per', ['class' => 'control-label']) }} +{{ Form::select('year', $years, $year, ['class' => 'form-control']) }} +{{ Form::submit('Lihat Laporan', ['class' => 'btn btn-info btn-sm']) }} +{{ link_to_route('reports.payments.yearly', 'Tahun ini', [], ['class' => 'btn btn-default btn-sm']) }} +{{ Form::close() }}

    Grafik Profit {{ $year }}

    @@ -37,43 +36,33 @@
    - + @foreach(getMonths() as $monthNumber => $monthName) - count : 0; - $cashin = $any ? $reports[$monthNumber]->cashin : 0; - $cashout = $any ? $reports[$monthNumber]->cashout : 0; - $profit = $any ? $reports[$monthNumber]->profit : 0; - ?> + - - - - + + + + - monthId($monthNumber), 'value' => $profit]; - ?> + monthId($monthNumber), 'value' => $profit];?> @endforeach - + @@ -87,12 +76,12 @@ @endsection @section('ext_css') - {!! Html::style(url('assets/css/plugins/morris.css')) !!} + {{ Html::style(url('assets/css/plugins/morris.css')) }} @endsection @section('ext_js') - {!! Html::script(url('assets/js/plugins/morris/raphael.min.js')) !!} - {!! Html::script(url('assets/js/plugins/morris/morris.min.js')) !!} + {{ Html::script(url('assets/js/plugins/morris/raphael.min.js')) }} + {{ Html::script(url('assets/js/plugins/morris/morris.min.js')) }} @endsection @section('script') @@ -100,13 +89,14 @@ (function() { new Morris.Line({ element: 'yearly-chart', - data: {!! json_encode($cartData) !!}, + data: {!! collect($chartData)->toJson() !!}, xkey: 'month', ykeys: ['value'], - labels: ['Profit'], + labels: ['Profit Rp'], parseTime:false, goals: [0], goalLineColors : ['red'], + smooth: false, }); })(); diff --git a/tests/Unit/Models/PaymentTest.php b/tests/Unit/Models/PaymentTest.php index 0f9be49..ea596cd 100644 --- a/tests/Unit/Models/PaymentTest.php +++ b/tests/Unit/Models/PaymentTest.php @@ -14,29 +14,23 @@ class PaymentTest extends TestCase public function it_can_have_partner_relation_on_customer_model_for_income_payment() { $payment = factory(Payment::class)->create(); - $this->assertTrue( - $payment->partner instanceof Customer, - 'An income payment should have a App\Entities\Partners\Customer model as partner relation' - ); + $this->assertInstanceOf(Customer::class, $payment->partner); + + $payment = factory(Payment::class)->states('customer')->create(); + $this->assertInstanceOf(Customer::class, $payment->partner); } /** @test */ public function it_can_have_partner_relation_on_vendor_model_for_expanse_payment() { $payment = factory(Payment::class)->states('vendor')->create(); - $this->assertTrue( - $payment->partner instanceof Vendor, - 'An expanse payment can have a App\Entities\Partners\Vendor model as partner relation' - ); + $this->assertInstanceOf(Vendor::class, $payment->partner); } /** @test */ public function it_can_have_partner_relation_on_user_model_for_fee_payment() { $payment = factory(Payment::class)->states('fee')->create(); - $this->assertTrue( - $payment->partner instanceof User, - 'An expanse payment can have a App\Entities\Users\User model as partner relation' - ); + $this->assertInstanceOf(User::class, $payment->partner); } }
    {{ $payment->partner->name }} {{ $payment->description }} [{{ $payment->type() }}] - {!! link_to_route('payments.show','Lihat',[$payment->id],['title' => 'Lihat Detail Pembayaran','target' => '_blank','class'=>'btn btn-info btn-xs']) !!} + {{ link_to_route('payments.show','Lihat',[$payment->id],['title' => 'Lihat Detail Pembayaran','target' => '_blank','class' => 'btn btn-info btn-xs']) }}
    {{ trans('payment.not_found') }}
    {{ trans('payment.not_found') }}
    Pilihan
    {{ dateId($date = $year . '-' . $month . '-' . $dateNumber) }}{{ $count }}{{ formatRp($cashin) }}{{ formatRp($cashout) }}{{ $any ? $reports[$dateNumber]->count : 0 }}{{ formatRp($any ? $reports[$dateNumber]->cashin : 0) }}{{ formatRp($any ? $reports[$dateNumber]->cashout : 0) }} {{ formatRp($profit) }} - {!! link_to_route( + {{ link_to_route( 'reports.payments.daily', 'Lihat Harian', ['date' => $date], @@ -68,10 +60,11 @@ 'class' => 'btn btn-info btn-xs', 'title' => 'Lihat laporan harian ' . $date ] - ) !!} + ) }}
    Pilihan
    {{ monthId($monthNumber) }}{{ $count }}{{ formatRp($cashin) }}{{ formatRp($cashout) }}{{ formatRp($profit) }}{{ $any ? $reports[$monthNumber]->count : 0 }}{{ formatRp($any ? $reports[$monthNumber]->cashin : 0) }}{{ formatRp($any ? $reports[$monthNumber]->cashout : 0) }}{{ formatRp($profit = $any ? $reports[$monthNumber]->profit : 0) }} - {!! link_to_route( + {{ link_to_route( 'reports.payments.monthly', 'Lihat Bulanan', ['month' => $monthNumber, 'year' => $year], [ - 'class'=>'btn btn-info btn-xs', - 'title'=>'Lihat laporan bulanan ' . monthId($monthNumber) + 'class' => 'btn btn-info btn-xs', + 'title' => 'Lihat laporan bulanan ' . monthId($monthNumber) ] - ) !!} + ) }}
    Jumlah{{ trans('app.total') }} {{ $reports->sum('count') }} {{ formatRp($reports->sum('cashin')) }} {{ formatRp($reports->sum('cashout')) }}