2023-05-10 03:59:42 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\Support\Collection;
|
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
|
|
|
|
use App\Models\ProviderOauth;
|
|
|
|
use App\Models\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);
|
|
|
|
|
2023-05-12 10:09:51 +00:00
|
|
|
$so = ProviderOauth::where('name',$provider)->singleOrFail();
|
|
|
|
if (! ($to=$so->token($uo)))
|
2023-05-10 03:59:42 +00:00
|
|
|
abort(500,sprintf('Unknown Tokens for [%s]',$uo->email));
|
|
|
|
|
2023-05-12 10:09:51 +00:00
|
|
|
$api = $to->API();
|
2023-05-10 03:59:42 +00:00
|
|
|
|
|
|
|
return $api->getItems()
|
2023-05-12 10:09:51 +00:00
|
|
|
->pluck('pid','Id')
|
|
|
|
->transform(function($item,$value) { return ['id'=>$value,'value'=>$item]; })
|
2023-05-10 03:59:42 +00:00
|
|
|
->values();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function webhook(Request $request)
|
|
|
|
{
|
|
|
|
Log::channel('webhook')->debug('Webhook event',['request'=>$request]);
|
|
|
|
}
|
|
|
|
}
|