Esempio n. 1
0
 def export_xls(self):
     from Common.exports_xlsx import export_dynamic_data
     dict_data = {
         'file_name':
         "versements",
         'headers':
         self.table.hheaders[:-1],
         'data':
         self.table.data,
         "extend_rows": [
             (1, self.table.label_mov_tt),
             (3, self.table.balance_tt),
         ],
         # "footers": [],
         'sheet':
         self.title,
         # 'title': self.title,
         'widths':
         self.table.stretch_columns,
         'exclude_row':
         len(self.table.data) - 1,
         'format_money': [
             "D:D",
         ],
         'others': [
             ("A7", "B7", "Compte : {}".format(self.table.provider_clt)),
             ("A8", "B8", "Du {} au {} : {}".format(
                 date_to_datetime(self.on_date.text()).strftime(
                     Config.DATEFORMAT),
                 date_to_datetime(
                     self.end_date.text()).strftime(Config.DATEFORMAT),
                 device_amount(self.table.balance_tt))),
         ],
     }
     export_dynamic_data(dict_data)
Esempio n. 2
0
    def __init__(self, parent=0, *args, **kwargs):

        super(ProvidersViewWidget, self).__init__(parent=parent,
                                                  *args,
                                                  **kwargs)

        self.parent = parent

        self.title = u"Movements"

        self.on_date = FormatDate(QDate(date.today().year, 1, 1))
        self.end_date = FormatDate(QDate.currentDate())
        # self.now = datetime.now().strftime("%x")
        self.soldeField = FormLabel("{}".format(device_amount(0)))
        balanceBox = QGridLayout()
        balanceBox.addWidget(self.soldeField, 0, 3)
        balanceBox.setColumnStretch(0, 1)

        self.string_list = [""] + [
            "{},{}".format(clt.name, clt.phone)
            for clt in ProviderOrClient.select().where(
                ProviderOrClient.type_ == ProviderOrClient.CLT).order_by(
                    ProviderOrClient.name.desc())
        ]

        self.name_client_field = ExtendedComboBox()
        self.name_client_field.addItems(self.string_list)
        self.name_client_field.setMaximumSize(
            200,
            self.name_client_field.maximumSize().height())
        self.name_client_field.setToolTip("Nom, numero du client")

        self.table = RapportTableWidget(parent=self)
        self.button = Button(u"Ok")
        self.button.clicked.connect(self.refresh_prov_clt)

        self.btt_export = BttExportXLSX(u"Exporter")
        self.btt_export.clicked.connect(self.export_xls)

        editbox = QGridLayout()
        editbox.addWidget(FormLabel(u"Date debut"), 0, 1)
        editbox.addWidget(self.on_date, 0, 2)
        editbox.addWidget(FormLabel(u"Date fin"), 1, 1)
        editbox.addWidget(self.end_date, 1, 2)
        editbox.addWidget(self.name_client_field, 0, 3)
        editbox.addWidget(self.button, 1, 3)

        editbox.addWidget(self.btt_export, 1, 7)
        editbox.setColumnStretch(4, 2)
        vbox = QVBoxLayout()
        vbox.addWidget(FPageTitle(self.title))
        vbox.addLayout(editbox)
        vbox.addWidget(self.table)
        vbox.addLayout(balanceBox)
        self.setLayout(vbox)
Esempio n. 3
0
 def extend_rows(self):
     nb_rows = self.rowCount()
     self.setRowCount(nb_rows + 2)
     self.setSpan(nb_rows + 2, 2, 2, 4)
     cp = 0
     self.balance_tt = sum([
         is_int(unicode(self.item(row_num, 3).text()))
         for row_num in range(0, self.data.__len__())
     ])
     self.label_mov_tt = u"Totals "
     self.setItem(nb_rows, 2, TotalsWidget(self.label_mov_tt))
     self.setItem(nb_rows, 3, TotalsWidget(device_amount(self.balance_tt)))
Esempio n. 4
0
    def refresh_(self, provid_clt_id=None, search=None):
        """ """

        self.totals_debit = 0
        self.totals_credit = 0
        self.balance_tt = 0
        self.d_star = date_to_datetime(self.parent.on_date.text())
        self.d_end = date_to_datetime(self.parent.end_date.text())
        l_date = [self.d_star, self.d_end]
        self._reset()
        self.set_data_for(l_date, provid_clt_id=provid_clt_id, search=search)
        self.refresh()

        pw = self.parent.parent.page_width() / 6
        self.setColumnWidth(0, pw)
        self.setColumnWidth(1, pw)
        self.setColumnWidth(2, pw * 2)
        self.setColumnWidth(3, pw)

        self.parent.soldeField.setText(
            self.parent.display_remaining(device_amount(self.balance_tt)))
Esempio n. 5
0
 def cal_total(self):
     total = is_int(self.apports_numeraire_field.text() or 0) + is_int(
         self.apports_nature_field.text() or 0) + is_int(
             self.apports_industrie_field.text() or 0)
     self.capitalSGroupBox.setTitle("7. {} :  {}".format(
         MONTANT_CAPITAL_SI, device_amount(total)))
Esempio n. 6
0
def pdf_view(filename, invoice):
    """
        cette views est cree pour la generation du PDF
    """

    if not filename:
        filename = get_temp_filename('pdf')
        # print(filename)
    # on recupere les items de la facture
    items_invoice = Report.filter(invoice=invoice)
    # Static source pdf to be overlayed
    PDFSOURCE = Config.INV_TEMPLATE_PDF
    TMP_FILE = os.path.join(Config.ROOT_DIR, 'tmp.pdf')
    DATE_FORMAT = u"%d/%m/%Y"
    DEFAULT_FONT_SIZE = 11
    FONT = 'Times-Roman'

    # PDF en entrée
    input1 = PdfFileReader(file(PDFSOURCE, "rb"))
    # PDF en sortie
    output = PdfFileWriter()
    # Récupération du nombre de pages
    n_pages = input1.getNumPages()
    # Pour chaque page

    for i in range(n_pages):
        # Récupération de la page du doc initial (input1)
        page = input1.getPage(i)
        p = canvas.Canvas(TMP_FILE, pagesize=A4)
        p.setFont(FONT, DEFAULT_FONT_SIZE)
        p.drawString(115, 639, str(invoice.number))
        p.drawString(82, 625, (invoice.client.name))
        p.drawString(445, 625, str(invoice.date.strftime(DATE_FORMAT)))
        # On ecrit les invoiceitem
        x, y = 122, 574
        x_qty = x
        x_description = x + 10
        x_price = x + 340
        x_amount = x + 433

        for i in items_invoice:
            p.drawRightString(x_qty, y, str(i.qty))
            p.drawString(x_description, y, str(i.product.name))
            p.drawRightString(x_price, y, str(
                formatted_number(i.selling_price)))
            p.drawRightString(x_amount, y, str(formatted_number(
                i.selling_price * i.qty)))
            y -= 17
        # On calcul le montant total hors taxe et sa conversion en lettre
        ht = sum([(val.selling_price * val.qty) for val in items_invoice])
        tax_rate = invoice.tax_rate if invoice.tax else 0
        mt_tax = int((ht * tax_rate) / 100)
        htt = mt_tax + ht
        ht_en_lettre = num2words(ht, lang="fr")
        ht_en_lettre1, ht_en_lettre2 = controle_caratere(
            ht_en_lettre + " francs CFA", 50, 50)
        p.drawString(260, 191, (ht_en_lettre1))
        p.drawString(50, 175, (ht_en_lettre2))
        p.setFont('Times-Bold', 11)
        p.drawString(52, 639, "Facture N° :")
        p.drawString(x_price - 20, 248, str(tax_rate) + "%")
        # TVA
        p.drawRightString(x_amount, 248, device_amount(mt_tax))
        # Hors Taxe
        p.drawRightString(x_amount, 265, str(device_amount(ht)))
        # Tout Taxe
        p.drawRightString(x_amount, 232, str(device_amount(htt)))
        x_foot = 145
        p.drawString(50, x_foot, "Acceptation" if invoice.type_ ==
                     "Proforma" else "Acquit")
        p.drawString(490, x_foot, "Fournisseur")
        p.showPage()
        # Sauvegarde de la page
        p.save()
        # Création du watermark
        watermark = PdfFileReader(file(TMP_FILE, "rb"))
        # Création page_initiale+watermark
        page.mergePage(watermark.getPage(0))
        # Création de la nouvelle page
        output.addPage(page)
    # Nouveau pdf
    file_dest = filename + ".pdf"
    try:
        outputStream = file(file_dest, u"wb")
        output.write(outputStream)
        outputStream.close()
        return file_dest
    except OSError as e:
        from Common.ui.util import raise_error
        raise_error(u"Impossible de lancer le PDF", """
                    Car un autre en cours d'utilistation. Kill le \n{}""".format(e))
        return