Exemplo n.º 1
0
        protected override void SetEstadoItem()
        {
            if (LineaRegistros_DGW.CurrentRow == null)
            {
                return;
            }

            LineaRegistro item = (LineaRegistro)LineaRegistros_DGW.CurrentRow.DataBoundItem;

            SelectEnumInputForm form = new SelectEnumInputForm(true);

            form.SetDataSource(Library.Common.EnumText <EEstado> .GetList(GetEstados()));

            if (form.ShowDialog(this) == DialogResult.OK)
            {
                ComboBoxSource estado = form.Selected as ComboBoxSource;

                if (estado.Oid == ((long)EEstado.Anulado))
                {
                    NullItem(LineaRegistros_DGW.CurrentRow);
                }
                else
                {
                    ChangeState(LineaRegistros_DGW.CurrentRow, (EEstado)estado.Oid);
                }

                LineaRegistros_DGW.CurrentCell.Value = estado.Texto;

                SetGridFormat();
            }
        }
Exemplo n.º 2
0
        protected void NullItem(DataGridViewRow row)
        {
            LineaRegistro item = row.DataBoundItem as LineaRegistro;

            item.EEstadoEntidad = EEstado.Exportado;
            item.EEstado        = EEstado.Anulado;
        }
        public virtual void ExportLoans()
        {
            Loans prestamos2 = null;

            try
            {
                _invoice_conditions.Orders.Clear();
                _invoice_conditions.Orders.NewOrder("Fecha", System.ComponentModel.ListSortDirection.Ascending, typeof(Loan));

                LoanList prestamos = LoanList.GetOrderedByFechaList(_invoice_conditions);

                foreach (LoanInfo item in prestamos)
                {
                    if (item.EEstado == EEstado.Anulado)
                    {
                        continue;
                    }

                    LineaRegistro lr = _registry.LineaRegistros.NewItem(_registry, item);

                    BuildLoanAccountingEntry(item, lr);

                    _accounting_entry++;
                }

                //Cambiamos el estado de las ayudas contabilizadas
                prestamos2 = Loans.GetList(_invoice_conditions);

                foreach (Loan item in prestamos2)
                {
                    if (item.EEstado == EEstado.Anulado)
                    {
                        continue;
                    }

                    if (item.EEstado != EEstado.Exportado)
                    {
                        item.EEstado = EEstado.Exportado;
                    }
                }

                prestamos2.Save();
            }
            catch (Exception ex)
            {
                _registry = null;
                throw ex;
            }
            finally
            {
                if (prestamos2 != null)
                {
                    prestamos2.CloseSession();
                }
            }
        }
        public virtual void ExportBankTransfers()
        {
            Traspasos banktransfers2 = null;

            try
            {
                _invoice_conditions.Orders.Clear();
                _invoice_conditions.Orders.NewOrder("Fecha", System.ComponentModel.ListSortDirection.Ascending, typeof(Traspaso));

                TraspasoList banktransfers = TraspasoList.GetList(_invoice_conditions, false);

                foreach (TraspasoInfo item in banktransfers)
                {
                    if (item.EEstado == EEstado.Anulado)
                    {
                        continue;
                    }

                    LineaRegistro lr = _registry.LineaRegistros.NewItem(_registry, item);

                    BuildBankTransferAccountingEntry(item, lr);

                    _accounting_entry++;
                }

                //Cambiamos el estado de las ayudas contabilizadas
                banktransfers2 = Traspasos.GetList(_invoice_conditions, false);

                foreach (Traspaso item in banktransfers2)
                {
                    if (item.EEstado == EEstado.Anulado)
                    {
                        continue;
                    }

                    if (item.EEstado != EEstado.Exportado)
                    {
                        item.EEstado = EEstado.Exportado;
                    }
                }

                banktransfers2.Save();
            }
            catch (Exception ex)
            {
                _registry = null;
                throw ex;
            }
            finally
            {
                if (banktransfers2 != null)
                {
                    banktransfers2.CloseSession();
                }
            }
        }
Exemplo n.º 5
0
        protected override void SetGridFormat()
        {
            foreach (DataGridViewRow row in LineaRegistros_DGW.Rows)
            {
                if (row.IsNewRow)
                {
                    return;
                }

                LineaRegistro item = (LineaRegistro)row.DataBoundItem;
                Face.Common.ControlTools.Instance.SetRowColor(row, item.EEstado);
            }
        }
Exemplo n.º 6
0
        public override void UpdateList()
        {
            switch (_current_action)
            {
            case molAction.Add:
                if (_entity == null)
                {
                    return;
                }
                List.AddItem(_entity.GetInfo(false));
                if (FilterType == IFilterType.Filter)
                {
                    LineaRegistroList listA = LineaRegistroList.GetList(_filter_results);
                    listA.AddItem(_entity.GetInfo(false));
                    _filter_results = listA.GetSortedList();
                }
                break;

            case molAction.Edit:
            case molAction.Lock:
            case molAction.Unlock:
                if (_entity == null)
                {
                    return;
                }
                ActiveItem.CopyFrom(_entity);
                break;

            case molAction.Delete:
                if (ActiveItem == null)
                {
                    return;
                }
                List.RemoveItem(ActiveOID);
                if (FilterType == IFilterType.Filter)
                {
                    LineaRegistroList listD = LineaRegistroList.GetList(_filter_results);
                    listD.RemoveItem(ActiveOID);
                    _filter_results = listD.GetSortedList();
                }
                break;
            }

            RefreshSources();
            if (_entity != null)
            {
                Select(_entity.Oid);
            }
            _entity = null;
        }
Exemplo n.º 7
0
        protected void ChangeState(DataGridViewRow row, EEstado estado)
        {
            if (row == null)
            {
                return;
            }
            if (row.DataBoundItem == null)
            {
                return;
            }

            LineaRegistro item = row.DataBoundItem as LineaRegistro;

            item.EEstadoEntidad = estado;
            item.EEstado        = estado;
        }
 protected virtual void BuildREAGrantAccountingEntry(ExpedienteREAInfo expediente, LineaRegistro lr)
 {
     throw new iQImplementationException("ContabilidadExporterBase::BuildREAGrantAccountingEntry");
 }
 protected virtual void BuildAsientoCobroAyudaFomento(ChargeInfo cobro, LineaRegistro lr)
 {
     throw new iQImplementationException("ContabilidadExporterBase::BuildAsientoCobroAyudaFomento");
 }
 protected virtual void BuildREAChargeAccountingEntry(ChargeInfo cobro, LineaRegistro lr)
 {
     throw new iQImplementationException("ContabilidadExporterBase::BuildREAChargeAccountingEntry");
 }
 protected virtual void BuildCreditCardStatementPaymentAccountingEntry(PaymentInfo pago, LineaRegistro lr)
 {
     throw new iQImplementationException("ContabilidadExporterBase::BuildCreditCardStatementPaymentAccountingEntry");
 }
        public virtual void ExportInputInvoices()
        {
            InputInvoices invoices = null;

            try
            {
                _store_conditions.Orders.Clear();
                _store_conditions.Orders.NewOrder("Acreedor", System.ComponentModel.ListSortDirection.Ascending, typeof(InputInvoice));
                _store_conditions.Orders.NewOrder("Fecha", System.ComponentModel.ListSortDirection.Ascending, typeof(InputInvoice));

                _input_invoices = InputInvoiceList.GetList(_store_conditions, true);
                _providers      = (_providers == null) ? ProviderBaseList.GetList(false) : _providers;

                foreach (InputInvoiceInfo item in _input_invoices)
                {
                    LineaRegistro lr = _registry.LineaRegistros.NewItem(_registry, item);

                    BuildInputInvoiceAccountingEntry(item, lr);
                    BuildTaxBookSoportadoAccountingEntry(item);

                    _accounting_entry++;
                }

                //Cambiamos el estado de las facturas contabilizadas
                invoices = InputInvoices.GetList(_store_conditions, false);

                foreach (InputInvoice item in invoices)
                {
                    item.LoadChilds(typeof(InputInvoiceLine), false);
                }

                foreach (InputInvoice item in invoices)
                {
                    if (item.EEstado == EEstado.Anulado)
                    {
                        continue;
                    }

                    if (item.EEstado != EEstado.Exportado)
                    {
                        item.EEstado = EEstado.Exportado;
                    }
                }

                invoices.Save();
            }
            catch (iQException ex)
            {
                _registry = null;
                throw ex;
            }
            catch (Exception ex)
            {
                _registry = null;
                throw ex;
            }
            finally
            {
                if (invoices != null)
                {
                    invoices.CloseSession();
                }
            }
        }
 protected virtual void BuildLoanAccountingEntry(LoanInfo traspaso, LineaRegistro lr)
 {
     throw new iQImplementationException("ContabilidadExporterBase::BuildLoanAccountingEntry");
 }
        public virtual void ExportGrants()
        {
            REAExpedients reas2 = null;

            //LineasFomento fomentos2 = null;

            try
            {
                //AYUDAS REA

                _store_conditions.Orders.Clear();
                _store_conditions.Orders.NewOrder("Fecha", System.ComponentModel.ListSortDirection.Ascending, typeof(REAExpedient));

                ExpedienteREAList reas = ExpedienteREAList.GetList(_store_conditions, true);
                _expedients = ExpedienteList.GetList(false);

                foreach (ExpedienteREAInfo item in reas)
                {
                    if (item.EEstado == EEstado.Anulado)
                    {
                        continue;
                    }
                    if (item.EEstado == EEstado.Desestimado)
                    {
                        continue;
                    }

                    LineaRegistro lr = _registry.LineaRegistros.NewItem(_registry, item);

                    BuildREAGrantAccountingEntry(item, lr);

                    _accounting_entry++;
                }

                //Cambiamos el estado de las ayudas contabilizadas
                reas2 = REAExpedients.GetList(_store_conditions, false);

                foreach (REAExpedient item in reas2)
                {
                    if (item.EEstado == EEstado.Anulado)
                    {
                        continue;
                    }
                    if (item.EEstado == EEstado.Desestimado)
                    {
                        continue;
                    }

                    if (item.EEstado != EEstado.Exportado)
                    {
                        item.EEstado = EEstado.Exportado;
                    }
                }

                reas2.Save();

                //AYUDAS FOMENTO

                /*LineaFomentoList fomentos = LineaFomentoList.GetList(_store_conditions, true);
                 *
                 * foreach (LineaFomentoInfo item in fomentos)
                 * {
                 *      if (item.EEstado == EEstado.Anulado) continue;
                 *      if (item.EEstado == EEstado.Desestimado) continue;
                 *
                 *      LineaRegistro lr = _registro.LineaRegistros.NewItem(_registro, item);
                 *
                 *      BuildAsientoAyudaFomento(item, lr);
                 *
                 *      _asiento++;
                 * }
                 *
                 * //Cambiamos el estado de las cobros contabilizados
                 * fomentos2 = LineasFomento.GetList(_store_conditions, false);
                 *
                 * foreach (LineaFomento item in fomentos2)
                 * {
                 *      if (item.EEstado == EEstado.Anulado) continue;
                 *      if (item.EEstado == EEstado.Desestimado) continue;
                 *
                 *      if (item.EEstado != EEstado.Exportado) item.EEstado = EEstado.Exportado;
                 * }
                 *
                 * fomentos2.Save();*/
            }
            catch (Exception ex)
            {
                _registry = null;
                throw ex;
            }
            finally
            {
                if (reas2 != null)
                {
                    reas2.CloseSession();
                }
                //if (fomentos2 != null) fomentos2.CloseSession();
            }
        }
        public virtual void ExportPayrolls()
        {
            PayrollBatchs payrollbatchs2 = null;

            try
            {
                if (Invoice.ModulePrincipal.GetCuentaNominasSetting() == string.Empty)
                {
                    throw new iQException("No se ha definido la cuenta contable asociada para las Nóminas");
                }

                if (Invoice.ModulePrincipal.GetCuentaSegurosSocialesSetting() == string.Empty)
                {
                    throw new iQException("No se ha definido la cuenta contable asociada para los seguros sociales");
                }

                if (Invoice.ModulePrincipal.GetCuentaHaciendaSetting() == string.Empty)
                {
                    throw new iQException("No se ha definido la cuenta contable asociada para la Hacienda Pública");
                }

                _store_conditions.Orders.Clear();
                _store_conditions.Orders.NewOrder("Vencimiento", System.ComponentModel.ListSortDirection.Ascending, typeof(Payment));

                _payments  = PaymentList.GetListInNomina(_store_conditions, true);
                _employees = EmployeeList.GetList(false);

                _store_conditions.Orders.Clear();
                _store_conditions.Orders.NewOrder("Fecha", System.ComponentModel.ListSortDirection.Ascending, typeof(PayrollBatch));

                PayrollBatchList payrollbatchs = PayrollBatchList.GetList(_store_conditions, true);

                foreach (PayrollBatchInfo item in payrollbatchs)
                {
                    if (item.EEstado == EEstado.Anulado)
                    {
                        continue;
                    }

                    LineaRegistro lr = _registry.LineaRegistros.NewItem(_registry, item);

                    BuildPayrollBatchAccountingEntry(item, lr);
                    _accounting_entry++;
                }

                //Cambiamos el estado de las nominas contabilizadas
                payrollbatchs2 = PayrollBatchs.GetList(_store_conditions, true);

                foreach (PayrollBatch item in payrollbatchs2)
                {
                    if (item.EEstado == EEstado.Anulado)
                    {
                        continue;
                    }

                    if (item.EEstado != EEstado.Exportado)
                    {
                        item.EEstado = EEstado.Exportado;
                    }
                }

                payrollbatchs2.Save();
            }
            catch (Exception ex)
            {
                _registry = null;
                throw ex;
            }
            finally
            {
                if (payrollbatchs2 != null)
                {
                    payrollbatchs2.CloseSession();
                }
            }
        }
        public virtual void ExportExpenses()
        {
            Payments pagos2 = null;

            try
            {
                _store_conditions.TipoPago       = ETipoPago.Gasto;
                _store_conditions.CategoriaGasto = ECategoriaGasto.Generales;
                _store_conditions.Orders.Clear();
                _store_conditions.Orders.NewOrder("Vencimiento", System.ComponentModel.ListSortDirection.Ascending, typeof(Payment));

                PaymentList pagos = PaymentList.GetList(_store_conditions, true);

                foreach (PaymentInfo item in pagos)
                {
                    if (item.EEstado == EEstado.Anulado)
                    {
                        continue;
                    }

                    LineaRegistro lr = _registry.LineaRegistros.NewItem(_registry, item);

                    BuildExpenseAccountingEntry(item, lr);

                    _accounting_entry++;
                }

                //Cambiamos el estado de los elementos contabilizados
                pagos2 = Payments.GetList(_store_conditions, false);

                foreach (Payment item in pagos2)
                {
                    if (item.EEstado == EEstado.Anulado)
                    {
                        continue;
                    }

                    if (item.EEstado != EEstado.Exportado)
                    {
                        if (item.EEstadoPago == EEstado.Pagado)
                        {
                            item.EEstado = EEstado.Exportado;
                        }
                    }
                }

                pagos2.Save();
            }
            catch (iQException ex)
            {
                _registry = null;
                throw ex;
            }
            catch (Exception ex)
            {
                _registry = null;
                throw ex;
            }
            finally
            {
                if (pagos2 != null)
                {
                    pagos2.CloseSession();
                }
            }
        }
        public virtual void ExportCharges()
        {
            Charges charges2 = null;

            try
            {
                _invoice_conditions.Orders.Clear();
                _invoice_conditions.Orders.NewOrder("Vencimiento", System.ComponentModel.ListSortDirection.Ascending, typeof(Charge));

                ChargeList cobros = ChargeList.GetList(_invoice_conditions, true);
                //Hacen falta todas porque un cobro puede estar asociado a una factura que no este en las condiciones del filtro
                _invoices = OutputInvoiceList.GetList(false);
                _clients  = (_clients == null) ? ClienteList.GetList(false) : _clients;

                _expedients = ExpedienteList.GetList(false);

                foreach (ChargeInfo item in cobros)
                {
                    if (item.EEstado == EEstado.Anulado)
                    {
                        continue;
                    }

                    LineaRegistro lr = _registry.LineaRegistros.NewItem(_registry, item);

                    switch (item.ETipoCobro)
                    {
                    case ETipoCobro.Cliente:
                    {
                        BuildChargeAccountingEntry(item, lr);
                        BuildFinalcialCashBookChargeAccountingEntry(item);
                    }
                    break;

                    case ETipoCobro.REA:
                    {
                        BuildREAChargeAccountingEntry(item, lr);
                    }
                    break;
                    }

                    _accounting_entry++;
                }

                //Cambiamos el estado de las cobros contabilizados
                charges2 = Charges.GetList(_invoice_conditions, false);
                FinancialCashList efectos = FinancialCashList.GetList(false);

                foreach (Charge item in charges2)
                {
                    if (item.EEstado == EEstado.Anulado)
                    {
                        continue;
                    }

                    if (item.EEstado != EEstado.Exportado)
                    {
                        if (item.EEstadoCobro == EEstado.Charged)
                        {
                            if (item.EMedioPago != EMedioPago.Cheque &&
                                item.EMedioPago != EMedioPago.Pagare)
                            {
                                item.EEstado = EEstado.Exportado;
                            }
                            else
                            {
                                FinancialCashInfo efecto = efectos.GetItemByCobro(item.Oid);
                                if (efecto != null && efecto.EEstadoCobro == EEstado.Charged)
                                {
                                    item.EEstado = EEstado.Exportado;
                                }
                            }
                        }
                    }
                }

                charges2.Save();
            }
            catch (iQException ex)
            {
                _registry = null;
                throw ex;
            }
            catch (Exception ex)
            {
                _registry = null;
                throw ex;
            }
            finally
            {
                if (charges2 != null)
                {
                    charges2.CloseSession();
                }
            }
        }
        public virtual void ExportOutputInvoices()
        {
            OutputInvoices invoices = null;

            try
            {
                _invoice_conditions.Orders.Clear();
                _invoice_conditions.Orders.NewOrder("Fecha", System.ComponentModel.ListSortDirection.Ascending, typeof(OutputInvoice));

                _invoices = OutputInvoiceList.GetList(_invoice_conditions, true);
                _clients  = (_clients == null) ? ClienteList.GetList(false) : _clients;

                foreach (OutputInvoiceInfo item in _invoices)
                {
                    if (item.EEstado == EEstado.Anulado)
                    {
                        continue;
                    }

                    LineaRegistro lr = _registry.LineaRegistros.NewItem(_registry, item);

                    BuildOutputInvoiceAccountingEntry(item, lr);
                    BuildTaxBookRepercutidoAccountingEntry(item);

                    _accounting_entry++;
                }

                //Cambiamos el estado de las facturas contabilizadas
                invoices = OutputInvoices.GetList(_invoice_conditions, false);

                foreach (OutputInvoice item in invoices)
                {
                    if (item.EEstado == EEstado.Anulado)
                    {
                        continue;
                    }

                    if (item.EEstado != EEstado.Exportado)
                    {
                        item.EEstado = EEstado.Exportado;
                    }
                }

                invoices.Save();
            }
            catch (iQException ex)
            {
                _registry = null;
                throw ex;
            }
            catch (Exception ex)
            {
                _registry = null;
                throw ex;
            }
            finally
            {
                if (invoices != null)
                {
                    invoices.CloseSession();
                }
            }
        }
        public virtual void ExportPayments()
        {
            Payments payments2 = null;

            try
            {
                _store_conditions.Orders.Clear();
                _store_conditions.Orders.NewOrder("Vencimiento", System.ComponentModel.ListSortDirection.Ascending, typeof(Payment));

                PaymentList payments = PaymentList.GetOrderedByFechaList(_store_conditions, true);

                //if (pagos.Count == 0) return; // throw new iQException(Library.Resources.Messages.NO_RESULTS);

                //Hacen falta todas porque un pago puede estar asociado a una factura que no este en las condiciones del filtro
                _input_invoices = InputInvoiceList.GetList(false);
                _providers      = (_providers == null) ? ProviderBaseList.GetList(false) : _providers;
                _employees      = (_employees == null) ? EmployeeList.GetList(false) : _employees;
                _expense_types  = (_expense_types == null) ? TipoGastoList.GetList(false) : _expense_types;
                _payrolls       = (_payrolls == null) ? PayrollList.GetList(false) : _payrolls;

                foreach (PaymentInfo item in payments)
                {
                    if (item.EEstado == EEstado.Anulado)
                    {
                        continue;
                    }

                    LineaRegistro lr = _registry.LineaRegistros.NewItem(_registry, item);

                    switch (item.ETipoPago)
                    {
                    case ETipoPago.Factura:
                    {
                        BuildInvoicePaymentAccountingEntry(item, lr);
                        BuildFinancialCashBookPaymentAccountingEntry(item);
                    }
                    break;

                    case ETipoPago.Nomina:
                    {
                        BuildPayrollPaymentAccountingEntry(item, lr);
                    }
                    break;

                    case ETipoPago.Gasto:
                    {
                        BuildExpensePaymentAccountingEntry(item, lr);
                    }
                    break;

                    case ETipoPago.ExtractoTarjeta:
                    {
                        BuildCreditCardStatementPaymentAccountingEntry(item, lr);
                    }
                    break;
                    }

                    _accounting_entry++;
                }

                //Cambiamos el estado de los pagos contabilizados
                payments2 = Payments.GetList(_store_conditions, false);

                foreach (Payment item in payments2)
                {
                    if (item.EEstado == EEstado.Anulado)
                    {
                        continue;
                    }

                    if (item.EEstado != EEstado.Exportado)
                    {
                        /*if (item.EEstadoPago == EEstado.Pagado)*/ item.EEstado = EEstado.Exportado;
                    }
                }

                payments2.Save();
            }
            catch (iQException ex)
            {
                _registry = null;
                throw ex;
            }
            catch (Exception ex)
            {
                _registry = null;
                throw ex;
            }
            finally
            {
                if (payments2 != null)
                {
                    payments2.CloseSession();
                }
            }
        }
 protected virtual void BuildFomentoGrantAccountingEntry(LineaFomentoInfo linea, LineaRegistro lr)
 {
     throw new iQImplementationException("ContabilidadExporterBase::BuildFomentoGrantAccountingEntry");
 }
 protected virtual void BuildPayrollBatchAccountingEntry(PayrollBatchInfo pago, LineaRegistro lr)
 {
     throw new iQImplementationException("ContabilidadExporterBase::BuildPayrollBatchAccountingEntry");
 }
        /// <summary>
        /// FORMATO: 9999999|G|01/10/2009||VENTAS DIA|4300000001|||||||||VENTAS P.S. DEL DIA|D| |37800| |7050000001|00000|00000|00000|4|001| |36000|500| |1800| |0|4777000000|0| | |0|0| |0| |0| | | | |0|0| |0| |0| | | | |0|0| |0| |0| | | | |0|0| |0| |0| | | | |0|0| |0| |0| | | | | | | | | | |1234| | | |0
        /// </summary>
        /// <param name="factura"></param>
        protected override void BuildInvoicePaymentAccountingEntry(PaymentInfo pago, LineaRegistro lr)
        {
            if (pago.ETipoPago != ETipoPago.Factura)
            {
                return;
            }
            if (pago.EEstadoPago != EEstado.Pagado)
            {
                return;
            }

            IAcreedorInfo    titular = _providers.GetItem(pago.OidAgente, pago.ETipoAcreedor);
            InputInvoiceInfo factura = null;

            if (titular.CuentaContable == string.Empty)
            {
                throw new iQException("El deudor nº " + titular.Codigo + " (" + titular.Nombre + ") no tiene cuenta contable asociada");
            }

            string apunte      = string.Empty;
            string descripcion = string.Empty;
            int    pos         = 1;
            string tipo        = "D";
            string signo       = "+";
            string importe     = string.Empty;

            foreach (TransactionPaymentInfo pf in pago.Operations)
            {
                factura     = _input_invoices.GetItem(pf.OidOperation);
                tipo        = "D";
                signo       = "+";
                descripcion = "Pago Fra. " + factura.NFactura + " (" + factura.Acreedor + ")";

                //Sumamos los gastos bancarios solo al primer pagofactura
                decimal valor = (pos++ == 1) ? pf.Cantidad + pago.GastosBancarios : pf.Cantidad;
                importe = valor.ToString().Replace(".", string.Empty);

                //apunte en la cuenta del acreedor
                apunte += AddValue(_config.Empresa);                                            /*CODIGO DE EMPRESA*/
                apunte += AddValue("S");                                                        /*TIPO DE REGISTRO*/
                apunte += AddValue(pago.Fecha.ToShortDateString());                             /*FECHA*/
                apunte += AddEmptyValue(1);                                                     /*Nº SERIE DOCUMENTO*/
                apunte += AddValue(pago.Codigo);                                                /*DOCUMENTO*/
                apunte += AddValue(titular.CuentaContable);                                     /*CUENTA*/
                apunte += AddEmptyValue(8);                                                     /*SIN USO*/
                apunte += AddValue(descripcion);                                                /*DESCRIPCION*/
                apunte += AddValue(tipo.ToString());                                            /*TIPO: DEBE=1, HABER=2*/
                apunte += AddValue(signo);                                                      /*SIGNO*/
                apunte += AddValue(importe);                                                    /*IMPORTE*/
                apunte += AddValue(_accounting_entry.ToString());                               /*ASIENTO*/
                apunte += AddEmptyValue(73);                                                    /*SIN USO*/
                apunte += AddValue(_config.CentroTrabajo);                                      /*CENTRO TRABAJO*/
                apunte += AddEmptyValue(2);                                                     /*SIN USO*/
                apunte += AddValue(lr.IDExportacion);                                           /*OPC. 1*/

                _export_file.WriteLine(apunte);

                apunte  = string.Empty;
                tipo    = "H";
                signo   = "-";
                importe = pf.Cantidad.ToString().Replace(".", string.Empty);

                //apunte en la cuenta del pago
                apunte += AddValue(_config.Empresa);                                            /*CODIGO DE EMPRESA*/
                apunte += AddValue("G");                                                        /*TIPO DE REGISTRO*/
                apunte += AddValue(pago.Fecha.ToShortDateString());                             /*FECHA*/
                apunte += AddEmptyValue(1);                                                     /*Nº SERIE DOCUMENTO*/
                apunte += AddValue(pago.Codigo);                                                /*DOCUMENTO*/
                apunte += AddValue(GetPaymentAccount(pago));                                    /*CUENTA*/
                apunte += AddEmptyValue(8);                                                     /*SIN USO*/
                apunte += AddValue(descripcion);                                                /*DESCRIPCION*/
                apunte += AddValue(tipo.ToString());                                            /*TIPO: DEBE=1, HABER=2*/
                apunte += AddValue(signo);                                                      /*SIGNO*/
                apunte += AddValue(importe);                                                    /*IMPORTE*/
                apunte += AddValue(_accounting_entry.ToString());                               /*ASIENTO*/
                apunte += AddEmptyValue(73);                                                    /*SIN USO*/
                apunte += AddValue(_config.CentroTrabajo);                                      /*CENTRO TRABAJO*/
                apunte += AddEmptyValue(2);                                                     /*SIN USO*/
                apunte += AddValue(lr.IDExportacion);                                           /*OPC. 1*/

                _export_file.WriteLine(apunte);

                apunte = string.Empty;
            }

            if (pago.GastosBancarios != 0)
            {
                apunte      = string.Empty;
                tipo        = "H";
                signo       = "-";
                descripcion = "Gtos. Banco. " + pago.Codigo + " (" + titular.Nombre + ")";
                importe     = pago.GastosBancarios.ToString().Replace(".", string.Empty);

                //apunte en la cuenta de gastos bancarios
                apunte += AddValue(_config.Empresa);                                            /*CODIGO DE EMPRESA*/
                apunte += AddValue("G");                                                        /*TIPO DE REGISTRO*/
                apunte += AddValue(pago.Fecha.ToShortDateString());                             /*FECHA*/
                apunte += AddEmptyValue(1);                                                     /*Nº SERIE DOCUMENTO*/
                apunte += AddValue(pago.Codigo);                                                /*DOCUMENTO*/
                apunte += AddValue(GetBankExpensesAccount(pago));                               /*CUENTA*/
                apunte += AddEmptyValue(8);                                                     /*SIN USO*/
                apunte += AddValue(descripcion);                                                /*DESCRIPCION*/
                apunte += AddValue(tipo.ToString());                                            /*TIPO: DEBE=1, HABER=2*/
                apunte += AddValue(signo);                                                      /*SIGNO*/
                apunte += AddValue(importe);                                                    /*IMPORTE*/
                apunte += AddValue(_accounting_entry.ToString());                               /*ASIENTO*/
                apunte += AddEmptyValue(73);                                                    /*SIN USO*/
                apunte += AddValue(_config.CentroTrabajo);                                      /*CENTRO TRABAJO*/
                apunte += AddEmptyValue(2);                                                     /*SIN USO*/
                apunte += AddValue(lr.IDExportacion);                                           /*OPC. 1*/

                _export_file.WriteLine(apunte);
            }
        }
        /// <summary>
        /// FORMATO: 9999999|G|01/10/2009||VENTAS DIA|4300000001|||||||||VENTAS P.S. DEL DIA|D| |37800| |7050000001|00000|00000|00000|4|001| |36000|500| |1800| |0|4777000000|0| | |0|0| |0| |0| | | | |0|0| |0| |0| | | | |0|0| |0| |0| | | | |0|0| |0| |0| | | | |0|0| |0| |0| | | | | | | | | | |1234| | | |0
        /// </summary>
        /// <param name="factura"></param>
        protected override void BuildOutputInvoiceAccountingEntry(OutputInvoiceInfo factura, LineaRegistro lr)
        {
            ClienteInfo titular = _clients.GetItem(factura.OidCliente);

            if (titular.CuentaContable == string.Empty)
            {
                throw new iQException("El cliente nº " + titular.NumeroClienteLabel + " (" + titular.Nombre + ") no tiene cuenta contable asociada");
            }

            string apunte      = string.Empty;
            string descripcion = "Fra. " + factura.NFactura + " (" + factura.Cliente + ")";

            string tipo    = (factura.Rectificativa) ? "H" : "D";
            string signo   = (factura.Rectificativa) ? "-" : "+";
            string importe = factura.Total.ToString().Replace(".", string.Empty);

            //apunte en la cuenta del cliente
            apunte += AddValue(_config.Empresa);                                /*CENTRO DE TRABAJO*/
            apunte += AddValue("S");                                            /*TIPO DE REGISTRO*/
            apunte += AddValue(factura.Fecha.ToShortDateString());              /*FECHA*/
            apunte += AddValue(factura.NumeroSerie);                            /*Nº SERIE DOCUMENTO*/
            apunte += AddValue(factura.NFactura);                               /*DOCUMENTO*/
            apunte += AddValue(titular.CuentaContable);                         /*CUENTA*/
            apunte += AddEmptyValue(8);                                         /*SIN USO*/
            apunte += AddValue(descripcion);                                    /*DESCRIPCION*/
            apunte += AddValue(tipo.ToString());                                /*TIPO: DEBE=1, HABER=2*/
            apunte += AddValue(signo);                                          /*SIGNO*/
            apunte += AddValue(importe);                                        /*IMPORTE*/
            apunte += AddValue(_accounting_entry.ToString());                   /*ASIENTO*/
            apunte += AddEmptyValue(73);                                        /*SIN USO*/
            apunte += AddValue(_config.CentroTrabajo);                          /*CENTRO TRABAJO*/
            apunte += AddEmptyValue(3);                                         /*SIN USO*/

            _export_file.WriteLine(apunte);

            List <CuentaResumen> cuentas = factura.GetCuentas();
            FamiliaInfo          familia;

            foreach (CuentaResumen cr in cuentas)
            {
                apunte = string.Empty;

                familia = _families.GetItem(cr.OidFamilia);

                if (familia == null)
                {
                    throw new iQException("Factura " + factura.NFactura + " con familia a nulo");
                }

                if (cr.CuentaContable == string.Empty)
                {
                    throw new iQException("La familia nº " + familia.Codigo + " (" + familia.Nombre + ") no tiene cuenta contable (venta) asociada");
                }

                tipo    = (factura.Rectificativa) ? "D" : "H";
                signo   = (factura.Rectificativa) ? "+" : "-";
                importe = cr.Importe.ToString().Replace(".", string.Empty);

                //apunte en la cuenta de venta
                apunte += AddValue(_config.Empresa);                                    /*CODIGO DE EMPRESA*/
                apunte += AddValue("G");                                                /*TIPO DE REGISTRO*/
                apunte += AddValue(factura.Fecha.ToShortDateString());                  /*FECHA*/
                apunte += AddValue(factura.NumeroSerie);                                /*Nº SERIE DOCUMENTO*/
                apunte += AddValue(factura.NFactura);                                   /*DOCUMENTO*/
                apunte += AddValue(cr.CuentaContable);                                  /*CUENTA*/
                apunte += AddEmptyValue(8);                                             /*SIN USO*/
                apunte += AddValue(descripcion);                                        /*DESCRIPCION*/
                apunte += AddValue(tipo.ToString());                                    /*TIPO: DEBE=1, HABER=2*/
                apunte += AddValue(signo);                                              /*SIGNO*/
                apunte += AddValue(importe);                                            /*IMPORTE*/
                apunte += AddValue(_accounting_entry.ToString());                       /*ASIENTO*/
                apunte += AddEmptyValue(73);                                            /*SIN USO*/
                apunte += AddValue(_config.CentroTrabajo);                              /*CENTRO TRABAJO*/
                apunte += AddEmptyValue(3);                                             /*SIN USO*/

                _export_file.WriteLine(apunte);
            }

            // Apuntes en las cuentas de Impuestos

            List <ImpuestoResumen> impuestos = new List <ImpuestoResumen>();

            foreach (DictionaryEntry impuesto in factura.GetImpuestos())
            {
                impuestos.Add((ImpuestoResumen)impuesto.Value);
            }

            foreach (ImpuestoResumen ir in impuestos)
            {
                if (ir.Importe == 0)
                {
                    continue;
                }

                apunte = string.Empty;

                ImpuestoInfo impuesto = _taxes.GetItem(ir.OidImpuesto);

                if (impuesto == null)
                {
                    throw new iQException("Factura " + factura.NFactura + " con impuesto a nulo");
                }

                if (impuesto.CuentaContableSoportado == string.Empty)
                {
                    throw new iQException("El impuesto '" + impuesto.Nombre + "' no tiene cuenta contable (repercutido) asociada");
                }

                tipo    = (factura.Rectificativa) ? "D" : "H";
                signo   = (factura.Rectificativa) ? "+" : "-";
                importe = ir.Importe.ToString().Replace(".", string.Empty);

                //apunte en la cuenta del impuesto
                apunte += AddValue(_config.Empresa);                                    /*CODIGO DE EMPRESA*/
                apunte += AddValue("G");                                                /*TIPO DE REGISTRO*/
                apunte += AddValue(factura.Fecha.ToShortDateString());                  /*FECHA*/
                apunte += AddValue(factura.NumeroSerie);                                /*Nº SERIE DOCUMENTO*/
                apunte += AddValue(factura.NFactura);                                   /*DOCUMENTO*/
                apunte += AddValue(impuesto.CuentaContableSoportado);                   /*CUENTA*/
                apunte += AddEmptyValue(8);                                             /*SIN USO*/
                apunte += AddValue(descripcion);                                        /*DESCRIPCION*/
                apunte += AddValue(tipo.ToString());                                    /*TIPO: DEBE=1, HABER=2*/
                apunte += AddValue(signo);                                              /*SIGNO*/
                apunte += AddValue(importe);                                            /*IMPORTE*/
                apunte += AddValue(_accounting_entry.ToString());                       /*ASIENTO*/
                apunte += AddEmptyValue(73);                                            /*SIN USO*/
                apunte += AddValue(_config.CentroTrabajo);                              /*CENTRO TRABAJO*/
                apunte += AddEmptyValue(3);                                             /*SIN USO*/

                _export_file.WriteLine(apunte);
            }
        }
 protected virtual void BuildOutputInvoiceAccountingEntry(OutputInvoiceInfo factura, LineaRegistro lr)
 {
     throw new iQImplementationException("ContabilidadExporterBase::BuildOutputInvoiceAccountingEntry");
 }
        public static void SendMailsFacturasPendientes()
        {
            try
            {
                OutputInvoiceList facturas = OutputInvoiceList.GetNoCobradasList(true);
                ClienteList       clientes = ClienteList.GetList(false);
                SerieList         series   = SerieList.GetList(false);
                CompanyInfo       empresa  = CompanyInfo.Get(AppContext.ActiveSchema.Oid);

                SerieInfo   serie;
                ClienteInfo cliente;

                Registro registro = Registro.New(ETipoRegistro.Email);
                registro.Nombre        = "Envio automático de Facturas";
                registro.Observaciones = "Envio automático de Facturas pendientes de pago";

                foreach (OutputInvoiceInfo item in facturas)
                {
                    if (item.Prevision.AddDays(ModulePrincipal.GetPeriodicidadEnvioFacturasPendientes()) > DateTime.Today)
                    {
                        continue;
                    }

                    cliente = clientes.GetItem(item.OidCliente);
                    if (!cliente.EnviarFacturaPendiente)
                    {
                        continue;
                    }

                    serie = series.GetItem(item.OidSerie);

                    FormatConfFacturaAlbaranReport conf = new FormatConfFacturaAlbaranReport();

                    conf.nota  = (cliente.OidImpuesto == 1) ? Resources.Messages.NOTA_EXENTO_IGIC : string.Empty;
                    conf.nota += Environment.NewLine + (item.Nota ? serie.Cabecera : "");

                    OutputInvoiceReportMng reportMng = new OutputInvoiceReportMng(AppContext.ActiveSchema, string.Empty, string.Empty);
                    ReportClass            report    = reportMng.GetDetailReport(item, serie, cliente, null, conf);

                    if (report != null)
                    {
                        LineaRegistro linea = registro.LineaRegistros.NewItem(registro, cliente);

                        ExportOptions options = new ExportOptions();
                        DiskFileDestinationOptions diskFileDestinationOptions = new DiskFileDestinationOptions();

                        string fileName = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
                        fileName += "\\" + item.FileName;

                        diskFileDestinationOptions.DiskFileName = fileName;
                        options.ExportFormatType         = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat;
                        options.ExportDestinationType    = CrystalDecisions.Shared.ExportDestinationType.DiskFile;
                        options.ExportDestinationOptions = diskFileDestinationOptions;

                        report.Export(options);

                        System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();

                        mail.To.Add(new MailAddress(cliente.Email, cliente.Nombre));
                        mail.From    = new MailAddress(SettingsMng.Instance.GetSMTPMail(), empresa.Name);
                        mail.Body    = String.Format(Resources.Messages.FACTURA_EMAIL_ATTACHMENT_BODY, empresa.Name);
                        mail.Subject = Resources.Messages.FACTURA_EMAIL_SUBJECT;
                        mail.Attachments.Add(new Attachment(fileName));

                        try
                        {
                            Thread mailThread = new Thread(SendMailDelegate);
                            mailThread.Start(mail);
                            while (mailThread.IsAlive)
                            {
                                ;
                            }

                            linea.Observaciones = linea.Descripcion;
                            linea.Descripcion   = String.Format(Resources.Messages.FACTURA_EMAIL_OK, item.NFactura);
                        }
                        catch (Exception ex)
                        {
                            linea.Observaciones = linea.Descripcion;
                            linea.Descripcion   = String.Format(Resources.Messages.FACTURA_EMAIL_ERROR, item.NFactura);
                            registro.Save();
                            throw new iQException(ex.Message + Environment.NewLine + Environment.NewLine + moleQule.Library.Resources.Errors.SMTP_SETTINGS);
                        }
                        finally
                        {
                            mail.Dispose();
                            try { File.Delete(fileName); }
                            catch (Exception ex) { string a = ex.Message; }
                        }
                    }
                }

                registro.Save();

                ModulePrincipal.SetFechaUltimoEnvioFacturasPendientes(DateTime.Now);
                AppContext.Principal.SaveSettings();
            }
            catch { }
        }
        /// <summary>
        /// FORMATO: 9999999|G|01/10/2009||VENTAS DIA|4300000001|||||||||VENTAS P.S. DEL DIA|D| |37800| |7050000001|00000|00000|00000|4|001| |36000|500| |1800| |0|4777000000|0| | |0|0| |0| |0| | | | |0|0| |0| |0| | | | |0|0| |0| |0| | | | |0|0| |0| |0| | | | |0|0| |0| |0| | | | | | | | | | |1234| | | |0
        /// </summary>
        /// <param name="factura"></param>
        protected override void BuildChargeAccountingEntry(ChargeInfo cobro, LineaRegistro lr)
        {
            if (cobro.EEstadoCobro != EEstado.Charged)
            {
                return;
            }

            ClienteInfo       titular = _clients.GetItem(cobro.OidCliente);
            OutputInvoiceInfo factura;

            string apunte      = string.Empty;
            string descripcion = string.Empty;
            string tipo        = "H";
            string signo       = "-";
            string importe     = string.Empty;

            if (titular.CuentaContable == string.Empty)
            {
                throw new iQException("El cliente nº " + titular.NumeroClienteLabel + " (" + titular.Nombre + ") no tiene cuenta contable asociada");
            }

            foreach (CobroFacturaInfo cf in cobro.CobroFacturas)
            {
                factura     = _invoices.GetItem(cf.OidFactura);
                tipo        = "H";
                signo       = "-";
                descripcion = "Cobro Fra. " + factura.NFactura + " (" + factura.Cliente + ")";
                importe     = cf.Cantidad.ToString().Replace(".", string.Empty);

                //apunte en la cuenta del cliente
                apunte += AddValue(_config.Empresa);                                    /*CODIGO DE EMPRESA*/
                apunte += AddValue("S");                                                /*TIPO DE REGISTRO*/
                apunte += AddValue(cobro.Fecha.ToShortDateString());                    /*FECHA*/
                apunte += AddEmptyValue(1);                                             /*Nº SERIE DOCUMENTO*/
                apunte += AddValue(cobro.Codigo);                                       /*DOCUMENTO*/
                apunte += AddValue(titular.CuentaContable);                             /*CUENTA*/
                apunte += AddEmptyValue(8);                                             /*SIN USO*/
                apunte += AddValue(descripcion);                                        /*DESCRIPCION*/
                apunte += AddValue(tipo.ToString());                                    /*TIPO: DEBE=1, HABER=2*/
                apunte += AddValue(signo);                                              /*SIGNO*/
                apunte += AddValue(importe);                                            /*IMPORTE*/
                apunte += AddValue(_accounting_entry.ToString());                       /*ASIENTO*/
                apunte += AddEmptyValue(73);                                            /*SIN USO*/
                apunte += AddValue(_config.CentroTrabajo);                              /*CENTRO TRABAJO*/
                apunte += AddEmptyValue(2);                                             /*SIN USO*/
                apunte += AddValue(lr.IDExportacion);                                   /*OPC. 1*/

                _export_file.WriteLine(apunte);

                apunte  = string.Empty;
                tipo    = "D";
                signo   = "+";
                importe = cf.Cantidad.ToString().Replace(".", string.Empty);

                //apunte en la cuenta del pago
                apunte += AddValue(_config.Empresa);                                    /*CODIGO DE EMPRESA*/
                apunte += AddValue("G");                                                /*TIPO DE REGISTRO*/
                apunte += AddValue(cobro.Fecha.ToShortDateString());                    /*FECHA*/
                apunte += AddEmptyValue(1);                                             /*Nº SERIE DOCUMENTO*/
                apunte += AddValue(cobro.Codigo);                                       /*DOCUMENTO*/
                apunte += AddValue(GetChargeAccount(cobro));                            /*CUENTA*/
                apunte += AddEmptyValue(8);                                             /*SIN USO*/
                apunte += AddValue(descripcion);                                        /*DESCRIPCION*/
                apunte += AddValue(tipo.ToString());                                    /*TIPO: DEBE=1, HABER=2*/
                apunte += AddValue(signo);                                              /*SIGNO*/
                apunte += AddValue(importe);                                            /*IMPORTE*/
                apunte += AddValue(_accounting_entry.ToString());                       /*ASIENTO*/
                apunte += AddEmptyValue(73);                                            /*SIN USO*/
                apunte += AddValue(_config.CentroTrabajo);                              /*CENTRO TRABAJO*/
                apunte += AddEmptyValue(2);                                             /*SIN USO*/
                apunte += AddValue(lr.IDExportacion);                                   /*OPC. 1*/

                _export_file.WriteLine(apunte);

                apunte = string.Empty;
            }
        }