mirror of
https://github.com/crater-invoice/crater.git
synced 2025-10-27 19:51:09 -04:00
v5.0.0 update
This commit is contained in:
@ -55,19 +55,24 @@ class CustomField extends Model
|
||||
return $this->$value_type;
|
||||
}
|
||||
|
||||
public function getInUseAttribute()
|
||||
{
|
||||
return $this->customFieldValues()->exists();
|
||||
}
|
||||
|
||||
public function company()
|
||||
{
|
||||
return $this->belongsTo(Company::class);
|
||||
}
|
||||
|
||||
public function customFieldValue()
|
||||
public function customFieldValues()
|
||||
{
|
||||
return $this->hasMany(CustomFieldValue::class);
|
||||
}
|
||||
|
||||
public function scopeWhereCompany($query, $company_id)
|
||||
public function scopeWhereCompany($query)
|
||||
{
|
||||
$query->where('custom_fields.company_id', $company_id);
|
||||
return $query->where('custom_fields.company_id', request()->header('company'));
|
||||
}
|
||||
|
||||
public function scopeWhereSearch($query, $search)
|
||||
@ -81,7 +86,7 @@ class CustomField extends Model
|
||||
public function scopePaginateData($query, $limit)
|
||||
{
|
||||
if ($limit == 'all') {
|
||||
return collect(['data' => $query->get()]);
|
||||
return $query->get();
|
||||
}
|
||||
|
||||
return $query->paginate($limit);
|
||||
@ -110,40 +115,17 @@ class CustomField extends Model
|
||||
$data = $request->validated();
|
||||
$data[getCustomFieldValueKey($request->type)] = $request->default_answer;
|
||||
$data['company_id'] = $request->header('company');
|
||||
$data['slug'] = clean_slug($request->model_type, $request->label);
|
||||
$data['slug'] = clean_slug($request->model_type, $request->name);
|
||||
|
||||
return CustomField::create($data);
|
||||
}
|
||||
|
||||
public function updateCustomField($request)
|
||||
{
|
||||
$oldSlug = $this->slug;
|
||||
$data = $request->validated();
|
||||
$data[getCustomFieldValueKey($request->type)] = $request->default_answer;
|
||||
$data['slug'] = clean_slug($request->model_type, $request->label, $this->id);
|
||||
$this->update($data);
|
||||
|
||||
if ($oldSlug !== $data['slug']) {
|
||||
$settings = [
|
||||
'invoice_company_address_format',
|
||||
'invoice_shipping_address_format',
|
||||
'invoice_billing_address_format',
|
||||
'estimate_company_address_format',
|
||||
'estimate_shipping_address_format',
|
||||
'estimate_billing_address_format',
|
||||
'payment_company_address_format',
|
||||
'payment_from_customer_address_format',
|
||||
];
|
||||
|
||||
$settings = CompanySetting::getSettings($settings, $this->company_id);
|
||||
|
||||
foreach ($settings as $key => $value) {
|
||||
$settings[$key] = str_replace($oldSlug, $data['slug'], $value);
|
||||
}
|
||||
|
||||
CompanySetting::setSettings($settings, $this->company_id);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user