mirror of
https://github.com/crater-invoice/crater.git
synced 2025-10-27 11:41:09 -04:00
Fix condition
This commit is contained in:
@ -4,8 +4,6 @@ namespace Crater\Http\Controllers\V1\Admin\Settings;
|
||||
|
||||
use Crater\Http\Controllers\Controller;
|
||||
use Crater\Models\Company;
|
||||
use Crater\Models\CompanySetting;
|
||||
use Crater\Models\Currency;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class CompanyCurrencyCheckTransactionsController extends Controller
|
||||
@ -18,13 +16,11 @@ class CompanyCurrencyCheckTransactionsController extends Controller
|
||||
*/
|
||||
public function __invoke(Request $request)
|
||||
{
|
||||
$this->authorize('manage company', Company::find($request->header('company')));
|
||||
$company = Company::find($request->header('company'));
|
||||
|
||||
$companyCurrency = CompanySetting::getSetting('currency', $request->header('company'));
|
||||
$this->authorize('manage company', $company);
|
||||
|
||||
$currency = Currency::find((int)$companyCurrency);
|
||||
|
||||
if ($currency->checkTransactions()) {
|
||||
if ($company->hasTransactions()) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
]);
|
||||
|
||||
@ -6,7 +6,6 @@ use Crater\Http\Controllers\Controller;
|
||||
use Crater\Http\Requests\UpdateSettingsRequest;
|
||||
use Crater\Models\Company;
|
||||
use Crater\Models\CompanySetting;
|
||||
use Crater\Models\Currency;
|
||||
|
||||
class UpdateCompanySettingsController extends Controller
|
||||
{
|
||||
@ -18,14 +17,13 @@ class UpdateCompanySettingsController extends Controller
|
||||
*/
|
||||
public function __invoke(UpdateSettingsRequest $request)
|
||||
{
|
||||
$this->authorize('manage company', Company::find($request->header('company')));
|
||||
$company = Company::find($request->header('company'));
|
||||
$this->authorize('manage company', $company);
|
||||
|
||||
$companyCurrency = CompanySetting::getSetting('currency', $request->header('company'));
|
||||
|
||||
$data = $request->settings;
|
||||
$currency = Currency::find((int)$companyCurrency);
|
||||
|
||||
if ($companyCurrency !== $data['currency'] && $currency->checkTransactions()) {
|
||||
if ($companyCurrency !== $data['currency'] && $company->hasTransactions()) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'You cannot change currency once transaction is created.'
|
||||
|
||||
@ -380,4 +380,21 @@ class Company extends Model implements HasMedia
|
||||
$model->taxes()->delete();
|
||||
}
|
||||
}
|
||||
|
||||
public function hasTransactions()
|
||||
{
|
||||
if (
|
||||
$this->customers()->exists() ||
|
||||
$this->items()->exists() ||
|
||||
$this->invoices()->exists() ||
|
||||
$this->estimates()->exists() ||
|
||||
$this->expenses()->exists() ||
|
||||
$this->payments()->exists() ||
|
||||
$this->recurringInvoices()->exists()
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -12,56 +12,4 @@ class Currency extends Model
|
||||
protected $guarded = [
|
||||
'id'
|
||||
];
|
||||
|
||||
public function customers()
|
||||
{
|
||||
return $this->hasMany(Customer::class);
|
||||
}
|
||||
|
||||
public function items()
|
||||
{
|
||||
return $this->hasMany(Item::class);
|
||||
}
|
||||
|
||||
public function invoices()
|
||||
{
|
||||
return $this->hasMany(Invoice::class);
|
||||
}
|
||||
|
||||
public function estimates()
|
||||
{
|
||||
return $this->hasMany(Estimate::class);
|
||||
}
|
||||
|
||||
public function expenses()
|
||||
{
|
||||
return $this->hasMany(Expense::class);
|
||||
}
|
||||
|
||||
public function payments()
|
||||
{
|
||||
return $this->hasMany(Payment::class);
|
||||
}
|
||||
|
||||
public function recurringInvoices()
|
||||
{
|
||||
return $this->hasMany(RecurringInvoice::class);
|
||||
}
|
||||
|
||||
public function checkTransactions()
|
||||
{
|
||||
if (
|
||||
$this->customers()->exists() ||
|
||||
$this->items()->exists() ||
|
||||
$this->invoices()->exists() ||
|
||||
$this->estimates()->exists() ||
|
||||
$this->expenses()->exists() ||
|
||||
$this->payments()->exists() ||
|
||||
$this->recurringInvoices()->exists()
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -307,7 +307,7 @@ class RecurringInvoice extends Model
|
||||
|
||||
$days = CompanySetting::getSetting('invoice_due_date_days', $this->company_id);
|
||||
|
||||
if ($days == "null") {
|
||||
if (! $days || $days == "null") {
|
||||
$days = 7;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user