Example #1
0
        public ActionResult _InsertPerson(int workerWorkplaceId, int StorageNameId)
        {
            Organization    currentOrg = organizationRepository.Get(getIntCurrentEnterpriseId());
            WorkerWorkplace wp         = workerWorkplaceRepository.Get(workerWorkplaceId);

            if (wp != null && wp.RootOrganization == currentOrg.Id)
            {
                StorageName currentStorageName          = storageNameRepository.Get(StorageNameId);
                Dictionary <string, object> queryParams = new Dictionary <string, object>();
                queryParams.Add("Organization", currentOrg);
                queryParams.Add("Worker", wp.Worker);
                queryParams.Add("StorageName", currentStorageName);
                MatPersonCardHead person = matPersonCardHeadRepository.FindOne(queryParams);
                if (person == null)
                {
                    person = new MatPersonCardHead();
                    person.Organization = currentOrg;
                    person.Worker       = wp.Worker;
                }

                /*
                 * if (person.StorageName != currentStorageName)
                 *  ModelState.AddModelError("","Этот сотрудник уже числится на складе: " + currentStorageName.Name);
                 * else
                 * {*/
                person.IsActive    = true;
                person.Department  = wp.Organization.Parent;
                person.StorageName = currentStorageName;
                matPersonCardHeadRepository.SaveOrUpdate(person);
                //}
            }
            return(View(new GridModel(new List <MatPersonCardHead>())));
        }
Example #2
0
        public ActionResult UpdateWorkerWorplace(string id)
        {
            WorkerWorkplace wwp = workplaceRepository.Get(int.Parse(id));

            if (TryUpdateModel(wwp, new string[] { "Organization", "RootOrganization", "IsActive" }))
            {
                //int workerId = int.Parse(Request.Params["Worker[Id]"]);
                //int workerId = -1;
                //string workerFio = Request.Params["Worker.Fio"];
                //Worker worker = null;
                //if (int.TryParse(workerFio, out workerId))
                //    worker = workerRepository.Get(workerId);

                ////int orgId = int.Parse(Request.Params["Organization[Id]"]);
                //int orgId = -1;
                //string orgName = Request.Params["Organization.Name"];
                //Organization org = null;
                //if (int.TryParse(orgName, out orgId))
                //    org = organizationRepository.Get(orgId);

                //WorkerWorkplace workplace = null;
                //if (id != null)
                //    workplace = workplaceRepository.Get(int.Parse(id));
                //else
                //    workplace = new WorkerWorkplace();
                //if (worker != null)
                //    workplace.Worker = worker;
                //if (org != null)
                //    workplace.Organization = org;
                workplaceRepository.SaveOrUpdate(wwp);
            }
            return(SelectWorkerWorplace((int)Session["workerWorkplaceParam"]));
        }
Example #3
0
        public ActionResult SelectWorkerWorplace(int?param)
        {
            IList <WorkerWorkplace> newWorkerWorkplace = new List <WorkerWorkplace>();

            if (param != null && param > 0)
            {
                Session.Add("workerWorkplaceParam", param);
                Dictionary <string, object> queryParams = new Dictionary <string, object>();
                queryParams.Add("Worker.id", param);
                queryParams.Add("Worker.RootOrganization", int.Parse(getCurrentEnterpriseId()));
                queryParams.Add("IsActive", true);

                Dictionary <string, object> orderParams = new Dictionary <string, object>();
                //orderParams.Add("IsActive", DESC);
                orderParams.Add("BeginDate", DESC);
                orderParams.Add("Worker.Fio", ASC);

                IList <WorkerWorkplace> workerWorkplaces = workplaceRepository.GetByLikeCriteria(queryParams, orderParams);

                foreach (WorkerWorkplace current in workerWorkplaces)
                {
                    WorkerWorkplace wwp = rebuildWorkerWorkplace(current);


                    newWorkerWorkplace.Add(wwp);
                }
            }
            return(View(new GridModel(newWorkerWorkplace)));
        }
Example #4
0
        public ActionResult Select(int?workerWorkplaceId)
        {
            IList <WorkerNorma> workerNormas = new List <WorkerNorma>();
            WorkerNorma         workerNorma  = null;

            if (workerWorkplaceId != null)
            {
                WorkerWorkplace workerWorkplace = workerWorkplaceRepository.Get(workerWorkplaceId.Value);
                //ViewData["worker"] = workerWorkplace.Worker;


                //HttpContext.Cache.Insert("workerWorkplaceId", workerWorkplaceId);
                Session.Add("workerWorkplaceId", workerWorkplaceId);

                Dictionary <string, object> query = new Dictionary <string, object>();
                query.Add("WorkerWorkplace", workerWorkplace);
                WorkerCardHead workerCardHead = workerCardRepository.FindOne(query);

                foreach (WorkerCardContent workerCardContent in workerCardHead.WorkerCardContents)
                {
                    workerNorma                 = new WorkerNorma();
                    workerNorma.StorageId       = workerCardContent.Storage.Id;
                    workerNorma.StorageInfo     = workerCardContent.Storage.StorageInfo;
                    workerNorma.ReceptionDate   = workerCardContent.Operation.OperDate;
                    workerNorma.PresentQuantity = workerCardContent.Quantity;
                    workerNormas.Add(workerNorma);
                }
            }
            return(View(new GridModel(workerNormas)));
        }
Example #5
0
        //public ActionResult Delete(WorkerWorkplace worker)
        public ActionResult DeleteWorkerWorplace(int id)
        {
            WorkerWorkplace workerWorkplace = workplaceRepository.Get(id);

            workplaceRepository.Delete(workerWorkplace);
            return(SelectWorkerWorplace((int)Session["workerWorkplaceParam"]));
        }
        public ActionResult Select_Worker(int?workerWorkplaceId)
        {
            IList <WorkerWorkplace> returnWorkerWorkplaces = new List <WorkerWorkplace>();
            WorkerWorkplace         activeWorkerWorkplaces = null;

            //if (workerWorkplaceId == null && Session["workerWorkplaceId"] != null)
            //    workerWorkplaceId = (int)Session["workerWorkplaceId"];
            if (workerWorkplaceId != null)
            {
                Dictionary <string, object> query = new Dictionary <string, object>();
                Dictionary <string, object> order = new Dictionary <string, object>();
                query.Add("Worker.Id", workerWorkplaceId);
                query.Add("IsActive", true);
                //Выбираем активные рабочие места
                IList <WorkerWorkplace> workerWorkplaces = workerWorkplaceRepository.GetByLikeCriteria(query);
                foreach (var item in workerWorkplaces)
                {
                    activeWorkerWorkplaces = item;
                    break;
                }
                if (activeWorkerWorkplaces != null)
                {
                    returnWorkerWorkplaces.Add(rebuildWorkerWorkplace(activeWorkerWorkplaces));
                }
            }
            return(View(new GridModel(returnWorkerWorkplaces)));
        }
Example #7
0
        public static Operation rebuildOperation(Operation inOperation, List <string> excludeProperty)
        {
            Operation outOperation = null;

            if (inOperation != null)
            {
                outOperation           = new Operation(inOperation.Id);
                outOperation.DocNumber = inOperation.DocNumber;
                outOperation.DocDate   = inOperation.DocDate;
                outOperation.Note      = inOperation.Note;
                outOperation.Wear      = inOperation.Wear;
                if (outOperation.Wear == null)
                {
                    outOperation.Wear = inOperation.Storage.Wear;
                }

                outOperation.Quantity = inOperation.Quantity;
                outOperation.OperDate = inOperation.OperDate;
                outOperation.Partner  = rebuildStorageName(inOperation.Partner);
                if (!isExclude(excludeProperty, "StorageName"))
                {
                    outOperation.StorageName = rebuildStorageName(inOperation.StorageName, rebuildExcludeProperty(excludeProperty, "StorageName"));
                }
                OperType ot = new OperType(inOperation.OperType.Id, inOperation.OperType.Name);
                outOperation.OperType = ot;
                if (!isExclude(excludeProperty, "Storage"))
                {
                    outOperation.Storage = rebuildStorage(inOperation.Storage, rebuildExcludeProperty(excludeProperty, "Storage"));
                }
                if (!isExclude(excludeProperty, "DocType"))
                {
                    if (inOperation.DocType != null)
                    {
                        DocType doct = new DocType(inOperation.DocType.Id, inOperation.DocType.Name);
                        outOperation.DocType = doct;
                    }
                }
                if (!isExclude(excludeProperty, "WorkerWorkplace"))
                {
                    WorkerWorkplace wwp    = new WorkerWorkplace();
                    Organization    org    = new Organization();
                    Worker          worker = new Worker();
                    wwp.Organization = org;
                    wwp.Worker       = worker;
                    if (inOperation.WorkerWorkplace != null)
                    {
                        wwp = rebuildWorkerWorkplaceSimple(inOperation.WorkerWorkplace, rebuildExcludeProperty(excludeProperty, "WorkerWorkplace"));
                    }
                    outOperation.WorkerWorkplace = wwp;
                }
                if (inOperation.Motiv != null)
                {
                    Motiv m = new Motiv(inOperation.Motiv.Id, inOperation.Motiv.Name);
                    outOperation.Motiv = m;
                }
            }
            return(outOperation);
        }
        //public ActionResult Delete(WorkerWorkplace worker)
        public ActionResult Delete(int id)
        {
            //workplaceRepository.Delete(worker);
            WorkerWorkplace workerWorkplace = workplaceRepository.Get(id);

            workplaceRepository.Delete(workerWorkplace);
            //return getAllAndView();
            //return Select((string)HttpContext.Cache.Get("workerWorkplaceParam"));
            return(Select((string)Session["workerWorkplaceParam"]));
        }
Example #9
0
        //public ActionResult Save(WorkerWorkplace workerWorkplace)
        public ActionResult SaveWorkerWorplace()
        {
            WorkerWorkplace workerWorkplace = new WorkerWorkplace();

            workerWorkplace.Worker           = workerRepository.Get((int)Session["workerWorkplaceParam"]);
            workerWorkplace.Organization     = organizationRepository.Get(int.Parse(Request["Organization"]));
            workerWorkplace.RootOrganization = workerWorkplace.Organization.RootOrganization;
            workerWorkplace.IsActive         = bool.Parse(Request["IsActive"]);
            workplaceRepository.SaveOrUpdate(workerWorkplace);
            return(SelectWorkerWorplace((int)Session["workerWorkplaceParam"]));
        }
        public ActionResult Select_Worker(int?workerWorkplaceId)
        {
            IList <WorkerWorkplace> workerWorkplaces = new List <WorkerWorkplace>();

            if (workerWorkplaceId != null)
            {
                WorkerWorkplace workerWorkplace = workerWorkplaceRepository.Get(workerWorkplaceId.Value);
                workerWorkplaces.Add(rebuildWorkerWorkplace(workerWorkplace));
            }
            return(View(new GridModel(workerWorkplaces)));
        }
Example #11
0
        public ActionResult Select(int?workerWorkplaceId, string workerWorkplaceText)
        {
            IList <WorkerNorma> workerNormas = new List <WorkerNorma>();
            WorkerNorma         workerNorma  = null;

            // Убрали запоминание табельных. Кладовщики путаются
            //if (workerWorkplaceId == null && Session["workerWorkplaceId"] != null)
            //    workerWorkplaceId = (int)Session["workerWorkplaceId"];
            if (workerWorkplaceId != null)
            {
                WorkerWorkplace workerWorkplace = workerWorkplaceRepository.Get(workerWorkplaceId.Value);
                //ViewData["worker"] = workerWorkplace.Worker;


                Session.Add("workerWorkplaceId", workerWorkplaceId);
                Session.Add("workerWorkplaceText", workerWorkplaceText);

                Dictionary <string, object> query = new Dictionary <string, object>();
                query.Add("WorkerWorkplace", workerWorkplace);
                WorkerCardHead workerCardHead = workerCardRepository.FindOne(query);

                if (workerCardHead != null)
                {
                    workerCardHead.WorkerCardContents = reorderWorkerCardContents(workerCardHead.WorkerCardContents);

                    foreach (WorkerCardContent workerCardContent in workerCardHead.WorkerCardContents)
                    {
                        //if (workerCardContent.Quantity <= 0)
                        //    continue;
                        if (workerCardContent.Quantity > 0)
                        {
                            workerNorma = new WorkerNorma();
                            //workerNorma.Storage = rebuildStorage(workerCardContent.Storage);
                            workerNorma.Id            = workerCardContent.Id;
                            workerNorma.StorageId     = workerCardContent.Storage.Id;
                            workerNorma.StorageNumber = workerCardContent.Storage.StorageName.StorageNumber;
                            workerNorma.StorageInfo   = workerCardContent.Storage.StorageInfo;
//                            workerNorma.ReceptionDate = workerCardContent.Operation.OperDate;
                            workerNorma.ReceptionDate   = workerCardContent.StartDate;
                            workerNorma.PresentQuantity = workerCardContent.Quantity;
                            //workerNorma.PutQuantity = workerNorma.PresentQuantity;
                            workerNorma.PutQuantity = 0;
                            workerNormas.Add(workerNorma);
                        }
                    }
                }
            }
            return(View(new GridModel(workerNormas)));
        }
Example #12
0
        public static WorkerWorkplace rebuildWorkerWorkplace(WorkerWorkplace inWorkerWorkplace)
        {
            if (inWorkerWorkplace == null)
            {
                return(null);
            }
            WorkerWorkplace outWorkerWorkplace = new WorkerWorkplace(inWorkerWorkplace.Id);

            outWorkerWorkplace.Worker           = rebuildWorker(inWorkerWorkplace.Worker);
            outWorkerWorkplace.Organization     = rebuildOrganization(inWorkerWorkplace.Organization);
            outWorkerWorkplace.RootOrganization = inWorkerWorkplace.RootOrganization;
            outWorkerWorkplace.IsActive         = inWorkerWorkplace.IsActive;
            outWorkerWorkplace.BeginDate        = inWorkerWorkplace.BeginDate;
            return(outWorkerWorkplace);
        }
        //public ActionResult Save(WorkerWorkplace workerWorkplace)
        public ActionResult Save()
        {
            WorkerWorkplace workerWorkplace = new WorkerWorkplace();

            if (TryUpdateModel(workerWorkplace))
            {
//                Organization rootOrg = workerWorkplace.Organization.RootOrganization;
                workerWorkplace.RootOrganization = workerWorkplace.Organization.RootOrganization;
                workplaceRepository.SaveOrUpdate(workerWorkplace);
            }
            //return getAllAndView();
            //return View(workers);
            //return Select((string)HttpContext.Cache.Get("workerWorkplaceParam"));
            return(Select((string)Session["workerWorkplaceParam"]));
        }
Example #14
0
        public static WorkerWorkplace rebuildWorkerWorkplaceSimple(WorkerWorkplace inWorkerWorkplace, List <string> excludeProperty)
        {
            WorkerWorkplace outWorkerWorkplace = new WorkerWorkplace(inWorkerWorkplace.Id);

            if (!isExclude(excludeProperty, "Worker"))
            {
                outWorkerWorkplace.Worker = rebuildWorker(inWorkerWorkplace.Worker, rebuildExcludeProperty(excludeProperty, "Worker"));
            }
            if (!isExclude(excludeProperty, "Organization"))
            {
                outWorkerWorkplace.Organization = rebuildOrganizationSimple(inWorkerWorkplace.Organization, rebuildExcludeProperty(excludeProperty, "Organization"));
            }
            outWorkerWorkplace.IsActive  = inWorkerWorkplace.IsActive;
            outWorkerWorkplace.BeginDate = inWorkerWorkplace.BeginDate;
            return(outWorkerWorkplace);
        }
        public ActionResult Select(string param)
        {
            //IList<Worker> workers = workerRepository.GetAll();
            //return View(new GridModel(workers));
            IList <WorkerWorkplace> newWorkerWorkplace = new List <WorkerWorkplace>();

            if (param != null && !"".Equals(param))
            {
                //HttpContext.Cache.Insert("workerWorkplaceParam", param);
                Session.Add("workerWorkplaceParam", param);

                Dictionary <string, object> queryParams = new Dictionary <string, object>();
                int tabn = -1;
                if (int.TryParse(param, out tabn))
                {
                    queryParams.Add("Worker.TabN", tabn);
                }
                else
                {
                    queryParams.Add("Worker.Fio", param);
                }
                //queryParams.Add("Organization.Parent.Id", int.Parse("50005303"));
                queryParams.Add("Worker.RootOrganization", int.Parse(getCurrentEnterpriseId()));
                queryParams.Add("IsActive", true);

                Dictionary <string, object> orderParams = new Dictionary <string, object>();
                orderParams.Add("Worker.Fio", ASC);

                IList <WorkerWorkplace> workerWorkplaces = workplaceRepository.GetByLikeCriteria(queryParams, orderParams);

                foreach (WorkerWorkplace current in workerWorkplaces)
                {
                    //Worker worker = rebuildWorker(current.Worker);
                    //Organization organization = rebuildOrganization(current.Organization);
                    //WorkerWorkplace wwp = new WorkerWorkplace(current.Id);
                    //wwp.Worker = worker;
                    //wwp.Organization = organization;
                    //wwp.IsActive = current.IsActive;

                    WorkerWorkplace wwp = rebuildWorkerWorkplace(current);
                    newWorkerWorkplace.Add(wwp);
                }
            }
            //newList = workerWorkplaces;
            return(View(new GridModel(newWorkerWorkplace)));
            //return getAllAndView();
        }
        public ActionResult _GetWorkerWorkplaces(int?workerWorkplaceId, string text)
        {
            if ((workerWorkplaceId == null) && (text == null))
            {
                return new JsonResult {
                           Data = new SelectList(new List <WorkerWorkplace>())
                }
            }
            ;
            Dictionary <string, object> queryParams = new Dictionary <string, object>();

            if (workerWorkplaceId != null)
            {
                WorkerWorkplace wwp = workerWorkplaceRepository.Get(workerWorkplaceId.Value);

                queryParams.Add("Worker", wwp.Worker);
            }
            else
            {
                int tabn = -1;
                if (int.TryParse(text, out tabn))
                {
                    queryParams.Add("Worker.TabN", tabn);
                }
                else
                {
                    queryParams.Add("Worker.Fio", text);
                }
            }
            queryParams.Add("RootOrganization", int.Parse(getCurrentEnterpriseId()));
            queryParams.Add("IsActive", true);
            IList <WorkerWorkplace> workerWorkplaces = workerWorkplaceRepository.GetByLikeCriteria(queryParams);

            return(new JsonResult
            {
                Data = new SelectList(workerWorkplaces, "Worker.Id", "WorkplaceInfo")
//                Data = new SelectList(workerWorkplaces, "Id", "WorkplaceInfo")
            });
        }
        public ActionResult Update(string id)
        {
            WorkerWorkplace wwp = workplaceRepository.Get(int.Parse(id));

            if (TryUpdateModel(wwp))
            {
                //int workerId = int.Parse(Request.Params["Worker[Id]"]);
                //int workerId = -1;
                //string workerFio = Request.Params["Worker.Fio"];
                //Worker worker = null;
                //if (int.TryParse(workerFio, out workerId))
                //    worker = workerRepository.Get(workerId);

                ////int orgId = int.Parse(Request.Params["Organization[Id]"]);
                //int orgId = -1;
                //string orgName = Request.Params["Organization.Name"];
                //Organization org = null;
                //if (int.TryParse(orgName, out orgId))
                //    org = organizationRepository.Get(orgId);

                //WorkerWorkplace workplace = null;
                //if (id != null)
                //    workplace = workplaceRepository.Get(int.Parse(id));
                //else
                //    workplace = new WorkerWorkplace();
                //if (worker != null)
                //    workplace.Worker = worker;
                //if (org != null)
                //    workplace.Organization = org;
                workplaceRepository.SaveOrUpdate(wwp);
            }
            //return getAllAndView();
            //return View(workers);
            //return RedirectToAction("Select");
            return(Select((string)Session["workerWorkplaceParam"]));
        }
//        public ActionResult Update(string id)
        //public ActionResult Update(WorkerNorma workerNorma)
        public ActionResult Update([Bind(Prefix = "updated")] IEnumerable <WorkerNorma> workerNormas)
        {
            //int workerWorkplaceId = (int)HttpContext.Cache.Get("workerWorkplaceId");
            int    workerWorkplaceId = (int)Session["workerWorkplaceId"];
            string docNumber         = operationRepository.GetNextDocNumber(DataGlobals.OPERATION_WORKER_RETURN, getCurrentEnterpriseId());
            int?   motivId           = null;
            //DateTime? docDate = null;
            DateTime?operDate = null;
            // перове число текущего месяца
            DateTime firstDay = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1);
            // первое число предыдущего месяца
            DateTime minDate = firstDay.AddMonths(-1);

            Dictionary <string, object> query = new Dictionary <string, object>();

            query.Add("Id", workerWorkplaceId);
            WorkerWorkplace workerWorkplace = workerWorkplaceRepository.Get(workerWorkplaceId);

            query.Clear();
            query.Add("WorkerWorkplace", workerWorkplace);

            WorkerCardHead workerCardHead = workerCardRepository.FindOne(query);


            if (workerNormas != null)
            {
                int i = -1;
                foreach (var workerNorma in workerNormas)
                {
                    i++;
                    if (i == 0)
                    {
                        if (workerNorma.OperDate != null)
                        {
                            operDate = workerNorma.OperDate.Value;

                            if (DateTime.Today > operDate)
                            {
                                operDate = operDate.Value.AddHours(21).AddMinutes(0).AddSeconds(0);
                            }
                            else
                            {
                                operDate = operDate.Value.AddHours(DateTime.Now.Hour).AddMinutes(DateTime.Now.Minute).AddSeconds(DateTime.Now.Second);
                            }
                        }
                        motivId = workerNorma.MotivId;
                    }

                    if (workerNorma.PutQuantity <= 0)
                    {
                        continue;
                    }

                    //NormaContent normaContent = normaContentRepository.Get(workerNorma.NormaContentId);

                    WorkerCardContent workerCardContentPresent = getWorkerCard(workerNorma.Id, workerCardHead);

                    //workerCardContent.Storage = workerNorma.WorkerCardContent.Storage;
                    //                    if (workerCardContentPresent.Quantity != workerNorma.PutQuantity)
                    //                        ModelState.AddModelError("updated[" + i + "].StorageName", "Списать можно только столько сколько есть на руках");


                    //if (operDate != null && (DateTime.Now < operDate || minDate > operDate))
                    if (operDate != null && DateTime.Now < operDate)
                    {
                        ModelState.AddModelError(operDate + ": ", "Дата операции должна быть не больше текущей даты и не меньше 1-го числа предыдущего месяца");
                    }
                    if (operDate < workerNorma.ReceptionDate)
                    {
                        ModelState.AddModelError(operDate + ": ", "Дата возврата не может быть меньше даты выдачи");
                    }
                    if (firstDay > operDate)
                    {
                        // проверка на закрытие периода
                        string   periodIsClosed = getConfigParamValue(configRepository, "periodIsClosed", getCurrentEnterpriseId());
                        string   periodDateStr  = getConfigParamValue(configRepository, "periodDate", getCurrentEnterpriseId());
                        DateTime periodDate;
                        DateTime.TryParseExact(periodDateStr, DataGlobals.DATE_FORMAT_FULL_YEAR, null, System.Globalization.DateTimeStyles.None, out periodDate);
                        if (periodIsClosed != null && periodIsClosed.Equals("1") && periodDate > operDate)
                        {
                            ModelState.AddModelError(operDate + ": ", "Период закрыт для изменений");
                        }
                    }
                    if (workerNorma.PutQuantity <= 0)
                    {
                        ModelState.AddModelError(workerCardContentPresent.Storage.Nomenclature.Name, "Вернуть можно кол-во больше 0");
                    }

                    if (workerNorma.PutQuantity > workerCardContentPresent.Quantity)
                    {
                        ModelState.AddModelError(workerCardContentPresent.Storage.Nomenclature.Name, "Вернуть можно не больше чем есть на руках");
                    }


                    if (workerNorma.Wear == null)
                    {
                        ModelState.AddModelError(workerCardContentPresent.Storage.Nomenclature.Name, "Введите износ");
                    }


                    //if (string.IsNullOrEmpty(docNumber) || docDate == null)
                    //    ModelState.AddModelError("updated[" + i + "].StorageName", "Номер и дата документа должны быть заполнены");
                }

                if (ModelState.IsValid)
                {
                    foreach (var workerNorma in workerNormas)
                    {
                        if (workerNorma.PutQuantity <= 0)
                        {
                            continue;
                        }

                        WorkerCardContent workerCardContentPresent = getWorkerCard(workerNorma.Id, workerCardHead);
                        //workerCardContentPresent.Storage = null;

                        Operation oper = new Operation();
                        oper.OperDate     = operDate.Value;
                        oper.OperType     = operTypeRepository.Get(DataGlobals.OPERATION_WORKER_RETURN);
                        oper.Organization = organizationRepository.Get(workerWorkplace.RootOrganization);
                        oper.Quantity     = workerNorma.PutQuantity;
                        //oper.Storage = workerCardContentPresent.Storage;
                        oper.Wear            = workerNorma.Wear;
                        oper.DocNumber       = docNumber;
                        oper.DocDate         = oper.OperDate;
                        oper.Motiv           = motivRepository.Get(motivId.Value);
                        oper.WorkerWorkplace = workerWorkplace;
                        oper.GiveOperation   = workerCardContentPresent.GiveOperation;

                        //workerCardContentPresent.Operation = oper;
                        //workerCardContentPresent.Quantity -= oper.Quantity;
                        if (workerNorma.PutQuantity == workerCardContentPresent.Quantity)
                        {
                            workerCardHead.WorkerCardContents.Remove(workerCardContentPresent);
                        }
//                        workerCardContentRepository.Delete(workerCardContentPresent);

                        //workerCardRepository.SaveOrUpdate(workerCardHead);

                        // если не утиль, ищем позицию с таким износом на складе
                        //if (int.Parse(workerNorma.Wear) > 0)
                        //{
                        query.Clear();
                        query.Add("Nomenclature", workerCardContentPresent.Storage.Nomenclature);
                        if (workerCardContentPresent.Storage.NomBodyPartSize != null)
                        {
                            query.Add("NomBodyPartSize", workerCardContentPresent.Storage.NomBodyPartSize);
                        }
                        if (workerCardContentPresent.Storage.Growth != null)
                        {
                            query.Add("Growth", workerCardContentPresent.Storage.Growth);
                        }
                        query.Add("StorageName", workerCardContentPresent.Storage.StorageName);
                        if (int.Parse(workerNorma.Wear) > 0)
                        {
                            query.Add("Wear", workerNorma.Wear);
                        }
                        IList <Storage> storages = storageRepository.GetByCriteria(query);

                        Storage storage = null;
                        if (storages.Count > 0)
                        {
                            storage = storages[0];
                            if (int.Parse(workerNorma.Wear) > 0)
                            {
                                storage.Quantity += workerNorma.PutQuantity;
                            }
                        }
                        else
                        {
                            storage                 = new Storage();
                            storage.Growth          = workerCardContentPresent.Storage.Growth;
                            storage.NomBodyPartSize = workerCardContentPresent.Storage.NomBodyPartSize;
                            storage.Nomenclature    = workerCardContentPresent.Storage.Nomenclature;
                            storage.StorageName     = workerCardContentPresent.Storage.StorageName;
                            storage.Wear            = workerNorma.Wear;
                            if (int.Parse(workerNorma.Wear) > 0)
                            {
                                storage.Quantity = workerNorma.PutQuantity;
                            }
                            else
                            {
                                storage.Quantity = 0;
                            }
                        }
                        storageRepository.SaveOrUpdate(storage);
                        oper.Storage = storage;
                        operationRepository.SaveOrUpdate(oper);
                        if (workerNorma.PutQuantity == workerCardContentPresent.Quantity)
                        {
                            workerCardContentPresent.OperReturn = oper;
                            workerCardContentPresent.Quantity   = 0;
                            workerCardContentPresent.EndDate    = oper.OperDate;
                        }
                        else
                        {
                            workerCardContentPresent.Quantity = workerCardContentPresent.Quantity - workerNorma.PutQuantity;
                            WorkerCardContent wcc = new WorkerCardContent();
                            wcc.Quantity       = 0;
                            wcc.StartDate      = workerCardContentPresent.StartDate;
                            wcc.EndDate        = oper.OperDate;
                            wcc.WorkerCardHead = workerCardContentPresent.WorkerCardHead;
                            wcc.Storage        = workerCardContentPresent.Storage;
                            wcc.Operation      = workerCardContentPresent.Operation;
                            wcc.OperReturn     = oper;
                            wcc.NormaContent   = workerCardContentPresent.NormaContent;
                            wcc.GiveOperation  = workerCardContentPresent.GiveOperation;

                            workerCardContentRepository.SaveOrUpdate(wcc);
                        }
                        workerCardContentRepository.SaveOrUpdate(workerCardContentPresent);

                        if (firstDay > operDate)
                        {
                            //пересчитываем остатки
                            rebuildRemaind(operationRepository, remainsRepository, storage, minDate, firstDay.AddSeconds(-1), firstDay);
                        }
                        //}
                    }
                }
            }
            return(Select(workerWorkplaceId, (string)Session["workerWorkplaceText"], (string)Session["storageNameId"]));
        }
        public ActionResult Select(int?workerWorkplaceId, string workerWorkplaceText, string storageNameId)
        {
            IList <WorkerNorma> workerNormas = new List <WorkerNorma>();
            WorkerNorma         workerNorma  = null;

            // Убрали запоминание табельных. Кладовщики путаются
            //if (workerWorkplaceId == null && Session["workerWorkplaceId"] != null)
            //    workerWorkplaceId = (int)Session["workerWorkplaceId"];
            if (workerWorkplaceId != null)
            {
                WorkerWorkplace workerWorkplace = workerWorkplaceRepository.Get(workerWorkplaceId.Value);
                //ViewData["worker"] = workerWorkplace.Worker;


                Session.Add("workerWorkplaceId", workerWorkplaceId);
                Session.Add("workerWorkplaceText", workerWorkplaceText);
                Session.Add("storageNameId", storageNameId);


                Dictionary <string, object> query = new Dictionary <string, object>();
                Dictionary <string, object> order = new Dictionary <string, object>();
                query.Add("WorkerWorkplace", workerWorkplace);
                WorkerCardHead workerCardHead = workerCardRepository.FindOne(query);

                if (workerCardHead != null)
                {
                    //query.Clear();
                    //order.Clear();
                    //query.Add("WorkerCardHead.Id", workerCardHead.Id);
                    //order.Add("Storage.Nomenclature.Name", ASC);
                    //workerCardHead.WorkerCardContents = workerCardContentRepository.GetByCriteria(query, order);
                    workerCardHead.WorkerCardContents = reorderWorkerCardContents(workerCardHead.WorkerCardContents);

                    foreach (WorkerCardContent workerCardContent in workerCardHead.WorkerCardContents)
                    {
                        //if (workerCardContent.Quantity <= 0)
                        //    continue;
                        StorageName storageName = storageNameRepository.Get(int.Parse(storageNameId));
//                        if (workerCardContent.Storage.StorageName.Id.ToString() != storageNameId)
                        if (workerCardContent.Storage.StorageName.StorageNumber != storageName.StorageNumber)
                        {
                            continue;
                        }
                        if (workerCardContent.Quantity > 0)
                        {
                            workerNorma = new WorkerNorma();
                            //workerNorma.Storage = rebuildStorage(workerCardContent.Storage);
                            workerNorma.Id            = workerCardContent.Id;
                            workerNorma.StorageId     = workerCardContent.Storage.Id;
                            workerNorma.StorageNumber = workerCardContent.Storage.StorageName.StorageNumber;
                            workerNorma.StorageInfo   = workerCardContent.Storage.StorageInfo;
                            workerNorma.Wear          = workerCardContent.Storage.Wear;
                            //Возвращают в основном б/у
                            //workerNorma.Wear = "50";
                            workerNorma.Wear = "";
//                            workerNorma.ReceptionDate = workerCardContent.Operation.OperDate;
                            workerNorma.ReceptionDate   = workerCardContent.StartDate;
                            workerNorma.PresentQuantity = workerCardContent.Quantity;
                            //workerNorma.PutQuantity = workerNorma.PresentQuantity;
                            workerNorma.PutQuantity = 0;
                            workerNormas.Add(workerNorma);
                        }
                    }
                }
            }
            return(View(new GridModel(workerNormas)));
        }
        public ActionResult _TransferWorkerCard(int?workerWorkplaceId, int storageNameId, string listId, Boolean outNorma, string OperDate)
        {
            DateTime operDate;

            DateTime.TryParseExact(OperDate, DataGlobals.DATE_FORMAT, null, System.Globalization.DateTimeStyles.None, out operDate);
            ResultState resultState = new ResultState();

            resultState.Status = ResultState.OK;
            if (workerWorkplaceId != null)
            {
                Dictionary <string, object> query = new Dictionary <string, object>();
                Dictionary <string, object> order = new Dictionary <string, object>();
                query.Add("Worker.Id", workerWorkplaceId);
                query.Add("IsActive", true);
                order.Add("Storage.StorageName.Id", storageNameId);
                //Выбираем активные рабочие места
                IList <WorkerWorkplace> workerWorkplaces = workerWorkplaceRepository.GetByLikeCriteria(query);
                if (workerWorkplaces.Count == 1)
                {
                    WorkerWorkplace ww = workerWorkplaces[0];
                    //Выбираем активные рабочие места
                    // Запрет на одевание работника в салоне к которому он не приписан. Пока закомментировала, т.к. не уверена, что не будет последствий

                    /*
                     * if (ww.Organization.StorageName.Id != storageNameId)
                     * {
                     *  resultState.Status = ResultState.ERROR;
                     *  resultState.setMessage("НЕЛЬЗЯ ВЫПОЛНИТЬ ПЕРЕВОД!!! Работник приписан к складу " + ww.Organization.StorageName.StorageNumber);
                     * }
                     */
                    string   periodDateStr  = getConfigParamValue(configRepository, "periodDate", getCurrentEnterpriseId());
                    string   periodIsClosed = getConfigParamValue(configRepository, "periodIsClosed", getCurrentEnterpriseId());
                    DateTime periodDate;
                    DateTime.TryParseExact(periodDateStr, DataGlobals.DATE_FORMAT_FULL_YEAR, null, System.Globalization.DateTimeStyles.None, out periodDate);

                    // проверка на закрытие периода
                    if (periodIsClosed != null && periodIsClosed.Equals("1") && periodDate > operDate)
                    {
                        resultState.Status = ResultState.ERROR;
                        resultState.setMessage(OperDate + ": Период закрыт для изменений");
                    }

                    if (resultState.Status == ResultState.OK)
                    {
                        query.Clear();
                        query.Add("WorkerWorkplace", ww);
                        WorkerCardHead newWorkerCardHead = workerCardRepository.FindOne(query);
                        if (newWorkerCardHead == null)
                        {
                            newWorkerCardHead = new WorkerCardHead();
                            newWorkerCardHead.WorkerWorkplace = ww;
                        }
                        query.Clear();
                        query.Add("Organization", ww.Organization);
                        query.Add("Norma.Organization.Id", int.Parse(getCurrentEnterpriseId()));
                        query.Add("Norma.IsActive", true);
                        IList <NormaOrganization>  normaOrganizations = normaOrganizationRepository.GetByCriteria(query);
                        IList <NomenclatureSimple> list = getNomenclaturesByParam(listId);
                        string docNumber = "00000";
                        // Убрала ниже, чтобы можно было изменять номер документа
                        docNumber = operationRepository.GetNextDocNumber(DataGlobals.OPERATION_STORAGE_TRANSFER_OUT, getCurrentEnterpriseId());
                        int?skladId = null;
                        foreach (var item in list)
                        {
                            ResultState listResultState = new ResultState();
                            listResultState.Status = ResultState.OK;

                            WorkerCardContent oldWorkerCardContent = workerCardContentRepository.Get(item.Id);
                            if (skladId != null && skladId != oldWorkerCardContent.Storage.StorageName.Id)
                            {
                                docNumber = operationRepository.GetNextDocNumber(DataGlobals.OPERATION_STORAGE_TRANSFER_OUT, getCurrentEnterpriseId());
                            }

                            if (oldWorkerCardContent.StartDate >= operDate)
                            {
                                listResultState.Status = ResultState.ERROR;
                                listResultState.setMessage(item.Name + "   Дата перевода раньше даты выдачи!!! Введите текущую дату!");

                                resultState.Status = ResultState.ERROR;
                                resultState.setMessage(item.Name + "   Дата перевода раньше даты выдачи!!! Введите текущую дату!");
                            }

                            NormaContent newNormaContent = GetNewNormaContent(normaOrganizations, item.GroupId);
                            // Если на новом рабочем месте номенклатура не подходит по норме и выбрана опция
                            //Ставим старую норму
                            //Закомментировано, т.к. по просьбе УПУ не нужно переносить на руки, то что не по норме
                            if (newNormaContent == null && outNorma == true)
                            {
                                newNormaContent = oldWorkerCardContent.NormaContent;
                            }
//                        if (newNormaContent != null )
                            if (newNormaContent == null && outNorma != true)
                            {
                                listResultState.Status = ResultState.ERROR;
                                listResultState.setMessage(item.Name + " НЕ СООТВЕТСТВУЕТ новой норме. Выполните ВОЗВРАТ или СПИСАНИЕ по акту!");

                                resultState.Status = ResultState.ERROR;
                                resultState.setMessage(item.Name + " НЕ СООТВЕТСТВУЕТ новой норме. Выполните ВОЗВРАТ или СПИСАНИЕ по акту!");
                            }
                            else
                            {
                                Storage storageTo = null;
                                //Выбранный склад и склад номенклатуры совпадают
                                if (oldWorkerCardContent.Storage.StorageName.Id == storageNameId)
                                {
                                    storageTo = oldWorkerCardContent.Storage;
                                }
                                //Выбранный склад и склад номенклатуры не совпадают
                                else
                                {
                                    //Пытаемся найти номенклатуру на другом складе
                                    StorageName storageName = storageNameRepository.Get(storageNameId);
                                    if (storageName == null)
                                    {
                                        listResultState.Status = ResultState.ERROR;
                                        listResultState.setMessage("В справочнике не найден склад с идентификатором " + storageNameId + "!");

                                        resultState.Status = ResultState.ERROR;
                                        resultState.setMessage("В справочнике не найден склад с идентификатором " + storageNameId + "!");
                                    }
                                    if (listResultState.Status == ResultState.OK)
                                    {
                                        query.Clear();
                                        query.Add("Nomenclature", oldWorkerCardContent.Storage.Nomenclature);
                                        query.Add("StorageName", storageName);
                                        if (oldWorkerCardContent.Storage.Wear == null)
                                        {
                                            query.Add("[]Wear", "");
                                        }
                                        else
                                        {
                                            query.Add("Wear", oldWorkerCardContent.Storage.Wear);
                                        }
                                        if (oldWorkerCardContent.Storage.Growth == null)
                                        {
                                            query.Add("[]Growth", "");
                                        }
                                        else
                                        {
                                            query.Add("Growth", oldWorkerCardContent.Storage.Growth);
                                        }
                                        if (oldWorkerCardContent.Storage.NomBodyPartSize == null)
                                        {
                                            query.Add("[]NomBodyPartSize", "");
                                        }
                                        else
                                        {
                                            query.Add("NomBodyPartSize", oldWorkerCardContent.Storage.NomBodyPartSize);
                                        }
                                        IList <Storage> storages = storageRepository.GetByLikeCriteria(query);
                                        if (storages.Count > 0)
                                        {
                                            storageTo = storages[0];
                                        }
                                        else
                                        {
                                            //На новом складе не нашлась номенклатура
                                            storageTo                 = new Storage();
                                            storageTo.StorageName     = storageName;
                                            storageTo.Nomenclature    = oldWorkerCardContent.Storage.Nomenclature;
                                            storageTo.Quantity        = 0;
                                            storageTo.Price           = oldWorkerCardContent.Storage.Price;
                                            storageTo.Growth          = oldWorkerCardContent.Storage.Growth;
                                            storageTo.NomBodyPartSize = oldWorkerCardContent.Storage.NomBodyPartSize;
                                            storageTo.Wear            = oldWorkerCardContent.Storage.Wear;
                                            storageRepository.SaveOrUpdate(storageTo);
                                        }
                                    }
                                }
//                            if (resultState.Status == ResultState.OK)
                                if (listResultState.Status == ResultState.OK)

                                {
                                    //Создаем операцию на перевод по старому месту работы
                                    Operation oldOperation = new Operation();
                                    oldOperation.WorkerWorkplace = oldWorkerCardContent.WorkerCardHead.WorkerWorkplace;
                                    oldOperation.OperDate        = operDate; //DateTime.Now;
                                    oldOperation.Quantity        = oldWorkerCardContent.Quantity;
                                    oldOperation.OperType        = operTypeRepository.Get(DataGlobals.OPERATION_STORAGE_TRANSFER_OUT);
                                    oldOperation.Organization    = organizationRepository.Get(int.Parse(getCurrentEnterpriseId()));
                                    oldOperation.DocNumber       = docNumber;
                                    oldOperation.GiveOperation   = oldWorkerCardContent.GiveOperation;
                                    //oldOperation.DocDate=
                                    query.Clear();
                                    query.Add("OperType", oldOperation.OperType);
                                    IList <Motiv> motivs = motivRepository.GetByLikeCriteria(query);
                                    if (motivs.Count > 0)
                                    {
                                        oldOperation.Motiv = motivs[0];
                                    }
                                    oldOperation.Storage = oldWorkerCardContent.Storage;

                                    //Создаем операцию на перевод по новому месту работы
                                    Operation newOperation = new Operation();
                                    newOperation.WorkerWorkplace = ww;
                                    newOperation.OperDate        = operDate; //DateTime.Now;
                                    newOperation.Quantity        = oldWorkerCardContent.Quantity;
                                    newOperation.OperType        = operTypeRepository.Get(DataGlobals.OPERATION_STORAGE_TRANSFER_IN);
                                    newOperation.Organization    = organizationRepository.Get(int.Parse(getCurrentEnterpriseId()));
                                    newOperation.DocNumber       = docNumber;
                                    newOperation.GiveOperation   = oldWorkerCardContent.GiveOperation;
                                    //newOperation.DocDate=

                                    motivs.Clear();
                                    query.Clear();
                                    query.Add("OperType", newOperation.OperType);
                                    motivs = motivRepository.GetByLikeCriteria(query);
                                    if (motivs.Count > 0)
                                    {
                                        newOperation.Motiv = motivs[0];
                                    }
                                    newOperation.Storage = storageTo;

                                    newOperation.TransferOperation = oldOperation;
                                    oldOperation.TransferOperation = newOperation;

                                    operationRepository.SaveOrUpdate(oldOperation);
                                    operationRepository.SaveOrUpdate(newOperation);
                                    //Создаем новую карточку
                                    WorkerCardContent newWorkerCardContent = new WorkerCardContent();
                                    newWorkerCardContent.WorkerCardHead = newWorkerCardHead;
                                    newWorkerCardContent.Storage        = storageTo;
                                    newWorkerCardContent.Quantity       = oldWorkerCardContent.Quantity;
                                    newWorkerCardContent.Operation      = newOperation;
                                    newWorkerCardContent.StartDate      = oldWorkerCardContent.StartDate;
                                    newWorkerCardContent.UsePeriod      = oldWorkerCardContent.UsePeriod;
                                    newWorkerCardContent.GiveOperation  = oldWorkerCardContent.GiveOperation;

                                    //Проставляем новую норму!!!
                                    newWorkerCardContent.NormaContent = newNormaContent;
                                    //Обнуляем старую карточку
                                    oldWorkerCardContent.Quantity   = 0;
                                    oldWorkerCardContent.EndDate    = operDate; //DateTime.Now;
                                    oldWorkerCardContent.OperReturn = oldOperation;
                                    //Сохраняем новую и старую карточки
                                    workerCardContentRepository.SaveOrUpdate(oldWorkerCardContent);
                                    workerCardContentRepository.SaveOrUpdate(newWorkerCardContent);
                                }
                            }

                            skladId = oldWorkerCardContent.Storage.StorageName.Id;
                        }
                    }
                }
                else
                {
                    //У человека несколько активных рабочих мест или рабочее место не найдено
                    resultState.Status = ResultState.ERROR;
                    resultState.setMessage("У человека больше одного рабочего места или рабочее место не найдено!");
                }
            }
            return(Json(resultState));
        }
Example #21
0
//        public ActionResult Update(string id)
        //public ActionResult Update(WorkerNorma workerNorma)
        public ActionResult Update([Bind(Prefix = "updated")] IEnumerable <WorkerNorma> workerNormas)
        {
            //int workerWorkplaceId = (int)HttpContext.Cache.Get("workerWorkplaceId");
            int workerWorkplaceId = (int)Session["workerWorkplaceId"];

            if (workerNormas != null)
            {
                int i = -1;
                foreach (var workerNorma in workerNormas)
                {
                    i++;
                    if (workerNorma.PutQuantity <= 0)
                    {
                        continue;
                    }
                    Dictionary <string, object> query = new Dictionary <string, object>();
                    query.Add("Id", workerWorkplaceId);
                    WorkerWorkplace workerWorkplace = workerWorkplaceRepository.Get(workerWorkplaceId);

                    //TryUpdateModel(workerNorma);

                    //WorkerCard workerCard = workerNorma.WorkerCard;
                    //WorkerCard workerCard = new WorkerCard();
                    query.Clear();
                    query.Add("WorkerWorkplace", workerWorkplace);

                    WorkerCardHead    workerCardHead    = workerCardRepository.FindOne(query);
                    WorkerCardContent workerCardContent = new WorkerCardContent();
                    if (workerCardHead == null)
                    {
                        workerCardHead = new WorkerCardHead();
                        workerCardHead.WorkerCardContents = new List <WorkerCardContent>();
                        workerCardHead.WorkerWorkplace    = workerWorkplace;
                    }

                    workerCardContent.Quantity = workerNorma.PutQuantity;
                    //workerCardContent.Storage = workerNorma.WorkerCardContent.Storage;
                    if (workerNorma.StorageId == 0)
                    {
                        ModelState.AddModelError("updated[" + i + "].StorageName", "Выберите номенклатуру");
                    }
                    else
                    {
                        workerCardContent.Storage        = storageRepository.Get(workerNorma.StorageId);
                        workerCardContent.WorkerCardHead = workerCardHead;

                        if (workerCardContent.Storage.Quantity - workerNorma.PutQuantity < 0)
                        {
                            ModelState.AddModelError("updated[" + i + "].StorageName", "На складе недостаточно кол-ва");
                        }

                        if (workerNorma.PresentQuantity + workerNorma.PutQuantity > workerNorma.NormaQuantity)
                        {
                            ModelState.AddModelError("updated[" + i + "].StorageName", "На руках есть номенклатура у которой не истек срок");
                        }
                    }

                    if (ModelState.IsValid)
                    {
                        //replaceIfExist(workerCardHead.WorkerCardContents, workerCardContent, workerNorma);

                        Operation oper = new Operation();
                        oper.OperDate               = DateTime.Now;
                        oper.OperType               = operTypeRepository.Get(DataGlobals.OPERATION_WORKER_IN);
                        oper.Organization           = organizationRepository.Get(workerWorkplace.RootOrganization);
                        oper.Quantity               = workerCardContent.Quantity;
                        oper.Storage                = workerCardContent.Storage;
                        workerCardContent.Operation = oper;
                        oper.Storage.Quantity      -= oper.Quantity;
                        oper.WorkerWorkplace        = workerWorkplace;

                        operationRepository.SaveOrUpdate(oper);
                        workerCardRepository.SaveOrUpdate(workerCardHead);
                    }
                }
            }
            return(Select(workerWorkplaceId));
        }
Example #22
0
 public static WorkerWorkplace rebuildWorkerWorkplaceSimple(WorkerWorkplace inWorkerWorkplace)
 {
     return(rebuildWorkerWorkplaceSimple(inWorkerWorkplace, null));
 }
Example #23
0
//        public ActionResult Update(string id)
        //public ActionResult Update(WorkerNorma workerNorma)
        public ActionResult Update([Bind(Prefix = "updated")] IEnumerable <WorkerNorma> workerNormas)
        {
            //int workerWorkplaceId = (int)HttpContext.Cache.Get("workerWorkplaceId");
            int      workerWorkplaceId = (int)Session["workerWorkplaceId"];
            string   docNumber         = null;
            DateTime?docDate           = null;
            OperType operType          = null;
            DateTime?operDate          = null;
            Motiv    motiv             = null;
            Cause    cause             = null;


            Dictionary <string, object> query = new Dictionary <string, object>();

            query.Add("Id", workerWorkplaceId);
            WorkerWorkplace workerWorkplace = workerWorkplaceRepository.Get(workerWorkplaceId);

            query.Clear();
            query.Add("WorkerWorkplace", workerWorkplace);

            WorkerCardHead workerCardHead = workerCardRepository.FindOne(query);

            if (workerNormas != null)
            {
                int i = -1;
                foreach (var workerNorma in workerNormas)
                {
                    i++;
                    if (i == 0)
                    {
                        docNumber = workerNorma.DocNumber;
                        //DateTime docDate = DateTime.ParseExact(workerNorma.DocDate, DataGlobals.DATE_FORMAT, null);
                        docDate  = workerNorma.DocDate;
                        operType = operTypeRepository.Get(workerNorma.OperTypeId);
                        motiv    = motivRepository.Get(workerNorma.MotivId);
                        query.Clear();
                        query.Add("Id", workerNorma.CauseId);

                        cause = causeRepository.FindOne(query);

                        operDate = workerNorma.DocDate;

                        if (DateTime.Today > operDate)
                        {
                            operDate = operDate.Value.AddHours(21).AddMinutes(0).AddSeconds(0);
                        }
                        else
                        {
                            operDate = operDate.Value.AddHours(DateTime.Now.Hour).AddMinutes(DateTime.Now.Minute).AddSeconds(DateTime.Now.Second);
                        }
                    }

                    if (workerNorma.PutQuantity <= 0)
                    {
                        continue;
                    }

                    WorkerCardContent workerCardContentPresent = getWorkerCard(workerNorma.Id, workerCardHead);

                    if (workerNorma.PutQuantity <= 0)
                    {
                        ModelState.AddModelError(workerCardContentPresent.Storage.Nomenclature.Name, "Списать можно кол-во больше 0");
                    }

                    if (workerNorma.PutQuantity > workerCardContentPresent.Quantity)
                    {
                        ModelState.AddModelError(workerCardContentPresent.Storage.Nomenclature.Name, "Списать можно не больше чем есть на руках");
                    }


                    if (string.IsNullOrEmpty(docNumber) || docDate == null)
                    {
                        ModelState.AddModelError("updated[" + i + "].StorageName", "Номер и дата документа должны быть заполнены");
                    }

                    string   periodDateStr  = getConfigParamValue(configRepository, "periodDate", getCurrentEnterpriseId());
                    string   periodIsClosed = getConfigParamValue(configRepository, "periodIsClosed", getCurrentEnterpriseId());
                    DateTime periodDate;
                    DateTime.TryParseExact(periodDateStr, DataGlobals.DATE_FORMAT_FULL_YEAR, null, System.Globalization.DateTimeStyles.None, out periodDate);
                    // проверка на закрытие периода
                    if (periodIsClosed != null && periodIsClosed.Equals("1") && periodDate > operDate)
                    {
                        ModelState.AddModelError(operDate + ": ", "Период закрыт для изменений");
                    }
                }

                if (ModelState.IsValid)
                {
                    foreach (var workerNorma in workerNormas)
                    {
                        if (workerNorma.PutQuantity <= 0)
                        {
                            continue;
                        }

                        WorkerCardContent workerCardContentPresent = getWorkerCard(workerNorma.Id, workerCardHead);

                        Operation oper = new Operation();
                        oper.OperDate        = operDate.Value;
                        oper.OperType        = operTypeRepository.Get(DataGlobals.OPERATION_WORKER_OUT);
                        oper.Organization    = organizationRepository.Get(workerWorkplace.RootOrganization);
                        oper.Quantity        = workerNorma.PutQuantity;
                        oper.Storage         = workerCardContentPresent.Storage;
                        oper.DocNumber       = docNumber;
                        oper.DocDate         = docDate.Value;
                        oper.WorkerWorkplace = workerWorkplace;
                        oper.Motiv           = motiv;
                        oper.Cause           = cause;
                        oper.OperType        = operType;
                        oper.GiveOperation   = workerCardContentPresent.GiveOperation;

                        //workerCardContentPresent.Operation = oper;
                        //workerCardContentPresent.Quantity -= oper.Quantity;
                        if (workerNorma.PutQuantity == workerCardContentPresent.Quantity)
                        {
                            workerCardHead.WorkerCardContents.Remove(workerCardContentPresent);
                        }
//Теперь позиции на карточки не удаляем
//                        workerCardContentRepository.Delete(workerCardContentPresent);

                        operationRepository.SaveOrUpdate(oper);
                        if (workerNorma.PutQuantity == workerCardContentPresent.Quantity)
                        {
                            workerCardContentPresent.OperReturn = oper;
                            workerCardContentPresent.Quantity   = 0;
                            workerCardContentPresent.EndDate    = oper.OperDate;
                        }
                        else
                        {
                            workerCardContentPresent.Quantity = workerCardContentPresent.Quantity - workerNorma.PutQuantity;
                            WorkerCardContent wcc = new WorkerCardContent();
                            wcc.Quantity       = 0;
                            wcc.StartDate      = workerCardContentPresent.StartDate;
                            wcc.EndDate        = operDate.Value;
                            wcc.WorkerCardHead = workerCardContentPresent.WorkerCardHead;
                            wcc.Storage        = workerCardContentPresent.Storage;
                            wcc.Operation      = workerCardContentPresent.Operation;
                            wcc.OperReturn     = oper;
                            wcc.NormaContent   = workerCardContentPresent.NormaContent;
                            wcc.GiveOperation  = workerCardContentPresent.GiveOperation;
                            workerCardContentRepository.SaveOrUpdate(wcc);
                        }
                        workerCardContentRepository.SaveOrUpdate(workerCardContentPresent);

                        //workerCardRepository.SaveOrUpdate(workerCardHead);
                    }
                }
            }
            return(Select(workerWorkplaceId, (string)Session["workerWorkplaceText"]));
        }