Updates for quickbooks

This commit is contained in:
David Bomba 2025-02-10 13:19:41 +11:00
parent b9801cd802
commit 1876477346
8 changed files with 152 additions and 55 deletions

View File

@ -31,6 +31,9 @@ class ImportQuickbooksController extends BaseController
$qb = new QuickbooksService($company);
$authorizationUrl = $qb->sdk()->getAuthorizationUrl();
nlog($authorizationUrl);
$state = $qb->sdk()->getState();
Cache::put($state, $token, 190);

View File

@ -39,6 +39,9 @@ class QbClient implements SyncInterface
$ninja_data = $transformer->qbToNinja($record);
// nlog($ninja_data);
// nlog($record);
if ($ninja_data[0]['terms']) {
$days = $this->service->findEntityById('Term', $ninja_data[0]['terms']);

View File

@ -84,7 +84,7 @@ class QuickbooksService
$this->settings = $this->company->quickbooks->settings;
$this->checkDefaultAccounts();
// $this->checkDefaultAccounts(); // disabled, because if OAuth not present, we don't have access to the accounts.
return $this;
}

View File

@ -30,7 +30,6 @@ class ClientTransformer extends BaseTransformer
public function transform(mixed $data): array
{
nlog($data);
$contact = [
'first_name' => data_get($data, 'GivenName'),
@ -40,7 +39,7 @@ class ClientTransformer extends BaseTransformer
];
$client = [
'id' => data_get($data, 'Id.value', null),
'id' => data_get($data, 'Id.value', null) ?? data_get($data, 'Id', null),
'name' => data_get($data, 'CompanyName', ''),
'address1' => data_get($data, 'BillAddr.Line1', ''),
'address2' => data_get($data, 'BillAddr.Line2', ''),
@ -63,7 +62,7 @@ class ClientTransformer extends BaseTransformer
];
$settings = ClientSettings::defaults();
$settings->currency_id = (string) $this->resolveCurrency(data_get($data, 'CurrencyRef.value'));
$settings->currency_id = (string) $this->resolveCurrency(data_get($data, 'CurrencyRef.value', $this->company->settings->currency_id));
$client['settings'] = $settings;

View File

@ -31,7 +31,7 @@ class ProductTransformer extends BaseTransformer
{
return [
'id' => data_get($data, 'Id.value', null),
'id' => data_get($data, 'Id.value', null) ?? data_get($data, 'Id', null),
'product_key' => data_get($data, 'Name', data_get($data, 'FullyQualifiedName', '')),
'notes' => data_get($data, 'Description', ''),
'cost' => data_get($data, 'PurchaseCost', 0),

View File

@ -92,7 +92,7 @@
"predis/predis": "^2",
"psr/http-message": "^1.0",
"pusher/pusher-php-server": "^7.2",
"quickbooks/v3-php-sdk": "^6.1",
"quickbooks/v3-php-sdk": "^6.2",
"razorpay/razorpay": "2.*",
"sentry/sentry-laravel": "^4",
"setasign/fpdf": "^1.8",

98
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "99e318294f432f7df334da421558be59",
"content-hash": "2937b569c924dcc633b94288887c722c",
"packages": [
{
"name": "adrienrn/php-mimetyper",
@ -4351,16 +4351,16 @@
},
{
"name": "imdhemy/laravel-purchases",
"version": "1.15.0",
"version": "1.16.0",
"source": {
"type": "git",
"url": "https://github.com/imdhemy/laravel-in-app-purchases.git",
"reference": "b03fac928f80591ea16ac90dfeebf7e9b73d5744"
"reference": "91da08e5f87a07c6fb13113a424ca95773ff2e5e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/imdhemy/laravel-in-app-purchases/zipball/b03fac928f80591ea16ac90dfeebf7e9b73d5744",
"reference": "b03fac928f80591ea16ac90dfeebf7e9b73d5744",
"url": "https://api.github.com/repos/imdhemy/laravel-in-app-purchases/zipball/91da08e5f87a07c6fb13113a424ca95773ff2e5e",
"reference": "91da08e5f87a07c6fb13113a424ca95773ff2e5e",
"shasum": ""
},
"require": {
@ -4417,7 +4417,7 @@
],
"support": {
"issues": "https://github.com/imdhemy/laravel-in-app-purchases/issues",
"source": "https://github.com/imdhemy/laravel-in-app-purchases/tree/1.15.0"
"source": "https://github.com/imdhemy/laravel-in-app-purchases/tree/1.16.0"
},
"funding": [
{
@ -4425,7 +4425,7 @@
"type": "github"
}
],
"time": "2025-01-28T21:39:37+00:00"
"time": "2025-02-08T22:31:12+00:00"
},
{
"name": "intervention/image",
@ -9539,20 +9539,20 @@
},
{
"name": "phpoffice/phpspreadsheet",
"version": "2.3.7",
"version": "2.3.8",
"source": {
"type": "git",
"url": "https://github.com/PHPOffice/PhpSpreadsheet.git",
"reference": "cf357183b1d17a3862e8e4b9b056a556654dcae6"
"reference": "7a700683743bf1c4a21837c84b266916f1aa7d25"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/PHPOffice/PhpSpreadsheet/zipball/cf357183b1d17a3862e8e4b9b056a556654dcae6",
"reference": "cf357183b1d17a3862e8e4b9b056a556654dcae6",
"url": "https://api.github.com/repos/PHPOffice/PhpSpreadsheet/zipball/7a700683743bf1c4a21837c84b266916f1aa7d25",
"reference": "7a700683743bf1c4a21837c84b266916f1aa7d25",
"shasum": ""
},
"require": {
"composer/pcre": "^3.2",
"composer/pcre": "^1 || ^2 || ^3",
"ext-ctype": "*",
"ext-dom": "*",
"ext-fileinfo": "*",
@ -9638,9 +9638,9 @@
],
"support": {
"issues": "https://github.com/PHPOffice/PhpSpreadsheet/issues",
"source": "https://github.com/PHPOffice/PhpSpreadsheet/tree/2.3.7"
"source": "https://github.com/PHPOffice/PhpSpreadsheet/tree/2.3.8"
},
"time": "2025-01-26T04:53:06+00:00"
"time": "2025-02-08T03:01:45+00:00"
},
{
"name": "phpoption/phpoption",
@ -17353,16 +17353,16 @@
},
{
"name": "brianium/paratest",
"version": "v7.7.0",
"version": "v7.8.0",
"source": {
"type": "git",
"url": "https://github.com/paratestphp/paratest.git",
"reference": "4fb3f73bc5a4c3146bac2850af7dc72435a32daf"
"reference": "d18f88bfaa26d83bed8208d08fd918c224a0cc92"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/paratestphp/paratest/zipball/4fb3f73bc5a4c3146bac2850af7dc72435a32daf",
"reference": "4fb3f73bc5a4c3146bac2850af7dc72435a32daf",
"url": "https://api.github.com/repos/paratestphp/paratest/zipball/d18f88bfaa26d83bed8208d08fd918c224a0cc92",
"reference": "d18f88bfaa26d83bed8208d08fd918c224a0cc92",
"shasum": ""
},
"require": {
@ -17373,23 +17373,23 @@
"fidry/cpu-core-counter": "^1.2.0",
"jean85/pretty-package-versions": "^2.1.0",
"php": "~8.2.0 || ~8.3.0 || ~8.4.0",
"phpunit/php-code-coverage": "^11.0.8",
"phpunit/php-file-iterator": "^5.1.0",
"phpunit/php-timer": "^7.0.1",
"phpunit/phpunit": "^11.5.1",
"sebastian/environment": "^7.2.0",
"symfony/console": "^6.4.14 || ^7.2.1",
"symfony/process": "^6.4.14 || ^7.2.0"
"phpunit/php-code-coverage": "^11.0.8 || ^12",
"phpunit/php-file-iterator": "^5.1.0 || ^6",
"phpunit/php-timer": "^7.0.1 || ^8",
"phpunit/phpunit": "^11.5.7 || ^12.0.1",
"sebastian/environment": "^7.2.0 || ^8",
"symfony/console": "^6.4.17 || ^7.2.1",
"symfony/process": "^6.4.15 || ^7.2.0"
},
"require-dev": {
"doctrine/coding-standard": "^12.0.0",
"ext-pcov": "*",
"ext-posix": "*",
"phpstan/phpstan": "^2.0.3",
"phpstan/phpstan": "^2.1.2",
"phpstan/phpstan-deprecation-rules": "^2.0.1",
"phpstan/phpstan-phpunit": "^2.0.1",
"phpstan/phpstan-strict-rules": "^2",
"squizlabs/php_codesniffer": "^3.11.1",
"phpstan/phpstan-phpunit": "^2.0.4",
"phpstan/phpstan-strict-rules": "^2.0.3",
"squizlabs/php_codesniffer": "^3.11.3",
"symfony/filesystem": "^6.4.13 || ^7.2.0"
},
"bin": [
@ -17430,7 +17430,7 @@
],
"support": {
"issues": "https://github.com/paratestphp/paratest/issues",
"source": "https://github.com/paratestphp/paratest/tree/v7.7.0"
"source": "https://github.com/paratestphp/paratest/tree/v7.8.0"
},
"funding": [
{
@ -17442,7 +17442,7 @@
"type": "paypal"
}
],
"time": "2024-12-11T14:50:44+00:00"
"time": "2025-02-07T06:48:30+00:00"
},
{
"name": "clue/ndjson-react",
@ -18122,16 +18122,16 @@
},
{
"name": "larastan/larastan",
"version": "v2.9.12",
"version": "v2.9.14",
"source": {
"type": "git",
"url": "https://github.com/larastan/larastan.git",
"reference": "19012b39fbe4dede43dbe0c126d9681827a5e908"
"reference": "78f7f8da613e54edb2ab4afa5bede045228fb843"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/larastan/larastan/zipball/19012b39fbe4dede43dbe0c126d9681827a5e908",
"reference": "19012b39fbe4dede43dbe0c126d9681827a5e908",
"url": "https://api.github.com/repos/larastan/larastan/zipball/78f7f8da613e54edb2ab4afa5bede045228fb843",
"reference": "78f7f8da613e54edb2ab4afa5bede045228fb843",
"shasum": ""
},
"require": {
@ -18145,7 +18145,7 @@
"illuminate/support": "^9.52.16 || ^10.28.0 || ^11.16",
"php": "^8.0.2",
"phpmyadmin/sql-parser": "^5.9.0",
"phpstan/phpstan": "^1.12.11"
"phpstan/phpstan": "^1.12.17"
},
"require-dev": {
"doctrine/coding-standard": "^12.0",
@ -18203,7 +18203,7 @@
],
"support": {
"issues": "https://github.com/larastan/larastan/issues",
"source": "https://github.com/larastan/larastan/tree/v2.9.12"
"source": "https://github.com/larastan/larastan/tree/v2.9.14"
},
"funding": [
{
@ -18211,7 +18211,7 @@
"type": "github"
}
],
"time": "2024-11-26T23:09:02+00:00"
"time": "2025-02-06T21:03:14+00:00"
},
{
"name": "maximebf/debugbar",
@ -18669,16 +18669,16 @@
},
{
"name": "phpstan/phpstan",
"version": "1.12.16",
"version": "1.12.17",
"source": {
"type": "git",
"url": "https://github.com/phpstan/phpstan.git",
"reference": "e0bb5cb78545aae631220735aa706eac633a6be9"
"reference": "7027b3b0270bf392de0cfba12825979768d728bf"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/e0bb5cb78545aae631220735aa706eac633a6be9",
"reference": "e0bb5cb78545aae631220735aa706eac633a6be9",
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/7027b3b0270bf392de0cfba12825979768d728bf",
"reference": "7027b3b0270bf392de0cfba12825979768d728bf",
"shasum": ""
},
"require": {
@ -18723,7 +18723,7 @@
"type": "github"
}
],
"time": "2025-01-21T14:50:05+00:00"
"time": "2025-02-07T15:01:57+00:00"
},
{
"name": "phpunit/php-code-coverage",
@ -19050,16 +19050,16 @@
},
{
"name": "phpunit/phpunit",
"version": "11.5.6",
"version": "11.5.7",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/phpunit.git",
"reference": "3c3ae14c90f244cdda95028c3e469028e8d1c02c"
"reference": "e1cb706f019e2547039ca2c839898cd5f557ee5d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/3c3ae14c90f244cdda95028c3e469028e8d1c02c",
"reference": "3c3ae14c90f244cdda95028c3e469028e8d1c02c",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/e1cb706f019e2547039ca2c839898cd5f557ee5d",
"reference": "e1cb706f019e2547039ca2c839898cd5f557ee5d",
"shasum": ""
},
"require": {
@ -19131,7 +19131,7 @@
"support": {
"issues": "https://github.com/sebastianbergmann/phpunit/issues",
"security": "https://github.com/sebastianbergmann/phpunit/security/policy",
"source": "https://github.com/sebastianbergmann/phpunit/tree/11.5.6"
"source": "https://github.com/sebastianbergmann/phpunit/tree/11.5.7"
},
"funding": [
{
@ -19147,7 +19147,7 @@
"type": "tidelift"
}
],
"time": "2025-01-31T07:03:30+00:00"
"time": "2025-02-06T16:10:05+00:00"
},
{
"name": "react/cache",

View File

@ -0,0 +1,92 @@
<?php
namespace Tests\Feature\Import\Quickbooks;
use Mockery;
use Tests\TestCase;
use ReflectionClass;
use App\Models\Client;
use App\Models\Company;
use App\Models\Invoice;
use App\Models\Product;
use Tests\MockAccountData;
use Illuminate\Support\Str;
use App\Models\ClientContact;
use App\DataMapper\ClientSync;
use App\DataMapper\InvoiceItem;
use App\DataMapper\InvoiceSync;
use App\DataMapper\ProductSync;
use App\Utils\Traits\MakesHash;
use App\Import\Providers\Quickbooks;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Cache;
use QuickBooksOnline\API\Facades\Item;
use App\Import\Transformer\BaseTransformer;
use App\Services\Quickbooks\QuickbooksService;
use Illuminate\Routing\Middleware\ThrottleRequests;
use QuickBooksOnline\API\Facades\Invoice as QbInvoice;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class QuickbooksExportTest extends TestCase
{
use MakesHash;
use MockAccountData;
protected QuickbooksService $qb;
protected function setUp(): void
{
parent::setUp();
if(config('ninja.is_travis') || !config('services.quickbooks.client_id')){
$this->markTestSkipped('No Quickbooks Client ID found');
}
$company = Company::find(1);
if(!$company){
$this->markTestSkipped('No company found');
}
$this->qb = new QuickbooksService($company);
}
public function testImportProducts()
{
$entity = 'Product';
$entities = [
'client' => 'Customer',
'product' => 'Item',
'invoice' => 'Invoice',
// 'sales' => 'SalesReceipt',
];
foreach($entities as $key => $entity)
{
$records = $this->qb->sdk()->fetchRecords($entity);
$this->assertNotNull($records);
switch ($key) {
case 'product':
$this->qb->product->syncToNinja($records);
break;
case 'client':
$this->qb->client->syncToNinja($records);
break;
case 'invoice':
$this->qb->invoice->syncToNinja($records);
break;
case 'sales':
$this->qb->invoice->syncToNinja($records);
break;
}
}
}
}