Skip to content

Commit

Permalink
feat(document_map): make journal uuids readable
Browse files Browse the repository at this point in the history
This commit makes the rest of the UUIDs for records and references in
the journal readable.

Closes #630.
  • Loading branch information
Jonathan Niles committed Oct 6, 2016
1 parent 0aea62c commit cbbd628
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 21 deletions.
4 changes: 2 additions & 2 deletions client/src/partials/journal/journal.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ function JournalController(Journal, Sorting, Grouping, Filtering, Columns, Confi
editableCellTemplate: 'partials/journal/templates/date.edit.html',
enableCellEdit: true
},
{ field : 'hrRecord', displayName : 'TABLE.COLUMNS.RECORD', headerCellFilter: 'translate', visible: true },
{ field : 'description', displayName : 'TABLE.COLUMNS.DESCRIPTION', headerCellFilter: 'translate' },
{ field : 'account_number', displayName : 'TABLE.COLUMNS.ACCOUNT', headerCellFilter: 'translate' },
{ field : 'debit_equiv', displayName : 'TABLE.COLUMNS.DEBIT', headerCellFilter: 'translate', cellTemplate : '/partials/templates/grid/debit_equiv.cell.html' },
Expand All @@ -138,8 +139,7 @@ function JournalController(Journal, Sorting, Grouping, Filtering, Columns, Confi
// @todo this should be formatted showing the debtor/creditor
{ field : 'hrEntity', displayName : 'TABLE.COLUMNS.RECIPIENT', headerCellFilter: 'translate', visible: true},

{ field : 'reference_uuid', displayName : 'TABLE.COLUMNS.REFERENCE', headerCellFilter: 'translate', visible: false },
{ field : 'record_uuid', displayName : 'TABLE.COLUMNS.RECORD', headerCellFilter: 'translate', visible: false },
{ field : 'hrReference', displayName : 'TABLE.COLUMNS.REFERENCE', headerCellFilter: 'translate', visible: true },
{ field : 'user', displayName : 'TABLE.COLUMNS.RESPONSIBLE', headerCellFilter: 'translate', visible: false, enableCellEdit: false },
{ field : 'actions', displayName : '', headerCellFilter: 'translate', visible: true, enableCellEdit: false, cellTemplate: '/partials/journal/templates/actions.cell.html', allowCellFocus: false }
];
Expand Down
31 changes: 16 additions & 15 deletions server/controllers/finance/journal/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/**
* The /journal HTTP API endpoint
*
* @module finance/journal/
*
* @description This module is responsible for handling CRUD operations
* against the `posting journal` table.
*
* @requires lib/db
*/
* The /journal HTTP API endpoint
*
* @module finance/journal/
*
* @description This module is responsible for handling CRUD operations
* against the `posting journal` table.
*
* @requires lib/db
*/

'use strict';

Expand Down Expand Up @@ -71,20 +71,21 @@ function list(req, res, next) {
const sql = `
SELECT BUID(p.uuid) AS uuid, p.project_id, p.fiscal_year_id, p.period_id,
p.trans_id, p.trans_date, BUID(p.record_uuid) AS record_uuid,
p.description, p.account_id, p.debit, p.credit,
dm1.text AS hrRecord, p.description, p.account_id, p.debit, p.credit,
p.debit_equiv, p.credit_equiv, p.currency_id,
BUID(p.entity_uuid) AS entity_uuid, em.text AS hrEntity,
BUID(p.reference_uuid) AS reference_uuid, p.comment, p.origin_id,
p.user_id, p.cc_id, p.pc_id,
pro.abbr, pro.name AS project_name,
per.start_date AS period_start, per.end_date AS period_end,
a.number AS account_number, u.display_name
BUID(p.reference_uuid) AS reference_uuid, dm2.text AS hrReference,
p.comment, p.origin_id, p.user_id, p.cc_id, p.pc_id, pro.abbr,
pro.name AS project_name, per.start_date AS period_start,
per.end_date AS period_end, a.number AS account_number, u.display_name
FROM posting_journal p
JOIN project pro ON pro.id = p.project_id
JOIN period per ON per.id = p.period_id
JOIN account a ON a.id = p.account_id
JOIN user u ON u.id = p.user_id
LEFT JOIN entity_map em ON em.uuid = p.entity_uuid
LEFT JOIN document_map dm1 ON dm1.uuid = p.record_uuid
LEFT JOIN document_map dm2 ON dm2.uuid = p.reference_uuid
ORDER BY p.trans_date DESC;
`;

Expand Down
10 changes: 9 additions & 1 deletion server/models/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -594,8 +594,8 @@ CREATE TABLE `depot` (
UNIQUE KEY `depot_1` (`text`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

DROP TABLE IF EXISTS discount;

DROP TABLE IF EXISTS discount;
CREATE TABLE discount (
`id` SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
`label` VARCHAR(100) NOT NULL,
Expand All @@ -612,6 +612,14 @@ CREATE TABLE discount (
FOREIGN KEY (`account_id`) REFERENCES `account` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


DROP TABLE IF EXISTS `document_map`;
CREATE TABLE `document_map` (
`uuid` BINARY(16) NOT NULL,
`text` TEXT NOT NULL,
PRIMARY KEY (`uuid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

DROP TABLE IF EXISTS `employee`;
CREATE TABLE `employee` (
`id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
Expand Down
37 changes: 36 additions & 1 deletion server/models/triggers.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

DELIMITER $$


-- Patient Triggers

CREATE TRIGGER patient_reference BEFORE INSERT ON patient
Expand All @@ -26,28 +26,62 @@ END$$
CREATE TRIGGER purchase_reference BEFORE INSERT ON purchase
FOR EACH ROW SET NEW.reference = (SELECT IFNULL(MAX(reference) + 1, 1) FROM purchase WHERE purchase.project_id = new.project_id)$$

CREATE TRIGGER purchase_document_map AFTER INSERT ON purchase
FOR EACH ROW BEGIN
INSERT INTO document_map
SELECT new.uuid, CONCAT_WS('.', 'PO', project.abbr, new.reference) FROM project where project.id = new.project_id;
END$$


-- Invoice Triggers

CREATE TRIGGER invoice_reference BEFORE INSERT ON invoice
FOR EACH ROW SET NEW.reference = (SELECT IFNULL(MAX(reference) + 1, 1) FROM invoice WHERE invoice.project_id = new.project_id)$$

CREATE TRIGGER invoice_document_map AFTER INSERT ON invoice
FOR EACH ROW BEGIN
INSERT INTO document_map
SELECT new.uuid, CONCAT_WS('.', 'I', project.abbr, new.reference) FROM project where project.id = new.project_id;
END$$


-- Cash Payment Triggers

CREATE TRIGGER cash_before_insert BEFORE INSERT ON cash
FOR EACH ROW SET NEW.reference = (SELECT IFNULL(MAX(reference) + 1, 1) FROM cash WHERE cash.project_id = new.project_id)$$

CREATE TRIGGER cash_document_map AFTER INSERT ON cash
FOR EACH ROW BEGIN
INSERT INTO document_map
SELECT new.uuid, CONCAT_WS('.', 'CP', project.abbr, new.reference) FROM project where project.id = new.project_id;
END$$


-- Credit Note Triggers
-- @FIXME - why are we still using a credit note table?

CREATE TRIGGER credit_note_before_insert BEFORE INSERT ON credit_note
FOR EACH ROW SET NEW.reference = (SELECT IFNULL(MAX(reference) + 1, 1) FROM credit_note WHERE credit_note.project_id = new.project_id)$$

CREATE TRIGGER credit_note_document_map AFTER INSERT ON credit_note
FOR EACH ROW BEGIN
INSERT INTO document_map
SELECT new.uuid, CONCAT_WS('.', 'CN', project.abbr, new.reference) FROM project where project.id = new.project_id;
END$$


-- Voucher Triggers

CREATE TRIGGER voucher_before_insert BEFORE INSERT ON voucher
FOR EACH ROW SET NEW.reference = (SELECT IFNULL(MAX(reference) + 1, 1) FROM voucher WHERE voucher.project_id = NEW.project_id)$$

CREATE TRIGGER voucher_document_map AFTER INSERT ON voucher
FOR EACH ROW BEGIN
INSERT INTO document_map
SELECT new.uuid, CONCAT_WS('.', 'V', project.abbr, new.reference) FROM project where project.id = new.project_id;
END$$


-- Employee Triggers

CREATE TRIGGER employee_entity_map AFTER INSERT ON employee
Expand All @@ -58,6 +92,7 @@ FOR EACH ROW BEGIN
INSERT INTO entity_map SELECT new.debtor_uuid, CONCAT_WS('.', 'E', new.id);
END$$


-- Supplier Triggers

CREATE TRIGGER supplier_before_insert BEFORE INSERT ON supplier
Expand Down
4 changes: 2 additions & 2 deletions test/end-to-end/journal/journal.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ const FU = require('../shared/FormUtils');
function JournalConfigurationModal() {
'use strict';

const defaultVisibleColumnCount = 7;
const defaultVisibleColumnCount = 10;
const modifiedVisibleColumnCount = 3;
const page = new JournalCorePage();

it('displays six visible columns by default', () => {
it(`displays ${defaultVisibleColumnCount} visible columns by default`, () => {
page.expectColumnCount(defaultVisibleColumnCount);
});

Expand Down

0 comments on commit cbbd628

Please sign in to comment.