## Calculate payroll (G2N) with auto-generated earnings

### cURL

```
curl --request POST \
  --url https://api.staging.fluxpayroll.ai/api/mexico-payroll/calculate-with-derived-earnings \
  --header 'Content-Type: application/json' \
  --header 'x-api-key: <api-key>' \
  --data '
{
  "employees": [\
    {\
      "employeeId": "emp-001",\
      "employeeStartDate": "2020-01-01",\
      "compensation": {\
        "type": "MONTHLY",\
        "amount": 50000\
      },\
      "timeEntries": [],\
      "previousBimesterEarnigs": [],\
      "workAddress": {\
        "state": "AGU"\
      },\
      "earnings": [],\
      "workerRiskClass": "I"\
    }\
  ],\
  "payrollConfig": {\
    "startDate": "2026-01-01",
    "endDate": "2026-01-31",
    "period": "MONTHLY"
  },\
  "fillDefaultSchedule": true
}
'
```

### Python

```
import requests

url = "https://api.staging.fluxpayroll.ai/api/mexico-payroll/calculate-with-derived-earnings"

payload = {
    "employees": [\
        {\
            "employeeId": "emp-001",\
            "employeeStartDate": "2020-01-01",\
            "compensation": {\
                "type": "MONTHLY",\
                "amount": 50000\
            },\
            "timeEntries": [],\
            "previousBimesterEarnigs": [],\
            "workAddress": { "state": "AGU" },\
            "earnings": [],\
            "workerRiskClass": "I"\
        }\
    ],
    "payrollConfig": {
        "startDate": "2026-01-01",
        "endDate": "2026-01-31",
        "period": "MONTHLY"
    },
    "fillDefaultSchedule": True
}
headers = {
    "x-api-key": "<api-key>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
```

### JavaScript

```
const options = {
  method: 'POST',
  headers: {'x-api-key': '<api-key>', 'Content-Type': 'application/json'},
  body: JSON.stringify({
    employees: [\
      {\
        employeeId: 'emp-001',\
        employeeStartDate: '2020-01-01',\
        compensation: {type: 'MONTHLY', amount: 50000},\
        timeEntries: [],\
        previousBimesterEarnigs: [],\
        workAddress: {state: 'AGU'},\
        earnings: [],\
        workerRiskClass: 'I'\
      }\
    ],
    payrollConfig: {startDate: '2026-01-01', endDate: '2026-01-31', period: 'MONTHLY'},
    fillDefaultSchedule: true
  })
};

fetch('https://api.staging.fluxpayroll.ai/api/mexico-payroll/calculate-with-derived-earnings', options)
  .then(res => res.json())
  .then(res => console.log(res))
  .catch(err => console.error(err));
```

### Response Example

```json
{
  "results": [\
    {\
      "employeeId": "emp-001",\
      "grossPay": "50000.00",\
      "employeeTaxes": {\
        "MX_IMSS_DISEASE_MATERNITY_PENSIONERS_EE": {\
          "wageBase": "51241.80",\
          "taxAmount": "192.16",\
          "taxType": "CONTRIBUTIONS"\
        },\
        "MX_IMSS_DISEASE_MATERNITY_KIND_EE": {\
          "wageBase": "51241.80",\
          "taxAmount": "164.92",\
          "taxType": "CONTRIBUTIONS"\
        },\
        "MX_IMSS_DISEASE_MATERNITY_MONEY_EE": {\
          "wageBase": "51241.80",\
          "taxAmount": "128.10",\
          "taxType": "CONTRIBUTIONS"\
        },\
        "MX_SAT_ISR": {\
          "wageBase": "50000.00",\
          "taxAmount": "9107.82",\
          "taxType": "TAX",\
          "wageBaseContributions": {\
            "SALARY": {\
              "earningKey": "SALARY",\
              "grossAmount": "50000.00",\
              "exemptionAmount": "0.00",\
              "taxableAmount": "50000.00"\
            },\
            "SOCIAL_WELFARE_BENEFITS": {\
              "earningKey": "SOCIAL_WELFARE_BENEFITS",\
              "grossAmount": "0.00",\
              "exemptionAmount": "0.00",\
              "taxableAmount": "0.00"\
            }\
          }\
        },\
        "MX_IMSS_DISABILITY_LIFE_EE": {\
          "wageBase": "51241.80",\
          "taxAmount": "320.26",\
          "taxType": "CONTRIBUTIONS"\
        },\
        "MX_IMSS_RETIREMENT_ADVANCED_AGE_EE": {\
          "wageBase": "51241.80",\
          "taxAmount": "576.47",\
          "taxType": "CONTRIBUTIONS"\
        }\
      },\
      "employerTaxes": {\
        "MX_IMSS_DISEASE_MATERNITY_KIND_ER": {\
          "wageBase": "51241.80",\
          "taxAmount": "1134.40",\
          "taxType": "CONTRIBUTIONS"\
        },\
        "MX_IMSS_WORK_RISK": {\
          "wageBase": "51241.80",\
          "taxAmount": "278.52",\
          "taxType": "CONTRIBUTIONS"\
        },\
        "MX_IMSS_RETIREMENT_OLD_AGE_ER": {\
          "wageBase": "51241.80",\
          "taxAmount": "1024.84",\
          "taxType": "CONTRIBUTIONS"\
        },\
        "MX_IMSS_RETIREMENT_ADVANCED_AGE_ER": {\
          "wageBase": "51241.80",\
          "taxAmount": "3290.75",\
          "taxType": "CONTRIBUTIONS"\
        },\
        "MX_IMSS_DISEASE_MATERNITY_PENSIONERS_ER": {\
          "wageBase": "51241.80",\
          "taxAmount": "538.04",\
          "taxType": "CONTRIBUTIONS"\
        },\
        "MX_IMSS_DISEASE_MATERNITY_MONEY_ER": {\
          "wageBase": "51241.80",\
          "taxAmount": "358.69",\
          "taxType": "CONTRIBUTIONS"\
        },\
        "MX_IMSS_DISABILITY_LIFE_ER": {\
          "wageBase": "51241.80",\
          "taxAmount": "896.73",\
          "taxType": "CONTRIBUTIONS"\
        },\
        "MX_INFONAVIT_HOUSING": {\
          "wageBase": "51241.80",\
          "taxAmount": "2562.09",\
          "taxType": "CONTRIBUTIONS"\
        },\
        "MX_IMSS_NURSERY_SOCIAL_BENEFITS": {\
          "wageBase": "51241.80",\
          "taxAmount": "512.42",\
          "taxType": "CONTRIBUTIONS"\
        },\
        "MX_AGU_PAYROLL": {\
          "wageBase": "50000.00",\
          "taxAmount": "1250.00",\
          "taxType": "TAX",\
          "wageBaseContributions": {\
            "SALARY": {\
              "earningKey": "SALARY",\
              "grossAmount": "50000.00",\
              "exemptionAmount": "0.00",\
              "taxableAmount": "50000.00"\
            },\
            "TERMINATION_COMPENSATION": {\
              "earningKey": "TERMINATION_COMPENSATION",\
              "grossAmount": "0.00",\
              "exemptionAmount": "0.00",\
              "taxableAmount": "0.00"\
            }\
          }\
        }\
      },\
      "totalEmployerTaxes": "11846.48",\
      "totalEmployeeTaxes": "10489.73",\
      "netPay": "39510.27",\
      "dailySbc": "1737.01",\
      "totalEmployeeTax": "9107.82",\
      "totalEmployeeContributions": "1381.91",\
      "totalEmployerTax": "1250.00",\
      "totalEmployerContributions": "10596.48"\
    }\
  ]
}
```

### Error Response Example

```json
{
  "error": "VALIDATION_ERROR",
  "message": "Invalid input data provided",
  "details": [\
    {\
      "field": "<string>",\
      "message": "<string>"
    }\
  ]
}
```
