diff --git a/app/Http/Controllers/MarhunController.php b/app/Http/Controllers/MarhunController.php index d4c0ef8..a42c8e8 100644 --- a/app/Http/Controllers/MarhunController.php +++ b/app/Http/Controllers/MarhunController.php @@ -51,7 +51,7 @@ class MarhunController extends Controller } public function getAllJemas(){ - $jemas = Jemas::on('mysql7')->get(); + $jemas = Jemas::on('mysql7')->orderBy('ordernum', 'asc')->get(); return response()->json($jemas); } @@ -61,38 +61,48 @@ class MarhunController extends Controller $current = Carbon::now(); $current = new Carbon(); - $harga = HargaEmas::on('mysql7')->where('karat',$request->karat)->first(); + $request_data = json_decode($request->getContent(), false); + + $harga = HargaEmas::on('mysql7')->where('karat',$request_data->karat)->first(); $hargaemas = $harga['harga']; - if(isset($request->jenisAT)){ - if($request->jenisAT == 'hargalama'){ - $hargaemas = $request->harga; - // $nilai_marhun = $request->berat_emas * $request->harga; + if(isset($request_data->jenisAT)){ + if($request_data->jenisAT == 'hargalama'){ + $hargaemas = $request_data->harga; + // $nilai_marhun = $request_data->berat_emas * $request_data->harga; }else $hargaemas = $harga['harga']; - // $nilai_marhun = $request->berat_emas * $harga['harga']; + // $nilai_marhun = $request_data->berat_emas * $harga['harga']; }else $hargaemas = $harga['harga']; - $nilai_marhun = $request->berat_emas * $hargaemas; + $nilai_marhun = $request_data->berat_emas * $hargaemas; - - $cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first(); - $marhun = Marhun::on($cawangan['mysql'])->create([ + $marhunToCreate = [ 'kodcaw'=> $kodcaw, - 'norujukan'=> $request->norujukan, + 'norujukan'=> $request_data->norujukan, 't_gadai' => $current->toDateString(), 'bil' => 1, - 'marhun' => $request->marhun, - 'nota' => $request->nota, - 'karat' => $request->karat, - 'berat' => $request->berat_emas, + 'marhun' => $request_data->marhun, + 'nota' => $request_data->nota, + 'tag_permata' => $request_data->tag_permata, + 'berat_batu_permata' => $request_data->berat_batu_permata, + 'karat' => $request_data->karat, + 'berat' => $request_data->berat_emas, 'harga' => $hargaemas, 'n_marhun' => $nilai_marhun - ]); + ]; + + // Set value berat_batu_permata to null if value passed is null + if($marhunToCreate['berat_batu_permata'] == '') { + $marhunToCreate['berat_batu_permata'] = null; + }; + + $cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first(); + $marhun = Marhun::on($cawangan['mysql'])->create($marhunToCreate); $audit = new Audit(); - $audit->users = $request->teller; + $audit->users = $request_data->teller; $audit->actions = 'Daftar Marhun'; - $audit->norujukan = $request->norujukan; + $audit->norujukan = $request_data->norujukan; $audit->new_data = $marhun; $audit->kodcaw = $kodcaw; $audit->created_at = $current; @@ -154,15 +164,23 @@ class MarhunController extends Controller $old_data = Marhun::on($cawangan['mysql'])->where([['recno','=',$request->recno],['norujukan','=',$norujukan]])->first(); - $jemas = Marhun::on($cawangan['mysql'])->where([['recno','=',$request->recno],['norujukan','=',$norujukan]])->update( - [ - 'karat' => $request->karat, - 'marhun' => $request->marhun, - 'nota' => $request->nota, - 'berat' => $request->berat, - 'harga' => $harga['harga'], - 'n_marhun' => $nilai_marhun - ]); + $marhunToUpdate = [ + 'karat' => $request->karat, + 'marhun' => $request->marhun, + 'nota' => $request->nota, + 'tag_permata' => $request->tag_permata, + 'berat_batu_permata' => $request->berat_batu_permata, + 'berat' => $request->berat, + 'harga' => $harga['harga'], + 'n_marhun' => $nilai_marhun + ]; + + // Set value berat_batu_permata to null if value passed is null + if($marhunToUpdate['berat_batu_permata'] == '') { + $marhunToUpdate['berat_batu_permata'] = null; + }; + + $jemas = Marhun::on($cawangan['mysql'])->where([['recno','=',$request->recno],['norujukan','=',$norujukan]])->update($marhunToUpdate); $new_data = Marhun::on($cawangan['mysql'])->where([['recno','=',$request->recno],['norujukan','=',$norujukan]])->first(); @@ -184,7 +202,7 @@ class MarhunController extends Controller $cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first(); $marhun = Marhun::on($cawangan['mysql']) - ->select('marhun.norujukan','gadai.nokp','customer.nama','marhun.marhun','marhun.nota','marhun.berat','marhun.karat','marhun.harga','marhun.n_marhun','marhun.t_gadai') + ->select('marhun.norujukan','gadai.nokp','customer.nama','marhun.marhun','marhun.nota','marhun.berat','marhun.karat','marhun.harga','marhun.n_marhun','marhun.t_gadai','marhun.tag_permata', 'marhun.berat_batu_permata') ->rightJoin('gadai', 'gadai.norujukan', '=', 'marhun.norujukan') ->rightJoin('online_arrahn.customer as customer', 'customer.kpbaru','=','gadai.nokp') ->where('marhun.t_gadai','=',$tarikh) diff --git a/app/Jemas.php b/app/Jemas.php index e6579e8..297918a 100644 --- a/app/Jemas.php +++ b/app/Jemas.php @@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Model; class Jemas extends Model { protected $table = 'jemas'; + public $timestamps = false; /** * The attributes that are mass assignable. diff --git a/app/Marhun.php b/app/Marhun.php index 301566c..dbbf591 100644 --- a/app/Marhun.php +++ b/app/Marhun.php @@ -15,7 +15,7 @@ class Marhun extends Model * @var array */ protected $fillable = [ - 'kodcaw','marhun','t_gadai','norujukan','bil','nota','karat','berat','harga','n_marhun' + 'kodcaw','marhun','t_gadai','norujukan','bil','nota','karat','berat','harga','n_marhun','tag_permata','berat_batu_permata', ]; /** diff --git a/database/migrations/2024_01_24_125247_add_batu_permata_to_marhun.php b/database/migrations/2024_01_24_125247_add_batu_permata_to_marhun.php new file mode 100644 index 0000000..f1fcd30 --- /dev/null +++ b/database/migrations/2024_01_24_125247_add_batu_permata_to_marhun.php @@ -0,0 +1,78 @@ +getPdo(); + return true; + } catch (\Exception $e) { + return false; + } + }); + return $db_connection; + } + public function up() + { + $db_connection = $this->getActiveDB(); + + foreach ($db_connection as $dbase) { + Schema::connection($dbase)->table('marhun', function (Blueprint $table) use ($dbase) { + + $isBatuPermataExist = Schema::connection($dbase)->hasColumn('marhun', 'batu_permata'); + $isBatuPermataExist = Schema::connection($dbase)->hasColumn('marhun', 'berat_batu_permata'); + + if (!$isBatuPermataExist) { + $table->string('batu_permata')->nullable(); + $table->decimal('berat_batu_permata', 7, 2)->nullable(); + } + }); + } + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + $db_connection = $this->getActiveDB(); + + foreach ($db_connection as $dbase) { + $columns = ['batu_permata', 'berat_batu_permata']; + + + $columns_exist = array_filter($columns, function ($column) use ($dbase) { + return Schema::connection($dbase)->hasColumn('marhun', $column); + }); + + Schema::connection($dbase)->table('marhun', function (Blueprint $table) use ($columns_exist) { + foreach ($columns_exist as $column) { + $table->dropColumn($column); + } + }); + } + } +} diff --git a/database/migrations/2024_03_11_085511_alter_batu_permata_column_in_marhun_table.php b/database/migrations/2024_03_11_085511_alter_batu_permata_column_in_marhun_table.php new file mode 100644 index 0000000..ac6ff42 --- /dev/null +++ b/database/migrations/2024_03_11_085511_alter_batu_permata_column_in_marhun_table.php @@ -0,0 +1,76 @@ +getPdo(); + return true; + } catch (\Exception $e) { + return false; + } + }); + return $db_connection; + } + + public function up() + { + $db_connection = $this->getActiveDB(); + + foreach ($db_connection as $dbase) { + $isColumnBatuPermataExist = Schema::connection($dbase)->hasColumn('marhun', 'batu_permata'); + if ($isColumnBatuPermataExist) { + Schema::connection($dbase)->table('marhun', function (Blueprint $table) use ($dbase) { + $table->dropColumn('batu_permata'); + }); + } + Schema::connection($dbase)->table('marhun', function (Blueprint $table) use ($dbase) { + $table->integer('tag_permata')->default(0); + }); + } + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + $db_connection = $this->getActiveDB(); + + foreach ($db_connection as $dbase) { + Schema::connection($dbase)->table('marhun', function (Blueprint $table) use ($dbase) { + $table->dropColumn('tag_permata'); + }); + $isColumnBatuPermataExist = Schema::connection($dbase)->hasColumn('marhun', 'batu_permata'); + if (!$isColumnBatuPermataExist) { + Schema::connection($dbase)->table('marhun', function (Blueprint $table) use ($dbase) { + $table->string('batu_permata')->nullable(); + }); + } + } + } +} diff --git a/database/seeds/SortJenisEmas.php b/database/seeds/SortJenisEmas.php new file mode 100644 index 0000000..9e8c6c9 --- /dev/null +++ b/database/seeds/SortJenisEmas.php @@ -0,0 +1,72 @@ +where('marhun', '=', 'G/T')->update([ + 'ordernum' => '1', + ]); + + Jemas::on('mysql7')->where('marhun', '=', 'CIN')->update([ + 'ordernum' => '2', + ]); + + Jemas::on('mysql7')->where('marhun', '=', 'R/K')->update([ + 'ordernum' => '3', + ]); + + Jemas::on('mysql7')->where('marhun', '=', 'SBG')->update([ + 'ordernum' => '4', + ]); + + Jemas::on('mysql7')->where('marhun', '=', 'L/L')->update([ + 'ordernum' => '5', + ]); + + Jemas::on('mysql7')->where('marhun', '=', 'LKT')->update([ + 'ordernum' => '6', + ]); + + Jemas::on('mysql7')->where('marhun', '=', 'R/T')->update([ + 'ordernum' => '7', + ]); + + Jemas::on('mysql7')->where('marhun', '=', 'K/B')->update([ + 'ordernum' => '8', + ]); + + Jemas::on('mysql7')->where('marhun', '=', 'DNR')->update([ + 'ordernum' => '9', + ]); + + Jemas::on('mysql7')->where('marhun', '=', 'SYE')->update([ + 'ordernum' => '10', + ]); + + Jemas::on('mysql7')->where('marhun', '=', 'WFR')->update([ + 'ordernum' => '11', + ]); + + Jemas::on('mysql7')->where('marhun', '=', 'G/B')->update([ + 'ordernum' => '12', + ]); + + Jemas::on('mysql7')->where('marhun', '=', 'SPE')->update([ + 'ordernum' => '13', + ]); + + Jemas::on('mysql7')->where('marhun', '=', 'R/L')->update([ + 'ordernum' => '14', + ]); + } +}