public void Insert(BPStokDetilModel model) { var sSql = @" INSERT INTO BPStokDetil ( BPStokID, BPStokDetilID, NoUrut, ReffID, Tgl, Jam, QtyIn, NilaiHpp, QtyOut, HargaJual) VALUES ( @BPStokID, @BPStokDetilID, @NoUrut, @ReffID, @Tgl, @Jam, @QtyIn, @NilaiHpp, @QtyOut, @HargaJual) "; using (var conn = new SqlConnection(_connString)) using (var cmd = new SqlCommand(sSql, conn)) { cmd.AddParam("@BPStokID", model.BPStokID); cmd.AddParam("@BPStokDetilID", model.BPStokDetilID); cmd.AddParam("@NoUrut", model.NoUrut); cmd.AddParam("@ReffID", model.ReffID); cmd.AddParam("@Tgl", model.Tgl.ToTglYMD()); cmd.AddParam("@Jam", model.Jam); cmd.AddParam("@QtyIn", model.QtyIn); cmd.AddParam("NilaiHpp", model.NilaiHpp); cmd.AddParam("QtyOut", model.QtyOut); cmd.AddParam("@HargaJual", model.HargaJual); conn.Open(); cmd.ExecuteNonQuery(); } }
public void Generate_AdjMin_SingleStokControl_StokTidakCukup() { #region ARRANGE // arrange var adj = StokAdjustmentHeaderDataFactory(); adj.StokAdjustmentID = "A2"; var adjDetil = StokAdjustmentDetilDataFactory(); adj.ListBrg = new List <StokAdjustment2Model> { adjDetil }; adjDetil.QtyAdjust = -6; // bp stok var existingBPStok = BPStokHeaderDataFactory(); existingBPStok.ListDetil = new List <BPStokDetilModel> { BPStokDetilDataFactory() }; // expected var expected1 = existingBPStok.CloneObject(); expected1.QtySisa = 2; var addedDetil = new BPStokDetilModel { BPStokID = "A1B1", BPStokDetilID = "A1B1-002", NoUrut = 2, ReffID = "A2", Tgl = "20-02-2019", Jam = "21:39:00", QtyIn = 0, NilaiHpp = 0, QtyOut = 3, HargaJual = 2000, }; expected1.ListDetil.Add(addedDetil); var expected = new List <BPStokModel> { expected1 }; // setup mocking _bpStokDal.Setup(x => x.ListData("B1")) .Returns(new List <BPStokModel> { BPStokHeaderDataFactory() }); _bpStokDetilDal.Setup(x => x.ListData("A1B1")) .Returns(new List <BPStokDetilModel> { BPStokDetilDataFactory() }); #endregion // act var ex = Assert.Throws <ArgumentException>( () => _bpStokBL.Generate(adj)); // assert ex.Message.Should().Contain("Stok tidak cukup"); }
public void Generate_AdjMin_SingleStokControl_Berhasil() { #region ARRANGE // arrange var adj = StokAdjustmentHeaderDataFactory(); var adjDetil = StokAdjustmentDetilDataFactory(); adj.StokAdjustmentID = "A2"; adj.ListBrg = new List <StokAdjustment2Model> { adjDetil }; adjDetil.QtyAdjust = -3; // bp stok var existingBPStok = BPStokHeaderDataFactory(); existingBPStok.ListDetil = new List <BPStokDetilModel> { BPStokDetilDataFactory() }; // expected var expected1 = existingBPStok.CloneObject(); expected1.QtySisa = 2; var addedDetil = new BPStokDetilModel { BPStokID = "A1B1", BPStokDetilID = "A1B1-002", NoUrut = 2, ReffID = "A2", Tgl = "20-02-2019", Jam = "21:39:00", QtyIn = 0, NilaiHpp = 0, QtyOut = 3, HargaJual = 2000, }; expected1.ListDetil.Add(addedDetil); var expected = new List <BPStokModel> { expected1 }; // setup mocking _bpStokDal.Setup(x => x.ListData("B1")) .Returns(new List <BPStokModel> { BPStokHeaderDataFactory() }); _bpStokDetilDal.Setup(x => x.ListData("A1B1")) .Returns(new List <BPStokDetilModel> { BPStokDetilDataFactory() }); #endregion // act var actual = _bpStokBL.Generate(adj); // assert actual.Should().BeEquivalentTo(expected); }
public IEnumerable <BPStokDetilModel> ListData(string brgID, string tgl1, string tgl2) { List <BPStokDetilModel> result = null; var sSql = @" SELECT aa.BPStokID, aa.BPStokDetilID, aa.NoUrut, aa.ReffID, aa.Tgl, aa.Jam, aa.QtyIn, aa.NilaiHpp, aa.QtyOut, aa.HargaJual FROM BPStokDetil aa LEFT JOIN BPStok bb ON aa.BPStokID = bb.BPStokID WHERE bb.BrgID = @BrgID AND aa.Tgl BETWEEN @Tgl1 AND @Tgl2"; using (var conn = new SqlConnection(_connString)) using (var cmd = new SqlCommand(sSql, conn)) { cmd.AddParam("@BrgID", brgID); cmd.AddParam("@Tgl1", tgl1.ToTglYMD()); cmd.AddParam("@Tgl2", tgl2.ToTglYMD()); conn.Open(); using (var dr = cmd.ExecuteReader()) { if (!dr.HasRows) { return(null); } result = new List <BPStokDetilModel>(); while (dr.Read()) { var item = new BPStokDetilModel { BPStokID = dr["BPStokID"].ToString(), BPStokDetilID = dr["BPStokDetilID"].ToString(), NoUrut = Convert.ToInt16(dr["NoUrut"]), ReffID = dr["ReffID"].ToString(), Tgl = dr["Tgl"].ToString().ToTglDMY(), Jam = dr["Jam"].ToString(), QtyIn = Convert.ToDecimal(dr["QtyIn"]), NilaiHpp = Convert.ToDecimal(dr["NilaiHpp"]), QtyOut = Convert.ToDecimal(dr["QtyOut"]), HargaJual = Convert.ToDecimal(dr["HargaJual"]) }; result.Add(item); } } } return(result); }
public IEnumerable <BPStokDetilModel> ListData(string bpStokID) { List <BPStokDetilModel> result = null; var sSql = @" SELECT BPStokID, BPStokDetilID, NoUrut, ReffID, Tgl, Jam, QtyIn, NilaiHpp, QtyOut, HargaJual FROM BPStokDetil WHERE BPStokID = @BPStokID "; using (var conn = new SqlConnection(_connString)) using (var cmd = new SqlCommand(sSql, conn)) { cmd.AddParam("@BPStokID", bpStokID); conn.Open(); using (var dr = cmd.ExecuteReader()) { if (!dr.HasRows) { return(null); } result = new List <BPStokDetilModel>(); while (dr.Read()) { var item = new BPStokDetilModel { BPStokID = dr["BPStokID"].ToString(), BPStokDetilID = dr["BPStokDetilID"].ToString(), NoUrut = Convert.ToInt16(dr["NoUrut"]), ReffID = dr["ReffID"].ToString(), Tgl = dr["Tgl"].ToString().ToTglDMY(), Jam = dr["Jam"].ToString(), QtyIn = Convert.ToDecimal(dr["QtyIn"]), NilaiHpp = Convert.ToDecimal(dr["NilaiHpp"]), QtyOut = Convert.ToDecimal(dr["QtyOut"]), HargaJual = Convert.ToDecimal(dr["HargaJual"]) }; result.Add(item); } } } return(result); }
private BPStokDetilModel BPStokDetilDataFactory() { var result = new BPStokDetilModel { BPStokID = "A1B1", BPStokDetilID = "A1B1-001", NoUrut = 1, ReffID = "A1", Tgl = "20-02-2019", Jam = "21:39:00", QtyIn = 5, NilaiHpp = 2000, QtyOut = 0, HargaJual = 0, }; return(result); }
private BPStokDetilModel BPStokDetilDataFactory() { var result = new BPStokDetilModel { BPStokID = "A1", BPStokDetilID = "B1", NoUrut = 2, ReffID = "C1", Tgl = "20-02-2019", Jam = "21:12:00", QtyIn = 5, NilaiHpp = 52000, QtyOut = 3, HargaJual = 55125, }; return(result); }
private IEnumerable <BPStokModel> RemoveStok(StokItem stokItem) { List <BPStokModel> result = null; // null check if (stokItem == null) { throw new ArgumentNullException(nameof(stokItem)); } // list semua buku stok barang ini yang masih ada sisa stok var listBPStok = ListData(stokItem.BrgID); if (listBPStok == null) { return(null); } // jika pengurangan stok untuk kasus tertentu // (sudah ditetepkan stok mana yg dikurangi) if (stokItem.BPStokID.Trim() != "") { listBPStok = listBPStok.Where(x => x.BPStokID == stokItem.BPStokID); } // hapus detil utk 'trs ini' dulu // (kasus simpan ulang) foreach (var item in listBPStok) { item.ListDetil = item.ListDetil.Where(x => x.ReffID != stokItem.ReffID).ToList(); } // proses pengurangan stok, biar mudah di-pluskan dulu var qtyPengurang = stokItem.QtyOut; // proses pengurangan foreach (var item in listBPStok) { decimal qtyOut = 0; if (item.QtySisa >= qtyPengurang) { qtyOut = qtyPengurang; } else { qtyOut = item.QtySisa; } // kurangi pengurangnya qtyPengurang -= qtyOut; // var noUrut = item.ListDetil.Count() + 1; // jika hargajual = 0, // maka ambil harga beli-nya if (stokItem.HargaJual == 0) { stokItem.HargaJual = item.NilaiHpp; } // bikin detil baru var bpStokDetil = new BPStokDetilModel { BPStokID = item.BPStokID, ReffID = stokItem.ReffID, Tgl = stokItem.Tgl, Jam = stokItem.Jam, QtyIn = 0, NilaiHpp = 0, QtyOut = qtyOut, HargaJual = stokItem.HargaJual, }; item.ListDetil.Add(bpStokDetil); item.QtySisa = item.QtyIn - item.ListDetil.Sum(x => x.QtyOut); // add ke result if (result == null) { result = new List <BPStokModel>(); } result.Add(item); // generate ulang nomor urut-nya int noUrut = 1; foreach (var item2 in item.ListDetil.OrderBy(x => x.Tgl + x.Jam)) { item2.NoUrut = noUrut; item2.BPStokDetilID = item.BPStokID + '-' + noUrut.ToString().PadLeft(3, '0'); noUrut++; } // update header _bpStokDal.Update(item); // delete detil _bpStokDetilDal.Delete(item.BPStokID); // insert baru foreach (var item2 in item.ListDetil) { _bpStokDetilDal.Insert(item2); } if (qtyPengurang == 0) { break; } } // jika masih belum selesai pengurangan stok-nya, // berarti stok ngga cukup. Throw error. if (qtyPengurang != 0) { var errMsg = string.Format("Stok tidak cukup : {0} - {1}", stokItem.BrgID, stokItem.BrgName); throw new ArgumentException(errMsg); } return(result); }