import chunk reading
This commit is contained in:
		@@ -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(),
 | 
			
		||||
        ];
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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();
 | 
			
		||||
       }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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();
 | 
			
		||||
       }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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();
 | 
			
		||||
       }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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();
 | 
			
		||||
       }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,50 +0,0 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace App\Imports\Purchases\Sheets;
 | 
			
		||||
 | 
			
		||||
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 BillPayments implements ToModel, WithHeadingRow, WithMapping, WithValidation
 | 
			
		||||
{
 | 
			
		||||
    public function model(array $row)
 | 
			
		||||
    {
 | 
			
		||||
        return new Model($row);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function map($row): array
 | 
			
		||||
    {
 | 
			
		||||
        $row['company_id'] = session('company_id');
 | 
			
		||||
        $row['type'] = 'expense';
 | 
			
		||||
 | 
			
		||||
        // 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' => 'bill_payments',
 | 
			
		||||
                'line' => $failure->attribute(),
 | 
			
		||||
            ]);
 | 
			
		||||
    
 | 
			
		||||
            flash($message)->error()->important();
 | 
			
		||||
       }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -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();
 | 
			
		||||
       }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										33
									
								
								app/Imports/Purchases/Sheets/BillTransactions.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								app/Imports/Purchases/Sheets/BillTransactions.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,33 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace App\Imports\Purchases\Sheets;
 | 
			
		||||
 | 
			
		||||
use App\Abstracts\Import;
 | 
			
		||||
use App\Models\Banking\Transaction as Model;
 | 
			
		||||
use App\Http\Requests\Banking\Transaction as Request;
 | 
			
		||||
 | 
			
		||||
class BillTransactions extends Import
 | 
			
		||||
{
 | 
			
		||||
    public function model(array $row)
 | 
			
		||||
    {
 | 
			
		||||
        return new Model($row);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function map($row): array
 | 
			
		||||
    {
 | 
			
		||||
        $row['company_id'] = session('company_id');
 | 
			
		||||
        $row['type'] = 'expense';
 | 
			
		||||
 | 
			
		||||
        // Make reconciled field integer
 | 
			
		||||
        if (isset($row['reconciled'])) {
 | 
			
		||||
            $row['reconciled'] = (int) $row['reconciled'];
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return $row;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function rules(): array
 | 
			
		||||
    {
 | 
			
		||||
        return (new Request())->rules();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -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();
 | 
			
		||||
       }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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();
 | 
			
		||||
       }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user