How to create Project Contract Id and Sub Project Id
void clicked()
{
ProjTable projTable;
ProjInvoiceTable projInvoiceTable;
ProjFundingSource projFundingSource;
ProjFundingRule projFundingRule;
ProjFundingRuleAllocation projFundingRuleAllocation;
NumberSeq numberSeq,numberSeqInv;
// Sub project creation
ProjTableType projTableType;
NumberSeq projNumberSeq;
ProjId projIdLastSon, projectId;
ProjId projMask;
Integer sonNum;
str a,b;
ProjType _projType = ProjType::FixedPrice;
ProjParentId _projParentId = UnitReservation_ProjId.valueStr(); // // project id here
NumberSequenceFormat _numberSequenceMask;
ProjLinePropertyId _projInvoiceStatusId;
// Sub project
UnitReservation unitReservation1;
super();
ttsBegin;
numberSeqInv = NumberSeq::newGetNum(ProjParameters::numRefProjInvoiceProjId());
select forupdate projTable where projTable.ProjId == UnitReservation_ProjId.valueStr();//'MIPL-000025';
{
projTable.CustAccount = 'Cust Account';//UnitReservation_CustomerId.valueStr();
//projTable.Name = CustTable::find(projTable.CustAccount).name();
projInvoiceTable.ProjInvoiceProjId = numberSeqInv.num();
projInvoiceTable.Description = 'name'//UnitReservation_PropertyName.valueStr(); //PropertyTable.Name;
projInvoiceTable.CurrencyId = CompanyInfo::standardCurrency();
projFundingSource.ContractId = projInvoiceTable.ProjInvoiceProjId;
projFundingSource.FundingType = ProjFundingType::Customer;
projFundingSource.CustAccount = 'Cust Account';//UnitReservation_CustomerId.valueStr();
projFundingSource.editProjFunder(true,projFundingSource.CustAccount);
projFundingSource.FundingSourceId = CustTable::find(projFundingSource.CustAccount).name();
projFundingSource.LanguageId = 'en-in';
projFundingRule.ContractId = projFundingSource.ContractId;
projFundingRule.Priority = 1;
projFundingRule.insert();
projFundingSource.insert();
projFundingRuleAllocation.AllocateRounding = NoYes::Yes;
projFundingRuleAllocation.AllocationPercentage = 100;
projFundingRuleAllocation.FundingRule = projFundingRule.RecId;
projFundingRuleAllocation.FundingSource = projFundingSource.RecId;
projFundingRuleAllocation.insert();
projInvoiceTable.insert();
projTable.ProjInvoiceProjId = projInvoiceTable.ProjInvoiceProjId;
projTable.update();
}
ttsCommit;
info(strFmt("Project contract Id '%1' has been created", projInvoiceTable.ProjInvoiceProjId));
a = projInvoiceTable.ProjInvoiceProjId;
// sub project code
if (_projParentId)
{
projTable.type().initFromParent('Parent ProjId');//(UnitReservation_ProjId.valueStr());
projIdLastSon = ProjTable::projIdLastSon(projTable.ParentId);
if (projIdLastSon)
{
projMask = substr(projIdLastSon, strlen(projTable.ParentId) + 1, (strlen(projIdLastSon) - (strlen(projTable.ParentId)) + 1));
sonNum = ProjTable::numRemTemplate(projMask, ProjTable::find(projTable.ParentId).Format);
}
projTable.ProjId = projTable.ParentId + NumberSeq::numInsertFormat(sonNum + 1, ProjTable::find(projTable.ParentId).Format);
}
else
{
projNumberSeq = NumberSeq::newGetNum(ProjParameters::numRefProjId(), true);
if (projNumberSeq)
{
projTable.ProjId = projNumberSeq.num();
}
}
projectId = projTable.ProjId;
projTable.Type = ProjType::FixedPrice;//_projType;
projTable.ProjGroupId = UnitReservation_ProjGroupId.valueStr();
projTable.Name = _projName; //UnitReservation_CustName.valueStr();
projTableType = projTable.type();
projTableType.initProjTable();
projTable.ProjInvoiceProjId = a; //_projInvoiceProjId;
projInvoiceTable = ProjInvoiceTable::find(a);//_projInvoiceProjId);
projTable.CustAccount = UnitReservation_CustomerId.valueStr(); //; //projInvoiceTable.InvoiceAccount;
projTable.initFromInvoice(projInvoiceTable);
projTable.Format = _numberSequenceMask;
projTable.CheckBudget = ProjGroup::find(UnitReservation_ProjGroupId.valueStr()).CheckBudget;//_projGroupId).CheckBudget;
projTable.Status = ProjStatus::InProcess;
if (_projInvoiceStatusId)
{
ProjLinePropertySetup::updateLinePropertyProj(projTable.ProjId, _projInvoiceStatusId, TableGroupAll::Table, true);
}
projTable.initFromCustTable(CustTable::find(projTable.CustAccount));
if (ProjTable::exist(projTable.ProjId))
{
// Project already exists.
throw error('@SYS56494');
}
if (!projTableType.validateWrite())
throw error ('Validations failed');
projTable.insert();
if (projNumberSeq)
{
projNumberSeq.used();
}
else
{
projTable.clear();
if (projNumberSeq)
{
projNumberSeq.abort();
}
}
//info (strfmt('Project %1 successfully created', projectId));
b = projectId;
// sub project code
info(strFmt('%1',UnitReservation_ProjId.valueStr()));
}
{
ProjTable projTable;
ProjInvoiceTable projInvoiceTable;
ProjFundingSource projFundingSource;
ProjFundingRule projFundingRule;
ProjFundingRuleAllocation projFundingRuleAllocation;
NumberSeq numberSeq,numberSeqInv;
// Sub project creation
ProjTableType projTableType;
NumberSeq projNumberSeq;
ProjId projIdLastSon, projectId;
ProjId projMask;
Integer sonNum;
str a,b;
ProjType _projType = ProjType::FixedPrice;
ProjParentId _projParentId = UnitReservation_ProjId.valueStr(); // // project id here
NumberSequenceFormat _numberSequenceMask;
ProjLinePropertyId _projInvoiceStatusId;
// Sub project
UnitReservation unitReservation1;
super();
ttsBegin;
numberSeqInv = NumberSeq::newGetNum(ProjParameters::numRefProjInvoiceProjId());
select forupdate projTable where projTable.ProjId == UnitReservation_ProjId.valueStr();//'MIPL-000025';
{
projTable.CustAccount = 'Cust Account';//UnitReservation_CustomerId.valueStr();
//projTable.Name = CustTable::find(projTable.CustAccount).name();
projInvoiceTable.ProjInvoiceProjId = numberSeqInv.num();
projInvoiceTable.Description = 'name'//UnitReservation_PropertyName.valueStr(); //PropertyTable.Name;
projInvoiceTable.CurrencyId = CompanyInfo::standardCurrency();
projFundingSource.ContractId = projInvoiceTable.ProjInvoiceProjId;
projFundingSource.FundingType = ProjFundingType::Customer;
projFundingSource.CustAccount = 'Cust Account';//UnitReservation_CustomerId.valueStr();
projFundingSource.editProjFunder(true,projFundingSource.CustAccount);
projFundingSource.FundingSourceId = CustTable::find(projFundingSource.CustAccount).name();
projFundingSource.LanguageId = 'en-in';
projFundingRule.ContractId = projFundingSource.ContractId;
projFundingRule.Priority = 1;
projFundingRule.insert();
projFundingSource.insert();
projFundingRuleAllocation.AllocateRounding = NoYes::Yes;
projFundingRuleAllocation.AllocationPercentage = 100;
projFundingRuleAllocation.FundingRule = projFundingRule.RecId;
projFundingRuleAllocation.FundingSource = projFundingSource.RecId;
projFundingRuleAllocation.insert();
projInvoiceTable.insert();
projTable.ProjInvoiceProjId = projInvoiceTable.ProjInvoiceProjId;
projTable.update();
}
ttsCommit;
info(strFmt("Project contract Id '%1' has been created", projInvoiceTable.ProjInvoiceProjId));
a = projInvoiceTable.ProjInvoiceProjId;
// sub project code
if (_projParentId)
{
projTable.type().initFromParent('Parent ProjId');//(UnitReservation_ProjId.valueStr());
projIdLastSon = ProjTable::projIdLastSon(projTable.ParentId);
if (projIdLastSon)
{
projMask = substr(projIdLastSon, strlen(projTable.ParentId) + 1, (strlen(projIdLastSon) - (strlen(projTable.ParentId)) + 1));
sonNum = ProjTable::numRemTemplate(projMask, ProjTable::find(projTable.ParentId).Format);
}
projTable.ProjId = projTable.ParentId + NumberSeq::numInsertFormat(sonNum + 1, ProjTable::find(projTable.ParentId).Format);
}
else
{
projNumberSeq = NumberSeq::newGetNum(ProjParameters::numRefProjId(), true);
if (projNumberSeq)
{
projTable.ProjId = projNumberSeq.num();
}
}
projectId = projTable.ProjId;
projTable.Type = ProjType::FixedPrice;//_projType;
projTable.ProjGroupId = UnitReservation_ProjGroupId.valueStr();
projTable.Name = _projName; //UnitReservation_CustName.valueStr();
projTableType = projTable.type();
projTableType.initProjTable();
projTable.ProjInvoiceProjId = a; //_projInvoiceProjId;
projInvoiceTable = ProjInvoiceTable::find(a);//_projInvoiceProjId);
projTable.CustAccount = UnitReservation_CustomerId.valueStr(); //; //projInvoiceTable.InvoiceAccount;
projTable.initFromInvoice(projInvoiceTable);
projTable.Format = _numberSequenceMask;
projTable.CheckBudget = ProjGroup::find(UnitReservation_ProjGroupId.valueStr()).CheckBudget;//_projGroupId).CheckBudget;
projTable.Status = ProjStatus::InProcess;
if (_projInvoiceStatusId)
{
ProjLinePropertySetup::updateLinePropertyProj(projTable.ProjId, _projInvoiceStatusId, TableGroupAll::Table, true);
}
projTable.initFromCustTable(CustTable::find(projTable.CustAccount));
if (ProjTable::exist(projTable.ProjId))
{
// Project already exists.
throw error('@SYS56494');
}
if (!projTableType.validateWrite())
throw error ('Validations failed');
projTable.insert();
if (projNumberSeq)
{
projNumberSeq.used();
}
else
{
projTable.clear();
if (projNumberSeq)
{
projNumberSeq.abort();
}
}
//info (strfmt('Project %1 successfully created', projectId));
b = projectId;
// sub project code
info(strFmt('%1',UnitReservation_ProjId.valueStr()));
}
Comments
Post a Comment