<commit_before>/*****************************************************************************/
/* TaxCreate: Event Handlers */
/*****************************************************************************/
import Ladda from 'ladda';
import _ from 'underscore';

Template.TaxCreate.events({
    'click #TaxButton': (e, tmpl) => {
        e.preventDefault();
        let newTaxRuleCode = $('[name="code"]').val();
        let newTaxRuleName = $('[name="name"]').val();

        if(!newTaxRuleCode || newTaxRuleCode.trim().length < 1) {
            swal("Validation error", `Please enter a valid code`, "error");
            return;
        } else if(!newTaxRuleName || newTaxRuleName.trim().length < 1) {
            swal("Validation error", `Please enter a valid name`, "error");
            return;
        }
        let businessId = Session.get('context')
        //--
        let l = Ladda.create(tmpl.$('#TaxButton')[0]);
        l.start();
        let details = null;
        
        let taxableIncomeFormula = $('[name="taxableIncomeFormula"]').val().trim();
        let usingCustomTaxableIncomeFormula;
        if(taxableIncomeFormula && taxableIncomeFormula.length > 0) {
            usingCustomTaxableIncomeFormula = true;
        } else {
            usingCustomTaxableIncomeFormula = false
        }

        if(tmpl.isUsingEffectiveTaxRate.get()) {
            let effectiveTaxRate = $('#effectiveTaxRate').val()
            let effectiveTaxRateAsNumber = parseFloat(effectiveTaxRate)

            details = {
                businessId: businessId,
                code: $('[name="code"]').val(),
                name: $('[name="name"]').val(),
                isUsingEffectiveTaxRate : true,
                effectiveTaxRate: !isNaN(effectiveTaxRateAsNumber) ? effectiveTaxRateAsNumber : 0,
                employees: Core.returnSelection($('[name="employee"]')),
            };
        } else {
            details = {
                businessId: businessId,
                code: $('[name="code"]').val(),
                name: $('[name="name"]').val(),
                isUsingEffectiveTaxRate : false,
                grossIncomeRelief: parseInt($('[name="grossIncomeRelief"]').val()) || 20,
                consolidatedRelief: parseInt($('[name="consolidatedRelief"]').val()) || 200000,
                bucket: $('[name="bucket"]').val(),
                status: $('[name="status"]').val(),
                rules:  tmpl.dict.get("taxRules")
            };

            let grossIncomeBucket = $('[name="grossIncomeBucket"]').val()
            if(grossIncomeBucket && grossIncomeBucket.length > 0) {
                details.grossIncomeBucket = grossIncomeBucket
            }
        }
        details.usingCustomTaxableIncomeFormula = usingCustomTaxableIncomeFormula
        details.taxableIncomeFormula = taxableIncomeFormula        
        //--

        if(tmpl.data){//edit action for updating tax
            const tId = tmpl.data._id;
            const code = tmpl.data.code;
            Meteor.call("tax/update", tId, details, (err, res) => {
                l.stop();
                if(err){
                    swal("Update Failed", `Cannot Update tax ${code}`, "error");
                } else {
                    swal("Successful Update!", `Tax ${code} was updated successfully`, "success");
                    Modal.hide("TaxCreate");
                }
            });
        } else{ //New Action for creating paytype}
            Meteor.call('tax/create', details, (err, res) => {
                l.stop();
                if (res){
                    Modal.hide('TaxCreate');<commit_msg>fix for tax config edit/create<commit_after>/*****************************************************************************/
/* TaxCreate: Event Handlers */
/*****************************************************************************/
import Ladda from 'ladda';
import _ from 'underscore';

Template.TaxCreate.events({
    'click #TaxButton': (e, tmpl) => {
        e.preventDefault();
        let newTaxRuleCode = $('[name="code"]').val();
        let newTaxRuleName = $('[name="name"]').val();

        if(!newTaxRuleCode || newTaxRuleCode.trim().length < 1) {
            swal("Validation error", `Please enter a valid code`, "error");
            return;
        } else if(!newTaxRuleName || newTaxRuleName.trim().length < 1) {
            swal("Validation error", `Please enter a valid name`, "error");
            return;
        }
        let businessId = Session.get('context')
        //--
        let l = Ladda.create(tmpl.$('#TaxButton')[0]);
        l.start();
        let details = null;
        
        if(tmpl.isUsingEffectiveTaxRate.get()) {
            let effectiveTaxRate = $('#effectiveTaxRate').val()
            let effectiveTaxRateAsNumber = parseFloat(effectiveTaxRate)

            details = {
                businessId: businessId,
                code: $('[name="code"]').val(),
                name: $('[name="name"]').val(),
                isUsingEffectiveTaxRate : true,
                effectiveTaxRate: !isNaN(effectiveTaxRateAsNumber) ? effectiveTaxRateAsNumber : 0,
                employees: Core.returnSelection($('[name="employee"]')),
            };
        } else {
            details = {
                businessId: businessId,
                code: $('[name="code"]').val(),
                name: $('[name="name"]').val(),
                isUsingEffectiveTaxRate : false,
                grossIncomeRelief: parseInt($('[name="grossIncomeRelief"]').val()) || 20,
                consolidatedRelief: parseInt($('[name="consolidatedRelief"]').val()) || 200000,
                bucket: $('[name="bucket"]').val(),
                status: $('[name="status"]').val(),
                rules:  tmpl.dict.get("taxRules")
            };

            let grossIncomeBucket = $('[name="grossIncomeBucket"]').val()
            if(grossIncomeBucket && grossIncomeBucket.length > 0) {
                details.grossIncomeBucket = grossIncomeBucket
            }
            //--
            let taxableIncomeFormula = $('[name="taxableIncomeFormula"]').val().trim();
            let usingCustomTaxableIncomeFormula;
            if(taxableIncomeFormula && taxableIncomeFormula.length > 0) {
                usingCustomTaxableIncomeFormula = true;
            } else {
                usingCustomTaxableIncomeFormula = false
            }
    
            details.usingCustomTaxableIncomeFormula = usingCustomTaxableIncomeFormula
            details.taxableIncomeFormula = taxableIncomeFormula
        }
        //--

        if(tmpl.data){//edit action for updating tax
            const tId = tmpl.data._id;
            const code = tmpl.data.code;
            Meteor.call("tax/update", tId, details, (err, res) => {
                l.stop();
                if(err){
                    swal("Update Failed", `Cannot Update tax ${code}`, "error");
                } else {
                    swal("Successful Update!", `Tax ${code} was updated successfully`, "success");
                    Modal.hide("TaxCreate");
                }
            });
        } else{ //New Action for creating paytype}
            Meteor.call('tax/create', details, (err, res) => {
                l.stop();
                if (res){
                    Modal.hide('TaxCreate');
{'fraction_non_alphanumeric': 0.1824268925936048, 'fraction_numerical': 0.0038261820169445205, 'mean_word_length': 1.9812627291242362, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '11058', 'n_tokens_mistral': 2013, 'n_tokens_neox': 1871, 'n_words': 357}