Merge branch 'dev' of https://git.verdnatura.es/salix into dev

This commit is contained in:
Gerard 2018-10-24 14:21:39 +02:00
commit 3851e4a889
13 changed files with 175 additions and 19 deletions

View File

@ -224,6 +224,15 @@
"icon": "icon-invoices" "icon": "icon-invoices"
} }
}, },
{
"url": "/create?payed&companyFk&bankFk&payedAmount",
"state": "client.card.risk.create",
"component": "vn-client-risk-create",
"description": "New payment",
"params": {
"client": "$ctrl.client"
}
},
{ {
"url": "/recovery", "url": "/recovery",
"abstract": true, "abstract": true,

View File

@ -20,6 +20,7 @@ import './credit/create';
import './greuge/index'; import './greuge/index';
import './greuge/create'; import './greuge/create';
import './risk/index'; import './risk/index';
import './risk/create';
import './mandate'; import './mandate';
import './summary'; import './summary';
import './recovery/index'; import './recovery/index';

View File

@ -5,7 +5,8 @@ class Controller {
this.$ = $scope; this.$ = $scope;
this.$state = $state; this.$state = $state;
this.greuge = { this.greuge = {
shipped: new Date() shipped: new Date(),
clientFk: $state.params.id
}; };
} }
@ -18,7 +19,6 @@ class Controller {
} }
onSubmit() { onSubmit() {
this.greuge.clientFk = this.$state.params.id;
this.$.watcher.submit().then( this.$.watcher.submit().then(
() => { () => {
this.goToIndex(); this.goToIndex();

View File

@ -0,0 +1,45 @@
<mg-ajax path="/client/api/receipts" options="vnPost"></mg-ajax>
<vn-watcher
vn-id="watcher"
data="$ctrl.receipt"
form="form"
save="post">
</vn-watcher>
<form name="form" ng-submit="$ctrl.onSubmit()">
<vn-card pad-large>
<vn-title>New payment</vn-title>
<vn-horizontal>
<vn-date-picker vn-one
label="Date"
model="$ctrl.receipt.payed"
ini-options="{dateFormat: 'd-m-Y', time_24hr: true}">
</vn-date-picker>
<vn-autocomplete vn-one
url="/api/Companies"
label="Company"
show-field="code"
value-field="id"
field="$ctrl.receipt.companyFk">
</vn-autocomplete>
</vn-horizontal>
<vn-horizontal>
<vn-textfield
vn-one
margin-medium-right
label="Bank"
field="$ctrl.receipt.bankFk">
</vn-textfield>
<vn-textfield
vn-one
margin-medium-right
label="Amount"
field="$ctrl.receipt.amountPaid "
vn-focus>
</vn-textfield>
</vn-horizontal>
</vn-card>
<vn-button-bar>
<vn-submit label="Save"></vn-submit>
<vn-button ng-click="$ctrl.cancel($event)" label="Cancel"></vn-button>
</vn-button-bar>
</form>

View File

@ -0,0 +1,66 @@
import ngModule from '../../module';
class Controller {
constructor($scope, $state, $http, $stateParams) {
this.$http = $http;
this.$ = $scope;
this.$state = $state;
this.$stateParams = $stateParams;
this.receipt = {
payed: new Date(),
clientFk: this.$state.params.id,
companyFk: window.localStorage.defaultCompanyFk,
bankFk: window.localStorage.defaultBankFk
};
if (this.$stateParams.payed)
this.receipt.payed = this.$stateParams.payed;
if (this.$stateParams.bankFk)
this.receipt.bankFk = this.$stateParams.bankFk;
if (this.$stateParams.amountPaid)
this.receipt.amountPaid = this.$stateParams.amountPaid;
if (this.$stateParams.companyFk) {
this.receipt.companyFk = this.$stateParams.companyFk;
}
}
$onInit() {
let filter = {
where: {
clientFk: this.$state.params.id,
companyFk: this.receipt.companyFk
}
};
let query = `/client/api/ClientRisks?filter=${JSON.stringify(filter)}`;
this.$http.get(query).then(res => {
this.receipt.amountPaid = (res.data.length && res.data[0].amount) || null;
});
}
cancel() {
this.goToIndex();
}
goToIndex() {
this.$state.go('client.card.risk.index');
}
onSubmit() {
this.$.watcher.submit().then(
() => {
this.goToIndex();
}
);
}
}
Controller.$inject = ['$scope', '$state', '$http', '$stateParams'];
ngModule.component('vnClientRiskCreate', {
template: require('./index.html'),
controller: Controller
});

View File

@ -40,7 +40,6 @@
<vn-th>Debit</vn-th> <vn-th>Debit</vn-th>
<vn-th>Credit</vn-th> <vn-th>Credit</vn-th>
<vn-th>Conciliated</vn-th> <vn-th>Conciliated</vn-th>
<vn-th>Company</vn-th>
</vn-tr> </vn-tr>
</vn-thead> </vn-thead>
<vn-tbody> <vn-tbody>
@ -58,7 +57,6 @@
disabled="true"> disabled="true">
</vn-check> </vn-check>
</vn-td> </vn-td>
<vn-td>{{::risk.company}}</vn-td>
</vn-tr> </vn-tr>
</vn-tbody> </vn-tbody>
<vn-empty-rows ng-if="model.data.length === 0" translate> <vn-empty-rows ng-if="model.data.length === 0" translate>

View File

@ -43,7 +43,7 @@ module.exports = Self => {
name, name,
r.clientFk r.clientFk
FROM vn.receipt r FROM vn.receipt r
JOIN vn.worker w ON w.id = r.workerFk LEFT JOIN vn.worker w ON w.id = r.workerFk
JOIN vn.company c ON c.id = r.companyFk JOIN vn.company c ON c.id = r.companyFk
WHERE clientFk = ? WHERE clientFk = ?
UNION ALL UNION ALL

View File

@ -1,3 +1,13 @@
module.exports = function(Self) { module.exports = function(Self) {
require('../methods/receipt/filter')(Self); require('../methods/receipt/filter')(Self);
Self.observe('before save', async function(ctx) {
if (ctx.isNewInstance) {
let token = ctx.options.accessToken;
let userId = token && token.userId;
let worker = await Self.app.models.Worker.findOne({where: {userFk: userId}});
ctx.instance.workerFk = worker.id;
}
});
}; };

View File

@ -7,4 +7,3 @@ describe('client getMana()', () => {
expect(result.mana).toEqual(151.33); expect(result.mana).toEqual(151.33);
}); });
}); });

View File

@ -1,14 +1,13 @@
const app = require(`${servicesDir}/ticket/server/server`); const app = require(`${servicesDir}/ticket/server/server`);
xdescribe('sale removes()', () => { describe('sale removes()', () => {
let sale; let sale;
let newsale;
beforeAll(async() => { beforeAll(async() => {
sale = await app.models.Sale.findOne({where: {id: 1}}); sale = await app.models.Sale.findOne({where: {id: 9}});
}); sale.id = null;
newsale = await app.models.Sale.create(sale);
afterAll(async() => {
await app.models.Sale.create(sale);
}); });
it('should throw an error if the ticket of the given sales is not editable', async() => { it('should throw an error if the ticket of the given sales is not editable', async() => {
@ -30,8 +29,8 @@ xdescribe('sale removes()', () => {
it('should delete the sales', async() => { it('should delete the sales', async() => {
let params = { let params = {
sales: [{id: 1, instance: 0}], sales: [{id: newsale.id, instance: 0}],
actualTicketFk: 1 actualTicketFk: 16
}; };
let res = await app.models.Sale.removes(params); let res = await app.models.Sale.removes(params);

View File

@ -23,9 +23,12 @@ module.exports = Self => {
Self.removes = async params => { Self.removes = async params => {
if (!params.rows || !params.rows.length) if (!params.rows || !params.rows.length)
throw new UserError('There is nothing delete'); throw new UserError('There is nothing to delete');
await Self.app.models.Order.isEditable(params.actualOrderId); let isEditable = await Self.app.models.Order.isEditable(params.actualOrderId);
if (!isEditable)
throw new UserError('This order is not editable');
let promises = []; let promises = [];
for (let i = 0; i < params.rows.length; i++) { for (let i = 0; i < params.rows.length; i++) {

View File

@ -1,6 +1,11 @@
const app = require(`../../../../server/server`); const app = require(`../../../../server/server`);
describe('order addToOrder()', () => { describe('order addToOrder()', () => {
let rowToDelete;
afterAll(async() => {
await app.models.OrderRow.removes({rows: [rowToDelete], actualOrderId: 16});
});
it('should add a row to a given order', async() => { it('should add a row to a given order', async() => {
let unmodifiedRows = await app.models.OrderRow.find({where: {orderFk: 16}}); let unmodifiedRows = await app.models.OrderRow.find({where: {orderFk: 16}});
@ -19,7 +24,8 @@ describe('order addToOrder()', () => {
let modifiedRows = await app.models.OrderRow.find({where: {orderFk: 16}}); let modifiedRows = await app.models.OrderRow.find({where: {orderFk: 16}});
rowToDelete = modifiedRows[modifiedRows.length - 1].id;
expect(modifiedRows.length).toBe(5); expect(modifiedRows.length).toBe(5);
await app.models.OrderRow.removes({rows: [modifiedRows[modifiedRows.length - 1].id]});
}); });
}); });

View File

@ -1,6 +1,15 @@
const app = require(`../../../../server/server`); const app = require(`../../../../server/server`);
xdescribe('order removes()', () => { describe('order removes()', () => {
let row;
let newRow;
beforeAll(async() => {
row = await app.models.OrderRow.findOne({where: {id: 12}});
row.id = null;
newRow = await app.models.OrderRow.create(row);
});
it('should throw an error if rows property is empty', async() => { it('should throw an error if rows property is empty', async() => {
let error; let error;
try { try {
@ -9,7 +18,7 @@ xdescribe('order removes()', () => {
error = e; error = e;
} }
expect(error).toEqual(new Error('There is nothing delete')); expect(error).toEqual(new Error('There is nothing to delete'));
}); });
it('should throw an error if the row selected is not editable', async() => { it('should throw an error if the row selected is not editable', async() => {
@ -22,4 +31,15 @@ xdescribe('order removes()', () => {
expect(error).toEqual(new Error('This order is not editable')); expect(error).toEqual(new Error('This order is not editable'));
}); });
it('should delete the row', async() => {
let params = {
rows: [newRow.id],
actualOrderId: 16
};
let res = await app.models.OrderRow.removes(params);
expect(res).toEqual([{count: 1}]);
});
}); });