Skip to content
This repository has been archived by the owner on Jun 25, 2022. It is now read-only.

Commit

Permalink
feat(front-end): Make a complete ProductInvoiceRegister component
Browse files Browse the repository at this point in the history
See also: #153
  • Loading branch information
CarlosPavajeau committed Jan 5, 2021
1 parent ef09b7b commit c4e5302
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,12 @@
</mat-card-content>
<mat-card-actions>
<div class="form-buttons" *ngIf="selectedProducts.length > 0">
<button mat-raised-button class="royal_azure">
<button
mat-raised-button
class="royal_azure"
(click)="onSubmit()"
[appLoadingButton]="savingProductInvoice"
>
Facturar productos
</button>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import { Component, OnInit } from '@angular/core';
import { AbstractControl, FormBuilder, FormGroup, Validators } from '@angular/forms';
import { Router } from '@angular/router';
import { IForm } from '@core/models/form';
import { buildIsoDate } from '@core/utils/date-utils';
import { zeroPad } from '@core/utils/number-utils';
import { Client } from '@modules/clients/models/client';
import { Product } from '@modules/inventory/products/models/product';
import { ProductService } from '@modules/inventory/products/services/product.service';
import { InvoiceState } from '@modules/payments/models/invoice-state';
import { PaymentMethod } from '@modules/payments/models/payment-method';
import { ProductInvoice } from '@modules/payments/models/product-invoice';
import { ProductInvoiceDetail } from '@modules/payments/models/product-invoice-detail';
import { ProductInvoiceService } from '@modules/payments/services/product-invoice.service';
import { ObservableStatus } from '@shared/models/observable-with-status';
Expand All @@ -22,6 +29,7 @@ export class ProductInvoiceRegisterComponent implements OnInit, IForm {
subTotal = 0.0;

productInvoiceForm: FormGroup;
savingProductInvoice = false;

get controls(): { [p: string]: AbstractControl } {
return this.productInvoiceForm.controls;
Expand All @@ -31,7 +39,8 @@ export class ProductInvoiceRegisterComponent implements OnInit, IForm {
private productService: ProductService,
private productInvoiceService: ProductInvoiceService,
private notificationsService: NotificationsService,
private formBuilder: FormBuilder
private formBuilder: FormBuilder,
private router: Router
) {}

ngOnInit(): void {
Expand All @@ -50,7 +59,32 @@ export class ProductInvoiceRegisterComponent implements OnInit, IForm {
});
}

onSubmit(): void {}
onSubmit(): void {
if (this.selectedProducts.length > 0) {
const client: Client = JSON.parse(localStorage.getItem('current_person'));
const today = new Date();
const todayISO = buildIsoDate(today, `${zeroPad(today.getHours(), 2)}:${zeroPad(today.getMinutes(), 2)}`);
const productInvoice: ProductInvoice = {
state: InvoiceState.Generated,
paymentMethod: PaymentMethod.None,
generationDate: todayISO,
clientId: client.id,
productInvoiceDetails: this.selectedProducts
};

this.savingProductInvoice = true;
this.productInvoiceService.saveProductInvoice(productInvoice).subscribe((result) => {
if (result) {
this.notificationsService.showSuccessMessage(
'Factura de producto generada con éxito, puede proceder a pagarla.',
() => {
this.router.navigateByUrl(`payments/pay/product_invoice/${result.id}`);
}
);
}
});
}
}

addProduct(): void {
if (this.productInvoiceForm.valid) {
Expand Down

0 comments on commit c4e5302

Please sign in to comment.