<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.cim.idm.dao.CostCenterDao">

    <select id="getCostCenter" resultType="com.cim.idm.model.CostCenter">
        select id, cost_code costCode, cost_name costName, erp_factory erpFactory, department, division
        from cost_center
        where division = 'Y'
        and erp_factory = #{erpFactory}
    </select>

    <select id="getUserInfo" resultType="java.util.Map">
        SELECT USERID, USERNAME FROM USERINFO
    </select>

    <update id="updatePacking">
        UPDATE MATERIALPACKING SET
        SALESHIPREQUESTNAME = #{SALESHIPREQUESTNAME, jdbcType=VARCHAR},
        SALESHIPREQUESTDETAILNAME = #{SALESHIPREQUESTDETAILNAME, jdbcType=VARCHAR},
        POSTSTATUS = #{POSTSTATUS, jdbcType=VARCHAR},
        OLDSALESHIPREQUESTNAME = #{saleshiprequestname, jdbcType=VARCHAR},
        OLDSALESHIPREQUESTDETAILNAME = #{saleShipRequestDetailName, jdbcType=VARCHAR}
        WHERE MATERIALPACKINGNAME = #{MATERIALPACKINGNAME, jdbcType=VARCHAR}
    </update>

    <insert id="insertPackingChenk">
        insert into MATERIALPACKINGCHECK(MATERIALPACKINGNAME,SALESHIPREQUESTNAME,
              SALESHIPREQUESTDETAILNAME,SITENAME,IS_CHECK, MATERIALSPECNAME,
              CHARGE,PHASE,CUSTOMNO,CAREER_ASSISTANCE,POSTSTATUS, MAIN_ID, OLDSALESHIPREQUESTNAME,OLDSALESHIPREQUESTDETAILNAME)
        values(#{MATERIALPACKINGNAME, jdbcType=VARCHAR}, #{SALESHIPREQUESTNAME, jdbcType=VARCHAR},
               #{SALESHIPREQUESTDETAILNAME, jdbcType=VARCHAR}, #{SITENAME, jdbcType=VARCHAR}, 'N',
               #{materialSpecName, jdbcType=VARCHAR}, #{charge, jdbcType=VARCHAR}, #{phase, jdbcType=VARCHAR},
               #{customno, jdbcType=VARCHAR},#{careerAssistance, jdbcType=VARCHAR},
               #{POSTSTATUS, jdbcType=VARCHAR}, #{id, jdbcType=VARCHAR},#{saleshiprequestname, jdbcType=VARCHAR},#{saleShipRequestDetailName, jdbcType=VARCHAR})
    </insert>

    <insert id="insertPackingChenkMain">
        insert into MATERIALPACKINGCHECK_MAIN(ID, CAREER_ASSISTANCE, STATUS, SALESHIPREQUESTNAME, SALESHIPREQUESTDETAILNAME)
        values(#{id, jdbcType=VARCHAR}, #{careerAssistance, jdbcType=VARCHAR}, #{status, jdbcType=VARCHAR},
               #{saleshiprequestname, jdbcType=VARCHAR}, #{saleshiprequestdetailname, jdbcType=VARCHAR})
    </insert>

    <update id="updateCheckMain" parameterType="java.lang.String">
        update MATERIALPACKINGCHECK_MAIN set STATUS = '1'
        where ID = #{mainId, jdbcType=VARCHAR}
    </update>

    <update id="editMaterialPackingName">
        update MATERIALPACKING set REMARK = #{remark, jdbcType=VARCHAR},CHARGE = #{charge, jdbcType=VARCHAR},
                                   MATERIALPACKINGNAME = #{materialPackingNameNew, jdbcType=VARCHAR}
        WHERE MATERIALPACKINGNAME = #{materialPackingName, jdbcType=VARCHAR}
        and SITENAME = #{siteName, jdbcType=VARCHAR}
    </update>

    <select id="getMaterialInfo" resultType="com.cim.idm.model.vo.MaterialInfo"
            parameterType="java.lang.String">
        select * from MATERIALSPEC where MATERIALSPECNAME = #{materialSpecName}
    </select>

    <select id="getMaterialPacking" resultType="java.util.LinkedHashMap">
        select * from MATERIALPACKING
        where MATERIALSPECNAME = #{materialSpecName}
        AND SITENAME = #{siteName}
        AND ERPFACTORY = #{erpFactory}
        AND ERPLOCATION = #{erpLocation}
        <if test="location != null || location != ''">
            AND LOCATIONNAME = #{location}
        </if>
        AND stockstate = 'Stocked'
        order by CREATETIME
    </select>

    <select id="getByMaterialPackingName" resultType="java.util.HashMap" parameterType="java.lang.String">
        select * from MATERIALPACKING
        where MATERIALPACKINGNAME = #{newBoxId}
    </select>

    <update id="updateQty">
        update MATERIALPACKING set MATERIALQUANTITY = MATERIALQUANTITY - #{materialQuantityFont},
                                   LASTEVENTTIME = SYSDATE, LASTEVENTUSER = #{user}
        where MATERIALPACKINGNAME = #{materialPackingName}
    </update>
</mapper>