Ejemplo n.º 1
0
        public void FindDetail(int LedgerId)
        {
            JournalDetail pod = JDetails.Where(x => x.LedgerId == LedgerId).FirstOrDefault();

            if (pod != null)
            {
                pod.toCopy <JournalDetail>(JDetail);
            }
        }
Ejemplo n.º 2
0
        public void DeleteDetail(int LedgerId)
        {
            JournalDetail pod = JDetails.Where(x => x.LedgerId == LedgerId).FirstOrDefault();

            if (pod != null)
            {
                JDetails.Remove(pod);
                Amount = JDetails.Sum(x => x.DrAmt) - JDetails.Sum(x => x.CrAmt);
            }
        }
Ejemplo n.º 3
0
        public void SaveDetail()
        {
            JournalDetail pod = JDetails.Where(x => x.LedgerId == JDetail.LedgerId).FirstOrDefault();

            if (pod == null)
            {
                pod = new JournalDetail();
                JDetails.Add(pod);
            }

            JDetail.toCopy <JournalDetail>(pod);
            ClearDetail();
            Amount = JDetails.Sum(x => x.DrAmt) - JDetails.Sum(x => x.CrAmt);
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> CuttingPlanImportData(
            [FromBody] IEnumerable <CuttingImportViewModel> ImportDatas,
            string UserName = "")
        {
            string Message = "";

            try
            {
                if (ImportDatas != null)
                {
                    var date = DateTime.Now;

                    foreach (var Jobs in ImportDatas.GroupBy(x => x.JobNo.Trim()))
                    {
                        var PMaster = await this.repositoryProMaster.GetAllAsQueryable()
                                      .Where(x => x.ProjectCode.Trim().ToLower()
                                             .Equals(Jobs.Key.Trim().ToLower()))
                                      .Include(x => x.ProjectCodeDetails)
                                      .ThenInclude(z => z.CuttingPlans)
                                      .FirstOrDefaultAsync();

                        if (PMaster != null)
                        {
                            foreach (var JDetails in Jobs.GroupBy(x => x.Level23.Trim()))
                            {
                                var PDetail = PMaster.ProjectCodeDetails
                                              .FirstOrDefault(x => x.ProjectCodeDetailCode.Trim()
                                                              .ToLower().Equals(JDetails.Key.Trim().ToLower()));

                                if (PDetail != null)
                                {
                                    foreach (var Import in JDetails.GroupBy(x => x.CuttingPlan.Trim() + x.MaterialSize.Trim()))
                                    {
                                        var Cutting = PDetail.CuttingPlans
                                                      .FirstOrDefault(x =>
                                                                      ((x.CuttingPlanNo != null ? x.CuttingPlanNo.ToLower() : "") +
                                                                       (x.MaterialSize != null ? x.MaterialSize.ToLower() : ""))
                                                                      .Equals(Import.Key.ToLower()));

                                        if (Cutting == null)
                                        {
                                            foreach (var import2 in Import)
                                            {
                                                double.TryParse(import2.Quantity, out double qty);
                                                // Insert CuttingPlan and Material
                                                var nCuttingPlan = new CuttingPlan()
                                                {
                                                    ProjectCodeDetailId = PDetail.ProjectCodeDetailId,
                                                    CreateDate          = date,
                                                    Creator             = UserName,
                                                    CuttingPlanNo       = import2.CuttingPlan,
                                                    Description         = "Did not has description yet",
                                                    Quantity            = qty,
                                                    TypeCuttingPlan     = TypeCuttingPlan.CuttingPlan,
                                                    MaterialSize        = string.IsNullOrEmpty(import2.MaterialSize) ? "" : import2.MaterialSize.Trim(),
                                                    MaterialGrade       = string.IsNullOrEmpty(import2.MaterialGrade) ? "" : import2.MaterialGrade.Trim(),
                                                };

                                                await this.repository.AddAsync(nCuttingPlan);
                                            }
                                        }
                                    }
                                }
                                // if don't have add all data in this level2/3
                                else
                                {
                                    // Insert ProjectDetail
                                    var nProDetail = new ProjectCodeDetail()
                                    {
                                        CreateDate            = date,
                                        Creator               = UserName,
                                        Description           = "Did not has description yet.",
                                        ProjectCodeDetailCode = JDetails.Key,
                                        ProjectCodeMasterId   = PMaster.ProjectCodeMasterId,
                                        CuttingPlans          = new List <CuttingPlan>()
                                    };

                                    foreach (var Import in JDetails)
                                    {
                                        // Insert CuttingPlan and Material
                                        double.TryParse(Import.Quantity, out double qty);

                                        var nCuttingPlan = new CuttingPlan()
                                        {
                                            CreateDate      = date,
                                            Creator         = UserName,
                                            CuttingPlanNo   = Import.CuttingPlan,
                                            Description     = "Did not has description yet",
                                            Quantity        = qty,
                                            TypeCuttingPlan = TypeCuttingPlan.CuttingPlan,
                                            MaterialSize    = string.IsNullOrEmpty(Import.MaterialSize) ? "" : Import.MaterialSize.Trim(),
                                            MaterialGrade   = string.IsNullOrEmpty(Import.MaterialGrade) ? "" : Import.MaterialGrade.Trim(),
                                        };
                                        nProDetail.CuttingPlans.Add(nCuttingPlan);
                                    }

                                    // Insert ProjectDetail to DataBase
                                    await this.repositoryProDetail.AddAsync(nProDetail);
                                }
                            }
                        }
                        // if don't have add all data in this job
                        else
                        {
                            // Insert ProjectMaster
                            var nProMaster = new ProjectCodeMaster()
                            {
                                CreateDate         = date,
                                Creator            = UserName,
                                ProjectCode        = Jobs.Key,
                                ProjectName        = "Did not has name yet.",
                                StartDate          = date,
                                ProjectCodeDetails = new List <ProjectCodeDetail>()
                            };
                            // Insert all ProjectDetail ,CuttingPlan and Material
                            foreach (var JDetails in Jobs.GroupBy(x => x.Level23))
                            {
                                // Insert ProjectDetail
                                var nProDetail = new ProjectCodeDetail()
                                {
                                    CreateDate            = date,
                                    Creator               = UserName,
                                    Description           = "Did not has description yet.",
                                    ProjectCodeDetailCode = JDetails.Key,
                                    CuttingPlans          = new List <CuttingPlan>()
                                };
                                foreach (var Import in JDetails)
                                {
                                    // Insert CuttingPlan and Material
                                    double.TryParse(Import.Quantity, out double qty);
                                    var nCuttingPlan = new CuttingPlan()
                                    {
                                        CreateDate      = date,
                                        Creator         = UserName,
                                        CuttingPlanNo   = Import.CuttingPlan,
                                        Description     = "Did not has description yet",
                                        Quantity        = qty,
                                        TypeCuttingPlan = TypeCuttingPlan.CuttingPlan,
                                        MaterialSize    = string.IsNullOrEmpty(Import.MaterialSize) ? "" : Import.MaterialSize.Trim(),
                                        MaterialGrade   = string.IsNullOrEmpty(Import.MaterialGrade) ? "" : Import.MaterialGrade.Trim(),
                                    };
                                    nProDetail.CuttingPlans.Add(nCuttingPlan);
                                }

                                nProMaster.ProjectCodeDetails.Add(nProDetail);
                            }
                            // Insert ProjectMaster to DataBase
                            await this.repositoryProMaster.AddAsync(nProMaster);
                        }
                    }

                    // alway return true
                    return(new JsonResult(true, this.DefaultJsonSettings));
                }
            }
            catch (Exception ex)
            {
                Message = $"Has error {ex.ToString()}";
            }

            return(NotFound(new { Message }));
        }