item & ticket crud-refactor #372

This commit is contained in:
Joan Sanchez 2018-07-17 08:44:31 +02:00
parent 7e1a2025a5
commit ef71f5c7cf
23 changed files with 516 additions and 290 deletions

View File

@ -83,9 +83,13 @@ vn-table {
text-align: left;
padding: 10px;
&[number]{
&[number] {
text-align: right;
}
&[center] {
text-align: center;
}
vn-icon.bright, i.bright {
color: #f7931e;

View File

@ -1,44 +1,59 @@
<mg-ajax path="/ticket/api/Expeditions/filter" options="vnIndexNonAuto"></mg-ajax>
<vn-crud-model
vn-id="model"
url="/ticket/api/Expeditions"
filter="::$ctrl.filter"
link="{ticketFk: $ctrl.$stateParams.id}"
limit="20"
data="expeditions">
</vn-crud-model>
<vn-vertical>
<vn-card pad-large>
<vn-vertical>
<vn-title>Expedition</vn-title>
<vn-grid-header on-order="$ctrl.onOrder(field, order)">
<vn-column-header vn-one pad-medium-h text="Delete"></vn-column-header>
<vn-column-header vn-one pad-medium-h field="itemFk" text="Item"></vn-column-header>
<vn-column-header vn-one pad-medium-h field="name" text="Name" order-locked></vn-column-header>
<vn-column-header vn-one pad-medium-h field="packageFk" text="Package type"></vn-column-header>
<vn-column-header vn-one pad-medium-h field="counter" text="Counter"></vn-column-header>
<vn-column-header vn-one pad-medium-h field="checked" text="Checked"></vn-column-header>
<vn-column-header vn-one pad-medium-h field="worker" text="Worker"></vn-column-header>
<vn-column-header vn-one pad-medium-h field="created" text="Created" default-order="DESC"></vn-column-header>
</vn-grid-header>
<vn-one class="list list-content">
<vn-horizontal
vn-one class="list list-element text-center"
pad-small-bottom
ng-repeat="expedition in index.model.instances track by expedition.id">
<vn-one pad-medium-h style="color:#FFA410;">
<i
pointer
class="material-icons"
vn-tooltip="delete expedition"
ng-click="$ctrl.deleteExpedition(expedition)">delete</i>
</vn-one>
<vn-one pointer number
ng-click="$ctrl.showDescriptor($event, expedition.item.id)">{{::expedition.itemFk}}</vn-one>
<vn-one pad-medium-h>{{::expedition.item.name}}</vn-one>
<vn-one pad-medium-h>{{::expedition.package.name}}</vn-one>
<vn-one pad-medium-h>{{::expedition.counter}}</vn-one>
<vn-one pad-medium-h>{{::expedition.checked}}</vn-one>
<vn-one pad-medium-h>{{::expedition.worker.firstName}} {{::expedition.worker.name}}</vn-one>
<vn-one pad-medium-h>{{::expedition.created | date:'dd/MM/yyyy'}}</vn-one>
</vn-horizontal>
</vn-one>
<vn-one class="text-center pad-small-v" ng-if="index.model.count === 0" translate>No results</vn-one>
<vn-horizontal vn-one class="list list-footer"></vn-horizontal>
<vn-table model="model">
<vn-thead>
<vn-tr>
<vn-th></vn-th>
<vn-th field="itemFk" number>Item</vn-th>
<vn-th field="name">Name</vn-th>
<vn-th field="isBox">Package type</vn-th>
<vn-th field="counter" number>Counter</vn-th>
<vn-th field="checked" number>Checked</vn-th>
<vn-th field="worker">Worker</vn-th>
<vn-th field="created" default-order="DESC">Created</vn-th>
</vn-tr>
</vn-thead>
<vn-tbody>
<vn-tr ng-repeat="expedition in expeditions">
<vn-td pad-medium-h style="color:#FFA410;">
<i
pointer
class="material-icons"
vn-tooltip="Delete expedition"
ng-click="$ctrl.deleteExpedition(expedition)">delete</i>
</vn-td>
<vn-td pointer number
ng-click="$ctrl.showDescriptor($event, expedition.item.id)">
{{::expedition.itemFk}}
</vn-td>
<vn-td>{{::expedition.item.name}}</vn-td>
<vn-td>{{::expedition.box.name}}</vn-td>
<vn-td number>{{::expedition.counter}}</vn-td>
<vn-td number>{{::expedition.checked}}</vn-td>
<vn-td>{{::expedition.worker.firstName}} {{::expedition.worker.name}}</vn-td>
<vn-td>{{::expedition.created | date:'dd/MM/yyyy'}}</vn-td>
</vn-tr>
</vn-tbody>
<vn-empty-rows ng-if="model.data.length === 0" translate>
No results
</vn-empty-rows>
</vn-table>
</vn-vertical>
<vn-pagination
model="model"
scroll-selector="ui-view">
</vn-pagination>
</vn-card>
<vn-paging vn-one margin-large-top index="index" total="index.model.count"></vn-paging>
</vn-vertical>
<vn-item-descriptor-popover vn-id="descriptor"></vn-item-descriptor-popover>

View File

@ -1,17 +1,33 @@
import ngModule from '../module';
import FilterTicketList from '../filter-ticket-list';
class Controller extends FilterTicketList {
constructor($scope, $timeout, $stateParams, $http) {
super($scope, $timeout, $stateParams);
class Controller {
constructor($scope, $stateParams, $http) {
this.$scope = $scope;
this.params = $stateParams;
this.$stateParams = $stateParams;
this.$http = $http;
this.filter = {
include: [{
relation: 'item',
scope: {
fields: ['name']
}
},
{
relation: 'box',
scope: {
fields: ['name']
}
},
{
relation: 'worker',
scope: {fields: ['firstName', 'name']}
}]
};
}
deleteExpedition(expedition) {
this.$http.delete(`/ticket/api/Expeditions/${expedition.id}`, this.params).then(
() => this.$.index.accept()
() => this.$scope.model.refresh()
);
}
@ -26,7 +42,7 @@ class Controller extends FilterTicketList {
}
}
Controller.$inject = ['$scope', '$timeout', '$state', '$http'];
Controller.$inject = ['$scope', '$stateParams', '$http'];
ngModule.component('vnTicketExpedition', {
template: require('./index.html'),

View File

@ -6,7 +6,11 @@ vn-fetched-tags {
flex-direction: column;
text-align: center;
& vn-two {
& > vn-one {
padding: 0 0 0.2em 0;
}
& > vn-two {
text-align: center;
margin: 0 auto
}
@ -29,7 +33,7 @@ vn-fetched-tags {
& vn-one {
padding-top: 6px
padding-top: 0.2em
}
& vn-two {

View File

@ -12,7 +12,7 @@ Counter: Contador
Created : Añadido
Date : Fecha
Delete: Borrar
delete expedition: borrar expedición
Delete expedition: Borrar expedición
Description: Descripción
Discount: Descuento
Employee : Empleado

View File

@ -1,37 +1,49 @@
<mg-ajax path="/ticket/api/sales/filter" options="vnIndexNonAuto"></mg-ajax>
<vn-crud-model
vn-id="model"
url="/ticket/api/sales"
filter="::$ctrl.filter"
link="{ticketFk: $ctrl.$stateParams.id}"
limit="20"
data="sales">
</vn-crud-model>
<vn-vertical>
<vn-card pad-large>
<vn-vertical>
<vn-title>Sale checked</vn-title>
<table class="vn-grid">
<thead>
<tr>
<th style="text-align:center" translate>Is checked</th>
<th number translate>Item</th>
<th translate>Description</th>
<th number translate>Quantity</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="sale in index.model.instances track by sale.id">
<td style="text-align:center!important">
<vn-check style="text-align:center!important"
vn-one field="sale.isChecked.isChecked"
disabled="true">
</vn-check>
</td>
<td number pointer
ng-click="$ctrl.showDescriptor($event, sale.itemFk)">{{::sale.itemFk}}</td>
<td><vn-fetched-tags sale="sale"/></td>
<td number>{{::sale.quantity}}</td>
</tr>
<tr ng-if="index.model.count === 0" class="list list-element">
<td colspan="4" style="text-align: center" translate>No results</td>
</tr>
</tbody>
</table>
<vn-table model="model">
<vn-thead>
<vn-tr>
<vn-th field="isChecked" center>Is checked</vn-th>
<vn-th field="itemFk" number>Item</vn-th>
<vn-th field="concept" default-order="ASC">Description</vn-th>
<vn-th field="quantity" number>Quantity</vn-th>
</vn-tr>
</vn-thead>
<vn-tbody>
<vn-tr ng-repeat="sale in sales">
<vn-td center>
<vn-check
vn-one field="sale.isChecked.isChecked"
disabled="true">
</vn-check>
</vn-td>
<vn-td number pointer
ng-click="$ctrl.showDescriptor($event, sale.itemFk)">
{{::sale.itemFk}}
</vn-td>
<vn-td><vn-fetched-tags sale="sale"/></vn-td>
<vn-td number>{{::sale.quantity}}</vn-td>
</vn-tr>
</vn-tbody>
<vn-empty-rows ng-if="model.data.length === 0" translate>
No results
</vn-empty-rows>
</vn-table>
</vn-vertical>
<vn-pagination
model="model"
scroll-selector="ui-view">
</vn-pagination>
</vn-card>
<vn-paging vn-one margin-large-top index="index" total="index.model.count"></vn-paging>
</vn-vertical>
</vn-vertical>
<vn-item-descriptor-popover vn-id="descriptor"></vn-item-descriptor-popover>

View File

@ -1,11 +1,36 @@
import ngModule from '../module';
import FilterTicketList from '../filter-ticket-list';
class Controller extends FilterTicketList {
constructor($scope, $timeout, $state) {
super($scope, $timeout, $state);
class Controller {
constructor($scope, $stateParams) {
this.$scope = $scope;
this.onOrder('quantity', 'ASC');
this.$stateParams = $stateParams;
this.filter = {
include: [{
relation: 'item',
scope: {
include: {
relation: 'tags',
scope: {
fields: ['tagFk', 'value'],
include: {
relation: 'tag',
scope: {
fields: ['name']
}
},
limit: 6
}
},
fields: ['itemFk', 'name']
}
},
{
relation: 'isChecked',
scope: {
fields: ['isChecked']
}
}]
};
}
showDescriptor(event, itemFk) {
@ -19,7 +44,7 @@ class Controller extends FilterTicketList {
}
}
Controller.$inject = ['$scope', '$timeout', '$state'];
Controller.$inject = ['$scope', '$stateParams'];
ngModule.component('vnTicketSaleChecked', {
template: require('./index.html'),

View File

@ -1,10 +1,11 @@
<vn-crud-model
vn-id="model"
url="/ticket/api/SaleTrackings/listSaleTracking"
filter="::$ctrl.filter"
filter="{}"
link="{ticketFk: $ctrl.$stateParams.id}"
limit="20"
data="sales"
auto-load="true" on-data-change="$ctrl.getTags()">
on-data-change="$ctrl.getTags()">
</vn-crud-model>
<vn-vertical>
<vn-card pad-large>
@ -51,12 +52,11 @@
</vn-empty-rows>
</vn-table>
</vn-vertical>
<vn-pagination
model="model"
scroll-selector="ui-view">
</vn-pagination>
</vn-card>
<vn-pagination
model="model"
scroll-selector="ui-view">
</vn-pagination>
</vn-vertical>
<vn-item-descriptor-popover vn-id="descriptor"></vn-item-descriptor-popover>

View File

@ -1,12 +1,9 @@
import ngModule from '../module';
class Controller {
constructor($scope, $state, $http) {
constructor($scope, $stateParams) {
this.$scope = $scope;
this.$http = $http;
this.filter = {
where: {ticketFk: $state.params.id}
};
this.$stateParams = $stateParams;
}
showDescriptor(event, itemFk) {
@ -20,7 +17,7 @@ class Controller {
}
}
Controller.$inject = ['$scope', '$state', '$http'];
Controller.$inject = ['$scope', '$stateParams'];
ngModule.component('vnTicketSaleTracking', {
template: require('./index.html'),

View File

@ -1,3 +1,10 @@
<vn-crud-model
vn-id="model"
url="/api/Tickets/{{$ctrl.$stateParams.id}}/getSales"
filter="{}"
data="sales" on-data-change="$ctrl.onDataChange()">
</vn-crud-model>
<vn-vertical>
<vn-card pad-large>
<vn-vertical>
@ -38,99 +45,125 @@
icon="call_split">
</vn-button>
</vn-tool-bar>
<table class="vn-grid">
<thead>
<tr>
<th number>
<vn-table model="model">
<vn-thead>
<vn-tr>
<vn-th number>
<vn-multi-check
data="$ctrl.sales"
disabled="!$ctrl.isEditable">
</vn-multi-check>
</th>
<th></th>
<th style="text-align: center" translate>Item</th>
<th number translate>Id</th>
<th style="text-align: center" translate>Description</th>
<th number translate>Quantity</th>
<th number translate>Price</th>
<th number translate>Disc</th>
<th number translate>Amount</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="sale in $ctrl.sales">
<td number>
</vn-th>
<vn-th></vn-th>
<vn-th>Item</vn-th>
<vn-th number>Id</vn-th>
<vn-th>Description</vn-th>
<vn-th number>Quantity</vn-th>
<vn-th number>Price</vn-th>
<vn-th number>Disc</vn-th>
<vn-th number>Amount</vn-th>
</vn-tr>
</vn-thead>
<vn-tbody>
<vn-tr ng-repeat="sale in sales">
<vn-td number>
<vn-check
field="sale.checked"
disabled="!$ctrl.isEditable">
</vn-check>
</td>
<td>
<vn-icon ng-show="sale.visible" icon="warning" vn-tooltip="Visible: {{::sale.visible}}"></vn-icon>
<vn-icon ng-show="sale.avaible" icon="warning" vn-tooltip="Avaible: {{::sale.avaible}}"></vn-icon>
</vn-td>
<vn-td>
<vn-icon
ng-show="sale.visible"
icon="warning"
vn-tooltip="Visible: {{::sale.visible}}">
</vn-icon>
<vn-icon
ng-show="sale.avaible"
icon="warning"
vn-tooltip="Avaible: {{::sale.avaible}}">
</vn-icon>
<vn-icon ng-show="sale.reserved" icon="icon-reserved"></vn-icon>
</td>
<td style="text-align: center">
</vn-td>
<vn-td style="text-align: center">
<img
ng-src="//verdnatura.es/vn-image-data/catalog/50x50/{{sale.image}}"
zoom-image="//verdnatura.es/vn-image-data/catalog/900x900/{{sale.image}}"
on-error-src/>
</td>
<td
pointer
number
ng-click="$ctrl.showDescriptor($event, sale.itemFk)">
</vn-td>
<vn-td ng-click="$ctrl.showDescriptor($event, sale.itemFk)"
pointer number>
{{::sale.itemFk}}
</td>
<td><vn-fetched-tags sale="sale"/></td>
<td ng-if="!$ctrl.isEditable" number>{{sale.quantity}}</td>
<td ng-if="$ctrl.isEditable" number>
</vn-td>
<vn-td><vn-fetched-tags sale="sale"/></vn-td>
<vn-td ng-if="!$ctrl.isEditable" number>{{sale.quantity}}</vn-td>
<vn-td ng-if="$ctrl.isEditable" number>
<vn-textfield
model="sale.quantity"
on-change="$ctrl.updateQuantity(sale.id,sale.quantity)"
type="text">
</vn-textfield>
</td>
<td number
</vn-td>
<vn-td number
ng-if="$ctrl.isEditable"
ng-click="$ctrl.showEditPricePopover($event, sale)"
pointer
vn-tooltip="Edit price">
{{sale.price | currency:'€':2}}
</td>
<td number ng-if="!$ctrl.isEditable">
</vn-td>
<vn-td number ng-if="!$ctrl.isEditable">
{{sale.price | currency:'€':2}}
</td>
<td number
</vn-td>
<vn-td number
ng-if="$ctrl.isEditable"
ng-click="$ctrl.showEditPopover($event, sale)"
pointer
vn-tooltip="Edit discount">
{{sale.discount}} %
</td>
<td number
ng-if="!$ctrl.isEditable">
{{sale.discount}} %
</td>
<td number>{{(sale.quantity * sale.price) - ((sale.discount * (sale.quantity * sale.price))/100) | currency:' €':2}}</td>
</tr>
<tr ng-if="$ctrl.sales.length === 0 || !$ctrl.sales" class="list list-element">
<td colspan="9" style="text-align: center" translate>No results</td>
</tr>
<tfoot>
<tr>
<td number colspan="9">
<section>
<p><vn-label translate>Subtotal</vn-label> {{$ctrl.subTotal | currency:' €':2}}</p>
<p><vn-label translate>VAT</vn-label> {{$ctrl.VAT | currency:' €':2}}</p>
<p><vn-label><strong>Total</strong></vn-label> <strong>{{$ctrl.total | currency:' €':2}}</strong></p>
</section>
</td>
</tr>
</tfoot>
</tbody>
</table>
</vn-td>
<vn-td number
ng-if="!$ctrl.isEditable">
{{sale.discount}} %
</vn-td>
<vn-td number>
{{(sale.quantity * sale.price) -
((sale.discount * (sale.quantity * sale.price))/100) | currency:' €':2
}}
</vn-td>
</vn-tr>
</vn-tbody>
<vn-empty-rows ng-if="model.data.length === 0" translate>
No results
</vn-empty-rows>
<vn-tfoot>
<vn-tr ng-if="model.data.length > 0">
<vn-td></vn-td>
<vn-td></vn-td>
<vn-td></vn-td>
<vn-td></vn-td>
<vn-td></vn-td>
<vn-td></vn-td>
<vn-td></vn-td>
<vn-td></vn-td>
<vn-td number>
<section>
<p>
<vn-label translate>Subtotal</vn-label>
<span>{{$ctrl.subTotal | currency:' €':2}}</span>
</p>
<p>
<vn-label translate>VAT</vn-label>
<span>{{$ctrl.VAT | currency:' €':2}}</span>
</p>
<p>
<vn-label><strong>Total</strong></vn-label>
<strong>{{$ctrl.total | currency:' €':2}}</strong>
</p>
</section>
</vn-td>
</vn-tr>
</vn-tfoot>
</vn-table>
</vn-vertical>
</vn-card>
<vn-item-descriptor-popover vn-id="descriptor">
@ -298,7 +331,7 @@
</vn-vertical>
<vn-confirm
vn-id="deleteConfirmation"
on-response="$ctrl.deleteTicket(response)"
on-response="$ctrl.returnDeleteTicketDialog(response)"
question="You are going to delete this ticket"
message="Continue anyway?">
</vn-confirm>

View File

@ -2,12 +2,12 @@ import ngModule from '../module';
import './style.scss';
class Controller {
constructor($scope, $timeout, $stateParams, $http, vnApp, $translate) {
this.$ = $scope;
constructor($scope, $state, $http, vnApp, $translate) {
this.$scope = $scope;
this.vnApp = vnApp;
this.translate = $translate;
this.$timeout = $timeout;
this.$state = $stateParams;
this.$state = $state;
this.$stateParams = $state.params;
this.$http = $http;
this.deletable = false;
this.edit = {};
@ -20,24 +20,21 @@ class Controller {
];
}
getSales() {
this.$http.get(`/api/Tickets/${this.ticket.id}/getSales`).then(res => {
this.sales = res.data;
this.getTaxes();
});
}
$onChanges() {
if (this.ticket && this.ticket.clientFk)
this.getSales(this.ticket.clientFk);
onDataChange() {
this.sales = this.$scope.model.data;
this.getTaxes();
}
onMoreOpen() {
let options = this.moreOptions.filter(o => o.always || this.isChecked);
this.$.moreButton.data = options;
this.$scope.moreButton.data = options;
}
getTaxes() {
this.getSubTotal();
this.getVAT();
}
getSubTotal() {
let sales = this.sales;
@ -46,12 +43,14 @@ class Controller {
this.subTotal += (sale.quantity * sale.price) - ((sale.discount * (sale.quantity * sale.price)) / 100);
});
}
getVAT() {
this.$http.get(`/ticket/api/Tickets/${this.ticket.id}/getVAT`).then(res => {
this.VAT = res.data || 0;
this.total = this.subTotal + this.VAT;
});
}
get isEditable() {
try {
return !this.ticket.tracking.state.alertLevel;
@ -59,6 +58,7 @@ class Controller {
return true;
}
get isChecked() {
let data = this.sales;
if (data)
@ -68,6 +68,7 @@ class Controller {
return false;
}
getCheckedLines() {
let lines = [];
let data = this.sales;
@ -78,9 +79,11 @@ class Controller {
return lines;
}
onMoreChange(callback) {
callback.call(this);
}
// Change State
onStateOkClick() {
let filter = {where: {code: "OK"}, fields: ["id"]};
@ -89,6 +92,7 @@ class Controller {
this.onStateChange(res.data[0].id);
});
}
onStateChange(value) {
let params = {ticketFk: this.$state.params.id, stateFk: value};
this.$http.post(`/ticket/api/TicketTrackings/changeState`, params).then(() => {
@ -96,21 +100,25 @@ class Controller {
this.vnApp.showSuccess(this.translate.instant('Data saved!'));
});
}
// Add Turn
showAddTurnDialog() {
this.$.addTurn.show();
this.$scope.addTurn.show();
}
addTurn(day) {
let params = {ticketFk: this.$state.params.id, weekDay: day};
this.$http.patch(`/ticket/api/TicketWeeklies`, params).then(() => {
this.$.addTurn.hide();
this.$scope.addTurn.hide();
this.vnApp.showSuccess(this.translate.instant('Data saved!'));
});
}
// Delete Ticket
showDeleteTicketDialog() {
this.$.deleteConfirmation.show();
this.$scope.deleteConfirmation.show();
}
deleteTicket(response) {
if (response === 'ACCEPT') {
let params = {id: this.$state.params.id};
@ -120,6 +128,7 @@ class Controller {
});
}
}
// Remove Lines
onRemoveLinesClick(response) {
if (response === 'ACCEPT') {
@ -131,14 +140,17 @@ class Controller {
});
}
}
removeInstances(instances) {
for (let i = instances.length - 1; i >= 0; i--) {
this.sales.splice(instances[i].instance, 1);
}
}
showRemoveLinesDialog() {
this.$.deleteLines.show();
this.$scope.deleteLines.show();
}
// Move Lines
showTransferPopover(event) {
let filter = {clientFk: this.ticket.clientFk, ticketFk: this.ticket.id};
@ -147,9 +159,10 @@ class Controller {
this.$http.get(query).then(res => {
this.lastThreeTickets = res.data;
});
this.$.transfer.parent = event.target;
this.$.transfer.show();
this.$scope.transfer.parent = event.target;
this.$scope.transfer.show();
}
moveLines(ticketID) {
let sales = this.getCheckedLines();
@ -158,6 +171,7 @@ class Controller {
this.goToTicket(ticketID);
});
}
// In Progress
linesToNewTicket() {
let ticket = {
@ -173,13 +187,15 @@ class Controller {
this.$http.post(`/api/Sales/MoveToNewTicket`, {ticket: ticket, sales: sales}).then(res => {
let url = this.$state.href("ticket.card.sale", {id: res.data}, {absolute: true});
window.open(url, '_blank');
this.$.transfer.hide();
this.getSales();
this.$scope.transfer.hide();
this.$scope.model.refresh();
});
}
goToTicket(ticketID) {
this.$state.go("ticket.card.sale", {id: ticketID});
}
// Focus First Input
focusFirstInput(e) {
let firstFocusable = e.querySelector('input, textarea');
@ -192,21 +208,25 @@ class Controller {
}, 200);
}
}
// Slesperson Mana
getManaSalespersonMana() {
this.$http.get(`/api/Tickets/${this.$state.params.id}/getSalesPersonMana`).then(res => {
this.mana = res.data;
});
}
// Item Descriptor
showDescriptor(event, itemFk) {
this.$.descriptor.itemFk = itemFk;
this.$.descriptor.parent = event.target;
this.$.descriptor.show();
this.$scope.descriptor.itemFk = itemFk;
this.$scope.descriptor.parent = event.target;
this.$scope.descriptor.show();
}
onDescriptorLoad() {
this.$.popover.relocate();
this.$scope.popover.relocate();
}
// Edit Line
showEditPricePopover(event, sale) {
this.sale = sale;
@ -216,19 +236,21 @@ class Controller {
id: sale.id,
quantity: sale.quantity
};
this.$.editPricePopover.parent = event.target;
this.$.editPricePopover.show();
this.focusFirstInput(this.$.editPricePopover.$element[0]);
this.$scope.editPricePopover.parent = event.target;
this.$scope.editPricePopover.show();
this.focusFirstInput(this.$scope.editPricePopover.$element[0]);
}
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;
this.getSales();
this.$scope.model.refresh();
});
}
this.$.editPricePopover.hide();
this.$scope.editPricePopover.hide();
}
showEditPopover(event, sale) {
this.sale = sale;
this.edit = [{
@ -238,29 +260,33 @@ class Controller {
price: sale.price,
discount: sale.discount
}];
this.$.editPopover.parent = event.target;
this.$.editPopover.show();
this.focusFirstInput(this.$.editPopover.$element[0]);
this.$scope.editPopover.parent = event.target;
this.$scope.editPopover.show();
this.focusFirstInput(this.$scope.editPopover.$element[0]);
}
showEditDialog() {
this.edit = this.getCheckedLines();
this.$.editDialog.show();
this.focusFirstInput(this.$.editDialog.$element[0]);
this.$scope.editDialog.show();
this.focusFirstInput(this.$scope.editDialog.$element[0]);
}
hideEditDialog() {
this.getSales();
this.$.editDialog.hide();
this.$scope.model.refresh();
this.$scope.editDialog.hide();
}
hideEditPopover() {
this.getSales();
this.$.editPopover.hide();
this.$scope.model.refresh();
this.$scope.editPopover.hide();
}
updateQuantity(id, quantity) {
this.$http.post(`/ticket/api/Sales/${id}/updateQuantity`, {quantity: parseInt(quantity)}).then(() => {
this.vnApp.showSuccess(this.translate.instant('Data saved!'));
}).catch(e => {
this.vnApp.showError(this.translate.instant(e.data.error.message));
this.getSales();
this.$scope.model.refresh();
});
}
@ -283,12 +309,12 @@ class Controller {
let params = {sales: sales, ticketFk: this.ticket.id, reserved: reserved};
this.$http.post(`/ticket/api/Sales/reserve`, params).then(() => {
this.getSales();
this.$scope.model.refresh();
});
}
}
Controller.$inject = ['$scope', '$timeout', '$state', '$http', 'vnApp', '$translate'];
Controller.$inject = ['$scope', '$state', '$http', 'vnApp', '$translate'];
ngModule.component('vnTicketSale', {
template: require('./index.html'),

View File

@ -22,7 +22,7 @@ describe('Ticket', () => {
$state.params.id = 1;
controller = $componentController('vnTicketSale', {$scope: $scope}, {$state: $state});
controller.ticket = {id: 1};
controller.$ = {index: {model: {instances: [
controller.$scope = {model: {data: [
{
id: 1,
quantity: 5,
@ -41,16 +41,32 @@ describe('Ticket', () => {
return {
then: () => {}
};
}}};
}};
}));
describe('getSales()', () => {
it('should make a query and call getTaxes()', () => {
spyOn(controller, 'getTaxes');
$httpBackend.expectGET(`/api/Tickets/1/getSales`).respond();
controller.getSales();
$httpBackend.flush();
let data = [
{
id: 1,
quantity: 5,
price: 23.5,
discount: 0,
checked: true
},
{
id: 4,
quantity: 20,
price: 5.5,
discount: 0,
checked: true
}
];
spyOn(controller, 'getTaxes');
controller.onDataChange();
expect(controller.sales).toEqual(data);
expect(controller.getTaxes).toHaveBeenCalledWith();
});
});
@ -123,22 +139,22 @@ describe('Ticket', () => {
});
describe('showAddTurnDialog()', () => {
it('should call contrtoller.$.addTurn.show()', () => {
controller.$.addTurn = {show: () => {}};
spyOn(controller.$.addTurn, 'show');
it('should call contrtoller.$scope.addTurn.show()', () => {
controller.$scope.addTurn = {show: () => {}};
spyOn(controller.$scope.addTurn, 'show');
controller.showAddTurnDialog();
expect(controller.$.addTurn.show).toHaveBeenCalledWith();
expect(controller.$scope.addTurn.show).toHaveBeenCalledWith();
});
});
xdescribe('addTurn(day)', () => {
it('should make a query and call $.addTurn.hide() and vnApp.showSuccess()', () => {
controller.$.addTurn = {hide: () => {}};
spyOn(controller.$.addTurn, 'hide');
controller.$scope.addTurn = {hide: () => {}};
spyOn(controller.$scope.addTurn, 'hide');
controller.showAddTurnDialog();
expect(controller.$.addTurn.show).toHaveBeenCalledWith();
expect(controller.$scope.addTurn.show).toHaveBeenCalledWith();
});
});

View File

@ -52,7 +52,7 @@ vn-ticket-sale {
}
vn-popover.transfer{
table {
vn-table {
min-width: 650px;
margin-bottom: 10px;
}
@ -71,7 +71,7 @@ vn-ticket-sale {
}
}
table {
vn-table {
vn-textfield {
max-width: 100px;
float: right;

View File

@ -1,29 +1,42 @@
<mg-ajax path="/ticket/api/TicketTrackings/filter" options="vnIndexNonAuto"></mg-ajax>
<vn-crud-model
vn-id="model"
url="/ticket/api/TicketTrackings"
filter="::$ctrl.filter"
link="{ticketFk: $ctrl.$stateParams.id}"
limit="20"
data="trackings">
</vn-crud-model>
<vn-vertical>
<vn-card pad-large>
<vn-vertical>
<vn-title>Tracking</vn-title>
<vn-grid-header on-order="$ctrl.onOrder(field, order)">
<vn-column-header vn-one pad-medium-h field="state.name" text="State" order-locked></vn-column-header>
<vn-column-header vn-two pad-medium-h field="employee" text="Employee" order-locked></vn-column-header>
<vn-column-header vn-two pad-medium-h field="created" text="Created" default-order="ASC"></vn-column-header>
</vn-grid-header>
<vn-one class="list list-content">
<vn-horizontal
vn-one class="list list-element text-center"
pad-small-bottom
ng-repeat="ticket in index.model.instances track by ticket.id">
<vn-one pad-medium-h>{{::ticket.state.name}}</vn-one>
<vn-two pad-medium-h>{{::ticket.worker.firstName}} {{ticket.worker.name}}</vn-two>
<vn-two pad-medium-h>{{::ticket.created | date:'dd/MM/yyyy HH:mm'}}</vn-two>
</vn-horizontal>
</vn-one>
<vn-one class="text-center pad-small-v" ng-if="index.model.count === 0" translate>No results</vn-one>
<vn-horizontal vn-one class="list list-footer"></vn-horizontal>
<vn-table model="model">
<vn-thead>
<vn-tr>
<vn-th field="state">State</vn-th>
<vn-th field="worker">Worker</vn-th>
<vn-th field="created" default-order="DESC">Created</vn-th>
</vn-tr>
</vn-thead>
<vn-tbody>
<vn-tr ng-repeat="tracking in trackings">
<vn-td>{{::tracking.state.name}}</vn-td>
<vn-td>{{::tracking.worker.firstName}} {{ticket.worker.name}}</vn-td>
<vn-td>{{::tracking.created | date:'dd/MM/yyyy HH:mm'}}</vn-td>
</vn-tr>
</vn-tbody>
<vn-empty-rows ng-if="model.data.length === 0" translate>
No results
</vn-empty-rows>
</vn-table>
</vn-vertical>
<vn-pagination
model="model"
scroll-selector="ui-view">
</vn-pagination>
</vn-card>
<vn-paging vn-one margin-large-top index="index" total="index.model.count"></vn-paging>
</vn-vertical>
</vn-vertical>
<a ui-sref="ticket.card.tracking.edit" vn-bind="+" vn-visible-by="production" fixed-bottom-right>
<vn-float-button icon="add"></vn-float-button>
</a>

View File

@ -1,7 +1,30 @@
import ngModule from '../../module';
import FilterTicketList from '../../filter-ticket-list';
class Controller {
constructor($stateParams) {
this.$stateParams = $stateParams;
this.filter = {
include: [
{
relation: "worker",
scope: {
fields: ["firstName", "name"]
}
},
{
relation: "state",
scope: {
fields: ["name"]
}
}
]
};
}
}
Controller.$inject = ['$stateParams'];
ngModule.component('vnTicketTrackingIndex', {
template: require('./index.html'),
controller: FilterTicketList
controller: Controller
});

View File

@ -1,5 +1,12 @@
<mg-ajax path="/ticket/api/sales/filter" options="vnIndexNonAuto" actions="$ctrl.setVolumes()"></mg-ajax>
<mg-ajax path="/client/api/tickets/{{edit.params.id}}/getTotalVolume" options="mgEdit"></mg-ajax>
<vn-crud-model
vn-id="model"
url="/ticket/api/sales"
filter="::$ctrl.filter"
link="{itemFk: $ctrl.$stateParams.id}"
limit="20"
data="sales" on-data-change="$ctrl.onDataChange()">
</vn-crud-model>
<mg-ajax path="/client/api/tickets/{{$ctrl.$stateParams.id}}/getTotalVolume" options="mgEdit"></mg-ajax>
<vn-vertical>
<vn-card pad-large>
<vn-vertical>
@ -12,31 +19,36 @@
value="{{::edit.model.totalBoxes}}">
</vn-label-value>
</vn-one>
<table class="vn-grid">
<thead>
<tr>
<th number translate>Item</th>
<th translate>Description</th>
<th number translate>Quantity</th>
<th number translate>m³ per quantity</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="sale in index.model.instances track by sale.id" class="list list-element">
<td number pointer
ng-click="$ctrl.showDescriptor($event, sale.itemFk)">{{::sale.itemFk}}</td>
<td><vn-fetched-tags sale="sale"/></td>
<td number>{{::sale.quantity}}</td>
<td number>{{::sale.volume.m3 | number:3}}</td>
</tr>
<tr ng-if="index.model.count === 0" class="list list-element">
<td colspan="6" style="text-align: center" translate>No results</td>
</tr>
</tbody>
</table>
<vn-table model="model">
<vn-thead>
<vn-tr>
<vn-th field="itemFk" number>Item</vn-th>
<vn-th field="concept" default-order="ASC">Description</vn-th>
<vn-th field="quantity" number>Quantity</vn-th>
<vn-th number>m³ per quantity</vn-th>
</vn-tr>
</vn-thead>
<vn-tbody>
<vn-tr ng-repeat="sale in sales">
<vn-td number pointer
ng-click="$ctrl.showDescriptor($event, sale.itemFk)">
{{::sale.itemFk}}
</vn-td>
<vn-td><vn-fetched-tags sale="sale"/></vn-td>
<vn-td number>{{::sale.quantity}}</vn-td>
<vn-td number>{{::sale.volume.m3 | number:3}}</vn-td>
</vn-tr>
</vn-tbody>
<vn-empty-rows ng-if="model.data.length === 0" translate>
No results
</vn-empty-rows>
</vn-table>
</vn-vertical>
<vn-pagination
model="model"
scroll-selector="ui-view">
</vn-pagination>
</vn-card>
<vn-paging vn-one margin-large-top index="index" total="index.model.count"></vn-paging>
</vn-vertical>
</vn-vertical>
<vn-item-descriptor-popover vn-id="descriptor"></vn-item-descriptor-popover>

View File

@ -1,24 +1,41 @@
import ngModule from '../module';
import FilterTicketList from '../filter-ticket-list';
import './style.scss';
class Controller extends FilterTicketList {
constructor($scope, $http, $translate, $timeout, $state) {
super($scope, $timeout, $state);
class Controller {
constructor($scope, $http, $stateParams) {
this.$scope = $scope;
this.$http = $http;
this.$translate = $translate;
this.onOrder('itemFk', 'ASC');
this.$stateParams = $stateParams;
this.filter = {
include: [{
relation: 'item',
scope: {
include: {
relation: 'tags',
scope: {
fields: ['tagFk', 'value'],
include: {
relation: 'tag',
scope: {
fields: ['name']
}
},
limit: 6
}
},
fields: ['itemFk', 'name']
}
}]
};
this.ticketVolumes = [];
}
setVolumes() {
if (!this.$scope.index) return;
onDataChange() {
this.$http.get(`/api/tickets/${this.ticket.id}/getVolume`)
.then(response => {
if (response.data) {
this.$scope.index.model.instances.forEach(sale => {
this.$scope.model.data.forEach(sale => {
response.data.volumes.forEach(volume => {
if (sale.id === volume.saleFk) {
sale.volume = volume;
@ -40,7 +57,7 @@ class Controller extends FilterTicketList {
}
}
Controller.$inject = ['$scope', '$http', '$translate', '$timeout', '$state'];
Controller.$inject = ['$scope', '$http', '$stateParams'];
ngModule.component('vnTicketVolume', {
template: require('./index.html'),

View File

@ -17,7 +17,7 @@ describe('ticket', () => {
$httpBackend = _$httpBackend_;
$httpBackend.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({});
$scope = $rootScope.$new();
$scope.index = {model: {instances: [{id: 1}, {id: 2}]}, accept: () => {
$scope.model = {data: [{id: 1}, {id: 2}], accept: () => {
return {
then: () => {}
};
@ -32,11 +32,11 @@ describe('ticket', () => {
let response = {volumes: [{saleFk: 1, m3: 0.008}, {saleFk: 2, m3: 0.003}]};
$httpBackend.whenGET(`/api/tickets/1/getVolume`).respond(response);
$httpBackend.expectGET(`/api/tickets/1/getVolume`);
controller.setVolumes();
controller.onDataChange();
$httpBackend.flush();
expect($scope.index.model.instances[0].volume.m3).toBe(0.008);
expect($scope.index.model.instances[1].volume.m3).toBe(0.003);
expect($scope.model.data[0].volume.m3).toBe(0.008);
expect($scope.model.data[1].volume.m3).toBe(0.003);
});
});
});

View File

@ -292,8 +292,8 @@ export default {
},
ticketExpedition: {
expeditionButton: `vn-menu-item a[ui-sref="ticket.card.expedition"]`,
secondExpeditionRemoveButton: `body > vn-app > vn-vertical > vn-vertical > ui-view > vn-ticket-card > vn-main-block > vn-horizontal > vn-one > vn-vertical > vn-ticket-expedition > vn-vertical > vn-card > div > vn-vertical > vn-one > vn-horizontal:nth-child(2) > vn-one:nth-child(1) > i`,
secondExpeditionText: `body > vn-app > vn-vertical > vn-vertical > ui-view > vn-ticket-card > vn-main-block > vn-horizontal > vn-one > vn-vertical > vn-ticket-expedition > vn-vertical > vn-card > div > vn-vertical > vn-one > vn-horizontal:nth-child(2)`
secondExpeditionRemoveButton: `vn-ticket-expedition vn-table div > vn-tbody > vn-tr:nth-child(2) > vn-td:nth-child(1) > i`,
secondExpeditionText: `vn-ticket-expedition vn-table div > vn-tbody > vn-tr:nth-child(2)`
},
ticketPackages: {
packagesButton: `vn-menu-item a[ui-sref="ticket.card.package.index"]`,
@ -307,14 +307,14 @@ export default {
},
ticketSales: {
saleButton: `vn-menu-item a[ui-sref="ticket.card.sale"]`,
firstSaleText: `table > tbody > tr:nth-child(1)`,
secondSaleText: `table > tbody > tr:nth-child(2)`
firstSaleText: `vn-table div > vn-tbody > vn-tr:nth-child(1)`,
secondSaleText: `vn-table div > vn-tbody > vn-tr:nth-child(2)`
},
ticketTracking: {
trackingButton: `vn-menu-item a[ui-sref="ticket.card.tracking.index"]`,
createStateButton: `${components.vnFloatButton}`,
firstSaleText: `table > tbody > tr:nth-child(1)`,
secondSaleText: `table > tbody > tr:nth-child(2)`
firstSaleText: `vn-table div > vn-tbody > vn-tr:nth-child(1)`,
secondSaleText: `vn-table div > vn-tbody > vn-tr:nth-child(2)`
},
createStateView: {
stateInput: `vn-autocomplete[field="$ctrl.ticket.stateFk"] > div > div > input`,

View File

@ -1,7 +1,7 @@
import selectors from '../../helpers/selectors.js';
import createNightmare from '../../helpers/helpers';
describe('Item', () => {
fdescribe('Item', () => {
describe('Create botanical path', () => {
const nightmare = createNightmare();

View File

@ -46,7 +46,7 @@ describe('Ticket', () => {
});
});
it('should confirm the fist ticket sale is the expected one', () => {
it('should confirm the first ticket sale is the expected one', () => {
return nightmare
.wait(selectors.ticketSales.firstSaleText)
.getInnerText(selectors.ticketSales.firstSaleText)

View File

@ -20,6 +20,9 @@
},
"life": {
"type": "Number"
},
"isPackaging": {
"type": "Boolean"
}
},
"relations": {

View File

@ -45,6 +45,16 @@
"type": "belongsTo",
"model": "Worker",
"foreignKey": "workerFk"
},
"packages": {
"type": "hasMany",
"model": "TicketPackaging",
"foreignKey": "ticketFk"
},
"box": {
"type": "belongsTo",
"model": "Item",
"foreignKey": "isBox"
}
}
}