API to create a Customer

This post I put a code to create a client, it will serve as a basic register to be able to issue a sales order.

DECLARE

v_location_rec hz_location_v2pub.location_rec_type;
 v_party_site_rec hz_party_site_v2pub.party_site_rec_type;
 v_cust_site_use_rec hz_cust_account_site_v2pub.cust_site_use_rec_type;
 v_customer_profile_rec hz_customer_profile_v2pub.customer_profile_rec_type;
 v_cust_acct_site_rec hz_cust_account_site_v2pub.cust_acct_site_rec_type;
 v_cust_account_rec hz_cust_account_v2pub.cust_account_rec_type;
 v_organization_rec hz_party_v2pub.organization_rec_type;
 v_cust_account_id NUMBER;
 v_account_number VARCHAR2(2000);
 v_party_id NUMBER;
 v_party_number VARCHAR2(2000);
 v_profile_id NUMBER;
 v_return_status VARCHAR2(2000);
 v_msg_count NUMBER;
 v_msg_data VARCHAR2(2000);
 v_location_id NUMBER;
 v_party_site_id NUMBER;
 v_party_site_number VARCHAR2(2000);
 v_cust_acct_site_id NUMBER;
 v_site_use_id NUMBER;
 v_contact_point_rec hz_contact_point_v2pub.contact_point_rec_type;
 v_edi_rec hz_contact_point_v2pub.edi_rec_type;
 v_email_rec hz_contact_point_v2pub.email_rec_type;
 v_phone_rec hz_contact_point_v2pub.phone_rec_type;
 v_telex_rec hz_contact_point_v2pub.telex_rec_type;
 v_web_rec hz_contact_point_v2pub.web_rec_type;
 v_contact_point_id NUMBER;

BEGIN

mo_global.init('AR');
 fnd_global.apps_initialize ( user_id => pi_user_id,
 resp_id => pi_resp_id,
 resp_appl_id => pi_application_id);

mo_global.set_policy_context('S', pi_org_id );
 fnd_global.set_nls_context('AMERICAN');
 mo_global.set_policy_context('S', pi_org_id );

v_cust_account_rec.created_by_module := 'HZ_CPUI';
 v_cust_account_rec.ship_sets_include_lines_flag := 'N';
 v_cust_account_rec.arrivalsets_include_lines_flag := 'N' ;
 v_cust_account_rec.sched_date_push_flag := 'N';
 v_cust_account_rec.application_id := pi_application_id;
 v_cust_account_rec.global_attribute_category := 'JL.BR.ARXCUDCI.Additional' ;
 v_cust_account_rec.status := 'A';
 v_location_rec.created_by_module := 'HZ_CPUI';
 v_location_rec.address_style := 'BR';
 v_location_rec.application_id := pi_application_id;
 v_cust_acct_site_rec.created_by_module := 'HZ_CPUI';
 v_cust_acct_site_rec.application_id := pi_application_id;
 v_cust_acct_site_rec.global_attribute_category := 'JL.BR.ARXCUDCI.Additional';
 v_cust_site_use_rec.site_use_code := 'BILL_TO';
 v_cust_site_use_rec.created_by_module := 'HZ_CPUI';
 v_cust_site_use_rec.application_id := pi_application_id;
 v_cust_site_use_rec.global_attribute_category := 'JL.BR.ARXCUDCI.RA';
 v_cust_site_use_rec.site_use_code := 'SHIP_TO';
 v_contact_point_rec.contact_point_type := 'EMAIL';
 v_contact_point_rec.owner_table_name := 'HZ_PARTY_SITES';
 v_contact_point_rec.primary_flag := 'Y' ;
 v_contact_point_rec.contact_point_purpose := 'BUSINESS' ;
 v_contact_point_rec.application_id := pi_application_id;
 v_contact_point_rec.status := 'A';
 v_contact_point_rec.primary_by_purpose := 'N';
 v_email_rec.email_format := 'MAILHTML';
 v_cust_account_rec.account_number := pi_account_number;--0112;
 v_cust_account_rec.account_name := pi_account_name;-- nome do cliente
 v_organization_rec.organization_name := UPPER (pi_organization_name);
 v_organization_rec.party_rec.party_number := pi_party_number;-- CNPJ OU CPF
 v_organization_rec.gsa_indicator_flag := pi_gsa_indicator_flag;
 v_organization_rec.organization_name_phonetic := pi_organization_name_phonetic;
 v_location_rec.country := pi_country;
 v_location_rec.city := pi_city;
 v_location_rec.postal_code := pi_postal_code;
 v_location_rec.state := pi_state;
 v_location_rec.address1 := UPPER( pi_logradouro);
 v_location_rec.address2 := UPPER( pi_numero);
 v_location_rec.address3 := UPPER( pi_complemento);
 v_location_rec.address4 := UPPER( pi_bairro);
 v_cust_site_use_rec.location := pi_location;
 v_cust_site_use_rec.primary_salesrep_id := pi_pr_salesrep_id;
 v_location_rec.language := pi_language;
 v_email_rec.email_address := pi_email_address;
 v_cust_acct_site_rec.global_attribute2 := pi_tipo_inscricao;
 v_cust_acct_site_rec.global_attribute3 := pi_numero_inscricao;
 v_cust_acct_site_rec.global_attribute4 := pi_agencia_inscricao;
 v_cust_acct_site_rec.global_attribute5 := pi_digito_inscricao;
 v_cust_acct_site_rec.global_attribute6 := pi_inscricao_estadual;
 v_cust_acct_site_rec.global_attribute7 := pi_inscricao_municipal;
 v_cust_acct_site_rec.global_attribute8 := pi_classe_contribuinte;
 v_cust_acct_site_rec.global_attribute9 := pi_usar_perfil_local;
 v_cust_acct_site_rec.global_attribute10 := pi_numero_suframa;
 v_cust_acct_site_rec.global_attribute11 := pi_indicador_ret_imposto;
 v_cust_acct_site_rec.global_attribute12 := pi_sujeito_cfop_zf;
 v_phone_rec.phone_area_code := pi_phone_area_code;
 v_phone_rec.phone_country_code := pi_phone_country_code;
 v_phone_rec.phone_number := pi_phone_number;

BEGIN

hz_cust_account_v2pub.create_cust_account( p_init_msg_list => 'T',
 p_cust_account_rec => v_cust_account_rec,
 p_organization_rec => v_organization_rec,
 p_customer_profile_rec => v_customer_profile_rec,
 p_create_profile_amt => 'F',
 x_cust_account_id => v_cust_account_id,
 x_account_number => v_account_number,
 x_party_id => v_party_id,
 x_party_number => v_party_number,
 x_profile_id => v_profile_id,
 x_return_status => v_return_status,
 x_msg_count => v_msg_count,
 x_msg_data => v_msg_data );

hz_location_v2pub.create_location( p_init_msg_list => 'T',
 p_do_addr_val => v_location_rec,
 x_location_id => v_location_id,
 x_return_status => v_return_status,
 x_msg_count => v_msg_count,
 x_msg_data => v_msg_data );

hz_party_site_v2pub.create_party_site( p_init_msg_list => 'T',
 p_party_site_rec => v_party_site_rec,
 x_party_site_id => v_party_site_id,
 x_party_site_number => v_party_site_number,
 x_return_status => v_return_status,
 x_msg_count => v_msg_count,
 x_msg_data => v_msg_data );

hz_cust_account_site_v2pub.create_cust_acct_site( p_init_msg_list => 'T',
 p_cust_acct_site_rec => v_cust_acct_site_rec,
 x_cust_acct_site_id => v_cust_acct_site_id,
 x_return_status => v_return_status,
 x_msg_count => v_msg_count,
 x_msg_data => v_msg_data );

hz_contact_point_v2pub.create_contact_point ( p_init_msg_list => 'T' ,
 p_contact_point_rec => v_contact_point_rec,
 p_edi_rec => v_edi_rec ,
 p_email_rec => v_email_rec ,
 p_phone_rec => v_phone_rec ,
 p_telex_rec => v_telex_rec ,
 p_web_rec => v_web_rec ,
 x_contact_point_id => v_contact_point_id ,
 x_return_status => v_return_status ,
 x_msg_count => v_msg_count ,
 x_msg_data => v_msg_data );
 po_return_status := v_return_status;
 po_msg_data := v_msg_data;

END;
 END;

 

Deixe uma resposta

Powered by WordPress.com. Tema: Baskerville 2 por Anders Noren

Acima ↑

%d blogueiros gostam disto: