mirror of
https://github.com/crater-invoice/crater.git
synced 2025-10-29 20:51:09 -04:00
v5.0.0 update
This commit is contained in:
@ -23,7 +23,12 @@ class Item extends Model
|
||||
|
||||
public function unit()
|
||||
{
|
||||
return $this->belongsTo(Unit::class);
|
||||
return $this->belongsTo(Unit::class, 'unit_id');
|
||||
}
|
||||
|
||||
public function company()
|
||||
{
|
||||
return $this->belongsTo(Company::class);
|
||||
}
|
||||
|
||||
public function creator()
|
||||
@ -31,6 +36,11 @@ class Item extends Model
|
||||
return $this->belongsTo('Crater\Models\User', 'creator_id');
|
||||
}
|
||||
|
||||
public function currency()
|
||||
{
|
||||
return $this->belongsTo(Currency::class);
|
||||
}
|
||||
|
||||
public function scopeWhereSearch($query, $search)
|
||||
{
|
||||
return $query->where('items.name', 'LIKE', '%'.$search.'%');
|
||||
@ -86,7 +96,7 @@ class Item extends Model
|
||||
public function scopePaginateData($query, $limit)
|
||||
{
|
||||
if ($limit == 'all') {
|
||||
return collect(['data' => $query->get()]);
|
||||
return $query->get();
|
||||
}
|
||||
|
||||
return $query->paginate($limit);
|
||||
@ -94,7 +104,7 @@ class Item extends Model
|
||||
|
||||
public function getFormattedCreatedAtAttribute($value)
|
||||
{
|
||||
$dateFormat = CompanySetting::getSetting('carbon_date_format', $this->company_id);
|
||||
$dateFormat = CompanySetting::getSetting('carbon_date_format', request()->header('company'));
|
||||
|
||||
return Carbon::parse($this->created_at)->format($dateFormat);
|
||||
}
|
||||
@ -106,9 +116,9 @@ class Item extends Model
|
||||
->where('estimate_item_id', null);
|
||||
}
|
||||
|
||||
public function scopeWhereCompany($query, $company_id)
|
||||
public function scopeWhereCompany($query)
|
||||
{
|
||||
$query->where('items.company_id', $company_id);
|
||||
$query->where('items.company_id', request()->header('company'));
|
||||
}
|
||||
|
||||
public function invoiceItems()
|
||||
@ -126,10 +136,14 @@ class Item extends Model
|
||||
$data = $request->validated();
|
||||
$data['company_id'] = $request->header('company');
|
||||
$data['creator_id'] = Auth::id();
|
||||
$company_currency = CompanySetting::getSetting('currency', $request->header('company'));
|
||||
$data['currency_id'] = $company_currency;
|
||||
$item = self::create($data);
|
||||
|
||||
if ($request->has('taxes')) {
|
||||
foreach ($request->taxes as $tax) {
|
||||
$item->tax_per_item = true;
|
||||
$item->save();
|
||||
$tax['company_id'] = $request->header('company');
|
||||
$item->taxes()->create($tax);
|
||||
}
|
||||
@ -148,6 +162,8 @@ class Item extends Model
|
||||
|
||||
if ($request->has('taxes')) {
|
||||
foreach ($request->taxes as $tax) {
|
||||
$this->tax_per_item = true;
|
||||
$this->save();
|
||||
$tax['company_id'] = $request->header('company');
|
||||
$this->taxes()->create($tax);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user