示例#1
0
        void saveUdefEntry(Voucher item, dynamic tran)
        {
            if (item.udefenties == null)
            {
                return;
            }
            var       udefTemplate = TemplateSevice.GetInstance(mContext).FindUdefTemplate("_VoucherEntryUdef");
            DataTable dtUdef       = new DataTable();

            dtUdef.Columns.Add(new DataColumn("_id", typeof(long)));
            dtUdef.Columns.Add(new DataColumn("_uniqueKey", typeof(string)));

            udefTemplate.Add(new UdefTemplateItem {
                name = "act_qty", dataType = "decimal"
            });
            udefTemplate.Add(new UdefTemplateItem {
                name = "act_price", dataType = "decimal"
            });
            udefTemplate.Add(new UdefTemplateItem {
                name = "actItemGrp", dataType = "int"
            });

            udefTemplate.ForEach(udef => {
                var dc = new DataColumn("_" + udef.name, CommonUtils.ConvertDataTypeFromStr(udef.dataType));
                dtUdef.Columns.Add(dc);
            });

            foreach (var udef in item.udefenties)
            {
                DataRow dr = dtUdef.NewRow();
                dr["_id"]        = item.header.id;
                dr["_uniqueKey"] = udef.Key;

                Dictionary <string, object> udefValues = udef.Value;
                foreach (var temp in udefTemplate)
                {
                    Type t = CommonUtils.ConvertDataTypeFromStr(temp.dataType);
                    if (udefValues.ContainsKey(temp.name))
                    {
                        dr["_" + temp.name] = Convert.ChangeType(udefValues[temp.name], t);
                    }
                    else
                    {
                        dr["_" + temp.name] = t.IsValueType ? Activator.CreateInstance(t) : DBNull.Value;
                    }
                }
                dtUdef.Rows.Add(dr);
            }
            DBHelper.GetInstance(mContext).InsertTable(tran, dtUdef, "_VoucherEntryUdef");
        }
示例#2
0
        public List <CashflowSheetItem> ListSheet(Dictionary <string, string> filter)
        {
            List <ExcelTemplateItem> lstTemplate = TemplateSevice.GetInstance(mContext).FindTemplate("现金流量表");
            var result = new List <CashflowSheetItem>();

            var beginYear   = int.Parse(filter["beginYear"]);
            var beginPeriod = int.Parse(filter["beginPeriod"]);
            var endYear     = int.Parse(filter["endYear"]);
            var endPeriod   = int.Parse(filter["endPeriod"]);
            var prev        = CommonUtils.CalcPrevPeriod(new PeridStrunct {
                Year = beginYear, Period = beginPeriod
            });
            var curYear = SystemProfileService.GetInstance(mContext).GetInt(SystemProfileCategory.Account, SystemProfileKey.CurrentYear);

            m_lstAso    = DataManager.GetInstance(mContext).Query <AccountSubject>(null).OrderBy(a => a.no).ToList();
            m_lstBegin  = AccountBalanceService.GetInstance(mContext).QuerySettled(prev.Year, prev.Period);
            m_lstOccurs = AccountBalanceService.GetInstance(mContext).QueryOccurs(beginYear, beginPeriod, endYear, endPeriod);
            m_lstYear   = AccountBalanceService.GetInstance(mContext).QueryOccurs(curYear, 1, curYear, 12);

            Dictionary <int, CalTempObj> dictTemplate = new Dictionary <int, CalTempObj>();

            foreach (var template in lstTemplate)
            {
                var item = new CashflowSheetItem();
                item.Name   = template.a;
                item.LineNo = template.b;
                var lineNo = 0;
                if (int.TryParse(item.LineNo, out lineNo))
                {
                    item.Amount = CalcFormula(lineNo, template.c);
                    dictTemplate.Add(lineNo, new CalTempObj(template, item.Amount));
                }
                result.Add(item);
            }

            foreach (var item in result)
            {
                //计算扩展列
                var lineNo = 0;
                if (int.TryParse(item.LineNo, out lineNo))
                {
                    decimal extendAmount = 0;
                    if (CalcExtend(lineNo, dictTemplate, out extendAmount))
                    {
                        item.Amount = extendAmount;
                    }
                }
            }

            foreach (var item in result)
            {
                //计算合计列L
                var lineNo = 0;
                if (int.TryParse(item.LineNo, out lineNo))
                {
                    decimal sumAmount = 0;
                    if (CalcSum(lineNo, dictTemplate, out sumAmount))
                    {
                        item.Flag   = 1;
                        item.Amount = sumAmount;
                        dictTemplate[lineNo].originAmount = item.Amount;
                    }
                }
            }
            return(result);
        }
示例#3
0
        void ExecCarriedForward(string taskId, string procName, Dictionary <string, object> paramMap)
        {
            if (paramMap == null)
            {
                paramMap = new Dictionary <string, object>();
            }

            RefreshTaskResult(taskId, ExecTaskType.CarriedForward.ToString(), 0, "开始执行", "");

            Auxiliary auxFilter = new Auxiliary()
            {
                type = (int)AuxiliaryType.CarriedForward, no = procName
            };
            var lst = DataManager.GetInstance(mContext).Query(auxFilter);

            if (lst == null || lst.Count == 0)
            {
                throw new FinanceException(FinanceResult.RECORD_NOT_EXIST, "结转方式不存在");
            }

            var auxObj       = lst.FirstOrDefault();
            var templateList = TemplateSevice.GetInstance(mContext).ListCarriedForwardTemplate(auxObj.id);

            if (templateList == null || templateList.Count == 0)
            {
                throw new FinanceException(FinanceResult.RECORD_NOT_EXIST, "结转模板不存在");
            }

            var year     = SystemProfileService.GetInstance(mContext).GetInt(SystemProfileCategory.Account, SystemProfileKey.CurrentYear);
            var period   = SystemProfileService.GetInstance(mContext).GetInt(SystemProfileCategory.Account, SystemProfileKey.CurrentPeriod);
            var dbHelper = DBHelper.GetInstance(mContext);

            //1、检查是否还有未过账
            if (dbHelper.Exist(string.Format("select 1 from _VoucherHeader where _year = {0} and _period = {1} and _status < {2} and _status <> {3}"
                                             , year, period, (int)VoucherStatus.Posted, (int)VoucherStatus.Canceled)))
            {
                throw new FinanceException(FinanceResult.INCORRECT_STATE, "当前凭证没有全部过账");
            }
            //2、生成凭证
            var direction = 1;

            switch (auxObj.description)
            {
            case "income":

                break;

            case "cost":
                direction = -1;
                break;

            case "investment":

                break;

            case "profits":

                break;
            }
            var word = "转";

            if (paramMap.ContainsKey("word"))
            {
                word = paramMap["word"].ToString();
            }
            var explanation = auxObj.name;

            if (paramMap.ContainsKey("explanation"))
            {
                explanation = paramMap["explanation"].ToString();
            }
            var lstAccountObject = AccountSubjectService.GetInstance(mContext).List();
            var lstEntries       = new List <VoucherEntry>();
            var index            = 0;

            foreach (var temp in templateList)
            {
                var srcActObj = lstAccountObject.FirstOrDefault(actObj => actObj.id == temp.src);
                var dstActObj = lstAccountObject.FirstOrDefault(actObj => actObj.id == temp.dst);
                if (srcActObj == null || dstActObj == null)
                {
                    throw new FinanceException(FinanceResult.RECORD_NOT_EXIST, "结转模板数据错误");
                }

                var amountObj = dbHelper.ExecuteScalar(string.Format(@"select sum(_amount * _direction) as _amount 
from _VoucherEntry where _accountSubjectId = {0}
and _id in (select _id from _VoucherHeader where _year = {1} and _period = {2})", temp.src, year, period));
                if (amountObj == null || amountObj == DBNull.Value)
                {
                    continue;
                }

                var amount = (decimal)amountObj;
                if (amount < 0)
                {
                    direction = -1 * direction;
                    amount    = -1 * amount;
                }

                var voucherEntrySrc = new VoucherEntry();
                voucherEntrySrc.index            = index++;
                voucherEntrySrc.accountSubjectId = temp.src;
                voucherEntrySrc.accountSubjectNo = srcActObj.no;
                voucherEntrySrc.amount           = amount;
                voucherEntrySrc.direction        = direction;
                voucherEntrySrc.explanation      = explanation;
                lstEntries.Add(voucherEntrySrc);

                var voucherEntryDst = new VoucherEntry();
                voucherEntryDst.index            = index++;
                voucherEntryDst.accountSubjectId = temp.dst;
                voucherEntryDst.accountSubjectNo = dstActObj.no;
                voucherEntryDst.amount           = amount;
                voucherEntryDst.direction        = -1 * direction;
                voucherEntryDst.explanation      = explanation;
                lstEntries.Add(voucherEntryDst);
            }
            if (lstEntries.Count == 0)
            {
                throw new FinanceException(FinanceResult.RECORD_NOT_EXIST, "没有需要结转的凭证");
            }

            var voucherHeader = new VoucherHeader();

            voucherHeader.word   = word;
            voucherHeader.year   = year;
            voucherHeader.period = period;
            voucherHeader.date   = CommonUtils.CalcMaxPeriodDate(year, period);
            var now = DateTime.Now;

            voucherHeader.businessDate = now;
            voucherHeader.creatTime    = now;
            voucherHeader.creater      = 13594;

            Voucher voucher = new Voucher();

            voucher.header  = voucherHeader;
            voucher.entries = lstEntries;
            var id  = VoucherService.GetInstance(mContext).Add(voucher);
            var h   = VoucherService.GetInstance(mContext).FindHeader(id);
            var msg = string.Format("结转成功,凭证字号:{0} - {1};", h.word, h.no);

            RefreshTaskResult(taskId, ExecTaskType.CreateVoucher.ToString(), 100, "", msg, 1);
        }