Пример #1
0
function web_invoice_draw_itemized_table($invoice_id)
{
    global $wpdb;
    $_invoice = new Web_Invoice_GetInfo($invoice_id);
    $invoice_info = $_invoice->_row_cache;
    $itemized = $invoice_info->itemized;
    $amount = $invoice_info->amount;
    $_tax_percents = unserialize(web_invoice_meta($invoice_id, 'tax_value'));
    $_tax_names = unserialize(get_option('web_invoice_tax_name'));
    if (is_array($_tax_percents)) {
        $tax_percent = 0;
        foreach ($_tax_percents as $_x => $_tax_percentx) {
            $tax_percent += $_tax_percentx;
            if (!isset($_tax_names[$_x])) {
                $_tax_names[$_x] = sprintf(__("Tax %s", WEB_INVOICE_TRANS_DOMAIN), $_x + 1);
            }
        }
    } else {
        $tax_percent = $_tax_percents;
    }
    // Determine currency. First we check invoice-specific, then default code, and then we settle on USD
    $currency_code = web_invoice_determine_currency($invoice_id);
    if ($tax_percent) {
        $tax_free_amount = $amount * (100 / (100 + 100 * ($tax_percent / 100)));
        $tax_value = $amount - $tax_free_amount;
    }
    if (!strpos($amount, '.')) {
        $amount = $amount . ".00";
    }
    $itemized_array = unserialize(urldecode($itemized));
    $response = "";
    if (is_array($itemized_array)) {
        $response .= "<p><table id=\"web_invoice_itemized_table\">\r\n\t\t<tr>\n";
        if (get_option('web_invoice_show_quantities') == "Show") {
            $response .= '<th style="width: 40px; text-align: right;">' . __('Quantity', WEB_INVOICE_TRANS_DOMAIN) . '</th><th style="width: 50px; text-align: right;">' . __('Unit price', WEB_INVOICE_TRANS_DOMAIN) . '</th>';
        }
        $response .= "<th>" . __('Item', WEB_INVOICE_TRANS_DOMAIN) . "</th><th style=\"width: 70px; text-align: right;\">" . __('Cost', WEB_INVOICE_TRANS_DOMAIN) . "</th>\r\n\t\t</tr> ";
        $i = 1;
        foreach ($itemized_array as $itemized_item) {
            //Show Quantites or not
            if (get_option('web_invoice_show_quantities') == '') {
                $show_quantity = false;
            }
            if (get_option('web_invoice_show_quantities') == 'Hide') {
                $show_quantity = false;
            }
            if (get_option('web_invoice_show_quantities') == 'Show') {
                $show_quantity = true;
            }
            if (!empty($itemized_item['name'])) {
                if (!strpos($itemized_item['price'], '.')) {
                    $itemized_item['price'] = $itemized_item['price'] . ".00";
                }
                if ($i % 2) {
                    $response .= "<tr class='alt_row'>";
                } else {
                    $response .= "<tr >";
                }
                //Quantities
                if ($show_quantity) {
                    $response .= "<td style=\"width: 70px; text-align: right;\">" . $itemized_item['quantity'] . "</td>";
                    $response .= "<td style=\"width: 50px; text-align: right;\">" . web_invoice_currency_format($itemized_item['price'], $currency_code) . "</td>";
                }
                //Item Name
                $response .= "<td>" . stripslashes($itemized_item['name']) . " <br /><span class='description_text'>" . stripslashes($itemized_item['description']) . "</span></td>";
                //Item Price
                $response .= "<td style=\"width: 70px; text-align: right;\">" . sprintf(web_invoice_currency_symbol_format($currency_code), web_invoice_currency_format($itemized_item['quantity'] * $itemized_item['price'], $currency_code)) . "</td>";
                $response .= "</tr>";
                $i++;
            }
        }
        if ($tax_percent) {
            if (is_array($_tax_percents)) {
                foreach ($_tax_percents as $_x => $_tax_percentx) {
                    if ($i % 2) {
                        $response .= "<tr class='alt_row'>";
                    } else {
                        $response .= "<tr >";
                    }
                    if (get_option('web_invoice_show_quantities') == "Show") {
                        $response .= "<td></td><td></td>";
                    }
                    $_tax_value = $tax_free_amount * ($_tax_percentx / 100);
                    $response .= "<td>" . $_tax_names[$_x] . " (" . round($_tax_percentx, 2) . "%) </td>";
                    if (get_option('web_invoice_show_quantities') == "Show") {
                        $response .= "<td style='text-align:right;'>" . sprintf(web_invoice_currency_symbol_format($currency_code), web_invoice_currency_format($_tax_value, $currency_code)) . "</td></tr>";
                    } else {
                        $response .= "<td style='text-align:right;'>" . sprintf(web_invoice_currency_symbol_format($currency_code), web_invoice_currency_format($_tax_value, $currency_code)) . "</td></tr>";
                    }
                    $i++;
                }
            } else {
                if ($i % 2) {
                    $response .= "<tr class='alt_row'>";
                } else {
                    $response .= "<tr >";
                }
                if (get_option('web_invoice_show_quantities') == "Show") {
                    $response .= "<td></td><td></td>";
                }
                $response .= "<td>" . __('Tax', WEB_INVOICE_TRANS_DOMAIN) . " (" . round($tax_percent, 2) . "%) </td>";
                if (get_option('web_invoice_show_quantities') == "Show") {
                    $response .= "<td style='text-align:right;'>" . sprintf(web_invoice_currency_symbol_format($currency_code), web_invoice_currency_format($tax_value, $currency_code)) . "</td></tr>";
                } else {
                    $response .= "<td style='text-align:right;'>" . sprintf(web_invoice_currency_symbol_format($currency_code), web_invoice_currency_format($tax_value, $currency_code)) . "</td></tr>";
                }
                $i++;
            }
        }
        if ($i % 2) {
            $response .= "<tr class=\"web_invoice_bottom_line alt_row\">";
        } else {
            $response .= "<tr  class='web_invoice_bottom_line'>";
        }
        if (get_option('web_invoice_show_quantities') == "Show") {
            $response .= "\r\n\t\t\t<td align=\"right\" colspan=\"2\">" . __('Invoice Total', WEB_INVOICE_TRANS_DOMAIN) . ":</td>\r\n\t\t\t<td  colspan=\"2\" style=\"text-align: right;\" class=\"grand_total\">";
        } else {
            $response .= "\r\n\t\t\t<td align=\"right\">" . __('Invoice Total', WEB_INVOICE_TRANS_DOMAIN) . ":</td>\r\n\t\t\t<td style=\"text-align: right;\" class=\"grand_total\">";
        }
        $response .= sprintf(web_invoice_currency_symbol_format($currency_code), web_invoice_currency_format($amount, $currency_code));
        $response .= "</td></tr></table></p>";
        return $response;
    }
}
Пример #2
0
function web_invoice_display_payment($currency, $amount)
{
    return sprintf(web_invoice_currency_symbol_format($currency), web_invoice_currency_format($amount, $currency));
}