Earning Statement Document Service

Share on linkedin
LinkedIn
Share on twitter
Twitter
Share on facebook
Facebook

The best way to create MIcrosoft Dynamics AX entities from code is to use standard Dynamics AX document services. It is a safest way to make sure that all business logic is performed, and everything is created correctly. This article describes how to create earning statement using standard Dynamics AX document service.

This example will create earning statement for worker with personnel number 000001, for Pay cycle BW (BiWeekly) and pay period September 13th – September 26th. Earning date must be a date in pay period, in this case September 15th.

Position must be assigned to worker for which the statement is created. Earning code can be one of the earning codes assigned to a worker and positon (Each worker can have several earning codes for the position.

Earning quantity is number of hours.

[crayon lang=”csharp”]
static void insertPayrollEarningStatements()
{

PayrollEarningsImportService service;
PayrollEarningsImport_EarningStatement earningStatement;
PayrollEarningsImport_EarningStmtLine earningStatementLineOne;
PayrollEarningsImport_EarningStmtLine earningStatementLine;
PayrollPayPeriodKey period = new PayrollPayPeriodKey();

PeriodStart periodStart = mkDate(13, 9, 2015);
PeriodEnd periodEnd = mkDate(26, 9, 2015);
PayrollEarningCodeId earningCode = ’01’;
DataAreaId dataAreaId = ’01’;
PersonnelNumber personnelNumber = ‘000001’;
PayrollPayCycleId payCycleId = ‘BW’;
TransDate earningDate = mkDate(15, 9, 2015);
HcmPositionId positionId = ‘POS0001’;
PayrollEarningQuantity earningQuantity = 1;
PayrollEarningStatement earningStatementTable;
PayrollEarningsImport statement;
;

info(“Import of Earning statements started”);
service = PayrollEarningsImportService::construct();

statement = new PayrollEarningsImport();

earningStatement = statement.createEarningStatement().addNew();
earningStatement.parmWorker(personnelNumber);
period.parmPayCycle_PayCycleId(payCycleId);
period.parmPeriodEndDate(periodEnd);
earningStatement.parmPayPeriod(period);

earningStatementLine = earningStatement.createEarningStmtLine().addNew();
earningStatementLine.parmEarningCode(earningCode);
earningStatementLine.parmEarningDate(earningDate);
earningStatementLine.parmPosition(positionId);
earningStatementLine.parmQuantity(earningQuantity);

service.create(statement);

info(“Import of Earning statements finished”);

}
[/crayon]

You Might Also Like:

Leave a Reply