Browse Source

Add invoice delete feature with deletation confirm page

Restructure invoice detail page to invoice detail view partial
pull/3/head
Nafies Luthfi 8 years ago
parent
commit
6a65b6aa80
  1. 16
      app/Http/Controllers/Invoices/InvoicesController.php
  2. 37
      resources/views/invoices/edit.blade.php
  3. 12
      resources/views/invoices/partials/detail.blade.php
  4. 13
      resources/views/invoices/show.blade.php
  5. 30
      tests/Feature/Invoices/ManageInvoicesTest.php

16
app/Http/Controllers/Invoices/InvoicesController.php

@ -48,6 +48,22 @@ class InvoicesController extends Controller
return redirect()->route('invoices.show', $invoice);
}
public function destroy(Invoice $invoice)
{
$this->validate(request(), [
'invoice_id' => 'required',
]);
if (request('invoice_id') == $invoice->id && $invoice->delete()) {
flash(trans('invoice.deleted'), 'warning');
return redirect()->route('projects.invoices', $invoice->project_id);
}
flash(trans('invoice.undeleted'), 'danger');
return back();
}
public function pdf(Invoice $invoice)
{
return view('invoices.pdf', compact('invoice'));

37
resources/views/invoices/edit.blade.php

@ -3,6 +3,40 @@
@section('title', $invoice->number . ' - ' . trans('invoice.edit'))
@section('content')
@if (request('action') == 'delete')
<h1 class="page-header">
<div class="pull-right">
{{ link_to_route('invoices.edit', trans('app.back'), $invoice, ['class' => 'btn btn-default']) }}
</div>
{{ $invoice->number }} <small>{{ trans('invoice.delete') }}</small>
</h1>
<div class="row">
<div class="col-md-6 col-lg-offset-3">
<div class="panel panel-default">
<div class="panel-heading"><h3 class="panel-title">{{ trans('invoice.delete') }}</h3></div>
@include('invoices.partials.detail')
<div class="panel-body">
{{ trans('invoice.delete_confirm') }}
</div>
<div class="panel-footer">
{{ link_to_route('invoices.edit', trans('app.back'), $invoice, ['class' => 'btn btn-default']) }}
{!! FormField::delete(
['route' => ['invoices.destroy',$invoice->number], 'onsubmit' => trans('invoice.delete_confirm')],
trans('invoice.delete'),
['class'=>'btn btn-danger'],
[
'invoice_id' => $invoice->id,
]
) !!}
</div>
</div>
</div>
</div>
@else
<h1 class="page-header">
<div class="pull-right">
{{ link_to_route('invoices.show', trans('invoice.back_to_show'), $invoice, ['class' => 'btn btn-default']) }}
@ -35,6 +69,9 @@
</div>
</div>
{{ link_to_route('invoices.edit', trans('invoice.delete'), [$invoice, 'action' => 'delete'], ['class'=>'btn btn-danger']) }}
@endif
@endsection
@section('ext_css')

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

@ -0,0 +1,12 @@
<table class="table">
<tbody>
<tr><th>{{ trans('invoice.number') }}</th><td class="text-primary strong">{{ $invoice->number }}</td></tr>
<tr><th>{{ trans('invoice.date') }}</th><td>{{ $invoice->date }}</td></tr>
<tr><th>{{ trans('invoice.due_date') }}</th><td>{{ $invoice->due_date }}</td></tr>
<tr><th>{{ trans('invoice.project') }}</th><td>{{ $invoice->project->nameLink() }}</td></tr>
<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>
</tbody>
</table>

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

@ -14,18 +14,7 @@
<div class="col-sm-4">
<div class="panel panel-default">
<div class="panel-heading"><h3 class="panel-title">{{ trans('invoice.detail') }}</h3></div>
<table class="table">
<tbody>
<tr><th>{{ trans('invoice.number') }}</th><td class="text-primary strong">{{ $invoice->number }}</td></tr>
<tr><th>{{ trans('invoice.date') }}</th><td>{{ $invoice->date }}</td></tr>
<tr><th>{{ trans('invoice.due_date') }}</th><td>{{ $invoice->due_date }}</td></tr>
<tr><th>{{ trans('invoice.project') }}</th><td>{{ $invoice->project->nameLink() }}</td></tr>
<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>
</tbody>
</table>
@include('invoices.partials.detail')
</div>
</div>
<div class="col-sm-8">

30
tests/Feature/Invoices/ManageInvoicesTest.php

@ -53,7 +53,7 @@ class ManageInvoicesTest extends TestCase
}
/** @test */
public function user_can_add_invoice_item()
public function user_can_add_invoice_item_on_invoice_edit_page()
{
$this->adminUserSigningIn();
$invoice = factory(Invoice::class)->create();
@ -84,7 +84,7 @@ class ManageInvoicesTest extends TestCase
}
/** @test */
public function user_can_update_invoice_item()
public function user_can_update_invoice_item_on_invoice_edit_page()
{
$this->adminUserSigningIn();
@ -115,7 +115,7 @@ class ManageInvoicesTest extends TestCase
}
/** @test */
public function user_can_remove_invoice_item()
public function user_can_remove_invoice_item_on_invoice_edit_page()
{
$this->adminUserSigningIn();
@ -142,4 +142,28 @@ class ManageInvoicesTest extends TestCase
'amount' => 1111,
]);
}
/** @test */
public function user_can_delete_an_invoice()
{
$this->adminUserSigningIn();
$invoice = factory(Invoice::class)->create();
$this->visit(route('invoices.edit', $invoice));
$this->click(trans('invoice.delete'));
$this->seePageIs(route('invoices.edit', [$invoice, 'action' => 'delete']));
$this->submitForm(trans('invoice.delete'), [
'invoice_id' => $invoice->id,
]);
$this->see(trans('invoice.deleted'));
$this->seePageIs(route('projects.invoices', $invoice->project_id));
$this->dontSeeInDatabase('invoices', [
'id' => $invoice->id,
]);
}
}
Loading…
Cancel
Save