Пример #1
0
        public void ReserializePropertyDirectory1Level()
        {
            var propdir = new PropertyDirectory
            {
                { "level1/prop1", "STRING" },
                { "level1/prop2", 123 }
            };

            Assert.AreEqual(1, propdir.Count);

            var serialized = Thing.Serialize(propdir);

            Assert.NotNull(serialized);
            var deserializedResult = Thing.DeserializePart(serialized).ToArray();

            Assert.NotNull(deserializedResult);
            var deserializedResultArray = deserializedResult.ToArray();

            Assert.NotNull(deserializedResultArray);
            Assert.AreEqual(1, deserializedResultArray.Length);
            Assert.AreEqual(string.Empty, deserializedResultArray[0].Item2);
            var deserialized = deserializedResultArray[0].Item1;

            Assert.NotNull(deserialized);
            Assert.IsInstanceOf <PropertyDirectory>(deserialized);
            Assert.AreEqual(propdir.ElementAt(0), ((PropertyDirectory)deserialized !).ElementAt(0));
            Assert.AreEqual(propdir, deserialized);
        }
Пример #2
0
        public void ReserializePropertyDirectory0Level()
        {
            var propdir = new PropertyDirectory {
                { "prop1", "STRING" },
                { "prop2", 123 },
            };
            var serialized = Thing.Serialize(propdir);

            Assert.NotNull(serialized);
            var deserializedResult = Thing.DeserializePart(serialized).ToArray();

            Assert.NotNull(deserializedResult);
            var deserializedResultArray = deserializedResult.ToArray();

            Assert.NotNull(deserializedResultArray);
            Assert.AreEqual(1, deserializedResultArray.Length);
            Assert.AreEqual(string.Empty, deserializedResultArray[0].Item2);
            var deserialized = deserializedResultArray[0].Item1;

            Assert.NotNull(deserialized);
            Assert.AreEqual(propdir, deserialized);
        }
        private async Task GenerateBill(PropertyDirectory pd, DateTime dueDate)
        {
            var currentBill = await GetBilling(pd.id, dueDate.ToString("yyyyMM"));

            if (currentBill == null)
            {
                currentBill                     = new Billing();
                currentBill.billId              = Guid.NewGuid();
                currentBill.transactionDate     = DateTime.Today;
                currentBill.dateDue             = dueDate;
                currentBill.MonthYear           = dueDate.ToString("yyyyMM");
                currentBill.propertyDirectoryId = pd.id;
                currentBill.createDate          = DateTime.Now;
                currentBill.createdBy           = UserName;
                currentBill.companyId           = CompanyId;
                currentBill.documentId          = await GetDocId();

                currentBill.billType = "MB";

                var parameters = new DynamicParameters();

                parameters.Add("propertyDirectoryid", pd.id);
                parameters.Add("MonthYear", currentBill.MonthYear);

                decimal monthlyRentBalance     = 0m;
                decimal monthlyAssocDueBalance = 0m;

                var balanceView = await dapperManager.GetAllAsync <PropertyBalanceViewModel>("spGetMonthlyBalance", parameters);

                monthlyRentBalance = balanceView.Where(a => a.billLineType.Equals(Constants.BillLineTypes.MONTHLYBILLITEM, StringComparison.OrdinalIgnoreCase) ||
                                                       a.billLineType.Equals(Constants.BillLineTypes.MONTHLYBILLITEM_PREVBAL, StringComparison.OrdinalIgnoreCase) ||
                                                       a.billLineType.Equals(Constants.BillLineTypes.MONTHLYBILLITEMPENALTY, StringComparison.OrdinalIgnoreCase) ||
                                                       a.billLineType.Equals(Constants.BillLineTypes.MONTHLYBILLITEM_VAT, StringComparison.OrdinalIgnoreCase) ||
                                                       a.billLineType.Equals(Constants.BillLineTypes.MONTHLYBILLITEM_WT, StringComparison.OrdinalIgnoreCase)

                                                       )
                                     .Sum(a => a.balance);

                monthlyAssocDueBalance = balanceView.Where(a => a.billLineType.Equals(Constants.BillLineTypes.MONTHLYASSOCDUE, StringComparison.OrdinalIgnoreCase) ||
                                                           a.billLineType.Equals(Constants.BillLineTypes.MONTHLYASSOCDUEPENALTY, StringComparison.OrdinalIgnoreCase) ||
                                                           a.billLineType.Equals(Constants.BillLineTypes.MONTHLYASSOCDUE_PREVBAL, StringComparison.OrdinalIgnoreCase) ||
                                                           a.billLineType.Equals(Constants.BillLineTypes.MONTHLYASSOCDUE_VAT, StringComparison.OrdinalIgnoreCase)
                                                           )
                                         .Sum(a => a.balance);

                List <BillingLineItem> billItems = new List <BillingLineItem>();

                var dueAmount = 0m;

                dueAmount = pd.monthlyRate;
                var dueAmountVat       = CalculateVat(dueAmount);
                var dueAmountBeforeVat = dueAmount - dueAmountVat;
                var wtAmt = 0m;

                if (dueAmountBeforeVat != 0m && pd.withWT)
                {
                    wtAmt = CalculateWT(dueAmountBeforeVat);
                    dueAmountBeforeVat = dueAmount - (dueAmountVat + wtAmt);
                }

                if (monthlyRentBalance > 0)
                {
                    var penaltyPct = pd.penaltyPct;
                    var penalty    = 0m;
                    if (penaltyPct > 0)
                    {
                        penalty = monthlyRentBalance * (penaltyPct / 100m);
                    }

                    if (penalty > 0)
                    {
                        billItems.Add(new BillingLineItem()
                        {
                            Id           = Guid.NewGuid(),
                            description  = $"Monthly rent penalty {penaltyPct.ToString("0.00")}%",
                            amount       = penalty,
                            lineNo       = 0,
                            generated    = true,
                            billLineType = Constants.BillLineTypes.MONTHLYBILLITEMPENALTY
                        });
                    }

                    billItems.Add(new BillingLineItem()
                    {
                        Id           = Guid.NewGuid(),
                        description  = "Previous balance",
                        amount       = monthlyRentBalance,
                        lineNo       = 1,
                        generated    = true,
                        billLineType = Constants.BillLineTypes.MONTHLYBILLITEM_PREVBAL
                    });
                }

                if (dueAmountBeforeVat != 0m)
                {
                    billItems.Add(new BillingLineItem()
                    {
                        Id           = Guid.NewGuid(),
                        description  = "Monthly due",
                        amount       = dueAmountBeforeVat,
                        amountPaid   = 0,
                        lineNo       = 2,
                        generated    = true,
                        billLineType = Constants.BillLineTypes.MONTHLYBILLITEM
                    });
                }

                if (dueAmountBeforeVat != 0m)
                {
                    billItems.Add(new BillingLineItem()
                    {
                        Id           = Guid.NewGuid(),
                        description  = "Monthly due (VAT)",
                        amount       = dueAmountVat,
                        amountPaid   = 0,
                        lineNo       = 2,
                        generated    = true,
                        billLineType = Constants.BillLineTypes.MONTHLYBILLITEM_VAT
                    });
                }


                if (wtAmt != 0m)
                {
                    billItems.Add(new BillingLineItem()
                    {
                        Id           = Guid.NewGuid(),
                        description  = "Monthly due (WT)",
                        amount       = wtAmt,
                        amountPaid   = 0,
                        lineNo       = 2,
                        generated    = true,
                        billLineType = Constants.BillLineTypes.MONTHLYBILLITEM_WT
                    });
                }

                if (monthlyAssocDueBalance > 0)
                {
                    billItems.Add(new BillingLineItem()
                    {
                        Id           = Guid.NewGuid(),
                        description  = "Association dues penalty",
                        amount       = monthlyAssocDueBalance * (pd.penaltyPct / 100m),
                        lineNo       = 3,
                        generated    = true,
                        billLineType = Constants.BillLineTypes.MONTHLYASSOCDUEPENALTY
                    });

                    billItems.Add(new BillingLineItem()
                    {
                        Id           = Guid.NewGuid(),
                        description  = "Previous association dues balance",
                        amount       = monthlyAssocDueBalance,
                        lineNo       = 4,
                        generated    = true,
                        billLineType = Constants.BillLineTypes.MONTHLYASSOCDUE_PREVBAL
                    });
                }

                if (pd.associationDues > 0)
                {
                    var assocDuesBeforevat = pd.associationDues;
                    //var assocDuesVat = CalculateVat(pd.associationDues);

                    billItems.Add(new BillingLineItem()
                    {
                        Id           = Guid.NewGuid(),
                        description  = "Association dues",
                        amount       = assocDuesBeforevat,
                        amountPaid   = 0,
                        lineNo       = 6,
                        generated    = true,
                        billLineType = Constants.BillLineTypes.MONTHLYASSOCDUE
                    });

                    //billItems.Add(new BillingLineItem()
                    //{
                    //    Id = Guid.NewGuid(),
                    //    description = "Association dues (VAT)",
                    //    amount = assocDuesVat,
                    //    amountPaid = 0,
                    //    lineNo = 7,
                    //    generated = true,
                    //    billLineType = Constants.BillLineTypes.MONTHLYASSOCDUE_VAT
                    //});
                }

                currentBill.totalAmount      = billItems.Sum(a => a.amount);
                currentBill.balance          = billItems.Sum(a => a.amount - a.amountPaid);
                currentBill.amountPaid       = billItems.Sum(a => a.amountPaid);
                currentBill.billingLineItems = billItems;
                var result = await SaveBill(currentBill);
            }
        }
        protected async Task HandleValidSubmit()
        {
            UserName = await _sessionStorageService.GetItemAsync <string>("UserName");

            CompanyId = await _sessionStorageService.GetItemAsync <string>("CompanyId");

            DateTime datetoday = DateTime.Now;


            string propertyid = tenants.propertyid.ToString();


            errorMessagePropertyDateRange = "";


            var company = await appDBContext.Companies.Where(a => a.companyId.Equals(CompanyId)).FirstOrDefaultAsync();

            var property = await appDBContext.Properties
                           .Where(a => a.id.Equals(propertyid) && a.companyId.Equals(CompanyId)).FirstOrDefaultAsync();



            decimal areasq = property.areaInSqm;
            decimal asssq  = tenants.ratePerSQM;

            if (areasq == null)
            {
                areasq = 0;
            }

            if (asssq == null)
            {
                asssq = 0;
            }

            decimal _monthlyrate = areasq * asssq;
            decimal _assorate    = property.areaInSqm * tenants.ratePerSQMAssocDues;

            bool withWT_sw;


            decimal new_monthly_rate = 0;

            if (CompanyId == "ADBCA")
            {
                new_monthly_rate = 0;
            }
            else
            {
                new_monthly_rate = tenants.monthlyRate;
            }



            if (tenants.withWT == "N")
            {
                withWT_sw = false;
            }
            else
            {
                withWT_sw = true;
            }



            var pdpropertyid = await appDBContext.PropertyDirectory.Where(a => a.propertyId.Equals(Guid.Parse(tenants.propertyid)) && a.companyId.Equals(CompanyId) && a.dateFrom <= tenants.dateTo && a.dateTo >= tenants.dateFrom && a.deleted.Equals(false)).ToListAsync();


            if (pdpropertyid.Count > 0)
            {
                errorMessagePropertyDateRange = "Invalid Date Range. The property is with other tenant.";
                return;
            }

            if (string.IsNullOrEmpty(id))
            {
                var tenantId = Guid.NewGuid();

                var properDirectoryId = Guid.NewGuid();

                Tenant t = new Tenant()
                {
                    id            = tenantId.ToString(),
                    company       = company,
                    updateDate    = datetoday,
                    updatedBy     = UserName,
                    lastName      = tenants.lastName,
                    firstName     = tenants.firstName,
                    middleName    = tenants.middleName,
                    TenantIDs     = tenants.TenantIDs,
                    contactNumber = tenants.contactNumber,
                    emailAddress  = tenants.emailAddress,
                    tenantProxID  = tenants.tenantProxID,

                    //Owned_Mgd = tenants.Owned_Mgd,
                    //MgtFeePct = tenants.MgtFeePct,
                    //CCTNumber = tenants.CCTNumber,


                    contactNo2              = tenants.contactNo2,
                    contactNo3              = tenants.contactNo3,
                    homeAddress             = tenants.homeAddress,
                    workAddress             = tenants.workAddress,
                    emergyFullName          = tenants.emergyFullName,
                    emergyContactNo         = tenants.emergyContactNo,
                    emergyAdrress           = tenants.emergyAdrress,
                    emergyRelationshipOwner = tenants.emergyRelationshipOwner,
                    //otherRestenanted1 = tenants.otherRestenanted1,
                    //otherResResiding1 = tenants.otherResResiding1,
                    //otherResFullName1 = tenants.otherResFullName1,
                    //otherResRelationshipToOwner1 = tenants.otherResRelationshipToOwner1,
                    //otherRestenanted2 = tenants.otherRestenanted2,
                    //otherResResiding2 = tenants.otherResResiding2,
                    //otherResFullName2 = tenants.otherResFullName2,
                    //otherResRelationshipToOwner2 = tenants.otherResRelationshipToOwner2,
                    //otherRestenanted3 = tenants.otherRestenanted3,
                    //otherResResiding3 = tenants.otherResResiding3,
                    //otherResFullName3 = tenants.otherResFullName3,
                    //otherResRelationshipToOwner3 = tenants.otherResRelationshipToOwner3,
                    subTenantProxID1      = tenants.subTenantProxID1,
                    subTenantFullName1    = tenants.subTenantFullName1,
                    subTenantID1          = tenants.subTenantID1,
                    subTenantHomeAddress1 = tenants.subTenantHomeAddress1,
                    subTenantWorkAddress1 = tenants.subTenantWorkAddress1,
                    subTenantContactNo1   = tenants.subTenantContactNo1,
                    subTenantEmailAdd1    = tenants.subTenantEmailAdd1,
                    RelToPrimary1         = tenants.RelToPrimary1,

                    subTenantProxID2      = tenants.subTenantProxID2,
                    subTenantFullName2    = tenants.subTenantFullName2,
                    subTenantID2          = tenants.subTenantID2,
                    subTenantHomeAddress2 = tenants.subTenantHomeAddress2,
                    subTenantWorkAddress2 = tenants.subTenantWorkAddress2,
                    subTenantContactNo2   = tenants.subTenantContactNo2,
                    subTenantEmailAdd2    = tenants.subTenantEmailAdd2,
                    RelToPrimary2         = tenants.RelToPrimary2,

                    subTenantProxID3      = tenants.subTenantProxID3,
                    subTenantFullName3    = tenants.subTenantFullName3,
                    subTenantID3          = tenants.subTenantID3,
                    subTenantHomeAddress3 = tenants.subTenantHomeAddress3,
                    subTenantWorkAddress3 = tenants.subTenantWorkAddress3,
                    subTenantContactNo3   = tenants.subTenantContactNo3,
                    subTenantEmailAdd3    = tenants.subTenantEmailAdd3,
                    RelToPrimary3         = tenants.RelToPrimary3
                };

                if (tenants.tenantDocument != null && tenants.tenantDocument.Any())
                {
                    foreach (var td in tenants.tenantDocument)
                    {
                        appDBContext.TenantDocuments.Add(new TenantDocument()
                        {
                            id = td.id,
                            propertyDirectoryId = properDirectoryId,
                            createDate          = td.createDate,
                            createdBy           = td.createdBy,
                            fileName            = td.fileName,
                            fileDesc            = td.fileDesc,
                            extName             = td.extName,
                            filePath            = td.filePath
                        });
                    }
                }

                appDBContext.Tenants.Add(t);
                //await appDBContext.SaveChangesAsync();

                //---------------------------------------------


                var pd = new PropertyDirectory();

                //id = properDirectoryId;
                pd.id         = properDirectoryId;
                pd.createDate = datetoday;
                pd.createdBy  = UserName;
                pd.propertyId = tenants.propertyid;
                //pd.property = tenants.properties.Where(a => a.id.Equals(Guid.Parse(tenants.propertyid))).FirstOrDefault();

                if (CompanyId == "ADBCA")
                {
                    pd.dateFrom = DateTime.Parse("01/01/1900");
                    pd.dateTo   = DateTime.Parse("12/31/2099");
                }
                else
                {
                    pd.dateFrom = tenants.dateFrom;
                    pd.dateTo   = tenants.dateTo;
                }

                pd.companyId   = CompanyId;
                pd.monthlyRate = new_monthly_rate;
                pd.tenandId    = tenantId.ToString();

                pd.associationDues     = _assorate;
                pd.penaltyPct          = tenants.penaltyPct;
                pd.ratePerSQM          = tenants.ratePerSQM;
                pd.totalBalance        = tenants.totalBalance;
                pd.withWT              = withWT_sw;
                pd.ratePerSQMAssocDues = tenants.ratePerSQMAssocDues;

                appDBContext.PropertyDirectory.Add(pd);
                await appDBContext.SaveChangesAsync();
            }
            else
            {
                var t = await appDBContext.Tenants
                        //.Select(a => new { id = a.id, company = a.company, lastName = a.lastName, firstName = a.firstName, middleName = a.middleName, contactNumber = a.contactNumber, emailAddress = a.emailAddress })
                        .Include(a => a.company)
                        .Where(r => r.id.Equals(tenandId) && r.company.companyId.Equals(CompanyId) && r.deleted.Equals(false)).FirstOrDefaultAsync();


                t.tenantProxID  = tenants.tenantProxID;
                t.lastName      = tenants.lastName;
                t.firstName     = tenants.firstName;
                t.middleName    = tenants.middleName;
                t.TenantIDs     = tenants.TenantIDs;
                t.homeAddress   = tenants.homeAddress;
                t.contactNumber = tenants.contactNumber;
                t.emailAddress  = tenants.emailAddress;

                //t.Owned_Mgd = tenants.Owned_Mgd;
                //t.MgtFeePct = tenants.MgtFeePct;
                //t.CCTNumber = tenants.CCTNumber;


                t.contactNo2              = tenants.contactNo2;
                t.contactNo3              = tenants.contactNo3;
                t.workAddress             = tenants.workAddress;
                t.emergyFullName          = tenants.emergyFullName;
                t.emergyContactNo         = tenants.emergyContactNo;
                t.emergyAdrress           = tenants.emergyAdrress;
                t.emergyRelationshipOwner = tenants.emergyRelationshipOwner;
                //t.otherRestenanted1 = tenants.otherRestenanted1;
                //t.otherResResiding1 = tenants.otherResResiding1;
                //t.otherResFullName1 = tenants.otherResFullName1;
                //t.otherResRelationshipToOwner1 = tenants.otherResRelationshipToOwner1;
                //t.otherRestenanted2 = tenants.otherRestenanted2;
                //t.otherResResiding2 = tenants.otherResResiding2;
                //t.otherResFullName2 = tenants.otherResFullName2;
                //t.otherResRelationshipToOwner2 = tenants.otherResRelationshipToOwner2;
                //t.otherRestenanted3 = tenants.otherRestenanted3;
                //t.otherResResiding3 = tenants.otherResResiding3;
                //t.otherResFullName3 = tenants.otherResFullName3;
                //t.otherResRelationshipToOwner3 = tenants.otherResRelationshipToOwner3;

                t.subTenantProxID1      = tenants.subTenantProxID1;
                t.subTenantFullName1    = tenants.subTenantFullName1;
                t.subTenantID1          = tenants.subTenantID1;
                t.subTenantHomeAddress1 = tenants.subTenantHomeAddress1;
                t.subTenantWorkAddress1 = tenants.subTenantWorkAddress1;
                t.subTenantContactNo1   = tenants.subTenantContactNo1;
                t.subTenantEmailAdd1    = tenants.subTenantEmailAdd1;
                t.RelToPrimary1         = tenants.RelToPrimary1;


                t.subTenantProxID2      = tenants.subTenantProxID2;
                t.subTenantFullName2    = tenants.subTenantFullName2;
                t.subTenantID2          = tenants.subTenantID2;
                t.subTenantHomeAddress2 = tenants.subTenantHomeAddress2;
                t.subTenantWorkAddress2 = tenants.subTenantWorkAddress2;
                t.subTenantContactNo2   = tenants.subTenantContactNo2;
                t.subTenantEmailAdd2    = tenants.subTenantEmailAdd2;
                t.RelToPrimary2         = tenants.RelToPrimary2;

                t.subTenantProxID3      = tenants.subTenantProxID3;
                t.subTenantFullName3    = tenants.subTenantFullName3;
                t.subTenantID3          = tenants.subTenantID3;
                t.subTenantHomeAddress3 = tenants.subTenantHomeAddress3;
                t.subTenantWorkAddress3 = tenants.subTenantWorkAddress3;
                t.subTenantContactNo3   = tenants.subTenantContactNo3;
                t.subTenantEmailAdd3    = tenants.subTenantEmailAdd3;
                t.RelToPrimary3         = tenants.RelToPrimary3;


                appDBContext.Tenants.Update(t);
                //await appDBContext.SaveChangesAsync();



                var pd = await appDBContext.PropertyDirectory
                         //.Select(a => new { id = a.id, company = a.company, lastName = a.lastName, firstName = a.firstName, middleName = a.middleName, contactNumber = a.contactNumber, emailAddress = a.emailAddress })
                         .Include(a => a.company)
                         .Include(a => a.property)
                         .Include(a => a.tenant)
                         .Where(r => r.id.Equals(Guid.Parse(id)) && r.companyId.Equals(CompanyId) && r.deleted.Equals(false)).FirstOrDefaultAsync();


                //id = properDirectoryId;

                pd.updateDate = datetoday;
                pd.updatedBy  = UserName;

                pd.dateFrom = tenants.dateFrom;
                pd.dateTo   = tenants.dateTo;
                //pd.monthlyRate = tenants.monthlyRate;
                pd.monthlyRate         = new_monthly_rate;
                pd.associationDues     = _assorate;
                pd.penaltyPct          = tenants.penaltyPct;
                pd.ratePerSQM          = tenants.ratePerSQM;
                pd.totalBalance        = tenants.totalBalance;
                pd.withWT              = withWT_sw;
                pd.ratePerSQMAssocDues = tenants.ratePerSQMAssocDues;


                appDBContext.PropertyDirectory.Update(pd);
                //await appDBContext.SaveChangesAsync();


                //if (selectedFiles != null)
                //{
                //    foreach (var file in selectedFiles)
                //    {


                //        //var tmpPath = Path.Combine(_env.WebRootPath, "Uploaded/TenantDocument");
                //        var tmpPath = Path.Combine(_env.WebRootPath, "Uploaded", "Attachments");
                //        if (!Directory.Exists(tmpPath))
                //        {
                //            Directory.CreateDirectory(tmpPath);
                //        }

                //        string fileId = Guid.NewGuid().ToString();

                //        var prefix = $"{DateTime.Today.ToString("yyyyMMdd")}{Guid.NewGuid().ToString()}";


                //        var _filename = file.Name.Split(".");

                //        string outputfile = _filename[0].ToString();
                //        string extname = "." + _filename[1].ToString();

                //        var filedestination = tmpPath + "\\" + prefix + extname;



                //        var td = new TenantDocument();

                //        td.createDate = datetoday;
                //        td.createdBy = UserName;
                //        td.propertyDirectoryId = Guid.Parse(id);
                //        td.id = Guid.Parse(fileId);
                //        td.fileName = prefix.ToString();
                //        td.filePath = filedestination.ToString();
                //        td.fileDesc = file.Name;
                //        td.extName = extname;

                //        appDBContext.TenantDocuments.Add(td);
                //        await appDBContext.SaveChangesAsync();

                //        using (FileStream DestinationStream = File.Create(filedestination))
                //        {
                //            await file.Data.CopyToAsync(DestinationStream);
                //        }
                //    }
                //}

                var tenantDocs = await appDBContext.TenantDocuments.Where(td => td.propertyDirectoryId.Equals(pd.id)).ToListAsync();


                if (tenants.tenantDocument != null && tenants.tenantDocument.Any())
                {
                    foreach (var td in tenants.tenantDocument)
                    {
                        var tenantDoc = tenantDocs.Where(d => d.id.Equals(td.id)).FirstOrDefault();
                        if (tenantDoc == null)
                        {
                            appDBContext.TenantDocuments.Add(new TenantDocument()
                            {
                                id = td.id,
                                propertyDirectoryId = pd.id,
                                createDate          = td.createDate,
                                createdBy           = td.createdBy,
                                fileName            = td.fileName,
                                fileDesc            = td.fileDesc,
                                extName             = td.extName,
                                filePath            = td.filePath
                            });
                        }
                        else
                        {
                            tenantDoc.deleted = tenantDoc.deleted;
                            appDBContext.TenantDocuments.Update(tenantDoc);
                        }
                    }
                }

                await appDBContext.SaveChangesAsync();
            }



            StateHasChanged();

            NavigateToList();
        }