order_overview.php

Go to the documentation of this file.
00001 <?php
00002 
00003     // DTAUS
00004     require_once "dtaus/class.DTAUS.php";
00005 
00011 class Order_Overview extends oxAdminDetails
00012 {
00020     public function render()
00021     {
00022         $myConfig = $this->getConfig();
00023         parent::render();
00024 
00025         $oOrder = oxNew( "oxorder" );
00026         $oCur  = $myConfig->getActShopCurrencyObject();
00027         $oLang = oxLang::getInstance();
00028 
00029         $soxId = oxConfig::getParameter( "oxid");
00030         if ( $soxId != "-1" && isset( $soxId)) {
00031             // load object
00032             $oOrder->load( $soxId);
00033 
00034             $this->_aViewData["edit"]          = $oOrder;
00035             $this->_aViewData["aProductVats"]  = $oOrder->getProductVats();
00036             $this->_aViewData["orderArticles"] = $oOrder->getOrderArticles();
00037             $this->_aViewData["giftCard"]      = $oOrder->getGiftCard();
00038             $this->_aViewData["paymentType"]   = $this->_getPaymentType( $oOrder );
00039             $this->_aViewData["deliveryType"]  = $oOrder->getDelSet();
00040             if ( $oOrder->oxorder__oxtsprotectcosts->value ) {
00041                 $this->_aViewData["tsprotectcosts"]  = $oLang->formatCurrency( $oOrder->oxorder__oxtsprotectcosts->value, $oCur);
00042             }
00043         }
00044 
00045         // orders today
00046         $dSum  = $oOrder->getOrderSum(true);
00047         $this->_aViewData["ordersum"] = $oLang->formatCurrency($dSum, $oCur);
00048         $this->_aViewData["ordercnt"] = $oOrder->getOrderCnt(true);
00049 
00050         // ALL orders
00051         $dSum = $oOrder->getOrderSum();
00052         $this->_aViewData["ordertotalsum"] = $oLang->formatCurrency( $dSum, $oCur);
00053         $this->_aViewData["ordertotalcnt"] = $oOrder->getOrderCnt();
00054         $this->_aViewData["afolder"] = $myConfig->getConfigParam( 'aOrderfolder' );
00055         $this->_aViewData["sfolder"] = $myConfig->getConfigParam( 'aOrderfolder' );
00056             $this->_aViewData["alangs"] = $oLang->getLanguageNames();
00057 
00058 
00059         $this->_aViewData["currency"] = $oCur;
00060 
00061         return "order_overview.tpl";
00062     }
00063 
00073     protected function _getPaymentType( $oOrder )
00074     {
00075         if ( !( $oUserPayment = $oOrder->getPaymentType() ) && $oOrder->oxorder__oxpaymenttype->value ) {
00076             $oPayment = oxNew( "oxpayment" );
00077             if ( $oPayment->load( $oOrder->oxorder__oxpaymenttype->value ) ) {
00078                 // in case due to security reasons payment info was not kept in db
00079                 $oUserPayment = oxNew( "oxuserpayment" );
00080                 $oUserPayment->oxpayments__oxdesc = new oxField( $oPayment->oxpayments__oxdesc->value );
00081             }
00082         }
00083 
00084         return $oUserPayment;
00085     }
00086 
00092     public function exportlex()
00093     {
00094         $sOrderNr   = oxConfig::getParameter( "ordernr");
00095         $sToOrderNr = oxConfig::getParameter( "toordernr");
00096         $oImex = oxNew( "oximex" );
00097         if ( ( $sLexware = $oImex->exportLexwareOrders( $sOrderNr, $sToOrderNr ) ) ) {
00098             $oUtils = oxUtils::getInstance();
00099             $oUtils->setHeader( "Pragma: public" );
00100             $oUtils->setHeader( "Cache-Control: must-revalidate, post-check=0, pre-check=0" );
00101             $oUtils->setHeader( "Expires: 0" );
00102             $oUtils->setHeader( "Content-type: application/x-download" );
00103             $oUtils->setHeader( "Content-Length: ".strlen( $sLexware ) );
00104             $oUtils->setHeader( "Content-Disposition: attachment; filename=intern.xml" );
00105             $oUtils->showMessageAndExit( $sLexware );
00106         }
00107     }
00113     public function createPDF()
00114     {
00115         $soxId = oxConfig::getParameter( "oxid" );
00116         if ( $soxId != "-1" && isset( $soxId ) ) {
00117             // load object
00118             $oOrder = oxNew( "oxorder" );
00119             if ( $oOrder->load( $soxId ) ) {
00120                 $oUtils = oxUtils::getInstance();
00121                 $sFilename = $oOrder->oxorder__oxordernr->value . "_" . $oOrder->oxorder__oxbilllname->getRawValue() . ".pdf";
00122 
00123                 ob_start();
00124                 $oOrder->genPDF( $sFilename, oxConfig::getParameter( "pdflanguage" ) );
00125                 $sPDF = ob_get_contents();
00126                 ob_end_clean();
00127 
00128                 $oUtils->setHeader( "Pragma: public" );
00129                 $oUtils->setHeader( "Cache-Control: must-revalidate, post-check=0, pre-check=0" );
00130                 $oUtils->setHeader( "Expires: 0" );
00131                 $oUtils->setHeader( "Content-type: application/pdf" );
00132                 $oUtils->setHeader( "Content-Disposition: attachment; filename=".$sFilename );
00133                 oxUtils::getInstance()->showMessageAndExit( $sPDF );
00134             }
00135         }
00136     }
00137 
00143     public function exportDTAUS()
00144     {
00145         $oOrderList = oxNew( "oxlist" );
00146         $oOrderList->init( "oxorder" );
00147         $sSelect =  "select * from oxorder where oxpaymenttype = 'oxiddebitnote'";
00148 
00149         if ( ( $iFromOrderNr = oxConfig::getParameter( "ordernr") ) ) {
00150             $sSelect .= " and oxordernr >= $iFromOrderNr";
00151         }
00152 
00153         $oOrderList->selectString( $sSelect );
00154         if ( count( $oOrderList ) ) {
00155             $oPayment = oxNew( "oxuserpayment" );
00156             $oShop = $this->getConfig()->getActiveShop();
00157             $oDtaus = new DTAUS( "L", $oShop->oxshops__oxcompany->value, str_replace( " ", "", $oShop->oxshops__oxbankcode->value), str_replace( " ", "", $oShop->oxshops__oxbanknumber->value ) );
00158 
00159             $oUtils = oxUtils::getInstance();
00160             $oLang  = oxLang::getInstance();
00161             foreach ( $oOrderList as $oOrder ) {
00162                 $oPayment->load( $oOrder->oxorder__oxpaymentid->value );
00163                 $aDynValues = $oUtils->assignValuesFromText( $oPayment->oxuserpayments__oxvalue->value );
00164                 $oDtaus->addTransaktion( $aDynValues[3]->value, str_replace( " ", "", $aDynValues[1]->value ), str_replace( " ", "", $aDynValues[2]->value ), str_replace( ",", ".", $oOrder->ftotalorder), $oShop->oxshops__oxname->getRawValue(), $oLang->translateString( "order" )." ".$oOrder->oxorder__oxordernr->value, "" );
00165             }
00166 
00167             $oUtils->setHeader( "Content-Disposition: attachment; filename=\"dtaus0.txt\"" );
00168             $oUtils->setHeader( "Content-type: text/plain" );
00169             $oUtils->setHeader( "Cache-control: public" );
00170             $oUtils->showMessageAndExit( $oDtaus->create() );
00171         }
00172     }
00173 
00179     public function sendorder()
00180     {
00181         $oOrder = oxNew( "oxorder" );
00182         if ( $oOrder->load( oxConfig::getParameter( "oxid" ) ) ) {
00183             $oOrder->oxorder__oxsenddate->setValue( date( "Y-m-d H:i:s", oxUtilsDate::getInstance()->getTime() ) );
00184             $oOrder->save();
00185 
00186             // #1071C
00187             $oOrderArticles = $oOrder->getOrderArticles();
00188             foreach ( $oOrderArticles as $sOxid => $oArticle ) {
00189                 // remove canceled articles from list
00190                 if ( $oArticle->oxorderarticles__oxstorno->value == 1 ) {
00191                     $oOrderArticles->offsetUnset( $sOxid );
00192                 }
00193             }
00194 
00195             if ( ( $blMail = oxConfig::getParameter( "sendmail" ) ) ) {
00196                 // send eMail
00197                 $oEmail = oxNew( "oxemail" );
00198                 $oEmail->sendSendedNowMail( $oOrder );
00199             }
00200         }
00201     }
00202 
00208     public function resetorder()
00209     {
00210         $oOrder = oxNew( "oxorder" );
00211         if ( $oOrder->load( oxConfig::getParameter( "oxid" ) ) ) {
00212             $oOrder->oxorder__oxsenddate->setValue( "0000-00-00 00:00:00" );
00213             $oOrder->save();
00214         }
00215     }
00216 
00222     public function canExport()
00223     {
00224         $blCan = false;
00225         //V #529: check if PDF invoice module is active
00226         if ( oxUtilsObject::getInstance()->isModuleActive( 'oxorder', 'myorder' ) ) {
00227             $oDb = oxDb::getDb();
00228             $sOrderId = oxConfig::getParameter( "oxid" );
00229             $sTable = getViewName( "oxorderarticles" );
00230             $sQ = "select count(oxid) from {$sTable} where oxorderid = ".$oDb->quote( $sOrderId )." and oxstorno = 0";
00231             $blCan = (bool) $oDb->getOne( $sQ );
00232         }
00233         return $blCan;
00234     }
00235 }