From 6f8fb03b57f8c3c5f9a4f44a4b8e5d816b44e88c Mon Sep 17 00:00:00 2001 From: Chris Lomame Date: Thu, 7 Jan 2021 13:44:54 +0100 Subject: [PATCH] improvement(Employee payslip and description in journal) - Addition of the employee's name, on the description of the transaction in posting journal - Adding employee reference to payslip closes #4654 --- .../payroll/multiplePayroll/commitment.js | 18 ++++-- .../multiplePayroll/commitmentFunction.js | 10 ++- .../reports/payslipGenerator.handlebars | 1 + server/models/migrations/next/migrate.sql | 62 +++++++++++++++++++ server/models/procedures/voucher.sql | 2 +- 5 files changed, 87 insertions(+), 6 deletions(-) diff --git a/server/controllers/payroll/multiplePayroll/commitment.js b/server/controllers/payroll/multiplePayroll/commitment.js index 6dc5623a2d..5ff81918b3 100644 --- a/server/controllers/payroll/multiplePayroll/commitment.js +++ b/server/controllers/payroll/multiplePayroll/commitment.js @@ -26,6 +26,10 @@ function commitments(employees, rubrics, rubricsConfig, account, projectId, user const datePeriodTo = moment(account[0].dateTo).format('YYYY-MM-DD'); const labelPayroll = account[0].label; const commitmentUuid = util.uuid(); + + const descriptionCommitment = `ENGAGEMENT DE PAIE [${periodPayroll}]/ ${labelPayroll}`; + const descriptionWithholding = `RETENUE DU PAIEMENT [${periodPayroll}]/ ${labelPayroll}`; + const voucherCommitmentUuid = db.bid(commitmentUuid); const withholdingUuid = util.uuid(); const voucherWithholdingUuid = db.bid(withholdingUuid); @@ -35,6 +39,8 @@ function commitments(employees, rubrics, rubricsConfig, account, projectId, user voucherCommitmentUuid, voucherWithholdingUuid, voucherChargeRemunerationUuid, + descriptionCommitment, + descriptionWithholding, }; const enterpriseChargeRemunerations = []; @@ -113,7 +119,7 @@ function commitments(employees, rubrics, rubricsConfig, account, projectId, user currency_id : currencyId, user_id : userId, type_id : COMMITMENT_TYPE_ID, - description : `ENGAGEMENT DE PAIE [${periodPayroll}]/ ${labelPayroll}`, + description : descriptionCommitment, amount : totalCommitments, }; @@ -124,6 +130,7 @@ function commitments(employees, rubrics, rubricsConfig, account, projectId, user 0, voucherCommitmentUuid, null, + voucherCommitment.description, ]); if (rubricsBenefits.length) { @@ -135,6 +142,7 @@ function commitments(employees, rubrics, rubricsConfig, account, projectId, user 0, voucherCommitmentUuid, null, + voucherCommitment.description, ]); }); } @@ -179,7 +187,7 @@ function commitments(employees, rubrics, rubricsConfig, account, projectId, user currency_id : currencyId, user_id : userId, type_id : WITHHOLDING_TYPE_ID, - description : `RETENUE DU PAIEMENT [${periodPayroll}]/ ${labelPayroll}`, + description : descriptionWithholding, amount : util.roundDecimal(totalWithholdings, 2), }; @@ -191,6 +199,7 @@ function commitments(employees, rubrics, rubricsConfig, account, projectId, user util.roundDecimal(withholding.totals, 2), voucherWithholdingUuid, null, + voucherWithholding.description, ]); }); } @@ -200,7 +209,8 @@ function commitments(employees, rubrics, rubricsConfig, account, projectId, user query : 'INSERT INTO voucher SET ?', params : [voucherCommitment], }, { - query : 'INSERT INTO voucher_item (uuid, account_id, debit, credit, voucher_uuid, entity_uuid) VALUES ?', + query : `INSERT INTO voucher_item + (uuid, account_id, debit, credit, voucher_uuid, entity_uuid, description) VALUES ?`, params : [employeesBenefitsItem], }, { query : 'CALL PostVoucher(?);', @@ -227,7 +237,7 @@ function commitments(employees, rubrics, rubricsConfig, account, projectId, user params : [voucherWithholding], }, { query : `INSERT INTO voucher_item - (uuid, account_id, debit, credit, voucher_uuid, entity_uuid) VALUES ?`, + (uuid, account_id, debit, credit, voucher_uuid, entity_uuid, description) VALUES ?`, params : [employeesWithholdingItem], }, { query : 'CALL PostVoucher(?);', diff --git a/server/controllers/payroll/multiplePayroll/commitmentFunction.js b/server/controllers/payroll/multiplePayroll/commitmentFunction.js index 27a8a5266f..0be07825cc 100644 --- a/server/controllers/payroll/multiplePayroll/commitmentFunction.js +++ b/server/controllers/payroll/multiplePayroll/commitmentFunction.js @@ -18,7 +18,12 @@ function dataCommitment(employees, exchangeRates, rubrics, identificationCommitm let totalCommitments = 0; let totalBasicSalaries = 0; - const { voucherCommitmentUuid, voucherWithholdingUuid } = identificationCommitment; + const { + voucherCommitmentUuid, + voucherWithholdingUuid, + descriptionCommitment, + descriptionWithholding, + } = identificationCommitment; const employeesBenefitsItem = []; const employeesWithholdingItem = []; @@ -57,6 +62,7 @@ function dataCommitment(employees, exchangeRates, rubrics, identificationCommitm conversionGrossSalary, voucherCommitmentUuid, db.bid(employee.creditor_uuid), + `${descriptionCommitment} (${employee.display_name})`, ]); rubrics.forEach(rubric => { @@ -82,6 +88,7 @@ function dataCommitment(employees, exchangeRates, rubrics, identificationCommitm 0, voucherWithholdingUuid, db.bid(employee.creditor_uuid), + `${descriptionWithholding} (${employee.display_name})`, ]); if (employeeWithholdings.length) { @@ -94,6 +101,7 @@ function dataCommitment(employees, exchangeRates, rubrics, identificationCommitm util.roundDecimal(withholding.value, 2), voucherWithholdingUuid, db.bid(employee.creditor_uuid), + `${descriptionWithholding} (${employee.display_name})`, ]); } }); diff --git a/server/controllers/payroll/reports/payslipGenerator.handlebars b/server/controllers/payroll/reports/payslipGenerator.handlebars index d2cc622798..756eac1dd5 100644 --- a/server/controllers/payroll/reports/payslipGenerator.handlebars +++ b/server/controllers/payroll/reports/payslipGenerator.handlebars @@ -17,6 +17,7 @@
{{translate "FORM.LABELS.NAME"}} : {{display_name}}
{{translate "FORM.LABELS.GENDER"}} : {{sex}}
{{translate "FORM.LABELS.CODE"}} : {{code}}
+
{{translate "FORM.LABELS.REFERENCE"}} : {{hrreference}}
{{translate "FORM.LABELS.GRADE"}} : {{text}}
{{translate "FORM.LABELS.DATE_EMBAUCHE"}} : {{date date_embauche}}
{{translate "FORM.LABELS.NB_CHILD"}} : {{nb_enfant}}
diff --git a/server/models/migrations/next/migrate.sql b/server/models/migrations/next/migrate.sql index 37ad68e6fd..85705db8bb 100644 --- a/server/models/migrations/next/migrate.sql +++ b/server/models/migrations/next/migrate.sql @@ -7,3 +7,65 @@ ALTER TABLE `user` ADD COLUMN `updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TI -- reset all last_login information UPDATE `user` SET `last_login` = NULL; + + +/* + * @author: lomamech + * @date: 2021-01-07 + * @subject : Using the description from the voucher_item table in the alternative where it is provided + */ +DELIMITER $$ + +DROP PROCEDURE IF EXISTS PostVoucher$$ + +CREATE PROCEDURE PostVoucher( + IN uuid BINARY(16) +) +BEGIN + DECLARE enterprise_id INT; + DECLARE project_id INT; + DECLARE currency_id INT; + DECLARE date TIMESTAMP; + + -- variables to store core set-up results + DECLARE fiscal_year_id MEDIUMINT(8) UNSIGNED; + DECLARE period_id MEDIUMINT(8) UNSIGNED; + DECLARE current_exchange_rate DECIMAL(19, 8) UNSIGNED; + DECLARE enterprise_currency_id TINYINT(3) UNSIGNED; + DECLARE transaction_id VARCHAR(100); + DECLARE gain_account_id INT UNSIGNED; + DECLARE loss_account_id INT UNSIGNED; + + + DECLARE transIdNumberPart INT; + -- + SELECT p.enterprise_id, p.id, v.currency_id, v.date + INTO enterprise_id, project_id, currency_id, date + FROM voucher AS v JOIN project AS p ON v.project_id = p.id + WHERE v.uuid = uuid; + + -- populate core setup values + CALL PostingSetupUtil(date, enterprise_id, project_id, currency_id, fiscal_year_id, period_id, current_exchange_rate, enterprise_currency_id, transaction_id, gain_account_id, loss_account_id); + + -- make sure the exchange rate is correct + SET current_exchange_rate = GetExchangeRate(enterprise_id, currency_id, date); + SET current_exchange_rate = (SELECT IF(currency_id = enterprise_currency_id, 1, current_exchange_rate)); + + SET transIdNumberPart = GetTransactionNumberPart(transaction_id, project_id); + + -- POST to the posting journal + -- @TODO(sfount) transaction ID number reference should be fetched seperately from full transaction ID to model this relationship better + INSERT INTO posting_journal (uuid, project_id, fiscal_year_id, period_id, + trans_id, trans_id_reference_number, trans_date, record_uuid, description, account_id, debit, + credit, debit_equiv, credit_equiv, currency_id, entity_uuid, + reference_uuid, comment, transaction_type_id, user_id) + SELECT + HUID(UUID()), v.project_id, fiscal_year_id, period_id, transaction_id, transIdNumberPart, v.date, + v.uuid, IF((vi.description IS NULL), v.description, vi.description), vi.account_id, vi.debit, vi.credit, + vi.debit * (1 / current_exchange_rate), vi.credit * (1 / current_exchange_rate), v.currency_id, + vi.entity_uuid, vi.document_uuid, NULL, v.type_id, v.user_id + FROM voucher AS v JOIN voucher_item AS vi ON v.uuid = vi.voucher_uuid + WHERE v.uuid = uuid; + + -- NOTE: this does not handle any rounding - it simply converts the currency as needed. +END $$ diff --git a/server/models/procedures/voucher.sql b/server/models/procedures/voucher.sql index 63ff1250c5..9f9425a80a 100644 --- a/server/models/procedures/voucher.sql +++ b/server/models/procedures/voucher.sql @@ -80,7 +80,7 @@ BEGIN reference_uuid, comment, transaction_type_id, user_id) SELECT HUID(UUID()), v.project_id, fiscal_year_id, period_id, transaction_id, transIdNumberPart, v.date, - v.uuid, v.description, vi.account_id, vi.debit, vi.credit, + v.uuid, IF((vi.description IS NULL), v.description, vi.description), vi.account_id, vi.debit, vi.credit, vi.debit * (1 / current_exchange_rate), vi.credit * (1 / current_exchange_rate), v.currency_id, vi.entity_uuid, vi.document_uuid, NULL, v.type_id, v.user_id FROM voucher AS v JOIN voucher_item AS vi ON v.uuid = vi.voucher_uuid