public static ChequeStatu CreateChequeStatus(Cheque cheque, int chequeStatusTypeId, DateTime transitionDateTime, string remarks, bool isActive)
        {
            ChequeStatu newCheckStatus = new ChequeStatu();

            newCheckStatus.Cheque = cheque;
            newCheckStatus.CheckStatusTypeId = chequeStatusTypeId;
            newCheckStatus.TransitionDateTime = transitionDateTime;
            newCheckStatus.Remarks = remarks;
            newCheckStatus.IsActive = isActive;

            return newCheckStatus;
        }
        public static ChequeStatu ChangeStatus(Cheque cheque, ChequeStatusType chequeStatusTo, string remarks)
        {
            var statusFrom = GetActive(cheque);
            if (statusFrom != null && statusFrom.IsActive == true)
            {
                statusFrom.IsActive = false;
            }

            ChequeStatu status = new ChequeStatu();
            if (statusFrom == null || statusFrom.IsActive == false)
                status = CreateChequeStatus(cheque, chequeStatusTo.Id, DateTime.Now, remarks, true);

            Context.ChequeStatus.AddObject(status);
            return status;
        }
        protected void btnSave_onDirectEventClick(object sender, DirectEventArgs e)
        {
            int receiptId = int.Parse(hdnReceiptID.Text);
            int paymentId = Payment.GetReceiptPayment(receiptId).Id;
            var cancelledReceiptStatusTypeId = ReceiptStatusType.CancelledReceiptStatusType.Id;
            if(!EndCurrentReceiptStatus(receiptId, cancelledReceiptStatusTypeId)) return;

            ReceiptStatu newReceiptStatus = new ReceiptStatu();
            DateTime now = DateTime.Now;

            newReceiptStatus.TransitionDateTime = now;
            newReceiptStatus.IsActive = true;
            newReceiptStatus.ReceiptStatusTypeId = cancelledReceiptStatusTypeId;
            newReceiptStatus.ReceiptId = receiptId;
            newReceiptStatus.Remarks = txtComment.Text;

            var check = ObjectContext.Cheques.SingleOrDefault(entity => entity.PaymentId == paymentId);
            if (check != null)
            {
                var checkStatus = check.ChequeStatus.SingleOrDefault(entity => entity.IsActive == true && entity.CheckId == check.Id);
                checkStatus.IsActive = false;

                ChequeStatu newCheckStatus = new ChequeStatu();

                newCheckStatus.CheckId = check.Id;
                newCheckStatus.ChequeStatusType = ChequeStatusType.CancelledType;
                newCheckStatus.TransitionDateTime = now;
                newCheckStatus.Remarks = txtComment.Text;
                newCheckStatus.IsActive = true;

                ObjectContext.ChequeStatus.AddObject(newCheckStatus);
            }

            ObjectContext.ReceiptStatus.AddObject(newReceiptStatus);
            ObjectContext.SaveChanges();
        }
        public static void SaveToDisbursementCheques(DateTime transactdate, DateTime entrydate, Payment parent, List<AddChequesModel> Cheques, int processedTo, int processedby, SpecificPaymentType specifictype, DisbursementType distype, string DisbursedToName, int CurrencyId)
        {
            foreach (var cheque in Cheques)
            {
                PaymentMethodType type = PaymentMethodType.PayCheckType;
                if (cheque.CheckType == PaymentMethodType.PersonalCheckType.Name)
                    type = PaymentMethodType.PersonalCheckType;
                Payment chequepayment = new Payment();

                chequepayment.PaymentMethodType = type;
                chequepayment.Payment2 = parent;
                chequepayment.ProcessedToPartyRoleId = processedTo;
                chequepayment.ProcessedByPartyRoleId = processedby;
                chequepayment.PaymentReferenceNumber = cheque.CheckNumber;
                chequepayment.TransactionDate = transactdate;
                chequepayment.EntryDate = entrydate;
                chequepayment.TotalAmount = cheque.Amount;
                chequepayment.PaymentType = PaymentType.Disbursement;
                chequepayment.SpecificPaymentType = specifictype;
                ObjectContext.Payments.AddObject(chequepayment);

                Disbursement disbursement = new Disbursement();
                disbursement.Payment = chequepayment;
                disbursement.DisbursementType = distype;
                if (string.IsNullOrEmpty(DisbursedToName) == false)
                    disbursement.DisbursedToName = DisbursedToName;
                ObjectContext.Disbursements.AddObject(disbursement);

                Cheque newCheque = new Cheque();
                newCheque.BankPartyRoleId = cheque.BankPartyRoleId;
                newCheque.Payment = chequepayment;
                newCheque.CheckDate = cheque.CheckDate;
                ObjectContext.Cheques.AddObject(newCheque);

                ChequeStatu newChequeStatus = new ChequeStatu();
                newChequeStatus.Cheque = newCheque;
                newChequeStatus.CheckStatusTypeId = ChequeStatusType.ClearedType.Id;
                newChequeStatus.TransitionDateTime = entrydate;
                newChequeStatus.IsActive = true;
                ObjectContext.ChequeStatus.AddObject(newChequeStatus);

                Currency.CreatePaymentCurrencyAssoc(chequepayment, CurrencyId);

            }
        }
        protected void CreateCheckStatus(Cheque check, DateTime now)
        {
            ChequeStatu newCheckStatus = new ChequeStatu();

            newCheckStatus.CheckId = check.Id;
            newCheckStatus.CheckStatusTypeId = int.Parse(cmbCheckStatus.SelectedItem.Value);
            newCheckStatus.TransitionDateTime = now;
            newCheckStatus.Remarks = txtCheckRemarks.Text;
            newCheckStatus.IsActive = true;

            ObjectContext.ChequeStatus.AddObject(newCheckStatus);
        }
        protected void CreateCheckStatus(Cheque check, DateTime now, ChequeStatusType CheckStatusType)
        {
            ChequeStatu newCheckStatus = new ChequeStatu();

            newCheckStatus.CheckId = check.Id;
            newCheckStatus.ChequeStatusType = CheckStatusType;
            newCheckStatus.TransitionDateTime = now;
            newCheckStatus.Remarks = txtCheckRemarks.Text;
            newCheckStatus.IsActive = true;

            ObjectContext.ChequeStatus.AddObject(newCheckStatus);
        }