public PenjualanModel GetData(string id) { var header = _penjualanDal.GetData(id); if (header != null) { var detilBrg = _penjualan2Dal.ListData(id); if (detilBrg != null) { header.ListBrg = detilBrg; } var detilBayar = _penjualanBayarDal.ListData(id); if (detilBayar != null) { header.ListBayar = detilBayar; } } return(header); }
public LunasKasBonModel Save(LunasKasBonModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } var kasBon = _kasBonDal.GetData(model.KasBonID); if (kasBon == null) { throw new ArgumentException("PiutangID invalid"); } // validate pihak kedua var pihakKedua = _pihakKeduaDal.GetData(model.PihakKeduaID); if (pihakKedua == null) { throw new ArgumentException("PihakKeduaID invalid"); } else { model.PihakKeduaName = pihakKedua.PihakKeduaName; } if (kasBon.PihakKeduaID != model.PihakKeduaID) { throw new ArgumentException("PihakKeduaID tidak sama dengan data KasBon"); } if (model.ListLunas == null) { throw new ArgumentException("Detil Pelunasan masih kosong"); } // update nilai total lunas model.NilaiTotLunas = model.ListLunas.Sum(x => x.NilaiLunas); if (model.NilaiSisaPiutang < model.NilaiTotLunas) { throw new ArgumentException("Nilai Pelunasan KasBon terlalu banyak"); } foreach (var item in model.ListLunas) { var jenisLunas = _jenisLunasDal.GetData(item.JenisLunasID); if (jenisLunas == null) { throw new ArgumentException("JenisLunasID invalid : " + item.JenisLunasID); } if (item.NilaiLunas <= 0) { throw new ArgumentException("Pelunasan tidak boleh minus atau nol"); } // jika PelunasanID muncul, cek apakah NoPenjualan valid if (item.PenjualanID.Trim() != "") { var penjualan = _penjualanDal.GetData(item.PenjualanID); if (penjualan == null) { throw new ArgumentException("Penjualan ID invalid"); } // nomor referensi penjualan hanya boleh untuk jenis lunas biaya var jenisBiaya = _jenisBiayaDal.GetData(jenisLunas.JenisBiayaID); if (jenisBiaya == null) { throw new ArgumentException("Penjualan hanya diisi jika Biaya"); } } } using (var trans = TransHelper.NewScope()) { // generate id (jika baru) if (model.LunasKasBonID.Trim() == "") { model.LunasKasBonID = GenNewID(); } // update id di detil; var noUrut = 1; foreach (var item in model.ListLunas) { item.LunasKasBonID = model.LunasKasBonID; item.LunasKasBonDetilID = model.LunasKasBonID + '-' + noUrut.ToString().PadLeft(2, '0'); noUrut++; } // hapus data lama _lunasKasBonDal.Delete(model.LunasKasBonID); _lunasKasBonDetilDal.Delete(model.LunasKasBonID); // simpan data baru _lunasKasBonDal.Insert(model); foreach (var item in model.ListLunas) { _lunasKasBonDetilDal.Insert(item); } // commit changes trans.Complete(); } return(model); }
public void Generate(string brgID) { // listing brg // from adjustment plus var listStok = new List <StokItem>(); var listAdj = _stokAdj2Dal.ListDataBrg(brgID); if (listAdj != null) { Int32 i2 = 0; var e1 = new StartProsesStokEventArgs { ProsesName = "List Data Adjustment", DataCount = listAdj.Count() }; OnStartProses(e1); foreach (var item in listAdj) { i2++; var header = _stokAdjDal.GetData(item.StokAdjustmentID); if (header is null) { continue; } var e = new ProsesRegenStokEventArgs { Counter = i2, Tgl = header.TglTrs, TrsID = header.StokAdjustmentID }; OnProsesRegenStok(e); StokItem stok; if (item.QtyAdjust > 0) { stok = new StokItem { ReffID = item.StokAdjustmentID, Tgl = header.TglTrs, Jam = header.JamTrs, BrgID = item.BrgID, BrgName = item.BrgName, QtyIn = item.QtyAdjust, NilaiHpp = item.HppAdjust, QtyOut = 0, HargaJual = 0, BPStokID = "" } } ; else { stok = new StokItem { ReffID = item.StokAdjustmentID, Tgl = header.TglTrs, Jam = header.JamTrs, BrgID = item.BrgID, BrgName = item.BrgName, QtyIn = 0, NilaiHpp = 0, QtyOut = item.QtyAdjust * -1, HargaJual = 0, BPStokID = "", } }; listStok.Add(stok); } } var listJual = _penjualan2Dal.ListDataBrg(brgID); if (listJual != null) { Int32 i2 = 0; var e1 = new StartProsesStokEventArgs { ProsesName = "List Data Penjualan", DataCount = listJual.Count() }; OnStartProses(e1); foreach (var item in listJual) { i2++; var header = _penjualanDal.GetData(item.PenjualanID); if (header is null) { continue; } var e = new ProsesRegenStokEventArgs { Counter = i2, Tgl = header.TglPenjualan, TrsID = header.PenjualanID }; OnProsesRegenStok(e); var stok = new StokItem { ReffID = header.PenjualanID, Tgl = header.TglPenjualan, Jam = header.JamPenjualan, BrgID = item.BrgID, BPStokID = item.BPStokID, BrgName = item.BrgName, QtyIn = 0, NilaiHpp = 0, QtyOut = item.Qty, HargaJual = item.Harga, }; listStok.Add(stok); } } var listReceipt = _receiptDetilDal.ListData(brgID); if (listReceipt != null) { Int32 i2 = 0; var e1 = new StartProsesStokEventArgs { ProsesName = "List Data PenReceiptjualan", DataCount = listReceipt.Count() }; OnStartProses(e1); foreach (var item in listReceipt) { i2++; var header = _receiptDal.GetData(item.ReceiptID); if (header is null) { continue; } var e = new ProsesRegenStokEventArgs { Counter = i2, Tgl = header.Tgl, TrsID = header.ReceiptID }; OnProsesRegenStok(e); var stok = new StokItem { ReffID = header.ReceiptID, Tgl = header.Tgl, Jam = header.Jam, BrgID = item.BrgID, BrgName = item.BrgName, QtyIn = item.Qty, NilaiHpp = item.Harga - item.Diskon - item.TaxRupiah, QtyOut = 0, HargaJual = 0, BPStokID = "", }; listStok.Add(stok); } } Int32 i3 = 0; var e3 = new StartProsesStokEventArgs { ProsesName = "Re-generate stok", DataCount = listStok.Count() }; OnStartProses(e3); var listProsesAdd = listStok.Where(x => x.QtyIn > 0); foreach (var item in listProsesAdd.OrderBy(x => x.Tgl + x.Jam)) { i3++; var e = new ProsesRegenStokEventArgs { Counter = i3, Tgl = item.Tgl, TrsID = item.ReffID }; OnProsesRegenStok(e); _ = AddStok(item); } var listProsesRemove = listStok.Where(x => x.QtyOut > 0); foreach (var item in listProsesRemove.OrderBy(x => x.Tgl + x.Jam)) { i3++; var e = new ProsesRegenStokEventArgs { Counter = i3, Tgl = item.Tgl, TrsID = item.ReffID }; OnProsesRegenStok(e); _ = RemoveStok(item); } }
public IEnumerable <BPHutangModel> GenHutang(LunasKasBonModel lunasKasBon) { // list semua penjualan di detil lunas kas bon List <LunasKasBonJualDepositModel> listLunasKasBonJualDeposit = null; foreach (var item in lunasKasBon.ListLunas) { if (item.PenjualanID.Trim() == "") { continue; } var penjualan = _penjualanDal.GetData(item.PenjualanID); if (penjualan == null) { throw new ArgumentException("Penjualan ID invalid"); } if (listLunasKasBonJualDeposit == null) { listLunasKasBonJualDeposit = new List <LunasKasBonJualDepositModel>(); } listLunasKasBonJualDeposit.Add(new LunasKasBonJualDepositModel { LunasKasBonID = lunasKasBon.LunasKasBonID, PenjualanID = penjualan.PenjualanID, NilaiLunas = item.NilaiLunas, Keterangan = " " + item.Keterangan }); } // ambil data deposti dari penjualan tsb if (listLunasKasBonJualDeposit == null) { return(null); } foreach (var item in listLunasKasBonJualDeposit) { var penjualan = _penjualanDal.GetData(item.PenjualanID); if (penjualan.DepositID.Trim() == "") { continue; } var deposit = _depositDal.GetData(penjualan.DepositID); if (deposit == null) { throw new ArgumentException("Deposit ID invalid"); } item.DepositID = deposit.DepositID; } // generate pelunasan atas deposit tsb List <BPHutangModel> result = null; foreach (var item in listLunasKasBonJualDeposit.Where(x => x.DepositID.Trim() != "")) { var bpHutang = GetData(item.DepositID); // hapus detil pelunasan atas id lunasKasBon ini var listDetilHtg = ( from c in bpHutang.ListLunas where c.ReffID != lunasKasBon.LunasKasBonID select c ).ToList(); // tambahkan detil lunas kasbon ini var detilLunas = new BPHutangDetilModel { BPHutangID = bpHutang.BPHutangID, Tgl = lunasKasBon.Tgl, Jam = lunasKasBon.Jam, ReffID = lunasKasBon.LunasKasBonID, Keterangan = item.Keterangan, NilaiHutang = 0, NilaiLunas = item.NilaiLunas }; listDetilHtg.Add(detilLunas); // pindahkan listbaru ke object bpHutang bpHutang.ListLunas = listDetilHtg; // proses simpan Save(bpHutang); if (result == null) { result = new List <BPHutangModel>(); } result.Add(bpHutang); } return(result); }