public ActionResult NewOrEdit(split_expenses model, FormCollection frm) { try { var db = DB.Entities; model.Date = CommonFunction.ChangeFormatDate(frm["Date"]); if (model.OwnerDriver == 1) { model.Idndex = int.Parse(frm["Idndex2"]); } if (model.Id == 0) { // Edit db.split_expenses.AddObject(model); } else { // Add new db.AttachTo("split_expenses", model); db.ObjectStateManager.ChangeObjectState(model, System.Data.EntityState.Modified); } db.SaveChanges(); return(RedirectToAction("Index")); } catch { SelectOption(model); return(View(model)); } }
public ActionResult NewOrEdit(int?id = 0) { var obj = DB.Entities.split_expenses.FirstOrDefault(m => m.Id == id); if (obj == null) { obj = new split_expenses() { Current_Payroll = true, Fee_Charged = true, OwnerDriver = 1 }; } SelectOption(obj); return(View(obj)); }
void SelectOption(split_expenses obj) { #region SELECT OPTION string dataSplit_Expenses = "<option value=''>--Select Split_Expenses--</option>"; foreach (var item in NationalIT.DB.Entities.split_expenses) { dataSplit_Expenses += string.Format("<option value='{0}'>{0}</option>", item.Id); } ViewBag.dataSplit_Expenses = dataSplit_Expenses; #endregion #region SELECT Driver info string dataDriver_Info = "<option value=''>--Select Driver_Info--</option>"; foreach (var item in NationalIT.DB.Entities.Driver_Info) { if (obj != null && obj.OwnerDriver == 2 && obj.Idndex == item.ID) { dataDriver_Info += string.Format("<option value='{0}' selected='selected'>{1} {2}</option>", item.ID, item.Last_name, item.First_name); } else { dataDriver_Info += string.Format("<option value='{0}'>{1} {2}</option>", item.ID, item.Last_name, item.First_name); } } ViewBag.dataDriver = dataDriver_Info; string dataOwner_Info = "<option value=''>--Select Owner_Info--</option>"; foreach (var item in NationalIT.DB.Entities.Owners) { if (obj != null && obj.OwnerDriver == 1 && obj.Idndex == item.OwnerID) { dataOwner_Info += string.Format("<option value='{0}' selected='selected'>{1}</option>", item.OwnerID, item.Name); } else { dataOwner_Info += string.Format("<option value='{0}'>{1}</option>", item.OwnerID, item.Name); } } ViewBag.dataOwner = dataOwner_Info; #endregion }
public ActionResult RollBack(string driverID, int id, string Trips, string Fuel, string operating, string splitdriver, string escrowLoan, string splitowner, bool isRollBackAll = false) { var db = DB.Entities; if (isRollBackAll) { RollBackAll(id); return(RedirectToAction("PayrollsRollBack", new { driverID = driverID })); } #region Trips if (!string.IsNullOrEmpty(Trips)) { string[] lstID = Trips.Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries); List <int> lst = new List <int>(); foreach (var item in lstID) { lst.Add(int.Parse(item)); } var lstTrip = db.Temp_Trip_Info.Where(m => lst.Contains(m.TripID)); foreach (var item in lstTrip) { bool add = false; Trip_Info ttrip = db.Trip_Info.FirstOrDefault(m => m.Trip_ID == item.TripID); if (ttrip == null) { ttrip = new Trip_Info(); add = true; } ttrip.Address = item.Address; ttrip.Comfirmed_Rate = item.Comfirmed_Rate; ttrip.Comment = item.Comment; ttrip.Current_Payroll = item.Current_Payroll; ttrip.Customer = item.Customer; ttrip.Customer_Invoiced = item.Customer_Invoiced; ttrip.Customer_Invoiced_date = item.Customer_Invoiced_date; ttrip.Dead_head_miles = item.Dead_head_miles; ttrip.Deliverd = item.Deliverd; ttrip.Delivery_date = item.Delivery_date; ttrip.Delivery_location = item.Delivery_location; ttrip.Detention = item.Detention; ttrip.Detention_pay = item.Detention_pay; ttrip.Dispatcher = item.Dispatcher; ttrip.Driver = item.Driver; ttrip.Driver_paid = item.Driver_paid; ttrip.Equipment_ID = item.Equipment_ID; ttrip.Extra_charges = item.Extra_charges; ttrip.Extra_stops = item.Extra_stops; ttrip.Invoice = item.Invoice; ttrip.Loaded_miles = item.Loaded_miles; ttrip.Order_date = item.Order_date; ttrip.Paid = item.Paid; ttrip.Pick_up_location = item.Pick_up_location; ttrip.Picked = item.Picked; ttrip.Pickup_date = item.Pickup_date; ttrip.PO_ = item.PO_; ttrip.Total_charges = item.Total_charges; if (add) { db.Trip_Info.AddObject(ttrip); } else { db.ObjectStateManager.ChangeObjectState(ttrip, System.Data.EntityState.Modified); } } foreach (var item in lst) { var xxx = db.Temp_Trip_Info.FirstOrDefault(m => m.ID == item); if (xxx != null) { db.DeleteObject(xxx); } } } #endregion #region Fuel Expenses if (!string.IsNullOrEmpty(Fuel)) { string[] lstID = Fuel.Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries); List <int> lst = new List <int>(); foreach (var item in lstID) { lst.Add(int.Parse(item)); } var lstTrip = db.Temp_Fuel_Expenses.Where(m => lst.Contains(m.ID)); foreach (var item in lstTrip) { bool add = false; Fuel___Expenses tfuel = db.Fuel___Expenses.FirstOrDefault(m => m.ID == item.FuelExpensesID); if (tfuel == null) { tfuel = new Fuel___Expenses(); add = true; } tfuel.Amount = item.Amount; tfuel.AmountN = item.AmountN; tfuel.Current_Payroll = item.Current_Payroll; tfuel.Date = item.Date; tfuel.Description = item.Description; tfuel.Driver = item.Driver; tfuel.fee_charged = item.fee_charged; tfuel.Fuel_Card = item.Fuel_Card; tfuel.Location = item.Location; tfuel.Paid_off = item.Paid_off; tfuel.Type = item.Type; if (add) { db.Fuel___Expenses.AddObject(tfuel); } else { db.ObjectStateManager.ChangeObjectState(tfuel, System.Data.EntityState.Modified); } } foreach (var item in lst) { var xxx = db.Temp_Fuel_Expenses.FirstOrDefault(m => m.ID == item); if (xxx != null) { db.DeleteObject(xxx); } } } #endregion #region Operating Expenses if (!string.IsNullOrEmpty(operating)) { string[] lstID = operating.Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries); List <int> lst = new List <int>(); foreach (var item in lstID) { lst.Add(int.Parse(item)); } var lstTrip = db.Temp_Operating_Expenses.Where(m => lst.Contains(m.ID)); foreach (var item in lstTrip) { bool add = false; Operating_Expenses toperating = db.Operating_Expenses.FirstOrDefault(m => m.ID == item.OperatingExpensesID); if (toperating == null) { toperating = new Operating_Expenses(); add = true; } toperating.Amount = item.Amount; toperating.Current_Payroll = item.Current_Payroll; toperating.Date = item.Date; toperating.Description = item.Description; toperating.Driver = item.Driver; toperating.Location = item.Location; toperating.Type = item.Type; if (add) { db.Operating_Expenses.AddObject(toperating); } else { db.ObjectStateManager.ChangeObjectState(toperating, System.Data.EntityState.Modified); } } foreach (var item in lst) { var xxx = db.Temp_Operating_Expenses.FirstOrDefault(m => m.ID == item); if (xxx != null) { db.DeleteObject(xxx); } } } #endregion #region Owner Expenses if (!string.IsNullOrEmpty(splitowner)) { string[] lstID = splitowner.Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries); List <int> lst = new List <int>(); foreach (var item in lstID) { lst.Add(int.Parse(item)); } var lstTrip = db.Temp_Split_Expenses.Where(m => lst.Contains(m.ID)); foreach (var item in lstTrip) { bool add = false; split_expenses tsowner = db.split_expenses.FirstOrDefault(m => m.Id == item.SplitExpensesID); if (tsowner == null) { tsowner = new split_expenses(); add = true; } tsowner.Amount = item.Amount; tsowner.Current_Payroll = item.Current_Payroll; tsowner.Date = item.Date; tsowner.Details = item.Details; tsowner.Expenses = item.Expenses; tsowner.Fee_Charged = item.Fee_Charged; tsowner.Idndex = item.Index; tsowner.OwnerDriver = item.OwnerDriver; tsowner.Paid_Off = item.Paid_Off; if (add) { db.split_expenses.AddObject(tsowner); } else { db.ObjectStateManager.ChangeObjectState(tsowner, System.Data.EntityState.Modified); } } foreach (var item in lst) { var xxx = db.Temp_Split_Expenses.FirstOrDefault(m => m.ID == item); if (xxx != null) { db.DeleteObject(xxx); } } } #endregion #region Driver Expenses if (!string.IsNullOrEmpty(splitdriver)) { string[] lstID = splitdriver.Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries); List <int> lst = new List <int>(); foreach (var item in lstID) { lst.Add(int.Parse(item)); } var lstTrip = db.Temp_Split_Expenses.Where(m => lst.Contains(m.ID)); foreach (var item in lstTrip) { bool add = false; split_expenses tsowner = db.split_expenses.FirstOrDefault(m => m.Id == item.SplitExpensesID); if (tsowner == null) { tsowner = new split_expenses(); add = true; } tsowner.Amount = item.Amount; tsowner.Current_Payroll = item.Current_Payroll; tsowner.Date = item.Date; tsowner.Details = item.Details; tsowner.Expenses = item.Expenses; tsowner.Fee_Charged = item.Fee_Charged; tsowner.Idndex = item.Index; tsowner.OwnerDriver = item.OwnerDriver; tsowner.Paid_Off = item.Paid_Off; if (add) { db.split_expenses.AddObject(tsowner); } else { db.ObjectStateManager.ChangeObjectState(tsowner, System.Data.EntityState.Modified); } } foreach (var item in lst) { var xxx = db.Temp_Split_Expenses.FirstOrDefault(m => m.ID == item); if (xxx != null) { db.DeleteObject(xxx); } } } #endregion #region Escrow Loan if (!string.IsNullOrEmpty(escrowLoan)) { string[] lstID = escrowLoan.Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries); List <int> lst = new List <int>(); foreach (var item in lstID) { lst.Add(int.Parse(item)); } var lstEscrowLoan = db.Temp_EscrowLoan.Where(m => lst.Contains(m.ID)); foreach (var item in lstEscrowLoan) { bool add = false; EscrowLoan tEscrowLoan = db.EscrowLoan.FirstOrDefault(m => m.ID == item.EscrowLoanID); if (tEscrowLoan == null) { tEscrowLoan = new EscrowLoan(); add = true; } tEscrowLoan.AmountPaid = item.AmountPaid; tEscrowLoan.TotalAmount = item.TotalAmount; tEscrowLoan.OwnerDriver = item.OwnerDriver; tEscrowLoan.Owner = item.Owner; tEscrowLoan.Expenses = item.Expenses; tEscrowLoan.Balance = item.Balance; tEscrowLoan.CurrentCharge = 0; tEscrowLoan.OwnerDriver = item.OwnerDriver; tEscrowLoan.Escrow_Loan = item.Escrow_Loan; if (add) { db.EscrowLoan.AddObject(tEscrowLoan); } else { db.ObjectStateManager.ChangeObjectState(tEscrowLoan, System.Data.EntityState.Modified); } } foreach (var item in lst) { var xxx = db.Temp_Split_Expenses.FirstOrDefault(m => m.ID == item); if (xxx != null) { db.DeleteObject(xxx); } } } #endregion db.SaveChanges(); var driver = db.Driver_Info.FirstOrDefault(m => m.ID == int.Parse(driverID)); var tempreport = db.TempReport.FirstOrDefault(m => m.ID == id); if (driver != null && tempreport != null) { new BaseController().SavePayrollLog(id, "Processed payroll rollback a few item", driver.ID, tempreport.TotalAmount, driver.Last_name + " " + driver.First_name, false); } return(RedirectToAction("PayrollsRollBack", new { driverID = driverID })); }
private void RollBackAll(int tempReportID) { var db = DB.Entities; var tempreport = db.TempReport.FirstOrDefault(m => m.ID == tempReportID); #region Trips foreach (var item in tempreport.Temp_Trip_Info) { bool add = false; Trip_Info ttrip = db.Trip_Info.FirstOrDefault(m => m.Trip_ID == item.TripID); if (ttrip == null) { ttrip = new Trip_Info(); add = true; } ttrip.Address = item.Address; ttrip.Comfirmed_Rate = item.Comfirmed_Rate; ttrip.Comment = item.Comment; ttrip.Current_Payroll = item.Current_Payroll; ttrip.Customer = item.Customer; ttrip.Customer_Invoiced = item.Customer_Invoiced; ttrip.Customer_Invoiced_date = item.Customer_Invoiced_date; ttrip.Dead_head_miles = item.Dead_head_miles; ttrip.Deliverd = item.Deliverd; ttrip.Delivery_date = item.Delivery_date; ttrip.Delivery_location = item.Delivery_location; ttrip.Detention = item.Detention; ttrip.Detention_pay = item.Detention_pay; ttrip.Dispatcher = item.Dispatcher; ttrip.Driver = item.Driver; ttrip.Driver_paid = item.Driver_paid; ttrip.Equipment_ID = item.Equipment_ID; ttrip.Extra_charges = item.Extra_charges; ttrip.Extra_stops = item.Extra_stops; ttrip.Invoice = item.Invoice; ttrip.Loaded_miles = item.Loaded_miles; ttrip.Order_date = item.Order_date; ttrip.Paid = item.Paid; ttrip.Pick_up_location = item.Pick_up_location; ttrip.Picked = item.Picked; ttrip.Pickup_date = item.Pickup_date; ttrip.PO_ = item.PO_; ttrip.Total_charges = item.Total_charges; if (add) { db.Trip_Info.AddObject(ttrip); } else { db.ObjectStateManager.ChangeObjectState(ttrip, System.Data.EntityState.Modified); } } #endregion #region Fuel Expenses foreach (var item in tempreport.Temp_Fuel_Expenses) { bool add = false; Fuel___Expenses tfuel = db.Fuel___Expenses.FirstOrDefault(m => m.ID == item.FuelExpensesID); if (tfuel == null) { tfuel = new Fuel___Expenses(); add = true; } tfuel.Amount = item.Amount; tfuel.AmountN = item.AmountN; tfuel.Current_Payroll = item.Current_Payroll; tfuel.Date = item.Date; tfuel.Description = item.Description; tfuel.Driver = item.Driver; tfuel.fee_charged = item.fee_charged; tfuel.Fuel_Card = item.Fuel_Card; tfuel.Location = item.Location; tfuel.Paid_off = item.Paid_off; tfuel.Type = item.Type; if (add) { db.Fuel___Expenses.AddObject(tfuel); } else { db.ObjectStateManager.ChangeObjectState(tfuel, System.Data.EntityState.Modified); } } #endregion #region Operating Expenses foreach (var item in tempreport.Temp_Operating_Expenses) { bool add = false; Operating_Expenses toperating = db.Operating_Expenses.FirstOrDefault(m => m.ID == item.OperatingExpensesID); if (toperating == null) { toperating = new Operating_Expenses(); add = true; } toperating.Amount = item.Amount; toperating.Current_Payroll = item.Current_Payroll; toperating.Date = item.Date; toperating.Description = item.Description; toperating.Driver = item.Driver; toperating.Location = item.Location; toperating.Type = item.Type; toperating.Paid_off = item.Paid_off; if (add) { db.Operating_Expenses.AddObject(toperating); } else { db.ObjectStateManager.ChangeObjectState(toperating, System.Data.EntityState.Modified); } } #endregion #region Owner driver Expenses foreach (var item in tempreport.Temp_Split_Expenses) { bool add = false; split_expenses tsowner = db.split_expenses.FirstOrDefault(m => m.Id == item.SplitExpensesID); if (tsowner == null) { tsowner = new split_expenses(); add = true; } tsowner.Amount = item.Amount; tsowner.Current_Payroll = item.Current_Payroll; tsowner.Date = item.Date; tsowner.Details = item.Details; tsowner.Expenses = item.Expenses; tsowner.Fee_Charged = item.Fee_Charged; tsowner.Idndex = item.Index; tsowner.OwnerDriver = item.OwnerDriver; tsowner.Paid_Off = item.Paid_Off; if (add) { db.split_expenses.AddObject(tsowner); } else { db.ObjectStateManager.ChangeObjectState(tsowner, System.Data.EntityState.Modified); } } #endregion #region EscrowLoan foreach (var item in tempreport.Temp_EscrowLoan) { bool add = false; EscrowLoan tEscrowLoan = db.EscrowLoan.FirstOrDefault(m => m.ID == item.EscrowLoanID); if (tEscrowLoan == null) { tEscrowLoan = new EscrowLoan(); add = true; } tEscrowLoan.AmountPaid = item.AmountPaid; tEscrowLoan.TotalAmount = item.TotalAmount; tEscrowLoan.OwnerDriver = item.OwnerDriver; tEscrowLoan.Owner = item.Owner; tEscrowLoan.Expenses = item.Expenses; tEscrowLoan.Balance = item.Balance; tEscrowLoan.CurrentCharge = 0; tEscrowLoan.OwnerDriver = item.OwnerDriver; tEscrowLoan.Escrow_Loan = item.Escrow_Loan; // db.EscrowLoan.AddObject(tEscrowLoan); if (add) { db.EscrowLoan.AddObject(tEscrowLoan); } else { db.ObjectStateManager.ChangeObjectState(tEscrowLoan, System.Data.EntityState.Modified); } } #endregion db.SaveChanges(); // save payroll log var driver = db.Driver_Info.FirstOrDefault(m => m.ID == tempreport.DriverID); if (driver != null) { new BaseController().SavePayrollLog(tempreport.ID, "Processed payroll rollback all", tempreport.DriverID, tempreport.TotalAmount, driver.Last_name + " " + driver.First_name, true); } DeleteItem(db.TempReport, tempreport.ID); //db.ObjectStateManager.ChangeObjectState(tempreport, System.Data.EntityState.Deleted); }