Example #1
0
        public ValidationMsg Save(PrqChemLocalPurcBillPay model, int userId)
        {
            try
            {
                using (var tx = new TransactionScope())
                {
                    using (_context)
                    {
                        var bill = ConvertBillPayment(model, userId);
                        if (bill.PaymentID == 0)
                        {
                            _context.PRQ_ChemLocalPurcBillPayment.Add(bill);
                            _context.SaveChanges();
                            _mode = 1;
                        }
                        else
                        {
                            _context.SaveChanges();
                            _mode = 2;
                        }
                        if (model.References != null)
                        {
                            foreach (var reference in model.References)
                            {
                                var entityRef = ConvertBillPaymentReference(reference, bill.PaymentID, userId);
                                if (entityRef.BillPaymtRefID == 0)
                                {
                                    _context.PRQ_ChemBillPymtReference.Add(entityRef);
                                    _context.SaveChanges();
                                }
                                else
                                {
                                    _context.SaveChanges();
                                }
                            }
                        }

                        tx.Complete();
                        if (_mode == 1)
                        {
                            _validationMsg.ReturnId   = bill.PaymentID;
                            _validationMsg.ReturnCode = bill.PaymentNo;
                            _validationMsg.Type       = Enums.MessageType.Success;
                            _validationMsg.Msg        = "Saved successfully.";
                        }
                        if (_mode == 2)
                        {
                            _validationMsg.Type = Enums.MessageType.Update;
                            _validationMsg.Msg  = "Updated successfully.";
                        }
                    }
                }
            }
            catch
            {
                _validationMsg.Type = Enums.MessageType.Error;
                _validationMsg.Msg  = "Failed to save.";
            }
            return(_validationMsg);
        }
        public ActionResult GetBillPayById(long paymentId)
        {
            var bill   = _unit.ChemicalLocalPurchaseBillPaymentRepository.GetByID(paymentId);
            var result = new PrqChemLocalPurcBillPay
            {
                PaymentId   = bill.PaymentID,
                PaymentNo   = bill.PaymentNo,
                PaymentDate = string.Format("{0:dd/MM/yyyy}", bill.PaymentDate),
                SupplierId  = bill.SupplierID,
                SupplierNo  = bill.SupplierID == null
                    ? ""
                    : _unit.SysSupplierRepository.GetByID(bill.SupplierID).SupplierCode,
                SupplierName = bill.SupplierID == null
                    ? ""
                    : _unit.SysSupplierRepository.GetByID(bill.SupplierID).SupplierName,
                SupplierAddressId = bill.SupplierAddressID,
                SupplierAddress   = bill.SupplierAddressID == null
                    ? ""
                    : _unit.SupplierAddressRepository.GetByID(bill.SupplierAddressID).Address,
                PurchaseYear  = bill.PurchaseYear,
                PaymentType   = bill.PaymentType,
                PaymentMethod = bill.PaymentMethod,
                Currency      = bill.Currency,
                PaymentDoc    = bill.PaymentDoc,
                BillAmount    = bill.BillAmount,
                VatAmount     = bill.VatAmount,
                DeductAmount  = bill.DeductAmount,
                PaymentAmount = bill.PaymentAmount,
                PaymentStatus = bill.PaymentStatus,
                Remarks       = bill.Remarks,
                RecordStatus  = bill.RecordStatus,
                CheckedBy     = bill.CheckedBy,
                CheckedByName = bill.CheckedBy == null
                    ? ""
                    : _unit.SysSupplierRepository.GetByID(bill.CheckedBy).SupplierName,
                CheckComments  = bill.CheckComments,
                ApprovedBy     = bill.ApprovedBy,
                ApprovedByName = bill.ApprovedBy == null
                    ? ""
                    : _unit.SysSupplierRepository.GetByID(bill.ApprovedBy).SupplierName,
                ApprovalAdvice = bill.ApprovalAdvice,
                References     =
                    _unit.ChemicalBillPaymentReference.Get().Where(ob => ob.PaymentID == bill.PaymentID).Select(
                        reff => new PrqChemBillPymtRef
                {
                    BillPaymtRefID = reff.BillPaymtRefID,
                    PaymentID      = reff.PaymentID,
                    BillID         = reff.BillID,
                    BillNo         =
                        reff.BillID == null
                                    ? ""
                                    : _unit.ChemicalLocalPurchaseBillRepository.GetByID(reff.BillID).BillNo,
                    SupplierBillNo = reff.SupplierBillNo,
                    RecordStatus   = reff.RecordStatus
                }).ToList()
            };

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Example #3
0
        private PRQ_ChemLocalPurcBillPayment ConvertBillPayment(PrqChemLocalPurcBillPay model, int userId)
        {
            var entity = model.PaymentId == 0 ? new PRQ_ChemLocalPurcBillPayment() : (from b in _context.PRQ_ChemLocalPurcBillPayment.AsEnumerable()
                                                                                      where b.PaymentID == model.PaymentId
                                                                                      select b).FirstOrDefault();

            entity.PaymentID         = model.PaymentId;
            entity.PaymentNo         = model.PaymentNo;
            entity.PaymentDate       = DalCommon.SetDate(model.PaymentDate);
            entity.SupplierID        = model.SupplierId;
            entity.SupplierAddressID = model.SupplierAddressId;
            entity.PurchaseYear      = model.PurchaseYear;
            entity.PaymentType       = model.PaymentType;
            entity.PaymentMethod     = model.PaymentMethod;
            entity.Currency          = model.Currency;
            entity.PaymentDoc        = model.PaymentDoc;
            entity.BillAmount        = model.BillAmount;
            entity.VatAmount         = model.VatAmount;
            entity.DeductAmount      = model.DeductAmount;
            entity.PaymentAmount     = model.PaymentAmount;
            entity.PaymentStatus     = model.PaymentStatus;
            entity.Remarks           = model.Remarks;
            entity.RecordStatus      = model.PaymentId == 0
                ? "NCF"
                : _unit.ChemicalLocalPurchaseBillPaymentRepository.GetByID(model.PaymentId).RecordStatus;
            entity.SetOn = model.PaymentId == 0
                ? DateTime.Now
                : _unit.ChemicalLocalPurchaseBillPaymentRepository.GetByID(model.PaymentId).SetOn;
            entity.SetBy = model.PaymentId == 0
                ? userId
                : _unit.ChemicalLocalPurchaseBillPaymentRepository.GetByID(model.PaymentId).SetBy;
            entity.ModifiedBy = model.PaymentId == 0 ? (int?)null : userId;
            entity.ModifiedOn = model.PaymentId == 0 ? (DateTime?)null : DateTime.Now;

            return(entity);
        }
 public ActionResult Save(PrqChemLocalPurcBillPay model)
 {
     _userId        = Convert.ToInt32(Session["UserID"]);
     _validationMsg = _dalPrqChemLocalPurcBillPay.Save(model, _userId);
     return(Json(_validationMsg, JsonRequestBehavior.AllowGet));
 }