| | |
| | | if err != nil { |
| | | return err |
| | | } |
| | | |
| | | autoCode, codeStandard, maxAutoIncr, err := GetAutoCode(constvar.CodeStandardType_Outgoing) |
| | | if err != nil { |
| | | return err |
| | | } |
| | | |
| | | opTypeMap := make(map[int]*models.OperationType, len(opTypes)) |
| | | for _, opType := range opTypes { |
| | | opTypeMap[opType.WarehouseId] = opType |
| | | } |
| | | operations := make([]*models.Operation, 0, len(outputList)) |
| | | for _, output := range outputList { |
| | | location, err := models.NewLocationSearch().SetType(int(constvar.LocationTypeCustomer)).First() |
| | | if err != nil { |
| | | return err |
| | | } |
| | | details := make([]*models.OperationDetails, 0, len(output.Products)) |
| | | for _, product := range output.Products { |
| | | details = append(details, &models.OperationDetails{ |
| | |
| | | ProductId: product.ProductID, |
| | | Amount: product.Amount, |
| | | FromLocationID: output.LocationID, |
| | | ToLocationID: location.Id, |
| | | }) |
| | | } |
| | | if opTypeMap[output.WarehouseID] == nil { |
| | |
| | | } |
| | | operation := &models.Operation{ |
| | | Id: 0, |
| | | Number: "", |
| | | Number: autoCode, |
| | | SourceNumber: output.SourceNumber, |
| | | OperationTypeId: opTypeMap[output.WarehouseID].Id, |
| | | OperationTypeName: opTypeMap[output.WarehouseID].Name, |
| | |
| | | LocationID: output.LocationID, |
| | | } |
| | | operations = append(operations, operation) |
| | | autoCode = models.GetAutoCode(maxAutoIncr, codeStandard) |
| | | maxAutoIncr++ |
| | | } |
| | | |
| | | return models.NewOperationSearch().CreateBatch(operations) |