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 = oxLang::getInstance();
00025 
00026         $soxId = oxConfig::getParameter( "oxid");
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["sfolder"] = $myConfig->getConfigParam( 'aOrderfolder' );
00053             $this->_aViewData["alangs"] = $oLang->getLanguageNames();
00054 
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 
00089     public function exportlex()
00090     {
00091         $sOrderNr   = oxConfig::getParameter( "ordernr");
00092         $sToOrderNr = oxConfig::getParameter( "toordernr");
00093         $oImex = oxNew( "oximex" );
00094         if ( ( $sLexware = $oImex->exportLexwareOrders( $sOrderNr, $sToOrderNr ) ) ) {
00095             $oUtils = oxUtils::getInstance();
00096             $oUtils->setHeader( "Pragma: public" );
00097             $oUtils->setHeader( "Cache-Control: must-revalidate, post-check=0, pre-check=0" );
00098             $oUtils->setHeader( "Expires: 0" );
00099             $oUtils->setHeader( "Content-type: application/x-download" );
00100             $oUtils->setHeader( "Content-Length: ".strlen( $sLexware ) );
00101             $oUtils->setHeader( "Content-Disposition: attachment; filename=intern.xml" );
00102             $oUtils->showMessageAndExit( $sLexware );
00103         }
00104     }
00110     public function createPDF()
00111     {
00112         $soxId = oxConfig::getParameter( "oxid" );
00113         if ( $soxId != "-1" && isset( $soxId ) ) {
00114             // load object
00115             $oOrder = oxNew( "oxorder" );
00116             if ( $oOrder->load( $soxId ) ) {
00117                 $oUtils = oxUtils::getInstance();
00118                 $sFilename = $oOrder->oxorder__oxordernr->value . "_" . $oOrder->oxorder__oxbilllname->getRawValue() . ".pdf";
00119 
00120                 ob_start();
00121                 $oOrder->genPDF( $sFilename, oxConfig::getParameter( "pdflanguage" ) );
00122                 $sPDF = ob_get_contents();
00123                 ob_end_clean();
00124 
00125                 $oUtils->setHeader( "Pragma: public" );
00126                 $oUtils->setHeader( "Cache-Control: must-revalidate, post-check=0, pre-check=0" );
00127                 $oUtils->setHeader( "Expires: 0" );
00128                 $oUtils->setHeader( "Content-type: application/pdf" );
00129                 $oUtils->setHeader( "Content-Disposition: attachment; filename=".$sFilename );
00130                 oxUtils::getInstance()->showMessageAndExit( $sPDF );
00131             }
00132         }
00133     }
00134 
00140     public function exportDTAUS()
00141     {
00142         $oOrderList = oxNew( "oxlist" );
00143         $oOrderList->init( "oxorder" );
00144         $sSelect =  "select * from oxorder where oxpaymenttype = 'oxiddebitnote'";
00145 
00146         if ( ( $iFromOrderNr = oxConfig::getParameter( "ordernr") ) ) {
00147             $sSelect .= " and oxordernr >= $iFromOrderNr";
00148         }
00149 
00150         $oOrderList->selectString( $sSelect );
00151         if ( count( $oOrderList ) ) {
00152             $oUserPayment = oxNew( "oxuserpayment" );
00153             $oUtils = oxUtils::getInstance();
00154             $oShop  = $this->getConfig()->getActiveShop();
00155 
00156             $sCompany   = $oShop->oxshops__oxcompany->value;
00157             $sRoutingNr = $this->_cleanup( $oShop->oxshops__oxbankcode->value ) + 1 - 1;
00158             $sAccountNr = $this->_cleanup( $oShop->oxshops__oxbanknumber->value );
00159             $sSubject   = oxLang::getInstance()->translateString( "order" );
00160 
00161             // can't be called with oxnew, as it only supports single constructor parameter
00162             $oDtaus = oxNew( "oxDtausBuilder", $sCompany, $sRoutingNr, $sAccountNr );
00163             foreach ( $oOrderList as $oOrder ) {
00164                 $oUserPayment->load( $oOrder->oxorder__oxpaymentid->value );
00165                 $aDynValues = $oUtils->assignValuesFromText( $oUserPayment->oxuserpayments__oxvalue->value );
00166 
00167                 $sCustName  = $aDynValues[3]->value;
00168                 $sRoutingNr = $this->_cleanup( $aDynValues[1]->value );
00169                 $sAccountNr = $this->_cleanup( $aDynValues[2]->value );
00170 
00171                 $oDtaus->add( $sCustName, $sRoutingNr, $sAccountNr, $oOrder->getTotalOrderSum(), array( $oShop->oxshops__oxname->getRawValue(), $sSubject . " " . $oOrder->oxorder__oxordernr->value ) );
00172             }
00173 
00174             $oUtils->setHeader( "Content-Disposition: attachment; filename=\"dtaus0.txt\"" );
00175             $oUtils->setHeader( "Content-type: text/plain" );
00176             $oUtils->setHeader( "Cache-control: public" );
00177             $oUtils->showMessageAndExit( $oDtaus->create() );
00178         }
00179     }
00180 
00188     protected function _cleanup( $sValue )
00189     {
00190         return str_replace( " ", "", $sValue );
00191     }
00192 
00198     public function sendorder()
00199     {
00200         $oOrder = oxNew( "oxorder" );
00201         if ( $oOrder->load( oxConfig::getParameter( "oxid" ) ) ) {
00202             $oOrder->oxorder__oxsenddate->setValue( date( "Y-m-d H:i:s", oxUtilsDate::getInstance()->getTime() ) );
00203             $oOrder->save();
00204 
00205             // #1071C
00206             $oOrderArticles = $oOrder->getOrderArticles();
00207             foreach ( $oOrderArticles as $sOxid => $oArticle ) {
00208                 // remove canceled articles from list
00209                 if ( $oArticle->oxorderarticles__oxstorno->value == 1 ) {
00210                     $oOrderArticles->offsetUnset( $sOxid );
00211                 }
00212             }
00213 
00214             if ( ( $blMail = oxConfig::getParameter( "sendmail" ) ) ) {
00215                 // send eMail
00216                 $oEmail = oxNew( "oxemail" );
00217                 $oEmail->sendSendedNowMail( $oOrder );
00218             }
00219         }
00220     }
00221 
00227     public function resetorder()
00228     {
00229         $oOrder = oxNew( "oxorder" );
00230         if ( $oOrder->load( oxConfig::getParameter( "oxid" ) ) ) {
00231             $oOrder->oxorder__oxsenddate->setValue( "0000-00-00 00:00:00" );
00232             $oOrder->save();
00233         }
00234     }
00235 
00241     public function canExport()
00242     {
00243         $blCan = false;
00244         //V #529: check if PDF invoice module is active
00245         if ( oxUtilsObject::getInstance()->isModuleActive( 'oxorder', 'myorder' ) ) {
00246             $oDb = oxDb::getDb();
00247             $sOrderId = oxConfig::getParameter( "oxid" );
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 );
00251         }
00252         return $blCan;
00253     }
00254 }