order_overview.php

Go to the documentation of this file.
00001 <?php
00002 
00008 class Order_Overview extends oxAdminDetails
00009 {
00017     public function render()
00018     {
00019         $myConfig = $this->getConfig();
00020         parent::render();
00021 
00022         $oOrder = oxNew( "oxOrder" );
00023         $oCur  = $myConfig->getActShopCurrencyObject();
00024         $oLang = oxRegistry::getLang();
00025 
00026         $soxId = $this->getEditObjectId();
00027         if ( $soxId != "-1" && isset( $soxId)) {
00028             // load object
00029             $oOrder->load( $soxId);
00030 
00031             $this->_aViewData["edit"]          = $oOrder;
00032             $this->_aViewData["aProductVats"]  = $oOrder->getProductVats();
00033             $this->_aViewData["orderArticles"] = $oOrder->getOrderArticles();
00034             $this->_aViewData["giftCard"]      = $oOrder->getGiftCard();
00035             $this->_aViewData["paymentType"]   = $this->_getPaymentType( $oOrder );
00036             $this->_aViewData["deliveryType"]  = $oOrder->getDelSet();
00037             if ( $oOrder->oxorder__oxtsprotectcosts->value ) {
00038                 $this->_aViewData["tsprotectcosts"]  = $oLang->formatCurrency( $oOrder->oxorder__oxtsprotectcosts->value, $oCur);
00039             }
00040         }
00041 
00042         // orders today
00043         $dSum  = $oOrder->getOrderSum(true);
00044         $this->_aViewData["ordersum"] = $oLang->formatCurrency($dSum, $oCur);
00045         $this->_aViewData["ordercnt"] = $oOrder->getOrderCnt(true);
00046 
00047         // ALL orders
00048         $dSum = $oOrder->getOrderSum();
00049         $this->_aViewData["ordertotalsum"] = $oLang->formatCurrency( $dSum, $oCur);
00050         $this->_aViewData["ordertotalcnt"] = $oOrder->getOrderCnt();
00051         $this->_aViewData["afolder"] = $myConfig->getConfigParam( 'aOrderfolder' );
00052             $this->_aViewData["alangs"] = $oLang->getLanguageNames();
00053 
00054         $this->_aViewData["currency"] = $oCur;
00055 
00056         return "order_overview.tpl";
00057     }
00058 
00068     protected function _getPaymentType( $oOrder )
00069     {
00070         if ( !( $oUserPayment = $oOrder->getPaymentType() ) && $oOrder->oxorder__oxpaymenttype->value ) {
00071             $oPayment = oxNew( "oxPayment" );
00072             if ( $oPayment->load( $oOrder->oxorder__oxpaymenttype->value ) ) {
00073                 // in case due to security reasons payment info was not kept in db
00074                 $oUserPayment = oxNew( "oxUserPayment" );
00075                 $oUserPayment->oxpayments__oxdesc = new oxField( $oPayment->oxpayments__oxdesc->value );
00076             }
00077         }
00078 
00079         return $oUserPayment;
00080     }
00081 
00087     public function exportlex()
00088     {
00089         $sOrderNr   = oxConfig::getParameter( "ordernr");
00090         $sToOrderNr = oxConfig::getParameter( "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     }
00108     public function createPDF()
00109     {
00110         $soxId = $this->getEditObjectId();
00111         if ( $soxId != "-1" && isset( $soxId ) ) {
00112             // load object
00113             $oOrder = oxNew( "oxorder" );
00114             if ( $oOrder->load( $soxId ) ) {
00115                 $oUtils = oxRegistry::getUtils();
00116                 $sTrimmedBillName = trim($oOrder->oxorder__oxbilllname->getRawValue());
00117                 $sFilename = $oOrder->oxorder__oxordernr->value . "_" . $sTrimmedBillName . ".pdf";
00118                 $sFilename = str_replace(" ", "_", $sFilename);
00119                 ob_start();
00120                 $oOrder->genPDF( $sFilename, oxConfig::getParameter( "pdflanguage" ) );
00121                 $sPDF = ob_get_contents();
00122                 ob_end_clean();
00123                 $oUtils->setHeader( "Pragma: public" );
00124                 $oUtils->setHeader( "Cache-Control: must-revalidate, post-check=0, pre-check=0" );
00125                 $oUtils->setHeader( "Expires: 0" );
00126                 $oUtils->setHeader( "Content-type: application/pdf" );
00127                 $oUtils->setHeader( "Content-Disposition: attachment; filename=".$sFilename );
00128                 oxRegistry::getUtils()->showMessageAndExit( $sPDF );
00129             }
00130         }
00131     }
00132 
00138     public function exportDTAUS()
00139     {
00140         $oOrderList = oxNew( "oxList" );
00141         $oOrderList->init( "oxOrder" );
00142         $sSelect =  "select * from oxorder where oxpaymenttype = 'oxiddebitnote'";
00143 
00144         if ( ( $iFromOrderNr = oxConfig::getParameter( "ordernr") ) ) {
00145             $sSelect .= " and oxordernr >= $iFromOrderNr";
00146         }
00147 
00148         $oOrderList->selectString( $sSelect );
00149         if ( count( $oOrderList ) ) {
00150             $oUserPayment = oxNew( "oxUserPayment" );
00151             $oUtils = oxRegistry::getUtils();
00152             $oShop  = $this->getConfig()->getActiveShop();
00153 
00154             $sCompany   = $oShop->oxshops__oxcompany->value;
00155             $sRoutingNr = $this->_cleanup( $oShop->oxshops__oxbankcode->value ) + 1 - 1;
00156             $sAccountNr = $this->_cleanup( $oShop->oxshops__oxbanknumber->value );
00157             $sSubject   = oxRegistry::getLang()->translateString( "order" );
00158 
00159             // can't be called with oxnew, as it only supports single constructor parameter
00160             $oDtaus = oxNew( "oxDtausBuilder", $sCompany, $sRoutingNr, $sAccountNr );
00161             foreach ( $oOrderList as $oOrder ) {
00162                 $oUserPayment->load( $oOrder->oxorder__oxpaymentid->value );
00163                 $aDynValues = $oUtils->assignValuesFromText( $oUserPayment->oxuserpayments__oxvalue->value );
00164 
00165                 $sCustName  = $aDynValues[3]->value;
00166                 $sRoutingNr = $this->_cleanup( $aDynValues[1]->value );
00167                 $sAccountNr = $this->_cleanup( $aDynValues[2]->value );
00168 
00169                 $oDtaus->add( $sCustName, $sRoutingNr, $sAccountNr, $oOrder->getTotalOrderSum(), array( $oShop->oxshops__oxname->getRawValue(), $sSubject . " " . $oOrder->oxorder__oxordernr->value ) );
00170             }
00171 
00172             $oUtils->setHeader( "Content-Disposition: attachment; filename=\"dtaus0.txt\"" );
00173             $oUtils->setHeader( "Content-type: text/plain" );
00174             $oUtils->setHeader( "Cache-control: public" );
00175             $oUtils->showMessageAndExit( $oDtaus->create() );
00176         }
00177     }
00178 
00186     protected function _cleanup( $sValue )
00187     {
00188         return str_replace( " ", "", $sValue );
00189     }
00190 
00196     public function sendorder()
00197     {
00198         $oOrder = oxNew( "oxorder" );
00199         if ( $oOrder->load( $this->getEditObjectId() ) ) {
00200             $oOrder->oxorder__oxsenddate = new oxField( date( "Y-m-d H:i:s", oxRegistry::get("oxUtilsDate")->getTime() ) );
00201             $oOrder->save();
00202 
00203             // #1071C
00204             $oOrderArticles = $oOrder->getOrderArticles();
00205             foreach ( $oOrderArticles as $sOxid => $oArticle ) {
00206                 // remove canceled articles from list
00207                 if ( $oArticle->oxorderarticles__oxstorno->value == 1 ) {
00208                     $oOrderArticles->offsetUnset( $sOxid );
00209                 }
00210             }
00211 
00212             if ( ( $blMail = oxConfig::getParameter( "sendmail" ) ) ) {
00213                 // send eMail
00214                 $oEmail = oxNew( "oxemail" );
00215                 $oEmail->sendSendedNowMail( $oOrder );
00216             }
00217         }
00218     }
00219 
00225     public function resetorder()
00226     {
00227         $oOrder = oxNew( "oxorder" );
00228         if ( $oOrder->load( $this->getEditObjectId() ) ) {
00229             $oOrder->oxorder__oxsenddate = new oxField( "0000-00-00 00:00:00" );
00230             $oOrder->save();
00231         }
00232     }
00233 
00239     public function canExport()
00240     {
00241         $blCan = false;
00242         //V #529: check if PDF invoice module is active
00243         $oModule = oxNew('oxmodule');
00244         $oModule->load('invoicepdf');
00245         if ( $oModule->isActive() ) {
00246             $oDb = oxDb::getDb();
00247             $sOrderId = $this->getEditObjectId();
00248             $sTable = getViewName( "oxorderarticles" );
00249             $sQ = "select count(oxid) from {$sTable} where oxorderid = ".$oDb->quote( $sOrderId )." and oxstorno = 0";
00250             $blCan = (bool) $oDb->getOne( $sQ, false, false );
00251         }
00252         return $blCan;
00253     }
00254 
00260     public function canResetShippingDate()
00261     {
00262         $oOrder = oxNew( "oxorder" );
00263         $blCan = false;
00264         if ( $oOrder->load( $this->getEditObjectId() ) ) {
00265             $blCan = $oOrder->oxorder__oxstorno->value == "0" &&
00266                      !( $oOrder->oxorder__oxsenddate->value == "0000-00-00 00:00:00" || $oOrder->oxorder__oxsenddate->value == "-" );
00267         }
00268         return $blCan;
00269     }
00270 }