Beispiel #1
0
 /**
  * Constructor
  *
  * @param string $purpose
  * @param integer $item_id
  * @param integer $user_id
  */
 function __construct($purpose, $item_id, $user_id)
 {
     $this->DB = Core::GetDBInstance();
     $this->UserID = $user_id;
     $this->Purpose = $purpose;
     $this->ItemID = $item_id;
     $this->Hidden = 0;
     $this->Status = INVOICE_STATUS::PENDING;
     $this->ActionStatus = INVOICE_ACTION_STATUS::PENDING;
     $userinfo = $this->DB->GetRow("SELECT * FROM users WHERE id=?", array($this->UserID));
     //
     // � ����������� �� ���������� ������� �������� ����� � ��������
     //
     switch ($this->Purpose) {
         case INVOICE_PURPOSE::DOMAIN_CREATE:
         case INVOICE_PURPOSE::DOMAIN_RENEW:
         case INVOICE_PURPOSE::DOMAIN_TRANSFER:
         case INVOICE_PURPOSE::DOMAIN_TRADE:
         case INVOICE_PURPOSE::PREREGISTRATION_DROPCATCHING:
             if (is_numeric($item_id)) {
                 $Domain = DBDomain::GetInstance()->Load($item_id);
             } else {
                 $Domain = $item_id;
                 $this->ItemID = $items_id = $Domain->ID;
             }
             if ($this->Purpose == INVOICE_PURPOSE::DOMAIN_CREATE || $this->Purpose == INVOICE_PURPOSE::DOMAIN_RENEW || $this->Purpose == INVOICE_PURPOSE::PREREGISTRATION_DROPCATCHING) {
                 $period = $Domain->Period;
             }
             $min_period = $this->Purpose == INVOICE_PURPOSE::DOMAIN_RENEW ? (int) $Domain->GetConfig()->renewal->min_period : 1;
             $period = max($period, $min_period);
             $price = $this->DB->GetRow("\r\n\t\t\t\t\t\tSELECT * FROM prices WHERE TLD=? AND purpose=? AND period=?", array($Domain->Extension, $this->Purpose, $period));
             if ($price === array()) {
                 throw new Exception(sprintf("Failed to find price for %s TLD: %s period: %s", $this->Purpose, $Domain->Extension, $period));
             }
             // Get discount
             if ($userinfo["packageid"] != 0) {
                 $discount = $this->DB->GetRow("SELECT * FROM discounts WHERE TLD=? AND purpose=? AND packageid=?", array($Domain->Extension, $this->Purpose, $userinfo["packageid"]));
                 $this->Discount = round($price["cost"] / 100 * $discount["discount"], 2);
             } else {
                 $this->Discount = 0;
             }
             $this->Total = $price["cost"] - $this->Discount;
             break;
     }
     // ����������� ���
     $this->VATPercent = 0;
     if ((double) $userinfo["vat"] > -1) {
         $this->VATPercent = (double) $userinfo["vat"];
     } else {
         $this->VATPercent = (double) $this->DB->GetOne("SELECT vat FROM countries WHERE code=?", array($userinfo["country"]));
     }
     if ($this->VATPercent > 0) {
         $this->VAT = round($this->Total / 100 * $this->VATPercent, 2);
         $this->Total = $this->Total + $this->VAT;
     } else {
         $this->VAT = 0;
     }
 }