public override bool SaveChanges(DB_CommonTransactionType commonTransactionType)
        {
            if (ActiveCollector.ActiveDBItem == null)
            {
                return(false);
            }
            switch (CommonTransactionType)
            {
            case DB_CommonTransactionType.CreateNew:
                return(((Invoice)ActiveCollector.ActiveDBItem).SaveChanges());

            case DB_CommonTransactionType.UpdateExisting:
                InvoiceShare invoiceShare = ((Invoice)ActiveDBItem).InvoiceShare;
                invoiceShare.DBCommonTransactionType = commonTransactionType;
                invoiceShare.InvoiceID = ((Invoice)ActiveDBItem).ID;
                invoiceShare.SaveChanges();
                if (((Invoice)ActiveDBItem).InvoicePayments != null &&
                    ((Invoice)ActiveDBItem).InvoicePayments.Count > 0)
                {
                    List <InvoicePayment> invoicePayments = ((Invoice)ActiveDBItem).InvoicePayments.ToList();
                }

                return(true);
            }

            return(false);
        }
Пример #2
0
        public override bool AfterSave()
        {
            if ((InvoicePayment)ActiveDBItem == null)
            {
                return(false);
            }

            switch (PaymentViewerType)
            {
            case PaymentViewerType.MedicalInvoicePayment:
                Invoice invoice = DBCommon.GetEntity <Invoice>(Convert.ToInt32(((InvoicePayment)ActiveDBItem).InvoiceID));
                if (invoice != null)
                {
                    invoice.IsPaymentsEnough = Convert.ToBoolean(IsPaymentEnough);

                    InvoiceShare invoiceShare = DBCommon.GetEntity <InvoiceShare>(Convert.ToInt32(((InvoicePayment)ActiveDBItem).InvoiceID));
                    invoiceShare.TotalPayment = Convert.ToBoolean(IsRefund)
                                                        ? Convert.ToDouble(invoiceShare.TotalPayment) + Convert.ToDouble(PaymentAmount) * -1
                                                        : Convert.ToDouble(invoiceShare.TotalPayment) + Convert.ToDouble(PaymentAmount);
                    if (Math.Abs(Convert.ToDouble(invoiceShare.TotalPayment) - Convert.ToDouble(invoiceShare.TotalRequestedAmount)) <
                        0.0001)
                    {
                        invoice.IsPaymentsEnough = true;
                    }

                    invoice.DBCommonTransactionType      = DB_CommonTransactionType.UpdateExisting;
                    invoiceShare.DBCommonTransactionType = DB_CommonTransactionType.UpdateExisting;
                    invoice.InvoiceShare = invoiceShare;
                    return(invoice.SaveChanges());
                }
                break;

            case PaymentViewerType.PatientDepositPayment:
                PatientDepositeBalance patientBalance = DBCommon.CreateNewDBEntity <PatientDepositeBalance>();
                patientBalance.Service_CU_ID = Convert.ToInt32(ServiceID);
                patientBalance.Patient_CU_ID = Convert.ToInt32(((Patient_cu)Patient).ID);
                patientBalance.Date          = Convert.ToDateTime(PaymentDate);
                patientBalance.Blance        = Convert.ToDouble(PaymentAmount);
                patientBalance.Factor        = 1;
                patientBalance.IsOnDuty      = true;
                if (UserID != null)
                {
                    patientBalance.InsertedBy = Convert.ToInt32(UserID);
                }
                return(patientBalance.SaveChanges());

                break;
            }

            return(false);
        }