5842-hotfix_recalcularFechaFactura #1617

Merged
alexm merged 4 commits from 5842-hotfix_recalcularFechaFactura into master 2023-06-15 08:32:16 +00:00
2 changed files with 23 additions and 16 deletions

View File

@ -118,7 +118,8 @@
label="Company" label="Company"
show-field="code" show-field="code"
value-field="id" value-field="id"
ng-model="$ctrl.companyFk"> ng-model="$ctrl.companyFk"
on-change="$ctrl.getInvoiceDate(value)">
</vn-autocomplete> </vn-autocomplete>
<vn-autocomplete <vn-autocomplete
url="Printers" url="Printers"

View File

@ -7,23 +7,29 @@ class Controller extends Section {
$onInit() { $onInit() {
const date = Date.vnNew(); const date = Date.vnNew();
Object.assign(this, { Object.assign(this, {
maxShipped: new Date(date.getFullYear(), date.getMonth(), 0), maxShipped: new Date(date.getFullYear(), date.getMonth(), 0),
clientsToInvoice: 'all', clientsToInvoice: 'all',
}); });
this.$http.get('UserConfigs/getUserConfig') this.$http.get('UserConfigs/getUserConfig')
.then(res => { .then(res => {
this.companyFk = res.data.companyFk; this.companyFk = res.data.companyFk;
const params = { this.getInvoiceDate(this.companyFk);
companyFk: this.companyFk });
}; }
return this.$http.get('InvoiceOuts/getInvoiceDate', {params});
}) getInvoiceDate(companyFk) {
.then(res => { const params = { companyFk: companyFk };
this.minInvoicingDate = res.data.issued ? new Date(res.data.issued) : null; this.fetchInvoiceDate(params);
this.invoiceDate = this.minInvoicingDate; }
});
} fetchInvoiceDate(params) {
this.$http.get('InvoiceOuts/getInvoiceDate', { params })
.then(res => {
this.minInvoicingDate = res.data.issued ? new Date(res.data.issued) : null;
this.invoiceDate = this.minInvoicingDate;
});
}
stopInvoicing() { stopInvoicing() {
this.status = 'stopping'; this.status = 'stopping';
@ -42,7 +48,7 @@ class Controller extends Section {
throw new UserError('Invoice date and the max date should be filled'); throw new UserError('Invoice date and the max date should be filled');
if (this.invoiceDate < this.maxShipped) if (this.invoiceDate < this.maxShipped)
throw new UserError('Invoice date can\'t be less than max date'); throw new UserError('Invoice date can\'t be less than max date');
if (this.invoiceDate.getTime() < this.minInvoicingDate.getTime()) if (this.minInvoicingDate && this.invoiceDate.getTime() < this.minInvoicingDate.getTime())
throw new UserError('Exists an invoice with a previous date'); throw new UserError('Exists an invoice with a previous date');
if (!this.companyFk) if (!this.companyFk)
throw new UserError('Choose a valid company'); throw new UserError('Choose a valid company');