Ejemplo n.º 1
0
 public ActionResult Grid(int ID = 0)
 {
     ViewBag.ID = ID;
     using (Models.VTEntities db = new Models.VTEntities())
     {
         updateSoTien(ID);
         var data = db.SalesOrders.Where(z => z.SalesOrderId == ID).FirstOrDefault();
         if (data == null)
         {
             return(RedirectToAction("index", "SalesOrder"));
         }
         ViewBag.SalesTypeId     = db.SalesTypes.Where(z => z.SalesTypeId == data.SalesTypeId).Select(z => z.SalesTypeName).FirstOrDefault();
         ViewBag.CustomerId      = db.Customers.Where(z => z.CustomerId == data.CustomerId).Select(z => z.CustomerName).FirstOrDefault();
         ViewBag.SalesOrderLines = db.SalesOrderLines.Where(z => z.SalesOrderId == data.SalesOrderId).ToList();
         var    LDaThanhToan = db.PaymentReceives.Where(z => z.SalesOrderId == ID).ToList();
         Double DaThanhToan  = 0;
         if (LDaThanhToan.Count != 0)
         {
             DaThanhToan = LDaThanhToan.Sum(z => z.PaymentAmount);
         }
         ViewBag.ConLai      = (data.Total - DaThanhToan).ToString("#,###");
         ViewBag.DaThanhToan = DaThanhToan.ToString("#,###");
         ViewBag.CongNo      = db.Database.SqlQuery <Double>("select isnull(Total-PaymentAmount,0) AS CongNo from SalesOrder as t1 left join (select SalesOrderId,SUM(PaymentAmount) AS PaymentAmount from PaymentReceive  WHERE PaymentAmount>0  group by SalesOrderId ) as t2 on t1.SalesOrderId = t2.SalesOrderId where CustomerId = " + data.CustomerId + " and T1.SalesOrderId != " + data.SalesOrderId + " ").FirstOrDefault().ToString("#,###");
         ViewBag.ConLai      = (ViewBag.ConLai == "" ? "0" : ViewBag.ConLai);
         ViewBag.DaThanhToan = (ViewBag.DaThanhToan == "" ? "0" : ViewBag.DaThanhToan);
         ViewBag.CongNo      = (ViewBag.CongNo == "" ? "0" : ViewBag.CongNo);
         return(PartialView(data));
     }
 }
Ejemplo n.º 2
0
 public ActionResult NhanThanhToan(PaymentReceive item)
 {
     using (Models.VTEntities db = new Models.VTEntities())
     {
         item.PaymentDate = DateTime.Now;
         db.PaymentReceives.Add(item);
         db.SaveChanges();
     }
     return(Json("", JsonRequestBehavior.AllowGet));
 }
Ejemplo n.º 3
0
 public ActionResult Delete(int ID)
 {
     using (Models.VTEntities db = new Models.VTEntities())
     {
         var item = db.SalesOrderLines.Where(z => z.SalesOrderLineId == ID).FirstOrDefault();
         ID = item.SalesOrderId;
         db.SalesOrderLines.Remove(item);
         db.SaveChanges();
         updateSoTien(ID);
     }
     return(Json("", JsonRequestBehavior.AllowGet));
 }
Ejemplo n.º 4
0
 public void updateSoTien(int ID = 0)
 {
     using (Models.VTEntities db = new Models.VTEntities())
     {
         var data = db.SalesOrderLines.AsNoTracking().Where(z => z.SalesOrderId == ID).ToList();
         var item = db.SalesOrders.Where(z => z.SalesOrderId == ID).FirstOrDefault();
         item.Amount   = data.Sum(Z => Z.Price);
         item.Discount = data.Where(Z => Z.DiscountAmount.HasValue).Sum(Z => Z.Amount / 100 * Z.DiscountAmount.Value);
         item.SubTotal = data.Where(Z => Z.SubTotal.HasValue).Sum(Z => Z.SubTotal.Value);
         item.Tax      = data.Where(Z => Z.TaxAmount.HasValue).Sum(Z => Z.Amount / 100 * Z.TaxAmount.Value);
         item.Total    = item.Amount - item.Discount + item.SubTotal + item.Tax;
         db.SaveChanges();
     }
 }
Ejemplo n.º 5
0
 public ActionResult Create(int ID = 0, int SalesOrderId = 0)
 {
     ViewBag.ID = ID;
     using (Models.VTEntities db = new Models.VTEntities())
     {
         db.Configuration.ProxyCreationEnabled = false;
         var data = db.SalesOrderLines.AsNoTracking().Where(z => z.SalesOrderLineId == ID).FirstOrDefault();
         if (data == null)
         {
             data = new Models.SalesOrderLine();
             data.SalesOrderId = SalesOrderId;
         }
         var jsonSettings = new JsonSerializerSettings();
         jsonSettings.DateFormatString = "yyyy-MM-dd";
         ViewBag.item = JsonConvert.SerializeObject(data, jsonSettings);
     }
     return(PartialView());
 }
Ejemplo n.º 6
0
 public ActionResult Create(SalesOrderLine item)
 {
     using (Models.VTEntities db = new Models.VTEntities())
     {
         if (item.SalesOrderLineId == 0)
         {
             item.DateUpdate = DateTime.Now;
             db.SalesOrderLines.Add(item);
         }
         else
         {
             var data = db.SalesOrderLines.Where(z => z.SalesOrderLineId == item.SalesOrderLineId).FirstOrDefault();
             data.Quantity       = item.Quantity;
             data.Price          = item.Price;
             data.TaxAmount      = item.TaxAmount;
             data.DiscountAmount = item.DiscountAmount;
             data.Total          = item.Total;
             data.SubTotal       = item.SubTotal;
         }
         db.SaveChanges();
     }
     return(Json("", JsonRequestBehavior.AllowGet));
 }