Opening Balance calculation in DHIS2 stock management

<--script>
dhis2.util.on( 'dhis2.de.event.formReady', function( event,iReVg2xgFPL ) {
	  var periodN= $( '#selectedPeriodId' ).val();// From DHIS2 Selection Param
	  var nextPeriod=(+periodN) + (+1);//201611,201612,201613
	  var nextPeriodSeperate=periodN.toString().substring(0, 4);
	  var year=parseInt(nextPeriodSeperate.trim());
	  var month=parseInt(periodN % 100);
	  if(month==12){
	    year++;
		month=01;
		nextPeriod=year+'01';	
		//console.log("Next period: "+nextPeriod);
	  }	
	 $('.selectedDate').val(nextPeriod);
});

function closingBL(op,re,adplus,adminus,con,closingid,opnextId,period){
// All id pick
 var opbalance= new Number(document.getElementById(op).value);
 var receipts= new Number(document.getElementById(re).value);
 var adjustPlus= new Number(document.getElementById(adplus).value);
 var adjustMinus= new Number(document.getElementById(adminus).value);
 var consump= new Number(document.getElementById(con).value);
 var nextPeriod= $(period).val();
// Closing Balance text data set
var clobalance=opbalance+receipts+adjustPlus-adjustMinus-consump;
/*if(clobalance<0){
 alert('Closing Balance can not be newgative.');
 $(closingid).val(' ');
}*/
$(closingid).val(clobalance);// Display closing balance at the text field
$(opnextId).val(clobalance);// Display closing balance at the text field
$(closingid).change();
$(opnextId).change();
$(closingid).prop("readonly",true);
$(opnextId).prop("readonly",true);
// Spliting Element ID
var ArrayFromString = op.split("-");
var elementId=ArrayFromString[0];

//console.log('Element Id: '+elementId);
//console.log('nextPeriod Id: '+nextPeriod);
var valueSaver = new ValueSaver( elementId,nextPeriod, 'dCWAvZ8hcrs', clobalance, null, 'red' );
valueSaver.save();

}
<--/script>