예제 #1
0
        protected override void _(Events.RowUpdated <Document> e)
        {
            SOOrder row    = Document.Cache.GetMain((Document)e.Row) as SOOrder;
            SOOrder oldRow = Document.Cache.GetMain((Document)e.OldRow) as SOOrder;

            if (row != null && oldRow != null)
            {
                UpdateARBalances(e.Cache, e.Row, e.OldRow);
            }

            if (_InternalCall)
            {
                return;
            }

            if (oldRow != null && row.CustomerID == oldRow.CustomerID &&
                row.CreditHold != oldRow.CreditHold &&
                row.CreditHold == false &&
                row.Hold == false ||
                oldRow != null && row.IsCCAuthorized != oldRow.IsCCAuthorized &&
                row.IsCCAuthorized == true ||
                oldRow != null && row.IsCCCaptured != oldRow.IsCCCaptured &&
                row.IsCCCaptured == true)
            {
                e.Cache.SetValue <SOOrder.approvedCredit>(row, true);
                e.Cache.SetValue <SOOrder.approvedCreditAmt>(row, row.OrderTotal);
            }

            if (oldRow != null && row.Hold != oldRow.Hold && row.Hold == true)
            {
                e.Cache.SetValueExt <SOOrder.creditHold>(row, false);
            }

            base._(e);
        }
        private void SetSOHeaderObjectsData(PrepareAndImportOrdersParams orderParams)
        {
            SOOrder newOrder = new SOOrder();

            if (orderParams.objSOOrderEntry.sosetup.Current != null)
            {
                SOSetupAmazonExt objSOOSetupext = orderParams.objSOOrderEntry.sosetup.Current.GetExtension <SOSetupAmazonExt>();
                if (objSOOSetupext != null && objSOOSetupext.UsrGuestCustID.HasValue)
                {
                    newOrder.OrderType  = orderParams.objSOAmazonSetup.OrderType;
                    newOrder            = (SOOrder)orderParams.objSOOrderEntry.Document.Cache.Insert(newOrder);
                    newOrder.CustomerID = objSOOSetupext.UsrGuestCustID;
                }
                else
                {
                    throw new PXException(SOMessages.guestCustomerErrorMsg);
                }
            }
            AssignValueAsPerIntegrationMapping(orderParams.objliUsrMapping, newOrder, orderParams.ObjCurrentOrder, null, orderParams.objSOOrderEntry.Document.View.Name);
            newOrder.OrderDesc = !string.IsNullOrEmpty(orderParams.ObjCurrentOrder.FulfillmentChannel) ?
                                 orderParams.ObjCurrentOrder.FulfillmentChannel == SOConstants.fulfillmentChannelAFN ?
                                 string.IsNullOrEmpty(newOrder.OrderDesc) ? SOMessages.fbaOrder : newOrder.OrderDesc + " - " + SOMessages.fbaOrder :
                                 orderParams.ObjCurrentOrder.FulfillmentChannel == SOConstants.fulfillmentChannelMFN ?
                                 string.IsNullOrEmpty(newOrder.OrderDesc) ? SOMessages.fbmOrder : newOrder.OrderDesc + " - " + SOMessages.fbmOrder :
                                 newOrder.OrderDesc : newOrder.OrderDesc;
            newOrder.DefaultSiteID = orderParams.objSOAmazonSetup.DfltWarehouseID;
            SOOrderAmazonExt newOrderExt = newOrder.GetExtension <SOOrderAmazonExt>();

            if (newOrderExt != null)
            {
                newOrderExt.UsrAmazonOrderID = orderParams.ObjCurrentOrder.AmazonOrderId;
            }
            orderParams.objSOOrderEntry.Document.Current = newOrder;
            orderParams.objSOOrderEntry.Document.Update(orderParams.objSOOrderEntry.Document.Current);
        }
예제 #3
0
 private void FillSalesOrder(SalesOrderModel salesOrderModel, SOOrder salesOrder)
 {
     salesOrder.OrderDesc   = "Team Alpha";
     salesOrder.CustomerID  = GetCustomerId(salesOrderModel.CustomerCd);
     salesOrder.RequestDate = GetRequestDate(salesOrderModel.RequestDate);
     salesOrder.ShipVia     = salesOrderModel.ShipVia;
 }
        public virtual IAddressBase GetFromAddress(SOOrder order, SOLine line, GetFromAddressLineDelegate del)
        {
            int?SOID = GetSOIDRelated(line);

            if (SOID != null && line.SiteID == null)
            {
                IAddressBase returnAddress = null;

                returnAddress = PXSelectJoin <FSAddress,
                                              InnerJoin <
                                                  FSBranchLocation,
                                                  On <FSBranchLocation.branchLocationAddressID, Equal <FSAddress.addressID> >,
                                                  InnerJoin <FSServiceOrder,
                                                             On <FSServiceOrder.branchLocationID, Equal <FSBranchLocation.branchLocationID> > > >,
                                              Where <
                                                  FSServiceOrder.sOID, Equal <Required <FSServiceOrder.sOID> > > >
                                .Select(Base, SOID)
                                .RowCast <FSAddress>()
                                .FirstOrDefault();

                return(returnAddress);
            }

            return(del(order, line));
        }
        public virtual IEnumerable addBlanketOrderLineAction(PXAdapter adapter)
        {
            if (IsBlanketOrder)
            {
                return(adapter.Get());
            }

            if (blanketLinesSelected.AskExt() != WebDialogResult.OK)
            {
                foreach (BlanketSOLine row in blanketLinesSelected.Cache.Updated)
                {
                    row.Selected = false;
                }
                return(adapter.Get());
            }

            SOOrder currentOrder = Base?.Document?.Current;

            foreach (BlanketSOLine row in blanketLinesSelected.Cache.Updated)
            {
                AddSOLine(row);
                row.Selected          = false;
                Base.Document.Current = currentOrder; //For now - make sure document current is staying set correctly...
            }

            return(adapter.Get());
        }
예제 #6
0
        /// <summary>
        /// Create an sales order from external logistic.
        /// </summary>
        public static void ImportRecords(LUM3DCartSetup curSetup, LUM3DCartProcessOrder processOrder)
        {
            try
            {
                SOOrderEntry orderEntry = PXGraph.CreateInstance <SOOrderEntry>();

                SOOrder order = orderEntry.Document.Cache.CreateInstance() as SOOrder;

                order.OrderType        = curSetup.OrderType;
                order.CustomerID       = curSetup.CustomerID;
                order.CustomerOrderNbr = processOrder.OrderID;
                order.DocDate          = processOrder.OrderDate;

                order = orderEntry.Document.Insert(order);

                CreateOrderDetail(orderEntry, curSetup, order);

                orderEntry.Save.Press();

                CreatePaymentProcess(order);
            }
            catch (PXException ex)
            {
                PXProcessing.SetError <LUM3DCartProcessOrder>(ex.Message);
                throw;
            }
        }
예제 #7
0
        //public PXAction<SalesFcstInquiry> generateRecords;
        //[PXUIField(DisplayName = "Generate Records")]
        //[PXButton(CommitChanges = true)]
        //public virtual IEnumerable GenerateRecords(PXAdapter adapter)
        //{
        //    PXLongOperation.StartOperation(this, delegate
        //    {
        //        InsertRecords();
        //    });

        //    return adapter.Get();
        //}
        #endregion

        #region Function
        private void InsertRecords()
        {
            int count = 1;

            SalesFcstInquiry fcstInquiry = SOFcstInq.Cache.CreateInstance() as SalesFcstInquiry;

            foreach (PXResult <SalesForecast> result in SOForecast.Select())
            {
                SalesForecast salesForecast = result.GetItem <SalesForecast>();

                fcstInquiry.Numbering     = count;
                fcstInquiry.SalesPersonID = salesForecast.SalesPersonID;
                fcstInquiry.CustomerID    = salesForecast.CustomerID;
                fcstInquiry.EndCustomer   = salesForecast.EndCustomer;
                fcstInquiry.InventoryID   = salesForecast.InventoryID;
                fcstInquiry.FinPeriodID   = salesForecast.FinPeriodID;
                fcstInquiry.CountryID     = salesForecast.CountryID;
                fcstInquiry.IsTotal       = salesForecast.IsTotal;
                fcstInquiry.IsSplit       = salesForecast.IsSplit;
                fcstInquiry.PercentSplit  = salesForecast.PercentSplit;
                fcstInquiry.Date          = salesForecast.Date;
                fcstInquiry.Qty           = salesForecast.Qty;
                fcstInquiry.UnitPrice     = salesForecast.UnitPrice;
                fcstInquiry.ItemClassID   = salesForecast.ItemClassID;

                count++;
                SOFcstInq.Cache.Insert(fcstInquiry);
            }

            foreach (PXResult <SOLine, SOOrder, Customer, InventoryItem> result2 in Backlog.Select())
            {
                SOOrder order = result2.GetItem <SOOrder>();
                SOLine  line  = result2.GetItem <SOLine>();

                fcstInquiry.Numbering     = count;
                fcstInquiry.OrderNbr      = order.OrderNbr;
                fcstInquiry.OrderDate     = line.OrderDate;
                fcstInquiry.RequestDate   = line.RequestDate;
                fcstInquiry.ShipDate      = line.ShipDate;
                fcstInquiry.InventoryID   = line.InventoryID;
                fcstInquiry.SiteID        = line.SiteID;
                fcstInquiry.OrderQty      = line.OrderQty;
                fcstInquiry.OpenQty       = line.OpenQty;
                fcstInquiry.CustomerID    = line.CustomerID;
                fcstInquiry.LineNbr       = line.LineNbr;
                fcstInquiry.UnitPrice     = line.UnitPrice;
                fcstInquiry.Amount        = line.OpenAmt;
                fcstInquiry.SalesPersonID = line.SalesPersonID;
                fcstInquiry.FinPeriodID   = String.Format("{0}{1}", line.ShipDate.Value.Year, line.ShipDate.Value.Month.ToString("00"));
                fcstInquiry.EndCustomer   = PXCache <SOLine> .GetExtension <SOLineExt>(line).UsrEndCustomer;

                fcstInquiry.ItemClassID      = result2.GetItem <InventoryItem>().ItemClassID;
                fcstInquiry.CustomerOrderNbr = order.CustomerOrderNbr;
                fcstInquiry.Status           = order.Status;
                fcstInquiry.TermsID          = result2.GetItem <Customer>().TermsID;

                count++;
                SOFcstInq.Cache.Insert(fcstInquiry);
            }
        }
        private void SetFinancialInformationobjectsData(PrepareAndImportOrdersParams orderParams)
        {
            SOOrder financialInformation = (SOOrder)orderParams.objSOOrderEntry.Document.Current;

            if (financialInformation == null)
            {
                return;
            }
            if (orderParams.objSOOrderEntry.sosetup.Current != null)
            {
                bool             isCarrierAvaliable = false;
                SOSetupAmazonExt objSOOSetupext     = orderParams.objSOOrderEntry.sosetup.Current.GetExtension <SOSetupAmazonExt>();
                if (orderParams != null && orderParams.objSOProcessOrderRecord != null && (orderParams.objSOProcessOrderRecord.Carrier != null || !string.IsNullOrEmpty(orderParams.objSOProcessOrderRecord.Carrier)))
                {
                    isCarrierAvaliable = orderParams.listOfCarriers.Any(x => x.ToLower().Trim() == orderParams.objSOProcessOrderRecord.Carrier.ToLower().Trim());
                }
                if (isCarrierAvaliable)
                {
                    financialInformation.ShipVia = orderParams.objSOProcessOrderRecord.Carrier;
                }
                else if (objSOOSetupext != null && !string.IsNullOrEmpty(objSOOSetupext.UsrAmazonShipVia))
                {
                    financialInformation.ShipVia = objSOOSetupext.UsrAmazonShipVia;
                }
                orderParams.objSOOrderEntry.Document.Update(financialInformation);
            }
            AssignValueAsPerIntegrationMapping(orderParams.objliUsrMapping, financialInformation, orderParams.ObjCurrentOrder, null, /*SOConstants.currentDocument*/ orderParams.objSOOrderEntry.CurrentDocument.View.Name);
            orderParams.objSOOrderEntry.Document.Update(financialInformation);
        }
        public virtual void InvoiceCreated(ARInvoice invoice, SOOrder source, SOInvoiceEntry.InvoiceCreatedDelegate baseMethod)
        {
            baseMethod(invoice, source);

            SOOrderRUTROT orderRR = PXCache <SOOrder> .GetExtension <SOOrderRUTROT>(source);

            if (orderRR?.IsRUTROTDeductible == true && invoice != null)
            {
                ARInvoiceRUTROT invoiceRR = PXCache <ARInvoice> .GetExtension <ARInvoiceRUTROT>(invoice);

                Base.Document.SetValueExt <ARInvoiceRUTROT.isRUTROTDeductible>(invoice, true);
                Base.Document.Update(invoice);

                RUTROT rutrot = PXSelect <RUTROT,
                                          Where <RUTROT.docType, Equal <Required <SOOrder.orderType> >,
                                                 And <RUTROT.refNbr, Equal <Required <SOOrder.orderNbr> > > > > .Select(Base, source.OrderType, source.OrderNbr);

                rutrot = RUTROTHelper.CreateCopy(Base.Rutrots.Cache, rutrot, invoice.DocType, invoice.RefNbr);
                rutrot = Base.Rutrots.Update(rutrot);

                foreach (RUTROTDistribution rutrotDetail in PXSelect <RUTROTDistribution,
                                                                      Where <RUTROTDistribution.docType, Equal <Required <SOOrder.orderType> >,
                                                                             And <RUTROTDistribution.refNbr, Equal <Required <SOOrder.orderNbr> > > > > .Select(Base, source.OrderType, source.OrderNbr))
                {
                    RUTROTDistribution new_detail = (RUTROTDistribution)Base.RRDistribution.Cache.CreateCopy(rutrotDetail);
                    new_detail.RefNbr  = null;
                    new_detail.DocType = null;
                    Base.RRDistribution.Insert(new_detail);
                }
            }
        }
예제 #10
0
        protected virtual IEnumerable fixedDemand()
        {
            PXView select = new PXView(Base, false, Base.FixedDemand.View.BqlSelect);

            Int32         totalrow = 0;
            Int32         startrow = PXView.StartRow;
            List <object> result   = select.Select(PXView.Currents, PXView.Parameters, PXView.Searches,
                                                   PXView.SortColumns, PXView.Descendings, PXView.Filters, ref startrow, PXView.MaximumRows, ref totalrow);

            PXView.StartRow = 0;

            foreach (PXResult <POFixedDemand, InventoryItem, Vendor, POVendorInventory, CRLocation, SOOrder, SOLineSplit, SOLine, INItemClass, FSServiceOrder> rec in result)
            {
                var demand = (POFixedDemand)rec;
                var item   = (InventoryItem)rec;
                var vendor = (Vendor)rec;
                var price  = (POVendorInventory)rec;
                Base.EnumerateAndPrepareFixedDemandRow(demand, item, vendor, price);

                FSServiceOrder fsServiceOrderRow = (FSServiceOrder)rec;
                SOOrder        soOrderRow        = (SOOrder)rec;

                if (fsServiceOrderRow.CustomerID != null)
                {
                    soOrderRow.CustomerID = fsServiceOrderRow.CustomerID;
                }

                FSxPOFixedDemand fSxPOFixedDemandRow = Base.FixedDemand.Cache.GetExtension <FSxPOFixedDemand>(demand);
                fSxPOFixedDemandRow.FSRefNbr = fsServiceOrderRow.RefNbr;
            }

            return(result);
        }
예제 #11
0
 public static bool IsOrderSelfCaptured(PXGraph graph, SOOrder doc)
 {
     return(PXSelectReadonly <ExternalTransaction,
                              Where <ExternalTransaction.origDocType, Equal <Required <SOOrder.orderType> >, And <ExternalTransaction.origRefNbr, Equal <Required <SOOrder.orderNbr> >,
                                                                                                                  And <ExternalTransaction.origDocType, NotEqual <ExternalTransaction.docType>, And <ExternalTransaction.origRefNbr, NotEqual <ExternalTransaction.refNbr> > > > > >
            .SelectWindowed(graph, 0, 1, doc.OrderType, doc.OrderNbr).Count == 0);
 }
예제 #12
0
        private void UpdateOrderBalances(SOOrder order)
        {
            if (order == null)
            {
                return;
            }
            bool?     isFromCA = order.GetExtension <KCSOOrderExt>().UsrKCSiteName?.EndsWith("FBA");
            ARPayment payment  = KCOrderPayment.Select(order.CustomerOrderNbr);

            if (isFromCA == true && payment != null)
            {
                order.PaymentTotal = order.CuryPaymentTotal = payment.CuryOrigDocAmt;
            }

            order.DocBal        = order.CuryDocBal = order.CuryOrderTotal;
            order.UnpaidBalance = order.CuryUnpaidBalance = 0;

            foreach (ARTran line in Base.Transactions.Select())
            {
                SOLine      sOLine      = KCSOLineByOrderNbrAndLineNbr.SelectSingle(line.SOOrderNbr, line.SOOrderLineNbr);
                SOLinePCExt SOLinePCExt = sOLine.GetExtension <SOLinePCExt>();
                if (SOLinePCExt.UsrKNMasterLineNbr == sOLine.LineNbr)
                {
                    line.CuryExtPrice = sOLine.CuryExtPrice;
                    line.CuryTranAmt  = sOLine.CuryLineAmt;
                }
            }
        }
예제 #13
0
        public virtual void CopyOrderProc(SOOrder order, CopyParamFilter copyFilter, CopyOrderProcDelegate baseMethod)
        {
            RUTROT rutrotRecord = null;
            PXResultset <RUTROTDistribution> rutrotDistribution = null;
            SOOrderRUTROT orderRR = RUTROTHelper.GetExtensionNullable <SOOrder, SOOrderRUTROT>(order);

            if (RUTROTHelper.IsRUTROTcompatibleType(order.OrderType) && orderRR?.IsRUTROTDeductible == true)
            {
                rutrotRecord       = Rutrots.SelectSingle();
                rutrotDistribution = RRDistribution.Select();
            }

            baseMethod(order, copyFilter);
            if (RUTROTHelper.IsRUTROTcompatibleType(copyFilter.OrderType) && rutrotRecord != null && rutrotDistribution != null)
            {
                rutrotRecord                      = (RUTROT)Rutrots.Cache.CreateCopy(rutrotRecord);
                rutrotRecord.RefNbr               = Base.Document.Current.OrderNbr;
                rutrotRecord.DocType              = Base.Document.Current.OrderType;
                rutrotRecord.CuryDistributedAmt   = 0m;
                rutrotRecord.CuryUndistributedAmt = 0m;
                rutrotRecord                      = Rutrots.Update(rutrotRecord);
                foreach (RUTROTDistribution distribution in rutrotDistribution)
                {
                    RUTROTDistribution new_distribution = (RUTROTDistribution)RRDistribution.Cache.CreateCopy(distribution);
                    new_distribution.RefNbr  = null;
                    new_distribution.DocType = null;
                    RRDistribution.Insert(new_distribution);
                }
            }
            else
            {
                Base.Document.Cache.SetValueExt <SOOrderRUTROT.isRUTROTDeductible>(Base.Document.Current, false);
                Base.Document.Update(Base.Document.Current);
            }
        }
예제 #14
0
        public virtual void InsertSOAdjustments(SOOrder order, ARPaymentEntry docgraph, ARPayment payment, InsertSOAdjustmentsDelegate baseMethod)
        {
            baseMethod(order, docgraph, payment);
            SOOrderRUTROT orderRR = RUTROTHelper.GetExtensionNullable <SOOrder, SOOrderRUTROT>(order);

            if (orderRR.IsRUTROTDeductible == true)
            {
                RUTROT rutrot = PXSelect <RUTROT, Where <RUTROT.docType, Equal <Required <SOOrder.orderType> >,
                                                         And <RUTROT.refNbr, Equal <Required <SOOrder.orderNbr> > > > > .Select(Base, order.OrderType, order.OrderNbr);

                foreach (SOAdjust adj in docgraph.SOAdjustments.Select())
                {
                    SOAdjust other = PXSelectGroupBy <SOAdjust,
                                                      Where <SOAdjust.voided, Equal <False>,
                                                             And <SOAdjust.adjdOrderType, Equal <Required <SOAdjust.adjdOrderType> >,
                                                                  And <SOAdjust.adjdOrderNbr, Equal <Required <SOAdjust.adjdOrderNbr> >,
                                                                       And <Where <SOAdjust.adjgDocType, NotEqual <Required <SOAdjust.adjgDocType> >, Or <SOAdjust.adjgRefNbr, NotEqual <Required <SOAdjust.adjgRefNbr> > > > > > > >,
                                                      Aggregate <GroupBy <SOAdjust.adjdOrderType,
                                                                          GroupBy <SOAdjust.adjdOrderNbr, Sum <SOAdjust.curyAdjdAmt, Sum <SOAdjust.adjAmt> > > > > > .Select(Base, adj.AdjdOrderType, adj.AdjdOrderNbr, adj.AdjgDocType, adj.AdjgRefNbr);

                    if (other == null || other.AdjdOrderNbr == null)
                    {
                        docgraph.SOAdjustments.Cache.SetValueExt <SOAdjust.curyAdjgAmt>(adj, adj.CuryAdjgAmt - rutrot.CuryTotalAmt);
                        docgraph.SOAdjustments.Update(adj);
                    }
                }
            }
        }
예제 #15
0
        public virtual void FieldVerifying(PXCache sender, PXFieldVerifyingEventArgs e)
        {
            var newValue = (string)e.NewValue;
            var order    = (SOOrder)e.Row;

            if (order?.OrderType == null || order.CustomerID == null)
            {
                return;
            }

            var orderType = SOOrderType.PK.Find(sender.Graph, order.OrderType);

            if (orderType.CustomerOrderIsRequired != true || string.IsNullOrWhiteSpace(newValue) ||
                orderType.CustomerOrderValidation.IsNotIn(CustomerOrderValidationType.Warn, CustomerOrderValidationType.Error))
            {
                return;
            }

            SOOrder duplicateOrder = FindCustomerOrderDuplicate(sender, newValue, order);

            if (duplicateOrder == null)
            {
                return;
            }

            if (orderType.CustomerOrderValidation == CustomerOrderValidationType.Error)
            {
                throw new PXSetPropertyException(Messages.CustomerOrderHasDuplicateError, PXErrorLevel.Error, duplicateOrder.OrderNbr);
            }

            sender.RaiseExceptionHandling <SOOrder.customerOrderNbr>(order, newValue,
                                                                     new PXSetPropertyException(Messages.CustomerOrderHasDuplicateWarning, PXErrorLevel.Warning, duplicateOrder.OrderNbr));
        }
예제 #16
0
        public virtual void RowUpdated(PXCache sender, PXRowUpdatedEventArgs e)
        {
            var order    = (SOOrder)e.Row;
            var oldOrder = (SOOrder)e.OldRow;

            if (order?.OrderType == null || order.CustomerID == null || oldOrder.CustomerID == order.CustomerID)
            {
                return;
            }

            var orderType = SOOrderType.PK.Find(sender.Graph, order.OrderType);

            if (orderType.CustomerOrderIsRequired != true || string.IsNullOrWhiteSpace(order.CustomerOrderNbr) ||
                orderType.CustomerOrderValidation.IsNotIn(CustomerOrderValidationType.Warn, CustomerOrderValidationType.Error))
            {
                return;
            }

            SOOrder duplicateOrder = FindCustomerOrderDuplicate(sender, order.CustomerOrderNbr, order);

            if (duplicateOrder == null)
            {
                return;
            }

            var exception = orderType.CustomerOrderValidation == CustomerOrderValidationType.Error
                                ? new PXSetPropertyException(Messages.CustomerOrderHasDuplicateError, PXErrorLevel.Error, duplicateOrder.OrderNbr)
                                : new PXSetPropertyException(Messages.CustomerOrderHasDuplicateWarning, PXErrorLevel.Warning, duplicateOrder.OrderNbr);

            sender.RaiseExceptionHandling <SOOrder.customerOrderNbr>(order, order.CustomerOrderNbr, exception);
        }
        protected override PMCommitment FromRecord(PXCache sender, object row)
        {
            SOMiscLine2 line  = (SOMiscLine2)row;
            SOOrder     order = (SOOrder)PXParentAttribute.SelectParent(sender.Graph.Caches[detailEntity], row, typeof(SOOrder));

            int sign = line.Operation == SOOperation.Issue ? 1 : -1;

            PMCommitment commitment = new PMCommitment();

            commitment.Type               = PMCommitmentType.Internal;
            commitment.CommitmentID       = line.CommitmentID ?? Guid.NewGuid();
            commitment.AccountGroupID     = GetAccountGroup(sender, row);
            commitment.ProjectID          = line.ProjectID;
            commitment.ProjectTaskID      = line.TaskID;
            commitment.UOM                = line.UOM;
            commitment.Qty                = sign * line.OrderQty;
            commitment.Amount             = sign * line.LineAmt;
            commitment.OpenQty            = sign * line.UnbilledQty;
            commitment.OpenAmount         = sign * line.UnbilledAmt;
            commitment.ReceivedQty        = 0;
            commitment.InvoicedQty        = 0;
            commitment.InvoicedAmount     = 0;
            commitment.InvoicedIsReadonly = true;
            commitment.RefNoteID          = order.NoteID;
            commitment.InventoryID        = line.InventoryID ?? PMInventorySelectorAttribute.EmptyInventoryID;
            commitment.CostCodeID         = line.CostCodeID ?? CostCodeAttribute.GetDefaultCostCode();

            return(commitment);
        }
예제 #18
0
        protected virtual IEnumerable CreateSOContact(PXAdapter adapter)
        {
            SOOrder   order   = adapter.Get().RowCast <SOOrder>().First();
            SOContact contact = Base.Billing_Contact.Current;
            SOAddress address = Base.Billing_Address.Current;

            if (contact != null && address != null)
            {
                if (string.IsNullOrEmpty(contact.Email))
                {
                    throw new ArgumentNullException(string.Format("{0} {1}", PX.Objects.AR.Messages.ARBillingContact.Substring(3), nameof(SOContact.Email)));
                }

                MyArray myArray = new MyArray()
                {
                    BillingEmail       = contact.Email,
                    BillingLastName    = contact.Attention,
                    BillingPhoneNumber = contact.Phone1,
                    BillingAddress     = address.AddressLine1,
                    BillingAddress2    = address.AddressLine2,
                    BillingCity        = address.City,
                    BillingCountry     = address.CountryID,
                    BillingZipCode     = address.PostalCode,
                    BillingState       = address.State
                };

                order.ContactID = ThreeDCartHelper.CreateSOContact(order.CustomerID, myArray);

                Base.CurrentDocument.Cache.MarkUpdated(order);
                Base.Save.Press();
            }

            return(adapter.Get());
        }
예제 #19
0
        public virtual void InvoiceOrder(DateTime invoiceDate, PXResult <SOOrderShipment, SOOrder, CurrencyInfo, SOAddress, SOContact, SOOrderType> order, PXResultset <SOShipLine, SOLine> details, Customer customer, DocumentList <ARInvoice, SOInvoice> list, InvoiceOrderDelegate baseMethod)
        {
            baseMethod(invoiceDate, order, details, customer, list);
            SOOrder       soorder = (SOOrder)order;
            SOOrderRUTROT orderRR = PXCache <SOOrder> .GetExtension <SOOrderRUTROT>(soorder);

            if (orderRR?.IsRUTROTDeductible == true && Base.Document.Current != null)
            {
                Base.Document.SetValueExt <ARInvoiceRUTROT.isRUTROTDeductible>(Base.Document.Current, true);
                Base.Document.Update(Base.Document.Current);

                RUTROT rutrot = PXSelect <RUTROT, Where <RUTROT.docType, Equal <Required <SOOrder.orderType> >,
                                                         And <RUTROT.refNbr, Equal <Required <SOOrder.orderNbr> > > > > .Select(Base, soorder.OrderType, soorder.OrderNbr);

                rutrot                      = (RUTROT)Base.Rutrots.Cache.CreateCopy(rutrot);
                rutrot.DocType              = Base.Document.Current.DocType;
                rutrot.RefNbr               = Base.Document.Current.RefNbr;
                rutrot.CuryDistributedAmt   = 0m;
                rutrot.CuryUndistributedAmt = 0m;
                rutrot                      = Base.Rutrots.Update(rutrot);
                RecalcFormulas(rutrot, PXCache <ARInvoice> .GetExtension <ARInvoiceRUTROT>(Base.Document.Current));
                foreach (RUTROTDistribution rutrotDetail in PXSelect <RUTROTDistribution, Where <RUTROTDistribution.docType, Equal <Required <SOOrder.orderType> >,
                                                                                                 And <RUTROTDistribution.refNbr, Equal <Required <SOOrder.orderNbr> > > > > .Select(Base, soorder.OrderType, soorder.OrderNbr))
                {
                    RUTROTDistribution new_detail = (RUTROTDistribution)Base.RRDistribution.Cache.CreateCopy(rutrotDetail);
                    new_detail.RefNbr  = null;
                    new_detail.DocType = null;
                    Base.RRDistribution.Insert(new_detail);
                }

                Base.Save.Press();
            }
        }
        private static void UpdateTrackingNumberDetails(SOGetFBATrackingNumberProcess graph, List <SOProcessOrder> list, SOAmazonSetup objSOAmazonSetupDetails, SOOrderEntry orderEntry, SOPartialMaint objPartialMaint, InvokeReporstServicesCallResponse liShipmentResponse)
        {
            string trackingNumber = string.Empty;
            string carrier        = string.Empty;

            foreach (SOProcessOrder currentRecord in list)
            {
                try
                {
                    if (liShipmentResponse != null && liShipmentResponse.objShipmentResponse != null && liShipmentResponse.objShipmentResponse.Count > 0)
                    {
                        trackingNumber = SOHelper.GetTrackingForFBAOrders(currentRecord.AmazonOrderID, liShipmentResponse.objShipmentResponse, out carrier);
                        currentRecord.AmazonTrackingNumber = !string.IsNullOrEmpty(trackingNumber) ? trackingNumber : null;
                        currentRecord.Carrier = !string.IsNullOrEmpty(carrier) ? carrier : null;
                        graph.TrackingNumberOrdersList.Cache.Update(currentRecord);
                        SOOrder objSOOrder = objPartialMaint.SOOrderView.Select(objSOAmazonSetupDetails.OrderType, currentRecord.AmazonOrderID);
                        if (objSOOrder != null)
                        {
                            PXNoteAttribute.SetNote(orderEntry.Document.Cache, objSOOrder, trackingNumber);
                            orderEntry.Document.Cache.Update(objSOOrder);
                            orderEntry.Actions.PressSave();
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw new PXException(ex.Message);
                }
            }
        }
예제 #21
0
        protected void disableSelectorValidationScopePart1()
        {
            // Retrieve an inactive income account from the chart of accounts and try to set it as sales account -- you'll receive an
            int?    prospectID = GetProspectID();
            SOOrder doc        = Base.Document.Current;

            doc.CustomerID = prospectID;
            Base.Document.Update(doc);
        }
        private void SetFreightData(PrepareAndImportOrdersParams orderParams)
        {
            //Update Premium Freight
            SOOrder          document    = orderParams.objSOOrderEntry.Document.Current;
            SOOrderAmazonExt documentExt = PXCache <SOOrder> .GetExtension <SOOrderAmazonExt>(document);

            document.CuryPremiumFreightAmt = documentExt.UsrAmazonFreightTotal.GetValueOrDefault(0) - documentExt.UsrAmazonFreightDiscountTotal.GetValueOrDefault(0);
            orderParams.objSOOrderEntry.Document.Update(document);
        }
예제 #23
0
 public virtual void SOOrder_TestField_FieldSelecting(PXCache sender, PXFieldSelectingEventArgs e)
 {
     if (e.Row != null)
     {
         List <string> values = new List <string>();
         values.AddRange(new [] { "First", "Second" });
         SOOrder row = (SOOrder)e.Row;
         PXStringListAttribute.SetList <SOOrderExt.testField>(sender, row, values.ToArray(), values.ToArray());
     }
 }
        private void SetDocumentLevelDiscountandTaxData(PrepareAndImportOrdersParams orderParams)
        {
            if (taxtotal <= 0)
            {
                return;
            }
            SOOrder currentFin = (SOOrder)orderParams.objSOOrderEntry.Document.Current;

            if (currentFin != null && orderParams.objSOOrderEntry.sosetup.Current != null)
            {
                SOSetupAmazonExt objSOOSetupext = orderParams.objSOOrderEntry.sosetup.Current.GetExtension <SOSetupAmazonExt>();
                if (objSOOSetupext != null && !string.IsNullOrEmpty(objSOOSetupext.UsrAmazonTaxID))
                {
                    if (currentFin.TaxZoneID != objSOOSetupext.UsrAmazonTaxZoneID)
                    {
                        currentFin.OverrideTaxZone = true;
                        currentFin           = orderParams.objSOOrderEntry.CurrentDocument.Update(currentFin);
                        currentFin.TaxZoneID = objSOOSetupext.UsrAmazonTaxZoneID;
                        currentFin           = orderParams.objSOOrderEntry.CurrentDocument.Update(currentFin);
                    }
                    if (currentFin.TaxZoneID != objSOOSetupext.UsrAmazonTaxZoneID)
                    {
                        return;
                    }

                    SOTaxTran orderTax = (SOTaxTran)orderParams.objSOOrderEntry.Taxes.Select();
                    if (orderTax == null && !string.IsNullOrEmpty(objSOOSetupext.UsrAmazonTaxID))
                    {
                        orderTax           = (SOTaxTran)orderParams.objSOOrderEntry.Taxes.Cache.Insert();
                        orderTax.OrderType = orderParams.objSOOrderEntry.Document.Current.OrderType;
                        orderTax.OrderNbr  = orderParams.objSOOrderEntry.Document.Current.OrderNbr;
                        orderTax.LineNbr   = int.MaxValue;
                        orderTax.TaxID     = objSOOSetupext.UsrAmazonTaxID;
                        orderParams.objSOOrderEntry.Taxes.Cache.Update(orderTax);
                        orderTax.CuryTaxableAmt = taxableamount;
                        orderTax.CuryTaxAmt     = taxtotal;
                        orderTax.TaxRate        = taxRate;
                        orderParams.objSOOrderEntry.Taxes.Cache.Update(orderTax);
                        orderParams.objSOOrderEntry.Document.SetValueExt <SOOrder.curyTaxTotal>(orderParams.objSOOrderEntry.Document.Current, taxtotal);
                        orderTotal = orderParams.objSOOrderEntry.Document.Current.OrderTotal + orderTax.CuryTaxAmt;
                        orderParams.objSOOrderEntry.Document.SetValueExt <SOOrder.curyOrderTotal>(orderParams.objSOOrderEntry.Document.Current, orderTotal);
                        orderParams.objSOOrderEntry.Document.Cache.Update(orderParams.objSOOrderEntry.Document.Current);
                    }
                    else if (orderTax != null && !string.IsNullOrEmpty(objSOOSetupext.UsrAmazonTaxID))
                    {
                        orderTax.CuryTaxAmt = taxtotal;
                        orderParams.objSOOrderEntry.Taxes.Cache.Update(orderTax);
                        orderParams.objSOOrderEntry.Document.SetValueExt <SOOrder.curyTaxTotal>(orderParams.objSOOrderEntry.Document.Current, taxtotal);
                        orderTotal = orderParams.objSOOrderEntry.Document.Current.OrderTotal + orderTax.CuryTaxAmt;
                        orderParams.objSOOrderEntry.Document.SetValueExt <SOOrder.curyOrderTotal>(orderParams.objSOOrderEntry.Document.Current, orderTotal);
                        orderParams.objSOOrderEntry.Document.Cache.Update(orderParams.objSOOrderEntry.Document.Current);
                    }
                }
            }
        }
예제 #25
0
 protected void disableSelectorValidationScopePart2()
 {
     // Retrieve an inactive income account from the chart of accounts and try to set it as sales account, this time using DisableSelectorValidationScope
     using (new DisableSelectorValidationScope(Base.Document.Cache))
     {
         int?    prospectID = GetProspectID();
         SOOrder doc        = Base.Document.Current;
         doc.CustomerID = prospectID;
         Base.Document.Update(doc);
     }
 }
예제 #26
0
        protected void _(Events.FieldUpdated <LumShipmentPlan.customer> e)
        {
            var row = e.Row as LumShipmentPlan;

            if (e.NewValue != null && row != null)
            {
                SOOrder soOrder = SOOrder.PK.Find(this, row.OrderType, row.OrderNbr);

                Order.Cache.SetValueExt(soOrder, PX.Objects.CS.Messages.Attribute + ENDC, e.NewValue);
                Order.Update(soOrder);
            }
        }
예제 #27
0
        protected virtual void SOOrder_IsRUTROTDeductible_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
        {
            SOOrder row = (SOOrder)e.Row;

            if (row != null)
            {
                SOOrderRUTROT rowRR = RUTROTHelper.GetExtensionNullable <SOOrder, SOOrderRUTROT>(row);
                if (rowRR.IsRUTROTDeductible == true)
                {
                    row.BillSeparately = true;
                }
            }
        }
예제 #28
0
        public IEnumerable <decimal?> GetPrediction(SOOrder salesOrder)
        {
            Prices = new List <decimal?>();
            var lineItems = SelectFrom <SOLine>
                            .Where <SOLine.orderNbr.IsEqual <P.AsString> > .View
                            .Select(this, salesOrder.OrderNbr).FirstTableItems;

            foreach (var lineItem in lineItems)
            {
                InvokeRequestResponseService(lineItem, salesOrder.CuryID).Wait();
            }
            return(Prices);
        }
예제 #29
0
        public static SOOrder GetSOOrder(SOOrderEntry orderGraph, KCAPIOrder order, SOOrder acumaticaOrder, int?branchID, bool FBA)
        {
            KCSiteMasterMaint graph = PXGraph.CreateInstance <KCSiteMasterMaint>();
            var customer            = KCGeneralDataHelper.GetCustomerByCAOrder(graph, order);
            var paymentmethod       = KCGeneralDataHelper.GetPaymenthMethodId(graph, order);
            var mapper          = new KCDynamicOrderMapper(KCMappingEntitiesConstants.Order);
            var conversionGraph = PXGraph.CreateInstance <KCOrderConversionDataMaint>();

            mapper.Mapping.MappingValues = conversionGraph.GetEntity();
            mapper.MapOrder(acumaticaOrder, order);
            if (paymentmethod == null)
            {
                KCPaymentMethodsMappingMaint paymentMethodMappingGraph = PXGraph.CreateInstance <KCPaymentMethodsMappingMaint>();
                CustomerPaymentMethodMaint   paymentMethodGraph        = PXGraph.CreateInstance <CustomerPaymentMethodMaint>();
                try
                {
                    KCGeneralDataHelper.CreatePaymentMethod(paymentMethodGraph, paymentMethodMappingGraph, customer.BAccountID, order);
                    paymentmethod = KCGeneralDataHelper.GetPaymenthMethodId(graph, order);
                }
                catch { }
            }
            acumaticaOrder.CustomerID       = customer.BAccountID;
            acumaticaOrder.PMInstanceID     = paymentmethod?.PMInstanceID;
            acumaticaOrder.Status           = SOOrderStatus.Open;
            acumaticaOrder.CreatePMInstance = true;
            KCSOOrderEntryExt orderext  = orderGraph.GetExtension <KCSOOrderEntryExt>();
            string            orderType = new KCMarketplaceHelper().GetOrderType(order, orderGraph);

            acumaticaOrder.OrderType = orderType ?? acumaticaOrder.OrderType;

            if (order.EstimatedShipDateUtc == null)
            {
                acumaticaOrder.RequestDate = acumaticaOrder.OrderDate;
            }
            orderGraph.CurrentDocument.Current = acumaticaOrder;

            PXNoteAttribute.SetNote(orderGraph.CurrentDocument.Cache, orderGraph.CurrentDocument.Current, order.PrivateNotes);
            string       firstName      = orderext.AccountCD.SelectSingle(acumaticaOrder.CustomerID).AcctName;
            bool         isFBAFirstName = firstName.Contains("FBA");
            KCSOOrderExt orderExt       = acumaticaOrder.GetExtension <KCSOOrderExt>();

            orderExt = mapper.MapOrderCaExt(orderExt, order);
            orderExt.UsrKCSyncDate  = DateTime.Now;
            orderExt.UsrKCSiteName += FBA ? "/FBA" : "/Non-FBA";
            if ((FBA && orderExt.UsrKCSiteName.Contains("Amazon")) || isFBAFirstName)
            {
                acumaticaOrder.Status = KCCheckoutStatus.CCompleted;
            }

            return(acumaticaOrder);
        }
예제 #30
0
        public override void UpdateARBalances(PXCache cache, Object newRow, Object oldRow)
        {
            if (oldRow != null)
            {
                SOOrder oldSORow = Document.Cache.GetMain((Document)oldRow) as SOOrder;
                ARReleaseProcess.UpdateARBalances(cache.Graph, oldSORow, -(oldSORow).UnbilledOrderTotal, -(oldSORow.OpenOrderTotal));
            }

            if (newRow != null)
            {
                SOOrder newSORow = Document.Cache.GetMain((Document)newRow) as SOOrder;
                ARReleaseProcess.UpdateARBalances(cache.Graph, newSORow, (newSORow).UnbilledOrderTotal, newSORow.OpenOrderTotal);
            }
        }
예제 #31
0
		private void FillFreightDetails(SOOrder order, SOOrderShipment ordershipment)
		{
            SOFreightDetail freightdet;

            if (ordershipment.ShipmentType == SOShipmentType.DropShip)
			{
                freightdet = PXSelect<SOFreightDetail, Where<SOFreightDetail.docType, Equal<Current<ARInvoice.docType>>, And<SOFreightDetail.refNbr, Equal<Current<SOFreightDetail.refNbr>>, And<SOFreightDetail.shipmentNbr, Equal<Current<SOOrderShipment.shipmentNbr>>>>>>.SelectSingleBound(this, new object[] { ordershipment });

                if (freightdet == null)
                {
                    freightdet = new SOFreightDetail();
                    freightdet.CuryInfoID = Document.Current.CuryInfoID;
                    freightdet.ShipmentNbr = ordershipment.ShipmentNbr;
                    freightdet.ShipmentType = ordershipment.ShipmentType;
                    freightdet.OrderType = ordershipment.OrderType;
                    freightdet.OrderNbr = ordershipment.OrderNbr;
                    freightdet.ProjectID = order.ProjectID;

                    int? accountID;
                    object subID;
                    GetFreightAccountAndSubAccount(order, order.ShipVia, out accountID, out subID);
                    freightdet.AccountID = accountID;
                    FreightDetails.Cache.RaiseFieldUpdating<SOFreightDetail.subID>(freightdet, ref subID);
                    freightdet.SubID = (int?)subID;

                    freightdet = FreightDetails.Insert(freightdet);
                }

                freightdet = PXCache<SOFreightDetail>.CreateCopy(freightdet);

                freightdet.ShipTermsID = order.ShipTermsID; //!!
                freightdet.ShipVia = order.ShipVia; //!!
                freightdet.ShipZoneID = order.ShipZoneID; //!!
                freightdet.TaxCategoryID = order.FreightTaxCategoryID;

                freightdet.Weight = 0m;
                freightdet.Volume = 0m;
                freightdet.CuryLineTotal = 0m;
                freightdet.CuryFreightCost = 0m;
                freightdet.CuryFreightAmt = 0m;
                freightdet.CuryPremiumFreightAmt = 0m;

                decimal dropShipLineAmt = 0m;
                foreach (PXResult<SOLine, PO.POLine, POReceiptLine> res in PXSelectJoin<SOLine, 
                    InnerJoin<PO.POLine, On<PO.POLine.lineNbr, Equal<SOLine.pOLineNbr>, And<PO.POLine.lineNbr, Equal<SOLine.pOLineNbr>>>, 
                    InnerJoin<POReceiptLine, On<POReceiptLine.pOLineNbr, Equal<PO.POLine.lineNbr>, And<POReceiptLine.pONbr, Equal<PO.POLine.orderNbr>>>>>, 
                    Where<POReceiptLine.receiptNbr, Equal<Required<POReceiptLine.receiptNbr>>, And<SOLine.orderType, 
                    Equal<Required<SOLine.orderType>>, And<SOLine.orderNbr, Equal<Required<SOLine.orderNbr>>>>>>.Select(this, ordershipment.ShipmentNbr, ordershipment.OrderType, ordershipment.OrderNbr))
                {
                    SOLine line2 = (SOLine)res;
                    dropShipLineAmt += line2.LineAmt ?? 0m;
                }

                foreach (PXResult<SOOrderShipment, SOOrder> res in PXSelectJoin<SOOrderShipment, InnerJoin<SOOrder, On<SOOrder.orderType, Equal<SOOrderShipment.orderType>, And<SOOrder.orderNbr, Equal<SOOrderShipment.orderNbr>>>>, Where<SOOrderShipment.invoiceType, Equal<Current<ARInvoice.docType>>, And<SOOrderShipment.invoiceNbr, Equal<Current<ARInvoice.refNbr>>>>>.SelectMultiBound(this, new object[] { ordershipment }))
                {
                    SOOrder order2 = (SOOrder)res;
                    freightdet.CuryLineTotal += dropShipLineAmt;
                    decimal? ShipRatio = order2.CuryLineTotal > 0m ? dropShipLineAmt / order2.LineTotal : 1m;

                    freightdet.CuryPremiumFreightAmt += PXDBCurrencyAttribute.Round(FreightDetails.Cache, freightdet, (decimal)(order2.CuryPremiumFreightAmt * (ShipRatio > 1m ? 1m : ShipRatio) ?? 0m), CMPrecision.TRANCURY);
                    freightdet.CuryFreightAmt += PXDBCurrencyAttribute.Round(FreightDetails.Cache, freightdet, (decimal)(order2.CuryFreightAmt * (ShipRatio > 1m ? 1m : ShipRatio) ?? 0m), CMPrecision.TRANCURY);
                }

                freightdet.CuryTotalFreightAmt = freightdet.CuryPremiumFreightAmt + freightdet.CuryFreightAmt;
                FreightDetails.Update(freightdet);

                if (freightdet.CuryTotalFreightAmt > 0 && freightdet.TaskID == null && !PM.ProjectDefaultAttribute.IsNonProject(this, freightdet.ProjectID))
                {
                    Account ac = PXSelect<Account, Where<Account.accountID, Equal<Required<Account.accountID>>>>.Select(this, freightdet.AccountID);
                    throw new PXException(Messages.TaskWasNotAssigned, ac.AccountCD);
                }
                return;
			}
			
			if (string.Equals(ordershipment.ShipmentNbr, Constants.NoShipmentNbr))
			{
				freightdet = PXSelect<SOFreightDetail, Where<SOFreightDetail.docType, Equal<Current<ARInvoice.docType>>, And<SOFreightDetail.refNbr, Equal<Current<SOFreightDetail.refNbr>>, And<SOFreightDetail.shipmentNbr, Equal<Current<SOOrderShipment.shipmentNbr>>>>>>.SelectSingleBound(this, new object[] { ordershipment });

				if (freightdet == null)
				{
					freightdet = new SOFreightDetail();
					freightdet.CuryInfoID = Document.Current.CuryInfoID;
					freightdet.ShipmentNbr = ordershipment.ShipmentNbr;
					freightdet.ShipmentType = ordershipment.ShipmentType;
                    freightdet.OrderType = ordershipment.OrderType;
                    freightdet.OrderNbr = ordershipment.OrderNbr;
					freightdet.ProjectID = order.ProjectID;

					int? accountID;
					object subID;
					GetFreightAccountAndSubAccount(order, order.ShipVia, out accountID, out subID);
					freightdet.AccountID = accountID;
					FreightDetails.Cache.RaiseFieldUpdating<SOFreightDetail.subID>(freightdet, ref subID);
					freightdet.SubID = (int?)subID;

					freightdet = FreightDetails.Insert(freightdet);
				}

				freightdet = PXCache<SOFreightDetail>.CreateCopy(freightdet);

				freightdet.ShipTermsID = order.ShipTermsID; //!!
				freightdet.ShipVia = order.ShipVia; //!!
				freightdet.ShipZoneID = order.ShipZoneID; //!!
				freightdet.TaxCategoryID = order.FreightTaxCategoryID;

				freightdet.Weight = 0m;
				freightdet.Volume = 0m;
				freightdet.CuryLineTotal = 0m;
				freightdet.CuryFreightCost = 0m;
				freightdet.CuryFreightAmt = 0m;
				freightdet.CuryPremiumFreightAmt = 0m;

				foreach (PXResult<SOOrderShipment, SOOrder> res in PXSelectJoin<SOOrderShipment, InnerJoin<SOOrder, On<SOOrder.orderType, Equal<SOOrderShipment.orderType>, And<SOOrder.orderNbr, Equal<SOOrderShipment.orderNbr>>>>, Where<SOOrderShipment.invoiceType, Equal<Current<ARInvoice.docType>>, And<SOOrderShipment.invoiceNbr, Equal<Current<ARInvoice.refNbr>>, And<SOOrderShipment.shipmentNbr, Equal<Constants.noShipmentNbr>>>>>.SelectMultiBound(this, new object[] { ordershipment }))
				{
					SOOrder order2 = (SOOrder)res;
					freightdet.Weight += order2.OrderWeight;
					freightdet.Volume += order2.OrderVolume;
					freightdet.CuryLineTotal += order2.CuryLineTotal;
					freightdet.CuryFreightCost += order2.CuryFreightCost;
					freightdet.CuryFreightAmt += order2.CuryFreightAmt;
					freightdet.CuryPremiumFreightAmt += order2.CuryPremiumFreightAmt;
				}

				freightdet.CuryTotalFreightAmt = freightdet.CuryPremiumFreightAmt + freightdet.CuryFreightAmt;
				FreightDetails.Update(freightdet);

				if (freightdet.CuryTotalFreightAmt > 0 && freightdet.TaskID == null && !PM.ProjectDefaultAttribute.IsNonProject(this, freightdet.ProjectID))
				{
					Account ac = PXSelect<Account, Where<Account.accountID, Equal<Required<Account.accountID>>>>.Select(this, freightdet.AccountID);
					throw new PXException(Messages.TaskWasNotAssigned, ac.AccountCD);
				}
			}
			else
			{
				freightdet = PXSelect<SOFreightDetail, Where<SOFreightDetail.shipmentNbr, Equal<Current<SOOrderShipment.shipmentNbr>>>>.SelectSingleBound(this, new object[] { ordershipment });

				if (freightdet == null)
				{
					SOShipment shipment = PXSelect<SOShipment, Where<SOShipment.shipmentNbr, Equal<Current<SOOrderShipment.shipmentNbr>>>>.Select(this, new object[] { ordershipment });

					if (shipment != null)
					{
						freightdet = new SOFreightDetail();
						freightdet.CuryInfoID = Document.Current.CuryInfoID;
						freightdet.ShipmentNbr = ordershipment.ShipmentNbr;
						freightdet.ShipmentType = ordershipment.ShipmentType;
                        if ((PXSelect<SOOrderShipment, Where<SOOrderShipment.shipmentNbr, Equal<Current<SOOrderShipment.shipmentNbr>>>>.Select(this)).Count == 1)
                        {
                            freightdet.OrderType = ordershipment.OrderType;
                            freightdet.OrderNbr = ordershipment.OrderNbr;
                        }
						freightdet.ProjectID = order.ProjectID;

						freightdet.ShipTermsID = shipment.ShipTermsID;
						freightdet.ShipVia = shipment.ShipVia;
						freightdet.ShipZoneID = shipment.ShipZoneID;
						freightdet.TaxCategoryID = shipment.TaxCategoryID;
						freightdet.Weight = shipment.ShipmentWeight;
						freightdet.Volume = shipment.ShipmentVolume;
						freightdet.LineTotal = shipment.LineTotal;
						PXCurrencyAttribute.CuryConvCury<SOFreightDetail.curyLineTotal>(FreightDetails.Cache, freightdet);
						freightdet.FreightCost = shipment.FreightCost;
						PXCurrencyAttribute.CuryConvCury<SOFreightDetail.curyFreightCost>(FreightDetails.Cache, freightdet);
						freightdet.FreightAmt = shipment.FreightAmt;
						PXCurrencyAttribute.CuryConvCury<SOFreightDetail.curyFreightAmt>(FreightDetails.Cache, freightdet);

						freightdet.CuryPremiumFreightAmt = 0m;
						//recalculate All Premium Freight for Shipment
						foreach (PXResult<SOOrderShipment, SOOrder> res in PXSelectJoin<SOOrderShipment, InnerJoin<SOOrder, On<SOOrder.orderType, Equal<SOOrderShipment.orderType>, And<SOOrder.orderNbr, Equal<SOOrderShipment.orderNbr>>>>, Where<SOOrderShipment.shipmentNbr, Equal<Current<SOOrderShipment.shipmentNbr>>, And<SOOrderShipment.shipmentType, NotEqual<SOShipmentType.dropShip>>>>.SelectMultiBound(this, new object[] { ordershipment }))
						{
							SOOrderShipment ordershipment2 = (SOOrderShipment)res;
							SOOrder order2 = (SOOrder)res;

							if (sosetup.Current.FreightAllocation == FreightAllocationList.Prorate)
							{
								if (order2.CuryLineTotal > 0m)
								{
									decimal? ShipRatio = ordershipment2.LineTotal / order2.LineTotal;
									freightdet.CuryPremiumFreightAmt += PXDBCurrencyAttribute.Round(FreightDetails.Cache, freightdet, (decimal)(order2.CuryPremiumFreightAmt * (ShipRatio > 1m ? 1m : ShipRatio) ?? 0m), CMPrecision.TRANCURY);
								}
								else
								{
									freightdet.CuryPremiumFreightAmt += order2.CuryPremiumFreightAmt;
								}
							}
							else
							{
								SOOrderShipment prev_shipment = PXSelectReadonly<SOOrderShipment,
									Where<SOOrderShipment.shipmentNbr, NotEqual<Current<SOOrderShipment.shipmentNbr>>, And<SOOrderShipment.shipmentType, NotEqual<SOShipmentType.dropShip>,
									And<SOOrderShipment.orderType, Equal<Current<SOOrderShipment.orderType>>,
									And<SOOrderShipment.orderNbr, Equal<Current<SOOrderShipment.orderNbr>>,
									And<SOOrderShipment.invoiceNbr, IsNotNull>>>>>>.SelectSingleBound(this, new object[] { ordershipment2 });
								if (prev_shipment == null)
								{
									freightdet.CuryPremiumFreightAmt += order2.CuryPremiumFreightAmt;
								}
								else
								{
									freightdet.CuryPremiumFreightAmt = 0m;
								}
							}
						}

						freightdet.CuryTotalFreightAmt = freightdet.CuryPremiumFreightAmt + freightdet.CuryFreightAmt;

						int? accountID;
						object subID;
						GetFreightAccountAndSubAccount(order, shipment.ShipVia, out accountID, out subID);
						freightdet.AccountID = accountID;
						FreightDetails.Cache.RaiseFieldUpdating<SOFreightDetail.subID>(freightdet, ref subID);
						freightdet.SubID = (int?)subID;

						freightdet = FreightDetails.Insert(freightdet);
					}
				}
			}
		}
예제 #32
0
		private void GetFreightAccountAndSubAccount(SOOrder order, string ShipVia, out int? accountID, out object subID)
		{
			accountID = null;
			subID = null;
			SOOrderType type = PXSelect<SOOrderType, Where<SOOrderType.orderType, Equal<Required<SOOrderType.orderType>>>>.Select(this, order.OrderType);

			if (type != null)
			{
				Location customerloc = location.Current;
				Carrier carrier = PXSelect<Carrier, Where<Carrier.carrierID, Equal<Required<Carrier.carrierID>>>>.Select(this, ShipVia);

                Location companyloc =
                        (Location)PXSelectJoin<Location, InnerJoin<BAccountR, On<Location.bAccountID, Equal<BAccountR.bAccountID>, And<Location.locationID, Equal<BAccountR.defLocationID>>>, InnerJoin<Branch, On<Branch.bAccountID, Equal<BAccountR.bAccountID>>>>, Where<Branch.branchID, Equal<Current<ARRegister.branchID>>>>.Select(this);

				switch (type.FreightAcctDefault)
				{
					case SOFreightAcctSubDefault.OrderType:
						accountID = (int?)GetValue<SOOrderType.freightAcctID>(type);
						break;
					case SOFreightAcctSubDefault.MaskLocation:
						accountID = (int?)GetValue<Location.cFreightAcctID>(customerloc);
						break;
					case SOFreightAcctSubDefault.MaskShipVia:
						accountID = (int?)GetValue<Carrier.freightSalesAcctID>(carrier);
						break;
				}

				if (accountID == null)
				{
					accountID = type.FreightAcctID;

					if (accountID == null)
					{
						throw new PXException(Messages.FreightAccountIsRequired);
					}

				}

				if (accountID != null)
				{
					object orderType_SubID = GetValue<SOOrderType.freightSubID>(type);
					object customer_Location_SubID = GetValue<Location.cFreightSubID>(customerloc);
					object carrier_SubID = GetValue<Carrier.freightSalesSubID>(carrier);
                    object branch_SubID = GetValue<Location.cMPFreightSubID>(companyloc);

					subID = SOFreightSubAccountMaskAttribute.MakeSub<SOOrderType.freightSubMask>(this, type.FreightSubMask,
						new object[] { orderType_SubID, customer_Location_SubID, carrier_SubID, branch_SubID },
						new Type[] { typeof(SOOrderType.freightSubID), typeof(Location.cFreightSubID), typeof(Carrier.freightSalesSubID), typeof(Location.cMPFreightSubID) });

				}
			}
		}