Ejemplo n.º 1
0
        private void add_CRM(sales_order order)
        {
            if (order.id_sales_budget == 0 || order.id_sales_budget == null)
            {
                crm_opportunity crm_opportunity = new crm_opportunity();
                crm_opportunity.id_contact  = order.id_contact;
                crm_opportunity.id_currency = order.id_currencyfx;

                crm_opportunity.value = order.sales_order_detail.Sum(x => x.SubTotal_Vat);

                crm_opportunity.sales_order.Add(order);
                base.crm_opportunity.Add(crm_opportunity);
            }
            else
            {
                crm_opportunity crm_opportunity = sales_budget.Where(x => x.id_sales_budget == order.id_sales_budget).FirstOrDefault().crm_opportunity;
                crm_opportunity.sales_order.Add(order);
                base.crm_opportunity.Attach(crm_opportunity);
            }
        }
Ejemplo n.º 2
0
        public sales_order New()
        {
            sales_order sales_order = new sales_order();

            sales_order.State    = EntityState.Added;
            sales_order.id_range = Brillo.GetDefault.Return_RangeID(App.Names.SalesOrder);
            sales_order.status   = Status.Documents_General.Pending;

            security_user security_user = base.security_user.Where(x => x.id_user == sales_order.id_user).FirstOrDefault();

            if (security_user != null)
            {
                sales_order.security_user = security_user;
            }

            sales_order.State      = EntityState.Added;
            sales_order.IsSelected = true;

            return(sales_order);
        }
Ejemplo n.º 3
0
        public void loadSalesOrderReport(int id)
        {
            string path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

            path = path + "\\CogntivoERP";
            string SubFolder = "";

            SubFolder = "\\TemplateFiles";
            ReportDataSource reportDataSource = new ReportDataSource();

            try
            {
                reportDataSource.Name = "DataSet1"; // Name of the DataSet we set in .rdlc
                sales_order sales_order = db.sales_order.Where(x => x.id_sales_order == id).FirstOrDefault();
                List <sales_order_detail> sales_order_detail = db.sales_order_detail.Where(x => x.id_sales_order == sales_order.id_sales_order).ToList();

                reportDataSource.Value = sales_order_detail
                                         .Select(g => new
                {
                    sales_budget_number        = g.sales_order.sales_budget != null ? g.sales_order.sales_budget.number : "",
                    contact_name               = g.sales_order.contact.name,
                    customer_address           = g.sales_order.contact.address,
                    customer_telephone         = g.sales_order.contact.telephone,
                    customer_email             = g.sales_order.contact.email,
                    company_Name               = g.app_company.name,
                    sales_order_terminal       = g.sales_order.app_terminal.name,
                    branch_Name                = g.sales_order.app_branch.name,
                    order_Code                 = g.sales_order.code,
                    delivery_Date              = g.sales_order.delivery_date,
                    sales_number               = g.sales_order.number,
                    order_Total                = g.sales_order.GrandTotal,
                    project_Name               = g.sales_order.project != null ? g.sales_order.project.name : "",
                    sales_order_representative = g.sales_order.sales_rep != null ? g.sales_order.sales_rep.name : "",
                    security_user_name         = g.sales_order.security_user.name,
                    trans_date                 = g.sales_order.trans_date,
                    sales_order_contract       = g.sales_order.app_contract.name,
                    sales_order_condition      = g.sales_order.app_condition.name,
                    DeliveryDate               = g.sales_order.delivery_date,
                    sales_order_Comment        = g.sales_order.comment,
                    item_code        = g.item.code,
                    item_description = g.item.name,
                    item_brand       = g.item.item_brand != null ? g.item.item_brand.name : "",
                    quantity         = g.quantity,
                    sub_Total        = g.SubTotal,
                    sub_Total_vat    = g.SubTotal_Vat,
                    unit_cost        = g.unit_cost,
                    unit_price       = g.unit_price,
                    unit_price_vat   = g.UnitPrice_Vat,
                }).ToList();


                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                    Directory.CreateDirectory(path + SubFolder);
                    File.Copy(AppDomain.CurrentDomain.BaseDirectory + "\\bin\\debug\\Sales_Order.rdlc", path + SubFolder + "\\Sales_Order.rdlc");
                }
                else if (!Directory.Exists(path + SubFolder))
                {
                    Directory.CreateDirectory(path + SubFolder);
                    File.Copy(AppDomain.CurrentDomain.BaseDirectory + "\\bin\\debug\\Sales_Order.rdlc", path + SubFolder + "\\Sales_Order.rdlc");
                }
                else if (!File.Exists(path + SubFolder + "\\Sales_Order.rdlc"))
                {
                    File.Copy(AppDomain.CurrentDomain.BaseDirectory + "\\bin\\debug\\Sales_Order.rdlc", path + SubFolder + "\\Sales_Order.rdlc");
                }



                if (!sales_order.app_document_range.use_default_printer)
                {
                    reportViewer.LocalReport.ReportPath = path + SubFolder + "\\Sales_Order.rdlc"; // Path of the rdlc file
                    reportViewer.LocalReport.DataSources.Add(reportDataSource);
                    reportViewer.RefreshReport();
                    Window window = new Window
                    {
                        Title   = "Report",
                        Content = this
                    };

                    window.ShowDialog();
                }
                else
                {
                    try
                    {
                        if (sales_order.app_document_range.printer_name != null)
                        {
                            LocalReport  report       = new LocalReport();
                            PrintInvoice PrintInvoice = new PrintInvoice();
                            report.ReportPath = path + SubFolder + "\\Sales_Order.rdlc"; // Path of the rdlc file
                            report.DataSources.Add(reportDataSource);
                            PrintInvoice.Export(report);
                            PrintInvoice.Print(sales_order.app_document_range.printer_name);
                        }
                        else
                        {
                            NotSupportedException ex = new NotSupportedException();
                            throw ex;
                        }
                    }
                    catch
                    {
                        reportViewer.LocalReport.ReportPath = path + SubFolder + "\\Sales_Order.rdlc"; // Path of the rdlc file
                        reportViewer.LocalReport.DataSources.Add(reportDataSource);
                        reportViewer.RefreshReport();
                        Window window = new Window
                        {
                            Title   = "Report",
                            Content = this
                        };

                        window.ShowDialog();
                    }
                }
            }
            catch
            {
                reportViewer.LocalReport.ReportPath = path + SubFolder + "\\Sales_Order.rdlc"; // Path of the rdlc file
                reportViewer.LocalReport.DataSources.Add(reportDataSource);
                reportViewer.RefreshReport();
                Window window = new Window
                {
                    Title   = "Report",
                    Content = this
                };

                window.ShowDialog();
            }
        }
Ejemplo n.º 4
0
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            if (project != null)
            {
                toolBar             toolBar          = new cntrl.toolBar();
                List <project_task> project_taskLIST = project.project_task.Where(x => x.IsSelected).ToList();

                sales_order sales_order = new entity.sales_order();
                if (Generate_Budget)
                {
                    SalesBudgetDB SalesBudgetDB = new SalesBudgetDB();

                    sales_budget sales_budget = new entity.sales_budget();

                    sales_budget.id_contact = (int)project.id_contact;
                    sales_budget.contact    = SalesBudgetDB.contacts.Where(x => x.id_contact == (int)project.id_contact).FirstOrDefault();

                    sales_budget.id_project    = project.id_project;
                    sales_budget.id_condition  = (int)cbxCondition.SelectedValue;
                    sales_budget.id_contract   = (int)cbxContract.SelectedValue;
                    sales_budget.id_currencyfx = (int)cbxCurrency.SelectedValue;
                    sales_budget.comment       = "Project -> " + project.name;
                    sales_budget.trans_date    = DateTime.Now;

                    foreach (project_task _project_task in project_taskLIST)
                    {
                        sales_budget_detail sales_budget_detail = new sales_budget_detail();
                        sales_budget_detail.State            = EntityState.Added;
                        sales_budget_detail.id_sales_budget  = sales_budget.id_sales_budget;
                        sales_budget_detail.sales_budget     = sales_budget;
                        sales_budget_detail.id_item          = (int)_project_task.id_item;
                        sales_budget_detail.item_description = _project_task.item_description;

                        if (project.is_Executable)
                        {
                            sales_budget_detail.quantity = (decimal)_project_task.quantity_exe;
                        }
                        else
                        {
                            sales_budget_detail.quantity = (decimal)_project_task.quantity_est;
                        }


                        if (_project_task.unit_price_vat != null)
                        {
                            sales_budget_detail.UnitPrice_Vat = (decimal)_project_task.unit_price_vat;
                        }

                        sales_budget_detail.id_project_task = _project_task.id_project_task;
                        _project_task.IsSelected            = false;

                        sales_budget.sales_budget_detail.Add(sales_budget_detail);
                    }

                    sales_budget.State      = EntityState.Added;
                    sales_budget.IsSelected = true;
                    SalesBudgetDB.sales_budget.Add(sales_budget);
                    SalesBudgetDB.SaveChanges();
                }
                else
                {
                    //if (Generate_Budget)
                    //{
                    //    sales_order.id_sales_budget = sales_budget.id_sales_budget;
                    //}
                    if (SalesOrderDB.contacts.Where(x => x.id_contact == (int)project.id_contact).FirstOrDefault() != null)
                    {
                        sales_order.id_contact = (int)project.id_contact;
                        sales_order.contact    = SalesOrderDB.contacts.Where(x => x.id_contact == (int)project.id_contact).FirstOrDefault();
                    }
                    else
                    {
                        toolBar.msgWarning("Contact Not Found...");
                        return;
                    }

                    if (Generate_Invoice)
                    {
                        if (cbxDocument.SelectedValue != null)
                        {
                            sales_order.id_range = (int)cbxDocument.SelectedValue;
                        }
                        else
                        {
                            toolBar.msgWarning("Document Range Needed for Approval");
                            // return;
                        }
                    }
                    sales_order.id_project = project.id_project;

                    if (Convert.ToInt16(cbxCondition.SelectedValue) > 0)
                    {
                        sales_order.id_condition = (int)cbxCondition.SelectedValue;
                    }
                    else
                    {
                        toolBar.msgWarning("Condition Not Found...");
                        return;
                    }

                    if (Convert.ToInt16(cbxContract.SelectedValue) > 0)
                    {
                        sales_order.id_contract = (int)cbxContract.SelectedValue;
                    }
                    else
                    {
                        toolBar.msgWarning("Contract Not Found...");
                        return;
                    }

                    if (Convert.ToInt16(cbxCurrency.SelectedValue) > 0)
                    {
                        sales_order.id_currencyfx = (int)cbxCurrency.SelectedValue;
                    }
                    else
                    {
                        toolBar.msgWarning("Currency Not Found...");
                        return;
                    }

                    sales_order.comment = "Project -> " + project.name;

                    sales_order_detail sales_order_detail = null;

                    foreach (project_task _project_task in project_taskLIST)
                    {
                        if (_project_task.items.id_item_type == item.item_type.Task || _project_task.sales_detail == null)
                        {
                            sales_order_detail                = new sales_order_detail();
                            sales_order_detail.State          = EntityState.Added;
                            sales_order_detail.id_sales_order = sales_order.id_sales_order;
                            sales_order_detail.sales_order    = sales_order;
                            if (Convert.ToInt16(_project_task.id_item) > 0)
                            {
                                sales_order_detail.id_item = (int)_project_task.id_item;
                            }

                            sales_order_detail.item_description = _project_task.item_description;

                            if (project.is_Executable)
                            {
                                sales_order_detail.quantity = (decimal)_project_task.quantity_exe;
                            }
                            else
                            {
                                sales_order_detail.quantity = (decimal)_project_task.quantity_est;
                            }


                            if (_project_task.unit_price_vat != null)
                            {
                                sales_order_detail.UnitPrice_Vat = (decimal)_project_task.unit_price_vat;
                            }

                            sales_order_detail.id_project_task = _project_task.id_project_task;
                            _project_task.IsSelected           = false;
                            _project_task.sales_detail         = sales_order_detail;
                        }

                        if (sales_order_detail != null)
                        {
                            sales_order.sales_order_detail.Add(sales_order_detail);
                        }
                    }

                    if (sales_order.sales_order_detail.Count() > 0)
                    {
                        sales_order.State      = EntityState.Added;
                        sales_order.IsSelected = true;

                        SalesOrderDB.sales_order.Add(sales_order);
                        SalesOrderDB.SaveChanges();

                        if (Generate_Invoice)
                        {
                            SalesOrderDB.Approve();
                            sales_invoice sales_invoice = new entity.sales_invoice();

                            if (SalesOrderDB.app_document_range.Where(x => x.app_document.id_application == App.Names.SalesBudget).FirstOrDefault() != null)
                            {
                                sales_invoice.id_range = SalesOrderDB.app_document_range.Where(x => x.app_document.id_application == App.Names.SalesInvoice).FirstOrDefault().id_range;
                            }
                            sales_invoice.id_contact    = (int)project.id_contact;
                            sales_invoice.contact       = SalesOrderDB.contacts.Where(x => x.id_contact == (int)project.id_contact).FirstOrDefault();
                            sales_invoice.sales_order   = sales_order;
                            sales_invoice.id_project    = project.id_project;
                            sales_invoice.id_condition  = (int)cbxCondition.SelectedValue;
                            sales_invoice.id_contract   = (int)cbxContract.SelectedValue;
                            sales_invoice.id_currencyfx = (int)cbxCurrency.SelectedValue;
                            sales_invoice.comment       = "Project -> " + project.name;
                            sales_invoice.trans_date    = DateTime.Now;
                            sales_invoice_detail sales_invoice_detail = null;

                            foreach (project_task _project_task in project_taskLIST)
                            {
                                sales_invoice_detail                  = new sales_invoice_detail();
                                sales_invoice_detail.State            = EntityState.Added;
                                sales_invoice_detail.id_sales_invoice = sales_invoice.id_sales_invoice;
                                sales_invoice_detail.sales_invoice    = sales_invoice;
                                sales_invoice_detail.id_item          = (int)_project_task.id_item;
                                sales_invoice_detail.item_description = _project_task.item_description;

                                if (project.is_Executable)
                                {
                                    sales_invoice_detail.quantity = (decimal)_project_task.quantity_exe;
                                }
                                else
                                {
                                    sales_invoice_detail.quantity = (decimal)_project_task.quantity_est;
                                }

                                if (_project_task.unit_price_vat != null)
                                {
                                    sales_invoice_detail.UnitPrice_Vat = (decimal)_project_task.unit_price_vat;
                                }

                                sales_invoice_detail.id_project_task = _project_task.id_project_task;
                                _project_task.IsSelected             = false;

                                sales_invoice.sales_invoice_detail.Add(sales_invoice_detail);
                            }

                            sales_invoice.State      = EntityState.Added;
                            sales_invoice.IsSelected = true;
                            crm_opportunity crm_opportunity = sales_order.crm_opportunity;
                            crm_opportunity.sales_invoice.Add(sales_invoice);
                            SalesOrderDB.crm_opportunity.Attach(crm_opportunity);
                            SalesOrderDB.sales_invoice.Add(sales_invoice);
                        }
                    }
                }

                SalesOrderDB.SaveChanges();
                btnCancel_Click(null, null);
            }
        }