Beispiel #1
0
        public VoucherItem AddTransferFileItem(VoucherItem vitem)
        {
            if (vitem.IsSetup)
            {
                var itm = m_ItemCollection.FindFirstOrDefault((ii) => (ii.State == eState.NA && ii.Forsed) || ((ii.State == eState.NA) && ((VoucherItem)ii).Equals(vitem)));
                if (itm == null)
                {
                    throw new FileInfoApplicationException(
                              string.Concat("Cannot match voucher.\r\nCountry: ", vitem.CountryID, "\r\nRetailer: ",
                                            vitem.RetailerID, "\r\nVoucher: ", vitem.VoucherID, "\r\nState: NA"))
                          {
                              Info = vitem.FileInfoList.FirstOrDefault(fi => !fi.Name.Contains("barcode"))
                          };
                }

                m_CurrentItem = itm;
                ((VoucherItem)m_CurrentItem).CopyFromWithBarcode(vitem);
            }
            else
            {
                var itm = m_ItemCollection.FindFirstOrDefault((ii) => (ii.State == eState.NA && !ii.Ignored));
                if (itm == null)
                {
                    throw new ApplicationException("No more vouchers are expected.");
                }
                m_CurrentItem = itm;
                ((VoucherItem)m_CurrentItem).CopyFromNoBarcode(vitem);
            }
            return((VoucherItem)m_CurrentItem);
        }
Beispiel #2
0
        private void PickSegments(VoucherItem voucherItem, List <Segment> segments)
        {
            var segmentGrouop1 = voucherItem.Ledger.GetSegmentSetting(1).SegmentGroup;

            voucherItem.Segment1 = Pick(segments.Where(s => s.SegmentGroup == segmentGrouop1).ToArray());

            var segmentGrouop2 = voucherItem.Ledger.GetSegmentSetting(2).SegmentGroup;

            voucherItem.Segment2 = Pick(segments.Where(s => s.SegmentGroup == segmentGrouop2).ToArray());
        }
Beispiel #3
0
 public void AddVoucherItem(int id, int countryId, int retailerId, int voucherId, eState state, Guid session, string siteCode, string name)
 {
     lock (m_ItemCollection.SyncRoot)
     {
         if (m_ItemCollection.FirstOrDefault((ii) => ii is VoucherItem && ((VoucherItem)ii).Equals(countryId, retailerId, voucherId)) == null)
         {
             VoucherItem item = new VoucherItem(id, countryId, retailerId, voucherId, state, session, siteCode, name);
             m_ItemCollection.Add(item);
             FireNewItemAdded(item);
         }
     }
 }
Beispiel #4
0
        private void ButtonVoucherDetailsClick(object sender, RoutedEventArgs e)
        {
            VoucherItem voucher = _vm.SelectedVoucherItem;

            if (voucher == null)
            {
                return;
            }

            VoucherDetailsWindow voucherWindow = new VoucherDetailsWindow(voucher)
            {
                Owner = Window.GetWindow(this)
            };

            voucherWindow.Closed += (sndr, eventArgs) => _vm.Reset();
            voucherWindow.ShowDialog();
        }
Beispiel #5
0
        public void Load(string filePath)
        {
            if (filePath.IsNullOrEmpty() || !File.Exists(filePath))
            {
                return;
            }

            try
            {
                var lines = File.ReadAllLines(filePath);

                lock (m_ItemCollection.SyncRoot)
                {
                    foreach (var line in lines)
                    {
                        var str = line.TrimSafe();
                        if (!str.IsNullOrEmpty())
                        {
                            VoucherItem item = null;

                            if (VoucherItem.TryParse(str, ref item))
                            {
                                m_ItemCollection.Add(item);
                                FireNewItemAdded(item);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Clear();
                throw new ApplicationException("Wrong file format.", ex);
            }
            finally
            {
            }
        }
 public VoucherDetailsWindow(VoucherItem voucher)
 {
     Init();
     _vm.VoucherItem = voucher;
     _vm.SetRecordItems();
 }
        public bool GenerateReport(List <DictObject> dictObjList)
        {
            try
            {
                const XplugDepartments lrGlobal = XplugDepartments.LrGlobal;
                var z = Enum.GetName(typeof(XplugDepartments), lrGlobal);
                var y = 0;
                if (z != null)
                {
                    y = (int)Enum.Parse(typeof(XplugDepartments), z);
                }

                const XplugDepartments xPlug = XplugDepartments.XPlug;
                var s = Enum.GetName(typeof(XplugDepartments), xPlug);
                var x = 0;
                if (s != null)
                {
                    x = (int)Enum.Parse(typeof(XplugDepartments), s);
                }

                var repFilePath = "";

                if (dictObjList.ElementAt(0).DepartmentId == x)
                {
                    repFilePath = Server.MapPath("~/ExpenseMgt/Reports/ReportFiles/XplugMultiVoucher.rpt");
                }

                if (dictObjList.ElementAt(0).DepartmentId == y)
                {
                    repFilePath = Server.MapPath("~/ExpenseMgt/Reports/ReportFiles/LRMultiVoucher.rpt");
                }

                if (dictObjList.ElementAt(0).DepartmentId != x && dictObjList.ElementAt(0).DepartmentId != y)
                {
                    repFilePath = Server.MapPath("~/ExpenseMgt/Reports/ReportFiles/XplugMultiVoucher.rpt");
                }

                var voucherItemList = new List <VoucherItem>();

                foreach (var dictObj in dictObjList)
                {
                    foreach (var dictItem in dictObj.TransactionItems)
                    {
                        var newVoucherItem = new VoucherItem
                        {
                            AmountInWords       = dictObj.WordValue,
                            AmountPaid          = string.Format("{0}{1}", "N", NumberMap.GroupToDigits(dictObj.AmmountPaid.ToString(CultureInfo.InvariantCulture))),
                            Approver            = dictObj.Approver,
                            DatePaid            = dictObj.DatePaid,
                            ChequeNo            = dictObj.ChequeNo,
                            PcvNo               = dictObj.PcvNo,
                            TransactionId       = dictObj.TransactionpaymentHistoryId,
                            RequestedBy         = dictObj.RequestedBy,
                            ReceivedBy          = dictObj.ReceivedBy,
                            TotalApprovedAmount = string.Format("{0}{1}", "N", NumberMap.GroupToDigits(dictObj.TotalApprovedAmmount.ToString(CultureInfo.InvariantCulture))),
                            ApprovedQuantity    = dictItem.ApprovedQuantity.ToString(CultureInfo.InvariantCulture),
                            ApprovedUnitPrice   = NumberMap.GroupToDigits(dictItem.ApprovedUnitPrice.ToString(CultureInfo.InvariantCulture)),
                            ApprovedTotalPrice  = NumberMap.GroupToDigits(dictItem.ApprovedTotalPrice.ToString(CultureInfo.InvariantCulture)),
                            ItemName            = dictItem.ExpenseItem.Title,
                            ItemCode            = dictItem.ExpenseItem.Code,
                            DetailDesription    = dictItem.Description
                        };

                        if (newVoucherItem.TransactionId > 0 && !string.IsNullOrEmpty(newVoucherItem.ItemName) && !string.IsNullOrEmpty(newVoucherItem.ItemCode))
                        {
                            voucherItemList.Add(newVoucherItem);
                        }
                    }
                }

                var pdfPath = Session.SessionID + DateTime.Now.Millisecond.ToString(CultureInfo.InvariantCulture) + Environment.TickCount.ToString(CultureInfo.InvariantCulture) + ".pdf";
                var path    = Server.MapPath("~/GeneratedDocuments/");
                pdfPath = path + pdfPath;

                var repDoc = new ReportDocument();
                repDoc.Load(repFilePath);

                repDoc.SetDataSource(voucherItemList);

                var crDiskFileDestinationOptions = new DiskFileDestinationOptions();
                var crFormatTypeOptions          = new PdfRtfWordFormatOptions();
                crDiskFileDestinationOptions.DiskFileName = pdfPath;
                var crExportOptions = repDoc.ExportOptions;
                {
                    crExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
                    crExportOptions.ExportFormatType      = ExportFormatType.PortableDocFormat;
                    crExportOptions.DestinationOptions    = crDiskFileDestinationOptions;
                    crExportOptions.FormatOptions         = crFormatTypeOptions;
                }
                repDoc.Export();
                Session["myPDF.InvoicePath"] = pdfPath;

                Context.Response.Buffer = false;
                var buffer = new byte[1024];
                var inStr  = File.OpenRead(pdfPath);
                while ((inStr.Read(buffer, 0, buffer.Length)) > 0)
                {
                    if (Context.Response.IsClientConnected)
                    {
                        Response.Clear();
                        Response.ContentType = "application/pdf";
                        Context.Response.OutputStream.Write(buffer, 0, buffer.Length);
                        Context.Response.Flush();
                    }
                }
                return(true);
            }
            catch (Exception ex)
            {
                ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                return(false);
            }
        }
 private static void AssertVoucherItem(VoucherItem source, VoucherItem dest)
 {
     Assert.AreEqual(source.VoucherCode, dest.VoucherCode);
     Assert.AreEqual(source.Code, dest.Code);
     Assert.AreEqual(source.CreateTime, dest.CreateTime.ToLocalTime());
 }
 public void AddItem(VoucherItem item)
 {
     this.Vouchers.Add(item);
 }
Beispiel #10
0
        public void Init()
        {
            Database.SetInitializer <AccountingDbContext>(null);
            //Database.SetInitializer(new MigrateDatabaseToLatestVersion<AccountingDbContext, Configuration>());
            //Database.SetInitializer(new DropCreateDatabaseAlways<AccountingDbContext>());

            db = new AccountingDbContext();

            db.Database.ExecuteSqlCommand(
                @"
                    DELETE FROM [Accounting].FiscalYear
                    DELETE FROM [Accounting].LedgerSegmentSetting
                    DELETE FROM [Accounting].VoucherItemSegment
                    DELETE FROM [Accounting].[VoucherItem]
                    DELETE FROM [Accounting].[Voucher]
                    DELETE FROM [Accounting].AccLedger
                    DELETE FROM [Accounting].AccGeneral
                    DELETE FROM [Accounting].AccGroup
                    DELETE FROM [Accounting].VoucherType
                    DELETE FROM [Accounting].Segment
                    DELETE FROM [Accounting].SegmentGroup
               ");

            var fiscalYears   = new List <FiscalYear>();
            var voucherTypes  = new List <VoucherType>();
            var accGroups     = new List <AccGroup>();
            var accGenerals   = new List <AccGeneral>();
            var accLedgers    = new List <AccLedger>();
            var vouchers      = new List <Voucher>();
            var segmentGroups = new List <SegmentGroup>();
            var segments      = new List <Segment>();

            fiscalYears.AddRange(
                new List <FiscalYear>
            {
                new FiscalYear()
                {
                    Id        = Guid.NewGuid(),
                    Name      = "1394",
                    StartDate = new DateTime(2015, 3, 20),
                    EndDate   = new DateTime(2016, 3, 19),
                },
                new FiscalYear()
                {
                    Id        = Guid.NewGuid(),
                    Name      = "1395",
                    StartDate = new DateTime(2016, 3, 20),
                    EndDate   = new DateTime(2017, 3, 19),
                },
                new FiscalYear()
                {
                    Id        = Guid.NewGuid(),
                    Name      = "1396",
                    StartDate = new DateTime(2017, 3, 20),
                    EndDate   = new DateTime(2018, 3, 19),
                }
            });

            segmentGroups.AddRange(new []
            {
                new SegmentGroup()
                {
                    Id   = Guid.NewGuid(),
                    Code = "10",
                    Name = "اشخاص حقیقی و حقوقی"
                },
                new SegmentGroup()
                {
                    Id   = Guid.NewGuid(),
                    Code = "11",
                    Name = "پروژه‌ها"
                },
                new SegmentGroup()
                {
                    Id   = Guid.NewGuid(),
                    Code = "12",
                    Name = "حساب‌ها"
                },
            });
            InsertToDb(segmentGroups);

            for (var i = 1; i <= 800; i++)
            {
                var segmentGroup = Pick(segmentGroups);
                segments.Add(new Segment()
                {
                    Id           = Guid.NewGuid(),
                    Code         = i.ToString(),
                    SegmentGroup = segmentGroup,
                    Name         = $"{segmentGroup.Name} {i}"
                });
            }
            InsertToDb(segments);

            for (var i = 1; i <= 15; i++)
            {
                voucherTypes.Add(new VoucherType()
                {
                    Id   = Guid.NewGuid(),
                    Code = i.ToString(),
                    Name = $"نوع سند {i}"
                });
            }
            InsertToDb(voucherTypes);

            for (var i = 1; i <= 10; i++)
            {
                accGroups.Add(new AccGroup()
                {
                    Id   = Guid.NewGuid(),
                    Code = i.ToString(),
                    Name = $"گروه حساب {i}"
                });
            }
            InsertToDb(accGroups);


            for (var i = 1; i <= 30; i++)
            {
                accGenerals.Add(new AccGeneral()
                {
                    Id    = Guid.NewGuid(),
                    Code  = i.ToString(),
                    Name  = $"حساب کل {i}",
                    Group = Pick(accGroups)
                });
            }
            InsertToDb(accGenerals);

            for (var i = 1; i <= 200; i++)
            {
                var leftPick = Pick(1, 2);
                var settings = new List <LedgerSegmentSetting>
                {
                    new LedgerSegmentSetting()
                    {
                        Id           = Guid.NewGuid(),
                        SegmentGroup = Pick(segmentGroups[0]),
                        Level        = leftPick,
                        IsMandatory  = false,
                    },
                    new LedgerSegmentSetting()
                    {
                        Id           = Guid.NewGuid(),
                        SegmentGroup = Pick(segmentGroups[1]),
                        Level        = 3 - leftPick,
                        IsMandatory  = false,
                    }
                };

                accLedgers.Add(new AccLedger()
                {
                    Id              = Guid.NewGuid(),
                    Code            = i.ToString(),
                    Name            = $"معین {i}",
                    General         = Pick(accGenerals),
                    SegmentSettings = settings
                });
            }
            InsertToDb(accLedgers);

            for (var i = 1; i <= 400; i++)
            {
                var voucherDate = RandomDay();
                var fiscalYear  = fiscalYears.First(f => f.StartDate <= voucherDate && voucherDate <= f.EndDate);
                var voucher     = new Voucher()
                {
                    Id           = Guid.NewGuid(),
                    FixNo        = i.ToString(),
                    TempNo       = i.ToString(),
                    Description  = $"سند حسابداری {i}",
                    VoucherState =
                        Pick(VoucherState.Values.Accepted, VoucherState.Values.Draft, VoucherState.Values.Fixed, VoucherState.Values.Registered),
                    VoucherDate = voucherDate,
                    VoucherType = Pick(voucherTypes),
                    FiscalYear  = fiscalYear
                };
                vouchers.Add(voucher);

                voucher.VoucherItems = new List <VoucherItem>();

                var row = 1;

                for (var j = 1; j <= 8; j++)
                {
                    var amount = _random.Next(1000, 1000000);

                    var left = new VoucherItem()
                    {
                        Id          = Guid.NewGuid(),
                        Voucher     = voucher,
                        Description = $"سند {i}, آرتیکل {j} - شرح بستانکار",
                        Credit      = amount,
                        Debit       = 0,
                        Ledger      = Pick(accLedgers),
                    };
                    left.SetRowNo(row++);

                    PickSegments(left, segments);

                    var right = new VoucherItem()
                    {
                        Id          = Guid.NewGuid(),
                        Voucher     = voucher,
                        Description = $"سند {i}, آرتیکل {j} - شرح بدهکار",
                        Credit      = 0,
                        Debit       = amount,
                        Ledger      = Pick(accLedgers)
                    };
                    right.SetRowNo(row++);
                    PickSegments(right, segments);

                    voucher.VoucherItems.Add(left);
                    voucher.VoucherItems.Add(right);
                }
                //InsertToDb(new List<Voucher> {voucher});
            }
            InsertToDb(vouchers);


            db.Dispose();
        }