Skip to content

Commit

Permalink
Merge pull request #4 from Sleepy8/master
Browse files Browse the repository at this point in the history
botoes mudados e bug relatorio arrumados
  • Loading branch information
GabR36 authored Mar 25, 2024
2 parents f396344 + cf272b8 commit ec713ff
Show file tree
Hide file tree
Showing 8 changed files with 454 additions and 333 deletions.
17 changes: 16 additions & 1 deletion alterarproduto.ui
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,29 @@
<string>Alterar Produto - QEstoqueLoja</string>
</property>
<property name="styleSheet">
<string notr="true">AlterarProduto{
<string notr="true">

#AlterarProduto{
background-color: rgb(199, 199, 199);

}
QPushButton{
background-color: rgb(43, 132, 191);
color: rgb(255, 255, 255);
font-size: 15px;
border-radius: 13px;

}

QPushButton:hover{
background-color: rgb(13, 92, 161);
}
QPushButton:pressed{

color: rgb(255, 255, 255);
background-color: rgb(153, 193, 241);
font-size: 15px;
border-radius: 13px;
}
QGroupBox{
background-color:rgb(170, 170, 170);
Expand Down
3 changes: 3 additions & 0 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ void MainWindow::on_Btn_Alterar_clicked()
alterar->janelaPrincipal = this;
alterar->idAlt = productId;
alterar->TrazerInfo(productDesc, productQuant, productPreco, productBarras, productNf);
alterar->setWindowModality(Qt::ApplicationModal);
alterar->show();
}

Expand All @@ -269,6 +270,7 @@ void MainWindow::on_Btn_Venda_clicked()
{
Vendas *vendas = new Vendas;
vendas->janelaPrincipal = this;
vendas->setWindowModality(Qt::ApplicationModal);
vendas->show();
}

Expand All @@ -277,6 +279,7 @@ void MainWindow::on_Btn_Venda_clicked()
void MainWindow::on_Btn_Relatorios_clicked()
{
relatorios *relatorios1 = new relatorios;
relatorios1->setWindowModality(Qt::ApplicationModal);
relatorios1->show();
}

Expand Down
51 changes: 41 additions & 10 deletions mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ color: rgb(255, 255, 255);
font-size: 15px;
border-radius: 13px;

}

QPushButton:hover{
background-color: rgb(13, 92, 161);
}
QPushButton:pressed{

color: rgb(255, 255, 255);
background-color: rgb(153, 193, 241);
font-size: 15px;
border-radius: 13px;
}
QGroupBox{
background-color:rgb(170, 170, 170);
Expand Down Expand Up @@ -115,7 +126,7 @@ background-color:rgb(170, 170, 170);
<widget class="QGroupBox" name="groupBox">
<property name="geometry">
<rect>
<x>20</x>
<x>60</x>
<y>70</y>
<width>341</width>
<height>271</height>
Expand Down Expand Up @@ -236,15 +247,25 @@ font-size: 15px;</string>
<widget class="QPushButton" name="Btn_Venda">
<property name="geometry">
<rect>
<x>50</x>
<x>90</x>
<y>460</y>
<width>281</width>
<height>51</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">
background-color: rgb(33, 105, 149);</string>
<string notr="true">#Btn_Venda{
background-color: rgb(33, 105, 149);

}

#Btn_Venda:hover{
background-color:rgb(03,75,119);

}
#Btn_Venda:pressed{
background-color: rgb(153, 193, 241);
}</string>
</property>
<property name="text">
<string>Venda</string>
Expand All @@ -259,7 +280,7 @@ background-color: rgb(33, 105, 149);</string>
<widget class="QLabel" name="label_5">
<property name="geometry">
<rect>
<x>20</x>
<x>60</x>
<y>0</y>
<width>341</width>
<height>61</height>
Expand All @@ -275,7 +296,7 @@ background-color: rgb(33, 105, 149);</string>
<widget class="QPushButton" name="Btn_Delete">
<property name="geometry">
<rect>
<x>50</x>
<x>90</x>
<y>390</y>
<width>281</width>
<height>31</height>
Expand All @@ -294,7 +315,7 @@ background-color: rgb(33, 105, 149);</string>
<widget class="QPushButton" name="Btn_Alterar">
<property name="geometry">
<rect>
<x>50</x>
<x>90</x>
<y>350</y>
<width>281</width>
<height>31</height>
Expand Down Expand Up @@ -336,15 +357,25 @@ background-color: rgb(33, 105, 149);</string>
<widget class="QPushButton" name="Btn_Relatorios">
<property name="geometry">
<rect>
<x>50</x>
<x>90</x>
<y>530</y>
<width>281</width>
<height>51</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">
background-color: rgb(33, 105, 149);</string>
<string notr="true">#Btn_Relatorios{
background-color: rgb(33, 105, 149);
}
#Btn_Relatorios:hover{
background-color:rgb(03,75,119);
}
#Btn_Relatorios:pressed{

background-color: rgb(153, 193, 241);

}
</string>
</property>
<property name="text">
<string>Relatórios</string>
Expand Down
79 changes: 56 additions & 23 deletions relatorios.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "relatorios.h"
#include "ui_relatorios.h"
#include <QDebug>;
//#include <QDebug>;
#include <QPainter>
#include <QFileDialog>
#include <QPdfWriter>
Expand Down Expand Up @@ -32,59 +32,92 @@ void relatorios::on_Btn_PdfGen_clicked()
return;
}



QSqlQuery query("SELECT * FROM produtos");

QPdfWriter writer(fileName);
writer.setPageSize(QPageSize(QPageSize::A4));
QPainter painter(&writer);
painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing);
painter.setFont(QFont("Arial", 10, QFont::Bold));

// Determinar a altura de uma linha e o espaço disponível na página
int lineHeight = 300; // Altura de uma linha
int availableHeight = writer.height(); // Altura disponível na página
int startY = 1500; // Define a coordenada Y inicial

// Desenha os dados da tabela no PDF
double sumData4 = 0.0;
QImage logo(":/QEstoqueLOja/mkaoyvbl.png");
painter.drawImage(QRect(100, 100, 2000, 400), logo);
painter.drawText(500, 1000, "Dados da Tabela Produtos:");
painter.drawText(1000, 1500, "ID");
painter.drawText(1600, 1500, "Quantidade");
painter.drawText(3000, 1500, "Descrição");
painter.drawText(8500, 1500, "Preço R$");
int row = 1;
painter.setFont(QFont("Arial", 10));
int lineHeight = 300; // Define o espaçamento vertical entre as linhas
int startY = 1500; // Define a coordenada Y inicial
while (query.next()) {
QString data1 = query.value(0).toString(); // id
QString data2 = query.value(1).toString(); // quant
QString data3 = query.value(2).toString(); // desc

QSqlQuery query("SELECT * FROM produtos");

int row2 = 1;
double sumData4 = 0.0;
while(query.next()){
QString data4 = query.value(3).toString(); // preco
double valueData4 = data4.toDouble(); // Converte o valor para double
sumData4 += valueData4; // Adiciona o valor à soma total


++row2;
};

painter.drawText(5000, 1000,"total R$:" + QString::number( sumData4));
painter.drawText(8000, 1000,"total itens:" + QString::number( row2));

QSqlQuery query2("SELECT * FROM produtos");




int row = 1;
// double sumData4 = 0.0;


while (query2.next()) {
QString data1 = query2.value(0).toString(); // id
QString data2 = query2.value(1).toString(); // quant
QString data3 = query2.value(2).toString(); // desc
QString data4 = query2.value(3).toString(); // preco

// Verifica se há espaço suficiente na página atual para desenhar outra linha
if (startY + lineHeight * row > availableHeight) {
// Se não houver, inicie uma nova página
writer.newPage();
startY = 100; // Reinicie a coordenada Y inicial
row = 1; // Reinicie o contador de linha
}

// Desenhe os dados na página atual
painter.drawText(1000, startY + lineHeight * row, data1);
painter.drawText(1600, startY + lineHeight * row, data2);
painter.drawText(3000, startY + lineHeight * row, data3);
painter.drawText(8500, startY + lineHeight * row, data4);

double valueData4 = data4.toDouble(); // Converte o valor para double
sumData4 += valueData4; // Adiciona o valor à soma total

++row;
}
painter.setFont(QFont("Arial", 10, QFont::Bold));
painter.drawText(4000, 1000, "Soma dos preços: R$ " + QString::number(sumData4));
painter.setFont(QFont("Arial", 10));

// // Desenha a quantidade de itens e a soma dos preços apenas na primeira página
// painter.drawText(4000, 1000, "Quantidade de Itens: " + QString::number(totalItems));
// painter.drawText(4000, 1100, "Soma dos preços: R$ " + QString::number(sumData4));

painter.end();

db.close();

// Abre o PDF após a criação
QDesktopServices::openUrl(QUrl::fromLocalFile(fileName));


}



void relatorios::on_Btn_CsvGen_clicked()
{
void relatorios::on_Btn_CsvGen_clicked(){

QString fileName = QFileDialog::getSaveFileName(nullptr, "Salvar Arquivo CSV", "", "Arquivos CSV (*.csv)");

Expand All @@ -108,13 +141,13 @@ void relatorios::on_Btn_CsvGen_clicked()

// Executando a consulta para recuperar os itens da tabela
QSqlQuery query("SELECT * FROM produtos");
out << "ID,Quant,Desc,Preço,CodBarra,NF\n";
out << "ID;Quant;Desc;Preço;CodBarra;NF\n";
while (query.next()) {
// Escrevendo os dados no arquivo CSV
for (int i = 0; i < query.record().count(); ++i) {
out << query.value(i).toString();
if (i != query.record().count() - 1)
out << ","; // Adicionando vírgula para separar os campos
out << ";"; // Adicionando vírgula para separar os campos
}
out << "\n"; // Adicionando uma nova linha após cada registro
}
Expand Down
40 changes: 23 additions & 17 deletions relatorios.ui
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
<property name="styleSheet">
<string notr="true">

#relatorios
{
#relatorios{
background-color: rgb(199, 199, 199);

}
Expand All @@ -33,6 +32,26 @@ color: rgb(255, 255, 255);
font-size: 15px;
border-radius: 13px;

}
QPushButton#Btn_CsvGerar{
font: 700 9pt &quot;Segoe UI&quot;;
background-color: rgb(43, 132, 191);
color: rgb(255, 255, 255);
font-size: 15px;
border-radius: 13px;


}

QPushButton:hover{
background-color: rgb(13, 92, 161);
}
QPushButton:pressed{

color: rgb(255, 255, 255);
background-color: rgb(153, 193, 241);
font-size: 15px;
border-radius: 13px;
}
QGroupBox{
background-color:rgb(170, 170, 170);
Expand Down Expand Up @@ -107,14 +126,7 @@ background-color:rgb(170, 170, 170);
<bool>false</bool>
</property>
<property name="styleSheet">
<string notr="true">font: 700 9pt &quot;Segoe UI&quot;;

background-color: rgb(43, 132, 191);
color: rgb(255, 255, 255);
font-size: 15px;
border-radius: 13px;

</string>
<string notr="true"/>
</property>
<property name="text">
<string>Gerar CSV produtos estoque</string>
Expand All @@ -139,13 +151,7 @@ border-radius: 13px;
</size>
</property>
<property name="styleSheet">
<string notr="true">font: 700 9pt &quot;Segoe UI&quot;;
background-color: rgb(43, 132, 191);
color: rgb(255, 255, 255);
font-size: 15px;
border-radius: 13px;

</string>
<string notr="true"/>
</property>
<property name="text">
<string>Gerar PDF produtos estoque</string>
Expand Down
Loading

0 comments on commit ec713ff

Please sign in to comment.