improved import mapping
This commit is contained in:
parent
d7cf148958
commit
f58a15034a
@ -3,6 +3,7 @@
|
|||||||
namespace App\Abstracts;
|
namespace App\Abstracts;
|
||||||
|
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
use Jenssegers\Date\Date;
|
||||||
use Maatwebsite\Excel\Concerns\ToModel;
|
use Maatwebsite\Excel\Concerns\ToModel;
|
||||||
use Maatwebsite\Excel\Concerns\WithBatchInserts;
|
use Maatwebsite\Excel\Concerns\WithBatchInserts;
|
||||||
use Maatwebsite\Excel\Concerns\WithChunkReading;
|
use Maatwebsite\Excel\Concerns\WithChunkReading;
|
||||||
@ -27,6 +28,15 @@ abstract class Import implements ToModel, WithBatchInserts, WithChunkReading, Wi
|
|||||||
$row['reconciled'] = (int) $row['reconciled'];
|
$row['reconciled'] = (int) $row['reconciled'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$date_fields = ['paid_at', 'invoiced_at', 'billed_at', 'due_at', 'issued_at', 'created_at'];
|
||||||
|
foreach ($date_fields as $date_field) {
|
||||||
|
if (!isset($row[$date_field])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$row[$date_field] = Date::parse($row[$date_field])->format('Y-m-d H:i:s');
|
||||||
|
}
|
||||||
|
|
||||||
return $row;
|
return $row;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,7 +5,6 @@ namespace App\Imports\Purchases;
|
|||||||
use App\Abstracts\Import;
|
use App\Abstracts\Import;
|
||||||
use App\Models\Banking\Transaction as Model;
|
use App\Models\Banking\Transaction as Model;
|
||||||
use App\Http\Requests\Banking\Transaction as Request;
|
use App\Http\Requests\Banking\Transaction as Request;
|
||||||
use Jenssegers\Date\Date;
|
|
||||||
|
|
||||||
class Payments extends Import
|
class Payments extends Import
|
||||||
{
|
{
|
||||||
@ -16,14 +15,9 @@ class Payments extends Import
|
|||||||
|
|
||||||
public function map($row): array
|
public function map($row): array
|
||||||
{
|
{
|
||||||
$row['company_id'] = session('company_id');
|
$row = parent::map($row);
|
||||||
$row['type'] = 'expense';
|
|
||||||
$row['paid_at'] = Date::parse($row['paid_at'])->format('Y-m-d H:i:s');
|
|
||||||
|
|
||||||
// Make reconciled field integer
|
$row['type'] = 'expense';
|
||||||
if (isset($row['reconciled'])) {
|
|
||||||
$row['reconciled'] = (int) $row['reconciled'];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $row;
|
return $row;
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@ namespace App\Imports\Purchases\Sheets;
|
|||||||
use App\Abstracts\Import;
|
use App\Abstracts\Import;
|
||||||
use App\Models\Banking\Transaction as Model;
|
use App\Models\Banking\Transaction as Model;
|
||||||
use App\Http\Requests\Banking\Transaction as Request;
|
use App\Http\Requests\Banking\Transaction as Request;
|
||||||
use Jenssegers\Date\Date;
|
|
||||||
|
|
||||||
class BillTransactions extends Import
|
class BillTransactions extends Import
|
||||||
{
|
{
|
||||||
@ -16,14 +15,9 @@ class BillTransactions extends Import
|
|||||||
|
|
||||||
public function map($row): array
|
public function map($row): array
|
||||||
{
|
{
|
||||||
$row['company_id'] = session('company_id');
|
$row = parent::map($row);
|
||||||
$row['type'] = 'expense';
|
|
||||||
$row['paid_at'] = Date::parse($row['paid_at'])->format('Y-m-d H:i:s');
|
|
||||||
|
|
||||||
// Make reconciled field integer
|
$row['type'] = 'expense';
|
||||||
if (isset($row['reconciled'])) {
|
|
||||||
$row['reconciled'] = (int) $row['reconciled'];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $row;
|
return $row;
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@ namespace App\Imports\Purchases\Sheets;
|
|||||||
use App\Abstracts\Import;
|
use App\Abstracts\Import;
|
||||||
use App\Models\Purchase\Bill as Model;
|
use App\Models\Purchase\Bill as Model;
|
||||||
use App\Http\Requests\Purchase\Bill as Request;
|
use App\Http\Requests\Purchase\Bill as Request;
|
||||||
use Jenssegers\Date\Date;
|
|
||||||
|
|
||||||
class Bills extends Import
|
class Bills extends Import
|
||||||
{
|
{
|
||||||
@ -14,15 +13,6 @@ class Bills extends Import
|
|||||||
return new Model($row);
|
return new Model($row);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function map($row): array
|
|
||||||
{
|
|
||||||
$row['company_id'] = session('company_id');
|
|
||||||
$row['billed_at'] = Date::parse($row['billed_at'])->format('Y-m-d H:i:s');
|
|
||||||
$row['due_at'] = Date::parse($row['due_at'])->format('Y-m-d H:i:s');
|
|
||||||
|
|
||||||
return $row;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function rules(): array
|
public function rules(): array
|
||||||
{
|
{
|
||||||
return (new Request())->rules();
|
return (new Request())->rules();
|
||||||
|
@ -15,13 +15,9 @@ class Vendors extends Import
|
|||||||
|
|
||||||
public function map($row): array
|
public function map($row): array
|
||||||
{
|
{
|
||||||
$row['company_id'] = session('company_id');
|
$row = parent::map($row);
|
||||||
$row['type'] = 'vendor';
|
|
||||||
|
|
||||||
// Make enabled field integer
|
$row['type'] = 'vendor';
|
||||||
if (isset($row['enabled'])) {
|
|
||||||
$row['enabled'] = (int) $row['enabled'];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $row;
|
return $row;
|
||||||
}
|
}
|
||||||
|
@ -15,13 +15,9 @@ class Customers extends Import
|
|||||||
|
|
||||||
public function map($row): array
|
public function map($row): array
|
||||||
{
|
{
|
||||||
$row['company_id'] = session('company_id');
|
$row = parent::map($row);
|
||||||
$row['type'] = 'customer';
|
|
||||||
|
|
||||||
// Make enabled field integer
|
$row['type'] = 'customer';
|
||||||
if (isset($row['enabled'])) {
|
|
||||||
$row['enabled'] = (int) $row['enabled'];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $row;
|
return $row;
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@ namespace App\Imports\Sales;
|
|||||||
use App\Abstracts\Import;
|
use App\Abstracts\Import;
|
||||||
use App\Models\Banking\Transaction as Model;
|
use App\Models\Banking\Transaction as Model;
|
||||||
use App\Http\Requests\Banking\Transaction as Request;
|
use App\Http\Requests\Banking\Transaction as Request;
|
||||||
use Jenssegers\Date\Date;
|
|
||||||
|
|
||||||
class Revenues extends Import
|
class Revenues extends Import
|
||||||
{
|
{
|
||||||
@ -16,14 +15,9 @@ class Revenues extends Import
|
|||||||
|
|
||||||
public function map($row): array
|
public function map($row): array
|
||||||
{
|
{
|
||||||
$row['company_id'] = session('company_id');
|
$row = parent::map($row);
|
||||||
$row['type'] = 'income';
|
|
||||||
$row['paid_at'] = Date::parse($row['paid_at'])->format('Y-m-d H:i:s');
|
|
||||||
|
|
||||||
// Make reconciled field integer
|
$row['type'] = 'income';
|
||||||
if (isset($row['reconciled'])) {
|
|
||||||
$row['reconciled'] = (int) $row['reconciled'];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $row;
|
return $row;
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@ namespace App\Imports\Sales\Sheets;
|
|||||||
use App\Abstracts\Import;
|
use App\Abstracts\Import;
|
||||||
use App\Models\Banking\Transaction as Model;
|
use App\Models\Banking\Transaction as Model;
|
||||||
use App\Http\Requests\Banking\Transaction as Request;
|
use App\Http\Requests\Banking\Transaction as Request;
|
||||||
use Jenssegers\Date\Date;
|
|
||||||
|
|
||||||
class InvoiceTranactions extends Import
|
class InvoiceTranactions extends Import
|
||||||
{
|
{
|
||||||
@ -16,14 +15,9 @@ class InvoiceTranactions extends Import
|
|||||||
|
|
||||||
public function map($row): array
|
public function map($row): array
|
||||||
{
|
{
|
||||||
$row['company_id'] = session('company_id');
|
$row = parent::map($row);
|
||||||
$row['type'] = 'income';
|
|
||||||
$row['paid_at'] = Date::parse($row['paid_at'])->format('Y-m-d H:i:s');
|
|
||||||
|
|
||||||
// Make reconciled field integer
|
$row['type'] = 'income';
|
||||||
if (isset($row['reconciled'])) {
|
|
||||||
$row['reconciled'] = (int) $row['reconciled'];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $row;
|
return $row;
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@ namespace App\Imports\Sales\Sheets;
|
|||||||
use App\Abstracts\Import;
|
use App\Abstracts\Import;
|
||||||
use App\Models\Sale\Invoice as Model;
|
use App\Models\Sale\Invoice as Model;
|
||||||
use App\Http\Requests\Sale\Invoice as Request;
|
use App\Http\Requests\Sale\Invoice as Request;
|
||||||
use Jenssegers\Date\Date;
|
|
||||||
|
|
||||||
class Invoices extends Import
|
class Invoices extends Import
|
||||||
{
|
{
|
||||||
@ -14,15 +13,6 @@ class Invoices extends Import
|
|||||||
return new Model($row);
|
return new Model($row);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function map($row): array
|
|
||||||
{
|
|
||||||
$row['company_id'] = session('company_id');
|
|
||||||
$row['invoiced_at'] = Date::parse($row['invoiced_at'])->format('Y-m-d H:i:s');
|
|
||||||
$row['due_at'] = Date::parse($row['due_at'])->format('Y-m-d H:i:s');
|
|
||||||
|
|
||||||
return $row;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function rules(): array
|
public function rules(): array
|
||||||
{
|
{
|
||||||
return (new Request())->rules();
|
return (new Request())->rules();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user