================================================================================ WAGES SETTINGS - CALCULATION LOGIC Client module and Project module : Cumans Wages & Corporate Wages ================================================================================ Both modules have a "Wages Settings" section with two wage types. A client / project has EITHER Cumans Wages OR Corporate Wages (field: wage_type). When saving, the selected type's blocks are stored and ALL blocks of the other type are deleted (Client.php / Project.php -> saveWageSettings()). A block whose values are all empty or zero ("untouched") is NOT stored. Where the logic lives: - Form (live) calculation ... resources/views/template/client/partials/wages-details.blade.php resources/views/template/project/partials/wages-details.blade.php - Server recalculation ...... app/Support/CorporateWageCalculator.php (Corporate only) - Save / delete logic ....... app/Models/Client.php, app/Models/Project.php - Field definitions ......... app/Models/ClientCumansWage.php, ClientCorporateWage.php, ProjectCumansWage.php, ProjectCorporateWage.php Calculated fields are auto-filled in the form; typing over them shows a warning and the value is reset to the calculated amount when the field is left. ================================================================================ 1. CUMANS WAGES (Client and Project - same formulas) ================================================================================ INPUT (typed by user): Category, Pay Days (required), BP, DA, HRA, Conveyance, Medical Allowance, Incentive, OT, Retaining Allowance, Other Allowance CALCULATED: Gross Salary (earned_gross) = BP + DA + HRA + Conveyance + Medical Allowance + Other Allowance + Incentive + OT + Retaining Allowance EPF Wages = BP + DA + Retaining Allowance, capped at 25,000 (i.e. min(BP + DA + Retaining Allowance, 25000)) EMP EPF (12%) = EPF Wages x 0.12 (employee EPF) EMR EPF (13%) = EPF Wages x 0.13 (employer EPF) ESI applies only while Gross Salary is within the ESI limit: Client : if Gross > 20,999 -> ESI = 0 Project : if Gross > 21,000 -> ESI = 0 (note: 1-rupee difference, see "Known inconsistencies" below) EMP ESI (0.75%) = Gross x 0.0075 (when within limit, else 0) EMR ESI (3.25%) = Gross x 0.0325 (when within limit, else 0) Net Pay = Gross Salary - (EMP EPF + EMP ESI) CTC = Gross Salary + EMR EPF + EMR ESI -------------------------------------------------------------------------------- CLIENT ONLY - Service Charge and GST on Cumans Wages (the Project module removed these fields; old project rows keep their values) -------------------------------------------------------------------------------- Service Cost From (dropdown) decides the base: "Net Pay" -> base = Net Pay "CTC" -> base = CTC "BP + DA" -> base = BP + DA "Others" -> no formula; Service Charge is typed in manually Service Charge = base x Percentage / 100 (Percentage default 0) Sub Total = CTC + Service Charge GST (on Sub Total): If an "SGST + CGST (%)" rate is selected (format "a+b"): CGST = Sub Total x a/100 SGST = Sub Total x b/100 Otherwise CGST and SGST stay empty. If an IGST (%) rate is selected: IGST = Sub Total x rate/100 Else, if NO SGST+CGST rate is selected AND the client's state is set and is not Tamil Nadu: IGST = Sub Total x 0.18 (18% default for out-of-state) Grand Total = Sub Total + CGST + SGST + IGST + Cess Amount SERVER SIDE: Cumans values are stored exactly as submitted - there is NO server recalculation for Cumans Wages (saveCumansWages just filters to known fields). ================================================================================ 2. CORPORATE WAGES (Client and Project - same formulas) ================================================================================ INPUT (typed by user): Category, Department (required), Pay Days (required), and the earnings: Earning BP, Earning DA, Stay Allowance, Attendance Allowance, Shift Allowance, Management Allowance, OT Wages, EL Wages, KX Allowance, Key Station Allowance, Performance Allowance, Statutory Bonus, Arrears Gross, Arrears Allowance "Other Allowance" (client) / "Other Allowance" column other_addition (project) is a TEXT field - stored but NEVER added to Total Earnings. Manual deduction inputs: Professional Tax, Meal, ID Deduction, Apron Deduction, LWF Employee, LWF Employer. CALCULATED: Total Earnings = sum of all earning fields above (excluding the text "Other Allowance" field) Capped Earnings = min(Total Earnings, 25000) (EPF-family contributions use only the first 25,000) EMPLOYEE SIDE: EPF (12%) = Capped Earnings x 0.12 ESI (0.75%) = Total Earnings x 0.0075, but 0 if Total Earnings > 20,999 Total Deductions = EPF + ESI + Professional Tax + Meal + ID Deduction + Apron Deduction + LWF Employee NET PAY = Total Earnings - Total Deductions EMPLOYER SIDE: EPF Account 01 (3.67%) = Capped Earnings x 0.0367 EPS Account 10 (8.33%) = Capped Earnings x 0.0833 EDLI (0.5%) = Capped Earnings x 0.005 ADMIN (0.5%) = Capped Earnings x 0.005 ESI (3.25%) = Total Earnings x 0.0325, 0 if Total Earnings > 20,999 CTC = Total Earnings + EPF 3.67% + EPS 8.33% + EDLI + ADMIN + ESI 3.25% + LWF Employer -------------------------------------------------------------------------------- CLIENT ONLY - Service Charge and GST on Corporate Wages (removed from the Project module; old project rows keep their values) -------------------------------------------------------------------------------- Service Cost From base: "Net Pay" -> Net Pay, "CTC" -> CTC, "Earning BP + Earning DA" -> Earning BP + Earning DA, "Others" -> Service Charge typed in manually Service Charge = base x Percentage / 100 Sub Total = CTC + Service Charge GST Taxable value = Sub Total CGST / SGST = Sub Total x each part of the selected "a+b" rate / 100 IGST = Sub Total x IGST rate / 100 (only when a rate is selected; no automatic 18% fallback here, unlike Cumans) Total Value = Sub Total + CGST + SGST + IGST -------------------------------------------------------------------------------- SERVER RECALCULATION (Corporate only) - app/Support/CorporateWageCalculator.php -------------------------------------------------------------------------------- On save, the server recomputes and OVERWRITES these, ignoring posted values: total_earnings = round(sum of numeric earning fields, 2) eligible = min(max(total_earnings, 0), 25000) EPF 3.67% = round(eligible x 0.0367, 2) EPS 8.33% = round(eligible x 0.0833, 2) EDLI 0.5% = round(eligible x 0.005, 2) ADMIN 0.5% = round(eligible x 0.005, 2) Client additionally stores gst_gross = posted sub_total. All OTHER values (EPF 12%, ESI, Total Deductions, Net Pay, CTC, GST amounts) are stored as posted by the form - they are NOT re-verified on the server. ================================================================================ 3. BULK UPLOAD (both modules) ================================================================================ Sample sheets use the same columns/labels as the form. On upload (ProjectController::readWagesSheet and the client equivalent): - headings are matched case/spacing-insensitively; "%" becomes "pct" so a rate column ("IGST (%)") stays distinct from its amount ("IGST"); - old headings "BA" -> bp and "Earning Basic" -> earning_bp are understood; - columns of removed fields (service cost / GST, in project sheets) are skipped; - required: Pay Days (Cumans), Department + Pay Days (Corporate); - every non-text field must be numeric. Each sheet row fills one form block and the block is then RECALCULATED by the form, so calculated columns in the sheet are effectively ignored. ================================================================================ 4. KNOWN INCONSISTENCIES / NOTES (observed, not changed) ================================================================================ 1. ESI limit differs: Project Cumans uses "gross > 21000 -> 0" while Client Cumans and both Corporate forms use "> 20999 -> 0". A gross of exactly 21,000 gets ESI in the project form but not elsewhere. 2. Cumans Wages have NO server-side recalculation - the stored EPF/ESI/Net Pay/CTC are whatever the browser submitted. 3. For Corporate, only Total Earnings and the 4 employer EPF-family amounts are recalculated server-side; EPF 12%, ESI, Net Pay and CTC are trusted from the form. 4. Client Cumans IGST defaults to 18% for a non-Tamil-Nadu state when no GST rate is chosen; Client Corporate has no such default. 5. The server cap is min(max(total,0),25000) (negative totals clamp to 0); the form uses min(total, 25000) without the negative clamp. ================================================================================