Skip to content

Commit

Permalink
fix(cash): search by today fix
Browse files Browse the repository at this point in the history
This commit fixes the search by today to parse dates correctly in SQL.
  • Loading branch information
Jonathan Niles authored and jniles committed Jan 9, 2017
1 parent 305a470 commit e311f0b
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 33 deletions.
25 changes: 14 additions & 11 deletions client/src/js/components/bhDateInterval.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,24 @@ bhDateInterval.$inject = ['DateService', 'moment'];
function bhDateInterval(Dates, moment) {
var vm = this;

vm.options = [
{ translateKey : 'FORM.LABELS.TODAY', fn : day },
{ translateKey : 'FORM.LABELS.THIS_WEEK', fn : week },
{ translateKey : 'FORM.LABELS.THIS_MONTH', fn : month },
{ translateKey : 'FORM.LABELS.THIS_YEAR', fn : year }
];

vm.pickerOptions = { showWeeks : false };

// expose to the viewe
vm.search = search;
vm.clear = clear;

// start up the modal
startup();
vm.$onInit = function () {

vm.options = [
{ translateKey : 'FORM.LABELS.TODAY', fn : day },
{ translateKey : 'FORM.LABELS.THIS_WEEK', fn : week },
{ translateKey : 'FORM.LABELS.THIS_MONTH', fn : month },
{ translateKey : 'FORM.LABELS.THIS_YEAR', fn : year }
];

vm.pickerOptions = { showWeeks : false };

// start up the modal
startup();
};

function search(selection) {
vm.selected = selection.translateKey;
Expand Down
32 changes: 16 additions & 16 deletions client/src/partials/cash/payments/templates/search.modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

<div class="modal-header">
<ol class="headercrumb">
<li class="static">{{ "FORM.LABELS.PAYMENT" | translate }}</li>
<li class="title">{{ "FORM.LABELS.SEARCH" | translate }}</li>
<li class="static" translate>FORM.LABELS.PAYMENT</li>
<li class="title" translate>FORM.LABELS.SEARCH</li>
</ol>
</div>

Expand All @@ -18,26 +18,25 @@
validation-trigger="!$ctrl.validDateRange"
on-change="$ctrl.validate()"
required="true"
date-from="$ctrl.bundle.dateFrom" date-to="$ctrl.bundle.dateTo" mode="clean">
date-from="$ctrl.bundle.dateFrom"
date-to="$ctrl.bundle.dateTo"
mode="clean">
</bh-date-interval>


<fieldset>
<legend>
{{ "FORM.LABELS.PAYMENT_DETAILS" | translate }}
<span translate>FORM.LABELS.PAYMENT_DETAILS</span>
</legend>

<!-- reference -->
<div class="form-group">
<label class="control-label">
{{ 'FORM.LABELS.REFERENCE' | translate }}
</label>
<label class="control-label" translate>FORM.LABELS.REFERENCE</label>
<input type="text" class="form-control" name="reference" ng-model="$ctrl.bundle.reference">
</div>

<!-- client -->
<div class="form-group">
<label class="control-label">{{ "FORM.LABELS.CLIENT" | translate }}</label>
<label class="control-label" translate>FORM.LABELS.CLIENT</label>

<ui-select name="debtor" ng-model="$ctrl.bundle.debtor_uuid">
<ui-select-match>
Expand All @@ -52,13 +51,13 @@
<div class="checkbox">
<label>
<input type="checkbox" name="is_caution" ng-true-value="1" ng-false-value="0" ng-model="$ctrl.bundle.is_caution">
{{ "FORM.LABELS.CAUTION" | translate }}
<span translate>FORM.LABELS.CAUTION</span>
</label>
</div>

<!-- cashbox -->
<div class="form-group">
<label class="control-label">{{ "FORM.LABELS.CASHBOX" | translate }}</label>
<label class="control-label" translate>FORM.LABELS.CASHBOX</label>

<ui-select name="cashbox" ng-model="$ctrl.bundle.cashbox_id">
<ui-select-match>
Expand All @@ -72,7 +71,9 @@

<!-- user -->
<div class="form-group">
<label class="control-label">{{ "FORM.LABELS.USER" | translate }}</label>
<label class="control-label" translate>
FORM.LABELS.USER
</label>

<ui-select name="user" ng-model="$ctrl.bundle.user_id">
<ui-select-match>
Expand All @@ -90,16 +91,15 @@
</bh-currency-select>

</fieldset>

</div>

<div class="modal-footer">
<button type="button" class="btn btn-default" ng-click="$ctrl.cancel()" data-method="cancel">
{{ "FORM.BUTTONS.CLOSE" | translate }}
<button type="button" class="btn btn-default" ng-click="$ctrl.cancel()" data-method="cancel" translate>
FORM.BUTTONS.CLOSE
</button>

<bh-loading-button loading-state="ModalForm.$loading" disabled="!$ctrl.validDateRange">
{{ "FORM.BUTTONS.SUBMIT" | translate }}
<span translate>FORM.BUTTONS.SUBMIT</span>
</bh-loading-button>
</div>
</form>
3 changes: 1 addition & 2 deletions client/src/partials/cash/payments/templates/search.modal.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
angular.module('bhima.controllers')
.controller('SearchCashPaymentModalController', SearchCashPaymentModalController);
.controller('SearchCashPaymentModalController', SearchCashPaymentModalController);

// dependencies injections
SearchCashPaymentModalController.$inject = [
Expand Down Expand Up @@ -90,5 +90,4 @@ function SearchCashPaymentModalController(Debtors, Users, Cashboxes, Notify, Ins

return out;
}

}
4 changes: 2 additions & 2 deletions server/controllers/finance/cash.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,14 @@ function listPayment(params) {

// load all cash payments from (and including) a certain date
if (params.dateFrom) {
conditions.statements.push('cash.date >= DATE(?)');
conditions.statements.push('DATE(cash.date) >= DATE(?)');
conditions.parameters.push(new Date(params.dateFrom));
delete params.dateFrom;
}

// load all cash payments up to (and including) a certain date
if (params.dateTo) {
conditions.statements.push('cash.date <= DATE(?)');
conditions.statements.push('DATE(cash.date) <= DATE(?)');
conditions.parameters.push(new Date(params.dateTo));
delete params.dateTo;
}
Expand Down
4 changes: 2 additions & 2 deletions server/controllers/finance/cashboxes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ exports.delete = remove;
exports.currencies = currencies;

/**
* @method l;ist
* @method list
*
* @description
* GET /cashboxes
Expand All @@ -49,7 +49,7 @@ function list(req, res, next) {
if (req.query.detailed === '1') {
sql = `
SELECT cash_box.id, label, account_id, transfer_account_id, symbol,
cash_box_account_currency.currency_id
cash_box_account_currency.currency_id
FROM cash_box JOIN cash_box_account_currency ON
cash_box.id = cash_box_account_currency.cash_box_id JOIN currency ON
currency.id = cash_box_account_currency.currency_id
Expand Down

0 comments on commit e311f0b

Please sign in to comment.