Esempio n. 1
0
        public void CreateNewEnterStockOrder(CreateNewEnterStockOrderInput input)
        {
            StockBill bill = new StockBill();

            bill.CategoryID = input.CategoryID;
            bill.StockType  = input.StockType;

            User straff = null;

            if (input.CategoryID == 4)
            {
                straff = AsyncHelper.RunSync <User>(() => _userManager.GetUserByIdAsync(input.StraffID));
            }
            bill.Straff           = straff;
            bill.Description      = input.Description;
            bill.StockBillEntries = new  List <StockBillEntry>();
            foreach (var e in input.StockBillEntry)
            {
                var entry = new StockBillEntry();
                entry.Bill = bill;

                Accessory accessory = _accessoryRepository.Get(e.AccessoryId);
                entry.Accessory = accessory;
                entry.Count     = e.Count;
                bill.StockBillEntries.Add(entry);
                //更新备件库存
                _inventroyDomainService.UpdateOrgInventory(accessory, e.Count);
                if (input.CategoryID == 4)
                {
                    //员工退料,更新员工持有数量
                    _inventroyDomainService.UpdateStaffInventory(straff, accessory, e.Count * (-1));
                }
            }
            //保存单据
            _stockBillRepository.Insert(bill);
        }
Esempio n. 2
0
        private void AccessoryEntryProcess(CompleteInput input, WorkOrderBill bill, CompleteOutput output)
        {
            if (input.Accessories != null)
            {
                //新增
                foreach (var accessory in input.Accessories)
                {
                    var entry = bill.AccessoryEntry.FirstOrDefault(x => x.AccessoryId == accessory.AccessoryId);
                    if (entry == null)
                    {
                        entry             = new WorkOrderAccessoryEntry();
                        entry.AccessoryId = accessory.AccessoryId;
                        entry.Count       = accessory.Count;
                        entry.NewSerials  = entry.OldSerials;
                        entry.BillId      = bill.Id;
                        Accessory accessoryEntity = _accessoryRepository.Get(accessory.AccessoryId);
                        _workOrderAccessoryEntryRepository.Insert(entry);
                        int currentCount = _inventoryDomainService.GetAccessoryCountByUser(bill.AssignedPerson, accessoryEntity);
                        if (currentCount >= entry.Count)
                        {
                            //扣减库存
                            _inventoryDomainService.UpdateStaffInventory(bill.AssignedPerson, entry.Accessory, entry.Count * (-1));
                        }
                        else
                        {
                            //库存不足
                            output.Successed = false;
                            string msg = string.Format("配件【{0}】持有量不足,缺少{1}{2}\r\n", entry.Accessory.Name, entry.Count - currentCount, entry.Accessory.Unit);
                            output.Error = output.Error + msg;
                        }
                    }
                }
            }
            //删除分录
            for (int i = bill.AccessoryEntry.Count - 1; i >= 0; i--)
            {
                WorkOrderAccessoryEntry accessoryEntry = bill.AccessoryEntry.ElementAt(i);


                if (input.Accessories == null)
                {
                    //增加配件持有数量
                    _inventoryDomainService.UpdateStaffInventory(bill.AssignedPerson, accessoryEntry.Accessory, accessoryEntry.Count);
                    //删除分录
                    _workOrderAccessoryEntryRepository.Delete(accessoryEntry);


                    i--;
                }
                else
                {
                    var entryInput = input.Accessories.FirstOrDefault(x => x.AccessoryId == accessoryEntry.AccessoryId);
                    if (entryInput == null)
                    {
                        //增加配件持有数量
                        _inventoryDomainService.UpdateStaffInventory(bill.AssignedPerson, accessoryEntry.Accessory, accessoryEntry.Count);
                        //删除分录
                        _workOrderAccessoryEntryRepository.Delete(accessoryEntry);


                        i--;
                    }
                    else
                    {
                        //增加配件持有数量
                        _inventoryDomainService.UpdateStaffInventory(bill.AssignedPerson, accessoryEntry.Accessory, accessoryEntry.Count);

                        //检查库存量
                        int currentCount = _inventoryDomainService.GetAccessoryCountByUser(bill.AssignedPerson, accessoryEntry.Accessory);
                        if (currentCount >= entryInput.Count)
                        {
                            //更新分录
                            accessoryEntry.Count      = entryInput.Count;
                            accessoryEntry.NewSerials = entryInput.NewSerials;
                            accessoryEntry.OldSerials = entryInput.OldSerials;
                            //扣减
                            _inventoryDomainService.UpdateStaffInventory(bill.AssignedPerson, accessoryEntry.Accessory, accessoryEntry.Count * (-1));
                        }
                        else
                        {
                            //库存不足
                            output.Successed = false;
                            string msg = string.Format("配件【{0}】持有量不足,缺少{1} {2}\r\n", accessoryEntry.Accessory.Name, accessoryEntry.Count - currentCount, accessoryEntry.Accessory.Unit);
                            output.Error = output.Error + msg;
                        }
                        //i--;
                    }
                }
            }
        }