Merge branch 'dev' into 3439-item_search-panel
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
commit
a1da6081b5
|
@ -0,0 +1,2 @@
|
|||
INSERT INTO salix.ACL (model,property,accessType,permission,principalType,principalId)
|
||||
VALUES ('Sale','payBack','WRITE','ALLOW','ROLE','employee');
|
|
@ -0,0 +1,90 @@
|
|||
DROP PROCEDURE IF EXISTS `vn`.`ticket_doRefund`;
|
||||
|
||||
DELIMITER $$
|
||||
$$
|
||||
CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_doRefund`(IN vOriginTicket INT, OUT vNewTicket INT)
|
||||
BEGIN
|
||||
|
||||
DECLARE vDone BIT DEFAULT 0;
|
||||
DECLARE vCustomer MEDIUMINT;
|
||||
DECLARE vWarehouse TINYINT;
|
||||
DECLARE vCompany MEDIUMINT;
|
||||
DECLARE vAddress MEDIUMINT;
|
||||
DECLARE vRefundAgencyMode INT;
|
||||
DECLARE vItemFk INT;
|
||||
DECLARE vQuantity DECIMAL (10,2);
|
||||
DECLARE vConcept VARCHAR(50);
|
||||
DECLARE vPrice DECIMAL (10,2);
|
||||
DECLARE vDiscount TINYINT;
|
||||
DECLARE vSaleNew INT;
|
||||
DECLARE vSaleMain INT;
|
||||
DECLARE vZoneFk INT;
|
||||
|
||||
DECLARE vRsMainTicket CURSOR FOR
|
||||
SELECT *
|
||||
FROM tmp.sale;
|
||||
|
||||
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = 1;
|
||||
|
||||
SELECT id INTO vRefundAgencyMode
|
||||
FROM agencyMode WHERE `name` = 'ABONO';
|
||||
|
||||
SELECT clientFk, warehouseFk, companyFk, addressFk
|
||||
INTO vCustomer, vWarehouse, vCompany, vAddress
|
||||
FROM ticket
|
||||
WHERE id = vOriginTicket;
|
||||
|
||||
SELECT id INTO vZoneFk
|
||||
FROM zone WHERE agencyModeFk = vRefundAgencyMode
|
||||
LIMIT 1;
|
||||
|
||||
INSERT INTO vn.ticket (
|
||||
clientFk,
|
||||
shipped,
|
||||
addressFk,
|
||||
agencyModeFk,
|
||||
nickname,
|
||||
warehouseFk,
|
||||
companyFk,
|
||||
landed,
|
||||
zoneFk
|
||||
)
|
||||
SELECT
|
||||
vCustomer,
|
||||
CURDATE(),
|
||||
vAddress,
|
||||
vRefundAgencyMode,
|
||||
a.nickname,
|
||||
vWarehouse,
|
||||
vCompany,
|
||||
CURDATE(),
|
||||
vZoneFk
|
||||
FROM address a
|
||||
WHERE a.id = vAddress;
|
||||
|
||||
SET vNewTicket = LAST_INSERT_ID();
|
||||
|
||||
SET vDone := 0;
|
||||
OPEN vRsMainTicket ;
|
||||
FETCH vRsMainTicket INTO vSaleMain, vItemFk, vQuantity, vConcept, vPrice, vDiscount;
|
||||
|
||||
WHILE NOT vDone DO
|
||||
|
||||
INSERT INTO vn.sale(ticketFk, itemFk, quantity, concept, price, discount)
|
||||
VALUES( vNewTicket, vItemFk, vQuantity, vConcept, vPrice, vDiscount );
|
||||
|
||||
SET vSaleNew = LAST_INSERT_ID();
|
||||
|
||||
INSERT INTO vn.saleComponent(saleFk,componentFk,`value`)
|
||||
SELECT vSaleNew,componentFk,`value`
|
||||
FROM vn.saleComponent
|
||||
WHERE saleFk = vSaleMain;
|
||||
|
||||
FETCH vRsMainTicket INTO vSaleMain, vItemFk, vQuantity, vConcept, vPrice, vDiscount;
|
||||
|
||||
END WHILE;
|
||||
CLOSE vRsMainTicket;
|
||||
|
||||
END;
|
||||
$$
|
||||
DELIMITER ;
|
|
@ -558,6 +558,7 @@ export default {
|
|||
moreMenuUnmarkReseved: 'vn-item[name="unreserve"]',
|
||||
moreMenuUpdateDiscount: 'vn-item[name="discount"]',
|
||||
moreMenuRecalculatePrice: 'vn-item[name="calculatePrice"]',
|
||||
moreMenuPayBack: 'vn-item[name="payBack"]',
|
||||
moreMenuUpdateDiscountInput: 'vn-input-number[ng-model="$ctrl.edit.discount"] input',
|
||||
transferQuantityInput: '.vn-popover.shown vn-table > div > vn-tbody > vn-tr > vn-td-editable > span > text',
|
||||
transferQuantityCell: '.vn-popover.shown vn-table > div > vn-tbody > vn-tr > vn-td-editable',
|
||||
|
|
|
@ -206,7 +206,16 @@ describe('Ticket Edit sale path', () => {
|
|||
expect(message.text).toContain('Data saved!');
|
||||
});
|
||||
|
||||
it('should select the third sale and create a pay back', async() => {
|
||||
await page.waitToClick(selectors.ticketSales.firstSaleCheckbox);
|
||||
await page.waitToClick(selectors.ticketSales.moreMenu);
|
||||
await page.waitToClick(selectors.ticketSales.moreMenuPayBack);
|
||||
await page.waitForState('ticket.card.sale');
|
||||
});
|
||||
|
||||
it('should select the third sale and create a claim of it', async() => {
|
||||
await page.accessToSearchResult('16');
|
||||
await page.accessToSection('ticket.card.sale');
|
||||
await page.waitToClick(selectors.ticketSales.thirdSaleCheckbox);
|
||||
await page.waitToClick(selectors.ticketSales.moreMenu);
|
||||
await page.waitToClick(selectors.ticketSales.moreMenuCreateClaim);
|
||||
|
|
|
@ -82,7 +82,7 @@ class Controller extends Dialog {
|
|||
}
|
||||
|
||||
set amountToReturn(value) {
|
||||
if (!value) return;
|
||||
if (isNaN(value)) return;
|
||||
|
||||
value = value.toFixed(2);
|
||||
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('payBack', {
|
||||
description: 'Create ticket with the selected lines changing the sign to the quantites',
|
||||
accessType: 'WRITE',
|
||||
accepts: [{
|
||||
arg: 'sales',
|
||||
description: 'The sales',
|
||||
type: ['object'],
|
||||
required: true
|
||||
},
|
||||
{
|
||||
arg: 'ticketId',
|
||||
type: 'number',
|
||||
required: true,
|
||||
description: 'The ticket id'
|
||||
}],
|
||||
returns: {
|
||||
type: 'number',
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/payBack`,
|
||||
verb: 'post'
|
||||
}
|
||||
});
|
||||
|
||||
Self.payBack = async(ctx, sales, ticketId, options) => {
|
||||
const myOptions = {};
|
||||
let tx;
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
if (!myOptions.transaction) {
|
||||
tx = await Self.beginTransaction({});
|
||||
myOptions.transaction = tx;
|
||||
}
|
||||
|
||||
try {
|
||||
const salesIds = [];
|
||||
const params = [];
|
||||
sales.forEach(sale => {
|
||||
salesIds.push(sale.id);
|
||||
params.push('?');
|
||||
});
|
||||
|
||||
const paramsString = params.join();
|
||||
|
||||
const query = `
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.sale;
|
||||
CREATE TEMPORARY TABLE tmp.sale
|
||||
SELECT s.id, s.itemFk, - s.quantity, s.concept, s.price, s.discount
|
||||
FROM sale s
|
||||
WHERE s.id IN (${paramsString});
|
||||
CALL vn.ticket_doRefund(${ticketId}, @newTicket);
|
||||
DROP TEMPORARY TABLE tmp.sale;`;
|
||||
|
||||
await Self.rawSql(query, salesIds, myOptions);
|
||||
const [newTicket] = await Self.rawSql('SELECT @newTicket id', null, myOptions);
|
||||
ticketId = newTicket.id;
|
||||
|
||||
if (tx) await tx.commit();
|
||||
|
||||
return ticketId;
|
||||
} catch (e) {
|
||||
if (tx) await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
};
|
|
@ -0,0 +1,26 @@
|
|||
const models = require('vn-loopback/server/server').models;
|
||||
|
||||
describe('sale payBack()', () => {
|
||||
it('should create ticket with the selected lines changing the sign to the quantites', async() => {
|
||||
const tx = await models.Sale.beginTransaction({});
|
||||
const ticketId = 11;
|
||||
const sales = [
|
||||
{id: 7, ticketFk: 11},
|
||||
{id: 8, ticketFk: 11}
|
||||
];
|
||||
try {
|
||||
const options = {transaction: tx};
|
||||
|
||||
const ctx = {req: {accessToken: {userId: 9}}};
|
||||
const response = await models.Sale.payBack(ctx, sales, ticketId, options);
|
||||
const [newTicketId] = await models.Sale.rawSql('SELECT MAX(t.id) id FROM vn.ticket t;', null, options);
|
||||
|
||||
expect(response).toEqual(newTicketId.id);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
});
|
|
@ -6,6 +6,7 @@ module.exports = Self => {
|
|||
require('../methods/sale/updateQuantity')(Self);
|
||||
require('../methods/sale/updateConcept')(Self);
|
||||
require('../methods/sale/recalculatePrice')(Self);
|
||||
require('../methods/sale/payBack')(Self);
|
||||
require('../methods/sale/canEdit')(Self);
|
||||
|
||||
Self.validatesPresenceOf('concept', {
|
||||
|
|
|
@ -490,4 +490,9 @@
|
|||
ng-if="$ctrl.isEditable && $ctrl.hasReserves()">
|
||||
Unmark as reserved
|
||||
</vn-item>
|
||||
<vn-item translate
|
||||
name="payBack"
|
||||
ng-click="$ctrl.createPayBack()">
|
||||
Pay Back
|
||||
</vn-item>
|
||||
</vn-menu>
|
|
@ -460,6 +460,18 @@ class Controller extends Section {
|
|||
});
|
||||
}
|
||||
|
||||
createPayBack() {
|
||||
const sales = this.selectedValidSales();
|
||||
if (!sales) return;
|
||||
|
||||
const params = {sales: sales, ticketId: this.ticket.id};
|
||||
const query = `Sales/payBack`;
|
||||
this.resetChanges();
|
||||
this.$http.post(query, params).then(res => {
|
||||
this.$state.go('ticket.card.sale', {id: res.data});
|
||||
});
|
||||
}
|
||||
|
||||
itemSearchFunc($search) {
|
||||
return /^\d+$/.test($search)
|
||||
? {id: $search}
|
||||
|
|
|
@ -701,6 +701,22 @@ describe('Ticket', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('createPayBack()', () => {
|
||||
it('should make an HTTP POST query and then call to the $state go() method', () => {
|
||||
jest.spyOn(controller, 'selectedValidSales').mockReturnValue(controller.sales);
|
||||
jest.spyOn(controller, 'resetChanges');
|
||||
jest.spyOn(controller.$state, 'go');
|
||||
|
||||
const expectedId = 9999;
|
||||
$httpBackend.expect('POST', `Sales/payBack`).respond(200, expectedId);
|
||||
controller.createPayBack();
|
||||
$httpBackend.flush();
|
||||
|
||||
expect(controller.resetChanges).toHaveBeenCalledWith();
|
||||
expect(controller.$state.go).toHaveBeenCalledWith('ticket.card.sale', {id: expectedId});
|
||||
});
|
||||
});
|
||||
|
||||
describe('itemSearchFunc()', () => {
|
||||
it('should return the filter by id property for an input of a number', () => {
|
||||
const itemId = 1;
|
||||
|
|
|
@ -36,3 +36,4 @@ Warehouse: Almacen
|
|||
Agency: Agencia
|
||||
Shipped: F. envio
|
||||
Packaging: Encajado
|
||||
Pay Back: Abono
|
|
@ -23,6 +23,10 @@
|
|||
<td class="font gray uppercase">{{$t('clientId')}}</td>
|
||||
<th>{{client.id}}</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="font gray uppercase">{{$t('phone')}}</td>
|
||||
<th>{{client.phone}}</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="font gray uppercase">{{$t('date')}}</td>
|
||||
<th>{{dated}}</th>
|
||||
|
|
|
@ -9,6 +9,7 @@ reference: Referencia
|
|||
concept: Concepto
|
||||
clientSignature: Firma del cliente
|
||||
claim: Reclamación {0}
|
||||
phone: Teléfono
|
||||
sections:
|
||||
agency:
|
||||
description: 'Para agilizar su recogida, por favor, póngase en contacto con la oficina
|
||||
|
|
|
@ -8,7 +8,8 @@ SELECT
|
|||
a.street,
|
||||
a.nickname,
|
||||
p.name AS province,
|
||||
ct.country
|
||||
ct.country,
|
||||
IFNULL(c.phone, cc.phone) AS phone
|
||||
FROM claim cl
|
||||
JOIN client c ON c.id = cl.clientFk
|
||||
JOIN account.user u ON u.id = c.id
|
||||
|
@ -17,4 +18,6 @@ FROM claim cl
|
|||
LEFT JOIN province p ON p.id = a.provinceFk
|
||||
LEFT JOIN autonomy amy ON amy.id = p.autonomyFk
|
||||
LEFT JOIN country ct ON ct.id = amy.countryFk
|
||||
LEFT JOIN clientContact cc ON cc.clientFk = c.id
|
||||
WHERE cl.id = ?
|
||||
LIMIT 1;
|
Loading…
Reference in New Issue