Integration with Intuit - get accounting details for products
This commit is contained in:
48
app/Http/Controllers/AccountingController.php
Normal file
48
app/Http/Controllers/AccountingController.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?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
|
||||
{
|
||||
$so = ProviderOauth::where('name',$provider)->singleOrFail();
|
||||
// @todo This should be a variable
|
||||
$uo = User::findOrFail(1);
|
||||
|
||||
if (($x=$so->tokens->where('user_id',$uo->id))->count() !== 1)
|
||||
abort(500,sprintf('Unknown Tokens for [%s]',$uo->email));
|
||||
|
||||
$to = $x->pop();
|
||||
|
||||
$api = $so->API($to,TRUE); // @todo Remove TRUE
|
||||
|
||||
return $api->getItems()
|
||||
->pluck('pid','FullyQualifiedName')
|
||||
->transform(function($item,$value) { return ['id'=>$item,'value'=>$value]; })
|
||||
->values();
|
||||
}
|
||||
|
||||
public function webhook(Request $request)
|
||||
{
|
||||
Log::channel('webhook')->debug('Webhook event',['request'=>$request]);
|
||||
}
|
||||
}
|
@@ -10,9 +10,4 @@ class WelcomeController extends Controller
|
||||
public function home() {
|
||||
return view('welcome.home');
|
||||
}
|
||||
|
||||
public function webhook(Request $request)
|
||||
{
|
||||
Log::channel('webhook')->debug('Webhook event',['request'=>$request]);
|
||||
}
|
||||
}
|
@@ -30,11 +30,11 @@ class ProductAddEdit extends FormRequest
|
||||
return [
|
||||
'translate.name_short' => 'required|string|min:2|max:100',
|
||||
'translate.name_detail' => 'required|string|min:2|max:100',
|
||||
'translate.description' => 'required|string|min:2|max:255',
|
||||
'translate.description' => 'required|string|min:2|max:65535',
|
||||
'active' => 'sometimes|accepted',
|
||||
'model' => 'sometimes|string', // @todo Check that it is a valid model type
|
||||
'model_id' => 'sometimes|int', // @todo Check that it is a valid model type
|
||||
'accounting' => 'nullable|string',
|
||||
'accounting' => 'nullable|string', // @todo Validate that the value is in the accounting system
|
||||
'pricing' => 'required|array', // @todo Validate the elements in the pricing
|
||||
];
|
||||
}
|
||||
|
Reference in New Issue
Block a user