From c996eeae9f74e791ff5f879974129a3101e20c3f Mon Sep 17 00:00:00 2001 From: patrick Date: Tue, 9 Jul 2019 00:19:01 +1000 Subject: [PATCH] job class created and data is being attached --- css/bts_timesheet.css | 4 +- html/job.html | 5 +- js/bts_timesheet.js | 113 +++++++++++++++++++++++++++- ts.php | 167 ++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 275 insertions(+), 14 deletions(-) diff --git a/css/bts_timesheet.css b/css/bts_timesheet.css index 25b6b3b..cdf88b4 100644 --- a/css/bts_timesheet.css +++ b/css/bts_timesheet.css @@ -648,7 +648,7 @@ div.sheettableheader { div.btos, div.bstart, div.bfinish, -div.bhours, +div.brate, div.bstaff, div.bclient, div.bconfirmed, @@ -661,7 +661,7 @@ div.btos { width: 20%; } -div.bhours{ +div.brate{ width: 20%; max-width: 20px; } diff --git a/html/job.html b/html/job.html index fd2dad5..d14eb06 100644 --- a/html/job.html +++ b/html/job.html @@ -1,6 +1,7 @@
+
-
[bts_hours_options]
+
[bts_rate_options]
[bts_select_staff]
[bts_select_client]
-
+
diff --git a/js/bts_timesheet.js b/js/bts_timesheet.js index ff8781c..464273a 100644 --- a/js/bts_timesheet.js +++ b/js/bts_timesheet.js @@ -217,7 +217,8 @@ _ajax_nonce: bts().nonce, // nonce action: "earnings_rate", // action }, function(response, status, xhr){ - console.log("%o", response); + bts().earnings_rate = response; + console.log("%o", bts().earnings_rate); }); } @@ -225,8 +226,10 @@ $(document).on('click', 'div.divTableHead.bdelete', function(){ for (var i=1; i<10; i++){ - var html = jQuery("#job_item").html(); - jQuery('div.workspace').append(html); +// var html = jQuery("#job_item").html(); +// var o = jQuery('div.workspace').append(html); + var o = new Job({i:i}); + o.debug(); } reset_date_time_picker(); }); @@ -237,7 +240,8 @@ } $(document).on('click', 'div.divTableCell.bdelete', function(){ - $(this).closest('div.divTable').remove(); + if (confirm('delete this job?')) + $(this).closest('div.divTable').remove(); }); $(document).on('mouseenter', 'div.divTableCell', function(){ @@ -247,7 +251,108 @@ $(this).closest('div.divTable').removeClass('highlight'); }); + $(document).on('click', 'span.ticon.ticon-save', function(){ + var table = $(this).closest('div.divTable') + console.log('clicked table data = %o', $(table).data()); + var r = get_record_from_ui(table); + do_save_record(r); + }); + function do_save_record(r){ + $.post(bts().ajax_url, { // POST request + _ajax_nonce: bts().nonce, // nonce + action: "save_job", // action + record: r, + }, function(response, status, xhr){ + console.log("response for save %o", response); + }); + } + + function get_record_from_ui(table){ + var record = {}; + record.id = get_job_id(table); + record.tos = get_tos(table); + record.start = get_start(table); + record.finish = get_finish(table); + record.rate = get_rate(table); + record.staff = get_staff(table); + record.client = get_client(table); + record.ack = get_ack(table); + return record; + } + + class Job{ + constructor(data){ + var html = jQuery("#job_item").html(); + this.el = $(html); + this.data = data; + this.el.data({obj:this, data:data}); + jQuery('div.workspace').append(this.el); + } + + debug(){ + console.log("data %o", this.el.data()); + } + + load_data(data) + { + $(selector).data(data);//save data to object + //update gui; + set_job_id(data.id); + } + + get_job_id(){ + return $(this.selector).find('input[name="id"]').attr('value'); + } + set_job_id(val){ + return $(this.selector).find('input[name="id"]').attr('value', val); + } + get_tos() + { + return $(this.selector).find('div.btos select').children("option:selected").val(); + } + set_tos(val) + { + return $(this.selector).find('div.btos select').children("option:selected").val(); + } + get_start(){ + + } + + } + + function get_job_id(table) + { + $(table).find('input[name="id"]').attr('value'); + } + function get_tos(table) + { + return $(table).find('div.btos select').children("option:selected").val(); + } + function get_start(table){ + return $(table).find('div.bstart input').attr('value'); + } + function get_finish(table) + { + return $(table).find('div.bfinish input').attr('value'); + } + function get_rate(table) + { + return $(table).find('div.brate select').children("option:selected").val(); + } + function get_staff(table) + { + return $(table).find('div.bstaff select').children("option:selected").val(); + } + function get_client(table) + { + return $(table).find('div.bclient select').children("option:selected").val(); + } + function get_ack(table) + { + return $(table).find('div.bconfirmed input:checked').length > 0; + } + /*________________________________________________________________________*/ }); })(jQuery); diff --git a/ts.php b/ts.php index 6b0fc44..eea487f 100644 --- a/ts.php +++ b/ts.php @@ -18,10 +18,14 @@ class AcareOffice{ private $nonce; //for ajax verification private $pages = array('time-sheets', 'user-list'); private $acaresydney_userid = 0; - - private $xero ; + private $xero ; + private $db; + private $table_name; public function __construct() { + add_option( "acare_ts_db_version", "1.0" ); + register_activation_hook( __FILE__, array($this, 'db_install') ); + add_action('init', array($this, 'class_loader')); add_action('wp', array($this, 'check_auth')); add_action('wp_enqueue_scripts', array($this, 'register_js_css'), 99); @@ -34,17 +38,24 @@ class AcareOffice{ add_shortcode( 'bts_staff_item', array($this, 'bts_staff_item')); add_shortcode( 'bts_client_item', array($this, 'bts_client_item')); add_shortcode( 'bts_job_item', array($this, 'bts_job_item')); - add_shortcode( 'bts_hours_options', array($this, 'bts_hours_options')); + add_shortcode( 'bts_rate_options', array($this, 'bts_rate_options')); add_shortcode( 'bts_select_staff', array($this, 'bts_select_staff')); add_shortcode( 'bts_select_client', array($this, 'bts_select_client')); add_action('wp_ajax_list_staff', array($this,'list_staff' )); add_action('wp_ajax_list_client', array($this,'list_client' )); + add_action('wp_ajax_save_job', array($this,'save_job' )); + add_action('wp_ajax_list_job', array($this,'list_job' )); + add_action('wp_ajax_delete_job', array($this,'delete_job' )); add_action('wp_ajax_earnings_rate', array($this,'get_payitem_earnings_rate' )); add_action('wp_ajax_nopriv_earnings_rate', array($this,'get_payitem_earnings_rate' )); + global $wpdb; + $this->db = $wpdb; + $this->table_name = $wpdb->prefix . 'acare_ts'; + } /** @@ -66,6 +77,51 @@ class AcareOffice{ $this->xero->init_wp(); } + //init database + public function db_install () { + global $wpdb; + $charset_collate = $wpdb->get_charset_collate(); + + //table name: broker transactions + $table_name = $this->table_name; + + $sql = "CREATE TABLE $table_name ( + id INT NOT NULL AUTO_INCREMENT, + tos VARCHAR(45) NULL, + start DATETIME NULL, + finish DATETIME NULL, + rate VARCHAR(45) NULL, + staff VARCHAR(45) NULL, + client VARCHAR(45) NULL, + ack TINYINT(4) NULL, + rating INT NULL DEFAULT 0, + PRIMARY KEY (id) + ) $charset_collate;"; + +// $sql = "CREATE TABLE $table_name ( +// id int(64) NOT NULL AUTO_INCREMENT, +// paid tinyint(4) DEFAULT NULL, +// referal varchar(45) COLLATE utf8mb4_unicode_520_ci DEFAULT NULL, +// clientid int(64) NOT NULL, +// loanamount float DEFAULT NULL, +// settledate date DEFAULT NULL, +// loanterm mediumint(10) DEFAULT NULL, +// commissionrate float DEFAULT NULL, +// commission float DEFAULT NULL, +// trailrate float DEFAULT NULL, +// trail float DEFAULT NULL, +// paydate date DEFAULT NULL, +// brokerid int(64) NOT NULL, +// status tinyint(4) NOT NULL, +// notes varchar(255) COLLATE utf8mb4_unicode_520_ci DEFAULT NULL, +// PRIMARY KEY (id) +// ) $charset_collate;"; + + //create database + require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); + dbDelta( $sql ); + } + // // @@ -140,7 +196,7 @@ class AcareOffice{ return $html; } - public function bts_hours_options($attr){ + public function bts_rate_options($attr){ $result = "