revenues import/export
This commit is contained in:
@ -2,6 +2,11 @@
|
||||
|
||||
namespace App\Abstracts;
|
||||
|
||||
use App\Models\Banking\Account;
|
||||
use App\Models\Common\Contact;
|
||||
use App\Models\Common\Item;
|
||||
use App\Models\Setting\Category;
|
||||
use App\Models\Setting\Tax;
|
||||
use Illuminate\Support\Str;
|
||||
use Jenssegers\Date\Date;
|
||||
use Maatwebsite\Excel\Concerns\Importable;
|
||||
@ -86,4 +91,104 @@ abstract class Import implements ToModel, SkipsOnError, SkipsOnFailure, WithBatc
|
||||
{
|
||||
flash($e->getMessage())->error()->important();
|
||||
}
|
||||
|
||||
public function getAccountIdFromCurrency($row)
|
||||
{
|
||||
return Account::firstOrCreate([
|
||||
'currency_code' => $row['currency_code'],
|
||||
], [
|
||||
'company_id' => session('company_id'),
|
||||
'name' => $row['currency_code'],
|
||||
'number' => Account::max('number') + 1,
|
||||
'opening_balance' => 0,
|
||||
'enabled' => 1,
|
||||
])->id;
|
||||
}
|
||||
|
||||
public function getAccountIdFromName($row)
|
||||
{
|
||||
return Account::firstOrCreate([
|
||||
'name' => $row['account_name'],
|
||||
], [
|
||||
'company_id' => session('company_id'),
|
||||
'number' => Account::max('number') + 1,
|
||||
'currency_code' => setting('default.currency'),
|
||||
'opening_balance' => 0,
|
||||
'enabled' => 1,
|
||||
])->id;
|
||||
}
|
||||
|
||||
public function getAccountIdFromNumber($row)
|
||||
{
|
||||
return Account::firstOrCreate([
|
||||
'number' => $row['account_number'],
|
||||
], [
|
||||
'company_id' => session('company_id'),
|
||||
'name' => $row['account_number'],
|
||||
'currency_code' => setting('default.currency'),
|
||||
'opening_balance' => 0,
|
||||
'enabled' => 1,
|
||||
])->id;
|
||||
}
|
||||
|
||||
public function getCategoryIdFromName($row, $type)
|
||||
{
|
||||
return Category::firstOrCreate([
|
||||
'name' => $row['category_name'],
|
||||
], [
|
||||
'company_id' => session('company_id'),
|
||||
'type' => $type,
|
||||
'color' => '#' . dechex(rand(0x000000, 0xFFFFFF)),
|
||||
'enabled' => 1,
|
||||
])->id;
|
||||
}
|
||||
|
||||
public function getContactIdFromEmail($row, $type)
|
||||
{
|
||||
return Contact::firstOrCreate([
|
||||
'email' => $row['contact_email'],
|
||||
], [
|
||||
'company_id' => session('company_id'),
|
||||
'type' => $type,
|
||||
'name' => $row['contact_email'],
|
||||
'currency_code' => setting('default.currency'),
|
||||
'enabled' => 1,
|
||||
])->id;
|
||||
}
|
||||
|
||||
public function getContactIdFromName($row, $type)
|
||||
{
|
||||
return Contact::firstOrCreate([
|
||||
'name' => $row['contact_name'],
|
||||
], [
|
||||
'company_id' => session('company_id'),
|
||||
'type' => $type,
|
||||
'currency_code' => setting('default.currency'),
|
||||
'enabled' => 1,
|
||||
])->id;
|
||||
}
|
||||
|
||||
public function getItemIdFromName($row)
|
||||
{
|
||||
return Item::firstOrCreate([
|
||||
'name' => $row['item_name'],
|
||||
], [
|
||||
'company_id' => session('company_id'),
|
||||
'sale_price' => $row['price'],
|
||||
'purchase_price' => $row['price'],
|
||||
'enabled' => 1,
|
||||
])->id;
|
||||
}
|
||||
|
||||
public function getTaxIdFromRate($row, $type = 'normal')
|
||||
{
|
||||
return Tax::firstOrCreate([
|
||||
'rate' => $row['tax_rate'],
|
||||
], [
|
||||
'company_id' => session('company_id'),
|
||||
'type' => $type,
|
||||
'name' => $row['tax_rate'],
|
||||
'enabled' => 1,
|
||||
])->id;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user