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 dfe0046..0000000 Binary files a/treeitem.o and /dev/null differ