Exemplo n.º 1
0
        public bool UpdateQuotation(DeliveryReturn deliveryreturns, IList <DeliveryReturnItems> deliveryreturnItemList, ref string ErrorMessage)
        {
            ErrorMessage = string.Empty;
            try
            {
                deliveryreturn.Entry(deliveryreturns).State = EntityState.Modified;
                deliveryreturn.SaveChanges();

                foreach (var model in deliveryreturnItemList)
                {
                    if (model.IsDummy == 1)
                    {
                        deliveryreturn.Entry(model).State = EntityState.Deleted;
                        deliveryreturn.SaveChanges();
                    }
                    else
                    {
                        if (model.Delivery_Return_Items_Id == 0)
                        {
                            model.Delivery_Return_Id = deliveryreturns.Delivery_Return_Id;
                            deliveryreturn.deliveryreturnitem.Add(model);
                            deliveryreturn.SaveChanges();
                        }
                        else
                        {
                            deliveryreturn.Entry(model).State = EntityState.Modified;
                            deliveryreturn.SaveChanges();
                        }
                    }
                }

                return(true);
            }
            catch (DbEntityValidationException dbEx)
            {
                var errorList = new List <string>();

                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        errorList.Add(String.Format("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage));
                    }
                }
                return(false);
            }
        }
Exemplo n.º 2
0
        public bool AddNewQuotation(DeliveryReturn Deliveryreturn, IList <DeliveryReturnItems> DeliveryreturnItemList, ref string ErrorMessage)
        {
            ErrorMessage = string.Empty;
            try
            {
                deliveryreturn.deliveryreturn.Add(Deliveryreturn);
                deliveryreturn.SaveChanges();

                int currentId = Deliveryreturn.Delivery_Return_Id;

                for (int i = 0; i < DeliveryreturnItemList.Count; i++)
                {
                    DeliveryreturnItemList[i].Delivery_Return_Id = currentId;
                }

                deliveryreturn.deliveryreturnitem.AddRange(DeliveryreturnItemList);

                deliveryreturn.SaveChanges();

                return(true);
            }

            catch (DbEntityValidationException dbEx)
            {
                var errorList = new List <string>();

                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        errorList.Add(String.Format("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage));
                    }
                }
                return(false);
            }
            //catch (Exception ex)
            //{
            //    ExceptionHandler.LogException(ex);
            //    ErrorMessage = ex.Message;
            //    return false;
            //}
        }
Exemplo n.º 3
0
        public ActionResult Index(string submitButton, DeliveryReturnViewModels model, HttpPostedFileBase file = null)
        {
            try
            {
                if (submitButton == "Save")
                {
                    model.deliveryreturn.TargetDocId       = "0";
                    model.deliveryreturn.Remarks           = "hi";
                    model.deliveryreturn.Doc_Status        = "Open";
                    model.deliveryreturn.Created_Branc_Id  = CurrentBranchId;//CurrentBranchId;
                    model.deliveryreturn.Created_Date      = DateTime.Now;
                    model.deliveryreturn.BaseDocId         = model.salesdelivery.BaseDocId;
                    model.deliveryreturn.Created_User_Id   = CurrentUser.Id;//CurrentUser.Id;
                    model.deliveryreturn.Sales_Delivery_Id = model.salesdelivery.Sales_Delivery_Id;
                    model.deliveryreturn.Customer          = model.salesdelivery.Customer;
                    model.deliveryreturn.Doc_Status        = model.salesdelivery.Doc_Status;
                    model.deliveryreturn.Posting_Date      = model.salesdelivery.Posting_Date;
                    model.deliveryreturn.Document_Date     = model.salesdelivery.Posting_Date;
                    model.deliveryreturn.Delivery_Date     = model.salesdelivery.Delivery_Date;
                    //model.deliveryreturn.Document_Date = model.salesdelivery.Document_Date;
                    model.deliveryreturn.Branch           = model.salesdelivery.Branch;
                    model.deliveryreturn.TotalBefDocDisc  = model.salesdelivery.TotalBefDocDisc;
                    model.deliveryreturn.DocDiscAmt       = model.salesdelivery.DocDiscAmt;
                    model.deliveryreturn.TaxAmt           = model.salesdelivery.TaxAmt;
                    model.deliveryreturn.TotalSlsDlvryAmt = model.salesdelivery.TotalSlsDlvryAmt;
                    model.deliveryreturn.Reference_Number = model.salesdelivery.Reference_Number;



                    var GoodsList = model.deliveryreturnitemlist.Where(x => x.IsDummy == 0);
                    model.deliveryreturnitemlist = GoodsList.ToList();

                    for (int i = 0; i < model.deliveryreturnitemlist.Count; i++)
                    {
                        model.deliveryreturnitemlist[i].BaseDocLink      = "Y";
                        model.deliveryreturnitemlist[i].Product_Id       = model.salesdeliverytitemlist[i].Product_Id;
                        model.deliveryreturnitemlist[i].Quantity         = model.salesdeliverytitemlist[i].Quantity;
                        model.deliveryreturnitemlist[i].Unit_Price       = model.salesdeliverytitemlist[i].Unit_Price;
                        model.deliveryreturnitemlist[i].Discount_Precent = model.salesdeliverytitemlist[i].Discount_Precent;
                        model.deliveryreturnitemlist[i].Vat_Code         = model.salesdeliverytitemlist[i].Vat_Code;
                        //   model.deliveryreturnitemlist[i].Freight_Loading = model.goodreceiptitemlist[i].Freight_Loading;
                        model.deliveryreturnitemlist[i].LineTotal = model.salesdeliverytitemlist[i].LineTotal;
                    }

                    if (deliveryreturnrepository.AddNewQuotation(model.deliveryreturn, model.deliveryreturnitemlist, ref ErrorMessage))
                    {
                        model.salesdelivery = deliveryreturnrepository.FindOneQuotationById1(model.salesdelivery.Sales_Delivery_Id);

                        model.salesdeliverytitemlist = deliveryreturnrepository.FindOneQuotationItemById1(model.salesdelivery.Sales_Delivery_Id);
                        for (int k = 0; k < model.salesdeliverytitemlist.Count; k++)
                        {
                            if (model.salesdeliverytitemlist[k].Product_Id == model.salesdeliverytitemlist[k].Product_Id && model.salesdeliverytitemlist[k].Return_Qty >= model.salesdeliverytitemlist[k].Quantity)
                            {
                                model.salesdelivery.Doc_Status = "Closed";
                                //model1.PurchaseOrder.TargetDocId = Convert.ToString(model.PurchaseOrder.Purchase_Order_Id);
                                if (model.salesdelivery.TargetDocId == "")
                                {
                                    model.salesdelivery.TargetDocId = Convert.ToString(model.salesdelivery.Sales_Order_Id);
                                }
                                else
                                {
                                    model.salesdelivery.TargetDocId = model.salesdelivery.TargetDocId + "," + Convert.ToString(model.salesdelivery.Sales_Order_Id);
                                }

                                model.salesdeliverytitemlist[k].BaseDocLink       = "N";
                                model.salesdeliverytitemlist[k].sales_Item_Id     = model.salesdeliverytitemlist[k].sales_Item_Id;
                                model.salesdeliverytitemlist[k].Sales_Delivery_Id = model.salesdeliverytitemlist[k].Sales_Delivery_Id;
                                //model1.PurchaseOrderItemsList[j].Quoted_date = model1.PurchaseOrderItemsList[j].Quoted_date;
                                model.salesdeliverytitemlist[k].Quantity         = Convert.ToInt32(model.salesdeliverytitemlist[k].Return_Qty);
                                model.salesdeliverytitemlist[k].Product_Id       = model.salesdeliverytitemlist[k].Product_Id;
                                model.salesdeliverytitemlist[k].Unit_Price       = model.salesdeliverytitemlist[k].Unit_Price;
                                model.salesdeliverytitemlist[k].Discount_Precent = model.salesdeliverytitemlist[k].Discount_Precent;
                                model.salesdeliverytitemlist[k].Vat_Code         = model.salesdeliverytitemlist[k].Vat_Code;
                            }
                            else if (model.salesdeliverytitemlist[k].Product_Id == model.salesdeliverytitemlist[k].Product_Id && model.salesdeliverytitemlist[k].Return_Qty < model.salesdeliverytitemlist[k].Quantity)
                            {
                                model.salesdelivery.Doc_Status  = "Open";
                                model.salesdelivery.TargetDocId = Convert.ToString(model.salesdelivery.Sales_Order_Id);

                                model.salesdeliverytitemlist[k].BaseDocLink       = "N";
                                model.salesdeliverytitemlist[k].sales_Item_Id     = model.salesdeliverytitemlist[k].sales_Item_Id;
                                model.salesdeliverytitemlist[k].Sales_Delivery_Id = model.salesdeliverytitemlist[k].Sales_Delivery_Id;
                                //model1.PurchaseOrderItemsList[j].Quoted_date = model1.PurchaseOrderItemsList[j].Quoted_date;
                                model.salesdeliverytitemlist[k].Quantity         = Convert.ToInt32(model.salesdeliverytitemlist[k].Return_Qty);
                                model.salesdeliverytitemlist[k].Product_Id       = model.salesdeliverytitemlist[k].Product_Id;
                                model.salesdeliverytitemlist[k].Unit_Price       = model.salesdeliverytitemlist[k].Unit_Price;
                                model.salesdeliverytitemlist[k].Discount_Precent = model.salesdeliverytitemlist[k].Discount_Precent;
                                model.salesdeliverytitemlist[k].Vat_Code         = model.salesdeliverytitemlist[k].Vat_Code;
                            }
                        }

                        //model1.PurchaseOrder.Creating_Branch = 1;
                        model.salesdelivery.Created_Branc_Id  = CurrentBranchId; //currentUser.Created_Branch_Id;
                        model.salesdelivery.Created_Date      = DateTime.Now;
                        model.salesdelivery.Created_User_Id   = CurrentUser.Id;  //currentUser.Created_User_Id;  //GetUserId()
                        model.salesdelivery.Modified_User_Id  = CurrentUser.Id;  //currentUser.Modified_User_Id;
                        model.salesdelivery.Modified_Date     = DateTime.Now;
                        model.salesdelivery.Modified_Branc_Id = CurrentBranchId; //currentUser.Modified_Branch_Id;



                        deliveryreturnrepository.UpdateQuotationreceipt(model.salesdelivery, model.salesdeliverytitemlist, ref ErrorMessage);
                        return(RedirectToAction("Index", "DeliveryReturns"));
                    }
                    else
                    {
                        ViewBag.AppErrorMessage = ErrorMessage;
                        return(View("Error"));
                    }
                }
                else if (submitButton == "Update")
                {
                    model.deliveryreturn.TargetDocId       = "0";
                    model.deliveryreturn.Remarks           = "hi";
                    model.deliveryreturn.Modified_Branc_Id = CurrentBranchId; //CurrentBranchId;
                    model.deliveryreturn.Modified_Date     = DateTime.Now;
                    model.deliveryreturn.Modified_User_Id  = CurrentUser.Id;  //CurrentUser.Id;


                    for (int i = 0; i < model.deliveryreturnitemlist.Count; i++)
                    {
                        model.deliveryreturnitemlist[i].Delivery_Return_Id = model.deliveryreturn.Delivery_Return_Id;
                        model.deliveryreturnitemlist[i].BaseDocLink        = "N";
                    }
                    if (deliveryreturnrepository.UpdateQuotation(model.deliveryreturn, model.deliveryreturnitemlist, ref ErrorMessage))
                    {
                        return(RedirectToAction("Index", "DeliveryReturns"));
                    }
                    else
                    {
                        ViewBag.AppErrorMessage = ErrorMessage;
                        return(View("Error"));
                    }
                }

                return(RedirectToAction("Index", "DeliveryReturns"));
            }
            catch (OptimisticConcurrencyException ex)
            {
                ObjectStateEntry entry = ex.StateEntries[0];
                DeliveryReturn   post  = entry.Entity as DeliveryReturn; //Post is the entity name he is using. Rename it with yours
                Console.WriteLine("Failed to save {0} because it was changed in the database", post.Delivery_Return_Id);
                return(View("Error"));
            }
            //catch (Exception ex)
            //{
            //    ExceptionHandler.LogException(ex);
            //    ViewBag.AppErrorMessage = ex.Message;
            //    return View("Error");
            //}
        }