mirror of
https://github.com/crater-invoice/crater.git
synced 2025-10-27 11:41:09 -04:00
fix issues
This commit is contained in:
@ -96,12 +96,7 @@ class User extends Authenticatable implements HasMedia
|
||||
|
||||
public function estimates()
|
||||
{
|
||||
return $this->hasMany(Estimate::class, 'creator_id');
|
||||
}
|
||||
|
||||
public function customers()
|
||||
{
|
||||
return $this->hasMany(Customer::class, 'creator_id');
|
||||
return $this->hasMany(Estimate::class);
|
||||
}
|
||||
|
||||
public function currency()
|
||||
@ -119,29 +114,34 @@ class User extends Authenticatable implements HasMedia
|
||||
return $this->belongsToMany(Company::class, 'user_company', 'user_id', 'company_id');
|
||||
}
|
||||
|
||||
public function recurringInvoices()
|
||||
public function addresses()
|
||||
{
|
||||
return $this->hasMany(RecurringInvoice::class, 'creator_id');
|
||||
return $this->hasMany(Address::class);
|
||||
}
|
||||
|
||||
public function expenses()
|
||||
{
|
||||
return $this->hasMany(Expense::class, 'creator_id');
|
||||
return $this->hasMany(Expense::class);
|
||||
}
|
||||
|
||||
public function billingAddress()
|
||||
{
|
||||
return $this->hasOne(Address::class)->where('type', Address::BILLING_TYPE);
|
||||
}
|
||||
|
||||
public function shippingAddress()
|
||||
{
|
||||
return $this->hasOne(Address::class)->where('type', Address::SHIPPING_TYPE);
|
||||
}
|
||||
|
||||
public function payments()
|
||||
{
|
||||
return $this->hasMany(Payment::class, 'creator_id');
|
||||
return $this->hasMany(Payment::class);
|
||||
}
|
||||
|
||||
public function invoices()
|
||||
{
|
||||
return $this->hasMany(Invoice::class, 'creator_id');
|
||||
}
|
||||
|
||||
public function items()
|
||||
{
|
||||
return $this->hasMany(Item::class, 'creator_id');
|
||||
return $this->hasMany(Invoice::class);
|
||||
}
|
||||
|
||||
public function settings()
|
||||
@ -255,6 +255,37 @@ class User extends Authenticatable implements HasMedia
|
||||
});
|
||||
}
|
||||
|
||||
public static function deleteCustomers($ids)
|
||||
{
|
||||
foreach ($ids as $id) {
|
||||
$customer = self::find($id);
|
||||
|
||||
if ($customer->estimates()->exists()) {
|
||||
$customer->estimates()->delete();
|
||||
}
|
||||
|
||||
if ($customer->invoices()->exists()) {
|
||||
$customer->invoices()->delete();
|
||||
}
|
||||
|
||||
if ($customer->payments()->exists()) {
|
||||
$customer->payments()->delete();
|
||||
}
|
||||
|
||||
if ($customer->addresses()->exists()) {
|
||||
$customer->addresses()->delete();
|
||||
}
|
||||
|
||||
if ($customer->fields()->exists()) {
|
||||
$customer->fields()->delete();
|
||||
}
|
||||
|
||||
$customer->delete();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getAvatarAttribute()
|
||||
{
|
||||
$avatar = $this->getMedia('admin_avatar')->first();
|
||||
@ -454,47 +485,4 @@ class User extends Authenticatable implements HasMedia
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function deleteUsers($ids)
|
||||
{
|
||||
foreach ($ids as $id) {
|
||||
$user = self::find($id);
|
||||
|
||||
if ($user->invoices()->exists()) {
|
||||
$user->invoices()->update(['creator_id' => null]);
|
||||
}
|
||||
|
||||
if ($user->estimates()->exists()) {
|
||||
$user->estimates()->update(['creator_id' => null]);
|
||||
}
|
||||
|
||||
if ($user->customers()->exists()) {
|
||||
$user->customers()->update(['creator_id' => null]);
|
||||
}
|
||||
|
||||
if ($user->recurringInvoices()->exists()) {
|
||||
$user->recurringInvoices()->update(['creator_id' => null]);
|
||||
}
|
||||
|
||||
if ($user->expenses()->exists()) {
|
||||
$user->expenses()->update(['creator_id' => null]);
|
||||
}
|
||||
|
||||
if ($user->payments()->exists()) {
|
||||
$user->payments()->update(['creator_id' => null]);
|
||||
}
|
||||
|
||||
if ($user->items()->exists()) {
|
||||
$user->items()->update(['creator_id' => null]);
|
||||
}
|
||||
|
||||
if ($user->settings()->exists()) {
|
||||
$user->settings()->delete();
|
||||
}
|
||||
|
||||
$user->delete();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -16,8 +16,7 @@ class AddBaseColumnsToExpenseTable extends Migration
|
||||
Schema::table('expenses', function (Blueprint $table) {
|
||||
$table->decimal('exchange_rate', 19, 6)->nullable();
|
||||
$table->unsignedBigInteger('base_amount')->nullable();
|
||||
$table->unsignedInteger('currency_id');
|
||||
$table->foreign('currency_id')->references('id')->on('currencies');
|
||||
$table->unsignedInteger('currency_id')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user