예제 #1
0
        private void CalculateFreightCost(bool supressErrors)
        {
            Carrier carrier = Carrier.PK.Find(Base, "UPSGROUND");

            if (carrier != null && carrier.IsExternal == true)
            {
                var _doc = new SOOrder();
                //_doc = SelectFrom<SOOrder>.Where<SOOrder.orderNbr.IsEqual<P.AsString>.And<SOOrder.orderType.IsEqual<P.AsString>>>.View.Select(Base, "SUS2100212", "SO").RowCast<SOOrder>().FirstOrDefault();
                _doc.CuryID          = Base.Quote.Current.CuryID;
                _doc.ShipVia         = "UPSGROUND";
                _doc.CuryInfoID      = Base.Quote.Current.CuryInfoID;
                _doc.DocDate         = Base.Quote.Current.DocumentDate;
                _doc.IsPackageValid  = false;
                _doc.IsManualPackage = false;
                CarrierPlugin   plugin = CarrierPlugin.PK.Find(Base, carrier.CarrierPluginID);
                ICarrierService cs     = CarrierPluginMaint.CreateCarrierService(Base, plugin);
                cs.Method = carrier.PluginMethod;

                var graph = PXGraph.CreateInstance <SOOrderEntry>();
                _doc = graph.Document.Insert(_doc);
                graph.Shipping_Address.Cache.Current = new SOShippingAddress();
                CarrierRatesExt(graph).RecalculatePackagesForOrder(graph.Document.Current);
                CarrierRequest            cr     = CarrierRatesExt(graph).BuildRateRequest(_doc);
                CarrierResult <RateQuote> result = cs.GetRateQuote(cr);

                if (result != null)
                {
                    StringBuilder sb = new StringBuilder();
                    foreach (Message message in result.Messages)
                    {
                        sb.AppendFormat("{0}:{1} ", message.Code, message.Description);
                    }

                    if (result.IsSuccess)
                    {
                        throw new PXException(result.Result.Amount.ToString());
                        //decimal baseCost = ConvertAmtToBaseCury(result.Result.Currency, arsetup.Current.DefaultRateTypeID, Document.Current.OrderDate.Value, result.Result.Amount);
                        //SetFreightCost(baseCost);
                    }
                }
            }
        }