فهرست منبع

feature(*): 1、首页当年回款金额与报表不一致问题处理,统一为报表处的统计逻辑
2、合同审批通过生成工单时,合同签约单位带到工单中
3、交付工单中销售可以创建安装任务流程调整

likai 2 سال پیش
والد
کامیت
0664f04bab

+ 15 - 15
opms_parent/app/model/contract/ctr_contract_invoice.go

@@ -41,15 +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"`                   // 快递单号
+	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"`                        // 备注
+	Bank              string      `json:"bank" `                     // 开户行
+	AccountNo         string      `json:"accountNo"  `               // 账号
+	Remark            string      `json:"remark"`                    // 备注
 }
 
 type CtrContractInvoiceUpdateReq struct {
@@ -59,18 +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"  `                   // 账号
+	Bank              string      `json:"bank" `                     // 开户行
+	AccountNo         string      `json:"accountNo"  `               // 账号
 	Remark            *string     `json:"remark"`
 }
 

+ 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 {

+ 5 - 2
opms_parent/app/service/home/home.go

@@ -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: //我发起的督办

+ 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