insert into api.organizations (organization_uuid, parent_organization_uuid, organization_name, organization_description, job_code_prefix)
	select	 'de47b02d-2aac-47e2-9511-7188553935b2', 'd6d4e03e-7e88-4f69-9664-2e16da4da2b1', 'Dream Graphics', 'Dream Graphics', 'Z';

	insert into api.users (user_uuid, last_name, first_name, email, user_notes) 
	select   'f72bff37-2d38-4c14-8d5f-7603cf64364f', 'api', 'dreamgraphics', 'info@dreamgraphicsusa.com', '';  

	insert	into api.organization_users(	organization_uuid, user_uuid, created_at, updated_at, deleted_at, user_reference_code, is_pay_by_check, default_currency_code, tax_reference_code, is_approved, 
					is_tax_exempt, can_pickup, can_deliver, is_deactivated, is_flagged, is_banned, is_internal, is_pending, is_enabled, opt_out_email_list, organization_user_uuid, loyalty_level_uuid, contract_pricing_ratio) 
	select  (select o.organization_uuid FROM api.organizations o WHERE o.organization_name = 'Dream Graphics' and o.primary_contact_user_uuid is null) as organization_uuid,
		(select u.user_uuid from api.users u where u.email = 'info@dreamgraphicsusa.com' and u.last_name = 'api') as user_uuid,
		now() as created_at,
		now() as updated_at,
		deleted_at,
		user_reference_code,
		is_pay_by_check,
		default_currency_code,
		tax_reference_code,
		is_approved,
		is_tax_exempt,
		can_pickup,
		can_deliver,
		is_deactivated,
		is_flagged,
		is_banned,
		is_internal,
		is_pending,
		is_enabled,
		opt_out_email_list,
		'f44b5bcf-54bf-4628-9edc-81c3698672dd' as organization_user_uuid,
		loyalty_level_uuid,
		contract_pricing_ratio
	FROM 	api.organization_users ou
	WHERE 	ou.organization_uuid = '0d605ff0-24ac-4772-9868-87ba31afa256'
	AND 	ou.user_uuid = (select ou.user_uuid from api.organization_users ou where ou.user_reference_code = '186299' and ou.organization_uuid = '0d605ff0-24ac-4772-9868-87ba31afa256');


	insert	into api.organization_contacts(
		organization_contact_uuid, organization_uuid, user_uuid, first_name, last_name, company, is_validated, 
		is_user_only_contact, created_at, updated_at, deleted_at, is_address_book_contact, middle_name, salutation, suffix)
	select	'579ba2ee-dee4-47d9-8c2f-95c1d25b1232' as organization_contact_uuid,
		(select o.organization_uuid FROM api.organizations o WHERE o.organization_name = 'Dream Graphics' and o.primary_contact_user_uuid is null) as organization_uuid, 
		(select u.user_uuid from api.users u where u.email = 'info@dreamgraphicsusa.com' and u.last_name = 'api') as user_uuid,
		oc.first_name,
		last_name,
		company,
		is_validated,
		is_user_only_contact,
		created_at,
		updated_at,
		deleted_at,
		is_address_book_contact,
		middle_name, salutation, suffix
	from 	api.organization_contacts oc
	where	oc.organization_contact_uuid = (	select oc.organization_contact_uuid 
						from 	api.organization_contacts oc
						where	oc.company = 'Dream Graphics' and oc.is_address_book_contact = 'f' and oc.organization_uuid = '0d605ff0-24ac-4772-9868-87ba31afa256' and oc.first_name = 'Irfan' and oc.last_name = 'Ozair');

	
	insert	into api.organization_contact_addresses(organization_contact_address_uuid, organization_contact_uuid, address_type_uuid, address_uuid, organization_uuid, user_uuid)
	select	'1c0cab8e-d253-4ccb-beea-eb2b23cea0a6' as organization_contact_address_uuid,
		(select oc.organization_contact_uuid from api.organization_contacts oc where oc.organization_uuid = (select o.organization_uuid FROM api.organizations o WHERE o.organization_name = 'Dream Graphics' and o.primary_contact_user_uuid is null) 
		    and oc.user_uuid = (select u.user_uuid from api.users u where u.email = 'info@dreamgraphicsusa.com' and u.last_name = 'api')) as organization_contact_uuid,
		    'f450648b-b472-41f7-a459-ca55a19201d7' as address_type_uuid,
		(SELECT a.address_uuid FROM api.addresses a WHERE  a.street = '1500 Jennifer Court' and a.street2 = '' and a.city = 'Round Rock') as address_uuid,
		(select o.organization_uuid FROM api.organizations o WHERE o.organization_name = 'Dream Graphics' and o.primary_contact_user_uuid is null) as organization_uuid,
		(select u.user_uuid from api.users u where u.email = 'info@dreamgraphicsusa.com' and u.last_name = 'api') as user_uuid;


	insert	into api.organization_contact_addresses(organization_contact_address_uuid, organization_contact_uuid, address_type_uuid, address_uuid, organization_uuid, user_uuid)
	select	'e1ed511c-6628-4db9-a5c7-759d86534a77' as organization_contact_address_uuid,
		(select oc.organization_contact_uuid from api.organization_contacts oc where oc.organization_uuid = (select o.organization_uuid FROM api.organizations o WHERE o.organization_name = 'Dream Graphics' and o.primary_contact_user_uuid is null)
		    and oc.user_uuid = (select u.user_uuid from api.users u where u.email = 'info@dreamgraphicsusa.com' and u.last_name = 'api'))  as organization_contact_uuid,
		    'ea3725bf-2fe6-449c-9b7b-ecc2e622e27f' as address_type_uuid,
		(SELECT a.address_uuid FROM api.addresses a WHERE  a.street = '1500 Jennifer Court' and a.street2 = '' and a.city = 'Round Rock') as address_uuid,
		(select o.organization_uuid FROM api.organizations o WHERE o.organization_name = 'Dream Graphics' and o.primary_contact_user_uuid is null) as organization_uuid,
		(select u.user_uuid from api.users u where u.email = 'info@dreamgraphicsusa.com' and u.last_name = 'api') as user_uuid;


	insert	into api.organization_contact_addresses(organization_contact_address_uuid, organization_contact_uuid, address_type_uuid, address_uuid, organization_uuid, user_uuid)
	select	'a3ef021e-b1fa-41e5-9ca0-003cadd0236f' as organization_contact_address_uuid,
		(select oc.organization_contact_uuid from api.organization_contacts oc where oc.organization_uuid = (select o.organization_uuid FROM api.organizations o WHERE o.organization_name = 'Dream Graphics'
		    and o.primary_contact_user_uuid is null) and oc.user_uuid = (select u.user_uuid from api.users u where u.email = 'info@dreamgraphicsusa.com' and u.last_name = 'api'))  as organization_contact_uuid,
		    '872f416f-9bae-4334-b9ba-fa39798691a7' as address_type_uuid,
		(SELECT a.address_uuid FROM api.addresses a WHERE  a.street = '1500 Jennifer Court' and a.street2 = '' and a.city = 'Round Rock') as address_uuid,
		(select o.organization_uuid FROM api.organizations o WHERE o.organization_name = 'Dream Graphics' and o.primary_contact_user_uuid is null) as organization_uuid,
		(select u.user_uuid from api.users u where u.email = 'info@dreamgraphicsusa.com' and u.last_name = 'api') as user_uuid;
 

	insert	into api.organization_contact_addresses(organization_contact_address_uuid, organization_contact_uuid, address_type_uuid, address_uuid, organization_uuid, user_uuid)
	select	'af05fecf-b73b-4068-9edf-2324c79d8b2b' as organization_contact_address_uuid,
		(select oc.organization_contact_uuid from api.organization_contacts oc where oc.organization_uuid = (select o.organization_uuid FROM api.organizations o WHERE o.organization_name = 'Dream Graphics'
		    and o.primary_contact_user_uuid is null) and oc.user_uuid = (select u.user_uuid from api.users u where u.email = 'info@dreamgraphicsusa.com' and u.last_name = 'api'))  as organization_contact_uuid,
		    '218eef26-84d2-4ccd-9d67-f4eda9711ab8' as address_type_uuid,
		(SELECT a.address_uuid FROM api.addresses a WHERE  a.street = '1500 Jennifer Court' and a.street2 =  '' and a.city = 'Round Rock') as address_uuid,
		(select o.organization_uuid FROM api.organizations o WHERE o.organization_name = 'Dream Graphics' and o.primary_contact_user_uuid is null) as organization_uuid,
		(select u.user_uuid from api.users u where u.email = 'info@dreamgraphicsusa.com' and u.last_name = 'api') as user_uuid;


	update api.organizations o
	set primary_contact_user_uuid = (SELECT oc.user_uuid FROM api.organization_contacts oc 
						WHERE oc.organization_uuid = (select o.organization_uuid from api.organizations o where o.organization_name = 'Dream Graphics' and o.primary_contact_user_uuid is null) 
						AND oc.is_address_book_contact is false)
	where o.organization_name = 'Dream Graphics' and o.primary_contact_user_uuid is null;


	insert	into api.organization_contact_info(organization_contact_info_uuid, organization_contact_uuid, contact_info_type_uuid, contact_info, is_validated, created_at, updated_at, deleted_at)
		select '1cdde2a2-00bd-4300-ba6d-5ab54d9c1e93' as organization_contact_info_uuid, 
		(select oc.organization_contact_uuid 
		from api.organization_contacts oc 
		where oc.organization_uuid = (
	
					select o.organization_uuid 
					FROM api.organizations o 
					WHERE o.organization_name = 'Dream Graphics'
					and o.primary_contact_user_uuid = (
										select o.primary_contact_user_uuid 
										from api.organizations o 
										where o.organization_name = 'Dream Graphics'
										and o.primary_contact_user_uuid = (select u.user_uuid from api.users u where u.email = 'info@dreamgraphicsusa.com' and last_name = 'api')
									)

	) 
	 
	and oc.user_uuid =(select u.user_uuid from api.users u where u.email = 'info@dreamgraphicsusa.com' and u.last_name = 'api')
		)  as organization_contact_uuid,

		'd379aab3-bb8d-444d-81cd-b80ae979dd58' as contact_info_type_uuid, 
		'info@dreamgraphicsusa.com' as contact_info,
		false as is_validated,
		now() as created_at,
		now() as updated_at,
		NULL as deleted_at;

		
-------------------------------------------------------------------------------------------------------------------


