From e39dde05d84585a33cfb7b0c3e736f78f67c57fd Mon Sep 17 00:00:00 2001 From: Deon George Date: Thu, 22 Aug 2024 21:35:23 +1000 Subject: [PATCH] Fixes for intuit:invoice:add, TaxSync and InvoiceSync --- app/Console/Commands/Intuit/InvoiceSync.php | 46 +++++++++++ app/Console/Commands/Intuit/TaxSync.php | 2 +- app/Jobs/AccountingInvoiceSync.php | 79 ++++++++++++++++++ app/Jobs/AccountingTaxSync.php | 8 +- composer.lock | 88 ++++++++++----------- 5 files changed, 174 insertions(+), 49 deletions(-) create mode 100644 app/Console/Commands/Intuit/InvoiceSync.php create mode 100644 app/Jobs/AccountingInvoiceSync.php diff --git a/app/Console/Commands/Intuit/InvoiceSync.php b/app/Console/Commands/Intuit/InvoiceSync.php new file mode 100644 index 0000000..15262bb --- /dev/null +++ b/app/Console/Commands/Intuit/InvoiceSync.php @@ -0,0 +1,46 @@ +argument('user') ?: config('osb.admin'))->singleOrFail(); + + $so = ProviderOauth::where('name',self::provider)->singleOrFail(); + if (! ($to=$so->token($uo))) + abort(500,sprintf('Unknown Tokens for [%s]',$uo->email)); + + Job::dispatchSync($to); + + return self::SUCCESS; + } +} \ No newline at end of file diff --git a/app/Console/Commands/Intuit/TaxSync.php b/app/Console/Commands/Intuit/TaxSync.php index 9e8bce9..2ae3f01 100644 --- a/app/Console/Commands/Intuit/TaxSync.php +++ b/app/Console/Commands/Intuit/TaxSync.php @@ -19,7 +19,7 @@ class TaxSync extends Command * * @var string */ - protected $signature = 'accounting:tax:sync' + protected $signature = 'intuit:tax:sync' .' {user? : User Email}'; /** diff --git a/app/Jobs/AccountingInvoiceSync.php b/app/Jobs/AccountingInvoiceSync.php new file mode 100644 index 0000000..9f7099c --- /dev/null +++ b/app/Jobs/AccountingInvoiceSync.php @@ -0,0 +1,79 @@ +to = $to; + } + + /** + * Execute the job. + * + * @return void + * @throws \Exception + */ + public function handle() + { + $api = $this->to->API(); + $ref = Invoice::select('id')->get(); + + foreach ($api->getInvoices() as $acc) { + $o = NULL; + + // See if we are already linked + if (($x=$this->to->provider->accounts->where('pivot.ref',$acc->id))->count() === 1) { + $o = $x->pop(); + + // If not, see if our reference matches + } elseif (($x=$ref->filter(fn($item)=>$item->lid == $acc->DocNumber))->count() === 1) { + $o = $x->pop(); + + } else { + // Log not found + Log::alert(sprintf('%s:Invoice not found [%s:%s]',self::LOGKEY,$acc->id,$acc->DocNumber)); + continue; + } + + $o->providers()->syncWithoutDetaching([ + $this->to->provider->id => [ + 'ref' => $acc->id, + 'synctoken' => $acc->synctoken, + 'created_at' => Carbon::create($acc->created_at), + 'updated_at' => Carbon::create($acc->updated_at), + 'site_id' => $this->to->site_id, + ], + ]); + + + Log::alert(sprintf('%s:Invoice updated [%s:%s]',self::LOGKEY,$o->id,$acc->DocNumber)); + } + } +} \ No newline at end of file diff --git a/app/Jobs/AccountingTaxSync.php b/app/Jobs/AccountingTaxSync.php index ef44380..b2d9ce4 100644 --- a/app/Jobs/AccountingTaxSync.php +++ b/app/Jobs/AccountingTaxSync.php @@ -61,7 +61,7 @@ class AccountingTaxSync implements ShouldQueue */ // Look based on Name - } elseif (($x=$ref->filter(function($item) use ($acc) { return $item->description === $acc->name; }))->count() === 1) { + } elseif (($x=$ref->filter(fn($item)=>$item->description === $acc->name))->count() === 1) { $o = $x->pop(); } else { @@ -74,9 +74,9 @@ class AccountingTaxSync implements ShouldQueue $this->to->provider->id => [ 'ref' => $acc->id, 'synctoken' => $acc->synctoken, - 'created_at'=>Carbon::create($acc->created_at), - 'updated_at'=>Carbon::create($acc->updated_at), - 'site_id'=>$this->to->site_id, + 'created_at' => Carbon::create($acc->created_at), + 'updated_at' => Carbon::create($acc->updated_at), + 'site_id' => $this->to->site_id, ], ]); diff --git a/composer.lock b/composer.lock index 62cbe7e..a23d864 100644 --- a/composer.lock +++ b/composer.lock @@ -1504,16 +1504,16 @@ }, { "name": "laravel/framework", - "version": "v11.20.0", + "version": "v11.21.0", "source": { "type": "git", "url": "https://github.com/laravel/framework.git", - "reference": "3cd7593dd9b67002fc416b46616f4d4d1da3e571" + "reference": "9d9d36708d56665b12185493f684abce38ad2d30" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/framework/zipball/3cd7593dd9b67002fc416b46616f4d4d1da3e571", - "reference": "3cd7593dd9b67002fc416b46616f4d4d1da3e571", + "url": "https://api.github.com/repos/laravel/framework/zipball/9d9d36708d56665b12185493f684abce38ad2d30", + "reference": "9d9d36708d56665b12185493f684abce38ad2d30", "shasum": "" }, "require": { @@ -1706,7 +1706,7 @@ "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" }, - "time": "2024-08-06T14:39:21+00:00" + "time": "2024-08-20T15:00:52+00:00" }, { "name": "laravel/passport", @@ -1786,16 +1786,16 @@ }, { "name": "laravel/prompts", - "version": "v0.1.24", + "version": "v0.1.25", "source": { "type": "git", "url": "https://github.com/laravel/prompts.git", - "reference": "409b0b4305273472f3754826e68f4edbd0150149" + "reference": "7b4029a84c37cb2725fc7f011586e2997040bc95" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/prompts/zipball/409b0b4305273472f3754826e68f4edbd0150149", - "reference": "409b0b4305273472f3754826e68f4edbd0150149", + "url": "https://api.github.com/repos/laravel/prompts/zipball/7b4029a84c37cb2725fc7f011586e2997040bc95", + "reference": "7b4029a84c37cb2725fc7f011586e2997040bc95", "shasum": "" }, "require": { @@ -1838,9 +1838,9 @@ "description": "Add beautiful and user-friendly forms to your command-line applications.", "support": { "issues": "https://github.com/laravel/prompts/issues", - "source": "https://github.com/laravel/prompts/tree/v0.1.24" + "source": "https://github.com/laravel/prompts/tree/v0.1.25" }, - "time": "2024-06-17T13:58:22+00:00" + "time": "2024-08-12T22:06:33+00:00" }, { "name": "laravel/serializable-closure", @@ -3021,11 +3021,11 @@ }, { "name": "leenooks/intuit", - "version": "0.2.1", + "version": "0.2.2", "source": { "type": "git", "url": "https://gitea.dege.au/laravel/intuit.git", - "reference": "9d81824b52dadc7b5fc0db9912373ecfb0942da7" + "reference": "6741d950738e2ab7154a21ea8288428a150f66f3" }, "require": { "jenssegers/model": "^1.5" @@ -3055,15 +3055,15 @@ "laravel", "leenooks" ], - "time": "2024-08-14T12:18:57+00:00" + "time": "2024-08-22T11:04:15+00:00" }, { "name": "leenooks/laravel", - "version": "11.1.13", + "version": "11.1.14", "source": { "type": "git", "url": "https://gitea.dege.au/laravel/leenooks.git", - "reference": "be6061fb6e91689714260dd0139839b9cfbffbc7" + "reference": "037abb17496a9d0fcbf2c415014190a287e70705" }, "type": "library", "extra": { @@ -3096,7 +3096,7 @@ "laravel", "leenooks" ], - "time": "2024-08-17T03:14:51+00:00" + "time": "2024-08-22T11:42:02+00:00" }, { "name": "leenooks/passkey", @@ -3309,16 +3309,16 @@ }, { "name": "nesbot/carbon", - "version": "3.7.0", + "version": "3.8.0", "source": { "type": "git", "url": "https://github.com/briannesbitt/Carbon.git", - "reference": "cb4374784c87d0a0294e8513a52eb63c0aff3139" + "reference": "bbd3eef89af8ba66a3aa7952b5439168fbcc529f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/cb4374784c87d0a0294e8513a52eb63c0aff3139", - "reference": "cb4374784c87d0a0294e8513a52eb63c0aff3139", + "url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/bbd3eef89af8ba66a3aa7952b5439168fbcc529f", + "reference": "bbd3eef89af8ba66a3aa7952b5439168fbcc529f", "shasum": "" }, "require": { @@ -3411,7 +3411,7 @@ "type": "tidelift" } ], - "time": "2024-07-16T22:29:20+00:00" + "time": "2024-08-19T06:22:39+00:00" }, { "name": "nette/schema", @@ -4438,16 +4438,16 @@ }, { "name": "psr/log", - "version": "3.0.0", + "version": "3.0.1", "source": { "type": "git", "url": "https://github.com/php-fig/log.git", - "reference": "fe5ea303b0887d5caefd3d431c3e61ad47037001" + "reference": "79dff0b268932c640297f5208d6298f71855c03e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/log/zipball/fe5ea303b0887d5caefd3d431c3e61ad47037001", - "reference": "fe5ea303b0887d5caefd3d431c3e61ad47037001", + "url": "https://api.github.com/repos/php-fig/log/zipball/79dff0b268932c640297f5208d6298f71855c03e", + "reference": "79dff0b268932c640297f5208d6298f71855c03e", "shasum": "" }, "require": { @@ -4482,9 +4482,9 @@ "psr-3" ], "support": { - "source": "https://github.com/php-fig/log/tree/3.0.0" + "source": "https://github.com/php-fig/log/tree/3.0.1" }, - "time": "2021-07-14T16:46:02+00:00" + "time": "2024-08-21T13:31:24+00:00" }, { "name": "psr/simple-cache", @@ -8589,32 +8589,32 @@ }, { "name": "phpunit/php-code-coverage", - "version": "11.0.5", + "version": "11.0.6", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "19b6365ab8b59a64438c0c3f4241feeb480c9861" + "reference": "ebdffc9e09585dafa71b9bffcdb0a229d4704c45" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/19b6365ab8b59a64438c0c3f4241feeb480c9861", - "reference": "19b6365ab8b59a64438c0c3f4241feeb480c9861", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/ebdffc9e09585dafa71b9bffcdb0a229d4704c45", + "reference": "ebdffc9e09585dafa71b9bffcdb0a229d4704c45", "shasum": "" }, "require": { "ext-dom": "*", "ext-libxml": "*", "ext-xmlwriter": "*", - "nikic/php-parser": "^5.0", + "nikic/php-parser": "^5.1.0", "php": ">=8.2", - "phpunit/php-file-iterator": "^5.0", - "phpunit/php-text-template": "^4.0", - "sebastian/code-unit-reverse-lookup": "^4.0", - "sebastian/complexity": "^4.0", - "sebastian/environment": "^7.0", - "sebastian/lines-of-code": "^3.0", - "sebastian/version": "^5.0", - "theseer/tokenizer": "^1.2.0" + "phpunit/php-file-iterator": "^5.0.1", + "phpunit/php-text-template": "^4.0.1", + "sebastian/code-unit-reverse-lookup": "^4.0.1", + "sebastian/complexity": "^4.0.1", + "sebastian/environment": "^7.2.0", + "sebastian/lines-of-code": "^3.0.1", + "sebastian/version": "^5.0.1", + "theseer/tokenizer": "^1.2.3" }, "require-dev": { "phpunit/phpunit": "^11.0" @@ -8626,7 +8626,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "11.0-dev" + "dev-main": "11.0.x-dev" } }, "autoload": { @@ -8655,7 +8655,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", "security": "https://github.com/sebastianbergmann/php-code-coverage/security/policy", - "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/11.0.5" + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/11.0.6" }, "funding": [ { @@ -8663,7 +8663,7 @@ "type": "github" } ], - "time": "2024-07-03T05:05:37+00:00" + "time": "2024-08-22T04:37:56+00:00" }, { "name": "phpunit/php-file-iterator",