6
Answers

Calculate salary for week based & distributed Month end

   I want to generate payroll for employees those are getting weekly salary.
Salary distributed at end of the month. So month end i have to calculate the salary based on each and every week. one week can assume from Mon to Sun(7 days) .
For ex,July month salary has to calculate
  sal=    01-07-16 to 03-07-16(friday to sun) +
         04-07-16 to 10-07-16(mon to sun) +
       11-07-16 to 17-07-16(Mon to sun) +
      18-07-16 to 24-07-16(mon to sun) +
       25-07-16 to 31-07-16(mon to sun).
   Each and every week their will be OT ,Allowance, Deductions,Paid Leave.
 
      Here How to Split the week (Monday to Sunday) for the given salary date? Then only I can salary and OT for each and every week. I tried a code. It’s good for monthly salary but not correct for weekly salary.. 
I used Employee clocker punches as input. Based on that am calculating the working days. 
 
  1. Private void calculatePayroll(string ID, DateTime FromDate, DateTime ToDate)  
  2.     {  
  3.         float cworkedDay = 0, cPaidLeave = 0, cAbsent = 0;  
  4.         TimeSpan vWorkHr, vweekOT, vsatOT, vsunOT;  
  5.         while (FromDate <= ToDate)  
  6.         {  
  7.             var objAttMas = getAttendance(EmpID, FromDate);  
  8.             var objLeaveMas = getLeave(empID, FromDate)if (objAttMas != null//Present  
  9.             {  
  10.                 if (FromDate.DayOfWeek.ToString() == "Sunday"//Allowance for Sunday work  
  11.                 {  
  12.                     sunOT = sunOT + sunOT  
  13.                 }  
  14.   
  15.                 if (FromDate.DayOfWeek.ToString() == "Saturday"//Saturday 5 hr work  
  16.                 {  
  17.                     if (totalHour < new TimeSpan(5, 0, 0))  
  18.                     {  
  19.                         totalHour = WorkHr + totalHour )  
  20.                         ;  
  21.                     }  
  22.                     else  
  23.                     {  
  24.                         satOT = satOT + totalHour - new TimeSpan(5, 0, 0) )  
  25.                         ;  
  26.                         WorkHr = WorkHr + TimeSpan(5, 0, 0) )  
  27.                         ;  
  28.                     }  
  29.                 }  
  30.                 else //Week day work  
  31.                 {  
  32.                     WorkHr = WorkHr + totalHour  
  33.                 }  
  34.   
  35.                 cworkedDay += float.Parse(noOfDay.ToString());  
  36.             }  
  37.   
  38.             if (objLeaveMas != null//Leave  
  39.             {  
  40.                 var objleaveType = getLeaveType(leaveType)if (objleaveType != null//  
  41.                 {  
  42.                     if (FromDate.DayOfWeek.ToString() == "Saturday")  
  43.                     {  
  44.                         if (objleaveType.incWeekend == 1)  
  45.                         {  
  46.                             cPaidLeave += float.Parse(objLeaveMas.noOfDay.ToString());  
  47.                         }  
  48.                         else  
  49.                         {  
  50.                             cAbsent += float.Parse(objLeaveMas.noOfDay.ToString());  
  51.                         }  
  52.                     }  
  53.                     else  
  54.                     {  
  55.                         if (objleaveType.paidLeave == 1)  
  56.                         {  
  57.                             cPaidLeave += float.Parse(objLeaveMas.noOfDay.ToString());  
  58.                         }  
  59.                         else  
  60.                         {  
  61.                             cAbsent += float.Parse(objLeaveMas.noOfDay.ToString());  
  62.                         }  
  63.                     }  
  64.                 }  
  65.             }  
  66.   
  67.             if (objAttMas != null && objLeaveMas != null//Absent  
  68.             {  
  69.                 if (FromDate.DayOfWeek.ToString() != "Sunday)  
  70.                 {  
  71.                     cAbsent += 1;  
  72.                 }  
  73.             }  
  74.   
  75.             FromDate = FromDate.AddDays(1);  
  76.         } //End of For loop  
  77.     }  
 
Answers (6)