2018-03-22 17:02:48 +00:00
|
|
|
import ngModule from '../module';
|
2018-06-06 14:54:40 +00:00
|
|
|
import './style.scss';
|
2018-03-22 17:02:48 +00:00
|
|
|
|
2018-07-04 12:41:01 +00:00
|
|
|
class Controller {
|
2018-07-17 06:44:31 +00:00
|
|
|
constructor($scope, $state, $http, vnApp, $translate) {
|
|
|
|
this.$scope = $scope;
|
2018-06-06 14:54:40 +00:00
|
|
|
this.vnApp = vnApp;
|
2018-08-02 13:33:24 +00:00
|
|
|
this.$translate = $translate;
|
2018-07-17 06:44:31 +00:00
|
|
|
this.$state = $state;
|
|
|
|
this.$stateParams = $state.params;
|
2018-05-08 07:25:15 +00:00
|
|
|
this.$http = $http;
|
2018-06-06 14:54:40 +00:00
|
|
|
this.deletable = false;
|
2018-06-28 13:17:50 +00:00
|
|
|
this.edit = {};
|
2018-06-06 14:54:40 +00:00
|
|
|
this.moreOptions = [
|
2018-07-02 11:18:22 +00:00
|
|
|
{callback: this.showAddTurnDialog, name: "Add turn", always: true},
|
|
|
|
{callback: this.showDeleteTicketDialog, name: "Delete ticket", always: true},
|
|
|
|
{callback: this.markAsReserved, name: 'Mark as reserved'},
|
|
|
|
{callback: this.unmarkAsReserved, name: 'Unmark as reserved'},
|
|
|
|
{callback: this.showEditDialog, name: 'Update discount'}
|
2018-06-06 14:54:40 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2018-08-01 10:15:09 +00:00
|
|
|
set ticket(value) {
|
|
|
|
this._ticket = value;
|
|
|
|
|
|
|
|
if (!value) return;
|
|
|
|
|
|
|
|
this.quicklinks = {
|
|
|
|
btnThree: {
|
|
|
|
icon: 'icon-transaction',
|
|
|
|
state: 'item.card.diary',
|
|
|
|
params: {id: value.id, q: `{"warehouseFk": ${value.warehouseFk}}`},
|
|
|
|
tooltip: 'Item diary'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
get ticket() {
|
|
|
|
return this._ticket;
|
|
|
|
}
|
|
|
|
|
2018-07-17 06:44:31 +00:00
|
|
|
onDataChange() {
|
|
|
|
this.sales = this.$scope.model.data;
|
|
|
|
this.getTaxes();
|
2018-07-04 12:41:01 +00:00
|
|
|
}
|
2018-07-17 06:44:31 +00:00
|
|
|
|
2018-07-02 11:18:22 +00:00
|
|
|
onMoreOpen() {
|
|
|
|
let options = this.moreOptions.filter(o => o.always || this.isChecked);
|
2018-07-17 06:44:31 +00:00
|
|
|
this.$scope.moreButton.data = options;
|
2018-07-02 11:18:22 +00:00
|
|
|
}
|
2018-07-17 06:44:31 +00:00
|
|
|
|
2018-06-19 10:10:38 +00:00
|
|
|
getTaxes() {
|
|
|
|
this.getSubTotal();
|
|
|
|
this.getVAT();
|
|
|
|
}
|
2018-07-17 06:44:31 +00:00
|
|
|
|
2018-06-19 10:10:38 +00:00
|
|
|
getSubTotal() {
|
2018-07-04 12:41:01 +00:00
|
|
|
let sales = this.sales;
|
2018-06-19 10:10:38 +00:00
|
|
|
|
|
|
|
this.subTotal = 0.00;
|
|
|
|
sales.forEach(sale => {
|
2018-06-28 13:17:50 +00:00
|
|
|
this.subTotal += (sale.quantity * sale.price) - ((sale.discount * (sale.quantity * sale.price)) / 100);
|
2018-06-19 10:10:38 +00:00
|
|
|
});
|
|
|
|
}
|
2018-07-17 06:44:31 +00:00
|
|
|
|
2018-06-19 10:10:38 +00:00
|
|
|
getVAT() {
|
2018-08-02 13:39:32 +00:00
|
|
|
if (this.ticket || this.ticket.id) {
|
|
|
|
this.$http.get(`/ticket/api/Tickets/${this.ticket.id}/getVAT`).then(res => {
|
|
|
|
this.VAT = res.data || 0;
|
|
|
|
this.total = this.subTotal + this.VAT;
|
|
|
|
});
|
|
|
|
}
|
2018-06-19 10:10:38 +00:00
|
|
|
}
|
2018-07-17 06:44:31 +00:00
|
|
|
|
2018-06-06 14:54:40 +00:00
|
|
|
get isEditable() {
|
|
|
|
try {
|
|
|
|
return !this.ticket.tracking.state.alertLevel;
|
|
|
|
} catch (e) {}
|
|
|
|
|
|
|
|
return true;
|
2018-05-08 07:25:15 +00:00
|
|
|
}
|
2018-07-17 06:44:31 +00:00
|
|
|
|
2018-05-08 07:54:14 +00:00
|
|
|
get isChecked() {
|
2018-07-04 12:41:01 +00:00
|
|
|
let data = this.sales;
|
2018-05-08 07:54:14 +00:00
|
|
|
if (data)
|
|
|
|
for (let instance of data)
|
|
|
|
if (instance.checked)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2018-07-17 06:44:31 +00:00
|
|
|
|
2018-06-06 14:54:40 +00:00
|
|
|
getCheckedLines() {
|
|
|
|
let lines = [];
|
2018-07-04 12:41:01 +00:00
|
|
|
let data = this.sales;
|
2018-06-06 14:54:40 +00:00
|
|
|
if (data)
|
|
|
|
for (let i = 0; i < data.length; i++)
|
|
|
|
if (data[i].checked)
|
|
|
|
lines.push({id: data[i].id, instance: i});
|
2018-07-02 12:14:16 +00:00
|
|
|
|
2018-06-06 14:54:40 +00:00
|
|
|
return lines;
|
|
|
|
}
|
2018-07-17 06:44:31 +00:00
|
|
|
|
2018-06-06 14:54:40 +00:00
|
|
|
onMoreChange(callback) {
|
|
|
|
callback.call(this);
|
|
|
|
}
|
2018-07-17 06:44:31 +00:00
|
|
|
|
2018-06-06 14:54:40 +00:00
|
|
|
// 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);
|
|
|
|
});
|
|
|
|
}
|
2018-07-17 06:44:31 +00:00
|
|
|
|
2018-05-08 07:25:15 +00:00
|
|
|
onStateChange(value) {
|
|
|
|
let params = {ticketFk: this.$state.params.id, stateFk: value};
|
2018-08-02 08:54:03 +00:00
|
|
|
this.$http.post(`/ticket/api/TicketTrackings/changeState`, params).then(() => {
|
2018-05-08 07:25:15 +00:00
|
|
|
this.card.reload();
|
2018-08-02 13:33:24 +00:00
|
|
|
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
|
2018-06-06 14:54:40 +00:00
|
|
|
});
|
|
|
|
}
|
2018-07-17 06:44:31 +00:00
|
|
|
|
2018-06-06 14:54:40 +00:00
|
|
|
// Add Turn
|
|
|
|
showAddTurnDialog() {
|
2018-07-17 06:44:31 +00:00
|
|
|
this.$scope.addTurn.show();
|
2018-06-06 14:54:40 +00:00
|
|
|
}
|
2018-07-17 06:44:31 +00:00
|
|
|
|
2018-06-06 14:54:40 +00:00
|
|
|
addTurn(day) {
|
|
|
|
let params = {ticketFk: this.$state.params.id, weekDay: day};
|
|
|
|
this.$http.patch(`/ticket/api/TicketWeeklies`, params).then(() => {
|
2018-07-17 06:44:31 +00:00
|
|
|
this.$scope.addTurn.hide();
|
2018-08-02 13:33:24 +00:00
|
|
|
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
|
2018-05-08 07:25:15 +00:00
|
|
|
});
|
2018-04-26 14:41:08 +00:00
|
|
|
}
|
2018-07-17 06:44:31 +00:00
|
|
|
|
2018-06-06 14:54:40 +00:00
|
|
|
// Delete Ticket
|
|
|
|
showDeleteTicketDialog() {
|
2018-08-02 13:33:24 +00:00
|
|
|
if (!this.isEditable)
|
|
|
|
return;
|
2018-07-17 06:44:31 +00:00
|
|
|
this.$scope.deleteConfirmation.show();
|
2018-06-06 14:54:40 +00:00
|
|
|
}
|
2018-07-17 06:44:31 +00:00
|
|
|
|
2018-07-16 11:31:03 +00:00
|
|
|
deleteTicket(response) {
|
|
|
|
if (response === 'ACCEPT') {
|
|
|
|
let params = {id: this.$state.params.id};
|
|
|
|
this.$http.post(`/ticket/api/Tickets/deleted`, params).then(() => {
|
|
|
|
this.$state.go('ticket.index');
|
2018-08-02 13:33:24 +00:00
|
|
|
this.vnApp.showSuccess(this.$translate.instant('Ticket deleted'));
|
2018-07-16 11:31:03 +00:00
|
|
|
});
|
|
|
|
}
|
2018-06-06 14:54:40 +00:00
|
|
|
}
|
2018-07-17 06:44:31 +00:00
|
|
|
|
2018-06-06 14:54:40 +00:00
|
|
|
// Remove Lines
|
2018-07-02 12:14:16 +00:00
|
|
|
onRemoveLinesClick(response) {
|
|
|
|
if (response === 'ACCEPT') {
|
|
|
|
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-06-06 14:54:40 +00:00
|
|
|
}
|
2018-07-17 06:44:31 +00:00
|
|
|
|
2018-07-02 11:18:22 +00:00
|
|
|
removeInstances(instances) {
|
|
|
|
for (let i = instances.length - 1; i >= 0; i--) {
|
2018-07-04 12:41:01 +00:00
|
|
|
this.sales.splice(instances[i].instance, 1);
|
2018-07-02 11:18:22 +00:00
|
|
|
}
|
|
|
|
}
|
2018-07-17 06:44:31 +00:00
|
|
|
|
2018-07-02 12:14:16 +00:00
|
|
|
showRemoveLinesDialog() {
|
2018-07-17 06:44:31 +00:00
|
|
|
this.$scope.deleteLines.show();
|
2018-07-02 12:14:16 +00:00
|
|
|
}
|
2018-07-17 06:44:31 +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));
|
2018-07-02 11:18:22 +00:00
|
|
|
let query = `/ticket/api/Tickets/threeLastActive?filter=${json}`;
|
|
|
|
this.$http.get(query).then(res => {
|
2018-06-06 14:54:40 +00:00
|
|
|
this.lastThreeTickets = res.data;
|
|
|
|
});
|
2018-07-17 06:44:31 +00:00
|
|
|
this.$scope.transfer.parent = event.target;
|
|
|
|
this.$scope.transfer.show();
|
2018-06-06 14:54:40 +00:00
|
|
|
}
|
2018-07-17 06:44:31 +00:00
|
|
|
|
2018-06-06 14:54:40 +00:00
|
|
|
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-07-17 06:44:31 +00:00
|
|
|
|
2018-06-28 13:17:50 +00:00
|
|
|
// In Progress
|
|
|
|
linesToNewTicket() {
|
|
|
|
let ticket = {
|
|
|
|
oldTicketFk: this.ticket.id,
|
|
|
|
clientFk: this.ticket.clientFk,
|
|
|
|
addressFk: this.ticket.addressFk,
|
|
|
|
agencyModeFk: this.ticket.agencyModeFk,
|
|
|
|
warehouseFk: this.ticket.warehouseFk
|
|
|
|
};
|
|
|
|
|
|
|
|
let sales = this.getCheckedLines();
|
|
|
|
|
|
|
|
this.$http.post(`/api/Sales/MoveToNewTicket`, {ticket: ticket, sales: sales}).then(res => {
|
2018-07-11 11:52:04 +00:00
|
|
|
let url = this.$state.href("ticket.card.sale", {id: res.data}, {absolute: true});
|
2018-07-04 12:41:01 +00:00
|
|
|
window.open(url, '_blank');
|
2018-07-17 06:44:31 +00:00
|
|
|
this.$scope.transfer.hide();
|
|
|
|
this.$scope.model.refresh();
|
2018-06-06 14:54:40 +00:00
|
|
|
});
|
2018-06-28 13:17:50 +00:00
|
|
|
}
|
2018-07-17 06:44:31 +00:00
|
|
|
|
2018-06-06 14:54:40 +00:00
|
|
|
goToTicket(ticketID) {
|
|
|
|
this.$state.go("ticket.card.sale", {id: ticketID});
|
|
|
|
}
|
2018-07-17 06:44:31 +00:00
|
|
|
|
2018-07-09 13:06:36 +00:00
|
|
|
// Focus First Input
|
|
|
|
focusFirstInput(e) {
|
|
|
|
let firstFocusable = e.querySelector('input, textarea');
|
|
|
|
if (firstFocusable) {
|
|
|
|
firstFocusable.addEventListener('focus', () => {
|
|
|
|
firstFocusable.select();
|
|
|
|
});
|
|
|
|
setTimeout(() => {
|
|
|
|
firstFocusable.focus();
|
|
|
|
}, 200);
|
|
|
|
}
|
|
|
|
}
|
2018-07-17 06:44:31 +00:00
|
|
|
|
2018-06-28 13:17:50 +00:00
|
|
|
// Slesperson Mana
|
|
|
|
getManaSalespersonMana() {
|
|
|
|
this.$http.get(`/api/Tickets/${this.$state.params.id}/getSalesPersonMana`).then(res => {
|
|
|
|
this.mana = res.data;
|
|
|
|
});
|
|
|
|
}
|
2018-07-17 06:44:31 +00:00
|
|
|
|
2018-06-06 14:54:40 +00:00
|
|
|
// Item Descriptor
|
2018-04-26 14:41:08 +00:00
|
|
|
showDescriptor(event, itemFk) {
|
2018-07-17 06:44:31 +00:00
|
|
|
this.$scope.descriptor.itemFk = itemFk;
|
|
|
|
this.$scope.descriptor.parent = event.target;
|
|
|
|
this.$scope.descriptor.show();
|
2018-04-26 14:41:08 +00:00
|
|
|
}
|
2018-07-17 06:44:31 +00:00
|
|
|
|
2018-04-26 14:41:08 +00:00
|
|
|
onDescriptorLoad() {
|
2018-07-17 06:44:31 +00:00
|
|
|
this.$scope.popover.relocate();
|
2018-03-26 12:55:10 +00:00
|
|
|
}
|
2018-07-17 06:44:31 +00:00
|
|
|
|
2018-06-28 13:17:50 +00:00
|
|
|
// Edit Line
|
|
|
|
showEditPricePopover(event, sale) {
|
|
|
|
this.sale = sale;
|
|
|
|
this.editedPrice = this.sale.price;
|
|
|
|
this.edit = {
|
|
|
|
ticketFk: this.ticket.id,
|
|
|
|
id: sale.id,
|
|
|
|
quantity: sale.quantity
|
|
|
|
};
|
2018-07-17 06:44:31 +00:00
|
|
|
this.$scope.editPricePopover.parent = event.target;
|
|
|
|
this.$scope.editPricePopover.show();
|
|
|
|
this.focusFirstInput(this.$scope.editPricePopover.$element[0]);
|
2018-06-06 14:54:40 +00:00
|
|
|
}
|
2018-07-17 06:44:31 +00:00
|
|
|
|
2018-06-28 13:17:50 +00:00
|
|
|
updatePrice() {
|
|
|
|
if (this.editedPrice != this.sale.price) {
|
|
|
|
this.$http.post(`/ticket/api/Sales/updatePrice`, {id: this.edit.id, price: this.editedPrice, ticketFk: this.ticket.id}).then(() => {
|
|
|
|
this.sale.price = this.edit.price;
|
2018-07-17 06:44:31 +00:00
|
|
|
this.$scope.model.refresh();
|
2018-08-02 13:33:24 +00:00
|
|
|
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
|
2018-06-28 13:17:50 +00:00
|
|
|
});
|
2018-06-06 14:54:40 +00:00
|
|
|
}
|
2018-07-17 06:44:31 +00:00
|
|
|
this.$scope.editPricePopover.hide();
|
2018-06-06 14:54:40 +00:00
|
|
|
}
|
2018-07-17 06:44:31 +00:00
|
|
|
|
2018-06-06 14:54:40 +00:00
|
|
|
showEditPopover(event, sale) {
|
|
|
|
this.sale = sale;
|
2018-06-28 13:17:50 +00:00
|
|
|
this.edit = [{
|
|
|
|
ticketFk: this.ticket.id,
|
2018-06-06 14:54:40 +00:00
|
|
|
id: sale.id,
|
|
|
|
quantity: sale.quantity,
|
|
|
|
price: sale.price,
|
|
|
|
discount: sale.discount
|
2018-06-28 13:17:50 +00:00
|
|
|
}];
|
2018-07-17 06:44:31 +00:00
|
|
|
this.$scope.editPopover.parent = event.target;
|
|
|
|
this.$scope.editPopover.show();
|
|
|
|
this.focusFirstInput(this.$scope.editPopover.$element[0]);
|
2018-06-28 13:17:50 +00:00
|
|
|
}
|
2018-07-17 06:44:31 +00:00
|
|
|
|
2018-07-09 13:06:36 +00:00
|
|
|
showEditDialog() {
|
2018-06-28 13:17:50 +00:00
|
|
|
this.edit = this.getCheckedLines();
|
2018-07-17 06:44:31 +00:00
|
|
|
this.$scope.editDialog.show();
|
|
|
|
this.focusFirstInput(this.$scope.editDialog.$element[0]);
|
2018-06-28 13:17:50 +00:00
|
|
|
}
|
2018-07-17 06:44:31 +00:00
|
|
|
|
2018-06-28 13:17:50 +00:00
|
|
|
hideEditDialog() {
|
2018-07-17 06:44:31 +00:00
|
|
|
this.$scope.model.refresh();
|
|
|
|
this.$scope.editDialog.hide();
|
2018-06-28 13:17:50 +00:00
|
|
|
}
|
2018-07-17 06:44:31 +00:00
|
|
|
|
2018-06-28 13:17:50 +00:00
|
|
|
hideEditPopover() {
|
2018-07-17 06:44:31 +00:00
|
|
|
this.$scope.model.refresh();
|
|
|
|
this.$scope.editPopover.hide();
|
2018-06-28 13:17:50 +00:00
|
|
|
}
|
2018-07-17 06:44:31 +00:00
|
|
|
|
2018-06-28 13:17:50 +00:00
|
|
|
updateQuantity(id, quantity) {
|
|
|
|
this.$http.post(`/ticket/api/Sales/${id}/updateQuantity`, {quantity: parseInt(quantity)}).then(() => {
|
2018-08-02 13:33:24 +00:00
|
|
|
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
|
|
|
|
this.$scope.model.refresh();
|
2018-08-07 14:06:44 +00:00
|
|
|
}).catch(e => {
|
|
|
|
this.vnApp.showError(e.data.error.message);
|
|
|
|
this.$scope.model.refresh();
|
2018-06-28 13:17:50 +00:00
|
|
|
});
|
2018-06-06 14:54:40 +00:00
|
|
|
}
|
|
|
|
|
2018-06-19 07:09:49 +00:00
|
|
|
/**
|
|
|
|
* Unmark sale as reserved
|
|
|
|
*/
|
|
|
|
unmarkAsReserved() {
|
|
|
|
this.setReserved(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-07-03 13:00:16 +00:00
|
|
|
* Mark sale as reserved
|
2018-06-19 07:09:49 +00:00
|
|
|
*/
|
2018-07-03 13:00:16 +00:00
|
|
|
markAsReserved() {
|
|
|
|
this.setReserved(true);
|
|
|
|
}
|
2018-06-19 07:09:49 +00:00
|
|
|
|
2018-07-03 13:00:16 +00:00
|
|
|
setReserved(reserved) {
|
|
|
|
let sales = this.getCheckedLines();
|
|
|
|
let params = {sales: sales, ticketFk: this.ticket.id, reserved: reserved};
|
2018-06-19 07:09:49 +00:00
|
|
|
|
2018-07-03 13:00:16 +00:00
|
|
|
this.$http.post(`/ticket/api/Sales/reserve`, params).then(() => {
|
2018-07-17 06:44:31 +00:00
|
|
|
this.$scope.model.refresh();
|
2018-06-19 07:09:49 +00:00
|
|
|
});
|
|
|
|
}
|
2018-03-26 12:55:10 +00:00
|
|
|
}
|
|
|
|
|
2018-07-17 06:44:31 +00:00
|
|
|
Controller.$inject = ['$scope', '$state', '$http', 'vnApp', '$translate'];
|
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
|
|
|
});
|