Beispiel #1
0
 public function signinAction()
 {
     $request = $this->getRequest();
     $NS = new Zend_Session_Namespace('Default');
     $translator = Shineisp_Registry::getInstance()->Zend_Translate;
     $customerparams = array();
     // Check the request of redirection of the user
     $redir = $request->getParam('redir');
     // Check if we have a POST request
     if (!$request->isPost()) {
         return $this->_helper->redirector('login', 'customer');
     }
     // Get our form and validate it
     $form = new Default_Form_LoginForm(array('action' => '/customer/signin/redir/' . $redir, 'method' => 'post'));
     if (!$form->isValid($request->getPost())) {
         // Invalid entries
         $this->view->form = $form;
         return $this->_helper->viewRenderer('login');
         // re-render the login form
     }
     // Get the values posted
     $params = $form->getValues();
     $auth = Zend_Auth::getInstance();
     $auth->setStorage(new Zend_Auth_Storage_Session('default'));
     // Get the customer
     $retval = Customers::login($params['email'], $params['password']);
     if (empty($retval)) {
         $result = new Zend_Auth_Result(Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID, $params['email']);
         $NS->customer = null;
         $this->view->form = $form;
         $this->view->message = $translator->translate('User not found. Please check your credentials.');
         return $this->_helper->viewRenderer('login');
         // re-render the login form
     } else {
         $result = new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, null);
         $customer = Customers::getAllInfo($retval['customer_id'], "c.customer_id, a.address_id, cts.type_id, l.legalform_id, ct.country_id, cn.contact_id, s.status_id, c.*, a.*, l.*, cn.*, cts.*, s.*");
         $NS->customer = $customer;
         // Set the default control panel language
         if (!empty($retval['language'])) {
             $lang = $retval['language'];
         }
     }
     // We're authenticated! Redirect to the home page
     $auth->getStorage()->write($retval);
     // If exist a redirect request the client will be redirect after the login action
     if (!empty($NS->goto) && is_array($NS->goto)) {
         $this->_helper->redirector($NS->goto['action'], $NS->goto['controller'], $NS->goto['module'], $NS->goto['options']);
     }
     if (!empty($lang)) {
         $this->_helper->redirector('index', 'dashboard', 'default', array('lang' => $lang));
         // back to login page
     } else {
         $this->_helper->redirector('index', 'dashboard', 'default');
     }
 }
Beispiel #2
0
 public function get($uuid)
 {
     $this->authenticate();
     $customer = Customers::findWithUuid($uuid);
     if (empty($customer)) {
         return false;
     }
     $customerid = $customer['customer_id'];
     $fields = ' c.company as company, c.firstname as firstname, c.lastname as lastname,c.sex,c.email, c.taxpayernumber, c.vat, l.legalform_id as legalformid,c.birthdate as birthdate, 
                 c.sex as sex, a.address_id, a.address as address, a.city as city,a.code as code,a.country_id as countryid ,a.region_id as regionid,a.area as area, ct.code as countrycode
                 ,cn.*,cnts.*';
     $customerid = $customer['customer_id'];
     $customer = Customers::getAllInfo($customerid, $fields);
     unset($customer['password']);
     return $customer;
 }
Beispiel #3
0
 /**
  * accountAction
  * Manage the profile account settings.
  * @return void
  */
 public function accountAction()
 {
     $form = $this->getForm('/profile/process');
     $this->view->form = $form;
     $this->view->mex = $this->getRequest()->getParam('mex');
     $this->view->mexstatus = $this->getRequest()->getParam('status');
     $this->view->title = $this->translator->translate("Profile details");
     $this->view->description = $this->translator->translate("Update here your details filling the applicant form with all the information about you.");
     $rs = Customers::getAllInfo($this->profile['customer_id'], "c.customer_id as customer_id, c.firstname as firstname, c.lastname as lastname, c.company as company, c.type_id as company_type_id, c.legalform_id as legalform, c.email as email, c.vat as vat, a.address as address, a.city as city, a.code as code, a.country_id as country_id, a.area as area, DATE_FORMAT(c.birthdate,'%d/%m/%Y') as birthdate, c.birthplace as birthplace, c.taxpayernumber as taxpayernumber, c.gender as gender, c.birthdistrict as birthdistrict, c.birthcountry as birthcountry, c.birthnationality as birthnationality, c.issubscriber as newsletter");
     if (!empty($rs)) {
         $form->populate($rs);
         $this->view->contactsdatagrid = $this->contactsGrid($this->profile['customer_id']);
         $this->view->clients = $this->getClients($this->profile['customer_id']);
         $this->view->isReseller = Customers::isReseller($this->profile['customer_id']);
     } else {
         $this->view->isReseller = false;
     }
     $this->_helper->viewRenderer('applicantform');
 }
Beispiel #4
0
 /**
  * Create a Nic-Handle for the client 
  * 
  * Executes the 'login' command on Ascio's servers, to retrive the session variable
  * for execute the commands.
  * 
  *   Parameters
  *   ===========
  *   string session : the session id
  *   string name : the contact name
  *   string firstname : the contact firstname
  *   string sex : the contact sex (M/F)
  *   string password : the contact password
  *   string email : the contact email
  *   string phone : the contact phone number (international format, ex: +33.899701761)
  *   string fax : the contact fax number
  *   string address : the contact address
  *   string city : the contact city
  *   string area : the contact area
  *   string zip : the contact zip code
  *   string country : the contact country (be|fr|pl|es|lu|ch|de|...)
  *   string language : the contact language (fr|en|pl|es|de)
  *   boolean isOwner : is it an owner nic ? default false
  *   string legalform : the contact legalform (corporation|individual|association|other)
  *   string organisation : organisation name
  *   string legalName : the contact legalname
  *   string legalNumber : the contact legalnumber (SIRET/SIREN/...)
  *   string vat : the contact vat
  *   string birthDay : the contact birthDay
  *   string birthCity : the contact birth city
  *   string nationalIdentificationNumber : the contact fiscal code or company vat
  *   string companyNationalIdentificationNumber : the contact vat
  *   string corporationType : the contact vat (s.a.s.|s.n.c.|s.r.l.|s.p.a.|s.a.p.a.|s.c.a.r.l.|individuale)
  * 
  * 
  * @param      integer      $customerID		Code identifier
  * @return     string       $nicHandle		the new contact handle id
  * @access     private
  */
 private function createNicHandle($customerID)
 {
     $soap = $this->Connect();
     if (!empty($this->session)) {
         $fields = "c.customer_id as customer_id, c.company as company, c.firstname as firstname, c.lastname as lastname, c.gender as gender, c.email as email, c.password as password, c.birthdate as birthdate, c.birthplace as birthplace, c.taxpayernumber as taxpayernumber, c.vat as vat, c.note as note,  a.address as address, a.code as code, a.city as city, a.area as area, ct.name as country, ct.code as countrycode, cts.type_id as type_id, cts.name as companytype, l.legalform_id as legalform_id, l.name as legalform, s.status_id as status_id, s.status as status, cn.contact as contact";
         $customer = Customers::getAllInfo($customerID, $fields);
         return $soap->nicCreateIT($this->session['id'], $customer['lastname'], $customer['firstname'], $customer['gender'], Shineisp_Commons_Utilities::GenerateRandomString(), $customer['email'], $customer['contact'], null, $customer['address'], $customer['city'], $customer['area'], $customer['code'], strtolower($customer['countrycode']), "en", true, $customer['legalform'], $customer['company'], $customer['firstname'] . " " . $customer['lastname'], null, $customer['vat'], Shineisp_Commons_Utilities::formatDateOut($customer['birthdate']), $customer['birthplace'], $customer['taxpayernumber'], $customer['vat'], $customer['companytype']);
         // Corporation Type
     }
     return false;
 }
Beispiel #5
0
 /**
  * print the credit note
  * @param integer $creditnoteId
  */
 public static function PrintPDF($creditnoteId, $show = true)
 {
     $currency = Shineisp_Registry::getInstance()->Zend_Currency;
     $pdf = new Shineisp_Commons_PdfOrder();
     $translator = Shineisp_Registry::getInstance()->Zend_Translate;
     $creditnote = Doctrine_Query::create()->from('CreditNotes cn')->leftJoin('cn.CreditNotesItems cni')->leftJoin('cn.Invoices i')->leftJoin('i.Customers c')->leftJoin('c.Addresses a')->leftJoin('a.Countries co')->leftJoin('i.Orders o')->leftJoin('o.OrdersItems oi')->leftJoin('o.Isp isp')->leftJoin('o.Payments p')->leftJoin('p.Banks b')->leftJoin('o.Statuses s')->leftJoin('o.Customers oc')->where("cn.creditnote_id = ?", $creditnoteId)->execute(array(), Doctrine::HYDRATE_ARRAY);
     if (empty($creditnote)) {
         return false;
     }
     $invoice = $creditnote[0]['Invoices'];
     $customer = $creditnote[0]['Invoices']['Customers'];
     $payments = $creditnote[0]['Invoices']['Orders']['Payments'];
     $order = $creditnote[0]['Invoices']['Orders'];
     $items = $creditnote[0]['CreditNotesItems'];
     $database['header']['label'] = $translator->translate('Credit Note No.') . " " . sprintf("%03d", $creditnote[0]['number']) . " - " . Shineisp_Commons_Utilities::formatDateOut($creditnote[0]['creationdate']);
     $database['columns'][] = array("value" => "Description");
     $database['columns'][] = array("value" => "Qty", "size" => 30, "align" => "center");
     $database['columns'][] = array("value" => "Unit", "size" => 30);
     $database['columns'][] = array("value" => "Tax Free Price", "size" => 60, "align" => "right");
     $database['columns'][] = array("value" => "VAT", "size" => 40, "align" => "right");
     $database['columns'][] = array("value" => "Total", "size" => 50, "align" => "right");
     if (isset($order)) {
         $info['order_number'] = $order['order_id'];
         $info['invoice_number'] = $invoice['number'];
         $info['date'] = Shineisp_Commons_Utilities::formatDateOut($invoice['invoice_date']);
         //if customer comes from reseller
         if ($order['Customers']['parent_id']) {
             $reseller = Customers::getAllInfo($order['Customers']['parent_id']);
             $info['customer']['customer_id'] = $reseller['customer_id'];
             $info['customer']['company'] = $reseller['company'];
             $info['customer']['firstname'] = $reseller['firstname'];
             $info['customer']['lastname'] = $reseller['lastname'];
             $info['customer']['vat'] = $reseller['vat'];
             $info['customer']['email'] = $reseller['email'];
             if (isset($reseller['Addresses'][0])) {
                 $info['customer']['address'] = $reseller['Addresses'][0]['address'];
                 $info['customer']['city'] = $reseller['Addresses'][0]['city'];
                 $info['customer']['code'] = $reseller['Addresses'][0]['code'];
                 $info['customer']['country'] = !empty($reseller['Addresses'][0]['Countries']['name']) ? $reseller['Addresses'][0]['Countries']['name'] : "";
             }
         } else {
             $info['customer']['customer_id'] = $customer['customer_id'];
             $info['customer']['company'] = $customer['company'];
             $info['customer']['firstname'] = $customer['firstname'];
             $info['customer']['lastname'] = $customer['lastname'];
             $info['customer']['vat'] = $customer['vat'];
             $info['customer']['email'] = $customer['email'];
             if (isset($customer['Addresses'][0])) {
                 $info['customer']['address'] = $customer['Addresses'][0]['address'];
                 $info['customer']['city'] = $customer['Addresses'][0]['city'];
                 $info['customer']['code'] = $customer['Addresses'][0]['code'];
                 $info['customer']['country'] = $customer['Addresses'][0]['Countries']['name'];
             }
         }
         if (count($payments) > 0) {
             $info['payment_date'] = Shineisp_Commons_Utilities::formatDateOut($payments[0]['paymentdate']);
             $info['payment_mode'] = $payments[0]['Banks']['name'];
             $info['payment_description'] = $payments[0]['description'];
             $info['payment_transaction_id'] = $payments[0]['reference'];
         }
         $info['invoice_id'] = $invoice['number'];
         $info['company']['name'] = $order['Isp']['company'];
         $info['company']['vat'] = $order['Isp']['vatnumber'];
         $info['company']['bankname'] = $order['Isp']['bankname'];
         $info['company']['iban'] = $order['Isp']['iban'];
         $info['company']['bic'] = $order['Isp']['bic'];
         $info['company']['address'] = $order['Isp']['address'];
         $info['company']['zip'] = $order['Isp']['zip'];
         $info['company']['city'] = $order['Isp']['city'];
         $info['company']['country'] = $order['Isp']['country'];
         $info['company']['telephone'] = $order['Isp']['telephone'];
         $info['company']['fax'] = $order['Isp']['fax'];
         $info['company']['website'] = $order['Isp']['website'];
         $info['company']['email'] = $order['Isp']['email'];
         $info['company']['slogan'] = $order['Isp']['slogan'];
         $info['subtotal'] = $currency->toCurrency($creditnote[0]['total_net'], array('currency' => Settings::findbyParam('currency')));
         $info['grandtotal'] = $currency->toCurrency($creditnote[0]['total'], array('currency' => Settings::findbyParam('currency')));
         $info['vat'] = $currency->toCurrency($creditnote[0]['vat'], array('currency' => Settings::findbyParam('currency')));
         $info['delivery'] = 0;
         $database['records'] = $info;
         //				Zend_Debug::dump($creditnote);
         //				die;
         foreach ($items as $item) {
             $item['price'] = $currency->toCurrency($item['price'], array('currency' => Settings::findbyParam('currency')));
             $item['vat'] = $currency->toCurrency($item['vat'], array('currency' => Settings::findbyParam('currency')));
             $item['total'] = $currency->toCurrency($item['total'], array('currency' => Settings::findbyParam('currency')));
             $database['records'][] = array($item['description'], $item['quantity'], 'nr', $item['price'], $item['vat'], $item['total']);
         }
         if (isset($order)) {
             $pdf->CreatePDF($database, $creditnote[0]['creationdate'] . " - " . $creditnote[0]['number'] . ".pdf", $show, "/documents/creditnotes", true);
         }
     }
 }
Beispiel #6
0
 /**
  * print the order
  *
  * @param unknown_type $invoiceid
  */
 public static function pdf($order_id, $show = true, $force = false, $path = "/documents/orders/")
 {
     $taxpercent = "";
     $currency = Shineisp_Registry::getInstance()->Zend_Currency;
     if (!is_numeric($order_id)) {
         return false;
     }
     $pdf = new Shineisp_Commons_PdfOrder();
     $translator = Shineisp_Registry::getInstance()->Zend_Translate;
     $payments = Payments::findbyorderid($order_id, null, true);
     $order = self::getAllInfo($order_id, null, true);
     // Set the name of the file
     $filename = $order[0]['order_date'] . " - " . $order[0]['order_id'] . ".pdf";
     $database['header']['label'] = $translator->translate('Order No.') . " " . $order[0]['order_number'] . " - " . Shineisp_Commons_Utilities::formatDateOut($order[0]['order_date']);
     $database['columns'][] = array("value" => $translator->translate("SKU"), "size" => 40);
     $database['columns'][] = array("value" => $translator->translate("Description"));
     $database['columns'][] = array("value" => $translator->translate("Qty"), "size" => 30, "align" => "center");
     $database['columns'][] = array("value" => $translator->translate("Unit"), "size" => 30);
     $database['columns'][] = array("value" => $translator->translate("Tax Free Price"), "size" => 60, "align" => "right");
     $database['columns'][] = array("value" => $translator->translate("Discount"), "size" => 60, "align" => "right");
     $database['columns'][] = array("value" => $translator->translate("Setup fee"), "size" => 60, "align" => "right");
     $database['columns'][] = array("value" => $translator->translate("Tax %"), "size" => 40, "align" => "center");
     $database['columns'][] = array("value" => $translator->translate("Total"), "size" => 50, "align" => "right");
     if (isset($order[0])) {
         $orderinfo['order_number'] = !empty($order[0]['order_number']) ? $order[0]['order_number'] : self::formatOrderId($order[0]['order_id']);
         $orderinfo['invoice_id'] = "";
         $orderinfo['date'] = Shineisp_Commons_Utilities::formatDateOut($order[0]['order_date']);
         //if customer comes from reseller
         if ($order[0]['Customers']['parent_id']) {
             $isTaxFree = Customers::isTaxFree($order[0]['Customers']['parent_id']);
             $isVATFree = Customers::isVATFree($order[0]['Customers']['parent_id']);
             $invoice_dest = Customers::getAllInfo($order[0]['Customers']['parent_id'], 'c.*, a.*');
             $orderinfo['customer']['customer_id'] = $invoice_dest['customer_id'];
             $orderinfo['customer']['company'] = $invoice_dest['company'];
             $orderinfo['customer']['firstname'] = $invoice_dest['firstname'];
             $orderinfo['customer']['lastname'] = $invoice_dest['lastname'];
             $orderinfo['customer']['vat'] = $invoice_dest['vat'];
             $orderinfo['customer']['taxpayernumber'] = $invoice_dest['taxpayernumber'];
             $orderinfo['customer']['email'] = $invoice_dest['email'];
             if (isset($invoice_dest['Addresses'][0])) {
                 $orderinfo['customer']['address'] = $invoice_dest['Addresses'][0]['address'];
                 $orderinfo['customer']['city'] = $invoice_dest['Addresses'][0]['city'];
                 $orderinfo['customer']['code'] = $invoice_dest['Addresses'][0]['code'];
                 $orderinfo['customer']['country'] = !empty($invoice_dest['Addresses'][0]['Countries']['name']) ? $invoice_dest['Addresses'][0]['Countries']['name'] : "";
             }
         } else {
             $isTaxFree = Customers::isTaxFree($order[0]['Customers']['customer_id']);
             $isVATFree = Customers::isVATFree($order[0]['Customers']['customer_id']);
             $orderinfo['customer']['customer_id'] = $order[0]['Customers']['customer_id'];
             $orderinfo['customer']['company'] = $order[0]['Customers']['company'];
             $orderinfo['customer']['firstname'] = $order[0]['Customers']['firstname'];
             $orderinfo['customer']['lastname'] = $order[0]['Customers']['lastname'];
             $orderinfo['customer']['vat'] = $order[0]['Customers']['vat'];
             $orderinfo['customer']['taxpayernumber'] = $order[0]['Customers']['taxpayernumber'];
             $orderinfo['customer']['email'] = $order[0]['Customers']['email'];
             if (isset($order[0]['Customers']['Addresses'][0])) {
                 $orderinfo['customer']['address'] = $order[0]['Customers']['Addresses'][0]['address'];
                 $orderinfo['customer']['city'] = $order[0]['Customers']['Addresses'][0]['city'];
                 $orderinfo['customer']['code'] = $order[0]['Customers']['Addresses'][0]['code'];
                 $orderinfo['customer']['country'] = $order[0]['Customers']['Addresses'][0]['Countries']['name'];
             }
         }
         if (count($payments) > 0) {
             $orderinfo['payment_date'] = Shineisp_Commons_Utilities::formatDateOut($payments[0]['paymentdate']);
             $orderinfo['payment_mode'] = $payments[0]['Banks']['name'];
             $orderinfo['payment_description'] = $payments[0]['description'];
             $orderinfo['payment_transaction_id'] = $payments[0]['reference'];
         }
         $orderinfo['invoice_id'] = "";
         $orderinfo['company']['name'] = $order[0]['Isp']['company'];
         $orderinfo['company']['manager'] = $order[0]['Isp']['manager'];
         $orderinfo['company']['vat'] = $order[0]['Isp']['vatnumber'];
         $orderinfo['company']['bankname'] = $order[0]['Isp']['bankname'];
         $orderinfo['company']['iban'] = $order[0]['Isp']['iban'];
         $orderinfo['company']['bic'] = $order[0]['Isp']['bic'];
         $orderinfo['company']['address'] = $order[0]['Isp']['address'];
         $orderinfo['company']['zip'] = $order[0]['Isp']['zip'];
         $orderinfo['company']['city'] = $order[0]['Isp']['city'];
         $orderinfo['company']['country'] = $order[0]['Isp']['country'];
         $orderinfo['company']['telephone'] = $order[0]['Isp']['telephone'];
         $orderinfo['company']['fax'] = $order[0]['Isp']['fax'];
         $orderinfo['company']['website'] = $order[0]['Isp']['website'];
         $orderinfo['company']['email'] = $order[0]['Isp']['email'];
         $orderinfo['company']['slogan'] = $order[0]['Isp']['slogan'];
         $orderinfo['company']['custom1'] = $order[0]['Isp']['custom1'];
         $orderinfo['company']['custom2'] = $order[0]['Isp']['custom2'];
         $orderinfo['company']['custom3'] = $order[0]['Isp']['custom3'];
         if ($order[0]['status_id'] == Statuses::id("tobepaid", "orders")) {
             // To be payed
             $orderinfo['ribbon']['text'] = $translator->translate("To be Paid");
             $orderinfo['ribbon']['color'] = "#D60000";
             $orderinfo['ribbon']['border-color'] = "#BD0000";
         } elseif ($order[0]['status_id'] == Statuses::id("complete", "orders")) {
             // Complete
             $orderinfo['ribbon']['text'] = $translator->translate("Paid");
             $orderinfo['ribbon']['color'] = "#009926";
             $orderinfo['ribbon']['border-color'] = "#00661A";
         } else {
             $orderinfo['ribbon']['text'] = $translator->translate(Statuses::getLabel($order[0]['status_id']));
             $orderinfo['ribbon']['color'] = "#FFCC33";
             $orderinfo['ribbon']['border-color'] = "#E6AC00";
         }
         $orderinfo['subtotal'] = $order[0]['total'];
         $orderinfo['grandtotal'] = $order[0]['grandtotal'];
         $orderinfo['vat'] = $order[0]['vat'];
         $orderinfo['delivery'] = 0;
         $database['records'] = $orderinfo;
         foreach ($order[0]['OrdersItems'] as $item) {
             $price = $item['price'] * $item['quantity'] + $item['setupfee'];
             $tax = Taxes::getTaxbyProductID($item['product_id']);
             if ($tax['percentage'] > 0) {
                 $rowtotal = $price * (100 + $tax['percentage']) / 100;
             } else {
                 $rowtotal = $price;
             }
             if (!$isTaxFree && !$isVATFree) {
                 $taxes = Taxes::getTaxbyProductID($item['product_id']);
                 if (!empty($taxes['percentage'])) {
                     $taxpercent = $taxes['percentage'];
                 }
             }
             if (!empty($item['discount'])) {
                 $item['discount'] = $item['discount'] . "%";
             }
             $database['records'][] = array($item['Products']['sku'], $item['description'], $item['quantity'], $translator->translate('nr'), $item['price'], $item['discount'], $item['setupfee'], $taxpercent, $rowtotal);
         }
         if (isset($order[0])) {
             $pdf->CreatePDF($database, $filename, $show, $path, $force);
             // Execute a custom event
             self::events()->trigger('orders_pdf_created', "Orders", array('file' => "{$path}/{$filename}"));
             return $path . $filename;
         }
     }
     return false;
 }
Beispiel #7
0
 /**
  * CREATE THE ORDER FOR ALL THE AUTORENEWABLE DOMAINS/SERVICES
  * Check all the services [domains, products] and create the orders for each customer only if the service has been set as renewable
  * @return void
  */
 public static function checkServices()
 {
     try {
         $i = 0;
         $customers = array();
         /* We have to start to get all the domains that them expiring date is today
         			 then we have to create a custom array sorted by customerID in order to
         			group services and domains of a specific customer.
         			*/
         // Get all the active domains that expire in 1 day
         $domains = Domains::getExpiringDomainsByDays(1, Statuses::id("active", "domains"));
         if ($domains) {
             Shineisp_Commons_Utilities::log("There are (" . count($domains) . ") new domains to renew");
             // Create the customer group list for the email summary
             foreach ($domains as $domain) {
                 if (is_numeric($domain['reseller'])) {
                     $invoice_dest = Customers::getAllInfo($domain['reseller']);
                     $customers[$domain['customer_id']]['id'] = $invoice_dest['customer_id'];
                     $customers[$domain['customer_id']]['fullname'] = $invoice_dest['firstname'] . " " . $invoice_dest['lastname'] . " " . $invoice_dest['company'];
                     $customers[$domain['customer_id']]['email'] = $invoice_dest['email'];
                     $customers[$domain['customer_id']]['language_id'] = $invoice_dest['language_id'];
                 } else {
                     $customers[$domain['customer_id']]['id'] = $domain['customer_id'];
                     $customers[$domain['customer_id']]['fullname'] = $domain['fullname'];
                     $customers[$domain['customer_id']]['email'] = $domain['email'];
                     $customers[$domain['customer_id']]['language_id'] = $domain['language_id'];
                 }
                 $customers[$domain['customer_id']]['products'][$i]['name'] = $domain['domain'];
                 $customers[$domain['customer_id']]['products'][$i]['type'] = "domain";
                 $customers[$domain['customer_id']]['products'][$i]['renew'] = $domain['renew'];
                 $customers[$domain['customer_id']]['products'][$i]['expiring_date'] = $domain['expiringdate'];
                 $customers[$domain['customer_id']]['products'][$i]['days'] = $domain['days'];
                 // Get the last old order item id
                 if (!empty($domain['oldorders'])) {
                     // find the domain
                     foreach ($domain['oldorders'] as $olditemorder) {
                         // Get all the information from the old order
                         $olditem = OrdersItems::getAllInfo($olditemorder['orderitem_id']);
                         // Check if the old order item refers to the domain selected
                         if (!empty($olditem['parameters']) && !empty($olditem['Orders']['OrdersItemsDomains'][0]['Domains']['tld_id'])) {
                             // Get the old configuration parameters
                             $params = json_decode($olditem['parameters'], true);
                             // 								Zend_Debug::dump($olditem);
                             // 								Zend_Debug::dump($params);
                             // 								Zend_Debug::dump($domain['domain']);
                             // Extract the domain name and match it with the domain selected
                             if (!empty($params['domain']) && $params['domain']['name'] == $domain['domain']) {
                                 $customers[$domain['customer_id']]['products'][$i]['oldorderitemid'] = $olditemorder['orderitem_id'];
                             }
                         }
                     }
                 }
                 Shineisp_Commons_Utilities::log("- " . $domain['domain']);
                 $i++;
             }
         }
         /*
          * Now we have to get the services expired and we have to sum the previous $customers array with these
          * new information.
          */
         // Get all the services active that expire the day after
         $services = OrdersItems::getExpiringServicesByDays(1, Statuses::id("complete", "orders"));
         if ($services) {
             Shineisp_Commons_Utilities::log("There are (" . count($services) . ") new services to renew");
             // Create the customer group list for the email summary
             foreach ($services as $service) {
                 if (is_numeric($service['reseller'])) {
                     $invoice_dest = Customers::getAllInfo($service['reseller']);
                     $customers[$service['customer_id']]['id'] = $invoice_dest['customer_id'];
                     $customers[$service['customer_id']]['fullname'] = $invoice_dest['firstname'] . " " . $invoice_dest['lastname'] . " " . $invoice_dest['company'];
                     $customers[$service['customer_id']]['email'] = $invoice_dest['email'];
                     $customers[$service['customer_id']]['password'] = $invoice_dest['password'];
                     $customers[$service['customer_id']]['language_id'] = $invoice_dest['language_id'];
                 } else {
                     $customers[$service['customer_id']]['id'] = $service['id'];
                     $customers[$service['customer_id']]['fullname'] = $service['fullname'];
                     $customers[$service['customer_id']]['email'] = $service['email'];
                     $customers[$service['customer_id']]['password'] = $service['password'];
                     $customers[$service['customer_id']]['language_id'] = $service['language_id'];
                 }
                 $customers[$service['customer_id']]['products'][$i]['name'] = $service['product'];
                 $customers[$service['customer_id']]['products'][$i]['type'] = "service";
                 $customers[$service['customer_id']]['products'][$i]['renew'] = $service['renew'];
                 $customers[$service['customer_id']]['products'][$i]['expiring_date'] = $service['expiringdate'];
                 $customers[$service['customer_id']]['products'][$i]['days'] = $service['days'];
                 $customers[$service['customer_id']]['products'][$i]['oldorderitemid'] = $service['detail_id'];
                 Shineisp_Commons_Utilities::log("- " . $service['product']);
                 $i++;
             }
         }
         // Create the email messages for the customers
         if (count($customers) > 0) {
             foreach ($customers as $customer) {
                 $items = "";
                 // **** CREATE THE ORDER FOR ALL THE AUTORENEWABLE DOMAINS/SERVICES ***
                 // ============================================================
                 // Renew all the services and domain where the customer has choosen the autorenew of the service.
                 $orderID = Orders::renewOrder($customer['id'], $customer['products']);
                 if (is_numeric($orderID)) {
                     $link = Fastlinks::findlinks($orderID, $customer['id'], 'orders');
                     // Create the fast link to include in the email
                     if (!empty($link[0]['code'])) {
                         $url = "http://" . $_SERVER['HTTP_HOST'] . "/index/link/id/" . $link[0]['code'];
                     } else {
                         $url = "http://" . $_SERVER['HTTP_HOST'];
                     }
                     Shineisp_Commons_Utilities::sendEmailTemplate($customer['email'], 'order_renew', array('fullname' => $customer['fullname'], ':shineisp:' => $customer, 'url' => $url), null, null, null, null, $customer['language_id'], Settings::findbyParam('cron_notify'));
                 }
             }
         }
         /*
          * Now we have to set as expired all the domains records that the date is the date of the expiring of the domain
          * // Expired
          */
         $dq = Doctrine_Query::create()->update('Domains d')->set('d.status_id', Statuses::id('expired', 'domains'))->where('DATEDIFF(d.expiring_date, CURRENT_DATE) <= ?', 0)->addWhere('DATEDIFF(d.expiring_date, CURRENT_DATE) >= ?', 0);
         $dq->execute(null, Doctrine::HYDRATE_ARRAY);
         /*
          * Now we have to set as closed all the domains records that the date is older of -2 days
          * // Closed
          */
         $dq = Doctrine_Query::create()->update('Domains d')->set('d.status_id', Statuses::id('suspended', 'domains'))->where('DATEDIFF(d.expiring_date, CURRENT_DATE) <= ?', -2);
         $dq->execute(null, Doctrine::HYDRATE_ARRAY);
         /*
          * Now we have to set as expired all the services records
          * // Expired
          */
         $dq = Doctrine_Query::create()->update('OrdersItems oi')->set('oi.status_id', Statuses::id('expired', 'orders'))->where('DATEDIFF(oi.date_end, CURRENT_DATE) <= ?', 0);
         $dq->execute(null, Doctrine::HYDRATE_ARRAY);
         /*
          * Now we have to set as deleted all the services records
          * // Deleted
          */
         $dq = Doctrine_Query::create()->update('OrdersItems oi')->set('oi.status_id', Statuses::id('deleted', 'orders'))->where('DATEDIFF(oi.date_end, CURRENT_DATE) <= ?', -2);
         $dq->execute(null, Doctrine::HYDRATE_ARRAY);
         Shineisp_Commons_Utilities::sendEmailTemplate(null, 'cron', array('cronjob' => 'Check Services'), null, null, null, null, null, Settings::findbyParam('cron_notify'));
     } catch (Exception $e) {
         Shineisp_Commons_Utilities::logs($e->getMessage(), "cron.log");
         return false;
     }
     return true;
 }
Beispiel #8
0
 /**
  * Do the login action
  * 
  * @param integer $customerid
  */
 private function doLogin($customerid)
 {
     if (is_numeric($customerid)) {
         $session = new Zend_Session_Namespace('Default');
         $auth = Zend_Auth::getInstance();
         $auth->setStorage(new Zend_Auth_Storage_Session('default'));
         $result = new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, null);
         $customer = Customers::getAllInfo($customerid, "c.customer_id, a.address_id, cts.type_id, l.legalform_id, ct.country_id, cn.contact_id, s.status_id, c.*, a.*, l.*, cn.*, cts.*, s.*");
         // We're authenticated!
         $auth->getStorage()->write($customer);
         // Set the owner of the cart
         $session->cart->setCustomer($customerid);
         return $customer;
     }
     return false;
 }
Beispiel #9
0
 /**
  * Create a Nic-Handle for the client 
  * 
  * Executes the 'login' command on OVH's servers, to retrive the session variable
  * for execute the commands.
  * 
  *   Parameters
  *   ===========
  *   string session : the session id
  *   string name : the contact name
  *   string firstname : the contact firstname
  *   string sex : the contact sex (M/F)
  *   string password : the contact password
  *   string email : the contact email
  *   string phone : the contact phone number (international format, ex: +33.899701761)
  *   string fax : the contact fax number
  *   string address : the contact address
  *   string city : the contact city
  *   string area : the contact area
  *   string zip : the contact zip code
  *   string country : the contact country (be|fr|pl|es|lu|ch|de|...)
  *   string language : the contact language (fr|en|pl|es|de)
  *   boolean isOwner : is it an owner nic ? default false
  *   string legalform : the contact legalform (corporation|individual|association|other)
  *   string organisation : organisation name
  *   string legalName : the contact legalname
  *   string legalNumber : the contact legalnumber (SIRET/SIREN/...)
  *   string vat : the contact vat
  *   string birthDay : the contact birthDay
  *   string birthCity : the contact birth city
  *   string nationalIdentificationNumber : the contact fiscal code or company vat
  *   string companyNationalIdentificationNumber : the contact vat
  *   string corporationType : the contact vat (s.a.s.|s.n.c.|s.r.l.|s.p.a.|s.a.p.a.|s.c.a.r.l.|individuale)
  * 
  * 
  * @param      integer      $customerID		Code identifier
  * @return     string       $nicHandle		the new contact handle id
  * @access     private
  */
 private function createNicHandlebyCustomer($customerID, $domainId)
 {
     $soap = $this->Connect();
     if (!empty($this->session)) {
         $fields = "c.customer_id as customer_id, c.company as company, c.firstname as firstname, c.lastname as lastname, c.gender as gender, c.email as email, c.password as password, c.birthdate as birthdate, c.birthplace as birthplace, c.taxpayernumber as taxpayernumber, c.vat as vat, c.note as note,  a.address as address, a.code as code, a.city as city, a.area as area, ct.name as country, ct.code as countrycode, cts.type_id as type_id, cts.name as companytype, l.legalform_id as legalform_id, l.name as legalform, s.status_id as status_id, s.status as status, cn.contact as contact";
         $customer = Customers::getAllInfo($customerID, $fields);
         $tld = Domains::getDomainTld($domainId);
         if ($tld == "it") {
             // Create a nicHandle for the Italian domain tld
             $params[] = $this->session['id'];
             // Session
             $params[] = $customer['lastname'];
             // Lastname
             $params[] = $customer['firstname'];
             // Firstname
             $params[] = $customer['gender'];
             // Gender
             $params[] = Shineisp_Commons_Utilities::GenerateRandomString();
             // Password
             $params[] = $customer['email'];
             // Email
             $params[] = $customer['contact'];
             // Phone
             $params[] = null;
             // Fax
             $params[] = $customer['address'];
             // Address
             $params[] = $customer['city'];
             // City
             $params[] = $customer['area'];
             // Area
             $params[] = $customer['code'];
             // Zip
             $params[] = strtolower($customer['countrycode']);
             // Country Code
             $params[] = "en";
             // Language
             $params[] = true;
             // isOwner
             $params[] = strtolower($customer['legalform']);
             // Legalform
             $params[] = $customer['company'];
             // Organisation
             $params[] = $customer['firstname'] . " " . $customer['lastname'];
             // Legal name
             $params[] = null;
             // Legal Number
             $params[] = $customer['vat'];
             // VAT or IVA
             $params[] = Shineisp_Commons_Utilities::formatDateOut($customer['birthdate']);
             // Birthday
             $params[] = $customer['birthplace'];
             // Birthcity
             $params[] = $customer['taxpayernumber'];
             // Contact fiscal code or company vat
             $params[] = $customer['vat'];
             // Company National Identification Number
             $params[] = strtolower($customer['companytype']);
             // Call the soap service and send the parameters
             Shineisp_Commons_Utilities::log('Calling nicCreateIT with these params: ' . json_encode($params), "registrar.ovh.log");
             return call_user_func_array(array($soap, 'nicCreateIT'), $params);
         } else {
             $params[] = $this->session['id'];
             // Session
             $params[] = $customer['lastname'];
             // Lastname
             $params[] = $customer['firstname'];
             // Firstname
             $params[] = Shineisp_Commons_Utilities::GenerateRandomString();
             // Password
             $params[] = $customer['email'];
             // Email
             $params[] = $customer['contact'];
             // Phone
             $params[] = null;
             // Fax
             $params[] = $customer['address'];
             // Address
             $params[] = $customer['city'];
             // City
             $params[] = $customer['area'];
             // Area
             $params[] = $customer['code'];
             // Zip
             $params[] = strtolower($customer['countrycode']);
             // Country Code
             $params[] = "en";
             // Language
             $params[] = true;
             // isOwner
             $params[] = strtolower($customer['legalform']);
             // Legalform
             $params[] = $customer['company'];
             // Organisation
             $params[] = $customer['firstname'] . " " . $customer['lastname'];
             // Legal name
             $params[] = null;
             // Legal Number
             $params[] = $customer['vat'];
             // VAT or IVA
             // Call the soap service and send the parameters
             Shineisp_Commons_Utilities::log('Calling nicCreate with these params: ' . json_encode($params), "registrar.ovh.log");
             return call_user_func_array(array($soap, 'nicCreate'), $params);
         }
     }
     return false;
 }
Beispiel #10
0
 /**
  * Create a new client
  * 
  * Executes the creation of new client in the IspConfig control panel
  * Note in order to not fail this command, it must meet the following requirements:
  * 
  * - The customer must be registered in the db.
  * - The customer has bought a hosting plan
  * 
  * @param      array      $task     Must be a valid task 
  * @return     integer    RemoteClientId
  * @access     public
  */
 public function create_client(array $task)
 {
     $clientId = "";
     if (empty($task)) {
         throw new Exception('Task empty.', '3000');
     }
     // Execute a custom event
     $this->events()->trigger('panels_create_client_before', __CLASS__, array('task' => $task));
     $server = self::getServer($task['orderitem_id'], 'web');
     // Connection to the SOAP system
     $client = $this->connect($server['server_id']);
     if (!$client) {
         throw new Exception("There is no way to connect the client with the IspConfig Panel.", "3010");
     }
     try {
         // Get all the customer information
         $customer = Customers::getAllInfo($task['customer_id']);
         // Get the client id saved previously in the customer information page
         $customAttribute = CustomAttributes::getAttribute($task['customer_id'], 'client_id');
         // Get the custom ISPConfig attribute set in the customer control panel
         if (is_numeric($customAttribute['value'])) {
             /**
              * Client_id (IspConfig Attribute Set in ShineISP database in the setup of the panel)
              * @see Shineisp_Controller_Plugin_SetupcPanelsModules
              */
             $clientId = $customAttribute['value'];
             $record = $client->client_get($this->getSession(), $clientId);
             if ($record == false) {
                 $clientId = "";
             }
         }
         // Customer Profile
         $record['company_name'] = $customer['company'];
         $record['contact_name'] = $customer['firstname'] . " " . $customer['lastname'];
         $record['customer_no'] = $customer['customer_id'];
         $record['vat_id'] = $customer['vat'];
         $record['email'] = $customer['email'];
         $record['street'] = !empty($customer['Addresses'][0]['address']) ? $customer['Addresses'][0]['address'] : "";
         $record['zip'] = !empty($customer['Addresses'][0]['code']) ? $customer['Addresses'][0]['code'] : "";
         $record['city'] = !empty($customer['Addresses'][0]['city']) ? $customer['Addresses'][0]['city'] : "";
         $record['state'] = !empty($customer['Addresses'][0]['area']) ? $customer['Addresses'][0]['area'] : "";
         $record['country'] = !empty($customer['Addresses'][0]['Countries']['code']) ? $customer['Addresses'][0]['Countries']['code'] : "";
         $record['mobile'] = Contacts::getContact($customer['customer_id'], "Mobile");
         $record['fax'] = Contacts::getContact($customer['customer_id'], "Fax");
         $record['telephone'] = Contacts::getContact($customer['customer_id']);
         // System Configuration
         $languagecode = Languages::get_code($customer['language_id']);
         $record['language'] = $languagecode;
         $record['usertheme'] = "default";
         $record['template_master'] = 0;
         $record['template_additional'] = "";
         $record['created_at'] = date('');
         $record['web_php_options'] = "no,fast-cgi,cgi,mod,suphp,php-fpm";
         $record['ssh_chroot'] = 'jailkit';
         // Get the Json encoded parameters in the task
         $parameters = json_decode($task['parameters'], true);
         // Match all the ShineISP product system attribute and IspConfig attributes (see below about info)
         $retval = self::matchFieldsValues($parameters, $record);
         if (is_array($retval)) {
             $record = array_merge($record, $retval);
         } else {
             Shineisp_Commons_Utilities::logs("No hosting attribute parameters have been set in ShineISP. Check the hosting product attributes section.", "ispconfig.log");
         }
         // Execute the SOAP action
         if (!empty($clientId) && is_numeric($clientId)) {
             $client->client_update($this->getSession(), $clientId, 1, $record);
         } else {
             $arrUsernames = array();
             $arrUsernames = self::generateUsernames($customer);
             // Check if username is available
             foreach ($arrUsernames as $username) {
                 if (!$client->client_get_by_username($this->getSession(), $username)) {
                     break;
                 }
             }
             // Create a random password string
             $password = Shineisp_Commons_Utilities::GenerateRandomString();
             $record['username'] = $username;
             $record['password'] = $password;
             // Save the setup in the service setup field
             OrdersItems::set_setup($task['orderitem_id'], array('url' => 'http://' . $server['ip'] . ':8080', 'username' => $username, 'password' => $password), "webpanel");
             // Adding the client in ISPConfig
             $clientId = $client->client_add($this->getSession(), 0, $record);
             // Update the custom customer attribute client_id
             CustomAttributes::saveElementsValues(array(array('client_id' => $clientId)), $task['customer_id'], "customers");
             // Execute a custom event
             $this->events()->trigger('panels_create_client_after', __CLASS__, array('task' => $task, 'clientid' => $clientId, 'customerdata' => $record));
         }
         // Create the log message
         Shineisp_Commons_Utilities::logs("ID: " . $task['action_id'] . " - " . __METHOD__ . " - Parameters: " . json_encode($record), "ispconfig.log");
         // Logout from the IspConfig Remote System
         $client->logout($this->getSession());
         return $clientId;
     } catch (Exception $e) {
         Shineisp_Commons_Utilities::logs(__METHOD__ . ": " . $e->getMessage());
         echo $e->getMessage();
     }
 }
Beispiel #11
0
 /**
  * print the invoice
  * @param unknown_type $invoiceid
  */
 public static function PrintPDF($invoice_id, $show = true, $force = false, $path = "/documents/invoices/")
 {
     $currency = Shineisp_Registry::getInstance()->Zend_Currency;
     $pdf = new Shineisp_Commons_PdfOrder();
     if (!is_numeric($invoice_id)) {
         return false;
     }
     $invoice = Invoices::find($invoice_id);
     if (!$invoice) {
         return false;
     }
     $invoice = $invoice->toArray();
     // Set the basepath for the file
     $Order = Doctrine::getTable('Orders')->findOneBy('order_id', $invoice['order_id']);
     $invoicePath = $path . $Order->isp_id . '/' . str_replace('-', '/', $invoice['invoice_id']);
     // Set the name of the file
     $filename = $invoicePath . '/' . $invoice['invoice_id'] . ".pdf";
     $filenameOld = $path . $invoice['invoice_date'] . " - " . $invoice['number'] . ".pdf";
     // 			Invoice already exists, we return it
     if ((file_exists(PUBLIC_PATH . $filename) || file_exists(PUBLIC_PATH . $filenameOld)) && $show && !$force) {
         $outputFilename = !empty($invoice['formatted_number']) ? $invoice['formatted_number'] . ".pdf" : $invoice['invoice_date'] . "_" . $invoice['number'] . ".pdf";
         header('Content-type: application/pdf');
         header('Content-Disposition: attachment; filename="' . $outputFilename . '"');
         $invoice = file_exists(PUBLIC_PATH . $filename) ? file_get_contents(PUBLIC_PATH . $filename) : file_get_contents(PUBLIC_PATH . $filenameOld);
         die($invoice);
     }
     $translator = Shineisp_Registry::getInstance()->Zend_Translate;
     $payments = Payments::findbyorderid($invoice['order_id'], null, true);
     $order = Orders::getAllInfo($invoice['order_id'], null, true);
     $database['header']['label'] = $translator->translate('Invoice No.') . " " . (!empty($invoice['formatted_number']) ? $invoice['formatted_number'] : $database['records']['invoice_number']) . " - " . Shineisp_Commons_Utilities::formatDateOut($invoice['invoice_date']);
     $database['columns'][] = array("value" => $translator->translate("SKU"), "size" => 20, "align" => "left", "key" => "sku");
     $database['columns'][] = array("value" => $translator->translate("Description"), "size" => 65, "align" => "left", "key" => "description");
     $database['columns'][] = array("value" => $translator->translate("Qty"), "size" => 2, "align" => "right", "key" => "qty");
     $database['columns'][] = array("value" => $translator->translate("Unit"), "size" => 12, "align" => "left", "key" => "unit");
     $database['columns'][] = array("value" => $translator->translate("Tax Free Price"), "size" => 9, "align" => "right", "key" => "taxfreeprice");
     $database['columns'][] = array("value" => $translator->translate("Discount"), "size" => 10, "align" => "right", "key" => "discount");
     $database['columns'][] = array("value" => $translator->translate("Setup fee"), "size" => 15, "align" => "right", "key" => "setup");
     $database['columns'][] = array("value" => $translator->translate("Total"), "size" => 18, "align" => "right", "key" => "total");
     if (isset($order[0])) {
         $orderinfo['order_number'] = !empty($order[0]['order_number']) ? $order[0]['order_number'] : Orders::formatOrderId($order[0]['order_id']);
         $orderinfo['invoice_id'] = $invoice['number'];
         $orderinfo['date'] = Shineisp_Commons_Utilities::formatDateOut($invoice['invoice_date']);
         //if customer comes from reseller
         if ($order[0]['Customers']['parent_id']) {
             $invoice_dest = Customers::getAllInfo($order[0]['Customers']['parent_id'], 'c.*, a.*');
             $orderinfo['customer']['customer_id'] = $invoice_dest['customer_id'];
             $orderinfo['customer']['company'] = $invoice_dest['company'];
             $orderinfo['customer']['firstname'] = $invoice_dest['firstname'];
             $orderinfo['customer']['lastname'] = $invoice_dest['lastname'];
             $orderinfo['customer']['vat'] = $invoice_dest['vat'];
             $orderinfo['customer']['taxpayernumber'] = $invoice_dest['taxpayernumber'];
             $orderinfo['customer']['email'] = $invoice_dest['email'];
             if (isset($invoice_dest['Addresses'][0])) {
                 $orderinfo['customer']['address'] = $invoice_dest['Addresses'][0]['address'];
                 $orderinfo['customer']['city'] = $invoice_dest['Addresses'][0]['city'];
                 $orderinfo['customer']['code'] = $invoice_dest['Addresses'][0]['code'];
                 $orderinfo['customer']['country'] = !empty($invoice_dest['Addresses'][0]['Countries']['name']) ? $invoice_dest['Addresses'][0]['Countries']['name'] : "";
             }
         } else {
             $orderinfo['customer']['customer_id'] = $order[0]['Customers']['customer_id'];
             $orderinfo['customer']['company'] = $order[0]['Customers']['company'];
             $orderinfo['customer']['firstname'] = $order[0]['Customers']['firstname'];
             $orderinfo['customer']['lastname'] = $order[0]['Customers']['lastname'];
             $orderinfo['customer']['vat'] = $order[0]['Customers']['vat'];
             $orderinfo['customer']['taxpayernumber'] = $order[0]['Customers']['taxpayernumber'];
             $orderinfo['customer']['email'] = $order[0]['Customers']['email'];
             if (isset($order[0]['Customers']['Addresses'][0])) {
                 $orderinfo['customer']['address'] = $order[0]['Customers']['Addresses'][0]['address'];
                 $orderinfo['customer']['city'] = $order[0]['Customers']['Addresses'][0]['city'];
                 $orderinfo['customer']['code'] = $order[0]['Customers']['Addresses'][0]['code'];
                 $orderinfo['customer']['country'] = $order[0]['Customers']['Addresses'][0]['Countries']['name'];
             }
         }
         $orderinfo['payments'] = array();
         if (count($payments) > 0) {
             if ($payments > 1) {
                 $numPayment = 1;
                 foreach ($payments as $payment) {
                     if ($numPayment++ > 10) {
                         break;
                     }
                     $payment['paymentdate'] = Shineisp_Commons_Utilities::formatDateOut($payment['paymentdate']);
                     $payment['income'] = $currency->toCurrency($payment['income'], array('currency' => Settings::findbyParam('currency')));
                     $orderinfo['payments'][] = $payment;
                 }
             }
             $orderinfo['payment_date'] = Shineisp_Commons_Utilities::formatDateOut($payments[0]['paymentdate']);
             $orderinfo['payment_mode'] = $payments[0]['Banks']['name'];
             $orderinfo['payment_description'] = $payments[0]['description'];
             $orderinfo['payment_transaction_id'] = $payments[0]['reference'];
         }
         $orderinfo['invoice_number'] = $invoice['number'];
         $orderinfo['company']['name'] = $order[0]['Isp']['company'];
         $orderinfo['company']['manager'] = $order[0]['Isp']['manager'];
         $orderinfo['company']['vat'] = $order[0]['Isp']['vatnumber'];
         $orderinfo['company']['bankname'] = $order[0]['Isp']['bankname'];
         $orderinfo['company']['iban'] = $order[0]['Isp']['iban'];
         $orderinfo['company']['bic'] = $order[0]['Isp']['bic'];
         $orderinfo['company']['address'] = $order[0]['Isp']['address'];
         $orderinfo['company']['zip'] = $order[0]['Isp']['zip'];
         $orderinfo['company']['city'] = $order[0]['Isp']['city'];
         $orderinfo['company']['country'] = $order[0]['Isp']['country'];
         $orderinfo['company']['telephone'] = $order[0]['Isp']['telephone'];
         $orderinfo['company']['fax'] = $order[0]['Isp']['fax'];
         $orderinfo['company']['website'] = $order[0]['Isp']['website'];
         $orderinfo['company']['email'] = $order[0]['Isp']['email'];
         $orderinfo['company']['slogan'] = $order[0]['Isp']['slogan'];
         $orderinfo['company']['custom1'] = $order[0]['Isp']['custom1'];
         $orderinfo['company']['custom2'] = $order[0]['Isp']['custom2'];
         $orderinfo['company']['custom3'] = $order[0]['Isp']['custom3'];
         $orderinfo['subtotal'] = $currency->toCurrency($order[0]['total'], array('currency' => Settings::findbyParam('currency')));
         $orderinfo['grandtotal'] = $currency->toCurrency($order[0]['grandtotal'], array('currency' => Settings::findbyParam('currency')));
         $orderinfo['vat'] = $currency->toCurrency($order[0]['vat'], array('currency' => Settings::findbyParam('currency')));
         $orderinfo['delivery'] = 0;
         if ($order[0]['status_id'] == Statuses::id("tobepaid", "orders")) {
             // To be payed
             $orderinfo['ribbon']['text'] = $translator->translate("To be Paid");
             $orderinfo['ribbon']['color'] = "#D60000";
         } elseif ($order[0]['status_id'] == Statuses::id("paid", "orders")) {
             // Paid
             $orderinfo['ribbon']['text'] = $translator->translate("Paid");
             $orderinfo['ribbon']['color'] = "#009926";
         } elseif ($order[0]['status_id'] == Statuses::id("complete", "orders")) {
             // Complete
             $orderinfo['ribbon']['text'] = $translator->translate("Complete");
             $orderinfo['ribbon']['color'] = "#009926";
         } else {
             $orderinfo['ribbon']['text'] = $translator->translate(Statuses::getLabel($order[0]['status_id']));
             $orderinfo['ribbon']['color'] = "#FFCC33";
         }
         $database['records'] = $orderinfo;
         foreach ($order[0]['OrdersItems'] as $item) {
             $billingCycle = BillingCycle::getAllinfo($item['billing_cycle_id']);
             if (!empty($billingCycle)) {
                 if (!empty($billingCycle['months']) && empty($item['tld_id'])) {
                     $price = $item['price'] * $billingCycle['months'] + $item['setupfee'];
                 } else {
                     $price = $item['price'] + $item['setupfee'];
                 }
             } else {
                 $price = $item['price'] * $item['quantity'] + $item['setupfee'];
             }
             $rowtotal = $price + $item['vat'];
             $item['price'] = $currency->toCurrency($item['price'], array('currency' => Settings::findbyParam('currency')));
             $item['setupfee'] = $currency->toCurrency($item['setupfee'], array('currency' => Settings::findbyParam('currency')));
             $rowtotal = $currency->toCurrency($rowtotal, array('currency' => Settings::findbyParam('currency')));
             if (!empty($item['discount'])) {
                 $item['discount'] = $item['discount'] . "%";
             }
             if (!empty($billingCycle['name']) && empty($item['tld_id'])) {
                 $item['date_end'] = Shineisp_Commons_Utilities::formatDateOut($item['date_end']);
                 $billingCycleName = $billingCycle['name'];
                 $item['description'] .= "<br/><br/> - " . $translator->translate('Expiring date') . ": " . $item['date_end'];
             } else {
                 $billingCycleName = "-";
             }
             // 					var_dump($item);
             $database['records']['items'][] = array($item['Products']['sku'], $item['description'], $item['quantity'], $billingCycleName, $item['price'], $item['discount'], $item['setupfee'], $rowtotal);
         }
         // 				var_dump($database['records']);
         // 				die;
         // Sanitize some fields
         $database['records']['invoice_number'] = !empty($database['records']['invoice_number']) ? $database['records']['invoice_number'] : "";
         $database['records']['formatted_number'] = !empty($invoice['formatted_number']) ? $invoice['formatted_number'] : $database['records']['invoice_number'];
         $database['records']['payment_description'] = !empty($database['records']['payment_description']) ? $database['records']['payment_description'] : "";
         $database['records']['payment_mode'] = !empty($database['records']['payment_mode']) ? $database['records']['payment_mode'] : "";
         $database['records']['payment_date'] = !empty($database['records']['payment_date']) ? $database['records']['payment_date'] : "";
         $database['records']['totalPayments'] = count($database['records']['payments']);
         // QRCode Image
         $code['order'] = $database['records']['order_number'];
         $code['customer'] = $database['records']['customer']['customer_id'];
         $jcode = base64_encode(json_encode($code));
         $database['records']['qrcode_url'] = $_SERVER['HTTP_HOST'] . "/index/qrcode/q/" . $jcode;
         $database['records']['skip_barcode'] = 1;
         if (!empty($database['records']['invoice_number'])) {
             $database['records']['barcode'] = $database['records']['invoice_number'];
             $database['records']['skip_barcode'] = 0;
         }
         if (isset($order[0])) {
             // Create the path structure
             if (!is_dir(PUBLIC_PATH . $invoicePath)) {
                 mkdir(PUBLIC_PATH . $invoicePath, 0700, true);
             }
             // Template name
             $templateName = Settings::findByParam('invoice_template');
             if (empty($templateName)) {
                 $templateName = Shineisp_Commons_Utilities::getFirstFile(PUBLIC_PATH . '/skins/commons/invoices', '/\\.phtml$/');
             }
             $invoiceview = new Shineisp_Invoice();
             $invoiceview->assign('header', $database['header']);
             $invoiceview->assign('columns', $database['columns']);
             $invoiceview->assign('data', $database['records']);
             $html = $invoiceview->render($templateName);
             $html2pdf = new HTML2PDF('P', 'A4', 'it', true, 'UTF-8', array(4, 4, 4, 1));
             $html2pdf->WriteHTML($html);
             $html2pdf->Output(PUBLIC_PATH . $filename, "F");
             // Execute a custom event
             self::events()->trigger('invoices_pdf_created', "Invoices", array('order' => $order, 'invoice' => $invoice, 'file' => $filename));
             return PUBLIC_PATH . $filename;
         }
     }
     return false;
 }
 /**
  * Add the customer in the newsletter
  * @param integer $customer_id
  */
 public static function customer_optOut($customer_id)
 {
     $customer = Customers::getAllInfo($customer_id, "email");
     $subscriber = Doctrine::getTable('NewslettersSubscribers')->findOneBy('email', $customer['email']);
     if ($subscriber) {
         $subscriber->delete();
         return true;
     } else {
         return false;
     }
 }