Lector de precio desarrollado en Qt
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

2 months ago
  1. #include <QtSql>
  2. #include <QItemSelection>
  3. #include <QStandardItemModel>
  4. #include <QMessageBox>
  5. #include <QDebug>
  6. #include <QKeyEvent>
  7. #include <QEvent>
  8. #include <QDate>
  9. #include <QTimer>
  10. #include "principal.h"
  11. #include "ui_principal.h"
  12. extern struct g_datos p_datos;
  13. extern QSettings settings;
  14. Principal::Principal(QWidget *parent) :
  15. QMainWindow(parent),
  16. ui(new Ui::Principal)
  17. {
  18. ui->setupUi(this);
  19. ui->centralWidget->installEventFilter(this);
  20. db = QSqlDatabase::addDatabase("QPSQL");
  21. Leo_Settings();
  22. db.setHostName(settings.value("conexion").toString());
  23. db.setPort(settings.value("port").toInt());
  24. db.setDatabaseName(settings.value("dbase").toString());
  25. db.setUserName(settings.value("user").toString());
  26. db.setPassword(settings.value("pass").toString());
  27. db.open();
  28. g_flag1=0;
  29. g_flag2=0;
  30. connect(timer, SIGNAL(timeout()), this, SLOT(Muestra_principal()));
  31. Muestra_principal();
  32. Leo_config();
  33. Leo_fecha();
  34. Leo_situa();
  35. }
  36. Principal::~Principal()
  37. {
  38. delete ui;
  39. }
  40. QString Principal::Leo_fecha()
  41. {
  42. QDate fnow= QDate::currentDate();
  43. QString fec_now= fnow.toString("dd/MM/yyyy");
  44. g_fecha_sql= fnow.toString("yyyy/MM/dd");
  45. return fec_now;
  46. }
  47. QString Principal::Leo_hora()
  48. {
  49. QTime hnow = QTime::currentTime();
  50. g_hora_sql = hnow.toString("hh:mm:ss");
  51. return g_hora_sql;
  52. }
  53. void Principal::Leo_Settings()
  54. {
  55. /*if(settings.value("conexion", "default").toString() == "default")
  56. settings.setValue("conexion", "192.168.200.201");
  57. if(settings.value("port", "default").toString() == "default")
  58. settings.setValue("port", "5432");
  59. if(settings.value("dbase", "default").toString() == "default")
  60. settings.setValue("dbase", "maxi");
  61. if(settings.value("user", "default").toString() == "default")
  62. settings.setValue("user", "postgres");
  63. if(settings.value("pass", "default").toString() == "default")
  64. settings.setValue("pass", "postgres08");*/
  65. }
  66. void Principal::Leo_situa()
  67. {
  68. QSqlQuery query;
  69. QString v_sql;
  70. int num_items=0;
  71. v_sql="SELECT codsit,desr FROM general.situa WHERE desr='CF' LIMIT 1; ";
  72. query.exec(v_sql);
  73. QSqlRecord rec = query.record();
  74. num_items=query.size();
  75. if(num_items>0)
  76. {
  77. int nameCol1 = rec.indexOf("codsit");
  78. int nameCol2 = rec.indexOf("desr");
  79. query.next();
  80. g_codsit = query.value(nameCol1).toString();
  81. g_desr = query.value(nameCol2).toString();
  82. busiva(g_codsit);
  83. }
  84. }
  85. int Principal::busiva( QString p_codsit )
  86. {
  87. int v_error, v_i;
  88. v_error=1;
  89. v_i=0;
  90. QSqlQuery query_select;
  91. QString v_sql;
  92. QString v_tiptas, v_forexp, v_tasa1, v_tasa2, v_tasa3, v_tasa4, v_pciasli, v_suslib;
  93. int row=0;
  94. int num_items=0;
  95. QDate fnow= QDate::currentDate();
  96. fec_now= fnow.toString("dd/MM/yyyy");
  97. fec_now2=fnow.toString("yyyyMMdd");
  98. 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;";
  99. query_select.exec(v_sql);
  100. num_items=query_select.size();
  101. QSqlRecord rec = query_select.record();
  102. if( num_items > 0 )
  103. {
  104. int nameCol1 = rec.indexOf("tiptas" );
  105. int nameCol2 = rec.indexOf("forexp" );
  106. int nameCol3 = rec.indexOf("tasa1" );
  107. int nameCol4 = rec.indexOf("tasa2" );
  108. int nameCol5 = rec.indexOf("tasa3" );
  109. int nameCol6 = rec.indexOf("tasa4" );
  110. int nameCol7 = rec.indexOf("pciasli");
  111. int nameCol8 = rec.indexOf("suslib" );
  112. row=0;
  113. while (query_select.next())
  114. {
  115. v_tiptas = query_select.value(nameCol1).toString();
  116. v_forexp = query_select.value(nameCol2).toString();
  117. v_tasa1 = query_select.value(nameCol3).toString();
  118. v_tasa2 = query_select.value(nameCol4).toString();
  119. v_tasa3 = query_select.value(nameCol5).toString();
  120. v_tasa4 = query_select.value(nameCol6).toString();
  121. v_pciasli= query_select.value(nameCol7).toString();
  122. v_suslib = query_select.value(nameCol8).toString();
  123. row++;
  124. }
  125. v_error=0;
  126. }
  127. if( v_error == 0 )
  128. {
  129. tiptas=v_tiptas;
  130. forexp=v_forexp;
  131. tasa1 =v_tasa1.toInt();
  132. tasa2 =v_tasa2.toInt();
  133. tasa3 =v_tasa3.toInt();
  134. tasa4 =v_tasa4.toInt();
  135. porsus=0;
  136. }
  137. return v_error;
  138. }
  139. int Principal::caltas( int p_tiart )
  140. {
  141. tasa_iva=0;
  142. tas1=tas2=tas3=tas4=0;
  143. int v_error=1;
  144. QSqlQuery query_select;
  145. QString v_sql;
  146. QString v_valtas1, v_valtas2, v_valtas3, v_valtas4;
  147. int row=0;
  148. int num_items=0;
  149. QDate fnow= QDate::currentDate();
  150. QString fec_now= fnow.toString("dd/MM/yyyy");
  151. if( tasa1 != 0 || tasa2 != 0 || tasa3 != 0 || tasa4 != 0 )
  152. {
  153. 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;";
  154. query_select.exec(v_sql);
  155. num_items=query_select.size();
  156. QSqlRecord rec = query_select.record();
  157. if( num_items > 0 )
  158. {
  159. int nameCol1 = rec.indexOf("valtas1" );
  160. int nameCol2 = rec.indexOf("valtas2" );
  161. int nameCol3 = rec.indexOf("valtas3" );
  162. int nameCol4 = rec.indexOf("valtas4" );
  163. row=0;
  164. while (query_select.next())
  165. {
  166. v_valtas1 = query_select.value(nameCol1).toString();
  167. v_valtas2 = query_select.value(nameCol2).toString();
  168. v_valtas3 = query_select.value(nameCol3).toString();
  169. v_valtas4 = query_select.value(nameCol4).toString();
  170. row++;
  171. }
  172. v_error=0;
  173. }
  174. }
  175. if( tasa1 == 1 )
  176. {
  177. tas1=v_valtas1.toDouble();
  178. tasa_iva=v_valtas1.toDouble();;
  179. }
  180. if( tasa2 == 1 )
  181. {
  182. tas2=v_valtas2.toDouble();
  183. tasa_iva=v_valtas2.toDouble();;
  184. }
  185. if( tasa3 == 1 )
  186. {
  187. tas3=v_valtas3.toDouble();
  188. tasa_iva=v_valtas3.toDouble();;
  189. }
  190. if( tasa4 == 1 )
  191. {
  192. tas4=v_valtas4.toDouble();
  193. tasa_iva=v_valtas4.toDouble();;
  194. }
  195. return v_error;
  196. }
  197. void Principal::caliva(double impor)
  198. {
  199. iva1=impor*tas1/100;
  200. iva2=impor*tas2/100;
  201. iva3=impor*tas3/100;
  202. iva4=impor*tas4/100;
  203. iva=iva1+iva2+iva3+iva4;
  204. neto=impor+iva;
  205. }
  206. void Principal::Leo_config()
  207. {
  208. QSqlQuery query;
  209. QSqlQuery query_m;
  210. QSqlQuery query_o;
  211. QSqlQuery query_s;
  212. QSqlQuery query_p;
  213. QString v_sql;
  214. QString v_sql_m;
  215. QString v_sql_o;
  216. QString v_sql_s;
  217. QString v_sql_p;
  218. int num_items=0;
  219. int num_items_m=0;
  220. int num_items_o=0;
  221. int num_items_s=0;
  222. int num_items_p=0;
  223. // v_sql="SELECT g_sucursal,g_tcom,g_ope,g_cliente FROM minor.configuracion;"; LA BASE NO TIENE CLIENTE
  224. v_sql="SELECT g_sucursal,g_tcom,g_ope FROM minor.configuracion;";
  225. query.exec(v_sql);
  226. QSqlRecord rec = query.record();
  227. num_items=query.size();
  228. if(num_items>0)
  229. {
  230. int nameCol1 = rec.indexOf("g_sucursal");
  231. int nameCol2 = rec.indexOf("g_tcom");
  232. int nameCol3 = rec.indexOf("g_ope");
  233. //int nameCol4 = rec.indexOf("g_cliente");
  234. query.next();
  235. g_suc = query.value(nameCol1).toString();
  236. g_tcom = query.value(nameCol2).toString();
  237. g_ope = query.value(nameCol3).toString();
  238. //g_cliente = query.value(nameCol4).toString();
  239. }
  240. v_sql_m="select mos_mvta from forum.mov_sto where mos_tip='"+g_tcom+"' and mos_stip='"+g_ope+"';";
  241. query_m.exec(v_sql_m);
  242. QSqlRecord rec_m = query_m.record();
  243. num_items_m=query_m.size();
  244. if(num_items_m>0)
  245. {
  246. int nameCol1 = rec_m.indexOf("mos_mvta");
  247. query_m.next();
  248. g_mos_vta = query_m.value(nameCol1).toString();
  249. }
  250. v_sql_o="select opr_secup from forumpre.oprecio where opr_tvta='"+g_mos_vta+"';";
  251. query_o.exec(v_sql_o);
  252. QSqlRecord rec_o = query_o.record();
  253. num_items_o=query_o.size();
  254. if(num_items_o>0)
  255. {
  256. int nameCol1 = rec_o.indexOf("opr_secup");
  257. query_o.next();
  258. g_opr_secup = query_o.value(nameCol1).toString();
  259. qDebug() << "g_opr_secup" << g_opr_secup;
  260. QStringList v_secup_list;
  261. int v_n=g_opr_secup.length();
  262. g_opr_secup=g_opr_secup.mid(1,v_n-2);
  263. v_secup_list=g_opr_secup.split(",", QString::SkipEmptyParts);
  264. v_n=v_secup_list.length();
  265. for(v_i=0;v_i<v_n;v_i++)
  266. {
  267. g_secup[v_i]=v_secup_list.at(v_i).toLatin1().constData();
  268. }
  269. }
  270. v_sql_s="select gps_tlisuc, gps_suc from forumpre.gralsuc where gps_suc='"+g_suc+"';";
  271. query_s.exec(v_sql_s);
  272. QSqlRecord rec_s = query_s.record();
  273. num_items_s=query_s.size();
  274. if(num_items_s>0)
  275. {
  276. int nameCol1 = rec_s.indexOf("gps_tlisuc");
  277. int nameCol2 = rec_s.indexOf("gps_suc");
  278. query_s.next();
  279. g_gps_tlisuc = query_s.value(nameCol1).toString();
  280. g_gps_suc = query_s.value(nameCol2).toString();
  281. }
  282. }
  283. int Principal::Busca_Articulo(QString p_codbar, g_datos * p_datos)
  284. {
  285. p_datos->g_cod = 0;
  286. p_datos->g_des = "";
  287. p_datos->g_iva = "";
  288. p_datos->g_dep = "";
  289. p_datos->g_uxb = "";
  290. p_datos->g_env = 0;
  291. p_datos->g_medi= "";
  292. p_datos->g_tpre= "";
  293. p_datos->g_codb= "";
  294. p_datos->g_iint= "";
  295. p_datos->g_datfar= "";
  296. p_datos->g_cpie= "";
  297. QSqlQuery query;
  298. QString v_sql, v_sql_tip;
  299. int num_items=0;
  300. int num_items_tip=0;
  301. 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' ;";
  302. query.exec(v_sql);
  303. num_items=query.size();
  304. qDebug() << "v_sql" << v_sql;
  305. p_datos->g_tprect="0.0";
  306. QSqlRecord rec = query.record();
  307. if( num_items > 0 )
  308. {
  309. int nameCol1 = rec.indexOf("art_cod" );
  310. int nameCol2 = rec.indexOf("art_des" );
  311. int nameCol3 = rec.indexOf("art_desr");
  312. int nameCol5 = rec.indexOf("art_iva" );
  313. int nameCol6 = rec.indexOf("art_dep" );
  314. int nameCol7 = rec.indexOf("bar_uxb" );//art_bul
  315. int nameCol8 = rec.indexOf("art_env" );
  316. int nameCol9 = rec.indexOf("art_ustk");
  317. int nameCol11= rec.indexOf("bar_cod" );
  318. int nameCol12= rec.indexOf("art_desf");
  319. int nameCol13= rec.indexOf("art_iin" );
  320. int nameCol14= rec.indexOf("art_datfar");
  321. int nameCol15= rec.indexOf("art_coda");
  322. while (query.next())
  323. {
  324. p_datos->g_cod = query.value(nameCol1).toLongLong();
  325. p_datos->g_des = query.value(nameCol2).toString (); //+" "+query.value(nameCol12).toString()).left(30) ;
  326. p_datos->g_iva = query.value(nameCol5).toString ();
  327. p_datos->g_dep = query.value(nameCol6).toString ();
  328. p_datos->g_uxb = query.value(nameCol7).toString ();
  329. p_datos->g_env = query.value(nameCol8).toLongLong();
  330. p_datos->g_medi= query.value(nameCol9).toString ();
  331. p_datos->g_codb= query.value(nameCol11).toString ();
  332. p_datos->g_iint= query.value(nameCol13).toString ();
  333. p_datos->g_datfar= query.value(nameCol14).toString();
  334. p_datos->g_coda = query.value(nameCol15).toString();
  335. if(p_datos->g_medi=="1")
  336. p_datos->g_cpie="1";
  337. else
  338. p_datos->g_cpie="0";
  339. Leo_fecha();
  340. Leo_hora();
  341. g_pre_ofe = 0;
  342. for( int v_i=-1; v_i<10; v_i++ )
  343. {
  344. QSqlQuery querydpr;
  345. qDebug() << "v_i" << v_i;
  346. if( v_i == -1 )
  347. {
  348. 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+"' "+
  349. "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)" +
  350. "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)";
  351. }
  352. else
  353. {
  354. 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]+"' "+
  355. "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)" +
  356. "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)";
  357. }
  358. querydpr.exec(v_sql);
  359. num_items=querydpr.size();
  360. qDebug() << "v_sql" << v_sql;
  361. p_datos->g_tip_pre=g_secup[v_i]; // tipo de precio
  362. QSqlRecord rec_p = querydpr.record();
  363. if( num_items > 0 )
  364. {
  365. querydpr.next();
  366. int nameCol4 = rec_p.indexOf("dpr_pval");
  367. int nameCol10= rec_p.indexOf("dpr_tpre");// no va
  368. double v_precio = querydpr.value(nameCol4).toDouble();
  369. p_datos->g_pre= QString::number(v_precio,'f',2);
  370. if( p_datos->g_pre != "0.00" )
  371. {
  372. p_datos->g_tpre= querydpr.value(nameCol10).toString();
  373. caltas(p_datos->g_iva.toInt());
  374. caliva(p_datos->g_pre.toDouble());
  375. g_prec_iva = neto;
  376. QSqlQuery querytip;
  377. v_sql_tip="SELECT ctp_mvili FROM forumpre.ctippre WHERE ctp_tpre='"+p_datos->g_tip_pre+"' LIMIT 1;";
  378. qDebug()<< v_sql_tip;
  379. querytip.exec(v_sql_tip);
  380. num_items_tip=querytip.size();
  381. if( num_items_tip > 0 )
  382. {
  383. querytip.next();
  384. qDebug() << "TIPO DE PRECIO: " << querytip.value(0).toInt();
  385. if(querytip.value(0).toInt() > 0)
  386. {
  387. g_pre_ofe = 1;
  388. }
  389. }
  390. break;
  391. }
  392. }
  393. }
  394. }
  395. }
  396. else
  397. {
  398. return 2;
  399. }
  400. }
  401. void Principal::Ingresa_articulo()
  402. {
  403. QString v_codbar=ui->label_status->text();
  404. int v_resu = Busca_Articulo(v_codbar, &p_datos);
  405. if(v_resu==2)
  406. {
  407. ui->label_status->setText("Artículo no encontrado");
  408. ui->label_codart->setText("");
  409. ui->label_codbar->setText("");
  410. ui->label_desc->setText("");
  411. ui->label_desc2->setText("");
  412. ui->label_precio->setText("");
  413. ui->label_promo->setText("");
  414. ui->label_prom_valida->setText("");
  415. g_flag1=0;
  416. g_flag2=0;
  417. timer->setSingleShot(true);
  418. timer->start(1000);
  419. }
  420. else
  421. {
  422. Busca_promo(QString::number(p_datos.g_cod), &p_datos);
  423. Imprime_pantalla();
  424. }
  425. }
  426. void Principal::Imprime_pantalla()
  427. {
  428. g_flag1=0;
  429. g_flag2=0;
  430. ui->label_codart->setVisible(true);
  431. ui->label_codbar->setVisible(true);
  432. ui->label_desc->setVisible(true);
  433. ui->label_desc2->setVisible(true);
  434. ui->label_promo->setVisible(true);
  435. ui->label_prom_valida->setVisible(true);
  436. ui->label_status->setVisible(true);
  437. ui->label_status->setText("");
  438. if (g_pre_ofe == 1)
  439. {
  440. ui->label_ofe->setVisible(true);
  441. ui->label_despofe->setVisible(true);
  442. ui->label_ofe->setText("$"+QString::number(g_prec_iva,'f',2));
  443. }
  444. else
  445. {
  446. ui->label_precio->setVisible(true);
  447. ui->label_despnorm->setVisible(true);
  448. ui->label_precio->setText("$"+QString::number(g_prec_iva,'f',2));
  449. }
  450. int v_largo = p_datos.g_des.length();
  451. if(v_largo>25)
  452. {
  453. ui->label_desc->setText(p_datos.g_des.left(25));
  454. ui->label_desc2->setText(p_datos.g_des.mid(25));
  455. }
  456. else
  457. {
  458. ui->label_desc->setText(p_datos.g_des);
  459. }
  460. ui->label_codbar->setText("Cod.Barras: "+p_datos.g_codb);
  461. ui->label_codart->setText("Cod.Int: "+p_datos.g_coda);
  462. timer->setSingleShot(true);
  463. timer->start(20000);
  464. }
  465. void Principal::Muestra_principal()
  466. {
  467. ui->label_codart->setText("");
  468. ui->label_codbar->setText("");
  469. ui->label_desc->setText("");
  470. ui->label_desc2->setText("");
  471. ui->label_precio->setText("");
  472. ui->label_ofe->setText("");
  473. ui->label_promo->setText("");
  474. ui->label_prom_valida->setText("");
  475. ui->label_status->setText("");
  476. ui->label_codart->setVisible(false);
  477. ui->label_codbar->setVisible(false);
  478. ui->label_desc->setVisible(false);
  479. ui->label_desc2->setVisible(false);
  480. ui->label_precio->setVisible(false);
  481. ui->label_despnorm->setVisible(false);
  482. ui->label_ofe->setVisible(false);
  483. ui->label_despofe->setVisible(false);
  484. ui->label_promo->setVisible(false);
  485. ui->label_prom_valida->setVisible(false);
  486. ui->label_status->setVisible(false);
  487. ui->label_principal->setVisible(true);
  488. ui->label_imagen->setVisible(true);
  489. ui->label_principal->setText("Escanee un articulo...");
  490. g_startcodbar=0;
  491. }
  492. void Principal::Busca_promo(QString p_cod , g_datos * p_datos)
  493. {
  494. QSqlQuery query;
  495. QString v_sql;
  496. int num_items=0;
  497. /*v_sql="SELECT * FROM forumpr1.dpromo join forumpr1.accionpro on dpr_accion = accionpro.acp_accion "
  498. "WHERE (dpr_art = '"+p_cod+"' or dpr_art = '"+p_cod+"') and acp_fdesde <= '"+g_fecha_sql+"' and acp_fhasta >= '"+g_fecha_sql+"' "
  499. "and dpr_accion in (SELECT dpr_accion FROM forumpr1.dpromo join forumpr1.accionpro on dpr_accion = accionpro.acp_accion "
  500. "WHERE acp_fdesde <= '"+g_fecha_sql+"' and acp_fhasta >= '"+g_fecha_sql+"' and (dpr_art = '"+p_cod+"' or dpr_art = '"+p_cod+"') "
  501. "order by dpr_accion asc, dpr_promo, dpr_item desc limit 1);";*/
  502. v_sql="SELECT * FROM forumpr1.dpromo join forumpr1.accionpro on dpr_accion = accionpro.acp_accion "
  503. "join forumpr1.cpromocup on dpr_accion = cpromocup.kpr_accion join minor.configuracion on kpr_suc = configuracion.g_sucursal "
  504. "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 "
  505. "and dpr_accion in (SELECT dpr_accion FROM forumpr1.dpromo join forumpr1.accionpro on dpr_accion = accionpro.acp_accion "
  506. "join forumpr1.cpromocup on dpr_accion = cpromocup.kpr_accion join minor.configuracion on kpr_suc = configuracion.g_sucursal "
  507. "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) "
  508. "order by dpr_accion asc, dpr_promo, dpr_item desc limit 1);";
  509. qDebug()<< "sql_dpromo: "<< v_sql;
  510. query.exec(v_sql);
  511. num_items=query.size();
  512. QSqlRecord rec = query.record();
  513. if(num_items>0)
  514. {
  515. int nameCol1 = rec.indexOf("dpr_promo");
  516. int nameCol2 = rec.indexOf("dpr_lleva");
  517. int nameCol3 = rec.indexOf("dpr_paga");
  518. int nameCol4 = rec.indexOf("dpr_des");
  519. int nameCol5 = rec.indexOf("acp_accion");
  520. int nameCol6 = rec.indexOf("acp_fdesde");
  521. int nameCol7 = rec.indexOf("acp_fhasta");
  522. while( query.next() )
  523. {
  524. QString v_promo = query.value(nameCol1).toString();
  525. QString v_lleva = query.value(nameCol2).toString();
  526. QString v_paga = query.value(nameCol3).toString();
  527. float v_des = query.value(nameCol4).toFloat();
  528. QString v_accion = query.value(nameCol5).toString();
  529. QString v_fdesde = query.value(nameCol6).toString();
  530. QString v_fhasta = query.value(nameCol7).toString();
  531. QSqlQuery query_select, query_select2, query_select3;
  532. QString v_sql1, v_sql2, v_sql3;
  533. int num_items1=0;
  534. int num_items2=0;
  535. int num_items3=0;
  536. v_sql1="SELECT * FROM forumpr1.cpromo WHERE cpr_accion = '"+v_accion+"' and cpr_promo = '"+v_promo+"';";
  537. //qDebug()<< "sql_cpromo: _____________"<< v_sql1;
  538. query_select.exec(v_sql1);
  539. num_items1=query_select.size();
  540. QSqlRecord rec1 = query_select.record();
  541. if(num_items1>0)
  542. {
  543. int nameCol1 = rec1.indexOf("cpr_tpromo");
  544. //int nameCol2 = rec1.indexOf("cpr_dpromo");
  545. while( query_select.next() )
  546. {
  547. QString v_tpromo = query_select.value(nameCol1).toString();
  548. //QString v_dpromo = query_select.value(nameCol2).toString();
  549. if(v_tpromo=="1" || v_tpromo=="2" || v_tpromo=="3" || v_tpromo=="4" || v_tpromo=="6")
  550. {
  551. if(v_tpromo=="1")
  552. ui->label_promo->setText(ui->label_promo->text()+"\n"+"LLEVA "+v_lleva+" PAGA "+v_paga);
  553. if(v_tpromo=="2")
  554. {
  555. //BUSCA LOS OTROS ARTICULOS DE LA PROMO
  556. 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;";
  557. query_select2.exec(v_sql2);
  558. num_items2=query_select2.size();
  559. ui->label_promo->setText("LLEVANDO ");//LEER TABLA RPROMO
  560. if(num_items2>0)
  561. {
  562. while( query_select2.next() )
  563. {
  564. QString v_descartpromo = query_select2.value(0).toString();
  565. QString v_artpromo = query_select2.value(1).toString();
  566. QString v_llevaartpromo = query_select2.value(2).toString();
  567. QString v_connartpromo = query_select2.value(3).toString();
  568. //BUSQUEDA DE DESCRIPCION DE ARTICULO
  569. if(v_connartpromo == "fin") v_connartpromo = "";
  570. ui->label_promo->setText(ui->label_promo->text()+"\n"+v_llevaartpromo+" x "+v_descartpromo+" "+v_connartpromo);//LEER TABLA RPROMO
  571. }
  572. }
  573. //BUSCA EL REGALO
  574. 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+"' ;";
  575. query_select3.exec(v_sql3);
  576. num_items3=query_select3.size();
  577. ui->label_promo->setText(ui->label_promo->text()+"\n"+"DE REGALO: ");//LEER TABLA RPROMO
  578. if(num_items3>0)
  579. {
  580. if(query_select3.next())
  581. {
  582. QString v_desartregalo = query_select3.value(0).toString();
  583. QString v_artregalo = query_select3.value(1).toString();
  584. QString v_cantartregalo = query_select3.value(2).toString();
  585. ui->label_promo->setText(ui->label_promo->text()+"\n"+v_cantartregalo+" x "+v_artregalo+ " " + v_desartregalo);
  586. }
  587. }
  588. }
  589. if(v_tpromo=="3")
  590. ui->label_promo->setText(ui->label_promo->text()+"\n"+"LLEVA SURTIDO "+v_lleva+" PAGA "+v_paga);
  591. if(v_tpromo=="4")
  592. ui->label_promo->setText(ui->label_promo->text()+"\n"+"LLEVA "+v_lleva+" DESCUENTO "+QString::number(v_des,'f',2)+"%");
  593. if(v_tpromo=="6")
  594. ui->label_promo->setText(ui->label_promo->text()+"\n"+"LLEVA SURTIDO "+v_lleva+" DESCUENTO "+QString::number(v_des,'f',2)+"%");
  595. ui->label_prom_valida->setText("Valido desde "+v_fdesde+" hasta "+v_fhasta+" inclusive.");
  596. }
  597. }
  598. }
  599. }
  600. }
  601. else {
  602. QSqlQuery query_select_frac;
  603. QString v_sql2;
  604. int num_items=0;
  605. v_sql2="SELECT art_des, art_frac, art_cumf FROM forum.articulo WHERE forum.articulo.art_frac < 0 AND art_cod = "+p_cod+" ;";
  606. query_select_frac.exec(v_sql2);
  607. num_items=query_select_frac.size();
  608. if(num_items>0)
  609. {
  610. if(query_select_frac.next())
  611. {
  612. QString v_desc = query_select_frac.value(0).toString();
  613. QString v_frac = query_select_frac.value(1).toString();
  614. QString v_cumf = query_select_frac.value(2).toString();
  615. 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
  616. qDebug() <<"PRE: "<< g_prec_iva << " DESC: " << (float)g_prec_iva-((float)g_prec_iva*(-1)*v_frac.toFloat()/(float)100);
  617. ui->label_ofe->setVisible(true);
  618. ui->label_ofe->setText("$"+QString::number((float)g_prec_iva-((float)g_prec_iva*(-1)*v_frac.toFloat()/(float)100),'f',2));
  619. ui->label_despofe->setVisible(true);
  620. }
  621. }
  622. }
  623. }
  624. bool Principal::eventFilter(QObject *obj, QEvent *event)
  625. {
  626. if (obj == (QObject *)ui->centralWidget)
  627. {
  628. if ( event->type() == QEvent::KeyRelease )
  629. {
  630. QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
  631. //qDebug() << "Toque esta tecla: " << keyEvent->key();
  632. if(g_startcodbar==0 && keyEvent->key() == 48) //número 0
  633. {
  634. g_flag1=1;
  635. g_startcodbar=1;
  636. }
  637. if(keyEvent->key() == Qt::Key_Enter || keyEvent->key() == 16777220 ) //enter
  638. {
  639. if(g_flag1==0)
  640. {
  641. g_startcodbar=0;
  642. if(ui->label_status->text()!="")
  643. {
  644. Ingresa_articulo();
  645. }
  646. }
  647. if(g_flag1==1)
  648. {
  649. g_codigo="";
  650. g_startcodbar=1;
  651. ui->label_status->setVisible(true);
  652. ui->label_status->setText("Ingrese código de barras");
  653. ui->label_codart->setText("");
  654. ui->label_codbar->setText("");
  655. ui->label_desc->setText("");
  656. ui->label_desc2->setText("");
  657. ui->label_precio->setText("");
  658. ui->label_ofe->setText("");
  659. ui->label_promo->setText("");
  660. ui->label_prom_valida->setText("");
  661. ui->label_precio->setVisible(false);
  662. ui->label_ofe->setVisible(false);
  663. ui->label_despofe->setVisible(false);
  664. ui->label_despnorm->setVisible(false);
  665. ui->label_principal->setVisible(false);
  666. ui->label_imagen->setVisible(false);
  667. g_flag2=1;
  668. }
  669. }
  670. if(g_startcodbar==0 && keyEvent->key() == 16777275) //F12 (16777275)
  671. {
  672. g_codigo="";
  673. g_startcodbar=1;
  674. ui->label_status->setVisible(true);
  675. ui->label_status->setText("Ingrese código de barras");
  676. ui->label_codart->setText("");
  677. ui->label_codbar->setText("");
  678. ui->label_desc->setText("");
  679. ui->label_desc2->setText("");
  680. ui->label_precio->setText("");
  681. ui->label_ofe->setText("");
  682. ui->label_promo->setText("");
  683. ui->label_prom_valida->setText("");
  684. ui->label_precio->setVisible(false);
  685. ui->label_ofe->setVisible(false);
  686. ui->label_despofe->setVisible(false);
  687. ui->label_despnorm->setVisible(false);
  688. ui->label_principal->setVisible(false);
  689. ui->label_imagen->setVisible(false);
  690. g_flag2=1;
  691. }
  692. if(keyEvent->key() == 16777216 || keyEvent->key() == 16777233) //esc o fin
  693. {
  694. close();
  695. }
  696. if(keyEvent->key() >= 48 && keyEvent->key() <= 57 && g_startcodbar==1 && g_flag2==1) //TECLADO NUMERICO
  697. {
  698. if(g_codigo.count()<=13)
  699. {
  700. g_codigo+=keyEvent->text().toUpper();
  701. ui->label_status->setText(g_codigo);
  702. g_flag1=0;
  703. }
  704. }
  705. if(keyEvent->key() ==16777219 && g_startcodbar==1)// <-- BORRAR
  706. {
  707. g_codigo.chop(1);
  708. ui->label_status->setText(g_codigo);
  709. }
  710. }
  711. }
  712. }