示例#1
0
        public ActionResult _Create(int Id, bool?IsSaleBased)  //Id ==>Sale Order Header Id
        {
            SaleInvoiceHeader H = new SaleInvoiceHeaderService(_unitOfWork).FindDirectSaleInvoice(Id);
            DirectSaleInvoiceLineViewModel s = new DirectSaleInvoiceLineViewModel();



            //Getting Settings
            var settings = new SaleInvoiceSettingService(_unitOfWork).GetSaleInvoiceSettingForDocument(H.DocTypeId, H.DivisionId, H.SiteId);

            s.SaleInvoiceSettings = Mapper.Map <SaleInvoiceSetting, SaleInvoiceSettingsViewModel>(settings);

            s.DocumentTypeSettings = new DocumentTypeSettingsService(_unitOfWork).GetDocumentTypeSettingsForDocument(H.DocTypeId);

            s.IsSaleBased            = IsSaleBased;
            s.SaleInvoiceHeaderId    = H.SaleInvoiceHeaderId;
            s.SaleInvoiceHeaderDocNo = H.DocNo;
            s.DocTypeId  = H.DocTypeId;
            s.SiteId     = H.SiteId;
            s.DivisionId = H.DivisionId;


            ViewBag.LineMode = "Create";
            PrepareViewBag();
            return(PartialView("_Create", s));
        }
示例#2
0
        private ActionResult _Delete(int id)
        {
            SaleInvoiceLine temp = _SaleInvoiceLineService.Find(id);

            if (temp == null)
            {
                return(HttpNotFound());
            }

            #region DocTypeTimeLineValidation
            try
            {
                TimePlanValidation = DocumentValidation.ValidateDocumentLine(new DocumentUniqueId {
                    LockReason = temp.LockReason
                }, User.Identity.Name, out ExceptionMsg, out Continue);
            }
            catch (Exception ex)
            {
                string message = _exception.HandleException(ex);
                TempData["CSEXCL"] += message;
                TimePlanValidation  = false;
            }

            if (!TimePlanValidation)
            {
                TempData["CSEXCL"] += ExceptionMsg;
            }
            #endregion

            if ((TimePlanValidation || Continue))
            {
                ViewBag.LineMode = "Delete";
            }


            SaleInvoiceHeader H = new SaleInvoiceHeaderService(_unitOfWork).FindDirectSaleInvoice(temp.SaleInvoiceHeaderId);
            PrepareViewBag();

            DirectSaleInvoiceLineViewModel vm = _SaleInvoiceLineService.GetDirectSaleInvoiceLineForEdit(id);
            //Getting Settings
            var settings = new SaleInvoiceSettingService(_unitOfWork).GetSaleInvoiceSettingForDocument(H.DocTypeId, H.DivisionId, H.SiteId);

            vm.SaleInvoiceSettings  = Mapper.Map <SaleInvoiceSetting, SaleInvoiceSettingsViewModel>(settings);
            vm.DocumentTypeSettings = new DocumentTypeSettingsService(_unitOfWork).GetDocumentTypeSettingsForDocument(H.DocTypeId);

            return(PartialView("_Create", vm));
        }
示例#3
0
        public ActionResult _Detail(int id)
        {
            SaleInvoiceLine   temp = _SaleInvoiceLineService.Find(id);
            SaleInvoiceHeader H    = new SaleInvoiceHeaderService(_unitOfWork).FindDirectSaleInvoice(temp.SaleInvoiceHeaderId);

            PrepareViewBag();

            DirectSaleInvoiceLineViewModel vm = _SaleInvoiceLineService.GetDirectSaleInvoiceLineForEdit(id);
            //Getting Settings
            var settings = new SaleInvoiceSettingService(_unitOfWork).GetSaleInvoiceSettingForDocument(H.DocTypeId, H.DivisionId, H.SiteId);

            vm.SaleInvoiceSettings = Mapper.Map <SaleInvoiceSetting, SaleInvoiceSettingsViewModel>(settings);

            if (temp == null)
            {
                return(HttpNotFound());
            }
            return(PartialView("_Create", vm));
        }
示例#4
0
        public ActionResult DeletePost(DirectSaleInvoiceLineViewModel vm)
        {
            List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();

            SaleInvoiceHeader Sh = new SaleInvoiceHeaderService(_unitOfWork).FindDirectSaleInvoice(vm.SaleInvoiceHeaderId);

            int status = Sh.Status;

            SaleInvoiceLine       Sl  = _SaleInvoiceLineService.Find(vm.SaleInvoiceLineId);
            SaleInvoiceLineDetail Sid = _SaleInvoiceLineDetailService.Find(vm.SaleInvoiceLineId);

            LogList.Add(new LogTypeViewModel
            {
                ExObj = Sl,
            });


            _SaleInvoiceLineDetailService.Delete(Sid);
            _SaleInvoiceLineService.Delete(Sl);



            if (Sh.Status != (int)StatusConstants.Drafted)
            {
                Sh.Status = (int)StatusConstants.Modified;
                new SaleInvoiceHeaderService(_unitOfWork).Update(Sh);
            }

            var chargeslist = new SaleInvoiceLineChargeService(_unitOfWork).GetCalculationProductList(vm.SaleInvoiceLineId);

            if (chargeslist != null)
            {
                foreach (var item in chargeslist)
                {
                    new SaleInvoiceLineChargeService(_unitOfWork).Delete(item.Id);
                }
            }

            if (vm.footercharges != null)
            {
                foreach (var item in vm.footercharges)
                {
                    var footer = new SaleInvoiceHeaderChargeService(_unitOfWork).Find(item.Id);
                    footer.Rate   = item.Rate;
                    footer.Amount = item.Amount;
                    new SaleInvoiceHeaderChargeService(_unitOfWork).Update(footer);
                }
            }
            XElement Modifications = new ModificationsCheckService().CheckChanges(LogList);

            try
            {
                _unitOfWork.Save();
            }

            catch (Exception ex)
            {
                string message = _exception.HandleException(ex);
                TempData["CSEXCL"] += message;
                PrepareViewBag();
                return(PartialView("_Create", vm));
            }

            LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
            {
                DocTypeId       = Sh.DocTypeId,
                DocId           = Sh.SaleInvoiceHeaderId,
                DocLineId       = Sl.SaleInvoiceLineId,
                ActivityType    = (int)ActivityTypeContants.Deleted,
                DocNo           = Sh.DocNo,
                xEModifications = Modifications,
                DocDate         = Sh.DocDate,
                DocStatus       = Sh.Status,
            }));

            return(Json(new { success = true }));
        }
示例#5
0
        //[ValidateAntiForgeryToken]
        public ActionResult _CreatePost(DirectSaleInvoiceLineViewModel svm)
        {
            SaleInvoiceHeader Sh = new SaleInvoiceHeaderService(_unitOfWork).FindDirectSaleInvoice(svm.SaleInvoiceHeaderId);

            if (svm.SaleInvoiceLineId <= 0)
            {
                ViewBag.LineMode = "Create";
            }
            else
            {
                ViewBag.LineMode = "Edit";
            }

            if (svm.SaleDispatchLineId <= 0)
            {
                ModelState.AddModelError("SaleDispatchLineId", "Sale Dispatch field is required");
            }

            if (svm.Qty <= 0)
            {
                ModelState.AddModelError("Qty", "The Qty field is required");
            }

            if (ModelState.IsValid)
            {
                if (svm.SaleInvoiceLineId <= 0)
                {
                    SaleInvoiceLine       Sl  = Mapper.Map <DirectSaleInvoiceLineViewModel, SaleInvoiceLine>(svm);
                    SaleInvoiceLineDetail Sid = Mapper.Map <DirectSaleInvoiceLineViewModel, SaleInvoiceLineDetail>(svm);

                    Sl.SaleDispatchLineId  = svm.SaleDispatchLineId;
                    Sl.SaleInvoiceHeaderId = Sh.SaleInvoiceHeaderId;
                    Sl.DiscountPer         = svm.DiscountPer;
                    Sl.Sr           = _SaleInvoiceLineService.GetMaxSr(Sh.SaleInvoiceHeaderId);
                    Sl.CreatedDate  = DateTime.Now;
                    Sl.ModifiedDate = DateTime.Now;
                    Sl.CreatedBy    = User.Identity.Name;
                    Sl.ModifiedBy   = User.Identity.Name;
                    Sl.ObjectState  = Model.ObjectState.Added;
                    _SaleInvoiceLineService.Create(Sl);

                    Sid.SaleInvoiceLineId = Sl.SaleInvoiceLineId;
                    _SaleInvoiceLineDetailService.Create(Sid);



                    if (svm.linecharges != null)
                    {
                        foreach (var item in svm.linecharges)
                        {
                            item.LineTableId   = Sl.SaleInvoiceLineId;
                            item.PersonID      = Sh.BillToBuyerId;
                            item.HeaderTableId = Sh.SaleInvoiceHeaderId;
                            item.ObjectState   = Model.ObjectState.Added;
                            new SaleInvoiceLineChargeService(_unitOfWork).Create(item);
                        }
                    }

                    if (svm.footercharges != null)
                    {
                        foreach (var item in svm.footercharges)
                        {
                            if (item.Id > 0)
                            {
                                var footercharge = new SaleInvoiceHeaderChargeService(_unitOfWork).Find(item.Id);
                                footercharge.Rate   = item.Rate;
                                footercharge.Amount = item.Amount;
                                new SaleInvoiceHeaderChargeService(_unitOfWork).Update(footercharge);
                            }

                            else
                            {
                                item.HeaderTableId = Sh.SaleInvoiceHeaderId;
                                item.PersonID      = Sh.BillToBuyerId;
                                item.ObjectState   = Model.ObjectState.Added;
                                new SaleInvoiceHeaderChargeService(_unitOfWork).Create(item);
                            }
                        }
                    }



                    if (Sh.Status != (int)StatusConstants.Drafted)
                    {
                        Sh.Status = (int)StatusConstants.Modified;
                        new SaleInvoiceHeaderService(_unitOfWork).Update(Sh);
                    }

                    try
                    {
                        _unitOfWork.Save();
                    }

                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        TempData["CSEXCL"] += message;
                        PrepareViewBag();
                        return(PartialView("_Create", svm));
                    }

                    LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                    {
                        DocTypeId    = Sh.DocTypeId,
                        DocId        = Sl.SaleInvoiceHeaderId,
                        DocLineId    = Sl.SaleInvoiceLineId,
                        ActivityType = (int)ActivityTypeContants.Added,
                        DocNo        = Sh.DocNo,
                        DocDate      = Sh.DocDate,
                        DocStatus    = Sh.Status,
                    }));


                    return(RedirectToAction("_Create", new { id = Sh.SaleInvoiceHeaderId, IsSaleBased = (Sl.SaleDispatchLineId == null ? false : true) }));
                }
                else
                {
                    List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();

                    int status = Sh.Status;

                    SaleInvoiceLine       Sl  = _SaleInvoiceLineService.Find(svm.SaleInvoiceLineId);
                    SaleInvoiceLineDetail Sid = _SaleInvoiceLineDetailService.Find(svm.SaleInvoiceLineId);

                    SaleInvoiceLine ExRecS = new SaleInvoiceLine();
                    ExRecS = Mapper.Map <SaleInvoiceLine>(Sl);

                    Sl.Dimension1Id             = svm.Dimension1Id;
                    Sl.Dimension2Id             = svm.Dimension2Id;
                    Sl.ProductId                = svm.ProductId;
                    Sl.DiscountPer              = svm.DiscountPer;
                    Sl.Qty                      = svm.Qty;
                    Sl.Amount                   = svm.Amount;
                    Sl.Weight                   = svm.Weight;
                    Sl.UnitConversionMultiplier = svm.UnitConversionMultiplier;
                    Sl.DealQty                  = svm.DealQty;
                    Sl.DealUnitId               = svm.DealUnitId;
                    Sl.Rate                     = svm.Rate;
                    Sl.Remark                   = svm.Remark;
                    Sl.ModifiedDate             = DateTime.Now;
                    Sl.ModifiedBy               = User.Identity.Name;
                    Sl.ObjectState              = Model.ObjectState.Modified;
                    _SaleInvoiceLineService.Update(Sl);

                    if (svm.RewardPoints != null)
                    {
                        Sid.RewardPoints = svm.RewardPoints;
                    }
                    _SaleInvoiceLineDetailService.Update(Sid);

                    LogList.Add(new LogTypeViewModel
                    {
                        ExObj = ExRecS,
                        Obj   = Sl,
                    });


                    if (Sh.Status != (int)StatusConstants.Drafted)
                    {
                        Sh.Status = (int)StatusConstants.Modified;
                        new SaleInvoiceHeaderService(_unitOfWork).Update(Sh);
                    }


                    if (svm.linecharges != null)
                    {
                        foreach (var item in svm.linecharges)
                        {
                            var productcharge = new SaleInvoiceLineChargeService(_unitOfWork).Find(item.Id);
                            SaleInvoiceLineCharge ExRecLine = new SaleInvoiceLineCharge();
                            ExRecLine = Mapper.Map <SaleInvoiceLineCharge>(productcharge);

                            productcharge.Rate   = item.Rate;
                            productcharge.Amount = item.Amount;
                            new SaleInvoiceLineChargeService(_unitOfWork).Update(productcharge);
                            LogList.Add(new LogTypeViewModel
                            {
                                ExObj = ExRecLine,
                                Obj   = productcharge,
                            });
                        }
                    }


                    if (svm.footercharges != null)
                    {
                        foreach (var item in svm.footercharges)
                        {
                            var footercharge = new SaleInvoiceHeaderChargeService(_unitOfWork).Find(item.Id);
                            SaleInvoiceHeaderCharge ExRecLine = new SaleInvoiceHeaderCharge();
                            ExRecLine = Mapper.Map <SaleInvoiceHeaderCharge>(footercharge);

                            footercharge.Rate   = item.Rate;
                            footercharge.Amount = item.Amount;
                            new SaleInvoiceHeaderChargeService(_unitOfWork).Update(footercharge);
                            LogList.Add(new LogTypeViewModel
                            {
                                ExObj = ExRecLine,
                                Obj   = footercharge,
                            });
                        }
                    }

                    XElement Modifications = new ModificationsCheckService().CheckChanges(LogList);
                    try
                    {
                        _unitOfWork.Save();
                    }

                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        TempData["CSEXCL"] += message;
                        PrepareViewBag();
                        return(PartialView("_Create", svm));
                    }

                    //Saving the Activity Log

                    LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                    {
                        DocTypeId       = Sh.DocTypeId,
                        DocId           = Sl.SaleInvoiceHeaderId,
                        DocLineId       = Sl.SaleInvoiceLineId,
                        ActivityType    = (int)ActivityTypeContants.Modified,
                        DocNo           = Sh.DocNo,
                        xEModifications = Modifications,
                        DocDate         = Sh.DocDate,
                        DocStatus       = Sh.Status,
                    }));

                    //End of Saving the Activity Log

                    return(Json(new { success = true }));
                }
            }
            PrepareViewBag();
            return(PartialView("_Create", svm));
        }