Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 74 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| Invoices_Endpoint | |
0.00% |
0 / 73 |
|
0.00% |
0 / 4 |
420 | |
0.00% |
0 / 1 |
| register_endpoint | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
6 | |||
| before_endpoint_actions | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
6 | |||
| single_invoice_html_output | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| list_invoices_html_output | |
0.00% |
0 / 55 |
|
0.00% |
0 / 1 |
240 | |||
| 1 | <?php // phpcs:ignore Squiz.Commenting.FileComment.Missing |
| 2 | namespace Automattic\JetpackCRM; |
| 3 | |
| 4 | defined( 'ZEROBSCRM_PATH' ) || exit( 0 ); |
| 5 | |
| 6 | /** |
| 7 | * Invoices endpoint |
| 8 | */ |
| 9 | class Invoices_Endpoint extends Client_Portal_Endpoint { |
| 10 | |
| 11 | public static function register_endpoint( $endpoints, $client_portal ) { |
| 12 | if ( zeroBSCRM_getSetting( 'feat_invs' ) > 0 ) { |
| 13 | $new_endpoint = new Invoices_Endpoint( $client_portal ); |
| 14 | |
| 15 | $new_endpoint->portal = $client_portal; |
| 16 | $new_endpoint->slug = $client_portal->get_endpoint( ZBS_TYPE_INVOICE ); |
| 17 | $new_endpoint->name = __( 'Invoices', 'zero-bs-crm' ); |
| 18 | $new_endpoint->hide_from_menu = false; |
| 19 | $new_endpoint->menu_order = 2; |
| 20 | $new_endpoint->icon = 'fa-file-text-o'; |
| 21 | $new_endpoint->add_rewrite_endpoint = true; |
| 22 | |
| 23 | $endpoints[] = $new_endpoint; |
| 24 | } |
| 25 | |
| 26 | return $endpoints; |
| 27 | } |
| 28 | |
| 29 | // Handle dual-mode endpoint properties invoices vs. single invoice |
| 30 | public function before_endpoint_actions() { |
| 31 | |
| 32 | // We should call invoices if no param is given, single invoice otherwise |
| 33 | if ( empty( $this->param_value ) ) { |
| 34 | $this->template_name = 'invoices.php'; |
| 35 | $this->should_check_user_permission = true; |
| 36 | } else { |
| 37 | global $zbs; |
| 38 | |
| 39 | $this->template_name = 'single-invoice.php'; |
| 40 | $this->should_check_user_permission = $zbs->settings->get( 'easyaccesslinks' ) === 0; |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Single Endpoint rendering function |
| 46 | */ |
| 47 | function single_invoice_html_output( $invoice_id = -1, $invoice_hash = '' ) { |
| 48 | echo zeroBSCRM_invoice_generatePortalInvoiceHTML( $invoice_id, $invoice_hash ); |
| 49 | } |
| 50 | |
| 51 | #} New functions here. Used as NAMED in WooSync. Please do not rename and not tell me as need to update WooSync if so |
| 52 | #} 1. The invoice list function |
| 53 | /** |
| 54 | * |
| 55 | * @param $link and $endpoint as they will differ between Portal and WooCommerce My Account |
| 56 | */ |
| 57 | function list_invoices_html_output( $link = '', $endpoint = '' ) { |
| 58 | global $wpdb; |
| 59 | |
| 60 | $uid = get_current_user_id(); |
| 61 | $uinfo = get_userdata( $uid ); |
| 62 | $cID = zeroBS_getCustomerIDWithEmail( $uinfo->user_email ); |
| 63 | $is_invoice_admin = $uinfo->has_cap( 'admin_zerobs_invoices' ); |
| 64 | |
| 65 | // if the current is a valid contact or a WP user with permissions to view invoices... |
| 66 | if ( $cID > 0 || $is_invoice_admin ) { |
| 67 | |
| 68 | // this allows the current admin to see all invoices even if they're a contact |
| 69 | if ( $is_invoice_admin ) { |
| 70 | $cID = -1; |
| 71 | $this->portal->render->portal_viewing_as_admin_banner( __( 'Admins will see all invoices below, but clients will only see invoices assigned to them.', 'zero-bs-crm' ) ); |
| 72 | } |
| 73 | |
| 74 | // get invoices |
| 75 | $customer_invoices = zeroBS_getInvoicesForCustomer( $cID, true, 100, 0, false ); |
| 76 | |
| 77 | // if there are more than zero invoices... |
| 78 | if ( count( $customer_invoices ) > 0 ) { |
| 79 | |
| 80 | global $zbs; |
| 81 | ?> |
| 82 | <?php |
| 83 | |
| 84 | // capture output buffer: this isn't ideal but since other extensions modify this table with existing hooks, it's the best we can do. |
| 85 | ob_start(); |
| 86 | foreach ( $customer_invoices as $cinv ) { |
| 87 | |
| 88 | // invstatus check |
| 89 | $inv_status = $cinv['status']; |
| 90 | |
| 91 | // id |
| 92 | $idStr = '#' . $cinv['id']; |
| 93 | if ( isset( $cinv['id_override'] ) && ! empty( $cinv['id_override'] ) ) { |
| 94 | $idStr = $cinv['id_override']; |
| 95 | } |
| 96 | |
| 97 | // skip drafts if not an admin with invoice access |
| 98 | if ( $inv_status === 'Draft' && ! $is_invoice_admin ) { |
| 99 | continue; |
| 100 | } |
| 101 | |
| 102 | if ( ! isset( $cinv['due_date'] ) || empty( $cinv['due_date'] ) || $cinv['due_date'] == -1 ) { |
| 103 | // no due date; |
| 104 | $due_date_str = __( 'No due date', 'zero-bs-crm' ); |
| 105 | } else { |
| 106 | $due_date_str = $cinv['due_date_date']; |
| 107 | } |
| 108 | |
| 109 | // view on portal (hashed?) |
| 110 | $invoiceURL = zeroBSCRM_portal_linkObj( $cinv['id'], ZBS_TYPE_INVOICE ); // zeroBS_portal_link('invoices',$invoiceID); |
| 111 | |
| 112 | $idLinkStart = ''; |
| 113 | $idLinkEnd = ''; |
| 114 | if ( ! empty( $invoiceURL ) ) { |
| 115 | $idLinkStart = '<a href="' . $invoiceURL . '">'; |
| 116 | $idLinkEnd = '</a>'; |
| 117 | } |
| 118 | |
| 119 | echo '<tr>'; |
| 120 | echo '<td data-title="' . esc_attr( $zbs->settings->get( 'reflabel' ) ) . '">' . $idLinkStart . esc_html( $idStr ) . ' ' . esc_html__( '(view)', 'zero-bs-crm' ) . $idLinkEnd . '</td>'; |
| 121 | echo '<td data-title="' . esc_attr__( 'Date', 'zero-bs-crm' ) . '">' . esc_html( $cinv['date_date'] ) . '</td>'; |
| 122 | echo '<td data-title="' . esc_attr__( 'Due date', 'zero-bs-crm' ) . '">' . esc_html( $due_date_str ) . '</td>'; |
| 123 | echo '<td data-title="' . esc_attr__( 'Total', 'zero-bs-crm' ) . '">' . esc_html( zeroBSCRM_formatCurrency( $cinv['total'] ) ) . '</td>'; |
| 124 | echo '<td data-title="' . esc_attr__( 'Status', 'zero-bs-crm' ) . '"><span class="status ' . esc_attr( $inv_status ) . '">' . esc_html( $cinv['status'] ) . '</span></td>'; |
| 125 | |
| 126 | do_action( 'zbs-extra-invoice-body-table', $cinv['id'] ); |
| 127 | |
| 128 | // echo '<td class="tools"><a href="account/invoices/274119/pdf" class="pdf_download" target="_blank"><i class="fa fa-file-pdf-o"></i></a></td>'; |
| 129 | echo '</tr>'; |
| 130 | } |
| 131 | $invoices_to_show = ob_get_contents(); |
| 132 | ob_end_clean(); |
| 133 | |
| 134 | if ( ! empty( $invoices_to_show ) ) { |
| 135 | // there are invoices to show to this user, so build table |
| 136 | echo '<table class="table zbs-invoice-list">'; |
| 137 | echo '<thead>'; |
| 138 | echo '<th>' . esc_html( $zbs->settings->get( 'reflabel' ) ) . '</th>'; |
| 139 | echo '<th>' . esc_html__( 'Date', 'zero-bs-crm' ) . '</th>'; |
| 140 | echo '<th>' . esc_html__( 'Due date', 'zero-bs-crm' ) . '</th>'; |
| 141 | echo '<th>' . esc_html__( 'Total', 'zero-bs-crm' ) . '</th>'; |
| 142 | echo '<th>' . esc_html__( 'Status', 'zero-bs-crm' ) . '</th>'; |
| 143 | do_action( 'zbs-extra-invoice-header-table' ); |
| 144 | echo '</thead>'; |
| 145 | echo $invoices_to_show; |
| 146 | echo '</table>'; |
| 147 | } else { |
| 148 | // no invoices to show...might have drafts but no admin perms |
| 149 | esc_html_e( 'You do not have any invoices yet.', 'zero-bs-crm' ); |
| 150 | } |
| 151 | } else { |
| 152 | // invoice object count for current user is 0 |
| 153 | esc_html_e( 'You do not have any invoices yet.', 'zero-bs-crm' ); |
| 154 | } |
| 155 | } else { |
| 156 | // not a valid contact or invoice admin user |
| 157 | esc_html_e( 'You do not have any invoices yet.', 'zero-bs-crm' ); |
| 158 | } |
| 159 | } |
| 160 | } |