# Create Missing Move Records for C1371

Run on the live server via `php artisan tinker` — one line at a time.

## Step 1 — Check the error log for why Move creation failed

```bash
grep -A 5 "OrderObserver.*failed\|failed.*Move" /var/www/html/Cydekick/storage/logs/laravel.log | tail -40
```

## Step 2 — Diagnose (run each line separately in tinker)

```php
// Check customer location exists on server
$cust = \Webkul\Inventory\Models\Location::where('type', 'customer')->first();
echo "Customer: id={$cust?->id} name={$cust?->name}\n";
```

```php
// Check product 1176 UOM and company
$product = \Webkul\Product\Models\Product::find(1176);
echo "Product: uom_id={$product?->uom_id} company_id=2\n";
```

```php
// Check Somerset4x4 internal location for this product
$pq = \Webkul\Inventory\Models\ProductQuantity::where('product_id', 1176)->with('location')->first();
echo "PQ: location_id={$pq?->location_id} qty={$pq?->quantity} loc_type={$pq?->location?->type?->value}\n";
```

```php
// Check UOM id=1 exists
$uom = \Webkul\Support\Models\UOM::find(1);
echo "UOM 1: {$uom?->name}\n";
// If null, find the right UOM:
\Webkul\Support\Models\UOM::all(['id','name'])->each(fn($u) => print("  uom id={$u->id} {$u->name}\n"));
```

## Step 3 — Create Move records directly

Replace `$CUSTOMER_ID`, `$SOURCE_LOC_ID`, `$UOM_ID` with values from Step 2.

```php
// AEU2147L (product_id=1176)
try {
    $move = \Webkul\Inventory\Models\Move::create([
        'name'                    => 'C1371',
        'origin'                  => 'C1371',
        'reference'               => 'C1371',
        'state'                   => 'done',
        'quantity'                => 1,
        'product_qty'             => 1,
        'product_uom_qty'         => 1,
        'product_id'              => 1176,
        'uom_id'                  => 1,       // ← confirm from Step 2
        'source_location_id'      => $pq->location_id,   // ← Somerset4x4/Stock
        'destination_location_id' => $cust->id,
        'company_id'              => 2,
        'scheduled_at'            => '2026-06-22 00:00:00',
        'procure_method'          => 'make_to_stock',
        'is_favorite'             => false,
        'is_picked'               => true,
        'is_scraped'              => false,
        'is_refund'               => false,
        'is_inventory'            => false,
    ]);
    echo "AEU2147L Move created: id={$move->id}\n";
} catch (\Throwable $e) {
    echo "ERROR: " . $e->getMessage() . "\n";
}
```

```php
// PRC6022 (product_id=6873) — find its PQ first
$pq2 = \Webkul\Inventory\Models\ProductQuantity::where('product_id', 6873)->with('location')->first();
echo "PRC6022 PQ: loc_id={$pq2?->location_id} qty={$pq2?->quantity}\n";
```

```php
// PRC6022 Move (only if it had stock before the deduction ran)
try {
    $move2 = \Webkul\Inventory\Models\Move::create([
        'name'                    => 'C1371',
        'origin'                  => 'C1371',
        'reference'               => 'C1371',
        'state'                   => 'done',
        'quantity'                => 1,
        'product_qty'             => 1,
        'product_uom_qty'         => 1,
        'product_id'              => 6873,
        'uom_id'                  => 1,
        'source_location_id'      => $pq2->location_id,
        'destination_location_id' => $cust->id,
        'company_id'              => 2,
        'scheduled_at'            => '2026-06-22 00:00:00',
        'procure_method'          => 'make_to_stock',
        'is_favorite'             => false,
        'is_picked'               => true,
        'is_scraped'              => false,
        'is_refund'               => false,
        'is_inventory'            => false,
    ]);
    echo "PRC6022 Move created: id={$move2->id}\n";
} catch (\Throwable $e) {
    echo "ERROR: " . $e->getMessage() . "\n";
}
```

## Step 4 — Verify

After running Step 3, reload the IN/OUT tab for AEU2147L:
`/admin/inventory/products/1176/moves`

You should now see a "Done" Move line with Source = Somerset4×4/Stock and Destination = Customers.

The £2.76 Total Value issue: this is a valuation ledger maintained separately.
If it doesn't auto-update after the Move, run:
```php
// Check if there's a valuation layer record
\Illuminate\Support\Facades\DB::table('inventories_valuation_layers')
    ->where('product_id', 1176)->get();
```
