Ejemplo n.º 1
0
        private static string DispatchGoods(DispatchFormEntity form, DispatchFormItemEntity formItem, Database db, DbTransaction trans)
        {
            var orderDetail = OrderFormRepository.GetItem(form.OrderDetailId);

            var goodsSerial = new GoodsSerialEntity
            {
                ProductId         = form.ProductId,
                DispatchedCount   = formItem.Count,
                HospitalId        = form.HospitalId,
                VendorId          = form.VendorId,
                NeedAudit         = orderDetail.NeedAudit,
                NeedCheck         = orderDetail.NeedCheck,
                NeedSplit         = orderDetail.NeedSplit,
                SplitCopies       = orderDetail.SplitCopies,
                SplitUnit         = orderDetail.SplitUnit,
                SplitCapacity     = orderDetail.SplitCapacity,
                SplitPackageCount = orderDetail.SplitPackageCount,
                ValidDays         = orderDetail.ValidDays,
                BatchNo           = formItem.BatchNo,
                ExpiredDate       = formItem.ExpiredDate,
                IsClosed          = false,
                CreatedId         = form.CreatedId,
                CreatedTime       = DateTime.Now,
                UpdatedId         = form.CreatedId,
                UpdatedTime       = DateTime.Now
            };

            GoodsSerialRepository.Create(goodsSerial, db, trans);

            GoodsSerialFormRepository.Create(new GoodsSerialFormEntity
            {
                SerialId    = goodsSerial.Id,
                FormId      = form.Id,
                FormKind    = FormKind.DispatchItem,
                CreatedId   = form.CreatedId,
                CreatedTime = DateTime.Now,
            }, new GoodsSerialFormEntity
            {
                SerialId    = goodsSerial.Id,
                FormId      = form.OrderDetailId,
                FormKind    = FormKind.OrderDetail,
                CreatedId   = form.CreatedId,
                CreatedTime = DateTime.Now,
            }, db, trans);

            return(goodsSerial.Id);
        }
Ejemplo n.º 2
0
        public static IList <GoodsEntity> Split(GoodsEntity goods, GoodsSerialEntity goodsSerial, string userId)
        {
            var expiredDate     = GetSplitExpiredDate(goodsSerial);
            var product         = ProductRepository.Get(goods.ProductId);
            var hospitalProduct = HospitalProductRepository.GetOneProduct(goods.ProductId, goods.HospitalId);

            var list = new List <GoodsEntity>();

            var db = DatabaseFactory.CreateDatabase();

            using (var conn = db.CreateConnection())
            {
                conn.Open();
                using (var trans = conn.BeginTransaction())
                {
                    try
                    {
                        if (UpdateSplittingUser(goods.Id, userId, db, trans))
                        {
                            var newSerial = NewGoodsSerial(goodsSerial, expiredDate, userId);
                            var barcodes  = GoodsSerialRepository.Create(newSerial, db, trans);

                            var name = !string.IsNullOrEmpty(goods.Name) ? goods.Name : hospitalProduct.Alias;
                            if (string.IsNullOrEmpty(name))
                            {
                                name = product.Name;
                            }

                            if (string.IsNullOrEmpty(hospitalProduct.SplitCapacity))
                            {
                                name += "(" + hospitalProduct.SplitCopies + "-{0})";
                            }
                            else
                            {
                                name += "(" + hospitalProduct.MiniSplitNumber + "*" + hospitalProduct.SplitCapacity + hospitalProduct.SplitUnit + "," + hospitalProduct.SplitCopies + "-{0})";
                            }

                            var index = 0;
                            foreach (var barcode in barcodes)
                            {
                                index++;

                                var newGoods = new GoodsEntity
                                {
                                    Name            = string.Format(name, index),
                                    Barcode         = barcode,
                                    SerialId        = newSerial.Id,
                                    ParentId        = goods.Id,
                                    HospitalId      = goods.HospitalId,
                                    VendorId        = goods.VendorId,
                                    ProductId       = goods.ProductId,
                                    BatchNo         = goods.BatchNo,
                                    ExpiredDate     = expiredDate,
                                    StoreroomId     = goods.StoreroomId,
                                    PackageCapacity = goodsSerial.SplitCapacity,
                                    PackageCount    = goodsSerial.SplitPackageCount,
                                    MeasuringUnit   = goodsSerial.SplitUnit,
                                    Status          = GoodsStatus.Usable,
                                    GrantedCount    = 0,
                                    SplitUserId     = userId,
                                    SplitDate       = DateTime.Now,
                                    CreatedId       = userId,
                                    CreatedTime     = DateTime.Now,
                                    UpdatedId       = userId,
                                    UpdatedTime     = DateTime.Now
                                };

                                Create(newGoods, db, trans);

                                list.Add(newGoods);
                            }

                            AdjustInventory(goods, newSerial.Id, barcodes.Count, goodsSerial.SplitPackageCount, userId, db, trans);
                        }

                        trans.Commit();
                    }
                    catch
                    {
                        trans.Rollback();
                        throw;
                    }
                }
            }

            return(list);
        }