예제 #1
0
        private void AddRetailRdRecords(Guid consumeListId, Guid rdId, int rdFlag, Guid invId,
                                        Guid mainUnit, Guid sTUnit, decimal exchRate, string batch, decimal num,
                                        decimal price, DXInfo.Models.CurrentStock oldCurStock)
        {
            DXInfo.Models.RdRecords rdRecords;
            if (string.IsNullOrEmpty(batch))
            {
                rdRecords = uow.RdRecords.GetAll().Where(w => w.RdId == rdId &&
                                                         w.InvId == invId &&
                                                         w.Price == price).FirstOrDefault();
            }
            else
            {
                rdRecords = uow.RdRecords.GetAll().Where(w => w.RdId == rdId &&
                                                         w.InvId == invId &&
                                                         w.Batch == batch).FirstOrDefault();
            }
            bool isExist = true;

            if (rdRecords != null)
            {
                rdRecords.Num = rdRecords.Num + num;
            }
            else
            {
                isExist         = false;
                rdRecords       = new DXInfo.Models.RdRecords();
                rdRecords.RdId  = rdId;
                rdRecords.InvId = invId;
                rdRecords.Num   = num;
                rdRecords.Price = price;
                rdRecords.Batch = batch;
            }
            rdRecords.MainUnit = mainUnit;
            rdRecords.STUnit   = sTUnit;
            rdRecords.ExchRate = exchRate;
            rdRecords.Amount   = rdRecords.Num * price;

            if (isShelfLife)
            {
                if (oldCurStock != null)
                {
                    rdRecords.MadeDate      = oldCurStock.MadeDate;
                    rdRecords.ShelfLife     = oldCurStock.ShelfLife;
                    rdRecords.ShelfLifeType = oldCurStock.ShelfLifeType;
                    rdRecords.InvalidDate   = oldCurStock.InvalidDate;
                }
            }

            if (!isExist)
            {
                uow.RdRecords.Add(rdRecords);
            }
            else
            {
                uow.RdRecords.Update(rdRecords);
            }
            uow.Commit();
            AddConsumeListRds(consumeListId, rdRecords.Id);
        }
예제 #2
0
 private DXInfo.Models.CurrentStock GetCurInStock(Guid rdsId)
 {
     DXInfo.Models.CurrentStock oldCurStock = null;
     DXInfo.Models.RdRecords    rds         = uow.RdRecords.GetById(g => g.Id == rdsId);
     if (rds != null)
     {
         DXInfo.Models.RdRecord rd = uow.RdRecord.GetById(g => g.Id == rds.RdId);
         if (rd != null)
         {
             if (string.IsNullOrEmpty(rds.Batch))
             {
                 oldCurStock = (from d in uow.CurrentStock.GetAll()
                                where d.WhId == rd.WhId && d.InvId == rds.InvId && d.Batch == null
                                orderby d.Num
                                select d).FirstOrDefault();
             }
             else
             {
                 oldCurStock = (from d in uow.CurrentStock.GetAll()
                                where d.WhId == rd.WhId && d.InvId == rds.InvId && d.Batch == rds.Batch
                                orderby d.Num
                                select d).FirstOrDefault();
             }
             if (oldCurStock == null)
             {
                 oldCurStock               = new DXInfo.Models.CurrentStock();
                 oldCurStock.WhId          = rd.WhId;
                 oldCurStock.InvId         = rds.InvId;
                 oldCurStock.MainUnit      = rds.MainUnit;
                 oldCurStock.STUnit        = rds.STUnit;
                 oldCurStock.ExchRate      = rds.ExchRate;
                 oldCurStock.Quantity      = rds.Quantity;
                 oldCurStock.Num           = rds.Num;
                 oldCurStock.Batch         = rds.Batch;
                 oldCurStock.Price         = rds.Price;
                 oldCurStock.Amount        = oldCurStock.Num * oldCurStock.Price;
                 oldCurStock.InvalidDate   = rds.InvalidDate;
                 oldCurStock.MadeDate      = rds.MadeDate;
                 oldCurStock.ShelfLife     = rds.ShelfLife;
                 oldCurStock.ShelfLifeType = rds.ShelfLifeType;
                 uow.CurrentStock.Add(oldCurStock);
                 uow.Commit();
             }
         }
     }
     return(oldCurStock);
 }
예제 #3
0
 private void SetUnitAndQuantity(DXInfo.Models.RdRecords rdRecords, DXInfo.Models.ClientRetailOutStockDetail detail)
 {
     DXInfo.Models.Inventory            inv   = uow.Inventory.GetById(g => g.Id == detail.InvId);
     DXInfo.Models.MeasurementUnitGroup group = uow.MeasurementUnitGroup.GetById(g => g.Id == inv.MeasurementUnitGroup);
     if (group.Category == (int)DXInfo.Models.UnitGroupCategory.No)
     {
         rdRecords.MainUnit = inv.MainUnit;
         rdRecords.STUnit   = inv.MainUnit;
         rdRecords.ExchRate = 1;
         rdRecords.Quantity = rdRecords.Num;
     }
     else
     {
         if (!inv.StockUnit.HasValue)
         {
             throw new DXInfo.Models.BusinessException("请设置库存单位");
         }
         DXInfo.Models.UnitOfMeasures uom = uow.UnitOfMeasures.GetById(g => g.Id == inv.StockUnit);
         rdRecords.MainUnit = inv.MainUnit;
         rdRecords.STUnit   = inv.StockUnit.Value;
         rdRecords.ExchRate = uom.Rate;
         rdRecords.Quantity = rdRecords.Num * uom.Rate;
     }
 }
예제 #4
0
        public void AddRetailOutStock(DXInfo.Models.ClientRetailOutStock retail, string stockVouchLocalCode)
        {
            using (TransactionScope transaction = new TransactionScope())
            {
                DateTime dtNow    = DateTime.Now;
                var      rdRecord = uow.RdRecord.GetAll().Where(w =>
                                                                w.WhId == retail.WhId &&
                                                                w.DeptId == retail.DeptId &&
                                                                w.Maker == retail.UserId &&
                                                                w.RdDate == dtNow.Date &&
                                                                w.STCode == "002" &&
                                                                w.VouchType == DXInfo.Models.VouchTypeCode.SaleOutStock &&
                                                                !w.IsVerify).FirstOrDefault();
                if (rdRecord == null)
                {
                    rdRecord           = new DXInfo.Models.RdRecord();
                    rdRecord.Code      = common.GetVouchCode(DXInfo.Models.VouchTypeCode.SaleOutStock, stockVouchLocalCode);
                    rdRecord.VouchType = DXInfo.Models.VouchTypeCode.SaleOutStock;
                    rdRecord.Maker     = retail.UserId;
                    rdRecord.MakeDate  = dtNow;
                    rdRecord.MakeTime  = dtNow;
                    rdRecord.RdFlag    = 1;
                    rdRecord.RdCode    = DXInfo.Models.VouchTypeCode.SaleOutStock;
                    rdRecord.DeptId    = retail.DeptId;
                    rdRecord.STCode    = "002";
                    rdRecord.RdDate    = dtNow;
                    rdRecord.Salesman  = retail.UserId;
                    rdRecord.WhId      = retail.WhId;
                    rdRecord.BusType   = DXInfo.Models.VouchTypeCode.SaleOutStock;
                    uow.RdRecord.Add(rdRecord);
                    uow.Commit();
                }
                foreach (DXInfo.Models.ClientRetailOutStockDetail detail in retail.Detail)
                {
                    DXInfo.Models.RdRecords rdRecords;
                    if (string.IsNullOrEmpty(detail.Batch))
                    {
                        rdRecords = uow.RdRecords.GetAll()
                                    .Where(w => w.InvId == detail.InvId &&
                                           w.RdId == rdRecord.Id &&
                                           w.Batch == null && w.Price == detail.Price).FirstOrDefault();
                    }
                    else
                    {
                        rdRecords = uow.RdRecords.GetAll()
                                    .Where(w => w.InvId == detail.InvId &&
                                           w.RdId == rdRecord.Id &&
                                           w.Batch == detail.Batch && w.Price == detail.Price).FirstOrDefault();
                    }
                    if (rdRecords == null)
                    {
                        rdRecords        = new DXInfo.Models.RdRecords();
                        rdRecords.RdId   = rdRecord.Id;
                        rdRecords.InvId  = detail.InvId;
                        rdRecords.Num    = detail.Num;
                        rdRecords.Price  = detail.Price;
                        rdRecords.Batch  = detail.Batch;
                        rdRecords.Amount = detail.Num * detail.Price;
                        this.SetUnitAndQuantity(rdRecords, detail);
                        if (isShelfLife)
                        {
                            DXInfo.Models.CurrentStock currentStock;

                            var q = uow.CurrentStock.GetAll().Where(w =>
                                                                    w.WhId == retail.WhId &&
                                                                    w.InvId == detail.InvId);

                            if (string.IsNullOrEmpty(rdRecords.Batch))
                            {
                                currentStock = q.Where(w => w.Batch == null).FirstOrDefault();
                            }
                            else
                            {
                                currentStock = q.Where(w => w.Batch == detail.Batch).FirstOrDefault();
                            }
                            rdRecords.MadeDate      = currentStock.MadeDate;
                            rdRecords.ShelfLife     = currentStock.ShelfLife;
                            rdRecords.ShelfLifeType = currentStock.ShelfLifeType;
                            rdRecords.InvalidDate   = currentStock.InvalidDate;
                        }
                        uow.RdRecords.Add(rdRecords);
                    }
                    else
                    {
                        rdRecords.Num    = rdRecords.Num + detail.Num;
                        rdRecords.Amount = rdRecords.Num * rdRecords.Price;
                        this.SetUnitAndQuantity(rdRecords, detail);
                        uow.RdRecords.Update(rdRecords);
                    }
                    uow.Commit();
                }
                uow.Commit();
                transaction.Complete();
            }
        }