3 |
from ConfigParser import ConfigParser |
from ConfigParser import ConfigParser |
4 |
from sys import argv |
from sys import argv |
5 |
import os |
import os |
6 |
|
from pprint import pprint |
7 |
|
|
8 |
# ordena los campos imprimibles |
# ordena los campos imprimibles |
9 |
# para poder ir escribiendolos linea a linea |
# para poder ir escribiendolos linea a linea |
20 |
elif a[2]>b[2]: |
elif a[2]>b[2]: |
21 |
return 1 |
return 1 |
22 |
|
|
23 |
# toma de parametros |
def readXYConfigSection (section, fieldsToRead): |
24 |
printer= argv[1] |
fields= [] |
25 |
document_type= argv[2] |
for field in fieldsToRead: |
26 |
inFile=argv[3] |
optionValue= config.get (section, field) |
27 |
|
try: |
28 |
|
(x, y)= optionValue.split (',') |
29 |
|
except ValueError: |
30 |
|
# ['detail_first_row', 'detail_last_row'] have no x coord |
31 |
|
x= '0' |
32 |
|
y= config.get (section, field) |
33 |
|
fields.append ([field, int(x), int(y)]) |
34 |
|
return fields |
35 |
|
|
36 |
|
def splitAndClean (line): |
37 |
|
# take out trailing '\n' |
38 |
|
line= line[:-1] |
39 |
|
# the [1:-1] thing is for taking out quotes |
40 |
|
# this relies in that data has no commas :( |
41 |
|
return map (lambda x: x[1:-1], line.split(',')) |
42 |
|
|
43 |
|
|
44 |
|
# toma de parametros |
45 |
|
document_type= argv[1] |
46 |
|
dataFile=argv[2] |
47 |
|
|
48 |
# process the configuration |
# process the configuration |
49 |
config= ConfigParser () |
config= ConfigParser () |
50 |
config.read (['../print/print-'+printer+'-'+document_type+'.cfg']) |
config.read (['../print/print-'+document_type+'.cfg']) |
51 |
|
|
52 |
fields= [] |
fields= [] |
53 |
|
|
54 |
section= 'main' |
section= 'main' |
55 |
for option in ['date', 'name', 'address', 'net_total', 'tax', 'total']: |
headerFields= config.get (section, 'header_fields').split (',') |
56 |
optionValue= config.get (section, option) |
footerFields= config.get (section, 'footer_fields').split (',') |
57 |
(x, y)= optionValue.split (',') |
fields= readXYConfigSection ('header', headerFields) |
58 |
fields.append ([option, int(x), int(y)]) |
fields+= readXYConfigSection ('footer', footerFields) |
59 |
for option in ['detail_first_row', 'detail_last_row']: |
fields+= [('detail_first_row', 0, config.getint (section, 'detail_first_row')), ('detail_last_row', 0, config.getint (section, 'detail_last_row'))] |
60 |
y= config.get (section, option) |
|
|
fields.append ([option, 0, int(y)]) |
|
61 |
|
|
62 |
# columnas |
# columnas |
63 |
colsQty = config.getint (section, 'column_count') |
detailFields = config.get (section, 'detail_fields').split (',') |
64 |
|
colsQty= len (detailFields) |
65 |
cols= [] |
cols= [] |
66 |
for colNo in map (lambda x: x+1, range (colsQty)): |
for section in detailFields: |
|
section= 'column'+str(colNo) |
|
67 |
if config.has_section (section): |
if config.has_section (section): |
68 |
cols.append ([ |
cols.append ([ |
69 |
config.getint (section, 'distance'), |
config.getint (section, 'distance'), |
70 |
config.getint (section, 'width'), |
config.getint (section, 'width'), |
71 |
config.getint (section, 'justify') |
config.getint (section, 'justify') |
72 |
]) |
]) |
73 |
#colsQty+= 1 |
else: |
74 |
|
# bark and bail out! |
75 |
|
pass |
76 |
|
|
77 |
fields.sort (sortByYAndThenByX) |
fields.sort (sortByYAndThenByX) |
78 |
|
|
79 |
|
|
83 |
'detail': [], |
'detail': [], |
84 |
'detailSize': 0 |
'detailSize': 0 |
85 |
} |
} |
86 |
f= open (inFile, 'r') |
f= open (dataFile, 'r') |
87 |
# the first line has the header data |
# the first line has the header data |
88 |
line= f.readline () |
line= f.readline () |
89 |
# take out trailing '\n' |
headerData= splitAndClean (line) |
90 |
line= line[:-1] |
for field in headerFields: |
91 |
# ri: responsable inscripto |
data[field]= headerData.pop (0) |
|
# rni: responsable no inscripto |
|
|
# cf: consumidor final |
|
|
# e: exento |
|
|
# the [1:-1] thing is for taking out quotes |
|
|
# this relies in that data has no commas :( |
|
|
# (data['date'], data['name'], data['address'], data['ri'], data['rni'], data['cf'], data['e'])= map (lambda x: x[1:-1], line.split(',')) |
|
|
(data['date'], data['name'], data['address'])= map (lambda x: x[1:-1], line.split(',')) |
|
92 |
# take only the date, not the time |
# take only the date, not the time |
93 |
# again a hackery |
# again a hackery |
94 |
(data['date'], None)= data['date'].split (' ') |
(data['date'], None)= data['date'].split (' ') |
95 |
# now comes the detail rows |
# now comes the detail rows |
96 |
line= f.readline () |
line= f.readline () |
97 |
# take out trailing '\n' |
dataFields= splitAndClean (line) |
|
line= line[:-1] |
|
|
dataFields= map (lambda x: x[1:-1], line.split(',')) |
|
98 |
|
|
99 |
while len (dataFields)==colsQty: |
while len (dataFields)==colsQty: |
100 |
data['detail'].append (dataFields) |
data['detail'].append (dataFields) |
101 |
data['detailSize']+= 1 |
data['detailSize']+= 1 |
102 |
# next one, please |
# next one, please |
103 |
line= f.readline () |
line= f.readline () |
104 |
# take out trailing '\n' |
dataFields= splitAndClean (line) |
105 |
line= line[:-1] |
|
106 |
dataFields= map (lambda x: x[1:-1], line.split(',')) |
for field in footerFields: |
107 |
|
data[field]= dataFields.pop (0) |
108 |
|
|
109 |
# the the 3 totals (net, tax and final) |
# pprint ([fields, data]) |
|
(data['net_total'], data['tax'], data['total'])= dataFields |
|
110 |
|
|
111 |
|
|
112 |
# print the thingie |
# print the thingie |
119 |
for i in range (row, y): |
for i in range (row, y): |
120 |
print |
print |
121 |
row+= 1 |
row+= 1 |
122 |
|
|
123 |
if field=='detail_first_row': |
if field=='detail_first_row': |
124 |
# for each data line |
# for each data line |
125 |
for i in range (data['detailSize']): |
for i in range (data['detailSize']): |