|
|
@@ -0,0 +1,173 @@
|
|
|
+/**
|
|
|
+* @Author: zou.yingbin
|
|
|
+* @Create : 2021/3/10 9:13
|
|
|
+* @Modify : 2021/3/10 9:13
|
|
|
+ */
|
|
|
+
|
|
|
+package models
|
|
|
+
|
|
|
+import (
|
|
|
+ "fmt"
|
|
|
+ "mtp2_if/db"
|
|
|
+ "mtp2_if/mtpcache"
|
|
|
+ "mtp2_if/utils"
|
|
|
+)
|
|
|
+
|
|
|
+// ErmcpAreaStockApply 出入库申请
|
|
|
+type ErmcpAreaStockApply struct {
|
|
|
+ INOUTAPPLYID string `json:"inoutapplyid" xorm:"'INOUTAPPLYID'"` // 申请ID(607+Unix秒时间戳(10位)+xxxxxx)
|
|
|
+ USERID string `json:"userid" xorm:"'USERID'"` // 机构ID
|
|
|
+ INOUTTYPE int32 `json:"inouttype" xorm:"'INOUTTYPE'"` // 出入库类型 - 1:采购入库 2:销售出库 3:生产入库 4:生产出库
|
|
|
+ WRSTANDARDID string `json:"wrstandardid" xorm:"'WRSTANDARDID'"` // 现货商品ID
|
|
|
+ SPOTGOODSMODELID int32 `json:"spotgoodsmodelid" xorm:"'SPOTGOODSMODELID'"` // 现货型号ID
|
|
|
+ SPOTGOODSBRANDID int32 `json:"spotgoodsbrandid" xorm:"'SPOTGOODSBRANDID'"` // 现货品牌ID
|
|
|
+ DELIVERYGOODSID int64 `json:"deliverygoodsid" xorm:"'DELIVERYGOODSID'"` // 现货品种ID
|
|
|
+ SPOTCONTRACTID string `json:"spotcontractid" xorm:"'SPOTCONTRACTID'"` // 关联现货合同ID [1:采购入库 2:销售出库 ]
|
|
|
+ WAREHOUSEINFOID string `json:"warehouseinfoid" xorm:"'WAREHOUSEINFOID'"` // 现货仓库ID
|
|
|
+ QTY float64 `json:"qty" xorm:"'QTY'"` // 数量
|
|
|
+ APPLYSTATUS int32 `json:"applystatus" xorm:"'APPLYSTATUS'"` // 申请状态 - 1:待审核 2:审核通过 3:审核拒绝 4:处理失败 5:已撤回
|
|
|
+ APPLYSRC int32 `json:"applysrc" xorm:"'APPLYSRC'"` // 申请来源 - 1:管理端 2:终端
|
|
|
+ APPLYID int64 `json:"applyid" xorm:"'APPLYID'"` // 申请人
|
|
|
+ APPLYREMARK string `json:"applyremark" xorm:"'APPLYREMARK'"` // 申请备注
|
|
|
+ APPLYTIME string `json:"applytime" xorm:"'APPLYTIME'"` // 申请时间
|
|
|
+ AUDITSRC int32 `json:"auditsrc" xorm:"'AUDITSRC'"` // 审核来源 - 1:管理端 2:终端
|
|
|
+ AUDITID int64 `json:"auditid" xorm:"'AUDITID'"` // 审核人
|
|
|
+ AUDITTIME string `json:"audittime" xorm:"'AUDITTIME'"` // 审核时间
|
|
|
+ AUDITREMARK string `json:"auditremark" xorm:"'AUDITREMARK'"` // 审核备注
|
|
|
+ AUDITTRADEDATE string `json:"audittradedate" xorm:"'AUDITTRADEDATE'"` // 审核交易日(yyyyMMdd)
|
|
|
+ WRSTANDARDNAME string `json:"wrstandardname" xorm:"'WRSTANDARDNAME'"` // 现货商品名称
|
|
|
+ WRSTANDARDCODE string `json:"wrstandardcode" xorm:"'WRSTANDARDCODE'"` // 现货商品代码
|
|
|
+ UNITID int32 `json:"unitid" xorm:"'UNITID'"` // 单位id
|
|
|
+ BRANDNAME string `json:"brandname" xorm:"'BRANDNAME'"` // 品牌名称
|
|
|
+ MODELNAME string `json:"modelname" xorm:"'MODELNAME'"` // 型号名称
|
|
|
+ WAREHOUSENAME string `json:"warehousename" xorm:"'WAREHOUSENAME'"` // 仓库名称
|
|
|
+ WAREHOUSECODE string `json:"warehousecode" xorm:"'WAREHOUSECODE'"` // 仓库代码
|
|
|
+ WAREHOUSETYPE int32 `json:"warehousetype" xorm:"'WAREHOUSETYPE'"` // 仓库类型 - 1 厂库 2 自有库 3 合作库
|
|
|
+ CONTRACTNO string `json:"contractno" xorm:"'CONTRACTNO'"` // 合同编号
|
|
|
+ CONTRACTTYPE int32 `json:"contracttype" xorm:"'CONTRACTTYPE'"` // 现货合同类型 - 1:采购 -1:销售
|
|
|
+ BUYUSERID int64 `json:"buyuserid" xorm:"'BUYUSERID'"` // 采购方userid
|
|
|
+ SELLUSERID int64 `json:"selluserid" xorm:"'SELLUSERID'"` // 销售方userid
|
|
|
+ PRICETYPE int32 `json:"pricetype" xorm:"'PRICETYPE'"` // 定价类型 - 1:一口价 2:点价 3:暂定价
|
|
|
+ CONTRACTQTY float64 `json:"contractqty" xorm:"'CONTRACTQTY'"` // 合同量
|
|
|
+ BUYUSERNAME string `json:"buyusername"` // 采购方名称
|
|
|
+ SELLUSERNAME string `json:"sellusername"` // 销售方名称
|
|
|
+ APPLYNAME string `json:"applyname"` // 申请人名称
|
|
|
+ AUDITNAME string `json:"auditname"` // 审核人名称
|
|
|
+ ENUMDICNAME string `json:"enumdicname"` // 现货商品单位名称
|
|
|
+
|
|
|
+ FilterStatus string `json:"-"` // 查询条件, 申请状态, 逗号隔开
|
|
|
+ FilterType string `json:"-"` // 查询条件, 出入库类型, 逗号隔开
|
|
|
+}
|
|
|
+
|
|
|
+func (r *ErmcpAreaStockApply) calc() {
|
|
|
+ // 采购方名称
|
|
|
+ r.BUYUSERNAME = mtpcache.GetUserNameByUserId(r.BUYUSERID)
|
|
|
+ // 销售方名称
|
|
|
+ r.SELLUSERNAME = mtpcache.GetUserNameByUserId(r.SELLUSERID)
|
|
|
+ // 申请人名称
|
|
|
+ if r.APPLYSRC == 1 {
|
|
|
+ r.APPLYNAME = mtpcache.GetSystemmangerLoginCode(r.APPLYID)
|
|
|
+ }else {
|
|
|
+ r.APPLYNAME = mtpcache.GetLoginCodeByLoginId(r.APPLYID)
|
|
|
+ }
|
|
|
+ // 审核人名称
|
|
|
+ if r.AUDITSRC == 1 {
|
|
|
+ r.AUDITNAME = mtpcache.GetSystemmangerLoginCode(r.AUDITID)
|
|
|
+ }else {
|
|
|
+ r.AUDITNAME = mtpcache.GetLoginCodeByLoginId(r.AUDITID)
|
|
|
+ }
|
|
|
+ // 单位名称
|
|
|
+ r.ENUMDICNAME = mtpcache.GetEnumDicitemName(r.UNITID)
|
|
|
+}
|
|
|
+
|
|
|
+func (r *ErmcpAreaStockApply) buildSql() string {
|
|
|
+ var sqlId utils.SQLVal = "SELECT to_char(t.INOUTAPPLYID) INOUTAPPLYID," +
|
|
|
+ " t.USERID," +
|
|
|
+ " t.INOUTTYPE," +
|
|
|
+ " t.WRSTANDARDID," +
|
|
|
+ " t.SPOTGOODSMODELID," +
|
|
|
+ " t.SPOTGOODSBRANDID," +
|
|
|
+ " t.DELIVERYGOODSID," +
|
|
|
+ " to_char(t.SPOTCONTRACTID) SPOTCONTRACTID," +
|
|
|
+ " to_char(t.WAREHOUSEINFOID) WAREHOUSEINFOID," +
|
|
|
+ " t.QTY," +
|
|
|
+ " t.APPLYSTATUS," +
|
|
|
+ " t.APPLYSRC," +
|
|
|
+ " t.APPLYID," +
|
|
|
+ " t.APPLYREMARK," +
|
|
|
+ " to_char(t.APPLYTIME, 'yyyy-mm-dd hh24:mi:ss') APPLYTIME," +
|
|
|
+ " t.AUDITSRC," +
|
|
|
+ " t.AUDITID," +
|
|
|
+ " to_char(t.AUDITTIME, 'yyyy-mm-dd hh24:mi:ss') AUDITTIME," +
|
|
|
+ " t.AUDITREMARK," +
|
|
|
+ " t.AUDITTRADEDATE," +
|
|
|
+ " w.wrstandardname," +
|
|
|
+ " w.wrstandardcode," +
|
|
|
+ " w.unitid," +
|
|
|
+ " gb.brandname," +
|
|
|
+ " gm.modelname," +
|
|
|
+ " h.warehousename," +
|
|
|
+ " h.warehousecode," +
|
|
|
+ " h.warehousetype," +
|
|
|
+ " s.contractno," +
|
|
|
+ " s.contracttype," +
|
|
|
+ " s.buyuserid," +
|
|
|
+ " s.selluserid," +
|
|
|
+ " s.pricetype," +
|
|
|
+ " s.qty CONTRACTQTY" +
|
|
|
+ " FROM ERMCP_AREAINOUTSTOCKAPPLY t" +
|
|
|
+ " left join wrstandard w" +
|
|
|
+ " on t.wrstandardid = w.wrstandardid" +
|
|
|
+ " left join spotgoodsbrand gb" +
|
|
|
+ " on t.spotgoodsbrandid = gb.brandid" +
|
|
|
+ " left join spotgoodsmodel gm" +
|
|
|
+ " on t.spotgoodsmodelid = gm.modelid" +
|
|
|
+ " left join warehouseinfo h" +
|
|
|
+ " on t.warehouseinfoid = h.autoid" +
|
|
|
+ " left join ermcp_spotcontract s" +
|
|
|
+ " on t.spotcontractid = s.spotcontractid" +
|
|
|
+ " WHERE 1 = 1"
|
|
|
+ // 用户id(必要条件)
|
|
|
+ sqlId.And("t.USERID", r.USERID)
|
|
|
+ // 出入库类型
|
|
|
+ if r.INOUTTYPE > 0 {
|
|
|
+ sqlId.And("t.INOUTTYPE", r.INOUTTYPE)
|
|
|
+ }
|
|
|
+ // 合同id
|
|
|
+ if len(r.SPOTCONTRACTID) > 0 {
|
|
|
+ sqlId.And("t.SPOTCONTRACTID", r.SPOTCONTRACTID)
|
|
|
+ }
|
|
|
+ // 现货商品id
|
|
|
+ if len(r.WRSTANDARDID) > 0 {
|
|
|
+ sqlId.And("t.WRSTANDARDID", r.WRSTANDARDID)
|
|
|
+ }
|
|
|
+ // 品牌id
|
|
|
+ if r.SPOTGOODSBRANDID > 0 {
|
|
|
+ sqlId.And("t.SPOTGOODSBRANDID", r.SPOTGOODSBRANDID)
|
|
|
+ }
|
|
|
+ // 型号id
|
|
|
+ if r.SPOTGOODSMODELID > 0 {
|
|
|
+ sqlId.And("t.SPOTGOODSMODELID", r.SPOTGOODSMODELID)
|
|
|
+ }
|
|
|
+ // 仓库id
|
|
|
+ if len(r.WAREHOUSEINFOID) > 0 {
|
|
|
+ sqlId.And("t.WAREHOUSEINFOID", r.WAREHOUSEINFOID)
|
|
|
+ }
|
|
|
+ // 出入库状态
|
|
|
+ if len(r.FilterStatus) > 0 {
|
|
|
+ sqlId.Join(fmt.Sprintf(" and t.APPLYSTATUS in(%v)", r.FilterStatus))
|
|
|
+ }
|
|
|
+ return sqlId.String()
|
|
|
+}
|
|
|
+
|
|
|
+// 查询库存申请(记录)
|
|
|
+func (r *ErmcpAreaStockApply) GetDataEx() (interface{}, error) {
|
|
|
+ sData := make([]ErmcpAreaStockApply, 0)
|
|
|
+ err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
|
|
|
+ if err == nil {
|
|
|
+ for i := range sData {
|
|
|
+ sData[i].calc()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return sData, err
|
|
|
+}
|