Merge branch 'dev' into 3622-client_defaulter
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Joan Sanchez 2022-03-01 09:33:38 +00:00
commit b7dd4952df
30 changed files with 633 additions and 45 deletions

View File

@ -0,0 +1,93 @@
const got = require('got');
module.exports = Self => {
Self.remoteMethodCtx('checkFile', {
description: 'Check if exist docuware file',
accessType: 'READ',
accepts: [
{
arg: 'id',
type: 'number',
description: 'The id',
http: {source: 'path'}
},
{
arg: 'fileCabinet',
type: 'string',
required: true,
description: 'The fileCabinet name'
},
{
arg: 'dialog',
type: 'string',
required: true,
description: 'The dialog name'
}
],
returns: {
type: 'boolean',
root: true
},
http: {
path: `/:id/checkFile`,
verb: 'POST'
}
});
Self.checkFile = async function(ctx, id, fileCabinet, dialog) {
const myUserId = ctx.req.accessToken.userId;
if (!myUserId)
return false;
const models = Self.app.models;
const docuwareConfig = await models.DocuwareConfig.findOne();
const docuwareInfo = await models.Docuware.findOne({
where: {
code: fileCabinet,
dialogName: dialog
}
});
const docuwareUrl = docuwareConfig.url;
const cookie = docuwareConfig.token;
const fileCabinetName = docuwareInfo.fileCabinetName;
const find = docuwareInfo.find;
const options = {
'headers': {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Cookie': cookie
}
};
const searchFilter = {
condition: [
{
DBName: find,
Value: [id]
}
]
};
try {
// get fileCabinetId
const fileCabinetResponse = await got.get(`${docuwareUrl}/FileCabinets`, options);
const fileCabinetJson = JSON.parse(fileCabinetResponse.body).FileCabinet;
const fileCabinetId = fileCabinetJson.find(dialogs => dialogs.Name === fileCabinetName).Id;
// get dialog
const dialogResponse = await got.get(`${docuwareUrl}/FileCabinets/${fileCabinetId}/dialogs`, options);
const dialogJson = JSON.parse(dialogResponse.body).Dialog;
const dialogId = dialogJson.find(dialogs => dialogs.DisplayName === 'find').Id;
// get docuwareID
Object.assign(options, {'body': JSON.stringify(searchFilter)});
const response = await got.post(
`${docuwareUrl}/FileCabinets/${fileCabinetId}/Query/DialogExpression?dialogId=${dialogId}`, options);
JSON.parse(response.body).Items[0].Id;
return true;
} catch (error) {
return false;
}
};
};

View File

@ -0,0 +1,120 @@
/* eslint max-len: ["error", { "code": 180 }]*/
const got = require('got');
const UserError = require('vn-loopback/util/user-error');
module.exports = Self => {
Self.remoteMethodCtx('download', {
description: 'Download an docuware PDF',
accessType: 'READ',
accepts: [
{
arg: 'id',
type: 'number',
description: 'The id',
http: {source: 'path'}
},
{
arg: 'fileCabinet',
type: 'string',
description: 'The id',
http: {source: 'path'}
},
{
arg: 'dialog',
type: 'string',
description: 'The id',
http: {source: 'path'}
}
],
returns: [
{
arg: 'body',
type: 'file',
root: true
}, {
arg: 'Content-Type',
type: 'string',
http: {target: 'header'}
}, {
arg: 'Content-Disposition',
type: 'string',
http: {target: 'header'}
}
],
http: {
path: `/:id/download/:fileCabinet/:dialog`,
verb: 'GET'
}
});
Self.download = async function(ctx, id, fileCabinet, dialog) {
const myUserId = ctx.req.accessToken.userId;
if (!myUserId)
throw new UserError(`You don't have enough privileges`);
const models = Self.app.models;
const docuwareConfig = await models.DocuwareConfig.findOne();
const docuwareInfo = await models.Docuware.findOne({
where: {
code: fileCabinet,
dialogName: dialog
}
});
const docuwareUrl = docuwareConfig.url;
const cookie = docuwareConfig.token;
const fileCabinetName = docuwareInfo.fileCabinetName;
const find = docuwareInfo.find;
const options = {
'headers': {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Cookie': cookie
}
};
const searchFilter = {
condition: [
{
DBName: find,
Value: [id]
}
]
};
try {
// get fileCabinetId
const fileCabinetResponse = await got.get(`${docuwareUrl}/FileCabinets`, options);
const fileCabinetJson = JSON.parse(fileCabinetResponse.body).FileCabinet;
const fileCabinetId = fileCabinetJson.find(dialogs => dialogs.Name === fileCabinetName).Id;
// get dialog
const dialogResponse = await got.get(`${docuwareUrl}/FileCabinets/${fileCabinetId}/dialogs`, options);
const dialogJson = JSON.parse(dialogResponse.body).Dialog;
const dialogId = dialogJson.find(dialogs => dialogs.DisplayName === 'find').Id;
// get docuwareID
Object.assign(options, {'body': JSON.stringify(searchFilter)});
const response = await got.post(`${docuwareUrl}/FileCabinets/${fileCabinetId}/Query/DialogExpression?dialogId=${dialogId}`, options);
const docuwareId = JSON.parse(response.body).Items[0].Id;
// download & save file
const fileName = `filename="${id}.pdf"`;
const contentType = 'application/pdf';
const downloadUri = `${docuwareUrl}/FileCabinets/${fileCabinetId}/Documents/${docuwareId}/FileDownload?targetFileType=Auto&keepAnnotations=false`;
const downloadOptions = {
'headers': {
'Cookie': cookie
}
};
const stream = got.stream(downloadUri, downloadOptions);
return [stream, contentType, fileName];
} catch (error) {
if (error.code === 'ENOENT')
throw new UserError('The DOCUWARE PDF document does not exists');
throw error;
}
};
};

View File

@ -0,0 +1,64 @@
const models = require('vn-loopback/server/server').models;
const got = require('got');
describe('docuware download()', () => {
const ticketId = 1;
const userId = 9;
const ctx = {
req: {
accessToken: {userId: userId},
headers: {origin: 'http://localhost:5000'},
}
};
const fileCabinetName = 'deliveryClientTest';
const dialogDisplayName = 'find';
const dialogName = 'findTest';
const gotGetResponse = {
body: JSON.stringify(
{
FileCabinet: [
{Id: 12, Name: fileCabinetName}
],
Dialog: [
{Id: 34, DisplayName: dialogDisplayName}
]
})
};
it('should return exist file in docuware', async() => {
const gotPostResponse = {
body: JSON.stringify(
{
Items: [
{Id: 56}
],
})
};
spyOn(got, 'get').and.returnValue(new Promise(resolve => resolve(gotGetResponse)));
spyOn(got, 'post').and.returnValue(new Promise(resolve => resolve(gotPostResponse)));
const result = await models.Docuware.checkFile(ctx, ticketId, fileCabinetName, dialogName);
expect(result).toEqual(true);
});
it('should return not exist file in docuware', async() => {
const gotPostResponse = {
body: JSON.stringify(
{
Items: [],
})
};
spyOn(got, 'get').and.returnValue(new Promise(resolve => resolve(gotGetResponse)));
spyOn(got, 'post').and.returnValue(new Promise(resolve => resolve(gotPostResponse)));
const result = await models.Docuware.checkFile(ctx, ticketId, fileCabinetName, dialogName);
expect(result).toEqual(false);
});
});

View File

@ -0,0 +1,50 @@
const models = require('vn-loopback/server/server').models;
const got = require('got');
const stream = require('stream');
describe('docuware download()', () => {
const userId = 9;
const ticketId = 1;
const ctx = {
req: {
accessToken: {userId: userId},
headers: {origin: 'http://localhost:5000'},
}
};
it('should return the downloaded file name', async() => {
const fileCabinetName = 'deliveryClientTest';
const dialogDisplayName = 'find';
const dialogName = 'findTest';
const gotGetResponse = {
body: JSON.stringify(
{
FileCabinet: [
{Id: 12, Name: fileCabinetName}
],
Dialog: [
{Id: 34, DisplayName: dialogDisplayName}
]
})
};
const gotPostResponse = {
body: JSON.stringify(
{
Items: [
{Id: 56}
],
})
};
spyOn(got, 'get').and.returnValue(new Promise(resolve => resolve(gotGetResponse)));
spyOn(got, 'post').and.returnValue(new Promise(resolve => resolve(gotPostResponse)));
spyOn(got, 'stream').and.returnValue(new stream.PassThrough({objectMode: true}));
const result = await models.Docuware.download(ctx, ticketId, fileCabinetName, dialogName);
expect(result[1]).toEqual('application/pdf');
expect(result[2]).toEqual(`filename="${ticketId}.pdf"`);
});
});

View File

@ -44,6 +44,12 @@
"DmsType": { "DmsType": {
"dataSource": "vn" "dataSource": "vn"
}, },
"Docuware": {
"dataSource": "vn"
},
"DocuwareConfig": {
"dataSource": "vn"
},
"EmailUser": { "EmailUser": {
"dataSource": "vn" "dataSource": "vn"
}, },

View File

@ -0,0 +1,32 @@
{
"name": "DocuwareConfig",
"description": "Docuware config",
"base": "VnModel",
"options": {
"mysql": {
"table": "docuwareConfig"
}
},
"properties": {
"id": {
"type": "number",
"id": true,
"description": "Identifier"
},
"url": {
"type": "string"
},
"token": {
"type": "string"
}
},
"acls": [
{
"property": "*",
"accessType": "*",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "ALLOW"
}
]
}

4
back/models/docuware.js Normal file
View File

@ -0,0 +1,4 @@
module.exports = Self => {
require('../methods/docuware/download')(Self);
require('../methods/docuware/checkFile')(Self);
};

38
back/models/docuware.json Normal file
View File

@ -0,0 +1,38 @@
{
"name": "Docuware",
"description": "Docuware sections",
"base": "VnModel",
"options": {
"mysql": {
"table": "docuware"
}
},
"properties": {
"id": {
"type": "number",
"id": true,
"description": "Identifier"
},
"code": {
"type": "string"
},
"fileCabinetName": {
"type": "string"
},
"dialogName": {
"type": "string"
},
"find": {
"type": "string"
}
},
"acls": [
{
"property": "*",
"accessType": "*",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "ALLOW"
}
]
}

View File

@ -0,0 +1,3 @@
INSERT INTO salix.ACL
(model, property, accessType, permission, principalType, principalId)
VALUES('Docuware', '*', '*', 'ALLOW', 'ROLE', 'employee');

View File

@ -0,0 +1,11 @@
CREATE TABLE `vn`.`docuware` (
`id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`code` varchar(50) NULL,
`fileCabinetName` varchar(50) NULL,
`dialogName` varchar(255) DEFAULT NULL,
`find` varchar(50) DEFAULT NULL
);
INSERT INTO `vn`.`docuware` (`code`, `fileCabinetName`, `dialogName` , `find`)
VALUES
('deliveryClient', 'Albaranes cliente', 'findTicket', 'N__ALBAR_N');

View File

@ -0,0 +1,9 @@
CREATE TABLE `vn`.`docuwareConfig` (
`id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`url` varchar(75) NULL,
`token` varchar(1000) DEFAULT NULL
);
INSERT INTO `vn`.`docuwareConfig` (`url`)
VALUES
('https://verdnatura.docuware.cloud/docuware/platform');

View File

@ -6,19 +6,22 @@ CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`ticket_getMovable`(vTicketFk INT, vDat
BEGIN BEGIN
/** /**
* Cálcula el stock movible para los artículos de un ticket * Cálcula el stock movible para los artículos de un ticket
* vDatedNew debe ser menor que vDatedOld, en los otros casos se
* asume que siempre es posible
* *
* @param vTicketFk -> Ticket * @param vTicketFk -> Ticket
* @param vDatedNew -> Nueva fecha * @param vDatedNew -> Nueva fecha
* @return Sales con Movible * @return Sales con Movible
*/ */
DECLARE vDatedOld DATETIME; DECLARE vDatedOld DATETIME;
SET vDatedNew = DATE_ADD(vDatedNew, INTERVAL 1 DAY);
SELECT t.shipped INTO vDatedOld SELECT t.shipped INTO vDatedOld
FROM ticket t FROM ticket t
WHERE t.id = vTicketFk; WHERE t.id = vTicketFk;
CALL itemStock(vWarehouseFk, DATE_SUB(vDatedNew, INTERVAL 1 DAY), NULL); CALL itemStock(vWarehouseFk, vDatedNew, NULL);
CALL item_getMinacum(vWarehouseFk, vDatedNew, DATEDIFF(vDatedOld, vDatedNew), NULL); CALL item_getMinacum(vWarehouseFk, vDatedNew, DATEDIFF(DATE_SUB(vDatedOld, INTERVAL 1 DAY), vDatedNew), NULL);
SELECT s.id, SELECT s.id,
s.itemFk, s.itemFk,

View File

@ -2443,3 +2443,11 @@ INSERT INTO `bs`.`defaulter` (`clientFk`, `amount`, `created`, `defaulterSinced`
(1103, 500, CURDATE(), CURDATE()), (1103, 500, CURDATE(), CURDATE()),
(1107, 500, CURDATE(), CURDATE()), (1107, 500, CURDATE(), CURDATE()),
(1109, 500, CURDATE(), CURDATE()); (1109, 500, CURDATE(), CURDATE());
INSERT INTO `vn`.`docuware` (`code`, `fileCabinetName`, `dialogName` , `find`)
VALUES
('deliveryClientTest', 'deliveryClientTest', 'findTest', 'word');
INSERT INTO `vn`.`docuwareConfig` (`url`)
VALUES
('https://verdnatura.docuware.cloud/docuware/platform');

View File

@ -1,6 +1,10 @@
module.exports = Self => { module.exports = Self => {
Self.getSynchronizer = async function() { Self.getSynchronizer = async function() {
let NODE_ENV = process.env.NODE_ENV;
if (!NODE_ENV || NODE_ENV == 'development')
return null;
return await Self.findOne({ return await Self.findOne({
fields: ['id', 'rolePrefix', 'userPrefix', 'userHost'] fields: ['id', 'rolePrefix', 'userPrefix', 'userHost']
}); });

View File

@ -1,7 +1,8 @@
const models = require('vn-loopback/server/server').models; const models = require('vn-loopback/server/server').models;
const soap = require('soap'); const soap = require('soap');
describe('client sendSms()', () => { // #3673 sendSms tests excluded
xdescribe('client sendSms()', () => {
it('should now send a message and log it', async() => { it('should now send a message and log it', async() => {
spyOn(soap, 'createClientAsync').and.returnValue('a so fake client'); spyOn(soap, 'createClientAsync').and.returnValue('a so fake client');
const tx = await models.Client.beginTransaction({}); const tx = await models.Client.beginTransaction({});

View File

@ -1,6 +1,7 @@
const app = require('vn-loopback/server/server'); const app = require('vn-loopback/server/server');
describe('sms send()', () => { // #3673 sendSms tests excluded
xdescribe('sms send()', () => {
it('should not return status error', async() => { it('should not return status error', async() => {
const ctx = {req: {accessToken: {userId: 1}}}; const ctx = {req: {accessToken: {userId: 1}}};
const result = await app.models.Sms.send(ctx, 1105, '123456789', 'My SMS Body'); const result = await app.models.Sms.send(ctx, 1105, '123456789', 'My SMS Body');

View File

@ -10,7 +10,6 @@
name="showInvoicePdf" name="showInvoicePdf"
translate> translate>
Show invoice... Show invoice...
<vn-menu vn-id="showInvoiceMenu"> <vn-menu vn-id="showInvoiceMenu">
<vn-list> <vn-list>
<a class="vn-item" <a class="vn-item"
@ -33,7 +32,6 @@
name="sendInvoice" name="sendInvoice"
translate> translate>
Send invoice... Send invoice...
<vn-menu vn-id="sendInvoiceMenu"> <vn-menu vn-id="sendInvoiceMenu">
<vn-list> <vn-list>
<vn-item <vn-item

View File

@ -3,13 +3,21 @@
url="Items/getWasteByWorker" url="Items/getWasteByWorker"
data="details"> data="details">
</vn-crud-model> </vn-crud-model>
<vn-data-viewer model="model"> <vn-data-viewer model="model">
<vn-card>
<section ng-repeat="detail in details" class="vn-pa-md"> <section ng-repeat="detail in details" class="vn-pa-md">
<vn-horizontal class="header"> <vn-horizontal class="header">
<h5><span><span translate>{{detail.buyer}}</span></h5> <h5><span translate>{{detail.buyer}}</span></h5>
<vn-none>
<vn-icon
ng-class="{'hidden': !$ctrl.wasteConfig[detail.buyer].hidden}"
class="arrow pointer"
icon="keyboard_arrow_up"
vn-tooltip="Minimize/Maximize"
ng-click="$ctrl.toggleHidePanel(detail)">
</vn-icon>
</vn-none>
</vn-horizontal> </vn-horizontal>
<vn-card ng-class="{'hidden': !$ctrl.wasteConfig[detail.buyer].hidden}">
<vn-table> <vn-table>
<vn-thead> <vn-thead>
<vn-tr> <vn-tr>
@ -21,7 +29,7 @@
</vn-thead> </vn-thead>
<vn-tbody> <vn-tbody>
<a ng-repeat="waste in detail.lines" class="clickable vn-tr" <a ng-repeat="waste in detail.lines" class="clickable vn-tr"
ui-sref="item.waste.detail({buyer: waste.buyer, family: waste.family})" > ui-sref="item.waste.detail({buyer: waste.buyer, family: waste.family})">
<vn-td class="waste-family">{{::waste.family}}</vn-td> <vn-td class="waste-family">{{::waste.family}}</vn-td>
<vn-td number>{{::(waste.percentage / 100) | percentage: 2}}</vn-td> <vn-td number>{{::(waste.percentage / 100) | percentage: 2}}</vn-td>
<vn-td number>{{::waste.dwindle | currency: 'EUR'}}</vn-td> <vn-td number>{{::waste.dwindle | currency: 'EUR'}}</vn-td>
@ -29,6 +37,6 @@
</vn-tr> </vn-tr>
</vn-tbody> </vn-tbody>
</vn-table> </vn-table>
</section>
</vn-card> </vn-card>
</section>
</vn-data-viewer> </vn-data-viewer>

View File

@ -2,7 +2,34 @@ import ngModule from '../../module';
import Section from 'salix/components/section'; import Section from 'salix/components/section';
import './style.scss'; import './style.scss';
export default class Controller extends Section {
constructor($element, $) {
super($element, $);
this.getWasteConfig();
}
getWasteConfig() {
return this.wasteConfig = JSON.parse(localStorage.getItem('wasteConfig')) || {};
}
setWasteConfig() {
localStorage.setItem('wasteConfig', JSON.stringify(this.wasteConfig));
}
toggleHidePanel(detail) {
if (!this.wasteConfig[detail.buyer]) {
this.wasteConfig[detail.buyer] = {
hidden: true
};
} else
this.wasteConfig[detail.buyer].hidden = !this.wasteConfig[detail.buyer].hidden;
this.setWasteConfig();
}
}
ngModule.vnComponent('vnItemWasteIndex', { ngModule.vnComponent('vnItemWasteIndex', {
template: require('./index.html'), template: require('./index.html'),
controller: Section controller: Controller
}); });

View File

@ -0,0 +1,53 @@
import './index.js';
import crudModel from 'core/mocks/crud-model';
describe('Item', () => {
describe('Component vnItemWasteIndex', () => {
let $scope;
let controller;
beforeEach(ngModule('item'));
beforeEach(inject(($componentController, $rootScope) => {
$scope = $rootScope.$new();
$scope.model = crudModel;
const $element = angular.element('<vn-item-waste-index></vn-item-waste-index>');
controller = $componentController('vnItemWasteIndex', {$element, $scope});
}));
describe('getWasteConfig / setWasteConfig', () => {
it('should return the local storage wasteConfig', () => {
const result = controller.getWasteConfig();
expect(result).toEqual({});
});
it('should set and return the local storage wasteConfig', () => {
controller.wasteConfig = {salesPerson: {hidden: true}};
controller.setWasteConfig();
const result = controller.getWasteConfig();
expect(result).toEqual(controller.wasteConfig);
});
});
describe('toggleHidePanel()', () => {
it('should make details hidden by default', () => {
controller.wasteConfig = {};
controller.toggleHidePanel({buyer: 'salesPerson'});
expect(controller.wasteConfig.salesPerson.hidden).toEqual(true);
});
it('should toggle hidden false', () => {
controller.wasteConfig = {salesPerson: {hidden: true}};
controller.toggleHidePanel({buyer: 'salesPerson'});
expect(controller.wasteConfig.salesPerson.hidden).toEqual(false);
});
});
});
});

View File

@ -1,21 +1,24 @@
@import "variables"; @import "variables";
@import "effects";
vn-item-waste-index, vn-item-waste-index,
vn-item-waste-detail { vn-item-waste-detail {
.header { .header {
margin-bottom: 16px; padding: 12px 0 5px 0;
text-transform: uppercase; color: gray;
font-size: 1.25rem; font-size: 1.2rem;
line-height: 1; border-bottom: $border;
padding: 7px; margin-bottom: 10px;
padding-bottom: 7px;
padding-bottom: 4px; & > vn-none > vn-icon {
font-weight: lighter; @extend %clickable-light;
background-color: $color-bg; color: $color-button;
border-bottom: 1px solid #f7931e; font-size: 1.4rem;
white-space: nowrap; }
overflow: hidden;
text-overflow: ellipsis; vn-none > .arrow {
transition: transform 200ms;
}
} }
vn-table vn-th.waste-family, vn-table vn-th.waste-family,
@ -23,4 +26,12 @@ vn-item-waste-detail {
max-width: 64px; max-width: 64px;
width: 64px width: 64px
} }
.hidden {
display: none;
}
.header > vn-none > .arrow.hidden {
display: block;
transform: rotate(180deg);
}
} }

View File

@ -1,3 +1,4 @@
Family: Familia Family: Familia
Percentage: Porcentaje Percentage: Porcentaje
Dwindle: Mermas Dwindle: Mermas
Minimize/Maximize: Minimizar/Maximizar

View File

@ -86,8 +86,8 @@ describe('sale priceDifference()', () => {
const firstItem = result.items[0]; const firstItem = result.items[0];
const secondtItem = result.items[1]; const secondtItem = result.items[1];
expect(firstItem.movable).toEqual(440); expect(firstItem.movable).toEqual(410);
expect(secondtItem.movable).toEqual(1980); expect(secondtItem.movable).toEqual(1870);
await tx.rollback(); await tx.rollback();
} catch (e) { } catch (e) {

View File

@ -1,7 +1,8 @@
const models = require('vn-loopback/server/server').models; const models = require('vn-loopback/server/server').models;
const soap = require('soap'); const soap = require('soap');
describe('ticket sendSms()', () => { // #3673 sendSms tests excluded
xdescribe('ticket sendSms()', () => {
it('should send a message and log it', async() => { it('should send a message and log it', async() => {
const tx = await models.Ticket.beginTransaction({}); const tx = await models.Ticket.beginTransaction({});

View File

@ -18,7 +18,14 @@
</vn-thead> </vn-thead>
<vn-tbody> <vn-tbody>
<vn-tr ng-repeat="sale in $ctrl.ticket.sale.items track by sale.id"> <vn-tr ng-repeat="sale in $ctrl.ticket.sale.items track by sale.id">
<vn-td number>{{("000000"+sale.itemFk).slice(-6)}}</vn-td> <vn-td number>
<span
title="{{::sale.item.name}}"
vn-click-stop="itemDescriptor.show($event, sale.itemFk, sale.id)"
class="link">
{{::sale.itemFk | zeroFill:6}}
</span>
</vn-td>
<vn-td vn-fetched-tags> <vn-td vn-fetched-tags>
<div> <div>
<vn-one title="{{::sale.item.name}}">{{::sale.item.name}}</vn-one> <vn-one title="{{::sale.item.name}}">{{::sale.item.name}}</vn-one>
@ -83,5 +90,9 @@
</div> </div>
</div> </div>
</vn-side-menu> </vn-side-menu>
<vn-item-descriptor-popover
vn-id="item-descriptor"
warehouse-fk="$ctrl.ticket.warehouseFk"
ticket-fk="$ctrl.ticket.id">
</vn-item-descriptor-popover>

View File

@ -20,14 +20,22 @@
<vn-menu vn-id="showDeliveryNoteMenu"> <vn-menu vn-id="showDeliveryNoteMenu">
<vn-list> <vn-list>
<vn-item <vn-item
ng-if="!$ctrl.hasDocuwareFile"
ng-click="$ctrl.showPdfDeliveryNote()" ng-click="$ctrl.showPdfDeliveryNote()"
translate> translate>
Show as PDF as PDF
</vn-item> </vn-item>
<a class="vn-item"
ng-if="$ctrl.hasDocuwareFile"
href='api/Docuwares/{{$ctrl.ticket.id}}/download/deliveryClient/findTicket?access_token={{$ctrl.vnToken.token}}'
target="_blank"
translate>
as PDF
</a>
<vn-item <vn-item
ng-click="$ctrl.showCsvDeliveryNote()" ng-click="$ctrl.showCsvDeliveryNote()"
translate> translate>
Show as CSV as CSV
</vn-item> </vn-item>
</vn-list> </vn-list>
</vn-menu> </vn-menu>

View File

@ -84,6 +84,7 @@ class Controller extends Section {
.then(() => { .then(() => {
this.canStowaway(); this.canStowaway();
this.isTicketEditable(); this.isTicketEditable();
this.hasDocuware();
}); });
} }
@ -122,6 +123,15 @@ class Controller extends Section {
}); });
} }
hasDocuware() {
const params = {
fileCabinet: 'deliveryClient',
dialog: 'findTicket'
};
this.$http.post(`Docuwares/${this.id}/checkFile`, params)
.then(res => this.hasDocuwareFile = res.data);
}
showCsvDeliveryNote() { showCsvDeliveryNote() {
this.vnReport.showCsv('delivery-note', { this.vnReport.showCsv('delivery-note', {
recipientId: this.ticket.client.id, recipientId: this.ticket.client.id,

View File

@ -206,7 +206,8 @@ describe('Ticket Component vnTicketDescriptorMenu', () => {
it('should make a query and show a success snackbar', () => { it('should make a query and show a success snackbar', () => {
jest.spyOn(controller.vnApp, 'showSuccess'); jest.spyOn(controller.vnApp, 'showSuccess');
$httpBackend.whenGET(`Tickets/16`).respond(); $httpBackend.whenPOST(`Docuwares/${ticket.id}/checkFile`).respond();
$httpBackend.whenGET(`Tickets/${ticket.id}`).respond();
$httpBackend.expectPOST(`InvoiceOuts/${ticket.invoiceOut.id}/createPdf`).respond(); $httpBackend.expectPOST(`InvoiceOuts/${ticket.invoiceOut.id}/createPdf`).respond();
controller.createPdfInvoice(); controller.createPdfInvoice();
$httpBackend.flush(); $httpBackend.flush();
@ -275,4 +276,12 @@ describe('Ticket Component vnTicketDescriptorMenu', () => {
}); });
}); });
}); });
describe('hasDocuware()', () => {
it('should call hasDocuware method', () => {
$httpBackend.whenPOST(`Docuwares/${ticket.id}/checkFile`).respond();
controller.hasDocuware();
$httpBackend.flush();
});
});
}); });

View File

@ -1,7 +1,7 @@
Show Delivery Note...: Ver albarán... Show Delivery Note...: Ver albarán...
Send Delivery Note...: Enviar albarán... Send Delivery Note...: Enviar albarán...
Show as PDF: Ver como PDF as PDF: como PDF
Show as CSV: Ver como CSV as CSV: como CSV
Send PDF: Enviar PDF Send PDF: Enviar PDF
Send CSV: Enviar CSV Send CSV: Enviar CSV
Send CSV Delivery Note: Enviar albarán en CSV Send CSV Delivery Note: Enviar albarán en CSV

View File

@ -2,9 +2,13 @@ SELECT
ir.id AS code, ir.id AS code,
ir.description AS description, ir.description AS description,
CAST(SUM(IFNULL(i.stems,1) * s.quantity) AS DECIMAL(10,2)) as stems, CAST(SUM(IFNULL(i.stems,1) * s.quantity) AS DECIMAL(10,2)) as stems,
CAST(SUM( weight) AS DECIMAL(10,2)) as netKg, CAST(SUM(IF(sv.physicalWeight, sv.physicalWeight, i.density * sub.cm3delivery/1000000)) AS DECIMAL(10,2)) netKg,
CAST(SUM((s.quantity * s.price * (100 - s.discount) / 100 )) AS DECIMAL(10,2)) AS subtotal CAST(SUM((s.quantity * s.price * (100 - s.discount) / 100 )) AS DECIMAL(10,2)) AS subtotal
FROM vn.sale s FROM vn.sale s
LEFT JOIN (SELECT ic.itemFk, ic.cm3, ic.cm3delivery
FROM vn.itemCost ic
WHERE ic.cm3
GROUP BY ic.itemFk) sub ON s.itemFk = sub.itemFk
LEFT JOIN vn.saleVolume sv ON sv.saleFk = s.id LEFT JOIN vn.saleVolume sv ON sv.saleFk = s.id
LEFT JOIN vn.ticket t ON t.id = s.ticketFk LEFT JOIN vn.ticket t ON t.id = s.ticketFk
LEFT JOIN vn.invoiceOut io ON io.ref = t.refFk LEFT JOIN vn.invoiceOut io ON io.ref = t.refFk