Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 32
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
InvoiceQueryBuilder
0.00% covered (danger)
0.00%
0 / 32
0.00% covered (danger)
0.00%
0 / 1
132
0.00% covered (danger)
0.00%
0 / 1
 search
0.00% covered (danger)
0.00%
0 / 32
0.00% covered (danger)
0.00%
0 / 1
132
1<?php
2
3namespace Domain\Invoice\QueryBuilders;
4
5use Domain\Invoice\DTOs\SearchInvoiceDTO;
6use Domain\Invoice\Enums\InvoiceVerificationsStatusEnum;
7use Illuminate\Database\Eloquent\Builder;
8
9class InvoiceQueryBuilder extends Builder
10{
11
12    /**
13     * @param SearchInvoiceDTO $invoiceDTO
14     * @return $this
15     */
16    public function search(SearchInvoiceDTO $invoiceDTO): static
17    {
18        if ($invoiceDTO->key) {
19            $this->where('key', $invoiceDTO->key);
20        }
21
22        if (count($invoiceDTO->status) > 0) {
23            $this->whereIn('status', $invoiceDTO->status);
24        }
25
26        if ($invoiceDTO->issue_date) {
27            $this->whereBetween('issue_date', [
28                $invoiceDTO->issue_date[0]->startOfDay(),
29                $invoiceDTO->issue_date[1]->endOfDay(),
30            ]);
31        }
32
33        if (count($invoiceDTO->suppliers) > 0) {
34            $this->whereIn('supplier_id', $invoiceDTO->suppliers);
35        }
36
37        if (count($invoiceDTO->purchase_order_status) > 0) {
38            $this->whereIn('purchase_order_status', $invoiceDTO->purchase_order_status);
39        }
40
41        if (count($invoiceDTO->verification_status) > 0) {
42            $this->whereIn('verification_status', $invoiceDTO->verification_status);
43        }
44
45        if ($invoiceDTO->id) {
46            $this->where('id', $invoiceDTO->id);
47        }
48
49        if ($invoiceDTO->has_additional_itens) {
50            $this->whereHas('invoiceVerification', function (Builder $builder) {
51                $builder->where('status', InvoiceVerificationsStatusEnum::ADDITIONAL_ITEM);
52            });
53        }
54
55        if ($invoiceDTO->created_at) {
56            $this->whereBetween('created_at', [
57                $invoiceDTO->created_at[0]->startOfDay(),
58                $invoiceDTO->created_at[1]->endOfDay(),
59            ]);
60        }
61
62        if ($invoiceDTO->updated_at) {
63            $this->whereBetween('updated_at', [
64                $invoiceDTO->updated_at[0]->startOfDay(),
65                $invoiceDTO->updated_at[1]->endOfDay(),
66            ]);
67        }
68
69        return $this;
70    }
71}