Skip to content

Commit f015765

Browse files
author
leonardoespinosa
committed
Add establishment points
1 parent 5954d67 commit f015765

File tree

15 files changed

+77
-25
lines changed

15 files changed

+77
-25
lines changed

i4t_web/both/models/points/establishment-point.model.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,16 @@ import { CollectionObject } from '../collection-object.model';
44
* EstablishmentPoints model
55
*/
66
export interface EstablishmentPoint extends CollectionObject {
7-
establishments_ids: string[];
7+
establishments_ids: EstablishmentPointDistribution[];
88
current_points: number;
99
negative_balance: boolean;
1010
negative_advice_counter: number;
11+
}
12+
13+
/**
14+
* Establishment Point Distribution Model
15+
*/
16+
export interface EstablishmentPointDistribution {
17+
establishment_id: string;
18+
points: number;
1119
}

i4t_web/client/imports/app/web/administrator/administration/establishment/establishment/establishment.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
</ul>
5555
<p *ngIf="!establishment.isActive" class="establishment-inactive">{{'RESTAURANT.RESTAURANT_INACTIVE' | translate}}</p>
5656
<p *ngIf="establishment.isActive" class="establishment-active">{{'RESTAURANT.RESTAURANT_ACTIVE' | translate}}</p>
57+
<p class="points">{{getEstablishmentPoints(establishment._id)}} {{'RESTAURANT.AVAILABLE_POINTS' | translate}}</p>
5758
</mat-card-content>
5859
</mat-card>
5960
</div>

i4t_web/client/imports/app/web/administrator/administration/establishment/establishment/establishment.component.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,10 @@
2525
text-align: center;
2626
color: green;
2727
font-weight: 600;
28+
}
29+
30+
.points{
31+
text-align: center;
32+
font-weight: 600;
33+
color: #ef5350;
2834
}

i4t_web/client/imports/app/web/administrator/administration/establishment/establishment/establishment.component.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import { City } from '../../../../../../../../both/models/general/city.model';
1515
import { Cities } from '../../../../../../../../both/collections/general/city.collection';
1616
import { UserDetails } from '../../../../../../../../both/collections/auth/user-detail.collection';
1717
import { UserDetail } from '../../../../../../../../both/models/auth/user-detail.model';
18+
import { EstablishmentPoint } from '../../../../../../../../both/models/points/establishment-point.model';
19+
import { EstablishmentPoints } from '../../../../../../../../both/collections/points/establishment-points.collection';
1820

1921
@Component({
2022
selector: 'establishment',
@@ -31,6 +33,7 @@ export class EstablishmentComponent implements OnInit, OnDestroy {
3133
private countriesSub: Subscription;
3234
private citiesSub: Subscription;
3335
private _usersDetailsSub: Subscription;
36+
private _establishmentPointsSub: Subscription;
3437
private _ngUnsubscribe: Subject<void> = new Subject<void>();
3538

3639
public _dialogRef: MatDialogRef<any>;
@@ -78,6 +81,7 @@ export class EstablishmentComponent implements OnInit, OnDestroy {
7881

7982
});
8083
});
84+
this._establishmentPointsSub = MeteorObservable.subscribe('getEstablishmentPointsByIds', _establishmentIds).takeUntil(this._ngUnsubscribe).subscribe();
8185
});
8286
});
8387
this.countriesSub = MeteorObservable.subscribe('countries').takeUntil(this._ngUnsubscribe).subscribe();
@@ -153,6 +157,19 @@ export class EstablishmentComponent implements OnInit, OnDestroy {
153157
}
154158
}
155159

160+
/**
161+
* Get Establishment Points
162+
* @param {string} _pEstablishmentId
163+
*/
164+
getEstablishmentPoints(_pEstablishmentId: string): number {
165+
let _establishmentPoint: EstablishmentPoint = EstablishmentPoints.findOne({ 'establishments_ids.establishment_id': _pEstablishmentId });
166+
if (_establishmentPoint) {
167+
return _establishmentPoint.establishments_ids.find(est => est.establishment_id === _pEstablishmentId).points;
168+
} else {
169+
return 0;
170+
}
171+
}
172+
156173
/**
157174
* ngOnDestroy implementation
158175
*/

i4t_web/client/imports/app/web/administrator/administration/establishment/register/establishment-register.component.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import { PointValidity } from '../../../../../../../../both/models/general/point
3333
import { PointsValidity } from '../../../../../../../../both/collections/general/point-validity.collection';
3434
import { Parameter } from '../../../../../../../../both/models/general/parameter.model';
3535
import { Parameters } from '../../../../../../../../both/collections/general/parameter.collection';
36-
import { EstablishmentPoint } from '../../../../../../../../both/models/points/establishment-point.model';
36+
import { EstablishmentPoint, EstablishmentPointDistribution } from '../../../../../../../../both/models/points/establishment-point.model';
3737
import { EstablishmentPoints } from '../../../../../../../../both/collections/points/establishment-points.collection';
3838
import { BagPlan } from '../../../../../../../../both/models/points/bag-plan.model';
3939
import { BagPlans } from '../../../../../../../../both/collections/points/bag-plans.collection';
@@ -344,16 +344,16 @@ export class EstablishmentRegisterComponent implements OnInit, OnDestroy {
344344
}
345345
//Insert establishment points
346346
let _lBagPlan: BagPlan = BagPlans.findOne({ _id: "100" });
347-
if (_lBagPlan) {
348-
_lNewEstablishmentPoint = EstablishmentPoints.collection.insert({
349-
establishments_ids: [_lNewEstablishment],
350-
current_points: _lBagPlan.value_points,
351-
negative_balance: false,
352-
negative_advice_counter: 0,
353-
creation_user: this._user,
354-
creation_date: new Date()
355-
});
356-
}
347+
348+
let _pointDistribution: EstablishmentPointDistribution = { establishment_id: _lNewEstablishment, points: _lBagPlan.value_points };
349+
_lNewEstablishmentPoint = EstablishmentPoints.collection.insert({
350+
establishments_ids: [_pointDistribution],
351+
current_points: _lBagPlan.value_points,
352+
negative_balance: false,
353+
negative_advice_counter: 0,
354+
creation_user: this._user,
355+
creation_date: new Date()
356+
});
357357

358358
let pricePoints: PricePoints = {
359359
country_id: _lBagPlan.price.country_id,

i4t_web/client/imports/app/web/administrator/dashboard/dashboard.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<mat-card-header>
33
<img mat-card-avatar *ngIf="establishment.image" src="{{establishment.image.url }}">
44
<img mat-card-avatar *ngIf="!establishment.image" src="/images/default-restaurant.png">
5-
<mat-card-title>{{establishment.name}}</mat-card-title>
5+
<mat-card-title>{{establishment.name}} - {{getEstablishmentPoints(establishment._id)}} {{'ADMIN_DASHBOARD.AVAILABLE_POINTS' | translate}}</mat-card-title>
66
<mat-card-subtitle>{{establishment.address}}</mat-card-subtitle>
77
</mat-card-header>
88

i4t_web/client/imports/app/web/administrator/dashboard/dashboard.component.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,19 @@ export class DashboardComponent implements OnInit, OnDestroy {
122122
return Tables.collection.find({ establishment_id: _pEstablishmentId, status: 'BUSY' }).count();
123123
}
124124

125+
/**
126+
* Get Establishment Points
127+
* @param {string} _pEstablishmentId
128+
*/
129+
getEstablishmentPoints(_pEstablishmentId: string): number {
130+
let _establishmentPoint: EstablishmentPoint = EstablishmentPoints.findOne({ 'establishments_ids.establishment_id': _pEstablishmentId });
131+
if (_establishmentPoint) {
132+
return _establishmentPoint.establishments_ids.find(est => est.establishment_id === _pEstablishmentId).points;
133+
} else {
134+
return 0;
135+
}
136+
}
137+
125138
/**
126139
* Get available items
127140
* @param {string} _pEstablishmentId

i4t_web/client/imports/app/web/administrator/menu/items/creation/item-creation.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ <h3 *ngIf="_showEstablishments">{{'ITEMS.RESTAURANTS_MSG' | translate}}</h3>
8686
<p *ngIf="!_showCurrencies">{{'ITEMS.NO_RESTAURANTS_SELECTED' | translate}}</p>
8787
<p *ngIf="_showCurrencies">{{'ITEMS.ENTER_PRICE' | translate}}</p>
8888
<p *ngIf="_showTaxes">{{'ITEMS.ENTER_TAX' | translate}}</p>
89-
<span *ngFor="let currency of _currencies | async">
89+
<div *ngFor="let currency of _currencies | async">
9090
<div *ngIf="_showCurrencies" formGroupName="currencies" class="currencies">
9191
<div *ngFor="let cur of _establishmentCurrencies">
9292
<mat-form-field *ngIf="currency._id === cur" class="currency">
@@ -105,7 +105,7 @@ <h3 *ngIf="_showEstablishments">{{'ITEMS.RESTAURANTS_MSG' | translate}}</h3>
105105
</mat-form-field>
106106
</div>
107107
</div>
108-
</span>
108+
</div>
109109
</div>
110110
<p *ngIf="_showGeneralError" style="color:red">{{'ITEMS.RESTAURANTS_ITEMS_ERROR' | translate}}</p>
111111
</mat-card-content>

i4t_web/client/imports/app/web/administrator/menu/items/creation/item-creation.component.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ export class ItemCreationComponent implements OnInit, OnDestroy {
142142
ngOnInit() {
143143
this.removeSubscriptions();
144144
let _establishmentsId: string[] = [];
145+
let _currenciesIds: string[] = [];
145146
let _optionIds: string[] = [];
146147

147148
this._sectionsFormGroup = new FormGroup({
@@ -181,11 +182,12 @@ export class ItemCreationComponent implements OnInit, OnDestroy {
181182
this._ngZone.run(() => {
182183
Establishments.collection.find({}).fetch().forEach((res) => {
183184
_establishmentsId.push(res._id);
185+
_currenciesIds.push(res.currencyId);
184186
});
185187
this._countriesSub = MeteorObservable.subscribe('getCountriesByEstablishmentsId', _establishmentsId).takeUntil(this._ngUnsubscribe).subscribe();
186188
this._currenciesSub = MeteorObservable.subscribe('getCurrenciesByEstablishmentsId', _establishmentsId).takeUntil(this._ngUnsubscribe).subscribe(() => {
187189
this._ngZone.run(() => {
188-
this._currencies = Currencies.find({}).zone();
190+
this._currencies = Currencies.find({ _id: { $in: _currenciesIds } }).zone();
189191
});
190192
});
191193
this._optionSub = MeteorObservable.subscribe('optionsByEstablishment', _establishmentsId).takeUntil(this._ngUnsubscribe).subscribe(() => {

i4t_web/client/imports/app/web/administrator/menu/items/edition/item-edition.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ <h3 *ngIf="_showEstablishments">{{'ITEMS.RESTAURANTS_MSG' | translate}}</h3>
9292
<p *ngIf="!_showCurrencies">{{'ITEMS.NO_RESTAURANTS_SELECTED' | translate}}</p>
9393
<p *ngIf="_showCurrencies">{{'ITEMS.ENTER_PRICE' | translate}}</p>
9494
<p *ngIf="_showTaxes">{{'ITEMS.ENTER_TAX' | translate}}</p>
95-
<span *ngFor="let currency of _currencies | async">
95+
<div *ngFor="let currency of _currencies | async">
9696
<div *ngIf="_showCurrencies" formGroupName="editCurrencies" class="currencies">
9797
<div *ngFor="let cur of _establishmentCurrencies">
9898
<mat-form-field *ngIf="currency._id === cur" class="currency">
@@ -111,7 +111,7 @@ <h3 *ngIf="_showEstablishments">{{'ITEMS.RESTAURANTS_MSG' | translate}}</h3>
111111
</mat-form-field>
112112
</div>
113113
</div>
114-
</span>
114+
</div>
115115
</div>
116116
<p *ngIf="_showGeneralError" style="color:red">{{'ITEMS.RESTAURANTS_ITEMS_ERROR' | translate}}</p>
117117
</mat-card>

0 commit comments

Comments
 (0)