Browse Source

Fixed sintax to pass StyleCI

pull/3/head
Nafies Luthfi 9 years ago
parent
commit
87bbaf78ba
  1. 10
      app/Cart/Item.php
  2. 20
      app/Cart/TransactionDraft.php
  3. 17
      app/Helpers/helpers.php
  4. 14
      app/Http/Controllers/CartController.php
  5. 2
      app/Transaction.php
  6. 4
      database/migrations/2017_04_27_121204_create_transactions_table.php
  7. 1
      resources/lang/id/app.php
  8. 16
      tests/Feature/TransactionEntryTest.php
  9. 22
      tests/Unit/Integration/TransactionDraftTest.php

10
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;
}

20
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,
];
}

17
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 = '<i class="fa fa-' . $attributes['icon'] . '"></i> ' . $title;
if (array_key_exists('icon', $attributes)) {
$title = '<i class="fa fa-'.$attributes['icon'].'"></i> '.$title;
}
return app('html')->decode(link_to_route($name, $title, $parameters, $attributes));
}

14
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();

2
app/Transaction.php

@ -7,7 +7,7 @@ use Illuminate\Database\Eloquent\Model;
class Transaction extends Model
{
protected $casts = [
'items' => 'array',
'items' => 'array',
'customer' => 'array',
];
}

4
database/migrations/2017_04_27_121204_create_transactions_table.php

@ -1,8 +1,8 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateTransactionsTable extends Migration
{

1
resources/lang/id/app.php

@ -34,4 +34,5 @@ return [
'count' => 'Jumlah',
'welcome' => 'Selamat datang',
'export-pdf' => 'Export PDF',
];

16
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,
]);
}
}

22
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,
]);
}
}
Loading…
Cancel
Save