+void fact_agregar(char *s)
+{
+ WINDOW *win, *items;
+ t_Form *form;
+ 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);
+ 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);
+
+ fact.numero = form_obtener_valor_int(form, "Numero de Factura");
+ fprintf(stderr, "Agregando numero %d\n", fact.numero);
+ 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");
+ 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') {
+ 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));
+ its[cant-1].numero = form_obtener_valor_int(form, entrada);
+ strcpy(its[cant-1].cv, form_obtener_valor_char(form, "CV"));
+ strcpy(its[cant-1].pvu, form_obtener_valor_char(form, "PVU"));
+ }
+ } while (strcmp(entrada, "*") != 0);
+
+ if (lst_facturas->fp->tipo == 3) {
+ if (cant != 10) {
+ /* TODO Limitar en la GUI en lugar de truncar! */
+ its = (t_Item *)realloc(its, 10*sizeof(t_Item));
+ cant = 10;
+ }
+ }
+ fact.items = its;
+ fact.cant_items = cant;
+
+ entrada = procesar_guardar_factura(&fact,lst_facturas, &size);
+ if (entrada) {
+ id = lst_facturas->fp->grabar_registro(lst_facturas->fp, entrada, size, &error);
+ /*id_texto = tmp->fp_texto->grabar_registro(tmp->fp_texto, fact.nota, 400, &error);*/
+ /* TODO : -1 == id_texto !!!!!!!! XXX XXX XXX XXX XXX XXX XXX */
+ agregar_nodo_factura(lst_facturas, crear_nodo_factura(id, -1, fact.numero));
+ free(entrada);
+ }
+
+ if (its) free(its);
+ form_destruir(form);
+
+ werase(win);
+ wrefresh(win);
+ delwin(items);
+ delwin(win);
+}
+
+void *procesar_guardar_factura(t_Factura *f, t_LstFacturas *lst, EMUFS_REG_SIZE *size)