/// <summary>
        /// 保存
        /// </summary>
        /// <param name="info"></param>
        public void Save(RealTimeGrossSettlementInfo info)
        {
            if (info == null)
            {
                return;
            }
            const string SQL = @"
INSERT INTO [RealTimeGrossSettlement]
           ([FilialeId]
           ,[GoodsId]
           ,[UnitPrice]
           ,[StockQuantity]
           ,[GoodsQuantityInBill]
           ,[GoodsAmountInBill]
           ,[RelatedTradeType]
           ,[RelatedTradeNo]
           ,[OccurTime]
           ,[CreateTime]
           ,[ExtField_1])
     VALUES
            (@FilialeId
            ,@GoodsId
            ,@UnitPrice
            ,@StockQuantity
            ,@GoodsQuantityInBill
            ,@GoodsAmountInBill
            ,@RelatedTradeType
            ,@RelatedTradeNo
            ,@OccurTime
            ,getdate()
            ,@ExtField_1)
";

            using (SqlConnection conn = Databases.GetSqlConnection(GlobalConfig.ERP_DB_NAME, false))
            {
                conn.Execute(SQL, new
                {
                    FilialeId           = info.FilialeId,
                    GoodsId             = info.GoodsId,
                    UnitPrice           = info.UnitPrice,
                    StockQuantity       = info.StockQuantity,
                    GoodsQuantityInBill = info.GoodsQuantityInBill,
                    GoodsAmountInBill   = info.GoodsAmountInBill,
                    RelatedTradeType    = info.RelatedTradeType,
                    RelatedTradeNo      = info.RelatedTradeNo,
                    OccurTime           = info.OccurTime,
                    ExtField_1          = info.ExtField_1,
                });
            }
        }
Ejemplo n.º 2
0
        public static void Save(RealTimeGrossSettlementInfo info)
        {
            const string SQL = @"
update RealTimeGrossSettlement
set UnitPrice=@UnitPrice,GoodsAmountInBill=@GoodsAmountInBill,ExtField_1=@ExtField_1
where RelatedTradeType<>0 and FilialeId=@FilialeId and GoodsId=@GoodsId and RelatedTradeNo=@RelatedTradeNo";

            if (info != null)
            {
                using (var conn = new SqlConnection(GlobalConfig.ERPConnnectionString))
                {
                    conn.Execute(SQL, new { FilialeId = info.FilialeId, GoodsId = info.GoodsId, RelatedTradeNo = info.RelatedTradeNo, UnitPrice = info.UnitPrice, GoodsAmountInBill = info.GoodsAmountInBill, ExtField_1 = info.ExtField_1 });
                }
            }
        }
Ejemplo n.º 3
0
        public static void Delete(RealTimeGrossSettlementInfo info)
        {
            const string SQL = @"
select *
from RealTimeGrossSettlement
where RelatedTradeType<>0 and FilialeId=@FilialeId and GoodsId=@GoodsId and RelatedTradeNo=@RelatedTradeNo";

            const string DEL_SQL = @"
delete from RealTimeGrossSettlement
where RelatedTradeType<>0 and FilialeId=@FilialeId and GoodsId=@GoodsId and RelatedTradeNo=@RelatedTradeNo";

            if (info != null)
            {
                using (var conn = new SqlConnection(GlobalConfig.ERPConnnectionString))
                {
                    var list = conn.Query <RealTimeGrossSettlementInfo>(SQL, new { FilialeId = info.FilialeId, GoodsId = info.GoodsId, RelatedTradeNo = info.RelatedTradeNo });
                    if (list.Count() == 1)
                    {
                        conn.Execute(DEL_SQL, new { FilialeId = info.FilialeId, GoodsId = info.GoodsId, RelatedTradeNo = info.RelatedTradeNo });
                    }
                }
                //
            }
        }
        private RealTimeGrossSettlementInfo Create(RealTimeGrossSettlementProcessQueueInfo item)
        {
            if (item == null)
            {
                return(null);
            }
            var result = new RealTimeGrossSettlementInfo
            {
                FilialeId           = item.FilialeId,
                GoodsId             = item.GoodsId,
                StockQuantity       = item.StockQuantity,
                GoodsQuantityInBill = item.GoodsQuantityInBill,
                GoodsAmountInBill   = item.GoodsAmountInBill,
                RelatedTradeNo      = item.RelatedTradeNo,
                RelatedTradeType    = item.RelatedTradeType,
                OccurTime           = item.OccurTime,
                ExtField_1          = item.ExtField_1,
            };

            // 即时结算计算方式:(上次结算价 * (最新库存数 - 单据中数量) + 单据中的总金额) / 最新库存数
            switch (item.RelatedTradeType)
            {
            case (int)RealTimeGrossSettlementRelatedTradeType.PurchaseStockIn:
                if (item.StockQuantity < item.GoodsQuantityInBill)
                {
                    // 采购后的库存应不能小于采购入库单内的数量
                    result.UnitPrice = item.GoodsAmountInBill / item.GoodsQuantityInBill;
                    if (result.UnitPrice == 0)
                    {
                        result.UnitPrice = item.LastUnitPrice;    // 按当前单据计算结算价,如果为0,则取上次结算价
                    }
                }
                else
                {
                    if (item.LastGrossSettlement != null && item.LastGrossSettlement.StockQuantity <= 0 &&
                        item.LastGrossSettlement.RelatedTradeType == (int)RealTimeGrossSettlementRelatedTradeType.PurchaseReturnStockOut)
                    {
                        // 上次的结算价时采购退货,且库存为0的,则按上次退货和这次进货一起算
                        var x = ((item.StockQuantity - item.GoodsQuantityInBill + item.LastGrossSettlement.GoodsQuantityInBill) * item.LastUnitPrice
                                 + item.LastGrossSettlement.GoodsAmountInBill
                                 + item.GoodsAmountInBill)
                                / item.StockQuantity;
                    }
                    else
                    {
                        result.UnitPrice = (item.LastUnitPrice * (item.StockQuantity - item.GoodsQuantityInBill) + item.GoodsAmountInBill) / item.StockQuantity;
                    }
                }
                break;

            case (int)RealTimeGrossSettlementRelatedTradeType.PurchaseReturnStockOut:
                if (item.StockQuantity <= 0)
                {
                    // 采购退货后,如果当前库存为0,则不计算,直接取上次结算价
                    result.UnitPrice = item.LastUnitPrice;
                }
                else
                {
                    if (item.LastGrossSettlement != null && item.LastGrossSettlement.StockQuantity < item.GoodsQuantityInBill &&
                        item.LastGrossSettlement.RelatedTradeType == (int)RealTimeGrossSettlementRelatedTradeType.PurchaseReturnStockOut)
                    {
                        result.UnitPrice = item.LastUnitPrice;
                    }
                    else
                    {
                        result.UnitPrice = (item.LastUnitPrice * (item.StockQuantity + item.GoodsQuantityInBill) + item.GoodsAmountInBill) / item.StockQuantity;
                    }
                }
                break;

            case (int)RealTimeGrossSettlementRelatedTradeType.StockInFormDashAtRed:
                if (item.GoodsAmountInBill == item.ExtField_1)
                {
                    // 单据红冲金额和原采购入库单的金额一致,则不需要计算结算价
                    return(null);
                }
                if (item.StockQuantity <= 0)
                {
                    result.UnitPrice = item.LastUnitPrice;
                }
                else
                {
                    var tmpUnitPrice = (item.StockQuantity * item.LastUnitPrice + item.GoodsAmountInBill) / (item.StockQuantity + item.GoodsQuantityInBill); // 先按进货方式计算
                    result.UnitPrice = (tmpUnitPrice * (item.StockQuantity + item.GoodsQuantityInBill) - item.ExtField_1) / item.StockQuantity;              // 再按退货方式计算
                }
                break;

            case (int)RealTimeGrossSettlementRelatedTradeType.CombineSplit:
                if (item.StockQuantity <= 0)
                {
                    result.UnitPrice = item.GoodsAmountInBill / item.GoodsQuantityInBill;
                }
                else
                {
                    result.UnitPrice = (item.LastUnitPrice * (item.StockQuantity - item.GoodsQuantityInBill) + item.GoodsAmountInBill) / item.StockQuantity;
                }
                break;
            }
            return(result);
        }