My Requirements: (Doing this for learning purpose)
An integration between an employee management web app and Acumatica ERP, just need to push the salary payment data to the ERP.
My Current Approach:
I have created a DAC called EmloymentHeroRawData which stores the raw data received from the employee management web app. I have created the web service endpoint and it works as expected. Now I need to create journal transaction entry, it should include the all transaction entries in the EmloymentHeroRawData DAC, excluding the already process rows. That part also works in my code.
after entering a row to a journal transaction entry I need to change the its status in to “COM”. But that part is not working.
When doing debugging I create a separate action called ToggleStatus just to change the status of all recode. But it also not works it gives following error.
Error: An attempt of an update of the whole table EmloymentHeroRawData was detected because of missed key values.
Code :
namespace Fruitspotv1
{
public class EmploymentHeroRawDataGraph : PXGraph<EmploymentHeroRawDataGraph, EmloymentHeroRawData>
{
public PXSave<EmloymentHeroRawData> Save;
public PXCancel<EmloymentHeroRawData> Cancel;
public SelectFrom<EmloymentHeroRawData>.View EmloymentHeroRawDataView;
#region Actions
public PXAction<EmloymentHeroRawData> CreateGLAction;
GPXProcessButton]
rPXUIField(DisplayName = "Create GL", Enabled = true)]
protected virtual IEnumerable createGLAction(PXAdapter adapter)
{
// Populate a local list variable.
bool isMassProcess = adapter.MassProcess;
List<EmloymentHeroRawData> list = new List<EmloymentHeroRawData>();
foreach (EmloymentHeroRawData order in adapter.Get<EmloymentHeroRawData>())
{
list.Add(order);
}
Save.Press();
PXLongOperation.StartOperation(this, delegate ()
{
ValidatePrices(list, isMassProcess);
});
return list;
}
#endregion
#region Actions
public PXAction<EmloymentHeroRawData> toggleStatus;
PXProcessButton]
tPXUIField(DisplayName = "Toggle Status", Enabled = true)]
protected virtual IEnumerable ToggleStatus(PXAdapter adapter)
{
var emHero = CreateInstance<EmploymentHeroRawDataGraph>();
var tranacationList = emHero.EmloymentHeroRawDataView.Select();
foreach (EmloymentHeroRawData entitiy in tranacationList)
{
try
{
entitiy.Status = "COM";
}
catch (Exception ex)
{
entitiy.Status = "FIL";
}
emHero.EmloymentHeroRawDataView.Cache.Update(entitiy);
}
emHero.Actions.PressSave();
// Save.Press();
return tranacationList;
}
#endregion
private static void ValidatePrices(List<EmloymentHeroRawData> emloymentHeroEntitiyList, bool isMassProcess = false)
{
try
{
using (var ts = new PXTransactionScope())
{
var journalEntry = CreateInstance<JournalEntry>();
var doc = new Batch()
{
Module = "GL"
};
doc = journalEntry.BatchModule.Insert(doc);
Branch branch = PXSelect<Branch, Where<Branch.branchCD, Equal<Required<Branch.branchCD>>>>.Select(journalEntry, "HEADOFFICE");
EmploymentHeroRawDataGraph employmentHeroRawDataGraph = CreateInstance<EmploymentHeroRawDataGraph>();
//doc.LedgerCD = "ACTUAL";
doc.BranchID = branch.BranchID;
doc.Description = emloymentHeroEntitiyList.Count.ToString() + " Generated from EM";
journalEntry.BatchModule.Update(doc);
foreach (EmloymentHeroRawData entitiy in emloymentHeroEntitiyList)
{
Account account = PXSelect<Account, Where<Account.accountCD, Equal<Required<Account.accountCD>>>>.Select(journalEntry, entitiy.AccountCode);
try
{
var tr = new GLTran
{
AccountID = account.AccountID,
CuryCreditAmt = entitiy.Credit,
CuryDebitAmt = entitiy.Debit,
};
var tran = journalEntry.GLTranModuleBatNbr.Insert(tr);
//var savedData = journalEntry.GLTranModuleBatNbr.Update(tran);
entitiy.Status = "COM";
}
catch(Exception ex)
{
entitiy.Status = "FIL";
}
}
// Trigger the Save action to save changes in the database.
journalEntry.Actions.PressSave();
ts.Complete();
if (isMassProcess)
{
//PXProcessing<EmloymentHeroRawData>.SetInfo(i,string.Format(Messages.WorkOrderAssigned,workOrder.OrderNbr));
}
}
}
catch (Exception ex)
{
}
}
}
}