2744-invoiceIn-module_rdy_n_summary #602

Merged
joan merged 10 commits from 2744-invoiceIn-module_rdy_n_summary into dev 2021-04-15 10:06:35 +00:00
25 changed files with 506 additions and 67 deletions

View File

@ -30193,7 +30193,7 @@ BEGIN
NEW.currencyFk != OLD.currencyFk NEW.currencyFk != OLD.currencyFk
THEN THEN
CALL vn2008.recibidaIvaDivisaUpdate(NEW.id); -- CALL vn2008.recibidaIvaDivisaUpdate(NEW.id);
END IF; END IF;

View File

@ -10,76 +10,81 @@ module.exports = Self => {
accepts: [ accepts: [
{ {
arg: 'filter', arg: 'filter',
type: 'Object', type: 'object',
description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string', description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string',
http: {source: 'query'} http: {source: 'query'}
}, { }, {
arg: 'search', arg: 'search',
type: 'String', type: 'string',
description: 'Searchs the entry by id', description: 'Searchs the entry by id',
http: {source: 'query'} http: {source: 'query'}
}, { }, {
arg: 'id', arg: 'id',
type: 'Integer', type: 'integer',
description: 'The entry id', description: 'The entry id',
http: {source: 'query'} http: {source: 'query'}
}, { }, {
arg: 'created', arg: 'created',
type: 'Date', type: 'date',
description: 'The created date to filter', description: 'The created date to filter',
http: {source: 'query'} http: {source: 'query'}
}, { }, {
arg: 'travelFk', arg: 'travelFk',
type: 'Number', type: 'number',
description: 'The travel id to filter', description: 'The travel id to filter',
http: {source: 'query'} http: {source: 'query'}
}, { }, {
arg: 'companyFk', arg: 'companyFk',
type: 'Number', type: 'number',
description: 'The company to filter', description: 'The company to filter',
http: {source: 'query'} http: {source: 'query'}
}, { }, {
arg: 'isBooked', arg: 'isBooked',
type: 'Boolean', type: 'boolean',
description: 'The isBokked filter', description: 'The isBokked filter',
http: {source: 'query'} http: {source: 'query'}
}, { }, {
arg: 'isConfirmed', arg: 'isConfirmed',
type: 'Boolean', type: 'boolean',
description: 'The isConfirmed filter', description: 'The isConfirmed filter',
http: {source: 'query'} http: {source: 'query'}
}, { }, {
arg: 'isOrdered', arg: 'isOrdered',
type: 'Boolean', type: 'boolean',
description: 'The isOrdered filter', description: 'The isOrdered filter',
http: {source: 'query'} http: {source: 'query'}
}, { }, {
arg: 'ref', arg: 'ref',
type: 'String', type: 'string',
description: 'The ref filter', description: 'The ref filter',
http: {source: 'query'} http: {source: 'query'}
}, { }, {
arg: 'supplierFk', arg: 'supplierFk',
type: 'Number', type: 'number',
description: 'The supplier id to filter', description: 'The supplier id to filter',
http: {source: 'query'} http: {source: 'query'}
}, {
arg: 'invoiceInFk',
type: 'number',
description: 'The invoiceIn id to filter',
http: {source: 'query'}
}, { }, {
arg: 'currencyFk', arg: 'currencyFk',
type: 'Number', type: 'number',
description: 'The currency id to filter', description: 'The currency id to filter',
http: {source: 'query'} http: {source: 'query'}
}, { }, {
arg: 'from', arg: 'from',
type: 'Date', type: 'date',
description: `The from date filter` description: `The from date filter`
}, { }, {
arg: 'to', arg: 'to',
type: 'Date', type: 'date',
description: `The to date filter` description: `The to date filter`
} }
], ],
returns: { returns: {
type: ['Object'], type: ['object'],
root: true root: true
}, },
http: { http: {
@ -116,6 +121,7 @@ module.exports = Self => {
case 'travelFk': case 'travelFk':
case 'currencyFk': case 'currencyFk':
case 'supplierFk': case 'supplierFk':
case 'invoiceInFk':
param = `e.${param}`; param = `e.${param}`;
return {[param]: value}; return {[param]: value};
} }

View File

@ -17,7 +17,7 @@ module.exports = Self => {
{ {
arg: 'search', arg: 'search',
type: 'string', type: 'string',
description: 'Searchs the invoiceOut by id', description: 'Searchs the invoiceIn by id',
http: {source: 'query'} http: {source: 'query'}
}, },
{ {
@ -25,6 +25,11 @@ module.exports = Self => {
type: 'string', type: 'string',
description: 'The supplier reference' description: 'The supplier reference'
}, },
{
arg: 'supplierFk',
type: 'number',
description: 'The supplier id'
},
{ {
arg: 'fi', arg: 'fi',
type: 'string', type: 'string',
@ -108,6 +113,7 @@ module.exports = Self => {
case 'fi': case 'fi':
return {[`s.${param}`]: value}; return {[`s.${param}`]: value};
case 'supplierRef': case 'supplierRef':
case 'supplierFk':
case 'serialNumber': case 'serialNumber':
case 'serial': case 'serial':
case 'issued': case 'issued':
@ -132,7 +138,7 @@ module.exports = Self => {
ii.isBooked, ii.isBooked,
ii.supplierRef, ii.supplierRef,
ii.docFk AS dmsFk, ii.docFk AS dmsFk,
s.id AS supplierFk, ii.supplierFk,
s.name AS supplierName, s.name AS supplierName,
s.account, s.account,
SUM(iid.amount) AS amount, SUM(iid.amount) AS amount,

View File

@ -0,0 +1,9 @@
const app = require('vn-loopback/server/server');
describe('invoiceIn summary()', () => {
it('should return a summary object containing data from one invoiceIn', async() => {
const summary = await app.models.InvoiceIn.summary(1);
expect(summary.supplierRef).toEqual('1234');
});
});

View File

@ -0,0 +1,48 @@
module.exports = Self => {
Self.remoteMethod('summary', {
description: 'The invoiceIn summary',
accessType: 'READ',
accepts: [{
arg: 'id',
type: 'number',
required: true,
description: 'The invoiceIn id',
http: {source: 'path'}
}],
returns: {
type: 'object',
root: true
},
http: {
path: `/:id/summary`,
verb: 'GET'
}
});
Self.summary = async id => {
const filter = {
include: [
{
relation: 'company',
scope: {
fields: ['id', 'code']
}
},
{
relation: 'supplier',
scope: {
fields: ['id', 'name']
}
},
{
relation: 'sageWithholding',
scope: {
fields: ['withholding']
}
}
]
};
return Self.app.models.InvoiceIn.findById(id, filter);
};
};

View File

@ -1,5 +1,8 @@
{ {
"InvoiceIn": { "InvoiceIn": {
"dataSource": "vn" "dataSource": "vn"
},
"InvoiceInDueDay": {
"dataSource": "vn"
} }
} }

View File

@ -0,0 +1,33 @@
{
"name": "InvoiceInDueDay",
"base": "VnModel",
"options": {
"mysql": {
"table": "invoiceInDueDay"
}
},
"properties": {
"id": {
"id": true,
"type": "number",
"description": "Identifier"
},
"invoiceInFk": {
"type": "number"
},
"dueDated": {
"type": "date"
},
"bankFk": {
"type": "number"
},
"amount": {
"type": "number"
},
"created": {
"type": "date"
}
}
}

View File

@ -1,3 +1,4 @@
module.exports = Self => { module.exports = Self => {
require('../methods/invoice-in/filter')(Self); require('../methods/invoice-in/filter')(Self);
require('../methods/invoice-in/summary')(Self);
}; };

View File

@ -18,6 +18,9 @@
"serial": { "serial": {
"type": "string" "type": "string"
}, },
"supplierRef": {
"type": "string"
},
"issued": { "issued": {
"type": "date" "type": "date"
}, },
@ -27,12 +30,18 @@
"isBooked": { "isBooked": {
"type": "boolean" "type": "boolean"
}, },
"isVatDeductible": {
"type": "boolean"
},
"booked": { "booked": {
"type": "date" "type": "date"
}, },
"operated": { "operated": {
"type": "date" "type": "date"
}, },
"bookEntried": {
"type": "date"
},
"dmsFk": { "dmsFk": {
"type": "number", "type": "number",
"mysql": { "mysql": {
@ -41,6 +50,16 @@
} }
}, },
"relations": { "relations": {
"invoiceInDueDay": {
"type": "hasMany",
"model": "InvoiceInDueDay",
"foreignKey": "invoiceInFk"
},
"sageWithholding": {
"type": "belongsTo",
"model": "SageWithholding",
"foreignKey": "withholdingSageFk"
},
"company": { "company": {
"type": "belongsTo", "type": "belongsTo",
"model": "Company", "model": "Company",

View File

@ -0,0 +1,93 @@
<mg-ajax path="InvoiceIns/{{patch.params.id}}" options="vnPatch"></mg-ajax>
<vn-watcher
vn-id="watcher"
data="$ctrl.invoiceIn"
form="form"
save="patch">
</vn-watcher>
<form name="form" ng-submit="watcher.submit()" class="vn-w-md">
<vn-card class="vn-pa-lg">
<vn-horizontal>
<vn-date-picker
vn-one
label="Expedition date"
ng-model="$ctrl.invoiceIn.issued"
vn-focus
rule>
</vn-date-picker>
<vn-date-picker
vn-one
label="Operation date"
ng-model="$ctrl.invoiceIn.operated"
rule>
</vn-date-picker>
</vn-horizontal>
<vn-horizontal>
<vn-autocomplete
vn-one
ng-model="$ctrl.invoiceIn.supplierFk"
url="Suppliers"
show-field="nickname"
search-function="{or: [{id: $search}, {nickname: {like: '%'+ $search +'%'}}]}"
value-field="id"
order="nickname"
label="Supplier"
required="true"
rule>
<tpl-item>
{{::id}} - {{::nickname}}
</tpl-item>
</vn-autocomplete>
<vn-textfield
label="Supplier ref"
ng-model="$ctrl.invoiceIn.supplierRef"
rule>
</vn-textfield>
</vn-horizontal>
<vn-horizontal>
<vn-date-picker
vn-one
label="Entry date"
ng-model="$ctrl.invoiceIn.bookEntried"
rule>
</vn-date-picker>
<vn-date-picker
vn-one
label="Accounted date"
ng-model="$ctrl.invoiceIn.booked"
rule>
</vn-date-picker>
</vn-horizontal>
<vn-horizontal>
<vn-autocomplete
vn-one
label="Currency"
ng-model="$ctrl.invoiceIn.currencyFk"
url="Currencies"
show-field="name"
value-field="id"
rule>
</vn-autocomplete>
<vn-autocomplete
url="Companies"
label="Company"
show-field="code"
value-field="id"
ng-model="$ctrl.invoiceIn.companyFk"
rule>
</vn-autocomplete>
</vn-horizontal>
</vn-card>
<vn-button-bar>
<vn-submit
disabled="!watcher.dataChanged()"
label="Save">
</vn-submit>
<vn-button
class="cancel"
label="Undo changes"
disabled="!watcher.dataChanged()"
ng-click="watcher.loadOriginalData()">
</vn-button>
</vn-button-bar>
</form>

View File

@ -0,0 +1,10 @@
import ngModule from '../module';
import Section from 'salix/components/section';
ngModule.vnComponent('vnInvoiceInBasicData', {
template: require('./index.html'),
controller: Section,
bindings: {
invoiceIn: '<'
}
});

View File

@ -3,10 +3,27 @@ import ModuleCard from 'salix/components/module-card';
class Controller extends ModuleCard { class Controller extends ModuleCard {
reload() { reload() {
const filter = {}; const filter = {
include: [
{
relation: 'supplier'
},
{
relation: 'invoiceInDueDay'
},
{
relation: 'company'
}
]};
this.$http.get(`InvoiceIns/${this.$params.id}`, {filter}) this.$http.get(`InvoiceIns/${this.$params.id}`, {filter})
.then(res => this.invoiceIn = res.data); .then(res => {
this.invoiceIn = res.data;
this.invoiceIn.amount = res.data.invoiceInDueDay.reduce(
(accumulator, currentValue) => {
return accumulator + (currentValue['amount'] || 0);
}, 0);
});
} }
} }

View File

@ -3,7 +3,12 @@ import './index.js';
describe('vnInvoiceIn', () => { describe('vnInvoiceIn', () => {
let controller; let controller;
let $httpBackend; let $httpBackend;
let data = {id: 1, name: 'fooName'}; const expectedAmount = 99;
const data = {
id: 1,
name: 'fooName',
invoiceInDueDay: [{amount: expectedAmount}]
};
beforeEach(ngModule('invoiceIn')); beforeEach(ngModule('invoiceIn'));
@ -21,7 +26,8 @@ describe('vnInvoiceIn', () => {
controller.reload(); controller.reload();
$httpBackend.flush(); $httpBackend.flush();
expect(controller.invoiceIn).toEqual(data); expect(controller.invoiceIn).toBeDefined();
expect(controller.invoiceIn.amount).toEqual(expectedAmount);
}); });
}); });

View File

@ -0,0 +1,49 @@
<vn-descriptor-content module="invoiceIn" description="$ctrl.invoiceIn.supplierRef">
<slot-menu>
<vn-item
ng-click="deleteConfirmation.show()"
vn-acl="invoicing"
vn-acl-action="remove"
name="deleteInvoice"
translate>
Delete Invoice
</vn-item>
</slot-menu>
<slot-body>
<div class="attributes">
<vn-label-value label="Date" value="{{$ctrl.invoiceIn.issued | date: 'dd/MM/yyyy'}}">
</vn-label-value>
<vn-label-value label="Booked" value="{{$ctrl.invoiceIn.booked | date: 'dd/MM/yyyy'}}">
</vn-label-value>
<vn-label-value label="Import" value="{{$ctrl.invoiceIn.amount | currency: 'EUR': 2}}">
</vn-label-value>
<vn-label-value label="Supplier">
<span ng-click="supplierDescriptor.show($event, $ctrl.invoiceIn.supplier.id)" class="link">
{{$ctrl.invoiceIn.supplier.nickname}}
</span>
</vn-label-value>
</div>
<div class="quicklinks">
<div ng-transclude="btnOne">
<vn-quick-link tooltip="Supplier" state="['supplier.card.summary', {id: $ctrl.invoiceIn.supplier.id}]"
icon="icon-supplier">
</vn-quick-link>
</div>
<div ng-transclude="btnTwo">
<vn-quick-link tooltip="Entries list" state="['entry.index', {q: $ctrl.entryFilter}]"
icon="icon-entry">
</vn-quick-link>
</div>
<div ng-transclude="btnThree">
<vn-quick-link tooltip="Invoice list" state="['invoiceIn.index', {q: $ctrl.invoiceInFilter}]"
icon="icon-invoiceIn">
</vn-quick-link>
</div>
</div>
</slot-body>
</vn-descriptor-content>
<vn-confirm vn-id="deleteConfirmation" on-accept="$ctrl.deleteInvoiceIn()"
question="Are you sure you want to delete this invoice?">
</vn-confirm>
<vn-supplier-descriptor-popover vn-id="supplierDescriptor">
</vn-supplier-descriptor-popover>

View File

@ -10,6 +10,26 @@ class Controller extends Descriptor {
this.entity = value; this.entity = value;
} }
get entryFilter() {
if (this.invoiceIn)
return JSON.stringify({invoiceInFk: this.invoiceIn.id});
return null;
}
get invoiceInFilter() {
if (this.invoiceIn)
return JSON.stringify({supplierFk: this.invoiceIn.supplierFk});
return null;
}
deleteInvoiceIn() {
return this.$http.delete(`InvoiceIns/${this.id}`)
.then(() => this.$state.go('invoiceIn.index'))
.then(() => this.vnApp.showSuccess(this.$t('InvoiceIn deleted')));
}
loadData() { loadData() {
const filter = { const filter = {
include: [ include: [

View File

@ -6,3 +6,5 @@ import './search-panel';
import './card'; import './card';
import './descriptor'; import './descriptor';
import './descriptor-popover'; import './descriptor-popover';
import './summary';
import './basic-data';

View File

@ -22,8 +22,10 @@
</vn-tr> </vn-tr>
</vn-thead> </vn-thead>
<vn-tbody> <vn-tbody>
<a ng-repeat="invoiceIn in model.data" <a
class="clickable vn-tr search-result"> ng-repeat="invoiceIn in model.data"
class="clickable vn-tr search-result"
ui-sref="invoiceIn.card.summary({id: {{::invoiceIn.id}}})">
<vn-td>{{::invoiceIn.id}}</vn-td> <vn-td>{{::invoiceIn.id}}</vn-td>
<vn-td> <vn-td>
<span <span
@ -67,38 +69,6 @@
</vn-data-viewer> </vn-data-viewer>
<vn-popup vn-id="summary"> <vn-popup vn-id="summary">
<vn-invoice-in-summary <vn-invoice-in-summary
invoice-in="$ctrl.selectedinvoiceIn"> invoice-in="$ctrl.selectedInvoiceIn">
</vn-invoice-in-summary> </vn-invoice-in-summary>
</vn-popup> </vn-popup>
<vn-supplier-descriptor-popover
vn-id="supplierDescriptor">
</vn-supplier-descriptor-popover>
<vn-contextmenu vn-id="contextmenu" targets="['vn-data-viewer']" model="model"
expr-builder="$ctrl.exprBuilder(param, value)">
<slot-menu>
<vn-item translate
ng-if="contextmenu.isFilterAllowed()"
ng-click="contextmenu.filterBySelection()">
Filter by selection
</vn-item>
<vn-item translate
ng-if="contextmenu.isFilterAllowed()"
ng-click="contextmenu.excludeSelection()">
Exclude selection
</vn-item>
<vn-item translate
ng-if="contextmenu.isFilterAllowed()"
ng-click="contextmenu.removeFilter()">
Remove filter
</vn-item>
<vn-item translate
ng-click="contextmenu.removeAllFilters()">
Remove all filters
</vn-item>
<vn-item translate
ng-if="contextmenu.isActionAllowed()"
ng-click="contextmenu.copyValue()">
Copy value
</vn-item>
</slot-menu>
</vn-contextmenu>

View File

@ -34,6 +34,11 @@ export default class Controller extends Section {
return [minHour, maxHour]; return [minHour, maxHour];
} }
preview(invoiceIn) {
this.selectedInvoiceIn = invoiceIn;
this.$.summary.show();
}
} }
ngModule.vnComponent('vnInvoiceInIndex', { ngModule.vnComponent('vnInvoiceInIndex', {

View File

@ -1,2 +1,5 @@
InvoiceIn: Facturas recibidas InvoiceIn: Facturas recibidas
Search invoices in by reference: Buscar facturas recibidas por referencia Search invoices in by reference: Buscar facturas recibidas por referencia
Entries list: Listado de entradas
Invoice list: Listado de entradas
InvoiceIn deleted: Factura eliminada

View File

@ -7,6 +7,12 @@
"menus": { "menus": {
"main": [ "main": [
{"state": "invoiceIn.index", "icon": "icon-invoiceIn"} {"state": "invoiceIn.index", "icon": "icon-invoiceIn"}
],
"card": [
{
"state": "invoiceIn.card.basicData",
"icon": "settings"
}
] ]
}, },
"routes": [ "routes": [
@ -36,9 +42,18 @@
"component": "vn-invoice-in-summary", "component": "vn-invoice-in-summary",
"description": "Summary", "description": "Summary",
"params": { "params": {
"invoice-In": "$ctrl.invoiceIn" "invoice-in": "$ctrl.invoiceIn"
}, },
"acl": ["developer"] "acl": ["administrative"]
},
{
"url": "/basic-data",
"state": "invoiceIn.card.basicData",
"component": "vn-invoice-in-basic-data",
"description": "Basic data",
"params": {
"invoice-in": "$ctrl.invoiceIn"
}
} }
] ]
} }

View File

@ -0,0 +1,52 @@
<vn-card class="summary">
<h5>
<a
ng-if="::$ctrl.summary.id"
vn-tooltip="Go to the Invoice In"
ui-sref="invoiceIn.card.summary({id: {{::$ctrl.summary.id}}})"
name="goToSummary">
<vn-icon-button icon="launch"></vn-icon-button>
</a>
<span>{{$ctrl.summary.id}} - {{$ctrl.summary.supplier.name}}</span>
</h5>
<vn-horizontal>
<vn-auto>
<h4 translate>Basic data</h4>
<vn-horizontal>
<vn-one>
<vn-label-value label="Supplier" value="{{$ctrl.summary.supplier.name}}">
</vn-label-value>
<vn-label-value label="Supplier ref" value="{{$ctrl.summary.supplierRef}}">
</vn-label-value>
<vn-label-value label="Doc number" value="{{$ctrl.summary.serial}}/{{$ctrl.summary.serialNumber}}">
</vn-label-value>
</vn-one>
<vn-one>
<vn-label-value label="Expedition date" value="{{$ctrl.summary.issued | date: 'dd/MM/yyyy'}}">
</vn-label-value>
<vn-label-value label="Operation date" value="{{$ctrl.summary.operated | date: 'dd/MM/yyyy'}}">
</vn-label-value>
<vn-label-value label="Entry date" value="{{$ctrl.summary.bookEntried | date: 'dd/MM/yyyy'}}">
</vn-label-value>
<vn-label-value label="Booked date" value="{{$ctrl.summary.booked | date: 'dd/MM/yyyy'}}">
</vn-label-value>
</vn-one>
<vn-one>
<vn-label-value label="Sage withholding" value="{{$ctrl.summary.sageWithholding.withholding}}">
</vn-label-value>
<vn-label-value label="Company" value="{{$ctrl.summary.company.code}}">
</vn-label-value>
<vn-vertical>
<vn-check label="Deductible" ng-model="$ctrl.summary.isVatDeductible" disabled="true">
</vn-check>
<vn-check label="Booked" ng-model="$ctrl.summary.isBooked" disabled="true">
</vn-check>
</vn-vertical>
</vn-one>
</vn-horizontal>
</vn-auto>
</vn-horizontal>
</vn-card>
<vn-supplier-descriptor-popover
vn-id="supplierDescriptor">
</vn-supplier-descriptor-popover>

View File

@ -0,0 +1,28 @@
import ngModule from '../module';
import Summary from 'salix/components/summary';
import './style.scss';
class Controller extends Summary {
set invoiceIn(value) {
this._invoiceIn = value;
if (value && value.id)
this.getSummary();
}
get invoiceIn() {
return this._invoiceIn;
}
getSummary() {
return this.$http.get(`InvoiceIns/${this.invoiceIn.id}/summary`)
.then(res => this.summary = res.data);
}
}
ngModule.vnComponent('vnInvoiceInSummary', {
template: require('./index.html'),
controller: Controller,
bindings: {
invoiceIn: '<'
}
});

View File

@ -0,0 +1,29 @@
import './index.js';
describe('InvoiceIn', () => {
describe('Component summary', () => {
let controller;
let $httpBackend;
let $scope;
beforeEach(ngModule('invoiceIn'));
beforeEach(inject(($componentController, _$httpBackend_, $rootScope) => {
$httpBackend = _$httpBackend_;
$scope = $rootScope.$new();
const $element = angular.element('<vn-invoice-in-summary></vn-invoice-in-summary>');
controller = $componentController('vnInvoiceInSummary', {$element, $scope});
controller.invoiceIn = {id: 1};
}));
describe('getSummary()', () => {
it('should perform a query to set summary', () => {
$httpBackend.when('GET', `InvoiceIns/1/summary`).respond(200, 'the data you are looking for');
controller.getSummary();
$httpBackend.flush();
expect(controller.summary).toEqual('the data you are looking for');
});
});
});
});

View File

@ -0,0 +1,10 @@
Go to the Invoice In: Ir a la factura recibida
Expedition date: Fecha expedición
Operation date: Fecha operación
Supplier ref: Ref. proveedor
Entry date: Fecha asiento
Booked date: Fecha contable
Accounted date: Fecha contable
Doc number: Numero documento
Sage withholding: Retención sage
Deductible: Deducible

View File

@ -0,0 +1,5 @@
@import "variables";
vn-invoice-in-summary .summary {
width: $width-lg;
}