Compare commits
32 Commits
c267d312b2
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 0dcb155acb | |||
|
|
47a0cf31d2 | ||
| 0903c60316 | |||
|
|
e5f23303d9 | ||
| 724cdb9c3f | |||
|
|
b9e164725e | ||
| f9d870073f | |||
|
|
4699de9a77 | ||
| 81ee36f956 | |||
|
|
196117f07f | ||
| 1a31fb6f4e | |||
|
|
84b617f8fb | ||
| ed52e1b62c | |||
|
|
9f6959784f | ||
| 99e9dd6699 | |||
|
|
bbdd9fb75c | ||
| 6dc7a10865 | |||
|
|
cc788ea6d4 | ||
| 36082e27f9 | |||
|
|
8c0af96b94 | ||
| 122d39d912 | |||
|
|
b02954d0a2 | ||
|
|
9b098864bc | ||
|
|
50f542c3d1 | ||
| b15a823c9c | |||
|
|
dfb48055ea | ||
| 779449d117 | |||
|
|
881e2fa6d9 | ||
| 21751bf811 | |||
|
|
3a7104513c | ||
| 67f20caf04 | |||
|
|
25cfaa6479 |
@@ -91,6 +91,7 @@ class SendInvoiceReport extends Command
|
||||
|
||||
$serialTableData[] = [
|
||||
'no' => $no,
|
||||
'plant_id' => $plantId,
|
||||
'plant' => $plantName,
|
||||
'totalInvoice' => $totalSerialCount,
|
||||
'scannedInvoice' => $scannedSerialCount,
|
||||
@@ -127,6 +128,7 @@ class SendInvoiceReport extends Command
|
||||
|
||||
$materialTableData[] = [
|
||||
'no' => $no,
|
||||
'plant_id' => $plantId,
|
||||
'plant' => $plantName,
|
||||
'totalInvoice' => $totalMatCount,
|
||||
'scannedInvoice' => $scannedMatCount,
|
||||
@@ -163,6 +165,7 @@ class SendInvoiceReport extends Command
|
||||
|
||||
$bundleTableData[] = [
|
||||
'no' => $no,
|
||||
'plant_id' => $plantId,
|
||||
'plant' => $plantName,
|
||||
'totalInvoice' => $totalBundleCount,
|
||||
'scannedInvoice' => $scannedBundleCount,
|
||||
@@ -206,7 +209,26 @@ class SendInvoiceReport extends Command
|
||||
continue;
|
||||
}
|
||||
|
||||
\Mail::to($toEmails)->cc($ccEmails)->send(new test($serialTableData, [], [], $schedule));
|
||||
if ($rule->plant == 0) {
|
||||
$filteredSerialData = $serialTableData;
|
||||
|
||||
} else {
|
||||
$filteredSerialData = collect($serialTableData)
|
||||
->where('plant_id', $rule->plant)
|
||||
->values()
|
||||
->toArray();
|
||||
}
|
||||
|
||||
\Mail::to($toEmails)
|
||||
->cc($ccEmails)
|
||||
->send(new test(
|
||||
$filteredSerialData,
|
||||
[],
|
||||
[],
|
||||
$schedule
|
||||
));
|
||||
|
||||
// \Mail::to($toEmails)->cc($ccEmails)->send(new test($serialTableData, [], [], $schedule));
|
||||
|
||||
$this->info("Mail sent for rule ID {$rule->id} → To: ".implode(', ', $toEmails).($ccEmails ? ' | CC: '.implode(', ', $ccEmails) : ''));
|
||||
}
|
||||
@@ -240,7 +262,35 @@ class SendInvoiceReport extends Command
|
||||
continue;
|
||||
}
|
||||
|
||||
\Mail::to($toEmails)->cc($ccEmails)->send(new test([], $materialTableData, $bundleTableData, $schedule));
|
||||
// FILTER DATA
|
||||
if ($rule->plant == 0) {
|
||||
|
||||
$filteredMaterialData = $materialTableData;
|
||||
$filteredBundleData = $bundleTableData;
|
||||
|
||||
} else {
|
||||
|
||||
$filteredMaterialData = collect($materialTableData)
|
||||
->where('plant_id', $rule->plant)
|
||||
->values()
|
||||
->toArray();
|
||||
|
||||
$filteredBundleData = collect($bundleTableData)
|
||||
->where('plant_id', $rule->plant)
|
||||
->values()
|
||||
->toArray();
|
||||
}
|
||||
|
||||
\Mail::to($toEmails)
|
||||
->cc($ccEmails)
|
||||
->send(new test(
|
||||
[],
|
||||
$filteredMaterialData,
|
||||
$filteredBundleData,
|
||||
$schedule
|
||||
));
|
||||
|
||||
// \Mail::to($toEmails)->cc($ccEmails)->send(new test([], $materialTableData, $bundleTableData, $schedule));
|
||||
|
||||
$this->info("Mail sent for rule ID {$rule->id} → To: ".implode(', ', $toEmails).($ccEmails ? ' | CC: '.implode(', ', $ccEmails) : ''));
|
||||
}
|
||||
@@ -275,7 +325,41 @@ class SendInvoiceReport extends Command
|
||||
continue;
|
||||
}
|
||||
|
||||
\Mail::to($toEmails)->cc($ccEmails)->send(new test($serialTableData, $materialTableData, $bundleTableData, $schedule));
|
||||
// FILTER DATA
|
||||
if ($rule->plant == 0) {
|
||||
|
||||
$filteredSerialData = $serialTableData;
|
||||
$filteredMaterialData = $materialTableData;
|
||||
$filteredBundleData = $bundleTableData;
|
||||
|
||||
} else {
|
||||
|
||||
$filteredSerialData = collect($serialTableData)
|
||||
->where('plant_id', $rule->plant)
|
||||
->values()
|
||||
->toArray();
|
||||
|
||||
$filteredMaterialData = collect($materialTableData)
|
||||
->where('plant_id', $rule->plant)
|
||||
->values()
|
||||
->toArray();
|
||||
|
||||
$filteredBundleData = collect($bundleTableData)
|
||||
->where('plant_id', $rule->plant)
|
||||
->values()
|
||||
->toArray();
|
||||
}
|
||||
|
||||
\Mail::to($toEmails)
|
||||
->cc($ccEmails)
|
||||
->send(new test(
|
||||
$filteredSerialData,
|
||||
$filteredMaterialData,
|
||||
$filteredBundleData,
|
||||
$schedule
|
||||
));
|
||||
|
||||
// \Mail::to($toEmails)->cc($ccEmails)->send(new test($serialTableData, $materialTableData, $bundleTableData, $schedule));
|
||||
|
||||
$this->info("Mail sent for rule ID {$rule->id} → To: ".implode(', ', $toEmails).($ccEmails ? ' | CC: '.implode(', ', $ccEmails) : ''));
|
||||
}
|
||||
|
||||
@@ -102,7 +102,6 @@ class ProductCharacteristicsMasterImporter extends Importer
|
||||
|
||||
public function resolveRecord(): ?ProductCharacteristicsMaster
|
||||
{
|
||||
|
||||
$warnMsg = [];
|
||||
$plantCod = trim($this->data['plant']) ?? null;
|
||||
$itemCod = trim($this->data['item']) ?? null;
|
||||
|
||||
@@ -11,6 +11,7 @@ use Filament\Forms\Form;
|
||||
use Filament\Pages\Page;
|
||||
use Filament\Pages\Dashboard\Concerns\HasFiltersForm;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Filament\Forms\Components\DatePicker;
|
||||
|
||||
class InvoiceDashboard extends Page
|
||||
{
|
||||
@@ -27,9 +28,13 @@ class InvoiceDashboard extends Page
|
||||
public function mount(): void
|
||||
{
|
||||
session()->forget(['selec_plant', 'select_invoice']);
|
||||
session()->forget(['from_date']);
|
||||
session()->forget(['to_date']);
|
||||
$this->filtersForm->fill([
|
||||
'plant' => null,
|
||||
'invoice' => null,
|
||||
'from_date' => null,
|
||||
'to_date' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -62,9 +67,23 @@ class InvoiceDashboard extends Page
|
||||
->afterStateUpdated(function ($state) {
|
||||
session(['select_invoice' => $state]);
|
||||
$this->dispatch('invoiceChart');
|
||||
})
|
||||
}),
|
||||
DatePicker::make('created_from')
|
||||
->label('Created From')
|
||||
->reactive()
|
||||
->afterStateUpdated(function ($state,callable $set) {
|
||||
session(['from_date' => $state]);
|
||||
$this->dispatch('invoiceChart');
|
||||
}),
|
||||
DatePicker::make('created_to')
|
||||
->label('Created To')
|
||||
->reactive()
|
||||
->afterStateUpdated(function ($state,callable $set) {
|
||||
session(['to_date' => $state]);
|
||||
$this->dispatch('invoiceChart');
|
||||
}),
|
||||
])
|
||||
->columns(2);
|
||||
->columns(4);
|
||||
}
|
||||
|
||||
public static function getNavigationLabel(): string
|
||||
|
||||
@@ -459,6 +459,13 @@ class ImportTransitResource extends Resource
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
$formattedDate = null;
|
||||
$formattedShipperDate = null;
|
||||
$etaDate = null;
|
||||
$etdDate = null;
|
||||
$formattedBlRcvdDate = null;
|
||||
|
||||
$criRfqNo = trim($row[1] ?? '');
|
||||
$mailRcvdDate = trim($row[2] ?? '');
|
||||
$pricolRefNo = trim($row[3] ?? '');
|
||||
|
||||
@@ -37,6 +37,9 @@ class VehicleEntryResource extends Resource
|
||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
|
||||
})
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('uuid')
|
||||
->label('Uuid')
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('vehicle_number')
|
||||
->label('Vehicle Number')
|
||||
->required(),
|
||||
@@ -102,6 +105,11 @@ class VehicleEntryResource extends Resource
|
||||
->alignCenter()
|
||||
->sortable()
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('uuid')
|
||||
->label('UUID')
|
||||
->alignCenter()
|
||||
->sortable()
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('vehicle_number')
|
||||
->label('Vehicle Number')
|
||||
->alignCenter()
|
||||
|
||||
@@ -22,6 +22,10 @@ class InvoiceChart extends ChartWidget
|
||||
{
|
||||
$selectedPlant = session('selec_plant');
|
||||
$selectedInvoice = session('select_invoice');
|
||||
|
||||
$fromDt = session('from_date');
|
||||
$toDt = session('to_date');
|
||||
|
||||
$activeFilter = $this->filter; // Assuming filter is passed and activeFilter can be 'yesterday', 'this_week', 'this_month'
|
||||
|
||||
if (!$selectedPlant || !$selectedInvoice) {
|
||||
@@ -31,23 +35,33 @@ class InvoiceChart extends ChartWidget
|
||||
];
|
||||
}
|
||||
|
||||
// Define the date range based on the active filter
|
||||
if ($activeFilter == 'yesterday') {
|
||||
$startDate = now()->subDay()->setTime(8, 0, 0);
|
||||
$endDate = now()->setTime(8, 0, 0);
|
||||
$groupBy = 'none'; // No grouping by hour
|
||||
} elseif ($activeFilter == 'this_week') {
|
||||
$startDate = now()->startOfWeek()->setTime(8, 0, 0);
|
||||
$endDate = now()->endOfWeek()->addDay()->setTime(8, 0, 0);
|
||||
$groupBy = 'day_of_week';
|
||||
} elseif ($activeFilter == 'this_month') {
|
||||
$startDate = now()->startOfMonth()->setTime(8, 0, 0);
|
||||
$endDate = now()->endOfMonth()->setTime(8, 0, 0);
|
||||
$groupBy = 'week_of_month';
|
||||
} else {
|
||||
$startDate = now()->setTime(8, 0, 0);
|
||||
$endDate = now()->copy()->addDay()->setTime(8, 0, 0);
|
||||
$groupBy = 'none'; // No grouping by hour
|
||||
$isCustomDate = !empty($fromDt) && !empty($toDt);
|
||||
|
||||
if (!empty($fromDt) && !empty($toDt)) {
|
||||
$startDate = \Carbon\Carbon::parse($fromDt)->setTime(8, 0, 0);
|
||||
$endDate = \Carbon\Carbon::parse($toDt)->addDay()->setTime(8, 0, 0);
|
||||
$groupBy = 'none';
|
||||
}
|
||||
else{
|
||||
|
||||
// Define the date range based on the active filter
|
||||
if ($activeFilter == 'yesterday') {
|
||||
$startDate = now()->subDay()->setTime(8, 0, 0);
|
||||
$endDate = now()->setTime(8, 0, 0);
|
||||
$groupBy = 'none'; // No grouping by hour
|
||||
} elseif ($activeFilter == 'this_week') {
|
||||
$startDate = now()->startOfWeek()->setTime(8, 0, 0);
|
||||
$endDate = now()->endOfWeek()->addDay()->setTime(8, 0, 0);
|
||||
$groupBy = 'day_of_week';
|
||||
} elseif ($activeFilter == 'this_month') {
|
||||
$startDate = now()->startOfMonth()->setTime(8, 0, 0);
|
||||
$endDate = now()->endOfMonth()->setTime(8, 0, 0);
|
||||
$groupBy = 'week_of_month';
|
||||
} else {
|
||||
$startDate = now()->setTime(8, 0, 0);
|
||||
$endDate = now()->copy()->addDay()->setTime(8, 0, 0);
|
||||
$groupBy = 'none'; // No grouping by hour
|
||||
}
|
||||
}
|
||||
|
||||
// Get the counts for Imported Invoices (unique invoice numbers) and Completed Invoices
|
||||
@@ -111,7 +125,11 @@ class InvoiceChart extends ChartWidget
|
||||
$labels = []; // Labels for each bar
|
||||
$datasets = []; // Datasets for the chart
|
||||
|
||||
if (in_array($activeFilter, ['yesterday'])) {
|
||||
if (!empty($fromDt) && !empty($toDt)) {
|
||||
$activeFilter = null;
|
||||
}
|
||||
|
||||
if ($isCustomDate || in_array($activeFilter, ['yesterday'])) {
|
||||
$labels = ['Imported Invoice', 'Completed Invoice'];
|
||||
$datasets = [[
|
||||
'label' => 'Invoices',
|
||||
@@ -120,8 +138,7 @@ class InvoiceChart extends ChartWidget
|
||||
'fill' => false,
|
||||
]];
|
||||
}
|
||||
|
||||
elseif ($activeFilter == 'this_week')
|
||||
elseif ($isCustomDate || $activeFilter == 'this_week')
|
||||
{
|
||||
$daysOfWeek = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];
|
||||
$importedInvoicesPerDay = array_fill(0, 7, 0);
|
||||
@@ -191,7 +208,7 @@ class InvoiceChart extends ChartWidget
|
||||
],
|
||||
];
|
||||
}
|
||||
elseif ($activeFilter == 'this_month') {
|
||||
elseif ($isCustomDate || $activeFilter == 'this_month') {
|
||||
$startOfMonth = now()->startOfMonth()->setTime(8, 0, 0);
|
||||
$endOfMonth = now()->endOfMonth()->addDay()->setTime(23, 59, 59); // include full last day
|
||||
$monthName = $startOfMonth->format('M');
|
||||
@@ -279,7 +296,7 @@ class InvoiceChart extends ChartWidget
|
||||
],
|
||||
];
|
||||
}
|
||||
else
|
||||
elseif (!$isCustomDate)
|
||||
{
|
||||
$labels = ['Imported Invoice', 'Completed Invoice'];
|
||||
$datasets = [[
|
||||
@@ -354,7 +371,7 @@ class InvoiceChart extends ChartWidget
|
||||
|
||||
public static function canView(): bool
|
||||
{
|
||||
// dd('Checking route:', request()->route()->getName());
|
||||
// dd('Checking route:', request()->route()->getName());
|
||||
// to avoid showing the widget in other pages
|
||||
return request()->routeIs('filament.admin.pages.invoice-dashboard');
|
||||
}
|
||||
|
||||
@@ -3780,7 +3780,7 @@ class CharacteristicsController extends Controller
|
||||
if (! $cField) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Master characteristic field value '{$charField}'' not found in approver master!",
|
||||
'status_description' => "Master characteristic field value '{$charField}' not found in approver master!",
|
||||
], 404);
|
||||
}
|
||||
|
||||
@@ -3856,6 +3856,21 @@ class CharacteristicsController extends Controller
|
||||
$query->where('approver_type', 'Characteristic');
|
||||
})->where('machine_id', $machineId)->where('plant_id', $plantId)->get();
|
||||
|
||||
$requestQual = RequestCharacteristic::where('aufnr', $jobNo)->where('item_id', $itemId)->where('model_type', $modelType)
|
||||
->whereHas('approver', function ($query) {
|
||||
$query->where('approver_type', 'Quality');
|
||||
})->where('machine_id', $machineId)->where('plant_id', $plantId)->orderBy('id')->get();
|
||||
|
||||
foreach ($requestQual as $row) {
|
||||
$workFlowStatus = ($row->approver_status1 == 'Approved' || $row->approver_status2 == 'Approved' || $row->approver_status3 == 'Approved') ? '0' : '1';
|
||||
|
||||
TempClassCharacteristic::where('aufnr', $jobNo)->where('model_type', $modelType)->where('machine_id', $machineId)->where('plant_id', $plantId)
|
||||
->update([
|
||||
'has_work_flow_id' => $workFlowStatus,
|
||||
'updated_by' => $userName,
|
||||
]);
|
||||
}
|
||||
|
||||
$tempClassChars = TempClassCharacteristic::where('aufnr', $jobNo)->where('machine_id', $machineId)->where('plant_id', $plantId)->get();
|
||||
|
||||
if (! $requestChars->isEmpty()) {
|
||||
@@ -3966,6 +3981,21 @@ class CharacteristicsController extends Controller
|
||||
$query->where('approver_type', 'Characteristic');
|
||||
})->where('machine_id', $machineId)->where('plant_id', $plantId)->get();
|
||||
|
||||
$requestQual = RequestCharacteristic::where('aufnr', $jobNo)->where('item_id', $itemId)->where('model_type', $modelType)
|
||||
->whereHas('approver', function ($query) {
|
||||
$query->where('approver_type', 'Quality');
|
||||
})->where('machine_id', $machineId)->where('plant_id', $plantId)->orderBy('id')->get();
|
||||
|
||||
foreach ($requestQual as $row) {
|
||||
$workFlowStatus = ($row->approver_status1 == 'Approved' || $row->approver_status2 == 'Approved' || $row->approver_status3 == 'Approved') ? '0' : '1';
|
||||
|
||||
TempClassCharacteristic::where('aufnr', $jobNo)->where('model_type', $modelType)->where('machine_id', $machineId)->where('plant_id', $plantId)
|
||||
->update([
|
||||
'has_work_flow_id' => $workFlowStatus,
|
||||
'updated_by' => $userName,
|
||||
]);
|
||||
}
|
||||
|
||||
if (! $requestChars->isEmpty()) {
|
||||
$hasCharPending = false;
|
||||
|
||||
@@ -4980,6 +5010,21 @@ class CharacteristicsController extends Controller
|
||||
$query->where('approver_type', 'Characteristic');
|
||||
})->where('machine_id', $machineId)->where('plant_id', $plantId)->get();
|
||||
|
||||
$requestQual = RequestCharacteristic::where('aufnr', $jobNo)->where('item_id', $itemId)->where('model_type', $modelType)
|
||||
->whereHas('approver', function ($query) {
|
||||
$query->where('approver_type', 'Quality');
|
||||
})->where('machine_id', $machineId)->where('plant_id', $plantId)->orderBy('id')->get();
|
||||
|
||||
foreach ($requestQual as $row) {
|
||||
$workFlowStatus = ($row->approver_status1 == 'Approved' || $row->approver_status2 == 'Approved' || $row->approver_status3 == 'Approved') ? '0' : '1';
|
||||
|
||||
TempClassCharacteristic::where('aufnr', $jobNo)->where('model_type', $modelType)->where('machine_id', $machineId)->where('plant_id', $plantId)
|
||||
->update([
|
||||
'has_work_flow_id' => $workFlowStatus,
|
||||
'updated_by' => $userName,
|
||||
]);
|
||||
}
|
||||
|
||||
$tempClassChars = TempClassCharacteristic::where('aufnr', $jobNo)->where('machine_id', $machineId)->where('plant_id', $plantId)->get();
|
||||
|
||||
if (! $requestChars->isEmpty()) {
|
||||
@@ -5084,6 +5129,21 @@ class CharacteristicsController extends Controller
|
||||
$query->where('approver_type', 'Characteristic');
|
||||
})->where('machine_id', $machineId)->where('plant_id', $plantId)->get();
|
||||
|
||||
$requestQual = RequestCharacteristic::where('aufnr', $jobNo)->where('item_id', $itemId)->where('model_type', $modelType)
|
||||
->whereHas('approver', function ($query) {
|
||||
$query->where('approver_type', 'Quality');
|
||||
})->where('machine_id', $machineId)->where('plant_id', $plantId)->orderBy('id')->get();
|
||||
|
||||
foreach ($requestQual as $row) {
|
||||
$workFlowStatus = ($row->approver_status1 == 'Approved' || $row->approver_status2 == 'Approved' || $row->approver_status3 == 'Approved') ? '0' : '1';
|
||||
|
||||
TempClassCharacteristic::where('aufnr', $jobNo)->where('model_type', $modelType)->where('machine_id', $machineId)->where('plant_id', $plantId)
|
||||
->update([
|
||||
'has_work_flow_id' => $workFlowStatus,
|
||||
'updated_by' => $userName,
|
||||
]);
|
||||
}
|
||||
|
||||
if (! $requestChars->isEmpty()) {
|
||||
$hasCharPending = false;
|
||||
|
||||
@@ -5160,12 +5220,20 @@ class CharacteristicsController extends Controller
|
||||
'approver_status_3' => $row->approver_status3 ?? '',
|
||||
'approver_remark_3' => $row->approver_remark3 ?? '',
|
||||
'approved_at_3' => $row->approved3_at ?? '', // ? $row->approved3_at->format('d-m-Y H:i:s') : '',
|
||||
'mail_status' => ($row->mail_status == 'Sent') ? 'Sent-M1' : (($row->mail_status == 'Sent-Mail2') ? 'Sent-M2' : (($row->mail_status == 'Sent-Mail3') ? 'Sent-M3' : '-')),
|
||||
'triggered_at' => $row->trigger_at ?? '',
|
||||
'requested_by' => ($row->created_by == 'Admin') ? 'jothi' : $row->created_by ?? '',
|
||||
'requested_at' => $row->created_at ? $row->created_at->format('Y-m-d H:i:s') : '',
|
||||
];
|
||||
} else {
|
||||
$workFlowStatus = ($row->approver_status1 == 'Approved' || $row->approver_status2 == 'Approved' || $row->approver_status3 == 'Approved') ? '0' : '1';
|
||||
|
||||
// / TempClassCharacteristic::where('aufnr', $jobNo)->where('model_type', $modelType)->where('machine_id', $machineId)->where('plant_id', $plantId)
|
||||
// / ->update([
|
||||
// / 'has_work_flow_id' => $workFlowStatus,
|
||||
// / 'updated_by' => $userName,
|
||||
// / ]);
|
||||
|
||||
if ($workFlowStatus == '1') {
|
||||
$workFlowStatus = ($row->approver_status1 == 'Rejected' || $row->approver_status2 == 'Rejected' || $row->approver_status3 == 'Rejected') ? '2' : '1';
|
||||
}
|
||||
@@ -5191,6 +5259,8 @@ class CharacteristicsController extends Controller
|
||||
'approver_status_3' => $row->approver_status3 ?? '',
|
||||
'approver_remark_3' => $row->approver_remark3 ?? '',
|
||||
'approved_at_3' => $row->approved3_at ?? '', // ? $row->approved3_at->format('d-m-Y H:i:s') : '',
|
||||
'mail_status' => ($row->mail_status == 'Sent') ? 'Sent-M1' : (($row->mail_status == 'Sent-Mail2') ? 'Sent-M2' : (($row->mail_status == 'Sent-Mail3') ? 'Sent-M3' : '-')),
|
||||
'triggered_at' => $row->trigger_at ?? '',
|
||||
'requested_by' => ($row->created_by == 'Admin') ? 'jothi' : $row->created_by ?? '',
|
||||
'requested_at' => $row->created_at ? $row->created_at->format('Y-m-d H:i:s') : '',
|
||||
];
|
||||
|
||||
@@ -41,12 +41,11 @@ class VehicleController extends Controller
|
||||
|
||||
if (!ctype_digit((string) $plantCode)) {
|
||||
return response()->json([
|
||||
'status' => 'error',
|
||||
'status' => 'ERROR',
|
||||
'status_description' => "plant code must be $plantCode a numeric value",
|
||||
], 404);
|
||||
}
|
||||
|
||||
|
||||
$plantCod = Plant::where('code', $plantCode)->first();
|
||||
|
||||
if(!$plantCod){
|
||||
@@ -58,100 +57,167 @@ class VehicleController extends Controller
|
||||
|
||||
$plantId = $plantCod->id;
|
||||
|
||||
$data = $request->all();
|
||||
// $data = $request->all();
|
||||
|
||||
$vehicleNo = $data['vehicle_number'] ?? '';
|
||||
$entryTimeRaw = $data['entry_time'] ?? '';
|
||||
$exitTimeRaw = $data['exit_time'] ?? '';
|
||||
$duration = $data['duration'] ?? '';
|
||||
$type = $data['type'] ?? '';
|
||||
$data = $request->json()->all();
|
||||
|
||||
if(!$vehicleNo)
|
||||
$results = [];
|
||||
|
||||
foreach ($data as $item) {
|
||||
|
||||
$uuid = $item['uuid'] ?? '';
|
||||
$vehicleNo = trim($item['vehicle_number'] ?? '');
|
||||
$entryTimeRaw = $item['entry_time'] ?? '';
|
||||
$exitTimeRaw = $item['exit_time'] ?? '';
|
||||
$duration = $item['duration'] ?? '';
|
||||
$type = $item['type'] ?? '';
|
||||
|
||||
if (!$vehicleNo) {
|
||||
|
||||
$results[] = [
|
||||
'uuid' => $uuid,
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Vehicle number can't be empty!"
|
||||
];
|
||||
|
||||
continue;
|
||||
}
|
||||
elseif (strlen($vehicleNo) < 8) {
|
||||
|
||||
$results[] = [
|
||||
'uuid' => $uuid,
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Vehicle number '$vehicleNo' must be at least 8 characters long"
|
||||
];
|
||||
|
||||
continue;
|
||||
}
|
||||
elseif (!$entryTimeRaw) {
|
||||
|
||||
$results[] = [
|
||||
'uuid' => $uuid,
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Entry time can't be empty!"
|
||||
];
|
||||
|
||||
continue;
|
||||
}
|
||||
elseif (!$type) {
|
||||
|
||||
$results[] = [
|
||||
'uuid' => $uuid,
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Type can't be empty!"
|
||||
];
|
||||
|
||||
continue;
|
||||
}
|
||||
elseif ($entryTimeRaw && !Carbon::hasFormat($entryTimeRaw, 'd/m/Y h:i:s A')) {
|
||||
$results[] = [
|
||||
'uuid' => $uuid,
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Invalid Entry time format $entryTimeRaw. Expected dd/mm/yyyy hh:mm:ss AM/PM"
|
||||
];
|
||||
continue;
|
||||
}
|
||||
else if ($exitTimeRaw && !Carbon::hasFormat($exitTimeRaw, 'd/m/Y h:i:s A')) {
|
||||
|
||||
$results[] = [
|
||||
'uuid' => $uuid,
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Invalid Exit time format $exitTimeRaw. Expected dd/mm/yyyy hh:mm:ss AM/PM"
|
||||
];
|
||||
continue;
|
||||
}
|
||||
elseif ($duration && !preg_match('/^\d{2}:\d{2}:\d{2}$/', $duration)) {
|
||||
|
||||
$results[] = [
|
||||
'uuid' => $uuid,
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Invalid duration format $duration"
|
||||
];
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if(!empty($results)){
|
||||
return response()->json($results, 404);
|
||||
}
|
||||
|
||||
foreach ($data as $item) {
|
||||
|
||||
$uuid = $item['uuid'] ?? '';
|
||||
$vehicleNo = trim($item['vehicle_number'] ?? '');
|
||||
$entryTimeRaw = $item['entry_time'] ?? '';
|
||||
$exitTimeRaw = $item['exit_time'] ?? '';
|
||||
$duration = $item['duration'] ?? '';
|
||||
$type = $item['type'] ?? '';
|
||||
|
||||
if(!empty($entryTimeRaw)){
|
||||
$entryTime = $entryTimeRaw
|
||||
? Carbon::createFromFormat('d/m/Y h:i:s A', $entryTimeRaw)
|
||||
: null;
|
||||
}
|
||||
|
||||
$exitTime = null;
|
||||
|
||||
if(!empty($exitTimeRaw)){
|
||||
|
||||
$exitTime = $exitTimeRaw
|
||||
? Carbon::createFromFormat('d/m/Y h:i:s A', $exitTimeRaw)
|
||||
: null;
|
||||
}
|
||||
|
||||
if (
|
||||
empty($duration) &&
|
||||
!empty($entryTime) &&
|
||||
!empty($exitTime)
|
||||
) {
|
||||
|
||||
$totalSeconds = $entryTime->diffInSeconds($exitTime);
|
||||
|
||||
$hours = floor($totalSeconds / 3600);
|
||||
$minutes = floor(($totalSeconds % 3600) / 60);
|
||||
$seconds = $totalSeconds % 60;
|
||||
|
||||
$duration = sprintf(
|
||||
'%02d:%02d:%02d',
|
||||
$hours,
|
||||
$minutes,
|
||||
$seconds
|
||||
);
|
||||
}
|
||||
|
||||
$record = VehicleEntry::updateOrInsert(
|
||||
[
|
||||
'plant_id' => $plantId,
|
||||
'uuid' => $uuid
|
||||
],
|
||||
[
|
||||
'vehicle_number' => $vehicleNo,
|
||||
'entry_time' => $entryTime,
|
||||
'exit_time' => $exitTime ?? null,
|
||||
'duration' => $duration ?: null,
|
||||
'type' => $type,
|
||||
'updated_at' => now(),
|
||||
'created_at' => now(),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
if($record){
|
||||
return response()->json([
|
||||
'status' => 'SUCCESS',
|
||||
'status_description' => 'Vehicle entry inserted successfully'
|
||||
], 200);
|
||||
}
|
||||
else
|
||||
{
|
||||
return response()->json([
|
||||
'status' => 'ERROR',
|
||||
'status_description' => "Vehicle number cant't be empty!",
|
||||
'status_description' => 'Failed to insert record in the table vehicle entry'
|
||||
], 404);
|
||||
}
|
||||
else if (strlen($vehicleNo) < 8) {
|
||||
return response()->json([
|
||||
'status' => 'ERROR',
|
||||
'status_description' => "vehicle number '$vehicleNo' must be at least 8 characters long",
|
||||
], 404);
|
||||
}
|
||||
else if(!$entryTimeRaw)
|
||||
{
|
||||
return response()->json([
|
||||
'status' => 'ERROR',
|
||||
'status_description' => "Entry time cant't be empty!",
|
||||
], 404);
|
||||
}
|
||||
else if(!$exitTimeRaw)
|
||||
{
|
||||
return response()->json([
|
||||
'status' => 'ERROR',
|
||||
'status_description' => "Exit time cant't be empty!",
|
||||
], 404);
|
||||
}
|
||||
else if(!$duration)
|
||||
{
|
||||
return response()->json([
|
||||
'status' => 'ERROR',
|
||||
'status_description' => "Duration cant't be empty!",
|
||||
], 404);
|
||||
}
|
||||
else if(!$type)
|
||||
{
|
||||
return response()->json([
|
||||
'status' => 'ERROR',
|
||||
'status_description' => "type cant't be empty!",
|
||||
], 404);
|
||||
}
|
||||
|
||||
|
||||
if ($entryTimeRaw && !Carbon::hasFormat($entryTimeRaw, 'd/m/Y h:i:s A')) {
|
||||
return response()->json([
|
||||
'status' => 'ERROR',
|
||||
'status_description' => "Invalid Entry time format $entryTimeRaw. Expected dd/mm/yyyy hh:mm:ss AM/PM",
|
||||
], 404);
|
||||
}
|
||||
else if ($exitTimeRaw && !Carbon::hasFormat($exitTimeRaw, 'd/m/Y h:i:s A')) {
|
||||
return response()->json([
|
||||
'status' => 'ERROR',
|
||||
'status_description' => "Invalid Exit time format $exitTimeRaw. Expected dd/mm/yyyy hh:mm:ss AM/PM",
|
||||
], 404);
|
||||
}
|
||||
else if ($duration && !preg_match('/^\d{2}:\d{2}:\d{2}$/', $duration)) {
|
||||
return response()->json([
|
||||
'status' => 'error',
|
||||
'status_description' => "Invalid duration format $duration. Expected HH:MM:SS",
|
||||
], 404);
|
||||
}
|
||||
|
||||
$entryTime = $entryTimeRaw
|
||||
? Carbon::createFromFormat('d/m/Y h:i:s A', $entryTimeRaw)
|
||||
: null;
|
||||
|
||||
$exitTime = $exitTimeRaw
|
||||
? Carbon::createFromFormat('d/m/Y h:i:s A', $exitTimeRaw)
|
||||
: null;
|
||||
|
||||
VehicleEntry::insert([
|
||||
'plant_id' => $plantId,
|
||||
'vehicle_number' => $vehicleNo,
|
||||
'entry_time' => $entryTime,
|
||||
'exit_time' => $exitTime,
|
||||
'duration' => $duration,
|
||||
'type' => $type,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'status' => 'success',
|
||||
'status_description' => 'Vehicle entry inserted successfully'
|
||||
], 200);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -34,7 +34,7 @@ class RequestCharacteristic extends Model
|
||||
'mail_status',
|
||||
'trigger_at',
|
||||
'work_flow_id',
|
||||
|
||||
'model_type',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'created_by',
|
||||
|
||||
@@ -17,6 +17,7 @@ class VehicleEntry extends Model
|
||||
'exit_time',
|
||||
'duration',
|
||||
'type',
|
||||
'uuid',
|
||||
'created_at',
|
||||
'created_by',
|
||||
'updated_at',
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
$sql1 = <<<'SQL'
|
||||
ALTER TABLE request_characteristics
|
||||
ADD COLUMN model_type TEXT DEFAULT NULL
|
||||
SQL;
|
||||
|
||||
DB::statement($sql1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
// Schema::table('request_characteristics', function (Blueprint $table) {
|
||||
// //
|
||||
// });
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
$sql1 = <<<'SQL'
|
||||
ALTER TABLE vehicle_entries
|
||||
ADD COLUMN uuid TEXT DEFAULT NULL
|
||||
SQL;
|
||||
|
||||
DB::statement($sql1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
// Schema::table('vehicle_entries', function (Blueprint $table) {
|
||||
// //
|
||||
// });
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user