Ejemplo n.º 1
0
        public sales_return New()
        {
            sales_return sales_return = new sales_return();

            sales_return.State      = EntityState.Added;
            sales_return.id_range   = Brillo.GetDefault.Return_RangeID(App.Names.SalesReturn);
            sales_return.status     = Status.Documents_General.Pending;
            sales_return.trans_date = DateTime.Now;

            sales_return.id_branch  = CurrentSession.Id_Branch;
            sales_return.app_branch = base.app_branch.Where(x => x.id_branch == sales_return.id_branch).FirstOrDefault();
            sales_return.State      = EntityState.Added;
            sales_return.IsSelected = true;

            //Get any value, so that it doesn't cause NotNull Exception. This data is not important.
            sales_return.app_condition = base.app_condition.FirstOrDefault();
            sales_return.app_contract  = base.app_contract.Where(x => x.id_condition == sales_return.app_condition.id_condition).FirstOrDefault();

            return(sales_return);
        }
Ejemplo n.º 2
0
        private void add_CRM(sales_return sales_return)
        {
            sales_invoice_detail sales_invoice_detail = sales_return.sales_return_detail.FirstOrDefault().sales_invoice_detail;

            if (sales_invoice_detail == null)
            {
                crm_opportunity crm_opportunity = new crm_opportunity();
                crm_opportunity.id_contact  = sales_return.id_contact;
                crm_opportunity.id_currency = sales_return.id_currencyfx;
                crm_opportunity.value       = sales_return.GrandTotal;

                crm_opportunity.sales_return.Add(sales_return);
                base.crm_opportunity.Add(crm_opportunity);
            }
            else
            {
                crm_opportunity crm_opportunity = sales_invoice.Where(x => x.id_sales_invoice == sales_invoice_detail.id_sales_invoice).FirstOrDefault().crm_opportunity;
                crm_opportunity.sales_return.Add(sales_return);
                base.crm_opportunity.Attach(crm_opportunity);
            }
        }
Ejemplo n.º 3
0
        public void loadSalesReturnReport(int id)
        {
            try
            {
                ReportDataSource reportDataSource = new ReportDataSource();
                reportDataSource.Name = "DataSet1"; // Name of the DataSet we set in .rdlc
                sales_return sales_return = db.sales_return.Where(x => x.id_sales_return == id).FirstOrDefault();
                List <sales_return_detail> sales_return_detail = db.sales_return_detail.Where(x => x.id_sales_return == sales_return.id_sales_return).ToList();

                reportDataSource.Value = sales_return_detail
                                         .Select(g => new
                {
                    id_sales_return        = g.id_sales_return,
                    id_sales_return_detail = g.id_sales_return_detail,
                    sales_return           = g.id_sales_return_detail,
                    id_company             = g.id_company,
                    add1             = g.sales_return.contact.address,
                    telephone        = g.sales_return.contact.telephone,
                    email            = g.sales_return.contact.email,
                    company_name     = g.app_company.name,
                    item_code        = g.item.code,
                    item_description = g.item.name,
                    Description      = 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_return.app_terminal.name,
                    code             = g.sales_return.code,
                    contact_name     = g.sales_return.contact.name,
                    trans_date       = g.sales_return.trans_date,
                    id_vat_group     = g.id_vat_group,
                    gov_id           = g.sales_return.contact.gov_code,
                    Number           = g.sales_return.number,
                }).ToList();

                string path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                path = path + "\\CogntivoERP";
                string SubFolder = "";
                SubFolder = "\\TemplateFiles";
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                    Directory.CreateDirectory(path + SubFolder);
                    File.Copy(AppDomain.CurrentDomain.BaseDirectory + "\\bin\\debug\\Sales_Return.rdlc", path + SubFolder + "\\Sales_Return.rdlc");
                }
                else if (!Directory.Exists(path + SubFolder))
                {
                    Directory.CreateDirectory(path + SubFolder);
                    File.Copy(AppDomain.CurrentDomain.BaseDirectory + "\\bin\\debug\\Sales_Return.rdlc", path + SubFolder + "\\Sales_Return.rdlc");
                }
                else if (!File.Exists(path + SubFolder + "\\Sales_Return.rdlc"))
                {
                    File.Copy(AppDomain.CurrentDomain.BaseDirectory + "\\bin\\debug\\Sales_Return.rdlc", path + SubFolder + "\\Sales_Return.rdlc");
                }
                if (!sales_return.app_document_range.use_default_printer)
                {
                    reportViewer.LocalReport.ReportPath = path + SubFolder + "\\Sales_Return.rdlc"; // Path of the rdlc file
                    reportViewer.LocalReport.DataSources.Add(reportDataSource);
                    reportViewer.RefreshReport();
                }
                else
                {
                    try
                    {
                        if (sales_return.app_document_range.printer_name != null)
                        {
                            LocalReport  report       = new LocalReport();
                            PrintInvoice PrintInvoice = new PrintInvoice();
                            report.ReportPath = path + SubFolder + "\\Sales_Return.rdlc"; // Path of the rdlc file
                            report.DataSources.Add(reportDataSource);
                            PrintInvoice.Export(report);
                            PrintInvoice.Print(sales_return.app_document_range.printer_name);
                        }
                        else
                        {
                            NotSupportedException ex = new NotSupportedException();
                            throw ex;
                        }
                    }
                    catch
                    {
                        reportViewer.LocalReport.ReportPath = path + SubFolder + "\\Sales_Return.rdlc"; // Path of the rdlc file
                        reportViewer.LocalReport.DataSources.Add(reportDataSource);
                        reportViewer.RefreshReport();
                        Window window = new Window
                        {
                            Title   = "Report",
                            Content = this
                        };

                        window.ShowDialog();
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }