1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-11 21:52:35 +01:00
invoiceninja/app/Import/Transformer/BaseTransformer.php

721 lines
19 KiB
PHP
Raw Normal View History

2022-02-01 07:14:27 +01:00
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
2023-01-28 23:21:40 +01:00
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
2022-02-01 07:14:27 +01:00
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Import\Transformer;
2023-10-26 04:57:44 +02:00
use App\Factory\ClientFactory;
use App\Factory\ExpenseCategoryFactory;
use App\Factory\ProjectFactory;
use App\Factory\VendorFactory;
2023-02-16 02:36:09 +01:00
use App\Models\Client;
2023-10-26 04:57:44 +02:00
use App\Models\ClientContact;
2022-02-01 07:14:27 +01:00
use App\Models\Country;
2023-02-16 02:36:09 +01:00
use App\Models\Expense;
2023-10-26 04:57:44 +02:00
use App\Models\ExpenseCategory;
2023-02-16 02:36:09 +01:00
use App\Models\Invoice;
2023-10-26 04:57:44 +02:00
use App\Models\PaymentType;
2023-02-16 02:36:09 +01:00
use App\Models\Product;
2022-09-01 09:37:55 +02:00
use App\Models\Project;
2023-10-26 04:57:44 +02:00
use App\Models\Quote;
use App\Models\RecurringInvoice;
2022-09-01 09:37:55 +02:00
use App\Models\TaxRate;
2023-10-26 04:57:44 +02:00
use App\Models\Vendor;
use App\Repositories\ClientRepository;
use App\Utils\Number;
2022-02-01 07:14:27 +01:00
use Illuminate\Support\Carbon;
2022-02-01 07:35:16 +01:00
use Illuminate\Support\Facades\Cache;
2022-02-01 07:14:27 +01:00
/**
* Class BaseTransformer.
*/
class BaseTransformer
{
protected $company;
public function __construct($company)
{
$this->company = $company;
}
2022-11-01 23:49:40 +01:00
public function parseDate($date)
{
2023-10-26 04:57:44 +02:00
if(stripos($date, "/") !== false && $this->company->settings->country_id != 840) {
2023-10-09 06:16:35 +02:00
$date = str_replace('/', '-', $date);
2023-10-26 04:57:44 +02:00
}
2023-10-09 06:16:35 +02:00
2023-02-16 02:36:09 +01:00
try {
2022-11-01 23:49:40 +01:00
$parsed_date = Carbon::parse($date);
return $parsed_date->format('Y-m-d');
2023-02-16 02:36:09 +01:00
} catch(\Exception $e) {
2022-11-01 23:49:40 +01:00
$parsed_date = date('Y-m-d', strtotime($date));
2023-02-16 02:36:09 +01:00
if ($parsed_date == '1970-01-01') {
2022-11-01 23:49:40 +01:00
return now()->format('Y-m-d');
2023-02-16 02:36:09 +01:00
}
2022-11-01 23:49:40 +01:00
return $parsed_date;
}
}
2023-02-01 23:15:11 +01:00
public function getInvoiceTypeId($data, $field)
{
return isset($data[$field]) && $data[$field] ? (string)$data[$field] : '1';
}
2022-11-03 07:01:58 +01:00
public function getNumber($data, $field)
{
return (isset($data->$field) && $data->$field) ? (int)$data->$field : 0;
}
2022-02-01 07:14:27 +01:00
public function getString($data, $field)
2023-11-20 05:31:40 +01:00
{
2022-02-10 05:10:56 +01:00
return isset($data[$field]) && $data[$field] ? trim($data[$field]) : '';
2022-02-01 07:14:27 +01:00
}
2022-02-10 03:02:02 +01:00
public function getValueOrNull($data, $field)
{
return isset($data[$field]) && $data[$field] ? $data[$field] : null;
2022-02-10 03:02:02 +01:00
}
2022-02-03 00:14:54 +01:00
public function getCurrencyByCode($data, $key = 'client.currency_id')
2022-02-01 07:14:27 +01:00
{
2022-02-03 00:14:54 +01:00
$code = array_key_exists($key, $data) ? $data[$key] : false;
2022-02-01 07:14:27 +01:00
2022-02-01 07:35:16 +01:00
$currencies = Cache::get('currencies');
2022-02-03 00:14:54 +01:00
$currency = $currencies
->filter(function ($item) use ($code) {
return $item->code == $code;
})
->first();
2022-02-01 07:14:27 +01:00
2022-02-03 00:14:54 +01:00
return $currency
? $currency->id
: $this->company->settings->currency_id;
2022-02-01 07:35:16 +01:00
}
2023-04-19 07:21:50 +02:00
public function getFrequency($frequency = RecurringInvoice::FREQUENCY_MONTHLY): int
{
switch ($frequency) {
case RecurringInvoice::FREQUENCY_DAILY:
case 'daily':
return RecurringInvoice::FREQUENCY_DAILY;
case RecurringInvoice::FREQUENCY_WEEKLY:
case 'weekly':
return RecurringInvoice::FREQUENCY_WEEKLY;
case RecurringInvoice::FREQUENCY_TWO_WEEKS:
case 'biweekly':
return RecurringInvoice::FREQUENCY_TWO_WEEKS;
case RecurringInvoice::FREQUENCY_FOUR_WEEKS:
case '4weeks':
return RecurringInvoice::FREQUENCY_FOUR_WEEKS;
case RecurringInvoice::FREQUENCY_MONTHLY:
case 'monthly':
return RecurringInvoice::FREQUENCY_MONTHLY;
case RecurringInvoice::FREQUENCY_TWO_MONTHS:
case 'bimonthly':
return RecurringInvoice::FREQUENCY_TWO_MONTHS;
case RecurringInvoice::FREQUENCY_THREE_MONTHS:
case 'quarterly':
return RecurringInvoice::FREQUENCY_THREE_MONTHS;
case RecurringInvoice::FREQUENCY_FOUR_MONTHS:
case '4months':
return RecurringInvoice::FREQUENCY_FOUR_MONTHS;
case RecurringInvoice::FREQUENCY_SIX_MONTHS:
case '6months':
return RecurringInvoice::FREQUENCY_SIX_MONTHS;
case RecurringInvoice::FREQUENCY_ANNUALLY:
case 'yearly':
return RecurringInvoice::FREQUENCY_ANNUALLY;
case RecurringInvoice::FREQUENCY_TWO_YEARS:
case '2years':
return RecurringInvoice::FREQUENCY_TWO_YEARS;
case RecurringInvoice::FREQUENCY_THREE_YEARS:
case '3years':
return RecurringInvoice::FREQUENCY_THREE_YEARS;
default:
return RecurringInvoice::FREQUENCY_MONTHLY;
}
}
public function getRemainingCycles($remaining_cycles = -1): int
{
2023-04-19 07:37:08 +02:00
if ($remaining_cycles == 'endless') {
return -1;
}
2023-04-19 07:21:50 +02:00
return (int)$remaining_cycles;
}
public function getAutoBillFlag(string $option): string
{
switch ($option) {
case 'off':
case 'false':
return 'off';
case 'always':
case 'true':
return 'always';
case 'optin':
return 'opt_in';
case 'optout':
return 'opt_out';
default:
return 'off';
}
}
2022-02-03 00:14:54 +01:00
public function getClient($client_name, $client_email)
2022-02-02 05:56:37 +01:00
{
2023-11-20 05:31:40 +01:00
if (! empty($client_name)) {
2023-08-07 07:07:52 +02:00
$client_id_search = Client::query()->where('company_id', $this->company->id)
->where('is_deleted', false)
->where('id_number', $client_name);
2022-02-01 07:14:27 +01:00
if ($client_id_search->count() >= 1) {
return $client_id_search->first()->id;
}
2022-02-01 07:14:27 +01:00
2023-08-07 07:07:52 +02:00
$client_name_search = Client::query()->where('company_id', $this->company->id)
->where('is_deleted', false)
2022-09-06 05:38:54 +02:00
->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $client_name)),
]);
2022-02-01 07:14:27 +01:00
if ($client_name_search->count() >= 1) {
return $client_name_search->first()->id;
}
}
if (! empty($client_email)) {
2023-08-07 07:07:52 +02:00
$contacts = ClientContact::query()->whereHas('client', function ($query) {
$query->where('is_deleted', false);
})
->where('company_id', $this->company->id)
->where('email', $client_email);
2022-02-01 07:14:27 +01:00
2022-02-03 00:14:54 +01:00
if ($contacts->count() >= 1) {
return $contacts->first()->client_id;
}
}
2022-02-01 07:14:27 +01:00
$client_repository = app()->make(ClientRepository::class);
$client_repository->import_mode = true;
$client = $client_repository->save(
[
'name' => $client_name,
'contacts' => [
[
'first_name' => $client_name,
'email' => $client_email,
],
],
],
ClientFactory::create(
$this->company->id,
$this->company->owner()->id
)
);
$client_repository = null;
return $client->id;
2022-02-03 00:14:54 +01:00
}
2022-02-01 07:14:27 +01:00
///////////////////////////////////////////////////////////////////////////////////
/**
* @param $name
*
* @return bool
*/
public function hasClient($name)
{
2023-08-21 07:25:46 +02:00
2023-08-07 07:07:52 +02:00
return Client::query()->where('company_id', $this->company->id)
->where('is_deleted', false)
2023-08-21 07:05:57 +02:00
->whereRaw("LOWER(REPLACE(`name`, ' ' , '')) = ?", [
2022-02-03 00:14:54 +01:00
strtolower(str_replace(' ', '', $name)),
])
->exists();
2022-02-01 07:14:27 +01:00
}
2023-08-21 07:05:57 +02:00
2023-06-21 06:21:43 +02:00
public function hasClientIdNumber($id_number)
{
2023-08-07 07:07:52 +02:00
return Client::query()->where('company_id', $this->company->id)
2023-06-21 06:21:43 +02:00
->where('is_deleted', false)
->where('id_number', trim($id_number))
->exists();
}
2022-02-01 07:14:27 +01:00
/**
* @param $name
*
* @return bool
*/
public function hasVendor($name)
{
2023-08-07 07:07:52 +02:00
return Vendor::query()->where('company_id', $this->company->id)
->where('is_deleted', false)
2022-02-03 00:14:54 +01:00
->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $name)),
])
->exists();
2022-02-01 07:14:27 +01:00
}
2022-02-03 08:53:39 +01:00
/**
* @param $name
*
* @return bool
*/
public function hasProject($name)
{
2023-08-07 07:07:52 +02:00
return Project::query()->where('company_id', $this->company->id)
->where('is_deleted', false)
2022-02-03 08:53:39 +01:00
->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $name)),
])
->exists();
}
2022-02-01 07:14:27 +01:00
/**
* @param $key
*
* @return bool
*/
public function hasProduct($key)
{
2023-08-07 07:07:52 +02:00
return Product::query()->where('company_id', $this->company->id)
->where('is_deleted', false)
2022-02-03 00:14:54 +01:00
->whereRaw("LOWER(REPLACE(`product_key`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $key)),
])
->exists();
2022-02-01 07:14:27 +01:00
}
/**
* @param $data
* @param $field
*
* @return float
*/
public function getFloat($data, $field)
{
if (array_key_exists($field, $data)) {
2022-09-08 04:15:25 +02:00
//$number = preg_replace('/[^0-9-.]+/', '', $data[$field]);
return Number::parseStringFloat($data[$field]);
2022-02-01 07:14:27 +01:00
} else {
2022-09-08 04:15:25 +02:00
//$number = 0;
return 0;
2022-02-01 07:14:27 +01:00
}
2022-09-08 04:15:25 +02:00
// return Number::parseFloat($number);
2022-02-01 07:14:27 +01:00
}
2023-07-16 12:39:41 +02:00
/**
* @param $data
* @param $field
*
* @return float
*/
public function getFloatOrOne($data, $field)
{
2023-10-26 04:57:44 +02:00
if (array_key_exists($field, $data)) {
2023-07-16 12:39:41 +02:00
return Number::parseStringFloat($data[$field]) > 0 ? Number::parseStringFloat($data[$field]) : 1;
2023-10-26 04:57:44 +02:00
}
2023-07-16 12:39:41 +02:00
2023-10-26 04:57:44 +02:00
return 1;
2023-07-16 12:39:41 +02:00
}
2022-02-01 07:14:27 +01:00
/**
* @param $name
*
* @return int|null
*/
public function getClientId($name)
{
2023-08-07 07:07:52 +02:00
$client = Client::query()->where('company_id', $this->company->id)
->where('is_deleted', false)
2022-02-03 00:14:54 +01:00
->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $name)),
])
->first();
2022-02-01 07:14:27 +01:00
return $client ? $client->id : null;
}
/**
* @param $name
*
* @return string
*/
2022-04-26 08:53:41 +02:00
public function getProduct($key)
2022-02-01 07:14:27 +01:00
{
2023-08-07 07:07:52 +02:00
$product = Product::query()->where('company_id', $this->company->id)
->where('is_deleted', false)
2022-02-03 00:14:54 +01:00
->whereRaw("LOWER(REPLACE(`product_key`, ' ' ,'')) = ?", [
2022-04-26 08:53:41 +02:00
strtolower(str_replace(' ', '', $key)),
2022-02-03 00:14:54 +01:00
])
->first();
2022-04-26 08:53:41 +02:00
return $product;
2022-02-01 07:14:27 +01:00
}
/**
* @param $email
*
2023-04-13 08:00:59 +02:00
* @return ?ClientContact
2022-02-01 07:14:27 +01:00
*/
2023-04-13 08:00:59 +02:00
public function getContact($email): ?ClientContact
2022-02-01 07:14:27 +01:00
{
2023-08-07 07:07:52 +02:00
$contact = ClientContact::query()->where('company_id', $this->company->id)
2022-02-03 00:14:54 +01:00
->whereRaw("LOWER(REPLACE(`email`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $email)),
])
->first();
if (! $contact) {
2022-02-01 07:14:27 +01:00
return null;
2022-02-03 00:14:54 +01:00
}
2022-02-01 07:14:27 +01:00
return $contact;
}
/**
* @param $name
*
* @return int|null
*/
public function getCountryId($name)
{
2023-05-10 03:49:08 +02:00
if (strlen(trim($name)) == 2) {
2022-02-01 07:14:27 +01:00
return $this->getCountryIdBy2($name);
2022-02-03 00:14:54 +01:00
}
2022-02-01 07:14:27 +01:00
2023-08-07 07:07:52 +02:00
$country = Country::query()->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [
2022-02-03 00:14:54 +01:00
strtolower(str_replace(' ', '', $name)),
])->first();
2022-02-01 07:14:27 +01:00
return $country ? $country->id : null;
}
/**
* @param $name
*
* @return int|null
*/
public function getCountryIdBy2($name)
{
2023-08-07 07:07:52 +02:00
return Country::query()->where('iso_3166_2', $name)->exists()
? Country::query()->where('iso_3166_2', $name)->first()->id
2022-02-03 00:14:54 +01:00
: null;
2022-02-01 07:14:27 +01:00
}
/**
* @param $name
*
2023-04-29 01:32:20 +02:00
* @return float
2022-02-01 07:14:27 +01:00
*/
public function getTaxRate($name)
{
$name = strtolower(trim($name));
2023-08-07 07:07:52 +02:00
$tax_rate = TaxRate::query()->where('company_id', $this->company->id)
->where('is_deleted', false)
2022-02-03 00:14:54 +01:00
->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $name)),
])
->first();
2022-02-01 07:14:27 +01:00
return $tax_rate ? $tax_rate->rate : 0;
}
/**
* @param $name
*
* @return string
*/
public function getTaxName($name)
{
$name = strtolower(trim($name));
2023-08-07 07:07:52 +02:00
$tax_rate = TaxRate::query()->where('company_id', $this->company->id)
->where('is_deleted', false)
2022-02-03 00:14:54 +01:00
->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $name)),
])
->first();
2022-02-01 07:14:27 +01:00
return $tax_rate ? $tax_rate->name : '';
}
/**
2023-04-19 07:21:50 +02:00
*
2022-02-01 07:14:27 +01:00
* @param mixed $data
* @param mixed $field
*
2023-04-29 01:32:20 +02:00
* @return ?string
2022-02-01 07:14:27 +01:00
*/
public function getDate($data, $field)
{
if ($date = data_get($data, $field)) {
try {
$date = new Carbon($date);
} catch (\Exception $e) {
// if we fail to parse return blank
$date = false;
}
}
return $date ? $date->format('Y-m-d') : null;
}
/**
* @param $number
*
* @return ?string
*/
public function getInvoiceNumber($number)
{
2022-02-03 00:14:54 +01:00
return $number ? ltrim(trim($number), '0') : null;
2022-02-01 07:14:27 +01:00
}
/**
* @param $invoice_number
*
* @return int|null
*/
public function getInvoiceId($invoice_number)
{
2023-08-07 07:07:52 +02:00
$invoice = Invoice::query()->where('company_id', $this->company->id)
->where('is_deleted', false)
2022-02-03 00:14:54 +01:00
->whereRaw("LOWER(REPLACE(`number`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $invoice_number)),
])
->first();
return $invoice ? $invoice->id : null;
2022-02-01 07:14:27 +01:00
}
/**
* @param $invoice_number
*
* @return bool
*/
public function hasInvoice($invoice_number)
{
2023-08-07 07:07:52 +02:00
return Invoice::query()->where('company_id', $this->company->id)
->where('is_deleted', false)
2022-02-03 00:14:54 +01:00
->whereRaw("LOWER(REPLACE(`number`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $invoice_number)),
])
->exists();
2022-02-01 07:14:27 +01:00
}
2023-04-19 07:21:50 +02:00
/**
* @param $invoice_number
*
* @return bool
*/
public function hasRecurringInvoice($invoice_number)
{
2023-08-07 07:07:52 +02:00
return RecurringInvoice::query()->where('company_id', $this->company->id)
2023-04-19 07:21:50 +02:00
->where('is_deleted', false)
->whereRaw("LOWER(REPLACE(`number`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $invoice_number)),
])
->exists();
}
2022-02-10 11:15:58 +01:00
/** *
* @return bool
*/
public function hasExpense($expense_number)
{
2023-08-07 07:07:52 +02:00
return Expense::query()->where('company_id', $this->company->id)
->where('is_deleted', false)
2022-02-10 11:15:58 +01:00
->whereRaw("LOWER(REPLACE(`number`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $expense_number)),
])
->exists();
}
2022-02-08 05:14:26 +01:00
/**
* @param $quote_number
*
* @return bool
*/
public function hasQuote($quote_number)
{
2023-08-07 07:07:52 +02:00
return Quote::query()->where('company_id', $this->company->id)
->where('is_deleted', false)
2022-02-08 05:14:26 +01:00
->whereRaw("LOWER(REPLACE(`number`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $quote_number)),
])
->exists();
}
2022-02-01 07:14:27 +01:00
/**
* @param $invoice_number
*
* @return int|null
*/
public function getInvoiceClientId($invoice_number)
{
2023-08-07 07:07:52 +02:00
$invoice = Invoice::query()->where('company_id', $this->company->id)
->where('is_deleted', false)
2022-02-03 00:14:54 +01:00
->whereRaw("LOWER(REPLACE(`number`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $invoice_number)),
])
->first();
2022-02-01 07:14:27 +01:00
return $invoice ? $invoice->client_id : null;
}
/**
* @param $name
*
* @return int|null
*/
public function getVendorId($name)
{
2023-08-07 07:07:52 +02:00
$vendor = Vendor::query()->where('company_id', $this->company->id)
->where('is_deleted', false)
2022-02-03 00:14:54 +01:00
->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $name)),
])
->first();
2022-02-01 07:14:27 +01:00
return $vendor ? $vendor->id : null;
}
2022-02-10 11:15:58 +01:00
public function getVendorIdOrCreate($name)
{
if (empty($name)) {
2022-02-10 11:15:58 +01:00
return null;
}
2022-02-10 11:15:58 +01:00
$vendor = $this->getVendorId($name);
if ($vendor) {
2022-02-10 11:15:58 +01:00
return $vendor;
}
2022-02-10 11:15:58 +01:00
$vendor = VendorFactory::create($this->company->id, $this->company->owner()->id);
$vendor->name = $name;
$vendor->save();
return $vendor->id;
}
2022-02-03 00:14:54 +01:00
/**
* @param $name
*
* @return int|null
*/
public function getExpenseCategoryId($name)
{
/** @var \App\Models\ExpenseCategory $ec */
2023-08-07 07:07:52 +02:00
$ec = ExpenseCategory::query()->where('company_id', $this->company->id)
->where('is_deleted', false)
2022-02-03 00:14:54 +01:00
->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $name)),
])
->first();
2022-02-01 07:14:27 +01:00
2023-10-26 04:57:44 +02:00
if($ec) {
return $ec->id;
2023-10-26 04:57:44 +02:00
}
$ec = \App\Factory\ExpenseCategoryFactory::create($this->company->id, $this->company->owner()->id);
$ec->name = $name;
$ec->save();
2022-02-01 07:14:27 +01:00
return $ec ? $ec->id : null;
2022-02-03 00:14:54 +01:00
}
2022-02-01 07:14:27 +01:00
2022-02-10 03:02:02 +01:00
public function getOrCreateExpenseCategry($name)
{
if (empty($name)) {
2022-02-10 11:15:58 +01:00
return null;
}
2022-02-10 11:15:58 +01:00
2022-02-10 03:02:02 +01:00
$ec = $this->getExpenseCategoryId($name);
if ($ec) {
2022-02-10 03:02:02 +01:00
return $ec;
}
2022-02-10 03:02:02 +01:00
2022-02-10 11:15:58 +01:00
$expense_category = ExpenseCategoryFactory::create($this->company->id, $this->company->owner()->id);
2022-02-10 03:02:02 +01:00
$expense_category->name = $name;
$expense_category->save();
return $expense_category->id;
2022-02-10 03:02:02 +01:00
}
2022-02-03 00:14:54 +01:00
/**
* @param $name
*
* @return int|null
*/
2022-02-03 09:43:28 +01:00
public function getProjectId($name, $clientId = null)
2022-02-03 00:14:54 +01:00
{
2023-11-14 04:53:25 +01:00
if(strlen($name) == 0)
return null;
2023-08-07 07:07:52 +02:00
$project = Project::query()->where('company_id', $this->company->id)
->where('is_deleted', false)
2022-02-03 00:14:54 +01:00
->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $name)),
])
->first();
2022-02-01 07:14:27 +01:00
2022-02-03 09:43:28 +01:00
return $project ? $project->id : $this->createProject($name, $clientId);
}
private function createProject($name, $clientId)
{
$project = ProjectFactory::create($this->company->id, $this->company->owner()->id);
$project->name = $name;
if ($clientId) {
2022-02-03 09:43:28 +01:00
$project->client_id = $clientId;
}
2022-02-03 09:43:28 +01:00
$project->saveQuietly();
2022-02-03 09:43:28 +01:00
return $project->id;
2022-02-03 00:14:54 +01:00
}
2022-02-01 07:14:27 +01:00
2022-02-03 00:14:54 +01:00
/**
* @param $name
*
* @return int|null
*/
public function getPaymentTypeId($name)
{
2023-08-07 07:07:52 +02:00
$pt = PaymentType::query()->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [
2022-02-03 00:14:54 +01:00
strtolower(str_replace(' ', '', $name)),
])->first();
2022-02-01 07:14:27 +01:00
return $pt ? $pt->id : null;
2022-02-03 00:14:54 +01:00
}
2022-02-01 07:14:27 +01:00
}