This commit is contained in:
Juan 2018-05-31 11:56:52 +02:00
commit 3c9d8f32bb
27 changed files with 378 additions and 62 deletions

View File

@ -34,7 +34,7 @@
</vn-horizontal>
</vn-vertical>
<a vn-auto ui-sref="client.card.creditInsurance.insurance.index({classificationId: {{classification.id}}})">
<vn-icon-button icon="desktop_windows" vn-tooltip="List classifications"></vn-icon-button>
<vn-icon-button icon="desktop_windows" vn-tooltip="View credits"></vn-icon-button>
</a>
</vn-horizontal>
</vn-one>

View File

@ -2,5 +2,6 @@ Contract credit insurance: Contratos de seguro de crédito
New contract: Nuevo contrato
Close contract: Cerrar contrato
Edit contract: Modificar contrato
List classifications: Ver clasificaciones
Are you sure you want to close this contract?: ¿Seguro que quieres cerrar este contrato?
View credits: Ver créditos
Are you sure you want to close this contract?: ¿Seguro que quieres cerrar este contrato?
Grade: Grado

View File

@ -8,7 +8,7 @@
<form name="form"
ng-submit="watcher.submitGo('client.card.creditInsurance.insurance.index', {classificationId: post.params.classificationId})">
<vn-card pad-large>
<vn-title>New classification</vn-title>
<vn-title>New credit</vn-title>
<vn-horizontal>
<vn-textfield
vn-one
@ -37,5 +37,9 @@
</vn-card>
<vn-button-bar>
<vn-submit label="Save"></vn-submit>
<button
class="mdl-button mdl-button--raised mdl-button--colored"
translate
ui-sref="client.card.creditInsurance.insurance.index({classificationId: post.params.classificationId})">Cancel</button>
</vn-button-bar>
</form>

View File

@ -1,15 +1,14 @@
import ngModule from '../../../module';
class Controller {
constructor($state, $filter) {
constructor($filter) {
this.insurance = {
created: $filter('date')(new Date(), 'yyyy-MM-dd HH:mm')
};
this.classificationId = $state.params.classificationId;
}
}
Controller.$inject = ['$state', '$filter'];
Controller.$inject = ['$filter'];
ngModule.component('vnClientCreditInsuranceInsuranceCreate', {
template: require('./index.html'),

View File

@ -1 +1 @@
New classification: Nueva clasificación
New credit: Nuevo crédito

View File

@ -1,31 +1,38 @@
<mg-ajax path="/client/api/CreditInsurances/filter" options="vnIndexNonAuto"></mg-ajax>
<mg-ajax path="/client/api/CreditClassifications/{{index.params.classificationId}}/creditInsurances" options="vnIndex"></mg-ajax>
<vn-vertical>
<vn-card pad-large>
<vn-vertical>
<vn-title>Requested credits</vn-title>
<vn-grid-header on-order="$ctrl.onOrder(field, order)">
<vn-column-header vn-one pad-medium-h field="credit" text="Credit"></vn-column-header>
<vn-column-header vn-one pad-medium-h field="grade" text="Grade"></vn-column-header>
<vn-column-header vn-two pad-medium-h field="created" text="Created" default-order="DESC"></vn-column-header>
</vn-grid-header>
<vn-one class="list list-content">
<vn-horizontal
vn-one class="list list-element text-center"
pad-small-bottom
ng-repeat="insurance in index.model.instances track by insurance.id">
<vn-one pad-medium-h>{{::insurance.credit}}</vn-one>
<vn-one pad-medium-h>{{::insurance.grade}}</vn-one>
<vn-two pad-medium-h>{{::insurance.created | date: 'dd/MM/yyyy'}}</vn-two>
</vn-horizontal>
</vn-one>
<vn-one class="text-center pad-small-v" ng-if="index.model.count === 0" translate>No results</vn-one>
<vn-horizontal vn-one class="list list-footer"></vn-horizontal>
<table class="vn-grid">
<thead>
<tr>
<th number translate>Credit</th>
<th number translate>Grade</th>
<th translate>Created</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="insurance in index.model track by insurance.id" class="list list-element">
<td number>{{::insurance.credit | currency: '€': 2}}</td>
<td number>{{::insurance.grade}}</td>
<td>{{::insurance.created | date: 'dd/MM/yyyy'}}</td>
</tr>
<tr ng-if="index.model.count === 0" class="list list-element">
<td colspan="6" style="text-align: center" translate>No results</td>
</tr>
</tbody>
</table>
</vn-vertical>
</vn-card>
<vn-button-bar>
<button
class="mdl-button mdl-button--raised mdl-button--colored"
translate
ui-sref="client.card.creditInsurance.index">Back</button>
</vn-button-bar>
<vn-paging vn-one margin-large-top index="index" total="index.model.count"></vn-paging>
<!-- <vn-auto-paging vn-one margin-large-top index="index" total="index.model.count" items="$ctrl.instances"></vn-auto-paging> -->
</vn-vertical>
<a ui-sref="client.card.creditInsurance.insurance.create({classificationId: {{index.params.classificationId}}})"
fixed-bottom-right vn-tooltip="New classification" vn-bind="+" ng-if="!$ctrl.isClosed">
fixed-bottom-right vn-tooltip="New credit" vn-bind="+" ng-if="!$ctrl.isClosed">
<vn-float-button icon="add"></vn-float-button>
</a>

View File

@ -21,3 +21,4 @@ Credit contracts: Contratos de crédito
Verified data: Datos comprobados
Mandate: Mandato
Amount: Importe
Back: Volver

View File

@ -1 +1 @@
<div ng-transclude></div>
<div></div>

View File

@ -7,8 +7,12 @@ export default function directive(vnTemplate) {
restrict: 'E',
transclude: true,
template: require('./card.html'),
link: function(_, $element) {
link: function($scope, $element, $attrs, $ctrl, $transclude) {
$element.addClass('demo-card-wide mdl-shadow--2dp bg-panel');
$transclude($scope, function(clone) {
angular.element($element[0].querySelector('div')).append(clone);
});
}
};
}

View File

@ -9,18 +9,18 @@ import './style.scss';
* @property {HTMLElement} buttons The dialog HTML buttons
*/
export default class Dialog extends Component {
constructor($element, $transclude) {
super($element);
constructor($element, $scope, $transclude) {
super($element, $scope);
this.shown = false;
this.$element.addClass('vn-dialog');
this.element.addEventListener('mousedown',
e => this.onBackgroundMouseDown(e));
if ($transclude) {
$transclude(tClone => {
$transclude($scope.$parent, tClone => {
this.body = tClone[0];
}, null, 'body');
$transclude(tClone => {
$transclude($scope.$parent, tClone => {
this.buttons = tClone[0];
}, null, 'buttons');
}
@ -104,7 +104,7 @@ export default class Dialog extends Component {
clearTimeout(this.transitionTimeout);
}
}
Dialog.$inject = ['$element', '$transclude'];
Dialog.$inject = ['$element', '$scope', '$transclude'];
ngModule.component('vnDialog', {
template: require('./dialog.html'),

View File

@ -33,7 +33,8 @@ class Controller {
let data = {
landed: toJsonDate(this.ticket.landed),
addressFk: this.ticket.addressFk,
agencyModeFk: this.ticket.agencyModeFk
agencyModeFk: this.ticket.agencyModeFk,
warehouseFk: this.ticket.warehouseFk
};
return this.$http.post(query, data).then(res => {

View File

@ -26,6 +26,7 @@ describe('ticket', () => {
addressFk: 121,
agencyModeFk: 1,
companyFk: 442,
warehouseFk: 1,
shipped: new Date(),
landed: new Date()
};
@ -46,6 +47,7 @@ describe('ticket', () => {
addressFk: 121,
agencyModeFk: 1,
companyFk: 442,
warehouseFk: 1,
shipped: new Date(),
landed: landed
};

View File

@ -11,5 +11,12 @@
initial-data="$ctrl.ticket.option">
</vn-autocomplete>
</vn-horizontal>
<vn-horizontal>
<vn-check
vn-one label="Remove from route"
field="$ctrl.ticket.hasToBeUnrouted"
vn-acl="delivery">
</vn-check>
</vn-horizontal>
</vn-card>
</form>

View File

@ -15,6 +15,7 @@ class Controller {
$onChanges() {
this.ticket.option = 1;
this.ticket.hasToBeUnrouted = true;
}
onStepChange(state) {
@ -29,12 +30,14 @@ class Controller {
let query = `/ticket/api/tickets/${this.ticket.id}/componentUpdate`;
let data = {
clientFk: this.ticket.clientFk,
agencyModeFk: this.ticket.agencyModeFk,
addressFk: this.ticket.addressFk,
warehouseFk: this.ticket.warehouseFk,
shipped: this.ticket.shipped,
landed: this.ticket.landed,
isDeleted: this.ticket.isDeleted,
hasToBeUnrouted: this.ticket.hasToBeUnrouted,
option: this.ticket.option
};

View File

@ -1,3 +1,4 @@
Charge: Cargo
Choose an option: Selecciona una opción
Charge difference to: Diferencia a cargo de
Charge difference to: Diferencia a cargo de
Remove from route: Sacar de la ruta

View File

@ -1,14 +0,0 @@
module.exports = Self => {
Self.installMethod('filter', filterParams);
function filterParams(params) {
return {
where: {
creditClassification: params.creditClassificationFk
},
skip: (params.page - 1) * params.size,
limit: params.size,
order: params.order
};
}
};

View File

@ -1,6 +1,4 @@
module.exports = function(Self) {
require('../methods/credit-insurance/filter')(Self);
Self.validateCredit = function(credit) {
return credit >= 0;
};
@ -20,6 +18,26 @@ module.exports = function(Self) {
allowNull: true
});
async function validateNullGrade(err, done) {
let filter = {
fields: ['grade'],
where: {
creditClassification: this.creditClassification
},
order: 'created DESC'
};
let insurance = await Self.findOne(filter);
if (insurance && (!insurance.grade && this.grade || insurance.grade && ! this.grade))
err();
done();
}
Self.validateAsync('nullGrade', validateNullGrade, {
message: 'The grade must be similar to the last one'
});
Self.messageSend = async function(data, accessToken) {
let filter = {
include: {

View File

@ -0,0 +1,54 @@
USE `vn`;
DROP procedure IF EXISTS `ticketComponentMakeUpdate`;
DELIMITER $$
USE `vn`$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketComponentMakeUpdate`(
vTicketFk INT,
vClientFk INT,
vAgencyModeFk INT,
vAddressFk INT,
vWarehouseFk INT,
vShipped DATETIME,
vLanded DATE,
vIsDeleted BOOLEAN,
vHasToBeUnrouted BOOLEAN,
vOption INT)
BEGIN
/**
* Calcula los componentes de un ticket
* y los actualiza con los nuevos datos.
*
* @param vTicketFk Id del ticket
* @param vClientFk Id del cliente
* @param vAgencyModeFk Id del tipo de agencia
* @param vAddressFk Id del consignatario
* @param vWarehouseFk Id del almacén
* @param vShipped Fecha de salida
* @param vLanded Fecha de llegada
* @param vIsDeleted Marcado como eliminado
* @param vHasToBeUnrouted Marcado para sacar de ruta
* @param vOption Id de la acción ticketUpdateAction
*/
CALL vn.ticketComponentPreview (vTicketFk, vLanded, vAddressFk, vAgencyModeFk, vWarehouseFk);
CALL vn.ticketComponentUpdate (
vTicketFk,
vClientFk,
vAgencyModeFk,
vAddressFk,
vWarehouseFk,
vShipped,
vLanded,
vIsDeleted,
vHasToBeUnrouted,
vOption
);
DROP TEMPORARY TABLE
tmp.ticketComponent,
tmp.ticketComponentPrice;
END$$
DELIMITER ;

View File

@ -0,0 +1,74 @@
USE `vn`;
DROP procedure IF EXISTS `ticketComponentPreview`;
DELIMITER $$
USE `vn`$$
CREATE DEFINER=`root`@`%` PROCEDURE `ticketComponentPreview`(
vTicketFk INT,
vDate DATE,
vAddressFk INT,
vAgencyModeFk INT,
vWarehouseFk SMALLINT)
BEGIN
/**
* Devuelve un listado previo de
* componentes para un ticket
*
* @param vTicketFk Id del ticket
* @param vDate Fecha de envío
* @param vAddressFk Id del consignatario
* @param vAgencyModeFk Id del modo de agencia
* @param vWarehouseFk Id del almacén
*/
DECLARE vAgencyFk INT;
DECLARE vShipped DATE;
DECLARE vBuyOrderItem INT DEFAULT 100;
SELECT agencyFk INTO vAgencyFk
FROM agencyMode
WHERE id = vAgencyModeFk;
CALL agencyHourOffer(vDate, vAddressFk, vAgencyFk);
SELECT shipped INTO vShipped
FROM tmp.agencyHourOffer
WHERE warehouseFk = vWarehouseFK;
CALL buyUltimate(vWarehouseFK, vShipped);
DROP TEMPORARY TABLE IF EXISTS tmp.ticketLot;
CREATE TEMPORARY TABLE tmp.ticketLot ENGINE = MEMORY (
SELECT
vWarehouseFK AS warehouseFk,
NULL AS available,
s.itemFk,
bu.buyFk
FROM sale s
LEFT JOIN tmp.buyUltimate bu ON bu.itemFk = s.itemFk
WHERE s.ticketFk = vTicketFk
AND s.itemFk != vBuyOrderItem
GROUP BY bu.warehouseFk, bu.itemFk);
CALL ticketComponentCalculate(vAddressFk, vAgencyModeFk);
REPLACE INTO tmp.ticketComponent (warehouseFk, itemFk, componentFk, cost)
SELECT t.warehouseFk, s.itemFk, sc.componentFk, sc.value
FROM saleComponent sc
JOIN sale s ON s.id = sc.saleFk
JOIN ticket t ON t.id = s.ticketFk
JOIN componentRate cr ON cr.id = sc.componentFk
WHERE s.ticketFk = vTicketFk AND NOT cr.isRenewable;
SET @shipped = vShipped;
DROP TEMPORARY TABLE
tmp.agencyHourOffer,
tmp.buyUltimate,
tmp.ticketLot;
IF IFNULL(vShipped, CURDATE() - 1) < CURDATE() THEN
CALL util.throw('NO_AGENCY_AVAILABLE');
END IF;
END$$
DELIMITER ;

View File

@ -0,0 +1,55 @@
USE `vn`;
DROP procedure IF EXISTS `ticketComponentPriceDifference`;
DELIMITER $$
USE `vn`$$
CREATE DEFINER=`root`@`%` PROCEDURE `ticketComponentPriceDifference`(
vTicketFk INT,
vDate DATE,
vAddressFk INT,
vAgencyModeFk INT,
vWarehouseFk INT)
BEGIN
/**
* Devuelve las diferencias de precio
* de los movimientos de un ticket.
*
* @param vTicketFk Id del ticket
* @param vDate Fecha de envío
* @param vAddressFk Id del consignatario
* @param vAgencyModeFk Id del modo de agencia
* @param vWarehouseFk Id del almacén
*/
CALL vn.ticketComponentPreview(vTicketFk, vDate, vAddressFk, vAgencyModeFk, vWarehouseFk);
SELECT
s.itemFk,
i.name,
i.size,
i.category,
IFNULL(s.quantity, 0) AS quantity,
IFNULL(s.price, 0) AS price,
ROUND(SUM(tc.cost), 4) AS newPrice,
s.quantity * (s.price - ROUND(SUM(cost), 4)) difference,
s.id AS saleFk
FROM sale s
JOIN item i ON i.id = s.itemFk
JOIN ticket t ON t.id = s.ticketFk
LEFT JOIN tmp.ticketComponent tc ON tc.itemFk = s.itemFk
AND tc.warehouseFk = t.warehouseFk
LEFT JOIN saleComponent sc ON sc.saleFk = s.id
AND sc.componentFk = tc.componentFk
LEFT JOIN componentRate cr ON cr.id = tc.componentFk
WHERE
t.id = vTicketFk
AND IF(sc.componentFk IS NULL
AND cr.classRate IS NOT NULL, FALSE, TRUE)
GROUP BY s.id ORDER BY s.id;
DROP TEMPORARY TABLE
tmp.ticketComponent,
tmp.ticketComponentPrice;
END$$
DELIMITER ;

View File

@ -0,0 +1,74 @@
USE `vn`;
DROP procedure IF EXISTS `ticketComponentUpdate`;
DELIMITER $$
USE `vn`$$
CREATE DEFINER=`root`@`%` PROCEDURE `ticketComponentUpdate`(
vTicketFk INT,
vClientFk INT,
vAgencyModeFk INT,
vAddressFk INT,
vWarehouseFk INT,
vShipped DATETIME,
vLanded DATE,
vIsDeleted BOOLEAN,
vHasToBeUnrouted BOOLEAN,
vOption INT)
BEGIN
/**
* Actualiza un ticket y sus componentes
* con los nuevos datos.
*
* @param vTicketFk Id del ticket
* @param vClientFk Id del cliente
* @param vAgencyModeFk Id del tipo de agencia
* @param vAddressFk Id del consignatario
* @param vWarehouseFk Id del almacén
* @param vShipped Fecha de salida
* @param vLanded Fecha de llegada
* @param vIsDeleted Marcado como eliminado
* @param vHasToBeUnrouted Marcado para sacar de ruta
* @param vOption Id de la acción ticketUpdateAction
*/
DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN
ROLLBACK;
RESIGNAL;
END;
START TRANSACTION;
UPDATE ticket t
SET
t.clientFk = vClientFk,
t.agencyModeFk = vAgencyModeFk,
t.addressFk = vAddressFk,
t.warehouseFk = vWarehouseFk,
t.landed = vLanded,
t.shipped = vShipped,
t.isDeleted = vIsDeleted
WHERE
t.id = vTicketFk;
IF vHasToBeUnrouted THEN
UPDATE ticket t SET t.routeFk = NULL
WHERE t.id = vTicketFk;
END IF;
IF vOption <> 8 THEN
DROP TEMPORARY TABLE IF EXISTS tmp.sale;
CREATE TEMPORARY TABLE tmp.sale
(PRIMARY KEY (saleFk))
ENGINE = MEMORY
SELECT id AS saleFk, vWarehouseFk warehouseFk
FROM sale s WHERE s.ticketFk = vTicketFk;
CALL ticketComponentUpdateSale (vOption);
DROP TEMPORARY TABLE tmp.sale;
END IF;
COMMIT;
END$$
DELIMITER ;

View File

@ -20,5 +20,7 @@
"Cannot change the payment method if no salesperson": "No se puede cambiar la forma de pago si no hay comercial asignado",
"can't be blank": "El campo no puede estar vacío",
"Observation type cannot be blank": "El tipo de observación no puede estar en blanco",
"Observation type must be unique": "El tipo de observación no puede repetirse"
"Observation type must be unique": "El tipo de observación no puede repetirse",
"The credit must be an integer greater than or equal to zero": "The credit must be an integer greater than or equal to zero",
"The grade must be similar to the last one": "El grado debe ser similar al último crédito"
}

View File

@ -57,8 +57,14 @@ module.exports = Self => {
salesObj.totalNewPrice = 0.00;
salesObj.totalDifference = 0.00;
let query = `CALL vn.ticketComponentPriceDifference(?, ?, ?, ?)`;
let [differences] = await Self.rawSql(query, [data.landed, data.addressFk, data.agencyModeFk, ticketFk]);
let query = `CALL vn.ticketComponentPriceDifference(?, ?, ?, ?, ?)`;
let [differences] = await Self.rawSql(query, [
ticketFk,
data.landed,
data.addressFk,
data.agencyModeFk,
data.warehouseFk
]);
salesObj.items.forEach(sale => {
differences.forEach(difference => {

View File

@ -5,7 +5,8 @@ describe('sale priceDifference()', () => {
let data = {
landed: Date.now(),
addressFk: 121,
agencyModeFk: 1
agencyModeFk: 1,
warehouseFk: 1
};
app.models.Sale.priceDifference(1, data)
.catch(response => {

View File

@ -12,8 +12,14 @@ module.exports = Self => {
arg: 'data',
type: 'Object',
required: true,
description: 'landed, addressFk, agencyModeFk',
description: 'landed, addressFk, agencyModeFk, warehouseFk',
http: {source: 'body'}
}, {
arg: 'context',
type: 'object',
http: function(ctx) {
return ctx;
}
}],
returns: {
type: ['Object'],
@ -25,16 +31,24 @@ module.exports = Self => {
}
});
Self.componentUpdate = async(ticketFk, data) => {
let query = 'CALL vn.ticketComponentMakeUpdate(?, ?, ?, ?, ?, ?, ?, ?)';
Self.componentUpdate = async(ticketFk, data, ctx) => {
let userId = ctx.req.accessToken.userId;
let hasDeliveryRole = await Self.app.models.Account.hasRole(userId, 'delivery');
if (!hasDeliveryRole)
data.hasToBeUnrouted = true;
let query = 'CALL vn.ticketComponentMakeUpdate(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
let res = await Self.rawSql(query, [
ticketFk,
data.clientFk,
data.agencyModeFk,
data.addressFk,
data.warehouseFk,
data.shipped,
data.landed,
data.isDeleted,
data.hasToBeUnrouted,
data.option
]);
return res;

View File

@ -8,9 +8,11 @@ describe('ticket componentUpdate()', () => {
warehouseFk: 1,
shipped: Date.now(),
landed: Date.now(),
hasToBeUnrouted: true,
option: 1
};
app.models.Ticket.componentUpdate(1, data)
let ctx = {req: {accessToken: {userId: 101}}};
app.models.Ticket.componentUpdate(1, data, ctx)
.catch(response => {
expect(response).toEqual(new Error('ER_SIGNAL_EXCEPTION: NO_AGENCY_AVAILABLE'));
done();

View File

@ -75,7 +75,7 @@ function vnBoot(app, rootDir, rootModule) {
let packageJson = require(`${rootDir}/../package.json`);
let appName = packageJson.name;
let baseUrl = app.get('url').replace(/\/$/, '');
console.log(`Web server ${appName} listening at: %s`, baseUrl);
console.log(`Web server ${appName} listening at: %s`, `${baseUrl}/explorer`);
}
let args = port ? [port, onListen] : [onListen];