/// <summary>
        ///     Opens the delete dialog prompting the user to confirm deletion or cancel
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Btn_delete_Click(object sender, RoutedEventArgs e)
        {
            int.TryParse(txtBox_creditNoteNumber.Text, out var creditNoteID);
            if (txtBox_creditNoteNumber.IsReadOnly)
            {
                var msgtext = "You are about to delete the credit note with ID = " + creditNoteID + ". Are you sure?";
                var txt     = "Delete Credit Note";
                var button  = MessageBoxButton.YesNo;
                var result  = MessageBox.Show(msgtext, txt, button);

                switch (result)
                {
                case MessageBoxResult.Yes:
                    CreditNoteViewModel.deleteCreditNote(creditNoteID);
                    Btn_clearView_Click(null, null);
                    MessageBox.Show("Deleted Credit Note with ID = " + creditNoteID);
                    break;

                case MessageBoxResult.No:
                    break;
                }
            }
            else
            {
                MessageBox.Show("No credit note is loaded");
            }
        }
        /// <summary>
        ///     Loads the credit note information on the page
        /// </summary>
        /// <param name="creditNoteID"></param>
        public void loadCreditNote(int creditNoteID)
        {
            creditNote = CreditNoteViewModel.getCreditNote(creditNoteID);
            if (creditNote != null)
            {
                // Customer details
                textBox_Customer.Text        = creditNote.customer.CustomerName;
                textBox_Contact_Details.Text = creditNote.customer.PhoneNumber.ToString();
                textBox_Email_Address.Text   = creditNote.customer.Email;
                textBox_Address.Text         = creditNote.customer.Address + ", " + creditNote.customer.City + ", " +
                                               creditNote.customer.Country;

                // Credit Note details
                txtBox_creditNoteNumber.Text       = creditNote.idCreditNote.ToString();
                txtBox_creditNoteNumber.IsReadOnly = true;
                txtBox_createdDate.Text            = creditNote.createdDate.ToString("d");
                txtBox_issuedBy.Text       = creditNote.issuedBy;
                NetTotal_TextBlock.Text    = creditNote.cost.ToString("C");
                Vat_TextBlock.Text         = creditNote.VAT.ToString("C");
                TotalAmount_TextBlock.Text = creditNote.totalCost.ToString("C");

                // Credit Note products
                creditNoteProductsGrid.ItemsSource = creditNote.products;
            }
            else
            {
                MessageBox.Show("Credit Note with ID = " + creditNoteID + ", does not exist");
            }
        }
        /// <summary>
        ///     Loads the statement items on the grid based on the filters given
        /// </summary>
        /// <returns></returns>
        private bool loadStatementItems()
        {
            var customerID = ((Customer)comboBox_customer.SelectedItem).idCustomer;
            var from       = fromDate.SelectedDate.Value.Date;

            from += new TimeSpan(0, 0, 0); // start from 00:00:00 of from date
            var to = toDate.SelectedDate.Value.Date;

            to += new TimeSpan(23, 59, 59); // end on 23:59:59 of to date

            var statement = new List <StatementItem>();

            statement.AddRange(InvoiceViewModel.getInvoicesForStatement(customerID, from, to));
            statement.AddRange(CreditNoteViewModel.getCreditNotesForStatement(customerID, from, to));
            statement.AddRange(ReceiptViewModel.getReceiptsForStatement(customerID, from, to));

            if (statement.Count > 0)
            {
                statementDataGrid.ItemsSource = statement;
                var firstCol = statementDataGrid.Columns.First();
                firstCol.SortDirection = ListSortDirection.Ascending;
                statementDataGrid.Items.SortDescriptions.Add(new SortDescription(firstCol.SortMemberPath,
                                                                                 ListSortDirection.Ascending));
                return(true);
            }

            return(false);
        }
        /// <summary>
        ///     Loads the credit note information on the page
        /// </summary>
        /// <param name="creditNoteId"></param>
        public void loadCreditNote(int creditNoteId)
        {
            oldCreditNote = CreditNoteViewModel.getCreditNote(creditNoteId);
            if (oldCreditNote != null)
            {
                // Customer details
                textBox_Customer.Text        = oldCreditNote.customer.CustomerName;
                textBox_Contact_Details.Text = oldCreditNote.customer.PhoneNumber.ToString();
                textBox_Email_Address.Text   = oldCreditNote.customer.Email;
                textBox_Address.Text         = oldCreditNote.customer.Address + ", " + oldCreditNote.customer.City + ", " +
                                               oldCreditNote.customer.Country;

                // Invoice details
                textBox_invoiceNumber.Text = oldCreditNote.idCreditNote.ToString();
                txtbox_invoiceDate.Text    = oldCreditNote.createdDate.ToString("d");
                ;
                issuedBy.Text              = oldCreditNote.issuedBy;
                NetTotal_TextBlock.Text    = oldCreditNote.cost.ToString("C");
                Vat_TextBlock.Text         = oldCreditNote.VAT.ToString("C");
                TotalAmount_TextBlock.Text = oldCreditNote.totalCost.ToString("C");

                foreach (var p in oldCreditNote.products)
                {
                    ProductDataGrid.Items.Add(p);
                }

                comboBox_invoiceID.ItemsSource =
                    InvoiceViewModel.getCustomerInvoices(oldCreditNote.customer.idCustomer);
            }
            else
            {
                MessageBox.Show("Credit Note id doesnt't exist");
            }
        }
        /// <summary>
        ///     Loads the customers in the combobox as well as the new credit note ID
        /// </summary>
        public void load()
        {
            if (refreshDataDB)
            {
                customerView = new CustomerViewModel();
                comboBox_customer.ItemsSource = customerView.customersList;
                textBox_invoiceNumber.Text    = (CreditNoteViewModel.returnLatestCreditNoteID() + 1).ToString();
                invoiceDate.SelectedDate      = DateTime.Today; //set curent date
            }

            refreshDataDB = false;
        }
 /// <summary>
 ///     After validating creates the credit note and switches to viewing it
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void Btn_Complete_Click(object sender, RoutedEventArgs e)
 {
     if (checkCustomerForm() && checkDetailsForm() && hasItemsSelected())
     {
         var creditNote = createCreditNoteObject();
         creditNote.createdDate += DateTime.Now.TimeOfDay;
         CreditNoteViewModel.insertCreditNote(creditNote);
         MessageBox.Show("Credit Note with ID " + creditNote.idCreditNote + " was created.");
         creditNoteMain.viewCreditNote(creditNote.idCreditNote);
         Btn_clearAll_Click(null, null);
     }
 }
        public CreditNoteView(CreditNoteViewModel model)
        {
            InitializeComponent();
            this.debitViewModel = model;

            this.DataContext = this.debitViewModel;
            if (debitViewModel.PQDetailsEntity != null)
            {
                this.grdPandS.ItemsSource = this.debitViewModel.PQDetailsEntity;
            }
            CustomGridLines.ItemsSource = DataGridTableCollection.GridLines(8, 50).AsEnumerable();
        }
 /// <summary>
 ///     After validating updates the credit note and switches to viewing it
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void Btn_Complete_Click(object sender, RoutedEventArgs e)
 {
     if (Has_Items_Selected())
     {
         if (int.TryParse(textBox_invoiceNumber.Text, out var creditNoteID))
         {
             CreditNoteViewModel.updateCreditNote(createCreditNoteObject(), oldCreditNote);
             creditNoteMain.viewCreditNote(creditNoteID);
             Btn_clearAll_Click(null, null);
         }
     }
 }
Example #9
0
        public CreditNoteReportViewer()
        {
            InitializeComponent();
            Type type = typeof(CreditNoteViewModel);

            //SalesInvoiceViewModel instance = (SalesInvoiceViewModel)Activator.CreateInstance(type);
            object obj = System.Runtime.Serialization.FormatterServices
                         .GetUninitializedObject(type);

            _viewModelSales = (CreditNoteViewModel)obj;

            this.DataContext = obj;
        }
 /// <summary>
 ///     After validating that the given credit note ID exists loads the credit note
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void Btn_Load_CreditNote(object sender, RoutedEventArgs e)
 {
     int.TryParse(textBox_invoiceNumber.Text, out var creditNoteid);
     if (CreditNoteViewModel.CreditNoteExists(creditNoteid))
     {
         Btn_clearAll_Click(null, null);
         loadCreditNote(creditNoteid);
         creditNote_loaded = true;
     }
     else
     {
         //not a number
         MessageBox.Show("Please insert a valid value for credit note ID.");
     }
 }
Example #11
0
        /// <summary>
        ///     Opens the delete dialog prompting the user to confirm deletion or cancel
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DeleteCreditNote_Click(object sender, RoutedEventArgs e)
        {
            var credID  = ((CreditNote)creditNoteDataGrid.SelectedItem).idCreditNote;
            var msgtext = "You are about to delete the credit note with ID = " + credID + ". Are you sure?";
            var txt     = "Delete Credit Note";
            var button  = MessageBoxButton.YesNo;
            var result  = MessageBox.Show(msgtext, txt, button);

            switch (result)
            {
            case MessageBoxResult.Yes:
                CreditNoteViewModel.deleteCreditNote(credID);
                load();
                break;

            case MessageBoxResult.No:
                break;
            }
        }
        public CreditNoteView(CreditNoteViewModel model)
        {
            InitializeComponent();
            this.debitViewModel = model;

            this.DataContext = this.debitViewModel;
            if (debitViewModel.PQDetailsEntity != null)
            {
                this.grdPandS.ItemsSource = this.debitViewModel.PQDetailsEntity;
            }
            if (debitViewModel.MustCompare == true)
            {
                PART_TextBox.IsReadOnly = false;
                CustomerDebitNoteDatepicker.IsEnabled = true;
            }
            else
            {
                PART_TextBox.IsReadOnly = true;
                CustomerDebitNoteDatepicker.IsEnabled = false;
            }
            CustomGridLines.ItemsSource = DataGridTableCollection.GridLines(8, 50).AsEnumerable();
        }
Example #13
0
 /// <summary>
 ///     Loads all the credit notes on to the grid
 /// </summary>
 public void load()
 {
     credVModel = new CreditNoteViewModel();
     filterList();
 }
Example #14
0
 public CreditNoteReportViewer(CreditNoteViewModel model) : this()
 {
     InitializeComponent();
     this.DataContext = _viewModelSales;
     _viewModelSales  = model;
 }
 public IActionResult CreditNote(CreditNoteViewModel creditNoteViewModel)
 {
     return(View());
 }