Пример #1
0
        private long AddNewBox(IUnitOfWork db,
                               DateTime when,
                               long?by)
        {
            var openBox = new OpenBox
            {
                StyleId     = StyleId,
                BoxBarcode  = BoxBarcode,
                BoxQuantity = BoxQuantity,
                Price       = Price,
                Printed     = Printed,
                PolyBags    = PolyBags,
                Owned       = Owned,
                Archived    = Archived,
                CreateDate  = DateHelper.ConvertAppToUtc(CreateDate) ?? when,
                CreatedBy   = by,

                UpdateDate = DateHelper.ConvertAppToUtc(CreateDate) ?? when,
                UpdatedBy  = by,

                OriginCreateDate = when,
                OriginType       = (int)BoxOriginTypes.ByUser
            };

            db.OpenBoxes.Add(openBox);
            db.Commit();

            return(openBox.Id);
        }
        public void OnAuthorization(AuthorizationFilterContext context)
        {
            _openBox = (OpenBox)context.HttpContext.RequestServices.GetService(typeof(OpenBox));

            if (_openBox.GetSaleBox() == null)
            {
                context.Result = new RedirectToActionResult("Box", "Sales", new { Area = "Employee" }, "#ClosedBox");
            }
        }
Пример #3
0
 public SalesController(ISalesOrderRepository salesOrderRepository, ISaleBoxRepository saleBoxRepository,
                        InventoryManagement inventoryManagement, IClientRepository clientRepository,
                        OpenBox openBox, EmployeeLogin employeeLogin, RagnarokContext context)
 {
     _salesOrderRepository = salesOrderRepository;
     _saleBoxRepository    = saleBoxRepository;
     _clientRepository     = clientRepository;
     _inventoryManagement  = inventoryManagement;
     _openBox       = openBox;
     _employeeLogin = employeeLogin;
     _context       = context;
 }
Пример #4
0
        public static void GENERAL_OPENBOX(SkillBaseEventArgs bargument)
        {
            if (bargument.Context == Saga.Enumarations.SkillContext.SkillUse)
            {
                SkillUsageEventArgs arguments = (SkillUsageEventArgs)bargument;

                if (arguments.Target is OpenBox)
                {
                    OpenBox current = arguments.Target as OpenBox;
                    arguments.Result = Saga.SkillBaseEventArgs.ResultType.NoDamage;
                    arguments.Damage = 0;
                    arguments.Failed = false;
                    current.OnOpenBox(arguments.Sender as Character);
                }
            }
        }
Пример #5
0
        private void UpdateExistingBox(IUnitOfWork db,
                                       OpenBox dbBox,
                                       DateTime when,
                                       long?by)
        {
            dbBox.StyleId     = StyleId;
            dbBox.BoxBarcode  = BoxBarcode;
            dbBox.Printed     = Printed;
            dbBox.PolyBags    = PolyBags;
            dbBox.BoxQuantity = BoxQuantity;
            dbBox.Price       = Price;
            dbBox.Owned       = Owned;
            dbBox.Archived    = Archived;
            dbBox.CreateDate  = DateHelper.ConvertAppToUtc(CreateDate) ?? when;
            dbBox.UpdateDate  = when;
            dbBox.UpdatedBy   = by;

            db.Commit();
        }
    private void GetAGun(NetworkMessage msg)
    {
        OpenBox bx = GameObject.Find(msg.ReadMessage <StringMessage>().value).GetComponent <OpenBox>();

        bx.GetGun();
    }
        public void Process()
        {
            using (var db = _dbFactory.GetRWDb())
            {
                IQueryable <Style> styleQuery = from st in db.Styles.GetAll()
                                                where !st.Deleted
                                                orderby st.Id descending
                                                select st;
                var styleList = styleQuery.ToList();

                //var toDate = new DateTime(2016, 9, 23);
                var openBoxList = (from b in db.OpenBoxCountings.GetAll()
                                   join bi in db.OpenBoxCountingItems.GetAll() on b.Id equals bi.BoxId
                                   //where bi.CreateDate <= toDate
                                   select new StyleBoxItemInfo
                {
                    StyleId = b.StyleId,
                    BoxQuantity = b.BoxQuantity,
                    StyleItemId = bi.StyleItemId,
                    Quantity = bi.Quantity,
                    CountingDate = b.CountingDate,
                    BatchTimeStatus = b.BatchTimeStatus,
                    IsProcessed = b.IsProcessed,
                }).ToList();

                var sealedBoxList = (from b in db.SealedBoxCountings.GetAll()
                                     join bi in db.SealedBoxCountingItems.GetAll() on b.Id equals bi.BoxId
                                     //where bi.CreateDate <= toDate
                                     select new StyleBoxItemInfo
                {
                    StyleId = b.StyleId,
                    BoxQuantity = b.BoxQuantity,
                    StyleItemId = bi.StyleItemId,
                    Quantity = bi.BreakDown,
                    CountingDate = b.CountingDate,
                    BatchTimeStatus = b.BatchTimeStatus,
                    IsProcessed = b.IsProcessed,
                }).ToList();

                var checkingFromDate = new DateTime(2017, 8, 1);
                var batchList        = db.OrderBatches.GetBatchesToDisplay(true)
                                       .OrderBy(b => b.CreateDate)
                                       .Where(b => b.CreateDate > checkingFromDate)
                                       .ToList();

                foreach (var style in styleList)
                {
                    var styleOpenBoxes   = openBoxList.Where(b => b.StyleId == style.Id && !b.IsProcessed).ToList();
                    var styleSealedBoxes = sealedBoxList.Where(b => b.StyleId == style.Id && !b.IsProcessed).ToList();

                    if (!styleSealedBoxes.Any() &&
                        !styleOpenBoxes.Any())
                    {
                        continue;
                    }

                    _log.Info("Processing style, StyleId=" + style.StyleID);

                    var styleBoxes = new List <StyleBoxItemInfo>();
                    styleBoxes.AddRange(styleOpenBoxes);
                    styleBoxes.AddRange(styleSealedBoxes);

                    var hasProcessed = openBoxList.Any(b => b.StyleId == style.Id && b.IsProcessed) ||
                                       sealedBoxList.Any(b => b.StyleId == style.Id && b.IsProcessed);

                    _log.Info("hasProcessed=" + hasProcessed);

                    //STEP 1. Get min box date + batch mode
                    var firstBox = styleBoxes.OrderBy(sb => sb.CountingDate).FirstOrDefault();
                    var boxDate  = firstBox.CountingDate;
                    _log.Info("Box date=" + boxDate);
                    var batchTimeStatus  = firstBox.BatchTimeStatus;
                    var nextBoxDay       = boxDate.Date.AddDays(1);
                    var boxDay           = boxDate.Date;
                    var boxPrevious2Week = boxDay.AddDays(-14);

                    var styleItems      = db.StyleItems.GetAll().Where(s => s.StyleId == style.Id).ToList();
                    var styleItemCaches = db.StyleItemCaches.GetForStyleId(style.Id);

                    if (styleItems.Any(si => si.LiteCountingStatus != CountingStatusesEx.Counted))
                    {
                        _log.Info("Skipped not all styleItems marked as Counted, styleId=" + style.StyleID);
                        continue;
                    }

                    #region STEP 2. Calculate pending orders when first boxes came
                    if (!hasProcessed)
                    {
                        //STEP 2.1 Get batch list
                        //Exclude batch with data > box date
                        //Exclude batch depend of "batch mode"
                        //NOTE: the "Main" batch can be created at 11 PM at previous day
                        var batchFromDate = boxDate.Date.AddHours(-3);
                        var batchToDate   = boxDate.Date.AddHours(21);


                        var excludeBatchList = batchList.Where(b => b.CreateDate < batchFromDate).ToList();

                        //NOTE: always BEFORE FIRST BATCH
                        var dayBatches = batchList.Where(b => b.CreateDate >= batchFromDate && b.CreateDate < batchToDate && b.OrdersCount > 0).ToList();
                        if (dayBatches.Count > 0)
                        {
                            if (batchTimeStatus == (int)BatchTimeStatus.BeforeFirst)
                            {
                                //Nothing
                            }
                            if (batchTimeStatus == (int)BatchTimeStatus.AfterFirstBeforeSecond ||
                                batchTimeStatus == (int)BatchTimeStatus.AfterSecond)
                            {
                                excludeBatchList.Add(dayBatches[0]);
                            }
                            if (batchTimeStatus == (int)BatchTimeStatus.AfterSecond)
                            {
                                if (dayBatches.Count > 1)
                                {
                                    excludeBatchList.Add(dayBatches[1]);
                                }
                            }
                        }

                        //STEP 2.2. Get all orders with (box date - 1 week) <= order date <= box date
                        //Get orders outside of exclude batches
                        var excludeBatchIdList = excludeBatchList.Select(b => b.Id).ToList();
                        //NOTE: as result we get the list of orders came till end of day, that In-Pending
                        var pendingOrders =
                            db.Orders.GetAll()
                            .Where(
                                o =>
                                (o.OrderStatus == OrderStatusEnumEx.Shipped ||
                                 o.OrderStatus == OrderStatusEnumEx.Pending) &&
                                (!o.BatchId.HasValue || !excludeBatchIdList.Contains(o.BatchId.Value)) &&
                                o.OrderDate > boxPrevious2Week && o.OrderDate < boxDay).ToList();

                        //Find styleId, styleItemId in these order items

                        _log.Info("Pending orders=" + pendingOrders.Count);
                        var pendingOrderIds = pendingOrders.Select(p => p.Id).ToArray();
                        var orderItems      = db.OrderItems.GetWithListingInfo().Where(i => i.OrderId.HasValue && pendingOrderIds.Contains(i.OrderId.Value)).ToList();
                        //    db.ItemOrderMappings.GetFilteredOrdersWithItems(new OrderSearchFilter()
                        //    {
                        //        EqualOrderIds = pendingOrders.Select(p => p.Id).ToArray()
                        //    }).ToList();
                        //var orderItems =
                        //    pendingOrdersWithItems.Select(o => o.Items).ToList().SelectMany(i => i).ToList();

                        //If > 0, Compose InPendingWhenInventory record
                        if (orderItems.Any(i => i.StyleEntityId == style.Id))
                        {
                            foreach (var si in styleItems)
                            {
                                var sizeQuantity =
                                    orderItems.Where(i => i.StyleItemId == si.Id).Sum(i => i.Quantity);
                                if (sizeQuantity > 0)
                                {
                                    _log.Info(String.Format("Has pending orders items, size={0}({1}), qty={2}", si.Size, si.Id, sizeQuantity));
                                    var operation = new QuantityOperation()
                                    {
                                        Comment    = "Pending orders",
                                        Type       = (int)QuantityOperationType.InPendingWhenInventory,
                                        CreateDate = _time.GetAppNowTime(),
                                    };
                                    db.QuantityOperations.Add(operation);
                                    db.Commit();

                                    db.QuantityChanges.Add(new QuantityChange()
                                    {
                                        QuantityOperationId = operation.Id,
                                        StyleItemId         = si.Id,
                                        StyleId             = si.StyleId,
                                        CreateDate          = _time.GetAppNowTime(),
                                        Quantity            = sizeQuantity,
                                    });
                                    db.Commit();
                                }
                            }
                        }

                        #region STEP 2.3. Checking Kiosk records (Disabled)
                        //NOTE: we use BoxDay as box date, it will be automatically substracted!

                        //var kioskFromDate = boxDate.Date;
                        //var kioskToDate = boxDate.Date.AddDays(1);
                        //var kioskItems = db.Scanned.GetScanItemAsDto()
                        //    .Where(s => s.StyleId == style.Id
                        //        && s.CreateDate > kioskFromDate
                        //        && s.CreateDate < kioskToDate)
                        //    .ToList();

                        ////If > 0, Compose InPendingWhenInventory record
                        //if (kioskItems.Any())
                        //{
                        //    foreach (var si in styleItems)
                        //    {
                        //        var sizeQuantity = kioskItems.Where(i => i.StyleItemId == si.Id).Sum(i => i.Quantity);
                        //        if (sizeQuantity > 0)
                        //        {
                        //            _log.Info("Has pending kiosk items, qty=" + sizeQuantity);
                        //            var operation = new QuantityOperation()
                        //            {
                        //                Comment = "Pending kiosk items",
                        //                Type = (int)QuantityOperationType.InPendingWhenInventory,
                        //                CreateDate = _time.GetAppNowTime(),
                        //            };
                        //            db.QuantityOperations.Add(operation);
                        //            db.Commit();

                        //            db.QuantityChanges.Add(new QuantityChange()
                        //            {
                        //                QuantityOperationId = operation.Id,
                        //                StyleItemId = si.Id,
                        //                StyleId = si.StyleId,
                        //                CreateDate = _time.GetAppNowTime(),
                        //                Quantity = sizeQuantity,
                        //            });
                        //            db.Commit();
                        //        }
                        //    }
                        //}
                        #endregion
                    }
                    #endregion

                    //Mark all exist boxes as archive, set box mode = true
                    var beginCounting  = new DateTime(2017, 10, 15);
                    var existOpenBoxes = db.OpenBoxes.GetByStyleId(style.Id)
                                         .Where(b => b.CreateDate < beginCounting && !b.ReInventory).ToList();
                    foreach (var openBox in existOpenBoxes)
                    {
                        _log.Info("Archive existing OpenBox, Id=" + openBox.Id);
                        openBox.Archived = true;
                    }

                    var existSealedBoxes = db.SealedBoxes.GetByStyleId(style.Id)
                                           .Where(b => b.CreateDate < beginCounting && !b.ReInventory).ToList();;
                    foreach (var sealedBox in existSealedBoxes)
                    {
                        _log.Info("Archive existing SealedBox, Id=" + sealedBox.Id);
                        sealedBox.Archived = true;
                    }
                    db.Commit();

                    foreach (var si in styleItems)
                    {
                        if (si.Quantity != null)
                        {
                            _log.Info(String.Format("Reset Manually Qty, size={0} ({1}) from={2}, at={3}", si.Size, si.Id, si.Quantity, si.QuantitySetDate));
                        }
                        si.Quantity        = null;
                        si.QuantitySetBy   = null;
                        si.QuantitySetDate = null;
                    }
                    db.Commit();

                    //STEP 3.1. Sealed Box
                    var newSealedBoxList = db.SealedBoxCountings.GetByStyleId(style.Id).Where(b => !b.IsProcessed).ToList();
                    var index            = 1;
                    foreach (var box in newSealedBoxList)
                    {
                        var newBoxItems = db.SealedBoxCountingItems.GetAll().Where(sb => sb.BoxId == box.Id).ToList();
                        var when        = _time.GetAppNowTime();
                        var sizePart    = "";
                        if (newBoxItems.Count == 1)
                        {
                            var styleItem = styleItems.FirstOrDefault(s => s.Id == newBoxItems[0].StyleItemId);
                            if (styleItem != null)
                            {
                                sizePart = "-" + styleItem.Size;
                            }
                        }

                        var newDbBox = new SealedBox()
                        {
                            StyleId     = style.Id,
                            BoxBarcode  = style.StyleID + sizePart + "-" + when.ToString("MMMMyyyy") + (index > 1 ? "-" + index : ""),
                            BoxQuantity = box.BoxQuantity,
                            CreateDate  = boxDay, //nextBoxDay
                            CreatedBy   = box.CreatedBy,
                            Owned       = true,
                            ReInventory = true,
                        };
                        db.SealedBoxes.Add(newDbBox);
                        db.Commit();

                        foreach (var boxItem in newBoxItems)
                        {
                            db.SealedBoxItems.Add(new SealedBoxItem()
                            {
                                BoxId       = newDbBox.Id,
                                StyleItemId = boxItem.StyleItemId,
                                BreakDown   = boxItem.BreakDown,

                                CreateDate = boxItem.CreateDate,
                                CreatedBy  = boxItem.CreatedBy
                            });
                        }

                        box.IsProcessed = true;
                        db.Commit();

                        _log.Info("Create SealedBox, name=" + newDbBox.BoxBarcode);

                        index++;
                    }

                    //STEP 3.2. Open Box
                    var newOpenBoxList = db.OpenBoxCountings.GetByStyleId(style.Id).Where(b => !b.IsProcessed).ToList();
                    index = 1;
                    foreach (var box in newOpenBoxList)
                    {
                        var when     = _time.GetAppNowTime();
                        var sizePart = "";

                        var newBoxItems = db.OpenBoxCountingItems.GetAll().Where(sb => sb.BoxId == box.Id).ToList();
                        if (newBoxItems.Count == 1)
                        {
                            var styleItem = styleItems.FirstOrDefault(si => si.Id == newBoxItems[0].StyleItemId);
                            if (styleItem != null)
                            {
                                sizePart = "-" + styleItem.Size;
                            }
                        }

                        var newDbBox = new OpenBox()
                        {
                            StyleId     = style.Id,
                            BoxBarcode  = style.StyleID + sizePart + "-" + when.ToString("MMMMyyyy") + (index > 1 ? "-" + index : ""),
                            BoxQuantity = box.BoxQuantity,
                            CreateDate  = boxDay, //nextBoxDay
                            CreatedBy   = box.CreatedBy,
                            Owned       = true,
                            ReInventory = true,
                        };
                        db.OpenBoxes.Add(newDbBox);
                        db.Commit();

                        foreach (var boxItem in newBoxItems)
                        {
                            db.OpenBoxItems.Add(new OpenBoxItem()
                            {
                                BoxId       = newDbBox.Id,
                                StyleItemId = boxItem.StyleItemId,
                                Quantity    = boxItem.Quantity,

                                CreateDate = boxItem.CreateDate,
                                CreatedBy  = boxItem.CreatedBy
                            });
                        }

                        box.IsProcessed = true;
                        db.Commit();

                        _log.Info("Create OpenBox, name=" + newDbBox.BoxBarcode);

                        index++;
                    }

                    _log.Info("Changes:");
                    foreach (var si in styleItems)
                    {
                        var cache  = styleItemCaches.FirstOrDefault(c => c.Id == si.Id);
                        var boxQty = styleBoxes.Where(b => b.StyleItemId == si.Id).Sum(b => b.BoxQuantity * b.Quantity);
                        _log.Info(si.Size + ": " + (cache != null ? cache.RemainingQuantity.ToString() : "[null]") + "->" + boxQty);
                    }
                }
            }
        }
Пример #8
0
        public static void GenerateOpenBox(IUnitOfWork db,
                                           ICacheService cache,
                                           IQuantityManager quantityManager,
                                           long styleId,
                                           DateTime when,
                                           long?by)
        {
            var styleItemCaches = db.StyleItemCaches.GetFiltered(si => si.StyleId == styleId).ToList();
            var openBox         = new OpenBox();

            openBox.BoxBarcode  = "Generated_" + when.ToString("yyyyMMdd");
            openBox.StyleId     = styleId;
            openBox.BoxQuantity = 1;
            openBox.CreateDate  = when;
            openBox.CreatedBy   = by;

            db.OpenBoxes.Add(openBox);
            db.Commit();

            foreach (var styleItem in styleItemCaches)
            {
                var openBoxItem = new OpenBoxItem()
                {
                    BoxId       = openBox.Id,
                    StyleItemId = styleItem.Id,
                    Quantity    = styleItem.RemainingQuantity,
                    CreateDate  = when,
                    CreatedBy   = by
                };
                db.OpenBoxItems.Add(openBoxItem);
            }
            db.Commit();

            var styleItems = db.StyleItems.GetFiltered(si => si.StyleId == styleId).ToList();

            foreach (var styleItem in styleItems)
            {
                var oldQuantity    = styleItem.Quantity;
                var styleItemCache = styleItemCaches.FirstOrDefault(sic => sic.Id == styleItem.Id);
                int?newQuantity    = styleItemCache != null ? styleItemCache.RemainingQuantity : (int?)null;

                styleItem.Quantity        = null;
                styleItem.QuantitySetDate = null;
                styleItem.QuantitySetBy   = null;
                styleItem.RestockDate     = null;

                quantityManager.LogStyleItemQuantity(db,
                                                     styleItem.Id,
                                                     newQuantity,
                                                     oldQuantity,
                                                     QuantityChangeSourceType.UseBoxQuantity,
                                                     null,
                                                     null,
                                                     null,
                                                     when,
                                                     by);

                db.Commit();
            }

            db.Styles.SetReSaveDate(styleId, when, by);

            if (AppSettings.IsDebug)
            {
                cache.UpdateStyleCacheForStyleId(db, new List <long>()
                {
                    styleId
                });
                cache.UpdateStyleItemCacheForStyleId(db, new List <long>()
                {
                    styleId
                });
            }
            else
            {
                cache.RequestStyleIdUpdates(db,
                                            new List <long>()
                {
                    styleId
                },
                                            UpdateCacheMode.IncludeChild,
                                            AccessManager.UserId);
            }
        }