コード例 #1
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (lblTenantId.Text.Length==0)
                {
                    Alert.Show("দয়া করে এই প্রক্রিয়াটি পুনরায় করুন।");
                    return;
                }
                if (txtInstallmentNo.Text==string.Empty)
                {
                    Alert.Show("দয়া করে কিস্তির সংখ্যা প্রদান করুন।");
                    txtInstallmentNo.Focus();
                    return;
                }

                //convert unicode to decimal
                string strInstallmentNo = Encode.HtmlEncode(txtInstallmentNo.Text);
                int decInstallmentNo = 0;
                try
                {
                    decInstallmentNo = int.Parse(strInstallmentNo);
                }
                catch (Exception ex)
                {
                    Alert.Show("দয়া করে কিস্তির সংখ্যা ফিল্ডে শুধুমাত্র নাম্বার প্রবেশ করুন।");
                    txtInstallmentNo.Focus();
                    return;
                }
                string strPrevDie = Encode.HtmlEncode(txtTotalDue.Text);
                decimal decPrevDue = 0;
                try
                {
                    decPrevDue = decimal.Parse(strPrevDie);
                }
                catch (Exception ex)
                {
                    Alert.Show("দয়া করে সার্ভিস চার্জ ফিল্ডে শুধুমাত্র নাম্বার প্রবেশ করুন।");
                    txtServiceCharge.Focus();
                    return;
                }
                string strAmount = Encode.HtmlEncode(txtInstallmentAmount.Text);
                decimal decAmount= 0;
                try
                {
                    decAmount = decimal.Parse(strAmount);
                }
                catch (Exception ex)
                {
                    Alert.Show("দয়া করে সার্ভিস চার্জ ফিল্ডে শুধুমাত্র নাম্বার প্রবেশ করুন।");
                    txtServiceCharge.Focus();
                    return;
                }

                DueInstallment obj = new DueInstallment();

                obj.TenantId = int.Parse(lblTenantId.Text);
                obj.ShopId = int.Parse(lblShopId.Text);
                obj.DueDate = System.DateTime.Today;
                obj.PreviousDue = decPrevDue;
                obj.NoOfInstallment = decInstallmentNo;
                obj.InstallmentAmount = decAmount;

                string startMonth = ddlMonth.SelectedValue;
                obj.StartMonth = int.Parse(startMonth.Substring(5));
                obj.StartYear = int.Parse(startMonth.Substring(0,4));
                obj.PaidAmount = 0;
                obj.UserId = userId;

                if (!isNewEntry)
                    obj.Id = int.Parse(lblId.Text);

                int success = 0;

                if (isNewEntry)
                    success = obj.InsertDueInstallment();
                else
                    success = obj.UpdateDueInstallment();

                if (success == 1)
                {
                    Alert.Show("তথ্য সংরক্ষণ হয়েছে।");

                    string marketId = ddlMarket.SelectedValue;
                    Response.Redirect("DueList.aspx?mid=" + marketId, false);
                }
            }
            catch (Exception ex)
            {
               Alert.Show(ex.Message);
            }
        }
コード例 #2
0
        protected void btnGenerate_Click(object sender, EventArgs e)
        {
            StringBuilder strSuccess=new StringBuilder();
            StringBuilder strFailure = new StringBuilder();

            strSuccess.Append("<strong>Success</strong><br>");
            strFailure.Append("<strong>Failure</strong><br>");

            try
            {
                if (ddlMarket.SelectedIndex <= 0)
                {
                    Alert.Show("Please select a market first.");
                    ddlMarket.Focus();
                    return;
                }

                int marketId = int.Parse(ddlMarket.SelectedValue);
                List<Shop> shopList = new Shop().GetAllShopByMarketId(marketId);
                BillMaster billMaster = new BillMaster();
                BillDetail billDetail = new BillDetail();

                foreach (ListItem li in cbListShops.Items)
                {
                    if (!li.Selected) continue;

                    int shopId = int.Parse(li.Value);

                    Shop shop = shopList.Find(x => x.Id == shopId);
                    try
                    {
                        #region process bill master data

                        string monthYearText = ddlMonth.SelectedItem.Text;
                        string monthYearVal = ddlMonth.SelectedValue;

                        ShopeMapping shopeMapping = new ShopeMapping().GetAllShopeMappingByShopId(shop.Id);

                        billMaster.BilGeneratelDate = DateTime.Parse(txtDate.Text);
                        billMaster.BillMonth = monthYearText.Substring(5);
                        billMaster.BillYear = int.Parse(monthYearText.Substring(0, 4));
                        billMaster.TenantId = shopeMapping.TenantId;

                        billMaster.BillNo = billMaster.BillYear + "-" + monthYearVal.Substring(5) + "-" +
                                            shop.Id + "-" + shopeMapping.TenantId;

                        billMaster.GenerateBy = 1;
                        billMaster.ApprovedBy = 0;
                        billMaster.TotalAmount = 0;
                        billMaster.TotalPayment = 0;
                        billMaster.LastPaymentDate = (DateTime) dtpLastDate.SelectedDate;

                        string MonthVal = ddlMonth.SelectedValue.Substring(5);
                        billMaster.BillMonthId = int.Parse(MonthVal);
                        int success = 0;

                        int billId = billMaster.CheckExistanceByBillNo(billMaster.BillNo);
                        if (billId > 0)
                        {
                            if (!chkUpdateExisting.Checked)
                            {
                                strFailure.Append("Bill already generated for the shop: " + shop.ShopNo + "<br>");
                                continue;
                            }

                            billMaster.Id = billId;
                            success = billMaster.UpdateBillMaster();
                        }
                        else
                        {
                            success = billMaster.InsertBillMaster();
                            billMaster.Id = new BillMaster().GetLastId();
                        }

                    #endregion

                        #region process bill detail data

                        if (success > 0)
                        {
                            billDetail = new BillDetail();
                            billDetail.BillMasterId = billMaster.Id;
                            billDetail.MarketId = int.Parse(ddlMarket.SelectedValue);
                            billDetail.ShopId = shop.Id;
                            billDetail.MonthlyRent = shopeMapping.MonthlyRent;
                            billDetail.ServiceCharge = shopeMapping.ServiceCharge;
                            billDetail.MiscBills = shopeMapping.MiscBill;

                            if (chkPrevDue.Checked)
                            {
                                DueInstallment installment = new DueInstallment().GetDueInstallmentByTenant(billMaster.TenantId);
                                if (installment.Id != 0)
                                {
                                    billDetail.PreviousDue = installment.InstallmentAmount;
                                    if (installment.DueAmount < installment.InstallmentAmount)
                                        billDetail.PreviousDue = installment.DueAmount;
                                }
                                else
                                {
                                    if (billDetail.CheckBillExistenceByTenant(billMaster.TenantId, shop.Id) > 0)
                                        billDetail.PreviousDue = billDetail.GetLastDueTenantAndShopWise(billMaster.TenantId, shop.Id);
                                    else
                                        billDetail.PreviousDue = new ShopeMapping().GetAllShopeMappingByShopId(shop.Id).PreviousDue;
                                }

                            }
                            else
                                billDetail.PreviousDue = 0;

                            billDetail.LateFee = Math.Round((shopeMapping.MonthlyRent*5)/100,0);
                            billDetail.Payment = 0;
                            billDetail.IsClosed = false;
                            billDetail.ClosedBy = 0;

                            if (billId > 0)
                            {
                                int billDetailId = billDetail.GetBillDetailIdByMasterId(billId);
                                if (billDetailId > 0)
                                {
                                    billDetail.Id = billDetailId;
                                    success = billDetail.UpdateBillDetail();
                                }
                                else
                                    success = billDetail.InsertBillDetail();
                            }
                            else
                                success = billDetail.InsertBillDetail();

                            //update total amount in master table
                            if (success > 0)
                            {
                                decimal totalAmount = (billDetail.MonthlyRent + billDetail.ServiceCharge +
                                                       billDetail.MiscBills +
                                                       billDetail.PreviousDue);

                                billMaster.UpdateTotalAmount(billMaster.Id, totalAmount);

                                strSuccess.Append("Bill generated for Shop: " + shop.ShopNo + "<br>");
                            }
                        }

                        #endregion

                    }

                    catch (Exception ex)
                    {
                        strFailure.Append("Bill generate failed for Shop " + shop.ShopNo + ". Error: " + ex.Message +
                                          "<br>");
                        continue;
                    }
                }

                strFailure.Append("<br><br>");

                ltrStatus.Text = strFailure.ToString() + strSuccess.ToString();
            }
            catch (Exception ex)
            {

                Alert.Show(ex.Message);
            }
        }