|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Invoice Subscription Details |
|
4
|
|
|
* |
|
5
|
|
|
* |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
|
9
|
|
|
exit; // Exit if accessed directly |
|
10
|
|
|
} |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* GetPaid_Meta_Box_Invoice_Subscription Class. |
|
14
|
|
|
*/ |
|
15
|
|
|
class GetPaid_Meta_Box_Invoice_Subscription { |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Output the metabox. |
|
19
|
|
|
* |
|
20
|
|
|
* @param WP_Post $post |
|
21
|
|
|
*/ |
|
22
|
|
|
public static function output( $post ) { |
|
23
|
|
|
|
|
24
|
|
|
//Fetch the invoice. |
|
25
|
|
|
$invoice = new WPInv_Invoice( $post ); |
|
26
|
|
|
|
|
27
|
|
|
// Ensure that it is recurring. |
|
28
|
|
|
if ( ! $invoice->is_recurring() ) { |
|
29
|
|
|
return; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
// Fetch the subscription. |
|
33
|
|
|
$subscription = wpinv_get_subscription( $invoice ); |
|
34
|
|
|
|
|
35
|
|
|
?> |
|
36
|
|
|
<?php if ( empty( $subscription ) ): ?> |
|
37
|
|
|
<p class="wpi-meta-row"> |
|
38
|
|
|
<?php |
|
39
|
|
|
echo |
|
40
|
|
|
wp_sprintf( |
|
41
|
|
|
__( 'A new subscription will be created when the customer checks out and pays the invoice. %sView all subscriptions%s', 'invoicing' ), |
|
42
|
|
|
'<a href="' . admin_url( 'admin.php?page=wpinv-subscriptions' ).'">', |
|
43
|
|
|
'</a>' |
|
44
|
|
|
); |
|
45
|
|
|
?> |
|
46
|
|
|
</p> |
|
47
|
|
|
<?php |
|
48
|
|
|
return; // If no subscription. |
|
49
|
|
|
endif; |
|
50
|
|
|
|
|
51
|
|
|
$frequency = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $subscription->period, $subscription->frequency ); |
|
|
|
|
|
|
52
|
|
|
$billing = wpinv_price(wpinv_format_amount( $subscription->recurring_amount ), wpinv_get_invoice_currency_code( $subscription->parent_payment_id ) ) . ' / ' . $frequency; |
|
53
|
|
|
$initial = wpinv_price(wpinv_format_amount( $subscription->initial_amount ), wpinv_get_invoice_currency_code( $subscription->parent_payment_id ) ); |
|
54
|
|
|
$exipired = strtotime( $subscription->expiration, current_time( 'timestamp' ) ) < current_time( 'timestamp' ); |
|
55
|
|
|
?> |
|
56
|
|
|
|
|
57
|
|
|
<p class="wpi-meta-row wpi-sub-label <?php echo 'status-' . esc_attr( $subscription->status ); ?>"> |
|
58
|
|
|
<?php echo $invoice->is_renewal() ? _e('Renewal Invoice', 'invoicing') : _e('Recurring Invoice', 'invoicing'); ?> |
|
|
|
|
|
|
59
|
|
|
</p> |
|
60
|
|
|
|
|
61
|
|
|
<?php if ( ! empty( $subscription->id ) ) : ?> |
|
62
|
|
|
<p class="wpi-meta-row wpi-sub-id"> |
|
63
|
|
|
<label><?php _e( 'Subscription ID:', 'invoicing' ); ?></label> |
|
64
|
|
|
<a href="<?php echo esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . $subscription->id ) ); ?>" title="<?php esc_attr_e( 'View or edit subscription', 'invoicing' ); ?>" target="_blank"><?php echo $subscription->id; ?></a> |
|
65
|
|
|
</p> |
|
66
|
|
|
<?php endif; ?> |
|
67
|
|
|
|
|
68
|
|
|
<p class="wpi-meta-row wpi-bill-cycle"> |
|
69
|
|
|
<label><?php _e( 'Billing Cycle:', 'invoicing'); ?> </label> |
|
70
|
|
|
<?php |
|
71
|
|
|
|
|
72
|
|
|
if ( $subscription->recurring_amount != $subscription->initial_amount ) { |
|
73
|
|
|
printf( |
|
74
|
|
|
_x( '%s then %s', 'Initial subscription amount then billing cycle and amount', 'invoicing' ), |
|
75
|
|
|
$initial, |
|
76
|
|
|
$billing |
|
77
|
|
|
); |
|
78
|
|
|
} else { |
|
79
|
|
|
echo $billing; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
?> |
|
83
|
|
|
</p> |
|
84
|
|
|
|
|
85
|
|
|
<p class="wpi-meta-row wpi-billed-times"> |
|
86
|
|
|
<label><?php _e( 'Times Billed:', 'invoicing' ); ?></label> |
|
87
|
|
|
<?php echo $subscription->get_times_billed() . ' / ' . ( ( $subscription->bill_times == 0 ) ? 'Until Cancelled' : $subscription->bill_times ); ?> |
|
88
|
|
|
</p> |
|
89
|
|
|
|
|
90
|
|
|
<p class="wpi-meta-row wpi-start-date"> |
|
91
|
|
|
<label><?php _e( 'Start Date:', 'invoicing' ); ?></label> |
|
92
|
|
|
<?php echo date_i18n( get_option( 'date_format' ), strtotime( $subscription->created, current_time( 'timestamp' ) ) ); ?> |
|
|
|
|
|
|
93
|
|
|
</p> |
|
94
|
|
|
|
|
95
|
|
|
<p class="wpi-meta-row wpi-end-date"> |
|
96
|
|
|
<label><?php echo $exipired ? __( 'Expired On:', 'invoicing' ) : __( 'Renews On:', 'invoicing' ); ?></label> |
|
97
|
|
|
<?php echo date_i18n( get_option( 'date_format' ), strtotime( $subscription->expiration, current_time( 'timestamp' ) ) ); ?> |
|
98
|
|
|
</p> |
|
99
|
|
|
|
|
100
|
|
|
<?php if ( $subscription->status ) { ?> |
|
101
|
|
|
<p class="wpi-meta-row wpi-sub-status"> |
|
102
|
|
|
<label><?php _e( 'Subscription Status:', 'invoicing'); ?> </label><?php echo $subscription->get_status_label(); ?> |
|
103
|
|
|
</p> |
|
104
|
|
|
<?php } ?> |
|
105
|
|
|
|
|
106
|
|
|
<?php if ( $invoice->is_renewal() ) { ?> |
|
107
|
|
|
<p class="wpi-meta-row wpi-invoice-parent"> |
|
108
|
|
|
<label><?php _e( 'Parent Invoice:', 'invoicing'); ?></label> |
|
109
|
|
|
<?php |
|
110
|
|
|
$parent = $invoice->get_parent_payment(); |
|
111
|
|
|
|
|
112
|
|
|
if ( $parent->get_id() ) { |
|
113
|
|
|
$parent_url = esc_url( get_edit_post_link( $parent->get_id() ) ); |
|
114
|
|
|
$parent_id = $parent->get_number(); |
|
115
|
|
|
echo "<a href='$parent_url'>$parent_id</a>"; |
|
116
|
|
|
} else { |
|
117
|
|
|
echo '<del>' . __( 'Deleted', 'invoicing' ) . '</del>'; |
|
118
|
|
|
} |
|
119
|
|
|
?> |
|
120
|
|
|
|
|
121
|
|
|
</p> |
|
122
|
|
|
<?php } ?> |
|
123
|
|
|
|
|
124
|
|
|
<?php |
|
125
|
|
|
|
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
} |
|
129
|
|
|
|