Format excel date cells as date for import/export
This commit is contained in:
parent
b76269e785
commit
691e7877f2
@ -9,6 +9,7 @@ use Maatwebsite\Excel\Concerns\ShouldAutoSize;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||
use Maatwebsite\Excel\Concerns\WithMapping;
|
||||
use Maatwebsite\Excel\Concerns\WithTitle;
|
||||
use PhpOffice\PhpSpreadsheet\Shared\Date as ExcelDate;
|
||||
|
||||
abstract class Export implements FromCollection, ShouldAutoSize, WithHeadings, WithMapping, WithTitle
|
||||
{
|
||||
@ -41,7 +42,7 @@ abstract class Export implements FromCollection, ShouldAutoSize, WithHeadings, W
|
||||
$value = $model->$field;
|
||||
|
||||
if (in_array($field, $date_fields)) {
|
||||
$value = Date::parse($value)->format('Y-m-d');
|
||||
$value = ExcelDate::PHPToExcel(Date::parse($value)->format('Y-m-d'));
|
||||
}
|
||||
|
||||
// Prevent CSV injection https://security.stackexchange.com/a/190848
|
||||
|
@ -17,6 +17,7 @@ use Maatwebsite\Excel\Concerns\WithMapping;
|
||||
use Maatwebsite\Excel\Concerns\WithValidation;
|
||||
use Maatwebsite\Excel\Validators\Failure;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use PhpOffice\PhpSpreadsheet\Shared\Date as ExcelDate;
|
||||
|
||||
abstract class Import implements ToModel, SkipsOnError, SkipsOnFailure, WithBatchInserts, WithChunkReading, WithHeadingRow, WithMapping, WithValidation
|
||||
{
|
||||
@ -44,7 +45,7 @@ abstract class Import implements ToModel, SkipsOnError, SkipsOnFailure, WithBatc
|
||||
continue;
|
||||
}
|
||||
|
||||
$row[$date_field] = Date::parse($row[$date_field])->format('Y-m-d H:i:s');
|
||||
$row[$date_field] = Date::parse(ExcelDate::excelToDateTimeObject($row[$date_field]))->format('Y-m-d H:i:s');
|
||||
}
|
||||
|
||||
return $row;
|
||||
|
@ -7,6 +7,8 @@ use App\Models\Banking\Transaction;
|
||||
use App\Models\Banking\Transfer as Model;
|
||||
use App\Models\Setting\Category;
|
||||
use App\Traits\Currencies;
|
||||
use App\Utilities\Date;
|
||||
use PhpOffice\PhpSpreadsheet\Shared\Date as ExcelDate;
|
||||
|
||||
class Transfers extends Import
|
||||
{
|
||||
@ -21,6 +23,7 @@ class Transfers extends Import
|
||||
{
|
||||
$row = parent::map($row);
|
||||
|
||||
$row['transferred_at'] = Date::parse(ExcelDate::excelToDateTimeObject($row['transferred_at']))->format('Y-m-d');
|
||||
$row['from_account_id'] = $this->getFromAccountId($row);
|
||||
$row['to_account_id'] = $this->getToAccountId($row);
|
||||
$row['expense_transaction_id'] = $this->getExpenseTransactionId($row);
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user