Merge branch 'dev' of http://git.verdnatura.es/salix into dev
This commit is contained in:
commit
7735c50512
|
@ -1,13 +1,9 @@
|
|||
<vn-crud-model
|
||||
vn-id="model"
|
||||
url="/client/api/receipts/filter"
|
||||
params= "{
|
||||
params: {
|
||||
clientFk:$ctrl.$stateParams.id
|
||||
}
|
||||
}"
|
||||
params="$ctrl.params"
|
||||
limit="20"
|
||||
data="risks">
|
||||
data="$ctrl.risks">
|
||||
</vn-crud-model>
|
||||
<vn-crud-model
|
||||
vn-id="riskModel"
|
||||
|
@ -18,15 +14,29 @@
|
|||
<vn-vertical>
|
||||
<vn-card pad-large>
|
||||
<vn-horizontal>
|
||||
<vn-title vn-two>Risk</vn-title>
|
||||
<div class="totalBox" ng-if="riskTotal.length">
|
||||
<h6> Total por empresa</h6>
|
||||
<vn-auto ng-repeat="riskByCompany in riskTotal">
|
||||
<vn-label-value label={{riskByCompany.company.code}}
|
||||
value="{{riskByCompany.amount | currency: ' €': 2}}">
|
||||
</vn-label-value>
|
||||
</vn-auto>
|
||||
</div>
|
||||
<vn-one>
|
||||
<vn-title>Risk</vn-title>
|
||||
</vn-one>
|
||||
<vn-one>
|
||||
<vn-autocomplete vn-one
|
||||
field="$ctrl.companyFk"
|
||||
on-change="$ctrl.setOrder(value)"
|
||||
url="/client/api/Companies"
|
||||
show-field="code"
|
||||
value-field="id"
|
||||
label="Select company">
|
||||
</vn-autocomplete>
|
||||
</vn-one>
|
||||
<vn-one>
|
||||
<div class="totalBox" ng-if="riskTotal.length">
|
||||
<h6> Total por empresa</h6>
|
||||
<vn-auto ng-repeat="riskByCompany in riskTotal">
|
||||
<vn-label-value label={{riskByCompany.company.code}}
|
||||
value="{{riskByCompany.amount | currency: ' €': 2}}">
|
||||
</vn-label-value>
|
||||
</vn-auto>
|
||||
</div>
|
||||
</vn-one>
|
||||
</vn-horizontal>
|
||||
<vn-vertical>
|
||||
<vn-table model="model">
|
||||
|
@ -43,7 +53,7 @@
|
|||
</vn-tr>
|
||||
</vn-thead>
|
||||
<vn-tbody>
|
||||
<vn-tr ng-repeat="risk in risks">
|
||||
<vn-tr ng-repeat="risk in $ctrl.risks">
|
||||
<vn-td>{{::risk.payed | dateTime:'dd/MM/yyyy'}}</vn-td>
|
||||
<vn-td>{{::risk.created | dateTime:'dd/MM/yyyy HH:mm'}}</vn-td>
|
||||
<vn-td>{{::risk.firstName}} {{::risk.name}}</vn-td>
|
||||
|
@ -51,6 +61,7 @@
|
|||
<vn-td>{{::risk.bankFk}}</vn-td>
|
||||
<vn-td>{{::risk.debit | currency: ' €': 2}}</vn-td>
|
||||
<vn-td>{{::risk.credit | currency: ' €': 2}}</vn-td>
|
||||
<vn-td>{{risk.balance}}</vn-td>
|
||||
<vn-td>
|
||||
<vn-check
|
||||
field="risk.isConciliate"
|
||||
|
|
|
@ -1,25 +1,59 @@
|
|||
import ngModule from '../../module';
|
||||
import './style.scss';
|
||||
|
||||
class Controller {
|
||||
constructor($stateParams) {
|
||||
constructor($stateParams, $translate, $scope) {
|
||||
this.$ = $scope;
|
||||
this.$stateParams = $stateParams;
|
||||
|
||||
this.$translate = $translate;
|
||||
this.companyFk = window.localStorage.defaultCompanyFk;
|
||||
this.filter = {
|
||||
include: {
|
||||
relation: "company",
|
||||
relation: 'company',
|
||||
scope: {
|
||||
fields: ["code"]
|
||||
}
|
||||
fields: ['code'],
|
||||
},
|
||||
},
|
||||
where: {
|
||||
clientFk: $stateParams.id
|
||||
}};
|
||||
clientFk: $stateParams.id,
|
||||
},
|
||||
};
|
||||
this.params = {
|
||||
params: {
|
||||
clientFk: this.$stateParams.id,
|
||||
companyFk: this.companyFk,
|
||||
},
|
||||
};
|
||||
}
|
||||
setOrder(value) {
|
||||
this.params.params.companyFk = value;
|
||||
this.$.model.refresh();
|
||||
}
|
||||
|
||||
set risks(value) {
|
||||
if (value) {
|
||||
for (let i = this.$.model.data.length - 1; i >= 0; i--) {
|
||||
let row = this.$.model.data[i];
|
||||
let tot;
|
||||
if (i != this.$.model.data.length - 1)
|
||||
row.balance = (row.credit - row.debit) + (this.$.model.data[i + 1].balance);
|
||||
else
|
||||
row.balance = row.credit - row.debit;
|
||||
|
||||
tot = tot + row.balance;
|
||||
}
|
||||
this._risks = this.$.model.data;
|
||||
}
|
||||
}
|
||||
|
||||
get risks() {
|
||||
return this._risks;
|
||||
}
|
||||
}
|
||||
|
||||
Controller.$inject = ['$stateParams'];
|
||||
Controller.$inject = ['$stateParams', '$translate', '$scope'];
|
||||
|
||||
ngModule.component('vnClientRiskIndex', {
|
||||
template: require('./index.html'),
|
||||
controller: Controller
|
||||
controller: Controller,
|
||||
});
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
import './index';
|
||||
|
||||
describe('Client', () => {
|
||||
describe('Component vnClientRiskIndex', () => {
|
||||
let $componentController;
|
||||
let $scope;
|
||||
let controller;
|
||||
|
||||
beforeEach(() => {
|
||||
angular.mock.module('client');
|
||||
});
|
||||
|
||||
beforeEach(angular.mock.inject((_$componentController_, $rootScope) => {
|
||||
$componentController = _$componentController_;
|
||||
$scope = $rootScope.$new();
|
||||
controller = $componentController('vnClientRiskIndex', {$scope: $scope});
|
||||
}));
|
||||
|
||||
describe('risks() setter', () => {
|
||||
it('should calculate the balance for each line from the oldest date to the newest', () => {
|
||||
let risks = [
|
||||
{credit: 100, debit: 0},
|
||||
{credit: 100, debit: 0},
|
||||
{credit: 0, debit: 300}
|
||||
];
|
||||
controller.$.model = {data: risks};
|
||||
controller.risks = risks;
|
||||
|
||||
expect(controller.risks[0].balance).toEqual(-100);
|
||||
expect(controller.risks[1].balance).toEqual(-200);
|
||||
expect(controller.risks[2].balance).toEqual(-300);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -0,0 +1,6 @@
|
|||
vn-client-risk-index {
|
||||
.totalBox {
|
||||
display: table;
|
||||
float: right;
|
||||
}
|
||||
}
|
|
@ -40,7 +40,8 @@
|
|||
</vn-td>
|
||||
<vn-td number>
|
||||
<span ng-class="::{'link pointer': sale.isTicket}"
|
||||
ng-click="$ctrl.showDescriptor($event, sale)">
|
||||
ng-click="$ctrl.showDescriptor($event, sale)"
|
||||
class="id">
|
||||
{{::sale.origin | dashIfEmpty}}
|
||||
</span>
|
||||
</vn-td>
|
||||
|
|
|
@ -34,14 +34,16 @@ class Controller {
|
|||
}
|
||||
|
||||
set warehouseFk(value) {
|
||||
this._warehouseFk = value;
|
||||
if (value && value != this._warehouseFk) {
|
||||
this._warehouseFk = value;
|
||||
|
||||
this.$state.go(this.$state.current.name, {
|
||||
warehouseFk: value
|
||||
});
|
||||
this.$state.go(this.$state.current.name, {
|
||||
warehouseFk: value
|
||||
});
|
||||
|
||||
this.filter.where.warehouseFk = value;
|
||||
this.$scope.model.refresh();
|
||||
this.filter.where.warehouseFk = value;
|
||||
this.$scope.model.refresh();
|
||||
}
|
||||
}
|
||||
|
||||
get warehouseFk() {
|
||||
|
@ -64,7 +66,7 @@ class Controller {
|
|||
get onPreparationLineIndex() {
|
||||
let lines = this.$scope.model.data;
|
||||
|
||||
for (let i = this.freeLineIndex; i > 0; i--) {
|
||||
for (let i = this.freeLineIndex; i >= 0; i--) {
|
||||
let line = lines[i];
|
||||
let currentDate = new Date();
|
||||
currentDate.setHours(0, 0, 0);
|
||||
|
@ -73,7 +75,7 @@ class Controller {
|
|||
let isPicked = line.alertLevel == 1 && line.isPicked;
|
||||
|
||||
if ((isPicked) || line.alertLevel > 1 || isPastDate)
|
||||
return i;
|
||||
return i + 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -90,32 +92,41 @@ class Controller {
|
|||
|
||||
scrollToLine() {
|
||||
let body = this.$window.document.body;
|
||||
|
||||
let lineIndex;
|
||||
if (this.ticketFk)
|
||||
lineIndex = this.givenTicketIndex;
|
||||
else
|
||||
lineIndex = this.onPreparationLineIndex;
|
||||
let selectedTicketLineIndex = this.givenTicketIndex;
|
||||
let lineIndex = this.onPreparationLineIndex;
|
||||
|
||||
let lines = body.querySelector('vn-tbody').children;
|
||||
|
||||
if (!lineIndex || !lines.length) return;
|
||||
if (lineIndex == undefined || !lines.length) return;
|
||||
|
||||
|
||||
let onPreparationLine = lines[lineIndex];
|
||||
|
||||
|
||||
let balance = onPreparationLine.querySelector('.balanceSpan');
|
||||
balance.classList.add('counter');
|
||||
balance.title = this.$translate.instant('Visible quantity');
|
||||
|
||||
let headerOffset = body.querySelector('header').getBoundingClientRect();
|
||||
let headerHeight = headerOffset.height;
|
||||
let offsetTop = onPreparationLine.offsetTop - headerHeight;
|
||||
|
||||
let offsetTop;
|
||||
if (this.ticketFk) {
|
||||
console.log(selectedTicketLineIndex);
|
||||
let selectedTicketLine = lines[selectedTicketLineIndex];
|
||||
let id = selectedTicketLine.querySelector('.id');
|
||||
id.classList.add('counter');
|
||||
offsetTop = selectedTicketLine.offsetTop - headerHeight;
|
||||
} else
|
||||
offsetTop = onPreparationLine.offsetTop - headerHeight;
|
||||
|
||||
body.querySelector('ui-view').scrollTop = offsetTop;
|
||||
|
||||
|
||||
this.ticketFk = null;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Compares a date with the current one
|
||||
* @param {Object} date - Date to compare
|
||||
* @return {Boolean} - Returns true if the two dates equals
|
||||
|
|
|
@ -58,14 +58,14 @@ describe('Item', () => {
|
|||
let currentDate = new Date();
|
||||
currentDate.setDate(currentDate.getDate() + 1);
|
||||
controller.$scope.model = {data: [
|
||||
{name: 'My item 1', alertLevel: 3, isPicked: true, date: '2018-05-02'},
|
||||
{name: 'My item 3', alertLevel: 1, isPicked: true, date: '2018-05-03'},
|
||||
{name: 'My item 4', alertLevel: 1, isPicked: false, date: '2018-05-03'},
|
||||
{name: 'My item 1', alertLevel: 3, isPicked: true, date: currentDate},
|
||||
{name: 'My item 3', alertLevel: 1, isPicked: true, date: currentDate},
|
||||
{name: 'My item 4', alertLevel: 1, isPicked: false, date: currentDate},
|
||||
{name: 'My item 5', alertLevel: 0, isPicked: false, date: currentDate}]
|
||||
};
|
||||
let result = controller.onPreparationLineIndex;
|
||||
|
||||
expect(result).toEqual(2);
|
||||
expect(result).toEqual(1);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -33,5 +33,5 @@ vn-item-diary {
|
|||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -46,7 +46,7 @@ module.exports = Self => {
|
|||
FROM vn.receipt r
|
||||
LEFT JOIN vn.worker w ON w.id = r.workerFk
|
||||
JOIN vn.company c ON c.id = r.companyFk
|
||||
WHERE clientFk = ?
|
||||
WHERE r.clientFk = ? AND r.companyFk = ?
|
||||
UNION ALL
|
||||
SELECT
|
||||
i.id,
|
||||
|
@ -63,11 +63,13 @@ module.exports = Self => {
|
|||
i.clientFk
|
||||
FROM vn.invoiceOut i
|
||||
JOIN vn.company c ON c.id = i.companyFk
|
||||
WHERE clientFk = ?
|
||||
WHERE i.clientFk = ? AND i.companyFk = ?
|
||||
) t
|
||||
ORDER BY payed DESC, created DESC`, [
|
||||
params.clientFk,
|
||||
params.clientFk
|
||||
params.companyFk,
|
||||
params.clientFk,
|
||||
params.companyFk,
|
||||
]
|
||||
);
|
||||
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
const app = require(`${servicesDir}/client/server/server`);
|
||||
|
||||
xdescribe('receipt filter()', () => {
|
||||
describe('receipt filter()', () => {
|
||||
it('should call the filter method', async () => {
|
||||
let filter = {limit: 20};
|
||||
let params = {
|
||||
clientFk: 101
|
||||
clientFk: 101,
|
||||
companyFk: 442
|
||||
};
|
||||
let result = await app.models.Receipt.filter(filter, params);
|
||||
|
||||
|
|
Loading…
Reference in New Issue