09cb9de7 by Chris Boden

Admin course registration bug fixes

1 parent 4b5ba596
...@@ -20,6 +20,7 @@ use Tz\WordPress\CBV\Events; ...@@ -20,6 +20,7 @@ use Tz\WordPress\CBV\Events;
20 use Tz\WordPress\CBV\CEHours; 20 use Tz\WordPress\CBV\CEHours;
21 use Tz\WordPress\CBV\Invoice; 21 use Tz\WordPress\CBV\Invoice;
22 use Tz\WordPress\CBV\Courses; 22 use Tz\WordPress\CBV\Courses;
23 use Tz\WordPress\CBV\CBVOptions;
23 use Exception, StdClass; 24 use Exception, StdClass;
24 25
25 const OPTION_NAME = "user_options"; 26 const OPTION_NAME = "user_options";
...@@ -400,11 +401,11 @@ class AccountValidation extends Common\Validation { ...@@ -400,11 +401,11 @@ class AccountValidation extends Common\Validation {
400 } 401 }
401 402
402 public function group($val) { 403 public function group($val) {
403 $this->on_groups = $val; 404 return;
404 $this->setGroups();
405 } 405 }
406 406
407 public function grpanch($val) { 407 public function grpanch($val) {
408 $this->on_groups = (isset($_POST['group']) ? $_POST['group'] : Array());
408 $this->all_groups = $val; 409 $this->all_groups = $val;
409 $this->setGroups(); 410 $this->setGroups();
410 } 411 }
...@@ -848,39 +849,105 @@ class Actions { ...@@ -848,39 +849,105 @@ class Actions {
848 849
849 } 850 }
850 851
851 public static function wp_ajax_course_registration() { // here 852 public static function wp_ajax_course_registration() {
853 // Get given working classes
852 $user = new User\Account($_POST['user_id']); 854 $user = new User\Account($_POST['user_id']);
853 $course = new Courses\Course($_POST['course_id']); 855 $course = new Courses\Course($_POST['course_id']);
854 $enrolltype = $_POST['enrolltype']; 856 $enrolltype = $_POST['enrolltype'];
855 $amount = $course->$enrolltype;
856
857 $user->registerForCourse($_POST['course_id'], (boolean)isset($_POST['exam']), $_POST['enrolltype']);
858 $user->approveToCourse($_POST['course_id']);
859 857
860 $items = array(); 858 // Apply user to course, sets group, set enrollment, etc.
861 859 $user->registerForCourse($course->getID(), (boolean)isset($_POST['exam']), $enrolltype);
862 $items[] = array( 860 $user->approveToCourse($course->getID());
863 'post_id' => $_POST['course_id'] 861
864 , 'cost' => $amount 862 // Do all the invoicey stuff
863 $items_subtotal = $items_taxes = $items_total = 0; // Running totals...should be a class
864 $tax_rate = $user->getLocTaxPct();
865 $calc_tax = function($cost, $tax_rate) {
866 return number_format(($cost * $tax_rate * 0.01), 2, '.', '');
867 };
868
869 $course_cost = $course->$enrolltype;
870 $course_taxes = $calc_tax($course_cost, $tax_rate);
871
872 // Add course cost to running totals
873 $items_subtotal += $course_cost;
874 $items_taxes += $course_taxes;
875 $items_total += ($course_cost + $course_taxes);
876
877 // Add the course its self to the receipt
878 $items = Array(Array(
879 'post_id' => $course->getID()
880 , 'cost' => $course_cost
865 , 'discount_label' => "" 881 , 'discount_label' => ""
866 , 'discount_amount' => 0 882 , 'discount_amount' => 0
867 , 'tax_label' => "" 883 , 'tax_label' => "Taxes"
868 , 'tax_rate' => "" 884 , 'tax_rate' => $tax_rate
869 , 'tax_amount' => "0.00" 885 , 'tax_amount' => $course_taxes
870 , 'subtotal' => $amount 886 , 'subtotal' => $course_cost
871 , 'total' => $amount 887 , 'total' => number_format(($course_cost + $course_taxes), 2, '.', '')
872 , 'description' => $course->post_title 888 , 'description' => $course->post_title
873 , 'extras' => array() 889 , 'extras' => array()
874 ); 890 ));
891
892 // If the user paid for the casebook add to invoice and Casebook group
893 if (isset($_POST['casebook']) && $_POST['casebook'] == 1) {
894 $book = UAM\getGroup('Casebook');
895 $book->addUser($user->ID);
896
897 $cost = substr($book->getDescription(), strpos($book->getDescription(), ':') + 1);
898 $taxes = $calc_tax($cost, CBV\get_tax_pct());
899
900 $items_subtotal += $cost;
901 $items_taxes += $taxes;
902 $items_total += $cost + $taxes;
903
904 $items[] = Array(
905 'post_id' => CBV\CASEBOOK_POSTID
906 , 'cost' => $cost
907 , 'discount_label' => ''
908 , 'discount_amount' => ''
909 , 'tax_label' => 'Taxes'
910 , 'tax_rate' => CBV\get_tax_pct()
911 , 'tax_amount' => $taxes
912 , 'subtotal' => $cost
913 , 'total' => ($cost + $taxes)
914 , 'description' => 'Casebook'
915 , 'extras' => Array()
916 );
917 }
918
919 // If the user is overseas and CBV charged them for it, add item to receipt
920 if (isset($_POST['overseas']) && $_POST['overseas'] == 1) {
921 $os_cost = number_format(CBVOptions\GetOption('overseas-surcharge', 'fees'), 2, '.', '');
922 $os_taxes = $calc_tax($os_cost, $tax_rate);
923
924 $items[] = Array(
925 'post_id' => 0
926 , 'cost' => $os_cost
927 , 'discount_label' => ''
928 , 'discount_amount' => ''
929 , 'tax_label' => 'Taxes'
930 , 'tax_rate' => $tax_rate
931 , 'tax_amount' => $os_taxes
932 , 'subtotal' => $os_cost
933 , 'total' => ($os_cost + $os_taxes)
934 , 'description' => 'Overseas Surcharge'
935 , 'extras' => Array()
936 );
937
938 $items_subtotal += $os_cost;
939 $items_taxes += $os_taxes;
940 $items_total += ($os_cost + $os_taxes);
941 }
875 942
876 $invoice_data = Array(); 943 $invoice_data = Array();
877 $invoice_data['items'] = $items; 944 $invoice_data['items'] = $items;
878 $invoice_data['payment'] = array( 945 $invoice_data['payment'] = Array(
879 'total_cost' => $amount 946 'total_cost' => $items_subtotal
880 , 'total_discounts' => "" 947 , 'total_discounts' => ""
881 , 'total_taxes' => "" 948 , 'total_taxes' => $items_taxes
882 , 'subtotal' => $amount 949 , 'subtotal' => $items_subtotal
883 , 'total' => $amount 950 , 'total' => $items_total
884 , 'bt_address' => "" 951 , 'bt_address' => ""
885 , 'bt_address2' => "" 952 , 'bt_address2' => ""
886 , 'bt_city' => "" 953 , 'bt_city' => ""
...@@ -892,7 +959,7 @@ class Actions { ...@@ -892,7 +959,7 @@ class Actions {
892 , 'bt_card_type' => $_POST['paid_by'] 959 , 'bt_card_type' => $_POST['paid_by']
893 ); 960 );
894 961
895 Invoice\create($invoice_data, 'course', 'Course Invoice', $user->ID, 'paid', 'publish', 0); 962 Invoice\create($invoice_data, 'course', 'Course Invoice', $user->ID, 'paid', 'publish', $items_total);
896 963
897 die(json_encode(Array('success' => 'true', 'refresh' => 'true'))); 964 die(json_encode(Array('success' => 'true', 'refresh' => 'true')));
898 } 965 }
...@@ -1586,6 +1653,4 @@ HTML; ...@@ -1586,6 +1653,4 @@ HTML;
1586 1653
1587 class Vars { 1654 class Vars {
1588 public static $validation; 1655 public static $validation;
1589 } 1656 }
1590
1591 ?>
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -19,7 +19,6 @@ use Exception, StdClass; ...@@ -19,7 +19,6 @@ use Exception, StdClass;
19 19
20 $fname = $user->first_name; 20 $fname = $user->first_name;
21 $lname = $user->last_name; 21 $lname = $user->last_name;
22 $member_id = $user->member_id;
23 22
24 if (empty($fname) || empty($lname)) { 23 if (empty($fname) || empty($lname)) {
25 $name = $user->user_login; 24 $name = $user->user_login;
...@@ -64,7 +63,7 @@ use Exception, StdClass; ...@@ -64,7 +63,7 @@ use Exception, StdClass;
64 <div id="" class="wrap"> 63 <div id="" class="wrap">
65 <div id="icon-users" class="icon32"><br /></div> 64 <div id="icon-users" class="icon32"><br /></div>
66 <h2>Editing: <?php echo $name; ?> 65 <h2>Editing: <?php echo $name; ?>
67 <?php if ($role=="member" && !empty($member_id)) { echo '<span class="admin-member-id"> ('.$member_id.')</span>'; }?> 66 <?php if (!empty($user->member_id)) { echo '<span class="admin-member-id"> (' . $user->member_id . ')</span>'; }?>
68 <?php if (in_array($suser->getRole(), Array('administrator', 'cbv_admin'))): ?> 67 <?php if (in_array($suser->getRole(), Array('administrator', 'cbv_admin'))): ?>
69 (<a href="<?php echo get_author_posts_url($user->ID); ?>?sulogin=1">Login</a>) 68 (<a href="<?php echo get_author_posts_url($user->ID); ?>?sulogin=1">Login</a>)
70 <?php endif; ?> 69 <?php endif; ?>
...@@ -74,7 +73,7 @@ use Exception, StdClass; ...@@ -74,7 +73,7 @@ use Exception, StdClass;
74 73
75 <div id="menu-management" style="margin-top:25px;"> 74 <div id="menu-management" style="margin-top:25px;">
76 <div class="nav-tabs-nav"> 75 <div class="nav-tabs-nav">
77 <div class="nav-tabs-wrapper" class="section-<?php echo $_GET['section'];?>"> 76 <div class="nav-tabs-wrapper" class="section-<?php echo @$_GET['section'];?>">
78 <div class="nav-tabs" style="padding: 0px; margin-left: 0px;"> 77 <div class="nav-tabs" style="padding: 0px; margin-left: 0px;">
79 <a id="overview" class="nav-tab hide-if-no-js <?php echo ($section=="overview") ? "nav-tab-active" : ""; ?>" href="/wp-admin/admin.php?page=cbv_users&action=edit&uid=<?php echo $_GET['uid']; ?>&section=overview">Overview</a> 78 <a id="overview" class="nav-tab hide-if-no-js <?php echo ($section=="overview") ? "nav-tab-active" : ""; ?>" href="/wp-admin/admin.php?page=cbv_users&action=edit&uid=<?php echo $_GET['uid']; ?>&section=overview">Overview</a>
80 <a id="profile" class="nav-tab hide-if-no-js <?php echo ($section=="profile") ? "nav-tab-active" : ""; ?>" href="/wp-admin/admin.php?page=cbv_users&action=edit&uid=<?php echo $_GET['uid']; ?>&section=profile">Profile</a> 79 <a id="profile" class="nav-tab hide-if-no-js <?php echo ($section=="profile") ? "nav-tab-active" : ""; ?>" href="/wp-admin/admin.php?page=cbv_users&action=edit&uid=<?php echo $_GET['uid']; ?>&section=profile">Profile</a>
......
...@@ -79,6 +79,31 @@ ...@@ -79,6 +79,31 @@
79 </div> 79 </div>
80 80
81 <div class="dashboard-section" style="margin-left:20px;margin-top:10px;"> 81 <div class="dashboard-section" style="margin-left:20px;margin-top:10px;">
82 <div class="dashboard-section-title">
83 <input type="checkbox" name="exam" id="exam" value="1" checked />
84 <label for="casebook">WRITING EXAM?</label>
85 </div>
86 </div>
87
88 <?php if (!$user->isMemberOf('Casebook')): ?>
89 <div class="dashboard-section" style="margin-left:20px;margin-top:10px;">
90 <div class="dashboard-section-title">
91 <input type="checkbox" name="casebook" id="casebook" value="1" checked />
92 <label for="casebook">PURCHASED CASEBOOK?</label>
93 </div>
94 </div>
95 <?php endif; ?>
96
97 <?php if ($user->isOverseas()): ?>
98 <div class="dashboard-section" style="margin-left:20px;margin-top:10px;">
99 <div class="dashboard-section-title">
100 <input type="checkbox" name="overseas" id="overseas" value="1" checked />
101 <label for="casebook">PAID OVERSEAS SURCHARGE?</label>
102 </div>
103 </div>
104 <?php endif; ?>
105
106 <div class="dashboard-section" style="margin-left:20px;margin-top:10px;">
82 <div class="dashboard-section-title"></div> 107 <div class="dashboard-section-title"></div>
83 <div class="dashboard-section-links"></div> 108 <div class="dashboard-section-links"></div>
84 <div class="dashboard-section-content small"> 109 <div class="dashboard-section-content small">
......