feat(ticket_basic-data_step-two): show visible and option withoutNegatives
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Alex Moreno 2021-12-15 14:45:45 +01:00
parent 15b78787df
commit e01d676bb1
4 changed files with 52 additions and 7 deletions

View File

@ -100,19 +100,25 @@ module.exports = Self => {
totalDifference: 0.00, totalDifference: 0.00,
}; };
const query = `CALL vn.ticket_priceDifference(?, ?, ?, ?, ?)`; // Get items visible
let query = `CALL ticketGetVisibleAvailable(?)`;
const [salesVisible] = await Self.rawSql(query, [args.id], myOptions);
const itemVisible = new Map();
for (sale of salesVisible)
itemVisible.set(sale.id, sale.visible);
// Sale price component, one per sale
query = `CALL vn.ticket_priceDifference(?, ?, ?, ?, ?)`;
const params = [args.id, args.landed, args.addressId, args.zoneId, args.warehouseId]; const params = [args.id, args.landed, args.addressId, args.zoneId, args.warehouseId];
const [difComponents] = await Self.rawSql(query, params, myOptions); const [difComponents] = await Self.rawSql(query, params, myOptions);
const map = new Map(); const map = new Map();
// Sale price component, one per sale
for (difComponent of difComponents) for (difComponent of difComponents)
map.set(difComponent.saleFk, difComponent); map.set(difComponent.saleFk, difComponent);
for (sale of salesObj.items) { for (sale of salesObj.items) {
const difComponent = map.get(sale.id); const difComponent = map.get(sale.id);
if (difComponent) { if (difComponent) {
sale.component = difComponent; sale.component = difComponent;
@ -125,6 +131,7 @@ module.exports = Self => {
salesObj.totalUnitPrice += sale.price; salesObj.totalUnitPrice += sale.price;
salesObj.totalUnitPrice = round(salesObj.totalUnitPrice); salesObj.totalUnitPrice = round(salesObj.totalUnitPrice);
sale.visible = itemVisible.get(sale.id);
} }
if (tx) await tx.commit(); if (tx) await tx.commit();

View File

@ -9,6 +9,7 @@
<vn-tr> <vn-tr>
<vn-th number>Item</vn-th> <vn-th number>Item</vn-th>
<vn-th class="align-center">Description</vn-th> <vn-th class="align-center">Description</vn-th>
<vn-th number>Visible</vn-th>
<vn-th number>Quantity</vn-th> <vn-th number>Quantity</vn-th>
<vn-th number>Price (PPU)</vn-th> <vn-th number>Price (PPU)</vn-th>
<vn-th number>New (PPU)</vn-th> <vn-th number>New (PPU)</vn-th>
@ -31,6 +32,13 @@
tabindex="-1"> tabindex="-1">
</vn-fetched-tags> </vn-fetched-tags>
</vn-td> </vn-td>
<vn-td number>
<span
class="chip"
ng-class="{'alert': sale.quantity>sale.visible}">
{{::sale.visible}}
</span>
</vn-td>
<vn-td number>{{::sale.quantity}}</vn-td> <vn-td number>{{::sale.quantity}}</vn-td>
<vn-td number>{{::sale.price | currency: 'EUR': 2}}</vn-td> <vn-td number>{{::sale.price | currency: 'EUR': 2}}</vn-td>
<vn-td number>{{::sale.component.newPrice | currency: 'EUR': 2}}</vn-td> <vn-td number>{{::sale.component.newPrice | currency: 'EUR': 2}}</vn-td>
@ -66,6 +74,12 @@
</div> </div>
</div> </div>
</vn-card> </vn-card>
<div class="totalBox align-left" ng-show="::$ctrl.haveNegatives">
<vn-check
ng-model="$ctrl.ticket.withoutNegatives"
label="Without create negatives">
</vn-check>
</div>
</div> </div>
</vn-side-menu> </vn-side-menu>

View File

@ -20,6 +20,7 @@ class Controller extends Component {
this.getTotalNewPrice(); this.getTotalNewPrice();
this.getTotalDifferenceOfPrice(); this.getTotalDifferenceOfPrice();
this.loadDefaultTicketAction(); this.loadDefaultTicketAction();
this.ticketHaveNegatives();
} }
loadDefaultTicketAction() { loadDefaultTicketAction() {
@ -63,15 +64,37 @@ class Controller extends Component {
this.totalPriceDifference = totalPriceDifference; this.totalPriceDifference = totalPriceDifference;
} }
ticketHaveNegatives() {
let haveNegatives = false;
this.ticket.sale.items.forEach(item => {
if (item.quantity > item.visible)
haveNegatives = true;
});
this.haveNegatives = haveNegatives;
}
onSubmit() { onSubmit() {
if (!this.ticket.option) { if (!this.ticket.option) {
return this.vnApp.showError( return this.vnApp.showError(
this.$t('Choose an option') this.$t('Choose an option')
); );
} }
if (this.ticket.withoutNegatives) {
let salesNewTicket = [];
this.ticket.sale.items.forEach(item => {
if (item.visible >= item.quantity)
salesNewTicket.push(item);
});
let query = `tickets/${this.ticket.id}/componentUpdate`; const params = {
let 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, clientFk: this.ticket.clientFk,
nickname: this.ticket.nickname, nickname: this.ticket.nickname,
agencyModeFk: this.ticket.agencyModeFk, agencyModeFk: this.ticket.agencyModeFk,

View File

@ -5,4 +5,5 @@ Charge difference to: Cargar diferencia a
The ticket has been unrouted: El ticket ha sido desenrutado The ticket has been unrouted: El ticket ha sido desenrutado
Price: Precio Price: Precio
New price: Nuevo precio New price: Nuevo precio
Price difference: Diferencia de precio Price difference: Diferencia de precio
Without create negatives: Sin crear negativos