Skip to content

Commit

Permalink
slightly updated readme and screenshot, also improved ajax code
Browse files Browse the repository at this point in the history
  • Loading branch information
ole committed Oct 27, 2017
1 parent 136d5b6 commit 15ab8e9
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 43 deletions.
Binary file modified assets/screenshot-6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 7 additions & 4 deletions js/wc-invoice-pdf-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ function WCInvoicePdfAdminClass() {
* @param {String} action action
*/
var jsonRequest = function (data, action) {
if(!action) action = 'invoicepdf';
if(!action) {
alert('No hook action defined');
return;
}
$.extend(data, { action: action });
return jQuery.post(ajaxurl, data, null, 'json');
};
Expand All @@ -38,7 +41,7 @@ function WCInvoicePdfAdminClass() {
$(obj).hide();

var container = openDateInput(d, function (newDate) {
jsonRequest({ invoice_id: invoice_id, due_date: newDate }).done(function (resp) {
jsonRequest({ invoice_id: invoice_id, due_date: newDate }, 'Invoice').done(function (resp) {
$(obj).text(resp);
$(obj).show();
});
Expand All @@ -60,7 +63,7 @@ function WCInvoicePdfAdminClass() {
$(obj).hide();

var container = openDateInput(d, function (newDate) {
jsonRequest({ invoice_id: invoice_id, paid_date: newDate }).done(function (resp) {
jsonRequest({ invoice_id: invoice_id, paid_date: newDate }, 'Invoice').done(function (resp) {
$(obj).text(resp);
$(obj).show();
});
Expand All @@ -84,7 +87,7 @@ function WCInvoicePdfAdminClass() {

$(obj).after(loading);

jsonRequest({ order_id: order_id, period: value}).done(function(resp){
jsonRequest({ order_id: order_id, period: value}, 'InvoiceMetabox').done(function(resp){
if (resp !== '')
$('.ispconfig_scheduler_info').show();
else
Expand Down
11 changes: 11 additions & 0 deletions metabox/invoice-metabox.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ public function __construct(){
add_action('post_updated', [$this, 'invoice_submit']);
}

public static function DoAjax(){
if(!empty($_POST['order_id']) && isset($_POST['period'])) {
$period = esc_attr($_POST['period']);
do_action('wcinvoicepdf_order_period', intval($_POST['order_id']), $period);
$result = $period;
}

echo json_encode($result);
wp_die();
}

public function invoice_box(){
add_meta_box( 'ispconfig-invoice-box', 'Invoice', [$this, 'invoice_box_callback'], 'shop_order', 'side', 'high' );
}
Expand Down
12 changes: 5 additions & 7 deletions model/invoice-task.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,24 @@ public static function Run(){
$me->payment_recur_reminder();
}

public function __construct(){
add_action( 'wp_ajax_InvoiceTask', [$this, 'doAjax'] );
}
public static function DoAjax(){
$task = new self();

public function doAjax(){
$name = esc_attr($_POST['name']);

switch($name) {
case 'reminder':
$result = $this->payment_reminder();
$result = $task->payment_reminder();
break;
case 'recurring':
if(!empty(WCInvoicePdf::$OPTIONS['wc_recur_test'])) {
$result = $this->payment_recur();
$result = $task->payment_recur();
} else {
$result = -2;
}
break;
case 'recurring_reminder':
$result = $this->payment_recur_reminder();
$result = $task->payment_recur_reminder();
break;
}

Expand Down
16 changes: 16 additions & 0 deletions model/invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,22 @@ public static function GetStatus($s, $lang = false){
return rtrim($res, ' | ');
}

public static function DoAjax(){
$result = '';
if(!empty($_POST['invoice_id'])) {
$invoice = new self(intval($_POST['invoice_id']));
if(!empty($_POST['due_date']))
$invoice->due_date = $result = date('Y-m-d H:i:s', strtotime($_POST['due_date']));
if(!empty($_POST['paid_date']))
$invoice->paid_date = $result = date('Y-m-d H:i:s', strtotime($_POST['paid_date']));

$invoice->Save();
}

echo json_encode($result);
wp_die();
}

public static function install(){
global $wpdb;

Expand Down
16 changes: 8 additions & 8 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ It also allows to setup WC Orders to be recurring and submits the invoices to th

**Features**

* save an invoice pdf from any order being created by WooCommerce
* build quote pdf (from orders) to send provisional offers to customer
* schedule recurring invoices and directly submit to customers email
* send kindly reminders to customers and limit the number of retries
* display (pending) invoices in "my Account" of the customer
* customize the PDF template by adding text and pictures
* remind a delegate person about pending payments of all customers
* save invoice as pdf from any order created by WooCommerce
* preview quote as pdf to submit provisional offer to customers
* schedule recurring invoices directly send to customers email address
* send kindly reminders for over due invoices
* show payable invoices in customers "My Account"
* individual the PDF template in text and picture
* remind delegate person about pending payments from customers

== Installation ==

Expand Down Expand Up @@ -68,7 +68,7 @@ You should have received a copy of the GNU General Public License along with WP
= 1.0.5 =
* fixed issue #1
* place holders for customer messages - see WC-Invoice -> Settings -> Templates for more details
* use Invoice Task properly when doing ajax request
* cleanup code for ajax execution

= 1.0.4 =
* reenable the invoice list filter
Expand Down
30 changes: 6 additions & 24 deletions wc-invoice-pdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,18 @@ public static function init() {
self::load_options();

// enable changing the due date through ajax
add_action( 'wp_ajax_invoicepdf', ['\WCInvoicePdf\WCInvoicePdf', 'doAjax'] );
add_action( 'wp_ajax_Invoice', ['\WCInvoicePdf\Model\Invoice', 'DoAjax'] );
// enable ajax requests for invoice tasks (admin-only)
add_action( 'wp_ajax_InvoiceTask', ['WCInvoicePdf\Model\InvoiceTask', 'DoAjax'] );
// enable ajax request for the invoice metabox located in the edit order post
add_action( 'wp_ajax_InvoiceMetabox', ['WCInvoicePdf\Metabox\InvoiceMetabox', 'DoAjax'] );

// register the scheduler action being used by wp_schedule_event
add_action( 'invoice_reminder', ['\WCInvoicePdf\Model\InvoiceTask', 'Run'] );

// update the order period
add_action('wcinvoicepdf_order_period', ['\WCInvoicePdf\WCInvoicePdf', 'order_period'], 10, 2);

// initialize the invoice task planer to allow ajax calls
new Model\InvoiceTask();

// the rest after this is for NON-AJAX requests
if(defined('DOING_AJAX') && DOING_AJAX) return;

Expand Down Expand Up @@ -205,26 +207,6 @@ public static function loadJS(){
wp_enqueue_script( 'my_custom_script', WCINVOICEPDF_PLUGIN_URL . 'js/wc-invoice-pdf-admin.js?_' . time() );
}

public static function doAjax(){
$result = '';
if(!empty($_POST['invoice_id'])) {
$invoice = new Model\Invoice(intval($_POST['invoice_id']));
if(!empty($_POST['due_date']))
$invoice->due_date = $result = date('Y-m-d H:i:s', strtotime($_POST['due_date']));
if(!empty($_POST['paid_date']))
$invoice->paid_date = $result = date('Y-m-d H:i:s', strtotime($_POST['paid_date']));

$invoice->Save();
} else if(!empty($_POST['order_id']) && isset($_POST['period'])) {
$period = esc_attr($_POST['period']);
do_action('wcinvoicepdf_order_period', intval($_POST['order_id']), $period);
$result = $period;
}

echo json_encode($result);
wp_die();
}

public static function plugin_meta($links, $file){
$l = strlen($file);

Expand Down

0 comments on commit 15ab8e9

Please sign in to comment.