80 lines
2.1 KiB
PHP
80 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use Illuminate\Console\Command;
|
|
use App\Models\Invoice;
|
|
use App\Models\Order;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class TestVMSave extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'test:vm-save {order_id} {vm_id}';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'Test saving VM ID to invoice table';
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*/
|
|
public function handle()
|
|
{
|
|
$orderId = $this->argument('order_id');
|
|
$vmId = $this->argument('vm_id');
|
|
|
|
$this->info("Testing VM ID save for Order #{$orderId} with VM ID: {$vmId}");
|
|
|
|
try {
|
|
// Tìm order
|
|
$order = Order::find($orderId);
|
|
if (!$order) {
|
|
$this->error("Order #{$orderId} not found!");
|
|
return 1;
|
|
}
|
|
|
|
$this->info("Found order: {$order->order_num}");
|
|
|
|
// Tìm invoice tương ứng
|
|
$invoice = Invoice::where('order_id', $orderId)->first();
|
|
if (!$invoice) {
|
|
$this->error("Invoice for Order #{$orderId} not found!");
|
|
return 1;
|
|
}
|
|
|
|
$this->info("Found invoice: #{$invoice->id}");
|
|
|
|
// Lưu vm_id
|
|
$oldVmId = $invoice->vm_id;
|
|
$invoice->update(['vm_id' => $vmId]);
|
|
|
|
$this->info("✅ Successfully updated VM ID:");
|
|
$this->info(" Old VM ID: " . ($oldVmId ?? 'NULL'));
|
|
$this->info(" New VM ID: {$vmId}");
|
|
|
|
// Verify
|
|
$invoice->refresh();
|
|
if ($invoice->vm_id === $vmId) {
|
|
$this->info("✅ Verification successful - VM ID saved correctly");
|
|
} else {
|
|
$this->error("❌ Verification failed - VM ID not saved correctly");
|
|
return 1;
|
|
}
|
|
|
|
return 0;
|
|
|
|
} catch (\Exception $e) {
|
|
$this->error("Error: " . $e->getMessage());
|
|
Log::error('TestVMSave error: ' . $e->getMessage());
|
|
return 1;
|
|
}
|
|
}
|
|
}
|