|
@@ -1,7 +1,8 @@
|
|
import { Component } from '@angular/core';
|
|
import { Component } from '@angular/core';
|
|
-import { NavController, NavParams } from 'ionic-angular';
|
|
|
|
|
|
+import { NavController, NavParams, ActionSheetController, AlertController } from 'ionic-angular';
|
|
|
|
|
|
import { SaleOrder } from "../../odoo/models/sale.order";
|
|
import { SaleOrder } from "../../odoo/models/sale.order";
|
|
|
|
+import { ProductProduct } from "../../odoo/models/product.product";
|
|
// import { SaleOrderLine } from "../../odoo/models/sale.order.line";
|
|
// import { SaleOrderLine } from "../../odoo/models/sale.order.line";
|
|
import { BaseDetailsView } from "../../base/base-details-view";
|
|
import { BaseDetailsView } from "../../base/base-details-view";
|
|
|
|
|
|
@@ -16,25 +17,29 @@ export class OrderPage extends BaseDetailsView<SaleOrder> {
|
|
|
|
|
|
cart = [
|
|
cart = [
|
|
{
|
|
{
|
|
|
|
+ id: 1,
|
|
name: "Producto 001",
|
|
name: "Producto 001",
|
|
price: 2000,
|
|
price: 2000,
|
|
qty: 1,
|
|
qty: 1,
|
|
subtotal: 2000
|
|
subtotal: 2000
|
|
},
|
|
},
|
|
{
|
|
{
|
|
- name: "Producto 001",
|
|
|
|
|
|
+ id: 2,
|
|
|
|
+ name: "Producto 002",
|
|
price: 2000,
|
|
price: 2000,
|
|
qty: 1,
|
|
qty: 1,
|
|
subtotal: 2000
|
|
subtotal: 2000
|
|
},
|
|
},
|
|
{
|
|
{
|
|
- name: "Producto 001",
|
|
|
|
|
|
+ id: 3,
|
|
|
|
+ name: "Producto 003",
|
|
price: 2000,
|
|
price: 2000,
|
|
qty: 1,
|
|
qty: 1,
|
|
subtotal: 2000
|
|
subtotal: 2000
|
|
},
|
|
},
|
|
{
|
|
{
|
|
- name: "Producto 001",
|
|
|
|
|
|
+ id: 4,
|
|
|
|
+ name: "Producto 004",
|
|
price: 2000,
|
|
price: 2000,
|
|
qty: 1,
|
|
qty: 1,
|
|
subtotal: 2000
|
|
subtotal: 2000
|
|
@@ -43,14 +48,16 @@ export class OrderPage extends BaseDetailsView<SaleOrder> {
|
|
|
|
|
|
constructor(
|
|
constructor(
|
|
public navCtrl: NavController,
|
|
public navCtrl: NavController,
|
|
- public navParams: NavParams
|
|
|
|
|
|
+ public navParams: NavParams,
|
|
|
|
+ public actionSheetCtrl: ActionSheetController,
|
|
|
|
+ public alertCtrl: AlertController
|
|
) {
|
|
) {
|
|
super(SaleOrder, navParams.data.item, navParams.data.kind);
|
|
super(SaleOrder, navParams.data.item, navParams.data.kind);
|
|
|
|
|
|
let titleKind = super.getKind() === "budget" ? "Presupuesto" : "Venta";
|
|
let titleKind = super.getKind() === "budget" ? "Presupuesto" : "Venta";
|
|
super.setTitle(super.itemExists() ? "Editar " + titleKind : "Crear " + titleKind);
|
|
super.setTitle(super.itemExists() ? "Editar " + titleKind : "Crear " + titleKind);
|
|
|
|
|
|
- this.getTotal();
|
|
|
|
|
|
+ this.updateTotal();
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -67,11 +74,46 @@ export class OrderPage extends BaseDetailsView<SaleOrder> {
|
|
this.navCtrl.push(CustomerSelectionPage);
|
|
this.navCtrl.push(CustomerSelectionPage);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ *
|
|
|
|
+ */
|
|
getCart(): Array<any> {
|
|
getCart(): Array<any> {
|
|
return this.cart;
|
|
return this.cart;
|
|
}
|
|
}
|
|
|
|
|
|
- getTotal(): number {
|
|
|
|
|
|
+ /**
|
|
|
|
+ *
|
|
|
|
+ * @param item
|
|
|
|
+ * @param quantity
|
|
|
|
+ */
|
|
|
|
+ updateQuantity(item: any, quantity: number) {
|
|
|
|
+ if ((item.qty + quantity) <= 0) {
|
|
|
|
+ this.askIfRemove(item);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ item.qty = item.qty + quantity;
|
|
|
|
+ item.subtotal = item.price * item.qty;
|
|
|
|
+
|
|
|
|
+ this.updateTotal();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ *
|
|
|
|
+ * @param item
|
|
|
|
+ * @param price
|
|
|
|
+ */
|
|
|
|
+ updatePrice(item: any, price: number) {
|
|
|
|
+ item.price = price;
|
|
|
|
+ item.subtotal = item.price * item.qty;
|
|
|
|
+
|
|
|
|
+ this.updateTotal();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ *
|
|
|
|
+ */
|
|
|
|
+ updateTotal(): number {
|
|
let total: number = 0;
|
|
let total: number = 0;
|
|
|
|
|
|
for (let i = 0; i < this.getCart().length; i++) {
|
|
for (let i = 0; i < this.getCart().length; i++) {
|
|
@@ -85,7 +127,6 @@ export class OrderPage extends BaseDetailsView<SaleOrder> {
|
|
*
|
|
*
|
|
*/
|
|
*/
|
|
openBarcodeReader(): void {
|
|
openBarcodeReader(): void {
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -98,9 +139,121 @@ export class OrderPage extends BaseDetailsView<SaleOrder> {
|
|
/**
|
|
/**
|
|
*
|
|
*
|
|
*/
|
|
*/
|
|
- openOptions(): void {
|
|
|
|
- console.log("options");
|
|
|
|
-
|
|
|
|
|
|
+ openOptions(item: any): void {
|
|
|
|
+ this.actionSheetCtrl.create({
|
|
|
|
+ title: "Opciones",
|
|
|
|
+ buttons: [
|
|
|
|
+ {
|
|
|
|
+ text: "Aplicar descuento",
|
|
|
|
+ icon: "calculator",
|
|
|
|
+ handler: () => {
|
|
|
|
+ this.showDiscount(item);
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ text: "Agregar cantidad",
|
|
|
|
+ icon: "cart",
|
|
|
|
+ handler: () => {
|
|
|
|
+ this.showQuantity(item);
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ text: "Borrar",
|
|
|
|
+ icon: "remove",
|
|
|
|
+ handler: () => {
|
|
|
|
+ this.askIfRemove(item);
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ text: "Cancelar",
|
|
|
|
+ role: "cancel"
|
|
|
|
+ }
|
|
|
|
+ ]
|
|
|
|
+ }).present();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ *
|
|
|
|
+ * @param item
|
|
|
|
+ */
|
|
|
|
+ showDiscount(item: any): void {
|
|
|
|
+ this.alertCtrl.create({
|
|
|
|
+ title: "Descuento",
|
|
|
|
+ inputs: [
|
|
|
|
+ {
|
|
|
|
+ name: "discount",
|
|
|
|
+ type: "number",
|
|
|
|
+ value: item.price
|
|
|
|
+ }
|
|
|
|
+ ],
|
|
|
|
+ buttons: [
|
|
|
|
+ {
|
|
|
|
+ text: "Cancelar"
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ text: "Aceptar",
|
|
|
|
+ handler: (e) => {
|
|
|
|
+ this.updatePrice(item, e.discount);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ ]
|
|
|
|
+ }).present();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ *
|
|
|
|
+ * @param item
|
|
|
|
+ */
|
|
|
|
+ showQuantity(item: any): void {
|
|
|
|
+ this.alertCtrl.create({
|
|
|
|
+ title: "Cantidad",
|
|
|
|
+ inputs: [
|
|
|
|
+ {
|
|
|
|
+ name: "quantity",
|
|
|
|
+ type: "number",
|
|
|
|
+ value: item.qty
|
|
|
|
+ }
|
|
|
|
+ ],
|
|
|
|
+ buttons: [
|
|
|
|
+ {
|
|
|
|
+ text: "Cancelar"
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ text: "Aceptar",
|
|
|
|
+ handler: (e) => {
|
|
|
|
+ this.updateQuantity(item, e.quantity);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ ]
|
|
|
|
+ }).present();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ *
|
|
|
|
+ */
|
|
|
|
+ askIfRemove(item: any): void {
|
|
|
|
+ this.alertCtrl.create({
|
|
|
|
+ title: "Borrar producto",
|
|
|
|
+ buttons: [
|
|
|
|
+ {
|
|
|
|
+ text: "Cancelar"
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ text: "Aceptar",
|
|
|
|
+ handler: () => {
|
|
|
|
+ this.remove(item);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ ]
|
|
|
|
+ }).present();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ *
|
|
|
|
+ * @param item
|
|
|
|
+ */
|
|
|
|
+ remove(item: any): void {
|
|
|
|
+ console.log(item);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|