/**
  * Add Tax Rule
  */
 function addTaxRule()
 {
     if ($this->post['allstates'] == "true") {
         $this->post['state'] = null;
     } else {
         if (!isset($this->post['state'])) {
             // A specific state was not provided
             throw new FieldMissingException("state");
         }
     }
     // Create a new Tax Rule DBO
     $taxrule_dbo = new TaxRuleDBO();
     $taxrule_dbo->setCountry($this->post['country']);
     $taxrule_dbo->setState($this->post['state']);
     $taxrule_dbo->setRate($this->post['rate']);
     $taxrule_dbo->setAllStates($this->post['allstates'] == "true" ? "Yes" : "Specific");
     $taxrule_dbo->setDescription($this->post['description']);
     // Insert Tax Rule into database
     add_TaxRuleDBO($taxrule_dbo);
     // Success
     $this->setMessage(array("type" => "[TAX_RULE_CREATED]"));
     $this->post['success'] = "true";
 }
Example #2
0
/**
 * Load multiple TaxRuleDBO's from database
 *
 * @param string $filter A WHERE clause
 * @param string $sortby Field name to sort results by
 * @param string $sortdir Direction to sort in (ASEC or DESC)
 * @param int $limit Limit the number of results
 * @param int $start Record number to start the results at
 * @return array Array of TaxRuleDBO's
 */
function &load_array_TaxRuleDBO($filter = null, $sortby = null, $sortdir = null, $limit = null, $start = null)
{
    $DB = DBConnection::getDBConnection();
    // Build query
    $sql = $DB->build_select_sql("taxrule", "*", $filter, $sortby, $sortdir, $limit, $start);
    // Run query
    if (!($result = @mysql_query($sql, $DB->handle()))) {
        // Query error
        throw new DBException(mysql_error($DB->handle()));
    }
    if (mysql_num_rows($result) == 0) {
        // No services found
        throw new DBNoRowsFoundException();
    }
    // Build an array of DBOs from the result set
    $dbo_array = array();
    while ($data = mysql_fetch_array($result)) {
        // Create and initialize a new DBO with the data from the DB
        $dbo = new TaxRuleDBO();
        $dbo->load($data);
        // Add TaxRuleDBO to array
        $dbo_array[] = $dbo;
    }
    return $dbo_array;
}