X-Git-Url: https://git.llucax.com/z.facultad/75.06/emufs.git/blobdiff_plain/7c4ffe61bc88d99fe6dd9da2c07c1a5de559b833..24b28f65b96a6b8d067751e3bf6715453df781aa:/emufs_gui/facturas.c diff --git a/emufs_gui/facturas.c b/emufs_gui/facturas.c index 254e35e..9573213 100644 --- a/emufs_gui/facturas.c +++ b/emufs_gui/facturas.c @@ -12,7 +12,7 @@ static t_Reg_Factura *crear_nodo_factura(EMUFS_REG_ID reg, EMUFS_REG_ID texto, u static int agregar_nodo_factura(t_LstFacturas *lst, t_Reg_Factura *nodo); int eliminar_nodo_factura(t_LstFacturas *lst, t_Reg_Factura *nodo); static t_Item *leer_items(xmlNode *, int *cant, int size); -static char *leer_nota(xmlNode *); +static char *leer_nota(xmlNode *, int max); t_LstFacturas *fact_get_lst() { @@ -116,14 +116,14 @@ t_Item *leer_items(xmlNode *node, int *cant, int size) while (node) { if (node->type == XML_ELEMENT_NODE) { if (strcmp(node->name, "ITEMVENTA") == 0) { - memset(&tmp[count], '*', sizeof(t_Item)); + memset(&tmp[count], 0, sizeof(t_Item)); prop = xml_get_prop(node, "NroArtículo"); tmp[count].numero = atoi(prop); xmlFree(prop); strncpy(tmp[count].cv, prop = xml_get_prop(node, "CV"), 8); xmlFree(prop); - tmp[count-1].cv[8] = '\0'; + tmp[count].cv[8] = '\0'; strncpy(tmp[count].pvu, prop = xml_get_prop(node, "PVU"), 8); xmlFree(prop); - tmp[count-1].pvu[8] = '\0'; + tmp[count].pvu[8] = '\0'; count++; } } @@ -134,7 +134,7 @@ t_Item *leer_items(xmlNode *node, int *cant, int size) return tmp; } -char *leer_nota(xmlNode *node) +char *leer_nota(xmlNode *node, int max) { xmlNode *tmp; char *salida; @@ -149,11 +149,22 @@ char *leer_nota(xmlNode *node) } if (tmp) { - salida = (char *)malloc(sizeof(char)*(strlen(XML_GET_CONTENT(tmp->children))+1)); - strcpy(salida, XML_GET_CONTENT(tmp->children)); + if (max == -1) { + salida = (char *)malloc(sizeof(char)*(strlen(XML_GET_CONTENT(tmp->children))+1)); + strcpy(salida, XML_GET_CONTENT(tmp->children)); + } else { + salida = (char *)malloc(sizeof(char)*max); + strncpy(salida, XML_GET_CONTENT(tmp->children), max-1); + salida[max-1] = '\0'; + } } else { - salida = (char *)malloc(sizeof(char)); - salida[0] = '\0'; + if (max == -1) { + salida = (char *)malloc(sizeof(char)); + salida[0] = '\0'; + } else { + salida = (char *)malloc(sizeof(char)*max); + memset(salida, 0, max); + } } return salida; } @@ -239,11 +250,11 @@ t_LstFacturas *fact_cargar(const char *filename, int tipo, int tam_bloque, int t strncpy(fact.cheque, prop = xml_get_prop(node, "NroCheque"), 18); xmlFree(prop); fact.cheque[18] = '\0'; - fact.nota = leer_nota(node); + fact.nota = leer_nota(node, (((tipo-1)==T3)?100:-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); + id = tmp->fp_texto->grabar_registro(tmp->fp_texto, fact.nota, ((tipo-1)==T3)?100:(strlen(fact.nota)+1), &error); fact.reg_nota = id; save = procesar_guardar_factura(&fact, lst_facturas, &size); if (save != NULL) { @@ -407,6 +418,7 @@ void fact_modificar(char *s) { WINDOW *win, *items, *nota, *subnota; t_Form *form, *form_nota; + t_Reg_Factura *nodo; t_Factura *fact; EMUFS_REG_SIZE size; EMUFS_REG_ID id, id_texto; @@ -418,7 +430,20 @@ void fact_modificar(char *s) win = newwin(LINES-4, COLS-2, 2, 1); box(win, 0, 0); - fact = fact_form_buscar(win, &id, &id_texto); + if (s == NULL) { + fact = fact_form_buscar(win, &id, &id_texto); + } else { + id = atoi(s); + fact = NULL; + nodo = lst_facturas->primero; + while (nodo) { + if (nodo->num_reg == id) { + fact = fact_buscar(lst_facturas, nodo->numero, &id, &id_texto); + break; + } + nodo = nodo->sig; + } + } if (fact == NULL) { wattron(win, COLOR_PAIR(COLOR_YELLOW));