Skip to content

Commit

Permalink
Merge pull request #38 from ole1986/feature/reset-paid-status
Browse files Browse the repository at this point in the history
Allow reset orders paid status and provide due_date setting
  • Loading branch information
ole1986 committed Feb 24, 2023
2 parents b65e607 + aac71dc commit b9dd4e4
Show file tree
Hide file tree
Showing 11 changed files with 90 additions and 42 deletions.
3 changes: 1 addition & 2 deletions composer.json
@@ -1,6 +1,5 @@
{
"name": "ole1986/wc-invoice-pdf",
"type": "",
"description": "WC Recurring Invoice Pdf plugin for wordpress",
"homepage": "https://github.com/ole1986/wc-invoice-pdf",
"license": "MIT",
Expand All @@ -12,7 +11,7 @@
}
],
"require": {
"php": ">=5.4.0",
"php": "^7.4 || ^8.0 || ^8.1",
"rospdf/pdf-php": "0.12.*"
}
}
40 changes: 23 additions & 17 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 20 additions & 5 deletions js/wc-invoice-pdf-admin.js
Expand Up @@ -115,6 +115,21 @@ function WCInvoicePdfAdminClass() {
}).always(function () { loading.remove(); });
}

this.ResetOrderPaidStatus = function(obj) {
var order_id = parseInt($(obj).data('id'));
var loading = $('<img />');

loading.attr('src', '/wp-admin/images/loading.gif');

$(obj).after(loading);

jsonRequest({ order_id: order_id, resetpaid: true}, 'InvoiceMetabox').done(function(resp){
document.location.reload();
}).fail(function(){
alert('An error occured');
}).always(function () { loading.remove(); });
}

this.RunTask = function(obj, name){
var tmp = $(obj).text();
$(obj).text('Loading...');
Expand Down Expand Up @@ -143,7 +158,7 @@ function WCInvoicePdfAdminClass() {

self.ShowNotice("Task " + name + " successfully executed | Return code: " + resp, 'success');
}).always(function () { $(obj).text(tmp); });
};
}

this.OpenMedia = function(event, name){

Expand All @@ -168,7 +183,7 @@ function WCInvoicePdfAdminClass() {
$('#' + name + "-preview").attr('src', att.url);
$('#' + name).val(att.id);
});
};
}

this.ClearMedia = function(event, name) {
$('#' + name).val('');
Expand Down Expand Up @@ -207,15 +222,15 @@ function WCInvoicePdfAdminClass() {
container.append(btnSave);
container.append(btnCancel);
return container;
};
}

var hideTabs = function(){
$('#wcinvoicepdf-tabs a').each(function () {
var other_id = $(this).attr('href');
$(other_id).hide();
})
$('#wcinvoicepdf-tabs > a').removeClass('nav-tab-active');
};
}

var initTabs = function(){
$('#wcinvoicepdf-tabs > a').click(function(event){
Expand All @@ -231,7 +246,7 @@ function WCInvoicePdfAdminClass() {

hideTabs();
$('#wcinvoicepdf-tabs a:first').trigger('click');
};
}

$(function(){
initTabs();
Expand Down
Binary file modified lang/wc-invoice-pdf-de_DE.mo
Binary file not shown.
12 changes: 12 additions & 0 deletions lang/wc-invoice-pdf-de_DE.po
Expand Up @@ -36,6 +36,15 @@ msgstr "Der Aufgabenplaner ist für das automatisierte versenden von Rechnungen
msgid "Show all invoices"
msgstr "Alle Rechnungen anzeigen"

msgid "Reset order paid status"
msgstr "Zahlungsstatus der Bestellung zurücksetzen"

msgid "Due date in days"
msgstr "Fälligkeitsdatum in Tage"

msgid "The number of days an invoice becomes due"
msgstr "Die Anzahl der Tage nachdem eine Rechnung fällig wird"

msgid "Task Scheduler"
msgstr "Aufgabenplaner"

Expand Down Expand Up @@ -75,6 +84,9 @@ msgstr "Adresszeile"
msgid "Payment terms"
msgstr "Zahlungsbedingungen"

msgid "Offer terms"
msgstr "Angebotsbedingungen"

msgid "Protect rows from splitting"
msgstr "Zeilenaufteilung vermeiden"

Expand Down
4 changes: 4 additions & 0 deletions menu/invoice-menu.php
Expand Up @@ -201,6 +201,9 @@ public function DisplaySettings()
<?php
WCInvoicePdf::addField('wc_pdf_b2c', '<strong>' . __('Enable B2C', 'wc-invoice-pdf') . '</strong><br />' . __('Create invoice compatible for Business to Customer (B2C) relationship', 'wc-invoice-pdf'), 'checkbox');
?>
<?php
WCInvoicePdf::addField('wc_invoice_due_days', '<strong>' . __('Due date in days', 'wc-invoice-pdf') . '</strong><br />' . __('The number of days an invoice becomes due', 'wc-invoice-pdf'), 'number');
?>
<p>
<label style="width: 220px; display:inline-block;vertical-align:top;">
<strong><?php _e('Subscription option', 'wc-invoice-pdf') ?></strong><br />
Expand Down Expand Up @@ -242,6 +245,7 @@ public function DisplaySettings()
WCInvoicePdf::addField('wc_pdf_logo', 'Logo', 'media');
WCInvoicePdf::addField('wc_pdf_addressline', __('Address line', 'wc-invoice-pdf'));
WCInvoicePdf::addField('wc_pdf_condition', __('Payment terms', 'wc-invoice-pdf'), 'textarea');
WCInvoicePdf::addField('wc_pdf_condition_offer', __('Offer terms', 'wc-invoice-pdf'), 'textarea');
WCInvoicePdf::addField('wc_pdf_info', '<strong>Info Block</strong><br />' . 'Supports "Inline codes" provided by the <a href="https://github.com/rospdf/pdf-php/blob/master/README.md" target="_blank">R&amp;OS pdf class</a>', 'textarea', ['input_attr' => ['style' => 'width: 340px; height: 100px']]);
WCInvoicePdf::addField('wc_pdf_keeprows', '<strong>' . __('Protect rows from splitting', 'wc-invoice-pdf') . '</strong><br />' . __('Keep rows together when page breaks', 'wc-invoice-pdf'), 'checkbox');

Expand Down
12 changes: 9 additions & 3 deletions model/invoice-pdf.php
Expand Up @@ -238,10 +238,16 @@ public function BuildInvoice($invoice, $isOffer = false, $stream = false)

$pdf->ezSetDy(-20);

$pdf->ezTable($summaryData, null, '', ['width' => 200, 'gridlines' => 0, 'showHeadings' => 0,'shaded' => 0 ,'xPos' => 'right', 'xOrientation' => 'left', 'cols' => $colOptions ]);
$yOffset = $pdf->y;
if ($isOffer) {
$pdf->ezText("<strong>" . \WCInvoicePdf\WCInvoicePdf::$OPTIONS['wc_pdf_condition_offer'] . "</strong>", 8, ["aright" => 350]);
} else {
$pdf->ezText("<strong>" . sprintf(\WCInvoicePdf\WCInvoicePdf::$OPTIONS['wc_pdf_condition'], \WCInvoicePdf\WCInvoicePdf::$OPTIONS['wc_invoice_due_days']) . "</strong>", 8, ["aright" => 350]);
}

$pdf->ezSetDy(-20);
$pdf->ezText("<strong>" . \WCInvoicePdf\WCInvoicePdf::$OPTIONS['wc_pdf_condition'] . "</strong>", 8, ['justification' => 'center']);
$pdf->ezSetDy($yOffset - $pdf->y);

$pdf->ezTable($summaryData, null, '', ['width' => 200, 'gridlines' => 0, 'showHeadings' => 0,'shaded' => 0 ,'xPos' => 'right', 'xOrientation' => 'left', 'cols' => $colOptions ]);

if ($stream) {
$pdf->ezStream(['Content-Disposition' => ($isOffer ? $invoice->offer_number : $invoice->invoice_number) . '.pdf' ]);
Expand Down
6 changes: 5 additions & 1 deletion model/invoice.php
Expand Up @@ -2,6 +2,8 @@

namespace WCInvoicePdf\Model;

use WCInvoicePdf\WCInvoicePdf;

class Invoice
{
/**
Expand Down Expand Up @@ -203,6 +205,7 @@ public function Delete($hard = false)
public function makeNew($isOffer = false)
{
unset($this->ID);
unset($this->reminder_sent);

if (!empty($this->order) && is_object($this->order)) {
$Ym = $this->order->get_date_created()->date('Ym');
Expand Down Expand Up @@ -232,6 +235,7 @@ public function makeNew($isOffer = false)
public function makeRecurring()
{
unset($this->ID);
unset($this->reminder_sent);

if (!empty($this->order) && is_object($this->order)) {
// reset the payment status for recurring invoices (customer has to pay first)
Expand All @@ -251,7 +255,7 @@ public function makeRecurring()
}
$this->created = $d->format('Y-m-d H:i:s');
// due date
$d->add(new \DateInterval('P14D'));
$d->add(new \DateInterval('P' . WCInvoicePdf::$OPTIONS['wc_invoice_due_days'] . 'D'));
$this->due_date = $d->format('Y-m-d H:i:s');
$this->paid_date = null;
$this->status = 0;
Expand Down
12 changes: 7 additions & 5 deletions wc-invoice-pdf.php
Expand Up @@ -2,7 +2,7 @@
/*
* Plugin Name: WC Recurring Invoice PDF
* Description: WooCommerce invoice pdf plugin with recurring payments (scheduled)
* Version: 1.5.16
* Version: 1.5.18
* Author: ole1986 <ole.k@web.de>
* Author URI: https://github.com/ole1986/wc-invoice-pdf
* Plugin URI: https://github.com/ole1986/wc-invoice-pdf/releases
Expand Down Expand Up @@ -57,9 +57,11 @@ class WCInvoicePdf
'wc_mail_sender' => 'Invoice <invoice@domain.tld>',
'wc_mail_reminder' => 'yourmail@domain.tld',
'wc_pdf_title' => 'YourCompany - %s',
'wc_invoice_due_days' => 14,
'wc_pdf_logo' => '/plugins/wc-invoice-pdf/logo.png',
'wc_pdf_addressline' => 'Your address in a single line',
'wc_pdf_condition' => "Some conditional things related to invoices\nLine breaks supported",
'wc_pdf_condition' => "Payment within %s days after invoice date.",
'wc_pdf_condition_offer' => "This offer is valid for 2 weeks",
'wc_pdf_info' => 'Info block containing created date here: %s',
'wc_pdf_block1' => 'BLOCK #1',
'wc_pdf_block2' => 'BLOCK #2',
Expand Down Expand Up @@ -127,7 +129,7 @@ protected static function load_options()
{
$opt = get_option(self::OPTION_KEY);
if (!empty($opt)) {
self::$OPTIONS = $opt;
self::$OPTIONS = array_replace(self::$OPTIONS, $opt);
}
}

Expand Down Expand Up @@ -217,7 +219,7 @@ public static function addField($name, $title, $type = 'text', $args = [])
$optValue = $xargs['value'];
}

if ($type == 'text' || $type == 'password') {
if ($type == 'text' || $type == 'password' || $type == 'number') {
echo '<input type="'.$type.'" class="regular-text" name="'.$name.'" value="'.$optValue.'"'.$attrStr.' />';
} elseif ($type == 'email') {
echo '<input type="'.$type.'" class="regular-text" name="'.$name.'" value="'.$optValue.'"'.$attrStr.' />';
Expand All @@ -236,7 +238,7 @@ public static function addField($name, $title, $type = 'text', $args = [])
$url = wp_get_attachment_url($optValue);
}
echo "<div class='image-preview-wrapper' style='display:inline-block;'>";
echo "<img id='${name}-preview' src=\"$url\" style='max-height: 100px;'><br />";
echo "<img id='$name-preview' src=\"$url\" style='max-height: 100px;'><br />";
echo "<input onclick=\"WCInvoicePdfAdmin.OpenMedia(this,'$name')\" type=\"button\" class=\"button\" value=\"" . __('Select image', 'wc-invoice-pdf') ."\" />";
echo "<input onclick=\"WCInvoicePdfAdmin.ClearMedia(this,'$name')\" type=\"button\" class=\"button\" value=\"" . __('Clear image', 'wc-invoice-pdf') ."\" />";
echo "<input type='hidden' name=\"".$name."\" id='$name' value=\"$optValue\" />";
Expand Down
6 changes: 6 additions & 0 deletions wc/wc_order_invoice_metabox.php
Expand Up @@ -34,6 +34,9 @@ public static function DoAjax()
} else {
delete_post_meta($order_id, '_wc_pdf_b2c');
}
} elseif (isset($_POST['resetpaid'])) {
delete_post_meta($order_id, '_date_paid');
delete_post_meta($order_id, '_paid_date');
}

echo json_encode($result);
Expand Down Expand Up @@ -83,6 +86,9 @@ public function invoice_box_callback()
<p style="text-align: right">
<a href="/wp-admin/admin.php?page=wcinvoicepdf_invoices"><?php _e('Show all invoices', 'wc-invoice-pdf') ?></a>
</p>
<p style="text-align: right;">
<a href="#" data-id="<?php echo $post_id ?>" onclick="WCInvoicePdfAdmin.ResetOrderPaidStatus(this)"><?php _e('Reset order paid status', 'wc-invoice-pdf') ?></a>
</p>
<p style="text-align: right">
<a href="admin.php?page=wcinvoicepdf_invoice&order=<?php echo $post_id ?>" target="_blank" class="button"><?php printf(__('Preview', 'wc-invoice-pdf'), '') ?></a>
<a href="admin.php?page=wcinvoicepdf_invoice&order=<?php echo $post_id ?>&offer=1" target="_blank" class="button"><?php _e('Offer', 'wc-invoice-pdf') ?></a>
Expand Down
12 changes: 3 additions & 9 deletions wc/wc_product.php
Expand Up @@ -257,20 +257,14 @@ public static function OnCreateOrderItem($order_item, $item_key, $item)
*/
public static function OnPaymentCompleted($processing, $order_id, $order)
{
if (!in_array($processing, ['processing', 'completed'])) {
if ($processing == 'completed') {
return $processing;
}

if ($order->get_status() == 'pending') {
if (in_array($order->get_status(), ['on-hold', 'pending'])) {
return $processing;
}

$payment_method = $order->get_payment_method();

if ($payment_method == 'bacs' && $order->get_status() == 'on-hold') {
return $processing;
}


// there is nothing to do when no wp-ispconfig3 plugin is installed
if (!class_exists('Ispconfig')) {
return $processing;
Expand Down

0 comments on commit b9dd4e4

Please sign in to comment.