|
@@ -2,12 +2,17 @@ import { Component } from '@angular/core';
|
|
|
import { NavController, NavParams, ActionSheetController, AlertController } from 'ionic-angular';
|
|
|
|
|
|
import { SaleOrder } from "../../odoo/models/sale.order";
|
|
|
+import { Partner } from "../../odoo/models/res.partner";
|
|
|
import { ProductProduct } from "../../odoo/models/product.product";
|
|
|
-// import { SaleOrderLine } from "../../odoo/models/sale.order.line";
|
|
|
import { BaseDetailsView } from "../../base/base-details-view";
|
|
|
|
|
|
-import { CustomerSelectionPage } from "./customer-selection/customer-selection";
|
|
|
-import { ProductSelectionPage } from "./product-selection/product-selection";
|
|
|
+import { CustomersPage } from "../customers/customers";
|
|
|
+import { VariantsPage } from "../variants/variants";
|
|
|
+
|
|
|
+import { Cart } from "./models/cart";
|
|
|
+import { CartItem } from "./models/cart-item"
|
|
|
+
|
|
|
+import { EventsManager } from "../../base/events/event-manager";
|
|
|
|
|
|
@Component({
|
|
|
selector: 'page-order',
|
|
@@ -15,153 +20,147 @@ import { ProductSelectionPage } from "./product-selection/product-selection";
|
|
|
})
|
|
|
export class OrderPage extends BaseDetailsView<SaleOrder> {
|
|
|
|
|
|
- cart = [
|
|
|
- // {
|
|
|
- // id: 1,
|
|
|
- // name: "Producto 001",
|
|
|
- // price: 2000,
|
|
|
- // qty: 1,
|
|
|
- // subtotal: 2000
|
|
|
- // },
|
|
|
- // {
|
|
|
- // id: 2,
|
|
|
- // name: "Producto 002",
|
|
|
- // price: 2000,
|
|
|
- // qty: 1,
|
|
|
- // subtotal: 2000
|
|
|
- // },
|
|
|
- // {
|
|
|
- // id: 3,
|
|
|
- // name: "Producto 003",
|
|
|
- // price: 2000,
|
|
|
- // qty: 1,
|
|
|
- // subtotal: 2000
|
|
|
- // },
|
|
|
- // {
|
|
|
- // id: 4,
|
|
|
- // name: "Producto 004",
|
|
|
- // price: 2000,
|
|
|
- // qty: 1,
|
|
|
- // subtotal: 2000
|
|
|
- // },
|
|
|
- // {
|
|
|
- // id: 5,
|
|
|
- // name: "Producto 005",
|
|
|
- // price: 2000,
|
|
|
- // qty: 1,
|
|
|
- // subtotal: 2000
|
|
|
- // },
|
|
|
- // {
|
|
|
- // id: 6,
|
|
|
- // name: "Producto 006",
|
|
|
- // price: 2000,
|
|
|
- // qty: 1,
|
|
|
- // subtotal: 2000
|
|
|
- // },
|
|
|
- // {
|
|
|
- // id: 7,
|
|
|
- // name: "Producto 006",
|
|
|
- // price: 2000,
|
|
|
- // qty: 1,
|
|
|
- // subtotal: 2000
|
|
|
- // },
|
|
|
- // {
|
|
|
- // id: 8,
|
|
|
- // name: "Producto 006",
|
|
|
- // price: 2000,
|
|
|
- // qty: 1,
|
|
|
- // subtotal: 2000
|
|
|
- // }
|
|
|
- ];
|
|
|
+ cart: Cart;
|
|
|
|
|
|
constructor(
|
|
|
public navCtrl: NavController,
|
|
|
public navParams: NavParams,
|
|
|
public actionSheetCtrl: ActionSheetController,
|
|
|
- public alertCtrl: AlertController
|
|
|
+ public alertCtrl: AlertController,
|
|
|
) {
|
|
|
super(SaleOrder, navParams.data.item, navParams.data.kind);
|
|
|
|
|
|
let titleKind = super.getKind() === "budget" ? "Presupuesto" : "Venta";
|
|
|
super.setTitle(super.itemExists() ? "Editar " + titleKind : "Crear " + titleKind);
|
|
|
|
|
|
- this.updateTotal();
|
|
|
+ this.cart = new Cart();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
*
|
|
|
*/
|
|
|
ionViewDidLoad() {
|
|
|
- console.log('ionViewDidLoad OrderPage');
|
|
|
+ EventsManager.subscribe("app:select", data => {
|
|
|
+ if (data.type instanceof Partner) {
|
|
|
+ this.setCustomer(data.item);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (data.type instanceof ProductProduct) {
|
|
|
+ this.addProduct(data.item);
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
*
|
|
|
*/
|
|
|
- selectCustomer(): void {
|
|
|
- this.navCtrl.push(CustomerSelectionPage);
|
|
|
+ getCart(): Cart {
|
|
|
+ return this.cart;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
*
|
|
|
*/
|
|
|
- getCart(): Array<any> {
|
|
|
- return this.cart;
|
|
|
+ getCustomer(): Partner {
|
|
|
+ return this.getCart().getCustomer();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
*
|
|
|
- * @param item
|
|
|
- * @param quantity
|
|
|
*/
|
|
|
- updateQuantity(item: any, quantity: number) {
|
|
|
- if ((item.qty + quantity) <= 0) {
|
|
|
- this.askIfRemove(item);
|
|
|
- return;
|
|
|
- }
|
|
|
+ getCustomerName(): string {
|
|
|
+ return this.getCustomer() ? this.getCustomer().name : "";
|
|
|
+ }
|
|
|
|
|
|
- item.qty = item.qty + quantity;
|
|
|
- item.subtotal = item.price * item.qty;
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ */
|
|
|
+ getItems(): Array<CartItem> {
|
|
|
+ return this.getCart().getItems();
|
|
|
+ }
|
|
|
|
|
|
- this.updateTotal();
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ */
|
|
|
+ getTotal(): number {
|
|
|
+ return this.getCart().getTotal();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
*
|
|
|
- * @param item
|
|
|
- * @param price
|
|
|
+ * @param cart
|
|
|
*/
|
|
|
- updatePrice(item: any, price: number) {
|
|
|
- item.price = price;
|
|
|
- item.subtotal = item.price * item.qty;
|
|
|
+ setCart(cart: Cart): void {
|
|
|
+ this.cart = cart;
|
|
|
+ }
|
|
|
|
|
|
- this.updateTotal();
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @param customer
|
|
|
+ */
|
|
|
+ setCustomer(customer: Partner): void {
|
|
|
+ this.getCart().setCustomer(customer);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
*
|
|
|
*/
|
|
|
- updateTotal(): number {
|
|
|
- let total: number = 0;
|
|
|
+ selectCustomer(): void {
|
|
|
+ this.navCtrl.push(CustomersPage, {
|
|
|
+ params: {
|
|
|
+ mode: "selection"
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
- for (let i = 0; i < this.getCart().length; i++) {
|
|
|
- total = total + this.getCart()[i].subtotal;
|
|
|
- }
|
|
|
-
|
|
|
- return total;
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ */
|
|
|
+ selectProduct(): void {
|
|
|
+ this.navCtrl.push(VariantsPage, {
|
|
|
+ params: {
|
|
|
+ mode: "selection"
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
*
|
|
|
+ * @param product
|
|
|
*/
|
|
|
- openBarcodeReader(): void {
|
|
|
+ addProduct(product: ProductProduct): void {
|
|
|
+ this.getCart().add(product, product.list_price, 1);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
*
|
|
|
+ * @param item
|
|
|
+ * @param quantity
|
|
|
*/
|
|
|
- selectProduct(): void {
|
|
|
- this.navCtrl.push(ProductSelectionPage);
|
|
|
+ updateQuantity(item: CartItem, quantity: number): void {
|
|
|
+ if ((item.getQuantity() + quantity) <= 0) {
|
|
|
+ this.askIfRemove(item);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ item.updateQuantity(quantity);
|
|
|
+ this.cart.updateTotal();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @param item
|
|
|
+ * @param price
|
|
|
+ */
|
|
|
+ updatePrice(item: CartItem, price: number): void {
|
|
|
+ item.updatePrice(price);
|
|
|
+ this.cart.updateTotal();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ */
|
|
|
+ openBarcodeReader(): void {
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -269,7 +268,7 @@ export class OrderPage extends BaseDetailsView<SaleOrder> {
|
|
|
{
|
|
|
text: "Aceptar",
|
|
|
handler: () => {
|
|
|
- this.remove(item);
|
|
|
+ this.removeFromCart(item);
|
|
|
}
|
|
|
}
|
|
|
]
|
|
@@ -280,22 +279,16 @@ export class OrderPage extends BaseDetailsView<SaleOrder> {
|
|
|
*
|
|
|
* @param item
|
|
|
*/
|
|
|
- remove(item: any): void {
|
|
|
- console.log(item);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- *
|
|
|
- */
|
|
|
- emptyCart(): boolean {
|
|
|
- return this.getCart().length === 0;
|
|
|
+ removeFromCart(item: CartItem): void {
|
|
|
+ this.cart.remove(item);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
*
|
|
|
* @param data
|
|
|
*/
|
|
|
- submit(data: any) {
|
|
|
- console.log(data);
|
|
|
+ submit() {
|
|
|
+ console.log(this.getCart());
|
|
|
+
|
|
|
}
|
|
|
}
|