Skip to content

Instantly share code, notes, and snippets.

@AlexMocioi
Created April 8, 2014 21:30
Show Gist options
  • Save AlexMocioi/10195794 to your computer and use it in GitHub Desktop.
Save AlexMocioi/10195794 to your computer and use it in GitHub Desktop.
Dacă aveți nevoie să verificați/extrageți ceva informații de la OpenAPI (cod fiscal)
onBlurCodFiscal: function() {
var localThis = this,
cui = trim(this.findByNume("cui").val());
if ( cui=="" ) return;
$.ajax({
type: 'get',
url: 'servlet/proxyOpenAPI.php',
data: {
cui: cui
},
dataType: 'json',
success: function(firmaInfo) {
// deja am aici datele în obiectul firmaInfo
localThis.findByNume("societate").val(firmaInfo.name);
localThis.findByNume("reg_com").val(firmaInfo.registration_id);
if ( firmaInfo.vat=="1" ) {
localThis.findByNume("platitor_tva").select2("val","D");
}
if ( firmaInfo.vat=="0" ) {
localThis.findByNume("platitor_tva").select2("val","N");
}
if ( firmaInfo.address==null ) firmaInfo.address="";
var bucati = toProperName(trim(firmaInfo.address)).split(" ");
if ( bucati.length>1 ) {
localThis.findByNume("numar_strada").val(bucati.pop());
// am eliminat ultima bucata (sper că era număr)
localThis.findByNume("strada").val(bucati.join(" "));
} else {
localThis.findByNume("strada").val(firmaInfo.address);
}
localThis.findByNume("telefon").val(firmaInfo.phone);
var judet = toProperName(makeSortString(firmaInfo.state));
localThis.findByNume("judet").select2("val",judet);
}
});
}
//URL-ul de mai sus din apelul ajax este la un proxyOpenAPI.php din cauză că situl RECS rulează pe https și nu te poți duce cu JSONP la un http ( OpenAPI este pe http )!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment