/**
  * Save Hosting Service Purchase
  */
 public function save()
 {
     $nextBillingDate = DBConnection::format_date($this->post['nextbillingdate']);
     $this->get['hspurchase']->setTerm($this->post['term']->getTermLength());
     $this->get['hspurchase']->setNextBillingDate($nextBillingDate);
     $this->get['hspurchase']->setDomainName($this->post['domain']);
     $this->get['hspurchase']->setServerID($this->post['server']->getID());
     $this->get['hspurchase']->setNote($this->post['note']);
     update_HostingServicePurchaseDBO($this->get['hspurchase']);
     // Success
     $this->setMessage(array("type" => "[CHANGES_SAVED]"));
     $this->reload();
 }
示例#2
0
/**
 * Insert InvoiceDBO into database
 *
 * @param InvoiceDBO &$dbo InvoiceDBO to add to database
 */
function add_InvoiceDBO(&$dbo)
{
    $DB = DBConnection::getDBConnection();
    // Build SQL
    $sql = $DB->build_insert_sql("invoice", array("accountid" => intval($dbo->getAccountID()), "date" => $dbo->getDate(), "periodbegin" => $dbo->getPeriodBegin(), "periodend" => $dbo->getPeriodEnd(), "note" => $dbo->getNote(), "terms" => intval($dbo->getTerms()), "outstanding" => $dbo->getOutstanding()));
    // Run query
    if (!mysql_query($sql, $DB->handle())) {
        throw new DBException(mysql_error($DB->handle()));
    }
    // Get auto-increment ID
    $id = mysql_insert_id($DB->handle());
    // Validate ID
    if ($id === false) {
        // DB error
        throw new DBException("Could not retrieve ID from previous INSERT!");
    }
    if ($id == 0) {
        // No ID?
        throw new DBException("Previous INSERT did not generate an ID");
    }
    // Add line-items to database as well
    if (($itemdbo_array = $dbo->getItems()) != null) {
        foreach ($itemdbo_array as $itemdbo) {
            $itemdbo->setInvoiceID($id);
            add_InvoiceItemDBO($itemdbo);
        }
    }
    // Update Purchase DBO's with a prev invoice id set to -1
    foreach ($dbo->getUpdatePurchases() as $purchaseDBO) {
        $purchaseDBO->setPrevInvoiceID($id);
        switch (get_class($purchaseDBO)) {
            case "DomainServicePurchaseDBO":
                update_DomainServicePurchaseDBO($purchaseDBO);
                break;
            case "HostingServicePurchaseDBO":
                update_HostingServicePurchaseDBO($purchaseDBO);
                break;
            case "ProductPurchaseDBO":
                update_ProductPurchaseDBO($purchaseDBO);
                break;
        }
    }
    // Store ID in DBO
    $dbo->setID($id);
}