I want to create project quotation by code. Below I've added the full code and it's working, however there are some issues.
salesQuotationLine.createLine(true, false, true, true, true, true);
3. is there a better way to create it?
FullCode
public ResContract createProjectQuotation(ReqContract _reqContract)
{
SalesQuotationTable salesQuotationTable;
SalesQuotationLine salesQuotationLine;
CustTable custTable;
int startLine = Global::infologLine();
int currentLine;
str errorMsg;
System.Exception ex;
ResContract resContract;
{
try
{
changecompany(_reqContract.DataArea())
{
ttsbegin;
if(!custTable)
{
throw Error(/Invalid customer account/);
}
else
{
salesQuotationTable.CustAccount = custTable.AccountNum;
}
salesQuotationTable.QuotationType = QuotationType::Project;
salesQuotationTable.initValue();
salesQuotationTable.initFromCustTable();
{
salesQuotationTable.CurrencyCode = _reqContract.Currency();
}
{
salesQuotationTable.DeliveryName = _reqContract.DeliveryName();
}
select firstonly inventSite where inventSite.SiteId == _reqContract.SiteId();
if(inventSite)
{
salesQuotationTable.InventSiteId = _reqContract.SiteId();
salesQuotationTable.modifiedInventSiteFromParent();
}
else
{
throw Error (strFmt(/SiteId :%1 is not found/, _reqContract.SiteId()));
}
salesQuotationTable.QuotationName = _reqContract.QuotationName();
QuotationType quotationType;
salesQuotationTable.QuotationType = str2Enum(quotationType, _reqContract.QuotationType());
{
salesQuotationTable.insert();
}
else
{
throw error(/Insert failed/);
}
projectQuotationLines = _reqContract.ProjectQuotationLines();
if(projectQuotationLines && projectQuotationLines.elements())
{
LineContract lineContract;
ListEnumerator linesEnum = projectQuotationLines.getEnumerator();
if(linesEnum)
{
while(linesEnum.moveNext())
{
lineContract = linesEnum.current();
if(lineContract)
{
salesQuotationLine.clear();
}
}
}
else
{
throw error(strFmt(/No project quoation lines found/));
}
resContract.QuotationId(salesQuotationTable.QuotationId);
resContract.Success(true);
resContract.Message(/Success/);
ttscommit;
}
}
catch(ex)
{
resContract.Success(NoYes::No);
for(currentLine = startLine + 1; currentLine <= Global::infologLine(); currentLine++)
{
errorMsg += infolog.text(currentLine) + '/';
}
startLine = currentLine - 1;
resContract.Message(errorMsg);
}
}
}
else
{
//logic
}
}
public SalesQuotationLine createProjectQuoationLine(SalesQuotationTable _salesQuotationTable, LineContract _lineContract, ReqContract _reqContract)
{
SalesQuotationLine salesQuotationLine;
salesQuotationLine.QuotationType = QuotationType::Project;
salesQuotationLine.initFromSalesQuotationTable(_salesQuotationTable);
salesQuotationLine.initValue();
salesQuotationLine.ProjTransType = QuotationProjTransType::Item;
salesQuotationLine.SalesQty = _lineContract.SalesQty();
salesQuotationLine.SalesPrice = _lineContract.SalesPrice();
}