<?php
/**
 * Created by PhpStorm.
 * User: boyer
 * Date: 2019/5/4
 * Time: 9:37
 */
// echo strtolower('CONSUMETAX');
// die();
require_once ('../config.php');
require_once("PHPExcel.php");
require_once("PHPExcel/Reader/Excel2007.php");
require_once("PHPExcel/Reader/Excel5.php");
$header = array(
    '系统hs_id'=>'string',
    '海关编码'=>'string',
    '新海关编码是否存在'=>'string',
    'uom1是否一样'=>'string',
    '新uom1'=>'string',
    'uom2是否一样'=>'string',
    '新uom2'=>'string',
    '消费税'=>'string',
    '增值税'=>'string',
);
$excel = new \XLSXWriter();
$excel->writeSheetHeader('sheet1',$header);
$hsCode = Service_Hscodes::getAll();
$db = Common_Common::getAdapter();
foreach ($hsCode as $code){
    $uom = Service_HsUom::getByField($code['hs_code'],'hs_code');
    echo $code['he_id'];
    echo PHP_EOL;
    $row = array(
        'he_id'=>$code['he_id'],
        'hs_code'=>$code['hs_code'],
        'hs_code_exit'=>'',
        'uom_exit'=>'',
       'new_uom'=>'',
        'uom2_exit'=>'',
        'uom2_new'=>'',
        'consumption_tax'=>'',
        'added_value_tax'=>'',
    );
    $new = $db->fetchRow("select * from hs_codes2021 where hs_code='{$code['hs_code']}'");
    if(!empty($new)){
        $row['hs_code_exit']=1;
        if($uom['pu_code_law']!=$new['uom_1']){
            $row['uom_exit']=1;
            $row['new_uom']=$new['uom_1'];
        }else{
            $row['uom_exit']=0;
        }
        if($uom['pu_code_second']!=$new['uom_2']){
            $row['uom2_exit']=1;
            $row['uom2_new']=$new['uom_2'];
        }else{
            $row['uom2_exit']=0;
        }
        if($code['consumption_tax']!=$new['consumption_tax']){
            $row['consumption_tax']=$new['consumption_tax'];
        }
        if($code['added_value_tax']!=$new['added_value_tax']){
            $row['added_value_tax']=$new['added_value_tax'];
        }
    }else{
        $row['hs_code_exit']=0;
    }
$excel->writeSheetRow('sheet1',$row);
}
$excel->writeToFile('hs_code1.xlsx');