//CALCULATION: 1
line = WO_Lines_Import1[ID != 0];
mainwo = WO[Works_Order_Number == line.WO_No];
if(line.Works_Line_Amount != null)
{
if(mainwo.VAT_ApplicableWO = "No")
{
line.Percent=line.Works_Line_Amount / mainwo.WO_NetValue * 100;
line.Gross=line.Works_Line_Amount;
line.VAT=0.00;
line.Net=line.Works_Line_Amount;
}
else if(mainwo.VAT_ApplicableWO = "Yes")
{
line.Percent=line.Works_Line_Amount / mainwo.WO_NetValue * 100;
line.Gross=line.Works_Line_Amount / 100 * 120;
line.VAT=line.Gross - line.Works_Line_Amount;
line.Net=line.Gross / 120 * 100;
}
//sum rows;
total_line = WO_Lines_Import1.sum(Works_Line_Amount);
total_perc = WO_Lines_Import1.sum(Percent);
info total_line;
info total_perc;
//CALC 2: Compare values /validations
if(total_perc != 100)
{
alertmsg = "Line item percentages do not sum to 100 - please amend and import again";
alerturl = "#Form:Alert?plain=" + alertmsg;
openUrl(alerturl,"popup window","height=300,width=500");
delete from WO_Lines_Import1[WO_No == mainwo.Works_Order_Number];
openURL("#Page:WO_Lines_Import","same window");
}
else if(total_line = 0.00 || total_line is null)
{
alertmsg = "Line item total cannot be zero or empty - please amend";
alerturl = "#Form:Alert?plain=" + alertmsg;
openUrl(alerturl,"popup window","height=300,width=500");
delete from WO_Lines_Import1[WO_No == mainwo.Works_Order_Number];
openURL("#Page:WO_Lines_Import","same window");
}
else if(total_line != mainwo.WO_NetValue)
{
alertmsg = "Sum of line totals does not equal WO net value - please amend";
alerturl = "#Form:Alert?plain=" + alertmsg;
openUrl(alerturl,"popup window","height=300,width=500");
delete from WO_Lines_Import1[WO_No == mainwo.Works_Order_Number];
openURL("#Page:WO_Lines_Import","same window");
}
else
{
mainwo.Line_item_total=total_line;
mainwo.Line_perctotal=total_perc;
// INSERT into WO
rows_collection = Collection();
for each rec in WO_Lines_Import1
{
row1 = WO.Order_DetailsWO();
//development
devID = Developments[Development_Name == rec.Dev_name].ID;
row1.Development_PropertySF=devID;
//block
blockID = Development_Blocks[Block_Name == rec.Block_name].ID;
row1.Block=blockID;
//schedule
sched = ScheduleBudgets[ID == rec.ScheduleID].ID;
row1.ScheduleID=sched;
//cost head
costheadID = BudgetBuilderCH[ID == rec.Cost_HeadID].ID;
row1.Cost_HeadID=costheadID;
//asset
assetID = Add_Single_Asset[ID == rec.AssetWO_ID].ID;
row1.AssetWO_ID=assetID;
//ppm
ppmID = Testing_and_Maintenance[ID == rec.PPM_ID].ID;
row1.PPM_ID=ppmID;
row1.Works_Required=rec.Works_Required;
//calculation fields
row1.Percent=rec.Percent;
row1.Works_Line_Amount=rec.Works_Line_Amount;
row1.VAT=0.2 * rec.Works_Line_Amount;
row1.Gross=rec.Works_Line_Amount + row1.VAT;
row1.Net=rec.Works_Line_Amount;
rows_collection.insert(row1);
fet = WO[Works_Order_Number == rec.WO_No];
fet.Order_DetailsWO.insert(rows_collection);
}
delete from WO_Lines_Import1[WO_No == rec.WO_No];
openURL("#Page:WO_Lines_Import","same window");
}
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter