This employee payroll works in general. There are 2 records in the member table. Likewise, there are two records in the 2nd table, tax and insurance table.
There is a tax base here. The two tables are directly related to each other. When listing the index view, it lists according to the last record, but the table values of the 1st record appear correct, but the calculations are correct. It is the same as the second record.
When I check the index action one by one with break point, records 1 and 2 are calculated correctly, but when I run index.cshtml, I do not see the calculations of the 1st record correctly. It is the same as the 2nd record. Also, there is a problem with the general totals.
In the index control, I enter db savechange into the tax and insurance table where the tax base is located. However, I tried very hard to do this, I couldn't find what I did wrong in the index check.
My dear teacher, I wonder what kind of stitching should be done in this control?
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
{
decimal grosssalary;
decimal totalspecialduties;
Decimal totallegalduties;
decimal extraworkinghours;
decimal extraworkingdays;
decimal taxbase;
decimal bigestgrosssalary;
decimal bigestspecialduties;
decimal bigesttotallegalduties;
decimal bigestextraworkinghours;
decimal bigestextraworkingdays;
decimal bigestnetsalary;
decimal netsalary;
bgl db = new bgl();
// GET: payrol
public ActionResult Index()
{
List<member> meml = new List<member>();
foreach (var mem1 in db.member)
{
//if (model1.day.HasValue && model1.wage.HasValue)
//{
// // Daha sonra diğer işlemleri yapabilirsiniz...
//}
//else
//{
// //decimal grosssalary = -1;
// // Değerler null olduğunda yapılacak bir işlem belirtin
// // Örneğin, varsayılan bir değer atayın veya hata mesajı gösterin
//}
grosssalary = mem1.day.Value * mem1.wage.Value;
@ViewBag.GROSSSALARY = grosssalary;
totalspecialduties = mem1.specialdetuction1.Value + mem1.specialdetuction2.Value;
@ViewBag.totalspecialduties = totalspecialduties;
totallegalduties = mem1.legaldeduction1.Value + mem1.legaldeduction2.Value + mem1.legaldeduction3.Value + mem1.legaldeduction4.Value;
@ViewBag.totallegalduties = totallegalduties;
extraworkinghours = ((mem1.wage.Value / mem1.extraworkinghours.Value));
@ViewBag.extraworkinghours = extraworkinghours;
extraworkingdays = mem1.wage.Value * mem1.extraworkingdays.Value;
@ViewBag.extraworkingdays = extraworkingdays;
taxbase = (grosssalary * mem1.taxandinsurancetable.basetax) + mem1.taxandinsurancetable.basetax;
@ViewBag.taxbase = taxbase;
db.Entry(mem1.taxandinsurancetable).State = System.Data.Entity.EntityState.Modified;
//db.SaveChanges(mem1.taxandinsurancetable);
netsalary = (((grosssalary) - totallegalduties) - (mem1.taxandinsurancetable.basetax));
ViewBag.NETSALARY = netsalary;
bigestgrosssalary += grosssalary;
bigestspecialduties += totalspecialduties;
bigesttotallegalduties += totallegalduties;
bigestextraworkinghours += extraworkinghours;
bigestextraworkingdays += extraworkingdays;
bigestnetsalary += netsalary;
grosssalary = 0;
totalspecialduties = 0;
totallegalduties = 0;
extraworkinghours = 0;
extraworkingdays = 0;
taxbase = 0;
//// GENERAL COUNT SIDE
@ViewBag.bigestgrosssalary = bigestgrosssalary;
@ViewBag.bigestspecialduties = bigestspecialduties;
@ViewBag.bigesttotallegalduties = bigesttotallegalduties;
@ViewBag.bigestextraworkinghours = bigestextraworkinghours;
@ViewBag.bigestextraworkingdays = bigestextraworkingdays;
@ViewBag.bigestnetsalary = bigestnetsalary;
}
return View(db.member.ToList());
//return View();
}
}
}
/// 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; }
}
}
/// taxandinsurancetable 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 taxandinsurancetable
{
public short id { get; set; }
public decimal basetax { get; set; } = 0;
public Nullable<short> memberid { get; set; }
public virtual member member { get; set; }
}
}
// VİEW SİDE
-----------------------------------------------
@using payrol.Models.tablolar @model IEnumerable<member>
@{
ViewBag.Title = "Index";
Layout = "~/Views/shared/Anamasterform.cshtml";
Layout = null;
}
<table class="table table-bordered">
<tr>
<th>ID </th>
<th>NAMESURNAME</th>
<th>WAGE </th>
<th> PICTURE</th>
<th>GROSS SALARY</th>
<th>TOTALSPECİALDUTIES</th>
<th>TOTALLEGALDUTIES</th>
<th>EXTRAWORKINGHOURS</th>
<th>EXTRAWORKINGDAYS</th>
<th>NETSALAY</th>
<th> taxbase </th>
</tr>
<tbody>
@foreach (var c in Model)
{
<tr>
<td>@c.id </td>
<td>@c.nsname </td>
<td>@c.wage </td>
<td> constractıon picture </td>
<td> @ViewBag.GROSSSALARY </td>
<td>@ViewBag.totalspecialduties</td>
<td>@ViewBag.totallegalduties</td>
<td>@ViewBag.extraworkinghours</td>
<td>@ViewBag.extraworkingdays</td>
<td> @ViewBag.NETSALARY</td>
<td> @ViewBag.taxbase</td>
</tr>
}
@*GENARAL REPORT SIDE for taking into account in accounting total total money to be paid from cash*@
</tbody>
<tfoot>
<tr>
<td></td>
<td> </td>
<td> </td>
<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>
</tfoot>
</table>