fixed #484
This commit is contained in:
parent
e3dd0b0c70
commit
7eba729e21
@ -16,42 +16,19 @@ class DateFormat
|
|||||||
*/
|
*/
|
||||||
public function handle($request, Closure $next)
|
public function handle($request, Closure $next)
|
||||||
{
|
{
|
||||||
if ($request->method() == 'POST' || $request->method() == 'PATCH') {
|
if (($request->method() == 'POST') || ($request->method() == 'PATCH')) {
|
||||||
$paid_at = $request->get('paid_at');
|
$fields = ['paid_at', 'due_at', 'billed_at', 'invoiced_at'];
|
||||||
$due_at = $request->get('due_at');
|
|
||||||
$billed_at = $request->get('billed_at');
|
|
||||||
$invoiced_at = $request->get('invoiced_at');
|
|
||||||
|
|
||||||
if (!empty($paid_at)) {
|
foreach ($fields as $field) {
|
||||||
$paid_at = Date::parse($paid_at)->format('Y-m-d');
|
$date = $request->get($field);
|
||||||
|
|
||||||
$date_time = $paid_at . ' ' . Date::now()->format('H:i:s');
|
if (empty($date)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$request->request->set('paid_at', $date_time);
|
$new_date = Date::parse($date)->format('Y-m-d') . ' ' . Date::now()->format('H:i:s');
|
||||||
}
|
|
||||||
|
|
||||||
if (!empty($due_at)) {
|
$request->request->set($field, $new_date);
|
||||||
$due_at = Date::parse($due_at)->format('Y-m-d');
|
|
||||||
|
|
||||||
$date_time = $due_at . ' ' . Date::now()->format('H:i:s');
|
|
||||||
|
|
||||||
$request->request->set('due_at', $date_time);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!empty($billed_at)) {
|
|
||||||
$billed_at = Date::parse($billed_at)->format('Y-m-d');
|
|
||||||
|
|
||||||
$date_time = $billed_at . ' ' . Date::now()->format('H:i:s');
|
|
||||||
|
|
||||||
$request->request->set('billed_at', $date_time);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!empty($invoiced_at)) {
|
|
||||||
$invoiced_at = Date::parse($invoiced_at)->format('Y-m-d');
|
|
||||||
|
|
||||||
$date_time = $invoiced_at . ' ' . Date::now()->format('H:i:s');
|
|
||||||
|
|
||||||
$request->request->set('invoiced_at', $date_time);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Utilities;
|
namespace App\Utilities;
|
||||||
|
|
||||||
|
use Date;
|
||||||
use Illuminate\Validation\ValidationException;
|
use Illuminate\Validation\ValidationException;
|
||||||
|
|
||||||
class Import
|
class Import
|
||||||
@ -44,6 +45,18 @@ class Import
|
|||||||
$sheet->each(function ($row, $index) use ($sheet, &$success, $model, $request) {
|
$sheet->each(function ($row, $index) use ($sheet, &$success, $model, $request) {
|
||||||
$data = $row->toArray();
|
$data = $row->toArray();
|
||||||
|
|
||||||
|
// Fix the date fields
|
||||||
|
$date_fields = ['paid_at', 'due_at', 'billed_at', 'invoiced_at'];
|
||||||
|
foreach ($date_fields as $date_field) {
|
||||||
|
if (empty($data[$date_field])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$new_date = Date::parse($data[$date_field])->format('Y-m-d') . ' ' . Date::now()->format('H:i:s');
|
||||||
|
|
||||||
|
$data[$date_field] = $new_date;
|
||||||
|
}
|
||||||
|
|
||||||
// Set the line values so that request class could validate
|
// Set the line values so that request class could validate
|
||||||
request()->merge($data);
|
request()->merge($data);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user