public static function render_invoice_html($seller_id, $bill, $items) { global $wpdb; $seller_id = intval($seller_id); $items = array_values((array) $items); // Get store details $store = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . NS365_SPI_Database::table('stores') . " WHERE seller_id=%d AND status='active' ORDER BY id ASC LIMIT 1", $seller_id)); $user = get_userdata($seller_id); $shop_name = ($store && !empty($store->store_name)) ? $store->store_name : ($user ? $user->display_name : 'Amar Money Transfer'); $shop_mobile = ($store && !empty($store->phone)) ? $store->phone : '7340714337'; $shop_email = ($store && !empty($store->email)) ? $store->email : ($user ? $user->user_email : ''); $shop_address = ($store && !empty($store->address)) ? $store->address : 'Main Som Bazar Road, near Riya Public School, Begam Vihar, Sector 33, Begum Pur, Delhi, 110086, India'; $shop_gstin = ($store && !empty($store->gstin)) ? $store->gstin : '07BEIPM1452Z0C1ZL'; $gst_settings = class_exists('NS365_SPI_GST') ? NS365_SPI_GST::settings() : array(); if (!$shop_gstin && !empty($gst_settings['shop_gstin'])) { $shop_gstin = $gst_settings['shop_gstin']; } // Extract customer address from notes $notes = (string) ($bill->notes ?? ''); $customer_address = ''; if (preg_match('/\[Customer Address\]\s*(.*?)(\n|$)/', $notes, $m)) { $customer_address = trim($m[1]); $notes = trim(str_replace($m[0], '', $notes)); } // Build product map for MRP and unit $product_ids = array(); foreach ($items as $tmp_item) { if (!empty($tmp_item->product_id)) { $product_ids[] = intval($tmp_item->product_id); } } $product_ids = array_values(array_unique(array_filter($product_ids))); $product_map = array(); if (!empty($product_ids)) { $placeholders = implode(',', array_fill(0, count($product_ids), '%d')); $sql = "SELECT id, mrp, unit, seller_barcode FROM " . NS365_SPI_Database::table('products') . " WHERE seller_id=%d AND id IN ($placeholders)"; $rows = $wpdb->get_results($wpdb->prepare($sql, array_merge(array($seller_id), $product_ids))); foreach ($rows as $r) { $product_map[intval($r->id)] = $r; } } // Prepare invoice data $bill_date = !empty($bill->created_at) ? date_i18n('d/m/Y', strtotime($bill->created_at)) : date_i18n('d/m/Y'); $bill_time = !empty($bill->created_at) ? date_i18n('h:i A', strtotime($bill->created_at)) : date_i18n('h:i A'); $bill_no = !empty($bill->bill_no) ? $bill->bill_no : ('BILL-' . intval($bill->id ?? 0)); $discount = (float)($bill->discount ?? 0); $taxable = max(0, (float)($bill->subtotal ?? 0) - $discount); $total_tax = (float)($bill->gst_amount ?? 0); $cgst = (float)($bill->cgst_amount ?? 0); $sgst = (float)($bill->sgst_amount ?? 0); $grand_total = (float)($bill->total_amount ?? 0); $paid = (float)($bill->received_amount ?? 0); $due = (float)($bill->due_amount ?? 0); $payment_mode = !empty($bill->payment_mode) ? ucfirst((string)$bill->payment_mode) : 'Cash'; $row_count = max(1, count($items)); $mrp_total = 0; ob_start(); ?>
AMAR MONEY TRANSFER
Fast • Safe • Reliable

Bill Date :  |  Bill Number :

Scan & Visit Our Shop

Bill From (Seller)

Amar Money Transfer

GSTIN:

Mobile Number:

Bill To (Customer)

Customer Name : Walk-in Customer

Mobile Number :

Home Address :

S.No Item Name Qty MRP (₹) Rate (₹) GST (%) CESS (₹) Net Rate (₹) Total (₹)

Amount In Words: