7773-testToMaster_2430 #2774

Merged
alexm merged 368 commits from 7773-testToMaster_2430 into master 2024-07-23 06:21:03 +00:00
5 changed files with 7 additions and 349 deletions
Showing only changes of commit ce59a2bbbf - Show all commits

View File

@ -1,121 +1,2 @@
<vn-crud-model <vn-card>
vn-id="model" </vn-card>
url="Items/getBalance"
filter="$ctrl.filter"
data="sales"
auto-load="false">
</vn-crud-model>
<vn-crud-model
auto-load="true"
url="Warehouses"
data="warehouses"
order="name"
vn-id="warehouse-model">
</vn-crud-model>
<vn-vertical>
<vn-card class="vn-pa-lg vn-w-lg">
<vn-vertical>
<vn-horizontal>
<vn-autocomplete
vn-focus
data="warehouses"
show-field="name"
value-field="id"
initial-data="$ctrl.warehouseFk"
ng-model="$ctrl.warehouseFk"
label="Select warehouse">
</vn-autocomplete>
<vn-check
ng-class="{'table-check':$ctrl.showOld}"
label="Show what's before the inventory"
ng-model="$ctrl.showOld">
</vn-check>
<vn-date-picker
label="Since"
ng-model="$ctrl.date"
ng-show="$ctrl.showOld">
</vn-date-picker>
</vn-horizontal>
<vn-table model="model">
<vn-thead>
<vn-tr>
<vn-th shrink></vn-th>
<vn-th expand>Date</vn-th>
<vn-th number order="DESC" shrink>Id</vn-th>
<vn-th>State</vn-th>
<vn-th>Reference</vn-th>
<vn-th expand>Client</vn-th>
<vn-th number>In</vn-th>
<vn-th number>Out</vn-th>
<vn-th number>Balance</vn-th>
</vn-tr>
</vn-thead>
<vn-tbody>
<vn-tr
ng-class="::{
'isIn': sale.invalue,
'balanceNegative': sale.balance < 0}"
ng-repeat="sale in sales"
vn-repeat-last
on-last="$ctrl.scrollToLine(sale.lastPreparedLineFk)"
ng-attr-id="vnItemDiary-{{::sale.lineFk}}">
<vn-td shrink>
<a ui-sref="claim.card.summary({id: sale.claimFk})">
<vn-icon icon="icon-claims"
ng-show="sale.claimFk"
vn-tooltip="{{::$ctrl.$t('Claim')}}: {{::sale.claimFk}}">
</vn-icon>
</a>
</vn-td>
<vn-td expand>
<span class="chip"
ng-class="::{warning: $ctrl.today == sale.shipped}">
{{::sale.shipped | date:'dd/MM/yyyy' }}
</span>
</vn-td>
<vn-td number shrink>
<span class="link"
ng-click="$ctrl.showDescriptor($event, sale)"
name="origin">
{{::sale.origin | dashIfEmpty}}
</span>
</vn-td>
<vn-td>{{::sale.stateName | dashIfEmpty}}</vn-td>
<vn-td>{{::sale.reference | dashIfEmpty}}</vn-td>
<vn-td class="truncate" expand>
<span ng-class="::{'warning chip': sale.highlighted}">
<span ng-if="::!sale.isTicket">
{{::sale.name | dashIfEmpty}}
</span>
<span
ng-if="::sale.isTicket"
vn-click-stop="clientDescriptor.show($event, sale.clientFk)"
class="link">
{{::sale.name | dashIfEmpty}}
</span>
</span>
</vn-td>
<vn-td number class="in">{{::sale.invalue | dashIfEmpty}}</vn-td>
<vn-td number>{{::sale.out | dashIfEmpty}}</vn-td>
<vn-td number class="balance">
<span class="chip balanceSpan"
ng-class="::{message: sale.lineFk == sale.lastPreparedLineFk}">
{{::sale.balance | dashIfEmpty}}
</span>
</vn-td>
</vn-tr>
</vn-tbody>
</vn-table>
</vn-vertical>
</vn-card>
</vn-vertical>
<vn-ticket-descriptor-popover
vn-id="ticket-descriptor">
</vn-ticket-descriptor-popover>
<vn-client-descriptor-popover
vn-id="clientDescriptor">
</vn-client-descriptor-popover>
<vn-entry-descriptor-popover
vn-id="entryDescriptor">
</vn-entry-descriptor-popover>

View File

@ -1,107 +1,21 @@
import ngModule from '../module'; import ngModule from '../module';
import Section from 'salix/components/section'; import Section from 'salix/components/section';
import './style.scss';
class Controller extends Section { class Controller extends Section {
constructor($element, $scope, $anchorScroll, $location) { constructor($element, $) {
super($element, $scope); super($element, $);
this.$anchorScroll = $anchorScroll;
this.$location = $location;
let today = Date.vnNew();
today.setHours(0, 0, 0, 0);
this.today = today.toJSON();
} }
get item() { async $onInit() {
return this._item; this.$state.go('item.card.summary', {id: this.$params.id});
} window.location.href = await this.vnApp.getUrl(`item/${this.$params.id}/diary`);
set item(value) {
this._item = value;
this.filter = {
where: {itemFk: this.$params.id}
};
this.$.$applyAsync(() => {
if (this.$params.warehouseFk)
this.warehouseFk = this.$params.warehouseFk;
else if (value)
this.warehouseFk = this.vnConfig.warehouseFk;
if (this.$params.lineFk)
this.lineFk = this.$params.lineFk;
});
}
set warehouseFk(value) {
if (value && value != this._warehouseFk) {
this._warehouseFk = value;
this.card.warehouseFk = value;
this.filter.where.warehouseFk = this.warehouseFk;
this.$.model.refresh();
}
}
get warehouseFk() {
return this._warehouseFk;
}
set date(value) {
this._date = value;
this.filter.where.date = value;
this.filter.where.warehouseFk = this.warehouseFk;
this.$.model.refresh();
}
get date() {
return this._date;
}
set showOld(value) {
this._showOld = value;
if (!this._showOld) this.date = null;
else this.date = new Date();
}
get showOld() {
return this._showOld;
}
scrollToLine(lineFk) {
this.$.$applyAsync(() => {
const hashFk = this.lineFk || lineFk;
const hash = `vnItemDiary-${hashFk}`;
this.$location.hash(hash);
this.$anchorScroll();
});
}
showDescriptor(event, sale) {
let descriptor = 'entryDescriptor';
if (sale.isTicket)
descriptor = 'ticketDescriptor';
this.$[descriptor].show(event.target, sale.origin);
}
$onDestroy() {
if (this.$state.getCurrentPath()[2].state.name === 'item')
this.card.reload();
} }
} }
Controller.$inject = ['$element', '$scope', '$anchorScroll', '$location'];
ngModule.vnComponent('vnItemDiary', { ngModule.vnComponent('vnItemDiary', {
template: require('./index.html'), template: require('./index.html'),
controller: Controller, controller: Controller,
bindings: { bindings: {
item: '<' item: '<'
},
require: {
card: '?^vnItemCard'
} }
}); });

View File

@ -1,99 +0,0 @@
import './index.js';
import crudModel from 'core/mocks/crud-model';
describe('Item', () => {
describe('Component vnItemDiary', () => {
let $scope;
let controller;
beforeEach(ngModule('item'));
beforeEach(inject(($componentController, $rootScope) => {
$scope = $rootScope.$new();
const $element = angular.element('<vn-item-diary></vn-item-diary>');
controller = $componentController('vnItemDiary', {$element, $scope});
controller.$.model = crudModel;
controller.$params = {id: 1};
controller.card = {};
}));
describe('set item()', () => {
it('should set warehouseFk property based on itemType warehouseFk', () => {
jest.spyOn(controller.$, '$applyAsync');
controller.vnConfig = {warehouseFk: 1};
controller.item = {id: 1};
expect(controller.$.$applyAsync).toHaveBeenCalledWith(jasmine.any(Function));
$scope.$apply();
expect(controller.warehouseFk).toEqual(1);
expect(controller.item.id).toEqual(1);
});
it(`should set warehouseFk property based on url query warehouseFk`, () => {
jest.spyOn(controller.$, '$applyAsync');
controller.$params.warehouseFk = 4;
controller.item = {id: 1, itemType: {warehouseFk: 1}};
expect(controller.$.$applyAsync).toHaveBeenCalledWith(jasmine.any(Function));
$scope.$apply();
expect(controller.warehouseFk).toEqual(4);
expect(controller.item.id).toEqual(1);
});
});
describe('scrollToLine ()', () => {
it('should assign $location then call anchorScroll using controller value', () => {
jest.spyOn(controller, '$anchorScroll');
controller.lineFk = 1;
controller.scrollToLine('invalidValue');
$scope.$apply();
expect(controller.$location.hash()).toEqual(`vnItemDiary-${1}`);
expect(controller.$anchorScroll).toHaveBeenCalledWith();
});
it('should assign $location then call anchorScroll using received value', () => {
jest.spyOn(controller, '$anchorScroll');
controller.lineFk = undefined;
controller.scrollToLine(1);
$scope.$apply();
expect(controller.$location.hash()).toEqual(`vnItemDiary-${1}`);
expect(controller.$anchorScroll).toHaveBeenCalledWith();
});
});
describe('showDescriptor ()', () => {
it('should call to the entryDescriptor show() method', () => {
controller.$.entryDescriptor = {};
controller.$.entryDescriptor.show = jest.fn();
const $event = new Event('click');
const target = document.createElement('div');
target.dispatchEvent($event);
const data = {id: 1, origin: 1};
controller.showDescriptor($event, data);
expect(controller.$.entryDescriptor.show).toHaveBeenCalledWith($event.target, data.origin);
});
it('should call to the ticketDescriptor show() method', () => {
controller.$.ticketDescriptor = {};
controller.$.ticketDescriptor.show = jest.fn();
const $event = new Event('click');
const target = document.createElement('div');
target.dispatchEvent($event);
const data = {id: 1, origin: 1, isTicket: true};
controller.showDescriptor($event, data);
expect(controller.$.ticketDescriptor.show).toHaveBeenCalledWith($event.target, data.origin);
});
});
});
});

View File

@ -1,5 +0,0 @@
In: Entrada
Out: Salida
Visible quantity: Cantidad visible
Ticket/Entry: Ticket/Entrada
Show what's before the inventory: Mostrar lo anterior al inventario

View File

@ -1,33 +0,0 @@
@import "variables";
vn-item-diary {
& > vn-vertical {
display: block;
}
vn-horizontal {
justify-content: center;
}
vn-autocomplete > div {
width: 400px;
}
.balanceNegative .balance {
color: $color-alert;
}
.isIn .in {
color: $color-success;
font-weight: bold;
}
.isToday .date {
color: white;
background-color: $color-main;
}
.truncate {
max-width: 250px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.table-check{
justify-content: center;
}
}