Beispiel #1
0
        public void CreateConsignmentsFromPendingItems_ValidPendingConsignmentItems_ConsignmentsCreated()
        {
            var dispatcher     = MockRepository.GenerateMock <IQueueDispatcher <IMessage> >();
            var userRepository = new UserAccountRepository();
            var user           = userRepository.GetByEmail("*****@*****.**", false);
            var userContext    = new TestUserContext(user);

            var consignmentRepository     = new ConsignmentRepository();
            var consignmentItemRepository = new ConsignmentItemRepository();
            var supplierRepository        = new SupplierRepository();
            var jobRepository             = new JobRepository();
            var jobItemRepository         = new JobItemRepository();
            var listItemRepository        = new ListItemRepository();
            var entityIdProvider          = new DirectEntityIdProvider();
            var instrumentRepository      = new InstrumentRepository();

            var supplier1Id = Guid.NewGuid();
            var supplier2Id = Guid.NewGuid();
            var supplier3Id = Guid.NewGuid();
            var job1Id      = Guid.NewGuid();
            var job2Id      = Guid.NewGuid();
            var job3Id      = Guid.NewGuid();
            var jobItem1Id  = Guid.NewGuid();
            var jobItem2Id  = Guid.NewGuid();
            var jobItem3Id  = Guid.NewGuid();
            var jobItem4Id  = Guid.NewGuid();
            var jobItem5Id  = Guid.NewGuid();
            var jobItem6Id  = Guid.NewGuid();
            var jobItem7Id  = Guid.NewGuid();

            CreateConsignmentsFromPendingItemsHelper.CreateContextForPendingItemTests(
                job1Id, job2Id, job3Id, supplier1Id, supplier2Id, supplier3Id,
                jobItem1Id, jobItem2Id, jobItem3Id, jobItem4Id, jobItem5Id, jobItem6Id, jobItem7Id);

            var instrumentService      = new InstrumentService(userContext, instrumentRepository, dispatcher);
            var listItemService        = new ListItemService(userContext, listItemRepository, dispatcher);
            var jobItemService         = new JobItemService(userContext, jobRepository, jobItemRepository, listItemService, instrumentService, dispatcher);
            var consignmentItemService = new ConsignmentItemService(
                userContext,
                consignmentRepository, consignmentItemRepository, jobItemRepository, new ListItemRepository(), supplierRepository, dispatcher);

            _consignmentService = new ConsignmentService(userContext, consignmentRepository, supplierRepository, new DirectEntityIdProvider(), consignmentItemService, dispatcher);
            var jobItems = jobItemService.GetJobItems(job1Id).OrderBy(ji => ji.ItemNo).ToList();

            consignmentItemService.CreatePending(Guid.NewGuid(), jobItems[0].Id, supplier1Id, "for cal");
            consignmentItemService.CreatePending(Guid.NewGuid(), jobItems[1].Id, supplier2Id, "for repair");
            consignmentItemService.CreatePending(Guid.NewGuid(), jobItems[2].Id, supplier1Id, "for cal");
            jobItems = jobItemService.GetJobItems(job2Id).OrderBy(ji => ji.ItemNo).ToList();
            consignmentItemService.CreatePending(Guid.NewGuid(), jobItems[0].Id, supplier1Id, "for cal");
            consignmentItemService.CreatePending(Guid.NewGuid(), jobItems[1].Id, supplier2Id, "for repair");
            consignmentItemService.CreatePending(Guid.NewGuid(), jobItems[2].Id, supplier3Id, "for cal");
            jobItems = jobItemService.GetJobItems(job3Id).OrderBy(ji => ji.ItemNo).ToList();
            consignmentItemService.CreatePending(Guid.NewGuid(), jobItems[0].Id, supplier3Id, "for cal");

            var consignmentService = new ConsignmentService(userContext, consignmentRepository, supplierRepository, entityIdProvider, consignmentItemService, dispatcher);

            consignmentService.CreateConsignmentsFromPendingItems();

            var consignments = consignmentService.GetConsignments().OrderBy(c => c.ConsignmentNo).ToList();

            Assert.AreEqual(3, consignments.Count);
            Assert.AreEqual("1", consignments[0].ConsignmentNo);
            Assert.AreEqual(supplier1Id, consignments[0].Supplier.Id);
            Assert.AreEqual("2", consignments[1].ConsignmentNo);
            Assert.AreEqual(supplier2Id, consignments[1].Supplier.Id);
            Assert.AreEqual("3", consignments[2].ConsignmentNo);
            Assert.AreEqual(supplier3Id, consignments[2].Supplier.Id);

            var consignmentItems = consignmentItemService.GetConsignmentItems(consignments[0].Id).OrderBy(ci => ci.ItemNo).ToList();

            Assert.AreEqual(3, consignmentItems.Count);
            Assert.AreEqual(jobItem1Id, consignmentItems[0].JobItem.Id);    // JR2000/1
            Assert.AreEqual(jobItem3Id, consignmentItems[1].JobItem.Id);    // JR2000/3
            Assert.AreEqual(jobItem4Id, consignmentItems[2].JobItem.Id);    // JR2001/1

            consignmentItems = consignmentItemService.GetConsignmentItems(consignments[1].Id).OrderBy(ci => ci.ItemNo).ToList();
            Assert.AreEqual(2, consignmentItems.Count);
            Assert.AreEqual(jobItem2Id, consignmentItems[0].JobItem.Id);    // JR2000/2
            Assert.AreEqual(jobItem5Id, consignmentItems[1].JobItem.Id);    // JR2001/2

            consignmentItems = consignmentItemService.GetConsignmentItems(consignments[2].Id).OrderBy(ci => ci.ItemNo).ToList();
            Assert.AreEqual(2, consignmentItems.Count);
            Assert.AreEqual(jobItem6Id, consignmentItems[0].JobItem.Id);    // JR2001/3
            Assert.AreEqual(jobItem7Id, consignmentItems[1].JobItem.Id);    // JR2002/1

            Assert.AreEqual(0, consignmentItemService.GetPendingItems().Count());
        }
Beispiel #2
0
        public ActionResult Details(Guid id, string TabNo)
        {
            var job       = _jobService.GetJob(id);
            var jobItems  = _jobItemService.GetJobItems(id);
            var viewModel = new JobDetailsViewModel
            {
                Id                = job.Id.ToString(),
                CreatedBy         = job.CreatedBy.ToString(),
                DateCreated       = job.DateCreated.ToLongDateString() + ' ' + job.DateCreated.ToShortTimeString(),
                JobNumber         = job.JobNo,
                OrderNumber       = job.OrderNo,
                AdviceNumber      = job.AdviceNo,
                Instruction       = job.Instructions,
                Note              = job.Notes,
                Contact           = job.Contact,
                CustomerName      = job.Customer.Name,
                CustomerAssetLine = job.Customer.AssetLine,
                CustomerAddress1  = job.Customer.Address1,
                CustomerAddress2  = job.Customer.Address2,
                CustomerAddress3  = job.Customer.Address3,
                CustomerAddress4  = job.Customer.Address4,
                CustomerAddress5  = job.Customer.Address5,
                CustomerEmail     = job.Customer.Email,
                CustomerTelephone = job.Customer.Telephone,
                IsPending         = job.IsPending,
                JobItems          = jobItems.Select(ji => new JobItemDetailsViewModel
                {
                    Id                   = ji.Id,
                    JobId                = id,
                    JobItemRef           = ji.GetJobItemRef(),
                    UserRole             = GetLoggedInUserRoles(),
                    AssetNo              = ji.AssetNo,
                    SerialNo             = ji.SerialNo,
                    Status               = ji.Status.Name.ToString(),
                    CalPeriod            = ji.CalPeriod,
                    Field                = ji.Field.Name.ToString(),
                    Accessories          = ji.Accessories,
                    Comments             = ji.Comments,
                    Instructions         = ji.Instructions,
                    IsReturned           = ji.IsReturned,
                    ReturnReason         = ji.ReturnReason,
                    IsInvoiced           = ji.IsInvoiced,
                    IsMarkedForInvoicing = ji.IsMarkedForInvoicing,
                    InstrumentDetails    = ji.Instrument.ToString(),
                    QuoteItem            = PopulateQuoteItemViewModel(ji.Id),
                    Delivery             = PopulateDeliveryItemViewModel(ji.Id),
                    Certificates         = PopulateCertificateViewModel(ji.Id),
                    WorkItems            = ji.HistoryItems.Select(wi => new WorkItemDetailsViewModel
                    {
                        Id          = wi.Id,
                        JobItemId   = wi.JobItem.Id,
                        OverTime    = wi.OverTime,
                        Report      = wi.Report,
                        Status      = wi.Status.Name.ToString(),
                        WorkTime    = wi.WorkTime,
                        WorkType    = wi.WorkType.Name.ToString(),
                        WorkBy      = wi.User.Name.ToString(),
                        DateCreated = wi.DateCreated.ToLongDateString() + ' ' + wi.DateCreated.ToShortTimeString()
                    }).OrderByDescending(wi => wi.DateCreated).ToList()
                }).OrderBy(ji => ji.JobItemRef).ToList(),
                Attachments = job.Attachments.Select(
                    a => new AttachmentViewModel
                {
                    Id   = a.Id,
                    Name = a.Filename
                }).ToList()
            };

            foreach (var ji in viewModel.JobItems)
            {
                PopulateOrderItemViewModel(ji);
                PopulateConsignmentItemViewModel(ji);
            }
            return(View(viewModel));
        }