char *xml_get_prop(xmlNode *node, char *nombre)
{
char *s;
- if (xmlGetProp(node, nombre) == NULL) {
+ s = xmlGetProp(node, nombre);
+ if (s == NULL) {
s = malloc(1);
s[0] = '\0';
return s;
}
- return xmlGetProp(node, nombre);
+ return s;
}
int eliminar_nodo_factura(t_LstFacturas *lst, t_Reg_Factura *nodo)
int count;
char *prop;
if (size == -1) {
- *cant = 0;
- return NULL;
+ tmp = NULL;
+ count = 0;
+ node = node->children;
+ while (node) {
+ if (node->type == XML_ELEMENT_NODE) {
+ if (strcmp(node->name, "ITEMVENTA") == 0) {
+ count++;
+ tmp = realloc(tmp, sizeof(t_Item)*count);
+ memset(&tmp[count-1], 0, sizeof(t_Item));
+ prop = xml_get_prop(node, "NroArtículo");
+ tmp[count-1].numero = atoi(prop);
+ xmlFree(prop);
+ strcpy(tmp[count-1].cv, prop = xml_get_prop(node, "CV")); xmlFree(prop);
+ strcpy(tmp[count-1].pvu, prop = xml_get_prop(node, "PVU")); xmlFree(prop);
+ }
+ }
+ node = node->next;
+ }
+ *cant = count;
} else {
(*cant) = size;
tmp = (t_Item *)malloc(sizeof(t_Item)*size);
count++;
}
}
+ if (count == 10) break; /* No me entran mas items! */
node = node->next;
}
}
PERR("Voy a cargar de un XML");
document = xmlReadFile(filename, "ISO-8859-1",0);
if (document == NULL) {
+ PERR("Error al leer documento!!");
free(tmp);
lst_facturas = NULL;
return NULL;
/* En el registro no guardo los punteros de nota ni items. Si guardo la cantidad de items
* y los items al final del registro.
*/
- if (tipo == 3) {
+ if (tipo == T3) {
/* Limito a 10 items en el caso de registro constante! */
cant_items = 10;
} else {
fact.procdoi = atof(prop); xmlFree(prop);
prop = xml_get_prop(node, "NroRemito");
fact.numero_remito = atoi(prop); xmlFree(prop);
- strcpy(fact.emision, prop = xml_get_prop(node, "FechaEmisión")); xmlFree(prop);
- strcpy(fact.vencimiento, prop = xml_get_prop(node, "FechaVto")); xmlFree(prop);
- strcpy(fact.estado, prop = xml_get_prop(node, "Estado")); xmlFree(prop);
- strcpy(fact.fp, prop = xml_get_prop(node, "FP")); xmlFree(prop);
- strcpy(fact.ctacte, prop = xml_get_prop(node, "NroCtaCte")); xmlFree(prop);
- strcpy(fact.cheque, prop = xml_get_prop(node, "NroCheque")); xmlFree(prop);
+ strncpy(fact.emision, prop = xml_get_prop(node, "FechaEmisión"), 8); xmlFree(prop);
+ fact.emision[8] = '\0';
+ strncpy(fact.vencimiento, prop = xml_get_prop(node, "FechaVto"), 8); xmlFree(prop);
+ fact.vencimiento[8] = '\0';
+ strncpy(fact.estado, prop = xml_get_prop(node, "Estado"), 2); xmlFree(prop);
+ fact.estado[2] = '\0';
+ strncpy(fact.fp, prop = xml_get_prop(node, "FP"), 2); xmlFree(prop);
+ fact.fp[2] = '\0';
+ strncpy(fact.ctacte, prop = xml_get_prop(node, "NroCtaCte"), 5); xmlFree(prop);
+ fact.ctacte[5] = '\0';
+ strncpy(fact.cheque, prop = xml_get_prop(node, "NroCheque"), 18); xmlFree(prop);
+ fact.cheque[18] = '\0';
fact.nota = leer_nota(node);
- fact.items = leer_items(node, &fact.cant_items, (tipo==3)?10:-1);
+ fact.items = leer_items(node, &fact.cant_items, ((tipo-1)==T3)?10:-1);
error = 0;
id = tmp->fp_texto->grabar_registro(tmp->fp_texto, fact.nota, strlen(fact.nota)+1, &error);
}
free(indices);
}
+
+ PERR("Facturas todo Ok");
return lst_facturas;
}
int fact_liberar(t_LstFacturas *l)
{
+ t_Reg_Factura *del;
if (l == NULL) l = lst_facturas;
if (l == NULL) return 1;
emufs_destruir(l->fp);
+ emufs_destruir(l->fp_texto);
+ while (l->primero) {
+ del = l->primero;
+ l->primero = l->primero->sig;
+ free(del);
+ }
free(l);
lst_facturas = NULL;
void fact_agregar(char *s)
{
- WINDOW *win, *items;
- t_Form *form;
+ WINDOW *win, *items, *nota, *subnota;
+ t_Form *form, *form_nota;
t_Item *its = NULL;
t_Factura fact;
EMUFS_REG_SIZE size;
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_ejecutar(form, 1,1);
+ form_nota = form_crear(subnota);
+ form_agregar_widget(form_nota, INPUT, "", 255, "");
+ form_ejecutar(form_nota, 0, 0);
+
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.cheque, form_obtener_valor_char(form, "Cheque Nro"));
form_destruir(form);
+ form_destruir(form_nota);
form = form_crear(win);
form_agregar_widget(form, INPUT, "Nro de Articulo (* == fin)", 8, "");
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", "");
entrada = form_obtener_valor_char(form, "Nro de Articulo (* == fin)");
- if (entrada[0] != '\0') {
+ if ((entrada[0] != '\0') && (entrada[0] != '*')){
y_actual++;
if (y_actual > LINES-22) {
y_actual = LINES-22;
/* 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"));
+ 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 (strcmp(entrada, "*") != 0);
+ } while (entrada[0] != '*');
- if (lst_facturas->fp->tipo == 3) {
+ 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));
- cant = 10;
+ if (its == NULL) {
+ cant = 0;
+ } else {
+ memset(its+sizeof(t_Item)*cant, 0, (10-cant)*sizeof(t_Item));
+ cant = 10;
+ }
}
}
fact.items = its;
werase(win);
wrefresh(win);
delwin(items);
+ delwin(subnota);
+ delwin(nota);
delwin(win);
}
memset(tmp, 0, *size);
/* Ahora copio la info */
memcpy(tmp, &f->numero, i[0]);
- memcpy(tmp, &f->procdoi, i[1]);
- memcpy(tmp, &f->numero_remito, i[2]);
- memcpy(tmp, &f->cant_items, i[3]);
- memcpy(tmp, &f->reg_nota, i[4]);
+ memcpy(tmp+i[0], &f->procdoi, i[1]);
+ memcpy(tmp+i[0]+i[1], &f->numero_remito, i[2]);
+ memcpy(tmp+i[0]+i[1]+i[2], &f->cant_items, i[3]);
+ memcpy(tmp+i[0]+i[1]+i[2]+i[3], &f->reg_nota, i[4]);
memcpy(tmp+i[0]+i[1]+i[2]+i[3]+i[4], f->emision, i[5]);
memcpy(tmp+i[0]+i[1]+i[2]+i[3]+i[4]+i[5], f->vencimiento, i[6]);
memcpy(tmp+i[0]+i[1]+i[2]+i[3]+i[4]+i[5]+i[6], f->estado, i[7]);
memcpy(tmp+i[0]+i[1]+i[2]+i[3]+i[4]+i[5]+i[6]+i[7], f->fp, i[8]);
memcpy(tmp+i[0]+i[1]+i[2]+i[3]+i[4]+i[5]+i[6]+i[7]+i[8], f->ctacte, i[9]);
memcpy(tmp+i[0]+i[1]+i[2]+i[3]+i[4]+i[5]+i[6]+i[7]+i[8]+i[9], f->cheque, i[10]);
- memcpy(tmp+i[0]+i[1]+i[2]+i[3]+i[4]+i[5]+i[6]+i[7]+i[8]+i[9]+i[10], f->items, i[11]);
+ if (i[11] != 0)
+ memcpy(tmp+i[0]+i[1]+i[2]+i[3]+i[4]+i[5]+i[6]+i[7]+i[8]+i[9]+i[10], f->items, i[11]);
break;
case T3:
(*size) = sizeof(t_Factura)-sizeof(char *)-sizeof(t_Item *) + f->cant_items*sizeof(t_Item);