+void fact_modificar(char *s)
+{
+ WINDOW *win, *items, *nota, *subnota;
+ t_Form *form, *form_nota;
+ t_Factura *fact;
+ EMUFS_REG_SIZE size;
+ EMUFS_REG_ID id, id_texto;
+ int error;
+ char tmp_str[10];
+ void *entrada;
+
+
+ win = newwin(LINES-4, COLS-2, 2, 1);
+ box(win, 0, 0);
+
+ fact = fact_form_buscar(win, &id, &id_texto);
+
+ if (fact == NULL) {
+ wattron(win, COLOR_PAIR(COLOR_YELLOW));
+ mvwaddstr(win, 2, 1, "No existe artículo con ese código. Abortando!");
+ wattroff(win, COLOR_PAIR(COLOR_YELLOW));
+ wrefresh(win);
+ getch();
+ werase(win);
+ wrefresh(win);
+ delwin(win);
+ return;
+ }
+
+ mvwaddch(win, 10, 0, ACS_LTEE);
+ mvwhline(win, 10, 1, ACS_HLINE, COLS-3);
+ mvwaddch(win, 10, COLS-3, ACS_RTEE);
+ wrefresh(win);
+
+ items = derwin(win, LINES-20, COLS-4, 15, 1);
+ nota = derwin(win, 9, COLS-62, 1, 56);
+ subnota = derwin(nota, 7, COLS-64, 1, 1);
+ box(nota, 0, 0);
+ mvwaddstr(nota, 0, 1, "Nota :");
+ wrefresh(nota);
+ wrefresh(items);
+
+ form = form_crear(win);
+ sprintf(tmp_str, "%08d", fact->numero);
+ form_agregar_widget(form, INPUT, "Numero de Factura", 8, tmp_str);
+ form_agregar_widget(form, INPUT, "Fecha Emision", 8, fact->emision);
+ form_agregar_widget(form, INPUT, "Fecha Vto", 8, fact->vencimiento);
+ sprintf(tmp_str, "%08d", fact->numero_remito);
+ form_agregar_widget(form, INPUT, "Nro Remito", 8, tmp_str);
+ form_agregar_widget(form, RADIO, "Estado", 6, "PN,CD,CM,SF,PM,NC");
+ form_agregar_widget(form, RADIO, "Forma de pago", 3, "CO,CR,CH");
+ sprintf(tmp_str, "%02.2f", fact->procdoi);
+ form_agregar_widget(form, INPUT, "%% Descuento", 5, tmp_str);
+ form_agregar_widget(form, INPUT, "Cuenta Cte", 5, fact->ctacte);
+ form_agregar_widget(form, INPUT, "Cheque Nro", 18, fact->cheque);
+
+ mvwaddstr(subnota, 0, 0, fact->nota);
+ wrefresh(subnota);
+ form_ejecutar(form, 1,1);
+
+ form_nota = form_crear(subnota);
+ form_agregar_widget(form_nota, INPUT, "", 255, fact->nota);
+ form_ejecutar(form_nota, 0, 0);
+
+ fact->numero = form_obtener_valor_int(form, "Numero de Factura");
+ strcpy(fact->emision, form_obtener_valor_char(form, "Fecha Emision"));
+ strcpy(fact->vencimiento, form_obtener_valor_char(form, "Fecha Vto"));
+ fact->numero_remito = form_obtener_valor_int(form, "Nro Remito");
+ strcpy(fact->estado, form_obtener_valor_char(form, "Estado"));
+ strcpy(fact->fp, form_obtener_valor_char(form, "Forma de pago"));
+ fact->procdoi = form_obtener_valor_float(form, "%% Descuento");
+ strcpy(fact->ctacte, form_obtener_valor_char(form, "Cuenta Cte"));
+ strcpy(fact->cheque, form_obtener_valor_char(form, "Cheque Nro"));
+
+ form_destruir(form);
+
+ free(fact->nota);
+ fact->nota = form_obtener_valor_char(form_nota, "");
+
+ form_destruir(form_nota);
+
+ entrada = procesar_guardar_factura(fact, lst_facturas, &size);
+ if (entrada) {
+ id = lst_facturas->fp->modificar_registro(lst_facturas->fp, id, entrada, size, &error);
+ id_texto = lst_facturas->fp_texto->modificar_registro(lst_facturas->fp_texto, id_texto, fact->nota, strlen(fact->nota)+1, &error);
+ free(entrada);
+ }
+
+ free(fact->items);
+ free(fact);
+
+ werase(win);
+ wrefresh(win);
+ delwin(subnota);
+ delwin(nota);
+ delwin(items);
+ delwin(win);
+}
+
+void fact_agregar(char *s)
+{
+ WINDOW *win, *items, *nota, *subnota;
+ t_Form *form, *form_nota;
+ t_Item *its = NULL;
+ t_Factura fact;
+ EMUFS_REG_SIZE size;
+ EMUFS_REG_ID id, id_texto;
+ int y_actual, cant, error;
+ char *entrada;
+
+ win = newwin(LINES-4, COLS-2, 2, 1);
+ box(win, 0, 0);
+ mvwaddch(win, 10, 0, ACS_LTEE);
+ mvwhline(win, 10, 1, ACS_HLINE, COLS-3);
+ mvwaddch(win, 10, COLS-3, ACS_RTEE);
+ wrefresh(win);
+
+ items = derwin(win, LINES-20, COLS-4, 15, 1);
+ nota = derwin(win, 9, COLS-62, 1, 56);
+ subnota = derwin(nota, 7, COLS-64, 1, 1);
+ box(nota, 0, 0);
+ mvwaddstr(nota, 0, 1, "Nota :");
+ wrefresh(nota);
+ wrefresh(items);
+
+ form = form_crear(win);
+ form_agregar_widget(form, INPUT, "Numero de Factura", 8, "");
+ form_agregar_widget(form, INPUT, "Fecha Emision", 8, "");
+ form_agregar_widget(form, INPUT, "Fecha Vto", 8, "");
+ form_agregar_widget(form, INPUT, "Nro Remito", 8, "");
+ form_agregar_widget(form, RADIO, "Estado", 6, "PN,CD,CM,SF,PM,NC");
+ form_agregar_widget(form, RADIO, "Forma de pago", 3, "CO,CR,CH");
+ form_agregar_widget(form, INPUT, "%% Descuento", 5, "");
+ form_agregar_widget(form, INPUT, "Cuenta Cte", 5, "");
+ form_agregar_widget(form, INPUT, "Cheque Nro", 18, "");
+
+ form_ejecutar(form, 1,1);
+
+ form_nota = form_crear(subnota);
+ form_agregar_widget(form_nota, INPUT, "", 255, "");
+ form_ejecutar(form_nota, 0, 0);
+
+ /* XXX No destruir form_nota hasta el final !!!!! XXX */
+
+ fact.numero = form_obtener_valor_int(form, "Numero de Factura");
+ strcpy(fact.emision, form_obtener_valor_char(form, "Fecha Emision"));
+ strcpy(fact.vencimiento, form_obtener_valor_char(form, "Fecha Vto"));
+ fact.numero_remito = form_obtener_valor_int(form, "Nro Remito");
+ strcpy(fact.estado, form_obtener_valor_char(form, "Estado"));
+ strcpy(fact.fp, form_obtener_valor_char(form, "Forma de pago"));
+ fact.procdoi = form_obtener_valor_float(form, "%% Descuento");
+ strcpy(fact.ctacte, form_obtener_valor_char(form, "Cuenta Cte"));
+ strcpy(fact.cheque, form_obtener_valor_char(form, "Cheque Nro"));
+
+ form_destruir(form);
+
+ form = form_crear(win);
+ form_agregar_widget(form, INPUT, "Nro de Articulo (* == fin)", 8, "");
+ form_agregar_widget(form, INPUT, "CV", 8, "");
+ form_agregar_widget(form, INPUT, "PVU", 8, "");
+ y_actual = 0;
+ scrollok(items, 1);
+ mvwaddstr(win, 15, 2, "Numero");
+ mvwaddstr(win, 15, 11, "CV");
+ mvwaddstr(win, 15, 21, "PVU");
+ cant = 0;
+ do {
+ form_set_valor(form, "Nro de Articulo (* == fin)", "");
+ form_set_valor(form, "CV", "");
+ form_set_valor(form, "PVU", "");
+ form_ejecutar(form, 2, 11);
+
+ entrada = form_obtener_valor_char(form, "Nro de Articulo (* == fin)");
+
+ if ((entrada[0] != '\0') && (entrada[0] != '*')){
+ y_actual++;
+ if (y_actual > LINES-22) {
+ y_actual = LINES-22;
+ wscrl(items, 1);
+ }
+ mvwaddstr(items, y_actual, 1, entrada);
+ mvwaddstr(items, y_actual, 10, form_obtener_valor_char(form, "CV"));
+ mvwaddstr(items, y_actual, 20, form_obtener_valor_char(form, "PVU"));
+ wrefresh(items);
+ /* Agrego el Item */
+ cant++;
+ its = (t_Item *)realloc(its, cant*sizeof(t_Item));
+ if (its != NULL) {
+ its[cant-1].numero = atoi(entrada);
+ strcpy(its[cant-1].cv, form_obtener_valor_char(form, "CV"));
+ strcpy(its[cant-1].pvu, form_obtener_valor_char(form, "PVU"));
+ }
+ }
+ } while (entrada[0] != '*');
+
+ if (lst_facturas->fp->tipo == T3) {
+ if (cant != 10) {
+ /* TODO Limitar en la GUI en lugar de truncar! */
+ its = (t_Item *)realloc(its, 10*sizeof(t_Item));
+ if (its == NULL) {
+ cant = 0;
+ } else {
+ memset(its+sizeof(t_Item)*cant, 0, (10-cant)*sizeof(t_Item));
+ cant = 10;
+ }
+ }
+ }
+ fact.items = its;
+ fact.cant_items = cant;
+ fact.nota = form_obtener_valor_char(form_nota, "");
+
+ entrada = procesar_guardar_factura(&fact,lst_facturas, &size);
+ if (entrada) {
+ error = 0;
+ id = lst_facturas->fp->grabar_registro(lst_facturas->fp, entrada, size, &error);
+ id_texto = lst_facturas->fp_texto->grabar_registro(lst_facturas->fp_texto, fact.nota, strlen(fact.nota)+1, &error);
+ agregar_nodo_factura(lst_facturas, crear_nodo_factura(id, id_texto, fact.numero));
+ free(entrada);
+ }
+
+ if (its) free(its);
+ form_destruir(form);
+ form_destruir(form_nota);
+
+ werase(win);
+ wrefresh(win);
+ delwin(items);
+ delwin(subnota);
+ delwin(nota);
+ delwin(win);
+}
+
+void *procesar_guardar_factura(t_Factura *f, t_LstFacturas *lst, EMUFS_REG_SIZE *size)