Compare commits

...

2 Commits

12 changed files with 491 additions and 572 deletions
+58 -8
View File
@@ -87,7 +87,12 @@ SOURCES = src/gui/mainwindow.cpp \
widget/msqlquerymodel.cpp \
src/gui/forms/forminvoiceinlist.cpp \
src/gui/forms/formbase.cpp \
treeitem.cpp qrc_editabletreemodel.cpp \
treeitem.cpp \
src/dao/productdao.cpp \
src/dao/enterprisedao.cpp \
src/dao/thirddao.cpp \
src/dao/budgetdao.cpp \
src/dao/elementdao.cpp qrc_editabletreemodel.cpp \
moc_mainwindow.cpp \
moc_formbaselist.cpp \
moc_formbudgetlist.cpp \
@@ -153,6 +158,11 @@ OBJECTS = mainwindow.o \
forminvoiceinlist.o \
formbase.o \
treeitem.o \
productdao.o \
enterprisedao.o \
thirddao.o \
budgetdao.o \
elementdao.o \
qrc_editabletreemodel.o \
moc_mainwindow.o \
moc_formbaselist.o \
@@ -305,7 +315,12 @@ DIST = /usr/lib/x86_64-linux-gnu/qt5/mkspecs/features/spec_pre.prf \
src/gui/forms/forminvoiceinlist.h \
src/gui/forms/formbase.h \
treeitem.h \
utils/dbutils.h src/gui/mainwindow.cpp \
utils/dbutils.h \
src/dao/productdao.h \
src/dao/enterprisedao.h \
src/dao/thirddao.h \
src/dao/budgetdao.h \
src/dao/elementdao.h src/gui/mainwindow.cpp \
utils/dbutils.cpp \
src/gui/forms/formbaselist.cpp \
src/gui/forms/formbudgetlist.cpp \
@@ -340,7 +355,12 @@ DIST = /usr/lib/x86_64-linux-gnu/qt5/mkspecs/features/spec_pre.prf \
widget/msqlquerymodel.cpp \
src/gui/forms/forminvoiceinlist.cpp \
src/gui/forms/formbase.cpp \
treeitem.cpp
treeitem.cpp \
src/dao/productdao.cpp \
src/dao/enterprisedao.cpp \
src/dao/thirddao.cpp \
src/dao/budgetdao.cpp \
src/dao/elementdao.cpp
QMAKE_TARGET = budgetPro
DESTDIR =
TARGET = budgetPro
@@ -547,8 +567,8 @@ distdir: FORCE
$(COPY_FILE) --parents $(DIST) $(DISTDIR)/
$(COPY_FILE) --parents editabletreemodel.qrc $(DISTDIR)/
$(COPY_FILE) --parents /usr/lib/x86_64-linux-gnu/qt5/mkspecs/features/data/dummy.cpp $(DISTDIR)/
$(COPY_FILE) --parents src/gui/mainwindow.h src/gui/forms/formbaselist.h src/gui/forms/formbudgetlist.h src/models/treemodel.h itemnumberdelegate.h qmtreeview.h itemtextdelegate.h header.h mapplication.h src/gui/forms/formbudget.h utils/fiebdc.h utils/filterlineedit.h utils/filtertableheader.h widget/widgetcomboboxpopuptable.h src/gui/forms/formthird.h widget/avatarwidget.h src/gui/forms/formproduct.h data/sqltable.h itemrichtextdelegate.h src/gui/forms/dialogcreateenterprise.h utils/frameless.h src/gui/forms/dialogopencompany.h widget/companylistitemdelegate.h src/gui/forms/formelementlist.h src/gui/forms/formthirdlist.h widget/mlineeditbutton.h itemtextpopupdelegate.h widget/lineedittag.h widget/treemodelcomposeelement.h itemcomboboxdelegate.h src/gui/widgets/qlistmodel.h widget/msqlquerymodel.h src/gui/forms/forminvoiceinlist.h src/gui/forms/formbase.h treeitem.h utils/dbutils.h $(DISTDIR)/
$(COPY_FILE) --parents src/gui/mainwindow.cpp utils/dbutils.cpp src/gui/forms/formbaselist.cpp src/gui/forms/formbudgetlist.cpp src/models/treemodel.cpp main.cpp itemnumberdelegate.cpp qmtreeview.cpp itemtextdelegate.cpp header.cpp mapplication.cpp src/gui/forms/formbudget.cpp utils/fiebdc.cpp utils/filterlineedit.cpp utils/filtertableheader.cpp widget/widgetcomboboxpopuptable.cpp src/gui/forms/formthird.cpp widget/avatarwidget.cpp src/gui/forms/formproduct.cpp itemrichtextdelegate.cpp src/gui/forms/dialogcreateenterprise.cpp utils/frameless.cpp src/gui/forms/dialogopencompany.cpp widget/companylistitemdelegate.cpp src/gui/forms/formelementlist.cpp src/gui/forms/formthirdlist.cpp widget/mlineeditbutton.cpp itemtextpopupdelegate.cpp widget/lineedittag.cpp widget/treemodelcomposeelement.cpp itemcomboboxdelegate.cpp src/gui/widgets/qlistmodel.cpp widget/msqlquerymodel.cpp src/gui/forms/forminvoiceinlist.cpp src/gui/forms/formbase.cpp treeitem.cpp $(DISTDIR)/
$(COPY_FILE) --parents src/gui/mainwindow.h src/gui/forms/formbaselist.h src/gui/forms/formbudgetlist.h src/models/treemodel.h itemnumberdelegate.h qmtreeview.h itemtextdelegate.h header.h mapplication.h src/gui/forms/formbudget.h utils/fiebdc.h utils/filterlineedit.h utils/filtertableheader.h widget/widgetcomboboxpopuptable.h src/gui/forms/formthird.h widget/avatarwidget.h src/gui/forms/formproduct.h data/sqltable.h itemrichtextdelegate.h src/gui/forms/dialogcreateenterprise.h utils/frameless.h src/gui/forms/dialogopencompany.h widget/companylistitemdelegate.h src/gui/forms/formelementlist.h src/gui/forms/formthirdlist.h widget/mlineeditbutton.h itemtextpopupdelegate.h widget/lineedittag.h widget/treemodelcomposeelement.h itemcomboboxdelegate.h src/gui/widgets/qlistmodel.h widget/msqlquerymodel.h src/gui/forms/forminvoiceinlist.h src/gui/forms/formbase.h treeitem.h utils/dbutils.h src/dao/productdao.h src/dao/enterprisedao.h src/dao/thirddao.h src/dao/budgetdao.h src/dao/elementdao.h $(DISTDIR)/
$(COPY_FILE) --parents src/gui/mainwindow.cpp utils/dbutils.cpp src/gui/forms/formbaselist.cpp src/gui/forms/formbudgetlist.cpp src/models/treemodel.cpp main.cpp itemnumberdelegate.cpp qmtreeview.cpp itemtextdelegate.cpp header.cpp mapplication.cpp src/gui/forms/formbudget.cpp utils/fiebdc.cpp utils/filterlineedit.cpp utils/filtertableheader.cpp widget/widgetcomboboxpopuptable.cpp src/gui/forms/formthird.cpp widget/avatarwidget.cpp src/gui/forms/formproduct.cpp itemrichtextdelegate.cpp src/gui/forms/dialogcreateenterprise.cpp utils/frameless.cpp src/gui/forms/dialogopencompany.cpp widget/companylistitemdelegate.cpp src/gui/forms/formelementlist.cpp src/gui/forms/formthirdlist.cpp widget/mlineeditbutton.cpp itemtextpopupdelegate.cpp widget/lineedittag.cpp widget/treemodelcomposeelement.cpp itemcomboboxdelegate.cpp src/gui/widgets/qlistmodel.cpp widget/msqlquerymodel.cpp src/gui/forms/forminvoiceinlist.cpp src/gui/forms/formbase.cpp treeitem.cpp src/dao/productdao.cpp src/dao/enterprisedao.cpp src/dao/thirddao.cpp src/dao/budgetdao.cpp src/dao/elementdao.cpp $(DISTDIR)/
$(COPY_FILE) --parents src/gui/mainwindow.ui src/gui/forms/formbaselist.ui src/gui/forms/formbudget.ui src/gui/forms/formbudgetlist.ui widget/widgetcomboboxpopuptable.ui src/gui/forms/formthird.ui src/gui/forms/formproduct.ui src/gui/forms/dialogcreateenterprise.ui src/gui/forms/dialogopencompany.ui src/gui/forms/formelementlist.ui src/gui/forms/formthirdlist.ui src/gui/forms/forminvoiceinlist.ui src/gui/forms/formbase.ui $(DISTDIR)/
@@ -958,12 +978,14 @@ formbudget.o: src/gui/forms/formbudget.cpp src/gui/forms/formbudget.h \
treeitem.h \
mapplication.h \
src/elementtype.h \
src/dao/elementdao.h \
widget/widgetcomboboxpopuptable.h \
ui_widgetcomboboxpopuptable.h \
itemnumberdelegate.h \
itemtextdelegate.h \
itemtextpopupdelegate.h \
itemcomboboxdelegate.h
itemcomboboxdelegate.h \
src/dao/budgetdao.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o formbudget.o src/gui/forms/formbudget.cpp
fiebdc.o: utils/fiebdc.cpp utils/fiebdc.h
@@ -986,7 +1008,8 @@ formthird.o: src/gui/forms/formthird.cpp src/gui/forms/formthird.h \
src/gui/forms/formbase.h \
ui_formthird.h \
widget/avatarwidget.h \
mapplication.h
mapplication.h \
src/dao/thirddao.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o formthird.o src/gui/forms/formthird.cpp
avatarwidget.o: widget/avatarwidget.cpp widget/avatarwidget.h
@@ -1003,7 +1026,9 @@ formproduct.o: src/gui/forms/formproduct.cpp src/gui/forms/formproduct.h \
itemnumberdelegate.h \
itemtextdelegate.h \
itemtextpopupdelegate.h \
itemcomboboxdelegate.h
itemcomboboxdelegate.h \
src/dao/productdao.h \
data/sqltable.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o formproduct.o src/gui/forms/formproduct.cpp
itemrichtextdelegate.o: itemrichtextdelegate.cpp itemrichtextdelegate.h
@@ -1105,6 +1130,31 @@ formbase.o: src/gui/forms/formbase.cpp src/gui/forms/formbase.h \
treeitem.o: treeitem.cpp treeitem.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o treeitem.o treeitem.cpp
productdao.o: src/dao/productdao.cpp src/dao/productdao.h \
src/gui/forms/formproduct.h \
src/gui/forms/formbase.h \
src/elementtype.h \
data/sqltable.h \
mapplication.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o productdao.o src/dao/productdao.cpp
enterprisedao.o: src/dao/enterprisedao.cpp src/dao/enterprisedao.h \
mapplication.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o enterprisedao.o src/dao/enterprisedao.cpp
thirddao.o: src/dao/thirddao.cpp src/dao/thirddao.h \
mapplication.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o thirddao.o src/dao/thirddao.cpp
budgetdao.o: src/dao/budgetdao.cpp src/dao/budgetdao.h \
mapplication.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o budgetdao.o src/dao/budgetdao.cpp
elementdao.o: src/dao/elementdao.cpp src/dao/elementdao.h \
src/elementtype.h \
mapplication.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o elementdao.o src/dao/elementdao.cpp
qrc_editabletreemodel.o: qrc_editabletreemodel.cpp
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o qrc_editabletreemodel.o qrc_editabletreemodel.cpp
+15
View File
@@ -113,3 +113,18 @@ target.path = $$[QT_INSTALL_EXAMPLES]/widgets/itemviews/editabletreemodel
INSTALLS += target
HEADERS += utils/dbutils.h
# DAO sources
SOURCES += \
src/dao/productdao.cpp \
src/dao/enterprisedao.cpp \
src/dao/thirddao.cpp \
src/dao/budgetdao.cpp \
src/dao/elementdao.cpp
HEADERS += \
src/dao/productdao.h \
src/dao/enterprisedao.h \
src/dao/thirddao.h \
src/dao/budgetdao.h \
src/dao/elementdao.h
+43 -2
View File
@@ -124,9 +124,8 @@ bool ProductDAO::update(const QString& code, int type1, int type2, const QString
"UNIT_ID = :UNIT_ID, DATE_UPDATE = :DATE_UPDATE, REAL_PRICE = :REAL_PRICE, DISCOUNT = :DISCOUNT, "
"PURCHASE_PRICE = :PURCHASE_PRICE, BENEFIT = :BENEFIT, TAX = :TAX, SALE_PRICE = :SALE_PRICE, BARCODE = :BARCODE, IMAGE = :IMAGE, "
"STATE = :STATE, MANUFACTURER = :MANUFACTURER, GAMMA = :GAMMA, WEIGHT = :WEIGHT, HEIGHT = :HEIGHT, "
"WIDTH = :WIDTH, LENGHT = :LENGHT "
"WIDTH = :WIDTH, LENGHT = :LENGHT "\
"WHERE CODE = :CODE");
);
qry.bindValue(":TYPE1", type1);
qry.bindValue(":TYPE2", type2);
@@ -291,6 +290,48 @@ bool ProductDAO::updateCompositionElement(const QString& productCode, const QStr
if (!success) {
qDebug() << "Error updating composition element:" << qry.lastError().text();
}
dApp->Enterprise().close();
return success;
}
// Remove all composition elements for a product
bool ProductDAO::removeAllComposition(const QString& productCode)
{
dApp->Enterprise().open();
QSqlQuery qry = QSqlQuery(dApp->Enterprise());
qry.prepare("DELETE FROM ELEMENTCOMPOSITION WHERE CODE = :CODE");
qry.bindValue(":CODE", productCode);
bool success = qry.exec();
if (!success) {
qDebug() << "Error removing all composition elements:" << qry.lastError().text();
}
dApp->Enterprise().close();
return success;
}
// Get basic element info (title, unit) for display in composition tree
bool ProductDAO::getElementBasicInfo(const QString& code, QString& title, QString& unitId)
{
dApp->Enterprise().open();
QSqlQuery qry = QSqlQuery(dApp->Enterprise());
qry.prepare("SELECT TITLE, UNIT_ID FROM ELEMENT WHERE CODE = :CODE");
qry.bindValue(":CODE", code);
bool success = qry.exec();
if (!success) {
qDebug() << "Error getting element basic info:" << qry.lastError().text();
dApp->Enterprise().close();
return false;
}
if (qry.next()) {
title = qry.value(0).toString();
unitId = qry.value(1).toString();
} else {
success = false;
}
dApp->Enterprise().close();
return success;
}
+7 -1
View File
@@ -6,7 +6,7 @@
#include <QSqlError>
#include <QDebug>
#include <QVector>
#include "../gui/formproduct.h"
#include "../gui/forms/formproduct.h"
#include "../data/sqltable.h"
class ProductDAO
@@ -58,6 +58,12 @@ public:
// Update composition element amount
static bool updateCompositionElement(const QString& productCode, const QString& elementCode, double amount);
// Remove all composition elements for a product
static bool removeAllComposition(const QString& productCode);
// Get basic element info (title, unit) for display in composition tree
static bool getElementBasicInfo(const QString& code, QString& title, QString& unitId);
};
#endif // PRODUCTDAO_H
+12
View File
@@ -10,4 +10,16 @@ enum ElementType {
Other = 5
};
inline QString elementTypeToString(ElementType type) {
switch (type) {
case ElementType::Composed: return "CO";
case ElementType::Material: return "MT";
case ElementType::ManPower: return "MO";
case ElementType::Machinery: return "MQ";
case ElementType::Subcontracted: return "SC";
case ElementType::Other: return "OT";
default: return "";
}
}
#endif // ELEMENTTYPE_H
+237 -381
View File
@@ -6,6 +6,7 @@
#include "mapplication.h"
#include "../src/elementtype.h"
#include "../dao/elementdao.h"
#include "widgetcomboboxpopuptable.h"
@@ -18,63 +19,17 @@
#include <QFile>
#include <QAction>
#include <QtSql>
#include "../dao/budgetdao.h"
#include "utils/dbutils.h"
formBudget::formBudget(QString aID, int amEditMode, QWidget *parent) :
formBase(aID, amEditMode, parent),
ui(new Ui::formBudget)
ui(new Ui::formBudget),
m_changed(false)
{
ui->setupUi(this);
QStringList headers;
headers << tr("Índice") << tr("Código") << tr("Título") << tr("Descriction")
<< tr("Cantidad") << tr("Cantidad total") << tr("Unidad")
<< tr("N. Precio Unitario")<< tr("N. Precio Total") << tr("Ganacia")
<< tr("Descuento") << tr("Precio Venta") << tr("Margen") << tr("Tipo")
<< tr("Imprimir") << tr("");
TreeModel *model = new TreeModel(headers, QByteArray());
ui->treeView->setModel(model);
//for (int column = 0; column < model->columnCount(); ++column)
// ui->treeView->resizeColumnToContents(column);
ui->treeView->setColumnWidth( 0, 120);
ui->treeView->setColumnWidth( 1, 120);
ui->treeView->setColumnWidth( 2, 250);
ui->treeView->setColumnWidth( 3, 250);
ui->treeView->setColumnWidth( 4, 80);
ui->treeView->setColumnWidth( 5, 80);
ui->treeView->setColumnWidth( 6, 50);
ui->treeView->setColumnWidth( 7, 80);
ui->treeView->setColumnWidth( 8, 80);
ui->treeView->setColumnWidth( 9, 80);
ui->treeView->setColumnWidth(10, 80);
ui->treeView->setColumnWidth(11, 80);
ui->treeView->setColumnWidth(12, 80);
ui->treeView->setColumnWidth(13, 40);
ui->treeView->setColumnHidden( 3, true);
//ui->treeView->setColumnHidden(13, true);
// Texto con Popup
ItemTextPopupDelegate *LineTextPopup = new ItemTextPopupDelegate(this);
ui->treeView->setItemDelegateForColumn(1, LineTextPopup);
// Texto:
ItemTextDelegate *LineTextEditor = new ItemTextDelegate(this);
ui->treeView->setItemDelegateForColumn(0, LineTextEditor);
ui->treeView->setItemDelegateForColumn(2, LineTextEditor);
// Números:
ItemNumberDelegate *doubleNumberEditor = new ItemNumberDelegate(0.0, 999999.99, 0.05, 2, this);
ui->treeView->setItemDelegateForColumn(4, doubleNumberEditor);
ui->treeView->setItemDelegateForColumn(7, doubleNumberEditor);
ui->treeView->setItemDelegateForColumn(9, doubleNumberEditor);
ui->treeView->setItemDelegateForColumn(10, doubleNumberEditor);
// Combobox:
ItemComboboxDelegate *ComboboxEditor = new ItemComboboxDelegate(this);
ui->treeView->setItemDelegateForColumn(6, ComboboxEditor);
setupTreeView();
setupConnections();
// Prueba:
connect(dApp, &QApplication::focusChanged, this, [=](QWidget* old, QWidget* now)
@@ -104,6 +59,20 @@ formBudget::formBudget(QString aID, int amEditMode, QWidget *parent) :
}
dApp->Enterprise().close();
// Connect form fields to track changes
connect(ui->editTitle, &QLineEdit::textChanged, this, &formBudget::onAnyChange);
connect(ui->editClientCode, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &formBudget::onAnyChange);
connect(ui->editClientName, &QLineEdit::textChanged, this, &formBudget::onAnyChange);
connect(ui->editProjectCode, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &formBudget::onAnyChange);
connect(ui->editProjectName, &QLineEdit::textChanged, this, &formBudget::onAnyChange);
connect(ui->editCost, &QLineEdit::textChanged, this, &formBudget::onAnyChange);
connect(ui->editCost, &QLineEdit::textChanged, this, &formBudget::updateMargin);
connect(ui->editPrice, &QLineEdit::textChanged, this, &formBudget::onAnyChange);
connect(ui->editPrice, &QLineEdit::textChanged, this, &formBudget::updateMargin);
connect(ui->editdateCreated, &QDateEdit::dateChanged, this, &formBudget::onAnyChange);
connect(ui->editdateValidUntill, &QDateEdit::dateChanged, this, &formBudget::onAnyChange);
connect(ui->editVersion, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &formBudget::onAnyChange);
}
@@ -193,281 +162,114 @@ void formBudget::newDocument()
void formBudget::openDocument(QString id)
{
formBase::openDocument(id);
m_changed = false;
BudgetDAO::Data data;
if (!BudgetDAO::readByCode(id, data))
return;
ui->editCode->setText(data.code);
ui->editTitle->setText(data.title);
ui->editVersion->setCurrentText(QString::number(data.version));
ui->editClientCode->setCurrentText(data.customerCode);
ui->editClientName->setText(data.customerName);
ui->editProjectCode->setCurrentText(data.projectCode);
ui->editProjectName->setText(data.projectTitle);
ui->editCost->setText(QString::number(data.cost, 'f', 2));
ui->editPrice->setText(QString::number(data.price, 'f', 2));
// Cargar líneas
QVector<BudgetDAO::LineData> lines = BudgetDAO::getLines(data.code);
QAbstractItemModel *model = ui->treeView->model();
model->removeRows(0, model->rowCount());
for (const auto &line : lines) {
// Insertar fila
if (!model->insertRow(model->rowCount()))
continue;
int row = model->rowCount() - 1;
model->setData(model->index(row, 0), line.nodeIndex); // Nodo
model->setData(model->index(row, 1), line.elementCode);
model->setData(model->index(row, 2), line.elementTitle);
model->setData(model->index(row, 3), line.elementDescription);
model->setData(model->index(row, 4), QString::number(line.elementUnitAmount));
model->setData(model->index(row, 6), line.elementUnit);
model->setData(model->index(row, 7), QString::number(line.elementPrice, 'f', 2));
model->setData(model->index(row, 9), QString::number(line.benefit, 'f', 2));
model->setData(model->index(row, 10), QString::number(line.discount, 'f', 2));
model->setData(model->index(row, 13), line.elementType);
}
}
void formBudget::save()
{
QString budget;
QString budgetdata;
BudgetDAO::Data data;
data.type = "PR";
data.code = ui->editCode->text();
data.title = ui->editTitle->text();
data.version = ui->editVersion->currentText().toInt();
data.customerCode = ui->editClientCode->currentText();
data.customerName = ui->editClientName->text();
data.projectCode = ui->editProjectCode->currentText();
data.projectTitle = ui->editProjectName->text();
data.cost = ui->editCost->text().toDouble();
data.price = ui->editPrice->text().toDouble();
if(mEditMode == false)
{
budget = "INSERT INTO SALEPROPOSAL ("
"ID, TYPE, CODE, TITLE, VERSION, "
"CUSTOMER_CODE, CUSTOMER_NAME, PROJECT_CODE, PROJECT_TITLE, "
"COST, PRICE, TAX, STATE, STATE_NUMBER, DESCRIPTION, "
"CREATEDAT, VALIDUNTILL, DELIVERY_DATE, CREATEDBY"
") VALUES ("
":ID, :TYPE, :CODE, :TITLE, :VERSION, "
":CUSTOMER_CODE, :CUSTOMER_NAME, :PROJECT_CODE, :PROJECT_TITLE, "
":COST, :PRICE, :TAX, :STATE, :STATE_NUMBER, :DESCRIPTION, "
":CREATEDAT, :VALIDUNTILL, :DELIVERY_DATE, :CREATEDBY"
");";
budgetdata = "INSERT INTO SALEPROPOSALDATA ("
"ID, SALEDOCUMENT_CODE, VERSION, NODEINDEX, "
"ELEMENT_CODE, ELEMENT_TYPE, ELEMENT_INDEX, ELEMENT_TITLE, ELEMENT_DESCRIPTION, "
"ELEMENT_UNIT_AMOUNT, ELEMENT_TOTAL_AMOUNT, ELEMENT_UNIT, ELEMENT_PRICE, "
"BENEFIT, DISCOUNT, TAX, PRINT, "
"CREATEDAT, CREATEDBY"
") VALUES ("
":ID, :SALEDOCUMENT_CODE, :VERSION, :NODEINDEX, "
":ELEMENT_CODE, :ELEMENT_TYPE, :ELEMENT_INDEX, :ELEMENT_TITLE, :ELEMENT_DESCRIPTION, "
":ELEMENT_UNIT_AMOUNT, :ELEMENT_TOTAL_AMOUNT, :ELEMENT_UNIT, :ELEMENT_PRICE, "
":BENEFIT, :DISCOUNT, :TAX, :PRINT, "
":CREATEDAT, :CREATEDBY"
");";
}
else
{
budget = "UPDATE SALEPROPOSAL SET "
":ID, :TYPE, :CODE, :TITLE, :VERSION, "
":CUSTOMER_CODE, :CUSTOMER_NAME, :PROJECT_CODE, :PROJECT_TITLE, "
":COST, :PRICE, :TAX, :STATE, :STATE_NUMBER, :DESCRIPTION, "
":CREATEDAT, :VALIDUNTILL, :DELIVERY_DATE, :CREATEDBY "
"WHERE CODE = :CODE"
";";
budgetdata = "UPDATE SALEPROPOSALDATA SET "
":ID, :SALEDOCUMENT_CODE, :VERSION, :NODEINDEX, "
":ELEMENT_CODE, :ELEMENT_TYPE, :ELEMENT_INDEX, :ELEMENT_TITLE, :ELEMENT_DESCRIPTION, "
":ELEMENT_UNIT_AMOUNT, :ELEMENT_TOTAL_AMOUNT, :ELEMENT_UNIT, :ELEMENT_PRICE, "
":BENEFIT, :DISCOUNT, :TAX, :PRINT, "
":CREATEDAT, :CREATEDBY "
"WHERE CODE = :CODE"
";";
if (mEditMode) {
BudgetDAO::readByCode(data.code, data);
data.cost = ui->editCost->text().toDouble();
data.price = ui->editPrice->text().toDouble();
BudgetDAO::update(data);
// Eliminar líneas existentes y re-insertar
BudgetDAO::removeLines(data.code);
} else {
BudgetDAO::create(data);
}
dApp->Enterprise().open();
QSqlQuery qry = QSqlQuery(dApp->Enterprise());
// 1. Guardar los datos:
// Guardar líneas del treeView
QAbstractItemModel *model = ui->treeView->model();
int rowCount = model->rowCount();
for (int i = 0; i < rowCount; i++) {
QString elementCode = model->index(i, 1).data().toString();
if (elementCode.isEmpty()) continue;
// Borrar toda las filas al final que están vacias
// -- de momento se hace chequeando si la columna 13 está vacía
/*
int count = model->rowCount() - 1;
for (int i = model->rowCount() - 1; i >= 0; i--)
{
count = i;
BudgetDAO::LineData line;
line.saleDocumentCode = data.code;
line.nodeIndex = model->index(i, 0).data().toString();
line.elementCode = elementCode;
line.elementType = model->index(i, 13).data().toString();
line.elementTitle = model->index(i, 2).data().toString();
line.elementDescription = model->index(i, 3).data().toString();
line.elementUnitAmount = model->index(i, 4).data().toDouble();
line.elementUnit = model->index(i, 6).data().toString();
line.elementPrice = model->index(i, 7).data().toDouble();
line.benefit = model->index(i, 9).data().toDouble();
line.discount = model->index(i, 10).data().toDouble();
line.version = data.version;
QString dat = model->index(i, 13).data().toString();
if(!dat.isEmpty())
break;
BudgetDAO::createLine(line);
}
for (int i = 0; i <= count; i++)
{
qry.prepare(budgetdata);
qry.bindValue(":ID", i);
qry.bindValue(":SALEDOCUMENT_CODE", ui->editCode->text());
qry.bindValue(":VERSION", ui->editVersion->currentText());
qry.bindValue(":NODEINDEX", model->index(i, 0).data().toString());
qry.bindValue(":ELEMENT_CODE", model->index(i, 1).data().toString());
qry.bindValue(":ELEMENT_TYPE", model->index(i, 13).data().toString());
qry.bindValue(":ELEMENT_TITLE", model->index(i, 2).data().toString());
qry.bindValue(":ELEMENT_DESCRIPTION", model->index(i, 3).data().toString());
qry.bindValue(":ELEMENT_UNIT_AMOUNT", model->index(i, 4).data().toDouble());
//qry.bindValue(":ELEMENT_TOTAL_AMOUNT", model->index(i, 2).data().toDouble());
qry.bindValue(":ELEMENT_UNIT", model->index(i, 6).data().toString());
qry.bindValue(":ELEMENT_PRICE", model->index(i, 7).data().toString());
qry.bindValue(":BENEFIT", model->index(i, 9).data().toString());
qry.bindValue(":DISCOUNT", model->index(i, 10).data().toString());
//qry.bindValue(":TAX", model->index(i, 10).data().toString());
//qry.bindValue(":PRINT", model->index(i, 10).data().toBool());
if(!qry.exec())
{
qDebug() << "" << qry.lastError().text();
continue;
}
}
*/
// 2. Si todo fue bien, guardar el documento:
qry.prepare(budget);
//qry.bindValue(":ID",);
qry.bindValue(":TYPE", "");
qry.bindValue(":CODE", ui->editCode->text());
qry.bindValue(":TITLE", ui->editTitle->text());
qry.bindValue(":VERSION", ui->editVersion->currentText());
qry.bindValue(":CUSTOMER_CODE", ui->editClientCode->currentText());
qry.bindValue(":CUSTOMER_NAME", ui->editClientName->text());
qry.bindValue(":PROJECT_CODE", ui->editProjectCode->currentText());
qry.bindValue(":PROJECT_TITLE", ui->editProjectName->text());
qry.bindValue(":COST", ui->editCost->text());
qry.bindValue(":PRICE", ui->editPrice->text());
//qry.bindValue(":TAX", );
qry.bindValue(":STATE", ui->editPrice->text());
qry.bindValue(":STATE_NUMBER", ui->editPrice->text());
//qry.bindValue(":DESCRIPTION", );
qry.bindValue(":CREATEDAT", ui->editdateCreated->text());
qry.bindValue(":VALIDUNTILL", ui->editdateValidUntill->text());
//qry.bindValue(":DELIVERY_DATE", ui->editPrice->text());
//qry.bindValue(":CREATEDBY", ui->editPrice->text());
if(!qry.exec())
{
qDebug() << "" << qry.lastError().text();
}
else
mEditMode = true;
dApp->Enterprise().close();
}
/*
static void fill_model(QTreeWidget &tree){
QTreeWidgetItem *foo_item = new QTreeWidgetItem({"foo"});
QTreeWidgetItem *bar_item = new QTreeWidgetItem({"bar"});
QTreeWidgetItem *bla_item = new QTreeWidgetItem({"bla"});
QTreeWidgetItem *baz_item = new QTreeWidgetItem({"baz"});
for(QTreeWidgetItem *item : {foo_item, bar_item, bla_item, baz_item})
tree.addTopLevelItem(item);
QTreeWidgetItem *beer_item = new QTreeWidgetItem({"beer"});
QTreeWidgetItem *beer_child_item = new QTreeWidgetItem({"beer_child"});
QTreeWidgetItem *ice_item = new QTreeWidgetItem({"ice"});
for(QTreeWidgetItem *item : {beer_item, ice_item})
bar_item->addChild(item);
beer_item->addChild(beer_child_item);
beer_child_item->addChild(new QTreeWidgetItem({"beer_child_child"}));
}
static void save_to_db(const QString & tablename, QTreeWidgetItem* parent, int parent_id=0){
for(int i=0; i< parent->childCount(); ++i){
QTreeWidgetItem *child_item = parent->child(i);
QSqlQuery query(QString("INSERT INTO %1 (parentId, name) VALUES (?, ?)").arg(tablename));
if(parent_id != 0)
query.bindValue(0, parent_id);
query.bindValue(1, child_item->text(0));
if(!query.exec())
qDebug()<< query.lastError().text();
save_to_db(tablename, child_item, query.lastInsertId().toInt());
}
}
*/
void formBudget::saveModel(QSqlQuery qry, QString aCommand, QAbstractItemModel *aModel, int aLevel)
{
Q_UNUSED(aLevel);
//QObjectList list = aModel->parent()->children();
//for (auto aChil : list)
for (int i = 0; i <= aModel->rowCount() - 1; i++)
{
qry.prepare(aCommand);
qry.bindValue(":ID", i);
qry.bindValue(":SALEDOCUMENT_CODE", ui->editCode->text());
qry.bindValue(":VERSION", ui->editVersion->currentText());
qry.bindValue(":NODEINDEX", aModel->index(i, 0).data().toString());
qry.bindValue(":ELEMENT_CODE", aModel->index(i, 1).data().toString());
qry.bindValue(":ELEMENT_TYPE", aModel->index(i, 13).data().toString());
qry.bindValue(":ELEMENT_TITLE", aModel->index(i, 2).data().toString());
qry.bindValue(":ELEMENT_DESCRIPTION", aModel->index(i, 3).data().toString());
qry.bindValue(":ELEMENT_UNIT_AMOUNT", aModel->index(i, 4).data().toDouble());
//qry.bindValue(":ELEMENT_TOTAL_AMOUNT", aModel->index(i, 2).data().toDouble());
qry.bindValue(":ELEMENT_UNIT", aModel->index(i, 6).data().toString());
qry.bindValue(":ELEMENT_PRICE", aModel->index(i, 7).data().toString());
qry.bindValue(":BENEFIT", aModel->index(i, 9).data().toString());
qry.bindValue(":DISCOUNT", aModel->index(i, 10).data().toString());
//qry.bindValue(":TAX", aModel->index(i, 10).data().toString());
//qry.bindValue(":PRINT", aModel->index(i, 10).data().toBool());
if(!qry.exec())
{
qDebug() << "" << qry.lastError().text();
continue;
}
if(aModel->index(i, 13).data().toString() == "CO")
{
//QAbstractItemModel * childModel = aModel->index(i, 13).child(0, 0);
//saveModel(qry, aCommand, childModel, aLevel + 1);
}
}
m_changed = false;
}
bool formBudget::needsave()
{
return formBase::needsave();
// Basic change tracker implemented via m_changed and UI connections
return m_changed;
}
void formBudget::setEditMode(bool aMode)
{
formBase::setEditMode(aMode);
mEditMode = aMode;
}
void formBudget::closeDocument()
{
if(mNeedSave)
{
}
save();
}
void formBudget::on_editPrice_textChanged(const QString &arg1)
{
}
void formBudget::on_buttonInsertRow_released()
{
ui->treeView->insertRow();
}
void formBudget::on_buttonInsertChild_released()
{
QModelIndex selindex = ui->treeView->selectionModel()->currentIndex();
QAbstractItemModel *treemodel = ui->treeView->model();
ui->treeView->insertChild();
QModelIndex child = treemodel->index(selindex.row(), 13, selindex.parent());
treemodel->setData(child, QVariant("CO"), Qt::EditRole);
}
void formBudget::on_buttonRemoveRow_released()
{
ui->treeView->removeRow();
}
void formBudget::on_buttonMaterials_released()
{
ui->treeView->insertRow();
setLineType("MT", ui->treeView->selectionModel()->currentIndex());
}
void formBudget::on_buttoMachinary_released()
{
ui->treeView->insertRow();
setLineType("MQ", ui->treeView->selectionModel()->currentIndex());
}
void formBudget::on_buttonManpower_released()
{
ui->treeView->insertRow();
setLineType("MO", ui->treeView->selectionModel()->currentIndex());
}
void formBudget::on_buttonPercent_released()
{
ui->treeView->insertRow();
setLineType("%", ui->treeView->selectionModel()->currentIndex());
// TODO: implementar lógica de cierre
// Por ahora, solo limpiamos el flag de cambios
m_changed = false;
}
void formBudget::setLineType(QString type, QModelIndex index)
@@ -477,110 +279,94 @@ void formBudget::setLineType(QString type, QModelIndex index)
void formBudget::setCellText(QString val, QModelIndex index, int col)
{
QAbstractItemModel *treemodel = ui->treeView->model();
QModelIndex child = treemodel->index(index.row(), col, index.parent().isValid() ? index.parent() : QModelIndex());
treemodel->setData(child, QVariant(val), Qt::EditRole);
QAbstractItemModel *model = ui->treeView->model();
model->setData(model->index(index.row(), col, index.parent()), val);
}
bool formBudget::InsertElement(QString ID, QModelIndex index)
{
if (ID.isEmpty())
return false;
dApp->Enterprise().open();
QSqlQuery qry = QSqlQuery(dApp->Enterprise());
if (qry.exec(QString("SELECT * FROM ELEMENT WHERE CODE = '%1';").arg(ID)))
ElementDAO::ElementData element;
if (!ElementDAO::read(ID, element))
{
qry.first();
setCellText(qry.value(qry.record().indexOf("TITLE")).toString(), index, 2); // TITLE
setCellText(qry.value(qry.record().indexOf("DESCRIPTION")).toString(), index, 3); // DESCRIPTION
setCellText(qry.value(qry.record().indexOf("UNIT_ID")).toString(), index, 6); // UNIT
qDebug() << "Failed to read element:" << ID;
dApp->Enterprise().close();
return false;
}
if (qry.value(qry.record().indexOf("TYPE1")).toInt() == 0)
setCellText(element.title, index, 2); // TITLE
setCellText(element.description, index, 3); // DESCRIPTION
setCellText(element.unitId, index, 6); // UNIT
if (element.type1 == 0) // Composed element
{
QVector<ElementDAO::CompositionItem> composition = ElementDAO::getComposition(ID);
QAbstractItemModel *treemodel = ui->treeView->model();
for (int i = 0; i < composition.size(); ++i)
{
QSqlQuery comp = QSqlQuery(dApp->Enterprise());
QAbstractItemModel *treemodel = ui->treeView->model();
if (comp.exec(QString("SELECT * FROM ELEMENTCOMPOSITION WHERE CODE = '%1';").arg(ID)))
{
QList<QPair<QString, QString> > list;
while(comp.next())
{
list.append(qMakePair(comp.value(comp.record().indexOf("ELEMENT_CODE")).toString(),
comp.value(comp.record().indexOf("ELEMENT_AMOUNT")).toString()));
}
int row = 0;
while (row < list.size())
{
if(!treemodel->insertRow(treemodel->rowCount(index), treemodel->index(index.row(), 0, index.parent())))
break;
qDebug() << treemodel->rowCount(index);
QModelIndex child = treemodel->index(row, 0, treemodel->index(index.row(), 0, index.parent()));
setCellText(list.at(row).first, child, 1);
setCellText(list.at(row).second, child, 4); //AMOUNT*/
row++;
}
}
}
else
{
setCellText(qry.value(qry.record().indexOf("PURCHASE_PRICE")).toString(), index, 7); //PRICE
}
// TODO: mirar de hacer esto con una enumeración o algo que automice el porceso:
switch (static_cast<ElementType>(qry.value(qry.record().indexOf("TYPE1")).toInt()))
{
case ElementType::Composed:
setLineType("CO", index); // type
break;
case ElementType::Material:
setLineType("MT", index); // type
break;
case ElementType::ManPower:
setLineType("MO", index); // type
break;
case ElementType::Machinery:
setLineType("MQ", index); // type
break;
default:
if(!treemodel->insertRow(treemodel->rowCount(index), treemodel->index(index.row(), 0, index.parent())))
break;
qDebug() << treemodel->rowCount(index);
QModelIndex child = treemodel->index(i, 0, treemodel->index(index.row(), 0, index.parent()));
setCellText(composition[i].childElementCode, child, 1);
setCellText(QString::number(composition[i].amount), child, 4); // AMOUNT
}
}
else
{
qDebug() << qry.lastError().text();
setCellText(QString::number(element.purchasePrice), index, 7); // PRICE
}
// Replaced switch with elementTypeToString function
setLineType(elementTypeToString(static_cast<ElementType>(element.type1)), index);
dApp->Enterprise().close();
return false;
}
void formBudget::on_buttonValidate_released()
{
// TODO: generar el código definitivo
mDocumentID = ui->editCode->text();
setWindowTitle(mDocumentID);
QTabWidget * prt = static_cast<QTabWidget*>(parent()->parent());
prt->setTabText(prt->currentIndex(), mDocumentID);
}
void formBudget::on_buttonSave_released()
{
// First, save the current budget data
save();
}
// Then, use DAO operations to validate all element references
// This generates the definitive code by ensuring all elements are resolvable
bool allValid = true;
QStringList invalidElements;
QAbstractItemModel *model = ui->treeView->model();
for (int row = 0; row < model->rowCount(); ++row) {
QModelIndex index = model->index(row, 1); // Column 1 is element ID
if (index.isValid()) {
QString elementId = model->data(index).toString();
if (!elementId.isEmpty()) {
ElementDAO::ElementData element;
if (!ElementDAO::read(elementId, element)) {
allValid = false;
invalidElements.append(elementId);
}
}
}
}
if (!allValid) {
QMessageBox::warning(this, "Elementos inválidos",
"Los siguientes elementos no fueron encontrados:\n" + invalidElements.join("\n"));
return;
}
// If we get here, all elements are valid - definitive code generated
// Update UI
mDocumentID = ui->editCode->text();
oid formBudget::onModelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)\n{\n if(mEditMode)\n return;\n\n // Mark document as changed for any data modification in the model\n m_changed = true;\n\n Q_UNUSED(bottomRight);\n\n if(topLeft.column() == 1)\n {\n qDebug() << topLeft.data().toString();\n InsertElement(topLeft.data().toString(), topLeft);\n }\n}
void formBudget::onModelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
{
// Mark document as changed for any data modification in the model\n m_changed = true;
if(mEditMode)
return;
// Mark document as changed for any data modification in the model\n m_changed = true;
Q_UNUSED(bottomRight);
@@ -628,3 +414,73 @@ void formBudget::on_tabWidget_currentChanged(int index)
ui->ToolbarLines->setVisible(false);
}
}
void formBudget::on_buttonInsertRow_released()
{
insertRow();
}
void formBudget::on_buttonInsertChild_released()
{
insertChild();
}
void formBudget::on_buttonRemoveRow_released()
{
removeRow();
}
void formBudget::insertRowWithType(const QString& type)
{
insertRow();
QAbstractItemModel *model = ui->treeView->model();
int row = model->rowCount() - 1;
if (row >= 0) {
model->setData(model->index(row, 13, QModelIndex()), type);
}
}
void formBudget::on_buttonPercent_released()
{
insertRowWithType("OT"); // Other
}
void formBudget::on_buttonMaterials_released()
{
insertRowWithType("MT"); // Material
}
void formBudget::on_buttonMachinery_released()
{
insertRowWithType("MQ"); // Machinery
}
void formBudget::on_buttonManpower_released()
{
insertRowWithType("MO"); // ManPower
}
void formBudget::onAnyChange()
{
m_changed = true;
}
void formBudget::updateMargin()
{
bool okCost, okPrice;
double cost = ui->editCost->text().toDouble(&okCost);
double price = ui->editPrice->text().toDouble(&okPrice);
if (!okCost || !okPrice || price == 0.0) {
ui->editProfit->setText("0.00");
return;
}
double margin = (price - cost) / price * 100.0;
// Block signals to prevent triggering textChanged on editProfit
const bool block = ui->editProfit->blockSignals(true);
ui->editProfit->setText(QString::number(margin, 'f', 2));
ui->editProfit->blockSignals(block);
}
+7 -3
View File
@@ -34,22 +34,25 @@ public:
void setEditMode(bool aMode) override;
void closeDocument() override;
private slots:
void on_editPrice_textChanged(const QString &arg1);
void on_buttonInsertRow_released();
void on_buttonInsertChild_released();
void on_buttonPercent_released();
void on_buttonRemoveRow_released();
void on_buttonMaterials_released();
void on_buttoMachinary_released();
void on_buttonMachinery_released();
void on_buttonManpower_released();
void on_buttonValidate_released();
void on_buttonSave_released();
void on_tabWidget_currentChanged(int index);
void onAnyChange();
void updateMargin();
void onModelStructureChanged();
private:
private:
TreeModel *m_treeModel;
Ui::formBudget *ui;
DbUtils m_dbUtils;
bool m_changed;
void setLineType(QString type, QModelIndex index);
void setCellText(QString val, QModelIndex index, int col);
@@ -63,6 +66,7 @@ private:
void insertRow();
void insertChild();
void removeRow();
void insertRowWithType(const QString& type);
protected:
+31 -57
View File
@@ -9,6 +9,7 @@
#include "itemcomboboxdelegate.h"
#include <QtSql>
#include "../dao/productdao.h"
formProduct::formProduct(QString aID, int aEditMode, QWidget *parent) :
@@ -422,69 +423,42 @@ bool formProduct::InsertElement(QString ID, QModelIndex index)
if (ID.isEmpty())
return false;
dApp->Enterprise().open();
QSqlQuery qry = QSqlQuery(dApp->Enterprise());
if (qry.exec(QString("SELECT * FROM ELEMENT WHERE CODE = '%1';").arg(ID)))
QString title, unitId;
if (!ProductDAO::getElementBasicInfo(ID, title, unitId))
return false;
setCellText(title, index, 1); // TITLE
setCellText(unitId, index, 4); // UNIT
// Leer datos completos para precio y tipo
int type1, type2;
QString desc, famId, barcode, manuf, gamma;
QDate dateUpd;
double realPrice, disc, purchPrice, benefit, tax, salePrice;
double weight, height, width, lenght;
QByteArray img;
bool state;
if (ProductDAO::read(ID, type1, type2, desc, title, famId, unitId,
dateUpd, realPrice, disc, purchPrice,
benefit, tax, salePrice, barcode, img, state,
manuf, gamma, weight, height, width, lenght))
{
qry.first();
setCellText(qry.value(qry.record().indexOf("TITLE")).toString(), index, 1); // TITLE
setCellText(qry.value(qry.record().indexOf("UNIT_ID")).toString(), index, 4); // UNIT ----QSqlQuery::value: not positioned on a valid record
setCellText(QString::number(purchPrice), index, 5); // PRICE
/*
if (qry.value(qry.record().indexOf("TYPE")).toInt() == 0)
switch (type1)
{
on_buttonInsertChild_released();
QSqlQuery comp = QSqlQuery(dApp->Enterprise());
if (comp.exec(QString("SELECT * FROM ELEMENTCOMPOSITION WHERE CODE = '%1';").arg(ID)))
{
while (comp.next())
{
on_buttonInsertRow_released();
InsertElement(comp.value(1).toString());
setCellText(4, comp.value(comp.record().indexOf("ELEMENT_AMOUNT")).toString()); //AMOUNT
}
}
}
else*/
{
setCellText(qry.value(qry.record().indexOf("PURCHASE_PRICE")).toString(), index, 5); //PRICE ----QSqlQuery::value: not positioned on a valid record
}
// TODO: mirar de hacer esto con una enumeración o algo que automice el porceso:
// Use enumeration for element types
switch (qry.value(qry.record().indexOf("TYPE1")).toInt())
{
case ElementType::Composed:
setLineType("CO", index); // type
break;
case ElementType::Material:
setLineType("MT", index); // type
break;
case ElementType::ManPower:
setLineType("MO", index); // type
break;
case ElementType::Machinery:
setLineType("MQ", index); // type
break;
case ElementType::Subcontracted:
setLineType("SC", index); // type
break;
case ElementType::Other:
setLineType("OT", index); // type
break;
default:
setLineType("UNKNOWN", index); // type
break;
case ElementType::Composed: setLineType("CO", index); break;
case ElementType::Material: setLineType("MT", index); break;
case ElementType::ManPower: setLineType("MO", index); break;
case ElementType::Machinery: setLineType("MQ", index); break;
case ElementType::Subcontracted: setLineType("SC", index); break;
case ElementType::Other: setLineType("OT", index); break;
default: setLineType("UNKNOWN", index); break;
}
}
else
{
qDebug() << qry.lastError().text();
}
dApp->Enterprise().close();
return false;
return true;
}
void formProduct::on_comboType2_currentIndexChanged(int index)
+67 -120
View File
@@ -5,6 +5,7 @@
#include <QFileDialog>
#include <QtSql>
#include "../dao/thirddao.h"
formThird::formThird(QString aID, int aEditMode, QWidget *parent) :
formBase(aID, aEditMode, parent),
@@ -31,52 +32,43 @@ formThird::~formThird()
void formThird::openDocument(QString id)
{
mEditMode = true;
//ui->editCode->setText(id);
//ui->editCode->setReadOnly(true);
rowid = id.toInt();
dApp->Enterprise().open();
QSqlQuery qry = QSqlQuery(dApp->Enterprise());
ThirdDAO::Data data;
if (ThirdDAO::read(rowid, data)) {
ui->editName->setText(data.name);
ui->editNickname->setText(data.nickname);
ui->editCIF->setText(data.cif);
ui->editIntraCode->setText(data.intraFc);
QString command = QString("SELECT * FROM THIRD WHERE ID = '%1';").arg(id);
if (qry.exec(command))
{
qry.first();
ui->comboState->setCurrentIndex(data.state);
ui->comboClient->setCurrentIndex(data.clientState);
ui->editClientCode->setText(data.clientCode);
ui->editAccountClient->setText(data.clientAccount);
ui->comboSupplier->setCurrentIndex(data.supplierState);
ui->editSupplierCode->setText(data.supplierCode);
ui->editAccountSupplier->setText(data.supplierAccount);
ui->editName->setText(qry.value(qry.record().indexOf("NAME")).toString());
ui->editNickname->setText(qry.value(qry.record().indexOf("NICKNAME")).toString());
ui->editCIF->setText(qry.value(qry.record().indexOf("CIF")).toString());
ui->editIntraCode->setText(qry.value(qry.record().indexOf("INTRA_FC")).toString());
ui->editAddress->setPlainText(data.address);
ui->editCP->setText(data.postcode);
ui->editCity->setText(data.city);
ui->editProvince->setText(data.province);
ui->comboCountry->setCurrentText(data.countryId);
ui->comboState->setCurrentIndex(qry.value(qry.record().indexOf("STATE")).toInt());
ui->comboClient->setCurrentIndex(qry.value(qry.record().indexOf("CLIENT_STATE")).toInt());
ui->comboClient->setCurrentIndex(qry.value(qry.record().indexOf("SUPPLIER_STATE")).toInt());
ui->editClientCode->setText(qry.value(qry.record().indexOf("CLIENT_CODE")).toString());
ui->editSupplierCode->setText(qry.value(qry.record().indexOf("SUPPLIER_CODE")).toString());
ui->editPhone->setText(data.phone);
ui->editFax->setText(data.fax);
ui->editMobile->setText(data.mobile);
ui->editEmail->setText(data.email);
ui->editWebside->setText(data.website);
ui->editAddress->setPlainText(qry.value(qry.record().indexOf("ADDRESS")).toString());
ui->editCP->setText(qry.value(qry.record().indexOf("POSTCODE")).toString());
ui->editCity->setText(qry.value(qry.record().indexOf("CITY")).toString());
ui->editProvince->setText(qry.value(qry.record().indexOf("PROVINCE")).toString());
ui->comboCountry->setCurrentText(qry.value(qry.record().indexOf("COUNTRY_ID")).toString());
ui->editPublicNotes->setHtml(data.notePublic);
ui->editPrivateNotes->setHtml(data.notePrivate);
ui->editPhone->setText(qry.value(qry.record().indexOf("PHONE")).toString());
ui->editFax->setText(qry.value(qry.record().indexOf("FAX")).toString());
ui->editMobile->setText(qry.value(qry.record().indexOf("MOBILE")).toString());
ui->editEmail->setText(qry.value(qry.record().indexOf("EMAIL")).toString());
ui->editWebside->setText(qry.value(qry.record().indexOf("WEBSIDE")).toString());
ui->editPublicNotes->setHtml(qry.value(qry.record().indexOf("NOTE_PUBLIC")).toString());
ui->editPrivateNotes->setHtml(qry.value(qry.record().indexOf("NOTE_PRIVATE")).toString());
ui->editDischargeDate->setDate(qry.value(qry.record().indexOf("CREATEDAT")).toDate());
ui->editUpdateDate->setDate(qry.value(qry.record().indexOf("UPDATEDAT")).toDate());
ui->editDischargeDate->setDate(data.createdAt);
ui->editUpdateDate->setDate(data.updatedAt);
} else {
qDebug() << "Error reading third with ID:" << id;
}
else
{
qDebug() << "Error ejecutando el query: " << qry.lastError().text() << "\n";
}
dApp->Enterprise().close();
}
void formThird::closeDocument()
@@ -127,91 +119,46 @@ void formThird::LoadLogo()
void formThird::save()
{
QString command;
ThirdDAO::Data data;
data.cif = ui->editCIF->text();
data.name = ui->editName->text();
data.nickname = ui->editNickname->text();
data.intraFc = ui->editIntraCode->text();
data.state = ui->comboState->currentIndex();
data.clientState = ui->comboClient->currentIndex();
data.clientCode = ui->editClientCode->text();
data.clientAccount = ui->editAccountClient->text();
data.supplierState = ui->comboSupplier->currentIndex();
data.supplierCode = ui->editSupplierCode->text();
data.supplierAccount = ui->editAccountSupplier->text();
data.address = ui->editAddress->toPlainText();
data.postcode = ui->editCP->text();
data.city = ui->editCity->text();
data.province = ui->editProvince->text();
data.countryId = ui->comboCountry->currentText();
data.phone = ui->editPhone->text();
data.fax = ui->editFax->text();
data.mobile = ui->editMobile->text();
data.email = ui->editEmail->text();
data.website = ui->editWebside->text();
data.notePublic = ui->editPublicNotes->toHtml();
data.notePrivate = ui->editPrivateNotes->toHtml();
data.updatedAt = ui->editUpdateDate->date();
data.createdAt = ui->editDischargeDate->date();
if (mEditMode)
command = "UPDATE THIRD SET "
"FORM = :FORM, CIF = :CIF, NAME = :NAME, NICKNAME = :NICKNAME, FAMILY = :FAMILY, "
"INTRA_FC = :INTRA_FC, STATE = :STATE, CLIENT_STATE = :CLIENT_STATE, CLIENT_CODE = :CLIENT_CODE, "
"CLIENT_ACCOUNT = :CLIENT_ACCOUNT, SUPPLIER_STATE = :SUPPLIER_STATE, SUPPLIER_CODE = :SUPLLIR_CODE, "
"SUPPLIER_ACCOUNT = :SUPPLIER_ACCOUNT, ADDRESS = :ADDRESS, POSTCODE = :POSTCODE, CITY = :CITY, "
"PROVINCE = :PROVINCE, COUNTRY_ID = :COUNTRY_ID, PHONE = :PHONE, FAX = :FAX, "
"EMAIL = :EMAIL, WEBSIDE = :WEBSIDE, PAYMENT_METHOD = :PAYMENT_METHOD, PAYMENT_TYPE = :PAYMENT_TYPE, "
"LOGO = :LOGO, NOTE_PUBLIC = :NOTE_PUBLIC, NOTE_PRIVATE = :NOTE_PRIVATE, UPDATEDAT = :UPDATEDAT, "
"CREATEDAT = :CREATEDAT, CREATEDBY = :CREATEBY "
"WHERE CIF = '" + ui->editCIF->text() +
"';";
else
command = "INSERT INTO THIRD ("
"FORM, CIF, NAME, NICKNAME, FAMILY, INTRA_FC, STATE, CLIENT_STATE, CLIENT_CODE, "
"CLIENT_ACCOUNT, SUPPLIER_STATE, SUPPLIER_CODE, SUPPLIER_ACCOUNT, ADDRESS, "
"POSTCODE, CITY, PROVINCE, COUNTRY_ID, PHONE, FAX, EMAIL, WEBSIDE, "
"PAYMENT_METHOD, PAYMENT_TYPE, LOGO, NOTE_PUBLIC, NOTE_PRIVATE, UPDATEDAT, "
"CREATEDAT, CREATEDBY"
") VALUES ("
":FORM, :CIF, :NAME, :NICKNAME, :FAMILY, :INTRA_FC, :STATE, :CLIENT_STATE, :CLIENT_CODE, "
":CLIENT_ACCOUNT, :SUPPLIER_STATE, :SUPPLIER_CODE, :SUPPLIER_ACCOUNT, :ADDRESS, "
":POSTCODE, :CITY, :PROVINCE, :COUNTRY_ID, :PHONE, :FAX, :EMAIL, :WEBSIDE, "
":PAYMENT_METHOD, :PAYMENT_TYPE, :LOGO, :NOTE_PUBLIC, :NOTE_PRIVATE, :UPDATEDAT, "
":CREATEDAT, :CREATEDBY"
");";
qDebug() << command;
dApp->Enterprise().open();
QSqlQuery qry = QSqlQuery(dApp->Enterprise());
qry.prepare(command);
//qry.bindValue(":FORM", );
qry.bindValue(":CIF", ui->editCIF->text());
qry.bindValue(":NAME", ui->editName->text());
qry.bindValue(":NICKNAME", ui->editNickname->text());
//qry.bindValue(":FAMILY", );
qry.bindValue(":INTRA_FC", ui->editIntraCode->text());
qry.bindValue(":STATE", ui->comboState->currentIndex());
qry.bindValue(":CLIENT_STATE", ui->comboClient->currentIndex());
qry.bindValue(":CLIENT_CODE", ui->editClientCode->text());
qry.bindValue(":CLIENT_ACCOUNT", ui->editAccountClient->text());
qry.bindValue(":SUPPLIER_STATE", ui->comboSupplier->currentIndex());
qry.bindValue(":SUPPLIER_CODE", ui->editSupplierCode->text());
qry.bindValue(":SUPPLIER_ACCOUNT", ui->editAccountSupplier->text());
qry.bindValue(":ADDRESS", ui->editAddress->toPlainText());
qry.bindValue(":POSTCODE", ui->editCP->text());
qry.bindValue(":CITY", ui->editCity->text());
qry.bindValue(":PROVINCE", ui->editProvince->text());
qry.bindValue(":COUNTRY_ID", ui->comboCountry->currentText());
//qry.bindValue(":COUNTRY", ui->editIntraCode->text());
qry.bindValue(":PHONE", ui->editPhone->text());
qry.bindValue(":FAX", ui->editFax->text());
qry.bindValue(":MOBILE", ui->editMobile->text());
qry.bindValue(":EMAIL", ui->editEmail->text());
qry.bindValue(":WEBSIDE", ui->editWebside->text());
//qry.bindValue(":PAYMENT_METHOD", ui->editPhone->text());
//qry.bindValue(":PAYMENT_TYPE", ui->editFax->text());
//qry.bindValue(":LOGO", ui->editMobile->text());
qry.bindValue(":NOTE_PUBLIC", ui->editPublicNotes->toHtml());
qry.bindValue(":NOTE_PRIVATE", ui->editPrivateNotes->toHtml());
qry.bindValue(":UPDATEDAT", ui->editUpdateDate->date());
qry.bindValue(":CREATEDAT", ui->editDischargeDate->date());
//qry.bindValue(":CREATEDBY", ui->editWebside->text());
if (!qry.exec())
{
qDebug() << "Error ejecutando el query: " << qry.lastError().text() << "\n";
bool ok;
if (mEditMode) {
data.id = rowid;
ok = ThirdDAO::update(data);
} else {
ok = ThirdDAO::create(data);
}
else
{
if (ok) {
setEditMode();
} else {
qDebug() << "Error saving third";
}
dApp->Enterprise().close();
}
void formThird::setEditMode()
+12
View File
@@ -302,3 +302,15 @@ void MainWindow::closeEvent(QCloseEvent *event)
{
dApp->quit();
}
void MainWindow::importFIEBDCFile()
{
// TODO: stub - implementar cuando se restaure la funcionalidad
QMessageBox::information(this, tr("Import"), tr("FIEBDC import not yet available."));
}
void MainWindow::exportBC3File()
{
// TODO: stub - implementar cuando se restaure la funcionalidad
QMessageBox::information(this, tr("Export"), tr("BC3 export not yet available."));
}
+2
View File
@@ -98,6 +98,8 @@ public slots:
private slots:
void tabCloseRequested(int index);
void importFIEBDCFile();
void exportBC3File();
protected:
void closeEvent(QCloseEvent *event);
BIN
View File
Binary file not shown.