Esempio n. 1
0
        public void inst_manodeobra(vw_operaciones_vh opr, int idtec)
        {
            tdetallemanoobraot oprOt = db.tdetallemanoobraot.FirstOrDefault(x => x.idorden == opr.ot_id && x.idtempario == opr.codigo);

            if (oprOt == null)
            {
                //busco la informacion específica del tempario
                ttempario operacion = db.ttempario.Where(d => d.codigo == opr.codigo).FirstOrDefault();

                tdetallemanoobraot operacionOt = new tdetallemanoobraot
                {
                    costopromedio = 0,
                    fecha         = DateTime.Now,
                    idorden       = opr.ot_id,
                    idtempario    = opr.codigo,
                    tiempo        = Convert.ToDecimal(opr.tiempo),
                    idtecnico     = idtec,
                    valorunitario = opr.precio_tempario != null ? opr.precio_tempario.Value : 0,
                    pordescuento  = 0,
                    poriva        = operacion.iva,
                    estado        = "1"
                };
                db.tdetallemanoobraot.Add(operacionOt);
                if (!string.IsNullOrWhiteSpace(opr.referencia))
                {
                    icb_referencia      referencia   = db.icb_referencia.Where(d => d.ref_codigo == opr.referencia).FirstOrDefault();
                    tencabezaorden      orden        = db.tencabezaorden.Where(d => d.id == opr.ot_id).FirstOrDefault();
                    tdetallerepuestosot referenciaOT = new tdetallerepuestosot
                    {
                        costopromedio                       = 0,
                        idorden                             = opr.ot_id,
                        idrepuesto                          = opr.referencia,
                        valorunitario                       = opr.precio_repuesto != null ? opr.precio_repuesto.Value : 0,
                        pordescto                           = referencia != null?Convert.ToDecimal(referencia.por_dscto) : 0,
                                                     poriva = referencia != null?Convert.ToDecimal(referencia.por_iva) : 0,
                                                                  cantidad   = opr.cant_sistema,
                                                                  idtercero  = orden.tercero,
                                                                  solicitado = false
                    };
                    db.tdetallerepuestosot.Add(referenciaOT);
                }

                db.SaveChanges();
            }
        }
Esempio n. 2
0
        public JsonResult eliminarOperacion(int oprid, int idot, bool origen = true)
        {
            int resl = 0;

            using (DbContextTransaction dbTr = db.Database.BeginTransaction())
            {
                try
                {
                    vw_operaciones_vh opr_ot = db.vw_operaciones_vh.Where(x => x.tinsvh_id == oprid && x.ot_id == idot)
                                               .FirstOrDefault();
                    if (opr_ot != null)
                    {
                        icb_tinspeccionsistemasvh opr_ins = db.icb_tinspeccionsistemasvh.Where(x => x.ot_id == idot && x.tinsvh_id == oprid)
                                                            .FirstOrDefault();
                        if (opr_ins != null)
                        {
                            db.icb_tinspeccionsistemasvh.Remove(opr_ins);
                            db.SaveChanges();
                        }

                        tdetallemanoobraot mno_obra = db.tdetallemanoobraot
                                                      .Where(x => x.idtempario == opr_ot.codigo && x.idorden == idot).FirstOrDefault();
                        if (mno_obra != null && origen)
                        {
                            db.tdetallemanoobraot.Remove(mno_obra);
                            db.SaveChanges();
                        }

                        resl = 1;
                    }

                    dbTr.Commit();
                }
                catch (Exception ex)
                {
                    Exception exp = ex;
                    resl = 0;
                    dbTr.Rollback();
                }
            }

            return(Json(new { resl }));
        }