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()
{
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);
+ strncpy(tmp[count-1].cv, prop = xml_get_prop(node, "CV"), 8); xmlFree(prop);
+ tmp[count-1].cv[8] = '\0';
+ strncpy(tmp[count-1].pvu, prop = xml_get_prop(node, "PVU"), 8); xmlFree(prop);
+ tmp[count-1].pvu[8] = '\0';
}
}
node = node->next;
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);
- strcpy(tmp[count].cv, prop = xml_get_prop(node, "CV")); xmlFree(prop);
- strcpy(tmp[count].pvu, prop = xml_get_prop(node, "PVU")); xmlFree(prop);
+ strncpy(tmp[count].cv, prop = xml_get_prop(node, "CV"), 8); xmlFree(prop);
+ tmp[count].cv[8] = '\0';
+ strncpy(tmp[count].pvu, prop = xml_get_prop(node, "PVU"), 8); xmlFree(prop);
+ tmp[count].pvu[8] = '\0';
count++;
}
}
return tmp;
}
-char *leer_nota(xmlNode *node)
+char *leer_nota(xmlNode *node, int max)
{
xmlNode *tmp;
char *salida;
}
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;
}
-t_LstFacturas *fact_cargar(const char *filename, int tipo, int tam_bloque)
+t_LstFacturas *fact_cargar(const char *filename, int tipo, int tam_bloque, int tipo_nota, int bloque_nota)
{
xmlDocPtr document;
xmlNode *node, *inicio;
cant_items = 0;
}
tmp->fp = emufs_crear("facturas", tipo-1, tam_bloque, sizeof(t_Factura)-sizeof(char *)-sizeof(t_Item*)+cant_items*sizeof(t_Item));
- tmp->fp_texto = emufs_crear("notas", T2, 100, 0);
+#ifdef DEBUG
+ fprintf(stderr, "Facturas : Tipo=%d Tam Bloque = %d\n", tipo-1, tam_bloque);
+ fprintf(stderr, "Notas : Tipo=%d Tam Bloque = %d\n", tipo_nota-1, bloque_nota);
+#endif
+ tmp->fp_texto = emufs_crear("notas", tipo_nota-1, bloque_nota, 100);
for (node=inicio ; node ; node = node->next) {
if (node->type == XML_ELEMENT_NODE) {
if (strcmp(node->name, "FACTURA") == 0) {
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) {
{
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;
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));
PERR("==== TERMINE ====\n");
}
+int fact_exportar_xml(const char *filename)
+{
+ int j;
+ t_Reg_Factura *nodo;
+ t_Factura *fact;
+ EMUFS_REG_ID id, id1;
+ FILE *fp;
+
+ if (lst_facturas->primero == NULL) return 0;
+
+ nodo = lst_facturas->primero;
+
+ if (!(fp = fopen(filename, "wt"))) return 0;
+
+ fprintf(fp, "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\n");
+ fprintf(fp, "<FACTURAS>\n");
+ while (nodo) {
+ fact = fact_buscar(lst_facturas, nodo->numero, &id, &id1);
+ fprintf(fp, "\t<FACTURA NroFac=\"%08d\" ", nodo->numero);
+ fprintf(fp, "FechaEmisión=\"%s\" ", fact->emision);
+ fprintf(fp, "FechaVto=\"%s\" ", fact->vencimiento);
+ fprintf(fp, "NroRemito=\"%08d\" ", fact->numero_remito);
+ fprintf(fp, "FP=\"%s\" ", fact->fp);
+ fprintf(fp, "Estado=\"%s\" ", fact->estado);
+ fprintf(fp, "NroCheque=\"%s\" ", fact->cheque);
+ fprintf(fp, "PorcDoI=\"%.2f\" ", fact->procdoi);
+ fprintf(fp, "NroCtaCte=\"%s\" ", fact->ctacte);
+ fprintf(fp, ">\n");
+ fprintf(fp, "\t\t<NOTA>%s</NOTA>\n", fact->nota);
+ for(j=0; j<fact->cant_items; j++) {
+ if (fact->items[j].numero != 0)
+ fprintf(fp, "\t\t<ITEMVENTA NroArtículo=\"%08d\" CV=\"%s\" PVU=\"%s\" />\n", fact->items[j].numero, fact->items[j].cv, fact->items[j].pvu);
+ }
+ fprintf(fp, "\t</FACTURA>\n");
+ nodo = nodo->sig;
+ }
+ fprintf(fp, "\t</FACTURAS>\n");
+
+ fclose(fp);
+ return 1;
+}
+