Skip to content

Commit

Permalink
fix: show pan status
Browse files Browse the repository at this point in the history
(cherry picked from commit 6d777b1)
  • Loading branch information
Sanket322 authored and mergify[bot] committed Aug 22, 2024
1 parent b82b334 commit d5b8e27
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 0 deletions.
4 changes: 4 additions & 0 deletions india_compliance/gst_india/client_scripts/party.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,14 @@ function set_gstin_options_and_status(doctype) {
refresh(frm) {
set_gstin_options(frm);
india_compliance.set_gstin_status(frm.get_field("gstin"));
india_compliance.set_pan_status(frm.get_field("pan"));
},
gstin(frm) {
india_compliance.set_gstin_status(frm.get_field("gstin"));
},
pan(frm) {
india_compliance.set_pan_status(frm.get_field("pan"));
},
});
}

Expand Down
70 changes: 70 additions & 0 deletions india_compliance/gst_india/overrides/party.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import json
import random

import requests

import frappe
from frappe import _
Expand Down Expand Up @@ -164,3 +167,70 @@ def make_address(doc):
"is_shipping_address": doc.get("is_shipping_address"),
}
).insert()


multiplication_table = [
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
[1, 2, 3, 4, 0, 6, 7, 8, 9, 5],
[2, 3, 4, 0, 1, 7, 8, 9, 5, 6],
[3, 4, 0, 1, 2, 8, 9, 5, 6, 7],
[4, 0, 1, 2, 3, 9, 5, 6, 7, 8],
[5, 9, 8, 7, 6, 0, 4, 3, 2, 1],
[6, 5, 9, 8, 7, 1, 0, 4, 3, 2],
[7, 6, 5, 9, 8, 2, 1, 0, 4, 3],
[8, 7, 6, 5, 9, 3, 2, 1, 0, 4],
[9, 8, 7, 6, 5, 4, 3, 2, 1, 0],
]

permutation_table = [
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
[1, 5, 7, 6, 2, 8, 3, 0, 9, 4],
[5, 8, 0, 3, 7, 9, 6, 1, 4, 2],
[8, 9, 1, 6, 0, 4, 3, 5, 2, 7],
[9, 4, 5, 3, 1, 2, 6, 8, 7, 0],
[4, 2, 8, 6, 5, 7, 3, 9, 0, 1],
[2, 7, 9, 3, 8, 0, 6, 4, 1, 5],
[7, 0, 4, 6, 9, 1, 3, 2, 5, 8],
]

inverse_table = [0, 4, 3, 2, 1, 5, 6, 7, 8, 9]


def verhoeff_checksum(number: str) -> int:
"""Calculate the Verhoeff checksum digit."""
c = 0
n = len(number)
for i in range(n):
c = multiplication_table[c][
permutation_table[(i + 1) % 8][int(number[n - i - 1])]
]
return inverse_table[c]


def generate_aadhaar_number():
"""Generate a valid Aadhaar number using the Verhoeff algorithm."""
base_number = "".join([str(random.randint(0, 9)) for _ in range(11)])
check_digit = verhoeff_checksum(base_number)
return base_number + str(check_digit)


@frappe.whitelist()
def validate_pancard_status(pan):
aadhaar_number = generate_aadhaar_number()
url = "https://eportal.incometax.gov.in/iec/servicesapi/getEntity"
payload = {
"aadhaarNumber": aadhaar_number,
"pan": pan,
"preLoginFlag": "Y",
"serviceName": "linkAadhaarPreLoginService",
}
response = requests.post(url, json=payload)
messages = response.json().get("messages", [])

if messages and "linked to some other Aadhaar" in messages[0].get("desc", ""):
return "Linked"
elif messages and "PAN does not exist." in messages[0].get("desc", ""):
return "Invalid PAN"
elif messages and "Individual taxpayers" in messages[0].get("desc", ""):
return "Not an Individual Taxpayer"
return ""
20 changes: 20 additions & 0 deletions india_compliance/public/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,26 @@ Object.assign(india_compliance, {
return message;
},

async set_pan_status(field){
const pan = field.value;
if (!pan || pan.length !== 10) return field.set_description("");

const { message } = await frappe.call({
method: "india_compliance.gst_india.overrides.party.validate_pancard_status",
args: { pan },
});

if (!message || message == "") return field.set_description("");

const STATUS_COLORS = { 'Linked': "green", 'Not-Linked': "red", "Not an Individual Taxpayer" : "red",
"Invalid PAN" : "red" };
pan_status = `<div class="d-flex indicator ${STATUS_COLORS[message] || "orange"}">
Status:&nbsp;<strong>${message}</strong>
</div>`;

field.set_description(pan_status);
},

validate_gst_transporter_id(transporter_id) {
if (!transporter_id || transporter_id.length !== 15) return;

Expand Down

0 comments on commit d5b8e27

Please sign in to comment.