Esempio n. 1
0
        private void CaculateAmount()
        {
            LoadingStatus = 1;
            PawnSpan Span = DianDangFunction.GetPawnSpan(DateTime.Parse(tbxStartDate.Text), DateTime.Parse(tbxEndDate.Text));

            double amount = 0, totalAmount = 0, serviceFee = 0, totalServiceFee = 0, interestFee = 0, totalInterestFee = 0, CustomerPaid = 0;

            for (int i = dataGridView1.Rows.Count - 1; i > -1; i--)
            {
                amount      = Convert.ToDouble(dataGridView1.Rows[i].Cells["Amount"].Value);
                serviceFee  = (Span.Months + Span.CountDays / 30) * amount * Convert.ToDouble(dataGridView1.Rows[i].Cells["FeeRate"].Value) / 100;
                interestFee = (Span.Months + Span.CountDays / 30) * amount * Convert.ToDouble(dataGridView1.Rows[i].Cells["InterestRate"].Value) / 100;
                serviceFee  = DianDangFunction.myRound(serviceFee, MainForm.AmountAccuracy);
                interestFee = DianDangFunction.myRound(interestFee, MainForm.AmountAccuracy);
                dataGridView1.Rows[i].Cells["ServiceFee"].Value = serviceFee;


                totalAmount      += amount;
                totalServiceFee  += serviceFee;
                totalInterestFee += interestFee;
            }
            CustomerPaid = totalServiceFee + Convert.ToDouble(this.tbxLastInterestFee.Text);
            CustomerPaid = DianDangFunction.myRound(CustomerPaid, MainForm.AmountAccuracy);

            this.tbxTotalAmount.Text  = totalAmount.ToString();
            this.tbxServiceFee.Text   = totalServiceFee.ToString();
            this.tbxInterestFee.Text  = totalInterestFee.ToString();
            this.tbxCustomerPaid.Text = CustomerPaid.ToString();

            this.lblTotalAmount.Text  = newChinese.toChineseChar(Convert.ToDecimal(totalAmount));
            this.lblServiceFee.Text   = newChinese.toChineseChar(Convert.ToDecimal(totalServiceFee));
            this.lblInterestFee.Text  = newChinese.toChineseChar(Convert.ToDecimal(totalInterestFee));
            this.lblCustomerPaid.Text = newChinese.toChineseChar(Convert.ToDecimal(CustomerPaid));
            LoadingStatus             = 0;
        }
Esempio n. 2
0
        private void LoadTicketInfo(int intTicketID)
        {
            m_TicketID = intTicketID;
            double       TotalLastInterestFee = 0;
            double       LastInterestFee      = 0;
            DDPawnTicket newTicket            = new DDPawnTicket("TicketID", intTicketID);

            this.lblOldTicketNum.Text = newTicket.TicketNumber;
            this.tbxStartDate.Text    = newTicket.EndDate;
            this.tbxEndDate.Text      = newTicket.EndDate;
            m_EndDate = newTicket.EndDate;
            DateTime operationDate = DateTime.Now;

            this.tbxOperationDate.Text = operationDate.Year.ToString() + "-" + operationDate.Month.ToString() + "-" + operationDate.Day.ToString();

            Query query = new Query(DDOperation.Schema);

            query.AddWhere("TicketID", intTicketID);
            query.AddWhere("NextOperationID", 0);
            query.AddWhere("OperationType", Comparison.NotEquals, 6);
            DataTable dt = query.ExecuteDataSet().Tables[0];

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                DDPawnageInfo pawnageInfo = new DDPawnageInfo("PawnageID", dt.Rows[i]["PawnageID"]);
                this.dataGridView1.Rows.Add(1);
                dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells["OperationID"].Value   = dt.Rows[i]["OperationID"];
                dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells["PawnageID"].Value     = pawnageInfo.PawnageID;
                dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells["ParentClassID"].Value = pawnageInfo.ParentID;
                DDPawnageClass parentClass = new DDPawnageClass("ClassID", pawnageInfo.ParentID);
                dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells["ParentClass"].Value  = parentClass.ClassName;
                dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells["ChildClassID"].Value = pawnageInfo.ClassID;
                DDPawnageClass childClass = new DDPawnageClass("ClassID", pawnageInfo.ClassID);
                dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells["ChildClass"].Value      = childClass.ClassName;
                dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells["FeeRate"].Value         = dt.Rows[i]["ServiceFeeRate"].ToString();
                dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells["InterestRate"].Value    = dt.Rows[i]["InterestFeeRate"].ToString();
                dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells["Description"].Value     = pawnageInfo.Description;
                dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells["CountNumber"].Value     = pawnageInfo.CountNumber;
                dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells["Weight"].Value          = pawnageInfo.Weight;
                dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells["DiscountPercent"].Value = pawnageInfo.DiscountPercent;
                dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells["Amount"].Value          = dt.Rows[i]["Amount"];
                dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells["Remark"].Value          = pawnageInfo.Remark;

                //计算上期利息
                DateTime StartDate        = DateTime.Parse(dt.Rows[i]["StartDate"].ToString());
                DateTime EndDate          = DateTime.Parse(dt.Rows[i]["EndDate"].ToString());
                PawnSpan LastInterestSpan = DianDangFunction.GetPawnSpan(StartDate, EndDate, FeeType.InterestFee, PeridType.Within);

                LastInterestFee = (LastInterestSpan.Months + LastInterestSpan.CountDays / 30) * Convert.ToDouble(dt.Rows[i]["InterestFeeRate"].ToString()) * Convert.ToDouble(dt.Rows[i]["Amount"].ToString()) / 100;
                LastInterestFee = DianDangFunction.myRound(LastInterestFee, MainForm.AmountAccuracy);
                dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells["InterestFee"].Value = LastInterestFee;
                TotalLastInterestFee += LastInterestFee;
            }
            CaculateAmount();

            this.tbxLastInterestFee.Text = TotalLastInterestFee.ToString();
            this.lblLastInterestFee.Text = newChinese.toChineseChar(Convert.ToDecimal(TotalLastInterestFee));
        }
Esempio n. 3
0
        void dataGridView1_CellValueChanged(object sender, System.Windows.Forms.DataGridViewCellEventArgs e)
        {
            if (LoadingStatus == 0 && e.ColumnIndex != -1)
            {
                if (e.ColumnIndex == dataGridView1.Columns["FeeRate"].Index)
                {
                    try
                    {
                        PawnSpan ServiceSpan    = DianDangFunction.GetPawnSpan(DateTime.Parse(tbxStartDate.Text), DateTime.Parse(tbxEndDate.Text), FeeType.ServiceFee, PeridType.Within);
                        double   amount         = Convert.ToDouble(dataGridView1.Rows[e.RowIndex].Cells["Amount"].Value.ToString());
                        double   serviceFeeRate = Convert.ToDouble(dataGridView1.Rows[e.RowIndex].Cells["FeeRate"].Value.ToString());
                        dataGridView1.Rows[e.RowIndex].Cells["ServiceFee"].Value = (ServiceSpan.Months + ServiceSpan.CountDays / 30) * amount * serviceFeeRate / 100;
                        CaculateDataGridAmount();
                    }
                    catch
                    {
                        dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = OldValue;
                        MessageBox.Show("请输入正确的费率", "提示信息");
                    }
                }
                else
                {
                    try
                    {
                        Convert.ToDouble(dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString());
                        CaculateDataGridAmount();
                    }
                    catch
                    {
                        dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = OldValue;
                        MessageBox.Show("请输入正确的金额", "提示信息");
                    }
                }
            }

            //throw new System.NotImplementedException();
        }
Esempio n. 4
0
        private void CaculateDataGridAmount()
        {
            LoadingStatus = 1;
            double totalServiceFee      = 0;
            double totalLastInterestFee = 0;
            double totalInterestFee     = 0;

            if (dataGridView1.Rows.Count > 0)
            {
                for (int i = 0; i < dataGridView1.Rows.Count; i++)
                {
                    PawnSpan InterestSpan    = DianDangFunction.GetPawnSpan(DateTime.Parse(tbxStartDate.Text), DateTime.Parse(tbxEndDate.Text), FeeType.InterestFee, PeridType.Within);
                    double   amount          = Convert.ToDouble(dataGridView1.Rows[i].Cells["Amount"].Value.ToString());
                    double   interestFeeRate = Convert.ToDouble(dataGridView1.Rows[i].Cells["InterestRate"].Value.ToString());

                    double interestFee = (InterestSpan.Months + InterestSpan.CountDays / 30) * amount * interestFeeRate / 100;
                    interestFee       = DianDangFunction.myRound(interestFee, MainForm.AmountAccuracy);
                    totalInterestFee += interestFee;

                    totalServiceFee      += Convert.ToDouble(dataGridView1.Rows[i].Cells["ServiceFee"].Value);
                    totalLastInterestFee += Convert.ToDouble(dataGridView1.Rows[i].Cells["InterestFee"].Value);
                }
            }
            tbxServiceFee.Text = DianDangFunction.myRound(totalServiceFee, MainForm.AmountAccuracy).ToString();
            lblServiceFee.Text = newChinese.toChineseChar(Convert.ToDecimal(totalServiceFee));

            tbxLastInterestFee.Text = DianDangFunction.myRound(totalLastInterestFee, MainForm.AmountAccuracy).ToString();
            lblLastInterestFee.Text = newChinese.toChineseChar(Convert.ToDecimal(totalLastInterestFee));

            tbxInterestFee.Text = DianDangFunction.myRound(totalInterestFee, MainForm.AmountAccuracy).ToString();
            lblInterestFee.Text = newChinese.toChineseChar(Convert.ToDecimal(totalInterestFee));

            tbxCustomerPaid.Text = DianDangFunction.myRound((totalServiceFee + totalLastInterestFee), MainForm.AmountAccuracy).ToString();
            lblCustomerPaid.Text = newChinese.toChineseChar(Convert.ToDecimal(tbxCustomerPaid.Text));
            LoadingStatus        = 0;
        }
Esempio n. 5
0
        public static PawnSpan GetPawnSpan(DateTime iStartDate, DateTime iEndDate)
        {
            DateTime StartDate, EndDate;

            if (iStartDate > iEndDate)
            {
                EndDate   = iStartDate;
                StartDate = iEndDate;
            }
            else
            {
                StartDate = iStartDate;
                EndDate   = iEndDate;
            }



            PawnSpan Result = new PawnSpan();

            int LastMonthDay = 0;

            if (EndDate.Month != 1)
            {
                LastMonthDay = CaculateDaysByMonth(EndDate.Year, EndDate.Month - 1);
            }
            else
            {
                LastMonthDay = CaculateDaysByMonth(EndDate.Year, 12);
            }


            Result.Months = (EndDate.Month - StartDate.Month) + (EndDate.Year - StartDate.Year) * 12;


            if (StartDate.Day != DateTime.DaysInMonth(StartDate.Year, StartDate.Month) || EndDate.Day != DateTime.DaysInMonth(EndDate.Year, EndDate.Month))
            {
                if (EndDate.Day < StartDate.Day)
                {
                    Result.Days   = LastMonthDay - StartDate.Day + EndDate.Day;
                    Result.Months = Result.Months - 1;
                }
                else
                {
                    Result.Days = EndDate.Day - StartDate.Day;
                }
            }


            #region CountDays 计算

            switch (MainForm.CountDayMode)
            {
            case 0:
                if (Result.Days == 0)
                {
                    Result.CountDays = 0;
                }
                else if (Result.Days <= 5)
                {
                    Result.CountDays = 5;
                }
                else if (Result.Days <= 15)
                {
                    Result.CountDays = 15;
                }
                else
                {
                    Result.CountDays = 0;
                    Result.Months++;
                }

                if (Result.Months == 0 && Result.Days == 0)
                {
                    Result.CountDays = 5;
                }
                break;

            case 1:
                Result.CountDays = Result.Days;
                break;
            }

            #endregion


            //计算整个天数

            Result.CountDaysAll = Result.Months * 30 + Result.CountDays;

            Result.DaysAll = EndDate.Subtract(StartDate).Days;


            return(Result);
        }
        private void LoadTicketInfo()
        {
            this.m_GridTable.Rows.Clear();

            DDPawnTicket newTicket = new DDPawnTicket("TicketID", m_TicketID);

            Query queryOperations = new Query(DDOperation.Schema);

            queryOperations.AddWhere("TicketID", m_TicketID);
            queryOperations.AddWhere("OperationType", Comparison.In, new int[] { 1, 3 });
            queryOperations.AddWhere("OperationType", Comparison.NotEquals, 6);
            queryOperations.AddWhere("NextOperationID", 0);

            DataTable dtOperations = queryOperations.ExecuteDataSet().Tables[0];

            m_StartDate = Convert.ToDateTime(newTicket.StartDate);
            m_EndDate   = Convert.ToDateTime(newTicket.EndDate);
            try
            {
                m_OperationDate = Convert.ToDateTime(this.tbxOperationDate.Text.Trim());
            }
            catch
            {
                MessageBox.Show("请输入正确的日期", "提示信息");
            }

            if (dtOperations.Rows.Count > 0)
            {
                for (int i = 0; i < dtOperations.Rows.Count; i++)
                {
                    double amount = 0;
                    double serviceFee = 0, interestFee = 0, paidInterestFee = 0;
                    double chargedServiceFee = 0, chargedInterestFee = 0;
                    double singleChargedServiceFee = 0, singleChargedInterestFee = 0;
                    double returnServiceFee = 0, returnInterestFee = 0;
                    double singleReturnServiceFee = 0, singleReturnInterestFee = 0;
                    double serviceFeeRate = 0, interestFeeRate = 0;

                    double overdueFee = 0;
                    amount = Convert.ToDouble(dtOperations.Rows[i]["Amount"]);
                    #region 原先错误的算法

                    /*
                     * Query queryRenewPawn = new Query(DDOperation.Schema);
                     * queryRenewPawn.AddWhere("TicketID",m_TicketID);
                     * queryRenewPawn.AddWhere("PawnageID",Convert.ToInt32(dtOperations.Rows[i]["PawnageID"]));
                     * queryRenewPawn.AddWhere("OperationType",3);
                     * DataTable dtRenewPawn = queryRenewPawn.ExecuteDataSet().Tables[0];
                     * if (dtRenewPawn.Rows.Count > 0)
                     * {
                     *  for (int j = 0; j < dtRenewPawn.Rows.Count; j++)
                     *  {
                     *      serviceFee += Convert.ToDouble(dtRenewPawn.Rows[j]["ServiceFee"]);
                     *      interestFee += Convert.ToDouble(dtRenewPawn.Rows[j]["InterestFee"]);
                     *  }
                     * }
                     *
                     * totalServiceFee += serviceFee;
                     * totalInterestFee += interestFee;
                     * //overdueFee = CaculateOverdueFee(amount, Convert.ToDouble(pawnageInfo.FeeRate), Convert.ToDouble(pawnageInfo.InterestRate))
                     * //returnFee = serviceFee + interestFee - CaculatePaidFee(amount, Convert.ToDouble(pawnageInfo.FeeRate), Convert.ToDouble(pawnageInfo.InterestRate));
                     * //returnFee = CaculateReturnFee(amount, Convert.ToDouble(pawnageInfo.FeeRate), Convert.ToDouble(pawnageInfo.InterestRate));
                     * if (returnFee < 0)
                     * {
                     *  returnFee = 0;
                     * }
                     * totalOverdueFee += overdueFee;
                     * totalReturnFee += returnFee;
                     */
                    #endregion

                    DDPawnageInfo pawnageInfo = new DDPawnageInfo("PawnageID", Convert.ToInt32(dtOperations.Rows[i]["PawnageID"]));

                    #region 费用计算
                    //判断当票状态
                    int PawnTicketStatus = 0;  //0:正好,1:提前,2:过期

                    //DDPawnTicket theTicket = new DDPawnTicket("TicketID", m_TicketID);
                    if (m_OperationDate <= DateTime.Parse(dtOperations.Rows[i]["EndDate"].ToString()))
                    {
                        PawnSpan Span     = DianDangFunction.GetPawnSpan(m_OperationDate, DateTime.Parse(dtOperations.Rows[i]["StartDate"].ToString()));
                        PawnSpan LastSpan = DianDangFunction.GetPawnSpan(DateTime.Parse(dtOperations.Rows[i]["StartDate"].ToString()), DateTime.Parse(dtOperations.Rows[i]["EndDate"].ToString()));
                        if (Span.Months == LastSpan.Months && Span.CountDays == LastSpan.CountDays && m_OperationDate >= DateTime.Parse(dtOperations.Rows[i]["StartDate"].ToString()))
                        {
                            PawnTicketStatus = 0;
                        }
                        else
                        {
                            PawnTicketStatus = 1;
                        }
                    }
                    else
                    {
                        PawnTicketStatus = 2;
                    }


                    if (DateTime.Parse(newTicket.StartDate) == m_OperationDate)//当天建当,当天还
                    {
                        int ifReturn = 0;

                        double InOperationServiceFee = 0, InOperationInterestFee = 0;
                        double InOPerationChargedServiceFee = 0, InOperationChargedInterestFee = 0;

                        //总计征收的费用
                        Query queryPaidOperation = new Query(DDOperation.Schema);
                        queryPaidOperation.AddWhere("PawnageID", pawnageInfo.PawnageID);
                        queryPaidOperation.AddWhere("OperationType", Comparison.NotEquals, 6);
                        queryPaidOperation.AddWhere("Deleted", 0);
                        DataTable dtPaidOperation = queryPaidOperation.ExecuteDataSet().Tables[0];
                        for (int j = 0; j < dtPaidOperation.Rows.Count; j++)
                        {
                            singleChargedServiceFee  = Convert.ToDouble(dtPaidOperation.Rows[j]["ServiceFee"].ToString());
                            singleChargedServiceFee  = DianDangFunction.myRound(singleChargedServiceFee, MainForm.AmountAccuracy);
                            chargedServiceFee       += singleChargedServiceFee;
                            singleChargedInterestFee = Convert.ToDouble(dtPaidOperation.Rows[j]["InterestFee"].ToString());
                            singleChargedInterestFee = DianDangFunction.myRound(singleChargedInterestFee, MainForm.AmountAccuracy);
                            chargedInterestFee      += singleChargedInterestFee;
                        }

                        //计算争议的服务费
                        Query queryInOperation = new Query(DDOperation.Schema);
                        queryInOperation.AddBetweenAnd("EndDate", m_OperationDate, new DateTime(9998, 12, 31));
                        queryInOperation.AddBetweenAnd("StartDate", new DateTime(1755, 1, 1), m_OperationDate);
                        queryInOperation.AddWhere("PawnageID", pawnageInfo.PawnageID);
                        queryInOperation.AddWhere("OperationType", Comparison.NotEquals, 6);
                        queryInOperation.AddWhere("Deleted", 0);
                        DataTable dtInOperation = queryInOperation.ExecuteDataSet().Tables[0];
                        if (dtInOperation.Rows.Count > 0)
                        {
                            InOPerationChargedServiceFee = Convert.ToDouble(dtInOperation.Rows[0]["ServiceFee"].ToString());

                            PawnSpan OperationSpan = DianDangFunction.GetPawnSpan(DateTime.Parse(dtInOperation.Rows[0]["StartDate"].ToString()), DateTime.Parse(dtInOperation.Rows[0]["EndDate"].ToString()));
                            PawnSpan Span          = DianDangFunction.GetPawnSpan(DateTime.Parse(dtInOperation.Rows[0]["StartDate"].ToString()), m_OperationDate);
                            double   DayFeeRate    = InOPerationChargedServiceFee / OperationSpan.CountDaysAll / amount * 100;

                            if (Span.CountDaysAll > OperationSpan.CountDaysAll)
                            {
                                Span.CountDaysAll = OperationSpan.CountDaysAll;
                            }
                            InOperationServiceFee = (Span.CountDaysAll) * amount * DayFeeRate / 100;
                            InOperationServiceFee = DianDangFunction.myRound(InOperationServiceFee, MainForm.AmountAccuracy);
                        }

                        //计算肯定要返还的费用
                        Query queryReturnOperation = new Query(DDOperation.Schema);
                        queryReturnOperation.AddBetweenAnd("StartDate", m_OperationDate.AddDays(1), new DateTime(9998, 12, 31));
                        queryReturnOperation.AddWhere("PawnageID", pawnageInfo.PawnageID);
                        queryReturnOperation.AddWhere("OperationType", Comparison.NotEquals, 6);
                        queryReturnOperation.AddWhere("Deleted", 0);
                        DataTable dtReturnOperation = queryReturnOperation.ExecuteDataSet().Tables[0];
                        for (int j = 0; j < dtReturnOperation.Rows.Count; j++)
                        {
                            //计算争议的利息费,因为本次收取的利息为上月利息,即为争议利息
                            if (j == 0 && dtInOperation.Rows.Count > 0)
                            {
                                InOperationChargedInterestFee = Convert.ToDouble(dtReturnOperation.Rows[0]["InterestFee"].ToString());
                                PawnSpan OperationSpan = DianDangFunction.GetPawnSpan(DateTime.Parse(dtInOperation.Rows[0]["StartDate"].ToString()), DateTime.Parse(dtInOperation.Rows[0]["EndDate"].ToString()));
                                PawnSpan Span          = DianDangFunction.GetPawnSpan(DateTime.Parse(dtInOperation.Rows[0]["StartDate"].ToString()), m_OperationDate);

                                double DayInterestFeeRate = InOperationChargedInterestFee / OperationSpan.CountDaysAll / amount * 100;
                                if (Span.CountDaysAll > OperationSpan.CountDaysAll)
                                {
                                    Span.CountDaysAll = OperationSpan.CountDaysAll;
                                }
                                InOperationInterestFee = (Span.CountDaysAll) * amount * DayInterestFeeRate / 100;
                                InOperationInterestFee = DianDangFunction.myRound(InOperationInterestFee, MainForm.AmountAccuracy);
                            }


                            ifReturn++;
                            singleReturnServiceFee = Convert.ToDouble(dtReturnOperation.Rows[j]["ServiceFee"].ToString());
                            singleReturnServiceFee = DianDangFunction.myRound(singleReturnServiceFee, MainForm.AmountAccuracy);
                            returnServiceFee      += singleReturnServiceFee;
                            if (j != 0 || dtInOperation.Rows.Count == 0)
                            {
                                singleReturnInterestFee = Convert.ToDouble(dtReturnOperation.Rows[j]["InterestFee"].ToString());
                                singleReturnInterestFee = DianDangFunction.myRound(singleReturnInterestFee, MainForm.AmountAccuracy);
                                returnInterestFee      += singleReturnInterestFee;
                            }
                        }



                        if (m_OperationDate > DateTime.Parse(dtOperations.Rows[i]["StartDate"].ToString())) //操作日期大于最后一次操作开始日期,则收取利息
                        {
                            PawnSpan Span = DianDangFunction.GetPawnSpan(DateTime.Parse(dtOperations.Rows[i]["StartDate"].ToString()), m_OperationDate);
                            paidInterestFee = 0;
                            paidInterestFee = (Span.Months + Span.Days / 30) * Convert.ToDouble(dtOperations.Rows[i]["InterestFeeRate"].ToString()) * amount / 100;
                            paidInterestFee = DianDangFunction.myRound(paidInterestFee, MainForm.AmountAccuracy);
                        }



                        returnServiceFee  = returnServiceFee + InOPerationChargedServiceFee - InOperationServiceFee;
                        returnServiceFee  = DianDangFunction.myRound(returnServiceFee, MainForm.AmountAccuracy);
                        returnInterestFee = returnInterestFee + InOperationChargedInterestFee - InOperationInterestFee;
                        returnInterestFee = DianDangFunction.myRound(returnInterestFee, MainForm.AmountAccuracy);


                        serviceFee  = chargedServiceFee - returnServiceFee;
                        serviceFee  = DianDangFunction.myRound(serviceFee, MainForm.AmountAccuracy);
                        interestFee = chargedInterestFee + paidInterestFee - returnInterestFee;
                        interestFee = DianDangFunction.myRound(interestFee, MainForm.AmountAccuracy);
                    }

                    else
                    {
                        if (PawnTicketStatus == 0)  //收取上期服务费
                        {
                            //计算上期利息
                            PawnSpan LastSpan = DianDangFunction.GetPawnSpan(DateTime.Parse(dtOperations.Rows[i]["StartDate"].ToString()), DateTime.Parse(dtOperations.Rows[i]["EndDate"].ToString()));
                            paidInterestFee = (LastSpan.Months + LastSpan.CountDays / 30) * amount * Convert.ToDouble(dtOperations.Rows[i]["InterestFeeRate"].ToString()) / 100;
                            paidInterestFee = DianDangFunction.myRound(paidInterestFee, MainForm.AmountAccuracy);

                            //计算已经付出的服务费和利息
                            Query queryPaidOperation = new Query(DDOperation.Schema);
                            queryPaidOperation.AddWhere("TicketID", m_TicketID);
                            queryPaidOperation.AddWhere("PawnageID", pawnageInfo.PawnageID);
                            queryPaidOperation.AddWhere("OperationType", Comparison.NotEquals, 6);
                            queryPaidOperation.AddWhere("Deleted", 0);
                            DataTable dtPaidOperation = queryPaidOperation.ExecuteDataSet().Tables[0];
                            if (dtPaidOperation.Rows.Count > 0)
                            {
                                for (int j = 0; j < dtPaidOperation.Rows.Count; j++)
                                {
                                    singleChargedServiceFee  = Convert.ToDouble(dtPaidOperation.Rows[j]["ServiceFee"].ToString());
                                    singleChargedServiceFee  = DianDangFunction.myRound(singleChargedServiceFee, MainForm.AmountAccuracy);
                                    chargedServiceFee       += singleChargedServiceFee;
                                    singleChargedInterestFee = Convert.ToDouble(dtPaidOperation.Rows[j]["InterestFee"].ToString());
                                    singleChargedInterestFee = DianDangFunction.myRound(singleChargedInterestFee, MainForm.AmountAccuracy);
                                    chargedInterestFee      += singleChargedInterestFee;
                                }
                            }

                            //当品应收的利息等于之前收过的利息+上期利息
                            interestFee = chargedInterestFee + paidInterestFee;
                            serviceFee  = chargedServiceFee;
                        }
                        else if (PawnTicketStatus == 2)  //过期状态,收取
                        {
                            //计算上期利息+过期利息,计算过期服务费
                            PawnSpan LastSpan = DianDangFunction.GetPawnSpan(DateTime.Parse(dtOperations.Rows[i]["StartDate"].ToString()), m_OperationDate);
                            paidInterestFee = (LastSpan.Months + LastSpan.CountDays / 30) * amount * Convert.ToDouble(dtOperations.Rows[i]["InterestFeeRate"].ToString()) / 100;
                            paidInterestFee = DianDangFunction.myRound(paidInterestFee, MainForm.AmountAccuracy);

                            PawnSpan OverdueSpan = DianDangFunction.GetPawnSpan(DateTime.Parse(dtOperations.Rows[i]["EndDate"].ToString()), m_OperationDate);
                            overdueFee = (OverdueSpan.Months + OverdueSpan.CountDays / 30) * amount * Convert.ToDouble(dtOperations.Rows[i]["ServiceFeeRate"].ToString()) / 100;
                            overdueFee = DianDangFunction.myRound(overdueFee, MainForm.AmountAccuracy);


                            //计算已经付出的服务费和利息
                            Query queryPaidOperation = new Query(DDOperation.Schema);
                            queryPaidOperation.AddWhere("TicketID", m_TicketID);
                            queryPaidOperation.AddWhere("PawnageID", pawnageInfo.PawnageID);
                            queryPaidOperation.AddWhere("OperationType", Comparison.NotEquals, 6);
                            queryPaidOperation.AddWhere("Deleted", 0);
                            DataTable dtPaidOperation = queryPaidOperation.ExecuteDataSet().Tables[0];
                            if (dtPaidOperation.Rows.Count > 0)
                            {
                                for (int j = 0; j < dtPaidOperation.Rows.Count; j++)
                                {
                                    singleChargedServiceFee  = Convert.ToDouble(dtPaidOperation.Rows[j]["ServiceFee"].ToString());
                                    singleChargedServiceFee  = DianDangFunction.myRound(singleChargedServiceFee, MainForm.AmountAccuracy);
                                    chargedServiceFee       += singleChargedServiceFee;
                                    singleChargedInterestFee = Convert.ToDouble(dtPaidOperation.Rows[j]["InterestFee"].ToString());
                                    singleChargedInterestFee = DianDangFunction.myRound(singleChargedInterestFee, MainForm.AmountAccuracy);
                                    chargedInterestFee      += singleChargedInterestFee;
                                }
                            }

                            //当品应收的利息等于之前收过的利息+应付利息
                            interestFee = chargedInterestFee + paidInterestFee;
                            //服务费应该等于所有已经收取的服务费+过期服务费
                            serviceFee = chargedServiceFee + overdueFee;
                        }
                        else if (PawnTicketStatus == 1)  //提前赎当
                        {
                            int ifReturn = 0;

                            double InOperationServiceFee = 0, InOperationInterestFee = 0;
                            double InOPerationChargedServiceFee = 0, InOperationChargedInterestFee = 0;

                            //总计征收的费用
                            Query queryPaidOperation = new Query(DDOperation.Schema);
                            queryPaidOperation.AddWhere("PawnageID", pawnageInfo.PawnageID);
                            queryPaidOperation.AddWhere("OperationType", Comparison.NotEquals, 6);
                            queryPaidOperation.AddWhere("Deleted", 0);
                            DataTable dtPaidOperation = queryPaidOperation.ExecuteDataSet().Tables[0];
                            for (int j = 0; j < dtPaidOperation.Rows.Count; j++)
                            {
                                singleChargedServiceFee  = Convert.ToDouble(dtPaidOperation.Rows[j]["ServiceFee"].ToString());
                                singleChargedServiceFee  = DianDangFunction.myRound(singleChargedServiceFee, MainForm.AmountAccuracy);
                                chargedServiceFee       += singleChargedServiceFee;
                                singleChargedInterestFee = Convert.ToDouble(dtPaidOperation.Rows[j]["InterestFee"].ToString());
                                singleChargedInterestFee = DianDangFunction.myRound(singleChargedInterestFee, MainForm.AmountAccuracy);
                                chargedInterestFee      += singleChargedInterestFee;
                            }

                            //计算争议的服务费
                            Query queryInOperation = new Query(DDOperation.Schema);
                            queryInOperation.AddBetweenAnd("EndDate", m_OperationDate.AddDays(1), new DateTime(9998, 12, 31));
                            queryInOperation.AddBetweenAnd("StartDate", new DateTime(1755, 1, 1), m_OperationDate.AddDays(-1));
                            queryInOperation.AddWhere("PawnageID", pawnageInfo.PawnageID);
                            queryInOperation.AddWhere("OperationType", Comparison.NotEquals, 6);
                            queryInOperation.AddWhere("Deleted", 0);
                            DataTable dtInOperation = queryInOperation.ExecuteDataSet().Tables[0];
                            if (dtInOperation.Rows.Count > 0)
                            {
                                InOPerationChargedServiceFee = Convert.ToDouble(dtInOperation.Rows[0]["ServiceFee"].ToString());

                                PawnSpan OperationSpan = DianDangFunction.GetPawnSpan(DateTime.Parse(dtInOperation.Rows[0]["StartDate"].ToString()), DateTime.Parse(dtInOperation.Rows[0]["EndDate"].ToString()));
                                PawnSpan Span          = DianDangFunction.GetPawnSpan(DateTime.Parse(dtInOperation.Rows[0]["StartDate"].ToString()), m_OperationDate);
                                double   DayFeeRate    = InOPerationChargedServiceFee / OperationSpan.CountDaysAll / amount * 100;

                                if (Span.CountDaysAll > OperationSpan.CountDaysAll)
                                {
                                    Span.CountDaysAll = OperationSpan.CountDaysAll;
                                }
                                InOperationServiceFee = (Span.CountDaysAll) * amount * DayFeeRate / 100;
                                InOperationServiceFee = DianDangFunction.myRound(InOperationServiceFee, MainForm.AmountAccuracy);
                            }

                            //计算肯定要返还的费用
                            Query queryReturnOperation = new Query(DDOperation.Schema);
                            queryReturnOperation.AddBetweenAnd("StartDate", m_OperationDate, new DateTime(9998, 12, 31));
                            queryReturnOperation.AddWhere("PawnageID", pawnageInfo.PawnageID);
                            queryReturnOperation.AddWhere("OperationType", Comparison.NotEquals, 6);
                            queryReturnOperation.AddWhere("Deleted", 0);
                            DataTable dtReturnOperation = queryReturnOperation.ExecuteDataSet().Tables[0];
                            for (int j = 0; j < dtReturnOperation.Rows.Count; j++)
                            {
                                //计算争议的利息费,因为本次收取的利息为上月利息,即为争议利息
                                if (j == 0 && dtInOperation.Rows.Count > 0)
                                {
                                    InOperationChargedInterestFee = Convert.ToDouble(dtReturnOperation.Rows[0]["InterestFee"].ToString());
                                    PawnSpan OperationSpan = DianDangFunction.GetPawnSpan(DateTime.Parse(dtInOperation.Rows[0]["StartDate"].ToString()), DateTime.Parse(dtInOperation.Rows[0]["EndDate"].ToString()));
                                    PawnSpan Span          = DianDangFunction.GetPawnSpan(DateTime.Parse(dtInOperation.Rows[0]["StartDate"].ToString()), m_OperationDate);

                                    double DayInterestFeeRate = InOperationChargedInterestFee / OperationSpan.CountDaysAll / amount * 100;
                                    if (Span.CountDaysAll > OperationSpan.CountDaysAll)
                                    {
                                        Span.CountDaysAll = OperationSpan.CountDaysAll;
                                    }
                                    InOperationInterestFee = (Span.CountDaysAll) * amount * DayInterestFeeRate / 100;
                                    InOperationInterestFee = DianDangFunction.myRound(InOperationInterestFee, MainForm.AmountAccuracy);
                                }


                                ifReturn++;
                                singleReturnServiceFee = Convert.ToDouble(dtReturnOperation.Rows[j]["ServiceFee"].ToString());
                                singleReturnServiceFee = DianDangFunction.myRound(singleReturnServiceFee, MainForm.AmountAccuracy);
                                returnServiceFee      += singleReturnServiceFee;
                                if (j != 0 || dtInOperation.Rows.Count == 0)
                                {
                                    singleReturnInterestFee = Convert.ToDouble(dtReturnOperation.Rows[j]["InterestFee"].ToString());
                                    singleReturnInterestFee = DianDangFunction.myRound(singleReturnInterestFee, MainForm.AmountAccuracy);
                                    returnInterestFee      += singleReturnInterestFee;
                                }
                            }



                            if (m_OperationDate > DateTime.Parse(dtOperations.Rows[i]["StartDate"].ToString())) //操作日期大于最后一次操作开始日期,则收取利息
                            {
                                PawnSpan Span = DianDangFunction.GetPawnSpan(DateTime.Parse(dtOperations.Rows[i]["StartDate"].ToString()), m_OperationDate);
                                paidInterestFee = 0;
                                paidInterestFee = (Span.Months + Span.Days / 30) * Convert.ToDouble(dtOperations.Rows[i]["InterestFeeRate"].ToString()) * amount / 100;
                                paidInterestFee = DianDangFunction.myRound(paidInterestFee, MainForm.AmountAccuracy);
                            }



                            returnServiceFee  = returnServiceFee + InOPerationChargedServiceFee - InOperationServiceFee;
                            returnServiceFee  = DianDangFunction.myRound(returnServiceFee, MainForm.AmountAccuracy);
                            returnInterestFee = returnInterestFee + InOperationChargedInterestFee - InOperationInterestFee;
                            returnInterestFee = DianDangFunction.myRound(returnInterestFee, MainForm.AmountAccuracy);


                            serviceFee  = chargedServiceFee - returnServiceFee;
                            serviceFee  = DianDangFunction.myRound(serviceFee, MainForm.AmountAccuracy);
                            interestFee = chargedInterestFee + paidInterestFee - returnInterestFee;
                            interestFee = DianDangFunction.myRound(interestFee, MainForm.AmountAccuracy);
                        }
                    }



                    //Query queryOperation = new Query(DDOperation.Schema);
                    //queryOperations.AddWhere("TicketID", m_TicketID);

                    #endregion

                    serviceFeeRate  = Convert.ToDouble(dtOperations.Rows[i]["ServiceFeeRate"].ToString());
                    interestFeeRate = Convert.ToDouble(dtOperations.Rows[i]["InterestFeeRate"].ToString());

                    interestFee        = DianDangFunction.myRound(interestFee, MainForm.AmountAccuracy);
                    serviceFee         = DianDangFunction.myRound(serviceFee, MainForm.AmountAccuracy);
                    amount             = DianDangFunction.myRound(amount, MainForm.AmountAccuracy);
                    returnServiceFee   = DianDangFunction.myRound(returnServiceFee, MainForm.AmountAccuracy);
                    returnInterestFee  = DianDangFunction.myRound(returnInterestFee, MainForm.AmountAccuracy);
                    overdueFee         = DianDangFunction.myRound(overdueFee, MainForm.AmountAccuracy);
                    paidInterestFee    = DianDangFunction.myRound(paidInterestFee, MainForm.AmountAccuracy);
                    chargedServiceFee  = DianDangFunction.myRound(chargedServiceFee, MainForm.AmountAccuracy);
                    chargedInterestFee = DianDangFunction.myRound(chargedInterestFee, MainForm.AmountAccuracy);


                    DataRow        drow         = m_GridTable.NewRow();
                    DDPawnageClass pawnageClass = new DDPawnageClass("ClassID", pawnageInfo.ClassID);
                    drow["ClassName"]          = pawnageClass.ClassName;
                    drow["Amount"]             = amount;
                    drow["ServiceFee"]         = serviceFee;
                    drow["InterestFee"]        = interestFee;
                    drow["ReturnFee"]          = returnServiceFee;
                    drow["ReturnInterestFee"]  = returnInterestFee;
                    drow["OverdueFee"]         = overdueFee;
                    drow["PaidInterestFee"]    = paidInterestFee;
                    drow["ChargedServiceFee"]  = chargedServiceFee;
                    drow["ChargedInterestFee"] = chargedInterestFee;
                    drow["PawnageID"]          = dtOperations.Rows[i]["PawnageID"].ToString();
                    drow["ServiceFeeRate"]     = serviceFeeRate;
                    drow["InterestFeeRate"]    = interestFeeRate;
                    m_GridTable.Rows.Add(drow);
                }
            }


            this.dataGridView1.DataSource = m_GridTable;
            CaculateDatagridAmount();
        }
Esempio n. 7
0
        private void UpdateOperation()
        {
            try
            {
                if (dataGridView1.Rows.Count > 0)
                {
                    DDPawnTicket newTicket = new DDPawnTicket("TicketID", m_TicketID);

                    newTicket.StatusID = 3;  //3:续当
                    newTicket.EndDate  = this.tbxEndDate.Text;
                    newTicket.Save();

                    int iPawnageID     = 0;
                    int preOperationID = 0;

                    PawnSpan Span = new PawnSpan();
                    Span = DianDangFunction.GetPawnSpan(DateTime.Parse(tbxStartDate.Text), DateTime.Parse(tbxEndDate.Text));

                    for (int i = dataGridView1.Rows.Count - 1; i > -1; i--)
                    {
                        DataGridViewRow dgr = dataGridView1.Rows[i];

                        iPawnageID = Convert.ToInt32(dgr.Cells["PawnageID"].Value);
                        DDPawnageInfo newInfo = new DDPawnageInfo("PawnageID", iPawnageID);


                        preOperationID = Convert.ToInt32(dgr.Cells["OperationID"].Value);
                        DDOperation newOperation = new DDOperation();
                        newOperation.TicketID        = m_TicketID;
                        newOperation.PawnageID       = iPawnageID;
                        newOperation.OperationType   = 3; //3 :续当
                        newOperation.OperationNumber = m_OperationNumber;
                        newOperation.ServiceFee      = dataGridView1.Rows[i].Cells["ServiceFee"].Value.ToString();
                        newOperation.InterestFee     = dataGridView1.Rows[i].Cells["InterestFee"].Value.ToString();
                        newOperation.ReturnFee       = "0";
                        newOperation.OverdueFee      = "0";
                        newOperation.Amount          = dgr.Cells["Amount"].Value.ToString();
                        newOperation.ReckonAmount    = "0";
                        newOperation.OperationDate   = this.tbxOperationDate.Text;
                        newOperation.StartDate       = this.tbxStartDate.Text;
                        newOperation.EndDate         = this.tbxEndDate.Text;
                        DDUser newOperater = new DDUser("AccountName", MainForm.AccountName);
                        newOperation.OperaterName    = newOperater.UserName;
                        newOperation.PreOperationID  = preOperationID;
                        newOperation.ServiceFeeRate  = dgr.Cells["FeeRate"].Value.ToString();
                        newOperation.InterestFeeRate = dgr.Cells["InterestRate"].Value.ToString();
                        newOperation.NextOperationID = 0;
                        newOperation.Deleted         = 0;
                        newOperation.Save();

                        DDOperation oldOperation = new DDOperation("OperationID", preOperationID);
                        oldOperation.NextOperationID = newOperation.OperationID;
                        oldOperation.Save();

                        newInfo.FeeRate      = dgr.Cells["FeeRate"].Value.ToString();
                        newInfo.InterestRate = dgr.Cells["InterestRate"].Value.ToString();
                        newInfo.EndDate      = this.tbxEndDate.Text;
                        newInfo.StatusID     = 3; //续当
                        newInfo.Save();
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 8
0
        public static PawnSpan GetPawnSpan(DateTime iStartDate, DateTime iEndDate, FeeType iFeeType, PeridType iPeridType)
        {
            DateTime StartDate, EndDate;

            if (iStartDate > iEndDate)
            {
                EndDate   = iStartDate;
                StartDate = iEndDate;
            }
            else
            {
                StartDate = iStartDate;
                EndDate   = iEndDate;
            }



            PawnSpan Result = new PawnSpan();

            int LastMonthDay = 0;

            if (EndDate.Month != 1)
            {
                LastMonthDay = CaculateDaysByMonth(EndDate.Year, EndDate.Month - 1);
            }
            else
            {
                LastMonthDay = CaculateDaysByMonth(EndDate.Year, 12);
            }


            Result.Months = (EndDate.Month - StartDate.Month) + (EndDate.Year - StartDate.Year) * 12;


            if (StartDate.Day != DateTime.DaysInMonth(StartDate.Year, StartDate.Month) || EndDate.Day != DateTime.DaysInMonth(EndDate.Year, EndDate.Month))
            {
                if (EndDate.Day < StartDate.Day)
                {
                    Result.Days   = LastMonthDay - StartDate.Day + EndDate.Day;
                    Result.Months = Result.Months - 1;
                }
                else
                {
                    Result.Days = EndDate.Day - StartDate.Day;
                }
            }


            #region CountDays 计算

            int[] CountValue = CaculateCountDays(Result.Days, Result.Months);

            switch (iPeridType)
            {
            case PeridType.Within:
                switch (iFeeType)
                {
                case FeeType.ServiceFee:
                    switch ((int)(MainForm.CountDayMode / 2))
                    {
                    case 0:
                        Result.CountDays = CountValue[0];
                        Result.Months   += CountValue[1];
                        break;

                    case 1:
                        Result.CountDays = Result.Days;
                        break;
                    }
                    break;

                case FeeType.InterestFee:
                    switch ((int)(MainForm.CountDayMode / 2))
                    {
                    case 0:
                        Result.CountDays = CountValue[0];
                        Result.Months   += CountValue[1];
                        break;

                    case 1:
                        Result.CountDays = Result.Days;
                        break;
                    }
                    break;
                }
                break;

            case PeridType.Overdue:
                switch (iFeeType)
                {
                case FeeType.ServiceFee:
                    switch ((int)(MainForm.CountDayMode % 2))
                    {
                    case 0:
                        Result.CountDays = CountValue[0];
                        Result.Months   += CountValue[1];
                        break;

                    case 1:
                        Result.CountDays = Result.Days;
                        break;
                    }
                    break;

                case FeeType.InterestFee:
                    switch ((int)(MainForm.CountDayMode % 2))
                    {
                    case 0:
                        Result.CountDays = CountValue[0];
                        Result.Months   += CountValue[1];
                        break;

                    case 1:
                        Result.CountDays = Result.Days;
                        break;
                    }
                    break;
                }
                break;
            }

            /*
             * switch ((int)(MainForm.CountDayMode / 2))
             * {
             *  case 0:
             *
             *      break;
             *  case 1:
             *      Result.CountDays = Result.Days;
             *      break;
             * }
             */

            #endregion


            //计算整个天数

            Result.CountDaysAll = Result.Months * 30 + Result.CountDays;

            Result.DaysAll = EndDate.Subtract(StartDate).Days;


            return(Result);
        }
Esempio n. 9
0
        public static PawnSpan GetPawnSpan(DateTime iStartDate, DateTime iEndDate)
        {
            DateTime StartDate, EndDate;

            if (iStartDate > iEndDate)
            {
                EndDate   = iStartDate;
                StartDate = iEndDate;
            }
            else
            {
                StartDate = iStartDate;
                EndDate   = iEndDate;
            }



            PawnSpan Result = new PawnSpan();

            int LastMonthDay = 0;

            if (EndDate.Month != 1)
            {
                LastMonthDay = CaculateDaysByMonth(EndDate.Year, EndDate.Month - 1);
            }
            else
            {
                LastMonthDay = CaculateDaysByMonth(EndDate.Year, 12);
            }


            Result.Months = (EndDate.Month - StartDate.Month) + (EndDate.Year - StartDate.Year) * 12;



            if (EndDate.Day < StartDate.Day)
            {
                Result.Days   = LastMonthDay - StartDate.Day + EndDate.Day;
                Result.Months = Result.Months - 1;
            }
            else
            {
                Result.Days = EndDate.Day - StartDate.Day;
            }


            if (Result.Days == 0)
            {
                Result.CountDays = 0;
            }
            else if (Result.Days <= 5)
            {
                Result.CountDays = 5;
            }
            else if (Result.Days <= 15)
            {
                Result.CountDays = 15;
            }
            else
            {
                Result.CountDays = 0;
                Result.Months++;
            }

            if (Result.Months == 0 && Result.Days == 0)
            {
                Result.CountDays = 5;
            }



            //计算整个天数

            Result.CountDaysAll = Result.Months * 30 + Result.CountDays;

            Result.DaysAll = EndDate.Subtract(StartDate).Days;


            return(Result);
        }