osb/app/Http/Controllers/AccountingController.php
Deon George 3ff34af7f0
All checks were successful
Create Docker Image / Build Docker Image (x86_64) (push) Successful in 37s
Create Docker Image / Final Docker Image Manifest (push) Successful in 9s
Update laravel framework from 9 to 11, removed some old packages
2024-07-04 15:03:11 +10:00

38 lines
824 B
PHP

<?php
namespace App\Http\Controllers;
use Illuminate\Support\Collection;
use App\Models\{ProviderOauth,User};
class AccountingController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
/**
* Query the accounting system and get a valid list of accounting codes
*
* @param string $provider
* @return Collection
*/
public static function list(string $provider): Collection
{
// @todo This should be a variable
$uo = User::findOrFail(1);
$so = ProviderOauth::where('name',$provider)->singleOrFail();
if (! ($to=$so->token($uo)))
abort(500,sprintf('Unknown Tokens for [%s]',$uo->email));
$api = $to->API();
return $api->getItems()
->pluck('pid','Id')
->transform(function($item,$value) { return ['id'=>$value,'value'=>$item]; })
->values();
}
}