Skip to content

Commit

Permalink
feat(component) bhperiod, use period translate_key as label
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremielodi committed Jun 8, 2019
1 parent b7cc0d3 commit d061ecc
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 10 deletions.
6 changes: 3 additions & 3 deletions client/src/js/components/bhPeriodSelection.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ angular.module('bhima.components')
});

PeriodSelectionController.$inject = [
'FiscalService', 'moment',
'FiscalService', '$translate',
];

/**
Expand All @@ -24,7 +24,7 @@ PeriodSelectionController.$inject = [
* opening balance period is not displayed. One a period is selected, it is
* returned via the onSelectCallback().
*/
function PeriodSelectionController(Fiscal, moment) {
function PeriodSelectionController(Fiscal, $translate) {
const $ctrl = this;

$ctrl.$onInit = () => {
Expand Down Expand Up @@ -55,7 +55,7 @@ function PeriodSelectionController(Fiscal, moment) {
.then(periods => {
periods.forEach(period => {
// add 2 days to make sure timezone is accounted for
period.hrLabel = moment(period.start_date).add(2, 'days').format('MMMM YYYY');
period.hrLabel = `${$translate.instant(period.translate_key)} ${period.year}`;
});

$ctrl.periods = periods.filter(p => p.number !== 0);
Expand Down
3 changes: 2 additions & 1 deletion server/controllers/finance/fiscal.js
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,8 @@ function closing(req, res, next) {
*/
function getPeriodByFiscal(fiscalYearId) {
const sql = `
SELECT period.number, period.id, period.start_date, period.end_date, period.locked
SELECT period.number, period.id, period.start_date,
period.end_date, period.translate_key, period.year, period.locked
FROM period
WHERE period.fiscal_year_id = ?
AND period.start_date IS NOT NULL
Expand Down
3 changes: 2 additions & 1 deletion server/controllers/finance/period.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ function list(req, res, next) {
const params = req.query;
const filters = new FilterParser(params, { tableAlias : 'p' });
const query = `
SELECT p.id, p.fiscal_year_id, p.number, p.start_date, p.end_date, p.locked
SELECT p.id, p.fiscal_year_id, p.number, p.start_date, p.end_date, p.locked,
p.translate_key, p.year
FROM period p
`;

Expand Down
41 changes: 41 additions & 0 deletions server/models/migrations/next/migrations.sql
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,44 @@ ALTER TABLE invoice_invoicing_fee ADD PRIMARY KEY (invoice_uuid, invoicing_fee_i
* @date: 2019-05-31
*/
ALTER TABLE `service` ADD COLUMN project_id SMALLINT(5) UNSIGNED NOT NULL;


/*
* @author: jeremielodi
* @date: 2019-06-07
*/
ALTER TABLE `period` ADD COLUMN `translate_key` VARCHAR(40) NULL;
ALTER TABLE `period` ADD COLUMN `year` VARCHAR(10) NULL;


DELIMITER $$

DROP PROCEDURE IF EXISTS `UpdatePeriodLabels`$$
CREATE PROCEDURE `UpdatePeriodLabels`()
BEGIN
DECLARE _id mediumint(8) unsigned;
DECLARE _start_date, _end_date DATE;

DECLARE done BOOLEAN;
DECLARE curs1 CURSOR FOR
SELECT id, start_date, end_date FROM period;

DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;

OPEN curs1;
read_loop: LOOP
FETCH curs1 INTO _id, _start_date, _end_date;
IF done THEN
LEAVE read_loop;
END IF;
UPDATE period SET
period.translate_key = CONCAT('TABLE.COLUMNS.DATE_MONTH.', UPPER(DATE_FORMAT(_start_date, "%M"))),
period.year = YEAR(_start_date)
WHERE period.id = _id;
END LOOP;
CLOSE curs1;
END$$
DELIMITER ;

-- update columns
call UpdatePeriodLabels();
30 changes: 30 additions & 0 deletions server/models/procedures/time_period.sql
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,39 @@ BEGIN
END IF;

SET periodNumber = periodNumber + 1;

call UpdatePeriodLabels();
END WHILE;
END $$



DROP PROCEDURE IF EXISTS `UpdatePeriodLabels`$$
CREATE PROCEDURE `UpdatePeriodLabels`()
BEGIN
DECLARE _id mediumint(8) unsigned;
DECLARE _start_date DATE;

DECLARE done BOOLEAN;
DECLARE curs1 CURSOR FOR
SELECT id, start_date FROM period;

DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;

OPEN curs1;
read_loop: LOOP
FETCH curs1 INTO _id, _start_date;
IF done THEN
LEAVE read_loop;
END IF;
UPDATE period SET
period.translate_key = CONCAT('TABLE.COLUMNS.DATE_MONTH.', UPPER(DATE_FORMAT(_start_date, "%M"))),
period.year = YEAR(_start_date)
WHERE period.id = _id;
END LOOP;
CLOSE curs1;
END$$

/*
CALL CloseFiscalYear();
Expand Down
2 changes: 2 additions & 0 deletions server/models/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1295,6 +1295,8 @@ CREATE TABLE `period` (
`start_date` DATE NULL,
`end_date` DATE NULL,
`locked` TINYINT(1) NOT NULL DEFAULT 0,
`translate_key` VARCHAR(40) NULL,
`year` VARCHAR(10) NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `period_1` (`start_date`, `end_date`),
KEY `fiscal_year_id` (`fiscal_year_id`),
Expand Down
4 changes: 2 additions & 2 deletions test/end-to-end/reports/aged_creditors/aged_creditors.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ describe('Aged Creditors Report', () => {
report_name : 'Aged Creditors Report Saved by E2E',
renderer : 'PDF',
year : '2015',
month : 'mai ',
month2 : 'juin',
month : 'Mai 2015',
month2 : 'Juin 2015',
};

before(async () => {
Expand Down
4 changes: 2 additions & 2 deletions test/end-to-end/reports/aged_debtors/aged_debtors.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ describe('Aged Debtors Report', () => {
report_name : 'Aged Debtors Report Saved by E2E',
renderer : 'PDF',
year : '2015',
month : 'mai ',
month2 : 'juin',
month : 'Mai 2015',
month2 : 'Juin 2015',
currency_id : 2,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe('Balance Report', () => {
const key = 'balance_report';

const dataset = {
month : 'juin',
month : 'Juin 2018',
year : '2018',
reportName : 'Balance Report Saved by E2E',
renderer : 'PDF',
Expand Down

0 comments on commit d061ecc

Please sign in to comment.