Esempio n. 1
0
        public string UpdateBillGroupMaster(BillGroup input)
        {
            string result = "Success";

            if (input.Id == 0)
            {
                input.AddedAt = DateTime.Now;
                BillGroup.Add(input);

                SaveChanges();
                return(result);
            }
            var bgUpdate = (from bg in BillGroup
                            where bg.Id == input.Id
                            select bg).FirstOrDefault();

            if (bgUpdate != null)
            {
                bgUpdate.Description   = input.Description;
                bgUpdate.Code          = input.Code;
                bgUpdate.BiMonthly     = input.BiMonthly;
                bgUpdate.BiMonthlyEven = input.BiMonthlyEven;
                bgUpdate.StartDay      = input.StartDay;
                bgUpdate.DueDays       = input.DueDays;
                bgUpdate.AddedAt       = DateTime.Now;
                BillGroup.Update(bgUpdate);
                SaveChanges();
            }
            return(result);
        }
Esempio n. 2
0
        public JsonResult DeleteBillGroupMaster([FromBody] BillGroup input)
        {
            var result = BusinessService.DeleteBillGroupMaster(input);

            var ret = $"{{\"msg\":\"{result}\"}}";

            return(new JsonResult(ret));
        }
Esempio n. 3
0
        public string DeleteBillGroupMaster(BillGroup input)
        {
            string result     = "Success";
            var    unitsCount = (from un in UnitSummary
                                 where un.billgroupid == input.Id
                                 select un).Count();

            if (unitsCount > 0)
            {
                result = "Units are linked to this Bill Group, Please unlink them before deleting.";
            }
            else
            {
                var bgRemove = (from bg in BillGroup where bg.Id == input.Id
                                select bg).FirstOrDefault();
                if (bgRemove != null)
                {
                    BillGroup.Remove(bgRemove);
                    SaveChanges();
                }
            }

            return(result);
        }
Esempio n. 4
0
 public string DeleteBillGroupMaster(BillGroup input)
 {
     return(Repository.DeleteBillGroupMaster(Mapper.Map <DataModels.Billing.BillGroup>(input)));
 }
Esempio n. 5
0
        public ServiceResult<Bill> AddBill(string name, decimal amount, int billGroupId, int? categoryId, int? vendorId, DateTime startDate, DateTime endDate, int frequency, DateTime? secondaryStartDate, DateTime? secondaryEndDate)
        {
            ServiceResult<Bill> result = new ServiceResult<Bill>();

            if (categoryId.HasValue && categoryId.Value == 0)
                categoryId = null;
            if (vendorId.HasValue && vendorId.Value == 0)
                vendorId = null;

            // get bill group
            var billGroup = _billGroupRepository.GetById(billGroupId);
            if (billGroup == null)
            {
                // if we don't have any bill groups at all, create one
                if (_billGroupRepository.GetAll().Count() == 0)
                {
                    billGroup = new BillGroup() { IsActive = true, Name = "Bills" };
                    _billGroupRepository.Add(billGroup);
                    _unitOfWork.Commit();
                }
                else
                {
                    result.AddError(ErrorType.NotFound, "Bill Group {0} not found", billGroupId);
                    return result;
                }
            }

            // create bill
            var bill = new Bill()
            {
                Name = name,
                Amount = amount,
                BillGroupId = billGroup.Id,
                CategoryId = categoryId,
                VendorId = vendorId,
                StartDate = startDate,
                EndDate = endDate,
                RecurrenceFrequency = frequency,
                StartDate2 = secondaryStartDate,
                EndDate2 = secondaryEndDate
            };

            // create transactions
            int count = 0;
            DateTime cur = new DateTime(startDate.Year, startDate.Month, startDate.Day);

            while (cur <= endDate)
            {
                BillTransaction trx = new BillTransaction()
                {
                    Amount = amount,
                    OriginalAmount = amount,
                    CategoryId = categoryId,
                    OriginalCategoryId = categoryId,
                    VendorId = vendorId,
                    OriginalVendorId = vendorId,
                    Timestamp = cur,
                    OriginalTimestamp = cur
                };
                bill.BillTransactions.Add(trx);

                count++;
                if (frequency == 0)
                    cur = endDate.AddDays(1);
                else if (frequency > 0)
                    cur = startDate.AddDays(count * frequency);
                else
                    cur = startDate.AddMonths(count * -1 * frequency);
            }

            if (secondaryStartDate.HasValue)
            {
                if (secondaryEndDate.HasValue)
                    endDate = secondaryEndDate.Value;

                count = 0;
                cur = new DateTime(secondaryStartDate.Value.Year, secondaryStartDate.Value.Month, secondaryStartDate.Value.Day);

                while (cur <= endDate)
                {
                    BillTransaction trx = new BillTransaction()
                    {
                        Amount = amount,
                        OriginalAmount = amount,
                        CategoryId = categoryId,
                        OriginalCategoryId = categoryId,
                        VendorId = vendorId,
                        OriginalVendorId = vendorId,
                        Timestamp = cur,
                        OriginalTimestamp = cur
                    };
                    bill.BillTransactions.Add(trx);

                    count++;
                    if (frequency == 0)
                        cur = endDate.AddDays(1);
                    else if (frequency > 0)
                        cur = secondaryStartDate.Value.AddDays(count * frequency);
                    else
                        cur = secondaryStartDate.Value.AddMonths(count * -1 * frequency);
                }
            }

            _billRepository.Add(bill);
            _unitOfWork.Commit();

            return result;
        }
    public static IQueryable <IGrouping <INamed, T> > GroupByNamed <T>(this IQueryable <T> query, BillGroup group)
    {
        //enum name must be the same as property name
        string property = group.ToString();
        ParameterExpression parameter = Expression.Parameter(typeof(T));
        Expression          prop      = Expression.Property(parameter, property);
        var lambda = Expression.Lambda <Func <T, INamed> >(prop, parameter);

        return(query.GroupBy(lambda));
    }