def genInvoice(response, invoice, request): MARGIN_SIZE = 8 * mm PAGE_SIZE = A4 # c = canvas.Canvas("hello.pdf") # c.drawString(9*cm, 19*cm, "Hello World!") pdf_doc = SimpleDocTemplate(response, pagesize=PAGE_SIZE, leftMargin=MARGIN_SIZE, rightMargin=MARGIN_SIZE, topMargin=4 * MARGIN_SIZE, bottomMargin=3 * MARGIN_SIZE) # data = [['', '', '', 'Grand Total', '' , pFooterGrandTotal]] pdf_doc.invoice = invoice pdf_doc.request = request tableHeaderStyle = styles['Normal'].clone('tableHeaderStyle') tableHeaderStyle.textColor = colors.white tableHeaderStyle.fontSize = 7 pHeadProd = Paragraph('<strong>Product/<br/>Service</strong>', tableHeaderStyle) pHeadDetails = Paragraph('<strong>Details</strong>', tableHeaderStyle) pHeadTaxCode = Paragraph('<strong>HSN/<br/>SAC</strong>', tableHeaderStyle) pHeadQty = Paragraph('<strong>Qty</strong>', tableHeaderStyle) pHeadPrice = Paragraph('<strong>Rate</strong>', tableHeaderStyle) # pHeadTotal = Paragraph('<strong>Total</strong>' , tableHeaderStyle) pHeadsubTotalTax = Paragraph('<strong>IGST <br/> Tax</strong>', tableHeaderStyle) pHeadsubTotal = Paragraph('<strong>Sub Total</strong>', tableHeaderStyle) # # bookingTotal , bookingHrs = getBookingAmount(o) # # pFooterQty = Paragraph('%s' % ('o.quantity') , styles['Normal']) # pFooterTax = Paragraph('%s' %('tax') , styles['Normal']) # pFooterTotal = Paragraph('%s' % (1090) , styles['Normal']) # pFooterGrandTotal = Paragraph('%s' % ('INR 150') , tableHeaderStyle) data = [[ pHeadProd, pHeadDetails, pHeadTaxCode, pHeadPrice, pHeadQty, pHeadsubTotalTax, pHeadsubTotal ]] totalQuant = 0 totalTax = 0 grandTotal = 0 tableBodyStyle = styles['Normal'].clone('tableBodyStyle') tableBodyStyle.fontSize = 7 for i in json.loads(invoice.products): print '***********', i pDescSrc = i['data']['name'] totalQuant += i['quantity'] print i # # if 'price' not in i: # print "Continuing" # continue i['subTotalTax'] = i['data']['price'] * i['quantity'] * ( i['data']['productMeta']['taxRate'] / float(100)) i['subTotal'] = i['data']['price'] * i['quantity'] * ( 1 + i['data']['productMeta']['taxRate'] / float(100)) totalTax += i['subTotalTax'] grandTotal += i['subTotal'] pBodyProd = Paragraph('Product', tableBodyStyle) pBodyTitle = Paragraph(pDescSrc, tableBodyStyle) pBodyQty = Paragraph(str(i['quantity']), tableBodyStyle) pBodyPrice = Paragraph(str(i['data']['price']), tableBodyStyle) # if 'taxCode' in i: taxCode = '%s(%s %%)' % (i['data']['productMeta']['code'], i['data']['productMeta']['taxRate']) # else: # taxCode = '' pBodyTaxCode = Paragraph(taxCode, tableBodyStyle) pBodysubTotalTax = Paragraph(str(i['subTotalTax']), tableBodyStyle) pBodyTotal = Paragraph(str(i['quantity'] * i['data']['price']), tableBodyStyle) pBodySubTotal = Paragraph(str(i['subTotal']), tableBodyStyle) data.append([ pBodyProd, pBodyTitle, pBodyTaxCode, pBodyPrice, pBodyQty, pBodyTotal, pBodysubTotalTax, pBodySubTotal ]) invoice.subTotal = grandTotal # invoice.saveInvoiceForm() tableGrandStyle = tableHeaderStyle.clone('tableGrandStyle') tableGrandStyle.fontSize = 10 data += [[ '', '', '', '', '', '', Paragraph(str(totalTax), tableBodyStyle), Paragraph(str(grandTotal), tableBodyStyle) ], [ '', '', '', '', '', Paragraph('sub Total (INR)', tableHeaderStyle), '', Paragraph(str(grandTotal), tableGrandStyle) ]] t = Table(data) ts = TableStyle([ ('ALIGN', (1, 1), (-3, -3), 'RIGHT'), ('VALIGN', (0, 1), (-1, -3), 'TOP'), ('VALIGN', (0, -2), (-1, -2), 'TOP'), ('VALIGN', (0, -1), (-1, -1), 'TOP'), ('SPAN', (-3, -1), (-2, -1)), ('TEXTCOLOR', (0, 0), (-1, 0), colors.white), ('BACKGROUND', (0, 0), (-1, 0), themeColor), ('LINEABOVE', (0, 0), (-1, 0), 0.25, themeColor), ('LINEABOVE', (0, 1), (-1, 1), 0.25, themeColor), ('BACKGROUND', (-2, -2), (-1, -2), colors.HexColor('#eeeeee')), ('BACKGROUND', (-3, -1), (-1, -1), themeColor), ('LINEABOVE', (-2, -2), (-1, -2), 0.25, colors.gray), ('LINEABOVE', (0, -1), (-1, -1), 0.25, colors.gray), # ('LINEBELOW',(0,-1),(-1,-1),0.25,colors.gray), ]) t.setStyle(ts) t._argW[0] = 1.5 * cm t._argW[1] = 6 * cm t._argW[2] = 2.4 * cm t._argW[3] = 2 * cm t._argW[4] = 2 * cm t._argW[5] = 2 * cm t._argW[6] = 1.6 * cm t._argW[7] = 2 * cm story = [] expHead = expanseReportHead(request, invoice) story.append(Spacer(2.5, 2 * cm)) story.append(expHead) story.append(Spacer(2.5, 0.75 * cm)) adrs = invoice.customer if invoice.customer.gst is None: tin = 'NA' else: tin = invoice.customer.gst summryParaSrc = """ <font size='11'><strong>Customer details:</strong></font> <br/><br/> <font size='9'> %s<br/> %s<br/> %s<br/> %s<br/> %s , %s<br/> %s<br/> <strong>GSTIN:</strong>%s<br/> </font> """ % (invoice.customer.name, invoice.customer.company, invoice.customer.street, invoice.customer.city, invoice.customer.state, invoice.customer.pincode, invoice.customer.country, tin) story.append(Paragraph(summryParaSrc, styleN)) story.append(t) story.append(Spacer(2.5, 0.5 * cm)) pdf_doc.build(story, onFirstPage=addPageNumber, onLaterPages=addPageNumber, canvasmaker=PageNumCanvas)
def genInvoice(response, contract, request): MARGIN_SIZE = 8 * mm PAGE_SIZE = A4 # c = canvas.Canvas("hello.pdf") # c.drawString(9*cm, 19*cm, "Hello World!") pdf_doc = SimpleDocTemplate(response, pagesize=PAGE_SIZE, leftMargin=MARGIN_SIZE, rightMargin=MARGIN_SIZE, topMargin=4 * MARGIN_SIZE, bottomMargin=3 * MARGIN_SIZE) # data = [['', '', '', 'Grand Total', '' , pFooterGrandTotal]] pdf_doc.contract = contract pdf_doc.request = request tableHeaderStyle = styles['Normal'].clone('tableHeaderStyle') tableHeaderStyle.textColor = colors.white tableHeaderStyle.fontSize = 7 pHeadProd = Paragraph('<strong>Product/<br/>Service</strong>', tableHeaderStyle) pHeadDetails = Paragraph('<strong>Details</strong>', tableHeaderStyle) pHeadTaxCode = Paragraph('<strong>HSN/<br/>SAC</strong>', tableHeaderStyle) pHeadQty = Paragraph('<strong>Qty</strong>', tableHeaderStyle) pHeadPrice = Paragraph('<strong>Rate</strong>', tableHeaderStyle) pHeadTotal = Paragraph('<strong>Total</strong>', tableHeaderStyle) pHeadTax = Paragraph('<strong>IGST <br/> Tax</strong>', tableHeaderStyle) pHeadSubTotal = Paragraph('<strong>Sub Total</strong>', tableHeaderStyle) # # bookingTotal , bookingHrs = getBookingAmount(o) # # pFooterQty = Paragraph('%s' % ('o.quantity') , styles['Normal']) # pFooterTax = Paragraph('%s' %('tax') , styles['Normal']) # pFooterTotal = Paragraph('%s' % (1090) , styles['Normal']) # pFooterGrandTotal = Paragraph('%s' % ('INR 150') , tableHeaderStyle) data = [[ pHeadProd, pHeadDetails, pHeadTaxCode, pHeadPrice, pHeadQty, pHeadTotal, pHeadTax, pHeadSubTotal ]] totalQuant = 0 totalTax = 0 grandTotal = 0 tableBodyStyle = styles['Normal'].clone('tableBodyStyle') tableBodyStyle.fontSize = 7 for i in json.loads(contract.data): print i pDescSrc = i['desc'] totalQuant += i['quantity'] totalTax += i['totalTax'] grandTotal += i['subtotal'] pBodyProd = Paragraph('Service', tableBodyStyle) pBodyTitle = Paragraph(pDescSrc, tableBodyStyle) pBodyQty = Paragraph(str(i['quantity']), tableBodyStyle) pBodyPrice = Paragraph(str(i['rate']), tableBodyStyle) if 'taxCode' in i: taxCode = '%s(%s %%)' % (i['taxCode'], i['tax']) else: taxCode = '' pBodyTaxCode = Paragraph(taxCode, tableBodyStyle) pBodyTax = Paragraph(str(i['totalTax']), tableBodyStyle) pBodyTotal = Paragraph(str(i['quantity'] * i['rate']), tableBodyStyle) pBodySubTotal = Paragraph(str(i['subtotal']), tableBodyStyle) data.append([ pBodyProd, pBodyTitle, pBodyTaxCode, pBodyPrice, pBodyQty, pBodyTotal, pBodyTax, pBodySubTotal ]) contract.grandTotal = grandTotal contract.save() tableGrandStyle = tableHeaderStyle.clone('tableGrandStyle') tableGrandStyle.fontSize = 10 data += [[ '', '', '', '', '', '', Paragraph(str(totalTax), tableBodyStyle), Paragraph(str(grandTotal), tableBodyStyle) ], [ '', '', '', '', '', Paragraph('Grand Total (INR)', tableHeaderStyle), '', Paragraph(str(grandTotal), tableGrandStyle) ]] t = Table(data) ts = TableStyle([ ('ALIGN', (1, 1), (-3, -3), 'RIGHT'), ('VALIGN', (0, 1), (-1, -3), 'TOP'), ('VALIGN', (0, -2), (-1, -2), 'TOP'), ('VALIGN', (0, -1), (-1, -1), 'TOP'), ('SPAN', (-3, -1), (-2, -1)), ('TEXTCOLOR', (0, 0), (-1, 0), colors.white), ('BACKGROUND', (0, 0), (-1, 0), themeColor), ('LINEABOVE', (0, 0), (-1, 0), 0.25, themeColor), ('LINEABOVE', (0, 1), (-1, 1), 0.25, themeColor), ('BACKGROUND', (-2, -2), (-1, -2), colors.HexColor('#eeeeee')), ('BACKGROUND', (-3, -1), (-1, -1), themeColor), ('LINEABOVE', (-2, -2), (-1, -2), 0.25, colors.gray), ('LINEABOVE', (0, -1), (-1, -1), 0.25, colors.gray), # ('LINEBELOW',(0,-1),(-1,-1),0.25,colors.gray), ]) t.setStyle(ts) t._argW[0] = 1.5 * cm t._argW[1] = 6 * cm t._argW[2] = 2.4 * cm t._argW[3] = 2 * cm t._argW[4] = 2 * cm t._argW[5] = 2 * cm t._argW[6] = 1.6 * cm t._argW[7] = 2 * cm #add some flowables story = [] expHead = expanseReportHead(request, contract) story.append(Spacer(2.5, 2 * cm)) story.append(expHead) story.append(Spacer(2.5, 0.75 * cm)) adrs = contract.deal.company.address if contract.deal.company.tin is None: tin = 'NA' else: tin = contract.deal.company.tin summryParaSrc = """ <font size='11'><strong>Customer details:</strong></font> <br/><br/> <font size='9'> %s<br/> %s<br/> %s<br/> %s<br/> %s , %s<br/> %s<br/> <strong>GSTIN:</strong>%s<br/> </font> """ % (contract.deal.contacts.all()[0].name, contract.deal.company.name, adrs.street, adrs.city, adrs.state, adrs.pincode, adrs.country, tin) story.append(Paragraph(summryParaSrc, styleN)) story.append(t) story.append(Spacer(2.5, 0.5 * cm)) if contract.status in ['billed', 'approved', 'recieved']: summryParaSrc = settingsFields.get(name='regulatoryDetails').value story.append(Paragraph(summryParaSrc, styleN)) summryParaSrc = settingsFields.get(name='bankDetails').value story.append(Paragraph(summryParaSrc, styleN)) tncPara = settingsFields.get(name='tncInvoice').value else: tncPara = settingsFields.get(name='tncQuotation').value story.append(Paragraph(tncPara, styleN)) # scans = ['scan.jpg' , 'scan2.jpg', 'scan3.jpg'] # for s in scans: # story.append(PageBreak()) # story.append(FullPageImage(s)) pdf_doc.build(story, onFirstPage=addPageNumber, onLaterPages=addPageNumber, canvasmaker=PageNumCanvas)
def payslip(response, paySlip, userObj, request): # print '999999999999999999999999999999999999999',paySlip.hra,userObj.first_name+' '+userObj.last_name now = datetime.datetime.now() monthdays = calendar.monthrange(now.year, now.month)[1] currencyType = 'INR' s = CurrencyCodes().get_symbol(currencyType) # currencysymbol if currencyType == 'INR': s = 'Rs.' absent = 3 daysPresent = monthdays - absent paidHolidays = 1 accountNumber = paySlip.accountNumber print '99999999999999', paySlip.joiningDate.year print paySlip.joiningDate.year, userObj.pk print str(paySlip.joiningDate.year) + str(userObj.pk) (empCode, name, location, department, grade, designation, pfNo, escisNo, pan, sbs) = (str(paySlip.joiningDate.year) + str(userObj.pk), userObj.first_name + ' ' + userObj.last_name, 'Bangalore', 'Software', 'A', 'Software developer', '', '', '', paySlip.basic) (days, ml, al, cl, adHocLeaves, balanceSL, balanceCL, balanceCO) = (daysPresent + paidHolidays, paySlip.ml, paySlip.al, 0, paySlip.adHocLeaves, 0, 0, 0) # (basicSalary,hra,cn,cr,mr,oe)=(sbs,50000,40000,0,40000,0) (basic, hra, special, lta, adHoc, amount) = (paySlip.basic, paySlip.hra, paySlip.special, paySlip.lta, paySlip.adHoc, paySlip.amount) (spf, pdf, iol, od) = (10000, 50000, 0, 0) totalEarnings, deductions = (0, 0) # for i in (basicSalary,hra,cn,cr,oe): for i in (basic, hra, special, lta, adHoc, amount): totalEarnings += i for i in (spf, pdf, iol, od): deductions += i netpay = totalEarnings - deductions styles = getSampleStyleSheet() styledict = { 'center': ParagraphStyle(name='center', parent=styles['Normal'], alignment=TA_CENTER, fontSize=10) } doc = SimpleDocTemplate( response, pagesize=A3, topMargin=1 * cm, ) doc.request = request # container for the 'Flowable' objects elements = [] a = [ Paragraph( "<para fontSize=25 alignment='Left' textColor=#6375d4><strong>CIOC</strong></para>", styles['Normal']), Paragraph("<b>CIOC FMCG Pvt ltd.</b><br/>", styledict['center']), Paragraph( "<para fontSize=7 alignment='center'>4th Floor,Venkateshwara Heritage,Kudlu Hosa Road,opp Sai Purna Premium Apartment,Sai Meadows,Kudlu,Bengaluru,Karnataka-560068<br/> <b>www.cioc.co.in</b> </para>", styles['Normal']), Paragraph( "<para fontSize=8 alignment='center'><strong>Employee PaySlip For Month Of {0} {1} </strong></para>" .format(calendar.month_name[now.month], now.year), styles['Normal']) ] p1 = Paragraph( "<para fontSize=8><strong>Bank Details : </strong>Salary Has Been Credited To {0},ICICI Bank LTD." .format(accountNumber), styles['Normal']) data = [ [a, '', '', ''], ['', '', '', ''], ['Emp Code : %s' % (empCode), 'Name : %s' % (name), '', ''], [ 'Location : %s' % (location), 'Department :%s' % (department), 'Grade : %s' % (grade), 'Designation : %s' % (designation) ], [ 'PF No : %s' % (pfNo), 'ESIC No : %s' % (escisNo), 'PAN : %s' % (pan), 'Standard Basic Salary : %s %d' % (s, sbs) ], [ 'Days Paid : %d' % (days), 'Days Present : %d' % (daysPresent), 'Paid Holidays : %d' % (paidHolidays), 'Lwp/Absent : %d' % (absent) ], [ 'Sick Leaves : %d' % (ml), 'Annual Leaves : %d' % (al), 'Compensatory Leaves : %d' % (cl), 'AdHoc Leaves : %d' % (adHocLeaves) ], [ 'Balance SL : %d' % (balanceSL), 'Balance CL : %d' % (balanceCL), 'Balance CO : %d' % (balanceCO), '' ], ['Earnings', 'Amount', 'Deductions', 'Amount'], [ 'Basic Salary', s + ' ' + str(basic), 'Saturatory Provident Fund', s + ' ' + str(spf) ], [ 'HRA', s + ' ' + str(hra), 'Professional Tax Deduction', s + ' ' + str(pdf) ], [ 'Conveyance', s + ' ' + str(special), 'Interest On Loan', s + ' ' + str(iol) ], [ 'Conveyance Reimbursement', s + ' ' + str(lta), 'Other Deduction ', s + ' ' + str(od) ], ['Medical Reimbursement', s + ' ' + str(adHoc), '', ''], ['Other Earnings', s + ' ' + str(amount), '', ''], [ 'Total Earnings ', s + ' ' + str(totalEarnings), 'Total Deduction', s + ' ' + str(deductions) ], ['', '', '', 'Net Pay : %s %d' % (s, netpay)], [p1, '', '', ''], ] lines = [('LINEBELOW', (0, 1), (-1, 1), 0.5, black), ('LINEBELOW', (0, 4), (-1, 4), 0.5, black), ('LINEBELOW', (0, 7), (-1, 7), 0.5, black), ('LINEBELOW', (0, 8), (-1, 8), 0.5, black), ('LINEBELOW', (0, 14), (-1, 14), 0.5, black), ('LINEBELOW', (0, 15), (-1, 15), 0.5, black), ('LINEBELOW', (0, 16), (-1, 16), 0.5, black), ('LINEBEFORE', (2, 8), (2, 16), 0.5, black)] spans = [('SPAN', (0, 0), (-1, 1)), ('SPAN', (1, 2), (-1, 2)), ('SPAN', (0, -1), (-1, -1))] aligns = [('ALIGN', (1, 8), (1, 15), 'RIGHT'), ('ALIGN', (-1, 8), (-1, 16), 'RIGHT')] rheights = 18 * [0.3 * inch] rheights[1] = 0.5 * inch t1 = Table(data, rowHeights=rheights) t1.setStyle( TableStyle([ ('BOX', (0, 0), (-1, -1), 0.75, black), ] + lines + spans + aligns)) elements.append(t1) doc.build(elements)