00001 <?php
00002
00008 class Order_List extends oxAdminList
00009 {
00015 protected $_sListClass = 'oxorder';
00016
00022 protected $_blDesc = true;
00023
00029 protected $_sDefSort = "oxorder.oxorderdate";
00030
00037 public function render()
00038 {
00039 parent::render();
00040
00041 $aFolders = $this->getConfig()->getConfigParam( 'aOrderfolder' );
00042 $sFolder = oxConfig::getParameter( "folder" );
00043
00044 if ( !$sFolder && is_array( $aFolders )) {
00045 $aNames = array_keys( $aFolders );
00046 $sFolder = $aNames[0];
00047 }
00048
00049 $aSearch = array( 'oxorderarticles' => 'ARTID', 'oxpayments' => 'PAYMENT');
00050 $sSearch = oxConfig::getParameter( "addsearch" );
00051 $sSearchfld = oxConfig::getParameter( "addsearchfld" );
00052
00053 $this->_aViewData["folder"] = $sFolder ? $sFolder : -1;
00054 $this->_aViewData["addsearchfld"] = $sSearchfld ? $sSearchfld : -1;
00055 $this->_aViewData["asearch"] = $aSearch;
00056 $this->_aViewData["addsearch"] = $sSearch;
00057 $this->_aViewData["afolder"] = $aFolders;
00058
00059 return "order_list.tpl";
00060 }
00061
00070 protected function _prepareWhereQuery( $aWhere, $sqlFull )
00071 {
00072 $sQ = parent::_prepareWhereQuery( $aWhere, $sqlFull );
00073 $myConfig = $this->getConfig();
00074 $aFolders = $myConfig->getConfigParam( 'aOrderfolder' );
00075 $sFolder = oxConfig::getParameter( 'folder' );
00076
00077 if ( $sFolder && $sFolder != '-1' ) {
00078 $sQ .= " and ( oxorder.oxfolder = '".$sFolder."' ";
00079
00080 $sQ .= "or oxorder.oxfolder = '".oxLang::getInstance()->translateString($sFolder)."')";
00081 } elseif ( !$sFolder && is_array( $aFolders ) ) {
00082 $aFolderNames = array_keys( $aFolders );
00083 $sQ .= " and ( oxorder.oxfolder = '".$aFolderNames[0]."' ";
00084
00085 $sQ .= "or oxorder.oxfolder = '".oxLang::getInstance()->translateString($aFolderNames[0])."')";
00086 }
00087
00088 return $sQ;
00089 }
00090
00098 protected function _buildSelectString( $oListObject = null )
00099 {
00100 $sSql = parent::_buildSelectString( $oListObject );
00101
00102 $sSearch = oxConfig::getParameter( 'addsearch' );
00103 $sSearch = trim( $sSearch );
00104 $sSearchField = oxConfig::getParameter( 'addsearchfld' );
00105
00106 if ( $sSearch ) {
00107 switch ($sSearchField) {
00108 case 'oxorderarticles':
00109 $sQ = "oxorder left join oxorderarticles on oxorderarticles.oxorderid=oxorder.oxid where ( oxorderarticles.oxartnum like '%{$sSearch}%' or oxorderarticles.oxtitle like '%{$sSearch}%' ) and ";
00110 break;
00111 case 'oxpayments':
00112 $sQ = "oxorder left join oxpayments on oxpayments.oxid=oxorder.oxpaymenttype where oxpayments.oxdesc like '%{$sSearch}%' and ";
00113 break;
00114 default:
00115 $sQ = "oxorder where oxorder.oxpaid like '%{$sSearch}%' and ";
00116 break;
00117 }
00118 $sSql = str_replace( 'oxorder where', $sQ, $sSql);
00119 }
00120
00121 return $sSql;
00122 }
00123
00128 public function storno()
00129 {
00130 $myConfig = $this->getConfig();
00131 $soxId = oxConfig::getParameter( "oxid");
00132
00133 $oOrder = oxNew( "oxorder" );
00134 $oOrder->load( $soxId);
00135 $oOrder->oxorder__oxstorno->setValue(1);
00136 $oOrder->save();
00137
00138
00139 $blUseStock = $myConfig->getConfigParam( 'blUseStock' );
00140 $blAllowNegativeStock = $myConfig->getConfigParam('blAllowNegativeStock');
00141 $oDB = oxDb::getDb();
00142 foreach ( $oOrder->getOrderArticles() as $oArticle) {
00143 if ( $oArticle->oxorderarticles__oxstorno->value == 0) {
00144 if ( $blUseStock )
00145 $oArticle->updateArticleStock($oArticle->oxorderarticles__oxamount->value, $blAllowNegativeStock );
00146 $oDB->execute( "update oxorderarticles set oxorderarticles.oxstorno = '1' where oxorderarticles.oxid = '".$oArticle->oxorderarticles__oxid->value."' ");
00147 }
00148 }
00149
00150
00151
00152 $this->init();
00153 }
00154
00162 protected function _prepareOrderByQuery( $sSql = null )
00163 {
00164 $sSortParam = oxConfig::getParameter( 'sort' );
00165
00166
00167 if ( $sSortParam && $sSortParam == 'oxorder.oxbilllname' )
00168 $this->_blDesc = false;
00169
00170 return parent::_prepareOrderByQuery( $sSql );
00171 }
00172 }