Compare commits
1 Commits
2c66f2e6bd
...
renovate/l
| Author | SHA1 | Date | |
|---|---|---|---|
| c7620c11b4 |
@@ -39,8 +39,6 @@ class Scheduler extends Command
|
||||
public function handle()
|
||||
{
|
||||
|
||||
// $this->call('approval:trigger-mails');
|
||||
|
||||
// --- Production Rules ---
|
||||
$productionRules = AlertMailRule::where('module', 'ProductionQuantities')
|
||||
->where('rule_name', 'ProductionMail')
|
||||
@@ -76,6 +74,7 @@ class Scheduler extends Command
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// --- Invoice Validation Rules ---
|
||||
$invoiceRules = AlertMailRule::where('module', 'InvoiceValidation')
|
||||
->where('rule_name', 'InvoiceMail')
|
||||
@@ -175,7 +174,7 @@ class Scheduler extends Command
|
||||
}
|
||||
break;
|
||||
case 'Daily':
|
||||
if (now()->format('H:i') == '11:30') {
|
||||
if (now()->format('H:i') == '10:00') {
|
||||
\Artisan::call('send:invoice-data-report', [
|
||||
'schedule_type' => $rule->schedule_type,
|
||||
'plant' => $rule->plant,
|
||||
@@ -210,25 +209,11 @@ class Scheduler extends Command
|
||||
}
|
||||
break;
|
||||
case 'Daily':
|
||||
if (now()->format('H:i') == '10:45') {
|
||||
try {
|
||||
\Artisan::call('send:invoice-transit-report', [
|
||||
'schedule_type' => $rule->schedule_type,
|
||||
'plant' => $rule->plant,
|
||||
]);
|
||||
|
||||
Log::info('Invoice Transit executed', [
|
||||
'plant' => $rule->plant,
|
||||
'type' => $rule->schedule_type,
|
||||
]);
|
||||
}
|
||||
catch (\Throwable $e) {
|
||||
Log::error('Invoice Transit FAILED', [
|
||||
'plant' => $rule->plant,
|
||||
'error' => $e->getMessage(),
|
||||
'trace' => $e->getTraceAsString(),
|
||||
]);
|
||||
}
|
||||
if (now()->format('H:i') == '10:00') {
|
||||
\Artisan::call('send:invoice-transit-report', [
|
||||
'schedule_type' => $rule->schedule_type,
|
||||
'plant' => $rule->plant,
|
||||
]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -6,8 +6,12 @@ use App\Mail\InvoiceDataMail;
|
||||
use App\Models\AlertMailRule;
|
||||
use App\Models\InvoiceDataValidation;
|
||||
use App\Models\InvoiceOutValidation;
|
||||
use App\Models\Line;
|
||||
use App\Models\Plant;
|
||||
use App\Models\ProductionPlan;
|
||||
use App\Models\ProductionQuantity;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
class SendInvoiceDataReport extends Command
|
||||
{
|
||||
@@ -45,7 +49,7 @@ class SendInvoiceDataReport extends Command
|
||||
$plants = ($plantId == 0) ? Plant::all() : Plant::where('id', $plantId)->get();
|
||||
|
||||
if ($plants->isEmpty()) {
|
||||
$this->error('No valid plant(s) found.');
|
||||
$this->error("No valid plant(s) found.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -101,7 +105,7 @@ class SendInvoiceDataReport extends Command
|
||||
->where('distribution_channel_desc', $selectedDistribution)
|
||||
->whereBetween('document_date', [$startDate, $endDate])
|
||||
->orderBy('document_date', 'asc')
|
||||
->select('customer_code', 'document_number', 'document_date', 'customer_trade_name', 'customer_location', 'location', 'remark')
|
||||
->select('customer_code', 'document_number', 'document_date', 'customer_trade_name', 'customer_location', 'location')
|
||||
->get()
|
||||
->unique('document_number')
|
||||
->values();
|
||||
@@ -110,6 +114,7 @@ class SendInvoiceDataReport extends Command
|
||||
continue;
|
||||
}
|
||||
|
||||
// Filter invoices directly — exclude ones with '-' in document_number
|
||||
$invoices = $invoices->filter(function ($inv) {
|
||||
return !empty($inv->document_number) && !str_contains($inv->document_number, '-');
|
||||
});
|
||||
@@ -129,6 +134,7 @@ class SendInvoiceDataReport extends Command
|
||||
->map(fn($n) => preg_replace('/\s+/', '', strtoupper((string) $n)))
|
||||
->toArray();
|
||||
|
||||
//where('plant_id', $plant->id)
|
||||
$wentOutInvoices = InvoiceOutValidation::whereIn('qr_code', $invoiceNumbers)
|
||||
//->whereBetween('scanned_at', [$startDate, $endDate])
|
||||
->distinct('qr_code')
|
||||
@@ -158,6 +164,7 @@ class SendInvoiceDataReport extends Command
|
||||
return !in_array($doc, $wentOutInvoices, true);
|
||||
});
|
||||
|
||||
|
||||
if ($pendingInvoices->isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
@@ -175,7 +182,7 @@ class SendInvoiceDataReport extends Command
|
||||
}
|
||||
|
||||
$tableData[] = [
|
||||
// 'no' => $no++,
|
||||
//'no' => $no++,
|
||||
'plant' => $plant->name,
|
||||
// 'distribution_type' => $selectedDistribution,
|
||||
'customer_code' => $inv->customer_code,
|
||||
@@ -187,7 +194,6 @@ class SendInvoiceDataReport extends Command
|
||||
'no_of_days_pending' => abs((int)now()->diffInDays($documentDate)),
|
||||
'status' => 'Pending',
|
||||
'status_class' => $statusColor,
|
||||
'remark' => $inv->remark,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -197,7 +203,6 @@ class SendInvoiceDataReport extends Command
|
||||
->values()
|
||||
->map(function ($item, $index) {
|
||||
$item['no'] = $index + 1;
|
||||
|
||||
return $item;
|
||||
})
|
||||
->toArray();
|
||||
@@ -209,7 +214,7 @@ class SendInvoiceDataReport extends Command
|
||||
|
||||
$this->info($contentVars['greeting'] ?? 'Invoice Data Report');
|
||||
$this->table(
|
||||
['No', 'Plant', 'Customer Code', 'Document Number', 'Document Date', 'Trade Name', 'Location', 'Pending Days', 'Status', 'Remark'],// 'Distribution Type'
|
||||
['No', 'Plant', 'Customer Code', 'Document Number', 'Document Date', 'Trade Name', 'Location', 'Pending Days', 'Status'],//'Distribution Type'
|
||||
$tableData
|
||||
);
|
||||
$this->info($contentVars['wishes'] ?? '');
|
||||
@@ -231,13 +236,13 @@ class SendInvoiceDataReport extends Command
|
||||
->toArray();
|
||||
|
||||
if (empty($toEmails)) {
|
||||
$this->info("Skipping rule ID {$rule->id} — no valid To emails found.");
|
||||
$this->warn("Skipping rule ID {$rule->id} — no valid To emails found.");
|
||||
continue;
|
||||
}
|
||||
|
||||
\Mail::to($toEmails)->cc($ccEmails)->send($mail);
|
||||
|
||||
$this->info("Mail sent for rule ID {$rule->id} → To: ".implode(', ', $toEmails).($ccEmails ? ' | CC: '.implode(', ', $ccEmails) : ''));
|
||||
$this->info("Mail sent for rule ID {$rule->id} → To: " . implode(', ', $toEmails) . ($ccEmails ? " | CC: " . implode(', ', $ccEmails) : ''));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ class SendInvoiceReport extends Command
|
||||
$scannedSerialCount = InvoiceValidation::select('invoice_number')
|
||||
->where('plant_id', $plantId)
|
||||
->whereNull('quantity')
|
||||
->whereBetween('created_at', [$startDate, $endDate])
|
||||
->whereBetween('updated_at', [$startDate, $endDate])
|
||||
->groupBy('invoice_number')
|
||||
->havingRaw("COUNT(*) = SUM(CASE WHEN scanned_status = 'Scanned' THEN 1 ELSE 0 END)")
|
||||
->count();
|
||||
@@ -86,7 +86,7 @@ class SendInvoiceReport extends Command
|
||||
$query->whereNull('quantity')
|
||||
->orWhere('quantity', 0);
|
||||
})
|
||||
->whereBetween('created_at', [$startDate, $endDate])
|
||||
->whereBetween('updated_at', [$startDate, $endDate])
|
||||
->count();
|
||||
|
||||
$serialTableData[] = [
|
||||
@@ -108,7 +108,7 @@ class SendInvoiceReport extends Command
|
||||
$scannedMatCount = InvoiceValidation::select('invoice_number')
|
||||
->where('plant_id', $plantId)
|
||||
->where('quantity', 1)
|
||||
->whereBetween('created_at', [$startDate, $endDate])
|
||||
->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();
|
||||
@@ -122,7 +122,7 @@ class SendInvoiceReport extends Command
|
||||
->where('quantity', 1)
|
||||
->whereNotNull('serial_number')
|
||||
->where('serial_number', '!=', '')
|
||||
->whereBetween('created_at', [$startDate, $endDate])
|
||||
->whereBetween('updated_at', [$startDate, $endDate])
|
||||
->count();
|
||||
|
||||
$materialTableData[] = [
|
||||
@@ -144,7 +144,7 @@ class SendInvoiceReport extends Command
|
||||
$scannedBundleCount = InvoiceValidation::select('invoice_number')
|
||||
->where('plant_id', $plantId)
|
||||
->where('quantity', '>', 1)
|
||||
->whereBetween('created_at', [$startDate, $endDate])
|
||||
->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();
|
||||
@@ -158,7 +158,7 @@ class SendInvoiceReport extends Command
|
||||
->where('quantity', '>', 1)
|
||||
->whereNotNull('serial_number')
|
||||
->where('serial_number', '!=', '')
|
||||
->whereBetween('created_at', [$startDate, $endDate])
|
||||
->whereBetween('updated_at', [$startDate, $endDate])
|
||||
->count();
|
||||
|
||||
$bundleTableData[] = [
|
||||
@@ -180,104 +180,25 @@ class SendInvoiceReport extends Command
|
||||
|
||||
// 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, [], [], $schedule));
|
||||
// }
|
||||
foreach ($mailRules->get('SerialInvoiceMail') as $rule) {
|
||||
|
||||
$toEmails = collect(explode(',', $rule->email))
|
||||
->map(fn ($e) => trim($e))
|
||||
->filter()
|
||||
->unique()
|
||||
->values()
|
||||
->toArray();
|
||||
|
||||
$ccEmails = collect(explode(',', $rule->cc_emails ?? ''))
|
||||
->map(fn ($e) => trim($e))
|
||||
->filter()
|
||||
->unique()
|
||||
->values()
|
||||
->toArray();
|
||||
|
||||
if (empty($toEmails)) {
|
||||
$this->warn("Skipping rule ID {$rule->id} — no valid To emails found.");
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
\Mail::to($toEmails)->cc($ccEmails)->send(new test($serialTableData, [], [], $schedule));
|
||||
|
||||
$this->info("Mail sent for rule ID {$rule->id} → To: ".implode(', ', $toEmails).($ccEmails ? ' | CC: '.implode(', ', $ccEmails) : ''));
|
||||
$emails = $mailRules['SerialInvoiceMail']->pluck('email')->unique()->toArray();
|
||||
foreach ($emails as $email) {
|
||||
Mail::to($email)->send(new test($serialTableData, [], [], $schedule));
|
||||
}
|
||||
}
|
||||
|
||||
// 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, $schedule));
|
||||
// }
|
||||
foreach ($mailRules->get('MaterialInvoiceMail') as $rule) {
|
||||
|
||||
$toEmails = collect(explode(',', $rule->email))
|
||||
->map(fn ($e) => trim($e))
|
||||
->filter()
|
||||
->unique()
|
||||
->values()
|
||||
->toArray();
|
||||
|
||||
$ccEmails = collect(explode(',', $rule->cc_emails ?? ''))
|
||||
->map(fn ($e) => trim($e))
|
||||
->filter()
|
||||
->unique()
|
||||
->values()
|
||||
->toArray();
|
||||
|
||||
if (empty($toEmails)) {
|
||||
$this->warn("Skipping rule ID {$rule->id} — no valid To emails found.");
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
\Mail::to($toEmails)->cc($ccEmails)->send(new test([], $materialTableData, $bundleTableData, $schedule));
|
||||
|
||||
$this->info("Mail sent for rule ID {$rule->id} → To: ".implode(', ', $toEmails).($ccEmails ? ' | CC: '.implode(', ', $ccEmails) : ''));
|
||||
$emails = $mailRules['MaterialInvoiceMail']->pluck('email')->unique()->toArray();
|
||||
foreach ($emails as $email) {
|
||||
Mail::to($email)->send(new test([], $materialTableData, $bundleTableData, $schedule));
|
||||
}
|
||||
}
|
||||
|
||||
// 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, $schedule));
|
||||
// $this->info("✅ Sent InvoiceMail to: {$email}");
|
||||
// }
|
||||
foreach ($mailRules->get('InvoiceMail') as $rule) {
|
||||
|
||||
$toEmails = collect(explode(',', $rule->email))
|
||||
->map(fn ($e) => trim($e))
|
||||
->filter()
|
||||
->unique()
|
||||
->values()
|
||||
->toArray();
|
||||
|
||||
$ccEmails = collect(explode(',', $rule->cc_emails ?? ''))
|
||||
->map(fn ($e) => trim($e))
|
||||
->filter()
|
||||
->unique()
|
||||
->values()
|
||||
->toArray();
|
||||
|
||||
if (empty($toEmails)) {
|
||||
$this->warn("Skipping rule ID {$rule->id} — no valid To emails found.");
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
\Mail::to($toEmails)->cc($ccEmails)->send(new test($serialTableData, $materialTableData, $bundleTableData, $schedule));
|
||||
|
||||
$this->info("Mail sent for rule ID {$rule->id} → To: ".implode(', ', $toEmails).($ccEmails ? ' | CC: '.implode(', ', $ccEmails) : ''));
|
||||
$emails = $mailRules['InvoiceMail']->pluck('email')->unique()->toArray();
|
||||
foreach ($emails as $email) {
|
||||
Mail::to($email)->send(new test($serialTableData, $materialTableData, $bundleTableData, $schedule));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -292,6 +213,5 @@ class SendInvoiceReport extends Command
|
||||
$this->table(['#', 'Plant', 'Total Invoice', 'Scanned Invoice', 'TotalInvoice Quantity', 'ScannedInvoice Quantity'], $bundleTableData);
|
||||
|
||||
$this->info($contentVars['wishes'] ?? '');
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports;
|
||||
|
||||
use Maatwebsite\Excel\Concerns\FromCollection;
|
||||
use Maatwebsite\Excel\Concerns\FromArray;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||
use Maatwebsite\Excel\Concerns\WithMapping;
|
||||
|
||||
class InvoicePendingReasonExport implements FromArray, WithHeadings, WithMapping
|
||||
{
|
||||
/**
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
protected array $data;
|
||||
|
||||
public function __construct(array $data)
|
||||
{
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
public function array(): array
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
public function headings(): array
|
||||
{
|
||||
return [
|
||||
'Plant Code',
|
||||
'Document Number',
|
||||
'Remark',
|
||||
'Customer Trade Name',
|
||||
'Location',
|
||||
];
|
||||
}
|
||||
|
||||
public function map($row): array
|
||||
{
|
||||
return [
|
||||
$row['plant_id'] ?? '',
|
||||
$row['document_number'] ?? '',
|
||||
$row['remark'] ?? '',
|
||||
$row['customer_trade_name'] ?? '',
|
||||
$row['location'] ?? '',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1,472 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Pages;
|
||||
|
||||
use App\Imports\InvoicePendingReasonImport;
|
||||
use App\Models\InvoiceDataValidation;
|
||||
use App\Models\InvoiceOutValidation;
|
||||
use App\Models\Plant;
|
||||
use Filament\Pages\Page;
|
||||
use Filament\Forms\Contracts\HasForms;
|
||||
use Filament\Forms\Concerns\InteractsWithForms;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Forms\Components\FileUpload;
|
||||
use Filament\Forms\Components\Hidden;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Pages\Dashboard\Concerns\HasFiltersForm;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use Storage;
|
||||
|
||||
class InvoicePendingReason extends Page
|
||||
{
|
||||
use HasFiltersForm;
|
||||
protected static ?string $navigationIcon = 'heroicon-o-document-text';
|
||||
|
||||
protected static string $view = 'filament.pages.invoice-pending-reason';
|
||||
|
||||
protected static ?string $navigationGroup = 'Manufacturing SD';
|
||||
|
||||
public ?string $file = null;
|
||||
|
||||
public array $importErrors = [];
|
||||
|
||||
public array $invoicePending = [];
|
||||
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
$this->filtersForm->fill([
|
||||
'plant_id' => null,
|
||||
'document_number' => null,
|
||||
'remark' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
public function filtersForm(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->statePath('filters')
|
||||
->schema([
|
||||
Select::make('plant_id')
|
||||
->label('Plant')
|
||||
->reactive()
|
||||
->required()
|
||||
->columnSpan(1)
|
||||
->options(function (callable $get) {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
|
||||
})
|
||||
->afterStateUpdated(function ($state, $set, callable $get,$livewire) {
|
||||
$plantId = $get('plant_id');
|
||||
|
||||
if($plantId){
|
||||
$this->dispatch('loadData' ,$plantId);
|
||||
}
|
||||
else{
|
||||
$this->dispatch('emptyData');
|
||||
}
|
||||
|
||||
$set('document_number', null);
|
||||
$set('customer_trade_name', null);
|
||||
$set('location', null);
|
||||
})
|
||||
->hint(fn ($get) => $get('pqPlantError') ? $get('pqPlantError') : null)
|
||||
->hintColor('danger'),
|
||||
|
||||
Select::make('document_number')
|
||||
->label('Document Number')
|
||||
->required()
|
||||
->reactive()
|
||||
->columnSpan(1)
|
||||
->options(function (callable $get) {
|
||||
$plantId = $get('plant_id');
|
||||
if (empty($plantId)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$distributions = InvoiceDataValidation::whereNotNull('distribution_channel_desc')
|
||||
->distinct()
|
||||
->pluck('distribution_channel_desc')
|
||||
->filter(fn ($v) => trim($v) !== '')
|
||||
->values()
|
||||
->toArray();
|
||||
|
||||
$distributions[] = '';
|
||||
|
||||
$pendingInvoices = collect();
|
||||
|
||||
foreach ($distributions as $distribution) {
|
||||
|
||||
$invoices = InvoiceDataValidation::where('plant_id', $plantId)
|
||||
->where('distribution_channel_desc', $distribution)
|
||||
->select('id', 'document_number')
|
||||
->get()
|
||||
->unique('document_number')
|
||||
->filter(fn ($inv) =>
|
||||
! empty($inv->document_number) &&
|
||||
! str_contains($inv->document_number, '-')
|
||||
);
|
||||
|
||||
if (trim($distribution) == '') {
|
||||
$invoices = $invoices->filter(fn ($inv) =>
|
||||
str_starts_with($inv->document_number, '7')
|
||||
);
|
||||
}
|
||||
|
||||
if ($invoices->isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$invoiceNumbers = $invoices->pluck('document_number')
|
||||
->map(fn ($n) => preg_replace('/\s+/', '', strtoupper($n)))
|
||||
->toArray();
|
||||
|
||||
$wentOut = InvoiceOutValidation::whereIn('qr_code', $invoiceNumbers)
|
||||
->distinct()
|
||||
->pluck('qr_code')
|
||||
->map(fn ($n) => preg_replace('/\s+/', '', strtoupper($n)))
|
||||
->toArray();
|
||||
|
||||
$pending = $invoices->filter(function ($inv) use ($wentOut) {
|
||||
$doc = preg_replace('/\s+/', '', strtoupper($inv->document_number));
|
||||
return ! in_array($doc, $wentOut, true);
|
||||
});
|
||||
|
||||
$pendingInvoices = $pendingInvoices->merge($pending);
|
||||
}
|
||||
|
||||
return $pendingInvoices
|
||||
->unique('document_number')
|
||||
->pluck('document_number', 'document_number')
|
||||
->toArray();
|
||||
})
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
$plantId = $get('plant_id');
|
||||
if (empty($plantId)) {
|
||||
return [];
|
||||
}
|
||||
$documentNumber = $get('document_number');
|
||||
|
||||
$customers = InvoiceDataValidation::where('plant_id', $plantId)
|
||||
->where('document_number', $documentNumber)
|
||||
->value('customer_trade_name');
|
||||
|
||||
$location = InvoiceDataValidation::where('plant_id', $plantId)
|
||||
->where('document_number', $documentNumber)
|
||||
->value('location');
|
||||
|
||||
$set('customer_trade_name', $customers);
|
||||
$set('location', $location);
|
||||
})
|
||||
->extraAttributes(fn ($get) => [
|
||||
'class' => $get('pqBlockError') ? 'border-red-500' : '',
|
||||
])
|
||||
->hint(fn ($get) => $get('pqBlockError') ? $get('pqBlockError') : null)
|
||||
->hintColor('danger'),
|
||||
TextInput::make('customer_trade_name')
|
||||
->label('Customer Trade Name')
|
||||
->required()
|
||||
->readOnly()
|
||||
->reactive()
|
||||
->columnSpan(1),
|
||||
TextInput::make('location')
|
||||
->label('Location')
|
||||
->required()
|
||||
->readOnly()
|
||||
->reactive()
|
||||
->columnSpan(1),
|
||||
TextInput::make('remark')
|
||||
->label('Remark')
|
||||
->reactive()
|
||||
->maxLength(40)
|
||||
->helperText('Max 40 characters allowed.')
|
||||
->extraAttributes([
|
||||
'wire:keydown.enter.prevent' => 'addRemark($event.target.value)',
|
||||
])
|
||||
->autofocus()
|
||||
->required(),
|
||||
FileUpload::make('file')
|
||||
->label('Upload Excel File')
|
||||
->required()
|
||||
->disk('local')
|
||||
->multiple(false)
|
||||
->directory('invoice-pending')
|
||||
->dehydrated(false)
|
||||
//->preserveFilenames()
|
||||
//->storeFiles()
|
||||
//storeFileNamesIn('original_name')
|
||||
// ->visibility('private')
|
||||
->acceptedFileTypes([
|
||||
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
||||
'application/vnd.ms-excel',
|
||||
'text/csv',
|
||||
])
|
||||
->rules(['mimes:xlsx,xls,csv'])
|
||||
->afterStateUpdated(function ($state, callable $set) {
|
||||
if ($state instanceof \Livewire\Features\SupportFileUploads\TemporaryUploadedFile) {
|
||||
$set('file', $state->store('invoice-pending'));
|
||||
}
|
||||
}),
|
||||
])
|
||||
->columns(3);
|
||||
}
|
||||
|
||||
public function addRemark(){
|
||||
$plantId = $this->filters['plant_id'] ?? null;
|
||||
$documentNumber = $this->filters['document_number'] ?? null;
|
||||
$remark = $this->filters['remark'] ?? null;
|
||||
|
||||
if (! $plantId) {
|
||||
Notification::make()
|
||||
->title('Plant')
|
||||
->body("please select plant first..!")
|
||||
->danger()
|
||||
->send();
|
||||
return;
|
||||
}
|
||||
if (! $documentNumber) {
|
||||
Notification::make()
|
||||
->title('Document Number')
|
||||
->body("please select document number..!")
|
||||
->danger()
|
||||
->send();
|
||||
return;
|
||||
}
|
||||
if ($remark == '') {
|
||||
Notification::make()
|
||||
->title('Remark')
|
||||
->body("Remark can't be empty..!")
|
||||
->danger()
|
||||
->send();
|
||||
return;
|
||||
}
|
||||
|
||||
InvoiceDataValidation::where('plant_id', $plantId)
|
||||
->where('document_number', $documentNumber)
|
||||
->update([
|
||||
'remark' => $remark,
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
$this->filtersForm->fill([
|
||||
'plant_id' => $plantId,
|
||||
'document_number' => $documentNumber,
|
||||
'remark' => null,
|
||||
]);
|
||||
|
||||
Notification::make()
|
||||
->title('Remark updated successfully')
|
||||
->success()
|
||||
->send();
|
||||
}
|
||||
|
||||
// public function importPendingReason()
|
||||
// {
|
||||
|
||||
// $file = $this->filters['file'] ?? null;
|
||||
|
||||
// $absolutePath = Storage::disk('local')->path($file);
|
||||
|
||||
// Excel::import(new InvoicePendingReasonImport, $absolutePath);
|
||||
|
||||
// $this->reset('filters.file');
|
||||
|
||||
// Notification::make()
|
||||
// ->title('File processed and database updated successfully')
|
||||
// ->success()
|
||||
// ->send();
|
||||
// }
|
||||
|
||||
public function importPendingReason()
|
||||
{
|
||||
$file = $this->filters['file'] ?? null;
|
||||
|
||||
$plantId = $this->filters['plant_id'] ?? null;
|
||||
|
||||
if (empty($file)) {
|
||||
Notification::make()
|
||||
->title('Please upload a file')
|
||||
->danger()
|
||||
->send();
|
||||
return;
|
||||
}
|
||||
|
||||
// if (
|
||||
// empty($fileFilter) ||
|
||||
// !is_array($fileFilter) ||
|
||||
// empty($fileFilter[0])
|
||||
// ) {
|
||||
// Notification::make()
|
||||
// ->title('Please upload a file')
|
||||
// ->danger()
|
||||
// ->send();
|
||||
|
||||
// return;
|
||||
// }
|
||||
|
||||
|
||||
// $filePath = $fileFilter[0];
|
||||
|
||||
// if (!is_string($filePath)) {
|
||||
// Notification::make()
|
||||
// ->title('Invalid file upload')
|
||||
// ->danger()
|
||||
// ->send();
|
||||
|
||||
// return;
|
||||
// }
|
||||
|
||||
$absolutePath = Storage::disk('local')->path($file);
|
||||
|
||||
$import = new InvoicePendingReasonImport();
|
||||
|
||||
try {
|
||||
|
||||
Excel::import(
|
||||
$import,
|
||||
$absolutePath
|
||||
);
|
||||
|
||||
if(!empty($import->plantCodeEmpty)) {
|
||||
|
||||
Notification::make()
|
||||
->title('Import failed')
|
||||
->body("Plant code can't be empty")
|
||||
->danger()
|
||||
->send();
|
||||
$this->filtersForm->fill([
|
||||
'file' => null,
|
||||
'plant_id' => $plantId,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
else if(!empty($import->docNoEmpty)) {
|
||||
|
||||
Notification::make()
|
||||
->title('Import failed')
|
||||
->body("Document number can't be empty")
|
||||
->danger()
|
||||
->send();
|
||||
$this->filtersForm->fill([
|
||||
'file' => null,
|
||||
'plant_id' => $plantId,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
// else if(!empty($import->remarkEmpty)) {
|
||||
|
||||
// Notification::make()
|
||||
// ->title('Import failed')
|
||||
// ->body("Remark can't be empty")
|
||||
// ->danger()
|
||||
// ->send();
|
||||
// $this->filtersForm->fill([
|
||||
// 'file' => null,
|
||||
// ]);
|
||||
// return;
|
||||
// }
|
||||
else if (! empty($import->duplicateExcelDocs)) {
|
||||
|
||||
$duplicates = collect($import->duplicateExcelDocs)
|
||||
->map(function ($rows, $key) {
|
||||
[$plant, $doc] = explode('|', $key);
|
||||
return "{$plant}-{$doc}";
|
||||
})
|
||||
->implode(', ');
|
||||
|
||||
Notification::make()
|
||||
->title('Import failed')
|
||||
->body("Duplicate Document Numbers found in Excel: {$duplicates}")
|
||||
->danger()
|
||||
->send();
|
||||
$this->filtersForm->fill([
|
||||
'file' => null,
|
||||
'plant_id' => $plantId,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
else if(!empty($import->missingPlantCodes)) {
|
||||
$codes = implode(', ', array_keys($import->missingPlantCodes));
|
||||
Notification::make()
|
||||
->title('Import failed')
|
||||
->body("Plant codes not found: {$codes}")
|
||||
->danger()
|
||||
->send();
|
||||
$this->filtersForm->fill([
|
||||
'file' => null,
|
||||
'plant_id' => $plantId,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
else if(!empty($import->missingDocNo)) {
|
||||
$docNo = implode(', ', array_keys($import->missingDocNo));
|
||||
Notification::make()
|
||||
->title('Import failed')
|
||||
->body("Document numbers not found: {$docNo}")
|
||||
->danger()
|
||||
->send();
|
||||
$this->filtersForm->fill([
|
||||
'file' => null,
|
||||
'plant_id' => $plantId,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($import->validRows as $row) {
|
||||
InvoiceDataValidation::where('plant_id', $row['plant_id'])
|
||||
->where('document_number', $row['document_number'])
|
||||
->update([
|
||||
'remark' => $row['remark'],
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
}
|
||||
|
||||
Notification::make()
|
||||
->title('Import successful')
|
||||
->body('All records updated successfully.')
|
||||
->success()
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData' ,$plantId);
|
||||
|
||||
$this->filtersForm->fill([
|
||||
'file' => null,
|
||||
'plant_id' => $plantId,
|
||||
]);
|
||||
|
||||
} catch (\Throwable $e) {
|
||||
|
||||
Notification::make()
|
||||
->title('Import error')
|
||||
->body($e->getMessage())
|
||||
->danger()
|
||||
->send();
|
||||
}
|
||||
}
|
||||
|
||||
public function exportPendingReason()
|
||||
{
|
||||
$plantId = $this->filters['plant_id'] ?? null;
|
||||
|
||||
if (! $plantId) {
|
||||
Notification::make()
|
||||
->title('Plant')
|
||||
->body("please select plant to export data..!")
|
||||
->danger()
|
||||
->send();
|
||||
return;
|
||||
}
|
||||
|
||||
$this->dispatch('loadData1' ,$plantId);
|
||||
|
||||
}
|
||||
|
||||
public static function canAccess(): bool
|
||||
{
|
||||
return Auth::check() && Auth::user()->can('view invoice pending reason');
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Pages;
|
||||
|
||||
use Filament\Pages\Page;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class Welcome extends Page
|
||||
{
|
||||
protected static ?string $navigationIcon = 'heroicon-o-document-text';
|
||||
|
||||
protected static string $view = 'filament.pages.welcome';
|
||||
|
||||
|
||||
|
||||
public function getHeading(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
// public static function canAccess(): bool
|
||||
// {
|
||||
// return Auth::check() && Auth::user()->can('view welcome page');
|
||||
// }
|
||||
}
|
||||
@@ -59,8 +59,6 @@ class InvoiceDataValidationResource extends Resource
|
||||
Forms\Components\TextInput::make('location')
|
||||
->label('Location')
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('remark')
|
||||
->label('Remark'),
|
||||
Forms\Components\Hidden::make('created_by')
|
||||
->label('Created By')
|
||||
->default(Filament::auth()->user()?->name),
|
||||
@@ -125,11 +123,6 @@ class InvoiceDataValidationResource extends Resource
|
||||
->alignCenter()
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('remark')
|
||||
->label('Remark')
|
||||
->alignCenter()
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('created_at')
|
||||
->label('Created At')
|
||||
->alignCenter()
|
||||
|
||||
@@ -398,104 +398,122 @@ class InvoiceOutValidationResource extends Resource
|
||||
// }
|
||||
|
||||
$successCount = 0;
|
||||
$updateCount = 0;
|
||||
$insertCount = 0;
|
||||
$failedRecords = [];
|
||||
|
||||
foreach ($rows as $index => $row)
|
||||
{
|
||||
if ($index == 0) {
|
||||
continue;
|
||||
}
|
||||
DB::beginTransaction();
|
||||
|
||||
$rowNumber = $index + 1;
|
||||
|
||||
try {
|
||||
$qrcode = trim($row[1]);
|
||||
$plantCode = trim($row[2]);
|
||||
$scannedAt = trim($row[3]);
|
||||
$scannedBy = trim($row[4]);
|
||||
|
||||
if (empty($qrcode)) {
|
||||
throw new \Exception("Row '{$rowNumber}' Missing QR Code");
|
||||
try {
|
||||
foreach ($rows as $index => $row) {
|
||||
if ($index == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$plant = Plant::where('code', $plantCode)->first();
|
||||
if (! $plant) {
|
||||
throw new \Exception("Invalid plant code : '{$plantCode}'");
|
||||
}
|
||||
$rowNumber = $index + 1;
|
||||
|
||||
$formattedDate = null;
|
||||
if (! empty($scannedAt)) {
|
||||
try {
|
||||
// $formattedDate = Carbon::createFromFormat('d-m-Y H:i:s', $scannedAt)
|
||||
// ->format('Y-m-d H:i:s');
|
||||
if (is_numeric($scannedAt)) {
|
||||
$formattedDate = ExcelDate::excelToDateTimeObject($scannedAt)
|
||||
->format('Y-m-d H:i:s');
|
||||
} else {
|
||||
// Or handle as manual string date (d-m-Y H:i:s)
|
||||
$formattedDate = Carbon::createFromFormat('d-m-Y H:i:s', $scannedAt)
|
||||
->format('Y-m-d H:i:s');
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
throw new \Exception("Invalid date format : '{$scannedAt}'");
|
||||
try {
|
||||
$qrcode = trim($row[1]);
|
||||
$plantCode = trim($row[2]);
|
||||
$scannedAt = trim($row[3]);
|
||||
$scannedBy = trim($row[4]);
|
||||
|
||||
if (empty($qrcode)) {
|
||||
throw new \Exception("Row '{$rowNumber}' Missing QR Code");
|
||||
}
|
||||
|
||||
$plant = Plant::where('code', $plantCode)->first();
|
||||
if (! $plant) {
|
||||
throw new \Exception("Invalid plant code : '{$plantCode}'");
|
||||
}
|
||||
|
||||
$formattedDate = null;
|
||||
if (! empty($scannedAt)) {
|
||||
try {
|
||||
// $formattedDate = Carbon::createFromFormat('d-m-Y H:i:s', $scannedAt)
|
||||
// ->format('Y-m-d H:i:s');
|
||||
if (is_numeric($scannedAt)) {
|
||||
$formattedDate = ExcelDate::excelToDateTimeObject($scannedAt)
|
||||
->format('Y-m-d H:i:s');
|
||||
} else {
|
||||
// Or handle as manual string date (d-m-Y H:i:s)
|
||||
$formattedDate = Carbon::createFromFormat('d-m-Y H:i:s', $scannedAt)
|
||||
->format('Y-m-d H:i:s');
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
throw new \Exception("Invalid date format : '{$scannedAt}'");
|
||||
}
|
||||
}
|
||||
|
||||
$record = InvoiceOutValidation::where('plant_id', $plant->id)
|
||||
->where('qr_code', $qrcode)
|
||||
->first();
|
||||
|
||||
$curStat = $record ? 'Updation' : 'Insertion';
|
||||
|
||||
if ($record) {
|
||||
$record->update([
|
||||
'scanned_at' => $formattedDate,
|
||||
'scanned_by' => $scannedBy,
|
||||
'updated_by' => $operatorName,
|
||||
]);
|
||||
$inserted = $record;
|
||||
} else {
|
||||
// Record does not exist, create with 'created_by'
|
||||
$inserted = InvoiceOutValidation::create([
|
||||
'plant_id' => $plant->id,
|
||||
'qr_code' => $qrcode,
|
||||
'scanned_at' => $formattedDate,
|
||||
'scanned_by' => $scannedBy,
|
||||
'created_by' => $operatorName,
|
||||
]);
|
||||
}
|
||||
// $inserted = InvoiceOutValidation::create([
|
||||
// 'plant_id' => $plant->id,
|
||||
// 'qr_code' => $qrcode,
|
||||
// 'scanned_at' => $formattedDate,
|
||||
// 'scanned_by' => $scannedBy,
|
||||
// 'created_by' => $operatorName
|
||||
// ]);
|
||||
|
||||
if (! $inserted) {
|
||||
throw new \Exception("{$curStat} failed for QR : {$qrcode}");
|
||||
}
|
||||
|
||||
$successCount++;
|
||||
} catch (\Exception $e) {
|
||||
$failedRecords[] = [
|
||||
'row' => $rowNumber,
|
||||
'qrcode' => $qrcode ?? null,
|
||||
'error' => $e->getMessage(),
|
||||
];
|
||||
}
|
||||
|
||||
$exists = InvoiceOutValidation::where('plant_id', $plant->id)
|
||||
->where('qr_code', $qrcode)
|
||||
->first();
|
||||
|
||||
InvoiceOutValidation::updateOrCreate(
|
||||
[
|
||||
'plant_id' => $plant->id,
|
||||
'qr_code' => $qrcode,
|
||||
],
|
||||
[
|
||||
'scanned_at' => $formattedDate,
|
||||
'scanned_by' => $scannedBy,
|
||||
'updated_by' => $operatorName,
|
||||
'created_by' => $operatorName,
|
||||
]
|
||||
);
|
||||
|
||||
$exists ? $updateCount++ : $insertCount++;
|
||||
$successCount++;
|
||||
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
$failedRecords[] = [
|
||||
'row' => $rowNumber,
|
||||
'qrcode' => $qrcode ?? null,
|
||||
'error' => $e->getMessage(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
if (count($failedRecords) > 0) {
|
||||
DB::commit();
|
||||
|
||||
if (count($failedRecords) > 0) {
|
||||
$failedSummary = collect($failedRecords)
|
||||
->map(fn ($f) => "Row {$f['row']} ({$f['qrcode']}) : {$f['error']}")
|
||||
->take(5)
|
||||
->take(5) // limit preview to first 5 errors
|
||||
->implode("\n");
|
||||
Notification::make()
|
||||
->title('Partial Import Warning')
|
||||
->body(
|
||||
"Total Success: {$successCount}\n" .
|
||||
"Inserted: {$insertCount}\n" .
|
||||
"Updated: {$updateCount}\n" .
|
||||
"Failed: " . count($failedRecords) . "\n\n" .
|
||||
$failedSummary
|
||||
)
|
||||
->warning()
|
||||
->send();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Notification::make()
|
||||
->title('Partial Import Warning')
|
||||
->body("'{$successCount}' records inserted. ".count($failedRecords)." failed.\n\n{$failedSummary}")
|
||||
->warning()
|
||||
->send();
|
||||
} else {
|
||||
Notification::make()
|
||||
->title('Import Success')
|
||||
->body("Successfully imported '{$successCount}' records.")
|
||||
->success()
|
||||
->send();
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
Notification::make()
|
||||
->title('Import Success')
|
||||
->body("Successfully imported '{$successCount}' records.")
|
||||
->success()
|
||||
->title('Import Failed')
|
||||
->body("No records were inserted. Error : {$e->getMessage()}")
|
||||
->danger()
|
||||
->send();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,9 +17,9 @@ use Filament\Resources\Pages\CreateRecord;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Livewire\Attributes\On;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use Str;
|
||||
use Livewire\Attributes\On;
|
||||
|
||||
class CreateInvoiceValidation extends CreateRecord
|
||||
{
|
||||
@@ -53,7 +53,6 @@ class CreateInvoiceValidation extends CreateRecord
|
||||
public bool $showCapacitorInput = false;
|
||||
|
||||
public $excel_file;
|
||||
|
||||
public $mInvoiceNo;
|
||||
|
||||
public function getFormActions(): array
|
||||
@@ -122,7 +121,8 @@ class CreateInvoiceValidation extends CreateRecord
|
||||
|
||||
// ..GET SERIAL INVOICE API
|
||||
|
||||
if (strlen($invoiceNumber) > 15) {
|
||||
if(strlen($invoiceNumber) > 15)
|
||||
{
|
||||
|
||||
$payloadJson = base64_decode(strtr($parts[1], '-_', '+/'));
|
||||
|
||||
@@ -132,44 +132,41 @@ class CreateInvoiceValidation extends CreateRecord
|
||||
->danger()
|
||||
->seconds(1)
|
||||
->send();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$payload = json_decode($payloadJson, true);
|
||||
|
||||
if (! isset($payload['data'])) {
|
||||
|
||||
if (!isset($payload['data'])) {
|
||||
Notification::make()
|
||||
->title('Invalid payload for scanned qr code.')
|
||||
->info()
|
||||
->seconds(1)
|
||||
->send();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$documentData = $payload['data'];
|
||||
|
||||
if ($documentData == '' || $documentData == '') {
|
||||
if($documentData == '' || $documentData == ''){
|
||||
Notification::make()
|
||||
->title('Invalid payload for scanned qr code.')
|
||||
->info()
|
||||
->seconds(1)
|
||||
->send();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Extract DocNo
|
||||
// Extract DocNo
|
||||
preg_match('/"DocNo"\s*:\s*"([^"]+)"/', $documentData, $matches);
|
||||
|
||||
if (! isset($matches[1])) {
|
||||
if (!isset($matches[1])) {
|
||||
Notification::make()
|
||||
->title('Invoice number not found.')
|
||||
->info()
|
||||
->seconds(1)
|
||||
->send();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -178,7 +175,7 @@ class CreateInvoiceValidation extends CreateRecord
|
||||
}
|
||||
}
|
||||
|
||||
// dd($invoiceNumber);
|
||||
//dd($invoiceNumber);
|
||||
|
||||
// ..
|
||||
|
||||
@@ -1430,7 +1427,6 @@ class CreateInvoiceValidation extends CreateRecord
|
||||
return;
|
||||
}
|
||||
|
||||
$missingCodes = [];
|
||||
foreach ($rows as $index => $row) {
|
||||
if ($index == 0) {
|
||||
continue;
|
||||
@@ -1442,8 +1438,8 @@ class CreateInvoiceValidation extends CreateRecord
|
||||
if (Str::length($materialCode) < 6) {
|
||||
continue;
|
||||
} else {
|
||||
$sticker = StickerMaster::where('plant_id', $plantId)->whereHas('item', function ($query) use ($plantId, $materialCode) {
|
||||
$query->where('plant_id', $plantId)->where('code', $materialCode); // $this->plantId >> Check if item.code matches Excel's materialCode
|
||||
$sticker = StickerMaster::where('plant_id', $plantId)->whereHas('item', function ($query) use ($materialCode) {
|
||||
$query->where('plant_id', $this->plantId)->where('code', $materialCode); // Check if item.code matches Excel's materialCode
|
||||
});
|
||||
if ($sticker->exists()) {
|
||||
if ($sticker->first()->material_type && ! empty($sticker->first()->material_type)) {
|
||||
@@ -1454,8 +1450,6 @@ class CreateInvoiceValidation extends CreateRecord
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
$missingCodes[] = $materialCode;
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -1464,26 +1458,7 @@ class CreateInvoiceValidation extends CreateRecord
|
||||
}
|
||||
}
|
||||
|
||||
$uniqueCodes = array_unique($missingCodes);
|
||||
|
||||
if (! empty($uniqueCodes)) {
|
||||
$missingCount = count($uniqueCodes);
|
||||
|
||||
$message = $missingCount > 10 ? "'$missingCount' item codes are not found in database for choosed plant." : 'The following item codes are not found in database for choosed plant:<br>'.implode(', ', $uniqueCodes);
|
||||
|
||||
Notification::make()
|
||||
->title('Unknown: Item Codes')
|
||||
->body($message)
|
||||
->danger()
|
||||
->seconds(3)
|
||||
->send();
|
||||
$this->dispatch('playWarnSound');
|
||||
|
||||
// if ($disk->exists($filePath)) {
|
||||
// $disk->delete($filePath);
|
||||
// }
|
||||
return;
|
||||
} elseif ($invoiceType == 'M') {
|
||||
if ($invoiceType == 'M') {
|
||||
$invalidMatCodes = [];
|
||||
$materialCodes = [];
|
||||
$missingQuantities = [];
|
||||
@@ -3220,7 +3195,7 @@ class CreateInvoiceValidation extends CreateRecord
|
||||
|
||||
if (! empty($emails)) {
|
||||
Mail::to($emails)->send(
|
||||
new InvalidSerialMail($serNo, $invoiceNumber, $mPlantName, $mInvoiceType, $itemCode, $mUserName, 'NotFoundInvoice')
|
||||
new InvalidSerialMail($serNo, $invoiceNumber, $mPlantName, $mInvoiceType, $itemCode,$mUserName,'NotFoundInvoice')
|
||||
);
|
||||
} else {
|
||||
\Log::warning("No recipients found for plant {$plantId}, module Serial, rule invalid_serial.");
|
||||
|
||||
@@ -197,7 +197,6 @@ class ItemResource extends Resource
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('category')
|
||||
->label('Category')
|
||||
->default('-')
|
||||
->alignCenter()
|
||||
->sortable()
|
||||
->searchable(),
|
||||
@@ -218,7 +217,6 @@ class ItemResource extends Resource
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('uom')
|
||||
->label('Unit of Measure')
|
||||
->default('-')
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('created_at')
|
||||
@@ -239,7 +237,6 @@ class ItemResource extends Resource
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
])
|
||||
->searchPlaceholder('Search Item Code')
|
||||
->filters([
|
||||
Tables\Filters\TrashedFilter::make(),
|
||||
Filter::make('advanced_filters')
|
||||
@@ -259,7 +256,7 @@ class ItemResource extends Resource
|
||||
$set('operator_id', null);
|
||||
}),
|
||||
Select::make('code')
|
||||
->label('Search by Code')
|
||||
->label('Search by Item Code')
|
||||
->nullable()
|
||||
// ->options(function (callable $get) {
|
||||
// $plantId = $get('Plant');
|
||||
|
||||
@@ -30,7 +30,6 @@ use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
// use Illuminate\Validation\Rule;
|
||||
|
||||
@@ -94,33 +93,21 @@ class StickerMasterResource extends Resource
|
||||
Forms\Components\Select::make('item_id')
|
||||
->label('Item Code')
|
||||
->options(function (callable $get) {
|
||||
$plantId = $get('plant_id');
|
||||
if (! $get('plant_id')) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (! $get('id')) {
|
||||
// whereHas
|
||||
return Item::where('plant_id', $plantId)->whereDoesntHave('stickerMasters')->pluck('code', 'id');
|
||||
} else {
|
||||
$itemId = StickerMaster::where('id', $get('id'))->first()?->item_id;
|
||||
|
||||
return Item::where('plant_id', $plantId)
|
||||
->where(function ($query) use ($itemId) {
|
||||
$query->whereDoesntHave('stickerMasters')
|
||||
->orWhere('id', $itemId);
|
||||
})
|
||||
->pluck('code', 'id');
|
||||
}
|
||||
// return Item::where('plant_id', $plantId)->pluck('code', 'id')->toArray();
|
||||
})
|
||||
->rule(function (callable $get) {
|
||||
return Rule::unique('sticker_masters', 'item_id')
|
||||
->where('plant_id', $get('plant_id'))
|
||||
->ignore($get('id')); // Ignore current record during updates
|
||||
return \App\Models\Item::where('plant_id', $get('plant_id'))
|
||||
->pluck('code', 'id')
|
||||
->toArray();
|
||||
})
|
||||
// ->rule(function (callable $get) {
|
||||
// return Rule::unique('items', 'code')
|
||||
// ->where('plant_id', $get('plant_id'))
|
||||
// ->ignore($get('id')); // Ignore current record during updates
|
||||
// })
|
||||
->required()
|
||||
// ->nullable()
|
||||
->nullable()
|
||||
->searchable()
|
||||
->reactive()
|
||||
// ->disabled(fn (Get $get) => !empty($get('id')))
|
||||
@@ -145,7 +132,7 @@ class StickerMasterResource extends Resource
|
||||
return;
|
||||
}
|
||||
|
||||
$availableItems = Item::where('plant_id', $plantId)->exists();
|
||||
$availableItems = \App\Models\Item::where('plant_id', $plantId)->exists();
|
||||
if (! $availableItems) {
|
||||
$set('item_error', null);
|
||||
|
||||
@@ -160,7 +147,7 @@ class StickerMasterResource extends Resource
|
||||
}
|
||||
|
||||
// Check if item exists for the selected plant
|
||||
$item = Item::where('plant_id', $plantId)
|
||||
$item = \App\Models\Item::where('plant_id', $plantId)
|
||||
->where('id', $itemId)
|
||||
->first();
|
||||
|
||||
@@ -174,8 +161,7 @@ class StickerMasterResource extends Resource
|
||||
->where('item_id', $itemId)
|
||||
->exists();
|
||||
if (! $get('id')) {
|
||||
// $set('item_error', $duplicateSticker ? 'Item Code already exists for the selected plant.' : null);
|
||||
$set('item_error', null);
|
||||
$set('item_error', $duplicateSticker ? 'Item Code already exists for the selected plant.' : null);
|
||||
}
|
||||
})
|
||||
->extraAttributes(fn ($get) => [
|
||||
@@ -191,7 +177,7 @@ class StickerMasterResource extends Resource
|
||||
if ($get('id')) {
|
||||
$itemId = StickerMaster::where('id', $get('id'))->first()?->item_id;
|
||||
if ($itemId) {
|
||||
$item = Item::where('id', $itemId)->first()?->description;
|
||||
$item = \App\Models\Item::where('id', $itemId)->first()?->description;
|
||||
if ($item) {
|
||||
$set('item_description', $item);
|
||||
} else {
|
||||
@@ -539,35 +525,27 @@ class StickerMasterResource extends Resource
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('part_validation1')
|
||||
->label('Part Validation 1')
|
||||
->default('-')
|
||||
->alignCenter(),
|
||||
Tables\Columns\TextColumn::make('part_validation2')
|
||||
->label('Part Validation 2')
|
||||
->default('-')
|
||||
->alignCenter(),
|
||||
Tables\Columns\TextColumn::make('part_validation3')
|
||||
->label('Part Validation 3')
|
||||
->default('-')
|
||||
->alignCenter(),
|
||||
Tables\Columns\TextColumn::make('part_validation4')
|
||||
->label('Part Validation 4')
|
||||
->default('-')
|
||||
->alignCenter(),
|
||||
Tables\Columns\TextColumn::make('part_validation5')
|
||||
->label('Part Validation 5')
|
||||
->default('-')
|
||||
->alignCenter(),
|
||||
Tables\Columns\TextColumn::make('laser_part_validation1')
|
||||
->label('Laser Part Validation 1')
|
||||
->default('-')
|
||||
->alignCenter(),
|
||||
Tables\Columns\TextColumn::make('laser_part_validation2')
|
||||
->label('Laser Part Validation 2')
|
||||
->default('-')
|
||||
->alignCenter(),
|
||||
Tables\Columns\TextColumn::make('panel_box_code')
|
||||
->label('Panel Box Code')
|
||||
->default('-')
|
||||
->alignCenter(),
|
||||
Tables\Columns\TextColumn::make('load_rate')
|
||||
->label('Load Rate')
|
||||
@@ -575,22 +553,20 @@ class StickerMasterResource extends Resource
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('bundle_quantity')
|
||||
->label('Bundle Quantity')
|
||||
->default('-')
|
||||
->alignCenter(),
|
||||
Tables\Columns\TextColumn::make('material_type')
|
||||
->label('Material Type')
|
||||
->default('-')
|
||||
->alignCenter()
|
||||
->formatStateUsing(function ($state) {
|
||||
if (is_null($state) || $state == '') {
|
||||
return '-';
|
||||
if (is_null($state) || $state === '') {
|
||||
return '';
|
||||
}
|
||||
|
||||
return match ($state) {
|
||||
1 => 'Individual',
|
||||
2 => 'Bundle',
|
||||
3 => 'Quantity',
|
||||
default => '-',
|
||||
default => '',
|
||||
};
|
||||
}),
|
||||
Tables\Columns\TextColumn::make('created_at')
|
||||
@@ -611,7 +587,9 @@ class StickerMasterResource extends Resource
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
])
|
||||
->searchPlaceholder('Search Item Code')
|
||||
// ->filters([
|
||||
// Tables\Filters\TrashedFilter::make(),
|
||||
// ])
|
||||
->filters([
|
||||
Tables\Filters\TrashedFilter::make(),
|
||||
Filter::make('advanced_filters')
|
||||
@@ -657,7 +635,7 @@ class StickerMasterResource extends Resource
|
||||
->searchable()
|
||||
->reactive(),
|
||||
Select::make('material_type')
|
||||
->label('Select Material Type')
|
||||
->label('Material Type')
|
||||
->options([
|
||||
1 => 'Individual',
|
||||
2 => 'Bundle',
|
||||
@@ -666,7 +644,7 @@ class StickerMasterResource extends Resource
|
||||
->reactive(),
|
||||
|
||||
TextInput::make('panel_box_code')
|
||||
->label('Search by Panel Box Code')
|
||||
->label('Panel Box Code')
|
||||
->placeholder(placeholder: 'Enter Panel Box Code'),
|
||||
DateTimePicker::make(name: 'created_from')
|
||||
->label('Created From')
|
||||
|
||||
@@ -80,7 +80,7 @@ class InvoiceChart extends ChartWidget
|
||||
$completedInvoicesCount = InvoiceValidation::select('invoice_number')
|
||||
->where('plant_id', $selectedPlant)
|
||||
->whereNull('quantity')
|
||||
->whereBetween('created_at', [$startDate, $endDate])
|
||||
->whereBetween('updated_at', [$startDate, $endDate])
|
||||
->groupBy('invoice_number')
|
||||
->havingRaw(
|
||||
"COUNT(*) = SUM(CASE WHEN scanned_status = 'Scanned' THEN 1 ELSE 0 END)"
|
||||
@@ -99,7 +99,7 @@ class InvoiceChart extends ChartWidget
|
||||
$completedInvoicesCount = InvoiceValidation::select('invoice_number')
|
||||
->where('plant_id', $selectedPlant)
|
||||
->where('quantity', '>', 1)
|
||||
->whereBetween('created_at', [$startDate, $endDate])
|
||||
->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)"
|
||||
@@ -142,7 +142,7 @@ class InvoiceChart extends ChartWidget
|
||||
$query->where('quantity', 1)->whereBetween('created_at', [$dayStart, $dayEnd]);
|
||||
|
||||
$completedQuery->where('quantity', 1)
|
||||
->whereBetween('created_at', [$dayStart, $dayEnd])
|
||||
->whereBetween('updated_at', [$dayStart, $dayEnd])
|
||||
->groupBy('invoice_number')
|
||||
->havingRaw(
|
||||
"COUNT(*) = SUM(CASE WHEN serial_number IS NOT NULL AND serial_number != '' THEN 1 ELSE 0 END)"
|
||||
@@ -153,7 +153,7 @@ class InvoiceChart extends ChartWidget
|
||||
$query->whereNull('quantity')->whereBetween('created_at', [$dayStart, $dayEnd]);
|
||||
|
||||
$completedQuery->whereNull('quantity')
|
||||
->whereBetween('created_at', [$dayStart, $dayEnd])
|
||||
->whereBetween('updated_at', [$dayStart, $dayEnd])
|
||||
->groupBy('invoice_number')
|
||||
->havingRaw(
|
||||
"COUNT(*) = SUM(CASE WHEN scanned_status = 'Scanned' THEN 1 ELSE 0 END)"
|
||||
@@ -164,7 +164,7 @@ class InvoiceChart extends ChartWidget
|
||||
$query->where('quantity', '>', 1)->whereBetween('created_at', [$dayStart, $dayEnd]);
|
||||
|
||||
$completedQuery->where('quantity', '>', 1)
|
||||
->whereBetween('created_at', [$dayStart, $dayEnd])
|
||||
->whereBetween('updated_at', [$dayStart, $dayEnd])
|
||||
->groupBy('invoice_number')
|
||||
->havingRaw(
|
||||
"COUNT(*) = SUM(CASE WHEN serial_number IS NOT NULL AND serial_number != '' THEN 1 ELSE 0 END)"
|
||||
@@ -193,31 +193,22 @@ class InvoiceChart extends ChartWidget
|
||||
}
|
||||
elseif ($activeFilter == 'this_month') {
|
||||
$startOfMonth = now()->startOfMonth()->setTime(8, 0, 0);
|
||||
$endOfMonth = now()->endOfMonth()->addDay()->setTime(23, 59, 59); // include full last day
|
||||
$endOfMonth = now()->endOfMonth()->addDay()->setTime(8, 0, 0); // include full last day
|
||||
$monthName = $startOfMonth->format('M');
|
||||
|
||||
// Prepare weekly labels like "May(1-7)", "May(8-14)", etc.
|
||||
$labels = [];
|
||||
$weekStart = $startOfMonth->copy();
|
||||
$importedInvoicesPerWeek = [];
|
||||
$completedInvoicesPerWeek = [];
|
||||
|
||||
$weekIndex = 0;
|
||||
while ($weekStart <= $endOfMonth) {
|
||||
// $weekEnd = $weekStart->copy()->addDays(6);
|
||||
$weekEnd = $weekStart->copy()->addDays(6)->endOfDay();
|
||||
|
||||
// If week end exceeds end of month, limit it
|
||||
if ($weekEnd->greaterThan($endOfMonth)) {
|
||||
$weekEnd = $endOfMonth->copy()->endOfDay();
|
||||
}
|
||||
|
||||
while ($weekStart < $endOfMonth) {
|
||||
$weekEnd = $weekStart->copy()->addDays(7);
|
||||
$startDay = $weekStart->format('j');
|
||||
$endDay = $weekEnd->format('j');
|
||||
|
||||
// $startDay = $weekStart->format('j');
|
||||
// $weekEndLimit = $weekEnd->copy()->subDay();
|
||||
// $actualEnd = $weekEndLimit->greaterThan($endOfMonth) ? $endOfMonth : $weekEndLimit;
|
||||
// $endDay = $actualEnd->format('j');
|
||||
$weekEndLimit = $weekEnd->copy()->subDay();
|
||||
$actualEnd = $weekEndLimit->greaterThan($endOfMonth) ? $endOfMonth : $weekEndLimit;
|
||||
$endDay = $actualEnd->format('j');
|
||||
|
||||
$labels[] = "{$monthName}({$startDay}-{$endDay})";
|
||||
|
||||
@@ -242,7 +233,7 @@ class InvoiceChart extends ChartWidget
|
||||
// --- Completed ---
|
||||
$queryCompleted = InvoiceValidation::select('invoice_number')
|
||||
->where('plant_id', $selectedPlant)
|
||||
->whereBetween('created_at', [$weekStart, $weekEnd]);
|
||||
->whereBetween('updated_at', [$weekStart, $weekEnd]);
|
||||
|
||||
if ($selectedInvoice == 'individual_material') {
|
||||
$queryCompleted->where('quantity', 1)
|
||||
@@ -261,8 +252,7 @@ class InvoiceChart extends ChartWidget
|
||||
$completedInvoicesPerWeek[$weekIndex] = $queryCompleted->count();
|
||||
|
||||
// Move to next week
|
||||
// $weekStart = $weekEnd;
|
||||
$weekStart = $weekEnd->copy()->addDay(1);
|
||||
$weekStart = $weekEnd;
|
||||
$weekIndex++;
|
||||
}
|
||||
|
||||
@@ -308,7 +298,6 @@ class InvoiceChart extends ChartWidget
|
||||
{
|
||||
return 'bar';
|
||||
}
|
||||
|
||||
public static function getDefaultName(): string
|
||||
{
|
||||
return 'invoice-chart';
|
||||
|
||||
@@ -70,10 +70,6 @@ class ProductionStickerReprintController extends Controller
|
||||
{
|
||||
$copies = 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
$copies = 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -1,126 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Imports;
|
||||
|
||||
use App\Models\InvoiceDataValidation;
|
||||
use App\Models\Plant;
|
||||
use Illuminate\Support\Collection;
|
||||
use Maatwebsite\Excel\Concerns\ToCollection;
|
||||
|
||||
class InvoicePendingReasonImport implements ToCollection
|
||||
{
|
||||
/**
|
||||
* @param Collection $collection
|
||||
*/
|
||||
|
||||
public array $errors = [];
|
||||
|
||||
public array $missingPlantCodes = [];
|
||||
public array $missingDocNo = [];
|
||||
public array $plantCodeEmpty = [];
|
||||
public array $docNoEmpty = [];
|
||||
public array $remarkEmpty = [];
|
||||
|
||||
public array $duplicateExcelDocs = [];
|
||||
|
||||
private array $seenExcelKeys = [];
|
||||
|
||||
public array $validRows = [];
|
||||
|
||||
public function collection(Collection $collection)
|
||||
{
|
||||
$rows = $collection;
|
||||
// foreach ($rows->skip(1) as $row) {
|
||||
|
||||
// $plantCode = trim($row[0] ?? '');
|
||||
// $documentNumber = trim($row[1] ?? '');
|
||||
// $remark = trim($row[2] ?? '');
|
||||
|
||||
// if (! $plantCode || ! $documentNumber || ! $remark) {
|
||||
// continue;
|
||||
// }
|
||||
|
||||
// $plantId = Plant::where('code', $plantCode)->value('id');
|
||||
|
||||
// InvoiceDataValidation::where('plant_id', $plantId)
|
||||
// ->where('document_number', $documentNumber)
|
||||
// ->update([
|
||||
// 'remark' => $remark,
|
||||
// 'updated_at' => now(),
|
||||
// ]);
|
||||
// }
|
||||
|
||||
foreach ($rows->skip(1) as $index => $row) {
|
||||
|
||||
$rowNo = $index + 2;
|
||||
|
||||
$plantCode = trim($row[0] ?? '');
|
||||
$documentNumber = trim($row[1] ?? '');
|
||||
$remark = trim($row[2] ?? '');
|
||||
|
||||
if (! $plantCode) {
|
||||
$this->plantCodeEmpty[] = [
|
||||
'row' => $rowNo,
|
||||
'reason' => "Plant Code can't be empty!",
|
||||
];
|
||||
continue;
|
||||
}
|
||||
else if (! $documentNumber) {
|
||||
$this->docNoEmpty[] = [
|
||||
'row' => $rowNo,
|
||||
'reason' => "Document number can't be empty!",
|
||||
];
|
||||
continue;
|
||||
}
|
||||
|
||||
//Excel-level duplicate check
|
||||
$key = $plantCode . '|' . $documentNumber;
|
||||
|
||||
if (isset($this->seenExcelKeys[$key])) {
|
||||
$this->duplicateExcelDocs[$key][] = $rowNo;
|
||||
|
||||
$this->errors[] = [
|
||||
'row' => $rowNo,
|
||||
'reason' => "Duplicate Document Number in Excel ({$plantCode} - {$documentNumber})",
|
||||
];
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->seenExcelKeys[$key] = true;
|
||||
|
||||
$plantId = Plant::where('code', $plantCode)->value('id');
|
||||
|
||||
if (! $plantId) {
|
||||
$this->missingPlantCodes[$plantCode] = true;
|
||||
|
||||
$this->errors[] = [
|
||||
'row' => $rowNo,
|
||||
'reason' => "Plant code not found: {$plantCode}",
|
||||
];
|
||||
continue;
|
||||
}
|
||||
|
||||
$invoiceExists = InvoiceDataValidation::where('plant_id', $plantId)
|
||||
->where('document_number', $documentNumber)
|
||||
->first();
|
||||
|
||||
if (! $invoiceExists) {
|
||||
$this->missingDocNo[$documentNumber] = true;
|
||||
|
||||
$this->errors[] = [
|
||||
'row' => $rowNo,
|
||||
'reason' => "Document number not found: {$documentNumber}",
|
||||
];
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
$this->validRows[] = [
|
||||
'plant_id' => $plantId,
|
||||
'document_number' => $documentNumber,
|
||||
'remark' => $remark,
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,125 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire;
|
||||
|
||||
use App\Models\InvoiceDataValidation;
|
||||
use App\Models\InvoiceOutValidation;
|
||||
use App\Models\PalletValidation;
|
||||
use Livewire\Component;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use App\Exports\InvoicePendingReasonExport;
|
||||
use App\Models\Plant;
|
||||
|
||||
class InvoicePending extends Component
|
||||
{
|
||||
|
||||
public $plantId;
|
||||
|
||||
public $invoicePending = [];
|
||||
|
||||
protected $listeners = [
|
||||
'loadData' => 'loadInvoiceData',
|
||||
'emptyData' => 'loadInvoiceEmptyData',
|
||||
'loadData1' => 'exportPendingReason',
|
||||
];
|
||||
|
||||
public function loadInvoiceEmptyData()
|
||||
{
|
||||
$this->invoicePending = [];
|
||||
}
|
||||
|
||||
public function loadInvoiceData($plantId)
|
||||
{
|
||||
$this->plantId = $plantId;
|
||||
|
||||
$distributions = InvoiceDataValidation::whereNotNull('distribution_channel_desc')
|
||||
->distinct()
|
||||
->pluck('distribution_channel_desc')
|
||||
->filter(fn ($v) => trim($v) != '')
|
||||
->values()
|
||||
->toArray();
|
||||
|
||||
$distributions[] = '';
|
||||
|
||||
$pendingInvoices = collect();
|
||||
|
||||
foreach ($distributions as $distribution) {
|
||||
|
||||
$invoices = InvoiceDataValidation::where('plant_id', $plantId)
|
||||
->where('distribution_channel_desc', $distribution)
|
||||
->select(
|
||||
'id',
|
||||
'document_number',
|
||||
'customer_trade_name',
|
||||
'location',
|
||||
'remark',
|
||||
'created_at',
|
||||
'created_by',
|
||||
'updated_at',
|
||||
'updated_by'
|
||||
)
|
||||
->get()
|
||||
->unique('document_number')
|
||||
->filter(fn ($inv) =>
|
||||
!empty($inv->document_number) &&
|
||||
!str_contains($inv->document_number, '-')
|
||||
);
|
||||
|
||||
if (trim($distribution) == '') {
|
||||
$invoices = $invoices->filter(fn ($inv) =>
|
||||
str_starts_with($inv->document_number, '7')
|
||||
);
|
||||
}
|
||||
|
||||
if ($invoices->isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$invoiceNumbers = $invoices->pluck('document_number')
|
||||
->map(fn ($n) => preg_replace('/\s+/', '', strtoupper($n)))
|
||||
->toArray();
|
||||
|
||||
$wentOut = InvoiceOutValidation::whereIn('qr_code', $invoiceNumbers)
|
||||
->distinct()
|
||||
->pluck('qr_code')
|
||||
->map(fn ($n) => preg_replace('/\s+/', '', strtoupper($n)))
|
||||
->toArray();
|
||||
|
||||
$pending = $invoices->filter(function ($inv) use ($wentOut) {
|
||||
$doc = preg_replace('/\s+/', '', strtoupper($inv->document_number));
|
||||
return !in_array($doc, $wentOut, true);
|
||||
});
|
||||
|
||||
$pendingInvoices = $pendingInvoices->merge($pending);
|
||||
}
|
||||
|
||||
$plantCode = Plant::find($this->plantId)->code ?? '';
|
||||
|
||||
$this->invoicePending = $pendingInvoices
|
||||
->unique('document_number')
|
||||
->map(function ($record) use ($plantCode) {
|
||||
return [
|
||||
'plant_id' => $plantCode ?? '',
|
||||
'document_number' => $record->document_number ?? '',
|
||||
'customer_trade_name' => $record->customer_trade_name ?? '',
|
||||
'location' => $record->location ?? '',
|
||||
'remark' => $record->remark ?? '',
|
||||
];
|
||||
})
|
||||
->values()
|
||||
->toArray();
|
||||
}
|
||||
|
||||
public function exportPendingReason()
|
||||
{
|
||||
return Excel::download(
|
||||
new InvoicePendingReasonExport($this->invoicePending),
|
||||
'invoice_pending_reason.xlsx'
|
||||
);
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.invoice-pending');
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@
|
||||
"laravel/sanctum": "^4.0",
|
||||
"laravel/tinker": "^2.9",
|
||||
"league/flysystem-sftp-v3": "^3.30",
|
||||
"livewire/livewire": "^3.6",
|
||||
"livewire/livewire": "^4.0",
|
||||
"maatwebsite/excel": "^3.1",
|
||||
"mike42/escpos-php": "^4.0",
|
||||
"mpdf/mpdf": "^8.2",
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
$sql1 = <<<'SQL'
|
||||
ALTER TABLE invoice_data_validations
|
||||
ADD COLUMN remark TEXT DEFAULT NULL
|
||||
SQL;
|
||||
|
||||
DB::statement($sql1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
// Schema::table('invoice_data_validations', function (Blueprint $table) {
|
||||
// //
|
||||
// });
|
||||
}
|
||||
};
|
||||
@@ -161,9 +161,6 @@ class PermissionSeeder extends Seeder
|
||||
Permission::updateOrCreate(['name' => 'view production data send to sap']);
|
||||
Permission::updateOrCreate(['name' => 'create production sticker reject reason page']);
|
||||
Permission::updateOrCreate(['name' => 'create web capture page']);
|
||||
|
||||
Permission::updateOrCreate(['name' => 'view invoice pending reason']);
|
||||
|
||||
Permission::updateOrCreate(['name' => 'view import invoice out validation']);
|
||||
Permission::updateOrCreate(['name' => 'view export invoice out validation']);
|
||||
Permission::updateOrCreate(['name' => 'view import invoice data validation']);
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
<x-filament-panels::page>
|
||||
<div class="space-y-4">
|
||||
{{ $this->filtersForm($this->form) }}
|
||||
</div>
|
||||
<div class="flex-row gap-2 mt-4">
|
||||
<x-filament::button
|
||||
{{-- type="button" --}}
|
||||
{{-- wire:click="addRemark"
|
||||
class="px-3 py-1 border border-primary-500 text-primary-600 rounded hover:bg-primary-50 hover:border-primary-700 transition text-sm" --}}
|
||||
wire:click="addRemark"
|
||||
color="primary"
|
||||
class="mt-4"
|
||||
>
|
||||
Save
|
||||
</x-filament::button>
|
||||
|
||||
<x-filament::button
|
||||
wire:click="importPendingReason"
|
||||
color="primary"
|
||||
class="mt-4"
|
||||
>
|
||||
Import
|
||||
</x-filament::button>
|
||||
<x-filament::button
|
||||
wire:click="exportPendingReason"
|
||||
color="primary"
|
||||
class="mt-4"
|
||||
>
|
||||
Export
|
||||
</x-filament::button>
|
||||
<div class="bg-white shadow rounded-xl p-4 mt-6">
|
||||
<livewire:invoice-pending />
|
||||
</div>
|
||||
</div>
|
||||
</x-filament-panels::page>
|
||||
@@ -1,19 +0,0 @@
|
||||
<x-filament-panels::page>
|
||||
|
||||
<h1 class="text-3xl font-bold mb-6">Welcome to CRI Digital Manufacturing IIOT</h1>
|
||||
|
||||
<div class="w-full overflow-hidden rounded-xl shadow">
|
||||
<img
|
||||
src="{{ asset('images/iiot-banner.jpg') }}"
|
||||
alt="CRI Digital Manufacturing IIoT"
|
||||
class="w-full h-64 object-cover"
|
||||
>
|
||||
</div>
|
||||
|
||||
<p class="text-lg text-gray-600 mb-6">
|
||||
This dashboard provides real-time visibility into your manufacturing operations,
|
||||
enabling you to monitor production, track performance, and make data-driven decisions
|
||||
across plants and lines—all from one centralized platform.
|
||||
</p>
|
||||
|
||||
</x-filament-panels::page>
|
||||
@@ -1,45 +0,0 @@
|
||||
<div class="p-4">
|
||||
<h2 class="text-lg font-bold mb-4 text-gray-700 uppercase tracking-wider">
|
||||
PENDING INVOICE DATA TABLE:
|
||||
</h2>
|
||||
<div class="overflow-x-auto rounded-lg shadow">
|
||||
<table class="w-full divide-y divide-gray-200 text-sm text-center">
|
||||
<thead class="bg-gray-100 text-s font-semibold uppercase text-gray-700">
|
||||
<tr>
|
||||
<th class="border px-4 py-2">No</th>
|
||||
<th class="border px-4 py-2">Plant Code</th>
|
||||
<th class="border px-4 py-2">Document Number</th>
|
||||
<th class="border px-4 py-2">Customer Trade Location</th>
|
||||
<th class="border px-4 py-2">Location</th>
|
||||
<th class="border px-4 py-2">Remark</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="divide-y divide-gray-100">
|
||||
@if (empty($invoicePending))
|
||||
<tr>
|
||||
<td colspan="6" class="px-4 py-4 text-center text-gray-500">
|
||||
Please select plant to load pending invoice.
|
||||
</td>
|
||||
</tr>
|
||||
@else
|
||||
@forelse ($invoicePending as $index => $locator)
|
||||
<tr class="hover:bg-gray-50">
|
||||
<td class="border px-4 py-2">{{ $index + 1 }}</td>
|
||||
<td class="border px-4 py-2 whitespace-nowrap">{{ $locator['plant_id'] ?? '-' }}</td>
|
||||
<td class="border px-4 py-2 whitespace-nowrap">{{ $locator['document_number'] ?? '-' }}</td>
|
||||
<td class="border px-4 py-2">{{ $locator['customer_trade_name'] ?? '-' }}</td>
|
||||
<td class="border px-4 py-2 whitespace-nowrap">{{ $locator['location'] ?? '-' }}</td>
|
||||
<td class="border px-4 py-2 whitespace-nowrap">{{ $locator['remark'] ?? '-' }}</td>
|
||||
</tr>
|
||||
@empty
|
||||
<tr>
|
||||
<td colspan="9" class="px-4 py-4 text-center text-gray-500">
|
||||
No invoice pending records found.
|
||||
</td>
|
||||
</tr>
|
||||
@endforelse
|
||||
@endif
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
@@ -88,7 +88,6 @@
|
||||
<th>Location</th>
|
||||
<th>Pending Days</th>
|
||||
<th>Status</th>
|
||||
<th>Remark</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -118,7 +117,6 @@
|
||||
<td class="{{ $row['status_class'] ?? '' }}">
|
||||
{{ $row['status'] }}
|
||||
</td>
|
||||
<td>{{ $row['remark'] ?? '-'}}</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
|
||||
247
routes/web.php
247
routes/web.php
@@ -1,116 +1,76 @@
|
||||
<?php
|
||||
|
||||
use App\Http\Controllers\CharacteristicApprovalController;
|
||||
use App\Http\Controllers\FileUploadController;
|
||||
use App\Mail\test;
|
||||
use App\Models\EquipmentMaster;
|
||||
use App\Models\InvoiceValidation;
|
||||
use App\Models\Plant;
|
||||
use App\Models\User;
|
||||
use Filament\Facades\Filament;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Illuminate\Http\Request;
|
||||
use thiagoalessio\TesseractOCR\TesseractOCR;
|
||||
|
||||
Route::get('/', function () {
|
||||
return redirect('/admin');
|
||||
});
|
||||
|
||||
// Route::get('/admin', function () {
|
||||
// return redirect('/admin/welcome');
|
||||
// });
|
||||
Route::get('/', function () {
|
||||
return redirect('/admin');
|
||||
});
|
||||
|
||||
// ..Characteristic Approval Routes..//
|
||||
// routes/web.php
|
||||
Route::post('/save-serials-to-session', function (Request $request) {
|
||||
session(['serial_numbers' => $request->serial_numbers]);
|
||||
return response()->json([
|
||||
'status' => 'success',
|
||||
'serial_numbers' => session('serial_numbers'),
|
||||
]);
|
||||
});
|
||||
|
||||
Route::get('/characteristic/hold', [CharacteristicApprovalController::class, 'holdForm'])
|
||||
->name('characteristic.hold')
|
||||
->middleware('signed');
|
||||
Route::get('/part-validation-image/{filename}', function ($filename) {
|
||||
$path = storage_path("app/private/uploads/PartValidation/{$filename}");
|
||||
|
||||
Route::post('/characteristic/hold-save', [CharacteristicApprovalController::class, 'holdSave'])
|
||||
->name('characteristic.hold.save');
|
||||
if (!file_exists($path)) {
|
||||
abort(404, 'Image not found');
|
||||
}
|
||||
|
||||
Route::get('/approval/hold-success', function () {
|
||||
return view('approval.hold-success');
|
||||
})->name('approval.hold.success');
|
||||
return response()->file($path);
|
||||
})->name('part.validation.image');
|
||||
|
||||
Route::get('/characteristic/reject', [CharacteristicApprovalController::class, 'rejectForm'])
|
||||
->name('characteristic.reject')
|
||||
->middleware('signed');
|
||||
// web.php
|
||||
Route::post('/temp-upload', function (Request $request) {
|
||||
if (!$request->hasFile('photo')) {
|
||||
return response()->json(['success' => false], 400);
|
||||
}
|
||||
|
||||
Route::post('/characteristic/reject-save', [CharacteristicApprovalController::class, 'rejectSave'])
|
||||
->name('characteristic.reject.save');
|
||||
$file = $request->file('photo');
|
||||
$filename = 'capture_' . time() . '.jpeg';
|
||||
$path = $file->storeAs('temp', $filename, 'local'); // storage/app/temp
|
||||
|
||||
Route::get('/approval/reject-success', function () {
|
||||
return view('approval.reject-success');
|
||||
})->name('approval.reject.success');
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'path' => $path,
|
||||
]);
|
||||
});
|
||||
|
||||
Route::get('/characteristic/approve', [CharacteristicApprovalController::class, 'approve'])
|
||||
->name('characteristic.approve')
|
||||
->middleware('signed');
|
||||
Route::post('/verify-ocr', function (Request $request) {
|
||||
|
||||
Route::post('/file-upload', [FileUploadController::class, 'upload'])->name('file.upload');
|
||||
if (!$request->has('path')) {
|
||||
return response()->json(['success' => false, 'error' => 'No file path provided']);
|
||||
}
|
||||
|
||||
// Route::get('/characteristic/hold', [CharacteristicApprovalController::class, 'hold'])
|
||||
// ->name('characteristic.hold')
|
||||
// ->middleware('signed');
|
||||
$filePath = storage_path('app/private/temp/' . basename($request->path));
|
||||
|
||||
// Route::get('/characteristic/reject', [CharacteristicApprovalController::class, 'reject'])
|
||||
// ->name('characteristic.reject')
|
||||
// ->middleware('signed');
|
||||
if (!file_exists($filePath)) {
|
||||
return response()->json(['success' => false, 'error' => 'File not found']);
|
||||
}
|
||||
|
||||
// routes/web.php
|
||||
Route::post('/save-serials-to-session', function (Request $request) {
|
||||
session(['serial_numbers' => $request->serial_numbers]);
|
||||
|
||||
return response()->json([
|
||||
'status' => 'success',
|
||||
'serial_numbers' => session('serial_numbers'),
|
||||
]);
|
||||
});
|
||||
|
||||
Route::get('/part-validation-image/{filename}', function ($filename) {
|
||||
$path = storage_path("app/private/uploads/PartValidation/{$filename}");
|
||||
|
||||
if (! file_exists($path)) {
|
||||
abort(404, 'Image not found');
|
||||
}
|
||||
|
||||
return response()->file($path);
|
||||
})->name('part.validation.image');
|
||||
|
||||
// web.php
|
||||
Route::post('/temp-upload', function (Request $request) {
|
||||
if (! $request->hasFile('photo')) {
|
||||
return response()->json(['success' => false], 400);
|
||||
}
|
||||
|
||||
$file = $request->file('photo');
|
||||
$filename = 'capture_'.time().'.jpeg';
|
||||
$path = $file->storeAs('temp', $filename, 'local'); // storage/app/temp
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'path' => $path,
|
||||
]);
|
||||
});
|
||||
|
||||
Route::post('/verify-ocr', function (Request $request) {
|
||||
|
||||
if (! $request->has('path')) {
|
||||
return response()->json(['success' => false, 'error' => 'No file path provided']);
|
||||
}
|
||||
|
||||
$filePath = storage_path('app/private/temp/'.basename($request->path));
|
||||
|
||||
if (! file_exists($filePath)) {
|
||||
return response()->json(['success' => false, 'error' => 'File not found']);
|
||||
}
|
||||
|
||||
try {
|
||||
try {
|
||||
// $text = (new TesseractOCR($filePath))->lang('eng')->run();
|
||||
$text = (new TesseractOCR($filePath))
|
||||
->executable('/usr/bin/tesseract')
|
||||
->lang('eng')
|
||||
->psm(6) // treats the image as a block of text
|
||||
->config('tessedit_char_whitelist', '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz')
|
||||
->run();
|
||||
->executable('/usr/bin/tesseract')
|
||||
->lang('eng')
|
||||
->psm(6) // treats the image as a block of text
|
||||
->config('tessedit_char_whitelist', '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz')
|
||||
->run();
|
||||
|
||||
$text = trim($text); // remove whitespace
|
||||
|
||||
@@ -119,19 +79,19 @@ Route::post('/verify-ocr', function (Request $request) {
|
||||
return response()->json(['success' => true, 'text' => 'Text not found']);
|
||||
}
|
||||
|
||||
// return response()->json(['success' => true, 'text' => $text]);
|
||||
$lines = preg_split('/\r\n|\r|\n/', $text);
|
||||
$serials = array_filter(array_map('trim', $lines), fn ($line) => preg_match('/^[A-Za-z0-9]+$/', $line));
|
||||
//return response()->json(['success' => true, 'text' => $text]);
|
||||
$lines = preg_split('/\r\n|\r|\n/', $text);
|
||||
$serials = array_filter(array_map('trim', $lines), fn($line) => preg_match('/^[A-Za-z0-9]+$/', $line));
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'text' => array_values($serials), // reindex array
|
||||
]);
|
||||
}
|
||||
// catch (\Exception $e) {
|
||||
// return response()->json(['success' => false, 'error' => $e->getMessage()]);
|
||||
// }
|
||||
catch (\Exception $e) {
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'text' => array_values($serials) // reindex array
|
||||
]);
|
||||
}
|
||||
//catch (\Exception $e) {
|
||||
// return response()->json(['success' => false, 'error' => $e->getMessage()]);
|
||||
// }
|
||||
catch (\Exception $e) {
|
||||
// Log the full exception class and message
|
||||
\Log::error('Tesseract OCR failed', [
|
||||
'exception_class' => get_class($e),
|
||||
@@ -151,61 +111,62 @@ Route::post('/verify-ocr', function (Request $request) {
|
||||
'trace' => $e->getTraceAsString(),
|
||||
]);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Route::get('/download/{equipmentNumber}', function ($equipmentNumber) {
|
||||
Route::get('/download/{equipmentNumber}', function ($equipmentNumber) {
|
||||
$model = EquipmentMaster::where('equipment_number', $equipmentNumber)->firstOrFail();
|
||||
|
||||
if (! $model->attachment || ! Storage::disk('local')->exists($model->attachment)) {
|
||||
abort(404, 'File not found.');
|
||||
}
|
||||
return Storage::disk('local')->download($model->attachment);
|
||||
})->name('download.attachment');
|
||||
|
||||
return Storage::disk('local')->download($model->attachment);
|
||||
})->name('download.attachment');
|
||||
// Route::get('/admin/forgot-password', function () {
|
||||
// return view('auth.forgot-password');
|
||||
// })->name('filament.admin.forgot-password');
|
||||
|
||||
// Route::get('/admin/forgot-password', function () {
|
||||
// return view('auth.forgot-password');
|
||||
// })->name('filament.admin.forgot-password');
|
||||
|
||||
// Route::post('/admin/forgot-password', function(Request $request){
|
||||
// Route::post('/admin/forgot-password', function(Request $request){
|
||||
|
||||
// $validator = Validator::make($request->all(), [
|
||||
// 'email'=>'required|email',
|
||||
// 'old_password'=>'required',
|
||||
// 'password'=>'required',
|
||||
// 'password_confirmation'=>'required'
|
||||
// ]);
|
||||
// $validator = Validator::make($request->all(), [
|
||||
// 'email'=>'required|email',
|
||||
// 'old_password'=>'required',
|
||||
// 'password'=>'required',
|
||||
// 'password_confirmation'=>'required'
|
||||
// ]);
|
||||
|
||||
// if($validator->fails()){
|
||||
// return response()->json([
|
||||
// 'emailError' => $validator->errors()->first('email'),
|
||||
// 'oldPasswordError' => $validator->errors()->first('old_password'),
|
||||
// 'newPasswordError' => $validator->errors()->first('password'),
|
||||
// 'confirmPasswordError' => $validator->errors()->first('password_confirmation')
|
||||
// ]);
|
||||
// }
|
||||
// if($validator->fails()){
|
||||
// return response()->json([
|
||||
// 'emailError' => $validator->errors()->first('email'),
|
||||
// 'oldPasswordError' => $validator->errors()->first('old_password'),
|
||||
// 'newPasswordError' => $validator->errors()->first('password'),
|
||||
// 'confirmPasswordError' => $validator->errors()->first('password_confirmation')
|
||||
// ]);
|
||||
// }
|
||||
|
||||
// $user = User::where('email',$request->email)->first();
|
||||
// if(!$user){
|
||||
// return response()->json(['passwordError'=>'No user found with this email.']);
|
||||
// }
|
||||
// $user = User::where('email',$request->email)->first();
|
||||
// if(!$user){
|
||||
// return response()->json(['passwordError'=>'No user found with this email.']);
|
||||
// }
|
||||
|
||||
// if(!Hash::check($request->old_password, $user->password)){
|
||||
// return response()->json(['oldPasswordError'=>'Old password does not match']);
|
||||
// }
|
||||
// if(!Hash::check($request->old_password, $user->password)){
|
||||
// return response()->json(['oldPasswordError'=>'Old password does not match']);
|
||||
// }
|
||||
|
||||
// if($request->password != $request->password_confirmation){
|
||||
// return response()->json(['newPasswordError'=>'New password and confirm password do not match']);
|
||||
// }
|
||||
// if($request->password != $request->password_confirmation){
|
||||
// return response()->json(['newPasswordError'=>'New password and confirm password do not match']);
|
||||
// }
|
||||
|
||||
// $user->password = Hash::make($request->password);
|
||||
// $user->save();
|
||||
// $user->password = Hash::make($request->password);
|
||||
// $user->save();
|
||||
|
||||
// return response()->json(['success'=>'Password changed successfully!']);
|
||||
// })->name('filament.admin.forgot-password.otp');
|
||||
// return response()->json(['success'=>'Password changed successfully!']);
|
||||
// })->name('filament.admin.forgot-password.otp');
|
||||
|
||||
// Route::post('/admin/check-email', function(Request $request){
|
||||
// $request->validate(['email' => 'required|email']);
|
||||
// $exists = User::where('email', $request->email)->first();
|
||||
// return response()->json(['exists' => $exists]);
|
||||
// })->name('admin.check-email');
|
||||
|
||||
// Route::post('/admin/check-email', function(Request $request){
|
||||
// $request->validate(['email' => 'required|email']);
|
||||
// $exists = User::where('email', $request->email)->first();
|
||||
// return response()->json(['exists' => $exists]);
|
||||
// })->name('admin.check-email');
|
||||
|
||||
Reference in New Issue
Block a user