示例#1
0
        /// <summary>
        /// 供应商月销售额存档 历史数据
        /// </summary>
        public static void RunHistorySupplierSaleTask()
        {
            //结算价的起点是2014年12月份,2014年12月份的结算价数据由老龚初始化,供应商月销售额从2015年1月开始计算
            int year = 0, month = 1;

            while (!(DateTime.Now.Year.Equals(2015 + year) && DateTime.Now.Month.Equals(month - 1)))
            {
                if (month == 13)
                {
                    year++;
                    month = 1;
                }

                try
                {
                    var result = _supplierSaleRecordBll.InsertSaleRecord(new DateTime(2015 + year, month, 1));
                    if (result)
                    {
                        month++;
                    }
                }
                catch (Exception ex)
                {
                    ERP.SAL.LogCenter.LogService.LogError("供应商月销售额报表存档(历史数据)", "RunGoodsStockRecordTask.Error", ex);
                }
            }
        }
示例#2
0
        /// <summary>执行结算价与商品库存存档任务
        /// </summary>
        public static void RunGoodsStockRecordTask()
        {
            string title = "";

            try
            {
                var date            = DateTime.Now;
                var createStockHour = Configuration.AppSettings["CreateStockHour"];
                var hours           = createStockHour.Split(',');
                if (!hours.Contains(string.Format("{0}", date.Hour)))
                {
                    return;
                }
                var preDate = date.AddMonths(-1);
                //10月份算9月份存档
                var recordDate = new DateTime(preDate.Year, preDate.Month, 1);

                if (_day == DateTime.Now.Day)
                {
                    return;
                }

                if (date.Day == 1)
                {
                    title = "每月月末库存存档";
                    //备份月末库存
                    if (!_goodsStockSettleRecordBll.CopyMonthGoodsStockInfos(recordDate))
                    {
                        ERP.SAL.LogCenter.LogService.LogError("每月月末库存备份失败", "结算价报表存档", null);
                        return;
                    }


                    title = "商品结算价存档";
                    var result = _goodsStockSettleRecordBll.AddSettlePriceAndStockRecord(date.Year, date.Month);
                    if (!result)
                    {
                        ERP.SAL.LogCenter.LogService.LogError(string.Format("{0}年{1}月份商品结算价报表存档失败", preDate.Year, preDate.Month), "商品库存、结算价报表存档", null);
                        return;
                    }

                    //记录销售额存档
                    if (_goodsStockRecord.IsExistsSettlePriceRecord(recordDate))
                    {
                        title = "供应商月销售额存档";
                        if (!_supplierSaleRecordBll.InsertSaleRecord(recordDate))
                        {
                            ERP.SAL.LogCenter.LogService.LogError(string.Format("{0}年{1}月份供应商销售额报表存档失败", preDate.Year, preDate.Month), "供应商月销售额报表存档", null);
                            return;
                        }
                    }
                }
                else
                {
                    //如果是非每月1号先删除所有数据   当月数据的存储
                    var resultData = _supplierSaleRecordBll.SelectSupplierSaleRecordInfos(date);
                    if (!resultData)
                    {
                        ERP.SAL.LogCenter.LogService.LogError(string.Format("{0}年{1}月{2}日供应商每日销售额存档失败", date.Year, date.Month, date.Day), "供应商每日销售额", null);
                        return;
                    }
                }
                _day = DateTime.Now.Day;
            }
            catch (Exception exp)
            {
                ERP.SAL.LogCenter.LogService.LogError("执行结算价与商品库存存档任务", title, exp);
            }
        }
        public void TestInsertSaleRecord()
        {
            _stubISupplierSaleRecord.IsExistsDateTime = time => true;
            var result1 = _supplierSaleRecordBll.InsertSaleRecord(DateTime.Now);

            Assert.IsTrue(result1);

            _stubISupplierSaleRecord.IsExistsDateTime = time => false;


            _stuIStorageRecordDao.GeTempStorageRecordDetailInfosDateTimeDateTime = (time, dateTime) =>
                                                                                   new List <TempStorageRecordDetailInfo>();

            var result2 = _supplierSaleRecordBll.InsertSaleRecord(DateTime.Now);

            Assert.IsTrue(result2);


            _stuIStorageRecordDao.GeTempStorageRecordDetailInfosDateTimeDateTime = (time, dateTime) => new List <TempStorageRecordDetailInfo>
            {
                new TempStorageRecordDetailInfo
                {
                    GoodsId     = new Guid("F1203667-B1B8-4F48-956F-17E524B97B0C"),
                    ID          = Guid.NewGuid(),
                    Quantity    = 10,
                    RealGoodsId = new Guid("B72D12A7-86A6-403A-AE25-0BDFBA092D8F"),
                    StockType   = 4,
                    UnitPrice   = 15,
                    WarehouseId = new Guid("B5BCDF6E-95D5-4AEE-9B19-6EE218255C05")
                },
                new TempStorageRecordDetailInfo
                {
                    GoodsId     = new Guid("F1203667-B1B8-4F48-956F-17E524B97B0C"),
                    ID          = Guid.NewGuid(),
                    Quantity    = 10,
                    RealGoodsId = new Guid("AFDCB083-7AD4-4FEC-A7F0-3D8E2C2665F0"),
                    StockType   = 4,
                    UnitPrice   = 15,
                    WarehouseId = new Guid("B5BCDF6E-95D5-4AEE-9B19-6EE218255C05")
                },
                new TempStorageRecordDetailInfo
                {
                    GoodsId     = new Guid("F1203667-B1B8-4F48-956F-17E524B97B0C"),
                    ID          = Guid.NewGuid(),
                    Quantity    = 10,
                    RealGoodsId = new Guid("545AFF83-C54D-4EFD-8F42-42269E2875AB"),
                    StockType   = 4,
                    UnitPrice   = 15,
                    WarehouseId = new Guid("B5BCDF6E-95D5-4AEE-9B19-6EE218255C05")
                }
            };


            _stubIPurchaseSet.GetPurchaseSetList = () => new List <PurchaseSetInfo>();
            var result3 = _supplierSaleRecordBll.InsertSaleRecord(DateTime.Now);

            Assert.IsTrue(result3);

            _stubIPurchaseSet.GetPurchaseSetList = () => new List <PurchaseSetInfo>
            {
                new PurchaseSetInfo
                {
                    GoodsId     = new Guid("F1203667-B1B8-4F48-956F-17E524B97B0C"),
                    WarehouseId = new Guid("C9752B7B-D2FB-466E-BA73-53F3C36C864A"),
                    CompanyId   = new Guid("32CB5565-6EED-4F78-BC82-0571738FD771")
                }
            };

            _stubIGoodsStockRecord.GetGoodsSettlePriceDictsDateTime = (time) => new Dictionary <Guid, decimal>();

            var result6 = _supplierSaleRecordBll.InsertSaleRecord(DateTime.Now);

            Assert.IsTrue(result6);


            _stubIGoodsStockRecord.GetGoodsSettlePriceDictsDateTime = (time) => new Dictionary <Guid, decimal>
            {
                { new Guid("E838D1AC-A972-413C-87A6-697861A6D69F"), Convert.ToDecimal("14.8") }
            };
            var result5 = _supplierSaleRecordBll.InsertSaleRecord(DateTime.Now);

            Assert.IsTrue(result5);
        }