private ActionResult CreateCustomerSupplier(PapiroMVC.Models.CustomerSupplier c)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    //if code is empty then sistem has to assign one
                    if (c.CodCustomerSupplier == null)
                    {
                        c.CodCustomerSupplier = customerSupplierRepository.GetNewCode(c);
                    }

                    c.TimeStampTable = DateTime.Now;
                    
                    customerSupplierRepository.Add(c);
                    customerSupplierRepository.Save();

                    TempData["CreateCustomerSupplier"] = true;
                    return Json(new { redirectUrl = Url.Action("IndexBase", new { id = c.CodCustomerSupplier })});
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError(string.Empty, "Something went wrong. Message: " + ex.Message);
                }
            }
            if (c.TypeOfCustomerSupplier == PapiroMVC.Models.CustomerSupplier.CustomerSupplierType.Customer)
                return PartialView("_EditAndCreateCustomer", c);
            else
                return PartialView("_EditAndCreateSupplier", c);
        }
Esempio n. 2
0
        public ActionResult EditOrder(PapiroMVC.Models.Order c)
        {
            var taskList = this.typeOfTaskRepository.GetAll();
            ((Order)c).ReportOrderNames = documentRepository.GetAllReportOrderName(CurrentDatabase);

            if (ModelState.IsValid)
            {
                try
                {

                    Console.Write(c.DocumentStates);

                    documentRepository.Edit(c);
                    //rigeneration name of article
                    //c.OrderSingleSheet.OrderName = c.OrderSingleSheet.ToString();
                    documentRepository.Save();
                    return Json(new { redirectUrl = Url.Action("ListOrder") });
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError(string.Empty, "Something went wrong. Message: " + ex.Message);
                }
            }

            //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 = "EditOrder";
            return PartialView("_EditAndCreateOrder", c);
        }
Esempio n. 3
0
        // Create an invoice for a factitious company called "The Happy Builder".
        private DocX CompileFromTemplate(DocX template, PapiroMVC.Models.Document d)
        {

            //customer
            var customer = customerSupplierRepository.GetSingle(d.CodCustomer);
            customer = customer ?? new Customer();

            var cbase = customer.CustomerSupplierBases.Where(x => x.TypeOfBase.CodTypeOfBase == "0001").FirstOrDefault();

            //se non c'è una sede
            cbase = cbase ?? new CustomerSupplierBase();

            #region Set CustomProperty values
            // Set the value of the custom property 'company_name'.
            template.AddCustomProperty(new Novacode.CustomProperty("company_name", customer.BusinessName));

            // Set the value of the custom property 'company_slogan'.
            template.AddCustomProperty(new Novacode.CustomProperty("company_slogan", ""));

            // Set the value of the custom properties 'hired_company_address_line_one', 'hired_company_address_line_two' and 'hired_company_address_line_three'.
            template.AddCustomProperty(new Novacode.CustomProperty("hired_company_address_line_one", cbase.Address ?? ""));
            template.AddCustomProperty(new Novacode.CustomProperty("hired_company_address_line_two", (cbase.PostalCode ?? "") + " " + (cbase.City ?? "") + " " + (cbase.Province ?? "")));
            template.AddCustomProperty(new Novacode.CustomProperty("hired_company_address_line_three", (cbase.Phone ?? "")));

            // Set the value of the custom property 'invoice_date'.
            template.AddCustomProperty(new Novacode.CustomProperty("invoice_date", d.DateDocument.Value.ToString("d")));

            // Set the value of the custom property 'invoice_number'.
            template.AddCustomProperty(new Novacode.CustomProperty("invoice_number", d.Number.ToString()));

            // Set the value of the custom property 'hired_company_details_line_one' and 'hired_company_details_line_two'.
            template.AddCustomProperty(new Novacode.CustomProperty("hired_company_details_line_one", "Business Street, Dublin, 12345"));
            template.AddCustomProperty(new Novacode.CustomProperty("hired_company_details_line_two", "Phone: 012-345-6789, Fax: 012-345-6789, e-mail: [email protected]"));
            #endregion


            /* 
             * InvoiceTemplate.docx contains a blank Table, 
             * we want to replace this with a new Table that
             * contains all of our invoice data.
             */
            Novacode.Table t = template.Tables[1];
            Novacode.Table invoice_table = CreateAndInsertInvoiceTableAfter(t, ref template, d);
            t.Remove();

            // Return the template now that it has been modified to hold all of our custom data.
            return template;
        }
Esempio n. 4
0
        private static Novacode.Table CreateAndInsertInvoiceTableAfter(Novacode.Table t, ref DocX document, PapiroMVC.Models.Document d)
        {

            var docProd = d.DocumentProducts.Select(x => x.CodProduct).Distinct();

            /* 
             * The trick to replacing one Table with another,
             * is to insert the new Table after the old one, 
             * and then remove the old one.
             */
            Novacode.Table invoice_table = t.InsertTableAfterSelf(d.DocumentProducts.Count + 1, 4);
            invoice_table.Design = TableDesign.LightShadingAccent1;

            #region Table title
            Formatting table_title = new Formatting();
            table_title.Bold = true;


            Type res = typeof(PapiroMVC.Models.Resources.Document.ResDocumentProduct);


            invoice_table.Rows[0].Cells[0].Paragraphs[0].InsertText(
                (string)res.GetProperty("Product").GetValue(null, null), false, table_title);
            invoice_table.Rows[0].Cells[0].Paragraphs[0].Alignment = Alignment.left;

            invoice_table.Rows[0].Cells[1].Paragraphs[0].InsertText(
                (string)res.GetProperty("Quantity").GetValue(null, null), false, table_title);
            invoice_table.Rows[0].Cells[1].Paragraphs[0].Alignment = Alignment.right;

            invoice_table.Rows[0].Cells[2].Paragraphs[0].InsertText(
                (string)res.GetProperty("UnitPrice").GetValue(null, null), false, table_title);
            invoice_table.Rows[0].Cells[2].Paragraphs[0].Alignment = Alignment.right;

            invoice_table.Rows[0].Cells[3].Paragraphs[0].InsertText(
                (string)res.GetProperty("TotalAmount").GetValue(null, null), false, table_title);
            invoice_table.Rows[0].Cells[3].Paragraphs[0].Alignment = Alignment.right;

            #endregion

            // Loop through the rows in the Table and insert data from the data source.
            for (int row = 1; row < invoice_table.RowCount; )
            {
                Novacode.Paragraph cell_paragraph;

                foreach (var dp in docProd)
                {
                    var sel = d.DocumentProducts.Where(y => y.CodProduct == dp).OrderBy(z => z.Quantity);
                    var k = 0;
                    foreach (var item in sel)
                    {
                        cell_paragraph = invoice_table.Rows[row].Cells[0].Paragraphs[0];
                        cell_paragraph.InsertText(k++ == 0 ? item.ProductName : "", false);
                        invoice_table.Rows[row].Cells[0].Paragraphs[0].Alignment = Alignment.left;

                        cell_paragraph = invoice_table.Rows[row].Cells[1].Paragraphs[0];
                        cell_paragraph.InsertText(item.Quantity.ToString(), false);
                        invoice_table.Rows[row].Cells[1].Paragraphs[0].Alignment = Alignment.right;

                        cell_paragraph = invoice_table.Rows[row].Cells[2].Paragraphs[0];
                        cell_paragraph.InsertText(item.UnitPrice, false);
                        invoice_table.Rows[row].Cells[2].Paragraphs[0].Alignment = Alignment.right;

                        cell_paragraph = invoice_table.Rows[row].Cells[3].Paragraphs[0];
                        cell_paragraph.InsertText(item.TotalAmount, false);
                        invoice_table.Rows[row].Cells[3].Paragraphs[0].Alignment = Alignment.right;

                        row++;
                    }
                }

            }


            invoice_table.InsertRow();

            // Let the tables coloumns expand to fit its contents.
            invoice_table.AutoFit = AutoFit.Contents;

            // Center the Table
            invoice_table.Alignment = Alignment.center;

            //Return the invloce table now that it has been created.
            return invoice_table;
        }
Esempio n. 5
0
        public ActionResult EditDocument(PapiroMVC.Models.Document c)
        {
            var taskList = this.typeOfTaskRepository.GetAll();

            if (ModelState.IsValid)
            {
                try
                {
                    documentRepository.Edit(c);
                    //rigeneration name of article
                    //c.DocumentSingleSheet.DocumentName = c.DocumentSingleSheet.ToString();
                    documentRepository.Save();
                    return Json(new { redirectUrl = Url.Action("Index") });
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError(string.Empty, "Something went wrong. Message: " + ex.Message);
                }
            }

            //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 = "EditDocument";
            return PartialView("_EditAndCreateDocument", c);
        }