/**
* @Author: zou.yingbin
* @Create  : 2021/2/4 11:27
* @Modify  : 2021/2/4 11:27
 */

package ermcp

import (
	"github.com/gin-gonic/gin"
	"mtp2_if/global/app"
	"mtp2_if/global/e"
	"mtp2_if/models"
	"net/http"
)

// 财务日报表请求
type QryReportDayReq struct {
	UserId    int64  `form:"userid" binding:"required"`    //用户ID
	TradeDate string `form:"tradedate" binding:"required"` // 交易日
}

type QryReportFinanceDayRsp models.ErmcpReportDayFR

// QryReportDayFinance 查询财务日报表(菜单:报表查询/财务报表/日报表)
func QryReportDayFinance(c *gin.Context) {
	a := app.GinUtils{Gin: app.Gin{C: c}}
	req := QryReportDayReq{}
	a.DoBindReq(&req)
	m := models.ErmcpReportDayFR{AREAUSERID: req.UserId, RECKONDATE: req.TradeDate}
	a.DoGetDataEx(&m)
}

// 财务日报表款项明细
type QryReportFinanceKxRsp models.ErmcpReportOPLog

// QryReportDayFinanceKx 查询财务日报表款项(菜单:报表查询/财务报表/日报表/款项)
func QryReportDayFinanceKx(c *gin.Context) {
	a := app.GinUtils{Gin: app.Gin{C: c}}
	req := QryReportDayReq{}
	a.DoBindReq(&req)
	m := models.ErmcpReportDayFRKx{USERID: req.UserId, TRADEDATE: req.TradeDate}
	a.DoGetDataEx(&m)
}

// 财务日报表发票明细
type QryReportFinanceFpRsp models.ErmcpReportOPLog

// QryReportDayFinanceFp 查询财务日报表发票(菜单:报表查询/财务报表/日报表/发票)
func QryReportDayFinanceFp(c *gin.Context) {
	a := app.GinUtils{Gin: app.Gin{C: c}}
	req := QryReportDayReq{}
	a.DoBindReq(&req)
	m := models.ErmcpReportOPLog{USERID: req.UserId, TRADEDATE: req.TradeDate, LogTypeFilter: "11, 12"}
	a.DoGetDataEx(&m)
}

// 财务月报表请求
type QryReportMonthReq struct {
	UserId    int64  `form:"userid" binding:"required"`    //用户ID
	CycleTime string `form:"cycletime" binding:"required"` // 周期时间:月(格式:yyyyMM)
}

// 财务月报表应答
type QryReportFinanceMonRsp models.ErmcpReportMonthFR

// QryReportMonthFinance 查询财务月报表(菜单:报表查询/财务报表/月报表)
func QryReportMonthFinance(c *gin.Context) {
	a := app.GinUtils{Gin: app.Gin{C: c}}
	req := QryReportMonthReq{}
	a.DoBindReq(&req)
	m := models.ErmcpReportMonthFR{AREAUSERID: req.UserId, CYCLETIME: req.CycleTime}
	a.DoGetDataEx(&m)
}

// 现货日报表
type QryReportSpotDayRsp models.ErmcpReportDaySpot

// QryReportDaySpot 查询现货日报表(菜单:报表查询/现货报表/现货日报表)
func QryReportDaySpot(c *gin.Context) {
	a := app.GinUtils{Gin: app.Gin{C: c}}
	req := QryReportDayReq{}
	a.DoBindReq(&req)
	m := models.ErmcpReportDaySpot{AREAUSERID: req.UserId, RECKONDATE: req.TradeDate}
	a.DoGetDataEx(&m)
}

// 现货日报表明细请求
type QryReportDaySpotDetailReq struct {
	UserId       int64  `form:"userid" binding:"required"`       //用户ID
	Wrstandardid int64  `form:"wrstandardid" binding:"required"` // 现货商品id
	TradeDate    string `form:"tradedate" binding:"required"`    // 交易日
}

// 现货日报表明细应答
type QryReportDaySpotDetailRsp models.ErmcpReportOPLog

// QryReportDaySpotDetail 查询现货日报表详情(菜单:报表查询/现货报表/现货日报表详情)
func QryReportDaySpotDetail(c *gin.Context) {
	a := app.GinUtils{Gin: app.Gin{C: c}}
	req := QryReportDaySpotDetailReq{}
	a.DoBindReq(&req)
	m := models.ErmcpReportOPLog{USERID: req.UserId, WRSTANDARDID: req.Wrstandardid,
		TRADEDATE: req.TradeDate, LogTypeFilter: "2,3"}
	a.DoGetDataEx(&m)
}

// 现货月报表应答
type QryReportSpotMonRsp models.ErmcpReportMonSpot

// QryReportMonthSpot 查询现货月报表(菜单:报表查询/现货报表/现货月报表)
func QryReportMonthSpot(c *gin.Context) {
	a := app.GinUtils{Gin: app.Gin{C: c}}
	req := QryReportMonthReq{}
	a.DoBindReq(&req)
	m := models.ErmcpReportMonSpot{AREAUSERID: req.UserId, CYCLETIME: req.CycleTime}
	a.DoGetDataEx(&m)
}

// 现货月报表详情请求
type QryReportSpotMonthDetailReq struct {
	UserId       int64  `form:"userid" binding:"required"`       //用户ID
	Wrstandardid int64  `form:"wrstandardid" binding:"required"` // 现货商品id
	CycleTime    string `form:"cycletime" binding:"required"`    // 周期时间:月(格式:yyyyMM)
}

// 现货月报表详情应答
type QryReportSpotMonthDetailRsp models.ErmcpReportDaySpot

// QryReportMonthSpotDetail 查询现货月报表详情(菜单:报表查询/现货月报表/现货月报表详情)
func QryReportMonthSpotDetail(c *gin.Context) {
	a := app.GinUtils{Gin: app.Gin{C: c}}
	req := QryReportSpotMonthDetailReq{}
	a.DoBindReq(&req)
	if len(req.CycleTime) != 6 {
		// 月报表的日期应是6位,如 202101
		a.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
		return
	}
	t1 := req.CycleTime + "01"
	t2 := req.CycleTime + "31"
	m := models.ErmcpReportDaySpot{AREAUSERID: req.UserId, WRSTANDARDID: req.Wrstandardid,
		BeginDate: t1, EndDate: t2}
	a.DoGetDataEx(&m)
}

// QueryReportAreaSpotPLReq
type QueryReportAreaSpotPLReq struct {
	USERID           int64  `form:"userid" binding:"required"`    // 用户id
	WRSTANDARDID     int64  `form:"wrstandardid"`                 // 现货商品ID
	SPOTGOODSBRANDID int32  `form:"spotgoodsbrandid"`             // 品牌ID
	SPOTGOODSMODELID int32  `form:"spotgoodsmodelid"`             // 型号ID
	QUERYTYPE        int32  `form:"querytype" binding:"required"` // 查询类型 1-日报表(或明细) 2-月报表(或明细)
	QUERYDATE        string `form:"querydate" binding:"required"` // 查询日期(格式 日报表YYYYMMDD, 月报表YYYYMM)
}

// QryReportAreaSpotPL
func QryReportAreaSpotPL(c *gin.Context) {
	a := app.GinUtils{Gin: app.Gin{C: c}}
	req := QueryReportAreaSpotPLReq{}
	a.DoBindReq(&req)
	if QueryDate(req.QUERYDATE).IsNumberic(req.QUERYTYPE) {
		m := models.ErmcpReportAreaSpotPL{AREAUSERID: req.USERID, WRSTANDARDID: req.WRSTANDARDID,
			SPOTGOODSBRANDID: req.SPOTGOODSBRANDID, SPOTGOODSMODELID: req.SPOTGOODSMODELID,
			ReportDate: req.QUERYDATE, ReportType: req.QUERYTYPE}
		a.DoGetDataI(&m)
	} else {
		a.Gin.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
	}
}
