using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DataLibrary;
using CoreSavingLibrary;
using DataLibrary;
using System.Data;
namespace Saving.Applications.shrlon
{
public class LawClass
{
Sdt dt = new Sdt();
string Sqlse = string.Empty;
public DateTime _ofgetworkdatestore(string storeid)
{
DateTime workdate = new DateTime();
Sqlse = "select work_date from ststore where store_id = {0}";
Sqlse = WebUtil.SQLFormat(Sqlse, storeid);
dt = WebUtil.QuerySdt(Sqlse);
if (dt.Next())
{
workdate = dt.GetDate("work_date");
}
return (DateTime)workdate;
}
public int _ofgetvattype(int itemamt, int vattype)
{
int vatAtm = 0;
return vatAtm;
}
public Decimal Calint(String loancontract, DateTime date_now, string coop_id)
{
Decimal intrate = 0, int_cal = 0;//อัตราดอกเบี้ย
// get yaer จาก ค่าคงที่
decimal year = 0, rdintdec_type = 0, INTROUNDSUM_TYPE = 0;
string sql21 = @"
select dayinyear,rdintdec_type,INTROUNDSUM_TYPE from lnloanconstant ";
sql21 = WebUtil.SQLFormat(sql21, loancontract);
Sdt dt21 = WebUtil.QuerySdt(sql21);
if (dt21.Next())
{
year = dt21.GetDecimal("dayinyear");
rdintdec_type = dt21.GetDecimal("rdintdec_type");
INTROUNDSUM_TYPE = dt21.GetDecimal("INTROUNDSUM_TYPE");
}
Decimal cal_int = 0;
String getmaster = "select * from lnlawmaster where loancontract_no = '" + loancontract + "'";
// Sdt sd = WebUtil.QuerySdt(hart);
Sdt sd = WebUtil.QuerySdt(getmaster);
if (sd.Next())
{
DateTime calint = sd.GetDate("lastcalint_date");
Decimal principal_balance = sd.GetDecimal("principal_calintamt"); // ยอดคงเหลือ
TimeSpan diff1 = date_now.Subtract(calint);
Double TotalDay2 = diff1.TotalDays;
int CalDay = Convert.ToInt32(TotalDay2); // คำนวณวัน
decimal finerate = sd.GetDecimal("int_rate") / 100;
cal_int = (principal_balance * finerate * CalDay) / year; // ค่าปรับใหม่
}
//คำนวณดอกเบี้ย กล้า
if (rdintdec_type == 0)//ทศนิยม 2 ตำแหน่ง
{
int_cal = Convert.ToDecimal(Math.Round(cal_int, 2));
}
else if (rdintdec_type == 1)//ปัดทิ้ง
{
int_cal = Convert.ToDecimal(Math.Floor(cal_int));
}
else if (rdintdec_type == 2)//ปัดทิ้ง
{
int_cal = Convert.ToDecimal(Math.Ceiling(cal_int));
}
else
{
int_cal = Convert.ToDecimal(Math.Round(cal_int, 0));
}
if (int_cal < 0)
{
int_cal = 0;
}
return int_cal;
}
public Decimal calfine_new(String loancontract, DateTime date_now, string coop_id)//
{
decimal fine = 0;
decimal cal_int = 0; //ผลลัพธ์
decimal year = 0;
int rdintsatang_type = 0;
// get yaer จาก ค่าคงที่
Sdt dt2 = WebUtil.QuerySdt(@"
select dayinyear,rdintsatang_type from lnloanconstant");
if (dt2.Next())
{
year = dt2.GetDecimal("dayinyear");
rdintsatang_type = dt2.GetInt32("rdintsatang_type");//ปัดเศษ
}
String getmaster = "select * from lnlawmaster where loancontract_no = '" + loancontract + "'";
// Sdt sd = WebUtil.QuerySdt(hart);
Sdt sd = WebUtil.QuerySdt(getmaster);
if (sd.Next())
{
DateTime calint = sd.GetDate("lastcalfine_date");
Decimal principal_balance = sd.GetDecimal("principal_calintamt"); // ยอดคงเหลือ
TimeSpan diff1 = date_now.Subtract(calint);
Double TotalDay2 = diff1.TotalDays;
int CalDay = Convert.ToInt32(TotalDay2); // คำนวณวัน
decimal finerate = sd.GetDecimal("fine_rate") / 100;
cal_int = (principal_balance * finerate * CalDay) / year; // ค่าปรับใหม่
}
// ทศนิยม 2 ตำแหน่ง
// ปัดทิ้ง
// ปัดขึ้น
if (rdintsatang_type == 0)//ทศนิยม 2 ตำแหน่ง
{
fine = Convert.ToDecimal(Math.Round(cal_int, 2));
}
else if (rdintsatang_type == 1)//ปัดทิ้ง
{
fine = Convert.ToDecimal(Math.Floor(cal_int));
}
else if (rdintsatang_type == 2)//ปัดขึ้น
{
fine = Convert.ToDecimal(Math.Ceiling(cal_int));
}
else
{
decimal fils = Convert.ToDecimal(Math.Floor(cal_int));
fine = Convert.ToDecimal(Math.Round(cal_int, 2));
fils = (fine - fils) * 100;
if (fils >= 49)
{
fine = Convert.ToDecimal(Math.Ceiling(cal_int));
}
else
{
fine = Convert.ToDecimal(Math.Floor(cal_int));
}
}
if (fine < 0)
{
fine = 0;
}
return fine;
}
}
}