function getLettersEmailsCount($letters_ids) { global $application; if (empty($letters_ids)) { return array(); } $tables = $this->getTables(); $ntables = modApiFunc('Newsletter', 'getTables'); $ltable = 'newsletter_topics'; $lcolumns =& $ntables[$ltable]['columns']; $ttable = 'subscription_topic'; $tcolumns =& $tables[$ttable]['columns']; $etable = 'subscription_email'; $ecolumns =& $tables[$etable]['columns']; $query = new DB_Select($ltable); $query->addSelectField($lcolumns['letter_id']); $query->addSelectField($ecolumns['email_id']); $query->addInnerJoin($ttable, $lcolumns['topic_id'], DB_EQ, $tcolumns['topic_id']); $query->addSelectField(DB_Select::fCountDistinct($ecolumns['email_id']), 'topic_emails'); $query->addLeftJoin($etable, $ecolumns['topic_id'], DB_EQ, $tcolumns['topic_id']); $query->Where($lcolumns['letter_id'], DB_IN, DBQuery::arrayToIn($letters_ids)); $query->SelectGroup($lcolumns['letter_id']); $res = $application->db->getDB_Result($query); $counts = array(); foreach (array_keys($res) as $i) { $r =& $res[$i]; $counts[$r['letter_id']] = $r['topic_emails']; } return $counts; }
function getTaxFormulaViewFull($tax_rate_id, $specific_rate = "") { if (!$tax_rate_id || $tax_rate_id == 0) { return ""; } global $application; $MessageResources =& $application->getInstance('MessageResources'); $tables = $this->getTables(); $tr = $tables['tax_rates']['columns']; $tn = $tables['tax_names']['columns']; $query = new DB_Select(); $query->addSelectField($tr['rate'], 'Rate'); $query->addSelectField($tr['formula'], 'Formula'); $query->addSelectField($tr['applicable'], 'Applicable'); $query->addLeftJoin('tax_names', $tn['id'], DB_EQ, $tr['tn_id']); $query->setMultiLangAlias('_name', 'tax_names', $tn['name'], $tn['id'], 'Taxes'); $query->addSelectField($query->getMultiLangAlias('_name'), 'TaxName'); $query->WhereValue($tr['id'], DB_EQ, $tax_rate_id); $result = $application->db->getDB_Result($query); if (sizeof($result) == 0) { return ""; } $result = $result[0]; if ($specific_rate != "") { $result['Rate'] = "[{$specific_rate}]"; } if ($result["Applicable"] == "false") { return prepareHTMLDisplay($result['TaxName']) . " = " . $MessageResources->getMessage('TAX_RATE_NOT_APPLICABLE_LABEL'); } $replace = array(); foreach ($this->getTaxNamesList() as $taxNameInfo) { $replace['{t_' . $taxNameInfo['Id'] . '}'] = prepareHTMLDisplay($taxNameInfo['Name']); } foreach ($this->getTaxCostsList() as $cost) { $replace['{p_' . $cost['id'] . '}'] = $MessageResources->getMessage($cost['name']); } preg_match_all("/([0-9]+\\.?[0-9]+)/", $result['Formula'], $numbers); for ($j = 0; $j < sizeof($numbers[0]); $j++) { $replace[$numbers[0][$j]] = modApiFunc("Localization", "num_format", $numbers[0][$j]); } $result['Formula'] = strtr($result['Formula'], $replace); return prepareHTMLDisplay($result['TaxName']) . " = " . $result['Rate'] . "% * (" . $result['Formula'] . ")"; }
/** * Returns complete person info with the specified id, which is not used * (Nov.2006). It wasn't tested with the person info variants. */ function getPersonInfo($person_id) { global $application; $tables = $this->getTables(); $pit = $tables['person_info_types']['columns']; $piv = $tables['person_info_variants']['columns']; $ptiv = $tables['person_to_info_variants']['columns']; $pd = $tables['persons_data']['columns']; # get a list of variants, associated with the person $query = new DB_Select(); #get data on person info type variant $query->addSelectField($piv['tag'], 'piv_tag'); $query->addLeftJoin('person_info_variants', $ptiv['variant_id'], DB_EQ, $piv['id']); $query->addSelectField($pit['id'], 'type_id'); $query->addLeftJoin('person_info_types', $pit['id'], DB_EQ, $piv['type_id']); $query->addSelectField($ptiv['variant_id'], 'variant_id'); $query->Where($ptiv['person_id'], DB_EQ, $person_id); $result = $application->db->getDB_Result($query); # get all data associated with that person $query = new DB_Select(); $query->addSelectField($pd['value'], 'value'); $query->addSelectField($pd['variant_id'], 'variant_id'); $query->addSelectField($pd['attribute_id'], 'attribute_id'); $query->Where($pd['person_id'], DB_EQ, $person_id); $data_result = $application->db->getDB_Result($query); # structure for the following usage $person_data = array(); foreach ($data_result as $data) { if (!array_key_exists($data['variant_id'], $person_data)) { $person_data[$data['variant_id']] = array(); } $person_data[$data['variant_id']][$data['attribute_id']] = $data['value']; } $variants = array(); for ($i = 0; $i < sizeof($result); $i++) { $variant = $this->getPersonVariantInfo($result[$i]['variant_id']); # real attribute values for this type if (array_key_exists($variant['id'], $person_data)) { $variant_value =& $person_data[$variant['id']]; # save real values foreach ($variant['attr'] as $attr) { if (!array_key_exists($attr['id'], $variant_value)) { continue; } $variant['attr'][$attr['tag']]['value'] = $variant_value[$attr['id']]; } } $variants[$variant['type_tag']] = $variant; } return $variants; }
function __loadOrdersSummary() { if (!$this->search_completed or empty($this->orders_ids)) { return; } // : // , // main_store_currency . // main_store_currency, // . // main_store_currency. global $application; $co_tables = modApiStaticFunc('Checkout', 'getTables'); $orders_table = $co_tables['orders']['columns']; $order_prices_table = $co_tables['order_prices']['columns']; $query = new DB_Select(); $query->addSelectTable('orders'); $query->addSelectField($order_prices_table['order_total'], 'order_total'); $query->addSelectField($orders_table['payment_status_id'], 'payment_status_id'); $query->addSelectField($order_prices_table['currency_code'], 'currency_code'); $query->WhereValue($order_prices_table['currency_type'], DB_EQ, CURRENCY_TYPE_MAIN_STORE_CURRENCY); $query->WhereAnd(); $query->Where($orders_table['id'], DB_IN, "('" . implode("','", $this->orders_ids) . "')"); $query->addLeftJoin('order_prices', $orders_table['id'], DB_EQ, $order_prices_table['order_id']); $rows = $application->db->getDB_Result($query); $amount = 0.0; $fully_paid_amount = 0.0; $main_store_currency = modApiFunc("Localization", "getCurrencyCodeById", modApiFunc("Localization", "getMainStoreCurrency")); foreach ($rows as $order_info) { $order_main_currency = $order_info['currency_code']; $order_total = $order_info['order_total']; if ($order_main_currency != $main_store_currency) { $order_total = modApiFunc('Currency_Converter', 'convert', $order_total, $order_main_currency, $main_store_currency); } $amount += $order_total; if ($order_info['payment_status_id'] == ORDER_PAYMENT_STATUS_FULLY_PAID) { $fully_paid_amount += $order_total; } } $query = new DB_Select(); $query->addSelectTable('orders'); $query->addSelectField($query->fMax($orders_table['date']), 'max_date'); $query->addSelectField($query->fMin($orders_table['date']), 'min_date'); $query->Where($orders_table['id'], DB_IN, "('" . implode("','", $this->orders_ids) . "')"); $res = $application->db->getDB_Result($query); $this->orders_summary = array('amount' => $amount, 'max_date' => $res[0]['max_date'], 'min_date' => $res[0]['min_date'], 'fully_paid_amount' => $fully_paid_amount); }