| 1 |
<?php |
| 2 |
|
| 3 |
namespace EasyInvoice\Helpers; |
| 4 |
|
| 5 |
/** |
| 6 |
* Helper class for managing quote-invoice relationships |
| 7 |
*/ |
| 8 |
class QuoteInvoiceHelper |
| 9 |
{ |
| 10 |
/** |
| 11 |
* Check if an invoice was converted from a quote |
| 12 |
* |
| 13 |
* @param int $invoice_id |
| 14 |
* @return bool |
| 15 |
*/ |
| 16 |
public static function isInvoiceConvertedFromQuote($invoice_id) |
| 17 |
{ |
| 18 |
// Check if this invoice was converted from a quote |
| 19 |
$quote_id = get_post_meta($invoice_id, '_converted_from_quote', true); |
| 20 |
return !empty($quote_id); |
| 21 |
} |
| 22 |
|
| 23 |
/** |
| 24 |
* Get quote information for an invoice |
| 25 |
* |
| 26 |
* @param int $invoice_id |
| 27 |
* @return array|false Quote information or false if not found |
| 28 |
*/ |
| 29 |
public static function getQuoteInfoFromInvoice($invoice_id) |
| 30 |
{ |
| 31 |
// Check if this invoice was converted from a quote |
| 32 |
$quote_id = get_post_meta($invoice_id, '_converted_from_quote', true); |
| 33 |
|
| 34 |
if (!$quote_id) { |
| 35 |
return false; |
| 36 |
} |
| 37 |
|
| 38 |
// Get quote post |
| 39 |
$quote_post = get_post($quote_id); |
| 40 |
if (!$quote_post || $quote_post->post_type !== 'easy_invoice_quote') { |
| 41 |
return false; |
| 42 |
} |
| 43 |
|
| 44 |
// Get quote number |
| 45 |
$quote_number = get_post_meta($quote_id, '_quote_number', true); |
| 46 |
|
| 47 |
// Get quote title |
| 48 |
$quote_title = $quote_post->post_title; |
| 49 |
|
| 50 |
// Determine icon and tooltip |
| 51 |
$icon_class = 'fas fa-exchange-alt'; |
| 52 |
$tooltip_text = sprintf(__('Converted from Quote %s', 'easy-invoice'), $quote_number ?: $quote_title); |
| 53 |
|
| 54 |
return [ |
| 55 |
'id' => $quote_id, |
| 56 |
'number' => $quote_number, |
| 57 |
'title' => $quote_title, |
| 58 |
'icon_class' => $icon_class, |
| 59 |
'tooltip_text' => $tooltip_text, |
| 60 |
'url' => admin_url('admin.php?page=easy-invoice-quote-builder&id=' . $quote_id) |
| 61 |
]; |
| 62 |
} |
| 63 |
} |
| 64 |
|