@fleetbase/fleetops-engine
Version:
Fleet & Transport Management Extension for Fleetbase
71 lines (60 loc) • 2.34 kB
JavaScript
import Controller from '@ember/controller';
import { tracked } from '@glimmer/tracking';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';
import { task } from 'ember-concurrency';
export default class ManagementFuelTransactionsIndexDetailsController extends Controller {
fetch;
notifications;
hostRouter;
vehicleId;
orderId;
get normalizedPayloadJson() {
return JSON.stringify(this.model?.normalized_payload ?? {}, null, 2);
}
get rawPayloadJson() {
return JSON.stringify(this.model?.raw_payload ?? {}, null, 2);
}
setVehicleId(event) {
this.vehicleId = event.target.value;
}
setOrderId(event) {
this.orderId = event.target.value;
}
*matchVehicle() {
try {
yield this.fetch.post(`fuel-provider-transactions/${this.model.id}/match-vehicle`, { vehicle: this.vehicleId });
this.notifications.success('Fuel transaction matched to vehicle.');
yield this.hostRouter.refresh();
} catch (error) {
this.notifications.serverError(error);
}
}
*matchOrder() {
try {
yield this.fetch.post(`fuel-provider-transactions/${this.model.id}/match-order`, { order: this.orderId });
this.notifications.success('Fuel transaction matched to order.');
yield this.hostRouter.refresh();
} catch (error) {
this.notifications.serverError(error);
}
}
*reprocess() {
try {
yield this.fetch.post(`fuel-provider-transactions/${this.model.id}/reprocess`);
this.notifications.success('Fuel transaction reprocessed.');
yield this.hostRouter.refresh();
} catch (error) {
this.notifications.serverError(error);
}
}
*review(status) {
try {
yield this.fetch.post(`fuel-provider-transactions/${this.model.id}/review`, { status });
this.notifications.success(status === 'ignored' ? 'Fuel transaction ignored.' : 'Fuel transaction reviewed.');
yield this.hostRouter.refresh();
} catch (error) {
this.notifications.serverError(error);
}
}
}