unserver-unify
Version:
117 lines (113 loc) • 4.74 kB
JavaScript
;
angular.module('bamboo.common').controller('TransactionsCtrl', function($scope, loginService, $uibModal, CommonService, ApiService) {
var self = this;
this.itemNumber = 10;
this.school = loginService.school;
this.icon = 'assets/images/school_logo.jpg';
this.companyname = 'Bamboo Learning';
if(this.school.icon)
{
this.icon = ApiService.SHOST + "/public/" + ApiService.RES + "/school/" + this.school._id + "/" + this.school.icon;
}
if(this.school.name)
{
this.companyname = this.school.name;
}
this.getitems = function(tableState) {
var limit = tableState.pagination.number;
var start = tableState.pagination.start;
var search = tableState.search.predicateObject;
var info = {
start: start,
limit: limit,
sort: tableState.sort,
search: search,
action: 'getmytransactions',
};
console.log(info);
ApiService.post("/transaction", info).then(function(result) {
if (result.data.success) {
$scope.displayedItems = result.data.data.items;
console.log($scope.displayedItems);
angular.forEach($scope.displayedItems, function(student, key) {
// console.log(student);
student.avatar_url = CommonService.getAvatarSrc(student.user);
});
$scope.total = result.data.data.counter;
tableState.pagination.numberOfPages = Math.ceil(result.data.data.counter / limit);
}
});
}
this.previewInvoice = function(_id) {
if (ApiService.school.invoicedoc) {
ApiService.get("/schooldoc/" + ApiService.school.invoicedoc).then(function(result) {
if (result.data.success) {
self.doc = result.data.data;
console.log(self.doc);
if (self.doc) {
var detail = self.doc.detail;
ApiService.get("/transaction/" + _id).then(function(result) {
if (result.data.success) {
var record = result.data.data;
if (!record) {
return;
}
console.log(record);
var fullname = record.user.fullname;
var address = (record.user.address)?record.user.address:'';
var email = record.user.email;
var item = record.type.toUpperCase() + " < " + record.descriptions + " > ";
var description = record.descriptions;
var price = '$' + record.price + 'SGD';
var counter = record.counter;
var total = '$' + record.totalPrice + 'SGD';
var Iid = record._id.toUpperCase();
var date = record.submitTime.substring(0, 10);
console.log(item);
// var date=self.record.
for (var i = 0; i < 3; i++) {
detail = detail.replace('%%logo%%', self.icon);
detail = detail.replace('%%companyname%%', self.companyname);
detail = detail.replace('%%username%%', fullname);
detail = detail.replace('%%item%%', item);
detail = detail.replace('%%description%%', description);
detail = detail.replace('%%date%%', date);
detail = detail.replace('%%address%%', address);
detail = detail.replace('%%invoice%%', Iid);
detail = detail.replace('%%price%%', price);
detail = detail.replace('%%counter%%', counter);
detail = detail.replace('%%total%%', total);
}
console.log(detail);
var conf = {
content:detail,
title: 'Invoice'
}
var modalInstance = $uibModal.open({
animation: true,
ariaLabelledBy: 'modal-title',
ariaDescribedBy: 'modal-body',
templateUrl: 'components/dialog/invoicepreview-dlg.html',
controller: 'InvoicePreviewModalCtrl',
controllerAs: 'ctrl',
size: 'lg',
resolve: {
config: function() {
return conf;
}
}
});
modalInstance.result.then(function(selectedItem) {
//$ctrl.selected = selectedItem;
console.log("---success");
}, function() {
console.log('Modal dismissed at: ' + new Date());
});
}
});
}
}
});
}
};
});