| 1 |
<?php |
| 2 |
/** |
| 3 |
* System extentions Ganbare Tencho |
| 4 |
* Version: 1.0.0 |
| 5 |
* Author: Collne Inc. |
| 6 |
* |
| 7 |
* @package Welcart |
| 8 |
*/ |
| 9 |
|
| 10 |
/** |
| 11 |
* Ganbare Tencho class |
| 12 |
*/ |
| 13 |
class USCES_GANBARE_TENCHO { |
| 14 |
|
| 15 |
/** |
| 16 |
* Option value |
| 17 |
* |
| 18 |
* @var array |
| 19 |
*/ |
| 20 |
public static $opts; |
| 21 |
|
| 22 |
/** |
| 23 |
* Class Constructor |
| 24 |
*/ |
| 25 |
public function __construct() { |
| 26 |
|
| 27 |
self::initialize_data(); |
| 28 |
|
| 29 |
if ( is_admin() ) { |
| 30 |
|
| 31 |
add_action( 'usces_action_admin_system_extentions', array( $this, 'setting_form' ) ); |
| 32 |
add_action( 'init', array( $this, 'save_data' ) ); |
| 33 |
|
| 34 |
if ( self::$opts['activate_flag'] ) { |
| 35 |
add_action( 'usces_action_order_list_page', array( $this, 'output_csv' ) ); |
| 36 |
add_action( 'usces_action_order_list_searchbox_bottom', array( $this, 'action_button' ) ); |
| 37 |
add_filter( 'usces_filter_order_list_page_js', array( $this, 'add_js' ) ); |
| 38 |
} |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
* Initialize |
| 44 |
* Modified:2 Nov.2015 |
| 45 |
*/ |
| 46 |
public function initialize_data() { |
| 47 |
global $usces; |
| 48 |
$options = get_option( 'usces_ex', array( 'system' => array( 'ganbare' => array() ) ) ); |
| 49 |
$options['system']['ganbare']['activate_flag'] = ! isset( $options['system']['ganbare']['activate_flag'] ) ? 0 : (int) $options['system']['ganbare']['activate_flag']; |
| 50 |
update_option( 'usces_ex', $options ); |
| 51 |
self::$opts = $options['system']['ganbare']; |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* Save ganbare tencho option data |
| 56 |
* Modified:10 Oct.2015 |
| 57 |
*/ |
| 58 |
public function save_data() { |
| 59 |
global $usces; |
| 60 |
if ( isset( $_POST['usces_ganbare_option_update'] ) ) { |
| 61 |
|
| 62 |
check_admin_referer( 'admin_system', 'wc_nonce' ); |
| 63 |
if ( ! current_user_can( 'wel_manage_setting' ) ) { |
| 64 |
wp_die( __( 'You do not have sufficient permissions to access this page.' ) ); |
| 65 |
} |
| 66 |
|
| 67 |
self::$opts['activate_flag'] = isset( $_POST['ganbare_activate_flag'] ) ? (int) $_POST['ganbare_activate_flag'] : 0; |
| 68 |
|
| 69 |
$options = get_option( 'usces_ex', array( 'system' => array( 'ganbare' => array() ) ) ); |
| 70 |
$options['system']['ganbare'] = self::$opts; |
| 71 |
update_option( 'usces_ex', $options ); |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
/** |
| 76 |
* Setting form |
| 77 |
* Modified:10 Oct.2015 |
| 78 |
*/ |
| 79 |
public function setting_form() { |
| 80 |
$status = self::$opts['activate_flag'] ? '<span class="running">' . __( 'Running', 'usces' ) . '</span>' : '<span class="stopped">' . __( 'Stopped', 'usces' ) . '</span>'; |
| 81 |
?> |
| 82 |
<form action="" method="post" name="option_form" id="ganbare_form"> |
| 83 |
<div class="postbox"> |
| 84 |
<div class="postbox-header"> |
| 85 |
<h2><span><?php esc_html_e( 'Ganbare Tencho', 'usces' ); ?></span><?php wel_esc_script_e( $status ); ?></h2> |
| 86 |
<div class="handle-actions"><button type="button" class="handlediv" id="ganbare"><span class="screen-reader-text"><?php echo esc_html( sprintf( __( 'Toggle panel: %s' ), __( 'Ganbare Tencho', 'usces' ) ) ); ?></span><span class="toggle-indicator"></span></button></div> |
| 87 |
</div> |
| 88 |
<div class="inside"> |
| 89 |
<table class="form_table"> |
| 90 |
<tr height="35"> |
| 91 |
<th class="system_th"><a style="cursor:pointer;" onclick="toggleVisibility('ex_ganbare_activate_flag');"><?php esc_html_e( 'Activation', 'usces' ); ?></a></th> |
| 92 |
<td width="10"><input name="ganbare_activate_flag" id="ganbare_activate_flag0" type="radio" value="0"<?php checked( self::$opts['activate_flag'], 0 ); ?> /></td><td width="100"><label for="ganbare_activate_flag0"><?php esc_html_e( 'disable', 'usces' ); ?></label></td> |
| 93 |
<td width="10"><input name="ganbare_activate_flag" id="ganbare_activate_flag1" type="radio" value="1"<?php checked( self::$opts['activate_flag'], 1 ); ?> /></td><td width="100"><label for="ganbare_activate_flag1"><?php esc_html_e( 'enable', 'usces' ); ?></label></td> |
| 94 |
<td><div id="ex_ganbare_activate_flag" class="explanation"><?php _e( "Activation the Ganbare-Tencho function.<br>It also can be used as data for the Tempo-Up.", 'usces' ); ?></div></td> |
| 95 |
</tr> |
| 96 |
</table> |
| 97 |
<hr /> |
| 98 |
<input name="usces_ganbare_option_update" type="submit" class="button button-primary" value="<?php esc_attr_e( 'change decision', 'usces' ); ?>" /> |
| 99 |
</div> |
| 100 |
</div><!--postbox--> |
| 101 |
<?php wp_nonce_field( 'admin_system', 'wc_nonce' ); ?> |
| 102 |
</form> |
| 103 |
<?php |
| 104 |
} |
| 105 |
|
| 106 |
/** |
| 107 |
* Output CSV |
| 108 |
* Modified:10 Oct.2015 |
| 109 |
* |
| 110 |
* @param string $order_action Order action. |
| 111 |
*/ |
| 112 |
public function output_csv( $order_action ) { |
| 113 |
if ( 'ganbare_tencho_csv' == $order_action && check_admin_referer( 'csv-nonce', 'nonce' ) ) { |
| 114 |
$this->outcsv_shipping(); |
| 115 |
} |
| 116 |
} |
| 117 |
|
| 118 |
/** |
| 119 |
* Action button |
| 120 |
*/ |
| 121 |
public function action_button() { |
| 122 |
echo ' |
| 123 |
<input type="button" id="dl_ganbare_tencho_csv" class="searchbutton button" value="' . esc_html__( 'Ganbare Tencho data output', 'usces' ) . '" /> |
| 124 |
'; |
| 125 |
} |
| 126 |
|
| 127 |
/** |
| 128 |
* Add Scripts |
| 129 |
* |
| 130 |
* @param string $html HTML form. |
| 131 |
* @return string |
| 132 |
*/ |
| 133 |
public function add_js( $html ) { |
| 134 |
$html .= ' |
| 135 |
$("#dl_ganbare_tencho_csv").click(function() { |
| 136 |
if( $("input[name*=\'listcheck\']:checked").length == 0 ) { |
| 137 |
alert("' . __( 'Choose the data.', 'usces' ) . '"); |
| 138 |
$("#oederlistaction").val(""); |
| 139 |
return false; |
| 140 |
} |
| 141 |
var listcheck = ""; |
| 142 |
$("input[name*=\'listcheck\']").each(function(i) { |
| 143 |
if( $(this).prop("checked") ) { |
| 144 |
listcheck += "&listcheck["+i+"]="+$(this).val(); |
| 145 |
} |
| 146 |
}); |
| 147 |
location.href = "' . USCES_ADMIN_URL . '?page=usces_orderlist&order_action=ganbare_tencho_csv"+listcheck+"&noheader=true&nonce=' . wp_create_nonce( 'csv-nonce' ) . '"; |
| 148 |
}); |
| 149 |
'; |
| 150 |
return $html; |
| 151 |
} |
| 152 |
|
| 153 |
/** |
| 154 |
* Output CSV |
| 155 |
*/ |
| 156 |
public function outcsv_shipping() { |
| 157 |
global $usces; |
| 158 |
|
| 159 |
$filename = 'ganbare' . date( 'YmdHis', current_time( 'timestamp' ) ) . '.csv'; |
| 160 |
$ids = $_GET['listcheck']; |
| 161 |
|
| 162 |
$line = ''; |
| 163 |
$ldata = array( |
| 164 |
'受注番号' => '', |
| 165 |
'レコードナンバー' => '', |
| 166 |
'注文日時' => '', |
| 167 |
'商品名' => '', |
| 168 |
'商品コード' => '', |
| 169 |
'SKU名' => '', |
| 170 |
'SKUコード' => '', |
| 171 |
'個数' => '', |
| 172 |
'単価' => '', |
| 173 |
'注文� |
| 174 |
名字' => '', |
| 175 |
'注文� |
| 176 |
名前' => '', |
| 177 |
'注文� |
| 178 |
名字フリガナ' => '', |
| 179 |
'注文� |
| 180 |
名前フリガナ' => '', |
| 181 |
'メールアドレス' => '', |
| 182 |
'注文� |
| 183 |
郵便番号' => '', |
| 184 |
'注文� |
| 185 |
住所:都道府県' => '', |
| 186 |
'注文� |
| 187 |
住所:市区町村' => '', |
| 188 |
'注文� |
| 189 |
住所:番地' => '', |
| 190 |
'注文� |
| 191 |
住所:ビル名' => '', |
| 192 |
'注文� |
| 193 |
電話番号' => '', |
| 194 |
'注文� |
| 195 |
FAX番号' => '', |
| 196 |
'送付� |
| 197 |
�名字' => '', |
| 198 |
'送付� |
| 199 |
�名前' => '', |
| 200 |
'送付� |
| 201 |
�名字フリガナ' => '', |
| 202 |
'送付� |
| 203 |
�名前フリガナ' => '', |
| 204 |
'送付� |
| 205 |
�郵便番号' => '', |
| 206 |
'送付� |
| 207 |
�住所:都道府県' => '', |
| 208 |
'送付� |
| 209 |
�住所:市区町村' => '', |
| 210 |
'送付� |
| 211 |
�住所:番地' => '', |
| 212 |
'送付� |
| 213 |
�住所:ビル名' => '', |
| 214 |
'送付� |
| 215 |
�電話番号' => '', |
| 216 |
'決済方法' => '', |
| 217 |
'� |
| 218 |
�送方法' => '', |
| 219 |
'備考' => '', |
| 220 |
'お届け予定日' => '', |
| 221 |
'お届け予定時間' => '', |
| 222 |
'� |
| 223 |
�送会社名' => '', |
| 224 |
'� |
| 225 |
�送追跡番号' => '', |
| 226 |
'商品合計' => '', |
| 227 |
'送料' => '', |
| 228 |
'消費税' => '', |
| 229 |
'代引料' => '', |
| 230 |
'値引き' => '', |
| 231 |
'ポイント利用額' => '', |
| 232 |
'請求金額' => '', |
| 233 |
'消費税区分' => '', |
| 234 |
'管理� |
| 235 |
メモ' => '', |
| 236 |
); |
| 237 |
$ldata = apply_filters( 'usces_filter_ganbare_tencho_column', $ldata ); |
| 238 |
foreach ( $ldata as $lkey => $lvalue ) { |
| 239 |
$line .= '"' . $lkey . '",'; |
| 240 |
} |
| 241 |
$line = trim( $line, ',' ); |
| 242 |
$line .= "\r\n"; |
| 243 |
|
| 244 |
foreach ( (array) $ids as $order_id ) { |
| 245 |
|
| 246 |
$data = $usces->get_order_data( $order_id, 'direct' ); |
| 247 |
$delivery = unserialize( $data['order_delivery'] ); |
| 248 |
$cart = usces_get_ordercartdata( $order_id ); |
| 249 |
if ( isset( $delivery['delivery_flag'] ) && 2 === (int) $delivery['delivery_flag'] && ! empty( $data['mem_id'] ) && function_exists( 'msa_get_orderdestination' ) ) { |
| 250 |
$orderdestination = msa_get_orderdestination( $order_id ); |
| 251 |
} else { |
| 252 |
$orderdestination = array(); |
| 253 |
} |
| 254 |
|
| 255 |
$deco_order_id = usces_get_deco_order_id( $order_id ); |
| 256 |
|
| 257 |
if ( ! empty( $data['order_delivery_date'] ) && $this->isdate( $data['order_delivery_date'] ) ) { |
| 258 |
$arrivaldate = $data['order_delivery_date']; |
| 259 |
} else { |
| 260 |
$arrivaldate = ''; |
| 261 |
} |
| 262 |
if ( ! empty( $data['order_delivery_time'] ) ) { |
| 263 |
$arrivaltime = $data['order_delivery_time']; |
| 264 |
} else { |
| 265 |
$arrivaltime = ''; |
| 266 |
} |
| 267 |
|
| 268 |
$order_date = date( 'Ymd', strtotime( $data['order_date'] ) ); |
| 269 |
$total_full_price = $data['order_item_total_price'] - $data['order_usedpoint'] + $data['order_discount'] + $data['order_shipping_charge'] + $data['order_cod_fee'] + $data['order_tax']; |
| 270 |
if ( $total_full_price < 0 ) { |
| 271 |
$total_full_price = 0; |
| 272 |
} |
| 273 |
$payments = usces_get_payments_by_name( $data['order_payment_name'] ); |
| 274 |
$delivery_method_name = usces_delivery_method_name( $data['order_delivery_method'], 'return' ); |
| 275 |
$order_memo = $usces->get_order_meta_value( 'order_memo', $order_id ); |
| 276 |
$delivery_company = $usces->get_order_meta_value( 'delivery_company', $order_id ); |
| 277 |
$tracking_number = $usces->get_order_meta_value( apply_filters( 'usces_filter_tracking_meta_key', 'tracking_number' ), $order_id ); |
| 278 |
$order_condition = unserialize( $data['order_condition'] ); |
| 279 |
$tax_div = ( 'include' == $order_condition['tax_mode'] ) ? '税込' : '税別'; |
| 280 |
|
| 281 |
$cart_count = ( $cart && is_array( $cart ) ) ? count( $cart ) : 0; |
| 282 |
for ( $i = 0; $i < $cart_count; $i++ ) { |
| 283 |
$cart_row = $cart[ $i ]; |
| 284 |
$group_id = $cart_row['group_id']; |
| 285 |
if ( isset( $delivery['delivery_flag'] ) && 2 === (int) $delivery['delivery_flag'] && ! empty( $data['mem_id'] ) && isset( $orderdestination[ $group_id ] ) && function_exists( 'msa_get_destination' ) ) { |
| 286 |
$destination_info = msa_get_destination( $data['mem_id'], $orderdestination[ $group_id ]['destination_id'] ); |
| 287 |
} else { |
| 288 |
$destination_info = array(); |
| 289 |
} |
| 290 |
|
| 291 |
$ldata['受注番号'] = $deco_order_id; |
| 292 |
$ldata['レコードナンバー'] = $i + 1; |
| 293 |
$ldata['注文日時'] = $data['order_date']; |
| 294 |
$ldata['商品名'] = $cart_row['item_name']; |
| 295 |
$ldata['商品コード'] = $cart_row['item_code']; |
| 296 |
$ldata['SKU名'] = $cart_row['sku_name']; |
| 297 |
$ldata['SKUコード'] = $cart_row['sku']; |
| 298 |
$ldata['個数'] = $cart_row['quantity']; |
| 299 |
$ldata['単価'] = usces_crform( $cart_row['price'], false, false, 'return', false ); |
| 300 |
$ldata['注文� |
| 301 |
名字'] = $data['order_name1']; |
| 302 |
$ldata['注文� |
| 303 |
名前'] = $data['order_name2']; |
| 304 |
$ldata['注文� |
| 305 |
名字フリガナ'] = $data['order_name3']; |
| 306 |
$ldata['注文� |
| 307 |
名前フリガナ'] = $data['order_name4']; |
| 308 |
$ldata['メールアドレス'] = $data['order_email']; |
| 309 |
$ldata['注文� |
| 310 |
郵便番号'] = $data['order_zip']; |
| 311 |
$ldata['注文� |
| 312 |
住所:都道府県'] = $data['order_pref']; |
| 313 |
$ldata['注文� |
| 314 |
住所:市区町村'] = $data['order_address1']; |
| 315 |
$ldata['注文� |
| 316 |
住所:番地'] = $data['order_address2']; |
| 317 |
$ldata['注文� |
| 318 |
住所:ビル名'] = $data['order_address3']; |
| 319 |
$ldata['注文� |
| 320 |
電話番号'] = $data['order_tel']; |
| 321 |
$ldata['注文� |
| 322 |
FAX番号'] = $data['order_fax']; |
| 323 |
|
| 324 |
if ( ! empty( $destination_info ) ) { |
| 325 |
$ldata['送付� |
| 326 |
�名字'] = $destination_info['msa_name']; |
| 327 |
$ldata['送付� |
| 328 |
�名前'] = $destination_info['msa_name2']; |
| 329 |
$ldata['送付� |
| 330 |
�名字フリガナ'] = $destination_info['msa_furigana']; |
| 331 |
$ldata['送付� |
| 332 |
�名前フリガナ'] = $destination_info['msa_furigana2']; |
| 333 |
$ldata['送付� |
| 334 |
�郵便番号'] = $destination_info['msa_zip']; |
| 335 |
$ldata['送付� |
| 336 |
�住所:都道府県'] = $destination_info['msa_pref']; |
| 337 |
$ldata['送付� |
| 338 |
�住所:市区町村'] = $destination_info['msa_address1']; |
| 339 |
$ldata['送付� |
| 340 |
�住所:番地'] = $destination_info['msa_address2']; |
| 341 |
$ldata['送付� |
| 342 |
�住所:ビル名'] = $destination_info['msa_address3']; |
| 343 |
$ldata['送付� |
| 344 |
�電話番号'] = $destination_info['msa_tel']; |
| 345 |
} else { |
| 346 |
$ldata['送付� |
| 347 |
�名字'] = $delivery['name1']; |
| 348 |
$ldata['送付� |
| 349 |
�名前'] = $delivery['name2']; |
| 350 |
$ldata['送付� |
| 351 |
�名字フリガナ'] = isset( $delivery['name3'] ) ? $delivery['name3'] : ''; |
| 352 |
$ldata['送付� |
| 353 |
�名前フリガナ'] = isset( $delivery['name4'] ) ? $delivery['name4'] : ''; |
| 354 |
$ldata['送付� |
| 355 |
�郵便番号'] = $delivery['zipcode']; |
| 356 |
$ldata['送付� |
| 357 |
�住所:都道府県'] = $delivery['pref']; |
| 358 |
$ldata['送付� |
| 359 |
�住所:市区町村'] = $delivery['address1']; |
| 360 |
$ldata['送付� |
| 361 |
�住所:番地'] = $delivery['address2']; |
| 362 |
$ldata['送付� |
| 363 |
�住所:ビル名'] = $delivery['address3']; |
| 364 |
$ldata['送付� |
| 365 |
�電話番号'] = $delivery['tel']; |
| 366 |
} |
| 367 |
|
| 368 |
$ldata['決済方法'] = $data['order_payment_name']; |
| 369 |
$ldata['� |
| 370 |
�送方法'] = $delivery_method_name; |
| 371 |
$ldata['備考'] = $data['order_note']; |
| 372 |
$ldata['お届け予定日'] = $arrivaldate; |
| 373 |
$ldata['お届け予定時間'] = $arrivaltime; |
| 374 |
$ldata['� |
| 375 |
�送会社名'] = $delivery_company; |
| 376 |
$ldata['� |
| 377 |
�送追跡番号'] = $tracking_number; |
| 378 |
$ldata['商品合計'] = usces_crform( $data['order_item_total_price'], false, false, 'return', false ); |
| 379 |
$ldata['送料'] = usces_crform( $data['order_shipping_charge'], false, false, 'return', false ); |
| 380 |
$ldata['消費税'] = usces_crform( $data['order_tax'], false, false, 'return', false ); |
| 381 |
$ldata['代引料'] = usces_crform( $data['order_cod_fee'], false, false, 'return', false ); |
| 382 |
$ldata['値引き'] = usces_crform( $data['order_discount'], false, false, 'return', false ); |
| 383 |
$ldata['ポイント利用額'] = $data['order_usedpoint']; |
| 384 |
$ldata['請求金額'] = usces_crform( $total_full_price, false, false, 'return', false ); |
| 385 |
$ldata['消費税区分'] = $tax_div; |
| 386 |
$ldata['管理� |
| 387 |
メモ'] = $order_memo; |
| 388 |
|
| 389 |
$args = compact( 'cart_row', 'i', 'destination_info', 'data', 'delivery', 'cart', 'order_id' ); |
| 390 |
$ldata = apply_filters( 'usces_filter_ganbare_tencho_data', $ldata, $args ); |
| 391 |
|
| 392 |
foreach ( $ldata as $lkey => $lvalue ) { |
| 393 |
$line .= '"' . $lvalue . '",'; |
| 394 |
} |
| 395 |
$line = trim( $line, ',' ); |
| 396 |
$line .= "\r\n"; |
| 397 |
} |
| 398 |
} |
| 399 |
ob_end_clean(); |
| 400 |
$line = mb_convert_encoding( $line, 'SJIS-win', 'UTF-8' ); |
| 401 |
header( 'Content-Type: application/octet-stream' ); |
| 402 |
header( "Content-Disposition: attachment; filename=\"$filename\"" ); |
| 403 |
print( $line ); |
| 404 |
exit(); |
| 405 |
} |
| 406 |
|
| 407 |
/** |
| 408 |
* Date validity check |
| 409 |
* |
| 410 |
* @param string $date Date text. |
| 411 |
* @return bool |
| 412 |
*/ |
| 413 |
public function isdate( $date ) { |
| 414 |
try { |
| 415 |
if ( empty( $date ) ) { |
| 416 |
return false; |
| 417 |
} |
| 418 |
new DateTime( $date ); |
| 419 |
return true; |
| 420 |
} catch ( Exception $e ) { |
| 421 |
return false; |
| 422 |
} |
| 423 |
} |
| 424 |
} |
| 425 |
|