394 lines
14 KiB
C#
394 lines
14 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace BankSampahApp.Controllers.ReduksiSampah
|
|
{
|
|
internal static class ReduksiSampahDataStore
|
|
{
|
|
private static readonly IReadOnlyList<ReduksiSampahItem> Items = new List<ReduksiSampahItem>
|
|
{
|
|
new()
|
|
{
|
|
Id = 1,
|
|
PeriodeBulan = "Jan 2025",
|
|
NamaLokasi = "Jakarta Pusat",
|
|
JenisLokasi = "Maggot",
|
|
BeratReduksi = 8,
|
|
BeratSampah = 15,
|
|
Kecamatan = "Tanah Abang",
|
|
Kelurahan = "Cideng",
|
|
Rt = "002",
|
|
Rw = "001",
|
|
DetailAlamat = "Jl. Kebersihan No. 12",
|
|
Status = "Aktif",
|
|
B1 = 12.5m,
|
|
B2 = 13.2m,
|
|
B3 = 11.8m,
|
|
B4 = 14.4m,
|
|
B5 = 15.1m,
|
|
B6 = 12.9m,
|
|
B7 = 13.5m,
|
|
B8 = 12.3m,
|
|
B9 = 14.1m,
|
|
B10 = 13.7m,
|
|
B11 = 12.8m,
|
|
B12 = 13.0m,
|
|
Alamat = AddressBlock("Tanah Abang", "Cideng", "002", "001", "Jl. Kebersihan No. 12")
|
|
},
|
|
new()
|
|
{
|
|
Id = 2,
|
|
PeriodeBulan = "Feb 2025",
|
|
NamaLokasi = "Jakarta Barat",
|
|
JenisLokasi = "Maggot",
|
|
BeratReduksi = 10,
|
|
BeratSampah = 20,
|
|
Kecamatan = "Palmerah",
|
|
Kelurahan = "Kemanggisan",
|
|
Rt = "003",
|
|
Rw = "004",
|
|
DetailAlamat = "Jl. Kemanggisan Raya No. 9",
|
|
Status = "Aktif",
|
|
B1 = 10.2m,
|
|
B2 = 11.4m,
|
|
B3 = 10.8m,
|
|
B4 = 12.6m,
|
|
B5 = 13.3m,
|
|
B6 = 11.9m,
|
|
B7 = 12.8m,
|
|
B8 = 11.1m,
|
|
B9 = 12.4m,
|
|
B10 = 11.9m,
|
|
B11 = 11.4m,
|
|
B12 = 12.0m,
|
|
Alamat = AddressBlock("Palmerah", "Kemanggisan", "003", "004", "Jl. Kemanggisan Raya No. 9")
|
|
},
|
|
new()
|
|
{
|
|
Id = 3,
|
|
PeriodeBulan = "Mar 2025",
|
|
NamaLokasi = "Jakarta Selatan",
|
|
JenisLokasi = "Maggot",
|
|
BeratReduksi = 7,
|
|
BeratSampah = 14,
|
|
Kecamatan = "Tebet",
|
|
Kelurahan = "Manggarai",
|
|
Rt = "001",
|
|
Rw = "002",
|
|
DetailAlamat = "Jl. Manggarai Utara No. 7",
|
|
Status = "Tidak Aktif",
|
|
B1 = 9.5m,
|
|
B2 = 9.9m,
|
|
B3 = 10.1m,
|
|
B4 = 10.5m,
|
|
B5 = 10.2m,
|
|
B6 = 9.7m,
|
|
B7 = 9.9m,
|
|
B8 = 10.0m,
|
|
B9 = 9.8m,
|
|
B10 = 10.1m,
|
|
B11 = 9.6m,
|
|
B12 = 9.9m,
|
|
Alamat = AddressBlock("Tebet", "Manggarai", "001", "002", "Jl. Manggarai Utara No. 7")
|
|
},
|
|
new()
|
|
{
|
|
Id = 4,
|
|
PeriodeBulan = "Apr 2025",
|
|
NamaLokasi = "Jakarta Timur",
|
|
JenisLokasi = "Maggot",
|
|
BeratReduksi = 6,
|
|
BeratSampah = 12,
|
|
Kecamatan = "Cakung",
|
|
Kelurahan = "Jatinegara",
|
|
Rt = "004",
|
|
Rw = "006",
|
|
DetailAlamat = "Jl. Industri Hijau No. 5",
|
|
Status = "Aktif",
|
|
B1 = 14.6m,
|
|
B2 = 13.9m,
|
|
B3 = 14.1m,
|
|
B4 = 14.8m,
|
|
B5 = 15.3m,
|
|
B6 = 14.5m,
|
|
B7 = 15.0m,
|
|
B8 = 14.2m,
|
|
B9 = 15.1m,
|
|
B10 = 14.7m,
|
|
B11 = 14.3m,
|
|
B12 = 14.9m,
|
|
Alamat = AddressBlock("Cakung", "Jatinegara", "004", "006", "Jl. Industri Hijau No. 5")
|
|
},
|
|
new()
|
|
{
|
|
Id = 5,
|
|
PeriodeBulan = "Mei 2025",
|
|
NamaLokasi = "Jakarta Utara",
|
|
JenisLokasi = "Maggot",
|
|
BeratReduksi = 9,
|
|
BeratSampah = 16,
|
|
Kecamatan = "Koja",
|
|
Kelurahan = "Lagoa",
|
|
Rt = "005",
|
|
Rw = "003",
|
|
DetailAlamat = "Jl. Lagoa Mas No. 3",
|
|
Status = "Aktif",
|
|
B1 = 11.7m,
|
|
B2 = 11.3m,
|
|
B3 = 11.1m,
|
|
B4 = 11.8m,
|
|
B5 = 12.4m,
|
|
B6 = 11.5m,
|
|
B7 = 11.9m,
|
|
B8 = 11.2m,
|
|
B9 = 12.0m,
|
|
B10 = 11.6m,
|
|
B11 = 11.3m,
|
|
B12 = 11.9m,
|
|
Alamat = AddressBlock("Koja", "Lagoa", "005", "003", "Jl. Lagoa Mas No. 3")
|
|
},
|
|
new()
|
|
{
|
|
Id = 6,
|
|
PeriodeBulan = "Jun 2025",
|
|
NamaLokasi = "Depok",
|
|
JenisLokasi = "Komposting",
|
|
BeratReduksi = 11,
|
|
BeratSampah = 18,
|
|
Kecamatan = "Beji",
|
|
Kelurahan = "Beji Timur",
|
|
Rt = "006",
|
|
Rw = "002",
|
|
DetailAlamat = "Jl. Melati Hijau No. 10",
|
|
Alamat = AddressBlock("Beji", "Beji Timur", "006", "002", "Jl. Melati Hijau No. 10")
|
|
},
|
|
new()
|
|
{
|
|
Id = 7,
|
|
PeriodeBulan = "Jul 2025",
|
|
NamaLokasi = "Bekasi",
|
|
JenisLokasi = "Komposting",
|
|
BeratReduksi = 13,
|
|
BeratSampah = 21,
|
|
Kecamatan = "Bekasi Timur",
|
|
Kelurahan = "Margahayu",
|
|
Rt = "009",
|
|
Rw = "005",
|
|
DetailAlamat = "Jl. Margahayu Harmonis No. 8",
|
|
Alamat = AddressBlock("Bekasi Timur", "Margahayu", "009", "005", "Jl. Margahayu Harmonis No. 8")
|
|
},
|
|
new()
|
|
{
|
|
Id = 8,
|
|
PeriodeBulan = "Agu 2025",
|
|
NamaLokasi = "Bogor",
|
|
JenisLokasi = "Komposting",
|
|
BeratReduksi = 9,
|
|
BeratSampah = 15,
|
|
Kecamatan = "Bogor Utara",
|
|
Kelurahan = "Kedunghalang",
|
|
Rt = "001",
|
|
Rw = "004",
|
|
DetailAlamat = "Jl. Kedunghalang Sejahtera No. 2",
|
|
Alamat = AddressBlock("Bogor Utara", "Kedunghalang", "001", "004", "Jl. Kedunghalang Sejahtera No. 2")
|
|
},
|
|
new()
|
|
{
|
|
Id = 9,
|
|
PeriodeBulan = "Sep 2025",
|
|
NamaLokasi = "Tangerang",
|
|
JenisLokasi = "Komposting",
|
|
BeratReduksi = 8,
|
|
BeratSampah = 13,
|
|
Kecamatan = "Karawaci",
|
|
Kelurahan = "Nusa Jaya",
|
|
Rt = "008",
|
|
Rw = "003",
|
|
DetailAlamat = "Jl. Nusa Jaya Indah No. 11",
|
|
Alamat = AddressBlock("Karawaci", "Nusa Jaya", "008", "003", "Jl. Nusa Jaya Indah No. 11")
|
|
},
|
|
new()
|
|
{
|
|
Id = 10,
|
|
PeriodeBulan = "Okt 2025",
|
|
NamaLokasi = "Cilegon",
|
|
JenisLokasi = "Komposting",
|
|
BeratReduksi = 12,
|
|
BeratSampah = 19,
|
|
Kecamatan = "Ciwandan",
|
|
Kelurahan = "Kebonsari",
|
|
Rt = "010",
|
|
Rw = "002",
|
|
DetailAlamat = "Jl. Kebonsari Permai No. 4",
|
|
Alamat = AddressBlock("Ciwandan", "Kebonsari", "010", "002", "Jl. Kebonsari Permai No. 4")
|
|
}
|
|
};
|
|
|
|
private const string ActionButtons = @"<div class=""flex gap-2"">
|
|
<a href=""#"" class=""btn btn-circle btn-warning text-white btn-sm btn-edit""><i class=""ph ph-note-pencil""></i></a>
|
|
<a href=""#"" class=""btn btn-circle btn-error text-white btn-sm btn-delete""><i class=""ph ph-trash""></i></a>
|
|
<a href=""#"" class=""btn btn-circle btn-success text-white btn-sm btn-preview""><i class=""ph ph-eye""></i></a>
|
|
<a href=""#"" class=""btn btn-circle bg-blue-500 text-white btn-sm btn-history""><i class=""ph ph-clock-counter-clockwise""></i></a>
|
|
<a href=""#"" class=""btn btn-circle btn-warning text-white btn-sm btn-validation""><i class=""ph ph-check""></i></a>
|
|
</div>";
|
|
|
|
private const string ProofButton = @"<a href=""#"" class=""btn bg-gray-500 text-white rounded-lg""><i class=""ph ph-file-text""></i></a>";
|
|
|
|
public static IEnumerable<ReduksiSampahItem> GetItems(string jenisLokasi) =>
|
|
Items.Where(item => string.Equals(item.JenisLokasi, jenisLokasi, StringComparison.OrdinalIgnoreCase));
|
|
|
|
public static bool MatchesBulan(ReduksiSampahItem item, string? bulan)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(bulan))
|
|
{
|
|
return true;
|
|
}
|
|
|
|
return item.PeriodeBulan.Contains(bulan.Trim(), StringComparison.OrdinalIgnoreCase);
|
|
}
|
|
|
|
public static bool MatchesPeriode(ReduksiSampahItem item, string? bulan, string? tahun)
|
|
{
|
|
if (!MatchesBulan(item, bulan))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (string.IsNullOrWhiteSpace(tahun))
|
|
{
|
|
return true;
|
|
}
|
|
|
|
return item.PeriodeBulan.EndsWith(tahun.Trim(), StringComparison.OrdinalIgnoreCase);
|
|
}
|
|
|
|
public static object ToResponse(ReduksiSampahItem item) => new
|
|
{
|
|
id = item.Id,
|
|
periode_bulan = item.PeriodeBulan,
|
|
nama_lokasi = item.NamaLokasi,
|
|
alamat = item.Alamat,
|
|
jenis_lokasi = item.JenisLokasi,
|
|
berat_reduksi = item.BeratReduksi,
|
|
berat_sampah = item.BeratSampah,
|
|
gambar = ProofButton,
|
|
aksi = ActionButtons
|
|
};
|
|
|
|
public static object ToDetailedResponse(ReduksiSampahItem item) => new
|
|
{
|
|
id = item.Id,
|
|
periode = item.PeriodeBulan,
|
|
kecamatan = item.Kecamatan,
|
|
kelurahan = item.Kelurahan,
|
|
rt = item.Rt,
|
|
rw = item.Rw,
|
|
detail_alamat = item.DetailAlamat,
|
|
status = item.Status,
|
|
b1 = item.B1,
|
|
b2 = item.B2,
|
|
b3 = item.B3,
|
|
b4 = item.B4,
|
|
b5 = item.B5,
|
|
b6 = item.B6,
|
|
b7 = item.B7,
|
|
b8 = item.B8,
|
|
b9 = item.B9,
|
|
b10 = item.B10,
|
|
b11 = item.B11,
|
|
b12 = item.B12
|
|
};
|
|
|
|
public static bool UpdateReduksiValues(
|
|
string jenisLokasi,
|
|
int id,
|
|
string? status,
|
|
decimal? b1,
|
|
decimal? b2,
|
|
decimal? b3,
|
|
decimal? b4,
|
|
decimal? b5,
|
|
decimal? b6,
|
|
decimal? b7,
|
|
decimal? b8,
|
|
decimal? b9,
|
|
decimal? b10,
|
|
decimal? b11,
|
|
decimal? b12)
|
|
{
|
|
var item = Items.FirstOrDefault(x =>
|
|
x.Id == id &&
|
|
string.Equals(x.JenisLokasi, jenisLokasi, StringComparison.OrdinalIgnoreCase));
|
|
|
|
if (item == null)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (!string.IsNullOrWhiteSpace(status))
|
|
{
|
|
item.Status = status;
|
|
}
|
|
|
|
if (b1.HasValue) item.B1 = b1.Value;
|
|
if (b2.HasValue) item.B2 = b2.Value;
|
|
if (b3.HasValue) item.B3 = b3.Value;
|
|
if (b4.HasValue) item.B4 = b4.Value;
|
|
if (b5.HasValue) item.B5 = b5.Value;
|
|
if (b6.HasValue) item.B6 = b6.Value;
|
|
if (b7.HasValue) item.B7 = b7.Value;
|
|
if (b8.HasValue) item.B8 = b8.Value;
|
|
if (b9.HasValue) item.B9 = b9.Value;
|
|
if (b10.HasValue) item.B10 = b10.Value;
|
|
if (b11.HasValue) item.B11 = b11.Value;
|
|
if (b12.HasValue) item.B12 = b12.Value;
|
|
|
|
return true;
|
|
}
|
|
|
|
private static string AddressBlock(string kecamatan, string kelurahan, string rt, string rw, string detailAlamat)
|
|
{
|
|
return $@"
|
|
<div class=""flex flex-col gap-1"">
|
|
<span class=""text-sm font-semibold text-gray-900"">{kecamatan}</span>
|
|
<div class=""flex items-center gap-1 text-xs text-gray-500"">
|
|
<span>{kelurahan}</span>
|
|
<span>RT {rt}</span>
|
|
<span>RW {rw}</span>
|
|
</div>
|
|
<span class=""text-xs text-gray-500"">{detailAlamat}</span>
|
|
</div>";
|
|
}
|
|
|
|
public class ReduksiSampahItem
|
|
{
|
|
public int Id { get; set; }
|
|
public string PeriodeBulan { get; set; } = string.Empty;
|
|
public string NamaLokasi { get; set; } = string.Empty;
|
|
public string Alamat { get; set; } = string.Empty;
|
|
public string DetailAlamat { get; set; } = string.Empty;
|
|
public string Kecamatan { get; set; } = string.Empty;
|
|
public string Kelurahan { get; set; } = string.Empty;
|
|
public string Rt { get; set; } = string.Empty;
|
|
public string Rw { get; set; } = string.Empty;
|
|
public string JenisLokasi { get; set; } = string.Empty;
|
|
public string Status { get; set; } = "Aktif";
|
|
public double BeratReduksi { get; set; }
|
|
public double BeratSampah { get; set; }
|
|
public decimal B1 { get; set; }
|
|
public decimal B2 { get; set; }
|
|
public decimal B3 { get; set; }
|
|
public decimal B4 { get; set; }
|
|
public decimal B5 { get; set; }
|
|
public decimal B6 { get; set; }
|
|
public decimal B7 { get; set; }
|
|
public decimal B8 { get; set; }
|
|
public decimal B9 { get; set; }
|
|
public decimal B10 { get; set; }
|
|
public decimal B11 { get; set; }
|
|
public decimal B12 { get; set; }
|
|
}
|
|
}
|
|
}
|