Ejemplo n.º 1
0
    protected void OnBtnSaveClicked(object sender, EventArgs e)
    {
        InvoiceDetailsRepository repo = new InvoiceDetailsRepository();
        InvoicesRepository repoInv = new InvoicesRepository();
        if (!string.IsNullOrEmpty(Request.QueryString["InvoiceDetailId"]))
        {
            string[] key = Request.QueryString["InvoiceDetailId"].Split('-');
            int idFactNumber = int.Parse(key[0]);
            string type = key[1];
            int idYear = int.Parse(key[2]);
            int idLigneNumber = int.Parse(key[3]);
            IList<InvoiceDetails> invDetailList = repo.GetInvoiceDetailsOfInvoice(
                idFactNumber, type, idYear, idLigneNumber);
            if (invDetailList.Count == 1)
            {
                InvoiceDetails invDetail = invDetailList[0];
                invDetail.Description = txtDescription.Text;
                invDetail.Quantity = txtQuantity.Value;
                invDetail.UnitPriceEuro = txtUnitPrice.Value;
                invDetail.AmountEuro = (invDetail.Quantity.HasValue ? invDetail.Quantity.Value : 0) *
                    (invDetail.UnitPriceEuro.HasValue ? invDetail.UnitPriceEuro.Value : 0);
                invDetail.VatCode = int.Parse(ddlVAT.SelectedValue);
                repo.UpdateInvoiceDetails(invDetail);
                repoInv.ReComputeAmountOfInvoice(idFactNumber, type, idYear);
            }
        }
        else if (!string.IsNullOrEmpty(Request.QueryString["InvoiceIdPK"]))
        {
            string[] key = Request.QueryString["InvoiceIdPK"].Split('-');
            int idFactNumber = int.Parse(key[0]);
            string type = key[1];
            int idYear = int.Parse(key[2]);
            int? idLigneNumber = repo.GetMaxInvoiceDetailOrderNumber(idFactNumber, type, idYear);
            if (!idLigneNumber.HasValue)
                idLigneNumber = 1;
            else
                idLigneNumber += 1;
            InvoiceDetails invDetail = new InvoiceDetails();
            invDetail.IdFactNumber = idFactNumber;
            invDetail.IdTypeInvoice = type;
            invDetail.IdYear = idYear;
            invDetail.IdLigneNumber = idLigneNumber.Value;

            invDetail.Description = txtDescription.Text;
            invDetail.Quantity = txtQuantity.Value;
            invDetail.UnitPriceEuro = txtUnitPrice.Value;
            invDetail.AmountEuro = (invDetail.Quantity.HasValue ? invDetail.Quantity.Value : 0) *
                    (invDetail.UnitPriceEuro.HasValue ? invDetail.UnitPriceEuro.Value : 0);
            invDetail.VatCode = int.Parse(ddlVAT.SelectedValue);
            repo.InserNewInvoiceDetails(invDetail);
            repoInv.ReComputeAmountOfInvoice(idFactNumber, type, idYear);
        }

        string script = "<script type=\"text/javascript\">";
        script += " OnBtnSaveClientClicked();";
        script += " </script>";

        if (!ClientScript.IsClientScriptBlockRegistered("saveAndCloseWindow"))
            ClientScript.RegisterStartupScript(this.GetType(), "saveAndCloseWindow", script);
    }
Ejemplo n.º 2
0
 public InvoicesService(InvoicesRepository invoicesRepository,
                        InvoicesWorkflowStagesRepository workflowStagesRepository,
                        InvoicesApprovalWorkflowRepository invoicesApprovalWorkflowRepository)
 {
     this.invoicesRepository                 = invoicesRepository;
     this.workflowStagesRepository           = workflowStagesRepository;
     this.invoicesApprovalWorkflowRepository = invoicesApprovalWorkflowRepository;
 }
Ejemplo n.º 3
0
 public DashboardController(UsersRepository usersRepo,
                            CustomersRepository customerRepo,
                            InvoicesRepository invoiceRepo,
                            GeoDivisionsRepository geoDivisonsRepo)
 {
     _usersRepo       = usersRepo;
     _customerRepo    = customerRepo;
     _invoiceRepo     = invoiceRepo;
     _geoDivisonsRepo = geoDivisonsRepo;
 }
        public async Task GetById_WhenNotPresent_ReturnsNull(Func <string, InvoicingContext> factory)
        {
            //Arrange
            using (var context = factory(nameof(GetById_WhenNotPresent_ReturnsNull)))
            {
                var sut = new InvoicesRepository(context);

                //Act
                var invoice = await sut.Get(100);

                //Assert
                invoice.Should().BeNull();
            }
        }
        public async Task GetNotesByInvoice_WhenInvoiceExistsButHasNoNotes_ReturnsEmpty(Func <string, InvoicingContext> factory)
        {
            //Arrange
            using (var context = factory(nameof(GetNotesByInvoice_WhenInvoiceExistsButHasNoNotes_ReturnsEmpty)))
            {
                var sut = new InvoicesRepository(context);

                //Act
                var notes = await sut.GetNotesBy(2);

                //Assert
                notes.Should().NotBeNull();
                notes.Should().BeEmpty();
            }
        }
        public async Task GetNotesByInvoiceId_WhenExists_ReturnsNotes(Func <string, InvoicingContext> factory)
        {
            //Arrange
            using (var context = factory(nameof(GetNotesByInvoiceId_WhenExists_ReturnsNotes)))
            {
                var invoiceId = 1;
                var sut       = new InvoicesRepository(context);

                //Act
                var notes = await sut.GetNotesBy(invoiceId);

                //Assert
                notes.Should().NotBeNullOrEmpty();
            }
        }
        public async Task GetById_WhenExists_ReturnsInvoice(Func <string, InvoicingContext> factory)
        {
            //Arrange
            using (var context = factory(nameof(GetById_WhenExists_ReturnsInvoice)))
            {
                var invoiceId = 1;
                var sut       = new InvoicesRepository(context);

                //Act
                var invoice = await sut.Get(invoiceId);

                //Assert
                invoice.Should().NotBeNull();
                invoice.InvoiceId.Should().Be(invoiceId);
            }
        }
        static void Main()
        {
            Console.Write("Informe o alias do tenant: ");
            var tenantAlias = Console.ReadLine();

            Console.Write("Informe o nome do tenant: ");
            var tenantBusiness = Console.ReadLine();

            Console.Write("Informe a url para database do tenant: ");
            var tenantDatabase = Console.ReadLine();

            var urlDatabase = "http://gabriel-nt:8080";
            var repository  = new TenantsRepository(urlDatabase);
            var tenant      = Tenant.Create(tenantAlias, tenantBusiness, tenantDatabase);

            repository.Save(tenant);

            var canExit = false;

            while (!canExit)
            {
                Console.WriteLine("Inclusão de fatura");
                Console.WriteLine("");

                Console.Write("Informe o nome do cliente: ");
                var clientInfo = Console.ReadLine();
                Console.Write("Informe o valor da fatura: ");
                var ammount           = Convert.ToDecimal(Console.ReadLine());
                var invoice           = Invoice.Create(clientInfo, ammount);
                var invoiceRepository = new InvoicesRepository(tenant);
                invoiceRepository.Save(invoice);

                Console.WriteLine();
                Console.Write("Incluir outra invoice? ");
                var pressKey = Console.ReadKey();
                if (pressKey.Key == ConsoleKey.N)
                {
                    canExit = true;
                }
                Console.Clear();
            }


            Console.Read();
        }
Ejemplo n.º 9
0
        public MainWindow()
        {
            InitializeComponent();

            try
            {
                //TODO: retrieve invoices due from data layer
                List <Invoice> invoices = new List <Invoice>();
                invoices = InvoicesRepository.GetInvoices();
                //TODO: show a message box when no invoiced are due and close the application
                InvoicesListView.ItemsSource = invoices;

                //InvoicesListView.ItemsSource = InvoicesRepository.GetInvoices();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, ex.GetType().ToString());
                Close();
            }
        }
Ejemplo n.º 10
0
        public async Task UpdateInvoice_WhenInvoiceValid_ReturnsInvoice(Func <string, InvoicingContext> factory)
        {
            //Arrange
            var db = nameof(UpdateInvoice_WhenInvoiceValid_ReturnsInvoice);
            int nextInvoiceId;

            using (var context = factory(db))
            {
                nextInvoiceId = await context.GetNextInvoiceId();

                var invoice = new Invoice
                {
                    InvoiceId  = nextInvoiceId,
                    Amount     = 1,
                    Identifier = "INV-" + nextInvoiceId,
                    UpdatedBy  = "Test"
                };

                context.Invoices.Add(invoice);
                await context.SaveChangesAsync();
            }

            //Act
            using (var context = factory(db))
            {
                var sut = new InvoicesRepository(context);

                var invoice = context.Invoices.Find(nextInvoiceId);
                invoice.Amount = 100;

                await sut.Update();
            }

            //Assert
            using (var context = factory(nameof(UpdateInvoice_WhenInvoiceValid_ReturnsInvoice)))
            {
                var invoice = context.Invoices.Find(nextInvoiceId);

                invoice.Amount.Should().Be(100);
            }
        }
Ejemplo n.º 11
0
    protected void OnBtnGoClicked(object sender, EventArgs e)
    {
        if (!datStartDate.SelectedDate.HasValue || !datEndDate.SelectedDate.HasValue)
        {
            string message = ResourceManager.GetString("messageInvalidDateTurnover");
            string script = "<script type=\"text/javascript\">";
            script += " alert(\"" + message + "\");";
            script += " </script>";

            if (!ClientScript.IsClientScriptBlockRegistered("ttt"))
                ClientScript.RegisterStartupScript(this.GetType(), "ttt", script);
        }
        else
        {
            InvoicesRepository repo = new InvoicesRepository();
            double? iAmount = repo.GetSumAmountNotVAT("I", datStartDate.SelectedDate, datEndDate.SelectedDate);
            double? cAmount = repo.GetSumAmountNotVAT("C", datStartDate.SelectedDate, datEndDate.SelectedDate);
            double result = (iAmount.HasValue ? iAmount.Value : 0) - (cAmount.HasValue ? cAmount.Value : 0);
            txtResult.Text = result.ToString();
        }
    }
        public void ItReturnsNotNullModel()
        {
            // Arrange
            AviTradeContext dbContext = new AviTradeContext();
            IItemsRepository itemsRepository = new ItemsRepository(dbContext);
            IAirportsRepository airportsRepository = new AirportsRepository(dbContext);
            IAircraftsRepository aircraftsRepository = new AircraftsRepository(dbContext);
            IContractsRepository contractsRepository = new ContractsRepository(dbContext);
            ITradersRepository tradersRepository = new TradersRepository(dbContext);
            IPeriodsRepository periodsRepository = new PeriodsRepository(dbContext);
            IInvoicesRepository invoicesRepository = new InvoicesRepository(dbContext, periodsRepository);
            ICurrenciesRepository currenciesRepository = new CurrenciesRepository(dbContext);
            IOrdersRepository ordersRepository = new OrdersRepository(dbContext, contractsRepository, airportsRepository, aircraftsRepository, itemsRepository, currenciesRepository, invoicesRepository);
            DataServiceController controller = null; // new DataServiceController(contractsRepository, tradersRepository, ordersRepository, itemsRepository, airportsRepository, aircraftsRepository);

            // Act
            AjaxOrdersViewModel model = controller.BuildAjaxOrdersViewModel(1, 0, "1,2,3,4", DateTime.Now.AddDays(30),
                                                                            true, 0, 20);

            // Assert
            Assert.IsNotNull(model);
        }
        public async Task CreateInvoice_WhenInvoiceValid_ReturnsInvoice(Func <string, InvoicingContext> factory)
        {
            //Arrange
            using (var context = factory(nameof(CreateInvoice_WhenInvoiceValid_ReturnsInvoice)))
            {
                var nextInvoiceId = await context.GetNextInvoiceId();

                var invoice = new Invoice
                {
                    InvoiceId  = nextInvoiceId,
                    Identifier = "INV-" + nextInvoiceId,
                    UpdatedBy  = "Test"
                };
                var sut = new InvoicesRepository(context);

                //Act
                await sut.Create(invoice);

                //Assert
                invoice.Should().NotBeNull();
                invoice.InvoiceId.Should().BeGreaterThan(0);
            }
        }
        public ContractorAppController(AccountantsRepository accountant,
            CarRepository car,
            ChequesRepository cheaque,
            CompaniesRepository companies,
            ContactsLoanRepository contactLoans,
            ExpensesRepository expenses,
            ExpensesTypes expensesTypes,

           FinancialcustodyRepository finacialCustody,
           InventoryprojectreleaseRepository inventoryprojectrelease,
           InventoryRepository inventory,
           InvoicesitemsRepository invoiceItem,
           InvoicesRepository invoice,
           LoansItemsRepository loanItems,
           LoansRepository loans,
           ProjectItemsRepository projectItems,
            UsersRepository userRepository
            )
        {
            _userRepository = userRepository;
            _accountant = accountant;
            _car = car;
            _cheaque = cheaque;
            _companies = companies;
            _contactLoans = contactLoans;
            _expenses = expenses;
            _expensesTypes = expensesTypes;

            _finacialCustody = finacialCustody;
            _inventoryprojectrelease = inventoryprojectrelease;
            _inventory = inventory;
            _invoiceItem = invoiceItem;
            _invoice = invoice;
            _loanItems = loanItems;
            _loans = loans;
            _projectItems = projectItems;
        }
Ejemplo n.º 15
0
    protected void OnButtonInvoicePrintSelectionClicked(object sender, EventArgs e)
    {
        List<InvoicingFile> fileList = new List<InvoicingFile>();
        GridItemCollection col = gridInvoice.SelectedItems;
        foreach (GridDataItem item in col)
        {
            TableCell cell = item["InvoiceIdPK"];
            if (!string.IsNullOrEmpty(cell.Text))
            {
                string[] key = cell.Text.Split('-');
                int idFactNumber = int.Parse(key[0]);
                string type = key[1];
                int idYear = int.Parse(key[2]);
                Invoices invoice = new InvoicesRepository().GetInvoiceByID(idFactNumber, type, idYear);
                string fileName = Common.ExportInvoices(invoice, WebConfig.AddressFillInInvoice,
                    WebConfig.AbsoluteExportDirectory);

                InvoicingFile file = new InvoicingFile();
                file.InvoiceIdPK = invoice.InvoiceIdPK;
                file.FilePath = fileName;
                fileList.Add(file);
            }
        }
        InvoicingMView.ActiveViewIndex = 1;
        ProcessPrintedFiles(fileList);

        /*string message = ResourceManager.GetString("messageExportSuccessfully");
        string script1 = "<script type=\"text/javascript\">";
        script1 += " alert(\"" + message + "\")";
        script1 += " </script>";

        if (!ClientScript.IsClientScriptBlockRegistered("redirectUser"))
            ClientScript.RegisterStartupScript(this.GetType(), "redirectUser", script1);*/
    }
Ejemplo n.º 16
0
    protected void OnInvoiceDeleteClicked(object sender, EventArgs e)
    {
        LinkButton lnkItem = (LinkButton)sender;
        string invoiceID = lnkItem.CommandArgument;
        if (!string.IsNullOrEmpty(invoiceID))
        {
            string[] key = invoiceID.Split('-');
            int idFactNumber = int.Parse(key[0]);
            string type = key[1];
            int idYear = int.Parse(key[2]);

            //Delete Invoice's payments first.
            InvoicePaymentsRepository payRepo = new InvoicePaymentsRepository();
            payRepo.DeleteInvoicePaymentsOfInvoice(idFactNumber, type, idYear);

            //Delete invoice's details
            InvoiceDetailsRepository detailRepo = new InvoiceDetailsRepository();
            detailRepo.DeleteInvoiceDetails(idFactNumber, type, idYear, null);

            //Delete Invoice
            InvoicesRepository invoiceRepo = new InvoicesRepository();
            invoiceRepo.DeleteInvoice(idFactNumber, type, idYear);

            BindGridData(null);
            gridInvoice.DataBind();
        }
    }
Ejemplo n.º 17
0
    protected void OnInvoiceGridItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridDataItem)
        {
            GridDataItem dataItem = e.Item as GridDataItem;
            LinkButton buttonDelete = dataItem["TemplateDeleteInvoiceColumn"].Controls[1] as LinkButton;

            //Check that this invoice is the last invoice of a fiscal year.
            string invoiceIdPK = ((Invoices)e.Item.DataItem).InvoiceIdPK;
            string[] key = invoiceIdPK.Split('-');
            int idFactNumber = int.Parse(key[0]);
            string type = key[1];
            int idYear = int.Parse(key[2]);
            bool canDelete = true;
            InvoicesRepository invoiceRepo = new InvoicesRepository();
            int firstFutureNumber = int.Parse(WebConfig.FirstNumberFutureInvoice);
            if (firstFutureNumber > idFactNumber)
            {
                Invoices lastNormalInvoice = invoiceRepo.GetInvoicesWithMaxNumber(
                        idYear, type, false, firstFutureNumber);
                if (lastNormalInvoice != null && idFactNumber != lastNormalInvoice.IdFactNumber)
                {
                    canDelete = false;
                }
            }

            if(canDelete)
                buttonDelete.OnClientClick = "return confirm('" + ResourceManager.GetString("deleteConfirmText") + "')";
            else
                buttonDelete.OnClientClick = string.Format("javascript:alert('{0}'); return false;", ResourceManager.GetString("messageInvoiceCanNotDelete"));

            if (!string.IsNullOrEmpty(Request.QueryString["type"]) && Request.QueryString["type"] == "future")
            {
                buttonDelete.OnClientClick = string.Empty;
            }

            buttonDelete.CommandArgument = ((Invoices)e.Item.DataItem).InvoiceIdPK;
            buttonDelete.Text = ResourceManager.GetString("deleteText");

            HyperLink hypEdit = dataItem["TemplateEditInvoiceColumn"].Controls[1] as HyperLink;
            hypEdit.Text = ResourceManager.GetString("editText");

            HyperLink hypInvoice = dataItem["TemplateInvoiceInvoiceColumn"].Controls[1] as HyperLink;
            hypInvoice.Text = ResourceManager.GetString("lblInvoiceInvoice");
        }
        if (e.Item.ItemType == GridItemType.Item || e.Item.ItemType == GridItemType.AlternatingItem)
        {
            Invoices invoice = (Invoices)e.Item.DataItem;
            if (invoice.Payement.HasValue && invoice.Payement.Value)
            {
                e.Item.BackColor = Color.YellowGreen;
            }
        }
    }
Ejemplo n.º 18
0
    protected void OnButtonInvoiceEmailSelectionClicked(object sender, EventArgs e)
    {
        GridItemCollection col = gridInvoice.SelectedItems;
        IList<Invoices> invoiceList = new List<Invoices>();
        string email = string.Empty;
        foreach (GridDataItem item in col)
        {
            TableCell cell = item["InvoiceIdPK"];
            if (!string.IsNullOrEmpty(cell.Text))
            {
                string[] key = cell.Text.Split('-');
                int idFactNumber = int.Parse(key[0]);
                string type = key[1];
                int idYear = int.Parse(key[2]);
                Invoices invoice = new InvoicesRepository().GetInvoiceByID(idFactNumber, type, idYear);
                invoiceList.Add(invoice);
                CompanyAddress address = new CompanyAddressRepository().FindOne(
                    new CompanyAddress(invoice.RefCustomerNumber.Value));

                if (!string.IsNullOrEmpty(address.Email))
                {
                    if (email == string.Empty)
                    {
                        email = address.Email.Trim();
                    }
                    else if (email != address.Email.Trim())
                    {
                        string message = ResourceManager.GetString("messageInvoicesNotHaveSameEmail");
                        string script1 = "<script type=\"text/javascript\">";
                        script1 += " alert(\"" + message + "\")";
                        script1 += " </script>";

                        if (!ClientScript.IsClientScriptBlockRegistered("redirectUser"))
                            ClientScript.RegisterStartupScript(this.GetType(), "redirectUser", script1);
                        return;
                    }
                }
                else
                {
                    string message = ResourceManager.GetString("messageInvoiceNotHaveAnyEmail");
                    string script1 = "<script type=\"text/javascript\">";
                    script1 += " alert(\"" + message + "\")";
                    script1 += " </script>";

                    if (!ClientScript.IsClientScriptBlockRegistered("redirectUser"))
                        ClientScript.RegisterStartupScript(this.GetType(), "redirectUser", script1);
                    return;
                }
            }
        }

        Microsoft.Office.Interop.Outlook.Application outlookApp =
                        new Microsoft.Office.Interop.Outlook.Application();
        Microsoft.Office.Interop.Outlook.MailItem mailItem =
            (Microsoft.Office.Interop.Outlook.MailItem)
            outlookApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
        mailItem.To = email;
        mailItem.Subject = "Send invoice";

        foreach (Invoices item in invoiceList)
        {
            string fileName = Common.ExportInvoices(
                item, WebConfig.AddressFillInInvoice, WebConfig.AbsoluteExportDirectory);
            mailItem.Attachments.Add(fileName,
                Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue, Type.Missing, Type.Missing);
        }
        mailItem.Display(true);
    }
Ejemplo n.º 19
0
 public InvoicesController(InvoicesRepository repo, GeoDivisionsRepository geoRepo)
 {
     _repo    = repo;
     _GeoRepo = geoRepo;
 }
Ejemplo n.º 20
0
    private void BindGridData(GridSortCommandEventArgs sortEventArgs)
    {
        InvoicesRepository repo = new InvoicesRepository();
        IList<Invoices> list = new List<Invoices>();
        if (!string.IsNullOrEmpty(Request.QueryString["type"]) && Request.QueryString["type"] == "search")
        {
            int pageNumber = gridInvoice.CurrentPageIndex + 1;
            string sortExpress = string.Empty;
            string sortExpressInvert = string.Empty;
            foreach (GridSortExpression item in gridInvoice.MasterTableView.SortExpressions)
            {
                GridSortOrder newSortOrder = item.SortOrder;
                if (sortEventArgs != null && item.FieldName == sortEventArgs.SortExpression)
                {
                    newSortOrder = sortEventArgs.NewSortOrder;
                }

                if (!string.IsNullOrEmpty(sortExpress) && newSortOrder != GridSortOrder.None)
                {
                    sortExpress += ", ";
                    sortExpressInvert += ", ";
                }
                if (newSortOrder == GridSortOrder.Ascending)
                {
                    sortExpress += item.FieldName + " ASC";
                    sortExpressInvert += item.FieldName + " DESC";
                }
                else if (newSortOrder == GridSortOrder.Descending)
                {
                    sortExpress += item.FieldName + " DESC";
                    sortExpressInvert += item.FieldName + " ASC";
                }
            }

            if (sortEventArgs != null && !sortExpress.Contains(sortEventArgs.SortExpression))
            {
                if (!string.IsNullOrEmpty(sortExpress) && sortEventArgs.NewSortOrder != GridSortOrder.None)
                {
                    sortExpress += ", ";
                    sortExpressInvert += ", ";
                }
                if (sortEventArgs.NewSortOrder == GridSortOrder.Ascending)
                {
                    sortExpress += sortEventArgs.SortExpression + " ASC";
                    sortExpressInvert += sortEventArgs.SortExpression + " DESC";
                }
                else if (sortEventArgs.NewSortOrder == GridSortOrder.Descending)
                {
                    sortExpress += sortEventArgs.SortExpression + " DESC";
                    sortExpressInvert += sortEventArgs.SortExpression + " ASC";
                }
            }

            if (!string.IsNullOrEmpty(sortExpress))
            {
                if (sortExpress.Contains("CompanyName"))
                {
                    sortExpress = sortExpress.Replace("CompanyName", "SocNom");
                    sortExpressInvert = sortExpressInvert.Replace("CompanyName", "SocNom");
                }
                if (sortExpress.Contains("CompanyId"))
                {
                    sortExpress = sortExpress.Replace("CompanyId", "SocieteID");
                    sortExpressInvert = sortExpressInvert.Replace("CompanyId", "SocieteID");
                }
                if (sortExpress.Contains("InvoiceDate"))
                {
                    sortExpress = sortExpress.Replace("InvoiceDate", "Date");
                    sortExpressInvert = sortExpressInvert.Replace("InvoiceDate", "Date");
                }
            }
            else
            {
                sortExpress = "IdYear DESC, IdFactNumber DESC, IdTypeInvoice ASC";
                sortExpressInvert = "IdYear ASC, IdFactNumber ASC, IdTypeInvoice DESC";
            }

            InvoicesSearchCriteria criteria = GetSearchCriteria();

            if (!string.IsNullOrEmpty(Request.QueryString["invoiceNumberFrom"]))
                criteria.InvoiceNumberFrom = int.Parse(Request.QueryString["invoiceNumberFrom"]);
            if (!string.IsNullOrEmpty(Request.QueryString["invoiceNumberTo"]))
                criteria.InvoiceNumberTo = int.Parse(Request.QueryString["invoiceNumberTo"]);

            if (!string.IsNullOrEmpty(Request.QueryString["fiscalYear"]))
                criteria.FiscalYear = int.Parse(Request.QueryString["fiscalYear"]);

            if (!string.IsNullOrEmpty(Request.QueryString["dateFrom"]))
                criteria.InvoiceDateFrom = DateTime.ParseExact(Request.QueryString["dateFrom"], "dd/MM/yyyy",
                    System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat);
            if (!string.IsNullOrEmpty(Request.QueryString["dateTo"]))
                criteria.InvoiceDateTo = DateTime.ParseExact(Request.QueryString["dateTo"], "dd/MM/yyyy",
                    System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat);

            if (!string.IsNullOrEmpty(Request.QueryString["invoiceType"]))
                criteria.InvoiceType = Request.QueryString["invoiceType"];

            if (!string.IsNullOrEmpty(Request.QueryString["customer"]))
                criteria.Customer = int.Parse(Request.QueryString["customer"]);

            gridInvoice.VirtualItemCount = repo.CountInvoices(criteria, pageSize, pageNumber, sortExpress, sortExpressInvert);
            list = repo.SearchInvoices(criteria, pageSize, pageNumber, sortExpress, sortExpressInvert);
        }
        else if (!string.IsNullOrEmpty(Request.QueryString["type"]) && Request.QueryString["type"] == "future")
        {
            lblTitle.Text = ResourceManager.GetString("lblInvoiceFutureGridHeader");
            list = repo.GetFutureInvoices(int.Parse(WebConfig.FirstNumberFutureInvoice));

        }
        else if (!string.IsNullOrEmpty(Request.QueryString["CompanyId"]))
        {
            int companyID = int.Parse(Request.QueryString["CompanyId"]);
            list = repo.GetUnpaidInvoicesOfCompany(companyID, false);
        }
        else
        {
            int notConfirmedFuture = repo.CountNotConfirmedFutureInvoices(int.Parse(WebConfig.FirstNumberFutureInvoice));
            if (notConfirmedFuture > 0)
            {
                Response.Redirect("InvoicesPage.aspx?type=future");
            }
        }

        gridInvoice.DataSource = list;
        btnPrintAll.Visible = (list.Count > 0);
        btnExcelExport.Visible = (list.Count > 0);
        //btnPrintSelection.Visible = false;
    }
Ejemplo n.º 21
0
        public void GetInvoiceCheck()
        {
            var repo = new InvoicesRepository();

            repo.GetClientUsageDetails(15, new DateTime(2018, 12, 6), new DateTime(2019, 1, 10));
        }
Ejemplo n.º 22
0
    protected void OnButtonInvoiceEditSaveClicked(object sender, EventArgs e)
    {
        if (btnEditSave.Text == ResourceManager.GetString("editText"))
        {
            //Change mode to Edit mode.
            //btnEditSave.Text = ResourceManager.GetString("saveText");
            //EnableInvoiceControls(true);
            //lnkAddInvoiceDetail.OnClientClick = "return OnAddNewInvoiceDetailClientClicked('"
            //    + SessionManager.CurrentInvoice.InvoiceIdPK + "')";
            //lnkAddNewPayment.OnClientClick = "return OnAddNewInvoicePaymentClientClicked('"
            //    + SessionManager.CurrentInvoice.InvoiceIdPK + "')";
            //btnExport.Visible = false;
            string url = Request.Url.PathAndQuery;

            if (!string.IsNullOrEmpty(Request.QueryString["mode"]))
                url = url.Replace(Request.QueryString["mode"], "edit");
            else
                url += "&mode=edit";
            Response.Redirect(url, true);
        }
        else if (Request.QueryString["type"] == "copy")
        {
            string message;
            SessionManager.CurrentInvoice = null;
            Invoices saveItem = GetInvoice(out message);
            if (!string.IsNullOrEmpty(message))
            {
                string script = "<script type=\"text/javascript\">";
                script += " alert(\"" + message + "\")";
                script += " </script>";

                if (!ClientScript.IsClientScriptBlockRegistered("redirectUser"))
                    ClientScript.RegisterStartupScript(this.GetType(), "redirectUser", script);
                return;
            }
            InvoicesRepository repo = new InvoicesRepository();
            repo.InserNewInvoices(saveItem);
            //insert invoice details
            if (!string.IsNullOrEmpty(Request.QueryString["from"]))
            {
                string invoideIDPK = Request.QueryString["from"];
                string[] key = invoideIDPK.Split('-');
                int idFactNumber = int.Parse(key[0]);
                string type = key[1];
                int idYear = int.Parse(key[2]);

                InvoiceDetailsRepository detailRepo = new InvoiceDetailsRepository();
                IList<InvoiceDetails> detailList = detailRepo.GetInvoiceDetailsOfInvoice(idFactNumber, type, idYear, null);
                foreach (InvoiceDetails detail in detailList)
                {
                    detail.IdFactNumber = saveItem.IdFactNumber;
                    detail.IdTypeInvoice = saveItem.IdTypeInvoice;
                    detail.IdYear = saveItem.IdYear;

                    detailRepo.InserNewInvoiceDetails(detail);
                }
            }

            Response.Redirect("~/InvoiceProfile.aspx?InvoiceIdPK=" + saveItem.InvoiceIdPK + "&mode=edit", true);
        }
        else
        {
            string message;
            //Save data.
            Invoices saveItem = GetInvoice(out message);
            if (!string.IsNullOrEmpty(message))
            {
                string script = "<script type=\"text/javascript\">";
                script += " alert(\"" + message + "\")";
                script += " </script>";

                if (!ClientScript.IsClientScriptBlockRegistered("redirectUser"))
                    ClientScript.RegisterStartupScript(this.GetType(), "redirectUser", script);
                return;
            }
            InvoicesRepository repo = new InvoicesRepository();

            //if (SessionManager.CurrentInvoice != null)
            if (!string.IsNullOrEmpty(Request.QueryString["InvoiceIdPK"]))
            {
                repo.UpdateInvoices(saveItem);
            }
            else
            {
                repo.InserNewInvoices(saveItem);
            }

            if (saveItem.IdFactNumberNew.HasValue)
                SessionManager.CurrentInvoice = repo.GetInvoiceByID(saveItem.IdFactNumberNew.Value, saveItem.IdTypeInvoice, saveItem.IdYear);
            else
                SessionManager.CurrentInvoice = repo.GetInvoiceByID(saveItem.IdFactNumber, saveItem.IdTypeInvoice, saveItem.IdYear);

            if (SessionManager.CurrentInvoice.CompanyId.HasValue)
            {
                txtIdCustomer.Text = SessionManager.CurrentInvoice.CompanyId.ToString();
                txtCustomerName.Text = SessionManager.CurrentInvoice.CompanyName.Trim();
            }
            txtInvoiceNumber.Text = SessionManager.CurrentInvoice.IdFactNumber.ToString();
            //    //Change mode to View mode

            string addBackUrl = string.Empty;
            if (!string.IsNullOrEmpty(Request.QueryString["backurl"]) && Request.QueryString["backurl"] == "visible")
            {
                addBackUrl = "&backurl=visible";
            }
            Response.Redirect(string.Format("~/InvoiceProfile.aspx?InvoiceIdPK={0}&mode=view" + addBackUrl, SessionManager.CurrentInvoice.InvoiceIdPK), true);
        }
    }
Ejemplo n.º 23
0
    protected void OnInvoiceProfileAjaxManagerAjaxRequest(object sender, AjaxRequestEventArgs e)
    {
        if (e.Argument.IndexOf("DataBindCompanyAddress") != -1)
        {
            string[] param = e.Argument.Split('-');
            if (param.Length == 2)
            {
                invoiceProfileAjaxManager.AjaxSettings.AddAjaxSetting(invoiceProfileAjaxManager, divHeader);
                //invoiceProfileAjaxManager.AjaxSettings.AddAjaxSetting(invoiceProfileAjaxManager, txtAddressName);
                //invoiceProfileAjaxManager.AjaxSettings.AddAjaxSetting(invoiceProfileAjaxManager, txtAddress);
                //invoiceProfileAjaxManager.AjaxSettings.AddAjaxSetting(invoiceProfileAjaxManager, txtZipCode);
                //invoiceProfileAjaxManager.AjaxSettings.AddAjaxSetting(invoiceProfileAjaxManager, txtCity);
                //invoiceProfileAjaxManager.AjaxSettings.AddAjaxSetting(invoiceProfileAjaxManager, txtVatNumber);
                //invoiceProfileAjaxManager.AjaxSettings.AddAjaxSetting(invoiceProfileAjaxManager, btnChooseAddress);

                invoiceProfileAjaxManager.AjaxSettings.AddAjaxSetting(invoiceProfileAjaxManager, hiddenCompanyAddressId);
                int companyID = int.Parse(param[1]);
                Company company = new CompanyRepository().FindOne(new Company(companyID));
                txtCustomerName.Text = company.CompanyName;
                txtIdCustomer.Text = companyID.ToString();

                IList<CompanyAddress> comAdrList = new CompanyAddressRepository().GetAddressesOfCompany(companyID);
                hiddenCompanyAddressId.Value = null;

                txtAddressName.Text = null;
                txtAddress.Text = null;
                txtZipCode.Text = null;
                txtCity.Text = null;
                txtVatNumber.Text = null;
                foreach (CompanyAddress item in comAdrList)
                {
                    if (item.IsDefault)
                    {
                        hiddenCompanyAddressId.Value = item.AddressID.ToString();
                        txtAddressName.Text = item.Name;
                        txtAddress.Text = item.Address;
                        txtZipCode.Text = item.ZipCode;
                        txtCity.Text = item.City;
                        txtVatNumber.Text = item.VatNumber;
                        break;
                    }
                }
                btnChooseAddress.Enabled = true;
            }
        }

        else if (e.Argument.IndexOf("RebindInvoiceDetailData") != -1)
        {
            invoiceProfileAjaxManager.AjaxSettings.AddAjaxSetting(invoiceProfileAjaxManager, divTotal);
            //invoiceProfileAjaxManager.AjaxSettings.AddAjaxSetting(invoiceProfileAjaxManager, txtTotalHTVA);
            //invoiceProfileAjaxManager.AjaxSettings.AddAjaxSetting(invoiceProfileAjaxManager, txtTotalVAT);
            //invoiceProfileAjaxManager.AjaxSettings.AddAjaxSetting(invoiceProfileAjaxManager, txtTotal);
            //invoiceProfileAjaxManager.AjaxSettings.AddAjaxSetting(invoiceProfileAjaxManager, txtPaymentDate);
            //invoiceProfileAjaxManager.AjaxSettings.AddAjaxSetting(invoiceProfileAjaxManager, txtPayment);
            //invoiceProfileAjaxManager.AjaxSettings.AddAjaxSetting(invoiceProfileAjaxManager, chkPayment);
            invoiceProfileAjaxManager.AjaxSettings.AddAjaxSetting(invoiceProfileAjaxManager, gridInvoiceDetails);
            gridInvoiceDetails.Rebind();
        }
        else if (e.Argument.IndexOf("RebindInvoicePaymentData") != -1)
        {
            invoiceProfileAjaxManager.AjaxSettings.AddAjaxSetting(invoiceProfileAjaxManager, divTotal);
            //invoiceProfileAjaxManager.AjaxSettings.AddAjaxSetting(invoiceProfileAjaxManager, txtPaymentDate);
            //invoiceProfileAjaxManager.AjaxSettings.AddAjaxSetting(invoiceProfileAjaxManager, txtPayment);
            //invoiceProfileAjaxManager.AjaxSettings.AddAjaxSetting(invoiceProfileAjaxManager, chkPayment);
            invoiceProfileAjaxManager.AjaxSettings.AddAjaxSetting(invoiceProfileAjaxManager, gridInvoicePayments);
            gridInvoicePayments.Rebind();
        }
        else if (e.Argument.IndexOf("ViewEditInvoice") != -1)
        {
            string url = Request.Url.PathAndQuery;

            if (hidMode.Value == "view")
            {
                if (!string.IsNullOrEmpty(Request.QueryString["mode"]))
                    url = url.Replace(Request.QueryString["mode"], "edit");
                else
                    url += "&mode=edit";
                Response.Redirect(url, true);
            }
            else
            {
                if (!string.IsNullOrEmpty(Request.QueryString["mode"]))
                    url = url.Replace(Request.QueryString["mode"], "view");
                else
                    url += "&mode=view";
                Response.Redirect(url, true);
            }
        }
        else if (e.Argument.IndexOf("SaveInvoice") != -1)
        {
            string message;
            Invoices saveItem = GetInvoice(out message);
            if (!string.IsNullOrEmpty(message))
            {
                string script = "<script type=\"text/javascript\">";
                script += " alert(\"" + message + "\")";
                script += " </script>";

                if (!ClientScript.IsClientScriptBlockRegistered("redirectUser"))
                    ClientScript.RegisterStartupScript(this.GetType(), "redirectUser", script);
                return;
            }
            InvoicesRepository repo = new InvoicesRepository();
            if (SessionManager.CurrentInvoice != null)
            {
                repo.UpdateInvoices(saveItem);
            }
            else
            {
                repo.InserNewInvoices(saveItem);
            }
            SessionManager.CurrentInvoice = saveItem;

            string addBackUrl = string.Empty;
            if (!string.IsNullOrEmpty(Request.QueryString["backurl"]) && Request.QueryString["backurl"] == "visible")
            {
                addBackUrl = "&backurl=visible";
            }
            Response.Redirect(string.Format("~/InvoiceProfile.aspx?InvoiceIdPK={0}&mode=view" + addBackUrl, SessionManager.CurrentInvoice.InvoiceIdPK), true);
            //string url = Request.Url.PathAndQuery;
            //if (!string.IsNullOrEmpty(Request.QueryString["mode"]))
            //    url = url.Replace(Request.QueryString["mode"], "view");
            //else
            //    url += "&mode=view";
            //Response.Redirect(url, true);
        }
        else if (e.Argument.IndexOf("PrintInvoice") != -1)
        {
           /* Common.ExportInvoices(SessionManager.CurrentInvoice,
            WebConfig.AddressFillInInvoice, WebConfig.AbsoluteExportDirectory);
            string script = " alert(\"" + ResourceManager.GetString("messageExportSuccessfully") + "\")";
            invoiceProfileAjaxManager.ResponseScripts.Add(script);*/
        }
        else if (e.Argument.IndexOf("EmailInvoice") != -1)
        {
            if (!string.IsNullOrEmpty(Request.QueryString["InvoiceIdPK"]))
            {
                string selectedInvoiceIDs = Request.QueryString["InvoiceIdPK"];
                string url = "SendEmail.aspx?type=invoice&ids=" + selectedInvoiceIDs;
                invoiceProfileAjaxManager.ResponseScripts.Add(string.Format("OnSendInvoiceByEmail('{0}')", url));
            }
        }
    }
Ejemplo n.º 24
0
    private Invoices GetInvoice(out string message)
    {
        message = string.Empty;
        InvoicesRepository invoiceRepo = new InvoicesRepository();
        if (!datInvoiceDate.SelectedDate.HasValue)
        {
            message = ResourceManager.GetString("messageInvoiceDateNotNull");
            return null;
        }

        string[] fiscalKey = WebConfig.FiscalDate.Split('/');

        Invoices saveItem = null;
        int firstFutureNumber = int.Parse(WebConfig.FirstNumberFutureInvoice);
        //if (SessionManager.CurrentInvoice != null)
        if (!string.IsNullOrEmpty(Request.QueryString["InvoiceIdPK"]))
        {
            saveItem = SessionManager.CurrentInvoice;
            DateTime fiscalDateMin = new DateTime(saveItem.IdYear, int.Parse(fiscalKey[1]), int.Parse(fiscalKey[0]));
            DateTime fiscalDateMax = new DateTime(saveItem.IdYear + 1, int.Parse(fiscalKey[1]), int.Parse(fiscalKey[0]));
            if (datInvoiceDate.SelectedDate.Value < fiscalDateMin
                || datInvoiceDate.SelectedDate.Value >= fiscalDateMax)
            {
                message = string.Format(ResourceManager.GetString("messageInvoiceDateNotValidFiscalDate"),
                    fiscalDateMin.ToString("dd/MM/yyyy"), fiscalDateMax.ToString("dd/MM/yyyy"));
                return null;
            }
            //if this is a future invoice.
            if (!string.IsNullOrEmpty(Request.QueryString["type"]) && Request.QueryString["type"] == "future")
            {
                //If change the date less than or equal today, we will change this future invoice to normal invoice.
                if (datInvoiceDate.SelectedDate.Value <= DateTime.Today)
                {
                    Invoices lastNormalInvoice = invoiceRepo.GetInvoicesWithMaxNumber(
                        saveItem.IdYear, saveItem.IdTypeInvoice, false, firstFutureNumber);
                    if (lastNormalInvoice != null && lastNormalInvoice.Date.HasValue
                        && lastNormalInvoice.Date.Value > datInvoiceDate.SelectedDate.Value)
                    {
                        message = ResourceManager.GetString("messageInvoiceDateMustHigherthan") + lastNormalInvoice.Date.Value.ToString("dd/MM/yyyy");
                    }
                    else
                    {
                        saveItem.IdFactNumberNew = new InvoicesRepository().GetMaxInvoiceNumber(
                            saveItem.IdYear, saveItem.IdTypeInvoice, false, firstFutureNumber);
                        if (!saveItem.IdFactNumberNew.HasValue)
                        {
                            if (saveItem.IdTypeInvoice == "I")
                                saveItem.IdFactNumberNew = int.Parse(WebConfig.FirstNumberInvoice);
                            else
                                saveItem.IdFactNumberNew = int.Parse(WebConfig.FirstNumberCreditNote);
                        }
                        else
                        {
                            saveItem.IdFactNumberNew = saveItem.IdFactNumberNew.Value + 1;
                        }
                    }
                }
            }
            else
            {
                //If the date is changed.
                if (datInvoiceDate.SelectedDate.Value != saveItem.Date.Value)
                {
                    bool isFuture = saveItem.IdFactNumber >= firstFutureNumber;
                    Invoices nextInvoice = invoiceRepo.GetNextInvoices(saveItem.IdFactNumber,
                        saveItem.IdYear, saveItem.IdTypeInvoice, isFuture, firstFutureNumber);
                    if (nextInvoice != null && nextInvoice.Date.HasValue
                        && nextInvoice.Date.Value < datInvoiceDate.SelectedDate.Value)
                    {
                        message = ResourceManager.GetString("messageInvoiceDateMustHigherthan") + nextInvoice.Date.Value.ToString("dd/MM/yyyy");
                    }

                    Invoices previousInvoice = invoiceRepo.GetPreviousInvoices(saveItem.IdFactNumber,
                        saveItem.IdYear, saveItem.IdTypeInvoice, isFuture, firstFutureNumber);
                    if (previousInvoice != null && previousInvoice.Date.HasValue
                        && previousInvoice.Date.Value > datInvoiceDate.SelectedDate.Value)
                    {
                        message = ResourceManager.GetString("messageInvoiceDateMustLowerthan") + previousInvoice.Date.Value.ToString("dd/MM/yyyy");

                    }
                    //If this is the lasted normal invocie, then change the date to future, we have to change this invoice to future invoice.
                    if (string.IsNullOrEmpty(message))
                    {
                        int? maxNumber = invoiceRepo.GetMaxInvoiceNumber(
                            saveItem.IdYear, saveItem.IdTypeInvoice, false, firstFutureNumber);
                        if (maxNumber.HasValue && maxNumber.Value == saveItem.IdFactNumber
                            && datInvoiceDate.SelectedDate.Value > DateTime.Today)
                        {
                            int? maxNumberFuture = invoiceRepo.GetMaxInvoiceNumber(
                                saveItem.IdYear, saveItem.IdTypeInvoice, true, firstFutureNumber);
                            if (maxNumberFuture.HasValue)
                                saveItem.IdFactNumberNew = maxNumberFuture.Value + 1;
                            else
                                saveItem.IdFactNumberNew = firstFutureNumber;
                        }

                    }
                }
            }
        }
        else
        {
            saveItem = new Invoices();
            int idYear = 0;
            string type = "C";
            int idFactNumber = 0;
            if (radInvoice.Checked)
            {
                type = "I";
                idFactNumber = int.Parse(WebConfig.FirstNumberInvoice);
            }
            else
                idFactNumber = int.Parse(WebConfig.FirstNumberCreditNote);

            DateTime today = DateTime.Today;
            DateTime fiscalDate = new DateTime(DateTime.Today.Year, int.Parse(fiscalKey[1]), int.Parse(fiscalKey[0]));
            //If Current date is lower than FiscalDate in the current civil year:
            //    IdYear=Year(Current Date) – 1
            //Elseif Current date is higher than FiscalDate in the current civil year:
            //    IdYear= Year(Current Date)
            if (today < fiscalDate)
                idYear = today.Year - 1;
            else
                idYear = today.Year;

            int? maxNbr = 1;
            if (datInvoiceDate.SelectedDate.HasValue && datInvoiceDate.SelectedDate.Value > today)
            {
                maxNbr = new InvoicesRepository().GetMaxInvoiceNumber(idYear, type, true, firstFutureNumber);
                idFactNumber = firstFutureNumber;
            }
            else
            {
                maxNbr = new InvoicesRepository().GetMaxInvoiceNumber(idYear, type, false, firstFutureNumber);
            }

            if (maxNbr.HasValue)
                idFactNumber = maxNbr.Value + 1;

            saveItem.IdFactNumber = idFactNumber;
            saveItem.IdYear = idYear;
            saveItem.IdTypeInvoice = type;

            bool isFuture = saveItem.IdFactNumber >= firstFutureNumber;
            Invoices lastNormalInvoice = invoiceRepo.GetInvoicesWithMaxNumber(
                       saveItem.IdYear, saveItem.IdTypeInvoice, isFuture, firstFutureNumber);
            if (lastNormalInvoice != null && lastNormalInvoice.Date.HasValue
                    && lastNormalInvoice.Date.Value > datInvoiceDate.SelectedDate.Value)
            {
                message = ResourceManager.GetString("messageInvoiceDateMustHigherthan") + lastNormalInvoice.Date.Value.ToString("dd/MM/yyyy");
            }
        }

        saveItem.InvoiceIdPK = saveItem.IdFactNumber.ToString() + "-" + saveItem.IdTypeInvoice + "-" + saveItem.IdYear;

        saveItem.RefCustomerNumber = int.Parse(hiddenCompanyAddressId.Value);
        saveItem.Date = datInvoiceDate.SelectedDate;
        saveItem.Currency = WebConfig.Currency;
        if (!string.IsNullOrEmpty(txtTotalVAT.Text))
        {
            saveItem.AmountVatEuro = Convert.ToDouble(txtTotalVAT.Text, Common.GetDoubleFormatProvider());
        }
        else
        {
            saveItem.AmountVatEuro = 0;
        }
        if (!string.IsNullOrEmpty(txtTotalHTVA.Text))
        {
            saveItem.TotalHtvaEuro = Convert.ToDouble(txtTotalHTVA.Text, Common.GetDoubleFormatProvider());
        }
        else
        {
            saveItem.TotalHtvaEuro = 0;
        }
        saveItem.Remark = txtRemark.Text;
        saveItem.Remark_Internal = txtInternalRemark.Text;
        saveItem.Payement = chkPayment.Checked;
        saveItem.Factoring = chkFactoring.Checked;
        if (!string.IsNullOrEmpty(txtPaymentDate.Text))
            saveItem.DateOfPayement = DateTime.ParseExact(txtPaymentDate.Text, "dd/MM/yyyy",
                    System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat);
        return saveItem;
    }
 private static void SetupRepositories(AviTradeContext ctx)
 {
     _contractsRepository = new ContractsRepository(ctx);
     _airportsRepository = new AirportsRepository(ctx);
     _aircraftsRepository = new AircraftsRepository(ctx);
     _itemsRepository = new ItemsRepository(ctx);
     _currenciesRepository = new CurrenciesRepository(ctx);
     _periodsRepository = new PeriodsRepository(ctx);
     _invoicesRepository = new InvoicesRepository(ctx, _periodsRepository);
     _ordersRepository = new OrdersRepository(ctx, _contractsRepository, _airportsRepository, _aircraftsRepository, _itemsRepository, _currenciesRepository, _invoicesRepository);
     _tradersRepository = new TradersRepository(ctx);
 }
Ejemplo n.º 26
0
    protected void OnButtonInvoicePrintAllClicked(object sender, EventArgs e)
    {
        List<InvoicingFile> fileList = new List<InvoicingFile>();

        if (!string.IsNullOrEmpty(Request.QueryString["type"]) && Request.QueryString["type"] == "search")
        {
            InvoicesSearchCriteria criteria = new InvoicesSearchCriteria();
            string sortExpress = "IdFactNumber DESC, IdTypeInvoice ASC, IdYear DESC";
            string sortExpressInvert = "IdFactNumber ASC, IdTypeInvoice DESC, IdYear ASC";

            if (!string.IsNullOrEmpty(Request.QueryString["invoiceNumberFrom"]))
                criteria.InvoiceNumberFrom = int.Parse(Request.QueryString["invoiceNumberFrom"]);
            if (!string.IsNullOrEmpty(Request.QueryString["invoiceNumberTo"]))
                criteria.InvoiceNumberTo = int.Parse(Request.QueryString["invoiceNumberTo"]);

            if (!string.IsNullOrEmpty(Request.QueryString["fiscalYear"]))
                criteria.FiscalYear = int.Parse(Request.QueryString["fiscalYear"]);

            if (!string.IsNullOrEmpty(Request.QueryString["dateFrom"]))
                criteria.InvoiceDateFrom = DateTime.ParseExact(Request.QueryString["dateFrom"], "dd/MM/yyyy",
                    System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat);
            if (!string.IsNullOrEmpty(Request.QueryString["dateTo"]))
                criteria.InvoiceDateTo = DateTime.ParseExact(Request.QueryString["dateTo"], "dd/MM/yyyy",
                    System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat);

            if (!string.IsNullOrEmpty(Request.QueryString["invoiceType"]))
                criteria.InvoiceType = Request.QueryString["invoiceType"];

            if (!string.IsNullOrEmpty(Request.QueryString["customer"]))
                criteria.Customer = int.Parse(Request.QueryString["customer"]);

            InvoicesRepository repo = new InvoicesRepository();
            gridInvoice.VirtualItemCount = repo.CountInvoices(criteria, 10, 1, sortExpress, sortExpressInvert);
            IList<Invoices> list = repo.SearchInvoices(criteria, gridInvoice.VirtualItemCount,
                1, sortExpress, sortExpressInvert);
            foreach (Invoices item in list)
            {
                string filePath = Common.ExportInvoices(item, WebConfig.AddressFillInInvoice,
                    WebConfig.AbsoluteExportDirectory);

                InvoicingFile file = new InvoicingFile();
                file.InvoiceIdPK = item.InvoiceIdPK;
                file.FilePath = filePath;

                fileList.Add(file);
            }
            InvoicingMView.ActiveViewIndex = 1;
            ProcessPrintedFiles(fileList);

            /*string message = ResourceManager.GetString("messageExportSuccessfully");
            string script1 = "<script type=\"text/javascript\">";
            script1 += " alert(\"" + message + "\")";
            script1 += " </script>";

            if (!ClientScript.IsClientScriptBlockRegistered("redirectUser"))
                ClientScript.RegisterStartupScript(this.GetType(), "redirectUser", script1);*/
        }
    }
Ejemplo n.º 27
0
 public InvoicesController(InvoicesRepository repository, UsersRepository userRepo, ProductsRepository productsRepository)
 {
     _repository         = repository;
     _userRepository     = userRepo;
     _productsRepository = productsRepository;
 }
Ejemplo n.º 28
0
 public static InvoicesRepository GetInvoicesRepository()
 {
     var repository = new InvoicesRepository();
     repository.UnitOfWork = GetUnitOfWork();
     return repository;
 }
Ejemplo n.º 29
0
    private IList<Invoices> GetSearchInvoiceList()
    {
        InvoicesRepository repo = new InvoicesRepository();
        IList<Invoices> list = new List<Invoices>();
        if (!string.IsNullOrEmpty(Request.QueryString["type"]) && Request.QueryString["type"] == "search")
        {
            InvoicesSearchCriteria criteria = GetSearchCriteria();
            list = repo.SearchInvoicesWithoutPage(criteria);
        }
        else if (!string.IsNullOrEmpty(Request.QueryString["type"]) && Request.QueryString["type"] == "future")
        {
            list = repo.GetFutureInvoices(int.Parse(WebConfig.FirstNumberFutureInvoice));

        }
        else if (!string.IsNullOrEmpty(Request.QueryString["CompanyId"]))
        {
            int companyID = int.Parse(Request.QueryString["CompanyId"]);
            list = repo.GetUnpaidInvoicesOfCompany(companyID, false);
        }
        return list;
    }
Ejemplo n.º 30
0
 public static InvoicesRepository GetInvoicesRepository(IUnitOfWork unitOfWork)
 {
     var repository = new InvoicesRepository();
     repository.UnitOfWork = unitOfWork;
     return repository;
 }
Ejemplo n.º 31
0
 public InvoicesController(InvoicesRepository repo)
 {
     _repo = repo;
 }
Ejemplo n.º 32
0
    protected void OnMyAjaxManagerAjaxRequest(object sender, AjaxRequestEventArgs e)
    {
        if (e.Argument.IndexOf("RebindInvoiceDetailGrid") != -1)
        {
            InvoiceAjaxManager.AjaxSettings.AddAjaxSetting(InvoiceAjaxManager, gridInvoiceDetails);
            //InvoiceAjaxManager.AjaxSettings.AddAjaxSetting(InvoiceAjaxManager, btnPrintSelection);
            string[] args = e.Argument.Split('/');
            if (args.Length == 3)
            {
                try
                {
                    //string userID = args[1];
                    int rowIndex = Int32.Parse(args[2]);
                    gridInvoice.MasterTableView.ClearSelectedItems();
                    gridInvoice.MasterTableView.Items[rowIndex - 1].Selected = true;
                }
                catch (System.Exception ex) { throw ex; }
                gridInvoiceDetails.Rebind();
                //btnPrintSelection.Enabled = true;
            }
        }
        else if (e.Argument.IndexOf("InvoiceGridMultiSelected") != -1)
        {
            //InvoiceAjaxManager.AjaxSettings.AddAjaxSetting(InvoiceAjaxManager, btnPrintSelection);
            //btnPrintSelection.Enabled = true;

            bool isSameReceiptionEmail = true;
            string email = "";
            string[] args = e.Argument.Split('/');
            if (args.Length == 2)
            {
                List<string> invoices = new List<string>(args[1].TrimEnd(';').Split(';'));
                foreach (string invoiceId in invoices)
                {
                    if (!string.IsNullOrEmpty(invoiceId))
                    {
                        string[] key = invoiceId.Split('-');
                        int idFactNumber = int.Parse(key[0]);
                        string type = key[1];
                        int idYear = int.Parse(key[2]);
                        Invoices invoice = new InvoicesRepository().GetInvoiceByID(idFactNumber, type, idYear);
                        if (string.IsNullOrEmpty(email))
                        {
                            email = GetEmailOfCompany(invoice.CompanyId.Value);
                        }
                        else
                            if (email.CompareTo(GetEmailOfCompany(invoice.CompanyId.Value)) != 0)
                            {
                                isSameReceiptionEmail = false;
                                break;
                            }
                        //InvoiceAjaxManager.ResponseScripts.Add(string.Format("alert('{0}: {1}')", invoice.InvoiceIdPK, GetEmailOfCompany(invoice.CompanyId.Value)));
                    }
                }
            }
            if (isSameReceiptionEmail)
            {
                InvoiceAjaxManager.ResponseScripts.Add("processInvoiceToolBar(\"InvoiceGridSelectedSameReceiptionEmail\")");
            }
            else
                InvoiceAjaxManager.ResponseScripts.Add("processInvoiceToolBar(\"InvoiceGridMultiSelected\")");

        }
        else if (e.Argument.IndexOf("RebindInvoiceGrid") != -1)
        {
            InvoiceAjaxManager.AjaxSettings.AddAjaxSetting(InvoiceAjaxManager, gridInvoice);
            InvoiceAjaxManager.AjaxSettings.AddAjaxSetting(InvoiceAjaxManager, gridInvoiceDetails);
            gridInvoice.Rebind();
            gridInvoiceDetails.Rebind();
        }
        else
        {
            switch (e.Argument)
            {
                case "OpenSelectedInvoice":
                    Response.Redirect(string.Format("~/InvoiceProfile.aspx?InvoiceIdPK={0}&mode=edit&backurl=visible", GetSelectedInvoiceIdPK()), true);
                    break;
                case "DeleteSelectedInvoice":
                    InvoiceAjaxManager.AjaxSettings.AddAjaxSetting(InvoiceAjaxManager, gridInvoice);
                    InvoiceAjaxManager.AjaxSettings.AddAjaxSetting(InvoiceAjaxManager, gridInvoiceDetails);
                    foreach (GridDataItem selectedItem in gridInvoice.SelectedItems)
                    {
                        TableCell invoiceIDCell = selectedItem["InvoiceIdPK"];
                        string invoiceID = selectedItem["InvoiceIdPK"].Text;
                        if (!string.IsNullOrEmpty(invoiceID))
                        {
                            string[] key = invoiceID.Split('-');
                            int idFactNumber = int.Parse(key[0]);
                            string type = key[1];
                            int idYear = int.Parse(key[2]);
                            //Delete Invoice's payments first.
                            InvoicePaymentsRepository payRepo = new InvoicePaymentsRepository();
                            payRepo.DeleteInvoicePaymentsOfInvoice(idFactNumber, type, idYear);

                            //Delete invoice's details
                            InvoiceDetailsRepository detailRepo = new InvoiceDetailsRepository();
                            detailRepo.DeleteInvoiceDetails(idFactNumber, type, idYear, null);

                            //Delete Invoice
                            InvoicesRepository invoiceRepo = new InvoicesRepository();
                            invoiceRepo.DeleteInvoice(idFactNumber, type, idYear);
                        }
                    }
                    BindGridData(null);
                    gridInvoice.DataBind();
                    break;
                case "PrintInvoice":

                    List<InvoicingFile> fileList = new List<InvoicingFile>();
                    GridItemCollection col = gridInvoice.SelectedItems;
                    foreach (GridDataItem item in col)
                    {
                        TableCell cell = item["InvoiceIdPK"];
                        if (!string.IsNullOrEmpty(cell.Text))
                        {
                            string[] key = cell.Text.Split('-');
                            int idFactNumber = int.Parse(key[0]);
                            string type = key[1];
                            int idYear = int.Parse(key[2]);
                            Invoices invoice = new InvoicesRepository().GetInvoiceByID(idFactNumber, type, idYear);
                            string fileName = Common.ExportInvoices(invoice, WebConfig.AddressFillInInvoice,
                                WebConfig.AbsoluteExportDirectory);

                            InvoicingFile file = new InvoicingFile();
                            file.InvoiceIdPK = invoice.InvoiceIdPK;
                            file.FilePath = fileName;
                            fileList.Add(file);
                        }
                    }
                    InvoicingMView.ActiveViewIndex = 1;
                    ProcessPrintedFiles(fileList);

                    break;
                case "EmailInvoice":
                    string selectedInvoiceIDs = "";
                    foreach (GridDataItem selectedItem in gridInvoice.SelectedItems)
                    {
                        TableCell invoiceIDCell = selectedItem["InvoiceIdPK"];
                        string invoiceID = selectedItem["InvoiceIdPK"].Text;
                        if (!string.IsNullOrEmpty(invoiceID))
                        {
                            selectedInvoiceIDs += invoiceID + ";";
                        }
                    }
                    selectedInvoiceIDs = selectedInvoiceIDs.TrimEnd(';');
                    string url = "SendEmail.aspx?type=invoice&ids=" + selectedInvoiceIDs;
                    InvoiceAjaxManager.ResponseScripts.Add(string.Format("OnSendInvoiceByEmail('{0}')", url));

                    break;
                case "CopyInvoice":
                    Response.Redirect(string.Format("~/InvoiceProfile.aspx?type=copy&from={0}&mode=edit", GetSelectedInvoiceIdPK()));
                    break;
            }
        }
    }
Ejemplo n.º 33
0
    private void BindInvoiceData(string InvoiceIdPK)
    {
        string[] key = InvoiceIdPK.Split('-');
        int idFactNumber = int.Parse(key[0]);
        string type = key[1];
        int idYear = int.Parse(key[2]);

        //Get invoice
        Invoices invoice = new InvoicesRepository().GetInvoiceByID(idFactNumber, type, idYear);
        SessionManager.CurrentInvoice = invoice;
        if (invoice.IdTypeInvoice == "I")
            radInvoice.Checked = true;
        else
            radCreditNote.Checked = true;
        txtCustomerName.Text = invoice.CompanyName;
        if (invoice.CompanyId.HasValue)
            txtIdCustomer.Text = invoice.CompanyId.Value.ToString();
        txtInvoiceNumber.Text = invoice.IdFactNumber.ToString();
        chkFactoring.Checked = invoice.Factoring.HasValue ? invoice.Factoring.Value : false;
        datInvoiceDate.SelectedDate = invoice.Date;
        txtRemark.Text = invoice.Remark;
        txtInternalRemark.Text = invoice.Remark_Internal;
        txtTotalHTVA.Value = invoice.TotalHtvaEuro;
        txtTotalVAT.Value = invoice.AmountVatEuro;
        txtTotal.Value = invoice.TotalAmountIncludeVatEuro;

        ddlCustomer.Items.Add(new RadComboBoxItem(invoice.CompanyName, invoice.CompanyId.ToString()));
        ddlCustomer.SelectedIndex = 0;
        //Payment : Choose option 1 : not use these fields any more.
        //datPaymentDate.SelectedDate = invoice.DateOfPayement;
        //if (invoice.Payement.HasValue)
        //    chkPayment.Checked = invoice.Payement.Value;
        //else
        //    chkPayment.Checked = false;
        InvoicePaymentsRepository paymentRepo = new InvoicePaymentsRepository();
        IList<InvoicePayments> paymentList = paymentRepo.GetInvoicePaymentsOfInvoice(idFactNumber, type, idYear);
        gridInvoicePayments.DataSource = paymentList;
        double payment = paymentRepo.GetSumPaymentOfInvoice(idFactNumber, type, idYear);
        txtPayment.Value = payment;
        if (invoice.TotalAmountIncludeVatEuro.HasValue && paymentList.Count > 0
            && invoice.TotalAmountIncludeVatEuro.Value <= payment)
        {
            chkPayment.Checked = true;
            DateTime? paymentDate =
                new InvoicePaymentsRepository().GetLatestDatePaymentOfInvoice(idFactNumber, type, idYear);
            if (paymentDate.HasValue)
                txtPaymentDate.Text = paymentDate.Value.ToString("dd/MM/yyyy");
        }

        //Get invoice address
        if (invoice.RefCustomerNumber.HasValue)
        {
            CompanyAddress compAdr = new CompanyAddressRepository().FindOne(
                new CompanyAddress(invoice.RefCustomerNumber.Value));
            hiddenCompanyAddressId.Value = compAdr.AddressID.ToString();
            txtAddressName.Text = compAdr.Name;
            txtAddress.Text = compAdr.Address;
            txtCity.Text = compAdr.City;
            txtZipCode.Text = compAdr.ZipCode;
            txtVatNumber.Text = compAdr.VatNumber;
        }
        //Get invoice details
        IList<InvoiceDetails> detailList =
            new InvoiceDetailsRepository().GetInvoiceDetailsOfInvoice(
                        idFactNumber, type, idYear, null);
        gridInvoiceDetails.DataSource = detailList;
        //lnkAddInvoiceDetail.Visible = true;
        //lnkAddNewPayment.Visible = true;
        lnkAddInvoiceDetail.OnClientClick = "return OnAddNewInvoiceDetailClientClicked('"
            + SessionManager.CurrentInvoice.InvoiceIdPK + "')";
        lnkAddNewPayment.OnClientClick = "return OnAddNewInvoicePaymentClientClicked('"
            + SessionManager.CurrentInvoice.InvoiceIdPK + "')";

        //For future invoice
        if (!string.IsNullOrEmpty(Request.QueryString["type"]) && Request.QueryString["type"] == "future")
        {
            datInvoiceDate.SelectedDate = DateTime.Today;
        }
    }
Ejemplo n.º 34
0
    private void BindGridData(GridSortCommandEventArgs sortEventArgs)
    {
        if (!string.IsNullOrEmpty(Request.QueryString["type"]) && Request.QueryString["type"] == "unpaid")
        {
            int pageSize = 20;
            int pageNumber = gridInvoiceUnpaid.CurrentPageIndex + 1;
            string sortExpress = string.Empty;
            string sortExpressInvert = string.Empty;
            foreach (GridSortExpression item in gridInvoiceUnpaid.MasterTableView.SortExpressions)
            {
                GridSortOrder newSortOrder = item.SortOrder;
                if (sortEventArgs != null && item.FieldName == sortEventArgs.SortExpression)
                {
                    newSortOrder = sortEventArgs.NewSortOrder;
                }

                if (!string.IsNullOrEmpty(sortExpress) && newSortOrder != GridSortOrder.None)
                {
                    sortExpress += ", ";
                    sortExpressInvert += ", ";
                }
                if (newSortOrder == GridSortOrder.Ascending)
                {
                    sortExpress += item.FieldName + " ASC";
                    sortExpressInvert += item.FieldName + " DESC";
                }
                else if (newSortOrder == GridSortOrder.Descending)
                {
                    sortExpress += item.FieldName + " DESC";
                    sortExpressInvert += item.FieldName + " ASC";
                }
            }

            if (sortEventArgs != null && !sortExpress.Contains(sortEventArgs.SortExpression))
            {
                if (!string.IsNullOrEmpty(sortExpress) && sortEventArgs.NewSortOrder != GridSortOrder.None)
                {
                    sortExpress += ", ";
                    sortExpressInvert += ", ";
                }
                if (sortEventArgs.NewSortOrder == GridSortOrder.Ascending)
                {
                    sortExpress += sortEventArgs.SortExpression + " ASC";
                    sortExpressInvert += sortEventArgs.SortExpression + " DESC";
                }
                else if (sortEventArgs.NewSortOrder == GridSortOrder.Descending)
                {
                    sortExpress += sortEventArgs.SortExpression + " DESC";
                    sortExpressInvert += sortEventArgs.SortExpression + " ASC";
                }
            }

            if (string.IsNullOrEmpty(sortExpress))
            {
                sortExpress = "CompanyName ASC";
                sortExpressInvert = "CompanyName DESC";
            }

            InvoicesRepository repo = new InvoicesRepository();
            gridInvoiceUnpaid.VirtualItemCount = repo.CountUnpaidInvoices(pageSize, pageNumber, sortExpress, sortExpressInvert);
            IList<InvoiceUnpaid> list = repo.GetUnpaidInvoices(pageSize, pageNumber, sortExpress, sortExpressInvert);
            gridInvoiceUnpaid.DataSource = list;
        }
        else
        {
            gridInvoiceUnpaid.DataSource = new List<Invoices>();
        }
    }
 public InvoicesController()
 {
     db = new InvoicesRepository();
 }
Ejemplo n.º 36
0
    /// <summary>
    /// copy information and invoice detail from another invoice
    /// </summary>
    /// <param name="InvoiceIdPK"></param>
    private void CopyInvoiceData(string sourceInvoiceId)
    {
        string[] key = sourceInvoiceId.Split('-');
        int idFactNumber = int.Parse(key[0]);
        string type = key[1];
        int idYear = int.Parse(key[2]);

        //Get invoice
        Invoices invoice = new InvoicesRepository().GetInvoiceByID(idFactNumber, type, idYear);
        SessionManager.CurrentInvoice = invoice;
        if (invoice.IdTypeInvoice == "I")
            radInvoice.Checked = true;
        else
            radCreditNote.Checked = true;
        txtCustomerName.Text = invoice.CompanyName;
        if (invoice.CompanyId.HasValue)
            txtIdCustomer.Text = invoice.CompanyId.Value.ToString();
        txtInvoiceNumber.Text = "";
        datInvoiceDate.SelectedDate = DateTime.Now;
        txtRemark.Text = invoice.Remark;
        txtTotalHTVA.Value = invoice.TotalHtvaEuro;
        txtTotalVAT.Value = invoice.AmountVatEuro;
        txtTotal.Value = invoice.TotalAmountIncludeVatEuro;

        gridInvoicePayments.DataSource = new List<InvoicePayments>();
        gridInvoicePayments.DataBind();
        //Get invoice address
        if (invoice.RefCustomerNumber.HasValue)
        {
            CompanyAddress compAdr = new CompanyAddressRepository().FindOne(
                new CompanyAddress(invoice.RefCustomerNumber.Value));
            hiddenCompanyAddressId.Value = compAdr.AddressID.ToString();
            txtAddressName.Text = compAdr.Name;
            txtAddress.Text = compAdr.Address;
            txtCity.Text = compAdr.City;
            txtZipCode.Text = compAdr.ZipCode;
            txtVatNumber.Text = compAdr.VatNumber;
        }
        //Get invoice details
        IList<InvoiceDetails> detailList = new InvoiceDetailsRepository().GetInvoiceDetailsOfInvoice(idFactNumber, type, idYear, null);
        gridInvoiceDetails.DataSource = detailList;
        lnkAddInvoiceDetail.Visible = false;
        lnkAddNewPayment.Visible = false;
        gridInvoiceDetails.Columns.FindByUniqueName("TemplateEditInvoiceDetailColumn").Display = false;
        gridInvoiceDetails.Columns.FindByUniqueName("TemplateDeleteInvoiceDetailColumn").Display = false;
    }
Ejemplo n.º 37
0
 public InvoiceService(ClientsRepository clients, InvoicesRepository invoices)
 {
     this.clients  = clients;
     this.invoices = invoices;
 }
Ejemplo n.º 38
0
    private void BindData()
    {
        if (Request.QueryString["type"] == "invoice")
        {
            if (!string.IsNullOrEmpty(Request.QueryString["ids"]))
            {
                string companyEmail = "";
                List<string> exportFiles = new List<string>();
                string[] invoiceIds = Request.QueryString["ids"].Split(';');

                for (int i = 0; i < invoiceIds.Length; i++)
                {
                    string[] key = invoiceIds[i].Split('-');
                    int idFactNumber = int.Parse(key[0]);
                    string type = key[1];
                    int idYear = int.Parse(key[2]);
                    Invoices invoice = new InvoicesRepository().GetInvoiceByID(idFactNumber, type, idYear);
                    if(string.IsNullOrEmpty(companyEmail))
                    {
                        companyEmail = GetEmailOfCompany(invoice.CompanyId.Value);
                        txtTo.Text = companyEmail;
                    }
                    string fileName = Common.ExportInvoices(invoice, WebConfig.AddressFillInInvoice,
                        WebConfig.AbsoluteExportDirectory);

                    exportFiles.Add(fileName);
                }
                rptAttachInvoices.DataSource = exportFiles;
                rptAttachInvoices.DataBind();
            }
        }
    }