refactor: code
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Vicent Llopis 2022-12-27 13:50:10 +01:00
parent b406551f52
commit 7b8a9791b4
3 changed files with 55 additions and 61 deletions

View File

@ -1,46 +1,46 @@
<div class="vn-w-md">
<vn-data-viewer
data="data"
class="vn-w-md vn-mb-xl">
<vn-card>
<vn-table>
<vn-thead>
<vn-tr>
<vn-th field="id">Id</vn-th>
<vn-th field="name">Status</vn-th>
</vn-tr>
</vn-thead>
<vn-tbody>
<vn-tr
ng-repeat="client in data track by client.id">
<vn-td>
<span
vn-click-stop="clientDescriptor.show($event, client.id)"
class="link">
{{::client.id}}
</span>
</vn-td>
<vn-td>
<vn-spinner
ng-if="client.status == 'waiting'"
enable="true">
</vn-spinner>
<vn-icon
ng-if="client.status == 'ok'"
icon="check">
</vn-icon>
<vn-icon
class="error"
ng-if="client.status == 'error'"
icon="error">
</vn-icon>
</vn-td>
</vn-tr>
</vn-tbody>
</vn-table>
</vn-card>
</vn-data-viewer>
</div>
<h3 ng-if="$ctrl.packageInvoicing" translate style="text-align: center;">{{'Calculating packages to invoice...'}}</h3>
<vn-card class="vn-w-lg">
<vn-table ng-if="data.length">
<vn-thead>
<vn-tr>
<vn-th field="id">Id</vn-th>
<vn-th field="id">Address</vn-th>
<vn-th field="name">Status</vn-th>
</vn-tr>
</vn-thead>
<vn-tbody>
<vn-tr
ng-repeat="client in data">
<vn-td>
<span
vn-click-stop="clientDescriptor.show($event, client.id)"
class="link">
{{::client.id}}
</span>
</vn-td>
<vn-td>
{{::client.address}}
</vn-td>
<vn-td>
<vn-spinner
ng-if="client.status == 'waiting'"
enable="true">
</vn-spinner>
<vn-icon
ng-if="client.status == 'ok'"
icon="check">
</vn-icon>
<vn-icon
class="error"
ng-if="client.status == 'error'"
icon="error">
</vn-icon>
</vn-td>
</vn-tr>
</vn-tbody>
</vn-table>
</vn-card>
<vn-side-menu side="right">
<vn-crud-model
@ -113,7 +113,7 @@
</vn-autocomplete>
</vn-horizontal>
<vn-submit vn-id="invoiceButton" ng-click="$ctrl.makeInvoice()" label="Invoice" class="vn-mt-sm" ></vn-submit>
<vn-button ng-click="$ctrl.clean()" label="Clean" class="vn-mt-sm"></vn-button>
<vn-button ng-click="$ctrl.clean()" label="Clean" class="vn-mt-sm" disabled="!data.length"></vn-button>
</form>
</vn-side-menu>

View File

@ -40,7 +40,6 @@ class Controller extends Section {
}
restartValues() {
this.lastClientId = null;
this.$.invoiceButton.disabled = false;
}
@ -52,7 +51,6 @@ class Controller extends Section {
invoiceOut(invoice, clientsAndAddresses) {
const [clientAndAddress] = clientsAndAddresses;
if (!clientAndAddress) return;
this.currentClientId = clientAndAddress.clientId;
const params = {
clientId: clientAndAddress.clientId,
addressId: clientAndAddress.addressId,
@ -63,7 +61,14 @@ class Controller extends Section {
};
const index = this.$.data.findIndex(element => element.id == clientAndAddress.clientId);
this.$.data.push({
id: clientAndAddress.clientId,
address: clientAndAddress.addressId,
status: 'waiting'
});
const index = this.$.data.findIndex(
client => client.id == clientAndAddress.clientId && client.address == clientAndAddress.addressId
);
return this.$http.post(`InvoiceOuts/invoiceClient`, params)
.then(() => {
this.$.data[index].status = 'ok';
@ -84,26 +89,13 @@ class Controller extends Section {
throw new Error('Choose a valid clients range');
this.$.invoiceButton.disabled = true;
this.$.data = [];
this.packageInvoicing = true;
this.$http.post(`InvoiceOuts/clientsToInvoice`, this.invoice)
.then(res => {
this.packageInvoicing = false;
const invoice = res.data.invoice;
const clientsIds = [];
for (const clientAndAddress of res.data.clientsAndAddresses)
clientsIds.push(clientAndAddress.clientId);
const dataArr = new Set(clientsIds);
const clientsIdsNoRepeat = [...dataArr];
const clients = clientsIdsNoRepeat.map(clientId => {
return {
id: clientId,
status: 'waiting'
};
});
this.$.data = clients;
const clientsAndAddresses = res.data.clientsAndAddresses;
if (!clientsAndAddresses.length) throw new UserError(`There aren't clients to invoice`);
return this.invoiceOut(invoice, clientsAndAddresses);

View File

@ -4,4 +4,6 @@ Invoice date: Fecha de factura
Invoice date and the max date should be filled: La fecha de factura y la fecha límite deben rellenarse
Choose a valid clients range: Selecciona un rango válido de clientes
Clients range: Rango de clientes
All clients: Todos los clientes
Calculating packages to invoice...: Calculando paquetes a factura...
Clean: Limpiar