Compare commits
	
		
			No commits in common. "aa64332418d7ada253d2549994adf82b083eda67" and "1834441d78a5a733d0c4714f813105380f6101eb" have entirely different histories.
		
	
	
		
			aa64332418
			...
			1834441d78
		
	
		
| @ -2,7 +2,6 @@ | ||||
| 
 | ||||
| namespace Database\Factories; | ||||
| 
 | ||||
| use App\Models\Produk; | ||||
| use Illuminate\Database\Eloquent\Factories\Factory; | ||||
| 
 | ||||
| /** | ||||
| @ -18,7 +17,7 @@ class ItemFactory extends Factory | ||||
|     public function definition(): array | ||||
|     { | ||||
|         return [ | ||||
|             'id_produk' => Produk::inRandomOrder()->first()->id, | ||||
|             'id_produk' => \App\Models\Produk::factory(), | ||||
|             'id_nampan' => null, | ||||
|         ]; | ||||
|     } | ||||
|  | ||||
| @ -49,59 +49,31 @@ class DatabaseSeeder extends Seeder | ||||
|             ]); | ||||
|         } | ||||
| 
 | ||||
|         // Produk::factory(10)->create()->each(function ($produk) {
 | ||||
|         //     // setiap produk punya 1-3 foto
 | ||||
|         //     $jumlah_foto = rand(1, 3);
 | ||||
|         //     $fotoData = [];
 | ||||
|         //     for ($i = 0; $i < $jumlah_foto; $i++) {
 | ||||
|         //         $fotoData[] = [
 | ||||
|         //             // 'url' => 'https://random-image-pepebigotes.vercel.app/api/random-image'
 | ||||
|         //             'url' => 'https://static.promediateknologi.id/crop/0x0:0x0/0x0/webp/photo/p2/255/2024/12/10/Screenshot_2024-12-10-11-50-18-88_1c337646f29875672b5a61192b9010f9-1-1282380831.jpg'
 | ||||
|         //         ];
 | ||||
|         //     }
 | ||||
|         //     $produk->foto()->createMany($fotoData);
 | ||||
|         Produk::factory(10)->create()->each(function ($produk) { | ||||
|             // setiap produk punya 1-3 foto
 | ||||
|             $jumlah_foto = rand(1, 3); | ||||
|             $fotoData = []; | ||||
|             for ($i = 0; $i < $jumlah_foto; $i++) { | ||||
|                 $fotoData[] = [ | ||||
|                     // 'url' => 'https://random-image-pepebigotes.vercel.app/api/random-image'
 | ||||
|                     'url' => 'https://static.promediateknologi.id/crop/0x0:0x0/0x0/webp/photo/p2/255/2024/12/10/Screenshot_2024-12-10-11-50-18-88_1c337646f29875672b5a61192b9010f9-1-1282380831.jpg' | ||||
|                 ]; | ||||
|             } | ||||
|             $produk->foto()->createMany($fotoData); | ||||
| 
 | ||||
|         //     $jumlah_item = rand(1, 20);
 | ||||
|         //     Item::factory($jumlah_item)->create([
 | ||||
|         //         'id_produk' => $produk->id,
 | ||||
|         //     ]);
 | ||||
|         // });
 | ||||
|             $jumlah_item = rand(1, 20); | ||||
|             Item::factory($jumlah_item)->create([ | ||||
|                 'id_produk' => $produk->id, | ||||
|             ]); | ||||
|         }); | ||||
| 
 | ||||
|         $produk1 = Produk::factory()->create([ | ||||
|             'nama'=>'Gelang serut daun shimmer mp (mas putih)', | ||||
|             'id_kategori'=>Kategori::find(2), | ||||
|             'berat'=>1.4, | ||||
|             'kadar'=>8, | ||||
|             'harga_per_gram'=>900000, | ||||
|             'harga_jual'=>1260000, | ||||
|         ]); | ||||
|         $produk1->foto()->create([ | ||||
|             'id_produk'=>$produk1->id, | ||||
|             'url'=>'https://i.imgur.com/eGYHzvw.jpeg' | ||||
|         ]); | ||||
|          | ||||
|         $produk2 = Produk::factory()->create([ | ||||
|             'nama'=>'Gelang rantai 5 buah clover merah', | ||||
|             'id_kategori'=>Kategori::find(2), | ||||
|             'berat'=>3.6, | ||||
|             'kadar'=>8, | ||||
|             'harga_per_gram'=>850000, | ||||
|             'harga_jual'=>3060000, | ||||
|         ]); | ||||
|         $produk2->foto()->create([ | ||||
|             'id_produk'=>$produk2->id, | ||||
|             'url'=>'https://i.imgur.com/UjQzYoE.jpeg' | ||||
|         ]); | ||||
| 
 | ||||
|         Item::factory(500)->create(); | ||||
| 
 | ||||
|         // 75% peluang item masuk nampan, sisanya di brankas
 | ||||
|         // 30% peluang item masuk nampan, sisanya di brankas
 | ||||
|         $nampans = Nampan::all()->pluck('id')->toArray(); | ||||
|         $jumlahNampan = count($nampans); | ||||
|         $counter = 0; | ||||
| 
 | ||||
|         foreach (Item::all() as $item) { | ||||
|             if (rand(1, 100) <= 75) { | ||||
|             if (rand(1, 100) <= 30) { | ||||
|                 $item->update([ | ||||
|                     'id_nampan' => $nampans[$counter % $jumlahNampan], | ||||
|                 ]); | ||||
| @ -109,7 +81,7 @@ class DatabaseSeeder extends Seeder | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         Transaksi::factory(250)->create()->each(function ($transaksi) { | ||||
|         Transaksi::factory(40)->create()->each(function ($transaksi) { | ||||
|             $jumlah_item = rand(1, 2); | ||||
|             $items = Item::with('produk')->inRandomOrder()->limit($jumlah_item)->get(); | ||||
|             if ($items->isEmpty()) return; | ||||
| @ -118,7 +90,7 @@ class DatabaseSeeder extends Seeder | ||||
|                 $transaksi->itemTransaksi()->create([ | ||||
|                     'id_produk' => $item->produk->id, | ||||
|                     'harga_deal' => $item->produk->harga_jual, | ||||
|                     'posisi_asal' => $item->id_nampan ? $item->nampan->nama : 'Brankas', | ||||
|                     'posisi_asal' => $item->id_nampan ? 'Nampan ' . $item->nampan->nama : 'Brankas', | ||||
|                 ]); | ||||
|                 $item->delete(); | ||||
|                 $total_harga += $item->produk->harga_jual; | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user