示例#1
0
        private int ThemMoi(BOXuLyKho item, List<BOXuLyKhoChiTiet> lsArray, Transit mTransit)
        {
            if (lsArray != null)
            {
                List<Data.TONKHOTONG> lsTonKhoTong = new List<TONKHOTONG>();
                List<Data.TONKHO> lsTonKho = new List<TONKHO>();
                foreach (BOXuLyKhoChiTiet line in lsArray)
                {
                    IQueryable<Data.TONKHO> lsArrayLine = null;
                    switch (item.XuLyKho.LoaiID)
                    {
                        case 1:
                            lsArrayLine = frmTonKho.Query().Where(s => s.DonViID == line.TonKho.DonViID && s.MonID == line.TonKho.MonID && s.KhoID == item.XuLyKho.KhoID && s.SoLuongTon > 0).OrderBy(s => s.NgayHetHan).ThenBy(s => s.TonKhoID);
                            if (lsArrayLine.Count() > 0 && line.TonKho.SoLuongNhap < lsArrayLine.Sum(s => s.SoLuongTon) && line.TonKho.SoLuongNhap > 0)
                            {
                                foreach (var l in lsArrayLine)
                                {
                                    if (line.TonKho.SoLuongNhap > 0)
                                    {
                                        Data.TONKHOTONG tonkhotong = null;
                                        if (lsTonKhoTong.Exists(s => s.KhoID == item.XuLyKho.KhoID && s.MonID == line.TonKho.MonID && s.DonViID == line.TonKho.DonViID))
                                        {
                                            tonkhotong = lsTonKhoTong.Find(s => s.KhoID == item.XuLyKho.KhoID && s.MonID == line.TonKho.MonID && s.DonViID == line.TonKho.DonViID);
                                        }
                                        else
                                        {
                                            tonkhotong = KiemTraTonKhoTong(frmTonKhoTong, (int)item.XuLyKho.KhoID, (int)line.TonKho.MonID, (int)line.TonKho.DonViID);
                                            lsTonKhoTong.Add(tonkhotong);
                                        }
                                        tonkhotong.SoLuongTon += line.TonKho.SoLuongNhap;
                                        tonkhotong.SoLuongDieuChinh += line.TonKho.SoLuongNhap;
                                        Data.TONKHO tonkho = null;
                                        if (lsTonKho.Exists(s => s.TonKhoID == l.TonKhoID))
                                        {
                                            tonkho = lsTonKho.Find(s => s.TonKhoID == l.TonKhoID);
                                        }
                                        else
                                        {
                                            tonkho = l;
                                            lsTonKho.Add(tonkho);
                                        }
                                        line.XuLyKhoChiTiet.TONKHO = new TONKHO();
                                        line.XuLyKhoChiTiet.TONKHO.PhatSinhTuTonKhoID = tonkho.TonKhoID;
                                        line.XuLyKhoChiTiet.TONKHO.LoaiPhatSinhID = (int)item.XuLyKho.LoaiID;
                                        CopyTonKho(line.XuLyKhoChiTiet.TONKHO, tonkho);

                                        if (tonkho.SoLuongTon > line.TonKho.SoLuongNhap)
                                        {
                                            line.XuLyKhoChiTiet.TONKHO.SoLuongPhatSinh = tonkho.SoLuongTon - line.TonKho.SoLuongNhap;
                                            tonkho.SoLuongTon += line.TonKho.SoLuongNhap;
                                            line.TonKho.SoLuongNhap = 0;
                                        }
                                        else
                                        {
                                            line.XuLyKhoChiTiet.TONKHO.SoLuongPhatSinh = line.TonKho.SoLuongNhap - tonkho.SoLuongTon;
                                            line.TonKho.SoLuongNhap += tonkho.SoLuongTon;
                                            tonkho.SoLuongTon = 0;
                                        }
                                    }
                                }
                            }
                            break;
                        case 2:
                        case 3:
                            lsArrayLine = frmTonKho.Query().Where(s => s.DonViID == line.TonKho.DonViID && s.MonID == line.TonKho.MonID && s.KhoID == item.XuLyKho.KhoID && s.SoLuongTon > 0).OrderBy(s => s.NgayHetHan).ThenBy(s => s.TonKhoID);
                            if (lsArrayLine.Count() > 0 && line.TonKho.SoLuongNhap < lsArrayLine.Sum(s => s.SoLuongTon) && line.TonKho.SoLuongNhap > 0)
                            {
                                foreach (var l in lsArrayLine)
                                {
                                    if (line.TonKho.SoLuongNhap > 0)
                                    {
                                        Data.TONKHOTONG tonkhotong = null;
                                        if (lsTonKhoTong.Exists(s => s.KhoID == item.XuLyKho.KhoID && s.MonID == line.TonKho.MonID && s.DonViID == line.TonKho.DonViID))
                                        {
                                            tonkhotong = lsTonKhoTong.Find(s => s.KhoID == item.XuLyKho.KhoID && s.MonID == line.TonKho.MonID && s.DonViID == line.TonKho.DonViID);
                                        }
                                        else
                                        {
                                            tonkhotong = KiemTraTonKhoTong(frmTonKhoTong, (int)item.XuLyKho.KhoID, (int)line.TonKho.MonID, (int)line.TonKho.DonViID);
                                            lsTonKhoTong.Add(tonkhotong);
                                        }
                                        tonkhotong.SoLuongTon -= line.TonKho.SoLuongNhap;
                                        if (item.XuLyKho.LoaiID == 2)
                                        {
                                            tonkhotong.SoLuongMat += line.TonKho.SoLuongNhap;
                                        }
                                        if (item.XuLyKho.LoaiID == 3)
                                        {
                                            tonkhotong.SoLuongHu += line.TonKho.SoLuongNhap;
                                        }

                                        Data.TONKHO tonkho = null;
                                        if (lsTonKho.Exists(s => s.TonKhoID == l.TonKhoID))
                                        {
                                            tonkho = lsTonKho.Find(s => s.TonKhoID == l.TonKhoID);
                                        }
                                        else
                                        {
                                            tonkho = l;
                                            lsTonKho.Add(tonkho);
                                        }
                                        line.XuLyKhoChiTiet.TONKHO = new TONKHO();
                                        line.XuLyKhoChiTiet.TONKHO.PhatSinhTuTonKhoID = tonkho.TonKhoID;
                                        line.XuLyKhoChiTiet.TONKHO.LoaiPhatSinhID = (int)item.XuLyKho.LoaiID;
                                        CopyTonKho(line.XuLyKhoChiTiet.TONKHO, tonkho);

                                        if (tonkho.SoLuongTon > line.TonKho.SoLuongNhap)
                                        {
                                            line.XuLyKhoChiTiet.TONKHO.SoLuongPhatSinh = tonkho.SoLuongTon - line.TonKho.SoLuongNhap;
                                            tonkho.SoLuongTon -= line.TonKho.SoLuongNhap;
                                            line.TonKho.SoLuongNhap = 0;
                                        }
                                        else
                                        {
                                            line.XuLyKhoChiTiet.TONKHO.SoLuongPhatSinh = line.TonKho.SoLuongNhap - tonkho.SoLuongTon;
                                            line.TonKho.SoLuongNhap -= tonkho.SoLuongTon;
                                            tonkho.SoLuongTon = 0;
                                        }
                                    }
                                }
                            }
                            break;
                        default:
                            break;
                    }

                    line.XuLyKho = new XULYKHO();
                    line.XuLyKho.KhoID = item.XuLyKho.KhoID;
                    item.XuLyKho.XULYKHOCHITIETs.Add(line.XuLyKhoChiTiet);
                }
                item.XuLyKho.TongTien = lsArray.Sum(s => s.TonKho.SoLuongNhap * s.TonKho.GiaBan);
                foreach (TONKHO i in lsTonKho)
                {
                    frmTonKho.Update(i);
                }
                foreach (TONKHOTONG i in lsTonKhoTong)
                {
                    frmTonKhoTong.Update(i);
                }
                frmTonKho.Commit();
                frmTonKhoTong.Commit();
            }
            return item.XuLyKho.ChinhKhoID;
        }
        public static ResumenFinal getResumenFinal(edificio e, DateTime fechaDesde, DateTime fechaHasta)
        {
            try
            {
                admEntities db = Datos.getDB();
                ResumenFinal resumenFinal = new ResumenFinal();
                fechaHasta = DateTime.Parse(fechaHasta.AddMonths(1).AddDays(-fechaHasta.Day).Day + "/" + fechaHasta.Month + "/" + fechaHasta.Year);

                var sectoresDB = db.sector.ToList();

                var facturas = db.factura.Where(x => x.dir_edificio == e.direccion && x.fecha >= fechaDesde && x.fecha <= fechaHasta).ToList();

                //var facturasAgrupadas = facturas.GroupBy(x => x.fecha.ToString("MM yyyy")).Select(x=> new { Importe = x.Sum(y=> y.importe) });

                DateTime tmpFecha = fechaDesde;
                List<Periodo> periodos = new List<Periodo>();
                bool seguir = true;

                do
                {
                    List<Sector> sectores = new List<Sector>();
                    var Conceptos = db.Database.SqlQuery<Conceptos>(@"select  s.descripcion 'Sector', f.numero_factura 'NumeroFactura', p.razon_social 'Proveedor', concat(tg.descripcion, ' ', f.detalle) 'concepto', f.importe from factura f                                                     left join provedor p                            on p.razon_social = f.razon_provedor   join sector s on id_sector = s.idsector      join tipo_gasto tg  on f.id_tipogasto = tg.idtipo_gasto                    where dir_edificio = '" + e.direccion + "' and month(f.fecha) = " + tmpFecha.Month + " and year(f.fecha) = " + tmpFecha.Year).ToList();
                    foreach(var c in Conceptos.OrderBy(x=> x.Sector))
                    {
                        var s = sectores.Where(x => x.Nombre == c.Sector).SingleOrDefault();
                        if (s == null)
                        {
                            Sector sect = new Sector();
                            sect.Nombre = c.Sector;
                            sect.Importe += c.Importe;
                            sectores.Add(sect);
                        }
                        else
                            s.Importe += c.Importe;
                    }

                    sectores = OrdenarSectores(sectores,sectoresDB);

                    Periodo p = new Periodo();
                    p.Sectores = sectores;
                    p.Total = sectores.Sum(x => x.Importe);
                    p.Nombre = tmpFecha.Month + "/" + tmpFecha.Year;

                    if (sectores.Count > 0)
                        periodos.Add(p);

                    if (tmpFecha <= fechaHasta)
                        seguir = true;
                    else
                        seguir = false;

                    tmpFecha = tmpFecha.AddMonths(1);
                }
                while (seguir);

                resumenFinal.Periodos = periodos;

                var deudaDelEdificio = CatalogoDeudores.getDeudoresFromEdificioRegenerarUnidad(e, fechaHasta).Sum(x=> x.Importe);
                var totalExpensas = periodos.Sum(x => x.Total);

                var entradasDeCaja = getMovimientosCaja(e, fechaDesde, fechaHasta).Sum(x => x.importe > 0 ? (Double)x.importe : 0);

                var salidasDeCaja = getMovimientosCaja(e, fechaDesde, fechaHasta).Sum(x => x.importe < 0 ? (Double)x.importe : 0);

                if (salidasDeCaja < 0)
                    salidasDeCaja *= -1;

                resumenFinal.CobroDeExpensas = totalExpensas - deudaDelEdificio;
                resumenFinal.CobroFondosEspeciales = entradasDeCaja;
                resumenFinal.TotalIngresos = totalExpensas - deudaDelEdificio + entradasDeCaja;

                resumenFinal.GastosComunes = totalExpensas;
                resumenFinal.GastosEspeciales = salidasDeCaja;
                resumenFinal.TotalEgresos = totalExpensas + salidasDeCaja;

                resumenFinal.SaldoEnCaja = resumenFinal.TotalIngresos - resumenFinal.TotalEgresos;

                return resumenFinal;

            }
            catch (Exception ex)
            {
                Logger.Log.write(ex.InnerException == null ? ex.Message : ex.InnerException.Message);
                throw ex;
            }
        }
示例#3
0
        public long DamageReceived(Entity target, Entity source, bool timed)
        {
            var sourceString = source?.Id.ToString() ?? "";
            var key = "damage_received/" + target + "/" + sourceString + "/" + timed;
            if (_caching.ContainsKey(key)) return (long) _caching[key];
            IEnumerable<long> result = new List<long>();

            if (TargetSourceSkill.ContainsKey(target))
            {
                if (!timed && source != null)
                 {
                    if (TargetSourceSkill[target].ContainsKey(source))
                    {
                        result = from skills in TargetSourceSkill[target][source]
                            where skills.Type == Database.Type.Damage
                            select skills.Amount;
                    }
                }
                else
                {
                    result = from skills in TargetSourceSkill[target].Values
                        from skill in skills
                        where skill.Type == Database.Type.Damage
                        select skill.Amount;
                }

            }

            var sum = result.Sum();
            _caching.Add(key, sum);
            return sum;
        }