1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-15 07:33:04 +01:00
invoiceninja/app/Services/Quickbooks/Transformers/BaseTransformer.php

87 lines
2.5 KiB
PHP
Raw Normal View History

2024-08-26 07:48:48 +02:00
<?php
/**
* Invoice Ninja (https://clientninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
2024-08-26 12:17:51 +02:00
namespace App\Services\Quickbooks\Transformers;
2024-08-26 07:48:48 +02:00
use App\Models\Client;
2024-09-21 08:30:13 +02:00
use App\Models\Vendor;
2024-08-26 07:48:48 +02:00
use App\Models\Company;
/**
* Class BaseTransformer.
*/
class BaseTransformer
{
public function __construct(public Company $company)
{
}
public function resolveCountry(string $iso_3_code): string
{
/** @var \App\Models\Country $country */
$country = app('countries')->first(function ($c) use ($iso_3_code){
/** @var \App\Models\Country $c */
2024-09-21 08:30:13 +02:00
return $c->iso_3166_3 == $iso_3_code || $c->name == $iso_3_code;
2024-08-26 07:48:48 +02:00
});
2024-09-21 08:30:13 +02:00
return $country ? (string) $country->id : $this->company->settings->country_id;
2024-08-26 07:48:48 +02:00
}
public function resolveCurrency(string $currency_code): string
{
/** @var \App\Models\Currency $currency */
$currency = app('currencies')->first(function($c) use ($currency_code){
/** @var \App\Models\Currency $c */
return $c->code == $currency_code;
});
2024-09-21 08:30:13 +02:00
return $currency ? (string) $currency->id : $this->company->settings->currency_id;
2024-08-26 07:48:48 +02:00
}
public function getShipAddrCountry($data, $field)
{
return is_null(($c = $this->getString($data, $field))) ? null : $this->getCountryId($c);
}
public function getBillAddrCountry($data, $field)
{
return is_null(($c = $this->getString($data, $field))) ? null : $this->getCountryId($c);
}
public function getClientId($customer_reference_id): ?int
{
$client = Client::query()
->withTrashed()
->where('company_id', $this->company->id)
2024-09-22 11:27:34 +02:00
// ->where('number', $customer_reference_id)
->where('sync->qb_id', $customer_reference_id)
2024-08-26 07:48:48 +02:00
->first();
return $client ? $client->id : null;
}
2024-09-21 08:30:13 +02:00
public function getVendorId($customer_reference_id): ?int
{
$vendor = Vendor::query()
->withTrashed()
->where('company_id', $this->company->id)
->where('number', $customer_reference_id)
->first();
return $vendor ? $vendor->id : null;
}
2024-08-26 07:48:48 +02:00
}