Пример #1
0
        public bool RegenerateBillingPerEnterprise()
        {
            bool isDeleted = false;

            try
            {
                BCS_Context    db        = new BCS_Context();
                List <Company> Companies = new List <Company>();
                Companies = db.Company.Where(m => m.EnterpriseType.ToUpper() == EnterpriseType.ToUpper()).ToList();
                foreach (var item in Companies)
                {
                    //db.SubsidiaryLedger.RemoveRange(db.SubsidiaryLedger.Where(m => m.BillingPeriod == id));
                    db.Database.ExecuteSqlCommand("Delete from SubsidiaryLedgers where BillingPeriod = '" + id + "' and CompanyId = '" + item.CompanyID + "' and TransactionType = 'BILLING'");
                    //db.Database.ExecuteSqlCommand("Delete from GeneralBillings where BillingPeriod = '" + id + "' and CompanyId = '" + companyId + "' and TransactionType = 'BILLING'");
                    db.Database.ExecuteSqlCommand("Delete from Balances where CurrentBillingPeriod = '" + id + "' and CompanyId = '" + item.CompanyID + "'");// and TransactionType = 'BILLING'");
                }

                db.SaveChanges();
                isDeleted = true;
            }
            catch (Exception)
            {
                isDeleted = false;
            }

            return(isDeleted);
        }
Пример #2
0
        public bool hasDuplicateByBillingPeriod()
        {
            bool        hasDuplicate = true;
            BCS_Context db           = new BCS_Context();

            if (Services.ToUpper() == "GARBAGE")
            {
                hasDuplicate = db.GarbageInformations.Any(m => m.CompanyId == CompanyId && m.BillingPeriod == BillingPeriod);
            }

            return(hasDuplicate);
        }
Пример #3
0
        public static int GetMonth(string zoneGroup)
        {
            int         returnMonth = 0;
            BCS_Context db          = new BCS_Context();

            var           maxBillingId  = db.BillingPeriod.Where(m => m.groupCode == zoneGroup).Max(m => m.BillingPeriodId);
            BillingPeriod billingPeriod = db.BillingPeriod.Where(m => m.BillingPeriodId == maxBillingId).FirstOrDefault();

            if (billingPeriod != null)
            {
                returnMonth = billingPeriod.Finalized.ToUpper() == "YES" ? billingPeriod.DateTo.Month : billingPeriod.DateFrom.Month;
            }

            return(returnMonth);
        }
Пример #4
0
        public bool hasVat()
        {
            BCS_Context db            = new BCS_Context();
            bool        isValid       = false;
            string      _vatableItems = db.Company.Single(m => m.CompanyID == id).VatableItems;

            if (!string.IsNullOrEmpty(_vatableItems))
            {
                if (_vatableItems.ToUpper() == "YES")
                {
                    isValid = true;
                }
            }
            return(isValid);
        }
Пример #5
0
        public bool hasDuplicateEntry()
        {
            bool        hasDup = false;
            BCS_Context db     = new BCS_Context();

            if (!string.IsNullOrEmpty(zonegroupname))
            {
                if (zonegroupname.ToUpper() != name.ToUpper())
                {
                    hasDup = db.Zone.Any(m => m.ZoneName.ToUpper() == name.ToUpper() && m.ZoneGroup == zonegroup);
                }
            }
            else
            {
                hasDup = db.Zone.Any(m => m.ZoneName.ToUpper() == name.ToUpper() && m.ZoneGroup == zonegroup);
            }

            return(hasDup);
        }
Пример #6
0
        public static void AssignBalance(SubsidiaryLedger baseValue, Balances assignValue, decimal balance, decimal interest, decimal vat, string lastid)
        {
            assignValue.BillingType          = baseValue.BillingType;
            assignValue.TransactionReference = baseValue.TransactionReference;
            //assignValue.BillingSubType = "BALANCE";
            assignValue.BillingSubType  = "PRINCIPAL";
            assignValue.CompanyId       = baseValue.CompanyId;
            assignValue.TransactionType = baseValue.TransactionType;

            int _lastid = 0;

            if (lastid != null)
            {
                try
                {
                    BCS_Context          db      = new BCS_Context();
                    ApplicationDbContext context = new ApplicationDbContext();
                    var uname     = HttpContext.Current.User.Identity.Name;
                    var zonegroup = context.Users.FirstOrDefault(m => m.UserName == uname).ZoneGroup;

                    _lastid = db.BillingPeriod.FirstOrDefault(m => m.groupCode == zonegroup).BillingPeriodId;
                }
                catch (Exception ex)
                {
                    _lastid = 0;
                }
            }


            assignValue.DueDate               = baseValue.DueDate;
            assignValue.VAT                   = Math.Abs(vat);
            assignValue.Amount                = baseValue.DebitAmount;
            assignValue.BillingPeriodId       = _lastid;
            assignValue.BillingGenerationDate = DateTime.Now;
            assignValue.BillingReference      = baseValue.BillingReference;
            assignValue.CurrentBillingPeriod  = baseValue.BillingPeriod;
            assignValue.Interest              = Math.Abs(interest);
            assignValue.BalanceType           = "FORWARDED BALANCE";
        }
Пример #7
0
        public bool canGenerate()
        {
            bool                 isVerified = false;
            BCS_Context          db         = new BCS_Context();
            List <BillingPeriod> bill       = new List <BillingPeriod>();

            bill = db.BillingPeriod.OrderByDescending(m => m.BillingPeriodId).Where(m => m.groupCode == ZoneGroup).ToList();
            var indexNumber = bill.IndexOf(bill.SingleOrDefault(m => m.BillingPeriodId == id));

            if (indexNumber > 0)
            {
                BillingPeriod newBill = bill[indexNumber - 1];
                if (newBill.Generated.ToUpper() == "NO")
                {
                    isVerified = true;
                }
            }
            else
            {
                isVerified = true;
            }

            return(isVerified);
        }
Пример #8
0
        public static decimal?GetWaterAmount(decimal WaterConsumption, string userid)
        {
            BCS_Context          db      = new BCS_Context();
            ApplicationDbContext context = new ApplicationDbContext();

            string ZoneGroup = context.Users.SingleOrDefault(m => m.Id == userid).ZoneGroup;

            decimal?           waterAmount  = 0;
            List <BillingRate> BillingRates = new List <BillingRate>();

            BillingRates = db.BillingRates.Where(m => m.Category.ToUpper().Trim() == "WATER").Where(m => m.ZoneGroup == ZoneGroup).ToList();
            int                i                = BillingRates.Count;
            BillingRate        tempBillRate     = new BillingRate();
            List <BillingRate> tempBillingRates = new List <BillingRate>();
            bool               isTrue           = true;
            bool               isSorted         = false;

            while (isTrue)
            {
                isTrue   = false;
                isSorted = true;
                for (int j = 0; j < i - 1; j++)
                {
                    string[] first    = BillingRates[j].SubCategory.Split('-');
                    string[] sec      = BillingRates[j + 1].SubCategory.Split('-');
                    double   dblFirst = Convert.ToDouble(first[0]);
                    double   dblSec   = Convert.ToDouble(sec[0]);

                    if (dblFirst > dblSec)
                    {
                        tempBillRate        = BillingRates[j + 1];
                        BillingRates[j + 1] = BillingRates[j];
                        BillingRates[j]     = tempBillRate;

                        isTrue   = true;
                        isSorted = false;
                    }
                }
            }

            if (isSorted)
            {
                decimal?AddToTotal = BillingRates[0].Rate;  //If belong to first consumption range. save this value.
                //double PrevRange = 0;
                decimal AddToAmount = 0;
                for (int j = 0; j < i; j++)
                {
                    string[] SubcatRange = BillingRates[j].SubCategory.Split('-');
                    decimal  StartRange  = decimal.Parse(SubcatRange[0]);
                    decimal  EndRange    = decimal.Parse(SubcatRange[1]);
                    decimal? Rate        = BillingRates[j].Rate;
                    AddToAmount += EndRange; //accumulated "end cu. m".

                    if (WaterConsumption >= StartRange && WaterConsumption <= EndRange || j == (i - 1))
                    {
                        if (j > 0) //If not within the range of first consumption range.
                        {
                            decimal newWaterConsumption = Convert.ToDecimal(WaterConsumption);
                            decimal cuM = (AddToAmount - EndRange); //accumulated "end cu. m" minus present end range.

                            cuM         = (newWaterConsumption - cuM) * decimal.Parse(Rate.ToString());
                            cuM        += decimal.Parse(AddToTotal.ToString());
                            waterAmount = Math.Round(cuM, 2);

                            break;
                        }
                        else
                        {
                            waterAmount = Rate; //Return this if consumption belong to first rate.
                            break;
                        }
                    }

                    AddToTotal = j > 0 ? AddToTotal + (EndRange * Rate) : BillingRates[j].Rate;
                    //PrevRange = EndRange;
                }
            }
            return(waterAmount);
        }