protected override void EliminarAlbaranAction()
        {
            if (Entity.AlbaranesFacturas.Count == 0)
            {
                return;
            }

            InputDeliverySelectForm form = new InputDeliverySelectForm(this, InputDeliveryList.GetList(_albaranes));

            if (form.ShowDialog(this) == DialogResult.OK)
            {
                List <InputDeliveryInfo> results = form.Selected as List <InputDeliveryInfo>;

                foreach (InputDeliveryInfo item in results)
                {
                    _entity.Extract(item);
                    _albaranes.Remove(item);
                }
            }

            if (_entity.AlbaranesFacturas.Count == 0)
            {
                Serie_BT.Enabled = true;
            }

            Datos.ResetBindings(false);
            RefreshLineas();
        }
        public virtual void CrearFacturaAction()
        {
            InputDeliverySelectForm form = new InputDeliverySelectForm(this, InputDeliveryList.GetNoFacturados(true));

            form.ShowDialog(this);

            if (form.DialogResult == DialogResult.OK)
            {
                try
                {
                    PgMng.Reset(4, 1, Resources.Messages.GENERANDO_FACTURAS, this);
                    List <InputDeliveryInfo> deliveries = form.Selected as List <InputDeliveryInfo>;
                    PgMng.Grow();

                    InputInvoices invoices = InputInvoices.NewList();
                    invoices.NewItems(deliveries);
                    PgMng.Grow();

                    invoices.Save();
                    invoices.CloseSession();

                    _selected      = deliveries;
                    _action_result = DialogResult.OK;
                }
                catch (Exception ex)
                {
                    PgMng.ShowInfoException(ex);
                }
                finally
                {
                    PgMng.FillUp();
                    RefreshList();
                }
            }
        }
        protected bool AddAlbaran()
        {
            if (_entity.OidSerie == 0)
            {
                PgMng.ShowInfoException(Resources.Messages.NO_SERIE_SELECTED);
                return(false);
            }

            InputDeliveryList list = null;

            list = InputDeliveryList.GetNoFacturados(false, _entity);

            //Quitamos de la lista los ya añadidos
            List <InputDeliveryInfo> lista = new List <InputDeliveryInfo>();

            foreach (InputDeliveryInfo item in list)
            {
                if (_entity.AlbaranesFacturas.GetItemByAlbaran(item.Oid) == null)
                {
                    lista.Add(item);
                }
            }

            InputDeliveryList lista_completa = InputDeliveryList.GetListByAcreedor(false, _entity.ETipoAcreedor, _entity.OidAcreedor);

            //Añadimos a lista los eliminados
            foreach (AlbaranFacturaProveedor item in _albaranes_factura)
            {
                if (_entity.AlbaranesFacturas.GetItemByAlbaran(item.OidAlbaran) == null)
                {
                    lista.Add(lista_completa.GetItem(item.OidAlbaran));
                }
            }

            InputDeliverySelectForm form = new InputDeliverySelectForm(this, InputDeliveryList.GetList(lista));

            if (form.ShowDialog(this) == DialogResult.OK)
            {
                _results = form.Selected as List <InputDeliveryInfo>;

                if (_entity.Rectificativa && (_results.Count > 1))
                {
                    PgMng.ShowInfoException("No es posible asignar varios albaranes a una factura rectificativa.");
                    return(false);
                }

                foreach (InputDeliveryInfo item in _results)
                {
                    if (item.OidAcreedor != _results[0].OidAcreedor)
                    {
                        PgMng.ShowInfoException("No es posible asignar albaranes de acreedores distintos a una misma Factura.");
                        return(false);
                    }
                }

                /*foreach (InputDeliveryInfo item in _results)
                 * {
                 *  if (item.PIRPF != _results[0].PIRPF)
                 *  {
                 *      PgMng.ShowInfoException(Resources.Messages.ALBARANES_CON_IRPF_DISTINTO);
                 *      return false;
                 *  }
                 * }*/

                _back_job = BackJob.AddAlbaran;
                //PgMng.StartBackJob(this);

                DoAddAlbaran(null);

                if (Result == BGResult.OK)
                {
                    Serie_BT.Enabled = false;
                    Datos.ResetBindings(false);
                }
            }

            return(false);
        }