Hi,
I want to create project quotation by code. Below I've added the full code and it's working, however there are some issues.
1. SalesPrice is not being set, do i need to update salesQuotationLine.SalesPrice after i create the line? or is there a way to make it get reflected directly? Would this line of code be the issue?
salesQuotationLine.createLine(true, false, true, true, true, true);
2. In SalesQuotationLine: LinePropertyId and ProjectDescription are not being auto populated
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;
if(_reqContract)
{
try
{
changecompany(_reqContract.DataArea())
{
ttsbegin;
select firstonly custTable where custTable.AccountNum == _reqContract.AccountNum();
if(!custTable)
{
throw Error(/Invalid customer account/);
}
else
{
salesQuotationTable.CustAccount = custTable.AccountNum;
}
salesQuotationTable.QuotationId = NumberSeq::newGetNum(SalesParameters::numRefSalesQuotationId()).num();
salesQuotationTable.QuotationType = QuotationType::Project;
salesQuotationTable.initValue();
salesQuotationTable.initFromCustTable();
if(_reqContract.Currency())
{
salesQuotationTable.CurrencyCode = _reqContract.Currency();
}
if(_reqContract.DeliveryName())
{
salesQuotationTable.DeliveryName = _reqContract.DeliveryName();
}
salesQuotationTable.CustomerRef = _reqContract.CustomerReference();
InventSite inventSite;
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.ReceiptDateRequested = _reqContract.ReceiptDateRequested();
salesQuotationTable.QuotationName = _reqContract.QuotationName();
QuotationType quotationType;
salesQuotationTable.QuotationType = str2Enum(quotationType, _reqContract.QuotationType());
if(salesQuotationTable.validateWrite())
{
salesQuotationTable.insert();
}
else
{
throw error(/Insert failed/);
}
List projectQuotationLines = new List(Types::Class);
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();
salesQuotationLine = this.createProjectQuoationLine(salesQuotationTable, lineContract, _reqContract);
}
}
}
}
else
{
throw error(strFmt(/No project quoation lines found/));
}
resContract = new ResContract();
resContract.QuotationId(salesQuotationTable.QuotationId);
resContract.Success(true);
resContract.Message(/Success/);
ttscommit;
}
}
catch(ex)
{
ResContract resContract = new ResContract();
resContract.Success(NoYes::No);
errorMsg = '';
for(currentLine = startLine + 1; currentLine <= Global::infologLine(); currentLine++)
{
errorMsg += infolog.text(currentLine) + '/';
}
startLine = currentLine - 1;
resContract.Message(errorMsg);
}
}
}
else
{
//logic
}
return resContract;
}
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.ItemId = _lineContract.ItemId();
salesQuotationLine.SalesQty = _lineContract.SalesQty();
salesQuotationLine.SalesPrice = _lineContract.SalesPrice();
salesQuotationLine.createLine(true, false, true, true, true, true);
return salesQuotationLine;
}