/    Sign up×
Community /Pin to ProfileBookmark

Imbrication of scripts

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.
[upl-image-preview url=https://www.webdeveloper.com/assets/files/2019-10-25/1572014156-915303-report.jpeg]

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@rootOct 27.2019 — document.write and document.writeLn went out with the ark and should not be used at all now in favor of updating DOM elements or server scripts to output the data in the format you requested.

> @belilan#1610382 <td width="5%">{{fields.planned_price}}

indicates that you have a server and some CMS system... you have most of what you need already. I suggest you process the document server side rather than at the clients side.
Copy linkTweet thisAlerts:
@belilanauthorOct 28.2019 — @root#1610424 My results are fetched from our local software through SQL queries, that's how I refer to the fields like "planned_price". I can have queries for sums as well, but not when I want to break down by status or project managers. If I want that, I do have to use JavaScript into the report itself.

I know I just made a mistake somewhere in my scripts and trying to find out where.
Copy linkTweet thisAlerts:
@rootOct 28.2019 — You are using a method that is depreciated by at least 15 years or more.

You should be doing this at the server OR putting the data in to a format that your script can filter through for the information you need.

However, it still does not get around the fact that you have databases and server queries that can be done via AJAX to the server and a server script fetches the data you wanted.

Job done.
Copy linkTweet thisAlerts:
@belilanauthorOct 28.2019 — It would be too long to explain why, but I'm limited to what I can do from our software itself. Those are the methods I'm able to use and nothing else. In a year or so we'll have a new version more flexible, but for now that's what it is.

So this said, do you have an idea of why my problem is occurring?
Copy linkTweet thisAlerts:
@belilanauthorOct 28.2019 — @root#1610444

It would be too long to explain why, but I'm limited to what I can do from our software itself. Those are the methods I'm able to use and nothing else. In a year or so we'll have a new version more flexible, but for now that's what it is.

So this said, do you have an idea of why my problem is occurring?
Copy linkTweet thisAlerts:
@rootNov 06.2019 — No idea and not about to invest time in scanning old code for a problem, I have lots to do myself with my projects and can only offer limited advice.
×

Success!

Help @belilan spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...