Fixed various details.
authorAndreas Schiermeier <andreas@schiermeier.name>
Mon, 13 Jan 2014 19:55:29 +0000 (20:55 +0100)
committerAndreas Schiermeier <andreas@schiermeier.name>
Mon, 13 Jan 2014 19:55:29 +0000 (20:55 +0100)
UPGRADE.txt [new file with mode: 0644]
include/directdebit.php
include/earnings.php
include/members.php
include/xlsexport.php

diff --git a/UPGRADE.txt b/UPGRADE.txt
new file mode 100644 (file)
index 0000000..91c3b3c
--- /dev/null
@@ -0,0 +1,4 @@
+
+// Upgrade existing database:
+// ALTER TABLE `memberdb_members` ADD `ddmandatesigdate` datetime NOT NULL AFTER `directdebit`;
+// UPDATE memberdb_members, memberdb_events SET memberdb_members.ddmandatesigdate = memberdb_events.event_date WHERE memberdb_members.id = memberdb_events.member_id AND memberdb_members.ddmandatesigdate = '0000-00-00 00:00:00' AND memberdb_events.event_type = 'joined' AND memberdb_members.directdebit IN (1, 2, 3);
index d3d5d6c..e30816a 100644 (file)
@@ -132,8 +132,10 @@ function action_directdebit() {
 <?php endforeach ?>
 <input class="submit" type="submit" name="btn_create_earnings" value="Einnahmen verbuchen"/>
 </form>
-
-<a href="<?=link_to('export_ibanhin')?>">IBAN-hin Export</a>
+<hr/>
+<form action="<?=link_to('export_ibanhin')?>" method="POST" class="clearfix">
+<input class="submit" type="submit" name="btn_export_ibanhin" value="IBAN-hin Export"/>
+</form>
 
 <div id="password_popup" class="modal_window">
     <fieldset>
@@ -256,7 +258,7 @@ function generate_directdebit() {/*{{{*/
                
                // Mandatsreferenz '/V1/M:n/'; z.B. /V:1/M:2/
                var mandateref = '/V:1/M:' + debits[i]['member_number'] + '/';
-               var e2eid = mandateref + 'E2E:' + parseInt(SEPACORE.creationdate.getTime()/1000) + '/S:' + debits[i]['debittype'][0] + '/';
+               var e2eid = '/V:1/E2E:' + parseInt(SEPACORE.creationdate.getTime()/1000) + '/S:' + debits[i]['debittype'][0] + '/I:' + i + '/';
                if (!SEPACORE.addDDTx(debits[i]['debittype'], accountholder, accountnumber, bankcode, mandateref, debits[i]['ddmandatesigdate'].substring(0, 10), debits[i]['amountcent'], debits[i]['purpose'], e2eid)) {
                    $('#directdebit_content').val('Mitglied ' + debits[i]['member_number'] + ' ' + accountholder + '\n' + SEPACORE.errormsg);
                    return;
@@ -264,7 +266,7 @@ function generate_directdebit() {/*{{{*/
            }
            
            directdebitcontent = SEPACORE.getXMLContent('FRST');
-            directdebitcontent2 = SEPACORE.getXMLContent('RCUR');
+           directdebitcontent2 = SEPACORE.getXMLContent('RCUR');
             
            if (SEPACORE.errormsg.lenght > 0) {
                $('#directdebit_content').val(SEPACORE.errormsg);
index 41e5b2e..afba167 100644 (file)
@@ -193,6 +193,7 @@ function action_create_earnings() {/*{{{*/
     db_begin();
     foreach ($_POST['earnings'] as $post_data) {
         $log_messages = array();
+
         unset($post_data['id']);
         $earning = array(
             'account' => 'bank'
@@ -212,6 +213,14 @@ function action_create_earnings() {/*{{{*/
         }
     }
     db_commit();
+    
+    // SET directdebit from FRST to RCUR
+    foreach ($_POST['earnings'] as $post_data) {
+        $member['modified_at'] = db_unixtime2datetime(time());
+        $member['directdebit'] = 3; // RCUR
+        db_update_single(DB_TABLE_MEMBERS, $member, sprintf('directdebit=\'2\' AND id=\'%1$d\'', db_escape($post_data['member_id'])));
+    }
+
     redirect(link_to('finances'));
 }/*}}}*/
 
index 28e9f50..cac6ec8 100644 (file)
@@ -1,8 +1,5 @@
 <?php
 
-// UPGRADE EXISTING DATABASE TABLE:
-// ALTER TABLE `memberdb_members` ADD `ddmandatesigdate` datetime NULL AFTER `directdebit`;
-
 $SQL_CREATE_MEMBERS = sprintf('
     CREATE TABLE IF NOT EXISTS `%1$s` (
       `id` int(10) unsigned NOT NULL auto_increment,
@@ -15,7 +12,7 @@ $SQL_CREATE_MEMBERS = sprintf('
       `bankcode` blob NOT NULL,
       `bankname` blob NOT NULL,
       `directdebit` tinyint(1) NOT NULL,
-      `ddmandatesigdate` datetime NULL,
+      `ddmandatesigdate` datetime NOT NULL,
       `street` varchar(255) NOT NULL,
       `housenumber` varchar(255) NOT NULL,
       `postcode` varchar(255) NOT NULL,
@@ -50,7 +47,6 @@ $DIRECTDEBIT_STATES = array(
 
 function db_create_member($member) {
     unset($member['id']);
-    $member['ddmandatesigdate'] = ($member['ddmandatesigdate'] == "") ? '0' : db_unixtime2datetime(ui_date2unixtime($member['ddmandatesigdate']));
     $member['created_at']   = db_unixtime2datetime(time());
     $member['modified_at']  = db_unixtime2datetime(time());
     if (!db_insert_single(DB_TABLE_MEMBERS, $member)) return false;
@@ -60,7 +56,6 @@ function db_create_member($member) {
 function db_change_member($member) {
     $id = $member['id'];
     unset($member['id']);
-    $member['ddmandatesigdate'] = ($member['ddmandatesigdate'] == "") ? '0' : db_unixtime2datetime(ui_date2unixtime($member['ddmandatesigdate']));
     $member['modified_at']  = db_unixtime2datetime(time());
     return db_update_single(DB_TABLE_MEMBERS, $member, sprintf('id=\'%1$d\'', db_escape($id)));
 }
@@ -337,8 +332,18 @@ function action_create_member() {/*{{{*/
     $log_messages = array();
     if (isset($_POST['submit'])) {
         unset($_POST['id']);
+        
         if (validate_member($_POST, $member, $log_messages)) {
             if (empty($member['number'])) $member['number'] = db_get_next_free_member_number();
+            
+            if (($member['ddmandatesigdate'] == 'TT.MM.JJJJ') ||
+                ($member['ddmandatesigdate'] == ''))
+            {
+              $member['ddmandatesigdate'] = '0000-00-00 00:00:00';
+            } else {
+              $member['ddmandatesigdate'] = db_unixtime2datetime(ui_date2unixtime($member['ddmandatesigdate']));
+            }
+            
             if ($member_id = db_create_member($member)) {
                 redirect(link_to('view_member', array('id' => $member_id)) . '#events');
             }
@@ -356,6 +361,15 @@ function action_change_member() {/*{{{*/
     if (isset($_POST['submit'])) {
         if (validate_member($_POST, $member, $log_messages)) {
             if (empty($member['number'])) $member['number'] = db_get_next_free_member_number();
+                        
+            if (($member['ddmandatesigdate'] == 'TT.MM.JJJJ') ||
+                ($member['ddmandatesigdate'] == ''))
+            {
+              $member['ddmandatesigdate'] = '0000-00-00 00:00:00';
+            } else {
+              $member['ddmandatesigdate'] = db_unixtime2datetime(ui_date2unixtime($member['ddmandatesigdate']));
+            }
+
             if (db_change_member($member)) {
                 redirect(link_to('view_member', array('id' => $member['id'])));
             }
@@ -445,7 +459,16 @@ function form_member($member = array(), $readonly = false, $log_messages = array
                 <input class="submit" type="button" name="btn_bank_details" value="Bankverbindung &auml;ndern" onclick="bank_details_ask_pass()" id="btn_bank_details"/>
             <?php endif ?>
             <?=html_list_box('Beitragseinzug', 'directdebit', $DIRECTDEBIT_STATES, $member, $readonly)?>
-            <?php $member['ddmandatesigdate'] = ($member['ddmandatesigdate'] != 0) ? html_escape(format_date(db_date2unixtime($member['ddmandatesigdate']))) : "";  ?>
+            <?php
+              if ((!isset($member['ddmandatesigdate'])) ||
+                  ($member['ddmandatesigdate'] == '') ||
+                  ($member['ddmandatesigdate'] == '0000-00-00 00:00:00'))
+              {
+                $member['ddmandatesigdate'] = ($readonly) ? '' : html_escape('TT.MM.JJJJ');
+              } else {              
+                $member['ddmandatesigdate'] = html_escape(format_date(db_date2unixtime($member['ddmandatesigdate'])));
+              }
+            ?>
             <?=html_text_field('Mandatsunterschrift', 'ddmandatesigdate', $member, $readonly)?>
         </fieldset>
         <fieldset style="clear: left;">
index e32252d..27cbbc7 100644 (file)
@@ -45,6 +45,7 @@ function action_export_members() {
        $worksheet->write($row, $col++, 'Website');
        $worksheet->write($row, $col++, 'Twitter');
        $worksheet->write($row, $col++, 'Lastschrifteinzug');
+       $worksheet->write($row, $col++, 'Mandatunterschriftsdatum');
        $worksheet->write($row, $col++, 'Status');
        $row++;
        
@@ -71,6 +72,7 @@ function action_export_members() {
                $worksheet->write($row, $col++, $member['url']);    
                $worksheet->write($row, $col++, $member['twitter']);
                $worksheet->write($row, $col++, $member['directdebit']);
+               $worksheet->write($row, $col++, $member['ddmandatesigdate']);
                $membership_info = fees_info_for_member($member['id'], time());
                $worksheet->write($row, $col++, $membership_info['is_member']);
                $col = 0;