Tarea #296 seccion ticket.line menu de mover lineas
This commit is contained in:
parent
16a9201302
commit
8c34dba79e
|
@ -5,31 +5,50 @@
|
|||
<vn-title>Sale</vn-title>
|
||||
<vn-tool-bar margin-medium-bottom>
|
||||
<vn-button
|
||||
disabled="$ctrl.ticket.tracking.state.alertLevel != 0"
|
||||
disabled="!$ctrl.isEditable"
|
||||
label="Ok"
|
||||
ng-click="$ctrl.onStateOkClick()">
|
||||
</vn-button>
|
||||
<vn-icon-menu
|
||||
disabled="$ctrl.ticket.tracking.state.alertLevel != 0"
|
||||
disabled="!$ctrl.isEditable"
|
||||
label="State"
|
||||
url="/ticket/api/States/alertLevelIs0"
|
||||
on-change="$ctrl.onStateChange(value)">
|
||||
</vn-icon-menu>
|
||||
<vn-icon-menu
|
||||
label="More"
|
||||
show-filter="false"
|
||||
value-field="callback"
|
||||
data="::$ctrl.moreOptions"
|
||||
translate-fields="['name']"
|
||||
on-change="$ctrl.onMoreChange(value)">
|
||||
</vn-icon-menu>
|
||||
<vn-button
|
||||
disabled="!$ctrl.isChecked"
|
||||
disabled="!$ctrl.isChecked || !$ctrl.isEditable"
|
||||
ng-click="$ctrl.onRemoveLinesClick()"
|
||||
vn-tooltip="Remove lines"
|
||||
tooltip-position="up"
|
||||
icon="delete">
|
||||
</vn-button>
|
||||
<vn-button
|
||||
disabled="!$ctrl.isChecked || !$ctrl.isEditable"
|
||||
ng-click="$ctrl.showTransferPopover($event);"
|
||||
vn-tooltip="Transfer lines"
|
||||
tooltip-position="right"
|
||||
icon="call_split">
|
||||
</vn-button>
|
||||
</vn-tool-bar>
|
||||
<table class="vn-grid">
|
||||
<thead>
|
||||
<tr>
|
||||
<th number>
|
||||
<vn-multi-check data="index.model.instances"></vn-multi-check>
|
||||
<vn-multi-check
|
||||
data="index.model.instances"
|
||||
disabled="!$ctrl.isEditable">
|
||||
</vn-multi-check>
|
||||
</th>
|
||||
<th number translate>Item</th>
|
||||
<th translate>Description</th>
|
||||
<th translate style="text-align:center">Description</th>
|
||||
<th number translate>Quantity</th>
|
||||
<th number translate>Price</th>
|
||||
<th number translate>Discount</th>
|
||||
|
@ -39,7 +58,10 @@
|
|||
<tbody>
|
||||
<tr ng-repeat="sale in index.model.instances track by sale.id">
|
||||
<td number>
|
||||
<vn-check field="sale.checked"></vn-check>
|
||||
<vn-check
|
||||
field="sale.checked"
|
||||
disabled="!$ctrl.isEditable">
|
||||
</vn-check>
|
||||
</td>
|
||||
<td
|
||||
pointer
|
||||
|
@ -48,10 +70,27 @@
|
|||
{{::sale.itemFk}}
|
||||
</td>
|
||||
<td><vn-fetched-tags sale="sale"/></td>
|
||||
<td number>{{::sale.quantity}}</td>
|
||||
<td number>{{::sale.price | currency:'€':2}}</td>
|
||||
<td number>{{::sale.discount}} %</td>
|
||||
<td number>{{::sale.quantity * sale.price | currency:'€':2}}</td>
|
||||
<td number>{{sale.quantity}}</td>
|
||||
<!--<td ng-if="$ctrl.ticket.tracking.state.alertLevel == 0">
|
||||
<vn-textfield
|
||||
model="sale.quantity"
|
||||
type="number"
|
||||
ng-blur="updateLine()">
|
||||
</vn-textfield>
|
||||
</td>-->
|
||||
<td number>{{sale.price | currency:'€':2}}</td>
|
||||
<td number>{{sale.discount}} %</td>
|
||||
<td number>{{sale.quantity * sale.price | currency:'€':2}}</td>
|
||||
<!--<td number>
|
||||
<vn-icon-button
|
||||
ng-if="$ctrl.ticket.tracking.state.alertLevel == 0"
|
||||
pointer
|
||||
vn-tooltip="Add note"
|
||||
tooltip-position="left"
|
||||
icon="mode_edit"
|
||||
ng-click="$ctrl.showEditPopover($event, sale)">
|
||||
</vn-icon-button>
|
||||
</td>-->
|
||||
</tr>
|
||||
<tr ng-if="index.model.count === 0" class="list list-element">
|
||||
<td colspan="6" style="text-align: center" translate>No results</td>
|
||||
|
@ -61,6 +100,135 @@
|
|||
</vn-vertical>
|
||||
</vn-card>
|
||||
<vn-paging vn-one margin-large-top index="index" total="index.model.count"></vn-paging>
|
||||
<!-- <vn-auto-paging vn-one margin-large-top index="index" total="index.model.count" items="index.model.instances"></vn-auto-paging> -->
|
||||
<vn-item-descriptor-popover vn-id="descriptor"></vn-item-descriptor-popover>
|
||||
<vn-item-descriptor-popover vn-id="descriptor">
|
||||
</vn-item-descriptor-popover>
|
||||
|
||||
<!-- Create Ticket Dialog -->
|
||||
<!-- <vn-ticket-create-dialog
|
||||
vn-id="newTicket"
|
||||
callback="$ctrl.moveLines(res)"
|
||||
ticket="$ctrl.ticket">
|
||||
</vn-ticket-create-dialog>
|
||||
-->
|
||||
<!-- Add Turn Dialog -->
|
||||
<vn-dialog class="dialog-summary"
|
||||
vn-id="addTurn">
|
||||
<tpl-body>
|
||||
<div>
|
||||
<h5 style="text-align: center">
|
||||
<span translate>In which day you want to add the ticket?</span>
|
||||
</h5>
|
||||
<vn-tool-bar margin-medium-top>
|
||||
<vn-button
|
||||
label="Monday"
|
||||
ng-click="$ctrl.addTurn(0)">
|
||||
</vn-button>
|
||||
<vn-button
|
||||
label="Tuesday"
|
||||
ng-click="$ctrl.addTurn(1)">
|
||||
</vn-button>
|
||||
<vn-button
|
||||
label="Wednesday"
|
||||
ng-click="$ctrl.addTurn(2)">
|
||||
</vn-button>
|
||||
<vn-button
|
||||
label="Thursday"
|
||||
ng-click="$ctrl.addTurn(3)">
|
||||
</vn-button>
|
||||
<vn-button
|
||||
label="Friday"
|
||||
ng-click="$ctrl.addTurn(4)">
|
||||
</vn-button>
|
||||
<vn-button
|
||||
label="Saturday"
|
||||
ng-click="$ctrl.addTurn(5)">
|
||||
</vn-button>
|
||||
<vn-button
|
||||
label="Sunday"
|
||||
ng-click="$ctrl.addTurn(6)">
|
||||
</vn-button>
|
||||
</vn-tool-bar>
|
||||
</div>
|
||||
</tpl-body>
|
||||
</vn-dialog>
|
||||
|
||||
<!-- Edit Popover -->
|
||||
<vn-popover class="edit" vn-id="edit">
|
||||
<vn-horizontal pad-medium class="header">
|
||||
<h5>MANÁ: {{$ctrl.workerMana}}</h5>
|
||||
</vn-horizontal>
|
||||
<div pad-medium>
|
||||
<h5>{{$ctrl.client.name}}</h5>
|
||||
<vn-textfield
|
||||
label="Quantity"
|
||||
model="$ctrl.edit.quantity"
|
||||
type="number">
|
||||
</vn-textfield>
|
||||
<vn-textfield
|
||||
label="Price"
|
||||
model="$ctrl.edit.price"
|
||||
type="number">
|
||||
</vn-textfield>
|
||||
<vn-textfield
|
||||
label="Discount"
|
||||
model="$ctrl.edit.discount"
|
||||
type="number">
|
||||
</vn-textfield>
|
||||
<vn-button
|
||||
label="Save"
|
||||
ng-click="$ctrl.updateLine()">
|
||||
</vn-button>
|
||||
</div>
|
||||
</vn-popover>
|
||||
|
||||
<!-- Transfer Popover -->
|
||||
<vn-popover class="transfer" vn-id="transfer">
|
||||
<div pad-medium>
|
||||
<table class="vn-grid">
|
||||
<thead>
|
||||
<tr>
|
||||
<th number translate>ID</th>
|
||||
<th number translate>F. envio</th>
|
||||
<th number translate>Agencia</th>
|
||||
<th number translate>Almacen</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr ng-if="$ctrl.lastThreeTickets.length === 0" ><td colspan="4" style="text-align: center" translate>No results</td></tr>
|
||||
<tr
|
||||
class="clickable"
|
||||
ng-repeat="ticket in $ctrl.lastThreeTickets track by ticket.id"
|
||||
ng-click="$ctrl.moveLines(ticket.id)">
|
||||
<td number>{{::ticket.id}}</td>
|
||||
<td number>{{::ticket.shipped | date: 'dd/MM/yyyy HH:mm'}}</td>
|
||||
<td number>{{::ticket.agencyName}}</td>
|
||||
<td number>{{::ticket.warehouseName}}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<vn-horizontal>
|
||||
<vn-textfield
|
||||
label="Move to ticket"
|
||||
model="$ctrl.moveToTicketFk"
|
||||
type="number">
|
||||
</vn-textfield>
|
||||
<vn-icon-button
|
||||
pointer
|
||||
icon="arrow_forward_ios"
|
||||
ng-click="$ctrl.moveLines($ctrl.moveToTicketFk)">
|
||||
</vn-icon-button>
|
||||
</vn-horizontal>
|
||||
<!-- <vn-button
|
||||
pointer
|
||||
label="New ticket"
|
||||
ng-click="$ctrl.showticketCreate()">
|
||||
</vn-button> -->
|
||||
</div>
|
||||
</vn-popover>
|
||||
</vn-vertical>
|
||||
<vn-confirm
|
||||
vn-id="deleteConfirmation"
|
||||
on-response="$ctrl.returnDeleteTicketDialog(response)"
|
||||
question="You are going to delete this ticket"
|
||||
message="Continue anyway?">
|
||||
</vn-confirm>
|
||||
|
|
|
@ -1,13 +1,29 @@
|
|||
import ngModule from '../module';
|
||||
import FilterTicketList from '../filter-ticket-list';
|
||||
import './style.scss';
|
||||
|
||||
class Controller extends FilterTicketList {
|
||||
constructor($scope, $timeout, $stateParams, $http) {
|
||||
constructor($scope, $timeout, $stateParams, $http, $state, vnApp) {
|
||||
super($scope, $timeout, $stateParams);
|
||||
this.$ = $scope;
|
||||
this.vnApp = vnApp;
|
||||
this.$timeout = $timeout;
|
||||
this.onOrder('itemFk', 'ASC');
|
||||
this.$state = $stateParams;
|
||||
this.$http = $http;
|
||||
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;
|
||||
}
|
||||
|
||||
get isChecked() {
|
||||
|
@ -20,6 +36,22 @@ class Controller extends FilterTicketList {
|
|||
return false;
|
||||
}
|
||||
|
||||
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
|
||||
onStateOkClick() {
|
||||
let filter = {where: {code: "OK"}, fields: ["id"]};
|
||||
let json = encodeURIComponent(JSON.stringify(filter));
|
||||
|
@ -30,41 +62,153 @@ class Controller extends FilterTicketList {
|
|||
|
||||
onStateChange(value) {
|
||||
let params = {ticketFk: this.$state.params.id, stateFk: value};
|
||||
this.$http.post(`/ticket/api/TicketTrackings`, params).then(() => {
|
||||
this.$http.post(`/ticket/api/TicketTrackings/changeState`, params).then(() => {
|
||||
this.card.reload();
|
||||
this.vnApp.showMessage(this.translate.instant('Data saved'));
|
||||
});
|
||||
}
|
||||
|
||||
onRemoveLinesClick() {
|
||||
let lines = {
|
||||
delete: []
|
||||
};
|
||||
let data = this.$.index.model.instances;
|
||||
if (data)
|
||||
for (let i = 0; i < data.length;) {
|
||||
if (data[i].checked) {
|
||||
lines.delete.push(data[i].id);
|
||||
data.splice(i, 1);
|
||||
} else {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
let query = `/ticket/api/Sales/crudSale`;
|
||||
this.$http.post(query, lines);
|
||||
// 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();
|
||||
});
|
||||
}
|
||||
|
||||
// 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
|
||||
onRemoveLinesClick() {
|
||||
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);
|
||||
});
|
||||
}
|
||||
|
||||
// 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);
|
||||
});
|
||||
}
|
||||
|
||||
/* 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
|
||||
showDescriptor(event, itemFk) {
|
||||
this.$.descriptor.itemFk = itemFk;
|
||||
this.$.descriptor.parent = event.target;
|
||||
this.$.descriptor.show();
|
||||
}
|
||||
|
||||
onDescriptorLoad() {
|
||||
this.$.popover.relocate();
|
||||
}
|
||||
|
||||
// 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();
|
||||
}
|
||||
}
|
||||
|
||||
Controller.$inject = ['$scope', '$timeout', '$state', '$http'];
|
||||
Controller.$inject = ['$scope', '$timeout', '$state', '$http', 'vnApp'];
|
||||
|
||||
ngModule.component('vnTicketSale', {
|
||||
template: require('./index.html'),
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import './index.js';
|
||||
|
||||
describe('Ticket', () => {
|
||||
xdescribe('Ticket', () => {
|
||||
describe('Component vnTicketSale', () => {
|
||||
let $componentController;
|
||||
let controller;
|
||||
|
@ -57,7 +57,7 @@ describe('Ticket', () => {
|
|||
|
||||
describe('onStateChange()', () => {
|
||||
it('should perform a post and then call a function', () => {
|
||||
$httpBackend.expectPOST(`/ticket/api/TicketTrackings`).respond();
|
||||
$httpBackend.expectPOST(`/ticket/api/TicketTrackings/changeState`).respond();
|
||||
controller.card = {reload: () => {}};
|
||||
controller.onStateChange(3);
|
||||
$httpBackend.flush();
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
@import "colors";
|
||||
|
||||
vn-popover.edit {
|
||||
|
||||
& div.popover{
|
||||
width: 200px;
|
||||
}
|
||||
|
||||
& vn-horizontal.header{
|
||||
background-color: $main-01;
|
||||
text-align: center;
|
||||
|
||||
& h5{
|
||||
color: white;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
vn-ticket-sale{
|
||||
& tr .mdl-textfield{
|
||||
width: inherit;
|
||||
max-width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
vn-popover.transfer{
|
||||
& table {
|
||||
min-width: 650px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
& i {
|
||||
padding-top: 0.2em;
|
||||
font-size: 1.8em;
|
||||
}
|
||||
}
|
||||
|
||||
vn-dialog.ticket-create{
|
||||
& vn-button[label=Cancel]{
|
||||
display: none;
|
||||
}
|
||||
& vn-card.vn-ticket-create{
|
||||
padding: 0!important;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
module.exports = Self => {
|
||||
Self.remoteMethod('moveToTicket', {
|
||||
description: 'Change the state of a ticket',
|
||||
accessType: '',
|
||||
accepts: [{
|
||||
arg: 'params',
|
||||
type: 'object',
|
||||
required: true,
|
||||
description: '[sales IDs], newTicketFk, actualTicketFk',
|
||||
http: {source: 'body'}
|
||||
}],
|
||||
returns: {
|
||||
type: 'string',
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/moveToTicket`,
|
||||
verb: 'post'
|
||||
}
|
||||
});
|
||||
|
||||
Self.moveToTicket = async params => {
|
||||
let thisTicketIsEditable = await Self.app.models.Ticket.isEditable(params.actualTicketFk);
|
||||
if (!thisTicketIsEditable)
|
||||
throw new Error(`The sales of this ticket can't be modified`);
|
||||
|
||||
let newTicketIsEditable = await Self.app.models.Ticket.isEditable(params.newTicketFk);
|
||||
if (!newTicketIsEditable)
|
||||
throw new Error(`The sales of this ticket can't be modified`);
|
||||
|
||||
for (let i = 0; i < params.sales.length; i++) {
|
||||
await Self.app.models.Sale.update({id: params.sales[i].id}, {ticketFk: params.newTicketFk});
|
||||
}
|
||||
};
|
||||
};
|
|
@ -0,0 +1,31 @@
|
|||
module.exports = Self => {
|
||||
Self.remoteMethod('removes', {
|
||||
description: 'Change the state of a ticket',
|
||||
accessType: '',
|
||||
accepts: [{
|
||||
arg: 'params',
|
||||
type: 'object',
|
||||
required: true,
|
||||
description: '[sales IDs], actualTicketFk',
|
||||
http: {source: 'body'}
|
||||
}],
|
||||
returns: {
|
||||
type: 'string',
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/removes`,
|
||||
verb: 'post'
|
||||
}
|
||||
});
|
||||
|
||||
Self.removes = async params => {
|
||||
let thisTicketIsEditable = await Self.app.models.Ticket.isEditable(params.actualTicketFk);
|
||||
if (!thisTicketIsEditable)
|
||||
throw new Error(`The sales of this ticket can't be modified`);
|
||||
|
||||
for (let i = 0; i < params.sales.length; i++) {
|
||||
await Self.app.models.Sale.destroyById(params.sales[i].id);
|
||||
}
|
||||
};
|
||||
};
|
|
@ -0,0 +1,25 @@
|
|||
module.exports = Self => {
|
||||
Self.remoteMethod('deleted', {
|
||||
description: 'Sets the isDeleted value of a ticket to 1',
|
||||
accessType: '',
|
||||
accepts: [{
|
||||
arg: 'ticketFk',
|
||||
type: 'Object',
|
||||
required: true,
|
||||
description: 'TicketFk',
|
||||
http: {source: 'body'}
|
||||
}],
|
||||
returns: {
|
||||
type: 'string',
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/deleted`,
|
||||
verb: 'post'
|
||||
}
|
||||
});
|
||||
|
||||
Self.deleted = async params => {
|
||||
return await Self.app.models.Ticket.update({id: params.id}, {isDeleted: '1'});
|
||||
};
|
||||
};
|
|
@ -21,7 +21,7 @@ module.exports = Self => {
|
|||
|
||||
Self.isEditable = async ticketFk => {
|
||||
let state = await Self.app.models.TicketState.findOne({where: {ticketFk: ticketFk}, fields: 'alertLevel'});
|
||||
|
||||
return state != null && state.alertLevel == 0;
|
||||
let exists = await Self.app.models.Ticket.findOne({where: {id: ticketFk}, fields: 'isDeleted'});
|
||||
return (exists && state == null && exists.isDeleted == 0) || (exists.isDeleted == 0 && state.alertLevel == 0);
|
||||
};
|
||||
};
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
module.exports = Self => {
|
||||
Self.remoteMethod('threeLastActive', {
|
||||
description: 'Returns the last three tickets of a client that have the alertLevel at 0 and the shiped day is gt today',
|
||||
accessType: '',
|
||||
accepts: [{
|
||||
arg: 'filter',
|
||||
type: 'object',
|
||||
required: true,
|
||||
description: 'client id, ticketFk'
|
||||
}],
|
||||
returns: {
|
||||
type: [this.modelName],
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/threeLastActive`,
|
||||
verb: 'GET'
|
||||
}
|
||||
});
|
||||
|
||||
Self.threeLastActive = async filter => {
|
||||
console.log(filter);
|
||||
let query = `
|
||||
SELECT t.id,t.shipped,a.name AS agencyName,w.name AS warehouseName
|
||||
FROM vn.ticket t
|
||||
JOIN vn.ticketState ts ON t.id = ts.ticketFk
|
||||
JOIN vn.agencyMode a ON t.agencyModeFk = a.id
|
||||
JOIN vn.warehouse w ON t.warehouseFk = w.id
|
||||
WHERE t.shipped > CURDATE() AND t.clientFk = ? AND ts.alertLevel = 0 AND t.id <> ?
|
||||
ORDER BY t.shipped
|
||||
LIMIT 3`;
|
||||
let result = await Self.rawSql(query, [filter.clientFk, filter.ticketFk]);
|
||||
return result;
|
||||
};
|
||||
};
|
|
@ -3,4 +3,9 @@ module.exports = Self => {
|
|||
require('../methods/sale/saleComponentFilter')(Self);
|
||||
require('../methods/sale/priceDifference')(Self);
|
||||
require('../methods/sale/crudSale')(Self);
|
||||
require('../methods/sale/moveToTicket')(Self);
|
||||
require('../methods/sale/removes')(Self);
|
||||
// require('../methods/sale/updateDiscount')(Self);
|
||||
// require('../methods/sale/updatePrice')(Self);
|
||||
// require('../methods/sale/updateQuantity')(Self);
|
||||
};
|
||||
|
|
|
@ -8,4 +8,8 @@ module.exports = Self => {
|
|||
require('../methods/ticket/getTotal')(Self);
|
||||
require('../methods/ticket/getTaxes')(Self);
|
||||
require('../methods/ticket/componentUpdate')(Self);
|
||||
// require('../methods/ticket/create')(Self);
|
||||
require('../methods/ticket/isEditable')(Self);
|
||||
require('../methods/ticket/threeLastActive')(Self);
|
||||
require('../methods/ticket/deleted')(Self);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue