public void itemFulfillmentSearch(string orderNumber) { NetSuiteService service = new NetSuiteService(); service.CookieContainer = new CookieContainer(); NetsuiteUser user = new NetsuiteUser("3451682", "*****@*****.**", "1026", "tridenT168"); Passport passport = user.prepare(user); Status status = service.login(passport).status; TransactionSearchAdvanced tranSearchAdvanced = new TransactionSearchAdvanced(); TransactionSearch tranSearch = new TransactionSearch(); SearchStringField orderID = new SearchStringField(); orderID.@operator = SearchStringFieldOperator.@is; orderID.operatorSpecified = true; orderID.searchValue = orderNumber; TransactionSearchBasic tranSearchBasic = new TransactionSearchBasic(); tranSearchBasic.tranId = orderID; tranSearch.basic = tranSearchBasic; tranSearchAdvanced.criteria = tranSearch; SearchPreferences searchPreferences = new SearchPreferences(); searchPreferences.bodyFieldsOnly = false; service.searchPreferences = searchPreferences; SearchResult transactionResult = service.search(tranSearchAdvanced); if (transactionResult.status.isSuccess != true) throw new Exception("Cannot find Order " + orderNumber + " " + transactionResult.status.statusDetail[0].message); if (transactionResult.recordList.Count() != 1) throw new Exception("More than one order found for item " + orderNumber); this.itemFulfillment = new com.netsuite.webservices.ItemFulfillment(); this.itemFulfillment = ((com.netsuite.webservices.ItemFulfillment)transactionResult.recordList[0]); }
public ItemFulfillment(SalesOrder salesOrder) { itemFulfillment = new com.netsuite.webservices.ItemFulfillment(); RecordRef salesOrderID = new RecordRef(); salesOrderID.type = RecordType.salesOrder; salesOrderID.typeSpecified = true; salesOrderID.internalId = salesOrder.salesOrder.internalId; itemFulfillment.createdFrom = salesOrderID; ItemFulfillmentItemList itemFulItemList = new ItemFulfillmentItemList(); int i = 0; ItemFulfillmentItem[] Items = new ItemFulfillmentItem[salesOrder.salesOrder.itemList.item.Count()]; Dictionary<string, double> binQuantities = new Dictionary<string, double>(); foreach (var itemLine in salesOrder.salesOrder.itemList.item) { Items[i] = new ItemFulfillmentItem(); RecordRef item = new RecordRef(); item.type = RecordType.inventoryItem; item.typeSpecified = true; item.internalId = itemLine.item.internalId; Items[i].item = item; Items[i].quantity = itemLine.quantity; Items[i].quantitySpecified = true; Items[i].orderLine = itemLine.line; Items[i].orderLineSpecified = true; binQuantities = getBins(itemLine.item.name); string[] bins = new string[binQuantities.Count]; int j = 0; foreach (var key in binQuantities) { bins[j] = key.Key; j++; } Array.Sort(bins, new AlphanumComparatorFast()); bins = bins.Where(x => !string.IsNullOrEmpty(x)).ToArray(); List<string> notPreferredBins = new List<string>(); List<string> preferredBins = new List<string>(); List<string> orderedBins = new List<string>(); Regex regex = new Regex("[0-9]+[A-Z]"); string C = "C"; foreach (var bin in bins) { Match match = regex.Match(bin); if (match.Success) { string letter = (match.Value[match.Value.Length - 1]).ToString(); int compare = string.Compare(letter, C); if (compare < 0) { notPreferredBins.Add(bin); } else preferredBins.Add(bin); } } foreach (var bin in preferredBins) { orderedBins.Add(bin); } orderedBins.Add("Stock"); foreach (var bin in notPreferredBins) { orderedBins.Add(bin); } foreach (var bin in orderedBins) { double availQuantity = binQuantities[bin]; if (availQuantity >= Items[i].quantity) { Items[i].binNumbers = bin; break; } } i++; } itemFulItemList.item = Items; this.itemFulfillment.itemList = itemFulItemList; }