コード例 #1
0
ファイル: csv.php プロジェクト: huylv-hust/ws
 public static function writecsv($post = [])
 {
     $branch = utilities::getAllBranch();
     $branch_code = isset($branch['all_ss_branch'][$post['D01_SS_CD']]) ? $branch['all_ss_branch'][$post['D01_SS_CD']] : '';
     $branch_name = isset($branch['all_branch'][$branch_code]) ? $branch['all_branch'][$branch_code] : '';
     $ss_name = isset($branch['all_ss'][$post['D01_SS_CD']]) ? $branch['all_ss'][$post['D01_SS_CD']] : '';
     if ($post['D01_MOBTEL_NO'] && $post['D01_TEL_NO']) {
         $post['TEL_NUMBER'] = $post['D01_TEL_NO'] . ',' . $post['D01_MOBTEL_NO'];
     } elseif ($post['D01_MOBTEL_NO']) {
         $post['TEL_NUMBER'] = $post['D01_MOBTEL_NO'];
     } elseif ($post['D01_TEL_NO']) {
         $post['TEL_NUMBER'] = $post['D01_TEL_NO'];
     } else {
         $post['TEL_NUMBER'] = '';
     }
     $data[0] = ['保証書番号', '保証期間', '購入日', '購入本数', '顧客名', 'フリガナ', '郵便番号', '住所', '電話番号', '車名', '車番', '右前メーカー', '右前商品名', '右前サイズ', '右前セリアル', '右前本数', '左前メーカー', '左前商品名', '左前サイズ', '左前セリアル', '左前本数', '右後メーカー', '右後商品名', '右後サイズ', '右後セリアル', '右後本数', '左後メーカー', '左後商品名', '左後サイズ', '左後セリアル', '左後本数', 'その他Aメーカー', 'その他A商品名', 'その他Aサイズ', 'その他Aセリアル', 'その他A本数', 'その他Bメーカー', 'その他B商品名', 'その他Bサイズ', 'その他Bセリアル', 'その他B本数', 'POS伝票番号', '支店コード', '支店名', 'SSコード', 'SS名', '作業伝票番号'];
     $data[1] = ['warranty_card_number' => isset($post['M09_WARRANTY_NO']) ? $post['M09_WARRANTY_NO'] : '', 'warranty_period' => isset($post['warranty_period']) ? $post['warranty_period'] : '', 'purchase_date' => isset($post['M09_INP_DATE']) ? $post['M09_INP_DATE'] : '', 'purchase_no' => isset($post['D05_SURYO']) ? $post['D05_SURYO'] : '', 'D01_CUST_NAMEN' => isset($post['D01_CUST_NAMEN']) ? $post['D01_CUST_NAMEN'] : '', 'D01_CUST_NAMEK' => isset($post['D01_CUST_NAMEK']) ? $post['D01_CUST_NAMEK'] : '', 'D01_YUBIN_BANGO' => isset($post['D01_YUBIN_BANGO']) && trim($post['D01_YUBIN_BANGO']) != '' ? substr($post['D01_YUBIN_BANGO'], 0, 3) . '-' . substr($post['D01_YUBIN_BANGO'], 3, 4) : '', 'D01_ADDR' => isset($post['D01_ADDR']) ? $post['D01_ADDR'] : '', 'TEL_NUMBER' => $post['TEL_NUMBER'], 'D02_MODEL_CD' => isset($post['D02_CAR_NAMEN_' . $post['D02_CAR_SEQ_SELECT']]) ? $post['D02_CAR_NAMEN_' . $post['D02_CAR_SEQ_SELECT']] : '', 'D02_CAR_NO' => isset($post['D02_CAR_NO_' . $post['D02_CAR_SEQ_SELECT']]) ? $post['D02_RIKUUN_NAMEN_' . $post['D02_CAR_SEQ_SELECT']] . ' ' . $post['D02_CAR_ID_' . $post['D02_CAR_SEQ_SELECT']] . ' ' . $post['D02_HIRA_' . $post['D02_CAR_SEQ_SELECT']] . ' ' . $post['D02_CAR_NO_' . $post['D02_CAR_SEQ_SELECT']] : '', 'right_front_manu' => isset($post['right_front_manu']) ? $post['right_front_manu'] : '', 'right_front_product' => isset($post['right_front_product']) ? $post['right_front_product'] : '', 'right_front_size' => isset($post['right_front_size']) ? $post['right_front_size'] : '', 'right_front_serial' => isset($post['right_front_serial']) ? $post['right_front_serial'] : '', 'right_front_no' => isset($post['right_front_no']) && $post['right_front_no'] ? $post['right_front_no'] : '', 'left_front_manu' => isset($post['left_front_manu']) ? $post['left_front_manu'] : '', 'left_front_product' => isset($post['left_front_product']) ? $post['left_front_product'] : '', 'left_front_size' => isset($post['left_front_size']) ? $post['left_front_size'] : '', 'left_front_serial' => isset($post['left_front_serial']) ? $post['left_front_serial'] : '', 'left_front_no' => isset($post['left_front_no']) && $post['left_front_no'] ? $post['left_front_no'] : '', 'right_behind_manu' => isset($post['right_behind_manu']) ? $post['right_behind_manu'] : '', 'right_behind_product' => isset($post['right_behind_product']) ? $post['right_behind_product'] : '', 'right_behind_size' => isset($post['right_behind_size']) ? $post['right_behind_size'] : '', 'right_behind_serial' => isset($post['right_behind_serial']) ? $post['right_behind_serial'] : '', 'right_behind_no' => isset($post['right_behind_no']) && $post['right_behind_no'] ? $post['right_behind_no'] : '', 'left_behind_manu' => isset($post['left_behind_manu']) ? $post['left_behind_manu'] : '', 'left_behind_product' => isset($post['left_behind_product']) ? $post['left_behind_product'] : '', 'left_behind_size' => isset($post['left_behind_size']) ? $post['left_behind_size'] : '', 'left_behind_serial' => isset($post['left_behind_serial']) ? $post['left_behind_serial'] : '', 'left_behind_no' => isset($post['left_behind_no']) && $post['left_behind_no'] ? $post['left_behind_no'] : '', 'other_a_manu' => isset($post['other_a_manu']) ? $post['other_a_manu'] : '', 'other_a_product' => isset($post['other_a_product']) ? $post['other_a_product'] : '', 'other_a_size' => isset($post['other_a_size']) ? $post['other_a_size'] : '', 'other_a_serial' => isset($post['other_a_serial']) ? $post['other_a_serial'] : '', 'other_a_no' => isset($post['other_a_no']) && $post['other_a_no'] ? $post['other_a_no'] : '', 'other_b_manu' => isset($post['other_b_manu']) ? $post['other_b_manu'] : '', 'other_b_product' => isset($post['other_b_product']) ? $post['other_b_product'] : '', 'other_b_size' => isset($post['other_b_size']) ? $post['other_b_size'] : '', 'other_b_serial' => isset($post['other_b_serial']) ? $post['other_b_serial'] : '', 'other_b_no' => isset($post['other_b_no']) && $post['other_b_no'] ? $post['other_b_no'] : '', 'D03_POS_DEN_NO' => isset($post['D03_POS_DEN_NO']) ? $post['D03_POS_DEN_NO'] : '', 'branch_code' => $branch_code, 'branch_name' => $branch_name, 'D01_SS_CD' => isset($post['D01_SS_CD']) ? $post['D01_SS_CD'] : '', 'ss_name' => $ss_name, 'D03_DEN_NO' => isset($post['D03_DEN_NO']) ? $post['D03_DEN_NO'] : ''];
     utilities::createFolder('data/csv/');
     $fp = fopen(getcwd() . '/data/csv/' . $post['D03_DEN_NO'] . '.csv', 'w+');
     fputs($fp, $bom = chr(0xef) . chr(0xbb) . chr(0xbf));
     foreach ($data as $key => $value) {
         fputcsv($fp, $value);
     }
     fclose($fp);
 }