Index: app/Models/Batch.php
===================================================================
--- app/Models/Batch.php	(revision 5f313241c1feb027aa5371c417930b38562c8625)
+++ app/Models/Batch.php	(revision 35b5d403322cce0cabaa8c872113cb24a80e377a)
@@ -34,6 +34,6 @@
     public function orders(): BelongsToMany
     {
-        return $this->belongsToMany(Order::class, 'order_products')
-            ->withPivot('quantity')
+        return $this->belongsToMany(Order::class, 'order_batches')
+            ->withPivot('quantity', 'price_per_unit', 'total_price')
             ->withTimestamps();
     }
Index: app/Models/Order.php
===================================================================
--- app/Models/Order.php	(revision 5f313241c1feb027aa5371c417930b38562c8625)
+++ app/Models/Order.php	(revision 35b5d403322cce0cabaa8c872113cb24a80e377a)
@@ -8,4 +8,5 @@
 use Illuminate\Database\Eloquent\Relations\BelongsTo;
 use Illuminate\Database\Eloquent\Relations\BelongsToMany;
+use Illuminate\Database\Eloquent\Relations\HasOne;
 
 class Order extends Model
@@ -47,32 +48,32 @@
     }
 
-    public function invoice()
+    public function invoice(): HasOne
     {
         return $this->hasOne(Invoice::class);
     }
 
-    public function products():BelongsToMany
+    //ova ne mi treba deka ide kroz batches ne products
+//    public function products(): BelongsToMany
+//    {
+//        return $this->belongsToMany(Product::class, 'order_products')
+//            ->withPivot('quantity', 'price_per_unit', 'total_price')
+//            ->withTimestamps();
+//    }
+
+    public function batches(): BelongsToMany
     {
-        return $this->belongsToMany(Product::class, 'order_products')
+        return $this->belongsToMany(Batch::class, 'order_batches')
             ->withPivot('quantity', 'price_per_unit', 'total_price')
             ->withTimestamps();
     }
 
-    public function batches(): BelongsToMany
-    {
-        return $this->belongsToMany(Batch::class, 'order_batches')
-            ->withPivot('quantity')
-            ->withTimestamps();
-    }
-
-    public function packingList()
+    public function packingList(): HasOne
     {
         return $this->hasOne(PackingList::class);
     }
 
-    // Helper to calculate the total amount
-//    public function getTotalAmountAttribute(): float
-//    {
-//        return $this->products->sum('pivot.total_price') ?? 0;
-//    }
+    public function getTotalAmountAttribute(): float
+    {
+        return $this->batches->sum('pivot.total_price') ?? 0;
+    }
 }
Index: app/Models/Product.php
===================================================================
--- app/Models/Product.php	(revision 5f313241c1feb027aa5371c417930b38562c8625)
+++ app/Models/Product.php	(revision 35b5d403322cce0cabaa8c872113cb24a80e377a)
@@ -35,8 +35,9 @@
     }
 
-    public function orders(): BelongsToMany
-    {
-        return $this->belongsToMany(Order::class, 'order_products', 'product_id', 'order_id');
-    }
+    //ne mi treba ova zasho ne ide direktno kroz orders tuku kroz batches
+//    public function orders(): BelongsToMany
+//    {
+//        return $this->belongsToMany(Order::class, 'order_products', 'product_id', 'order_id');
+//    }
 
     public function batches(): HasMany
Index: database/factories/ClientFactory.php
===================================================================
--- database/factories/ClientFactory.php	(revision 5f313241c1feb027aa5371c417930b38562c8625)
+++ database/factories/ClientFactory.php	(revision 35b5d403322cce0cabaa8c872113cb24a80e377a)
@@ -19,5 +19,5 @@
             'country' => $this->faker->country(),
             'registration_number' => $this->faker->regexify('[A-Z]{2}[0-9]{8}'),
-            'tax_id' => $this->faker->regexify('TAX[0-9]{10}'),
+            'tax_code' => $this->faker->regexify('TAX[0-9]{10}'),
             'contact_person' => $this->faker->name(),
             'phone_number' => $this->faker->phoneNumber(),
Index: tabase/migrations/2025_08_07_143525_create_order_products_table.php
===================================================================
--- database/migrations/2025_08_07_143525_create_order_products_table.php	(revision 5f313241c1feb027aa5371c417930b38562c8625)
+++ 	(revision )
@@ -1,42 +1,0 @@
-<?php
-
-use Illuminate\Database\Migrations\Migration;
-use Illuminate\Database\Schema\Blueprint;
-use Illuminate\Support\Facades\Schema;
-
-return new class extends Migration
-{
-    public function up(): void
-    {
-        Schema::create('order_products', function (Blueprint $table) {
-            $table->id();
-
-            // UUID foreign keys for orders and products
-            $table->uuid('order_id');
-            $table->uuid('product_id');
-
-            // Pivot data columns
-            $table->integer('quantity')->default(1);
-            $table->decimal('price_per_unit', 10, 2)->nullable();
-            $table->decimal('total_price', 10, 2)->nullable();
-
-            $table->timestamps();
-
-            // Foreign key constraints
-            $table->foreign('order_id')->references('id')->on('orders')->onDelete('cascade');
-            $table->foreign('product_id')->references('id')->on('products')->onDelete('cascade');
-
-            // Unique constraint
-            $table->unique(['order_id', 'product_id']);
-
-            // Indexes
-            $table->index('order_id');
-            $table->index('product_id');
-        });
-    }
-
-    public function down(): void
-    {
-        Schema::dropIfExists('order_products');
-    }
-};
Index: database/migrations/2025_08_14_120623_create_order_batches_table.php
===================================================================
--- database/migrations/2025_08_14_120623_create_order_batches_table.php	(revision 5f313241c1feb027aa5371c417930b38562c8625)
+++ database/migrations/2025_08_14_120623_create_order_batches_table.php	(revision 35b5d403322cce0cabaa8c872113cb24a80e377a)
@@ -5,9 +5,5 @@
 use Illuminate\Support\Facades\Schema;
 
-return new class extends Migration
-{
-    /**
-     * Run the migrations.
-     */
+return new class extends Migration {
     public function up(): void
     {
@@ -17,4 +13,6 @@
             $table->uuid('batch_id');
             $table->integer('quantity');
+            $table->decimal('price_per_unit', 10, 2);
+            $table->decimal('total_price', 10, 2);
             $table->timestamps();
 
@@ -24,7 +22,4 @@
     }
 
-    /**
-     * Reverse the migrations.
-     */
     public function down(): void
     {
Index: database/seeders/DatabaseSeeder.php
===================================================================
--- database/seeders/DatabaseSeeder.php	(revision 5f313241c1feb027aa5371c417930b38562c8625)
+++ database/seeders/DatabaseSeeder.php	(revision 35b5d403322cce0cabaa8c872113cb24a80e377a)
@@ -3,4 +3,5 @@
 namespace Database\Seeders;
 
+use App\Models\Order;
 use Illuminate\Database\Seeder;
 
@@ -16,4 +17,7 @@
             ClientSeeder::class,
             TransportSeeder::class,
+            OrderSeeder::class,
+            //invoiceseeder
+            //packinglistseeder
         ]);
     }
Index: tabase/seeders/OrderBatchSeeder.php
===================================================================
--- database/seeders/OrderBatchSeeder.php	(revision 5f313241c1feb027aa5371c417930b38562c8625)
+++ 	(revision )
@@ -1,51 +1,0 @@
-<?php
-
-use Illuminate\Database\Seeder;
-use Illuminate\Support\Str;
-use Illuminate\Support\Facades\DB;
-use App\Models\Order;
-use App\Models\Product;
-use App\Models\Batch;
-
-class OrderBatchSeeder extends Seeder
-{
-    public function run(): void
-    {
-        $orders = Order::all();
-        $products = Product::all();
-
-        if ($orders->isEmpty() || $products->isEmpty()) {
-            $this->command->warn('No orders or products found.');
-            return;
-        }
-
-        foreach ($orders as $order) {
-            // pick 1-3 random products for this order
-            $picked = $products->random(rand(1, min(3, $products->count())));
-            foreach ($picked as $product) {
-                // choose batches for this product
-                $batches = Batch::where('product_id', $product->id)->inRandomOrder()->get();
-                if ($batches->isEmpty()) continue;
-                // allocate a total quantity for this product in order
-                $remainingQty = rand(100, 10000); // number of units to ship for this product
-                foreach ($batches as $batch) {
-                    if ($remainingQty <= 0) break;
-                    // take between 1 and min(remainingQty, 5000)
-                    $take = rand(1, min($remainingQty, 5000));
-                    // insert into order_batches (we include UUID for id)
-                    DB::table('order_batches')->insert([
-                        'id' => (string)Str::uuid(),
-                        'order_id' => $order->id,
-                        'batch_id' => $batch->id,
-                        'quantity' => $take,
-                        'created_at' => now(),
-                        'updated_at' => now(),
-                    ]);
-                    $remainingQty -= $take;
-                }
-            }
-        }
-
-        $this->command->info('Order batches seeded.');
-    }
-}
Index: tabase/seeders/OrderProductSeeder.php
===================================================================
--- database/seeders/OrderProductSeeder.php	(revision 5f313241c1feb027aa5371c417930b38562c8625)
+++ 	(revision )
@@ -1,43 +1,0 @@
-<?php
-
-namespace Database\Seeders;
-
-use App\Models\Order;
-use App\Models\Product;
-use Illuminate\Database\Seeder;
-
-class OrderProductSeeder extends Seeder
-{
-    public function run(): void
-    {
-        // Get all orders and products
-        $orders = Order::all();
-        $products = Product::all();
-
-        if ($orders->isEmpty() || $products->isEmpty()) {
-            $this->command->warn('No orders or products found. Create some first.');
-            return;
-        }
-
-        foreach ($orders as $order) {
-            // Attach 1-5 random products to each order
-            $randomProducts = $products->random(rand(1, min(5, $products->count())));
-
-            foreach ($randomProducts as $product) {
-                $quantity = rand(1, 10);
-                $pricePerUnit = $product->price ?? rand(10, 100);
-
-                // Attach with pivot data
-                $order->products()->attach($product->id, [
-                    'quantity' => $quantity,
-                    'price_per_unit' => $pricePerUnit,
-                    'total_price' => $quantity * $pricePerUnit,
-                    'created_at' => now(),
-                    'updated_at' => now(),
-                ]);
-            }
-        }
-
-        $this->command->info('Order-Product relationships created successfully!');
-    }
-}
Index: database/seeders/OrderSeeder.php
===================================================================
--- database/seeders/OrderSeeder.php	(revision 35b5d403322cce0cabaa8c872113cb24a80e377a)
+++ database/seeders/OrderSeeder.php	(revision 35b5d403322cce0cabaa8c872113cb24a80e377a)
@@ -0,0 +1,69 @@
+<?php
+
+namespace Database\Seeders;
+
+use App\Models\Order;
+use App\Models\Client;
+use App\Models\Transport;
+use App\Models\Batch;
+use Illuminate\Database\Seeder;
+use Illuminate\Support\Str;
+use Illuminate\Support\Facades\DB;
+
+class OrderSeeder extends Seeder
+{
+    /**
+     * Run the database seeds.
+     */
+    public function run(): void
+    {
+        $buyers = Client::all();
+        $receivers = Client::all();
+        $transports = Transport::all();
+        $batches = Batch::with('product')->get();
+
+        if ($buyers->isEmpty() || $receivers->isEmpty() || $transports->isEmpty() || $batches->isEmpty()) {
+            $this->command->warn('No clients, transports, or batches found. Please seed these first.');
+            return;
+        }
+
+        $statuses = ['pending', 'confirmed', 'processing', 'shipped', 'delivered', 'cancelled'];
+
+        for ($i = 0; $i < 20; $i++) {
+            $orderDate = now()->subDays(rand(1, 60));
+            $estimatedDeliveryDate = $orderDate->copy()->addDays(rand(7, 30));
+
+            $order = Order::create([
+                'id' => Str::uuid(),
+                'date' => $orderDate,
+                'status' => $statuses[array_rand($statuses)],
+                'estimated_delivery_date' => $estimatedDeliveryDate,
+                'buyer_id' => $buyers->random()->id,
+                'receiver_id' => $receivers->random()->id,
+                'transport_id' => $transports->random()->id,
+            ]);
+
+            // Attach 1-3 random batches to this order
+            $selectedBatches = $batches->random(rand(1, min(3, $batches->count())));
+
+            foreach ($selectedBatches as $batch) {
+                $quantity = rand(100, 1000);
+                $pricePerUnit = $batch->product->price ?? rand(10, 100);
+                $totalPrice = $quantity * $pricePerUnit;
+
+                DB::table('order_batches')->insert([
+                    'id' => (string)Str::uuid(),
+                    'order_id' => $order->id,
+                    'batch_id' => $batch->id,
+                    'quantity' => $quantity,
+                    'price_per_unit' => $pricePerUnit,
+                    'total_price' => $totalPrice,
+                    'created_at' => now(),
+                    'updated_at' => now(),
+                ]);
+            }
+        }
+
+        $this->command->info('Orders with batches seeded successfully!');
+    }
+}
