You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
786 lines
30 KiB
786 lines
30 KiB
#include <QtSql>
|
|
#include <QItemSelection>
|
|
#include <QStandardItemModel>
|
|
#include <QMessageBox>
|
|
#include <QDebug>
|
|
#include <QKeyEvent>
|
|
#include <QEvent>
|
|
#include <QDate>
|
|
#include <QTimer>
|
|
|
|
#include "principal.h"
|
|
#include "ui_principal.h"
|
|
|
|
extern struct g_datos p_datos;
|
|
extern QSettings settings;
|
|
|
|
Principal::Principal(QWidget *parent) :
|
|
QMainWindow(parent),
|
|
ui(new Ui::Principal)
|
|
{
|
|
ui->setupUi(this);
|
|
ui->centralWidget->installEventFilter(this);
|
|
db = QSqlDatabase::addDatabase("QPSQL");
|
|
Leo_Settings();
|
|
db.setHostName(settings.value("conexion").toString());
|
|
db.setPort(settings.value("port").toInt());
|
|
db.setDatabaseName(settings.value("dbase").toString());
|
|
db.setUserName(settings.value("user").toString());
|
|
db.setPassword(settings.value("pass").toString());
|
|
db.open();
|
|
|
|
g_flag1=0;
|
|
g_flag2=0;
|
|
|
|
|
|
connect(timer, SIGNAL(timeout()), this, SLOT(Muestra_principal()));
|
|
|
|
Muestra_principal();
|
|
|
|
Leo_config();
|
|
Leo_fecha();
|
|
Leo_situa();
|
|
}
|
|
|
|
Principal::~Principal()
|
|
{
|
|
delete ui;
|
|
}
|
|
|
|
QString Principal::Leo_fecha()
|
|
{
|
|
QDate fnow= QDate::currentDate();
|
|
QString fec_now= fnow.toString("dd/MM/yyyy");
|
|
g_fecha_sql= fnow.toString("yyyy/MM/dd");
|
|
return fec_now;
|
|
}
|
|
|
|
QString Principal::Leo_hora()
|
|
{
|
|
QTime hnow = QTime::currentTime();
|
|
g_hora_sql = hnow.toString("hh:mm:ss");
|
|
return g_hora_sql;
|
|
}
|
|
|
|
void Principal::Leo_Settings()
|
|
{
|
|
/*if(settings.value("conexion", "default").toString() == "default")
|
|
settings.setValue("conexion", "192.168.200.201");
|
|
if(settings.value("port", "default").toString() == "default")
|
|
settings.setValue("port", "5432");
|
|
if(settings.value("dbase", "default").toString() == "default")
|
|
settings.setValue("dbase", "maxi");
|
|
if(settings.value("user", "default").toString() == "default")
|
|
settings.setValue("user", "postgres");
|
|
if(settings.value("pass", "default").toString() == "default")
|
|
settings.setValue("pass", "postgres08");*/
|
|
}
|
|
|
|
|
|
void Principal::Leo_situa()
|
|
{
|
|
QSqlQuery query;
|
|
QString v_sql;
|
|
int num_items=0;
|
|
|
|
v_sql="SELECT codsit,desr FROM general.situa WHERE desr='CF' LIMIT 1; ";
|
|
query.exec(v_sql);
|
|
QSqlRecord rec = query.record();
|
|
num_items=query.size();
|
|
if(num_items>0)
|
|
{
|
|
int nameCol1 = rec.indexOf("codsit");
|
|
int nameCol2 = rec.indexOf("desr");
|
|
query.next();
|
|
|
|
g_codsit = query.value(nameCol1).toString();
|
|
g_desr = query.value(nameCol2).toString();
|
|
busiva(g_codsit);
|
|
}
|
|
}
|
|
|
|
int Principal::busiva( QString p_codsit )
|
|
{
|
|
int v_error, v_i;
|
|
v_error=1;
|
|
v_i=0;
|
|
|
|
QSqlQuery query_select;
|
|
QString v_sql;
|
|
QString v_tiptas, v_forexp, v_tasa1, v_tasa2, v_tasa3, v_tasa4, v_pciasli, v_suslib;
|
|
int row=0;
|
|
int num_items=0;
|
|
QDate fnow= QDate::currentDate();
|
|
fec_now= fnow.toString("dd/MM/yyyy");
|
|
fec_now2=fnow.toString("yyyyMMdd");
|
|
|
|
v_sql="SELECT tiptas, forexp, tasa1, tasa2, tasa3, tasa4, pciasli, suslib FROM general.situa WHERE '"+fec_now+"' >= fecvig AND '"+p_codsit+"' = codsit ORDER BY fecvig DESC LIMIT 1;";
|
|
query_select.exec(v_sql);
|
|
|
|
num_items=query_select.size();
|
|
QSqlRecord rec = query_select.record();
|
|
if( num_items > 0 )
|
|
{
|
|
int nameCol1 = rec.indexOf("tiptas" );
|
|
int nameCol2 = rec.indexOf("forexp" );
|
|
int nameCol3 = rec.indexOf("tasa1" );
|
|
int nameCol4 = rec.indexOf("tasa2" );
|
|
int nameCol5 = rec.indexOf("tasa3" );
|
|
int nameCol6 = rec.indexOf("tasa4" );
|
|
int nameCol7 = rec.indexOf("pciasli");
|
|
int nameCol8 = rec.indexOf("suslib" );
|
|
row=0;
|
|
while (query_select.next())
|
|
{
|
|
v_tiptas = query_select.value(nameCol1).toString();
|
|
v_forexp = query_select.value(nameCol2).toString();
|
|
v_tasa1 = query_select.value(nameCol3).toString();
|
|
v_tasa2 = query_select.value(nameCol4).toString();
|
|
v_tasa3 = query_select.value(nameCol5).toString();
|
|
v_tasa4 = query_select.value(nameCol6).toString();
|
|
v_pciasli= query_select.value(nameCol7).toString();
|
|
v_suslib = query_select.value(nameCol8).toString();
|
|
row++;
|
|
}
|
|
v_error=0;
|
|
}
|
|
|
|
if( v_error == 0 )
|
|
{
|
|
tiptas=v_tiptas;
|
|
forexp=v_forexp;
|
|
tasa1 =v_tasa1.toInt();
|
|
tasa2 =v_tasa2.toInt();
|
|
tasa3 =v_tasa3.toInt();
|
|
tasa4 =v_tasa4.toInt();
|
|
porsus=0;
|
|
}
|
|
return v_error;
|
|
}
|
|
|
|
int Principal::caltas( int p_tiart )
|
|
{
|
|
tasa_iva=0;
|
|
tas1=tas2=tas3=tas4=0;
|
|
int v_error=1;
|
|
|
|
QSqlQuery query_select;
|
|
QString v_sql;
|
|
QString v_valtas1, v_valtas2, v_valtas3, v_valtas4;
|
|
int row=0;
|
|
int num_items=0;
|
|
QDate fnow= QDate::currentDate();
|
|
QString fec_now= fnow.toString("dd/MM/yyyy");
|
|
if( tasa1 != 0 || tasa2 != 0 || tasa3 != 0 || tasa4 != 0 )
|
|
{
|
|
v_sql="SELECT valtas1, valtas2, valtas3, valtas4 FROM general.tasas WHERE '"+fec_now+"' >= fecvig AND '"+QString::number(p_tiart)+"' = tipiva ORDER BY fecvig DESC LIMIT 1;";
|
|
query_select.exec(v_sql);
|
|
num_items=query_select.size();
|
|
QSqlRecord rec = query_select.record();
|
|
if( num_items > 0 )
|
|
{
|
|
int nameCol1 = rec.indexOf("valtas1" );
|
|
int nameCol2 = rec.indexOf("valtas2" );
|
|
int nameCol3 = rec.indexOf("valtas3" );
|
|
int nameCol4 = rec.indexOf("valtas4" );
|
|
row=0;
|
|
while (query_select.next())
|
|
{
|
|
v_valtas1 = query_select.value(nameCol1).toString();
|
|
v_valtas2 = query_select.value(nameCol2).toString();
|
|
v_valtas3 = query_select.value(nameCol3).toString();
|
|
v_valtas4 = query_select.value(nameCol4).toString();
|
|
row++;
|
|
}
|
|
v_error=0;
|
|
}
|
|
}
|
|
if( tasa1 == 1 )
|
|
{
|
|
tas1=v_valtas1.toDouble();
|
|
tasa_iva=v_valtas1.toDouble();;
|
|
}
|
|
if( tasa2 == 1 )
|
|
{
|
|
tas2=v_valtas2.toDouble();
|
|
tasa_iva=v_valtas2.toDouble();;
|
|
}
|
|
if( tasa3 == 1 )
|
|
{
|
|
tas3=v_valtas3.toDouble();
|
|
tasa_iva=v_valtas3.toDouble();;
|
|
}
|
|
if( tasa4 == 1 )
|
|
{
|
|
tas4=v_valtas4.toDouble();
|
|
tasa_iva=v_valtas4.toDouble();;
|
|
}
|
|
return v_error;
|
|
}
|
|
|
|
void Principal::caliva(double impor)
|
|
{
|
|
iva1=impor*tas1/100;
|
|
iva2=impor*tas2/100;
|
|
iva3=impor*tas3/100;
|
|
iva4=impor*tas4/100;
|
|
iva=iva1+iva2+iva3+iva4;
|
|
neto=impor+iva;
|
|
}
|
|
|
|
void Principal::Leo_config()
|
|
{
|
|
QSqlQuery query;
|
|
QSqlQuery query_m;
|
|
QSqlQuery query_o;
|
|
QSqlQuery query_s;
|
|
QSqlQuery query_p;
|
|
QString v_sql;
|
|
QString v_sql_m;
|
|
QString v_sql_o;
|
|
QString v_sql_s;
|
|
QString v_sql_p;
|
|
int num_items=0;
|
|
int num_items_m=0;
|
|
int num_items_o=0;
|
|
int num_items_s=0;
|
|
int num_items_p=0;
|
|
|
|
// v_sql="SELECT g_sucursal,g_tcom,g_ope,g_cliente FROM minor.configuracion;"; LA BASE NO TIENE CLIENTE
|
|
|
|
v_sql="SELECT g_sucursal,g_tcom,g_ope FROM minor.configuracion;";
|
|
query.exec(v_sql);
|
|
QSqlRecord rec = query.record();
|
|
num_items=query.size();
|
|
if(num_items>0)
|
|
{
|
|
int nameCol1 = rec.indexOf("g_sucursal");
|
|
int nameCol2 = rec.indexOf("g_tcom");
|
|
int nameCol3 = rec.indexOf("g_ope");
|
|
//int nameCol4 = rec.indexOf("g_cliente");
|
|
query.next();
|
|
g_suc = query.value(nameCol1).toString();
|
|
g_tcom = query.value(nameCol2).toString();
|
|
g_ope = query.value(nameCol3).toString();
|
|
//g_cliente = query.value(nameCol4).toString();
|
|
}
|
|
v_sql_m="select mos_mvta from forum.mov_sto where mos_tip='"+g_tcom+"' and mos_stip='"+g_ope+"';";
|
|
query_m.exec(v_sql_m);
|
|
QSqlRecord rec_m = query_m.record();
|
|
num_items_m=query_m.size();
|
|
if(num_items_m>0)
|
|
{
|
|
int nameCol1 = rec_m.indexOf("mos_mvta");
|
|
query_m.next();
|
|
g_mos_vta = query_m.value(nameCol1).toString();
|
|
}
|
|
|
|
v_sql_o="select opr_secup from forumpre.oprecio where opr_tvta='"+g_mos_vta+"';";
|
|
query_o.exec(v_sql_o);
|
|
QSqlRecord rec_o = query_o.record();
|
|
num_items_o=query_o.size();
|
|
if(num_items_o>0)
|
|
{
|
|
int nameCol1 = rec_o.indexOf("opr_secup");
|
|
query_o.next();
|
|
g_opr_secup = query_o.value(nameCol1).toString();
|
|
qDebug() << "g_opr_secup" << g_opr_secup;
|
|
QStringList v_secup_list;
|
|
int v_n=g_opr_secup.length();
|
|
g_opr_secup=g_opr_secup.mid(1,v_n-2);
|
|
v_secup_list=g_opr_secup.split(",", QString::SkipEmptyParts);
|
|
v_n=v_secup_list.length();
|
|
for(v_i=0;v_i<v_n;v_i++)
|
|
{
|
|
g_secup[v_i]=v_secup_list.at(v_i).toLatin1().constData();
|
|
}
|
|
}
|
|
v_sql_s="select gps_tlisuc, gps_suc from forumpre.gralsuc where gps_suc='"+g_suc+"';";
|
|
query_s.exec(v_sql_s);
|
|
QSqlRecord rec_s = query_s.record();
|
|
num_items_s=query_s.size();
|
|
if(num_items_s>0)
|
|
{
|
|
int nameCol1 = rec_s.indexOf("gps_tlisuc");
|
|
int nameCol2 = rec_s.indexOf("gps_suc");
|
|
query_s.next();
|
|
g_gps_tlisuc = query_s.value(nameCol1).toString();
|
|
g_gps_suc = query_s.value(nameCol2).toString();
|
|
}
|
|
}
|
|
|
|
int Principal::Busca_Articulo(QString p_codbar, g_datos * p_datos)
|
|
{
|
|
p_datos->g_cod = 0;
|
|
p_datos->g_des = "";
|
|
p_datos->g_iva = "";
|
|
p_datos->g_dep = "";
|
|
p_datos->g_uxb = "";
|
|
p_datos->g_env = 0;
|
|
p_datos->g_medi= "";
|
|
p_datos->g_tpre= "";
|
|
p_datos->g_codb= "";
|
|
p_datos->g_iint= "";
|
|
p_datos->g_datfar= "";
|
|
p_datos->g_cpie= "";
|
|
|
|
QSqlQuery query;
|
|
QString v_sql, v_sql_tip;
|
|
int num_items=0;
|
|
int num_items_tip=0;
|
|
|
|
v_sql="SELECT art_baj,art_cod,bar_cod,art_des,art_desr,art_iva,art_dep,art_bul,art_ustk,art_datfar,art_env,art_medi,bar_uxb,art_coda,art_iin,art_desf FROM forum.articulo INNER JOIN forum.barras on art_cod=bar_art WHERE bar_cod='"+p_codbar+"' AND art_frag!='M' ;";
|
|
|
|
query.exec(v_sql);
|
|
num_items=query.size();
|
|
qDebug() << "v_sql" << v_sql;
|
|
p_datos->g_tprect="0.0";
|
|
|
|
QSqlRecord rec = query.record();
|
|
if( num_items > 0 )
|
|
{
|
|
int nameCol1 = rec.indexOf("art_cod" );
|
|
int nameCol2 = rec.indexOf("art_des" );
|
|
int nameCol3 = rec.indexOf("art_desr");
|
|
int nameCol5 = rec.indexOf("art_iva" );
|
|
int nameCol6 = rec.indexOf("art_dep" );
|
|
int nameCol7 = rec.indexOf("bar_uxb" );//art_bul
|
|
int nameCol8 = rec.indexOf("art_env" );
|
|
int nameCol9 = rec.indexOf("art_ustk");
|
|
int nameCol11= rec.indexOf("bar_cod" );
|
|
int nameCol12= rec.indexOf("art_desf");
|
|
int nameCol13= rec.indexOf("art_iin" );
|
|
int nameCol14= rec.indexOf("art_datfar");
|
|
int nameCol15= rec.indexOf("art_coda");
|
|
|
|
while (query.next())
|
|
{
|
|
p_datos->g_cod = query.value(nameCol1).toLongLong();
|
|
p_datos->g_des = query.value(nameCol2).toString (); //+" "+query.value(nameCol12).toString()).left(30) ;
|
|
p_datos->g_iva = query.value(nameCol5).toString ();
|
|
p_datos->g_dep = query.value(nameCol6).toString ();
|
|
p_datos->g_uxb = query.value(nameCol7).toString ();
|
|
p_datos->g_env = query.value(nameCol8).toLongLong();
|
|
p_datos->g_medi= query.value(nameCol9).toString ();
|
|
p_datos->g_codb= query.value(nameCol11).toString ();
|
|
p_datos->g_iint= query.value(nameCol13).toString ();
|
|
p_datos->g_datfar= query.value(nameCol14).toString();
|
|
p_datos->g_coda = query.value(nameCol15).toString();
|
|
|
|
if(p_datos->g_medi=="1")
|
|
p_datos->g_cpie="1";
|
|
else
|
|
p_datos->g_cpie="0";
|
|
|
|
Leo_fecha();
|
|
Leo_hora();
|
|
g_pre_ofe = 0;
|
|
|
|
for( int v_i=-1; v_i<10; v_i++ )
|
|
{
|
|
QSqlQuery querydpr;
|
|
qDebug() << "v_i" << v_i;
|
|
|
|
if( v_i == -1 )
|
|
{
|
|
v_sql="SELECT dpr_pval, dpr_tpre FROM forumpre.dprecio WHERE dpr_art='"+QString::number(p_datos->g_cod)+"' AND dpr_tli='"+g_gps_tlisuc+"' AND dpr_tpre='3"+g_gps_suc+"' "+
|
|
"AND dpr_fvig IN (SELECT dpr_fvig FROM forumpre.dprecio WHERE dpr_art = '"+QString::number(p_datos->g_cod)+"' AND dpr_tli='"+g_gps_tlisuc+"' AND dpr_tpre='3"+g_gps_suc+"' AND dpr_fvig <= '"+g_fecha_sql+"' ORDER BY dpr_fvig desc, dpr_hvig desc LIMIT 1)" +
|
|
"AND dpr_hvig IN (SELECT dpr_hvig FROM forumpre.dprecio WHERE dpr_art = '"+QString::number(p_datos->g_cod)+"' AND dpr_tli='"+g_gps_tlisuc+"' AND dpr_tpre='3"+g_gps_suc+"' AND dpr_fvig <= '"+g_fecha_sql+"' ORDER BY dpr_fvig desc, dpr_hvig desc LIMIT 1)";
|
|
}
|
|
else
|
|
{
|
|
v_sql="SELECT dpr_pval, dpr_tpre FROM forumpre.dprecio WHERE dpr_art='"+QString::number(p_datos->g_cod)+"' AND dpr_tli='"+g_gps_tlisuc+"' AND dpr_tpre='"+g_secup[v_i]+"' "+
|
|
"AND dpr_fvig IN (SELECT dpr_fvig FROM forumpre.dprecio WHERE dpr_art = '"+QString::number(p_datos->g_cod)+"' AND dpr_tli='"+g_gps_tlisuc+"' AND dpr_tpre='"+g_secup[v_i]+"' AND dpr_fvig <= '"+g_fecha_sql+"' ORDER BY dpr_fvig desc, dpr_hvig desc LIMIT 1)" +
|
|
"AND dpr_hvig IN (SELECT dpr_hvig FROM forumpre.dprecio WHERE dpr_art = '"+QString::number(p_datos->g_cod)+"' AND dpr_tli='"+g_gps_tlisuc+"' AND dpr_tpre='"+g_secup[v_i]+"' AND dpr_fvig <= '"+g_fecha_sql+"' ORDER BY dpr_fvig desc, dpr_hvig desc LIMIT 1)";
|
|
}
|
|
querydpr.exec(v_sql);
|
|
num_items=querydpr.size();
|
|
qDebug() << "v_sql" << v_sql;
|
|
p_datos->g_tip_pre=g_secup[v_i]; // tipo de precio
|
|
QSqlRecord rec_p = querydpr.record();
|
|
if( num_items > 0 )
|
|
{
|
|
querydpr.next();
|
|
int nameCol4 = rec_p.indexOf("dpr_pval");
|
|
int nameCol10= rec_p.indexOf("dpr_tpre");// no va
|
|
double v_precio = querydpr.value(nameCol4).toDouble();
|
|
p_datos->g_pre= QString::number(v_precio,'f',2);
|
|
if( p_datos->g_pre != "0.00" )
|
|
{
|
|
p_datos->g_tpre= querydpr.value(nameCol10).toString();
|
|
caltas(p_datos->g_iva.toInt());
|
|
caliva(p_datos->g_pre.toDouble());
|
|
g_prec_iva = neto;
|
|
|
|
QSqlQuery querytip;
|
|
v_sql_tip="SELECT ctp_mvili FROM forumpre.ctippre WHERE ctp_tpre='"+p_datos->g_tip_pre+"' LIMIT 1;";
|
|
qDebug()<< v_sql_tip;
|
|
querytip.exec(v_sql_tip);
|
|
num_items_tip=querytip.size();
|
|
if( num_items_tip > 0 )
|
|
{
|
|
querytip.next();
|
|
qDebug() << "TIPO DE PRECIO: " << querytip.value(0).toInt();
|
|
if(querytip.value(0).toInt() > 0)
|
|
{
|
|
g_pre_ofe = 1;
|
|
}
|
|
}
|
|
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return 2;
|
|
}
|
|
}
|
|
|
|
void Principal::Ingresa_articulo()
|
|
{
|
|
QString v_codbar=ui->label_status->text();
|
|
int v_resu = Busca_Articulo(v_codbar, &p_datos);
|
|
|
|
if(v_resu==2)
|
|
{
|
|
ui->label_status->setText("Artículo no encontrado");
|
|
ui->label_codart->setText("");
|
|
ui->label_codbar->setText("");
|
|
ui->label_desc->setText("");
|
|
ui->label_desc2->setText("");
|
|
ui->label_precio->setText("");
|
|
ui->label_promo->setText("");
|
|
ui->label_prom_valida->setText("");
|
|
g_flag1=0;
|
|
g_flag2=0;
|
|
|
|
timer->setSingleShot(true);
|
|
timer->start(1000);
|
|
}
|
|
else
|
|
{
|
|
Busca_promo(QString::number(p_datos.g_cod), &p_datos);
|
|
Imprime_pantalla();
|
|
}
|
|
}
|
|
|
|
void Principal::Imprime_pantalla()
|
|
{
|
|
g_flag1=0;
|
|
g_flag2=0;
|
|
ui->label_codart->setVisible(true);
|
|
ui->label_codbar->setVisible(true);
|
|
ui->label_desc->setVisible(true);
|
|
ui->label_desc2->setVisible(true);
|
|
ui->label_promo->setVisible(true);
|
|
ui->label_prom_valida->setVisible(true);
|
|
ui->label_status->setVisible(true);
|
|
|
|
ui->label_status->setText("");
|
|
|
|
if (g_pre_ofe == 1)
|
|
{
|
|
ui->label_ofe->setVisible(true);
|
|
ui->label_despofe->setVisible(true);
|
|
ui->label_ofe->setText("$"+QString::number(g_prec_iva,'f',2));
|
|
}
|
|
else
|
|
{
|
|
ui->label_precio->setVisible(true);
|
|
ui->label_despnorm->setVisible(true);
|
|
ui->label_precio->setText("$"+QString::number(g_prec_iva,'f',2));
|
|
}
|
|
|
|
int v_largo = p_datos.g_des.length();
|
|
|
|
if(v_largo>25)
|
|
{
|
|
ui->label_desc->setText(p_datos.g_des.left(25));
|
|
ui->label_desc2->setText(p_datos.g_des.mid(25));
|
|
}
|
|
else
|
|
{
|
|
ui->label_desc->setText(p_datos.g_des);
|
|
}
|
|
|
|
ui->label_codbar->setText("Cod.Barras: "+p_datos.g_codb);
|
|
ui->label_codart->setText("Cod.Int: "+p_datos.g_coda);
|
|
|
|
timer->setSingleShot(true);
|
|
|
|
timer->start(20000);
|
|
}
|
|
|
|
void Principal::Muestra_principal()
|
|
{
|
|
ui->label_codart->setText("");
|
|
ui->label_codbar->setText("");
|
|
ui->label_desc->setText("");
|
|
ui->label_desc2->setText("");
|
|
ui->label_precio->setText("");
|
|
ui->label_ofe->setText("");
|
|
ui->label_promo->setText("");
|
|
ui->label_prom_valida->setText("");
|
|
ui->label_status->setText("");
|
|
|
|
ui->label_codart->setVisible(false);
|
|
ui->label_codbar->setVisible(false);
|
|
ui->label_desc->setVisible(false);
|
|
ui->label_desc2->setVisible(false);
|
|
ui->label_precio->setVisible(false);
|
|
ui->label_despnorm->setVisible(false);
|
|
ui->label_ofe->setVisible(false);
|
|
ui->label_despofe->setVisible(false);
|
|
ui->label_promo->setVisible(false);
|
|
ui->label_prom_valida->setVisible(false);
|
|
ui->label_status->setVisible(false);
|
|
|
|
ui->label_principal->setVisible(true);
|
|
ui->label_imagen->setVisible(true);
|
|
ui->label_principal->setText("Escanee un articulo...");
|
|
|
|
g_startcodbar=0;
|
|
}
|
|
|
|
void Principal::Busca_promo(QString p_cod , g_datos * p_datos)
|
|
{
|
|
QSqlQuery query;
|
|
QString v_sql;
|
|
int num_items=0;
|
|
/*v_sql="SELECT * FROM forumpr1.dpromo join forumpr1.accionpro on dpr_accion = accionpro.acp_accion "
|
|
"WHERE (dpr_art = '"+p_cod+"' or dpr_art = '"+p_cod+"') and acp_fdesde <= '"+g_fecha_sql+"' and acp_fhasta >= '"+g_fecha_sql+"' "
|
|
"and dpr_accion in (SELECT dpr_accion FROM forumpr1.dpromo join forumpr1.accionpro on dpr_accion = accionpro.acp_accion "
|
|
"WHERE acp_fdesde <= '"+g_fecha_sql+"' and acp_fhasta >= '"+g_fecha_sql+"' and (dpr_art = '"+p_cod+"' or dpr_art = '"+p_cod+"') "
|
|
"order by dpr_accion asc, dpr_promo, dpr_item desc limit 1);";*/
|
|
v_sql="SELECT * FROM forumpr1.dpromo join forumpr1.accionpro on dpr_accion = accionpro.acp_accion "
|
|
"join forumpr1.cpromocup on dpr_accion = cpromocup.kpr_accion join minor.configuracion on kpr_suc = configuracion.g_sucursal "
|
|
"WHERE (dpr_art = '"+p_cod+"' or dpr_art = '"+p_cod+"') and acp_fdesde <= '"+g_fecha_sql+"' and acp_fhasta >= '"+g_fecha_sql+"' and kpr_promo = dpr_promo "
|
|
"and dpr_accion in (SELECT dpr_accion FROM forumpr1.dpromo join forumpr1.accionpro on dpr_accion = accionpro.acp_accion "
|
|
"join forumpr1.cpromocup on dpr_accion = cpromocup.kpr_accion join minor.configuracion on kpr_suc = configuracion.g_sucursal "
|
|
"WHERE acp_fdesde <= '"+g_fecha_sql+"' and acp_fhasta >= '"+g_fecha_sql+"' and (dpr_art = '"+p_cod+"' or dpr_art = '"+p_cod+"' and kpr_promo = dpr_promo) "
|
|
"order by dpr_accion asc, dpr_promo, dpr_item desc limit 1);";
|
|
|
|
qDebug()<< "sql_dpromo: "<< v_sql;
|
|
query.exec(v_sql);
|
|
num_items=query.size();
|
|
QSqlRecord rec = query.record();
|
|
if(num_items>0)
|
|
{
|
|
int nameCol1 = rec.indexOf("dpr_promo");
|
|
int nameCol2 = rec.indexOf("dpr_lleva");
|
|
int nameCol3 = rec.indexOf("dpr_paga");
|
|
int nameCol4 = rec.indexOf("dpr_des");
|
|
int nameCol5 = rec.indexOf("acp_accion");
|
|
int nameCol6 = rec.indexOf("acp_fdesde");
|
|
int nameCol7 = rec.indexOf("acp_fhasta");
|
|
while( query.next() )
|
|
{
|
|
QString v_promo = query.value(nameCol1).toString();
|
|
QString v_lleva = query.value(nameCol2).toString();
|
|
QString v_paga = query.value(nameCol3).toString();
|
|
float v_des = query.value(nameCol4).toFloat();
|
|
QString v_accion = query.value(nameCol5).toString();
|
|
QString v_fdesde = query.value(nameCol6).toString();
|
|
QString v_fhasta = query.value(nameCol7).toString();
|
|
|
|
QSqlQuery query_select, query_select2, query_select3;
|
|
QString v_sql1, v_sql2, v_sql3;
|
|
int num_items1=0;
|
|
int num_items2=0;
|
|
int num_items3=0;
|
|
|
|
v_sql1="SELECT * FROM forumpr1.cpromo WHERE cpr_accion = '"+v_accion+"' and cpr_promo = '"+v_promo+"';";
|
|
//qDebug()<< "sql_cpromo: _____________"<< v_sql1;
|
|
|
|
query_select.exec(v_sql1);
|
|
num_items1=query_select.size();
|
|
QSqlRecord rec1 = query_select.record();
|
|
if(num_items1>0)
|
|
{
|
|
int nameCol1 = rec1.indexOf("cpr_tpromo");
|
|
//int nameCol2 = rec1.indexOf("cpr_dpromo");
|
|
while( query_select.next() )
|
|
{
|
|
QString v_tpromo = query_select.value(nameCol1).toString();
|
|
//QString v_dpromo = query_select.value(nameCol2).toString();
|
|
if(v_tpromo=="1" || v_tpromo=="2" || v_tpromo=="3" || v_tpromo=="4" || v_tpromo=="6")
|
|
{
|
|
if(v_tpromo=="1")
|
|
ui->label_promo->setText(ui->label_promo->text()+"\n"+"LLEVA "+v_lleva+" PAGA "+v_paga);
|
|
if(v_tpromo=="2")
|
|
{
|
|
//BUSCA LOS OTROS ARTICULOS DE LA PROMO
|
|
v_sql2="SELECT art_des, dpr_art, dpr_lleva, dpr_yo FROM forumpr1.dpromo, forum.articulo WHERE forum.articulo.art_cod = forumpr1.dpromo.dpr_art AND dpr_accion = '"+v_accion+"' AND dpr_promo = '"+v_promo+"' order by dpr_item;";
|
|
query_select2.exec(v_sql2);
|
|
num_items2=query_select2.size();
|
|
ui->label_promo->setText("LLEVANDO ");//LEER TABLA RPROMO
|
|
if(num_items2>0)
|
|
{
|
|
while( query_select2.next() )
|
|
{
|
|
QString v_descartpromo = query_select2.value(0).toString();
|
|
QString v_artpromo = query_select2.value(1).toString();
|
|
QString v_llevaartpromo = query_select2.value(2).toString();
|
|
QString v_connartpromo = query_select2.value(3).toString();
|
|
//BUSQUEDA DE DESCRIPCION DE ARTICULO
|
|
|
|
if(v_connartpromo == "fin") v_connartpromo = "";
|
|
ui->label_promo->setText(ui->label_promo->text()+"\n"+v_llevaartpromo+" x "+v_descartpromo+" "+v_connartpromo);//LEER TABLA RPROMO
|
|
}
|
|
|
|
}
|
|
//BUSCA EL REGALO
|
|
v_sql3="SELECT forum.articulo.art_des, rpr_art, rpr_regalo FROM forumpr1.rpromo, forum.articulo WHERE forum.articulo.art_cod = rpr_art AND rpr_accion = '"+v_accion+"' AND rpr_promo = '"+v_promo+"' ;";
|
|
query_select3.exec(v_sql3);
|
|
num_items3=query_select3.size();
|
|
ui->label_promo->setText(ui->label_promo->text()+"\n"+"DE REGALO: ");//LEER TABLA RPROMO
|
|
if(num_items3>0)
|
|
{
|
|
if(query_select3.next())
|
|
{
|
|
QString v_desartregalo = query_select3.value(0).toString();
|
|
QString v_artregalo = query_select3.value(1).toString();
|
|
QString v_cantartregalo = query_select3.value(2).toString();
|
|
ui->label_promo->setText(ui->label_promo->text()+"\n"+v_cantartregalo+" x "+v_artregalo+ " " + v_desartregalo);
|
|
}
|
|
}
|
|
|
|
}
|
|
if(v_tpromo=="3")
|
|
ui->label_promo->setText(ui->label_promo->text()+"\n"+"LLEVA SURTIDO "+v_lleva+" PAGA "+v_paga);
|
|
if(v_tpromo=="4")
|
|
ui->label_promo->setText(ui->label_promo->text()+"\n"+"LLEVA "+v_lleva+" DESCUENTO "+QString::number(v_des,'f',2)+"%");
|
|
if(v_tpromo=="6")
|
|
ui->label_promo->setText(ui->label_promo->text()+"\n"+"LLEVA SURTIDO "+v_lleva+" DESCUENTO "+QString::number(v_des,'f',2)+"%");
|
|
|
|
ui->label_prom_valida->setText("Valido desde "+v_fdesde+" hasta "+v_fhasta+" inclusive.");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
QSqlQuery query_select_frac;
|
|
QString v_sql2;
|
|
int num_items=0;
|
|
v_sql2="SELECT art_des, art_frac, art_cumf FROM forum.articulo WHERE forum.articulo.art_frac < 0 AND art_cod = "+p_cod+" ;";
|
|
query_select_frac.exec(v_sql2);
|
|
num_items=query_select_frac.size();
|
|
|
|
|
|
if(num_items>0)
|
|
{
|
|
if(query_select_frac.next())
|
|
{
|
|
QString v_desc = query_select_frac.value(0).toString();
|
|
QString v_frac = query_select_frac.value(1).toString();
|
|
QString v_cumf = query_select_frac.value(2).toString();
|
|
|
|
ui->label_promo->setText(ui->label_promo->text()+"\n"+"LLEVANDO "+v_cumf+" O MAS TIENE UN "+v_frac+"% DE DESCUENTO $ "+ QString::number( (float)g_prec_iva-((float)g_prec_iva*(-1)*v_frac.toFloat()/(float)100) ,'f', 2));//LEER TABLA RPROMO
|
|
qDebug() <<"PRE: "<< g_prec_iva << " DESC: " << (float)g_prec_iva-((float)g_prec_iva*(-1)*v_frac.toFloat()/(float)100);
|
|
ui->label_ofe->setVisible(true);
|
|
ui->label_ofe->setText("$"+QString::number((float)g_prec_iva-((float)g_prec_iva*(-1)*v_frac.toFloat()/(float)100),'f',2));
|
|
ui->label_despofe->setVisible(true);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
bool Principal::eventFilter(QObject *obj, QEvent *event)
|
|
{
|
|
if (obj == (QObject *)ui->centralWidget)
|
|
{
|
|
if ( event->type() == QEvent::KeyRelease )
|
|
{
|
|
QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
|
|
|
|
//qDebug() << "Toque esta tecla: " << keyEvent->key();
|
|
|
|
if(g_startcodbar==0 && keyEvent->key() == 48) //número 0
|
|
{
|
|
g_flag1=1;
|
|
g_startcodbar=1;
|
|
}
|
|
|
|
if(keyEvent->key() == Qt::Key_Enter || keyEvent->key() == 16777220 ) //enter
|
|
{
|
|
if(g_flag1==0)
|
|
{
|
|
g_startcodbar=0;
|
|
if(ui->label_status->text()!="")
|
|
{
|
|
Ingresa_articulo();
|
|
}
|
|
}
|
|
if(g_flag1==1)
|
|
{
|
|
g_codigo="";
|
|
g_startcodbar=1;
|
|
ui->label_status->setVisible(true);
|
|
ui->label_status->setText("Ingrese código de barras");
|
|
ui->label_codart->setText("");
|
|
ui->label_codbar->setText("");
|
|
ui->label_desc->setText("");
|
|
ui->label_desc2->setText("");
|
|
ui->label_precio->setText("");
|
|
ui->label_ofe->setText("");
|
|
ui->label_promo->setText("");
|
|
ui->label_prom_valida->setText("");
|
|
ui->label_precio->setVisible(false);
|
|
ui->label_ofe->setVisible(false);
|
|
ui->label_despofe->setVisible(false);
|
|
ui->label_despnorm->setVisible(false);
|
|
ui->label_principal->setVisible(false);
|
|
ui->label_imagen->setVisible(false);
|
|
g_flag2=1;
|
|
}
|
|
}
|
|
|
|
if(g_startcodbar==0 && keyEvent->key() == 16777275) //F12 (16777275)
|
|
{
|
|
g_codigo="";
|
|
g_startcodbar=1;
|
|
ui->label_status->setVisible(true);
|
|
ui->label_status->setText("Ingrese código de barras");
|
|
ui->label_codart->setText("");
|
|
ui->label_codbar->setText("");
|
|
ui->label_desc->setText("");
|
|
ui->label_desc2->setText("");
|
|
ui->label_precio->setText("");
|
|
ui->label_ofe->setText("");
|
|
ui->label_promo->setText("");
|
|
ui->label_prom_valida->setText("");
|
|
ui->label_precio->setVisible(false);
|
|
ui->label_ofe->setVisible(false);
|
|
ui->label_despofe->setVisible(false);
|
|
ui->label_despnorm->setVisible(false);
|
|
ui->label_principal->setVisible(false);
|
|
ui->label_imagen->setVisible(false);
|
|
g_flag2=1;
|
|
}
|
|
|
|
if(keyEvent->key() == 16777216 || keyEvent->key() == 16777233) //esc o fin
|
|
{
|
|
close();
|
|
}
|
|
|
|
if(keyEvent->key() >= 48 && keyEvent->key() <= 57 && g_startcodbar==1 && g_flag2==1) //TECLADO NUMERICO
|
|
{
|
|
if(g_codigo.count()<=13)
|
|
{
|
|
g_codigo+=keyEvent->text().toUpper();
|
|
ui->label_status->setText(g_codigo);
|
|
g_flag1=0;
|
|
}
|
|
}
|
|
if(keyEvent->key() ==16777219 && g_startcodbar==1)// <-- BORRAR
|
|
{
|
|
g_codigo.chop(1);
|
|
ui->label_status->setText(g_codigo);
|
|
}
|
|
}
|
|
}
|
|
}
|