package pwc.taxtech.atms.vat.dao;

import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.session.RowBounds;
import pwc.taxtech.atms.MyVatMapper;
import pwc.taxtech.atms.dto.vatdto.VoucherAccountMto;
import pwc.taxtech.atms.dto.vatdto.VoucherBalanceDto;
import pwc.taxtech.atms.vat.entity.ValidationInfo;
import pwc.taxtech.atms.vat.entity.ValidationInfoExample;

@Mapper
public interface ValidationInfoMapper extends MyVatMapper {
    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table ValidationInfo
     *
     * @mbg.generated
     */
    long countByExample(ValidationInfoExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table ValidationInfo
     *
     * @mbg.generated
     */
    int deleteByExample(ValidationInfoExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table ValidationInfo
     *
     * @mbg.generated
     */
    int deleteByPrimaryKey(String ID);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table ValidationInfo
     *
     * @mbg.generated
     */
    int insert(ValidationInfo record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table ValidationInfo
     *
     * @mbg.generated
     */
    int insertSelective(ValidationInfo record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table ValidationInfo
     *
     * @mbg.generated
     */
    List<ValidationInfo> selectByExampleWithRowbounds(ValidationInfoExample example, RowBounds rowBounds);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table ValidationInfo
     *
     * @mbg.generated
     */
    List<ValidationInfo> selectByExample(ValidationInfoExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table ValidationInfo
     *
     * @mbg.generated
     */
    ValidationInfo selectByPrimaryKey(String ID);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table ValidationInfo
     *
     * @mbg.generated
     */
    int updateByExampleSelective(@Param("record") ValidationInfo record, @Param("example") ValidationInfoExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table ValidationInfo
     *
     * @mbg.generated
     */
    int updateByExample(@Param("record") ValidationInfo record, @Param("example") ValidationInfoExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table ValidationInfo
     *
     * @mbg.generated
     */
    int updateByPrimaryKeySelective(ValidationInfo record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table ValidationInfo
     *
     * @mbg.generated
     */
    int updateByPrimaryKey(ValidationInfo record);

    @Select("SELECT  " +
            "    c.AcctCode as AccountCode, COUNT(1) as Count " +
            "FROM " +
            "    CompanyBalance c " +
            "        LEFT JOIN " +
            "    EnterpriseAccount a ON c.AcctCode = a.AcctCode " +
            "WHERE " +
            "    a.IsDummy != 1 " +
            "        AND (c.AcctCode != '' AND c.AcctCode != NULL) " +
            "GROUP BY c.AcctCode")
    List<VoucherAccountMto> getCompanyBalanceAcctChecks();

    @Select("SELECT  " +
            "    c.AcctCode as AccountCode, COUNT(1) as Count " +
            "FROM " +
            "    Voucher c " +
            "        LEFT JOIN " +
            "    EnterpriseAccount a ON c.AcctCode = a.AcctCode " +
            "WHERE " +
            "    a.IsDummy != 1 " +
            "        AND (c.AcctCode != '' AND c.AcctCode != NULL) " +
            "GROUP BY c.AcctCode")
    List<VoucherAccountMto> getVoucherAccountChecks();


    @Select("SELECT  " +
            "    vv.VID, " +
            "    vv.Group, " +
            "    vv.CurrentPeriodBo, " +
            "    vv.CustomerCode, " +
            "    vv.Summary, " +
            "    vv.AcctCode, " +
            "    vv.Debit, " +
            "    vv.Credit, " +
            "    vv.ItemID " +
            "FROM " +
            "    Voucher vv " +
            "        JOIN " +
            "    (SELECT  " +
            "        v.VID, " +
            "            v.CurrentPeriodBo, " +
            "            v.Group, " +
            "            MAX(v.Date) AS `Date`, " +
            "            SUM(v.Debit) AS Debit, " +
            "            SUM(v.Credit) AS Credit " +
            "    FROM " +
            "        Voucher v " +
            "    GROUP BY v.VID , v.CurrentPeriodBo , v.Group " +
            "    HAVING Debit != Credit) q ON vv.VID = q.VID AND vv.CurrentPeriodBo = q.CurrentPeriodBo " +
            "        AND vv.Group = q.Group " +
            "")
    List<VoucherBalanceDto>getSingleVoucherCheck();
    
}