def getColor1(): admUtilReports = getUtility(IAdmUtilReports, name='AdmUtilReports') if admUtilReports.color1 is not None: rString = admUtilReports.color1[1:3] gString = admUtilReports.color1[3:5] bString = admUtilReports.color1[5:7] rValue = float(int(rString, 16))/256.0 gValue = float(int(gString, 16))/256.0 bValue = float(int(bString, 16))/256.0 cmyk_tuple = colors.rgb2cmyk(rValue, gValue, bValue) return colors.CMYKColor(*cmyk_tuple) else: return colors.CMYKColor(1.0, 0.49, 0.612, 0.0)
def test3(self): '''some special properties''' palette = [ colors.CMYKColorSep(0.6, 0.34, 0, 0.1, spotName='625C', density=1), colors.CMYKColorSep(0.13, 0.51, 0.87, 0.48, spotName='464c', density=1), ] canv = canvas.Canvas( 'test_pdfgen_general_spots.pdf', pagesize=(346, 102), ) canv.setLineWidth(1) canv.setStrokeColor(colors.CMYKColor(0, 0, 0, 1)) x = 10 y = 10 for c in palette: c.density = 1.0 canv.setFillColor(c) canv.setFont('Helvetica', 20) canv.drawString(x, 80, 'This is %s' % c.spotName) canv.setFont('Helvetica', 6) canv.rect(x, y, 50, 50, fill=1) canv.setFillColor(c.clone(density=0.5)) canv.rect(x + 55, y, 20, 20, fill=1) canv.setFillColor(colors.CMYKColor(0, 0, 1, 0)) canv.rect(x + 80, y, 30, 30, fill=1) canv.rect(x + 120, y, 30, 30, fill=1) alpha = c is palette[0] and 1 or 0.5 op = c is palette[0] and True or False canv.setFillAlpha(alpha) canv.setFillColor(colors.CMYKColor(1, 0, 0, 0)) canv.drawString(x + 80 + 1, y + 3, 'OP=%d' % int(False)) canv.drawString(x + 80 + 1, y + 23, 'Alpha=%.1f' % alpha) canv.rect(x + 90, y + 10, 10, 10, fill=1) canv.setFillOverprint(op) canv.drawString(x + 120 + 1, y + 3, 'OP=%d' % int(op)) canv.drawString(x + 120 + 1, y + 23, 'Alpha=%.1f' % alpha) canv.rect(x + 130, y + 10, 10, 10, fill=1) canv.setFillAlpha(1) canv.setFillOverprint(False) x += canv._pagesize[0] * 0.5 canv.showPage() canv.save()
def _create_front_page(self): """Create the front page witht the model and name """ data = [] image = self.model.images.all().order_by('-primary')[0] logger.debug(image.__dict__) data.append([Spacer(0, 50)]) data.append([self.model.name]) data.append([Spacer(0, 30)]) data.append([self._get_image(image.generate_url(), width=500)]) table = Table(data, rowHeights=(50, 30, 30, 600)) style_data = [('ALIGNMENT', (0, 0), (-1, -1), 'CENTER'), #('GRID', (0, 0), (-1, -1), 1, 'red'), ('FONTSIZE', (0, 1), (0, 1), 30), ('TEXTCOLOR', (0, 0), (-1, -1), colors.CMYKColor(black=10)), ('VALIGN', (0, -1), (0, -1), 'MIDDLE') # Configuration Image alignment ] style = TableStyle(style_data) table.setStyle(style) return table
def _create_employee_attendance(self, records): """Create and overall detailed summary of all attendances """ data = [[ 'ID', 'Card ID', 'Name', Table([['Date', 'Start Time', 'End Time', 'Hours', 'Overtime']], colWidths=100) ]] for record in records: data.append([ record.employee.id, record.employee.card_id, self._format_text(record.employee.name), self._create_attendance_details(record) ]) table = Table(data, colWidths=(100, 100, 100, 500), repeatRows=1) style = TableStyle([('ALIGNMENT', (0, 0), (-1, -1), 'CENTER'), ('VALIGN', (0, 1), (2, -1), 'TOP'), ('PADDING', (0, 0), (-1, -1), 0), ('GRID', (0, 0), (-1, -1), 1, colors.CMYKColor(black=60))]) table.setStyle(style) return table
def _create_supply_table(self): subtable = Table([['Supplier', 'Cost', 'Units', 'Total']], colWidths=(175, 55, 55, 115)) subtable.setStyle(TableStyle(self.details_style)) data = [['ID', 'Description', 'Qty', 'Qty to Buy', subtable]] for supply in self.supplies: style = ParagraphStyle(name='Normal', fontName='Tahoma', leading=12, wordWrap='CJK', allowWidows=1, allowOrphans=1, fontSize=10, textColor=colors.CMYKColor(black=60)) description = Paragraph(supply.description, style) data.append([ supply.id, description, supply.quantity, "{0} {1}".format(supply.to_buy, supply.units), self._create_suppliers_table(supply, supply.to_buy) ]) data.append(['', '', '', 'Total', "{0:f}".format(self.running_total)]) table = Table(data, colWidths=(50, 225, 55, 75, 405)) table.setStyle(TableStyle(self.layout_style)) return table
def create(self, response=None): if response is None: response = 'Phase-Summary({0}).pdf'.format(self.phase.description) doc = SimpleDocTemplate(response, pagesize=A4, leftMargin=12, rightMargin=12, topMargin=12, bottomMargin=12) stories = [] # Create the document title title_text = u"{0}: Project Summary".format( self.phase.project.codename) style = ParagraphStyle(name='Normal', alignment=TA_CENTER, fontName='Garuda', fontSize=20, textColor=colors.CMYKColor(black=60)) title = Paragraph(title_text, style) title.hAlign = "CENTER" stories.append(title) stories.append(Spacer(0, 50)) #Create room details section stories = self._create_and_append_phase_details_section(stories) doc.build(stories)
def _get_description(self, supply): # Set description description = supply.description.replace('\n', '<br/>') if supply.comments: msg_template = u"<br/>[Comments: {0}]" description += msg_template.format(supply.comments.replace('\n', '<br/>')) # If there is a discount then append # original price string style = ParagraphStyle(name='Normal', fontName='Garuda', fontSize=10, wordWrap='CJK', allowWidows=1, allowOrphans=1, textColor=colors.CMYKColor(black=60)) if supply.discount > 0: supply.supply.supplier = self.po.supplier description += u" (discounted {0}% from {1})".format(supply.discount, supply.supply.cost) # return description return Paragraph(description, style)
def _test0(self): "Create color ranges." c0, c1 = colors.Color(0, 0, 0), colors.Color(1, 1, 1) for c in colorRange(c0, c1, 4): print c print c0, c1 = colors.CMYKColor(0, 0, 0, 0), colors.CMYKColor(0, 0, 0, 1) for c in colorRange(c0, c1, 4): print c print c0, c1 = colors.PCMYKColor(0, 0, 0, 0), colors.PCMYKColor(0, 0, 0, 100) for c in colorRange(c0, c1, 4): print c print
def _prepare_text(self, description, font_size=8): text = description if description else u"" style = ParagraphStyle(name='Normal', fontName='Garuda', fontSize=font_size, textColor=colors.CMYKColor(black=60)) return Paragraph(text, style)
def _create_prop_item(self, prop): data = [ self._get_image(prop.image.generate_url(), width=70), prop.id, code128.Code128("Prop-{0}".format(prop.id), barHeight=20), prop.reference, float(prop.cost) * 5.07 ] table = Table([data], colWidths=(70, 50, 100, 100, 100)) style_data = [ ('TEXTCOLOR', (0, 0), (-1, -1), colors.CMYKColor(black=60)), ('GRID', (0, 0), (-1, 0), 1, colors.CMYKColor(black=60)), #General alignment ('ALIGNMENT', (0, 0), (-1, -1), 'CENTER'), ('VALIGN', (0, 0), (-1, -1), 'TOP') ] style = TableStyle(style_data) table.setStyle(style) return table
def _create_employee_attendance(self): """Create and overall detailed summary of all attendances """ dates = [ self.start_date + timedelta(days=i) for i in xrange((self.end_date - self.start_date).days + 1) ] dates_table = Table( [[d.strftime("%b") for d in dates], [d.strftime("%d") for d in dates]], colWidths=self.cell_width, rowHeights=20) dates_table.setStyle( TableStyle([ ('ALIGNMENT', (0, 0), (-1, -1), 'CENTER'), ('FONTSIZE', (0, 0), (-1, -1), 14), ('VALIGN', (0, 0), (-1, -1), 'MIDDLE'), ('LINEBELOW', (0, 0), (-1, 0), 1, colors.black), ('TOPPADDING', (0, 0), (-1, -1), 0), ('BOTTOMPADDING', (0, 0), (-1, -1), 0), ('RIGHTPADDING', (0, 0), (-1, -1), 0), ('LEFTPADDING', (0, 0), (-1, -1), 0), ])) data = [['Employee', dates_table]] for employee in self.employees: try: id_data = [[self._format_text(employee.name)], [ self.get_image(employee.image.generate_url(), width=90) ]] except AttributeError as e: id_data = [[self._format_text(employee.name)], ['']] id_table = Table(id_data, rowHeights=(25, 125)) data.append( [id_table, self._create_attendance_details(employee, dates)]) table = Table(data, colWidths=(100, self.cell_width * len(dates)), repeatRows=1) style = TableStyle([('ALIGNMENT', (0, 0), (-1, -1), 'LEFT'), ('FONT', (0, 0), (-1, -1), 'Tahoma'), ('TOPPADDING', (0, 0), (-1, -1), 0), ('BOTTOMPADDING', (0, 0), (-1, -1), 0), ('RIGHTPADDING', (0, 0), (-1, -1), 0), ('LEFTPADDING', (0, 0), (-1, -1), 0), ('GRID', (0, 0), (-1, -1), 1, colors.CMYKColor(black=60))]) table.setStyle(style) return table
def _create_totals_section(self): #Create data and style array data = [] # Adding Totals to the data container # Add Subtotal if self.receipt.vat or self.receipt.discount or self.receipt.second_discount: data.append( ['', u'Subtotal', "{0:,.2f}".format(self.receipt.subtotal)]) # Add Discount if greater than 0 if self.receipt.discount_amount > 0: data.append([ '', u'Discount {0}%'.format(self.receipt.discount), u"-{:,.2f}".format(self.receipt.discount_amount) ]) # Add Second Discount if greater than 0 if self.receipt.second_discount_amount > 0: data.append([ '', u'Additional Discount {0}%'.format( self.receipt.second_discount), u"-{:,.2f}".format(self.receipt.second_discount_amount) ]) if (self.receipt.second_discount > 0 or self.receipt.discount > 0) and self.receipt.vat: data.append(['', 'Total', "{0:,.2f}".format(self.receipt.total)]) if self.receipt.vat_amount: data.append([ '', 'Vat {0:.0f}%'.format(self.receipt.vat), "{0:,.2f}".format(self.receipt.vat_amount) ]) final_total_title = u"Grand Total" if ( self.receipt.discount or self.receipt.second_discount) and self.receipt.vat else u"Total" data.append([ '', final_total_title, "{0:,.2f}".format(self.receipt.grand_total) ]) table = Table(data, colWidths=(80, 300, 165)) style = TableStyle([ ('TEXTCOLOR', (0, 0), (-1, -1), colors.black), #Lines around content ('LINEBELOW', (-2, -1), (-1, -1), 1, colors.CMYKColor(black=80)), ('LINEAFTER', (-2, 0), (-1, -1), 1, colors.black), ('LINEBEFORE', (-2, 0), (-2, -1), 1, colors.black), #General alignment ('ALIGNMENT', (-2, 0), (-2, -1), 'LEFT'), #Align description ('ALIGNMENT', (-1, 0), (-1, -1), 'RIGHT') ]) table.setStyle(style) style = TableStyle() return table
def _create_prop_title(self): titles = [ 'Example', 'ID', 'Barcode', 'Reference #', 'Unit Price(Baht)' ] table = Table([titles], colWidths=( 70, 50, 100, 100, 100, )) style_data = [ ('TEXTCOLOR', (0, 0), (-1, -1), colors.CMYKColor(black=60)), ('GRID', (0, 0), (-1, 0), 1, colors.CMYKColor(black=60)), #General alignment ('ALIGNMENT', (0, 0), (-1, -1), 'CENTER') ] style = TableStyle(style_data) table.setStyle(style) return table
def _create_products_item_section(self, product): data = [] #add the data data.append([ code128.Code128("DRAI-{0}".format(product.id), barHeight=20), product.description, product.unit_price, product.quantity, product.total ]) #Add comments if they exists if product.comments: style = ParagraphStyle(name='Normal', fontName='Garuda', leading=12, wordWrap='CJK', allowWidows=1, allowOrphans=1, fontSize=10, textColor=colors.black) paragraph = Paragraph(product.comments.replace('\n', '<br/>'), style) comments = Table([[' Comments:', paragraph]], colWidths=(60, 235)) comments.setStyle( TableStyle([('FONT', (0, 0), (-1, -1), 'Garuda'), ('FONTSIZE', (0, 0), (-1, -1), 10), ('VALIGN', (0, 0), (-1, -1), 'TOP'), ('TEXTCOLOR', (0, 0), (-1, -1), colors.black)])) data.append(['', comments, '']) #Create table table = Table(data, colWidths=(80, 300, 60, 40, 65)) style_data = [ ('TEXTCOLOR', (0, 0), (-1, -1), colors.black), #Lines around content ('LINEBELOW', (0, -1), (-1, -1), 1, colors.CMYKColor(black=80)), ('LINEAFTER', (0, 0), (-1, -1), 1, colors.black), ('LINEBEFORE', (0, 0), (0, -1), 1, colors.black), ('FONT', (0, 0), (-1, -1), 'Garuda'), #General alignment ('ALIGNMENT', (0, 0), (1, -1), 'CENTER'), #Align description ('ALIGNMENT', (1, 0), (1, -1), 'LEFT'), #Align Unit Price ('ALIGNMENT', (-3, 0), (-3, -1), 'RIGHT'), #Align Quantity ('ALIGNMENT', (-2, 0), (-2, -1), 'CENTER'), #align totals to the right ('ALIGNMENT', (-1, 0), (-1, -1), 'RIGHT') ] style = TableStyle(style_data) table.setStyle(style) return table
def _create_signature_section(self): signature = Table([['x', '', 'x'], ['Purchasing Agent', '', 'Manager']], colWidths=(200, 100, 200)) dark_grey = colors.CMYKColor(black=60) style = TableStyle([('TEXTCOLOR', (0, 0), (-1, -1), dark_grey), ('LINEBELOW', (0, 0), (0, 0), 1, dark_grey), ('LINEBELOW', (-1, 0), (-1, 0), 1, dark_grey), ('ALIGNMENT', (0, -1), (-1, -1), 'CENTER'), ('ALIGNMENT', (0, 0), (-1, 0), 'LEFT')]) # spacer signature.setStyle(style) return signature
def _format_string_to_paragraph(self, string): """ Changes the string to a paragraph """ super_re = re.compile('\^(\d+)') string = super_re.sub('<super>\g<1></super>', string) style = ParagraphStyle(name='Normal', fontName='Garuda', fontSize=10, alignment=TA_CENTER, textColor=colors.CMYKColor(black=60)) # return description return Paragraph(string, style)
def __create_supplier_section(self): # Create data array data = [] # Add supplier name data.append(['Supplier:', self.supplier.name]) try: # extract supplier address address = self.supplier.addresses.all()[0] # add supplier address data data.append(['', address.address1]) if address.address2: if address.address2.strip() != "": data.append(['', address.address2]) data.append(['', u"{0}, {1}".format(address.city, address.territory)]) data.append(['', u"{0} {1}".format(address.country, address.zipcode)]) except Exception as e: logger.info(e) if self.supplier.telephone: data.append(['', u"T: {0}".format(self.supplier.telephone)]) if self.supplier.fax: data.append(['', u"F: {0}".format(self.supplier.fax)]) if self.supplier.email: data.append(['', u"E: {0}".format(self.supplier.email)]) try: contact = self.supplier.contacts.order_by('id')[0] data.append(['Contact:', u"{0}".format(contact.name)]) data.append(['', u"{0}".format(contact.email)]) data.append(['', u"{0}".format(contact.telephone)]) except Exception as e: logger.warn(e) # Create Table table = Table(data, colWidths=(60, 200)) # Create and apply Table Style style = TableStyle([('BOTTOMPADDING', (0, 0), (-1, -1), 1), ('TOPPADDING', (0, 0), (-1, -1), 1), ('ALIGNMENT', (0, 0), (-1, -1), 'LEFT'), ('ALIGNMENT', (0, 0), (0, -1), 'RIGHT'), ('TEXTCOLOR', (0, 0), (-1, -1), colors.CMYKColor(black=60)), ('FONT', (0, 0), (-1, -1), 'Garuda')]) table.setStyle(style) # Return the Recipient Table return table
def _format_text(self, description, font_size=12): """ Formats the description into a paragraph with the paragraph style """ style = ParagraphStyle(name='Normal', fontName='Garuda', leading=12, wordWrap=None, allowWidows=0, alignment=1, allowOrphans=0, fontSize=font_size, textColor=colors.CMYKColor(black=60)) return Paragraph(description, style)
def _get_reference(self, supply): # Set reference try: reference = supply.reference except AttributeError: reference = supply.supply.reference or u"" # If there is a discount then append # original price string style = ParagraphStyle(name='Normal', fontName='Garuda', fontSize=10, textColor=colors.CMYKColor(black=60)) # return description return Paragraph(reference, style)
def _format_description(self, description): """ Formats the description into a paragraph with the paragraph style """ style = ParagraphStyle(name='Normal', fontName='Tahoma', leading=12, wordWrap='CJK', allowWidows=1, alignment=0, allowOrphans=1, fontSize=14, textColor=colors.CMYKColor(black=60)) return Paragraph(description, style)
def _prepare_text(self, description, font_size=10, alignment=TA_LEFT, bold=False, font='Garuda'): text = description if description else u"" if bold: text = "<b>" + text + "</b>" style = ParagraphStyle(name='Normal', alignment=alignment, fontName=font, fontSize=font_size, textColor=colors.CMYKColor(black=60)) return Paragraph(text, style)
def _prepare_text(self, description, font_size=12, alignment=TA_CENTER, left_indent=0, fontname='Garuda', leading=12): text = description if description else u"" style = ParagraphStyle(name='Normal', alignment=alignment, fontName=fontname, fontSize=font_size, textColor=colors.CMYKColor(black=60), leftIndent=left_indent, leading=leading) return Paragraph(text, style)
def test5(self): "List and display all named colors and their gray equivalents." canvas = reportlab.pdfgen.canvas.Canvas( outputfile('test_lib_colors.pdf')) #do all named colors framePage(canvas, 'Color Demo - page %d' % canvas.getPageNumber()) all_colors = list(reportlab.lib.colors.getAllNamedColors().items()) all_colors.sort() # alpha order by name canvas.setFont('Times-Roman', 10) text = 'This shows all the named colors in the HTML standard (plus their gray and CMYK equivalents).' canvas.drawString(72, 740, text) canvas.drawString(200, 725, 'Pure RGB') canvas.drawString(300, 725, 'B&W Approx') canvas.drawString(400, 725, 'CMYK Approx') y = 700 for (name, color) in all_colors: canvas.setFillColor(colors.black) canvas.drawString(100, y, name) canvas.setFillColor(color) canvas.rect(200, y - 10, 80, 30, fill=1) canvas.setFillColor(colors.color2bw(color)) canvas.rect(300, y - 10, 80, 30, fill=1) c, m, yel, k = colors.rgb2cmyk(color.red, color.green, color.blue) CMYK = colors.CMYKColor(c, m, yel, k) canvas.setFillColor(CMYK) canvas.rect(400, y - 10, 80, 30, fill=1) y = y - 40 if y < 100: canvas.showPage() framePage(canvas, 'Color Demo - page %d' % canvas.getPageNumber()) canvas.setFont('Times-Roman', 10) y = 700 canvas.drawString(200, 725, 'Pure RGB') canvas.drawString(300, 725, 'B&W Approx') canvas.drawString(400, 725, 'CMYK Approx') canvas.save()
def test4(self): "Construct CMYK instances and test round trip conversion" rgbCols = list(colors.getAllNamedColors().items()) # Make a roundtrip test (RGB > CMYK > RGB). for name, rgbCol in rgbCols: r1, g1, b1 = rgbCol.red, rgbCol.green, rgbCol.blue c, m, y, k = colors.rgb2cmyk(r1, g1, b1) cmykCol = colors.CMYKColor(c, m, y, k) r2, g2, b2 = cmykCol.red, cmykCol.green, cmykCol.blue #colors.cmyk2rgb((c, m, y, k)) rgbCol2 = colors.Color(r2, g2, b2) # Make sure the differences for each RGB component # isreally small (< power(10, -N)! N = 16 # max. value found to work on Python2.0 and Win2K. deltas = list(map(abs, (r1 - r2, g1 - g2, b1 - b2))) assert deltas < [math.pow(10, -N)] * 3
def _create_prop_section(self): data = [] data.append([self._create_prop_title()]) for prop in Supply.objects.filter(type='prop').order_by('reference'): data.append([self._create_prop_item(prop)]) table = Table(data, colWidths=(490), repeatRows=1) #Create table style data and merge with totals style data style_data = [('TEXTCOLOR', (0, 0), (-1, -1), colors.CMYKColor(black=60)), ('TOPPADDING', (0, 0), (-1, -1), 0), ('BOTTOMPADDING', (0, 0), (-1, -1), 0), ('ALIGNMENT', (0, 0), (-1, -1), 'CENTER')] table.setStyle(TableStyle(style_data)) #loop through index to add line below item #Return the table return table
def _create_section(self, products, index): data = [] for index, config in enumerate(products): if index < 5: product = products[config] data.append([ svg2rlg('armless-sofa.svg'), config, product['export_price'] ]) table = Table(data) table.setStyle( TableStyle([('GRID', (0, 0), (-1, -1), 1, colors.CMYKColor(black=60)), ('LEFTPADDING', (0, 0), (-1, -1), 0), ('VALIGN', (0, 0), (-1, -1), 'MIDDLE')])) return table
def __create_po_section(self): # Create data array data = [] # Add Data data.append(['Terms:', self._get_payment_terms()]) data.append(['Currency:', self._get_currency()]) order_date = self._outputBKKTime(self.po.order_date, '%B %d, %Y') data.append(['Order Date:', order_date]) if self.po.receive_date: delivery_date = self._outputBKKTime(self.po.receive_date, '%B %d, %Y') data.append(['Delivery Date:', delivery_date]) if self.po.deposit: data.append(['Deposit:', u"{0}%".format(self.po.deposit)]) if self.po.project: project = self.po.project.codename if self.po.room: project += u", {0}".format(self.po.room.description) if self.po.phase: project += u", {0}".format(self.po.phase.description) data.append(['Project:', project]) if self.po.comments: data.append(['Comments:', self._format_string_to_paragraph(self.po.comments)]) # Create table table = Table(data, colWidths=(60, 200)) # Create and set table style style = TableStyle([('BOTTOMPADDING', (0, 0), (-1, -1), 1), ('TOPPADDING', (0, 0), (-1, -1), 1), ('ALIGNMENT', (0, 0), (-1, -1), 'LEFT'), ('ALIGNMENT', (0, 0), (0, -1), 'RIGHT'), ('TEXTCOLOR', (0, 0), (-1, -1), colors.CMYKColor(black=60)), ('FONT', (0, 0), (-1, -1), 'Helvetica'), ('FONT', (0, -1), (-1, -1), 'Garuda')]) table.setStyle(style) # Return Table return table
def _create_product_price_table(self, product): """ Calculate price list for each product """ data = [[ "W:{0} x D:{1} x H:{2}".format(product['width'], product['depth'], product['height']) ]] #data = [] #prices = product['prices'] data.append([product['export_price']]) logger.debug(data) table = Table(data, colWidths=(120, )) table.setStyle( TableStyle([ ('ALIGNMENT', (0, 0), (-1, -1), 'CENTER'), ('INNERGRID', (0, 0), (-1, -1), 1, colors.CMYKColor(black=60)), #('TEXTCOLOR', (0, -1), (-1, -1), 'red') ])) return table
def _create_section(self, products, row_height=20): header = [] #[self._prepare_text('Grade', font_size=12)] col_widths = [] titles = Table( [[i] for i in ['', 'A1']], colWidths=50) #, 'A2', 'A3', 'A4', 'A5', 'A6']], colWidths=50) titles.setStyle( TableStyle([('ALIGNMENT', (0, 0), (-1, -1), 'CENTER'), ('VALIGN', (0, 0), (-1, -1), 'MIDDLE')])) if self.export: data = [Table([[], ["Price"], ["Export Price"]])] #[titles] else: data = [] #Table([[], ["Price"]])]#[titles] for product_table, product, widths in products: header.append( self._prepare_text(product['configuration'], font_size=12)) #t, w = self._create_product_price_table(product) data.append(product_table) col_widths.append(widths) row_heights = [40, (20 * 4)] self.max_row_height if self.max_row_height > 20: row_heights[1] = row_heights[1] + self.max_row_height table = Table([header, data], colWidths=col_widths, rowHeights=row_heights) table.setStyle( TableStyle([('GRID', (0, 0), (-1, -1), 1, colors.CMYKColor(black=60)), ('LEFTPADDING', (0, 0), (-1, -1), 0), ('VALIGN', (0, 0), (-1, -1), 'MIDDLE')])) return table
def _create_attendance_details(self, record): data = [] r_days = 0 r_ot = 0 sundays = 0 sunday_ot = 0 for a in record.attendances.all().order_by('date'): data.append([ a.date, a.start_time.time() if a.start_time else '', a.end_time.time() if a.end_time else '', "{0:.2f}".format(Decimal(a.regular_time or 0)), "{0:.2f}".format(Decimal(a.overtime or 0)) ]) #"{0:.2f}".format(a.gross_wage), #"{0:.2f}".format(a.net_wage)]) if a.is_sunday: sundays += 1 sunday_ot += a.overtime else: r_days += (a.regular_time or Decimal('0')) / Decimal('8') r_ot += a.overtime data.append(['', '', '', 'Regular', '{0:.2f}'.format(r_days)]) data.append(['', '', '', 'Overtime', '{0:.2f}'.format(r_ot)]) data.append(['', '', '', 'Sundays', '{0:.2f}'.format(sundays)]) data.append( ['', '', '', 'Sunday Overtime', '{0:.2f}'.format(sunday_ot)]) table = Table(data, colWidths=(100, 100, 100, 100, 100)) style = TableStyle([('BOX', (3, -4), (-1, -1), 1, colors.CMYKColor(black=60))]) table.setStyle(style) return table