Inuit sync of tax, product accounting, accounts and invoices

This commit is contained in:
Deon George
2023-05-12 20:09:51 +10:00
parent e2d8f8a096
commit ad2f6f3a7f
22 changed files with 707 additions and 144 deletions

View File

@@ -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;
}
}