public void Save() { var orderJual = new OrderJualModel { OrderJualID = _view.OrderJualID, TglOrderJual = _view.TglOrderJual, JamOrderJual = _view.JamOrderJual, CustomerID = _view.CustomerID, BuyerName = _view.BuyerName, Alamat = _view.Alamat, NoTelp = _view.NoTelpon, Catatan = _view.Catatan, NilaiTotal = _view.NilaiTotal, NilaiDiskonLain = _view.NilaiDiskonLain, NilaiBiayaLain = _view.NilaiBiayaLain, NilaiGrandTotal = _view.NilaiGrandTotal, }; orderJual.ListBrg = orderJual.ListBrg.Where(x => x.BrgID != "").ToList(); using (var trans = TransHelper.NewScope()) { var result = _orderJualBL.Save(orderJual); trans.Complete(); } }
public IEnumerable <OrderJualModel> ListData(string tgl1, string tgl2) { List <OrderJualModel> result = null; var sSql = @" SELECT OrderJualID, TglOrderJual, JamOrderJual, BuyerName, CustomerID, Alamat, NoTelp, Catatan, IsBayarDeposit, DepositID, NilaiDeposit, NilaiTotal, NilaiDiskonLain, NilaiBiayaLain, NilaiGrandTotal, NilaiBayar, NilaiKembali FROM OrderJual WHERE TglOrderJual BETWEEN @Tgl1 AND @Tgl2 "; using (var conn = new SqlConnection(_connString)) using (var cmd = new SqlCommand(sSql, conn)) { cmd.AddParam("@Tgl1", tgl1.ToTglYMD()); cmd.AddParam("@Tgl2", tgl2.ToTglYMD()); conn.Open(); using (var dr = cmd.ExecuteReader()) { if (dr.HasRows) { result = new List <OrderJualModel>(); while (dr.Read()) { var item = new OrderJualModel { OrderJualID = dr["OrderJualID"].ToString(), TglOrderJual = dr["TglOrderJual"].ToString().ToTglDMY(), JamOrderJual = dr["JamOrderJual"].ToString(), BuyerName = dr["BuyerName"].ToString(), CustomerID = dr["CustomerID"].ToString(), Alamat = dr["Alamat"].ToString(), NoTelp = dr["NoTelp"].ToString(), Catatan = dr["Catatan"].ToString(), NilaiTotal = Convert.ToDecimal(dr["NilaiTotal"]), NilaiDiskonLain = Convert.ToDecimal(dr["NilaiDiskonLain"]), NilaiBiayaLain = Convert.ToDecimal(dr["NilaiBiayaLain"]), NilaiGrandTotal = Convert.ToDecimal(dr["NilaiGrandTotal"]), }; result.Add(item); } } } } return(result); }
public OrderJualModel GetData(string orderJualID) { OrderJualModel result = null; var sSql = @" SELECT OrderJualID, TglOrderJual, JamOrderJual, BuyerName, CustomerID, Alamat, NoTelp, Catatan, IsBayarDeposit, DepositID, NilaiTotal, NilaiDiskonLain, NilaiDeposit, NilaiBiayaLain, NilaiGrandTotal, NilaiBayar, NilaiKembali FROM OrderJual WHERE OrderJualID = @OrderJualID "; using (var conn = new SqlConnection(_connString)) using (var cmd = new SqlCommand(sSql, conn)) { cmd.AddParam("@OrderJualID", orderJualID); conn.Open(); using (var dr = cmd.ExecuteReader()) { if (dr.HasRows) { dr.Read(); result = new OrderJualModel { OrderJualID = dr["OrderJualID"].ToString(), TglOrderJual = dr["TglOrderJual"].ToString().ToTglDMY(), JamOrderJual = dr["JamOrderJual"].ToString(), BuyerName = dr["BuyerName"].ToString(), CustomerID = dr["CustomerID"].ToString(), Alamat = dr["Alamat"].ToString(), NoTelp = dr["NoTelp"].ToString(), Catatan = dr["Catatan"].ToString(), NilaiTotal = Convert.ToDecimal(dr["NilaiTotal"]), NilaiDiskonLain = Convert.ToDecimal(dr["NilaiDiskonLain"]), NilaiBiayaLain = Convert.ToDecimal(dr["NilaiBiayaLain"]), NilaiGrandTotal = Convert.ToDecimal(dr["NilaiGrandTotal"]), }; } } } return(result); }
public void Update(OrderJualModel orderJual) { var sSql = @" UPDATE OrderJual SET TglOrderJual = @TglOrderJual, JamOrderJual = @JamOrderJual, BuyerName = @BuyerName, CustomerID = @CustomerID, Alamat = @Alamat, NoTelp = @NoTelp, Catatan = @Catatan, IsBayarDeposit = @IsBayarDeposit, DepositID = @DepositID, NilaiDeposit = @NilaiDeposit, NilaiTotal = @NilaiTotal, NilaiDiskonLain = @NilaiDiskonLain, NilaiBiayaLain = @NilaiBiayaLain, NilaiGrandTotal = @NilaiGrandTotal, NilaiBayar = @NilaiBayar, NilaiKembali = @NilaiKembali WHERE OrderJualID = @OrderJualID "; using (var conn = new SqlConnection(_connString)) using (var cmd = new SqlCommand(sSql, conn)) { cmd.AddParam("@OrderJualID", orderJual.OrderJualID); cmd.AddParam("@TglOrderJual", orderJual.TglOrderJual.ToTglYMD()); cmd.AddParam("@JamOrderJual", orderJual.JamOrderJual); cmd.AddParam("@BuyerName", orderJual.BuyerName); cmd.AddParam("@CustomerID", orderJual.CustomerID); cmd.AddParam("@Alamat", orderJual.Alamat); cmd.AddParam("@NoTelp", orderJual.NoTelp); cmd.AddParam("@Catatan", orderJual.Catatan); cmd.AddParam("@NilaiTotal", orderJual.NilaiTotal); cmd.AddParam("@NilaiDiskonLain", orderJual.NilaiDiskonLain); cmd.AddParam("@NilaiBiayaLain", orderJual.NilaiBiayaLain); cmd.AddParam("@NilaiGrandTotal", orderJual.NilaiGrandTotal); conn.Open(); cmd.ExecuteNonQuery(); } }
public OrderJualModel Save(OrderJualModel orderJual) { // validasi var result = orderJual; result = TryValidate(orderJual); var trsID = ""; // save using (var trans = TransHelper.NewScope()) { // edit: delete data lama if (orderJual.OrderJualID.Trim() != "") { _orderJual2Dal.Delete(orderJual.OrderJualID); _orderJualDal.Delete(orderJual.OrderJualID); trsID = orderJual.OrderJualID; } // baru: generate no.transaksi else { var prefix = "JL" + DateTime.Now.ToString("yyMM"); trsID = _paramNoBL.GenNewID(prefix, 10); } // save header orderJual.OrderJualID = trsID; _orderJualDal.Insert(orderJual); // save detil barang foreach (var item in orderJual.ListBrg) { item.OrderJualID = trsID; item.OrderJualID2 = string.Format("{0}-{1}", trsID, item.NoUrut.ToString().PadLeft(3, '0')); _orderJual2Dal.Insert(item); } trans.Complete(); } return(result); }
public OrderJualModel TryValidate(OrderJualModel orderJual) { var result = orderJual; if (orderJual == null) { throw new ArgumentNullException(nameof(orderJual)); } // validasi tgl dan jam if (!orderJual.TglOrderJual.IsValidTgl("dd-MM-yyyy")) { throw new ArgumentException("Invalid Tgl.OrderJual"); } if (!orderJual.JamOrderJual.IsValidJam("HH:mm:ss")) { throw new ArgumentException("Invalid Jam.OrderJual"); } // cek BrgID foreach (var item in orderJual.ListBrg) { var brg = _brgBL.GetData(item.BrgID); if (brg == null) { throw new ArgumentException("Invalid BrgID "); } else { item.BrgName = brg.BrgName; } // re-calc qty akhir item.SubTotal = (item.Harga - item.Diskon) * item.Qty; } return(result); }
public void Insert(OrderJualModel orderJual) { var sSql = @" INSERT INTO OrderJual( OrderJualID, TglOrderJual, JamOrderJual, BuyerName, CustomerID, Alamat, NoTelp, Catatan, IsBayarDeposit, DepositID, NilaiDeposit, NilaiTotal, NilaiDiskonLain, NilaiBiayaLain, NilaiGrandTotal, NilaiBayar, NilaiKembali) VALUES ( @OrderJualID, @TglOrderJual, @JamOrderJual, @BuyerName, @CustomerID, @Alamat, @NoTelp, @Catatan, @IsBayarDeposit, @DepositID, @NilaiDeposit, @NilaiTotal, @NilaiDiskonLain, @NilaiBiayaLain, @NilaiGrandTotal, @NilaiBayar, @NilaiKembali) "; using (var conn = new SqlConnection(_connString)) using (var cmd = new SqlCommand(sSql, conn)) { cmd.AddParam("@OrderJualID", orderJual.OrderJualID); cmd.AddParam("@TglOrderJual", orderJual.TglOrderJual.ToTglYMD()); cmd.AddParam("@JamOrderJual", orderJual.JamOrderJual); cmd.AddParam("@BuyerName", orderJual.BuyerName); cmd.AddParam("@CustomerID", orderJual.CustomerID); cmd.AddParam("@Alamat", orderJual.Alamat); cmd.AddParam("@NoTelp", orderJual.NoTelp); cmd.AddParam("@Catatan", orderJual.Catatan); cmd.AddParam("@NilaiTotal", orderJual.NilaiTotal); cmd.AddParam("@NilaiDiskonLain", orderJual.NilaiDiskonLain); cmd.AddParam("@NilaiBiayaLain", orderJual.NilaiBiayaLain); cmd.AddParam("@NilaiGrandTotal", orderJual.NilaiGrandTotal); conn.Open(); cmd.ExecuteNonQuery(); } }