示例#1
0
        private void select_Item(sales_budget sales_budget, item item)
        {
            Settings SalesSettings = new Settings();

            if (sales_budget.sales_budget_detail.Where(a => a.id_item == item.id_item).FirstOrDefault() == null || SalesSettings.AllowDuplicateItem)
            {
                sales_budget_detail _sales_budget_detail = new sales_budget_detail();
                _sales_budget_detail.State            = EntityState.Added;
                _sales_budget_detail.sales_budget     = sales_budget;
                _sales_budget_detail.Contact          = sales_budget.contact;
                _sales_budget_detail.item_description = item.description;
                _sales_budget_detail.item             = item;

                _sales_budget_detail.id_item = item.id_item;

                sales_budget.sales_budget_detail.Add(_sales_budget_detail);
            }
            else
            {
                sales_budget_detail sales_budget_detail = sales_budget.sales_budget_detail.Where(a => a.id_item == item.id_item).FirstOrDefault();
                sales_budget_detail.quantity += 1;
            }

            Dispatcher.BeginInvoke((Action)(() =>
            {
                sales_budgetsales_budget_detailViewSource.View.Refresh();
                calculate_vat(null, null);
            }));
        }
示例#2
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);
            }
        }
示例#3
0
        private void saveOrder_Click(object sender, RoutedEventArgs e)
        {
            project_event project_costing = project_costingViewSource.View.CurrentItem as project_event;

            if (project_costing != null)
            {
                contact       contact       = EventDB.contacts.Where(x => x.id_contact == sbxContact.ContactID).FirstOrDefault();
                app_condition app_condition = id_conditionComboBox.SelectedItem as app_condition;
                app_contract  app_contract  = id_contractComboBox.SelectedItem as app_contract;


                if (contact != null && app_condition != null && app_contract != null)
                {
                    using (SalesBudgetDB db = new SalesBudgetDB())
                    {
                        sales_budget sales_budget = new sales_budget();
                        sales_budget.IsSelected = true;
                        sales_budget.State      = EntityState.Added;
                        sales_budget.status     = Status.Documents_General.Pending;
                        sales_budget.id_contact = contact.id_contact;
                        sales_budget.contact    = db.contacts.Where(x => x.id_contact == contact.id_contact).FirstOrDefault();

                        if (CurrentSession.Id_Branch > 0)
                        {
                            sales_budget.id_branch = CurrentSession.Id_Branch;
                        }
                        else
                        {
                            sales_budget.id_branch = db.app_branch.Where(a => a.is_active == true && a.id_company == CurrentSession.Id_Company).FirstOrDefault().id_branch;
                        }

                        sales_budget.id_condition  = app_condition.id_condition;
                        sales_budget.id_contract   = app_contract.id_contract;
                        sales_budget.id_currencyfx = project_costing.id_currencyfx;


                        foreach (project_event_variable project_event_variable in project_costing.project_event_variable.Where(a => a.is_included == true))
                        {
                            sales_budget_detail sales_budget_detail = new sales_budget_detail();
                            sales_budget_detail.sales_budget  = sales_budget;
                            sales_budget_detail.item          = db.items.Where(a => a.id_item == project_event_variable.id_item).FirstOrDefault();
                            sales_budget_detail.id_item       = project_event_variable.id_item;
                            sales_budget_detail.quantity      = ((project_event_variable.adult_consumption) + (project_event_variable.child_consumption));
                            sales_budget_detail.UnitPrice_Vat = Math.Round(get_Price(contact, IDcurrencyfx, sales_budget_detail.item, entity.App.Modules.Sales));
                            sales_budget.sales_budget_detail.Add(sales_budget_detail);
                        }

                        foreach (project_event_fixed project_event_fixed in project_costing.project_event_fixed.Where(a => a.is_included == true))
                        {
                            sales_budget_detail sales_budget_detail = new sales_budget_detail();
                            sales_budget_detail.sales_budget  = sales_budget;
                            sales_budget_detail.item          = db.items.Where(a => a.id_item == project_event_fixed.id_item).FirstOrDefault();
                            sales_budget_detail.id_item       = project_event_fixed.id_item;
                            sales_budget_detail.quantity      = project_event_fixed.consumption;
                            sales_budget_detail.UnitPrice_Vat = Math.Round(get_Price(contact, IDcurrencyfx, sales_budget_detail.item, entity.App.Modules.Sales));
                            sales_budget.sales_budget_detail.Add(sales_budget_detail);
                        }

                        sales_budget_detail sales_budget_detail_hall = new sales_budget_detail();
                        sales_budget_detail_hall.sales_budget  = sales_budget;
                        sales_budget_detail_hall.item          = db.items.Where(a => a.id_item == project_costing.id_item).FirstOrDefault();
                        sales_budget_detail_hall.id_item       = project_costing.id_item;
                        sales_budget_detail_hall.quantity      = 1;
                        sales_budget_detail_hall.UnitPrice_Vat = Math.Round(get_Price(contact, IDcurrencyfx, sales_budget_detail_hall.item, entity.App.Modules.Sales));
                        sales_budget.sales_budget_detail.Add(sales_budget_detail_hall);

                        db.sales_budget.Add(sales_budget);
                        db.SaveChanges();
                    }

                    lblCancel_MouseDown(null, null);
                }
                else
                {
                    if (MessageBox.Show("VALIDATION EXCEPTION : Please fill up all the fields", "Cognitivo", MessageBoxButton.OKCancel, MessageBoxImage.Asterisk) == MessageBoxResult.Cancel)
                    {
                        lblCancel_MouseDown(null, null);
                    }
                }
            }
        }