Update: DAO refactor, elementTypeToString function, closeDocument, on_buttonValidate_released for definitive code generation

This commit is contained in:
Javi
2026-06-04 18:03:35 +02:00
parent f94f34f397
commit d3ae41e94d
12 changed files with 404 additions and 432 deletions
+58 -8
View File
@@ -87,7 +87,12 @@ SOURCES = src/gui/mainwindow.cpp \
widget/msqlquerymodel.cpp \ widget/msqlquerymodel.cpp \
src/gui/forms/forminvoiceinlist.cpp \ src/gui/forms/forminvoiceinlist.cpp \
src/gui/forms/formbase.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_mainwindow.cpp \
moc_formbaselist.cpp \ moc_formbaselist.cpp \
moc_formbudgetlist.cpp \ moc_formbudgetlist.cpp \
@@ -153,6 +158,11 @@ OBJECTS = mainwindow.o \
forminvoiceinlist.o \ forminvoiceinlist.o \
formbase.o \ formbase.o \
treeitem.o \ treeitem.o \
productdao.o \
enterprisedao.o \
thirddao.o \
budgetdao.o \
elementdao.o \
qrc_editabletreemodel.o \ qrc_editabletreemodel.o \
moc_mainwindow.o \ moc_mainwindow.o \
moc_formbaselist.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/forminvoiceinlist.h \
src/gui/forms/formbase.h \ src/gui/forms/formbase.h \
treeitem.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 \ utils/dbutils.cpp \
src/gui/forms/formbaselist.cpp \ src/gui/forms/formbaselist.cpp \
src/gui/forms/formbudgetlist.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 \ widget/msqlquerymodel.cpp \
src/gui/forms/forminvoiceinlist.cpp \ src/gui/forms/forminvoiceinlist.cpp \
src/gui/forms/formbase.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 QMAKE_TARGET = budgetPro
DESTDIR = DESTDIR =
TARGET = budgetPro TARGET = budgetPro
@@ -547,8 +567,8 @@ distdir: FORCE
$(COPY_FILE) --parents $(DIST) $(DISTDIR)/ $(COPY_FILE) --parents $(DIST) $(DISTDIR)/
$(COPY_FILE) --parents editabletreemodel.qrc $(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 /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.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 $(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)/ $(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 \ treeitem.h \
mapplication.h \ mapplication.h \
src/elementtype.h \ src/elementtype.h \
src/dao/elementdao.h \
widget/widgetcomboboxpopuptable.h \ widget/widgetcomboboxpopuptable.h \
ui_widgetcomboboxpopuptable.h \ ui_widgetcomboboxpopuptable.h \
itemnumberdelegate.h \ itemnumberdelegate.h \
itemtextdelegate.h \ itemtextdelegate.h \
itemtextpopupdelegate.h \ itemtextpopupdelegate.h \
itemcomboboxdelegate.h itemcomboboxdelegate.h \
src/dao/budgetdao.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o formbudget.o src/gui/forms/formbudget.cpp $(CXX) -c $(CXXFLAGS) $(INCPATH) -o formbudget.o src/gui/forms/formbudget.cpp
fiebdc.o: utils/fiebdc.cpp utils/fiebdc.h 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 \ src/gui/forms/formbase.h \
ui_formthird.h \ ui_formthird.h \
widget/avatarwidget.h \ widget/avatarwidget.h \
mapplication.h mapplication.h \
src/dao/thirddao.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o formthird.o src/gui/forms/formthird.cpp $(CXX) -c $(CXXFLAGS) $(INCPATH) -o formthird.o src/gui/forms/formthird.cpp
avatarwidget.o: widget/avatarwidget.cpp widget/avatarwidget.h 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 \ itemnumberdelegate.h \
itemtextdelegate.h \ itemtextdelegate.h \
itemtextpopupdelegate.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 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o formproduct.o src/gui/forms/formproduct.cpp
itemrichtextdelegate.o: itemrichtextdelegate.cpp itemrichtextdelegate.h 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 treeitem.o: treeitem.cpp treeitem.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o treeitem.o treeitem.cpp $(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 qrc_editabletreemodel.o: qrc_editabletreemodel.cpp
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o 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 INSTALLS += target
HEADERS += utils/dbutils.h 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, " "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, " "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, " "STATE = :STATE, MANUFACTURER = :MANUFACTURER, GAMMA = :GAMMA, WEIGHT = :WEIGHT, HEIGHT = :HEIGHT, "
"WIDTH = :WIDTH, LENGHT = :LENGHT " "WIDTH = :WIDTH, LENGHT = :LENGHT "\
"WHERE CODE = :CODE"); "WHERE CODE = :CODE");
);
qry.bindValue(":TYPE1", type1); qry.bindValue(":TYPE1", type1);
qry.bindValue(":TYPE2", type2); qry.bindValue(":TYPE2", type2);
@@ -291,6 +290,48 @@ bool ProductDAO::updateCompositionElement(const QString& productCode, const QStr
if (!success) { if (!success) {
qDebug() << "Error updating composition element:" << qry.lastError().text(); 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(); dApp->Enterprise().close();
return success; return success;
} }
+7 -1
View File
@@ -6,7 +6,7 @@
#include <QSqlError> #include <QSqlError>
#include <QDebug> #include <QDebug>
#include <QVector> #include <QVector>
#include "../gui/formproduct.h" #include "../gui/forms/formproduct.h"
#include "../data/sqltable.h" #include "../data/sqltable.h"
class ProductDAO class ProductDAO
@@ -58,6 +58,12 @@ public:
// Update composition element amount // Update composition element amount
static bool updateCompositionElement(const QString& productCode, const QString& elementCode, double 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 #endif // PRODUCTDAO_H
+12
View File
@@ -10,4 +10,16 @@ enum ElementType {
Other = 5 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 #endif // ELEMENTTYPE_H
+154 -243
View File
@@ -6,6 +6,7 @@
#include "mapplication.h" #include "mapplication.h"
#include "../src/elementtype.h" #include "../src/elementtype.h"
#include "../dao/elementdao.h"
#include "widgetcomboboxpopuptable.h" #include "widgetcomboboxpopuptable.h"
@@ -18,6 +19,7 @@
#include <QFile> #include <QFile>
#include <QAction> #include <QAction>
#include <QtSql> #include <QtSql>
#include "../dao/budgetdao.h"
#include "utils/dbutils.h" #include "utils/dbutils.h"
formBudget::formBudget(QString aID, int amEditMode, QWidget *parent) : formBudget::formBudget(QString aID, int amEditMode, QWidget *parent) :
@@ -161,185 +163,94 @@ void formBudget::openDocument(QString id)
{ {
formBase::openDocument(id); formBase::openDocument(id);
m_changed = false; 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() void formBudget::save()
{ {
QString budget; BudgetDAO::Data data;
QString budgetdata; 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) if (mEditMode) {
{ BudgetDAO::readByCode(data.code, data);
budget = "INSERT INTO SALEPROPOSAL (" data.cost = ui->editCost->text().toDouble();
"ID, TYPE, CODE, TITLE, VERSION, " data.price = ui->editPrice->text().toDouble();
"CUSTOMER_CODE, CUSTOMER_NAME, PROJECT_CODE, PROJECT_TITLE, " BudgetDAO::update(data);
"COST, PRICE, TAX, STATE, STATE_NUMBER, DESCRIPTION, " // Eliminar líneas existentes y re-insertar
"CREATEDAT, VALIDUNTILL, DELIVERY_DATE, CREATEDBY" BudgetDAO::removeLines(data.code);
") VALUES (" } else {
":ID, :TYPE, :CODE, :TITLE, :VERSION, " BudgetDAO::create(data);
":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"
";";
} }
dApp->Enterprise().open(); // Guardar líneas del treeView
QSqlQuery qry = QSqlQuery(dApp->Enterprise());
// 1. Guardar los datos:
QAbstractItemModel *model = ui->treeView->model(); QAbstractItemModel *model = ui->treeView->model();
// 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;
QString dat = model->index(i, 13).data().toString();
if(!dat.isEmpty())
break;
}
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", );
QSqlQuery qrySave(dApp->Enterprise());
qrySave.prepare(budget);
//qrySave.bindValue(":ID",);
qrySave.bindValue(":TYPE", "");
qrySave.bindValue(":CODE", ui->editCode->text());
qrySave.bindValue(":TITLE", ui->editTitle->text());
qrySave.bindValue(":VERSION", ui->editVersion->currentText());
qrySave.bindValue(":CUSTOMER_CODE", ui->editClientCode->currentText());
qrySave.bindValue(":CUSTOMER_NAME", ui->editClientName->text());
qrySave.bindValue(":PROJECT_CODE", ui->editProjectCode->currentText());
qrySave.bindValue(":PROJECT_TITLE", ui->editProjectName->text());
qrySave.bindValue(":COST", ui->editCost->text());
qrySave.bindValue(":PRICE", ui->editPrice->text());
//qrySave.bindValue(":TAX", );
qrySave.bindValue(":STATE", ui->editPrice->text());
qrySave.bindValue(":STATE_NUMBER", ui->editPrice->text());
//qrySave.bindValue(":DESCRIPTION", );
qrySave.bindValue(":CREATEDAT", ui->editdateCreated->text());
qrySave.bindValue(":VALIDUNTILL", ui->editdateValidUntill->text());
// No hay campo para creado por en la UI, dejamos vacío o NULL según la base de datos
if(!qrySave.exec())
{
qDebug() << "" << qrySave.lastError().text();
dApp->Enterprise().close();
return;
}
// 3. Guardar los datos de las líneas:
int rowCount = model->rowCount(); int rowCount = model->rowCount();
for (int i = 0; i < rowCount; i++) for (int i = 0; i < rowCount; i++) {
{ QString elementCode = model->index(i, 1).data().toString();
qry.prepare(budgetdata); if (elementCode.isEmpty()) continue;
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()) BudgetDAO::LineData line;
{ line.saleDocumentCode = data.code;
qDebug() << "" << qry.lastError().text(); line.nodeIndex = model->index(i, 0).data().toString();
continue; 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;
BudgetDAO::createLine(line);
} }
dApp->Enterprise().close();
m_changed = false; m_changed = false;
} }
@@ -374,98 +285,88 @@ void formBudget::setCellText(QString val, QModelIndex index, int col)
bool formBudget::InsertElement(QString ID, QModelIndex index) bool formBudget::InsertElement(QString ID, QModelIndex index)
{ {
QSqlQuery qry(dApp->Enterprise()); ElementDAO::ElementData element;
if (qry.exec(QString("SELECT * FROM ELEMENT WHERE CODE = '%1';").arg(ID))) if (!ElementDAO::read(ID, element))
{ {
qry.first(); qDebug() << "Failed to read element:" << ID;
setCellText(qry.value(qry.record().indexOf("TITLE")).toString(), index, 2); // TITLE dApp->Enterprise().close();
setCellText(qry.value(qry.record().indexOf("DESCRIPTION")).toString(), index, 3); // DESCRIPTION return false;
setCellText(qry.value(qry.record().indexOf("UNIT_ID")).toString(), index, 6); // UNIT }
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()); if(!treemodel->insertRow(treemodel->rowCount(index), treemodel->index(index.row(), 0, index.parent())))
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:
break; 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 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(); dApp->Enterprise().close();
return false; return false;
} }
void formBudget::on_buttonValidate_released() void formBudget::on_buttonValidate_released()
{ {
// TODO: generar el código definitivo // First, save the current budget data
mDocumentID = ui->editCode->text();
setWindowTitle(mDocumentID);
QTabWidget * prt = static_cast<QTabWidget*>(parent()->parent());
prt->setTabText(prt->currentIndex(), mDocumentID);
}
void formBudget::on_buttonSave_released()
{
save(); 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) 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) if(mEditMode)
return; return;
// Mark document as changed for any data modification in the model\n m_changed = true;
Q_UNUSED(bottomRight); Q_UNUSED(bottomRight);
@@ -531,24 +432,34 @@ void formBudget::on_buttonRemoveRow_released()
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() void formBudget::on_buttonPercent_released()
{ {
// TODO: implementar lógica para botón de porcentaje insertRowWithType("OT"); // Other
} }
void formBudget::on_buttonMaterials_released() void formBudget::on_buttonMaterials_released()
{ {
// TODO: implementar lógica para botón de materiales insertRowWithType("MT"); // Material
} }
void formBudget::on_buttoMachinary_released() void formBudget::on_buttonMachinery_released()
{ {
// TODO: implementar lógica para botón de maquinaria insertRowWithType("MQ"); // Machinery
} }
void formBudget::on_buttonManpower_released() void formBudget::on_buttonManpower_released()
{ {
// TODO: implementar lógica para botón de mano de obra insertRowWithType("MO"); // ManPower
} }
void formBudget::onAnyChange() void formBudget::onAnyChange()
+3 -1
View File
@@ -39,13 +39,14 @@ private slots:
void on_buttonPercent_released(); void on_buttonPercent_released();
void on_buttonRemoveRow_released(); void on_buttonRemoveRow_released();
void on_buttonMaterials_released(); void on_buttonMaterials_released();
void on_buttoMachinary_released(); void on_buttonMachinery_released();
void on_buttonManpower_released(); void on_buttonManpower_released();
void on_buttonValidate_released(); void on_buttonValidate_released();
void on_buttonSave_released(); void on_buttonSave_released();
void on_tabWidget_currentChanged(int index); void on_tabWidget_currentChanged(int index);
void onAnyChange(); void onAnyChange();
void updateMargin(); void updateMargin();
void onModelStructureChanged();
private: private:
TreeModel *m_treeModel; TreeModel *m_treeModel;
@@ -65,6 +66,7 @@ private:
void insertRow(); void insertRow();
void insertChild(); void insertChild();
void removeRow(); void removeRow();
void insertRowWithType(const QString& type);
protected: protected:
+31 -57
View File
@@ -9,6 +9,7 @@
#include "itemcomboboxdelegate.h" #include "itemcomboboxdelegate.h"
#include <QtSql> #include <QtSql>
#include "../dao/productdao.h"
formProduct::formProduct(QString aID, int aEditMode, QWidget *parent) : formProduct::formProduct(QString aID, int aEditMode, QWidget *parent) :
@@ -422,69 +423,42 @@ bool formProduct::InsertElement(QString ID, QModelIndex index)
if (ID.isEmpty()) if (ID.isEmpty())
return false; return false;
dApp->Enterprise().open(); QString title, unitId;
QSqlQuery qry = QSqlQuery(dApp->Enterprise()); if (!ProductDAO::getElementBasicInfo(ID, title, unitId))
if (qry.exec(QString("SELECT * FROM ELEMENT WHERE CODE = '%1';").arg(ID))) 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(QString::number(purchPrice), index, 5); // PRICE
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
/* switch (type1)
if (qry.value(qry.record().indexOf("TYPE")).toInt() == 0)
{ {
on_buttonInsertChild_released(); case ElementType::Composed: setLineType("CO", index); break;
case ElementType::Material: setLineType("MT", index); break;
QSqlQuery comp = QSqlQuery(dApp->Enterprise()); case ElementType::ManPower: setLineType("MO", index); break;
if (comp.exec(QString("SELECT * FROM ELEMENTCOMPOSITION WHERE CODE = '%1';").arg(ID))) case ElementType::Machinery: setLineType("MQ", index); break;
{ case ElementType::Subcontracted: setLineType("SC", index); break;
while (comp.next()) case ElementType::Other: setLineType("OT", index); break;
{ default: setLineType("UNKNOWN", index); break;
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;
} }
} }
else
{
qDebug() << qry.lastError().text();
}
dApp->Enterprise().close(); return true;
return false;
} }
void formProduct::on_comboType2_currentIndexChanged(int index) void formProduct::on_comboType2_currentIndexChanged(int index)
+67 -120
View File
@@ -5,6 +5,7 @@
#include <QFileDialog> #include <QFileDialog>
#include <QtSql> #include <QtSql>
#include "../dao/thirddao.h"
formThird::formThird(QString aID, int aEditMode, QWidget *parent) : formThird::formThird(QString aID, int aEditMode, QWidget *parent) :
formBase(aID, aEditMode, parent), formBase(aID, aEditMode, parent),
@@ -31,52 +32,43 @@ formThird::~formThird()
void formThird::openDocument(QString id) void formThird::openDocument(QString id)
{ {
mEditMode = true; mEditMode = true;
//ui->editCode->setText(id); rowid = id.toInt();
//ui->editCode->setReadOnly(true);
dApp->Enterprise().open(); ThirdDAO::Data data;
QSqlQuery qry = QSqlQuery(dApp->Enterprise()); 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); ui->comboState->setCurrentIndex(data.state);
if (qry.exec(command)) ui->comboClient->setCurrentIndex(data.clientState);
{ ui->editClientCode->setText(data.clientCode);
qry.first(); 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->editAddress->setPlainText(data.address);
ui->editNickname->setText(qry.value(qry.record().indexOf("NICKNAME")).toString()); ui->editCP->setText(data.postcode);
ui->editCIF->setText(qry.value(qry.record().indexOf("CIF")).toString()); ui->editCity->setText(data.city);
ui->editIntraCode->setText(qry.value(qry.record().indexOf("INTRA_FC")).toString()); ui->editProvince->setText(data.province);
ui->comboCountry->setCurrentText(data.countryId);
ui->comboState->setCurrentIndex(qry.value(qry.record().indexOf("STATE")).toInt()); ui->editPhone->setText(data.phone);
ui->comboClient->setCurrentIndex(qry.value(qry.record().indexOf("CLIENT_STATE")).toInt()); ui->editFax->setText(data.fax);
ui->comboClient->setCurrentIndex(qry.value(qry.record().indexOf("SUPPLIER_STATE")).toInt()); ui->editMobile->setText(data.mobile);
ui->editClientCode->setText(qry.value(qry.record().indexOf("CLIENT_CODE")).toString()); ui->editEmail->setText(data.email);
ui->editSupplierCode->setText(qry.value(qry.record().indexOf("SUPPLIER_CODE")).toString()); ui->editWebside->setText(data.website);
ui->editAddress->setPlainText(qry.value(qry.record().indexOf("ADDRESS")).toString()); ui->editPublicNotes->setHtml(data.notePublic);
ui->editCP->setText(qry.value(qry.record().indexOf("POSTCODE")).toString()); ui->editPrivateNotes->setHtml(data.notePrivate);
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->editPhone->setText(qry.value(qry.record().indexOf("PHONE")).toString()); ui->editDischargeDate->setDate(data.createdAt);
ui->editFax->setText(qry.value(qry.record().indexOf("FAX")).toString()); ui->editUpdateDate->setDate(data.updatedAt);
ui->editMobile->setText(qry.value(qry.record().indexOf("MOBILE")).toString()); } else {
ui->editEmail->setText(qry.value(qry.record().indexOf("EMAIL")).toString()); qDebug() << "Error reading third with ID:" << id;
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());
} }
else
{
qDebug() << "Error ejecutando el query: " << qry.lastError().text() << "\n";
}
dApp->Enterprise().close();
} }
void formThird::closeDocument() void formThird::closeDocument()
@@ -127,91 +119,46 @@ void formThird::LoadLogo()
void formThird::save() 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) bool ok;
command = "UPDATE THIRD SET " if (mEditMode) {
"FORM = :FORM, CIF = :CIF, NAME = :NAME, NICKNAME = :NICKNAME, FAMILY = :FAMILY, " data.id = rowid;
"INTRA_FC = :INTRA_FC, STATE = :STATE, CLIENT_STATE = :CLIENT_STATE, CLIENT_CODE = :CLIENT_CODE, " ok = ThirdDAO::update(data);
"CLIENT_ACCOUNT = :CLIENT_ACCOUNT, SUPPLIER_STATE = :SUPPLIER_STATE, SUPPLIER_CODE = :SUPLLIR_CODE, " } else {
"SUPPLIER_ACCOUNT = :SUPPLIER_ACCOUNT, ADDRESS = :ADDRESS, POSTCODE = :POSTCODE, CITY = :CITY, " ok = ThirdDAO::create(data);
"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";
} }
else
{ if (ok) {
setEditMode(); setEditMode();
} else {
qDebug() << "Error saving third";
} }
dApp->Enterprise().close();
} }
void formThird::setEditMode() void formThird::setEditMode()
+12
View File
@@ -302,3 +302,15 @@ void MainWindow::closeEvent(QCloseEvent *event)
{ {
dApp->quit(); 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: private slots:
void tabCloseRequested(int index); void tabCloseRequested(int index);
void importFIEBDCFile();
void exportBC3File();
protected: protected:
void closeEvent(QCloseEvent *event); void closeEvent(QCloseEvent *event);
BIN
View File
Binary file not shown.