2 回答
TA贡献1828条经验 获得超4个赞
看起来您的 TimesheetLines 是一个包含名为 TimesheetLine 的属性的对象,它是一个集合 - 但根据文档, TimesheetLines 本身应该是时间表行的集合。
即你应该有类似的东西:
[{ EmployeeID : 4fd71c0f-8612-4fd8-99d0-b3a2e8272b02 , StartDate : 2020-08-03 , EndDate : 2020-08-09 , Status : Draft , TimesheetLines :[{ EarningsRateID : 0e30f933-04ed-4b96-9357-9747209c306f , NumberOfUnits :{ NumberOfUnit :[ 0.00 , 0.00 , 8 , 0.00 , 0.00 , 0.00 , 0.00 ]}},{ EarningsRateID : 0e30f933-04ed-4b96-9357-9747209c306f , NumberOfUnits :{ NumberOfUnit :[ 0.00 , 0.00 , 0.00 , 8.5 , 0.00 , 0.00 , 0.00 ]}},{ EarningsRateID : 0e30f933-04ed-4b96-9357-9747209c306f , NumberOfUnits :{ NumberOfUnit :[ 0.00 , 0.00 , 0.00 , 0.00 , 8 , 0.00 , 0.00 ]}},{ EarningsRateID : 0e30f933-04ed-4b96-9357-9747209c306f , NumberOfUnits :{ NumberOfUnit :[ 0.00 , 0.00 , 0.00 , 0.00 , 0.00 , 8 , 0.00 ]}},{ EarningsRateID : 0e30f933-04ed-4b96-9357-9747209c306f , NumberOfUnits :{ NumberOfUnit :[ 0.00 , 0.00 , 0.00 , 0.00 , 0.00 , 0.00 , 8.5 ]}}]}]
...代替...
[{ EmployeeID : 4fd71c0f-8612-4fd8-99d0-b3a2e8272b02 , StartDate : 2020-08-03 , EndDate : 2020-08-09 , Status : Draft , TimesheetLines :{ TimesheetLine :[{ EarningsRateID : 0e30f933-04ed-4b96-9357-9747209c306f , NumberOfUnits :{ NumberOfUnit :[ 0.00 , 0.00 , 8 , 0.00 , 0.00 , 0.00 , 0.00 ]}},{ EarningsRateID : 0e30f933-04ed-4b96-9357-9747209c306f , NumberOfUnits :{ NumberOfUnit :[ 0.00 , 0.00 , 0.00 , 8.5 , 0.00 , 0.00 , 0.00 ]}},{ EarningsRateID : 0e30f933-04ed-4b96-9357-9747209c306f , NumberOfUnits :{ NumberOfUnit :[ 0.00 , 0.00 , 0.00 , 0.00 , 8 , 0.00 , 0.00 ]}},{ EarningsRateID : 0e30f933-04ed-4b96-9357-9747209c306f , NumberOfUnits :{ NumberOfUnit :[ 0.00 , 0.00 , 0.00 , 0.00 , 0.00 , 8 , 0.00 ]}},{ EarningsRateID : 0e30f933-04ed-4b96-9357-9747209c306f , NumberOfUnits :{ NumberOfUnit :[ 0.00 , 0.00 , 0.00 , 0.00 , 0.00 , 0.00 , 8.5 ]}}]}}]
改变这个有帮助吗?
TA贡献1891条经验 获得超3个赞
对于遇到此问题的任何人来说,问题在于,与我在私人应用程序中使用的旧包装器不同,我在私人应用程序中构建了完整的 XML 时间表并发送它,Xero 的 oauth2 包装器并不需要完整的时间表。相反,您创建时间表的实例并为其设置属性。
代码积分从存储库转到@wobinb
$config = XeroAPI\XeroPHP\Configuration::getDefaultConfiguration()-
>setAccessToken( (string)$storage->getAccessToken() );
$payrollApi = new XeroAPI\XeroPHP\Api\PayrollAuApi(
new GuzzleHttp\Client(),
$config
);
//first retrieve a list of active employees
$apiResponse = $payrollApi->getEmployees($tenantId, null, "Status==\"ACTIVE\"");
$employees = $apiResponse->getEmployees();
foreach ($employees AS $employee) {
print $employee->getFirstName()." ".$employee->getLastName()." - ".$employee->getPayrollCalendarID();
if ($employee->getPayrollCalendarID() != null) {
$employeeID = $employee->getEmployeeID();
$payrollCalendarID = $employee->getPayrollCalendarID();
$ordinaryEarningsRateID = $employee->getOrdinaryEarningsRateID();
}
print "<br />";
}
print "<br />";
//and now the payroll calendar
$apiResponse = $payrollApi->getPayrollCalendar($tenantId,$payrollCalendarID);
$calendar = $apiResponse->getPayrollCalendars()[0];
print $calendar->getName()." - ".$calendar->getCalendarType();
print "<br />";
//finally create the timesheet
$timesheet = new XeroAPI\XeroPHP\Models\PayrollAu\Timesheet();
$timesheet->setEmployeeID($employeeID);
$timesheet->setStartDateAsDate($calendar->getStartDateAsDate());
//need to calculate how many days the timesheet will cover
switch ($calendar->getCalendarType()) {
case "WEEKLY":
$lengthofCalendar = 7;
break;
case "FORTNIGHTLY":
$lengthofCalendar = 14;
break;
case "FOURWEEKLY":
$lengthofCalendar = 28;
break;
//monthly pay runs will be more complicated to calculate
}
$endDate = $calendar->getStartDateAsDate();
//end date will be start date plus the length and minus one day
$period = "P". ($lengthofCalendar - 1) . "D";
$endDate->add(new DateInterval($period));
$timesheet->setEndDateAsDate($endDate);
$timesheet->setStatus("DRAFT");
$timesheetLine = new XeroAPI\XeroPHP\Models\PayrollAu\TimesheetLine();
$timesheetLine->setEarningsRateId($ordinaryEarningsRateID);
for ($day = 1; $day <= $lengthofCalendar; $day++) {
$numberOfUnits[] = $day;
}
$timesheetLine->setNumberOfUnits($numberOfUnits);
$timesheetLines[] = $timesheetLine;
$timesheet->setTimeSheetLines($timesheetLines);
$timesheets[] = $timesheet;
$apiResponse = $payrollApi->createTimesheet($tenantId,$timesheets);
- 2 回答
- 0 关注
- 97 浏览
添加回答
举报