Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto fill company / customer form - Autofill VAT number from SIRET if SIRET defined and not VAT #9928

Open
HumanG33k opened this issue Oct 31, 2018 · 2 comments
Labels
Feature request This is a feature request good-first-issue This is a good issue to try make your first PR if you don't know very well the project hacktoberfest This is a good issue to try make your first PR if you don't know very well the project

Comments

@HumanG33k
Copy link

Feature Request

Improve autofill for company form. Autocalculate VAT number from siren.

Use case

User add a company and he prompt the siren and vat is calculate and validate from ue website.
Also Address and name can be autofill to if dolibarr have an internet access. A good practice can be to show some filtering information like ip address/domain name for UE website.

Suggested implementation

I just pick up some javascript code from a website :
Maybe it should be translate in php in order it can be use with no js.

function calcul_tvaint(){
	// Suppression des espaces
	saisie = $("#siren_tvaint").val().replace(/ /g, "");
	
	// Vérification que la saisie contient bien 9 ou 14 chiffres
	if(! /^[0-9]{9}$/.test(saisie) && ! /^[0-9]{14}$/.test(saisie)){
		alert("Veuillez indiquer un numéro SIREN (9 chiffres) ou SIRET (14 chiffres).");
		return;
	}
	
	// Pour la suite, on ne garde que les 9 premiers chiffres (le siren)
	var siren = saisie.substring(0,9);
	
	// Vérification de la validité du siren
	var sommeControle = 0;

	for (var i=1; i<=9; i++) {
		var sommeIntermediaire = parseInt(siren[i-1]) * (((i-1) % 2) + 1);
		if (sommeIntermediaire >= 10) {
			sommeIntermediaire = 1 + (sommeIntermediaire % 10)
		};
		sommeControle += sommeIntermediaire;
	}

	if (sommeControle % 10 != 0) {
		if (/^[0-9]{14}$/.test(saisie)) {
			alert("Le SIRET est invalide : aucune entreprise ne peut avoir ce numéro SIRET. Veuillez vérifier votre saisie.");
			return;
		}
		alert("Le SIREN est invalide : aucune entreprise ne peut avoir ce numéro SIREN. Veuillez vérifier votre saisie.");
		return;
	}
	
	// Calcul du numéro de TVA
	var numTVA = "FR"+((((siren % 97) * 3) + 12) % 97) + "" + siren;
	
	// Affichage du numéro de TVA sur la page
	$("#code_tvaint").val(numTVA);
	$("#resultats").show();
}
@github-actions
Copy link
Contributor

This issue is stale because it has been open 1 year with no activity. If this is a bug, please comment to confirm it is still present on latest stable version. if this is a feature request, please comment to notify the request is still relevant and not yet covered by latest stable version. Without comment, this issue will be closed automatically by stale bot in 15 days.

@github-actions github-actions bot added the Issue Stale (automatic label) This issue is stale because it has been open 1 year with no activity. Remove this label to keep open label Feb 20, 2020
@HumanG33k
Copy link
Author

i not check but for me if not implemented yet is still relevant

@github-actions github-actions bot closed this as completed Mar 6, 2020
@eldy eldy reopened this Mar 7, 2020
@eldy eldy added Feature request This is a feature request and removed Issue Stale (automatic label) This issue is stale because it has been open 1 year with no activity. Remove this label to keep open labels Mar 23, 2020
@eldy eldy reopened this Mar 23, 2020
@eldy eldy changed the title Auto fill company / customer form Auto fill company / customer form - Autofill VAT number from SIRET. Mar 23, 2020
@eldy eldy changed the title Auto fill company / customer form - Autofill VAT number from SIRET. Auto fill company / customer form - Autofill VAT number from SIRET if SIRET defined and not VAT Mar 23, 2020
@eldy eldy added good-first-issue This is a good issue to try make your first PR if you don't know very well the project hacktoberfest This is a good issue to try make your first PR if you don't know very well the project labels Mar 23, 2020
@badre-agtaib badre-agtaib self-assigned this Jun 24, 2022
@badre-agtaib badre-agtaib removed their assignment Oct 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature request This is a feature request good-first-issue This is a good issue to try make your first PR if you don't know very well the project hacktoberfest This is a good issue to try make your first PR if you don't know very well the project
Projects
None yet
Development

No branches or pull requests

3 participants