order_overview.php

Go to the documentation of this file.
00001 <?php
00002 
00008 class Order_Overview extends oxAdminDetails
00009 {
00010 
00018     public function render()
00019     {
00020         $myConfig = $this->getConfig();
00021         parent::render();
00022 
00023         $oOrder = oxNew("oxOrder");
00024         $oCur = $myConfig->getActShopCurrencyObject();
00025         $oLang = oxRegistry::getLang();
00026 
00027         $soxId = $this->getEditObjectId();
00028         if ($soxId != "-1" && isset($soxId)) {
00029             // load object
00030             $oOrder->load($soxId);
00031 
00032             $this->_aViewData["edit"] = $oOrder;
00033             $this->_aViewData["aProductVats"] = $oOrder->getProductVats();
00034             $this->_aViewData["orderArticles"] = $oOrder->getOrderArticles();
00035             $this->_aViewData["giftCard"] = $oOrder->getGiftCard();
00036             $this->_aViewData["paymentType"] = $this->_getPaymentType($oOrder);
00037             $this->_aViewData["deliveryType"] = $oOrder->getDelSet();
00038             $sTsProtectsField = 'oxorder__oxtsprotectcosts';
00039             if ($oOrder->$sTsProtectsField->value) {
00040                 $this->_aViewData["tsprotectcosts"] = $oLang->formatCurrency($oOrder->$sTsProtectsField->value, $oCur);
00041             }
00042         }
00043 
00044         // orders today
00045         $dSum = $oOrder->getOrderSum(true);
00046         $this->_aViewData["ordersum"] = $oLang->formatCurrency($dSum, $oCur);
00047         $this->_aViewData["ordercnt"] = $oOrder->getOrderCnt(true);
00048 
00049         // ALL orders
00050         $dSum = $oOrder->getOrderSum();
00051         $this->_aViewData["ordertotalsum"] = $oLang->formatCurrency($dSum, $oCur);
00052         $this->_aViewData["ordertotalcnt"] = $oOrder->getOrderCnt();
00053         $this->_aViewData["afolder"] = $myConfig->getConfigParam('aOrderfolder');
00054         $this->_aViewData["alangs"] = $oLang->getLanguageNames();
00055 
00056         $this->_aViewData["currency"] = $oCur;
00057 
00058         return "order_overview.tpl";
00059     }
00060 
00070     protected function _getPaymentType($oOrder)
00071     {
00072         if (!($oUserPayment = $oOrder->getPaymentType()) && $oOrder->oxorder__oxpaymenttype->value) {
00073             $oPayment = oxNew("oxPayment");
00074             if ($oPayment->load($oOrder->oxorder__oxpaymenttype->value)) {
00075                 // in case due to security reasons payment info was not kept in db
00076                 $oUserPayment = oxNew("oxUserPayment");
00077                 $oUserPayment->oxpayments__oxdesc = new oxField($oPayment->oxpayments__oxdesc->value);
00078             }
00079         }
00080 
00081         return $oUserPayment;
00082     }
00083 
00087     public function exportlex()
00088     {
00089         $sOrderNr = oxRegistry::getConfig()->getRequestParameter("ordernr");
00090         $sToOrderNr = oxRegistry::getConfig()->getRequestParameter("toordernr");
00091         $oImex = oxNew("oximex");
00092         if (($sLexware = $oImex->exportLexwareOrders($sOrderNr, $sToOrderNr))) {
00093             $oUtils = oxRegistry::getUtils();
00094             $oUtils->setHeader("Pragma: public");
00095             $oUtils->setHeader("Cache-Control: must-revalidate, post-check=0, pre-check=0");
00096             $oUtils->setHeader("Expires: 0");
00097             $oUtils->setHeader("Content-type: application/x-download");
00098             $oUtils->setHeader("Content-Length: " . strlen($sLexware));
00099             $oUtils->setHeader("Content-Disposition: attachment; filename=intern.xml");
00100             $oUtils->showMessageAndExit($sLexware);
00101         }
00102     }
00103 
00111     public function makeValidFileName($sFilename)
00112     {
00113         $sFilename = preg_replace('/[\s]+/', '_', $sFilename);
00114         $sFilename = preg_replace('/[^a-zA-Z0-9_\.-]/', '', $sFilename);
00115 
00116         return str_replace(' ', '_', $sFilename);
00117     }
00118 
00124     public function createPDF()
00125     {
00126         $soxId = $this->getEditObjectId();
00127         if ($soxId != "-1" && isset($soxId)) {
00128             // load object
00129             $oOrder = oxNew("oxorder");
00130             if ($oOrder->load($soxId)) {
00131                 $oUtils = oxRegistry::getUtils();
00132                 $sTrimmedBillName = trim($oOrder->oxorder__oxbilllname->getRawValue());
00133                 $sFilename = $oOrder->oxorder__oxordernr->value . "_" . $sTrimmedBillName . ".pdf";
00134                 $sFilename = $this->makeValidFileName($sFilename);
00135                 ob_start();
00136                 $oOrder->genPDF($sFilename, oxRegistry::getConfig()->getRequestParameter("pdflanguage"));
00137                 $sPDF = ob_get_contents();
00138                 ob_end_clean();
00139                 $oUtils->setHeader("Pragma: public");
00140                 $oUtils->setHeader("Cache-Control: must-revalidate, post-check=0, pre-check=0");
00141                 $oUtils->setHeader("Expires: 0");
00142                 $oUtils->setHeader("Content-type: application/pdf");
00143                 $oUtils->setHeader("Content-Disposition: attachment; filename=" . $sFilename);
00144                 oxRegistry::getUtils()->showMessageAndExit($sPDF);
00145             }
00146         }
00147     }
00148 
00149 
00153     public function sendorder()
00154     {
00155         $oOrder = oxNew("oxorder");
00156         if ($oOrder->load($this->getEditObjectId())) {
00157             $oOrder->oxorder__oxsenddate = new oxField(date("Y-m-d H:i:s", oxRegistry::get("oxUtilsDate")->getTime()));
00158             $oOrder->save();
00159 
00160             // #1071C
00161             $oOrderArticles = $oOrder->getOrderArticles();
00162             foreach ($oOrderArticles as $sOxid => $oArticle) {
00163                 // remove canceled articles from list
00164                 if ($oArticle->oxorderarticles__oxstorno->value == 1) {
00165                     $oOrderArticles->offsetUnset($sOxid);
00166                 }
00167             }
00168 
00169             if (($blMail = oxRegistry::getConfig()->getRequestParameter("sendmail"))) {
00170                 // send eMail
00171                 $oEmail = oxNew("oxemail");
00172                 $oEmail->sendSendedNowMail($oOrder);
00173             }
00174         }
00175     }
00176 
00180     public function resetorder()
00181     {
00182         $oOrder = oxNew("oxorder");
00183         if ($oOrder->load($this->getEditObjectId())) {
00184             $oOrder->oxorder__oxsenddate = new oxField("0000-00-00 00:00:00");
00185             $oOrder->save();
00186         }
00187     }
00188 
00194     public function canExport()
00195     {
00196         $blCan = false;
00197         //V #529: check if PDF invoice module is active
00198         $oModule = oxNew('oxmodule');
00199         $oModule->load('invoicepdf');
00200         if ($oModule->isActive()) {
00201             $oDb = oxDb::getDb();
00202             $sOrderId = $this->getEditObjectId();
00203             $sTable = getViewName("oxorderarticles");
00204             $sQ = "select count(oxid) from {$sTable} where oxorderid = " . $oDb->quote($sOrderId) . " and oxstorno = 0";
00205             $blCan = (bool) $oDb->getOne($sQ, false, false);
00206         }
00207 
00208         return $blCan;
00209     }
00210 
00216     public function canResetShippingDate()
00217     {
00218         $oOrder = oxNew("oxorder");
00219         $blCan = false;
00220         if ($oOrder->load($this->getEditObjectId())) {
00221             $blCan = $oOrder->oxorder__oxstorno->value == "0" &&
00222                      !($oOrder->oxorder__oxsenddate->value == "0000-00-00 00:00:00" || $oOrder->oxorder__oxsenddate->value == "-");
00223         }
00224 
00225         return $blCan;
00226     }
00227 }