/// <summary> /// Ajouter Un Recue a Payer Par l'Etudiant /// </summary> /// <param name="myBill"></param> /// <returns>True pour Success</returns> public bool AddFeeReceipt(StudentBill myBill) { if (myBill.NetAmount < 0.0000001) { return(true); } if (FeeReceiptExist(myBill)) { return(true); } using (var db = new SchoolContext()) if (db.Students.Find(myBill.StudentGuid) == null) { throw new InvalidOperationException("STUDENT_REFERENCE_NOT_FOUND"); } using (var db = new EconomatContext()) { var newSchoolFee = new SchoolFee { SchoolFeeGuid = myBill.SchoolFeeGuid == Guid.Empty ? Guid.NewGuid() : myBill.SchoolFeeGuid, StudentGuid = myBill.StudentGuid, Designation = myBill.Designation, NetAmount = myBill.NetAmount, DueDate = myBill.DueDate, DateAdded = DateTime.Now, AddUserGuid = Guid.Empty, LastEditUserGuid = Guid.Empty }; db.SchoolFees.Add(newSchoolFee); return(db.SaveChanges() > 0); } }
/// <summary> /// /// </summary> /// <param name="newTransaction"></param> /// <returns></returns> internal static bool StaticNewTransaction(Transaction newTransaction) { //if(Math.Abs(newTransaction.Amount) < 0.000000000000000001) // return true; if (TransactionExist(newTransaction)) { throw new InvalidOperationException("TRANSACTION_REFERENCE_ALREADY_EXIST"); } if (newTransaction.TransactionDate < DateTime.Today.AddDays(-1)) { throw new InvalidOperationException("TRANSACTION_DATE_NOT_VALIDE"); } using (var db = new EconomatContext()) { newTransaction.TransactionGuid = newTransaction.TransactionGuid == Guid.Empty ? Guid.NewGuid() : newTransaction.TransactionGuid; var transDate = newTransaction.TransactionDate.GetValueOrDefault(); newTransaction.TransactionDate = new DateTime(transDate.Year, transDate.Month, transDate.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second); if (string.IsNullOrEmpty(newTransaction.Description)) { newTransaction.Description = newTransaction.Designation; } newTransaction.DateAdded = DateTime.Now; newTransaction.AddUserGuid = Guid.Empty; newTransaction.LastEditDate = DateTime.Now; newTransaction.LastEditUserGuid = Guid.Empty; db.Transactions.Add(newTransaction); return(db.SaveChanges() > 0); } }
/// <summary> /// Supprime Un Recue /// </summary> /// <param name="myReceiptGuid">Guid du Ticket</param> /// <returns>True pour Success</returns> protected internal static bool HardDeleteFeeReceipt(Guid myReceiptGuid) { using (var db = new EconomatContext()) { //db.FeeReceipts.Remove(db.FeeReceipts.Find(myReceiptGuid)); return(db.SaveChanges() > 0); } }
/// <summary> /// Soft Supprime Un Recue /// </summary> /// <param name="myPayOff">Guid du Ticket</param> /// <returns>True pour Success</returns> protected internal static bool DeleteFeeReceipt(BillPayOff myPayOff) { using (var db = new EconomatContext()) { //db.FeeReceipts.Attach(myReceipt); db.Entry(myPayOff).State = EntityState.Modified; return(db.SaveChanges() > 0); } }
/// <summary> /// Modifier un Recue /// </summary> /// <param name="myPayOff"></param> /// <returns>True pour Success</returns> protected internal static bool UpdateFeeReceipt(BillPayOff myPayOff) { //myPayement.DateEdited = DateTime.Now; using (var db = new EconomatContext()) { //db.FeeReceipts.Attach(myReceipt); db.Entry(myPayOff).State = EntityState.Modified; return(db.SaveChanges() > 0); } }
/// <summary> /// Modifier les information d'un salaire /// </summary> /// <param name="salary"></param> /// <exception cref="NotImplementedException"></exception> public bool CancelSalary(Salary salary) { if (string.IsNullOrEmpty(salary.Designation)) { throw new InvalidOperationException("DESIGNATION_CAN_NOT_BE_EMPTY"); } if (salary.StartDate > salary.EndDate) { throw new InvalidOperationException("START_DATE_SUPERIOR_TO_END_DATE"); } if (salary.EndDate < DateTime.Today) { throw new InvalidOperationException("END_DATE_CAN_NOT_BE_LESS_THAN_TODAY"); } Employment emp; using (var db = new EconomatContext()) emp = db.Employments.Find(salary.EmploymentGuid); if (emp == null) { throw new InvalidOperationException("EMPLOYEMENT_REFERENCE_NOT_FOUND"); } if ((salary.StartDate < emp.StartDate) || (salary.EndDate > emp.EndDate)) { throw new InvalidOperationException("DATES_CAN_NOT_BE_OUT_OF_EMPLOYMENT_BOUNDRIES"); } using (var db = new EconomatContext()) { var newSalary = db.Salaries.Find(salary.SalaryGuid); if (newSalary == null) { throw new InvalidOperationException("SALARY_REFERENCE_NOT_FOUND"); } newSalary.EndDate = salary.EndDate; newSalary.Description = salary.Description; var user = Membership.GetUser(); if (user == null) { throw new SecurityException("USER_CAN_NOT_DETERMINED"); } // ReSharper disable once PossibleNullReferenceException newSalary.LastEditUserGuid = (Guid)user.ProviderUserKey; newSalary.LastEditDate = DateTime.Now; db.Salaries.Attach(newSalary); db.Entry(newSalary).State = EntityState.Modified; return(db.SaveChanges() > 0); } }
/// <summary> /// /// </summary> /// <param name="salary"></param> /// <returns></returns> protected internal static bool StaticAddSalary(Salary salary) { if (SalaryExist(salary)) { return(true); } if (string.IsNullOrEmpty(salary.Designation)) { throw new InvalidOperationException("DESIGNATION_CAN_NOT_BE_EMPTY"); } if (salary.StartDate > salary.EndDate) { throw new InvalidOperationException("START_DATE_SUPERIOR_TO_END_DATE"); } Employment emp; using (var db = new EconomatContext()) emp = db.Employments.Find(salary.EmploymentGuid); if (emp == null) { throw new InvalidOperationException("EMPLOYEMENT_REFERENCE_NOT_FOUND"); } if ((salary.StartDate < emp.StartDate) || (salary.EndDate > emp.EndDate)) { throw new InvalidOperationException("DATES_CAN_NOT_BE_OUT_OF_EMPLOYMENT_BOUNDRIES"); } using (var db = new EconomatContext()) { if (salary.SalaryGuid == Guid.Empty) { salary.SalaryGuid = Guid.NewGuid(); } if (salary.Description == string.Empty) { salary.Description = salary.Designation; } salary.DateAdded = DateTime.Now; salary.AddUserGuid = Guid.Empty; salary.LastEditDate = DateTime.Now; salary.LastEditUserGuid = Guid.Empty; db.Salaries.Add(salary); return(db.SaveChanges() > 0); } }
/// <summary> /// Modifier les information d'un employement /// </summary> /// <param name="employ"></param> /// <returns></returns> /// <exception cref="NotImplementedException"></exception> public bool UpdateEmployment(Employment employ) { if (string.IsNullOrEmpty(employ.Position)) { throw new InvalidOperationException("POSITION_CAN_NOT_BE_EMPTY"); } if (employ.StartDate > employ.EndDate) { throw new InvalidOperationException("START_DATE_SUPERIOR_TO_END_DATE"); } using (var db = new SchoolContext()) if (db.Staffs.Find(employ.StaffGuid) == null) { throw new InvalidOperationException("STAFF_REFERENCE_NOT_FOUND"); } using (var db = new EconomatContext()) { var newEmploy = db.Employments.Find(employ.EmploymentGuid); if (newEmploy == null) { throw new InvalidOperationException("EMPLOYEMENT_REFERENCE_NOT_FOUND"); } //todo cancel Employ newEmploy.Position = employ.Position; newEmploy.Category = employ.Category; newEmploy.Project = employ.Project; newEmploy.Grade = employ.Grade; newEmploy.Departement = employ.Departement; newEmploy.Division = employ.Division; newEmploy.ReportTo = employ.ReportTo; //newEmploy.SalaryRecurrence = employ.SalaryRecurrence; //newEmploy.StartDate = employ.StartDate; //newEmploy.EndDate = employ.EndDate; newEmploy.Description = employ.Description; newEmploy.LastEditDate = DateTime.Now; newEmploy.LastEditUserGuid = Guid.Empty; db.Employments.Attach(newEmploy); db.Entry(newEmploy).State = EntityState.Modified; return(db.SaveChanges() > 0); } }
/// <summary> /// Confirmer paiement d'un salaire /// </summary> /// <param name="payrollGuid"></param> /// <param name="finalPaycheck"></param> /// <param name="numeroReference"></param> /// <param name="totalHoursWorked"></param> /// <returns></returns> /// <exception cref="InvalidOperationException"></exception> public bool Paycheck(Guid payrollGuid, double?finalPaycheck = null, string numeroReference = null, TimeSpan?totalHoursWorked = null) { using (var db = new EconomatContext()) { var payroll = db.Payrolls.Find(payrollGuid); if (payroll == null) { throw new InvalidOperationException("PAYROLL_REFERENCE_NOT_FOUND"); } if (payroll.IsPaid) { throw new InvalidOperationException("PAYCHECK_ALREADY_PAID"); } if (!string.IsNullOrEmpty(numeroReference) && SalarySlipExist(numeroReference)) { throw new InvalidOperationException("PAYSLIP_REFERENCE_DUPLICATE"); } if (totalHoursWorked != null) { payroll.HoursWorked = (TimeSpan)totalHoursWorked; } if (finalPaycheck == null) { finalPaycheck = (new PayrollCard(payroll)).TotalSalary; } payroll.FinalPaycheck = (double)finalPaycheck; payroll.IsPaid = true; payroll.IsPaidTo = Guid.Empty; payroll.DatePaid = DateTime.Now; payroll.NumeroReference = string.IsNullOrEmpty(numeroReference) ? GetNewSalarySlipRef() : numeroReference; payroll.LastEditDate = DateTime.Now; payroll.LastEditUserGuid = Guid.Empty; db.Payrolls.Attach(payroll); db.Entry(payroll).State = EntityState.Modified; return(db.SaveChanges() > 0); } }
/// <summary> /// Payer Frais d'Etude /// </summary> /// <param name="myPayOff"></param> /// <exception cref="InvalidDataException">CAN_NOT_FIND_SCHOOL_FEE_REFERENCE</exception> /// <exception cref="InvalidOperationException">SCHOOL_FEE_ALREADY_PAID</exception> /// <returns>True pour Success</returns> public bool PaySchoolFee(BillPayOff myPayOff) { using (var db = new EconomatContext()) { var newSchoolFee = db.SchoolFees.Find(myPayOff.SchoolFeeGuid); if (newSchoolFee == null) { throw new InvalidOperationException("CAN_NOT_FIND_BILL_REFERENCE"); } if (newSchoolFee.IsPaid) { throw new InvalidOperationException("BILL_ALREADY_PAID"); } if (string.IsNullOrEmpty(newSchoolFee.NumeroReference)) { newSchoolFee.NumeroReference = GetNewReceipRef(); } if (RefRecueExist(newSchoolFee.NumeroReference)) { throw new InvalidOperationException("RECEIPT_REFERENCE_ALREADY_EXIST"); } if (string.IsNullOrEmpty(newSchoolFee.Description)) { newSchoolFee.Description = "Reglement effectuer le " + DateTime.Now; } newSchoolFee.IsPaid = true; newSchoolFee.IsPaidBy = myPayOff.IsPaidBy; newSchoolFee.PaymentMethode = myPayOff.PaymentMethode; newSchoolFee.NumeroReference = myPayOff.NumeroReference; newSchoolFee.NumeroVirement = myPayOff.NumeroVirement; newSchoolFee.Bank = myPayOff.Bank; newSchoolFee.Description = myPayOff.Description; newSchoolFee.LastEditDate = DateTime.Now; newSchoolFee.DatePaid = DateTime.Now; db.SchoolFees.Attach(newSchoolFee); db.Entry(newSchoolFee).State = EntityState.Modified; return(db.SaveChanges() > 0); } }
/// <summary> /// Ajouter Un Employement Pour un Staff /// </summary> /// <param name="employ"></param> /// <returns>True pour Success</returns> public bool AddEmployment(Employment employ) { if (string.IsNullOrEmpty(employ.Position)) { throw new InvalidOperationException("POSITION_CAN_NOT_BE_EMPTY"); } if (employ.StartDate > employ.EndDate) { throw new InvalidOperationException("START_DATE_SUPERIOR_TO_END_DATE"); } using (var db = new SchoolContext()) if (db.Staffs.Find(employ.StaffGuid) == null) { throw new InvalidOperationException("STAFF_REFERENCE_NOT_FOUND"); } using (var db = new EconomatContext()) { if (employ.EmploymentGuid == Guid.Empty) { employ.EmploymentGuid = Guid.NewGuid(); } employ.DateAdded = DateTime.Now; employ.AddUserGuid = Guid.Empty; employ.LastEditDate = DateTime.Now; employ.LastEditUserGuid = Guid.Empty; db.Employments.Add(employ); if (db.SaveChanges() <= 0) { return(false); } foreach (var payRoll in PayRollHelper.GeneratePayRolls(employ)) { StaticAddPayRoll(payRoll); } return(true); } }
/// <summary> /// /// </summary> /// <param name="transactionGuid"></param> /// <returns></returns> public bool CancelTransaction(Guid transactionGuid) { using (var db = new EconomatContext()) { var theTransaction = db.Transactions.Find(transactionGuid); if (theTransaction == null) { throw new InvalidOperationException("CAN_NOT_FIND_REFERENCE_TRANSACTION"); } theTransaction.IsDeleted = true; theTransaction.DeleteDate = DateTime.Now; theTransaction.DeleteUserGuid = Guid.Empty; theTransaction.LastEditDate = DateTime.Now; theTransaction.LastEditUserGuid = Guid.Empty; db.Transactions.Attach(theTransaction); db.Entry(theTransaction).State = EntityState.Modified; return(db.SaveChanges() > 0); } }
/// <summary> /// Annuler un Paiement d'un salaire /// </summary> /// <param name="payrollGuid"></param> /// <param name="totalSalary"></param> public bool CancelPaycheck(Guid payrollGuid) { using (var db = new EconomatContext()) { var payroll = db.Payrolls.Find(payrollGuid); if (payroll == null) { throw new InvalidOperationException("PAYROLL_REFERENCE_NOT_FOUND"); } payroll.IsPaid = false; payroll.IsPaidTo = Guid.Empty; payroll.DatePaid = DateTime.Now; payroll.NumeroReference = string.Empty; payroll.LastEditDate = DateTime.Now; payroll.LastEditUserGuid = Guid.Empty; db.Payrolls.Attach(payroll); db.Entry(payroll).State = EntityState.Modified; return(db.SaveChanges() > 0); } }
/// <summary> /// Ajouter un Payroll /// </summary> /// <returns></returns> protected internal static bool StaticAddPayRoll(Payroll payRoll) { if (PayRollExist(payRoll)) { return(true); } using (var db = new EconomatContext()) { if (payRoll.PayrollGuid == Guid.Empty) { payRoll.PayrollGuid = Guid.NewGuid(); } payRoll.DateAdded = DateTime.Now; payRoll.AddUserGuid = Guid.Empty; payRoll.LastEditDate = DateTime.Now; payRoll.LastEditUserGuid = Guid.Empty; db.Payrolls.Add(payRoll); return(db.SaveChanges() > 0); } }