Forums: Calculating order totals on the fly - Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Calculating order totals on the fly

#1 User is offline   admin 

  • Administrator
  • PipPipPip
  • Group: Admin
  • Posts: 17571
  • Joined: 03-February 03
  • Gender:Male

Posted 30 July 2015 - 09:37 PM

Lets consider a simple order entry form where users create order and order details on the same screen. It will be handy to calculate order totals on the fly to save them in 'total' field of 'Orders' table. Here is how it's going to look in generated application.

Posted Image

This is how this can be done in your project. Note that this approach is purely Javascript-based and will work exactly the same way in ASPRunner.NET/ASPRunnerPro applications.

1. Database structure

Posted Image

2. Javascript code that calculates totals

Create a text file named totals.js and save it in <output>/include folder. Paste the following code there:
function calcTotals() {
	 var total=0;	
	$("tr[id*=gridRow]").each(function() {
		var id=$(this).attr('id');
		id = id.substring(7);
		t=+($("#value_price_"+id).val() * $("#value_quantity_"+id).val());
			if (t>0) total+= t;
	});

	$("#value_total_1").val(total);
};


In this code we go through all details table rows, calculate total for each item and add it all together. Once done we assign the totals value to "total" field of master table.

If your database structure is different make sure to update field names like "price", "quantity" and "total".

3. Plug-in external Javascript file

Add the following code snippet to Orders table Add and Edit page. To do so switch to HTML mode, scroll to the end of the page and add code snippet in bold.

Quote

{$footer}
{END body}
<script type="text/javascript" src="include/totals.js">
</script>
</body>
</html>


Now we can use calcTotals() function in our code.

4. Make use of calcTotals function when price or quantity field changes.

To do so add the following code snippet to Javascript onload event of Add and Edit pages of "Order Totals" table.

var ctrlPrice = Runner.getControl(pageid, 'price');
var ctrlQuantity = Runner.getControl(pageid, 'quantity');
ctrlPrice.on('change keyup', function(e){ calcTotals(); } );
ctrlQuantity.on('change keyup', function(e){ calcTotals(); } );

Best regards,
Sergey Kornilov
0

#2 User is offline   milver 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 35
  • Joined: 05-August 11
  • Gender:Male
  • Location:Brazil

Posted 22 February 2016 - 01:00 PM

How to do, to cancel or delete a OrderDetails decrease the value of excluded OrderDetails the total value of the Order?

View Postadmin, on 30 July 2015 - 09:37 PM, said:

Lets consider a simple order entry form where users create order and order details on the same screen. It will be handy to calculate order totals on the fly to save them in 'total' field of 'Orders' table. Here is how it's going to look in generated application.

Posted Image

This is how this can be done in your project. Note that this approach is purely Javascript-based and will work exactly the same way in ASPRunner.NET/ASPRunnerPro applications.

1. Database structure

Posted Image

2. Javascript code that calculates totals

Create a text file named totals.js and save it in <output>/include folder. Paste the following code there:
function calcTotals() {
	 var total=0;	
	$("tr[id*=gridRow]").each(function() {
		var id=$(this).attr('id');
		id = id.substring(7);
		t=+($("#value_price_"+id).val() * $("#value_quantity_"+id).val());
			if (t>0) total+= t;
	});

	$("#value_total_1").val(total);
};


In this code we go through all details table rows, calculate total for each item and add it all together. Once done we assign the totals value to "total" field of master table.

If your database structure is different make sure to update field names like "price", "quantity" and "total".

3. Plug-in external Javascript file

Add the following code snippet to Orders table Add and Edit page. To do so switch to HTML mode, scroll to the end of the page and add code snippet in bold.

Quote

{$footer}
{END body}
<script type="text/javascript" src="include/totals.js">
</script>
</body>
</html>


Now we can use calcTotals() function in our code.

4. Make use of calcTotals function when price or quantity field changes.

To do so add the following code snippet to Javascript onload event of Add and Edit pages of "Order Totals" table.

var ctrlPrice = Runner.getControl(pageid, 'price');
var ctrlQuantity = Runner.getControl(pageid, 'quantity');
ctrlPrice.on('change keyup', function(e){ calcTotals(); } );
ctrlQuantity.on('change keyup', function(e){ calcTotals(); } );

Milver Silva
Analista de Sistemas
E-mail: milver.silva@gmail.com
0

#3 User is offline   jadach 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 527
  • Joined: 26-April 08
  • Gender:Male
  • Location:New York

Posted 22 February 2016 - 07:27 PM

Looks like all Javascript. I assume this can be used "as is" in ASPRunner.Net?
-jerry
0

#4 User is offline   admin 

  • Administrator
  • PipPipPip
  • Group: Admin
  • Posts: 17571
  • Joined: 03-February 03
  • Gender:Male

Posted 22 February 2016 - 07:42 PM

Jerry,

yes, it's all Javascript. Will work as is in ASPRunner.NET.
Best regards,
Sergey Kornilov
0

#5 User is offline   Athanasios Alekizoglou 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 131
  • Joined: 09-October 09
  • Gender:Male
  • Location:Greece

Posted 15 June 2016 - 10:05 AM

Sergey,

on a similar solution I have I a trying to call CalcTotals when deleting an item. So after seeing javascript struck I was lead to onDetailsDeleted function.

Is there a way I can override this, or is there another solution to recalculate totals when deleting an order line or all of them
Best Regards,

Athanasios Alekizoglou
QUALISYS SOFTWARE
0

#6 User is offline   Athanasios Alekizoglou 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 131
  • Joined: 09-October 09
  • Gender:Male
  • Location:Greece

Posted 15 June 2016 - 10:24 AM

View PostAthanasios Alekizoglou, on 15 June 2016 - 01:05 PM, said:

Sergey,

on a similar solution I have I a trying to call CalcTotals when deleting an item. So after seeing javascript struck I was lead to onDetailsDeleted function.

Is there a way I can override this, or is there another solution to recalculate totals when deleting an order line or all of them


Never mind. Found that you have Events for details as well ("beforeSaveDetails", "afterSaveDetails", "afterDeleteDetails", "afterPageReady").

So adding the below code works fine.



pageObj.on('afterDeleteDetails', function(){
alert('Deleted');
});

Best Regards,

Athanasios Alekizoglou
QUALISYS SOFTWARE
0

#7 User is offline   Peterp 

  • Member
  • PipPip
  • Group: Members
  • Posts: 11
  • Joined: 14-June 16

Posted 26 July 2016 - 08:05 AM

View Postadmin, on 31 July 2015 - 08:37 AM, said:

Lets consider a simple order entry form where users create order and order details on the same screen. It will be handy to calculate order totals on the fly to save them in 'total' field of 'Orders' table. Here is how it's going to look in generated application.

Posted Image

This is how this can be done in your project. Note that this approach is purely Javascript-based and will work exactly the same way in ASPRunner.NET/ASPRunnerPro applications.

1. Database structure

Posted Image

2. Javascript code that calculates totals

Create a text file named totals.js and save it in <output>/include folder. Paste the following code there:
function calcTotals() {
	 var total=0;	
	$("tr[id*=gridRow]").each(function() {
		var id=$(this).attr('id');
		id = id.substring(7);
		t=+($("#value_price_"+id).val() * $("#value_quantity_"+id).val());
			if (t>0) total+= t;
	});

	$("#value_total_1").val(total);
};


In this code we go through all details table rows, calculate total for each item and add it all together. Once done we assign the totals value to "total" field of master table.

If your database structure is different make sure to update field names like "price", "quantity" and "total".

3. Plug-in external Javascript file

Add the following code snippet to Orders table Add and Edit page. To do so switch to HTML mode, scroll to the end of the page and add code snippet in bold.

Quote

{$footer}
{END body}
<script type="text/javascript" src="include/totals.js">
</script>
</body>
</html>


Now we can use calcTotals() function in our code.

4. Make use of calcTotals function when price or quantity field changes.

To do so add the following code snippet to Javascript onload event of Add and Edit pages of "Order Totals" table.

var ctrlPrice = Runner.getControl(pageid, 'price');
var ctrlQuantity = Runner.getControl(pageid, 'quantity');
ctrlPrice.on('change keyup', function(e){ calcTotals(); } );
ctrlQuantity.on('change keyup', function(e){ calcTotals(); } );



Hi All,
I have been trying to replicate this demonstration of totals being calculated on the fly and it seems I have missed something because I am unable to get this to perform as shown. I have setup the database to be exactly the same and I think that I have set all of the other parameters as I get the Orders and the orders detail on the same page and when I insert data into the fields the total field in the order header does not change. There must be something I'm not setting up I need this functionality as I'm developing a system for a client. Could somebody please help me as I have spent many hours on this trying to get some result, any help will be greatly appreciated.

Best Regards,
Peterp
0

#8 User is offline   Peterp 

  • Member
  • PipPip
  • Group: Members
  • Posts: 11
  • Joined: 14-June 16

Posted 27 July 2016 - 07:39 AM

View PostPeterp, on 26 July 2016 - 07:05 PM, said:

View Postadmin, on 31 July 2015 - 08:37 AM, said:

Lets consider a simple order entry form where users create order and order details on the same screen. It will be handy to calculate order totals on the fly to save them in 'total' field of 'Orders' table. Here is how it's going to look in generated application.

Posted Image

This is how this can be done in your project. Note that this approach is purely Javascript-based and will work exactly the same way in ASPRunner.NET/ASPRunnerPro applications.

1. Database structure

Posted Image

2. Javascript code that calculates totals

Create a text file named totals.js and save it in <output>/include folder. Paste the following code there:
function calcTotals() {
	 var total=0;	
	$("tr[id*=gridRow]").each(function() {
		var id=$(this).attr('id');
		id = id.substring(7);
		t=+($("#value_price_"+id).val() * $("#value_quantity_"+id).val());
			if (t>0) total+= t;
	});

	$("#value_total_1").val(total);
};


In this code we go through all details table rows, calculate total for each item and add it all together. Once done we assign the totals value to "total" field of master table.

If your database structure is different make sure to update field names like "price", "quantity" and "total".

3. Plug-in external Javascript file

Add the following code snippet to Orders table Add and Edit page. To do so switch to HTML mode, scroll to the end of the page and add code snippet in bold.

Quote

{$footer}
{END body}
<script type="text/javascript" src="include/totals.js">
</script>
</body>
</html>


Now we can use calcTotals() function in our code.

4. Make use of calcTotals function when price or quantity field changes.

To do so add the following code snippet to Javascript onload event of Add and Edit pages of "Order Totals" table.

var ctrlPrice = Runner.getControl(pageid, 'price');
var ctrlQuantity = Runner.getControl(pageid, 'quantity');
ctrlPrice.on('change keyup', function(e){ calcTotals(); } );
ctrlQuantity.on('change keyup', function(e){ calcTotals(); } );



Hi All,
I have been trying to replicate this demonstration of totals being calculated on the fly and it seems I have missed something because I am unable to get this to perform as shown. I have setup the database to be exactly the same and I think that I have set all of the other parameters as I get the Orders and the orders detail on the same page and when I insert data into the fields the total field in the order header does not change. There must be something I'm not setting up I need this functionality as I'm developing a system for a client. Could somebody please help me as I have spent many hours on this trying to get some result, any help will be greatly appreciated.

Best Regards,
Peterp

Hi All,
I have finally manage to get this working, sorry for any inconvenience I may have caused
Best Regards,
Peterp
0

#9 User is offline   jian 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 42
  • Joined: 13-May 08

Posted 10 January 2020 - 09:43 AM

View Postadmin, on 31 July 2015 - 05:37 AM, said:

Lets consider a simple order entry form where users create order and order details on the same screen. It will be handy to calculate order totals on the fly to save them in 'total' field of 'Orders' table. Here is how it's going to look in generated application.

Posted Image

This is how this can be done in your project. Note that this approach is purely Javascript-based and will work exactly the same way in ASPRunner.NET/ASPRunnerPro applications.

1. Database structure

Posted Image

2. Javascript code that calculates totals

Create a text file named totals.js and save it in <output>/include folder. Paste the following code there:
function calcTotals() {
	 var total=0;	
	$("tr[id*=gridRow]").each(function() {
		var id=$(this).attr('id');
		id = id.substring(7);
		t=+($("#value_price_"+id).val() * $("#value_quantity_"+id).val());
			if (t>0) total+= t;
	});

	$("#value_total_1").val(total);
};


In this code we go through all details table rows, calculate total for each item and add it all together. Once done we assign the totals value to "total" field of master table.

If your database structure is different make sure to update field names like "price", "quantity" and "total".

3. Plug-in external Javascript file

Add the following code snippet to Orders table Add and Edit page. To do so switch to HTML mode, scroll to the end of the page and add code snippet in bold.

Quote

{$footer}
{END body}
<script type="text/javascript" src="include/totals.js">
</script>
</body>
</html>


Now we can use calcTotals() function in our code.

4. Make use of calcTotals function when price or quantity field changes.

To do so add the following code snippet to Javascript onload event of Add and Edit pages of "Order Totals" table.

var ctrlPrice = Runner.getControl(pageid, 'price');
var ctrlQuantity = Runner.getControl(pageid, 'quantity');
ctrlPrice.on('change keyup', function(e){ calcTotals(); } );
ctrlQuantity.on('change keyup', function(e){ calcTotals(); } );


Hi Sergey

I found this useful and replicated it in my project built with version 10.3. Do the javascript codes applicable to version 10.3? Because it won't calculate Total.
Please advise. Thanks.
0

#10 User is offline   jian 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 42
  • Joined: 13-May 08

Posted 10 January 2020 - 01:17 PM

View Postjian, on 10 January 2020 - 05:43 PM, said:

View Postadmin, on 31 July 2015 - 05:37 AM, said:

Lets consider a simple order entry form where users create order and order details on the same screen. It will be handy to calculate order totals on the fly to save them in 'total' field of 'Orders' table. Here is how it's going to look in generated application.

Posted Image

This is how this can be done in your project. Note that this approach is purely Javascript-based and will work exactly the same way in ASPRunner.NET/ASPRunnerPro applications.

1. Database structure

Posted Image

2. Javascript code that calculates totals

Create a text file named totals.js and save it in <output>/include folder. Paste the following code there:
function calcTotals() {
	 var total=0;	
	$("tr[id*=gridRow]").each(function() {
		var id=$(this).attr('id');
		id = id.substring(7);
		t=+($("#value_price_"+id).val() * $("#value_quantity_"+id).val());
			if (t>0) total+= t;
	});

	$("#value_total_1").val(total);
};


In this code we go through all details table rows, calculate total for each item and add it all together. Once done we assign the totals value to "total" field of master table.

If your database structure is different make sure to update field names like "price", "quantity" and "total".

3. Plug-in external Javascript file

Add the following code snippet to Orders table Add and Edit page. To do so switch to HTML mode, scroll to the end of the page and add code snippet in bold.

Quote

{$footer}
{END body}
<script type="text/javascript" src="include/totals.js">
</script>
</body>
</html>


Now we can use calcTotals() function in our code.

4. Make use of calcTotals function when price or quantity field changes.

To do so add the following code snippet to Javascript onload event of Add and Edit pages of "Order Totals" table.

var ctrlPrice = Runner.getControl(pageid, 'price');
var ctrlQuantity = Runner.getControl(pageid, 'quantity');
ctrlPrice.on('change keyup', function(e){ calcTotals(); } );
ctrlQuantity.on('change keyup', function(e){ calcTotals(); } );


Hi Sergey

I found this useful and replicated it in my project built with version 10.3. Do the javascript codes applicable to version 10.3? Because it won't calculate Total.
Please advise. Thanks.


Please don't bother. It works now. Thanks.
0

#11 User is offline   Jack Tong 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 69
  • Joined: 23-August 19

Posted 15 February 2020 - 04:15 AM

View Postjian, on 10 January 2020 - 09:17 PM, said:

View Postjian, on 10 January 2020 - 05:43 PM, said:

View Postadmin, on 31 July 2015 - 05:37 AM, said:

Lets consider a simple order entry form where users create order and order details on the same screen. It will be handy to calculate order totals on the fly to save them in 'total' field of 'Orders' table. Here is how it's going to look in generated application.

Posted Image

This is how this can be done in your project. Note that this approach is purely Javascript-based and will work exactly the same way in ASPRunner.NET/ASPRunnerPro applications.

1. Database structure

Posted Image

2. Javascript code that calculates totals

Create a text file named totals.js and save it in <output>/include folder. Paste the following code there:
function calcTotals() {
	 var total=0;	
	$("tr[id*=gridRow]").each(function() {
		var id=$(this).attr('id');
		id = id.substring(7);
		t=+($("#value_price_"+id).val() * $("#value_quantity_"+id).val());
			if (t>0) total+= t;
	});

	$("#value_total_1").val(total);
};


In this code we go through all details table rows, calculate total for each item and add it all together. Once done we assign the totals value to "total" field of master table.

If your database structure is different make sure to update field names like "price", "quantity" and "total".

3. Plug-in external Javascript file

Add the following code snippet to Orders table Add and Edit page. To do so switch to HTML mode, scroll to the end of the page and add code snippet in bold.

Quote

{$footer}
{END body}
<script type="text/javascript" src="include/totals.js">
</script>
</body>
</html>


Now we can use calcTotals() function in our code.

4. Make use of calcTotals function when price or quantity field changes.

To do so add the following code snippet to Javascript onload event of Add and Edit pages of "Order Totals" table.

var ctrlPrice = Runner.getControl(pageid, 'price');
var ctrlQuantity = Runner.getControl(pageid, 'quantity');
ctrlPrice.on('change keyup', function(e){ calcTotals(); } );
ctrlQuantity.on('change keyup', function(e){ calcTotals(); } );


Hi Sergey

I found this useful and replicated it in my project built with version 10.3. Do the javascript codes applicable to version 10.3? Because it won't calculate Total.
Please advise. Thanks.


Please don't bother. It works now. Thanks.


I don't quite understand how it works for deleting detail records. Could anyone elaborate more please? Thanks.
0

#12 User is offline   ruzgarajans 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 48
  • Joined: 20-September 17
  • Gender:Male

Posted 25 December 2020 - 05:00 PM

Hello to everyone,
The order details table is a good job I use frequently.(thank you very much)
I have a question;

In the example we examined, ice cream and some products were written one by one thanks to the "inline add button".

if so; I have my products table and what should I do if I want all of them to appear one under the other.
How can I define all products as default.
0

#13 User is offline   fhumanes 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 241
  • Joined: 10-October 10
  • Gender:Male
  • Location:Madrid (Espaņa)

Posted 29 December 2020 - 06:16 PM

Hello:

I have tried to collect the original proposal of this thread and complete it with many other aspects.
Also, have a complete and installable example on your computers so that you can carry out the tests and corrections that you consider appropriate.

It's at: https://asprunner.co...ter-and-detail/

Greetings,
fernando
0

#14 User is offline   ruzgarajans 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 48
  • Joined: 20-September 17
  • Gender:Male

Posted 30 December 2020 - 06:03 PM

(I hope the dictionary has been translated successfully :)
Dear teacher,
you are doing very successful work.
you guide like a lighthouse

Thank you for your efforts.

I want to differentiate the question a little.
Question 1-) There are duplicate fields. these should not happen again
Question2-) Can't a complete product list be like an excel table? For example, how many products are in content management systems, they are all listed, so we don't need an "add inline button".
What do you think the method should be


(I'm following your website, a great resource)

Thank you

Posted Image[/url][/img]

Posted Image

Posted Image
Posted Image
0

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users