Ejemplo n.º 1
0
        private void LoadData(string date, string strSearch)
        {
            List <CONTRACT_FULL_VW> dataList = CommonList.GetWarningData(date, strSearch, STORE_ID);

            rptWarning.DataSource = dataList;
            rptWarning.DataBind();
        }
Ejemplo n.º 2
0
 public bool IsBadContract(int contractId)
 {
     using (var db = new RentBikeEntities())
     {
         return(CommonList.IsBadContract(db, contractId));
     }
 }
Ejemplo n.º 3
0
        public CommonList GetaticleList(int pageIndex, int PageSize, string where)
        {
            articleDal dal    = new articleDal();
            CommonList Result = dal.GetarticleList(pageIndex, PageSize, where);

            return(Result);
        }
Ejemplo n.º 4
0
        public CommonList GetarticleList(int pageIndex, int pageSize, string where)
        {
            if (string.IsNullOrEmpty(where))
            {
                where = " 1=1";
            }
            where += " and isdel=0";
            int    n     = 0;
            string filds = "id,title,[desc],content,click_count,is_recommend,date_publish,username,tag,(select name from blog_category where id = category) as category,isdel";

            //文章列表
            SqlParameter[] sp =
            {
                new SqlParameter("@TableFields", filds),
                new SqlParameter("@TableName",   "blog_article"),
                new SqlParameter("@SqlWhere",    where),
                new SqlParameter("@OrderBy",     "id"),
                new SqlParameter("@PageIndex",   pageIndex),
                new SqlParameter("@PageSize",    pageSize),
                new SqlParameter("@TotalCount",  n)
            };
            sp[6].Direction = System.Data.ParameterDirection.InputOutput;//设置条数为返回参数

            List <blog_article> article = SQLHelper.ExcuteList <blog_article>("Proc_Paging", CommandType.StoredProcedure, sp);
            CommonList          Result  = new CommonList();

            Result.pageinfo = new PageInfo {
                PaggeSize  = pageSize,
                TotalCount = Convert.ToInt32(sp[6].Value)
            };
            Result.Articlelist = article;
            return(Result);
        }
Ejemplo n.º 5
0
        void InitFilter()
        {
            CommonList.GroupBy(x => x.Manufacturer).ForEach(m => {
                manufacturers.Add(m.Key);
            });
            SelectedManufacturer = manufacturers.FirstOrDefault();

            RefreshModels();
        }
 void RefreshModels()
 {
     models.Clear();
     CommonList.Where(man => man.Manufacturer == SelectedManufacturer)
     .GroupBy(x => x.Model)
     .ForEach(m => {
         models.Add(m.Key);
     });
     SelectedModel = models.FirstOrDefault();
 }
Ejemplo n.º 7
0
 void RefreshFirmwares()
 {
     firmwares.Clear();
     CommonList.Where(man => man.Manufacturer == SelectedManufacturer)
     .GroupBy(x => x.Firmware)
     .ForEach(f => {
         firmwares.Add(f.Key);
     });
     SelectedFirmware = firmwares.FirstOrDefault();
 }
Ejemplo n.º 8
0
 private void LoadStore(int permissionid)
 {
     ddlStore.Items.Add(new ListItem("--Tất cả cửa hàng--", ""));
     CommonList.LoadStore(ddlStore);
     if (permissionid != (int)ROLE.ADMIN)
     {
         ddlStore.SelectedValue = Session["store_id"].ToString();
         ddlStore.Enabled       = false;
     }
 }
Ejemplo n.º 9
0
        void RefreshList()
        {
            items.Clear();
            CommonList.ForEach(elem => elem.IsChecked = false);

            CommonList.Where(item => item.Manufacturer == SelectedManufacturer && item.Model == SelectedModel && item.Firmware == SelectedFirmware)
            .ForEach(it => {
                it.IsChecked = true;
                items.Add(it);
            });
        }
Ejemplo n.º 10
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                // Lock on the readonly object.
                if (!Singleton.IsRunningBatch())
                {
                    Singleton.CreateSingletonFile();

                    Logger.Log("Backup database start");
                    CommonList.BackUp();
                    Logger.Log("Backup database end");

                    Logger.Log("Save summary fee daily start");
                    CommonList.SaveSummaryPayFeeDaily();
                    Logger.Log("Save summary fee daily end");

                    int day = Convert.ToInt32(WebConfigurationManager.AppSettings["RentBike.EndDayOfMonth"]);
                    if (day == 0)
                    {
                        day = 6;
                    }

                    if (Helper.IsDay(day))
                    {
                        Logger.Log("Save summary fee montly start");
                        CommonList.SaveSummaryPayFeeMonthly();
                        Logger.Log("Save summary fee montly start");
                    }

                    Logger.Log("Auto extend contract start");
                    CommonList.AutoExtendContract();
                    Logger.Log("Auto extend contract end");

                    Logger.Log("Auto create dummy inout start");
                    CommonList.CreateDummyInout();
                    Logger.Log("Auto create dummy inout end");

                    Logger.Log("Backup database into dropbox start");
                    DropboxHelper.BackUp();
                    Logger.Log("Backup database into dropbox end");
                }
            }
            catch (Exception ex)
            {
                Logger.Log("Error Entry at: " + ex.Message + Environment.NewLine + ex.StackTrace);
            }
            finally
            {
                Singleton.DeleteSingletonFile();
            }
        }
Ejemplo n.º 11
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            // SAVE INOUT
            int periodId = Convert.ToInt32(Request.QueryString["ID"]);

            using (var db = new RentBikeEntities())
            {
                if (!string.IsNullOrEmpty(txtIncome.Text))
                {
                    var pp = db.PayPeriods.FirstOrDefault(s => s.ID == periodId);
                    pp.ACTUAL_PAY = Convert.ToDecimal(txtIncome.Text) + pp.ACTUAL_PAY;
                    db.SaveChanges();

                    var contract                    = db.Contracts.FirstOrDefault(c => c.ID == pp.CONTRACT_ID && c.CONTRACT_STATUS == true);
                    List <PayPeriod> payList        = db.PayPeriods.Where(c => c.CONTRACT_ID == pp.CONTRACT_ID).ToList();
                    decimal          totalActualPay = payList.Select(c => c.ACTUAL_PAY).DefaultIfEmpty(0).Sum();
                    decimal          totalPlanPay   = payList.Select(c => c.AMOUNT_PER_PERIOD).DefaultIfEmpty(0).Sum();

                    if (totalActualPay > totalPlanPay)
                    {
                        CommonList.CreatePayPeriod(db, contract.ID, payList.LastOrDefault(), false);
                    }

                    InOut io = new InOut();
                    io.IN_AMOUNT     = Convert.ToDecimal(txtIncome.Text);
                    io.OUT_AMOUNT    = 0;
                    io.CONTRACT_ID   = pp.CONTRACT_ID;
                    io.PERIOD_ID     = pp.ID;
                    io.RENT_TYPE_ID  = contract.RENT_TYPE_ID;
                    io.INOUT_TYPE_ID = Convert.ToInt32(ddInOutType.SelectedValue);
                    io.PERIOD_DATE   = pp.PAY_DATE;
                    io.MORE_INFO     = txtMoreInfo.Text.Trim();
                    io.STORE_ID      = Convert.ToInt32(Session["store_id"]);
                    io.SEARCH_TEXT   = string.Format("{0} ", io.MORE_INFO);
                    io.INOUT_DATE    = DateTime.Now;
                    io.CREATED_BY    = Session["username"].ToString();
                    io.CREATED_DATE  = DateTime.Now;
                    io.UPDATED_BY    = Session["username"].ToString();
                    io.UPDATED_DATE  = DateTime.Now;

                    db.InOuts.Add(io);
                    db.SaveChanges();

                    var    customer = db.Customers.FirstOrDefault(c => c.ID == contract.CUSTOMER_ID);
                    string message  = string.Format("Tài khoản {0} cửa hàng {1} thực hiện thu phí kỳ hạn ngày {2} của hợp đồng {3} số tiền {4} vào lúc {5}", Convert.ToString(Session["username"]), STORE_NAME, pp.PAY_DATE.ToString("dd/MM/yyyy"), customer.NAME, Helper.FormatedAsCurrency(io.IN_AMOUNT), DateTime.Now);
                    Helper.WriteLog(Convert.ToString(Session["username"]), STORE_NAME, Constants.ACTION_CREATE_INOUT, message, false);

                    Response.Redirect("FormContractUpdate.aspx?ID=" + pp.CONTRACT_ID, false);
                }
            }
        }
Ejemplo n.º 12
0
        public LoanInformation GetListingDefaultValuesForLoanInformation()
        {
            LoanInformation lstListingModel = new LoanInformation();
            DBUtility       objUtility      = new DBUtility();

            _cmd = new SqlCommand();
            var _ds = new DataSet();

            _cmd.CommandType = CommandType.StoredProcedure;
            _cmd.CommandText = "GP_SP_GetListingDefaultValuesForLoanInformation";
            _ds = objUtility.FillDataSet(_cmd, _ds);
            lstListingModel.RateType                      = new List <CommonList>();
            lstListingModel.AmortizationType              = new List <CommonList>();
            lstListingModel.PaymentsFrequency             = new List <CommonList>();
            lstListingModel.LienPositionType              = new List <CommonList>();
            lstListingModel.JuniorTrustDeedORMortgageList = new List <CommonList>();

            for (int i = 0; i < _ds.Tables.Count; i++)
            {
                foreach (DataRow dr in _ds.Tables[i].Rows)
                {
                    CommonList temp = new CommonList();
                    temp.ID   = Convert.ToInt32(dr["ID"]);
                    temp.Name = Convert.ToString(dr["Name"]);
                    if (i == 0)
                    {
                        lstListingModel.RateType.Add(temp);
                    }
                    if (i == 1)
                    {
                        lstListingModel.AmortizationType.Add(temp);
                    }
                    if (i == 2)
                    {
                        lstListingModel.PaymentsFrequency.Add(temp);
                    }
                    if (i == 3)
                    {
                        lstListingModel.LienPositionType.Add(temp);
                    }
                    if (i == 4)
                    {
                        lstListingModel.JuniorTrustDeedORMortgageList.Add(temp);
                    }
                }
            }
            return(lstListingModel);
        }
Ejemplo n.º 13
0
        /****************************************************************
         *                         Common Node
         ***************************************************************/

        public Node Common()
        {
            var commonToken = Expect(TokenCategory.COMMON);

            Expect(TokenCategory.DIV);
            var commonId = new Identifier()
            {
                AnchorToken = Expect(TokenCategory.IDENTIFIER)
            };

            Expect(TokenCategory.DIV);

            var commonFields = new CommonList();

            if (CurrentToken == TokenCategory.IDENTIFIER)
            {
                commonFields.Add(new Identifier()
                {
                    AnchorToken = Expect(TokenCategory.IDENTIFIER)
                });
            }

            while (CurrentToken == TokenCategory.COMMA)
            {
                Expect(TokenCategory.COMMA);
                commonFields.Add(new Identifier()
                {
                    AnchorToken = Expect(TokenCategory.IDENTIFIER)
                });
            }

            var commonResult = new Common()
            {
                commonId, commonFields
            };

            commonResult.AnchorToken = commonToken;
            return(commonResult);
        }
Ejemplo n.º 14
0
        private void ReadDataDele()
        {
            var instanceSheetName = "Default";
            var commonSheetName   = "Common";

            this.InstaceList = ExcelHelper.GetContentVertical(DataPath, instanceSheetName);
            var temp = ExcelHelper.GetContent(DataPath, commonSheetName);

            this.CommonList = new List <KeyValue>();
            foreach (var item in temp)
            {
                var kv = new KeyValue();
                kv.Key   = item[0].Value;
                kv.Value = item[1].Value;
                CommonList.Add(kv);
            }
            ExcelHelper.KillProcess();

            this.BeginInvoke(new DeleParaNone(ReadDataAction));

            base.EndExecute(null);
        }
Ejemplo n.º 15
0
        public PropertyInformation GetListingDefaultValuesForPropertyInformation()
        {
            PropertyInformation lstListingModel = new PropertyInformation();
            DBUtility           objUtility      = new DBUtility();

            _cmd = new SqlCommand();
            var _ds = new DataSet();

            _cmd.CommandType = CommandType.StoredProcedure;
            _cmd.CommandText = "GP_SP_GetListingDefaultValuesForPropertyInformation";
            _ds = objUtility.FillDataSet(_cmd, _ds);
            lstListingModel.PropertyType    = new List <CommonList>();
            lstListingModel.OccupancyStatus = new List <CommonList>();
            lstListingModel.ValuationType   = new List <CommonList>();
            for (int i = 0; i < _ds.Tables.Count; i++)
            {
                foreach (DataRow dr in _ds.Tables[i].Rows)
                {
                    CommonList temp = new CommonList();
                    temp.ID   = Convert.ToInt32(dr["ID"]);
                    temp.Name = Convert.ToString(dr["Name"]);
                    if (i == 0)
                    {
                        lstListingModel.PropertyType.Add(temp);
                    }
                    if (i == 1)
                    {
                        lstListingModel.OccupancyStatus.Add(temp);
                    }
                    if (i == 2)
                    {
                        lstListingModel.ValuationType.Add(temp);
                    }
                }
            }
            return(lstListingModel);
        }
Ejemplo n.º 16
0
        protected void lnkExportExcel_Click(object sender, EventArgs e)
        {
            DateTime searchDate = DateTime.Today;

            if (!string.IsNullOrEmpty(txtDate.Text))
            {
                searchDate = Convert.ToDateTime(txtDate.Text);
            }

            List <SummaryPayFeeDaily> dataList = CommonList.GetSummaryPayFeeDailyData(searchDate, DateTime.MinValue, txtSearch.Text, STORE_ID);

            if (dataList.Any())
            {
                using (ExcelPackage package = new ExcelPackage())
                {
                    // add a new worksheet to the empty workbook
                    ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("BTP");
                    worksheet.View.ZoomScale        = 90;
                    worksheet.Cells.Style.Font.Size = 12;
                    worksheet.Cells.Style.Font.Name = "Times New Roman";

                    worksheet.Cells[1, 1, 1, 8].Merge                     = true;
                    worksheet.Cells[1, 1, 1, 8].Value                     = "Bảng Thu Phí " + dataList[0].STORE_NAME;
                    worksheet.Row(1).Height                               = 20;
                    worksheet.Cells[1, 1, 1, 8].Style.Font.Bold           = true;
                    worksheet.Cells[1, 1, 1, 8].Style.Font.Size           = 14;
                    worksheet.Cells[1, 1, 1, 8].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;

                    worksheet.Cells[2, 1, 2, 8].Merge                     = true;
                    worksheet.Cells[2, 1, 2, 8].Value                     = "(" + searchDate + ")";
                    worksheet.Row(2).Height                               = 35;
                    worksheet.Cells[2, 1, 2, 8].Style.Font.Bold           = true;
                    worksheet.Cells[2, 1, 2, 8].Style.Font.Size           = 18;
                    worksheet.Cells[2, 1, 2, 8].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;

                    worksheet.Cells[3, 1, 3, 8].Merge = true;
                    worksheet.Cells[3, 1, 3, 8].Value = "";
                    worksheet.Row(2).Height           = 20;

                    worksheet.Column(1).Width          = 5;
                    worksheet.Column(2).Width          = 35;
                    worksheet.Column(3).Width          = 30;
                    worksheet.Column(4).Width          = 30;
                    worksheet.Column(5).Width          = 25;
                    worksheet.Column(6).Width          = 30;
                    worksheet.Column(7).Width          = 20;
                    worksheet.Column(8).Width          = 15;
                    worksheet.Column(7).Style.WrapText = true;

                    worksheet.Cells[4, 1].Value = "#";
                    worksheet.Cells[4, 2].Value = "Tên khách hàng";
                    worksheet.Cells[4, 3].Value = "Loại hình thuê";
                    worksheet.Cells[4, 4].Value = "Số ĐT khách hàng";
                    worksheet.Cells[4, 5].Value = "Giá trị HĐ/Phí";
                    worksheet.Cells[4, 6].Value = "Ghi chú";
                    worksheet.Cells[4, 7].Value = "Số lần đóng phí";
                    worksheet.Cells[4, 8].Value = "Thông báo";
                    worksheet.Cells[4, 1, 4, 8].Style.Font.Bold = true;
                    worksheet.Cells[4, 1, 4, 8].Style.Font.Size = 13;
                    worksheet.Row(4).Height = 25;

                    int no    = 1;
                    int index = 5;
                    foreach (var contract in dataList)
                    {
                        worksheet.Cells[index, 1].Value = no;

                        worksheet.Cells[index, 2].Style.WrapText = true;
                        worksheet.Cells[index, 2].IsRichText     = true;
                        ExcelRichText ert = worksheet.Cells[index, 2].RichText.Add(contract.CUSTOMER_NAME);
                        ert.Bold = true;
                        //ert = worksheet.Cells[index, 2].RichText.Add("\n(" + (contract.BIRTH_DAY == null ? "" : contract.BIRTH_DAY.Value.ToString("dd/MM/yyyy")) + ")");
                        //ert.Bold = false;

                        worksheet.Cells[index, 3].Value = contract.RENT_TYPE_NAME;
                        worksheet.Cells[index, 4].Value = contract.PHONE;
                        worksheet.Cells[index, 5].Value = string.Format("{0:0,0}", contract.PAY_FEE);
                        worksheet.Cells[index, 6].Value = contract.NOTE;
                        worksheet.Cells[index, 7].Value = contract.PAY_TIME + " lần";
                        worksheet.Cells[index, 8].Value = contract.PAY_MESSAGE;

                        no    += 1;
                        index += 1;
                    }

                    worksheet.Cells[4, 1, index, 8].Style.Border.Top.Style    = ExcelBorderStyle.Thin;
                    worksheet.Cells[4, 1, index, 8].Style.Border.Right.Style  = ExcelBorderStyle.Thin;
                    worksheet.Cells[4, 1, index, 8].Style.Border.Bottom.Style = ExcelBorderStyle.Thin;
                    worksheet.Cells[4, 1, index, 8].Style.Border.Left.Style   = ExcelBorderStyle.Thin;

                    Response.Clear();
                    Response.ClearContent();
                    Response.ClearHeaders();

                    if ((Request.Browser.Browser.ToLower() == "ie") && (Request.Browser.MajorVersion < 9))
                    {
                        Response.Cache.SetCacheability(System.Web.HttpCacheability.Private);
                        Response.Cache.SetMaxAge(TimeSpan.FromMilliseconds(1));
                    }
                    else
                    {
                        Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache); //IE set to not cache
                        Response.Cache.SetNoStore();                                         //Firefox/Chrome not to cache
                        Response.Cache.SetExpires(DateTime.UtcNow);                          //for safe measure expire it immediately
                    }

                    string fileName = string.Format("BTP {0}.{1}", searchDate.ToString("dd-MM-yyyy"), "xlsx");
                    Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                    Response.AddHeader("content-disposition", "attachment; filename=\"" + fileName + "\"");
                    Response.BinaryWrite(package.GetAsByteArray());
                    Response.Flush();
                    Response.Close();
                    Response.End();
                }
            }
        }
        private void LoadData(int page)
        {
            using (var db = new RentBikeEntities())
            {
                List <SummaryInfo> listSum = GetSummaryData(STORE_ID);
                if (listSum.Any())
                {
                    int count = ((listSum.LastOrDefault().InOutDate.Year - listSum.FirstOrDefault().InOutDate.Year) * 12) + (listSum.LastOrDefault().InOutDate.Month - listSum.FirstOrDefault().InOutDate.Month) + 1;
                    IEnumerable <int> pageList = Enumerable.Range(1, count);

                    DateTime startDate = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 6);

                    int startMonth = DateTime.Today.Month;
                    int startYear  = DateTime.Today.Year;
                    if (startMonth == 1)
                    {
                        startMonth = 12;
                        startYear  = startYear - 1;
                    }
                    else
                    {
                        startMonth = startMonth - 1;
                    }
                    StartDate = startDate = DateTime.Today < startDate == true ? new DateTime(startYear, startMonth, 6) : startDate;

                    if (page > 1)
                    {
                        startDate = startDate.AddMonths(1 - page);
                        StartDate = startDate = new DateTime(startDate.Year, startDate.Month, 6);
                    }
                    if (ViewState["StartDate"] == null)
                    {
                        ViewState["StartDate"] = StartDate;
                    }

                    DateTime        datePager = Convert.ToDateTime(ViewState["StartDate"]);
                    List <ListItem> listItem  = new List <ListItem>();
                    listItem.Add(new ListItem {
                        Text = datePager.ToString("MM/yyyy"), Value = "1"
                    });
                    for (int i = 1; i < pageList.Count(); i++)
                    {
                        listItem.Add(new ListItem {
                            Text = datePager.AddMonths(-i).ToString("MM/yyyy"), Value = (i + 1).ToString()
                        });
                    }
                    if (listSum.FirstOrDefault().InOutDate < datePager.AddMonths(pageList.Count() - 1))
                    {
                        listItem.Add(new ListItem {
                            Text = datePager.AddMonths(-pageList.Count()).ToString("MM/yyyy"), Value = (pageList.Count() + 1).ToString()
                        });
                    }
                    ddlPager.DataSource     = listItem;
                    ddlPager.DataTextField  = "Text";
                    ddlPager.DataValueField = "Value";
                    ddlPager.DataBind();
                    if (pageList.Count() > 0)
                    {
                        ddlPager.SelectedValue = page.ToString();
                    }
                    if (count > page)
                    {
                        count = page;
                    }

                    int endYear  = startDate.Year;
                    int endMonth = startDate.Month;
                    if (endMonth == 12)
                    {
                        endMonth = 1;
                        endYear  = endYear + 1;
                    }
                    else
                    {
                        endMonth += 1;
                    }
                    DateTime endDate = new DateTime(endYear, endMonth, 5);

                    txtStartDate.Text = startDate.ToString("dd/MM/yyyy");
                    txtEndDate.Text   = endDate.ToString("dd/MM/yyyy");

                    listSum             = listSum.Where(c => c.InOutDate >= startDate && c.InOutDate <= endDate).OrderByDescending(c => c.InOutDate).ToList();
                    rptInOut.DataSource = listSum;
                    rptInOut.DataBind();

                    decimal beginAmount   = listSum.Select(c => c.BeginAmount).DefaultIfEmpty(0).Sum();
                    decimal contractFee   = listSum.Select(c => c.ContractFee).DefaultIfEmpty(0).Sum();
                    decimal rentFee       = listSum.Select(c => c.RentFee).DefaultIfEmpty(0).Sum();
                    decimal closedFee     = listSum.Select(c => c.CloseFee).DefaultIfEmpty(0).Sum();
                    decimal redundantFee  = listSum.Select(c => c.RedundantFee).DefaultIfEmpty(0).Sum();
                    decimal outOtherFee   = listSum.Select(c => c.OutOther).DefaultIfEmpty(0).Sum();
                    decimal inOtherFee    = listSum.Select(c => c.InOther).DefaultIfEmpty(0).Sum();
                    decimal outCapitalFee = listSum.Select(c => c.OutCapital).DefaultIfEmpty(0).Sum();
                    decimal inCapitalFee  = listSum.Select(c => c.InCapital).DefaultIfEmpty(0).Sum();
                    decimal endAmount     = listSum.Select(c => c.EndAmount).DefaultIfEmpty(0).Sum();

                    Label lblTotalBegin        = (Label)rptInOut.Controls[rptInOut.Controls.Count - 1].Controls[0].FindControl("lblTotalBegin");
                    Label lblTotalContractFee  = (Label)rptInOut.Controls[rptInOut.Controls.Count - 1].Controls[0].FindControl("lblTotalContractFee");
                    Label lblTotalRentFee      = (Label)rptInOut.Controls[rptInOut.Controls.Count - 1].Controls[0].FindControl("lblTotalRentFee");
                    Label lblTotalClosedFee    = (Label)rptInOut.Controls[rptInOut.Controls.Count - 1].Controls[0].FindControl("lblTotalClosedFee");
                    Label lblTotalRedundantFee = (Label)rptInOut.Controls[rptInOut.Controls.Count - 1].Controls[0].FindControl("lblTotalRedundantFee");
                    Label lblTotalOutOtherFee  = (Label)rptInOut.Controls[rptInOut.Controls.Count - 1].Controls[0].FindControl("lblTotalOutOtherFee");
                    Label lblTotalInOtherFee   = (Label)rptInOut.Controls[rptInOut.Controls.Count - 1].Controls[0].FindControl("lblTotalInOtherFee");
                    Label lblTotalOutCapital   = (Label)rptInOut.Controls[rptInOut.Controls.Count - 1].Controls[0].FindControl("lblTotalOutCapital");
                    Label lblTotalInCapital    = (Label)rptInOut.Controls[rptInOut.Controls.Count - 1].Controls[0].FindControl("lblTotalInCapital");
                    Label lblTotalEnd          = (Label)rptInOut.Controls[rptInOut.Controls.Count - 1].Controls[0].FindControl("lblTotalEnd");

                    lblTotalContractFee.Text  = contractFee == 0 ? "0" : string.Format("{0:0,0}", contractFee);
                    lblTotalRentFee.Text      = rentFee == 0 ? "0" : string.Format("{0:0,0}", rentFee);
                    lblTotalClosedFee.Text    = closedFee == 0 ? "0" : string.Format("{0:0,0}", closedFee);
                    lblTotalRedundantFee.Text = redundantFee == 0 ? "0" : string.Format("{0:0,0}", redundantFee);
                    lblTotalOutOtherFee.Text  = outOtherFee == 0 ? "0" : string.Format("{0:0,0}", outOtherFee);
                    lblTotalInOtherFee.Text   = inOtherFee == 0 ? "0" : string.Format("{0:0,0}", inOtherFee);
                    lblTotalOutCapital.Text   = outCapitalFee == 0 ? "0" : string.Format("{0:0,0}", outCapitalFee);
                    lblTotalInCapital.Text    = inCapitalFee == 0 ? "0" : string.Format("{0:0,0}", inCapitalFee);

                    lblTotalContractAmount.Text = contractFee == 0 ? "0" : string.Format("{0:0,0}", contractFee);
                    lblClosedAmount.Text        = closedFee == 0 ? "0" : string.Format("{0:0,0}", closedFee);
                    lblResultAmount.Text        = contractFee - closedFee == 0 ? "0" : string.Format("{0:0,0}", contractFee - closedFee);
                    lblTotalInAmount.Text       = rentFee + inOtherFee == 0 ? "0" : string.Format("{0:0,0}", rentFee + inOtherFee);
                    lblTotalOutAmount.Text      = redundantFee + outOtherFee == 0 ? "0" : string.Format("{0:0,0}", redundantFee + outOtherFee);
                    lblRevenue.Text             = (rentFee + inOtherFee) - (redundantFee + outOtherFee) == 0 ? "0" : string.Format("{0:0,0}", (rentFee + inOtherFee) - (redundantFee + outOtherFee));

                    List <SummaryPayFeeDaily> dataListMonthly = CommonList.GetSummaryPayFeeDailyData(startDate, endDate, string.Empty, STORE_ID);
                    int[]   monthlycontractIds = dataListMonthly.Select(c => c.CONTRACT_ID).ToArray();
                    decimal totalMonthlyFee    = dataListMonthly.Where(c => monthlycontractIds.Contains(c.CONTRACT_ID)).Select(c => c.PAY_FEE).DefaultIfEmpty(0).Sum();

                    lblTotalInCapitalF.Text  = inCapitalFee == 0 ? "0" : string.Format("{0:0,0}", inCapitalFee);
                    lblTotalOutCapitalF.Text = outCapitalFee == 0 ? "0" : string.Format("{0:0,0}", outCapitalFee);
                    lblTotalTheoryFee.Text   = totalMonthlyFee == 0 ? "0" : string.Format("{0:0,0}", totalMonthlyFee);
                    lblTotalRealFee.Text     = rentFee == 0 ? "0" : string.Format("{0:0,0}", rentFee);

                    decimal totalSlowFee = 0, totalDebtFee = 0;
                    var     sumMonthlies = db.SummaryPayFeeMonthlies.Where(c => c.SUMMURY_DATE.Month == startDate.Month && c.SUMMURY_DATE.Year == startDate.Year);
                    if (STORE_ID != 0)
                    {
                        sumMonthlies = sumMonthlies.Where(c => c.STORE_ID == STORE_ID);
                    }

                    if (sumMonthlies.Any())
                    {
                        totalSlowFee = sumMonthlies.Where(c => c.SUMMURY_FEE_TYPE == (int)SUMMURY_FEE_TYPE.SLOW_FEE).Select(c => c.SUMMURY_FEE).DefaultIfEmpty(0).Sum();
                        totalDebtFee = sumMonthlies.Where(c => c.SUMMURY_FEE_TYPE == (int)SUMMURY_FEE_TYPE.DEBT_FEE).Select(c => c.SUMMURY_FEE).DefaultIfEmpty(0).Sum();
                    }
                    else
                    {
                        CommonList.GetSummuryFeeMonthly(out totalSlowFee, out totalDebtFee, STORE_ID);
                    }

                    lblTotalSlowFee.Text = totalSlowFee == 0 ? "0" : string.Format("{0:0,0}", totalSlowFee);
                    lblTotalDebtFee.Text = totalDebtFee == 0 ? "0" : string.Format("{0:0,0}", totalDebtFee);
                }
            }
        }
Ejemplo n.º 18
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                using (TransactionScope ts = new TransactionScope())
                {
                    string id     = Request.QueryString["ID"];
                    string copy   = Request.QueryString["copy"];
                    string result = ValidateFields();
                    int    cusid  = 0;

                    if (!string.IsNullOrEmpty(result))
                    {
                        lblMessage.Text = result;
                        return;
                    }

                    if (string.IsNullOrEmpty(id) || (!string.IsNullOrEmpty(copy) && copy == "1")) // NEW
                    {
                        Contract contract = CommonList.GetContractByLicenseNo(txtLicenseNumber.Text.Trim());
                        if (contract != null)
                        {
                            // Initialize StringWriter instance.
                            StringWriter stringWriter = new StringWriter();
                            // Put HtmlTextWriter in using block because it needs to call Dispose.
                            using (HtmlTextWriter writer = new HtmlTextWriter(stringWriter))
                            {
                                writer.Write("Số CMTND/GPLX này hiện tại đã đăng ký hợp đồng ");
                                writer.AddAttribute(HtmlTextWriterAttribute.Href, string.Format("FormContractUpdate.aspx?ID={0}&sID={1}", contract.ID, contract.STORE_ID));
                                writer.RenderBeginTag(HtmlTextWriterTag.A); // Start of A
                                writer.Write(contract.CONTRACT_NO);
                                writer.RenderEndTag();                      //End of A

                                lblMessage.Text = stringWriter.ToString();
                                return;
                            }
                        }
                        Customer cusItem = null;
                        using (var db = new RentBikeEntities())
                        {
                            bool IsNewCust = false;
                            cusItem = db.Customers.FirstOrDefault(c => c.LICENSE_NO == txtLicenseNumber.Text.Trim() && c.NAME == txtCustomerName.Text.Trim());
                            if (cusItem == null)
                            {
                                IsNewCust = true;
                                cusItem   = new Customer();
                            }

                            cusItem.NAME                = txtCustomerName.Text.Trim();
                            cusItem.BIRTH_DAY           = DateTime.ParseExact(txtBirthDay.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture);
                            cusItem.LICENSE_NO          = txtLicenseNumber.Text.Trim();
                            cusItem.LICENSE_RANGE_DATE  = DateTime.ParseExact(txtRangeDate.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture);
                            cusItem.LICENSE_RANGE_PLACE = txtPlaceDate.Text.Trim();
                            cusItem.PHONE               = txtPhone.Text.Trim();
                            cusItem.PERMANENT_RESIDENCE = txtPermanentResidence.Text.Trim();
                            cusItem.CURRENT_RESIDENCE   = txtCurrentResidence.Text.Trim();

                            if (IsNewCust)
                            {
                                db.Customers.Add(cusItem);
                            }
                            db.SaveChanges();
                            cusid = cusItem.ID;
                        }

                        // New Contract
                        Contract item = new Contract();
                        item.RENT_TYPE_ID = Convert.ToInt32(ddlRentType.SelectedValue);
                        item.FEE_PER_DAY  = Math.Round(Convert.ToDecimal(txtFeePerDay.Text.Replace(",", string.Empty)));
                        if (!string.IsNullOrEmpty(txtRentDate.Text))
                        {
                            item.RENT_DATE = DateTime.ParseExact(txtRentDate.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture);
                        }
                        else
                        {
                            item.RENT_DATE = DateTime.Now;
                        }

                        if (!string.IsNullOrEmpty(txtEndDate.Text))
                        {
                            item.END_DATE = DateTime.ParseExact(txtEndDate.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture);
                        }
                        else
                        {
                            item.END_DATE = item.RENT_DATE.AddDays(29);
                        }
                        item.EXTEND_END_DATE     = item.END_DATE;
                        item.CLOSE_CONTRACT_DATE = new DateTime(1, 1, 1);
                        item.PAY_FEE_MESSAGE     = string.Empty;
                        item.NOTE              = txtNote.Text;
                        item.REFERENCE_ID      = -1;
                        item.REFERENCE_NAME    = txtReferencePerson.Text.Trim();
                        item.ITEM_TYPE         = txtItemName.Text.Trim();
                        item.ITEM_LICENSE_NO   = txtItemLicenseNo.Text.Trim();
                        item.SERIAL_1          = txtSerial1.Text.Trim();
                        item.SERIAL_2          = txtSerial2.Text.Trim();
                        item.REFERENCE_PHONE   = txtReferencePhone.Text.Trim();
                        item.SCHOOL_NAME       = txtSchool.Text.Trim();
                        item.CLASS_NAME        = txtClass.Text.Trim();
                        item.IMPLEMENTER       = txtImplementer.Text.Trim();
                        item.BACK_TO_DOCUMENTS = txtBackDocument.Text.Trim();
                        item.DETAIL            = txtItemDetail.Text.Trim();
                        item.CUSTOMER_ID       = cusid;
                        item.CONTRACT_STATUS   = true;
                        item.CONTRACT_AMOUNT   = Convert.ToDecimal(txtAmount.Text.Replace(",", string.Empty));
                        item.CREATED_BY        = Session["username"].ToString();
                        item.CREATED_DATE      = DateTime.Now;
                        item.UPDATED_BY        = Session["username"].ToString();
                        item.UPDATED_DATE      = DateTime.Now;
                        //item.CONTRACT_NO = txtContractNo.Text.Trim();
                        if (ddlStore.Enabled == true)
                        {
                            item.STORE_ID = Convert.ToInt32(ddlStore.SelectedValue);
                        }
                        else
                        {
                            item.STORE_ID = Convert.ToInt32(Session["store_id"]);
                        }
                        item.SEARCH_TEXT = string.Format("{0} {1} {2} {3} {4} {5} {6} {7} {8}",
                                                         txtCustomerName.Text.Trim(),
                                                         txtBirthDay.Text.Trim(),
                                                         txtLicenseNumber.Text.Trim(),
                                                         txtRangeDate.Text.Trim(),
                                                         txtPermanentResidence.Text.Trim(),
                                                         txtCurrentResidence.Text.Trim(),
                                                         txtPhone.Text.Trim(),
                                                         item.CONTRACT_NO,
                                                         item.RENT_DATE.ToString("dd/MM/yyyy"));
                        SavePhoto(item);
                        using (var db = new RentBikeEntities())
                        {
                            db.Contracts.Add(item);
                            db.SaveChanges();


                            DateTime periodTime = DateTime.Today;
                            if (!string.IsNullOrEmpty(txtRentDate.Text))
                            {
                                periodTime = DateTime.ParseExact(txtRentDate.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture);
                            }
                            PayPeriod newPeriod = new PayPeriod();
                            newPeriod.PAY_DATE = periodTime;
                            CommonList.CreatePayPeriod(db, item.ID, newPeriod, true);
                        }

                        InOut io = new InOut();
                        io.CONTRACT_ID  = item.ID;
                        io.IN_AMOUNT    = 0;
                        io.OUT_AMOUNT   = Convert.ToDecimal(txtAmount.Text);
                        io.RENT_TYPE_ID = Convert.ToInt32(ddlRentType.SelectedValue);
                        io.PERIOD_DATE  = DateTime.Now;
                        io.MORE_INFO    = string.Format("Cho khách {0} thuê: {1} ngày {2} trị giá {3}", txtCustomerName.Text.Trim(), txtItemName.Text.Trim(), DateTime.Now.ToString("dd/MM/yyyy"), txtAmount.Text.Trim());
                        if (ddlStore.Enabled == true)
                        {
                            io.STORE_ID = Convert.ToInt32(ddlStore.SelectedValue);
                        }
                        else
                        {
                            io.STORE_ID = Convert.ToInt32(Session["store_id"]);
                        }
                        io.SEARCH_TEXT   = string.Format("{0} ", io.MORE_INFO);
                        io.INOUT_DATE    = DateTime.Now;
                        io.CREATED_BY    = Session["username"].ToString();
                        io.CREATED_DATE  = DateTime.Now;
                        io.UPDATED_BY    = Session["username"].ToString();
                        io.UPDATED_DATE  = DateTime.Now;
                        io.INOUT_TYPE_ID = CommonList.GetInoutTypeFromRentType(Helper.parseInt(ddlRentType.SelectedValue));

                        using (var rbdb = new RentBikeEntities())
                        {
                            rbdb.InOuts.Add(io);
                            rbdb.SaveChanges();

                            CommonList.AutoExtendPeriod(rbdb, item.ID);
                        }
                        string message = string.Format("Tài khoản {0} cửa hàng {1} thực hiện làm hợp đồng cho khách hàng {2} vào lúc {3}", Convert.ToString(Session["username"]), STORE_NAME, cusItem.NAME, DateTime.Now);
                        Helper.WriteLog(Convert.ToString(Session["username"]), STORE_NAME, Constants.ACTION_CREATE_CONTRACT, message, false);
                        ts.Complete();
                    }
                    else // EDIT
                    {
                        result = ValidatePermission();
                        if (!string.IsNullOrEmpty(result))
                        {
                            lblMessage.Text = result;
                            return;
                        }

                        int  contractId            = Helper.parseInt(id);
                        bool bUpdateInOutAndPeriod = false;
                        using (var db = new RentBikeEntities())
                        {
                            var     item           = db.Contracts.FirstOrDefault(itm => itm.ID == contractId);
                            int     rentTypeId     = Helper.parseInt(ddlRentType.SelectedValue);
                            decimal contractAmount = Convert.ToDecimal(txtAmount.Text);
                            decimal feePerDay      = Convert.ToDecimal(txtFeePerDay.Text);

                            if (contractAmount != item.CONTRACT_AMOUNT || rentTypeId != item.RENT_TYPE_ID || feePerDay != item.FEE_PER_DAY)
                            {
                                bUpdateInOutAndPeriod = true;
                            }


                            if (bUpdateInOutAndPeriod)
                            {
                                //Update for contract record only.
                                int inOutTypeId = CommonList.GetInoutTypeFromRentType(item.RENT_TYPE_ID);
                                var inOut       = db.InOuts.FirstOrDefault(c => c.CONTRACT_ID == contractId && c.INOUT_TYPE_ID == inOutTypeId);
                                if (inOut != null)
                                {
                                    // SAVE INOUT
                                    inOut.OUT_AMOUNT    = contractAmount;
                                    inOut.RENT_TYPE_ID  = rentTypeId;
                                    inOut.INOUT_TYPE_ID = CommonList.GetInoutTypeFromRentType(rentTypeId);
                                    inOut.MORE_INFO     = inOut.SEARCH_TEXT = string.Format("Cho khách {0} thuê: {1} ngày {2} trị giá {3}", txtCustomerName.Text.Trim(), txtItemName.Text.Trim(), DateTime.Now.ToString("dd/MM/yyyy"), txtAmount.Text.Trim());
                                    inOut.UPDATED_BY    = Session["username"].ToString();
                                    inOut.UPDATED_DATE  = DateTime.Now;
                                }

                                //Update for others in out record of the contract
                                var listInOut = db.InOuts.Where(c => c.CONTRACT_ID == contractId && c.RENT_TYPE_ID == item.RENT_TYPE_ID).ToList();
                                foreach (var io in listInOut)
                                {
                                    io.RENT_TYPE_ID = rentTypeId;
                                    io.UPDATED_BY   = Session["username"].ToString();
                                    io.UPDATED_DATE = DateTime.Now;
                                }

                                //Update for 3 first PayPeriod records
                                List <PayPeriod> listPayPeriod = db.PayPeriods.Where(c => c.CONTRACT_ID == contractId).ToList();
                                foreach (var pp in listPayPeriod.Take(3))
                                {
                                    pp.AMOUNT_PER_PERIOD = feePerDay * 10;
                                }

                                //Update for remain PayPeriod records
                                int     multipleFee      = Convert.ToInt32(Decimal.Floor(contractAmount / 100000));
                                decimal increateFeeCar   = (feePerDay * 10) + (multipleFee * 50 * 10);
                                decimal increateFeeEquip = (feePerDay * 10) + (multipleFee * 100 * 10);
                                decimal increateFeeOther = (feePerDay * 10);
                                foreach (var pp in listPayPeriod.Skip(3))
                                {
                                    switch (rentTypeId)
                                    {
                                    case 1:
                                        if (((feePerDay / multipleFee) * 10) < 4000)
                                        {
                                            pp.AMOUNT_PER_PERIOD = increateFeeCar;
                                        }
                                        else
                                        {
                                            pp.AMOUNT_PER_PERIOD = feePerDay * 10;
                                        }
                                        break;

                                    case 2:
                                        if (((feePerDay / multipleFee) * 10) < 6000)
                                        {
                                            pp.AMOUNT_PER_PERIOD = increateFeeEquip;
                                        }
                                        else
                                        {
                                            pp.AMOUNT_PER_PERIOD = feePerDay * 10;
                                        }
                                        break;

                                    default:
                                        pp.AMOUNT_PER_PERIOD = increateFeeOther;
                                        break;
                                    }
                                }
                            }

                            //Update contract infor
                            item.NOTE              = txtNote.Text;
                            item.REFERENCE_ID      = -1;
                            item.REFERENCE_NAME    = txtReferencePerson.Text.Trim();
                            item.ITEM_TYPE         = txtItemName.Text.Trim();
                            item.ITEM_LICENSE_NO   = txtItemLicenseNo.Text.Trim();
                            item.RENT_TYPE_ID      = Helper.parseInt(ddlRentType.SelectedValue);
                            item.CONTRACT_AMOUNT   = Convert.ToDecimal(txtAmount.Text);
                            item.FEE_PER_DAY       = Convert.ToDecimal(txtFeePerDay.Text);
                            item.SERIAL_1          = txtSerial1.Text.Trim();
                            item.SERIAL_2          = txtSerial2.Text.Trim();
                            item.REFERENCE_PHONE   = txtReferencePhone.Text.Trim();
                            item.SCHOOL_NAME       = txtSchool.Text.Trim();
                            item.CLASS_NAME        = txtClass.Text.Trim();
                            item.IMPLEMENTER       = txtImplementer.Text.Trim();
                            item.BACK_TO_DOCUMENTS = txtBackDocument.Text.Trim();
                            item.DETAIL            = txtItemDetail.Text.Trim();
                            item.SEARCH_TEXT       = string.Format("{0} {1} {2} {3} {4} {5} {6} {7} {8}",
                                                                   txtCustomerName.Text.Trim(),
                                                                   txtBirthDay.Text.Trim(),
                                                                   txtLicenseNumber.Text.Trim(),
                                                                   txtRangeDate.Text.Trim(),
                                                                   txtPermanentResidence.Text.Trim(),
                                                                   txtCurrentResidence.Text.Trim(),
                                                                   txtPhone.Text.Trim(),
                                                                   item.CONTRACT_NO,
                                                                   item.RENT_DATE.ToString("dd/MM/yyyy"));

                            item.UPDATED_BY   = Session["username"].ToString();
                            item.UPDATED_DATE = DateTime.Now;
                            //Contract photo
                            SavePhoto(item);
                            //Update customer infor
                            var cusItem = db.Customers.FirstOrDefault(c => c.ID == item.CUSTOMER_ID);
                            if (cusItem != null)
                            {
                                cusItem.NAME                = txtCustomerName.Text.Trim();
                                cusItem.BIRTH_DAY           = DateTime.ParseExact(txtBirthDay.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture);
                                cusItem.LICENSE_NO          = txtLicenseNumber.Text.Trim();
                                cusItem.LICENSE_RANGE_DATE  = DateTime.ParseExact(txtRangeDate.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture);
                                cusItem.LICENSE_RANGE_PLACE = txtPlaceDate.Text.Trim();
                                cusItem.PHONE               = txtPhone.Text.Trim();
                                cusItem.PERMANENT_RESIDENCE = txtPermanentResidence.Text.Trim();
                                cusItem.CURRENT_RESIDENCE   = txtCurrentResidence.Text.Trim();
                            }

                            db.SaveChanges();

                            string message = string.Format("Tài khoản {0} cửa hàng {1} thực hiện chỉnh sửa hợp đồng của khách hàng {2} vào lúc {3}", Convert.ToString(Session["username"]), STORE_NAME, cusItem.NAME, DateTime.Now);
                            Helper.WriteLog(Convert.ToString(Session["username"]), STORE_NAME, Constants.ACTION_UPDATE_CONTRACT, message, false);
                        }
                        ts.Complete();
                    }
                    Response.Redirect("FormContractManagement.aspx", false);
                }
            }
            catch (Exception ex)
            {
                lblMessage.Text     = ex.Message;
                lblMessage.CssClass = "text-center text-danger";
                Logger.Log(ex.Message);
            }
        }
Ejemplo n.º 19
0
        private void LoadData(string date, string strSearch)
        {
            DateTime searchDate = DateTime.Today;

            if (!string.IsNullOrEmpty(date))
            {
                searchDate = Convert.ToDateTime(date);
            }

            List <SummaryPayFeeDaily> dataListDaily = CommonList.GetSummaryPayFeeDailyData(searchDate, DateTime.MinValue, strSearch, STORE_ID);

            rptSummaryFeeDaily.DataSource = dataListDaily;
            rptSummaryFeeDaily.DataBind();

            using (var db = new RentBikeEntities())
            {
                DateTime startDate = new DateTime(searchDate.Year, searchDate.Month, 6);

                int startMonth = searchDate.Month;
                int startYear  = searchDate.Year;
                if (startMonth == 1)
                {
                    startMonth = 12;
                    startYear  = startYear - 1;
                }
                else
                {
                    startMonth = startMonth - 1;
                }
                StartDate = startDate = searchDate < startDate == true ? new DateTime(startYear, startMonth, 6) : startDate;

                int endYear  = searchDate.Year;
                int endMonth = searchDate.Month;
                if (endMonth + 1 > 12)
                {
                    endMonth = 1;
                    endYear  = endYear + 1;
                }
                DateTime endDate = new DateTime(endYear, endMonth + 1, 5);
                endDate = searchDate < endDate == true ? searchDate : endDate;

                List <SummaryPayFeeDaily> dataListMonthly = CommonList.GetSummaryPayFeeDailyData(startDate, endDate, strSearch, STORE_ID);

                int[] dailyContractIds   = dataListDaily.Select(c => c.CONTRACT_ID).ToArray();
                int[] monthlycontractIds = dataListMonthly.Select(c => c.CONTRACT_ID).ToArray();

                IQueryable <INOUT_FULL_VW> inOutList = db.INOUT_FULL_VW.Where(c => c.ACTIVE == true && (c.INOUT_TYPE_ID == 14 || c.INOUT_TYPE_ID == 15 || c.INOUT_TYPE_ID == 16));
                if (STORE_ID != 0)
                {
                    inOutList = inOutList.Where(c => c.STORE_ID == STORE_ID);
                }
                if (!string.IsNullOrEmpty(strSearch))
                {
                    inOutList = inOutList.Where(c => c.SEARCH_TEXT.ToLower().Contains(strSearch.ToLower()));
                }
                IQueryable <INOUT_FULL_VW> inOutDaily   = inOutList.Where(c => c.INOUT_DATE == searchDate);
                IQueryable <INOUT_FULL_VW> inOutMonthly = inOutList.Where(c => c.INOUT_DATE >= startDate && c.INOUT_DATE <= endDate);

                decimal totalDailyFee              = dataListDaily.Where(c => dailyContractIds.Contains(c.CONTRACT_ID)).Select(c => c.PAY_FEE).DefaultIfEmpty(0).Sum();
                decimal totalActualInAmountDaily   = inOutDaily.Select(c => c.IN_AMOUNT).DefaultIfEmpty(0).Sum();
                decimal totalMonthlyFee            = dataListMonthly.Where(c => monthlycontractIds.Contains(c.CONTRACT_ID)).Select(c => c.PAY_FEE).DefaultIfEmpty(0).Sum();
                decimal totalActualInAmountMonthly = inOutMonthly.Select(c => c.IN_AMOUNT).DefaultIfEmpty(0).Sum();

                lblTotalDailyFee.Text         = string.Format("{0:0,0}", totalDailyFee);
                lblActualTotalDailyFee.Text   = string.Format("{0:0,0}", totalActualInAmountDaily);
                lblTotalMonthlyFee.Text       = string.Format("{0:0,0}", totalMonthlyFee);
                lblActualTotalMonthlyFee.Text = string.Format("{0:0,0}", totalActualInAmountMonthly);
            }
        }
Ejemplo n.º 20
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            using (TransactionScope trans = new TransactionScope())
            {
                int contractId = Convert.ToInt32(Request.QueryString["ID"]);
                using (var db = new RentBikeEntities())
                {
                    var    con = db.CONTRACT_FULL_VW.FirstOrDefault(c => c.ID == contractId && c.ACTIVE == true);
                    string closedContractName = string.Empty;
                    switch (con.RENT_TYPE_ID)
                    {
                    case 1:
                        closedContractName = "Thanh lý thuê xe";
                        break;

                    case 2:
                        closedContractName = "Thanh lý thuê thiết bị";
                        break;

                    default:
                        closedContractName = "Thanh lý thuê khác";
                        break;
                    }
                    // INOUT --> IN amount
                    InOut io1 = new InOut();
                    io1.IN_AMOUNT    = con.CONTRACT_AMOUNT;
                    io1.OUT_AMOUNT   = 0;
                    io1.CONTRACT_ID  = con.ID;
                    io1.PERIOD_ID    = -1;
                    io1.PERIOD_DATE  = new DateTime(1, 1, 1);
                    io1.RENT_TYPE_ID = con.RENT_TYPE_ID;

                    var item = db.InOutTypes.FirstOrDefault(s => s.NAME == "Thanh lý");
                    io1.INOUT_TYPE_ID = item.ID;
                    io1.MORE_INFO     = txtMoreInfo.Text.Trim();
                    io1.STORE_ID      = con.STORE_ID;
                    io1.SEARCH_TEXT   = string.Format("{0} {1} {2} {3} {4}", con.CONTRACT_NO, con.CUSTOMER_NAME, con.STORE_NAME, closedContractName, txtMoreInfo.Text.Trim());
                    io1.INOUT_DATE    = DateTime.Now;
                    io1.CREATED_BY    = Session["username"].ToString();
                    io1.CREATED_DATE  = DateTime.Now;
                    io1.UPDATED_BY    = Session["username"].ToString();
                    io1.UPDATED_DATE  = DateTime.Now;
                    db.InOuts.Add(io1);

                    // IN --> Rent Fee
                    if (!string.IsNullOrEmpty(txtRealIncome.Text))
                    {
                        decimal realInAmount = Convert.ToDecimal(txtRealIncome.Text.Replace(",", string.Empty));
                        if (realInAmount > 0)
                        {
                            InOut io2 = new InOut();

                            string feeName = string.Empty;
                            switch (con.RENT_TYPE_NAME)
                            {
                            case "Cho thuê xe":
                                feeName = "Phí thuê xe";
                                break;

                            case "Cho thuê thiết bị văn phòng":
                                feeName = "Phí thuê thiết bị";
                                break;

                            case "Cho thuê mặt hàng khác":
                                feeName = "Phí khác";
                                break;
                            }
                            item = db.InOutTypes.First(s => s.NAME == feeName);

                            io2.INOUT_TYPE_ID = item.ID;
                            io2.RENT_TYPE_ID  = con.RENT_TYPE_ID;
                            io2.CONTRACT_ID   = con.ID;
                            io2.IN_AMOUNT     = realInAmount;
                            io2.OUT_AMOUNT    = 0;
                            io2.MORE_INFO     = txtMoreInfo.Text;
                            io2.PERIOD_DATE   = DateTime.Now;
                            io2.STORE_ID      = con.STORE_ID;
                            io2.SEARCH_TEXT   = string.Format("{0} {1} {2} {3} {4}", con.CONTRACT_NO, con.CUSTOMER_NAME, con.STORE_NAME, feeName, txtMoreInfo.Text.Trim());
                            io2.INOUT_DATE    = DateTime.Now;
                            io2.CREATED_BY    = Session["username"].ToString();
                            io2.CREATED_DATE  = DateTime.Now;
                            io2.UPDATED_BY    = Session["username"].ToString();
                            io2.UPDATED_DATE  = DateTime.Now;
                            db.InOuts.Add(io2);
                        }
                    }


                    //Out --> Return redundant fee if the client comes before deadline date.
                    if (!string.IsNullOrEmpty(txtReduceAmount.Text))
                    {
                        decimal reduceAmount = Convert.ToDecimal(txtReduceAmount.Text.Replace(",", string.Empty));
                        if (reduceAmount > 0)
                        {
                            InOut io3 = new InOut();
                            item = db.InOutTypes.FirstOrDefault(s => s.NAME == "Trả lại phí thừa");

                            io3.INOUT_TYPE_ID = item.ID;
                            io3.RENT_TYPE_ID  = con.RENT_TYPE_ID;
                            io3.CONTRACT_ID   = con.ID;
                            io3.IN_AMOUNT     = 0;
                            io3.OUT_AMOUNT    = reduceAmount;
                            io3.RENT_TYPE_ID  = con.RENT_TYPE_ID;
                            io3.MORE_INFO     = txtMoreInfo.Text.Trim();
                            io3.PERIOD_DATE   = DateTime.Now;
                            io3.STORE_ID      = con.STORE_ID;
                            io3.SEARCH_TEXT   = string.Format("{0} {1} {2} {3} {4}", con.CONTRACT_NO, con.CUSTOMER_NAME, con.STORE_NAME, "Trả lại phí thừa", txtMoreInfo.Text.Trim());
                            io3.INOUT_DATE    = DateTime.Now;
                            io3.CREATED_BY    = Session["username"].ToString();
                            io3.CREATED_DATE  = DateTime.Now;
                            io3.UPDATED_BY    = Session["username"].ToString();
                            io3.UPDATED_DATE  = DateTime.Now;

                            db.InOuts.Add(io3);
                        }
                    }
                    db.SaveChanges();

                    // Writelog
                    string rentTypeNameClosed = string.Empty;
                    switch (con.RENT_TYPE_ID)
                    {
                    case 1:
                        rentTypeNameClosed = "thuê xe";
                        break;

                    case 2:
                        rentTypeNameClosed = "thuê thiết bị";
                        break;

                    default:
                        rentTypeNameClosed = "thuê khác";
                        break;
                    }
                    var    customer = db.Customers.FirstOrDefault(c => c.ID == con.CUSTOMER_ID);
                    string message  = string.Format("Tài khoản {0} cửa hàng {1} thực hiện thanh lý hợp đồng {2} của khách hàng {3} vào lúc {4}", Convert.ToString(Session["username"]), STORE_NAME, rentTypeNameClosed, customer.NAME, DateTime.Now);
                    Helper.WriteLog(Convert.ToString(Session["username"]), STORE_NAME, Constants.ACTION_CLOSE_CONTRACT, message, false);
                }

                using (var db = new RentBikeEntities())
                {
                    // Update status contract
                    var con = db.Contracts.FirstOrDefault(c => c.ID == contractId);
                    con.CONTRACT_STATUS     = false;
                    con.CLOSE_CONTRACT_DATE = DateTime.Now;

                    // Insert History row
                    ContractHistory ch = new ContractHistory();
                    ch.CONTRACT_ID         = con.ID;
                    ch.CONTRACT_NO         = con.CONTRACT_NO;
                    ch.CUSTOMER_ID         = con.CUSTOMER_ID;
                    ch.CONTRACT_AMOUNT     = con.CONTRACT_AMOUNT;
                    ch.DETAIL              = con.DETAIL;
                    ch.RENT_DATE           = con.RENT_DATE;
                    ch.END_DATE            = con.END_DATE;
                    ch.FEE_PER_DAY         = con.FEE_PER_DAY;
                    ch.ITEM_LICENSE_NO     = con.ITEM_LICENSE_NO;
                    ch.ITEM_TYPE           = con.ITEM_TYPE;
                    ch.NOTE                = con.NOTE;
                    ch.REFERENCE_NAME      = con.REFERENCE_NAME;
                    ch.RENT_TYPE_ID        = con.RENT_TYPE_ID;
                    ch.SERIAL_1            = con.SERIAL_1;
                    ch.SERIAL_2            = con.SERIAL_2;
                    ch.STORE_ID            = con.STORE_ID;
                    ch.SEARCH_TEXT         = con.SEARCH_TEXT;
                    ch.PAY_FEE_MESSAGE     = string.Empty;
                    ch.CLOSE_CONTRACT_DATE = DateTime.Now;
                    ch.REFERENCE_PHONE     = con.REFERENCE_PHONE;
                    ch.SCHOOL_NAME         = con.SCHOOL_NAME;
                    ch.CLASS_NAME          = con.CLASS_NAME;
                    ch.IMPLEMENTER         = con.IMPLEMENTER;
                    ch.BACK_TO_DOCUMENTS   = con.BACK_TO_DOCUMENTS;
                    ch.PHOTO_1             = con.PHOTO_1;
                    ch.THUMBNAIL_PHOTO_1   = con.THUMBNAIL_PHOTO_1;
                    ch.PHOTO_2             = con.PHOTO_2;
                    ch.THUMBNAIL_PHOTO_2   = con.THUMBNAIL_PHOTO_2;
                    ch.PHOTO_3             = con.PHOTO_3;
                    ch.THUMBNAIL_PHOTO_3   = con.THUMBNAIL_PHOTO_3;
                    ch.PHOTO_4             = con.PHOTO_4;
                    ch.THUMBNAIL_PHOTO_4   = con.THUMBNAIL_PHOTO_4;
                    ch.PHOTO_5             = con.PHOTO_5;
                    ch.THUMBNAIL_PHOTO_5   = con.THUMBNAIL_PHOTO_5;
                    ch.CREATED_BY          = Session["username"].ToString();
                    ch.CREATED_DATE        = DateTime.Now;
                    ch.UPDATED_BY          = Session["username"].ToString();
                    ch.UPDATED_DATE        = DateTime.Now;

                    if (CommonList.IsBadContract(db, contractId))
                    {
                        con.IS_BAD_CONTRACT = ch.IS_BAD_CONTRACT = true;
                    }

                    db.ContractHistories.Add(ch);
                    db.SaveChanges();
                    trans.Complete();
                }
            }
            Response.Redirect("FormContractManagement.aspx");
        }
Ejemplo n.º 21
0
        protected override void Page_Load(object sender, EventArgs e)
        {
            base.Page_Load(sender, e);
            if (!IsPostBack)
            {
                try
                {
                    CommonList.LoadRentType(ddlRentType);
                    CommonList.LoadStore(ddlStore);
                    hdfFeeRate.Value = (GetFeeRate(Convert.ToInt32(Session["store_id"])) / 10000).ToString();
                    string id       = Request.QueryString["ID"];
                    string sId      = Request.QueryString["sID"];
                    string copy     = Request.QueryString["copy"];
                    int    STORE_ID = Convert.ToInt32(Session["store_id"]);

                    if (!string.IsNullOrEmpty(id) && string.IsNullOrEmpty(copy)) // EDIT
                    {
                        using (var db = new RentBikeEntities())
                        {
                            int contractId = Helper.parseInt(id);
                            var contract   = db.Contracts.FirstOrDefault(c => c.CONTRACT_STATUS == true && c.ID == contractId);

                            IsNewContract = false;
                            ContractID    = id;
                            List <CONTRACT_FULL_VW> lst;
                            int contractid = Convert.ToInt32(id);

                            Store stor = new Store();
                            stor = db.Stores.FirstOrDefault(s => s.ID == STORE_ID && s.ACTIVE == true);

                            var st = from s in db.CONTRACT_FULL_VW
                                     where s.ID == contractid && s.ACTIVE == true
                                     select s;

                            lst = st.ToList <CONTRACT_FULL_VW>();
                            ddlStore.SelectedValue = STORE_ID.ToString();

                            bool bDifferentSTORE_ID = false;
                            if (Helper.parseInt(sId) != STORE_ID)
                            {
                                if (!IS_ADMIN)
                                {
                                    bDifferentSTORE_ID = true;
                                }
                                STORE_ID = Helper.parseInt(sId);
                            }

                            ddlStore.SelectedValue = STORE_ID.ToString();
                            if (!IS_ADMIN)
                            {
                                ddlStore.Enabled = false;
                            }

                            if (!lst[0].CONTRACT_STATUS || (bDifferentSTORE_ID && !string.IsNullOrEmpty(Request.QueryString["sID"])))
                            {
                                pnlTable.Enabled          = false;
                                rptPayFeeSchedule.Visible = false;
                            }

                            CONTRACT_FULL_VW cntrct = lst[0];
                            txtLicenseNumber.Text      = cntrct.LICENSE_NO;
                            txtCustomerName.Text       = cntrct.CUSTOMER_NAME;
                            txtBirthDay.Text           = string.Format("{0:dd/MM/yyyy}", cntrct.BIRTH_DAY);
                            txtRangeDate.Text          = string.Format("{0:dd/MM/yyyy}", cntrct.LICENSE_RANGE_DATE);
                            txtPlaceDate.Text          = cntrct.LICENSE_RANGE_PLACE;
                            txtPhone.Text              = cntrct.PHONE;
                            txtPermanentResidence.Text = cntrct.PERMANENT_RESIDENCE;
                            txtCurrentResidence.Text   = cntrct.CURRENT_RESIDENCE;
                            txtContractNo.Text         = cntrct.CONTRACT_NO;
                            var rentType = db.RentTypes.Where(c => c.NAME == cntrct.RENT_TYPE_NAME).FirstOrDefault();
                            ddlRentType.SelectedValue = rentType.ID.ToString();
                            RentTypeID        = cntrct.RENT_TYPE_ID;
                            txtAmount.Text    = string.Format("{0:0,0}", cntrct.CONTRACT_AMOUNT);
                            txtFeePerDay.Text = string.Format("{0:0,0}", cntrct.FEE_PER_DAY);
                            txtRentDate.Text  = string.Format("{0:dd/MM/yyyy}", cntrct.RENT_DATE);
                            txtEndDate.Text   = string.Format("{0:dd/MM/yyyy}", cntrct.END_DATE);
                            txtNote.Text      = cntrct.NOTE;

                            txtReferencePerson.Text = cntrct.REFERENCE_NAME;
                            txtItemName.Text        = cntrct.ITEM_TYPE;
                            txtItemLicenseNo.Text   = cntrct.ITEM_LICENSE_NO;
                            txtSerial1.Text         = cntrct.SERIAL_1;
                            txtSerial2.Text         = cntrct.SERIAL_2;
                            txtImplementer.Text     = cntrct.IMPLEMENTER;
                            txtBackDocument.Text    = cntrct.BACK_TO_DOCUMENTS;
                            txtItemDetail.Text      = cntrct.DETAIL;
                            txtReferencePhone.Text  = cntrct.REFERENCE_PHONE;
                            txtSchool.Text          = cntrct.SCHOOL_NAME;
                            txtClass.Text           = cntrct.CLASS_NAME;

                            Customer customer = db.Customers.FirstOrDefault(c => c.ID == cntrct.CUSTOMER_ID);
                            if (customer != null)
                            {
                                if (customer.IS_LOW_RECOVERABILITY)
                                {
                                    btnLowRecoverability.Text            = "Bỏ khả năng thu hồi thấp";
                                    btnLowRecoverability.CommandArgument = "RevertLowRecoverability";
                                }
                            }

                            BuildPhotoLibrary(cntrct);

                            ddlStore.Enabled = txtContractNo.Enabled = txtRentDate.Enabled = txtEndDate.Enabled = false;

                            LoadPayFeeSchedule();
                        }
                    }
                    else // NEW
                    {
                        //Remove [rent other] option if user is just staff
                        if (PERMISSION == ROLE.STAFF)
                        {
                            ddlRentType.Items.Remove(ddlRentType.Items[ddlRentType.Items.Count - 1]);
                        }

                        IsNewContract             = true;
                        btnFinishContract.Visible = false;
                        txtContractNo.Visible     = false;
                        using (var db = new RentBikeEntities())
                        {
                            if (!IS_ADMIN)
                            {
                                ddlStore.SelectedValue = STORE_ID.ToString();
                                ddlStore.Enabled       = false;
                            }
                            RentTypeID       = Convert.ToInt32(ddlRentType.SelectedValue);
                            txtRentDate.Text = string.Format("{0:dd/MM/yyyy}", DateTime.Now);
                            txtEndDate.Text  = string.Format("{0:dd/MM/yyyy}", DateTime.Now.AddDays(29));

                            if (!string.IsNullOrEmpty(id) && !string.IsNullOrEmpty(copy))
                            {
                                int contractid          = Convert.ToInt32(id);
                                CONTRACT_FULL_VW cntrct = db.CONTRACT_FULL_VW.Where(s => s.ID == contractid && s.ACTIVE == true).FirstOrDefault();
                                if (cntrct != null)
                                {
                                    if (IS_ADMIN)
                                    {
                                        STORE_ID = cntrct.STORE_ID;
                                    }
                                    else
                                    {
                                        ddlStore.Enabled = false;
                                    }

                                    ddlStore.SelectedValue = STORE_ID.ToString();

                                    txtLicenseNumber.Text      = cntrct.LICENSE_NO;
                                    txtCustomerName.Text       = cntrct.CUSTOMER_NAME;
                                    txtBirthDay.Text           = string.Format("{0:dd/MM/yyyy}", cntrct.BIRTH_DAY);
                                    txtRangeDate.Text          = string.Format("{0:dd/MM/yyyy}", cntrct.LICENSE_RANGE_DATE);
                                    txtPlaceDate.Text          = cntrct.LICENSE_RANGE_PLACE;
                                    txtPhone.Text              = cntrct.PHONE;
                                    txtPermanentResidence.Text = cntrct.PERMANENT_RESIDENCE;
                                    txtCurrentResidence.Text   = cntrct.CURRENT_RESIDENCE;
                                    txtContractNo.Text         = cntrct.CONTRACT_NO;
                                    var rentType = db.RentTypes.Where(c => c.NAME == cntrct.RENT_TYPE_NAME).FirstOrDefault();
                                    ddlRentType.SelectedValue = rentType.ID.ToString();
                                    RentTypeID        = cntrct.RENT_TYPE_ID;
                                    txtAmount.Text    = string.Format("{0:0,0}", cntrct.CONTRACT_AMOUNT);
                                    txtFeePerDay.Text = string.Format("{0:0,0}", cntrct.FEE_PER_DAY);
                                    txtNote.Text      = cntrct.NOTE;

                                    txtReferencePerson.Text = cntrct.REFERENCE_NAME;
                                    txtItemName.Text        = cntrct.ITEM_TYPE;
                                    txtItemLicenseNo.Text   = cntrct.ITEM_LICENSE_NO;
                                    txtSerial1.Text         = cntrct.SERIAL_1;
                                    txtSerial2.Text         = cntrct.SERIAL_2;
                                    txtImplementer.Text     = cntrct.IMPLEMENTER;
                                    txtBackDocument.Text    = cntrct.BACK_TO_DOCUMENTS;
                                    txtItemDetail.Text      = cntrct.DETAIL;
                                    txtReferencePhone.Text  = cntrct.REFERENCE_PHONE;
                                    txtSchool.Text          = cntrct.SCHOOL_NAME;
                                    txtClass.Text           = cntrct.CLASS_NAME;

                                    BuildPhotoLibrary(cntrct);
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    lblMessage.Text     = ex.Message;
                    lblMessage.CssClass = "text-center text-danger";
                }
            }

            //Disable UI for Admin account
            if (IS_ADMIN)
            {
                pnlTable.Enabled = false;
            }
        }