private async Task CreateInventoryDocumentOut(ShipmentDocumentModel model) { string referenceType = string.IsNullOrWhiteSpace(model.StorageName) ? model.StorageName : ""; var inventoryDoc = new InventoryDocumentViewModel() { date = model.DeliveryDate, referenceType = $"Pengiriman Barang {referenceType}", referenceNo = model.Code, remark = "Pengiriman Barang", type = "OUT", storageId = model.StorageId, storageCode = model.StorageCode, storageName = model.StorageName, items = new List <InventoryDocumentItemViewModel>() }; foreach (var detail in model.Details) { foreach (var item in detail.Items) { foreach (var packingReceiptItem in item.PackingReceiptItems) { var data = new InventoryDocumentItemViewModel { productCode = packingReceiptItem.ProductCode, productName = packingReceiptItem.ProductName, productId = packingReceiptItem.ProductId, remark = packingReceiptItem.Remark, quantity = packingReceiptItem.Quantity, uomId = packingReceiptItem.UOMId, stockPlanning = 0, uom = packingReceiptItem.UOMUnit }; inventoryDoc.items.Add(data); } } } string uri = "inventory-documents"; var httpClient = (IHttpClientService)_ServiceProvider.GetService(typeof(IHttpClientService)); var response = await httpClient.PostAsync($"{APIEndpoint.Inventory}{uri}", new StringContent(JsonConvert.SerializeObject(inventoryDoc).ToString(), Encoding.UTF8, "application/json")); response.EnsureSuccessStatusCode(); }
private async Task CreateInventory(PackingReceiptModel model) { var client = ServiceProvider.GetService <IHttpClientService>(); var uri = string.Format("{0}{1}", APIEndpoint.Inventory, "inventory-documents"); InventoryDocumentViewModel inventoryDoc = new InventoryDocumentViewModel(); inventoryDoc.referenceNo = "RFNO" + " - " + model.Code; string referenceType = string.IsNullOrWhiteSpace(model.StorageName) ? model.StorageName : ""; inventoryDoc.referenceType = $"Penerimaan Packing {referenceType}"; inventoryDoc.remark = " "; inventoryDoc.type = "IN"; inventoryDoc.date = DateTime.UtcNow; inventoryDoc.storageId = (model.StorageId); inventoryDoc.storageCode = (model.StorageCode); inventoryDoc.storageName = model.StorageName; inventoryDoc.items = new List <InventoryDocumentItemViewModel>(); foreach (var item in model.Items) { var data = new InventoryDocumentItemViewModel { productCode = item.ProductCode, productName = item.Product, productId = item.ProductId, remark = item.Remark, quantity = item.Quantity, uomId = item.UomId, stockPlanning = 0, uom = item.Uom }; inventoryDoc.items.Add(data); } var myContentJson = JsonConvert.SerializeObject(inventoryDoc, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); var myContent = new StringContent(myContentJson, Encoding.UTF8, "application/json"); var response = await client.PostAsync(uri, myContent); response.EnsureSuccessStatusCode(); }
public void CreateInventoryDocument(StockTransferNote Model, string Type, string Context) { StockTransferNoteViewModel ViewModel = MapToViewModel(Model); string inventoryDocumentURI = "inventory/inventory-documents"; HttpClient httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Token); /* Create Inventory Document */ List <InventoryDocumentItemViewModel> inventoryDocumentItems = new List <InventoryDocumentItemViewModel>(); foreach (StockTransferNote_ItemViewModel stni in ViewModel.StockTransferNoteItems) { InventoryDocumentItemViewModel inventoryDocumentItem = new InventoryDocumentItemViewModel { productId = stni.Summary.productId, productCode = stni.Summary.productCode, productName = stni.Summary.productName, quantity = stni.TransferedQuantity != null ? (double)stni.TransferedQuantity : 0, uomId = stni.Summary.uomId, uom = stni.Summary.uom }; inventoryDocumentItems.Add(inventoryDocumentItem); } InventoryDocumentViewModel inventoryDocument = new InventoryDocumentViewModel { date = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.fffZ"), referenceNo = Model.ReferenceNo, referenceType = Model.ReferenceType, type = Type, storageId = string.Equals(Context.ToUpper(), "CREATE") || string.Equals(Context.ToUpper(), "DELETE-SOURCE") ? Model.SourceStorageId : Model.TargetStorageId, storageCode = string.Equals(Context.ToUpper(), "CREATE") || string.Equals(Context.ToUpper(), "DELETE-SOURCE") ? Model.SourceStorageCode : Model.TargetStorageCode, storageName = string.Equals(Context.ToUpper(), "CREATE") || string.Equals(Context.ToUpper(), "DELETE-SOURCE") ? Model.SourceStorageName : Model.TargetStorageName, items = inventoryDocumentItems }; var response = httpClient.PostAsync($"{APIEndpoint.Inventory}{inventoryDocumentURI}", new StringContent(JsonConvert.SerializeObject(inventoryDocument).ToString(), Encoding.UTF8, General.JsonMediaType)).Result; response.EnsureSuccessStatusCode(); }
public async Task CreateInventory(PackingReceiptModel model) { using (var client = new HttpClient()) { var uri = new Uri(string.Format("{0}{1}", APIEndpoint.Inventory, "inventory-documents")); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", IdentityService.Token); InventoryDocumentViewModel inventoryDoc = new InventoryDocumentViewModel(); inventoryDoc.referenceNo = "RFNO" + " - " + model.Code; string referenceType = string.IsNullOrWhiteSpace(model.StorageName) ? model.StorageName : ""; inventoryDoc.referenceType = $"Penerimaan Packing {referenceType}"; inventoryDoc.remark = " "; inventoryDoc.type = "IN"; inventoryDoc.date = DateTime.UtcNow; inventoryDoc.storageId = (model.StorageId); inventoryDoc.storageCode = (model.StorageCode); inventoryDoc.storageName = model.StorageName; inventoryDoc.items = new List <InventoryDocumentItemViewModel>(); foreach (var item in model.Items) { var data = new InventoryDocumentItemViewModel(); data.productCode = item.ProductCode; data.productName = item.Product; data.productId = item.ProductId; data.remark = item.Remark; data.quantity = item.Quantity; data.uomId = item.UomId; data.stockPlanning = 0; data.uom = item.Uom; inventoryDoc.items.Add(data); } var myContentJson = JsonConvert.SerializeObject(inventoryDoc, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); var myContent = new StringContent(myContentJson, Encoding.UTF8, "application/json"); var response = await client.PostAsync(uri, myContent); response.EnsureSuccessStatusCode(); } }
public void CreateInventoryDocument(FPReturnInvToPurchasing model, string Type) { string inventoryDocumentURI = "inventory/inventory-documents"; string storageURI = "master/storages"; string uomURI = "master/uoms"; HttpClientService httpClient = (HttpClientService)this.serviceProvider.GetService(typeof(HttpClientService)); #region UOM Dictionary <string, object> filterUOM = new Dictionary <string, object> { { "unit", "MTR" } }; var responseUOM = httpClient.GetAsync($@"{APIEndpoint.Core}{uomURI}?filter=" + JsonConvert.SerializeObject(filterUOM)).Result.Content.ReadAsStringAsync(); Dictionary <string, object> resultUOM = JsonConvert.DeserializeObject <Dictionary <string, object> >(responseUOM.Result); var jsonUOM = resultUOM.Single(p => p.Key.Equals("data")).Value; Dictionary <string, object> uom = JsonConvert.DeserializeObject <List <Dictionary <string, object> > >(jsonUOM.ToString())[0]; #endregion UOM #region Storage var storageName = model.UnitName.Equals("PRINTING") ? "Gudang Greige Printing" : "Gudang Greige Finishing"; Dictionary <string, object> filterStorage = new Dictionary <string, object> { { "name", storageName } }; var responseStorage = httpClient.GetAsync($@"{APIEndpoint.Core}{storageURI}?filter=" + JsonConvert.SerializeObject(filterStorage)).Result.Content.ReadAsStringAsync(); Dictionary <string, object> resultStorage = JsonConvert.DeserializeObject <Dictionary <string, object> >(responseStorage.Result); var jsonStorage = resultStorage.Single(p => p.Key.Equals("data")).Value; Dictionary <string, object> storage = JsonConvert.DeserializeObject <List <Dictionary <string, object> > >(jsonStorage.ToString())[0]; #endregion Storage #region Inventory Document List <InventoryDocumentItemViewModel> inventoryDocumentItems = new List <InventoryDocumentItemViewModel>(); foreach (FPReturnInvToPurchasingDetail detail in model.FPReturnInvToPurchasingDetails) { InventoryDocumentItemViewModel inventoryDocumentItem = new InventoryDocumentItemViewModel(); inventoryDocumentItem.productId = detail.ProductId; inventoryDocumentItem.productCode = detail.ProductCode; inventoryDocumentItem.productName = detail.ProductName; inventoryDocumentItem.quantity = detail.Length; inventoryDocumentItem.uomId = uom["_id"].ToString(); inventoryDocumentItem.uom = uom["unit"].ToString(); inventoryDocumentItems.Add(inventoryDocumentItem); } InventoryDocumentViewModel inventoryDocument = new InventoryDocumentViewModel { date = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.fffZ"), referenceNo = model.No, referenceType = "Bon Retur Barang - Pembelian", type = Type, storageId = storage["_id"].ToString(), storageCode = storage["code"].ToString(), storageName = storage["name"].ToString(), items = inventoryDocumentItems }; var response = httpClient.PostAsync($"{APIEndpoint.Inventory}{inventoryDocumentURI}", new StringContent(JsonConvert.SerializeObject(inventoryDocument).ToString(), Encoding.UTF8, General.JsonMediaType)).Result; response.EnsureSuccessStatusCode(); #endregion Inventory Document }
public void CreateInventoryDocument(MaterialDistributionNote Model, string Type) { string inventoryDocumentURI = "inventory/inventory-documents"; string storageURI = "master/storages"; string uomURI = "master/uoms"; HttpClient httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Token); /* Get UOM */ Dictionary <string, object> filterUOM = new Dictionary <string, object> { { "unit", "MTR" } }; var responseUOM = httpClient.GetAsync($@"{APIEndpoint.Core}{uomURI}?filter=" + JsonConvert.SerializeObject(filterUOM)).Result.Content.ReadAsStringAsync(); Dictionary <string, object> resultUOM = JsonConvert.DeserializeObject <Dictionary <string, object> >(responseUOM.Result); var jsonUOM = resultUOM.Single(p => p.Key.Equals("data")).Value; Dictionary <string, object> uom = JsonConvert.DeserializeObject <List <Dictionary <string, object> > >(jsonUOM.ToString())[0]; /* Get Storage */ var storageName = Model.UnitName.Equals("PRINTING") ? "Gudang Greige Printing" : "Gudang Greige Finishing"; Dictionary <string, object> filterStorage = new Dictionary <string, object> { { "name", storageName } }; var responseStorage = httpClient.GetAsync($@"{APIEndpoint.Core}{storageURI}?filter=" + JsonConvert.SerializeObject(filterStorage)).Result.Content.ReadAsStringAsync(); Dictionary <string, object> resultStorage = JsonConvert.DeserializeObject <Dictionary <string, object> >(responseStorage.Result); var jsonStorage = resultStorage.Single(p => p.Key.Equals("data")).Value; Dictionary <string, object> storage = JsonConvert.DeserializeObject <List <Dictionary <string, object> > >(jsonStorage.ToString())[0]; /* Create Inventory Document */ List <InventoryDocumentItemViewModel> inventoryDocumentItems = new List <InventoryDocumentItemViewModel>(); List <MaterialDistributionNoteDetail> mdnds = new List <MaterialDistributionNoteDetail>(); foreach (MaterialDistributionNoteItem mdni in Model.MaterialDistributionNoteItems) { mdnds.AddRange(mdni.MaterialDistributionNoteDetails); } //List<MaterialDistributionNoteDetail> list = mdnds // .GroupBy(m => new { m.ProductId, m.ProductCode, m.ProductName }) // .Select(s => new MaterialDistributionNoteDetail // { // ProductId = s.First().ProductId, // ProductCode = s.First().ProductCode, // ProductName = s.First().ProductName, // ReceivedLength = s.Sum(d => d.ReceivedLength), // MaterialRequestNoteItemLength = s.Sum(d => d.MaterialRequestNoteItemLength) // }).ToList(); foreach (MaterialDistributionNoteDetail mdnd in mdnds) { InventoryDocumentItemViewModel inventoryDocumentItem = new InventoryDocumentItemViewModel { productId = mdnd.ProductId, productCode = mdnd.ProductCode, productName = mdnd.ProductName, quantity = mdnd.ReceivedLength, stockPlanning = Model.Type != "RE-GRADING" ? (mdnd.DistributedLength == 0 ? mdnd.MaterialRequestNoteItemLength - mdnd.ReceivedLength : mdnd.ReceivedLength * -1) : mdnd.ReceivedLength * -1, uomId = uom["_id"].ToString(), uom = uom["unit"].ToString() }; inventoryDocumentItems.Add(inventoryDocumentItem); } List <InventoryDocumentItemViewModel> list = inventoryDocumentItems .GroupBy(m => new { m.productId, m.productCode, m.productName }) .Select(s => new InventoryDocumentItemViewModel { productId = s.First().productId, productCode = s.First().productCode, productName = s.First().productName, quantity = s.Sum(d => d.quantity), stockPlanning = s.Sum(d => d.stockPlanning), uom = s.First().uom, uomId = s.First().uomId }).ToList(); InventoryDocumentViewModel inventoryDocument = new InventoryDocumentViewModel { date = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.fffZ"), referenceNo = Model.No, referenceType = "Bon Pengantar Greige", type = Type, storageId = storage["_id"].ToString(), storageCode = storage["code"].ToString(), storageName = storage["name"].ToString(), items = list }; var response = httpClient.PostAsync($"{APIEndpoint.Inventory}{inventoryDocumentURI}", new StringContent(JsonConvert.SerializeObject(inventoryDocument).ToString(), Encoding.UTF8, General.JsonMediaType)).Result; response.EnsureSuccessStatusCode(); }
public void CreateInventoryDocument(Models.FpRegradingResultDocs Model, string Type) { string inventoryDocumentURI = "inventory/inventory-documents"; string storageURI = "master/storages"; string uomURI = "master/uoms"; HttpClient httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Token); /* Get UOM */ Dictionary <string, object> filterUOM = new Dictionary <string, object> { { "unit", "MTR" } }; var responseUOM = httpClient.GetAsync($@"{APIEndpoint.Core}{uomURI}?filter=" + JsonConvert.SerializeObject(filterUOM)).Result.Content.ReadAsStringAsync(); Dictionary <string, object> resultUOM = JsonConvert.DeserializeObject <Dictionary <string, object> >(responseUOM.Result); var jsonUOM = resultUOM.Single(p => p.Key.Equals("data")).Value; Dictionary <string, object> uom = JsonConvert.DeserializeObject <List <Dictionary <string, object> > >(jsonUOM.ToString())[0]; /* Get Storage */ var storageName = Model.UnitName.Equals("PRINTING") ? "Gudang Greige Printing" : "Gudang Greige Finishing"; Dictionary <string, object> filterStorage = new Dictionary <string, object> { { "name", storageName } }; var responseStorage = httpClient.GetAsync($@"{APIEndpoint.Core}{storageURI}?filter=" + JsonConvert.SerializeObject(filterStorage)).Result.Content.ReadAsStringAsync(); Dictionary <string, object> resultStorage = JsonConvert.DeserializeObject <Dictionary <string, object> >(responseStorage.Result); var jsonStorage = resultStorage.Single(p => p.Key.Equals("data")).Value; Dictionary <string, object> storage = JsonConvert.DeserializeObject <List <Dictionary <string, object> > >(jsonStorage.ToString())[0]; /* Create Inventory Document */ List <InventoryDocumentItemViewModel> inventoryDocumentItems = new List <InventoryDocumentItemViewModel>(); InventoryDocumentItemViewModel inventoryDocumentItem = new InventoryDocumentItemViewModel(); double TotalLength = 0; foreach (FpRegradingResultDocsDetails o in Model.Details) { TotalLength += o.Length; //inventoryDocumentItem = new InventoryDocumentItemViewModel //{ //productId = o.ProductId, //productCode = o.ProductCode, //productName = o.ProductName, //quantity = o.Length, //uomId = uom["_id"].ToString(), //uom = uom["unit"].ToString() //}; //inventoryDocumentItems.Add(inventoryDocumentItem); } inventoryDocumentItem.productId = Model.ProductId; inventoryDocumentItem.productCode = Model.ProductCode; inventoryDocumentItem.productName = Model.ProductName; inventoryDocumentItem.quantity = TotalLength; inventoryDocumentItem.uomId = uom["_id"].ToString(); inventoryDocumentItem.uom = uom["unit"].ToString(); inventoryDocumentItems.Add(inventoryDocumentItem); InventoryDocumentViewModel inventoryDocument = new InventoryDocumentViewModel { date = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.fffZ"), referenceNo = Model.Code, referenceType = "Bon Hasil Re-grading", type = Type, storageId = storage["_id"].ToString(), storageCode = storage["code"].ToString(), storageName = storage["name"].ToString(), items = inventoryDocumentItems }; var response = httpClient.PostAsync($"{APIEndpoint.Inventory}{inventoryDocumentURI}", new StringContent(JsonConvert.SerializeObject(inventoryDocument).ToString(), Encoding.UTF8, General.JsonMediaType)).Result; response.EnsureSuccessStatusCode(); }
public void CreateInventoryDocument(MaterialsRequestNote Model, string Type) { string inventoryDocumentURI = "inventory/inventory-documents"; string storageURI = "master/storages"; string uomURI = "master/uoms"; HttpClient httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Token); /* Get UOM */ Dictionary <string, object> filterUOM = new Dictionary <string, object> { { "unit", "MTR" } }; var responseUOM = httpClient.GetAsync($@"{APIEndpoint.Core}{uomURI}?filter=" + JsonConvert.SerializeObject(filterUOM)).Result.Content.ReadAsStringAsync(); Dictionary <string, object> resultUOM = JsonConvert.DeserializeObject <Dictionary <string, object> >(responseUOM.Result); var jsonUOM = resultUOM.Single(p => p.Key.Equals("data")).Value; Dictionary <string, object> uom = JsonConvert.DeserializeObject <List <Dictionary <string, object> > >(jsonUOM.ToString())[0]; /* Get Storage */ var storageName = Model.UnitName.Equals("PRINTING") ? "Gudang Greige Printing" : "Gudang Greige Finishing"; Dictionary <string, object> filterStorage = new Dictionary <string, object> { { "name", storageName } }; var responseStorage = httpClient.GetAsync($@"{APIEndpoint.Core}{storageURI}?filter=" + JsonConvert.SerializeObject(filterStorage)).Result.Content.ReadAsStringAsync(); Dictionary <string, object> resultStorage = JsonConvert.DeserializeObject <Dictionary <string, object> >(responseStorage.Result); var jsonStorage = resultStorage.Single(p => p.Key.Equals("data")).Value; Dictionary <string, object> storage = JsonConvert.DeserializeObject <List <Dictionary <string, object> > >(jsonStorage.ToString())[0]; /* Create Inventory Document */ List <InventoryDocumentItemViewModel> inventoryDocumentItems = new List <InventoryDocumentItemViewModel>(); List <MaterialsRequestNote_Item> list = Model.MaterialsRequestNote_Items .GroupBy(m => new { m.ProductId, m.ProductCode, m.ProductName }) .Select(s => new MaterialsRequestNote_Item { ProductId = s.First().ProductId, ProductCode = s.First().ProductCode, ProductName = s.First().ProductName, Length = s.Sum(d => d.Length) }).ToList(); foreach (MaterialsRequestNote_Item item in list) { InventoryDocumentItemViewModel inventoryDocumentItem = new InventoryDocumentItemViewModel(); inventoryDocumentItem.productId = item.ProductId; inventoryDocumentItem.productCode = item.ProductCode; inventoryDocumentItem.productName = item.ProductName; inventoryDocumentItem.quantity = item.Length; inventoryDocumentItem.uomId = uom["_id"].ToString(); inventoryDocumentItem.uom = uom["unit"].ToString(); inventoryDocumentItems.Add(inventoryDocumentItem); } InventoryDocumentViewModel inventoryDocument = new InventoryDocumentViewModel { date = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.fffZ"), referenceNo = Model.Code, referenceType = "Surat Permintaan Barang", type = Type, storageId = storage["_id"].ToString(), storageCode = storage["code"].ToString(), storageName = storage["name"].ToString(), items = inventoryDocumentItems }; var response = httpClient.PostAsync($"{APIEndpoint.Inventory}{inventoryDocumentURI}", new StringContent(JsonConvert.SerializeObject(inventoryDocument).ToString(), Encoding.UTF8, General.JsonMediaType)).Result; response.EnsureSuccessStatusCode(); }