Esempio n. 1
0
    def __init__(self, parent, id):
        wx.Dialog.__init__(self, parent, id)

        self.parent = parent
        self.controller_pay = Pay_controller()
        self.controller_sale = Sale()
        img_cash = Platform("/img/toolbars/coins.png")
        img_card = Platform("/img/toolbars/credit_card.png")

        self.get_total()

        self.p_total = wx.Panel(self, -1)
        self.p_due = wx.Panel(self, -1)
        self.p_pay = wx.Panel(self, -1)
        self.bm_cash = wx.BitmapButton(self.p_pay, -1, wx.Bitmap(img_cash.string, wx.BITMAP_TYPE_ANY))
        self.bm_card = wx.BitmapButton(self.p_pay, -1, wx.Bitmap(img_card.string, wx.BITMAP_TYPE_ANY))
        self.sl_pay = wx.StaticLine(self, -1, style=wx.LI_VERTICAL)

        self.controller_pay.get_data_pay()
        self.cb_salesman = wx.ComboBox(
            self,
            -1,
            choices=self.controller_pay.choices_salesman,
            style=wx.CB_DROPDOWN | wx.CB_DROPDOWN | wx.CB_READONLY,
        )
        self.cb_coins = wx.ComboBox(
            self, -1, choices=self.controller_pay.choices_coins, style=wx.CB_DROPDOWN | wx.CB_READONLY
        )
        self.l_before = wx.StaticText(self, -1, "Pagado")
        self.l_vbefore = wx.StaticText(self, -1, "$00.00", style=wx.ALIGN_CENTRE)
        self.l_due = wx.StaticText(self.p_due, -1, "Faltante")
        self.l_vdue = wx.StaticText(self.p_due, -1, "$" + self.total)
        self.tc_total = wx.TextCtrl(self.p_total, -1, self.total)
        self.l_change = wx.StaticText(self.p_total, -1, "Cambio")
        self.l_vchange = wx.StaticText(self.p_total, -1, "$00.00")
        self.b_accept = wx.Button(self, -1, "aceptar")
        self.b_cancel = wx.Button(self, -1, "cancel")
        self.Center()
        self.get_paid()

        self.Bind(wx.EVT_BUTTON, self.close, id=self.b_cancel.GetId())
        self.Bind(wx.EVT_BUTTON, self.accept, id=self.b_accept.GetId())
        self.Bind(wx.EVT_TEXT, self.get_change, id=self.tc_total.GetId())

        self.__set_properties()
        self.__do_layout()
Esempio n. 2
0
class Sale_helper:
    """
    Crea el proceso de venta, agrega productos seleccionados
    desde el panel del listado de productos al panel de venta,
    ademas de que genera el total por producto y total de venta

    GetParent = rightPanel
    """
	
    def __init__(self, getparent):
	    self.GetParent = getparent
	    self.controller_sale = Sale()

    def get_column_text(self, lc, index, col):
	    """
	    Obtiene el valor de la columna del item seleccionado
	    """
	    item = lc.GetItem(index, col)
	    return item.GetText()

    def set_column_text(self, lc, index, col, value):
	    """
	    Asigna un valor a la columna del item seleccionado
	    """
	    lc.SetStringItem(index, col, value)

    def get_total(self, lc, index, col, amount, price):
	    total = amount * float(price)
	    lc.SetStringItem(index, col, str(total))

    def get_subtotal(self, lc, l_vsubtotal):
	    self.subtotal = l_vsubtotal
	    count = int(lc.GetItemCount())
	    subtotal = 0

	    for i in range(0, count):
		    subtotal += float(self.get_column_text(lc, i, 3))

	    self.subtotal.SetLabel(str(subtotal))
	    return subtotal

    def get_tax_total(self, lc, l_vstax):
	    self.taxtotal = l_vstax
	    count = int(lc.GetItemCount())
	    totalTax = 0

	    for i in range(0, count):
		    name = self.get_column_text(lc, i, 0)
		    amount = int(self.get_column_text(lc, i, 1))
		    price = float(self.get_column_text(lc, i, 2))
		    totalTax += self.controller_sale.get_tax_product(name, amount, price)

	    self.taxtotal.SetLabel(str(totalTax))
	    return totalTax

    def get_total_sale(self, totalTax, subtotal, l_vtotal):
	    self.saletotal = l_vtotal
	    total = totalTax + subtotal
	    self.saletotal.SetLabel(str(total))

    def insert_product(self,currentIndex, name, price):
	    self.lc_sale = self.GetParent.wp_right.p_content.lc_sale
	    foundIndex = self.search_product(name)
	    count = self.lc_sale.GetItemCount()

	    if count == 0:
	        index = self.lc_sale.InsertStringItem(0,name)
	        self.lc_sale.SetStringItem(index, 1, "1")
	        self.lc_sale.SetStringItem(index, 2, price)
	        self.lc_sale.SetStringItem(index, 3, price)
	        amount = 1
	    elif foundIndex == -1:
	        index = self.lc_sale.InsertStringItem(0,name)
	        self.lc_sale.SetStringItem(index, 1, "1")
	        self.lc_sale.SetStringItem(index, 2, price)
	        self.lc_sale.SetStringItem(index, 3, price)
	        amount = 1
	    else:
	            amount = int(self.get_column_text(self.lc_sale, foundIndex, 1)) + 1
	            self.set_column_text(self.lc_sale, foundIndex, 1, str(amount))
	            self.get_total(self.lc_sale, foundIndex, 3, amount, price)

	    subtotal = self.get_subtotal(self.lc_sale, self.GetParent.wp_right.p_content.l_vsubtotal)
	    taxTotal = self.get_tax_total(self.lc_sale, self.GetParent.wp_right.p_content.l_vstax)
	    self.get_total_sale(taxTotal, subtotal, self.GetParent.wp_right.p_content.l_vtotal)

    def update_sale_info(self, lc, currentIndex, amount):
	    price = self.get_column_text(lc, currentIndex,2)
	    self.set_column_text(lc, currentIndex, 1, str(amount))
	    self.get_total(lc, currentIndex, 3, amount, price)
	    subtotal = self.get_subtotal(lc, self.GetParent.p_content.l_vsubtotal)
	    taxTotal = self.get_tax_total(lc, self.GetParent.p_content.l_vstax)

	    self.get_total_sale(taxTotal, subtotal, self.GetParent.p_content.l_vtotal)
	    sale_current = self.get_products_sale(currentIndex)
	    if subtotal == 0:
		    self.GetParent.list_sales_current[self.GetParent.sale_id-1].clear()
		    self.GetParent.list_sales_current.remove({})

    def search_product(self, name):
	    foundIndex = self.lc_sale.FindItem(-1, name, True)
	    return foundIndex

    def get_products_sale(self, current_id):
	    """
	    Obtiene venta actual con sus productos, para agregarla
	    a la lista de ventas actuales, tambien evita que una venta
	    pendiente se agregue otra vez a la lista de ventas actuales
	    """
	    self.lc_sale = self.GetParent.p_content.lc_sale
	    self.saletotal = self.GetParent.p_content.l_vtotal
	
	    count = int(self.lc_sale.GetItemCount())
	    products_sale_current = []
	    amountSale = 0
	    print count, self.GetParent.statusSale, self.GetParent.statusSalePending
	    if (count and self.GetParent.statusSale) or self.GetParent.statusSalePending:
	        for i in range(0, count):
		        amountSale += int(self.get_column_text(self.lc_sale, i, 1))
		        products_sale_current.append({'name': self.get_column_text(self.lc_sale, i, 0), 'amount': int(self.get_column_text(self.lc_sale, i, 1)),  'price': float(self.get_column_text(self.lc_sale, i, 2)), 'total': float(self.get_column_text(self.lc_sale, i, 3))})

	        if self.GetParent.statusSalePending:
		        """
		        Actualiza los detalles de una venta pendiente y 
		        tambien actualiza la lista de ventas actuales con
		        los datos actualizado de la venta pendiente seleccionada
		        """
		        tmp = []
		        print "GET_PRODUCTS_SALE ",self.GetParent.list_sales_current
		        for item in self.GetParent.list_sales_current:
				    if item['id'] == self.GetParent.sale_id:
					    item['total'] = self.saletotal.GetLabel()
					    item['amount'] = amountSale
					    item['products'] = products_sale_current
				    tmp.append(item)
		        self.GetParent.list_sales_current = tmp
		        sale_current = None
	        else:
			    sale_current  = {'id': current_id,'sku': '--', 'sale': '--', 'amount': amountSale, 'total': self.saletotal.GetLabel(), 'products': products_sale_current}
	    else:
		    sale_current = None

	    return sale_current

    def get_details_sale(self, list_sales_current, current_id):
	    print "get_details_sale ",list_sales_current
	    for item in list_sales_current:
		    if item['id'] == current_id:
			    self.GetParent.details_sale = item['products']
	    self.GetParent.close_sale_list()
Esempio n. 3
0
class Pay_view(wx.Dialog):
    def __init__(self, parent, id):
        wx.Dialog.__init__(self, parent, id)

        self.parent = parent
        self.controller_pay = Pay_controller()
        self.controller_sale = Sale()
        img_cash = Platform("/img/toolbars/coins.png")
        img_card = Platform("/img/toolbars/credit_card.png")

        self.get_total()

        self.p_total = wx.Panel(self, -1)
        self.p_due = wx.Panel(self, -1)
        self.p_pay = wx.Panel(self, -1)
        self.bm_cash = wx.BitmapButton(self.p_pay, -1, wx.Bitmap(img_cash.string, wx.BITMAP_TYPE_ANY))
        self.bm_card = wx.BitmapButton(self.p_pay, -1, wx.Bitmap(img_card.string, wx.BITMAP_TYPE_ANY))
        self.sl_pay = wx.StaticLine(self, -1, style=wx.LI_VERTICAL)

        self.controller_pay.get_data_pay()
        self.cb_salesman = wx.ComboBox(
            self,
            -1,
            choices=self.controller_pay.choices_salesman,
            style=wx.CB_DROPDOWN | wx.CB_DROPDOWN | wx.CB_READONLY,
        )
        self.cb_coins = wx.ComboBox(
            self, -1, choices=self.controller_pay.choices_coins, style=wx.CB_DROPDOWN | wx.CB_READONLY
        )
        self.l_before = wx.StaticText(self, -1, "Pagado")
        self.l_vbefore = wx.StaticText(self, -1, "$00.00", style=wx.ALIGN_CENTRE)
        self.l_due = wx.StaticText(self.p_due, -1, "Faltante")
        self.l_vdue = wx.StaticText(self.p_due, -1, "$" + self.total)
        self.tc_total = wx.TextCtrl(self.p_total, -1, self.total)
        self.l_change = wx.StaticText(self.p_total, -1, "Cambio")
        self.l_vchange = wx.StaticText(self.p_total, -1, "$00.00")
        self.b_accept = wx.Button(self, -1, "aceptar")
        self.b_cancel = wx.Button(self, -1, "cancel")
        self.Center()
        self.get_paid()

        self.Bind(wx.EVT_BUTTON, self.close, id=self.b_cancel.GetId())
        self.Bind(wx.EVT_BUTTON, self.accept, id=self.b_accept.GetId())
        self.Bind(wx.EVT_TEXT, self.get_change, id=self.tc_total.GetId())

        self.__set_properties()
        self.__do_layout()
        # end wxGlade

    def __set_properties(self):
        # begin wxGlade: Pay_view.__set_properties
        self.SetTitle("Pago")
        self.SetBackgroundColour(wx.Colour(47, 47, 47))
        self.bm_cash.SetSize(self.bm_cash.GetBestSize())
        self.bm_card.SetSize(self.bm_card.GetBestSize())
        self.p_pay.SetBackgroundColour(wx.Colour(47, 47, 47))
        self.sl_pay.SetBackgroundColour(wx.Colour(0, 0, 0))
        self.cb_salesman.SetSelection(-1)
        self.cb_coins.SetSelection(-1)
        self.l_before.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, ""))
        self.l_vbefore.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, ""))
        self.l_due.SetBackgroundColour(wx.Colour(255, 255, 255))
        self.l_due.SetFont(wx.Font(30, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, ""))
        self.l_vdue.SetForegroundColour(wx.Colour(255, 0, 0))
        self.l_vdue.SetFont(wx.Font(25, wx.DECORATIVE, wx.NORMAL, wx.BOLD, 0, ""))
        self.p_due.SetBackgroundColour(wx.Colour(255, 255, 255))
        self.tc_total.SetMinSize((398, 52))
        self.tc_total.SetBackgroundColour(wx.Colour(0, 255, 0))
        self.tc_total.SetFont(wx.Font(40, wx.DECORATIVE, wx.NORMAL, wx.NORMAL, 0, ""))
        self.l_change.SetFont(wx.Font(20, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, ""))
        self.l_vchange.SetFont(wx.Font(20, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, ""))
        self.p_total.SetBackgroundColour(wx.Colour(0, 255, 0))
        # end wxGlade

    def __do_layout(self):
        # begin wxGlade: Pay_view.__do_layout
        s_pay = wx.BoxSizer(wx.VERTICAL)
        s_buttons = wx.BoxSizer(wx.HORIZONTAL)
        s_total = wx.BoxSizer(wx.VERTICAL)
        s_due = wx.BoxSizer(wx.VERTICAL)
        sizer_5 = wx.BoxSizer(wx.HORIZONTAL)
        s_paymentforms = wx.BoxSizer(wx.HORIZONTAL)
        s_paymentforms.Add(self.bm_cash, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 10)
        s_paymentforms.Add(self.bm_card, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 10)
        self.p_pay.SetSizer(s_paymentforms)
        s_pay.Add(self.p_pay, 0, wx.EXPAND, 0)
        s_pay.Add(self.sl_pay, 0, wx.ALL | wx.EXPAND, 10)
        sizer_5.Add(self.cb_salesman, 0, wx.ALL, 10)
        sizer_5.Add(self.cb_coins, 0, wx.ALL, 10)
        sizer_5.Add(self.l_before, 0, wx.ALL | wx.ALIGN_CENTER_HORIZONTAL, 5)
        sizer_5.Add(self.l_vbefore, 0, wx.ALL | wx.ALIGN_CENTER_HORIZONTAL, 5)
        s_pay.Add(sizer_5, 0, wx.EXPAND, 0)
        s_due.Add(self.l_due, 0, wx.ALIGN_CENTER_HORIZONTAL, 10)
        s_due.Add(self.l_vdue, 0, wx.ALIGN_CENTER_HORIZONTAL, 10)
        self.p_due.SetSizer(s_due)
        s_pay.Add(self.p_due, 0, wx.EXPAND, 0)
        s_total.Add(self.tc_total, 0, wx.ALL | wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL, 10)
        s_total.Add(self.l_change, 0, wx.ALL | wx.ALIGN_CENTER_HORIZONTAL, 5)
        s_total.Add(self.l_vchange, 0, wx.LEFT | wx.RIGHT | wx.ALIGN_CENTER_HORIZONTAL, 5)
        self.p_total.SetSizer(s_total)
        s_pay.Add(self.p_total, 0, wx.EXPAND, 0)
        s_buttons.Add(self.b_accept, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 10)
        s_buttons.Add(self.b_cancel, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 10)
        s_pay.Add(s_buttons, 0, wx.EXPAND, 0)
        self.SetSizer(s_pay)
        s_pay.Fit(self)
        self.Layout()
        # end wxGlade

    def accept(self, evt):
        """
	    Acepta pagos por partes o completos, una vez pagado aplicado el descuento
	    se puede seguir haciendo pagos por partes.
	    """
        print "Accept DUe", self.parent.statusDue

        if self.parent.statusDue:
            self.parent.l_due = wx.StaticText(self.parent.p_content.p_total, -1, "Faltante")
            self.parent.l_vdue = wx.StaticText(self.parent.p_content.p_total, -1, "0.000")
            self.parent.p_content.s_terms.Add(self.parent.l_due, 3, wx.ALIGN_RIGHT, 0)
            self.parent.p_content.s_values.Add(self.parent.l_vdue, 3, wx.ALIGN_RIGHT, 0)
            self.parent.p_content.Layout()
            self.parent.statusDue = False

        due = float(self.total) - float(self.tc_total.GetValue())
        if due > 0:
            self.parent.l_vdue.SetLabel(str(due))
        else:
            self.parent.l_vdue.SetLabel("0.000")
            self.shopping_cart()
            self.parent.pay_close()

        self.Close()

    def shopping_cart(self):
        """
	    Crea la venta y agrega los productos al carro de compra
	    """

        self.controller_sale.create_sale()

        count = self.parent.p_content.lc_sale.GetItemCount()
        for i in range(0, count):
            name = str(self.parent.p_content.lc_sale.GetItemText(i))
            amount = int(self.parent.helpers_sale.get_column_text(self.parent.p_content.lc_sale, i, 1))
            self.controller_sale.add_shopping_cart(name, amount, self.parent.pos)

    def close(self, evt):
        self.Close()

    def get_paid(self):
        """
	    Obtiene lo pagodo hasta el momento
	    """
        if not self.parent.statusDue:
            paid = float(self.parent.p_content.l_vtotal.GetLabelText()) - float(self.parent.l_vdue.GetLabelText())
            self.l_vbefore.SetLabel(str(paid))

    def get_total(self):
        """
	    Obtiene el total a pagar y va cambiando conforme realicen pagos,
	    total o parcial, genera el faltante del pago.
	    """
        if self.parent.statusDue:
            self.total = self.parent.p_content.l_vtotal.GetLabelText()
        elif float(self.parent.l_vdue.GetLabelText()) > 0:
            self.total = self.parent.l_vdue.GetLabelText()
        else:
            self.parent.statusDue = False

    def get_change(self, evt):
        payment = float(self.tc_total.GetValue())
        change = payment - float(self.total)
        if change > 0:
            self.l_vchange.SetLabel(str(change))
        else:
            self.l_vchange.SetLabel(str("0"))
Esempio n. 4
0
    def __init__(self, getparent):
	    self.GetParent = getparent
	    self.controller_sale = Sale()