diff --git a/jey_erp/custom_fields.py b/jey_erp/custom_fields.py index 686a0a3..97de3dc 100644 --- a/jey_erp/custom_fields.py +++ b/jey_erp/custom_fields.py @@ -4,15 +4,36 @@ from frappe.custom.doctype.custom_field.custom_field import create_custom_field def create_custom_fields(): custom_fields = { "Asset": [ - # Main Asset Type field + # Asset Category checkboxes + dict( + fieldname='land', + label='Land', + fieldtype='Check', + insert_after='asset_name', + reqd=0, + in_list_view=1, + columns=3 + ), + + dict( + fieldname='property', + label='Property', + fieldtype='Check', + insert_after='land', + reqd=0, + in_list_view=1, + columns=3 + ), + + # Main Asset Type field (initially hidden) dict( fieldname='custom_asset_type', label='Asset Type', fieldtype='Select', - options='\nKənd təsərrüfatı təyinatlı torpaq sahələri\nSənaye, tikinti, nəqliyyat, rabitə, ticarət-məişət xidməti və digər xüsusi təyinatlı torpaq sahələri', - insert_after='asset_name', + options='', # Options will be set dynamically + insert_after='property', reqd=0, - in_list_view=1, + hidden=1, columns=6 ), @@ -121,12 +142,72 @@ def create_custom_fields(): depends_on='eval:doc.custom_asset_type == "Sənaye, tikinti, nəqliyyat, rabitə, ticarət-məişət xidməti və digər xüsusi təyinatlı torpaq sahələri"' ), + # === TAX EXEMPT ASSETS SECTION === + dict( + fieldname='tax_exempt_assets_section', + label='Tax Exempt Assets Information', + fieldtype='Section Break', + insert_after='mining_note', + collapsible=1, + depends_on='eval:doc.custom_asset_type == "Vergidən azad olunan əsas vəsaitlər"' + ), + + dict( + fieldname='tax_exempt_tax_article', + label='Tax Article', + fieldtype='Link', + options='Tax Article', + insert_after='tax_exempt_assets_section', + depends_on='eval:doc.custom_asset_type == "Vergidən azad olunan əsas vəsaitlər"', + reqd=0 + ), + + dict( + fieldname='tax_exempt_settlements', + label='Settlements', + fieldtype='Select', + options='\nBakı\nGəncə, Sumqayıt şəhərləri və Abşeron rayonu\nDigər şəhərlər, rayon mərkəzləri\nRayon tabeliyində olan şəhərlərdə, qəsəbələrdə və kəndlərdə', + insert_after='tax_exempt_tax_article', + depends_on='eval:doc.custom_asset_type == "Vergidən azad olunan əsas vəsaitlər"', + reqd=0 + ), + + # === TAXABLE ASSETS SECTION === + dict( + fieldname='taxable_assets_section', + label='Taxable Assets Information', + fieldtype='Section Break', + insert_after='tax_exempt_settlements', + collapsible=1, + depends_on='eval:doc.custom_asset_type == "Vergiyə cəlb olunan əsas vəsaitlər"' + ), + + dict( + fieldname='taxable_settlements', + label='Settlements', + fieldtype='Select', + options='\nBakı\nGəncə, Sumqayıt şəhərləri və Abşeron rayonu\nDigər şəhərlər, rayon mərkəzləri\nRayon tabeliyində olan şəhərlərdə, qəsəbələrdə və kəndlərdə', + insert_after='taxable_assets_section', + depends_on='eval:doc.custom_asset_type == "Vergiyə cəlb olunan əsas vəsaitlər"', + reqd=0 + ), + + dict( + fieldname='taxable_asset_type', + label='Taxable Asset Type', + fieldtype='Select', + options='\nBinalar, tikililər və qurğular\nÇoxmərtəbəli (çoxmənzilli) yaşayış binalar\nQeyri-yaşayış binaları (sahələri)\nƏmlak kompleksi kimi müəssisələr\nQurğular\nMənzillər\nFərdi yaşayış və bağ evləri\nMaşınlar və avadanlıqlar\nYüksək texnologiyalar məhsulu olan hesablama texnikası\nNəqliyyat vasitələri\nDigər əsas vəsaitlər', + insert_after='taxable_settlements', + depends_on='eval:doc.custom_asset_type == "Vergiyə cəlb olunan əsas vəsaitlər"', + reqd=0 + ), + # === COMMON SECTION (ALWAYS VISIBLE) === dict( fieldname='common_land_section', label='Common Information', fieldtype='Section Break', - insert_after='mining_note', + insert_after='taxable_asset_type', collapsible=1 ), diff --git a/jey_erp/public/js/asset.js b/jey_erp/public/js/asset.js index 9502625..8a879c1 100644 --- a/jey_erp/public/js/asset.js +++ b/jey_erp/public/js/asset.js @@ -3,6 +3,14 @@ frappe.ui.form.on('Asset', { setup_asset_fields(frm); }, + land: function(frm) { + handle_category_checkboxes(frm, 'land'); + }, + + property: function(frm) { + handle_category_checkboxes(frm, 'property'); + }, + custom_asset_type: function(frm) { setup_asset_fields(frm); clear_dependent_fields(frm); @@ -10,19 +18,31 @@ frappe.ui.form.on('Asset', { cadastral_district_name: function(frm) { if (frm.doc.cadastral_district_name) { - frappe.db.get_value('Cadastral Valuation District', - frm.doc.cadastral_district_name, 'district_code') - .then(r => { + frappe.call({ + method: 'frappe.client.get', + args: { + doctype: 'Cadastral Valuation District', + name: frm.doc.cadastral_district_name + }, + callback: function(r) { if (r.message && r.message.district_code) { frm.set_value('cadastral_district_code', r.message.district_code); } - }); + } + }); } else { frm.set_value('cadastral_district_code', ''); } }, validate: function(frm) { + // Check if at least one category is selected + if (!frm.doc.land && !frm.doc.property) { + frappe.msgprint(__('Please select either Land or Property')); + frappe.validated = false; + return; + } + if (!frm.doc.custom_asset_type) { frappe.msgprint(__('Please select an Asset Type')); frappe.validated = false; @@ -62,31 +82,84 @@ frappe.ui.form.on('Asset', { } } } - }, - - + + // Validate tax exempt assets fields + if (frm.doc.custom_asset_type === "Vergidən azad olunan əsas vəsaitlər") { + const required_fields = [ + ['tax_exempt_tax_article', 'Tax Article'], + ['tax_exempt_settlements', 'Settlements'] + ]; + + for (let [field, label] of required_fields) { + if (!frm.doc[field]) { + frappe.msgprint(__(`${label} is required for Tax Exempt Assets`)); + frappe.validated = false; + return; + } + } + } + + // Validate taxable assets fields + if (frm.doc.custom_asset_type === "Vergiyə cəlb olunan əsas vəsaitlər") { + const required_fields = [ + ['taxable_settlements', 'Settlements'], + ['taxable_asset_type', 'Taxable Asset Type'] + ]; + + for (let [field, label] of required_fields) { + if (!frm.doc[field]) { + frappe.msgprint(__(`${label} is required for Taxable Assets`)); + frappe.validated = false; + return; + } + } + } + } }); -function setup_asset_fields(frm) { - const asset_type = frm.doc.custom_asset_type; - - // Hide all conditional sections initially - hide_all_conditional_fields(frm); - - if (!asset_type) { - return; +function handle_category_checkboxes(frm, current_field) { + // Mutual exclusion logic + if (frm.doc[current_field]) { + const other_field = current_field === 'land' ? 'property' : 'land'; + if (frm.doc[other_field]) { + frm.set_value(other_field, 0); + } } - if (asset_type === "Kənd təsərrüfatı təyinatlı torpaq sahələri") { - setup_agricultural_fields(frm); - } else if (asset_type === "Sənaye, tikinti, nəqliyyat, rabitə, ticarət-məişət xidməti və digər xüsusi təyinatlı torpaq sahələri") { - setup_industrial_fields(frm); + // Update Asset Type options and visibility + setup_asset_type_options(frm); + setup_asset_fields(frm); +} + +function setup_asset_type_options(frm) { + let options = '\n'; + + if (frm.doc.land) { + options += 'Kənd təsərrüfatı təyinatlı torpaq sahələri\nSənaye, tikinti, nəqliyyat, rabitə, ticarət-məişət xidməti və digər xüsusi təyinatlı torpaq sahələri'; + } else if (frm.doc.property) { + options += 'Vergidən azad olunan əsas vəsaitlər\nVergiyə cəlb olunan əsas vəsaitlər'; } - // Show common section for both types - show_common_fields(frm); + // Update field options + frm.set_df_property('custom_asset_type', 'options', options); - frm.refresh_fields(); + // Show/hide asset type field + if (frm.doc.land || frm.doc.property) { + frm.set_df_property('custom_asset_type', 'hidden', 0); + frm.set_df_property('custom_asset_type', 'reqd', 1); + } else { + frm.set_df_property('custom_asset_type', 'hidden', 1); + frm.set_df_property('custom_asset_type', 'reqd', 0); + frm.set_value('custom_asset_type', ''); + } +} + +function show_common_fields(frm) { + // Always show common fields + frm.set_df_property('common_land_section', 'hidden', 0); + frm.set_df_property('tax_exempt_area', 'hidden', 0); + frm.set_df_property('tax_exempt_area', 'description', + 'Enter the tax-exempt area in square meters'); } function hide_all_conditional_fields(frm) { @@ -107,17 +180,55 @@ function hide_all_conditional_fields(frm) { 'mining_note' ]; - const common_fields = [ - 'common_land_section', - 'tax_exempt_area' + const tax_exempt_fields = [ + 'tax_exempt_assets_section', + 'tax_exempt_tax_article', + 'tax_exempt_settlements' ]; - [...agricultural_fields, ...industrial_fields, ...common_fields].forEach(fieldname => { + const taxable_fields = [ + 'taxable_assets_section', + 'taxable_settlements', + 'taxable_asset_type' + ]; + + // Hide all conditional fields + [...agricultural_fields, ...industrial_fields, ...tax_exempt_fields, ...taxable_fields].forEach(fieldname => { frm.set_df_property(fieldname, 'hidden', 1); frm.set_df_property(fieldname, 'reqd', 0); }); } +function setup_asset_fields(frm) { + const asset_type = frm.doc.custom_asset_type; + + // Setup asset type options based on category selection + setup_asset_type_options(frm); + + // Hide all conditional sections initially + hide_all_conditional_fields(frm); + + // Always show common fields regardless of asset type selection + show_common_fields(frm); + + if (!asset_type) { + frm.refresh_fields(); + return; + } + + if (asset_type === "Kənd təsərrüfatı təyinatlı torpaq sahələri") { + setup_agricultural_fields(frm); + } else if (asset_type === "Sənaye, tikinti, nəqliyyat, rabitə, ticarət-məişət xidməti və digər xüsusi təyinatlı torpaq sahələri") { + setup_industrial_fields(frm); + } else if (asset_type === "Vergidən azad olunan əsas vəsaitlər") { + setup_tax_exempt_fields(frm); + } else if (asset_type === "Vergiyə cəlb olunan əsas vəsaitlər") { + setup_taxable_fields(frm); + } + + frm.refresh_fields(); +} + function setup_agricultural_fields(frm) { const agricultural_fields = [ 'agricultural_land_section', @@ -183,10 +294,94 @@ function setup_industrial_fields(frm) { 'Check if this relates to mining operations'); } +function setup_tax_exempt_fields(frm) { + const tax_exempt_fields = [ + 'tax_exempt_assets_section', + 'tax_exempt_tax_article', + 'tax_exempt_settlements' + ]; + + tax_exempt_fields.forEach(fieldname => { + frm.set_df_property(fieldname, 'hidden', 0); + }); + + const required_tax_exempt_fields = [ + 'tax_exempt_tax_article', + 'tax_exempt_settlements' + ]; + + required_tax_exempt_fields.forEach(fieldname => { + frm.set_df_property(fieldname, 'reqd', 1); + }); + + // Set filter for tax article field + frm.set_query('tax_exempt_tax_article', function() { + return { + filters: { + 'name': ['in', [ + 'Vergi Məcəlləsinin 199.1-ci maddəsinə əsasən, azaldılmalı əmlak vergisinin məbləği', + 'Vergi Məcəlləsinin 199.4.1-ci maddəsinə əsasən', + 'Vergi Məcəlləsinin 199.4.2-ci maddəsinə əsasən', + 'Vergi Məcəlləsinin 199.4.3-cü maddəsinə əsasən', + 'Vergi Məcəlləsinin 199.4.4-cü maddəsinə əsasən', + 'Vergi Məcəlləsinin 199.4.1-1-ci maddəsinə əsasən', + 'Vergi Məcəlləsinin 199.5-ci maddəsinə əsasən', + 'Vergi Məcəlləsinin 199.7-ci maddəsinə əsasən', + 'Vergi Məcəlləsinin 199.8-ci maddəsinə əsasən', + 'Vergi Məcəlləsinin 199.9-cu maddəsinə əsasən', + 'Vergi Məcəlləsinin 199.11-ci maddəsinə əsasən', + 'Vergi Məcəlləsinin 199.14-cü maddəsinə əsasən', + 'Vergi Məcəlləsinin 199.15-ci maddəsinə əsasən', + 'Vergi Məcəlləsinin 199.16-cı maddəsinə əsasən', + 'Vergi Məcəlləsinin 199.17-ci maddəsinə əsasən', + 'Vergi Məcəlləsinin 199.18-ci maddəsinə əsasən', + 'Vergi Məcəlləsinin 199.19-cu maddəsinə əsasən', + 'Vergi Məcəlləsinin 199.20-ci maddəsinə əsasən', + 'Vergi Məcəlləsinin 227.1-ci maddəsinə əsasən', + 'Qanunla təsdiq olunmuş hasilatın pay bölgüsü haqqında, əsas boru kəməri haqqında və digər bu qəbildən olan sazişlərdə və ya qanunlarda, o cümlədən neft və qaz haqqında, ixrac məqsədli neft-qaz fəaliyyəti üzrə', + 'Xüsusi iqtisadi zonalar haqqında qanunlarda nəzərdə tutulan əmlaklar üzrə', + 'Azərbaycan Respublikasının tərəfdar çıxdığı beynəlxalq müqavilələr üzrə' + ]] + } + }; + }); + + // Set descriptions + frm.set_df_property('tax_exempt_tax_article', 'description', + 'Select the applicable tax article for tax exempt assets'); + frm.set_df_property('tax_exempt_settlements', 'description', + 'Select the settlement type'); +} +function setup_taxable_fields(frm) { + const taxable_fields = [ + 'taxable_assets_section', + 'taxable_settlements', + 'taxable_asset_type' + ]; + + taxable_fields.forEach(fieldname => { + frm.set_df_property(fieldname, 'hidden', 0); + }); + + const required_taxable_fields = [ + 'taxable_settlements', + 'taxable_asset_type' + ]; + + required_taxable_fields.forEach(fieldname => { + frm.set_df_property(fieldname, 'reqd', 1); + }); + + // Set descriptions + frm.set_df_property('taxable_settlements', 'description', + 'Select the settlement type'); + frm.set_df_property('taxable_asset_type', 'description', + 'Select the type of taxable asset'); +} function clear_dependent_fields(frm) { - const all_conditional_fields = [ + const conditional_fields = [ 'agricultural_purpose', 'cadastral_district_name', 'cadastral_district_code', @@ -196,10 +391,14 @@ function clear_dependent_fields(frm) { 'territorial_unit_code', 'industrial_land_purpose', 'mining_note', - 'tax_exempt_area' + 'tax_exempt_tax_article', + 'tax_exempt_settlements', + 'taxable_settlements', + 'taxable_asset_type' ]; - all_conditional_fields.forEach(fieldname => { + // Clear only conditional fields, not common fields like tax_exempt_area + conditional_fields.forEach(fieldname => { frm.set_value(fieldname, ''); }); } \ No newline at end of file