src/com/shrewdify/diaroser/impl/PeerImpl.java
public String[] bill(int balance, int chargperblock,
				int timeperBlock, int wereReserved, int usedUnits, String Anum, int type) throws SQLException{
			int unittoAll = Constants.MINUSONE;
			int resCode = Constants.ZERO;
			if (wereReserved > Constants.ZERO) {
				
				int wereUsed = Constants.ZERO;
				if (wereReserved >= Constants.ZERO)
					wereUsed = usedUnits;
				int remaining = wereReserved - wereUsed;
				int leftBal = Constants.ZERO;
				if (remaining > Constants.ZERO)
					leftBal =  (chargperblock  * (remaining/timeperBlock));
				balance += leftBal;
				if(type==1){
					return new String[]{""+resCode,""+balance};
				}
			}

			int reservedUnit = Constants.ZERO;
			if (balance == Constants.ZERO) {
				balance = db.readUserBalance(Anum);
				reservedUnit = reservedUnit + balance;
			}
			if (balance > Constants.ZERO) {
				if (timeperBlock > Constants.ONE) {
					unittoAll = (int) ((((int) (chargperblock / balance) == Constants.ZERO) ? Constants.ONE
							: (chargperblock / balance)) * timeperBlock);
					balance -= chargperblock;
					resCode = Constants.SUCCESS_CODE;
				} else {
					resCode = Constants.NOBALANCE_CODE;
				}

			} else if (balance ==Constants.ZERO){
				resCode = Constants.NOBALANCE_CODE;
			}else{
				resCode =Constants.UKNOWNUSER_CODE;
			}

			return new String[] { "" + resCode, "" + balance, "" + unittoAll,
					"" + reservedUnit };

		}
/**
		 * 
		 * @param balance
		 * @param chargperblock
		 * @param timeperBlock
		 * @param wereReserved
		 * @param usedUnits
		 * @param Anum
		 * @param type
		 * @return
		 * @throws SQLException
		 * 
		 * It reserves units for all initial and Update request's to the user based on his balance , reserved and used units. 
		 * It returns back corresponding units of time allocated and result code in the array.
		 */


It reserves units for all initial and Update request's to the user based on his balance , reserved and used units.
It returns back corresponding units of time allocated and result code in the array.
It reserves units for all initial and Update request ' s to the user based on his balance reserved and used units . It returns back corresponding units of time allocated and result code in the array .
public String[] bill(int balance, int chargperblock,
				int timeperBlock, int wereReserved, int usedUnits, String Anum, int type) throws SQLException{
			int unittoAll = Constants.MINUSONE;
			int resCode = Constants.ZERO;
			if (wereReserved > Constants.ZERO) {
				int wereUsed = Constants.ZERO;
				if (wereReserved >= Constants.ZERO)
					wereUsed = usedUnits;
				int remaining = wereReserved - wereUsed;
				int leftBal = Constants.ZERO;
				if (remaining > Constants.ZERO)
					leftBal =  (chargperblock  * (remaining/timeperBlock));
				balance += leftBal;
				if(type==1){
					return new String[]{""+resCode,""+balance};
				}
			}
			int reservedUnit = Constants.ZERO;
			if (balance == Constants.ZERO) {
				balance = db.readUserBalance(Anum);
				reservedUnit = reservedUnit + balance;
			}
			if (balance > Constants.ZERO) {
				if (timeperBlock > Constants.ONE) {
					unittoAll = (int) ((((int) (chargperblock / balance) == Constants.ZERO) ? Constants.ONE
							: (chargperblock / balance)) * timeperBlock);
					balance -= chargperblock;
					resCode = Constants.SUCCESS_CODE;
				} else {
					resCode = Constants.NOBALANCE_CODE;
				}
			} else if (balance ==Constants.ZERO){
				resCode = Constants.NOBALANCE_CODE;
			}else{
				resCode =Constants.UKNOWNUSER_CODE;
			}
			return new String[] { "" + resCode, "" + balance, "" + unittoAll,
					"" + reservedUnit };
		}
public String [ ] bill ( int balance , int chargperblock , int timeperBlock , int wereReserved , int usedUnits , String Anum , int type ) throws SQLException { int unittoAll = Constants . MINUSONE ; int resCode = Constants . ZERO ; if ( wereReserved > Constants . ZERO ) { int wereUsed = Constants . ZERO ; if ( wereReserved >= Constants . ZERO ) wereUsed = usedUnits ; int remaining = wereReserved - wereUsed ; int leftBal = Constants . ZERO ; if ( remaining > Constants . ZERO ) leftBal = ( chargperblock * ( remaining / timeperBlock ) ) ; balance += leftBal ; if ( type == 1 ) { return new String [ ] { "" + resCode , "" + balance } ; } } int reservedUnit = Constants . ZERO ; if ( balance == Constants . ZERO ) { balance = db . readUserBalance ( Anum ) ; reservedUnit = reservedUnit + balance ; } if ( balance > Constants . ZERO ) { if ( timeperBlock > Constants . ONE ) { unittoAll = ( int ) ( ( ( ( int ) ( chargperblock / balance ) == Constants . ZERO ) ? Constants . ONE : ( chargperblock / balance ) ) * timeperBlock ) ; balance -= chargperblock ; resCode = Constants . SUCCESS_CODE ; } else { resCode = Constants . NOBALANCE_CODE ; } } else if ( balance == Constants . ZERO ) { resCode = Constants . NOBALANCE_CODE ; } else { resCode = Constants . UKNOWNUSER_CODE ; } return new String [ ] { "" + resCode , "" + balance , "" + unittoAll , "" + reservedUnit } ; }
@param balance
 @param chargperblock
 @param timeperBlock
 @param wereReserved
 @param usedUnits
 @param Anum
 @param type
 @return
 @throws SQLException
@param balance @param chargperblock @param timeperBlock @param wereReserved @param usedUnits @param Anum @param type @return @throws SQLException