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

Revision 22926, 8.7 KB checked in by Seasoft, 11 years ago (diff)

#2287 (環境によりデストラクタが正しく動作しないケースがある)
#2288 (リクエスト単位で実行されるべきログ出力がブロックにも適用されている)
#2043 (typo修正・ソース整形・ソースコメントの改善 for 2.13.0)

  • 不明確な仕様にコメントを残した。
  • 親デストラクタを呼ぶだけの記述は可読性が悪くなると考え削除した。(上述のチケットで OS の仕様に依存したデストラクタとなるため、敢えてアプリケーション側で記述しておく意義は薄れたという認識のもと。)
Line 
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/**
27 * 税金管理 のページクラス.
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 */
33class LC_Page_Admin_Basis_Tax extends LC_Page_Admin_Ex
34{
35    /** エラー情報 */
36    var $arrErr;
37
38    /**
39     * Page を初期化する.
40     *
41     * @return void
42     */
43    function init()
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 = '基本情報管理';
50        $this->tpl_subtitle = '税金管理';
51        $masterData = new SC_DB_MasterData_Ex();
52        $this->arrPref = $masterData->getMasterData('mtb_pref');
53        $this->arrTAXCALCRULE = $masterData->getMasterData('mtb_taxrule');
54
55        //適用時刻の項目値設定
56        $this->objDate = new SC_Date();
57        //適用時間の年を、「現在年~現在年+2」の範囲に設定
58        for ($year=date("Y"); $year<=date("Y") + 2;$year++){
59            $arrYear[$year] = $year;
60        }
61        $this->arrYear = $arrYear;
62
63        for ($minutes=0; $minutes< 60; $minutes++){
64            $arrMinutes[$minutes] = $minutes;
65        }
66        $this->arrMinutes = $arrMinutes;
67    }
68
69    /**
70     * Page のプロセス.
71     *
72     * @return void
73     */
74    function process()
75    {
76        $this->action();
77        $this->sendResponse();
78    }
79
80    /**
81     * Page のアクション.
82     *
83     * @return void
84     */
85    function action()
86    {
87        $objTaxRule = new SC_Helper_TaxRule_Ex();
88        $objFormParam = new SC_FormParam_Ex();
89
90        // パラメーター情報の初期化
91        $this->lfInitParam($objFormParam);
92
93        // POST値をセット
94        $objFormParam->setParam($_POST);
95
96        // POST値の入力文字変換
97        $objFormParam->convParam();
98
99        //tax_rule_idを変数にセット
100        $tax_rule_id = $objFormParam->getValue('tax_rule_id');
101
102        // モードによる処理切り替え
103        switch ($this->getMode()) {
104            // 編集処理
105            case 'edit':
106                // エラーチェック
107                $this->arrErr = $this->lfCheckError($objFormParam, $objTaxRule);
108
109                if (count($this->arrErr) <= 0) {
110                    // POST値の引き継ぎ
111                    $arrParam = $objFormParam->getHashArray();
112                    // 登録実行
113                    $res_tax_rule_id = $this->doRegist($tax_rule_id, $arrParam, $objTaxRule);
114                    if ($res_tax_rule_id !== FALSE) {
115                        // 完了メッセージ
116                        $this->tpl_onload = "alert('登録が完了しました。');";
117                        // リロード
118                        SC_Response_Ex::reload();
119                    }
120                }
121
122                break;
123
124            // 編集前処理
125            case 'pre_edit':
126                $TaxRule = $objTaxRule->getTaxRuleData($tax_rule_id);
127
128                $tmp = explode(" ", $TaxRule['apply_date']);
129                $tmp_ymd = explode("-", $tmp[0]);
130                $TaxRule['apply_date_year'] = $tmp_ymd[0];
131                $TaxRule['apply_date_month'] = $tmp_ymd[1];
132                $TaxRule['apply_date_day'] = $tmp_ymd[2];
133                $tmp_hm = explode(":", $tmp[1]);
134                $TaxRule['apply_date_hour'] = $tmp_hm[0];
135                $TaxRule['apply_date_minutes'] = $tmp_hm[1];
136
137                $objFormParam->setParam($TaxRule);
138
139                // POSTデータを引き継ぐ
140                $this->tpl_tax_rule_id = $tax_rule_id;
141                break;
142
143            // 削除
144            case 'delete':
145                $objTaxRule->deleteTaxRuleData($tax_rule_id);
146
147                // リロード
148                SC_Response_Ex::reload();
149                break;
150
151            default:
152                break;
153        }
154
155        $this->arrForm = $objFormParam->getFormParamList();
156
157        // 税規約情報読み込み
158        $this->arrTaxrule = $objTaxRule->getTaxRuleList();
159    }
160
161    /**
162     * パラメーター情報の初期化を行う.
163     *
164     * @param SC_FormParam $objFormParam SC_FormParam インスタンス
165     * @return void
166     */
167    function lfInitParam(&$objFormParam)
168    {
169        $objFormParam->addParam('税規約ID', 'tax_rule_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
170        $objFormParam->addParam('消費税率', 'tax_rate', PERCENTAGE_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'));
171        $objFormParam->addParam('課税規則', 'calc_rule', PERCENTAGE_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'));
172        // 適用日時
173        $objFormParam->addParam('適用年', 'apply_date_year', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'));
174        $objFormParam->addParam('適用月', 'apply_date_month', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'));
175        $objFormParam->addParam('適用日', 'apply_date_day', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'));
176        $objFormParam->addParam('適用時', 'apply_date_hour', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'));
177        $objFormParam->addParam('適用分', 'apply_date_minutes', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'));
178        $objFormParam->addParam('適用日時', 'apply_date_year', 'apply_date_month', 'apply_date_day', INT_LEN, 'n', array("CHECK_DATE"));
179    }
180
181    /**
182     * 登録処理を実行.
183     *
184     * @param integer $tax_rule_id
185     * @param array $sqlval
186     * @param object $objTaxRule
187     * @return multiple
188     */
189    function doRegist($tax_rule_id, $arrParam, SC_Helper_TaxRule_Ex $objTaxRule)
190    {
191        $apply_date = SC_Utils_Ex::sfGetTimestampistime($arrParam['apply_date_year'], sprintf("%02d",$arrParam['apply_date_month']), sprintf("%02d",$arrParam['apply_date_day']),sprintf("%02d",$arrParam['apply_date_hour']), sprintf("%02d",$arrParam['apply_date_minutes']));
192
193        $calc_rule = $arrParam['calc_rule'];
194        $tax_rate = $arrParam['tax_rate'];
195
196        return $objTaxRule->setTaxRule($calc_rule, $tax_rate, $apply_date, $tax_rule_id);
197    }
198
199    /**
200     * 入力エラーチェック.
201     *
202     * @return array $objErr->arrErr エラー内容
203     */
204    function lfCheckError(&$objFormParam, SC_Helper_TaxRule_Ex &$objTaxRule)
205    {
206        $arrErr = $objFormParam->checkError();
207        $arrForm = $objFormParam->getHashArray();
208
209        // tax_rule_id の正当性チェック
210        if (!empty($arrForm['tax_rule_id'])) {
211            if (!SC_Utils_Ex::sfIsInt($arrForm['tax_rule_id'])
212                || !$objTaxRule->getTaxRuleData($arrForm['tax_rule_id'])
213            ) {
214                // tax_rule_idが指定されていて、且つその値が不正と思われる場合はエラー
215                $arrErr['tax_rule_id'] = '※ 税規約IDが不正です<br />';
216            }
217        }
218
219        if ($arrForm['tax_rule_id'] != '0') {
220        $apply_date = SC_Utils_Ex::sfGetTimestampistime($arrForm['apply_date_year'], sprintf("%02d",$arrForm['apply_date_month']), sprintf("%02d",$arrForm['apply_date_day']),sprintf("%02d",$arrForm['apply_date_hour']), sprintf("%02d",$arrForm['apply_date_minutes']));
221
222        // 税規約情報読み込み
223        $arrTaxRuleByTime = $objTaxRule->getTaxRuleByTime($apply_date);
224        // 編集中のレコード以外に同じ消費税率、課税規則が存在する場合
225            if (
226                !SC_Utils_Ex::isBlank($arrTaxRuleByTime)
227                && $arrTaxRuleByTime['tax_rule_id'] != $arrForm['tax_rule_id']
228                && $arrTaxRuleByTime['apply_date'] == $apply_date
229            ) {
230                $arrErr['apply_date'] = '※ 既に同じ適用日時で登録が存在します。<br />';
231            }
232        }
233
234        return $arrErr;
235    }
236}
Note: See TracBrowser for help on using the repository browser.