Пример #1
0
        public int UpdatePaymentById(Int64 _masterId, bool applyLateFee)
        {
            Hashtable lstItems = new Hashtable();
            lstItems.Add("@Id", _masterId);
            int success = 0;

            if(applyLateFee)
                success = new BillDetail().UpdatePaymentWithLateFeeByMasterId(_masterId);
            else
                success = new BillDetail().UpdatePaymentWithoutLateFeeByMasterId(_masterId);

            if (success>0)
                success = dal.UpdatePaymentById(lstItems);

            return success;
        }
Пример #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);
            }
        }