/** * Choose product step. * * @param tempcode The page title. * @return tempcode The result of execution. */ function choose($title) { breadcrumb_set_self(do_lang_tempcode('PURCHASING')); /*if (is_guest()) { $register=$GLOBALS['FORUM_DRIVER']->join_url(); if (is_object($register)) $register=$register->evaluate(); $_redirect=build_url(array('page'=>'_SELF','type'=>'misc'),'_SELF'); $redirect=$_redirect->evaluate(); $_login=build_url(array('page'=>'login','redirect'=>$redirect)); $login=$_login->evaluate(); return $this->wrap(do_template('PURCHASE_WIZARD_STAGE_GUEST',array('_GUID'=>'accf475a1457f73d7280b14d774acc6e','TITLE'=>$title,'TEXT'=>do_lang_tempcode('PURCHASE_NOT_LOGGED_IN_2',escape_html($register),escape_html($login)))),$title,NULL); }*/ $url = build_url(array('page' => '_SELF', 'type' => 'message', 'id' => get_param_integer('id', -1)), '_SELF', NULL, true, true); require_code('form_templates'); $list = new ocp_tempcode(); $filter = get_param('filter', ''); $products = find_all_products(); foreach ($products as $product => $details) { if ($filter != '') { if (!is_string($product) || substr($product, 0, strlen($filter)) != $filter) { continue; } } if (($details[0] == PRODUCT_PURCHASE_WIZARD || $details[0] == PRODUCT_SUBSCRIPTION || $details[0] == PRODUCT_CATALOGUE) && method_exists($details[count($details) - 1], 'is_available') && $details[count($details) - 1]->is_available($product, get_member())) { require_code('currency'); $currency = get_option('currency'); $price = currency_convert(floatval($details[1]), $currency, NULL, true); $description = $details[4]; if (strpos($details[4], strpos($details[4], '.') === false ? preg_replace('#\\.00($|[^\\d])#', '', $price) : $price) === false) { $description .= ' (' . $price . ')'; } $list->attach(form_input_list_entry($product, false, protect_from_escaping($description))); } } if ($list->is_empty()) { inform_exit(do_lang_tempcode('NO_CATEGORIES')); } $fields = form_input_list(do_lang_tempcode('PRODUCT'), '', 'product', $list, NULL, true); return $this->wrap(do_template('PURCHASE_WIZARD_STAGE_CHOOSE', array('_GUID' => '47c22d48313ff50e6323f05a78342eae', 'FIELDS' => $fields, 'TITLE' => $title)), $title, $url, true); }
/** * UI to add an invoice. * * @return tempcode The interface. */ function ad() { $title = get_page_title('CREATE_INVOICE'); breadcrumb_set_parents(array(array('_SEARCH:admin_ecommerce:ecom_usage', do_lang_tempcode('ECOMMERCE')), array('_SELF:_SELF:misc', do_lang_tempcode('INVOICES')))); require_code('form_templates'); $to = get_param('to', ''); $products = find_all_products(); $list = new ocp_tempcode(); foreach ($products as $product => $details) { if ($details[0] == PRODUCT_INVOICE) { $text = do_lang_tempcode('CUSTOM_PRODUCT_' . $product); if ($details[1] != '?') { $text->attach(escape_html(' (' . $details[1] . ' ' . get_option('currency') . ')')); } $list->attach(form_input_list_entry($product, false, $text)); } } if ($list->is_empty()) { inform_exit(do_lang_tempcode('NOTHING_TO_INVOICE_FOR')); } $fields = new ocp_tempcode(); $fields->attach(form_input_list(do_lang_tempcode('PRODUCT'), '', 'product', $list)); $fields->attach(form_input_username(do_lang_tempcode('USERNAME'), do_lang_tempcode('DESCRIPTION_INVOICE_FOR'), 'to', $to, true)); $fields->attach(form_input_float(do_lang_tempcode('AMOUNT'), do_lang_tempcode('INVOICE_AMOUNT_TEXT', escape_html(get_option('currency'))), 'amount', NULL, false)); $fields->attach(form_input_line(do_lang_tempcode('INVOICE_SPECIAL'), do_lang_tempcode('DESCRIPTION_INVOICE_SPECIAL'), 'special', '', false)); $fields->attach(form_input_text(do_lang_tempcode('INVOICE_NOTE'), do_lang_tempcode('DESCRIPTION_INVOICE_NOTE'), 'note', '', false)); $post_url = build_url(array('page' => '_SELF', 'type' => '_ad'), '_SELF'); $submit_name = do_lang_tempcode('CREATE_INVOICE'); return do_template('FORM_SCREEN', array('HIDDEN' => '', 'TITLE' => $title, 'URL' => $post_url, 'FIELDS' => $fields, 'SUBMIT_NAME' => $submit_name, 'TEXT' => do_lang_tempcode('DESCRIPTION_INVOICE_PAGE'))); }
/** * Get transaction summaries. * * @param TIME Start of time range * @param TIME End of time range * @param boolean Whether to count unpaid invoices into this. This means any invoicing in transactions will be ignored, and instead invoicing will be read directly. * @return array A template-ready list of maps of summary for multiple transaction types. */ function get_types($from, $to, $unpaid_invoices_count = false) { $types = array('OPENING' => array('TYPE' => do_lang_tempcode('OPENING_BALANCE'), 'AMOUNT' => 0, 'SPECIAL' => true), 'INTEREST_PLUS' => array('TYPE' => do_lang_tempcode('M_INTEREST_PLUS'), 'AMOUNT' => 0, 'SPECIAL' => false)); $products = find_all_products(); foreach ($products as $product => $details) { $types[$product] = array('TYPE' => $details[4], 'AMOUNT' => 0, 'SPECIAL' => false); } $types += array('COST' => array('TYPE' => do_lang_tempcode('EXPENSES'), 'AMOUNT' => 0, 'SPECIAL' => false), 'TRANS' => array('TYPE' => do_lang_tempcode('TRANSACTION_FEES'), 'AMOUNT' => 0, 'SPECIAL' => false), 'WAGE' => array('TYPE' => do_lang_tempcode('WAGES'), 'AMOUNT' => 0, 'SPECIAL' => false), 'INTEREST_MINUS' => array('TYPE' => do_lang_tempcode('M_INTEREST_MINUS'), 'AMOUNT' => 0, 'SPECIAL' => false), 'TAX' => array('TYPE' => do_lang_tempcode('TAX_GENERAL'), 'AMOUNT' => 0, 'SPECIAL' => false), 'CLOSING' => array('TYPE' => do_lang_tempcode('CLOSING_BALANCE'), 'AMOUNT' => 0, 'SPECIAL' => true), 'PROFIT' => array('TYPE' => do_lang_tempcode('NET_PROFIT'), 'AMOUNT' => 0, 'SPECIAL' => true)); require_code('currency'); $transactions = $GLOBALS['SITE_DB']->query('SELECT * FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'transactions WHERE t_time<' . strval((int) $to) . ' AND ' . db_string_equal_to('status', 'Completed') . ' ORDER BY t_time'); foreach ($transactions as $transaction) { if ($transaction['t_time'] > $from) { $types['TRANS']['AMOUNT'] += get_transaction_fee($transaction['amount'], $transaction['t_via']); } if ($unpaid_invoices_count) { foreach ($products as $product => $details) { if ($transaction['item'] == $product && $details[0] == PRODUCT_INVOICE) { continue 2; } } } $product = $transaction['item']; $transaction['amount'] = currency_convert($transaction['amount'], $transaction['t_currency'], get_option('currency')); $types['CLOSING']['AMOUNT'] += $transaction['amount']; if ($transaction['t_time'] < $from) { $types['OPENING']['AMOUNT'] += $transaction['amount'] - get_transaction_fee($transaction['amount'], $transaction['t_via']); continue; } if ($transaction['item'] == 'OTHER' && $transaction['amount'] < 0) { $types['COST']['AMOUNT'] += $transaction['amount']; } elseif ($transaction['item'] == 'TAX') { $types['TAX']['AMOUNT'] += $transaction['amount']; } elseif ($transaction['item'] == 'INTEREST') { $types[$product][$transaction['amount'] < 0 ? 'INTEREST_MINUS' : 'INTEREST_PLUS']['AMOUNT'] += $transaction['amount']; } elseif ($transaction['item'] == 'WAGE') { $types['WAGE']['AMOUNT'] += $transaction['amount']; } else { if (!array_key_exists($product, $types)) { $types[$product] = array('TYPE' => $product, 'AMOUNT' => 0, 'SPECIAL' => false); } // In case product no longer exists $types[$product]['AMOUNT'] += $transaction['amount']; } } if ($unpaid_invoices_count) { $invoices = $GLOBALS['SITE_DB']->query('SELECT * FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'invoices WHERE ' . db_string_equal_to('i_state', 'new') . ' AND i_time<' . strval((int) $to) . ' ORDER BY i_time'); foreach ($invoices as $invoice) { $product = $invoice['i_type_code']; $types['CLOSING']['AMOUNT'] += intval($invoice['i_amount']); if ($invoice['i_time'] < $from) { $types['OPENING']['AMOUNT'] += intval($invoice['i_amount']); continue; } $types[$product]['AMOUNT'] += intval($invoice['i_amount']); } } // $types['PROFIT_GROSS'] is not calculated $types['PROFIT']['AMOUNT'] = $types['CLOSING']['AMOUNT'] - $types['OPENING']['AMOUNT'] + $types['TAX']['AMOUNT']; // $types['PROFIT_NET_TAXED'] is not calculated foreach ($types as $item => $details) { $types[$item]['AMOUNT'] = float_to_raw_string($types[$item]['AMOUNT']); } foreach ($types as $i => $t) { if (is_float($t['AMOUNT'])) { $types[$i]['AMOUNT'] = float_to_raw_string($t['AMOUNT']); } elseif (is_integer($t['AMOUNT'])) { $types[$i]['AMOUNT'] = strval($t['AMOUNT']); } } return $types; }