Browse Source

Add draft invoice entry from project invoices page

pull/3/head
Nafies Luthfi 8 years ago
parent
commit
e3944eec00
  1. 10
      app/Http/Controllers/Invoices/DraftsController.php
  2. 3
      resources/lang/id/invoice.php
  3. 1
      resources/lang/id/project.php
  4. 33
      resources/views/invoice-drafts/index.blade.php
  5. 21
      resources/views/invoice-drafts/partials/draft-confirm.blade.php
  6. 25
      resources/views/invoice-drafts/partials/form-draft-detail.blade.php
  7. 2
      resources/views/invoice-drafts/partials/invoice-draft-tabs.blade.php
  8. 2
      resources/views/invoices/partials/detail.blade.php
  9. 5
      resources/views/invoices/show.blade.php
  10. 4
      resources/views/projects/invoices.blade.php
  11. 25
      tests/Feature/Invoices/InvoiceEntryTest.php

10
app/Http/Controllers/Invoices/DraftsController.php

@ -46,7 +46,13 @@ class DraftsController extends Controller
public function create(Request $request)
{
$this->draftCollection->add(new InvoiceDraft());
$draft = new InvoiceDraft();
if ($request->has('project_id')) {
$draft->projectId = $request->get('project_id');
}
$this->draftCollection->add($draft);
return redirect()->route('invoice-drafts.show', $this->draftCollection->content()->last()->draftKey);
}
@ -137,8 +143,6 @@ class DraftsController extends Controller
return redirect()->route('invoice-drafts.show', [$draftKey]);
}
flash(trans('invoice.confirm_instruction'), 'warning')->important();
return redirect()->route('invoice-drafts.show', [$draftKey, 'action' => 'confirm']);
}

3
resources/lang/id/invoice.php

@ -10,6 +10,7 @@ return [
'empty' => 'Belum ada Invoice',
'back_to_show' => 'Kembali ke Detail Invoice',
'back_to_index' => 'Kembali ke daftar Invoice',
'back_to_project' => 'Kembali ke Invoice Project',
'draft_list' => 'List Draft Invoice',
'draft_list_empty' => 'Draft Invoice kosong.',
'draft_not_found' => 'Draft Invoice tidak ditemukan.',
@ -34,7 +35,7 @@ return [
'item_added' => 'Item berhasil ditambahkan.',
'item_updated' => 'Item berhasil diupdate.',
'item_removed' => 'Item berhasil dihapus.',
'confirm_instruction' => 'Silakan periksa rincian di bawah ini, jika belum sesuai, silakan klik kembali.',
'confirm_instruction' => 'Silakan periksa rincian di bawah ini, jika belum sesuai, silakan klik :back_link.',
// Attributes
'number' => 'No. Invoice',

1
resources/lang/id/project.php

@ -10,6 +10,7 @@ return [
'search' => 'Cari Project',
'found' => 'Project ditemukan',
'not_found' => 'Project tidak ditemukan',
'select' => 'Pilih Project',
'empty' => 'Belum ada Project',
'back_to_index' => 'Kembali ke daftar Project',

33
resources/views/invoice-drafts/index.blade.php

@ -34,4 +34,35 @@
'style' => 'padding:0px',
]) !!}
@endif
@endsection
@endsection
@section('ext_css')
{!! Html::style(url('assets/css/plugins/jquery.datetimepicker.css')) !!}
{!! Html::style(url('assets/css/plugins/select2.min.css')) !!}
<style>
.form-control.select2-hidden-accessible {
width: 80%;
}
</style>
@endsection
@section('ext_js')
{!! Html::script(url('assets/js/plugins/jquery.datetimepicker.js')) !!}
{!! Html::script(url('assets/js/plugins/select2.min.js')) !!}
@endsection
@section('script')
<script>
(function() {
$('#date,#due_date').datetimepicker({
timepicker:false,
format:'Y-m-d',
closeOnDateSelect: true,
scrollInput: false
});
$('#project_id').select2({
placeholder: '-- {{ trans('project.select') }} --'
});
})();
</script>
@endsection

21
resources/views/invoice-drafts/partials/draft-confirm.blade.php

@ -1,16 +1,25 @@
<div class="row" style="margin-top: 10px">
<div class="alert alert-warning">
{!! trans('invoice.confirm_instruction', [
'back_link' => link_to_route('invoice-drafts.show', trans('app.back'), $draft->draftKey)
]) !!}
</div>
<div class="row">
<div class="col-md-4">
<div class="panel panel-default">
<div class="panel-heading"><h3 class="panel-title">{{ trans('invoice.detail') }}</h3></div>
@php
$project = App\Entities\Projects\Project::findOrFail($draft->projectId);
@endphp
<table class="table">
<tbody>
<tr><td>{{ trans('invoice.project') }}</td><td>{{ $project->name }}</td></tr>
<tr><td>{{ trans('customer.customer') }}</td><td>{{ $project->customer->name }}</td></tr>
<tr><td>{{ trans('invoice.date') }}</td><td>{{ $draft->date }}</td></tr>
<tr><td>{{ trans('invoice.due_date') }}</td><td>{{ $draft->dueDate }}</td></tr>
<tr>
<td>{{ trans('invoice.project') }}</td>
<td>
{{ App\Entities\Projects\Project::findOrFail($draft->projectId)->name }}
</td>
<td>{{ trans('invoice.total') }}</td>
<th class="text-right lead">{{ formatRp($draft->getTotal()) }}</th>
</tr>
<tr><td>{{ trans('invoice.total') }}</td><th class="text-right">{{ formatRp($draft->getTotal()) }}</th></tr>
<tr><td>{{ trans('invoice.notes') }}</td><td>{{ $draft->notes }}</td></tr>
</tbody>
</table>

25
resources/views/invoice-drafts/partials/form-draft-detail.blade.php

@ -2,14 +2,35 @@
<div class="panel-heading"><h3 class="panel-title">{{ trans('invoice.detail') }}</h3></div>
{{ Form::open(['route' => ['invoice-drafts.draft-proccess', $draft->draftKey], 'method' => 'patch']) }}
<div class="panel-body">
@php
$project = App\Entities\Projects\Project::find($draft->projectId);
@endphp
@if (!is_null($project))
{!! FormField::textDisplay(trans('project.project'), $project->name) !!}
{!! FormField::textDisplay(trans('project.customer'), $project->customer->name) !!}
{{ Form::hidden('project_id', $project->id) }}
@else
{!! FormField::select('project_id', $projects, [
'label' => trans('invoice.project'),
'value' => $draft->projectId,
'required' => true,
]) !!}
@endif
<div class="row">
<div class="col-md-6">{!! FormField::text('date', ['label' => trans('invoice.date')]) !!}</div>
<div class="col-md-6">{!! FormField::text('due_date', ['label' => trans('invoice.due_date')]) !!}</div>
<div class="col-md-6">
{!! FormField::text('date', [
'placeholder' => 'yyyy-mm-dd',
'label' => trans('invoice.date'),
'value' => $draft->date,
]) !!}
</div>
<div class="col-md-6">
{!! FormField::text('due_date', [
'placeholder' => 'yyyy-mm-dd',
'label' => trans('invoice.due_date'),
'value' => $draft->dueDate,
]) !!}
</div>
</div>
{!! FormField::textarea('notes', ['label' => trans('invoice.notes'), 'value' => $draft->notes]) !!}
</div>

2
resources/views/invoice-drafts/partials/invoice-draft-tabs.blade.php

@ -1,5 +1,5 @@
<?php use Facades\App\Services\InvoiceDrafts\InvoiceDraftCollection;?>
<ul class="nav nav-tabs transaction-draft-tabs">
<ul class="nav nav-tabs transaction-draft-tabs" style="margin-bottom: 15px">
@foreach(InvoiceDraftCollection::content() as $key => $content)
<?php $active = ($draft->draftKey == $key) ? 'class=active' : ''?>
<li {{ $active }} role="presentation">

2
resources/views/invoices/partials/detail.blade.php

@ -7,6 +7,6 @@
<tr><th>{{ trans('invoice.customer') }}</th><td>{{ $invoice->project->customer->nameLink() }}</td></tr>
<tr><th>{{ trans('invoice.items_count') }}</th><td>{{ $invoice->items_count }}</td></tr>
<tr><th>{{ trans('invoice.creator') }}</th><td>{{ $invoice->creator->name }}</td></tr>
<tr><th>{{ trans('invoice.amount') }}</th><td class="text-right strong">{{ formatRp($invoice->amount) }}</td></tr>
<tr><th>{{ trans('invoice.amount') }}</th><td class="text-right lead">{{ formatRp($invoice->amount) }}</td></tr>
</tbody>
</table>

5
resources/views/invoices/show.blade.php

@ -5,8 +5,9 @@
@section('content')
<h1 class="page-header">
<div class="pull-right">
{{ link_to_route('invoices.edit', trans('invoice.edit'), [$invoice->number], ['class' => 'btn btn-warning']) }}
{{ link_to_route('invoices.pdf', trans('invoice.print'), [$invoice->number], ['class' => 'btn btn-default']) }}
{{ link_to_route('invoices.edit', trans('invoice.edit'), [$invoice], ['class' => 'btn btn-warning']) }}
{{ link_to_route('invoices.pdf', trans('invoice.print'), [$invoice], ['class' => 'btn btn-default']) }}
{{ link_to_route('projects.invoices', trans('invoice.back_to_project'), [$invoice->project_id], ['class' => 'btn btn-default']) }}
</div>
{{ $invoice->number }} <small>{{ trans('invoice.detail') }}</small>
</h1>

4
resources/views/projects/invoices.blade.php

@ -11,6 +11,8 @@
'class' => 'btn btn-success',
'name' => 'create-invoice-draft',
'id' => 'invoice-draft-create-button'
], [
'project_id' => $project->id
]) !!}
</div>
{{ $project->name }} <small>{{ trans('project.invoices') }}</small>
@ -34,7 +36,7 @@
@forelse($project->invoices as $key => $invoice)
<tr>
<td class="text-center">{{ 1 + $key }}</td>
<td class="text-center">{{ $invoice->number }}</td>
<td class="text-center">{{ $invoice->numberLink() }}</td>
<td class="text-center">{{ $invoice->date }}</td>
<td class="text-center">{{ $invoice->due_date }}</td>
<td>{{ $project->customer->nameLink() }}</td>

25
tests/Feature/Invoices/InvoiceEntryTest.php

@ -43,6 +43,25 @@ class InvoiceEntryTest extends TestCase
}
/** @test */
public function user_can_create_invoice_draft_from_project_invoices_page()
{
$this->adminUserSigningIn();
$project = factory(Project::class)->create();
$this->visit(route('projects.invoices', $project));
$this->press(trans('invoice.create'));
$cart = new InvoiceDraftCollection();
$draft = $cart->content()->last();
$this->assertEquals($draft->projectId, $project->id);
$this->seePageIs(route('invoice-drafts.show', $draft->draftKey));
$this->see($project->name);
$this->see($project->customer->name);
}
/** @test */
public function user_can_add_item_to_invoice_draft()
{
$this->adminUserSigningIn();
@ -145,8 +164,12 @@ class InvoiceEntryTest extends TestCase
$this->seePageIs(route('invoice-drafts.show', [$draft->draftKey, 'action' => 'confirm']));
$this->see(trans('invoice.confirm_instruction'));
$this->see(trans('invoice.confirm_instruction', [
'back_link' => link_to_route('invoice-drafts.show', trans('app.back'), $draft->draftKey),
]));
$this->see($project->name);
$this->see($project->customer->name);
$this->see($draft->notes);
$this->see(formatRp(3000));
$this->seeElement('input', ['id' => 'save-invoice-draft']);

Loading…
Cancel
Save