function add(order, totalPayment, balance, status,payment_method, ref_no,register_id, register_history_id, return_order_id,user_id,store_id) {
	  		var defered = $q.defer();
	  		if (ref_no == undefined) {
	  			ref_no = null;
	  		}
	  		if (balance == undefined) {
	  			balance = null;
	  		}

	  // 		if (ref_no != null) {
			// 	$('#modalCreditCard').modal('hide')
			// }
	  		var order_row = _createOrderObj(order, totalPayment, balance, status,payment_method, ref_no, register_id,register_history_id,return_order_id,user_id,store_id);
	  		var transaction = dbService.db_.createTransaction();
	  		console.log(order_row);
			$('#LoaderDiv').show();
	  		var insertQuery = transaction.begin([dbService.orderTable, dbService.orderItemsTable])
	  				.then(function(){
				  		var insert_order =  dbService.db_.insert().into(dbService.orderTable).values([order_row]);
						return transaction.attach(insert_order);
	  				}).catch(function(){
	  					//error while begining transaction
	  				});

	  		var itemsQuery = insertQuery.then(function(order_db){
	  		// console.log('order_db');
	  		// console.log(order_db);

	  			//now insert detail rows here
	  		    var order_items = _createOrderItemObjs(order.items, order_db[0].id);
	  		    // console.log('order_items');
	  		    // console.log(order_items);

		  		var q = dbService.db_
		  						.insert()
								.into(dbService.orderItemsTable)
								.values(order_items);
				return transaction.attach(q);
	  		}).catch(function(r){
	  			//error while inserting order
	  			defered.resolve(false);
	  		});
			// console.log('itemsQuery');
			// console.log(itemsQuery);

			var commit = itemsQuery.then(function(){
				return transaction.commit();
			}).catch(function(r){
				//error while inserting items
				defered.resolve(false);
			});

			commit.then(function(){
				sync();
				defered.resolve(true);
				
			}).catch(function(){
				//error on committing changes
				defered.resolve(false);
			});

			return defered.promise;
	  	}
/* 
	  	* add order and order details rows in
	  	* local db, and call the sync service to sync 
	  	* changes with server
	  	*/
add order and order details rows in
local db, and call the sync service to sync
changes with server
add order and order details rows in local db and call the sync service to sync changes with server
function add(order, totalPayment, balance, status,payment_method, ref_no,register_id, register_history_id, return_order_id,user_id,store_id) {
	  		var defered = $q.defer();
	  		if (ref_no == undefined) {
	  			ref_no = null;
	  		}
	  		if (balance == undefined) {
	  			balance = null;
	  		}
	  		var order_row = _createOrderObj(order, totalPayment, balance, status,payment_method, ref_no, register_id,register_history_id,return_order_id,user_id,store_id);
	  		var transaction = dbService.db_.createTransaction();
	  		console.log(order_row);
			$('#LoaderDiv').show();
	  		var insertQuery = transaction.begin([dbService.orderTable, dbService.orderItemsTable])
	  				.then(function(){
				  		var insert_order =  dbService.db_.insert().into(dbService.orderTable).values([order_row]);
						return transaction.attach(insert_order);
	  				}).catch(function(){
	  				});
	  		var itemsQuery = insertQuery.then(function(order_db){
	  		    var order_items = _createOrderItemObjs(order.items, order_db[0].id);
		  		var q = dbService.db_
		  						.insert()
								.into(dbService.orderItemsTable)
								.values(order_items);
				return transaction.attach(q);
	  		}).catch(function(r){
	  			defered.resolve(false);
	  		});
			var commit = itemsQuery.then(function(){
				return transaction.commit();
			}).catch(function(r){
				defered.resolve(false);
			});
			commit.then(function(){
				sync();
				defered.resolve(true);
			}).catch(function(){
				defered.resolve(false);
			});
			return defered.promise;
	  	}
function add ( order , totalPayment , balance , status , payment_method , ref_no , register_id , register_history_id , return_order_id , user_id , store_id ) { var defered = $q . defer ( ) ; if ( ref_no == undefined ) { ref_no = null ; } if ( balance == undefined ) { balance = null ; } var order_row = _createOrderObj ( order , totalPayment , balance , status , payment_method , ref_no , register_id , register_history_id , return_order_id , user_id , store_id ) ; var transaction = dbService . db_ . createTransaction ( ) ; console . log ( order_row ) ; $ ( '#LoaderDiv' ) . show ( ) ; var insertQuery = transaction . begin ( [ dbService . orderTable , dbService . orderItemsTable ] ) . then ( function ( ) { var insert_order = dbService . db_ . insert ( ) . into ( dbService . orderTable ) . values ( [ order_row ] ) ; return transaction . attach ( insert_order ) ; } ) . catch ( function ( ) { } ) ; var itemsQuery = insertQuery . then ( function ( order_db ) { var order_items = _createOrderItemObjs ( order . items , order_db [ 0 ] . id ) ; var q = dbService . db_ . insert ( ) . into ( dbService . orderItemsTable ) . values ( order_items ) ; return transaction . attach ( q ) ; } ) . catch ( function ( r ) { defered . resolve ( false ) ; } ) ; var commit = itemsQuery . then ( function ( ) { return transaction . commit ( ) ; } ) . catch ( function ( r ) { defered . resolve ( false ) ; } ) ; commit . then ( function ( ) { sync ( ) ; defered . resolve ( true ) ; } ) . catch ( function ( ) { defered . resolve ( false ) ; } ) ; return defered . promise ; }
add order and order details rows in
 local db, and call the sync service to sync
 changes with server
add order and order details rows in local db and call the sync service to sync changes with server
// 		if (ref_no != null) { // 	$('#modalCreditCard').modal('hide') // } //error while begining transaction // console.log('order_db'); // console.log(order_db); //now insert detail rows here // console.log('order_items'); // console.log(order_items); //error while inserting order // console.log('itemsQuery'); // console.log(itemsQuery); //error while inserting items //error on committing changes