public LUMDCLImportProc() { DCLFilter currentFilter = this.DocFilter.Current; ImportOrderList.SetProcessCaption(PX.Objects.CR.Messages.Import); ImportOrderList.SetProcessAllCaption(PX.Objects.CR.Messages.Prepare + " & " + PX.Objects.CR.Messages.Import); ImportOrderList.SetProcessDelegate( delegate(List <LUMVendCntrlProcessOrder> list) { ImportRecords(list, currentFilter); }); }
/// <summary> Call DCL To Get SO. By Filter </summary> public static LumAPIResultModel CallDCLToGetSOByFilter(LUMVendCntrlSetup setup, DCLFilter filter) { var config = new DCL_Config() { RequestMethod = HttpMethod.Get, RequestUrl = APIHelper.CombineQueryString( setup.SecureURL, new { Received_from = filter.Received_from?.ToString("yyyy-MM-dd"), Received_to = filter.Received_to?.ToString("yyyy-MM-dd"), Filter = $"Customer_number eq {filter.Customer_number}" }), AuthType = setup.AuthType, Token = Convert.ToBase64String(Encoding.UTF8.GetBytes($"{setup.ClientID}:{setup.ClientSecret}")) }; var caller = new APICaller(config); return(caller.CallApi()); }
/// <summary> Create SO Data </summary> public virtual void ImportRecords(List <LUMVendCntrlProcessOrder> list, DCLFilter currentFilter) { try { PXLongOperation.StartOperation(this, delegate() { var setup = this.DCLSetup.Select().RowCast <LUMVendCntrlSetup>().FirstOrDefault(); var result = DCLHelper.CallDCLToGetSOByFilter( this.DCLSetup.Select().RowCast <LUMVendCntrlSetup>().FirstOrDefault(), this.DocFilter.Current); if (result.StatusCode == HttpStatusCode.OK) { var apiOrders = JsonConvert.DeserializeObject <OrderResponse>(result.ContentResult); var inventoryitems = SelectFrom <InventoryItem> .View.Select(this).RowCast <InventoryItem>() .ToList(); var LogDatas = SelectFrom <LUMVendCntrlProcessLog> .Where <LUMVendCntrlProcessLog.importStatus.IsEqual <True> .And <LUMVendCntrlProcessLog.acumaticaOrderID.IsNotNull> > .View.Select(this) .RowCast <LUMVendCntrlProcessLog>().ToList(); // Import Data int count = 0; foreach (var item in list.Where(x => !x.Processed.Value)) { // var logNewOrderNbr = string.Empty; var logExceptionMsg = string.Empty; var impRow = apiOrders.orders.Where(x => x.order_number == item.OrderID).FirstOrDefault(); try { if (impRow == null) { throw new Exception("Cant not mapping API Data"); } // Check Data is Exists var existsLog = LogDatas.Where(x => x.OrderID == item.OrderID && x.CustomerID == item.CustomerID).ToList(); if (existsLog.Any()) { throw new Exception( $"This Order has been Created, SONbr: {existsLog.FirstOrDefault()?.AcumaticaOrderType} {existsLog.FirstOrDefault()?.AcumaticaOrderID}"); } // SOOrder var graph = PXGraph.CreateInstance <SOOrderEntry>(); var newOrder = (SOOrder)graph.Document.Cache.CreateInstance(); newOrder.OrderType = setup.OrderType; newOrder.OrderDate = DateTime.Parse(impRow.ordered_date); newOrder.CustomerID = setup.CustomerID; newOrder.CustomerOrderNbr = impRow.po_number; newOrder.CustomerRefNbr = impRow.order_number; if (impRow.stage_description == "Fully Shipped") { newOrder.OrderDesc = impRow.stage_description == "Fully Shipped" ? $"Create SO BY Import Process |Tacking Number: {impRow.shipments.FirstOrDefault().packages.FirstOrDefault()?.tracking_number}" : $"DCL Stage is {impRow.stage_description}"; } newOrder = (SOOrder)graph.Document.Cache.Insert(newOrder); foreach (var line in impRow.order_lines) { // SOLine var newTranc = (SOLine)graph.Transactions.Cache.CreateInstance(); newTranc.InventoryID = inventoryitems .FirstOrDefault(x => x.InventoryCD.Trim() == line.item_number)?.InventoryID; newTranc.ManualPrice = true; newTranc.OrderQty = (decimal)line.quantity; newTranc.OpenQty = (decimal)line.quantity; newTranc.CuryUnitPrice = (decimal)line.price; graph.Transactions.Insert(newTranc); } graph.Save.Press(); item.Processed = true; // Update Process Order this.ImportOrderList.Cache.Update(item); logNewOrderNbr = newOrder.OrderNbr; #region Prepare Invoice var newAdapter = new PXAdapter(graph.Document) { Searches = new Object[] { newOrder.OrderType, newOrder.OrderNbr } }; graph.PrepareInvoice(newAdapter); #endregion } catch (Exception e) { // Prepare Invoice完成是throw exception if (e.Message?.ToLower() != "invoice") { logExceptionMsg = e.Message; PXProcessing.SetError <LUMVendCntrlProcessOrder>(count, e.Message); } } finally { InsertImpLog( setup, item, string.IsNullOrEmpty(logExceptionMsg), logExceptionMsg, string.IsNullOrEmpty(logNewOrderNbr) ? null : logNewOrderNbr); } count++; } // end ImpRow this.Actions.PressSave(); } }); } catch (Exception e) { throw new PXOperationCompletedWithErrorException(e.Message); } }