diff --git a/app/Cart/Item.php b/app/Cart/Item.php index b49dbfc..05dbf9c 100644 --- a/app/Cart/Item.php +++ b/app/Cart/Item.php @@ -20,11 +20,11 @@ class Item public function __construct(Product $product, $qty) { - $this->id = $product->id; - $this->name = $product->name; - $this->product = $product; - $this->qty = $qty; - $this->price = $product->getPrice(); + $this->id = $product->id; + $this->name = $product->name; + $this->product = $product; + $this->qty = $qty; + $this->price = $product->getPrice(); $this->subtotal = $product->getPrice() * $qty; } diff --git a/app/Cart/TransactionDraft.php b/app/Cart/TransactionDraft.php index 4600078..76fa37d 100644 --- a/app/Cart/TransactionDraft.php +++ b/app/Cart/TransactionDraft.php @@ -105,7 +105,7 @@ abstract class TransactionDraft public function store() { - $transaction = new Transaction; + $transaction = new Transaction(); $transaction->invoice_no = $this->getNewInvoiceNo(); $transaction->items = $this->getItemsArray(); $transaction->customer = $this->customer; @@ -123,16 +123,16 @@ abstract class TransactionDraft { $prefix = date('ym'); - $lastTransaction = Transaction::orderBy('invoice_no','desc')->first(); + $lastTransaction = Transaction::orderBy('invoice_no', 'desc')->first(); - if (! is_null($lastTransaction)) { + if (!is_null($lastTransaction)) { $lastInvoiceNo = $lastTransaction->invoice_no; if (substr($lastInvoiceNo, 0, 4) == $prefix) { return ++$lastInvoiceNo; } } - return $prefix . '0001'; + return $prefix.'0001'; } protected function getItemsArray() @@ -140,13 +140,13 @@ abstract class TransactionDraft $items = []; foreach ($this->items as $item) { $items[] = [ - 'id' => $item->product->id, - 'name' => $item->name, - 'price' => $item->price, - 'qty' => $item->qty, - 'item_discount' => $item->item_discount, + 'id' => $item->product->id, + 'name' => $item->name, + 'price' => $item->price, + 'qty' => $item->qty, + 'item_discount' => $item->item_discount, 'item_discount_subtotal' => $item->item_discount_subtotal, - 'subtotal' => $item->subtotal, + 'subtotal' => $item->subtotal, ]; } diff --git a/app/Helpers/helpers.php b/app/Helpers/helpers.php index fb23b11..6b82167 100755 --- a/app/Helpers/helpers.php +++ b/app/Helpers/helpers.php @@ -15,16 +15,19 @@ function formatRp($number) } /** - * Overide Laravel Collective link_to_route helper function - * @param string $name Name of route - * @param string $title Text that displayed on view - * @param array $parameters URL Parameter - * @param array $attributes The anchor tag atributes + * Overide Laravel Collective link_to_route helper function. + * + * @param string $name Name of route + * @param string $title Text that displayed on view + * @param array $parameters URL Parameter + * @param array $attributes The anchor tag atributes */ function html_link_to_route($name, $title = null, $parameters = [], $attributes = []) { - if (array_key_exists('icon', $attributes)) - $title = ' ' . $title; + if (array_key_exists('icon', $attributes)) { + $title = ' '.$title; + } return app('html')->decode(link_to_route($name, $title, $parameters, $attributes)); + } \ No newline at end of file diff --git a/app/Http/Controllers/CartController.php b/app/Http/Controllers/CartController.php index f59011c..4e45fe6 100644 --- a/app/Http/Controllers/CartController.php +++ b/app/Http/Controllers/CartController.php @@ -89,8 +89,9 @@ class CartController extends Controller { $this->cart->removeDraft($request->draft_key); - if ($this->cart->isEmpty()) + if ($this->cart->isEmpty()) { return redirect()->route('cart.index'); + } $lastDraft = $this->cart->content()->last(); return redirect()->route('cart.show', $lastDraft->draftKey); @@ -107,12 +108,12 @@ class CartController extends Controller public function proccess(Request $request, $draftKey) { $this->validate($request, [ - 'customer.name' => 'required|string|max:30', + 'customer.name' => 'required|string|max:30', 'customer.phone' => 'nullable|string|max:20', - 'payment' => 'required|numeric', - 'notes' => 'nullable|string|max:100', + 'payment' => 'required|numeric', + 'notes' => 'nullable|string|max:100', ]); - $draft = $this->cart->updateDraftAttributes($draftKey, $request->only('customer','notes','payment')); + $draft = $this->cart->updateDraftAttributes($draftKey, $request->only('customer', 'notes', 'payment')); if ($draft->getItemsCount() == 0) { flash(trans('transaction.item_list_empty'), 'warning')->important(); @@ -126,8 +127,9 @@ class CartController extends Controller public function store(Request $request, $draftKey) { $draft = $this->cart->get($draftKey); - if (is_null($draft)) + if (is_null($draft)) { return redirect()->route('cart.index'); + } $transaction = $draft->store(); $draft->destroy(); diff --git a/app/Transaction.php b/app/Transaction.php index 864e2b5..246cd7d 100644 --- a/app/Transaction.php +++ b/app/Transaction.php @@ -7,7 +7,7 @@ use Illuminate\Database\Eloquent\Model; class Transaction extends Model { protected $casts = [ - 'items' => 'array', + 'items' => 'array', 'customer' => 'array', ]; } diff --git a/database/migrations/2017_04_27_121204_create_transactions_table.php b/database/migrations/2017_04_27_121204_create_transactions_table.php index 2b50456..ca30206 100644 --- a/database/migrations/2017_04_27_121204_create_transactions_table.php +++ b/database/migrations/2017_04_27_121204_create_transactions_table.php @@ -1,8 +1,8 @@ 'Jumlah', 'welcome' => 'Selamat datang', 'export-pdf' => 'Export PDF', + ]; \ No newline at end of file diff --git a/tests/Feature/TransactionEntryTest.php b/tests/Feature/TransactionEntryTest.php index dde497f..5431255 100644 --- a/tests/Feature/TransactionEntryTest.php +++ b/tests/Feature/TransactionEntryTest.php @@ -221,11 +221,11 @@ class TransactionEntryTest extends BrowserKitTestCase $draftAttributes = [ 'customer' => [ - 'name' => 'Nafies', + 'name' => 'Nafies', 'phone' => '081234567890', ], 'payment' => 10000, - 'notes' => 'Catatan', + 'notes' => 'Catatan', ]; $cart->updateDraftAttributes($draft->draftKey, $draftAttributes); @@ -239,12 +239,12 @@ class TransactionEntryTest extends BrowserKitTestCase $this->seeInDatabase('transactions', [ 'invoice_no' => date('ym') . '0001', - 'items' => '[{"id":' . $product1->id . ',"name":"' . $product1->name . '","price":1000,"qty":1,"item_discount":0,"item_discount_subtotal":0,"subtotal":1000},{"id":' . $product2->id . ',"name":"' . $product2->name . '","price":2000,"qty":3,"item_discount":0,"item_discount_subtotal":0,"subtotal":6000}]', - 'customer' => '{"name":"Nafies","phone":"081234567890"}', - 'payment' => 10000, - 'total' => 7000, - 'notes' => 'Catatan', - 'user_id' => $user->id, + 'items' => '[{"id":' . $product1->id . ',"name":"' . $product1->name . '","price":1000,"qty":1,"item_discount":0,"item_discount_subtotal":0,"subtotal":1000},{"id":' . $product2->id . ',"name":"' . $product2->name . '","price":2000,"qty":3,"item_discount":0,"item_discount_subtotal":0,"subtotal":6000}]', + 'customer' => '{"name":"Nafies","phone":"081234567890"}', + 'payment' => 10000, + 'total' => 7000, + 'notes' => 'Catatan', + 'user_id' => $user->id, ]); } } diff --git a/tests/Unit/Integration/TransactionDraftTest.php b/tests/Unit/Integration/TransactionDraftTest.php index 99b5085..4a25784 100644 --- a/tests/Unit/Integration/TransactionDraftTest.php +++ b/tests/Unit/Integration/TransactionDraftTest.php @@ -168,11 +168,11 @@ class TransactionDraftTest extends TestCase $draftAttributes = [ 'customer' => [ - 'name' => 'Nafies', + 'name' => 'Nafies', 'phone' => '081234567890', ], 'payment' => 10000, - 'notes' => 'Catatan', + 'notes' => 'Catatan', ]; $cart->updateDraftAttributes($draft->draftKey, $draftAttributes); @@ -180,7 +180,7 @@ class TransactionDraftTest extends TestCase $this->assertEquals(7000, $draft->getTotal()); $this->assertEquals(3000, $draft->getExchange()); $this->assertEquals([ - 'name' => 'Nafies', + 'name' => 'Nafies', 'phone' => '081234567890', ], $draft->customer); $this->assertEquals('Catatan', $draft->notes); @@ -203,11 +203,11 @@ class TransactionDraftTest extends TestCase $draftAttributes = [ 'customer' => [ - 'name' => 'Nafies', + 'name' => 'Nafies', 'phone' => '081234567890', ], 'payment' => 10000, - 'notes' => 'Catatan', + 'notes' => 'Catatan', ]; $cart->updateDraftAttributes($draft->draftKey, $draftAttributes); @@ -215,12 +215,12 @@ class TransactionDraftTest extends TestCase $this->assertDatabaseHas('transactions', [ 'invoice_no' => date('ym') . '0001', - 'items' => '[{"id":' . $product1->id . ',"name":"' . $product1->name . '","price":1000,"qty":1,"item_discount":0,"item_discount_subtotal":0,"subtotal":1000},{"id":' . $product2->id . ',"name":"' . $product2->name . '","price":2000,"qty":3,"item_discount":0,"item_discount_subtotal":0,"subtotal":6000}]', - 'customer' => '{"name":"Nafies","phone":"081234567890"}', - 'payment' => 10000, - 'total' => 7000, - 'notes' => 'Catatan', - 'user_id' => 1, + 'items' => '[{"id":' . $product1->id . ',"name":"' . $product1->name . '","price":1000,"qty":1,"item_discount":0,"item_discount_subtotal":0,"subtotal":1000},{"id":' . $product2->id . ',"name":"' . $product2->name . '","price":2000,"qty":3,"item_discount":0,"item_discount_subtotal":0,"subtotal":6000}]', + 'customer' => '{"name":"Nafies","phone":"081234567890"}', + 'payment' => 10000, + 'total' => 7000, + 'notes' => 'Catatan', + 'user_id' => 1, ]); } }