Merge branch 'dev' of https://git.verdnatura.es/salix into dev
This commit is contained in:
commit
67afda853c
|
@ -28,14 +28,15 @@ describe('Client', () => {
|
|||
|
||||
describe('onSubmit()', () => {
|
||||
it('should perform a POST query', () => {
|
||||
let started = new Date();
|
||||
controller.creditClassification = {
|
||||
started: new Date(),
|
||||
started: started,
|
||||
credit: 300,
|
||||
grade: 1
|
||||
};
|
||||
|
||||
let newData = {
|
||||
started: new Date(),
|
||||
started: started,
|
||||
credit: 300,
|
||||
grade: 1,
|
||||
clientFk: 101
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
import ngModule from '../module';
|
||||
|
||||
/**
|
||||
* Returns a formatted date based on input filter.
|
||||
*
|
||||
* @return {String} The string result
|
||||
*/
|
||||
dateTime.$inject = ['$filter'];
|
||||
|
||||
export default function dateTime($filter) {
|
||||
return function(input, format) {
|
||||
return $filter('date')(new Date(input), format);
|
||||
};
|
||||
}
|
||||
ngModule.filter('dateTime', dateTime);
|
|
@ -1,3 +1,4 @@
|
|||
import './phone';
|
||||
import './ucwords';
|
||||
import './dash-if-empty';
|
||||
import './dateTime';
|
|
@ -21,7 +21,7 @@
|
|||
<vn-thead>
|
||||
<vn-tr>
|
||||
<vn-th></vn-th>
|
||||
<vn-th field="id" number>Id</vn-th>
|
||||
<vn-th field="ticketFk" number>Id</vn-th>
|
||||
<vn-th field="salesPersonFk">Salesperson</vn-th>
|
||||
<vn-th field="shipped">Date</vn-th>
|
||||
<vn-th>Hour</vn-th>
|
||||
|
@ -32,24 +32,24 @@
|
|||
<vn-th field="warehouseFk">Warehouse</vn-th>
|
||||
<vn-th field="refFk" number>Invoice</vn-th>
|
||||
<vn-th field="routeFk" number>Route</vn-th>
|
||||
<vn-th number>Total</vn-th>
|
||||
<vn-th field="total" number>Total</vn-th>
|
||||
<vn-th></vn-th>
|
||||
</vn-tr>
|
||||
</vn-thead>
|
||||
<vn-tbody>
|
||||
<vn-tr ng-repeat="ticket in tickets"
|
||||
class="{{::$ctrl.compareDate(ticket.shipped)}} clickable"
|
||||
ui-sref="ticket.card.summary({id: {{::ticket.id}}})">
|
||||
ui-sref="ticket.card.summary({id: {{::ticket.ticketFk}}})">
|
||||
<vn-td>
|
||||
<vn-icon ng-show="ticket.problem" class="bright"
|
||||
vn-tooltip="{{ticket.problem}}"
|
||||
icon="warning">
|
||||
</vn-icon>
|
||||
</vn-td>
|
||||
<vn-td number>{{::ticket.id}}</vn-td>
|
||||
<vn-td number>{{::ticket.ticketFk}}</vn-td>
|
||||
<vn-td>{{::ticket.salesPerson | dashIfEmpty}}</vn-td>
|
||||
<vn-td>{{::ticket.shipped | date:'dd/MM/yyyy'}}</vn-td>
|
||||
<vn-td>{{::ticket.shipped | date:'HH:mm'}}</vn-td>
|
||||
<vn-td>{{::ticket.shipped | dateTime: 'dd/MM/yyyy'}}</vn-td>
|
||||
<vn-td>{{::ticket.shipped | dateTime: 'HH:mm'}}</vn-td>
|
||||
<vn-td>
|
||||
<span
|
||||
class="link"
|
||||
|
|
|
@ -52,7 +52,7 @@ export default class Controller {
|
|||
}
|
||||
}
|
||||
],
|
||||
order: 'shipped DESC'
|
||||
order: 'shipped DESC, ticketFk'
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -90,6 +90,7 @@ export default class Controller {
|
|||
if (comparation < 0)
|
||||
return 'success';
|
||||
}
|
||||
|
||||
showDescriptor(event, clientFk) {
|
||||
this.$.descriptor.clientFk = clientFk;
|
||||
this.$.descriptor.parent = event.target;
|
||||
|
|
|
@ -6,8 +6,10 @@ USE `vn`$$
|
|||
CREATE DEFINER=`root`@`%` PROCEDURE `ticketGetProblems`()
|
||||
BEGIN
|
||||
/*
|
||||
* Necesita la tabla tmp.ticket
|
||||
* Obtiene los problemas de uno o varios tickets
|
||||
*
|
||||
* @table tmp.ticketGetProblems(ticketFk, clientFk, warehouseFk, shipped)
|
||||
* @return tmp.ticketProblems
|
||||
*/
|
||||
DECLARE vWarehouse INT;
|
||||
DECLARE vDate DATE;
|
||||
|
@ -17,7 +19,7 @@ BEGIN
|
|||
|
||||
DECLARE vCursor CURSOR FOR
|
||||
SELECT DISTINCT tt.warehouseFk, date(tt.shipped)
|
||||
FROM tmp.ticket tt
|
||||
FROM tmp.ticketGetProblems tt
|
||||
WHERE DATE(tt.shipped) BETWEEN CURDATE()
|
||||
AND TIMESTAMPADD(DAY, 1.9, CURDATE());
|
||||
|
||||
|
@ -34,7 +36,7 @@ BEGIN
|
|||
-- CONGELADO
|
||||
INSERT INTO tmp.ticketProblems(ticketFk, problem)
|
||||
SELECT DISTINCT tt.ticketFk, 'Freezed'
|
||||
FROM tmp.ticket tt
|
||||
FROM tmp.ticketGetProblems tt
|
||||
JOIN vn.client c ON c.id = tt.clientFk
|
||||
WHERE c.isFreezed;
|
||||
|
||||
|
@ -45,26 +47,26 @@ BEGIN
|
|||
(PRIMARY KEY (ticketFk))
|
||||
ENGINE = MEMORY
|
||||
SELECT tt.ticketFk, c.id
|
||||
FROM tmp.ticket tt
|
||||
FROM tmp.ticketGetProblems tt
|
||||
JOIN vn.client c ON c.id = tt.clientFk
|
||||
WHERE c.isFreezed = 0;
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.client_list;
|
||||
CREATE TEMPORARY TABLE tmp.client_list
|
||||
(PRIMARY KEY (Id_Cliente))
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.clientGetDebt;
|
||||
CREATE TEMPORARY TABLE tmp.clientGetDebt
|
||||
(PRIMARY KEY (clientFk))
|
||||
ENGINE = MEMORY
|
||||
SELECT DISTINCT tt.clientFk AS Id_Cliente
|
||||
FROM tmp.ticket tt;
|
||||
SELECT DISTINCT tt.clientFk
|
||||
FROM tmp.ticketGetProblems tt;
|
||||
|
||||
-- RIESGO
|
||||
CALL vn2008.risk_vs_client_list(CURDATE());
|
||||
CALL clientGetDebt(CURDATE());
|
||||
|
||||
INSERT INTO tmp.ticketProblems(ticketFk, problem)
|
||||
SELECT DISTINCT tt.ticketFk, 'Risk'
|
||||
FROM tmp.ticketListFiltered tt
|
||||
JOIN vn.ticket t ON t.id = tt.ticketFk
|
||||
JOIN vn.agencyMode a ON t.agencyModeFk = a.id
|
||||
JOIN tmp.risk r ON r.Id_Cliente = t.clientFk
|
||||
JOIN tmp.risk r ON r.clientFk = t.clientFk
|
||||
JOIN vn.client c ON c.id = t.clientFk
|
||||
WHERE r.risk > c.credit + 10
|
||||
AND a.deliveryMethodFk != 3; -- para que las recogidas se preparen
|
||||
|
@ -76,7 +78,7 @@ BEGIN
|
|||
-- CODIGO 100
|
||||
INSERT INTO tmp.ticketProblems(ticketFk, problem)
|
||||
SELECT DISTINCT tt.ticketFk, 'Code 100'
|
||||
FROM tmp.ticket tt
|
||||
FROM tmp.ticketGetProblems tt
|
||||
JOIN sale s ON s.ticketFk = tt.ticketFk
|
||||
WHERE s.itemFk = 100;
|
||||
|
||||
|
@ -96,7 +98,7 @@ BEGIN
|
|||
-- El disponible es menor que 0
|
||||
INSERT INTO tmp.ticketProblems(ticketFk, problem)
|
||||
SELECT tt.ticketFk, i.name
|
||||
FROM tmp.ticket tt
|
||||
FROM tmp.ticketGetProblems tt
|
||||
JOIN vn.ticket t ON t.id = tt.ticketFk
|
||||
LEFT JOIN vn.sale s ON s.ticketFk = t.id
|
||||
JOIN vn.item i ON i.id = s.itemFk
|
||||
|
@ -120,7 +122,7 @@ BEGIN
|
|||
-- Amarillo: El disponible es mayor que cero y la cantidad supera el visible, estando aun sin preparar
|
||||
INSERT INTO tmp.ticketProblems(ticketFk, problem)
|
||||
SELECT tt.ticketFk, CONCAT('Delay', i.name)
|
||||
FROM tmp.ticket tt
|
||||
FROM tmp.ticketGetProblems tt
|
||||
JOIN vn.ticket t ON t.id = tt.ticketFk
|
||||
LEFT JOIN vn.sale s ON s.ticketFk = t.id
|
||||
JOIN vn.item i ON i.id = s.itemFk
|
||||
|
@ -140,7 +142,9 @@ BEGIN
|
|||
|
||||
CLOSE vCursor;
|
||||
|
||||
DROP TEMPORARY TABLE tmp.ticketListFiltered;
|
||||
DROP TEMPORARY TABLE
|
||||
tmp.clientGetDebt,
|
||||
tmp.ticketListFiltered;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
|
|
@ -1,32 +0,0 @@
|
|||
USE `vn`;
|
||||
DROP procedure IF EXISTS `ticketFilter`;
|
||||
|
||||
DELIMITER $$
|
||||
USE `vn`$$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `ticketFilter`()
|
||||
BEGIN
|
||||
/**
|
||||
* Obtiene un listado de tickets
|
||||
* junto con el precio total y los problemas
|
||||
*
|
||||
* @table tmp.ticket(ticketFk) Identificadores de los tickets a calcular
|
||||
* @return Listado de tickets
|
||||
*/
|
||||
CALL ticketGetTotal();
|
||||
CALL ticketGetProblems();
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.ticketFilter;
|
||||
CREATE TEMPORARY TABLE tmp.ticketFilter ENGINE = MEMORY
|
||||
SELECT t.*, tt.total, tp.problem
|
||||
FROM tmp.ticket t
|
||||
JOIN tmp.ticketTotal tt ON tt.ticketFk = t.ticketFk
|
||||
LEFT JOIN tmp.ticketProblems tp ON tp.ticketFk = t.ticketFk;
|
||||
|
||||
DROP TEMPORARY TABLE
|
||||
tmp.ticket,
|
||||
tmp.ticketTotal,
|
||||
tmp.ticketProblems;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
DROP procedure IF EXISTS vn.`clientGetDebt`;
|
||||
|
||||
DELIMITER $$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE vn.`clientGetDebt`(vDate DATE)
|
||||
BEGIN
|
||||
/**
|
||||
* Calcula el riesgo para los clientes activos
|
||||
*
|
||||
* @table tmp.clientGetDebt(clientFk)
|
||||
* @param vDate Fecha maxima de los registros
|
||||
* @return tmp.risk
|
||||
*/
|
||||
DECLARE vStarted DATETIME DEFAULT TIMESTAMPADD(DAY, - DAYOFMONTH(CURDATE()) - 5, CURDATE());
|
||||
DECLARE vEnded DATETIME;
|
||||
|
||||
SET vEnded = TIMESTAMP(IFNULL(vDate, CURDATE()), '23:59:59');
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.ticket;
|
||||
CREATE TEMPORARY TABLE tmp.ticket
|
||||
(INDEX (ticketFk))
|
||||
ENGINE = MEMORY
|
||||
SELECT id ticketFk, c.clientFk
|
||||
FROM ticket t
|
||||
JOIN tmp.clientGetDebt c ON c.clientFk = t.clientFk
|
||||
WHERE refFk IS NULL
|
||||
AND shipped BETWEEN vStarted AND vEnded;
|
||||
|
||||
CALL ticketGetTotal();
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tClientRisk;
|
||||
CREATE TEMPORARY TABLE tClientRisk
|
||||
ENGINE = MEMORY
|
||||
SELECT cr.customer_id clientFk, SUM(cr.amount) amount
|
||||
FROM bi.customer_risk cr
|
||||
JOIN tmp.clientGetDebt c ON c.clientFk = cr.customer_id
|
||||
GROUP BY cr.customer_id;
|
||||
|
||||
INSERT INTO tClientRisk
|
||||
SELECT c.clientFk, SUM(r.amountPaid)
|
||||
FROM receipt r
|
||||
JOIN tmp.clientGetDebt c ON c.clientFk = r.clientFk
|
||||
WHERE r.payed > vStarted
|
||||
GROUP BY c.clientFk;
|
||||
|
||||
INSERT INTO tClientRisk
|
||||
SELECT t.clientFk, CAST(-SUM(t.amount) / 100 AS DECIMAL(10,2))
|
||||
FROM hedera.tpvTransaction t
|
||||
JOIN tmp.clientGetDebt c ON c.clientFk = t.clientFk
|
||||
WHERE t.receiptFk IS NULL
|
||||
AND t.status = 'ok'
|
||||
GROUP BY t.clientFk;
|
||||
|
||||
INSERT INTO tClientRisk
|
||||
SELECT t.clientFk, total
|
||||
FROM tmp.ticketTotal tt
|
||||
JOIN tmp.ticket t ON t.ticketFk = tt.ticketFk;
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.risk;
|
||||
CREATE TEMPORARY TABLE tmp.risk
|
||||
(PRIMARY KEY (clientFk))
|
||||
ENGINE = MEMORY
|
||||
SELECT clientFk, SUM(amount) risk
|
||||
FROM client c
|
||||
JOIN tClientRisk cr ON cr.clientFk = c.id
|
||||
WHERE c.isActive
|
||||
GROUP BY c.id;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
|
@ -20,14 +20,14 @@ describe('item clone()', () => {
|
|||
});
|
||||
|
||||
it('should attempt to clone the given item but give an error as it doesnt exist', async() => {
|
||||
let result;
|
||||
try {
|
||||
let itemFk = 999;
|
||||
result = await app.models.Item.clone(itemFk);
|
||||
} catch (error) {
|
||||
expect(error.toString()).toContain('Cannot convert undefined or null to object');
|
||||
}
|
||||
let error;
|
||||
let itemFk = 999;
|
||||
await app.models.Item.clone(itemFk)
|
||||
.catch(e => {
|
||||
expect(e.message).toContain('Cannot convert undefined or null to object');
|
||||
error = e;
|
||||
});
|
||||
|
||||
expect(result).toBeFalsy();
|
||||
expect(error).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
const app = require(`${servicesDir}/item/server/server`);
|
||||
|
||||
describe('item updateTaxes()', () => {
|
||||
afterAll(async() => {
|
||||
let taxesInFixtures = [{id: 509368, taxClassFk: 1}];
|
||||
|
||||
await app.models.Item.updateTaxes(taxesInFixtures);
|
||||
});
|
||||
|
||||
it('should throw an error if the taxClassFk is blank', async() => {
|
||||
let error;
|
||||
let taxes = [{id: 509368, taxClassFk: undefined}];
|
||||
|
||||
await app.models.Item.updateTaxes(taxes)
|
||||
.catch(err => {
|
||||
expect(err.message).toEqual('Tax class cannot be blank');
|
||||
error = err;
|
||||
});
|
||||
|
||||
expect(error).toBeDefined();
|
||||
});
|
||||
|
||||
it('should update the tax of a given country of an item', async() => {
|
||||
let taxCountry = await app.models.ItemTaxCountry.findById(509368);
|
||||
|
||||
expect(taxCountry.taxClassFk).toEqual(1);
|
||||
|
||||
let taxes = [{id: 509368, taxClassFk: 2}];
|
||||
|
||||
let result = await app.models.Item.updateTaxes(taxes);
|
||||
|
||||
expect(result).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should confirm the tax class was updated', async() => {
|
||||
let taxCountry = await app.models.ItemTaxCountry.findById(509368);
|
||||
|
||||
expect(taxCountry.taxClassFk).toEqual(2);
|
||||
});
|
||||
});
|
|
@ -11,7 +11,7 @@ module.exports = Self => {
|
|||
description: 'The item id',
|
||||
http: {source: 'path'}
|
||||
}, {
|
||||
arg: 'niches',
|
||||
arg: 'taxes',
|
||||
type: ['object'],
|
||||
required: true,
|
||||
description: 'The list of taxes to update',
|
||||
|
@ -27,7 +27,7 @@ module.exports = Self => {
|
|||
}
|
||||
});
|
||||
|
||||
Self.updateTaxes = async(id, taxes) => {
|
||||
Self.updateTaxes = async taxes => {
|
||||
let promises = [];
|
||||
for (let tax of taxes) {
|
||||
if (!tax.taxClassFk)
|
||||
|
|
|
@ -27,13 +27,12 @@ module.exports = Self => {
|
|||
let stmts = [];
|
||||
let stmt;
|
||||
|
||||
stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.ticket');
|
||||
stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.filter');
|
||||
|
||||
stmt = new ParameterizedSQL(
|
||||
`CREATE TEMPORARY TABLE tmp.ticket
|
||||
`CREATE TEMPORARY TABLE tmp.filter
|
||||
(PRIMARY KEY (ticketFk)) ENGINE = MEMORY
|
||||
SELECT
|
||||
t.id,
|
||||
SELECT
|
||||
t.id AS ticketFk,
|
||||
t.shipped,
|
||||
t.nickname,
|
||||
|
@ -49,7 +48,8 @@ module.exports = Self => {
|
|||
w.name AS warehouse,
|
||||
am.name AS agencyMode,
|
||||
st.name AS state,
|
||||
wk.name AS salesPerson
|
||||
wk.name AS salesPerson,
|
||||
0 AS total
|
||||
FROM ticket t
|
||||
LEFT JOIN address a ON a.id = t.addressFk
|
||||
LEFT JOIN province p ON p.id = a.provinceFk
|
||||
|
@ -62,17 +62,45 @@ module.exports = Self => {
|
|||
stmt.merge(Self.buildSuffix(filter, 't'));
|
||||
stmts.push(stmt);
|
||||
|
||||
stmts.push('CALL ticketFilter()');
|
||||
stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.ticket');
|
||||
stmts.push(`
|
||||
CREATE TEMPORARY TABLE tmp.ticket
|
||||
(PRIMARY KEY (ticketFk)) ENGINE = MEMORY
|
||||
SELECT ticketFk FROM tmp.filter`);
|
||||
stmts.push('CALL ticketGetTotal()');
|
||||
|
||||
stmt = new ParameterizedSQL(
|
||||
`SELECT * FROM tmp.ticketFilter tfl`
|
||||
);
|
||||
stmt.merge(Self.buildSuffix(filter, 'tfl'));
|
||||
let rsIndex = stmts.push(stmt) - 1;
|
||||
stmts.push(`
|
||||
UPDATE tmp.filter f
|
||||
JOIN tmp.ticketTotal tt ON f.ticketFk = tt.ticketFk
|
||||
SET f.total = tt.total`);
|
||||
|
||||
stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.ticketGetProblems');
|
||||
stmts.push(`
|
||||
CREATE TEMPORARY TABLE tmp.ticketGetProblems
|
||||
(PRIMARY KEY (ticketFk)) ENGINE = MEMORY
|
||||
SELECT ticketFk, clientFk, warehouseFk, shipped
|
||||
FROM tmp.filter`);
|
||||
stmts.push('CALL ticketGetProblems()');
|
||||
|
||||
stmt = new ParameterizedSQL(`
|
||||
SELECT
|
||||
f.*,
|
||||
tp.problem
|
||||
FROM tmp.filter f
|
||||
LEFT JOIN tmp.ticketProblems tp ON tp.ticketFk = f.ticketFk`);
|
||||
stmt.merge(Self.buildSuffix(filter, 'f'));
|
||||
let ticketsIndex = stmts.push(stmt) - 1;
|
||||
|
||||
stmts.push(
|
||||
`DROP TEMPORARY TABLE
|
||||
tmp.filter,
|
||||
tmp.ticket,
|
||||
tmp.ticketTotal,
|
||||
tmp.ticketGetProblems`);
|
||||
|
||||
let sql = ParameterizedSQL.join(stmts, ';');
|
||||
let tickets = await Self.rawStmt(sql);
|
||||
let result = await Self.rawStmt(sql);
|
||||
|
||||
return tickets[rsIndex];
|
||||
return result[ticketsIndex];
|
||||
};
|
||||
};
|
||||
|
|
|
@ -4,7 +4,7 @@ describe('ticket filter()', () => {
|
|||
it('should call the filter method', async() => {
|
||||
let filter = {order: 'shipped DESC'};
|
||||
let result = await app.models.Ticket.filter(filter);
|
||||
let ticketId = result[0].id;
|
||||
let ticketId = result[0].ticketFk;
|
||||
|
||||
expect(ticketId).toEqual(15);
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue