From d3ae41e94d0c64a32bd41c4bce5d594f736f3e5c Mon Sep 17 00:00:00 2001 From: Javi Date: Thu, 4 Jun 2026 18:03:35 +0200 Subject: [PATCH] Update: DAO refactor, elementTypeToString function, closeDocument, on_buttonValidate_released for definitive code generation --- Makefile | 66 +++++- budgetPro.pro | 15 ++ src/dao/productdao.cpp | 45 +++- src/dao/productdao.h | 8 +- src/elementtype.h | 12 + src/gui/forms/formbudget.cpp | 397 +++++++++++++--------------------- src/gui/forms/formbudget.h | 4 +- src/gui/forms/formproduct.cpp | 88 +++----- src/gui/forms/formthird.cpp | 187 ++++++---------- src/gui/mainwindow.cpp | 12 + src/gui/mainwindow.h | 2 + treeitem.o | Bin 15160 -> 0 bytes 12 files changed, 404 insertions(+), 432 deletions(-) delete mode 100644 treeitem.o diff --git a/Makefile b/Makefile index 20b9a2d..1f7f66d 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/budgetPro.pro b/budgetPro.pro index b4f91dd..2f30a75 100644 --- a/budgetPro.pro +++ b/budgetPro.pro @@ -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 diff --git a/src/dao/productdao.cpp b/src/dao/productdao.cpp index f9f2364..eb7f8aa 100644 --- a/src/dao/productdao.cpp +++ b/src/dao/productdao.cpp @@ -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; } \ No newline at end of file diff --git a/src/dao/productdao.h b/src/dao/productdao.h index e712701..6a39909 100644 --- a/src/dao/productdao.h +++ b/src/dao/productdao.h @@ -6,7 +6,7 @@ #include #include #include -#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 \ No newline at end of file diff --git a/src/elementtype.h b/src/elementtype.h index 08bf677..7933a89 100644 --- a/src/elementtype.h +++ b/src/elementtype.h @@ -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 \ No newline at end of file diff --git a/src/gui/forms/formbudget.cpp b/src/gui/forms/formbudget.cpp index b4f58d5..93d5d26 100644 --- a/src/gui/forms/formbudget.cpp +++ b/src/gui/forms/formbudget.cpp @@ -6,6 +6,7 @@ #include "mapplication.h" #include "../src/elementtype.h" +#include "../dao/elementdao.h" #include "widgetcomboboxpopuptable.h" @@ -18,6 +19,7 @@ #include #include #include +#include "../dao/budgetdao.h" #include "utils/dbutils.h" formBudget::formBudget(QString aID, int amEditMode, QWidget *parent) : @@ -161,185 +163,94 @@ 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 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(); - - // 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(); - for (int i = 0; i < rowCount; 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()); + for (int i = 0; i < rowCount; i++) { + QString elementCode = model->index(i, 1).data().toString(); + if (elementCode.isEmpty()) continue; - if(!qry.exec()) - { - qDebug() << "" << qry.lastError().text(); - continue; - } + 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; + + BudgetDAO::createLine(line); } - dApp->Enterprise().close(); m_changed = false; } @@ -374,98 +285,88 @@ void formBudget::setCellText(QString val, QModelIndex index, int col) bool formBudget::InsertElement(QString ID, QModelIndex index) { - QSqlQuery qry(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 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 > 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(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(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(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); @@ -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() { - // TODO: implementar lógica para botón de porcentaje + insertRowWithType("OT"); // Other } 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() { - // TODO: implementar lógica para botón de mano de obra + insertRowWithType("MO"); // ManPower } void formBudget::onAnyChange() diff --git a/src/gui/forms/formbudget.h b/src/gui/forms/formbudget.h index 5124ac3..ab1f4d0 100644 --- a/src/gui/forms/formbudget.h +++ b/src/gui/forms/formbudget.h @@ -39,13 +39,14 @@ private slots: 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: TreeModel *m_treeModel; @@ -65,6 +66,7 @@ private: void insertRow(); void insertChild(); void removeRow(); + void insertRowWithType(const QString& type); protected: diff --git a/src/gui/forms/formproduct.cpp b/src/gui/forms/formproduct.cpp index 6360082..da34438 100644 --- a/src/gui/forms/formproduct.cpp +++ b/src/gui/forms/formproduct.cpp @@ -9,6 +9,7 @@ #include "itemcomboboxdelegate.h" #include +#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) diff --git a/src/gui/forms/formthird.cpp b/src/gui/forms/formthird.cpp index 8fb80ce..f191597 100644 --- a/src/gui/forms/formthird.cpp +++ b/src/gui/forms/formthird.cpp @@ -5,6 +5,7 @@ #include #include +#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() diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index b62358d..054058f 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -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.")); +} diff --git a/src/gui/mainwindow.h b/src/gui/mainwindow.h index e6edc04..a226e4a 100644 --- a/src/gui/mainwindow.h +++ b/src/gui/mainwindow.h @@ -98,6 +98,8 @@ public slots: private slots: void tabCloseRequested(int index); + void importFIEBDCFile(); + void exportBC3File(); protected: void closeEvent(QCloseEvent *event); diff --git a/treeitem.o b/treeitem.o deleted file mode 100644 index dfe0046ca6cd7f43fead4139b33e46dff9a57e5a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 15160 zcmbVT3v^q>nZDPO9T6Kz4M{Lf3L>bj!$Y+a6RZZhmLtcbpah3FBqapl$V%*u{J@s; zXj5XUD9ha&fe+=JWf!)myW4I#-E!b;Sq|m2G`2$=D1>afq%WG%up46BG%jsZ2&LZd zpF3lXt|g$IbFOFZH~;*v`RAXRt7LCeY-O3QYqIFt=d}ErL^W;Kl6<>?HygC8v_+h@ z67N-bXxznk+;}|V-HZBTqCF4we9^uXb+u?;hWg`psQk`z`GxHHT|Q=dSR(8)*H$ea z37z7@^d&5F(8WR{18+Ywg~Iux`v_Znj19lz z7~Q%x;JIQSS5NS7c9{)MPDk?AF>{BD8SgE>&DnP;Gk(IxW)bnGv1S*lK~BdK$C+b? zmkpnCGX2CE>IdbfQA^)u@95B0&lM5N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