def writeInvoice(self, invoice_data, calculated_date, invoice_positions,
                     calculated_price):
        invoice_text = open(configuration.TEMPLATE_INVOICE_TEXT).read()
        invoice_template = Template(invoice_text)
        self.createInvoicePosString(invoice_positions)
        calculated_price = "{:10.2f}".format(calculated_price)
        filename = open(invoice_data[7] + "_" +
                        invoice_data[0].replace('\'Rechnung_', '') +
                        "_invoice.txt",
                        "w",
                        encoding='utf-8')

        try:
            self.finished_invoice_text = invoice_template.substitute(
                firmname=invoice_data[8],
                name=invoice_data[9],
                address=invoice_data[10],
                firm_location=invoice_data[11],
                uid=invoice_data[12],
                location=invoice_data[2],
                date=invoice_data[3],
                customer_number=invoice_data[7],
                job_number=invoice_data[1].replace('Auftrag_', ''),
                invoice_number=invoice_data[0].replace('\'Rechnung_', ''),
                receiver_firm=invoice_data[16],
                receiver_firm_address=invoice_data[17],
                receiver_firm_location=invoice_data[18],
                calculated_date=calculated_date,
                positions_text=self.positions_text,
                total_price=calculated_price)

            filename.write(self.finished_invoice_text)
        except:
            create_log.log().createLog('failed to create: ' + filename)
Exemple #2
0
 def connectionToFTP(self, host, user, password, path):
     try:
         self.ftp = ftplib.FTP(host)
         self.ftp.login(user, password)
         self.ftp.cwd(path)
         return self.ftp
     except:
         create_log.log().createLog(
             'could not build connection to ftp server: ' + host)
Exemple #3
0
 def uploadZip(self):
     try:
         files = os.listdir()
         for zipfile in files:
             if zipfile.endswith('.zip'):
                 filename = open(zipfile, 'rb')
                 self.client_ftp_in.storbinary('STOR ' + zipfile, filename)
     except:
         create_log.log().createLog('failed upload of the zip file:' +
                                    zipfile)
Exemple #4
0
 def writeMail(self):
     self.createMailMessage()
     try:
         mailserver = smtplib.SMTP_SSL('smtp.gmail.com', 465)
         mailserver.ehlo()
         mailserver.login(configuration.EMAIL_USER,
                          configuration.EMAIL_PASSWORD)
         mailserver.send_message(self.mail_message)
         mailserver.close()
     except:
         create_log.log().createLog('failed to send mail')
Exemple #5
0
    def prepareMail(self, invoice_data, receipt_date, receipt_time):
        self.subject = invoice_data[0].replace('\'', '').replace('_', ' ')
        self.mail_to = '*****@*****.**'  #invoice_data[13]
        template_mail_text = open(configuration.TEMPLATE_EMAIL).read()
        template_mail = Template(template_mail_text)

        try:
            self.mail_text = template_mail.substitute(
                customer_name=invoice_data[16],
                receipt_date=receipt_date,
                receipt_time=receipt_time,
                invoice_number=invoice_data[0].replace('_', ' '),
                ftp_server=configuration.PAYMENT_HOST)
            self.writeMail()
        except:
            create_log.log().createLog('could not create mail text')
    def createInvoicePosString(self, position_data):
        invoice_position_template_text = open(
            configuration.TEMPLATE_INVOICE_TEXT_POSITION).read()
        invoice_postion_template = Template(invoice_position_template_text)

        try:
            for i in range(0, len(position_data)):
                self.positions_text += invoice_postion_template.substitute(
                    position_id=position_data[i][1],
                    position_description=position_data[i][2],
                    quantity=position_data[i][3],
                    price_pre_quantity=position_data[i][4],
                    price=position_data[i][5],
                    mwst=position_data[i][6])
        except:
            create_log.log().createLog(
                'failed to create invoice position template for text')
    def createPositions(self, position_data, invoice_data):
        invoice_xml_positions_text = open(
            configuration.TEMPLATE_INVOICE_XML_POSITION).read()
        invoice_xml_position = Template(invoice_xml_positions_text)

        try:
            for i in range(0, len(position_data)):
                self.calculateVatPos(position_data, i)
                self.position_text += invoice_xml_position.substitute(
                    position_id=position_data[i][1],
                    item_description=position_data[i][2],
                    item_date=invoice_data[3],
                    quantity=position_data[i][3],
                    total_item_amount=position_data[i][5],
                    total_item_amount_vat=self.vat_total_position,
                    vat=position_data[i][6],
                )
                self.number_positions = self.number_positions + 1
        except:
            create_log.log().createLog('failed to create position for xml')
Exemple #8
0
 def prepare_data(self, data):
     try:
         global string_invoice_data
         string_data = str(data)
         string_data = string_data.replace('\\r\\n', ';')
         string_data = string_data.split(';')
         for splitted_data in string_data:
             self.invoice_data.append(splitted_data)
         self.calculateDate()
         self.calculateInvoicePos()
         create_invoice_text.createInvoice().writeInvoice(
             self.invoice_data,
             datetime.datetime.strftime(self.calculated_date, "%d.%m.%Y"),
             self.invoice_position_data, self.calculated_price)
         create_invoice_xml.createInvoiceXml().createXml(
             self.invoice_data,
             datetime.datetime.strftime(self.calculated_date, "%d.%m.%Y"),
             self.invoice_position_data, self.calculated_price,
             self.calculated_total_with_vat, self.vat)
         string_invoice_data = self.invoice_data
     except:
         create_log.log().createLog(
             'wrong data in the csv-file, pls check the csv file')
    def createXml(self, invoice_data, calculated_date, position_data,
                  calculated_price, calculated_total_with_vat, vat):
        invoice_xml_text = open(configuration.TEMPLATE_INVOICE_XML).read()
        self.createPositions(position_data, invoice_data)
        filename = open(invoice_data[7] + "_" +
                        invoice_data[0].replace('\'Rechnung_', '') +
                        "_invoice.xml",
                        "w",
                        encoding='utf-8')
        template_invoice_xml = Template(invoice_xml_text)

        try:
            invoice_xml = template_invoice_xml.substitute(
                invoice_number=invoice_data[0].replace('\'Rechnung_', ''),
                date=invoice_data[3],
                mail=invoice_data[13],
                receiver_number_4=invoice_data[15][:4],
                receiver_number_17=invoice_data[15],
                receiver_name=invoice_data[16],
                receiver_plz=invoice_data[18][:4],
                receiver_location=invoice_data[18][5:],
                firmname=invoice_data[8],
                firm_address=invoice_data[10],
                firm_plz=invoice_data[11][:4],
                firm_location=invoice_data[11][5:],
                calculated_date=calculated_date,
                vat_number=invoice_data[12],
                invoice_xml_position=self.position_text,
                number_positions=self.number_positions,
                calculated_total=calculated_price,
                vat_amount=vat,
                calculated_total_with_vat=calculated_total_with_vat,
                vat=vat)

            filename.write(invoice_xml)
        except:
            create_log.log().createLog('failed to create' + filename)