From c4153169ebfd97ce3964aae9389a6f80f3d27599 Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Thu, 29 Jan 2026 18:51:23 +0530 Subject: [PATCH 1/2] Added generate mail report for deletable record count via scheduler daily at 7 AM --- routes/console.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/routes/console.php b/routes/console.php index 757e44a..ee3dd6b 100644 --- a/routes/console.php +++ b/routes/console.php @@ -3,8 +3,6 @@ use Illuminate\Foundation\Inspiring; use Illuminate\Support\Facades\Artisan; - - Artisan::command('inspire', function () { $this->comment(Inspiring::quote()); })->purpose('Display an inspiring quote'); @@ -13,6 +11,11 @@ Artisan::command('auto:scheduler', function () { $this->call('custom:scheduler'); })->everyMinute()->withoutOverlapping(); +Schedule::command('model:prune --pretend')// , ['--model' => WeightValidation::class] + ->description('Deletable Old Records From Database') + ->dailyAt('07:00') + ->emailOutputTo('digitalmanufacturingiiot@gmail.com'); + // app()->booted(function () { // $schedule = app(Schedule::class); -- 2.49.1 From 1b1a02a5654d650e7176c01165e37eea174cee2d Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Thu, 29 Jan 2026 19:01:02 +0530 Subject: [PATCH 2/2] Added prune logic for transaction models --- app/Models/CharacteristicValue.php | 9 +- app/Models/ClassCharacteristic.php | 8 ++ app/Models/EbReading.php | 8 ++ app/Models/InvoiceDataValidation.php | 8 ++ app/Models/InvoiceInTransit.php | 60 +++++----- app/Models/InvoiceOutValidation.php | 8 ++ app/Models/InvoiceValidation.php | 12 +- app/Models/LocatorInvoiceValidation.php | 30 +++-- app/Models/MfmReading.php | 30 +++-- app/Models/PalletValidation.php | 26 +++-- app/Models/ProcessOrder.php | 10 +- app/Models/ProductionLineStop.php | 30 +++-- app/Models/ProductionPlan.php | 23 ++-- app/Models/ProductionQuantity.php | 33 +++--- app/Models/QualityValidation.php | 12 +- app/Models/RequestCharacteristic.php | 13 ++- app/Models/ReworkLocatorInvoiceValidation.php | 35 +++--- app/Models/SerialValidation.php | 11 +- app/Models/StickerPrinting.php | 10 +- app/Models/TempLiveReading.php | 18 ++- app/Models/TestingPanelReading.php | 103 ++++++++++-------- 21 files changed, 326 insertions(+), 171 deletions(-) diff --git a/app/Models/CharacteristicValue.php b/app/Models/CharacteristicValue.php index e190168..450bd22 100644 --- a/app/Models/CharacteristicValue.php +++ b/app/Models/CharacteristicValue.php @@ -2,13 +2,15 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Prunable; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\SoftDeletes; class CharacteristicValue extends Model { - + use Prunable; use SoftDeletes; protected $fillable = [ @@ -45,4 +47,9 @@ class CharacteristicValue extends Model { return $this->belongsTo(Machine::class); } + + public function prunable(): Builder + { + return static::where('created_at', '<=', now()->subMonthsNoOverflow(6)); + } } diff --git a/app/Models/ClassCharacteristic.php b/app/Models/ClassCharacteristic.php index 2ee37fd..42bc6cc 100644 --- a/app/Models/ClassCharacteristic.php +++ b/app/Models/ClassCharacteristic.php @@ -2,12 +2,15 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Prunable; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\SoftDeletes; class ClassCharacteristic extends Model { + use Prunable; use SoftDeletes; protected $fillable = [ @@ -179,4 +182,9 @@ class ClassCharacteristic extends Model { return $this->belongsTo(Machine::class); } + + public function prunable(): Builder + { + return static::where('created_at', '<=', now()->subMonthsNoOverflow(6)); + } } diff --git a/app/Models/EbReading.php b/app/Models/EbReading.php index c5d7529..86bc078 100644 --- a/app/Models/EbReading.php +++ b/app/Models/EbReading.php @@ -2,12 +2,15 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Prunable; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\SoftDeletes; class EbReading extends Model { + use Prunable; use SoftDeletes; protected $fillable = [ @@ -66,4 +69,9 @@ class EbReading extends Model { return $this->belongsTo(Plant::class); } + + public function prunable(): Builder + { + return static::where('created_at', '<=', now()->subMonthsNoOverflow(6)); + } } diff --git a/app/Models/InvoiceDataValidation.php b/app/Models/InvoiceDataValidation.php index e705294..7454c61 100644 --- a/app/Models/InvoiceDataValidation.php +++ b/app/Models/InvoiceDataValidation.php @@ -2,12 +2,15 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Prunable; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\SoftDeletes; class InvoiceDataValidation extends Model { + use Prunable; use SoftDeletes; protected $dates = ['deleted_at']; @@ -32,4 +35,9 @@ class InvoiceDataValidation extends Model { return $this->belongsTo(Plant::class); } + + public function prunable(): Builder + { + return static::where('created_at', '<=', now()->subMonthsNoOverflow(6)); + } } diff --git a/app/Models/InvoiceInTransit.php b/app/Models/InvoiceInTransit.php index afb3c21..1bb38d3 100644 --- a/app/Models/InvoiceInTransit.php +++ b/app/Models/InvoiceInTransit.php @@ -2,45 +2,53 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Prunable; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\SoftDeletes; class InvoiceInTransit extends Model { + use Prunable; use SoftDeletes; protected $fillable = [ - "plant_id", - "receiving_plant", - "receiving_plant_name", - "invoice_number", - "invoice_date", - "item_code", - "description", - "quantity", - "transport_name", - "lr_bl_aw_number", - "lr_bl_aw_date", - "pending_days", - "obd_number", - "obd_date", - "shipment_weight", - "unit_price", - "net_value", - "total_item_amount", - "tax_amount", - "transport_mode", - "vehicle_number", - "e_waybill_number", - "created_at", - "created_by", - "updated_by", - "updated_at" + 'plant_id', + 'receiving_plant', + 'receiving_plant_name', + 'invoice_number', + 'invoice_date', + 'item_code', + 'description', + 'quantity', + 'transport_name', + 'lr_bl_aw_number', + 'lr_bl_aw_date', + 'pending_days', + 'obd_number', + 'obd_date', + 'shipment_weight', + 'unit_price', + 'net_value', + 'total_item_amount', + 'tax_amount', + 'transport_mode', + 'vehicle_number', + 'e_waybill_number', + 'created_at', + 'created_by', + 'updated_by', + 'updated_at', ]; public function plant(): BelongsTo { return $this->belongsTo(Plant::class); } + + public function prunable(): Builder + { + return static::where('created_at', '<=', now()->subMonthsNoOverflow(6)); + } } diff --git a/app/Models/InvoiceOutValidation.php b/app/Models/InvoiceOutValidation.php index 6af8050..8562a35 100644 --- a/app/Models/InvoiceOutValidation.php +++ b/app/Models/InvoiceOutValidation.php @@ -2,12 +2,15 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Prunable; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\SoftDeletes; class InvoiceOutValidation extends Model { + use Prunable; use SoftDeletes; // protected $dates = ['deleted_at']; @@ -27,4 +30,9 @@ class InvoiceOutValidation extends Model { return $this->belongsTo(Plant::class); } + + public function prunable(): Builder + { + return static::where('created_at', '<=', now()->subMonthsNoOverflow(6)); + } } diff --git a/app/Models/InvoiceValidation.php b/app/Models/InvoiceValidation.php index 11a9cbd..0413a71 100644 --- a/app/Models/InvoiceValidation.php +++ b/app/Models/InvoiceValidation.php @@ -2,18 +2,21 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Prunable; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\SoftDeletes; class InvoiceValidation extends Model { + use Prunable; use SoftDeletes; protected $fillable = [ 'sticker_master_id', 'plant_id', - 'invoice_number', + 'invoice_number', 'serial_number', 'motor_scanned_status', 'pump_scanned_status', @@ -38,11 +41,14 @@ class InvoiceValidation extends Model { return $this->belongsTo(StickerMaster::class); } - + public function stickerMasterRelation() { return $this->belongsTo(StickerMaster::class, 'sticker_master_id'); } - + public function prunable(): Builder + { + return static::where('created_at', '<=', now()->subMonthsNoOverflow(6)); + } } diff --git a/app/Models/LocatorInvoiceValidation.php b/app/Models/LocatorInvoiceValidation.php index 2b57cba..57059a1 100644 --- a/app/Models/LocatorInvoiceValidation.php +++ b/app/Models/LocatorInvoiceValidation.php @@ -2,32 +2,40 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Prunable; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\SoftDeletes; class LocatorInvoiceValidation extends Model { + use Prunable; use SoftDeletes; protected $fillable = [ 'plant_id', - 'invoice_number', + 'invoice_number', 'serial_number', - 'pallet_number', - 'locator_number', - 'scanned_status', - 'upload_status', - 'created_at', - 'updated_at', - 'scanned_at', - 'created_by', - 'scanned_by', - 'updated_by', + 'pallet_number', + 'locator_number', + 'scanned_status', + 'upload_status', + 'created_at', + 'updated_at', + 'scanned_at', + 'created_by', + 'scanned_by', + 'updated_by', ]; public function plant(): BelongsTo { return $this->belongsTo(Plant::class); } + + public function prunable(): Builder + { + return static::where('created_at', '<=', now()->subMonthsNoOverflow(6)); + } } diff --git a/app/Models/MfmReading.php b/app/Models/MfmReading.php index 272f60a..6d4a920 100644 --- a/app/Models/MfmReading.php +++ b/app/Models/MfmReading.php @@ -2,39 +2,42 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Prunable; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\SoftDeletes; class MfmReading extends Model { + use Prunable; use SoftDeletes; protected $fillable = [ 'plant_id', 'mfm_meter_id', - 'apparent_energy_received', + 'apparent_energy_received', 'reactive_energy_received', 'active_energy_received', 'active_power_r', - 'active_power_y', - 'active_power_b', + 'active_power_y', + 'active_power_b', 'active_power_total', - 'voltage_ry', - 'voltage_yb', + 'voltage_ry', + 'voltage_yb', 'voltage_br', 'current_r', - 'current_y', + 'current_y', 'current_b', 'current_n', - 'voltage_r_n', - 'voltage_y_n', + 'voltage_r_n', + 'voltage_y_n', 'voltage_b_n', - 'frequency', - 'power_factor_r', + 'frequency', + 'power_factor_r', 'power_factor_y', 'power_factor_b', - 'power_factor_total', + 'power_factor_total', 'created_at', 'updated_at', ]; @@ -48,4 +51,9 @@ class MfmReading extends Model { return $this->belongsTo(MfmMeter::class, 'mfm_meter_id'); } + + public function prunable(): Builder + { + return static::where('created_at', '<=', now()->subMonthsNoOverflow(6)); + } } diff --git a/app/Models/PalletValidation.php b/app/Models/PalletValidation.php index b98d7e5..fda41cf 100644 --- a/app/Models/PalletValidation.php +++ b/app/Models/PalletValidation.php @@ -2,31 +2,39 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Prunable; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\SoftDeletes; class PalletValidation extends Model { + use Prunable; use SoftDeletes; protected $fillable = [ 'plant_id', - 'pallet_number', + 'pallet_number', 'serial_number', - 'pallet_status', - 'locator_number', + 'pallet_status', + 'locator_number', 'locator_quantity', - 'created_at', - 'updated_at', - 'scanned_at', - 'created_by', - 'scanned_by', - 'updated_by', + 'created_at', + 'updated_at', + 'scanned_at', + 'created_by', + 'scanned_by', + 'updated_by', ]; public function plant(): BelongsTo { return $this->belongsTo(Plant::class); } + + public function prunable(): Builder + { + return static::where('created_at', '<=', now()->subMonthsNoOverflow(6)); + } } diff --git a/app/Models/ProcessOrder.php b/app/Models/ProcessOrder.php index b5e46f8..76d84f8 100644 --- a/app/Models/ProcessOrder.php +++ b/app/Models/ProcessOrder.php @@ -2,12 +2,15 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Prunable; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\SoftDeletes; class ProcessOrder extends Model { + use Prunable; use SoftDeletes; protected $fillable = [ @@ -24,8 +27,8 @@ class ProcessOrder extends Model 'rework_status', 'created_at', 'created_by', - 'updated_by', 'updated_at', + 'updated_by', ]; public function plant(): BelongsTo @@ -42,4 +45,9 @@ class ProcessOrder extends Model { return $this->belongsTo(Item::class, 'item_id'); } + + public function prunable(): Builder + { + return static::where('created_at', '<=', now()->subMonthsNoOverflow(6)); + } } diff --git a/app/Models/ProductionLineStop.php b/app/Models/ProductionLineStop.php index fb88ff9..13f9437 100644 --- a/app/Models/ProductionLineStop.php +++ b/app/Models/ProductionLineStop.php @@ -2,24 +2,29 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; -use Illuminate\Database\Eloquent\SoftDeletes; +use Illuminate\Database\Eloquent\Prunable; use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Illuminate\Database\Eloquent\SoftDeletes; class ProductionLineStop extends Model { + use Prunable; use SoftDeletes; protected $fillable = [ - "plant_id", - "shift_id", - "line_id", - "linestop_id", - "from_datetime", - "to_datetime", - "stop_hour", - "stop_min", - "operator_id", + 'plant_id', + 'line_id', + 'shift_id', + 'linestop_id', + 'from_datetime', + 'to_datetime', + 'stop_hour', + 'stop_min', + 'operator_id', + 'created_at', + 'updated_at', ]; public function plant(): BelongsTo @@ -48,5 +53,8 @@ class ProductionLineStop extends Model // return $this->belongsTo(LineStop::class, 'linestop_id'); // } - + public function prunable(): Builder + { + return static::where('created_at', '<=', now()->subMonthsNoOverflow(6)); + } } diff --git a/app/Models/ProductionPlan.php b/app/Models/ProductionPlan.php index 56ca38c..35bbb39 100644 --- a/app/Models/ProductionPlan.php +++ b/app/Models/ProductionPlan.php @@ -2,22 +2,26 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Prunable; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\SoftDeletes; class ProductionPlan extends Model { + use Prunable; use SoftDeletes; protected $fillable = [ - "plant_id", - "shift_id", - "created_at", - "line_id", - "plan_quantity", - "production_quantity", - "operator_id", + 'plant_id', + 'shift_id', + 'line_id', + 'plan_quantity', + 'production_quantity', + 'operator_id', + 'created_at', + 'updated_at', ]; public function plant(): BelongsTo @@ -34,4 +38,9 @@ class ProductionPlan extends Model { return $this->belongsTo(Line::class); } + + public function prunable(): Builder + { + return static::where('created_at', '<=', now()->subMonthsNoOverflow(6)); + } } diff --git a/app/Models/ProductionQuantity.php b/app/Models/ProductionQuantity.php index f3eeeb9..88cef82 100644 --- a/app/Models/ProductionQuantity.php +++ b/app/Models/ProductionQuantity.php @@ -4,30 +4,33 @@ namespace App\Models; use Carbon\Carbon; use Filament\Facades\Filament; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; -use Illuminate\Database\Eloquent\SoftDeletes; +use Illuminate\Database\Eloquent\Prunable; use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Illuminate\Database\Eloquent\SoftDeletes; class ProductionQuantity extends Model { + use Prunable; use SoftDeletes; public static $importing = false; // Add this flag protected $fillable = [ - "plant_id", - "shift_id", - "line_id", - "item_id", - "serial_number", - "production_order", - "operator_id", + 'plant_id', + 'shift_id', + 'line_id', + 'item_id', + 'serial_number', + 'production_order', + 'operator_id', // "success_status", + // "notok_at", // "no_of_employee", // "list_of_employee", - "created_at", - "updated_at" - + 'created_at', + 'updated_at', ]; public function plant(): BelongsTo @@ -66,8 +69,7 @@ class ProductionQuantity extends Model ->latest() ->first(); - if (!$productionPlan) - { + if (! $productionPlan) { $productionPlan = ProductionPlan::where('plant_id', $productionQuantity->plant_id) ->where('shift_id', $productionQuantity->shift_id) ->where('line_id', $productionQuantity->line_id) @@ -88,4 +90,9 @@ class ProductionQuantity extends Model } }); } + + public function prunable(): Builder + { + return static::where('created_at', '<=', now()->subMonthsNoOverflow(6)); + } } diff --git a/app/Models/QualityValidation.php b/app/Models/QualityValidation.php index b4110c8..0b1aa42 100644 --- a/app/Models/QualityValidation.php +++ b/app/Models/QualityValidation.php @@ -2,19 +2,22 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Prunable; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\SoftDeletes; class QualityValidation extends Model { + use Prunable; use SoftDeletes; protected $fillable = [ 'sticker_master_id', - 'plant_id', + 'plant_id', 'line_id', - 'production_order', + 'production_order', 'serial_number_motor', 'serial_number_pump', 'serial_number_pumpset', @@ -56,4 +59,9 @@ class QualityValidation extends Model { return $this->belongsTo(Line::class); } + + public function prunable(): Builder + { + return static::where('created_at', '<=', now()->subMonthsNoOverflow(6)); + } } diff --git a/app/Models/RequestCharacteristic.php b/app/Models/RequestCharacteristic.php index 40f7cd6..197dcd8 100644 --- a/app/Models/RequestCharacteristic.php +++ b/app/Models/RequestCharacteristic.php @@ -2,12 +2,15 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Prunable; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\SoftDeletes; class RequestCharacteristic extends Model { + use Prunable; use SoftDeletes; protected $fillable = [ @@ -48,7 +51,6 @@ class RequestCharacteristic extends Model return $this->belongsTo(Item::class); } - public function machine(): BelongsTo { return $this->belongsTo(Machine::class); @@ -91,9 +93,8 @@ class RequestCharacteristic extends Model ); } - - - - - + public function prunable(): Builder + { + return static::where('created_at', '<=', now()->subMonthsNoOverflow(6)); + } } diff --git a/app/Models/ReworkLocatorInvoiceValidation.php b/app/Models/ReworkLocatorInvoiceValidation.php index fb2841e..bb46301 100644 --- a/app/Models/ReworkLocatorInvoiceValidation.php +++ b/app/Models/ReworkLocatorInvoiceValidation.php @@ -2,30 +2,33 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Prunable; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\SoftDeletes; class ReworkLocatorInvoiceValidation extends Model { + use Prunable; use SoftDeletes; protected $fillable = [ 'plant_id', - 'invoice_number', - 'serial_number', - 'pallet_number', - 'locator_number', - 'scanned_status', - 'upload_status', - 'created_by', - 'scanned_by', - 'updated_by', - 'reworked_by', - 'created_at', - 'updated_at', - 'scanned_at', - 'reworked_at', + 'invoice_number', + 'serial_number', + 'pallet_number', + 'locator_number', + 'scanned_status', + 'upload_status', + 'created_by', + 'scanned_by', + 'updated_by', + 'reworked_by', + 'created_at', + 'updated_at', + 'scanned_at', + 'reworked_at', ]; public function plant(): BelongsTo @@ -33,4 +36,8 @@ class ReworkLocatorInvoiceValidation extends Model return $this->belongsTo(Plant::class); } + public function prunable(): Builder + { + return static::where('created_at', '<=', now()->subMonthsNoOverflow(6)); + } } diff --git a/app/Models/SerialValidation.php b/app/Models/SerialValidation.php index 258fadf..a78a639 100644 --- a/app/Models/SerialValidation.php +++ b/app/Models/SerialValidation.php @@ -2,19 +2,21 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Prunable; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\SoftDeletes; class SerialValidation extends Model { - + use Prunable; use SoftDeletes; protected $fillable = [ 'sticker_master_id', 'plant_id', - 'invoice_number', + 'invoice_number', 'serial_number', 'motor_scanned_status', 'pump_scanned_status', @@ -44,4 +46,9 @@ class SerialValidation extends Model { return $this->belongsTo(StickerMaster::class, 'sticker_master_id'); } + + public function prunable(): Builder + { + return static::where('created_at', '<=', now()->subMonthsNoOverflow(6)); + } } diff --git a/app/Models/StickerPrinting.php b/app/Models/StickerPrinting.php index 1570632..a3379cc 100644 --- a/app/Models/StickerPrinting.php +++ b/app/Models/StickerPrinting.php @@ -2,14 +2,15 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Prunable; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\SoftDeletes; class StickerPrinting extends Model { - // - + use Prunable; use SoftDeletes; protected $fillable = [ @@ -26,4 +27,9 @@ class StickerPrinting extends Model { return $this->belongsTo(Plant::class); } + + public function prunable(): Builder + { + return static::where('created_at', '<=', now()->subMonthsNoOverflow(6)); + } } diff --git a/app/Models/TempLiveReading.php b/app/Models/TempLiveReading.php index 141a47d..d5911a1 100644 --- a/app/Models/TempLiveReading.php +++ b/app/Models/TempLiveReading.php @@ -2,30 +2,38 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Prunable; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\SoftDeletes; class TempLiveReading extends Model { - use SoftDeletes; + use Prunable; + use SoftDeletes; protected $fillable = [ 'plant_id', 'mfm_meter_id', - 'register_data', + 'register_data', 'created_at', - 'updated_at', - 'created_by', + 'updated_at', + 'created_by', ]; public function plant(): BelongsTo { return $this->belongsTo(Plant::class); } - + public function mfmMeter(): BelongsTo { return $this->belongsTo(MfmMeter::class, 'mfm_meter_id'); } + + public function prunable(): Builder + { + return static::where('created_at', '<=', now()->subMonthsNoOverflow(6)); + } } diff --git a/app/Models/TestingPanelReading.php b/app/Models/TestingPanelReading.php index f50175c..991ee49 100644 --- a/app/Models/TestingPanelReading.php +++ b/app/Models/TestingPanelReading.php @@ -2,66 +2,69 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Prunable; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\SoftDeletes; class TestingPanelReading extends Model { + use Prunable; use SoftDeletes; protected $fillable = [ 'plant_id', - 'line_id', - 'motor_testing_master_id', - 'machine_id', - 'output', - 'serial_number', + 'line_id', + 'motor_testing_master_id', + 'machine_id', + 'output', + 'serial_number', 'winded_serial_number', - 'before_fr_volt', - 'before_fr_cur', - 'before_fr_pow', - 'before_fr_res_ry', - 'before_fr_res_yb', - 'before_fr_res_br', - 'before_fr_ir', - 'before_fr_ir_r', - 'before_fr_ir_y', - 'before_fr_ir_b', - 'before_fr_freq', - 'before_fr_speed', - 'after_fr_vol', - 'after_fr_cur', - 'after_fr_pow', - 'after_fr_ir_hot', - 'after_fr_ir_hot_r', - 'after_fr_ir_hot_y', - 'after_fr_ir_hot_b', - 'after_fr_ir_cool', - 'after_fr_ir_cool_r', - 'after_fr_ir_cool_y', - 'after_fr_ir_cool_b', - 'after_fr_freq', - 'after_fr_speed', - 'after_fr_leak_cur', - 'locked_rt_volt', - 'locked_rt_cur', - 'locked_rt_pow', - 'no_load_pickup_volt', - 'room_temperature', - 'hv_test', - 'batch_number', - 'batch_count', - 'result', - 'remark', - 'rework_count', + 'before_fr_volt', + 'before_fr_cur', + 'before_fr_pow', + 'before_fr_res_ry', + 'before_fr_res_yb', + 'before_fr_res_br', + 'before_fr_ir', + 'before_fr_ir_r', + 'before_fr_ir_y', + 'before_fr_ir_b', + 'before_fr_freq', + 'before_fr_speed', + 'after_fr_vol', + 'after_fr_cur', + 'after_fr_pow', + 'after_fr_ir_hot', + 'after_fr_ir_hot_r', + 'after_fr_ir_hot_y', + 'after_fr_ir_hot_b', + 'after_fr_ir_cool', + 'after_fr_ir_cool_r', + 'after_fr_ir_cool_y', + 'after_fr_ir_cool_b', + 'after_fr_freq', + 'after_fr_speed', + 'after_fr_leak_cur', + 'locked_rt_volt', + 'locked_rt_cur', + 'locked_rt_pow', + 'no_load_pickup_volt', + 'room_temperature', + 'hv_test', + 'batch_number', + 'batch_count', + 'result', + 'remark', + 'rework_count', 'update_count', 'output_flag', - 'tested_by', - 'updated_by', + 'tested_by', + 'updated_by', 'created_at', 'updated_at', - 'scanned_at', + 'scanned_at', ]; public function plant(): BelongsTo @@ -69,10 +72,11 @@ class TestingPanelReading extends Model return $this->belongsTo(Plant::class); } - public function line(): BelongsTo + public function line(): BelongsTo { return $this->belongsTo(Line::class); } + public function machine(): BelongsTo { return $this->belongsTo(Machine::class); @@ -83,8 +87,13 @@ class TestingPanelReading extends Model return $this->belongsTo(Item::class); } - public function motorTestingMaster() + public function motorTestingMaster() { return $this->belongsTo(MotorTestingMaster::class); } + + public function prunable(): Builder + { + return static::where('created_at', '<=', now()->subMonthsNoOverflow(6)); + } } -- 2.49.1