Пример #1
0
def calculate_capital(self):
    try:
        diary_data_for_capital = crud_driver(
            self, 'diary', 'read', {
                'pick_all': False,
                'multi': False,
                'pick_cols': ['*'],
                'field': 'amount',
                'operator': '<>',
                'order_by': ['id', 'date'],
                'order_': ['ASC', 'ASC'],
                'sort': True,
                'value': (0, )
            })
        capital_data = translate_diary_data_to_table(self, 'capital',
                                                     diary_data_for_capital)
        crud_driver(self, 'capital', 'delete', None)
        crud_driver(
            self, 'capital', 'create', {
                'multi': True,
                'fields': get_template_fields('capital'),
                'value_list': capital_data
            })
        return
    except BaseException as err:
        print('error on generating sales table: {}'.format(err))
        raise Exception(str(err))
Пример #2
0
    def __init__(self):
        super(MainWindow, self).__init__()
        self.status = {}
        # status props---------
        self.connection = None
        self.cursor = None
        self.date_session = current_date  # yyyy-mm-dd
        self.operation = ''  # used for calculator to work
        self.use_secure_entry = True

        # this props will be initialized on init_ui. are used for keep track of counter
        self.counter = 0
        self.last_date = ''

        self.table_on_target = 'diary'
        self.filter_dialog_options: dict = {}
        self.headers_for_tab1: [str
                                ] = get_template_fields(self.table_on_target)
        self.data_to_display_on_tab1 = [
        ]  # this props holds the data to show on table
        #  and need a signal for detect changes and react properly
        #  is readen any time we display data and must be proper updated
        self.data_to_export = []  # used most on buttons export appwide
        #  this prop is used for holding data just
        #  in case that prop <source> on export() is empty
        #  can remain [] if source is provided
        self.imported_data = []

        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        ui_init_routine(self)
Пример #3
0
def calculate_stock(self):
    try:
        diary_data_for_stock = crud_driver(
            self,
            'diary',
            'read',
            {
                'pick_all': False,
                'multi': False,
                'pick_cols': ['*'],
                'field': 'item_code',
                'operator': '<>',
                'order_by': ['is_new', 'date'],
                'order_': ['DESC', 'ASC'
                           ],  # is_new is mandatory to be sorted desc
                'sort': True,
                'value': ('', )
            })
        data_tuples_for_stock = data_tuple_for_stock_builder(
            self, diary_data_for_stock)
        crud_driver(self, 'stock', 'delete', None)
        crud_driver(
            self, 'stock', 'create', {
                'multi': True,
                'fields': get_template_fields('stock'),
                'value_list': data_tuples_for_stock
            })
        return
    except BaseException as err:
        print('error on generating sales table: {}'.format(err))
        raise Exception(str(err))
Пример #4
0
def execute_display_table(self, table_name):
    self.table_on_target = table_name
    self.headers_for_tab1 = get_template_fields(table_name)
    if table_name != 'diary':
        self.recalculate_tables_signal.emit()
        # what else??
    self.data_to_display_on_tab1 = crud_driver(self, table_name, 'read',
                                               {'pick_all': True})
    self.display_table_signal.emit()
    self.ui.tabWidget.setCurrentIndex(0)
    selfCloseInterface(
        'tabla: {} ha sido cargada con exito'.format(table_name), 1, 1,
        'Ver {}'.format(table_name))
    return
Пример #5
0
def import_data_to_diary(self):
    try:
        import_data(
            self,
            False)  # imports the data and writes the array self.imported_data
        transform_imported_data(self, 'diary', 'entry_counter',
                                entry_counter_creator)
        data_to_import = self.imported_data.copy()
        crud_driver(
            self, 'diary', 'create', {
                'fields': get_template_fields('diary'),
                'value_list': data_to_import,
                'multi': True
            })
        self.display_table_signal.emit()
        selfCloseInterface('Data imported to Diary Table', 3, 1,
                           'Import Success')
        return
    except BaseException as error:
        selfCloseInterface('Failed on Importing Data to Diary Table', 3, 2,
                           'Import Failed', str(error))
        print('failed import of data')
        raise error
Пример #6
0
    def apply_routine(self, parent):

        # props alias...
        data_len__ = get_template_fields('diary')
        date__ = get_index_in_template('diary', 'date')
        is_new__ = get_index_in_template('diary', 'is_new')
        is_sale__ = get_index_in_template('diary', 'is_sale')
        is_consignation__ = get_index_in_template('diary', 'is_consignation')
        quantity__ = get_index_in_template('diary', 'quantity')
        item_name__ = get_index_in_template('diary', 'item_name')
        price__ = get_index_in_template('diary', 'price')
        sell_price__ = get_index_in_template('diary', 'sell_price')
        comments__ = get_index_in_template('diary', 'comments')
        item_code__ = get_index_in_template('diary', 'item_code')
        salary__ = get_index_in_template('diary', 'salary')
        invested__ = get_index_in_template('diary', 'invested_')
        cash__ = get_index_in_template('diary', 'cash_')
        total__ = get_index_in_template('diary', 'total_')
        parts__ = [
            get_index_in_template('diary', 'robert_'),
            get_index_in_template('diary', 'ariadna_')
        ]

        last_row_data__ = crud_driver(parent, 'diary', 'read', {})
        last_row_data = build_data_template() if len(
            last_row_data__) == 0 else last_row_data__[-1]
        last_row_data = build_data_template(
        ) if len(data_len__) > len(last_row_data) else last_row_data
        data = build_data_template()

        # this block  is for preventing sales form to be submitted with  invalid data
        # protect against zero items sale
        if self.ui.cantidadVendidaComboBox.currentIndex() == 0:
            selfCloseInterface(
                'No esta permitido vender "cero" {},defina una cantidad adecuada antes de hacer la operacion'
                .format(self.ui.nombreDelProductoComboBox.currentText()), 8, 3,
                'Venta Denegada: CANTIDAD INCORRECTA',
                'la menor cantidad admitida es 1, si no puede, significa que el producto se ha agotado'
            )
            self.init_ui(parent)  # init ui for clean zero items...
            return
            # protect against low price sales
        minimum_sell_price = self.ui.cantidadVendidaComboBox.currentIndex(
        ) * float(self.combo_data[
            self.ui.codigoDelProductoComboBox.currentIndex()][3])
        if self.ui.precioDeVentaDoubleSpinBox.value() < minimum_sell_price:
            low_price_switch = {'switch': False}
            low_price_warn = MessageBox(
                lambda: low_price_switch.update({'switch': True}),
                'Esta seguro de que desea vender {} {} por ${:,.2f} ??'
                '\nel precio minimo para esta cantidad es ${:,.2f}.'
                '\nSi realiza la venta a este precio ocasiona perdidas !!'.
                format(self.ui.cantidadVendidaComboBox.currentText(),
                       self.ui.nombreDelProductoComboBox.currentText(),
                       self.ui.precioDeVentaDoubleSpinBox.value(),
                       minimum_sell_price), 'w',
                'Advertencia: Venta por debajo del precio de costo',
                '\n\n Esta accion es intencional y desea continuar??')
            low_price_warn.show()
            if not low_price_switch.get('switch'):
                return
                # protect against sale more than on_stock
        on_stock__ = int(
            crud_driver(
                parent, 'stock', 'read', {
                    'field': 'item_code',
                    'operator': '=',
                    'value':
                    (self.ui.codigoDelProductoComboBox.currentText(), )
                })[0][get_index_in_template('stock', 'on_stock')])
        if on_stock__ < 1:
            selfCloseInterface(
                'El producto {} no existe en el inventario en este momento,'
                'revise el nombre del producto antes de hacer la operacion'.
                format(self.ui.nombreDelProductoComboBox.currentText()), 8, 3,
                'Venta Denegada: PRODUCTO NO EXISTE',
                'Es muy probable que el producto se haya agotado en la ultima entrada. Verifique el nombre otra vez'
            )
            self.init_ui(parent)  # init ui for clean zero items...
            return

        data[date__] = parent.date_session
        data[is_new__] = False
        data[is_sale__] = True
        data[
            is_consignation__] = self.ui.codigoDelProductoComboBox.currentText(
            )[0] == 'c'
        data[quantity__] = self.ui.cantidadVendidaComboBox.currentIndex()
        data[item_name__] = self.ui.nombreDelProductoComboBox.currentText()
        data[price__] = minimum_sell_price
        data[sell_price__] = self.ui.precioDeVentaDoubleSpinBox.value()
        data[comments__] = self.ui.comentariosLineEdit.text()
        data[item_code__] = self.ui.codigoDelProductoComboBox.currentText()
        data[salary__] = build_salary(parent, data[sell_price__],
                                      minimum_sell_price)
        # capital cells # touches invested
        data[parts__[0]] = last_row_data[parts__[0]]
        data[parts__[1]] = last_row_data[parts__[1]]
        data[total__] = float(last_row_data[total__])

        data[invested__] = float(last_row_data[invested__]) if \
            data[is_consignation__] else (float(last_row_data[invested__]) - data[price__])

        data[cash__] = data[total__] - data[invested__]

        # this is the secure entry block
        msg_str = 'vender {} {} por ${:,.2f}'.format(data[quantity__],
                                                     data[item_name__],
                                                     data[sell_price__])
        if parent.use_secure_entry:
            confirm = MessageBox(lambda: parent.append_data_to_diary(data),
                                 'Desea confirmar la Entrada?', 'q',
                                 'Confirmar Entrada', msg_str)
            confirm.show()
        else:
            parent.append_data_to_diary(data)
            selfCloseInterface(msg_str, 4, 1, 'Operacion Realizada',
                               'Cambios Insertados en la Base de Datos')

        self.init_ui(parent)
        return
Пример #7
0
    def accept_routine(self, parent, is_bulk=False, bulk_data=None):
        # props alias...
        data_len__ = get_template_fields('diary')
        date__ = get_index_in_template('diary', 'date')
        is_new__ = get_index_in_template('diary', 'is_new')
        is_sale__ = get_index_in_template('diary', 'is_sale')
        is_consignation__ = get_index_in_template('diary', 'is_consignation')
        quantity__ = get_index_in_template('diary', 'quantity')
        item_name__ = get_index_in_template('diary', 'item_name')
        price__ = get_index_in_template('diary', 'price')
        sell_price__ = get_index_in_template('diary', 'sell_price')
        comments__ = get_index_in_template('diary', 'comments')
        item_code__ = get_index_in_template('diary', 'item_code')

        # --
        invested__ = get_index_in_template('diary', 'invested_')
        cash__ = get_index_in_template('diary', 'cash_')
        total__ = get_index_in_template('diary', 'total_')
        parts__ = [get_index_in_template('diary', 'robert_'), get_index_in_template('diary', 'ariadna_')]

        last_row_data__ = crud_driver(parent, 'diary', 'read', {})
        last_row_data = build_data_template() if len(last_row_data__) == 0 else last_row_data__[-1]
        last_row_data = build_data_template() if len(data_len__) > len(last_row_data) else last_row_data
        data = build_data_template()

        # this block  is for preventing purchases with no cash
        if last_row_data[cash__] <= 0:
            selfCloseInterface(
                'No esta permitido comprar cuando el saldo de caja es cero, agregue saldo a su caja antes de hacer esta operacion',
                8, 3, 'Compras Denegadas: SIN EFECTIVO',
                'Vaya a:\nMenu Herramientas > Modificar la Inversion\nO presione: CTRL+ALT+M \ny agregue efectivo antes de comprar')
            self.reject()
            parent.ui.actionModificar_la_inversion.trigger()
            return

        data[date__] = parent.date_session
        data[is_new__] = self.ui.nuevoItemPurchaseCheckBox.isChecked() if not is_bulk else True
        data[is_sale__] = False
        data[is_consignation__] = self.ui.itemAConsignacionCheckBox.isChecked() if\
            not is_bulk else not int(bulk_data[0])
        data[quantity__] = self.ui.totalDeItemsCompradosSpinBox.value() if not is_bulk else int(bulk_data[3])
        if not is_bulk:
            data[item_name__] = self.ui.nombreDelItemIncrementadoComboBox.currentText() \
                if not data[is_new__] else self.ui.nombreDelItemCompradoLineEdit.text()
            data[price__] = (self.ui.precioTotalPagadoPorLaCompraDoubleSpinBox.value() / data[quantity__]) \
                if data[is_new__] else self.ui.precioTotalPagadoPorLaCompraDoubleSpinBox.value()
        if is_bulk:
            data[item_name__] = bulk_data[1]
            data[price__] = float(bulk_data[2]) / data[quantity__]

        if any([len(data[item_name__]) < 3, data[price__] == 0]):
            selfCloseInterface(
                'Los datos son incorrectos. Revise la informacion antes de realizar una entrada',
                8, 2, 'Entrada Fallida: DATOS INCORRECTOS',
                'REVISE:\n1- Que el precio no sea cero\n2- Que el articulo tenga un nombre apropiado (mas de 3 letras)'
            )
            return
        data[sell_price__] = 0
        data[comments__] = self.ui.comentariosDeEntradaLineEdit.text()
        data[item_code__] = self.ui.codigoDelItemIncrementadoComboBox.currentText() \
            if not data[is_new__] else build_item_code(data[price__], self.ui.itemAConsignacionCheckBox.isChecked())

        # capital cells # touches invested
        data[parts__[0]] = last_row_data[parts__[0]]
        data[parts__[1]] = last_row_data[parts__[1]]
        data[total__] = float(last_row_data[total__])

        data[invested__] = float(last_row_data[invested__]) if data[is_consignation__] else \
            float(last_row_data[invested__]) + data[quantity__] * data[price__]

        data[cash__] = data[total__] - data[invested__]

        # this block prevents for goes negative funds after purchasing something
        if data[cash__] < 0:
            selfCloseInterface(
                'No esta permitido comprar cuando el monto es mayor que el saldo de caja, agregue saldo a su caja antes de hacer esta operacion',
                8, 3, 'Compras Denegadas: CAPACIDAD EXCEDIDA',
                'Vaya a:\nMenu Herramientas > Modificar la Inversion\nO presione: CTRL+ALT+M \ny agregue efectivo antes de comprar\n\nO reduzca la cantidad de articulos comprados')
            self.reject()
            return

        # this is the secure entry block
        msg_str = 'comprar {} {} por ${:,.2f} cada uno'.format(data[quantity__], data[item_name__], data[price__])
        if parent.use_secure_entry and not is_bulk:
            confirm = MessageBox(
                lambda: parent.append_data_to_diary(data),
                'Desea confirmar la Entrada?', 'q', 'Confirmar Entrada', msg_str
            )
            confirm.show()
        else:
            parent.append_data_to_diary(data)
            if not is_bulk:
                selfCloseInterface(msg_str, 4, 1, 'Operacion Realizada',
                                   'Cambios Insertados en la Base de Datos')

                self.init_ui(parent)
        return
Пример #8
0
    def apply_form(self, parent):
        # props alias...
        data_len__ = get_template_fields('diary')
        date__ = get_index_in_template('diary', 'date')
        comments__ = get_index_in_template('diary', 'comments')
        amount__ = get_index_in_template('diary', 'amount')
        owner__ = get_index_in_template('diary', 'owner')
        invested__ = get_index_in_template('diary', 'invested_')
        cash__ = get_index_in_template('diary', 'cash_')
        total__ = get_index_in_template('diary', 'total_')
        parts__ = [
            get_index_in_template('diary', 'robert_'),
            get_index_in_template('diary', 'ariadna_')
        ]
        sign__ = -1 if self.ui.extraccionDelMontoCheckBox.isChecked() else 1
        last_row_data__ = crud_driver(parent, 'diary', 'read', {})
        last_row_data = build_data_template() if len(
            last_row_data__) == 0 else last_row_data__[-1]
        last_row_data = build_data_template(
        ) if len(data_len__) > len(last_row_data) else last_row_data
        data = build_data_template()

        data[comments__] = self.ui.comentariosDeCapitalLineEdit.text()
        data[date__] = parent.date_session
        data[amount__] = self.ui.cantidadDeDineroDoubleSpinBox.value() * sign__
        data[
            owner__] = self.ui.nombreDelQueInsertaElDineroComboBox.currentText(
            )
        data[parts__[0]] = last_row_data[parts__[0]]
        data[parts__[1]] = last_row_data[parts__[1]]
        data[parts__[self.ui.nombreDelQueInsertaElDineroComboBox.currentIndex()]] = \
            last_row_data[parts__[self.ui.nombreDelQueInsertaElDineroComboBox.currentIndex()]] + data[amount__]

        # this block is for defunding protection:
        amount___ = float(data[parts__[
            self.ui.nombreDelQueInsertaElDineroComboBox.currentIndex()]])
        if amount___ < 0:
            print('capital extraction denied. No enough funds ')
            selfCloseInterface(
                'No puede extraer $ {:,.2f} del saldo de {}.\nFondos Insuficientes'
                .format(
                    self.ui.cantidadDeDineroDoubleSpinBox.value(),
                    self.ui.nombreDelQueInsertaElDineroComboBox.currentText()),
                5, 3, 'Extraccion Denegada',
                'No esta permitido extraer mas dinero que el total de la parte de un socio '
            )
            return self.clean_form()

        data[invested__] = last_row_data[invested__]
        data[total__] = data[parts__[0]] + data[parts__[1]]
        data[cash__] = data[total__] - data[invested__]

        if parent.use_secure_entry:
            confirm = MessageBox(lambda: parent.append_data_to_diary(data),
                                 'Desea confirmar la Entrada?', 'q',
                                 'Confirmar Entrada',
                                 self.ui.notasDeCapital.text())
            confirm.show()
            return
        else:
            parent.append_data_to_diary(data)
            selfCloseInterface(self.ui.notasDeCapital.text(), 4, 1,
                               'Operacion Realizada',
                               'Cambios Insertados en la Base de Datos')
            return