Skip to content

Commit

Permalink
feature-of-tax-rate
Browse files Browse the repository at this point in the history
  • Loading branch information
aditya00jangir committed Dec 10, 2024
1 parent d9f9076 commit fff598a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
29 changes: 28 additions & 1 deletion packages/server/src/services/Import/ImportFileMapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import {
} from './interfaces';
import ResourceService from '../Resource/ResourceService';
import { ServiceError } from '@/exceptions';
import { ERRORS } from './_utils';
import { ERRORS,readImportFile } from './_utils';
import { Import } from '@/system/models';
import { parseSheetData } from './sheet_utils';

@Service()
export class ImportFileMapping {
Expand Down Expand Up @@ -40,6 +41,7 @@ export class ImportFileMapping {

// Validate the date format mapping.
this.validateDateFormatMapping(tenantId, importFile.resource, maps);
await this.validateDataForTax(tenantId, importFile);

const mappingStringified = JSON.stringify(maps);

Expand Down Expand Up @@ -162,4 +164,29 @@ export class ImportFileMapping {
}
});
}
private async validateDataForTax(tenantId: number,
importFile: any,
)
{
const buffer = await readImportFile(importFile.filename);
const [sheetData, sheetColumns] = parseSheetData(buffer);
if(importFile.resource === "SaleInvoice")
{
let invoiceNo = "";
let isInvoiceTaxInclusive;
const Count = sheetData.length;
for (let i = 0; i < Count; i++) {
if (sheetData[i]['Amounts Are'])
{
invoiceNo = sheetData[i]['Invoice No.'];
isInvoiceTaxInclusive = sheetData[i]['Amounts Are'];
for (let j = i + 1; j < Count; j++) {
if (invoiceNo === sheetData[j]['Invoice No.'] && isInvoiceTaxInclusive !== sheetData[j]['Amounts Are']) {
throw new ServiceError(ERRORS.AN_INVOICE_CAN_HAVE_ONE_AMOUNT_IN_EITHER_TRUE_OR_FALSE);
}
}
}
}
}
}
}
1 change: 1 addition & 0 deletions packages/server/src/services/Import/_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const ERRORS = {
MAP_DATE_FORMAT_NOT_DEFINED: 'MAP_DATE_FORMAT_NOT_DEFINED',
IMPORTED_SHEET_EMPTY: 'IMPORTED_SHEET_EMPTY',
AMOUNT_ARE_AND_TAX_RATE_ARE_REQUIRED_IF_ANY_ONE_OF_THEM_SELECTED: 'AMOUNT_ARE_AND_TAX_RATE_ARE_REQUIRED_IF_ANY_ONE_OF_THEM_SELECTED',
AN_INVOICE_CAN_HAVE_ONE_AMOUNT_IN_EITHER_TRUE_OR_FALSE:"AN_INVOICE_CAN_HAVE_ONE_AMOUNT_IN_EITHER_TRUE_OR_FALSE",

};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ export function ImportFileMappingForm({
message: 'Amounts Are and Tax Rate are required if any one of them selected',
intent: Intent.DANGER,
});
else if (data.errors.find((e) => e.type === 'AN_INVOICE_CAN_HAVE_ONE_AMOUNT_IN_EITHER_TRUE_OR_FALSE')) {
AppToaster.show({
message: 'An Invoice can have same Amounts In either true or false',
intent: Intent.DANGER,
});
}
setSubmitting(false);
});
};
Expand Down

0 comments on commit fff598a

Please sign in to comment.