source: branches/version-2_13_0/data/class/pages/admin/basis/LC_Page_Admin_Basis_Tax.php @ 23157

Revision 23157, 10.8 KB checked in by m_uehara, 11 years ago (diff)

#2323
・税金設定の適用日の日付チェックを修正
・受注編集の税率に数値チェックを追加
・カートの税率取得処理を修正
・税規約IDのエラーメッセージ表示

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    public $arrErr;
37
38    /**
39     * Page を初期化する.
40     *
41     * @return void
42     */
43    public 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        $this->arrEnable = array( '1' => '有効', '0' => '無効');
69
70    }
71
72    /**
73     * Page のプロセス.
74     *
75     * @return void
76     */
77    public function process()
78    {
79        $this->action();
80        $this->sendResponse();
81    }
82
83    /**
84     * Page のアクション.
85     *
86     * @return void
87     */
88    public function action()
89    {
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()) {
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                    }
118                }
119                break;
120
121            // 編集処理
122            case 'edit':
123                // エラーチェック
124                $this->arrErr = $this->lfCheckError($objFormParam, $objTaxRule);
125
126                if (count($this->arrErr) <= 0) {
127                    // POST値の引き継ぎ
128                    $arrParam = $objFormParam->getHashArray();
129                    // 登録実行
130                    $res_tax_rule_id = $this->doRegist($tax_rule_id, $arrParam, $objTaxRule);
131                    if ($res_tax_rule_id !== FALSE) {
132                        // 完了メッセージ
133                        $this->tpl_onload = "alert('登録が完了しました。');";
134                        // リロード
135                        SC_Response_Ex::reload();
136                    }
137                }
138
139                break;
140
141            // 編集前処理
142            case 'pre_edit':
143                $TaxRule = $objTaxRule->getTaxRuleData($tax_rule_id);
144
145                $tmp = explode(" ", $TaxRule['apply_date']);
146                $tmp_ymd = explode("-", $tmp[0]);
147                $TaxRule['apply_date_year'] = $tmp_ymd[0];
148                $TaxRule['apply_date_month'] = $tmp_ymd[1];
149                $TaxRule['apply_date_day'] = $tmp_ymd[2];
150                $tmp_hm = explode(":", $tmp[1]);
151                $TaxRule['apply_date_hour'] = $tmp_hm[0];
152                $TaxRule['apply_date_minutes'] = $tmp_hm[1];
153
154                $objFormParam->setParam($TaxRule);
155
156                // POSTデータを引き継ぐ
157                $this->tpl_tax_rule_id = $tax_rule_id;
158                break;
159
160            // 削除
161            case 'delete':
162                $objTaxRule->deleteTaxRuleData($tax_rule_id);
163
164                // リロード
165                SC_Response_Ex::reload();
166                break;
167
168            default:
169                break;
170        }
171
172        $this->arrForm = $objFormParam->getFormParamList();
173
174        // 税規約情報読み込み
175        $this->arrTaxrule = $objTaxRule->getTaxRuleList();
176    }
177
178    /**
179     * パラメーター情報の初期化を行う.
180     *
181     * @param  SC_FormParam $objFormParam SC_FormParam インスタンス
182     * @return void
183     */
184    public function lfInitParam(&$objFormParam)
185    {
186        $objFormParam->addParam('商品個別 税率設定機能', 'product_tax_flg', INT_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'), OPTION_PRODUCT_TAX_RULE);
187        $objFormParam->addParam('税規約ID', 'tax_rule_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
188        $objFormParam->addParam('消費税率', 'tax_rate', PERCENTAGE_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'));
189        $objFormParam->addParam('課税規則', 'calc_rule', PERCENTAGE_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'));
190        // 適用日時
191        $objFormParam->addParam('適用年', 'apply_date_year', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'));
192        $objFormParam->addParam('適用月', 'apply_date_month', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'));
193        $objFormParam->addParam('適用日', 'apply_date_day', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'));
194        $objFormParam->addParam('適用時', 'apply_date_hour', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'));
195        $objFormParam->addParam('適用分', 'apply_date_minutes', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'));
196    }
197
198    /**
199     * 登録処理を実行.
200     *
201     * @param  integer  $tax_rule_id
202     * @param  array    $sqlval
203     * @param  object   $objTaxRule
204     * @return multiple
205     */
206    public function doRegist($tax_rule_id, $arrParam, SC_Helper_TaxRule_Ex $objTaxRule)
207    {
208        $apply_date = SC_Utils_Ex::sfGetTimestampistime(
209                $arrParam['apply_date_year'],
210                sprintf("%02d", $arrParam['apply_date_month']),
211                sprintf("%02d", $arrParam['apply_date_day']),
212                sprintf("%02d", $arrParam['apply_date_hour']),
213                sprintf("%02d", $arrParam['apply_date_minutes'])
214                );
215
216        $calc_rule = $arrParam['calc_rule'];
217        $tax_rate = $arrParam['tax_rate'];
218
219        return $objTaxRule->setTaxRule($calc_rule, $tax_rate, $apply_date, $tax_rule_id);
220    }
221
222    /**
223     * 共通設定の登録処理を実行.
224     *
225     * @param  array   $arrParam
226     * @return boolean
227     */
228    public function doParamRegist($arrParam)
229    {
230        $arrData = array();
231        foreach ($arrParam as $key => $val) {
232            switch ($key) {
233            case 'product_tax_flg':
234                $arrData['OPTION_PRODUCT_TAX_RULE'] = $val;
235                break;
236            default:
237            }
238        }
239        $masterData = new SC_DB_MasterData_Ex();
240        // DBのデータを更新
241        $res = $masterData->updateMasterData('mtb_constants', array(), $arrData);
242        // キャッシュを生成
243        $masterData->createCache('mtb_constants', array(), true, array('id', 'remarks'));
244
245        return $res;
246    }
247
248    /**
249     * 入力エラーチェック.
250     *
251     * @return array $objErr->arrErr エラー内容
252     */
253    public function lfCheckError(&$objFormParam, SC_Helper_TaxRule_Ex &$objTaxRule)
254    {
255        $arrErr = $objFormParam->checkError();
256        $arrForm = $objFormParam->getHashArray();
257        $objErr = new SC_CheckError_Ex($arrForm);
258
259        // tax_rule_id の正当性チェック
260        if (!empty($arrForm['tax_rule_id'])) {
261            if (!SC_Utils_Ex::sfIsInt($arrForm['tax_rule_id'])
262                || !$objTaxRule->getTaxRuleData($arrForm['tax_rule_id'])
263            ) {
264                // tax_rule_idが指定されていて、且つその値が不正と思われる場合はエラー
265                $arrErr['tax_rule_id'] = '※ 税規約IDが不正です<br />';
266            }
267        }
268
269        // 適用日時チェック
270        $objErr->doFunc(array('適用日時', 'apply_date_year', 'apply_date_month', 'apply_date_day'), array('CHECK_DATE'));
271        if (SC_Utils_Ex::isBlank($objErr->arrErr['apply_date_year']) && $arrForm['tax_rule_id'] != '0') {
272            $apply_date = SC_Utils_Ex::sfGetTimestampistime(
273                    $arrForm['apply_date_year'],
274                    sprintf("%02d", $arrForm['apply_date_month']),
275                    sprintf("%02d", $arrForm['apply_date_day']),
276                    sprintf("%02d", $arrForm['apply_date_hour']),
277                    sprintf("%02d", $arrForm['apply_date_minutes'])
278                    );
279
280            // 税規約情報読み込み
281            $arrTaxRuleByTime = $objTaxRule->getTaxRuleByTime($apply_date);
282
283            // 編集中のレコード以外に同じ消費税率、課税規則が存在する場合
284            if (
285                !SC_Utils_Ex::isBlank($arrTaxRuleByTime)
286                && $arrTaxRuleByTime['tax_rule_id'] != $arrForm['tax_rule_id']
287                && $arrTaxRuleByTime['apply_date'] == $apply_date
288            ) {
289                $arrErr['apply_date'] = '※ 既に同じ適用日時で登録が存在します。<br />';
290            }
291        }
292        if (!SC_Utils_Ex::isBlank($objErr->arrErr)) {
293            $arrErr = array_merge($arrErr, $objErr->arrErr);
294        }
295
296        return $arrErr;
297    }
298}
Note: See TracBrowser for help on using the repository browser.