public void RunValidation(InvoiceValidator invoiceValidator)
        {
            var _materialLists        = MaterialLists;
            var _materialInvoiceItems = invoiceValidator.MaterialItems;

            foreach (var ml in _materialLists)
            {
                foreach (var listItem in ml.MaterialListItems.AsQueryable().Include(m => m.JobMaterial).ThenInclude(jm => jm.MaterialId).ToList())
                {
                    if (!_materialInvoiceItems.Any(m => m.Sku.Id == listItem.MaterialId))
                    {
                        this.State = new Invalid();
                        invoiceValidator.SetInvoiceStateInvalid();
                        invoiceValidator.InvoiceErrors.Add(new InvoiceError()
                        {
                            FlaggedJobId        = invoiceValidator.Job.Id,
                            ServiceCode         = ServiceCode,
                            FlaggedMaterialCode = listItem.JobMaterial.Code,
                            FlaggedMaterialId   = listItem.JobMaterial.MaterialId,
                            JobCompletedDate    = invoiceValidator.Job.CompletedOn,
                            TechnicianName      = invoiceValidator.Job.JobAssignments.Where(j => j.Active == true).Select(ja => ja.Technician.Name).FirstOrDefault().ToString(),
                            TechnicianId        = invoiceValidator.Job.JobAssignments.Where(j => j.Active == true).Select(ja => ja.Technician.Id).FirstOrDefault()
                        });
                        continue;
                    }
                }
            }
        }
예제 #2
0
        public void RunValidation(InvoiceValidator invoiceValidator)
        {
            var _materialLists        = MaterialLists;
            var _materialInvoiceItems = invoiceValidator.MaterialItems;



            foreach (var list in _materialLists.AsQueryable().Include(ml => ml.MaterialListItems).ThenInclude(mli => mli.JobMaterial).ToList())
            {
                var    anyMatch            = false;
                string flaggedMaterialCode = list.Name.Contains(" - links") ? list.Name.Remove(list.Name.Length - 8) : list.Name;


                foreach (var item in list.MaterialListItems)
                {
                    if (_materialInvoiceItems.Any(m => m.Sku.Id == item.MaterialId))
                    {
                        anyMatch = true;
                    }
                }

                if (!anyMatch)
                {
                    this.State = new Invalid();
                    invoiceValidator.SetInvoiceStateInvalid();
                    invoiceValidator.InvoiceErrors.Add(new InvoiceError()
                    {
                        FlaggedJobId        = invoiceValidator.Job.Id,
                        ServiceCode         = ServiceCode,
                        FlaggedMaterialCode = flaggedMaterialCode,
                        FlaggedMaterialId   = 0,
                        JobCompletedDate    = invoiceValidator.Job.CompletedOn,
                        TechnicianName      = invoiceValidator.Job.JobAssignments.Where(j => j.Active == true).Select(ja => ja.Technician.Name).FirstOrDefault().ToString(),
                        TechnicianId        = invoiceValidator.Job.JobAssignments.Where(j => j.Active == true).Select(ja => ja.Technician.Id).FirstOrDefault()
                    });
                }
            }
        }