Skip to content

Commit

Permalink
item autocomplete by sku
Browse files Browse the repository at this point in the history
  • Loading branch information
denisdulici committed Apr 10, 2018
1 parent 094e9d3 commit 98bcefc
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 11 deletions.
2 changes: 2 additions & 0 deletions app/Http/Controllers/Api/Expenses/Bills.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public function store(Request $request)

$item_id = $item['item_id'];

$item['name'] = $item_object->name;
$item_sku = $item_object->sku;

// Increase stock (item bought)
Expand Down Expand Up @@ -143,6 +144,7 @@ public function update(Bill $bill, Request $request)

$item_id = $item['item_id'];

$item['name'] = $item_object->name;
$item_sku = $item_object->sku;
} elseif (!empty($item['sku'])) {
$item_sku = $item['sku'];
Expand Down
2 changes: 2 additions & 0 deletions app/Http/Controllers/Api/Incomes/Invoices.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public function store(Request $request)

$item_id = $item['item_id'];

$item['name'] = $item_object->name;
$item_sku = $item_object->sku;

// Decrease stock (item sold)
Expand Down Expand Up @@ -201,6 +202,7 @@ public function update(Invoice $invoice, Request $request)

$item_id = $item['item_id'];

$item['name'] = $item_object->name;
$item_sku = $item_object->sku;
} elseif (!empty($item['sku'])) {
$item_sku = $item['sku'];
Expand Down
2 changes: 2 additions & 0 deletions app/Http/Controllers/Expenses/Bills.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ public function store(Request $request)
if (!empty($item['item_id'])) {
$item_object = Item::find($item['item_id']);

$item['name'] = $item_object->name;
$item_sku = $item_object->sku;

// Increase stock (item bought)
Expand Down Expand Up @@ -348,6 +349,7 @@ public function update(Bill $bill, Request $request)
if (!empty($item['item_id'])) {
$item_object = Item::find($item['item_id']);

$item['name'] = $item_object->name;
$item_sku = $item_object->sku;
}

Expand Down
2 changes: 2 additions & 0 deletions app/Http/Controllers/Incomes/Invoices.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ public function store(Request $request)
if (!empty($item['item_id'])) {
$item_object = Item::find($item['item_id']);

$item['name'] = $item_object->name;
$item_sku = $item_object->sku;

// Decrease stock (item sold)
Expand Down Expand Up @@ -369,6 +370,7 @@ public function update(Invoice $invoice, Request $request)
if (!empty($item['item_id'])) {
$item_object = Item::find($item['item_id']);

$item['name'] = $item_object->name;
$item_sku = $item_object->sku;
}

Expand Down
7 changes: 4 additions & 3 deletions app/Http/Controllers/Items/Items.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,10 @@ public function autocomplete()

$currency = Currency::where('code', $currency_code)->first();

$filter_data = array(
'name' => $query
);
$filter_data = [
'name' => $query,
'sku' => $query,
];

$items = Item::getItems($filter_data);

Expand Down
10 changes: 6 additions & 4 deletions app/Models/Item/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,15 @@ public static function getItems($filter_data = array())
return Item::all();
}

$query = Item::select('id as item_id', 'name', 'sale_price', 'purchase_price', 'tax_id');
$query = Item::select('id as item_id', 'name', 'sku', 'sale_price', 'purchase_price', 'tax_id');

$query->where('quantity', '>', '0');

foreach ($filter_data as $key => $value) {
$query->where($key, 'LIKE', "%" . $value . "%");
}
$query->where(function ($query) use ($filter_data) {
foreach ($filter_data as $key => $value) {
$query->orWhere($key, 'LIKE', "%" . $value . "%");
}
});

return $query->get();
}
Expand Down
2 changes: 1 addition & 1 deletion resources/views/expenses/bills/create.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ function addItem() {
$(this).typeahead({
minLength: 3,
displayText:function (data) {
return data.name;
return data.name + ' (' + data.sku + ')';
},
source: function (query, process) {
$.ajax({
Expand Down
2 changes: 1 addition & 1 deletion resources/views/expenses/bills/edit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ function addItem() {
$(this).typeahead({
minLength: 3,
displayText:function (data) {
return data.name;
return data.name + ' (' + data.sku + ')';
},
source: function (query, process) {
$.ajax({
Expand Down
2 changes: 1 addition & 1 deletion resources/views/incomes/invoices/create.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ function addItem() {
$(this).typeahead({
minLength: 3,
displayText:function (data) {
return data.name;
return data.name + ' (' + data.sku + ')';
},
source: function (query, process) {
$.ajax({
Expand Down
2 changes: 1 addition & 1 deletion resources/views/incomes/invoices/edit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ function addItem() {
$(this).typeahead({
minLength: 3,
displayText:function (data) {
return data.name;
return data.name + ' (' + data.sku + ')';
},
source: function (query, process) {
$.ajax({
Expand Down

0 comments on commit 98bcefc

Please sign in to comment.