コード例 #1
0
 public void ValidateItems(AdjustContractPrice model)
 {
     if (model.Items.Count() == 0)
     {
         throw new Exception("明细不能为空");
     }
 }
コード例 #2
0
        public void Update(AdjustContractPrice model)
        {
            ValidateItems(model);

            if (_db.Table.Exists <AdjustContractPriceItem>(n => n.AdjustContractPriceId == model.Id))
            {
                _db.Delete <AdjustContractPriceItem>(n => n.AdjustContractPriceId == model.Id);
            }
            _db.Insert <AdjustContractPriceItem>(model.Items.ToArray());
            _db.Update(model);
        }
コード例 #3
0
        public void AdjustContractPrice(AdjustContractPrice entity)
        {
            if (entity.Items.Count() == 0)
            {
                throw new Exception("调价明细为空");
            }
            string sql        = @" select i.* from purchasecontract 
c inner join purchasecontractitem i on c.Id = i.PurchaseContractId
where c.`Status` = 3 and FIND_IN_SET(@StoreId, c.StoreIds) and c.SupplierId=@SupplierId and i.ProductId in @ProductIds order by c.Id desc";
            var    productIds = entity.Items.Select(n => n.ProductId).ToArray();
            //已存在的所有要更新合同明细
            var updateList = _db.Table.FindAll <PurchaseContractItem>(sql,
                                                                      new { StoreId = entity.StoreId, SupplierId = entity.SupplierId, ProductIds = productIds }).ToList();
            // 该供应商最后一个合同
            string sqlContract = "select * from purchasecontract c where c.`Status` = 3 and FIND_IN_SET(@StoreId, c.StoreIds) and c.SupplierId=@SupplierId order by c.Id desc  LIMIT 1 ";
            var    contract    = _db.Table.Find <PurchaseContract>(sqlContract, new { StoreId = entity.StoreId, SupplierId = entity.SupplierId });

            if (contract == null)
            {
                throw new Exception("供应商无合同,不能调价");
            }
            List <PurchaseContractItem> insertList = new List <PurchaseContractItem>();

            foreach (var item in entity.Items)
            {
                // 更新明细中不存在的,就是需要添加的
                var model = updateList.FirstOrDefault(n => n.ProductId == item.ProductId);
                if (model == null)
                {
                    model = new PurchaseContractItem()
                    {
                        PurchaseContractId = contract.Id,
                        ProductId          = item.ProductId,
                        ContractPrice      = item.AdjustPrice,
                        Status             = SupplyStatus.Supplying,
                    };
                    insertList.Add(model);
                }
                else
                {
                    model.ContractPrice = item.AdjustPrice;
                }
            }
            if (insertList.Count > 0)
            {
                _db.Insert <PurchaseContractItem>(insertList.ToArray());
            }
            if (updateList.Count > 0)
            {
                _db.Update <PurchaseContractItem>(updateList.ToArray());
            }
        }
コード例 #4
0
        public void Create(AdjustContractPriceModel model)
        {
            var entity = new AdjustContractPrice();

            entity = model.MapTo <AdjustContractPrice>();
            entity.SetItems(model.ConvertJsonToItem());
            _service.ValidateItems(entity);
            entity.CreatedBy = model.UpdatedBy;
            entity.Code      = _sequenceService.GenerateNewCode(BillIdentity.AdjustContractPrice);
            _db.Insert(entity);
            // 直接调整合同价,不存在的商品,添加,存在的商品直接修改价格
            var reason  = "创建合同调价单";
            var history = new ProcessHistory(model.UpdatedBy, model.UpdatedByName, (int)entity.Status, entity.Id, BillIdentity.AdjustContractPrice.ToString(), reason);

            _db.Command.AddExecute(history.CreateSql(entity.GetType().Name, entity.Code), history);

            _db.SaveChange();
        }
コード例 #5
0
        /// <summary>
        /// 调整供应商商品价格
        /// </summary>
        /// <param name="entity"></param>
        public void AdjustSupplierProduct(AdjustContractPrice entity)
        {
            var supplierProducts = _db.Table.FindAll <SupplierProduct>(n => n.SupplierId == entity.SupplierId).ToList();
            List <SupplierProduct> insertList = new List <SupplierProduct>();
            List <SupplierProduct> updateList = new List <SupplierProduct>();

            foreach (var item in entity.Items)
            {
                var model = supplierProducts.FirstOrDefault(n => n.ProductId == item.ProductId);
                if (model == null)
                {
                    SupplierProduct newProduct = new SupplierProduct()
                    {
                        ProductId  = item.ProductId,
                        SupplierId = entity.SupplierId,
                        Price      = item.AdjustPrice,
                        UpdatedBy  = entity.UpdatedBy,
                        Status     = ValueObject.SupplierProductStatus.Supplying
                    };
                    insertList.Add(newProduct);
                }
                else
                {
                    model.Price = item.AdjustPrice;
                    updateList.Add(model);
                }
            }
            if (insertList.Count > 0)
            {
                _db.Insert <SupplierProduct>(insertList.ToArray());
            }
            if (updateList.Count > 0)
            {
                _db.Update <SupplierProduct>(updateList.ToArray());
            }
        }