Inuit sync of tax, product accounting, accounts and invoices
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
use App\Traits\SiteID;
|
||||
@@ -23,10 +24,17 @@ class ProviderOauth extends Model
|
||||
->withPivot('ref','synctoken','created_at','updated_at');
|
||||
}
|
||||
|
||||
public function products()
|
||||
public function invoices()
|
||||
{
|
||||
return $this->belongsToMany(Product::class,'product__provider')
|
||||
->where('product__provider.site_id',$this->site_id)
|
||||
return $this->belongsToMany(Invoice::class,'invoice__provider')
|
||||
->where('invoice__provider.site_id',$this->site_id)
|
||||
->withPivot('ref','synctoken','created_at','updated_at');
|
||||
}
|
||||
|
||||
public function taxes()
|
||||
{
|
||||
return $this->belongsToMany(Tax::class,'tax__provider')
|
||||
->where('tax__provider.site_id',$this->site_id)
|
||||
->withPivot('ref','synctoken','created_at','updated_at');
|
||||
}
|
||||
|
||||
@@ -42,23 +50,30 @@ class ProviderOauth extends Model
|
||||
|
||||
/* METHODS */
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function api_class(): ?string
|
||||
{
|
||||
return config('services.provider.'.strtolower($this->name).'.api');
|
||||
}
|
||||
|
||||
public function API(ProviderToken $o,bool $tryprod=FALSE): mixed
|
||||
/**
|
||||
* Return a list of the provider OAUTH details
|
||||
*/
|
||||
public static function providers(): Collection
|
||||
{
|
||||
return ($this->api_class() && $o->access_token) ? new ($this->api_class())($o,$tryprod) : NULL;
|
||||
return (new self)::whereIn('name',array_keys(config('services.provider')))->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Do we have API details for this supplier
|
||||
* Return the token object for a specific user
|
||||
*
|
||||
* @return bool
|
||||
* @param User $uo
|
||||
* @return ProviderToken|null
|
||||
*/
|
||||
public function hasAPIdetails(): bool
|
||||
public function token(User $uo): ?ProviderToken
|
||||
{
|
||||
return $this->api_class() && $this->access_token && (! $this->hasAccessTokenExpired());
|
||||
return (($x=$this->tokens->where('user_id',$uo->id))->count() === 1) ? $x->pop() : NULL;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user