Fixes for intuit:invoice:add, TaxSync and InvoiceSync
Some checks failed
Create Docker Image / Build Docker Image (x86_64) (push) Failing after 26s
Create Docker Image / Final Docker Image Manifest (push) Has been skipped

This commit is contained in:
Deon George 2024-08-22 21:35:23 +10:00
parent 2c3665650c
commit 9a0bc58564
5 changed files with 171 additions and 46 deletions

View File

@ -0,0 +1,46 @@
<?php
namespace App\Console\Commands\Intuit;
use Illuminate\Console\Command;
use App\Models\{ProviderOauth,User};
use App\Jobs\AccountingInvoiceSync as Job;
class InvoiceSync extends Command
{
private const provider = 'intuit';
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'intuit:invoice:sync'
.' {user? : User Email}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Synchronise invoices with accounting system';
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$uo = User::where('email',$this->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;
}
}

View File

@ -19,7 +19,7 @@ class TaxSync extends Command
*
* @var string
*/
protected $signature = 'accounting:tax:sync'
protected $signature = 'intuit:tax:sync'
.' {user? : User Email}';
/**

View File

@ -0,0 +1,79 @@
<?php
namespace App\Jobs;
use Carbon\Carbon;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;
use App\Models\{Invoice,ProviderToken};
/**
* Synchronise invoices ref numbers with our database
*/
class AccountingInvoiceSync implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
private const LOGKEY = 'JIS';
private ProviderToken $to;
/**
* Create a new job instance.
*
* @param ProviderToken $to
*/
public function __construct(ProviderToken $to)
{
$this->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));
}
}
}

View File

@ -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 {

82
composer.lock generated
View File

@ -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,7 +3055,7 @@
"laravel",
"leenooks"
],
"time": "2024-08-14T12:18:57+00:00"
"time": "2024-08-22T11:04:15+00:00"
},
{
"name": "leenooks/laravel",
@ -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",