|
@@ -1,5 +1,5 @@
|
|
|
import { Component, ViewChild } from "@angular/core";
|
|
|
-import { NavController, Slides, Searchbar, AlertController } from "ionic-angular";
|
|
|
+import { NavController, Slides, Searchbar, AlertController, ToastController } from "ionic-angular";
|
|
|
import { Keyboard } from "ionic-native";
|
|
|
import { DetailsView } from "../../defaults/default-details-view";
|
|
|
import { SaleOrder } from "../../models/sale.order";
|
|
@@ -42,6 +42,7 @@ export class SaleOrderDetailsPage extends DetailsView<SaleOrder> {
|
|
|
constructor(
|
|
|
public navCtrl: NavController,
|
|
|
public alertCtrl: AlertController,
|
|
|
+ public toastCtrl: ToastController,
|
|
|
public db: DataProvider,
|
|
|
public customer: Partner,
|
|
|
) {
|
|
@@ -81,8 +82,6 @@ export class SaleOrderDetailsPage extends DetailsView<SaleOrder> {
|
|
|
this.events.publish(Slots.APP_LOADING);
|
|
|
|
|
|
this.db.getAll(DataProvider.DOCS.PARTNER).then((partners: Array<Partner>) => {
|
|
|
- console.log(partners);
|
|
|
-
|
|
|
this.customers = partners.filter(item => {
|
|
|
return item.customer && item.doc_state != "deleted";
|
|
|
});
|
|
@@ -110,7 +109,7 @@ export class SaleOrderDetailsPage extends DetailsView<SaleOrder> {
|
|
|
/**
|
|
|
*
|
|
|
*/
|
|
|
- onSlideChanged(e: Slides): void {
|
|
|
+ onSlideWillChange(e: Slides): void {
|
|
|
this.search = false;
|
|
|
this.customerSearchBar.value = "";
|
|
|
this.productSearchBar.value = "";
|
|
@@ -119,13 +118,36 @@ export class SaleOrderDetailsPage extends DetailsView<SaleOrder> {
|
|
|
/**
|
|
|
*
|
|
|
*/
|
|
|
- goToNext(): void {
|
|
|
- this.slider.slideNext();
|
|
|
- this.footer.back.show = true;
|
|
|
+ onSlideDidChange(e: Slides): void {
|
|
|
+
|
|
|
+ if (e.getActiveIndex() == 1 && !this.customer.id) {
|
|
|
+ this.goToBack();
|
|
|
|
|
|
- if (this.slider.getActiveIndex() == this.slider.length() - 1) {
|
|
|
- this.footer.forward.show = false;
|
|
|
+ this.alertCtrl.create({
|
|
|
+ title: "Información",
|
|
|
+ message: "No hay un cliente seleccionado",
|
|
|
+ buttons: ["Aceptar"]
|
|
|
+ }).present();
|
|
|
+
|
|
|
+ return;
|
|
|
}
|
|
|
+
|
|
|
+ if (e.getActiveIndex() == 2 && this.lines.length == 0) {
|
|
|
+ this.goToBack();
|
|
|
+
|
|
|
+ this.alertCtrl.create({
|
|
|
+ title: "Información",
|
|
|
+ message: "No hay líneas de presupuesto",
|
|
|
+ buttons: ["Aceptar"]
|
|
|
+ }).present();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ */
|
|
|
+ goToNext(): void {
|
|
|
+ this.slider.slideNext();
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -133,11 +155,6 @@ export class SaleOrderDetailsPage extends DetailsView<SaleOrder> {
|
|
|
*/
|
|
|
goToBack(): void {
|
|
|
this.slider.slidePrev();
|
|
|
- this.footer.forward.show = true;
|
|
|
-
|
|
|
- if (this.slider.getActiveIndex() == 0) {
|
|
|
- this.footer.back.show = false;
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -147,6 +164,9 @@ export class SaleOrderDetailsPage extends DetailsView<SaleOrder> {
|
|
|
this.search = !this.search;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ */
|
|
|
isSearch(): boolean {
|
|
|
return this.search;
|
|
|
}
|
|
@@ -164,7 +184,6 @@ export class SaleOrderDetailsPage extends DetailsView<SaleOrder> {
|
|
|
}
|
|
|
|
|
|
this.search = false;
|
|
|
- this.footer.forward.show = false;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -174,7 +193,6 @@ export class SaleOrderDetailsPage extends DetailsView<SaleOrder> {
|
|
|
this.customer = item;
|
|
|
this.search = false;
|
|
|
this.customerSearchBar.value = "";
|
|
|
- this.footer.forward.show = true;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -369,6 +387,7 @@ export class SaleOrderDetailsPage extends DetailsView<SaleOrder> {
|
|
|
removeItem(line: any): void {
|
|
|
let index = this.lines.indexOf(line);
|
|
|
this.lines.splice(index, 1);
|
|
|
+
|
|
|
this.sumTotal();
|
|
|
}
|
|
|
|
|
@@ -376,6 +395,22 @@ export class SaleOrderDetailsPage extends DetailsView<SaleOrder> {
|
|
|
*
|
|
|
*/
|
|
|
saveSale(): void {
|
|
|
-
|
|
|
+ let saleOrder = {
|
|
|
+ customer: this.customer,
|
|
|
+ lines: this.lines,
|
|
|
+ total: this.total
|
|
|
+ };
|
|
|
+
|
|
|
+ this.db.save(DataProvider.DOCS.SALE_ORDER, saleOrder).then(result => {
|
|
|
+ this.events.publish(Slots.ITEM_CREATE, result);
|
|
|
+ this.navCtrl.pop(this);
|
|
|
+ }).catch(error => {
|
|
|
+ console.log(error);
|
|
|
+
|
|
|
+ this.toastCtrl.create({
|
|
|
+ message: "No se ha podido guardar los datos",
|
|
|
+ duration: 3000
|
|
|
+ }).present();
|
|
|
+ });
|
|
|
}
|
|
|
}
|