public async Task <int> UpdateCostCalAsync(CostCalculationGarment costCalculationGarment, int Id)
        {
            costCalculationGarment.SCGarmentId = Id;
            await costCalGarmentLogic.UpdateAsync((int)costCalculationGarment.Id, costCalculationGarment);

            return(await DbContext.SaveChangesAsync());
        }
Ejemplo n.º 2
0
        public async Task <int> CreateAsync(CostCalculationGarment model)
        {
            int Created = 0;

            using (var transaction = DbContext.Database.BeginTransaction())
            {
                try
                {
                    do
                    {
                        model.Code = CodeGenerator.Generate();
                        await CustomCodeGenerator(model);
                    }while (this.DbSet.Any(d => d.Code.Equals(model.Code)));

                    if (!string.IsNullOrWhiteSpace(model.ImageFile))
                    {
                        model.ImagePath = await this.AzureImageFacade.UploadImage(model.GetType().Name, model.Id, model.CreatedUtc, model.ImageFile);
                    }
                    costCalculationGarmentLogic.Create(model);
                    Created = await DbContext.SaveChangesAsync();

                    transaction.Commit();
                }
                catch (Exception e)
                {
                    transaction.Rollback();
                    throw new Exception(e.Message);
                }
            }
            return(Created);
        }
        private GarmentPurchaseRequestViewModel FillGarmentPurchaseRequest(CostCalculationGarment costCalculation, Dictionary <long, string> productDicts)
        {
            GarmentPurchaseRequestViewModel garmentPurchaseRequest = new GarmentPurchaseRequestViewModel
            {
                PRType = "JOB ORDER",
                RONo   = costCalculation.RO_Number,
                SCId   = costCalculation.PreSCId,
                SCNo   = costCalculation.PreSCNo,
                Buyer  = new BuyerViewModel
                {
                    Id   = Convert.ToInt64(costCalculation.BuyerBrandId),
                    Code = costCalculation.BuyerBrandCode,
                    Name = costCalculation.BuyerBrandName
                },
                Article      = costCalculation.Article,
                Date         = DateTimeOffset.Now,
                ShipmentDate = costCalculation.DeliveryDate,
                Unit         = new UnitViewModel
                {
                    Id   = costCalculation.UnitId,
                    Code = costCalculation.UnitCode,
                    Name = costCalculation.UnitName
                },
                IsPosted = true,

                IsValidate    = true,
                ValidatedBy   = costCalculation.LastModifiedBy,
                ValidatedDate = costCalculation.LastModifiedUtc,

                Items = FillGarmentPurchaseRequestItems(costCalculation.CostCalculationGarment_Materials.ToList(), productDicts)
            };

            return(garmentPurchaseRequest);
        }
        private GarmentPurchaseRequestViewModel FillGarmentPurchaseRequest(CostCalculationGarment costCalculation, Dictionary <long, string> productDicts)
        {
            GarmentPurchaseRequestViewModel garmentPurchaseRequest = new GarmentPurchaseRequestViewModel
            {
                RONo  = costCalculation.RO_Number,
                Buyer = new BuyerViewModel
                {
                    Id   = Convert.ToInt64(costCalculation.BuyerBrandId),
                    Code = costCalculation.BuyerBrandCode,
                    Name = costCalculation.BuyerBrandName
                },
                Article      = costCalculation.Article,
                Date         = DateTimeOffset.Now,
                ShipmentDate = costCalculation.DeliveryDate,
                Unit         = new UnitViewModel
                {
                    Id   = costCalculation.UnitId,
                    Code = costCalculation.UnitCode,
                    Name = costCalculation.UnitName
                },
                Items = FillGarmentPurchaseRequestItems(costCalculation.CostCalculationGarment_Materials.ToList(), productDicts)
            };

            return(garmentPurchaseRequest);
        }
        public async Task <int> CreateAsync(RO_Garment Model)
        {
            do
            {
                Model.Code = Code.Generate();
            }while (this.DbSet.Any(d => d.Code.Equals(Model.Code)));

            CostCalculationGarment costCalculationGarment = await costCalGarmentLogic.ReadByIdAsync((int)Model.CostCalculationGarment.Id); //Model.CostCalculationGarment;

            foreach (var item in costCalculationGarment.CostCalculationGarment_Materials)
            {
                foreach (var itemModel in Model.CostCalculationGarment.CostCalculationGarment_Materials)
                {
                    if (item.Id == itemModel.Id)
                    {
                        item.Information = itemModel.Information;
                    }
                }
            }
            Model.CostCalculationGarment = null;

            roGarmentLogic.Create(Model);
            int created = await DbContext.SaveChangesAsync();

            Model.ImagesPath = await AzureImageFacade.UploadMultipleImage(Model.GetType().Name, (int)Model.Id, Model.CreatedUtc, Model.ImagesFile, Model.ImagesPath);

            Model.DocumentsPath = await AzureDocumentFacade.UploadMultipleFile(Model.GetType().Name, (int)Model.Id, Model.CreatedUtc, Model.DocumentsFile, Model.DocumentsFileName, Model.DocumentsPath);

            await UpdateCostCalAsync(costCalculationGarment, (int)Model.Id);

            return(created);
        }
        public async Task <int> ValidateROGarment(CostCalculationGarment CostCalculationGarment, Dictionary <long, string> productDicts)
        {
            int Updated = 0;

            using (var transaction = DbContext.Database.BeginTransaction())
            {
                try
                {
                    var model = this.DbSet
                                .Include(m => m.CostCalculationGarment_Materials)
                                .FirstOrDefault(m => m.Id == CostCalculationGarment.Id);

                    EntityExtension.FlagForUpdate(model, IdentityService.Username, "sales-service");
                    model.IsValidated = true;
                    foreach (var material in model.CostCalculationGarment_Materials)
                    {
                        var sentMaterial = CostCalculationGarment.CostCalculationGarment_Materials.FirstOrDefault(m => m.Id == material.Id);
                        if (sentMaterial != null)
                        {
                            material.IsPosted = true;
                            EntityExtension.FlagForUpdate(material, IdentityService.Username, "sales-service");
                        }
                    }
                    DbSet.Update(model);

                    Updated = await DbContext.SaveChangesAsync();

                    model.CostCalculationGarment_Materials = model.CostCalculationGarment_Materials.Where(material => CostCalculationGarment.CostCalculationGarment_Materials.Any(oldMaterial => oldMaterial.Id == material.Id)).ToList();

                    if (CostCalculationGarment.CostCalculationGarment_Materials.All(m => !m.CategoryName.ToUpper().Equals("PROCESS")))
                    {
                        await RO_Garment_ValidationLogic.CreateGarmentPurchaseRequest(model, productDicts);
                    }
                    else if (CostCalculationGarment.CostCalculationGarment_Materials.All(m => m.CategoryName.ToUpper().Equals("PROCESS")))
                    {
                        await RO_Garment_ValidationLogic.AddItemsGarmentPurchaseRequest(model, productDicts);
                    }
                    else
                    {
                        throw new Exception("Kategori Ada Proses dan Lainnnya");
                    }

                    transaction.Commit();
                }
                //catch (ServiceValidationException e)
                //{
                //    transaction.Rollback();
                //    throw new ServiceValidationException(e.Message, null, null);
                //}
                catch (Exception e)
                {
                    transaction.Rollback();
                    throw new Exception(e.Message);
                }
            }
            return(Updated);
        }
Ejemplo n.º 7
0
 public async Task <int> UpdateAsync(int id, CostCalculationGarment model)
 {
     costCalculationGarmentLogic.UpdateAsync(id, model);
     if (!string.IsNullOrWhiteSpace(model.ImageFile))
     {
         model.ImagePath = await this.AzureImageFacade.UploadImage(model.GetType().Name, model.Id, model.CreatedUtc, model.ImageFile);
     }
     return(await DbContext.SaveChangesAsync());
 }
        public async Task CreateGarmentPurchaseRequest(CostCalculationGarment costCalculationGarment, Dictionary <long, string> productDicts)
        {
            var httpClient = serviceProvider.GetService <IHttpClientService>();

            var stringContent = JsonConvert.SerializeObject(FillGarmentPurchaseRequest(costCalculationGarment, productDicts));
            var httpContent   = new StringContent(stringContent, Encoding.UTF8, General.JsonMediaType);

            var httpResponseMessage = await httpClient.PostAsync($@"{APIEndpoint.AzurePurchasing}{GarmentPurchaseRequestUri}", httpContent);

            CheckResponse(httpResponseMessage);
        }
Ejemplo n.º 9
0
        public async Task <int> UpdateAsync(int id, RO_Garment Model)
        {
            CostCalculationGarment costCalculationGarment = Model.CostCalculationGarment;

            Model.CostCalculationGarment = null;

            Model.ImagesPath = await this.AzureImageFacade.UploadMultipleImage(Model.GetType().Name, (int)Model.Id, Model.CreatedUtc, Model.ImagesFile, Model.ImagesPath);

            roGarmentLogic.UpdateAsync(id, Model);
            await DbContext.SaveChangesAsync();

            return(await UpdateCostCalAsync(costCalculationGarment, (int)Model.Id));
        }
        public async Task <int> DeleteAsync(int id)
        {
            GarmentSalesContract sc = await ReadByIdAsync(id);

            CostCalculationGarment costCal = await DbContext.CostCalculationGarments.FirstOrDefaultAsync(a => a.Id.Equals(sc.CostCalculationId));

            costCal.SCGarmentId = null;
            await costCalGarmentLogic.UpdateAsync((int)sc.CostCalculationId, costCal);

            await garmentSalesContractLogic.DeleteAsync(id);

            return(await DbContext.SaveChangesAsync());
        }
        public async Task <int> DeletedROCostCalAsync(CostCalculationGarment costCalculationGarment, int Id)
        {
            CostCalculationGarment costCal = await costCalGarmentLogic.ReadByIdAsync((int)costCalculationGarment.Id); //Model.CostCalculationGarment;

            costCal.RO_GarmentId = null;
            costCal.ImageFile    = string.IsNullOrWhiteSpace(costCal.ImageFile) ? "#" : costCal.ImageFile;
            foreach (var item in costCal.CostCalculationGarment_Materials)
            {
                item.Information = null;
            }
            await costCalGarmentLogic.UpdateAsync((int)costCal.Id, costCal);

            return(await DbContext.SaveChangesAsync());
        }
Ejemplo n.º 12
0
        public async Task <CostCalculationGarment> ReadByIdAsync(int id)
        {
            CostCalculationGarment read = await this.DbSet
                                          .Where(d => d.Id.Equals(id) && d.IsDeleted.Equals(false))
                                          .Include(d => d.CostCalculationGarment_Materials)
                                          .FirstOrDefaultAsync();

            if (read.ImagePath != null)
            {
                read.ImageFile = await this.AzureImageFacade.DownloadImage(read.GetType().Name, read.ImagePath);
            }

            return(read);
        }
Ejemplo n.º 13
0
        public override async Task <int> UpdateModel(int Id, RO_Garment Model)
        {
            CostCalculationGarment costCalculationGarment = Model.CostCalculationGarment;

            Model.CostCalculationGarment = null;

            Model.ImagesPath = await this.AzureImageService.UploadMultipleImage(Model.GetType().Name, Model.Id, Model._CreatedUtc, Model.ImagesFile, Model.ImagesPath);

            int updated = await this.UpdateAsync(Id, Model);

            costCalculationGarment.RO_GarmentId = Model.Id;
            await this.CostCalculationGarmentService.UpdateModel(costCalculationGarment.Id, costCalculationGarment);

            return(updated);
        }
        public async Task <CostCalculationGarment> ReadByRO(string ro)
        {
            CostCalculationGarment read = await this.DbSet
                                          .Where(d => d.RO_Number.Equals(ro) && d.IsDeleted.Equals(false))
                                          .Include(d => d.CostCalculationGarment_Materials)
                                          .FirstOrDefaultAsync();

            read.CostCalculationGarment_Materials = read.CostCalculationGarment_Materials.OrderBy(o => o.MaterialIndex).ToList();

            if (read.ImagePath != null)
            {
                read.ImageFile = await this.AzureImageFacade.DownloadImage(read.GetType().Name, read.ImagePath);
            }

            return(read);
        }
        public async Task <int> CreateAsync(GarmentSalesContract model)
        {
            //do
            //{
            //    model.Code = CodeGenerator.Generate();
            //}
            //while (this.DbSet.Any(d => d.Code.Equals(model.Code)));
            CostCalculationGarment costCal = await DbContext.CostCalculationGarments.FirstOrDefaultAsync(a => a.Id.Equals(model.CostCalculationId));

            //costCal.SCGarmentId=
            garmentSalesContractLogic.Create(model);

            await DbContext.SaveChangesAsync();

            return(await UpdateCostCalAsync(costCal, (int)model.Id));
        }
 GarmentProductionOrderReportDetailViewModel GetGarmentProductionOrder(CostCalculationGarment cc)
 {
     return(new GarmentProductionOrderReportDetailViewModel
     {
         Section = cc.Section,
         Commodity = cc.Commodity,
         Article = cc.Article,
         RONo = cc.RO_Number,
         Date = cc.CreatedUtc.AddHours(identityService.TimezoneOffset),
         Quantity = cc.Quantity,
         Uom = cc.UOMUnit,
         ConfirmPrice = cc.ConfirmPrice,
         Amount = cc.Quantity * cc.ConfirmPrice,
         ConfirmDate = cc.ConfirmDate.ToOffset(TimeSpan.FromHours(identityService.TimezoneOffset)).DateTime,
         ShipmentDate = cc.DeliveryDate.ToOffset(TimeSpan.FromHours(identityService.TimezoneOffset)).DateTime,
         ValidationPPIC = cc.IsApprovedKadivMD ? "SUDAH" : "BELUM"
     });
 }
Ejemplo n.º 17
0
        public async Task <int> CreateAsync(CostCalculationGarment model)
        {
            do
            {
                model.Code = CodeGenerator.Generate();
                await CustomCodeGenerator(model);
            }while (this.DbSet.Any(d => d.Code.Equals(model.Code)));

            model.ImagePath = await this.AzureImageFacade.UploadImage(model.GetType().Name, model.Id, model.CreatedUtc, model.ImageFile);

            costCalculationGarmentLogic.Create(model);
            if (model.ImagePath != null)
            {
                model.ImagePath = await this.AzureImageFacade.UploadImage(model.GetType().Name, model.Id, model.CreatedUtc, model.ImageFile);
            }
            model.IsValidated = false;
            costCalculationGarmentLogic.Create(model);
            return(await DbContext.SaveChangesAsync());
        }
        private async void ApproveData(CostCalculationGarment data, CostCalculationGarmentFacade costCalculationGarmentFacade)
        {
            var AvailableBy = "AvailableBy";

            await costCalculationGarmentFacade.AcceptanceCC(new List <long> {
                data.Id
            }, AvailableBy);

            await costCalculationGarmentFacade.AvailableCC(new List <long> {
                data.Id
            }, AvailableBy);

            JsonPatchDocument <CostCalculationGarment> jsonPatch = new JsonPatchDocument <CostCalculationGarment>();

            jsonPatch.Replace(m => m.IsApprovedPPIC, true);
            jsonPatch.Replace(m => m.ApprovedPPICBy, "Super Man");
            jsonPatch.Replace(m => m.ApprovedPPICDate, DateTimeOffset.Now);

            await costCalculationGarmentFacade.Patch(data.Id, jsonPatch);
        }
        public async Task AddItemsGarmentPurchaseRequest(CostCalculationGarment costCalculationGarment, Dictionary <long, string> productDicts)
        {
            var httpClient = serviceProvider.GetService <IHttpClientService>();

            var oldGarmentPurchaseRequest = await GetGarmentPurchaseRequestByRONo(costCalculationGarment.RO_Number);

            var garmentPurchaseRequest = FillGarmentPurchaseRequest(costCalculationGarment, productDicts);

            //garmentPurchaseRequest.Id = oldGarmentPurchaseRequest.Id;

            foreach (var item in garmentPurchaseRequest.Items)
            {
                oldGarmentPurchaseRequest.Items.Add(item);
            }

            var stringContent = JsonConvert.SerializeObject(oldGarmentPurchaseRequest);
            var httpContent   = new StringContent(stringContent, Encoding.UTF8, General.JsonMediaType);

            var httpResponseMessage = await httpClient.PutAsync($@"{APIEndpoint.AzurePurchasing}{GarmentPurchaseRequestUri}/{oldGarmentPurchaseRequest.Id}", httpContent);

            CheckResponse(httpResponseMessage);
        }
Ejemplo n.º 20
0
        public override async Task <int> DeleteModel(int Id)
        {
            RO_Garment deletedImage = await this.GetAsync(Id);

            await this.AzureImageService.RemoveMultipleImage(deletedImage.GetType().Name, deletedImage.ImagesPath);

            int deleted = await this.DeleteAsync(Id);

            CostCalculationGarment costCalculationGarment = await this.CostCalculationGarmentService.ReadModelById(deletedImage.CostCalculationGarmentId);

            costCalculationGarment.RO_GarmentId = null;
            await this.CostCalculationGarmentService.UpdateModel(costCalculationGarment.Id, costCalculationGarment);

            List <CostCalculationGarment_Material> costCalculationGarment_Materials = this.CostCalculationGarment_MaterialService.DbSet.Where(p => p.CostCalculationGarmentId.Equals(costCalculationGarment.Id)).ToList();

            foreach (CostCalculationGarment_Material costCalculationGarment_Material in costCalculationGarment_Materials)
            {
                costCalculationGarment_Material.Information = null;
                await this.CostCalculationGarment_MaterialService.UpdateModel(costCalculationGarment_Material.Id, costCalculationGarment_Material);
            }

            return(deleted);
        }
Ejemplo n.º 21
0
        public async Task <int> CreateAsync(RO_Garment Model)
        {
            do
            {
                Model.Code = Code.Generate();
            }while (this.DbSet.Any(d => d.Code.Equals(Model.Code)));

            CostCalculationGarment costCalculationGarment = await costCalGarmentLogic.ReadByIdAsync((int)Model.CostCalculationGarment.Id); //Model.CostCalculationGarment;

            Model.CostCalculationGarment = null;

            Model.ImagesPath = await this.AzureImageFacade.UploadMultipleImage(Model.GetType().Name, (int)Model.Id, Model.CreatedUtc, Model.ImagesFile, Model.ImagesPath);

            roGarmentLogic.Create(Model);
            await DbContext.SaveChangesAsync();

            //Model.ImagesPath = await this.AzureImageService.UploadMultipleImage(Model.GetType().Name, Model.Id, Model._CreatedUtc, Model.ImagesFile, Model.ImagesPath);

            //await this.UpdateAsync((int)Model.Id, Model);
            //update CostCal

            return(await UpdateCostCalAsync(costCalculationGarment, (int)Model.Id));
        }
Ejemplo n.º 22
0
        public async Task <CostCalculationGarment> CustomCodeGenerator(CostCalculationGarment Model)
        {
            List <string> convectionOption = new List <string> {
                "C2A", "C2B", "C2C", "C1A", "C1B"
            };
            int convectionCode = convectionOption.IndexOf(Model.UnitCode) + 1;

            var lastData = await this.DbSet.Where(w => w.IsDeleted == false && w.UnitCode == Model.UnitCode).OrderByDescending(o => o.CreatedUtc).FirstOrDefaultAsync();

            DateTime Now  = DateTime.Now;
            string   Year = Now.ToString("yy");

            if (lastData == null)
            {
                Model.AutoIncrementNumber = 1;
                string Number = Model.AutoIncrementNumber.ToString().PadLeft(4, '0');
                Model.RO_Number = $"{Year}{convectionCode.ToString()}{Number}";
            }
            else
            {
                if (lastData.CreatedUtc.Year < Now.Year)
                {
                    Model.AutoIncrementNumber = 1;
                    string Number = Model.AutoIncrementNumber.ToString().PadLeft(4, '0');
                    Model.RO_Number = $"{Year}{convectionCode.ToString()}{Number}";
                }
                else
                {
                    Model.AutoIncrementNumber = lastData.AutoIncrementNumber + 1;
                    string Number = Model.AutoIncrementNumber.ToString().PadLeft(4, '0');
                    Model.RO_Number = $"{Year}{convectionCode.ToString()}{Number}";
                }
            }

            return(Model);
        }