Ejemplo n.º 1
0
class IniciarCaja(wx.Dialog):
    def __init__(self, parent, id, title):
        wx.Dialog.__init__(self, parent, id, title, size=(180,90))
        self.DBM = DBManager()

        vbox  = wx.BoxSizer(wx.VERTICAL)

        hbox1 = wx.BoxSizer(wx.HORIZONTAL)
        font  = wx.Font(16, wx.NORMAL, wx.NORMAL, wx.BOLD)
        title = wx.StaticText(self, -1, "Inicio de caja")
        title.SetFont( font )

        hbox2      = wx.BoxSizer(wx.HORIZONTAL)
        self.money = wx.TextCtrl(self, -1, "")
        image      = wx.Image('green-ok.gif', 
                              wx.BITMAP_TYPE_ANY).ConvertToBitmap()
        btn_ini    = wx.BitmapButton(self, id=-1, bitmap=image, size=(30,30))

        vbox.Add(  hbox1 )
        vbox.Add(  hbox2 )
        hbox1.Add( title )
        hbox2.Add( self.money )
        hbox2.Add( btn_ini )

        self.Bind(wx.EVT_BUTTON, self.OnInit, btn_ini)

        #self.SetSizerAndFit(vbox)
        self.SetSizer(vbox)
        self.Show(True)

    def OnInit( self, evt ):
        dinero    = self.money.GetValue()
        this_time = datetime.datetime.now().strftime("%m/%d/%y")
        self.DBM.addProductTrans( this_time, dinero, 1, 1, 19, 1, 1, 0, 0)
        self.Close()
Ejemplo n.º 2
0
class VentaAdmin( wx.Dialog ):
    def __init__(self, parent, id, title):
        wx.Dialog.__init__(self, parent, id, title)

        self.SetSize((800,600))
        self.SetMinSize((800,600))

        self.rows      = list()
        self.list_ctrl = wx.ListCtrl(self, style=wx.LC_REPORT)
        image2         = wx.Image('images/add.png', 
                                  wx.BITMAP_TYPE_ANY).ConvertToBitmap()
        self.btn_add   = wx.BitmapButton(self,
                                         id     = -1,
                                         bitmap = image2,
                                         size   = (24,24))
        image3         = wx.Image('images/red.gif',
                                  wx.BITMAP_TYPE_ANY).ConvertToBitmap()
        self.btn_prt   = wx.BitmapButton(self,
                                         id     = -1,
                                         bitmap = image3, 
                                         size   = (24,24))
        image5         = wx.Image('images/delete.png',
                                  wx.BITMAP_TYPE_ANY).ConvertToBitmap()
        self.btn_del   = wx.BitmapButton(self, 
                                         id     = -1,
                                         bitmap = image5,
                                         size   = (24,24))
        self.DBM       = DBManager()
        self.__generateContent()
        Publisher().subscribe(self.__redefine,
                             ("producto_seleccionado_sin_cancha"))

    def __generateContent( self, myfilter=None ):
        rows = self.rows

        self.list_ctrl.InsertColumn(0, "Codigo")
        self.list_ctrl.InsertColumn(1, "Marca")
        self.list_ctrl.InsertColumn(2, "Descripcion")
        self.list_ctrl.InsertColumn(3, "Cantidad")
        self.list_ctrl.InsertColumn(4, "Precio")

        total = 0
        index = 0
        for row in rows:
            if row[0] != '1000':
               self.list_ctrl.InsertStringItem(index, row[0])
               self.list_ctrl.SetStringItem(index, 1, row[1])
               self.list_ctrl.SetStringItem(index, 2, row[2])
               self.list_ctrl.SetStringItem(index, 3, row[4])
               self.list_ctrl.SetStringItem(index, 4, "$ %.2f" % float(row[3]))

               total += float( row[3] )
             
               if index % 2:
                   self.list_ctrl.SetItemBackgroundColour(index, "white")
               else:
                   self.list_ctrl.SetItemBackgroundColour(index, "gray")

               index += 1

        self.list_ctrl.InsertStringItem(index, 'TOTAL')
        self.list_ctrl.SetStringItem(index, 1, '')
        self.list_ctrl.SetStringItem(index, 2, '')
        self.list_ctrl.SetStringItem(index, 3, '')
        self.list_ctrl.SetStringItem(index, 4, '$ %.2f' % float(total))
        self.list_ctrl.SetItemBackgroundColour(index, "red")
        self.list_ctrl.SetItemTextColour(index, "yellow")

        self.Bind(wx.EVT_BUTTON, self.onAdd, self.btn_add)
        self.Bind(wx.EVT_BUTTON, self.onClose, self.btn_prt)

        sizer  = wx.BoxSizer(wx.VERTICAL)
        sizer2 = wx.BoxSizer(wx.HORIZONTAL)

        sizer2.Add(self.btn_add, 0, wx.ALL, 1)
        sizer2.Add(self.btn_del, 0, wx.ALL, 1)
        sizer2.Add(self.btn_prt, 0, wx.ALL, 1)
        sizer.Add(sizer2, 0, wx.ALL, 1)
        sizer.Add(self.list_ctrl, 1, wx.EXPAND)
        self.SetSizer(sizer)
        self.Show(True)

        Publisher().subscribe(self.onSearch, ("producto_buscado"))
        Publisher().subscribe(self.refreshAfterAdd, ("producto_agregado"))

    def __redefine( self, evt ):
        self.list_ctrl.ClearAll()
        producto = evt.data['producto']
        cantidad = evt.data['cantidad']

        self.rows.append( (producto[1],
                           producto[3],
                           producto[2], 
                           str(producto[4]),
                           cantidad, 
                           producto[0] ) )

        self.__generateContent()

    def onSearch( self, evt ):
        self.list_ctrl.ClearAll()
        search_stock = SearchStock(self, -1, "Buscar")
        self.__generateContent(evt.data)

    def onAdd( self, evt ):
        seleccionar = SeleccionarProducto(self,
                                          -1,
                                          "Agregar un producto a la compra")

    def onClose( self, evt ):
        dlg = wx.MessageDialog(self, 
                               'Seguro que desea cerrar la venta?', 
                               'Cerrar Venta?', wx.YES_NO | wx.ICON_QUESTION)
        result = dlg.ShowModal() == wx.ID_YES

        if result:
           dlg.Destroy()
           self.Destroy()

        for producto in self.rows:
           stock          = int( self.DBM.getCantidadByCodigo( str( producto[0] ) )[0] )
           nueva_cantidad = stock - int(producto[4])

           self.DBM.reduceStockById( producto[5], nueva_cantidad )
           self.DBM.addProductTrans( datetime.datetime.now().strftime("%m/%d/%y %H:%M:%S").__str__(), 
                                     producto[4],
                                     1,
                                     producto[3], 
                                     producto[5], 
                                     1,
                                     1,
                                     0,
                                     0 )

    def refreshAfterAdd( self, evt ):
        self.list_ctrl.ClearAll()
        self.__generateContent()
Ejemplo n.º 3
0
class CuentaCancha( wx.Dialog ):

   def __init__( self, parent, id, title, data ):
       wx.Dialog.__init__( self, parent, id, title )
       self.data = data

       self.SetSize(    ( 800, 600 ) )
       self.SetMinSize( ( 800, 600 ) )

       self.list_ctrl = wx.ListCtrl(self, style=wx.LC_REPORT)
       image2         = wx.Image('images/add.png',
                                 wx.BITMAP_TYPE_ANY).ConvertToBitmap()
       self.btn_add   = wx.BitmapButton(self, id=-1, bitmap=image2, 
                                        size=(24,24))
       image5         = wx.Image('images/delete.png',
                                  wx.BITMAP_TYPE_ANY).ConvertToBitmap()
       self.btn_del   = wx.BitmapButton(self, id=-1, bitmap=image5, 
                                        size=(24,24))

       self.__generateContent( )
       self.Bind(wx.EVT_CLOSE, self.__OnClose)
       Publisher().subscribe(self.__redefine, ("producto_seleccionado"))

   def __OnClose( self, evt ):
       Publisher().sendMessage(("cuentacancha_cerrada"), True)
       self.Destroy() 

   def __generateContent( self ):
       self.DBM          = DBManager()
       id_reserva        = self.DBM.getIDReservado( self.data['fecha'],
                                                    self.data['id_cancha'],
                                                    self.data['horario'] )
       id_cuenta_horario = self.DBM.getCuentaHorarioID( id_reserva )[0]
       productos         = self.DBM.getProductosByCuenta( id_cuenta_horario )
       rows              = list()

       try:
          for row in productos:
             rows.append( (row[3], row[4], row[5], row[1], row[2]) )
       except:
          rows.append( ('Vacio', '', '', '', '') )

       self.list_ctrl.InsertColumn(0, "Codigo")
       self.list_ctrl.InsertColumn(1, "Marca")
       self.list_ctrl.InsertColumn(2, "Descripcion")
       self.list_ctrl.InsertColumn(3, "Precio")
       self.list_ctrl.InsertColumn(4, "Cantidad")

       index = 0
       total = 0
       for row in rows:
          self.list_ctrl.InsertStringItem(index, row[0])
          self.list_ctrl.SetStringItem(index, 1, row[1])
          self.list_ctrl.SetStringItem(index, 2, row[2])
          self.list_ctrl.SetStringItem(index, 3, "$ %s" % str( row[3] ))
          self.list_ctrl.SetStringItem(index, 4, str( row[4] ))

          total +=  row[3] * row[4]

          if index % 2:
             self.list_ctrl.SetItemBackgroundColour(index, "white")
          else:
             self.list_ctrl.SetItemBackgroundColour(index, "gray")

          index += 1

       self.list_ctrl.InsertStringItem(index, "TOTAL")
       self.list_ctrl.SetStringItem(index, 1, "")
       self.list_ctrl.SetStringItem(index, 2, "")
       self.list_ctrl.SetStringItem(index, 3, "")
       self.list_ctrl.SetStringItem(index, 4, "$ %s" % total)
       self.list_ctrl.SetItemBackgroundColour(index, "red")

       self.Bind(wx.EVT_BUTTON, self.onAdd, self.btn_add)
       self.Bind(wx.EVT_BUTTON, self.onDel, self.btn_del)

       sizer  = wx.BoxSizer(wx.VERTICAL)
       sizer2 = wx.BoxSizer(wx.HORIZONTAL)

       sizer2.Add(self.btn_add, 0, wx.ALL, 1)
       sizer2.Add(self.btn_del, 0, wx.ALL, 1)
       sizer.Add(sizer2, 0, wx.ALL, 1)
       sizer.Add(self.list_ctrl, 1, wx.EXPAND)
       self.SetSizer(sizer)
       self.Show(True)

   def __redefine( self, evt ):
      self.list_ctrl.ClearAll()
      id_reserva        = self.DBM.getIDReservado( self.data['fecha'], 
                                                   self.data['id_cancha'], 
                                                   self.data['horario'] )
      id_cuenta_horario = self.DBM.getCuentaHorarioID( id_reserva )[0]

      self.DBM.addProductToCuentaCancha( id_cuenta_horario, 
                                         evt.data['producto'][0],
                                         evt.data['producto'][4],
                                         evt.data['cantidad'] )
      nueva_cantidad = evt.data['producto'][6] - int( evt.data['cantidad'] )
      self.DBM.reduceStockById( evt.data['producto'][0], nueva_cantidad ) 
      self.DBM.addProductTrans( self.data["fecha"],
                                evt.data['cantidad'], 
                                1, 
                                evt.data['producto'][4],
                                evt.data['producto'][0],
                                1,
                                1,
                                self.data['id_cancha'], 
                                id_cuenta_horario)

      self.__generateContent()

   def onAdd( self, evt ):
      sp = SeleccionarProducto( self, id=wx.ID_ANY, 
                                title="Agregar Producto a la Compra")

   def onDel( self, evt ):
      item              = self.list_ctrl.GetItem( self.list_ctrl.GetFirstSelected() )
      product           = self.DBM.getProductoByCode( item.GetText() )
      id_reserva        = self.DBM.getIDReservado( self.data['fecha'], 
                                                   self.data['id_cancha'],
                                                   self.data['horario'] )
      id_cuenta_horario = self.DBM.getCuentaHorarioID( id_reserva )[0]
      productos         = self.DBM.getProductosByCuenta( id_cuenta_horario )
      cantidad          = 0

      for prod in productos:
         if prod[0] == product[0][0]:
            cantidad = prod[2]

      n_cantidad = cantidad + product[0][6]

      self.DBM.reduceStockById(               product[0][0], n_cantidad        )
      self.DBM.deleteProductFromCuenta(       product[0][0], id_cuenta_horario )
      self.DBM.deleteProductFromProductTrans( product[0][0], id_cuenta_horario )

      self.list_ctrl.ClearAll()
      self.__generateContent()