Skip to content

Commit

Permalink
fix(invoice): use bhDateInterval for date searches
Browse files Browse the repository at this point in the history
This commit improves the search modals by using bhDateInterval instead
of custom date pickers.
  • Loading branch information
Jonathan Niles authored and sfount committed Jan 13, 2017
1 parent 828864a commit 8696e6d
Show file tree
Hide file tree
Showing 16 changed files with 131 additions and 187 deletions.
1 change: 1 addition & 0 deletions client/src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,7 @@
"PROJECT" : "Select a Project",
"PROJECTS" : "Select Projects",
"PROVINCE" : "Select a Province",
"PATIENT_GROUP" : "Select a Patient Group",
"REFERENCE" : "Select a Reference",
"REFERENCE_GROUP" : "Select a Reference Group",
"REPORT_TYPE" : "Select a Report Type",
Expand Down
1 change: 1 addition & 0 deletions client/src/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,7 @@
"PRICE_LIST" : "Sélectionner la liste de prix",
"PROFIT_CENTER" : "Sélectionner centre profit",
"PROJECT" : "Sélectionner projet",
"PATIENT_GROUP" : "Sélectionner une groupe des patients",
"PROVINCE" : "Sélectionner une province",
"REFERENCE" : "Sélectionner la Référence",
"REFERENCE_GROUP" : "Sélectionner un groupe de référence",
Expand Down
8 changes: 4 additions & 4 deletions client/src/js/components/bhDateInterval.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ function bhDateInterval(Dates, moment) {
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 }
{ translateKey : 'FORM.LABELS.TODAY', fn : day, range: 'day' },
{ translateKey : 'FORM.LABELS.THIS_WEEK', fn : week, range: 'week' },
{ translateKey : 'FORM.LABELS.THIS_MONTH', fn : month, range: 'month' },
{ translateKey : 'FORM.LABELS.THIS_YEAR', fn : year, range: 'year' }
];

vm.pickerOptions = { showWeeks : false };
Expand Down
22 changes: 6 additions & 16 deletions client/src/js/services/DateService.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
angular.module('bhima.services')
.service('DateService', DateService);
.service('DateService', DateService);

DateService.$inject = [ 'moment' ];

/**
* @class DateService
Expand Down Expand Up @@ -44,7 +46,7 @@ angular.module('bhima.services')
* *NEW*
* Provides a generic date-to-string function that returns a same date string
*/
function DateService() {
function DateService(moment) {
var service = this;

// set up namespaces for date operations
Expand Down Expand Up @@ -249,19 +251,7 @@ function DateService() {
// yet another javascript date string function
// expects a date object
// return 'YYYY-MM-DD' format
service.util.str = function (date) {

// if we pass in a string, return it right away
if (typeof date === 'string') { return date; }

var d = new Date(date),
month = '' + (d.getMonth() + 1),
day = '' + d.getDate(),
year = d.getFullYear();

if (month.length < 2) { month = '0' + month; }
if (day.length < 2) { day = '0' + day; }

return [year, month, day].join('-');
service.util.str = function (date, format) {
return moment(date).format(format || 'YYYY-MM-DD');
};
}
6 changes: 5 additions & 1 deletion client/src/partials/cash/payments/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ function CashPaymentRegistryController(Cash, bhConstants, Notify, Session, uiGri
field : 'description', displayName : 'TABLE.COLUMNS.DESCRIPTION', headerCellFilter: 'translate'
}, {
field : 'amount', displayName : 'TABLE.COLUMNS.AMOUNT', headerCellFilter: 'translate',
cellTemplate : 'partials/cash/payments/templates/amount.grid.html'
cellTemplate : 'partials/cash/payments/templates/amount.grid.html',

// @TODO(jniles): This is temporary, as it doesn't take into account USD payments
aggregationType: uiGridConstants.aggregationTypes.sum, aggregationHideLabel : true,
footerCellFilter: 'currency:' + Session.enterprise.currency_id
}, {
field : 'cashbox_label', displayName : 'TABLE.COLUMNS.CASHBOX', headerCellFilter: 'translate'
}, {
Expand Down
1 change: 1 addition & 0 deletions client/src/partials/patient_invoice/registry/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ function InvoiceRegistryController(Invoices, bhConstants, Notify, Session, util,
if (vm.filters && vm.filters.patientUuid) {
delete vm.filters.patientUuid;
}

vm.filtersFmt = Invoices.formatFilterParameters(vm.filters || {});

load(vm.filters);
Expand Down
91 changes: 19 additions & 72 deletions client/src/partials/patient_invoice/registry/search.modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,88 +7,36 @@

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

<div class="modal-body" style="overflow: auto; max-height: 400px;">

<!-- billing date fieldset -->
<fieldset>
<legend>
{{ "FORM.LABELS.BILLING_DATE" | translate }}
</legend>
<legend translate>FORM.LABELS.BILLING_DATE</legend>

<ul class="list-inline" data-invoice-date>
<li ng-repeat="(key, view) in ModalCtrl.periods track by key">
<a ng-click="ModalCtrl.setDateRange(view.cacheKey)" data-date-range="{{ key }}" href>
{{ ::view.translateKey | translate }}
</a>
</li>
<li class="pull-right">
<a href ng-click="ModalCtrl.clear('date')" tabindex="-1">
<i class="fa fa-eraser"></i> {{ "FORM.BUTTONS.CLEAR" | translate }}
</a>
</li>
</ul>

<div class="row">
<div class="col-md-5">
<div class="input-group">
<input
type="text"
class="form-control"
ng-model="ModalCtrl.params.billingDateFrom"
uib-datepicker-popup="yyyy-MM-dd"
is-open="ModalCtrl.billingDateFromIsOpen"
show-button-bar="false"
>
<span class="input-group-btn">
<button class="btn btn-default" type="button" ng-click="ModalCtrl.billingDateFromIsOpen =! ModalCtrl.billingDateFromIsOpen">
<i class="fa fa-calendar-plus-o"></i>
</button>
</span>
</div>
</div>

<div class="col-md-2 text-center">
<hr />
</div>

<div class="col-md-5">
<div class="input-group">
<input
type="text"
class="form-control"
ng-model="ModalCtrl.params.billingDateTo"
uib-datepicker-popup="yyyy-MM-dd"
is-open="ModalCtrl.billingDateToIsOpen"
show-button-bar="false"
>
<span class="input-group-btn">
<button class="btn btn-default" type="button" ng-click="ModalCtrl.billingDateToIsOpen =! ModalCtrl.billingDateToIsOpen">
<i class="fa fa-calendar-plus-o"></i>
</button>
</span>
</div>
</div>
</div>
<bh-date-interval
validation-trigger="ModalForm.$submitted"
date-from="ModalCtrl.params.billingDateFrom"
date-to="ModalCtrl.params.billingDateTo"
mode="clean">
</bh-date-interval>
</fieldset>

<br />

<!-- invoice details fieldset -->
<fieldset>
<legend>
{{ "FORM.LABELS.INVOICES_DETAILS" | translate }}
</legend>
<legend translate> FORM.LABELS.INVOICES_DETAILS </legend>

<div class="form-group" ng-class="{ 'has-error' : ModalForm.$submitted && ModalForm.reference.$invalid }">
<label class="control-label">{{ 'FORM.LABELS.REFERENCE' | translate }}</label>
<span style="display:inline-block;" class="pull-right">
<a href ng-click="ModalCtrl.clear('reference')" tabindex="-1">
<i class="fa fa-eraser"></i> {{ "FORM.BUTTONS.CLEAR" | translate }}
<i class="fa fa-eraser"></i> <span translate>FORM.BUTTONS.CLEAR</span>
</a>
</span>
<input type="text" class="form-control" name="reference"ng-model="ModalCtrl.params.reference">
Expand All @@ -101,7 +49,7 @@
<label class="control-label">{{ 'FORM.LABELS.SERVICE' | translate }}</label>
<span style="display:inline-block;" class="pull-right">
<a href ng-click="ModalCtrl.clear('service_id')" tabindex="-1">
<i class="fa fa-eraser"></i> {{ "FORM.BUTTONS.CLEAR" | translate }}
<i class="fa fa-eraser"></i> <span translate>FORM.BUTTONS.CLEAR</span>
</a>
</span>
<select
Expand All @@ -117,35 +65,34 @@
<label class="control-label">{{ 'FORM.LABELS.USER' | translate }}</label>
<span style="display:inline-block;" class="pull-right">
<a href ng-click="ModalCtrl.clear('user_id')" tabindex="-1">
<i class="fa fa-eraser"></i> {{ "FORM.BUTTONS.CLEAR" | translate }}
<i class="fa fa-eraser"></i> <span translate>FORM.BUTTONS.CLEAR</span>
</a>
</span>
<select
class="form-control"
name="user"
ng-model="ModalCtrl.params.user_id"
ng-options="u.id as u.display_name for u in ModalCtrl.users | orderBy:'display_name'">
<option value="" disabled>{{ 'FORM.SELECT.USER' | translate }}</option>
<option value="" disabled translate>FORM.SELECT.USER</option>
</select>
</div>

<div class="form-group">
<bh-find-patient
on-search-complete="ModalCtrl.setPatient(patient)"
on-register-api="ModalCtrl.onPatientSearchApiCallback(api)"
validation-trigger="ModalForm.$submitted"
>
validation-trigger="ModalForm.$submitted">
</bh-find-patient>
</div>
</fieldset>
</div>

<div class="modal-footer">
<button type="button" class="btn btn-default" ng-click="ModalCtrl.cancel()">
{{ "FORM.BUTTONS.CLOSE" | translate }}
<button type="button" class="btn btn-default" ng-click="ModalCtrl.cancel()" translate>
FORM.BUTTONS.CLOSE
</button>
<button class="btn btn-default" type="submit" data-method="submit">
{{ "FORM.BUTTONS.SUBMIT" | translate }}
<button class="btn btn-primary" type="submit" data-method="submit" translate>
FORM.BUTTONS.SUBMIT
</button>
</div>
</form>
37 changes: 12 additions & 25 deletions client/src/partials/patient_invoice/registry/search.modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ angular.module('bhima.controllers')
InvoiceRegistrySearchModalController.$inject = [
'$uibModalInstance', 'PatientInvoiceService', 'PatientService',
'ProjectService', 'UserService', 'ServiceService', 'DateService', 'filters',
'NotifyService'
'NotifyService', 'moment'
];

/**
Expand All @@ -15,7 +15,7 @@ InvoiceRegistrySearchModalController.$inject = [
* returning it as a JSON object to the parent controller. The data can be
* preset by passing in a filters object using filtersProvider().
*/
function InvoiceRegistrySearchModalController(ModalInstance, Invoices, Patients, Projects, Users, Services, Dates, filters, Notify) {
function InvoiceRegistrySearchModalController(ModalInstance, Invoices, Patients, Projects, Users, Services, Dates, filters, Notify, moment) {
var vm = this;

// set controller data
Expand All @@ -27,7 +27,6 @@ function InvoiceRegistrySearchModalController(ModalInstance, Invoices, Patients,
vm.submit = submit;
vm.clear = clear;
vm.cancel = function () { ModalInstance.close(); };
vm.setDateRange = setDateRange;
vm.onPatientSearchApiCallback = onPatientSearchApiCallback;
vm.setPatient = setPatient;

Expand Down Expand Up @@ -68,7 +67,16 @@ function InvoiceRegistrySearchModalController(ModalInstance, Invoices, Patients,
function submit(form) {
if (form.$invalid) { return; }

var parameters = vm.params;
var parameters = angular.copy(vm.params);

// convert dates to strings
if (parameters.billingDateFrom) {
parameters.billingDateFrom = Dates.util.str(parameters.billingDateFrom);
}

if (parameters.billingDateTo) {
parameters.billingDateTo = Dates.util.str(parameters.billingDateTo);
}

// make sure we don't have any undefined or empty parameters
angular.forEach(parameters, function (value, key) {
Expand All @@ -80,26 +88,6 @@ function InvoiceRegistrySearchModalController(ModalInstance, Invoices, Patients,
return ModalInstance.close(parameters);
}

// sets the start and end dates of the date input searches
function setDateRange(range) {
// billingDateTo can be at most today
vm.params.billingDateTo = new Date();

switch (range) {
case 'today' :
vm.params.billingDateFrom = Dates.current.day();
break;
case 'week' :
vm.params.billingDateFrom = Dates.previous.week();
break;
case 'month' :
vm.params.billingDateFrom = Dates.previous.month();
break;
default:
vm.params.billingDateFrom = Dates.previous.year();
}
}

// clears search parameters. Custom logic if a date is used so that we can
// clear two properties.
function clear(value) {
Expand All @@ -120,5 +108,4 @@ function InvoiceRegistrySearchModalController(ModalInstance, Invoices, Patients,
vm.params.patientUuid = patient.uuid;
vm.params.patientNames = patient.display_name;
}

}
Loading

0 comments on commit 8696e6d

Please sign in to comment.