Initial integration with Quickbooks
This commit is contained in:
7
app/Classes/External/Accounting.php
vendored
Normal file
7
app/Classes/External/Accounting.php
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\External;
|
||||
|
||||
abstract class Accounting
|
||||
{
|
||||
}
|
50
app/Classes/External/Accounting/Quickbooks.php
vendored
Normal file
50
app/Classes/External/Accounting/Quickbooks.php
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\External\Accounting;
|
||||
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
use QuickBooksOnline\API\Data\IPPCustomer;
|
||||
use QuickBooksOnline\API\Facades\Customer;
|
||||
|
||||
use App\User;
|
||||
use App\Classes\External\Accounting as Base;
|
||||
|
||||
class Quickbooks extends Base
|
||||
{
|
||||
private $api = NULL;
|
||||
|
||||
public function __construct(User $uo)
|
||||
{
|
||||
if (Auth::user())
|
||||
throw new \Exception('User logged in - *TODO* handle this');
|
||||
|
||||
Auth::loginUsingId($uo->id);
|
||||
|
||||
$this->api = app('Spinen\QuickBooks\Client');
|
||||
}
|
||||
|
||||
public function getCustomers($refresh=FALSE): Collection
|
||||
{
|
||||
if ($refresh)
|
||||
Cache::forget(__METHOD__);
|
||||
|
||||
return Cache::remember(__METHOD__,86400,function() {
|
||||
return collect($this->api->getDataService()->Query('SELECT * FROM Customer'));
|
||||
});
|
||||
}
|
||||
|
||||
public function updateCustomer(IPPCustomer $r,array $args)
|
||||
{
|
||||
$r->sparse = TRUE;
|
||||
|
||||
foreach ($args as $k=>$v)
|
||||
{
|
||||
$r->{$k} = $v;
|
||||
}
|
||||
|
||||
return $this->api->getDataService()->Update($r);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user