def edit_party(party_id): if request.method == 'POST': name = request.form.get('name') gstin = request.form.get('gstin') address = request.form.get('local_address') state = request.form.get('state') country = request.form.get('country') pincode = request.form.get('pincode') contact_person_name = request.form.get('contact_person_name') email = request.form.get('email') mobile_no_1 = request.form.get('mobile_no_1') mobile_no_2 = request.form.get('mobile_no_2') city = request.form.get('city') id = party_id party = Party(name, gstin, address, city, state, country, int(pincode), contact_person_name, mobile_no_1, email, mobile_no_2, party_id) party.save_to_mongo() return redirect(url_for('.index')) return render_template('party/edit_party.jinja2', new_party_page=True, party=Party.get_by_id(party_id))
def get_data_for_list(): json_datas = [] invoices = Invoice.get_all_invoice() for invoice in invoices: invoice.party_id = Party.get_by_id(invoice.party_id) x = "<td><div class=\"dropdown-content\"><a id=\"navbarDropdownMenuLink" + invoice._id + "\" href=\"#\" data-toggle=\"dropdown\" aria-haspopup=\"true\" aria-expanded=\"false\" class=\"nav-link tasks-toggle\"><i class=\"icon-new-file\"></i></a><div aria-labelledby=\"navbarDropdownMenuLink" + invoice._id + "\" class=\"invoice_datatable dropdown-menu tasks-list\"><a href=\"/invoices/edit/" + invoice._id + "\" class=\"dropdown-item\"><div class=\"text d-flex justify-content-between\"><strong><i class=\"fa fa-pencil fa-fw\"></i> Edit</strong></div></a><a data-href=\"/invoices/delete/" + invoice._id + "\" data-toggle=\"modal\" data-target=\"#confirm-delete\" class=\"dropdown-item\"><div class=\"text d-flex justify-content-between\"><strong><i class=\"fa fa-trash-o fa-fw\"></i> Delete</strong></div></a><a href=\"/invoices/print/" + invoice._id + "\" class=\"dropdown-item\"><div class=\"text d-flex justify-content-between\"><strong><i class=\"fa fa-file-pdf-o fa fw\" style=\"margin-right: 6px;padding-left: 3px;\"></i> Print</strong></div></a></div></div></td>" json_data = { "no": str(invoice.no), "date": datetime.datetime.strftime(invoice.date, "%d-%m-%Y"), "party_ac_name": invoice.party_id.name, "party_city": invoice.party_id.city, "total_amount": invoice.total_amount, "party_contact_person_name": invoice.party_id.contact_person, "party_contact": invoice.party_id.mobile_no_1, "actions": x, } json_datas.append(json_data) #print(json_datas) return json_datas
def get_data_for_serial_no_list(): json_datas = [] serial_nos = Serial_no.get_all_serial_no() for serial_no in serial_nos: invoice_item = Invoice_item.get_by_id(serial_no.invoice_item_id) invoice_item.item_id = Item.get_by_id(invoice_item.item_id) invoice = Invoice.get_by_id(invoice_item.invoice_id) invoice.party_id = Party.get_by_id(invoice.party_id) x = "<td><div class=\"dropdown-content\"><a id=\"navbarDropdownMenuLink" + invoice._id + "\" href=\"#\" data-toggle=\"dropdown\"aria-haspopup=\"true\" aria-expanded=\"false\" class=\"nav-link tasks-toggle\"><i class=\"icon-new-file\"></i></a><div aria-labelledby=\"navbarDropdownMenuLink" + invoice._id + "\" class=\"invoice_datatable dropdown-menu tasks-list\"><a href=\"/invoices/print/" + invoice._id + "\" class=\"dropdown-item\"><div class=\"text d-flex justify-content-between\"><strong><i class=\"fa fa-file-pdf-o fa fw\" style=\"margin-right: 6px;padding-left: 3px;\"></i>Print</strong></div></a></div></div></td>" json_data = { "no": serial_no.serial_no, "invoice_no": invoice.no, "date": datetime.datetime.strftime(invoice.date, "%d-%m-%y"), "item": invoice_item.item_id.model_name, "party": invoice.party_id.name, "city": invoice.party_id.city, "price": invoice_item.rate_per, "action": x, } json_datas.append(json_data) return json_datas
def make_final_workbook(self): gst=[] igst = [] gst.append(['Date','Number','Party Name','City','GSTIN','Product Model Name','Quantity','Rate Per','Base Price','SGST','CGST','Total','Serial_No','e-Way Bill No.']) igst.append(['Date', 'Number', 'Party Name', 'City', 'GSTIN', 'Product Model Name', 'Quantity', 'Rate Per', 'Base Price', 'IGST', 'Total', 'Serial_No','e-Way Bill No.']) gst.append([]) igst.append([]) invoices = Invoice.filter_by_date(self.start,self.end) print(invoices) for invoice in invoices: total_invoice,total_base_price,total_tax = 0,0,0 invoice.date = datetime.datetime.strftime(invoice.date,'%d-%m-%Y') invoice.party_id = Party.get_by_id(invoice.party_id) invoice_items = Invoice_item.get_by_invoice_id(invoice._id) flag = False if invoice.party_id.tax_type() == 'gst': flag = True for invoice_item in invoice_items: invoice_item.item_id = Item.get_by_id(invoice_item.item_id) y = [] serial_nos = Serial_no.get_by_invoice_item_id(invoice_item._id) q='' for i in serial_nos: q = q+i.serial_no+'\n' print(q) invoice_item.quantity = int(invoice_item.quantity) invoice_item.rate_per = float(invoice_item.rate_per) invoice_item.item_id.tax = float(invoice_item.item_id.tax) base_price = invoice_item.rate_per * invoice_item.quantity tax = (base_price * invoice_item.item_id.tax) / 100 total = base_price + tax total_base_price +=base_price total_tax +=tax total_invoice+=total if flag: y = [invoice.date, invoice.no, invoice.party_id.name, invoice.party_id.city, invoice.party_id.gstin, invoice_item.item_id.model_name, invoice_item.quantity, invoice_item.rate_per, base_price, tax/2, tax/2, total, q] gst.append(y) else: y = [invoice.date, invoice.no, invoice.party_id.name, invoice.party_id.city, invoice.party_id.gstin, invoice_item.item_id.model_name, invoice_item.quantity, invoice_item.rate_per, base_price, tax, total, q] igst.append(y) if flag: gst.append(['','','','','','','','','',total_base_price,total_tax/2,total_tax/2,total_invoice,invoice.e_way]) gst.append([]) else: igst.append(['','','','','','','','','',total_base_price,total_tax,total_invoice,invoice.e_way]) igst.append([]) print(igst) print(gst) for i in igst: print(i) print() for i in gst: print(i) self.gst = gst self.igst = igst self.make_workbook(gst,igst)
def print_invoice(invoice_id): print(invoice_id) company = Company.get_company() company[0].address = format(company[0].address) company[0].address = Utils.format_address(company[0].address) invoice = Invoice.get_by_id(invoice_id) if (invoice is None): invoice = Invoice.get_by_no(invoice_id) invoice_id = invoice._id invoice.date = datetime.datetime.strftime(invoice.date, "%d-%m-%Y") invoice_items = Invoice_item.get_by_invoice_id(invoice_id) invoice_package = {} invoice_package['invoice'] = invoice #invoice_package.append(invoice) party = Party.get_by_id(invoice.party_id) party.address = Utils.format_address(party.address) invoice_package['party'] = party tax_type = party.tax_type() tax, igst, round_off, total_amount, hsn_taxable_tot, total_quantity = 0.0, 0.0, 0.0, 0.0, 0.0, 0 hsn_list = {} invoice_package['invoice_items'] = [] sr = 0 for invoice_item in invoice_items: sr += 1 serial_no = Serial_no.get_by_invoice_item_id(invoice_item._id) total_quantity += invoice_item.quantity #invoice_package.append([invoice_item,serial_no]) item = Item.get_by_id(invoice_item.item_id) print(item.type_id) amount_item = int(invoice_item.quantity) * float(invoice_item.rate_per) if item.hsn not in hsn_list: hsn_list[item.hsn] = [0, invoice_item.rate_per, 0, 0, item.tax] if tax_type == "gst": tax1 = amount_item * float(item.tax) / 200 total_amount += (tax1 * 2) else: tax1 = amount_item * float(item.tax) / 100 total_amount += tax1 hsn_list[item.hsn][2] += tax1 hsn_list[item.hsn][0] += amount_item if tax_type == "gst": hsn_list[item.hsn][3] += tax1 * 2 else: hsn_list[item.hsn][3] += tax1 hsn_taxable_tot += amount_item tax += tax1 print('Type_obj', item.type_id) item.type_id = Type.get_by_id(item.type_id) print(item.type_id) print() invoice_package['invoice_items'].append({ "invoice_item": invoice_item, "item": item, "serial_no": serial_no, "amount": amount_item, "sr_no": sr }) if tax_type == "gst": x = tax * 2 else: x = tax invoice_package['total_tax_amount'] = x total = hsn_taxable_tot + x round_off = abs(round(total) - total) invoice_package['hsn_taxable_total'] = hsn_taxable_tot invoice_package['tax'] = tax invoice_package['total_items'] = len(invoice_items) invoice_package['round_off'] = round_off invoice_package['total'] = total invoice_package['tax_type'] = tax_type invoice_package['company'] = company[0] invoice_package['total_words'] = Utils.get_currency_words(total) if tax_type == "gst": invoice_package['tax_words'] = Utils.get_currency_words(tax * 2) else: invoice_package['tax_words'] = Utils.get_currency_words(tax) invoice_package['hsn_list'] = hsn_list invoice_package['total_quantity'] = total_quantity #for i in invoice_package: # print(i,invoice_package[i]) #print() #for i in invoice_package['invoice_items']: # print(i) print(invoice_package['hsn_list']) #print(company[0].address) #print(party.address) return render_template('invoices/invoice_print.jinja2', invoice_package=invoice_package)
def edit_invoice(invoice_id): parties = Party.get_parties() items = Item.get_items() invoice_items = Invoice_item.get_by_invoice_id(invoice_id) company = Company.get_company() invoice = Invoice.get_by_id(invoice_id) invoice.date = datetime.datetime.strftime(invoice.date, "%d-%m-%Y") invoice_package = {} invoice_package['invoice'] = invoice party = Party.get_by_id(invoice.party_id) invoice_package['party'] = party tax_type = party.tax_type() tax, igst, round_off, total_amount, hsn_taxable_tot, total_quantity = 0.0, 0.0, 0.0, 0.0, 0.0, 0 invoice_package['invoice_items'] = [] sr = 0 for invoice_item in invoice_items: sr += 1 serial_no = Serial_no.get_by_invoice_item_id(invoice_item._id) total_quantity += invoice_item.quantity item = Item.get_by_id(invoice_item.item_id) amount_item = int(invoice_item.quantity) * float(invoice_item.rate_per) if tax_type == "gst": tax1 = amount_item * float(item.tax) / 200 total_amount += (tax1 * 2) else: tax1 = amount_item * float(item.tax) / 100 total_amount += tax1 tax += tax1 hsn_taxable_tot += amount_item invoice_package['invoice_items'].append({ "invoice_item": invoice_item, "item": item, "serial_no": serial_no, "amount": amount_item, "sr_no": sr }) if tax_type == "gst": x = tax * 2 else: x = tax invoice_package['total_tax_amount'] = x total = hsn_taxable_tot + x round_off = abs(round(total) - total) invoice_package['tax'] = tax invoice_package['total_items'] = len(invoice_items) invoice_package['round_off'] = round_off invoice_package['total'] = total invoice_package['tax_type'] = tax_type invoice_package['company'] = company[0] # for i in invoice_package: # print(i,invoice_package[i]) if request.method == 'POST': Invoice.get_by_id(invoice_id).delete() string = {} data = request.form print(data) print() for key in data.keys(): for value in data.getlist(key): string[key] = value for i in string: print(i, string[i]) # ---- Invoice Creation ---- no = string['number'] party_id = Party.get_by_gstin(string['select_party']) date = string['date'] narration = string['narration'] invoice_amount = string['total_amount'] e_way = string['e_way'] invoice = Invoice(no, party_id._id, invoice_amount, date, narration, e_way) invoice.save_to_mongo() # --- Find Items items = [] serial_no = {} for i in string: print(i[:7]) if i[:12] == 'select_item_': items.append([i, string[i][14::]]) if i[:7] == 'myModal': if i[8] != '_': num = int(i[7]) * 10 + int(i[8]) else: num = int(i[7]) if str(num) not in serial_no: serial_no[str(num)] = [] serial_no[str(num)].append(string[i]) # print(items) item_details = [] for i in range(len(items)): item = items[i][0][12::] quantity = string['quantity_' + item] rate_per = string['rate_per_' + item] item_details.append( [item, items[i][1], quantity, rate_per, serial_no[item]]) # print() # print(item_details) for i in item_details: item_id = Item.get_by_name(i[1]) print(invoice._id, item_id, float(i[3]), int(i[2])) invoice_item = Invoice_item(invoice._id, item_id._id, float(i[3]), int(i[2])) invoice_item.save_to_mongo() for j in i[4]: serial_no = Serial_no(invoice_item._id, j) serial_no.save_to_mongo() # print() # print(serial_no) # print(string) return redirect(url_for('.print_invoice', invoice_id=invoice._id)) return render_template('invoices/edit_invoice.jinja2', invoice_package=invoice_package, edit_invoice_page=True, parties=parties, items=items, company=Company.get_company()[0])