diff --git a/client/src/modules/stock/adjustment/adjustment.html b/client/src/modules/stock/adjustment/adjustment.html deleted file mode 100644 index 2b954ad062..0000000000 --- a/client/src/modules/stock/adjustment/adjustment.html +++ /dev/null @@ -1,152 +0,0 @@ -
-
-
    -
  1. TREE.STOCK
  2. -
  3. - STOCK.ADJUSTMENT -
  4. -
  5. - {{ StockCtrl.depot.text }} - - {{ StockCtrl.adjustmentType}} - -
  6. -
- -
-
- - - - - - - -
-
-
-
- - -
-
-
-
-
- - -
- - - -
- -
-

STOCK.INCREASE_HELP

-
- -
-

STOCK.DECREASE_HELP

-
- - - - - - -
- - -
-
-
-
-
-
- - -
-
- -

- - FORM.INFO.NO_DESTINATION -

- - -
- -
- - - - -
-
- - -
-
- - -
-
-
- - - - FORM.BUTTONS.SUBMIT - -
-
-
-
-
-
diff --git a/client/src/modules/stock/adjustment/adjustment.js b/client/src/modules/stock/adjustment/adjustment.js deleted file mode 100644 index 9dcfe08480..0000000000 --- a/client/src/modules/stock/adjustment/adjustment.js +++ /dev/null @@ -1,275 +0,0 @@ -angular.module('bhima.controllers') - .controller('StockAdjustmentController', StockAdjustmentController); - -// dependencies injections -StockAdjustmentController.$inject = [ - 'NotifyService', 'SessionService', 'util', - 'bhConstants', 'ReceiptModal', 'StockFormService', 'StockService', - 'uiGridConstants', '$translate', -]; - -/** - * @class StockAdjustmentController - * - * @description - * This module exists to make sure that stock can be adjusted up and down as needed. - */ -function StockAdjustmentController( - Notify, Session, util, bhConstants, ReceiptModal, StockForm, - Stock, uiGridConstants, $translate, -) { - const vm = this; - - // global variables - vm.Stock = new StockForm('StockAdjustment'); - vm.movement = {}; - vm.ROW_ERROR_FLAG = bhConstants.grid.ROW_ERROR_FLAG; - - vm.onDateChange = date => { - vm.movement.date = date; - }; - - vm.onChangeDepot = depot => { - vm.depot = depot; - loadInventories(vm.depot); - }; - - // bind constants - vm.enterprise = Session.enterprise; - vm.maxLength = util.maxLength; - vm.maxDate = new Date(); - - // bind methods - vm.addItems = addItems; - vm.removeItem = removeItem; - vm.configureItem = configureItem; - vm.checkValidity = checkValidity; - vm.submit = submit; - vm.handleAdjustmentOption = handleAdjustmentOption; - - // grid columns - const columns = [ - { - field : 'status', - width : 25, - displayName : '', - cellTemplate : 'modules/stock/exit/templates/status.tmpl.html', - }, - - { - field : 'code', - width : 120, - displayName : 'TABLE.COLUMNS.CODE', - headerCellFilter : 'translate', - cellTemplate : 'modules/stock/exit/templates/code.tmpl.html', - }, - - { - field : 'description', - displayName : 'TABLE.COLUMNS.DESCRIPTION', - headerCellFilter : 'translate', - cellTemplate : 'modules/stock/exit/templates/description.tmpl.html', - }, - - { - field : 'lot', - width : 150, - displayName : 'TABLE.COLUMNS.LOT', - headerCellFilter : 'translate', - cellTemplate : 'modules/stock/exit/templates/lot.tmpl.html', - }, - - { - field : 'quantity', - width : 150, - displayName : 'TABLE.COLUMNS.QUANTITY', - headerCellFilter : 'translate', - cellTemplate : 'modules/stock/adjustment/templates/quantity.tmpl.html', - aggregationType : uiGridConstants.aggregationTypes.sum, - }, - - { - field : 'available_lot', - width : 150, - displayName : 'TABLE.COLUMNS.AVAILABLE', - headerCellFilter : 'translate', - cellTemplate : 'modules/stock/exit/templates/available.tmpl.html', - }, - - { - field : 'expiration_date', - width : 150, - displayName : 'TABLE.COLUMNS.EXPIRATION_DATE', - headerCellFilter : 'translate', - cellTemplate : 'modules/stock/exit/templates/expiration.tmpl.html', - }, - - { - field : 'actions', - displayName : '...', - width : 25, - cellTemplate : 'modules/stock/exit/templates/actions.tmpl.html', - }, - ]; - - // grid options - vm.gridOptions = { - appScopeProvider : vm, - enableSorting : false, - enableColumnMenus : false, - columnDefs : columns, - data : vm.Stock.store.data, - fastWatch : true, - flatEntityAccess : true, - rowTemplate : 'modules/templates/grid/error.row.html', - }; - - // add items - function addItems(n) { - vm.Stock.addItems(n); - checkValidity(); - } - - // remove item - function removeItem(item) { - vm.Stock.removeItem(item.id); - checkValidity(); - } - - function handleAdjustmentOption(value) { - vm.adjustmentOption = value; - if (vm.adjustmentOption === 'increase') { - vm.adjustmentType = 'FORM.LABELS.INCREASE'; - } else if (vm.adjustmentOption === 'decrease') { - vm.adjustmentType = 'FORM.LABELS.DECREASE'; - } - - vm.Stock.store.data.forEach(item => { - item.lots = getVisibleLots(item); - }); - } - - /** - * @function getVisibleLots - * - * @description - * Only shows lots with positive quantities if the adjustment option is to decrease - * the quantity in stock. - */ - function getVisibleLots(item) { - return item.lotsFull - .filter(v => (vm.adjustmentOption === 'decrease' ? v.quantity > 0 : true)); - } - - // configure item - function configureItem(item) { - item._initialised = true; - // get lots - Stock.lots.read(null, { depot_uuid : vm.depot.uuid, inventory_uuid : item.inventory.inventory_uuid }) - .then((lots) => { - item.lotsFull = lots; - item.lots = getVisibleLots(item); - }) - .catch(Notify.handleError); - } - - function setupStock() { - vm.Stock.setup(); - vm.Stock.store.clear(); - } - - function startup() { - vm.movement = { - date : new Date(), - entity : {}, - }; - } - - // ============================ Inventories ========================== - function loadInventories(depot) { - setupStock(); - - Stock.inventories.read(null, { depot_uuid : depot.uuid }) - .then((inventories) => { - vm.selectableInventories = angular.copy(inventories); - checkValidity(); - }) - .catch(Notify.handleError); - } - - // check validity - function checkValidity() { - const lotsExists = vm.Stock.store.data.every((item) => { - return item.quantity > 0 && item.lot.uuid; - }); - - vm.validForSubmit = (lotsExists && vm.Stock.store.data.length); - } - - // ================================= Submit ================================ - function submit(form) { - let isExit; - let fluxId; - - // check stock validity - checkValidity(); - - if (form.$invalid) { return 0; } - - if (!vm.validForSubmit || !vm.adjustmentOption) { return 0; } - - if (vm.Stock.hasDuplicatedLots()) { - return Notify.danger('ERRORS.ER_DUPLICATED_LOT', 20000); - } - - let description; - - if (vm.adjustmentOption === 'increase') { - isExit = 0; - fluxId = bhConstants.flux.FROM_ADJUSTMENT; - description = $translate.instant('STOCK.ENTRY_ADJUSTMENT', { - numArticles : vm.Stock.store.data.length, - user : Session.user.display_name, - depot : vm.depot.text, - }); - } else if (vm.adjustmentOption === 'decrease') { - isExit = 1; - fluxId = bhConstants.flux.TO_ADJUSTMENT; - description = $translate.instant('STOCK.EXIT_ADJUSTMENT', { - numArticles : vm.Stock.store.data.length, - user : Session.user.display_name, - depot : vm.depot.text, - }); - } - - const movement = { - depot_uuid : vm.depot.uuid, - entity_uuid : vm.movement.entity.uuid, - date : vm.movement.date, - description : description.concat(' -- ', vm.movement.description || ''), - is_exit : isExit, - flux_id : fluxId, - user_id : Session.user.id, - }; - - const lots = vm.Stock.store.data.map((row) => { - return { - uuid : row.lot.uuid, - quantity : row.quantity, - unit_cost : row.lot.unit_cost, - inventory_uuid : row.lot.inventory_uuid, - }; - }); - - movement.lots = lots; - - return Stock.movements.create(movement) - .then(document => { - vm.Stock.store.clear(); - ReceiptModal.stockAdjustmentReceipt(document.uuid, fluxId); - }) - .catch(Notify.handleError); - } - - startup(); -} diff --git a/client/src/modules/stock/adjustment/templates/quantity.tmpl.html b/client/src/modules/stock/adjustment/templates/quantity.tmpl.html deleted file mode 100644 index ed8f11fcbf..0000000000 --- a/client/src/modules/stock/adjustment/templates/quantity.tmpl.html +++ /dev/null @@ -1,11 +0,0 @@ -
- -
diff --git a/client/src/modules/stock/inventory-adjustment/inventory-adjustment.js b/client/src/modules/stock/inventory-adjustment/inventory-adjustment.js index 6670091c27..d8d24b90c6 100644 --- a/client/src/modules/stock/inventory-adjustment/inventory-adjustment.js +++ b/client/src/modules/stock/inventory-adjustment/inventory-adjustment.js @@ -288,6 +288,10 @@ function StockInventoryAdjustmentController( startup(); return loadInventories(vm.depot); }) + .then(() => { + // reset error handling on the form + form.$setPristine(); + }) .catch(Notify.handleError); } diff --git a/client/src/modules/stock/stock.routes.js b/client/src/modules/stock/stock.routes.js index d491ac3b7d..43a68c7012 100644 --- a/client/src/modules/stock/stock.routes.js +++ b/client/src/modules/stock/stock.routes.js @@ -52,13 +52,6 @@ angular.module('bhima.routes') onExit : ['$uibModalStack', closeModals], }) - .state('stockAdjustment', { - url : '/stock/adjustment', - controller : 'StockAdjustmentController as StockCtrl', - templateUrl : 'modules/stock/adjustment/adjustment.html', - onExit : ['$uibModalStack', closeModals], - }) - .state('stockInventoryAdjustment', { url : '/stock/inventory-adjustment', controller : 'StockInventoryAdjustmentController as StockCtrl', diff --git a/server/controllers/stock/reports/stock/adjustment_receipt.js b/server/controllers/stock/reports/stock/adjustment_receipt.js index aa0a4b1cdc..172d4d57dd 100644 --- a/server/controllers/stock/reports/stock/adjustment_receipt.js +++ b/server/controllers/stock/reports/stock/adjustment_receipt.js @@ -29,12 +29,12 @@ async function stockAdjustmentReceipt(documentUuid, session, options) { l.label, l.expiration_date, d.text AS depot_name, m.flux_id, sal.new_quantity, sal.old_quantity, (sal.new_quantity - sal.old_quantity) AS difference FROM stock_movement m - LEFT JOIN stock_adjustment_log sal ON sal.movement_uuid = m.uuid - JOIN document_map dm ON dm.uuid = m.document_uuid - JOIN lot l ON l.uuid = m.lot_uuid - JOIN inventory i ON i.uuid = l.inventory_uuid - JOIN depot d ON d.uuid = m.depot_uuid - JOIN user u ON u.id = m.user_id + LEFT JOIN stock_adjustment_log sal ON sal.movement_uuid = m.uuid + JOIN document_map dm ON dm.uuid = m.document_uuid + JOIN lot l ON l.uuid = m.lot_uuid + JOIN inventory i ON i.uuid = l.inventory_uuid + JOIN depot d ON d.uuid = m.depot_uuid + JOIN user u ON u.id = m.user_id WHERE m.flux_id IN (${FLUX_TYPE}) AND m.document_uuid = ? `; diff --git a/server/models/bhima.sql b/server/models/bhima.sql index 6efbc981cf..963f27954e 100644 --- a/server/models/bhima.sql +++ b/server/models/bhima.sql @@ -63,7 +63,6 @@ INSERT INTO unit VALUES (163,'Stock Inventory','TREE.STOCK_INVENTORY','The stock inventory registry',160,'/stock/inventories'), (164,'Stock Exit','STOCK.EXIT','The stock exit module',160,'/stock/exit'), (165,'Stock Entry','STOCK.ENTRY','The stock entry module',160,'/stock/entry'), - (167,'Stock Adjustment','STOCK.ADJUSTMENT','The stock adjustment module',160,'/stock/adjustment'), (168,'Aged Creditors','TREE.AGED_CREDITORS','Aged Creditors',281,'/reports/aged_creditors'), (170,'Account Statement','TREE.ACCOUNT_STATEMENT','Account Statement Module',281,'/account_statement'), (180,'Profit & Loss Statement','REPORT.PROFIT_AND_LOSS','The report of income and expenses',281,'/reports/income_expense'), diff --git a/server/models/migrations/next/migrate.sql b/server/models/migrations/next/migrate.sql index ed81caa2e4..ce060e527c 100644 --- a/server/models/migrations/next/migrate.sql +++ b/server/models/migrations/next/migrate.sql @@ -252,4 +252,12 @@ CREATE TABLE IF NOT EXISTS `required_inventory_scan` ( ) ENGINE=InnoDB DEFAULT CHARACTER SET = utf8mb4 DEFAULT COLLATE = utf8mb4_unicode_ci; INSERT IGNORE INTO unit VALUES - (313, 'Inventory Scans Management', 'TREE.REQUIRED_INVENTORY_SCANS', 'Inventory Scans Management', 307, '/required/inventory/scans'); \ No newline at end of file + (313, 'Inventory Scans Management', 'TREE.REQUIRED_INVENTORY_SCANS', 'Inventory Scans Management', 307, '/required/inventory/scans'); + +/** +Issue: 6501 +@author: jniles +@date: 2022-04-06 +*/ +DELETE FROM role WHERE unit_id = 167; +DELETE FROM `unit` WHERE id = 167;