Skip to content

Commit

Permalink
fix: [438] Set Financial Report as invalid only if the organization c…
Browse files Browse the repository at this point in the history
…ompleted some of the data
  • Loading branch information
radulescuandrew committed Sep 5, 2024
1 parent 1695b2d commit 00e3789
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class AllowTotalAndEmployeesToBeNull1725518140608
implements MigrationInterface
{
name = 'AllowTotalAndEmployeesToBeNull1725518140608';

/**
* Allow Total and Employees to be null to better reflect if the user has not completed the financials or is just the default value
*/

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "organization_financial" ALTER COLUMN "number_of_employees" DROP NOT NULL`,
);
await queryRunner.query(
`ALTER TABLE "organization_financial" ALTER COLUMN "number_of_employees" DROP DEFAULT`,
);
await queryRunner.query(
`ALTER TABLE "organization_financial" ALTER COLUMN "total" DROP NOT NULL`,
);
await queryRunner.query(
`ALTER TABLE "organization_financial" ALTER COLUMN "total" DROP DEFAULT`,
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "organization_financial" ALTER COLUMN "total" SET DEFAULT '0'`,
);
await queryRunner.query(
`ALTER TABLE "organization_financial" ALTER COLUMN "total" SET NOT NULL`,
);
await queryRunner.query(
`ALTER TABLE "organization_financial" ALTER COLUMN "number_of_employees" SET DEFAULT '0'`,
);
await queryRunner.query(
`ALTER TABLE "organization_financial" ALTER COLUMN "number_of_employees" SET NOT NULL`,
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ export class OrganizationFinancial extends BaseEntity {
@Column({
type: 'integer',
name: 'number_of_employees',
default: 0,
nullable: true,
})
numberOfEmployees: number;

@Column({ type: 'integer', name: 'year' })
year: number;

@Column({ type: 'integer', name: 'total', default: 0 })
@Column({ type: 'integer', name: 'total', nullable: true })
total: number;

@Column({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,21 +148,41 @@ export class OrganizationFinancialService {
];
}

/**
* Determines the status of a financial report based on the organization's input and ANAF data.
*
* @param addedByOrganizationTotal - The total amount entered by the organization (per each category).
* @param anafTotal - The total amount retrieved from ANAF.
* @param isSynced - Whether the report has been synced with ANAF data.
* @returns The status of the financial report.
*/
private determineReportStatus(
addedByOrganizationTotal: number,
anafTotal: number,
isSynced: boolean,
) {
): OrganizationFinancialReportStatus {
// If the organization hasn't entered any data, the report is not completed
if (addedByOrganizationTotal === null) {
return OrganizationFinancialReportStatus.NOT_COMPLETED;
}

// If the report is synced with ANAF data
if (isSynced) {
// If the totals match, the report is completed
if (anafTotal === addedByOrganizationTotal) {
return OrganizationFinancialReportStatus.COMPLETED;
} else {
// If the totals don't match, the report is invalid
return OrganizationFinancialReportStatus.INVALID;
}
} else if (addedByOrganizationTotal !== 0) {
return OrganizationFinancialReportStatus.PENDING;
} else {
return OrganizationFinancialReportStatus.NOT_COMPLETED;
// If not synced but the organization has entered some data, the report is pending
if (addedByOrganizationTotal !== 0) {
return OrganizationFinancialReportStatus.PENDING;
} else {
// If not synced and no data entered, the report is not completed
return OrganizationFinancialReportStatus.NOT_COMPLETED;
}
}
}

Expand Down Expand Up @@ -337,7 +357,7 @@ export class OrganizationFinancialService {
const existingData = curr.data as Object;
let existingTotal = null;

if (curr.data) {
if (existingData) {
existingTotal = Object.keys(existingData).reduce(
(acc, curr) => acc + +existingData[curr],
0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,16 @@ export const OrganizationFinancialTableHeaders: TableColumn<IOrganizationFinanci
{
id: 'numberOfEmployees',
name: <DataTableNameHeader text={translations.employees} />,
selector: (row: IOrganizationFinancial) => row.numberOfEmployees,
selector: (row: IOrganizationFinancial) => row.numberOfEmployees ?? '-',
sortable: true,
minWidth: '8rem',
grow: 0,
},
{
id: 'total',
name: <DataTableNameHeader text={translations.sum} />,
selector: (row: IOrganizationFinancial) => formatCurrency(row?.total),
selector: (row: IOrganizationFinancial) =>
row?.total !== null ? formatCurrency(row?.total) : '-',
sortable: true,
minWidth: '7rem',
grow: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { ANAF_HELPER_LINK } from '../../../../../common/constants/constants';
const ExpenseReportModal = ({
onClose,
readonly,
total = 0,
total,
year,
defaultValue,
onSave,
Expand Down Expand Up @@ -110,9 +110,9 @@ const ExpenseReportModal = ({
</div>
</div>
<div className="mt-6 flex flex-row-reverse">
<span className="sm:text-lg lg:text-xl text-md text-gray-900 font-bold leading-6">{`${formatCurrency(
total,
)} RON`}</span>
<span className="sm:text-lg lg:text-xl text-md text-gray-900 font-bold leading-6">
{total !== null && total !== undefined ? `${formatCurrency(total)} RON` : 'N/A'}
</span>
<span className="sm:text-lg lg:text-xl text-md text-gray-400 font-normal leading-6 px-3">
{t('modal.expense')}
</span>
Expand Down Expand Up @@ -177,16 +177,16 @@ const ExpenseReportModal = ({
{t('modal.defalcat')}
</td>
<td className="sm:whitespace-nowrap py-4 px-3 sm:text-sm lg:text-base text-xs font-bold ">
{`${totalDefalcat} `}
{totalDefalcat !== total && (
{`${totalDefalcat} RON`}
{total !== null && total !== undefined && totalDefalcat !== total && (
<span className="font-medium text-red-600">
{total > totalDefalcat
? `(${formatCurrency(total - totalDefalcat)} RON ${t(
'modal.unallocated',
)})`
'modal.unallocated',
)})`
: `(${formatCurrency(totalDefalcat - total)} RON ${t(
'modal.excess',
)})`}
'modal.excess',
)})`}
</span>
)}
</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const IncomeReportModal = ({
onClose,
readonly,
year,
total = 0,
total,
defaultValue,
onSave,
}: ReportModalProps) => {
Expand Down Expand Up @@ -110,9 +110,9 @@ const IncomeReportModal = ({
</div>
</div>
<div className="mt-6 flex flex-row-reverse">
<span className="sm:text-lg lg:text-xl text-md text-gray-900 font-bold leading-6">{`${formatCurrency(
total,
)} RON`}</span>
<span className="sm:text-lg lg:text-xl text-md text-gray-900 font-bold leading-6">
{total !== null && total !== undefined ? `${formatCurrency(total)} RON` : 'N/A'}
</span>
<span className="sm:text-lg lg:text-xl text-md text-gray-400 font-normal leading-6 px-3">
{t('modal.income')}
</span>
Expand Down Expand Up @@ -178,15 +178,15 @@ const IncomeReportModal = ({
</td>
<td className="sm:whitespace-nowrap py-4 px-3 sm:text-sm lg:text-base text-xs font-bold ">
{`${totalDefalcat} `}
{totalDefalcat !== total && (
{total !== null && total !== undefined && totalDefalcat !== total && (
<span className="font-medium text-red-600">
{total > totalDefalcat
? `(${formatCurrency(total - totalDefalcat)} RON ${t(
'modal.unallocated',
)})`
'modal.unallocated',
)})`
: `(${formatCurrency(totalDefalcat - total)} RON ${t(
'modal.excess',
)})`}
'modal.excess',
)})`}
</span>
)}
</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import { FinancialType } from '../enums/FinancialType.enum';

export interface IOrganizationFinancial extends BaseEntity {
type: FinancialType;
numberOfEmployees: number;
numberOfEmployees: number | null;
year: number;
total: number;
total: number | null;
synched_anaf: boolean;
data: Partial<Income> | Partial<Expense> | null;
status: CompletionStatus;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Income } from './Income.interface';
export interface ReportModalProps {
onClose: () => void;
year?: number;
total?: number;
total?: number | null;
readonly?: boolean;
defaultValue?: Partial<Expense> | Partial<Income> | null;
onSave: (data: Partial<Expense> | Partial<Income>) => void;
Expand Down

0 comments on commit 00e3789

Please sign in to comment.