1 import {Component, OnInit, Input, ViewChild} from '@angular/core';
2 import {GridComponent} from '@eg/share/grid/grid.component';
3 import {GridDataSource, GridColumn, GridRowFlairEntry} from '@eg/share/grid/grid';
4 import {IdlService} from '@eg/core/idl.service';
5 import {NetService} from '@eg/core/net.service';
6 import {AuthService} from '@eg/core/auth.service';
7 import {OrgService} from '@eg/core/org.service';
8 import {UserDialogComponent} from './user-dialog.component';
13 credit_card_payment = 0;
24 templateUrl: './cash-reports.component.html'
26 export class CashReportsComponent implements OnInit {
28 deskPaymentDataSource: GridDataSource = new GridDataSource();
29 userPaymentDataSource: GridDataSource = new GridDataSource();
30 userDataSource: GridDataSource = new GridDataSource();
31 deskIdlClass = 'mwps';
32 userIdlClass = 'mups';
33 selectedOrg = this.org.get(this.auth.user().ws_ou());
35 startDate = `${this.today.getFullYear()}-${String(this.today.getMonth() + 1).padStart(2, '0')}-${String(this.today.getDate()).padStart(2, '0')}`;
36 endDate = `${this.today.getFullYear()}-${String(this.today.getMonth() + 1).padStart(2, '0')}-${String(this.today.getDate()).padStart(2, '0')}`;
37 deskTotals = new DeskTotals();
38 userTotals = new UserTotals();
40 activeTab = 'deskPayments';
42 // Default sort field, used when no grid sorting is applied.
43 @Input() sortField: string;
44 @ViewChild('userDialog') userDialog: UserDialogComponent;
45 @ViewChild('deskPaymentGrid') deskPaymentGrid: GridComponent;
46 @ViewChild('userPaymentGrid') userPaymentGrid: GridComponent;
47 @ViewChild('userGrid') userGrid: GridComponent;
50 private idl: IdlService,
51 private net: NetService,
52 private org: OrgService,
53 private auth: AuthService) {}
56 this.disabledOrgs = this.getFilteredOrgList();
57 this.searchForData(this.startDate, this.endDate);
60 onRowActivate(userObject) {
61 if (userObject.user && this.userDataSource.data.length === 0) {
62 this.userDataSource.data = [userObject.user];
63 this.showUserInformation();
69 showUserInformation() {
70 return this.userDialog.open({size: 'lg'}).toPromise();
73 searchForData(start, end) {
74 this.userDataSource.data = [];
75 this.fillGridData(this.deskIdlClass, 'deskPaymentDataSource',
78 'open-ils.circ.money.org_unit.desk_payments',
79 this.auth.token(), this.selectedOrg.id(), start, end));
81 this.fillGridData(this.userIdlClass, 'userPaymentDataSource',
84 'open-ils.circ.money.org_unit.user_payments',
85 this.auth.token(), this.selectedOrg.id(), start, end));
88 fillGridData(idlClass, dataSource, data) {
89 data.subscribe((result) => {
90 if (idlClass === this.userIdlClass) {
91 result.forEach((userObject, index) => {
92 result[index].user = userObject.usr();
93 result[index].usr(userObject.usr().usrname());
96 this[dataSource].data = result;
102 this.userDataSource.data = [];
105 getDeskTotal(idlObjects) {
106 this.deskTotals = new DeskTotals();
108 if (idlObjects.length > 0) {
109 const idlObjectFormat = this.idl.create('mwps');
110 idlObjects.forEach((idlObject) => {
111 this.deskTotals['cash_payment'] += parseFloat(idlObject.cash_payment());
112 this.deskTotals['check_payment'] += parseFloat(idlObject.check_payment());
113 this.deskTotals['credit_card_payment'] += parseFloat(idlObject.credit_card_payment());
115 idlObjectFormat.cash_payment(this.deskTotals['cash_payment']);
116 idlObjectFormat.check_payment(this.deskTotals['check_payment']);
117 idlObjectFormat.credit_card_payment(this.deskTotals['credit_card_payment']);
118 return idlObjectFormat;
122 getUserTotal(idlObjects) {
123 this.userTotals = new UserTotals();
124 if (idlObjects.length > 0) {
125 const idlObjectFormat = this.idl.create('mups');
126 idlObjects.forEach((idlObject, index) => {
127 this.userTotals['forgive_payment'] += parseFloat(idlObject.forgive_payment());
128 this.userTotals['work_payment'] += parseFloat(idlObject.work_payment());
129 this.userTotals['credit_payment'] += parseFloat(idlObject.credit_payment());
130 this.userTotals['goods_payment'] += parseFloat(idlObject.goods_payment());
131 this.userDataSource.data = idlObjects[index].usr();
133 idlObjectFormat.forgive_payment(this.userTotals['forgive_payment']);
134 idlObjectFormat.work_payment(this.userTotals['work_payment']);
135 idlObjectFormat.credit_payment(this.userTotals['credit_payment']);
136 idlObjectFormat.goods_payment(this.userTotals['goods_payment']);
137 return idlObjectFormat;
141 getFilteredOrgList() {
142 const orgFilter = {canHaveUsers: false};
143 return this.org.filterList(orgFilter, true);
146 onStartDateChange(date) {
147 this.startDate = date;
150 onEndDateChange(date) {
155 this.selectedOrg = org;
156 this.searchForData(this.startDate, this.endDate);