diff --git a/app/Http/Controllers/Invoices/DuplicationController.php b/app/Http/Controllers/Invoices/DuplicationController.php new file mode 100644 index 0000000..4469ec0 --- /dev/null +++ b/app/Http/Controllers/Invoices/DuplicationController.php @@ -0,0 +1,35 @@ +draftCollection = new InvoiceDraftCollection(); + } + + public function store(Invoice $invoice) + { + $draft = new InvoiceDraft(); + $this->draftCollection->add($draft); + + foreach ($invoice->items as $existingItem) { + $item = new Item(['description' => $existingItem['description'], 'amount' => $existingItem['amount']]); + $this->draftCollection->addItemToDraft($draft->draftKey, $item); + } + $draft->date = today()->format('Y-m-d'); + $draft->projectId = $invoice->project_id; + $draft->notes = $invoice->notes; + + return redirect()->route('invoice-drafts.show', $draft->draftKey); + } +} diff --git a/resources/lang/de/invoice.php b/resources/lang/de/invoice.php index 326aa29..9c262e9 100644 --- a/resources/lang/de/invoice.php +++ b/resources/lang/de/invoice.php @@ -22,6 +22,7 @@ return [ 'save' => 'Rechnung speichern', 'created' => 'Neue Rechnung wurde erstellt.', 'show' => 'Rechnungsdetails', + 'duplicate' => 'Duplicate Invoice', 'edit' => 'Rechnung bearbeiten', 'update' => 'Rechnung aktualisieren', 'updated' => 'Rechnungsdetails wurden aktualisiert.', diff --git a/resources/lang/en/invoice.php b/resources/lang/en/invoice.php index af86676..504d8d8 100644 --- a/resources/lang/en/invoice.php +++ b/resources/lang/en/invoice.php @@ -22,6 +22,7 @@ return [ 'save' => 'Save Invoice', 'created' => 'New Invoice has been created.', 'show' => 'View Invoice Detail', + 'duplicate' => 'Duplicate Invoice', 'edit' => 'Edit Invoice', 'update' => 'Update Invoice', 'updated' => 'Invoice data has been updated.', diff --git a/resources/lang/id/invoice.php b/resources/lang/id/invoice.php index a73f957..4cb5211 100644 --- a/resources/lang/id/invoice.php +++ b/resources/lang/id/invoice.php @@ -22,6 +22,7 @@ return [ 'save' => 'Simpan Invoice', 'created' => 'Input Invoice baru telah berhasil.', 'show' => 'Lihat Detail Invoice', + 'duplicate' => 'Duplikat Invoice', 'edit' => 'Edit Invoice', 'update' => 'Update Invoice', 'updated' => 'Update data Invoice telah berhasil.', diff --git a/resources/views/invoices/show.blade.php b/resources/views/invoices/show.blade.php index 6bb50c2..d79a8f3 100644 --- a/resources/views/invoices/show.blade.php +++ b/resources/views/invoices/show.blade.php @@ -5,6 +5,7 @@ @section('content')

+ {!! FormField::formButton(['route' => ['invoices.duplication.store', $invoice]], __('invoice.duplicate'), ['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']) }} diff --git a/routes/web/invoices.php b/routes/web/invoices.php index f8d6b82..e4e831f 100644 --- a/routes/web/invoices.php +++ b/routes/web/invoices.php @@ -28,4 +28,9 @@ Route::group(['middleware' => ['web', 'role:admin'], 'namespace' => 'Invoices'], Route::post('invoices/{invoice}/items', ['as' => 'invoices.items.store', 'uses' => 'ItemsController@store']); Route::patch('invoices/{invoice}/items', ['as' => 'invoices.items.update', 'uses' => 'ItemsController@update']); Route::delete('invoices/{invoice}/items', ['as' => 'invoices.items.destroy', 'uses' => 'ItemsController@destroy']); + + /* + * Invoice Duplication Route + */ + Route::post('invoices/{invoice}/duplicate', ['as' => 'invoices.duplication.store', 'uses' => 'DuplicationController@store']); }); diff --git a/tests/Feature/Invoices/InvoiceDuplicateTest.php b/tests/Feature/Invoices/InvoiceDuplicateTest.php new file mode 100644 index 0000000..b518e82 --- /dev/null +++ b/tests/Feature/Invoices/InvoiceDuplicateTest.php @@ -0,0 +1,39 @@ + + */ +class InvoiceDuplicateTest extends TestCase +{ + /** @test */ + public function user_can_create_invoice_draft_by_duplicate_existing_invoice() + { + $this->adminUserSigningIn(); + $invoice = factory(Invoice::class)->create([ + 'items' => [ + [ + 'description' => 'Item 1 description', + 'amount' => 100000, + ], + [ + 'description' => 'Item 1 description', + 'amount' => 150000, + ], + ], + ]); + $this->visit(route('invoices.show', $invoice)); + + $this->press(trans('invoice.duplicate')); + $invoiceDrafts = new InvoiceDraftCollection(); + $draft = $invoiceDrafts->content()->last(); + $this->seePageIs(route('invoice-drafts.show', $draft->draftKey)); + } +}