Bug #422 refactorizar el summary de item y añadir el visible y avaible

This commit is contained in:
gerard 2018-07-23 09:58:07 +02:00
parent 9a80f22e93
commit 72d9212262
6 changed files with 183 additions and 102 deletions

View File

@ -51,4 +51,5 @@ Remove barcode: Quitar código de barras
Buyer: Comprador
No results: Sin resultados
Tag: Etiqueta
Worker: Trabajador
Worker: Trabajador
Available: Disponible

View File

@ -3,50 +3,60 @@
<vn-horizontal>
<vn-auto margin-medium>
<vn-vertical>
<vn-one>
<img
ng-src="//verdnatura.es/vn-image-data/catalog/200x200/{{$ctrl.item.image}}"
zoom-image="//verdnatura.es/vn-image-data/catalog/1600x900/{{$ctrl.item.image}}" on-error-src/>
</vn-one>
<vn-one>
<h5 text-center pad-small-v class="title">{{$ctrl.item.id}}</h5>
</vn-one>
<vn-one>
<img
ng-src="//verdnatura.es/vn-image-data/catalog/200x200/{{::$ctrl.item.image}}"
zoom-image="//verdnatura.es/vn-image-data/catalog/1600x900/{{::$ctrl.item.image}}" on-error-src/>
</vn-one>
<vn-horizontal class="state">
<vn-one>
<p class="title" uppercase text-center>Visible</p>
<h5 class="title" text-center>{{::$ctrl.summary.visible}}</h5>
</vn-one>
<vn-one>
<p class="title" uppercase translate text-center>Available</p>
<h5 text-center class="title">{{::$ctrl.summary.available}}</h5>
</vn-one>
</vn-horizontal>
</vn-vertical>
</vn-auto>
<vn-one margin-medium>
<vn-vertical name="basicData">
<h5 translate>Basic data</h5>
<vn-label-value label="Name"
value="{{$ctrl.item.name}}">
value="{{::$ctrl.summary.item.name}}">
</vn-label-value>
<vn-label-value label="Type"
value="{{$ctrl.item.itemType.name}}">
value="{{::$ctrl.summary.item.itemType.name}}">
</vn-label-value>
<vn-label-value label="Intrastat code"
value="{{$ctrl.item.intrastat.id}}">
value="{{::$ctrl.summary.item.intrastat.id}}">
</vn-label-value>
<vn-label-value label="Intrastat"
value="{{$ctrl.item.intrastat.description}}">
value="{{::$ctrl.summary.item.intrastat.description}}">
</vn-label-value>
<vn-label-value label="Relevancy"
value="{{$ctrl.item.relevancy}}">
value="{{::$ctrl.summary.item.relevancy}}">
</vn-label-value>
<vn-label-value label="Origin"
value="{{$ctrl.item.origin.name}}">
value="{{::$ctrl.summary.item.origin.name}}">
</vn-label-value>
<vn-label-value label="Expence"
value="{{$ctrl.item.expence.name}}">
value="{{::$ctrl.summary.item.expence.name}}">
</vn-label-value>
<vn-label-value label="Buyer"
value="{{$ctrl.item.itemType.worker.firstName}} {{$ctrl.item.itemType.worker.name}}">
value="{{::$ctrl.summary.item.itemType.worker.firstName}} {{::$ctrl.summary.item.itemType.worker.name}}">
</vn-label-value>
</vn-vertical>
</vn-one>
<vn-one margin-medium>
<vn-vertical name="tax">
<h5 translate>Tax</h5>
<vn-label-value label="{{tax.country.country}}" ng-repeat="tax in $ctrl.taxes track by $index"
value="{{tax.taxClass.description}}">
<vn-label-value label="{{::tax.country.country}}" ng-repeat="tax in $ctrl.summary.item.taxes track by $index"
value="{{::tax.taxClass.description}}">
</vn-label-value>
</vn-vertical>
</vn-one>
@ -55,16 +65,16 @@
<vn-one margin-medium>
<vn-vertical name="tags">
<h5 translate>Tags</h5>
<vn-label-value label="{{tag.tag.name}}" ng-repeat="tag in $ctrl.tags track by tag.id"
value="{{tag.value}}">
<vn-label-value label="{{::tag.tag.name}}" ng-repeat="tag in $ctrl.summary.tags track by tag.id"
value="{{::tag.value}}">
</vn-label-value>
</vn-vertical>
</vn-one>
<vn-one margin-medium>
<vn-vertical name="niche">
<h5 translate>Niche</h5>
<vn-label-value label="{{niche.warehouse.name}}" ng-repeat="niche in $ctrl.niches track by $index"
value="{{niche.code}}">
<vn-label-value label="{{::niche.warehouse.name}}" ng-repeat="niche in $ctrl.summary.niches track by $index"
value="{{::niche.code}}">
</vn-label-value>
</vn-vertical>
</vn-one>
@ -72,20 +82,20 @@
<vn-vertical name="botanical">
<h5 translate>Botanical</h5>
<vn-label-value label="Botanical"
value="{{$ctrl.item.botanical.botanical}}">
value="{{::$ctrl.summary.botanical.botanical}}">
</vn-label-value>
<vn-label-value label="Genus"
value="{{$ctrl.item.botanical.genus.latin_genus_name}}">
value="{{::$ctrl.summary.botanical.genus.latin_genus_name}}">
</vn-label-value>
<vn-label-value label="Specie"
value="{{$ctrl.item.botanical.specie.latin_species_name}}">
value="{{::$ctrl.summary.botanical.specie.latin_species_name}}">
</vn-label-value>
</vn-vertical>
</vn-one>
<vn-one margin-medium>
<vn-vertical name="barcode">
<h5 translate>Barcode</h5>
<p ng-repeat="barcode in $ctrl.barcodes track by $index">
<p ng-repeat="barcode in $ctrl.summary.barcodes track by $index">
<b>{{barcode.code}}</b>
</p>
</vn-vertical>

View File

@ -5,86 +5,19 @@ class Controller {
this.$http = $http;
}
_getTags() {
let filter = {
where: {
itemFk: this.item.id
}
};
this.tags = [];
this.$http.get(`/item/api/ItemTags?filter=${JSON.stringify(Object.assign({}, filter, {include: {relation: 'tag'}}))}`).then(res => {
this.tags = res.data;
});
}
_getTaxes() {
let filter = {
fields: ['id', 'countryFk', 'taxClassFk'],
include: [{
relation: 'country',
scope: {fields: ['country']}
}, {
relation: 'taxClass',
scope: {fields: ['id', 'description']}
}]
};
let urlFilter = encodeURIComponent(JSON.stringify(filter));
let url = `/item/api/Items/${this.item.id}/taxes?filter=${urlFilter}`;
this.$http.get(url).then(json => {
this.taxes = json.data;
});
}
_getBotanical() {
let filter = {
where: {itemFk: this.item.id},
include: [{relation: 'genus'}, {relation: 'specie'}]
};
this.item.botanical = {};
this.$http.get(`/item/api/ItemBotanicals?filter=${JSON.stringify(filter)}`)
.then(res => {
if (res.data.length) {
this.item.botanical = res.data[0];
}
});
}
_getNiches() {
let filter = {
where: {itemFk: this.item.id},
include: {relation: 'warehouse'}
};
this.$http.get(`/item/api/ItemNiches?filter=${JSON.stringify(filter)}`).then(response => {
this.niches = response.data;
});
}
_getBarcodes() {
let filter = {
where: {
itemFk: this.item.id
}
};
this.barcodes = [];
this.$http.get(`/item/api/ItemBarcodes?filter=${JSON.stringify(filter)}`).then(response => {
this.barcodes = response.data;
getSummary() {
this.$http.get(`/item/api/Items/${this.item.id}/getSummary`).then(response => {
this.summary = response.data;
});
}
$onChanges() {
if (this.item && this.item.id) {
this._getTags();
this._getBarcodes();
this._getNiches();
this._getTaxes();
if (!this.item.botanical)
this._getBotanical();
}
if (this.item && this.item.id)
this.getSummary();
}
}
Controller.$inject = ['$http'];
Controller.$inject = ['$http', '$stateParams'];
ngModule.component('vnItemSummary', {
template: require('./index.html'),

View File

@ -3,15 +3,12 @@
.summary{
h5 {
border-bottom: 2px solid $main-01;
margin: 0 0 5px 0
}
h5.title {
.title, p.title {
border: none;
background: $main-01;
color: $color-white;
}
p {
margin: 0 0 5px 0
margin: 0!important;
}
p:after {
content: ' ';
@ -23,4 +20,36 @@
vn-label-value > section {
margin-bottom: .3em
}
}
.state {
@extend .summary;
vn-one:nth-child(1){
border-right: 1px solid white;
}
p {
font-size: 12px;
line-height: 20px!important;
margin: 0 0 5px 0;
}
h5 {
line-height: 10px!important;
}
vn-one {
padding: 0;
}
vn-one > h5{
padding-bottom: 7px;
}
}
vn-item-descriptor .state{
@extend .state;
vn-one > p{
padding-top: 5px;
}
vn-one > h5{
padding-bottom: 12px;
}
}

View File

@ -0,0 +1,107 @@
module.exports = Self => {
Self.remoteMethod('getSummary', {
description: 'Updates the item taxes',
accessType: 'READ',
accepts: [{
arg: 'id',
type: 'number',
required: true,
description: 'The item id',
http: {source: 'path'}
}],
returns: {
type: 'object',
root: true
},
http: {
path: `/:id/getSummary`,
verb: 'GET'
}
});
Self.getSummary = async id => {
let summary = {};
// Item basic data and taxes
let filter = {
where: {id: id},
include: [
{relation: 'itemType',
scope: {
fields: ['id', 'name', 'workerFk', 'warehouseFk'],
include: [{
relation: 'worker',
scope: {
fields: ['id', 'name', 'firstName']
}
}]
}
},
{relation: 'intrastat'},
{relation: 'expence'},
{relation: 'origin'},
{relation: 'taxes',
scope: {
fields: ['id', 'countryFk', 'taxClassFk'],
include: [{
relation: 'country',
scope: {
fields: ['id', 'country']
}
}, {
relation: 'taxClass',
scope: {
fields: ['id', 'description']
}
}]
}
}
]
};
[summary.item] = await Self.app.models.Item.find(filter);
// Tags
filter = {
where: {
itemFk: id
},
include: {
relation: 'tag'
}
};
summary.tags = await Self.app.models.ItemTag.find(filter);
// Botanical
filter = {
where: {itemFk: id},
include: [{relation: 'genus'}, {relation: 'specie'}]
};
[summary.botanical] = await Self.app.models.ItemBotanical.find(filter);
// Niches
filter = {
where: {itemFk: id},
include: {relation: 'warehouse'}
};
summary.niches = await Self.app.models.ItemNiche.find(filter);
// Barcodes
filter = {
where: {
itemFk: id
}
};
summary.barcodes = await Self.app.models.ItemNiche.find(filter);
// Visible Avaible
let query = `
CALL vn.getItemVisibleAvailable(?,curdate(),?,?)`;
let options = [summary.item.id, summary.item.itemType().warehouseFk, false];
let [res] = await Self.rawSql(query, options);
summary.available = res[0].available ? res[0].available : '-';
summary.visible = res[0].visible ? res[0].visible : '-';
return summary;
};
};

View File

@ -6,6 +6,7 @@ module.exports = Self => {
require('../methods/item/updateTaxes')(Self);
require('../methods/item/getDiary')(Self);
require('../methods/item/getLastEntries')(Self);
require('../methods/item/getSummary')(Self);
Self.validatesPresenceOf('name', {message: 'Cannot be blank'});
Self.validatesPresenceOf('originFk', {message: 'Cannot be blank'});