From: Damien Bobillot Date: Wed, 25 May 2011 17:43:42 +0000 (+0200) Subject: Amount column in payment table is now a number (was a text) X-Git-Tag: xorg/1.1.2~75 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=a7c0d514f97ce39696d5660ef4faccdd8380fe00;p=platal.git Amount column in payment table is now a number (was a text) Schmurtz --- diff --git a/modules/payment.php b/modules/payment.php index e7c588f..bd6139b 100644 --- a/modules/payment.php +++ b/modules/payment.php @@ -163,10 +163,10 @@ class PaymentModule extends PLModule $pay->init($val, $meth); $pay->prepareform($pay); } else { - $res = XDB::iterator('SELECT timestamp, amount + $res = XDB::iterator('SELECT ts_confirmed, amount FROM payment_transactions WHERE uid = {?} AND ref = {?} - ORDER BY timestamp DESC', + ORDER BY ts_confirmed DESC', S::v('uid', -1), $ref); if ($res->total()) { @@ -186,8 +186,7 @@ class PaymentModule extends PLModule $ref); $sum = 0; foreach ($donations as $d) { - $amount = $d['amount']; - $sum += trim(strtr(substr($amount, 0, strpos($amount, 'EUR')), ',', '.')); + $sum += $d['amount']; } $page->assign('donations', $donations); @@ -195,7 +194,7 @@ class PaymentModule extends PLModule } } - $val = floor($val) . '.' . substr(floor(($val - floor($val)) * 100 + 100), 1); + $val = floor($val*100)/100; $page->assign('montant', $val); $page->assign('comment', Env::v('comment')); @@ -246,8 +245,7 @@ class PaymentModule extends PLModule if (Env::v('vads_currency') != '978') { cb_erreur("monnaie autre que l'euro"); } - $amount = ((float)Env::i('vads_amount')) / 100; - $montant = sprintf("%.02f EUR", $amount); + $montant = ((float)Env::i('vads_amount')) / 100; /* on extrait le code de retour */ if (Env::v('vads_result') != '00') { @@ -255,10 +253,10 @@ class PaymentModule extends PLModule } /* on fait l'insertion en base de donnees */ - XDB::execute('INSERT INTO payment_transactions (id, uid, ref, fullref, amount, pkey, comment, display) - VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})', + XDB::execute('INSERT INTO payment_transactions (id, method_id, uid, ref, fullref, ts_confirmed, amount, pkey, comment, status, display) + VALUES ({?}, 2, {?}, {?}, {?}, NOW(), {?}, {?}, {?}, "confirmed", {?})', Env::v('vads_trans_date'), $user->id(), $ref, Env::v('vads_order_id'), $montant, '', Env::v('vads_order_info'), Env::i('vads_order_info2')); - echo "Paiement stored.\n"; + echo "Payment stored.\n"; // We check if it is an Xnet payment and then update the related ML. $res = XDB::query('SELECT eid, asso_id @@ -319,10 +317,11 @@ class PaymentModule extends PLModule /* reference complete de la commande */ $fullref = Env::s('cm'); /* montant de la transaction */ - $montant_nb = Env::s('amt'); + $montant = Env::s('amt'); /* devise */ - $montant_dev = Env::s('cc'); - $montant = "$montant_nb $montant_dev"; + if (Env::s('cc') != 'EUR') { + cb_erreur("monnaie autre que l'euro"); + } /* on extrait le code de retour */ if ($status != "Completed") { @@ -353,8 +352,8 @@ class PaymentModule extends PLModule } /* on fait l'insertion en base de donnees */ - XDB::execute("INSERT INTO payment_transactions (id, uid, ref, fullref, amount, pkey, comment, display) - VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, '?})", + XDB::execute("INSERT INTO payment_transactions (id, method_id, uid, ref, fullref, ts_confirmed, amount, pkey, comment, status, display) + VALUES ({?}, 1, {?}, {?}, {?}, NOW(), {?}, {?}, {?}, 'confirmed', {?})", $no_transaction, $user->id(), $ref, $fullref, $montant, $clef, Env::v('comment'), Get::i('display')); // We check if it is an Xnet payment and then update the related ML. @@ -462,7 +461,7 @@ class PaymentModule extends PLModule foreach($tit as $foo) { $pid = $foo['id']; if (may_update()) { - $res = XDB::query('SELECT p.uid, IF(p.timestamp = \'0000-00-00\', 0, p.timestamp) AS date, p.comment, p.amount + $res = XDB::query('SELECT p.uid, IF(p.ts_confirmed = \'0000-00-00\', 0, p.ts_confirmed) AS date, p.comment, p.amount FROM payment_transactions AS p INNER JOIN accounts AS a ON (a.uid = p.uid) LEFT JOIN account_profiles AS ap ON (ap.uid = p.uid AND FIND_IN_SET(\'owner\', ap.perms)) @@ -472,11 +471,11 @@ class PaymentModule extends PLModule $trans[$pid] = User::getBulkUsersWithUIDs($res->fetchAllAssoc(), 'uid', 'user'); $sum = 0; foreach ($trans[$pid] as $i => $t) { - $sum += strtr(substr($t['amount'], 0, strpos($t['amount'], 'EUR')), ',', '.'); - $trans[$pid][$i]['amount'] = str_replace('EUR', '€', $t['amount']); + $sum += $t['amount']; + $trans[$pid][$i]['amount'] = $t['amount']; } $trans[$pid][] = array('limit' => true, - 'amount' => strtr($sum, '.', ',') . ' €'); + 'amount' => $sum); } $res = XDB::iterRow("SELECT e.eid, e.short_name, e.intitule, ep.nb, ei.montant, ep.paid FROM group_events AS e @@ -497,15 +496,10 @@ class PaymentModule extends PLModule $event[$pid]['paid'] = $paid; } } - $res = XDB::query('SELECT amount + $res = XDB::query('SELECT SUM(amount) AS sum_amount FROM payment_transactions WHERE ref = {?} AND uid = {?}', $pid, S::v('uid')); - $montants = $res->fetchColumn(); - - foreach ($montants as $m) { - $p = strtr(substr($m, 0, strpos($m, 'EUR')), ',', '.'); - $event[$pid]['paid'] += trim($p); - } + $event[$pid]['paid'] = $res->fetchOneCell(); } $page->register_modifier('decode_comment', 'decode_comment'); $page->assign('trans', $trans); @@ -521,10 +515,10 @@ class PaymentModule extends PLModule $pid = substr($pid, 0, strlen($pid) - 4); } - $res = XDB::fetchAllAssoc('SELECT uid, IF(timestamp = \'0000-00-00\', 0, timestamp) AS date, comment, amount + $res = XDB::fetchAllAssoc('SELECT uid, IF(ts_confirmed = \'0000-00-00\', 0, ts_confirmed) AS date, comment, amount FROM payment_transactions WHERE ref = {?} - ORDER BY timestamp', + ORDER BY ts_confirmed', $pid); if (is_null($res)) { pl_redirect('payment'); @@ -538,12 +532,12 @@ class PaymentModule extends PLModule fputcsv($csv, array('Date', 'Nom', 'Prénom', 'Sexe', 'Promotion', 'Email', 'Commentaire', 'Montant'), ';'); foreach ($users as $item) { $user = $item['user']; - $sum += strtr(substr($item['amount'], 0, strpos($item['amount'], 'EUR')), ',', '.'); + $sum += $item['amount']; fputcsv($csv, array(format_datetime($item['date'], '%d/%m/%y'), $user->lastName(), $user->firstName(), ($user->isFemale()) ? 'F' : 'M', $user->promo(), $user->ForlifeEmail(), - $item['comment'], str_replace('EUR', '€', $item['amount'])), ';'); + $item['comment'], strtr($item['amount'],'.',',').' €' ), ';'); } - fputcsv($csv, array(date('d/m/y'), 'Total', '', '', '' , '', '', strtr($sum, '.', ',') . ' €'), ';'); + fputcsv($csv, array(date('d/m/y'), 'Total', '', '', '' , '', '', strtr($sum,'.',',').' €'), ';'); fclose($csv); exit; diff --git a/modules/xnetevents.php b/modules/xnetevents.php index 45767f5..d2d8390 100644 --- a/modules/xnetevents.php +++ b/modules/xnetevents.php @@ -151,16 +151,11 @@ class XnetEventsModule extends PLModule $e['topay'] += $m['nb'] * $m['montant']; } - $query = XDB::query( - "SELECT amount + $montant = XDB::fetchOneCell( + "SELECT SUM(amount) as sum_amount FROM payment_transactions AS t WHERE ref = {?} AND uid = {?}", $e['paiement_id'], S::v('uid')); - $montants = $query->fetchColumn(); - - foreach ($montants as $m) { - $p = strtr(substr($m, 0, strpos($m, 'EUR')), ',', '.'); - $e['paid'] += trim($p); - } + $e['paid'] += $montant; make_event_date($e); diff --git a/modules/xnetevents/xnetevents.inc.php b/modules/xnetevents/xnetevents.inc.php index cc95c4d..52c4ad2 100644 --- a/modules/xnetevents/xnetevents.inc.php +++ b/modules/xnetevents/xnetevents.inc.php @@ -80,16 +80,12 @@ function get_event_detail($eid, $item_id = false, $asso_id = null) $evt['notify_payment'] = $evt['notify_payment'] || $m['notify_payment']; } - $montants = XDB::fetchColumn('SELECT amount + $montant = XDB::fetchOneCell('SELECT SUM(amount) AS sum_amount FROM payment_transactions AS t WHERE ref = {?} AND uid = {?}', $evt['paiement_id'], S::v('uid')); - $evt['telepaid'] = 0; - foreach ($montants as $m) { - $p = strtr(substr($m, 0, strpos($m, 'EUR')), ',', '.'); - $evt['paid'] += trim($p); - $evt['telepaid'] += trim($p); - } + $evt['telepaid'] = $montant; + $evt['paid'] += $montant; $evt['organizer'] = User::getSilent($evt['uid']); make_event_date($evt); @@ -137,14 +133,11 @@ function get_event_participants(&$evt, $item_id, array $tri = array(), $limit = $u['adminpaid'] = $u['paid']; $u['montant'] = 0; if ($money && $pay_id) { - $montants = XDB::fetchColumn('SELECT amount + $montant = XDB::fetchOneCell('SELECT SUM(amount) FROM payment_transactions AS t WHERE ref = {?} AND uid = {?}', $pay_id, $uid); - foreach ($montants as $m) { - $p = strtr(substr($m, 0, strpos($m, "EUR")), ",", "."); - $u['paid'] += trim($p); - } + $u['paid'] += $montant; } $u['telepayment'] = $u['paid'] - $u['adminpaid']; $res_ = XDB::iterator('SELECT ep.nb, ep.item_id, ei.montant diff --git a/templates/payment/index.tpl b/templates/payment/index.tpl index 1b40c17..69b0bc7 100644 --- a/templates/payment/index.tpl +++ b/templates/payment/index.tpl @@ -167,8 +167,8 @@ function payment_submit(form) DateMontant {iterate from=$transactions item=t} - {$t.timestamp|date_format} - {$t.amount|replace:'EUR':'€'} + {$t.ts_confirmed|date_format} + {$t.amount|replace:'.':','} € {/iterate} @@ -187,7 +187,7 @@ function payment_submit(form) {foreach from=$donations item=d} {$d.name} - {$d.amount|replace:'EUR':'€'} + {$d.amount|replace:'.':','} € {/foreach} diff --git a/templates/payment/xnet.tpl b/templates/payment/xnet.tpl index 89dddb1..1ab4219 100644 --- a/templates/payment/xnet.tpl +++ b/templates/payment/xnet.tpl @@ -139,7 +139,7 @@ il suffit de cliquer sur le titre de la colonne concernée. {$p.user->promo()} {$p.comment|comment_decode} - {$p.amount} + {$p.amount|replace:'.':','} € {elseif $smarty.foreach.people.first} @@ -148,7 +148,7 @@ il suffit de cliquer sur le titre de la colonne concernée. {else} Total - {$p.amount} + {$p.amount|replace:'.':','} € {/if} {/foreach} diff --git a/templates/xnetevents/admin.tpl b/templates/xnetevents/admin.tpl index 4ed095d..c27462d 100644 --- a/templates/xnetevents/admin.tpl +++ b/templates/xnetevents/admin.tpl @@ -97,7 +97,7 @@ Ils ont payé mais ont oublié de s'inscrire : {icon name=vcard title="vcard"} {icon name=email title="email"} - {$m.amount} + {$m.amount|replace:'.':','} € {/foreach} diff --git a/upgrade/1.0.1/13_payments.sql b/upgrade/1.0.1/13_payments.sql index 6252fbd..0196b9a 100644 --- a/upgrade/1.0.1/13_payments.sql +++ b/upgrade/1.0.1/13_payments.sql @@ -55,26 +55,6 @@ CREATE TABLE payment_reconcilations ( comments text NOT NULL ) ENGINE=InnoDB, CHARSET=utf8; -ALTER TABLE payment_transactions ADD method_id INTEGER DEFAULT NULL AFTER id; # NULL if not initiated from the site -ALTER TABLE payment_transactions CHANGE timestamp ts_confirmed DATETIME DEFAULT NULL; # NULL = not confirmed -ALTER TABLE payment_transactions ADD ts_initiated DATETIME DEFAULT NULL AFTER ts_confirmed; # NULL = not initiated -ALTER TABLE payment_transactions CHANGE amount amount_tmp VARCHAR(15); -ALTER TABLE payment_transactions ADD amount DECIMAL(9,2) NOT NULL AFTER amount_tmp; # only local currency allowed (EUR) -ALTER TABLE payment_transactions ADD commission DECIMAL(9,2) DEFAULT NULL AFTER amount; -ALTER TABLE payment_transactions ADD status ENUM('confirmed','pending','canceled') NOT NULL DEFAULT 'pending'; -ALTER TABLE payment_transactions ADD recon_id INTEGER DEFAULT NULL; # NULL = not reconciliated -UPDATE payment_transactions SET method_id = 0 WHERE length(id)=7; -UPDATE payment_transactions SET method_id = 1 WHERE length(id)=15 OR length(id)=17; -UPDATE payment_transactions SET method_id = 2 WHERE length(id)=14; -UPDATE payment_transactions SET status = 'confirmed'; -UPDATE payment_transactions SET amount=CONVERT(REPLACE(REPLACE(amount_tmp," EUR",""),",","."),DECIMAL(9,2)); -ALTER TABLE payment_transactions ADD KEY method_id (method_id); -ALTER TABLE payment_transactions ADD KEY ref (ref); -# ALTER TABLE payment_transactions ADD UNIQUE KEY fullref (fullref); -#fullref dupliqués : -#select t1.* from payment_transactions as t1 join payment_transactions as t2 using(fullref) group by(t1.id) having count(*)!=1 order by fullref; -ALTER TABLE payment_transactions DROP amount_tmp; - DROP TABLE IF EXISTS payment_transfers; CREATE TABLE payment_transfers ( id INTEGER PRIMARY KEY auto_increment, diff --git a/upgrade/1.1.2/02_payments.sql b/upgrade/1.1.2/02_payments.sql index 64359f7..99332d3 100644 --- a/upgrade/1.1.2/02_payments.sql +++ b/upgrade/1.1.2/02_payments.sql @@ -1,4 +1,25 @@ -ALTER TABLE payments MODIFY COLUMN flags SET('unique', 'old', 'donation') NOT NULL DEFAULT ''; +ALTER TABLE payment_transactions ADD method_id INTEGER DEFAULT NULL AFTER id; # NULL if not initiated from the site +ALTER TABLE payment_transactions CHANGE timestamp ts_confirmed DATETIME DEFAULT NULL; # NULL = not confirmed +ALTER TABLE payment_transactions ADD ts_initiated DATETIME DEFAULT NULL AFTER ts_confirmed; # NULL = not initiated +ALTER TABLE payment_transactions CHANGE amount amount_tmp VARCHAR(15); +ALTER TABLE payment_transactions ADD amount DECIMAL(9,2) NOT NULL AFTER amount_tmp; # only local currency allowed (EUR) +ALTER TABLE payment_transactions ADD commission DECIMAL(9,2) DEFAULT NULL AFTER amount; +ALTER TABLE payment_transactions ADD status ENUM('confirmed','pending','canceled') NOT NULL DEFAULT 'pending'; +ALTER TABLE payment_transactions ADD recon_id INTEGER DEFAULT NULL; # NULL = not reconciliated +UPDATE payment_transactions SET method_id = 0 WHERE length(id)=7; +UPDATE payment_transactions SET method_id = 1 WHERE length(id)=15 OR length(id)=17; +UPDATE payment_transactions SET method_id = 2 WHERE length(id)=14; +UPDATE payment_transactions SET status = 'confirmed'; +UPDATE payment_transactions SET amount=CONVERT(REPLACE(REPLACE(amount_tmp," EUR",""),",","."),DECIMAL(9,2)); +ALTER TABLE payment_transactions ADD KEY method_id (method_id); +ALTER TABLE payment_transactions ADD KEY ref (ref); +# ALTER TABLE payment_transactions ADD UNIQUE KEY fullref (fullref); +#fullref dupliqués : +#select t1.* from payment_transactions as t1 join payment_transactions as t2 using(fullref) group by(t1.id) having count(*)!=1 order by fullref; +ALTER TABLE payment_transactions DROP amount_tmp; + ALTER TABLE payment_transactions ADD COLUMN display BOOL NOT NULL DEFAULT FALSE; +ALTER TABLE payments MODIFY COLUMN flags SET('unique', 'old', 'donation') NOT NULL DEFAULT ''; -- vim:set syntax=mysql: +