McDonald's has agreed to pay what could be tens of millions of dollars to New Zealand employees after becoming embroiled in a nationwide payroll debacle.

The fast food giant will pay back all past and present employees in the past 10 years for miscalculated holiday wages, according to McDonald's spokesperson Simon Kenny.

This agreement follows a years-long campaign by local labor union Unite Union, which Kenny said represents about 7% of McDonald's New Zealand employees. He estimated that about 40,000 employees were affected.

The union gave a much higher estimate, saying in a statement Monday that "It is possible that every person who worked for McDonald's after November 2009 is owed some money." It added that it believes "as many as 60,000 staff and millions of dollars will be involved."

The union's national director, Mike Treen, estimated that the remediation may cost McDonald's at least 45 million New Zealand dollars (almost $29 million), according to CNN affiliate Radio New Zealand — and that's just a starting "baseline figure."

Both Kenny and the union pointed out that this isn't an isolated incident — rather, it's part of a much larger problem that has seen employees underpaid in the public and private sectors across New Zealand.

Unite Union said it first raised the issue with McDonald's in 2015, accusing the company of "stealing" annual leave from employees by not properly paying them for working public holidays and failing to provide compensation rest days.

Since then, the company has been working with both McDonald's and the Ministry of Business Innovation and Enterprise (MBIE), the New Zealand government agency that enforces economic policies, to reach an agreement.

"We have spent tens of thousands of hours working on what is a hugely complex project, in order to ensure the approach to making calculations is correct," Kenny said in a statement to CNN Business. "With the agreement in place we can now start the process of doing individual calculations."

Payroll problems nationwide

McDonald's is just one of many companies that have been swept up in the nationwide payroll problem -— more than 150 companies are currently being audited, according to MBIE. In 2016, the government estimated that up to 763,000 employees nationwide could be owed wages, and the total cost of remediation could reach 2.2 billion New Zealand dollars (about $1.4 billion), Radio New Zealand reported.

It's not just companies. Even government agencies like MBIE and the District Health Boards have made similar errors in calculating holiday pay. The health boards announced just last month that they owe health workers up to 650 million New Zealand dollars (about $415.7 million), Radio New Zealand reported.

The payroll crisis all stems from a complicated law, the Holidays Act, which was enacted in 2003.

The law is relatively straightforward for employees who work standard five-day, 40-hour weeks. But it's much more difficult to apply for certain industries with irregular hours, like hospitality, retail or health, according to a 2018 report commissioned by the government.

The law is also so complex that employers often have trouble interpreting it correctly, according to the report. For instance, there are many different ways to calculate daily pay, weekly pay, holiday pay, and pay for alternative holidays — so it's hard to know when to use which calculations.

The rules have only become more confusing as work culture has changed over the years, with more employees working flexible hours or commission payments. Some companies, having discovered their errors, need to overhaul the entire payroll system to abide by the law, according to Radio New Zealand.

After many companies complained that the law was too complex, outdated and costly, the government assembled a task force to review the law, identify issues and make recommendations. The investigation is ongoing.

The Minister of Workplace Relations, Iain Lees-Galloway, said last year that the task force would help simplify the existing law, Radio New Zealand reported.

"There's been enormous change in our labor market over the past 15 years and it's clear we need to look at the Holidays Act with a fresh pair of eyes and ensure it is fit for modern workplaces and new working arrangements," he said.