diff --git a/app/Imports/Purchases/Sheets/BillPayments.php b/app/Abstracts/Import.php similarity index 57% rename from app/Imports/Purchases/Sheets/BillPayments.php rename to app/Abstracts/Import.php index 1a53af47d..d6e5f5c3e 100644 --- a/app/Imports/Purchases/Sheets/BillPayments.php +++ b/app/Abstracts/Import.php @@ -1,26 +1,26 @@ rules(); + return []; + } + + public function batchSize(): int + { + return 100; + } + + public function chunkSize(): int + { + return 100; } public function onFailure(Failure ...$failures) { + $sheet = Str::snake((new \ReflectionClass($this))->getShortName()); + foreach ($failures as $failure) { $message = trans('messages.error.import_column', [ 'message' => $failure->errors()->first(), - 'sheet' => 'bill_payments', + 'sheet' => $sheet, 'line' => $failure->attribute(), ]); - + flash($message)->error()->important(); } } -} \ No newline at end of file +} diff --git a/app/Imports/Banking/Transactions.php b/app/Imports/Banking/Transactions.php index 37ca4c366..75a25e98e 100644 --- a/app/Imports/Banking/Transactions.php +++ b/app/Imports/Banking/Transactions.php @@ -2,48 +2,19 @@ namespace App\Imports\Banking; +use App\Abstracts\Import; use App\Models\Banking\Transaction as Model; use App\Http\Requests\Banking\Transaction as Request; -use Maatwebsite\Excel\Concerns\ToModel; -use Maatwebsite\Excel\Concerns\WithHeadingRow; -use Maatwebsite\Excel\Concerns\WithMapping; -use Maatwebsite\Excel\Concerns\WithValidation; -use Maatwebsite\Excel\Validators\Failure; -class Transactions implements ToModel, WithHeadingRow, WithMapping, WithValidation +class Transactions extends Import { public function model(array $row) { return new Model($row); } - public function map($row): array - { - $row['company_id'] = session('company_id'); - - // Make reconciled field integer - if (isset($row['reconciled'])) { - $row['reconciled'] = (int) $row['reconciled']; - } - - return $row; - } - public function rules(): array { return (new Request())->rules(); } - - public function onFailure(Failure ...$failures) - { - foreach ($failures as $failure) { - $message = trans('messages.error.import_column', [ - 'message' => $failure->errors()->first(), - 'sheet' => 'transactions', - 'line' => $failure->attribute(), - ]); - - flash($message)->error()->important(); - } - } -} \ No newline at end of file +} diff --git a/app/Imports/Common/Items.php b/app/Imports/Common/Items.php index 59ad08e15..44c2cbd26 100644 --- a/app/Imports/Common/Items.php +++ b/app/Imports/Common/Items.php @@ -2,16 +2,12 @@ namespace App\Imports\Common; +use App\Abstracts\Import; use App\Models\Common\Item as Model; use App\Http\Requests\Common\Item as Request; use App\Jobs\Common\CreateItem; -use Maatwebsite\Excel\Concerns\ToModel; -use Maatwebsite\Excel\Concerns\WithHeadingRow; -use Maatwebsite\Excel\Concerns\WithMapping; -use Maatwebsite\Excel\Concerns\WithValidation; -use Maatwebsite\Excel\Validators\Failure; -class Items implements ToModel, WithHeadingRow, WithMapping, WithValidation +class Items extends Import { public function model(array $row) { @@ -21,33 +17,8 @@ class Items implements ToModel, WithHeadingRow, WithMapping, WithValidation //return dispatch_now(new CreateItem($request)); } - public function map($row): array - { - $row['company_id'] = session('company_id'); - - // Make enabled field integer - if (isset($row['enabled'])) { - $row['enabled'] = (int) $row['enabled']; - } - - return $row; - } - public function rules(): array { return (new Request())->rules(); } - - public function onFailure(Failure ...$failures) - { - foreach ($failures as $failure) { - $message = trans('messages.error.import_column', [ - 'message' => $failure->errors()->first(), - 'sheet' => 'items', - 'line' => $failure->attribute(), - ]); - - flash($message)->error()->important(); - } - } } diff --git a/app/Imports/Purchases/Bills.php b/app/Imports/Purchases/Bills.php index de550736c..ca871a727 100644 --- a/app/Imports/Purchases/Bills.php +++ b/app/Imports/Purchases/Bills.php @@ -6,8 +6,8 @@ use App\Imports\Purchases\Sheets\Bills as Base; use App\Imports\Purchases\Sheets\BillItems; use App\Imports\Purchases\Sheets\BillItemTaxes; use App\Imports\Purchases\Sheets\BillHistories; -use App\Imports\Purchases\Sheets\BillPayments; use App\Imports\Purchases\Sheets\BillTotals; +use App\Imports\Purchases\Sheets\BillTransactions; use Maatwebsite\Excel\Concerns\WithMultipleSheets; class Bills implements WithMultipleSheets @@ -19,8 +19,8 @@ class Bills implements WithMultipleSheets 'bill_items' => new BillItems(), 'bill_item_taxes' => new BillItemTaxes(), 'bill_histories' => new BillHistories(), - 'bill_payments' => new BillPayments(), 'bill_totals' => new BillTotals(), + 'bill_transactions' => new BillTransactions(), ]; } -} \ No newline at end of file +} diff --git a/app/Imports/Purchases/Payments.php b/app/Imports/Purchases/Payments.php index 38b2cde34..5b34e8256 100644 --- a/app/Imports/Purchases/Payments.php +++ b/app/Imports/Purchases/Payments.php @@ -2,15 +2,12 @@ namespace App\Imports\Purchases; +use App\Abstracts\Import; use App\Models\Banking\Transaction as Model; use App\Http\Requests\Banking\Transaction as Request; -use Maatwebsite\Excel\Concerns\ToModel; -use Maatwebsite\Excel\Concerns\WithHeadingRow; -use Maatwebsite\Excel\Concerns\WithMapping; -use Maatwebsite\Excel\Concerns\WithValidation; -use Maatwebsite\Excel\Validators\Failure; +use Jenssegers\Date\Date; -class Payments implements ToModel, WithHeadingRow, WithMapping, WithValidation +class Payments extends Import { public function model(array $row) { @@ -21,6 +18,7 @@ class Payments implements ToModel, WithHeadingRow, WithMapping, WithValidation { $row['company_id'] = session('company_id'); $row['type'] = 'expense'; + $row['paid_at'] = Date::parse($row['paid_at'])->format('Y-m-d H:i:s'); // Make reconciled field integer if (isset($row['reconciled'])) { @@ -34,17 +32,4 @@ class Payments implements ToModel, WithHeadingRow, WithMapping, WithValidation { return (new Request())->rules(); } - - public function onFailure(Failure ...$failures) - { - foreach ($failures as $failure) { - $message = trans('messages.error.import_column', [ - 'message' => $failure->errors()->first(), - 'sheet' => 'payments', - 'line' => $failure->attribute(), - ]); - - flash($message)->error()->important(); - } - } -} \ No newline at end of file +} diff --git a/app/Imports/Purchases/Sheets/BillHistories.php b/app/Imports/Purchases/Sheets/BillHistories.php index a8d134388..d5bae8e6a 100644 --- a/app/Imports/Purchases/Sheets/BillHistories.php +++ b/app/Imports/Purchases/Sheets/BillHistories.php @@ -2,43 +2,19 @@ namespace App\Imports\Purchases\Sheets; +use App\Abstracts\Import; use App\Models\Purchase\BillHistory as Model; use App\Http\Requests\Purchase\BillHistory as Request; -use Maatwebsite\Excel\Concerns\ToModel; -use Maatwebsite\Excel\Concerns\WithHeadingRow; -use Maatwebsite\Excel\Concerns\WithMapping; -use Maatwebsite\Excel\Concerns\WithValidation; -use Maatwebsite\Excel\Validators\Failure; -class BillHistories implements ToModel, WithHeadingRow, WithMapping, WithValidation +class BillHistories extends Import { public function model(array $row) { return new Model($row); } - public function map($row): array - { - $row['company_id'] = session('company_id'); - - return $row; - } - public function rules(): array { return (new Request())->rules(); } - - public function onFailure(Failure ...$failures) - { - foreach ($failures as $failure) { - $message = trans('messages.error.import_column', [ - 'message' => $failure->errors()->first(), - 'sheet' => 'bill_histories', - 'line' => $failure->attribute(), - ]); - - flash($message)->error()->important(); - } - } -} \ No newline at end of file +} diff --git a/app/Imports/Purchases/Sheets/BillItemTaxes.php b/app/Imports/Purchases/Sheets/BillItemTaxes.php index 8740e13c6..f0ba171a8 100644 --- a/app/Imports/Purchases/Sheets/BillItemTaxes.php +++ b/app/Imports/Purchases/Sheets/BillItemTaxes.php @@ -2,36 +2,13 @@ namespace App\Imports\Purchases\Sheets; +use App\Abstracts\Import; use App\Models\Purchase\BillItemTax as Model; -use Maatwebsite\Excel\Concerns\ToModel; -use Maatwebsite\Excel\Concerns\WithHeadingRow; -use Maatwebsite\Excel\Concerns\WithMapping; -use Maatwebsite\Excel\Validators\Failure; -class BillItemTaxes implements ToModel, WithHeadingRow, WithMapping +class BillItemTaxes extends Import { public function model(array $row) { return new Model($row); } - - public function map($row): array - { - $row['company_id'] = session('company_id'); - - return $row; - } - - public function onFailure(Failure ...$failures) - { - foreach ($failures as $failure) { - $message = trans('messages.error.import_column', [ - 'message' => $failure->errors()->first(), - 'sheet' => 'bill_item_taxes', - 'line' => $failure->attribute(), - ]); - - flash($message)->error()->important(); - } - } -} \ No newline at end of file +} diff --git a/app/Imports/Purchases/Sheets/BillItems.php b/app/Imports/Purchases/Sheets/BillItems.php index c006f23bd..51acb287d 100644 --- a/app/Imports/Purchases/Sheets/BillItems.php +++ b/app/Imports/Purchases/Sheets/BillItems.php @@ -2,43 +2,19 @@ namespace App\Imports\Purchases\Sheets; +use App\Abstracts\Import; use App\Models\Purchase\BillItem as Model; use App\Http\Requests\Purchase\BillItem as Request; -use Maatwebsite\Excel\Concerns\ToModel; -use Maatwebsite\Excel\Concerns\WithHeadingRow; -use Maatwebsite\Excel\Concerns\WithMapping; -use Maatwebsite\Excel\Concerns\WithValidation; -use Maatwebsite\Excel\Validators\Failure; -class BillItems implements ToModel, WithHeadingRow, WithMapping, WithValidation +class BillItems extends Import { public function model(array $row) { return new Model($row); } - public function map($row): array - { - $row['company_id'] = session('company_id'); - - return $row; - } - public function rules(): array { return (new Request())->rules(); } - - public function onFailure(Failure ...$failures) - { - foreach ($failures as $failure) { - $message = trans('messages.error.import_column', [ - 'message' => $failure->errors()->first(), - 'sheet' => 'bill_items', - 'line' => $failure->attribute(), - ]); - - flash($message)->error()->important(); - } - } -} \ No newline at end of file +} diff --git a/app/Imports/Purchases/Sheets/BillTotals.php b/app/Imports/Purchases/Sheets/BillTotals.php index f6983c442..18b93a0a2 100644 --- a/app/Imports/Purchases/Sheets/BillTotals.php +++ b/app/Imports/Purchases/Sheets/BillTotals.php @@ -2,43 +2,19 @@ namespace App\Imports\Purchases\Sheets; +use App\Abstracts\Import; use App\Models\Purchase\BillTotal as Model; use App\Http\Requests\Purchase\BillTotal as Request; -use Maatwebsite\Excel\Concerns\ToModel; -use Maatwebsite\Excel\Concerns\WithHeadingRow; -use Maatwebsite\Excel\Concerns\WithMapping; -use Maatwebsite\Excel\Concerns\WithValidation; -use Maatwebsite\Excel\Validators\Failure; -class BillTotals implements ToModel, WithHeadingRow, WithMapping, WithValidation +class BillTotals extends Import { public function model(array $row) { return new Model($row); } - public function map($row): array - { - $row['company_id'] = session('company_id'); - - return $row; - } - public function rules(): array { return (new Request())->rules(); } - - public function onFailure(Failure ...$failures) - { - foreach ($failures as $failure) { - $message = trans('messages.error.import_column', [ - 'message' => $failure->errors()->first(), - 'sheet' => 'bill_totals', - 'line' => $failure->attribute(), - ]); - - flash($message)->error()->important(); - } - } -} \ No newline at end of file +} diff --git a/app/Imports/Purchases/Sheets/BillTransactions.php b/app/Imports/Purchases/Sheets/BillTransactions.php new file mode 100644 index 000000000..5440c223d --- /dev/null +++ b/app/Imports/Purchases/Sheets/BillTransactions.php @@ -0,0 +1,33 @@ +rules(); + } +} diff --git a/app/Imports/Purchases/Sheets/Bills.php b/app/Imports/Purchases/Sheets/Bills.php index 45c4f8f95..f50ca9d45 100644 --- a/app/Imports/Purchases/Sheets/Bills.php +++ b/app/Imports/Purchases/Sheets/Bills.php @@ -2,43 +2,19 @@ namespace App\Imports\Purchases\Sheets; +use App\Abstracts\Import; use App\Models\Purchase\Bill as Model; use App\Http\Requests\Purchase\Bill as Request; -use Maatwebsite\Excel\Concerns\ToModel; -use Maatwebsite\Excel\Concerns\WithHeadingRow; -use Maatwebsite\Excel\Concerns\WithMapping; -use Maatwebsite\Excel\Concerns\WithValidation; -use Maatwebsite\Excel\Validators\Failure; -class Bills implements ToModel, WithHeadingRow, WithMapping, WithValidation +class Bills extends Import { public function model(array $row) { return new Model($row); } - public function map($row): array - { - $row['company_id'] = session('company_id'); - - return $row; - } - public function rules(): array { return (new Request())->rules(); } - - public function onFailure(Failure ...$failures) - { - foreach ($failures as $failure) { - $message = trans('messages.error.import_column', [ - 'message' => $failure->errors()->first(), - 'sheet' => 'bills', - 'line' => $failure->attribute(), - ]); - - flash($message)->error()->important(); - } - } -} \ No newline at end of file +} diff --git a/app/Imports/Purchases/Vendors.php b/app/Imports/Purchases/Vendors.php index 5f6440c64..832d35100 100644 --- a/app/Imports/Purchases/Vendors.php +++ b/app/Imports/Purchases/Vendors.php @@ -2,15 +2,11 @@ namespace App\Imports\Purchases; +use App\Abstracts\Import; use App\Models\Common\Contact as Model; use App\Http\Requests\Common\Contact as Request; -use Maatwebsite\Excel\Concerns\ToModel; -use Maatwebsite\Excel\Concerns\WithHeadingRow; -use Maatwebsite\Excel\Concerns\WithMapping; -use Maatwebsite\Excel\Concerns\WithValidation; -use Maatwebsite\Excel\Validators\Failure; -class Vendors implements ToModel, WithHeadingRow, WithMapping, WithValidation +class Vendors extends Import { public function model(array $row) { @@ -34,17 +30,4 @@ class Vendors implements ToModel, WithHeadingRow, WithMapping, WithValidation { return (new Request())->rules(); } - - public function onFailure(Failure ...$failures) - { - foreach ($failures as $failure) { - $message = trans('messages.error.import_column', [ - 'message' => $failure->errors()->first(), - 'sheet' => 'vendors', - 'line' => $failure->attribute(), - ]); - - flash($message)->error()->important(); - } - } -} \ No newline at end of file +} diff --git a/app/Imports/Sales/Customers.php b/app/Imports/Sales/Customers.php index 307482887..5dcf7da41 100644 --- a/app/Imports/Sales/Customers.php +++ b/app/Imports/Sales/Customers.php @@ -2,15 +2,11 @@ namespace App\Imports\Sales; +use App\Abstracts\Import; use App\Models\Common\Contact as Model; use App\Http\Requests\Common\Contact as Request; -use Maatwebsite\Excel\Concerns\ToModel; -use Maatwebsite\Excel\Concerns\WithHeadingRow; -use Maatwebsite\Excel\Concerns\WithMapping; -use Maatwebsite\Excel\Concerns\WithValidation; -use Maatwebsite\Excel\Validators\Failure; -class Customers implements ToModel, WithHeadingRow, WithMapping, WithValidation +class Customers extends Import { public function model(array $row) { @@ -34,17 +30,4 @@ class Customers implements ToModel, WithHeadingRow, WithMapping, WithValidation { return (new Request())->rules(); } - - public function onFailure(Failure ...$failures) - { - foreach ($failures as $failure) { - $message = trans('messages.error.import_column', [ - 'message' => $failure->errors()->first(), - 'sheet' => 'customers', - 'line' => $failure->attribute(), - ]); - - flash($message)->error()->important(); - } - } -} \ No newline at end of file +} diff --git a/app/Imports/Sales/Invoices.php b/app/Imports/Sales/Invoices.php index a45b0d748..6edd87328 100644 --- a/app/Imports/Sales/Invoices.php +++ b/app/Imports/Sales/Invoices.php @@ -6,8 +6,8 @@ use App\Imports\Sales\Sheets\Invoices as Base; use App\Imports\Sales\Sheets\InvoiceItems; use App\Imports\Sales\Sheets\InvoiceItemTaxes; use App\Imports\Sales\Sheets\InvoiceHistories; -use App\Imports\Sales\Sheets\InvoicePayments; use App\Imports\Sales\Sheets\InvoiceTotals; +use App\Imports\Sales\Sheets\InvoiceTranactions; use Maatwebsite\Excel\Concerns\WithMultipleSheets; class Invoices implements WithMultipleSheets @@ -19,8 +19,8 @@ class Invoices implements WithMultipleSheets 'invoice_items' => new InvoiceItems(), 'invoice_item_taxes' => new InvoiceItemTaxes(), 'invoice_histories' => new InvoiceHistories(), - 'invoice_payments' => new InvoicePayments(), 'invoice_totals' => new InvoiceTotals(), + 'invoice_transactions' => new InvoiceTranactions(), ]; } -} \ No newline at end of file +} diff --git a/app/Imports/Sales/Revenues.php b/app/Imports/Sales/Revenues.php index 0edbe9c58..d6deccefc 100644 --- a/app/Imports/Sales/Revenues.php +++ b/app/Imports/Sales/Revenues.php @@ -2,15 +2,12 @@ namespace App\Imports\Income; +use App\Abstracts\Import; use App\Models\Banking\Transaction as Model; use App\Http\Requests\Banking\Transaction as Request; -use Maatwebsite\Excel\Concerns\ToModel; -use Maatwebsite\Excel\Concerns\WithHeadingRow; -use Maatwebsite\Excel\Concerns\WithMapping; -use Maatwebsite\Excel\Concerns\WithValidation; -use Maatwebsite\Excel\Validators\Failure; +use Jenssegers\Date\Date; -class Revenues implements ToModel, WithHeadingRow, WithMapping, WithValidation +class Revenues extends Import { public function model(array $row) { @@ -21,6 +18,7 @@ class Revenues implements ToModel, WithHeadingRow, WithMapping, WithValidation { $row['company_id'] = session('company_id'); $row['type'] = 'income'; + $row['paid_at'] = Date::parse($row['paid_at'])->format('Y-m-d H:i:s'); // Make reconciled field integer if (isset($row['reconciled'])) { @@ -34,17 +32,4 @@ class Revenues implements ToModel, WithHeadingRow, WithMapping, WithValidation { return (new Request())->rules(); } - - public function onFailure(Failure ...$failures) - { - foreach ($failures as $failure) { - $message = trans('messages.error.import_column', [ - 'message' => $failure->errors()->first(), - 'sheet' => 'revenues', - 'line' => $failure->attribute(), - ]); - - flash($message)->error()->important(); - } - } -} \ No newline at end of file +} diff --git a/app/Imports/Sales/Sheets/InvoiceHistories.php b/app/Imports/Sales/Sheets/InvoiceHistories.php index 425c4df59..d64967a7b 100644 --- a/app/Imports/Sales/Sheets/InvoiceHistories.php +++ b/app/Imports/Sales/Sheets/InvoiceHistories.php @@ -2,43 +2,19 @@ namespace App\Imports\Sales\Sheets; +use App\Abstracts\Import; use App\Models\Sale\InvoiceHistory as Model; use App\Http\Requests\Sale\InvoiceHistory as Request; -use Maatwebsite\Excel\Concerns\ToModel; -use Maatwebsite\Excel\Concerns\WithHeadingRow; -use Maatwebsite\Excel\Concerns\WithMapping; -use Maatwebsite\Excel\Concerns\WithValidation; -use Maatwebsite\Excel\Validators\Failure; -class InvoiceHistories implements ToModel, WithHeadingRow, WithMapping, WithValidation +class InvoiceHistories extends Import { public function model(array $row) { return new Model($row); } - public function map($row): array - { - $row['company_id'] = session('company_id'); - - return $row; - } - public function rules(): array { return (new Request())->rules(); } - - public function onFailure(Failure ...$failures) - { - foreach ($failures as $failure) { - $message = trans('messages.error.import_column', [ - 'message' => $failure->errors()->first(), - 'sheet' => 'invoice_histories', - 'line' => $failure->attribute(), - ]); - - flash($message)->error()->important(); - } - } -} \ No newline at end of file +} diff --git a/app/Imports/Sales/Sheets/InvoiceItemTaxes.php b/app/Imports/Sales/Sheets/InvoiceItemTaxes.php index 1222ac20d..f6100e4ab 100644 --- a/app/Imports/Sales/Sheets/InvoiceItemTaxes.php +++ b/app/Imports/Sales/Sheets/InvoiceItemTaxes.php @@ -2,36 +2,13 @@ namespace App\Imports\Sales\Sheets; +use App\Abstracts\Import; use App\Models\Sale\InvoiceItemTax as Model; -use Maatwebsite\Excel\Concerns\ToModel; -use Maatwebsite\Excel\Concerns\WithHeadingRow; -use Maatwebsite\Excel\Concerns\WithMapping; -use Maatwebsite\Excel\Validators\Failure; -class InvoiceItemTaxes implements ToModel, WithHeadingRow, WithMapping +class InvoiceItemTaxes extends Import { public function model(array $row) { return new Model($row); } - - public function map($row): array - { - $row['company_id'] = session('company_id'); - - return $row; - } - - public function onFailure(Failure ...$failures) - { - foreach ($failures as $failure) { - $message = trans('messages.error.import_column', [ - 'message' => $failure->errors()->first(), - 'sheet' => 'invoice_item_taxes', - 'line' => $failure->attribute(), - ]); - - flash($message)->error()->important(); - } - } -} \ No newline at end of file +} diff --git a/app/Imports/Sales/Sheets/InvoiceItems.php b/app/Imports/Sales/Sheets/InvoiceItems.php index 6a7ed5b17..0f5ebf726 100644 --- a/app/Imports/Sales/Sheets/InvoiceItems.php +++ b/app/Imports/Sales/Sheets/InvoiceItems.php @@ -2,43 +2,19 @@ namespace App\Imports\Sales\Sheets; +use App\Abstracts\Import; use App\Models\Sale\InvoiceItem as Model; use App\Http\Requests\Sale\InvoiceItem as Request; -use Maatwebsite\Excel\Concerns\ToModel; -use Maatwebsite\Excel\Concerns\WithHeadingRow; -use Maatwebsite\Excel\Concerns\WithMapping; -use Maatwebsite\Excel\Concerns\WithValidation; -use Maatwebsite\Excel\Validators\Failure; -class InvoiceItems implements ToModel, WithHeadingRow, WithMapping, WithValidation +class InvoiceItems extends Import { public function model(array $row) { return new Model($row); } - public function map($row): array - { - $row['company_id'] = session('company_id'); - - return $row; - } - public function rules(): array { return (new Request())->rules(); } - - public function onFailure(Failure ...$failures) - { - foreach ($failures as $failure) { - $message = trans('messages.error.import_column', [ - 'message' => $failure->errors()->first(), - 'sheet' => 'invoice_items', - 'line' => $failure->attribute(), - ]); - - flash($message)->error()->important(); - } - } -} \ No newline at end of file +} diff --git a/app/Imports/Sales/Sheets/InvoicePayments.php b/app/Imports/Sales/Sheets/InvoicePayments.php deleted file mode 100644 index 63b1343a9..000000000 --- a/app/Imports/Sales/Sheets/InvoicePayments.php +++ /dev/null @@ -1,50 +0,0 @@ -rules(); - } - - public function onFailure(Failure ...$failures) - { - foreach ($failures as $failure) { - $message = trans('messages.error.import_column', [ - 'message' => $failure->errors()->first(), - 'sheet' => 'invoice_payments', - 'line' => $failure->attribute(), - ]); - - flash($message)->error()->important(); - } - } -} \ No newline at end of file diff --git a/app/Imports/Sales/Sheets/InvoiceTotals.php b/app/Imports/Sales/Sheets/InvoiceTotals.php index c0ac4b567..d36c0d1d4 100644 --- a/app/Imports/Sales/Sheets/InvoiceTotals.php +++ b/app/Imports/Sales/Sheets/InvoiceTotals.php @@ -2,43 +2,19 @@ namespace App\Imports\Sales\Sheets; +use App\Abstracts\Import; use App\Models\Sale\InvoiceTotal as Model; use App\Http\Requests\Sale\InvoiceTotal as Request; -use Maatwebsite\Excel\Concerns\ToModel; -use Maatwebsite\Excel\Concerns\WithHeadingRow; -use Maatwebsite\Excel\Concerns\WithMapping; -use Maatwebsite\Excel\Concerns\WithValidation; -use Maatwebsite\Excel\Validators\Failure; -class InvoiceTotals implements ToModel, WithHeadingRow, WithMapping, WithValidation +class InvoiceTotals extends Import { public function model(array $row) { return new Model($row); } - public function map($row): array - { - $row['company_id'] = session('company_id'); - - return $row; - } - public function rules(): array { return (new Request())->rules(); } - - public function onFailure(Failure ...$failures) - { - foreach ($failures as $failure) { - $message = trans('messages.error.import_column', [ - 'message' => $failure->errors()->first(), - 'sheet' => 'invoice_totals', - 'line' => $failure->attribute(), - ]); - - flash($message)->error()->important(); - } - } -} \ No newline at end of file +} diff --git a/app/Imports/Sales/Sheets/InvoiceTranactions.php b/app/Imports/Sales/Sheets/InvoiceTranactions.php new file mode 100644 index 000000000..7792cdd6b --- /dev/null +++ b/app/Imports/Sales/Sheets/InvoiceTranactions.php @@ -0,0 +1,33 @@ +rules(); + } +} diff --git a/app/Imports/Sales/Sheets/Invoices.php b/app/Imports/Sales/Sheets/Invoices.php index a02689d6a..dd5e0b75d 100644 --- a/app/Imports/Sales/Sheets/Invoices.php +++ b/app/Imports/Sales/Sheets/Invoices.php @@ -2,43 +2,19 @@ namespace App\Imports\Sales\Sheets; +use App\Abstracts\Import; use App\Models\Sale\Invoice as Model; use App\Http\Requests\Sale\Invoice as Request; -use Maatwebsite\Excel\Concerns\ToModel; -use Maatwebsite\Excel\Concerns\WithHeadingRow; -use Maatwebsite\Excel\Concerns\WithMapping; -use Maatwebsite\Excel\Concerns\WithValidation; -use Maatwebsite\Excel\Validators\Failure; -class Invoices implements ToModel, WithHeadingRow, WithMapping, WithValidation +class Invoices extends Import { public function model(array $row) { return new Model($row); } - public function map($row): array - { - $row['company_id'] = session('company_id'); - - return $row; - } - public function rules(): array { return (new Request())->rules(); } - - public function onFailure(Failure ...$failures) - { - foreach ($failures as $failure) { - $message = trans('messages.error.import_column', [ - 'message' => $failure->errors()->first(), - 'sheet' => 'invoices', - 'line' => $failure->attribute(), - ]); - - flash($message)->error()->important(); - } - } -} \ No newline at end of file +}