source: branches/version-2_13-dev/data/class/pages/admin/basis/LC_Page_Admin_Basis_Tax.php @ 23230

Revision 23230, 11.2 KB checked in by m_uehara, 11 years ago (diff)

#2363 r23177, r23181 - r23186, r23188 - r23191, r23194, r23197, r23199 - r23218, r23220, r23223 - r23225 をマージ

RevLine 
[22624]1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2013 LOCKON CO.,LTD. All Rights Reserved.
6 *
7 * http://www.lockon.co.jp/
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22 */
23
24require_once CLASS_EX_REALDIR . 'page_extends/admin/LC_Page_Admin_Ex.php';
25
26/**
[23230]27 * 税率設定 のページクラス.
[22624]28 *
29 * @package Page
30 * @author LOCKON CO.,LTD.
31 * @version $Id: LC_Page_Admin_Basis_Tax_Ex.php 22567 2013-03-09 12:18:54Z yomoro $
32 */
[22856]33class LC_Page_Admin_Basis_Tax extends LC_Page_Admin_Ex
[22624]34{
35    /** エラー情報 */
[23124]36    public $arrErr;
[22624]37
38    /**
39     * Page を初期化する.
40     *
41     * @return void
42     */
[23124]43    public function init()
[22624]44    {
45        parent::init();
46        $this->tpl_mainpage = 'basis/tax.tpl';
47        $this->tpl_subno = 'tax';
48        $this->tpl_mainno = 'basis';
49        $this->tpl_maintitle = '基本情報管理';
[23230]50        $this->tpl_subtitle = '税率設定';
[22624]51        $masterData = new SC_DB_MasterData_Ex();
52        $this->arrPref = $masterData->getMasterData('mtb_pref');
53        $this->arrTAXCALCRULE = $masterData->getMasterData('mtb_taxrule');
54
[22642]55        //適用時刻の項目値設定
[22624]56        $this->objDate = new SC_Date();
[22642]57        //適用時間の年を、「現在年~現在年+2」の範囲に設定
[23124]58        for ($year=date("Y"); $year<=date("Y") + 2;$year++) {
[22624]59            $arrYear[$year] = $year;
60        }
61        $this->arrYear = $arrYear;
62
[23124]63        for ($minutes=0; $minutes< 60; $minutes++) {
[22624]64            $arrMinutes[$minutes] = $minutes;
65        }
66        $this->arrMinutes = $arrMinutes;
[22977]67
68        $this->arrEnable = array( '1' => '有効', '0' => '無効');
69
[22624]70    }
71
72    /**
73     * Page のプロセス.
74     *
75     * @return void
76     */
[23124]77    public function process()
[22624]78    {
79        $this->action();
80        $this->sendResponse();
81    }
82
83    /**
84     * Page のアクション.
85     *
86     * @return void
87     */
[23124]88    public function action()
[22624]89    {
[22642]90        $objTaxRule = new SC_Helper_TaxRule_Ex();
91        $objFormParam = new SC_FormParam_Ex();
92
93        // パラメーター情報の初期化
94        $this->lfInitParam($objFormParam);
95
96        // POST値をセット
97        $objFormParam->setParam($_POST);
98
99        // POST値の入力文字変換
100        $objFormParam->convParam();
101
102        //tax_rule_idを変数にセット
103        $tax_rule_id = $objFormParam->getValue('tax_rule_id');
104
105        // モードによる処理切り替え
106        switch ($this->getMode()) {
[22977]107            // 共通設定登録
108            case 'param_edit':
109                $arrErr = $this->lfCheckError($objFormParam, $objTaxRule);
110                if (SC_Utils_Ex::isBlank($arrErr['product_tax_flg'])) {
111                    // POST値の引き継ぎ
112                    $arrParam = $objFormParam->getHashArray();
113                    // 登録実行
114                    if ($this->doParamRegist($arrParam)) {
115                        // 完了メッセージ
116                        $this->tpl_onload = "alert('登録が完了しました。');";
117                    }
[23170]118                } else {
119                    // エラーが存在する場合、メッセージを表示する為に代入
120                    $this->arrErr['product_tax_flg'] = $arrErr['product_tax_flg'];
[22977]121                }
[23170]122               
[22977]123                break;
124
[22642]125            // 編集処理
126            case 'edit':
127                // エラーチェック
128                $this->arrErr = $this->lfCheckError($objFormParam, $objTaxRule);
129
130                if (count($this->arrErr) <= 0) {
131                    // POST値の引き継ぎ
132                    $arrParam = $objFormParam->getHashArray();
133                    // 登録実行
134                    $res_tax_rule_id = $this->doRegist($tax_rule_id, $arrParam, $objTaxRule);
135                    if ($res_tax_rule_id !== FALSE) {
136                        // 完了メッセージ
137                        $this->tpl_onload = "alert('登録が完了しました。');";
[23170]138
[22642]139                        // リロード
140                        SC_Response_Ex::reload();
141                    }
[23170]142                } else if(SC_Utils_Ex::isBlank($this->arrErr['tax_rule_id'])) {
143                    // 税率ID以外のエラーの場合、ID情報を引き継ぐ
144                    $this->tpl_tax_rule_id = $tax_rule_id;
[22642]145                }
146
147                break;
148
149            // 編集前処理
150            case 'pre_edit':
151                $TaxRule = $objTaxRule->getTaxRuleData($tax_rule_id);
152
153                $tmp = explode(" ", $TaxRule['apply_date']);
154                $tmp_ymd = explode("-", $tmp[0]);
155                $TaxRule['apply_date_year'] = $tmp_ymd[0];
156                $TaxRule['apply_date_month'] = $tmp_ymd[1];
157                $TaxRule['apply_date_day'] = $tmp_ymd[2];
158                $tmp_hm = explode(":", $tmp[1]);
159                $TaxRule['apply_date_hour'] = $tmp_hm[0];
160                $TaxRule['apply_date_minutes'] = $tmp_hm[1];
161
162                $objFormParam->setParam($TaxRule);
163
164                // POSTデータを引き継ぐ
165                $this->tpl_tax_rule_id = $tax_rule_id;
166                break;
167
168            // 削除
169            case 'delete':
170                $objTaxRule->deleteTaxRuleData($tax_rule_id);
171
172                // リロード
173                SC_Response_Ex::reload();
174                break;
175
176            default:
177                break;
178        }
179
180        $this->arrForm = $objFormParam->getFormParamList();
181
182        // 税規約情報読み込み
183        $this->arrTaxrule = $objTaxRule->getTaxRuleList();
[22624]184    }
185
186    /**
[22642]187     * パラメーター情報の初期化を行う.
188     *
[23124]189     * @param  SC_FormParam $objFormParam SC_FormParam インスタンス
[22642]190     * @return void
191     */
[23124]192    public function lfInitParam(&$objFormParam)
[22642]193    {
[22977]194        $objFormParam->addParam('商品個別 税率設定機能', 'product_tax_flg', INT_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'), OPTION_PRODUCT_TAX_RULE);
[22642]195        $objFormParam->addParam('税規約ID', 'tax_rule_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
196        $objFormParam->addParam('消費税率', 'tax_rate', PERCENTAGE_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'));
[22667]197        $objFormParam->addParam('課税規則', 'calc_rule', PERCENTAGE_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'));
[23170]198
[22642]199        // 適用日時
200        $objFormParam->addParam('適用年', 'apply_date_year', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'));
201        $objFormParam->addParam('適用月', 'apply_date_month', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'));
202        $objFormParam->addParam('適用日', 'apply_date_day', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'));
203        $objFormParam->addParam('適用時', 'apply_date_hour', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'));
204        $objFormParam->addParam('適用分', 'apply_date_minutes', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'));
205    }
206
207    /**
208     * 登録処理を実行.
209     *
[23124]210     * @param  integer  $tax_rule_id
211     * @param  array    $sqlval
212     * @param  object   $objTaxRule
[22642]213     * @return multiple
214     */
[23124]215    public function doRegist($tax_rule_id, $arrParam, SC_Helper_TaxRule_Ex $objTaxRule)
[22642]216    {
[22977]217        $apply_date = SC_Utils_Ex::sfGetTimestampistime(
218                $arrParam['apply_date_year'],
219                sprintf("%02d", $arrParam['apply_date_month']),
220                sprintf("%02d", $arrParam['apply_date_day']),
221                sprintf("%02d", $arrParam['apply_date_hour']),
222                sprintf("%02d", $arrParam['apply_date_minutes'])
223                );
[22667]224
225        $calc_rule = $arrParam['calc_rule'];
226        $tax_rate = $arrParam['tax_rate'];
[22856]227
[22667]228        return $objTaxRule->setTaxRule($calc_rule, $tax_rate, $apply_date, $tax_rule_id);
[22642]229    }
230
231    /**
[22977]232     * 共通設定の登録処理を実行.
233     *
[23124]234     * @param  array   $arrParam
[22977]235     * @return boolean
236     */
[23124]237    public function doParamRegist($arrParam)
[22977]238    {
239        $arrData = array();
240        foreach ($arrParam as $key => $val) {
241            switch ($key) {
242            case 'product_tax_flg':
243                $arrData['OPTION_PRODUCT_TAX_RULE'] = $val;
244                break;
245            default:
246            }
247        }
248        $masterData = new SC_DB_MasterData_Ex();
249        // DBのデータを更新
250        $res = $masterData->updateMasterData('mtb_constants', array(), $arrData);
251        // キャッシュを生成
252        $masterData->createCache('mtb_constants', array(), true, array('id', 'remarks'));
[23124]253
[22977]254        return $res;
255    }
256
257    /**
[22642]258     * 入力エラーチェック.
259     *
260     * @return array $objErr->arrErr エラー内容
261     */
[23124]262    public function lfCheckError(&$objFormParam, SC_Helper_TaxRule_Ex &$objTaxRule)
[22642]263    {
264        $arrErr = $objFormParam->checkError();
265        $arrForm = $objFormParam->getHashArray();
[23170]266        $objErr = new SC_CheckError_Ex($arrForm);
[22642]267
268        // tax_rule_id の正当性チェック
269        if (!empty($arrForm['tax_rule_id'])) {
270            if (!SC_Utils_Ex::sfIsInt($arrForm['tax_rule_id'])
271                || !$objTaxRule->getTaxRuleData($arrForm['tax_rule_id'])
272            ) {
273                // tax_rule_idが指定されていて、且つその値が不正と思われる場合はエラー
274                $arrErr['tax_rule_id'] = '※ 税規約IDが不正です<br />';
275            }
276        }
277
[23170]278        // 適用日時チェック
279        $objErr->doFunc(array('適用日時', 'apply_date_year', 'apply_date_month', 'apply_date_day'), array('CHECK_DATE'));
280        if (SC_Utils_Ex::isBlank($objErr->arrErr['apply_date_year']) && $arrForm['tax_rule_id'] != '0') {
281            $apply_date = SC_Utils_Ex::sfGetTimestampistime(
282                    $arrForm['apply_date_year'],
283                    sprintf("%02d", $arrForm['apply_date_month']),
284                    sprintf("%02d", $arrForm['apply_date_day']),
285                    sprintf("%02d", $arrForm['apply_date_hour']),
286                    sprintf("%02d", $arrForm['apply_date_minutes'])
287                    );
[22667]288
[23170]289            // 税規約情報読み込み
290            $arrTaxRuleByTime = $objTaxRule->getTaxRuleByTime($apply_date);
291
292            // 編集中のレコード以外に同じ消費税率、課税規則が存在する場合
[22642]293            if (
294                !SC_Utils_Ex::isBlank($arrTaxRuleByTime)
295                && $arrTaxRuleByTime['tax_rule_id'] != $arrForm['tax_rule_id']
296                && $arrTaxRuleByTime['apply_date'] == $apply_date
297            ) {
298                $arrErr['apply_date'] = '※ 既に同じ適用日時で登録が存在します。<br />';
299            }
[22667]300        }
[23170]301        if (!SC_Utils_Ex::isBlank($objErr->arrErr)) {
302            $arrErr = array_merge($arrErr, $objErr->arrErr);
303        }
[22642]304
305        return $arrErr;
306    }
[22624]307}
Note: See TracBrowser for help on using the repository browser.