예제 #1
0
 function createInvoiceNumber($orderDetails, &$invoiceNumber)
 {
     $orderDetails = (array) $orderDetails;
     $db = JFactory::getDBO();
     if (!isset($orderDetails['virtuemart_order_id'])) {
         vmWarn('createInvoiceNumber $orderDetails has no virtuemart_order_id ', $orderDetails);
         vmdebug('createInvoiceNumber $orderDetails has no virtuemart_order_id ', $orderDetails);
     }
     $q = 'SELECT * FROM `#__virtuemart_invoices` WHERE `virtuemart_order_id`= "' . $orderDetails['virtuemart_order_id'] . '" ';
     // AND `order_status` = "'.$orderDetails->order_status.'" ';
     $db->setQuery($q);
     $result = $db->loadAssoc();
     // 		vmdebug('my createInvoiceNumber $q '.$q,$result);
     if (!class_exists('ShopFunctions')) {
         require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'shopfunctions.php';
     }
     if (!$result or empty($result['invoice_number'])) {
         $data['virtuemart_order_id'] = $orderDetails['virtuemart_order_id'];
         $data['order_status'] = $orderDetails['order_status'];
         $data['virtuemart_vendor_id'] = $orderDetails['virtuemart_vendor_id'];
         JPluginHelper::importPlugin('vmshopper');
         JPluginHelper::importPlugin('vmpayment');
         $dispatcher = JDispatcher::getInstance();
         // plugin returns invoice number, 0 if it does not want an invoice number to be created by Vm
         $plg_datas = $dispatcher->trigger('plgVmOnUserInvoice', array($orderDetails, &$data));
         foreach ($plg_datas as $plg_data) {
             // 				$data = array_merge($plg_data,$data);
         }
         if (!isset($data['invoice_number'])) {
             // check the default configuration
             $orderstatusForInvoice = VmConfig::get('inv_os', array());
             if (!is_array($orderstatusForInvoice)) {
                 $orderstatusForInvoice = array($orderstatusForInvoice);
             }
             //for backward compatibility 2.0.8e
             $pdfInvoice = (int) VmConfig::get('pdf_invoice', 0);
             // backwards compatible
             $force_create_invoice = JRequest::getInt('create_invoice', 0);
             // florian : added if pdf invoice are enabled
             if (in_array($orderDetails['order_status'], $orderstatusForInvoice) or $pdfInvoice == 1 or $force_create_invoice == 1) {
                 $q = 'SELECT COUNT(1) FROM `#__virtuemart_invoices` WHERE `virtuemart_vendor_id`= "' . $orderDetails['virtuemart_vendor_id'] . '" ';
                 // AND `order_status` = "'.$orderDetails->order_status.'" ';
                 $db->setQuery($q);
                 $count = $db->loadResult() + 1;
                 if (empty($data['invoice_number'])) {
                     //$variable_fixed=sprintf("%05s",$num_rows);
                     $date = date("Y-m-d");
                     // 					$date = JFactory::getDate()->toMySQL();
                     $data['invoice_number'] = str_replace('-', '', substr($date, 2, 8)) . substr(md5($orderDetails['order_number'] . $orderDetails['order_status']), 0, 3) . '0' . $count;
                 }
             } else {
                 return false;
             }
         }
         $table = $this->getTable('invoices');
         $table->bindChecknStore($data);
         $invoiceNumber = array($table->invoice_number, $table->created_on);
     } elseif (ShopFunctions::InvoiceNumberReserved($result['invoice_number'])) {
         $invoiceNumber = array($result['invoice_number'], $result['created_on']);
         return true;
     } else {
         $invoiceNumber = array($result['invoice_number'], $result['created_on']);
     }
     return true;
 }
예제 #2
0
 public function display($tpl = null)
 {
     $document = JFactory::getDocument();
     VmConfig::loadJLang('com_virtuemart_shoppers', true);
     //We never want that the cart is indexed
     $document->setMetaData('robots', 'NOINDEX, NOFOLLOW, NOARCHIVE, NOSNIPPET');
     if (empty($this->uselayout)) {
         $layout = JRequest::getWord('layout', 'mail');
     } else {
         $layout = $this->uselayout;
     }
     switch ($layout) {
         case 'invoice':
             $this->doctype = $layout;
             $title = JText::_('COM_VIRTUEMART_INVOICE');
             break;
         case 'deliverynote':
             $this->doctype = $layout;
             $layout = 'invoice';
             $title = JText::_('COM_VIRTUEMART_DELIVERYNOTE');
             break;
         case 'confirmation':
             $this->doctype = $layout;
             $layout = 'confirmation';
             $title = JText::_('COM_VIRTUEMART_CONFIRMATION');
             break;
         case 'mail':
             if (VmConfig::get('order_mail_html')) {
                 $layout = 'mail_html';
             } else {
                 $layout = 'mail_raw';
             }
     }
     $this->setLayout($layout);
     $tmpl = JRequest::getWord('tmpl');
     $print = false;
     if ($tmpl) {
         $print = true;
     }
     $this->assignRef('print', $print);
     $this->format = JRequest::getWord('format', 'html');
     if ($layout == 'invoice') {
         $document->setTitle(JText::_('COM_VIRTUEMART_INVOICE'));
     }
     $order_print = false;
     if ($print and $this->format == 'html') {
         $order_print = true;
     }
     $orderModel = VmModel::getModel('orders');
     $orderDetails = $this->orderDetails;
     if ($orderDetails == 0) {
         $orderDetails = $orderModel->getMyOrderDetails();
         if (!$orderDetails or empty($orderDetails['details'])) {
             echo JText::_('COM_VIRTUEMART_CART_ORDER_NOTFOUND');
             return;
         }
     }
     if (empty($orderDetails['details'])) {
         echo JText::_('COM_VIRTUEMART_ORDER_NOTFOUND');
         return 0;
     }
     if (!empty($orderDetails['details']['BT']->order_language)) {
         $jlang = JFactory::getLanguage();
         $jlang->load('com_virtuemart', JPATH_SITE, $orderDetails['details']['BT']->order_language, true);
         $jlang->load('com_virtuemart_shoppers', JPATH_SITE, $orderDetails['details']['BT']->order_language, true);
         $jlang->load('com_virtuemart_orders', JPATH_SITE, $orderDetails['details']['BT']->order_language, true);
     }
     $this->assignRef('orderDetails', $orderDetails);
     // if it is order print, invoice number should not be created, either it is there, either it has not been created
     if (empty($this->invoiceNumber) and !$order_print) {
         $invoiceNumberDate = array();
         if ($orderModel->createInvoiceNumber($orderDetails['details']['BT'], $invoiceNumberDate)) {
             if (ShopFunctions::InvoiceNumberReserved($invoiceNumberDate[0])) {
                 if ($this->uselayout != 'mail') {
                     $document->setTitle(JText::_('COM_VIRTUEMART_PAYMENT_INVOICE'));
                     return;
                 }
             }
             $this->invoiceNumber = $invoiceNumberDate[0];
             $this->invoiceDate = $invoiceNumberDate[1];
             if (!$this->invoiceNumber or empty($this->invoiceNumber)) {
                 vmError('Cant create pdf, createInvoiceNumber failed');
                 if ($this->uselayout != 'mail') {
                     return;
                 }
             }
         } else {
             // Could OR should not create Invoice Number, createInvoiceNumber failed
             if ($this->uselayout != 'mail') {
                 return;
             }
         }
     }
     //Todo multix
     $vendorId = 1;
     $emailCurrencyId = $orderDetails['details']['BT']->user_currency_id;
     $exchangeRate = FALSE;
     if (!class_exists('vmPSPlugin')) {
         require JPATH_VM_PLUGINS . DS . 'vmpsplugin.php';
     }
     JPluginHelper::importPlugin('vmpayment');
     $dispatcher = JDispatcher::getInstance();
     $dispatcher->trigger('plgVmgetEmailCurrency', array($orderDetails['details']['BT']->virtuemart_paymentmethod_id, $orderDetails['details']['BT']->virtuemart_order_id, &$emailCurrencyId));
     if (!class_exists('CurrencyDisplay')) {
         require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'currencydisplay.php';
     }
     $currency = CurrencyDisplay::getInstance($emailCurrencyId, $vendorId);
     if ($emailCurrencyId) {
         $currency->exchangeRateShopper = $orderDetails['details']['BT']->user_currency_rate;
     }
     $this->assignRef('currency', $currency);
     //Create BT address fields
     $userFieldsModel = VmModel::getModel('userfields');
     $_userFields = $userFieldsModel->getUserFields('account', array('captcha' => true, 'delimiters' => true), array('delimiter_userinfo', 'user_is_vendor', 'username', 'password', 'password2', 'agreed', 'address_type'));
     $userfields = $userFieldsModel->getUserFieldsFilled($_userFields, $orderDetails['details']['BT']);
     $this->assignRef('userfields', $userfields);
     //Create ST address fields
     $orderst = array_key_exists('ST', $orderDetails['details']) ? $orderDetails['details']['ST'] : $orderDetails['details']['BT'];
     $shipmentFieldset = $userFieldsModel->getUserFields('shipment', array(), array('delimiter_userinfo', 'username', 'email', 'password', 'password2', 'agreed', 'address_type'));
     $shipmentfields = $userFieldsModel->getUserFieldsFilled($shipmentFieldset, $orderst);
     $this->assignRef('shipmentfields', $shipmentfields);
     $civility = "";
     foreach ($userfields['fields'] as $field) {
         if ($field['name'] == "title") {
             $civility = $field['value'];
             break;
         }
     }
     $company = empty($orderDetails['details']['BT']->company) ? "" : $orderDetails['details']['BT']->company . ", ";
     $shopperName = $company . $civility . ' ' . $orderDetails['details']['BT']->first_name . ' ' . $orderDetails['details']['BT']->last_name;
     $this->assignRef('shopperName', $shopperName);
     $this->assignRef('civility', $civility);
     // Create an array to allow orderlinestatuses to be translated
     // We'll probably want to put this somewhere in ShopFunctions..
     $orderStatusModel = VmModel::getModel('orderstatus');
     $_orderstatuses = $orderStatusModel->getOrderStatusList();
     $orderstatuses = array();
     foreach ($_orderstatuses as $_ordstat) {
         $orderstatuses[$_ordstat->order_status_code] = JText::_($_ordstat->order_status_name);
     }
     $this->assignRef('orderstatuslist', $orderstatuses);
     $this->assignRef('orderstatuses', $orderstatuses);
     $_itemStatusUpdateFields = array();
     $_itemAttributesUpdateFields = array();
     foreach ($orderDetails['items'] as $_item) {
         // 			$_itemStatusUpdateFields[$_item->virtuemart_order_item_id] = JHTML::_('select.genericlist', $orderstatuses, "item_id[".$_item->virtuemart_order_item_id."][order_status]", 'class="selectItemStatusCode"', 'order_status_code', 'order_status_name', $_item->order_status, 'order_item_status'.$_item->virtuemart_order_item_id,true);
         $_itemStatusUpdateFields[$_item->virtuemart_order_item_id] = $_item->order_status;
     }
     if (empty($orderDetails['shipmentName'])) {
         if (!class_exists('vmPSPlugin')) {
             require JPATH_VM_PLUGINS . DS . 'vmpsplugin.php';
         }
         JPluginHelper::importPlugin('vmshipment');
         $dispatcher = JDispatcher::getInstance();
         $returnValues = $dispatcher->trigger('plgVmOnShowOrderFEShipment', array($orderDetails['details']['BT']->virtuemart_order_id, $orderDetails['details']['BT']->virtuemart_shipmentmethod_id, &$orderDetails['shipmentName']));
     }
     if (empty($orderDetails['paymentName'])) {
         if (!class_exists('vmPSPlugin')) {
             require JPATH_VM_PLUGINS . DS . 'vmpsplugin.php';
         }
         JPluginHelper::importPlugin('vmpayment');
         $dispatcher = JDispatcher::getInstance();
         $returnValues = $dispatcher->trigger('plgVmOnShowOrderFEPayment', array($orderDetails['details']['BT']->virtuemart_order_id, $orderDetails['details']['BT']->virtuemart_paymentmethod_id, &$orderDetails['paymentName']));
     }
     $virtuemart_vendor_id = 1;
     $vendorModel = VmModel::getModel('vendor');
     $vendor = $vendorModel->getVendor($virtuemart_vendor_id);
     $vendorModel->addImages($vendor);
     $vendor->vendorFields = $vendorModel->getVendorAddressFields();
     if (VmConfig::get('enable_content_plugin', 0)) {
         if (!class_exists('shopFunctionsF')) {
             require JPATH_VM_SITE . DS . 'helpers' . DS . 'shopfunctionsf.php';
         }
         shopFunctionsF::triggerContentPlugin($vendor, 'vendor', 'vendor_store_desc');
         shopFunctionsF::triggerContentPlugin($vendor, 'vendor', 'vendor_terms_of_service');
         shopFunctionsF::triggerContentPlugin($vendor, 'vendor', 'vendor_legal_info');
     }
     $this->assignRef('vendor', $vendor);
     // 		vmdebug('vendor', $vendor);
     if (strpos($layout, 'mail') !== false) {
         $lineSeparator = "<br />";
     } else {
         $lineSeparator = "\n";
     }
     $this->assignRef('headFooter', $this->showHeaderFooter);
     //Attention, this function will be removed, it wont be deleted, but it is obsoloete in any view.html.php
     if (!class_exists('ShopFunctions')) {
         require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'shopfunctions.php';
     }
     $vendorAddress = shopFunctions::renderVendorAddress($virtuemart_vendor_id, $lineSeparator);
     $this->assignRef('vendorAddress', $vendorAddress);
     $vendorEmail = $vendorModel->getVendorEmail($virtuemart_vendor_id);
     $vars['vendorEmail'] = $vendorEmail;
     // this is no setting in BE to change the layout !
     //shopFunctionsF::setVmTemplate($this,0,0,$layoutName);
     //vmdebug('renderMailLayout invoice '.date('H:i:s'),$this->order);
     if (strpos($layout, 'mail') !== false) {
         if ($this->doVendor) {
             //Old text key COM_VIRTUEMART_MAIL_SUBJ_VENDOR_C
             $this->subject = JText::sprintf('COM_VIRTUEMART_MAIL_SUBJ_VENDOR_' . $orderDetails['details']['BT']->order_status, $this->shopperName, strip_tags($currency->priceDisplay($orderDetails['details']['BT']->order_total, $currency)), $orderDetails['details']['BT']->order_number);
             $recipient = 'vendor';
         } else {
             $this->subject = JText::sprintf('COM_VIRTUEMART_MAIL_SUBJ_SHOPPER_' . $orderDetails['details']['BT']->order_status, $vendor->vendor_store_name, strip_tags($currency->priceDisplay($orderDetails['details']['BT']->order_total, $currency)), $orderDetails['details']['BT']->order_number);
             $recipient = 'shopper';
         }
         $this->assignRef('recipient', $recipient);
     }
     $tpl = null;
     // 		vmdebug('my view data',$this->getLayout(),$layout);
     // 		ob_start();
     // 		echo '<pre>';
     // 		echo debug_print_backtrace();
     // 		echo '</pre>';
     // 		$dumptrace = ob_get_contents();
     // 		ob_end_clean();
     // 		return false;
     parent::display($tpl);
 }
 public function display($tpl = null)
 {
     $jinput = JFactory::getApplication()->input;
     $pdfTest = $jinput->get('print', 0, 'INT');
     if (empty($this->uselayout)) {
         $layout = JRequest::getWord('layout', 'mail');
     } else {
         $layout = $this->uselayout;
     }
     switch ($layout) {
         case 'invoice':
             $this->doctype = $layout;
             $title = JText::_('COM_VIRTUEMART_INVOICE');
             break;
         case 'deliverynote':
             $this->doctype = $layout;
             $layout = 'invoice';
             $title = JText::_('COM_VIRTUEMART_DELIVERYNOTE');
             break;
         case 'confirmation':
             $this->doctype = $layout;
             $layout = 'confirmation';
             $title = JText::_('COM_VIRTUEMART_CONFIRMATION');
             break;
         case 'mail':
             if (VmConfig::get('order_mail_html')) {
                 $layout = 'mail_html';
             } else {
                 $layout = 'mail_raw';
             }
     }
     $this->setLayout($layout);
     $tmpl = $jinput->get('tmpl', '', 'WORD');
     $this->print = false;
     if ($tmpl) {
         $this->print = true;
     }
     $this->format = $jinput->get('format', 'html', 'WORD');
     if ($layout == 'invoice') {
         $this->document->setTitle(JText::_('COM_VIRTUEMART_INVOICE'));
     }
     $order_print = false;
     if ($this->print and $this->format == 'html') {
         $order_print = true;
     }
     $orderModel = VmModel::getModel('orders');
     $orderDetails = $this->orderDetails;
     if ($orderDetails == 0) {
         $orderDetails = $orderModel->getMyOrderDetails();
         if (!$orderDetails or empty($orderDetails['details'])) {
             echo JText::_('COM_VIRTUEMART_CART_ORDER_NOTFOUND');
             return;
         }
     }
     if (empty($orderDetails['details'])) {
         echo JText::_('COM_VIRTUEMART_ORDER_NOTFOUND');
         return 0;
     }
     // if it is order print, invoice number should not be created, either it is there, either it has not been created
     if (empty($this->invoiceNumber) and !$order_print) {
         $invoiceNumberDate = array();
         if ($orderModel->createInvoiceNumber($orderDetails['details']['BT'], $invoiceNumberDate)) {
             if (ShopFunctions::InvoiceNumberReserved($invoiceNumberDate[0])) {
                 if ($this->uselayout != 'mail') {
                     $this->document->setTitle(JText::_('COM_VIRTUEMART_PAYMENT_INVOICE'));
                     return;
                 }
             }
             $this->invoiceNumber = $invoiceNumberDate[0];
             $this->invoiceDate = $invoiceNumberDate[1];
             if (!$this->invoiceNumber or empty($this->invoiceNumber)) {
                 vmError('Cant create pdf, createInvoiceNumber failed');
                 if ($this->uselayout != 'mail') {
                     return;
                 }
             }
         } else {
             // Could OR should not create Invoice Number, createInvoiceNumber failed
             if ($this->uselayout != 'mail') {
                 return;
             }
         }
     }
     $company = empty($orderDetails['details']['BT']->company) ? "" : $orderDetails['details']['BT']->company . ", ";
     $shopperName = $company . $orderDetails['details']['BT']->title . ' ' . $orderDetails['details']['BT']->first_name . ' ' . $orderDetails['details']['BT']->last_name;
     $this->shopperName = $shopperName;
     //Todo multix
     $vendorId = 1;
     $emailCurrencyId = 0;
     $exchangeRate = FALSE;
     JLoader::register('vmPSPlugin', JPATH_VM_PLUGINS . '/vmpsplugin.php');
     JPluginHelper::importPlugin('vmpayment');
     $dispatcher = JDispatcher::getInstance();
     $dispatcher->trigger('plgVmgetEmailCurrency', array($orderDetails['details']['BT']->virtuemart_paymentmethod_id, $orderDetails['details']['BT']->virtuemart_order_id, &$emailCurrencyId));
     JLoader::register('CurrencyDisplay', JPATH_VM_ADMINISTRATOR . '/helpers/currencydisplay.php');
     $currency = CurrencyDisplay::getInstance($emailCurrencyId, $vendorId);
     if ($emailCurrencyId) {
         $currency->exchangeRateShopper = $orderDetails['details']['BT']->user_currency_rate;
     }
     $this->currency = $currency;
     //Create BT address fields
     $userFieldsModel = VmModel::getModel('userfields');
     $_userFields = $userFieldsModel->getUserFields('account', array('captcha' => true, 'delimiters' => true), array('delimiter_userinfo', 'user_is_vendor', 'username', 'password', 'password2', 'agreed', 'address_type'));
     $userfields = $userFieldsModel->getUserFieldsFilled($_userFields, $orderDetails['details']['BT']);
     $this->userfields = $userfields;
     //Create ST address fields
     $orderst = array_key_exists('ST', $orderDetails['details']) ? $orderDetails['details']['ST'] : $orderDetails['details']['BT'];
     $shipmentFieldset = $userFieldsModel->getUserFields('shipment', array(), array('delimiter_userinfo', 'username', 'email', 'password', 'password2', 'agreed', 'address_type'));
     $this->shipmentfields = $userFieldsModel->getUserFieldsFilled($shipmentFieldset, $orderst);
     // Create an array to allow orderlinestatuses to be translated
     // We'll probably want to put this somewhere in ShopFunctions..
     $orderStatusModel = VmModel::getModel('orderstatus');
     $_orderstatuses = $orderStatusModel->getOrderStatusList();
     $orderstatuses = array();
     foreach ($_orderstatuses as $_ordstat) {
         $orderstatuses[$_ordstat->order_status_code] = JText::_($_ordstat->order_status_name);
     }
     $this->orderstatuslist = $orderstatuses;
     $this->orderstatuses = $orderstatuses;
     $_itemStatusUpdateFields = array();
     $_itemAttributesUpdateFields = array();
     foreach ($orderDetails['items'] as $_item) {
         // 			$_itemStatusUpdateFields[$_item->virtuemart_order_item_id] = JHTML::_('select.genericlist', $orderstatuses, "item_id[".$_item->virtuemart_order_item_id."][order_status]", 'class="selectItemStatusCode"', 'order_status_code', 'order_status_name', $_item->order_status, 'order_item_status'.$_item->virtuemart_order_item_id,true);
         $_itemStatusUpdateFields[$_item->virtuemart_order_item_id] = $_item->order_status;
     }
     if (empty($orderDetails['shipmentName'])) {
         JLoader::register('vmPSPlugin', JPATH_VM_PLUGINS . 'vmpsplugin.php');
         JPluginHelper::importPlugin('vmshipment');
         $dispatcher = JDispatcher::getInstance();
         $returnValues = $dispatcher->trigger('plgVmOnShowOrderFEShipment', array($orderDetails['details']['BT']->virtuemart_order_id, $orderDetails['details']['BT']->virtuemart_shipmentmethod_id, &$orderDetails['shipmentName']));
     }
     if (empty($orderDetails['paymentName'])) {
         JLoader::register('vmPSPlugin', JPATH_VM_PLUGINS . 'vmpsplugin.php');
         JPluginHelper::importPlugin('vmpayment');
         $dispatcher = JDispatcher::getInstance();
         $returnValues = $dispatcher->trigger('plgVmOnShowOrderFEPayment', array($orderDetails['details']['BT']->virtuemart_order_id, $orderDetails['details']['BT']->virtuemart_paymentmethod_id, &$orderDetails['paymentName']));
     }
     $virtuemart_vendor_id = 1;
     $vendorModel = VmModel::getModel('vendor');
     $this->vendor = $vendorModel->getVendor($virtuemart_vendor_id);
     $vendorModel->addImages($this->vendor);
     $this->vendor->vendorFields = $vendorModel->getVendorAddressFields();
     $tpl = null;
     if ($this->document->getType() === "pdf") {
         $tpl = 'pdf';
         $this->document->Set('Creator', 'Invoice by VirtueMart 2 Bootstrap');
         $this->document->Set('Author', $this->vendor->vendor_name);
         $this->document->Set('Title', JText::_('COM_VIRTUEMART_INVOICE_TITLE') . ' ' . $orderDetails['details']['BT']->order_number);
         $this->document->Set('Subject', JText::sprintf('COM_VIRTUEMART_INVOICE_SUBJ', $this->vendor->vendor_store_name, '', ''));
         $this->document->Set('Keywords', 'Invoice by VirtueMart 2');
         $this->document->setGenerator('Virtuemart 2 Bootstrap');
         $this->document->setTitle(JText::_('COM_VIRTUEMART_ORDER_PRINT_PO_NUMBER') . ' ' . $this->orderDetails['details']['BT']->order_number . ' ' . $this->vendor->vendor_store_name);
         $this->document->setName(JText::_('COM_VIRTUEMART_ACC_ORDER_INFO') . ' ' . $this->orderDetails['details']['BT']->order_number);
         $this->document->setDescription(JText::_('COM_VIRTUEMART_ORDER_PRINT_PO_NUMBER') . ' ' . $this->orderDetails['details']['BT']->order_number);
         if (empty($this->vendor->images[0])) {
             vmError('Vendor image given path empty ');
         } else {
             if (empty($this->vendor->images[0]->file_url_folder) or empty($this->vendor->images[0]->file_name) or empty($this->vendor->images[0]->file_extension)) {
                 vmError('Vendor image given image is not complete ' . $this->vendor->images[0]->file_url_folder . $this->vendor->images[0]->file_name . '.' . $this->vendor->images[0]->file_extension);
                 vmdebug('Vendor image given image is not complete, the given media', $this->vendor->images[0]);
             } else {
                 if (!empty($this->vendor->images[0]->file_extension) and strtolower($this->vendor->images[0]->file_extension) == 'png') {
                     vmError('Warning extension of the image is a png, tpcdf has problems with that in the header, choose a jpg or gif');
                 } else {
                     $imagePath = DS . str_replace('/', DS, $this->vendor->images[0]->file_url_folder . $this->vendor->images[0]->file_name . '.' . $this->vendor->images[0]->file_extension);
                     if (!file_exists(JPATH_ROOT . $imagePath)) {
                         vmError('Vendor image missing ' . $imagePath);
                     } else {
                         $this->document->Set('HeaderData', $imagePath, 60, $this->vendor->vendor_store_name, $this->vendorAddress);
                     }
                 }
             }
         }
         // set header and footer fonts
         $this->document->Set('HeaderFont', array('helvetica', '', 8));
         $this->document->Set('FooterFont', array('helvetica', '', 10));
         //TODO include the right file (in libraries/tcpdf/config/lang set some language-dependent strings
         $l = '';
         $this->document->Set('LanguageArray', $l);
         // set default font subsetting mode
         $this->document->Set('FontSubsetting', true);
         // Set font
         // dejavusans is a UTF-8 Unicode font, if you only need to
         // print standard ASCII chars, you can use core fonts like
         // helvetica or times to reduce file size.
         $this->document->Set('Font', 'helvetica', '', 8, '', true);
     }
     // 		vmdebug('vendor', $vendor);
     if (strpos($layout, 'mail') !== false) {
         $lineSeparator = "<br />";
     } else {
         $lineSeparator = "\n";
     }
     $this->headFooter = $this->showHeaderFooter;
     //Attention, this function will be removed, it wont be deleted, but it is obsoloete in any view.html.php
     JLoader::register('ShopFunctions', JPATH_VM_ADMINISTRATOR . '/helpers/shopfunctions.php');
     $this->vendorAddress = shopFunctions::renderVendorAddress($virtuemart_vendor_id, $lineSeparator);
     $vendorEmail = $vendorModel->getVendorEmail($virtuemart_vendor_id);
     $vars['vendorEmail'] = $vendorEmail;
     // this is no setting in BE to change the layout !
     //shopFunctionsF::setVmTemplate($this,0,0,$layoutName);
     //vmdebug('renderMailLayout invoice '.date('H:i:s'),$this->order);
     if (strpos($layout, 'mail') !== false) {
         if ($this->doVendor) {
             //Old text key COM_VIRTUEMART_MAIL_SUBJ_VENDOR_C
             $this->subject = JText::sprintf('COM_VIRTUEMART_MAIL_SUBJ_VENDOR_' . $orderDetails['details']['BT']->order_status, $this->shopperName, strip_tags($currency->priceDisplay($orderDetails['details']['BT']->order_total, $currency)), $orderDetails['details']['BT']->order_number);
             $recipient = 'vendor';
         } else {
             $this->subject = JText::sprintf('COM_VIRTUEMART_MAIL_SUBJ_SHOPPER_' . $orderDetails['details']['BT']->order_status, $vendor->vendor_store_name, strip_tags($currency->priceDisplay($orderDetails['details']['BT']->order_total, $currency)), $orderDetails['details']['BT']->order_number);
             $recipient = 'shopper';
         }
         $this->recipient = $recipient;
     }
     $this->orderDetails = $orderDetails;
     parent::display($tpl);
 }
예제 #4
0
 public function display($tpl = null)
 {
     $document = JFactory::getDocument();
     if (empty($this->uselayout)) {
         $layout = JRequest::getWord('layout', 'mail');
     } else {
         $layout = $this->uselayout;
     }
     if ($layout == 'mail') {
         if (VmConfig::get('order_mail_html')) {
             $layout = 'mail_html';
         } else {
             $layout = 'mail_raw';
         }
     }
     $this->setLayout($layout);
     $tmpl = JRequest::getWord('tmpl');
     $print = false;
     if ($tmpl) {
         $print = true;
     }
     $this->assignRef('print', $print);
     $this->format = JRequest::getWord('format', 'html');
     if ($layout == 'invoice') {
         $document->setTitle(JText::_('COM_VIRTUEMART_INVOICE'));
     }
     $order_print = false;
     if ($print and $this->format == 'html') {
         $order_print = true;
     }
     $orderModel = VmModel::getModel('orders');
     $orderDetails = $this->orderDetails;
     if ($orderDetails == 0) {
         // If the user is not logged in, we will check the order number and order pass
         if ($orderPass = JRequest::getString('order_pass', false) and $orderNumber = JRequest::getString('order_number', false)) {
             $orderId = $orderModel->getOrderIdByOrderPass($orderNumber, $orderPass);
             if (empty($orderId)) {
                 echo 'Invalid order_number/password ' . JText::_('COM_VIRTUEMART_RESTRICTED_ACCESS');
                 return 0;
             }
             $orderDetails = $orderModel->getOrder($orderId);
         }
         if ($orderDetails == 0) {
             $_currentUser = JFactory::getUser();
             $cuid = $_currentUser->get('id');
             // If the user is logged in, we will check if the order belongs to him
             $virtuemart_order_id = JRequest::getInt('virtuemart_order_id', 0);
             if (!$virtuemart_order_id) {
                 $virtuemart_order_id = VirtueMartModelOrders::getOrderIdByOrderNumber(JRequest::getString('order_number'));
             }
             $orderDetails = $orderModel->getOrder($virtuemart_order_id);
             if (!class_exists('Permissions')) {
                 require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'permissions.php';
             }
             if (!Permissions::getInstance()->check("admin")) {
                 if (!empty($orderDetails['details']['BT']->virtuemart_user_id)) {
                     if ($orderDetails['details']['BT']->virtuemart_user_id != $cuid) {
                         echo 'view ' . JText::_('COM_VIRTUEMART_RESTRICTED_ACCESS');
                         return;
                     }
                 }
             }
         }
     }
     if (empty($orderDetails['details'])) {
         echo JText::_('COM_VIRTUEMART_ORDER_NOTFOUND');
         return 0;
     }
     $this->assignRef('orderDetails', $orderDetails);
     // if it is order print, invoice number should not be created, either it is there, either it has not been created
     if (empty($this->invoiceNumber) and !$order_print) {
         $invoiceNumberDate = array();
         if ($orderModel->createInvoiceNumber($orderDetails['details']['BT'], $invoiceNumberDate)) {
             if (ShopFunctions::InvoiceNumberReserved($invoiceNumberDate[0])) {
                 if ($this->uselayout != 'mail') {
                     $document->setTitle(JText::_('COM_VIRTUEMART_PAYMENT_INVOICE'));
                     return;
                 }
             }
             $this->invoiceNumber = $invoiceNumberDate[0];
             $this->invoiceDate = $invoiceNumberDate[1];
             if (!$this->invoiceNumber or empty($this->invoiceNumber)) {
                 vmError('Cant create pdf, createInvoiceNumber failed');
                 if ($this->uselayout != 'mail') {
                     return;
                 }
             }
         } else {
             // Could OR should not create Invoice Number, createInvoiceNumber failed
             if ($this->uselayout != 'mail') {
                 return;
             }
         }
     }
     $company = empty($orderDetails['details']['BT']->company) ? "" : $orderDetails['details']['BT']->company . ", ";
     $shopperName = $company . $orderDetails['details']['BT']->title . ' ' . $orderDetails['details']['BT']->first_name . ' ' . $orderDetails['details']['BT']->last_name;
     $this->assignRef('shopperName', $shopperName);
     //Todo multix
     $vendorId = 1;
     $emailCurrencyId = 0;
     $exchangeRate = FALSE;
     if (!class_exists('vmPSPlugin')) {
         require JPATH_VM_PLUGINS . DS . 'vmpsplugin.php';
     }
     JPluginHelper::importPlugin('vmpayment');
     $dispatcher = JDispatcher::getInstance();
     $dispatcher->trigger('plgVmgetEmailCurrency', array($orderDetails['details']['BT']->virtuemart_paymentmethod_id, $orderDetails['details']['BT']->virtuemart_order_id, &$emailCurrencyId));
     if (!class_exists('CurrencyDisplay')) {
         require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'currencydisplay.php';
     }
     $currency = CurrencyDisplay::getInstance($emailCurrencyId, $vendorId);
     if ($emailCurrencyId) {
         $currency->exchangeRateShopper = $orderDetails['details']['BT']->user_currency_rate;
     }
     $this->assignRef('currency', $currency);
     //Create BT address fields
     $userFieldsModel = VmModel::getModel('userfields');
     $_userFields = $userFieldsModel->getUserFields('account', array('captcha' => true, 'delimiters' => true), array('delimiter_userinfo', 'user_is_vendor', 'username', 'password', 'password2', 'agreed', 'address_type'));
     $userfields = $userFieldsModel->getUserFieldsFilled($_userFields, $orderDetails['details']['BT']);
     $this->assignRef('userfields', $userfields);
     //Create ST address fields
     $orderst = array_key_exists('ST', $orderDetails['details']) ? $orderDetails['details']['ST'] : $orderDetails['details']['BT'];
     $shipmentFieldset = $userFieldsModel->getUserFields('shipment', array(), array('delimiter_userinfo', 'username', 'email', 'password', 'password2', 'agreed', 'address_type'));
     $shipmentfields = $userFieldsModel->getUserFieldsFilled($shipmentFieldset, $orderst);
     $this->assignRef('shipmentfields', $shipmentfields);
     // Create an array to allow orderlinestatuses to be translated
     // We'll probably want to put this somewhere in ShopFunctions..
     $orderStatusModel = VmModel::getModel('orderstatus');
     $_orderstatuses = $orderStatusModel->getOrderStatusList();
     $orderstatuses = array();
     foreach ($_orderstatuses as $_ordstat) {
         $orderstatuses[$_ordstat->order_status_code] = JText::_($_ordstat->order_status_name);
     }
     $this->assignRef('orderstatuslist', $orderstatuses);
     $this->assignRef('orderstatuses', $orderstatuses);
     $_itemStatusUpdateFields = array();
     $_itemAttributesUpdateFields = array();
     foreach ($orderDetails['items'] as $_item) {
         // 			$_itemStatusUpdateFields[$_item->virtuemart_order_item_id] = JHTML::_('select.genericlist', $orderstatuses, "item_id[".$_item->virtuemart_order_item_id."][order_status]", 'class="selectItemStatusCode"', 'order_status_code', 'order_status_name', $_item->order_status, 'order_item_status'.$_item->virtuemart_order_item_id,true);
         $_itemStatusUpdateFields[$_item->virtuemart_order_item_id] = $_item->order_status;
     }
     if (empty($orderDetails['shipmentName'])) {
         if (!class_exists('vmPSPlugin')) {
             require JPATH_VM_PLUGINS . DS . 'vmpsplugin.php';
         }
         JPluginHelper::importPlugin('vmshipment');
         $dispatcher = JDispatcher::getInstance();
         $returnValues = $dispatcher->trigger('plgVmOnShowOrderFEShipment', array($orderDetails['details']['BT']->virtuemart_order_id, $orderDetails['details']['BT']->virtuemart_shipmentmethod_id, &$orderDetails['shipmentName']));
     }
     if (empty($orderDetails['paymentName'])) {
         if (!class_exists('vmPSPlugin')) {
             require JPATH_VM_PLUGINS . DS . 'vmpsplugin.php';
         }
         JPluginHelper::importPlugin('vmpayment');
         $dispatcher = JDispatcher::getInstance();
         $returnValues = $dispatcher->trigger('plgVmOnShowOrderFEPayment', array($orderDetails['details']['BT']->virtuemart_order_id, $orderDetails['details']['BT']->virtuemart_paymentmethod_id, &$orderDetails['paymentName']));
     }
     $virtuemart_vendor_id = 1;
     $vendorModel = VmModel::getModel('vendor');
     $vendor = $vendorModel->getVendor($virtuemart_vendor_id);
     $vendorModel->addImages($vendor);
     $vendor->vendorFields = $vendorModel->getVendorAddressFields();
     $this->assignRef('vendor', $vendor);
     // 		vmdebug('vendor', $vendor);
     $task = JRequest::getWord('task', 0);
     if ($task == 'checkStoreInvoice') {
         $headFooter = false;
     } else {
         $headFooter = true;
     }
     if (strpos($layout, 'mail') !== false) {
         $lineSeparator = "<br />";
     } else {
         $lineSeparator = "\n";
     }
     $this->assignRef('headFooter', $headFooter);
     //Attention, this function will be removed, it wont be deleted, but it is obsoloete in any view.html.php
     if (!class_exists('ShopFunctions')) {
         require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'shopfunctions.php';
     }
     $vendorAddress = shopFunctions::renderVendorAddress($virtuemart_vendor_id, $lineSeparator);
     $this->assignRef('vendorAddress', $vendorAddress);
     $vendorEmail = $vendorModel->getVendorEmail($virtuemart_vendor_id);
     $vars['vendorEmail'] = $vendorEmail;
     // this is no setting in BE to change the layout !
     //shopFunctionsF::setVmTemplate($this,0,0,$layoutName);
     //vmdebug('renderMailLayout invoice '.date('H:i:s'),$this->order);
     if (strpos($layout, 'mail') !== false) {
         if ($this->doVendor) {
             //Old text key COM_VIRTUEMART_MAIL_SUBJ_VENDOR_C
             $this->subject = JText::sprintf('COM_VIRTUEMART_MAIL_SUBJ_VENDOR_' . $orderDetails['details']['BT']->order_status, $this->shopperName, strip_tags($currency->priceDisplay($orderDetails['details']['BT']->order_total)), $orderDetails['details']['BT']->order_number);
             $recipient = 'vendor';
         } else {
             $this->subject = JText::sprintf('COM_VIRTUEMART_MAIL_SUBJ_SHOPPER_' . $orderDetails['details']['BT']->order_status, $vendor->vendor_store_name, strip_tags($currency->priceDisplay($orderDetails['details']['BT']->order_total)), $orderDetails['details']['BT']->order_number);
             $recipient = 'shopper';
         }
         $this->assignRef('recipient', $recipient);
     }
     $tpl = null;
     // 		vmdebug('my view data',$this->getLayout(),$layout);
     // 		ob_start();
     // 		echo '<pre>';
     // 		echo debug_print_backtrace();
     // 		echo '</pre>';
     // 		$dumptrace = ob_get_contents();
     // 		ob_end_clean();
     // 		return false;
     parent::display($tpl);
 }
예제 #5
0
 function createInvoiceNumber($orderDetails, &$invoiceNumber)
 {
     $orderDetails = (array) $orderDetails;
     $db = JFactory::getDBO();
     if (!isset($orderDetails['tsmart_order_id'])) {
         vmWarn('createInvoiceNumber $orderDetails has no tsmart_order_id ', $orderDetails);
         vmdebug('createInvoiceNumber $orderDetails has no tsmart_order_id ', $orderDetails);
     }
     $q = 'SELECT * FROM `#__tsmart_invoices` WHERE `tsmart_order_id`= "' . $orderDetails['tsmart_order_id'] . '" ';
     // AND `order_status` = "'.$orderDetails->order_status.'" ';
     $db->setQuery($q);
     $result = $db->loadAssoc();
     if (!class_exists('ShopFunctions')) {
         require VMPATH_ADMIN . DS . 'helpers' . DS . 'shopfunctions.php';
     }
     if (!$result or empty($result['invoice_number'])) {
         $data['tsmart_order_id'] = $orderDetails['tsmart_order_id'];
         $data['order_status'] = $orderDetails['order_status'];
         $data['tsmart_vendor_id'] = $orderDetails['tsmart_vendor_id'];
         JPluginHelper::importPlugin('vmshopper');
         JPluginHelper::importPlugin('vmpayment');
         $dispatcher = JDispatcher::getInstance();
         // plugin returns invoice number, 0 if it does not want an invoice number to be created by Vm
         $plg_datas = $dispatcher->trigger('plgVmOnUserInvoice', array($orderDetails, &$data));
         if (!isset($data['invoice_number'])) {
             // check the default configuration
             $orderstatusForInvoice = tsmConfig::get('inv_os', array('C'));
             if (!is_array($orderstatusForInvoice)) {
                 $orderstatusForInvoice = array($orderstatusForInvoice);
             }
             //for backward compatibility 2.0.8e
             $pdfInvoice = (int) tsmConfig::get('pdf_invoice', 0);
             // backwards compatible
             $force_create_invoice = vRequest::getCmd('create_invoice', -1);
             // florian : added if pdf invoice are enabled
             if (in_array($orderDetails['order_status'], $orderstatusForInvoice) or $pdfInvoice == 1 or $force_create_invoice == $orderDetails['order_create_invoice_pass']) {
                 $q = 'SELECT COUNT(1) FROM `#__tsmart_invoices` WHERE `tsmart_vendor_id`= "' . $orderDetails['tsmart_vendor_id'] . '" ';
                 // AND `order_status` = "'.$orderDetails->order_status.'" ';
                 $db->setQuery($q);
                 $count = $db->loadResult() + 1;
                 if (empty($data['invoice_number'])) {
                     $date = date("Y-m-d");
                     if (!class_exists('tsmCrypt')) {
                         require VMPATH_ADMIN . DS . 'helpers' . DS . 'tsmcrypt.php';
                     }
                     $data['invoice_number'] = str_replace('-', '', substr($date, 2, 8)) . tsmCrypt::getHumanToken(4) . '0' . $count;
                 }
             } else {
                 return false;
             }
         }
         $table = $this->getTable('invoices');
         $table->bindChecknStore($data);
         $invoiceNumber = array($table->invoice_number, $table->created_on);
     } elseif (ShopFunctions::InvoiceNumberReserved($result['invoice_number'])) {
         $invoiceNumber = array($result['invoice_number'], $result['created_on']);
         return true;
     } else {
         $invoiceNumber = array($result['invoice_number'], $result['created_on']);
     }
     return true;
 }