Example #1
0
    <?php 
if (show_business_info()) {
    ?>
      <?php 
    wp_invoice_show_business_information();
    ?>
    <?php 
}
?>

    <?php 
if (!is_quote()) {
    ?>
      <div class="wpi_checkout">
        <?php 
    if (allow_partial_payments()) {
        ?>
          <?php 
        show_partial_payments();
        ?>
        <?php 
    }
    ?>

        <?php 
    show_payment_selection();
    ?>

        <?php 
    $method = !empty($invoice['default_payment_method']) ? $invoice['default_payment_method'] : 'manual';
    if ($method == 'manual') {
    function show_itemized_table($args = '')
    {
        global $invoice, $wpi_settings;
        $defaults = array('return' => false, 'item_heading' => __("Item", WPI), 'cost_heading' => __("Cost", WPI), 'show_quantities' => false, 'quantity_heading' => __('Quantity', WPI));
        extract(wp_parse_args($args, $defaults), EXTR_SKIP);
        // If hide_quantity is not passed by function, we referr to global setting
        if (!$show_quantities) {
            $show_quantities = $wpi_settings['globals']['show_quantities'] == 'true' ? true : false;
        }
        $currency_symbol = !empty($wpi_settings['currency']['symbol'][$invoice['default_currency_code']]) ? $wpi_settings['currency']['symbol'][$invoice['default_currency_code']] : "\$";
        ob_start();
        if (allow_partial_payments()) {
            ?>
      <script type="text/javascript">
        /**
         * Partial payments JS
         */
        var minimum_payment = <?php 
            echo $invoice['deposit_amount'];
            ?>
;
        var balance         = <?php 
            echo $invoice['net'];
            ?>
;
        jQuery(document).ready(function(){
          var validate_amount = function(amount) {
            amount = Math.abs( parseFloat( amount ) );
            if ( amount < minimum_payment ) return minimum_payment;
            if ( amount > balance ) return balance;
            if ( isNaN( amount ) ) return balance;
            return amount;
          }
          var set_pay_button_value = function() {
            if(jQuery("#pay_button_value").length > 0){
              var pa = jQuery("#payment_amount").val();
              jQuery("#pay_button_value").html(pa);
            }
          }
          //** Find fields */
          var payment_amount        = jQuery("#payment_amount");
          var my_amount             = jQuery("#my_amount");
          //** Find radios */
          var custom_amount_option  = jQuery("#wpi_custom_amount_option");
          var minimum_amount_option = jQuery("#wpi_minimum_amount_option");
          var full_amount_option    = jQuery("#wpi_full_amount_option");
          var custom_amount_field = jQuery("#wpi_custom_amount_option_field_wrapper");
          my_amount.on("focus", function(){
            custom_amount_option.attr("checked", "checked");
          });
          custom_amount_option.click(function(){
            my_amount.focus();
            custom_amount_field.show();
          });
          minimum_amount_option.click(function(){
            payment_amount.val( validate_amount( minimum_amount_option.val() ) );
            custom_amount_field.hide();
            set_pay_button_value();
          });
          full_amount_option.click(function(){
            payment_amount.val( validate_amount( full_amount_option.val() ) );
            custom_amount_field.hide();
            set_pay_button_value();
          });
          //** Handle changing of payment method */
          jQuery("#online_payment_form_wrapper").on("formLoaded", function(){
            payment_amount = jQuery("#payment_amount");
            my_amount      = jQuery("#my_amount");
            //** update field data */
            if ( custom_amount_option.is(":checked") ) {
              payment_amount.val( validate_amount( my_amount.val() ) );
            }
            if ( minimum_amount_option.is(":checked") ) {
              payment_amount.val( validate_amount( minimum_amount_option.val() ) );
            }
            set_pay_button_value();
          });
          //** If there are required fields */
          if ( payment_amount.length && my_amount.length ) {
            //** update field data */
            my_amount.on("keyup", function(){
              var new_value = my_amount.val();
              payment_amount.val( validate_amount( new_value ) );
              set_pay_button_value();
            });
            my_amount.on("blur", function(){
              my_amount.val( payment_amount.val() );
              set_pay_button_value();
            });
            my_amount.on("focus", function(){
              my_amount.val( payment_amount.val() );
              set_pay_button_value();
            });
          } else {
            alert( "<?php 
            _e('Partial payment is not available because of an error.\\nContact Administirator for more information.', WPI);
            ?>
" );
          }
        });
      </script>
      <?php 
        }
        if ($wpi_settings['use_custom_templates'] != 'yes' || !file_exists(TEMPLATEPATH . '/wpi/table.php')) {
            ?>
      <table id="wp_invoice_itemized_table" class="table table-striped wp_invoice_itemized_table">
        <thead>
          <tr>
            <th class="title_column"><?php 
            echo $item_heading;
            ?>
</th>
      <?php 
            if ($show_quantities) {
                ?>
              <th class="quantity_column"><?php 
                echo $quantity_heading;
                ?>
</th>
      <?php 
            }
            ?>
            <th class="cost_column"><?php 
            echo $cost_heading;
            ?>
</th>
          </tr>
        </thead>
        <tbody>
      <?php 
            $i = 1;
            ?>
      <?php 
            if (isset($invoice['itemized_list']) && is_array($invoice['itemized_list'])) {
                ?>
        <?php 
                foreach ($invoice['itemized_list'] as $row) {
                    ?>
              <tr class="<?php 
                    echo ++$i % 2 ? 'alt_row' : '';
                    ?>
">
                <td class="title_column">
                  <div class="wpi_line_item_title"><?php 
                    echo stripslashes($row['name']);
                    ?>
</div>
                  <div class="description_text"><?php 
                    echo nl2br($row['description']);
                    ?>
</div>
                </td>
                <?php 
                    if ($show_quantities) {
                        ?>
                  <td class="quantity_column">
            <?php 
                        echo $row['quantity'];
                        ?>
                  </td>
              <?php 
                    }
                    ?>
                <td class="cost_column"><?php 
                    echo $currency_symbol . wp_invoice_currency_format($row['line_total_before_tax']);
                    ?>
</td>
              </tr>
        <?php 
                }
                ?>
            <?php 
            }
            ?>
            <?php 
            if (isset($invoice['itemized_charges']) && is_array($invoice['itemized_charges'])) {
                ?>
            <tr>
              <th class="title_column"><?php 
                _e('Charges', WPI);
                ?>
</th>
        <?php 
                if ($show_quantities) {
                    ?>
                <th class="quantity_column"></th>
            <?php 
                }
                ?>
              <th class="cost_column"><?php 
                echo $cost_heading;
                ?>
</th>
            </tr>
                <?php 
                $i = 1;
                ?>
                <?php 
                foreach ($invoice['itemized_charges'] as $row) {
                    ?>
              <tr class="<?php 
                    echo ++$i % 2 ? 'alt_row' : '';
                    ?>
">
                <td class="title_column">
          <?php 
                    echo stripslashes($row['name']);
                    ?>
 <br>
                </td>
                <?php 
                    if ($show_quantities) {
                        ?>
                  <td class="quantity_column">
                  </td>
          <?php 
                    }
                    ?>
                <td class="cost_column">
              <?php 
                    echo $currency_symbol . wp_invoice_currency_format($row['amount']);
                    ?>
                </td>
              </tr>
            <?php 
                }
                ?>
          <?php 
            }
            ?>
        </tbody>
        <tfoot>
          <?php 
            //** Figure out what colspan is based on how many columns we have */
            $colspan = $show_quantities ? 'colspan="2"' : '';
            if (!empty($invoice['subtotal'])) {
                ?>
            <tr class="wpi_subtotal">
              <td class="bottom_line_title" <?php 
                echo $colspan;
                ?>
>
                <?php 
                _e('Subtotal:', WPI);
                ?>
              </td>
              <td class="wpi_money">
            <?php 
                echo $currency_symbol . wp_invoice_currency_format($invoice['subtotal']);
                ?>
</td>
            </tr>
      <?php 
            }
            ?>
      <?php 
            if (!empty($invoice['total_tax'])) {
                ?>
            <tr class="wpi_subtotal">
              <td class="bottom_line_title" <?php 
                echo $colspan;
                ?>
><?php 
                _e('Tax:', WPI);
                ?>
</td>
              <td class="wpi_money"><?php 
                echo $currency_symbol . wp_invoice_currency_format($invoice['total_tax']);
                ?>
</td>
            </tr>
      <?php 
            }
            ?>
      <?php 
            if (!empty($invoice['total_discount'])) {
                ?>
            <tr class="wpi_subtotal">
              <td class="bottom_line_title" <?php 
                echo $colspan;
                ?>
><?php 
                _e('Discounts:', WPI);
                ?>
</td>
              <td class="wpi_money"><?php 
                echo $currency_symbol . wp_invoice_currency_format($invoice['total_discount']);
                ?>
</td>
            </tr>
            <?php 
                if (!empty($invoice['discount'][1]['name'])) {
                    ?>
              <tr>
                <td colspan="2"><?php 
                    echo $invoice['discount'][1]['name'];
                    ?>
</td>
              </tr>
            <?php 
                }
                ?>
      <?php 
            }
            ?>
      <?php 
            if ($invoice['post_status'] != 'paid' && !empty($invoice['adjustments'])) {
                ?>
            <tr class="wpi_subtotal">
              <td class="bottom_line_title" <?php 
                echo $colspan;
                ?>
><?php 
                _e('Adjustments:', WPI);
                ?>
</td>
              <td class="wpi_money"><?php 
                echo $currency_symbol . wp_invoice_currency_format($invoice['adjustments']);
                ?>
</td>
            </tr>
      <?php 
            }
            ?>
      <?php 
            if ($invoice['post_status'] == 'paid' && !empty($invoice['total_payments'])) {
                ?>
            <tr class="wpi_subtotal">
              <td class="bottom_line_title" <?php 
                echo $colspan;
                ?>
><?php 
                _e('Received Payment:', WPI);
                ?>
</td>
              <td class="wpi_money"><?php 
                echo $currency_symbol . wp_invoice_currency_format($invoice['total_payments']);
                ?>
</td>
            </tr>
      <?php 
            }
            ?>
      <?php 
            if (!empty($invoice['net'])) {
                ?>
            <tr class="wpi_subtotal">
              <td class="bottom_line_title" <?php 
                echo $colspan;
                ?>
><?php 
                _e('Balance:', WPI);
                ?>
</td>
              <td class="wpi_money"><?php 
                echo $currency_symbol . wp_invoice_currency_format($invoice['net']);
                ?>
</td>
            </tr>
      <?php 
            }
            ?>
        </tfoot>
      </table>
    <?php 
        } else {
            require_once TEMPLATEPATH . '/wpi/table.php';
        }
        ?>
    <?php 
        $result = ob_get_contents();
        ob_end_clean();
        if ($return) {
            return $result;
        }
        echo $result;
    }