Compare commits
191 Commits
690a6f8026
...
gha-test
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bfed40f535 | ||
|
|
83f98d9e83 | ||
|
|
3d84661640 | ||
|
|
26ecaf49ef | ||
|
|
5fe2b74174 | ||
|
|
ce901e3b78 | ||
|
|
31ad036d0e | ||
|
|
c363faa357 | ||
|
|
a71864905e | ||
|
|
c75ac4781f | ||
|
|
c76cf1fb98 | ||
|
|
95a4ddf11e | ||
|
|
c309bed7d9 | ||
|
|
b2dc9e7024 | ||
|
|
bff2601ddc | ||
|
|
e80812b82e | ||
|
|
81c7812ef6 | ||
|
|
14b5f4ae8b | ||
|
|
eb31e6a406 | ||
|
|
740ceff0f8 | ||
|
|
ea1261fb01 | ||
|
|
74ad73622d | ||
|
|
a62220c9d0 | ||
|
|
a5036b7d6f | ||
|
|
27b8058ba8 | ||
|
|
58091726a4 | ||
|
|
6bdd210162 | ||
|
|
b9e3d463ed | ||
|
|
418e4fcf79 | ||
|
|
33881a3978 | ||
|
|
9d4cf0e3d9 | ||
|
|
72704a4a3f | ||
|
|
a34b55267d | ||
|
|
b6dcb93402 | ||
|
|
313dc012d5 | ||
|
|
2541300910 | ||
|
|
d1894e0d35 | ||
|
|
e5143a0ce8 | ||
|
|
b1674bba53 | ||
|
|
52a25fec8e | ||
|
|
dafe1ca458 | ||
|
|
af384faa7c | ||
|
|
c6f61fa19a | ||
|
|
aaa93e740b | ||
|
|
33acf73b5e | ||
|
|
ea5af41f7f | ||
|
|
c8ea502833 | ||
|
|
7e317f6e5f | ||
|
|
1465734acd | ||
|
|
642053653c | ||
|
|
27524c4d62 | ||
|
|
9fa4c0dd49 | ||
|
|
4d5b14fe69 | ||
|
|
b4ca4a9fcd | ||
|
|
484bc6d070 | ||
|
|
b153a53f4b | ||
|
|
658dea8e72 | ||
|
|
e934cdb193 | ||
|
|
d61c61879f | ||
|
|
4b597629aa | ||
|
|
9173dcb50a | ||
|
|
4a17892865 | ||
|
|
e9d967e2c2 | ||
|
|
215e1302cc | ||
|
|
1f085b3f91 | ||
|
|
ab9c3a80db | ||
|
|
5f0c01176a | ||
|
|
b73202e03f | ||
|
|
6a8978f676 | ||
|
|
61320dfae8 | ||
|
|
7715a20c19 | ||
|
|
bb41d72701 | ||
|
|
fcb6a945ff | ||
|
|
2d2f0d3662 | ||
|
|
cb4605221c | ||
|
|
5a8775c092 | ||
|
|
bef0c986b2 | ||
|
|
80163fb0ff | ||
|
|
170b784a9b | ||
|
|
4311c64531 | ||
|
|
3c9cc702d4 | ||
|
|
752c3cb0da | ||
|
|
1597795c74 | ||
|
|
d75dcdfdd1 | ||
|
|
b8738a2f6a | ||
|
|
4ac1823e5b | ||
|
|
eb2b857aa7 | ||
|
|
693e3a23a4 | ||
|
|
49d2f1088f | ||
|
|
34b2a05166 | ||
|
|
ee99ada3e7 | ||
|
|
3665b63ff9 | ||
|
|
aeb3b694e4 | ||
|
|
a4d2c20451 | ||
|
|
15849fc543 | ||
|
|
fec85824c2 | ||
|
|
6d6d3f2d60 | ||
|
|
29de91e03d | ||
|
|
5ab109006e | ||
|
|
35aa2fab56 | ||
|
|
a87bc6e909 | ||
|
|
3818fa612e | ||
|
|
0f6b62b47a | ||
|
|
656dd17603 | ||
|
|
0c27bd4cfd | ||
|
|
c7779f49b7 | ||
|
|
49c4f25c79 | ||
|
|
f37f62be46 | ||
|
|
5465364ffd | ||
|
|
75963b3ce6 | ||
|
|
b36700af92 | ||
|
|
5a654d1d40 | ||
|
|
2f3b028b17 | ||
|
|
904d850638 | ||
|
|
f5e7bcb348 | ||
|
|
171c675014 | ||
|
|
bd5bb7f54c | ||
|
|
74c3243c06 | ||
|
|
bd0eed07ac | ||
|
|
b564e2debe | ||
|
|
4c8fa0bdd6 | ||
|
|
48ce6681ac | ||
|
|
cefebd9f86 | ||
|
|
3a0185391a | ||
|
|
c38a417b85 | ||
|
|
cfe8ac3496 | ||
|
|
be79dcdc45 | ||
|
|
9398374f88 | ||
|
|
43edf2ec5a | ||
|
|
08b142e70f | ||
|
|
de0de426f0 | ||
|
|
3eb9f64fca | ||
|
|
7ff55f0b25 | ||
|
|
3e0633def2 | ||
|
|
cea7f86fed | ||
|
|
af3ae0803c | ||
|
|
10b439f8e3 | ||
|
|
fc6b3efd0a | ||
|
|
6372e293e2 | ||
|
|
c2817aefe4 | ||
|
|
40ad560bca | ||
|
|
a5bc41beda | ||
|
|
ba48c1307e | ||
|
|
d222fe5a3b | ||
|
|
aa4cec997d | ||
|
|
c2c9470979 | ||
|
|
6ea2fc3d23 | ||
|
|
04da674868 | ||
|
|
0174a8494d | ||
|
|
bff1cb0d28 | ||
|
|
5543938eae | ||
|
|
4addab5573 | ||
|
|
000c80c1e6 | ||
|
|
aae2fafc1f | ||
|
|
e958a036c7 | ||
|
|
710ff318ef | ||
|
|
5ec4be082d | ||
|
|
955d143f52 | ||
|
|
5b287f974d | ||
|
|
f5345fc2b8 | ||
|
|
cd09b912ee | ||
|
|
008e9ff791 | ||
|
|
a0c0588e49 | ||
|
|
137341fc6c | ||
|
|
33d22dec5b | ||
|
|
231b65ff7a | ||
|
|
102d9af638 | ||
|
|
b20bff9003 | ||
|
|
c8ad6f3dda | ||
|
|
062ab6d8a1 | ||
|
|
4d4414ffa7 | ||
|
|
4f87a0d318 | ||
|
|
33f787c6ad | ||
|
|
bf6874fe96 | ||
|
|
3406dbc1c7 | ||
|
|
e20ebfe667 | ||
|
|
3012dd61bb | ||
|
|
cdc8a5ce54 | ||
|
|
f3a4aa7411 | ||
|
|
2ae71b9bb8 | ||
|
|
58fc922f24 | ||
|
|
68c5c88fc8 | ||
|
|
c4b4993e1d | ||
|
|
fd3ef4656c | ||
|
|
6e7b847e89 | ||
|
|
0fbe279bf9 | ||
|
|
8188cd6cef | ||
|
|
bdbfc8e024 | ||
|
|
c3f9c9f2c4 | ||
|
|
5cb2842954 | ||
|
|
6a0f5b57a6 |
30
.github/workflows/pint.yaml
vendored
Normal file
30
.github/workflows/pint.yaml
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
name: Laravel Pint
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
pint:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
# Reinstall system libraries to ensure compatibility
|
||||
- name: Ensure system libraries are up-to-date
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install --reinstall --yes git libc6
|
||||
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Set up PHP
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: "8.3"
|
||||
|
||||
- name: Install dependencies
|
||||
run: composer install --no-interaction --prefer-dist --no-progress
|
||||
|
||||
# Run pint in test mode, check only files different from master branch
|
||||
- name: Run Laravel Pint in test mode
|
||||
run: vendor/bin/pint --test --diff=master
|
||||
164
app/Console/Commands/ScheduleList.php
Normal file
164
app/Console/Commands/ScheduleList.php
Normal file
@@ -0,0 +1,164 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\AlertMailRule;
|
||||
use Illuminate\Console\Scheduling\Schedule;
|
||||
|
||||
class ScheduleList
|
||||
{
|
||||
// public function schedule(Schedule $schedule): void
|
||||
// {
|
||||
// // Invoice Report Scheduling
|
||||
// $scheduleType = AlertMailRule::where('module', 'InvoiceValidation')
|
||||
// ->where('rule_name', 'InvoiceMail')
|
||||
// ->value('schedule_type');
|
||||
|
||||
// switch ($scheduleType) {
|
||||
// case 'Live':
|
||||
// $schedule->command('send:invoice-report')->everyMinute()->runInBackground();
|
||||
// break;
|
||||
// case 'Hourly':
|
||||
// $schedule->command('send:invoice-report')->hourly()->runInBackground();
|
||||
// break;
|
||||
// // case 'Daily':
|
||||
// // $schedule->command('send:invoice-report')->daily()->runInBackground(); //->dailyAt('07:59')
|
||||
// // break;
|
||||
// case 'Daily':
|
||||
// $schedule->command('send:invoice-report')->dailyAt('07:59')->runInBackground(); //->dailyAt('07:59')
|
||||
// break;
|
||||
// default:
|
||||
// $schedule->command('send:invoice-report')->hourly()->runInBackground();
|
||||
// break;
|
||||
// }
|
||||
|
||||
// $SerialscheduleType = AlertMailRule::where('module', 'InvoiceValidation')
|
||||
// ->where('rule_name', 'SerialInvoiceMail')
|
||||
// ->value('schedule_type');
|
||||
|
||||
// switch ($SerialscheduleType) {
|
||||
// case 'Live':
|
||||
// $schedule->command('send:invoice-report')->everyMinute()->runInBackground();
|
||||
// break;
|
||||
// case 'Hourly':
|
||||
// $schedule->command('send:invoice-report')->hourly()->runInBackground();
|
||||
// break;
|
||||
// // case 'Daily':
|
||||
// // $schedule->command('send:invoice-report')->daily()->runInBackground(); //->dailyAt('07:59')
|
||||
// // break;
|
||||
// case 'Daily':
|
||||
// $schedule->command('send:invoice-report')->dailyAt('07:59')->runInBackground(); //->dailyAt('07:59')
|
||||
// break;
|
||||
// default:
|
||||
// $schedule->command('send:invoice-report')->hourly()->runInBackground();
|
||||
// break;
|
||||
// }
|
||||
|
||||
|
||||
// $materialscheduleType = AlertMailRule::where('module', 'InvoiceValidation')
|
||||
// ->where('rule_name', 'MaterialInvoiceMail')
|
||||
// ->value('schedule_type');
|
||||
|
||||
// switch ($materialscheduleType) {
|
||||
// case 'Live':
|
||||
// $schedule->command('send:invoice-report')->everyMinute()->runInBackground();
|
||||
// break;
|
||||
// case 'Hourly':
|
||||
// $schedule->command('send:invoice-report')->hourly()->runInBackground();
|
||||
// break;
|
||||
// // case 'Daily':
|
||||
// // $schedule->command('send:invoice-report')->daily()->runInBackground(); //->dailyAt('07:59')
|
||||
// // break;
|
||||
// case 'Daily':
|
||||
// $schedule->command('send:invoice-report')->dailyAt('07:59')->runInBackground(); //->dailyAt('07:59')
|
||||
// break;
|
||||
// default:
|
||||
// $schedule->command('send:invoice-report')->hourly()->runInBackground();
|
||||
// break;
|
||||
// }
|
||||
|
||||
// // Production Report Scheduling
|
||||
// $productionScheduleType = AlertMailRule::where('module', 'ProductionQuantities')
|
||||
// ->where('rule_name', 'ProductionMail')
|
||||
// ->value('schedule_type');
|
||||
|
||||
// switch ($productionScheduleType) {
|
||||
// case 'Live':
|
||||
// $schedule->command('send:production-report')->everyMinute()->runInBackground();
|
||||
// break;
|
||||
// case 'Hourly':
|
||||
// $schedule->command('send:production-report')->hourly()->runInBackground();
|
||||
// break;
|
||||
// case 'Daily':
|
||||
// $schedule->command('send:production-report')->dailyAt('07:59')->runInBackground();
|
||||
// break;
|
||||
// default:
|
||||
// $schedule->command('send:production-report')->hourly()->runInBackground();
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
|
||||
public function schedule(Schedule $schedule): void
|
||||
{
|
||||
// Define the rules you want to schedule
|
||||
$rules = [
|
||||
[
|
||||
'module' => 'InvoiceValidation',
|
||||
'rule_name' => 'InvoiceMail',
|
||||
'argument' => 'InvoiceMail',
|
||||
],
|
||||
[
|
||||
'module' => 'InvoiceValidation',
|
||||
'rule_name' => 'SerialInvoiceMail',
|
||||
'argument' => 'SerialInvoiceMail',
|
||||
],
|
||||
[
|
||||
'module' => 'InvoiceValidation',
|
||||
'rule_name' => 'MaterialInvoiceMail',
|
||||
'argument' => 'MaterialInvoiceMail',
|
||||
],
|
||||
];
|
||||
|
||||
// Loop through each rule and schedule accordingly
|
||||
foreach ($rules as $rule) {
|
||||
$scheduleType = AlertMailRule::where('module', $rule['module'])
|
||||
->where('rule_name', $rule['rule_name'])
|
||||
->value('schedule_type');
|
||||
|
||||
switch ($scheduleType) {
|
||||
case 'Live':
|
||||
$schedule->command("send:invoice-report {$rule['argument']}")->everyMinute()->runInBackground();
|
||||
break;
|
||||
case 'Hourly':
|
||||
$schedule->command("send:invoice-report {$rule['argument']}")->hourly()->runInBackground();
|
||||
break;
|
||||
case 'Daily':
|
||||
$schedule->command("send:invoice-report {$rule['argument']}")->dailyAt('07:59')->runInBackground();
|
||||
break;
|
||||
default:
|
||||
$schedule->command("send:invoice-report {$rule['argument']}")->hourly()->runInBackground();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Production Report Scheduling
|
||||
$productionScheduleType = AlertMailRule::where('module', 'ProductionQuantities')
|
||||
->where('rule_name', 'ProductionMail')
|
||||
->value('schedule_type');
|
||||
|
||||
switch ($productionScheduleType) {
|
||||
case 'Live':
|
||||
$schedule->command('send:production-report')->everyMinute()->runInBackground();
|
||||
break;
|
||||
case 'Hourly':
|
||||
$schedule->command('send:production-report')->hourly()->runInBackground();
|
||||
break;
|
||||
case 'Daily':
|
||||
$schedule->command('send:production-report')->dailyAt('07:59')->runInBackground();
|
||||
break;
|
||||
default:
|
||||
$schedule->command('send:production-report')->hourly()->runInBackground();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
405
app/Console/Commands/SendInvoiceReport.php
Normal file
405
app/Console/Commands/SendInvoiceReport.php
Normal file
@@ -0,0 +1,405 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\InvoiceValidation;
|
||||
use App\Models\Plant;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use App\Mail\test;
|
||||
|
||||
class SendInvoiceReport extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
// protected $signature = 'app:send-invoice-report';
|
||||
protected $signature = 'send:invoice-report{schedule_type} {plant}';
|
||||
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Command description';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
|
||||
// public function handle()
|
||||
// {
|
||||
|
||||
// $schedule = $this->argument('schedule_type');
|
||||
// $plantid = $this->argument('plant');
|
||||
|
||||
// $mailRules = \App\Models\AlertMailRule::where('module', 'InvoiceValidation')->get()->groupBy('rule_name');
|
||||
|
||||
// $startDate = now()->setTime(8, 0, 0);
|
||||
// $endDate = now()->copy()->addDay()->setTime(8, 0, 0);
|
||||
// $plants = InvoiceValidation::select('plant_id')->distinct()->pluck('plant_id');
|
||||
|
||||
// $serialTableData = [];
|
||||
// $materialTableData = [];
|
||||
// $bundleTableData = [];
|
||||
// $noSerial = 1;
|
||||
// $noMaterial = 1;
|
||||
// $noBundle = 1;
|
||||
|
||||
// foreach ($plants as $plantId) {
|
||||
// $plant = Plant::find($plantId);
|
||||
// $plantName = $plant ? $plant->name : $plantId;
|
||||
|
||||
// //..Serial Invoice
|
||||
|
||||
// $totalSerialCount = InvoiceValidation::where('plant_id', $plantId)
|
||||
// ->whereNull('quantity')
|
||||
// ->whereBetween('created_at', [$startDate, $endDate])
|
||||
// ->distinct('invoice_number')
|
||||
// ->count('invoice_number');
|
||||
|
||||
// $scannedSerialCount = InvoiceValidation::select('invoice_number')
|
||||
// ->where('plant_id', $plantId)
|
||||
// ->whereNull('quantity')
|
||||
// ->whereBetween('updated_at', [$startDate, $endDate])
|
||||
// ->groupBy('invoice_number')
|
||||
// ->havingRaw(
|
||||
// "COUNT(*) = SUM(CASE WHEN scanned_status = 'Scanned' THEN 1 ELSE 0 END)"
|
||||
// )
|
||||
// ->count();
|
||||
|
||||
// $serialTableData[] = [
|
||||
// 'no' => $noSerial++,
|
||||
// 'plant' => $plantName,
|
||||
// 'totalInvoice' => $totalSerialCount,
|
||||
// 'scannedInvoice' => $scannedSerialCount,
|
||||
// ];
|
||||
|
||||
// //..Individual Invoice
|
||||
|
||||
// $TotalMatCount = InvoiceValidation::where('plant_id', $plantId)
|
||||
// ->where('quantity', 1)
|
||||
// ->whereBetween('created_at', [$startDate, $endDate])
|
||||
// ->distinct('invoice_number')
|
||||
// ->count('invoice_number');
|
||||
|
||||
// $scannedMatCount = InvoiceValidation::select('invoice_number')
|
||||
// ->where('plant_id', $plantId)
|
||||
// ->where('quantity', 1)
|
||||
// ->whereBetween('updated_at', [$startDate, $endDate])
|
||||
// ->groupBy('invoice_number')
|
||||
// ->havingRaw(
|
||||
// "COUNT(*) = SUM(CASE WHEN serial_number IS NOT NULL AND serial_number != '' THEN 1 ELSE 0 END)"
|
||||
// )
|
||||
// ->count();
|
||||
|
||||
// $materialTableData[] = [
|
||||
// 'no' => $noMaterial++,
|
||||
// 'plant' => $plantName,
|
||||
// 'totalInvoice' => $TotalMatCount,
|
||||
// 'scannedInvoice' => $scannedMatCount,
|
||||
// ];
|
||||
|
||||
// //..BUndle Invoice
|
||||
|
||||
// $totalBundleCount = InvoiceValidation::where('plant_id', $plantId)
|
||||
// ->where('quantity', '>', 1)
|
||||
// ->whereBetween('created_at', [$startDate, $endDate])
|
||||
// ->distinct('invoice_number')
|
||||
// ->count('invoice_number');
|
||||
|
||||
// $scannedBundleCount = InvoiceValidation::select('invoice_number')
|
||||
// ->where('plant_id', $plantId)
|
||||
// ->where('quantity', '>', 1)
|
||||
// ->whereBetween('updated_at', [$startDate, $endDate])
|
||||
// ->groupBy('invoice_number')
|
||||
// ->havingRaw(
|
||||
// "COUNT(*) = SUM(CASE WHEN serial_number IS NOT NULL AND serial_number != '' THEN 1 ELSE 0 END)"
|
||||
// )
|
||||
// ->count();
|
||||
|
||||
// $bundleTableData[] = [
|
||||
// 'no' => $noBundle++,
|
||||
// 'plant' => $plantName,
|
||||
// 'totalInvoice' => $totalBundleCount,
|
||||
// 'scannedInvoice' => $scannedBundleCount,
|
||||
// ];
|
||||
// }
|
||||
|
||||
// // Send to SerialInvoiceMail recipients
|
||||
// if ($mailRules->has('SerialInvoiceMail')) {
|
||||
// $emails = $mailRules['SerialInvoiceMail']->pluck('email')->unique()->toArray();
|
||||
// foreach ($emails as $email) {
|
||||
// Mail::to($email)->send(new test($serialTableData, [], []));
|
||||
// }
|
||||
// }
|
||||
|
||||
// // Send to MaterialInvoiceMail recipients (material + bundle table)
|
||||
// if ($mailRules->has('MaterialInvoiceMail')) {
|
||||
// $emails = $mailRules['MaterialInvoiceMail']->pluck('email')->unique()->toArray();
|
||||
// foreach ($emails as $email) {
|
||||
// Mail::to($email)->send(new test([], $materialTableData, $bundleTableData));
|
||||
// }
|
||||
// }
|
||||
|
||||
// // Send to InvoiceMail recipients (all three tables)
|
||||
// if ($mailRules->has('InvoiceMail')) {
|
||||
// $emails = $mailRules['InvoiceMail']->pluck('email')->unique()->toArray();
|
||||
// foreach ($emails as $email) {
|
||||
// Mail::to($email)->send(new test($serialTableData, $materialTableData, $bundleTableData));
|
||||
// }
|
||||
// }
|
||||
// //$this->info(json_encode($materialTableData));
|
||||
// }
|
||||
|
||||
// public function handle()
|
||||
// {
|
||||
// $schedule = $this->argument('schedule_type');
|
||||
// $plantId = $this->argument('plant');
|
||||
|
||||
// $mailRules = \App\Models\AlertMailRule::where('module', 'InvoiceValidation')->get()->groupBy('rule_name');
|
||||
|
||||
// $startDate = now()->setTime(8, 0, 0);
|
||||
// $endDate = now()->copy()->addDay()->setTime(8, 0, 0);
|
||||
|
||||
// $serialTableData = [];
|
||||
// $materialTableData = [];
|
||||
// $bundleTableData = [];
|
||||
|
||||
// $plant = Plant::find($plantId);
|
||||
// $plantName = $plant ? $plant->name : $plantId;
|
||||
|
||||
// // Serial Invoice
|
||||
// $totalSerialCount = InvoiceValidation::where('plant_id', $plantId)
|
||||
// ->whereNull('quantity')
|
||||
// ->whereBetween('created_at', [$startDate, $endDate])
|
||||
// ->distinct('invoice_number')
|
||||
// ->count('invoice_number');
|
||||
|
||||
// $scannedSerialCount = InvoiceValidation::select('invoice_number')
|
||||
// ->where('plant_id', $plantId)
|
||||
// ->whereNull('quantity')
|
||||
// ->whereBetween('updated_at', [$startDate, $endDate])
|
||||
// ->groupBy('invoice_number')
|
||||
// ->havingRaw(
|
||||
// "COUNT(*) = SUM(CASE WHEN scanned_status = 'Scanned' THEN 1 ELSE 0 END)"
|
||||
// )
|
||||
// ->count();
|
||||
|
||||
// $serialTableData[] = [
|
||||
// 'no' => 1,
|
||||
// 'plant' => $plantName,
|
||||
// 'totalInvoice' => $totalSerialCount,
|
||||
// 'scannedInvoice' => $scannedSerialCount,
|
||||
// ];
|
||||
|
||||
// // Individual Material Invoice
|
||||
// $TotalMatCount = InvoiceValidation::where('plant_id', $plantId)
|
||||
// ->where('quantity', 1)
|
||||
// ->whereBetween('created_at', [$startDate, $endDate])
|
||||
// ->distinct('invoice_number')
|
||||
// ->count('invoice_number');
|
||||
|
||||
// $scannedMatCount = InvoiceValidation::select('invoice_number')
|
||||
// ->where('plant_id', $plantId)
|
||||
// ->where('quantity', 1)
|
||||
// ->whereBetween('updated_at', [$startDate, $endDate])
|
||||
// ->groupBy('invoice_number')
|
||||
// ->havingRaw(
|
||||
// "COUNT(*) = SUM(CASE WHEN serial_number IS NOT NULL AND serial_number != '' THEN 1 ELSE 0 END)"
|
||||
// )
|
||||
// ->count();
|
||||
|
||||
// $materialTableData[] = [
|
||||
// 'no' => 1,
|
||||
// 'plant' => $plantName,
|
||||
// 'totalInvoice' => $TotalMatCount,
|
||||
// 'scannedInvoice' => $scannedMatCount,
|
||||
// ];
|
||||
|
||||
// // Bundle Invoice
|
||||
// $totalBundleCount = InvoiceValidation::where('plant_id', $plantId)
|
||||
// ->where('quantity', '>', 1)
|
||||
// ->whereBetween('created_at', [$startDate, $endDate])
|
||||
// ->distinct('invoice_number')
|
||||
// ->count('invoice_number');
|
||||
|
||||
// $scannedBundleCount = InvoiceValidation::select('invoice_number')
|
||||
// ->where('plant_id', $plantId)
|
||||
// ->where('quantity', '>', 1)
|
||||
// ->whereBetween('updated_at', [$startDate, $endDate])
|
||||
// ->groupBy('invoice_number')
|
||||
// ->havingRaw(
|
||||
// "COUNT(*) = SUM(CASE WHEN serial_number IS NOT NULL AND serial_number != '' THEN 1 ELSE 0 END)"
|
||||
// )
|
||||
// ->count();
|
||||
|
||||
// $bundleTableData[] = [
|
||||
// 'no' => 1,
|
||||
// 'plant' => $plantName,
|
||||
// 'totalInvoice' => $totalBundleCount,
|
||||
// 'scannedInvoice' => $scannedBundleCount,
|
||||
// ];
|
||||
|
||||
// // Send to SerialInvoiceMail recipients
|
||||
// if ($mailRules->has('SerialInvoiceMail')) {
|
||||
// $emails = $mailRules['SerialInvoiceMail']->pluck('email')->unique()->toArray();
|
||||
// foreach ($emails as $email) {
|
||||
// Mail::to($email)->send(new test($serialTableData, [], []));
|
||||
// }
|
||||
// }
|
||||
|
||||
// // Send to MaterialInvoiceMail recipients (material + bundle table)
|
||||
// if ($mailRules->has('MaterialInvoiceMail')) {
|
||||
// $emails = $mailRules['MaterialInvoiceMail']->pluck('email')->unique()->toArray();
|
||||
// foreach ($emails as $email) {
|
||||
// Mail::to($email)->send(new test([], $materialTableData, $bundleTableData));
|
||||
// }
|
||||
// }
|
||||
|
||||
// // Send to InvoiceMail recipients (all three tables)
|
||||
// if ($mailRules->has('InvoiceMail')) {
|
||||
// $emails = $mailRules['InvoiceMail']->pluck('email')->unique()->toArray();
|
||||
// foreach ($emails as $email) {
|
||||
// Mail::to($email)->send(new test($serialTableData, $materialTableData, $bundleTableData));
|
||||
// }
|
||||
// }
|
||||
|
||||
// // $this->table(
|
||||
// // ['No', 'Plant', 'Total Invoice', 'Scanned Invoice'],
|
||||
// // $serialTableData
|
||||
// // );
|
||||
// }
|
||||
public function handle()
|
||||
{
|
||||
$schedule = $this->argument('schedule_type');
|
||||
$plantIdArg = (int) $this->argument('plant'); // can be 0 for all plants
|
||||
|
||||
$mailRules = \App\Models\AlertMailRule::where('module', 'InvoiceValidation')->get()->groupBy('rule_name');
|
||||
|
||||
$startDate = now()->setTime(8, 0, 0);
|
||||
$endDate = now()->copy()->addDay()->setTime(8, 0, 0);
|
||||
|
||||
$serialTableData = [];
|
||||
$materialTableData = [];
|
||||
$bundleTableData = [];
|
||||
|
||||
// Get plant IDs: either one plant or all
|
||||
$plantIds = $plantIdArg == 0
|
||||
? InvoiceValidation::select('plant_id')->distinct()->pluck('plant_id')->toArray()
|
||||
: [$plantIdArg];
|
||||
|
||||
$no = 1;
|
||||
foreach ($plantIds as $plantId) {
|
||||
$plant = Plant::find($plantId);
|
||||
$plantName = $plant ? $plant->name : $plantId;
|
||||
|
||||
// Serial Invoice
|
||||
$totalSerialCount = InvoiceValidation::where('plant_id', $plantId)
|
||||
->whereNull('quantity')
|
||||
->whereBetween('created_at', [$startDate, $endDate])
|
||||
->distinct('invoice_number')
|
||||
->count('invoice_number');
|
||||
|
||||
$scannedSerialCount = InvoiceValidation::select('invoice_number')
|
||||
->where('plant_id', $plantId)
|
||||
->whereNull('quantity')
|
||||
->whereBetween('updated_at', [$startDate, $endDate])
|
||||
->groupBy('invoice_number')
|
||||
->havingRaw("COUNT(*) = SUM(CASE WHEN scanned_status = 'Scanned' THEN 1 ELSE 0 END)")
|
||||
->count();
|
||||
|
||||
$serialTableData[] = [
|
||||
'no' => $no,
|
||||
'plant' => $plantName,
|
||||
'totalInvoice' => $totalSerialCount,
|
||||
'scannedInvoice' => $scannedSerialCount,
|
||||
];
|
||||
|
||||
// Material Invoice
|
||||
$totalMatCount = InvoiceValidation::where('plant_id', $plantId)
|
||||
->where('quantity', 1)
|
||||
->whereBetween('created_at', [$startDate, $endDate])
|
||||
->distinct('invoice_number')
|
||||
->count('invoice_number');
|
||||
|
||||
$scannedMatCount = InvoiceValidation::select('invoice_number')
|
||||
->where('plant_id', $plantId)
|
||||
->where('quantity', 1)
|
||||
->whereBetween('updated_at', [$startDate, $endDate])
|
||||
->groupBy('invoice_number')
|
||||
->havingRaw("COUNT(*) = SUM(CASE WHEN serial_number IS NOT NULL AND serial_number != '' THEN 1 ELSE 0 END)")
|
||||
->count();
|
||||
|
||||
$materialTableData[] = [
|
||||
'no' => $no,
|
||||
'plant' => $plantName,
|
||||
'totalInvoice' => $totalMatCount,
|
||||
'scannedInvoice' => $scannedMatCount,
|
||||
];
|
||||
|
||||
// Bundle Invoice
|
||||
$totalBundleCount = InvoiceValidation::where('plant_id', $plantId)
|
||||
->where('quantity', '>', 1)
|
||||
->whereBetween('created_at', [$startDate, $endDate])
|
||||
->distinct('invoice_number')
|
||||
->count('invoice_number');
|
||||
|
||||
$scannedBundleCount = InvoiceValidation::select('invoice_number')
|
||||
->where('plant_id', $plantId)
|
||||
->where('quantity', '>', 1)
|
||||
->whereBetween('updated_at', [$startDate, $endDate])
|
||||
->groupBy('invoice_number')
|
||||
->havingRaw("COUNT(*) = SUM(CASE WHEN serial_number IS NOT NULL AND serial_number != '' THEN 1 ELSE 0 END)")
|
||||
->count();
|
||||
|
||||
$bundleTableData[] = [
|
||||
'no' => $no,
|
||||
'plant' => $plantName,
|
||||
'totalInvoice' => $totalBundleCount,
|
||||
'scannedInvoice' => $scannedBundleCount,
|
||||
];
|
||||
|
||||
$no++;
|
||||
}
|
||||
|
||||
// Send to SerialInvoiceMail recipients
|
||||
if ($mailRules->has('SerialInvoiceMail')) {
|
||||
$emails = $mailRules['SerialInvoiceMail']->pluck('email')->unique()->toArray();
|
||||
foreach ($emails as $email) {
|
||||
Mail::to($email)->send(new test($serialTableData, [], []));
|
||||
}
|
||||
}
|
||||
|
||||
// Send to MaterialInvoiceMail recipients (material + bundle table)
|
||||
if ($mailRules->has('MaterialInvoiceMail')) {
|
||||
$emails = $mailRules['MaterialInvoiceMail']->pluck('email')->unique()->toArray();
|
||||
foreach ($emails as $email) {
|
||||
Mail::to($email)->send(new test([], $materialTableData, $bundleTableData));
|
||||
}
|
||||
}
|
||||
|
||||
// Send to InvoiceMail recipients (all three tables)
|
||||
if ($mailRules->has('InvoiceMail')) {
|
||||
$emails = $mailRules['InvoiceMail']->pluck('email')->unique()->toArray();
|
||||
foreach ($emails as $email) {
|
||||
Mail::to($email)->send(new test($serialTableData, $materialTableData, $bundleTableData));
|
||||
}
|
||||
}
|
||||
|
||||
// Show preview in console
|
||||
$this->info('--- Serial Invoice Table ---');
|
||||
$this->table(['#', 'Plant', 'Total Invoice', 'Scanned Invoice'], $serialTableData);
|
||||
|
||||
$this->info('--- Material Invoice Table ---');
|
||||
$this->table(['#', 'Plant', 'Total Invoice', 'Scanned Invoice'], $materialTableData);
|
||||
|
||||
$this->info('--- Bundle Invoice Table ---');
|
||||
$this->table(['#', 'Plant', 'Total Invoice', 'Scanned Invoice'], $bundleTableData);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
247
app/Console/Commands/SendProductionReport.php
Normal file
247
app/Console/Commands/SendProductionReport.php
Normal file
@@ -0,0 +1,247 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\InvoiceValidation;
|
||||
use App\Models\Plant;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use App\Mail\ProductionMail;
|
||||
use App\Models\Line;
|
||||
use App\Models\ProductionPlan;
|
||||
use App\Models\ProductionQuantity;
|
||||
use DB;
|
||||
|
||||
class SendProductionReport extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
//protected $signature = 'send:production-report';
|
||||
protected $signature = 'send:production-report {schedule_type} {plant}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Command description';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
|
||||
// public function handle()
|
||||
// {
|
||||
// $scheduleType = $this->argument('schedule_type');
|
||||
// $plantId = $this->argument('plant');
|
||||
|
||||
// $mailRules = \App\Models\AlertMailRule::where('module', 'ProductionQuantities')
|
||||
// ->where('rule_name', 'ProductionMail')
|
||||
// ->where('plant', $plantId)
|
||||
// ->where('schedule_type', $scheduleType)
|
||||
// ->get();
|
||||
|
||||
// $emails = $mailRules->pluck('email')->unique()->toArray();
|
||||
|
||||
// $plant = Plant::find($plantId);
|
||||
|
||||
// if (!$plant) {
|
||||
// $this->error("Invalid plant ID: $plantId");
|
||||
// return;
|
||||
// }
|
||||
|
||||
// $lines = Line::where('plant_id', $plantId)->get();
|
||||
|
||||
// $startDate = now()->setTime(8, 0, 0);
|
||||
// $endDate = now()->copy()->addDay()->setTime(8, 0, 0);
|
||||
|
||||
// $PlanstartDate = now()->setTime(8, 0, 0);
|
||||
// $planendDate = now()->copy()->addDay()->setTime(7, 59, 00);
|
||||
|
||||
// $tableData = [];
|
||||
// $no = 1;
|
||||
|
||||
// foreach ($lines as $line) {
|
||||
// $lineId = $line->id;
|
||||
// $lineName = $line->name;
|
||||
|
||||
// $targetQuantity = ProductionPlan::where('plant_id', $plantId)
|
||||
// ->where('line_id', $lineId)
|
||||
// ->whereBetween('created_at', [$PlanstartDate, $planendDate])
|
||||
// ->sum('plan_quantity');
|
||||
|
||||
// $productionQuantity = ProductionQuantity::where('plant_id', $plantId)
|
||||
// ->where('line_id', $lineId)
|
||||
// ->whereBetween('created_at', [$startDate, $endDate])
|
||||
// ->count();
|
||||
|
||||
// $tableData[] = [
|
||||
// 'no' => $no++,
|
||||
// 'plant' => $plant->name,
|
||||
// 'line' => $lineName,
|
||||
// 'targetQuantity' => $targetQuantity,
|
||||
// 'productionQuantity' => $productionQuantity,
|
||||
// ];
|
||||
// }
|
||||
|
||||
// // $this->table(
|
||||
// // ['No', 'Plant', 'Line', 'Target Quantity', 'Production Quantity'],
|
||||
// // $tableData
|
||||
// // );
|
||||
|
||||
// if (!empty($emails)) {
|
||||
// foreach ($emails as $email) {
|
||||
// Mail::to($email)->send(new ProductionMail($tableData));
|
||||
// }
|
||||
// } else {
|
||||
// $this->info('No recipients found for ProductionMailAlert.');
|
||||
// }
|
||||
|
||||
// $this->info("Production report sent to " . count($emails) . " recipient(s).");
|
||||
|
||||
// }
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$scheduleType = $this->argument('schedule_type');
|
||||
$plantId = (int) $this->argument('plant'); // cast to int for safety
|
||||
|
||||
// Fetch mail rules based on schedule type
|
||||
$mailRules = \App\Models\AlertMailRule::where('module', 'ProductionQuantities')
|
||||
->where('rule_name', 'ProductionMail')
|
||||
->where('schedule_type', $scheduleType)
|
||||
->where('plant', $plantId)
|
||||
->get();
|
||||
|
||||
$emails = $mailRules->pluck('email')->unique()->toArray();
|
||||
|
||||
$plants = $plantId == 0
|
||||
? Plant::all()
|
||||
: Plant::where('id', $plantId)->get();
|
||||
|
||||
if ($plants->isEmpty()) {
|
||||
$this->error("No valid plant(s) found.");
|
||||
return;
|
||||
}
|
||||
|
||||
// $startDate = now()->setTime(8, 0, 0);
|
||||
// $endDate = now()->copy()->addDay()->setTime(8, 0, 0);
|
||||
if (strtolower($scheduleType) == 'daily')
|
||||
{
|
||||
$startDate = now()->subDay()->setTime(8, 0, 0);
|
||||
$endDate = now()->setTime(8, 0, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
$startDate = now()->setTime(8, 0, 0);
|
||||
$endDate = now()->copy()->addDay()->setTime(8, 0, 0);
|
||||
}
|
||||
|
||||
$PlanstartDate = now()->setTime(8, 0, 0);
|
||||
$planendDate = now()->copy()->addDay()->setTime(7, 59, 0);
|
||||
|
||||
$tableData = [];
|
||||
$no = 1;
|
||||
|
||||
// foreach ($plants as $plant) {
|
||||
// $lines = Line::where('plant_id', $plant->id)->get();
|
||||
|
||||
// foreach ($lines as $line) {
|
||||
// $targetQuantity = ProductionPlan::where('plant_id', $plant->id)
|
||||
// ->where('line_id', $line->id)
|
||||
// ->whereBetween('created_at', [$PlanstartDate, $planendDate])
|
||||
// ->sum('plan_quantity');
|
||||
|
||||
// $productionQuantity = ProductionQuantity::where('plant_id', $plant->id)
|
||||
// ->where('line_id', $line->id)
|
||||
// ->whereBetween('created_at', [$startDate, $endDate])
|
||||
// ->count();
|
||||
|
||||
// $tableData[] = [
|
||||
// 'no' => $no++,
|
||||
// 'plant' => $plant->name,
|
||||
// 'line' => $line->name,
|
||||
// 'targetQuantity' => $targetQuantity,
|
||||
// 'productionQuantity' => $productionQuantity,
|
||||
// ];
|
||||
// }
|
||||
// }
|
||||
|
||||
// $fgTableData = []; // store FG Line related data
|
||||
|
||||
// foreach ($plants as $plant) {
|
||||
// // ✅ Only get FG Lines
|
||||
// $fgLines = Line::where('plant_id', $plant->id)
|
||||
// ->where('type', 'FG Line')
|
||||
// ->get();
|
||||
|
||||
// foreach ($fgLines as $line) {
|
||||
// $validationCount = \App\Models\QualityValidation::where('plant_id', $plant->id)
|
||||
// ->where('line_id', $line->id)
|
||||
// ->whereBetween('created_at', [$startDate, $endDate])
|
||||
// ->count();
|
||||
|
||||
// $fgTableData[] = [
|
||||
// 'no' => $no++,
|
||||
// 'plant' => $plant->name,
|
||||
// 'line' => $line->name,
|
||||
// 'targetQuantity' => $targetQuantity,
|
||||
// 'productionQuantity' => $validationCount,
|
||||
// ];
|
||||
// }
|
||||
// }
|
||||
|
||||
foreach ($plants as $plant)
|
||||
{
|
||||
$lines = Line::where('plant_id', $plant->id)->get();
|
||||
|
||||
foreach ($lines as $line) {
|
||||
$targetQuantity = ProductionPlan::where('plant_id', $plant->id)
|
||||
->where('line_id', $line->id)
|
||||
->whereBetween('created_at', [$PlanstartDate, $planendDate])
|
||||
->sum('plan_quantity');
|
||||
|
||||
if (strtolower($line->type) === 'fg line') {
|
||||
$productionQuantity = \App\Models\QualityValidation::where('plant_id', $plant->id)
|
||||
->where('line_id', $line->id)
|
||||
->whereBetween('created_at', [$startDate, $endDate])
|
||||
->count();
|
||||
} else {
|
||||
$productionQuantity = ProductionQuantity::where('plant_id', $plant->id)
|
||||
->where('line_id', $line->id)
|
||||
->whereBetween('created_at', [$startDate, $endDate])
|
||||
->count();
|
||||
}
|
||||
|
||||
$tableData[] = [
|
||||
'no' => $no++,
|
||||
'plant' => $plant->name,
|
||||
'line' => $line->name,
|
||||
'targetQuantity' => $targetQuantity,
|
||||
'productionQuantity' => $productionQuantity,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
///$this->table(['No', 'Plant', 'Line', 'Target Quantity', 'Production Quantity'], $fgTableData);
|
||||
|
||||
$this->table(['No', 'Plant', 'Line', 'Target Quantity', 'Production Quantity'], $tableData);
|
||||
|
||||
if (!empty($emails)) {
|
||||
foreach ($emails as $email) {
|
||||
Mail::to($email)->send(new ProductionMail($tableData));
|
||||
}
|
||||
} else {
|
||||
$this->info('No recipients found for ProductionMailAlert.');
|
||||
}
|
||||
|
||||
$this->info("Production report sent to " . count($emails) . " recipient(s).");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -30,6 +30,8 @@ class LineExporter extends Exporter
|
||||
->label('NAME'),
|
||||
ExportColumn::make('type')
|
||||
->label('TYPE'),
|
||||
ExportColumn::make('group_work_center')
|
||||
->label('GROUP WORK CENTER'),
|
||||
ExportColumn::make('created_at')
|
||||
->label('CREATED AT'),
|
||||
ExportColumn::make('updated_at')
|
||||
|
||||
@@ -24,8 +24,8 @@ class LocatorExporter extends Exporter
|
||||
// Increment and return the row number
|
||||
return ++$rowNumber;
|
||||
}),
|
||||
ExportColumn::make('plant.name')
|
||||
->label('PLANT'),
|
||||
ExportColumn::make('plant.code')
|
||||
->label('PLANT CODE'),
|
||||
ExportColumn::make('locator_number')
|
||||
->label('LOCATOR NUMBER'),
|
||||
ExportColumn::make('locator_quantity')
|
||||
|
||||
@@ -23,8 +23,8 @@ class LocatorInvoiceValidationExporter extends Exporter
|
||||
// Increment and return the row number
|
||||
return ++$rowNumber;
|
||||
}),
|
||||
ExportColumn::make('plant.name')
|
||||
->label('PLANT'),
|
||||
ExportColumn::make('plant.code')
|
||||
->label('PLANT CODE'),
|
||||
ExportColumn::make('invoice_number')
|
||||
->label('INVOICE NUMBER'),
|
||||
ExportColumn::make('serial_number')
|
||||
|
||||
@@ -13,25 +13,30 @@ class MachineExporter extends Exporter
|
||||
|
||||
public static function getColumns(): array
|
||||
{
|
||||
static $rowNumber = 0;
|
||||
|
||||
return [
|
||||
ExportColumn::make('no')
|
||||
->label('No')
|
||||
->state(function ($record) use (&$rowNumber) {
|
||||
// Increment and return the row number
|
||||
return ++$rowNumber;
|
||||
}),
|
||||
->label('NO')
|
||||
->state(function ($record) use (&$rowNumber) {
|
||||
// Increment and return the row number
|
||||
return ++$rowNumber;
|
||||
}),
|
||||
ExportColumn::make('plant.name')
|
||||
->label('Plant'),
|
||||
->label('PLANT'),
|
||||
ExportColumn::make('line.name')
|
||||
->label('Line'),
|
||||
->label('LINE'),
|
||||
ExportColumn::make('name')
|
||||
->label('Name'),
|
||||
->label('MACHINE'),
|
||||
ExportColumn::make('work_center')
|
||||
->label('WORK CENTER'),
|
||||
ExportColumn::make('created_at')
|
||||
->label('Created At'),
|
||||
->label('CREATED AT'),
|
||||
ExportColumn::make('updated_at')
|
||||
->label('Updated At'),
|
||||
->label('UPDATED AT'),
|
||||
ExportColumn::make('deleted_at')
|
||||
->label('Deleted At'),
|
||||
->enabledByDefault(false)
|
||||
->label('DELETED AT'),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
43
app/Filament/Exports/MfmParameterExporter.php
Normal file
43
app/Filament/Exports/MfmParameterExporter.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Exports;
|
||||
|
||||
use App\Models\MfmParameter;
|
||||
use Filament\Actions\Exports\ExportColumn;
|
||||
use Filament\Actions\Exports\Exporter;
|
||||
use Filament\Actions\Exports\Models\Export;
|
||||
|
||||
class MfmParameterExporter extends Exporter
|
||||
{
|
||||
protected static ?string $model = MfmParameter::class;
|
||||
|
||||
public static function getColumns(): array
|
||||
{
|
||||
return [
|
||||
ExportColumn::make('id')
|
||||
->label('ID'),
|
||||
ExportColumn::make('plant.name'),
|
||||
ExportColumn::make('name'),
|
||||
ExportColumn::make('register_id'),
|
||||
ExportColumn::make('identifier'),
|
||||
ExportColumn::make('byte_to_convert'),
|
||||
ExportColumn::make('type_to_convert'),
|
||||
ExportColumn::make('decimal_to_display'),
|
||||
ExportColumn::make('created_at'),
|
||||
ExportColumn::make('updated_at'),
|
||||
ExportColumn::make('deleted_at'),
|
||||
ExportColumn::make('mfmMeter.name'),
|
||||
];
|
||||
}
|
||||
|
||||
public static function getCompletedNotificationBody(Export $export): string
|
||||
{
|
||||
$body = 'Your mfm parameter export has completed and ' . number_format($export->successful_rows) . ' ' . str('row')->plural($export->successful_rows) . ' exported.';
|
||||
|
||||
if ($failedRowsCount = $export->getFailedRowsCount()) {
|
||||
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to export.';
|
||||
}
|
||||
|
||||
return $body;
|
||||
}
|
||||
}
|
||||
@@ -24,8 +24,8 @@ class PalletValidationExporter extends Exporter
|
||||
// Increment and return the row number
|
||||
return ++$rowNumber;
|
||||
}),
|
||||
ExportColumn::make('plant.name')
|
||||
->label('PLANT'),
|
||||
ExportColumn::make('plant.code')
|
||||
->label('PLANT CODE'),
|
||||
ExportColumn::make('pallet_number')
|
||||
->label('PALLET NUMBER'),
|
||||
ExportColumn::make('serial_number')
|
||||
|
||||
@@ -24,8 +24,8 @@ class ReworkLocatorInvoiceValidationExporter extends Exporter
|
||||
// Increment and return the row number
|
||||
return ++$rowNumber;
|
||||
}),
|
||||
ExportColumn::make('plant.name')
|
||||
->label('PLANT'),
|
||||
ExportColumn::make('plant.code')
|
||||
->label('PLANT CODE'),
|
||||
ExportColumn::make('invoice_number')
|
||||
->label('INVOICE NUMBER'),
|
||||
ExportColumn::make('serial_number')
|
||||
|
||||
@@ -64,14 +64,18 @@ class StickerMasterExporter extends Exporter
|
||||
->label('PART VALIDATION 4'),
|
||||
ExportColumn::make('part_validation5')
|
||||
->label('PART VALIDATION 5'),
|
||||
ExportColumn::make('laser_part_validation1')
|
||||
->label('LASER PART VALIDATION 1'),
|
||||
ExportColumn::make('laser_part_validation2')
|
||||
->label('LASER PART VALIDATION 2'),
|
||||
ExportColumn::make('panel_box_code')
|
||||
->label('PANEL BOX CODE'),
|
||||
ExportColumn::make('load_rate')
|
||||
->label('LOAD RATE'),
|
||||
ExportColumn::make('bundle_quantity')
|
||||
->label('BUNDLE QUANTITY'),
|
||||
ExportColumn::make('material_type')
|
||||
->label('MATERIAL TYPE'),
|
||||
ExportColumn::make('bundle_quantity')
|
||||
->label('BUNDLE QUANTITY'),
|
||||
ExportColumn::make('created_at')
|
||||
->label('CREATED AT'),
|
||||
ExportColumn::make('updated_at')
|
||||
|
||||
@@ -126,10 +126,6 @@ class TestingPanelReadingExporter extends Exporter
|
||||
->label('UPDATE COUNT'),
|
||||
ExportColumn::make('output_flag')
|
||||
->label('OUTPUT FLAG'),
|
||||
ExportColumn::make('pds_status')
|
||||
->label('PDS STATUS'),
|
||||
ExportColumn::make('pds_description')
|
||||
->label('PDS DESCRIPTION'),
|
||||
ExportColumn::make('tested_by')
|
||||
->label('TESTED BY'),
|
||||
ExportColumn::make('updated_by')
|
||||
|
||||
@@ -59,17 +59,19 @@ class ItemImporter extends Importer
|
||||
public function resolveRecord(): ?Item
|
||||
{
|
||||
$warnMsg = [];
|
||||
$iCode = trim($this->data['code']);
|
||||
$description = trim($this->data['description']);
|
||||
$plant = Plant::where('name', $this->data['plant'])->first();
|
||||
if (!$plant) {
|
||||
$warnMsg[] = "Plant not found"; // '" . $this->data['plant'] . "'
|
||||
}
|
||||
if (Str::length($this->data['code']) < 6 || !ctype_alnum($this->data['code'])) {
|
||||
if (Str::length($iCode) < 6 || !ctype_alnum($iCode)) {
|
||||
$warnMsg[] = "Invalid item code found";
|
||||
}
|
||||
// if (Str::length($this->data['uom']) <= 0) {
|
||||
// $warnMsg[] = "Invalid unit of measure found";
|
||||
// }
|
||||
if (Str::length($this->data['description']) < 5) {
|
||||
if (Str::length($description) < 5) {
|
||||
$warnMsg[] = "Invalid description found";
|
||||
}
|
||||
if (Str::length($this->data['hourly_quantity']) < 0 || !is_numeric($this->data['hourly_quantity']) || $this->data['hourly_quantity'] <= 0) {
|
||||
@@ -79,14 +81,14 @@ class ItemImporter extends Importer
|
||||
throw new RowImportFailedException(implode(', ', $warnMsg));
|
||||
}
|
||||
return Item::updateOrCreate([
|
||||
'code' => $this->data['code'],
|
||||
'code' => $iCode,
|
||||
'plant_id' => $plant->id
|
||||
],
|
||||
[
|
||||
'category' => $this->data['category'],
|
||||
'description' => $this->data['description'],
|
||||
'category' => trim($this->data['category']),
|
||||
'description' => $description,
|
||||
'hourly_quantity' => $this->data['hourly_quantity'],
|
||||
'uom' => $this->data['uom']
|
||||
'uom' => trim($this->data['uom'])
|
||||
]
|
||||
);
|
||||
// return new Item;
|
||||
|
||||
@@ -29,6 +29,11 @@ class LineImporter extends Importer
|
||||
->example('Domestic Assembly')
|
||||
->label('Line Type')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('group_work_center')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Group Work Center')
|
||||
->example('RMGCEABC')
|
||||
->label('Group Work Center'),
|
||||
ImportColumn::make('plant')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Plant Name')
|
||||
@@ -60,7 +65,8 @@ class LineImporter extends Importer
|
||||
'plant_id' => $plant->id
|
||||
],
|
||||
[
|
||||
'type' => $this->data['type']
|
||||
'type' => $this->data['type'],
|
||||
'group_work_center' => $this->data['group_work_center']
|
||||
]
|
||||
);
|
||||
// return Line::firstOrNew([
|
||||
|
||||
@@ -3,9 +3,15 @@
|
||||
namespace App\Filament\Imports;
|
||||
|
||||
use App\Models\Locator;
|
||||
use App\Models\PalletValidation;
|
||||
use App\Models\Plant;
|
||||
use App\Models\User;
|
||||
use Filament\Actions\Imports\Exceptions\RowImportFailedException;
|
||||
use Filament\Actions\Imports\ImportColumn;
|
||||
use Filament\Actions\Imports\Importer;
|
||||
use Filament\Actions\Imports\Models\Import;
|
||||
use Filament\Facades\Filament;
|
||||
use Str;
|
||||
|
||||
class LocatorImporter extends Importer
|
||||
{
|
||||
@@ -17,36 +23,93 @@ class LocatorImporter extends Importer
|
||||
ImportColumn::make('locator_number')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Locator Number')
|
||||
->example(['W01-A1A'])
|
||||
->label('Locator Number')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('locator_quantity')
|
||||
->requiredMapping()
|
||||
->numeric()
|
||||
->exampleHeader('Locator Quantity')
|
||||
->example(['0'])
|
||||
->label('Locator Quantity')
|
||||
->rules(['required', 'integer']),
|
||||
ImportColumn::make('operator_id')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Operator ID')
|
||||
->example(['Admin'])
|
||||
->label('Operator ID')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('plant_id')
|
||||
ImportColumn::make('plant')
|
||||
->requiredMapping()
|
||||
->relationship('plant', 'name')
|
||||
->exampleHeader('Plant')
|
||||
->label('Plant')
|
||||
->relationship(resolveUsing: 'code')
|
||||
->exampleHeader('Plant Code')
|
||||
->example(['1000'])
|
||||
->label('Plant Code')
|
||||
->rules(['required']),
|
||||
];
|
||||
}
|
||||
|
||||
public function resolveRecord(): ?Locator
|
||||
{
|
||||
// return Locator::firstOrNew([
|
||||
// // Update existing records, matching them by `$this->data['column_name']`
|
||||
// 'email' => $this->data['email'],
|
||||
// ]);
|
||||
$warnMsg = [];
|
||||
$plantCod = $this->data['plant'];
|
||||
$plant = null;
|
||||
$user = null;
|
||||
$locator = $this->data['locator_number'];
|
||||
// $locatorQuantity = $this->data['locator_quantity'];
|
||||
$palletQuantity = 0;
|
||||
if (Str::length($plantCod) < 4 || !is_numeric($plantCod) || !preg_match('/^[1-9]\d{3,}$/', $plantCod)) {
|
||||
$warnMsg[] = "Invalid plant code found";
|
||||
}
|
||||
else
|
||||
{
|
||||
$plant = Plant::where('code', $plantCod)->first();
|
||||
if (!$plant) {
|
||||
$warnMsg[] = "Plant not found";
|
||||
}
|
||||
else
|
||||
{
|
||||
$user = Filament::auth()->user()->name;
|
||||
if (Str::length($locator) < 7) {
|
||||
$warnMsg[] = "Invalid locator number found";
|
||||
}
|
||||
else {
|
||||
// $locat = Locator::where('name', $locator)->where('plant_id', $plant->id)->first();
|
||||
$palletQuantity = PalletValidation::where('locator_number', $locator)->where('plant_id', $plant->id)->distinct('pallet_number')->count('pallet_number');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new Locator();
|
||||
// if (Str::length($locatorQuantity) < 0 || !is_numeric($locatorQuantity) || $locatorQuantity < 0 || $locatorQuantity > 2) {
|
||||
// $warnMsg[] = "Invalid locator quantity found";
|
||||
// }
|
||||
|
||||
// $user = User::where('name', $user)->first();
|
||||
// if (!$user) {
|
||||
// $warnMsg[] = "Operator ID not found";
|
||||
// }
|
||||
|
||||
if (!empty($warnMsg)) {
|
||||
throw new RowImportFailedException(implode(', ', $warnMsg));
|
||||
}
|
||||
|
||||
Locator::updateOrCreate(
|
||||
[
|
||||
'plant_id' => $plant->id,
|
||||
'locator_number' => $locator
|
||||
],
|
||||
[
|
||||
'locator_quantity' => $palletQuantity,
|
||||
'operator_id' => $user
|
||||
]
|
||||
);
|
||||
return null;
|
||||
// // return Locator::firstOrNew([
|
||||
// // // Update existing records, matching them by `$this->data['column_name']`
|
||||
// // 'email' => $this->data['email'],
|
||||
// // ]);
|
||||
|
||||
// return new Locator();
|
||||
}
|
||||
|
||||
public static function getCompletedNotificationBody(Import $import): string
|
||||
|
||||
@@ -3,9 +3,15 @@
|
||||
namespace App\Filament\Imports;
|
||||
|
||||
use App\Models\LocatorInvoiceValidation;
|
||||
use App\Models\Plant;
|
||||
use App\Models\User;
|
||||
use Carbon\Carbon;
|
||||
use Filament\Actions\Imports\Exceptions\RowImportFailedException;
|
||||
use Filament\Actions\Imports\ImportColumn;
|
||||
use Filament\Actions\Imports\Importer;
|
||||
use Filament\Actions\Imports\Models\Import;
|
||||
use Filament\Facades\Filament;
|
||||
use Str;
|
||||
|
||||
class LocatorInvoiceValidationImporter extends Importer
|
||||
{
|
||||
@@ -16,10 +22,10 @@ class LocatorInvoiceValidationImporter extends Importer
|
||||
return [
|
||||
ImportColumn::make('plant')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Plant Name')
|
||||
->example('Ransar Industries-I')
|
||||
->label('Plant Name')
|
||||
->relationship(resolveUsing: 'name')
|
||||
->exampleHeader('Plant Code')
|
||||
->example('1000')
|
||||
->label('Plant Code')
|
||||
->relationship(resolveUsing: 'code')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('invoice_number')
|
||||
->requiredMapping()
|
||||
@@ -34,56 +40,222 @@ class LocatorInvoiceValidationImporter extends Importer
|
||||
->label('Serial Number')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('pallet_number')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Pallet Number')
|
||||
->example('EP-2506001')
|
||||
->label('Pallet Number'),
|
||||
ImportColumn::make('locator_number')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Locator Number')
|
||||
->example('W05-D1B')
|
||||
->label('Locator Number'),
|
||||
ImportColumn::make('scanned_status')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Scanned Status')
|
||||
->example('')
|
||||
->label('Scanned Status'),
|
||||
ImportColumn::make('upload_status')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Upload Status')
|
||||
->example('Y')
|
||||
->label('Upload Status'),
|
||||
ImportColumn::make('created_at')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Created At')
|
||||
->example('2025-06-17 01:42:16')
|
||||
->label('Created At')
|
||||
->rules(['date_format:Y-m-d H:i:s']),
|
||||
->rules(['required']),
|
||||
ImportColumn::make('scanned_at')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Scanned At')
|
||||
->example('2025-06-17 08:42:16')
|
||||
->label('Scanned At')
|
||||
->rules(['date_format:Y-m-d H:i:s']),
|
||||
->label('Scanned At'),
|
||||
ImportColumn::make('updated_at')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Updated At')
|
||||
->example('2025-06-17 08:42:16')
|
||||
->label('Updated At'),
|
||||
ImportColumn::make('created_by')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Created by')
|
||||
->example('RAW002365')
|
||||
->example('RAW012345')
|
||||
->label('Created by')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('scanned_by')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Scanned by')
|
||||
->example('')
|
||||
->example('RAW012345')
|
||||
->label('Scanned by'),
|
||||
ImportColumn::make('updated_by')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Updated by')
|
||||
->example('')
|
||||
->example('RAW012345')
|
||||
->label('Updated by'),
|
||||
];
|
||||
}
|
||||
|
||||
public function resolveRecord(): ?LocatorInvoiceValidation
|
||||
{
|
||||
// return LocatorInvoiceValidation::firstOrNew([
|
||||
// // Update existing records, matching them by `$this->data['column_name']`
|
||||
// 'email' => $this->data['email'],
|
||||
// ]);
|
||||
$warnMsg = [];
|
||||
$plantCod = $this->data['plant'];
|
||||
$plant = null;
|
||||
$invoiceNo = $this->data['invoice_number'];
|
||||
$serialNo = $this->data['serial_number'];
|
||||
$palletNo = $this->data['pallet_number'];
|
||||
$locatorNo = $this->data['locator_number'];
|
||||
$scannedStat = $this->data['scanned_status'];
|
||||
$uploadStat = $this->data['upload_status'];
|
||||
$createdAt = $this->data['created_at'];
|
||||
$scannedAt = $this->data['scanned_at'];
|
||||
$updatedAt = $this->data['updated_at'];
|
||||
$cDateTime = null;
|
||||
$sDateTime = null;
|
||||
$uDateTime = null;
|
||||
$createdBy = $this->data['created_by'];
|
||||
$scannedBy = $this->data['scanned_by'];
|
||||
$updatedBy = $this->data['updated_by'];
|
||||
|
||||
return new LocatorInvoiceValidation();
|
||||
if (Str::length($plantCod) < 4 || !is_numeric($plantCod) || !preg_match('/^[1-9]\d{3,}$/', $plantCod)) {
|
||||
$warnMsg[] = "Invalid plant code found";
|
||||
}
|
||||
else
|
||||
{
|
||||
$plant = Plant::where('code', $this->data['plant'])->first();
|
||||
if (!$plant) {
|
||||
$warnMsg[] = "Plant not found";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Str::length($invoiceNo) < 5 || !ctype_alnum($invoiceNo)) {
|
||||
$warnMsg[] = "Invalid invoice number found";
|
||||
}
|
||||
if (Str::length($serialNo) < 9 || Str::length($serialNo) > 20 || !ctype_alnum($serialNo)) {
|
||||
$warnMsg[] = "Invalid serial number found";
|
||||
}
|
||||
if (Str::length($palletNo) > 0 && Str::length($palletNo) < 10) {
|
||||
$warnMsg[] = "Invalid pallet number found";
|
||||
}
|
||||
if (Str::length($locatorNo) > 0 && Str::length($locatorNo) < 7) {
|
||||
$warnMsg[] = "Invalid locator number found";
|
||||
}
|
||||
if (Str::length($scannedStat) > 0 && $scannedStat != 'Scanned') {
|
||||
$warnMsg[] = "Invalid scanned status found";
|
||||
}
|
||||
if ($uploadStat != 'Y' && $uploadStat != 'N') {
|
||||
$warnMsg[] = "Invalid upload status found";
|
||||
}
|
||||
$created = User::where('name', $createdBy)->first();
|
||||
if (!$created) {
|
||||
$warnMsg[] = "Created by not found";
|
||||
}
|
||||
if (Str::length($scannedBy) > 0) {
|
||||
$scanned = User::where('name', $scannedBy)->first();
|
||||
if (!$scanned) {
|
||||
$warnMsg[] = "Scanned by not found";
|
||||
}
|
||||
}
|
||||
if (Str::length($updatedBy) > 0) {
|
||||
$updated = User::where('name', $updatedBy)->first();
|
||||
if (!$updated) {
|
||||
$warnMsg[] = "Updated by not found";
|
||||
}
|
||||
}
|
||||
|
||||
$formats = ['d-m-Y H:i', 'd-m-Y H:i:s']; //'07-05-2025 08:00' or '07-05-2025 08:00:00'
|
||||
|
||||
foreach ($formats as $format) {
|
||||
try {
|
||||
$cDateTime = Carbon::createFromFormat($format, $createdAt);
|
||||
break;
|
||||
} catch (\Exception $e) {
|
||||
// Optionally collect warning messages
|
||||
// $warnMsg[] = "Date format mismatch with format: $format";
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($cDateTime)) {
|
||||
// throw new \Exception('Invalid date time format');
|
||||
$warnMsg[] = "Invalid 'Created DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
|
||||
}
|
||||
|
||||
if (Str::length($scannedAt) > 0)
|
||||
{
|
||||
foreach ($formats as $format) {
|
||||
try {
|
||||
$sDateTime = Carbon::createFromFormat($format, $scannedAt);
|
||||
break;
|
||||
} catch (\Exception $e) {
|
||||
// Optionally collect warning messages
|
||||
// $warnMsg[] = "Date format mismatch with format: $format";
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($sDateTime)) {
|
||||
$warnMsg[] = "Invalid 'Scanned DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
|
||||
}
|
||||
}
|
||||
|
||||
if (Str::length($updatedAt) > 0)
|
||||
{
|
||||
foreach ($formats as $format) {
|
||||
try {
|
||||
$uDateTime = Carbon::createFromFormat($format, $updatedAt);
|
||||
break;
|
||||
} catch (\Exception $e) {
|
||||
// Optionally collect warning messages
|
||||
// $warnMsg[] = "Date format mismatch with format: $format";
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($uDateTime)) {
|
||||
$warnMsg[] = "Invalid 'Updated DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (isset($cDateTime) && isset($uDateTime)) {
|
||||
if ($cDateTime->greaterThan($uDateTime)) {
|
||||
$warnMsg[] = "'Created DataTime' is greater than 'Updated DateTime'.";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if (!is_numeric($locatorQuantity) || $locatorQuantity < 0 || $locatorQuantity > 2) {
|
||||
// $warnMsg[] = "Invalid locator quantity found";
|
||||
// }
|
||||
|
||||
if (!empty($warnMsg)) {
|
||||
throw new RowImportFailedException(implode(', ', $warnMsg));
|
||||
}
|
||||
|
||||
LocatorInvoiceValidation::updateOrCreate(
|
||||
[
|
||||
'plant_id' => $plant->id,
|
||||
'serial_number' => $serialNo
|
||||
],
|
||||
[
|
||||
'invoice_number' => $invoiceNo,
|
||||
'pallet_number' => $palletNo,
|
||||
'locator_number' => $locatorNo,
|
||||
'scanned_status' => $scannedStat,
|
||||
'upload_status' => $uploadStat,
|
||||
'created_at' => $cDateTime->format('Y-m-d H:i:s'),
|
||||
'scanned_at' => (Str::length($scannedAt) > 0) ? $sDateTime->format('Y-m-d H:i:s') : null,
|
||||
'updated_at' => (Str::length($updatedAt) > 0) ? $uDateTime->format('Y-m-d H:i:s') : null,
|
||||
'created_by' => $createdBy,
|
||||
'scanned_by' => $scannedBy,
|
||||
'updated_by' => $updatedBy
|
||||
]
|
||||
);
|
||||
return null;
|
||||
// // return LocatorInvoiceValidation::firstOrNew([
|
||||
// // // Update existing records, matching them by `$this->data['column_name']`
|
||||
// // 'email' => $this->data['email'],
|
||||
// // ]);
|
||||
|
||||
// return new LocatorInvoiceValidation();
|
||||
}
|
||||
|
||||
public static function getCompletedNotificationBody(Import $import): string
|
||||
|
||||
@@ -2,10 +2,14 @@
|
||||
|
||||
namespace App\Filament\Imports;
|
||||
|
||||
use App\Models\Line;
|
||||
use App\Models\Machine;
|
||||
use App\Models\Plant;
|
||||
use Filament\Actions\Imports\Exceptions\RowImportFailedException;
|
||||
use Filament\Actions\Imports\ImportColumn;
|
||||
use Filament\Actions\Imports\Importer;
|
||||
use Filament\Actions\Imports\Models\Import;
|
||||
use Str;
|
||||
|
||||
class MachineImporter extends Importer
|
||||
{
|
||||
@@ -14,13 +18,17 @@ class MachineImporter extends Importer
|
||||
public static function getColumns(): array
|
||||
{
|
||||
return [
|
||||
ImportColumn::make('plant')
|
||||
ImportColumn::make('name')
|
||||
->requiredMapping()
|
||||
->relationship(resolveUsing: 'name')
|
||||
->exampleHeader('Plant')
|
||||
->example(['Ransar Industries-I'])
|
||||
->label('Plant')
|
||||
->exampleHeader('Machine')
|
||||
->example(['1600251'])
|
||||
->label('Machine')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('work_center')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Work Center')
|
||||
->example('RMGCE001')
|
||||
->label('Work Center'),
|
||||
ImportColumn::make('line')
|
||||
->requiredMapping()
|
||||
->relationship(resolveUsing: 'name')
|
||||
@@ -28,23 +36,66 @@ class MachineImporter extends Importer
|
||||
->example(['4 inch pump line'])
|
||||
->label('Line')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('name')
|
||||
ImportColumn::make('plant')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Name')
|
||||
->example(['1600251'])
|
||||
->label('Line')
|
||||
->relationship(resolveUsing: 'name')
|
||||
->exampleHeader('Plant')
|
||||
->example(['Ransar Industries-I'])
|
||||
->label('Plant')
|
||||
->rules(['required']),
|
||||
];
|
||||
}
|
||||
|
||||
public function resolveRecord(): ?Machine
|
||||
{
|
||||
// return Machine::firstOrNew([
|
||||
// // Update existing records, matching them by `$this->data['column_name']`
|
||||
// 'email' => $this->data['email'],
|
||||
// ]);
|
||||
$warnMsg = [];
|
||||
$plant = Plant::where('name', $this->data['plant'])->first();
|
||||
$line = null;
|
||||
$machine = $this->data['name'];
|
||||
$workCenter = $this->data['work_center'];
|
||||
if (!$plant) {
|
||||
$warnMsg[] = "Plant not found";
|
||||
}
|
||||
else {
|
||||
$line = Line::where('name', $this->data['line'])->where('plant_id', $plant->id)->first();
|
||||
if ($line) {
|
||||
$grpWrkCnr = $line->group_work_center;
|
||||
if (!$grpWrkCnr || Str::length($grpWrkCnr) < 1)
|
||||
{
|
||||
$warnMsg[] = "Group work center line not found";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$warnMsg[] = "Line not found";
|
||||
}
|
||||
}
|
||||
|
||||
return new Machine();
|
||||
if (Str::length($machine) <= 0) {
|
||||
$warnMsg[] = "Machine name not found";
|
||||
}
|
||||
|
||||
if (!empty($warnMsg)) {
|
||||
throw new RowImportFailedException(implode(', ', $warnMsg));
|
||||
}
|
||||
|
||||
Machine::updateOrCreate(
|
||||
[
|
||||
'name' => $machine,
|
||||
'plant_id' => $plant->id,
|
||||
'line_id' => $line->id
|
||||
],
|
||||
[
|
||||
'work_center' => $workCenter
|
||||
]
|
||||
);
|
||||
return null;
|
||||
// // return Machine::firstOrNew([
|
||||
// // // Update existing records, matching them by `$this->data['column_name']`
|
||||
// // 'email' => $this->data['email'],
|
||||
// // ]);
|
||||
|
||||
// return new Machine();
|
||||
}
|
||||
|
||||
public static function getCompletedNotificationBody(Import $import): string
|
||||
|
||||
91
app/Filament/Imports/MfmParameterImporter.php
Normal file
91
app/Filament/Imports/MfmParameterImporter.php
Normal file
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Imports;
|
||||
|
||||
use App\Models\MfmParameter;
|
||||
use Filament\Actions\Imports\ImportColumn;
|
||||
use Filament\Actions\Imports\Importer;
|
||||
use Filament\Actions\Imports\Models\Import;
|
||||
|
||||
class MfmParameterImporter extends Importer
|
||||
{
|
||||
protected static ?string $model = MfmParameter::class;
|
||||
|
||||
public static function getColumns(): array
|
||||
{
|
||||
return [
|
||||
ImportColumn::make('plant')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Plant Name')
|
||||
->example('Ransar Industries-I')
|
||||
->label('Plant Name')
|
||||
->relationship(resolveUsing:'name')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('mfmMeter')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Mfm Meter Sequence')
|
||||
->example('1')
|
||||
->label('Mfm Meter Sequence')
|
||||
->relationship(resolveUsing:'sequence')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('name')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Parameter Name')
|
||||
->example('apparent_energy_received')
|
||||
->label('Parameter Name')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('register_id')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Register ID')
|
||||
->example('2715')
|
||||
->label('Register ID')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('identifier')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Identifier')
|
||||
->example('Kvah')
|
||||
->label('Identifier')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('byte_to_convert')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Byte To Convert')
|
||||
->example('1')
|
||||
->label('Byte To Convert')
|
||||
->rules(['required', 'integer']),
|
||||
ImportColumn::make('type_to_convert')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Type To Convert')
|
||||
->example('FLOAT32')
|
||||
->label('Type To Convert')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('decimal_to_display')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Decimal To Display')
|
||||
->example('2')
|
||||
->label('Decimal To Display')
|
||||
->rules(['required', 'integer']),
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
public function resolveRecord(): ?MfmParameter
|
||||
{
|
||||
// return MfmParameter::firstOrNew([
|
||||
// // Update existing records, matching them by `$this->data['column_name']`
|
||||
// 'email' => $this->data['email'],
|
||||
// ]);
|
||||
|
||||
return new MfmParameter();
|
||||
}
|
||||
|
||||
public static function getCompletedNotificationBody(Import $import): string
|
||||
{
|
||||
$body = 'Your mfm parameter import has completed and ' . number_format($import->successful_rows) . ' ' . str('row')->plural($import->successful_rows) . ' imported.';
|
||||
|
||||
if ($failedRowsCount = $import->getFailedRowsCount()) {
|
||||
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to import.';
|
||||
}
|
||||
|
||||
return $body;
|
||||
}
|
||||
}
|
||||
257
app/Filament/Imports/PalletValidationImporter.php
Normal file
257
app/Filament/Imports/PalletValidationImporter.php
Normal file
@@ -0,0 +1,257 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Imports;
|
||||
|
||||
use App\Models\PalletValidation;
|
||||
use App\Models\Plant;
|
||||
use App\Models\User;
|
||||
use Carbon\Carbon;
|
||||
use Filament\Actions\Imports\Exceptions\RowImportFailedException;
|
||||
use Filament\Actions\Imports\ImportColumn;
|
||||
use Filament\Actions\Imports\Importer;
|
||||
use Filament\Actions\Imports\Models\Import;
|
||||
use Str;
|
||||
|
||||
class PalletValidationImporter extends Importer
|
||||
{
|
||||
protected static ?string $model = PalletValidation::class;
|
||||
|
||||
public static function getColumns(): array
|
||||
{
|
||||
return [
|
||||
ImportColumn::make('plant')
|
||||
->requiredMapping()
|
||||
->label('Plant Code')
|
||||
->exampleHeader('Plant Code')
|
||||
->example('1000')
|
||||
->relationship(resolveUsing: 'code')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('serial_number')
|
||||
->requiredMapping()
|
||||
->label('Serial Number')
|
||||
->exampleHeader('Serial Number')
|
||||
->example('12345678901234')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('pallet_number')
|
||||
->requiredMapping()
|
||||
->label('Pallet Number')
|
||||
->exampleHeader('Pallet Number')
|
||||
->example('EP-2507001'),
|
||||
ImportColumn::make('pallet_status')
|
||||
->requiredMapping()
|
||||
->label('Pallet Status')
|
||||
->exampleHeader('Pallet Status')
|
||||
->example('Completed'),
|
||||
ImportColumn::make('locator_number')
|
||||
->requiredMapping()
|
||||
->label('Locator Number')
|
||||
->exampleHeader('Locator Number')
|
||||
->example('W05-D1B'),
|
||||
ImportColumn::make('locator_quantity')
|
||||
->requiredMapping()
|
||||
->label('Locator Quantity')
|
||||
->exampleHeader('Locator Quantity')
|
||||
->example(1)
|
||||
->rules(['required']),
|
||||
ImportColumn::make('created_at')
|
||||
->requiredMapping()
|
||||
->label('Created At')
|
||||
->exampleHeader('Created At')
|
||||
->example('01-01-2025 08:00:00')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('scanned_at')
|
||||
->requiredMapping()
|
||||
->label('Scanned At')
|
||||
->exampleHeader('Scanned At')
|
||||
->example('01-01-2025 08:00:00')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('updated_at')
|
||||
->requiredMapping()
|
||||
->label('Updated At')
|
||||
->exampleHeader('Updated At')
|
||||
->example('01-01-2025 08:00:00')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('created_by')
|
||||
->requiredMapping()
|
||||
->label('Created By')
|
||||
->exampleHeader('Created By')
|
||||
->example('Admin')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('scanned_by')
|
||||
->requiredMapping()
|
||||
->label('Scanned By')
|
||||
->exampleHeader('Scanned By')
|
||||
->example('Admin')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('updated_by')
|
||||
->requiredMapping()
|
||||
->label('Updated By')
|
||||
->exampleHeader('Updated By')
|
||||
->example('Admin'),
|
||||
];
|
||||
}
|
||||
|
||||
public function resolveRecord(): ?PalletValidation
|
||||
{
|
||||
$warnMsg = [];
|
||||
$plantCod = $this->data['plant'];
|
||||
$plant = null;
|
||||
$serialNo = $this->data['serial_number'];
|
||||
$palletNo = $this->data['pallet_number'];
|
||||
$palletStat = $this->data['pallet_status'];
|
||||
$locatorNo = $this->data['locator_number'];
|
||||
$locatorQty = $this->data['locator_quantity'];
|
||||
$createdAt = $this->data['created_at'];
|
||||
$scannedAt = $this->data['scanned_at'];
|
||||
$updatedAt = $this->data['updated_at'];
|
||||
$cDateTime = null;
|
||||
$sDateTime = null;
|
||||
$uDateTime = null;
|
||||
$createdBy = $this->data['created_by'];
|
||||
$scannedBy = $this->data['scanned_by'];
|
||||
$updatedBy = $this->data['updated_by'];
|
||||
|
||||
if (Str::length($plantCod) < 4 || !is_numeric($plantCod) || !preg_match('/^[1-9]\d{3,}$/', $plantCod)) {
|
||||
$warnMsg[] = "Invalid plant code found";
|
||||
}
|
||||
else
|
||||
{
|
||||
$plant = Plant::where('code', $this->data['plant'])->first();
|
||||
if (!$plant) {
|
||||
$warnMsg[] = "Plant not found";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Str::length($serialNo) < 9 || Str::length($serialNo) > 20 || !ctype_alnum($serialNo)) {
|
||||
$warnMsg[] = "Invalid serial number found";
|
||||
}
|
||||
if (Str::length($palletNo) > 0 && Str::length($palletNo) < 10) {
|
||||
$warnMsg[] = "Invalid pallet number found";
|
||||
}
|
||||
if (Str::length($palletStat) > 0 && $palletStat != 'Completed') {
|
||||
$warnMsg[] = "Invalid pallet status found";
|
||||
}
|
||||
if (Str::length($locatorNo) > 0 && Str::length($locatorNo) < 7) {
|
||||
$warnMsg[] = "Invalid locator number found";
|
||||
}
|
||||
if (Str::length($palletNo) <= 0 && Str::length($locatorNo) <= 0) {
|
||||
$warnMsg[] = "Pallet and locator number found";
|
||||
}
|
||||
if (Str::length($locatorQty) < 0 || !is_numeric($locatorQty) || $locatorQty < 0 || $locatorQty > 2) {
|
||||
$warnMsg[] = "Invalid locator quantity found";
|
||||
}
|
||||
$created = User::where('name', $createdBy)->first();
|
||||
if (!$created) {
|
||||
$warnMsg[] = "Created by not found";
|
||||
}
|
||||
$scanned = User::where('name', $scannedBy)->first();
|
||||
if (!$scanned) {
|
||||
$warnMsg[] = "Scanned by not found";
|
||||
}
|
||||
$updated = User::where('name', $updatedBy)->first();
|
||||
if (!$updated) {
|
||||
$warnMsg[] = "Updated by not found";
|
||||
}
|
||||
|
||||
$formats = ['d-m-Y H:i', 'd-m-Y H:i:s']; //'07-05-2025 08:00' or '07-05-2025 08:00:00'
|
||||
|
||||
foreach ($formats as $format) {
|
||||
try {
|
||||
$cDateTime = Carbon::createFromFormat($format, $createdAt);
|
||||
break;
|
||||
} catch (\Exception $e) {
|
||||
// Optionally collect warning messages
|
||||
// $warnMsg[] = "Date format mismatch with format: $format";
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($cDateTime)) {
|
||||
// throw new \Exception('Invalid date time format');
|
||||
$warnMsg[] = "Invalid 'Created DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
|
||||
}
|
||||
|
||||
foreach ($formats as $format) {
|
||||
try {
|
||||
$sDateTime = Carbon::createFromFormat($format, $scannedAt);
|
||||
break;
|
||||
} catch (\Exception $e) {
|
||||
// Optionally collect warning messages
|
||||
// $warnMsg[] = "Date format mismatch with format: $format";
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($sDateTime)) {
|
||||
$warnMsg[] = "Invalid 'Scanned DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
|
||||
}
|
||||
|
||||
foreach ($formats as $format) {
|
||||
try
|
||||
{
|
||||
$uDateTime = Carbon::createFromFormat($format, $updatedAt);
|
||||
break;
|
||||
} catch (\Exception $e) {
|
||||
// Optionally collect warning messages
|
||||
// $warnMsg[] = "Date format mismatch with format: $format";
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($uDateTime)) {
|
||||
$warnMsg[] = "Invalid 'Updated DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (isset($cDateTime) && isset($uDateTime)) {
|
||||
if ($cDateTime->greaterThan($uDateTime)) {
|
||||
$warnMsg[] = "'Created DataTime' is greater than 'Updated DateTime'.";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if (!is_numeric($locatorQuantity) || $locatorQuantity < 0 || $locatorQuantity > 2) {
|
||||
// $warnMsg[] = "Invalid locator quantity found";
|
||||
// }
|
||||
|
||||
if (!empty($warnMsg)) {
|
||||
throw new RowImportFailedException(implode(', ', $warnMsg));
|
||||
}
|
||||
|
||||
PalletValidation::updateOrCreate(
|
||||
[
|
||||
'plant_id' => $plant->id,
|
||||
'serial_number' => $serialNo
|
||||
],
|
||||
[
|
||||
'pallet_number' => $palletNo,
|
||||
'pallet_status' => $palletStat,
|
||||
'locator_number' => $locatorNo,
|
||||
'locator_quantity' => $locatorQty,
|
||||
'created_at' => $cDateTime->format('Y-m-d H:i:s'),
|
||||
'scanned_at' => $sDateTime->format('Y-m-d H:i:s'),
|
||||
'updated_at' => $uDateTime->format('Y-m-d H:i:s'),
|
||||
'created_by' => $createdBy,
|
||||
'scanned_by' => $scannedBy,
|
||||
'updated_by' => $updatedBy
|
||||
]
|
||||
);
|
||||
return null;
|
||||
// // return PalletValidation::firstOrNew([
|
||||
// // // Update existing records, matching them by `$this->data['column_name']`
|
||||
// // 'email' => $this->data['email'],
|
||||
// // ]);
|
||||
|
||||
// return new PalletValidation();
|
||||
}
|
||||
|
||||
public static function getCompletedNotificationBody(Import $import): string
|
||||
{
|
||||
$body = 'Your pallet validation import has completed and ' . number_format($import->successful_rows) . ' ' . str('row')->plural($import->successful_rows) . ' imported.';
|
||||
|
||||
if ($failedRowsCount = $import->getFailedRowsCount()) {
|
||||
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to import.';
|
||||
}
|
||||
|
||||
return $body;
|
||||
}
|
||||
}
|
||||
@@ -24,13 +24,6 @@ class PlantImporter extends Importer
|
||||
->example('1000')
|
||||
->label('Plant Code')
|
||||
->rules(['required']), //, 'integer'
|
||||
ImportColumn::make('company')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Company Name')
|
||||
->example('C.R.I. Pumps Private Limited')
|
||||
->label('Company Name')
|
||||
->relationship(resolveUsing:'name')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('name')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Plant Name')
|
||||
@@ -43,6 +36,13 @@ class PlantImporter extends Importer
|
||||
->example('7/51-A, Keeranatham Road, Saravanampatty, Coimbatore - 641035')
|
||||
->label('Plant Address')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('company')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Company Name')
|
||||
->example('C.R.I. Pumps Private Limited')
|
||||
->label('Company Name')
|
||||
->relationship(resolveUsing:'name')
|
||||
->rules(['required']),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -30,20 +30,6 @@ class QualityValidationImporter extends Importer
|
||||
->example('12-02-2025 15:51:00')
|
||||
->label('Created DateTime')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('plant')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Plant Name')
|
||||
->example('Ransar Industries-I')
|
||||
->label('Plant Name')
|
||||
->relationship(resolveUsing:'name')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('line')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Line Name')
|
||||
->example('4 inch pump line')
|
||||
->label('Line Name')
|
||||
->relationship(resolveUsing:'name')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('sticker_master_id_code') // stickerMaster.item
|
||||
->requiredMapping()
|
||||
->exampleHeader('Item Code')
|
||||
@@ -165,6 +151,20 @@ class QualityValidationImporter extends Importer
|
||||
->exampleHeader('Unit of Measure')
|
||||
->example('EA')
|
||||
->label('Unit of Measure'),
|
||||
ImportColumn::make('line')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Line Name')
|
||||
->example('4 inch pump line')
|
||||
->label('Line Name')
|
||||
->relationship(resolveUsing:'name')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('plant')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Plant Name')
|
||||
->example('Ransar Industries-I')
|
||||
->label('Plant Name')
|
||||
->relationship(resolveUsing:'name')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('updated_at')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Updated DateTime')
|
||||
|
||||
308
app/Filament/Imports/ReworkLocatorInvoiceValidationImporter.php
Normal file
308
app/Filament/Imports/ReworkLocatorInvoiceValidationImporter.php
Normal file
@@ -0,0 +1,308 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Imports;
|
||||
|
||||
use App\Models\Plant;
|
||||
use App\Models\ReworkLocatorInvoiceValidation;
|
||||
use App\Models\User;
|
||||
use Carbon\Carbon;
|
||||
use Filament\Actions\Imports\Exceptions\RowImportFailedException;
|
||||
use Filament\Actions\Imports\ImportColumn;
|
||||
use Filament\Actions\Imports\Importer;
|
||||
use Filament\Actions\Imports\Models\Import;
|
||||
use Str;
|
||||
|
||||
class ReworkLocatorInvoiceValidationImporter extends Importer
|
||||
{
|
||||
protected static ?string $model = ReworkLocatorInvoiceValidation::class;
|
||||
|
||||
public static function getColumns(): array
|
||||
{
|
||||
return [
|
||||
ImportColumn::make('plant')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Plant Code')
|
||||
->example('1000')
|
||||
->label('Plant Code')
|
||||
->relationship(resolveUsing: 'code')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('invoice_number')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Invoice Number')
|
||||
->example('3RA002514')
|
||||
->label('Invoice Number')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('serial_number')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Serial Number')
|
||||
->example('25145441154545')
|
||||
->label('Serial Number')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('pallet_number')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Pallet Number')
|
||||
->example('')
|
||||
->label('Pallet Number'),
|
||||
ImportColumn::make('locator_number')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Locator Number')
|
||||
->example('')
|
||||
->label('Locator Number'),
|
||||
ImportColumn::make('scanned_status')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Scanned Status')
|
||||
->example('')
|
||||
->label('Scanned Status')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('upload_status')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Upload Status')
|
||||
->example('Y')
|
||||
->label('Upload Status')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('created_at')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Created At')
|
||||
->example('2025-06-17 08:42:16')
|
||||
->label('Created At')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('scanned_at')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Scanned At')
|
||||
->example('2025-06-17 08:42:16')
|
||||
->label('Scanned At')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('updated_at')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Updated At')
|
||||
->example('2025-06-17 08:42:16')
|
||||
->label('Updated At')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('reworked_at')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Reworked At')
|
||||
->example('2025-06-17 08:42:16')
|
||||
->label('Reworked At')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('created_by')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Created By')
|
||||
->example('admin')
|
||||
->label('Created By')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('scanned_by')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Scanned By')
|
||||
->example('admin')
|
||||
->label('Scanned By')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('updated_by')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Updated By')
|
||||
->example('admin')
|
||||
->label('Updated By'),
|
||||
ImportColumn::make('reworked_by')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Reworked By')
|
||||
->example('admin')
|
||||
->label('Reworked By')
|
||||
->rules(['required']),
|
||||
];
|
||||
}
|
||||
|
||||
public function resolveRecord(): ?ReworkLocatorInvoiceValidation
|
||||
{
|
||||
$warnMsg = [];
|
||||
$plantCod = $this->data['plant'];
|
||||
$plant = null;
|
||||
$invoiceNo = $this->data['invoice_number'];
|
||||
$serialNo = $this->data['serial_number'];
|
||||
$palletNo = $this->data['pallet_number'];
|
||||
$locatorNo = $this->data['locator_number'];
|
||||
$scannedStat = $this->data['scanned_status'];
|
||||
$uploadStat = $this->data['upload_status'];
|
||||
$createdAt = $this->data['created_at'];
|
||||
$scannedAt = $this->data['scanned_at'];
|
||||
$updatedAt = $this->data['updated_at'];
|
||||
$reworkedAt = $this->data['reworked_at'];
|
||||
$cDateTime = null;
|
||||
$sDateTime = null;
|
||||
$uDateTime = null;
|
||||
$rDateTime = null;
|
||||
$createdBy = $this->data['created_by'];
|
||||
$scannedBy = $this->data['scanned_by'];
|
||||
$updatedBy = $this->data['updated_by'];
|
||||
$reworkedBy = $this->data['reworked_by'];
|
||||
|
||||
if (Str::length($plantCod) < 4 || !is_numeric($plantCod) || !preg_match('/^[1-9]\d{3,}$/', $plantCod)) {
|
||||
$warnMsg[] = "Invalid plant code found";
|
||||
}
|
||||
else
|
||||
{
|
||||
$plant = Plant::where('code', $this->data['plant'])->first();
|
||||
if (!$plant) {
|
||||
$warnMsg[] = "Plant not found";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Str::length($invoiceNo) < 5 || !ctype_alnum($invoiceNo)) {
|
||||
$warnMsg[] = "Invalid invoice number found";
|
||||
}
|
||||
if (Str::length($serialNo) < 9 || Str::length($serialNo) > 20 || !ctype_alnum($serialNo)) {
|
||||
$warnMsg[] = "Invalid serial number found";
|
||||
}
|
||||
if (Str::length($palletNo) > 0 && Str::length($palletNo) < 10) {
|
||||
$warnMsg[] = "Invalid pallet number found";
|
||||
}
|
||||
if (Str::length($locatorNo) > 0 && Str::length($locatorNo) < 7) {
|
||||
$warnMsg[] = "Invalid locator number found";
|
||||
}
|
||||
if ($scannedStat != 'Scanned') {
|
||||
$warnMsg[] = "Invalid scanned status found";
|
||||
}
|
||||
if ($uploadStat != 'Y' && $uploadStat != 'N') {
|
||||
$warnMsg[] = "Invalid upload status found";
|
||||
}
|
||||
$created = User::where('name', $createdBy)->first();
|
||||
if (!$created) {
|
||||
$warnMsg[] = "Created by not found";
|
||||
}
|
||||
$scanned = User::where('name', $scannedBy)->first();
|
||||
if (!$scanned) {
|
||||
$warnMsg[] = "Scanned by not found";
|
||||
}
|
||||
if (Str::length($updatedBy) > 0) {
|
||||
$updated = User::where('name', $updatedBy)->first();
|
||||
if (!$updated) {
|
||||
$warnMsg[] = "Updated by not found";
|
||||
}
|
||||
}
|
||||
$reworked = User::where('name', $reworkedBy)->first();
|
||||
if (!$reworked) {
|
||||
$warnMsg[] = "Reworked by not found";
|
||||
}
|
||||
|
||||
$formats = ['d-m-Y H:i', 'd-m-Y H:i:s']; //'07-05-2025 08:00' or '07-05-2025 08:00:00'
|
||||
|
||||
foreach ($formats as $format) {
|
||||
try {
|
||||
$cDateTime = Carbon::createFromFormat($format, $createdAt);
|
||||
break;
|
||||
} catch (\Exception $e) {
|
||||
// Optionally collect warning messages
|
||||
// $warnMsg[] = "Date format mismatch with format: $format";
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($cDateTime)) {
|
||||
// throw new \Exception('Invalid date time format');
|
||||
$warnMsg[] = "Invalid 'Created DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
|
||||
}
|
||||
|
||||
foreach ($formats as $format) {
|
||||
try {
|
||||
$sDateTime = Carbon::createFromFormat($format, $scannedAt);
|
||||
break;
|
||||
} catch (\Exception $e) {
|
||||
// Optionally collect warning messages
|
||||
// $warnMsg[] = "Date format mismatch with format: $format";
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($sDateTime)) {
|
||||
$warnMsg[] = "Invalid 'Scanned DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
|
||||
}
|
||||
|
||||
foreach ($formats as $format) {
|
||||
try {
|
||||
$uDateTime = Carbon::createFromFormat($format, $updatedAt);
|
||||
break;
|
||||
} catch (\Exception $e) {
|
||||
// Optionally collect warning messages
|
||||
// $warnMsg[] = "Date format mismatch with format: $format";
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($uDateTime)) {
|
||||
$warnMsg[] = "Invalid 'Updated DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (isset($cDateTime) && isset($uDateTime)) {
|
||||
if ($cDateTime->greaterThan($uDateTime)) {
|
||||
$warnMsg[] = "'Created DataTime' is greater than 'Updated DateTime'.";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($formats as $format) {
|
||||
try {
|
||||
$rDateTime = Carbon::createFromFormat($format, $reworkedAt);
|
||||
break;
|
||||
} catch (\Exception $e) {
|
||||
// Optionally collect warning messages
|
||||
// $warnMsg[] = "Date format mismatch with format: $format";
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($rDateTime)) {
|
||||
$warnMsg[] = "Invalid 'Reworked DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (isset($cDateTime) && isset($rDateTime)) {
|
||||
if ($cDateTime->greaterThan($rDateTime)) {
|
||||
$warnMsg[] = "'Created DataTime' is greater than 'Reworked DateTime'.";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if (!is_numeric($locatorQuantity) || $locatorQuantity < 0 || $locatorQuantity > 2) {
|
||||
// $warnMsg[] = "Invalid locator quantity found";
|
||||
// }
|
||||
|
||||
if (!empty($warnMsg)) {
|
||||
throw new RowImportFailedException(implode(', ', $warnMsg));
|
||||
}
|
||||
|
||||
ReworkLocatorInvoiceValidation::updateOrCreate(
|
||||
[
|
||||
'plant_id' => $plant->id,
|
||||
'serial_number' => $serialNo,
|
||||
'invoice_number' => $invoiceNo,
|
||||
'pallet_number' => $palletNo,
|
||||
'locator_number' => $locatorNo,
|
||||
'scanned_status' => $scannedStat,
|
||||
'upload_status' => $uploadStat,
|
||||
'created_at' => $cDateTime->format('Y-m-d H:i:s'),
|
||||
'scanned_at' => $sDateTime->format('Y-m-d H:i:s'),
|
||||
'updated_at' => $uDateTime->format('Y-m-d H:i:s'),
|
||||
'reworked_at' => $rDateTime->format('Y-m-d H:i:s'),
|
||||
'created_by' => $createdBy,
|
||||
'scanned_by' => $scannedBy,
|
||||
'updated_by' => $updatedBy,
|
||||
'reworked_by' => $reworkedBy
|
||||
]
|
||||
);
|
||||
return null;
|
||||
// // return ReworkLocatorInvoiceValidation::firstOrNew([
|
||||
// // // Update existing records, matching them by `$this->data['column_name']`
|
||||
// // 'email' => $this->data['email'],
|
||||
// // ]);
|
||||
|
||||
// return new ReworkLocatorInvoiceValidation();
|
||||
}
|
||||
|
||||
public static function getCompletedNotificationBody(Import $import): string
|
||||
{
|
||||
$body = 'Your rework locator invoice validation import has completed and ' . number_format($import->successful_rows) . ' ' . str('row')->plural($import->successful_rows) . ' imported.';
|
||||
|
||||
if ($failedRowsCount = $import->getFailedRowsCount()) {
|
||||
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to import.';
|
||||
}
|
||||
|
||||
return $body;
|
||||
}
|
||||
}
|
||||
@@ -24,20 +24,6 @@ class ShiftImporter extends Importer
|
||||
->example('Day')
|
||||
->label('Shift Name')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('block')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Block Name')
|
||||
->example('Block A')
|
||||
->label('Block Name')
|
||||
->relationship(resolveUsing:'name')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('plant')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Plant Name')
|
||||
->example('Ransar Industries-I')
|
||||
->label('Plant Name')
|
||||
->relationship(resolveUsing:'name')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('start_time')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Start Time')
|
||||
@@ -57,6 +43,20 @@ class ShiftImporter extends Importer
|
||||
->example('19:30:00')
|
||||
->label('End Time')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('block')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Block Name')
|
||||
->example('Block A')
|
||||
->label('Block Name')
|
||||
->relationship(resolveUsing:'name')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('plant')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Plant Name')
|
||||
->example('Ransar Industries-I')
|
||||
->label('Plant Name')
|
||||
->relationship(resolveUsing:'name')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('status')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Active Status')
|
||||
|
||||
@@ -25,7 +25,130 @@ class StickerMasterImporter extends Importer
|
||||
->label('ITEM CODE')
|
||||
->relationship(resolveUsing: 'code')
|
||||
->rules(['required']),
|
||||
|
||||
ImportColumn::make('serial_number_motor')
|
||||
// ->requiredMapping()
|
||||
->exampleHeader('Serial Number Motor')
|
||||
->label('SERIAL NUMBER MOTOR')
|
||||
->example('1'),
|
||||
ImportColumn::make('serial_number_pump')
|
||||
//->requiredMapping()
|
||||
->exampleHeader('Serial Number Pump')
|
||||
->label('SERIAL NUMBER PUMP')
|
||||
->example('1'),
|
||||
ImportColumn::make('serial_number_pumpset')
|
||||
//->requiredMapping()
|
||||
->exampleHeader('Serial Number PumpSet')
|
||||
->label('SERIAL NUMBER PUMPSET')
|
||||
->example(''),
|
||||
ImportColumn::make('pack_slip_motor')
|
||||
//->requiredMapping()
|
||||
->exampleHeader('Pack Slip Motor')
|
||||
->label('PACK SLIP MOTOR')
|
||||
->example('1'),
|
||||
ImportColumn::make('pack_slip_pump')
|
||||
//->requiredMapping()
|
||||
->exampleHeader('Pack Slip Pump')
|
||||
->label('PACK SLIP PUMP')
|
||||
->example('1'),
|
||||
ImportColumn::make('pack_slip_pumpset')
|
||||
//->requiredMapping()
|
||||
->exampleHeader('Pack Slip PumpSet')
|
||||
->label('PACK SLIP PUMPSET')
|
||||
->example(''),
|
||||
ImportColumn::make('name_plate_motor')
|
||||
// ->requiredMapping()
|
||||
->exampleHeader('Name Plate Motor')
|
||||
->label('NAME PLATE MOTOR')
|
||||
->example('1'),
|
||||
ImportColumn::make('name_plate_pump')
|
||||
// ->requiredMapping()
|
||||
->exampleHeader('Name Plate Pump')
|
||||
->label('NAME PLATE PUMP')
|
||||
->example('1'),
|
||||
ImportColumn::make('name_plate_pumpset')
|
||||
// ->requiredMapping()
|
||||
->exampleHeader('Name Plate PumpSet')
|
||||
->label('NAME PLATE PUMPSET')
|
||||
->example(''),
|
||||
ImportColumn::make('tube_sticker_motor')
|
||||
// ->requiredMapping()
|
||||
->exampleHeader('Tube Sticker Motor')
|
||||
->label('TUBE STICKER MOTOR')
|
||||
->example('1'),
|
||||
ImportColumn::make('tube_sticker_pump')
|
||||
// ->requiredMapping()
|
||||
->exampleHeader('Tube Sticker Pump')
|
||||
->label('TUBE STICKER PUMP')
|
||||
->example('1'),
|
||||
ImportColumn::make('tube_sticker_pumpset')
|
||||
// ->requiredMapping()
|
||||
->exampleHeader('Tube Sticker PumpSet')
|
||||
->label('TUBE STICKER PUMPSET')
|
||||
->example(''),
|
||||
ImportColumn::make('warranty_card')
|
||||
// ->requiredMapping()
|
||||
->exampleHeader('Warranty Card')
|
||||
->label('WARRANTY CARD')
|
||||
->example('1'),
|
||||
ImportColumn::make('part_validation1')
|
||||
// ->requiredMapping()
|
||||
->exampleHeader('Part Validation 1')
|
||||
->label('PART VALIDATION 1')
|
||||
->example('12345'),
|
||||
ImportColumn::make('part_validation2')
|
||||
// ->requiredMapping()
|
||||
->exampleHeader('Part Validation 2')
|
||||
->label('PART VALIDATION 2')
|
||||
->example('23456'),
|
||||
ImportColumn::make('part_validation3')
|
||||
// ->requiredMapping()
|
||||
->exampleHeader('Part Validation 3')
|
||||
->label('PART VALIDATION 3')
|
||||
->example('34567'),
|
||||
ImportColumn::make('part_validation4')
|
||||
// ->requiredMapping()
|
||||
->exampleHeader('Part Validation 4')
|
||||
->label('PART VALIDATION 4')
|
||||
->example('45678'),
|
||||
ImportColumn::make('part_validation5')
|
||||
// ->requiredMapping()
|
||||
->exampleHeader('Part Validation 5')
|
||||
->label('PART VALIDATION 5')
|
||||
->example('56789'),
|
||||
ImportColumn::make('laser_part_validation1')
|
||||
// ->requiredMapping()
|
||||
->exampleHeader('Laser Part Validation 1')
|
||||
->label('LASER PART VALIDATION 1')
|
||||
->example('67890'),
|
||||
ImportColumn::make('laser_part_validation2')
|
||||
// ->requiredMapping()
|
||||
->exampleHeader('Laser Part Validation 2')
|
||||
->label('LASER PART VALIDATION 2')
|
||||
->example('78901'),
|
||||
ImportColumn::make('panel_box_code')
|
||||
// ->requiredMapping()
|
||||
->exampleHeader('Panel Box Code')
|
||||
->label('PANEL BOX CODE')
|
||||
->example('123456'),
|
||||
ImportColumn::make('load_rate')
|
||||
->requiredMapping()
|
||||
->integer()
|
||||
->exampleHeader('Load Rate')
|
||||
->label('LOAD RATE')
|
||||
->example('0')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('material_type')
|
||||
// ->requiredMapping()
|
||||
->integer()
|
||||
->exampleHeader('Material Type')
|
||||
->label('MATERIAL TYPE')
|
||||
->example(''),
|
||||
ImportColumn::make('bundle_quantity')
|
||||
// ->requiredMapping()
|
||||
->integer()
|
||||
->exampleHeader('Bundle Quantity')
|
||||
->label('BUNDLE QUANTITY')
|
||||
->example(''),
|
||||
ImportColumn::make('plant')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Plant Name')
|
||||
@@ -33,223 +156,84 @@ class StickerMasterImporter extends Importer
|
||||
->label('PLANT NAME')
|
||||
->relationship(resolveUsing: 'name')
|
||||
->rules(['required']),
|
||||
|
||||
ImportColumn::make('serial_number_motor')
|
||||
// ->requiredMapping()
|
||||
->exampleHeader('Serial Number Motor')
|
||||
->label('SERIAL NUMBER MOTOR')
|
||||
->example('1'),
|
||||
|
||||
ImportColumn::make('serial_number_pump')
|
||||
//->requiredMapping()
|
||||
->exampleHeader('Serial Number Pump')
|
||||
->label('SERIAL NUMBER PUMP')
|
||||
->example('1'),
|
||||
|
||||
ImportColumn::make('serial_number_pumpset')
|
||||
//->requiredMapping()
|
||||
->exampleHeader('Serial Number PumpSet')
|
||||
->label('SERIAL NUMBER PUMPSET')
|
||||
->example(''),
|
||||
|
||||
ImportColumn::make('pack_slip_motor')
|
||||
//->requiredMapping()
|
||||
->exampleHeader('Pack Slip Motor')
|
||||
->label('PACK SLIP MOTOR')
|
||||
->example('1'),
|
||||
|
||||
ImportColumn::make('pack_slip_pump')
|
||||
//->requiredMapping()
|
||||
->exampleHeader('Pack Slip Pump')
|
||||
->label('PACK SLIP PUMP')
|
||||
->example('1'),
|
||||
|
||||
ImportColumn::make('pack_slip_pumpset')
|
||||
//->requiredMapping()
|
||||
->exampleHeader('Pack Slip PumpSet')
|
||||
->label('PACK SLIP PUMPSET')
|
||||
->example(''),
|
||||
|
||||
ImportColumn::make('name_plate_motor')
|
||||
// ->requiredMapping()
|
||||
->exampleHeader('Name Plate Motor')
|
||||
->label('NAME PLATE MOTOR')
|
||||
->example('1'),
|
||||
|
||||
ImportColumn::make('name_plate_pump')
|
||||
// ->requiredMapping()
|
||||
->exampleHeader('Name Plate Pump')
|
||||
->label('NAME PLATE PUMP')
|
||||
->example('1'),
|
||||
|
||||
ImportColumn::make('name_plate_pumpset')
|
||||
// ->requiredMapping()
|
||||
->exampleHeader('Name Plate PumpSet')
|
||||
->label('NAME PLATE PUMPSET')
|
||||
->example(''),
|
||||
|
||||
ImportColumn::make('tube_sticker_motor')
|
||||
// ->requiredMapping()
|
||||
->exampleHeader('Tube Sticker Motor')
|
||||
->label('TUBE STICKER MOTOR')
|
||||
->example('1'),
|
||||
|
||||
ImportColumn::make('tube_sticker_pump')
|
||||
// ->requiredMapping()
|
||||
->exampleHeader('Tube Sticker Pump')
|
||||
->label('TUBE STICKER PUMP')
|
||||
->example('1'),
|
||||
|
||||
ImportColumn::make('tube_sticker_pumpset')
|
||||
// ->requiredMapping()
|
||||
->exampleHeader('Tube Sticker PumpSet')
|
||||
->label('TUBE STICKER PUMPSET')
|
||||
->example(''),
|
||||
|
||||
ImportColumn::make('warranty_card')
|
||||
// ->requiredMapping()
|
||||
->exampleHeader('Warranty Card')
|
||||
->label('WARRANTY CARD')
|
||||
->example('1'),
|
||||
|
||||
ImportColumn::make('part_validation1')
|
||||
// ->requiredMapping()
|
||||
->exampleHeader('Part Validation 1')
|
||||
->label('PART VALIDATION 1')
|
||||
->example('12345'),
|
||||
|
||||
|
||||
ImportColumn::make('part_validation2')
|
||||
// ->requiredMapping()
|
||||
->exampleHeader('Part Validation 2')
|
||||
->label('PART VALIDATION 2')
|
||||
->example('23456'),
|
||||
|
||||
|
||||
ImportColumn::make('part_validation3')
|
||||
// ->requiredMapping()
|
||||
->exampleHeader('Part Validation 3')
|
||||
->label('PART VALIDATION 3')
|
||||
->example('34567'),
|
||||
|
||||
|
||||
ImportColumn::make('part_validation4')
|
||||
// ->requiredMapping()
|
||||
->exampleHeader('Part Validation 4')
|
||||
->label('PART VALIDATION 4')
|
||||
->example('45678'),
|
||||
|
||||
|
||||
ImportColumn::make('part_validation5')
|
||||
// ->requiredMapping()
|
||||
->exampleHeader('Part Validation 5')
|
||||
->label('PART VALIDATION 5')
|
||||
->example('56789'),
|
||||
|
||||
|
||||
ImportColumn::make('panel_box_code')
|
||||
//->requiredMapping()
|
||||
->exampleHeader('Panel Box Code')
|
||||
->label('PANEL BOX CODE')
|
||||
->example('123456'),
|
||||
|
||||
|
||||
ImportColumn::make('load_rate')
|
||||
// ->requiredMapping()
|
||||
->integer()
|
||||
->exampleHeader('Load Rate')
|
||||
->label('LOAD RATE')
|
||||
->example('0'),
|
||||
|
||||
|
||||
ImportColumn::make('bundle_quantity')
|
||||
// ->requiredMapping()
|
||||
->integer()
|
||||
->exampleHeader('Bundle Quantity')
|
||||
->label('BUNDLE QUANTITY')
|
||||
->example(''),
|
||||
|
||||
|
||||
ImportColumn::make('material_type')
|
||||
// ->requiredMapping()
|
||||
->integer()
|
||||
->exampleHeader('Material Type')
|
||||
->label('MATERIAL TYPE')
|
||||
->example(''),
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
public function resolveRecord(): ?StickerMaster
|
||||
{
|
||||
$warnMsg = [];
|
||||
$item = null;
|
||||
$plant = Plant::where('name', $this->data['plant'])->first();
|
||||
if (!$plant) {
|
||||
$warnMsg[] = "Plant not found";
|
||||
}
|
||||
$item = null;
|
||||
if ($plant) {
|
||||
else
|
||||
{
|
||||
$item = Item::where('code', $this->data['item'])->where('plant_id', $plant->id)->first();
|
||||
}
|
||||
if (!$item) {
|
||||
$warnMsg[] = "Item code not found";
|
||||
}
|
||||
if (Str::length($this->data['serial_number_motor']) > 0 && $this->data['serial_number_motor'] != '1') {
|
||||
$warnMsg[] = "Serial number motor must be 1 or empty";
|
||||
}
|
||||
if (Str::length($this->data['serial_number_pump']) > 0 && $this->data['serial_number_pump'] != '1') {
|
||||
$warnMsg[] = "Serial number pump must be 1 or empty";
|
||||
}
|
||||
if (Str::length($this->data['serial_number_pumpset']) > 0 && $this->data['serial_number_pumpset'] != '1') {
|
||||
$warnMsg[] = "Serial number pumpset must be 1 or empty";
|
||||
}
|
||||
if (Str::length($this->data['pack_slip_motor']) > 0 && $this->data['pack_slip_motor'] != '1') {
|
||||
$warnMsg[] = "Pack slip motor must be 1 or empty";
|
||||
}
|
||||
if (Str::length($this->data['pack_slip_pump']) > 0 && $this->data['pack_slip_pump'] != '1') {
|
||||
$warnMsg[] = "Pack slip pump must be 1 or empty";
|
||||
}
|
||||
if (Str::length($this->data['pack_slip_pumpset']) > 0 && $this->data['pack_slip_pumpset'] != '1') {
|
||||
$warnMsg[] = "Pack slip pumpset must be 1 or empty";
|
||||
}
|
||||
if (Str::length($this->data['name_plate_motor']) > 0 && $this->data['name_plate_motor'] != '1') {
|
||||
$warnMsg[] = "Name plate motor must be 1 or empty";
|
||||
}
|
||||
if (Str::length($this->data['name_plate_pump']) > 0 && $this->data['name_plate_pump'] != '1') {
|
||||
$warnMsg[] = "Name plate pump must be 1 or empty";
|
||||
}
|
||||
if (Str::length($this->data['name_plate_pumpset']) > 0 && $this->data['name_plate_pumpset'] != '1') {
|
||||
$warnMsg[] = "Name plate pumpset must be 1 or empty";
|
||||
}
|
||||
if (Str::length($this->data['tube_sticker_motor']) > 0 && $this->data['tube_sticker_motor'] != '1') {
|
||||
$warnMsg[] = "Tube sticker motor must be 1 or empty";
|
||||
}
|
||||
if (Str::length($this->data['tube_sticker_pump']) > 0 && $this->data['tube_sticker_pump'] != '1') {
|
||||
$warnMsg[] = "Tube sticker pump must be 1 or empty";
|
||||
}
|
||||
if (Str::length($this->data['tube_sticker_pumpset']) > 0 && $this->data['tube_sticker_pumpset'] != '1') {
|
||||
$warnMsg[] = "Tube sticker pumpset must be 1 or empty";
|
||||
}
|
||||
if (Str::length($this->data['warranty_card']) > 0 && $this->data['warranty_card'] != '1') {
|
||||
$warnMsg[] = "Warranty card must be 1 or empty";
|
||||
}
|
||||
if (Str::length($this->data['panel_box_code']) > 0 && (Str::length($this->data['panel_box_code']) < 6 || !ctype_alnum($this->data['panel_box_code']))) {
|
||||
$warnMsg[] = "Invalid panel box code found";
|
||||
}
|
||||
if (!is_numeric($this->data['load_rate']) || $this->data['load_rate'] < 0) {
|
||||
$warnMsg[] = "Load rate must be greater than or equal to 0";
|
||||
}
|
||||
if (Str::length($this->data['bundle_quantity']) > 0 && (!is_numeric($this->data['bundle_quantity']) || $this->data['bundle_quantity'] <= 1)) {
|
||||
$warnMsg[] = "Bundle quantity must be greater than or equal to '2' or empty";
|
||||
}
|
||||
if (Str::length($this->data['material_type']) > 0 && $this->data['material_type'] != '1' && $this->data['material_type'] != '2' && $this->data['material_type'] != '3') { //($this->data['material_type'] != null) &&
|
||||
$warnMsg[] = "Material type must be 1 or 2 or 3 or empty";
|
||||
if (!$item) {
|
||||
$warnMsg[] = "Item code not found";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Str::length($this->data['serial_number_motor']) > 0 && $this->data['serial_number_motor'] != '1') {
|
||||
$warnMsg[] = "Serial number motor must be 1 or empty";
|
||||
}
|
||||
if (Str::length($this->data['serial_number_pump']) > 0 && $this->data['serial_number_pump'] != '1') {
|
||||
$warnMsg[] = "Serial number pump must be 1 or empty";
|
||||
}
|
||||
if (Str::length($this->data['serial_number_pumpset']) > 0 && $this->data['serial_number_pumpset'] != '1') {
|
||||
$warnMsg[] = "Serial number pumpset must be 1 or empty";
|
||||
}
|
||||
if (Str::length($this->data['pack_slip_motor']) > 0 && $this->data['pack_slip_motor'] != '1') {
|
||||
$warnMsg[] = "Pack slip motor must be 1 or empty";
|
||||
}
|
||||
if (Str::length($this->data['pack_slip_pump']) > 0 && $this->data['pack_slip_pump'] != '1') {
|
||||
$warnMsg[] = "Pack slip pump must be 1 or empty";
|
||||
}
|
||||
if (Str::length($this->data['pack_slip_pumpset']) > 0 && $this->data['pack_slip_pumpset'] != '1') {
|
||||
$warnMsg[] = "Pack slip pumpset must be 1 or empty";
|
||||
}
|
||||
if (Str::length($this->data['name_plate_motor']) > 0 && $this->data['name_plate_motor'] != '1') {
|
||||
$warnMsg[] = "Name plate motor must be 1 or empty";
|
||||
}
|
||||
if (Str::length($this->data['name_plate_pump']) > 0 && $this->data['name_plate_pump'] != '1') {
|
||||
$warnMsg[] = "Name plate pump must be 1 or empty";
|
||||
}
|
||||
if (Str::length($this->data['name_plate_pumpset']) > 0 && $this->data['name_plate_pumpset'] != '1') {
|
||||
$warnMsg[] = "Name plate pumpset must be 1 or empty";
|
||||
}
|
||||
if (Str::length($this->data['tube_sticker_motor']) > 0 && $this->data['tube_sticker_motor'] != '1') {
|
||||
$warnMsg[] = "Tube sticker motor must be 1 or empty";
|
||||
}
|
||||
if (Str::length($this->data['tube_sticker_pump']) > 0 && $this->data['tube_sticker_pump'] != '1') {
|
||||
$warnMsg[] = "Tube sticker pump must be 1 or empty";
|
||||
}
|
||||
if (Str::length($this->data['tube_sticker_pumpset']) > 0 && $this->data['tube_sticker_pumpset'] != '1') {
|
||||
$warnMsg[] = "Tube sticker pumpset must be 1 or empty";
|
||||
}
|
||||
if (Str::length($this->data['warranty_card']) > 0 && $this->data['warranty_card'] != '1') {
|
||||
$warnMsg[] = "Warranty card must be 1 or empty";
|
||||
}
|
||||
if (Str::length($this->data['panel_box_code']) > 0 && (Str::length($this->data['panel_box_code']) < 6 || !ctype_alnum($this->data['panel_box_code']))) {
|
||||
$warnMsg[] = "Invalid panel box code found";
|
||||
}
|
||||
if (Str::length($this->data['load_rate']) < 0 || !is_numeric($this->data['load_rate']) || $this->data['load_rate'] < 0) {
|
||||
$warnMsg[] = "Load rate must be greater than or equal to 0";
|
||||
}
|
||||
if (Str::length($this->data['bundle_quantity']) > 0 && (!is_numeric($this->data['bundle_quantity']) || $this->data['bundle_quantity'] <= 1)) {
|
||||
$warnMsg[] = "Bundle quantity must be greater than or equal to '2' or empty";
|
||||
}
|
||||
if (Str::length($this->data['material_type']) > 0 && $this->data['material_type'] != '1' && $this->data['material_type'] != '2' && $this->data['material_type'] != '3') { //($this->data['material_type'] != null) &&
|
||||
$warnMsg[] = "Material type must be 1 or 2 or 3 or empty";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($warnMsg)) {
|
||||
throw new RowImportFailedException(implode(', ', $warnMsg));
|
||||
}
|
||||
return StickerMaster::updateOrCreate([
|
||||
|
||||
StickerMaster::updateOrCreate([
|
||||
'item_id' => $item->id,
|
||||
'plant_id' => $plant->id
|
||||
],
|
||||
@@ -272,11 +256,14 @@ class StickerMasterImporter extends Importer
|
||||
'part_validation3' => $this->data['part_validation3'],
|
||||
'part_validation4' => $this->data['part_validation4'],
|
||||
'part_validation5' => $this->data['part_validation5'],
|
||||
'laser_part_validation1' => $this->data['laser_part_validation1'],
|
||||
'laser_part_validation2' => $this->data['laser_part_validation2'],
|
||||
'panel_box_code' => $this->data['panel_box_code'],
|
||||
'load_rate' => $this->data['load_rate'],
|
||||
'bundle_quantity' => $this->data['bundle_quantity'],
|
||||
'material_type' => $this->data['material_type']
|
||||
]);
|
||||
return null;
|
||||
// return StickerMaster::firstOrNew([
|
||||
// // Update existing records, matching them by `$this->data['column_name']`
|
||||
// 'email' => $this->data['email'],
|
||||
|
||||
@@ -14,14 +14,6 @@ class TestingPanelReadingImporter extends Importer
|
||||
public static function getColumns(): array
|
||||
{
|
||||
return [
|
||||
ImportColumn::make('plant')
|
||||
->requiredMapping()
|
||||
->relationship()
|
||||
->rules(['required']),
|
||||
ImportColumn::make('line')
|
||||
->requiredMapping()
|
||||
->relationship()
|
||||
->rules(['required']),
|
||||
ImportColumn::make('item')
|
||||
->requiredMapping()
|
||||
->relationship()
|
||||
@@ -83,13 +75,19 @@ class TestingPanelReadingImporter extends Importer
|
||||
ImportColumn::make('output_flag')
|
||||
->requiredMapping()
|
||||
->rules(['required']),
|
||||
ImportColumn::make('pds_status'),
|
||||
ImportColumn::make('pds_description'),
|
||||
ImportColumn::make('line')
|
||||
->requiredMapping()
|
||||
->relationship()
|
||||
->rules(['required']),
|
||||
ImportColumn::make('plant')
|
||||
->requiredMapping()
|
||||
->relationship()
|
||||
->rules(['required']),
|
||||
ImportColumn::make('tested_by'),
|
||||
ImportColumn::make('updated_by'),
|
||||
ImportColumn::make('scanned_at')
|
||||
->requiredMapping()
|
||||
->rules(['required', 'datetime']),
|
||||
->rules(['required']),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ class Dashboard extends \Filament\Pages\Dashboard
|
||||
->reactive()
|
||||
->afterStateUpdated(function ($state) {
|
||||
session(['selected_plant' => $state]); // fixed typo
|
||||
$this->dispatch('cumulativeChart'); // custom Livewire event
|
||||
//$this->dispatch('cumulativeChart'); // custom Livewire event
|
||||
}),
|
||||
]);
|
||||
|
||||
|
||||
358
app/Filament/Pages/DataSendToSap.php
Normal file
358
app/Filament/Pages/DataSendToSap.php
Normal file
@@ -0,0 +1,358 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Pages;
|
||||
|
||||
use App\Models\Item;
|
||||
use App\Models\Plant;
|
||||
use App\Models\ProductionQuantity;
|
||||
use App\Models\QualityValidation;
|
||||
use App\Models\StickerMaster;
|
||||
use Filament\Forms\Components\Actions;
|
||||
use Filament\Forms\Components\Actions\Action;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Pages\Page;
|
||||
use Filament\Forms\Concerns\InteractsWithForms;
|
||||
use Filament\Forms\Contracts\HasForms;
|
||||
use Filament\Notifications\Notification;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class DataSendToSap extends Page implements HasForms
|
||||
{
|
||||
use InteractsWithForms;
|
||||
|
||||
public $pId , $pOrder, $pUom, $pItem, $transHeadLog, $sNums = [];
|
||||
|
||||
public $scanned_quantity;
|
||||
|
||||
public array $data = []; //Required to back form state
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-document-text';
|
||||
protected static string $view = 'filament.pages.data-send-to-sap';
|
||||
|
||||
protected static ?string $navigationGroup = 'Send To SAP';
|
||||
|
||||
protected $listeners = ['updateScannedQuantity' => 'setScannedQuantity'];
|
||||
|
||||
|
||||
|
||||
public function setScannedQuantity($quantity)
|
||||
{
|
||||
// Set the scanned_quantity value in the Filament page/form
|
||||
$this->scanned_quantity = $quantity;
|
||||
$this->form->fill([
|
||||
'scanned_quantity' => $quantity,
|
||||
'production_order' => $this->pOrder,
|
||||
'plant_id' => $this->pId,
|
||||
]);
|
||||
}
|
||||
|
||||
public function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->statePath('data')
|
||||
->schema([
|
||||
Select::make('plant_id')
|
||||
->options(Plant::pluck('name', 'id'))
|
||||
->label('Plant')
|
||||
->reactive()
|
||||
->required()
|
||||
->afterStateUpdated(function ($state, $set, callable $get) {
|
||||
$plantId = $get('plant_id');
|
||||
if (!$plantId) {
|
||||
$set('pqPlantError', 'Please select a plant first.');
|
||||
$set('production_order', null);
|
||||
$set('scanned_quantity', null);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
$this->pId = $plantId;
|
||||
$set('production_order', null);
|
||||
$set('scanned_quantity', null);
|
||||
$set('validationError', null);
|
||||
$set('pqPlantError', null);
|
||||
}
|
||||
})
|
||||
->hint(fn ($get) => $get('pqPlantError') ? $get('pqPlantError') : null)
|
||||
->hintColor('danger'),
|
||||
|
||||
TextInput::make('production_order')
|
||||
->required()
|
||||
->reactive()
|
||||
->afterStateUpdated(function ($state, $set, callable $get) {
|
||||
$productionOrder = $get('production_order');
|
||||
|
||||
if (!$productionOrder) {
|
||||
$set('pqproducError', 'Please provide production order.');
|
||||
$set('production_order', null);
|
||||
$set('scanned_quantity', null);
|
||||
$this->dispatch('refreshed', $this->pId, $this->pOrder);
|
||||
|
||||
return;
|
||||
}
|
||||
else {
|
||||
$this->pOrder = null;
|
||||
$this->dispatch('refreshed', $this->pId, $this->pOrder);
|
||||
$set('scanned_quantity', null);
|
||||
$set('validationError', null);
|
||||
$set('pqproducError', null);
|
||||
}
|
||||
})
|
||||
->hint(fn ($get) => $get('pqproducError') ? $get('pqproducError') : null)
|
||||
->hintColor('danger')
|
||||
->extraAttributes([
|
||||
'wire:keydown.enter' => 'processValues($event.target.value)',
|
||||
]),
|
||||
|
||||
TextInput::make('scanned_quantity')
|
||||
->reactive() // Make it reactive to update when changed
|
||||
->afterStateUpdated(function ($state, $set, $get) {
|
||||
$this->scanned_quantity = $state;
|
||||
})
|
||||
->readOnly(),
|
||||
|
||||
// Add your custom action button here
|
||||
Actions::make([
|
||||
Action::make('send_to_sap')
|
||||
->label('Send Data to SAP')
|
||||
->action(function ($set, $get) {
|
||||
$year = date('y'); // '25' for 2025
|
||||
$month = date('m'); // '05' for May
|
||||
$plantId = $get('plant_id');
|
||||
$code = Plant::where('id', $plantId)->value('code');
|
||||
$finalBatch = $year . $month . $code;
|
||||
$transHeadLogId = $this->transHeadLog; //'3256';
|
||||
$lineItemCnt = '1'; //1 hard code
|
||||
$sapOrder = $get('production_order');
|
||||
$itemCode = $this->pItem;
|
||||
$quantity = (string)$get('scanned_quantity');
|
||||
$UOM = $this->pUom;
|
||||
$batchNumber = $finalBatch;
|
||||
$locationName = '';
|
||||
$lamiCdate = $get('lami_cdate');
|
||||
$serialNumbers = $this->sNums;
|
||||
|
||||
// dd($batchNumber);
|
||||
|
||||
$currentDateTime = date('j/n/Y h:i:s A');
|
||||
|
||||
$header = [
|
||||
'Trans_Head_Log_Id' => $transHeadLogId, //'3256',
|
||||
'Line_Item_Count' => $lineItemCnt, //'1',
|
||||
'SAP_Order_Number' => $sapOrder, //'12345678'
|
||||
'Item_Code' => $itemCode, //'6458795'
|
||||
];
|
||||
// $serialNumbers = ['12024090000142', '12024090000142', '12024090000142'];
|
||||
$Receipt = [
|
||||
// 'Receipt' => [
|
||||
[
|
||||
'Quantity' => $quantity, //'1',
|
||||
'UOM' => $UOM,
|
||||
'Batch_Number' => $batchNumber,
|
||||
'Location_Name' => $locationName,
|
||||
'LAMI_Cdate' => $currentDateTime, //'9/9/2024 10:48:37 AM',
|
||||
'Serial_Number' => array_map(function ($serial) {
|
||||
return ['Serial_Number' => $serial];
|
||||
}, $serialNumbers)
|
||||
]
|
||||
// ]
|
||||
];
|
||||
|
||||
|
||||
$payload = [
|
||||
// ...$header,
|
||||
'Receipt' => $Receipt
|
||||
];
|
||||
// dd($payload);
|
||||
|
||||
// $header = [
|
||||
// 'Trans_Head_Log_Id' => '3256',
|
||||
// 'Line_Item_Count' => '1',
|
||||
// 'SAP_Order_Number' => '12345678',
|
||||
// 'Item_Code' => '6458795'
|
||||
// ];
|
||||
// $serialNumbers = ['12024090000142'];
|
||||
// $Receipt = [
|
||||
// // 'Receipt' => [
|
||||
// [
|
||||
// 'Quantity' => '1',
|
||||
// 'UOM' => 'EA',
|
||||
// 'Batch_Number' => '',
|
||||
// 'Location_Name' => '',
|
||||
// 'LAMI_Cdate' => '9/9/2024 10:48:37 AM',
|
||||
// 'Serial_Number' => array_map(function ($serial) {
|
||||
// return ['Serial_Number' => $serial];
|
||||
// }, $serialNumbers)
|
||||
// ]
|
||||
// // ]
|
||||
// ];
|
||||
|
||||
|
||||
// $payload = [
|
||||
// // ...$header,
|
||||
// 'Receipt' => $Receipt
|
||||
// ];
|
||||
// dd($payload);
|
||||
try {
|
||||
// $response = Http::withHeaders([
|
||||
// 'Content-Type' => 'application/json',
|
||||
// 'Trans_Head_Log_Id' => '3256',//$transHeadLogId,
|
||||
// 'Line_Item_Count' => '1', // $lineItemCnt,
|
||||
// 'SAP_Order_Number' => '12345678', //$sapOrder,
|
||||
// 'Item_Code' => '6458795', //$itemCode,
|
||||
// ])
|
||||
$response = Http::withHeaders([
|
||||
'Content-Type' => 'application/json',
|
||||
'Trans_Head_Log_Id' => $transHeadLogId,
|
||||
'Line_Item_Count' => $lineItemCnt,
|
||||
'SAP_Order_Number' => $sapOrder,
|
||||
'Item_Code' => $itemCode,
|
||||
])
|
||||
|
||||
->withBasicAuth(
|
||||
env('SAP_API_USERNAME'),
|
||||
env('SAP_API_PASSWORD')
|
||||
)
|
||||
->withBody(json_encode($payload), 'application/json')
|
||||
->post(env('SAP_API_URL'), $payload);
|
||||
|
||||
$messageCode = $response->headers()['messagecode'][0] ?? null;
|
||||
|
||||
if ($messageCode && str_starts_with($messageCode, 'ERROR')) {
|
||||
|
||||
$cleanError = str_replace('ERROR:|', '', $messageCode);
|
||||
|
||||
// Update rows where plant_id and production_order match
|
||||
QualityValidation::where('plant_id', $get('plant_id'))
|
||||
->where('production_order', $get('production_order'))
|
||||
->update([
|
||||
'sap_msg_status' => 'ERROR',
|
||||
'sap_msg_description' => $cleanError,
|
||||
]);
|
||||
|
||||
Notification::make()
|
||||
->title('SAP Error')
|
||||
->body($cleanError)
|
||||
->danger()
|
||||
->send();
|
||||
$this->dispatch('loadItems', $this->pId, $this->pOrder);
|
||||
}
|
||||
else
|
||||
{
|
||||
$messageCode = $response->headers()['messagecode'][0] ?? null;
|
||||
$sapSuccessMsg = str_replace('SUCCESS:|', '', $messageCode);
|
||||
|
||||
QualityValidation::where('plant_id', $get('plant_id'))
|
||||
->where('production_order', $get('production_order'))
|
||||
->update([
|
||||
'sap_msg_status' => 'SUCCESS',
|
||||
'sap_msg_description' => $sapSuccessMsg,
|
||||
]);
|
||||
|
||||
Notification::make()
|
||||
->title('SAP Success')
|
||||
->body($sapSuccessMsg)
|
||||
->success()
|
||||
->send();
|
||||
$this->dispatch('loadItems', $this->pId, $this->pOrder);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
Notification::make()
|
||||
->title('Exception')
|
||||
->body('Error sending data to SAP: ' . $e->getMessage())
|
||||
->danger()
|
||||
->send();
|
||||
}
|
||||
})
|
||||
->color('success')
|
||||
->outlined()
|
||||
->hidden(fn (callable $get) => (!$get('scanned_quantity'))) //!$get('plant_id') && !$get('production_order') &&
|
||||
->extraAttributes(['class' => 'align-to-input']),
|
||||
]),
|
||||
])
|
||||
->columns(4);
|
||||
}
|
||||
|
||||
public function processValues($value)
|
||||
{
|
||||
|
||||
$this->pOrder = $value;
|
||||
|
||||
$plantId = trim($this->form->getState()['plant_id']) ?? null;
|
||||
//$this->plantId = $plantId;
|
||||
|
||||
|
||||
// $this->pUom = QualityValidation::where('plant_id',$this->pId)
|
||||
// ->where('production_order',$this->pOrder)
|
||||
// ->latest()
|
||||
// ->first()
|
||||
// ->value('uom');
|
||||
|
||||
// $this->transHeadLog = QualityValidation::where('plant_id',$this->pId)
|
||||
// ->where('production_order',$this->pOrder)
|
||||
// ->latest()
|
||||
// ->value('id');
|
||||
|
||||
$latestValidation = QualityValidation::where('plant_id', $this->pId)
|
||||
->where('production_order', $this->pOrder)
|
||||
->latest()
|
||||
->first();
|
||||
|
||||
if (!$latestValidation) {
|
||||
Notification::make()
|
||||
->title('Invalid Production Order')
|
||||
->body('No data found for the selected plant and production order.')
|
||||
->danger()
|
||||
->send();
|
||||
|
||||
$this->dispatch('refreshed', $this->pId, $this->pOrder);
|
||||
$this->pOrder = null;
|
||||
$this->form->fill([
|
||||
'plant_id' => $this->pId,
|
||||
'production_order' => null,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
$this->pUom = $latestValidation->uom;
|
||||
$this->transHeadLog = $latestValidation->id;
|
||||
|
||||
$this->sNums = [];
|
||||
|
||||
if(!$this->pUom)
|
||||
{
|
||||
Notification::make()
|
||||
->title('UOM Not Found')
|
||||
->body('UOM not found for the production order')
|
||||
->icon('heroicon-o-x-circle') // optional, to force red/error-style icon
|
||||
->danger()
|
||||
->send();
|
||||
$this->dispatch('refreshed', $this->pId, $this->pOrder);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->pItem = Item::where('id', StickerMaster::where('id', QualityValidation::where('plant_id',$this->pId)->where('production_order',$this->pOrder)->latest()->first()->sticker_master_id)->value('item_id'))->value('code');
|
||||
|
||||
$this->sNums = QualityValidation::where('plant_id', $this->pId)
|
||||
->where('production_order', $this->pOrder)
|
||||
->pluck('serial_number')
|
||||
->toArray();
|
||||
|
||||
//dd($this-> pItem);
|
||||
|
||||
$this->dispatch('loadItems', $this->pId, $this->pOrder);
|
||||
}
|
||||
}
|
||||
public static function canAccess(): bool
|
||||
{
|
||||
return Auth::check() && Auth::user()->can('view quality data send to sap');
|
||||
}
|
||||
|
||||
public static function getNavigationLabel(): string
|
||||
{
|
||||
return 'Quality Data';
|
||||
}
|
||||
}
|
||||
@@ -46,18 +46,18 @@ class InvoiceDashboard extends Page
|
||||
$this->dispatch('invoiceChart');
|
||||
}),
|
||||
Select::make('invoice')
|
||||
->options([
|
||||
'serial_invoice' => 'Serial Invoice',
|
||||
'individual_material' => 'Individual Material Invoice',
|
||||
'bundle_material' => 'Bundle Material Invoice',
|
||||
])
|
||||
->label('Select Invoice')
|
||||
->reactive()
|
||||
->default(0)
|
||||
->afterStateUpdated(function ($state) {
|
||||
session(['select_invoice' => $state]);
|
||||
$this->dispatch('invoiceChart');
|
||||
})
|
||||
->options([
|
||||
'serial_invoice' => 'Serial Invoice',
|
||||
'individual_material' => 'Individual Material Invoice',
|
||||
'bundle_material' => 'Bundle Material Invoice',
|
||||
])
|
||||
->label('Select Invoice')
|
||||
->reactive()
|
||||
->default(0)
|
||||
->afterStateUpdated(function ($state) {
|
||||
session(['select_invoice' => $state]);
|
||||
$this->dispatch('invoiceChart');
|
||||
})
|
||||
])
|
||||
->columns(2);
|
||||
}
|
||||
|
||||
@@ -23,6 +23,8 @@ class InvoiceFinder extends Page implements HasForms
|
||||
|
||||
protected static ?string $navigationGroup = 'Export Dispatch';
|
||||
|
||||
protected static ?int $navigationSort = 6;
|
||||
|
||||
//use InteractsWithForms;
|
||||
|
||||
public $pId, $invoiceNumber;
|
||||
@@ -59,7 +61,7 @@ class InvoiceFinder extends Page implements HasForms
|
||||
->readOnly()
|
||||
->reactive(),
|
||||
TextInput::make('total_sno_quantity')
|
||||
->label('Total SNo. Quantity')
|
||||
->label('Invoice Quantity')
|
||||
->readOnly()
|
||||
->reactive(),
|
||||
|
||||
@@ -75,9 +77,10 @@ class InvoiceFinder extends Page implements HasForms
|
||||
if(!$invoiceNo)
|
||||
{
|
||||
Notification::make()
|
||||
->title("Invoice number '$invoiceNo' can't be empty!")
|
||||
->danger()
|
||||
->send();
|
||||
->title("Invoice number '$invoiceNo' can't be empty!")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
$this->dispatch('loadData', '', [], [], [], [], $plantId);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
@@ -96,13 +99,14 @@ class InvoiceFinder extends Page implements HasForms
|
||||
if(!$invoiceExists)
|
||||
{
|
||||
Notification::make()
|
||||
->title("Invoice number '$invoiceNo' does not exist in locator invoice table!")
|
||||
->danger()
|
||||
->send();
|
||||
->title("Invoice number '$invoiceNo' does not exist in locator invoice table!")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
$this->dispatch('loadData', '', [], [], [], [], $plantId);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
'scan_invoice' => $invoiceNo,
|
||||
'scan_invoice' => null,//$invoiceNo,
|
||||
'total_sno_quantity' => 0,
|
||||
'pending_quantity' => 0,
|
||||
'scan_quantity' => 0
|
||||
@@ -118,21 +122,22 @@ class InvoiceFinder extends Page implements HasForms
|
||||
|
||||
if(!$invoiceCompleted)
|
||||
{
|
||||
$count = LocatorInvoiceValidation::where('invoice_number', $invoiceNo)
|
||||
->where('plant_id', $plantId)
|
||||
->count();
|
||||
// $count = LocatorInvoiceValidation::where('invoice_number', $invoiceNo)
|
||||
// ->where('plant_id', $plantId)
|
||||
// ->count();
|
||||
Notification::make()
|
||||
->title("Invoice number '$invoiceNo' already completed the scanning process...")
|
||||
->success()
|
||||
->send();
|
||||
->title("Invoice number '$invoiceNo' already completed the scanning process..!")
|
||||
->success()
|
||||
->duration(5000)
|
||||
->send();
|
||||
$this->dispatch('loadData', '', [], [], [], [], $plantId);
|
||||
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
'scan_invoice' => $invoiceNo,
|
||||
'total_sno_quantity' => $count,
|
||||
'pending_quantity' => 0,
|
||||
'scan_quantity' => $count
|
||||
'scan_invoice' => null,//$invoiceNo,
|
||||
'total_sno_quantity' => 0,//$count,
|
||||
'pending_quantity' => 0,//0,
|
||||
'scan_quantity' => 0//$count
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -3,6 +3,7 @@
|
||||
namespace App\Filament\Pages;
|
||||
|
||||
use App\Models\Locator;
|
||||
use App\Models\LocatorInvoiceValidation;
|
||||
use App\Models\PalletValidation;
|
||||
use App\Models\Plant;
|
||||
use Filament\Facades\Filament;
|
||||
@@ -26,6 +27,8 @@ class PalletFromLocator extends Page implements HasForms
|
||||
|
||||
protected static ?string $navigationGroup = 'Export Dispatch';
|
||||
|
||||
protected static ?int $navigationSort = 4;
|
||||
|
||||
public $plantId;
|
||||
|
||||
public $locatorNo;
|
||||
@@ -91,6 +94,7 @@ class PalletFromLocator extends Page implements HasForms
|
||||
TextInput::make('scan_locator_number')
|
||||
->label('Scan Locator Number')
|
||||
->reactive()
|
||||
->minLength(7)
|
||||
->columnSpan(1)
|
||||
->readOnly(fn (callable $get) => !$get('plant') || $get('scan_serial_number') || $get('scan_remove_sno'))
|
||||
->extraAttributes([
|
||||
@@ -99,6 +103,7 @@ class PalletFromLocator extends Page implements HasForms
|
||||
TextInput::make('scan_serial_number')
|
||||
->label('Scan Serial Number')
|
||||
->reactive()
|
||||
->minLength(9)
|
||||
->columnSpan(1)
|
||||
->readOnly(fn (callable $get) => !$get('plant') || $get('scan_locator_number') || $get('scan_remove_sno'))
|
||||
->extraAttributes([
|
||||
@@ -107,6 +112,7 @@ class PalletFromLocator extends Page implements HasForms
|
||||
TextInput::make('scan_remove_sno')
|
||||
->label('Remove Serial Number')
|
||||
->reactive()
|
||||
->minLength(9)
|
||||
->columnSpan(1)
|
||||
->readOnly(fn (callable $get) => !$get('plant') || $get('scan_locator_number') || $get('scan_serial_number') || count($this->records) <= 0)
|
||||
->extraAttributes([
|
||||
@@ -139,8 +145,9 @@ class PalletFromLocator extends Page implements HasForms
|
||||
Notification::make()
|
||||
->title('Press enter on "Scan Serial Number" field to proceed..!')
|
||||
->danger()
|
||||
->seconds(2)
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $this->records, $plantId);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
@@ -157,8 +164,9 @@ class PalletFromLocator extends Page implements HasForms
|
||||
Notification::make()
|
||||
->title('Press enter on "Remove Serial Number" field to proceed..!')
|
||||
->danger()
|
||||
->seconds(2)
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $this->records, $plantId);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
@@ -177,8 +185,9 @@ class PalletFromLocator extends Page implements HasForms
|
||||
->title('Invalid: Locator Number')
|
||||
->body("Locator number can't be empty!")
|
||||
->danger()
|
||||
->seconds(3)
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $this->records, $plantId);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
@@ -196,8 +205,9 @@ class PalletFromLocator extends Page implements HasForms
|
||||
->title('Invalid: Locator Number')
|
||||
->body("Locator number '$locatorNo' must be at least 7 digits.")
|
||||
->danger()
|
||||
->seconds(3)
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $this->records, $plantId);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
@@ -220,8 +230,9 @@ class PalletFromLocator extends Page implements HasForms
|
||||
->title('Unknown: Locator Number')
|
||||
->body("Locator number '$locatorNo' does not exist in the master.")
|
||||
->danger()
|
||||
->seconds(3)
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $this->records, $plantId);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
@@ -252,8 +263,9 @@ class PalletFromLocator extends Page implements HasForms
|
||||
->body("Scanned locator number '$locatorNo' does not have any locator serial numbers to store into the pallet.<br>
|
||||
Please scan a valid stored locator number to proceed.")
|
||||
->danger()
|
||||
->seconds(3)
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $this->records, $plantId);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
@@ -271,8 +283,9 @@ class PalletFromLocator extends Page implements HasForms
|
||||
->title('Add: Locator Serial Numbers')
|
||||
->body("Scanned locator number '$locatorNo' has '".$serialLocator->count()."' locator serial numbers!<br>Do you want to store it into 'PALLET DATA' table?")
|
||||
->info()
|
||||
->seconds(2)
|
||||
->duration(2000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('open-confirm-modal', locatorNo: $locatorNo, plantId: $plantId);
|
||||
}
|
||||
}
|
||||
@@ -330,7 +343,7 @@ class PalletFromLocator extends Page implements HasForms
|
||||
->orWhere('pallet_number', '');
|
||||
})
|
||||
->where('locator_number', $locatorNo)
|
||||
->orderByDesc('created_at')
|
||||
->orderBy('created_at', 'asc') //orderByDesc('created_at')
|
||||
->get()
|
||||
->map(function ($record) use($operatorName) {
|
||||
return [
|
||||
@@ -387,7 +400,7 @@ class PalletFromLocator extends Page implements HasForms
|
||||
->title('Add: Locator Serial Number')
|
||||
->body("Scanned locator serial number '$serialNo' successfully added into 'PALLET DATA' table.")
|
||||
->success()
|
||||
->seconds(3)
|
||||
->duration(500)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $this->records, $plantId);
|
||||
@@ -410,7 +423,7 @@ class PalletFromLocator extends Page implements HasForms
|
||||
->title('Remove: Locator Serial Number')
|
||||
->body("Scanned locator serial number '$removeserial' removed successfully from 'PALLET DATA' table.")
|
||||
->success()
|
||||
->seconds(3)
|
||||
->duration(500)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $this->records, $plantId);
|
||||
@@ -449,8 +462,9 @@ class PalletFromLocator extends Page implements HasForms
|
||||
->title('Add: Locator Serial Numbers')
|
||||
->body("Scanned locator number '$locatorNo' has '$serialLocator' locator serial numbers!<br>Successfully added into 'PALLET DATA' table.")
|
||||
->success()
|
||||
->seconds(3)
|
||||
->duration(500)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $this->records, $plantId);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
@@ -469,8 +483,9 @@ class PalletFromLocator extends Page implements HasForms
|
||||
->title('Skipped: Locator Number')
|
||||
->body('Scan the new locator number to proceed..!')
|
||||
->info()
|
||||
->seconds(3)
|
||||
->duration(2000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $this->records, $plantId);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
@@ -499,8 +514,9 @@ class PalletFromLocator extends Page implements HasForms
|
||||
Notification::make()
|
||||
->title('Press enter on "Scan Locator Number" field to proceed..!')
|
||||
->danger()
|
||||
->seconds(2)
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $this->records, $plantId);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
@@ -517,8 +533,9 @@ class PalletFromLocator extends Page implements HasForms
|
||||
Notification::make()
|
||||
->title('Press enter on "Remove Serial Number" field to proceed..!')
|
||||
->danger()
|
||||
->seconds(2)
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $this->records, $plantId);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
@@ -537,8 +554,9 @@ class PalletFromLocator extends Page implements HasForms
|
||||
->title('Invalid: Serial Number')
|
||||
->body("Serial number can't be empty!")
|
||||
->danger()
|
||||
->seconds(3)
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $this->records, $plantId);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
@@ -550,14 +568,15 @@ class PalletFromLocator extends Page implements HasForms
|
||||
]);
|
||||
return;
|
||||
}
|
||||
else if (strlen($serialNo) < 13)
|
||||
else if (strlen($serialNo) < 9 || strlen($serialNo) > 20)
|
||||
{
|
||||
Notification::make()
|
||||
->title('Invalid: Serial Number')
|
||||
->body("Serial number '$serialNo' must be at least 13 digits.")
|
||||
->body("Serial number should contain minimum 9 digits and maximum 20 digits.")
|
||||
->danger()
|
||||
->seconds(3)
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $this->records, $plantId);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
@@ -575,8 +594,9 @@ class PalletFromLocator extends Page implements HasForms
|
||||
->title('Invalid: Serial Number')
|
||||
->body("Serial number '$serialNo' must contain alpha-numeric values only.")
|
||||
->danger()
|
||||
->seconds(3)
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $this->records, $plantId);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
@@ -600,22 +620,53 @@ class PalletFromLocator extends Page implements HasForms
|
||||
|
||||
if ($serialLocator == '' || $serialLocator == null)
|
||||
{
|
||||
Notification::make()
|
||||
->title('Unknown: Serial Number')
|
||||
->body("Scanned serial number: '$serialNo' doesn't exist in pallet table.<br>Scan the valid exist locator-serial number to proceed..!")
|
||||
->danger()
|
||||
->seconds(3)
|
||||
->send();
|
||||
$this->dispatch('loadData', $this->records, $plantId);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
'plant' => $plantId,
|
||||
'scan_locator_number' => null,
|
||||
'scan_serial_number' => null,
|
||||
'scan_remove_sno' => null,
|
||||
'sno_quantity' => null,
|
||||
]);
|
||||
return;
|
||||
$invoicesnoexists = LocatorInvoiceValidation::where('plant_id', $plantId)
|
||||
->where('serial_number', $serialNo)
|
||||
->where('scanned_status', '=','Scanned')
|
||||
->first();
|
||||
|
||||
$invoiceNo = $invoicesnoexists?->invoice_number;
|
||||
|
||||
if ($invoicesnoexists)
|
||||
{
|
||||
Notification::make()
|
||||
->title('Invalid: Serial Number')
|
||||
->body("Serial number '$serialNo' already exists in invoice number '$invoiceNo' and completed the scanning process..!")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $this->records, $plantId);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
'plant' => $plantId,
|
||||
'scan_locator_number' => null,
|
||||
'scan_serial_number' => null,
|
||||
'scan_remove_sno' => null,
|
||||
'sno_quantity' => $count,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
Notification::make()
|
||||
->title('Unknown: Serial Number')
|
||||
->body("Scanned serial number: '$serialNo' doesn't exist in pallet table.<br>Scan the valid exist locator-serial number to proceed..!")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $this->records, $plantId);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
'plant' => $plantId,
|
||||
'scan_locator_number' => null,
|
||||
'scan_serial_number' => null,
|
||||
'scan_remove_sno' => null,
|
||||
'sno_quantity' => $count,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
elseif ($serialLocator->pallet_number != '' && $serialLocator->pallet_number != null)
|
||||
{
|
||||
@@ -623,8 +674,9 @@ class PalletFromLocator extends Page implements HasForms
|
||||
->title('Invalid: Serial Number')
|
||||
->body("Scanned serial number: '$serialNo' already exist in pallet number '".$serialLocator->pallet_number."'.<br>Scan the valid locator-serial number to proceed..!")
|
||||
->danger()
|
||||
->seconds(3)
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $this->records, $plantId);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
@@ -632,7 +684,7 @@ class PalletFromLocator extends Page implements HasForms
|
||||
'scan_locator_number' => null,
|
||||
'scan_serial_number' => null,
|
||||
'scan_remove_sno' => null,
|
||||
'sno_quantity' => null,
|
||||
'sno_quantity' => $count,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
@@ -655,8 +707,9 @@ class PalletFromLocator extends Page implements HasForms
|
||||
->title('Locator Serials Not Found')
|
||||
->body("Add some locator serial numbers to proceed generate pallet..!")
|
||||
->danger()
|
||||
->seconds(3)
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $this->records, $plantId);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
@@ -673,14 +726,14 @@ class PalletFromLocator extends Page implements HasForms
|
||||
$month = now()->format('m');
|
||||
$prefix = "EP-{$year}{$month}";
|
||||
|
||||
$lastPallet = PalletValidation::where('pallet_number', 'like', "{$prefix}%")
|
||||
->where('plant_id', $plantId)
|
||||
->orderByDesc('pallet_number')
|
||||
->first();
|
||||
|
||||
$newNumber = $lastPallet
|
||||
? str_pad(intval(substr($lastPallet->pallet_number, -3)) + 1, 3, '0', STR_PAD_LEFT)
|
||||
: '001';
|
||||
$lastPallet = PalletValidation::where('pallet_number', 'like', "{$prefix}%")->orderByDesc('pallet_number')->first(); //->where('plant_id', $plantId)
|
||||
$newNumber = '001'; // $lastPallet ? str_pad(intval(substr($lastPallet->pallet_number, -3)) + 1, 3, '0', STR_PAD_LEFT) : '001';
|
||||
if ($lastPallet) {
|
||||
$serialPart = substr($lastPallet->pallet_number, strlen($prefix));
|
||||
// OR
|
||||
// $serialPart = str_replace($prefix, '', $lastPallet->pallet_number);
|
||||
$newNumber = str_pad(intval($serialPart) + 1, strlen($serialPart), '0', STR_PAD_LEFT);
|
||||
}
|
||||
|
||||
$newPalletNumber = "{$prefix}{$newNumber}";
|
||||
|
||||
@@ -748,15 +801,16 @@ class PalletFromLocator extends Page implements HasForms
|
||||
->title('Success: Pallet Generated')
|
||||
->body("Pallet number '$newPalletNumber' completed the master packing successfully!")
|
||||
->success()
|
||||
->seconds(3)
|
||||
->duration(600)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $this->records, $plantId);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
'plant' => $plantId,
|
||||
'scan_locator_number' => $locatorNo,
|
||||
'scan_serial_number' => $serialNo,
|
||||
'scan_remove_sno' => $removeSerial,
|
||||
'scan_locator_number' => null,
|
||||
'scan_serial_number' => null,
|
||||
'scan_remove_sno' => null,
|
||||
'sno_quantity' => 0,
|
||||
]);
|
||||
return;
|
||||
@@ -768,15 +822,16 @@ class PalletFromLocator extends Page implements HasForms
|
||||
->title('Failed: Pallet Generated')
|
||||
->body("No locator serial number records found to generate pallet..!")
|
||||
->danger()
|
||||
->seconds(3)
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $this->records, $plantId);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
'plant' => $plantId,
|
||||
'scan_locator_number' => $locatorNo,
|
||||
'scan_serial_number' => $serialNo,
|
||||
'scan_remove_sno' => $removeSerial,
|
||||
'scan_locator_number' => null,
|
||||
'scan_serial_number' => null,
|
||||
'scan_remove_sno' => null,
|
||||
'sno_quantity' => 0,
|
||||
]);
|
||||
return;
|
||||
@@ -798,6 +853,7 @@ class PalletFromLocator extends Page implements HasForms
|
||||
// ->title('Pallet Generated')
|
||||
// ->body("Pallet number {$this->latestPalletNumber} assigned to all serials for locator {$locatorNo}")
|
||||
// ->success()
|
||||
// ->duration(1000)
|
||||
// ->send();
|
||||
// $this->dispatch('loadData', $this->records, $plantId);
|
||||
// $this->form->fill([
|
||||
@@ -826,8 +882,9 @@ class PalletFromLocator extends Page implements HasForms
|
||||
Notification::make()
|
||||
->title('Press enter on "Scan Locator Number" field to proceed..!')
|
||||
->danger()
|
||||
->seconds(2)
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $this->records, $plantId);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
@@ -844,8 +901,9 @@ class PalletFromLocator extends Page implements HasForms
|
||||
Notification::make()
|
||||
->title('Press enter on "Scan Serial Number" field to proceed..!')
|
||||
->danger()
|
||||
->seconds(2)
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $this->records, $plantId);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
@@ -864,8 +922,9 @@ class PalletFromLocator extends Page implements HasForms
|
||||
->title('Invalid: Serial Number')
|
||||
->body("Serial number can't be empty!")
|
||||
->danger()
|
||||
->seconds(3)
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $this->records, $plantId);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
@@ -877,14 +936,15 @@ class PalletFromLocator extends Page implements HasForms
|
||||
]);
|
||||
return;
|
||||
}
|
||||
else if (strlen($removeSno) < 13)
|
||||
else if (strlen($removeSno) < 9 || strlen($removeSno) > 20)
|
||||
{
|
||||
Notification::make()
|
||||
->title('Invalid: Serial Number')
|
||||
->body("Serial number '$removeSno' must be at least 13 digits.")
|
||||
->body("Serial number should contain minimum 9 digits and maximum 20 digits.")
|
||||
->danger()
|
||||
->seconds(3)
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $this->records, $plantId);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
@@ -902,8 +962,9 @@ class PalletFromLocator extends Page implements HasForms
|
||||
->title('Invalid: Serial Number')
|
||||
->body("Serial number '$removeSno' must contain alpha-numeric values only.")
|
||||
->danger()
|
||||
->seconds(3)
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $this->records, $plantId);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
@@ -934,8 +995,9 @@ class PalletFromLocator extends Page implements HasForms
|
||||
->title('Unknown: Serial Number')
|
||||
->body("Scanned serial number: '$removeSno' doesn't exist in 'PALLET DATA' table.<br>Scan the valid exist locator-serial number to proceed..!")
|
||||
->danger()
|
||||
->seconds(3)
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $this->records, $plantId);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
|
||||
370
app/Filament/Pages/ProductionDataSap.php
Normal file
370
app/Filament/Pages/ProductionDataSap.php
Normal file
@@ -0,0 +1,370 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Pages;
|
||||
|
||||
use App\Models\Item;
|
||||
use App\Models\Plant;
|
||||
use App\Models\ProductionQuantity;
|
||||
use App\Models\QualityValidation;
|
||||
use App\Models\StickerMaster;
|
||||
use Filament\Forms\Components\Actions;
|
||||
use Filament\Forms\Components\Actions\Action;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Pages\Page;
|
||||
use Filament\Forms\Concerns\InteractsWithForms;
|
||||
use Filament\Forms\Contracts\HasForms;
|
||||
use Filament\Notifications\Notification;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class ProductionDataSap extends Page implements HasForms
|
||||
{
|
||||
use InteractsWithForms;
|
||||
|
||||
public $pId , $pOrder, $pUom, $pItem, $transHeadLog, $sNums = [];
|
||||
|
||||
public $scanned_quantity;
|
||||
|
||||
public array $data = []; //Required to back form state
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-document-text';
|
||||
protected static string $view = 'filament.pages.production-data-sap';
|
||||
|
||||
protected static ?string $navigationGroup = 'Send To SAP';
|
||||
|
||||
protected $listeners = ['updateScannedQuantity' => 'setScannedQuantity'];
|
||||
|
||||
|
||||
|
||||
public function setScannedQuantity($quantity)
|
||||
{
|
||||
// Set the scanned_quantity value in the Filament page/form
|
||||
$this->scanned_quantity = $quantity;
|
||||
$this->form->fill([
|
||||
'scanned_quantity' => $quantity,
|
||||
'production_order' => $this->pOrder,
|
||||
'plant_id' => $this->pId,
|
||||
]);
|
||||
}
|
||||
|
||||
public function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->statePath('data')
|
||||
->schema([
|
||||
Select::make('plant_id')
|
||||
->options(Plant::pluck('name', 'id'))
|
||||
->label('Plant')
|
||||
->reactive()
|
||||
->required()
|
||||
->afterStateUpdated(function ($state, $set, callable $get) {
|
||||
$plantId = $get('plant_id');
|
||||
if (!$plantId) {
|
||||
$set('pqPlantError', 'Please select a plant first.');
|
||||
$set('production_order', null);
|
||||
$set('scanned_quantity', null);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
$this->pId = $plantId;
|
||||
$set('production_order', null);
|
||||
$set('scanned_quantity', null);
|
||||
$set('validationError', null);
|
||||
$set('pqPlantError', null);
|
||||
}
|
||||
})
|
||||
->hint(fn ($get) => $get('pqPlantError') ? $get('pqPlantError') : null)
|
||||
->hintColor('danger'),
|
||||
|
||||
TextInput::make('production_order')
|
||||
->required()
|
||||
->reactive()
|
||||
->afterStateUpdated(function ($state, $set, callable $get) {
|
||||
$productionOrder = $get('production_order');
|
||||
|
||||
if (!$productionOrder) {
|
||||
$set('pqproducError', 'Please provide production order.');
|
||||
$set('scanned_quantity', null);
|
||||
$this->dispatch('refreshed', $this->pId, $this->pOrder);
|
||||
|
||||
return;
|
||||
}
|
||||
else {
|
||||
$this->pOrder = null;
|
||||
$this->dispatch('refreshed', $this->pId, $this->pOrder);
|
||||
$set('scanned_quantity', null);
|
||||
$set('validationError', null);
|
||||
$set('pqproducError', null);
|
||||
}
|
||||
})
|
||||
->hint(fn ($get) => $get('pqproducError') ? $get('pqproducError') : null)
|
||||
->hintColor('danger')
|
||||
->extraAttributes([
|
||||
'wire:keydown.enter' => 'processValues($event.target.value)',
|
||||
]),
|
||||
|
||||
TextInput::make('scanned_quantity')
|
||||
->reactive() // Make it reactive to update when changed
|
||||
->afterStateUpdated(function ($state, $set, $get) {
|
||||
$this->scanned_quantity = $state;
|
||||
})
|
||||
->readOnly()
|
||||
->required(),
|
||||
|
||||
// Add your custom action button here
|
||||
Actions::make([
|
||||
Action::make('send_to_sap')
|
||||
->label('Send Data to SAP')
|
||||
->action(function ($set, $get) {
|
||||
$plantId = $get('plant_id');
|
||||
$plantWarehouseCodes = [
|
||||
// plant_id => warehouse_code
|
||||
1 => '110', // Ransar I
|
||||
2 => '101', // Ransar II
|
||||
3 => '102', // Chola Pumps
|
||||
4 => '104', // Tuff Pumps
|
||||
//5 => '107', //WH-Nark
|
||||
5 => '200', // Go-flex
|
||||
//7 => '301', // Krisgo II
|
||||
];
|
||||
|
||||
$year = date('y'); // '25' for 2025
|
||||
$month = date('m'); // '05' for May
|
||||
$transHeadLogId = $this->transHeadLog; //'3256';
|
||||
$lineItemCnt = '1'; //1 hard code
|
||||
$sapOrder = $get('production_order');
|
||||
$itemCode = $this->pItem;
|
||||
$quantity = (string)$get('scanned_quantity');
|
||||
$UOM = $this->pUom;
|
||||
|
||||
$locationName = '';
|
||||
$lamiCdate = $get('lami_cdate');
|
||||
$serialNumbers = $this->sNums;
|
||||
|
||||
$warehouseCode = $plantWarehouseCodes[$plantId] ?? null;
|
||||
$finalBatch = $warehouseCode . $year . $month;
|
||||
|
||||
$batchNumber = $finalBatch;
|
||||
//dd($batchNumber);
|
||||
|
||||
$currentDateTime = date('j/n/Y h:i:s A');
|
||||
|
||||
$header = [
|
||||
'Trans_Head_Log_Id' => $transHeadLogId, //'3256',
|
||||
'Line_Item_Count' => $lineItemCnt, //'1',
|
||||
'SAP_Order_Number' => $sapOrder, //'12345678'
|
||||
'Item_Code' => $itemCode, //'6458795'
|
||||
];
|
||||
// $serialNumbers = ['12024090000142', '12024090000142', '12024090000142'];
|
||||
$Receipt = [
|
||||
// 'Receipt' => [
|
||||
[
|
||||
'Quantity' => $quantity, //'1',
|
||||
'UOM' => $UOM,
|
||||
'Batch_Number' => $batchNumber,
|
||||
'Location_Name' => $locationName,
|
||||
'LAMI_Cdate' => $currentDateTime, //'9/9/2024 10:48:37 AM',
|
||||
'Serial_Number' => array_map(function ($serial) {
|
||||
return ['Serial_Number' => $serial];
|
||||
}, $serialNumbers)
|
||||
]
|
||||
// ]
|
||||
];
|
||||
|
||||
|
||||
$payload = [
|
||||
// ...$header,
|
||||
'Receipt' => $Receipt
|
||||
];
|
||||
// dd($payload);
|
||||
|
||||
// $header = [
|
||||
// 'Trans_Head_Log_Id' => '3256',
|
||||
// 'Line_Item_Count' => '1',
|
||||
// 'SAP_Order_Number' => '12345678',
|
||||
// 'Item_Code' => '6458795'
|
||||
// ];
|
||||
// $serialNumbers = ['12024090000142'];
|
||||
// $Receipt = [
|
||||
// // 'Receipt' => [
|
||||
// [
|
||||
// 'Quantity' => '1',
|
||||
// 'UOM' => 'EA',
|
||||
// 'Batch_Number' => '',
|
||||
// 'Location_Name' => '',
|
||||
// 'LAMI_Cdate' => '9/9/2024 10:48:37 AM',
|
||||
// 'Serial_Number' => array_map(function ($serial) {
|
||||
// return ['Serial_Number' => $serial];
|
||||
// }, $serialNumbers)
|
||||
// ]
|
||||
// // ]
|
||||
// ];
|
||||
|
||||
|
||||
// $payload = [
|
||||
// // ...$header,
|
||||
// 'Receipt' => $Receipt
|
||||
// ];
|
||||
// dd($payload);
|
||||
try {
|
||||
// $response = Http::withHeaders([
|
||||
// 'Content-Type' => 'application/json',
|
||||
// 'Trans_Head_Log_Id' => '3256',//$transHeadLogId,
|
||||
// 'Line_Item_Count' => '1', // $lineItemCnt,
|
||||
// 'SAP_Order_Number' => '12345678', //$sapOrder,
|
||||
// 'Item_Code' => '6458795', //$itemCode,
|
||||
// ])
|
||||
$response = Http::withHeaders([
|
||||
'Content-Type' => 'application/json',
|
||||
'Trans_Head_Log_Id' => $transHeadLogId,
|
||||
'Line_Item_Count' => $lineItemCnt,
|
||||
'SAP_Order_Number' => $sapOrder,
|
||||
'Item_Code' => $itemCode,
|
||||
])
|
||||
->withBasicAuth(
|
||||
'sb-eba140ab-74bb-44a4-8d92-70a636940def!b1182|it-rt-dev-cri-stjllphr!b68',
|
||||
'616d8991-307b-4ab1-be37-7894a8c6db9d$0p0fE2I7w1Ve23-lVSKQF0ka3mKrTVcKPJYELr-i4nE='
|
||||
)
|
||||
->withBody(json_encode($payload), 'application/json')
|
||||
//->dump()
|
||||
|
||||
->post('https://dev-cri-stjllphr.it-cpi004-rt.cfapps.ap11.hana.ondemand.com/http/LA2CRI/GoodsReceiptAgFG', $payload);
|
||||
|
||||
// dump($response->transferStats->getRequest());
|
||||
|
||||
// dd(json_encode($payload, JSON_PRETTY_PRINT));
|
||||
//dd($response->status(), $response->body());
|
||||
|
||||
// dump($response);
|
||||
|
||||
$messageCode = $response->headers()['messagecode'][0] ?? null;
|
||||
|
||||
if ($messageCode && str_starts_with($messageCode, 'ERROR')) {
|
||||
|
||||
$cleanError = str_replace('ERROR:|', '', $messageCode);
|
||||
|
||||
// Update rows where plant_id and production_order match
|
||||
ProductionQuantity::where('plant_id', $get('plant_id'))
|
||||
->where('production_order', $get('production_order'))
|
||||
->update([
|
||||
'sap_msg_status' => 'ERROR',
|
||||
'sap_msg_description' => $cleanError,
|
||||
]);
|
||||
|
||||
Notification::make()
|
||||
->title('SAP Error')
|
||||
->body($cleanError)
|
||||
->danger()
|
||||
->send();
|
||||
$this->dispatch('loadItems', $this->pId, $this->pOrder);
|
||||
}
|
||||
else
|
||||
{
|
||||
$messageCode = $response->headers()['messagecode'][0] ?? null;
|
||||
$sapSuccessMsg = str_replace('SUCCESS:|', '', $messageCode);
|
||||
|
||||
ProductionQuantity::where('plant_id', $get('plant_id'))
|
||||
->where('production_order', $get('production_order'))
|
||||
->update([
|
||||
'sap_msg_status' => 'SUCCESS',
|
||||
'sap_msg_description' => $sapSuccessMsg,
|
||||
]);
|
||||
|
||||
Notification::make()
|
||||
->title('SAP Success')
|
||||
->body($sapSuccessMsg)
|
||||
->success()
|
||||
->send();
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
Notification::make()
|
||||
->title('Exception')
|
||||
->body('Error sending data to SAP: ' . $e->getMessage())
|
||||
->danger()
|
||||
->send();
|
||||
}
|
||||
})
|
||||
->color('success')
|
||||
->outlined()
|
||||
->hidden(fn (callable $get) => (!$get('scanned_quantity'))) //!$get('plant_id') && !$get('production_order') &&
|
||||
->extraAttributes(['class' => 'align-to-input']),
|
||||
]),
|
||||
])
|
||||
->columns(4);
|
||||
}
|
||||
|
||||
public function processValues($value)
|
||||
{
|
||||
|
||||
$this->pOrder = $value;
|
||||
|
||||
$latestValidation = ProductionQuantity::where('plant_id', $this->pId)
|
||||
->where('production_order', $this->pOrder)
|
||||
->latest()
|
||||
->first();
|
||||
|
||||
if (!$latestValidation) {
|
||||
Notification::make()
|
||||
->title('Invalid Production Order')
|
||||
->body('No data found for the selected plant and production order.')
|
||||
->danger()
|
||||
->send();
|
||||
|
||||
$this->dispatch('refreshed', $this->pId, $this->pOrder);
|
||||
return;
|
||||
}
|
||||
|
||||
// $this->pUom = $latestValidation->uom;
|
||||
$this->transHeadLog = $latestValidation->id;
|
||||
|
||||
$itemId = $latestValidation->item_id;
|
||||
|
||||
$this->pUom = Item::where('id', $itemId)->value('uom');
|
||||
|
||||
$this->sNums = [];
|
||||
|
||||
if(!$this->pUom)
|
||||
{
|
||||
Notification::make()
|
||||
->title('UOM Not Found')
|
||||
->body('UOM not found for the production order')
|
||||
->icon('heroicon-o-x-circle')
|
||||
->danger()
|
||||
->send();
|
||||
$this->dispatch('refreshed', $this->pId, $this->pOrder);
|
||||
}
|
||||
else
|
||||
{
|
||||
$latestProduction = ProductionQuantity::where('plant_id', $this->pId)
|
||||
->where('production_order', $this->pOrder)
|
||||
->latest()
|
||||
->first();
|
||||
|
||||
$this->pItem = $latestProduction
|
||||
? Item::where('id', $latestProduction->item_id)->value('code')
|
||||
: null;
|
||||
|
||||
|
||||
$this->sNums = ProductionQuantity::where('plant_id', $this->pId)
|
||||
->where('production_order', $this->pOrder)
|
||||
->pluck('serial_number')
|
||||
->toArray();
|
||||
|
||||
$this->dispatch('loadItems', $this->pId, $this->pOrder);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static function canAccess(): bool
|
||||
{
|
||||
return Auth::check() && Auth::user()->can('view production data send to sap');
|
||||
}
|
||||
|
||||
public static function getNavigationLabel(): string
|
||||
{
|
||||
return 'Production Data';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,8 @@ use Route;
|
||||
use Illuminate\Support\Facades\Request;
|
||||
use Filament\Notifications\Notification;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Livewire\Attributes\On;
|
||||
|
||||
|
||||
class ProductionQuantityPage extends Page implements HasForms
|
||||
{
|
||||
@@ -130,7 +132,6 @@ class ProductionQuantityPage extends Page implements HasForms
|
||||
->options(Plant::pluck('name', 'id'))
|
||||
->label('Plant')
|
||||
->reactive()
|
||||
->live()
|
||||
->required()
|
||||
->columnSpan(1)
|
||||
->default(function () {
|
||||
@@ -163,7 +164,7 @@ class ProductionQuantityPage extends Page implements HasForms
|
||||
->label('Block')
|
||||
->required()
|
||||
// ->nullable()
|
||||
->live()
|
||||
->reactive()
|
||||
->columnSpan(1)
|
||||
->options(function (callable $get) {
|
||||
if (!$get('plant_id')) {
|
||||
@@ -174,7 +175,6 @@ class ProductionQuantityPage extends Page implements HasForms
|
||||
->pluck('name', 'id')
|
||||
->toArray();
|
||||
})
|
||||
->reactive()
|
||||
->default(function () {
|
||||
$latestShiftId = optional(ProductionQuantity::latest()->first())->shift_id;
|
||||
return optional(Shift::where('id', $latestShiftId)->first())->block_id;
|
||||
@@ -276,7 +276,6 @@ class ProductionQuantityPage extends Page implements HasForms
|
||||
->toArray();
|
||||
})
|
||||
->reactive()
|
||||
->live()
|
||||
->default(function () {
|
||||
return optional(ProductionQuantity::latest()->first())->line_id;
|
||||
})
|
||||
@@ -323,9 +322,9 @@ class ProductionQuantityPage extends Page implements HasForms
|
||||
TextInput::make('production_order')
|
||||
->label('Production Order')
|
||||
->reactive()
|
||||
->live()
|
||||
->required()
|
||||
->columnSpan(1)
|
||||
//->columnSpan(1)
|
||||
->columnSpan(['default' => 1, 'sm' => 1])
|
||||
->afterStateUpdated(function ($state, callable $get, callable $set): void {
|
||||
$set('item_code', null);
|
||||
$set('item_id', null);
|
||||
@@ -339,16 +338,16 @@ class ProductionQuantityPage extends Page implements HasForms
|
||||
// }
|
||||
}),
|
||||
|
||||
TextInput::make('item_code')
|
||||
->label('Item Code')
|
||||
->columnSpan(1)
|
||||
->autofocus(true)
|
||||
->reactive()
|
||||
->live()
|
||||
->default(fn () => $this->clear_qr)
|
||||
->extraAttributes([
|
||||
'wire:keydown.enter' => 'processAllValues($event.target.value)',
|
||||
]),
|
||||
// TextInput::make('item_code')
|
||||
// ->label('Item Code')
|
||||
// ->columnSpan(1)
|
||||
// ->autofocus(true)
|
||||
// //->reactive()
|
||||
// ->live(onBlur: true) // avoids per-keystroke triggering
|
||||
// ->default(fn () => $this->clear_qr)
|
||||
// ->extraAttributes([
|
||||
// 'wire:keydown.enter' => 'processAllValues($event.target.value)',
|
||||
// ]),
|
||||
|
||||
Hidden::make('serial_number')
|
||||
->required(),
|
||||
@@ -362,7 +361,8 @@ class ProductionQuantityPage extends Page implements HasForms
|
||||
TextInput::make('recent_qr')
|
||||
->label('Last scanned QR')
|
||||
->reactive()
|
||||
->columnSpan(1)
|
||||
->columnSpan(['default' => 1, 'sm' => 2])
|
||||
//->columnSpan(2)
|
||||
// ->default(function () {
|
||||
// // Get the latest 'item_id' foreign key from 'production_quantities' table
|
||||
// $latestProductionQuantity = ProductionQuantity::latest()->first();
|
||||
@@ -383,7 +383,6 @@ class ProductionQuantityPage extends Page implements HasForms
|
||||
|
||||
// })
|
||||
->default(fn () => $this->recQr)
|
||||
|
||||
->readOnly(true),
|
||||
|
||||
TextInput::make('id')
|
||||
@@ -392,11 +391,19 @@ class ProductionQuantityPage extends Page implements HasForms
|
||||
Hidden::make('operator_id')
|
||||
->default(Filament::auth()->user()->name),
|
||||
])
|
||||
->columns(7);
|
||||
// ->columns(6);
|
||||
->columns(['default' => 1, 'sm' => 7]);
|
||||
}
|
||||
|
||||
|
||||
// Method to process the value when Enter is pressed
|
||||
|
||||
#[On('handleQrScan')]
|
||||
public function handleQrScan($value)
|
||||
{
|
||||
$this->processAllValues($value);
|
||||
}
|
||||
|
||||
public function processAllValues($formQRData)
|
||||
{
|
||||
|
||||
@@ -417,36 +424,6 @@ class ProductionQuantityPage extends Page implements HasForms
|
||||
$user = Filament::auth()->user(); //->name
|
||||
$operatorName = $user->name;
|
||||
$this->qrData = $formQRData;
|
||||
// dd($formData, $formQRData);
|
||||
// dd($this->form->getState()['serial_number']);
|
||||
|
||||
// try {
|
||||
// // Access the nested form data
|
||||
// $componentData = json_decode($formValues['components'][0]['snapshot'], true);
|
||||
// $formData = $componentData['data']['data'][0]; // Access first item in data array
|
||||
|
||||
// // Extract specific values
|
||||
// $this->qrData = $formQRData ?? $formData['item_code'];
|
||||
// $this->pId = $formData['plant_id'] ?? null;
|
||||
// $this->bId = $formData['block_name'] ?? null;
|
||||
// $this->sId = $formData['shift_id'] ?? null;
|
||||
// $this->lId = $formData['line_id'] ?? null;
|
||||
// $this->iId = $formData['item_id'] ?? null;
|
||||
// $this->succId = $formData['success_msg'] ?? null;
|
||||
// // $this->sNoId = $formData['serial_number'] ?? null;
|
||||
// $this->prodOrder = $formData['production_order'] ?? null;
|
||||
// $this->recQr = $formData['recent_qr'] ?? null;
|
||||
// $this->dispatch('plant-line-updated', $this->pId,$this->lId);
|
||||
// } catch (\Exception $e) {
|
||||
// //dd('Error parsing form data:', $e->getMessage(), $formValues);
|
||||
// Notification::make()
|
||||
// ->title("Error Parsing Form Data") // {$operatorName}
|
||||
// ->body($e->getMessage())
|
||||
// ->danger()
|
||||
// // ->persistent()
|
||||
// ->send();
|
||||
// return;
|
||||
// }
|
||||
|
||||
$latestProductionQuantity = ProductionQuantity::latest()->first();
|
||||
|
||||
@@ -456,7 +433,6 @@ class ProductionQuantityPage extends Page implements HasForms
|
||||
$this->recQr = $itemCode && $serialNumber ? "{$itemCode} | {$serialNumber}" : null;
|
||||
}
|
||||
|
||||
|
||||
if (empty($formQRData)) {
|
||||
$this->form->fill([
|
||||
'plant_id'=> $this->pId,
|
||||
@@ -1303,7 +1279,7 @@ class ProductionQuantityPage extends Page implements HasForms
|
||||
'shift_id'=> $this->sId,
|
||||
'line_id'=> $this->lId,
|
||||
'item_id'=> null,
|
||||
// 'item_code'=> null,
|
||||
//'item_code'=> null,
|
||||
'serial_number'=> null,
|
||||
'success_msg'=> null,
|
||||
'production_order'=> $this->prodOrder,
|
||||
@@ -1317,6 +1293,7 @@ class ProductionQuantityPage extends Page implements HasForms
|
||||
->title("Valid QR Found") // {$operatorName}
|
||||
->body("Valid QR code scanned: {$this->qrData}.")
|
||||
->success()
|
||||
->duration(200)
|
||||
->send();
|
||||
}
|
||||
}
|
||||
@@ -1327,25 +1304,25 @@ class ProductionQuantityPage extends Page implements HasForms
|
||||
// For example:
|
||||
$model = ProductionQuantity::create($formValues);
|
||||
|
||||
// dd('Production Updated Event Dispatched');
|
||||
// dd('Production Updated Event Dispatched');
|
||||
|
||||
$this->dispatch('productionUpdated');
|
||||
|
||||
// // Optionally, you can emit an event or perform a redirect after saving
|
||||
// $this->emit('formSaved', $model->id);
|
||||
}
|
||||
public function triggerChartUpdate(): void
|
||||
{
|
||||
if (session()->has('select_plant') && session()->has('select_line')) {
|
||||
$this->dispatch('filtersUpdated');
|
||||
}
|
||||
}
|
||||
public function triggerChartUpdate(): void
|
||||
{
|
||||
if (session()->has('select_plant') && session()->has('select_line')) {
|
||||
$this->dispatch('filtersUpdated');
|
||||
}
|
||||
}
|
||||
|
||||
// Override the getTitle method
|
||||
public function getTitle(): string
|
||||
{
|
||||
return ''; // Return an empty string to remove the title
|
||||
}
|
||||
// Override the getTitle method
|
||||
public function getTitle(): string
|
||||
{
|
||||
return ''; // Return an empty string to remove the title
|
||||
}
|
||||
|
||||
public static function getNavigationLabel(): string
|
||||
{
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
182
app/Filament/Resources/AlertMailRuleResource.php
Normal file
182
app/Filament/Resources/AlertMailRuleResource.php
Normal file
@@ -0,0 +1,182 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use App\Filament\Resources\AlertMailRuleResource\Pages;
|
||||
use App\Filament\Resources\AlertMailRuleResource\RelationManagers;
|
||||
use App\Models\AlertMailRule;
|
||||
use App\Models\Plant;
|
||||
use Dotenv\Exception\ValidationException;
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Components\Checkbox;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Filament\Forms\Components\Section;
|
||||
use Illuminate\Validation\ValidationException as ValidationValidationException;
|
||||
|
||||
class AlertMailRuleResource extends Resource
|
||||
{
|
||||
protected static ?string $model = AlertMailRule::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
|
||||
|
||||
protected static ?string $navigationGroup = 'Alert Mail';
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Section::make('')
|
||||
->schema([
|
||||
Forms\Components\Select::make('plant')
|
||||
->label('Plant')
|
||||
->reactive()
|
||||
->options(fn () => Plant::pluck('name', 'id')->toArray())
|
||||
->required(fn ($get) => ! $get('is_active'))
|
||||
->afterStateUpdated(fn ($state, callable $set) => $state ? $set('is_active', false) : null),
|
||||
// ->options(fn () => Plant::pluck('id', 'name')->toArray()),
|
||||
Forms\Components\Select::make('module')
|
||||
->label('Module')
|
||||
->required()
|
||||
->options([
|
||||
'InvoiceValidation' => 'InvoiceValidation',
|
||||
'ProductionQuantities' => 'ProductionQuantities',
|
||||
]),
|
||||
Forms\Components\Select::make('rule_name')
|
||||
->label('Rule Name')
|
||||
->options([
|
||||
'InvoiceMail' => 'Invoice Mail',
|
||||
'SerialInvoiceMail' => 'Serial Invoice Mail',
|
||||
'MaterialInvoiceMail' => 'Material Invoice Mail',
|
||||
'ProductionMail' => 'Production Mail',
|
||||
])
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('email')
|
||||
->label('Email')
|
||||
->required(),
|
||||
Forms\Components\Select::make('schedule_type')
|
||||
->label('Schedule Type')
|
||||
->required()
|
||||
->options([
|
||||
'Live' => 'Live',
|
||||
'Hourly' => 'Hourly',
|
||||
'Daily' => 'Daily',
|
||||
]),
|
||||
Checkbox::make('is_active')
|
||||
->label('All Plants Reports')
|
||||
->afterStateUpdated(fn ($state, callable $set) => $state ? $set('plant', null) : null)
|
||||
->reactive(),
|
||||
Forms\Components\Hidden::make('created_by')
|
||||
->default(fn () => Filament::auth()->user()?->name),
|
||||
Forms\Components\Hidden::make('updated_by')
|
||||
->default(fn () => Filament::auth()->user()?->name),
|
||||
])
|
||||
->columns(5),
|
||||
]);
|
||||
}
|
||||
|
||||
// Optionally, also override for update/editing
|
||||
// public static function mutateFormDataBeforeSave(array $data): array
|
||||
// {
|
||||
// dd('test');
|
||||
// if ($data['is_active']) {
|
||||
// $data['plant'] = 'All Plants';
|
||||
// }
|
||||
// return $data;
|
||||
// }
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('id')
|
||||
->label('ID')
|
||||
->numeric()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('plant')
|
||||
->label('Plant')
|
||||
->sortable()
|
||||
->formatStateUsing(function ($state) {
|
||||
static $plants;
|
||||
if (! $plants) {
|
||||
$plants = Plant::pluck('name', 'id')->toArray();
|
||||
}
|
||||
return $plants[$state] ?? 'All Plants';
|
||||
}),
|
||||
Tables\Columns\TextColumn::make('module')
|
||||
->label('Module')
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('rule_name')
|
||||
->label('Rule Name')
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('email')
|
||||
->label('Email')
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('schedule_type')
|
||||
->label('Schedule Type')
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('created_at')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
Tables\Columns\TextColumn::make('created_by')
|
||||
->label('Created By')
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('updated_at')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
Tables\Columns\TextColumn::make('updated_by')
|
||||
->label('Updated By')
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('deleted_at')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
])
|
||||
->filters([
|
||||
Tables\Filters\TrashedFilter::make(),
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\ViewAction::make(),
|
||||
Tables\Actions\EditAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\BulkActionGroup::make([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
Tables\Actions\ForceDeleteBulkAction::make(),
|
||||
Tables\Actions\RestoreBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListAlertMailRules::route('/'),
|
||||
'create' => Pages\CreateAlertMailRule::route('/create'),
|
||||
'view' => Pages\ViewAlertMailRule::route('/{record}'),
|
||||
'edit' => Pages\EditAlertMailRule::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
|
||||
public static function getEloquentQuery(): Builder
|
||||
{
|
||||
return parent::getEloquentQuery()
|
||||
->withoutGlobalScopes([
|
||||
SoftDeletingScope::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\AlertMailRuleResource\Pages;
|
||||
|
||||
use App\Filament\Resources\AlertMailRuleResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateAlertMailRule extends CreateRecord
|
||||
{
|
||||
protected static string $resource = AlertMailRuleResource::class;
|
||||
|
||||
protected function mutateFormDataBeforeCreate(array $data): array
|
||||
{
|
||||
|
||||
if ($data['is_active']) {
|
||||
$data['plant'] = 0;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\AlertMailRuleResource\Pages;
|
||||
|
||||
use App\Filament\Resources\AlertMailRuleResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditAlertMailRule extends EditRecord
|
||||
{
|
||||
protected static string $resource = AlertMailRuleResource::class;
|
||||
|
||||
protected function mutateFormDataBeforeSave(array $data): array
|
||||
{
|
||||
//dd('test');
|
||||
if ($data['is_active']) {
|
||||
$data['plant'] = 0;
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\ViewAction::make(),
|
||||
Actions\DeleteAction::make(),
|
||||
Actions\ForceDeleteAction::make(),
|
||||
Actions\RestoreAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\AlertMailRuleResource\Pages;
|
||||
|
||||
use App\Filament\Resources\AlertMailRuleResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListAlertMailRules extends ListRecords
|
||||
{
|
||||
protected static string $resource = AlertMailRuleResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\AlertMailRuleResource\Pages;
|
||||
|
||||
use App\Filament\Resources\AlertMailRuleResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ViewRecord;
|
||||
|
||||
class ViewAlertMailRule extends ViewRecord
|
||||
{
|
||||
protected static string $resource = AlertMailRuleResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\EditAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -121,12 +121,14 @@ class InvoiceValidationResource extends Resource
|
||||
->readOnly(fn (callable $get) => empty($get('invoice_number')))
|
||||
//->disabled(fn (Get $get) => empty($get('invoice_number')))
|
||||
->extraAttributes([
|
||||
'id' => 'serial_number_input',
|
||||
'x-data' => '{ value: "" }',
|
||||
'x-model' => 'value',
|
||||
'wire:keydown.enter.prevent' => 'processSerialNumber(value)', // Using wire:keydown
|
||||
])
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
$set('update_invoice', 0);
|
||||
// $this->dispatch('focus-serial-number');
|
||||
// if (!$invNo) { return; } else { }
|
||||
})
|
||||
->columnSpan(1),
|
||||
@@ -376,7 +378,7 @@ class InvoiceValidationResource extends Resource
|
||||
}
|
||||
|
||||
$invalidMatCodes = [];
|
||||
$invalidSerialCodes=[];
|
||||
$invalidSerialCodes = [];
|
||||
$materialCodes = [];
|
||||
$missingSerials = [];
|
||||
$duplicateSerials = [];
|
||||
@@ -806,6 +808,7 @@ class InvoiceValidationResource extends Resource
|
||||
|
||||
if (count($invalidCodes) > 10)
|
||||
{
|
||||
$invalidCodes = array_unique($invalidCodes);
|
||||
Notification::make()
|
||||
->title('Invalid item codes found')
|
||||
->body('' . count($invalidCodes) . 'invalid item codes found have serial number.')
|
||||
@@ -819,6 +822,7 @@ class InvoiceValidationResource extends Resource
|
||||
}
|
||||
else if(count($invalidCodes) > 0)
|
||||
{
|
||||
$invalidCodes = array_unique($invalidCodes);
|
||||
Notification::make()
|
||||
->title('Invalid item codes found')
|
||||
->body('Serial invoice Item Codes found : ' . implode(', ', $invalidCodes))
|
||||
@@ -881,6 +885,10 @@ class InvoiceValidationResource extends Resource
|
||||
->send();
|
||||
};
|
||||
|
||||
$nonNumericQtyCodes = array_unique($nonNumericQtyCodes);
|
||||
$zeroQtyCodes = array_unique($zeroQtyCodes);
|
||||
$notDivisibleCodes = array_unique($notDivisibleCodes);
|
||||
|
||||
$showValidationNotification($nonNumericQtyCodes, "The following item codes contains invalid bundle quantity:");
|
||||
$showValidationNotification($zeroQtyCodes, "The following item codes quantity should be greater than '0':");
|
||||
$showValidationNotification($notDivisibleCodes, "The following item codes quantity is not divisible by bundle quantity.");
|
||||
@@ -964,74 +972,73 @@ class InvoiceValidationResource extends Resource
|
||||
->placeholder(placeholder: 'Select To DateTime')
|
||||
->reactive()
|
||||
->native(false),
|
||||
])
|
||||
->query(function ($query, array $data) {
|
||||
// Hide all records initially if no filters are applied
|
||||
if (empty($data['Plant']) && empty($data['invoice_number']) && empty($data['serial_number']) && empty($data['created_from']) && empty($data['created_to']) && empty($data['sticker_master_id'])) {
|
||||
return $query->whereRaw('1 = 0');
|
||||
}
|
||||
|
||||
if (!empty($data['Plant'])) { //$plant = $data['Plant'] ?? null
|
||||
$query->where('plant_id', $data['Plant']);
|
||||
}
|
||||
|
||||
if (!empty($data['invoice_number'])) {
|
||||
$query->where('invoice_number', 'like', '%' . $data['invoice_number'] . '%');
|
||||
}
|
||||
|
||||
if (!empty($data['serial_number'])) {
|
||||
$query->where('serial_number', 'like', '%' . $data['serial_number'] . '%');
|
||||
}
|
||||
|
||||
if (!empty($data['created_from'])) {
|
||||
$query->where('created_at', '>=', $data['created_from']);
|
||||
}
|
||||
|
||||
if (!empty($data['created_to'])) {
|
||||
$query->where('created_at', '<=', $data['created_to']);
|
||||
}
|
||||
|
||||
if (!empty($data['sticker_master_id'])) {
|
||||
$stickerMasterIds = StickerMaster::where('item_id', $data['sticker_master_id'])
|
||||
->pluck('id')
|
||||
->toArray();
|
||||
|
||||
if (!empty($stickerMasterIds)) {
|
||||
$query->whereIn('sticker_master_id', $stickerMasterIds);
|
||||
])
|
||||
->query(function ($query, array $data) {
|
||||
// Hide all records initially if no filters are applied
|
||||
if (empty($data['Plant']) && empty($data['invoice_number']) && empty($data['serial_number']) && empty($data['created_from']) && empty($data['created_to']) && empty($data['sticker_master_id'])) {
|
||||
return $query->whereRaw('1 = 0');
|
||||
}
|
||||
}
|
||||
})
|
||||
->indicateUsing(function (array $data) {
|
||||
$indicators = [];
|
||||
|
||||
if (!empty($data['Plant'])) {
|
||||
$indicators[] = 'Plant: ' . Plant::where('id', $data['Plant'])->value('name');
|
||||
}
|
||||
if (!empty($data['Plant'])) { //$plant = $data['Plant'] ?? null
|
||||
$query->where('plant_id', $data['Plant']);
|
||||
}
|
||||
|
||||
if (!empty($data['invoice_number'])) {
|
||||
$indicators[] = 'Invoice Number: ' . $data['invoice_number'];
|
||||
}
|
||||
if (!empty($data['invoice_number'])) {
|
||||
$query->where('invoice_number', 'like', '%' . $data['invoice_number'] . '%');
|
||||
}
|
||||
|
||||
if (!empty($data['serial_number'])) {
|
||||
$indicators[] = 'Serial Number: ' . $data['serial_number'];
|
||||
}
|
||||
if (!empty($data['serial_number'])) {
|
||||
$query->where('serial_number', 'like', '%' . $data['serial_number'] . '%');
|
||||
}
|
||||
|
||||
if (!empty($data['created_from'])) {
|
||||
$indicators[] = 'From: ' . $data['created_from'];
|
||||
}
|
||||
if (!empty($data['created_from'])) {
|
||||
$query->where('created_at', '>=', $data['created_from']);
|
||||
}
|
||||
|
||||
if (!empty($data['created_to'])) {
|
||||
$indicators[] = 'To: ' . $data['created_to'];
|
||||
}
|
||||
if (!empty($data['created_to'])) {
|
||||
$query->where('created_at', '<=', $data['created_to']);
|
||||
}
|
||||
|
||||
if (!empty($data['sticker_master_id'])) {
|
||||
$itemCode = Item::find($data['sticker_master_id'])->code ?? 'Unknown';
|
||||
$indicators[] = 'Item Code: ' . $itemCode;
|
||||
}
|
||||
if (!empty($data['sticker_master_id'])) {
|
||||
$stickerMasterIds = StickerMaster::where('item_id', $data['sticker_master_id'])
|
||||
->pluck('id')
|
||||
->toArray();
|
||||
|
||||
return $indicators;
|
||||
})
|
||||
if (!empty($stickerMasterIds)) {
|
||||
$query->whereIn('sticker_master_id', $stickerMasterIds);
|
||||
}
|
||||
}
|
||||
})
|
||||
->indicateUsing(function (array $data) {
|
||||
$indicators = [];
|
||||
|
||||
if (!empty($data['Plant'])) {
|
||||
$indicators[] = 'Plant: ' . Plant::where('id', $data['Plant'])->value('name');
|
||||
}
|
||||
|
||||
if (!empty($data['invoice_number'])) {
|
||||
$indicators[] = 'Invoice Number: ' . $data['invoice_number'];
|
||||
}
|
||||
|
||||
if (!empty($data['serial_number'])) {
|
||||
$indicators[] = 'Serial Number: ' . $data['serial_number'];
|
||||
}
|
||||
|
||||
if (!empty($data['created_from'])) {
|
||||
$indicators[] = 'From: ' . $data['created_from'];
|
||||
}
|
||||
|
||||
if (!empty($data['created_to'])) {
|
||||
$indicators[] = 'To: ' . $data['created_to'];
|
||||
}
|
||||
|
||||
if (!empty($data['sticker_master_id'])) {
|
||||
$itemCode = Item::find($data['sticker_master_id'])->code ?? 'Unknown';
|
||||
$indicators[] = 'Item Code: ' . $itemCode;
|
||||
}
|
||||
|
||||
return $indicators;
|
||||
})
|
||||
])
|
||||
->filtersFormMaxHeight('280px')
|
||||
->actions([
|
||||
|
||||
@@ -177,8 +177,8 @@ class ItemResource extends Resource
|
||||
$currentPage = method_exists($paginator, 'currentPage') ? $paginator->currentPage() : 1;
|
||||
return ($currentPage - 1) * $perPage + $rowLoop->iteration;
|
||||
}),
|
||||
Tables\Columns\TextColumn::make('code')
|
||||
->label('Item Code')
|
||||
Tables\Columns\TextColumn::make('plant.name')
|
||||
->label('Plant')
|
||||
->alignCenter()
|
||||
->sortable()
|
||||
->searchable(),
|
||||
@@ -187,6 +187,11 @@ class ItemResource extends Resource
|
||||
->alignCenter()
|
||||
->sortable()
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('code')
|
||||
->label('Item Code')
|
||||
->alignCenter()
|
||||
->sortable()
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('description')
|
||||
->label('Description')
|
||||
->alignCenter()
|
||||
@@ -201,11 +206,6 @@ class ItemResource extends Resource
|
||||
->label('Unit of Measure')
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('plant.name')
|
||||
->label('Plant')
|
||||
->alignCenter()
|
||||
->sortable()
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('created_at')
|
||||
->label('Created At')
|
||||
->dateTime()
|
||||
|
||||
@@ -29,6 +29,7 @@ class LineResource extends Resource
|
||||
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
|
||||
|
||||
protected static ?string $navigationGroup = 'Master Entries';
|
||||
|
||||
protected static ?int $navigationSort = 5;
|
||||
|
||||
public static function form(Form $form): Form
|
||||
@@ -174,6 +175,9 @@ class LineResource extends Resource
|
||||
])
|
||||
->hint(fn ($get) => $get('lTypeError') ? $get('lTypeError') : null)
|
||||
->hintColor('danger'),
|
||||
Forms\Components\TextInput::make('group_work_center')
|
||||
->label('Group Work Center')
|
||||
->placeholder('Scan the valid Group Work Center'),
|
||||
Forms\Components\TextInput::make('id')
|
||||
->hidden()
|
||||
->readOnly(),
|
||||
@@ -198,6 +202,11 @@ class LineResource extends Resource
|
||||
$currentPage = method_exists($paginator, 'currentPage') ? $paginator->currentPage() : 1;
|
||||
return ($currentPage - 1) * $perPage + $rowLoop->iteration;
|
||||
}),
|
||||
Tables\Columns\TextColumn::make('plant.name')
|
||||
->label('Plant')
|
||||
->alignCenter()
|
||||
->sortable()
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('name')
|
||||
->label('Line')
|
||||
->alignCenter()
|
||||
@@ -208,8 +217,8 @@ class LineResource extends Resource
|
||||
->alignCenter()
|
||||
->sortable()
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('plant.name')
|
||||
->label('Plant')
|
||||
Tables\Columns\TextColumn::make('group_work_center')
|
||||
->label('Group Work Center')
|
||||
->alignCenter()
|
||||
->sortable()
|
||||
->searchable(),
|
||||
|
||||
@@ -43,6 +43,8 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
|
||||
protected static ?string $navigationGroup = 'Export Dispatch';
|
||||
|
||||
protected static ?int $navigationSort = 5;
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
@@ -63,7 +65,9 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
$set('invoice_number', null);
|
||||
$set('pallet_number', null);
|
||||
$set('serial_number', null);
|
||||
$set('sno_quantity', null);
|
||||
$set('sno_quantity', 0);
|
||||
$set('scan_quantity', 0);
|
||||
$set('pend_quantity', 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -71,7 +75,9 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
$set('invoice_number', null);
|
||||
$set('pallet_number', null);
|
||||
$set('serial_number', null);
|
||||
$set('sno_quantity', null);
|
||||
$set('sno_quantity', 0);
|
||||
$set('scan_quantity', 0);
|
||||
$set('pend_quantity', 0);
|
||||
}
|
||||
}),
|
||||
|
||||
@@ -90,18 +96,33 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
->readOnly(fn (callable $get) => !$get('plant') || $get('pallet_number') || $get('serial_number'))
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
$plantId = $get('plant');
|
||||
$invNo = $get('invoice_number');
|
||||
$snoCount = 0;
|
||||
$pendingCount = 0;
|
||||
$scannedCount = 0;
|
||||
if (!$plantId) {
|
||||
$set('invoice_number', null);
|
||||
$set('pallet_number', null);
|
||||
}
|
||||
else if ($invNo)
|
||||
{
|
||||
$snoCount = LocatorInvoiceValidation::where('plant_id', $plantId)->where('invoice_number', $invNo)->count();
|
||||
|
||||
$pendingCount = LocatorInvoiceValidation::where('invoice_number', $invNo)->where('plant_id', $plantId)->whereNull('scanned_status')->orWhere('scanned_status', '=', '')->count();
|
||||
|
||||
$scannedCount = LocatorInvoiceValidation::where('invoice_number', $invNo)->where('plant_id', $plantId)->where('scanned_status', '=', 'Scanned')->count();
|
||||
}
|
||||
$set('update_invoice', null);
|
||||
$set('pallet_number', null);
|
||||
$set('serial_number', null);
|
||||
$set('sno_quantity', $snoCount);
|
||||
$set('scan_quantity', $scannedCount);
|
||||
$set('pend_quantity', $pendingCount);
|
||||
}),
|
||||
Forms\Components\TextInput::make('pallet_number')
|
||||
->label('Scan Pallet No')
|
||||
->reactive()
|
||||
->minLength(10)
|
||||
// ->readOnly(fn (callable $get) => !$get('plant') || !$get('invoice_number') || $get('serial_number'))
|
||||
->readOnly(function (callable $get) {
|
||||
$invoiceNumber = $get('invoice_number');
|
||||
@@ -143,6 +164,7 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
Forms\Components\TextInput::make('serial_number')
|
||||
->label('Scan Serial No')
|
||||
->reactive()
|
||||
->minLength(9)
|
||||
// ->readOnly(fn (callable $get) => !$get('plant') || !$get('invoice_number') || $get('pallet_number'))
|
||||
->readOnly(function (callable $get) {
|
||||
$invoiceNumber = $get('invoice_number');
|
||||
@@ -176,7 +198,18 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
'x-on:keydown.enter.prevent' => '$wire.processSerialNo()',
|
||||
]),
|
||||
Forms\Components\TextInput::make('sno_quantity')
|
||||
->label('SNo. Quantity')
|
||||
->label('Invoice Quantity')
|
||||
->default(0)
|
||||
->readOnly(),
|
||||
|
||||
Forms\Components\TextInput::make('scan_quantity')
|
||||
->label('Scanned Quantity')
|
||||
->default(0)
|
||||
->readOnly(),
|
||||
|
||||
Forms\Components\TextInput::make('pend_quantity')
|
||||
->label('Pending Quantity')
|
||||
->default(0)
|
||||
->readOnly(),
|
||||
|
||||
//Forms\Components\View::make('forms.components.update-invoice-button'),
|
||||
@@ -262,9 +295,10 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
if (!$palletRecord)
|
||||
{
|
||||
Notification::make()
|
||||
->title("Pallet number '{$palletNumber}' does not exist.")
|
||||
->danger()
|
||||
->send();
|
||||
->title("Pallet number '{$palletNumber}' does not exist.")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -285,8 +319,9 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
Notification::make()
|
||||
->title("Pallet number '{$palletNumber}' is not completed in masters")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
// if ($allCompleted)
|
||||
@@ -329,6 +364,7 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
// Notification::make()
|
||||
// ->title("Pallet number '{$palletNumber}' scanned successfully")
|
||||
// ->success()
|
||||
// ->duration(800)
|
||||
// ->send();
|
||||
// }
|
||||
|
||||
@@ -360,6 +396,7 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
// Notification::make()
|
||||
// ->title("Pallet number '{$palletNumber}' scanned successfully")
|
||||
// ->success()
|
||||
// ->duration(800)
|
||||
// ->send();
|
||||
// }
|
||||
|
||||
@@ -395,36 +432,29 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
Tables\Columns\TextColumn::make('plant.name')
|
||||
->label('Plant')
|
||||
->alignCenter()
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('invoice_number')
|
||||
->label('Invoice Number')
|
||||
->searchable()
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('serial_number')
|
||||
->label('Serial Number')
|
||||
->searchable()
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('pallet_number')
|
||||
->label('Pallet Number')
|
||||
->searchable()
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('locator_number')
|
||||
->label('Locator Number')
|
||||
->searchable()
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('scanned_status')
|
||||
->label('Scanned Status')
|
||||
->searchable()
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('upload_status')
|
||||
->label('Upload Status')
|
||||
->searchable()
|
||||
->alignCenter(),
|
||||
Tables\Columns\TextColumn::make('created_by')
|
||||
->label('Created By')
|
||||
@@ -467,16 +497,16 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
->label('Import Invoice')
|
||||
->form([
|
||||
Select::make('plant_id')
|
||||
->options(Plant::pluck('name', 'id')->toArray())
|
||||
->label('Select Plant')
|
||||
->required()
|
||||
->default(function () {
|
||||
return optional(InvoiceValidation::latest()->first())->plant_id;
|
||||
})
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
$set('invoice_serial_number', null);
|
||||
})
|
||||
->reactive(),
|
||||
->options(Plant::pluck('name', 'id')->toArray())
|
||||
->label('Select Plant')
|
||||
->required()
|
||||
->default(function () {
|
||||
return optional(InvoiceValidation::latest()->first())->plant_id;
|
||||
})
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
$set('invoice_serial_number', null);
|
||||
})
|
||||
->reactive(),
|
||||
|
||||
FileUpload::make('invoice_serial_number')
|
||||
->label('Invoice Serial Number')
|
||||
@@ -527,6 +557,7 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
->title('Invalid Locator Invoice Found')
|
||||
->body('Uploaded excel sheet is empty or<br>contains no valid data.')
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
if ($disk->exists($path)) {
|
||||
@@ -552,7 +583,7 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
}
|
||||
else
|
||||
{
|
||||
if(Str::length($serialNumber) < 13 || !ctype_alnum($serialNumber))
|
||||
if(Str::length($serialNumber) < 9 || Str::length($serialNumber) > 20 || !ctype_alnum($serialNumber))
|
||||
{
|
||||
$invalidSerialCodes[] = $serialNumber;
|
||||
}
|
||||
@@ -574,10 +605,12 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
|
||||
if (!empty($uniqueSerialCodes)) {
|
||||
Notification::make()
|
||||
->title('Invalid Serial Numbers Found')
|
||||
->body('The following serial numbers should contain minimum 13 digit alpha numeric values:<br>' . implode(', ', $uniqueSerialCodes))
|
||||
->danger()
|
||||
->send();
|
||||
->title('Invalid Serial Numbers Found')
|
||||
->body('The following serial numbers should contain minimum 9 digit (and maximum 20 digit) alpha numeric values:<br>' . implode(', ', $uniqueSerialCodes))
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
@@ -591,7 +624,9 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
->title('Duplicate Serial Numbers Found')
|
||||
->body('The following serial numbers are already exist in imported excel:<br>' . implode(', ', $duplicateSerialCodes))
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
@@ -603,10 +638,12 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
->title('Invalid Locator Invoice Found')
|
||||
->body('Uploaded excel sheet is empty or<br>contains no valid data.')
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -623,20 +660,22 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
->title('Duplicate Serial Numbers Found')
|
||||
->body('The following serial numbers already exist with a different invoice number:<br>' . implode(', ', $existingSerials))
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
if ($disk->exists($path))
|
||||
{
|
||||
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Save full file path to session
|
||||
// Save full file path to session
|
||||
session(['uploaded_invoice_path' => $fullPath]);
|
||||
Notification::make()
|
||||
->title('Success: Invoice imported successfully.')
|
||||
->success()
|
||||
->duration(800)
|
||||
->send();
|
||||
}
|
||||
}
|
||||
@@ -647,11 +686,15 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
|
||||
ImportAction::make()
|
||||
->importer(LocatorInvoiceValidationImporter::class)
|
||||
->label('Import Locator Invoice')
|
||||
->color('warning')
|
||||
->visible(function() {
|
||||
return Filament::auth()->user()->can('view import locator invoice validation');
|
||||
}),
|
||||
ExportAction::make()
|
||||
->exporter(LocatorInvoiceValidationExporter::class)
|
||||
->label('Export Locator Invoice')
|
||||
->color('warning')
|
||||
->visible(function() {
|
||||
return Filament::auth()->user()->can('view export locator invoice validation');
|
||||
}),
|
||||
@@ -901,6 +944,11 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
];
|
||||
}
|
||||
|
||||
public static function getNavigationLabel(): string
|
||||
{
|
||||
return 'Scan Invoice';
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -7,16 +7,25 @@ use App\Filament\Imports\LocatorImporter;
|
||||
use App\Filament\Resources\LocatorResource\Pages;
|
||||
use App\Filament\Resources\LocatorResource\RelationManagers;
|
||||
use App\Models\Locator;
|
||||
use App\Models\PalletValidation;
|
||||
use App\Models\Plant;
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Get;
|
||||
use Filament\Tables\Actions\ImportAction;
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Actions\ExportAction;
|
||||
use Filament\Tables\Filters\Filter;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Str;
|
||||
|
||||
class LocatorResource extends Resource
|
||||
{
|
||||
@@ -34,19 +43,87 @@ class LocatorResource extends Resource
|
||||
->schema([
|
||||
Forms\Components\Select::make('plant_id')
|
||||
->relationship('plant', 'name')
|
||||
->required(),
|
||||
->required()
|
||||
// ->nullable(),
|
||||
->reactive()
|
||||
->default(function () {
|
||||
return optional(Locator::latest()->first())->plant_id;
|
||||
})
|
||||
->disabled(fn (Get $get) => !empty($get('id')))
|
||||
// ->afterStateUpdated(fn ($set) => $set('block_id', null) & $set('name', null) & $set('start_time', null) & $set('duration', null) & $set('end_time', null))
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
$plantId = $get('plant_id');
|
||||
// Ensure `linestop_id` is not cleared
|
||||
if (!$plantId) {
|
||||
$set('locPlantError', 'Please select a plant first.');
|
||||
$set('locator_number', null);
|
||||
$set('locator_quantity', 0);
|
||||
$set('operator_id', Filament::auth()->user()?->name);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
$set('locPlantError', null);
|
||||
$set('locator_number', null);
|
||||
$set('locator_quantity', 0);
|
||||
$set('operator_id', Filament::auth()->user()?->name);
|
||||
}
|
||||
})
|
||||
->extraAttributes(fn ($get) => [
|
||||
'class' => $get('locPlantError') ? 'border-red-500' : '',
|
||||
])
|
||||
->hint(fn ($get) => $get('locPlantError') ? $get('locPlantError') : null)
|
||||
->hintColor('danger'),
|
||||
Forms\Components\TextInput::make('locator_number')
|
||||
->label('Locator Number')
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('locator_quantity')
|
||||
->minLength(7)
|
||||
->reactive()
|
||||
->required()
|
||||
->numeric()
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
$plantId = $get('plant_id');
|
||||
$locator = $get('locator_number');
|
||||
if (!$plantId) {
|
||||
$set('locNameError', 'Please select a plant first.');
|
||||
$set('locator_number', null);
|
||||
$set('locator_quantity', 0);
|
||||
$set('operator_id', Filament::auth()->user()?->name);
|
||||
return;
|
||||
}
|
||||
else if (!$locator || Str::length($locator) < 7) {
|
||||
$set('locNameError', 'Please scan the valid locator number.');
|
||||
$set('locator_quantity', 0);
|
||||
$set('operator_id', Filament::auth()->user()?->name);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
$set('locNameError', null);
|
||||
$set('locator_quantity', PalletValidation::where('locator_number', $locator)->where('plant_id', $plantId)->distinct('pallet_number')->count('pallet_number'));
|
||||
$set('operator_id', Filament::auth()->user()?->name);
|
||||
}
|
||||
})
|
||||
->extraAttributes(fn ($get) => [
|
||||
'class' => $get('locNameError') ? 'border-red-500' : '',
|
||||
])
|
||||
->hint(fn ($get) => $get('locNameError') ? $get('locNameError') : null)
|
||||
->hintColor('danger')
|
||||
->rule(function (callable $get) {
|
||||
return Rule::unique('locators', 'locator_number')
|
||||
->where('plant_id', $get('plant_id'))
|
||||
->ignore($get('id')); // Ignore current record during updates
|
||||
}),
|
||||
Forms\Components\TextInput::make('locator_quantity')
|
||||
->label('Locator Quantity')
|
||||
->required()
|
||||
->readOnly()
|
||||
->numeric()
|
||||
->default(0),
|
||||
Forms\Components\Hidden::make('operator_id')
|
||||
->default(Filament::auth()->user()?->name)
|
||||
->required(),
|
||||
|
||||
->default(Filament::auth()->user()?->name)
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('id')
|
||||
->hidden()
|
||||
->readOnly(),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -67,34 +144,183 @@ class LocatorResource extends Resource
|
||||
return ($currentPage - 1) * $perPage + $rowLoop->iteration;
|
||||
}),
|
||||
Tables\Columns\TextColumn::make('plant.name')
|
||||
->numeric()
|
||||
->searchable()
|
||||
->label('Plant')
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('locator_number')
|
||||
->label('Locator Number')
|
||||
->alignCenter()
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('locator_quantity')
|
||||
->label('Locator Quantity')
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('operator_id')
|
||||
->label('Operator ID')
|
||||
->searchable()
|
||||
->label('Created By')
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('created_at')
|
||||
->label('Created At')
|
||||
->dateTime()
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('updated_at')
|
||||
->label('Updated At')
|
||||
->dateTime()
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('deleted_at')
|
||||
->label('Deleted At')
|
||||
->dateTime()
|
||||
->alignCenter()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
])
|
||||
->filters([
|
||||
Tables\Filters\TrashedFilter::make(),
|
||||
Filter::make('advanced_filters')
|
||||
->label('Advanced Filters')
|
||||
->form([
|
||||
Select::make('Plant')
|
||||
->label('Select Plant')
|
||||
->nullable()
|
||||
->options(function () {
|
||||
return Plant::pluck('name', 'id');
|
||||
})
|
||||
->reactive()
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get): void {
|
||||
$set('locator_number', null);
|
||||
$set('locator_quantity', null);
|
||||
$set('created_from', null);
|
||||
$set('created_to', null);
|
||||
$set('created_by', null);
|
||||
$set('updated_from', null);
|
||||
$set('updated_to', null);
|
||||
}),
|
||||
Select::make('locator_number')
|
||||
->label('Locator Number')
|
||||
->options(function (callable $get) {
|
||||
$plantId = $get('Plant');
|
||||
if (!$plantId) {
|
||||
return [];
|
||||
}
|
||||
return Locator::where('plant_id', $plantId)->orderBy('locator_number', 'asc')->get()->unique('locator_number')->pluck('locator_number', 'locator_number')->toArray();
|
||||
// ->whereNotNull('locator_number')
|
||||
// ->where('locator_number','!=', '')
|
||||
})
|
||||
->searchable()
|
||||
->reactive(),
|
||||
Select::make('locator_quantity')
|
||||
->label('Locator Quantity')
|
||||
->options([
|
||||
0 => 0,
|
||||
1 => 1,
|
||||
2 => 2,
|
||||
])
|
||||
->reactive(),
|
||||
DateTimePicker::make(name: 'created_from')
|
||||
->label('Created From')
|
||||
->placeholder(placeholder: 'Select From DateTime')
|
||||
->reactive()
|
||||
->native(false),
|
||||
DateTimePicker::make('created_to')
|
||||
->label('Created To')
|
||||
->placeholder(placeholder: 'Select To DateTime')
|
||||
->reactive()
|
||||
->native(false),
|
||||
TextInput::make('created_by')
|
||||
->label('Created By')
|
||||
->reactive()
|
||||
->placeholder(placeholder: 'Enter Created By'),
|
||||
DateTimePicker::make(name: 'updated_from')
|
||||
->label('Updated From')
|
||||
->placeholder(placeholder: 'Select From DateTime')
|
||||
->reactive()
|
||||
->native(false),
|
||||
DateTimePicker::make('updated_to')
|
||||
->label('Updated To')
|
||||
->placeholder(placeholder: 'Select To DateTime')
|
||||
->reactive()
|
||||
->native(false),
|
||||
])
|
||||
->query(function ($query, array $data) {
|
||||
// Hide all records initially if no filters are applied
|
||||
if (empty($data['Plant']) && empty($data['locator_number']) && $data['locator_quantity'] == null && empty($data['created_from']) && empty($data['created_to']) && empty($data['created_by']) && empty($data['updated_from']) && empty($data['updated_to'])) {
|
||||
return $query->whereRaw('1 = 0');
|
||||
}
|
||||
|
||||
if (!empty($data['Plant'])) { //$plant = $data['Plant'] ?? null
|
||||
$query->where('plant_id', $data['Plant']);
|
||||
}
|
||||
|
||||
if (!empty($data['locator_number'])) {
|
||||
$query->where('locator_number', $data['locator_number']);
|
||||
}
|
||||
|
||||
if ($data['locator_quantity'] != null && $data['locator_quantity'] != '') { //isset($data['locator_quantity']) &&
|
||||
$query->where('locator_quantity', $data['locator_quantity']);//(int)
|
||||
}
|
||||
|
||||
if (!empty($data['created_from'])) {
|
||||
$query->where('created_at', '>=', $data['created_from']);
|
||||
}
|
||||
|
||||
if (!empty($data['created_to'])) {
|
||||
$query->where('created_at', '<=', $data['created_to']);
|
||||
}
|
||||
|
||||
if (!empty($data['created_by'])) {
|
||||
$query->where('operator_id', $data['created_by']);
|
||||
}
|
||||
|
||||
if (!empty($data['updated_from'])) {
|
||||
$query->where('updated_at', '>=', $data['updated_from']);
|
||||
}
|
||||
|
||||
if (!empty($data['updated_to'])) {
|
||||
$query->where('updated_at', '<=', $data['updated_to']);
|
||||
}
|
||||
})
|
||||
->indicateUsing(function (array $data) {
|
||||
$indicators = [];
|
||||
|
||||
if (!empty($data['Plant'])) {
|
||||
$indicators[] = 'Plant: ' . Plant::where('id', $data['Plant'])->value('name');
|
||||
}
|
||||
|
||||
if (!empty($data['locator_number'])) {
|
||||
$indicators[] = 'Locator Number: ' . $data['locator_number'];
|
||||
}
|
||||
|
||||
if ($data['locator_quantity'] != null && $data['locator_quantity'] != '') { //isset($data['locator_quantity']) &&
|
||||
$indicators[] = 'Locator Quantity: ' . $data['locator_quantity'];
|
||||
}
|
||||
|
||||
if (!empty($data['created_from'])) {
|
||||
$indicators[] = 'From: ' . $data['created_from'];
|
||||
}
|
||||
|
||||
if (!empty($data['created_to'])) {
|
||||
$indicators[] = 'To: ' . $data['created_to'];
|
||||
}
|
||||
|
||||
if (!empty($data['created_by'])) {
|
||||
$indicators[] = 'Created By: ' . $data['created_by'];
|
||||
}
|
||||
|
||||
if (!empty($data['updated_from'])) {
|
||||
$indicators[] = 'Updated From: ' . $data['updated_from'];
|
||||
}
|
||||
|
||||
if (!empty($data['updated_to'])) {
|
||||
$indicators[] = 'Updated To: ' . $data['updated_to'];
|
||||
}
|
||||
|
||||
return $indicators;
|
||||
})
|
||||
])
|
||||
->filtersFormMaxHeight('280px')
|
||||
->actions([
|
||||
Tables\Actions\ViewAction::make(),
|
||||
Tables\Actions\EditAction::make(),
|
||||
|
||||
@@ -19,6 +19,8 @@ use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Filament\Tables\Actions\ImportAction;
|
||||
use Filament\Tables\Actions\ExportAction;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Str;
|
||||
|
||||
class MachineResource extends Resource
|
||||
{
|
||||
@@ -85,6 +87,13 @@ class MachineResource extends Resource
|
||||
}
|
||||
else
|
||||
{
|
||||
$grpWrkCnr = Line::find($lineId)->group_work_center;
|
||||
if (!$grpWrkCnr || Str::length($grpWrkCnr) < 1)
|
||||
{
|
||||
$set('mLineError', 'Please select a group work center line.');
|
||||
$set('line_id', null);
|
||||
return;
|
||||
}
|
||||
$set('mLineError', null);
|
||||
}
|
||||
})
|
||||
@@ -95,7 +104,17 @@ class MachineResource extends Resource
|
||||
->hintColor('danger'),
|
||||
Forms\Components\TextInput::make('name')
|
||||
->label('Name')
|
||||
->required(),
|
||||
->placeholder('Scan the valid Machine Name')
|
||||
->required()
|
||||
->rule(function (callable $get) {
|
||||
return Rule::unique('machines', 'name')
|
||||
->where('line_id', $get('line_id'))
|
||||
->where('plant_id', $get('plant_id'))
|
||||
->ignore($get('id')); // Ignore current record during updates
|
||||
}),
|
||||
Forms\Components\TextInput::make('work_center')
|
||||
->label('Work Center')
|
||||
->placeholder('Scan the valid Work Center'),
|
||||
Forms\Components\TextInput::make('id')
|
||||
->hidden()
|
||||
->readOnly(),
|
||||
@@ -126,6 +145,11 @@ class MachineResource extends Resource
|
||||
->label('Name')
|
||||
->searchable()
|
||||
->alignCenter(),
|
||||
Tables\Columns\TextColumn::make('work_center')
|
||||
->label('Work Center')
|
||||
->alignCenter()
|
||||
->sortable()
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('created_at')
|
||||
->label('Created At')
|
||||
->alignCenter()
|
||||
|
||||
121
app/Filament/Resources/MfmMeterResource.php
Normal file
121
app/Filament/Resources/MfmMeterResource.php
Normal file
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use App\Filament\Resources\MfmMeterResource\Pages;
|
||||
use App\Filament\Resources\MfmMeterResource\RelationManagers;
|
||||
use App\Models\MfmMeter;
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Filament\Forms\Components\Section;
|
||||
|
||||
class MfmMeterResource extends Resource
|
||||
{
|
||||
protected static ?string $model = MfmMeter::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
|
||||
|
||||
protected static ?string $navigationGroup = 'Power House';
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Section::make('')
|
||||
->schema([
|
||||
Forms\Components\Select::make('plant_id')
|
||||
->relationship('plant', 'name')
|
||||
->label('Plant')
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('sequence')
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('name')
|
||||
->required(),
|
||||
Forms\Components\Hidden::make('created_by')
|
||||
->default(Filament::auth()->user()?->name),
|
||||
])
|
||||
->columns(4),
|
||||
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('id')
|
||||
->label('ID')
|
||||
->numeric()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('plant.name')
|
||||
->label('Plant')
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('sequence')
|
||||
->label('Sequence')
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('name')
|
||||
->label('Meter Name')
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('created_at')
|
||||
->label('Created At')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
Tables\Columns\TextColumn::make('updated_at')
|
||||
->label('Updated At')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
Tables\Columns\TextColumn::make('deleted_at')
|
||||
->label('Deleted At')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
])
|
||||
->filters([
|
||||
Tables\Filters\TrashedFilter::make(),
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\ViewAction::make(),
|
||||
Tables\Actions\EditAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\BulkActionGroup::make([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
Tables\Actions\ForceDeleteBulkAction::make(),
|
||||
Tables\Actions\RestoreBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListMfmMeters::route('/'),
|
||||
'create' => Pages\CreateMfmMeter::route('/create'),
|
||||
'view' => Pages\ViewMfmMeter::route('/{record}'),
|
||||
'edit' => Pages\EditMfmMeter::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
|
||||
public static function getEloquentQuery(): Builder
|
||||
{
|
||||
return parent::getEloquentQuery()
|
||||
->withoutGlobalScopes([
|
||||
SoftDeletingScope::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\MfmMeterResource\Pages;
|
||||
|
||||
use App\Filament\Resources\MfmMeterResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateMfmMeter extends CreateRecord
|
||||
{
|
||||
protected static string $resource = MfmMeterResource::class;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\MfmMeterResource\Pages;
|
||||
|
||||
use App\Filament\Resources\MfmMeterResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditMfmMeter extends EditRecord
|
||||
{
|
||||
protected static string $resource = MfmMeterResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\ViewAction::make(),
|
||||
Actions\DeleteAction::make(),
|
||||
Actions\ForceDeleteAction::make(),
|
||||
Actions\RestoreAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\MfmMeterResource\Pages;
|
||||
|
||||
use App\Filament\Resources\MfmMeterResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListMfmMeters extends ListRecords
|
||||
{
|
||||
protected static string $resource = MfmMeterResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\MfmMeterResource\Pages;
|
||||
|
||||
use App\Filament\Resources\MfmMeterResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ViewRecord;
|
||||
|
||||
class ViewMfmMeter extends ViewRecord
|
||||
{
|
||||
protected static string $resource = MfmMeterResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\EditAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
176
app/Filament/Resources/MfmParameterResource.php
Normal file
176
app/Filament/Resources/MfmParameterResource.php
Normal file
@@ -0,0 +1,176 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use App\Filament\Exports\MfmParameterExporter;
|
||||
use App\Filament\Imports\MfmParameterImporter;
|
||||
use App\Filament\Resources\MfmParameterResource\Pages;
|
||||
use App\Filament\Resources\MfmParameterResource\RelationManagers;
|
||||
use App\Models\MfmParameter;
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Filament\Forms\Components\Section;
|
||||
use Filament\Tables\Actions\ImportAction;
|
||||
use Filament\Tables\Actions\ExportAction;
|
||||
|
||||
class MfmParameterResource extends Resource
|
||||
{
|
||||
protected static ?string $model = MfmParameter::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
|
||||
protected static ?string $navigationGroup = 'Power House';
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Section::make('')
|
||||
->schema([
|
||||
Forms\Components\Select::make('plant_id')
|
||||
->label('Plant')
|
||||
->relationship('plant', 'name')
|
||||
->required(),
|
||||
Forms\Components\Select::make('mfm_meter_id')
|
||||
->label('Mfm Meter')
|
||||
->relationship('mfmMeter', 'sequence')
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('name')
|
||||
->label('Parameter Name')
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('register_id')
|
||||
->label('Register ID')
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('identifier')
|
||||
->label('Identifier')
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('byte_to_convert')
|
||||
->label('Byte To Convert')
|
||||
->default(2)
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('type_to_convert')
|
||||
->label('Type To Convert')
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('decimal_to_display')
|
||||
->label('Decimal To Display')
|
||||
->default(1)
|
||||
->required(),
|
||||
])
|
||||
->columns(8),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('id')
|
||||
->label('ID')
|
||||
->numeric()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('plant.name')
|
||||
->label('Plant')
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('mfmMeter.name')
|
||||
->label('Sequence')
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('name')
|
||||
->label('Parameter Name')
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('register_id')
|
||||
->label('Register ID')
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('identifier')
|
||||
->label('Identifier')
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('byte_to_convert')
|
||||
->label('Byte To Convert')
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('type_to_convert')
|
||||
->label('Type To Convert')
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('decimal_to_display')
|
||||
->label('Decimal To Display')
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('created_at')
|
||||
->dateTime()
|
||||
->alignCenter()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
Tables\Columns\TextColumn::make('updated_at')
|
||||
->alignCenter()
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
Tables\Columns\TextColumn::make('deleted_at')
|
||||
->alignCenter()
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
])
|
||||
->filters([
|
||||
Tables\Filters\TrashedFilter::make(),
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\ViewAction::make(),
|
||||
Tables\Actions\EditAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\BulkActionGroup::make([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
Tables\Actions\ForceDeleteBulkAction::make(),
|
||||
Tables\Actions\RestoreBulkAction::make(),
|
||||
]),
|
||||
])
|
||||
->headerActions([
|
||||
ImportAction::make()
|
||||
->importer(MfmParameterImporter::class)
|
||||
->visible(function() {
|
||||
return Filament::auth()->user()->can('view import mfm parameter');
|
||||
}),
|
||||
ExportAction::make()
|
||||
->exporter(MfmParameterExporter::class)
|
||||
->visible(function() {
|
||||
return Filament::auth()->user()->can('view export mfm parameter');
|
||||
}),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListMfmParameters::route('/'),
|
||||
'create' => Pages\CreateMfmParameter::route('/create'),
|
||||
'view' => Pages\ViewMfmParameter::route('/{record}'),
|
||||
'edit' => Pages\EditMfmParameter::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
|
||||
public static function getEloquentQuery(): Builder
|
||||
{
|
||||
return parent::getEloquentQuery()
|
||||
->withoutGlobalScopes([
|
||||
SoftDeletingScope::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\MfmParameterResource\Pages;
|
||||
|
||||
use App\Filament\Resources\MfmParameterResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateMfmParameter extends CreateRecord
|
||||
{
|
||||
protected static string $resource = MfmParameterResource::class;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\MfmParameterResource\Pages;
|
||||
|
||||
use App\Filament\Resources\MfmParameterResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditMfmParameter extends EditRecord
|
||||
{
|
||||
protected static string $resource = MfmParameterResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\ViewAction::make(),
|
||||
Actions\DeleteAction::make(),
|
||||
Actions\ForceDeleteAction::make(),
|
||||
Actions\RestoreAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\MfmParameterResource\Pages;
|
||||
|
||||
use App\Filament\Resources\MfmParameterResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListMfmParameters extends ListRecords
|
||||
{
|
||||
protected static string $resource = MfmParameterResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\MfmParameterResource\Pages;
|
||||
|
||||
use App\Filament\Resources\MfmParameterResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ViewRecord;
|
||||
|
||||
class ViewMfmParameter extends ViewRecord
|
||||
{
|
||||
protected static string $resource = MfmParameterResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\EditAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
223
app/Filament/Resources/MfmReadingResource.php
Normal file
223
app/Filament/Resources/MfmReadingResource.php
Normal file
@@ -0,0 +1,223 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use App\Filament\Resources\MfmReadingResource\Pages;
|
||||
use App\Filament\Resources\MfmReadingResource\RelationManagers;
|
||||
use App\Models\MfmReading;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
|
||||
class MfmReadingResource extends Resource
|
||||
{
|
||||
protected static ?string $model = MfmReading::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
|
||||
|
||||
protected static ?string $navigationGroup = 'Power House';
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Forms\Components\Select::make('plant_id')
|
||||
->relationship('plant', 'name')
|
||||
->required(),
|
||||
Forms\Components\Select::make('mfm_meter_id')
|
||||
->relationship('mfmMeter', 'name')
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('apparent_energy_received'),
|
||||
Forms\Components\TextInput::make('reactive_energy_received'),
|
||||
Forms\Components\TextInput::make('active_energy_received'),
|
||||
Forms\Components\TextInput::make('active_power_r'),
|
||||
Forms\Components\TextInput::make('active_power_y'),
|
||||
Forms\Components\TextInput::make('active_power_b'),
|
||||
Forms\Components\TextInput::make('active_power_total'),
|
||||
Forms\Components\TextInput::make('voltage_ry'),
|
||||
Forms\Components\TextInput::make('voltage_yb'),
|
||||
Forms\Components\TextInput::make('voltage_br'),
|
||||
Forms\Components\TextInput::make('current_r'),
|
||||
Forms\Components\TextInput::make('current_y'),
|
||||
Forms\Components\TextInput::make('current_b'),
|
||||
Forms\Components\TextInput::make('current_n'),
|
||||
Forms\Components\TextInput::make('voltage_r_n'),
|
||||
Forms\Components\TextInput::make('voltage_y_n'),
|
||||
Forms\Components\TextInput::make('voltage_b_n'),
|
||||
Forms\Components\TextInput::make('frequency'),
|
||||
Forms\Components\TextInput::make('power_factor_r'),
|
||||
Forms\Components\TextInput::make('power_factor_y'),
|
||||
Forms\Components\TextInput::make('power_factor_b'),
|
||||
Forms\Components\TextInput::make('power_factor_total'),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('id')
|
||||
->label('ID')
|
||||
->alignCenter()
|
||||
->numeric()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('plant.name')
|
||||
->label('Plant')
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('mfmMeter.name')
|
||||
->label('Mfm Meter')
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('apparent_energy_received')
|
||||
->label('Apparent Energy Received')
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('reactive_energy_received')
|
||||
->label('Reactive Energy Received')
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('active_energy_received')
|
||||
->label('Active Energy Received')
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('active_power_r')
|
||||
->label('Active Power R')
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('active_power_y')
|
||||
->label('Active Power Y')
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('active_power_b')
|
||||
->label('Active Power B')
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('active_power_total')
|
||||
->label('Active Power Total')
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('voltage_ry')
|
||||
->label('Voltage RY')
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('voltage_yb')
|
||||
->label('Voltage YB')
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('voltage_br')
|
||||
->label('Voltage BR')
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('current_r')
|
||||
->label('Current R')
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('current_y')
|
||||
->label('Current Y')
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('current_b')
|
||||
->label('Current B')
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('current_n')
|
||||
->label('Current N')
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('voltage_r_n')
|
||||
->label('Voltage R N')
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('voltage_y_n')
|
||||
->label('Voltage Y N')
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('voltage_b_n')
|
||||
->label('Voltage B N')
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('frequency')
|
||||
->label('Frequency')
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('power_factor_r')
|
||||
->label('Power Factor R')
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('power_factor_y')
|
||||
->label('Power Factor Y')
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('power_factor_b')
|
||||
->label('Power Factor B')
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('power_factor_total')
|
||||
->label('Power Factor Total')
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('created_at')
|
||||
->label('Created At')
|
||||
->alignCenter()
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
Tables\Columns\TextColumn::make('updated_at')
|
||||
->label('Updated At')
|
||||
->alignCenter()
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
Tables\Columns\TextColumn::make('deleted_at')
|
||||
->label('Deleted At')
|
||||
->alignCenter()
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
])
|
||||
->filters([
|
||||
Tables\Filters\TrashedFilter::make(),
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\ViewAction::make(),
|
||||
Tables\Actions\EditAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\BulkActionGroup::make([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
Tables\Actions\ForceDeleteBulkAction::make(),
|
||||
Tables\Actions\RestoreBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListMfmReadings::route('/'),
|
||||
'create' => Pages\CreateMfmReading::route('/create'),
|
||||
'view' => Pages\ViewMfmReading::route('/{record}'),
|
||||
'edit' => Pages\EditMfmReading::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
|
||||
public static function getEloquentQuery(): Builder
|
||||
{
|
||||
return parent::getEloquentQuery()
|
||||
->withoutGlobalScopes([
|
||||
SoftDeletingScope::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\MfmReadingResource\Pages;
|
||||
|
||||
use App\Filament\Resources\MfmReadingResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateMfmReading extends CreateRecord
|
||||
{
|
||||
protected static string $resource = MfmReadingResource::class;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\MfmReadingResource\Pages;
|
||||
|
||||
use App\Filament\Resources\MfmReadingResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditMfmReading extends EditRecord
|
||||
{
|
||||
protected static string $resource = MfmReadingResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\ViewAction::make(),
|
||||
Actions\DeleteAction::make(),
|
||||
Actions\ForceDeleteAction::make(),
|
||||
Actions\RestoreAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\MfmReadingResource\Pages;
|
||||
|
||||
use App\Filament\Resources\MfmReadingResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListMfmReadings extends ListRecords
|
||||
{
|
||||
protected static string $resource = MfmReadingResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\MfmReadingResource\Pages;
|
||||
|
||||
use App\Filament\Resources\MfmReadingResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ViewRecord;
|
||||
|
||||
class ViewMfmReading extends ViewRecord
|
||||
{
|
||||
protected static string $resource = MfmReadingResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\EditAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
125
app/Filament/Resources/ModuleListResource.php
Normal file
125
app/Filament/Resources/ModuleListResource.php
Normal file
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use App\Filament\Resources\ModuleListResource\Pages;
|
||||
use App\Filament\Resources\ModuleListResource\RelationManagers;
|
||||
use App\Models\ModuleList;
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Filament\Forms\Components\Section;
|
||||
|
||||
class ModuleListResource extends Resource
|
||||
{
|
||||
protected static ?string $model = ModuleList::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
|
||||
|
||||
protected static ?string $navigationGroup = 'Modules';
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Section::make('')
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('module_name')
|
||||
->label('Module Name')
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('dashboard_name')
|
||||
->label('DashBoard Name')
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('filter_name')
|
||||
->label('Filter Name')
|
||||
->required(),
|
||||
Forms\Components\Hidden::make('created_by')
|
||||
->label('Created By')
|
||||
->default(Filament::auth()->user()?->name),
|
||||
Forms\Components\Hidden::make('updated_by')
|
||||
->label('Updated By')
|
||||
->default(Filament::auth()->user()?->name),
|
||||
])
|
||||
->columns(3),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('id')
|
||||
->label('ID')
|
||||
->numeric()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('module_name')
|
||||
->label('Module Name')
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('dashboard_name')
|
||||
->label('DashBoard Name')
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('filter_name')
|
||||
->label('Filter Name')
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('created_at')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
Tables\Columns\TextColumn::make('updated_at')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
Tables\Columns\TextColumn::make('deleted_at')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
])
|
||||
->filters([
|
||||
Tables\Filters\TrashedFilter::make(),
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\ViewAction::make(),
|
||||
Tables\Actions\EditAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\BulkActionGroup::make([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
Tables\Actions\ForceDeleteBulkAction::make(),
|
||||
Tables\Actions\RestoreBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListModuleLists::route('/'),
|
||||
'create' => Pages\CreateModuleList::route('/create'),
|
||||
'view' => Pages\ViewModuleList::route('/{record}'),
|
||||
'edit' => Pages\EditModuleList::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
|
||||
public static function getEloquentQuery(): Builder
|
||||
{
|
||||
return parent::getEloquentQuery()
|
||||
->withoutGlobalScopes([
|
||||
SoftDeletingScope::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ModuleListResource\Pages;
|
||||
|
||||
use App\Filament\Resources\ModuleListResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateModuleList extends CreateRecord
|
||||
{
|
||||
protected static string $resource = ModuleListResource::class;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ModuleListResource\Pages;
|
||||
|
||||
use App\Filament\Resources\ModuleListResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditModuleList extends EditRecord
|
||||
{
|
||||
protected static string $resource = ModuleListResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\ViewAction::make(),
|
||||
Actions\DeleteAction::make(),
|
||||
Actions\ForceDeleteAction::make(),
|
||||
Actions\RestoreAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ModuleListResource\Pages;
|
||||
|
||||
use App\Filament\Resources\ModuleListResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListModuleLists extends ListRecords
|
||||
{
|
||||
protected static string $resource = ModuleListResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ModuleListResource\Pages;
|
||||
|
||||
use App\Filament\Resources\ModuleListResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ViewRecord;
|
||||
|
||||
class ViewModuleList extends ViewRecord
|
||||
{
|
||||
protected static string $resource = ModuleListResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\EditAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,7 @@ use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Filament\Tables\Actions\ImportAction;
|
||||
use Filament\Tables\Actions\ExportAction;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class MotorTestingMasterResource extends Resource
|
||||
{
|
||||
@@ -62,6 +63,7 @@ class MotorTestingMasterResource extends Resource
|
||||
->hintColor('danger'),
|
||||
Forms\Components\Select::make('item_id')
|
||||
->label('Item Code')
|
||||
//->relationship('item', 'name')
|
||||
->options(function (callable $get) {
|
||||
$plantId = $get('plant_id');
|
||||
if (!$plantId) {
|
||||
@@ -74,7 +76,12 @@ class MotorTestingMasterResource extends Resource
|
||||
})
|
||||
->required()
|
||||
->searchable()
|
||||
->reactive(),
|
||||
->reactive()
|
||||
->rule(function (callable $get) {
|
||||
return Rule::unique('motor_testing_masters', 'item_id')
|
||||
->where('plant_id', $get('plant_id'))
|
||||
->ignore($get('id')); // Ignore current record during updates
|
||||
}),
|
||||
Forms\Components\TimePicker::make('routine_test_time')
|
||||
->label('Routine Test Time')
|
||||
->default('00:40:00')
|
||||
|
||||
@@ -20,7 +20,6 @@ use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Filament\Forms\Components\Actions;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Tables\Actions\ExportAction;
|
||||
use Filament\Tables\Actions\ImportAction;
|
||||
use Log;
|
||||
@@ -36,8 +35,11 @@ class PalletValidationResource extends Resource
|
||||
protected static ?string $model = PalletValidation::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
|
||||
|
||||
protected static ?string $navigationGroup = 'Export Dispatch';
|
||||
|
||||
protected static ?int $navigationSort = 1;
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
|
||||
@@ -68,7 +70,7 @@ class PalletValidationResource extends Resource
|
||||
'x-on:keydown.enter.prevent' => '$wire.processPalletNo()',
|
||||
])
|
||||
->suffixAction(fn ($get,$set) =>
|
||||
Forms\Components\Actions\Action::make('addPallet')
|
||||
Forms\Components\Actions\Action::make('addPallet')
|
||||
->label('')
|
||||
->button()
|
||||
->icon('heroicon-o-plus')
|
||||
@@ -79,28 +81,23 @@ class PalletValidationResource extends Resource
|
||||
->action(function ($get, $set, $livewire) {
|
||||
$plantId = $get('plant_id');
|
||||
|
||||
$user = Filament::auth()->user();
|
||||
session(['pallet_clicked_time' => now()->toDateTimeString()]);
|
||||
|
||||
$operatorName = $user->name;
|
||||
|
||||
$clickedTime = now();
|
||||
|
||||
$created = $operatorName;
|
||||
|
||||
session(['pallet_clicked_time' => $clickedTime->toDateTimeString()]);
|
||||
|
||||
session(['pallet_created_by' => $created]);
|
||||
session(['pallet_created_by' => Filament::auth()->user()->name]);
|
||||
|
||||
$year = now()->format('y');
|
||||
$month = now()->format('m');
|
||||
$prefix = "EP-{$year}{$month}";
|
||||
$lastPallet = PalletValidation::where('pallet_number', 'like', "{$prefix}%")
|
||||
->where('plant_id', $plantId)
|
||||
->orderByDesc('pallet_number')
|
||||
->first();
|
||||
$newNumber = $lastPallet
|
||||
? str_pad(intval(substr($lastPallet->pallet_number, -3)) + 1, 3, '0', STR_PAD_LEFT)
|
||||
: '001';
|
||||
|
||||
$lastPallet = PalletValidation::where('pallet_number', 'like', "{$prefix}%")->orderByDesc('pallet_number')->first(); //->where('plant_id', $plantId)
|
||||
$newNumber = '001'; // $lastPallet ? str_pad(intval(substr($lastPallet->pallet_number, -3)) + 1, 3, '0', STR_PAD_LEFT) : '001';
|
||||
if ($lastPallet) {
|
||||
$serialPart = substr($lastPallet->pallet_number, strlen($prefix));
|
||||
// OR
|
||||
// $serialPart = str_replace($prefix, '', $lastPallet->pallet_number);
|
||||
$newNumber = str_pad(intval($serialPart) + 1, strlen($serialPart), '0', STR_PAD_LEFT);
|
||||
}
|
||||
|
||||
$newPalletNumber = "{$prefix}{$newNumber}";
|
||||
|
||||
$set('pallet_number', $newPalletNumber);
|
||||
@@ -114,6 +111,7 @@ class PalletValidationResource extends Resource
|
||||
Forms\Components\TextInput::make('serial_number')
|
||||
->label('Scan Serial No')
|
||||
->reactive()
|
||||
->minLength(9)
|
||||
->readOnly(fn (callable $get) => !$get('pallet_number') || $get('removeSno_number'))
|
||||
->extraAttributes([
|
||||
'x-on:keydown.enter.prevent' => '$wire.processPalletSNo()',
|
||||
@@ -121,6 +119,7 @@ class PalletValidationResource extends Resource
|
||||
Forms\Components\TextInput::make('removeSno_number')
|
||||
->label('Remove Serial No')
|
||||
->reactive()
|
||||
->minLength(9)
|
||||
->readOnly(fn (callable $get) => !$get('pallet_number') || $get('serial_number'))
|
||||
->extraAttributes([
|
||||
'x-data' => '{ value: "" }',
|
||||
@@ -196,27 +195,22 @@ class PalletValidationResource extends Resource
|
||||
}),
|
||||
Tables\Columns\TextColumn::make('plant.name')
|
||||
->label('Plant')
|
||||
->searchable()
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('pallet_number')
|
||||
->label('Pallet Number')
|
||||
->searchable()
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('serial_number')
|
||||
->label('Serial Number')
|
||||
->searchable()
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('pallet_status')
|
||||
->label('Pallet Status')
|
||||
->searchable()
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('locator_number')
|
||||
->label('Locator Number')
|
||||
->searchable()
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('locator_quantity')
|
||||
@@ -227,24 +221,24 @@ class PalletValidationResource extends Resource
|
||||
->label('Created By')
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('scanned_by')
|
||||
->label('Scanned By')
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('updated_by')
|
||||
->label('Updated By')
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('created_at')
|
||||
->dateTime()
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('updated_at')
|
||||
Tables\Columns\TextColumn::make('scanned_by')
|
||||
->label('Scanned By')
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('scanned_at')
|
||||
->dateTime()
|
||||
->alignCenter()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
Tables\Columns\TextColumn::make('scanned_at')
|
||||
Tables\Columns\TextColumn::make('updated_by')
|
||||
->label('Updated By')
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('updated_at')
|
||||
->dateTime()
|
||||
->alignCenter()
|
||||
->sortable()
|
||||
@@ -261,218 +255,218 @@ class PalletValidationResource extends Resource
|
||||
->filters([
|
||||
Tables\Filters\TrashedFilter::make(),
|
||||
Filter::make('advanced_filters')
|
||||
->label('Advanced Filters')
|
||||
->form([
|
||||
Select::make('Plant')
|
||||
->label('Select Plant')
|
||||
->nullable()
|
||||
->options(function () {
|
||||
return Plant::pluck('name', 'id');
|
||||
})
|
||||
->reactive()
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get): void {
|
||||
$set('pallet_number', null);
|
||||
$set('serial_number', null);
|
||||
$set('pallet_status', null);
|
||||
$set('locator_number', null);
|
||||
$set('locator_quantity', null);
|
||||
$set('created_from', null);
|
||||
$set('created_to', null);
|
||||
$set('created_by', null);
|
||||
$set('scanned_from', null);
|
||||
$set('scanned_to', null);
|
||||
$set('scanned_by', null);
|
||||
}),
|
||||
Select::make('pallet_number')
|
||||
->label('Pallet Number')
|
||||
->options(function (callable $get) {
|
||||
$plantId = $get('Plant');
|
||||
if (!$plantId) {
|
||||
return [];
|
||||
}
|
||||
return PalletValidation::where('plant_id', $plantId)
|
||||
->whereNotNull('pallet_number')
|
||||
->where('pallet_number','!=', '')
|
||||
->orderBy('pallet_number', 'asc')
|
||||
->get()
|
||||
->unique('pallet_number')
|
||||
->pluck('pallet_number', 'pallet_number')
|
||||
->toArray();
|
||||
})
|
||||
->searchable()
|
||||
->reactive(),
|
||||
TextInput::make('serial_number')
|
||||
->label('Serial Number')
|
||||
->placeholder(placeholder: 'Enter Serial Number'),
|
||||
Select::make('pallet_status')
|
||||
->label('Pallet Status')
|
||||
->options([
|
||||
'Completed' => 'Completed',
|
||||
]),
|
||||
Select::make('locator_number')
|
||||
->label('Locator Number')
|
||||
->options(function (callable $get) {
|
||||
$plantId = $get('Plant');
|
||||
if (!$plantId) {
|
||||
return [];
|
||||
}
|
||||
return PalletValidation::where('plant_id', $plantId)
|
||||
->whereNotNull('locator_number')
|
||||
->where('locator_number','!=', '')
|
||||
->orderBy('locator_number', 'asc')
|
||||
->get()
|
||||
->unique('locator_number')
|
||||
->pluck('locator_number', 'locator_number')
|
||||
->toArray();
|
||||
})
|
||||
->searchable()
|
||||
->reactive(),
|
||||
Select::make('locator_quantity')
|
||||
->label('Locator Quantity')
|
||||
->options([
|
||||
0 => 0,
|
||||
1 => '1',
|
||||
2 => '2',
|
||||
])
|
||||
->reactive(),
|
||||
DateTimePicker::make(name: 'created_from')
|
||||
->label('Created From')
|
||||
->placeholder(placeholder: 'Select From DateTime')
|
||||
->reactive()
|
||||
->native(false),
|
||||
DateTimePicker::make('created_to')
|
||||
->label('Created To')
|
||||
->placeholder(placeholder: 'Select To DateTime')
|
||||
->reactive()
|
||||
->native(false),
|
||||
TextInput::make('created_by')
|
||||
->label('Created By')
|
||||
->placeholder(placeholder: 'Enter Created By'),
|
||||
DateTimePicker::make(name: 'scanned_from')
|
||||
->label('Scanned From')
|
||||
->placeholder(placeholder: 'Select From DateTime')
|
||||
->reactive()
|
||||
->native(false),
|
||||
DateTimePicker::make('scanned_to')
|
||||
->label('Scanned To')
|
||||
->placeholder(placeholder: 'Select To DateTime')
|
||||
->reactive()
|
||||
->native(false),
|
||||
TextInput::make('scanned_by')
|
||||
->label('Scanned By')
|
||||
->placeholder(placeholder: 'Enter Scanned By'),
|
||||
])
|
||||
->query(function ($query, array $data) {
|
||||
// Hide all records initially if no filters are applied
|
||||
if (empty($data['Plant']) && empty($data['pallet_number']) && empty($data['serial_number']) && empty($data['pallet_status']) && empty($data['locator_number']) && empty($data['locator_quantity']) && empty($data['created_from']) && empty($data['created_to']) && empty($data['created_by']) && empty($data['scanned_from']) && empty($data['scanned_to']) && empty($data['scanned_by'])) {
|
||||
return $query->whereRaw('1 = 0');
|
||||
}
|
||||
->label('Advanced Filters')
|
||||
->form([
|
||||
Select::make('Plant')
|
||||
->label('Select Plant')
|
||||
->nullable()
|
||||
->options(function () {
|
||||
return Plant::pluck('name', 'id');
|
||||
})
|
||||
->reactive()
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get): void {
|
||||
$set('pallet_number', null);
|
||||
$set('serial_number', null);
|
||||
$set('pallet_status', null);
|
||||
$set('locator_number', null);
|
||||
$set('locator_quantity', null);
|
||||
$set('created_from', null);
|
||||
$set('created_to', null);
|
||||
$set('created_by', null);
|
||||
$set('scanned_from', null);
|
||||
$set('scanned_to', null);
|
||||
$set('scanned_by', null);
|
||||
}),
|
||||
Select::make('pallet_number')
|
||||
->label('Pallet Number')
|
||||
->options(function (callable $get) {
|
||||
$plantId = $get('Plant');
|
||||
if (!$plantId) {
|
||||
return [];
|
||||
}
|
||||
return PalletValidation::where('plant_id', $plantId)
|
||||
->whereNotNull('pallet_number')
|
||||
->where('pallet_number','!=', '')
|
||||
->orderBy('pallet_number', 'asc')
|
||||
->get()
|
||||
->unique('pallet_number')
|
||||
->pluck('pallet_number', 'pallet_number')
|
||||
->toArray();
|
||||
})
|
||||
->searchable()
|
||||
->reactive(),
|
||||
TextInput::make('serial_number')
|
||||
->label('Serial Number')
|
||||
->placeholder(placeholder: 'Enter Serial Number'),
|
||||
Select::make('pallet_status')
|
||||
->label('Pallet Status')
|
||||
->options([
|
||||
'Completed' => 'Completed',
|
||||
]),
|
||||
Select::make('locator_number')
|
||||
->label('Locator Number')
|
||||
->options(function (callable $get) {
|
||||
$plantId = $get('Plant');
|
||||
if (!$plantId) {
|
||||
return [];
|
||||
}
|
||||
return PalletValidation::where('plant_id', $plantId)
|
||||
->whereNotNull('locator_number')
|
||||
->where('locator_number','!=', '')
|
||||
->orderBy('locator_number', 'asc')
|
||||
->get()
|
||||
->unique('locator_number')
|
||||
->pluck('locator_number', 'locator_number')
|
||||
->toArray();
|
||||
})
|
||||
->searchable()
|
||||
->reactive(),
|
||||
Select::make('locator_quantity')
|
||||
->label('Locator Quantity')
|
||||
->options([
|
||||
0 => 0,
|
||||
1 => 1,
|
||||
2 => 2,
|
||||
])
|
||||
->reactive(),
|
||||
DateTimePicker::make(name: 'created_from')
|
||||
->label('Created From')
|
||||
->placeholder(placeholder: 'Select From DateTime')
|
||||
->reactive()
|
||||
->native(false),
|
||||
DateTimePicker::make('created_to')
|
||||
->label('Created To')
|
||||
->placeholder(placeholder: 'Select To DateTime')
|
||||
->reactive()
|
||||
->native(false),
|
||||
TextInput::make('created_by')
|
||||
->label('Created By')
|
||||
->placeholder(placeholder: 'Enter Created By'),
|
||||
DateTimePicker::make(name: 'scanned_from')
|
||||
->label('Scanned From')
|
||||
->placeholder(placeholder: 'Select From DateTime')
|
||||
->reactive()
|
||||
->native(false),
|
||||
DateTimePicker::make('scanned_to')
|
||||
->label('Scanned To')
|
||||
->placeholder(placeholder: 'Select To DateTime')
|
||||
->reactive()
|
||||
->native(false),
|
||||
TextInput::make('scanned_by')
|
||||
->label('Scanned By')
|
||||
->placeholder(placeholder: 'Enter Scanned By'),
|
||||
])
|
||||
->query(function ($query, array $data) {
|
||||
// Hide all records initially if no filters are applied
|
||||
if (empty($data['Plant']) && empty($data['pallet_number']) && empty($data['serial_number']) && empty($data['pallet_status']) && empty($data['locator_number']) && $data['locator_quantity'] == null && empty($data['created_from']) && empty($data['created_to']) && empty($data['created_by']) && empty($data['scanned_from']) && empty($data['scanned_to']) && empty($data['scanned_by'])) {
|
||||
return $query->whereRaw('1 = 0');
|
||||
}
|
||||
|
||||
if (!empty($data['Plant'])) { //$plant = $data['Plant'] ?? null
|
||||
$query->where('plant_id', $data['Plant']);
|
||||
}
|
||||
if (!empty($data['Plant'])) { //$plant = $data['Plant'] ?? null
|
||||
$query->where('plant_id', $data['Plant']);
|
||||
}
|
||||
|
||||
if (!empty($data['pallet_number'])) {
|
||||
$query->where('pallet_number', $data['pallet_number']);
|
||||
}
|
||||
if (!empty($data['pallet_number'])) {
|
||||
$query->where('pallet_number', $data['pallet_number']);
|
||||
}
|
||||
|
||||
if (!empty($data['serial_number'])) {
|
||||
$query->where('serial_number', $data['serial_number']);
|
||||
}
|
||||
if (!empty($data['serial_number'])) {
|
||||
$query->where('serial_number', $data['serial_number']);
|
||||
}
|
||||
|
||||
if (!empty($data['pallet_status'])) {
|
||||
$query->where('pallet_status', $data['pallet_status']);
|
||||
}
|
||||
if (!empty($data['pallet_status'])) {
|
||||
$query->where('pallet_status', $data['pallet_status']);
|
||||
}
|
||||
|
||||
if (!empty($data['locator_number'])) {
|
||||
$query->where('locator_number', $data['locator_number']);
|
||||
}
|
||||
if (!empty($data['locator_number'])) {
|
||||
$query->where('locator_number', $data['locator_number']);
|
||||
}
|
||||
|
||||
// if (!empty($data['locator_quantity'])) {
|
||||
// $query->where('locator_quantity', $data['locator_quantity']);
|
||||
// }
|
||||
// if (!empty($data['locator_quantity'])) {
|
||||
// $query->where('locator_quantity', $data['locator_quantity']);
|
||||
// }
|
||||
|
||||
if (isset($data['locator_quantity']) && $data['locator_quantity'] != '') {
|
||||
$query->where('locator_quantity', (int)$data['locator_quantity']);
|
||||
}
|
||||
if ($data['locator_quantity'] != null && $data['locator_quantity'] != '') { //isset($data['locator_quantity']) &&
|
||||
$query->where('locator_quantity', $data['locator_quantity']);//(int)
|
||||
}
|
||||
|
||||
if (!empty($data['created_from'])) {
|
||||
$query->where('created_at', '>=', $data['created_from']);
|
||||
}
|
||||
if (!empty($data['created_from'])) {
|
||||
$query->where('created_at', '>=', $data['created_from']);
|
||||
}
|
||||
|
||||
if (!empty($data['created_to'])) {
|
||||
$query->where('created_at', '<=', $data['created_to']);
|
||||
}
|
||||
if (!empty($data['created_to'])) {
|
||||
$query->where('created_at', '<=', $data['created_to']);
|
||||
}
|
||||
|
||||
if (!empty($data['created_by'])) {
|
||||
$query->where('created_by', $data['created_by']);
|
||||
}
|
||||
if (!empty($data['created_by'])) {
|
||||
$query->where('created_by', $data['created_by']);
|
||||
}
|
||||
|
||||
if (!empty($data['scanned_from'])) {
|
||||
$query->where('scanned_at', '>=', $data['scanned_from']);
|
||||
}
|
||||
if (!empty($data['scanned_from'])) {
|
||||
$query->where('scanned_at', '>=', $data['scanned_from']);
|
||||
}
|
||||
|
||||
if (!empty($data['scanned_to'])) {
|
||||
$query->where('scanned_at', '<=', $data['scanned_to']);
|
||||
}
|
||||
if (!empty($data['scanned_to'])) {
|
||||
$query->where('scanned_at', '<=', $data['scanned_to']);
|
||||
}
|
||||
|
||||
if (!empty($data['scanned_by'])) {
|
||||
$query->where('scanned_by', $data['scanned_by']);
|
||||
}
|
||||
})
|
||||
->indicateUsing(function (array $data) {
|
||||
$indicators = [];
|
||||
if (!empty($data['scanned_by'])) {
|
||||
$query->where('scanned_by', $data['scanned_by']);
|
||||
}
|
||||
})
|
||||
->indicateUsing(function (array $data) {
|
||||
$indicators = [];
|
||||
|
||||
if (!empty($data['Plant'])) {
|
||||
$indicators[] = 'Plant: ' . Plant::where('id', $data['Plant'])->value('name');
|
||||
}
|
||||
if (!empty($data['Plant'])) {
|
||||
$indicators[] = 'Plant: ' . Plant::where('id', $data['Plant'])->value('name');
|
||||
}
|
||||
|
||||
if (!empty($data['pallet_number'])) {
|
||||
$indicators[] = 'Pallet Number: ' . $data['pallet_number'];
|
||||
}
|
||||
if (!empty($data['pallet_number'])) {
|
||||
$indicators[] = 'Pallet Number: ' . $data['pallet_number'];
|
||||
}
|
||||
|
||||
if (!empty($data['serial_number'])) {
|
||||
$indicators[] = 'Serial Number: ' . $data['serial_number'];
|
||||
}
|
||||
if (!empty($data['serial_number'])) {
|
||||
$indicators[] = 'Serial Number: ' . $data['serial_number'];
|
||||
}
|
||||
|
||||
if (!empty($data['pallet_status'])) {
|
||||
$indicators[] = 'Pallet Status: ' . $data['pallet_status'];
|
||||
}
|
||||
if (!empty($data['pallet_status'])) {
|
||||
$indicators[] = 'Pallet Status: ' . $data['pallet_status'];
|
||||
}
|
||||
|
||||
if (!empty($data['locator_number'])) {
|
||||
$indicators[] = 'Locator Number: ' . $data['locator_number'];
|
||||
}
|
||||
if (!empty($data['locator_number'])) {
|
||||
$indicators[] = 'Locator Number: ' . $data['locator_number'];
|
||||
}
|
||||
|
||||
// if (!empty($data['locator_quantity'])) {
|
||||
// $indicators[] = 'Locator Quantity: ' . $data['locator_quantity'];
|
||||
// }
|
||||
if (isset($data['locator_quantity']) && $data['locator_quantity'] !== '') {
|
||||
$indicators[] = 'Locator Quantity: ' . $data['locator_quantity'];
|
||||
}
|
||||
// if (!empty($data['locator_quantity'])) {
|
||||
// $indicators[] = 'Locator Quantity: ' . $data['locator_quantity'];
|
||||
// }
|
||||
if ($data['locator_quantity'] != null && $data['locator_quantity'] != '') { //isset($data['locator_quantity']) &&
|
||||
$indicators[] = 'Locator Quantity: ' . $data['locator_quantity'];
|
||||
}
|
||||
|
||||
if (!empty($data['created_from'])) {
|
||||
$indicators[] = 'From: ' . $data['created_from'];
|
||||
}
|
||||
if (!empty($data['created_from'])) {
|
||||
$indicators[] = 'From: ' . $data['created_from'];
|
||||
}
|
||||
|
||||
if (!empty($data['created_to'])) {
|
||||
$indicators[] = 'To: ' . $data['created_to'];
|
||||
}
|
||||
if (!empty($data['created_to'])) {
|
||||
$indicators[] = 'To: ' . $data['created_to'];
|
||||
}
|
||||
|
||||
if (!empty($data['created_by'])) {
|
||||
$indicators[] = 'Created By: ' . $data['created_by'];
|
||||
}
|
||||
if (!empty($data['scanned_from'])) {
|
||||
$indicators[] = 'Scanned From: ' . $data['scanned_from'];
|
||||
}
|
||||
if (!empty($data['scanned_to'])) {
|
||||
$indicators[] = 'Scanned To: ' . $data['scanned_to'];
|
||||
}
|
||||
if (!empty($data['scanned_by'])) {
|
||||
$indicators[] = 'Scanned By: ' . $data['scanned_by'];
|
||||
}
|
||||
if (!empty($data['created_by'])) {
|
||||
$indicators[] = 'Created By: ' . $data['created_by'];
|
||||
}
|
||||
if (!empty($data['scanned_from'])) {
|
||||
$indicators[] = 'Scanned From: ' . $data['scanned_from'];
|
||||
}
|
||||
if (!empty($data['scanned_to'])) {
|
||||
$indicators[] = 'Scanned To: ' . $data['scanned_to'];
|
||||
}
|
||||
if (!empty($data['scanned_by'])) {
|
||||
$indicators[] = 'Scanned By: ' . $data['scanned_by'];
|
||||
}
|
||||
|
||||
return $indicators;
|
||||
})
|
||||
return $indicators;
|
||||
})
|
||||
])
|
||||
->filtersFormMaxHeight('280px')
|
||||
->actions([
|
||||
@@ -486,14 +480,64 @@ class PalletValidationResource extends Resource
|
||||
Tables\Actions\RestoreBulkAction::make(),
|
||||
]),
|
||||
])
|
||||
// ->headerActions([
|
||||
->headerActions([
|
||||
Tables\Actions\Action::make('reprint_pallet')
|
||||
->label('Re-Print Pallet QR')
|
||||
->form([
|
||||
Forms\Components\Section::make()
|
||||
->schema([
|
||||
Forms\Components\Select::make('plant')
|
||||
->label('Select Plant')
|
||||
->options(Plant::pluck('name', 'id')->toArray())
|
||||
->required()
|
||||
->reactive()
|
||||
->columnSpan(2),
|
||||
Forms\Components\Select::make('pallet_list')
|
||||
->label('Select Pallet')
|
||||
->searchable()
|
||||
->required()
|
||||
->reactive()
|
||||
->columnSpan(1)
|
||||
->options(function (callable $get) {
|
||||
$plantId = $get('plant');
|
||||
|
||||
if (!$plantId) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return PalletValidation::query()
|
||||
->where('plant_id', $plantId)
|
||||
->whereNotNull('pallet_number')
|
||||
->where('pallet_number', '!=', '')
|
||||
->select('pallet_number')
|
||||
->distinct()
|
||||
->orderBy('pallet_number')
|
||||
->pluck('pallet_number', 'pallet_number')
|
||||
->toArray();
|
||||
}),
|
||||
])
|
||||
->columns(['default' => 1, 'sm' => 3]),
|
||||
])
|
||||
->action(function (array $data) {
|
||||
$selectedPalletNumber = $data['pallet_list'];
|
||||
return redirect()->route('download-qr-pdf', ['palletNo' => $selectedPalletNumber]);
|
||||
|
||||
})
|
||||
->visible(function() {
|
||||
return Filament::auth()->user()->can('view reprint pallet number');
|
||||
}),
|
||||
ImportAction::make()
|
||||
->importer(PalletValidationImporter::class)
|
||||
->label('Import Pallet')
|
||||
->color('warning')
|
||||
->visible(function() {
|
||||
return Filament::auth()->user()->can('view import pallet validation');
|
||||
}),
|
||||
ExportAction::make()
|
||||
->exporter(PalletValidationExporter::class)
|
||||
->label('Export Pallet')
|
||||
->color('warning')
|
||||
->visible(function() {
|
||||
return Filament::auth()->user()->can('view export pallet validation');
|
||||
}),
|
||||
@@ -507,6 +551,11 @@ class PalletValidationResource extends Resource
|
||||
];
|
||||
}
|
||||
|
||||
public static function getNavigationLabel(): string
|
||||
{
|
||||
return 'Scan Pallet';
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
|
||||
@@ -57,13 +57,14 @@ class CreatePalletValidation extends CreateRecord
|
||||
|
||||
$clickedBy = session('pallet_created_by');
|
||||
|
||||
|
||||
if(!$palletNumber)
|
||||
if (!$palletNumber)
|
||||
{
|
||||
Notification::make()
|
||||
->title('Pallet number cannot be empty')
|
||||
->danger()
|
||||
->send();
|
||||
->title("Pallet number can't be empty")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->form->fill([
|
||||
'serial_number' => null,
|
||||
'plant_id' => $plantId,
|
||||
@@ -76,18 +77,17 @@ class CreatePalletValidation extends CreateRecord
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
$count = PalletValidation::where('plant_id', $plantId)
|
||||
->where('pallet_number', $palletNumber)
|
||||
->count('pallet_number');
|
||||
|
||||
|
||||
if(!$serialNumber)
|
||||
if (!$serialNumber)
|
||||
{
|
||||
Notification::make()
|
||||
->title('Serial number cannot be empty')
|
||||
->danger()
|
||||
->send();
|
||||
->title('Serial number is required to add.')
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $palletNumber, $plantId);
|
||||
$this->form->fill([
|
||||
'serial_number' => null,
|
||||
@@ -100,12 +100,14 @@ class CreatePalletValidation extends CreateRecord
|
||||
]);
|
||||
return;
|
||||
}
|
||||
if(strlen($serialNumber) < 13)
|
||||
else if (strlen($serialNumber) < 9 || strlen($serialNumber) > 20)
|
||||
{
|
||||
Notification::make()
|
||||
->title('Serial number should contain minimum 13 digits.')
|
||||
->danger()
|
||||
->send();
|
||||
->title('Serial number should contain minimum 9 digits and maximum 20 digits.')
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $palletNumber, $plantId);
|
||||
$this->form->fill([
|
||||
'serial_number' => null,
|
||||
@@ -118,12 +120,14 @@ class CreatePalletValidation extends CreateRecord
|
||||
]);
|
||||
return;
|
||||
}
|
||||
if (!ctype_alnum($serialNumber))
|
||||
else if (!ctype_alnum($serialNumber))
|
||||
{
|
||||
Notification::make()
|
||||
->title('Serial number must contain alpha-numeric values only.')
|
||||
->danger()
|
||||
->send();
|
||||
->title('Serial number must contain alpha-numeric values only.')
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $palletNumber, $plantId);
|
||||
$this->form->fill([
|
||||
'serial_number' => null,
|
||||
@@ -143,12 +147,14 @@ class CreatePalletValidation extends CreateRecord
|
||||
->first();
|
||||
|
||||
$invoiceNumber = $existInvoiceSno?->invoice_number;
|
||||
if($existInvoiceSno)
|
||||
if ($existInvoiceSno)
|
||||
{
|
||||
Notification::make()
|
||||
->title("Scanned serial number '{$serialNumber}' already completed the scanning process and exist in invoice number : {$invoiceNumber}.<br>Scan the new serial number to add!")
|
||||
->danger()
|
||||
->send();
|
||||
->title("Scanned serial number '{$serialNumber}' already completed the scanning process and exist in invoice number : {$invoiceNumber}.<br>Scan the new serial number to add!")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $palletNumber, $plantId);
|
||||
$this->form->fill([
|
||||
'serial_number' => null,
|
||||
@@ -173,6 +179,7 @@ class CreatePalletValidation extends CreateRecord
|
||||
// Notification::make()
|
||||
// ->title("Scanned serial number '{$serialNumber}' exists in pallet table .<br>scan the valid serial number to proceed...")
|
||||
// ->danger()
|
||||
// ->duration(5000)
|
||||
// ->send();
|
||||
// $this->form->fill([
|
||||
// 'serial_number' => null,
|
||||
@@ -191,6 +198,7 @@ class CreatePalletValidation extends CreateRecord
|
||||
Notification::make()
|
||||
->title("Scanned serial number '{$serialNumber}' is already exists in pallet number '{$palletNumber}'.<br>Scan the new serial number to proceed...")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
}
|
||||
else if ($existingRecord && $existingRecord->pallet_number && $existingRecord->pallet_number != $palletNumber)
|
||||
@@ -198,6 +206,7 @@ class CreatePalletValidation extends CreateRecord
|
||||
Notification::make()
|
||||
->title("Scanned serial number '{$serialNumber}' already exists in pallet number '{$existingRecord->pallet_number}'.<br>Scan the new serial number to proceed...")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
}
|
||||
else if ($existingRecord && $existingRecord->locator_number)
|
||||
@@ -205,6 +214,7 @@ class CreatePalletValidation extends CreateRecord
|
||||
Notification::make()
|
||||
->title("Scanned serial number '{$serialNumber}' is already exists in locator number '{$existingRecord->locator_number}'.<br>Scan the new serial number to proceed...")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
}
|
||||
$this->dispatch('loadData', $palletNumber, $plantId);
|
||||
@@ -248,15 +258,17 @@ class CreatePalletValidation extends CreateRecord
|
||||
|
||||
if ($record)
|
||||
{
|
||||
Notification::make()
|
||||
->title("Scanned serial number : '{$serialNumber}' successfully inserted into pallet table!<br>Scan the next new serial number to proceed...")
|
||||
->success()
|
||||
->send();
|
||||
// Notification::make()
|
||||
// ->title("Scanned serial number '{$serialNumber}' successfully inserted into pallet table!<br>Scan the next new serial number to proceed...")
|
||||
// ->success()
|
||||
// ->duration(600)
|
||||
// ->send();
|
||||
|
||||
$this->snoCount = PalletValidation::where('plant_id', $plantId)
|
||||
->where('pallet_number', $palletNumber)
|
||||
->count();
|
||||
|
||||
$this->dispatch('loadData', $palletNumber, $plantId);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
'pallet_number' => $palletNumber,
|
||||
@@ -266,34 +278,36 @@ class CreatePalletValidation extends CreateRecord
|
||||
'created_by' => $operatorName,
|
||||
'scanned_by' => $operatorName,
|
||||
]);
|
||||
|
||||
$this->dispatch('loadData', $palletNumber, $plantId);
|
||||
}
|
||||
else
|
||||
{
|
||||
Notification::make()
|
||||
->title('Pallet validation not inserted.')
|
||||
->title("Failed to insert scanned serial number '$serialNumber' into pallet table!")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
$this->dispatch('loadData', $palletNumber, $plantId);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
'pallet_number' => $palletNumber,
|
||||
'serial_number' => null,
|
||||
'pending_pallet_list' => $pendingPallet,
|
||||
'Sno_quantity' => $count,
|
||||
'scanned_by' => $operatorName,
|
||||
]);
|
||||
return;
|
||||
|
||||
$this->dispatch('loadData', $palletNumber, $plantId);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
'pallet_number' => $palletNumber,
|
||||
'serial_number' => null,
|
||||
'pending_pallet_list' => $pendingPallet,
|
||||
'Sno_quantity' => $count,
|
||||
'scanned_by' => $operatorName,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
Notification::make()
|
||||
->title('Error: Pallet validation not inserted.')
|
||||
->body("Something went wrong while inserting serial number : '{$serialNumber}' into pallet table!\nScan the new serial number to proceed...")
|
||||
->title('Error: Serial not inserted.')
|
||||
->body("Something went wrong while inserting serial number '{$serialNumber}' into pallet table!\nScan the new serial number to proceed...")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $palletNumber, $plantId);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
@@ -362,12 +376,14 @@ class CreatePalletValidation extends CreateRecord
|
||||
->where('plant_id', $plantId)
|
||||
->first();
|
||||
|
||||
if(!$palletExist)
|
||||
if (!$palletExist)
|
||||
{
|
||||
Notification::make()
|
||||
->title("Pallet number '$palletNumber' does not have serial numbers to save!<br>Add the valid serial number into pallet number to proceed...")
|
||||
->danger()
|
||||
->send();
|
||||
->title("Pallet number '$palletNumber' does not have serial numbers to save!<br>Add the valid serial number into pallet number to proceed...")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $palletNumber, $plantId);
|
||||
$this->form->fill([
|
||||
'serial_number' => null,
|
||||
@@ -391,7 +407,9 @@ class CreatePalletValidation extends CreateRecord
|
||||
Notification::make()
|
||||
->title("Pallet number '$palletNumber' already completed the master packing!<br>Generate the new pallet number or choose from pending pallet list!")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', '', $plantId);
|
||||
$this->form->fill([
|
||||
'serial_number' => null,
|
||||
@@ -405,9 +423,9 @@ class CreatePalletValidation extends CreateRecord
|
||||
return;
|
||||
}
|
||||
|
||||
$count = PalletValidation::where('plant_id', $plantId)
|
||||
->where('pallet_number', $palletNumber)
|
||||
->count('pallet_number');
|
||||
// $count = PalletValidation::where('plant_id', $plantId)
|
||||
// ->where('pallet_number', $palletNumber)
|
||||
// ->count('pallet_number');
|
||||
|
||||
if (!$isCompleted)
|
||||
{
|
||||
@@ -420,7 +438,12 @@ class CreatePalletValidation extends CreateRecord
|
||||
|
||||
if ($updated > 0)
|
||||
{
|
||||
Notification::make()->title("Pallet number '$palletNumber' records saved successfully!")->success()->send();
|
||||
Notification::make()
|
||||
->title("Pallet number '$palletNumber' records saved successfully!")
|
||||
->success()
|
||||
->duration(800)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', '', $plantId);
|
||||
$this->form->fill([
|
||||
'serial_number' => null,
|
||||
@@ -446,7 +469,12 @@ class CreatePalletValidation extends CreateRecord
|
||||
|
||||
if ($updated > 0)
|
||||
{
|
||||
Notification::make()->title("Pallet number '$palletNumber' completed the master packing successfully!")->success()->send();
|
||||
Notification::make()
|
||||
->title("Pallet number '$palletNumber' completed the master packing successfully!")
|
||||
->success()
|
||||
->duration(800)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', '', $plantId);
|
||||
$this->form->fill([
|
||||
'serial_number' => null,
|
||||
@@ -487,6 +515,7 @@ class CreatePalletValidation extends CreateRecord
|
||||
Notification::make()
|
||||
->title('Pallet number is required to remove.')
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
return;
|
||||
}
|
||||
@@ -501,7 +530,9 @@ class CreatePalletValidation extends CreateRecord
|
||||
Notification::make()
|
||||
->title('Serial number is required to remove.')
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $palletNumber, $plantId);
|
||||
$this->form->fill([
|
||||
'serial_number' => null,
|
||||
@@ -514,12 +545,14 @@ class CreatePalletValidation extends CreateRecord
|
||||
]);
|
||||
return;
|
||||
}
|
||||
if(strlen($serialNumber) < 13)
|
||||
else if (strlen($serialNumber) < 9 || strlen($serialNumber) > 20)
|
||||
{
|
||||
Notification::make()
|
||||
->title('Serial number should contain minimum 13 digits.')
|
||||
->danger()
|
||||
->send();
|
||||
->title('Serial number should contain minimum 9 digits and maximum 20 digits.')
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $palletNumber, $plantId);
|
||||
$this->form->fill([
|
||||
'serial_number' => null,
|
||||
@@ -535,9 +568,11 @@ class CreatePalletValidation extends CreateRecord
|
||||
else if (!ctype_alnum($serialNumber))
|
||||
{
|
||||
Notification::make()
|
||||
->title('Serial number must contain alpha-numeric values only.')
|
||||
->danger()
|
||||
->send();
|
||||
->title('Serial number must contain alpha-numeric values only.')
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $palletNumber, $plantId);
|
||||
$this->form->fill([
|
||||
'serial_number' => null,
|
||||
@@ -556,12 +591,14 @@ class CreatePalletValidation extends CreateRecord
|
||||
->where('scanned_status', '=', 'Scanned')
|
||||
->first();
|
||||
|
||||
if($invoiceExist)
|
||||
if ($invoiceExist)
|
||||
{
|
||||
Notification::make()
|
||||
->title("Scanned serial number '{$serialNumber}' already completed the scanning process and exist in invoice number : '{$invoiceExist->invoice_number}'.<br>Scan the valid exist serial number to remove!")
|
||||
->danger()
|
||||
->send();
|
||||
->title("Scanned serial number '{$serialNumber}' already completed the scanning process and exist in invoice number '{$invoiceExist->invoice_number}'.<br>Scan the valid exist serial number to remove!")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $palletNumber, $plantId);
|
||||
$this->form->fill([
|
||||
'serial_number' => null,
|
||||
@@ -578,12 +615,14 @@ class CreatePalletValidation extends CreateRecord
|
||||
$serialexist = PalletValidation::where('plant_id', $plantId)
|
||||
->where('serial_number', $serialNumber)
|
||||
->first();
|
||||
if(!$serialexist)
|
||||
if (!$serialexist)
|
||||
{
|
||||
Notification::make()
|
||||
->title('Serial number not exists in pallet table.')
|
||||
->danger()
|
||||
->send();
|
||||
->title('Serial number not exists in pallet table.')
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $palletNumber, $plantId);
|
||||
$this->form->fill([
|
||||
'serial_number' => null,
|
||||
@@ -603,12 +642,14 @@ class CreatePalletValidation extends CreateRecord
|
||||
->where('pallet_number', '!=', null)
|
||||
->first();
|
||||
|
||||
if($palletExist && $palletExist->pallet_number != $palletNumber)
|
||||
if ($palletExist && $palletExist->pallet_number != $palletNumber)
|
||||
{
|
||||
Notification::make()
|
||||
->title("Scanned serial number exist in pallet number '$palletExist->pallet_number'.<br>Scan the valid exist serial number to remove!")
|
||||
->danger()
|
||||
->send();
|
||||
->title("Scanned serial number exist in pallet number '$palletExist->pallet_number'.<br>Scan the valid exist serial number to remove!")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $palletNumber, $plantId);
|
||||
$this->form->fill([
|
||||
'serial_number' => null,
|
||||
@@ -628,12 +669,14 @@ class CreatePalletValidation extends CreateRecord
|
||||
->where('locator_number', '!=', null)
|
||||
->first();
|
||||
|
||||
if($locatorExist && $locatorExist->locator_number)
|
||||
if ($locatorExist && $locatorExist->locator_number)
|
||||
{
|
||||
Notification::make()
|
||||
->title("Scanned serial number exist in locator number '$locatorExist->locator_number'.<br>Scan the valid exist serial number to remove!")
|
||||
->danger()
|
||||
->send();
|
||||
->title("Scanned serial number exist in locator number '$locatorExist->locator_number'.<br>Scan the valid exist serial number to remove!")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $palletNumber, $plantId);
|
||||
$this->form->fill([
|
||||
'serial_number' => null,
|
||||
@@ -655,10 +698,11 @@ class CreatePalletValidation extends CreateRecord
|
||||
|
||||
if ($deleted)
|
||||
{
|
||||
Notification::make()
|
||||
->title("Scanned serial number : '$serialNumber' successfully removed from pallet table!<br>Scan the next exist serial number to remove...")
|
||||
->success()
|
||||
->send();
|
||||
// Notification::make()
|
||||
// ->title("Scanned serial number '$serialNumber' successfully removed from pallet table!<br>Scan the next exist serial number to remove...")
|
||||
// ->success()
|
||||
// ->duration(600)
|
||||
// ->send();
|
||||
|
||||
$this->snoCount = PalletValidation::where('plant_id', $plantId)
|
||||
->where('pallet_number', $palletNumber)
|
||||
@@ -679,24 +723,24 @@ class CreatePalletValidation extends CreateRecord
|
||||
else
|
||||
{
|
||||
Notification::make()
|
||||
->title('Failed to delete serial number.')
|
||||
->title("Failed to remove scanned serial number '$serialNumber' from pallet table!")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
$this->dispatch('loadData', $palletNumber, $plantId);
|
||||
$this->form->fill([
|
||||
'serial_number' => null,
|
||||
'plant_id' => $plantId,
|
||||
'pallet_number' => $palletNumber,
|
||||
'pending_pallet_list' => $pendingPallet,
|
||||
'Sno_quantity' => $count,
|
||||
'created_by' => $operatorName,
|
||||
'scanned_by' => $operatorName,
|
||||
]);
|
||||
|
||||
$this->dispatch('loadData', $palletNumber, $plantId);
|
||||
$this->form->fill([
|
||||
'serial_number' => null,
|
||||
'plant_id' => $plantId,
|
||||
'pallet_number' => $palletNumber,
|
||||
'pending_pallet_list' => $pendingPallet,
|
||||
'Sno_quantity' => $count,
|
||||
'created_by' => $operatorName,
|
||||
'scanned_by' => $operatorName,
|
||||
]);
|
||||
}
|
||||
|
||||
//$this->dispatch('removeSno', $serialNumber, $palletNumber, $plantId);
|
||||
|
||||
}
|
||||
|
||||
public function processPalletNo()
|
||||
@@ -735,7 +779,9 @@ class CreatePalletValidation extends CreateRecord
|
||||
Notification::make()
|
||||
->title('Pallet number is required.')
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', '', $plantId);
|
||||
$this->form->fill([
|
||||
'serial_number' => null,
|
||||
@@ -754,7 +800,9 @@ class CreatePalletValidation extends CreateRecord
|
||||
Notification::make()
|
||||
->title("Pallet number '$palletNumber' must be at least 10 digits.")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadLocator' ,'',$plantId);
|
||||
$this->form->fill([
|
||||
'serial_number' => null,
|
||||
@@ -782,8 +830,9 @@ class CreatePalletValidation extends CreateRecord
|
||||
if (!$palletNotCompleted)
|
||||
{
|
||||
Notification::make()
|
||||
->title("Already completed for pallet number $palletNumber")
|
||||
->title("Already completed for pallet number $palletNumber!")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $palletNumber, $plantId);
|
||||
|
||||
@@ -268,6 +268,7 @@ class ProductionLineStopResource extends Resource
|
||||
Forms\Components\DateTimePicker::make('from_datetime')
|
||||
->label('From DateTime')
|
||||
->required()
|
||||
->before('to_datetime')
|
||||
->reactive()
|
||||
// ->closeOnDateSelection()
|
||||
->afterStateUpdated(fn ($state, callable $set, callable $get) =>
|
||||
|
||||
@@ -1050,7 +1050,7 @@ class CreateProductionQuantity extends CreateRecord
|
||||
->body("Valid QR code scanned:<br>{$this->qrData}")
|
||||
->success()
|
||||
// ->persistent()
|
||||
->seconds(2)
|
||||
->duration(600)
|
||||
->send();
|
||||
|
||||
$formQRData = null;
|
||||
|
||||
@@ -38,6 +38,8 @@ class ReworkLocatorInvoiceValidationResource extends Resource
|
||||
|
||||
protected static ?string $navigationGroup = 'Export Dispatch';
|
||||
|
||||
protected static ?int $navigationSort = 7;
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
@@ -84,6 +86,7 @@ class ReworkLocatorInvoiceValidationResource extends Resource
|
||||
->label('Scan Pallet No')
|
||||
->required( fn ($get) => $get('rework_type') == 'pallet')
|
||||
->readOnly(fn ($get) => $get('rework_type') == 'invoice')
|
||||
->minLength(10)
|
||||
->reactive()
|
||||
->readOnly(fn (callable $get) => (!$get('plant') || !$get('rework_type') || ($get('rework_type') == 'invoice' && !$get('invoice_number')) || $get('scan_serial_no')))
|
||||
->extraAttributes([
|
||||
@@ -91,8 +94,9 @@ class ReworkLocatorInvoiceValidationResource extends Resource
|
||||
]),
|
||||
Forms\Components\TextInput::make('scan_serial_no')
|
||||
->label('Scan Serial No')
|
||||
->reactive()
|
||||
->readOnly(fn (callable $get) => (!$get('plant') || !$get('rework_type') || ($get('rework_type') == 'invoice' && !$get('invoice_number')) || ($get('rework_type') == 'invoice' && $get('scan_pallet_no')) || ($get('rework_type') == 'pallet' && !$get('scan_pallet_no'))))
|
||||
->minLength(9)
|
||||
->reactive()
|
||||
->extraAttributes([
|
||||
'wire:keydown.enter' => 'processSno($event.target.value)',
|
||||
]),
|
||||
@@ -143,21 +147,21 @@ class ReworkLocatorInvoiceValidationResource extends Resource
|
||||
$invoiceNumber = $get('invoice_number');
|
||||
|
||||
$rows = LocatorInvoiceValidation::where('invoice_number', $invoiceNumber)
|
||||
->where('plant_id', $plantId)
|
||||
->get();
|
||||
->where('plant_id', $plantId)
|
||||
->get();
|
||||
|
||||
$notCompletedCount = LocatorInvoiceValidation::where('invoice_number', $invoiceNumber)
|
||||
->where('plant_id', $plantId)
|
||||
->where(function($query) {
|
||||
$query->whereNull('scanned_status')
|
||||
->orWhere('scanned_status', '');
|
||||
})
|
||||
->count();
|
||||
->where('plant_id', $plantId)
|
||||
->where(function($query) {
|
||||
$query->whereNull('scanned_status')
|
||||
->orWhere('scanned_status', '');
|
||||
})
|
||||
->count();
|
||||
|
||||
$isScanningComplete = true;
|
||||
foreach ($rows as $row)
|
||||
{
|
||||
if ($row->scanned_status !== 'Scanned') {
|
||||
if ($row->scanned_status != 'Scanned') {
|
||||
$isScanningComplete = false;
|
||||
break;
|
||||
}
|
||||
@@ -166,9 +170,13 @@ class ReworkLocatorInvoiceValidationResource extends Resource
|
||||
if (!$isScanningComplete)
|
||||
{
|
||||
Notification::make()
|
||||
->title("Scanned invoice number: '$invoiceNumber' does not completed the scanning process!<br>Has '$notCompletedCount' pending serial number to scan!<br>Please, scan the valid completed invoice number to proceed...")
|
||||
->danger()
|
||||
->send();
|
||||
->title("Scanned invoice number: '$invoiceNumber' does not completed the scanning process!<br>Has '$notCompletedCount' pending serial number to scan!<br>Please, scan the valid completed invoice number to proceed...")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$set('invoice_number', null);
|
||||
$set('update_invoice', null);
|
||||
return;
|
||||
}
|
||||
}),
|
||||
@@ -182,24 +190,16 @@ class ReworkLocatorInvoiceValidationResource extends Resource
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get, $livewire) {
|
||||
$plantId = $get('plant');
|
||||
|
||||
$invoiceNumber = $get('invoice_number');
|
||||
$palletNumber = $get('scan_pallet_no');
|
||||
|
||||
$rows = LocatorInvoiceValidation::where('invoice_number', $invoiceNumber)
|
||||
->where('plant_id', $plantId)
|
||||
->get();
|
||||
|
||||
$notCompletedCount = LocatorInvoiceValidation::where('invoice_number', $invoiceNumber)
|
||||
->where('plant_id', $plantId)
|
||||
->where(function($query) {
|
||||
$query->whereNull('scanned_status')
|
||||
->orWhere('scanned_status', '');
|
||||
})
|
||||
->count();
|
||||
$rows = PalletValidation::where('pallet_number', $palletNumber)
|
||||
->where('plant_id', $plantId)
|
||||
->get();
|
||||
|
||||
$isScanningComplete = true;
|
||||
foreach ($rows as $row)
|
||||
{
|
||||
if ($row->scanned_status !== 'Scanned') {
|
||||
if ($row->pallet_status != 'Completed') {
|
||||
$isScanningComplete = false;
|
||||
break;
|
||||
}
|
||||
@@ -208,9 +208,13 @@ class ReworkLocatorInvoiceValidationResource extends Resource
|
||||
if (!$isScanningComplete)
|
||||
{
|
||||
Notification::make()
|
||||
->title("Scanned invoice number: '$invoiceNumber' does not completed the scanning process!<br>Has '$notCompletedCount' pending serial number to scan!<br>Please, scan the valid completed invoice number to proceed...")
|
||||
->danger()
|
||||
->send();
|
||||
->title("Scanned pallet number '$palletNumber' does not completed the master packing!<br>Please, scan the valid completed pallet number to proceed...")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$set('scan_pallet_no', null);
|
||||
$set('update_pallet', null);
|
||||
return;
|
||||
}
|
||||
}),
|
||||
@@ -241,6 +245,7 @@ class ReworkLocatorInvoiceValidationResource extends Resource
|
||||
}),
|
||||
Tables\Columns\TextColumn::make('plant.name')
|
||||
->label('Plant')
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('invoice_number')
|
||||
->label('Invoice Number')
|
||||
@@ -314,11 +319,15 @@ class ReworkLocatorInvoiceValidationResource extends Resource
|
||||
->headerActions([
|
||||
ImportAction::make()
|
||||
->importer(ReworkLocatorInvoiceValidationImporter::class)
|
||||
->label('Import Rework Invoice')
|
||||
->color('warning')
|
||||
->visible(function() {
|
||||
return Filament::auth()->user()->can('view import rework invoice validation');
|
||||
}),
|
||||
ExportAction::make()
|
||||
->exporter(ReworkLocatorInvoiceValidationExporter::class)
|
||||
->label('Export Rework Invoice')
|
||||
->color('warning')
|
||||
->visible(function() {
|
||||
return Filament::auth()->user()->can('view export rework invoice validation');
|
||||
}),
|
||||
@@ -372,7 +381,6 @@ class ReworkLocatorInvoiceValidationResource extends Resource
|
||||
TextInput::make('serial_number')
|
||||
->label('Serial Number')
|
||||
->placeholder(placeholder: 'Enter Serial Number'),
|
||||
|
||||
Select::make('pallet_number')
|
||||
->label('Pallet Number')
|
||||
->options(function (callable $get) {
|
||||
@@ -532,6 +540,11 @@ class ReworkLocatorInvoiceValidationResource extends Resource
|
||||
];
|
||||
}
|
||||
|
||||
public static function getNavigationLabel(): string
|
||||
{
|
||||
return 'Scan Rework';
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
@@ -541,10 +554,6 @@ class ReworkLocatorInvoiceValidationResource extends Resource
|
||||
'edit' => Pages\EditReworkLocatorInvoiceValidation::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
public static function getNavigationLabel(): string
|
||||
{
|
||||
return 'Rework Invoice / Pallet';
|
||||
}
|
||||
|
||||
public static function getEloquentQuery(): Builder
|
||||
{
|
||||
|
||||
@@ -54,7 +54,9 @@ class CreateReworkLocatorInvoiceValidation extends CreateRecord
|
||||
->title("Invalid: Invoice Number")
|
||||
->body("Invoice number can't be empty!")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', '', '', $plantId, $reworkType);
|
||||
// $snoCount = LocatorInvoiceValidation::where('plant_id', $plantId)->where('invoice_number', $invoiceNo)->count();
|
||||
$this->form->fill([
|
||||
@@ -81,6 +83,7 @@ class CreateReworkLocatorInvoiceValidation extends CreateRecord
|
||||
->title('Invoice Not Found')
|
||||
->body("Invoice number '$invoiceNo' doesn't exist in invoice table!<br><br>Scan the valid exist 'Invoice Number' to proceed..!")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', '', '', $plantId, $reworkType);
|
||||
@@ -126,7 +129,9 @@ class CreateReworkLocatorInvoiceValidation extends CreateRecord
|
||||
->title("Invalid: Pallet Number")
|
||||
->body("Pallet number '$palletNo' must be at least 10 digits.")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $invoiceNo, '', $plantId, $reworkType);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
@@ -143,13 +148,40 @@ class CreateReworkLocatorInvoiceValidation extends CreateRecord
|
||||
]);
|
||||
return;
|
||||
}
|
||||
else if (strlen($serialNo) > 0 && strlen($serialNo) < 13)
|
||||
else if (strlen($serialNo) > 0 && (strlen($serialNo) < 9 || strlen($serialNo) > 20))
|
||||
{
|
||||
Notification::make()
|
||||
->title("Invalid: Serial Number")
|
||||
->body("Serial number '$serialNo' must be at least 13 digits.")
|
||||
->body("Serial number should contain minimum 9 digits and maximum 20 digits.")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $invoiceNo, '', $plantId, $reworkType);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
'plant' => $plantId,
|
||||
'invoice_number' => $invoiceNo,
|
||||
'scan_pallet_no' => null,
|
||||
'scan_serial_no' => null,
|
||||
'rework_type' => $reworkType,
|
||||
'reworkType' => $reworkType,
|
||||
'update_invoice' => 0,
|
||||
'update_pallet' => 0,
|
||||
'created_by' => $operatorName,
|
||||
'scanned_by' => $operatorName,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
else if (strlen($serialNo) > 0 && !ctype_alnum($serialNo))
|
||||
{
|
||||
Notification::make()
|
||||
->title("Invalid: Serial Number")
|
||||
->body("Serial number '$serialNo' must contain alpha-numeric values only.")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $invoiceNo, '', $plantId, $reworkType);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
@@ -196,6 +228,7 @@ class CreateReworkLocatorInvoiceValidation extends CreateRecord
|
||||
->title('Completed: Rework Invoice')
|
||||
->body("Scanned invoice number '$invoiceNo' successfully moved into rework invoice table.<br><br>Please, scan the next completed invoice number to proceed..!")
|
||||
->success()
|
||||
->duration(800)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', '', '', $plantId, $reworkType);
|
||||
@@ -219,6 +252,7 @@ class CreateReworkLocatorInvoiceValidation extends CreateRecord
|
||||
->title('Completed: Invoice Found')
|
||||
->body("Press 'Yes' and Press 'Enter' in Scan Invoice No to do rework for entire invoice.<br><br>Press 'No' to do rework against 'Pallet or Serial Number'..!")
|
||||
->info()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $invoiceNo, '', $plantId, $reworkType);
|
||||
@@ -244,6 +278,7 @@ class CreateReworkLocatorInvoiceValidation extends CreateRecord
|
||||
->title('Invoice Not Completed')
|
||||
->body("Scanned invoice number '$invoiceNo' doesn't completed the scanning process!<br><br>Has '$notCompletedCount' pending serial number to scan!<br><br>Please, scan the valid completed invoice number to proceed..!")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', '', '', $plantId, $reworkType);
|
||||
@@ -269,15 +304,18 @@ class CreateReworkLocatorInvoiceValidation extends CreateRecord
|
||||
->title("Choosed: Pallet Rework Type")
|
||||
->body("Scan valid pallet number to proceed..!")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
return;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
Notification::make()
|
||||
->title("Rework Type Not Found")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', '', '', $plantId, $reworkType);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
@@ -331,7 +369,9 @@ class CreateReworkLocatorInvoiceValidation extends CreateRecord
|
||||
->title("Invalid: Invoice Number")
|
||||
->body("Invoice number can't be empty!")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', '', '', $plantId, $reworkType);
|
||||
// $snoCount = LocatorInvoiceValidation::where('plant_id', $plantId)->where('invoice_number', $invoiceNo)->count();
|
||||
$this->form->fill([
|
||||
@@ -358,6 +398,7 @@ class CreateReworkLocatorInvoiceValidation extends CreateRecord
|
||||
->title('Invoice Not Found')
|
||||
->body("Invoice number '$invoiceNo' doesn't exist in invoice table!<br><br>Scan the valid exist 'Invoice Number' to proceed..!")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', '', '', $plantId, $reworkType);
|
||||
@@ -403,7 +444,9 @@ class CreateReworkLocatorInvoiceValidation extends CreateRecord
|
||||
->title("Invalid: Pallet Number")
|
||||
->body("Pallet number can't be empty!")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $invoiceNo, '', $plantId, $reworkType);
|
||||
// $snoCount = LocatorInvoiceValidation::where('plant_id', $plantId)->where('invoice_number', $invoiceNo)->count();
|
||||
$this->form->fill([
|
||||
@@ -427,7 +470,9 @@ class CreateReworkLocatorInvoiceValidation extends CreateRecord
|
||||
->title("Invalid: Pallet Number")
|
||||
->body("Pallet number '$palletNo' must be at least 10 digits.")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $invoiceNo, '', $plantId, $reworkType);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
@@ -453,6 +498,7 @@ class CreateReworkLocatorInvoiceValidation extends CreateRecord
|
||||
->title('Pallet Not Found')
|
||||
->body("Pallet number '$palletNo' doesn't exist in scanned invoice number '$invoiceNo'!<br><br>Scan the valid exist 'Pallet Number' to proceed..!")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $invoiceNo, '', $plantId, $reworkType);
|
||||
@@ -472,13 +518,40 @@ class CreateReworkLocatorInvoiceValidation extends CreateRecord
|
||||
return;
|
||||
}
|
||||
|
||||
if (strlen($serialNo) > 0 && strlen($serialNo) < 13)
|
||||
if (strlen($serialNo) > 0 && (strlen($serialNo) < 9 || strlen($serialNo) > 20))
|
||||
{
|
||||
Notification::make()
|
||||
->title("Invalid: Serial Number")
|
||||
->body("Serial number '$serialNo' must be at least 13 digits.")
|
||||
->body("Serial number should contain minimum 9 digits and maximum 20 digits.")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $invoiceNo, $palletNo, $plantId, $reworkType);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
'plant' => $plantId,
|
||||
'invoice_number' => $invoiceNo,
|
||||
'scan_pallet_no' => $palletNo,
|
||||
'scan_serial_no' => null,
|
||||
'rework_type' => $reworkType,
|
||||
'reworkType' => $reworkType,
|
||||
'update_invoice' => 0,
|
||||
'update_pallet' => 0,
|
||||
'created_by' => $operatorName,
|
||||
'scanned_by' => $operatorName,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
else if (strlen($serialNo) > 0 && !ctype_alnum($serialNo))
|
||||
{
|
||||
Notification::make()
|
||||
->title("Invalid: Serial Number")
|
||||
->body("Serial number '$serialNo' must contain alpha-numeric values only.")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $invoiceNo, $palletNo, $plantId, $reworkType);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
@@ -526,6 +599,7 @@ class CreateReworkLocatorInvoiceValidation extends CreateRecord
|
||||
->title('Completed: Rework Pallet from Invoice')
|
||||
->body("Scanned pallet number '$palletNo' successfully moved into rework invoice table from invoice number '$invoiceNo'.<br><br>Please, scan the next pallet number to proceed..!")
|
||||
->success()
|
||||
->duration(500)
|
||||
->send();
|
||||
|
||||
$InvoiceSerialNumbers = LocatorInvoiceValidation::where('plant_id', $plantId)->where('invoice_number', $invoiceNo)->first();
|
||||
@@ -535,6 +609,7 @@ class CreateReworkLocatorInvoiceValidation extends CreateRecord
|
||||
Notification::make()
|
||||
->title("All available serial numbers are successfully moved into rework invoice table from invoice number '$invoiceNo'.<br><br>Please, scan the next invoice number to proceed..!")
|
||||
->success()
|
||||
->duration(800)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', '', '', $plantId, $reworkType);
|
||||
@@ -576,6 +651,7 @@ class CreateReworkLocatorInvoiceValidation extends CreateRecord
|
||||
->title('Invoice Not Completed')
|
||||
->body("Scanned invoice number '$invoiceNo' doesn't completed the scanning process!<br><br>Has '$notCompletedCount' pending serial number to scan!<br><br>Please, scan the valid completed invoice number to proceed..!")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', '', '', $plantId, $reworkType);
|
||||
@@ -603,7 +679,9 @@ class CreateReworkLocatorInvoiceValidation extends CreateRecord
|
||||
->title("Invalid: Pallet Number")
|
||||
->body("Pallet number can't be empty!")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', '', '', $plantId, $reworkType);
|
||||
// $snoCount = LocatorInvoiceValidation::where('plant_id', $plantId)->where('invoice_number', $invoiceNo)->count();
|
||||
$this->form->fill([
|
||||
@@ -627,7 +705,9 @@ class CreateReworkLocatorInvoiceValidation extends CreateRecord
|
||||
->title("Invalid: Pallet Number")
|
||||
->body("Pallet number '$palletNo' must be at least 10 digits.")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', '', '', $plantId, $reworkType);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
@@ -653,6 +733,7 @@ class CreateReworkLocatorInvoiceValidation extends CreateRecord
|
||||
->title('Pallet Not Found')
|
||||
->body("Pallet number '$palletNo' doesn't exist in pallet table!<br><br>Scan the valid exist 'Pallet Number' to proceed..!")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', '', '', $plantId, $reworkType);
|
||||
@@ -692,6 +773,7 @@ class CreateReworkLocatorInvoiceValidation extends CreateRecord
|
||||
->title('Locator Pallet Found')
|
||||
->body("Scanned pallet number '$palletNo' exist in locator number '$locatExist'.<br><br>Remove scanned 'Pallet' from 'Locator' to proceed re-master packing..!")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', '', '', $plantId, $reworkType);
|
||||
@@ -712,13 +794,40 @@ class CreateReworkLocatorInvoiceValidation extends CreateRecord
|
||||
}
|
||||
else
|
||||
{
|
||||
if (strlen($serialNo) > 0 && strlen($serialNo) < 13)
|
||||
if (strlen($serialNo) > 0 && (strlen($serialNo) < 9 || strlen($serialNo) > 20))
|
||||
{
|
||||
Notification::make()
|
||||
->title("Invalid: Serial Number")
|
||||
->body("Serial number '$serialNo' must be at least 13 digits.")
|
||||
->body("Serial number should contain minimum 9 digits and maximum 20 digits.")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', '', $palletNo, $plantId, $reworkType);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
'plant' => $plantId,
|
||||
'invoice_number' => null,
|
||||
'scan_pallet_no' => $palletNo,
|
||||
'scan_serial_no' => null,
|
||||
'rework_type' => $reworkType,
|
||||
'reworkType' => $reworkType,
|
||||
'update_invoice' => 0,
|
||||
'update_pallet' => 0,
|
||||
'created_by' => $operatorName,
|
||||
'scanned_by' => $operatorName,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
else if (strlen($serialNo) > 0 && !ctype_alnum($serialNo))
|
||||
{
|
||||
Notification::make()
|
||||
->title("Invalid: Serial Number")
|
||||
->body("Serial number '$serialNo' must contain alpha-numeric values only.")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', '', $palletNo, $plantId, $reworkType);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
@@ -747,6 +856,7 @@ class CreateReworkLocatorInvoiceValidation extends CreateRecord
|
||||
->title('Completed: Rework Pallet')
|
||||
->body("Scanned pallet number '$palletNo' successfully removed from pallet table.<br><br>Please, scan the next pallet number to re-master packing..!")
|
||||
->success()
|
||||
->duration(800)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', '', '', $plantId, $reworkType);
|
||||
@@ -771,6 +881,7 @@ class CreateReworkLocatorInvoiceValidation extends CreateRecord
|
||||
->title('Completed: Pallet Found')
|
||||
->body("Press 'Yes' and Press 'Enter' in Scan Pallet No to do re-master packing for entire pallet.<br><br>Press 'No' to do partial re-master packing against 'Serial Number'..!")
|
||||
->info()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', '', $palletNo, $plantId, $reworkType);
|
||||
@@ -797,6 +908,7 @@ class CreateReworkLocatorInvoiceValidation extends CreateRecord
|
||||
->title('Pallet Not Completed')
|
||||
->body("Scanned pallet number '$palletNo' doesn't completed the master packing!<br><br>Please, scan the valid completed pallet number to proceed..!")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', '', '', $plantId, $reworkType);
|
||||
@@ -821,7 +933,9 @@ class CreateReworkLocatorInvoiceValidation extends CreateRecord
|
||||
Notification::make()
|
||||
->title("Rework Type Not Found")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', '', '', $plantId, $reworkType);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
@@ -875,7 +989,9 @@ class CreateReworkLocatorInvoiceValidation extends CreateRecord
|
||||
->title("Invalid: Invoice Number")
|
||||
->body("Invoice number can't be empty!")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', '', '', $plantId, $reworkType);
|
||||
// $snoCount = LocatorInvoiceValidation::where('plant_id', $plantId)->where('invoice_number', $invoiceNo)->count();
|
||||
$this->form->fill([
|
||||
@@ -902,6 +1018,7 @@ class CreateReworkLocatorInvoiceValidation extends CreateRecord
|
||||
->title('Invoice Not Found')
|
||||
->body("Invoice number '$invoiceNo' doesn't exist in invoice table!<br><br>Scan the valid exist 'Invoice Number' to proceed..!")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', '', '', $plantId, $reworkType);
|
||||
@@ -947,7 +1064,9 @@ class CreateReworkLocatorInvoiceValidation extends CreateRecord
|
||||
->title("Invalid: Pallet Number")
|
||||
->body("Pallet number '$palletNo' must be at least 10 digits.")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $invoiceNo, '', $plantId, $reworkType);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
@@ -970,7 +1089,9 @@ class CreateReworkLocatorInvoiceValidation extends CreateRecord
|
||||
->title("Invalid: Serial Number")
|
||||
->body("Serial number can't be empty!")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $invoiceNo, '', $plantId, $reworkType);
|
||||
// $snoCount = LocatorInvoiceValidation::where('plant_id', $plantId)->where('invoice_number', $invoiceNo)->count();
|
||||
$this->form->fill([
|
||||
@@ -988,13 +1109,40 @@ class CreateReworkLocatorInvoiceValidation extends CreateRecord
|
||||
]);
|
||||
return;
|
||||
}
|
||||
else if (strlen($serialNo) < 13)
|
||||
else if (strlen($serialNo) < 9 || strlen($serialNo) > 20)
|
||||
{
|
||||
Notification::make()
|
||||
->title("Invalid: Serial Number")
|
||||
->body("Serial number '$serialNo' must be at least 13 digits.")
|
||||
->body("Serial number should contain minimum 9 digits and maximum 20 digits.")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $invoiceNo, '', $plantId, $reworkType);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
'plant' => $plantId,
|
||||
'invoice_number' => $invoiceNo,
|
||||
'scan_pallet_no' => null,
|
||||
'scan_serial_no' => null,
|
||||
'rework_type' => $reworkType,
|
||||
'reworkType' => $reworkType,
|
||||
'update_invoice' => 0,
|
||||
'update_pallet' => 0,
|
||||
'created_by' => $operatorName,
|
||||
'scanned_by' => $operatorName,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
else if (!ctype_alnum($serialNo))
|
||||
{
|
||||
Notification::make()
|
||||
->title("Invalid: Serial Number")
|
||||
->body("Serial number '$serialNo' must contain alpha-numeric values only.")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $invoiceNo, '', $plantId, $reworkType);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
@@ -1020,6 +1168,7 @@ class CreateReworkLocatorInvoiceValidation extends CreateRecord
|
||||
->title('Serial Not Found')
|
||||
->body("Serial number '$serialNo' doesn't exist in scanned invoice number '$invoiceNo'!<br><br>Scan the valid exist 'Serial Number' to proceed..!")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $invoiceNo, '', $plantId, $reworkType);
|
||||
@@ -1069,6 +1218,7 @@ class CreateReworkLocatorInvoiceValidation extends CreateRecord
|
||||
->title('Completed: Rework Serial from Invoice')
|
||||
->body("Scanned serial number '$serialNo' successfully moved into rework invoice table from invoice number '$invoiceNo'.<br><br>Please, scan the next serial number to proceed..!")
|
||||
->success()
|
||||
->duration(500)
|
||||
->send();
|
||||
|
||||
$InvoiceSerialNumbers = LocatorInvoiceValidation::where('plant_id', $plantId)->where('invoice_number', $invoiceNo)->first();
|
||||
@@ -1078,6 +1228,7 @@ class CreateReworkLocatorInvoiceValidation extends CreateRecord
|
||||
Notification::make()
|
||||
->title("All available serial numbers are successfully moved into rework invoice table from invoice number '$invoiceNo'.<br><br>Please, scan the next invoice number to proceed..!")
|
||||
->success()
|
||||
->duration(800)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', '', '', $plantId, $reworkType);
|
||||
@@ -1119,6 +1270,7 @@ class CreateReworkLocatorInvoiceValidation extends CreateRecord
|
||||
->title('Invoice Not Completed')
|
||||
->body("Scanned invoice number '$invoiceNo' doesn't completed the scanning process!<br><br>Has '$notCompletedCount' pending serial number to scan!<br><br>Please, scan the valid completed invoice number to proceed..!")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', '', '', $plantId, $reworkType);
|
||||
@@ -1146,7 +1298,9 @@ class CreateReworkLocatorInvoiceValidation extends CreateRecord
|
||||
->title("Invalid: Pallet Number")
|
||||
->body("Pallet number can't be empty!")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', '', '', $plantId, $reworkType);
|
||||
// $snoCount = LocatorInvoiceValidation::where('plant_id', $plantId)->where('invoice_number', $invoiceNo)->count();
|
||||
$this->form->fill([
|
||||
@@ -1170,7 +1324,9 @@ class CreateReworkLocatorInvoiceValidation extends CreateRecord
|
||||
->title("Invalid: Pallet Number")
|
||||
->body("Pallet number '$palletNo' must be at least 10 digits.")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', '', '', $plantId, $reworkType);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
@@ -1196,6 +1352,7 @@ class CreateReworkLocatorInvoiceValidation extends CreateRecord
|
||||
->title('Pallet Not Found')
|
||||
->body("Pallet number '$palletNo' doesn't exist in pallet table!<br><br>Scan the valid exist 'Pallet Number' to proceed..!")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', '', '', $plantId, $reworkType);
|
||||
@@ -1235,6 +1392,7 @@ class CreateReworkLocatorInvoiceValidation extends CreateRecord
|
||||
->title('Locator Pallet Found')
|
||||
->body("Scanned pallet number '$palletNo' exist in locator number '$locatExist'.<br><br>Remove scanned 'Pallet' from 'Locator' to proceed re-master packing..!")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', '' , '', $plantId, $reworkType);
|
||||
@@ -1261,7 +1419,9 @@ class CreateReworkLocatorInvoiceValidation extends CreateRecord
|
||||
->title("Invalid: Serial Number")
|
||||
->body("Serial number can't be empty!")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', '', $palletNo, $plantId, $reworkType);
|
||||
// $snoCount = LocatorInvoiceValidation::where('plant_id', $plantId)->where('invoice_number', $invoiceNo)->count();
|
||||
$this->form->fill([
|
||||
@@ -1279,13 +1439,40 @@ class CreateReworkLocatorInvoiceValidation extends CreateRecord
|
||||
]);
|
||||
return;
|
||||
}
|
||||
else if (strlen($serialNo) < 13)
|
||||
else if (strlen($serialNo) < 9 || strlen($serialNo) > 20)
|
||||
{
|
||||
Notification::make()
|
||||
->title("Invalid: Serial Number")
|
||||
->body("Serial number '$serialNo' must be at least 13 digits.")
|
||||
->title("Invalid: Serial Number")
|
||||
->body("Serial number should contain minimum 9 digits and maximum 20 digits.")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', '', $palletNo, $plantId, $reworkType);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
'plant' => $plantId,
|
||||
'invoice_number' => null,
|
||||
'scan_pallet_no' => $palletNo,
|
||||
'scan_serial_no' => null,
|
||||
'rework_type' => $reworkType,
|
||||
'reworkType' => $reworkType,
|
||||
'update_invoice' => 0,
|
||||
'update_pallet' => 0,
|
||||
'created_by' => $operatorName,
|
||||
'scanned_by' => $operatorName,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
else if (!ctype_alnum($serialNo))
|
||||
{
|
||||
Notification::make()
|
||||
->title("Invalid: Serial Number")
|
||||
->body("Serial number '$serialNo' must contain alpha-numeric values only.")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', '', $palletNo, $plantId, $reworkType);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
@@ -1311,6 +1498,7 @@ class CreateReworkLocatorInvoiceValidation extends CreateRecord
|
||||
->title('Serial Not Found')
|
||||
->body("Serial number '$serialNo' doesn't exist in pallet number '$palletNo'!<br><br>Scan the valid exist 'Serial Number' to proceed..!")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', '', $palletNo, $plantId, $reworkType);
|
||||
@@ -1332,9 +1520,10 @@ class CreateReworkLocatorInvoiceValidation extends CreateRecord
|
||||
|
||||
foreach ($records as $row)
|
||||
{
|
||||
if ($PalletSerialNumbers->serial_number != null && $PalletSerialNumbers->serial_number != '' && $PalletSerialNumbers->serial_number != $serialNo)
|
||||
if ($row->serial_number != null && $row->serial_number != '' && $row->serial_number == $serialNo)
|
||||
{
|
||||
$row->forceDelete();
|
||||
continue;
|
||||
}
|
||||
|
||||
$row->pallet_status = null;
|
||||
@@ -1347,6 +1536,7 @@ class CreateReworkLocatorInvoiceValidation extends CreateRecord
|
||||
->title('Completed: Rework Serial from Pallet')
|
||||
->body("Scanned serial number '$serialNo' successfully removed from pallet number '$palletNo'.<br><br>Please, scan the next pallet number to re-master packing..!")
|
||||
->success()
|
||||
->duration(500)
|
||||
->send();
|
||||
|
||||
$PalletSerialNumbers = PalletValidation::where('plant_id', $plantId)->where('pallet_number', $palletNo)->first();
|
||||
@@ -1356,6 +1546,7 @@ class CreateReworkLocatorInvoiceValidation extends CreateRecord
|
||||
Notification::make()
|
||||
->title("Pallet number '$palletNo' successfully re-master packed.<br><br>Please, scan the next pallet number to re-master packing..!")
|
||||
->success()
|
||||
->duration(800)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', '', '', $plantId, $reworkType);
|
||||
@@ -1398,6 +1589,7 @@ class CreateReworkLocatorInvoiceValidation extends CreateRecord
|
||||
->title('Pallet Not Completed')
|
||||
->body("Pallet number '$palletNo' doesn't completed the master packing for scanned serial number '$serialNo'!<br><br>Please, scan the valid completed pallet number to proceed..!")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', '' , '', $plantId, $reworkType);
|
||||
@@ -1422,7 +1614,9 @@ class CreateReworkLocatorInvoiceValidation extends CreateRecord
|
||||
Notification::make()
|
||||
->title("Rework Type Not Found")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', '', '', $plantId, $reworkType);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
|
||||
@@ -48,11 +48,17 @@ class StickerMasterResource extends Resource
|
||||
$set('item_id', null) & //when plant changed remove all the data which is in text input box
|
||||
$set('item_description', null) &
|
||||
$set('item_error', null) &
|
||||
$set('panel_box_code', null) &
|
||||
$set('load_rate', null) &
|
||||
$set('bundle_quantity', null) &
|
||||
$set('material_type', null) &
|
||||
$set('part_validation1', null) &
|
||||
$set('part_validation2', null) &
|
||||
$set('part_validation3', null) &
|
||||
$set('part_validation4', null) &
|
||||
$set('part_validation5', null) &
|
||||
$set('laser_part_validation1', null) &
|
||||
$set('laser_part_validation2', null) &
|
||||
$set('serial_number_motor', false) &
|
||||
$set('serial_number_pump', false) &
|
||||
$set('serial_number_pumpset', false) &
|
||||
@@ -169,6 +175,12 @@ class StickerMasterResource extends Resource
|
||||
Forms\Components\TextInput::make('part_validation5')
|
||||
->nullable(),
|
||||
|
||||
Forms\Components\TextInput::make('laser_part_validation1')
|
||||
->nullable(),
|
||||
|
||||
Forms\Components\TextInput::make('laser_part_validation2')
|
||||
->nullable(),
|
||||
|
||||
Forms\Components\TextInput::make('panel_box_code')
|
||||
->label('Panel Box Code')
|
||||
->readOnly(fn (callable $get) => $get('material_type'))
|
||||
@@ -509,6 +521,12 @@ class StickerMasterResource extends Resource
|
||||
Tables\Columns\TextColumn::make('part_validation5')
|
||||
->label('Part Validation 5')
|
||||
->alignCenter(),
|
||||
Tables\Columns\TextColumn::make('laser_part_validation1')
|
||||
->label('Laser Part Validation 1')
|
||||
->alignCenter(),
|
||||
Tables\Columns\TextColumn::make('laser_part_validation2')
|
||||
->label('Laser Part Validation 2')
|
||||
->alignCenter(),
|
||||
Tables\Columns\TextColumn::make('panel_box_code')
|
||||
->label('Panel Box Code')
|
||||
->alignCenter(),
|
||||
@@ -521,7 +539,18 @@ class StickerMasterResource extends Resource
|
||||
->alignCenter(),
|
||||
Tables\Columns\TextColumn::make('material_type')
|
||||
->label('Material Type')
|
||||
->alignCenter(),
|
||||
->alignCenter()
|
||||
->formatStateUsing(function ($state) {
|
||||
if (is_null($state) || $state === '') {
|
||||
return '';
|
||||
}
|
||||
return match ($state) {
|
||||
1 => 'Individual',
|
||||
2 => 'Bundle',
|
||||
3 => 'Quantity',
|
||||
default => '',
|
||||
};
|
||||
}),
|
||||
Tables\Columns\TextColumn::make('created_at')
|
||||
->label('Created At')
|
||||
->dateTime()
|
||||
|
||||
134
app/Filament/Resources/TempLiveReadingResource.php
Normal file
134
app/Filament/Resources/TempLiveReadingResource.php
Normal file
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use App\Filament\Resources\TempLiveReadingResource\Pages;
|
||||
use App\Filament\Resources\TempLiveReadingResource\RelationManagers;
|
||||
use App\Models\MfmMeter;
|
||||
use App\Models\TempLiveReading;
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Filament\Forms\Components\Section;
|
||||
|
||||
class TempLiveReadingResource extends Resource
|
||||
{
|
||||
protected static ?string $model = TempLiveReading::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
|
||||
protected static ?string $navigationGroup = 'Power House';
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Section::make('')
|
||||
->schema([
|
||||
Forms\Components\Select::make('plant_id')
|
||||
->label('Plant')
|
||||
->relationship('plant', 'name')
|
||||
->reactive()
|
||||
->required(),
|
||||
Forms\Components\Select::make('mfm_meter_id')
|
||||
->label('MFM Meter ID')
|
||||
->required()
|
||||
->reactive()
|
||||
->options(function (callable $get) {
|
||||
$plantId = $get('plant_id');
|
||||
if (!$plantId) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return MfmMeter::where('plant_id', $plantId)
|
||||
->pluck('sequence', 'id')
|
||||
->toArray();
|
||||
}),
|
||||
Forms\Components\TextInput::make('register_data')
|
||||
->label('Register Data')
|
||||
->required(),
|
||||
Forms\Components\Hidden::make('created_by')
|
||||
->default(Filament::auth()->user()?->name),
|
||||
])
|
||||
->columns(3),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('id')
|
||||
->label('ID')
|
||||
->numeric()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('plant.name')
|
||||
->numeric()
|
||||
->sortable(),
|
||||
// Tables\Columns\TextColumn::make('mfm_meter_id.sequence')
|
||||
// ->label('Sequence')
|
||||
// ->sortable(),
|
||||
Tables\Columns\TextColumn::make('mfmMeter.name')
|
||||
->label('Name')
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('register_data')
|
||||
->label('Register Data')
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('created_at')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
Tables\Columns\TextColumn::make('updated_at')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
Tables\Columns\TextColumn::make('deleted_at')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
])
|
||||
->filters([
|
||||
Tables\Filters\TrashedFilter::make(),
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\ViewAction::make(),
|
||||
Tables\Actions\EditAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\BulkActionGroup::make([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
Tables\Actions\ForceDeleteBulkAction::make(),
|
||||
Tables\Actions\RestoreBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListTempLiveReadings::route('/'),
|
||||
'create' => Pages\CreateTempLiveReading::route('/create'),
|
||||
'view' => Pages\ViewTempLiveReading::route('/{record}'),
|
||||
'edit' => Pages\EditTempLiveReading::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
|
||||
public static function getEloquentQuery(): Builder
|
||||
{
|
||||
return parent::getEloquentQuery()
|
||||
->withoutGlobalScopes([
|
||||
SoftDeletingScope::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\TempLiveReadingResource\Pages;
|
||||
|
||||
use App\Filament\Resources\TempLiveReadingResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateTempLiveReading extends CreateRecord
|
||||
{
|
||||
protected static string $resource = TempLiveReadingResource::class;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\TempLiveReadingResource\Pages;
|
||||
|
||||
use App\Filament\Resources\TempLiveReadingResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditTempLiveReading extends EditRecord
|
||||
{
|
||||
protected static string $resource = TempLiveReadingResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\ViewAction::make(),
|
||||
Actions\DeleteAction::make(),
|
||||
Actions\ForceDeleteAction::make(),
|
||||
Actions\RestoreAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\TempLiveReadingResource\Pages;
|
||||
|
||||
use App\Filament\Resources\TempLiveReadingResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListTempLiveReadings extends ListRecords
|
||||
{
|
||||
protected static string $resource = TempLiveReadingResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\TempLiveReadingResource\Pages;
|
||||
|
||||
use App\Filament\Resources\TempLiveReadingResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ViewRecord;
|
||||
|
||||
class ViewTempLiveReading extends ViewRecord
|
||||
{
|
||||
protected static string $resource = TempLiveReadingResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\EditAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -42,7 +42,6 @@ class TestingPanelReadingResource extends Resource
|
||||
|
||||
protected static ?string $navigationGroup = 'Testing Panel';
|
||||
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
@@ -219,7 +218,7 @@ class TestingPanelReadingResource extends Resource
|
||||
Forms\Components\TextInput::make('room_temperature')
|
||||
->label('Room Temperature'),
|
||||
Forms\Components\TextInput::make('hv_test')
|
||||
->label('HV Test'),
|
||||
->label('High Voltage Test'),
|
||||
Forms\Components\TextInput::make('batch_number')
|
||||
->label('Batch Number'),
|
||||
Forms\Components\TextInput::make('batch_count')
|
||||
@@ -396,7 +395,7 @@ class TestingPanelReadingResource extends Resource
|
||||
->label('Room Temperature')
|
||||
->alignCenter(),
|
||||
Tables\Columns\TextColumn::make('hv_test')
|
||||
->label('Hv Test')
|
||||
->label('High Voltage Test')
|
||||
->alignCenter(),
|
||||
Tables\Columns\TextColumn::make('batch_number')
|
||||
->label('Batch Number')
|
||||
@@ -416,6 +415,9 @@ class TestingPanelReadingResource extends Resource
|
||||
Tables\Columns\TextColumn::make('update_count')
|
||||
->label('Updated Count')
|
||||
->alignCenter(),
|
||||
Tables\Columns\TextColumn::make('output_flag')
|
||||
->label('Output Flag')
|
||||
->alignCenter(),
|
||||
Tables\Columns\TextColumn::make('scanned_at')
|
||||
->label('Scanned At')
|
||||
->alignCenter()
|
||||
|
||||
@@ -14,7 +14,6 @@ use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
class UserResource extends Resource
|
||||
{
|
||||
protected static ?string $model = User::class;
|
||||
@@ -29,6 +28,7 @@ class UserResource extends Resource
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('name')
|
||||
->required()
|
||||
->autofocus()
|
||||
->reactive()
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
$set('email', $state . '@cripumps.com');
|
||||
@@ -36,8 +36,13 @@ class UserResource extends Resource
|
||||
->maxLength(255),
|
||||
Forms\Components\TextInput::make('email')
|
||||
// ->email()
|
||||
->unique(ignoreRecord: true)
|
||||
->required()
|
||||
->readOnly()
|
||||
// ->rule(function (callable $get) {
|
||||
// return Rule::unique('users', 'email')
|
||||
// ->ignore($get('id')); // Ignore current record during updates
|
||||
// })
|
||||
->reactive()
|
||||
//->prefix(fn ($get) => $get('name') ?? null)
|
||||
// ->suffix('@cripumps.com')
|
||||
@@ -61,6 +66,9 @@ class UserResource extends Resource
|
||||
->multiple()
|
||||
->preload()
|
||||
->searchable(),
|
||||
Forms\Components\TextInput::make('id')
|
||||
->hidden()
|
||||
->readOnly(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,13 +7,18 @@ use App\Filament\Imports\WeightValidationImporter;
|
||||
use App\Filament\Resources\WeightValidationResource\Pages;
|
||||
use App\Filament\Resources\WeightValidationResource\RelationManagers;
|
||||
use App\Models\Item;
|
||||
use App\Models\Line;
|
||||
use App\Models\Plant;
|
||||
use App\Models\QualityValidation;
|
||||
use App\Models\StickerMaster;
|
||||
use App\Models\WeightValidation;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
use Filament\Forms\Components\FileUpload;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Forms\Get;
|
||||
use Filament\Notifications\Notification;
|
||||
@@ -28,6 +33,7 @@ use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use Str;
|
||||
use Filament\Tables\Filters\Filter;
|
||||
|
||||
class WeightValidationResource extends Resource
|
||||
{
|
||||
@@ -147,9 +153,209 @@ class WeightValidationResource extends Resource
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
])
|
||||
// ->filters([
|
||||
// Tables\Filters\TrashedFilter::make(),
|
||||
// ])
|
||||
->filters([
|
||||
Tables\Filters\TrashedFilter::make(),
|
||||
Filter::make('advanced_filters')
|
||||
->label('Advanced Filters')
|
||||
->form([
|
||||
Select::make('Plant')
|
||||
->label('Select Plant')
|
||||
->nullable()
|
||||
->options(function () {
|
||||
return Plant::pluck('name', 'id');
|
||||
})
|
||||
->reactive(),
|
||||
// ->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
// $set('sticker_master_id', null);
|
||||
// $set('sap_msg_status', null);
|
||||
// }),
|
||||
Select::make('Item Code')
|
||||
->label('Search by Item Code')
|
||||
->nullable()
|
||||
->options(function (callable $get) {
|
||||
$plantId = $get('Plant');
|
||||
if (!$plantId) {
|
||||
return [];
|
||||
}
|
||||
return Item::where('plant_id', $plantId)->pluck('code', 'id');
|
||||
})
|
||||
->searchable()
|
||||
->reactive(),
|
||||
TextInput::make('Obd Number')
|
||||
->label('OBD Number')
|
||||
->placeholder('Enter OBD Number'),
|
||||
|
||||
Select::make('Line')
|
||||
->label('Line')
|
||||
->options(function (callable $get) {
|
||||
$plantId = $get('Plant');
|
||||
|
||||
if (!$plantId) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// Get unique line_numbers for the selected plant_id
|
||||
return WeightValidation::where('plant_id', $plantId)
|
||||
->distinct()
|
||||
->orderBy('line_number')
|
||||
->pluck('line_number', 'line_number')
|
||||
->toArray();
|
||||
})
|
||||
->reactive(),
|
||||
|
||||
TextInput::make('Batch')
|
||||
->label('Batch Number')
|
||||
->placeholder('Enter Batch Number'),
|
||||
|
||||
TextInput::make('Actual Weight')
|
||||
->label('Actual Weight')
|
||||
->placeholder('Enter Actual Weight'),
|
||||
|
||||
TextInput::make('Vehicle Number')
|
||||
->label('Vehicle Number')
|
||||
->placeholder('Enter Vehicle Number'),
|
||||
|
||||
TextInput::make('Heat Number')
|
||||
->label('Heat Number')
|
||||
->placeholder('Enter Heat Number'),
|
||||
|
||||
TextInput::make('Bundle Number')
|
||||
->label('Bundle Number')
|
||||
->placeholder('Enter Bundle Number'),
|
||||
|
||||
TextInput::make('Scanned By')
|
||||
->label('Scanned By')
|
||||
->placeholder('Enter Scanned By'),
|
||||
|
||||
DateTimePicker::make(name: 'created_from')
|
||||
->label('Created From')
|
||||
->placeholder(placeholder: 'Select From DateTime')
|
||||
->reactive()
|
||||
->native(false),
|
||||
DateTimePicker::make('created_to')
|
||||
->label('Created To')
|
||||
->placeholder(placeholder: 'Select To DateTime')
|
||||
->reactive()
|
||||
->native(false),
|
||||
])
|
||||
->query(function ($query, array $data) {
|
||||
//Hide all records initially if no filters are applied
|
||||
if (empty($data['Plant']) && empty($data['Item Code']) && empty($data['Line']) && empty($data['Obd Number']) && empty($data['Batch']) && empty($data['Actual Weight']) && empty($data['Vehicle Number']) && empty($data['Heat Number']) && empty($data['Bundle Number']) && empty($data['Scanned By']) && empty($data['created_from']) && empty($data['created_to'])) {
|
||||
return $query->whereRaw('1 = 0');
|
||||
}
|
||||
|
||||
if (!empty($data['Plant'])) {
|
||||
$query->where('plant_id', $data['Plant']);
|
||||
}
|
||||
|
||||
if (!empty($data['Item Code'])) {
|
||||
$query->where('item_id', $data['Item Code']);
|
||||
}
|
||||
|
||||
if (!empty($data['Line'])) {
|
||||
$query->where('line_number', $data['Line']);
|
||||
}
|
||||
|
||||
if (!empty($data['Obd Number'])) {
|
||||
$query->where('obd_number', $data['Obd Number']);
|
||||
}
|
||||
|
||||
if (!empty($data['Batch'])) {
|
||||
$query->where('batch_number', $data['Batch']);
|
||||
}
|
||||
|
||||
if (!empty($data['Actual Weight'])) {
|
||||
$query->where('actual_weight', $data['Actual Weight']);
|
||||
}
|
||||
|
||||
if (!empty($data['Vehicle Number'])) {
|
||||
$query->where('vehicle_number',$data['Vehicle Number']);
|
||||
}
|
||||
|
||||
if (!empty($data['Heat Number'])) {
|
||||
$query->where('heat_number',$data['Heat Number']);
|
||||
}
|
||||
|
||||
if (!empty($data['Bundle Number'])) {
|
||||
$query->where('bundle_number',$data['Bundle Number']);
|
||||
}
|
||||
|
||||
if (!empty($data['Scanned By'])) {
|
||||
$query->where('scanned_by', $data['Scanned By']);
|
||||
}
|
||||
|
||||
|
||||
if (!empty($data['created_from'])) {
|
||||
$query->where('created_at', '>=', $data['created_from']);
|
||||
}
|
||||
|
||||
if (!empty($data['created_to'])) {
|
||||
$query->where('created_at', '<=', $data['created_to']);
|
||||
}
|
||||
})
|
||||
->indicateUsing(function (array $data) {
|
||||
$indicators = [];
|
||||
|
||||
if (!empty($data['Plant'])) {
|
||||
$indicators[] = 'Plant: ' . Plant::where('id', $data['Plant'])->value('name');
|
||||
}
|
||||
|
||||
if (!empty($data['Item Code'])) {
|
||||
$indicators[] = 'Item Code: ' . $data['Item Code'];
|
||||
}
|
||||
|
||||
if (!empty($data['Line'])) {
|
||||
$indicators[] = 'Line: ' . $data['Line'];
|
||||
}
|
||||
|
||||
if (!empty($data['Obd Number'])) {
|
||||
$indicators[] = 'OBD Number: ' . $data['Obd Number'];
|
||||
}
|
||||
|
||||
if (!empty($data['Batch'])) {
|
||||
$indicators[] = 'Batch Number: ' . $data['Batch'];
|
||||
}
|
||||
|
||||
if (!empty($data['Actual Weight'])) {
|
||||
$indicators[] = 'Actual Weight: ' . $data['Actual Weight'];
|
||||
}
|
||||
|
||||
if (!empty($data['Vehicle Number'])) {
|
||||
$indicators[] = 'Vehicle Number: ' . $data['Vehicle Number'];
|
||||
}
|
||||
|
||||
if (!empty($data['Heat Number'])) {
|
||||
$indicators[] = 'Heat Number: ' . $data['Heat Number'];
|
||||
}
|
||||
|
||||
if (!empty($data['Bundle Number'])) {
|
||||
$indicators[] = 'Bundle Number: ' . $data['Bundle Number'];
|
||||
}
|
||||
|
||||
if (!empty($data['Scanned By'])) {
|
||||
$indicators[] = 'Scanned By: ' . $data['Scanned By'];
|
||||
}
|
||||
|
||||
if (!empty($data['created_from'])) {
|
||||
$indicators[] = 'From: ' . $data['created_from'];
|
||||
}
|
||||
|
||||
if (!empty($data['created_to'])) {
|
||||
$indicators[] = 'To: ' . $data['created_to'];
|
||||
}
|
||||
|
||||
if (!empty($data['sticker_master_id'])) {
|
||||
$itemCode = Item::find($data['sticker_master_id'])->code ?? 'Unknown';
|
||||
$indicators[] = 'Item Codes: ' . $itemCode;
|
||||
}
|
||||
|
||||
return $indicators;
|
||||
})
|
||||
])
|
||||
->filtersFormMaxHeight('280px')
|
||||
->actions([
|
||||
Tables\Actions\ViewAction::make(),
|
||||
Tables\Actions\EditAction::make(),
|
||||
|
||||
73
app/Http/Controllers/MachineController.php
Normal file
73
app/Http/Controllers/MachineController.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Machine;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class MachineController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function get_all_data(Request $request)
|
||||
{
|
||||
$expectedUser = env('API_AUTH_USER');
|
||||
$expectedPw = env('API_AUTH_PW');
|
||||
$header_auth = $request->header('Authorization');
|
||||
$expectedToken = $expectedUser . ':' . $expectedPw;
|
||||
|
||||
if ("Bearer " . $expectedToken != $header_auth)
|
||||
{
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => 'Invalid authorization token!'
|
||||
], 403);
|
||||
}
|
||||
|
||||
$machines = Machine::with('plant')->with('line')->orderBy('plant_id')->get();
|
||||
$machinesData = $machines->map(function($machine) {
|
||||
return [
|
||||
'plant_code' => $machine->plant ? (String)$machine->plant->code : "",
|
||||
'group_work_center' => $machine->line->group_work_center ?? "",
|
||||
'work_center' => $machine->work_center ?? "",
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json([
|
||||
'machines' => $machinesData
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
205
app/Http/Controllers/MfmParameterController.php
Normal file
205
app/Http/Controllers/MfmParameterController.php
Normal file
@@ -0,0 +1,205 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\MfmMeter;
|
||||
use App\Models\MfmParameter;
|
||||
use App\Models\Plant;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class MfmParameterController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
}
|
||||
public function get_mfm_parameterid(Request $request)
|
||||
{
|
||||
$expectedUser = env('API_AUTH_USER');
|
||||
$expectedPw = env('API_AUTH_PW');
|
||||
$header_auth = $request->header('Authorization');
|
||||
$expectedToken = $expectedUser . ':' . $expectedPw;
|
||||
|
||||
if ("Bearer " . $expectedToken != $header_auth) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => 'Invalid authorization token!'
|
||||
], 403);
|
||||
}
|
||||
|
||||
$plantCode = $request->header('plant-code');
|
||||
|
||||
if (!$plantCode) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Plant Code value can't be empty"
|
||||
], 404);
|
||||
}
|
||||
|
||||
$plant = Plant::where('code', $plantCode)->first();
|
||||
|
||||
if (!$plant)
|
||||
{
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Plant Code '{$plantCode}' not found!"
|
||||
], 404);
|
||||
}
|
||||
|
||||
|
||||
// $sequences = MfmMeter::where('plant_id', $plant->id)
|
||||
// ->whereNotNull('sequence')
|
||||
// ->distinct()
|
||||
// ->orderBy('sequence', 'asc')
|
||||
// ->pluck('sequence');
|
||||
$sequences = MfmMeter::where('plant_id', $plant->id)
|
||||
->whereNotNull('sequence')
|
||||
->pluck('sequence')
|
||||
->unique()
|
||||
->map(fn($s) => is_numeric($s) ? (int) $s : $s)
|
||||
->sort()
|
||||
->values();
|
||||
|
||||
if ($sequences->isEmpty())
|
||||
{
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => 'No sequences found for the given plant.'
|
||||
], 404);
|
||||
}
|
||||
|
||||
|
||||
return response()->json([
|
||||
'status_code' => 'SUCCESS',
|
||||
'status_description' => $sequences
|
||||
], 200);
|
||||
|
||||
}
|
||||
|
||||
public function get_mfm_parameter(Request $request)
|
||||
{
|
||||
$expectedUser = env('API_AUTH_USER');
|
||||
$expectedPw = env('API_AUTH_PW');
|
||||
$header_auth = $request->header('Authorization');
|
||||
$expectedToken = $expectedUser . ':' . $expectedPw;
|
||||
|
||||
if ("Bearer " . $expectedToken != $header_auth) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => 'Invalid authorization token!'
|
||||
], 403);
|
||||
}
|
||||
|
||||
$plantCode = $request->header('plant-code');
|
||||
$mfmParameterSeq = $request->header('mfm-meter-sequence');
|
||||
|
||||
if (!$plantCode) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Plant Code value can't be empty"
|
||||
], 404);
|
||||
}
|
||||
else if (!$mfmParameterSeq) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Mfm Parameter sequence value can't be empty"
|
||||
], 404);
|
||||
}
|
||||
|
||||
$plant = Plant::where('code', $plantCode)->first();
|
||||
|
||||
if (!$plant)
|
||||
{
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Plant Code '{$plantCode}' not found!"
|
||||
], 404);
|
||||
}
|
||||
// Find mfm_meter by sequence and plant_id
|
||||
$mfmMeter = MfmMeter::where('sequence', trim($mfmParameterSeq))
|
||||
->where('plant_id', $plant->id)
|
||||
->first();
|
||||
|
||||
if (!$mfmMeter) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "MFM Meter with sequence '{$mfmParameterSeq}' not found for plant code '{$plantCode}'"
|
||||
], 404);
|
||||
}
|
||||
|
||||
// Now fetch mfm_parameters for this plant and meter
|
||||
$mfmParameters = MfmParameter::where('plant_id', $plant->id)
|
||||
->where('mfm_meter_id', $mfmMeter->id)
|
||||
->get(['register_id', 'byte_to_convert', 'type_to_convert', 'decimal_to_display']);
|
||||
|
||||
$transformed = $mfmParameters->map(function ($item) {
|
||||
$array = $item->toArray();
|
||||
foreach ($array as $key => $value) {
|
||||
if (is_null($value)) {
|
||||
$array[$key] = "";
|
||||
}
|
||||
}
|
||||
return $array;
|
||||
});
|
||||
|
||||
//..if want to send all values in string
|
||||
// $transformed = $mfmParameters->map(function ($item) {
|
||||
// $array = $item->toArray();
|
||||
// foreach ($array as $key => $value) {
|
||||
// // Always cast to string (empty string if null)
|
||||
// $array[$key] = is_null($value) ? "" : strval($value);
|
||||
// }
|
||||
// return $array;
|
||||
// });
|
||||
|
||||
|
||||
if ($transformed->isEmpty()) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "No MFM parameters found for the specified plant and meter."
|
||||
], 404);
|
||||
}
|
||||
|
||||
// Success: return list
|
||||
return response()->json([
|
||||
'status_code' => 'SUCCESS',
|
||||
'status_description' => $transformed
|
||||
], 200);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
103
app/Http/Controllers/ModuleChartController.php
Normal file
103
app/Http/Controllers/ModuleChartController.php
Normal file
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\ModuleList;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ModuleChartController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function get_moduleChart(Request $request)
|
||||
{
|
||||
$expectedUser = env('API_AUTH_USER');
|
||||
$expectedPw = env('API_AUTH_PW');
|
||||
|
||||
$header_auth = $request->header('Authorization');
|
||||
$expectedToken = $expectedUser . ':' . $expectedPw;
|
||||
|
||||
if ("Bearer " . $expectedToken != $header_auth)
|
||||
{
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => 'Invalid authorization token!'
|
||||
], 403);
|
||||
}
|
||||
|
||||
$moduleName = $request->header('module-name');
|
||||
|
||||
if (empty($moduleName))
|
||||
{
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Module Name can't be empty!"
|
||||
], 404);
|
||||
}
|
||||
|
||||
$exists = ModuleList::where('module_name', $moduleName)->exists();
|
||||
|
||||
if (!$exists) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Module Name '{$moduleName}' not found in system!"
|
||||
], 404);
|
||||
}
|
||||
|
||||
// Fetch all unique dashboard names for the given module_name
|
||||
// $dashboardNames = ModuleList::where('module_name', $moduleName)
|
||||
// ->distinct()
|
||||
// ->pluck('dashboard_name');
|
||||
$dashboardNames = ModuleList::where('module_name', $moduleName)
|
||||
->orderBy('created_at', 'asc')
|
||||
->get()
|
||||
->unique('dashboard_name')
|
||||
->pluck('dashboard_name')
|
||||
->values(); // reset array keys
|
||||
|
||||
|
||||
return response()->json([
|
||||
'status_code' => 'SUCCESS',
|
||||
'status_description' => $dashboardNames
|
||||
], 200);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
105
app/Http/Controllers/ModuleController.php
Normal file
105
app/Http/Controllers/ModuleController.php
Normal file
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\ModuleList;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ModuleController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
// public function show(string $id)
|
||||
// {
|
||||
// //
|
||||
// }
|
||||
|
||||
public function get_module(Request $request)
|
||||
{
|
||||
$expectedUser = env('API_AUTH_USER');
|
||||
$expectedPw = env('API_AUTH_PW');
|
||||
|
||||
$header_auth = $request->header('Authorization');
|
||||
$expectedToken = $expectedUser . ':' . $expectedPw;
|
||||
|
||||
if ("Bearer " . $expectedToken != $header_auth)
|
||||
{
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => 'Invalid authorization token!'
|
||||
], 403);
|
||||
}
|
||||
|
||||
$moduleName = $request->header('module-name');
|
||||
|
||||
if (empty($moduleName))
|
||||
{
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Module Name can't be empty!"
|
||||
], 404);
|
||||
}
|
||||
|
||||
$headerValue = $request->header('module-name');
|
||||
|
||||
if ($headerValue != 'Module List') {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Invalid value for 'module-name' header!"
|
||||
], 404);
|
||||
}
|
||||
|
||||
$uniqueModules = ModuleList::select('module_name', 'created_at')
|
||||
->orderBy('created_at', 'asc')
|
||||
->get()
|
||||
->unique('module_name')
|
||||
->pluck('module_name')
|
||||
->values();
|
||||
|
||||
if ($uniqueModules->isEmpty()) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => 'Module names not found'
|
||||
], 404);
|
||||
}
|
||||
|
||||
|
||||
return response()->json([
|
||||
'status_code' => 'SUCCESS',
|
||||
'status_description' => $uniqueModules
|
||||
], 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
106
app/Http/Controllers/ModuleFGLineController.php
Normal file
106
app/Http/Controllers/ModuleFGLineController.php
Normal file
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Line;
|
||||
use App\Models\ModuleList;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ModuleFGLineController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function get_moduleFGFilter(Request $request)
|
||||
{
|
||||
$expectedUser = env('API_AUTH_USER');
|
||||
$expectedPw = env('API_AUTH_PW');
|
||||
|
||||
$header_auth = $request->header('Authorization');
|
||||
$expectedToken = $expectedUser . ':' . $expectedPw;
|
||||
|
||||
if ("Bearer " . $expectedToken != $header_auth)
|
||||
{
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => 'Invalid authorization token!'
|
||||
], 403);
|
||||
}
|
||||
|
||||
$lineName = $request->header('line-name');
|
||||
|
||||
if (empty($lineName))
|
||||
{
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Line name can't be empty!"
|
||||
], 404);
|
||||
}
|
||||
|
||||
|
||||
$line = Line::where('name', $lineName)->first();
|
||||
|
||||
if (!$line) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Line '{$lineName}' not found!"
|
||||
], 404);
|
||||
}
|
||||
|
||||
if ($line->type !== 'FG Line') {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Line '{$lineName}' is not of type FG Line."
|
||||
], 400);
|
||||
}
|
||||
// Default logic to return filter names
|
||||
$filterNames = ModuleList::orderBy('created_at', 'asc')
|
||||
->get()
|
||||
->unique('filter_name')
|
||||
->pluck('filter_name')
|
||||
->filter()
|
||||
->values();
|
||||
|
||||
return response()->json([
|
||||
'status_code' => 'SUCCESS',
|
||||
'status_description' => $filterNames
|
||||
], 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
119
app/Http/Controllers/ModuleFilterController.php
Normal file
119
app/Http/Controllers/ModuleFilterController.php
Normal file
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\ModuleList;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ModuleFilterController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function get_moduleFilter(Request $request)
|
||||
{
|
||||
$expectedUser = env('API_AUTH_USER');
|
||||
$expectedPw = env('API_AUTH_PW');
|
||||
|
||||
$header_auth = $request->header('Authorization');
|
||||
$expectedToken = $expectedUser . ':' . $expectedPw;
|
||||
|
||||
if ("Bearer " . $expectedToken != $header_auth)
|
||||
{
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => 'Invalid authorization token!'
|
||||
], 403);
|
||||
}
|
||||
|
||||
$lineName = $request->header('line-name');
|
||||
|
||||
if (empty($lineName))
|
||||
{
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Line name can't be empty!"
|
||||
], 404);
|
||||
}
|
||||
// If 'line-name' is 'FG Lines', return actual FG Line names
|
||||
if (strtolower(trim($lineName)) == 'fg lines') {
|
||||
$fgLines = \App\Models\Line::where('type', 'FG Line')
|
||||
->orderBy('created_at', 'asc')
|
||||
->pluck('name');
|
||||
|
||||
if ($fgLines->isEmpty()) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => 'No FG Lines found!'
|
||||
], 404);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'status_code' => 'SUCCESS',
|
||||
'status_description' => $fgLines
|
||||
], 200);
|
||||
}
|
||||
|
||||
// Default logic to return filter names
|
||||
$filterNames = ModuleList::orderBy('created_at', 'asc')
|
||||
->get()
|
||||
->unique('filter_name')
|
||||
->pluck('filter_name')
|
||||
->filter()
|
||||
->values();
|
||||
|
||||
return response()->json([
|
||||
'status_code' => 'SUCCESS',
|
||||
'status_description' => $filterNames
|
||||
], 200);
|
||||
|
||||
// $filterNames = ModuleList::orderBy('created_at', 'asc')
|
||||
// ->get()
|
||||
// ->unique('filter_name')
|
||||
// ->pluck('filter_name')
|
||||
// ->filter()
|
||||
// ->values();
|
||||
|
||||
// return response()->json([
|
||||
// 'status_code' => 'SUCCESS',
|
||||
// 'status_description' => $filterNames
|
||||
// ], 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
573
app/Http/Controllers/ModuleFilterDataController.php
Normal file
573
app/Http/Controllers/ModuleFilterDataController.php
Normal file
@@ -0,0 +1,573 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Line;
|
||||
use App\Models\Plant;
|
||||
use App\Models\ProductionQuantity;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ModuleFilterDataController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
// public function get_moduleFilterData(Request $request)
|
||||
// {
|
||||
// $expectedUser = env('API_AUTH_USER');
|
||||
// $expectedPw = env('API_AUTH_PW');
|
||||
|
||||
// $header_auth = $request->header('Authorization');
|
||||
// $expectedToken = $expectedUser . ':' . $expectedPw;
|
||||
|
||||
// if ("Bearer " . $expectedToken != $header_auth)
|
||||
// {
|
||||
// return response()->json([
|
||||
// 'status_code' => 'ERROR',
|
||||
// 'status_description' => 'Invalid authorization token!'
|
||||
// ], 403);
|
||||
// }
|
||||
|
||||
// $moduleName = $request->header('module-name');
|
||||
// $chartName = $request->header('chart-name');
|
||||
// $plantName = $request->header('plant-name');
|
||||
// $lineName = $request->header('line-name');
|
||||
// $filterName = $request->header('filter-name');
|
||||
|
||||
// $requiredHeaders = [
|
||||
// 'module-name',
|
||||
// 'chart-name',
|
||||
// 'plant-name',
|
||||
// 'line-name',
|
||||
// 'filter-name',
|
||||
// ];
|
||||
|
||||
// $missingHeaders = [];
|
||||
|
||||
// foreach ($requiredHeaders as $header) {
|
||||
// if (empty($request->header($header))) {
|
||||
// $missingHeaders[] = $header;
|
||||
// }
|
||||
// }
|
||||
|
||||
// if (!empty($missingHeaders)) {
|
||||
// return response()->json([
|
||||
// 'status_code' => 'ERROR',
|
||||
// 'status_description' => 'Missing required headers: ' . implode(', ', $missingHeaders)
|
||||
// ], 400);
|
||||
// }
|
||||
|
||||
// // Fetch plant ID
|
||||
// $plant = Plant::where('name', $plantName)->first();
|
||||
// if (!$plant) {
|
||||
// return response()->json([
|
||||
// 'status_code' => 'ERROR',
|
||||
// 'status_description' => "Plant '{$plantName}' not found!"
|
||||
// ], 404);
|
||||
// }
|
||||
|
||||
// // Fetch line ID
|
||||
// $line = Line::where('name', $lineName)->where('plant_id', $plant->id)->first();
|
||||
// if (!$line) {
|
||||
// return response()->json([
|
||||
// 'status_code' => 'ERROR',
|
||||
// 'status_description' => "Line '{$lineName}' not found for plant '{$plantName}'"
|
||||
// ], 404);
|
||||
// }
|
||||
|
||||
// $activeFilter = strtolower(trim($request->header('filter-name')));
|
||||
|
||||
// if ($activeFilter == 'yesterday') {
|
||||
// $startDate = now()->subDay()->setTime(8, 0, 0);
|
||||
// $endDate = now()->setTime(8, 0, 0);
|
||||
// }
|
||||
// elseif ($activeFilter == 'this week') {
|
||||
// $startDate = now()->startOfWeek()->setTime(8, 0, 0);
|
||||
// $endDate = now()->endOfWeek()->addDay()->setTime(8, 0, 0);
|
||||
// }
|
||||
// elseif ($activeFilter == 'this month') {
|
||||
// $startDate = now()->startOfMonth();
|
||||
// $endDate = now()->endOfMonth();
|
||||
// }
|
||||
// else {
|
||||
// $startDate = now()->setTime(8, 0, 0);
|
||||
// $endDate = now()->copy()->addDay()->setTime(8, 0, 0);
|
||||
// }
|
||||
|
||||
// $rowCount = ProductionQuantity::where('plant_id', $plant->id)
|
||||
// ->where('line_id', $line->id)
|
||||
// ->whereBetween('created_at', [$startDate, $endDate])
|
||||
// ->count();
|
||||
|
||||
// return response()->json([
|
||||
// 'status_code' => 'SUCCESS',
|
||||
// 'status_description' => $rowCount
|
||||
// ], 200);
|
||||
// }
|
||||
|
||||
// public function get_moduleFilterData(Request $request)
|
||||
// {
|
||||
// $expectedUser = env('API_AUTH_USER');
|
||||
// $expectedPw = env('API_AUTH_PW');
|
||||
|
||||
// $header_auth = $request->header('Authorization');
|
||||
// $expectedToken = $expectedUser . ':' . $expectedPw;
|
||||
|
||||
// if ("Bearer " . $expectedToken != $header_auth) {
|
||||
// return response()->json([
|
||||
// 'status_code' => 'ERROR',
|
||||
// 'status_description' => 'Invalid authorization token!'
|
||||
// ], 403);
|
||||
// }
|
||||
|
||||
// $requiredHeaders = [
|
||||
// 'module-name',
|
||||
// 'chart-name',
|
||||
// 'plant-name',
|
||||
// 'line-name',
|
||||
// 'filter-name',
|
||||
// ];
|
||||
|
||||
// $missingHeaders = [];
|
||||
|
||||
// foreach ($requiredHeaders as $header) {
|
||||
// if (empty($request->header($header))) {
|
||||
// $missingHeaders[] = $header;
|
||||
// }
|
||||
// }
|
||||
|
||||
// if (!empty($missingHeaders)) {
|
||||
// return response()->json([
|
||||
// 'status_code' => 'ERROR',
|
||||
// 'status_description' => 'Missing required headers: ' . implode(', ', $missingHeaders)
|
||||
// ], 404);
|
||||
// }
|
||||
|
||||
// $validFilters = ['Today', 'Yesterday', 'This Week', 'This Month'];
|
||||
// $filterHeader = $request->header('filter-name');
|
||||
|
||||
// if (!in_array($filterHeader, $validFilters)) {
|
||||
// return response()->json([
|
||||
// 'status_code' => 'ERROR',
|
||||
// 'status_description' => "Invalid filter-name value! Accepted values are: " . implode(', ', $validFilters)
|
||||
// ], 404);
|
||||
// }
|
||||
|
||||
// $plantName = $request->header('plant-name');
|
||||
// $lineName = $request->header('line-name');
|
||||
// $filterName = strtolower(trim($request->header('filter-name')));
|
||||
|
||||
// $plant = Plant::where('name', $plantName)->first();
|
||||
// if (!$plant) {
|
||||
// return response()->json([
|
||||
// 'status_code' => 'ERROR',
|
||||
// 'status_description' => "Plant '{$plantName}' not found!"
|
||||
// ], 404);
|
||||
// }
|
||||
|
||||
// // Set date filter range
|
||||
// if ($filterName == 'yesterday') {
|
||||
// $startDate = now()->subDay()->setTime(8, 0, 0);
|
||||
// $endDate = now()->setTime(8, 0, 0);
|
||||
// } elseif ($filterName == 'this week') {
|
||||
// $startDate = now()->startOfWeek()->setTime(8, 0, 0);
|
||||
// $endDate = now()->endOfWeek()->addDay()->setTime(8, 0, 0);
|
||||
// } elseif ($filterName == 'this month') {
|
||||
// $startDate = now()->startOfMonth();
|
||||
// $endDate = now()->endOfMonth();
|
||||
// } else {
|
||||
// $startDate = now()->setTime(8, 0, 0);
|
||||
// $endDate = now()->copy()->addDay()->setTime(8, 0, 0);
|
||||
// }
|
||||
|
||||
// // Handle All Lines
|
||||
// if (strtolower(trim($lineName)) == 'all lines') {
|
||||
// $lines = Line::where('plant_id', $plant->id)->pluck('id', 'name');
|
||||
|
||||
// if ($lines->isEmpty()) {
|
||||
// return response()->json([
|
||||
// 'status_code' => 'ERROR',
|
||||
// 'status_description' => "No lines found for plant '{$plantName}'"
|
||||
// ], 404);
|
||||
// }
|
||||
|
||||
// $lineCounts = [];
|
||||
|
||||
// foreach ($lines as $name => $id) {
|
||||
// $count = ProductionQuantity::where('plant_id', $plant->id)
|
||||
// ->where('line_id', $id)
|
||||
// ->whereBetween('created_at', [$startDate, $endDate])
|
||||
// ->count();
|
||||
|
||||
// $lineCounts[$name] = $count;
|
||||
// }
|
||||
|
||||
// return response()->json([
|
||||
// 'status_code' => 'SUCCESS',
|
||||
// 'status_description' => $lineCounts
|
||||
// ], 200);
|
||||
// }
|
||||
|
||||
// // Handle single line
|
||||
// $line = Line::where('name', $lineName)->where('plant_id', $plant->id)->first();
|
||||
// if (!$line) {
|
||||
// return response()->json([
|
||||
// 'status_code' => 'ERROR',
|
||||
// 'status_description' => "Line '{$lineName}' not found for plant '{$plantName}'"
|
||||
// ], 404);
|
||||
// }
|
||||
|
||||
// $rowCount = ProductionQuantity::where('plant_id', $plant->id)
|
||||
// ->where('line_id', $line->id)
|
||||
// ->whereBetween('created_at', [$startDate, $endDate])
|
||||
// ->count();
|
||||
|
||||
// $chartName = $request->header('chart-name');
|
||||
|
||||
// if ($chartName == 'Production Hourly Count')
|
||||
// {
|
||||
|
||||
// if ($filterHeader == 'Today' || $filterHeader == 'Yesterday') {
|
||||
// $hourlyCounts = [];
|
||||
|
||||
// $hourStart = now()->startOfDay()->addHours(8); // Today 8:00 AM
|
||||
// if ($filterHeader == 'Yesterday') {
|
||||
// $hourStart->subDay(); // Yesterday 8:00 AM
|
||||
// }
|
||||
|
||||
// $hourEndFinal = $hourStart->copy()->addDay(); // +1 day = 24 hourly slots
|
||||
|
||||
// while ($hourStart < $hourEndFinal) {
|
||||
// $hourEnd = $hourStart->copy()->addHour();
|
||||
|
||||
// $label = $hourStart->format('g:i A') . ' to ' . $hourEnd->format('g:i A');
|
||||
|
||||
// $count = ProductionQuantity::where('plant_id', $plant->id)
|
||||
// ->where('line_id', $line->id)
|
||||
// ->whereBetween('created_at', [$hourStart, $hourEnd])
|
||||
// ->count();
|
||||
|
||||
// $hourlyCounts[$label] = $count;
|
||||
|
||||
// $hourStart = $hourEnd;
|
||||
// }
|
||||
|
||||
// return response()->json([
|
||||
// 'status_code' => 'SUCCESS',
|
||||
// 'hourly_data' => $hourlyCounts
|
||||
// ], 200);
|
||||
// }
|
||||
|
||||
// // THIS WEEK: group by weekdays (Mon to Sun)
|
||||
// if ($filterHeader == 'This Week') {
|
||||
// $dowCounts = ProductionQuantity::selectRaw('EXTRACT(DOW FROM created_at) as dow, COUNT(*) as total')
|
||||
// ->where('plant_id', $plant->id)
|
||||
// ->where('line_id', $line->id)
|
||||
// ->whereBetween('created_at', [$startDate, $endDate])
|
||||
// ->groupBy('dow')
|
||||
// ->pluck('total', 'dow');
|
||||
|
||||
// $labels = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];
|
||||
// $data = array_fill(0, 7, 0);
|
||||
|
||||
// foreach ($dowCounts as $dow => $count) {
|
||||
// $data[$dow] = $count;
|
||||
// }
|
||||
|
||||
// // Reorder from Monday (1) to Sunday (0)
|
||||
// $orderedData = [
|
||||
// $data[1] ?? 0,
|
||||
// $data[2] ?? 0,
|
||||
// $data[3] ?? 0,
|
||||
// $data[4] ?? 0,
|
||||
// $data[5] ?? 0,
|
||||
// $data[6] ?? 0,
|
||||
// $data[0] ?? 0
|
||||
// ];
|
||||
|
||||
// return response()->json([
|
||||
// 'status_code' => 'SUCCESS',
|
||||
// 'weekly_labels' => $labels,
|
||||
// 'weekly_counts' => $orderedData
|
||||
// ], 200);
|
||||
// }
|
||||
|
||||
// //THIS MONTH: group by weeks
|
||||
// if ($filterHeader == 'This Month') {
|
||||
// // Count records grouped by week number
|
||||
// $weekCounts = ProductionQuantity::selectRaw("FLOOR((EXTRACT(DAY FROM created_at) - 1) / 7) + 1 as week_number, COUNT(*) as total")
|
||||
// ->where('plant_id', $plant->id)
|
||||
// ->where('line_id', $line->id)
|
||||
// ->whereBetween('created_at', [$startDate, $endDate])
|
||||
// ->groupBy('week_number')
|
||||
// ->pluck('total', 'week_number');
|
||||
|
||||
// $weeksCount = ceil($endDate->day / 7); // Total number of weeks in month
|
||||
// $allWeeks = array_fill(1, $weeksCount, 0);
|
||||
// $data = array_replace($allWeeks, $weekCounts->toArray());
|
||||
|
||||
// // Prepare labels like Week 1 (01 Jul - 07 Jul)
|
||||
// $labels = [];
|
||||
// for ($i = 1; $i <= $weeksCount; $i++) {
|
||||
// $weekStart = $startDate->copy()->addDays(($i - 1) * 7);
|
||||
// $weekEnd = $startDate->copy()->addDays($i * 7 - 1)->min($endDate);
|
||||
|
||||
// $labels[] = "Week $i ({$weekStart->format('d M')} - {$weekEnd->format('d M')})";
|
||||
// }
|
||||
|
||||
// $orderedData = array_values($data);
|
||||
|
||||
// return response()->json([
|
||||
// 'status_code' => 'SUCCESS',
|
||||
// 'monthly_labels' => $labels,
|
||||
// 'monthly_counts' => $orderedData
|
||||
// ], 200);
|
||||
// }
|
||||
// }
|
||||
|
||||
// if ($chartName == 'Production Line Count')
|
||||
// {
|
||||
// return response()->json([
|
||||
// 'status_code' => 'SUCCESS',
|
||||
// 'status_description' => $rowCount
|
||||
// ], 200);
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
public function get_moduleFilterData(Request $request)
|
||||
{
|
||||
$expectedUser = env('API_AUTH_USER');
|
||||
$expectedPw = env('API_AUTH_PW');
|
||||
|
||||
$header_auth = $request->header('Authorization');
|
||||
$expectedToken = $expectedUser . ':' . $expectedPw;
|
||||
|
||||
if ("Bearer " . $expectedToken != $header_auth) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => 'Invalid authorization token!'
|
||||
], 403);
|
||||
}
|
||||
|
||||
$requiredHeaders = [
|
||||
'module-name', 'chart-name', 'plant-name', 'line-name', 'filter-name'
|
||||
];
|
||||
|
||||
$missingHeaders = [];
|
||||
foreach ($requiredHeaders as $header) {
|
||||
if (empty($request->header($header))) {
|
||||
$missingHeaders[] = $header;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($missingHeaders)) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => 'Missing required headers: ' . implode(', ', $missingHeaders)
|
||||
], 404);
|
||||
}
|
||||
|
||||
$validFilters = ['Today', 'Yesterday', 'This Week', 'This Month'];
|
||||
$filterHeader = $request->header('filter-name');
|
||||
|
||||
if (!in_array($filterHeader, $validFilters)) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Invalid filter-name value! Accepted values are: " . implode(', ', $validFilters)
|
||||
], 404);
|
||||
}
|
||||
|
||||
$plantName = $request->header('plant-name');
|
||||
$lineName = $request->header('line-name');
|
||||
$filterName = strtolower(trim($request->header('filter-name')));
|
||||
$chartName = $request->header('chart-name');
|
||||
|
||||
$plant = Plant::where('name', $plantName)->first();
|
||||
if (!$plant) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Plant '{$plantName}' not found!"
|
||||
], 404);
|
||||
}
|
||||
|
||||
$isAllLines = strtolower(trim($lineName)) == 'all lines';
|
||||
|
||||
if ($isAllLines) {
|
||||
$lines = Line::where('plant_id', $plant->id)->get();
|
||||
$fgLineIds = $lines->where('type', 'FG Line')->pluck('id')->toArray();
|
||||
$nonFgLineIds = $lines->where('type', '!=', 'FG Line')->pluck('id')->toArray();
|
||||
} else {
|
||||
$line = Line::where('name', $lineName)->where('plant_id', $plant->id)->first();
|
||||
if (!$line) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Line '{$lineName}' not found for plant '{$plantName}'"
|
||||
], 404);
|
||||
}
|
||||
$lineIds = [$line->id];
|
||||
$isFgLine = $line->type == 'FG Line';
|
||||
$baseTable = $isFgLine ? 'quality_validations' : 'production_quantities';
|
||||
}
|
||||
|
||||
if ($filterName == 'yesterday') {
|
||||
$startDate = now()->subDay()->setTime(8, 0, 0);
|
||||
$endDate = now()->setTime(8, 0, 0);
|
||||
$groupBy = 'EXTRACT(HOUR FROM created_at)';
|
||||
} elseif ($filterName == 'this week') {
|
||||
$startDate = now()->startOfWeek()->setTime(8, 0, 0);
|
||||
$endDate = now()->endOfWeek()->addDay()->setTime(8, 0, 0);
|
||||
$groupBy = 'EXTRACT(DOW FROM created_at)';
|
||||
} elseif ($filterName == 'this month') {
|
||||
$startDate = now()->startOfMonth();
|
||||
$endDate = now()->endOfMonth();
|
||||
$groupBy = "FLOOR((EXTRACT(DAY FROM created_at) - 1) / 7) + 1";
|
||||
} else {
|
||||
$startDate = now()->setTime(8, 0, 0);
|
||||
$endDate = now()->copy()->addDay()->setTime(8, 0, 0);
|
||||
$groupBy = 'EXTRACT(HOUR FROM created_at)';
|
||||
}
|
||||
|
||||
if ($chartName == 'Production Line Count' && $isAllLines) {
|
||||
$lineCounts = [];
|
||||
foreach ($lines as $line) {
|
||||
$table = ($line->type == 'FG Line') ? 'quality_validations' : 'production_quantities';
|
||||
$count = DB::table($table)
|
||||
->where('plant_id', $plant->id)
|
||||
->where('line_id', $line->id)
|
||||
->whereBetween('created_at', [$startDate, $endDate])
|
||||
->count();
|
||||
$lineCounts[$line->name] = $count;
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'status_code' => 'SUCCESS',
|
||||
'status_description' => $lineCounts
|
||||
], 200);
|
||||
}
|
||||
|
||||
if (!$isAllLines)
|
||||
{
|
||||
$rowCount = DB::table($baseTable)
|
||||
->where('plant_id', $plant->id)
|
||||
->where('line_id', $line->id)
|
||||
->whereBetween('created_at', [$startDate, $endDate])
|
||||
->count();
|
||||
|
||||
$query = DB::table($baseTable)
|
||||
->selectRaw("$groupBy AS time_unit, COUNT(*) AS total_quantity")
|
||||
->where('created_at', '>=', $startDate)
|
||||
->where('created_at', '<', $endDate)
|
||||
->where('plant_id', $plant->id)
|
||||
->where('line_id', $line->id)
|
||||
->groupByRaw($groupBy)
|
||||
->orderByRaw($groupBy)
|
||||
->pluck('total_quantity', 'time_unit')
|
||||
->toArray();
|
||||
|
||||
if ($chartName == 'Production Hourly Count') {
|
||||
if ($filterName == 'this month') {
|
||||
$weeksCount = ceil($endDate->day / 7);
|
||||
$allWeeks = array_fill(1, $weeksCount, 0);
|
||||
$data = array_replace($allWeeks, $query);
|
||||
$labels = [];
|
||||
for ($i = 1; $i <= $weeksCount; $i++) {
|
||||
$weekStart = $startDate->copy()->addDays(($i - 1) * 7)->format('d M');
|
||||
$weekEnd = $startDate->copy()->addDays($i * 7 - 1)->min($endDate)->format('d M');
|
||||
$labels[] = "Week $i ($weekStart - $weekEnd)";
|
||||
}
|
||||
$orderedData = array_values($data);
|
||||
} elseif ($filterName == 'this week') {
|
||||
$labels = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];
|
||||
$data = array_fill(0, 7, 0);
|
||||
foreach ($query as $dow => $count) {
|
||||
$data[$dow] = $count;
|
||||
}
|
||||
$orderedData = [
|
||||
$data[1] ?? 0, $data[2] ?? 0, $data[3] ?? 0,
|
||||
$data[4] ?? 0, $data[5] ?? 0, $data[6] ?? 0,
|
||||
$data[0] ?? 0,
|
||||
];
|
||||
} else {
|
||||
$allHours = array_fill(0, 24, 0);
|
||||
$data = array_replace($allHours, $query);
|
||||
$shiftedData = [];
|
||||
foreach ($data as $hour => $count) {
|
||||
$nextHour = ($hour + 1) % 24;
|
||||
$shiftedData[$nextHour] = $count;
|
||||
}
|
||||
$shiftedKeys = array_merge(range(9, 23), range(0, 8));
|
||||
$orderedData = array_map(fn($hour) => $shiftedData[$hour] ?? 0, $shiftedKeys);
|
||||
$labels = array_map(function ($hour) {
|
||||
$prevHour = ($hour - 1 + 24) % 24;
|
||||
return date("g:i A", strtotime("$prevHour:00")) . ' to ' . date("g:i A", strtotime("$hour:00"));
|
||||
}, $shiftedKeys);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'status_code' => 'SUCCESS',
|
||||
'datasets' => [[
|
||||
'label' => match ($filterName) {
|
||||
'this week' => $isFgLine ? 'Daily FG Count This Week' : 'Daily Production This Week',
|
||||
'this month' => $isFgLine ? 'Weekly FG Count This Month' : 'Weekly Production This Month',
|
||||
'yesterday' => $isFgLine ? "Yesterday's FG Count" : "Yesterday's Hourly Production",
|
||||
default => $isFgLine ? "Today's FG Count" : "Today's Hourly Production",
|
||||
},
|
||||
'data' => $orderedData
|
||||
]],
|
||||
'labels' => $labels,
|
||||
], 200);
|
||||
}
|
||||
|
||||
if ($chartName == 'Production Line Count') {
|
||||
return response()->json([
|
||||
'status_code' => 'SUCCESS',
|
||||
'status_description' => $rowCount
|
||||
], 200);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
191
app/Http/Controllers/ModuleGuardDayCountController.php
Normal file
191
app/Http/Controllers/ModuleGuardDayCountController.php
Normal file
@@ -0,0 +1,191 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\GuardPatrolEntry;
|
||||
use App\Models\Plant;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ModuleGuardDayCountController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function get_guardDay_countData(Request $request)
|
||||
{
|
||||
$expectedUser = env('API_AUTH_USER');
|
||||
$expectedPw = env('API_AUTH_PW');
|
||||
$header_auth = $request->header('Authorization');
|
||||
$expectedToken = $expectedUser . ':' . $expectedPw;
|
||||
|
||||
if ("Bearer " . $expectedToken != $header_auth) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => 'Invalid authorization token!'
|
||||
], 403);
|
||||
}
|
||||
|
||||
$plantName = $request->header('plant-name');
|
||||
$filterHeader = $request->header('filter-name');
|
||||
|
||||
if (empty($plantName) || empty($filterHeader)) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Missing required headers: plant-name, or filter-name"
|
||||
], 404);
|
||||
}
|
||||
|
||||
$validFilters = ['Today', 'Yesterday', 'This Week', 'This Month'];
|
||||
if (!in_array($filterHeader, $validFilters)) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Invalid filter-name value! Accepted values are: " . implode(', ', $validFilters)
|
||||
], 404);
|
||||
}
|
||||
|
||||
// $selectedPlant = $plant->id;
|
||||
// $activeFilter = strtolower(trim($filterHeader));
|
||||
|
||||
$plant = Plant::where('name', $plantName)->first();
|
||||
if (!$plant) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Plant '{$plantName}' not found!"
|
||||
], 404);
|
||||
}
|
||||
|
||||
$selectedPlant = $plant->id;
|
||||
$activeFilter = strtolower(trim($filterHeader));
|
||||
|
||||
// Set date range based on filter
|
||||
switch ($activeFilter) {
|
||||
case 'yesterday':
|
||||
$startDate = now()->subDay()->startOfDay();
|
||||
$endDate = now()->subDay()->endOfDay();
|
||||
break;
|
||||
case 'this week':
|
||||
$startDate = now()->startOfWeek();
|
||||
$endDate = now()->endOfWeek();
|
||||
break;
|
||||
case 'this month':
|
||||
$startDate = now()->startOfMonth();
|
||||
$endDate = now()->endOfMonth();
|
||||
break;
|
||||
default: // today
|
||||
$startDate = now()->startOfDay();
|
||||
$endDate = now()->endOfDay();
|
||||
break;
|
||||
}
|
||||
|
||||
// Get all unique guard names for this plant
|
||||
$uniqueGuardNames = GuardPatrolEntry::join('guard_names', 'guard_patrol_entries.guard_name_id', '=', 'guard_names.id')
|
||||
->where('guard_patrol_entries.plant_id', $selectedPlant)
|
||||
->select('guard_names.id', 'guard_names.name')
|
||||
->groupBy('guard_names.id', 'guard_names.name')
|
||||
->orderBy('guard_names.name')
|
||||
->pluck('name')
|
||||
->toArray();
|
||||
|
||||
// Get all patrol entries within the date range, grouped by guard name
|
||||
$guardPatrols = GuardPatrolEntry::join('guard_names', 'guard_patrol_entries.guard_name_id', '=', 'guard_names.id')
|
||||
->where('guard_patrol_entries.plant_id', $selectedPlant)
|
||||
->whereBetween('guard_patrol_entries.patrol_time', [$startDate, $endDate])
|
||||
->select('guard_names.id', 'guard_names.name', 'guard_patrol_entries.patrol_time')
|
||||
->orderBy('guard_names.name')
|
||||
->orderBy('guard_patrol_entries.patrol_time')
|
||||
->get()
|
||||
->groupBy('name');
|
||||
|
||||
$guardTimeSums = [];
|
||||
|
||||
foreach ($guardPatrols as $guardName => $patrols) {
|
||||
$totalSeconds = 0;
|
||||
$prevTime = null;
|
||||
|
||||
foreach ($patrols as $patrol) {
|
||||
$currentTime = Carbon::parse($patrol->patrol_time);
|
||||
if ($prevTime) {
|
||||
$totalSeconds += abs($currentTime->diffInSeconds($prevTime));
|
||||
}
|
||||
$prevTime = $currentTime;
|
||||
}
|
||||
|
||||
$guardTimeSums[$guardName] = [
|
||||
'minutes' => round($totalSeconds / 60),
|
||||
'hours' => round($totalSeconds / 3600, 1),
|
||||
];
|
||||
}
|
||||
|
||||
// Prepare chart data
|
||||
$chartData = [];
|
||||
foreach ($uniqueGuardNames as $guardName) {
|
||||
if (in_array($activeFilter, ['today', 'yesterday'])) {
|
||||
$chartData[] = $guardTimeSums[$guardName]['minutes'] ?? 0;
|
||||
} else {
|
||||
$chartData[] = $guardTimeSums[$guardName]['hours'] ?? 0;
|
||||
}
|
||||
}
|
||||
|
||||
// $chartData = array_map(function ($value) {
|
||||
// return ($value == 0 || is_null($value)) ? null : $value;
|
||||
// }, $chartData);
|
||||
|
||||
$chartData = array_map(function ($value) {
|
||||
return ($value == 0 || is_null($value)) ? "" : $value;
|
||||
}, $chartData);
|
||||
|
||||
return response()->json([
|
||||
'status_code' => 'SUCCESS',
|
||||
'labels' => array_values($uniqueGuardNames),
|
||||
'datasets' => [
|
||||
[
|
||||
'label' => match ($activeFilter) {
|
||||
'yesterday' => "Patrols by Guard (Yesterday) Minutes",
|
||||
'this week' => "Patrols by Guard (This Week) Hours",
|
||||
'this month' => "Patrols by Guard (This Month) Hours",
|
||||
default => "Patrols by Guard (Today) Minutes",
|
||||
},
|
||||
'data' => $chartData,
|
||||
],
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
173
app/Http/Controllers/ModuleGuardHourlyCountController.php
Normal file
173
app/Http/Controllers/ModuleGuardHourlyCountController.php
Normal file
@@ -0,0 +1,173 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\CheckPointTime;
|
||||
use App\Models\GuardName;
|
||||
use App\Models\GuardPatrolEntry;
|
||||
use App\Models\Plant;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ModuleGuardHourlyCountController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function get_guardDay_hourlyData(Request $request)
|
||||
{
|
||||
$expectedUser = env('API_AUTH_USER');
|
||||
$expectedPw = env('API_AUTH_PW');
|
||||
$header_auth = $request->header('Authorization');
|
||||
$expectedToken = $expectedUser . ':' . $expectedPw;
|
||||
|
||||
if ("Bearer " . $expectedToken != $header_auth) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => 'Invalid authorization token!'
|
||||
], 403);
|
||||
}
|
||||
|
||||
$plantName = $request->header('plant-name');
|
||||
$dateHeader = $request->header('date'); // required: format Y-m-d
|
||||
$guardIdHeader = $request->header('guard-name'); // required: guard_name_id
|
||||
$timeHeader = $request->header('time-range'); // required: "08:00 - 10:00"
|
||||
|
||||
if (!$plantName || !$dateHeader || !$guardIdHeader || !$timeHeader) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => 'Missing one or more headers: plant-name, date, guard-name, time-range'
|
||||
], 404);
|
||||
}
|
||||
|
||||
$plant = Plant::where('name', $plantName)->first();
|
||||
if (!$plant) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Plant '{$plantName}' not found!"
|
||||
], 404);
|
||||
}
|
||||
|
||||
$selectedPlant = $plant->id;
|
||||
//$selectedDate = $dateHeader;
|
||||
$selectedDate = Carbon::createFromFormat('d-m-Y', $dateHeader)->format('Y-m-d');
|
||||
// $selectedGuardId = $guardIdHeader;
|
||||
$guard = GuardName::where('name', $guardIdHeader)->first();
|
||||
|
||||
if (!$guard) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Guard '{$guardIdHeader}' not found!"
|
||||
], 404);
|
||||
}
|
||||
|
||||
$selectedGuardId = $guard->id;
|
||||
|
||||
[$startTime, $endTime] = explode(' - ', $timeHeader);
|
||||
// $startFormatted = Carbon::parse("{$selectedDate} {$startTime}");
|
||||
// $endFormatted = Carbon::parse("{$selectedDate} {$endTime}");
|
||||
|
||||
// $startDateTime = $startFormatted->format('H:i:s');
|
||||
// $endDateTime = $endFormatted->format('H:i:s');
|
||||
try
|
||||
{
|
||||
[$startTime, $endTime] = explode(' - ', $timeHeader);
|
||||
$startDateTime = Carbon::parse("{$selectedDate} {$startTime}");
|
||||
$endDateTime = Carbon::parse("{$selectedDate} {$endTime}");
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Invalid time-range format. Use HH:MM:SS - HH:MM:SS"
|
||||
], 400);
|
||||
}
|
||||
|
||||
$patrols = GuardPatrolEntry::where('plant_id', $selectedPlant)
|
||||
->where('guard_name_id', $selectedGuardId)
|
||||
->whereBetween('patrol_time', [$startDateTime, $endDateTime])
|
||||
->orderBy('patrol_time')
|
||||
->get();
|
||||
|
||||
if ($patrols->count() < 2) {
|
||||
return response()->json([
|
||||
'status_code' => 'SUCCESS',
|
||||
'labels' => [],
|
||||
'datasets' => []
|
||||
]);
|
||||
}
|
||||
|
||||
$checkPointTimes = CheckPointTime::where('plant_id', $selectedPlant)
|
||||
->orderBy('sequence_number')
|
||||
->get(['sequence_number', 'min_cushioning', 'max_cushioning', 'check_point1_id', 'check_point2_id']);
|
||||
|
||||
$expectedSequence = [];
|
||||
foreach ($checkPointTimes as $row) {
|
||||
$expectedSequence[] = $row->check_point1_id;
|
||||
}
|
||||
if ($checkPointTimes->isNotEmpty()) {
|
||||
$expectedSequence[] = $checkPointTimes->last()->check_point2_id;
|
||||
}
|
||||
|
||||
$intervals = [];
|
||||
$labels = [];
|
||||
$currentSeqIndex = 0;
|
||||
|
||||
for ($i = 0; $i < $patrols->count() - 1; $i++) {
|
||||
$current = Carbon::parse($patrols[$i]->patrol_time);
|
||||
$next = Carbon::parse($patrols[$i + 1]->patrol_time);
|
||||
$interval = round($next->floatDiffInRealSeconds($current, true) / 60, 2);
|
||||
|
||||
$intervals[] = $interval;
|
||||
$labels[] = "Seq " . ($i + 1);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'status_code' => 'SUCCESS',
|
||||
'labels' => $labels,
|
||||
'datasets' => [
|
||||
[
|
||||
'label' => 'Interval (minutes)',
|
||||
'data' => array_map(fn($val) => $val ?: "", $intervals),
|
||||
]
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
124
app/Http/Controllers/ModuleGuardNameController.php
Normal file
124
app/Http/Controllers/ModuleGuardNameController.php
Normal file
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\GuardPatrolEntry;
|
||||
use App\Models\Plant;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ModuleGuardNameController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function get_guard_name_Data(Request $request)
|
||||
{
|
||||
$expectedUser = env('API_AUTH_USER');
|
||||
$expectedPw = env('API_AUTH_PW');
|
||||
$header_auth = $request->header('Authorization');
|
||||
$expectedToken = $expectedUser . ':' . $expectedPw;
|
||||
|
||||
if ("Bearer " . $expectedToken != $header_auth) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => 'Invalid authorization token!'
|
||||
], 403);
|
||||
}
|
||||
|
||||
$plantName = $request->header('plant-name');
|
||||
$dateHeader = $request->header('date');
|
||||
|
||||
if (!$plantName) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Plant value can't be empty"
|
||||
], 404);
|
||||
}
|
||||
else if (!$dateHeader) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Date value can't be empty"
|
||||
], 404);
|
||||
}
|
||||
|
||||
$plant = Plant::where('name', $plantName)->first();
|
||||
if (!$plant) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Plant '{$plantName}' not found!"
|
||||
], 404);
|
||||
}
|
||||
|
||||
$selectedPlant = $plant->id;
|
||||
|
||||
try
|
||||
{
|
||||
$selectedDate = Carbon::createFromFormat('d-m-Y', $dateHeader)->format('Y-m-d');
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Invalid date format. Expected format: d-m-Y"
|
||||
], 400);
|
||||
}
|
||||
//$selectedDate = Carbon::createFromFormat('d-m-Y', $dateHeader)->format('Y-m-d');
|
||||
|
||||
$guardNames = GuardPatrolEntry::join('guard_names', 'guard_patrol_entries.guard_name_id', '=', 'guard_names.id')
|
||||
->where('guard_patrol_entries.plant_id', $selectedPlant)
|
||||
->whereDate('guard_patrol_entries.patrol_time', $selectedDate)
|
||||
->select('guard_names.name')
|
||||
->distinct()
|
||||
->orderBy('guard_names.name')
|
||||
->pluck('name');
|
||||
|
||||
if ($guardNames->isEmpty()) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => 'Guard names not found for the selected plant and date.'
|
||||
], 404);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'status_code' => 'SUCCESS',
|
||||
'status_description' => $guardNames,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
91
app/Http/Controllers/ModuleInvoiceDataController.php
Normal file
91
app/Http/Controllers/ModuleInvoiceDataController.php
Normal file
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ModuleInvoiceDataController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function get_invoiceData(Request $request)
|
||||
{
|
||||
$expectedUser = env('API_AUTH_USER');
|
||||
$expectedPw = env('API_AUTH_PW');
|
||||
|
||||
$header_auth = $request->header('Authorization');
|
||||
$expectedToken = $expectedUser . ':' . $expectedPw;
|
||||
|
||||
if ("Bearer " . $expectedToken != $header_auth)
|
||||
{
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => 'Invalid authorization token!'
|
||||
], 403);
|
||||
}
|
||||
|
||||
$moduleName = $request->header('invoice-type-list');
|
||||
|
||||
if (empty($moduleName))
|
||||
{
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Invoice type can't be empty!"
|
||||
], 404);
|
||||
}
|
||||
|
||||
$headerValue = $request->header('invoice-type-list');
|
||||
|
||||
if ($headerValue != 'Invoice Type List') {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Invalid value for 'invoice-type-list' header!"
|
||||
], 404);
|
||||
}
|
||||
|
||||
$invoiceTypes = ['All Invoice', 'Serial Invoice', 'Individual Invoice', 'Bundle Invoice'];
|
||||
|
||||
return response()->json([
|
||||
'status_code' => 'SUCCESS',
|
||||
'status_description' => $invoiceTypes
|
||||
], 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
274
app/Http/Controllers/ModuleInvoiceQuantityController.php
Normal file
274
app/Http/Controllers/ModuleInvoiceQuantityController.php
Normal file
@@ -0,0 +1,274 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\InvoiceValidation;
|
||||
use App\Models\Plant;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ModuleInvoiceQuantityController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
// public function get_invoiceQuantityData(Request $request)
|
||||
// {
|
||||
// $expectedUser = env('API_AUTH_USER');
|
||||
// $expectedPw = env('API_AUTH_PW');
|
||||
// $header_auth = $request->header('Authorization');
|
||||
// $expectedToken = $expectedUser . ':' . $expectedPw;
|
||||
|
||||
// if ("Bearer " . $expectedToken != $header_auth) {
|
||||
// return response()->json([
|
||||
// 'status_code' => 'ERROR',
|
||||
// 'status_description' => 'Invalid authorization token!'
|
||||
// ], 403);
|
||||
// }
|
||||
|
||||
// $plantName = $request->header('plant-name');
|
||||
// $filterHeader = $request->header('filter-name');
|
||||
// $invoiceHeader = $request->header('invoice-name');
|
||||
|
||||
// if (empty($plantName) || empty($invoiceHeader) || empty($filterHeader)) {
|
||||
// return response()->json([
|
||||
// 'status_code' => 'ERROR',
|
||||
// 'status_description' => "Missing required headers: plant-name, invoice-name, or filter-name"
|
||||
// ], 404);
|
||||
// }
|
||||
|
||||
// $validFilters = ['Today', 'Yesterday', 'This Week', 'This Month'];
|
||||
// if (!in_array($filterHeader, $validFilters)) {
|
||||
// return response()->json([
|
||||
// 'status_code' => 'ERROR',
|
||||
// 'status_description' => "Invalid filter-name value! Accepted values are: " . implode(', ', $validFilters)
|
||||
// ], 404);
|
||||
// }
|
||||
|
||||
// $validInvoiceFilters = ['All Invoice', 'Serial Invoice', 'Individual Invoice', 'Bundle Invoice'];
|
||||
// if (!in_array($invoiceHeader, $validInvoiceFilters)) {
|
||||
// return response()->json([
|
||||
// 'status_code' => 'ERROR',
|
||||
// 'status_description' => "Invalid invoice-name value! Accepted values are: " . implode(', ', $validInvoiceFilters)
|
||||
// ], 404);
|
||||
// }
|
||||
|
||||
// $plant = Plant::where('name', $plantName)->first();
|
||||
// if (!$plant) {
|
||||
// return response()->json([
|
||||
// 'status_code' => 'ERROR',
|
||||
// 'status_description' => "Plant '{$plantName}' not found!"
|
||||
// ], 404);
|
||||
// }
|
||||
|
||||
// $selectedPlant = $plant->id;
|
||||
// $activeFilter = strtolower(trim($filterHeader));
|
||||
// $selectedInvoice = strtolower(trim($invoiceHeader));
|
||||
|
||||
// // Set time range
|
||||
// if ($activeFilter == 'yesterday') {
|
||||
// $startDate = now()->subDay()->setTime(8, 0, 0);
|
||||
// $endDate = now()->setTime(8, 0, 0);
|
||||
// } elseif ($activeFilter == 'this week') {
|
||||
// $startDate = now()->startOfWeek()->setTime(8, 0, 0);
|
||||
// $endDate = now()->endOfWeek()->addDay()->setTime(8, 0, 0);
|
||||
// } elseif ($activeFilter == 'this month') {
|
||||
// $startDate = now()->startOfMonth()->setTime(8, 0, 0);
|
||||
// $endDate = now()->endOfMonth()->addDay()->setTime(8, 0, 0);
|
||||
// } else {
|
||||
// $startDate = now()->setTime(8, 0, 0);
|
||||
// $endDate = now()->copy()->addDay()->setTime(8, 0, 0);
|
||||
// }
|
||||
|
||||
// $labels = [];
|
||||
// $datasets = [];
|
||||
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
|
||||
public function get_invoiceQuantityData(Request $request)
|
||||
{
|
||||
$expectedUser = env('API_AUTH_USER');
|
||||
$expectedPw = env('API_AUTH_PW');
|
||||
$header_auth = $request->header('Authorization');
|
||||
$expectedToken = $expectedUser . ':' . $expectedPw;
|
||||
|
||||
if ("Bearer " . $expectedToken != $header_auth) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => 'Invalid authorization token!'
|
||||
], 403);
|
||||
}
|
||||
|
||||
$plantName = $request->header('plant-name');
|
||||
$filterHeader = $request->header('filter-name');
|
||||
$invoiceHeader = $request->header('invoice-name');
|
||||
|
||||
if (empty($plantName) || empty($invoiceHeader) || empty($filterHeader)) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Missing required headers: plant-name, invoice-name, or filter-name"
|
||||
], 404);
|
||||
}
|
||||
|
||||
$validFilters = ['Today', 'Yesterday', 'This Week', 'This Month'];
|
||||
if (!in_array($filterHeader, $validFilters)) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Invalid filter-name value! Accepted values are: " . implode(', ', $validFilters)
|
||||
], 404);
|
||||
}
|
||||
|
||||
$validInvoiceFilters = ['All Invoice', 'Serial Invoice', 'Individual Invoice', 'Bundle Invoice'];
|
||||
if (!in_array($invoiceHeader, $validInvoiceFilters)) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Invalid invoice-name value! Accepted values are: " . implode(', ', $validInvoiceFilters)
|
||||
], 404);
|
||||
}
|
||||
|
||||
$plant = Plant::where('name', $plantName)->first();
|
||||
if (!$plant) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Plant '{$plantName}' not found!"
|
||||
], 404);
|
||||
}
|
||||
|
||||
$selectedPlant = $plant->id;
|
||||
$activeFilter = strtolower(trim($filterHeader));
|
||||
$selectedInvoice = strtolower(trim($invoiceHeader));
|
||||
|
||||
// Set time range
|
||||
if ($activeFilter == 'yesterday') {
|
||||
$startDate = now()->subDay()->setTime(8, 0, 0);
|
||||
$endDate = now()->setTime(8, 0, 0);
|
||||
} elseif ($activeFilter == 'this week') {
|
||||
$startDate = now()->startOfWeek()->setTime(8, 0, 0);
|
||||
$endDate = now()->endOfWeek()->addDay()->setTime(8, 0, 0);
|
||||
} elseif ($activeFilter == 'this month') {
|
||||
$startDate = now()->startOfMonth()->setTime(8, 0, 0);
|
||||
$endDate = now()->endOfMonth()->addDay()->setTime(8, 0, 0);
|
||||
} else {
|
||||
$startDate = now()->setTime(8, 0, 0);
|
||||
$endDate = now()->copy()->addDay()->setTime(8, 0, 0);
|
||||
}
|
||||
|
||||
$types = ['individual_invoice', 'serial_invoice', 'bundle_invoice'];
|
||||
if ($selectedInvoice != 'all invoice') {
|
||||
$types = [str_replace(' ', '_', $selectedInvoice)];
|
||||
}
|
||||
|
||||
$labels = ['Total Invoices', 'Scanned Invoices'];
|
||||
$datasets = [];
|
||||
|
||||
$totals = [];
|
||||
$scanneds = [];
|
||||
|
||||
foreach ($types as $type) {
|
||||
$query = InvoiceValidation::where('plant_id', $selectedPlant)
|
||||
->whereBetween('created_at', [$startDate, $endDate]);
|
||||
|
||||
$completedQuery = InvoiceValidation::where('plant_id', $selectedPlant)
|
||||
->whereBetween('updated_at', [$startDate, $endDate]);
|
||||
|
||||
if ($type == 'individual_invoice') {
|
||||
$query->where('quantity', 1);
|
||||
$completedQuery->where('quantity', 1)
|
||||
->whereNotNull('serial_number')
|
||||
->where('serial_number', '!=', '');
|
||||
} elseif ($type == 'serial_invoice') {
|
||||
$query->whereNull('quantity');
|
||||
$completedQuery->where('scanned_status', 'Scanned')
|
||||
->where(function ($q) {
|
||||
$q->whereNull('quantity')->orWhere('quantity', 0);
|
||||
});
|
||||
} elseif ($type == 'bundle_invoice') {
|
||||
$query->where('quantity', '>', 1);
|
||||
$completedQuery->where('quantity', '>', 1)
|
||||
->whereNotNull('serial_number')
|
||||
->where('serial_number', '!=', '');
|
||||
}
|
||||
|
||||
$totals[] = $query->count();
|
||||
$scanneds[] = $completedQuery->count();
|
||||
}
|
||||
|
||||
// if (count($types) == 1) {
|
||||
// $datasets[] = [
|
||||
// 'label' => 'Invoices',
|
||||
// 'data' => [$totals[0], $scanneds[0]],
|
||||
// ];
|
||||
// }
|
||||
if (count($types) == 1)
|
||||
{
|
||||
$invoiceLabel = ucwords(str_replace('_invoice', '', str_replace('_', ' ', $types[0])));
|
||||
$datasets[] = [
|
||||
'label' => $invoiceLabel, // e.g., Serial Invoice
|
||||
'data' => [$totals[0], $scanneds[0]],
|
||||
];
|
||||
}
|
||||
else
|
||||
{
|
||||
$datasets[] = [
|
||||
'label' => 'Total Invoices',
|
||||
'data' => $totals,
|
||||
];
|
||||
$datasets[] = [
|
||||
'label' => 'Scanned Invoices',
|
||||
'data' => $scanneds,
|
||||
];
|
||||
$labels = array_map(function ($type) {
|
||||
return ucwords(str_replace('_invoice', '', str_replace('_', ' ', $type)));
|
||||
}, $types);
|
||||
}
|
||||
|
||||
foreach ($datasets as &$dataset) {
|
||||
$dataset['data'] = array_map(function ($value) {
|
||||
return $value ?? 0;
|
||||
}, $dataset['data']);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'status_code' => 'SUCCESS',
|
||||
'labels' => $labels,
|
||||
'datasets' => $datasets,
|
||||
], 200);
|
||||
}
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
554
app/Http/Controllers/ModuleInvoiceTypeController.php
Normal file
554
app/Http/Controllers/ModuleInvoiceTypeController.php
Normal file
@@ -0,0 +1,554 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\InvoiceValidation;
|
||||
use App\Models\ModuleList;
|
||||
use App\Models\Plant;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ModuleInvoiceTypeController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function get_invoiceFilter(Request $request)
|
||||
{
|
||||
$expectedUser = env('API_AUTH_USER');
|
||||
$expectedPw = env('API_AUTH_PW');
|
||||
|
||||
$header_auth = $request->header('Authorization');
|
||||
$expectedToken = $expectedUser . ':' . $expectedPw;
|
||||
|
||||
if ("Bearer " . $expectedToken != $header_auth)
|
||||
{
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => 'Invalid authorization token!'
|
||||
], 403);
|
||||
}
|
||||
|
||||
$filterName = $request->header('filter-name');
|
||||
|
||||
if (empty($filterName))
|
||||
{
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Filter Name can't be empty!"
|
||||
], 404);
|
||||
}
|
||||
|
||||
$headerValue = $request->header('filter-name');
|
||||
|
||||
if ($headerValue != 'Filter List') {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Invalid value for 'module-name' header!"
|
||||
], 404);
|
||||
}
|
||||
|
||||
$uniqueModules = ModuleList::select('filter_name', 'created_at')
|
||||
->orderBy('created_at', 'asc')
|
||||
->get()
|
||||
->unique('filter_name')
|
||||
->pluck('filter_name')
|
||||
->values();
|
||||
|
||||
if ($uniqueModules->isEmpty()) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => 'Filter names not found'
|
||||
], 404);
|
||||
}
|
||||
|
||||
|
||||
return response()->json([
|
||||
'status_code' => 'SUCCESS',
|
||||
'status_description' => $uniqueModules
|
||||
], 200);
|
||||
}
|
||||
|
||||
// public function get_invoiceCountData(Request $request)
|
||||
// {
|
||||
// $expectedUser = env('API_AUTH_USER');
|
||||
// $expectedPw = env('API_AUTH_PW');
|
||||
|
||||
// $header_auth = $request->header('Authorization');
|
||||
// $expectedToken = $expectedUser . ':' . $expectedPw;
|
||||
|
||||
// if ("Bearer " . $expectedToken != $header_auth)
|
||||
// {
|
||||
// return response()->json([
|
||||
// 'status_code' => 'ERROR',
|
||||
// 'status_description' => 'Invalid authorization token!'
|
||||
// ], 403);
|
||||
// }
|
||||
|
||||
// $moduleName = $request->header('invoice-name');
|
||||
|
||||
// if (empty($moduleName))
|
||||
// {
|
||||
// return response()->json([
|
||||
// 'status_code' => 'ERROR',
|
||||
// 'status_description' => "Invoice name can't be empty!"
|
||||
// ], 404);
|
||||
// }
|
||||
|
||||
// $plantName = $request->header('plant-name');
|
||||
// $selectedInvoice = strtolower(trim($request->header('invoice-name')));
|
||||
// $activeFilter = strtolower(trim($request->header('filter-name')));
|
||||
|
||||
// $plant = Plant::where('name', $plantName)->first();
|
||||
|
||||
// if (!$plant) {
|
||||
// return response()->json([
|
||||
// 'status_code' => 'ERROR',
|
||||
// 'status_description' => "Plant '{$plantName}' not found!"
|
||||
// ], 404);
|
||||
// }
|
||||
|
||||
// $selectedPlant = $plant->id;
|
||||
|
||||
// if (empty($selectedInvoice) || empty($selectedPlant) || empty($activeFilter)) {
|
||||
// return response()->json([
|
||||
// 'status_code' => 'ERROR',
|
||||
// 'status_description' => 'Missing required headers: invoice-name, plant-name, or filter-name'
|
||||
// ], 404);
|
||||
// }
|
||||
|
||||
// $validFilters = ['Today', 'Yesterday', 'This Week', 'This Month'];
|
||||
// $filterHeader = $request->header('filter-name');
|
||||
|
||||
// if (!in_array($filterHeader, $validFilters)) {
|
||||
// return response()->json([
|
||||
// 'status_code' => 'ERROR',
|
||||
// 'status_description' => "Invalid filter-name value! Accepted values are: " . implode(', ', $validFilters)
|
||||
// ], 404);
|
||||
// }
|
||||
|
||||
// $validInvoiceFilters = ['All Invoice', 'Serial Invoice', 'Individual Invoice', 'Bundle Invoice'];
|
||||
// $filterInvoice = $request->header('invoice-name');
|
||||
|
||||
// if (!in_array($filterInvoice, $validInvoiceFilters)) {
|
||||
// return response()->json([
|
||||
// 'status_code' => 'ERROR',
|
||||
// 'status_description' => "Invalid invoice-name value! Accepted values are: " . implode(', ', $validInvoiceFilters)
|
||||
// ], 404);
|
||||
// }
|
||||
|
||||
// if ($activeFilter == 'yesterday') {
|
||||
// $startDate = now()->subDay()->setTime(8, 0, 0);
|
||||
// $endDate = now()->setTime(8, 0, 0);
|
||||
// } elseif ($activeFilter == 'this week') {
|
||||
// $startDate = now()->startOfWeek()->setTime(8, 0, 0);
|
||||
// $endDate = now()->endOfWeek()->addDay()->setTime(8, 0, 0);
|
||||
// } elseif ($activeFilter == 'this month') {
|
||||
// $startDate = now()->startOfMonth()->setTime(8, 0, 0);
|
||||
// $endDate = now()->endOfMonth()->addDay()->setTime(8, 0, 0);
|
||||
// } else {
|
||||
// $startDate = now()->setTime(8, 0, 0);
|
||||
// $endDate = now()->copy()->addDay()->setTime(8, 0, 0);
|
||||
// }
|
||||
|
||||
// $labels = [];
|
||||
// $datasets = [];
|
||||
|
||||
// if ($activeFilter == 'yesterday' || $activeFilter == 'today')
|
||||
// {
|
||||
|
||||
// // === Imported Invoices ===
|
||||
// $importedQuery = InvoiceValidation::where('plant_id', $selectedPlant)
|
||||
// ->whereBetween('created_at', [$startDate, $endDate]);
|
||||
|
||||
// if ($selectedInvoice == 'individual invoice') {
|
||||
// $importedQuery->where('quantity', 1);
|
||||
// } elseif ($selectedInvoice == 'serial invoice') {
|
||||
// $importedQuery->whereNull('quantity');
|
||||
// } elseif ($selectedInvoice == 'bundle invoice') {
|
||||
// $importedQuery->where('quantity', '>', 1);
|
||||
// }
|
||||
|
||||
// $importedCount = $importedQuery->distinct('invoice_number')->count('invoice_number');
|
||||
|
||||
|
||||
|
||||
// // === Completed Invoices ===
|
||||
// $completedQuery = InvoiceValidation::select('invoice_number')
|
||||
// ->where('plant_id', $selectedPlant)
|
||||
// ->whereBetween('updated_at', [$startDate, $endDate]);
|
||||
|
||||
// if ($selectedInvoice == 'individual invoice') {
|
||||
// $completedQuery->where('quantity', 1)
|
||||
// ->groupBy('invoice_number')
|
||||
// ->havingRaw("COUNT(*) = SUM(CASE WHEN serial_number IS NOT NULL AND serial_number != '' THEN 1 ELSE 0 END)");
|
||||
// } elseif ($selectedInvoice == 'serial invoice') {
|
||||
// $completedQuery->whereNull('quantity')
|
||||
// ->groupBy('invoice_number')
|
||||
// ->havingRaw("COUNT(*) = SUM(CASE WHEN scanned_status = 'Scanned' THEN 1 ELSE 0 END)");
|
||||
// } elseif ($selectedInvoice == 'bundle invoice') {
|
||||
// $completedQuery->where('quantity', '>', 1)
|
||||
// ->groupBy('invoice_number')
|
||||
// ->havingRaw("COUNT(*) = SUM(CASE WHEN serial_number IS NOT NULL AND serial_number != '' THEN 1 ELSE 0 END)");
|
||||
// }
|
||||
|
||||
// $completedCount = $completedQuery->count();
|
||||
|
||||
// $labels = ['Imported Invoice', 'Completed Invoice'];
|
||||
// $datasets = [[
|
||||
// 'label' => 'Invoices',
|
||||
// 'data' => [$importedCount, $completedCount],
|
||||
// ]];
|
||||
|
||||
|
||||
// }
|
||||
|
||||
// elseif ($activeFilter == 'this week') {
|
||||
// $labels = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];
|
||||
// $imported = array_fill(0, 7, 0);
|
||||
// $completed = array_fill(0, 7, 0);
|
||||
|
||||
// for ($i = 0; $i < 7; $i++) {
|
||||
// $dayStart = now()->startOfWeek()->addDays($i)->setTime(8, 0, 0);
|
||||
// $dayEnd = $dayStart->copy()->addDay()->setTime(8, 0, 0);
|
||||
|
||||
// $importedQuery = InvoiceValidation::where('plant_id', $selectedPlant)
|
||||
// ->whereBetween('created_at', [$dayStart, $dayEnd]);
|
||||
|
||||
// $completedQuery = InvoiceValidation::select('invoice_number')
|
||||
// ->where('plant_id', $selectedPlant)
|
||||
// ->whereBetween('updated_at', [$dayStart, $dayEnd]);
|
||||
|
||||
// if ($selectedInvoice == 'individual invoice') {
|
||||
// $importedQuery->where('quantity', 1);
|
||||
// $completedQuery->where('quantity', 1)
|
||||
// ->groupBy('invoice_number')
|
||||
// ->havingRaw("COUNT(*) = SUM(CASE WHEN serial_number IS NOT NULL AND serial_number != '' THEN 1 ELSE 0 END)");
|
||||
// } elseif ($selectedInvoice == 'serial invoice') {
|
||||
// $importedQuery->whereNull('quantity');
|
||||
// $completedQuery->whereNull('quantity')
|
||||
// ->groupBy('invoice_number')
|
||||
// ->havingRaw("COUNT(*) = SUM(CASE WHEN scanned_status = 'Scanned' THEN 1 ELSE 0 END)");
|
||||
// } elseif ($selectedInvoice == 'bundle invoice') {
|
||||
// $importedQuery->where('quantity', '>', 1);
|
||||
// $completedQuery->where('quantity', '>', 1)
|
||||
// ->groupBy('invoice_number')
|
||||
// ->havingRaw("COUNT(*) = SUM(CASE WHEN serial_number IS NOT NULL AND serial_number != '' THEN 1 ELSE 0 END)");
|
||||
// }
|
||||
|
||||
// $imported[$i] = $importedQuery->distinct('invoice_number')->count('invoice_number');
|
||||
// $completed[$i] = $completedQuery->count();
|
||||
// }
|
||||
|
||||
// $datasets = [
|
||||
// ['label' => 'Imported Invoices', 'data' => $imported],
|
||||
// ['label' => 'Completed Invoices', 'data' => $completed],
|
||||
// ];
|
||||
// }
|
||||
|
||||
// elseif ($activeFilter == 'this month') {
|
||||
// $startOfMonth = now()->startOfMonth()->setTime(8, 0, 0);
|
||||
// $endOfMonth = now()->endOfMonth()->addDay()->setTime(8, 0, 0);
|
||||
|
||||
// $labels = [];
|
||||
// $imported = [];
|
||||
// $completed = [];
|
||||
|
||||
// $weekStart = $startOfMonth->copy();
|
||||
// while ($weekStart < $endOfMonth) {
|
||||
// $weekEnd = $weekStart->copy()->addDays(7);
|
||||
// $label = $weekStart->format('M') . ' (' . $weekStart->format('j') . '-' . $weekEnd->subDay()->format('j') . ')';
|
||||
// $labels[] = $label;
|
||||
|
||||
// $importedQuery = InvoiceValidation::where('plant_id', $selectedPlant)
|
||||
// ->whereBetween('created_at', [$weekStart, $weekEnd]);
|
||||
|
||||
// $completedQuery = InvoiceValidation::select('invoice_number')
|
||||
// ->where('plant_id', $selectedPlant)
|
||||
// ->whereBetween('updated_at', [$weekStart, $weekEnd]);
|
||||
|
||||
// if ($selectedInvoice == 'individual invoice') {
|
||||
// $importedQuery->where('quantity', 1);
|
||||
// $completedQuery->where('quantity', 1)
|
||||
// ->groupBy('invoice_number')
|
||||
// ->havingRaw("COUNT(*) = SUM(CASE WHEN serial_number IS NOT NULL AND serial_number != '' THEN 1 ELSE 0 END)");
|
||||
// } elseif ($selectedInvoice == 'serial invoice') {
|
||||
// $importedQuery->whereNull('quantity');
|
||||
// $completedQuery->whereNull('quantity')
|
||||
// ->groupBy('invoice_number')
|
||||
// ->havingRaw("COUNT(*) = SUM(CASE WHEN scanned_status = 'Scanned' THEN 1 ELSE 0 END)");
|
||||
// } elseif ($selectedInvoice == 'bundle invoice') {
|
||||
// $importedQuery->where('quantity', '>', 1);
|
||||
// $completedQuery->where('quantity', '>', 1)
|
||||
// ->groupBy('invoice_number')
|
||||
// ->havingRaw("COUNT(*) = SUM(CASE WHEN serial_number IS NOT NULL AND serial_number != '' THEN 1 ELSE 0 END)");
|
||||
// }
|
||||
|
||||
// $imported[] = $importedQuery->distinct('invoice_number')->count('invoice_number');
|
||||
// $completed[] = $completedQuery->count();
|
||||
|
||||
// $weekStart = $weekEnd;
|
||||
// }
|
||||
|
||||
// $datasets = [
|
||||
// ['label' => 'Imported Invoices', 'data' => $imported],
|
||||
// ['label' => 'Completed Invoices', 'data' => $completed],
|
||||
// ];
|
||||
// }
|
||||
|
||||
// // Clean zero values to null
|
||||
// foreach ($datasets as &$dataset) {
|
||||
// $dataset['data'] = array_map(function ($value) {
|
||||
// return ($value === null) ? 0 : $value;
|
||||
// }, $dataset['data']);
|
||||
// }
|
||||
|
||||
|
||||
// return response()->json([
|
||||
// 'status_code' => 'SUCCESS',
|
||||
// 'labels' => $labels,
|
||||
// 'datasets' => $datasets,
|
||||
// ], 200);
|
||||
// }
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function get_invoiceCountData(Request $request)
|
||||
{
|
||||
$expectedUser = env('API_AUTH_USER');
|
||||
$expectedPw = env('API_AUTH_PW');
|
||||
$header_auth = $request->header('Authorization');
|
||||
$expectedToken = $expectedUser . ':' . $expectedPw;
|
||||
|
||||
if ("Bearer " . $expectedToken != $header_auth) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => 'Invalid authorization token!'
|
||||
], 403);
|
||||
}
|
||||
|
||||
$plantName = $request->header('plant-name');
|
||||
$filterHeader = $request->header('filter-name');
|
||||
$invoiceHeader = $request->header('invoice-name');
|
||||
|
||||
if (empty($plantName) || empty($invoiceHeader) || empty($filterHeader)) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Missing required headers: plant-name, invoice-name, or filter-name"
|
||||
], 404);
|
||||
}
|
||||
|
||||
$validFilters = ['Today', 'Yesterday', 'This Week', 'This Month'];
|
||||
if (!in_array($filterHeader, $validFilters)) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Invalid filter-name value! Accepted values are: " . implode(', ', $validFilters)
|
||||
], 404);
|
||||
}
|
||||
|
||||
$validInvoiceFilters = ['All Invoice', 'Serial Invoice', 'Individual Invoice', 'Bundle Invoice'];
|
||||
if (!in_array($invoiceHeader, $validInvoiceFilters)) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Invalid invoice-name value! Accepted values are: " . implode(', ', $validInvoiceFilters)
|
||||
], 404);
|
||||
}
|
||||
|
||||
$plant = Plant::where('name', $plantName)->first();
|
||||
if (!$plant) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Plant '{$plantName}' not found!"
|
||||
], 404);
|
||||
}
|
||||
|
||||
$selectedPlant = $plant->id;
|
||||
$activeFilter = strtolower(trim($filterHeader));
|
||||
$selectedInvoice = strtolower(trim($invoiceHeader));
|
||||
|
||||
// Set time range
|
||||
if ($activeFilter == 'yesterday') {
|
||||
$startDate = now()->subDay()->setTime(8, 0, 0);
|
||||
$endDate = now()->setTime(8, 0, 0);
|
||||
} elseif ($activeFilter == 'this week') {
|
||||
$startDate = now()->startOfWeek()->setTime(8, 0, 0);
|
||||
$endDate = now()->endOfWeek()->addDay()->setTime(8, 0, 0);
|
||||
} elseif ($activeFilter == 'this month') {
|
||||
$startDate = now()->startOfMonth()->setTime(8, 0, 0);
|
||||
$endDate = now()->endOfMonth()->addDay()->setTime(8, 0, 0);
|
||||
} else {
|
||||
$startDate = now()->setTime(8, 0, 0);
|
||||
$endDate = now()->copy()->addDay()->setTime(8, 0, 0);
|
||||
}
|
||||
|
||||
$labels = [];
|
||||
$datasets = [];
|
||||
|
||||
// Map types for All Invoice
|
||||
$invoiceTypes = $selectedInvoice == 'all invoice'
|
||||
? [
|
||||
'Individual Invoice' => fn($q) => $q->where('quantity', 1),
|
||||
'Serial Invoice' => fn($q) => $q->whereNull('quantity'),
|
||||
'Bundle Invoice' => fn($q) => $q->where('quantity', '>', 1)
|
||||
]
|
||||
: [
|
||||
ucfirst($selectedInvoice) => match ($selectedInvoice) {
|
||||
'individual invoice' => fn($q) => $q->where('quantity', 1),
|
||||
'serial invoice' => fn($q) => $q->whereNull('quantity'),
|
||||
'bundle invoice' => fn($q) => $q->where('quantity', '>', 1),
|
||||
}
|
||||
];
|
||||
|
||||
foreach ($invoiceTypes as $labelPrefix => $queryModifier) {
|
||||
if ($activeFilter == 'yesterday' || $activeFilter == 'today') {
|
||||
$importedQuery = InvoiceValidation::where('plant_id', $selectedPlant)
|
||||
->whereBetween('created_at', [$startDate, $endDate]);
|
||||
|
||||
$queryModifier($importedQuery);
|
||||
$importedCount = $importedQuery->distinct('invoice_number')->count('invoice_number');
|
||||
|
||||
$completedQuery = InvoiceValidation::select('invoice_number')
|
||||
->where('plant_id', $selectedPlant)
|
||||
->whereBetween('updated_at', [$startDate, $endDate]);
|
||||
|
||||
if ($selectedInvoice == 'serial invoice' || $labelPrefix == 'Serial Invoice') {
|
||||
$queryModifier($completedQuery)
|
||||
->groupBy('invoice_number')
|
||||
->havingRaw("COUNT(*) = SUM(CASE WHEN scanned_status = 'Scanned' THEN 1 ELSE 0 END)");
|
||||
} else {
|
||||
$queryModifier($completedQuery)
|
||||
->groupBy('invoice_number')
|
||||
->havingRaw("COUNT(*) = SUM(CASE WHEN serial_number IS NOT NULL AND serial_number != '' THEN 1 ELSE 0 END)");
|
||||
}
|
||||
|
||||
$completedCount = $completedQuery->count();
|
||||
|
||||
$labels = ['Imported Invoice', 'Completed Invoice'];
|
||||
$datasets[] = [
|
||||
'label' => "$labelPrefix",
|
||||
'data' => [$importedCount, $completedCount],
|
||||
];
|
||||
}
|
||||
|
||||
elseif ($activeFilter == 'this week') {
|
||||
$labels = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];
|
||||
$imported = array_fill(0, 7, 0);
|
||||
$completed = array_fill(0, 7, 0);
|
||||
|
||||
for ($i = 0; $i < 7; $i++) {
|
||||
$dayStart = now()->startOfWeek()->addDays($i)->setTime(8, 0, 0);
|
||||
$dayEnd = $dayStart->copy()->addDay()->setTime(8, 0, 0);
|
||||
|
||||
$importedQuery = InvoiceValidation::where('plant_id', $selectedPlant)
|
||||
->whereBetween('created_at', [$dayStart, $dayEnd]);
|
||||
$queryModifier($importedQuery);
|
||||
$imported[$i] = $importedQuery->distinct('invoice_number')->count('invoice_number');
|
||||
|
||||
$completedQuery = InvoiceValidation::select('invoice_number')
|
||||
->where('plant_id', $selectedPlant)
|
||||
->whereBetween('updated_at', [$dayStart, $dayEnd]);
|
||||
|
||||
if ($selectedInvoice == 'serial invoice' || $labelPrefix == 'Serial Invoice') {
|
||||
$queryModifier($completedQuery)
|
||||
->groupBy('invoice_number')
|
||||
->havingRaw("COUNT(*) = SUM(CASE WHEN scanned_status = 'Scanned' THEN 1 ELSE 0 END)");
|
||||
} else {
|
||||
$queryModifier($completedQuery)
|
||||
->groupBy('invoice_number')
|
||||
->havingRaw("COUNT(*) = SUM(CASE WHEN serial_number IS NOT NULL AND serial_number != '' THEN 1 ELSE 0 END)");
|
||||
}
|
||||
|
||||
$completed[$i] = $completedQuery->count();
|
||||
}
|
||||
|
||||
$datasets[] = ['label' => "$labelPrefix Imported", 'data' => $imported];
|
||||
$datasets[] = ['label' => "$labelPrefix Completed", 'data' => $completed];
|
||||
}
|
||||
|
||||
elseif ($activeFilter == 'this month') {
|
||||
$startOfMonth = now()->startOfMonth()->setTime(8, 0, 0);
|
||||
$endOfMonth = now()->endOfMonth()->addDay()->setTime(8, 0, 0);
|
||||
$labels = [];
|
||||
$imported = [];
|
||||
$completed = [];
|
||||
|
||||
$weekStart = $startOfMonth->copy();
|
||||
while ($weekStart < $endOfMonth) {
|
||||
$weekEnd = $weekStart->copy()->addDays(7);
|
||||
$label = $weekStart->format('M') . ' (' . $weekStart->format('j') . '-' . $weekEnd->subDay()->format('j') . ')';
|
||||
$labels[] = $label;
|
||||
|
||||
$importedQuery = InvoiceValidation::where('plant_id', $selectedPlant)
|
||||
->whereBetween('created_at', [$weekStart, $weekEnd]);
|
||||
$queryModifier($importedQuery);
|
||||
$imported[] = $importedQuery->distinct('invoice_number')->count('invoice_number');
|
||||
|
||||
$completedQuery = InvoiceValidation::select('invoice_number')
|
||||
->where('plant_id', $selectedPlant)
|
||||
->whereBetween('updated_at', [$weekStart, $weekEnd]);
|
||||
|
||||
if ($selectedInvoice == 'serial invoice' || $labelPrefix == 'Serial Invoice') {
|
||||
$queryModifier($completedQuery)
|
||||
->groupBy('invoice_number')
|
||||
->havingRaw("COUNT(*) = SUM(CASE WHEN scanned_status = 'Scanned' THEN 1 ELSE 0 END)");
|
||||
} else {
|
||||
$queryModifier($completedQuery)
|
||||
->groupBy('invoice_number')
|
||||
->havingRaw("COUNT(*) = SUM(CASE WHEN serial_number IS NOT NULL AND serial_number != '' THEN 1 ELSE 0 END)");
|
||||
}
|
||||
|
||||
$completed[] = $completedQuery->count();
|
||||
$weekStart = $weekEnd;
|
||||
}
|
||||
|
||||
$datasets[] = ['label' => "$labelPrefix Imported", 'data' => $imported];
|
||||
$datasets[] = ['label' => "$labelPrefix Completed", 'data' => $completed];
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure 0 instead of null
|
||||
foreach ($datasets as &$dataset) {
|
||||
$dataset['data'] = array_map(fn($val) => $val === null ? 0 : $val, $dataset['data']);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'status_code' => 'SUCCESS',
|
||||
'labels' => $labels,
|
||||
'datasets' => $datasets,
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
94
app/Http/Controllers/ModulePlantController.php
Normal file
94
app/Http/Controllers/ModulePlantController.php
Normal file
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Plant;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ModulePlantController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function get_modulePlant(Request $request)
|
||||
{
|
||||
$expectedUser = env('API_AUTH_USER');
|
||||
$expectedPw = env('API_AUTH_PW');
|
||||
|
||||
$header_auth = $request->header('Authorization');
|
||||
$expectedToken = $expectedUser . ':' . $expectedPw;
|
||||
|
||||
if ("Bearer " . $expectedToken != $header_auth)
|
||||
{
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => 'Invalid authorization token!'
|
||||
], 403);
|
||||
}
|
||||
|
||||
$plantName = $request->header('plant-name');
|
||||
|
||||
if (empty($plantName))
|
||||
{
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Plant Name can't be empty!"
|
||||
], 404);
|
||||
}
|
||||
|
||||
$headerValue = $request->header('plant-name');
|
||||
|
||||
if ($headerValue != 'Plant List') {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Invalid value for 'plant-name' header!"
|
||||
], 404);
|
||||
}
|
||||
|
||||
$plantNames = Plant::orderBy('created_at', 'asc')
|
||||
->pluck('name')
|
||||
->values();
|
||||
|
||||
return response()->json([
|
||||
'status_code' => 'SUCCESS',
|
||||
'status_description' => $plantNames
|
||||
], 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
177
app/Http/Controllers/ModulePlantLineController.php
Normal file
177
app/Http/Controllers/ModulePlantLineController.php
Normal file
@@ -0,0 +1,177 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Line;
|
||||
use App\Models\Plant;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ModulePlantLineController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
// public function get_modulePlantLine(Request $request)
|
||||
// {
|
||||
// $expectedUser = env('API_AUTH_USER');
|
||||
// $expectedPw = env('API_AUTH_PW');
|
||||
|
||||
// $header_auth = $request->header('Authorization');
|
||||
// $expectedToken = $expectedUser . ':' . $expectedPw;
|
||||
|
||||
// if ("Bearer " . $expectedToken != $header_auth)
|
||||
// {
|
||||
// return response()->json([
|
||||
// 'status_code' => 'ERROR',
|
||||
// 'status_description' => 'Invalid authorization token!'
|
||||
// ], 403);
|
||||
// }
|
||||
|
||||
// $plantName = $request->header('plant-name');
|
||||
|
||||
// if (empty($plantName))
|
||||
// {
|
||||
// return response()->json([
|
||||
// 'status_code' => 'ERROR',
|
||||
// 'status_description' => "Plant Name can't be empty!"
|
||||
// ], 404);
|
||||
// }
|
||||
|
||||
// $plant = Plant::where('name', $plantName)->first();
|
||||
|
||||
// if (!$plant) {
|
||||
// return response()->json([
|
||||
// 'status_code' => 'ERROR',
|
||||
// 'status_description' => "Plant '{$plantName}' not found!"
|
||||
// ], 404);
|
||||
// }
|
||||
|
||||
// $lineNames = Line::where('plant_id', $plant->id)
|
||||
// ->orderBy('created_at', 'asc')
|
||||
// ->pluck('name');
|
||||
|
||||
// if ($lineNames->isEmpty()) {
|
||||
// return response()->json([
|
||||
// 'status_code' => 'ERROR',
|
||||
// 'status_description' => "No lines found for plant '{$plantName}'"
|
||||
// ], 404);
|
||||
// }
|
||||
|
||||
// // Prepend 'All Lines'
|
||||
// $lineNames->prepend('All Lines')->values();
|
||||
|
||||
// return response()->json([
|
||||
// 'status_code' => 'SUCCESS',
|
||||
// 'status_description' => $lineNames,
|
||||
// ], 200);
|
||||
|
||||
// }
|
||||
|
||||
public function get_modulePlantLine(Request $request)
|
||||
{
|
||||
$expectedUser = env('API_AUTH_USER');
|
||||
$expectedPw = env('API_AUTH_PW');
|
||||
|
||||
$header_auth = $request->header('Authorization');
|
||||
$expectedToken = $expectedUser . ':' . $expectedPw;
|
||||
|
||||
if ("Bearer " . $expectedToken != $header_auth) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => 'Invalid authorization token!'
|
||||
], 403);
|
||||
}
|
||||
|
||||
$plantName = $request->header('plant-name');
|
||||
$chartName = $request->header('chart-name');
|
||||
|
||||
if (empty($plantName)) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Plant name can't be empty!"
|
||||
], 404);
|
||||
}
|
||||
|
||||
if (empty($chartName)) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Chart name can't be empty!"
|
||||
], 404);
|
||||
}
|
||||
|
||||
$plant = Plant::where('name', $plantName)->first();
|
||||
|
||||
if (!$plant)
|
||||
{
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Plant '{$plantName}' not found!"
|
||||
], 404);
|
||||
}
|
||||
|
||||
// Load only lines NOT equal to FG Line
|
||||
$nonFgLines = Line::where('plant_id', $plant->id)
|
||||
//->where('type', '!=', 'FG Line')
|
||||
->orderBy('created_at', 'asc')
|
||||
->pluck('name')
|
||||
->toArray();
|
||||
|
||||
if (empty($nonFgLines)) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "No non-FG lines found for plant '{$plantName}'"
|
||||
], 404);
|
||||
}
|
||||
|
||||
if (strtolower(trim($chartName)) != 'production hourly count') {
|
||||
array_unshift($nonFgLines, 'All Lines');
|
||||
}
|
||||
|
||||
// Add "All Lines" to beginning and "FG Lines" at the end
|
||||
// array_unshift($nonFgLines, 'All Lines');
|
||||
// $nonFgLines[] = 'FG Line';
|
||||
|
||||
return response()->json([
|
||||
'status_code' => 'SUCCESS',
|
||||
'status_description' => $nonFgLines,
|
||||
], 200);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
107
app/Http/Controllers/ModuleProductionFGLineController.php
Normal file
107
app/Http/Controllers/ModuleProductionFGLineController.php
Normal file
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Line;
|
||||
use App\Models\Plant;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ModuleProductionFGLineController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function get_moduleFGFilterList(Request $request)
|
||||
{
|
||||
$expectedUser = env('API_AUTH_USER');
|
||||
$expectedPw = env('API_AUTH_PW');
|
||||
|
||||
$header_auth = $request->header('Authorization');
|
||||
$expectedToken = $expectedUser . ':' . $expectedPw;
|
||||
|
||||
if ("Bearer " . $expectedToken != $header_auth) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => 'Invalid authorization token!'
|
||||
], 403);
|
||||
}
|
||||
|
||||
$plantName = $request->header('plant-name');
|
||||
$FGName = $request->header('fg-lines');
|
||||
|
||||
if (empty($plantName)) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Plant name can't be empty!"
|
||||
], 404);
|
||||
}
|
||||
|
||||
if (empty($FGName)) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "FG line name can't be empty!"
|
||||
], 404);
|
||||
}
|
||||
|
||||
$plant = Plant::where('name', $plantName)->first();
|
||||
if (!$plant) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Plant '{$plantName}' not found!"
|
||||
], 404);
|
||||
}
|
||||
|
||||
$fgLines = Line::where('plant_id', $plant->id)
|
||||
->where('type', $FGName)
|
||||
->pluck('name'); // Only get line names
|
||||
|
||||
if ($fgLines->isEmpty()) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "No FG lines found for the selected plant and line!"
|
||||
], 404);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'status_code' => 'SUCCESS',
|
||||
'status_description' => $fgLines,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
171
app/Http/Controllers/ModuleProductionLineStopController.php
Normal file
171
app/Http/Controllers/ModuleProductionLineStopController.php
Normal file
@@ -0,0 +1,171 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Line;
|
||||
use App\Models\Plant;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ModuleProductionLineStopController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
}
|
||||
public function get_moduleProductionLineStop(Request $request)
|
||||
{
|
||||
$expectedUser = env('API_AUTH_USER');
|
||||
$expectedPw = env('API_AUTH_PW');
|
||||
|
||||
$header_auth = $request->header('Authorization');
|
||||
$expectedToken = $expectedUser . ':' . $expectedPw;
|
||||
|
||||
if ("Bearer " . $expectedToken != $header_auth) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => 'Invalid authorization token!'
|
||||
], 403);
|
||||
}
|
||||
|
||||
$requiredHeaders = ['module-name', 'chart-name', 'plant-name', 'line-name', 'filter-name'];
|
||||
|
||||
$missingHeaders = [];
|
||||
foreach ($requiredHeaders as $header) {
|
||||
if (empty($request->header($header))) {
|
||||
$missingHeaders[] = $header;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($missingHeaders)) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => 'Missing required headers: ' . implode(', ', $missingHeaders)
|
||||
], 404);
|
||||
}
|
||||
|
||||
$plantName = $request->header('plant-name');
|
||||
$lineName = $request->header('line-name');
|
||||
$filterName = strtolower(trim($request->header('filter-name')));
|
||||
|
||||
$plant = Plant::where('name', $plantName)->first();
|
||||
if (!$plant) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Plant '{$plantName}' not found!"
|
||||
], 404);
|
||||
}
|
||||
|
||||
$line = Line::where('name', $lineName)->where('plant_id', $plant->id)->first();
|
||||
if (!$line) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Line '{$lineName}' not found for plant '{$plantName}'"
|
||||
], 404);
|
||||
}
|
||||
|
||||
// Set time range
|
||||
if ($filterName == 'yesterday') {
|
||||
$startDate = now()->subDay()->setTime(8, 0, 0);
|
||||
$endDate = now()->setTime(8, 0, 0);
|
||||
} elseif ($filterName == 'this week') {
|
||||
$startDate = now()->startOfWeek()->setTime(8, 0, 0);
|
||||
$endDate = now()->endOfWeek()->addDay()->setTime(8, 0, 0);
|
||||
} elseif ($filterName == 'this month') {
|
||||
$startDate = now()->startOfMonth();
|
||||
$endDate = now()->endOfMonth();
|
||||
} else {
|
||||
$startDate = now()->setTime(8, 0, 0);
|
||||
$endDate = now()->copy()->addDay()->setTime(8, 0, 0);
|
||||
}
|
||||
|
||||
$query = DB::table('production_line_stops')
|
||||
->join('line_stops as ls', 'production_line_stops.linestop_id', '=', 'ls.id')
|
||||
->join('lines', 'production_line_stops.line_id', '=', 'lines.id')
|
||||
->join('plants', 'production_line_stops.plant_id', '=', 'plants.id')
|
||||
->select(
|
||||
'ls.code',
|
||||
'ls.reason',
|
||||
DB::raw("SUM(production_line_stops.stop_hour) as total_stop_hours"),
|
||||
DB::raw("SUM(production_line_stops.stop_min) as total_stop_minutes")
|
||||
)
|
||||
->where('plants.id', $plant->id)
|
||||
->where('lines.id', $line->id)
|
||||
->whereBetween('production_line_stops.created_at', [$startDate, $endDate])
|
||||
->groupBy('ls.code', 'ls.reason')
|
||||
->get();
|
||||
|
||||
if ($query->isEmpty()) {
|
||||
return response()->json([
|
||||
'status_code' => 'SUCCESS',
|
||||
'labels' => ['No Data'],
|
||||
'data' => [1],
|
||||
], 200);
|
||||
}
|
||||
|
||||
$labels = [];
|
||||
$data = [];
|
||||
$totalStopMinutes = 0;
|
||||
|
||||
foreach ($query as $row) {
|
||||
$stopHours = $row->total_stop_hours;
|
||||
$stopMinutes = $row->total_stop_minutes;
|
||||
$visualTotal = $stopHours + ($stopMinutes / 100);
|
||||
|
||||
$labels[] = "{$row->code} - {$row->reason}";
|
||||
$data[] = $visualTotal;
|
||||
|
||||
$totalStopMinutes += ($stopHours * 60) + $stopMinutes;
|
||||
}
|
||||
|
||||
// Calculate available runtime
|
||||
$remainingMinutes = 1440 - $totalStopMinutes;
|
||||
$runtimeHours = floor($remainingMinutes / 60);
|
||||
$runtimeMinutes = $remainingMinutes % 60;
|
||||
$runtimeVisual = $runtimeHours + ($runtimeMinutes / 100);
|
||||
|
||||
$labels[] = 'Available Runtime';
|
||||
$data[] = $runtimeVisual;
|
||||
|
||||
return response()->json([
|
||||
'status_code' => 'SUCCESS',
|
||||
'labels' => $labels,
|
||||
'data' => $data,
|
||||
], 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user