public List <Car_Leasings_Payment> getPaymentSchedule(string Leasing_id)
        {
            MySqlConnection con = MySQLConnection.connectionMySQL();

            try
            {
                con.Open();
                MySqlCommand cmd = new MySqlCommand("g_car_leasings_payment", con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@i_Leasing_id", Leasing_id);

                MySqlDataReader reader = cmd.ExecuteReader();

                List <Car_Leasings_Payment> list_cls_pay = new List <Car_Leasings_Payment>();

                while (reader.Read())
                {
                    Car_Leasings_Payment cls_pay = new Car_Leasings_Payment();
                    int    defaultNum            = 0;
                    string defaultString         = "";

                    cls_pay.Leasing_id            = reader.IsDBNull(0) ? defaultString : reader.GetString(0);
                    cls_pay.Period_no             = reader.IsDBNull(1) ? defaultNum : reader.GetInt32(1);
                    cls_pay.Period_schedule       = reader.IsDBNull(2) ? defaultString : reader.GetString(2);
                    cls_pay.Period_current        = reader.IsDBNull(3) ? defaultNum : reader.GetDouble(3);
                    cls_pay.Period_cash           = reader.IsDBNull(4) ? defaultNum : reader.GetDouble(4);
                    cls_pay.Period_value          = reader.IsDBNull(5) ? defaultNum : reader.GetDouble(5);
                    cls_pay.Period_principle      = reader.IsDBNull(6) ? defaultNum : reader.GetDouble(6);
                    cls_pay.Period_interst        = reader.IsDBNull(7) ? defaultNum : reader.GetDouble(7);
                    cls_pay.Period_vat            = reader.IsDBNull(8) ? defaultNum : reader.GetDouble(8);
                    cls_pay.Period_fine           = reader.IsDBNull(9) ? defaultNum : reader.GetDouble(9);
                    cls_pay.Total_Period_fine     = reader.IsDBNull(10) ? defaultNum : reader.GetDouble(10);
                    cls_pay.Total_Period_left     = reader.IsDBNull(11) ? defaultNum : reader.GetDouble(11);
                    cls_pay.Period_payment_status = reader.IsDBNull(12) ? defaultNum : reader.GetInt32(12);
                    cls_pay.Period_Save_Date      = reader.IsDBNull(13) ? defaultString : reader.GetString(13);

                    list_cls_pay.Add(cls_pay);
                }

                return(list_cls_pay);
            }
            catch (MySqlException ex)
            {
                error = "MysqlException ==> Managers_Leasings --> Car_Leasing_Payment_Manager --> getPaymentSchedule() ";
                Log_Error._writeErrorFile(error, ex);
                return(null);
            }
            catch (Exception ex)
            {
                error = "Exception ==> Managers_Leasings --> Car_Leasing_Payment_Manager --> getPaymentSchedule() ";
                Log_Error._writeErrorFile(error, ex);
                return(null);
            }
            finally
            {
                con.Close();
            }
        }
        public bool addPayment_Mod_III(Car_Leasings_Payment cls_pay, int type)
        {
            MySqlConnection con = MySQLConnection.connectionMySQL();

            try
            {
                con.Open();
                MySqlCommand cmd = new MySqlCommand("i_car_leasings_real_payment_mod_III", con);
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.AddWithValue("@i_Leasing_id", cls_pay.Leasing_id);
                cmd.Parameters.AddWithValue("@i_Period_free", cls_pay.Period_fee);
                cmd.Parameters.AddWithValue("@i_Period_track", cls_pay.Period_track);
                cmd.Parameters.AddWithValue("@i_Total_payment_fine", cls_pay.Total_payment_fine);
                cmd.Parameters.AddWithValue("@i_Discount", cls_pay.Discount);
                cmd.Parameters.AddWithValue("@i_Real_payment", cls_pay.Real_payment);
                cmd.Parameters.AddWithValue("@i_Bill_no", cls_pay.Bill_no);
                cmd.Parameters.AddWithValue("@i_Real_payment_date", cls_pay.Real_payment_date);
                cmd.Parameters.AddWithValue("@i_Account_id", cls_pay.acc_lgn.Account_id);
                cmd.Parameters.AddWithValue("@i_Company_Id", cls_pay.bs_cpn.Company_id);
                cmd.Parameters.AddWithValue("@i_Bill_no_manual_ref", cls_pay.Bill_no_manual_ref);
                cmd.Parameters.AddWithValue("@i_Type_Payment", type);

                cmd.ExecuteNonQuery();

                return(true);
            }
            catch (MySqlException ex)
            {
                error = "MysqlException ==> Managers_Leasings --> Car_Leasing_Payment_Manager --> addPayment_Mod_III() ";
                Log_Error._writeErrorFile(error, ex);
                return(false);
            }
            catch (Exception ex)
            {
                error = "Exception ==> Managers_Leasings --> Car_Leasings_Payment_Manager --> addPayment_Mod_III() ";
                Log_Error._writeErrorFile(error, ex);
                return(false);
            }
            finally
            {
                con.Close();
            }
        }
        private void _CheckLeasingPayment(string Leasing_id)
        {
            Car_Leasings_Manager         cls_mng      = new Car_Leasings_Manager();
            Car_Leasings_Payment_Manager cls_pay_mng  = new Car_Leasings_Payment_Manager();
            List <Car_Leasings_Payment>  list_cls_pay = cls_pay_mng.getPaymentSchedule(Leasing_id);

            if (list_cls_pay.Count > 0)
            {
                Car_Leasings_Payment cls_pay = list_cls_pay[0];

                if (string.IsNullOrEmpty(cls_pay.Real_payment_date))
                {
                    Payment_Schedule_DDL.Enabled   = true;
                    First_Payment_Date_TBx.Enabled = true;
                    Total_Require_TBx.Enabled      = true;
                    Interest_Rate_TBx.Enabled      = true;
                    Total_Period_TBx.Enabled       = true;
                    Vat_TBx.Enabled       = true;
                    Calculate_Btn.Enabled = true;
                }
                else
                {
                    Payment_Schedule_DDL.Enabled   = false;
                    First_Payment_Date_TBx.Enabled = false;
                    Total_Require_TBx.Enabled      = false;
                    Interest_Rate_TBx.Enabled      = false;
                    Total_Period_TBx.Enabled       = false;
                    Vat_TBx.Enabled       = false;
                    Calculate_Btn.Enabled = false;
                }
            }
            else
            {
                Payment_Schedule_DDL.Enabled   = true;
                First_Payment_Date_TBx.Enabled = true;
                Total_Require_TBx.Enabled      = true;
                Interest_Rate_TBx.Enabled      = true;
                Total_Period_TBx.Enabled       = true;
                Vat_TBx.Enabled       = true;
                Calculate_Btn.Enabled = true;
            }
        }
        public bool fixUpdtaeFine(Car_Leasings_Payment cls_pay)
        {
            MySqlConnection con = MySQLConnection.connectionMySQL();

            try
            {
                con.Open();
                MySqlCommand cmd = new MySqlCommand("s_fix_fine_amount", con);
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.AddWithValue("@i_Leasing_id", cls_pay.Leasing_id);
                cmd.Parameters.AddWithValue("@i_Total_payment_fine", cls_pay.Total_payment_fine);
                cmd.Parameters.AddWithValue("@i_Bill_no", cls_pay.Bill_no);
                cmd.Parameters.AddWithValue("@i_Real_payment_date", cls_pay.Real_payment_date);

                cmd.ExecuteNonQuery();

                return(true);
            }
            catch (MySqlException ex)
            {
                error = "MysqlException ==> Managers_Leasings --> Car_Leasing_Payment_Manager --> fixUpdtaeFine() ";
                Log_Error._writeErrorFile(error, ex);
                return(false);
            }
            catch (Exception ex)
            {
                error = "Exception ==> Managers_Leasings --> Car_Leasings_Payment_Manager --> fixUpdtaeFine() ";
                Log_Error._writeErrorFile(error, ex);
                return(false);
            }
            finally
            {
                con.Close();
            }
        }
        public List <Car_Leasings_Payment> getRealPaymentInfo(string Leasing_id)
        {
            MySqlConnection con = MySQLConnection.connectionMySQL();

            try
            {
                con.Open();
                MySqlCommand cmd = new MySqlCommand("g_car_leasings_payment_info", con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@i_Leasing_id", Leasing_id);

                MySqlDataReader reader = cmd.ExecuteReader();

                List <Car_Leasings_Payment> list_cls_pay = new List <Car_Leasings_Payment>();

                while (reader.Read())
                {
                    Car_Leasings_Payment cls_pay = new Car_Leasings_Payment();
                    int    defaultNum            = 0;
                    string defaultString         = "";

                    cls_pay.Leasing_id            = reader.IsDBNull(0) ? defaultString : reader.GetString(0);
                    cls_pay.Period_no             = reader.IsDBNull(1) ? defaultNum : reader.GetInt32(1);
                    cls_pay.Period_schedule       = reader.IsDBNull(2) ? defaultString : reader.GetString(2);
                    cls_pay.Period_current        = reader.IsDBNull(3) ? defaultNum : reader.GetDouble(3);
                    cls_pay.Period_cash           = reader.IsDBNull(4) ? defaultNum : reader.GetDouble(4);
                    cls_pay.Period_value          = reader.IsDBNull(5) ? defaultNum : reader.GetDouble(5);
                    cls_pay.Period_principle      = reader.IsDBNull(6) ? defaultNum : reader.GetDouble(6);
                    cls_pay.Period_interst        = reader.IsDBNull(7) ? defaultNum : reader.GetDouble(7);
                    cls_pay.Period_vat            = reader.IsDBNull(8) ? defaultNum : reader.GetDouble(8);
                    cls_pay.Period_fine           = reader.IsDBNull(9) ? defaultNum : reader.GetDouble(9);
                    cls_pay.Total_Period_fine     = reader.IsDBNull(10) ? defaultNum : reader.GetDouble(10);
                    cls_pay.Total_Period_left     = reader.IsDBNull(11) ? defaultNum : reader.GetDouble(11);
                    cls_pay.Period_payment_status = reader.IsDBNull(12) ? defaultNum : reader.GetInt32(12);
                    cls_pay.Period_Save_Date      = reader.IsDBNull(13) ? defaultString : reader.GetString(13);

                    cls_pay.Count_payment      = reader.IsDBNull(14) ? defaultNum : reader.GetInt32(14);
                    cls_pay.Period_fee         = reader.IsDBNull(15) ? defaultNum : reader.GetDouble(15);
                    cls_pay.Period_track       = reader.IsDBNull(16) ? defaultNum : reader.GetDouble(16);
                    cls_pay.Discount           = reader.IsDBNull(17) ? defaultNum : reader.GetDouble(17);
                    cls_pay.Real_payment       = reader.IsDBNull(18) ? defaultNum : reader.GetDouble(18);
                    cls_pay.Real_payment_fine  = reader.IsDBNull(19) ? defaultNum : reader.GetDouble(19);
                    cls_pay.Total_payment_fine = reader.IsDBNull(20) ? defaultNum : reader.GetDouble(20);
                    cls_pay.Total_payment_left = reader.IsDBNull(21) ? defaultNum : reader.GetDouble(21);
                    cls_pay.Bill_no            = reader.IsDBNull(22) ? defaultString : reader.GetString(22);
                    cls_pay.Real_payment_date  = reader.IsDBNull(23) ? defaultString : reader.GetString(23);
                    cls_pay.INN = reader.IsDBNull(24) ? defaultNum : reader.GetDouble(24);
                    cls_pay.TNC = reader.IsDBNull(25) ? defaultNum : reader.GetDouble(25);

                    cls_pay.acc_lgn                = new Account_Login();
                    cls_pay.acc_lgn.Account_id     = reader.IsDBNull(26) ? defaultString : reader.GetString(26);
                    cls_pay.acc_lgn.Account_F_name = reader.IsDBNull(27) ? defaultString : reader.GetString(27);

                    cls_pay.bs_cpn                     = new Base_Companys();
                    cls_pay.bs_cpn.Company_id          = reader.IsDBNull(28) ? defaultNum : reader.GetInt32(28);
                    cls_pay.bs_cpn.Company_N_name      = reader.IsDBNull(29) ? defaultString : reader.GetString(29);
                    cls_pay.bs_cpn.Company_F_name      = reader.IsDBNull(30) ? defaultString : reader.GetString(30);
                    cls_pay.bs_cpn.Company_tax_id      = reader.IsDBNull(31) ? defaultString : reader.GetString(31);
                    cls_pay.bs_cpn.Company_tax_subcode = reader.IsDBNull(32) ? defaultString : reader.GetString(32);
                    cls_pay.bs_cpn.Company_province    = reader.IsDBNull(33) ? defaultString : reader.GetString(33);

                    cls_pay.Bill_no_manual_ref = reader.IsDBNull(34) ? defaultString : reader.GetString(34);
                    cls_pay.Payment_save_date  = reader.IsDBNull(35) ? defaultString : reader.GetString(35);

                    list_cls_pay.Add(cls_pay);
                }

                return(list_cls_pay);
            }
            catch (MySqlException ex)
            {
                error = "MysqlException ==> Managers_Leasings --> Car_Leasing_Payment_Manager --> getRealPaymentInfo() ";
                Log_Error._writeErrorFile(error, ex);
                return(null);
            }
            catch (Exception ex)
            {
                error = "Exception ==> Managers_Leasings --> Car_Leasing_Payment_Manager --> getRealPaymentInfo() ";
                Log_Error._writeErrorFile(error, ex);
                return(null);
            }
            finally
            {
                con.Close();
            }
        }
        private void _loadLeasingDetails(string leasing_id, string idcard, string bill_no)
        {
            cls = cls_mng.getCarLeasingById(leasing_id);

            Leasing_Date_TBx.Text = DateTimeUtility.convertDateToPageRealServer(cls.Leasing_date);
            Deps_No_TBx.Text      = cls.Deps_no;
            Leasing_No_TBx.Text   = cls.Leasing_no;

            Leasing_Comments_Lbl.Text = cls.Leasing_Comment;

            bs_cpn = bs_cpn_mng.getCompanysById(cls.bs_cpn.Company_id.ToString());

            Company_N_Name_TBx.Text = bs_cpn.Company_N_name;
            Company_F_Name_TBx.Text = bs_cpn.Company_F_name;

            bs_zn = bs_zn_mng.getZoneById(cls.bs_zn.Zone_id);

            Zone_Name_TBx.Text = bs_zn.Zone_code + " " + bs_zn.Zone_name;

            ctm = cls_ctm_mng.getCustomersLeasing(leasing_id, idcard);

            if (ctm != null)
            {
                Customer_Name_TBx.Text   = ctm.Cust_Fname + " " + ctm.Cust_LName;
                Customer_Idcard_TBx.Text = ctm.Cust_Idcard.Length == 13 ? ctm.Cust_Idcard.Substring(0, 1) + "-" + ctm.Cust_Idcard.Substring(1, 4) + "-" + ctm.Cust_Idcard.Substring(5, 5) + "-" + ctm.Cust_Idcard.Substring(10, 2) + "-" + ctm.Cust_Idcard.Substring(12) : ctm.Cust_Idcard;
                //Customer_B_Date_TBx.Text = DateTimeUtility.convertDateToPage(ctm.Cust_B_date);
                //Customer_Age_TBx.Text = ctm.Cust_Age.ToString();

                Customer_H_Address_TBx.Text  = string.IsNullOrEmpty(ctm.Cust_Home_address_no) ? "" : ctm.Cust_Home_address_no;
                Customer_H_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Home_vilage_no) ? "" : ctm.Cust_Home_vilage_no.IndexOf('.') >= 1 ? ctm.Cust_Home_vilage_no.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Home_vilage_no : "";
                Customer_H_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Home_vilage) ? "" : ctm.Cust_Home_vilage.IndexOf('.') >= 1 ? ctm.Cust_Home_vilage.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Home_vilage : "";
                Customer_H_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Home_alley) ? "" : ctm.Cust_Home_alley.IndexOf('.') >= 1 ? ctm.Cust_Home_alley.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Home_alley : "";
                Customer_H_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Home_road) ? "" : ctm.Cust_Home_road.IndexOf('.') >= 1 ? ctm.Cust_Home_road.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Home_road : "";
                Customer_H_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Home_subdistrict) ? "" : ctm.Cust_Home_subdistrict.IndexOf('.') >= 1 ? ctm.Cust_Home_subdistrict.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Home_subdistrict : "";
                Customer_H_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Home_district) ? "" : ctm.Cust_Home_district.IndexOf('.') >= 1 ? ctm.Cust_Home_district.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Home_district : "";
                Customer_H_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Home_province) ? "" : ctm.Cust_Home_province.IndexOf('.') >= 1 ? ctm.Cust_Home_province.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Home_province : "";

                Customer_C_Address_TBx.Text  = string.IsNullOrEmpty(ctm.Cust_Current_address_no) ? "" : ctm.Cust_Current_address_no;
                Customer_C_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Current_vilage_no) ? "" : ctm.Cust_Current_vilage_no.IndexOf('.') >= 1 ? ctm.Cust_Current_vilage_no.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Current_vilage_no : "";
                Customer_C_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Current_vilage) ? "" : ctm.Cust_Current_vilage.IndexOf('.') >= 1 ? ctm.Cust_Current_vilage.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Current_vilage : "";
                Customer_C_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Current_alley) ? "" : ctm.Cust_Current_alley.IndexOf('.') >= 1 ? ctm.Cust_Current_alley.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Current_alley : "";
                Customer_C_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Current_road) ? "" : ctm.Cust_Current_road.IndexOf('.') >= 1 ? ctm.Cust_Current_road.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Current_road : "";
                Customer_C_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Current_subdistrict) ? "" : ctm.Cust_Current_subdistrict.IndexOf('.') >= 1 ? ctm.Cust_Current_subdistrict.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Current_subdistrict : "";
                Customer_C_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Current_district) ? "" : ctm.Cust_Current_district.IndexOf('.') >= 1 ? ctm.Cust_Current_district.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Current_district : "";
                Customer_C_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Current_province) ? "" : ctm.Cust_Current_province.IndexOf('.') >= 1 ? ctm.Cust_Current_province.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Current_province : "";
            }

            Car_Type_TBx.Text = cls.Car_type;

            bs_cbrn = cbrn_mng.getCarBrandById(cls.bs_cbrn.car_brand_id);

            if (bs_cbrn != null)
            {
                Car_Brand_TBx.Text = bs_cbrn.car_brand_name_th + " ( " + bs_cbrn.car_brand_name_eng + " )";
            }

            Car_Plate_TBx.Text = cls.Car_license_plate + " " + cls.Car_license_plate_province;

            Car_Chassis_No_TBx.Text = cls.Car_chassis_no;
            Car_Engine_No_TBx.Text  = cls.Car_engine_no;

            cag_com = cag_mng.getAgentCommission("", leasing_id);

            Agent_Commission_TBx.Text = cag_com.Agent_commission.ToString("#,###.00");

            Finance_Cost_TBx.Text       = cls.Total_require.ToString("#,###.00");
            Finance_Value_TBx.Text      = cls.Total_sum.ToString("#,###.00");
            Leasing_Cost_TBx.Text       = cls.Total_Net_leasing.ToString("#,###.00");
            Period_Amount_TBx.Text      = cls.Total_period.ToString();
            Period_Payment_TBx.Text     = cls.Period_payment.ToString("#,###.00");
            Payment_Schedule_TBx.Text   = cls.Payment_schedule.ToString();
            Frist_Payment_Date_TBx.Text = DateTimeUtility.convertDateToPageRealServer(cls.First_payment_date);

            Bill_No_TBx.Text = bill_no;

            Period_fee_TBx.Text   = "0.00";
            Period_track_TBx.Text = "0.00";

            List <Car_Leasings_Payment> list_cls_pay = cls_pay_mng.getRealPaymentInfo(leasing_id);

            double total_payment_left = 0.00;
            double total_payment_fine = 0.00;

            double total_fee              = 0.00;
            double total_track            = 0.00;
            double total_real_payment     = 0.00;
            double total_rea_payment_fine = 0.00;
            double total_discount         = 0.00;

            for (int i = 0; i < list_cls_pay.Count; i++)
            {
                Car_Leasings_Payment cls_pay = list_cls_pay[i];

                if (cls_pay.Bill_no == bill_no)
                {
                    Payment_Date_TBx.Text = DateTimeUtility.convertDateToPageRealServer(cls_pay.Real_payment_date);

                    total_fee              += cls_pay.Period_fee;
                    total_track            += cls_pay.Period_track;
                    total_real_payment     += cls_pay.Real_payment;
                    total_rea_payment_fine += cls_pay.Real_payment_fine;
                    total_discount         += cls_pay.Discount;

                    total_payment_left = cls_pay.Total_payment_left;
                    total_payment_fine = cls_pay.Total_payment_fine;

                    Bill_No_Manual_Ref_TBx.Text = cls_pay.Bill_no_manual_ref;

                    Session["old_company"] = cls_pay.bs_cpn.Company_id;
                }
            }

            Total_payment_left_TBx.Text = total_payment_left.ToString("#,###.00");
            Total_payment_fine_TBx.Text = total_payment_fine.ToString("#,###.00");

            Old_Period_fee_TBx.Text        = total_fee.ToString("#,###.00");
            Old_Period_track_TBx.Text      = total_track.ToString("#,###.00");
            Old_Real_Payment_TBx.Text      = total_real_payment.ToString("#,###.00");
            Old_Real_Payment_Fine_TBx.Text = total_rea_payment_fine.ToString("#,###.00");
            Old_Real_Discount_TBx.Text     = total_discount.ToString("#,###.00");

            Session["list_cls_pay"] = list_cls_pay;

            Real_Payment_TBx.Focus();
        }
Пример #7
0
        private void _calculateCloseLeasing(string leasing_id, string idcard)
        {
            cls = cls_mng.getCarLeasingById(leasing_id);

            List <Car_Leasings_Payment> list_cls_pay = cls_pay_mng.getRealPaymentInfo(leasing_id);

            double total_lost         = 0;
            double total_payment      = 0;
            double total_payment_fine = 0.00;
            string date_last_payemnt  = string.Empty;
            double payment_fine       = 0.00;
            double real_payment_fine  = 0.00;
            double interest           = 0;
            double interest_per_day   = 0;
            double day_of_cal         = 0;
            double discount           = 0;
            double next_period_no     = 1;
            double real_payment       = 0.00;
            double duplicate_period   = 0;

            for (int i = 0; i < list_cls_pay.Count; i++)
            {
                Car_Leasings_Payment cls_pay = list_cls_pay[i];

                if (string.IsNullOrEmpty(cls.Total_period_length))
                {
                    Period_No_TBx.Text = next_period_no.ToString();
                }
                else
                {
                    int period_str = Convert.ToInt32(cls.Total_period_length.Split('-')[0].Trim());
                    int period_end = Convert.ToInt32(cls.Total_period_length.Split('-')[1].Trim());

                    if (cls_pay.Period_no >= period_str && cls_pay.Period_no <= period_end)
                    {
                        total_lost += cls_pay.Period_current;
                    }
                }

                if (cls_pay.Period_no != duplicate_period)
                {
                    total_payment += cls_pay.Period_current;
                }
                else
                {
                    next_period_no += 1;
                }

                if (cls_pay.Total_payment_fine != 0)
                {
                    total_payment_fine = cls_pay.Total_payment_fine;
                }

                date_last_payemnt = cls_pay.Period_schedule;

                interest = cls_pay.Period_interst;

                if (cls_pay.Period_fine > 0 && cls_pay.Period_no != duplicate_period)
                {
                    payment_fine    += cls_pay.Period_fine;
                    duplicate_period = cls_pay.Period_no;
                }

                if (cls_pay.Real_payment_fine > 0)
                {
                    real_payment_fine += cls_pay.Real_payment_fine;
                }

                if (cls_pay.Real_payment > 0)
                {
                    real_payment += cls_pay.Real_payment;
                }
            }

            total_payment_fine = payment_fine - real_payment_fine;

            Total_payment_fine_TBx.Text = total_payment_fine <= 0 ? "0.00" : total_payment_fine.ToString("#,###.00");

            Total_period_left_TBx.Text = (total_lost - real_payment) <= 0 ? "0.00" : (total_lost - real_payment).ToString("#,###.00");

            Period_fine_TBx.Text = total_payment_fine < 0 ? "0.00" : total_payment_fine.ToString("#,###.00");

            interest_per_day = interest / 30;
            day_of_cal       = (Convert.ToDateTime(date_last_payemnt) - DateTime.Now).TotalDays;
            discount         = Math.Floor((day_of_cal * interest_per_day) / 2);

            Discount_TBx.Text = discount.ToString("#,###.00");

            Cal_Period_Payment_TBx.Text = (cls.Total_Net_leasing - real_payment).ToString("#,###.00");

            Real_Payment_TBx.Focus();

            Close_Leasing_Lbl.Visible = false;
            Cal_Status_Lbl.Visible    = true;
        }
Пример #8
0
        private void _loadLeasingDetails(string leasing_id, string idcard)
        {
            cls = cls_mng.getCarLeasingById(leasing_id);

            Leasing_Comments_Lbl.Text = cls.Leasing_Comment;

            if (cls.Total_payment_left == 0)
            {
                Close_Leasing_Lbl.Visible = true;
                Cal_Status_Lbl.Visible    = false;

                Payment_Btn.Visible = false;
                Calculate_Close_Leasing_Btn.Visible = false;
                Back_Before_Page_Btn.Visible        = false;

                Leasing_Date_TBx.Text = DateTimeUtility.convertDateToPageRealServer(cls.Leasing_date);

                Deps_No_TBx.Text    = cls.Deps_no;
                Leasing_No_TBx.Text = cls.Leasing_no;

                bs_cpn = bs_cpn_mng.getCompanysById(cls.bs_cpn.Company_id.ToString());

                Company_N_Name_TBx.Text = bs_cpn.Company_N_name;
                Company_F_Name_TBx.Text = bs_cpn.Company_F_name;

                bs_zn = bs_zn_mng.getZoneById(cls.bs_zn.Zone_id);

                Zone_Name_TBx.Text = bs_zn.Zone_code + " " + bs_zn.Zone_name;

                ctm = cls_ctm_mng.getCustomersLeasing(leasing_id, idcard);

                if (ctm != null)
                {
                    Customer_Name_TBx.Text   = ctm.Cust_Fname + " " + ctm.Cust_LName;
                    Customer_Idcard_TBx.Text = ctm.Cust_Idcard.Length == 13 ? ctm.Cust_Idcard.Substring(0, 1) + "-" + ctm.Cust_Idcard.Substring(1, 4) + "-" + ctm.Cust_Idcard.Substring(5, 5) + "-" + ctm.Cust_Idcard.Substring(10, 2) + "-" + ctm.Cust_Idcard.Substring(12) : ctm.Cust_Idcard;
                    //Customer_B_Date_TBx.Text = DateTimeUtility.convertDateToPage(ctm.Cust_B_date);
                    //Customer_Age_TBx.Text = ctm.Cust_Age.ToString();

                    Customer_H_Address_TBx.Text  = string.IsNullOrEmpty(ctm.Cust_Home_address_no) ? "" : ctm.Cust_Home_address_no;
                    Customer_H_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Home_vilage_no) ? "" : ctm.Cust_Home_vilage_no.IndexOf('.') >= 1 ? ctm.Cust_Home_vilage_no.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Home_vilage_no : "";
                    Customer_H_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Home_vilage) ? "" : ctm.Cust_Home_vilage.IndexOf('.') >= 1 ? ctm.Cust_Home_vilage.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Home_vilage : "";
                    Customer_H_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Home_alley) ? "" : ctm.Cust_Home_alley.IndexOf('.') >= 1 ? ctm.Cust_Home_alley.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Home_alley : "";
                    Customer_H_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Home_road) ? "" : ctm.Cust_Home_road.IndexOf('.') >= 1 ? ctm.Cust_Home_road.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Home_road : "";
                    Customer_H_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Home_subdistrict) ? "" : ctm.Cust_Home_subdistrict.IndexOf('.') >= 1 ? ctm.Cust_Home_subdistrict.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Home_subdistrict : "";
                    Customer_H_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Home_district) ? "" : ctm.Cust_Home_district.IndexOf('.') >= 1 ? ctm.Cust_Home_district.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Home_district : "";
                    Customer_H_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Home_province) ? "" : ctm.Cust_Home_province.IndexOf('.') >= 1 ? ctm.Cust_Home_province.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Home_province : "";

                    Customer_C_Address_TBx.Text  = string.IsNullOrEmpty(ctm.Cust_Current_address_no) ? "" : ctm.Cust_Current_address_no;
                    Customer_C_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Current_vilage_no) ? "" : ctm.Cust_Current_vilage_no.IndexOf('.') >= 1 ? ctm.Cust_Current_vilage_no.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Current_vilage_no : "";
                    Customer_C_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Current_vilage) ? "" : ctm.Cust_Current_vilage.IndexOf('.') >= 1 ? ctm.Cust_Current_vilage.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Current_vilage : "";
                    Customer_C_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Current_alley) ? "" : ctm.Cust_Current_alley.IndexOf('.') >= 1 ? ctm.Cust_Current_alley.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Current_alley : "";
                    Customer_C_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Current_road) ? "" : ctm.Cust_Current_road.IndexOf('.') >= 1 ? ctm.Cust_Current_road.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Current_road : "";
                    Customer_C_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Current_subdistrict) ? "" : ctm.Cust_Current_subdistrict.IndexOf('.') >= 1 ? ctm.Cust_Current_subdistrict.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Current_subdistrict : "";
                    Customer_C_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Current_district) ? "" : ctm.Cust_Current_district.IndexOf('.') >= 1 ? ctm.Cust_Current_district.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Current_district : "";
                    Customer_C_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Current_province) ? "" : ctm.Cust_Current_province.IndexOf('.') >= 1 ? ctm.Cust_Current_province.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Current_province : "";
                }

                Car_Type_TBx.Text = cls.Car_type;

                bs_cbrn = cbrn_mng.getCarBrandById(cls.bs_cbrn.car_brand_id);

                if (bs_cbrn != null)
                {
                    Car_Brand_TBx.Text = bs_cbrn.car_brand_name_th + " ( " + bs_cbrn.car_brand_name_eng + " )";
                }

                Car_Plate_TBx.Text = cls.Car_license_plate + " " + cls.Car_license_plate_province;

                Car_Chassis_No_TBx.Text = cls.Car_chassis_no;
                Car_Engine_No_TBx.Text  = cls.Car_engine_no;

                cag_com = cag_mng.getAgentCommission("", leasing_id);

                Agent_Commission_TBx.Text = cag_com.Agent_commission.ToString("#,###.00");

                Finance_Cost_TBx.Text       = cls.Total_require.ToString("#,###.00");
                Finance_Value_TBx.Text      = cls.Total_sum.ToString("#,###.00");
                Leasing_Cost_TBx.Text       = cls.Total_Net_leasing.ToString("#,###.00");
                Period_Amount_TBx.Text      = cls.Total_period.ToString();
                Period_Payment_TBx.Text     = cls.Period_payment.ToString("#,###.00");
                Payment_Schedule_TBx.Text   = cls.Payment_schedule.ToString();
                Frist_Payment_Date_TBx.Text = DateTimeUtility.convertDateToPageRealServer(cls.First_payment_date);

                Payment_Date_TBx.Enabled = false;

                List <Car_Leasings_Payment> list_cls_pay = cls_pay_mng.getRealPaymentInfo(leasing_id);

                Session["list_cls_pay"] = list_cls_pay;

                Period_free_TBx.Enabled  = false;
                Period_track_TBx.Enabled = false;

                Real_Payment_TBx.Enabled      = false;
                Real_Payment_Fine_TBx.Enabled = false;
                Real_Discount_TBx.Enabled     = false;

                Payment_Date_TBx.Text = "";

                Period_No_TBx.Text            = "";
                Total_Payment_Period_TBx.Text = "";
                Total_payment_left_TBx.Text   = "";
                Period_free_TBx.Text          = "";
                Period_track_TBx.Text         = "";
                Discount_TBx.Text             = "";

                Total_payment_fine_TBx.Text = "";

                Total_period_left_TBx.Text  = "";
                Period_fine_TBx.Text        = "";
                Cal_Period_Payment_TBx.Text = "";
            }
            else
            {
                Leasing_Date_TBx.Text = DateTimeUtility.convertDateToPageRealServer(cls.Leasing_date);
                Deps_No_TBx.Text      = cls.Deps_no;
                Leasing_No_TBx.Text   = cls.Leasing_no;

                bs_cpn = bs_cpn_mng.getCompanysById(cls.bs_cpn.Company_id.ToString());

                Company_N_Name_TBx.Text = bs_cpn.Company_N_name;
                Company_F_Name_TBx.Text = bs_cpn.Company_F_name;

                bs_zn = bs_zn_mng.getZoneById(cls.bs_zn.Zone_id);

                Zone_Name_TBx.Text = bs_zn.Zone_code + " " + bs_zn.Zone_name;

                ctm = cls_ctm_mng.getCustomersLeasing(leasing_id, idcard);

                if (ctm != null)
                {
                    Customer_Name_TBx.Text   = ctm.Cust_Fname + " " + ctm.Cust_LName;
                    Customer_Idcard_TBx.Text = ctm.Cust_Idcard.Length == 13 ? ctm.Cust_Idcard.Substring(0, 1) + "-" + ctm.Cust_Idcard.Substring(1, 4) + "-" + ctm.Cust_Idcard.Substring(5, 5) + "-" + ctm.Cust_Idcard.Substring(10, 2) + "-" + ctm.Cust_Idcard.Substring(12) : ctm.Cust_Idcard;
                    //Customer_B_Date_TBx.Text = DateTimeUtility.convertDateToPage(ctm.Cust_B_date);
                    //Customer_Age_TBx.Text = ctm.Cust_Age.ToString();

                    Customer_H_Address_TBx.Text  = string.IsNullOrEmpty(ctm.Cust_Home_address_no) ? "" : ctm.Cust_Home_address_no;
                    Customer_H_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Home_vilage_no) ? "" : ctm.Cust_Home_vilage_no.IndexOf('.') >= 1 ? ctm.Cust_Home_vilage_no.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Home_vilage_no : "";
                    Customer_H_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Home_vilage) ? "" : ctm.Cust_Home_vilage.IndexOf('.') >= 1 ? ctm.Cust_Home_vilage.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Home_vilage : "";
                    Customer_H_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Home_alley) ? "" : ctm.Cust_Home_alley.IndexOf('.') >= 1 ? ctm.Cust_Home_alley.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Home_alley : "";
                    Customer_H_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Home_road) ? "" : ctm.Cust_Home_road.IndexOf('.') >= 1 ? ctm.Cust_Home_road.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Home_road : "";
                    Customer_H_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Home_subdistrict) ? "" : ctm.Cust_Home_subdistrict.IndexOf('.') >= 1 ? ctm.Cust_Home_subdistrict.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Home_subdistrict : "";
                    Customer_H_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Home_district) ? "" : ctm.Cust_Home_district.IndexOf('.') >= 1 ? ctm.Cust_Home_district.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Home_district : "";
                    Customer_H_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Home_province) ? "" : ctm.Cust_Home_province.IndexOf('.') >= 1 ? ctm.Cust_Home_province.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Home_province : "";

                    Customer_C_Address_TBx.Text  = string.IsNullOrEmpty(ctm.Cust_Current_address_no) ? "" : ctm.Cust_Current_address_no;
                    Customer_C_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Current_vilage_no) ? "" : ctm.Cust_Current_vilage_no.IndexOf('.') >= 1 ? ctm.Cust_Current_vilage_no.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Current_vilage_no : "";
                    Customer_C_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Current_vilage) ? "" : ctm.Cust_Current_vilage.IndexOf('.') >= 1 ? ctm.Cust_Current_vilage.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Current_vilage : "";
                    Customer_C_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Current_alley) ? "" : ctm.Cust_Current_alley.IndexOf('.') >= 1 ? ctm.Cust_Current_alley.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Current_alley : "";
                    Customer_C_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Current_road) ? "" : ctm.Cust_Current_road.IndexOf('.') >= 1 ? ctm.Cust_Current_road.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Current_road : "";
                    Customer_C_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Current_subdistrict) ? "" : ctm.Cust_Current_subdistrict.IndexOf('.') >= 1 ? ctm.Cust_Current_subdistrict.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Current_subdistrict : "";
                    Customer_C_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Current_district) ? "" : ctm.Cust_Current_district.IndexOf('.') >= 1 ? ctm.Cust_Current_district.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Current_district : "";
                    Customer_C_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Current_province) ? "" : ctm.Cust_Current_province.IndexOf('.') >= 1 ? ctm.Cust_Current_province.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Current_province : "";
                }

                Car_Type_TBx.Text = cls.Car_type;

                bs_cbrn = cbrn_mng.getCarBrandById(cls.bs_cbrn.car_brand_id);

                if (bs_cbrn != null)
                {
                    Car_Brand_TBx.Text = bs_cbrn.car_brand_name_th + " ( " + bs_cbrn.car_brand_name_eng + " )";
                }

                Car_Plate_TBx.Text = cls.Car_license_plate + " " + cls.Car_license_plate_province;

                Car_Chassis_No_TBx.Text = cls.Car_chassis_no;
                Car_Engine_No_TBx.Text  = cls.Car_engine_no;

                cag_com = cag_mng.getAgentCommission("", leasing_id);

                Agent_Commission_TBx.Text = cag_com.Agent_commission.ToString("#,###.00");

                Finance_Cost_TBx.Text       = cls.Total_require.ToString("#,###.00");
                Finance_Value_TBx.Text      = cls.Total_sum.ToString("#,###.00");
                Leasing_Cost_TBx.Text       = cls.Total_Net_leasing.ToString("#,###.00");
                Period_Amount_TBx.Text      = cls.Total_period.ToString();
                Period_Payment_TBx.Text     = cls.Period_payment.ToString("#,###.00");
                Payment_Schedule_TBx.Text   = cls.Payment_schedule.ToString();
                Frist_Payment_Date_TBx.Text = DateTimeUtility.convertDateToPageRealServer(cls.First_payment_date);

                Payment_Date_TBx.Text = DateTimeUtility.convertDateToPageRealServer(DateTime.Now.ToString());

                Period_No_TBx.Text            = cls.Total_period_length;
                Total_Payment_Period_TBx.Text = cls.Total_period_lose == 0 ? "1" : cls.Total_period_lose.ToString();
                Total_payment_left_TBx.Text   = cls.Total_payment_left.ToString("#,###.00");
                Period_free_TBx.Text          = "0.00";
                Period_track_TBx.Text         = "0.00";
                Discount_TBx.Text             = "0.00";

                List <Car_Leasings_Payment> list_cls_pay = cls_pay_mng.getRealPaymentInfo(leasing_id);

                double total_lost         = 0.00;
                double total_payment_fine = 0.00;
                double payment_fine       = 0.00;
                double real_payment_fine  = 0.00;
                double real_payment       = 0.00;
                double next_period_no     = 1;
                double duplicate_period   = 0;

                for (int i = 0; i < list_cls_pay.Count; i++)
                {
                    Car_Leasings_Payment cls_pay = list_cls_pay[i];

                    if (string.IsNullOrEmpty(cls.Total_period_length))
                    {
                        total_lost         = cls_pay.Period_current;
                        Period_No_TBx.Text = next_period_no.ToString();
                    }
                    else
                    {
                        int period_str = Convert.ToInt32(cls.Total_period_length.Split('-')[0].Trim());
                        int period_end = Convert.ToInt32(cls.Total_period_length.Split('-')[1].Trim());

                        if (cls_pay.Period_no >= period_str && cls_pay.Period_no <= period_end && cls_pay.Period_no != duplicate_period)
                        {
                            total_lost += cls_pay.Period_current;
                        }
                    }

                    if (cls_pay.Period_fine > 0 && cls_pay.Period_no != duplicate_period)
                    {
                        payment_fine += cls_pay.Period_fine;
                    }

                    if (cls_pay.Real_payment_fine > 0)
                    {
                        real_payment_fine += cls_pay.Real_payment_fine;
                    }

                    if (cls_pay.Real_payment > 0 && cls_pay.Period_payment_status != 9)
                    {
                        real_payment += cls_pay.Real_payment;
                    }

                    if (cls_pay.Period_payment_status == 9 && cls_pay.Period_no != duplicate_period)
                    {
                        next_period_no += 1;
                    }

                    duplicate_period = cls_pay.Period_no;
                }

                total_payment_fine = payment_fine - real_payment_fine;

                Total_payment_fine_TBx.Text = total_payment_fine > 0 ? total_payment_fine.ToString("#,###.00") : "0.00";

                Total_period_left_TBx.Text = string.IsNullOrEmpty(cls.Total_period_length) ? "0.00" : (total_lost - real_payment).ToString("#,###.00");

                Period_fine_TBx.Text = total_payment_fine < 0 ? "0.00" : total_payment_fine.ToString("#,###.00");

                Cal_Period_Payment_TBx.Text = (total_lost - real_payment).ToString("#,###.00");

                Session["list_cls_pay"] = list_cls_pay;

                Real_Payment_TBx.Focus();
            }
        }