diff --git a/client/src/js/services/exchange.js b/client/src/js/services/exchange.js deleted file mode 100644 index 92accf69f1..0000000000 --- a/client/src/js/services/exchange.js +++ /dev/null @@ -1,108 +0,0 @@ -angular.module('bhima.services') -.service('exchange', [ - '$timeout', - '$translate', - 'store', - 'appstate', - 'messenger', - 'precision', - 'connect', - function ($timeout, $translate, Store, appstate, messenger, precision, connect) { - // FIXME : this module needs to be able to do - // exchange.setRate() so that it can detect changes - var called = false; - var cfg = {}; - - var DateStore = new Store({ identifier : 'date', data : [] }); - - function normalize (date) { - return date.setHours(0,0,0,0); - } - - function exchange (value, currency_id, date) { - // This function exchanges data from the currency specified by currency_id to - // the enterprise currency on a given date (default: today). - date = date || new Date(); - date = normalize(new Date(date)); - - var store = DateStore.get(date); - if (!store && !called) { // HACK to only show one messenger instance - messenger.danger($translate.instant('EXCHANGE.NO_EXCHANGE_RATE') + new Date(date)); - called = true; - $timeout(function () { called = false; }, 50); - } - - return precision.round(store && store.rates.get(currency_id) ? store.rates.get(currency_id).rate * value : value); - } - - exchange.rate = function rate (value, currency_id, date) { - /* jshint unused : false */ - date = normalize(new Date(date || new Date())); - - var store = DateStore.get(date); - if (!store) { messenger.danger($translate.instant('EXCHANGE.NO_EXCHANGE_RATE') + new Date(date)); } - return precision.round(store && store.rates.get(currency_id) ? store.rates.get(currency_id).rate : 1); - }; - - exchange.hasDailyRate = function hasDailyRate (dateParam) { - - var date = normalize(new Date(dateParam)) || normalize(new Date()); - return !!DateStore.get(date); - }; - - exchange.convertir = function convertir (value, from_currency_id, to_currency_id, date) { - date = new Date(date) || new Date(); - date = normalize(date); - var converter = DateStore.get(date); - if (!converter) { messenger.danger($translate.instant('EXCHANGE.NO_EXCHANGE_RATE') + new Date(date)); return;} - - var from = converter.rates.data.filter(function (item) { - return item.id === from_currency_id; - })[0]; - - var to = converter.rates.data.filter(function (item) { - return item.id === to_currency_id; - })[0]; - - return (value * to.rate) / from.rate; - }; - - function createDailyRateStore(rate) { - var date = normalize(new Date(rate.date)); - var store = DateStore.get(date); - - if (!store) { - DateStore.post({ date : date, rates : new Store({ data : [] }) }); - store = DateStore.get(date); - } - - store.rates.post({ - id : rate.currency_id, - rate : rate.rate, - }); - - store.rates.post({ - id : rate.enterprise_currency_id, - rate: 1 - }); - } - - function loadRates(rates) { - // loads in an array of rates - - rates.forEach(function (rate) { - createDailyRateStore(rate); - }); - } - - function forceRefresh() { - loadRates(appstate.get('exchange_rate')); - } - - exchange.forceRefresh = forceRefresh; - - appstate.register('exchange_rate', loadRates); - - return exchange; - } -]); diff --git a/client/src/partials/exchange/modal.js b/client/src/partials/exchange/modal.js index eef89a9114..af4f1ea6ed 100644 --- a/client/src/partials/exchange/modal.js +++ b/client/src/partials/exchange/modal.js @@ -3,10 +3,10 @@ angular.module('bhima.controllers') ExchangeModalController.$inject = [ 'ExchangeRateService', 'CurrencyService', - 'SessionService', '$uibModalInstance', 'data', 'exchange' + 'SessionService', '$uibModalInstance', 'data' ]; -function ExchangeModalController(Rates, Currencies, Session, $uibModalInstance, data, exchange) { +function ExchangeModalController(Rates, Currencies, Session, $uibModalInstance, data) { var vm = this; // bind variables diff --git a/client/src/partials/stock/loss_record/loss_record.css b/client/src/partials/stock/loss_record/loss_record.css deleted file mode 100644 index 64f0eced7e..0000000000 --- a/client/src/partials/stock/loss_record/loss_record.css +++ /dev/null @@ -1,3 +0,0 @@ -.loss-record-line { - background-color: #ccc; -} \ No newline at end of file diff --git a/client/src/partials/stock/loss_record/loss_record.html b/client/src/partials/stock/loss_record/loss_record.html deleted file mode 100644 index d2b3d334e7..0000000000 --- a/client/src/partials/stock/loss_record/loss_record.html +++ /dev/null @@ -1,115 +0,0 @@ -
- {{ "STOCK.LOSS.LOSS_RECORDS" | translate }} -
- - - -
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
{{'COLUMNS.ENTRY_DATE' | translate}}{{'COLUMNS.LOT_NUMBER' | translate}}{{'COLUMNS.TRACKING_NUMBER' | translate}}{{'COLUMNS.MEDECINE' | translate}}{{'COLUMNS.QTY' | translate}}{{'COLUMNS.UNIT_PRICE' | translate}}{{'COLUMNS.COST' | translate}}{{'COLUMNS.RECEIPT' | translate}}
{{'STOCK.LOSS.NO_LOSS_RECORDS' | translate}}
{{ rec.entry_date | date }}{{ rec.lot_number }}{{ rec.tracking_number }}{{ rec.text }}{{ rec.quantity}}{{ rec.unit_price | currency }}{{ rec.quantity * rec.unit_price | currency}} - - - {{'COLUMNS.RECEIPT' | translate}} - -
-
-
-
- - \ No newline at end of file diff --git a/client/src/partials/stock/loss_record/loss_record.js b/client/src/partials/stock/loss_record/loss_record.js deleted file mode 100644 index 7a0493cbfc..0000000000 --- a/client/src/partials/stock/loss_record/loss_record.js +++ /dev/null @@ -1,213 +0,0 @@ -/* jshint forin: false */ -angular.module('bhima.controllers') -.controller('stock.loss_record', [ - '$scope', - '$timeout', - '$routeParams', - 'util', - 'validate', - 'exchange', - function ($scope, $timeout, $routeParams, util, validate, exchange) { - // TODO add search (filter) - // TODO add sortable (clickable) columns - var dependencies = {}; - - var period = $scope.period = [ - { - key : 'CASH_PAYMENTS.DAY', - method : today - }, - { - key : 'CASH_PAYMENTS.WEEK', - method : week - }, - { - key : 'CASH_PAYMENTS.MONTH', - method : month - } - ]; - - var session = $scope.session = { - param : {}, - searching : true - }; - - var total = $scope.total = {}; - - var depotId = $routeParams.depotId; - - dependencies.loss = { - query : { - identifier : 'uuid', - tables : { - consumption : { columns : ['quantity', 'date', 'uuid'] }, - consumption_loss : { columns : ['document_uuid'] }, - stock : {columns : ['tracking_number', 'lot_number', 'entry_date']}, - inventory : {columns : ['text', 'purchase_price']}, - purchase : { columns : ['purchase_date']}, - purchase_item : { columns : ['unit_price']} - }, - join : [ - 'consumption.uuid=consumption_loss.consumption_uuid', - 'consumption.tracking_number=stock.tracking_number', - 'stock.inventory_uuid=inventory.uuid', - 'stock.purchase_order_uuid=purchase.uuid', - 'purchase.uuid=purchase_item.purchase_uuid', - 'purchase_item.inventory_uuid=inventory.uuid' - ] - } - }; - - init(); - - function init() { - validate.process(dependencies).then(loadProjects); - } - - function loadProjects(model) { - $scope.model = model; - select(period[0]); - } - - function select(period) { - session.selected = period; - period.method(); - } - - function updateSession(model) { - $scope.model = model; - groupingLoss(model.loss.data); - updateTotals(); - session.searching = false; - } - - function reset() { - var request; - - request = { - dateFrom : util.sqlDate(session.param.dateFrom), - dateTo : util.sqlDate(session.param.dateTo), - depotId : depotId - }; - - if (!isNaN(Number(session.project))) { - request.project = session.project; - } - - session.searching = true; - - dependencies.loss = { - query : { - identifier : 'uuid', - tables : { - consumption : { columns : ['quantity', 'date', 'uuid'] }, - consumption_loss : { columns : ['document_uuid'] }, - stock : {columns : ['tracking_number', 'lot_number', 'entry_date']}, - inventory : {columns : ['text', 'purchase_price']}, - purchase : { columns : ['purchase_date']}, - purchase_item : { columns : ['unit_price']} - }, - join : [ - 'consumption.uuid=consumption_loss.consumption_uuid', - 'consumption.tracking_number=stock.tracking_number', - 'stock.inventory_uuid=inventory.uuid', - 'stock.purchase_order_uuid=purchase.uuid', - 'purchase.uuid=purchase_item.purchase_uuid', - 'purchase_item.inventory_uuid=inventory.uuid' - ], - where: ['consumption.depot_uuid=' + request.depotId,'AND','consumption.date>=' + request.dateFrom,'AND','consumption.date<=' + request.dateTo] - } - }; - - total.result = {}; - if ($scope.model.loss) { - $scope.model.loss.data = []; - session.loss = []; - } - validate.refresh(dependencies, ['loss']).then(updateSession); - } - - function today() { - session.param.dateFrom = new Date(); - session.param.dateTo = new Date(); - reset(); - } - - function week() { - session.param.dateFrom = new Date(); - session.param.dateTo = new Date(); - session.param.dateFrom.setDate(session.param.dateTo.getDate() - session.param.dateTo.getDay()); - reset(); - } - - function month() { - session.param.dateFrom = new Date(); - session.param.dateTo = new Date(); - session.param.dateFrom.setDate(1); - reset(); - } - - function updateTotals() { - total.loss = totalLoss(); - total.loss_amount = $scope.model.loss.data.reduce(sum,0); - } - - function sum(a, b) { - return a + (b.unit_price * b.quantity); - } - - function totalLoss() { - return $scope.model.loss.data.length; - } - - function groupingLoss(data){ - // Grouping loss data by document_uuid - // In the case where we have more than one item in a loss document - var lossArray = []; - - data.forEach(function (iItem) { - var newLine = [], - temp = iItem.document_uuid; - - newLine.push(iItem); - - data.forEach(function (jItem) { - - if( data.indexOf(jItem) !== data.indexOf(iItem) ) { - if( jItem.document_uuid === temp ) { - newLine.push(jItem); - } - } - - if( !isInside(newLine, lossArray) ) { - lossArray.push(newLine); - } - - }); - - }); - - session.loss = lossArray; - } - - function isInside(element, tableau){ - var result = false; - - if(element.length && tableau.length){ - for(var i in tableau){ - for(var j in element){ - if(tableau[i][j] && tableau[i][j].document_uuid === element[j].document_uuid){ - result = true; - break; - } - } - } - } - - return result; - } - - $scope.select = select; - $scope.reset = reset; - } -]);