Beispiel #1
0
        public Prq_SupplierBillItem ConvertItem(PrqSupplierBillItem model, long billId, int userId)
        {
            var entity = model.BillItemID == 0
                ? new Prq_SupplierBillItem()
                : (from b in _context.Prq_SupplierBillItem.AsEnumerable()
                   where b.BillItemID == model.BillItemID
                   select b).FirstOrDefault();

            entity.SupplierBillID = billId;
            entity.BillItemID     = model.BillItemID;
            entity.ItemType       = model.ItemTypeID;
            entity.ItemSize       = model.ItemSizeID;
            entity.ItemQty        = model.ItemQty;
            entity.RejectQty      = model.RejectQty ?? 0;
            entity.ItemRate       = model.ItemRate;
            entity.ApproveRate    = model.ApproveRate;
            entity.Amount         = model.Amount;
            entity.AmtUnit        = model.AmtUnit;
            entity.AvgArea        = model.AvgArea;
            entity.AreaUnit       = model.AreaUnit;
            entity.Remarks        = model.Remarks;
            entity.SetOn          = model.BillItemID == 0
                ? DateTime.Now
                : _unit.SupplierBillItemRepository.GetByID(model.BillItemID).SetOn;
            entity.SetBy = model.BillItemID == 0
                ? userId
                : _unit.SupplierBillItemRepository.GetByID(model.BillItemID).SetBy;
            entity.RecordStatus = "NCF";
            entity.IsDelete     = false;

            return(entity);
        }
        public PrqSupplierBillItem SetToBussinessObject(Prq_SupplierBillItem entity)
        {
            var model = new PrqSupplierBillItem();

            model.SupplierBillID = entity.SupplierBillID;
            model.BillItemID     = entity.BillItemID;
            model.ItemTypeID     = entity.ItemType;
            model.ItemTypeName   =
                _context.Sys_ItemType.Where(w => w.ItemTypeID == entity.ItemType).FirstOrDefault().ItemTypeName;
            model.ItemSizeID   = entity.ItemSize;
            model.ItemSizeName = _context.Sys_Size.Where(w => w.SizeID == entity.ItemSize).FirstOrDefault().SizeName;
            model.ItemQty      = entity.ItemQty;
            model.RejectQty    = entity.RejectQty;
            model.ItemRate     = entity.ItemRate;
            model.ApproveRate  = entity.ApproveRate;
            model.Amount       = entity.Amount;
            model.AmtUnit      = entity.AmtUnit ?? 0;
            if (entity.AmtUnit != 0)
            {
                model.AmtUnitName = _context.Sys_Currency.Where(w => w.CurrencyID == entity.AmtUnit).FirstOrDefault().CurrencyName;
            }
            model.AvgArea  = entity.AvgArea;
            model.AreaUnit = entity.AreaUnit ?? 0;
            if (entity.AreaUnit != 0)
            {
                model.AreaUnitName = _context.Sys_Unit.Where(w => w.UnitID == entity.AreaUnit).FirstOrDefault().UnitName;
            }
            model.Remarks = entity.Remarks;

            return(model);
        }
        public ActionResult GetBillById(long billId)
        {
            var bill         = new PrqSupplierBill();
            var ritems       = new List <PrqSupplierBillItem>();
            var rchallans    = new List <PrqSupplierBillChallan>();
            var supplierBill = _unit.SupplierBillRepository.GetByID(billId);

            if (supplierBill != null)
            {
                bill.SupplierBillID    = supplierBill.SupplierBillID;
                bill.SupplierBillNo    = supplierBill.SupplierBillNo;
                bill.SupplierBillRefNo = supplierBill.SupplierBillRefNo;
                bill.SupplierID        = supplierBill.SupplierID;
                bill.SupplierCode      = _unit.SysSupplierRepository.GetByID(supplierBill.SupplierID).SupplierCode;
                bill.SupplierName      = _unit.SysSupplierRepository.GetByID(supplierBill.SupplierID).SupplierName;
                bill.SupplierAddressID = supplierBill.SupplierAddressID;
                bill.SupplierAddress   = _unit.SupplierAddressRepository.GetByID(supplierBill.SupplierAddressID).Address;
                bill.PurchaseID        = supplierBill.PurchaseID;
                bill.PurchaseNo        = supplierBill.PurchaseID == null
                    ? ""
                    : _unit.PrqPurchaseRepository.GetByID(supplierBill.PurchaseID).PurchaseNo;
                bill.BillCategory    = supplierBill.BillCategory;
                bill.BillType        = supplierBill.BillType;
                bill.BillDate        = string.Format("{0:dd/MM/yyyy}", supplierBill.BillDate);
                bill.PurchaseYear    = supplierBill.PurchaseYear;
                bill.Remarks         = supplierBill.Remarks;
                bill.TotalQty        = supplierBill.TotalQty;
                bill.TotalRejectQty  = supplierBill.TotalRejectQty;
                bill.AvgPrice        = supplierBill.ApprovedPrice;
                bill.ApprovedPrice   = supplierBill.ApprovedPrice;
                bill.OtherCost       = supplierBill.OtherCost;
                bill.DiscountAmt     = supplierBill.DiscountAmt;
                bill.DiscountPercent = supplierBill.DiscountPercent;
                bill.ApprovedAmt     = supplierBill.ApprovedAmt;
                bill.TotalAmt        = supplierBill.TotalAmt;
                bill.PayableAmt      = supplierBill.PayableAmt;
                bill.CheckComment    = supplierBill.CheckComment;
                bill.ApproveComment  = supplierBill.ApproveComment;
                bill.RecordStatus    = supplierBill.RecordStatus;
                var challans =
                    _unit.SupplierBillChallanRepository.Get()
                    .Where(ob => ob.SupplierBillID == supplierBill.SupplierBillID && ob.IsDelete == false)
                    .ToList();
                if (challans.Count > 0)
                {
                    foreach (var c in challans)
                    {
                        var rchallan = new PrqSupplierBillChallan();
                        rchallan.ChallanID   = c.ChallanID;
                        rchallan.ChallanNo   = c.S_ChallanRef;
                        rchallan.ChallanDate = string.Format("{0:dd/MM/yyyy}",
                                                             _unit.PrqPurchaseChallanRepo.GetByID(c.ChallanID).ChallanDate);
                        rchallan.Quantity =
                            _unit.PurchaseChallanItemRepository.Get()
                            .Where(ob => ob.ChallanID == c.ChallanID)
                            .Sum(ob => ob.ChallanQty);
                        rchallans.Add(rchallan);
                    }
                }
                var items =
                    _unit.SupplierBillItemRepository.Get()
                    .Where(ob => ob.SupplierBillID == supplierBill.SupplierBillID && ob.IsDelete == false)
                    .ToList();
                if (items.Count > 0)
                {
                    foreach (var item in items)
                    {
                        var ritem = new PrqSupplierBillItem();
                        ritem.BillItemID   = item.BillItemID;
                        ritem.ItemTypeID   = item.ItemType;
                        ritem.ItemTypeName = _unit.SysItemTypeRepository.GetByID(item.ItemType).ItemTypeName;
                        ritem.ItemSizeID   = item.ItemSize;
                        ritem.ItemSizeName = _unit.SysSizeRepository.GetByID(item.ItemSize).SizeName;
                        ritem.ItemQty      = item.ItemQty;
                        ritem.RejectQty    = item.RejectQty;
                        ritem.ItemRate     = item.ItemRate;
                        ritem.ApproveRate  = item.ApproveRate;
                        ritem.Amount       = item.Amount;
                        ritem.AmtUnit      = item.AmtUnit ?? 0;
                        ritem.AvgArea      = item.AvgArea;
                        ritem.AreaUnit     = item.AreaUnit;
                        ritem.AreaUnitName = item.AreaUnit == null ? "" : _unit.SysUnitRepository.GetByID(item.AreaUnit).UnitName;
                        ritem.Remarks      = item.Remarks;
                        ritems.Add(ritem);
                    }
                }
            }
            return(Json(new { bill, rchallans, ritems }, JsonRequestBehavior.AllowGet));
        }