/** * __construct * @param integer $orderid * @return array */ public function __construct($orderid) { $order = Orders::getAllInfo($orderid, 'o.*, oi.*, c.*', true); $this->orderid = $orderid; if (!empty($order[0])) { $this->order = $order[0]; } $this->translator = Shineisp_Registry::getInstance()->Zend_Translate; }
/** * QrCode Invoice Order Management */ public function qrcodeAction() { $qrcode = $this->getRequest()->getParam('q'); if (!empty($qrcode)) { $decoded = base64_decode($qrcode); if (!empty($decoded)) { $data = json_decode($decoded, true); if (is_array($data)) { if (!empty($data['customer'])) { $this->view->customer = Customers::find($data['customer']); $this->view->order = Orders::getAllInfo($data['order'], null, true); } } } } }
public static function CreateDomainsbyOrderID($orderid) { $domains = array(); if (is_numeric($orderid)) { // Get the order information $order = Orders::getAllInfo($orderid, "o.*, oi.*", true); // Get the order items if (!empty($order[0]['OrdersItems'])) { // Get all the order products $products = $order[0]['OrdersItems']; if (is_array($products) && count($products) > 0) { // For each product in order foreach ($products as $product) { // If it is a domain product if (is_numeric($product['tld_id'])) { // Get the additional parameters in the order item record $parameters = !empty($product['parameters']) ? json_decode($product['parameters'], true) : array(); // If the parameters are present go on... if (count($parameters) > 0) { // Get the Authcode for the domains that need the transfer action $authcode = !empty($parameters['authcode']) ? $parameters['authcode'] : ""; // Create the domain found in the order $domainID = self::Create($parameters['domain'], $product['tld_id'], $order[0]['customer_id'], $product['detail_id'], 6, $authcode); // Attach the domain to the order OrdersItemsDomains::addDomain($orderid, $domainID); // Prepare the result domain ids list $domains[] = $domainID; } } } } } } return $domains; }
/** * renewdomainAction * Renew a group of domains selected * @param $items * @return void */ private function renewdomains($items) { $mex = ""; if (is_array($items)) { try { $Orderid = Orders::createOrderWithMultiProducts($items, $this->customer['customer_id']); $isp = Shineisp_Registry::get('ISP'); $order = Orders::getAllInfo($Orderid, null, true); $link = Fastlinks::findlinks($Orderid, $this->customer['customer_id'], 'orders'); $retval = Shineisp_Commons_Utilities::getEmailTemplate('new_order'); if ($retval) { $subject = $retval['subject']; $subject = str_replace("[orderid]", sprintf("%03s", $Orderid) . " - " . Shineisp_Commons_Utilities::formatDateOut($order[0]['order_date']), $subject); $orderbody = $retval['template']; $orderbody = str_replace("[fullname]", $order[0]['Customers']['firstname'] . " " . $order[0]['Customers']['lastname'], $orderbody); $orderbody = str_replace("[bank]", $isp->bankname . "\nc/c:" . $isp->bankaccount . "\nIBAN: " . $isp->iban . "\nBIC: " . $isp->bic, $orderbody); $orderbody = str_replace("[orderid]", $Orderid . "/" . date('Y'), $orderbody); $orderbody = str_replace("[email]", $isp->email, $orderbody); $orderbody = str_replace("[signature]", $isp->company . "\n" . $isp->email, $orderbody); if (!empty($link[0])) { $orderbody = str_replace("[url]", "http://" . $_SERVER['HTTP_HOST'] . "/index/link/id/" . $link[0]['code'], $orderbody); } else { $orderbody = str_replace("[url]", "http://" . $_SERVER['HTTP_HOST'], $orderbody); } if (!empty($order[0]['Customers']['email'])) { Shineisp_Commons_Utilities::SendEmail($isp->email, $order[0]['Customers']['email'], $isp->email, $subject, $orderbody); } } die(json_encode(array('reload' => '/orders/edit/id/' . $Orderid))); } catch (Exception $e) { die(json_encode(array('mex' => $e->getMessage()))); } } return false; }
/** * Process the response of the banks gateways * * @return void */ public function responseAction() { $request = $this->getRequest(); $response = $request->getParams(); if (!empty($response['custom']) && is_numeric(trim($response['custom']))) { $isp = Shineisp_Registry::get('ISP'); // Orderid back from the bank $order_id = trim($response['custom']); // Getting the md5 value in order to match with the class name. $classrequest = $request->gateway; // Get the bank selected using the MD5 code $bank = Banks::findbyMD5($classrequest); if (!empty($bank[0]['classname'])) { if (!empty($bank[0]['classname']) && class_exists($bank[0]['classname'])) { $class = $bank[0]['classname']; $payment = new $class($order_id); // Check if the method "Response" exists in the Payment class and send all the bank information to the payment module if (method_exists($class, "Response")) { $OrderID = $payment->Response($response); } else { $OrderID = false; } } } // Check if the OrderID is a number because it // means that the order has been executed correctly if (is_numeric($OrderID)) { // Sending an email to the customer and the administrator with the order details. $order = Orders::getAllInfo($OrderID, null, true); Shineisp_Commons_Utilities::sendEmailTemplate($order[0]['Customers']['email'], 'order_confirm', array('fullname' => $order[0]['Customers']['fullname'], 'orderid' => $OrderID, 'order' => $order), null, null, null, null, $order[0]['Customers']['language_id']); // Redirect the user in the The task requested has been executed successfully. page $this->_helper->redirector('list', 'orders', 'default', array('mex' => 'The task requested has been executed successfully.', 'status' => 'success')); } } $this->_helper->redirector('list', 'orders', 'default', array('mex' => 'There was a problem during the payment process.', 'status' => 'danger')); }
/** * 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; }
public function get($uuid, $order_uuid = null, $service_uuid = null) { $this->authenticate(); $customers = Customers::findWithUuid($uuid); if (empty($customers)) { throw new Shineisp_Api_Exceptions(400006, ":: 'uuid' not valid"); exit; } $id = $customers['customer_id']; if ($order_uuid == null && $service_uuid == null) { throw new Shineisp_Api_Exceptions(400006, ":: 'order_uuid' not valid and 'service_uuid' not valid"); } #TODO get order from $order_uuid if ($service_uuid != null) { $objService = OrdersItems::findByUUID($service_uuid); if ($objService == false) { return false; } $service = $objService->toArray(); $orderid = $service['order_id']; $fields = "o.order_id, \n \t\t o.order_number,\n DATE_FORMAT(o.order_date, '%d/%m/%Y') as Starting, \n DATE_FORMAT(o.expiring_date, '%d/%m/%Y') as Valid_Up, \n in.invoice_id as invoice_id, \n in.number as Invoice, \n CONCAT(d.domain, '.', w.tld) as Domain, \n c.company as company, \n o.status_id, \n s.status as Status, \n o.vat as VAT, \n o.total as Total, \n o.grandtotal as Grandtotal\n so.code as servStatus"; $rs = Orders::getAllInfo($orderid, "*", true, $id); if (empty($rs)) { throw new Shineisp_Api_Exceptions(404001, ":: Orders not found"); } return $rs; $currency = Shineisp_Registry::getInstance()->Zend_Currency; $result = array(); $order = array_shift($rs); // Check the status of the order. // If the order has to be paid we have update it to the last prices and taxes if ($order['status_id'] == Statuses::id('tobepaid', 'orders')) { // Update the total order Orders::updateTotalsOrder($orderid); // Reload the data $rs = Orders::getAllInfo($orderid, $fields, true, $id); $order = array_shift($rs); $order['Total'] = $currency->toCurrency($order['Total'], array('currency' => Settings::findbyParam('currency'))); $order['VAT'] = $currency->toCurrency($order['VAT'], array('currency' => Settings::findbyParam('currency'))); $order['Grandtotal'] = $currency->toCurrency($order['Grandtotal'], array('currency' => Settings::findbyParam('currency'))); $order['price'] = $order['Grandtotal']; $result['tobepaid'] = true; } $result['order'] = $order; $records = OrdersItems::getAllDetails($orderid, "oi.detail_id, oi.description as description, DATE_FORMAT(oi.date_end, '%d/%m/%Y') as expiration_date, oi.quantity as quantity, oi.price as price, bc.name as billingcycle, oi.setupfee as setupfee,p.autosetup as autosetup, s.code as statuscode", true); $allactive = false; for ($i = 0; $i < count($records); $i++) { $records[$i]['itemactiveonorder'] = false; if ($records[$i]['autosetup'] == 1) { $records[$i]['itemactiveonorder'] = true; $allactive = true; } else { $allactive = false; } $records[$i]['price'] = $currency->toCurrency($records[$i]['price'], array('currency' => Settings::findbyParam('currency'))); $records[$i]['setupfee'] = $currency->toCurrency($records[$i]['setupfee'], array('currency' => Settings::findbyParam('currency'))); } $result['activeonorder'] = $allactive; $result['orderitems'] = $records; $result['invoidid'] = $order['status_id'] == Statuses::id("complete", "orders") && $order['Invoice'] > 0 ? true : false; $result['invoidnumber'] = $order['Invoice']; $result['invoidid'] = $order['invoice_id']; $result['payments'] = ""; if ($result['tobepaid'] == true) { $result['payments'] = array(); $banks = Banks::findAllActive("classname", true); if (!empty($banks)) { foreach ($banks as $bank) { if (!empty($bank['classname']) && class_exists($bank['classname'])) { if (class_exists($bank['classname'])) { $class = $bank['classname']; $payment = new $class($id); $payment->setUrlOk($_SERVER['HTTP_HOST'] . "/orders/response/gateway/" . md5($bank['classname'])); $payment->setUrlKo($_SERVER['HTTP_HOST'] . "/orders/response/gateway/" . md5($bank['classname'])); $payment->setUrlCallback($_SERVER['HTTP_HOST'] . "/common/callback/gateway/" . md5($bank['classname'])); $result['payments'][] = $payment->CreateForm(); } } } } } return $result; } }