private void ExportBatch(UGRS.Core.Auctions.Entities.Auctions.Batch pObjBatch) { try { if (SapBatchService.Add(GetSAPBatch(pObjBatch)) != 0) { LogUtility.Write(string.Format("[ERROR] {0}", DIApplication.Company.GetLastErrorDescription())); } } catch (Exception lObjException) { LogUtility.Write(string.Format("[ERROR] {0}", lObjException.ToString())); } }
private UGRS.Core.SDK.DI.Auctions.Tables.Batch GetSAPBatch(UGRS.Core.Auctions.Entities.Auctions.Batch pObjBatch) { bool lBoolPerPrice = pObjBatch.ItemType.SellType == Core.Auctions.Enums.Inventory.SellTypeEnum.PerPrice ? true : false; int lIntReturned = pObjBatch.GoodsReturns.Where(x => !x.Removed).Select(x => (int?)x.Quantity).Sum() ?? 0; int lIntQuantity = pObjBatch.Quantity - lIntReturned; float lFltWeight = lIntReturned != 0 ? lIntQuantity * pObjBatch.AverageWeight : pObjBatch.Weight; float lFlAverageW = lIntReturned != 0 ? lFltWeight / lIntQuantity : pObjBatch.AverageWeight; //decimal lDmlPrice = (lBolPerPrice ? (pObjBatch.Price / pObjBatch.Quantity * lIntQuantity) : pObjBatch.Price); //decimal lDmlAmount = (lBolPerPrice ? lDmlPrice : pObjBatch.Price * (decimal)lFltWeight); decimal lDmlPrice = pObjBatch.Price; decimal lDmlAmount = lIntReturned != 0 ? lDmlPrice * (Convert.ToDecimal(pObjBatch.Weight - pObjBatch.GoodsReturns.Where(x => !x.Removed) .Select(x => (float)x.Weight).Sum())) : lIntReturned != 0 && lBoolPerPrice ? pObjBatch.Price * lIntQuantity : pObjBatch.Amount; return(new UGRS.Core.SDK.DI.Auctions.Tables.Batch() { Id = GetBatchId(pObjBatch.Auction.Folio, pObjBatch.Number), AuctionId = GetSapAuctionId(pObjBatch.Auction.Folio), Number = pObjBatch.Number, SellerId = pObjBatch.SellerId ?? 0, SellerCode = pObjBatch.Seller != null ? pObjBatch.Seller.Code : string.Empty, Seller = pObjBatch.Seller != null ? pObjBatch.Seller.Name : string.Empty, BuyerId = pObjBatch.BuyerId ?? 0, BuyerCode = pObjBatch.Buyer != null ? pObjBatch.Buyer.Code : string.Empty, Buyer = pObjBatch.Buyer != null ? pObjBatch.Buyer.Name : string.Empty, ItemTypeId = pObjBatch.ItemTypeId ?? 0, ItemType = pObjBatch.ItemType != null ? pObjBatch.ItemType.Name : string.Empty, AverageWeight = pObjBatch.AverageWeight, //Recalculate fields Quantity = lIntQuantity, Weight = lFltWeight, Amount = lDmlAmount, Price = lDmlPrice, Returned = lIntReturned, Reprogrammed = pObjBatch.Reprogrammed, Unsold = pObjBatch.Unsold, Gender = pObjBatch.Gender, UnsoldMotive = (int)pObjBatch.UnsoldMotive > 0 ? pObjBatch.UnsoldMotive.GetDescription() : string.Empty, Protected = pObjBatch.Protected, Removed = pObjBatch.Removed, Active = pObjBatch.Active, CreationDate = pObjBatch.CreationDate, CreationTime = pObjBatch.CreationDate, ModificationDate = pObjBatch.ModificationDate, ModificationTime = pObjBatch.ModificationDate }); }