public ActionResult ReplaceTemplate()
        {
            TblQuotation         ob         = null;
            TblQuotationTemplate obTemplate = null;

            try
            {
                int QuotationId     = Request.Form["QuotationId"].ParseInt();
                int TempQuotationId = Request.Form["TempQuotationId"].ParseInt();
                ob = uow.Modules.Quotation.Get(QuotationId);
                if (ob.QuotationId >= 0)
                {
                    obTemplate                 = new TblQuotationTemplate();
                    obTemplate.QuotationId     = QuotationId;
                    obTemplate.TempQuotationId = TempQuotationId;
                    uow.Modules.QuotationTemplate.ReplaceVersion(obTemplate);
                    uow.SaveChanges();
                }
                return(RedirectToAction("Detail", MVCController, new { id = ob.QuotationId, msg = "บันทึกข้อมูลใหม่เรียบร้อยแล้ว", msgType = AlertMsgType.Success }));
            }
            catch (Exception ex)
            {
                string msg = ex.GetMessage(true);
                return(ViewDetail(ob, msg, AlertMsgType.Danger));
            }
        }
        public ActionResult saveDiscount()
        {
            int qid = Request.Form["QuotationId"].ParseInt();

            TblQuotation ob = uow.Modules.Quotation.Get(qid);

            ob.DiscountCash = Request.Form["DiscountCash"].ParseDecimal();
            uow.Modules.Quotation.Set(ob);
            uow.SaveChanges();
            return(RedirectToAction("Detail", MVCController, new { id = qid, tab = "Product", msg = "", msgType = AlertMsgType.Success }));
        }
        private ActionResult ViewDetail(TblQuotation ob, string msg, AlertMsgType?msgType)
        {
            try
            {
                if (ob == null)
                {
                    throw new Exception("ไม่พบข้อมูลที่ต้องการ, กรุณาลองใหม่อีกครั้ง");
                }

                if (!string.IsNullOrWhiteSpace(msg))
                {
                    WidgetAlertModel alert = new WidgetAlertModel()
                    {
                        Message = msg
                    };
                    if (msgType.HasValue)
                    {
                        alert.Type = msgType.Value;
                    }
                    ViewBag.Alert = alert;
                }



                AccountPermission permission = GetPermissionSale(CurrentUser.AccountId, ob.CreatedBy.HasValue ? ob.CreatedBy.Value : 0);


                ViewData["optQtDetail"]         = uow.Modules.QuotationDetail.Gets(ob.QuotationId);
                ViewData["optCustomer"]         = uow.Modules.Customer.GetAllAddress();
                ViewData["optCustomerAddress"]  = uow.Modules.CustomerAddress.Gets();
                ViewData["optProduct"]          = uow.Modules.Product.Gets();
                ViewData["optContact"]          = uow.Modules.CustomerContact.Gets();
                ViewData["optEmployee"]         = uow.Modules.Employee.Gets();
                ViewData["userAccount"]         = CurrentUser;
                ViewData["optWareHouse"]        = uow.Modules.WareHouse.Gets();
                ViewData["optPermission"]       = permission;
                ViewData["opQuotationTemplate"] = uow.Modules.QuotationTemplate.GetList(ob.QuotationId);
                return(View(ob));
            }
            catch (Exception ex)
            {
                return(RedirectToAction("Index", MVCController, new
                {
                    area = MVCArea,
                    msg = ex.GetMessage(),
                    msgType = AlertMsgType.Danger
                }));
            }
        }
        //[Authorized]
        public ActionResult Delete()
        {
            try
            {
                int          id = Request.Form["QuotationId"].ParseInt();
                TblQuotation ob = uow.Modules.Quotation.Get(id);
                if (ob == null)
                {
                    return(RedirectToAction("Index", MVCController, new { msg = "ไม่พบข้อมูลที่ต้องการ", msgType = AlertMsgType.Warning }));
                }

                uow.Modules.Quotation.Delete(ob);
                uow.SaveChanges();
                return(RedirectToAction("Index", MVCController, new { msg = "ลบข้อมูลเรียบร้อยแล้ว", msgType = AlertMsgType.Success }));
            }
            catch (Exception ex)
            { return(RedirectToAction("Index", MVCController, new { msg = ex.GetMessage(), msgType = AlertMsgType.Danger })); }
        }
        public ActionResult SetDetail()
        {
            int          id = Request.Form["QuotationId"].ParseInt();
            TblQuotation ob = uow.Modules.Quotation.Get(id);

            if (ob.QuotationId <= 0)
            {
                ob.QuotationNo   = genQuotationId();
                ob.CreatedBy     = CurrentUID;
                ob.UpdatedBy     = CurrentUID;
                ob.CreatedDate   = CurrentDate;
                ob.UpdateDate    = CurrentDate;
                ob.QuotationDate = CurrentDate;
            }
            else
            {
                ob.UpdatedBy  = CurrentUID;
                ob.UpdateDate = CurrentDate;
            }
            ob.SaleId   = Request.Form["SaleId"] != null  ? Request.Form["SaleId"].ParseInt() : 0;
            ob.SaleName = Request.Form["SaleName"];
            if (Request.Form["DeliveryDate"].ToString().Count() > 0)
            {
                var dd = Request.Form["DeliveryDate"].Split(' ')[0] + " 00:00:00";

                ob.DeliveryDate = dd.ParseDate(DateFormat.ddMMyyyyHHmmss);
            }

            ob.CustomerId   = Request.Form["CustomerId"].ParseInt();
            ob.CustomerName = Request.Form["CustomerName"];

            ob.ContractName   = Request.Form["ContractName"];
            ob.ContractEmail  = Request.Form["ContractEmail"];
            ob.ContractPhone  = Request.Form["ContractPhone"];
            ob.BillingAddress = Request.Form["BillingAddress"];

            ob.ShippingAddress = Request.Form["ShippingAddress"];
            ob.QuotationRemark = Request.Form["QuotationRemark"];

            if (Request.Form["DiscountCash"] != null)
            {
                ob.DiscountCash = decimal.Parse(Request.Form["DiscountCash"]);
            }

            ob.QuotationValidDay  = Request.Form["QuotationValidDay"].ParseInt();
            ob.QuotationCreditDay = Request.Form["QuotationCreditDay"].ParseInt();

            ob.DueDate = ob.CreatedDate.AddDays(ob.QuotationValidDay).ToUniversalTime();

            ob.StatusId = Request.Form["StatusId"].ParseInt();


            try
            {
                uow.Modules.Quotation.Set(ob);
                uow.SaveChanges();

                return(RedirectToAction("Detail", MVCController, new { id = ob.QuotationId, msg = "บันทึกข้อมูลเรียบร้อยแล้ว", msgType = AlertMsgType.Success }));
            }
            catch (Exception ex)
            {
                string msg = ex.GetMessage(true);
                return(ViewDetail(ob, msg, AlertMsgType.Danger));
            }
        }
        public ActionResult Detail(int?id, string msg, AlertMsgType?msgType)
        {
            TblQuotation ob = uow.Modules.Quotation.Get(id ?? 0);

            return(ViewDetail(ob, msg, msgType));
        }
        public ActionResult AddProduct()
        {
            int     qid                   = Request.Form["QuotationId"].ParseInt();
            var     productId             = Request.Form["selProduct"].Split(':');            //  ProductId:PriceNet
            var     SelQuotationProductId = Request.Form["SelQuotationProductId"].ParseInt(); //  ProductId:PriceNet
            int     qty                   = Request.Form["ProductQty"].ParseInt();
            Decimal price                 = Request.Form["ProductPrice"].ParseDecimal();
            Decimal discount              = Request.Form["ProductDiscount"].ParseDecimal();
            int     WHId                  = Request.Form["selWareHose"].ParseInt();
            decimal realDiscount          = 0;
            var     remark                = Request.Form["Remark"];

            if (productId.Count() > 0)
            {
                int pid = int.Parse(productId[0]);

                TblQuotationDetail ob = SelQuotationProductId > 0 ? uow.Modules.QuotationDetail.Get(SelQuotationProductId) : uow.Modules.QuotationDetail.Get(qid, Converting.ToInt(productId[0]), WHId);
                realDiscount   = discount;
                ob.QuotationId = qid;
                ob.WHId        = WHId;
                ob.ProductId   = pid;
                ob.Quantity    = qty;
                ob.CalType     = Request.Form["selCalType"].ParseInt();
                ob.PriceUnit   = price;
                ob.PriceNet    = price * qty;
                ob.PriceVat    = uow.Modules.System.GetVatFromNet(price * qty);
                // ob.PriceVat = (price * qty * vat) - (price * qty);
                ob.PriceTot = price * qty + ob.PriceVat;
                if (ob.CalType == 1)
                {
                    realDiscount = ((ob.PriceNet * discount) / 100);
                }

                ob.Discount    = discount;
                ob.DiscountNet = realDiscount;
                ob.DiscountVat = uow.Modules.System.GetVatFromNet(realDiscount);
                ob.DiscountTot = realDiscount + ob.DiscountVat;

                ob.TotalNet = ob.PriceNet - realDiscount;

                ob.TotalVat = ob.PriceVat - ob.DiscountVat;
                ob.TotalTot = ob.PriceTot - ob.DiscountTot;

                ob.Remark = remark;
                uow.Modules.QuotationDetail.Set(ob);
                uow.SaveChanges();

                TblQuotation objQuoation = uow.Modules.Quotation.GetDetail(qid);

                objQuoation.SubTotalNet = objQuoation.TblQuotationDetail.Sum(o => o.PriceNet);
                objQuoation.SubTotalVat = objQuoation.TblQuotationDetail.Sum(o => o.PriceVat);
                objQuoation.SubTotalTot = objQuoation.TblQuotationDetail.Sum(o => o.PriceTot);
                objQuoation.DiscountNet = objQuoation.TblQuotationDetail.Sum(o => o.DiscountNet);
                objQuoation.DiscountVat = objQuoation.TblQuotationDetail.Sum(o => o.DiscountVat);
                objQuoation.DiscountTot = objQuoation.TblQuotationDetail.Sum(o => o.DiscountTot);
                objQuoation.SummaryNet  = objQuoation.TblQuotationDetail.Sum(o => o.TotalNet);
                objQuoation.SummaryVat  = objQuoation.TblQuotationDetail.Sum(o => o.TotalVat);
                objQuoation.SummaryTot  = objQuoation.TblQuotationDetail.Sum(o => o.TotalTot);

                uow.Modules.Quotation.Set(objQuoation);
                uow.SaveChanges();
            }
            return(RedirectToAction("Detail", MVCController, new { id = qid, tab = "Product", msg = "", msgType = AlertMsgType.Success }));
        }
        public ActionResult SetDetail()
        {
            bool         updateOrgId   = false;
            TblQuotation cloneObj      = new TblQuotation();
            int          QuotationId   = Request.Form["QuotationId"].ParseInt();
            int          approveStatus = Request.Form["hdApprove"] != null ? Request.Form["hdApprove"].ParseInt():0;

            int          TempQuotationId = Request.Form["TempQuotationId"].ParseInt();
            TblQuotation ob = uow.Modules.Quotation.Get(QuotationId);

            if (ob.QuotationId <= 0)
            {
                updateOrgId      = true;
                ob.QuotationNo   = genQuotationId();
                ob.CreatedBy     = CurrentUID;
                ob.UpdatedBy     = CurrentUID;
                ob.CreatedDate   = CurrentDate;
                ob.UpdatedDate   = CurrentDate;
                ob.QuotationDate = CurrentDate;
                //  ob.RefQuotationId = id;
                //  ob.OrgQuotationId = ob.OrgQuotationId.HasValue ? ob.OrgQuotationId : id;
            }
            else
            {
                ob.UpdatedBy   = CurrentUID;
                ob.UpdatedDate = CurrentDate;
            }
            ob.StatusId = Request.Form["StatusId"].ParseInt();

            if (approveStatus == 3)
            {
                ob.StatusId   = 3;
                ob.ApprovedBy = Convert.ToInt32(CurrentUID);
            }
            ob.QuotationRemark = Request.Form["QuotationRemark"];;
            ob.SaleId          = Request.Form["SaleId"] != null ? Request.Form["SaleId"].ParseInt() : 0;
            ob.SaleName        = Request.Form["SaleName"];
            if (Request.Form["DeliveryDate"].ToString().Count() > 0)
            {
                var dd = Request.Form["DeliveryDate"].Split(' ')[0] + " 00:00:00";

                ob.DeliveryDate = dd.ParseDate(DateFormat.ddMMyyyyHHmmss);
            }

            ob.CustomerId   = Request.Form["CustomerId"].ParseInt();
            ob.CustomerName = Request.Form["CustomerName"];

            ob.ContractName   = Request.Form["ContractName"];
            ob.ContractEmail  = Request.Form["ContractEmail"];
            ob.ContractPhone  = Request.Form["ContractPhone"];
            ob.BillingAddress = Request.Form["BillingAddress"];

            ob.ShippingAddress = Request.Form["ShippingAddress"];


            if (Request.Form["DiscountCash"] != null)
            {
                ob.DiscountCash = decimal.Parse(Request.Form["DiscountCash"]);
            }

            ob.QuotationValidDay  = Request.Form["QuotationValidDay"].ParseInt();
            ob.QuotationCreditDay = Request.Form["QuotationCreditDay"].ParseInt();

            ob.DueDate = ob.CreatedDate.Value.AddDays(ob.QuotationValidDay).ToUniversalTime();



            try
            {
                uow.Modules.Quotation.Set(ob);


                uow.SaveChanges();
                if (updateOrgId)
                {
                    ob.OrgQuotationId = ob.QuotationId;
                    uow.Modules.Quotation.Set(ob);
                }


                //  ob = uow.Modules.Quotation.Get(QuotationId);
                if (approveStatus == 3)
                {
                    TblQuotationTemplate obTemplate = new TblQuotationTemplate();
                    obTemplate.QuotationId     = QuotationId;
                    obTemplate.TempQuotationId = TempQuotationId;
                    uow.Modules.QuotationTemplate.SetVersion(obTemplate);
                    uow.SaveChanges();
                }



                uow.SaveChanges();
                return(RedirectToAction("Detail", MVCController, new { id = ob.QuotationId, msg = "บันทึกข้อมูลเรียบร้อยแล้ว", msgType = AlertMsgType.Success }));
            }
            catch (Exception ex)
            {
                string msg = ex.GetMessage(true);
                return(ViewDetail(ob, msg, AlertMsgType.Danger));
            }
        }
        public ActionResult CloneDetail()
        {
            int id = Request.Form["QuotationId"].ParseInt();

            TblQuotation objOrg = uow.Modules.Quotation.GetDetail(id);
            TblQuotation ob     = Kemrex.Core.Common.Helper.Converting.ObjectClone <TblQuotation>(objOrg);

            ob.QuotationId    = 0;
            ob.RefQuotationId = id;
            ob.OrgQuotationId = ob.OrgQuotationId.HasValue ? ob.OrgQuotationId : id;

            /*   if (ob.QuotationId <= 0)
             *  {
             *      ob.QuotationNo = genQuotationId();
             *      ob.CreatedBy = CurrentUID;
             *      ob.UpdatedBy = CurrentUID;
             *      ob.CreatedDate = CurrentDate;
             *      ob.UpdatedDate = CurrentDate;
             *      ob.QuotationDate = CurrentDate;
             *  }
             *  else
             *  {
             *      ob.UpdatedBy = CurrentUID;
             *      ob.UpdatedDate = CurrentDate;
             *  }
             */



            ob.QuotationNo   = genQuotationId();
            ob.StatusId      = 1;
            ob.CreatedBy     = CurrentUID;
            ob.UpdatedBy     = CurrentUID;
            ob.CreatedDate   = CurrentDate;
            ob.UpdatedDate   = CurrentDate;
            ob.QuotationDate = CurrentDate;
            ob.ApprovedBy    = Convert.ToInt32(CurrentUID);
            ob.QuotationId   = 0;

            try
            {
                if (ob.TblQuotationDetail != null && ob.TblQuotationDetail.Count > 0)
                {
                    foreach (TblQuotationDetail detail in ob.TblQuotationDetail)
                    {
                        detail.QuotationId = ob.QuotationId;
                        detail.Id          = 0;
                    }
                }


                uow.Modules.Quotation.Set(ob);



                objOrg.StatusId = 9;
                uow.Modules.Quotation.Set(objOrg);
                uow.SaveChanges();

                /*
                 *              if (ob.TblQuotationDetail != null && ob.TblQuotationDetail.Count > 0)
                 *              {
                 *                  foreach (TblQuotationDetail detail in ob.TblQuotationDetail)
                 *                  {
                 *
                 *                      detail.QuotationId = ob.QuotationId;
                 *                      detail.Id = 0;
                 *                  }
                 *              }
                 *
                 *              uow.Modules.QuotationDetail.Set(ob.TblQuotationDetail.ToList());
                 *              uow.SaveChanges();
                 */


                return(RedirectToAction("Detail", MVCController, new { id = ob.QuotationId, msg = "บันทึกข้อมูลเรียบร้อยแล้ว", msgType = AlertMsgType.Success }));
            }
            catch (Exception ex)
            {
                string msg = ex.GetMessage(true);
                return(ViewDetail(ob, msg, AlertMsgType.Danger));
            }
        }
Beispiel #10
0
        public ActionResult QT2SO()
        {
            int sid = 0;

            if (string.IsNullOrEmpty(Request.Form["lbSaleOrderId"]))
            {
                sid = Request.Form["lbSaleOrderId"].ParseInt();
            }
            else
            {
                TblSaleOrder ob  = uow.Modules.SaleOrder.Get(sid);
                string       pre = Request.Form["lbPreSONo"];
                ob.SaleOrderNo   = genSaleOrderId(pre);
                ob.CreatedBy     = CurrentUID;
                ob.UpdatedBy     = CurrentUID;
                ob.CreatedDate   = CurrentDate;
                ob.UpdateDate    = CurrentDate;
                ob.SaleOrderDate = CurrentDate;
                ob.CustomerId    = 1;
                ob.SaleId        = 1;
                ob.StatusId      = 1;
                ob.ConditionId   = 1;
                uow.Modules.SaleOrder.Set(ob);
                uow.SaveChanges();

                sid = ob.SaleOrderId;
            }
            if (sid > 0)
            {
                string qno = Request.Form["lbQuotationId"];

                TblSaleOrder so  = uow.Modules.SaleOrder.Get(sid);
                var          qid = uow.Modules.Quotation.GetId(qno);
                TblQuotation qt  = uow.Modules.Quotation.Get(qid);
                List <TblQuotationDetail> qtd = uow.Modules.QuotationDetail.Gets(qid)
                                                .OrderBy(c => c.Id).ToList();


                // clear saleorderdetail
                uow.Modules.SaleOrderDetail.DeleteId(sid);
                //  uow.SaveChanges();

                // set QT to SO
                so.QuotationNo     = qno;
                so.CustomerId      = qt.CustomerId;
                so.CustomerName    = qt.CustomerName;
                so.ContractName    = qt.ContractName;
                so.SaleId          = qt.SaleId;
                so.SaleName        = qt.SaleName;
                so.BillingAddress  = qt.BillingAddress;
                so.ShippingAddress = qt.ShippingAddress;
                so.SaleOrderRemark = qt.QuotationRemark;
                so.SubTotalNet     = qt.SubTotalNet;
                so.SubTotalTot     = qt.SubTotalTot;
                so.SubTotalVat     = qt.SubTotalVat;
                so.DiscountCash    = qt.DiscountCash;
                so.DiscountNet     = qt.DiscountNet;
                so.DiscountTot     = qt.DiscountTot;
                so.DiscountVat     = qt.DiscountVat;
                so.SummaryNet      = qt.SummaryNet;
                so.SummaryTot      = qt.SummaryTot;
                so.SummaryVat      = qt.SummaryVat;

                uow.Modules.SaleOrder.Set(so);
                // uow.SaveChanges();


                //Add QT detail to SO detail
                if (qtd.Count() > 0)
                {
                    qtd.ForEach(dt =>
                    {
                        TblSaleOrderDetail sod = uow.Modules.SaleOrderDetail.Get(0);
                        sod.SaleOrderId        = sid;
                        sod.ProductId          = dt.ProductId;
                        sod.Quantity           = dt.Quantity;
                        sod.PriceNet           = dt.PriceNet;
                        sod.PriceVat           = dt.PriceVat;
                        sod.PriceTot           = dt.PriceTot;
                        sod.DiscountNet        = dt.DiscountNet;
                        sod.DiscountTot        = dt.DiscountTot;
                        sod.DiscountVat        = dt.DiscountVat;
                        sod.TotalNet           = dt.TotalNet;
                        sod.TotalTot           = dt.TotalTot;
                        sod.TotalVat           = dt.TotalVat;
                        uow.Modules.SaleOrderDetail.Set(sod);
                    });
                }

                uow.SaveChanges();
            }
            return(RedirectToAction("Detail", MVCController, new { id = sid, msg = "", msgType = AlertMsgType.Success }));
        }
Beispiel #11
0
        public ActionResult SetDetail()
        {
            bool         addQuotationDetail = false;
            int          id            = Request.Form["SaleOrderId"].ParseInt();
            int          approveStatus = Request.Form["hdApprove"] != null ? Request.Form["hdApprove"].ParseInt() : 0;
            TblSaleOrder ob            = uow.Modules.SaleOrder.Get(id);

            if (ob.SaleOrderId <= 0)
            {
                string pre = Request.Form["SaleOrderPreNo"];
                ob.SaleOrderNo     = genSaleOrderId(pre);
                ob.CreatedBy       = CurrentUID;
                ob.UpdatedBy       = CurrentUID;
                ob.CreatedDate     = CurrentDate;
                ob.UpdatedDate     = CurrentDate;
                ob.SaleOrderDate   = CurrentDate;
                addQuotationDetail = true;
            }
            else
            {
                ob.UpdatedBy   = CurrentUID;
                ob.UpdatedDate = CurrentDate;
            }


            if (approveStatus == 3)
            {
                ob.ApprovedBy = Convert.ToInt32(CurrentUID);
            }

            ob.QuotationNo = Request.Form["QuotationNo"];
            ob.SaleId      = Request.Form["SaleId"] != null ? Request.Form["SaleId"].ParseInt() : 0;
            ob.SaleName    = Request.Form["SaleName"];
            if (Request.Form["DeliveryDate"].ToString().Count() > 0)
            {
                var dd = Request.Form["DeliveryDate"].Split(' ')[0] + " 00:00:00";

                ob.DeliveryDate = dd.ParseDate(DateFormat.ddMMyyyyHHmmss);
            }

            ob.CustomerId   = Request.Form["CustomerId"].ParseInt();
            ob.CustomerName = Request.Form["CustomerName"];

            ob.ContractName   = Request.Form["ContractName"];
            ob.BillingAddress = Request.Form["BillingAddress"];

            ob.ShippingAddress = Request.Form["ShippingAddress"];
            ob.SaleOrderRemark = Request.Form["SaleOrderRemark"];
            ob.TeamId          = Request.Form["TeamId"].ParseInt();
            if (Request.Form["DiscountCash"] != null)
            {
                ob.DiscountCash = decimal.Parse(Request.Form["DiscountCash"]);
            }

            ob.SaleOrderCreditDay = Request.Form["SaleOrderCreditDay"].ParseInt();

            ob.StatusId    = Request.Form["StatusId"].ParseInt();
            ob.ConditionId = Request.Form["ConditionId"].ParseInt();
            try
            {
                uow.Modules.SaleOrder.Set(ob);
                uow.SaveChanges();

                id = ob.SaleOrderId;
                if (id > 0 && addQuotationDetail)
                {
                    string qno = Request.Form["QuotationNo"];

                    TblSaleOrder so  = uow.Modules.SaleOrder.Get(id);
                    var          qid = uow.Modules.Quotation.GetId(qno);
                    TblQuotation qt  = uow.Modules.Quotation.Get(qid);
                    List <TblQuotationDetail> qtd = uow.Modules.QuotationDetail.Gets(qid)
                                                    .OrderBy(c => c.Id).ToList();


                    // clear saleorderdetail
                    uow.Modules.SaleOrderDetail.DeleteId(id);
                    //  uow.SaveChanges();

                    // set QT to SO
                    so.QuotationNo        = qno;
                    so.CustomerId         = qt.CustomerId;
                    so.CustomerName       = qt.CustomerName;
                    so.ContractName       = qt.ContractName;
                    so.SaleId             = qt.SaleId;
                    so.SaleName           = qt.SaleName;
                    so.BillingAddress     = qt.BillingAddress;
                    so.ShippingAddress    = qt.ShippingAddress;
                    so.SaleOrderRemark    = qt.QuotationRemark;
                    so.SubTotalNet        = qt.SubTotalNet;
                    so.SubTotalTot        = qt.SubTotalTot;
                    so.SubTotalVat        = qt.SubTotalVat;
                    so.DiscountCash       = qt.DiscountCash;
                    so.DiscountNet        = qt.DiscountNet;
                    so.DiscountTot        = qt.DiscountTot;
                    so.DiscountVat        = qt.DiscountVat;
                    so.SummaryNet         = qt.SummaryNet;
                    so.SummaryTot         = qt.SummaryTot;
                    so.SummaryVat         = qt.SummaryVat;
                    so.SaleOrderCreditDay = qt.QuotationCreditDay;
                    uow.Modules.SaleOrder.Set(so);
                    // uow.SaveChanges();


                    //Add QT detail to SO detail
                    if (qtd.Count() > 0)
                    {
                        qtd.ForEach(dt =>
                        {
                            TblSaleOrderDetail sod = uow.Modules.SaleOrderDetail.Get(0);
                            sod.SaleOrderId        = id;
                            sod.ProductId          = dt.ProductId;
                            sod.Quantity           = dt.Quantity;
                            sod.PriceUnit          = dt.PriceUnit;
                            sod.PriceNet           = dt.PriceNet;
                            sod.PriceVat           = dt.PriceVat;
                            sod.PriceTot           = dt.PriceTot;
                            sod.DiscountNet        = dt.DiscountNet;
                            sod.DiscountTot        = dt.DiscountTot;
                            sod.DiscountVat        = dt.DiscountVat;
                            sod.TotalNet           = dt.TotalNet;
                            sod.TotalTot           = dt.TotalTot;
                            sod.TotalVat           = dt.TotalVat;
                            uow.Modules.SaleOrderDetail.Set(sod);
                        });
                    }

                    uow.SaveChanges();
                }

                if (ob.StatusId == 2)
                {
                    uow.Modules.SaleOrder.SaleOrderStockApprove(ob.SaleOrderId);
                }


                return(RedirectToAction("Detail", MVCController, new { id = ob.SaleOrderId, msg = "บันทึกข้อมูลเรียบร้อยแล้ว", msgType = AlertMsgType.Success }));
            }
            catch (Exception ex)
            {
                string msg = ex.GetMessage(true);
                return(ViewDetail(ob, msg, AlertMsgType.Danger));
            }
        }
Beispiel #12
0
        public ActionResult QT2SO()
        {
            int sid = 0;


            if (!string.IsNullOrEmpty(Request.Form["lbSaleOrderId"]))
            {
                sid = Request.Form["lbSaleOrderId"].ParseInt();
                TblSaleOrder ob = uow.Modules.SaleOrder.Get(sid);

                if (ob.SaleOrderId <= 0)
                {
                    string pre = Request.Form["SaleOrderPreNo"];
                    ob.SaleOrderNo   = genSaleOrderId(pre);
                    ob.CreatedBy     = CurrentUID;
                    ob.UpdatedBy     = CurrentUID;
                    ob.CreatedDate   = CurrentDate;
                    ob.UpdatedDate   = CurrentDate;
                    ob.SaleOrderDate = CurrentDate;
                }
                else
                {
                    ob.UpdatedBy   = CurrentUID;
                    ob.UpdatedDate = CurrentDate;
                }

                ob.QuotationNo = Request.Form["QuotationNo"];
                ob.SaleId      = Request.Form["SaleId"] != null ? Request.Form["SaleId"].ParseInt() : 0;
                ob.SaleName    = Request.Form["SaleName"];
                if (Request.Form["DeliveryDate"].ToString().Count() > 0)
                {
                    var dd = Request.Form["DeliveryDate"].Split(' ')[0] + " 00:00:00";

                    ob.DeliveryDate = dd.ParseDate(DateFormat.ddMMyyyyHHmmss);
                }
                TblQuotation quotation = uow.Modules.Quotation.Get(ob.QuotationNo);

                ob.CustomerId         = quotation.CustomerId;
                ob.CustomerName       = quotation.CustomerName;
                ob.SaleOrderCreditDay = quotation.QuotationCreditDay;
                ob.ContractName       = quotation.ContractName;
                ob.BillingAddress     = quotation.BillingAddress;

                ob.ShippingAddress = quotation.ShippingAddress;
                ob.SaleOrderRemark = Request.Form["SaleOrderRemark"];
                ob.TeamId          = Request.Form["TeamId"].ParseInt();
                if (Request.Form["DiscountCash"] != null)
                {
                    ob.DiscountCash = decimal.Parse(Request.Form["DiscountCash"]);
                }

                ob.SaleOrderCreditDay = Request.Form["SaleOrderCreditDay"].ParseInt();

                ob.StatusId    = Request.Form["StatusId"].ParseInt();
                ob.ConditionId = Request.Form["ConditionId"].ParseInt();


                uow.Modules.SaleOrder.Set(ob);
                uow.SaveChanges();
                sid = ob.SaleOrderId;
            }
            else if (Request.Form["lbSaleOrderId"] == "")
            {
            }
            else
            {
                TblSaleOrder ob  = uow.Modules.SaleOrder.Get(sid);
                string       pre = Request.Form["lbPreSONo"];
                ob.SaleOrderNo   = genSaleOrderId(pre);
                ob.CreatedBy     = CurrentUID;
                ob.UpdatedBy     = CurrentUID;
                ob.CreatedDate   = CurrentDate;
                ob.UpdatedDate   = CurrentDate;
                ob.SaleOrderDate = CurrentDate;
                ob.CustomerId    = 1;
                ob.SaleId        = 1;
                ob.StatusId      = 1;
                ob.ConditionId   = 1;

                uow.Modules.SaleOrder.Set(ob);
                uow.SaveChanges();

                sid = ob.SaleOrderId;
            }


            if (sid > 0)
            {
                string qno = Request.Form["QuotationNo"];

                TblSaleOrder so  = uow.Modules.SaleOrder.Get(sid);
                var          qid = uow.Modules.Quotation.GetId(qno);
                TblQuotation qt  = uow.Modules.Quotation.Get(qid);
                List <TblQuotationDetail> qtd = uow.Modules.QuotationDetail.Gets(qid)
                                                .OrderBy(c => c.Id).ToList();


                // clear saleorderdetail
                uow.Modules.SaleOrderDetail.DeleteId(sid);
                //  uow.SaveChanges();

                // set QT to SO
                so.QuotationNo     = qno;
                so.CustomerId      = qt.CustomerId;
                so.CustomerName    = qt.CustomerName;
                so.ContractName    = qt.ContractName;
                so.SaleId          = qt.SaleId;
                so.SaleName        = qt.SaleName;
                so.BillingAddress  = qt.BillingAddress;
                so.ShippingAddress = qt.ShippingAddress;
                so.SaleOrderRemark = qt.QuotationRemark;
                so.SubTotalNet     = qt.SubTotalNet;
                so.SubTotalTot     = qt.SubTotalTot;
                so.SubTotalVat     = qt.SubTotalVat;
                so.DiscountCash    = qt.DiscountCash;
                so.DiscountNet     = qt.DiscountNet;
                so.DiscountTot     = qt.DiscountTot;
                so.DiscountVat     = qt.DiscountVat;
                so.SummaryNet      = qt.SummaryNet;
                so.SummaryTot      = qt.SummaryTot;
                so.SummaryVat      = qt.SummaryVat;
                so.SaleOrderRemark = qt.QuotationRemark;

                uow.Modules.SaleOrder.Set(so);
                // uow.SaveChanges();


                //Add QT detail to SO detail
                if (qtd.Count() > 0)
                {
                    qtd.ForEach(dt =>
                    {
                        TblSaleOrderDetail sod = uow.Modules.SaleOrderDetail.Get(0);
                        sod.SaleOrderId        = sid;
                        sod.ProductId          = dt.ProductId;
                        sod.WHId        = dt.WHId;
                        sod.Quantity    = dt.Quantity;
                        sod.PriceUnit   = dt.PriceUnit;
                        sod.PriceNet    = dt.PriceNet;
                        sod.PriceVat    = dt.PriceVat;
                        sod.PriceTot    = dt.PriceTot;
                        sod.DiscountNet = dt.DiscountNet;
                        sod.DiscountTot = dt.DiscountTot;
                        sod.DiscountVat = dt.DiscountVat;
                        sod.TotalNet    = dt.TotalNet;
                        sod.TotalTot    = dt.TotalTot;
                        sod.TotalVat    = dt.TotalVat;
                        sod.Remark      = dt.Remark;
                        uow.Modules.SaleOrderDetail.Set(sod);
                    });
                }

                uow.SaveChanges();
            }
            return(RedirectToAction("Detail", MVCController, new { id = sid, msg = "", msgType = AlertMsgType.Success }));
        }