Пример #1
0
        /// <summary>
        /// Executes code that will insert Invoiced Items into Movement.
        /// </summary>
        /// <param name="invoice"></param>
        public void Insert_Items_2_Movement(sales_invoice invoice)
        {
            List <item_movement> item_movementList = new List <item_movement>();

            ///
            Brillo.Logic.Stock _Stock = new Brillo.Logic.Stock();
            item_movementList = _Stock.insert_Stock(this, invoice);

            if (item_movementList.Count() > 0)
            {
                item_movement.AddRange(item_movementList);

                foreach (sales_invoice_detail sales_detail in invoice.sales_invoice_detail.Where(x => x.item.item_product != null))
                {
                    if (sales_detail.item_movement.FirstOrDefault() != null)
                    {
                        if (sales_detail.item_movement.FirstOrDefault().item_movement_value != null)
                        {
                            sales_detail.unit_cost =
                                entity.Brillo.Currency.convert_Values(sales_detail.item_movement.FirstOrDefault().item_movement_value.Sum(x => x.unit_value),
                                                                      sales_detail.item_movement.FirstOrDefault().item_movement_value.FirstOrDefault().id_currencyfx,
                                                                      sales_detail.sales_invoice.id_currencyfx, App.Modules.Sales);
                        }
                    }
                }
            }
        }
Пример #2
0
        public void Approve(bool IsDiscountStock)
        {
            NumberOfRecords = 0;

            foreach (sales_packing sales_packing in base.sales_packing.Local)
            {
                if (sales_packing.IsSelected && sales_packing.Error == null)
                {
                    if (sales_packing.id_sales_packing == 0)
                    {
                        SaveChanges();
                    }

                    if (sales_packing.status != Status.Documents_General.Approved)
                    {
                        if (IsDiscountStock)
                        {
                            Brillo.Logic.Stock   _Stock            = new Brillo.Logic.Stock();
                            List <item_movement> item_movementList = new List <item_movement>();
                            item_movementList = _Stock.insert_Stock(this, sales_packing);

                            if (item_movementList != null && item_movementList.Count > 0)
                            {
                                item_movement.AddRange(item_movementList);
                            }
                        }

                        if (sales_packing.number == null && sales_packing.id_range > 0)
                        {
                            Brillo.Logic.Range.branch_Code   = base.app_branch.Where(x => x.id_branch == sales_packing.id_branch).FirstOrDefault().code;
                            Brillo.Logic.Range.terminal_Code = base.app_terminal.Where(x => x.id_terminal == sales_packing.id_terminal).FirstOrDefault().code;
                            app_document_range app_document_range = base.app_document_range.Where(x => x.id_range == sales_packing.id_range).FirstOrDefault();
                            sales_packing.number = Brillo.Logic.Range.calc_Range(app_document_range, true);
                            sales_packing.RaisePropertyChanged("number");
                            sales_packing.is_issued = true;

                            Brillo.Document.Start.Automatic(sales_packing, app_document_range);
                        }
                        else
                        {
                            sales_packing.is_issued = false;
                        }

                        sales_packing.status = Status.Documents_General.Approved;
                        SaveChanges();
                    }

                    NumberOfRecords += 1;
                }

                if (sales_packing.Error != null)
                {
                    sales_packing.HasErrors = true;
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Executes code that will insert Invoiced Items into Movement.
        /// </summary>
        /// <param name="invoice"></param>
        public void Insert_Items_2_Movement(purchase_invoice invoice)
        {
            Brillo.Logic.Stock   _Stock            = new Brillo.Logic.Stock();
            List <item_movement> item_movementList = new List <item_movement>();

            item_movementList = _Stock.insert_Stock(this, invoice);

            if (item_movementList != null && item_movementList.Count > 0)
            {
                item_movement.AddRange(item_movementList);
            }
        }
Пример #4
0
        //private void add_CRM(purchase_packing purchase_packing)
        //{
        //    if (purchase_packing.id_purchase_packing == 0 || purchase_packing == null)
        //    {
        //        crm_opportunity crm_opportunity = new crm_opportunity();
        //        crm_opportunity.id_contact = purchase_packing.id_contact;

        //        crm_opportunity.purchase_packing.Add(purchase_packing);
        //        base.crm_opportunity.Add(crm_opportunity);
        //    }
        //    else
        //    {
        //        crm_opportunity crm_opportunity = sales_order.Where(x => x.id_sales_order == purchase_packing.id_purchase_packing).FirstOrDefault().crm_opportunity;
        //        crm_opportunity.purchase_packing.Add(purchase_packing);
        //        base.crm_opportunity.Attach(crm_opportunity);
        //    }
        //}

        public void Approve(bool IsDiscountStock)
        {
            NumberOfRecords = 0;

            foreach (purchase_packing purchase_packing in base.purchase_packing.Local)
            {
                if (purchase_packing.IsSelected && purchase_packing.Error == null)
                {
                    if (purchase_packing.id_purchase_packing == 0)
                    {
                        SaveChanges();
                    }

                    if (purchase_packing.status != Status.Documents_General.Approved)
                    {
                        if (IsDiscountStock)
                        {
                            Brillo.Logic.Stock   _Stock            = new Brillo.Logic.Stock();
                            List <item_movement> item_movementList = new List <item_movement>();
                            item_movementList = _Stock.insert_Stock(this, purchase_packing);

                            if (item_movementList != null && item_movementList.Count > 0)
                            {
                                item_movement.AddRange(item_movementList);
                            }
                        }

                        if (purchase_packing.number == null && purchase_packing.id_range > 0)
                        {
                            Brillo.Logic.Range.branch_Code = base.app_branch.Where(x => x.id_branch == purchase_packing.id_branch).FirstOrDefault().code;
                            app_document_range app_document_range = base.app_document_range.Where(x => x.id_range == purchase_packing.id_range).FirstOrDefault();
                            purchase_packing.number = Brillo.Logic.Range.calc_Range(app_document_range, true);
                            purchase_packing.RaisePropertyChanged("number");
                        }


                        purchase_packing.status = Status.Documents_General.Approved;
                        SaveChanges();
                    }

                    NumberOfRecords += 1;
                }

                if (purchase_packing.Error != null)
                {
                    purchase_packing.HasErrors = true;
                }
            }
        }
Пример #5
0
        public bool Approve()
        {
            NumberOfRecords = 0;

            foreach (purchase_order purchase_order in base.purchase_order.Local.Where(x => x.IsSelected == true))
            {
                if (purchase_order.Error == null)
                {
                    if (purchase_order.id_purchase_order == 0)
                    {
                        SaveChanges();
                    }

                    if (purchase_order.status != Status.Documents_General.Approved)
                    {
                        if (purchase_order.number == null && purchase_order.id_range != null)
                        {
                            //Brillo.Logic.Document _Document = new Brillo.Logic.Document();
                            Brillo.Logic.Range.branch_Code   = base.app_branch.Where(x => x.id_branch == purchase_order.id_branch).FirstOrDefault().code;
                            Brillo.Logic.Range.terminal_Code = base.app_terminal.Where(x => x.id_terminal == purchase_order.id_terminal).FirstOrDefault().code;
                            app_document_range app_document_range = base.app_document_range.Where(x => x.id_range == purchase_order.id_range).FirstOrDefault();
                            purchase_order.number = Brillo.Logic.Range.calc_Range(app_document_range, true);
                            purchase_order.RaisePropertyChanged("number");
                            purchase_order.is_issued = true;
                        }
                        else
                        {
                            purchase_order.is_issued = false;
                        }

                        List <payment_schedual> payment_schedualList = new List <payment_schedual>();
                        Brillo.Logic.Payment    _Payment             = new Brillo.Logic.Payment();
                        payment_schedualList = _Payment.insert_Schedual(purchase_order);

                        Brillo.Logic.Stock   _Stock            = new Brillo.Logic.Stock();
                        List <item_movement> item_movementList = new List <item_movement>();
                        item_movementList = _Stock.insert_Stock(this, purchase_order);

                        if (payment_schedualList != null && payment_schedualList.Count > 0)
                        {
                            payment_schedual.AddRange(payment_schedualList);
                        }
                        if (item_movementList != null && item_movementList.Count > 0)
                        {
                            item_movement.AddRange(item_movementList);
                        }

                        purchase_order.status = Status.Documents_General.Approved;
                        SaveChanges();
                    }

                    if (purchase_order.is_issued)
                    {
                        app_document_range app_document_range = base.app_document_range.Where(x => x.id_range == purchase_order.id_range).FirstOrDefault();
                        Brillo.Document.Start.Automatic(purchase_order, app_document_range);
                    }

                    NumberOfRecords          += 1;
                    purchase_order.IsSelected = false;
                }
                else if (purchase_order.Error != null)
                {
                    purchase_order.HasErrors = true;
                }
            }

            return(true);
        }
Пример #6
0
        public void Approve()
        {
            foreach (purchase_return purchase_return in base.purchase_return.Local.Where(x => x.IsSelected == true))
            {
                if (purchase_return.Error == null)
                {
                    if (purchase_return.id_purchase_return == 0)
                    {
                        SaveChanges();
                    }

                    if (purchase_return.status != Status.Documents_General.Approved)
                    {
                        List <payment_schedual> payment_schedualList = new List <payment_schedual>();
                        Brillo.Logic.Payment    _Payment             = new Brillo.Logic.Payment();
                        payment_schedualList = _Payment.insert_Schedual(purchase_return);

                        Brillo.Logic.Stock   _Stock            = new Brillo.Logic.Stock();
                        List <item_movement> item_movementList = new List <item_movement>();
                        item_movementList = _Stock.insert_Stock(this, purchase_return);

                        if (payment_schedualList != null && payment_schedualList.Count > 0)
                        {
                            payment_schedual.AddRange(payment_schedualList);
                        }
                        if (item_movementList != null && item_movementList.Count > 0)
                        {
                            item_movement.AddRange(item_movementList);
                        }


                        if (purchase_return.purchase_invoice != null)
                        {
                            payment payment = new payment();
                            payment.id_contact = purchase_return.id_contact;
                            payment_detail payment_detailreturn = new payment_detail();
                            // payment_detailreturn.id_account = payment_quick.payment_detail.id_account;
                            payment_detailreturn.id_currencyfx = purchase_return.id_currencyfx;
                            if (base.payment_type.Where(x => x.payment_behavior == entity.payment_type.payment_behaviours.CreditNote).FirstOrDefault() != null)
                            {
                                payment_detailreturn.id_payment_type = base.payment_type.Where(x => x.payment_behavior == entity.payment_type.payment_behaviours.CreditNote).FirstOrDefault().id_payment_type;
                            }
                            else
                            {
                                System.Windows.Forms.MessageBox.Show("Please add crditnote payment type...");
                                return;
                            }


                            payment_detailreturn.id_sales_return = purchase_return.id_purchase_return;

                            payment_detailreturn.value = purchase_return.GrandTotal;

                            payment_schedual payment_schedualReturn = new payment_schedual();
                            payment_schedualReturn.debit           = purchase_return.GrandTotal;
                            payment_schedualReturn.credit          = 0;
                            payment_schedualReturn.id_currencyfx   = purchase_return.id_currencyfx;
                            payment_schedualReturn.purchase_return = purchase_return;
                            payment_schedualReturn.trans_date      = purchase_return.trans_date;
                            payment_schedualReturn.expire_date     = purchase_return.trans_date;
                            payment_schedualReturn.status          = entity.Status.Documents_General.Approved;
                            payment_schedualReturn.id_contact      = purchase_return.id_contact;
                            payment_schedualReturn.can_calculate   = true;
                            payment_schedualReturn.parent          = purchase_return.purchase_invoice.payment_schedual.FirstOrDefault();

                            payment_detailreturn.payment_schedual.Add(payment_schedualReturn);
                            payment.payment_detail.Add(payment_detailreturn);
                            base.payments.Add(payment);
                        }
                        purchase_return.status = Status.Documents_General.Approved;
                        SaveChanges();
                    }
                }
                else if (purchase_return.Error != null)
                {
                    purchase_return.HasErrors = true;
                }
            }
        }
Пример #7
0
        public bool Approve()
        {
            NumberOfRecords = 0;

            foreach (item_inventory item_inventory in base.item_inventory.Local.Where(x => x.status != Status.Documents.Issued && x.IsSelected))
            {
                //If Value Counted in Null, we undsertand that this has not been counted and will be removed from context.
                List <item_inventory_detail> null_detail = item_inventory.item_inventory_detail.Where(x => x.value_counted == null).ToList();
                if (null_detail.Count > 0)
                {
                    base.item_inventory_detail.RemoveRange(null_detail);
                }

                if (item_inventory.id_inventory == 0)
                {
                    SaveChanges();
                }

                List <item_movement> item_movementLIST = new List <item_movement>();

                Brillo.Logic.Stock _Stock = new Brillo.Logic.Stock();
                item_movementLIST = _Stock.insert_Stock(this, item_inventory);

                if (item_movementLIST.Count() > 0)
                {
                    item_movement.AddRange(item_movementLIST);
                }
                //foreach (item_inventory_detail item_inventory_detail in item_inventory.item_inventory_detail)
                //{

                //if (item_inventory_detail.item_inventory_dimension.Count() > 0)
                //{
                //    item_movement item_movement = new item_movement();
                //    item_movement.id_item_product = item_inventory_detail.item_product.id_item_product;
                //    item_movement.id_location = item_inventory_detail.app_location.id_location;
                //    item_movement.comment = Brillo.Localize.Text<string>("Inventory") + ": " + item_inventory_detail.comment;
                //    item_movement.status = Status.Stock.InStock;
                //    item_movement.debit = 0;
                //    item_movement.credit = (decimal)item_inventory_detail.value_counted;
                //    item_movement.trans_date = item_inventory.trans_date;
                //    item_movement.id_inventory_detail = item_inventory_detail.id_inventory_detail;
                //    item_movement.timestamp = DateTime.Now;

                //    if (item_inventory_detail.unit_value > 0 && item_inventory_detail.id_currencyfx > 0)
                //    {
                //        item_movement_value item_movement_value = new item_movement_value();
                //        item_movement_value.unit_value = item_inventory_detail.unit_value;
                //        item_movement_value.id_currencyfx = item_inventory_detail.id_currencyfx;
                //        item_movement_value.comment = Brillo.Localize.Text<string>("Inventory") + ": " + item_inventory_detail.comment;
                //        item_movement.item_movement_value.Add(item_movement_value);
                //    }

                //    foreach (item_inventory_dimension item_inventory_dimension in item_inventory_detail.item_inventory_dimension)
                //    {
                //        item_movement_dimension item_movement_dimension = new item_movement_dimension();
                //        item_movement_dimension.value = item_inventory_dimension.value;
                //        item_movement_dimension.id_dimension = item_inventory_dimension.id_dimension;
                //        item_movement.item_movement_dimension.Add(item_movement_dimension);
                //    }

                //    item_movementLIST.Add(item_movement);

                //    NumberOfRecords += 1;
                //}
                //else
                //{
                //    decimal delta = 0;

                //    if (item_inventory_detail.value_system != item_inventory_detail.value_counted)
                //    {
                //        //Negative
                //        delta = Convert.ToDecimal(item_inventory_detail.value_counted) - item_inventory_detail.value_system;
                //    }

                //    if (delta != 0)
                //    {
                //        item_movement item_movement = new item_movement();
                //        item_movement.id_item_product = item_inventory_detail.item_product.id_item_product;
                //        item_movement.id_location = item_inventory_detail.app_location.id_location;
                //        item_movement.comment = Brillo.Localize.Text<string>("Inventory") + ": " + item_inventory_detail.comment;
                //        item_movement.status = Status.Stock.InStock;
                //        item_movement.credit = delta > 0 ? delta : 0;
                //        item_movement.debit = delta < 0 ? Math.Abs(delta) : 0;
                //        item_movement.trans_date = item_inventory.trans_date;
                //        item_movement.id_inventory_detail = item_inventory_detail.id_inventory_detail;
                //        item_movement.timestamp = DateTime.Now;

                //        if (item_inventory_detail.unit_value > 0 && item_inventory_detail.id_currencyfx > 0)
                //        {
                //            item_movement_value item_movement_value = new item_movement_value();
                //            item_movement_value.unit_value = item_inventory_detail.unit_value;
                //            item_movement_value.id_currencyfx = item_inventory_detail.id_currencyfx;
                //            item_movement.item_movement_value.Add(item_movement_value);
                //        }
                //        else
                //        {
                //            item_inventory_detail parent_inventory = base.item_inventory_detail.Where(x => x.id_item_product == item_inventory_detail.id_item_product && x.id_location == item_inventory_detail.id_location && x.unit_value > 0).FirstOrDefault();
                //            if (parent_inventory != null)
                //            {
                //                item_movement_value item_movement_value = new item_movement_value();
                //                item_movement_value.unit_value = parent_inventory.unit_value;
                //                item_movement_value.id_currencyfx = parent_inventory.id_currencyfx;
                //                item_movement.item_movement_value.Add(item_movement_value);
                //            }
                //        }

                //        item_movementLIST.Add(item_movement);
                //        NumberOfRecords += 1;

                //    }
                //}
                // }

                base.item_movement.AddRange(item_movementLIST);

                item_inventory.status = Status.Documents.Issued;

                //window.ShowDialog();
                SaveChanges();
            }

            return(true);
        }
Пример #8
0
        public void Approve()
        {
            foreach (sales_return sales_return in base.sales_return.Local.Where(x => x.status != Status.Documents_General.Approved))
            {
                if (sales_return.status != Status.Documents_General.Approved &&
                    sales_return.IsSelected &&
                    sales_return.Error == null)
                {
                    if (sales_return.id_sales_return == 0)
                    {
                        SaveChanges();
                    }

                    if (sales_return.status != Status.Documents_General.Approved)
                    {
                        if (sales_return.number == null && sales_return.id_range != null)
                        {
                            Brillo.Logic.Range.branch_Code   = base.app_branch.Where(x => x.id_branch == sales_return.id_branch).FirstOrDefault().code;
                            Brillo.Logic.Range.terminal_Code = base.app_terminal.Where(x => x.id_terminal == sales_return.id_terminal).FirstOrDefault().code;
                            app_document_range app_document_range = base.app_document_range.Where(x => x.id_range == sales_return.id_range).FirstOrDefault();
                            sales_return.number = Brillo.Logic.Range.calc_Range(app_document_range, true);
                            sales_return.RaisePropertyChanged("number");
                            sales_return.is_issued = true;

                            //Save values bofore printing.
                            SaveChanges();

                            Brillo.Document.Start.Automatic(sales_return, app_document_range);
                        }
                        else
                        {
                            sales_return.is_issued = false;
                        }

                        List <payment_schedual> payment_schedualList = new List <payment_schedual>();
                        Brillo.Logic.Payment    _Payment             = new Brillo.Logic.Payment();
                        payment_schedualList = _Payment.insert_Schedual(sales_return);

                        Brillo.Logic.Stock   _Stock            = new Brillo.Logic.Stock();
                        List <item_movement> item_movementList = new List <item_movement>();
                        item_movementList = _Stock.insert_Stock(this, sales_return);

                        if (payment_schedualList != null && payment_schedualList.Count > 0)
                        {
                            payment_schedual.AddRange(payment_schedualList);
                        }
                        if (item_movementList != null && item_movementList.Count > 0)
                        {
                            item_movement.AddRange(item_movementList);
                        }

                        if (sales_return.sales_invoice != null)
                        {
                            payment payment = new payment();
                            payment.id_contact = sales_return.id_contact;
                            payment_detail payment_detailreturn = new payment_detail();
                            // payment_detailreturn.id_account = payment_quick.payment_detail.id_account;
                            payment_detailreturn.id_currencyfx = sales_return.id_currencyfx;

                            //Check for Credit Note PaymentType.
                            if (base.payment_type.Where(x => x.payment_behavior == entity.payment_type.payment_behaviours.CreditNote).FirstOrDefault() != null)
                            {
                                //Gets Payment Type form Database.
                                payment_detailreturn.id_payment_type = base.payment_type.Where(x => x.payment_behavior == entity.payment_type.payment_behaviours.CreditNote).FirstOrDefault().id_payment_type;
                            }
                            else
                            {
                                //In case Payment type doesn not exist, this will create it and try to fix the error.
                                payment_type payment_type = new payment_type();
                                payment_type.payment_behavior = entity.payment_type.payment_behaviours.CreditNote;
                                payment_type.name             = LocExtension.GetLocalizedValue <string>("Cognitivo:local:SalesReturn");
                                base.payment_type.Add(payment_type);

                                payment_detailreturn.payment_type = payment_type;
                            }

                            payment_detailreturn.id_sales_return = sales_return.id_sales_return;
                            payment_detailreturn.value           = sales_return.GrandTotal;

                            payment_schedual payment_schedualReturn = new payment_schedual();
                            payment_schedualReturn.debit         = 0;
                            payment_schedualReturn.credit        = sales_return.GrandTotal;
                            payment_schedualReturn.id_currencyfx = sales_return.id_currencyfx;
                            payment_schedualReturn.sales_return  = sales_return;
                            payment_schedualReturn.trans_date    = sales_return.trans_date;
                            payment_schedualReturn.expire_date   = sales_return.trans_date;
                            payment_schedualReturn.status        = entity.Status.Documents_General.Approved;
                            payment_schedualReturn.id_contact    = sales_return.id_contact;
                            payment_schedualReturn.can_calculate = true;
                            payment_schedualReturn.parent        = sales_return.sales_invoice.payment_schedual.FirstOrDefault();

                            payment_detailreturn.payment_schedual.Add(payment_schedualReturn);
                            payment.payment_detail.Add(payment_detailreturn);
                            base.payments.Add(payment);
                        }

                        sales_return.status = Status.Documents_General.Approved;
                        SaveChanges();
                    }

                    else if (sales_return.Error != null)
                    {
                        sales_return.HasErrors = true;
                    }
                }
            }
        }
Пример #9
0
        public bool Approve()
        {
            foreach (sales_order sales_order in base.sales_order.Local.Where(x => x.status != Status.Documents_General.Approved))
            {
                NumberOfRecords = 0;

                if (sales_order.status != Status.Documents_General.Approved &&
                    sales_order.IsSelected &&
                    sales_order.Error == null)
                {
                    if (sales_order.id_sales_order == 0)
                    {
                        SaveChanges();
                    }

                    if (sales_order.status != Status.Documents_General.Approved)
                    {
                        List <payment_schedual> payment_schedualList = new List <payment_schedual>();
                        Brillo.Logic.Payment    _Payment             = new Brillo.Logic.Payment();
                        payment_schedualList = _Payment.insert_Schedual(sales_order);

                        Brillo.Logic.Stock   _Stock            = new Brillo.Logic.Stock();
                        List <item_movement> item_movementList = new List <item_movement>();
                        item_movementList = _Stock.insert_Stock(this, sales_order);

                        if (payment_schedualList != null && payment_schedualList.Count > 0)
                        {
                            payment_schedual.AddRange(payment_schedualList);
                        }

                        if (item_movementList != null && item_movementList.Count > 0)
                        {
                            item_movement.AddRange(item_movementList);
                        }

                        if (sales_order.number == null && sales_order.id_range != null)
                        {
                            Brillo.Logic.Range.branch_Code   = base.app_branch.Where(x => x.id_branch == sales_order.id_branch).FirstOrDefault().code;
                            Brillo.Logic.Range.terminal_Code = base.app_terminal.Where(x => x.id_terminal == sales_order.id_terminal).FirstOrDefault().code;
                            app_document_range app_document_range = base.app_document_range.Where(x => x.id_range == sales_order.id_range).FirstOrDefault();
                            sales_order.number = Brillo.Logic.Range.calc_Range(app_document_range, true);
                            sales_order.RaisePropertyChanged("number");
                            sales_order.is_issued = true;

                            //Save Changes before Printing, so that all fields show up.
                            sales_order.status    = Status.Documents_General.Approved;
                            sales_order.timestamp = DateTime.Now;
                            SaveChanges();

                            Brillo.Document.Start.Automatic(sales_order, app_document_range);
                        }
                        else
                        {
                            sales_order.is_issued = false;
                            sales_order.status    = Status.Documents_General.Approved;
                            sales_order.timestamp = DateTime.Now;
                            SaveChanges();
                        }


                        item_request item_request = new item_request();
                        item_request.name    = sales_order.contact.name;
                        item_request.comment = sales_order.comment;


                        item_request.id_sales_order = sales_order.id_sales_order;
                        item_request.id_branch      = sales_order.id_branch;


                        item_request.request_date = (DateTime)sales_order.delivery_date;

                        foreach (sales_order_detail data in sales_order.sales_order_detail.Where(x => x.IsSelected))
                        {
                            item_request_detail item_request_detail = new entity.item_request_detail();
                            item_request_detail.date_needed_by        = (DateTime)sales_order.delivery_date;
                            item_request_detail.id_sales_order_detail = data.id_sales_order_detail;
                            item_request_detail.urgency = entity.item_request_detail.Urgencies.Medium;
                            int idItem = data.item.id_item;
                            item_request_detail.id_item = idItem;
                            item item = base.items.Where(x => x.id_item == idItem).FirstOrDefault();
                            if (item != null)
                            {
                                item_request_detail.item    = item;
                                item_request_detail.comment = item_request_detail.item.name;
                            }


                            item_request_detail.quantity = data.quantity;

                            foreach (item_dimension item_dimension in item.item_dimension)
                            {
                                item_request_dimension item_request_dimension = new item_request_dimension();
                                item_request_dimension.id_dimension    = item_dimension.id_app_dimension;
                                item_request_dimension.app_dimension   = item_dimension.app_dimension;
                                item_request_dimension.id_measurement  = item_dimension.id_measurement;
                                item_request_dimension.app_measurement = item_dimension.app_measurement;
                                item_request_dimension.value           = item_dimension.value;
                                item_request_detail.item_request_dimension.Add(item_request_dimension);
                            }

                            item_request.item_request_detail.Add(item_request_detail);
                        }
                        base.item_request.Add(item_request);
                        SaveChanges();
                    }

                    NumberOfRecords       += 1;
                    sales_order.IsSelected = false;
                }

                if (sales_order.Error != null)
                {
                    sales_order.HasErrors = true;
                }
            }

            return(true);
        }