Created
November 3, 2019 16:26
-
-
Save elyphas/badf4ba3bd386e2002013404b5106719 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def generate(idComparative: String) = { | |
val generateOrders = new CDmlQuerys() | |
implicit val getCalcularResult = GetResult(r => Calcular(r.nextString, r.nextString, r.nextString, r.nextInt, r.nextDouble, r.nextBoolean)) | |
val calcular = sql"""select * from calccantpedid as c where c.id_comparativo = $idComparative""".as[Calcular] | |
val lstOrdersF = generateOrders.run(calcular) | |
val dataGralesProcess = new CGralDataProceso() | |
val datGralesProcess = dataGralesProcess.byId(idComparative) | |
val resultados = for { | |
gralData <- EitherT(datGralesProcess) | |
lstOrders <- EitherT(lstOrdersF) | |
lastOrder <- EitherT(generateOrders.run(sql"""select max(no_pedido) as ultimo from tblpedi where compra = 'PEDI' and ejercicio = ${gralData.ejercicio}""".as[String])) | |
} yield { | |
var numOrder: Int = lastOrder.head.toInt | |
lstOrders.map { provGanad => | |
numOrder += 1 | |
GralDataPedido(no_pedido = numOrder.toString, ejercicio = gralData.ejercicio, fecha_pedido = Fechas("01/01/2020"), tipo_compra = gralData.tipo_compra, | |
fecha_entrega = Some(gralData.plazo), no_sol_compra = Some(gralData.memo), destino = gralData.destino, | |
elaboro = gralData.elaboro, cve_depto = gralData.cve_oficina, cve_provedor = provGanad.rfc, cve_presup = gralData.programa, | |
cancelado = Some(false), obsercancel = None, ejercicio_presupuesto = 2019, id_comparativo = Some(gralData.id_comparativo)) | |
} | |
} | |
val finalResult = Await.result(resultados.value, 500 seconds) | |
val dataGralPedi = new CGralDataPedido() | |
val creados = finalResult match { | |
case Right(value) => dataGralPedi.insertMany(value) | |
case Left(value) => Future.successful(println( s"Errorres $value *******************************")) | |
} | |
val ver = Await.result(creados, 500 seconds) | |
import manik1.manik1.shared.CantidadXDividir | |
implicit val getCantidadXDivirResult = GetResult(r => CantidadXDividir(r.nextString, r.nextString, r.nextString, r.nextInt, r.nextInt, r.nextInt, r.nextDouble, r.nextInt, r.nextInt, r.nextInt)) | |
val qryBuscaCantXdiv = sql"""select * from busca_cant_x_dividir where id_comparativo = $idComparative"""; | |
val buscaCantXdiv = generateOrders.run(qryBuscaCantXdiv.as[CantidadXDividir]) | |
implicit val getBuscaPedidoXProveedorResult = GetResult(r => BuscaPedidoXProveedor( | |
r.nextString, r.nextString, r.nextString, r.nextString, r.nextInt, r.nextDouble, r.nextString, r.nextString, | |
r.nextString, r.nextInt, r.nextInt, r.nextInt, r.nextInt, r.nextString, r.nextInt )) | |
def sqlBuscaPedProv(cveArt: String, programa: String, reng: Int, entrega: Int) = sql"""select * from busca_peddeprov where id_comparativo = $idComparative and cve_articulo = $cveArt and Programa = $programa and renglon = $reng and entrega = $entrega""" | |
val generateDetails = for { | |
cantXDividir <- EitherT(buscaCantXdiv) | |
} yield { | |
val insertarClaves = cantXDividir.map { cantXDiv => | |
val qrySQL = sqlBuscaPedProv(cantXDiv.cve_articulo, cantXDiv.programa, cantXDiv.renglon, cantXDiv.entrega) | |
val numeroPedidoProveedor = generateOrders.run(qrySQL.as[BuscaPedidoXProveedor]) | |
for { numPedProv <- numeroPedidoProveedor } yield { | |
numPedProv match { | |
case Right(asignar) => | |
asignar.map { asig => DetallePedido (no_pedido = asig.no_pedido, compra = asig.compra, ejercicio = asig.ejercicio, fecha_pedido = Fechas("01/01/2018"), | |
cve_articulo = asig.cve_articulo, cantidad = asig.cantidad, precio = asig.precio, anexo = asig.anexo, marcas = asig.marca, | |
id_comparativo = asig.id_comparativo /*modelo = asig.modelo*/ ) | |
} | |
case Left(value) => | |
println(s"Ocurrio un error: ++++ $value") | |
Seq.empty[DetallePedido] | |
} | |
} | |
} | |
for { | |
futSeq <- Future.sequence(insertarClaves) | |
} yield { | |
val detPedido = new CDetallePedido() | |
detPedido.insertMany(futSeq.flatten) | |
} | |
} | |
//Await.result(generateDetails.value, 50 seconds) | |
Future.successful ( Right("Vamos a regresar los números de pedido.") ) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment