Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 60
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
PickingOrderReportService
0.00% covered (danger)
0.00%
0 / 60
0.00% covered (danger)
0.00%
0 / 2
56
0.00% covered (danger)
0.00%
0 / 1
 complete
0.00% covered (danger)
0.00%
0 / 38
0.00% covered (danger)
0.00%
0 / 1
20
 summarized
0.00% covered (danger)
0.00%
0 / 22
0.00% covered (danger)
0.00%
0 / 1
12
1<?php
2
3namespace Domain\PickingOrder\Reports;
4
5use App\Events\ServiceProcessed;
6use App\Helper\AppHelper;
7use App\Models\PickingOrder\PickingOrder;
8use App\Models\User;
9use Carbon\Carbon;
10use Domain\Shared\Integrations\Senior\Exceptions\IntegrationSoapSeniorException;
11use Domain\Shared\Integrations\Senior\SeniorPreOrder;
12use Domain\StockIO\DTOs\SeniorPreOrderDTO;
13use Illuminate\Support\Facades\Auth;
14
15class PickingOrderReportService
16{
17    /**
18     * @param PickingOrder $pickingOrder
19     * @param User $user
20     * @return array
21     */
22    public function complete(PickingOrder $pickingOrder, User $user): array
23    {
24        $pickingOrderIds = $pickingOrder->stockIO->pickingOrders()
25            ->orderBy('id')
26            ->get()
27            ->pluck('id');
28
29        $position = null;
30        foreach ($pickingOrderIds as $index => $id) {
31            if ($id == $pickingOrder->getKey()) {
32                $position = $index + 1;
33                break;
34            }
35        }
36
37        $pickingOrder->load([
38            'integration',
39            'stockIOProducts.product.integration',
40            'stockIOProducts.product.unitMeasurement',
41            'stockIOProducts.product.measure',
42            'stockIOProducts.integration',
43        ]);
44
45        try {
46            $getOrderDetails = (new SeniorPreOrder())->execute(new SeniorPreOrderDTO([
47                'codemp' => 1,
48                'codfil' => 1,
49                'numpfa' => $pickingOrder->stockIO->integration->parameters['NUMPFA'],
50                'numane' => $pickingOrder->stockIO->integration->parameters['NUMANE'],
51            ]));
52        } catch (IntegrationSoapSeniorException $e) {
53            $getOrderDetails = null;
54        }
55
56
57        ServiceProcessed::dispatch($pickingOrder, $user);
58        return [
59            'pickingOrder' => $pickingOrder,
60            'customer' => AppHelper::fetchCustomer($pickingOrder->stockIO->integration->parameters['CODCLI']),
61            'now' => Carbon::now()->format('d/m/Y H:i'),
62            'generatedBy' => Auth::user()?->getAttribute('name'),
63            'qrcode' => json_encode([
64                'type' => 'picking_order',
65                'id' => $pickingOrder->getKey()
66            ]),
67            'position' => $position . '/' . count($pickingOrderIds),
68            'orderDetails' => $getOrderDetails,
69            'withItems' => true,
70        ];
71    }
72
73    /**
74     * @param PickingOrder $pickingOrder
75     * @param User $user
76     * @return array
77     */
78    public function summarized(PickingOrder $pickingOrder, User $user): array
79    {
80        $pickingOrderIds = $pickingOrder->stockIO->pickingOrders()
81            ->orderBy('created_at')
82            ->get()
83            ->pluck('id');
84
85        $position = null;
86        foreach ($pickingOrderIds as $index => $id) {
87            if ($id == $pickingOrder->getKey()) {
88                $position = $index + 1;
89                break;
90            }
91        }
92        $pickingOrder->load('stockIO.integration');
93
94        return [
95            'pickingOrder' => $pickingOrder,
96            'customer' => AppHelper::fetchCustomer($pickingOrder->stockIO->integration->parameters['CODCLI']),
97            'now' => Carbon::now()->format('d/m/Y H:i'),
98            'generatedBy' => Auth::user()?->getAttribute('name'),
99            'qrcode' => json_encode([
100                'type' => 'picking_order',
101                'id' => $pickingOrder->getKey()
102            ]),
103            'position' => $position . '/' . count($pickingOrderIds),
104            'withItems' => false,
105        ];
106    }
107}