@@ -64,28 +64,49 @@ class invoice extends Base {
6464 let endOfZipPos = this . config . get ( 'invoiceSettings' ) . from [ 3 ] . search ( "[ _]" ) ;
6565 let zip = this . config . get ( 'invoiceSettings' ) . from [ 3 ] . substring ( 0 , endOfZipPos ) ;
6666 let city = this . config . get ( 'invoiceSettings' ) . from [ 3 ] . substring ( endOfZipPos + 1 ) ;
67- let endOfZipPosDebitor = this . config . get ( 'invoiceAddress' ) [ 3 ] . search ( "[ _]" ) ;
68- let zipDebitor = this . config . get ( 'invoiceAddress' ) [ 3 ] . substring ( 0 , endOfZipPosDebitor ) ;
69- let cityDebitor = this . config . get ( 'invoiceAddress' ) [ 3 ] . substring ( endOfZipPosDebitor + 1 ) ;
67+
68+ // debitor
69+ let nDebitorAddressFields = this . config . get ( 'invoiceAddress' ) . length ;
70+ let nameDebitor = "" ;
71+ let zipDebitor = "" ;
72+ let cityDebitor = "" ;
73+ let addressDebitor = "" ;
74+ let countryDebitor = "CH" ;
75+
76+ if ( nDebitorAddressFields > 0 ) {
77+ nameDebitor = this . config . get ( 'invoiceAddress' ) [ 0 ] . replaceAll ( "_" , " " ) ;
78+ }
79+ if ( nDebitorAddressFields > 2 ) {
80+ let endOfZipPosDebitor = this . config . get ( 'invoiceAddress' ) [ nDebitorAddressFields - 1 ] . search ( "[ _]" ) ;
81+ zipDebitor = this . config . get ( 'invoiceAddress' ) [ nDebitorAddressFields - 1 ] . substring ( 0 , endOfZipPosDebitor ) . replaceAll ( "_" , " " ) ;
82+ cityDebitor = this . config . get ( 'invoiceAddress' ) [ nDebitorAddressFields - 1 ] . substring ( endOfZipPosDebitor + 1 ) . replaceAll ( "_" , " " ) ;
83+ addressDebitor = this . config . get ( 'invoiceAddress' ) [ nDebitorAddressFields - 2 ] . replaceAll ( "_" , " " ) ;
84+ if ( zipDebitor . search ( "-" ) > 0 )
85+ {
86+ let countryZip = zipDebitor . split ( "-" ) ;
87+ countryDebitor = countryZip [ 0 ] ;
88+ zipDebitor = countryZip [ 1 ] ;
89+ }
90+ }
7091
7192 const data = {
7293 currency : "CHF" ,
7394 amount : this . totalForInvoice ,
74- reference : this . config . get ( 'invoiceTitle ' ) ,
95+ additionalInformation : this . config . get ( 'invoiceReference ' ) ,
7596 creditor : {
76- name : this . config . get ( 'invoiceSettings' ) . from [ 0 ] ,
97+ name : this . config . get ( 'invoiceSettings' ) . from [ 0 ] ,
7798 address : this . config . get ( 'invoiceSettings' ) . from [ 2 ] ,
7899 zip : zip ,
79100 city : city ,
80101 account : this . config . get ( 'invoiceSettings' ) . IBAN ,
81102 country : this . config . get ( 'invoiceSettings' ) . Country
82103 } ,
83104 debtor : {
84- name : this . config . get ( 'invoiceAddress' ) [ 0 ] ,
85- address : this . config . get ( 'invoiceAddress' ) [ 2 ] ,
105+ name : nameDebitor ,
106+ address : addressDebitor ,
86107 zip : zipDebitor ,
87108 city : cityDebitor ,
88- country : "CH"
109+ country : countryDebitor
89110 }
90111 } ;
91112 const options = {
0 commit comments