private void add_CRM(sales_budget invoice) { crm_opportunity crm_opportunity = new crm_opportunity(); crm_opportunity.id_contact = invoice.id_contact; crm_opportunity.id_currency = invoice.id_currencyfx; crm_opportunity.value = invoice.sales_budget_detail.Sum(x => x.SubTotal_Vat); crm_opportunity.sales_budget.Add(invoice); base.crm_opportunity.Add(crm_opportunity); }
public sales_budget New() { sales_budget sales_budget = new sales_budget(); sales_budget.status = Status.Documents_General.Pending; sales_budget.State = EntityState.Added; sales_budget.id_range = Brillo.GetDefault.Return_RangeID(App.Names.SalesBudget); sales_budget.trans_date = DateTime.Now; sales_budget.IsSelected = true; return(sales_budget); }
public void loadSalesBudgetReport(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_budget sales_budget = db.sales_budget.Where(x => x.id_sales_budget == id).FirstOrDefault(); List <sales_budget_detail> sales_budget_detail = db.sales_budget_detail.Where(x => x.id_sales_budget == sales_budget.id_sales_budget).ToList(); reportDataSource.Value = sales_budget_detail .Select(g => new { id_sales_budget = g.id_sales_budget, id_sales_budget_detail = g.id_sales_budget_detail, sales_budget = g.id_sales_budget_detail, id_company = g.id_company, add1 = g.sales_budget.contact.address, telephone = g.sales_budget.contact.telephone, email = g.sales_budget.contact.email, company_name = g.app_company.name, 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_cost, unit_price_vat = g.UnitPrice_Vat, terminale_name = g.sales_budget.app_terminal.name, code = g.sales_budget.code, contact_name = g.sales_budget.contact.name, //project_name = g.sales_budget.project != null ? g.sales_budget.project.name : "", sales_rep_name = g.sales_budget.sales_rep != null ? g.sales_budget.sales_rep.name : "", trans_date = g.sales_budget.trans_date, id_vat_group = g.id_vat_group, gov_id = g.sales_budget.contact.gov_code, contract = g.sales_budget.app_contract.name, condition = g.sales_budget.app_contract.app_condition.name, Number = g.sales_budget.number, comment = g.sales_budget.comment }).ToList(); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); Directory.CreateDirectory(path + SubFolder); File.Copy(System.AppDomain.CurrentDomain.BaseDirectory + "\\bin\\debug\\Sales_Budget.rdlc", path + SubFolder + "\\Sales_Budget.rdlc"); } else if (!Directory.Exists(path + SubFolder)) { Directory.CreateDirectory(path + SubFolder); File.Copy(System.AppDomain.CurrentDomain.BaseDirectory + "\\bin\\debug\\Sales_Budget.rdlc", path + SubFolder + "\\Sales_Budget.rdlc"); } else if (!File.Exists(path + SubFolder + "\\Sales_Budget.rdlc")) { File.Copy(System.AppDomain.CurrentDomain.BaseDirectory + "\\bin\\debug\\Sales_Budget.rdlc", path + SubFolder + "\\Sales_Budget.rdlc"); } if (!sales_budget.app_document_range.use_default_printer) { reportViewer.LocalReport.ReportPath = path + SubFolder + "\\Sales_Budget.rdlc"; // Path of the rdlc file reportViewer.LocalReport.DataSources.Add(reportDataSource); reportViewer.RefreshReport(); } else { try { if (sales_budget.app_document_range.printer_name != null) { LocalReport report = new LocalReport(); PrintInvoice PrintInvoice = new PrintInvoice(); report.ReportPath = path + SubFolder + "\\Sales_Budget.rdlc"; // Path of the rdlc file report.DataSources.Add(reportDataSource); PrintInvoice.Export(report); PrintInvoice.Print(sales_budget.app_document_range.printer_name); } else { NotSupportedException ex = new NotSupportedException(); throw ex; } } catch { reportViewer.LocalReport.ReportPath = path + SubFolder + "\\Sales_Budget.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_Budget.rdlc"; // Path of the rdlc file reportViewer.LocalReport.DataSources.Add(reportDataSource); reportViewer.RefreshReport(); Window window = new Window { Title = "Report", Content = this }; window.ShowDialog(); } }
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); } }