コード例 #1
0
    protected void bt_WriteOff_Click(object sender, EventArgs e)
    {
        #region 求选中行的差旅费、住宿费、补贴合计
        decimal Cost1 = 0, Cost2 = 0, Cost3 = 0, Cost4 = 0, Cost5 = 0;
        decimal Cost11 = 0, Cost12 = 0, Cost13 = 0;     //车辆费用
        decimal Cost21 = 0, Cost22 = 0;

        DateTime   minbegindate = DateTime.Parse("2999-1-1"), maxenddate = DateTime.Parse("1900-1-1");
        List <int> selectedevectionids = new List <int>();

        foreach (GridViewRow row in gv_List.Rows)
        {
            CheckBox cbx = (CheckBox)row.FindControl("cbx");
            if (cbx != null && cbx.Checked)
            {
                int id = (int)gv_List.DataKeys[row.RowIndex][0];
                FNA_EvectionRoute evection = new FNA_EvectionRouteBLL(id).Model;

                #region 根据关联的工作日志的类型,判断是否培训费
                //获取关联的日志类型
                int journalid = 0, workingclassify = 0;
                if (int.TryParse(evection["RelateJournal"], out journalid) && journalid > 0)
                {
                    JN_Journal Joural = new JN_JournalBLL(journalid).Model;
                    if (Joural != null)
                    {
                        workingclassify = Joural.WorkingClassify;
                    }
                }

                switch (workingclassify)
                {
                case 4:         //总部组织的培训,计入总部培训-差旅费
                    Cost21 += evection.Cost1 + evection.Cost2 + evection.Cost3 + evection.Cost4 + evection.Cost5;
                    break;

                case 5:         //省区组织的培训,计入营业部培训-差旅费
                    Cost22 += evection.Cost1 + evection.Cost2 + evection.Cost3 + evection.Cost4 + evection.Cost5;
                    break;

                default:
                    Cost1 += evection.Cost1;          //交通费
                    Cost2 += evection.Cost2;          //住宿费
                    Cost3 += evection.Cost3;          //补贴
                    Cost4 += evection.Cost4;          //市内交通费
                    Cost5 += evection.Cost5;          //的士费
                    break;
                }
                #endregion

                if (minbegindate > evection.BeginDate)
                {
                    minbegindate = evection.BeginDate;
                }
                if (maxenddate < evection.EndDate)
                {
                    maxenddate = evection.EndDate;
                }

                int cardispatchid = 0;
                if (int.TryParse(gv_List.DataKeys[row.RowIndex]["Car_DispatchRide_ID"].ToString(), out cardispatchid) &&
                    cardispatchid > 0)
                {
                    Car_DispatchRide dispatch = new Car_DispatchRideBLL(cardispatchid).Model;
                    if (dispatch != null)
                    {
                        Cost11 += dispatch.RoadToll;    //过路过桥费
                        Cost12 += dispatch.FuelFee;     //油费
                        Cost13 += dispatch.ParkingFee;  //停车费
                        Cost13 += dispatch.OtherFee;    //其他费
                    }
                }
                selectedevectionids.Add(id);
            }
        }
        if (Cost1 + Cost2 + Cost3 + Cost4 + Cost5 + Cost11 + Cost12 + Cost13 + Cost21 + Cost22 == 0)
        {
            MessageBox.Show(this, "对不起,请勾选要报销的差旅行程记录!");
            return;
        }
        #endregion

        #region 新增费用核销单头
        Org_Staff staff = new Org_StaffBLL((int)Session["UserID"]).Model;

        FNA_FeeWriteOffBLL bll = new FNA_FeeWriteOffBLL();
        bll.Model.SheetCode             = FNA_FeeWriteOffBLL.GenerateSheetCode(staff.OrganizeCity); //自动产生报销单号
        bll.Model.AccountMonth          = AC_AccountMonthBLL.GetCurrentMonth();
        bll.Model.FeeType               = ConfigHelper.GetConfigInt("EvectionFeeType");             //差旅费对应的费用类型
        bll.Model.OrganizeCity          = staff.OrganizeCity;
        bll.Model.ApproveFlag           = 1;
        bll.Model.State                 = 1;
        bll.Model.InsertStaff           = (int)Session["UserID"];
        bll.Model["HasFeeApply"]        = "N";        //无申请单
        bll.Model["IsEvectionWriteOff"] = "Y";        //是差旅报销
        #endregion

        #region 新增费用核销单明细
        AddWriteOffDetail(bll, ConfigHelper.GetConfigInt("EvectionCost1ACTitle"), Cost1, minbegindate, maxenddate);   //交通费
        AddWriteOffDetail(bll, ConfigHelper.GetConfigInt("EvectionCost2ACTitle"), Cost2, minbegindate, maxenddate);   //住宿费
        AddWriteOffDetail(bll, ConfigHelper.GetConfigInt("EvectionCost3ACTitle"), Cost3, minbegindate, maxenddate);   //补贴
        AddWriteOffDetail(bll, ConfigHelper.GetConfigInt("EvectionCost4ACTitle"), Cost4, minbegindate, maxenddate);   //市内交通费
        AddWriteOffDetail(bll, ConfigHelper.GetConfigInt("EvectionCost5ACTitle"), Cost5, minbegindate, maxenddate);   //的士费

        AddWriteOffDetail(bll, ConfigHelper.GetConfigInt("EvectionCost11ACTitle"), Cost11, minbegindate, maxenddate); //车辆费用-路桥费
        AddWriteOffDetail(bll, ConfigHelper.GetConfigInt("EvectionCost12ACTitle"), Cost12, minbegindate, maxenddate); //车辆费用-油费
        AddWriteOffDetail(bll, ConfigHelper.GetConfigInt("EvectionCost13ACTitle"), Cost13, minbegindate, maxenddate); //车辆费用-其他杂费

        AddWriteOffDetail(bll, ConfigHelper.GetConfigInt("TrainingCost1ACTitle"), Cost21, minbegindate, maxenddate);  //总部培训费-差旅费
        AddWriteOffDetail(bll, ConfigHelper.GetConfigInt("TrainingCost2ACTitle"), Cost22, minbegindate, maxenddate);  //营业部培训费-差旅费
        #endregion

        int writeoff = bll.Add();

        #region 置差旅行程的关联报销单ID
        foreach (int evectionid in selectedevectionids)
        {
            FNA_EvectionRouteBLL evectionbll = new FNA_EvectionRouteBLL(evectionid);
            evectionbll.Model.WriteOffID = writeoff;
            evectionbll.Update();
        }
        #endregion

        Response.Redirect("FeeWriteoffDetail.aspx?ID=" + writeoff.ToString());
    }
コード例 #2
0
    protected void bt_Save_Click(object sender, EventArgs e)
    {
        ListTable <FNA_FeeWriteOffDetail> _details;

        if (ViewState["Details"] != null)
        {
            _details = ViewState["Details"] as ListTable <FNA_FeeWriteOffDetail>;
        }
        else
        {
            _details = new ListTable <FNA_FeeWriteOffDetail>(new FNA_FeeWriteOffBLL((int)ViewState["ID"]).Items, "ID");
        }

        FNA_FeeWriteOffBLL bll;

        if ((int)ViewState["ID"] == 0)
        {
            bll = new FNA_FeeWriteOffBLL();
        }
        else
        {
            bll = new FNA_FeeWriteOffBLL((int)ViewState["ID"]);
            if (bll.Model.State != 1)
            {
                MessageBox.ShowAndRedirect(this, "对不起,当前核销单的状态不是“未提交”状态,不可保存!", "FeeWriteOffDetail.aspx?ID=" + ViewState["ID"].ToString());
                return;
            }
        }
        pn_FeeWriteOff.GetData(bll.Model);
        bll.Model["Remark"] = tbx_Remark.Text;

        #region  效性校验
        // 判断是否选择了费用代垫客户或代垫员工
        {
            if (bll.Model["InsteadPaySystem"] == "0")
            {
                bll.Model["InsteadPaySystem"] = "";
            }
            if (bll.Model["InsteadPayStaff"] == "0")
            {
                bll.Model["InsteadPayStaff"] = "";
            }

            int insteadcount = 0;
            if (bll.Model.InsteadPayClient != 0)
            {
                insteadcount++;
            }
            if (!string.IsNullOrEmpty(bll.Model["InsteadPayStaff"]))
            {
                insteadcount++;
            }
            if (!string.IsNullOrEmpty(bll.Model["InsteadPaySystem"]))
            {
                insteadcount++;
            }

            if (insteadcount > 1)
            {
                MessageBox.Show(this, "代垫信息中,只能填写其中一个代垫信息!");
                return;
            }
            else if (insteadcount == 0)
            {
                MessageBox.Show(this, "代垫信息中,必须填写其中一个代垫信息!");
                return;
            }
        }
        #endregion

        if ((int)ViewState["ID"] == 0)
        {
            bll.Model.SheetCode             = FNA_FeeWriteOffBLL.GenerateSheetCode((int)ViewState["OrganizeCity"]); //自动产生报销单号
            bll.Model.AccountMonth          = (int)ViewState["AccountMonth"];
            bll.Model.FeeType               = (int)ViewState["FeeType"];
            bll.Model.OrganizeCity          = (int)ViewState["OrganizeCity"];
            bll.Model.ApproveFlag           = 1;
            bll.Model.State                 = 1;
            bll.Model["HasFeeApply"]        = ViewState["HasFeeApply"].ToString(); //是否有申请单
            bll.Model["IsEvectionWriteOff"] = "N";                                 //非关联于差旅行程的报销
            bll.Model.InsertStaff           = (int)Session["UserID"];
            bll.Model["InvoiceClassAB"]     = ViewState["InvoiceClassAB"].ToString();
            bll.Model["FeeApplyClient"]     = ViewState["FeeApplyClient"].ToString();
            bll.Model["FeeApplyStaff"]      = ViewState["FeeApplyStaff"].ToString();
            bll.Items = _details.GetListItem();

            ViewState["ID"] = bll.Add();
        }
        else
        {
            bll.Model.UpdateStaff = (int)Session["UserID"];
            bll.Update();

            #region 修改明细

            #region 增加报销明细时,再次判断该项费用是否已报销
            bll.Items = new List <FNA_FeeWriteOffDetail>();
            foreach (FNA_FeeWriteOffDetail item in _details.GetListItem(ItemState.Added))
            {
                FNA_FeeApplyBLL apply = new FNA_FeeApplyBLL();
                if (apply.GetDetailModel(item.ApplyDetailID).Flag == 1)
                {
                    bll.Items.Add(item);
                }
            }
            bll.AddDetail();
            #endregion

            foreach (FNA_FeeWriteOffDetail _deleted in _details.GetListItem(ItemState.Deleted))
            {
                bll.DeleteDetail(_deleted.ID);
            }

            bll.Items = _details.GetListItem(ItemState.Modified);
            bll.UpdateDetail();

            #endregion
        }

        if (sender != null)
        {
            Response.Redirect("FeeWriteOffDetail.aspx?ID=" + ViewState["ID"].ToString());
        }
    }