-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
InvoiceHistories.php
46 lines (34 loc) · 1023 Bytes
/
InvoiceHistories.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
namespace App\Imports\Sales\Sheets;
use App\Abstracts\Import;
use App\Http\Requests\Sale\InvoiceHistory as Request;
use App\Models\Sale\Invoice;
use App\Models\Sale\InvoiceHistory as Model;
class InvoiceHistories extends Import
{
public function model(array $row)
{
// @todo remove after laravel-excel 3.2 release
if ($row['invoice_number'] == $this->empty_field) {
return null;
}
return new Model($row);
}
public function map($row): array
{
if ($this->isEmpty($row, 'invoice_number')) {
return [];
}
$row = parent::map($row);
$row['invoice_id'] = (int) Invoice::number($row['invoice_number'])->pluck('id')->first();
$row['notify'] = (int) $row['notify'];
return $row;
}
public function rules(): array
{
$rules = (new Request())->rules();
$rules['invoice_number'] = 'required|string';
unset($rules['invoice_id']);
return $rules;
}
}