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

Revision 22736, 8.9 KB checked in by h_yoshimoto, 11 years ago (diff)

#2193 税率チームのコミットをマージ(from camp/camp-2_13-tax)

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