@@ -5,6 +5,14 @@ angular.module('supportAdminApp')
55 function ( $log , $q , $http , API_URL , API_VERSION_PATH ) {
66 var BillingAccountService = { } ;
77
8+ function serialize ( obj ) {
9+ var result = [ ] ;
10+ for ( var property in obj ) {
11+ result . push ( encodeURIComponent ( property ) + "=" + obj [ property ] ) ;
12+ }
13+ return result . join ( "&" ) ;
14+ }
15+
816 /**
917 * Handle API response error
1018 * @param {Error } error the error as received in catch callback
@@ -18,11 +26,16 @@ angular.module('supportAdminApp')
1826 status : error . status ,
1927 error : error . data . result . content
2028 } ;
29+ } else if ( error && error . data ) {
30+ err = {
31+ status : error . status ,
32+ error : error . data . message
33+ } ;
2134 }
2235 if ( ! err ) {
2336 err = {
2437 status : error . status ,
25- error : error . statusText
38+ error : error . message
2639 } ;
2740 }
2841 deferred . reject ( err ) ;
@@ -36,16 +49,25 @@ angular.module('supportAdminApp')
3649 * Search billing accounts
3750 */
3851 BillingAccountService . search = function ( criteria ) {
52+ if ( criteria . startDate && criteria . startDate . length ) {
53+ criteria . startDate = criteria . startDate . substring ( 0 , 16 ) + 'Z' ;
54+ }
55+ if ( criteria . endDate && criteria . endDate . length ) {
56+ criteria . endDate = criteria . endDate . substring ( 0 , 16 ) + 'Z' ;
57+ }
3958 var deferred = $q . defer ( ) ;
4059 var params = { } ;
4160 Object . keys ( criteria ) . forEach ( function ( key ) {
42- if ( criteria [ key ] && criteria [ key ] !== '' ) {
61+ if ( criteria [ key ] && criteria [ key ] !== '' && key !== 'limit' ) {
4362 params [ key ] = criteria [ key ] ;
4463 }
4564 } ) ;
4665 $http ( {
4766 url : BillingAccountService . getBasePath ( ) + '/billing-accounts' ,
48- params : params
67+ params : {
68+ limit : criteria . limit ,
69+ filter : serialize ( params )
70+ }
4971 } ) . then ( function ( response ) {
5072 deferred . resolve ( response . data . result . content ) ;
5173 } ) . catch ( function ( error ) {
@@ -55,12 +77,19 @@ angular.module('supportAdminApp')
5577 }
5678
5779 BillingAccountService . createBillingAccount = function ( entity ) {
80+ var request = angular . copy ( entity ) ;
81+ request . startDate = request . startDate . substring ( 0 , 16 ) + 'Z' ;
82+ request . endDate = request . endDate . substring ( 0 , 16 ) + 'Z' ;
83+ if ( request . paymentTerms ) {
84+ request . paymentTerms = {
85+ id : parseInt ( request . paymentTerms )
86+ } ;
87+ }
88+ delete request . customerNumber ;
5889 var deferred = $q . defer ( ) ;
5990 $http ( {
6091 method : 'POST' ,
61- data : {
62- param : entity
63- } ,
92+ data : request ,
6493 headers : {
6594 'Content-Type' : 'application/json'
6695 } ,
@@ -74,12 +103,13 @@ angular.module('supportAdminApp')
74103 }
75104
76105 BillingAccountService . editBillingAccount = function ( id , entity ) {
106+ entity . paymentTerms = {
107+ id : 1
108+ } ;
77109 var deferred = $q . defer ( ) ;
78110 $http ( {
79111 method : 'PATCH' ,
80- data : {
81- param : entity
82- } ,
112+ data : entity ,
83113 headers : {
84114 'Content-Type' : 'application/json'
85115 } ,
0 commit comments