예제 #1
0
        public ActionResult Index()
        {
            var adjustmentReasons = TransactionService.GetAllAdjustmentReasons();
            var transactionTypes  = TransactionTypeService.GetTransactionTypes();
            var cancellation      = CaseService.GetAllCancellation();

            var model = new IndexViewModel();

            return(View(model.Rebuild(model, adjustmentReasons, transactionTypes, cancellation)));
        }
예제 #2
0
        public JsonResult CertificationEditor(CertificationViewModel model)
        {
            var currentCase = CaseService.FindCaseDetailByNumber(model.CaseNumber, model.CaseKey);

            var transactionTemp   = new List <Transaction>();
            var concept           = PaymentService.GetAllConcepts();
            var status            = PaymentService.GetAllPaymentStatuses().Where(x => x.Status1 == "Certificado").Select(s => s.StatusId).FirstOrDefault();;
            var transactionTypeId = TransactionTypeService.GetTransactionTypes().Where(x => x.TransactionType1 == "Descuento").Select(s => s.TransactionTypeId).FirstOrDefault();

            foreach (var certification in model.Certification)
            {
                var payment   = new Payment();
                var conceptId = concept.Where(x => x.Concept1 == certification.Concept).Select(s => s.ConceptId).FirstOrDefault();
                if (certification.PaymentId != -1)
                {
                    payment                  = PaymentService.FindPaymentById(certification.PaymentId);
                    payment.ModifiedBy       = WebHelper.GetUserName();
                    payment.ModifiedDateTime = DateTime.Now;
                }
                else //Assigns necessary information when the payment doesn't exist in the table.
                {
                    payment.PaymentId       = certification.PaymentId;
                    payment.CaseId          = currentCase.CaseId;
                    payment.CaseDetailId    = currentCase.CaseDetailId;
                    payment.CaseNumber      = model.CaseNumber;
                    payment.CaseKey         = model.CaseKey == null ? "00" : model.CaseKey;
                    payment.TransactionNum  = certification.InvoiceNumber;
                    payment.Amount          = certification.Status == "Descuento" ? Math.Abs(Convert.ToDecimal(certification.Amount)) * -1 : Convert.ToDecimal(certification.Amount);
                    payment.FromDate        = Convert.ToDateTime(certification.FromDate);
                    payment.ToDate          = Convert.ToDateTime(certification.ToDate);
                    payment.ConceptId       = conceptId;
                    payment.StatusId        = status;
                    payment.CreatedBy       = WebHelper.GetUserName();
                    payment.CreatedDateTime = DateTime.Now;
                }

                payment.StatusId = status;
                payment.Comments = model.Comment;

                bool IsDiscount = certification.Status == "Descuento" ? true : false;

                if (IsDiscount && certification.PaymentId == -1)
                {
                    int?   referenceCaseId     = null;
                    string referenceCaseNumber = null;

                    if (model.CaseNumber != certification.CaseNumber)
                    {
                        var caseReference = CaseService.FindCaseByNumber(certification.CaseNumber);
                        referenceCaseId     = caseReference.CaseId;
                        referenceCaseNumber = caseReference.CaseNumber;
                    }

                    Transaction transactionLine = null;
                    transactionLine = TransactionService.GetTransaction(currentCase.CaseDetailId, certification.InvoiceNumber, conceptId, transactionTypeId);

                    if (transactionLine == null)
                    {
                        transactionLine = new Transaction();
                        transactionLine.CaseDetailId         = currentCase.CaseDetailId;
                        transactionLine.TransactionTypeId    = transactionTypeId;
                        transactionLine.TransactionAmount    = payment.Amount;
                        transactionLine.CaseId_Reference     = referenceCaseId;
                        transactionLine.CaseNumber_Reference = referenceCaseNumber;
                        transactionLine.ConceptId            = conceptId;
                        transactionLine.InvoiceNumber        = certification.InvoiceNumber.IsNullOrEmpty() ? null : certification.InvoiceNumber;
                        transactionLine.Comment         = model.Comment;
                        transactionLine.CreatedBy       = WebHelper.GetUserName();
                        transactionLine.CreatedDateTime = DateTime.Now;
                        TransactionService.CreateTransaction(transactionLine);
                    }
                    else
                    {
                        transactionLine.TransactionAmount += payment.Amount;
                        transactionLine.Comment            = model.Comment;
                        transactionLine.ModifiedBy         = WebHelper.GetUserName();
                        transactionLine.ModifiedDateTime   = DateTime.Now;
                        TransactionService.ModifyTransaction(transactionLine);
                    }
                    payment.TransactionId = transactionLine.TransactionId;
                }

                if (payment.PaymentId == -1)
                {
                    PaymentService.CreatePayment(payment);
                }
                else
                {
                    PaymentService.ModifyPayment(payment);
                }
            }

            return(Json(new { success = true }, JsonRequestBehavior.AllowGet));
        }