Exemple #1
0
        public virtual void CopySOLine()
        {
            SOLineSplitFilter current1 = this.LineSplitFilter.Current;
            SOLine            current2 = this.Base.Transactions.Current;
            SOLine            copy     = this.Base.Transactions.Cache.CreateCopy((object)current2) as SOLine;

            copy.LineNbr = copy.SortOrder = (int?)PXLineNbrAttribute.NewLineNbr <SOLine.lineNbr>(this.Base.Transactions.Cache, (object)this.Base.Document.Current);
            SOLine   soLine1   = copy;
            DateTime?shipDate  = current1.ShipDate;
            DateTime?nullable1 = shipDate.HasValue ? shipDate : current2.ShipDate;

            soLine1.ShipDate = nullable1;
            SOLine soLine2   = copy;
            bool?  poCreate  = current2.POCreate;
            bool   flag      = true;
            bool?  nullable2 = poCreate.GetValueOrDefault() == flag & poCreate.HasValue ? new bool?(!this.SOSplitHasPONbr(current2)) : current2.POCreate;

            soLine2.POCreate = nullable2;
            copy.NoteID      = new Guid?(Guid.NewGuid());
            copy.GetExtension <SOLineExt>().UsrOrigQty = current1.SplitQty;
            this.Base.Transactions.Insert(copy);
            copy.OrderQty = current1.SplitQty;
            this.Base.Transactions.Update(copy);
            if (!current2.GetExtension <SOLineExt>().UsrOrigQty.HasValue)
            {
                current2.GetExtension <SOLineExt>().UsrOrigQty = current2.OrderQty;
            }
            SOLine  soLine3  = current2;
            Decimal?orderQty = soLine3.OrderQty;
            Decimal?qty      = copy.Qty;

            soLine3.OrderQty = orderQty.HasValue & qty.HasValue ? new Decimal?(orderQty.GetValueOrDefault() - qty.GetValueOrDefault()) : new Decimal?();
            this.Base.Transactions.Update(current2);
        }
        public static void GetSOLine(KCAPIOrderItem orderItem, InventoryItem item, SOLine soLine, int?branchID, int?defaultWarehouse)
        {
            soLine.BranchID      = branchID;
            soLine.Qty           = orderItem.Quantity;
            soLine.OpenQty       = orderItem.Quantity;
            soLine.CuryUnitPrice = orderItem.UnitPrice;
            soLine.UOM           = item.SalesUnit;
            soLine.SalesAcctID   = item.SalesAcctID;
            soLine.SalesSubID    = item.SalesSubID ?? KCGeneralDataHelper.GetDefaultSalesSubID();
            soLine.InventoryID   = item.InventoryID;
            soLine.SiteID        = defaultWarehouse;
            soLine.TaxCategoryID = "TAXABLE";
            soLine.CuryLineAmt   = soLine.CuryUnitPrice * soLine.Qty;
            soLine.ShipComplete  = "B";
            KCSOLineExt soLineExt = soLine.GetExtension <KCSOLineExt>();

            soLineExt.UsrKCOrderItemID = orderItem.ID;
            soLineExt.UsrKCCAOrderID   = orderItem.OrderID;

            SOLinePCExt        soLinePCExt = soLine.GetExtension <SOLinePCExt>();
            InventoryItemPCExt itemPCExt   = item.GetExtension <InventoryItemPCExt>();

            if (itemPCExt.UsrKNCompositeType != null)
            {
                soLinePCExt.UsrKNIsMasterLine = true;
            }
        }
        public ODataShipment GetAPIShipment(SOShipment shipment, SOPackageDetail package, PXResultset <SOLine> lines)
        {
            var wrapper     = new ODataShipment();
            var apiShipment = new KCAPIShipment()
            {
                ShippedDateUtc  = shipment.ShipDate,
                TrackingNumber  = package?.TrackNumber,
                ShippingCarrier = shipment.ShipVia,
                ShippingClass   = shipment.ShipVia,
                DeliveryStatus  = "Complete"
            };
            var apiItems = new List <KCAPIShipmentItem>();

            foreach (PXResult <SOLine> line in lines)
            {
                SOLine     soLine   = line.GetItem <SOLine>();
                SOShipLine shipLine = line.GetItem <SOShipLine>();
                DAC.KNSIKCInventoryItem kcInventoryItem    = line.GetItem <DAC.KNSIKCInventoryItem>();
                InventoryItem           inventoryItem      = line.GetItem <InventoryItem>();
                InventoryItemPCExt      inventoryItemPcExt = inventoryItem.GetExtension <InventoryItemPCExt>();
                SOLinePCExt             soLinePcExt        = soLine.GetExtension <SOLinePCExt>();

                int quantity = Convert.ToInt32(shipLine.ShippedQty.GetValueOrDefault());

                if ((soLine.LineNbr != soLinePcExt?.UsrKNMasterLineNbr && ParentIsGrouped(lines, soLinePcExt)) ||
                    (inventoryItemPcExt?.UsrKNCompositeType == KCConstants.ConfigurableProduct && soLine.LineNbr == soLinePcExt?.UsrKNMasterLineNbr))
                {
                    continue;
                }

                if (inventoryItemPcExt?.UsrKNCompositeType == KCConstants.GroupedProduct && quantity == 0)
                {
                    SOShipLine childItem = lines.Where(x => x.GetItem <SOLine>().GetExtension <SOLinePCExt>().UsrKNMasterLineNbr == soLine.LineNbr &&
                                                       x.GetItem <SOLine>().LineNbr != soLine.LineNbr).RowCast <SOShipLine>().FirstOrDefault();

                    if (childItem != null)
                    {
                        KCDataExchangeMaint     graph          = PXGraph.CreateInstance <KCDataExchangeMaint>();
                        List <KNSIGroupedItems> origChildItems = graph.GroupedChildItems.Select(inventoryItem.InventoryID).RowCast <KNSIGroupedItems>().ToList();
                        quantity = Convert.ToInt32(childItem.ShippedQty / origChildItems.Where(x => x.MappedInventoryID == childItem.InventoryID).FirstOrDefault().Quantity);
                    }
                    else
                    {
                        throw new KCCorruptedShipmentException();
                    }
                }

                apiItems.Add(new KCAPIShipmentItem
                {
                    ProductID   = kcInventoryItem?.UsrKCCAID.ToString(),
                    OrderItemID = soLine?.GetExtension <KCSOLineExt>()?.UsrKCOrderItemID.ToString(),
                    Quantity    = shipLine == null ? 0 : Convert.ToInt32(quantity)
                });
            }

            apiShipment.Items = apiItems;
            wrapper.Value     = apiShipment;

            return(wrapper);
        }
Exemple #4
0
        protected virtual void ARTaxTran_RowInserting(PXCache sender, PXRowInsertingEventArgs e, PXRowInserting baseHandler)
        {
            if (!(e.Row is ARTaxTran row))
            {
                return;
            }
            baseHandler?.Invoke(sender, e);

            row.CuryTaxableAmt = 0;

            foreach (ARTran tran in Base.Transactions.Select())
            {
                SOLine line = PXSelect <
                    SOLine,
                    Where <SOLine.orderNbr, Equal <Required <SOLine.orderNbr> > > >
                              .Select(Base, tran.SOOrderNbr);

                SOLinePCExt   linePCExt = line.GetExtension <SOLinePCExt>();
                InventoryItem product   = KCInventoryItem.SelectSingle(tran.InventoryID);
                if (product != null)
                {
                    InventoryItemPCExt productPCExt = product.GetExtension <InventoryItemPCExt>();
                    if (productPCExt != null)
                    {
                        if (productPCExt.UsrKNCompositeType == null)
                        {
                            row.CuryTaxableAmt += tran.CuryTranAmt;
                        }
                    }
                }
            }
            baseHandler.Invoke(sender, e);
        }
Exemple #5
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;
                }
            }
        }
        /// <summary>
        /// Update the parent blanket order line to reflect the child line qty changing
        /// </summary>
        /// <param name="childOrderLine">child row of blanket order to update</param>
        /// <param name="orderQtyChange">qty changing (+/-)</param>
        protected virtual void UpdateParentBlanketOrderLine(SOLine childOrderLine, decimal orderQtyChange)
        {
            if (childOrderLine == null || orderQtyChange == 0m)
            {
                return;
            }

            var rowExt            = childOrderLine.GetExtension <SOLineDAExtension>();
            var parentBlanketLine = (BlanketSOLine)PXSelect <BlanketSOLine,
                                                             Where <BlanketSOLine.orderType, Equal <Required <BlanketSOLine.orderType> >,
                                                                    And <BlanketSOLine.orderNbr, Equal <Required <BlanketSOLine.orderNbr> >,
                                                                         And <BlanketSOLine.lineNbr, Equal <Required <BlanketSOLine.lineNbr> > > > > > .Select(Base,
                                                                                                                                                               rowExt.DABlanketOrderType, rowExt.DABlanketOrderNbr, rowExt.DABlanketLineNbr);

            if (parentBlanketLine == null)
            {
                return;
            }

            parentBlanketLine.DABlanketOrderQty += orderQtyChange;
            if (parentBlanketLine.DABlanketOrderQty.GetValueOrDefault() < 0m)
            {
                parentBlanketLine.DABlanketOrderQty = 0m;
            }
            parentBlanketLine.OpenQty = Math.Max(parentBlanketLine.OrderQty.GetValueOrDefault() - parentBlanketLine.DABlanketOrderQty.GetValueOrDefault(), 0m);
            blanketLinesSelected.Update(parentBlanketLine);
        }
        private decimal?GetLinesQty(List <SOShipLine> lines)
        {
            decimal?qty = 0;

            foreach (SOShipLine line in lines)
            {
                SOLine      soLine      = KCSOLineByLineNbrAndOrderNbr.SelectSingle(line.OrigLineNbr, line.OrigOrderNbr);
                SOLinePCExt soLinePCExt = soLine.GetExtension <SOLinePCExt>();

                if (soLinePCExt.UsrKNMasterLineNbr == null || soLinePCExt.UsrKNMasterLineNbr != soLine.LineNbr)
                {
                    qty += line.Qty;
                }
            }

            return(qty);
        }
        protected virtual void SOShipLine_RowUpdated(PXCache sender, PXRowUpdatedEventArgs e, PXRowUpdated baseHandler)
        {
            if (!(e.Row is SOShipLine))
            {
                return;
            }
            baseHandler?.Invoke(sender, e);
            SOShipLine row                = e.Row as SOShipLine;
            SOLine     soLine             = KCSOLineByLineNbrAndOrderNbr.SelectSingle(row.OrigLineNbr, row.OrigOrderNbr);
            int?       UsrKNMasterLineNbr = soLine?.GetExtension <SOLinePCExt>().UsrKNMasterLineNbr;

            if (soLine != null && soLine.GetExtension <SOLinePCExt>().UsrKNMasterLineNbr == soLine.LineNbr && row.LocationID == null)
            {
                SOShipLine childLine     = KCSOLineByMasterLineAndOrderNbr.Select(UsrKNMasterLineNbr, row.OrigOrderNbr).RowCast <SOLine>().Where(x => x.LineNbr != soLine.LineNbr).FirstOrDefault();
                SOShipLine childShipLine = Base.Transactions.Select().RowCast <SOShipLine>().Where(x => x.OrigLineNbr == childLine?.LineNbr).FirstOrDefault();
                row.LocationID = childShipLine?.LocationID;
            }
        }
        private void SetSOLineObjectsData(PrepareAndImportOrdersParams orderParams)
        {
            IEnumerable <SOFieldMapping> objMapping = orderParams.objliUsrMapping.Where(x => x.TargetObject == orderParams.objSOOrderEntry.Transactions.View.Name &&
                                                                                        x.TargetField.ToLower() == SOConstants.inventoryID.ToLower());

            if (objMapping.ToList().Count > 0)
            {
                foreach (OrderItem currentitem in orderParams.objamwLineItems)
                {
                    SOLine newitems = (SOLine)orderParams.objSOOrderEntry.Transactions.Cache.Insert();
                    foreach (SOFieldMapping data in orderParams.objliUsrMapping.Where(x => x.TargetObject == orderParams.objSOOrderEntry.Transactions.View.Name &&
                                                                                      x.TargetField.ToLower() == SOConstants.inventoryID.ToLower()))
                    {
                        if (data.SourceObject.ToLower().Trim() == SOConstants.orderItemTag.ToLower())
                        {
                            string fieldValue = currentitem != null?Convert.ToString(currentitem.GetType().GetProperty(data.SourceField).GetValue(currentitem, null)) : string.Empty;

                            string itemCode = SOLineInventoryItemAmazonExtAttribute.GetInventoryCode(orderParams.objSOOrderEntry.Transactions.Cache, fieldValue);

                            InventoryItem item = PXSelect <InventoryItem, Where <InventoryItem.inventoryCD, Equal <Required <InventoryItem.inventoryCD> >,
                                                                                 And <InventoryItem.itemStatus, Equal <InventoryItemStatus.active> > > > .Select(orderParams.objSOOrderEntry, itemCode);

                            newitems.InventoryID = item != null && item.InventoryID.HasValue ? item.InventoryID : null;
                            orderParams.objSOOrderEntry.Transactions.Update(newitems);
                            if (newitems.InventoryID.HasValue)
                            {
                                AssignValueAsPerIntegrationMapping(orderParams.objliUsrMapping, newitems, orderParams.ObjCurrentOrder, currentitem, orderParams.objSOOrderEntry.Transactions.View.Name);
                                //Embedd GiftPrice
                                string sGiftWrappPrice = currentitem.GiftWrapPrice != null?Convert.ToString(currentitem.GiftWrapPrice.Amount) : string.Empty;

                                newitems.CuryUnitPrice += String.IsNullOrEmpty(sGiftWrappPrice) ? 0m : Convert.ToDecimal(sGiftWrappPrice);

                                newitems.CuryUnitPrice = newitems.CuryUnitPrice > 0 && currentitem.QuantityOrdered > 0 ? newitems.CuryUnitPrice / currentitem.QuantityOrdered : newitems.CuryUnitPrice;
                                newitems.SiteID        = orderParams.objSOAmazonSetup.DfltWarehouseID;
                                SOSetupAmazonExt objSOOSetupext = orderParams.objSOOrderEntry.sosetup.Current.GetExtension <SOSetupAmazonExt>();
                                if (objSOOSetupext != null && !string.IsNullOrEmpty(objSOOSetupext.UsrAmazonTaxID))
                                {
                                    TaxCategoryDet objTaxDetails = PXSelect <TaxCategoryDet,
                                                                             Where <TaxCategoryDet.taxID, Equal <Required <Tax.taxID> > > >
                                                                   .Select(orderParams.objSOOrderEntry, objSOOSetupext.UsrAmazonTaxID);

                                    if (objTaxDetails != null)
                                    {
                                        newitems.TaxCategoryID = objTaxDetails.TaxCategoryID;
                                    }
                                    SOLineAmazonExt objnewitemsext = newitems.GetExtension <SOLineAmazonExt>();
                                    if (objnewitemsext != null)
                                    {
                                        objnewitemsext.UsrAMOrderItemID = currentitem.OrderItemId;
                                    }
                                    orderParams.objSOOrderEntry.Transactions.Update(newitems);
                                    FillDiscountObjectsData(orderParams.objSOOrderEntry, newitems, currentitem);

                                    taxtotal += currentitem.GiftWrapTax != null && !string.IsNullOrEmpty(currentitem.GiftWrapTax.Amount) && Convert.ToDecimal(currentitem.GiftWrapTax.Amount) > 0
                                             ? Convert.ToDecimal(currentitem.GiftWrapTax.Amount) : 0;

                                    taxtotal += currentitem.ItemTax != null && !string.IsNullOrEmpty(currentitem.ItemTax.Amount) && Convert.ToDecimal(currentitem.ItemTax.Amount) > 0
                                                 ? Convert.ToDecimal(currentitem.ItemTax.Amount) : 0;
                                    taxtotal += currentitem.ShippingTax != null && !string.IsNullOrEmpty(currentitem.ShippingTax.Amount) && Convert.ToDecimal(currentitem.ShippingTax.Amount) > 0
                                                ? Convert.ToDecimal(currentitem.ShippingTax.Amount) : 0;
                                    taxableamount += currentitem.ItemPrice != null && !string.IsNullOrEmpty(currentitem.ItemPrice.Amount) && Convert.ToDecimal(currentitem.ItemPrice.Amount) > 0
                                                    ? Convert.ToDecimal(currentitem.ItemPrice.Amount) : 0;
                                    shippingprice += currentitem.ShippingPrice != null && !string.IsNullOrEmpty(currentitem.ShippingPrice.Amount) && Convert.ToDecimal(currentitem.ShippingPrice.Amount) > 0
                                                    ? Convert.ToDecimal(currentitem.ShippingPrice.Amount) : 0;
                                    taxRate = (taxableamount > 0) ? (taxtotal * 100) / taxableamount : 0;
                                }
                                else
                                {
                                    throw new PXException(SOMessages.configMissing);
                                }
                            }
                            else
                            {
                                throw new PXException(SOMessages.inventoryItemNotExists);
                            }
                        }
                        else
                        {
                            throw new PXException(SOMessages.inventoryMappedtoOrderItem);
                        }
                    }
                }
            }
            else
            {
                throw new PXException(SOMessages.InvMappingErrorMsg);
            }
        }
Exemple #10
0
 protected static void GenerateData(FLXSupplyDemandProc graph, FLXSupplyDemand record)
 {
     try
     {
         graph.SupplyDemandProc.Delete(record);
         graph.Save.Press();
         if (graph.SupplyDemandProc.Select().Count == 0)
         {
             int num = 1;
             foreach (PXResult <SOLine, PX.Objects.SO.SOOrder> pxResult in SelectFrom <SOLine> .InnerJoin <PX.Objects.SO.SOOrder> .On <SOLine.orderType.IsEqual <PX.Objects.SO.SOOrder.orderType>
                                                                                                                                       .And <SOLine.orderNbr.IsEqual <PX.Objects.SO.SOOrder.orderNbr> > >
                      .Where <SOLine.openQty.IsGreater <decimal0>
                              .And <Where <PX.Objects.SO.SOOrder.orderType.IsEqual <P.AsString>
                                           .Or <PX.Objects.SO.SOOrder.orderType.IsEqual <P.AsString>
                                                .Or <PX.Objects.SO.SOOrder.orderType.IsEqual <P.AsString> > > > > > .View.ReadOnly.Select((PXGraph)graph, (object)"SO", (object)"SF", (object)"SS"))
             {
                 PX.Objects.SO.SOOrder soOrder   = (PX.Objects.SO.SOOrder)pxResult;
                 SOLine          soLine          = (SOLine)pxResult;
                 SOLineExt       extension       = soLine.GetExtension <SOLineExt>();
                 FLXSupplyDemand flxSupplyDemand = new FLXSupplyDemand()
                 {
                     LineNbr       = new int?(num++),
                     InventoryID   = soLine.InventoryID,
                     Type          = "D",
                     OpenQty       = soLine.OpenQty,
                     OrderDate     = soLine.ShipDate,
                     SOOrderType   = soLine.OrderType,
                     SOOrderNbr    = soLine.OrderNbr,
                     SOOrderStatus = soOrder.Status,
                     EndCustomerID = extension.UsrEndCustomerID,
                     NonStockMPN   = extension.UsrNonStockItem,
                     ProjectNbr    = extension.UsrProjectNbr
                 };
                 graph.SupplyDemandProc.Insert(flxSupplyDemand);
             }
             foreach (PXResult <POLine, POOrder> pxResult in SelectFrom <POLine> .InnerJoin <POOrder> .On <POLine.orderType.IsEqual <POOrder.orderType>
                                                                                                           .And <POLine.orderNbr.IsEqual <POOrder.orderNbr> > >
                      .Where <POLine.openQty.IsGreater <decimal0> > .View.ReadOnly.Select((PXGraph)graph))
             {
                 POOrder         poOrder         = (POOrder)pxResult;
                 POLine          poLine          = (POLine)pxResult;
                 POLineExt       extension       = poLine.GetExtension <POLineExt>();
                 FLXSupplyDemand flxSupplyDemand = new FLXSupplyDemand()
                 {
                     LineNbr       = new int?(num++),
                     InventoryID   = poLine.InventoryID,
                     Type          = "S",
                     OpenQty       = poLine.OpenQty,
                     OrderDate     = poLine.RequestedDate,
                     POOrderType   = poLine.OrderType,
                     POOrderNbr    = poLine.OrderNbr,
                     POOrderStatus = poOrder.Status,
                     EndCustomerID = extension.UsrEndCustomerID,
                     NonStockMPN   = extension.UsrNonStockItem,
                     ProjectNbr    = extension.UsrProjectNbr
                 };
                 graph.SupplyDemandProc.Insert(flxSupplyDemand);
             }
         }
         graph.Save.Press();
     }
     catch (Exception ex)
     {
         PXProcessing.SetError <FLXSupplyDemand>(ex);
         throw;
     }
 }