--- /dev/null
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('cmutuel', '0001_initial'),
+ ]
+
+ operations = [
+ # Transfer exisitng ledger entries to the general one
+ migrations.RunSQL("""
+INSERT INTO invoices_bankstatementrow (created, uniqueid, date, amount, description, balance, other, fromfile_id, method_id)
+SELECT
+ CURRENT_TIMESTAMP,
+ NULL,
+ opdate,
+ amount,
+ description,
+ balance,
+ jsonb_build_object('valdate', valdate),
+ NULL,
+ (SELECT id FROM invoices_invoicepaymentmethod WHERE classname='pgeusite.cmutuel.util.CMutuelPayment')
+FROM cmutuel_cmutueltransaction
+"""),
+ # Update the existing payment entries
+ migrations.RunSQL("""
+UPDATE invoices_invoicepaymentmethod SET
+ classname='postgresqleu.util.payment.banktransfer.GenericManagedBankPayment',
+ config=config || '{"filetype": "cmutuel", "definition": "", "description": "Pay using a direct IBAN bank transfer in EUR. We <strong>strongly advice</strong> not using this method if making a payment from outside the Euro-zone, as amounts must be exact and all fees covered by sender."}'::jsonb
+WHERE classname='pgeusite.cmutuel.util.CMutuelPayment'
+ """)
+ ]
+++ /dev/null
-from django import forms
-from django.shortcuts import render
-from django.template import Template, Context
-
-from urllib.parse import urlencode
-import csv
-import datetime
-from decimal import Decimal
-
-from postgresqleu.util.payment.banktransfer import BaseManagedBankPayment
-from postgresqleu.util.payment.banktransfer import BaseManagedBankPaymentForm
-from postgresqleu.invoices.models import Invoice
-from postgresqleu.invoices.util import register_bank_transaction
-
-from pgeusite.cmutuel.models import CMutuelTransaction
-
-
-class BackendCMutuelForm(BaseManagedBankPaymentForm):
- bank_file_uploads = True
-
-
-class CMutuelPayment(BaseManagedBankPayment):
- backend_form_class = BackendCMutuelForm
- description = """
-Pay using a direct IBAN bank transfer in EUR. We
-<strong>strongly advice</strong> not using this method if
-making a payment from outside the Euro-zone, as amounts
-must be exact and all fees covered by sender.
-"""
- upload_tooltip = """Go the CM website, select the account and click the download button for format <i>other</i>.
-
-<b>Format:</b> CSV
-<b>Format:</b> Excel XP and following
-<b>Dates:</b> French long
-<b>Field separator:</b> Semicolon
-<b>Amounts in:</b> a single column
-<b>Decimal separator:</b> point
-
-Download a reasonable range of transactions, typically with a few days overlap.
-""".replace("\n", "<br/>")
-
- def render_page(self, request, invoice):
- return render(request, 'cmutuel/payment.html', {
- 'invoice': invoice,
- })
-
- def parse_uploaded_file(self, f):
- contents = f.read().decode('iso-8859-1')
- reader = csv.reader(contents.splitlines(), delimiter=';')
-
- # Write everything to the database
- foundheader = False
- numrows = 0
- numtrans = 0
- numpending = 0
- for row in reader:
- if row[0] == 'Date':
- # Validaste the header
- colheaders = [['Date'], ['Value date', 'Date de valeur'], ['Amount', 'Montant'], ['Message', 'Libellé'], ['Balance', 'Solde']]
- if len(row) != len(colheaders):
- raise Exception("Invalid number of columns in input file. Got {}, expected {}.".format(len(row), len(colheaders)))
- for i in range(len(colheaders)):
- if not row[i] in colheaders[i]:
- raise Exception("Invalid column {}. Got {}, expected {}.".format(i, row[i], colheaders[i]))
- foundheader = True
- continue
- if not foundheader:
- raise Exception("Header row missing in file")
-
- numrows += 1
-
- try:
- opdate = datetime.datetime.strptime(row[0], '%d/%m/%Y')
- valdate = datetime.datetime.strptime(row[1], '%d/%m/%Y')
- amount = Decimal(row[2])
- description = row[3]
- balance = Decimal(row[4])
-
- if opdate.date() == datetime.date.today() and amount > 0 and description.startswith("VIR "):
- # For incoming transfers we sometimes don't get the full transaction text
- # right away. Because, reasons unknown. So if the transaction is actually
- # dated today and it starts with VIR, we ignore it until we get to tomorrow.
- continue
-
- if not CMutuelTransaction.objects.filter(opdate=opdate, valdate=valdate, amount=amount, description=description).exists():
- trans = CMutuelTransaction(opdate=opdate,
- valdate=valdate,
- amount=amount,
- description=description,
- balance=balance)
- trans.save()
- numtrans += 1
-
- # Also send the transaction into the main system. Unfortunately we don't
- # know the sender.
- # register_bank_transaction returns True if the transaction has been fully
- # processed and thus don't need anything else, so we just consider it
- # sent already.
- if register_bank_transaction(self.method, trans.id, amount, description, ''):
- trans.sent = True
- trans.save()
- else:
- numpending += 1
- except Exception as e:
- # Re-raise but including the full row information
- raise Exception("Exception '{0}' when parsing row {1}".format(e, row))
-
- return (contents, numrows, numtrans, numpending)
+++ /dev/null
-{%extends "navbase.html"%}
-{%block title%}Pay with bank transfer{%endblock%}
-{%block content%}
-<h1>Pay with bank transfer</h1>
-<p>
-To pay your invoice using bank transfer, please make a payment
-according to the following:
-</p>
-
-<table border="1" cellspacing="0" cellpadding="3">
-<tr>
- <th>Account holder</th>
- <td>Association PostgreSQL Europe</td>
-</tr>
-<tr>
- <th>Bank name</th>
- <td>CCM PARIS 1-2 LOUVRE MONTORGUEIL</td>
-</tr>
-<tr>
- <th>BIC</th>
- <td>CMCIFR2A</td>
-</tr>
-<tr>
- <th>IBAN</th>
- <td>FR76 1027 8060 3100 0205 2290 114</td>
-</tr>
-<tr>
- <th>Payment reference</th>
- <td>{{invoice.payment_reference}}</td>
-</tr>
-<tr>
- <th>Amount</th>
- <td>€{{invoice.total_amount}}</td>
-</tr>
-</table>
-
-<p>
-<b>Note</b> that it is <b><i>very</i></b> important that you provide the
-correct text on the transfer, or we may not be able to match your payment
-to the correct invoice. In particular, <b>do not</b> use the invoice number,
-use the given payment reference!
-</p>
-
-<p>
-<b>Note</b> that bank transfers take a few days to process, so if your
-payment is nedeed repidly in order to confirm something, this is not a good
-choice of payment method.
-</p>
-
-{%if returnurl%}<a href="{{returnurl}}" class="btn btn-outline-dark">Return to payment options</a>{%endif%}
-
-{%endblock%}