2018-03-22 17:02:48 +00:00
|
|
|
import ngModule from '../module';
|
2018-04-30 10:48:29 +00:00
|
|
|
import FilterTicketList from '../filter-ticket-list';
|
2018-06-06 14:54:40 +00:00
|
|
|
import './style.scss';
|
2018-03-22 17:02:48 +00:00
|
|
|
|
2018-04-30 10:48:29 +00:00
|
|
|
class Controller extends FilterTicketList {
|
2018-06-06 14:54:40 +00:00
|
|
|
constructor($scope, $timeout, $stateParams, $http, $state, vnApp) {
|
2018-04-30 10:48:29 +00:00
|
|
|
super($scope, $timeout, $stateParams);
|
2018-04-26 14:41:08 +00:00
|
|
|
this.$ = $scope;
|
2018-06-06 14:54:40 +00:00
|
|
|
this.vnApp = vnApp;
|
2018-04-26 14:41:08 +00:00
|
|
|
this.$timeout = $timeout;
|
2018-04-30 10:48:29 +00:00
|
|
|
this.onOrder('itemFk', 'ASC');
|
2018-06-06 14:54:40 +00:00
|
|
|
this.$state = $stateParams;
|
2018-05-08 07:25:15 +00:00
|
|
|
this.$http = $http;
|
2018-06-06 14:54:40 +00:00
|
|
|
this.deletable = false;
|
|
|
|
this.moreOptions = [
|
|
|
|
{callback: this.showAddTurnDialog, name: "Add turn"},
|
|
|
|
{callback: this.showDeleteTicketDialog, name: "Delete ticket"}
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
get isEditable() {
|
|
|
|
try {
|
|
|
|
return !this.ticket.tracking.state.alertLevel;
|
|
|
|
} catch (e) {}
|
|
|
|
|
|
|
|
return true;
|
2018-05-08 07:25:15 +00:00
|
|
|
}
|
|
|
|
|
2018-05-08 07:54:14 +00:00
|
|
|
get isChecked() {
|
|
|
|
let data = this.$.index.model.instances;
|
|
|
|
if (data)
|
|
|
|
for (let instance of data)
|
|
|
|
if (instance.checked)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-06-06 14:54:40 +00:00
|
|
|
getCheckedLines() {
|
|
|
|
let lines = [];
|
|
|
|
let data = this.$.index.model.instances;
|
|
|
|
if (data)
|
|
|
|
for (let i = 0; i < data.length; i++)
|
|
|
|
if (data[i].checked)
|
|
|
|
lines.push({id: data[i].id, instance: i});
|
|
|
|
|
|
|
|
return lines;
|
|
|
|
}
|
|
|
|
|
|
|
|
onMoreChange(callback) {
|
|
|
|
callback.call(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Change State
|
2018-05-08 07:25:15 +00:00
|
|
|
onStateOkClick() {
|
|
|
|
let filter = {where: {code: "OK"}, fields: ["id"]};
|
|
|
|
let json = encodeURIComponent(JSON.stringify(filter));
|
|
|
|
this.$http.get(`/ticket/api/States?filter=${json}`).then(res => {
|
|
|
|
this.onStateChange(res.data[0].id);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
onStateChange(value) {
|
|
|
|
let params = {ticketFk: this.$state.params.id, stateFk: value};
|
2018-06-06 14:54:40 +00:00
|
|
|
this.$http.post(`/ticket/api/TicketTrackings/changeState`, params).then(() => {
|
2018-05-08 07:25:15 +00:00
|
|
|
this.card.reload();
|
2018-06-06 14:54:40 +00:00
|
|
|
this.vnApp.showMessage(this.translate.instant('Data saved'));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add Turn
|
|
|
|
showAddTurnDialog() {
|
|
|
|
this.$.addTurn.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
addTurn(day) {
|
|
|
|
let params = {ticketFk: this.$state.params.id, weekDay: day};
|
|
|
|
this.$http.patch(`/ticket/api/TicketWeeklies`, params).then(() => {
|
|
|
|
this.$.addTurn.hide();
|
2018-05-08 07:25:15 +00:00
|
|
|
});
|
2018-04-26 14:41:08 +00:00
|
|
|
}
|
2018-03-26 12:55:10 +00:00
|
|
|
|
2018-06-06 14:54:40 +00:00
|
|
|
// Delete Ticket
|
|
|
|
showDeleteTicketDialog() {
|
|
|
|
this.$.deleteConfirmation.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
returnDeleteTicketDialog(response) {
|
|
|
|
if (response === 'ACCEPT')
|
|
|
|
this.deleteTicket();
|
|
|
|
}
|
|
|
|
|
|
|
|
deleteTicket() {
|
|
|
|
let params = {id: this.$state.params.id};
|
|
|
|
this.$http.post(`/ticket/api/Tickets/deleted`, params).then(() => {
|
|
|
|
this.$state.go('ticket.list');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove Lines
|
2018-05-08 07:54:14 +00:00
|
|
|
onRemoveLinesClick() {
|
2018-06-06 14:54:40 +00:00
|
|
|
let sales = this.getCheckedLines();
|
|
|
|
let params = {sales: sales, actualTicketFk: this.ticket.id};
|
|
|
|
let query = `/ticket/api/Sales/removes`;
|
|
|
|
this.$http.post(query, params).then(() => {
|
|
|
|
this.removeInstances(sales);
|
|
|
|
});
|
|
|
|
}
|
2018-05-08 07:54:14 +00:00
|
|
|
|
2018-06-06 14:54:40 +00:00
|
|
|
// Move Lines
|
|
|
|
showTransferPopover(event) {
|
|
|
|
let filter = {clientFk: this.ticket.clientFk, ticketFk: this.ticket.id};
|
|
|
|
let json = encodeURIComponent(JSON.stringify(filter));
|
|
|
|
this.$http.get(`/ticket/api/Tickets/threeLastActive?filter=${json}`).then(res => {
|
|
|
|
this.lastThreeTickets = res.data;
|
|
|
|
});
|
|
|
|
this.$.transfer.parent = event.target;
|
|
|
|
this.$.transfer.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
moveLines(ticketID) {
|
|
|
|
let sales = this.getCheckedLines();
|
|
|
|
|
|
|
|
let params = {sales: sales, newTicketFk: ticketID, actualTicketFk: this.ticket.id};
|
|
|
|
this.$http.post(`/ticket/api/Sales/moveToTicket`, params).then(() => {
|
|
|
|
this.goToTicket(ticketID);
|
|
|
|
});
|
2018-05-08 07:54:14 +00:00
|
|
|
}
|
|
|
|
|
2018-06-06 14:54:40 +00:00
|
|
|
/* newTicket() {
|
|
|
|
let params = [this.ticket.clientFk, this.ticket.warehouseFk, this.ticket.companyFk, this.ticket.addressFk, this.ticket.agencyModeFk, null];
|
|
|
|
this.$http.post(`/ticket/api/Tickets/create`, params).then(res => {
|
|
|
|
console.log(res);
|
|
|
|
});
|
|
|
|
}*/
|
|
|
|
|
|
|
|
goToTicket(ticketID) {
|
|
|
|
this.$state.go("ticket.card.sale", {id: ticketID});
|
|
|
|
}
|
|
|
|
|
|
|
|
removeInstances(instances) {
|
|
|
|
for (let i = instances.length - 1; i >= 0; i--) {
|
|
|
|
this.$.index.model.instances.splice(instances[i].instance, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Item Descriptor
|
2018-04-26 14:41:08 +00:00
|
|
|
showDescriptor(event, itemFk) {
|
|
|
|
this.$.descriptor.itemFk = itemFk;
|
|
|
|
this.$.descriptor.parent = event.target;
|
|
|
|
this.$.descriptor.show();
|
|
|
|
}
|
2018-06-06 14:54:40 +00:00
|
|
|
|
2018-04-26 14:41:08 +00:00
|
|
|
onDescriptorLoad() {
|
|
|
|
this.$.popover.relocate();
|
2018-03-26 12:55:10 +00:00
|
|
|
}
|
2018-06-06 14:54:40 +00:00
|
|
|
|
|
|
|
// Ticket Create
|
|
|
|
showticketCreate() {
|
|
|
|
console.log(this);
|
|
|
|
this.$.newTicket.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
onResponse(response) {
|
|
|
|
if (response === 'ACCEPT') {
|
|
|
|
let newTicketID = this.$.newTicket.dialog.createTicket();
|
|
|
|
console.log(newTicketID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Edit Line
|
|
|
|
_getworkerMana() {
|
|
|
|
this.$http.get(`/api/WorkerManas/getCurrentWorkerMana`).then(res => {
|
|
|
|
this.workerMana = res.data[0].mana;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
showEditPopover(event, sale) {
|
|
|
|
this.sale = sale;
|
|
|
|
this.edit = {
|
|
|
|
id: sale.id,
|
|
|
|
quantity: sale.quantity,
|
|
|
|
price: sale.price,
|
|
|
|
discount: sale.discount
|
|
|
|
};
|
|
|
|
this.$.edit.parent = event.target;
|
|
|
|
this._getworkerMana();
|
|
|
|
this.$.edit.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
updateLine() {
|
|
|
|
if (this.edit.quantity != this.sale.quantity) {
|
|
|
|
this.$http.post(`/ticket/api/Sales/updateQuantity`, {id: this.edit.id, quantity: this.edit.quantity}).then(() => {
|
|
|
|
this.sale.quantity = this.edit.quantity;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.edit.price != this.sale.price) {
|
|
|
|
this.$http.post(`/ticket/api/Sales/updatePrice`, {id: this.edit.id, price: this.edit.price}).then(() => {
|
|
|
|
this.sale.price = this.edit.price;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.edit.discount != this.sale.discount) {
|
|
|
|
this.$http.post(`/ticket/api/Sales/updateDiscount`, {id: this.edit.id, discount: this.edit.discount}).then(() => {
|
|
|
|
this.sale.discount = this.edit.discount;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
this.$.edit.hide();
|
|
|
|
}
|
2018-06-19 07:09:49 +00:00
|
|
|
|
|
|
|
onMoreClick() {
|
|
|
|
this.removeOptionByName('Mark as reserved');
|
|
|
|
this.removeOptionByName('Unmark as reserved');
|
|
|
|
|
|
|
|
if (!this.isChecked) return;
|
|
|
|
|
|
|
|
this.moreOptions.push({
|
|
|
|
callback: this.markAsReserved,
|
|
|
|
name: 'Mark as reserved'}
|
|
|
|
);
|
|
|
|
|
|
|
|
this.moreOptions.push({
|
|
|
|
callback: this.unmarkAsReserved,
|
|
|
|
name: 'Unmark as reserved'}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove options from 'More' menu
|
|
|
|
* @param {String} name - Option name
|
|
|
|
*/
|
|
|
|
removeOptionByName(name) {
|
|
|
|
let options = this.moreOptions;
|
|
|
|
for (let i = 0; i < this.moreOptions.length; i++) {
|
|
|
|
if (options[i].name === name)
|
|
|
|
this.moreOptions.splice(i, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Mark sale as reserved
|
|
|
|
*/
|
|
|
|
markAsReserved() {
|
|
|
|
this.setReserved(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unmark sale as reserved
|
|
|
|
*/
|
|
|
|
unmarkAsReserved() {
|
|
|
|
this.setReserved(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Mark/Unmark sale as reserved from selected lines
|
|
|
|
* @param {Boolean} reserved reserved
|
|
|
|
*/
|
|
|
|
setReserved(reserved) {
|
|
|
|
let data = {
|
|
|
|
delete: [],
|
|
|
|
create: [],
|
|
|
|
update: this.getCheckedLines()
|
|
|
|
};
|
|
|
|
|
|
|
|
data.update.forEach(line => {
|
|
|
|
line.reserved = reserved;
|
|
|
|
});
|
|
|
|
|
|
|
|
this.$http.post(`/ticket/api/Sales/crudSale`, data).then(() => {
|
|
|
|
this.$.index.accept();
|
|
|
|
});
|
|
|
|
}
|
2018-03-26 12:55:10 +00:00
|
|
|
}
|
|
|
|
|
2018-06-06 14:54:40 +00:00
|
|
|
Controller.$inject = ['$scope', '$timeout', '$state', '$http', 'vnApp'];
|
2018-03-26 12:55:10 +00:00
|
|
|
|
2018-03-22 17:02:48 +00:00
|
|
|
ngModule.component('vnTicketSale', {
|
2018-05-25 08:03:45 +00:00
|
|
|
template: require('./index.html'),
|
2018-05-08 07:25:15 +00:00
|
|
|
controller: Controller,
|
|
|
|
bindings: {
|
|
|
|
ticket: '<'
|
|
|
|
},
|
|
|
|
require: {
|
|
|
|
card: '^vnTicketCard'
|
|
|
|
}
|
2018-03-22 17:02:48 +00:00
|
|
|
});
|