/src/ventas.c
C | 7178 lines | 4781 code | 1293 blank | 1104 comment | 632 complexity | 0fe42238b99186b58a80fbcbc7c58742 MD5 | raw file
Possible License(s): GPL-2.0
Large files files are truncated, but you can click here to view the full file
1/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; 2 c-indentation-style: gnu -*- */ 3/*ventas.c 4 * 5 * Copyright (C) 2004,2008 Rizoma Tecnologia Limitada <info@rizoma.cl> 6 * 7 * This file is part of rizoma. 8 * 9 * Rizoma is free software; you can redistribute it and/or modify 10 * it under the terms of the GNU General Public License as published by 11 * the Free Software Foundation; either version 2 of the License, or 12 * (at your option) any later version. 13 * 14 * This program is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * GNU General Public License for more details. 18 * 19 * You should have received a copy of the GNU General Public License 20 * along with this program; if not, write to the Free Software 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 22 */ 23 24#define _XOPEN_SOURCE 600 25#include<features.h> 26 27#include<gtk/gtk.h> 28#include<gdk/gdkkeysyms.h> 29 30#include<math.h> 31#include<stdlib.h> 32#include<string.h> 33 34#include<time.h> 35 36#include"tipos.h" 37#include"ventas.h" 38#include"credito.h" 39#include"postgres-functions.h" 40#include"errors.h" 41#include"manejo_productos.h" 42#include"manejo_pagos.h" 43#include"boleta.h" 44#include"config_file.h" 45 46#include"utils.h" 47#include"encriptar.h" 48#include"factura_more.h" 49#include"rizoma_errors.h" 50#include"proveedores.h" 51#include"caja.h" 52#include"vale.h" 53 54GtkBuilder *builder; 55 56GtkWidget *vuelto_button; 57 58GtkWidget *calendar_window; 59GtkWidget *button_cheque; 60 61GtkWidget *buscador_window; 62 63GtkWidget *label_found; 64 65GtkWidget *tipos_window; 66 67GtkWidget *canje_cantidad; 68 69GtkWidget *window_seller; 70 71gchar *tipo_venta; 72 73gint monto_cheque = 0; 74 75gboolean cheques = FALSE; 76 77GtkWidget *canje_entry; 78 79gboolean ventas = TRUE; 80 81gint tipo_documento = -1; 82 83gboolean mayorista = FALSE; 84 85gboolean closing_tipos = FALSE; 86 87gboolean block_discount = FALSE; 88// Venta de mercadería que se encuentre en la tabla de reserva 89gboolean venta_reserva = FALSE; 90// Inhabilita los procedimientos que requieran un stock en el producto 91//gboolean no_venta = FALSE; 92 93 94/** 95 * Display the information of a product on the main sales window 96 * 97 * @param barcode the barcode of the product 98 * @param mayorista TRUE if the product has a especial value for mayorist sales 99 * @param marca the brand of the product 100 * @param descripcion the description of the product 101 * @param contenido the contents (amount) of the product 102 * @param unidad the unit of the product (i.e. kg) 103 * @param stock the current stock of the product 104 * @param stock_day for how many days the current stock will be enough 105 * @param precio the price of the product 106 * @param precio_mayor the price of the producto for mayorist values 107 * @param cantidad_mayor how many products must be saled to be considered as mayorist 108 * @param codigo_corto the short code associated to the product 109 */ 110void 111FillProductSell (gchar *barcode, 112 gboolean mayorista, 113 gchar *marca, 114 gchar *descripcion, 115 gchar *contenido, 116 gchar *unidad, 117 gchar *stock, 118 gchar *stock_day, 119 gchar *precio, 120 gchar *precio_mayor, 121 gchar *cantidad_mayor, 122 gchar *codigo_corto) 123{ 124 GtkWidget *widget; 125 gchar *str_aux; 126 127 //caja de producto 128 widget = GTK_WIDGET(gtk_builder_get_object(builder, "barcode_entry")); 129 gtk_entry_set_text(GTK_ENTRY(widget), barcode); 130 131 gtk_label_set_markup (GTK_LABEL (gtk_builder_get_object (builder, "product_label")), 132 g_strdup_printf ("<span weight=\"ultrabold\" size=\"12000\">%s\n%s %s %s</span>", 133 g_strndup (descripcion, 30), marca, contenido, unidad)); 134 135 if (strtod (PUT (stock), (char **)NULL) <= GetMinStock (barcode)) 136 gtk_label_set_markup (GTK_LABEL (gtk_builder_get_object (builder, "label_stockday")), 137 g_strdup_printf("<span foreground=\"red\"><b>%.2f dia(s)</b></span>", 138 strtod (PUT (stock_day), (char **)NULL))); 139 else 140 gtk_label_set_markup (GTK_LABEL (gtk_builder_get_object (builder, "label_stockday")), 141 g_strdup_printf ("<b>%.2f dia(s)</b>", strtod (PUT (stock_day), (char **)NULL))); 142 143 //precio 144 /*gtk_label_set_markup (GTK_LABEL (gtk_builder_get_object (builder, "label_precio")), 145 g_strdup_printf ("<span weight=\"ultrabold\" size=\"12000\">%s</span>", 146 PutPoints (precio)));*/ 147 148 if (rut_cliente_pre_factura > 0) 149 { 150 gchar *q; 151 gdouble client_price = 0; 152 q = g_strdup_printf ("SELECT precio FROM cliente_precio WHERE rut_cliente = %d AND barcode = '%s'", 153 rut_cliente_pre_factura, barcode); 154 155 PGresult *res = EjecutarSQL (q); 156 if (res != NULL && PQntuples (res) != 0) 157 { 158 client_price = strtod (PUT (PQgetvalue (res, 0, 0)), (char **)NULL); 159 160 if (client_price > 0) 161 precio = PUT (g_strdup_printf ("%.3f",client_price)); 162 } 163 164 g_free (q); 165 } 166 gtk_entry_set_text (GTK_ENTRY (builder_get (builder, "entry_precio")), precio); 167 168 //precio de mayorista 169 gtk_label_set_markup (GTK_LABEL (gtk_builder_get_object (builder, "label_mayor")), 170 g_strdup_printf ("<span weight=\"ultrabold\" size=\"12000\">%s</span>", 171 PutPoints (precio_mayor))); 172 173 gtk_label_set_markup (GTK_LABEL (gtk_builder_get_object (builder, "label_mayor_cantidad")), 174 g_strdup_printf ("<span weight=\"ultrabold\" size=\"12000\">%s</span>", 175 PutPoints (cantidad_mayor))); 176 177 gtk_label_set_markup (GTK_LABEL (gtk_builder_get_object (builder, "label_stock")), 178 g_strdup_printf ("<span weight=\"ultrabold\" size=\"12000\">%.2f</span>", 179 strtod (PUT (stock), (char **)NULL))); 180 181 str_aux = g_strdup(gtk_entry_get_text (GTK_ENTRY (gtk_builder_get_object (builder, "cantidad_entry")))); 182 str_aux = g_strdup_printf ("%.0f", strtod (PUT (str_aux), (char **)NULL) * atoi (precio)); 183 gtk_label_set_markup (GTK_LABEL (gtk_builder_get_object (builder, "label_subtotal")), 184 g_strdup_printf ("<span weight=\"ultrabold\" size=\"12000\">%s</span>", PutPoints(str_aux))); 185 186 gtk_label_set_markup (GTK_LABEL (gtk_builder_get_object (builder, "codigo_corto")), 187 g_strdup_printf ("<span weight=\"ultrabold\" size=\"12000\">%s</span>", codigo_corto)); 188} 189 190void 191CanjearProducto (GtkWidget *widget, gpointer data) 192{ 193 GtkWidget *entry = (GtkWidget *) data; 194 195 if (entry == NULL) 196 { 197 gtk_widget_destroy (gtk_widget_get_toplevel (widget)); 198 199 gtk_widget_grab_focus (GTK_WIDGET (gtk_builder_get_object (builder, "barcode_entry"))); 200 } 201 else 202 { 203 gchar *barcode = g_strdup (gtk_entry_get_text (GTK_ENTRY (canje_entry))); 204 205 if ((GetDataByOne (g_strdup_printf ("SELECT barcode FROM producto WHERE barcode='%s'", 206 barcode))) == NULL) 207 { 208 ErrorMSG (entry, "No existe el producto"); 209 return; 210 } 211 else 212 { 213 gdouble cantidad = strtod (PUT (g_strdup (gtk_entry_get_text (GTK_ENTRY (canje_cantidad)))), 214 (char **)NULL); 215 216 CanjearProduct (barcode, cantidad); 217 218 CanjearProducto (widget, NULL); 219 } 220 } 221} 222 223void 224CanjearProductoWin (GtkWidget *widget, gpointer data) 225{ 226 GtkWidget *window; 227 GtkWidget *vbox; 228 GtkWidget *hbox; 229 GtkWidget *label; 230 GtkWidget *button; 231 232 window = gtk_window_new (GTK_WINDOW_TOPLEVEL); 233 gtk_window_set_title (GTK_WINDOW (window), "Canjear Producto"); 234 gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER_ALWAYS); 235 gtk_window_set_resizable (GTK_WINDOW (window), FALSE); 236 gtk_window_present (GTK_WINDOW (window)); 237 gtk_widget_show (window); 238 239 g_signal_connect (G_OBJECT (window), "destroy", 240 G_CALLBACK (CanjearProducto), NULL); 241 242 vbox = gtk_vbox_new (FALSE, 3); 243 gtk_container_add (GTK_CONTAINER (window), vbox); 244 gtk_widget_show (vbox); 245 246 hbox = gtk_hbox_new (FALSE, 3); 247 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 3); 248 gtk_widget_show (hbox); 249 250 label = gtk_label_new ("Código de Barras: "); 251 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 3); 252 gtk_widget_show (label); 253 254 canje_entry = gtk_entry_new (); 255 gtk_box_pack_start (GTK_BOX (hbox), canje_entry, FALSE, FALSE, 3); 256 gtk_widget_show (canje_entry); 257 258 g_signal_connect (G_OBJECT (canje_entry), "activate", 259 G_CALLBACK (SearchSellProduct), (gpointer)FALSE); 260 261 gtk_window_set_focus (GTK_WINDOW (window), canje_entry); 262 263 hbox = gtk_hbox_new (FALSE, 3); 264 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 3); 265 gtk_widget_show (hbox); 266 267 label = gtk_label_new ("Cantidad: "); 268 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 3); 269 gtk_widget_show (label); 270 271 canje_cantidad = gtk_entry_new (); 272 gtk_box_pack_start (GTK_BOX (hbox), canje_cantidad, FALSE, FALSE, 3); 273 gtk_widget_show (canje_cantidad); 274 275 g_signal_connect (G_OBJECT (canje_entry), "activate", 276 G_CALLBACK (SendCursorTo), (gpointer)canje_cantidad); 277 278 hbox = gtk_hbox_new (FALSE, 3); 279 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 3); 280 gtk_widget_show (hbox); 281 282 button = gtk_button_new_from_stock (GTK_STOCK_CANCEL); 283 gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 3); 284 gtk_widget_show (button); 285 286 g_signal_connect (G_OBJECT (button), "clicked", 287 G_CALLBACK (CanjearProducto), NULL); 288 289 button = gtk_button_new_from_stock (GTK_STOCK_OK); 290 gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 3); 291 gtk_widget_show (button); 292 293 g_signal_connect (G_OBJECT (button), "clicked", 294 G_CALLBACK (CanjearProducto), (gpointer)canje_entry); 295 296 g_signal_connect (G_OBJECT (canje_cantidad), "activate", 297 G_CALLBACK (SendCursorTo), (gpointer)button); 298 299} 300 301void 302SetChequeDate (GtkCalendar *calendar, gpointer data) 303{ 304 GtkButton *button = (GtkButton *) data; 305 guint day, month, year; 306 307 time_t t; 308 struct tm *current; 309 310 if (calendar == NULL) 311 { 312 calendar = GTK_CALENDAR (gtk_calendar_new ()); 313 314 gtk_calendar_get_date (calendar, &year, &month, &day); 315 316 gtk_button_set_label (button, g_strdup_printf ("%.2u/%.2u/%.4u", day, month+1, year)); 317 } 318 else 319 { 320 time (&t); 321 322 current = localtime (&t); 323 324 gtk_calendar_get_date (calendar, &year, &month, &day); 325 326 if (year >= (current->tm_year + 1900) && month >= current->tm_mon && day >= current->tm_mday) 327 { 328 gtk_button_set_label (button, g_strdup_printf ("%.2u/%.2u/%.4u", day, month+1, year)); 329 330 SetToggleMode (GTK_TOGGLE_BUTTON (data), NULL); 331 } 332 } 333} 334 335void 336SelectChequeDate (GtkToggleButton *widget, gpointer data) 337{ 338 GtkWidget *vbox; 339 GtkCalendar *calendar; 340 GtkRequisition req; 341 gint h; //w; 342 gint x, y; 343 gint button_y, button_x; 344 gboolean toggle = gtk_toggle_button_get_active (widget); 345 346 if (toggle == TRUE) 347 { 348 gdk_window_get_origin (GTK_WIDGET (widget)->window, &x, &y); 349 350 gtk_widget_size_request (GTK_WIDGET (widget), &req); 351 h = req.height; 352 //w = req.width; 353 354 button_y = GTK_WIDGET (widget)->allocation.y; 355 button_x = GTK_WIDGET (widget)->allocation.x; 356 357 calendar_window = gtk_window_new (GTK_WINDOW_TOPLEVEL); 358 gtk_window_set_screen (GTK_WINDOW (calendar_window), 359 gtk_widget_get_screen (GTK_WIDGET (widget))); 360 361 gtk_container_set_border_width (GTK_CONTAINER (calendar_window), 5); 362 gtk_window_set_type_hint (GTK_WINDOW (calendar_window), GDK_WINDOW_TYPE_HINT_DOCK); 363 gtk_window_set_decorated (GTK_WINDOW (calendar_window), FALSE); 364 gtk_window_set_resizable (GTK_WINDOW (calendar_window), FALSE); 365 gtk_window_stick (GTK_WINDOW (calendar_window)); 366 gtk_window_set_title (GTK_WINDOW (calendar_window), "Calendario"); 367 368 vbox = gtk_vbox_new (FALSE, 3); 369 gtk_container_add (GTK_CONTAINER (calendar_window), vbox); 370 gtk_widget_show (vbox); 371 372 calendar = GTK_CALENDAR (gtk_calendar_new ()); 373 gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (calendar), FALSE, FALSE, 0); 374 gtk_widget_show (GTK_WIDGET (calendar)); 375 376 g_signal_connect (G_OBJECT (calendar), "day-selected-double-click", 377 G_CALLBACK (SetChequeDate), (gpointer) widget); 378 379 gtk_widget_show (calendar_window); 380 381 x = (x + button_x); 382 y = (y + button_y) + h; 383 384 gtk_window_move (GTK_WINDOW (calendar_window), x, y); 385 gtk_window_present (GTK_WINDOW (calendar_window)); 386 387 } 388 else if (toggle == FALSE) 389 { 390 gtk_widget_destroy (calendar_window); 391 } 392} 393 394void 395DatosCheque (void) 396{ 397 GtkWidget *window; 398 GtkWidget *label; 399 GtkWidget *frame; 400 GtkWidget *button; 401 GtkWidget *hbox; 402 GtkWidget *vbox; 403 GtkWidget *vbox2; 404 405 window = gtk_window_new (GTK_WINDOW_TOPLEVEL); 406 gtk_window_set_title (GTK_WINDOW (window), "Ingreso de Cheque"); 407 gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER_ALWAYS); 408 gtk_widget_show (window); 409 gtk_window_present (GTK_WINDOW (window)); 410 gtk_window_set_resizable (GTK_WINDOW (window), FALSE); 411 gtk_widget_show (window); 412 413 vbox = gtk_vbox_new (FALSE, 3); 414 gtk_container_add (GTK_CONTAINER (window), vbox); 415 gtk_widget_show (vbox); 416 417 hbox = gtk_hbox_new (FALSE, 3); 418 gtk_box_pack_end (GTK_BOX (vbox), hbox, FALSE, FALSE, 3); 419 gtk_widget_show (hbox); 420 421 button = gtk_button_new_with_mnemonic ("_Vender"); 422 gtk_box_pack_end (GTK_BOX (hbox), button, FALSE, FALSE, 3); 423 gtk_widget_show (button); 424 425 frame = gtk_frame_new ("Datos Cheque"); 426 gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 3); 427 gtk_widget_show (frame); 428 429 vbox2 = gtk_vbox_new (FALSE, 3); 430 gtk_container_add (GTK_CONTAINER (frame), vbox2); 431 gtk_widget_show (vbox2); 432 433 hbox = gtk_hbox_new (FALSE, 3); 434 gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, FALSE, 3); 435 gtk_widget_show (hbox); 436 437 label = gtk_label_new ("Serie: "); 438 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 3); 439 gtk_widget_show (label); 440 441 venta->cheque_serie = gtk_entry_new_with_max_length (10); 442 gtk_box_pack_end (GTK_BOX (hbox), venta->cheque_serie, FALSE, FALSE, 3); 443 gtk_widget_show (venta->cheque_serie); 444 445 g_signal_connect (G_OBJECT (venta->venta_rut), "changed", 446 G_CALLBACK (SendCursorTo), (gpointer)venta->cheque_serie); 447 448 hbox = gtk_hbox_new (FALSE, 3); 449 gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, FALSE, 3); 450 gtk_widget_show (hbox); 451 452 label = gtk_label_new ("Número: "); 453 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 3); 454 gtk_widget_show (label); 455 456 venta->cheque_numero = gtk_entry_new (); 457 gtk_box_pack_end (GTK_BOX (hbox), venta->cheque_numero, FALSE, FALSE, 3); 458 gtk_widget_show (venta->cheque_numero); 459 460 g_signal_connect (G_OBJECT (venta->cheque_serie), "activate", 461 G_CALLBACK (SendCursorTo), (gpointer)venta->cheque_numero); 462 463 hbox = gtk_hbox_new (FALSE, 3); 464 gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, FALSE, 3); 465 gtk_widget_show (hbox); 466 467 label = gtk_label_new ("Banco: "); 468 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 3); 469 gtk_widget_show (label); 470 471 venta->cheque_banco = gtk_entry_new_with_max_length (50); 472 gtk_box_pack_end (GTK_BOX (hbox), venta->cheque_banco, FALSE, FALSE, 3); 473 gtk_widget_show (venta->cheque_banco); 474 475 g_signal_connect (G_OBJECT (venta->cheque_numero), "activate", 476 G_CALLBACK (SendCursorTo), (gpointer)venta->cheque_banco); 477 478 hbox = gtk_hbox_new (FALSE, 3); 479 gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, FALSE, 3); 480 gtk_widget_show (hbox); 481 482 label = gtk_label_new ("Plaza: "); 483 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 3); 484 gtk_widget_show (label); 485 486 venta->cheque_plaza = gtk_entry_new_with_max_length (50); 487 gtk_box_pack_end (GTK_BOX (hbox), venta->cheque_plaza, FALSE, FALSE, 3); 488 gtk_widget_show (venta->cheque_plaza); 489 490 g_signal_connect (G_OBJECT (venta->cheque_banco), "activate", 491 G_CALLBACK (SendCursorTo), (gpointer)venta->cheque_plaza); 492 493 hbox = gtk_hbox_new (FALSE, 3); 494 gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, FALSE, 3); 495 gtk_widget_show (hbox); 496 497 label = gtk_label_new ("Fecha: "); 498 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 3); 499 gtk_widget_show (label); 500 501 button_cheque = gtk_toggle_button_new (); 502 gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (button_cheque), FALSE); 503 gtk_box_pack_end (GTK_BOX (hbox), button_cheque, FALSE, FALSE, 3); 504 gtk_widget_show (button_cheque); 505 506 g_signal_connect (G_OBJECT (venta->cheque_plaza), "activate", 507 G_CALLBACK (SendCursorTo), (gpointer)button_cheque); 508 509 SetChequeDate (NULL, (gpointer)button_cheque); 510 511 g_signal_connect (G_OBJECT (button_cheque), "toggled", 512 G_CALLBACK (SelectChequeDate), NULL); 513 514 hbox = gtk_hbox_new (FALSE, 3); 515 gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, FALSE, 3); 516 gtk_widget_show (hbox); 517 518 label = gtk_label_new ("Monto: "); 519 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 3); 520 gtk_widget_show (label); 521 522 venta->cheque_monto = gtk_entry_new_with_max_length (50); 523 gtk_box_pack_end (GTK_BOX (hbox), venta->cheque_monto, FALSE, FALSE, 3); 524 gtk_widget_show (venta->cheque_monto); 525 526 g_signal_connect (G_OBJECT (button_cheque), "toggled", 527 G_CALLBACK (SendCursorTo), (gpointer)venta->cheque_monto); 528 529 g_signal_connect (G_OBJECT (venta->cheque_monto), "activate", 530 G_CALLBACK (SendCursorTo), (gpointer)button); 531 532 venta->tipo_venta = CHEQUE; 533} 534 535 536void 537CancelarTipo (GtkWidget *widget, gpointer data) 538{ 539 540 if (closing_tipos == TRUE) 541 return; 542 543 closing_tipos = TRUE; 544 545 gtk_widget_destroy (gtk_widget_get_toplevel (widget)); 546 547 if ((gboolean)data == TRUE) 548 { 549 //TiposVenta (NULL, NULL); 550 } 551 else 552 { 553 gtk_widget_grab_focus (GTK_WIDGET (gtk_builder_get_object (builder, "sencillo_entry"))); 554 555 venta->tipo_venta = SIMPLE; 556 } 557 closing_tipos = FALSE; 558} 559 560 561 562/** 563 * 564 * 565 */ 566void 567on_precio_neto_sell_edited (GtkCellRendererText *cell, gchar *path_string, gchar *precio_neto_t, gpointer data) 568{ 569 GtkTreeModel *model = GTK_TREE_MODEL (data); 570 GtkTreePath *path = gtk_tree_path_new_from_string (path_string); 571 GtkTreeIter iter; 572 573 gchar *codigo, *barcode; 574 gdouble iva, otros; 575 gdouble precio_final, precio_neto, costo_neto, cantidad; 576 gint sub_neto, sub_total; 577 gdouble ganancia_minima = strtod (PUT (rizoma_get_value ("GANANCIA_MINIMA")), (char **)NULL); 578 579 //Verifica que sea un valor numérico 580 if (!is_numeric (precio_neto_t)) 581 { 582 AlertMSG (GTK_WIDGET (builder_get (builder, "sell_products_list")), 583 "El precio neto debe ser un valor numérico"); 584 return; 585 } 586 587 588 gtk_tree_model_get_iter (model, &iter, path); 589 gtk_tree_path_free (path); 590 591 gtk_tree_model_get (model, &iter, 592 0, &codigo, // Se obtiene el codigo del producto 593 2, &cantidad, 594 -1); 595 596 barcode = PQvaluebycol (EjecutarSQL (g_strdup_printf ("SELECT barcode FROM codigo_corto_to_barcode('%s')", codigo)), 597 0, "barcode"); 598 599 600 precio_neto = strtod (PUT (precio_neto_t), (char **)NULL); 601 602 costo_neto = obtener_costo_promedio (barcode); 603 ganancia_minima = (ganancia_minima > 0) ? (ganancia_minima/100)+1 : 1; 604 costo_neto = costo_neto * ganancia_minima; 605 606 //Se obtienen los impuestos 607 iva = GetIVA (barcode); 608 iva = (iva > 0) ? iva / 100 : 0; 609 otros = GetOtros (barcode); 610 otros = (otros > 0) ? otros / 100 : 0; 611 612 if (precio_neto < costo_neto) 613 { 614 AlertMSG (GTK_WIDGET (builder_get (builder, "sell_products_list")), 615 g_strdup_printf ("El precio es inferior al mínimo permitido ($ %s)", 616 PutPoints (g_strdup_printf ("%ld", lround (costo_neto))))); 617 return; 618 } 619 620 precio_final = (precio_neto * (1 + otros + iva)); 621 sub_neto = lround (precio_neto*cantidad); 622 sub_total = lround (precio_final*cantidad); 623 624 gtk_list_store_set (GTK_LIST_STORE (model), &iter, 625 3, precio_neto, 626 4, sub_neto, 627 5, precio_final, 628 6, sub_total, 629 -1); 630 631 /*Se modifican los datos de la estructura*/ 632 venta->product_check = BuscarPorCodigo (venta->header, codigo); 633 634 venta->product_check->product->precio_mayor = precio_final; 635 venta->product_check->product->precio = precio_final; 636 venta->product_check->product->precio_neto = precio_neto; 637 638 gtk_label_set_markup (GTK_LABEL (gtk_builder_get_object (builder, "label_total")), 639 g_strdup_printf ("<span size=\"40000\">%s</span>", 640 PutPoints (g_strdup_printf ("%ld", lround (CalcularTotal (venta->header)))))); 641} 642 643 644/** 645 * 646 * 647 */ 648void 649on_precio_final_sell_edited (GtkCellRendererText *cell, gchar *path_string, gchar *precio_final_t, gpointer data) 650{ 651 GtkTreeModel *model = GTK_TREE_MODEL (data); 652 GtkTreePath *path = gtk_tree_path_new_from_string (path_string); 653 GtkTreeIter iter; 654 655 gchar *codigo, *barcode; 656 gdouble iva, otros; 657 gdouble precio_final, precio_neto, costo_neto, cantidad; 658 gint sub_neto, sub_total; 659 gdouble ganancia_minima = strtod (PUT (rizoma_get_value ("GANANCIA_MINIMA")), (char **)NULL); 660 661 //Verifica que sea un valor numérico 662 if (!is_numeric (precio_final_t)) 663 { 664 AlertMSG (GTK_WIDGET (builder_get (builder, "sell_products_list")), 665 "El precio neto debe ser un valor numérico"); 666 return; 667 } 668 669 670 gtk_tree_model_get_iter (model, &iter, path); 671 gtk_tree_path_free (path); 672 673 gtk_tree_model_get (model, &iter, 674 0, &codigo, // Se obtiene el codigo del producto 675 2, &cantidad, 676 -1); 677 678 barcode = PQvaluebycol (EjecutarSQL 679 (g_strdup_printf ("SELECT barcode FROM codigo_corto_to_barcode('%s')", codigo)), 680 0, "barcode"); 681 682 precio_final = strtod (PUT (precio_final_t), (char **)NULL); 683 684 costo_neto = obtener_costo_promedio (barcode); 685 ganancia_minima = (ganancia_minima > 0) ? (ganancia_minima/100)+1 : 1; 686 costo_neto = costo_neto * ganancia_minima; 687 688 //Se obtienen los impuestos 689 iva = GetIVA (barcode); 690 iva = (iva > 0) ? iva / 100 : 0; 691 otros = GetOtros (barcode); 692 otros = (otros > 0) ? otros / 100 : 0; 693 694 //Costo neto + impuestos 695 costo_neto *= (1 + otros + iva); 696 697 if ((precio_final / (1 + otros + iva)) < costo_neto) 698 { 699 AlertMSG (GTK_WIDGET (builder_get (builder, "sell_products_list")), 700 g_strdup_printf ("El precio es inferior al mínimo permitido ($ %s)", 701 PutPoints (g_strdup_printf ("%ld", lround (costo_neto))))); 702 return; 703 } 704 705 precio_neto = (precio_final / (1 + otros + iva)); 706 sub_neto = lround ( (precio_neto*cantidad) ); 707 sub_total = lround ( (precio_final*cantidad) ); 708 709 gtk_list_store_set (GTK_LIST_STORE (model), &iter, 710 3, precio_neto, 711 4, sub_neto, 712 5, precio_final, 713 6, sub_total, 714 -1); 715 716 717 /*Se modifican los datos de la estructura*/ 718 venta->product_check = BuscarPorCodigo (venta->header, codigo); 719 720 venta->product_check->product->precio_mayor = precio_final; 721 venta->product_check->product->precio = precio_final; 722 venta->product_check->product->precio_neto = precio_neto; 723 724 gtk_label_set_markup (GTK_LABEL (gtk_builder_get_object (builder, "label_total")), 725 g_strdup_printf ("<span size=\"40000\">%s</span>", 726 PutPoints (g_strdup_printf ("%ld", lround (CalcularTotal (venta->header)))))); 727} 728 729 730 731/** 732 * 733 * 734 */ 735void 736on_cantidad_sell_edited (GtkCellRendererText *cell, gchar *path_string, gchar *cantidad_t, gpointer data) 737{ 738 GtkTreeModel *model = GTK_TREE_MODEL (data); 739 GtkTreePath *path = gtk_tree_path_new_from_string (path_string); 740 GtkTreeIter iter; 741 742 gchar *codigo, *color; 743 gdouble cantidad, precio_neto, precio_final, iva, otros; 744 745 //Verifica que sea un valor numérico 746 if (!is_numeric (cantidad_t) || (cantidad = strtod (PUT (cantidad_t), (char **)NULL)) < 1 ) 747 { 748 AlertMSG (GTK_WIDGET (builder_get (builder, "sell_products_list")), 749 "La cantidad debe ser un valor numérico mayor a cero"); 750 return; 751 } 752 753 gtk_tree_model_get_iter (model, &iter, path); 754 gtk_tree_path_free (path); 755 756 gtk_tree_model_get (model, &iter, 757 0, &codigo, // Se obtiene el codigo del producto 758 3, &precio_neto, 759 5, &precio_final, 760 -1); 761 762 /*Se modifican los datos de la estructura*/ 763 venta->product_check = BuscarPorCodigo (venta->header, codigo); 764 venta->product_check->product->cantidad = cantidad; 765 766 767 /*Se ve si es mayorista, de acuerdo a eso se le cambia el precio*/ 768 if (venta->product_check->product->mayorista == TRUE && venta->product_check->product->cantidad_mayorista > 0 && 769 venta->product_check->product->precio_mayor > 0 && cantidad >= venta->product_check->product->cantidad_mayorista) 770 { 771 //Se toma en cuenta el precio mayorista SOLO si no se ha modificado el precio del producto 772 if (venta->product_check->product->precio == venta->product_check->product->precio_original) 773 { 774 precio_final = venta->product_check->product->precio_mayor; 775 776 //Se obtienen los impuestos 777 iva = venta->product_check->product->iva; 778 iva = (iva > 0) ? iva / 100 : 0; 779 otros = venta->product_check->product->otros; 780 otros = (otros > 0) ? otros / 100 : 0; 781 782 precio_neto = venta->product_check->product->precio_mayor / (1 + otros + iva); 783 venta->product_check->product->precio_neto = precio_neto; 784 } 785 } 786 787 788 /*Se elige el color de la fila*/ 789 if (venta->product_check->product->cantidad <= venta->product_check->product->stock) 790 color = (venta->product_check->product->cantidad != venta->product_check->product->cantidad_impresa) ? g_strdup ("Blue") : g_strdup ("Black"); 791 else /*Si la cantidad solicitada supera al stock*/ 792 color = g_strdup ("Red"); 793 794 gtk_list_store_set (GTK_LIST_STORE (model), &iter, 795 2, cantidad, 796 3, precio_neto, 797 4, lround (precio_neto*cantidad), 798 5, precio_final, 799 6, lround (precio_final*cantidad), 800 9, color, 801 10, TRUE, 802 -1); 803 804 //Se actualiza la cantidad en la tabla mesa 805 if (rizoma_get_value_boolean ("MODO_MESERO") || 806 rizoma_get_value_boolean ("MODO_VENTA_RESTAURANT")) 807 modificar_producto_mesa (venta->num_mesa, venta->product_check->product->barcode, venta->product_check->product->cantidad, venta->product_check->product->cantidad_impresa); 808 809 810 /* AHORA SE PERMITE VENTA NEGATIVA 811 if (venta->product_check->product->stock < cantidad) 812 { 813 no_venta = TRUE; 814 gtk_widget_set_sensitive (GTK_WIDGET (builder_get (builder, "btn_invoice")), FALSE); 815 gtk_widget_set_sensitive (GTK_WIDGET (builder_get (builder, "btn_sale")), FALSE); 816 gtk_widget_set_sensitive (GTK_WIDGET (builder_get (builder, "btn_devolver")), FALSE); 817 gtk_widget_set_sensitive (GTK_WIDGET (builder_get (builder, "btn_traspaso_enviar")), FALSE); 818 }*/ 819 820 //habilitar_venta (); 821 gtk_label_set_markup (GTK_LABEL (gtk_builder_get_object (builder, "label_total")), 822 g_strdup_printf ("<span size=\"40000\">%s</span>", 823 PutPoints (g_strdup_printf ("%ld", lround (CalcularTotal (venta->header)))))); 824} 825 826 827/** 828 * 829 */ 830void 831on_btn_seleccionar_mesa_clicked (GtkButton *button, gpointer data) 832{ 833 clean_container (GTK_CONTAINER (builder_get (builder, "wnd_cambio_mesa"))); 834 gtk_widget_show (GTK_WIDGET (builder_get (builder, "wnd_cambio_mesa"))); 835 gtk_widget_grab_focus (GTK_WIDGET (builder_get (builder, "entry_numero_mesa"))); 836} 837 838 839/** 840 * Obtiene pre-ventas y reservas 841 */ 842void 843on_btn_get_preventa_ok_clicked (GtkButton *button, gpointer data) 844{ 845 gint id; 846 gchar *preventa_txt1; 847 gchar *preventa_txt2; 848 gchar *entry_text; 849 guint32 total; 850 851 gdouble iva, otros; 852 853 GtkTreeIter iter; 854 PGresult *res; 855 gchar *q; 856 gint tuples, i; 857 858 GtkListStore *sell = GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (builder_get (builder, "sell_products_list")))); 859 860 entry_text = pango_trim_string (gtk_entry_get_text (GTK_ENTRY (builder_get (builder, "entry_id_preventa")))); 861 if (g_str_equal (entry_text, "") || strlen (entry_text) < 3) 862 { 863 ErrorMSG (GTK_WIDGET (builder_get (builder, "entry_id_preventa")), "El ID ingresado es inválido"); 864 return; 865 } 866 867 preventa_txt1 = g_strndup (entry_text, 2); 868 preventa_txt2 = invested_strndup (entry_text, 2); 869 870 //Si el código no es un PV (PreVenta) o un RV (ReserVa) es inválido 871 if ( (!g_str_equal (preventa_txt1, "PV") && !g_str_equal (preventa_txt1, "RV")) 872 || HaveCharacters (preventa_txt2) || g_str_equal (preventa_txt2, "")) 873 { 874 ErrorMSG (GTK_WIDGET (builder_get (builder, "entry_id_preventa")), "El ID ingresado es inválido"); 875 return; 876 } 877 878 //printf ("COD: %s %s", preventa_txt1, preventa_txt2); 879 id = atoi (preventa_txt2); 880 881 //Si es un id valido 882 if (id > 0) 883 { 884 /*TODO: Se debería dejar que la preventa de agregue a la lista 885 junto a productos anteriormente agregados. Se debe cuidar que una 886 misma pre-venta no se cargue 2 veces en la misma lista. 887 Para ello debe haber una especie de 'manejo' de pre-venta.*/ 888 gtk_list_store_clear (sell); 889 CleanEntryAndLabelData (); 890 ListClean (); 891 892 //Se obtiene la preventa, si el id es del tipo PV 893 if (g_str_equal (preventa_txt1, "PV")) 894 q = g_strdup_printf ("SELECT barcode, cantidad, precio " 895 "FROM preventa_detalle pvd " 896 "INNER JOIN preventa pv " 897 "ON pvd.id_preventa = pv.id " 898 "WHERE pv.id = %d " 899 "AND pv.vendido = false", id); 900 //Se obtiene la reserva, si el id es del tipo RV 901 else if (g_str_equal (preventa_txt1, "RV")) 902 q = g_strdup_printf ("SELECT barcode, cantidad, precio FROM reserva_detalle WHERE id_reserva = %d", id); 903 904 res = EjecutarSQL (q); 905 g_free (q); 906 907 if (res != NULL && PQntuples (res) != 0) 908 { 909 tuples = PQntuples (res); 910 911 /*Se agregan las mercaderías independientemente de si tienen o no stock (al realizar el pago total de venta 912 ésta se finalizará y en ese proceso se debe exigir el stock suficiente de cada mercadería)*/ 913 for (i = 0; i < tuples; i++) 914 { 915 AgregarALista (NULL, PQvaluebycol (res, i, "barcode"), strtod (PUT (PQvaluebycol (res, i, "cantidad")), (char **)NULL)); 916 917 //Se reemplazan los 2 precios, para asegurarse que se venda con el precio puesto en el pedido, sin importar si la mercadería esta por mayor o no 918 venta->products->product->precio = strtod (PUT (PQvaluebycol (res, i, "precio")), (char **)NULL); 919 venta->products->product->precio_mayor = strtod (PUT (PQvaluebycol (res, i, "precio")), (char **)NULL); 920 921 iva = (gdouble)venta->products->product->iva / 100; 922 otros = (gdouble)venta->products->product->otros / 100; 923 venta->products->product->precio_neto = (venta->products->product->precio / (1 + otros + iva)); 924 925 gtk_list_store_insert_after (sell, &iter, NULL); 926 gtk_list_store_set (sell, &iter, 927 0, venta->products->product->codigo, 928 1, g_strdup_printf ("%s %s %d %s", 929 venta->products->product->producto, 930 venta->products->product->marca, 931 venta->products->product->contenido, 932 venta->products->product->unidad), 933 2, venta->products->product->cantidad, 934 3, venta->products->product->precio_neto, 935 4, lround (venta->products->product->cantidad * venta->products->product->precio_neto), 936 5, venta->products->product->precio, 937 6, lround (venta->products->product->cantidad * venta->products->product->precio), 938 7, venta->products->product->stock, 939 8, venta->products->product->cantidad_impresa, 940 9, (venta->products->product->cantidad > venta->products->product->stock) ? "Red":"Black", 941 10, TRUE, 942 -1); 943 944 venta->products->product->iter = iter; 945 } 946 947 total = llround (CalcularTotal (venta->header)); 948 949 gtk_label_set_markup (GTK_LABEL (gtk_builder_get_object (builder, "label_total")), 950 g_strdup_printf ("<span size=\"40000\">%s</span>", 951 PutPoints (g_strdup_printf ("%u", total)))); 952 } 953 else 954 { 955 //No existen datos con ese id 956 gtk_entry_set_text (GTK_ENTRY (builder_get (builder, "entry_id_preventa")), ""); 957 ErrorMSG (GTK_WIDGET (builder_get (builder, "entry_id_preventa")), 958 g_strdup_printf ("No existen datos con el id %s%s", preventa_txt1, preventa_txt2)); 959 return; 960 } 961 962 if (g_str_equal (preventa_txt1, "PV")) 963 venta->id_preventa = id; 964 else if (g_str_equal (preventa_txt2, "RV")) 965 { 966 res = get_data_from_reserva_id (id); 967 if (res == NULL || PQntuples (res) == 0) 968 { 969 //No existen datos con ese id 970 gtk_entry_set_text (GTK_ENTRY (builder_get (builder, "entry_id_preventa")), ""); 971 ErrorMSG (GTK_WIDGET (builder_get (builder, "entry_id_preventa")), 972 g_strdup_printf ("No existen datos con el id %s%s", preventa_txt1, preventa_txt2)); 973 return; 974 } 975 976 venta_reserva = TRUE; 977 venta->deuda_total = atoi (PQvaluebycol (res, 0, "monto")); 978 venta->total_pagado = atoi (PQvaluebycol (res, 0, "monto_pagado")); 979 venta->rut_cliente = atoi (g_strdup (PQvaluebycol(res, 0, "rut_cliente"))); 980 venta->id_reserva = id; 981 } 982 } 983 984 gtk_widget_hide (GTK_WIDGET (builder_get (builder, "wnd_get_preventa"))); 985 986 if (g_str_equal (preventa_txt1, "RV")) 987 TipoVenta (NULL, NULL); 988} 989 990 991/** 992 * Es llamada cuando se presiona el boton "btn_print_preventa" (signal clicked) 993 * 994 * Esta funcion muestra la ventana "wnd_preventa" 995 * 996 * @param button the button 997 * @param user_data the user data 998 */ 999void 1000on_btn_get_preventa_clicked (GtkButton *button, gpointer data) 1001{ 1002 GtkWidget *widget; 1003 1004 widget = GTK_WIDGET (gtk_builder_get_object(builder, "wnd_get_preventa")); 1005 clean_container (GTK_CONTAINER (widget)); 1006 gtk_widget_show(widget); 1007 gtk_widget_grab_focus (GTK_WIDGET (builder_get (builder,"entry_id_preventa"))); 1008} 1009 1010 1011/** 1012 * Main window 1013 */ 1014void 1015ventas_win () 1016{ 1017 GtkTreeViewColumn *column; 1018 GtkCellRenderer *renderer; 1019 GtkTreeIter iter; 1020 GtkWidget *ventas_gui; 1021 GError *error = NULL; 1022 1023 //Inicializacion de la estructura venta 1024 venta = (Venta *) g_malloc (sizeof (Venta)); 1025 venta->header = NULL; 1026 venta->products = NULL; 1027 venta->window = NULL; 1028 venta->id_preventa = 0; 1029 Productos *fill = venta->header; 1030 1031 //TODO: Usar esta estructura para almacenar los datos del cliente seleccionado 1032 cliente = (DatosCliente *) g_malloc (sizeof (DatosCliente)); 1033 1034 //Inicialización de la estructura de cheques de restaurant 1035 pago_chk_rest = (PagoChequesRest *) g_malloc (sizeof (PagoChequesRest)); 1036 pago_chk_rest->header = NULL; 1037 pago_chk_rest->cheques = NULL; 1038 //ChequesRestaurant *fill = pago_chk_rest->header; 1039 1040 //Inicialización de pago mixto 1041 pago_mixto = (PagoMixto *) g_malloc (sizeof (PagoMixto)); 1042 pago_mixto->check_rest1 = NULL; 1043 pago_mixto->check_rest2 = NULL; 1044 1045 //Se inicializa bandera global (venta suscritos) 1046 rut_cliente_pre_factura = 0; 1047 1048 venta->total_pagado = 0; 1049 venta->num_mesa = 0; 1050 1051 builder = gtk_builder_new (); 1052 1053 gtk_builder_add_from_file (builder, DATADIR"/ui/rizoma-ventas.ui", &error); 1054 1055 if (error != NULL) 1056 g_printerr ("%s: %s\n", G_STRFUNC, error->message); 1057 1058 1059 gtk_builder_add_from_file (builder, DATADIR"/ui/rizoma-common.ui", &error); 1060 1061 if (error != NULL) 1062 g_printerr ("%s: %s\n", G_STRFUNC, error->message); 1063 1064 gtk_builder_connect_signals (builder, NULL); 1065 1066 // check if is enabled the print of invoices to show or not show the 1067 // make invoice button 1068 if (!(rizoma_get_value_boolean ("PRINT_FACTURA"))) 1069 { 1070 GtkWidget *aux_widget; 1071 aux_widget = GTK_WIDGET(gtk_builder_get_object (builder, "btn_invoice")); 1072 gtk_widget_hide (aux_widget); 1073 } 1074 1075 if (rizoma_get_value_boolean ("CAJA")) 1076 { 1077 gtk_widget_show (GTK_WIDGET (builder_get (builder, "btn_cash_box_close"))); 1078 } 1079 1080 1081 if (rizoma_get_value_boolean ("TRASPASO")) 1082 { 1083 gtk_widget_show (GTK_WIDGET (builder_get (builder, "btn_traspaso_enviar"))); 1084 } 1085 1086 1087 ventas_gui = GTK_WIDGET (gtk_builder_get_object (builder, "wnd_sell")); 1088 1089 //Titulo 1090 gtk_window_set_title (GTK_WINDOW (ventas_gui), 1091 g_strdup_printf ("POS Rizoma Comercio: Ventas - Conectado a [%s@%s]", 1092 config_profile, 1093 rizoma_get_value ("SERVER_HOST"))); 1094 1095 // check if the window must be set to fullscreen 1096 if (rizoma_get_value_boolean("FULLSCREEN")) 1097 gtk_window_maximize(GTK_WINDOW(ventas_gui)); 1098 1099 gtk_widget_show_all (ventas_gui); 1100 1101 // Se setea el label con el nombre de usuario 1102 gtk_label_set_markup (GTK_LABEL (gtk_builder_get_object (builder, "label_seller_name")), 1103 g_strdup_printf ("<span size=\"15000\">%s</span>", user_data->user)); 1104 1105 1106 // Se setea el label con el número de mesa 1107 gtk_label_set_markup (GTK_LABEL (gtk_builder_get_object (builder, "lbl_num_mesa")), 1108 g_strdup_printf ("<span size=\"15000\">%d</span>", venta->num_mesa)); 1109 1110 // Se setea el label con el número de boleta 1111 gtk_label_set_markup (GTK_LABEL (gtk_builder_get_object (builder, "label_ticket_number")), 1112 g_strdup_printf ("<span size=\"15000\">%.6d</span>", get_ticket_number (SIMPLE)-1)); //antes get_last_sell_id () 1113 1114 // El numerno de venta no se debe basar en el numero de ticket, puesto que aquel corresponde a los documentos que se han emitido 1115 /* gtk_label_set_markup (GTK_LABEL (gtk_builder_get_object (builder, "label_ticket_number")), */ 1116 /* g_strdup_printf ("<b><big>%.6d</big></b>", get_ticket_number (SIMPLE))); */ 1117 1118 venta->store = gtk_list_store_new (11, 1119 G_TYPE_STRING, //CODIGO 1120 G_TYPE_STRING, //DESCRIPCION 1121 G_TYPE_DOUBLE, //CANTIDAD 1122 G_TYPE_DOUBLE, //PRECIO NETO 1123 G_TYPE_INT, //SUB TOTAL NETO 1124 G_TYPE_DOUBLE, //PRECIO FINAL 1125 G_TYPE_INT, //SUB TOTAL FINAL 1126 G_TYPE_DOUBLE, //STOCK 1127 G_TYPE_DOUBLE, //CANTIDAD IMPRESA 1128 G_TYPE_STRING, //COLOR 1129 G_TYPE_BOOLEAN); //COLOREAR 1130 if (venta->header != NULL) 1131 { 1132 gdouble precio, precio_neto; 1133 do 1134 { 1135 1136 if (fill->product->cantidad_mayorista > 0 && fill->product->precio_mayor > 0 && fill->product->cantidad >= fill->product->cantidad_mayorista && 1137 fill->product->mayorista == TRUE) 1138 precio = fill->product->precio_mayor; 1139 else 1140 precio = fill->product->precio; 1141 1142 precio_neto = precio / (fill->product->otros/100 + fill->product->iva/100 + 1); 1143 fill->product->precio_neto = precio_neto; 1144 1145 gtk_list_store_insert_after (venta->store, &iter, NULL); 1146 gtk_list_store_set (venta->store, &iter, 1147 0, fill->product->codigo, 1148 1, g_strdup_printf ("%s %s %d %s", 1149 fill->product->producto, 1150 fill->product->marca, 1151 fill->product->contenido, 1152 fill->product->unidad), 1153 2, fill->product->cantidad, 1154 3, precio_neto, 1155 4, lround (fill->product->cantidad * precio_neto), 1156 5, precio, 1157 6, lround (fill->product->cantidad * precio), 1158 7, fill->product->stock, 1159 8, fill->product->cantidad_impresa, 1160 9, (fill->product->cantidad > fill->product->stock) ? "Red":"Black", 1161 10, TRUE, 1162 -1); 1163 fill = fill->next; 1164 } 1165 while (fill != venta->header); 1166 } 1167 1168 venta->treeview_products = GTK_WIDGET (gtk_builder_get_object (builder, "sell_products_list")); 1169 gtk_tree_view_set_model (GTK_TREE_VIEW (venta->treeview_products), GTK_TREE_MODEL (venta->store)); 1170 1171 renderer = gtk_cell_renderer_text_new (); 1172 column = gtk_tree_view_column_new_with_attributes ("Código", renderer, 1173 "text", 0, 1174 "foreground", 9, 1175 "foreground-set", 10, 1176 NULL); 1177 gtk_tree_view_append_column (GTK_TREE_VIEW (venta->treeview_products), column); 1178 gtk_tree_view_column_set_alignment (column, 0.5); 1179 g_object_set (G_OBJECT (renderer), "xalign", 0.0, "font", "15", NULL); 1180 gtk_tree_view_column_set_resizable (column, FALSE); 1181 1182 renderer = gtk_cell_renderer_text_new (); 1183 column = gtk_tree_view_column_new_with_attributes ("Descripción", renderer, 1184 "text", 1, 1185 "foreground", 9, 1186 "foreground-set", 10, 1187 NULL); 1188 gtk_tree_view_append_column (GTK_TREE_VIEW (venta->treeview_products), column); 1189 gtk_tree_view_column_set_alignment (column, 0.5); 1190 g_object_set (G_OBJECT (renderer), "xalign", 0.0, "font", "15", NULL); 1191 gtk_tree_view_column_set_resizable (column, FALSE); 1192 gtk_tree_view_column_set_min_width (column, 400); 1193 gtk_tree_view_column_set_expand (column, TRUE); 1194 1195 /* renderer = gtk_cell_renderer_text_new (); */ 1196 /* column = gtk_tree_view_column_new_with_attributes ("Marca", renderer, */ 1197 /* "text", 2, */ 1198 /* NULL); */ 1199 /* gtk_tree_view_append_column (GTK_TREE_VIEW (venta->treeview_products), column); */ 1200 /* gtk_tree_view_column_set_alignment (column, 0.5); */ 1201 /* gtk_tree_view_column_set_resizable (column, FALSE); */ 1202 1203 /* renderer = gtk_cell_renderer_text_new (); */ 1204 /* column = gtk_tree_view_column_new_with_attributes ("Cont.", renderer, */ 1205 /* "text", 3, */ 1206 /* NULL); */ 1207 /* gtk_tree_view_append_column (GTK_TREE_VIEW (venta->treeview_products), column); */ 1208 /* gtk_tree_view_column_set_alignment (column, 0.5); */ 1209 /* gtk_tree_view_column_set_resizable (column, FALSE); */ 1210 1211 /* renderer = gtk_cell_renderer_text_new (); */ 1212 /* column = gtk_tree_view_column_new_with_attributes ("Uni.", renderer, */ 1213 /* "text", 4, */ 1214 /* NULL); */ 1215 /* gtk_tree_view_append_column (GTK_TREE_VIEW (venta->treeview_products), column); */ 1216 /* g_object_set (G_OBJECT (renderer), "xalign", 1.0, NULL); */ 1217 /* gtk_tree_view_column_set_resizable (column, FALSE); */ 1218 1219 renderer = gtk_cell_renderer_text_new (); 1220 g_object_set (renderer, "editable", TRUE, NULL); 1221 g_signal_connect (G_OBJECT (renderer), "edited", G_CALLBACK (on_cantidad_sell_edited), (gpointer)venta->store); 1222 column = gtk_tree_view_column_new_with_attributes ("Cant.", renderer, 1223 "text", 2, 1224 "foreground", 9, 1225 "foreground-set", 10, 1226 NULL); 1227 gtk_tree_view_append_column (GTK_TREE_VIEW (venta->treeview_products), column); 1228 gtk_tree_view_column_set_alignment (column, 0.5); 1229 g_object_set (G_OBJECT (renderer), "xalign", 1.0, "font", "15", NULL); 1230 gtk_tree_view_column_set_resizable (column, FALSE); 1231 gtk_tree_view_column_set_cell_data_func (column, renderer, control_decimal, (gpointer)2, NULL); 1232 1233 if (rizoma_get_value_boolean ("MODO_GUIA_FACTURA")) 1234 { 1235 renderer = gtk_cell_renderer_text_new (); 1236 //El precio es editable si PRECIO_DISCRECIONAL esta habilitado 1237 if (rizoma_get_value_boolean ("PRECIO_DISCRECIONAL")) 1238 { 1239 g_object_set (renderer, "editable", TRUE, NULL); 1240 g_signal_connect (G_OBJECT (renderer), "edited", G_CALLBACK (on_precio_neto_sell_edited), (gpointer)venta->store); 1241 } 1242 column = gtk_tree_view_column_new_with_attributes ("Prec. Neto Un.", renderer, 1243 "text", 3, 1244 "foreground", 9, 1245 "foreground-set", 10, 1246 NULL); 1247 gtk_tree_view_append_column (GTK_TREE_VIEW (venta->treeview_products), column); 1248 gtk_tree_view_column_set_alignment (column, 0.5); 1249 g_object_set (G_OBJECT (renderer), "xalign", 1.0, "font", "15", NULL); 1250 gtk_tree_view_column_set_resizable (column, FALSE); 1251 gtk_tree_view_column_set_cell_data_func (column, renderer, control_decimal, (gpointer)3, NULL); 1252 1253 1254 renderer = gtk_cell_renderer_text_new (); 1255 column = gtk_tree_view_column_new_with_attributes ("Sub Total Neto", renderer, 1256 "text", 4, 1257 "foreground", 9, 1258 "foreground-set", 10, 1259 NULL); 1260 gtk_tree_view_append_column (GTK_TREE_VIEW (venta->treeview_products), column); 1261 gtk_tree_view_column_set_alignment (column, 0.5); 1262 g_object_set (G_OBJECT (renderer), "xalign", 1.0, "font", "15", NULL); 1263 gtk_tree_view_column_set_resizable (column, FALSE); 1264 gtk_tree_view_column_set_max_width (column, 100); 1265 gtk_tree_view_column_set_cell_data_func (column, renderer, control_decimal, (gpointer)4, NULL); 1266 } 1267 1268 renderer = gtk_cell_renderer_text_new (); 1269 //El precio es editable si PRECIO_DISCRECIONAL esta habilitado 1270 if (rizoma_get_value_boolean ("PRECIO_DISCRECIONAL")) 1271 { 1272 g_object_set (renderer, "editable", TRUE, NULL); 1273 g_signal_connect (G_OBJECT (renderer), "edited", G_CALLBACK (on_precio_final_sell_edited), (gpointer)venta->store); 1274 } 1275 column = gtk_tree_view_column_new_with_attributes ("Precio Uni.", renderer, 1276 "text", 5, 1277 "foreground", 9, 1278 "foreground-set", 10, 1279 NULL); 1280 gtk_tree_view_append_column (GTK_TREE_VIEW (venta->treeview_products), column); 1281 gtk_tree_view_column_set_alignment (column, 0.5); 1282 g_object_set (G_OBJECT (renderer), "xalign", 1.0, "font", "15", NULL); 1283 gtk_tree_view_column_set_resizable (column, FALSE); 1284 gtk_tree_view_column_set_cell_data_func (column, renderer, control_decimal, (gpointer)5, NULL); 1285 1286 renderer = gtk_cell_renderer_text_new (); 1287 column = gtk_tree_view_column_new_with_attributes ("Sub Total", renderer, 1288 "text", 6, 1289 "foreground", 9, 1290 "foreground-set", 10, 1291 NULL); 1292 gtk_tree_view_append_column (GTK_TREE_VIEW (venta->treeview_products), column); 1293 gtk_tree_view_column_set_alignment (column, 0.5); 1294 g_object_set (G_OBJECT (renderer), "xalign", 1.0, "font", "15", NULL); 1295 gtk_tree_view_column_set_resizable (column, FALSE); 1296 gtk_tree_view_column_set_max_width (column, 100); 1297 gtk_tree_view_column_set_cell_data_func (column, renderer, control_decimal, (gpointer)6, NULL); 1298 1299 if (venta->header != NULL) 1300 CalcularVentas (venta->header); 1301 1302 gtk_widget_grab_focus (GTK_WIDGET (gtk_builder_get_object (builder, "barcode_entry"))); 1303 1304 if (rizoma_get_value_boolean ("CAJA")) 1305 { 1306 if (check_caja()) 1307 { 1308 open_caja (FALSE); 1309 } 1310 else 1311 { 1312 gtk…
Large files files are truncated, but you can click here to view the full file