Beispiel #1
0
        public virtual void Copy(DocumentProduct to)
        {

            to.TimeStampTable = this.TimeStampTable;
            to.CodDocumentProduct = this.CodDocumentProduct;
            to.CodDocument = this.CodDocument;
            to.ProductName = this.ProductName;
            to.CodProduct = this.CodProduct;
            to.Quantity = this.Quantity;
            to.UnitPrice = this.UnitPrice;
            to.TotalAmount = this.TotalAmount;

            to.Document = this.Document;
            to.Product = this.Product;

            List<CostDetail> cds = new List<CostDetail>();
            foreach (var cost in Costs)
            {
                var c = (Cost)cost.Clone();
                to.Costs.Add(c);

                foreach (var cd in c.CostDetails)
                {
                    cds.Add(cd);
                }
            }


            //foreach (var cd in cds)
            //{
            //    if (cd.CodComputedBy != "" && cd.CodComputedBy != null)
            //    {
            //        var c1 = cds.FirstOrDefault(x => x.CodCostDetail == cd.CodComputedBy);
            //        if (c1.Computes == null)
            //            c1.Computes = new HashSet<CostDetail>();
            //        c1.Computes.Add(cd);
            //        cd.ComputedBy=c1;
            //    }
            //}

            //CostDetail has two propery-> computed by and computes
            //         virtual ICollection<Cost> Costs 

        }
Beispiel #2
0
        public void NewProductJustDocument()
        {
            var inizio = DateTime.Now;

            IDocumentRepository docRep = new DocumentRepository();
            IProductRepository prodRep = new ProductRepository();

            PapiroService p = new PapiroService();
            p.DocumentRepository = docRep;
            p.CostDetailRepository = new CostDetailRepository();
            p.TaskExecutorRepository = new TaskExecutorRepository();
            p.ArticleRepository = new ArticleRepository();

            Document doc = docRep.GetEstimateEcommerce("000001");
            doc.EstimateNumber = "0";

            //work with product
            Product prod = p.InitProduct("EtichetteRotolo", new ProductTaskNameRepository(), new FormatsNameRepository(), new TypeOfTaskRepository());

            //------passaggio del prodotto inizializzato all'ecommerce o alla view
            prod.CodProduct = prodRep.GetNewCode(prod);
            prod.ProductParts.FirstOrDefault().Format = "15x21";
            prod.ProductParts.FirstOrDefault().SubjectNumber = 1;

            var art = prod.ProductParts.FirstOrDefault().ProductPartPrintableArticles.FirstOrDefault();

            #region Printable Article

            IArticleRepository artRep = new ArticleRepository();
            var artFormList = artRep.GetAll().OfType<RigidPrintableArticle>().FirstOrDefault();

            art.TypeOfMaterial = artFormList.TypeOfMaterial;
            art.NameOfMaterial = artFormList.NameOfMaterial;
            art.Weight = artFormList.Weight;
            art.Color = artFormList.Color;
            #endregion

            //------ritorno del prodotto modificato!!!!

            //rigenero
            prodRep.Add(prod);
            prodRep.Save();

            #region ViewModel
            ProductViewModel pv = new ProductViewModel();
            pv.Product = prod;
            //            prod.ProductCodeRigen();

            pv.Quantity=1000;
            #endregion

            DocumentProduct dp = new DocumentProduct();
            dp.Document = null;
            dp.CodProduct = pv.Product.CodProduct;
            dp.Product = pv.Product;
            dp.Quantity = pv.Quantity;

            dp.InitCost();

            doc.DocumentProducts.Add(dp);

            docRep.Edit(doc);
            docRep.Save();

            var step = DateTime.Now;

            p.EditOrCreateAllCost(dp.CodDocumentProduct);

            var fine = DateTime.Now.Subtract(inizio).TotalSeconds;

            Assert.IsTrue(fine < 4);
        }
Beispiel #3
0
        public ActionResult CreateProduct(ProductViewModel pv)
        {
            bool doControl = true;

            // var qts = pv.Quantities;
            var product = pv.Product;

            foreach (var item in product.ProductParts)
            {
                if (item.Format == "0x0" && item.FormatPersonalized != String.Empty)
                {
                    item.Format = item.FormatPersonalized;
                }
                if (item.Format == "0x0")
                {
                    item.Format = String.Empty;
                }

                if (item.TypeOfProductPart == ProductPart.ProductPartType.ProductPartDoubleLabelRoll)
                {
                    doControl = false;
                }

            }

            //CHECK IF EACH PRINTABLE ARTICLE IS IN LIST
            foreach (var item in product.ProductParts)
            {
                foreach (var pArticle in item.ProductPartPrintableArticles)
                {
                    if (!pArticle.IsInList(articleRepository.GetAll()))
                    {
                        ModelState.AddModelError("PersError", "ProductPartPrintableArticleListError");
                    }
                }
            }

            var ok = true;

            var taskList = typeOfTaskRepository.GetAll().ToList();
            var productParts = pv.Product.ProductParts;
            foreach (var pPart in productParts)
            {
                //per tutte le lavorazioni voglio controllare che esista almeno una macchina e almeno il formato giusto
                var lstTask = pPart.ProductPartTasks.Where(x => !x.CodOptionTypeOfTask.Contains("_NO"));
                var lstTaskExecutor = taskExecuteRepository.GetAll().ToList();


                foreach (var item in lstTask)
                {
                    var t = taskList.FirstOrDefault(y => y.OptionTypeOfTasks.Where(x => x.CodOptionTypeOfTask == item.CodOptionTypeOfTask).Count() > 0);
                    var s = TaskExecutor.FilterByTask(lstTaskExecutor.AsQueryable(), t.CodTypeOfTask);
                    Console.WriteLine(s);

                    //controllo se esiste una macchina
                    ok = ok && (s.Count() > 0);

                    foreach (var tsk in s)
                    {
                        ok = ok || SheetCut.IsValidOnMax(tsk.FormatMax, tsk.FormatMin, pPart.Format);
                    }

                    if (t.CodTypeOfTask.StartsWith("STAMPA"))
                    {
                        Console.WriteLine("");
                    }
                }


                if (!ok && doControl)
                {
                    ModelState.AddModelError("PersError", "FormatOrTaskExecutorError");
                }

            }

            //END CHECK
            if (ModelState.IsValid)
            {
                //               try
                {
                    //il cliente
                    var cust = customerSupplierRepository.GetAll().OfType<Customer>().Where(x => x.BusinessName == pv.Customer).FirstOrDefault();
                    if (cust == null)
                    {
                        cust = new Customer();
                        cust.CodCustomerSupplier = customerSupplierRepository.GetNewCode(cust);
                        cust.BusinessName = pv.Customer;
                        cust.VatNumber = "00000000000";
                        customerSupplierRepository.Add(cust);
                        customerSupplierRepository.Save();
                    }

                    product.ProductRefName = pv.ProductRefName;
                    product.CodProduct = productRepository.GetNewCode(product);

                    product.CheckConsistency();
                    //save the product
                    productRepository.Add(product);
                    productRepository.Save();

                    documentRepository.SetDbName("");
                    documentRepository.SetDbName(CurrentDatabase);

                    //se ho un documento attivo in sessione salvo anche la relazione
                    //oppure se non c'è un domcumento attivo lo creo e salvo la relazione
                    //dopodiche devo saltare al documento oppure alla view model del prodottodocumento
                    if (Session["CodDocument"] == null || documentRepository.GetSingle((string)Session["CodDocument"]) == null)
                    {
                        var d = new Document();
                        d.CodDocument = documentRepository.GetNewCode(d);
                        Session["CodDocument"] = d.CodDocument;
                        documentRepository.Add(d);
                        documentRepository.Save();
                    }

                    var document = documentRepository.GetSingle((string)Session["CodDocument"]);
                    document.DocumentName = pv.DocumentName;
                    document.CustomerSupplier = cust;
                    document.Customer = cust.BusinessName;
                    document.CodCustomer = cust.CodCustomerSupplier;

                    documentRepository.Edit(document);
                    documentRepository.Save();

                    DocumentProduct dp;
                    DocumentProduct firstDocumentProduct = null;


                    if (pv.Quantity != 0)
                    {
                        dp = new DocumentProduct();
                        //use first document product to lead each tecnical choice
                        if (firstDocumentProduct == null)
                        {
                            firstDocumentProduct = dp;
                        }
                        dp.Document = null;
                        dp.CodProduct = pv.Product.CodProduct;
                        dp.Product = pv.Product;

                        dp.Quantity = pv.Quantity;

                        dp.InitCost();
                        document.DocumentProducts.Add(dp);

                        documentRepository.Edit(document);
                        documentRepository.Save();

                    }

                    //OK questo funziona ma riporta alla lista dei costi
                    //TODO: Sending singlaR notification to client to reload basket product
                    //return Json(new { redirectUrl = Url.Action("EditDocumentProducts", "Document", new { id = document.DocumentProducts.LastOrDefault().CodProduct }) });

                    if (firstDocumentProduct.Costs.FirstOrDefault() != null)
                    {
                        Session["codProduct"] = document.DocumentProducts.LastOrDefault().CodProduct;

                        return Json(new { redirectUrl = Url.Action("EditAndCreateAllCost", "Document", new { id = firstDocumentProduct.Costs.FirstOrDefault().CodDocumentProduct }) });
                        //   return Json(new { redirectUrl = Url.Action("EditCost", "Document", new { id = firstDocumentProduct.Costs.FirstOrDefault().CodCost }) });
                    }
                    else
                    {
                        return Json(new { redirectUrl = Url.Action("EditDocumentProducts", "Document", new { id = document.DocumentProducts.LastOrDefault().CodProduct }) });
                    }

                }
                //                catch (Exception ex)
                //{
                //    ModelState.AddModelError(string.Empty, "Something went wrong. Message: " + ex.Message);
                //}
            }


            //Carico i nomi dei formati perchè se la validazione non va a buon fine devo ripresentarli
            product.FormatsName = formatsRepository.GetAllById(product.CodMenuProduct);
            product.SystemTaskList = typeOfTaskRepository.GetAll().ToList();

            //reload option object for productTask and productPartTask
            //            var taskList = this.typeOfTaskRepository.GetAll();
            foreach (var item in product.ProductTasks)
            {
                item.OptionTypeOfTask = typeOfTaskRepository.GetSingleOptionTypeOfTask(item.CodOptionTypeOfTask);
            }


            foreach (var item in product.ProductParts)
            {
                foreach (var item2 in item.ProductPartTasks)
                {
                    item2.OptionTypeOfTask = typeOfTaskRepository.GetSingleOptionTypeOfTask(item2.CodOptionTypeOfTask);
                }

            }
            //-----end reloding
            //????


            //view name is needed for reach right view because to using more than one submit we have to use "Action" in action method name
            ViewBag.ActionMethod = "CreateProduct";
            return PartialView("_EditAndCreateProduct", pv);
        }
Beispiel #4
0
        public HttpResponseMessage Test(
            string username,
            string nCom,
            string nPrev,
            string desc,
            string field1,
            string field2,
            string field3,
            string quantity,
            string price)
        {

            this.Init();

            taskCenterRepository.SetDbName(username);
            productRepository.SetDbName(username);
            documentRepository.SetDbName(username);

            //cerco il prodotto ---> se c'è ok
            //altrimenti lo creo come generico!!!

            //cerco la commessa ---> se c'è ok
            //altrimenti la creo

            var prod = productRepository.GetAll().Where(x => x.PapiroPrev == nPrev).FirstOrDefault();

            if (prod == null)
            {
                prod = new ProductEmpty();
                prod.CodProduct = productRepository.GetNewCode(prod);
                prod.CodMenuProduct = "Vuoto";
                prod.PapiroPrev = nPrev;
                prod.ProductName = desc;

                productRepository.Add(prod);
                productRepository.Save();
            }

            var docProd = documentRepository.GetAllDocumentProducts().Where(x => x.CodProduct == prod.CodProduct).FirstOrDefault();

            if (docProd == null)
            {
                docProd = new DocumentProduct();
                docProd.CodProduct = prod.CodProduct;
                docProd.UnitPrice = "0";//Convert.ToDouble(price).ToString();
                docProd.Quantity = 0; // Convert.ToInt16(quantity);

                Estimate e = new Estimate();
                e.CodDocument = documentRepository.GetNewCode(e);
                e.EstimateNumberSerie = DateTime.Now.Year.ToString();
                e.EstimateNumber = documentRepository.GetNewEstimateNumber(e);

                //var docProd = documentRepository.GetDocumentProductByCodDocumentProduct(codDocumentProduct);
                e.DocumentProducts.Add(docProd);

                documentRepository.Add(e);
                documentRepository.Save();

                docProd.Product = prod;
            }


            var c = (Order)documentRepository.GetAll().Where(x => x.PapiroCom == nCom).FirstOrDefault();

            if (c == null)
            {
                c = new Order();
                c.CodDocument = documentRepository.GetNewCode(c);
                c.OrderNumberSerie = DateTime.Now.Year.ToString();
                c.OrderNumber = documentRepository.GetNewOrderNumber(c);
                c.PapiroCom = nCom;

                c.OrderProduct = docProd;
                //c.CodCustomer = docProd.Document.CodCustomer;
                //c.Customer = docProd.Document.Customer;

                c.DateDocument = DateTime.Now;

                var allStates = documentRepository.GetAllStates().Where(x => (x.UseInOrder ?? false)).OrderBy(x => x.StateNumber);

                foreach (var s in allStates)
                {
                    c.DocumentStates.Add(new DocumentState
                    {
                        CodDocument = c.CodDocument,
                        StateNumber = s.StateNumber,
                        CodState = s.CodState,
                        //                    StateName = s.StateName, //derivated!!!
                        ResetLinkedStates = s.ResetLinkedStates,
                        Selected = false
                    });
                }

                documentRepository.Add(c);
                documentRepository.Save();

                //se ci sono dei TaskCenter inizio a buttare i taskcenter nel primo taskcenter (IndexOf==0)
                var taskCenter = taskCenterRepository.GetAll().Where(y => y.IndexOf == 0).FirstOrDefault();

                if (taskCenter != null)
                {
                    DocumentTaskCenter dtc = new DocumentTaskCenter();
                    dtc.CodTaskCenter = taskCenter.CodTaskCenter;
                    dtc.CodDocument = c.CodDocument;

                    if (docProd.Product.ProductRefName == null)
                    {
                        dtc.DocumentName = docProd.Product.ProductName;
                    }
                    else
                    {
                        dtc.DocumentName = docProd.Product.ProductRefName;
                    }


                    dtc.FieldA = field1;
                    dtc.FieldB = field2;
                    dtc.FieldC = field3;

                    if (username.ToLower() == "lamarina")
                    {
                        try
                        {
                            dtc.DocumentName = nCom.Substring(0,nCom.IndexOf('/')) + " " + dtc.DocumentName + " " + field1;
                        }
                        catch (Exception)
                        {
                        }
                        dtc.FieldA = "";
                    }
                    else
                    {
                        dtc.DocumentName = nCom + " " + dtc.DocumentName;
                    }

                    taskCenterRepository.AddNewDocumentTaskCenter(dtc);
                    taskCenterRepository.Save();
                }

            }

            taskCenterRepository.Dispose();
            productRepository.Dispose();
            documentRepository.Dispose();

            return Request.CreateResponse<string>(HttpStatusCode.OK, username);
        }