- Timestamp:
- 2013/03/10 09:21:47 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/camp/camp-2_13-tax/data/class/helper/SC_Helper_TaxRule.php
r22666 r22691 114 114 } 115 115 116 116 117 /** 117 118 * 現在有効な税金設定情報を返す … … 120 121 * @return array 税設定情報 121 122 */ 122 function getTaxRule($product_id = 0, $product_class_id = 0, $pref_id = 0, $country_id = 0) 123 { 124 // 条件に基づいて税情報を取得 125 $objQuery =& SC_Query_Ex::getSingletonInstance(); 126 $table = 'dtb_tax_rule'; 127 $where = '(product_id = 0 OR product_id = ?)' 128 . ' AND (product_class_id = 0 OR product_class_id = ?)' 129 . ' AND (pref_id = 0 OR pref_id = ?)' 130 . ' AND (country_id = 0 OR country_id = ?)'; 131 132 $arrVal = array($product_id, $product_class_id, $pref_id, $country_id); 133 $order = 'apply_date DESC'; 134 $objQuery->setOrder($order); 135 $arrData = $objQuery->select('*', $table, $where, $arrVal); 136 // 日付や条件でこねて選択は、作り中。取りあえずスタブ的にデフォルトを返却 137 // 一旦配列の最後の項目を返すように変更 138 // return $arrData[0]; 139 return $arrData[count($arrData)-1]; 123 function getTaxRule ($product_id = 0, $product_class_id = 0, $pref_id = 0, $country_id = 0) 124 { 125 // リクエストの配列化 126 $arrRequest = array('product_id' => $product_id, 127 'product_class_id' => $product_class_id, 128 'pref_id' => $pref_id, 129 'country_id' => $country_id); 130 131 // 地域設定を優先するが、システムパラメーターなどに設定を持っていくか 132 // 後に書いてあるほど優先される、詳細後述MEMO参照 133 $arrPriorityKeys = array('product_id', 'product_class_id', 'pref_id', 'country_id'); 134 $cache_key = "$product_id,$product_class_id,$pref_id,$country_id"; 135 136 // 複数回呼出があるのでキャッシュ化 137 static $data_c = array(); 138 139 if (empty($data_c[$cache_key])) { 140 $arrRet = array(); 141 142 // 条件に基づいて税の設定情報を取得 143 $objQuery =& SC_Query_Ex::getSingletonInstance(); 144 $table = 'dtb_tax_rule'; 145 $cols = '*, CASE WHEN apply_date IS NULL THEN 1 ELSE 0 END as nullorder'; 146 $where = '(product_id = 0 OR product_id = ?)' 147 . ' AND (product_class_id = 0 OR product_class_id = ?)' 148 . ' AND (pref_id = 0 OR pref_id = ?)' 149 . ' AND (country_id = 0 OR country_id = ?)' 150 . ' AND (apply_date < CURRENT_TIMESTAMP OR apply_date IS NULL)' 151 . ' AND del_flg = 0'; 152 153 $arrVal = array($product_id, $product_class_id, $pref_id, $country_id); 154 $order = 'nullorder ASC, apply_date DESC'; 155 $objQuery->setOrder($order); 156 $arrData = $objQuery->select($cols, $table, $where, $arrVal); 157 // 優先度付け 158 // MEMO: 税の設定は相反する設定を格納可能だが、その中で優先度を付けるため 159 // キーの優先度により、利用する税設定を判断する 160 // 優先度が同等の場合、適用日付で判断する 161 162 // XXXX: ビット演算で優先順位を判断という雑な事してます。すいません 163 foreach ($arrData as $data_key => $data) { 164 $res = 0; 165 foreach ($arrPriorityKeys as $key_no => $key) { 166 if ($arrRequest[$key] != 0 && $data[$key] == $arrRequest[$key]) { 167 // 配列の数値添字を重みとして利用する 168 $res += 1 << ($key_no + 1); 169 } 170 } 171 $arrData[$data_key]['rank'] = $res; 172 } 173 174 // 優先順位が高いものを返却値として確定 175 // 適用日降順に並んでいるので、単に優先順位比較のみで格納判断可能 176 foreach ($arrData as $data) { 177 if (!isset($arrRet['rank']) || $arrRet['rank'] < $data['rank']) { 178 // 優先度が高い場合, または空の場合 179 $arrRet = $data; 180 } 181 } 182 $data_c[$cache_key] = $arrRet; 183 } 184 185 GC_Utils_Ex::gfDebugLog('key=' . $cache_key . ' result_tax=' . print_r($data_c[$cache_key],true)); 186 return $data_c[$cache_key]; 140 187 } 141 188 … … 160 207 function setTaxRule($calc_rule, $tax_rate, $apply_date, $tax_rule_id=NULL, $tax_adjust=0, $product_id = 0, $product_class_id = 0, $pref_id = 0, $country_id = 0) 161 208 { 162 163 164 165 166 167 168 169 170 209 $table = 'dtb_tax_rule'; 210 $arrValues = array(); 211 $arrValues['calc_rule'] = $calc_rule; 212 $arrValues['tax_rate'] = $tax_rate; 213 $arrValues['tax_adjust'] = $tax_adjust; 214 $arrValues['apply_date'] = $apply_date; 215 $arrValues['member_id'] = $_SESSION['member_id']; 216 $arrValues['update_date'] = 'CURRENT_TIMESTAMP'; 217 171 218 // 新規か更新か? 172 219 $objQuery =& SC_Query_Ex::getSingletonInstance(); 173 220 if($tax_rule_id == NULL && $product_id != 0 && $product_class_id != 0){ 174 221 $where = 'product_id = ? AND product_class_id= ? AND pref_id = ? AND country_id = ?'; 175 222 $arrVal = array($product_id, $product_class_id, $pref_id, $country_id); 176 177 178 179 223 $arrCheck = $objQuery->getRow('*', 'dtb_tax_rule', $where, $arrVal); 224 $tax_rule_id = $arrCheck['tax_rule_id']; 225 } 226 180 227 if($tax_rule_id == NULL) { 181 228 // 税情報を新規 … … 186 233 $arrValues['product_id'] = $product_id; 187 234 $arrValues['product_class_id'] = $product_class_id; 188 189 235 $arrValues['create_date'] = 'CURRENT_TIMESTAMP'; 236 190 237 $objQuery->insert($table, $arrValues); 191 238 } else { … … 195 242 } 196 243 } 197 198 244 245 199 246 function getTaxRuleList($has_deleted = false) 200 247 { … … 222 269 } 223 270 224 271 225 272 226 273 function getTaxRuleByTime($apply_date, $has_deleted = false)
Note: See TracChangeset
for help on using the changeset viewer.