Beispiel #1
0
def print_ledger(result, owner_type, opening_balance):
    if owner_type == "customer": money = 'Receipt'
    if owner_type == "vendor": money = 'Payment'
    columns = ['Date', 'id_', 'Invoice', money, 'Balance']
    # right_align_columns = ['id', 'Invoice', money, 'Balance']
    # left_align_columns=['Date']
    # pt = PrettyTable(columns)
    print('OB is {}'.format(opening_balance))
    new_list = []
    new_list.append(['Opening', '', '', '', str(opening_balance)])

    # pt.add_row(['Opening', '','','',str(opening_balance)])
    # pt.set_style(PLAIN_COLUMNS)
    if result:
        for a in result:
            a0 = cf.reverse_date(str(a[0]))
            if a[1] is None:
                a1 = ''
            else:
                a1 = a[1]
            if a[2] is None:
                a2 = ''
            else:
                a2 = a[2]
            if a[3] is None:
                a3 = ''
            else:
                a3 = a[3]
            new_list.append([a0, a1, a2, a3, a[4]])
    cf.pretty_(columns, new_list, align_right=range(1, 5))
Beispiel #2
0
def view_print(result, self=None):
    # left_align = ["name"]
    # right_align = ["qty", "unit", "rate","discount", "sub_total"]
    # result = [a[:-2] for a in result]
    # cf.pretty_(invoice_detail.detail_columns[:-1], result)
    # pt = PrettyTable(invoice_detail.detail_columns)
    new_list = []
    for a in result:
        packed_ = a[-1]
        # result = a[:-2] # remove pack and print_name
        a0 = a[0] if not packed_ else colored.stylize(a[0], colored.fg("11"))
        a4 = '' if a[4] is None else a[4]
        new_list.append([a0, a[1], a[2], a[3], a4, a[5]])
        # pt.add_row([a0, a[1], a[2], a[3], a4, a[5], a[6]])
    col_ = ['Name', 'Qty', 'Unit', 'Rate', 'Disc', 'Total']
    # col_ = invoice_detail.detail_columns[:-1]
    col_ = [colored.stylize(a, colored.fg("138")) for a in col_]
    # cf.pretty_(['Date', 'No', 'Name'],((cf.reverse_date(str(self.date_)),str(self.no_), self.owner.name+" ("+self.owner.place+")"), ))
    if self is not None:
        header_ = (cf.reverse_date(str(self.date_)), self.owner.name + " (" +
                   self.owner.place + "): " + str(self.amount_after_freight))
    else:
        header_ = '*'

    cf.pretty_(col_,
               new_list,
               align_right=range(1, 6),
               header_=header_,
               footer_=True)
Beispiel #3
0
def header_(c, invoice_, height):
    # c.setFillColorRGB(0, 0, 102)
    c.setFillColor(navy)
    # c.setFillColorRGB(0,0,255)
    c.drawString(10, height, "Estimate")
    c.drawRightString(360, height, "No:")
    c.drawRightString(390, height, str(invoice_.no_))
    height = height - 15
    c.drawString(10, height,
                 invoice_.owner_name + " (" + invoice_.owner_place + ")")
    c.drawRightString(390, height, cf.reverse_date(str(invoice_.date_)))
    return c
    '''
Beispiel #4
0
def view_ledger():
    debtors_list = cf.cursor_(
        sql.SQL("select distinct name_place from bank.debtor"))
    debtors_list = [i[0] for i in debtors_list]
    while True:
        action = cf.prompt_("Enter debtor: ", debtors_list, empty_="yes")
        if action == "back":
            continue
        if action == "quit":
            break
        with conn() as cursor:
            cursor.execute(
                "select date_, invoice_amount, receipt_amount, ts-tr from bank.sale_led_view where name_place = %s",
                (action, ))
            result = cursor.fetchall()
        columns = ['date', 'invoice_amount', 'receipt_amount', 'balance']
        right_align_columns = ['invoice_amount', 'receipt_amount', 'balance']
        left_align_columns = ['date']
        pt = PrettyTable(columns)
        # pt.set_style(PLAIN_COLUMNS)
        for a in result:
            a0 = cf.reverse_date(str(a[0]))
            if a[1] is None:
                a1 = ''
            else:
                a1 = a[1]
            if a[2] is None:
                a2 = ''
            else:
                a2 = a[2]
            pt.add_row([a0, a1, a2, a[3]])
        pt.align = 'r'
        for l in left_align_columns:
            pt.align[l] = 'l'
        # for r in right_align_columns:
        #     pt.align[r] = 'r'
        print(pt)
Beispiel #5
0
def create_(dtd, page_size, owner_, opening_, **kwargs):
    # if opening_ is None: # taking care of zero
    #     opening_ = dtd[0][5]
    master_ = kwargs.get('master_', '')
    # dtd = invoice_.fetch_invoice_details(master_=master_)
    pdf_file_name = os.path.join(pdf_dir, str(1) + ".pdf")
    # print('dtd is {}'.format(dtd))
    margin = 0.5 * units.cm
    if page_size == 'A5':
        c = canvas.Canvas(pdf_file_name, pagesize=pagesizes.A5)
        wid, hei = pagesizes.portrait(pagesizes.A5)  # 420, 595 for A5 portrait
        max_page_item_count = 44
    elif page_size == 'A6':
        c = canvas.Canvas(pdf_file_name,
                          pagesize=pagesizes.landscape(pagesizes.A6))
        wid, hei = pagesizes.landscape(
            pagesizes.A6)  # 420, 297 for A6 landscape
        max_page_item_count = 19
    width = wid - margin
    height = hei - margin - 5
    y_start_value = height
    h = y_start_value
    c.setFont("DroidSans", invoice_detail_font_size, leading=None)
    page_count = 1
    row_height = 45
    item_count = 1
    page_item_count = 1
    flag_first = False
    last_item = len(dtd)
    for a in dtd:
        if h == y_start_value:
            c = header_(c, owner_, height)
            c = sub_header_(c, height)
        h = height - row_height
        if not flag_first:
            c.setFillColor(navy)
            # print('first height is {}'.format(h))
            c.drawRightString(60, h, 'Opening')
            c.drawRightString(210, h, str(opening_))
            page_item_count = page_item_count + 1
            h = h - 12
            row_height = row_height + 12
            flag_first = True
        # w = 20
        # print(item_count, h)
        w = 60
        w_date = w + 50
        w_invoice_amount = w_date + 50
        w_receipt_amount = w_invoice_amount + 50
        w_balance = w_receipt_amount + 50
        # c.setFillColorRGB(101,0,0)
        c.setFillColor(navy)
        date_ = cf.reverse_date(str(a[0]))
        if a[2] in [0, None]:
            invoice_amount = ''
        else:
            invoice_amount = str(a[2])
        if a[3] in [0, None]:
            receipt_amount = ''
        else:
            receipt_amount = str(a[3])
        # invoice_amount = '' if a[2] == 0 else str(a[2])
        # receipt_amount = '' if a[3] == 0 else str(a[3])
        c.drawRightString(w, h, date_)
        c.drawRightString(w_date, h, invoice_amount)
        c.drawRightString(w_invoice_amount, h, receipt_amount)
        if item_count == last_item:
            c.setFillColorRGB(128, 0, 0)
            c.setLineWidth(0.25)
            c.line(w_receipt_amount - 25, h - 3, w_receipt_amount, h - 3)
            c.line(w_receipt_amount - 25, h - 5, w_receipt_amount, h - 5)
            # c.setFillColor(lightcoral)
            c.drawRightString(w_receipt_amount, h, str(a[4]))
        else:
            c.drawRightString(w_receipt_amount, h, str(a[4]))
        row_height = row_height + 12
        item_count = item_count + 1
        page_item_count = page_item_count + 1
        if page_item_count == max_page_item_count:
            print("page_item_count is {}".format(page_item_count))
            page_item_count = 1
            c.drawRightString(40, h - 20, "Page: " + str(page_count))
            page_count = page_count + 1
            h = y_start_value
            row_height = 45
            c.showPage()
            c.setFont("DroidSans", invoice_detail_font_size, leading=None)
            c.setFillColor(navy)
            c = sub_header_(c, height)
            c = header_(c, owner_, height)
    c.showPage()
    c.save()
    os.system('xdg-open ' + pdf_file_name)
Beispiel #6
0
 def display_header(self):
     print("{}".format(self.invoice_type))
     cf.pretty_(['Date', 'No', 'Name'],
                ((cf.reverse_date(str(self.date_)), str(self.no_),
                  self.owner.name + " (" + self.owner.place + ")"), ))