Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
25 / 25 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| IntegrationInvoiceResource | |
100.00% |
25 / 25 |
|
100.00% |
1 / 1 |
3 | |
100.00% |
1 / 1 |
| toArray | |
100.00% |
25 / 25 |
|
100.00% |
1 / 1 |
3 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Domain\Integration\Resources; |
| 4 | |
| 5 | use Illuminate\Http\Request; |
| 6 | use Illuminate\Http\Resources\Json\JsonResource; |
| 7 | |
| 8 | use App\Models\Supplier; |
| 9 | use App\Models\Integration\Integration; |
| 10 | |
| 11 | /** |
| 12 | * @property array $parameters |
| 13 | */ |
| 14 | class IntegrationInvoiceResource extends JsonResource |
| 15 | { |
| 16 | public function toArray($request) |
| 17 | { |
| 18 | $params = $this->parameters; |
| 19 | |
| 20 | $supplier = null; |
| 21 | if (isset($params['supplier_code'])) { |
| 22 | $supplierERP = Integration::query() |
| 23 | ->where('integrable_type', Supplier::class) |
| 24 | ->whereRaw("parameters->>'CODFOR' = ?", [(string) $params['supplier_code']]) |
| 25 | ->first(); |
| 26 | |
| 27 | if (!empty($supplierERP)) { |
| 28 | $supplier = Supplier::find($supplierERP->integrable_id); |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | return [ |
| 33 | 'invoice_key' => $params['invoice_key'] ?? null, |
| 34 | 'derivation_code' => $params['derivation_code'] ?? null, |
| 35 | 'enterprise_code' => $params['enterprise_code'] ?? null, |
| 36 | 'product_code' => $params['product_code'] ?? null, |
| 37 | 'supplier_code' => $params['supplier_code'] ?? null, |
| 38 | 'supplier' => $supplier, |
| 39 | 'date_movement' => $params['date_movement'] ?? null, |
| 40 | 'warehouse_branch' => $params['warehouse_branch'] ?? null, |
| 41 | 'invoice_branch' => $params['invoice_branch'] ?? null, |
| 42 | 'invoice_number' => $params['invoice_number'] ?? null, |
| 43 | 'quantity_movement' => $params['quantity_movement'] ?? null, |
| 44 | 'sequence_movement' => $params['sequence_movement'] ?? null, |
| 45 | 'sequence_register' => $params['sequence_register'] ?? null, |
| 46 | 'invoice_series' => $params['invoice_series'] ?? null, |
| 47 | ]; |
| 48 | } |
| 49 | |
| 50 | } |