------------------layout side
@using payrol.Models.tablolar
@model IEnumerable<member>
@{
ViewBag.Title = "Index";
Layout = "~/Views/shared/Anamasterform.cshtml";
}
<table class="table table-bordered">
<tr>
<th>ID </th>
<th>NAMESURNAME</th>
<th>DAY</th>
<th>WAGE </th>
<th> PICTURE</th>
<th>LEGALDEDUCTION1</th>
<th>LEGALDEDUCTION2</th>
<th>LEGALDEDUCTION3</th>
<th>SPECIALDEDUCTION1</th>
<th>SPECIALDEDUCT1</th>
<th>LEGALDEDUCTION2</th>
<th>LEGALDEDUCTION2</th>
<th>GROSSSALARY</th>
<th>NETSALARY</th>
<th>TOTALOFSPECIALDUTIES</th>
<th>TOTALLEGALDUTIES</th>
<th>EXTRAWORKINGHOURS</th>
<th>EXTRAWORKINGDAYS</th>
<th> taxbase </th>
</tr>
<tbody>
@foreach (var c in Model)
{
<tr>
<td>@c.id </td>
<td>@c.nsname</td>
<td>@c.pictureway</td>
<TD> @ViewBag.GROSSSALARY </TD>
<TD> @ViewBag.NETSALARY </TD>
<th> @ViewBag.TOTALOFSPECIALDUTIES</th>
<th>@ViewBag.TOTVALLEGALDUTIES</th>
<th>@ViewBag.EXTRAWORKINGHOURS</th>
<th>@ViewBag.EXTRAWORKINGDAYS</th>
<th> @ViewBag.taxbase </th>
@*GENARAL REPORT SIDE for taking into account in accounting total total money to be paid from cash*@
<TD> @ViewBag.bigestgrosssalary </TD>
<TD> @ViewBag.bigestspecialduties </TD>
<TD> @ViewBag.bigesttotallegalduties </TD>
<TD> @ViewBag.bigestextraworkinghours </TD>
<TD> @ViewBag.bigestextraworkingdays </TD>
<TD> @ViewBag.bigestnetsalary </TD>
</tr>
}
</tbody>
</table>
----------------------------------------
// TABLE NAME: MEMBER TABLE//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated from a template.
//
// Manual changes to this file may cause unexpected behavior in your application.
// Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace payrol.Models.tablolar
{
using System;
using System.Collections.Generic;
public partial class member
{
public short id { get; set; }
public string nsname { get; set; }
public string pictureway { get; set; }
public Nullable<int> day { get; set; } = 0;
public Nullable<decimal> wage { get; set; } = 0;
public Nullable<decimal> specialdetuction1 { get; set; } = 0;
public Nullable<decimal> specialdetuction2 { get; set; } = 0;
public Nullable<decimal> legaldeduction1 { get; set; } = 0;
public Nullable<decimal> legaldeduction2 { get; set; } = 0;
public Nullable<decimal> legaldeduction3 { get; set; } = 0;
public Nullable<decimal> legaldeduction4 { get; set; } = 0;
public Nullable<int> extraworkinghours { get; set; } = 0;
public Nullable<int> extraworkingdays { get; set; } = 0;
public virtual taxandinsurancetable taxandinsurancetable { get; set; }
}
}
--------------------------------
//OTHER tables NAME : taxandinsurancetable
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated from a template.
//
// Manual changes to this file may cause unexpected behavior in your application.
// Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace payrol.Models.tablolar
{
using System;
using System.Collections.Generic;
public partial class taxandinsurancetable
{
public short id { get; set; }
public decimal basetax { get; set; }
public Nullable<short> memberid { get; set; }
public virtual member member { get; set; }
}
}
-------------------------------------
CONTROLER
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using payrol.Models.tablolar;
namespace payrol.Controllers
{
public class payrolController : Controller
{
bgl db = new bgl();
// GET: payrol
public ActionResult Index()
{
foreach (var model1 in db.member)
{
decimal grosssalary = model1.day.Value * model1.wage.Value;
ViewBag.GROSSSALARY = grosssalary;
decimal totalspecialduties = model1.specialdetuction1.Value + model1.specialdetuction2.Value;
ViewBag.totalspecialduties = totalspecialduties;
Decimal totallegalduties = model1.legaldeduction1.Value + model1.legaldeduction2.Value + model1.legaldeduction3.Value + model1.legaldeduction4.Value;
ViewBag.totallegalduties= totallegalduties;
decimal extraworkinghours = ((model1.wage.Value / model1.extraworkinghours.Value));
ViewBag.extraworkinghours= extraworkinghours;
decimal extraworkingdays = model1.wage.Value * model1.extraworkingdays.Value;
ViewBag.extrtaworkingdays= extraworkingdays;
decimal taxbase = (grosssalary * model1.taxandinsurancetable.basetax) + model1.taxandinsurancetable.basetax;
db.Entry(model1.taxandinsurancetable).State = System.Data.Entity.EntityState.Modified;
/// be careful area
//I couldn't run the following line, it will write the much needed tax base by adding it to the 2nd table log variable.
//db.SaveChanges(model1.taxandinsurancetable);
ViewBag.taxbase = taxbase;
decimal netsalary = (((grosssalary) - totallegalduties) - (model1.taxandinsurancetable.basetax));
ViewBag.NETSALARY = netsalary;
decimal bigestgrosssalary = +grosssalary;
decimal bigestspecialduties = +totalspecialduties;
decimal bigesttotallegalduties = +totallegalduties;
decimal bigestextraworkinghours = +extraworkinghours;
decimal bigestextraworkingdays = +extraworkingdays;
decimal bigestnetsalary = netsalary;
@ViewBag.bigestgrosssalary = bigestgrosssalary;
@ViewBag.bigestspecialduties = bigestspecialduties;
@ViewBag.bigesttotallegalduties = bigesttotallegalduties;
@ViewBag.bigestextraworkinghours = bigestextraworkinghours;
@ViewBag.bigestextraworkingdays = bigestextraworkingdays;
@ViewBag.bigestnetsalary = bigestnetsalary;
grosssalary = 0;
totalspecialduties = 0;
totallegalduties = 0;
extraworkinghours = 0;
extraworkingdays = 0;
netsalary = 0;
}
return View();
}
}
}
The output you asked about is the for each structure that comes from the control side in the layout section. In short, there is already a single index action here, and this is related to this, when returning the view, it says that the object reference is not set to the object instance and the program stops, whereas there is 1 single row record in the member table, all the variables could have been in these 500 people. I wanted it to calculate for 1 person. The database is full, all the variables are full, there is no null, I planned the code as follows. In the index action, it should calculate how many member rows are in the rows executed, start from the beginning to the end and show it in the index view. Increase the basetax with the formula and add the new tax base on it. In short, when the payroll is made every month, the tax base increases. For this, I kept the tax base in the basetax field in the 2nd table. In short, no matter how many people there are, the index action will calculate that many people. I tried to establish a structure for each there, teacher.
Also, in the member.cs file of the member table, I set 0 after get set to fix this error, but it didn't work, but I couldn't find the error with the code. There is no proper payroll on YouTube. In short, the reporting will only be in the view. Salary formulas are not very important. Calculate and index with viewbag. I wanted it to appear in cshtml, but I couldn't. Teacher, you need to stitch the index action of the code. This code is very important. It is a simple salary code. If it worked, it would make hundreds of people pay. I am sending the code again.
Also in the index action //db.SaveChanges(model1.taxandinsurancetable); The line is not working, I closed it, it was going to write the vetgi base to the 2nd file, but I am sending the code, teacher, I need your help, I will take notes, in short, the report will appear in index.cshml, the same number of payroll account lines will be created as there are people.