示例#1
0
        public ActionResult _Create(int Id, int?sid)  //Id ==>Sale Order Header Id
        {
            JobInvoiceAmendmentHeader            header = new JobInvoiceAmendmentHeaderService(_unitOfWork).Find(Id);
            JobInvoiceRateAmendmentLineViewModel svm    = new JobInvoiceRateAmendmentLineViewModel();

            //Getting Settings
            var settings = new JobInvoiceSettingsService(_unitOfWork).GetJobInvoiceSettingsForDocument(header.DocTypeId, header.DivisionId, header.SiteId);

            svm.JobInvoiceSettings          = Mapper.Map <JobInvoiceSettings, JobInvoiceSettingsViewModel>(settings);
            ViewBag.LineMode                = "Create";
            svm.JobInvoiceAmendmentHeaderId = Id;
            svm.JobWorkerId = sid.HasValue ? sid.Value : 0;
            svm.DocTypeId   = header.DocTypeId;
            svm.SiteId      = header.SiteId;
            svm.DivisionId  = header.DivisionId;
            return(PartialView("_Create", svm));
        }
示例#2
0
        private ActionResult _Delete(int id)
        {
            JobInvoiceRateAmendmentLineViewModel temp = _JobInvoiceRateAmendmentLineService.GetJobInvoiceRateAmendmentLine(id);

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

            JobInvoiceAmendmentHeader header = new JobInvoiceAmendmentHeaderService(_unitOfWork).Find(temp.JobInvoiceAmendmentHeaderId);

            #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";
            }

            //Getting Settings
            var settings = new JobInvoiceSettingsService(_unitOfWork).GetJobInvoiceSettingsForDocument(header.DocTypeId, header.DivisionId, header.SiteId);

            temp.JobInvoiceSettings = Mapper.Map <JobInvoiceSettings, JobInvoiceSettingsViewModel>(settings);

            return(PartialView("_Create", temp));
        }
示例#3
0
        public ActionResult DeletePost(JobInvoiceRateAmendmentLineViewModel vm)
        {
            bool BeforeSave = true;

            try
            {
                BeforeSave = JobInvoiceAmendmentDocEvents.beforeLineDeleteEvent(this, new JobEventArgs(vm.JobInvoiceAmendmentHeaderId, vm.JobInvoiceRateAmendmentLineId), ref db);
            }
            catch (Exception ex)
            {
                string message = _exception.HandleException(ex);
                TempData["CSEXC"] += message;
                EventException     = true;
            }

            if (!BeforeSave)
            {
                TempData["CSEXC"] += "Validation failed before delete.";
            }

            if (BeforeSave && !EventException)
            {
                JobInvoiceRateAmendmentLine JobInvoiceLine = db.JobInvoiceRateAmendmentLine.Find(vm.JobInvoiceRateAmendmentLineId);
                JobInvoiceAmendmentHeader   header         = new JobInvoiceAmendmentHeaderService(_unitOfWork).Find(JobInvoiceLine.JobInvoiceAmendmentHeaderId);

                //Commented No InvoiceLineStatus
                //new JobInvoiceLineStatusService(_unitOfWork).UpdateJobRateOnAmendment(JobInvoiceLine.JobInvoiceLineId, JobInvoiceLine.JobInvoiceRateAmendmentLineId, header.DocDate, 0, ref db);

                JobInvoiceLine.ObjectState = Model.ObjectState.Deleted;

                db.JobInvoiceRateAmendmentLine.Remove(JobInvoiceLine);

                if (header.Status != (int)StatusConstants.Drafted && header.Status != (int)StatusConstants.Import)
                {
                    header.Status       = (int)StatusConstants.Modified;
                    header.ObjectState  = Model.ObjectState.Modified;
                    header.ModifiedBy   = User.Identity.Name;
                    header.ModifiedDate = DateTime.Now;
                    db.JobInvoiceAmendmentHeader.Add(header);
                }

                var chargeslist = (from p in db.JobInvoiceRateAmendmentLineCharge
                                   where p.LineTableId == vm.JobInvoiceRateAmendmentLineId
                                   select p).ToList();

                if (chargeslist != null)
                {
                    foreach (var item in chargeslist)
                    {
                        item.ObjectState = Model.ObjectState.Deleted;
                        db.JobInvoiceRateAmendmentLineCharge.Remove(item);
                    }
                }

                if (vm.footercharges != null)
                {
                    foreach (var item in vm.footercharges)
                    {
                        var footer = new JobInvoiceAmendmentHeaderChargeService(db).Find(item.Id);
                        footer.Rate        = item.Rate;
                        footer.Amount      = item.Amount;
                        footer.ObjectState = Model.ObjectState.Modified;
                        db.JobInvoiceAmendmentHeaderCharge.Add(footer);
                    }
                }

                try
                {
                    JobInvoiceAmendmentDocEvents.onLineDeleteEvent(this, new JobEventArgs(JobInvoiceLine.JobInvoiceAmendmentHeaderId, JobInvoiceLine.JobInvoiceRateAmendmentLineId), ref db);
                }
                catch (Exception ex)
                {
                    string message = _exception.HandleException(ex);
                    TempData["CSEXCL"] += message;
                    EventException      = true;
                }

                try
                {
                    if (EventException)
                    {
                        throw new Exception();
                    }

                    db.SaveChanges();
                    //_unitOfWork.Save();
                }

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

                try
                {
                    JobInvoiceAmendmentDocEvents.afterLineDeleteEvent(this, new JobEventArgs(JobInvoiceLine.JobInvoiceAmendmentHeaderId, JobInvoiceLine.JobInvoiceRateAmendmentLineId), ref db);
                }
                catch (Exception ex)
                {
                    string message = _exception.HandleException(ex);
                    TempData["CSEXC"] += message;
                }
            }
            return(Json(new { success = true }));
        }
示例#4
0
        public ActionResult _CreatePost(JobInvoiceRateAmendmentLineViewModel svm)
        {
            bool BeforeSave = true;

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

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

            try
            {
                if (svm.JobInvoiceRateAmendmentLineId <= 0)
                {
                    BeforeSave = JobInvoiceAmendmentDocEvents.beforeLineSaveEvent(this, new JobEventArgs(svm.JobInvoiceAmendmentHeaderId, EventModeConstants.Add), ref db);
                }
                else
                {
                    BeforeSave = JobInvoiceAmendmentDocEvents.beforeLineSaveEvent(this, new JobEventArgs(svm.JobInvoiceAmendmentHeaderId, EventModeConstants.Edit), ref db);
                }
            }
            catch (Exception ex)
            {
                string message = _exception.HandleException(ex);
                TempData["CSEXCL"] += message;
                EventException      = true;
            }

            if (!BeforeSave)
            {
                ModelState.AddModelError("", "Validation failed before save.");
            }

            if (svm.JobInvoiceRateAmendmentLineId <= 0)
            {
                JobInvoiceRateAmendmentLine s = new JobInvoiceRateAmendmentLine();

                if (ModelState.IsValid && BeforeSave && !EventException)
                {
                    if (svm.Rate != 0)
                    {
                        s.Remark = svm.Remark;
                        s.JobInvoiceAmendmentHeaderId = svm.JobInvoiceAmendmentHeaderId;
                        s.JobInvoiceLineId            = svm.JobInvoiceLineId;
                        s.Qty            = svm.Qty;
                        s.AmendedRate    = svm.AmendedRate;
                        s.Amount         = svm.Amount;
                        s.JobInvoiceRate = svm.JobInvoiceRate;
                        s.JobWorkerId    = svm.JobWorkerId;
                        s.Rate           = svm.Rate;
                        s.Remark         = svm.Remark;
                        s.Sr             = _JobInvoiceRateAmendmentLineService.GetMaxSr(s.JobInvoiceAmendmentHeaderId);
                        s.CreatedDate    = DateTime.Now;
                        s.ModifiedDate   = DateTime.Now;
                        s.CreatedBy      = User.Identity.Name;
                        s.ModifiedBy     = User.Identity.Name;
                        s.ObjectState    = Model.ObjectState.Added;
                        db.JobInvoiceRateAmendmentLine.Add(s);



                        if (svm.linecharges != null)
                        {
                            foreach (var item in svm.linecharges)
                            {
                                item.LineTableId   = s.JobInvoiceRateAmendmentLineId;
                                item.PersonID      = s.JobWorkerId;
                                item.HeaderTableId = s.JobInvoiceAmendmentHeaderId;
                                item.ObjectState   = Model.ObjectState.Added;
                                db.JobInvoiceRateAmendmentLineCharge.Add(item);
                            }
                        }

                        if (svm.footercharges != null)
                        {
                            int PersonCount = (from p in db.JobInvoiceRateAmendmentLine
                                               where p.JobInvoiceAmendmentHeaderId == s.JobInvoiceAmendmentHeaderId
                                               group p by p.JobWorkerId into g
                                               select g).Count();

                            foreach (var item in svm.footercharges)
                            {
                                if (item.Id > 0)
                                {
                                    var footercharge = new JobInvoiceAmendmentHeaderChargeService(db).Find(item.Id);
                                    if (PersonCount > 1 || footercharge.PersonID != s.JobWorkerId)
                                    {
                                        footercharge.PersonID = null;
                                    }

                                    footercharge.Rate        = item.Rate;
                                    footercharge.Amount      = item.Amount;
                                    footercharge.ObjectState = Model.ObjectState.Modified;
                                    db.JobInvoiceAmendmentHeaderCharge.Add(footercharge);
                                }

                                else
                                {
                                    item.HeaderTableId = s.JobInvoiceAmendmentHeaderId;
                                    item.PersonID      = s.JobWorkerId;
                                    item.ObjectState   = Model.ObjectState.Added;
                                    db.JobInvoiceAmendmentHeaderCharge.Add(item);
                                }
                            }
                        }


                        JobInvoiceAmendmentHeader temp2 = new JobInvoiceAmendmentHeaderService(_unitOfWork).Find(s.JobInvoiceAmendmentHeaderId);
                        if (temp2.Status != (int)StatusConstants.Drafted && temp2.Status != (int)StatusConstants.Import)
                        {
                            temp2.Status       = (int)StatusConstants.Modified;
                            temp2.ModifiedBy   = User.Identity.Name;
                            temp2.ModifiedDate = DateTime.Now;
                        }

                        temp2.ObjectState = Model.ObjectState.Modified;
                        db.JobInvoiceAmendmentHeader.Add(temp2);

                        //Commented No InvoiceLineStatus
                        //new JobInvoiceLineStatusService(_unitOfWork).UpdateJobRateOnAmendment(svm.JobInvoiceLineId, s.JobInvoiceRateAmendmentLineId, temp2.DocDate, s.Rate, ref db);

                        try
                        {
                            JobInvoiceAmendmentDocEvents.onLineSaveEvent(this, new JobEventArgs(s.JobInvoiceAmendmentHeaderId, s.JobInvoiceRateAmendmentLineId, EventModeConstants.Add), ref db);
                        }
                        catch (Exception ex)
                        {
                            string message = _exception.HandleException(ex);
                            TempData["CSEXCL"] += message;
                            EventException      = true;
                        }

                        try
                        {
                            if (EventException)
                            {
                                throw new Exception();
                            }

                            db.SaveChanges();
                        }

                        catch (Exception ex)
                        {
                            string message = _exception.HandleException(ex);
                            TempData["CSEXCL"] += message;
                            return(PartialView("_Create", svm));
                        }
                        try
                        {
                            JobInvoiceAmendmentDocEvents.afterLineSaveEvent(this, new JobEventArgs(s.JobInvoiceAmendmentHeaderId, s.JobInvoiceRateAmendmentLineId, EventModeConstants.Add), ref db);
                        }
                        catch (Exception ex)
                        {
                            string message = _exception.HandleException(ex);
                            TempData["CSEXCL"] += message;
                        }

                        LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                        {
                            DocTypeId    = temp2.DocTypeId,
                            DocId        = temp2.JobInvoiceAmendmentHeaderId,
                            DocLineId    = s.JobInvoiceRateAmendmentLineId,
                            ActivityType = (int)ActivityTypeContants.Added,
                            DocNo        = temp2.DocNo,
                            DocDate      = temp2.DocDate,
                            DocStatus    = temp2.Status,
                        }));
                    }

                    if (!svm.JobInvoiceSettings.isVisibleHeaderJobWorker)
                    {
                        return(RedirectToAction("_Create", new { id = svm.JobInvoiceAmendmentHeaderId }));
                    }
                    else
                    {
                        return(RedirectToAction("_Create", new { id = svm.JobInvoiceAmendmentHeaderId, sid = svm.JobWorkerId }));
                    }
                }
                return(PartialView("_Create", svm));
            }
            else
            {
                List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();

                JobInvoiceAmendmentHeader temp = new JobInvoiceAmendmentHeaderService(_unitOfWork).Find(svm.JobInvoiceAmendmentHeaderId);
                int           status           = temp.Status;
                StringBuilder logstring        = new StringBuilder();

                JobInvoiceRateAmendmentLine s = _JobInvoiceRateAmendmentLineService.Find(svm.JobInvoiceRateAmendmentLineId);


                JobInvoiceRateAmendmentLine ExRecLine = new JobInvoiceRateAmendmentLine();
                ExRecLine = Mapper.Map <JobInvoiceRateAmendmentLine>(s);


                if (ModelState.IsValid && BeforeSave && !EventException)
                {
                    if (svm.Rate != 0)
                    {
                        s.Remark       = svm.Remark;
                        s.AmendedRate  = svm.AmendedRate;
                        s.Rate         = svm.Rate;
                        s.Amount       = svm.Amount;
                        s.ModifiedBy   = User.Identity.Name;
                        s.ModifiedDate = DateTime.Now;
                    }

                    s.ObjectState = Model.ObjectState.Modified;
                    db.JobInvoiceRateAmendmentLine.Add(s);

                    //Commented No InvoiceLineStatus
                    //new JobInvoiceLineStatusService(_unitOfWork).UpdateJobRateOnAmendment(s.JobInvoiceLineId, s.JobInvoiceRateAmendmentLineId, temp.DocDate, s.Rate, ref db);

                    if (temp.Status != (int)StatusConstants.Drafted && temp.Status != (int)StatusConstants.Import)
                    {
                        temp.Status       = (int)StatusConstants.Modified;
                        temp.ModifiedDate = DateTime.Now;
                        temp.ModifiedBy   = User.Identity.Name;
                    }

                    temp.ObjectState = Model.ObjectState.Modified;
                    db.JobInvoiceAmendmentHeader.Add(temp);

                    LogList.Add(new LogTypeViewModel
                    {
                        ExObj = ExRecLine,
                        Obj   = s,
                    });


                    if (svm.linecharges != null)
                    {
                        foreach (var item in svm.linecharges)
                        {
                            var productcharge = new JobInvoiceRateAmendmentLineChargeService(db).Find(item.Id);

                            JobInvoiceRateAmendmentLineCharge ExRecC = new JobInvoiceRateAmendmentLineCharge();
                            ExRecC = Mapper.Map <JobInvoiceRateAmendmentLineCharge>(productcharge);

                            productcharge.Rate        = item.Rate;
                            productcharge.Amount      = item.Amount;
                            productcharge.DealQty     = item.DealQty;
                            productcharge.ObjectState = Model.ObjectState.Modified;
                            db.JobInvoiceRateAmendmentLineCharge.Add(productcharge);

                            LogList.Add(new LogTypeViewModel
                            {
                                ExObj = ExRecC,
                                Obj   = productcharge,
                            });
                        }
                    }


                    if (svm.footercharges != null)
                    {
                        foreach (var item in svm.footercharges)
                        {
                            var footercharge = new JobInvoiceAmendmentHeaderChargeService(db).Find(item.Id);

                            JobInvoiceAmendmentHeaderCharge ExRecC = new JobInvoiceAmendmentHeaderCharge();
                            ExRecC = Mapper.Map <JobInvoiceAmendmentHeaderCharge>(footercharge);

                            footercharge.Rate        = item.Rate;
                            footercharge.Amount      = item.Amount;
                            footercharge.ObjectState = Model.ObjectState.Modified;
                            db.JobInvoiceAmendmentHeaderCharge.Add(footercharge);

                            LogList.Add(new LogTypeViewModel
                            {
                                ExObj = ExRecC,
                                Obj   = footercharge,
                            });
                        }
                    }



                    XElement Modifications = new ModificationsCheckService().CheckChanges(LogList);

                    try
                    {
                        JobInvoiceAmendmentDocEvents.onLineSaveEvent(this, new JobEventArgs(s.JobInvoiceAmendmentHeaderId, s.JobInvoiceRateAmendmentLineId, EventModeConstants.Edit), ref db);
                    }
                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        TempData["CSEXCL"] += message;
                        EventException      = true;
                    }

                    try
                    {
                        if (EventException)
                        {
                            throw new Exception();
                        }
                        db.SaveChanges();
                    }

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

                    try
                    {
                        JobInvoiceAmendmentDocEvents.afterLineSaveEvent(this, new JobEventArgs(s.JobInvoiceAmendmentHeaderId, s.JobInvoiceRateAmendmentLineId, EventModeConstants.Edit), ref db);
                    }
                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        TempData["CSEXC"] += message;
                    }

                    //SAving the Activity Log::

                    LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                    {
                        DocTypeId       = temp.DocTypeId,
                        DocId           = temp.JobInvoiceAmendmentHeaderId,
                        DocLineId       = s.JobInvoiceRateAmendmentLineId,
                        ActivityType    = (int)ActivityTypeContants.Modified,
                        DocNo           = temp.DocNo,
                        xEModifications = Modifications,
                        DocDate         = temp.DocDate,
                        DocStatus       = temp.Status,
                    }));

                    //End Of Saving Activity Log

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