Entry Form: Submitter and Approver has specified roles for taking action
Parameter Form:Form code:
public class FormRun extends ObjectRun
{
boolean roleExist;
boolean warningmsg1, warningmsg2;
AweSalesPriceTMP salesPriceTMP;
}
public void init() // Form level
{
super();
AweSalesPriceTMP_ds.executeQuery();
}
public void initValue() // Form DS level
{
super();
AweSalesPriceTMP.SalesCurrency = 'USD';
AweSalesPriceTMP.ProjSalesPriceModel = ProjSalesPriceModel::PercentMarkup;
AweSalesPriceTMP.Type = ProjType::TimeMaterial;
}
public int active() // Form DS level
{
int ret;
ret = super();
if (AweSalesPriceTMP.Status == AweStagingPriceStatus::Approved || AweSalesPriceTMP.Status == AweStagingPriceStatus::Submitted)
{
AweSalesPriceTMP_ds.allowEdit(false);
}
else
{
AweSalesPriceTMP_ds.allowEdit(true);
}
return ret;
}
public void executeQuery() // Form DS level
{
if (AweSalesPriceStagingTable_Status.valueStr() == enum2str(AweStagingPriceStatus::Approved))
{
this.query().dataSourceTable(tableNum(AweSalesPriceTMP)).clearRanges();
this.query().dataSourceTable(tableNum(AweSalesPriceTMP)).addRange(fieldNum(AweSalesPriceTMP, Status)).value(enum2str(AweStagingPriceStatus::Approved));
super();
}
else if (AweSalesPriceStagingTable_Status.valueStr() == enum2str(AweStagingPriceStatus::NotProcessed))
{
this.query().dataSourceTable(tableNum(AweSalesPriceTMP)).clearRanges();
this.query().dataSourceTable(tableNum(AweSalesPriceTMP)).addRange(fieldNum(AweSalesPriceTMP, Status)).value(enum2str(AweStagingPriceStatus::NotProcessed));
super();
}
else if (AweSalesPriceStagingTable_Status.valueStr() == enum2str(AweStagingPriceStatus::Submitted))
{
this.query().dataSourceTable(tableNum(AweSalesPriceTMP)).clearRanges();
this.query().dataSourceTable(tableNum(AweSalesPriceTMP)).addRange(fieldNum(AweSalesPriceTMP, Status)).value(enum2str(AweStagingPriceStatus::Submitted));
super();
}
else if (AweSalesPriceStagingTable_Status.valueStr() == enum2str(AweStagingPriceStatus::ALL))
{
this.query().dataSourceTable(tableNum(AweSalesPriceTMP)).clearRanges();
this.query().dataSourceTable(tableNum(AweSalesPriceTMP)).addRange(fieldNum(AweSalesPriceTMP, Status));
super();
}
}
void clicked() // Approved button
{
//super();
SecurityRole securityRole;
SecurityUserRole securityUserRole;
UserInfo userInfo;
str submitRole, ApproveRole, userRole,recid;
AweSalesPriceTMP aweSalesPriceTMPLoc;
int track = 0;
int64 recIdLoc;
ProjCostSalesPrice salesPriceExpense;
AweProjSalesPriceItem salesPriceItem;
warningmsg1 = false;
warningmsg2 = false;
aweSalesPriceTMPLoc = AweSalesPriceTMP_ds.getFirst(true);
ApproveRole = AweProjSalesPriceParameter::find().AweApproveRole;
while select securityRole
exists join securityUserRole
where securityRole.RecId == securityUserRole.SecurityRole &&
securityUserRole.User == curUserId()
{
userRole = securityRole.Name;
if (userRole == ApproveRole || userRole == 'System administrator')
{
roleExist = false;
while (aweSalesPriceTMPLoc.RecId != 0 && aweSalesPriceTMPLoc.Status == AweStagingPriceStatus::Submitted)
{
recIdLoc = aweSalesPriceTMPLoc.RecId;
ttsBegin;
select forUpdate aweSalesPriceTMPLoc
where aweSalesPriceTMPLoc.RecId == recIdLoc;
aweSalesPriceTMPLoc.Status = AweStagingPriceStatus::Approved;
aweSalesPriceTMPLoc.ApprovedUser = curUserId();
aweSalesPriceTMPLoc.ApprovedDateTime = DateTimeUtil::getSystemDateTime();
aweSalesPriceTMPLoc.update();
select forUpdate salesPriceExpense;
salesPriceExpense.TransDate = aweSalesPriceTMPLoc.EffectiveDate;
salesPriceExpense.CategoryId = aweSalesPriceTMPLoc.CategoryId;
salesPriceExpense.Worker = aweSalesPriceTMPLoc.Worker;
salesPriceExpense.ProjValidFor = aweSalesPriceTMPLoc.ProjValidFor;
salesPriceExpense.ProjId = aweSalesPriceTMPLoc.ProjId;
salesPriceExpense.PSAProjInvoiceProjId = aweSalesPriceTMPLoc.PSAProjInvoiceProjId;
salesPriceExpense.PSACustAccount = aweSalesPriceTMPLoc.PSACustAccount;
salesPriceExpense.ProjPriceGroup = aweSalesPriceTMPLoc.ProjPriceGroup;
salesPriceExpense.CurrencyId = aweSalesPriceTMPLoc.SalesCurrency;
salesPriceExpense.ProjSalesPriceModel = aweSalesPriceTMPLoc.ProjSalesPriceModel;
salesPriceExpense.ProjSalesPricing = aweSalesPriceTMPLoc.Pricing;
salesPriceExpense.insert();
select forUpdate salesPriceItem;
salesPriceItem.CustomerAccount = aweSalesPriceTMPLoc.PSACustAccount;
salesPriceItem.EffectiveDate = aweSalesPriceTMPLoc.EffectiveDate;
salesPriceItem.ProjectContractId = aweSalesPriceTMPLoc.PSAProjInvoiceProjId;
salesPriceItem.Pricing = aweSalesPriceTMPLoc.Pricing;
salesPriceItem.ProjectId = aweSalesPriceTMPLoc.ProjId;
salesPriceItem.SalesCurrency = aweSalesPriceTMPLoc.SalesCurrency;
salesPriceItem.ProjSalesPriceModel = aweSalesPriceTMPLoc.ProjSalesPriceModel;
salesPriceItem.Type = aweSalesPriceTMPLoc.Type;
salesPriceItem.insert();
ttsCommit;
aweSalesPriceTMPLoc = AweSalesPriceTMP_ds.getNext();
track ++;
roleExist = true;
}
if (aweSalesPriceTMPLoc.RecId != 0 && aweSalesPriceTMPLoc.status != AweStagingPriceStatus::Submitted)
{
warningmsg1 = true;
}
if (aweSalesPriceTMPLoc.RecId != 0 && aweSalesPriceTMPLoc.status == AweStagingPriceStatus::Approved)
{
warningmsg2 = true;
}
AweSalesPriceTMP_ds.reread();
AweSalesPriceTMP_ds.executeQuery();
AweSalesPriceTMP_ds.refresh();
}
}
if (roleExist == true)
{
//info(strFmt("Record has been approved successfully: %1",track));
info("Record has been approved successfully");
}
else if (warningmsg1 == true)
{
Global::warning("Status should be 'Submitted' state for approve the record");
}
else if (warningmsg2 == true)
{
Global::warning("Record already been approved state");
}
else
{
Global::error("User - " +curUserId()+ " - don't have privilleges to submit record");
}
}
public boolean modified() // Unbounded Enum(Filter)
{
boolean ret;
ret = super();
AweSalesPriceTMP_ds.executeQuery();
return ret;
}
void clicked() // Delete button
{
//super();
SecurityRole securityRole;
SecurityUserRole securityUserRole;
UserInfo userInfo;
str submitRole, ApproveRole, userRole,recid;
AweSalesPriceTMP aweSalesPriceTMPLoc;
int track = 0;
int64 recIdLoc;
aweSalesPriceTMPLoc = AweSalesPriceTMP_ds.getFirst(true);
submitRole = AweProjSalesPriceParameter::find().AweSubmissionRole;
ApproveRole = AweProjSalesPriceParameter::find().AweApproveRole;
while select securityRole
exists join securityUserRole
where securityRole.RecId == securityUserRole.SecurityRole &&
securityUserRole.User == curUserId()
{
userRole = securityRole.Name;
if (userRole == submitRole || userRole == ApproveRole || userRole == 'System administrator')
{
roleExist = false;
while (aweSalesPriceTMPLoc.RecId != 0 && aweSalesPriceTMPLoc.Status == AweStagingPriceStatus::Submitted)
{
recIdLoc = aweSalesPriceTMPLoc.RecId;
ttsBegin;
select forUpdate aweSalesPriceTMPLoc
where aweSalesPriceTMPLoc.RecId == recIdLoc;
aweSalesPriceTMPLoc.delete();
ttsCommit;
aweSalesPriceTMPLoc = AweSalesPriceTMP_ds.getNext();
track ++;
}
if (aweSalesPriceTMPLoc.RecId != 0 && aweSalesPriceTMPLoc.status == AweStagingPriceStatus::Approved)
{
throw Global::warning("Approved record will not be allowed for deletion");
}
AweSalesPriceTMP_ds.reread();
AweSalesPriceTMP_ds.executeQuery();
AweSalesPriceTMP_ds.refresh();
roleExist = true;
}
}
while (aweSalesPriceTMPLoc.RecId != 0 && aweSalesPriceTMPLoc.Status == AweStagingPriceStatus::NotProcessed)
{
roleExist = false;
recIdLoc = aweSalesPriceTMPLoc.RecId;
ttsBegin;
select forUpdate aweSalesPriceTMPLoc
where aweSalesPriceTMPLoc.RecId == recIdLoc;
aweSalesPriceTMPLoc.delete();
ttsCommit;
aweSalesPriceTMPLoc = AweSalesPriceTMP_ds.getNext();
track ++;
if (track)
{
AweSalesPriceTMP_ds.reread();
AweSalesPriceTMP_ds.executeQuery();
AweSalesPriceTMP_ds.refresh();
roleExist = true;
}
}
if (roleExist == true)
{
//info(strFmt("Record has been Deleted successfully: %1",track));
info("Record has been Deleted successfully");
}
else
{
Global::error("User - " +curUserId()+ " - don't have privilleges to submit record");
}
}
void clicked() // Edit button
{
//super();
SecurityRole securityRole;
SecurityUserRole securityUserRole;
UserInfo userInfo;
str submitRole, ApproveRole, userRole,recid;
AweSalesPriceTMP aweSalesPriceTMPLoc;
int track = 0;
int64 recIdLoc;
warningmsg1 = false;
warningmsg2 = false;
aweSalesPriceTMPLoc = AweSalesPriceTMP_ds.getFirst(true);
submitRole = AweProjSalesPriceParameter::find().AweSubmissionRole;
while select securityRole
exists join securityUserRole
where securityRole.RecId == securityUserRole.SecurityRole &&
securityUserRole.User == curUserId()
{
userRole = securityRole.Name;
if (userRole == submitRole || userRole == 'System administrator')
{
roleExist = false;
while (aweSalesPriceTMPLoc.RecId != 0 && aweSalesPriceTMPLoc.Status == AweStagingPriceStatus::Submitted)
{
recIdLoc = aweSalesPriceTMPLoc.RecId;
ttsBegin;
select forUpdate aweSalesPriceTMPLoc
where aweSalesPriceTMPLoc.RecId == recIdLoc;
aweSalesPriceTMPLoc.Status = AweStagingPriceStatus::NotProcessed;
aweSalesPriceTMPLoc.SubmittedUser = '';
aweSalesPriceTMPLoc.SubmittedDateTime = utcDateTimeNull();
aweSalesPriceTMPLoc.update();
ttsCommit;
aweSalesPriceTMPLoc = AweSalesPriceTMP_ds.getNext();
track ++;
roleExist = true;
}
if (aweSalesPriceTMPLoc.RecId != 0 && aweSalesPriceTMPLoc.status == AweStagingPriceStatus::Approved)
{
warningmsg1 = true;
}
if (aweSalesPriceTMPLoc.RecId != 0 && aweSalesPriceTMPLoc.status == AweStagingPriceStatus::NotProcessed)
{
warningmsg2 = true;
}
AweSalesPriceTMP_ds.reread();
AweSalesPriceTMP_ds.executeQuery();
AweSalesPriceTMP_ds.refresh();
}
}
if (roleExist == true)
{
//info(strFmt("Record has been moved to NotProcessed state successfully: %1",track));
info("Record has been moved to NotProcessed state successfully");
}
else if (warningmsg1 == true)
{
Global::error("Approved records will not be allowing to modify the record");
}
else if (warningmsg2 == true)
{
Global::warning("The record already in NotProcesed state for modify record");
}
else
{
Global::error("User - " +curUserId()+ " - don't have privilleges to submit record");
}
}
void clicked() // Submit button
{
//super();
SecurityRole securityRole;
SecurityUserRole securityUserRole;
UserInfo userInfo;
str submitRole, ApproveRole, userRole,recid;
AweSalesPriceTMP aweSalesPriceTMPLoc, aweSalesPriceTMPLocal,aweSalesPriceTMPLocal1;
int track = 0;
int64 recIdLoc;
boolean error = false;
TransDate transDate;
warningmsg1 = false;
warningmsg2 = false;
aweSalesPriceTMPLoc = AweSalesPriceTMP_ds.getFirst(true);
submitRole = AweProjSalesPriceParameter::find().AweSubmissionRole;
//ApproveRole = AweProjSalesPriceParameter::find().AweApproveRole;
while select securityRole
exists join securityUserRole
where securityRole.RecId == securityUserRole.SecurityRole &&
securityUserRole.User == curUserId()
{
userRole = securityRole.Name;
if (userRole == submitRole || userRole == 'System administrator')
{
if (aweSalesPriceTMPLoc.ProjId && aweSalesPriceTMPLoc.PSAProjInvoiceProjId)
{
throw Global::error(strFmt('The both ProjId %1 and Contractor %2 combination is not allowed', aweSalesPriceTMPLoc.ProjId, aweSalesPriceTMPLoc.PSAProjInvoiceProjId));
//error = true;
}
if (aweSalesPriceTMPLoc.ProjId && aweSalesPriceTMPLoc.PSACustAccount)
{
throw Global::error(strFmt('The both ProjId %1 and Customer account %2 combination is not allowed', aweSalesPriceTMPLoc.ProjId, aweSalesPriceTMPLoc.PSACustAccount));
//error = true;
}
if (aweSalesPriceTMPLoc.PSAProjInvoiceProjId && aweSalesPriceTMPLoc.PSACustAccount)
{
throw Global::error(strFmt('The both Contractor %1 and Customer account %2 combination is not allowed', aweSalesPriceTMPLoc.PSAProjInvoiceProjId, aweSalesPriceTMPLoc.PSACustAccount));
//error = true;
}
transDate = aweSalesPriceTMPLoc.EffectiveDate;
while select EffectiveDate,Status,ProjId,PSAProjInvoiceProjId,PSACustAccount from aweSalesPriceTMPLocal
where aweSalesPriceTMPLocal.EffectiveDate == transDate &&
aweSalesPriceTMPLocal.Status != AweStagingPriceStatus::NotProcessed
{
if (aweSalesPriceTMPLocal.ProjId == aweSalesPriceTMPLoc.ProjId &&
!aweSalesPriceTMPLocal.PSAProjInvoiceProjId &&
!aweSalesPriceTMPLocal.PSACustAccount
)
{
throw Global::warning(strFmt('The record %1 is already exist %2', aweSalesPriceTMPLocal.EffectiveDate, aweSalesPriceTMPLocal.ProjId));
//error = true;
}
else if (aweSalesPriceTMPLocal.PSAProjInvoiceProjId == aweSalesPriceTMPLoc.PSAProjInvoiceProjId &&
!aweSalesPriceTMPLocal.ProjId &&
!aweSalesPriceTMPLocal.PSACustAccount
)
{
throw Global::warning(strFmt('The record %1 is already exist %2', aweSalesPriceTMPLocal.EffectiveDate, aweSalesPriceTMPLocal.PSAProjInvoiceProjId));
//error = true;
}
else if (aweSalesPriceTMPLocal.PSACustAccount == aweSalesPriceTMPLoc.PSACustAccount &&
!aweSalesPriceTMPLocal.ProjId &&
!aweSalesPriceTMPLocal.PSAProjInvoiceProjId
)
{
throw Global::warning(strFmt('The record %1 is already exist %2', aweSalesPriceTMPLocal.EffectiveDate, aweSalesPriceTMPLocal.PSACustAccount));
//error = true;
}
}
roleExist = false;
while (aweSalesPriceTMPLoc.RecId != 0 && aweSalesPriceTMPLoc.Status == AweStagingPriceStatus::NotProcessed)
{
recIdLoc = aweSalesPriceTMPLoc.RecId;
ttsBegin;
select forUpdate aweSalesPriceTMPLoc
where aweSalesPriceTMPLoc.RecId == recIdLoc;
aweSalesPriceTMPLoc.Status = AweStagingPriceStatus::Submitted;
aweSalesPriceTMPLoc.SubmittedUser = curUserId();
aweSalesPriceTMPLoc.SubmittedDateTime = DateTimeUtil::getSystemDateTime();
aweSalesPriceTMPLoc.update();
ttsCommit;
aweSalesPriceTMPLoc = AweSalesPriceTMP_ds.getNext();
track ++;
roleExist = true;
}
if (aweSalesPriceTMPLoc.RecId != 0 && aweSalesPriceTMPLoc.status == AweStagingPriceStatus::Submitted)
{
warningmsg1 = true;
}
if (aweSalesPriceTMPLoc.RecId != 0 && aweSalesPriceTMPLoc.status == AweStagingPriceStatus::Approved)
{
warningmsg2 = true;
}
AweSalesPriceTMP_ds.reread();
AweSalesPriceTMP_ds.executeQuery();
AweSalesPriceTMP_ds.refresh();
}
}
if (roleExist == true)
{
//info(strFmt("Record has been submitted successfully: %1",track));
info("Record has been submitted successfully");
}
else if (warningmsg1 == true)
{
Global::warning("Record Status is already in 'Submitted' state");
}
else if (warningmsg2 == true)
{
Global::error("The Record is in Approved state");
}
else
{
Global::error("User - " +curUserId()+ " - don't have privilleges to submit record");
}
}
No comments:
Post a Comment