Beispiel #1
0
 public Task Delete(JobMaterial model)
 {
     return(Client.ExecuteDelete(DeleteByIdUrl, model.uuid));
 }
Beispiel #2
0
 public Task Update(JobMaterial model)
 {
     return(Client.ExecutePayload(UpdateUrl, model, model.uuid));
 }
Beispiel #3
0
        private static void CreateOtherJobs()
        {
            const int MaxLength = 50;

            foreach (var item in JobXRefList.Where(x => x.OriginalJob.StartsWith("G") || x.OriginalJob.StartsWith("M") || x.OriginalJob.StartsWith("P") ||
                                                   x.OriginalJob.StartsWith("T") || x.OriginalJob.StartsWith("V")).OrderBy(x => x.OriginalJob))
            {
                var jobinfo = SageJobHeaders.FirstOrDefault(x => x.JobNo == item.OriginalJob);
                if (jobinfo == null)
                {
                    ErrorList += String.Format("Job Header not found for Job: {0}", item.OriginalJob);
                    ErrorList += Environment.NewLine;
                }
                var custinfo = currentCustomers.FirstOrDefault(x => x.CustID == jobinfo.CustomerNo);
                if (custinfo == null)
                {
                    MissingCustomers += String.Format("Customer {0} for Job {1} was not found in Epicor", jobinfo.CustomerNo, item.OriginalJob);
                    MissingCustomers += Environment.NewLine;

                    custinfo = new DMT05CustomerVUKMasterLoad
                    {
                    };
                }

                var partnum = jobinfo.JobDesc;
                if (partnum.Length > MaxLength)
                {
                    partnum = partnum.Substring(0, MaxLength);
                }
                var jobhead = new JobHeader
                {
                    Company         = CompanyID,
                    JobEngineered   = true,
                    JobFirm         = true,
                    JobReleased     = true,
                    JobNum          = item.NewJob,
                    PartNum         = partnum,
                    Plant           = "MfgSys",
                    CustID          = jobinfo.CustomerNo,
                    PartDescription = partnum,
                    ProdQty         = 1,
                    ReqDueDate      = jobinfo.ContractDate,
                    StartDate       = jobinfo.ContractDate,
                    SyncReqBy       = false,
                };

                if (String.IsNullOrEmpty(jobhead.ReqDueDate))
                {
                    jobhead.ReqDueDate = "01/01/2019";
                }
                JobHeaders.Add(jobhead);

                var op1 = new JobOperation
                {
                    Company          = CompanyID,
                    AssemblySeq      = 0,
                    OpCode           = item.OpCode,
                    OpComplete       = false,
                    OprSeq           = 10,
                    ProdStandard     = 0,
                    QtyCompleted     = 0,
                    StdFormat        = "HP",
                    LaborEntryMethod = "T",
                    JobNum           = jobhead.JobNum,
                    SchedRelation    = "FS",
                    Plant            = "MfgSys",
                    AutoReceive      = true,
                    FinalOpr         = true,
                };

                JobOperations.Add(op1);

                //int mtlseq = 10;

                var camtl = new JobMaterial
                {
                    Company = jobhead.Company,
                    JobNum  = jobhead.JobNum,
                    //Plant = jobhead.Plant,
                    IssuedComplete = true,
                    PartNum        = "CostAdjustment",
                    Description    = "CostAdjustment",
                    //MaterialMtlCost = 0,
                    MtlSeq           = 5,
                    QtyPer           = 1,
                    AssemblySeq      = 0,
                    FixedQty         = true,
                    RelatedOperation = 10
                                       //RequiredQty = 1
                };

                JobMaterials.Add(camtl);
            }
        }
Beispiel #4
0
 public Task Create(JobMaterial model)
 {
     return(Client.ExecutePayload(CreateUrl, model));
 }
Beispiel #5
0
        private Dictionary <Type, List <EntityInfo> > BeforeSaveEntities(Dictionary <Type, List <EntityInfo> > saveMap)
        {
            #region JobPricing
            List <EntityInfo> entityInfos = saveMap.Where(e => e.Key == typeof(JobPricing)).Select(e => e.Value).FirstOrDefault();
            if (entityInfos != null)
            {
                foreach (EntityInfo entityInfo in entityInfos)
                {
                    JobPricing jobPricing = (JobPricing)(entityInfo.Entity);

                    // single query without lazy loading
                    var temp = (from p in Session.Query <JobTranslation>()
                                where p.Id == jobPricing.JobId
                                select new { JobTranslation = p, p.SourceMaterial.Request }).FirstOrDefault();

                    if (temp != null)
                    {
                        if (!CheckForObjectTypeInSaveMap(temp.JobTranslation, saveMap))
                        {
                            temp.JobTranslation.UpdateDate = DateTime.UtcNow;
                            saveMap.AddCustomEntity(temp.JobTranslation, this);
                        }

                        if (!saveMap.Any(e => e.Key == typeof(Request)))
                        {
                            temp.Request.UpdateDate = DateTime.UtcNow;
                            saveMap.AddCustomEntity(temp.Request, this);
                        }
                    }
                }
            }
            #endregion

            #region JobMaterial
            entityInfos = saveMap.Where(e => e.Key == typeof(JobMaterial)).Select(e => e.Value).FirstOrDefault();
            if (entityInfos != null)
            {
                foreach (EntityInfo entityInfo in entityInfos)
                {
                    JobMaterial jobMaterial = (JobMaterial)(entityInfo.Entity);

                    if (!saveMap.Any(e => e.Key.IsSubclassOf(typeof(Job)) && e.Value.Any(f => ((Job)f.Entity).Id == jobMaterial.JobId)))
                    {
                        // single query without lazy loading
                        var temp = (from p in Session.Query <Job>()
                                    where p.Id == jobMaterial.JobId
                                    select new { Job = p, Request = p.SourceMaterial.Request }).FirstOrDefault();

                        if (temp != null)
                        {
                            temp.Job.UpdateDate = DateTime.UtcNow;
                            saveMap.AddCustomEntity(temp.Job, this);

                            if (!saveMap.Any(e => e.Key == typeof(Request)))
                            {
                                temp.Request.UpdateDate = DateTime.UtcNow;
                                saveMap.AddCustomEntity(temp.Request, this);
                            }
                        }
                    }
                }
            }
            #endregion

            #region Reference
            entityInfos = saveMap.Where(e => e.Key == typeof(Reference)).Select(e => e.Value).FirstOrDefault();
            if (entityInfos != null)
            {
                foreach (EntityInfo entityInfo in entityInfos)
                {
                    Reference reference = (Reference)(entityInfo.Entity);
                    Request   request   = saveMap.Where(e => e.Key == typeof(Request)).SelectMany(e => e.Value).Select(c => (Request)c.Entity).FirstOrDefault();

                    if (request != null)
                    {
                        request.UpdateDate = DateTime.UtcNow;
                    }
                    else
                    {
                        // single query without lazy loading
                        request = (from p in Session.Query <Request>()
                                   where p.ReferenceSet.Id == reference.ReferenceSetId
                                   select p).FirstOrDefault();
                        if (request != null)
                        {
                            request.UpdateDate = DateTime.UtcNow;
                            saveMap.AddCustomEntity(request, this);
                        }
                    }
                }
            }
            #endregion

            #region JobComment
            entityInfos = saveMap.Where(e => e.Key == typeof(JobComment)).Select(e => e.Value).FirstOrDefault();
            if (entityInfos != null)
            {
                foreach (EntityInfo entityInfo in entityInfos)
                {
                    JobComment jobComment = (JobComment)(entityInfo.Entity);

                    // single query without lazy loading
                    var temp = (from p in Session.Query <Job>()
                                where p.Id == jobComment.JobId
                                select new { Job = p, Request = p.SourceMaterial.Request }).First();

                    temp.Job.UpdateDate = DateTime.UtcNow;
                    saveMap.AddCustomEntity(temp.Job, this);

                    if (!saveMap.Any(e => e.Key == typeof(Request)))
                    {
                        temp.Request.UpdateDate = DateTime.UtcNow;
                        saveMap.AddCustomEntity(temp.Request, this);
                    }
                }
            }
            #endregion

            #region Job
            entityInfos = saveMap.Where(e => e.Key.IsSubclassOf(typeof(Job))).Select(e => e.Value).FirstOrDefault();
            if (entityInfos != null)
            {
                foreach (EntityInfo entityInfo in entityInfos)
                {
                    if (!saveMap.Any(e => e.Key == typeof(Request)))
                    {
                        Request request = GetQuery <SourceMaterial>().Where(e => e.Id == ((Job)entityInfo.Entity).SourceMaterialId).Select(e => e.Request).FirstOrDefault();
                        if (request == null)
                        {
                            Guid?requestId = saveMap.Where(e => e.Key == typeof(SourceMaterial))
                                             .SelectMany(e => e.Value)
                                             .Select(x => (SourceMaterial)x.Entity)
                                             .Where(x => x.Id == ((Job)entityInfo.Entity).SourceMaterialId)
                                             .Select(x => x.RequestId)
                                             .SingleOrDefault();

                            if (requestId.HasValue)
                            {
                                request = GetQuery <Request>().FirstOrDefault(e => e.Id == requestId);
                            }
                        }
                        saveMap.AddCustomEntity(request, this);
                    }
                }
            }
            #endregion

            #region Material
            entityInfos = saveMap.Where(e => e.Key == typeof(Material) || e.Key.IsSubclassOf(typeof(Material))).Select(e => e.Value).FirstOrDefault();
            if (entityInfos != null)
            {
                // Update 'UploadedBy' field only for new entities
                foreach (EntityInfo entityInfo in entityInfos.Where(e => e.EntityState == EntityState.Added))
                {
                    Material material = (Material)entityInfo.Entity;
                    if (string.IsNullOrEmpty(material.UploadedBy))
                    {
                        material.UploadedBy = material.CreatedBy;
                    }
                    if (!material.UploaderType.HasValue)
                    {
                        material.UploaderType = UploaderType.Other;
                    }
                }
            }
            #endregion

            var tmp = saveMap.Where(p => p.Key.IsSubclassOf(typeof(Job)))
                      .Select(p => p.Value.Where(x => x.EntityState == EntityState.Deleted).ToList())
                      .FirstOrDefault();
            var jobs = tmp == null ? null : tmp.Select(x => (Job)x.Entity).ToList();

            var requestToChange = saveMap
                                  .Where(p => p.Key.IsAssignableFrom(typeof(Request)))
                                  .Select(p => p.Value)
                                  .FirstOrDefault();
            var smToChange = saveMap
                             .Where(p => p.Key.IsAssignableFrom(typeof(SourceMaterial)))
                             .Select(p => p.Value.Where(x => x.EntityState == EntityState.Added).ToList())
                             .FirstOrDefault();

            if (requestToChange != null)
            {
                var rq = ((Request)requestToChange.First().Entity);
                List <SourceMaterial> sms = new List <SourceMaterial>();
                sms = Session.Query <SourceMaterial>().Where(x => x.RequestId == rq.Id).Where(x => !x.Jobs.Any()).Distinct().ToList();
                if (jobs != null)
                {
                    foreach (var job in jobs)
                    {
                        sms.AddRange(Session.Query <SourceMaterial>().Where(x => x.RequestId == rq.Id).Where(v => v.Jobs.Contains(job)).Distinct().ToList());
                    }
                }

                if (rq.RequestTemplateId != null)
                {
                    foreach (var sm in sms)
                    {
                        if (!CheckForObjectTypeInSaveMap(sm, saveMap))
                        {
                            sm.UpdateDate = DateTime.UtcNow;
                            saveMap.AddCustomEntity <SourceMaterial>(sm, this);
                        }
                    }
                }
            }

            Session.Clear();
            return(saveMap);
        }