@@ -64,25 +64,40 @@ 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+
75+
76+ if ( nDebitorAddressFields > 0 ) {
77+ nameDebitor = this . config . get ( 'invoiceAddress' ) [ 0 ] . replace ( "_" , " " ) ;
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 ) . replace ( "_" , " " ) ;
82+ cityDebitor = this . config . get ( 'invoiceAddress' ) [ nDebitorAddressFields - 1 ] . substring ( endOfZipPosDebitor + 1 ) . replace ( "_" , " " ) ;
83+ addressDebitor = this . config . get ( 'invoiceAddress' ) [ nDebitorAddressFields - 2 ] . replace ( "_" , " " ) ;
84+ }
7085
7186 const data = {
7287 currency : "CHF" ,
7388 amount : this . totalForInvoice ,
7489 reference : this . config . get ( 'invoiceReference' ) ,
7590 creditor : {
76- name : this . config . get ( 'invoiceSettings' ) . from [ 0 ] ,
91+ name : this . config . get ( 'invoiceSettings' ) . from [ 0 ] ,
7792 address : this . config . get ( 'invoiceSettings' ) . from [ 2 ] ,
7893 zip : zip ,
7994 city : city ,
8095 account : this . config . get ( 'invoiceSettings' ) . IBAN ,
8196 country : this . config . get ( 'invoiceSettings' ) . Country
8297 } ,
8398 debtor : {
84- name : this . config . get ( 'invoiceAddress' ) [ 0 ] ,
85- address : this . config . get ( 'invoiceAddress' ) [ 2 ] ,
99+ name : nameDebitor ,
100+ address : addressDebitor ,
86101 zip : zipDebitor ,
87102 city : cityDebitor ,
88103 country : "CH"
0 commit comments