feat(ticket_basic-data_step-two): adapted for available and transfer sales in back
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Alex Moreno 2021-12-20 13:50:31 +01:00
parent 6426a629e0
commit b0019d09ad
7 changed files with 52 additions and 36 deletions

View File

@ -2,13 +2,13 @@ DROP PROCEDURE IF EXISTS `vn`.`ticket_getVisibleAvailable`;
DELIMITER $$
$$
CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`ticket_getVisibleAvailable`(vTicket INT, vDate DATE)
CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`ticket_getVisibleAvailable`(`vTicket` INT, `vDate` DATE)
BEGIN
DECLARE vVisibleCalc INT;
DECLARE vAvailableCalc INT;
DECLARE vShipped DATE;
DECLARE vWarehouse TINYINT;
DECLARE vAlertLevel INT;
DECLARE vAlertLevel INT;
SELECT t.warehouseFk, t.shipped, ts.alertLevel
INTO vWarehouse, vShipped, vAlertLevel

View File

@ -1,9 +1,10 @@
DROP PROCEDURE IF EXISTS vn.ticketGetVisibleAvailable;
DROP PROCEDURE IF EXISTS `vn`.`ticketGetVisibleAvailable`;
DELIMITER $$
$$
CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`ticketGetVisibleAvailable`(vTicket INT)
CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`ticketGetVisibleAvailable`(`vTicket` INT)
BEGIN
CALL `ticket_getVisibleAvailable`(vTicket, null);
END$$
DELIMITER ;

View File

@ -216,5 +216,6 @@
"The type of business must be filled in basic data": "El tipo de negocio debe estar rellenado en datos básicos",
"You can't create a claim from a ticket delivered more than seven days ago": "No puedes crear una reclamación de un ticket entregado hace más de siete días",
"The worker has hours recorded that day": "El trabajador tiene horas fichadas ese día",
"The worker has a marked absence that day": "El trabajador tiene marcada una ausencia ese día"
"The worker has a marked absence that day": "El trabajador tiene marcada una ausencia ese día",
"isWithoutNegatives": "Tiene Negativos"
}

View File

@ -77,6 +77,12 @@ module.exports = Self => {
type: 'number',
description: 'Action id',
required: true
},
{
arg: 'isWithoutNegatives',
type: 'boolean',
description: 'Is whithout negatives',
required: true
}],
returns: {
type: ['object'],
@ -112,11 +118,28 @@ module.exports = Self => {
const isProductionBoss = await models.Account.hasRole(userId, 'productionBoss', myOptions);
if (!isProductionBoss) {
const zoneShipped = await models.Agency.getShipped(args.landed, args.addressFk, args.agencyModeFk, args.warehouseFk, myOptions);
const params = [args.landed, args.addressFk, args.agencyModeFk, args.warehouseFk];
const zoneShipped = await models.Agency.getShipped(params, myOptions);
if (!zoneShipped || zoneShipped.zoneFk != args.zoneFk)
throw new UserError(`You don't have privileges to change the zone`);
}
if (args.isWithoutNegatives) {
let query = `CALL ticket_getVisibleAvailable(?,?)`;
let params = [args.id, args.shipped];
const [salesAvailable] = await Self.rawSql(query, params, myOptions);
let salesNewTicket = [];
salesAvailable.forEach(sale => {
if (sale.available >= sale.quantity)
salesNewTicket.push(sale);
});
if (salesNewTicket.length) {
const newTicket = await models.Ticket.transferSales(ctx, args.id, null, salesNewTicket, myOptions);
args.id = newTicket.id;
}
}
const originalTicket = await models.Ticket.findOne({
where: {id: args.id},

View File

@ -106,18 +106,18 @@ module.exports = Self => {
totalDifference: 0.00,
};
// Get items visible
// Get items available
let query = `CALL ticket_getVisibleAvailable(?,?)`;
let params = [args.id, args.shipped];
const [salesVisible] = await Self.rawSql(query, params, myOptions);
const [salesAvailable] = await Self.rawSql(query, params, myOptions);
const itemVisible = new Map();
for (sale of salesVisible) {
let visible = sale.available;
if (visible == null)
visible = 0;
const itemAvailable = new Map();
for (sale of salesAvailable) {
let available = sale.available;
if (available == null)
available = 0;
itemVisible.set(sale.id, visible);
itemAvailable.set(sale.id, available);
}
// Sale price component, one per sale
@ -143,7 +143,7 @@ module.exports = Self => {
salesObj.totalUnitPrice += sale.price;
salesObj.totalUnitPrice = round(salesObj.totalUnitPrice);
sale.visible = itemVisible.get(sale.id);
sale.available = itemAvailable.get(sale.id);
}
if (tx) await tx.commit();

View File

@ -9,7 +9,7 @@
<vn-tr>
<vn-th number>Item</vn-th>
<vn-th class="align-center">Description</vn-th>
<vn-th number>Visible</vn-th>
<vn-th number>Available</vn-th>
<vn-th number>Quantity</vn-th>
<vn-th number>Price (PPU)</vn-th>
<vn-th number>New (PPU)</vn-th>
@ -35,8 +35,8 @@
<vn-td number>
<span
class="chip"
ng-class="{'alert': sale.quantity>sale.visible}">
{{::sale.visible}}
ng-class="{'alert': sale.quantity>sale.available}">
{{::sale.available}}
</span>
</vn-td>
<vn-td number>{{::sale.quantity}}</vn-td>

View File

@ -66,11 +66,16 @@ class Controller extends Component {
ticketHaveNegatives() {
let haveNegatives = false;
let haveNotNegatives = false;
this.ticket.sale.items.forEach(item => {
if (item.quantity > item.visible)
if (item.quantity > item.available)
haveNegatives = true;
else
haveNotNegatives = true;
});
this.haveNegatives = haveNegatives;
this.haveNegatives = (haveNegatives && haveNotNegatives);
}
onSubmit() {
@ -80,21 +85,6 @@ class Controller extends Component {
);
}
if (this.ticket.withoutNegatives) {
let salesNewTicket = [];
this.ticket.sale.items.forEach(item => {
if (item.visible >= item.quantity)
salesNewTicket.push(item);
});
const params = {
sales: salesNewTicket
};
const query = `tickets/${this.ticket.id}/transferSales`;
this.$http.post(query, params);
}
const query = `tickets/${this.ticket.id}/componentUpdate`;
const params = {
clientFk: this.ticket.clientFk,
@ -107,7 +97,8 @@ class Controller extends Component {
shipped: this.ticket.shipped,
landed: this.ticket.landed,
isDeleted: this.ticket.isDeleted,
option: parseInt(this.ticket.option)
option: parseInt(this.ticket.option),
isWithoutNegatives: this.ticket.withoutNegatives
};
this.$http.post(query, params).then(res => {