From: Anne Limoges Date: Tue, 19 Mar 2013 09:14:36 +0000 (+0100) Subject: Clean bankaccounts for payment transfers. X-Git-Tag: xorg/1.1.8~11 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=38813e10bde5b6729d38c51f239dc9362d8089d7;p=platal.git Clean bankaccounts for payment transfers. --- diff --git a/modules/payment.php b/modules/payment.php index 1703917..b97b569 100644 --- a/modules/payment.php +++ b/modules/payment.php @@ -127,7 +127,7 @@ class PaymentModule extends PLModule 'admin/reconcile' => $this->make_hook('adm_reconcile', AUTH_PASSWD, 'admin'), 'admin/reconcile/importlogs' => $this->make_hook('adm_importlogs', AUTH_PASSWD, 'admin'), 'admin/reconcile/transfers' => $this->make_hook('adm_transfers', AUTH_PASSWD, 'admin'), - 'admin/payments/bankaccounts' => $this->make_hook('adm_bankaccounts', AUTH_PASSWD, 'admin'), + 'admin/payments/bankaccounts' => $this->make_hook('adm_bankaccounts', AUTH_PASSWD, 'admin'), ); } @@ -632,14 +632,15 @@ class PaymentModule extends PLModule $table_editor->describe('asso_id', 'ID du groupe', false, true); $table_editor->describe('owner', 'titulaire', true); $table_editor->add_option_table('groups', 'groups.id = t.asso_id'); - $table_editor->add_option_field('groups.diminutif', 'group_name', 'groupe', 'varchar','account'); + $table_editor->add_option_field('groups.diminutif', 'group_name', 'groupe', 'varchar','iban'); - // check RIB key + /* check RIB key FIXME: the column format (and name) changed if ($action == 'update' && Post::has('account') && !check_rib(Post::v('account'))) { $page->trigError("Le RIB n'est pas valide"); $table_editor->apply($page, 'edit', $id); return; } + */ $table_editor->apply($page, $action, $id); } @@ -710,12 +711,26 @@ class PaymentModule extends PLModule $recongp['id']); $recongp['recons'] = $res->fetchAllAssoc(); - $res = XDB::query('SELECT t.id, t.payment_id, t.amount, b.owner, t.message, t.date + $res = XDB::query('SELECT t.id, t.payment_id, t.amount, t.message, t.date FROM payment_transfers AS t - LEFT JOIN payment_bankaccounts AS b ON (t.account_id=b.id) WHERE recongroup_id = {?}', $recongp['id']); - $recongp['transfers'] = $res->fetchAllAssoc(); + $transfers = $res->fetchAllAssoc(); + foreach ($transfers as $id => $t) { + if ($t['date'] == NULL) { // si le virement n'est pas fait, on va récupérer le rib associé au paiment + $ownertmp = XDB::fetchOneCell('SELECT b.owner + FROM payment_bankaccounts AS b + LEFT JOIN payments AS p ON (p.rib_id = b.id) + WHERE p.id = {?}', $t['payment_id']); + } else { // sinon on prend celui associé au virement + $ownertmp = XDB::fetchOneCell('SELECT b.owner + FROM payment_bankaccounts AS b + LEFT JOIN payment_transfers AS t ON (t.account_id = b.id) + WHERE t.id = {?}', $t['id']); + } + $transfers[$id]['owner'] = $ownertmp; + } + $recongp['transfers'] = $transfers; $recongps[] = $recongp; } @@ -915,7 +930,7 @@ class PaymentModule extends PLModule // create transfers XDB::execute('INSERT INTO payment_transfers - SELECT NULL, {?}, t.ref, SUM(t.amount+t.commission), p.rib_id, p.text, NULL + SELECT NULL, {?}, t.ref, SUM(t.amount+t.commission), NULL, p.text, NULL FROM payment_transactions AS t LEFT JOIN payments AS p ON (t.ref = p.id) LEFT JOIN groups AS g ON (p.asso_id = g.id) @@ -942,9 +957,13 @@ class PaymentModule extends PLModule } elseif ($action == "confirm") { S::assert_xsrf_token(); + $account_id = XDB::fetchOneCell('SELECT rib_id + FROM payments AS p + LEFT JOIN payment_transfers AS t ON (t.payment_id = p.id) + WHERE t.id = {?}', $id); XDB::execute('UPDATE payment_transfers - SET date = NOW() - WHERE id = {?}', $id); + SET date = NOW(), account_id = {?} + WHERE id = {?}', $account_id, $id); $page->trigSuccess('Virement ' . $id . ' confirmé.'); $this->handler_adm_reconcile($page); diff --git a/upgrade/1.1.8/01_clean_bankaccounts.sql b/upgrade/1.1.8/01_clean_bankaccounts.sql new file mode 100644 index 0000000..5e1884a --- /dev/null +++ b/upgrade/1.1.8/01_clean_bankaccounts.sql @@ -0,0 +1,10 @@ +UPDATE payments SET rib_id = NULL; +UPDATE payment_transfers SET account_id = NULL +DELETE FROM payment_bankaccounts; +ALTER TABLE payment_bankaccounts CHANGE account iban varchar(33) NOT NULL DEFAULT 'FRkk BBBB BGGG GGCC CCCC CCCC CKK'; +ALTER TABLE payment_bankaccounts ADD COLUMN bic varchar(11) NOT NULL DEFAULT 'XXXXXXXXXXX' AFTER iban; +INSERT INTO payment_bankaccounts (id, asso_id, iban, bic, owner, status) VALUES (1, 53, DEFAULT, DEFAULT, 'RIB inconnu', 'new'); +UPDATE payments SET rib_id = 1; +ALTER TABLE payments CHANGE rib_id rib_id int(11) NOT NULL DEFAULT 1; + +-- vim=set syntax=mysql