public static void Update(DataClassesDatabaseDataContext db, TBSupplier supplier, TBStokBahanBaku stokBahanBaku, decimal harga) { if (supplier != null) { TBHargaSupplier hargaSupplier = db.TBHargaSuppliers.FirstOrDefault(item => item.TBSupplier == supplier && item.TBStokBahanBaku == stokBahanBaku); if (hargaSupplier == null) { hargaSupplier = new TBHargaSupplier { TBSupplier = supplier, Tanggal = DateTime.Now, Harga = harga, TBStokBahanBaku = stokBahanBaku }; db.TBHargaSuppliers.InsertOnSubmit(hargaSupplier); } else { hargaSupplier.Tanggal = DateTime.Now; hargaSupplier.Harga = harga; } } }
protected void RepeaterSupplier_ItemCommand(object source, RepeaterCommandEventArgs e) { using (DataClassesDatabaseDataContext db = new DataClassesDatabaseDataContext()) { if (e.CommandName == "Ubah") { TBSupplier supplier = db.TBSuppliers.FirstOrDefault(item => item.IDSupplier == e.CommandArgument.ToInt()); HiddenFieldIDSupplier.Value = supplier.IDSupplier.ToString(); TextBoxNama.Text = supplier.Nama; TextBoxAlamat.Text = supplier.Alamat; TextBoxEmail.Text = supplier.Email; TextBoxTelepon1.Text = supplier.Telepon1; TextBoxTelepon2.Text = supplier.Telepon2; TextBoxTax.Text = (supplier.PersentaseTax * 100).ToString(); ButtonSimpanSupplier.Text = "Ubah"; } else if (e.CommandName == "Hapus") { Supplier_Class.DeleteSupplier(db, e.CommandArgument.ToInt()); db.SubmitChanges(); LoadDataSupplier(db); } } }
protected void DropDownListSupplier_SelectedIndexChanged(object sender, EventArgs e) { using (DataClassesDatabaseDataContext db = new DataClassesDatabaseDataContext()) { if (DropDownListSupplier.SelectedValue == "0") { HiddenFieldTax.Value = "0"; LabelTax.Text = "Tax (0%)"; } else { TBSupplier supplier = db.TBSuppliers.FirstOrDefault(item => item.IDSupplier == DropDownListSupplier.SelectedValue.ToInt()); HiddenFieldTax.Value = supplier.PersentaseTax.ToString(); LabelTax.Text = "Tax (" + (supplier.PersentaseTax * 100).ToFormatHarga() + "%)"; } if (TextBoxIDProyeksi.Text != string.Empty && string.IsNullOrEmpty(Request.QueryString["edit"])) { ViewState["ViewStateListDetail"] = new List <POProduksiDetail_Model>(); LoadProyeksi(db, TextBoxIDProyeksi.Text); } CariHargaSupplierVendor(); HitungGrandTotal(); } }
public static void DeleteSupplier(DataClassesDatabaseDataContext db, int idSupplier) { TBSupplier supplier = db.TBSuppliers.FirstOrDefault(item => item.IDSupplier == idSupplier); if (supplier.TBHargaSuppliers.Count == 0 && supplier.TBPOProduksiBahanBakus.Count == 0) { db.TBSuppliers.DeleteOnSubmit(supplier); } }
protected void ButtonSimpanSupplier_Click(object sender, EventArgs e) { if (Page.IsValid) { using (DataClassesDatabaseDataContext db = new DataClassesDatabaseDataContext()) { TBSupplier supplier = null; if (ButtonSimpanSupplier.Text == "Tambah") { supplier = new TBSupplier { Nama = TextBoxNama.Text, Alamat = TextBoxAlamat.Text, Email = TextBoxEmail.Text, Telepon1 = TextBoxTelepon1.Text, Telepon2 = TextBoxTelepon2.Text, PersentaseTax = TextBoxTax.Text.ToDecimal() / 100 }; db.TBSuppliers.InsertOnSubmit(supplier); } else if (ButtonSimpanSupplier.Text == "Ubah") { supplier = db.TBSuppliers.FirstOrDefault(item => item.IDSupplier == HiddenFieldIDSupplier.Value.ToInt()); supplier.Nama = TextBoxNama.Text; supplier.Alamat = TextBoxAlamat.Text; supplier.Email = TextBoxEmail.Text; supplier.Telepon1 = TextBoxTelepon1.Text; supplier.Telepon2 = TextBoxTelepon2.Text; supplier.PersentaseTax = TextBoxTax.Text.ToDecimal() / 100; } db.SubmitChanges(); HiddenFieldIDSupplier.Value = null; TextBoxNama.Text = string.Empty; TextBoxAlamat.Text = string.Empty; TextBoxEmail.Text = string.Empty; TextBoxTelepon1.Text = string.Empty; TextBoxTelepon2.Text = string.Empty; TextBoxTax.Text = "0.00"; ButtonSimpanSupplier.Text = "Tambah"; LoadDataSupplier(db); } } }
public static TBHargaSupplier CariHargaSupplier(DataClassesDatabaseDataContext db, TBSupplier supplier, TBStokBahanBaku stokBahanBaku) { return(db.TBHargaSuppliers.FirstOrDefault(item => item.TBSupplier == supplier && item.TBStokBahanBaku == stokBahanBaku)); }
private void LoadProyeksi(DataClassesDatabaseDataContext db, string IDProyeksi) { PenggunaLogin pengguna = (PenggunaLogin)Session["PenggunaLogin"]; TextBoxIDProyeksi.Text = IDProyeksi; TextBoxPegawai.Text = pengguna.NamaLengkap; TBSupplier supplier = null; if (DropDownListSupplier.SelectedValue == "0") { HiddenFieldTax.Value = "0"; LabelTax.Text = "Tax (0%)"; } else { supplier = db.TBSuppliers.FirstOrDefault(item => item.IDSupplier == DropDownListSupplier.SelectedValue.ToInt()); HiddenFieldTax.Value = supplier.PersentaseTax.ToString(); LabelTax.Text = "Tax (" + (supplier.PersentaseTax * 100).ToFormatHarga() + "%)"; } var proyeksiKomposisi = db.TBProyeksiKomposisis.Where(item => item.IDProyeksi == IDProyeksi && item.BahanBakuDasar == true && (DropDownListSupplier.SelectedValue != "0" ? db.TBHargaSuppliers.Where(item2 => item2.IDSupplier == DropDownListSupplier.SelectedValue.ToInt()).Any(item2 => item2.TBStokBahanBaku.IDBahanBaku == item.IDBahanBaku) : true)) .GroupBy(item => new { item.TBBahanBaku }) .Select(item => new { item.Key, Sisa = item.Sum(x => x.Sisa), }).OrderBy(data => data.Key.TBBahanBaku.Nama); TBStokBahanBaku[] daftarStokBahanBaku = db.TBStokBahanBakus.AsEnumerable().Where(item => item.IDTempat == pengguna.IDTempat && proyeksiKomposisi.Any(data => data.Key.TBBahanBaku.IDBahanBaku == item.IDBahanBaku)).OrderBy(item => item.TBBahanBaku.Nama).ToArray(); DropDownListStokBahanBaku.DataSource = daftarStokBahanBaku.Select(item => new { item.IDStokBahanBaku, item.TBBahanBaku.Nama }).ToArray(); DropDownListStokBahanBaku.DataTextField = "Nama"; DropDownListStokBahanBaku.DataValueField = "IDStokBahanBaku"; DropDownListStokBahanBaku.DataBind(); List <POProduksiDetail_Model> ViewStateListDetail = (List <POProduksiDetail_Model>)ViewState["ViewStateListDetail"]; foreach (var item in proyeksiKomposisi.Where(item => item.Sisa > 0)) { TBStokBahanBaku stokBahanBaku = daftarStokBahanBaku.FirstOrDefault(data => data.IDBahanBaku == item.Key.TBBahanBaku.IDBahanBaku); POProduksiDetail_Model detail = new POProduksiDetail_Model(); detail.IDBahanBaku = stokBahanBaku.TBBahanBaku.IDBahanBaku; detail.IDSatuan = stokBahanBaku.TBBahanBaku.IDSatuanKonversi; detail.IDStokBahanBaku = stokBahanBaku.IDStokBahanBaku; detail.Kode = stokBahanBaku.TBBahanBaku.KodeBahanBaku; detail.BahanBaku = stokBahanBaku.TBBahanBaku.Nama; detail.Satuan = stokBahanBaku.TBBahanBaku.TBSatuan1.Nama; detail.HargaPokokKomposisi = 0; detail.BiayaTambahan = 0; detail.TotalHPP = detail.BiayaTambahan + detail.HargaPokokKomposisi; detail.Harga = supplier == null ? 0 : supplier.TBHargaSuppliers.FirstOrDefault(data => data.IDStokBahanBaku == stokBahanBaku.IDStokBahanBaku) == null ? 0 : supplier.TBHargaSuppliers.FirstOrDefault(data => data.IDStokBahanBaku == stokBahanBaku.IDStokBahanBaku).Harga.Value; detail.PotonganHarga = 0; detail.TotalHarga = detail.Harga - detail.PotonganHarga; detail.Jumlah = item.Sisa / stokBahanBaku.TBBahanBaku.Konversi.Value; detail.Sisa = detail.Jumlah; ViewStateListDetail.Add(detail); } ViewState["ViewStateListDetail"] = ViewStateListDetail; LoadData(); decimal subtotal = LabelTotalSubtotal.Text.ToDecimal(); decimal tax = subtotal * HiddenFieldTax.Value.ToDecimal(); TextBoxTax.Text = tax.ToFormatHarga(); TextBoxGrandtotal.Text = (subtotal + tax).ToFormatHarga(); CariHargaSupplierVendor(); }