public MaestroProduct GetUnknownItem() { MaestroProduct unknowProduct = ProductCache.Instance.GetByName(MaestroApplication.Instance.UNKNOWN_ITEM_NAME); if (unknowProduct == null) { unknowProduct = new MaestroProduct() { ProductGroup = new ProductGroupManager(context).GetUnknownItem(), Name = MaestroApplication.Instance.UNKNOWN_ITEM_NAME, MinimumOrderQuantity = 0, QuickBooksProductId = string.Empty, Price = 0M, CostBase = 0M, UnitType = new UnitTypeManager(context).GetUnknownItem(), Description = string.Empty, CreateDate = DateTime.Now, UpdateDate = DateTime.Now, CreatedUser = "******", UpdatedUser = "******", RecordStatus = "A" }; InsertNewItem(unknowProduct); ProductCache.Instance.Reload(true); } return(unknowProduct); }
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); }
protected override void Update() { MaestroProduct product = (MaestroProduct)request.TransactionEntityList[0]; pm.Update(product); Context.TransactionObject = product; }
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; }
protected override void New() { MaestroProduct product = (MaestroProduct)request.TransactionEntityList[0]; product.CreatedUser = Context.UserName; product.CreateDate = DateTime.Now; pm.InsertNewItem(product); response.TransactionResult = product; //Context.TransactionObject = product; }
public void InsertNewItem(MaestroProduct product) { SpCall call = new SpCall("DAT.PRODUCT_INSERT"); call.SetVarchar("@PRODUCT_NAME", product.Name); call.SetVarchar("@PRODUCT_DESCRIPTION", product.Description); call.SetVarchar("@QB_PRODUCT_ID", product.QuickBooksProductId); call.SetDecimal("@PRICE", product.Price); call.SetInt("@MINIMUM_ORDER_QUANTITY", product.MinimumOrderQuantity); call.SetBigInt("@UNIT_TYPE_ID", product.UnitType.Id); call.SetBigInt("@PRODUCT_GROUP_ID", product.GroupId); call.SetDecimal("@COST_BASE", product.CostBase); call.SetDateTime("@CREATE_DATE", product.CreateDate); call.SetVarchar("@CREATE_USER", product.CreatedUser); product.Id = db.ExecuteScalar <long>(call); }
public static ResponseMessage Add(int minimumOrder, decimal price, long unitTypeId, string name, long groupId) { MaestroProduct item = new MaestroProduct() { Name = name, Description = "A description", MinimumOrderQuantity = minimumOrder, Price = price, QuickBooksProductId = string.Empty, //GroupId = groupId, UnitType = new MaestroUnitType() { Id = unitTypeId } }; RequestMessage request = MessagePrepareAgent.GetRequest(action, tranCode, "", new List <ITransactionEntity>(new ITransactionEntity[] { item })); return(new MessageBroker().Execute(request)); }
void ExecuteBulkInsert(List <MaestroProduct> plist) { UnitTypeManager um = new UnitTypeManager(context); MaestroUnitType unknownUnitType = um.GetUnknownItem(); List <MaestroProduct> updatedProducts = new List <MaestroProduct>(); foreach (MaestroProduct product in plist) { MaestroProduct existing = ProductCache.Instance.GetByQbId(product.QuickBooksProductId); if (existing != null) { product.Id = existing.Id; product.UnitType = existing.UnitType; product.ProductGroup = existing.ProductGroup; pm.Update(product); updatedProducts.Add(existing); } else { product.UnitType = unknownUnitType; } } List <ITransactionEntity> clist = plist.Where(q => !updatedProducts.Select(u => u.QuickBooksProductId).Contains(q.QuickBooksProductId)).Cast <ITransactionEntity>().ToList(); if (clist.Count > 0) { pm.BulkInsert(clist); } if (updatedProducts.Count > 0) { updatedProducts.ForEach(p => pm.Update(p)); } if (clist.Count > 0 || updatedProducts.Count > 0) { ProductCache.Instance.Reload(true); } }
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); }
public void Update(MaestroProduct product) { SpCall call = new SpCall("DAT.PRODUCT_UPDATE"); call.SetBigInt("@ID", product.Id); call.SetVarchar("@PRODUCT_NAME", product.Name); call.SetVarchar("@PRODUCT_DESCRIPTION", product.Description); call.SetVarchar("@QB_PRODUCT_ID", product.QuickBooksProductId); call.SetDecimal("@PRICE", product.Price); call.SetInt("@MINIMUM_ORDER_QUANTITY", product.MinimumOrderQuantity); call.SetBigInt("@UNIT_TYPE_ID", product.UnitType.Id); call.SetBigInt("@PRODUCT_GROUP_ID", product.GroupId); call.SetDecimal("@COST_BASE", product.CostBase); call.SetDateTime("@UPDATE_DATE", DateTime.Now); call.SetVarchar("@UPDATE_USER", context.UserName); db.ExecuteNonQuery(call); }
MaestroProduct GetMaestroProduct(IItemNonInventoryRet item) { bool status = ReadBool(item.IsActive); string qbID = ReadQbId(item.ListID); MaestroProduct existingProduct = ProductCache.Instance.GetByQbId(qbID); MaestroProduct result = new MaestroProduct() { Name = ReadString(item.ORSalesPurchase.SalesOrPurchase.Desc), Description = ReadString(item.Name), ProductGroup = pgm.GetUnknownItem(), MinimumOrderQuantity = 0, Price = ReadPrice(item.ORSalesPurchase.SalesOrPurchase.ORPrice.Price), QuickBooksProductId = ReadQbId(item.ListID), CreateDate = DateTime.Now, UpdateDate = DateTime.Now, UpdatedUser = context.UserName, CreatedUser = context.UserName, RecordStatus = status ? "A" : "P" }; return(result); }
public override List <ITransactionEntity> Import() { StartSession(); IMsgSetRequest request = GetLatestMsgSetRequest(); IItemNonInventoryQuery query = request.AppendItemNonInventoryQueryRq(); query.ORListQueryWithOwnerIDAndClass.ListWithClassFilter.ActiveStatus.SetValue(ENActiveStatus.asAll); //IItemQuery query = request.AppendItemQueryRq(); IResponse res = GetResponse(request); //IORItemRetList returnList = res.Detail as IORItemRetList; IItemNonInventoryRetList returnList = res.Detail as IItemNonInventoryRetList; List <MaestroProduct> plist = new List <MaestroProduct>(); List <IItemNonInventoryRet> mapSourceList = new List <IItemNonInventoryRet>(); MaestroUnitType unknowUnitType = new UnitTypeManager(context).GetUnknownItem(); int cnt = returnList.Count; for (int i = 0; i <= cnt - 1; i++) { IItemNonInventoryRet inv = returnList.GetAt(i); if (inv != null) { string parentId = string.Empty; if (inv.ParentRef != null) { parentId = ReadQbId(inv.ParentRef.ListID); } if (string.IsNullOrEmpty(parentId)) { MaestroProduct product = GetMaestroProduct(inv); plist.Add(product); } mapSourceList.Add(inv);//for late processing /* * if (ReadBool(inv.IsActive)) * { * string parentId = string.Empty; * if (inv.ParentRef != null) * parentId = ReadQbId(inv.ParentRef.ListID); * * if (string.IsNullOrEmpty(parentId)) * { * MaestroProduct product = GetMaestroProduct(inv); * plist.Add(product); * } * * mapSourceList.Add(inv);//for late processing * } */ /* * else * { * string parentId = string.Empty; * if (inv.ParentRef != null) * parentId = ReadQbId(inv.ParentRef.ListID); * * if (string.IsNullOrEmpty(parentId)) * { * MaestroProduct product = GetMaestroProduct(inv); * //plist.Add(product); * * } * * * * * }*/ } #region commented //WalkItemNonInventoryRet(inv); //IORItemRet qbc = returnList.GetAt(i); /* * if (qbc.ItemNonInventoryRet != null) * { * WalkItemNonInventoryRet(qbc.ItemNonInventoryRet); * //GetMaestroProduct(qbc.ItemNonInventoryRet); * }*/ #endregion commented } ExecuteBulkInsert(plist); ImportMaps(mapSourceList, plist); QuickBooksProductMapCache.Instance.Reload(true); return(plist.Cast <ITransactionEntity>().ToList()); }