promonisme

auth
Zelda Ababil 2024-01-21 00:51:59 +07:00
parent aad0387131
commit 7ce9077184
6 changed files with 48 additions and 10 deletions

View File

@ -114,10 +114,15 @@ class Transaksi extends Controller
foreach ($request->orderMenus as $key => $value) {
// calculate produk promo untuk mengurangi stok
// $produk = Produk::find($value['id']);
// dd($produk->stok_produk);
// $produk->stok_produk = $produk->stok_produk - $value['qty'];
// $produk->save();
$produk = Produk::find($value['id']);
foreach ($produk->kelompokKategori as $key => $value2) {
if ($value2->kode_kelompok_kategori == 'PROMO') {
$produk->stok_promo = $produk->stok_promo - $value['qty'];
$produk->save();
}
}
$oderDatas = [
'pesanan_id' => $pesananModels->id,
'produk_id' => $value['id'],

View File

@ -41,4 +41,9 @@ class Produk extends Model
{
return $this->belongsTo(KategoriProduk::class, 'kategori_produk_id');
}
public function kelompokKategori()
{
return $this->belongsToMany(KelompokKategori::class, KelompokKategoriPivot::class, 'produk_id', 'kelompok_kategori_id');
}
}

View File

@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('produks', function (Blueprint $table) {
$table->integer('stok_promo')->nullable()->after('stok_produk');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('produks', function (Blueprint $table) {
$table->dropColumn('stok_promo');
});
}
};

View File

@ -26,7 +26,7 @@ class ProdukSeeder extends Seeder
"varian_produk" => $data['4'] ?? null,
"harga_produk" => $data['5'] ?? '',
"urutan" => $data['6'] == "" ? null : $data['6'],
"stok_produk" => $data['7'] == "" ? null : $data['7'],
"stok_promo" => $data['7'] == "" ? null : $data['7'],
]);
}
$firstline = false;

View File

@ -1,4 +1,4 @@
ketegori_produk_id,kode_produk,nama_produk,deskripsi_produk,varian_produk,harga_produk,urutan,stok_produk
ketegori_produk_id,kode_produk,nama_produk,deskripsi_produk,varian_produk,harga_produk,urutan,stok_promo
2,NP,Nasi Putih,,,5000,1,
2,NP T.KER SB.IJO,Paket Irit Nasi Putih Telur Keriting Sambal Ijo,,,10000,,
2,NP T.KER SB.MTH,Paket Irit Nasi Putih Telur Keriting Sambal Matah,,,10000,,

1 ketegori_produk_id kode_produk nama_produk deskripsi_produk varian_produk harga_produk urutan stok_produk stok_promo
2 2 NP Nasi Putih 5000 1
3 2 NP T.KER SB.IJO Paket Irit Nasi Putih Telur Keriting Sambal Ijo 10000
4 2 NP T.KER SB.MTH Paket Irit Nasi Putih Telur Keriting Sambal Matah 10000

View File

@ -282,11 +282,11 @@
</div>
<div class="col-md-12 mt-3">
@if (
$kelompokKategoriPivot->produk->stok_produk != '' ||
$kelompokKategoriPivot->produk->stok_produk != 0 ||
$kelompokKategoriPivot->produk->stok_produk != null)
$kelompokKategoriPivot->produk->stok_promo != '' ||
$kelompokKategoriPivot->produk->stok_promo != 0 ||
$kelompokKategoriPivot->produk->stok_promo != null)
<h6 style="color: red">Promo Tersisa:
{{ $kelompokKategoriPivot->produk->stok_produk ?? 0 }}
{{ $kelompokKategoriPivot->produk->stok_promo ?? 0 }}
</h6>
@endif
</div>