fixed #342
This commit is contained in:
parent
651194cd56
commit
72ed09c352
@ -205,12 +205,16 @@ class Items extends Controller
|
|||||||
|
|
||||||
$currency = Currency::where('code', $currency_code)->first();
|
$currency = Currency::where('code', $currency_code)->first();
|
||||||
|
|
||||||
$filter_data = [
|
$autocomplete = Item::autocomplete([
|
||||||
'name' => $query,
|
'name' => $query,
|
||||||
'sku' => $query,
|
'sku' => $query,
|
||||||
];
|
]);
|
||||||
|
|
||||||
$items = Item::getItems($filter_data);
|
if ($type == 'invoice') {
|
||||||
|
$autocomplete->quantity();
|
||||||
|
}
|
||||||
|
|
||||||
|
$items = $autocomplete->get();
|
||||||
|
|
||||||
if ($items) {
|
if ($items) {
|
||||||
foreach ($items as $item) {
|
foreach ($items as $item) {
|
||||||
|
@ -14,6 +14,13 @@ class Item extends Model
|
|||||||
|
|
||||||
protected $table = 'items';
|
protected $table = 'items';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The accessors to append to the model's array form.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $appends = ['item_id'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attributes that should be mass-assignable.
|
* Attributes that should be mass-assignable.
|
||||||
*
|
*
|
||||||
@ -81,23 +88,41 @@ class Item extends Model
|
|||||||
$this->attributes['purchase_price'] = (double) $value;
|
$this->attributes['purchase_price'] = (double) $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getItems($filter_data = array())
|
/**
|
||||||
|
* Get the item id.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getItemIdAttribute()
|
||||||
{
|
{
|
||||||
if (empty($filter_data)) {
|
return $this->id;
|
||||||
return Item::all();
|
}
|
||||||
}
|
|
||||||
|
|
||||||
$query = Item::select('id as item_id', 'name', 'sku', 'sale_price', 'purchase_price', 'tax_id');
|
/**
|
||||||
|
* Scope autocomplete.
|
||||||
$query->where('quantity', '>', '0');
|
*
|
||||||
|
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||||
$query->where(function ($query) use ($filter_data) {
|
* @param array $filter
|
||||||
foreach ($filter_data as $key => $value) {
|
* @return \Illuminate\Database\Eloquent\Builder
|
||||||
|
*/
|
||||||
|
public function scopeAutocomplete($query, $filter)
|
||||||
|
{
|
||||||
|
return $query->where(function ($query) use ($filter) {
|
||||||
|
foreach ($filter as $key => $value) {
|
||||||
$query->orWhere($key, 'LIKE', "%" . $value . "%");
|
$query->orWhere($key, 'LIKE', "%" . $value . "%");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return $query->get();
|
/**
|
||||||
|
* Scope quantity.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||||
|
* @return \Illuminate\Database\Eloquent\Builder
|
||||||
|
*/
|
||||||
|
public function scopeQuantity($query)
|
||||||
|
{
|
||||||
|
return $query->where('quantity', '>', '0');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user