item crud model refactor #372
This commit is contained in:
parent
4cf5777b4e
commit
75d7c79af1
|
@ -1,28 +1,41 @@
|
||||||
<mg-ajax path="/item/api/ItemLogs/getLog" options="vnIndexNonAuto"></mg-ajax>
|
<vn-crud-model
|
||||||
|
vn-id="model"
|
||||||
|
url="/item/api/ItemLogs"
|
||||||
|
filter="::$ctrl.filter"
|
||||||
|
link="{originFk: $ctrl.$stateParams.id}"
|
||||||
|
limit="20"
|
||||||
|
data="logs">
|
||||||
|
</vn-crud-model>
|
||||||
|
|
||||||
<vn-vertical>
|
<vn-vertical>
|
||||||
<vn-card pad-large>
|
<vn-card pad-large>
|
||||||
<vn-vertical>
|
<vn-vertical>
|
||||||
<vn-title>Item history</vn-title>
|
<vn-title>Item history</vn-title>
|
||||||
<vn-grid-header on-order="$ctrl.onOrder(field, order)">
|
<vn-table model="model">
|
||||||
<vn-column-header vn-two pad-medium-h field="description" text="Description"></vn-column-header>
|
<vn-thead>
|
||||||
<vn-column-header vn-one pad-medium-h field="action" text="Action"></vn-column-header>
|
<vn-tr>
|
||||||
<vn-column-header vn-one pad-medium-h field="userFk" text="Changed by"></vn-column-header>
|
<vn-th field="description">Description</vn-th>
|
||||||
<vn-column-header vn-one pad-medium-h field="creationDate" text="Date" default-order="ASC"></vn-column-header>
|
<vn-th field="action">Action</vn-th>
|
||||||
</vn-grid-header>
|
<vn-th field="userFk">Changed by</vn-th>
|
||||||
<vn-one class="list list-content">
|
<vn-th field="creationDate" default-order="DESC">Date</vn-th>
|
||||||
<vn-horizontal
|
</vn-tr>
|
||||||
class="list list-element text-center"
|
</vn-thead>
|
||||||
pad-small-bottom
|
<vn-tbody>
|
||||||
ng-repeat="itemLog in index.model.instances track by itemLog.id">
|
<vn-tr ng-repeat="itemLog in logs">
|
||||||
<vn-two pad-medium-h>{{::itemLog.description}}</vn-two>
|
<vn-td>{{::itemLog.description}}</vn-td>
|
||||||
<vn-one pad-medium-h>{{::itemLog.action}}</vn-one>
|
<vn-td>{{::itemLog.action}}</vn-td>
|
||||||
<vn-one pad-medium-h>{{::itemLog.user.name}}</vn-one>
|
<vn-td>{{::itemLog.user.name}}</vn-td>
|
||||||
<vn-one pad-medium-h>{{::itemLog.creationDate | date:'dd/MM/yyyy HH:mm'}}</vn-one>
|
<vn-td>{{::itemLog.creationDate | date:'dd/MM/yyyy HH:mm'}}</vn-td>
|
||||||
</vn-horizontal>
|
</vn-tr>
|
||||||
</vn-one>
|
</vn-tbody>
|
||||||
<vn-one class="text-center pad-small-v" ng-if="index.model.count === 0" translate>No results</vn-one>
|
<vn-empty-rows ng-if="model.data.length === 0" translate>
|
||||||
<vn-horizontal vn-one class="list list-footer text-center"></vn-horizontal>
|
No results
|
||||||
|
</vn-empty-rows>
|
||||||
|
</vn-table>
|
||||||
</vn-vertical>
|
</vn-vertical>
|
||||||
|
<vn-pagination
|
||||||
|
model="model"
|
||||||
|
scroll-selector="ui-view">
|
||||||
|
</vn-pagination>
|
||||||
</vn-card>
|
</vn-card>
|
||||||
<vn-paging vn-one margin-large-top index="index" total="index.model.count"></vn-paging>
|
|
||||||
</vn-vertical>
|
</vn-vertical>
|
||||||
|
|
|
@ -1,7 +1,25 @@
|
||||||
import ngModule from '../module';
|
import ngModule from '../module';
|
||||||
import FilterItemList from '../filter-item-list';
|
|
||||||
|
class Controller {
|
||||||
|
constructor($stateParams) {
|
||||||
|
this.$stateParams = $stateParams;
|
||||||
|
this.filter = {
|
||||||
|
include: [{
|
||||||
|
relation: "item"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
relation: "user",
|
||||||
|
scope: {
|
||||||
|
fields: ["name"]
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Controller.$inject = ['$stateParams'];
|
||||||
|
|
||||||
ngModule.component('vnItemHistory', {
|
ngModule.component('vnItemHistory', {
|
||||||
template: require('./index.html'),
|
template: require('./index.html'),
|
||||||
controller: FilterItemList
|
controller: Controller
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,3 +1,9 @@
|
||||||
|
<vn-crud-model
|
||||||
|
vn-id="model"
|
||||||
|
url="/item/api/Items/getLastEntries"
|
||||||
|
filter="::$ctrl.filter"
|
||||||
|
data="entries">
|
||||||
|
</vn-crud-model>
|
||||||
<vn-vertical>
|
<vn-vertical>
|
||||||
<vn-card pad-large>
|
<vn-card pad-large>
|
||||||
<vn-vertical>
|
<vn-vertical>
|
||||||
|
@ -6,62 +12,65 @@
|
||||||
<vn-date-picker
|
<vn-date-picker
|
||||||
vn-one
|
vn-one
|
||||||
label="Since"
|
label="Since"
|
||||||
model="$ctrl.entriesDate"
|
model="$ctrl.date"
|
||||||
ini-options="{dateFormat: 'd-m-Y'}">
|
ini-options="{dateFormat: 'd-m-Y'}">
|
||||||
</vn-date-picker>
|
</vn-date-picker>
|
||||||
<!--datepicker-->
|
<!--datepicker-->
|
||||||
</vn-horizontal>
|
</vn-horizontal>
|
||||||
<table class="vn-grid">
|
<vn-table model="model">
|
||||||
<thead>
|
<vn-thead>
|
||||||
<tr>
|
<vn-tr>
|
||||||
<th number vn-tooltip="Ignored">Ig</th>
|
<vn-th number vn-tooltip="Ignored">Ig</vn-th>
|
||||||
<th number translate>Warehouse</th>
|
<vn-th number>Warehouse</vn-th>
|
||||||
<th number translate>Landed</th>
|
<vn-th number>Landed</vn-th>
|
||||||
<th number translate>Entry</th>
|
<vn-th number>Entry</vn-th>
|
||||||
<th number vn-tooltip="Price Per Unit">P.P.U</th>
|
<vn-th number vn-tooltip="Price Per Unit">P.P.U</vn-th>
|
||||||
<th number vn-tooltip="Price Per Package">P.P.P</th>
|
<vn-th number vn-tooltip="Price Per Package">P.P.P</vn-th>
|
||||||
<th number class="expendable" translate>Label</th>
|
<vn-th number class="expendable">Label</vn-th>
|
||||||
<th number>Packing</th>
|
<vn-th number>Packing</vn-th>
|
||||||
<th number>Grouping</th>
|
<vn-th number>Grouping</vn-th>
|
||||||
<th number class="expendable" translate>Stems</th>
|
<vn-th number class="expendable">Stems</vn-th>
|
||||||
<th number translate>Quantity</th>
|
<vn-th number>Quantity</vn-th>
|
||||||
<th number class="expendable" translate>Cost</th>
|
<vn-th number class="expendable">Cost</vn-th>
|
||||||
<th number translate>Cube</th>
|
<vn-th number>Cube</vn-th>
|
||||||
<th number class="expendable" translate>Provider</th>
|
<vn-th number class="expendable">Provider</vn-th>
|
||||||
</tr>
|
</vn-tr>
|
||||||
</thead>
|
</vn-thead>
|
||||||
<tbody>
|
<vn-tbody>
|
||||||
<tr ng-repeat="entries in $ctrl.entries">
|
<vn-tr ng-repeat="entry in entries">
|
||||||
<td number>
|
<vn-td number>
|
||||||
<vn-check
|
<vn-check
|
||||||
field="entries.isIgnored"
|
field="entries.isIgnored"
|
||||||
disabled="true">
|
disabled="true">
|
||||||
</vn-check>
|
</vn-check>
|
||||||
</td>
|
</vn-td>
|
||||||
<td number>{{entries.warehouse| dashIfEmpty}}</td>
|
<vn-td number>{{entry.warehouse| dashIfEmpty}}</vn-td>
|
||||||
<td number>{{entries.landed | date:'dd/MM/yyyy HH:mm'}}</td>
|
<vn-td number>{{entry.landed | date:'dd/MM/yyyy HH:mm'}}</vn-td>
|
||||||
<td number>{{entries.entryFk | dashIfEmpty}}</td>
|
<vn-td number>{{entry.entryFk | dashIfEmpty}}</vn-td>
|
||||||
<td number>{{entries.price2 | dashIfEmpty}}</td>
|
<vn-td number>{{entry.price2 | dashIfEmpty}}</vn-td>
|
||||||
<td number>{{entries.price3 | dashIfEmpty}}</td>
|
<vn-td number>{{entry.price3 | dashIfEmpty}}</vn-td>
|
||||||
<td number class="expendable">{{entries.stickers | dashIfEmpty}}</td>
|
<vn-td number class="expendable">{{entry.stickers | dashIfEmpty}}</vn-td>
|
||||||
<td number>
|
<vn-td number>
|
||||||
<div ng-class="{'round': entries.groupingMode == 2}">{{entries.packing | dashIfEmpty}}</div>
|
<div ng-class="{'counter': entry.groupingMode == 2}">{{entry.packing | dashIfEmpty}}</div>
|
||||||
</td>
|
</vn-td>
|
||||||
<td number>
|
<vn-td number>
|
||||||
<div ng-class="{'round': entries.groupingMode == 1}">{{entries.grouping | dashIfEmpty}}</div>
|
<span ng-class="{'counter': entry.groupingMode == 1}">{{entry.grouping | dashIfEmpty}}</span>
|
||||||
</td>
|
</vn-td>
|
||||||
<td number class="expendable">{{entries.stems | dashIfEmpty}}</td>
|
<vn-td number class="expendable">{{entry.stems | dashIfEmpty}}</vn-td>
|
||||||
<td number>{{entries.quantity}}</td>
|
<vn-td number>{{entry.quantity}}</vn-td>
|
||||||
<td number class="expendable">{{entries.buyingValue | dashIfEmpty}}</td>
|
<vn-td number class="expendable">{{entry.buyingValue | dashIfEmpty}}</vn-td>
|
||||||
<td number>{{entries.packageFk | dashIfEmpty}}</td>
|
<vn-td number>{{entry.packageFk | dashIfEmpty}}</vn-td>
|
||||||
<td number class="expendable">{{entries.supplier | dashIfEmpty}}</td>
|
<vn-td number class="expendable">{{entry.supplier | dashIfEmpty}}</vn-td>
|
||||||
</tr>
|
</vn-tr>
|
||||||
<tr ng-if="$ctrl.entries.length === 0" class="list list-element">
|
</vn-tbody>
|
||||||
<td colspan="14" style="text-align: center" translate>No results</td>
|
<vn-empty-rows ng-if="model.data.length === 0" translate>
|
||||||
</tr>
|
No results
|
||||||
</tbody>
|
</vn-empty-rows>
|
||||||
</table>
|
</vn-table>
|
||||||
</vn-vertical>
|
</vn-vertical>
|
||||||
|
<vn-pagination
|
||||||
|
model="model"
|
||||||
|
scroll-selector="ui-view">
|
||||||
|
</vn-pagination>
|
||||||
</vn-card>
|
</vn-card>
|
||||||
<vn-paging margin-large-top vn-one index="$ctrl.entries" total="$ctrl.entries.count"></vn-paging>
|
|
||||||
</vn-vertical>
|
</vn-vertical>
|
||||||
|
|
|
@ -2,50 +2,38 @@ import ngModule from '../module';
|
||||||
import './style.scss';
|
import './style.scss';
|
||||||
|
|
||||||
class Controller {
|
class Controller {
|
||||||
constructor($scope, $http) {
|
constructor($scope, $stateParams) {
|
||||||
this.$ = $scope;
|
this.$scope = $scope;
|
||||||
this.$http = $http;
|
this.$stateParams = $stateParams;
|
||||||
this.entries = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
set item(value) {
|
let defaultDate = new Date();
|
||||||
this._item = value;
|
|
||||||
this._defaultEntriesDate();
|
|
||||||
this._getLastEntries();
|
|
||||||
}
|
|
||||||
|
|
||||||
get item() {
|
|
||||||
return this._item;
|
|
||||||
}
|
|
||||||
|
|
||||||
set entriesDate(value) {
|
|
||||||
this._entriesDate = value;
|
|
||||||
this._getLastEntries();
|
|
||||||
}
|
|
||||||
|
|
||||||
get entriesDate() {
|
|
||||||
return this._entriesDate;
|
|
||||||
}
|
|
||||||
|
|
||||||
_defaultEntriesDate() {
|
|
||||||
let defaultDate;
|
|
||||||
defaultDate = new Date();
|
|
||||||
defaultDate.setDate(defaultDate.getDate() - 75);
|
defaultDate.setDate(defaultDate.getDate() - 75);
|
||||||
defaultDate.setHours(0, 0, 0, 0);
|
defaultDate.setHours(0, 0, 0, 0);
|
||||||
this._entriesDate = defaultDate;
|
|
||||||
|
this.filter = {
|
||||||
|
where: {
|
||||||
|
itemFk: $stateParams.id,
|
||||||
|
date: defaultDate
|
||||||
|
}
|
||||||
|
};
|
||||||
|
this._date = defaultDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
_getLastEntries() {
|
set date(value) {
|
||||||
if (!this.entriesDate || !this.item)
|
this._date = value;
|
||||||
return;
|
|
||||||
let filter = {itemFk: this.item.id, date: this.entriesDate};
|
if (!value) return;
|
||||||
this.$http.get(`/item/api/Items/getLastEntries?filter=${JSON.stringify(filter)}`).then(res => {
|
|
||||||
this.entries = res.data;
|
this.filter.where.date = value;
|
||||||
});
|
this.$scope.model.refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
get date() {
|
||||||
|
return this._date;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Controller.$inject = ['$scope', '$http'];
|
Controller.$inject = ['$scope', '$stateParams'];
|
||||||
|
|
||||||
ngModule.component('vnItemLastEntries', {
|
ngModule.component('vnItemLastEntries', {
|
||||||
template: require('./index.html'),
|
template: require('./index.html'),
|
||||||
|
|
|
@ -1,71 +0,0 @@
|
||||||
import './index.js';
|
|
||||||
|
|
||||||
describe('Item', () => {
|
|
||||||
describe('Component vnItemLastEntries', () => {
|
|
||||||
let $componentController;
|
|
||||||
let $scope;
|
|
||||||
let controller;
|
|
||||||
let $httpBackend;
|
|
||||||
let defaultDate;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
angular.mock.module('item');
|
|
||||||
});
|
|
||||||
|
|
||||||
beforeEach(angular.mock.inject((_$componentController_, $rootScope, _$httpBackend_) => {
|
|
||||||
$componentController = _$componentController_;
|
|
||||||
$httpBackend = _$httpBackend_;
|
|
||||||
$httpBackend.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({});
|
|
||||||
$scope = $rootScope.$new();
|
|
||||||
controller = $componentController('vnItemLastEntries', {$scope: $scope});
|
|
||||||
controller.item = {id: 3};
|
|
||||||
}));
|
|
||||||
|
|
||||||
describe('set item()', () => {
|
|
||||||
it(`should set item and call _defaultEntriesDate() and _getLastEntries()`, () => {
|
|
||||||
spyOn(controller, '_defaultEntriesDate');
|
|
||||||
spyOn(controller, '_getLastEntries');
|
|
||||||
controller.item = [];
|
|
||||||
|
|
||||||
expect(controller._defaultEntriesDate).toHaveBeenCalledWith();
|
|
||||||
expect(controller._getLastEntries).toHaveBeenCalledWith();
|
|
||||||
expect(controller.item).toEqual([]);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('set entriesDate()', () => {
|
|
||||||
it(`should set entriesDate and call _getLastEntries()`, () => {
|
|
||||||
spyOn(controller, '_getLastEntries');
|
|
||||||
controller.item = [];
|
|
||||||
controller.entriesDate = new Date();
|
|
||||||
|
|
||||||
expect(controller._getLastEntries).toHaveBeenCalledWith();
|
|
||||||
expect(controller.item).toEqual([]);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('_defaultEntriesDate()', () => {
|
|
||||||
it(`should set entriesDate to a date 75 days ago`, () => {
|
|
||||||
defaultDate = new Date();
|
|
||||||
defaultDate.setDate(defaultDate.getDate() - 75);
|
|
||||||
defaultDate.setHours(0, 0, 0, 0);
|
|
||||||
controller._defaultEntriesDate();
|
|
||||||
|
|
||||||
expect(controller.entriesDate).toEqual(defaultDate);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('_getLastEntries()', () => {
|
|
||||||
it(`should make a GET if entriesDate and item are defined`, () => {
|
|
||||||
controller._defaultEntriesDate();
|
|
||||||
let filter = {itemFk: controller.item.id, date: controller.entriesDate};
|
|
||||||
$httpBackend.whenGET(`/item/api/Items/getLastEntries?filter=${JSON.stringify(filter)}`).respond([]);
|
|
||||||
$httpBackend.expectGET(`/item/api/Items/getLastEntries?filter=${JSON.stringify(filter)}`);
|
|
||||||
controller._getLastEntries();
|
|
||||||
$httpBackend.flush();
|
|
||||||
// expect(controller.entriesDate).toEqual(defaultDate);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
|
@ -19,8 +19,9 @@ module.exports = Self => {
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.getLastEntries = async filter => {
|
Self.getLastEntries = async filter => {
|
||||||
|
let where = filter.where;
|
||||||
let query = `CALL vn.itemLastEntries(?, ?)`;
|
let query = `CALL vn.itemLastEntries(?, ?)`;
|
||||||
let [lastEntries] = await Self.rawSql(query, [filter.itemFk, filter.date]);
|
let [lastEntries] = await Self.rawSql(query, [where.itemFk, where.date]);
|
||||||
return lastEntries;
|
return lastEntries;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -34,10 +34,10 @@ module.exports = class PaymentUpdate {
|
||||||
|
|
||||||
get paymentAdvice() {
|
get paymentAdvice() {
|
||||||
switch (this.payMethodFk) {
|
switch (this.payMethodFk) {
|
||||||
case 4:
|
case 4:
|
||||||
return `${this._.accountPaymentAdviceBefore} ${format.partialAccountAddress(this.iban)} ${this._.accountPaymentAdviceAfter}`;
|
return `${this._.accountPaymentAdviceBefore} ${format.partialAccountAddress(this.iban)} ${this._.accountPaymentAdviceAfter}`;
|
||||||
case 5:
|
case 5:
|
||||||
return this._.cardPaymentAdvice;
|
return this._.cardPaymentAdvice;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -19,6 +19,7 @@ module.exports = {
|
||||||
* @return {String} Cuenta bancaria formateada
|
* @return {String} Cuenta bancaria formateada
|
||||||
*/
|
*/
|
||||||
accountAddress: function(addressNumber) {
|
accountAddress: function(addressNumber) {
|
||||||
|
if (!addressNumber) return;
|
||||||
var formattedAccountAddress = addressNumber.replace(/(.{4})/g, '$1-');
|
var formattedAccountAddress = addressNumber.replace(/(.{4})/g, '$1-');
|
||||||
return formattedAccountAddress.substring(0, formattedAccountAddress.length - 1);
|
return formattedAccountAddress.substring(0, formattedAccountAddress.length - 1);
|
||||||
},
|
},
|
||||||
|
@ -29,6 +30,7 @@ module.exports = {
|
||||||
* @return {String} Cuenta bancaria formateada
|
* @return {String} Cuenta bancaria formateada
|
||||||
*/
|
*/
|
||||||
partialAccountAddress: function(addressNumber) {
|
partialAccountAddress: function(addressNumber) {
|
||||||
|
if (!addressNumber) return;
|
||||||
let address = this.accountAddress(addressNumber);
|
let address = this.accountAddress(addressNumber);
|
||||||
return address.substring(0, 19).replace(/[0-9]/g, 'X') + address.substring(19, 24);
|
return address.substring(0, 19).replace(/[0-9]/g, 'X') + address.substring(19, 24);
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue