Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
20.00% covered (danger)
20.00%
2 / 10
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
CofraiQuotationsWorkSync
20.00% covered (danger)
20.00%
2 / 10
50.00% covered (danger)
50.00%
1 / 2
17.80
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 handle
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
20
1<?php
2
3namespace App\Console\Commands;
4
5use App\Services\CofraiQuotationsService;
6use App\Services\PresupuestosService;
7use Illuminate\Console\Command;
8use Illuminate\Support\Facades\Log;
9
10class CofraiQuotationsWorkSync extends Command
11{
12    /**
13     * The name and signature of the console command.
14     *
15     * @var string
16     */
17    protected $signature = 'cofrai-quotations:sync-work {name?} {region?}';
18
19    /**
20     * The console command description.
21     *
22     * @var string
23     */
24    protected $description = 'Synchronizes cofrai works related to the orders';
25
26    /**
27     * @var PresupuestosService
28     */
29    private $cofraiQuotationsService;
30
31    /**
32     * Create a new command instance.
33     *
34     * @return void
35     */
36    public function __construct(CofraiQuotationsService $cofraiQuotationsService)
37    {
38        parent::__construct();
39        $this->cofraiQuotationsService = $cofraiQuotationsService;
40    }
41
42    /**
43     * Execute the console command.
44     *
45     * @return int
46     */
47    public function handle()
48    {
49        $name = $this->argument('name') ?? 'System';
50        $regions = $this->argument('region') ? explode(',', $this->argument('region')) : ['Cataluña', 'Madrid', 'Comunidad Valenciana'];
51        try {
52            foreach ($regions as $region) {
53                $this->cofraiQuotationsService->syncBudgetsWorks($name, $region);
54            }
55
56            return Command::SUCCESS;
57        } catch (\Exception $e) {
58            Log::channel('g3w')->error('Synchronization failed for sync the works, Error: '.$e->getMessage());
59
60            return Command::FAILURE;
61        }
62    }
63}