Changeset 2668 for pykota/trunk
- Timestamp:
- 02/11/06 17:24:00 (19 years ago)
- Location:
- pykota/trunk
- Files:
-
- 3 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/bin/pkinvoice
r2666 r2668 28 28 import os 29 29 import pwd 30 import time 30 31 import cStringIO 31 32 … … 134 135 pass 135 136 136 def pagePDF(self, invoicenumber, entry, vat, start, end) : 137 def printVar(self, label, value, size) : 138 """Outputs a variable onto the PDF canvas. 139 140 Returns the number of points to substract to current Y coordinate. 141 """ 142 xcenter = (self.pagesize[0] / 2.0) - 1*cm 143 self.canvas.saveState() 144 self.canvas.setFont("Helvetica-Bold", size) 145 self.canvas.setFillColorRGB(0, 0, 0) 146 self.canvas.drawRightString(xcenter, self.ypos, "%s :" % label) 147 self.canvas.setFont("Courier-Bold", size) 148 self.canvas.setFillColorRGB(0, 0, 1) 149 self.canvas.drawString(xcenter + 0.5*cm, self.ypos, value) 150 self.canvas.restoreState() 151 self.ypos -= (size + 4) 152 153 def pagePDF(self, invoicenumber, entry, vat, start, end, unitname) : 137 154 """Generates a new page in the PDF document.""" 138 self.canvas.doForm("background")139 140 155 extractonly = { "username" : entry.Name } 141 156 if start : … … 147 162 vatamount = 0.0 148 163 if records : 164 self.canvas.doForm("background") 165 self.ypos = self.yorigine - (cm + 20) 149 166 records = self.summarizeDatas(records, "history", extractonly, True) 150 167 fieldnames = records[0] … … 159 176 ht = ((amount * 10000.0) / (100.0 + vat)) / 100.0 160 177 vatamount = amount - ht 161 sys.stderr.write("#%06i %s %s %s %.2f %.2f\n" % (invoicenumber, entry.Name, numberofpages, numberofbytes, amount, vatamount)) 162 163 self.canvas.showPage() 178 self.printVar(_("Invoice"), "#%s" % invoicenumber, 22) 179 self.printVar(_("Username"), entry.Name, 22) 180 self.ypos -= 20 181 if start : 182 self.printVar(_("Since"), start, 14) 183 if end : 184 self.printVar(_("Until"), end, 14) 185 self.printVar(_("Edited on"), time.strftime("%c", time.localtime()), 14) 186 187 self.ypos -= 20 188 self.printVar(_("Number of bytes"), str(numberofbytes), 14) 189 self.printVar(_("Number of pages"), str(numberofpages), 14) 190 self.ypos -= 20 191 self.printVar(_("Amount due"), "%.2f %s" % (amount, unitname), 22) 192 if vat : 193 self.ypos += 8 194 self.printVar("%s (%.2f%%)" % (_("Included VAT"), vat), "%.2f %s" % (vatamount, unitname), 14) 195 self.canvas.showPage() 196 return 1 197 return 0 164 198 165 199 def initPDF(self, logo) : … … 172 206 c.setAuthor(pwd.getpwuid(os.geteuid())[0]) 173 207 c.setTitle("PyKota invoices") 174 c.setSubject("This is an invoice generated with PyKota") 175 176 xcenter = self.pagesize[0] / 2.0 177 ycenter = self.pagesize[1] / 2.0 178 179 ypos = self.pagesize[1] - (2 * cm) 208 c.setSubject("Invoices generated with PyKota") 209 180 210 181 211 self.canvas.beginForm("background") 182 212 self.canvas.saveState() 183 213 214 self.ypos = self.pagesize[1] - (2 * cm) 215 216 xcenter = self.pagesize[0] / 2.0 184 217 if logo : 185 218 try : … … 192 225 width = float(width) / multi 193 226 height = float(height) / multi 194 xpos = xcenter - (width / 2.0) 195 ypos -= height 196 c.drawImage(logo, xpos, ypos, width, height) 197 198 # New top 199 xpos = self.pagesize[0] / 5.0 200 ypos -= (1 * cm) + 20 201 227 self.ypos -= height 228 c.drawImage(logo, xcenter - (width / 2.0), \ 229 self.ypos, \ 230 width, height) 231 232 self.ypos -= (cm + 20) 233 self.canvas.setFont("Helvetica-Bold", 14) 234 self.canvas.setFillColorRGB(0, 0, 0) 235 self.canvas.drawCentredString(xcenter, self.ypos, "%s :" % _("Here's the invoice for your printouts")) 236 237 self.yorigine = self.ypos 202 238 self.canvas.restoreState() 203 239 self.canvas.endForm() … … 232 268 233 269 try : 234 number = float(options["number"])270 firstnumber = number = int(options["number"]) 235 271 if number <= 0 : 236 272 raise ValueError … … 256 292 for i in range(nbtotal) : 257 293 entry = entries[i] 258 self.pagePDF(number, entry, vat, options["start"], options["end"]) 259 number += 1 294 number += self.pagePDF(number, entry, vat, options["start"], options["end"], options["unit"]) 260 295 if outfname != "-" : 261 296 percent = 100.0 * float(i) / float(nbtotal) 262 297 self.display("\r%.02f%%" % percent) 263 298 264 self.endPDF(outfname) 299 if number > firstnumber : 300 self.endPDF(outfname) 265 301 266 302 if outfname != "-" : -
pykota/trunk/NEWS
r2659 r2668 22 22 PyKota NEWS : 23 23 24 - 1.24alpha11 : 25 26 - The pkinvoice invoice generator command line utility is now 27 included. 28 24 29 - 1.24alpha10 : 25 30 -
pykota/trunk/pykota/version.py
r2659 r2668 22 22 # 23 23 24 __version__ = "1.24alpha1 0_unofficial"24 __version__ = "1.24alpha11_unofficial" 25 25 26 26 __doc__ = "PyKota : a complete Printing Quota Solution for CUPS."