public Pure(Payment P)
 {
     State = States.Edit;
     Pa = P;
     InitializeComponent();
     Btn_Register.Enabled = false;
 }
        public AddEditPaymentModal(Model.Payment paymentToUpdate, PaymentType paymentType, PaymentControl paymentControl, Model.Bank bank)
		{
			this.InitializeComponent();

            _bank = bank;
            _paymentControl = paymentControl;
            _paymentType = paymentType;
            _paymentToUpdate = paymentToUpdate;
            _isUpdatePayment = _paymentToUpdate != null;

            FillBanks();
            AdjustWindowForPaymentType();

            if (_isUpdatePayment)
            {
                PrepareWindowForUpdates();
            }

            this.Title += " (" + paymentType.ToString() + ")";
        }
        private void btnAddPayment_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            string amountText = txtAmount.Text.Trim();
            Model.Bank bank = (cbBanks.SelectedItem as Controllers.ComboBoxItem).Value as Model.Bank;
            string voucherCheckNumber = txtVoucherCheckNumber.Text.Trim();
            decimal amount;

            if (AreValidFields(amountText, bank, voucherCheckNumber, out amount) == false)
            {
                return;
            }

            if (_isUpdatePayment)
            {
                _paymentToUpdate.PaymentDate = DateTime.Now;
                _paymentToUpdate.Amount = amount;
                _paymentToUpdate.Type = _paymentType.ToString();
                _paymentToUpdate.Observation = txtObservations.Text.Trim();

                if (_paymentType != PaymentType.Efectivo)
                {
                    _paymentToUpdate.BankId = bank.BankId;
                    _paymentToUpdate.VoucherCheckNumber = voucherCheckNumber;
                }

                _paymentControl.Payment = _paymentToUpdate;
            }
            else
            {
                Model.Payment paymentToAdd = new Model.Payment()
                {
                    PaymentDate = DateTime.Now,
                    Amount = amount,
                    Type = _paymentType.ToString(),
                    Observation = txtObservations.Text.Trim()
                };

                if (_paymentType != PaymentType.Efectivo)
                {
                    paymentToAdd.BankId = bank.BankId;
                    paymentToAdd.VoucherCheckNumber = voucherCheckNumber;
                }

                _paymentControl.Payment = paymentToAdd;
            }

            _paymentControl.Width = Double.NaN;
            _paymentControl.Bank = bank;
            _paymentControl.UpdateData();

            this.Close();
        }
        private void UpdatePositiveBalances()
        {
            RemoveAllPositiveBalances();

            if (_selectedPatient != null)
            {
                List<Model.PositiveBalance> activePositiveBalances = _selectedPatient.PositiveBalances
                                                                        .Where(pb => pb.AppliedDate == null)
                                                                        .ToList();
                foreach (var item in activePositiveBalances)
                {
                    Model.Payment paymentToAdd = new Model.Payment()
                    {
                        PaymentDate = DateTime.Now,
                        Amount = item.Amount,
                        Type = PaymentType.Efectivo.ToString(),
                        Observation = "Saldo a favor"
                    };

                    PaymentControl paymentControl = new PaymentControl(paymentToAdd, item)
                    {
                        Width = Double.NaN
                    };

                    spPayments.Children.Add(paymentControl);
                }
            }
        }