Welcome to the nuBuilder forums!

Please register and login to view forums and other content only available to registered users.

Invoice calculating

Locked
Eppo
Posts: 29
Joined: Mon Jan 14, 2013 3:49 pm
Location: The Netherlands, Leiden

Invoice calculating

Unread post by Eppo »

Hi There,

My customer system is up and running and is working great. I've got only one new problem.

I did make een invoice form like the one you have made on your sample nuFinancial module.
The problem I've got is: when I copy the calculating script from nuFinancial I wil get een blank screen and can't do anything.

it starts with the "Before open" tab:

Code: Select all

//build JavaScript for screen
$javascript = createJavaScriptSharedFunctions(); 
addJSFunction($javascript);
When I put this in my before open tab it already gives a blank screen. When I don't put in this script and only put in the JavaScript tab then my safe button doesn't work.

on the "before safe" tab I've got

Code: Select all

//--
and on the "javascript" tab I've got:

Code: Select all

function nuLoadThis() {
	calcinv_total();
}

function nuBeforeSave(){
	
	if ( !validateCloseDate() )
		return false;
	
	calcinv_total();
	return true;

}

function calclinetotal(pthis) {
   
   	if (pthis.length == 18) {
		// Parameter passed through from tri_product_id
   		PRE = pthis;
   	} else {  
		// Parameter passed through from tri_units or tri_cost
   		PRE = pthis.name.substring(0,18);	
   	}
   
   	//calculate the total of the line by quantity * cost
	unit                                = Number(document.getElementById(PRE+'fac_item_stuks').value);
	unitCost                            = Number(document.getElementById(PRE+'fac_item_prijs').value);
	taxPercent                          = Number(document.getElementById(PRE+'fac_btw_pro').value);

	//Make sure rounding is correct before setting field value
	total                               = Math.round(unit  * unitCost);
	taxAmount                           = Math.round(unit  * unitCost)/ (100 + taxPercent) * taxPercent;
	price                               = total - taxAmount;

	document.getElementById(PRE+'fac_item_netto').value     = price;
	document.getElementById(PRE+'fac_item_btw').value       = taxAmount;
	document.getElementById(PRE+'fac_item_totaal').value    = total;

	//if the values of the total field is blank then fill them in
	if(document.getElementById(PRE+'fac_item_totaal').value < '0'){

		document.getElementById(PRE+'fac_item_netto').value     = price;
		document.getElementById(PRE+'fac_item_btw').value       = taxAmount;
		document.getElementById(PRE+'fac_item_totaal').value    = total;
	}

	nuFormat(document.getElementById(PRE+'fac_item_stuks'));
	nuFormat(document.getElementById(PRE+'fac_item_prijs'));
	nuFormat(document.getElementById(PRE+'fac_item_totaal'));

	calcinv_total();
   
}

function calcinv_total() {
   
        //calculate the entire total of all the line totals
	theRows                       = Number(document.getElementById('rowssub_fac_item').value);

	invAmount                     = '0';
	invTax                        = '0';

        //for every line...
	for (int = 0;int < theRows; ++int) {   

		strlength	= '0000'+int;
		pstrlength      = strlength.length;
		PRE             = 'sub_fac_item' + ('0000'+int).substring(pstrlength-4);
		price           = Number(document.getElementById(PRE+'fac_item_netto').value);
		taxAmount       = Number(document.getElementById(PRE+'fac_item_btw').value);
		total           = Number(document.getElementById(PRE+'fac_item_totaal').value);

		//if delete is not checked then add prices
		if (document.getElementById("row"+PRE).checked != true) {

			invAmount	= Number(invAmount) + price;
		        invTax		= Number(invTax) + taxAmount;

			nuFormat(document.getElementById(PRE+'fac_item_netto'));
			nuFormat(document.getElementById(PRE+'fac_item_btw'));
			nuFormat(document.getElementById(PRE+'fac_item_totaal'));
			
		//else set to zero and don't add
		} else {

			document.getElementById(PRE+'fac_item_netto').value = 0;
			document.getElementById(PRE+'fac_item_btw').value = 0;
			document.getElementById(PRE+'fac_item_totaal').value = 0;
			
			nuFormat(document.getElementById(PRE+'fac_item_netto'));
			nuFormat(document.getElementById(PRE+'fac_item_btw'));
			nuFormat(document.getElementById(PRE+'fac_item_totaal'));
		}
	}
   

	document.getElementById('fac_netto').value        = invAmount; 
	document.getElementById('fac_btw').value           = invTax;
	document.getElementById('fac_totaal').value         = invAmount + invTax;  

	nuFormat(document.getElementById('fac_netto'));
	nuFormat(document.getElementById('fac_btw'));
	nuFormat(document.getElementById('fac_totaal'));
       
}

function getRowPrefixFromLookup(pthis) {
	// Needed to update row price totals if user changes a product lookup
	PRE  = pthis.name.substring(4,22);
	nuCreateCookie('row_name_for_transaction_item', PRE, 0);	
	calclinetotal(nuReadCookie('row_name_for_transaction_item'));	
}
I hope you can help me. I searched through your nuFianacial module but didn't find a piece of script with maked it worked.

Thanks you verry much.


Jeroen
massiws
Posts: 503
Joined: Thu May 24, 2012 2:08 am
Location: Milan, Italy
Contact:

Re: Invoice calculating

Unread post by massiws »

Jeroen,
have you defined the createJavaScriptSharedFunctions() function in system library?
Check for a function with this name in zzsys_library table:

Code: Select all

SELECT * FROM  `zzsys_library` WHERE  `slb_code` LIKE  '%function createJavaScriptSharedFunctions()%'
Hope this helps,
Max
Eppo
Posts: 29
Joined: Mon Jan 14, 2013 3:49 pm
Location: The Netherlands, Leiden

Re: Invoice calculating

Unread post by Eppo »

Thanks Max,

I've had to copy also a piece of script from de Code library (tab financials) and when that was done I could see the the page again.
But I don't think it has anything tot do with the calculating script because that piece is about dates en stuf and I just want to calculate invoice in my system.

However with this script I can see the page again but the calculating job doesn't work. What can I do to make it work because I understand what the Tab "javascript" does only i don't see any mistakes.

Thanks again.

Jeroen
massiws
Posts: 503
Joined: Thu May 24, 2012 2:08 am
Location: Milan, Italy
Contact:

Re: Invoice calculating

Unread post by massiws »

Eppo wrote:...the calculating job doesn't work. What can I do to make it work because I understand what the Tab "javascript" does only i don't see any mistakes.
Jeroen, are you saying that when you insert a new Invoice Item the Amount field doesn't change?
Have a look here:
  • FMInvoice form -> Custom Code -> Javascript tab
  • SubForm object -> On Change field
All calculating job is done in these places.

Max
Eppo
Posts: 29
Joined: Mon Jan 14, 2013 3:49 pm
Location: The Netherlands, Leiden

Re: Invoice calculating

Unread post by Eppo »

Hi Max,

Sorry for my late responce, but my wife gave birth to my new Son, so I had some other stuf to do. :D

Yes I was saying it didn't work. The problem was in:

Code: Select all

// Parameter passed through from tri_units or tri_cost
             PRE = pthis.name.substring(0,16);   
In the original script there was 18. But I changed the original name and that is only 16 characters so non of the created names were compatible and thats why it didn't calvulate.

Thanks very much for the help.

Jeroen
massiws
Posts: 503
Joined: Thu May 24, 2012 2:08 am
Location: Milan, Italy
Contact:

Re: Invoice calculating

Unread post by massiws »

Eppo wrote:... my wife gave birth to my new Son, so I had some other stuf to do. :D
That's the harder but more satisfying job!
All my best wishes!
Locked