2023-05-10 03:59:42 +00:00
|
|
|
<?php
|
|
|
|
|
2024-07-14 03:49:00 +00:00
|
|
|
namespace App\Console\Commands\Intuit;
|
2023-05-10 03:59:42 +00:00
|
|
|
|
|
|
|
use Illuminate\Console\Command;
|
2024-08-12 10:58:35 +00:00
|
|
|
use Intuit\Exceptions\NotTokenException;
|
|
|
|
use Intuit\Traits\ProviderTokenTrait;
|
2023-05-10 03:59:42 +00:00
|
|
|
|
2024-08-12 10:58:35 +00:00
|
|
|
use App\Models\Product;
|
2023-05-10 03:59:42 +00:00
|
|
|
|
2024-08-12 10:58:35 +00:00
|
|
|
/**
|
|
|
|
* Return a list of products and their accounting id
|
|
|
|
*/
|
2024-07-14 03:49:00 +00:00
|
|
|
class ItemList extends Command
|
2023-05-10 03:59:42 +00:00
|
|
|
{
|
2024-08-12 10:58:35 +00:00
|
|
|
use ProviderTokenTrait;
|
2024-07-14 03:49:00 +00:00
|
|
|
|
2023-05-10 03:59:42 +00:00
|
|
|
/**
|
|
|
|
* The name and signature of the console command.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $signature = 'accounting:item:list'
|
2024-07-14 03:49:00 +00:00
|
|
|
.' {user? : User Email}';
|
2023-05-10 03:59:42 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The console command description.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $description = 'Synchronise items with accounting system';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the console command.
|
|
|
|
*
|
|
|
|
* @return int
|
2024-08-12 10:58:35 +00:00
|
|
|
* @throws NotTokenException
|
2023-05-10 03:59:42 +00:00
|
|
|
*/
|
|
|
|
public function handle()
|
|
|
|
{
|
2024-08-12 10:58:35 +00:00
|
|
|
$to = $this->providerToken($this->argument('user'));
|
2023-05-10 03:59:42 +00:00
|
|
|
|
|
|
|
// Current Products used by services
|
|
|
|
$products = Product::select(['products.*'])
|
|
|
|
->distinct('products.id')
|
|
|
|
->join('services',['services.product_id'=>'products.id'])
|
|
|
|
->where('services.active',TRUE)
|
|
|
|
->get();
|
|
|
|
|
|
|
|
foreach ($products as $po) {
|
2024-08-12 10:58:35 +00:00
|
|
|
if (! $x=$po->provider_ref($to->provider))
|
|
|
|
$this->error(sprintf('Product [%03d](%s) doesnt have accounting set',$po->id,$po->name));
|
2023-05-10 03:59:42 +00:00
|
|
|
|
|
|
|
else
|
2024-08-12 10:58:35 +00:00
|
|
|
$this->info(sprintf('Product [%03d](%s) set to accounting [%s]',$po->id,$po->name,$x));
|
2023-05-10 03:59:42 +00:00
|
|
|
}
|
2024-07-14 03:49:00 +00:00
|
|
|
|
|
|
|
return self::SUCCESS;
|
2023-05-10 03:59:42 +00:00
|
|
|
}
|
|
|
|
}
|