PHP Code:
class invoice {
var $code, $title, $description, $enabled;
// class constructor
function invoice() {
global $order;
$this->code = 'invoice';
// what the user sees
$this->title = MODULE_PAYMENT_INVOICE_TEXT_TITLE;
// what the admin sees
$this->description = MODULE_PAYMENT_INVOICE_TEXT_DESCRIPTION;
$this->sort_order = MODULE_PAYMENT_INVOICE_SORT_ORDER;
$this->enabled = ((MODULE_PAYMENT_INVOICE_STATUS == 'True') ? true : false);
$this->email_footer = MODULE_PAYMENT_PO_TEXT_EMAIL_FOOTER;
if ((int)MODULE_PAYMENT_INVOICE_ORDER_STATUS_ID > 0) {
$this->order_status = MODULE_PAYMENT_INVOICE_ORDER_STATUS_ID;
}
if (is_object($order)) $this->update_status();
}
// class methods
function update_status() {
global $order, $db;
$group_query = $db->Execute("select customers_group_pricing from " . TABLE_CUSTOMERS . " where customers_id = '" . $_SESSION['customer_id'] . "'");
if ($this->enabled == true) {
$check_flag_group = false;
$check = $db->Execute("select group_name from " . TABLE_GROUP_PRICING . " where group_id = '" . $group_query->fields['customers_group_pricing'] . "'");
if ($check->RecordCount() == 1) {
$invoice_prefix = "invoice";
$check_prefix = substr($check->fields['group_name'], 0, strlen($invoice_prefix));
if (strcasecmp($check_prefix, $invoice_prefix) == 0) {
$check_flag_group = true;
}
}
if (($check->RecordCount() == 1) and ($invoice_prefix = "all") )
{
$check_prefix = substr($check->fields['group_name'], 0, strlen($invoice_prefix));
if (strcasecmp($check_prefix, $invoice_prefix) == 0) {
$check_flag_group = true;
}
}
if ($check_flag_group == false) {
$this->enabled = false;
}
}
// disable the module if the order only contains virtual products
if ($this->enabled == true) {
if ($order->content_type != 'physical') {
$this->enabled = false;
}
}
}
function javascript_validation() {
$validation_string = 'if (payment_value == "' . $this->code . '") {' . "\n" .
' var account_name = document.checkout_payment.account_name.value;' . "\n" .
' var account_number = document.checkout_payment.account_number.value;' . "\n" .
' var po_number = document.checkout_payment.po_number.value;' . "\n" .
' if (account_name.length == 0) {' . "\n" .
' error_message = error_message + "' . MODULE_PAYMENT_PO_TEXT_JS_ACC_NAME . ' ";' . "\n" .
' error = 1;' . "\n" .
' }' . "\n" .
' if (account_number.length == 0) {' . "\n" .
' error_message = error_message + "' . MODULE_PAYMENT_PO_TEXT_JS_ACC_NUMBER . ' ";' . "\n" .
' error = 1;' . "\n" .
' }' . "\n" .
' if (po_number.length == 0) {' . "\n" .
' error_message = error_message + "' . MODULE_PAYMENT_PO_TEXT_JS_PO_NUMBER . '";' . "\n" .
' error = 1;' . "\n" .
' }' . "\n" .
'}' . "\n";
return $validation_string;
}
// function javascript_validation() {
// return false;
// }
//new selection info
function selection() {
$selection = array('id' => $this->code,
'module' => $this->title,
'fields' => array(array('title' => MODULE_PAYMENT_PO_TEXT_ACCOUNT_NAME,
'field' => zen_draw_input_field('account_name')),
array('title' => MODULE_PAYMENT_PO_TEXT_ACCOUNT_NUMBER,
'field' => zen_draw_input_field('account_number')),
array('title' => MODULE_PAYMENT_PO_TEXT_PO_NUMBER,
'field' => zen_draw_input_field('po_number'))));
return $selection;
}
function pre_confirmation_check() {
return false;
}
//new confirmation info
function confirmation() {
global $HTTP_POST_VARS;
$confirmation = array('title' => $this->title,
'fields' => array(array('title' => MODULE_PAYMENT_PO_TEXT_ACCOUNT_NAME,
'field' => $HTTP_POST_VARS['account_name']),
array('title' => MODULE_PAYMENT_PO_TEXT_ACCOUNT_NUMBER,
'field' => $HTTP_POST_VARS['account_number']),
array('title' => MODULE_PAYMENT_PO_TEXT_PO_NUMBER,
'field' => $HTTP_POST_VARS['po_number'])));
return $confirmation;
}
function process_button() {
global $HTTP_POST_VARS;
$process_button_string = zen_draw_hidden_field('account_name', $HTTP_POST_VARS['account_name']) .
zen_draw_hidden_field('account_number', $HTTP_POST_VARS['account_number']) .
zen_draw_hidden_field('po_number', $HTTP_POST_VARS['po_number']);
return $process_button_string;
}
function before_process() {
return false;
}
function after_process() {
return false;
}
function get_error() {
return false;
}
function check() {
global $db;
if (!isset($this->_check)) {
$check_query = $db->Execute("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_PAYMENT_INVOICE_STATUS'");
$this->_check = $check_query->RecordCount();
}
return $this->_check;
}
function install() {
global $db;
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable Invoice Module', 'MODULE_PAYMENT_INVOICE_STATUS', 'True', 'Do you want to accept payments on invoice?', '6', '1', 'zen_cfg_select_option(array(\'True\', \'False\'), ', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort order of display.', 'MODULE_PAYMENT_INVOICE_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', '6', '0', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, use_function, date_added) values ('Set Order Status', 'MODULE_PAYMENT_INVOICE_ORDER_STATUS_ID', '0', 'Set the status of orders made with this payment module to this value', '6', '0', 'zen_cfg_pull_down_order_statuses(', 'zen_get_order_status_name', now())");
}
function remove() {
global $db;
$db->Execute("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
}
function keys() {
return array('MODULE_PAYMENT_INVOICE_STATUS', 'MODULE_PAYMENT_INVOICE_ORDER_STATUS_ID', 'MODULE_PAYMENT_INVOICE_SORT_ORDER');
}
}
Bookmarks