Skip to content

Commit

Permalink
Moved the WC_Product classes from wp-ispconfig3 into wc folder
Browse files Browse the repository at this point in the history
  • Loading branch information
ole committed Apr 9, 2019
1 parent f6f70ed commit 2285b72
Show file tree
Hide file tree
Showing 8 changed files with 475 additions and 20 deletions.
Binary file modified lang/wc-invoice-pdf-de_DE.mo
Binary file not shown.
29 changes: 29 additions & 0 deletions lang/wc-invoice-pdf-de_DE.po
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,33 @@ msgstr "jährlich"
msgid "monthly"
msgstr "monatlich"

msgid "month"
msgstr "Monat"

msgid "months"
msgstr "Monate"

msgid "per year"
msgstr "pro Jahr"

msgid "per month"
msgstr "pro Monat"

msgid "Hour"
msgstr "Stunde"

msgid "Hours"
msgstr "Stunden"

msgid "minute"
msgstr "Minute"

msgid "minutes"
msgstr "Minuten"

msgid "per"
msgstr "pro"

msgid "Invoice"
msgstr "Rechnung"

Expand Down Expand Up @@ -160,3 +181,11 @@ msgstr "Vorschau"
msgid "Settings saved"
msgstr "Einstellungen gespeichert"

msgid "To the minute calculation"
msgstr "Minuten-genaue Berechnung"

msgid "Working hours"
msgstr "Arbeitszeiten"

msgid "Webspace"
msgstr "Webspeicher"
8 changes: 4 additions & 4 deletions model/invoice-pdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ public function BuildInvoice($invoice, $isOffer = false, $stream = false){
$colOptions = [
'num' => ['width' => 32],
'desc' => [],
'qty' => ['justification' => 'right', 'width' => 64],
'price' => ['justification' => 'right', 'width' => 80],
'qty' => ['justification' => 'right', 'width' => 75],
'price' => ['justification' => 'right', 'width' => 70],
'total' => ['justification' => 'right', 'width' => 80],
];

Expand Down Expand Up @@ -130,13 +130,13 @@ public function BuildInvoice($invoice, $isOffer = false, $stream = false){
// overwrite the QTY to be 1 MONTH
$next->add(new \DateInterval('P12M'));
}
$qtyStr = number_format($v['qty'], 0, ',',' ') . ' Monat(e)';
$qtyStr = number_format($v['qty'], 0, ',',' ') . ' ' . $product->get_price_suffix('', $v['qty']);
//if(!$isOffer)
$product_name .= "\n<strong>Zeitraum: " . $current->format('d.m.Y')." - ".$next->format('d.m.Y') . '</strong>';
} else if($product instanceof \WC_Product_Hour) {
// check if product type is "hour" to output hours instead of Qty
$qtyStr = number_format($v['qty'], 1, ',',' ');
$qtyStr .= ' Std.';
$qtyStr.= ' ' . $product->get_price_suffix('', $v['qty']);
} else {
$qtyStr = number_format($v['qty'], 2, ',',' ');
}
Expand Down
24 changes: 13 additions & 11 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ It also allows to setup WC Orders to be recurring and submits the invoices to th

**Features**

* save invoice as pdf from any order created by WooCommerce
* export invoices into CSV (primary GnuCash, more may follow...)
* 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
* Save invoice as pdf from any order created by WooCommerce
* Export invoices into CSV (primary GnuCash, more may follow...)
* 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
* A "Webspace" product type for recurring payment support
* A "Working hours" product type to support service hours being invoiced to customers

[RELEASE NOTES]( https://github.com/ole1986/wc-invoice-pdf/releases)

Expand All @@ -40,7 +42,7 @@ For testing the recuring payments (submission of invoices) the "Test recuring" s

= DEVELOPMENT =

To set the *recurring state* of an order while receiving an action hook can be used to achieve this
To set the *recurring state* of an order while receiving a request, an action hook can be used to achieve this

Example:

Expand Down Expand Up @@ -68,5 +70,5 @@ You should have received a copy of the GNU General Public License along with WP

== Changelog ==

Please click on "Plugin Homepage" the for all release notes.
You will be refered to the github project page.
Please click on "Plugin Homepage" for release notes.
You will be redirected to the github project page.
11 changes: 6 additions & 5 deletions wc-invoice-pdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
/*
* Plugin Name: WC Recurring Invoice PDF
* Description: WooCommerce invoice pdf plugin with recurring payments (scheduled)
* Version: 1.1.0
* Version: 1.4.0
* Author: ole1986 <[email protected]>
* Author URI: https://github.com/ole1986/wc-invoice-pdf
* Plugin URI: https://github.com/ole1986/wc-invoice-pdf/releases
* Text Domain: wc-invoice-pdf
*
* WC requires at least: 3.0.0
* WC tested up to: 3.4.4
* WC tested up to: 3.5
*/

namespace WCInvoicePdf;
Expand Down Expand Up @@ -74,9 +74,10 @@ class WCInvoicePdf {
public static function init() {
self::load_textdomain_file();

if(file_exists(WCINVOICEPDF_PLUGIN_DIR . '../wp-ispconfig3/wc/ispconfig_wc_product.php')) {
include_once WCINVOICEPDF_PLUGIN_DIR . '../wp-ispconfig3/wc/ispconfig_wc_product.php';
include_once WCINVOICEPDF_PLUGIN_DIR . '../wp-ispconfig3/wc/ispconfig_wc_product_webspace.php';
if(file_exists(WCINVOICEPDF_PLUGIN_DIR . 'wc/wc_product.php')) {
include_once WCINVOICEPDF_PLUGIN_DIR . 'wc/wc_product.php';
include_once WCINVOICEPDF_PLUGIN_DIR . 'wc/wc_product_webspace.php';
include_once WCINVOICEPDF_PLUGIN_DIR . 'wc/wc_product_service.php';
}

self::load_options();
Expand Down
74 changes: 74 additions & 0 deletions wc/wc_product.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php
if (!class_exists('WC_Product')) {
return;
}

add_filter('woocommerce_product_data_tabs', ['WC_ISPConfigProduct','hotfix_product_data_tabs'], 5);

abstract class WC_ISPConfigProduct extends WC_Product
{
abstract public function OnCheckout($checkout);
abstract public function OnCheckoutValidate();
abstract public function OnCheckoutSubmit($order_id, $item_key, $item);

public static function add_to_cart()
{
wc_get_template('single-product/add-to-cart/simple.php');
}

public static function hotfix_product_data_tabs($product_data_tabs)
{
// HOTFIX: display the general pricing (even when switching back to simple products)
$generalClasses = &$product_data_tabs['general']['class'];
if (!in_array('show_if_simple', $generalClasses)) {
$generalClasses[] = 'show_if_simple';
}
if (!in_array('show_if_external', $generalClasses)) {
$generalClasses[] = 'show_if_external';
}

return $product_data_tabs;
}

public function is_purchasable()
{
return true;
}

public function get_sold_individually($context = 'view')
{
return true;
}

public function get_min_purchase_quantity() {
return 1;
}

public function get_price($context = 'view')
{
return $this->get_regular_price();
}

/**
* Get the add to url used mainly in loops.
*
* @return string
*/
public function add_to_cart_url()
{
$url = $this->is_purchasable() && $this->is_in_stock() ? remove_query_arg('added-to-cart', add_query_arg('add-to-cart', $this->id)) : get_permalink($this->id);
return $url;
}

/**
* Get the add to cart button text.
*
* @return string
*/
public function add_to_cart_text()
{
$text = $this->is_purchasable() && $this->is_in_stock() ? __('Add to cart', 'woocommerce') : __('Read more', 'woocommerce');

return apply_filters('woocommerce_product_add_to_cart_text', $text, $this);
}
}
117 changes: 117 additions & 0 deletions wc/wc_product_service.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<?php
add_filter('woocommerce_product_data_tabs', ['WC_Product_Hour','hour_product_data_tab']);

add_action('woocommerce_product_data_panels', ['WC_Product_Hour','product_data_fields']);
add_action('woocommerce_process_product_meta_hour', ['WC_Product_Hour', 'metadata_save']);

add_action('admin_footer', ['WC_Product_Hour', 'jsRegister']);
add_filter('product_type_selector', ['WC_Product_Hour','register']);

class WC_Product_Hour extends WC_Product
{
public static $current;

public function __construct($product)
{
$this->product_type = 'hour';
parent::__construct($product);
}

public static function register($types)
{
// Key should be exactly the same as in the class product_type parameter
$types[ 'hour' ] = __('Working hours', 'wc-invoice-pdf');
return $types;
}

public static function jsRegister()
{
global $product_object;
?>
<script type='text/javascript'>
jQuery( document ).ready( function() {
jQuery( '.options_group.pricing' ).addClass( 'show_if_hour' ).show();
<?php if ($product_object instanceof self) : ?>
jQuery('.general_options').show();
jQuery('.general_options > a').trigger('click');
<?php endif; ?>
});
</script>
<?php
}

/**
* Get the add to url used mainly in loops.
*
* @return string
*/
public function add_to_cart_url()
{
$url = $this->is_purchasable() && $this->is_in_stock() ? remove_query_arg('added-to-cart', add_query_arg('add-to-cart', $this->id)) : get_permalink($this->id);
return $url;
}

/**
* Get the add to cart button text.
*
* @return string
*/
public function add_to_cart_text()
{
$text = $this->is_purchasable() && $this->is_in_stock() ? __('Add to cart', 'woocommerce') : __('Read more', 'woocommerce');

return apply_filters('woocommerce_product_add_to_cart_text', $text, $this);
}

public static function hour_product_data_tab($product_data_tabs)
{
$product_data_tabs['general']['class'][] = 'show_if_hour';
$product_data_tabs['linked_product']['class'][] = 'hide_if_hour';
$product_data_tabs['attribute']['class'][] = 'hide_if_hour';
$product_data_tabs['advanced']['class'][] = 'hide_if_hour';
$product_data_tabs['shipping']['class'][] = 'hide_if_hour';

$product_data_tabs['hour_tab'] = array(
'label' => __('Working hours', 'wc-invoice-pdf'),
'target' => 'hour_data_tab',
'class' => 'show_if_hour'
);

return $product_data_tabs;
}


public static function product_data_fields()
{
echo '<div id="hour_data_tab" class="panel woocommerce_options_panel">';
woocommerce_wp_checkbox(['id' => '_hour_useminute', 'label' => __('minutes', 'wc-invoice-pdf'), 'description' => __("To the minute calculation", 'wc-invoice-pdf')]);
echo '</div>';
}

/**
* BACKEND: Used to save the template ID for later use (Cart/Order)
*/
public static function metadata_save($post_id)
{
update_post_meta($post_id, '_hour_useminute', $_POST['_hour_useminute']);
}

public function get_price_suffix($price = '', $qty = 1)
{
$plural = $qty > 1 ? 's' : '';
$suffix = __('Hour' . $plural, 'wc-invoice-pdf');

if($this->get_meta('_hour_useminute', true))
{
$suffix = __('minute' . $plural, 'wc-invoice-pdf');
}

return ' ' . $suffix;
}

public function get_price_html($price = '')
{
$price = wc_price(wc_get_price_to_display($this, array( 'price' => $this->get_regular_price() ))) . ' ' . __('per', 'wc-invoice-pdf') . $this->get_price_suffix('', 1);
return apply_filters('woocommerce_get_price_html', $price, $this);
}
}
Loading

0 comments on commit 2285b72

Please sign in to comment.