protected GarmentComodityResult GetGarmentComodities(string keyword = null)
        {
            var masterGarmentComoditiesUri = MasterDataSettings.Endpoint + $"master/garment-comodities? size={int.MaxValue}&keyword={keyword}";
            //var masterUnitUri = $"https://com-danliris-service-core-dev.azurewebsites.net/v1/master/products/simple";
            var garmentComoditiesResponse = _http.GetAsync(masterGarmentComoditiesUri).Result;

            var garmentComoditiesResult = new GarmentComodityResult();

            if (garmentComoditiesResponse.IsSuccessStatusCode)
            {
                garmentComoditiesResult = JsonConvert.DeserializeObject <GarmentComodityResult>(garmentComoditiesResponse.Content.ReadAsStringAsync().Result);
            }
            else
            {
                GetGarmentComodities(keyword);
            }
            return(garmentComoditiesResult);
        }
        public void SetGarmentComodities()
        {
            var masterGarmentComodityUri = MasterDataSettings.Endpoint + $"master/garment-comodities";
            var garmentComodityResponse  = _http.GetAsync(masterGarmentComodityUri).Result;

            var garmentComodityResult = new GarmentComodityResult();

            if (garmentComodityResponse.EnsureSuccessStatusCode().IsSuccessStatusCode)
            {
                garmentComodityResult = JsonConvert.DeserializeObject <GarmentComodityResult>(garmentComodityResponse.Content.ReadAsStringAsync().Result);
            }
            else
            {
                SetGarmentComodities();
            }
            if (garmentComodityResult.data.Count > 0)
            {
                cacheManager.Set("GarmentComodities", garmentComodityResult.data);
            }
        }
Exemplo n.º 3
0
        public async Task <CostCalculationGarmentDataProductionReport> GetDataCostCal(List <string> ro, string token)
        {
            CostCalculationGarmentDataProductionReport costCalculationGarmentDataProductionReport = new CostCalculationGarmentDataProductionReport();

            var listRO             = string.Join(",", ro.Distinct());
            var costCalculationUri = SalesDataSettings.Endpoint + $"cost-calculation-garments/data/{listRO}";
            var httpResponse       = await _http.GetAsync(costCalculationUri, token);

            var freeRO = new List <string>();

            if (httpResponse.IsSuccessStatusCode)
            {
                var contentString = await httpResponse.Content.ReadAsStringAsync();

                Dictionary <string, object> content = JsonConvert.DeserializeObject <Dictionary <string, object> >(contentString);
                var dataString = content.GetValueOrDefault("data").ToString();
                var listData   = JsonConvert.DeserializeObject <List <CostCalViewModel> >(dataString);

                foreach (var item in ro)
                {
                    var data = listData.SingleOrDefault(s => s.ro == item);
                    if (data != null)
                    {
                        costCalculationGarmentDataProductionReport.data.Add(data);
                    }
                    else
                    {
                        freeRO.Add(item);
                    }
                }
            }

            HOrderDataProductionReport hOrderDataProductionReport = await GetDataHOrder(freeRO, token);

            Dictionary <string, string> comodities = new Dictionary <string, string>();

            if (hOrderDataProductionReport.data.Count > 0)
            {
                var comodityCodes = hOrderDataProductionReport.data.Select(s => s.Kode).Distinct().ToList();
                var filter        = "{\"(" + string.Join(" || ", comodityCodes.Select(s => "Code==" + "\\\"" + s + "\\\"")) + ")\" : \"true\"}";

                var masterGarmentComodityUri = MasterDataSettings.Endpoint + $"master/garment-comodities?filter=" + filter;
                var garmentComodityResponse  = _http.GetAsync(masterGarmentComodityUri).Result;
                var garmentComodityResult    = new GarmentComodityResult();
                if (garmentComodityResponse.IsSuccessStatusCode)
                {
                    garmentComodityResult = JsonConvert.DeserializeObject <GarmentComodityResult>(garmentComodityResponse.Content.ReadAsStringAsync().Result);
                    //comodities = garmentComodityResult.data.ToDictionary(d => d.Code, d => d.Name);
                    foreach (var comodity in garmentComodityResult.data)
                    {
                        comodities[comodity.Code] = comodity.Name;
                    }
                }
            }

            foreach (var hOrder in hOrderDataProductionReport.data)
            {
                costCalculationGarmentDataProductionReport.data.Add(new CostCalViewModel
                {
                    ro           = hOrder.No,
                    buyerCode    = hOrder.Codeby,
                    comodityName = comodities.GetValueOrDefault(hOrder.Kode),
                    hours        = (double)hOrder.Sh_Cut,
                    qtyOrder     = (double)hOrder.Qty
                });
            }

            return(costCalculationGarmentDataProductionReport);
        }