public bool ReceiveServiceProduct(WarrantyBatteryModel product)
        {
            var maxSl = _iServiceGateway.GetMaxWarrantyProductReceiveSlNoByYear(DateTime.Now.Year);

            product.ReceiveRef = DateTime.Now.Year.ToString().Substring(2, 2) +
                                 GetReferenceAccountCodeById(Convert.ToInt32(ReferenceType.WarrantyBatteryReceive)) +
                                 (maxSl + 1);
            product.PrimaryTestResult = GetPrimaryTestResult(product);
            int rowAffected = _iServiceGateway.ReceiveServiceProduct(product);

            return(rowAffected > 0);
        }
        private string GetPrimaryTestResult(WarrantyBatteryModel product)
        {
            var policy = _iServiceGateway.GetTestPolicyByCategoryAndProductId(1, product.ProductId);

            if (product.OpenVoltage > policy.Ocv && product.LoadVoltage > policy.LoadVoltage && product.SpGrCellValueDifference < policy.SgDifference)
            {
                product.IsPassPrimaryTest = 1;
                return("The Battery was passed primary test,Please forward to next step (Charging stage)");
            }
            product.IsPassPrimaryTest = 0;
            return
                ("The Battery was Failed primary test please send the battery to R&D for further Analysis or proceed to charging step");
        }
        public bool ReceiveServiceProductTemp(WarrantyBatteryModel product)
        {
            var maxSl = _iServiceGateway.GetMaxWarrantyProductReceiveSlNoByYear(DateTime.Now.Year);

            product.ReceiveRef = DateTime.Now.Year.ToString().Substring(2, 2) +
                                 GetReferenceAccountCodeById(Convert.ToInt32(ReferenceType.WarrantyBatteryReceive)) +
                                 (maxSl + 1);
            int replaceNo = _iProductReplaceGateway.GetMaxReplaceSerialNoByYear(DateTime.Now.Year);

            product.ReplaceRef = GenerateReplaceRef(replaceNo);

            int rowAffected = _iServiceGateway.ReceiveServiceProductTemp(product);


            return(rowAffected > 0);
        }
 // GET: Services/WarrantyBattery
 public ActionResult Receive()
 {
     try
     {
         var user        = (ViewUser)Session["user"];
         var actionModel =
             _iCommonManager.GetActionListModelByAreaControllerActionName("Services", "WarrantyBattery",
                                                                          "Receive");
         var model = new WarrantyBatteryModel
         {
             PhysicalConditions = _iCommonManager.GetAllPhysicalConditions().ToList(),
             ServicingModels    = _iCommonManager.GetAllServicingStatus().ToList(),
             ChargingStatus     = _iCommonManager.GetAllCharginStatus().ToList(),
             ForwardToModels    = _iCommonManager.GetAllForwardToModelsByUserAndActionId(user.UserId, actionModel.Id).ToList(),
             DistributionPoints = _iBranchManager.GetAllBranches().ToList()
         };
         return(View(model));
     }
     catch (Exception exception)
     {
         Log.WriteErrorLog(exception);
         return(PartialView("_ErrorPartial", exception));
     }
 }
        public ActionResult Receive(WarrantyBatteryModel model)
        {
            try
            {
                var user = (ViewUser)Session["user"];

                if (model.ForwardToId != Convert.ToInt32(ForwardTo.Received))
                {
                    model.ForwardDetails = new ForwardDetails
                    {
                        ForwardToId     = model.ForwardToId,
                        ForwardFromId   = Convert.ToInt32(ForwardTo.Received),
                        ForwardDateTime = DateTime.Now,
                        UserId          = user.UserId,
                        ForwardRemarks  = model.ForwardRemarks
                    };
                }
                else
                {
                    model.ForwardDetails = new ForwardDetails
                    {
                        ForwardToId     = Convert.ToInt32(ForwardTo.Received),
                        ForwardFromId   = Convert.ToInt32(ForwardTo.Received),
                        ForwardDateTime = DateTime.Now,
                        UserId          = user.UserId,
                        ForwardRemarks  = model.ForwardRemarks
                    };
                }

                var product        = _iInventoryManager.GetProductHistoryByBarcode(model.Barcode) ?? new ViewProductHistory();
                var age            = (DateTime.Now.Date - Convert.ToDateTime(product.DeliveryDate).Date).TotalDays;
                var warrantyPeriod = product.LifeTime;
                //--------------02-Dec-2019 Begin---------



                var serviceDuration = Convert.ToInt32((model.DelearReceiveDate.Date - Convert.ToDateTime(product.SaleDate).Date).TotalDays);

                product.ServiceDuration   = serviceDuration;
                model.IsSoldInGracePeriod = product.AgeLimitInDealerStock < product.SalesDuration ? 0 : 1;
                model.IsInWarrantyPeriod  = product.ServiceDuration > product.LifeTime ? 0 : 1;

                //-----------End-------
                model.HasWarranty = age > warrantyPeriod ? "N" : "Y";
                var branchId = Convert.ToInt32(Session["BranchId"]);
                model.EntryByUserId     = user.UserId;
                model.ReceiveByBranchId = branchId;
                model.ReceiveDatetime   = DateTime.Now;
                model.DelivaryRef       = product.DeliveryRef;
                model.TransactionRef    = product.OrderRef;
                model.Barcode           = product.ProductBarCode;
                model.ClientId          = product.ClientId;
                model.ProductId         = product.ProductId;
                model.ServiceDuration   = serviceDuration;
                model.SaleDate          = Convert.ToDateTime(product.SaleDate);
                model.Status            = 0;
                var result = _iServiceManager.ReceiveServiceProduct(model);
                if (result)
                {
                    ModelState.Clear();
                    return(RedirectToAction("All"));
                }
                model.PhysicalConditions = _iCommonManager.GetAllPhysicalConditions().ToList();
                model.ServicingModels    = _iCommonManager.GetAllServicingStatus().ToList();
                model.ChargingStatus     = _iCommonManager.GetAllCharginStatus().ToList();
                return(Receive(model));
            }
            catch (Exception exception)
            {
                Log.WriteErrorLog(exception);
                return(PartialView("_ErrorPartial", exception));
            }
        }
 public bool Delete(WarrantyBatteryModel model)
 {
     throw new NotImplementedException();
 }
        public ActionResult Entry(FormCollection collection, ReplaceModel model)
        {
            try
            {
                int branchId  = Convert.ToInt32(Session["BranchId"]);
                int companyId = Convert.ToInt32(Session["CompanyId"]);
                var clientId  = Convert.ToInt32(collection["clientId"]);
                var user      = (ViewUser)Session["user"];
                var productId = Convert.ToInt32(collection["ProductId"]);

                var qty      = Convert.ToInt32(collection["Quantity"]);
                var aProduct = _iProductManager.GetProductByProductId(productId);
                aProduct.Quantity   = qty;
                aProduct.ExpiryDate = model.ExpiryDate;
                aProduct.SaleDate   = model.SaleDate;
                var products = new List <Product> {
                    aProduct
                };
                model.ClientId  = clientId;
                model.Products  = products.ToList();
                model.BranchId  = branchId;
                model.UserId    = user.UserId;
                model.CompanyId = companyId;
                model.Remarks   = collection["Remarks"];

                //var result = _iProductReplaceManager.SaveReplacementInfo(model);


                var warrantyBatteryModel = new WarrantyBatteryModel
                {
                    ReceiveDatetime    = DateTime.Now,
                    ClientId           = clientId,
                    ReceiveByBranchId  = branchId,
                    EntryByUserId      = user.UserId,
                    DelivaryRef        = DateTime.Now.Year.ToString().Substring(2, 2) + "FAKE",
                    TransactionRef     = Guid.NewGuid().ToString().ToUpper().Substring(0, 8),
                    ReportByEmployeeId = user.EmployeeId,
                    ReceiveRemarks     = model.Remarks,
                    ProductId          = productId,
                    IsManualEntry      = "Y",
                    Status             = 1,
                    ExpiryDate         = model.ExpiryDate,
                    SaleDate           = model.SaleDate
                };

                if (collection["Barcode"] == "")
                {
                    warrantyBatteryModel.Barcode = "FAKE" + Guid.NewGuid().ToString().ToUpper().Substring(0, 9);
                }
                else
                {
                    warrantyBatteryModel.Barcode = collection["Barcode"];
                }
                var resultTest = _iServiceManager.ReceiveServiceProductTemp(warrantyBatteryModel);

                if (resultTest)
                {
                    ModelState.Clear();
                    ViewBag.DistributionPointId = new SelectList(_iBranchManager.GetAllBranches(), "BranchId", "BranchName", branchId);
                    return(View());
                }
                // AddProductToTempReplaceProductXmlFile(aProduct);
                ViewBag.DistributionPointId = new SelectList(_iBranchManager.GetAllBranches(), "BranchId", "BranchName", branchId);
                return(View());
            }
            catch (Exception exception)
            {
                Log.WriteErrorLog(exception);

                return(PartialView("_ErrorPartial", exception));
            }

            //return View();
        }