浏览代码

Merge branch 'develop' of http://code.dashoo.cn/chengjian/opms_backend into develop

lai 2 年之前
父节点
当前提交
c22343b3cb

+ 15 - 0
opms_parent/app/dao/contract/internal/ctr_contract_invoice.go

@@ -42,6 +42,11 @@ type ctrContractInvoiceColumns struct {
 	InvoiceCode       string // 发票号码
 	ActualInvoiceDate string // 实际开票日期
 	CourierCode       string // 快递单号
+	TaxNo             string // 税号
+	Address           string // 开票地址
+	Phone             string // 开票电话
+	Bank              string // 开户行
+	AccountNo         string // 账号
 	Remark            string // 备注
 	CreatedBy         string // 创建者
 	CreatedName       string // 创建人
@@ -72,6 +77,11 @@ var (
 			InvoiceCode:       "invoice_code",
 			ActualInvoiceDate: "actual_invoice_date",
 			CourierCode:       "courier_code",
+			TaxNo:             "tax_no",
+			Address:           "address",
+			Phone:             "phone",
+			Bank:              "bank",
+			AccountNo:         "account_no",
 			Remark:            "remark",
 			CreatedBy:         "created_by",
 			CreatedName:       "created_name",
@@ -104,6 +114,11 @@ func NewCtrContractInvoiceDao(tenant string) CtrContractInvoiceDao {
 			InvoiceCode:       "invoice_code",
 			ActualInvoiceDate: "actual_invoice_date",
 			CourierCode:       "courier_code",
+			TaxNo:             "tax_no",
+			Address:           "address",
+			Phone:             "phone",
+			Bank:              "bank",
+			AccountNo:         "account_no",
 			Remark:            "remark",
 			CreatedBy:         "created_by",
 			CreatedName:       "created_name",

+ 21 - 11
opms_parent/app/model/contract/ctr_contract_invoice.go

@@ -41,10 +41,15 @@ type CtrContractInvoiceAddReq struct {
 	InvoiceDate   *gtime.Time `json:"invoiceDate"`   // 开票日期
 	InvoiceType   string      `json:"invoiceType"`   // 开票类型
 	// ApproStatus       string      `json:"approStatus"`       // 审核状态 10 未通过 20 已通过
-	InvoiceCode       string      `json:"invoiceCode"`       // 发票号码
-	ActualInvoiceDate *gtime.Time `json:"actualInvoiceDate"` // 实际开票日期
-	CourierCode       string      `json:"courierCode"`       // 快递单号
-	Remark            string      `json:"remark"`            // 备注
+	InvoiceCode       string      `json:"invoiceCode"`               // 发票号码
+	ActualInvoiceDate *gtime.Time `json:"actualInvoiceDate"`         // 实际开票日期
+	CourierCode       string      `json:"courierCode"`               // 快递单号
+	TaxNo             string      `json:"taxNo"  v:"required#税号为空"`  // 税号
+	Address           string      `json:"address" v:"required#地址为空"` // 开票地址
+	Phone             string      `json:"phone"  v:"required#电话为空"`  // 开票电话
+	Bank              string      `json:"bank" `                     // 开户行
+	AccountNo         string      `json:"accountNo"  `               // 账号
+	Remark            string      `json:"remark"`                    // 备注
 }
 
 type CtrContractInvoiceUpdateReq struct {
@@ -54,13 +59,18 @@ type CtrContractInvoiceUpdateReq struct {
 	// ContractId        int         `json:"contractId"`        // 关联合同
 	// ContractCode      string      `json:"contractCode"`      // 合同编号
 	// ContractAmount    float64     `json:"contractAmount"`    // 合同金额
-	InvoiceAmount     *float64    `json:"invoiceAmount"`     // 开票金额
-	InvoiceDate       *gtime.Time `json:"invoiceDate"`       // 开票日期
-	InvoiceType       string      `json:"invoiceType"`       // 开票类型
-	ApproStatus       string      `json:"approStatus"`       // 审核状态 10 未通过 20 已通过
-	InvoiceCode       string      `json:"invoiceCode"`       // 发票号码
-	ActualInvoiceDate *gtime.Time `json:"actualInvoiceDate"` // 实际开票日期
-	CourierCode       string      `json:"courierCode"`       // 快递单号
+	InvoiceAmount     *float64    `json:"invoiceAmount"`             // 开票金额
+	InvoiceDate       *gtime.Time `json:"invoiceDate"`               // 开票日期
+	InvoiceType       string      `json:"invoiceType"`               // 开票类型
+	ApproStatus       string      `json:"approStatus"`               // 审核状态 10 未通过 20 已通过
+	InvoiceCode       string      `json:"invoiceCode"`               // 发票号码
+	ActualInvoiceDate *gtime.Time `json:"actualInvoiceDate"`         // 实际开票日期
+	CourierCode       string      `json:"courierCode"`               // 快递单号
+	TaxNo             string      `json:"taxNo"  v:"required#税号为空"`  // 税号
+	Address           string      `json:"address" v:"required#地址为空"` // 开票地址
+	Phone             string      `json:"phone"  v:"required#电话为空"`  // 开票电话
+	Bank              string      `json:"bank" `                     // 开户行
+	AccountNo         string      `json:"accountNo"  `               // 账号
 	Remark            *string     `json:"remark"`
 }
 

+ 5 - 0
opms_parent/app/model/contract/internal/ctr_contract_invoice.go

@@ -23,6 +23,11 @@ type CtrContractInvoice struct {
 	InvoiceCode       string      `orm:"invoice_code"        json:"invoiceCode"`       // 发票号码
 	ActualInvoiceDate *gtime.Time `orm:"actual_invoice_date" json:"actualInvoiceDate"` // 实际开票日期
 	CourierCode       string      `orm:"courier_code"        json:"courierCode"`       // 快递单号
+	TaxNo             string      `orm:"tax_no"              json:"taxNo"`             // 税号
+	Address           string      `orm:"address"             json:"address"`           // 开票地址
+	Phone             string      `orm:"phone"               json:"phone"`             // 开票电话
+	Bank              string      `orm:"bank"                json:"bank"`              // 开户行
+	AccountNo         string      `orm:"account_no"          json:"accountNo"`         // 账号
 	Remark            string      `orm:"remark"              json:"remark"`            // 备注
 	CreatedBy         int         `orm:"created_by"          json:"createdBy"`         // 创建者
 	CreatedName       string      `orm:"created_name"        json:"createdName"`       // 创建人

+ 5 - 3
opms_parent/app/model/work/deliver_order.go

@@ -21,13 +21,15 @@ type DeliverOrderGetRsp struct {
 	Plan             []*DeliverOrderImpPlan    `json:"plan"`
 	Product          []*DeliverOrderProduct    `json:"product"`
 	ProgressProducts []*DeliverProgressProduct `json:"progressProducts"`
-	Number           int                       `json:"number"` // 发货单数量
+	Number           int                       `json:"number"`  // 发货单数量
+	Number2          int                       `json:"number2"` // 安装单数量
 }
 
 type DeliverOrderInfo struct {
 	DeliverOrder
-	Products string `json:"products"`
-	SaleId   int    `json:"saleId"`
+	Products      string `json:"products"`
+	SaleId        int    `json:"saleId"`
+	SignatoryUnit string `orm:"signatory_unit"        json:"signatoryUnit"` // 合同签订单位
 }
 
 type DeliverOrderListReq struct {

+ 12 - 10
opms_parent/app/model/work/deliver_order_imp_progress.go

@@ -31,13 +31,13 @@ type DeliverOrderProgressAddReq struct {
 	PlanId          int         `json:"planId" v:"required#请输入工单计划ID"`         // 关联实施计划
 	DeliverOrderId  int         `json:"deliverOrderId" v:"required#请输入交付订单ID"` // 关联交付订单ID
 	ProgressTitle   string      `json:"progressTitle" v:"required#请输入任务标题"`    // 任务标题
-	ProgressContext string      `json:"progressContext"`                       // 任务内容
+	ProgressContext string      `json:"progressContext"`                              // 任务内容
 	StartDate       *gtime.Time `json:"startDate" v:"required#请输入开始时间"`        // 开始时间
 	EndDate         *gtime.Time `json:"endDate" v:"required#请输入结束时间"`          // 结束时间
-	ReaStartDate    *gtime.Time `json:"reaStartDate"`                          // 实际开始时间
-	ReaEndDate      *gtime.Time `json:"reaEndDate"`                            // 实际结束时间
-	ProgressLevel   string      `json:"progressLevel"`                         // 优先级(10最高 20普通 30较低 )
-	Remark          string      `json:"remark"`                                // 备注
+	ReaStartDate    *gtime.Time `json:"reaStartDate"`                                 // 实际开始时间
+	ReaEndDate      *gtime.Time `json:"reaEndDate"`                                   // 实际结束时间
+	ProgressLevel   string      `json:"progressLevel"`                                // 优先级(10最高 20普通 30较低 )
+	Remark          string      `json:"remark"`                                       // 备注
 }
 
 type DeliverOrderProgressUpdateReq struct {
@@ -111,11 +111,13 @@ type ConfirmArrivalReq struct {
 }
 
 type CompleteInstallReq struct {
-	Id          int         `json:"id" v:"required#请输入Id"`
-	InstallDate *gtime.Time `json:"installDate"` // 安装日期
-	FileUrl     string      `json:"fileUrl"`     // 附件
-	FileName    string      `json:"fileName"`    // 附件名称
-	Remark      string      `json:"remark"`      // 备注
+	Id                    int         `json:"id" v:"required#请输入Id"`
+	InstallDate           *gtime.Time `json:"installDate"`           // 安装日期
+	FileUrl               string      `json:"fileUrl"`               // 附件
+	FileName              string      `json:"fileName"`              // 附件名称
+	Remark                string      `json:"remark"`                // 备注
+	InstallProductIdArr   []int       `json:"installProductIdArr"`   // 安装产品的Id数组
+	UninstallProductIdArr []int       `json:"uninstallProductIdArr"` // 未安装产品的Id数组
 }
 
 type UpdateProductReq struct {

+ 49 - 1
opms_parent/app/service/contract/ctr_contract_invoice.go

@@ -171,6 +171,11 @@ func (s CtrContractInvoiceService) Add(ctx context.Context, req *model.CtrContra
 		InvoiceCode:       req.InvoiceCode,
 		ActualInvoiceDate: req.ActualInvoiceDate,
 		CourierCode:       req.CourierCode,
+		TaxNo:             req.TaxNo,
+		Address:           req.Address,
+		Phone:             req.Phone,
+		Bank:              req.Bank,
+		AccountNo:         req.AccountNo,
 		Remark:            req.Remark,
 		CreatedBy:         int(s.userInfo.Id),
 		CreatedName:       s.userInfo.NickName,
@@ -273,8 +278,23 @@ func (s CtrContractInvoiceService) Update(ctx context.Context, req *model.CtrCon
 	if req.CourierCode != "" {
 		toupdate["courier_code"] = req.CourierCode
 	}
+	if req.TaxNo != "" {
+		toupdate["tax_no"] = req.TaxNo
+	}
+	if req.Address != "" {
+		toupdate["address"] = req.Address
+	}
+	if req.Phone != "" {
+		toupdate["phone"] = req.Phone
+	}
+	if req.Bank != "" {
+		toupdate["bank"] = req.Bank
+	}
+	if req.AccountNo != "" {
+		toupdate["account_no"] = req.AccountNo
+	}
 	if req.Remark != nil {
-		toupdate["remark"] = *req.Remark
+		toupdate["phone"] = *req.Remark
 	}
 	if len(toupdate) != 0 {
 		toupdate["updated_by"] = int(s.userInfo.Id)
@@ -393,6 +413,14 @@ func (s CtrContractInvoiceService) InvoiceApply(ctx context.Context, req *model.
 		strconv.Itoa(invoice.Id),
 		strconv.Itoa(s.userInfo.Id),
 	}, ":")
+	bankAndAccount := invoice.Bank
+	if invoice.AccountNo != "" {
+		if bankAndAccount == "" {
+			bankAndAccount += invoice.AccountNo
+		} else {
+			bankAndAccount += "、" + invoice.AccountNo
+		}
+	}
 	_, err = workflowSrv.StartProcessInstance(bizCode, "31", "", &workflow.StartProcessInstanceRequest{
 		ProcessCode: &InvoiceApplyProcessCode,
 		FormComponentValues: []*workflow.StartProcessInstanceRequestFormComponentValues{
@@ -437,6 +465,26 @@ func (s CtrContractInvoiceService) InvoiceApply(ctx context.Context, req *model.
 				Name:  utils.String("开票金额(元)"),
 				Value: utils.String(strconv.FormatFloat(invoice.InvoiceAmount, 'f', 2, 64)),
 			},
+			{
+				Id:    utils.String("TextField_1Z4M0MOV8T9C0"),
+				Name:  utils.String("税号"),
+				Value: utils.String(invoice.TaxNo),
+			},
+			{
+				Id:    utils.String("TextField_Z1KCAYC186O0"),
+				Name:  utils.String("地址、电话"),
+				Value: utils.String(invoice.Address + "、" + invoice.Phone),
+			},
+			{
+				Id:    utils.String("TextField_212KJ2MPKX340"),
+				Name:  utils.String("开户行、账号"),
+				Value: utils.String(bankAndAccount),
+			},
+			{
+				Id:    utils.String("TextField_7OR3HRJCW100"),
+				Name:  utils.String("备注"),
+				Value: utils.String(invoice.Remark),
+			},
 		},
 	})
 	if err != nil {

+ 11 - 3
opms_parent/app/service/home/home.go

@@ -95,7 +95,7 @@ func (s *HomeService) QueryHomeDataReportData(param *home.SearchDataReportData)
 // 20000-30000之间:报表数据 TODO 疑似与 sys_report 表对应?
 func (s *HomeService) getReportData(id int64, params *map[string]interface{}) (interface{}, error) {
 	switch id {
-	case 10000, 10001, 10002, 10003, 10004, 10005, 10006, 10007, 10008, 10009, 10010, 10011, 10012, 10013, 10014, 10015, 10016, 10017, 10018, 10019, 10020:
+	case 10000, 10001, 10002, 10003, 10004, 10005, 10006, 10007, 10008, 10009, 10010, 10011, 10012, 10013, 10014, 10015, 10016, 10017, 10018, 10019, 10020, 10021:
 		// 获取数值指标统计数据
 		return s.getNumStatisticsData(id, params)
 	case 20000:
@@ -193,8 +193,11 @@ func (s *HomeService) getNumStatisticsData(id int64, params *map[string]interfac
 		return gconv.String(count), err
 
 	case 10010: //当年的回款金额(维度:年)
-		count, err := contractDao.DataScope(s.Ctx, "incharge_id").WhereGTE(contractDao.C.ContractStartTime, yearStart).WhereLTE(contractDao.C.ContractStartTime, yearEnd).
-			Sum(contractDao.C.CollectedAmount)
+		//count, err := contractDao.DataScope(s.Ctx, "incharge_id").WhereGTE(contractDao.C.ContractStartTime, yearStart).WhereLTE(contractDao.C.ContractStartTime, yearEnd).
+		//	Sum(contractDao.C.CollectedAmount)
+		// 修改为报表统计相同的逻辑
+		count, err := contractDao.As("a").DataScope(s.Ctx, "incharge_id").InnerJoin("ctr_contract_collection b", "a.id=b.contract_id").Where("b.collection_datetime>=? AND b.collection_datetime<=?", yearStart, yearEnd).
+			Sum("b.collection_amount")
 		return gconv.String(count), err
 
 	case 10011: //我发起的督办
@@ -258,6 +261,11 @@ func (s *HomeService) getNumStatisticsData(id int64, params *map[string]interfac
 	case 10020: //项目来源为招标信息转化
 		count, err := businessDao.Where("bid_id<>0").Count()
 		return gconv.String(count), err
+
+	case 10021: //当年的已开票金额(维度:年)
+		count, err := contractDao.DataScope(s.Ctx, "incharge_id").WhereGTE(contractDao.C.ContractStartTime, yearStart).WhereLTE(contractDao.C.ContractStartTime, yearEnd).
+			Sum(contractDao.C.InvoiceAmount)
+		return gconv.String(count), err
 	}
 	return "", nil
 }

+ 12 - 5
opms_parent/app/service/work/deliver_order.go

@@ -77,6 +77,7 @@ func NewDeliverOrderService(ctx context.Context) (*DeliverOrderService, error) {
 
 func (s DeliverOrderService) Get(ctx context.Context, id int) (*work.DeliverOrderGetRsp, error) {
 	number := 0
+	number2 := 0
 	ent, err := s.Dao.Where("Id = ?", id).One()
 	if err != nil {
 		return nil, err
@@ -115,6 +116,11 @@ func (s DeliverOrderService) Get(ctx context.Context, id int) (*work.DeliverOrde
 	if err != nil {
 		return nil, err
 	}
+	// 安装单数量
+	number2, err = s.Dao.DB.Model("deliver_order_imp_progress").Where(fmt.Sprintf("deliver_order_id='%v' AND progress_type='30'", id)).Count()
+	if err != nil {
+		return nil, err
+	}
 
 	return &work.DeliverOrderGetRsp{
 		DeliverOrder:     *ent,
@@ -123,13 +129,14 @@ func (s DeliverOrderService) Get(ctx context.Context, id int) (*work.DeliverOrde
 		ProgressProducts: progressProducts,
 		SaleId:           saleId,
 		Number:           number + 1,
+		Number2:          number2 + 1,
 	}, nil
 }
 
 func (s DeliverOrderService) List(ctx context.Context, req *work.DeliverOrderListReq) (int, []*work.DeliverOrderInfo, error) {
 	g.Log().Infof("DeliverOrderService List roles %v", s.userInfo.Roles)
 	//dao := s.Dao.DeliverOrderDao.As("a").LeftJoin("ctr_contract b", "a.contract_id=b.id").Unscoped().Where("a.deleted_time is null") // 改为关联项目
-	dao := s.Dao.DeliverOrderDao.As("a").LeftJoin("proj_business b", "a.project_id=b.id").LeftJoin("deliver_order_product p", "p.deliver_order_id=a.id").Unscoped().Where("a.deleted_time is null")
+	dao := s.Dao.DeliverOrderDao.As("a").LeftJoin("ctr_contract b", "a.contract_id=b.id").LeftJoin("deliver_order_product p", "p.deliver_order_id=a.id").Unscoped().Where("a.deleted_time is null")
 	where := ""
 	//	系统管理员、研发主管、研发总监、品质主管、总经理、销售总监、销售助理看全部的
 	if service.StringsContains(s.userInfo.Roles, "ResearchAndDevelopmentDirector") || service.StringsContains(s.userInfo.Roles, "ResearchAndDevelopmentSupervisor") || service.StringsContains(s.userInfo.Roles, "QualityAssuranceSupervisor") || service.StringsContains(s.userInfo.Roles, "GeneralManager") || service.StringsContains(s.userInfo.Roles, "SalesDirector") || service.StringsContains(s.userInfo.Roles, "SaleAssociate") || service.StringsContains(s.userInfo.Roles, "SysAdmin") {
@@ -165,13 +172,13 @@ func (s DeliverOrderService) List(ctx context.Context, req *work.DeliverOrderLis
 			// 大区经理看所管理的销售的(包括自己)
 		}
 		if service.StringsContains(s.userInfo.Roles, "RegionalManager") {
-			where1 += fmt.Sprintf(" OR b.sale_id IN (SELECT id FROM sys_user WHERE dept_id='%v')", s.userInfo.DeptId)
+			where1 += fmt.Sprintf(" OR b.incharge_id IN (SELECT id FROM sys_user WHERE dept_id='%v')", s.userInfo.DeptId)
 			//dao = dao.Where(fmt.Sprintf("b.sale_id IN (SELECT id FROM sys_user WHERE dept_id='%v')", s.userInfo.DeptId))
 			// 销售工程师看自己负责的项目的
 		}
 		if service.StringsContains(s.userInfo.Roles, "SalesEngineer") {
-			where1 += fmt.Sprintf(" OR b.sale_id='%v'", s.userInfo.Id)
-			//dao = dao.Where("b.sale_id = ?", s.userInfo.Id)
+			where1 += fmt.Sprintf(" OR b.incharge_id='%v'", s.userInfo.Id)
+			//dao = dao.Where("b.incharge_id = ?", s.userInfo.Id)
 		}
 		where1 += ")"
 		where = where1
@@ -245,7 +252,7 @@ func (s DeliverOrderService) List(ctx context.Context, req *work.DeliverOrderLis
 	dao = dao.Order(orderby)
 
 	var ents []*work.DeliverOrderInfo
-	err = dao.Fields("a.*, group_concat(p.product_name) products, b.sale_id").Structs(&ents)
+	err = dao.Fields("a.*, group_concat(p.product_name) products, b.incharge_id saleId, b.signatory_unit").Structs(&ents)
 	if err != nil && err != sql.ErrNoRows {
 		return 0, nil, err
 	}

+ 38 - 12
opms_parent/app/service/work/deliver_order_progress.go

@@ -623,26 +623,45 @@ func (s DeliverOrderProgressService) CompleteInstall(ctx context.Context, req *w
 	if err != nil {
 		return err
 	}
-	progressMap := make(map[int]bool, 0)
+	installIdMap := make(map[int]bool, 0)
+	uninstallIdMap := make(map[int]bool, 0)
 	ids := ""
+	unIds := ""
 	progressIds := ""
+	// 已安装的产品
+	for _, id := range req.InstallProductIdArr {
+		installIdMap[id] = true
+		if ids == "" {
+			ids = gconv.String(id)
+		} else {
+			ids += "," + gconv.String(id)
+		}
+	}
+	// 未安装的产品
+	for _, id := range req.UninstallProductIdArr {
+		uninstallIdMap[id] = true
+		if unIds == "" {
+			unIds = gconv.String(id)
+		} else {
+			unIds += "," + gconv.String(id)
+		}
+	}
+	progressMap := make(map[int]bool, 0)
 	// 第一次循环,取出需要更新的数据
 	for _, product := range allProducts {
-		if product.InstallProgressId == req.Id {
+		if product.InstallProgressId == req.Id && installIdMap[product.Id] {
 			progressMap[product.DeliverProgressId] = true
-			if ids == "" {
-				ids = gconv.String(product.Id)
-			} else {
-				ids += "," + gconv.String(product.Id)
-			}
 		}
 	}
 	// 判断是否已全部完成
 	for key := range progressMap {
 		for _, product := range allProducts {
-			if product.DeliverProgressId == key && product.IsInstall != "20" && product.InstallProgressId != req.Id {
-				progressMap[key] = false
-				break
+			if product.DeliverProgressId == key {
+				// 未完成的情况
+				if (product.IsInstall != "20" && product.InstallProgressId != req.Id) || uninstallIdMap[product.Id] {
+					progressMap[key] = false
+					break
+				}
 			}
 		}
 		if progressMap[key] {
@@ -673,8 +692,15 @@ func (s DeliverOrderProgressService) CompleteInstall(ctx context.Context, req *w
 				return err
 			}
 		}
-		// 更新硬件交付工单完成状态
-		if count == 0 {
+		// 更新未安装产品信息
+		if unIds != "" {
+			_, err = tx.Update("deliver_progress_product", "install_progress_id=NULL", fmt.Sprintf("id IN (%v)", unIds))
+			if err != nil {
+				return err
+			}
+		}
+		// 更新硬件交付工单完成状态,未安装的产品为空
+		if count == 0 && len(req.UninstallProductIdArr) == 0 {
 			count1, err := tx.Model("deliver_order_imp_progress").Where(fmt.Sprintf("(progress_status='20' OR progress_status='10') AND progress_type='10' AND deliver_progress_id='%v'", progress.DeliverOrderId)).Count()
 			if err != nil {
 				return err

+ 5 - 0
opms_parent/schema/contract.sql

@@ -111,6 +111,11 @@ CREATE TABLE `ctr_contract_invoice` (
     `invoice_code` varchar(32) DEFAULT NULL COMMENT '发票号码',
     `actual_invoice_date` datetime DEFAULT NULL COMMENT '实际开票日期',
     `courier_code` varchar(32) DEFAULT NULL COMMENT '快递单号',
+    `tax_no` varchar(90) NOT NULL COMMENT '税号',
+    `address` varchar(255) DEFAULT NULL COMMENT '开票地址',
+    `phone` varchar(32) DEFAULT NULL COMMENT '开票电话',
+    `bank` varchar(90) DEFAULT NULL COMMENT '开户行',
+    `account_no` varchar(90) DEFAULT NULL COMMENT '账号',
     `remark` text DEFAULT NULL COMMENT '备注',
     `created_by` int(11) NOT NULL COMMENT '创建者',
     `created_name` varchar(90) NOT NULL COMMENT '创建人',