Skip to content

Commit

Permalink
Clean and sanitaze code
Browse files Browse the repository at this point in the history
  • Loading branch information
lomamech committed Jun 21, 2021
1 parent 761d498 commit 478630e
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 19 deletions.
15 changes: 15 additions & 0 deletions client/src/modules/stock/requisition/modals/search.modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,20 @@
</div>
</div>

<div>
<label class="control-label" translate>FORM.LABELS.STATUS</label>
<div class="row">
<div ng-repeat ="r in $ctrl.requisitionStatus | orderBy:'plainText'" class="col-md-6">
<div class="checkbox">
<label>
<input type="checkbox" ng-model="r.checked" ng-true-value="1" ng-false-value="0">
<span ng-class="r.class_style" translate> {{ r.plainText }} </span>
</label>
</div>
</div>
</div>
</div>

<!-- depot -->
<bh-depot-select
depot-uuid="$ctrl.searchQueries.depot_uuid"
Expand All @@ -53,6 +67,7 @@
on-select-callback="$ctrl.onSelectUser(user)">
<bh-clear on-clear="$ctrl.clear('user_id')"></bh-clear>
</bh-user-select>

</div>
</uib-tab>
<uib-tab index="1" heading="{{ 'FORM.LABELS.DEFAULTS' | translate }}" data-default-filter-tab>
Expand Down
27 changes: 25 additions & 2 deletions client/src/modules/stock/requisition/modals/search.modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ angular.module('bhima.controllers')
// dependencies injections
SearchStockRequisitionModalController.$inject = [
'data', 'util', 'Store', '$uibModalInstance', 'PeriodService', 'StockService',
'SearchModalUtilService',
'SearchModalUtilService', 'NotifyService', '$translate',
];

function SearchStockRequisitionModalController(data, util, Store, Instance, Periods, Stock, SearchModal) {
function SearchStockRequisitionModalController(data, util, Store, Instance, Periods, Stock, SearchModal, Notify,
$translate) {
const vm = this;
const changes = new Store({ identifier : 'key' });

Expand Down Expand Up @@ -56,13 +57,35 @@ function SearchStockRequisitionModalController(data, util, Store, Instance, Peri
}
};

// load all Requisition status
Stock.status.read()
.then(statuses => {
statuses.forEach((item) => {
item.plainText = $translate.instant(item.title_key);
item.checked = 0;
});

statuses.sort((a, b) => a.plainText > b.plainText);

vm.requisitionStatus = statuses;
})
.catch(Notify.handleError);

vm.clear = function clear(key) {
delete vm.searchQueries[key];
};

vm.cancel = Instance.dismiss;

vm.submit = function submit() {
vm.searchQueries.status = [];

if (vm.requisitionStatus.length) {
vm.requisitionStatus.forEach(status => {
if (status.checked) vm.searchQueries.status.push(status.id);
});
}

const loggedChanges = SearchModal.getChanges(vm.searchQueries, changes, displayValues, lastDisplayValues);
return Instance.close(loggedChanges);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
<div class="ui-grid-cell-contents">
<span ng-if="row.entity.status_key === 'completed'" class="label label-success" translate> {{ row.entity.title_key }} </span>
<span ng-if="row.entity.status_key === 'done'" class="label label-primary" translate> {{ row.entity.title_key }} </span>
<span ng-if="row.entity.status_key === 'partially'" class="label label-warning" translate> {{ row.entity.title_key }} </span>
<span ng-if="row.entity.status_key === 'in_progress'" class="label label-default" translate> {{ row.entity.title_key }} </span>
<span ng-if="row.entity.status_key === 'cancelled'" class="label label-danger" translate> {{ row.entity.title_key }} </span>
<span ng-if="row.entity.status_key === 'excessive'" class="label label-danger" translate> {{ row.entity.title_key }} </span>
<span ng-class="row.entity.class_style" translate> {{ row.entity.title_key }} </span>
</div>
2 changes: 1 addition & 1 deletion server/controllers/stock/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,7 @@ async function getInventoryMovements(params) {
}

async function listStatus(req, res, next) {
const sql = `SELECT id, status_key, title_key FROM status`;
const sql = `SELECT id, status_key, title_key, class_style FROM status`;
try {
const status = await db.exec(sql);
res.status(200).json(status);
Expand Down
6 changes: 3 additions & 3 deletions server/controllers/stock/requisition/requisition.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ const REQUISITION_STATUS_EXCESSIVE = 7;
const SELECT_QUERY = `
SELECT
BUID(sr.uuid) uuid, BUID(sr.requestor_uuid) requestor_uuid, BUID(sr.depot_uuid) depot_uuid,
sr.requestor_type_id, sr.description, sr.date, sr.user_id, sr.project_id,
sr.requestor_type_id, sr.description, sr.date, sr.user_id, sr.project_id, sr.status_id,
u.display_name AS user_display_name, d.text AS depot_text,
s.name service_requestor, dd.text depot_requestor,
dm.text reference, stat.title_key, stat.status_key
dm.text reference, stat.title_key, stat.status_key, stat.class_style
FROM stock_requisition sr
JOIN user u ON u.id = sr.user_id
JOIN depot d ON d.uuid = sr.depot_uuid
Expand Down Expand Up @@ -121,7 +121,6 @@ function getStockRequisition(params) {
filters.equals('uuid', 'uuid', 'sr');
filters.equals('stock_requisition_uuid', 'uuid', 'sr');
filters.equals('type_id', 'requestor_type_id', 'sr');
filters.equals('status_id', 'status_id', 'sr');
filters.equals('depot_uuid', 'depot_uuid', 'sr');
filters.equals('requestor_uuid', 'requestor_uuid', 'sr');
filters.equals('user_id', 'user_id', 'sr');
Expand All @@ -131,6 +130,7 @@ function getStockRequisition(params) {
filters.period('period', 'date', 'sr');
filters.dateFrom('custom_period_start', 'date', 'sr');
filters.dateTo('custom_period_end', 'date', 'sr');
filters.custom('status', 'sr.status_id IN (?)', [params.status]);
filters.setOrder('ORDER BY sr.date DESC');

const query = filters.applyQuery(SELECT_QUERY);
Expand Down
14 changes: 7 additions & 7 deletions server/models/bhima.sql
Original file line number Diff line number Diff line change
Expand Up @@ -460,13 +460,13 @@ INSERT INTO `survey_form_type` (`id`, `label`, `type`, `is_list`) VALUES

-- application process status
INSERT INTO `status` VALUES
(1, 'in_progress', 'FORM.LABELS.STATUS_TYPE.IN_PROGRESS'),
(2, 'done', 'FORM.LABELS.STATUS_TYPE.DONE'),
(3, 'partially', 'FORM.LABELS.STATUS_TYPE.PARTIALLY'),
(4, 'draft', 'FORM.LABELS.STATUS_TYPE.DRAFT'),
(5, 'cancelled', 'FORM.LABELS.STATUS_TYPE.CANCELLED'),
(6, 'completed', 'FORM.LABELS.STATUS_TYPE.COMPLETED'),
(7, 'excessive', 'FORM.LABELS.STATUS_TYPE.EXCESSIVE_RECEIVED_QUANTITY');
(1, 'in_progress', 'FORM.LABELS.STATUS_TYPE.IN_PROGRESS', 'label label-default'),
(2, 'done', 'FORM.LABELS.STATUS_TYPE.DONE', 'label label-primary'),
(3, 'partially', 'FORM.LABELS.STATUS_TYPE.PARTIALLY', 'label label-warning'),
(4, 'draft', 'FORM.LABELS.STATUS_TYPE.DRAFT', 'label label-info'),
(5, 'cancelled', 'FORM.LABELS.STATUS_TYPE.CANCELLED', 'label label-danger'),
(6, 'completed', 'FORM.LABELS.STATUS_TYPE.COMPLETED', 'label label-success'),
(7, 'excessive', 'FORM.LABELS.STATUS_TYPE.EXCESSIVE_RECEIVED_QUANTITY', 'label label-danger');

-- type of requestors
INSERT INTO `stock_requestor_type` (`type_key`, `title_key`) VALUES
Expand Down
55 changes: 55 additions & 0 deletions server/models/migrations/next/migrate.sql
Original file line number Diff line number Diff line change
@@ -1 +1,56 @@
<<<<<<< HEAD
/* migration file from v1.20.0 to next */
=======
/**
* Inventory tags table
*/
DROP TABLE IF EXISTS `inventory_tag`;
CREATE TABLE `inventory_tag` (
`inventory_uuid` BINARY(16) NOT NULL,
`tag_uuid` BINARY(16) NOT NULL,
FOREIGN KEY (`inventory_uuid`) REFERENCES `inventory` (`uuid`),
FOREIGN KEY (`tag_uuid`) REFERENCES `tags` (`uuid`)
) ENGINE=InnoDB DEFAULT CHARACTER SET = utf8mb4 DEFAULT COLLATE = utf8mb4_unicode_ci;


/**
* @author: jmcameron
* @date: 2021-06-02
*/
INSERT IGNORE INTO `report` (`report_key`, `title_key`) VALUES
('aggregated_stock_consumption', 'REPORT.AGGREGATED_STOCK_CONSUMPTION.TITLE');

INSERT IGNORE INTO `unit` VALUES
(296, 'Agg. Stock Consumption Report','REPORT.AGGREGATED_STOCK_CONSUMPTION.TITLE',
'aggregated consumption', 282, '/reports/aggregated_stock_consumption');


/**
* @author: mbayopanda
* @date: 2021-06-01
*/
INSERT IGNORE INTO `unit` VALUES
(297, 'Journal Log','TREE.JOURNAL_LOG','The Journal log module', 5,'/journal/log');

ALTER TABLE transaction_history ADD COLUMN `value` TEXT DEFAULT NULL;

/* author: jniles
* @date: 2021-06-15
*/
INSERT INTO `actions`(`id`, `description`) VALUES
(8, 'USERS.ACTIONS.EDIT_LOT');

/**
* @author: lomamech
* @date: 2021-06-17
* Requisition status
*/
ALTER TABLE `status` ADD COLUMN `class_style` VARCHAR(100) NOT NULL;

UPDATE status SET class_style = 'label label-default' WHERE id = 1;
UPDATE status SET class_style = 'label label-primary' WHERE id = 2;
UPDATE status SET class_style = 'label label-warning' WHERE id = 3;
UPDATE status SET class_style = 'label label-info' WHERE id = 4;
UPDATE status SET class_style = 'label label-danger' WHERE id = 5;
UPDATE status SET class_style = 'label label-success' WHERE id = 6;
UPDATE status SET class_style = 'label label-danger' WHERE id = 7;
1 change: 1 addition & 0 deletions server/models/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1942,6 +1942,7 @@ CREATE TABLE `status` (
`id` SMALLINT(5) NOT NULL AUTO_INCREMENT,
`status_key` VARCHAR(50) NOT NULL,
`title_key` VARCHAR(100) NOT NULL,
`class_style` VARCHAR(100) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARACTER SET = utf8mb4 DEFAULT COLLATE = utf8mb4_unicode_ci;

Expand Down

0 comments on commit 478630e

Please sign in to comment.