示例#1
0
        OrderItem InitOrderItem(DataRow row)
        {
            QuickBooksProductMapDef map     = null;
            MaestroProduct          product = null;
            MaestroUnit             unit    = null;
            long mapId     = row.Field <long>("QB_PRODUCT_MAP_ID");
            long productId = row.Field <long>("PRODUCT_ID");
            long unitId    = row.Field <long>("UNIT_ID");

            if (mapId >= 0)
            {
                map = QuickBooksProductMapCache.Instance[mapId];
            }

            if (productId >= 0)
            {
                product = ProductCache.Instance[productId];
            }
            if (unitId >= 0)
            {
                unit = UnitCache.Instance[unitId];
            }

            decimal price = 0;

            if (map != null)
            {
                price = map.Price;
            }

            if (product == null)
            {
                product = pm.GetUnknownItem();
            }

            if (unit == null)
            {
                unit = um.GetUnknownItem();
            }


            OrderItem result = new OrderItem()
            {
                Id           = row.Field <long>("ID"),
                CreateDate   = row.Field <DateTime>("CREATE_DATE"),
                CreatedUser  = row.Field <string>("CREATE_USER"),
                RecordStatus = row.Field <string>("RECORD_STATUS"),
                UpdateDate   = row.Field <DateTime>("UPDATE_DATE"),
                UpdatedUser  = row.Field <string>("UPDATE_USER"),
                OrderId      = row.Field <long>("ORDER_ID"),
                Product      = ProductCache.Instance[row.Field <long>("PRODUCT_ID")],
                Quantity     = row.Field <int>("QUANTITY"),
                QbProductMap = map,
                Price        = row.Field <decimal>("PRICE"),
                Unit         = unit,
                Amount       = row.Field <decimal>("AMOUNT")
            };

            return(result);
        }
示例#2
0
        public override void Deserialize(JToken token)
        {
            JObject entityObj = JObject.Parse(token.ToString());

            OrderMaster result = new OrderMaster()
            {
                Id                = entityObj["Id"].ToObject <long>(),
                OrderDate         = entityObj["OrderDate"].ToObject <DateTime>(),
                DeliveryDate      = entityObj["DeliveryDate"].ToObject <DateTime>(),
                PaymentType       = entityObj["PaymentType"].ToObject <string>(),
                Notes             = entityObj["Notes"].ToObject <string>(),
                OrderStatus       = entityObj.ContainsKey("OrderStatus") ? token["OrderStatus"].ToObject <string>() : string.Empty,
                ShippingAddressId = entityObj["ShippingAddressId"].ToObject <long>(),
                CreateDate        = DateTime.Now,
                UpdateDate        = DateTime.Now,
                RecordStatus      = "A",
                CreatedUser       = Context.UserName,
                UpdatedUser       = Context.UserName,
                OrderItems        = new List <OrderItem>()
            };

            result.Customer = CustomerCache.Instance[entityObj["CustomerId"].ToObject <long>()];
            UnitManager   um = new UnitManager(Context);
            List <JToken> orderItemTokens = entityObj["OrderItems"].Children().ToList();

            foreach (JToken itemToken in orderItemTokens)
            {
                QuickBooksProductMapDef map     = QuickBooksProductMapCache.Instance[itemToken["MapId"].ToObject <long>()];
                MaestroProduct          product = ProductCache.Instance[map.ProductId];
                long unitId = 0;
                if (map.UnitTypeCanHaveUnits)
                {
                    unitId = itemToken["UnitId"].ToObject <long>();
                }

                MaestroUnit unit      = unitId > 0 ? UnitCache.Instance[unitId] : um.GetUnknownItem();
                OrderItem   orderItem = new OrderItem()
                {
                    OrderId      = result.Id,
                    Product      = product,
                    QbProductMap = map,
                    Quantity     = itemToken["Quantity"].ToObject <int>(),
                    Unit         = unit,
                    Price        = map.Price,
                    CreateDate   = DateTime.Now,
                    UpdateDate   = DateTime.Now,
                    RecordStatus = "A",
                    CreatedUser  = Context.UserName,
                    UpdatedUser  = Context.UserName
                };
                result.OrderItems.Add(orderItem);
            }
            ;

            Context.TransactionObject = result;
        }
示例#3
0
        public void Update(QuickBooksProductMapDef map)
        {
            SpCall call = new SpCall("DAT.QB_PRODUCT_MAP_UPDATE");

            call.SetBigInt("@ID", map.Id);
            call.SetBigInt("@PRODUCT_ID", map.Product.Id);
            call.SetVarchar("@QB_CODE", map.QuickBooksCode);
            call.SetVarchar("@QB_LIST_ID", map.QuickBooksListId);
            call.SetVarchar("@QB_PARENT_CODE", map.QuickBooksParentCode);
            call.SetVarchar("@QB_PARENT_LIST_ID", map.QuickBooksParentListId);
            call.SetVarchar("@QB_DESCRIPTION", map.QuickBooksDescription);
            call.SetBigInt("@UNIT_ID", map.Unit.Id);
            call.SetDecimal("@PRICE", map.Price);
            call.SetDateTime("@UPDATE_DATE", DateTime.Now);
            call.SetVarchar("@UPDATE_USER", context.UserName);
            call.SetVarchar("@REPORT_LABEL", map.Label);

            db.ExecuteNonQuery(call);
        }
        QuickBooksProductMapDef GetMap(IItemNonInventoryRet item)
        {
            bool status = ReadBool(item.IsActive);
            QuickBooksProductMapDef result = new QuickBooksProductMapDef()
            {
                QuickBooksCode         = ReadString(item.Name),
                QuickBooksDescription  = ReadString(item.ORSalesPurchase.SalesOrPurchase.Desc),
                QuickBooksListId       = ReadQbId(item.ListID),
                QuickBooksParentCode   = item.ParentRef == null ? string.Empty : ReadString(item.ParentRef.FullName),
                QuickBooksParentListId = item.ParentRef == null ? string.Empty : ReadQbId(item.ParentRef.ListID),
                //Price = ReadPrice(item.ORSalesPurchase.SalesOrPurchase.ORPrice.Price),
                CreateDate   = DateTime.Now,
                UpdateDate   = DateTime.Now,
                CreatedUser  = context.UserName,
                UpdatedUser  = context.UserName,
                RecordStatus = status ? "A" : "P",
                Unit         = um.GetUnknownItem()
            };

            return(result);
        }
        List <QuickBooksProductMapDef> GetMapList(List <IItemNonInventoryRet> mapSourceList, List <MaestroProduct> plist)
        {
            List <QuickBooksProductMapDef> mapList = new List <QuickBooksProductMapDef>();

            mapSourceList.ForEach(ms =>
            {
                bool status = ReadBool(ms.IsActive);
                QuickBooksProductMapDef map = GetMap(ms);
                MaestroProduct product      = null;
                if (string.IsNullOrWhiteSpace(map.QuickBooksParentListId))
                {
                    product = ProductCache.Instance.GetByQbId(map.QuickBooksListId);
                }
                else
                {
                    product = ProductCache.Instance.GetByQbId(map.QuickBooksParentListId);
                }
                if (product == null)
                {
                    product = pm.GetUnknownItem();
                }
                map.Product      = product;
                map.Price        = product.Price;
                map.RecordStatus = status ? "A" : "P";
                QuickBooksProductMapDef existing = QuickBooksProductMapCache.Instance.GetByQbId(map.QuickBooksListId);
                if (existing != null)
                {
                    map.Id    = existing.Id;
                    map.Unit  = existing.Unit;
                    map.Label = existing.Label;
                    qmanager.Update(map);
                }
                else
                {
                    mapList.Add(map);
                }
            });

            return(mapList);
        }