Beispiel #1
0
        public JsonResult EditPart(PartOperationModel model)
        {
            var operationResult = new OperationResult();

            if (model.IsProjectPart)
            {
                var currentPart = _projectPartRepository.GetProjectPart(model.ProjectPartId);

                if (currentPart != null)
                {
                    currentPart = new ProjectPartConverter().ConvertToDomain(model);

                    operationResult = _projectPartRepository.UpdateProjectPart(currentPart);

                    if (operationResult.Success)
                    {
                        var partToEdit = _priceSheetRepository.GetProductionPriceSheetPartByProjectPart(currentPart.ProjectPartId);

                        if (partToEdit != null)
                        {
                            partToEdit.Cost        = model.Cost;
                            partToEdit.Price       = model.Price;
                            partToEdit.AnnualCost  = model.Cost * partToEdit.AnnualUsage;
                            partToEdit.AnnualPrice = model.Price * partToEdit.AnnualUsage;

                            operationResult = _priceSheetRepository.UpdatePriceSheetPart(partToEdit);

                            var totalAnnualCost  = _priceSheetRepository.GetPriceSheetParts(partToEdit.PriceSheetId).Select(x => x.AnnualCost).Sum();
                            var totalAnnualPrice = _priceSheetRepository.GetPriceSheetParts(partToEdit.PriceSheetId).Select(x => x.AnnualPrice).Sum();

                            var priceSheetToEdit = _priceSheetRepository.GetPriceSheet(partToEdit.PriceSheetId);

                            priceSheetToEdit.AnnualMargin = (totalAnnualPrice - totalAnnualCost) / totalAnnualCost;

                            operationResult = _priceSheetRepository.UpdatePriceSheet(priceSheetToEdit);
                        }
                    }
                }
            }
            else
            {
                var existingPart = _partRepository.GetPart(model.PartId);

                if (existingPart != null)
                {
                    Part part = new PartConverter().ConvertToUpdatePart(model);

                    operationResult = _partRepository.UpdatePart(part);
                }
            }

            return(Json(operationResult, JsonRequestBehavior.AllowGet));
        }
Beispiel #2
0
        public JsonResult SendPriceSheetEmail(Guid priceSheetId, EmailModel model)
        {
            var operationResult = new OperationResult();

            var _emailManager = new MailManager();

            var ms = ReportingManager.CreatePriceSheetReport(priceSheetId);

            var currentPriceSheet = _priceSheetRepository.GetPriceSheet(priceSheetId).Number;

            var fromUser = UserManager.FindById(User.Identity.GetUserId());

            model.MS        = ms;
            model.FromEmail = fromUser.Email;
            model.Number    = currentPriceSheet;

            operationResult = _emailManager.SendEmail(model);

            return(Json(operationResult, JsonRequestBehavior.AllowGet));
        }
Beispiel #3
0
        public JsonResult Create(PriceSheetViewModel priceSheet)
        {
            var operationResult = new OperationResult();

            var rfq = _rfqRepository.GetRfq(priceSheet.RfqId);

            var newPriceSheet = new PriceSheetConverter().ConvertToDomain(priceSheet);

            operationResult = _priceSheetRepository.SavePriceSheet(newPriceSheet);

            if (operationResult.Success && priceSheet.IsQuote)
            {
                rfq.IsOpen      = false;
                operationResult = _rfqRepository.UpdateRfq(rfq);
            }

            var insertedPriceSheet = _priceSheetRepository.GetPriceSheet(priceSheet.Number);

            if (operationResult.Success)
            {
                if (priceSheet.CostDetailList != null && priceSheet.CostDetailList.Count > 0)
                {
                    foreach (var costDetail in priceSheet.CostDetailList)
                    {
                        var priceDetail = priceSheet.PriceDetailList.FirstOrDefault(x => x.ProjectPartId == costDetail.ProjectPartId);

                        var tempPart = _projectPartRepository.GetProjectPart(costDetail.ProjectPartId);
                        {
                            tempPart.Weight       = costDetail.Weight;
                            tempPart.AnnualUsage  = (int)costDetail.AnnualUsage;
                            tempPart.Cost         = costDetail.Cost;
                            tempPart.PatternCost  = costDetail.PatternCost;
                            tempPart.FixtureCost  = costDetail.FixtureCost;
                            tempPart.PriceSheetId = insertedPriceSheet.PriceSheetId;
                            tempPart.Price        = priceDetail.Price;
                            tempPart.PatternPrice = priceDetail.PatternPrice;
                            tempPart.FixturePrice = priceDetail.FixturePrice;
                        }
                        operationResult = _projectPartRepository.UpdateProjectPart(tempPart);
                    }
                }

                if (operationResult.Success && priceSheet.IsQuote)
                {
                    operationResult = _rfqRepository.UpdatePriceSheet(rfq.RfqId, priceSheet.Number);
                }
                else if (priceSheet.IsProduction && operationResult.Success)
                {
                    if (priceSheet.QuoteId != Guid.Empty)
                    {
                        var quote = _quoteRepository.GetQuote(priceSheet.QuoteId);
                        quote.IsOpen    = false;
                        operationResult = _quoteRepository.UpdateQuote(quote);
                    }

                    ConvertProjectPartsToParts(insertedPriceSheet.PriceSheetId);
                }
            }

            operationResult.ReferenceId = insertedPriceSheet.PriceSheetId;

            return(Json(operationResult, JsonRequestBehavior.AllowGet));;
        }
Beispiel #4
0
        public JsonResult Create(QuoteViewModel model)
        {
            var operationResult = new OperationResult();

            Quote newQuote = new QuoteConverter().ConvertToDomain(model);

            operationResult = _quoteRepository.SaveQuote(newQuote);

            if (operationResult.Success)
            {
                var quoteId = operationResult.ReferenceId;

                var rfq = _rfqRepository.GetRfq(model.RfqId);

                if (rfq != null)
                {
                    rfq.IsOpen      = false;
                    operationResult = _rfqRepository.UpdateRfq(rfq);
                }

                var rfqId             = model.RfqId;
                var priceSheetId      = model.PriceSheetId;
                var projectId         = model.ProjectId;
                var customerAddressId = model.CustomerAddressId;
                var foundryId         = (rfq != null) ? rfq.FoundryId : string.Empty;
                var htsNumberId       = model.HtsNumberId;
                var shipmentTermId    = model.ShipmentTermId;
                var paymentTermId     = model.PaymentTermId;
                var materialId        = model.MaterialId;
                var coatingTypeId     = model.CoatingTypeId;

                var quotePriceSheet = _priceSheetRepository.GetPriceSheet(priceSheetId ?? Guid.Empty);

                if (model.QuoteParts != null && model.QuoteParts.Count() > 0)
                {
                    foreach (var quotePart in model.QuoteParts)
                    {
                        var projectPart = new ProjectPartConverter().ConvertToDomain(quotePart);

                        projectPart.RfqId             = rfqId;
                        projectPart.PriceSheetId      = priceSheetId;
                        projectPart.QuoteId           = quoteId;
                        projectPart.ProjectId         = projectId;
                        projectPart.CustomerAddressId = customerAddressId;
                        projectPart.FoundryId         = (!string.IsNullOrEmpty(foundryId)) ? foundryId : projectPart.FoundryId;
                        projectPart.HtsNumberId       = htsNumberId;
                        projectPart.ShipmentTermId    = shipmentTermId;
                        projectPart.PaymentTermId     = paymentTermId;
                        projectPart.MaterialId        = materialId;
                        projectPart.CoatingTypeId     = coatingTypeId;
                        projectPart.FixtureDate       = (quotePriceSheet != null) ? quotePriceSheet.CreatedDate : null; //enter from price sheet
                        projectPart.PatternDate       = (quotePriceSheet != null) ? quotePriceSheet.CreatedDate : null; //enter from price sheet

                        var projectPartToUpdate = _projectPartRepository.GetProjectPart(projectPart.ProjectPartId);

                        if (projectPartToUpdate != null)
                        {
                            operationResult = _projectPartRepository.UpdateProjectPart(projectPart);
                        }
                        else
                        {
                            operationResult           = _projectPartRepository.SaveProjectPart(projectPart);
                            projectPart.ProjectPartId = operationResult.ReferenceId;

                            if (quotePriceSheet != null)
                            {
                                var newPriceSheetPart = new PriceSheetPartConverter().ConvertToDomain(projectPart);

                                newPriceSheetPart.IsQuote      = true;
                                newPriceSheetPart.IsProduction = false;
                                operationResult = _priceSheetRepository.SavePriceSheetPart(newPriceSheetPart);
                            }
                        }
                    }
                }

                operationResult.ReferenceId = quoteId;
            }



            return(Json(operationResult, JsonRequestBehavior.AllowGet));
        }