コード例 #1
0
        public virtual IEnumerable orders(OrdersDeletage baseMethod)
        {
            var filterResult = baseMethod.Invoke();

            switch (Base.Filter.Current.Action)
            {
            // Filter Data By DCL order_number
            case "SO301000$lumCallDCLShipemnt":
                List <string> lstOrderNumbers = new List <string>();
                // Combine Query String
                foreach (SOOrder item in filterResult)
                {
                    if (!string.IsNullOrEmpty(item.CustomerRefNbr))
                    {
                        lstOrderNumbers.Add(item.CustomerRefNbr);
                    }
                }

                // Get DCL SO. Data
                var dclOrders = JsonConvert.DeserializeObject <OrderResponse>(
                    DCLHelper.CallDCLToGetSOByOrderNumbers(
                        this.DCLSetup.Select().RowCast <LUMVendCntrlSetup>().FirstOrDefault(),
                        string.Join(",", lstOrderNumbers.ToArray())).ContentResult);

                if (dclOrders.orders != null)
                {
                    foreach (SOOrder item in filterResult)
                    {
                        /*
                         *
                         *
                         * Debug mode  DCL.order_number = SO.CustomerRefNbr
                         * Release mode DCL.order_nu,ber = SO.orderNumber
                         *
                         *
                         *
                         */
                        if (dclOrders.orders.Any(x =>
                                                 x.order_number == item.CustomerRefNbr &&
                                                 !string.IsNullOrEmpty(x.shipping_carrier) &&
                                                 x.shipments.Any(s =>
                                                                 s.packages.Any(p => !string.IsNullOrEmpty(p.tracking_number)))))
                        {
                            yield return(item);
                        }
                    }
                }
                break;

            default:
                foreach (var item in filterResult)
                {
                    yield return(item);
                }
                break;
            }
        }
コード例 #2
0
        protected virtual IEnumerable PrepareImport(PXAdapter adapter)
        {
            PXLongOperation.StartOperation(this, () =>
            {
                try
                {
                    var result = DCLHelper.CallDCLToGetSOByFilter(this.DCLSetup.Select().RowCast <LUMVendCntrlSetup>().FirstOrDefault(), this.DocFilter.Current);
                    if (result.StatusCode == HttpStatusCode.OK)
                    {
                        // Delete temp table data
                        PXDatabase.Delete <LUMVendCntrlProcessOrder>(
                            new PXDataFieldRestrict <LUMVendCntrlProcessOrder.customerID>("AMZ"));
                        this.ImportOrderList.Cache.Clear();

                        int count      = 1;
                        var _dclOrders = JsonConvert.DeserializeObject <OrderResponse>(result.ContentResult);
                        // insert data to temp table
                        foreach (var orders in _dclOrders.orders)
                        {
                            if (this.ImportLog.Select().RowCast <LUMVendCntrlProcessLog>().Any(x => x.OrderID == orders.order_number && !string.IsNullOrEmpty(x.AcumaticaOrderID) && x.ImportStatus == true))
                            {
                                continue;
                            }
                            var _soOrder = this.ImportOrderList.Insert(
                                (LUMVendCntrlProcessOrder)this.ImportOrderList.Cache.CreateInstance());
                            _soOrder.LineNumber    = count++;
                            _soOrder.OrderID       = orders.order_number;
                            _soOrder.CustomerID    = orders.customer_number;
                            _soOrder.OrderDate     = DateTime.Parse(orders.ordered_date);
                            _soOrder.OrderStatusID = orders.order_stage.ToString();
                            _soOrder.OrderQty      = orders.order_lines.Sum(x => x.quantity);
                            _soOrder.OrderAmount   = orders.order_subtotal;
                            _soOrder.PoNumber      = orders.po_number;
                            _soOrder.LastUpdated   = DateTime.Parse(orders.modified_at);
                            _soOrder.Processed     = false;
                        }

                        this.Actions.PressSave();
                        return;
                    }
                    else
                    {
                        throw new Exception($"StatusCode:{result.StatusCode} Content: {result.ContentResult}");
                    }
                }
                catch (Exception e)
                {
                    throw new PXOperationCompletedWithErrorException(e.Message, e);
                }
            });
            return(adapter.Get());
        }
コード例 #3
0
ファイル: SOOrderEntry.cs プロジェクト: JeffJave/Ipevo
        protected virtual IEnumerable LumCallDCLShipemnt(PXAdapter adapter, [PXDate] DateTime?shipDate, [PXInt] int?siteID, [SOOperation.List] string operation)
        {
            try
            {
                var _soOrder = adapter.Get <SOOrder>().ToList()[0];

                // Get DCL SO. Data(正式:order_number = SO.OrderNbr)
                //var dclOrders = JsonConvert.DeserializeObject<OrderResponse>(
                //    DCLHelper.CallDCLToGetSOByOrderNumbers(
                //        this.DCLSetup.Select().RowCast<LUMVendCntrlSetup>().FirstOrDefault(), soOrder.OrderNbr).ContentResult);

                // Get DCL SO. Data(理論上資料一定存在,因為Process Order已經先篩選了)
                var dclOrders = JsonConvert.DeserializeObject <OrderResponse>(
                    DCLHelper.CallDCLToGetSOByOrderNumbers(
                        this.DCLSetup.Select().RowCast <LUMVendCntrlSetup>().FirstOrDefault(), _soOrder.CustomerRefNbr).ContentResult);

                if (dclOrders.orders == null)
                {
                    throw new Exception("Can not Mapping DCL Data");
                }

                if (!dclOrders.orders.Any(x => x.order_stage == 60))
                {
                    throw new Exception("DCL Order stage is not Fully Shipped");
                }

                if (_soOrder.OrderType == "FM")
                {
                    var setup           = this.MiddlewareSetup.Select().RowCast <LUMMiddleWareSetup>().FirstOrDefault();
                    var shippingCarrier = dclOrders.orders.FirstOrDefault()?.shipping_carrier;
                    var packagesInfo    = dclOrders.orders.FirstOrDefault().shipments.SelectMany(x => x.packages);
                    var _merchant       = string.IsNullOrEmpty(PXAccess.GetCompanyName()?.Split(' ')[1]) ? "us" :
                                          PXAccess.GetCompanyName()?.Split(' ')[1].ToLower() == "uk" ? "gb" : PXAccess.GetCompanyName()?.Split(' ')[1].ToLower();
                    MiddleWare_Shipment metaData = new MiddleWare_Shipment()
                    {
                        merchant        = _merchant,
                        amazon_order_id = dclOrders.orders.FirstOrDefault().po_number,
                        shipment_date   = dclOrders.orders.FirstOrDefault()?.shipments?.FirstOrDefault()?.ship_date + " 00:00:00",
                        shipping_method = "Standard",
                        carrier         = shippingCarrier,
                        tracking_number = string.Join("|", packagesInfo.Select(x => x.tracking_number))
                    };
                    // Update FBM
                    var updateResult = MiddleWareHelper.CallMiddleWareToUpdateFBM(setup, metaData);
                    // Check HttpStatusCode
                    if (updateResult.StatusCode != System.Net.HttpStatusCode.OK)
                    {
                        throw new PXException($"Update MiddleWare FBM fail , Code = {updateResult.StatusCode}");
                    }
                    // Check Response status
                    var updateModel = JsonConvert.DeserializeObject <MiddleWare_Response>(updateResult.ContentResult);
                    if (!updateModel.Status)
                    {
                        throw new PXException($"Update Middleware FBM fail, Msg = {updateModel.Message}");
                    }
                    _soOrder.GetExtension <SOOrderExt>().UsrSendToMiddleware = true;
                    Base.Document.Update(_soOrder);
                    Base.Save.Press();
                }
                else
                {
                    using (PXTransactionScope sc = new PXTransactionScope())
                    {
                        Base.CreateShipmentIssue(adapter, shipDate, siteID);
                        var processResult = PXProcessing <SOOrder> .GetItemMessage();

                        if (processResult.ErrorLevel != PXErrorLevel.RowInfo)
                        {
                            return(adapter.Get());
                        }

                        // Create SOShipment Graph
                        var graph = PXGraph.CreateInstance <SOShipmentEntry>();

                        // Find SOShipment
                        var _soOrderShipments =
                            FbqlSelect <SelectFromBase <SOOrderShipment, TypeArrayOf <IFbqlJoin> .Empty> .Where <BqlChainableConditionBase <TypeArrayOf <IBqlBinary> .FilledWith <And <Compare <SOOrderShipment.orderType, Equal <P.AsString> > > > > .And <BqlOperand <SOOrderShipment.orderNbr, IBqlString> .IsEqual <P.AsString> > >, SOOrderShipment> .View.Select(Base, _soOrder.OrderType, _soOrder.OrderNbr)
                            .RowCast <SOOrderShipment>();

                        foreach (var refItem in _soOrderShipments)
                        {
                            // Create new Adapter
                            var newAdapter = new PXAdapter(graph.Document)
                            {
                                Searches = new Object[] { refItem.ShipmentNbr }
                            };
                            // Select Current Shipment
                            var _soShipment = newAdapter.Get <SOShipment>().ToList()[0];

                            try
                            {
                                // Get Carrier and TrackingNbr
                                var shippingCarrier = dclOrders.orders.FirstOrDefault().shipping_carrier;
                                var packagesInfo    = dclOrders.orders.FirstOrDefault().shipments.SelectMany(x => x.packages);
                                _soShipment.GetExtension <SOShipmentExt>().UsrCarrier     = shippingCarrier;
                                _soShipment.GetExtension <SOShipmentExt>().UsrTrackingNbr = string.Join("|", packagesInfo.Select(x => x.tracking_number));
                                _soShipment.ShipmentDesc = $"Carrier: {shippingCarrier}|" +
                                                           $"TrackingNbr: {string.Join("|", packagesInfo.Select(x => x.tracking_number))}";
                                if (_soShipment.ShipmentDesc.Length > 256)
                                {
                                    _soShipment.ShipmentDesc = _soShipment.ShipmentDesc.Substring(0, 255);
                                }
                            }
                            catch (Exception e)
                            {
                                _soShipment.ShipmentDesc = e.Message;
                            }

                            // Update Data
                            graph.Document.Update(_soShipment);

                            // Remove Hold
                            graph.releaseFromHold.PressButton(newAdapter);
                            // Confirm Shipment
                            graph.confirmShipmentAction.PressButton(newAdapter);
                            // Prepare Invoice For 3D Orders
                            try
                            {
                                if (_soOrder.OrderType == "3D")
                                {
                                    newAdapter.AllowRedirect = true;
                                    graph.createInvoice.PressButton(newAdapter);
                                }
                            }
                            catch (PXRedirectRequiredException ex)
                            {
                                SOInvoiceEntry invoiceEntry = ex.Graph as SOInvoiceEntry;
                                var            soTax        = SelectFrom <SOTaxTran>
                                                              .Where <SOTaxTran.orderNbr.IsEqual <P.AsString>
                                                                      .And <SOTaxTran.orderType.IsEqual <P.AsString> > >
                                                              .View.Select(Base, _soOrder.OrderNbr, _soOrder.OrderType)
                                                              .RowCast <SOTaxTran>().FirstOrDefault();

                                var balance = invoiceEntry.Document.Current.CuryDocBal;
                                var refNbr  = invoiceEntry.Document.Current.RefNbr;
                                var invTax  = SelectFrom <ARTaxTran> .Where <ARTaxTran.refNbr.IsEqual <P.AsString> >
                                              .View.Select(Base, refNbr).RowCast <ARTaxTran>().FirstOrDefault();

                                var adjd = SelectFrom <ARAdjust2> .Where <ARAdjust2.adjdRefNbr.IsEqual <P.AsString> >
                                           .View.Select(Base, refNbr).RowCast <ARAdjust2>().FirstOrDefault();

                                if (soTax != null)
                                {
                                    // setting Tax
                                    invoiceEntry.Taxes.SetValueExt <ARTaxTran.curyTaxAmt>(invTax, soTax.CuryTaxAmt);
                                    invoiceEntry.Taxes.Update(invTax);
                                    // setting Document
                                    invoiceEntry.Document.SetValueExt <ARInvoice.curyTaxTotal>(invoiceEntry.Document.Current, soTax.CuryTaxAmt);
                                    invoiceEntry.Document.SetValueExt <ARInvoice.curyDocBal>(invoiceEntry.Document.Current, balance + (soTax.CuryTaxAmt ?? 0));
                                    invoiceEntry.Document.Update(invoiceEntry.Document.Current);
                                    invoiceEntry.Adjustments.SetValueExt <ARAdjust2.curyAdjdAmt>(adjd, adjd.CuryAdjdAmt + (soTax.CuryTaxAmt ?? 0));
                                    invoiceEntry.Adjustments.Update(adjd);
                                    invoiceEntry.releaseFromCreditHold.Press();
                                    invoiceEntry.Save.Press();
                                }
                            }
                            catch (Exception ex)
                            {
                                throw new Exception(ex.Message);
                            }
                        }

                        sc.Complete();
                    }
                }
            }
            catch (Exception e)
            {
                PXProcessing.SetError <SOOrder>(e.Message);
            }

            return(adapter.Get());
        }
コード例 #4
0
        /// <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);
            }
        }