SELECT 
o.invoiceid orders_id,
o.accountid customers_id,
 '' customers_name,
a.accountname customers_company,
b.SHIP_street  customers_street_address ,
'' customers_suburb,
b.SHIP_city customers_city,
b.SHIP_state customers_state,
concat(b.SHIP_code, ' ' , b.SHIP_pobox) customers_postcode,
b.SHIP_country  customers_country,
a.phone customers_telephone,
a.email1 customers_email_address,
1 customers_address_format_id,
 '' delivery_name,

 a.accountname delivery_company,
b.SHIP_street  delivery_street_address ,
'' delivery_suburb,

b.SHIP_city delivery_city,
b.SHIP_state delivery_state,
concat(b.SHIP_code, ' ' , b.SHIP_pobox) delivery_postcode,
b.SHIP_country  delivery_country,
1 delivery_address_format_id,
   
 '' billing_name,
 a.accountname billing_company,
c.bill_street billing_street_address,
'' billing_suburb,
c.bill_city billing_city,
c.bill_state billing_state,
c.bill_code billing_postcode,
c.bill_country billing_country,
1 billing_address_format_id, 
'' payment_method, 
1 cc_type, 
'' cc_owner, 
'' cc_number, 
'' cc_expires, 
now() last_modified, 
now() date_purchased, 
s.invoicestatusid orders_status, 
o.invoicedate orders_date_finished, 
'EUR' currency, 
1 currency_value,
o.notes remark
from vtiger_invoice o join vtiger_invoicestatus s on o.invoicestatus = s.invoicestatus
join vtiger_account a on o.accountid = a.accountid
left join vtiger_invoicebillads c on (o.invoiceid = c.invoicebilladdressid) 
left join vtiger_invoiceshipads b on (o.invoiceid = b.invoiceshipaddressid )
where s.invoicestatusid in (<@STATUS@>)