Hello,
I’m building some reports using HTML and Javascript. I have two scripts that break down per Project managers and within each of them per status of project. After each list of project’s statuses, I get a sum. My issue is that the script that checks if it’s a new project manager runs before the sum and displays the new section before the sums.
// This is the function that checks if it’s the same project manager
`function Checkstatus(value) {
if (previous_status != value) {
if (ctr > 0) {
document.writeln(‘<td colspan=”5″></td>’);
document.writeln(‘<td colspan=”1″ style=”border-top-style:solid;border-top-width: thin;font-weight: bold”>Sums:</td>’);
document.writeln(‘<td colspan=”1″ style=”border-top-style:solid;border-top-width: thin;font-weight: bold”>’ + qty + ‘</td>’);
document.writeln(‘<td colspan=”1″ style=”border-top-style:solid;border-top-width: thin;font-weight: bold”>’ + qty1 + ‘</td>’);
qty = 0.0;
qty1 = 0.0;
}
ctr++;
document.writeln(‘<tr><td></td></tr>’);
document.writeln(‘<tr>’);
document.writeln(‘<th colspan=”3″></th>’);
document.writeln(‘<th colspan=”10″>’ + value + ‘</th>’);
document.writeln(‘</tr>’);
document.writeln(‘<th width=”3%”>Req_ID</th>’)
document.writeln(‘<th width=”25%”>PM</th>’)
document.writeln(‘<th width=”45%”>Name</th>’)
document.writeln(‘<th width=”10%”>Status</th>’)
document.writeln(‘<th width=”5%”>Start Date</th>’)
document.writeln(‘<th width=”5%”>End Date</th>’)
document.writeln(‘<th width=”5%”>Pl. Cost</th>’)
document.writeln(‘<th width=”5%”>Pl. Price</th>’)
document.writeln(‘<th width=”5%”>Margin</th>’)
document.writeln(‘<tr><td></td></tr>’);
}
previous_status = value;
}`
// AND THIS IS THE FUNCTION THAT CHECKS THE STATUS
`function CheckTechnician(value) {
if (previous_tech != value) {
document.writeln(‘<tr><td></td></tr>’);
document.writeln(‘<tr style=”background-color: lightgray”>’);
document.writeln(‘<th colspan=”2″ style=”background-color: lightgray;color: red”>Project Manager:</th>’);
document.writeln(‘<th colspan=”10″ style=”background-color: lightgray;color:red “>’ + value + ‘</th>’);
document.writeln(‘</tr style=”background-color: lightgray”>’);
document.writeln(‘<tr><td></td></tr>’);
}
previous_tech = value;
}`
//AND THIS IS WHERE I CALL THEM
`<script>
CheckTechnician(‘{{fields.pm}}’)
</script>
<script>
Checkstatus(‘{{fields.status}}’)
</script>
<tr>
<td width=”3%”>{{fields.request}}</td>
<td width=”25%”>{{fields.pm}}</td>
<td width=”45%”>{{fields.name}}</td>
<td width=”10%”>{{fields.status1}}</td>
<td width=”5%”>{{fields.planned_start_date}}</td>
<td width=”5%”>{{fields.planned_end_date}}</td>
<td width=”5%”>{{fields.planned_cost}}
<script>
QuantitySum({
{
fields.planned_cost
}
})
</script>
</td>
<td width=”5%”>{{fields.planned_price}}
<script>
QuantitySum1({
{
fields.planned_price
}
})
</script>
</td>
<td width=”5%”>{{fields.planned_margin}}</td>
</tr>
`
//This is the result in the attachment. As you can see, eveytime the project manager changes, the sums are displayed after the new project manager section.