public void SavePayrollSetupItem() { using (var ctx = new PayrollDB(Properties.Settings.Default.PayrollDB)) { if (CurrentPayrollSetupItem == null) { return; } if (CurrentPayrollSetupItem.PayrollSetupItemId == 0) { ctx.PayrollSetupItems.AddObject(CurrentPayrollSetupItem); } else { if (CurrentPayrollSetupItem.EntityState == EntityState.Added) { return; } var ritm = ctx.PayrollSetupItems.First( x => x.PayrollSetupItemId == CurrentPayrollSetupItem.PayrollSetupItemId); ctx.PayrollSetupItems.Attach(ritm); ctx.PayrollSetupItems.ApplyCurrentValues(CurrentPayrollSetupItem); } SaveDatabase(ctx); } LoadPayrollSetupItems(); OnStaticPropertyChanged("PayrollSetupItems"); OnStaticPropertyChanged("CurrentPayrollSetupItem"); OnStaticPropertyChanged("PayrollSetupItemsCollection"); }
public void DeleteEmployee() { using (var ctx = new PayrollDB(Properties.Settings.Default.PayrollDB)) { if (CurrentEmployee == null) { MessageBox.Show("Please select an employee"); return; } if (CurrentEmployee.EmployeeId != 0) { if (CurrentEmployee.EntityState == EntityState.Added) { return; } var ritm = ctx.Employees.FirstOrDefault(x => x.EmployeeId == CurrentEmployee.EmployeeId); ctx.Employees.DeleteObject(ritm); SaveDatabase(ctx); } CurrentEmployee = null; GetEmployees(); OnStaticPropertyChanged("CurrentEmployee"); OnStaticPropertyChanged("Employees"); } }
public void SaveInstitution() { if (CurrentInstitution == null) { return; } using (var ctx = new PayrollDB(Properties.Settings.Default.PayrollDB)) { if (CurrentInstitution.InstitutionId == 0) { ctx.Institutions.AddObject(CurrentInstitution); } else { if (CurrentInstitution.EntityState == EntityState.Added) { return; } var ritm = ctx.Institutions.First(x => x.InstitutionId == CurrentInstitution.InstitutionId); ctx.Institutions.Attach(ritm); ctx.Institutions.ApplyCurrentValues(CurrentInstitution); } SaveDatabase(ctx); } OnStaticPropertyChanged("CurrentInstitutionAccount"); // CycleInstitutionAccounts(); OnStaticPropertyChanged("InstitutionAccounts"); }
public void SavePayrollEmployeeSetup() { if (CurrentPayrollEmployeeSetup == null) { return; } using (var ctx = new PayrollDB(Properties.Settings.Default.PayrollDB)) { if (CurrentPayrollEmployeeSetup.PayrollEmployeeSetupId == 0) { ctx.PayrollEmployeeSetups.AddObject(CurrentPayrollEmployeeSetup); } else { if (CurrentPayrollEmployeeSetup.EntityState == EntityState.Added) { return; } var ritm = ctx.PayrollEmployeeSetups.First( x => x.PayrollEmployeeSetupId == CurrentPayrollEmployeeSetup.PayrollEmployeeSetupId); ctx.PayrollEmployeeSetups.Attach(ritm); ctx.PayrollEmployeeSetups.ApplyCurrentValues(CurrentPayrollEmployeeSetup); } SaveDatabase(ctx); } OnStaticPropertyChanged("PayrollEmployeeSetup"); }
public void DeleteCompany() { if (CurrentCompany == null) { return; } var res = MessageBox.Show( "Are you sure you want to Delete this Company?", "Delete Payroll Job", MessageBoxButton.YesNo); if (res == MessageBoxResult.No) { return; } if (CurrentCompany.InstitutionId != 0) { using (var ctx = new PayrollDB(Properties.Settings.Default.PayrollDB)) { ctx.Companies.Attach(CurrentCompany); ctx.Companies.DeleteObject(CurrentCompany); // db.PayrollItems.Detach(CurrentPayrollItem); SaveDatabase(ctx); } } CurrentCompany = null; OnStaticPropertyChanged("CurrentCompany"); OnStaticPropertyChanged("Companies"); }
public void DeletePayrollItem() { if (CurrentPayrollItem == null) { return; } using (var ctx = new PayrollDB(Properties.Settings.Default.PayrollDB)) { if (CurrentPayrollItem.PayrollItemId != 0) { var ritm = ctx.PayrollItems.First(x => x.PayrollItemId == CurrentPayrollItem.PayrollItemId); foreach (var item in ctx.AccountEntries.Where(x => x.PayrollItemId == CurrentPayrollItem.PayrollItemId).ToList()) { ctx.AccountEntries.DeleteObject(item); } ctx.PayrollItems.DeleteObject(ritm); SaveDatabase(ctx); CurrentPayrollItems = ctx.PayrollItems.Include(x => x.PayrollSetupItem).Where(x => x.EmployeeId == CurrentEmployee.EmployeeId && x.PayrollJobId == CurrentPayrollJob.PayrollJobId) .ToList(); UpdatePayrollItemsBaseAmounts(CurrentPayrollItems, ctx); } CurrentPayrollItem = null; OnStaticPropertyChanged("CurrentPayrollJob"); OnStaticPropertyChanged("PayrollItems"); OnStaticPropertyChanged("Employees"); OnStaticPropertyChanged("CurrentPayrollItem"); } }
public EmployeeAccountDetailsModel() { using (var ctx = new PayrollDB(Properties.Settings.Default.PayrollDB)) { _employeeAccountTypes = new ListCollectionView(ctx.AccountTypes.ToList()); } }
public void SaveEmployeeAccount() { if (CurrentEmployeeAccount == null) { return; } using (var ctx = new PayrollDB(Properties.Settings.Default.PayrollDB)) { if (CurrentEmployeeAccount.AccountId == 0) { ctx.Accounts.AddObject(CurrentEmployeeAccount); } else { if (CurrentEmployeeAccount.EntityState == EntityState.Added) { return; } var ritm = ctx.Accounts.First(x => x.AccountId == CurrentEmployeeAccount.AccountId); ctx.Accounts.Attach(ritm); ctx.Accounts.ApplyCurrentValues(CurrentEmployeeAccount); } SaveDatabase(ctx); } OnStaticPropertyChanged("CurrentEmployeeAccount"); OnStaticPropertyChanged("EmployeeAccounts"); }
public void SaveEmployee() { if (CurrentEmployee == null) { return; } if (string.IsNullOrEmpty(CurrentEmployee.LastName) || string.IsNullOrEmpty(CurrentEmployee.FirstName) || CurrentEmployee.CompanyId == null) { MessageBox.Show("Employee Must Have First Name, Last Name and Location."); return; } using (var ctx = new PayrollDB(Properties.Settings.Default.PayrollDB)) { if (CurrentEmployee.EmployeeId == 0) { ctx.Employees.AddObject(CurrentEmployee); } else { if (CurrentEmployee.EntityState == EntityState.Added) { return; } var ritm = ctx.Employees.First(x => x.EmployeeId == CurrentEmployee.EmployeeId); ctx.Employees.Attach(ritm); ctx.Employees.ApplyCurrentValues(CurrentEmployee); } SaveDatabase(ctx); } LoadEmployees(); OnStaticPropertyChanged("CurrentEmployee"); OnStaticPropertyChanged("Employees"); }
void PayrollItemDetailsModel_staticPropertyChanged(object sender, PropertyChangedEventArgs e) { OnPropertyChanged(e.PropertyName); Debug.WriteLine(e.PropertyName); if ((e.PropertyName.Contains("Account") && e.PropertyName != "CurrentAccountsLst") || (e.PropertyName == "CurrentEmployee")) { UpdateCurrentAccountsLst(); OnStaticPropertyChanged("CurrentAccountsLst"); } if (e.PropertyName == nameof(CurrentEmployee)) { if (CurrentEmployee == null) { CurrentPayrollItems = new List <PayrollItem>(); } else { using (var ctx = new PayrollDB()) { CurrentPayrollItems = ctx.PayrollItems.Where(x => x.EmployeeId == CurrentEmployee.EmployeeId) .ToList(); } } } }
public void SaveAccount() { using (var ctx = new PayrollDB(Properties.Settings.Default.PayrollDB)) { if (CurrentAccount == null) { return; } if (CurrentAccount.AccountId == 0) { ctx.Accounts.AddObject(CurrentAccount); } else { if (CurrentAccount.EntityState == EntityState.Added) { return; } var ritm = ctx.Accounts.First(x => x.AccountId == CurrentAccount.AccountId); ctx.Accounts.Attach(ritm); ctx.Accounts.ApplyCurrentValues(CurrentAccount); } SaveDatabase(ctx); } LoadInstitutions(); LoadInstitutionsAndCompanies(); CurrentAccount = null; OnStaticPropertyChanged("CurrentAccount"); // CycleAccounts(); OnStaticPropertyChanged("Accounts"); }
public void DeletePayrollJob() { if (CurrentPayrollJob == null) { return; } var res = MessageBox.Show( "Are you sure you want to Delete this payroll Job? Have you checked all 'One Off' Payroll items?", "Delete Payroll Job", MessageBoxButton.YesNo); if (res == MessageBoxResult.No) { return; } if (CurrentPayrollJob.PayrollJobId != 0) { using (var ctx = new PayrollDB(Properties.Settings.Default.PayrollDB)) { ctx.PayrollJobs.Attach(CurrentPayrollJob); ctx.PayrollJobs.DeleteObject(CurrentPayrollJob); // db.PayrollItems.Detach(CurrentPayrollItem); SaveDatabase(ctx); } } CurrentPayrollJob = null; UpdatePayrollJobs(); OnStaticPropertyChanged("CurrentPayrollJob"); OnStaticPropertyChanged("PayrollJobs"); }
private async Task <List <EmployeeSummaryLine> > GetEmployeeDeductionsData() { try { var t = Task.Run(() => { if (CurrentPayrollJob == null) { return(new List <EmployeeSummaryLine>()); } using (var ctx = new PayrollDB()) { var plist = ctx.PayrollItems //use this to get all jobs over branches .Where(x => x.PayrollJob.StartDate == CurrentPayrollJob.StartDate && x.PayrollJob.EndDate == CurrentPayrollJob.EndDate && x.PayrollJob.PayrollJobTypeId == CurrentPayrollJob.PayrollJobTypeId) .Include("CreditAccount.Institution") .Include(x => x.Employee) .Where(pi => pi.DebitAccount.EmployeeAccounts != null && "Salary Deduction,Communal Birthday Club".ToUpper() .Contains(pi.Name.Trim().ToUpper())) .OrderBy(x => x.Employee.LastName) .GroupBy(p => new { DisplayName = p.Employee.FirstName + " " + p.Employee.LastName }) .Select(g => new { Employee = g.Key.DisplayName, Total = g.Sum(p => p.Amount), PayrollItems = g }) .ToList() .Select(g => new EmployeeSummaryLine { Employee = g.Employee, Total = g.Total, PayrollItems = g.PayrollItems.ToList() }).ToList(); if (!plist.Any()) { return(new List <EmployeeSummaryLine>()); } plist.ForEach(x => { x.PayrollItems.ForEach(z => { z.CreditAccountReference.Load(); z.CreditAccount.InstitutionReference.Load(); }); }); return(plist); } }).ConfigureAwait(false); return(await t); } catch (Exception) { throw; } }
private double GetAccountTotal(object value) { DataLayer.Account ia = value as DataLayer.Account; using (var ctx = new PayrollDB()) { return(ctx.AccountEntries.Where(ae => ae.AccountId == ia.AccountId).Sum(ae => ae.Total)); } }
public void NewEmployeeAccount() { using (var ctx = new PayrollDB(Properties.Settings.Default.PayrollDB)) { DataLayer.EmployeeAccount newemp = ctx.Accounts.CreateObject <DataLayer.EmployeeAccount>(); ctx.Accounts.AddObject(newemp); CurrentEmployeeAccount = newemp; } }
private double GetAccountTotal(object value, object parameter) { DataLayer.Account ia = value as DataLayer.Account; DataLayer.PayrollJob pj = parameter as DataLayer.PayrollJob; using (var ctx = new PayrollDB()) { return(ctx.AccountEntries.Where(ae => ae.AccountId == ia.AccountId && ae.PayrollItem.PayrollJobId == pj.PayrollJobId).Sum(ae => ae.Total)); } }
public void NewEmployee() { using (var ctx = new PayrollDB(Properties.Settings.Default.PayrollDB)) { var newemp = ctx.Employees.CreateObject <DataLayer.Employee>(); ctx.Employees.AddObject(newemp); CurrentEmployee = newemp; } OnPropertyChanged("CurrentEmployee"); }
public void NewPayrollSetupItem() { using (var ctx = new PayrollDB(Properties.Settings.Default.PayrollDB)) { PayrollSetupItem newpi = ctx.PayrollSetupItems.CreateObject(); ctx.PayrollSetupItems.AddObject(newpi); CurrentPayrollSetupItem = newpi; OnPropertyChanged("CurrentPayrollSetupItem"); } }
private async Task <List <EmployeeAccountSummaryLine> > GetNetSalaryData() { if (CurrentPayrollJob == null) { return(new List <EmployeeAccountSummaryLine>()); } var currentPayrollJob = CurrentPayrollJob; var t = Task.Run(() => { try { using (var ctx = new PayrollDB()) { var employeeSalaryData = ctx.PayrollItems.Where(x => x.PayrollJob.StartDate == currentPayrollJob.StartDate && x.PayrollJob.EndDate == currentPayrollJob.EndDate && x.PayrollJob.PayrollJobTypeId == currentPayrollJob.PayrollJobTypeId) .Include(x => x.CreditAccount.Institution) .Include(x => x.CreditAccount.AccountEntries) .Include(x => x.PayrollJob.PayrollJobType) .Include(x => x.Employee) //use this to get all jobs over branches .Where(pi => (pi.PayrollJob.StartDate == currentPayrollJob.StartDate && pi.PayrollJob.EndDate == currentPayrollJob.EndDate && pi.PayrollJob.PayrollJobTypeId == currentPayrollJob.PayrollJobTypeId) && pi.CreditAccount.EmployeeAccounts != null && pi.Name.Trim().ToUpper() == "Salary".ToUpper() ) .OrderBy(x => x.Employee.LastName) .Select(p => new { DisplayName = p.Employee.FirstName + " " + p.Employee.LastName, p.CreditAccount, Total = (double?)p.CreditAccount.AccountEntries.Where(z => z.PayrollItem.PayrollJob.StartDate == currentPayrollJob.StartDate && z.PayrollItem.PayrollJob.EndDate == currentPayrollJob.EndDate && z.PayrollItem.PayrollJob.PayrollJobTypeId == currentPayrollJob.PayrollJobTypeId).Sum(q => q.CreditAmount - q.DebitAmount) }) .Select(g => new EmployeeAccountSummaryLine { Employee = g.DisplayName, Account = g.CreditAccount, Total = g.Total ?? 0 }) .ToList(); if (!employeeSalaryData.Any()) { return(new List <EmployeeAccountSummaryLine>()); } employeeSalaryData.ForEach(x => x.Account.InstitutionReference.Load()); return(employeeSalaryData); } } catch (Exception e) { Console.WriteLine(e); throw; } }).ConfigureAwait(false); return(await t); }
public void NewInstitution() { using (var ctx = new PayrollDB(Properties.Settings.Default.PayrollDB)) { DataLayer.Institution newemp = ctx.Institutions.CreateObject(); ctx.Institutions.AddObject(newemp); CurrentInstitution = newemp; } OnPropertyChanged("CurrentInstitution"); }
public void NewAccount() { using (var ctx = new PayrollDB(Properties.Settings.Default.PayrollDB)) { DataLayer.Account newemp = ctx.Accounts.CreateObject <DataLayer.InstitutionAccounts>(); ctx.Accounts.AddObject(newemp); CurrentAccount = newemp; OnPropertyChanged("CurrentAccount"); } }
public void DeletePayrollEmployeeSetup(PayrollEmployeeSetup pi) { if (pi.PayrollEmployeeSetupId != 0) { using (var ctx = new PayrollDB(Properties.Settings.Default.PayrollDB)) { var ritm = ctx.PayrollEmployeeSetups.First(x => x.PayrollEmployeeSetupId == pi.PayrollEmployeeSetupId); ctx.PayrollEmployeeSetups.DeleteObject(ritm); SaveDatabase(ctx); } } pi = null; }
internal void DeleteEmployeeAccount(DataLayer.EmployeeAccount p) { if (p.AccountId != 0) { using (var ctx = new PayrollDB(Properties.Settings.Default.PayrollDB)) { var ritm = ctx.EmployeeAccounts.FirstOrDefault(x => x.AccountId == p.AccountId); ctx.EmployeeAccounts.DeleteObject(ritm); OnStaticPropertyChanged("CurrentEmployee"); OnStaticPropertyChanged("EmployeeAccounts"); } } p = null; }
private void EmailAllReport(object sender, MouseButtonEventArgs e) { using (var ctx = new PayrollDB()) { var emplst = BaseViewModel.Instance.Employees; foreach (var employee in emplst) { im.CurrentEmployee = employee; DailyReportGD.UpdateLayout(); im.EmailReport(ref DailyReportGD); } MessageBox.Show("Email Created. Please Check Drafts to review then send"); } }
void PayrollSetupItemsList_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { using (var ctx = new PayrollDB(Properties.Settings.Default.PayrollDB)) { foreach (PayrollSetupItem itm in e.NewItems) { ctx.PayrollSetupItems.Attach(itm); ctx.PayrollSetupItems.ApplyCurrentValues(itm); } SaveDatabase(ctx); } OnStaticPropertyChanged("PayrollSetupItems"); // UpdateDataSource(); }
public void NewPayrollItem() { using (var ctx = new PayrollDB(Properties.Settings.Default.PayrollDB)) { DataLayer.PayrollItem newpi = ctx.PayrollItems.CreateObject(); //ctx.PayrollJobs.Attach(CurrentPayrollJob); //newpi.PayrollJob = CurrentPayrollJob; newpi.EmployeeId = CurrentEmployee.EmployeeId; newpi.PayrollJobId = CurrentPayrollJob.PayrollJobId; ctx.PayrollItems.AddObject(newpi); newpi.Status = "Amounts Processed"; CurrentPayrollItem = newpi; OnPropertyChanged("CurrentPayrollItem"); SaveDatabase(ctx); } }
private List <CompanyPayrollItemSummaryLine> GetCompanyData() { try { using (var ctx = new PayrollDB()) { var startDate = DateTime.Parse(string.Format("{0}/1/{1}", ReportDate.Month, ReportDate.Year)); var endDate = DateTime.Parse(string.Format("{0}/1/{1}", ReportDate.AddMonths(1).Month, ReportDate.AddMonths(1).Year)); var plst = (from p in ctx.PayrollItems//.Where(x => x.PayrollJobId == CurrentPayrollJob.PayrollJobId) .Where( pi => pi.PayrollJob.EndDate.Month == ReportDate.Month && pi.PayrollJob.EndDate.Year == ReportDate.Year) .Include(x => x.PayrollJob.Company.Institution) .OrderByDescending(x => x.IncomeDeduction) .ThenBy(x => x.PayrollSetupItem == null ? x.Priority : x.PayrollSetupItem.Priority) group p by new { p.Name } into g select new CompanyPayrollItemSummaryLine { Payroll_Item = g.Key.Name, Total = g.Sum(p => p.Amount), PayrollItems = g.OrderByDescending(x => x.IncomeDeduction) .ThenBy(x => x.PayrollSetupItem == null ? x.Priority : x.PayrollSetupItem.Priority) }).ToList(); if (!plst.Any()) { return(null); } plst.ForEach(x => x.PayrollItems.ToList().ForEach(z => { z.PayrollJobReference.Load(); z.PayrollJob.CompanyReference.Load(); z.PayrollJob.Company.InstitutionReference.Load(); })); return(plst); } } catch (Exception) { throw; } }
public void DeleteEmployeeAccount() { using (var ctx = new PayrollDB(Properties.Settings.Default.PayrollDB)) { if (CurrentEmployeeAccount == null) { return; } ctx.Accounts.Attach(CurrentEmployeeAccount); ctx.Accounts.DeleteObject(CurrentEmployeeAccount); // db.PayrollItems.Detach(CurrentPayrollItem); SaveDatabase(ctx); CurrentEmployeeAccount = null; } }
public void DeleteInstition() { if (CurrentInstitution == null) { return; } if (CurrentInstitution.InstitutionId != 0) { using (var ctx = new PayrollDB(Properties.Settings.Default.PayrollDB)) { var ritm = ctx.Institutions.First(x => x.InstitutionId == CurrentInstitution.InstitutionId); ctx.Institutions.DeleteObject(ritm); SaveDatabase(ctx); } } CurrentInstitution = null; }
public void NewCompany() { DataLayer.Company newCompany; using (var ctx = new PayrollDB(Properties.Settings.Default.PayrollDB)) { newCompany = ctx.Companies.CreateObject <DataLayer.Company>(); newCompany.Institution = ctx.Institutions.CreateObject <DataLayer.Institution>(); newCompany.Institution.Name = "Name"; newCompany.Institution.ShortName = "Short Name"; newCompany.Institution.Address = "Address"; newCompany.Institution.PhoneNumber = "Phone Number"; ctx.Companies.AddObject(newCompany); SaveDatabase(ctx); } CurrentCompany = newCompany; OnPropertyChanged("CurrentCompany"); }