private void frmListMoneyLender_Load(object sender, EventArgs e)
 {
     cl_moneylender cMoneyLender = new cl_moneylender();
     cMoneyLender.LOAD_MONEYLENDER(lsvMoneyLender);
     //MYFUNCTIONS m = new MYFUNCTIONS();
     //string sql = "select * from tmoneylender";
     //m.PopulateListView(lsvMoneyLender, sql);
 }
        private void frmDetailsBorrower_Load(object sender, EventArgs e)
        {
            cl_moneylender lender = new cl_moneylender();
            cl_lender_inform li = new cl_lender_inform();

            lender.LOADTOFIELDSLenderID(bid);
            lblAddress.Text = lender.propAddress;
            lblContact.Text = lender.propContact_no;
            lblName.Text = lender.propfname.ToString() + " " + lender.propMI.ToString() + " "  + lender.proplname.ToString();

            li.loadDetailsBorrowers(lsvPaymentSched, lender.propMoneyLender_id);
        }
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (lsvMoneyLender.SelectedItems.Count > 0)
            {

                PUBLIC_VARS.activeID = Convert.ToInt32(lsvMoneyLender.SelectedItems[0].Text.ToString());
                cl_moneylender cMoneyLender = new cl_moneylender();
                DialogResult result1 = MessageBox.Show("Are you sure you want to delete entry?", "delete", MessageBoxButtons.YesNo);
                if (result1 == DialogResult.Yes)
                {
                    cMoneyLender.DELETE_DATA(PUBLIC_VARS.activeID);
                    MessageBox.Show(PUBLIC_VARS.deleteData);
                }
                cMoneyLender.LOAD_MONEYLENDER(lsvMoneyLender);
            }
            else {
                MessageBox.Show("No records to be deleted.");
            }
        }
 private void cboBtype_SelectedIndexChanged(object sender, EventArgs e)
 {
     cl_moneylender l = new cl_moneylender();
     l.LOAD_MONEYLENDER_Actvie(lsvMoneyLender, cboBtype.Text);
 }
 private void btnView_Click(object sender, EventArgs e)
 {
     cl_moneylender l = new cl_moneylender();
     l.Search_MONEYLENDER(lsvMoneyLender, "view");
 }
 private void btnSearch_Click(object sender, EventArgs e)
 {
     cl_moneylender l = new cl_moneylender();
      l.Search_MONEYLENDER(lsvMoneyLender,textBox1.Text);
 }
 private void textBox1_TextChanged(object sender, EventArgs e)
 {
     cl_moneylender l = new cl_moneylender();
     l.Search_MONEYLENDER(lsvMoneyLender, textBox1.Text);
 }
        private void btnSave_Click_1(object sender, EventArgs e)
        {
            if(txtAge.Text == "" || txtContactNo.Text == "" || txtFname.Text == "" || txtLname.Text =="" || txtAddress.Text == "" || txtContactNo.Text == ""){
                MessageBox.Show("Please supply the required fields.");
                return;
            }
            if(txtlengthservice.Text == ""){
                txtlengthservice.Text = "0";
            }
            cl_moneylender cMoneyLender = new cl_moneylender();
            cl_LenderInformation l_Info = new cl_LenderInformation();
            cMoneyLender.propfname = txtFname.Text;
            cMoneyLender.proplname = txtLname.Text;
            cMoneyLender.propMI = txtMI.Text;
            cMoneyLender.propAddress = txtAddress.Text;
            cMoneyLender.propAge = Convert.ToInt32(txtAge.Text);
            cMoneyLender.propCreditLimit = Convert.ToDouble(222);
            cMoneyLender.propLenderID = txtMoneyLenderID.Text;
            cMoneyLender.propContact_no = txtContactNo.Text;
            cMoneyLender.propIs_inactive = cboLenderType.Text;

            l_Info.propLengthofService = Convert.ToInt32(txtlengthservice.Text.ToString());
            l_Info.propHouseType = cbohousetype.Text;
            l_Info.propGender = cboGender.Text;
            l_Info.propEmail = txtemail.Text;
            l_Info.propOccupation  = txtoccupation.Text;
            l_Info.propPosition = txtposition.Text;
            l_Info.propTIN_no = txtTin_no.Text;
            l_Info.propCompanyName = txtcompanyname.Text;
            l_Info.propCompanyAdd = txtcompanyaddress.Text;
            l_Info.propCivilStatus = cboCivilStatus.Text;
            l_Info.propbirthplace = txtbirthplace.Text;
            l_Info.propDOB = dob.Value;

            cl_spouse sp = new cl_spouse();

            sp.propspousename  = txtspousename.Text;
            sp.propspouseOcc = txtSoCCu.Text;
            sp.propsCompany =txtsCompany.Text;
            sp.propsPosition=txtspouseP.Text;

            //check if is active or not
            cl_borrower_loan bl = new cl_borrower_loan();

            if (cboCivilStatus.Text != "Single")
            {
               sp.props_age = Convert.ToInt32(txtSpouseAge.Text);
            }
            if (cMoneyLender.propAge < 18 )
            {
                MessageBox.Show("Age should not lesser than 18");
                return;
            }
            if (PUBLIC_VARS.EDITMODE == true){

                cMoneyLender.UPDATE_DATA(mlt);

                int l_sid = Convert.ToInt32(PUBLIC_VARS.d.getlastid().ToString());
                l_Info.propmonenylenderInfoID = l_sid;
                l_Info.INSERT_DATATOLENDER();
                if (cboCivilStatus.Text != "Single")
                {
                    sp.propMoneyLender_id = l_sid;
                    sp.UPDATE_SPOUSE(mlt);

                }
                cMoneyLender.propMoneyLender_id = mlt;

                if (InsertPictureBarrowerImages == "")
                {
                    cMoneyLender.propPicBarrower = tempPictures;
                }
                else
                {
                    cMoneyLender.propPicBarrower = InsertPictureBarrowerImages;
                }
                cMoneyLender.UpdatePicBarrower();
                MessageBox.Show( PUBLIC_VARS.updateData);
            }
            else{
                MYFUNCTIONS f = new MYFUNCTIONS();

                if (cMoneyLender.isBarrowerExist() == true) {
                    MessageBox.Show("Record already exist.");
                    return;
                }

                cMoneyLender.INSERT_DATA();
                int iiiD = PUBLIC_VARS.d.getlastid();
                int l_sid = Convert.ToInt32(PUBLIC_VARS.d.getlastid().ToString());
                l_Info.propmonenylenderInfoID = l_sid;
                l_Info.INSERT_DATATOLENDER();
                if(cboCivilStatus.Text != "Single"){
                    sp.propMoneyLender_id = l_sid;
                    sp.INSERT_SPOUSE();

                }

                Int64 dx = f.autoUserID() + 1;

                f.InsertCounterNo(dx);

                if (InsertPictureBarrowerImages == ""){
                    InsertPictureBarrowerImages = "default_avatar.jpg";
                }

                cMoneyLender.propPicBarrower = InsertPictureBarrowerImages;
                cMoneyLender.propMoneyLender_id = iiiD;
                cMoneyLender.InserPictureBarrower();

                MessageBox.Show(PUBLIC_VARS.saveData);

            }
            //cMoneyLender.LOAD_MONEYLENDER(lst.lsvMoneyLender);
            //MYFUNCTIONS m = new MYFUNCTIONS();
            //string sql = "SELECT * FROM tmoneylender";
            //m.PopulateListView(lsvevent,sql);
            cMoneyLender.LOAD_MONEYLENDER(lsvevent);
            this.Close();
        }
        private void frmCustomer_Load(object sender, EventArgs e)
        {
            if (PUBLIC_VARS.EDITMODE == true)
            {
                cl_moneylender cm = new cl_moneylender();
                cl_LenderInformation c_info = new cl_LenderInformation();
                cm.LOADTOFIELDS(mlt);
                txtAddress.Text = cm.propAddress;
                txtFname.Text = cm.propfname;
                txtLname.Text = cm.proplname;
                txtMI.Text = cm.propMI;
                txtAge.Text = cm.propAge.ToString();
                txtTin_no.Text = cm.propCreditLimit.ToString();
                txtContactNo.Text = cm.propContact_no;
                txtMoneyLenderID.Text = cm.propLenderID;
                cboLenderType.Text = cm.propIs_inactive;

                c_info.LOAD_TOFIELDSinfo(mlt);
                txtbirthplace.Text = c_info.propbirthplace;
                dob.Value = c_info.propDOB;
                cboCivilStatus.Text = c_info.propCivilStatus;
                cboGender.Text = c_info.propGender;
                cbohousetype.Text = c_info.propHouseType;
                txtemail.Text = c_info.propEmail;
                txtoccupation.Text = c_info.propOccupation;
                txtposition.Text = c_info.propPosition;
                txtlengthservice.Text = Convert.ToInt32(c_info.propLengthofService).ToString();
                txtcompanyaddress.Text = c_info.propCompanyAdd;
                txtcompanyname.Text = c_info.propCompanyName;

                cm.loadPictureBarrower(mlt);
                tempPictures = cm.propPicBarrower;
                //pictureBarrowerImages = cm.propPicBarrower;
                picBorrower.Image = Image.FromFile(@"D:\MY PROJECTS\LoanTrackingSystem\loantracking\loantracking\bimages\" + cm.propPicBarrower);
                picBorrower.SizeMode = PictureBoxSizeMode.StretchImage;

               // picBorrower.Image = Image.FromFile(@"D:\MY PROJECTS\LoanTrackingSystem\loantracking\loantracking\bimages\default_avatar.jpg");
               // picBorrower.SizeMode = PictureBoxSizeMode.StretchImage;

                if (c_info.propCivilStatus != "Single")
                {
                    cl_spouse sp = new cl_spouse();
                    sp.LOAD_TOFIELDSPOUSE(mlt);
                    txtspousename.Text = sp.propspousename;
                    txtSpouseAge.Text = Convert.ToInt32(sp.props_age).ToString();
                    txtspouseP.Text = sp.propsPosition;
                    txtsCompany.Text = sp.propsCompany;
                    txtSoCCu.Text = sp.propspouseOcc;
                }
            }
            else
            {

                MYFUNCTIONS f = new MYFUNCTIONS();
                DateTime dt = DateTime.Today;
                Int64 dx =f.autoUserID()+1;
                txtMoneyLenderID.Text =dt.Year.ToString("X2") + String.Format("{0:D5}", dx);
               picBorrower.Image = Image.FromFile(@"D:\MY PROJECTS\LoanTrackingSystem\loantracking\loantracking\bimages\default_avatar.jpg");
               picBorrower.SizeMode = PictureBoxSizeMode.StretchImage;

            }
        }
        private void btnGenerate_Click(object sender, EventArgs e)
        {
            cl_moneylender m = new cl_moneylender();
            cl_lender_inform lend = new cl_lender_inform();
            //less 1 mo. interest = 1.5%
            //charges = 5%
            double amt_applied = 0d;
            int no_ofDays = 0;

            if (textBox1.Text == "") {
                MessageBox.Show("Please supply the borrowers name.");
                return;
            }
            if(Convert.ToDouble(txtAmountApplied.Text)<=0){
                MessageBox.Show("Please supply the correct amount.");
                return;
            }
            if (Convert.ToDouble(txtMonthlyDue.Text)< 0 || Convert.ToDouble(txtMonthlyDue.Text)< 5 )  {
                MessageBox.Show("Please supply the correct amount.");
                return;
            }

            if (m.isBarrowerActive(mYLenderIDs) == true)
            {
                MessageBox.Show("Cannot generate loan borrower is Inactive");
                return;
            }

            amt_applied = Convert.ToDouble(txtAmountApplied.Text);
            double charges = (amt_applied * 5) / 100;
            double rest1 = (amt_applied * 1.5) / 100;
            double net_proceeds = amt_applied - (rest1+charges);
            int termsNo;
            int monthstoPay;

            txtNetAmount.Text = net_proceeds.ToString("#,###0.00");

            DateTime timenow = DateTime.Today;
            try
            {
                termsNo = Convert.ToInt32(txtMonthsNo.Text);
                if (txtMonthsNo.Text == "")
                {
                    termsNo = 36;
                }
            }
            catch (Exception xx) {
                termsNo = 36;
            }

            lsvPaymentSched.Items.Clear();
            DateTime today = DateTime.Today;
            List<DateTime> lstq = new List<DateTime>();

            if (termsNo > 36) {
                MessageBox.Show("Invalid amount.");
                return;
            }
            else if(termsNo < 0){
                termsNo = 36;
            }

            int ctr;
            for (ctr = 1; ctr <= termsNo; ctr++)
            {
              //  lstq.Add(timenow.AddMonths(ctr).AddDays(-1));
              //  MessageBox.Show(timenow.AddMonths(ctr).AddDays(-1).ToString());
                lstq.Add(timenow.AddMonths(ctr).AddDays(-1));
            }

            //for (int i = 1; i < lstq.Count; i++)
            //{
            //    MessageBox.Show(lstq[i].ToString());
            //}

            double getamnt = Convert.ToDouble(txtAmountApplied.Text);
            double pmt = 0d;
            double pmt1 = 0d;

            double restDue = 0d;
            double re = 0d;
            double getamnt1 = 0d;
            double mntDue = Convert.ToDouble(txtMonthlyDue.Text);
            restDue = getamnt;
            double tmp = 0d;
            monthstoPay = 1;
            //================

            for (int i = 0; i < lstq.Count;i++ )
            {
                ListViewItem lvi1 = new ListViewItem();
                DateTime lastDayOfThisMonth = new DateTime(lstq[i].Year,lstq[i].Month, 1).AddMonths(1).AddDays(-1);

                //DateTime dt = DateTime.Today;
                lvi1.Text = lstq[i+1].ToString();  //lastDayOfThisMonth.AddMonths(1).ToString("d");

                //lstdatesched.Add(lastDayOfThisMonth.ToString());
                lstdatesched.Add(lvi1.Text.ToString());
                no_ofDays = Convert.ToInt32(lastDayOfThisMonth.Day.ToString());
                // no_ofDays = Convert.ToInt32(lastDayOfThisMonth.AddMonths(Convert.ToInt16(lvi1.Text.Substring(1).ToString())).Day.ToString());

                pmt = 0.0005; //0.015 / 30;  //
                pmt1 = pmt * no_ofDays;
                getamnt1 = getamnt * pmt1;
                re = (mntDue) - getamnt1;
                tmp = getamnt;
                getamnt = getamnt - re;

                if (getamnt >= 0)
                {
                    lvi1.SubItems.Add(mntDue.ToString("#,###0.00"));
                    lvi1.SubItems.Add(getamnt1.ToString("#,###0.00"));
                }

                monthstoPay = monthstoPay + 1;
                lstamt.Add(getamnt);
                if (getamnt <= 0)
                {
                    double tmp_mnt = tmp + getamnt1;
                    lvi1.SubItems.Add(tmp_mnt.ToString("#,###0.00"));
                    lvi1.SubItems.Add("0.00".ToString());
                    lvi1.SubItems.Add("0.00".ToString());
                    txtmonthstopay.Text = monthstoPay - 1 + " " + "Months to pay";
                    lvi1.SubItems.Add("Pending");
                    lsvPaymentSched.Items.Add(lvi1);
                    return;
                }
                else
                {
                    lvi1.SubItems.Add(getamnt.ToString("#,###0.00"));
                }
                lvi1.SubItems.Add("Pending");
                lsvPaymentSched.Items.Add(lvi1);
                //schedule_of_payment_id, schedule_date, cust_id, remarks

            }

            //=================

                //foreach (DateTime eel in lstq)
                //{
                //   ListViewItem lvi1 = new ListViewItem();
                //   DateTime lastDayOfThisMonth = new DateTime(eel.Year, eel.Month, 1).AddMonths(1).AddDays(-1);

                //    //DateTime dt = DateTime.Today;
                //  lvi1.Text = lastDayOfThisMonth.AddMonths(1).ToString("d");

                //   //lstdatesched.Add(lastDayOfThisMonth.ToString());
                //   lstdatesched.Add(lvi1.Text.ToString());
                //   no_ofDays = Convert.ToInt32(lastDayOfThisMonth.Day.ToString());
                //  // no_ofDays = Convert.ToInt32(lastDayOfThisMonth.AddMonths(Convert.ToInt16(lvi1.Text.Substring(1).ToString())).Day.ToString());

                //   pmt = 0.0005; //0.015 / 30;  //
                //   pmt1 = pmt * no_ofDays;
                //   getamnt1 = getamnt * pmt1;
                //   re = (mntDue) - getamnt1;
                //   tmp = getamnt;
                //   getamnt = getamnt - re;

                //   if (getamnt >= 0)
                //   {
                //       lvi1.SubItems.Add(mntDue.ToString("#,###0.00"));
                //       lvi1.SubItems.Add(getamnt1.ToString("#,###0.00"));
                //   }

                //   monthstoPay = monthstoPay + 1;
                //   lstamt.Add(getamnt);
                //  if (getamnt <= 0)
                //   {
                //       double tmp_mnt = tmp + getamnt1;
                //       lvi1.SubItems.Add(tmp_mnt.ToString("#,###0.00"));
                //       lvi1.SubItems.Add("0.00".ToString());
                //       lvi1.SubItems.Add("0.00".ToString());
                //       txtmonthstopay.Text = monthstoPay - 1 + " " + "Months to pay";
                //       lvi1.SubItems.Add("Pending");
                //       lsvPaymentSched.Items.Add(lvi1);
                //       return;
                //   }
                //   else
                //   {
                //       lvi1.SubItems.Add(getamnt.ToString("#,###0.00"));
                //   }
                //   lvi1.SubItems.Add("Pending");
                //   lsvPaymentSched.Items.Add(lvi1);
                //    //schedule_of_payment_id, schedule_date, cust_id, remarks

                //}
        }
 private void textBox1_TextChanged(object sender, EventArgs e)
 {
     cl_moneylender cl = new cl_moneylender();
     cl.SearchLenderByName(textBox1.Text, lsvLender);
     if (!string.IsNullOrEmpty(textBox1.Text))
     {
         this.lsvLender.BringToFront();
         this.lsvLender.Location = new Point(282, 79);
         this.lsvLender.Visible = true;
     }
     else if(textBox1.Text == "")
     {
         this.lsvLender.Visible = false;
     }
 }
 private void lsvLender_DoubleClick(object sender, EventArgs e)
 {
     cl_moneylender ml = new cl_moneylender();
     int ml_ID = Convert.ToInt32(lsvLender.SelectedItems[0].Text);
     mYLenderIDs = ml_ID;
     ml.LOADTOFIELDS(ml_ID);
     textBox1.Text = ml.propfname + " " + ml.propMI + " " + ml.proplname;
     txtlenderID.Text = ml.propLenderID;
     this.lsvLender.Visible = false;
 }
        private void lsvLender_DoubleClick(object sender, EventArgs e)
        {
            cl_moneylender ml = new cl_moneylender();
            cl_lender_inform lendIn = new cl_lender_inform();

            int ml_ID = Convert.ToInt32(lsvLender.SelectedItems[0].Text);
            mYLenderIDs = ml_ID;
            ml.LOADTOFIELDS(ml_ID);
            txtborrwersName.Text = ml.propfname + " " + ml.propMI + " " + ml.proplname;
            txtlenderID.Text = ml.propLenderID;
            txtAddress.Text = ml.propAddress;
            lendIn.PaySched(ml_ID);

            txtPenalty.Text = lendIn.propHpenalty.ToString("#,##0.00");
            this.lsvLender.Visible = false;
            cl_lender_inform le = new cl_lender_inform();

            le.hasBorrowerPenalty(ml_ID);
            txtAmountApplied.Text = lendIn.propPrinc.ToString("#,##0.00");
            double xd = lendIn.propMnt_amount + lendIn.propHpenalty;
            txtMonthlyDues.Text = xd.ToString("#,##0.00");
        }