|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Invoice\Features; |
| 4 | + |
| 5 | +trait Schema |
| 6 | +{ |
| 7 | + use Settings; |
| 8 | + |
| 9 | + public function schema($invoice_id, $public = false): array |
| 10 | + { |
| 11 | + $stored_invoice_series_number = get_field('invoice_series_number', $invoice_id); |
| 12 | + $stored_invoice_number = get_field('invoice_number', $invoice_id); |
| 13 | + $invoice_number = ''; |
| 14 | + if ($stored_invoice_series_number) { |
| 15 | + $invoice_number = "{$stored_invoice_number}-"; |
| 16 | + } |
| 17 | + $invoice_number .= $stored_invoice_number; |
| 18 | + $invoice_number = $stored_invoice_number === 99999 ? null : $invoice_number; |
| 19 | + $uuid = get_post_meta($invoice_id, 'uuid', true); |
| 20 | + $invoice_view_url = "/invoices/view/{$uuid}"; |
| 21 | + $invoice_edit_url = "/invoices/edit/{$uuid}"; |
| 22 | + |
| 23 | + $private_data = [ |
| 24 | + 'invoice_client' => get_field('invoice_client', $invoice_id, false), |
| 25 | + 'invoice_client_address' => get_field('invoice_client_address', $invoice_id, false), |
| 26 | + 'invoice_view_url' => $invoice_view_url, |
| 27 | + 'invoice_edit_url' => $invoice_edit_url, |
| 28 | + 'invoice_notes' => get_field('invoice_notes', $invoice_id), |
| 29 | + 'invoice_terms' => get_field('invoice_terms', $invoice_id), |
| 30 | + ]; |
| 31 | + |
| 32 | + $public_data = [ |
| 33 | + 'ID' => $invoice_id, |
| 34 | + 'UUID' => $uuid, |
| 35 | + 'invoice_series_number' => $stored_invoice_series_number, |
| 36 | + 'invoice_number' => $stored_invoice_number, |
| 37 | + 'generated_invoice_number' => $invoice_number, |
| 38 | + 'invoice_issue_date' => get_field( |
| 39 | + 'invoice_issue_date', |
| 40 | + $invoice_id, |
| 41 | + false, |
| 42 | + ), |
| 43 | + 'invoice_due_date' => get_field( |
| 44 | + 'invoice_due_date', |
| 45 | + $invoice_id, |
| 46 | + false, |
| 47 | + ), |
| 48 | + 'invoice_sender' => get_field('invoice_sender', $invoice_id, false), |
| 49 | + 'invoice_sender_address' => get_field('invoice_sender_address', $invoice_id, false), |
| 50 | + 'invoice_currency' => get_field('invoice_currency', $invoice_id, false), |
| 51 | + 'invoice_items' => get_field('invoice_items', $invoice_id), |
| 52 | + 'invoice_status' => get_post_status($invoice_id), |
| 53 | + 'invoice_tax_amount' => get_field('invoice_tax_amount', $invoice_id), |
| 54 | + 'invoice_taxes' => get_field('invoice_taxes', $invoice_id), |
| 55 | + 'invoice_discount_amount' => get_field('invoice_discount_amount', $invoice_id), |
| 56 | + 'invoice_discounts' => get_field('invoice_discounts', $invoice_id), |
| 57 | + 'invoice_subtotal' => get_field('invoice_subtotal', $invoice_id), |
| 58 | + 'invoice_tax_subtotal' => get_field('invoice_tax_subtotal', $invoice_id), |
| 59 | + 'invoice_taxes_total' => get_field('invoice_taxes_total', $invoice_id), |
| 60 | + 'invoice_discount_subtotal' => get_field('invoice_discount_subtotal', $invoice_id), |
| 61 | + 'invoice_discount_total' => get_field('invoice_discount_total', $invoice_id), |
| 62 | + 'invoice_total' => get_field('invoice_total', $invoice_id), |
| 63 | + 'invoice_logo' => $this->get_logo($invoice_id), |
| 64 | + ]; |
| 65 | + |
| 66 | + return $public ? $public_data : array_merge($public_data, $private_data); |
| 67 | + } |
| 68 | +} |
0 commit comments