add_action('admin_init', 'miox_handle_receipt_assignment'); function miox_handle_receipt_assignment() { if (isset($_POST['miox_save_manual_link'])) { $post_id = intval($_POST['receipt_idx']); $link = str_replace('http://', 'https://', esc_url_raw($_POST['manual_pdf_link'])); if (get_post_type($post_id) === 'miox_receipt_view') { update_post_meta($post_id, '_miox_receipt_manual_pdf_link', $link); wp_redirect(admin_url('admin.php?page=miox-all-receipts&updated=link')); exit; } } if (isset($_POST['miox_bulk_delete']) && isset($_POST['receipt_ids']) && check_admin_referer('miox_bulk_delete_action', 'miox_bulk_nonce')) { $to_delete = $_POST['receipt_ids']; foreach ($to_delete as $post_id) { $post_id = intval($post_id); if (get_post_type($post_id) === 'miox_receipt_view') { $media_id = get_post_meta($post_id, '_miox_receipt_media_id', true); if ($media_id) wp_delete_attachment($media_id, true); wp_delete_post($post_id, true); } } wp_redirect(admin_url('admin.php?page=miox-all-receipts&deleted=bulk')); exit; } if (isset($_GET['page']) && $_GET['page'] === 'miox-all-receipts' && isset($_GET['action']) && $_GET['action'] === 'delete' && isset($_GET['id'])) { $post_id = intval($_GET['id']); if (get_post_type($post_id) === 'miox_receipt_view') { $media_id = get_post_meta($post_id, '_miox_receipt_media_id', true); if ($media_id) wp_delete_attachment($media_id, true); wp_delete_post($post_id, true); wp_redirect(admin_url('admin.php?page=miox-all-receipts&deleted=1')); exit; } } if (isset($_POST['miox_save_receipt']) && check_admin_referer('miox_save_action', 'miox_nonce')) { $inv_no = sanitize_text_field($_POST['f_inv']); $client_name = sanitize_text_field($_POST['f_name_manual']); $raw_blob = $_POST['receipt_html_blob']; $attachment_id = 0; $manual_pdf = ''; if (!empty($_POST['f_manual_pdf_base64'])) { $base64_string = $_POST['f_manual_pdf_base64']; $ext = '.png'; if (strpos($base64_string, ',') !== false) { $parts = explode(',', $base64_string); $mime_part = $parts[0]; $base64_data = $parts[1]; if (strpos($mime_part, 'pdf') !== false) { $ext = '.pdf'; } elseif (strpos($mime_part, 'jpeg') !== false || strpos($mime_part, 'jpg') !== false) { $ext = '.jpg'; } } else { $base64_data = $base64_string; } $decoded_file = base64_decode($base64_data); $file_name = sanitize_title(strtolower($inv_no . '-' . $client_name)) . $ext; $upload = wp_upload_bits($file_name, null, $decoded_file); if (!$upload['error']) { $wp_filetype = wp_check_filetype($upload['file'], null); $attachment = array( 'post_mime_type' => $wp_filetype['type'], 'post_title' => preg_replace('/\.[^.]+$/', '', $file_name), 'post_content' => '', 'post_status' => 'inherit' ); $attachment_id = wp_insert_attachment($attachment, $upload['file']); require_once(ABSPATH . 'wp-admin/includes/image.php'); $attach_data = wp_generate_attachment_metadata($attachment_id, $upload['file']); wp_update_attachment_metadata($attachment_id, $attach_data); $manual_pdf = wp_get_attachment_url($attachment_id); } } else { $manual_pdf = esc_url_raw($_POST['f_manual_pdf_upload']); } $custom_title = sanitize_title(strtolower($inv_no . '-' . $client_name)); $edit_post_id = isset($_POST['miox_edit_index']) ? intval($_POST['miox_edit_index']) : 0; $pre_post_id = isset($_POST['miox_pre_post_id']) ? intval($_POST['miox_pre_post_id']) : 0; $post_id = 0; $is_corrected = 'no'; if ($pre_post_id > 0) { $post_id = $pre_post_id; wp_update_post(array('ID' => $post_id, 'post_title' => $custom_title, 'post_status' => 'publish')); } elseif ($edit_post_id > 0) { // Updating an existing receipt — automatically flag as corrected/revised! $post_id = $edit_post_id; $is_corrected = 'yes'; wp_update_post(array('ID' => $post_id, 'post_title' => $custom_title, 'post_status' => 'publish')); if ($attachment_id === 0) { $old_media = get_post_meta($post_id, '_miox_receipt_media_id', true); if ($old_media) $attachment_id = $old_media; $old_pdf = get_post_meta($post_id, '_miox_receipt_manual_pdf_link', true); if (empty($manual_pdf) && $old_pdf) $manual_pdf = $old_pdf; } } else { $found_post = get_page_by_path($custom_title, OBJECT, 'miox_receipt_view'); if ($found_post) { $post_id = $found_post->ID; $is_corrected = 'yes'; wp_update_post(array('ID' => $post_id, 'post_title' => $custom_title, 'post_status' => 'publish')); } else { $post_id = wp_insert_post(array( 'post_title' => $custom_title, 'post_status' => 'publish', 'post_type' => 'miox_receipt_view', 'post_name' => $custom_title )); } } // Save complete structured form data so editing pre-fills every single field $form_data = array( 'inv' => $inv_no, 'client_name' => $client_name, 'email' => sanitize_email($_POST['f_contact_email']), 'addr' => isset($_POST['f_addr']) ? sanitize_textarea_field($_POST['f_addr']) : '', 'contact' => isset($_POST['f_contact']) ? sanitize_text_field($_POST['f_contact']) : '', 'pay_type' => isset($_POST['f_pay_type']) ? sanitize_text_field($_POST['f_pay_type']) : 'FULL PAYMENT', 'discount' => isset($_POST['f_discount']) ? floatval($_POST['f_discount']) : 0, 'tax' => isset($_POST['f_tax']) ? floatval($_POST['f_tax']) : 0, 'amt_paid' => isset($_POST['f_amt_paid']) ? floatval($_POST['f_amt_paid']) : 0, 'notes' => isset($_POST['f_notes']) ? sanitize_textarea_field($_POST['f_notes']) : '', 'items' => array() ); for ($i = 1; $i <= 3; $i++) { $form_data['items'][$i] = array( 'prop' => isset($_POST['f_prop_' . $i]) ? sanitize_text_field($_POST['f_prop_' . $i]) : '', 'size' => isset($_POST['f_size_' . $i]) ? sanitize_text_field($_POST['f_size_' . $i]) : '', 'estate_name' => isset($_POST['f_estate_name_' . $i]) ? sanitize_text_field($_POST['f_estate_name_' . $i]) : '', 'location_addr' => isset($_POST['f_location_addr_' . $i]) ? sanitize_text_field($_POST['f_location_addr_' . $i]) : '', 'state' => isset($_POST['f_state_' . $i]) ? sanitize_text_field($_POST['f_state_' . $i]) : '', 'qty' => isset($_POST['f_qty_' . $i]) ? floatval($_POST['f_qty_' . $i]) : 0, 'amt' => isset($_POST['f_amt_' . $i]) ? floatval($_POST['f_amt_' . $i]) : 0, 'statuses' => isset($_POST['f_status_' . $i]) ? (is_array($_POST['f_status_' . $i]) ? array_map('sanitize_text_field', $_POST['f_status_' . $i]) : array(sanitize_text_field($_POST['f_status_' . $i]))) : array() ); } update_post_meta($post_id, '_miox_receipt_form_data', $form_data); update_post_meta($post_id, '_miox_receipt_inv', $inv_no); update_post_meta($post_id, '_miox_receipt_client_name', $client_name); update_post_meta($post_id, '_miox_receipt_amt', sanitize_text_field($_POST['f_amt_paid'])); update_post_meta($post_id, '_miox_receipt_date', date('Y-m-d')); update_post_meta($post_id, '_miox_receipt_prop', sanitize_text_field($_POST['f_prop_1'])); update_post_meta($post_id, '_miox_receipt_estate', sanitize_text_field($_POST['f_estate_name_1'])); update_post_meta($post_id, '_miox_receipt_email', sanitize_email($_POST['f_contact_email'])); update_post_meta($post_id, '_miox_html_blob', base64_encode($raw_blob)); update_post_meta($post_id, '_miox_receipt_media_id', $attachment_id); update_post_meta($post_id, '_miox_receipt_manual_pdf_link', $manual_pdf); update_post_meta($post_id, '_miox_receipt_manual_qr_blob', isset($_POST['f_manual_qr_blob']) ? sanitize_textarea_field($_POST['f_manual_qr_blob']) : ''); update_post_meta($post_id, '_miox_receipt_notes', isset($_POST['f_notes']) ? sanitize_textarea_field($_POST['f_notes']) : ''); // Save revision audit trail automatically update_post_meta($post_id, '_miox_receipt_is_corrected', $is_corrected); if ($is_corrected === 'yes') { update_post_meta($post_id, '_miox_receipt_corrected_date', current_time('mysql')); } wp_redirect(admin_url('post.php?post=' . $post_id . '&action=edit')); exit; } }
Warning: session_start(): Session cannot be started after headers have already been sent in /home/mioxincc/public_html/wp-content/plugins/property-asset-dashboard/modules/class-pad-auth.php on line 927

Warning: session_start(): Session cannot be started after headers have already been sent in /home/mioxincc/public_html/wp-content/plugins/property-asset-dashboard/modules/class-pad-auth.php on line 76
https://www.mioxinc.com/post-sitemap.xml 2026-04-13T06:19:24+00:00 https://www.mioxinc.com/page-sitemap.xml 2026-07-10T00:46:44+00:00 https://www.mioxinc.com/miox_receipt_view-sitemap.xml 2026-07-31T00:52:32+00:00 https://www.mioxinc.com/category-sitemap.xml 2026-04-13T06:19:24+00:00 https://www.mioxinc.com/author-sitemap.xml 2026-04-03T10:08:38+00:00