diff --git a/Database/scripts/factuges.sql b/Database/scripts/factuges.sql index 69133064..d8933497 100644 --- a/Database/scripts/factuges.sql +++ b/Database/scripts/factuges.sql @@ -632,7 +632,6 @@ CREATE TABLE CONT_APUNTES ( HABER TIPO_IMPORTE ); - CREATE TABLE CONT_ASIENTOS ( ID TIPO_ID NOT NULL, FECHA_ASIENTO DATE, @@ -4073,8 +4072,8 @@ begin RECIBOS_CLIENTE.IMPORTE, CONT_SUBCUENTAS.ID, CONT_SUBCUENTAS.ID_EJERCICIO FROM PAGOS_CLIENTE LEFT JOIN RECIBOS_CLIENTE ON (RECIBOS_CLIENTE.ID = PAGOS_CLIENTE.ID_RECIBO) - LEFT JOIN FACTURAS_CLIENTE ON (FACTURAS_CLIENTE.ID = RECIBOS_CLIENTE.ID_FACTURA) - LEFT JOIN CONT_SUBCUENTAS ON (CONT_SUBCUENTAS.ID_CONTACTO = FACTURAS_CLIENTE.ID_CLIENTE) +/* LEFT JOIN FACTURAS_CLIENTE ON (FACTURAS_CLIENTE.ID = RECIBOS_CLIENTE.ID_FACTURA) (ya no esta atado a las facturas)*/ + LEFT JOIN CONT_SUBCUENTAS ON (CONT_SUBCUENTAS.ID_CONTACTO = RECIBOS_CLIENTE.ID_CLIENTE) WHERE PAGOS_CLIENTE.ID = :IDPAGO INTO :IGNORARCONTABILIDAD, :REFERENCIARECIBO, :FECHAPAGO, :TIPOPAGO, :IMPORTE, :IDSUBCUENTA, :IDEJERCICIO; @@ -4408,3 +4407,12 @@ end SET TERM ; ^ + + + +/* Fields descriptions */ + +COMMENT ON COLUMN CONT_ASIENTOS.TIPO IS +'Tipo de asiento +''c'' cobro +''p'' pago'; diff --git a/Source/Base/Base.dproj b/Source/Base/Base.dproj index 5df5fbb9..04cef2f8 100644 --- a/Source/Base/Base.dproj +++ b/Source/Base/Base.dproj @@ -58,48 +58,48 @@ MainSource + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
fConfigurarConexion
TForm diff --git a/Source/Modulos/Contabilidad/Contabilidad_Group.groupproj b/Source/Modulos/Contabilidad/Contabilidad_Group.groupproj index d2e89d03..e6543a8a 100644 --- a/Source/Modulos/Contabilidad/Contabilidad_Group.groupproj +++ b/Source/Modulos/Contabilidad/Contabilidad_Group.groupproj @@ -11,6 +11,7 @@ + @@ -53,6 +54,15 @@ + + + + + + + + + @@ -162,13 +172,13 @@ - + - + - + \ No newline at end of file diff --git a/Source/Modulos/Contabilidad/Controller/uSubCuentasController.pas b/Source/Modulos/Contabilidad/Controller/uSubCuentasController.pas index 3a4ac989..0702b596 100644 --- a/Source/Modulos/Contabilidad/Controller/uSubCuentasController.pas +++ b/Source/Modulos/Contabilidad/Controller/uSubCuentasController.pas @@ -10,11 +10,13 @@ uses const // (REF_CUENTA = 430 SOLO CUENTAS DE CLIENTES) // (REF_CUENTA = 400 SOLO CUENTAS DE PROVEEDORES) - // (REF_CUENTA = 570 SOLO CUENTAS DE CLIENTES) - // (REF_CUENTA = 400 SOLO CUENTAS DE PROVEEDORES) + // (REF_CUENTA = 570 SOLO CUENTAS DE CAJA) + // (REF_CUENTA = 572 SOLO CUENTAS DE BANCO) - CTE_CUENTASCLIENTE = '430'; - CTE_CUENTASPROVEEDOR = '400'; + CTE_CUENTASCLIENTE = 430; + CTE_CUENTASPROVEEDOR = 400; + CTE_CUENTASCAJA = 570; + CTE_CUENTASBANCO = 572; type ISubCuentasController = interface(IObservador) @@ -35,15 +37,18 @@ type function ElegirSubCuenta(ASubCuentas : IBizSubCuenta; AMensaje: String; AMultiSelect: Boolean): IBizSubCuenta; procedure ElegirCuenta(ASubCuenta: IBizSubCuenta); - procedure ElegirSubCuentaContacto(ASubCuentaContacto: IBizSubCuentasContacto; TipoCuenta: String); + procedure ElegirSubCuentaContacto(ASubCuentaContacto: IBizSubCuentasContacto; TipoCuenta: Integer); procedure VerSubCuentaContacto(ASubCuentaContacto: IBizSubCuentasContacto); - procedure AnadirSubCuentaContacto(ASubCuentaContacto: IBizSubCuentasContacto; TipoCuenta: String); + procedure AnadirSubCuentaContacto(ASubCuentaContacto: IBizSubCuentasContacto; TipoCuenta: Integer); procedure EliminarSubCuentaContacto(ASubCuentaContacto: IBizSubCuentasContacto); + + function DarListaCajasBancos: TStringList; end; TSubCuentasController = class(TObservador, ISubCuentasController) private - function BuscarCuentas(TipoCuenta: String): IBizSubCuenta; + function BuscarCuentas(const REF_CUENTA: Integer): IBizSubCuenta; + function BuscarCuentasLibres(TipoCuenta: Integer): IBizSubCuenta; procedure AsignarSubCuentaAContacto(ASubCuenta: IBizSubCuenta; ASubCuentaContacto: IBizSubCuentasContacto); protected @@ -66,6 +71,7 @@ type procedure Anadir(ASubCuenta : IBizSubCuenta); function Nuevo : IBizSubCuenta; function BuscarTodos: IBizSubCuenta; + function BuscarCajasBancos: IBizSubCuenta; function Buscar(ID: Integer): IBizSubCuenta; procedure VerTodos(ASubCuentas: IBizSubCuenta); procedure Ver(ASubCuenta: IBizSubCuenta); @@ -76,10 +82,12 @@ type function ElegirSubCuenta(ASubCuentas : IBizSubCuenta; AMensaje: String; AMultiSelect: Boolean): IBizSubCuenta; procedure ElegirCuenta(ASubCuenta: IBizSubCuenta); - procedure ElegirSubCuentaContacto(ASubCuentaContacto: IBizSubCuentasContacto; TipoCuenta: String); + procedure ElegirSubCuentaContacto(ASubCuentaContacto: IBizSubCuentasContacto; TipoCuenta: Integer); procedure VerSubCuentaContacto(ASubCuentaContacto: IBizSubCuentasContacto); - procedure AnadirSubCuentaContacto(ASubCuentaContacto: IBizSubCuentasContacto; TipoCuenta: String); + procedure AnadirSubCuentaContacto(ASubCuentaContacto: IBizSubCuentasContacto; TipoCuenta: Integer); procedure EliminarSubCuentaContacto(ASubCuentaContacto: IBizSubCuentasContacto); + + function DarListaCajasBancos: TStringList; end; implementation @@ -98,7 +106,7 @@ begin ASubCuenta.Insert; end; -procedure TSubCuentasController.AnadirSubCuentaContacto(ASubCuentaContacto: IBizSubCuentasContacto; TipoCuenta: String); +procedure TSubCuentasController.AnadirSubCuentaContacto(ASubCuentaContacto: IBizSubCuentasContacto; TipoCuenta: Integer); var ASubCuenta: IBizSubCuenta; begin @@ -150,10 +158,12 @@ begin end; end; -function TSubCuentasController.BuscarCuentas(TipoCuenta: String): IBizSubCuenta; +function TSubCuentasController.BuscarCajasBancos: IBizSubCuenta; var + Condicion: TDAWhereExpression; Condicion1: TDAWhereExpression; Condicion2: TDAWhereExpression; + begin ShowHourglassCursor; try @@ -161,16 +171,63 @@ begin with Result.DataTable.DynamicWhere do begin - // (REF_CUENTA = 430/400) (SOLO CUENTAS DE CLIENTES, PROVEEDORES QUE ESTEN SIN ASIGNAR) - Condicion1 := NewBinaryExpression(NewField('', fld_SubCuentasREF_CUENTA), NewConstant(TipoCuenta, datString), dboEqual); - Condicion2 := NewBinaryExpression(NewField('', fld_SubCuentasID_CONTACTO), NewNull(), dboEqual); + // (REF_CUENTAS = 570 cajas) + Condicion1 := NewBinaryExpression(NewField('', fld_SubCuentasREF_CUENTA), NewConstant(CTE_CUENTASCAJA, datInteger), dboEqual); + // (REF_CUENTAS = 572 bancos) + Condicion2 := NewBinaryExpression(NewField('', fld_SubCuentasREF_CUENTA), NewConstant(CTE_CUENTASBANCO, datInteger), dboEqual); + Condicion := NewBinaryExpression(Condicion1, Condicion2, dboOr); if IsEmpty then - Expression := Condicion1 + Expression := Condicion else - Expression := NewBinaryExpression(Expression, Condicion1, dboAnd); + Expression := NewBinaryExpression(Expression, Condicion, dboAnd); + end; - Expression := NewBinaryExpression(Expression, Condicion2, dboAnd); + finally + HideHourglassCursor; + end; +end; + +function TSubCuentasController.BuscarCuentas(const REF_CUENTA: Integer): IBizSubCuenta; +var + Condicion: TDAWhereExpression; +begin + ShowHourglassCursor; + try + Result := BuscarTodos; + + with Result.DataTable.DynamicWhere do + begin + // (REF_CUENTA = 430 CLIENTES/400 PROVEEDORES/570 CAJAS/572 BANCOS) + Condicion := NewBinaryExpression(NewField('', fld_SubCuentasREF_CUENTA), NewConstant(REF_CUENTA, datInteger), dboEqual); + + if IsEmpty then + Expression := Condicion + else + Expression := NewBinaryExpression(Expression, Condicion, dboAnd); + end; + + finally + HideHourglassCursor; + end; +end; + +function TSubCuentasController.BuscarCuentasLibres(TipoCuenta: Integer): IBizSubCuenta; +var + Condicion: TDAWhereExpression; +begin + ShowHourglassCursor; + try + Result := BuscarCuentas(TipoCuenta); + + with Result.DataTable.DynamicWhere do + begin + Condicion := NewBinaryExpression(NewField('', fld_SubCuentasID_CONTACTO), NewNull(), dboEqual); + + if IsEmpty then + Expression := Condicion + else + Expression := NewBinaryExpression(Expression, Condicion, dboAnd); end; finally @@ -195,6 +252,31 @@ begin Result := Supports(EditorRegistry.CreateEditor(AName), IID, Intf); end; +function TSubCuentasController.DarListaCajasBancos: TStringList; +var + ACajasBancos: IBizSubCuenta; + i : integer; +begin + + ACajasBancos := BuscarCajasBancos; + ACajasBancos.DataTable.Active := True; + + Result := TStringList.Create; + try + with Result do + begin + ACajasBancos.DataTable.First; + while not ACajasBancos.DataTable.EOF do + begin + Add(Format('%s=%d', [ACajasBancos.DESCRIPCION, ACajasBancos.ID])); + ACajasBancos.DataTable.Next; + end; + end; + finally + ACajasBancos := NIL; + end; +end; + function TSubCuentasController.DarListaSubCuentas: TStringList; var ASubCuentas: IBizSubCuenta; @@ -376,11 +458,12 @@ begin end; end; -procedure TSubCuentasController.ElegirSubCuentaContacto(ASubCuentaContacto: IBizSubCuentasContacto; TipoCuenta: String); +procedure TSubCuentasController.ElegirSubCuentaContacto(ASubCuentaContacto: IBizSubCuentasContacto; TipoCuenta: Integer); var ASubCuenta: IBizSubCuenta; begin - ASubCuenta := BuscarCuentas(TipoCuenta); + ASubCuenta := BuscarCuentasLibres(TipoCuenta); + if (TipoCuenta = CTE_CUENTASCLIENTE) then ASubCuenta := ElegirSubCuenta(ASubCuenta, 'El cliente debe tener una subcuenta asociada', False) else diff --git a/Source/Modulos/Contabilidad/Servidor/srvContabilidad_Impl.dfm b/Source/Modulos/Contabilidad/Servidor/srvContabilidad_Impl.dfm index 74151962..ddb571be 100644 --- a/Source/Modulos/Contabilidad/Servidor/srvContabilidad_Impl.dfm +++ b/Source/Modulos/Contabilidad/Servidor/srvContabilidad_Impl.dfm @@ -338,6 +338,41 @@ object srvContabilidad: TsrvContabilidad DataDictionary = DataDictionary Diagrams = Diagrams Datasets = < + item + Params = < + item + Name = 'REFERENCIA' + Value = '' + ParamType = daptInput + end + item + Name = 'ID_EJERCICIO' + Value = '' + ParamType = daptInput + end> + Statements = < + item + Connection = 'IBX' + ConnectionType = 'Interbase' + Default = True + Name = 'IBX' + SQL = + 'select ID'#10'from cont_cuentas'#10'where ref_cuenta = :REFERENCIA'#10'and i' + + 'd_ejercicio = :ID_EJERCICIO'#10#10#10 + StatementType = stSQL + ColumnMappings = < + item + DatasetField = 'ID' + TableField = 'ID' + end> + end> + Name = 'DarIDCuenta' + Fields = < + item + Name = 'ID' + DataType = datInteger + end> + end item Params = < item diff --git a/Source/Modulos/Contabilidad/Servidor/srvContabilidad_Impl.pas b/Source/Modulos/Contabilidad/Servidor/srvContabilidad_Impl.pas index e516dc0b..385d3882 100644 --- a/Source/Modulos/Contabilidad/Servidor/srvContabilidad_Impl.pas +++ b/Source/Modulos/Contabilidad/Servidor/srvContabilidad_Impl.pas @@ -10,7 +10,7 @@ unit srvContabilidad_Impl; interface uses - {vcl:} Classes, SysUtils, + {vcl:} Classes, SysUtils, {RemObjects:} uROClientIntf, uROTypes, uROServer, uROServerIntf, uROSessions, {Ancestor Implementation:} DataAbstractService_Impl, {Used RODLs:} DataAbstract4_Intf, @@ -41,9 +41,8 @@ type public function TieneCuentaAsociada(const ID_CONTACTO: Integer; const ID_EMPRESA: Integer): Boolean; - function AnadirSubCuentaCliente(const ID_CONTACTO: Integer; const ID_TIENDA: Integer; const ID_EMPRESA: Integer): Boolean; - function AnadirSubCuentaProveedor(const ID_CONTACTO: Integer; const ID_TIENDA: Integer; const ID_EMPRESA: Integer): Boolean; - + function AnadirSubCuentaCliente(const ID_CONTACTO: Integer; const ID_TIENDA: Integer; const ID_EMPRESA: Integer; const CLIENTE: String): Boolean; + function AnadirSubCuentaProveedor(const ID_CONTACTO: Integer; const ID_TIENDA: Integer; const ID_EMPRESA: Integer; const PROVEEDOR: String): Boolean; end; implementation @@ -59,7 +58,7 @@ begin end; { srvContabilidad } -function TsrvContabilidad.AnadirSubCuentaCliente(const ID_CONTACTO, ID_TIENDA: Integer; const ID_EMPRESA: Integer): Boolean; +function TsrvContabilidad.AnadirSubCuentaCliente(const ID_CONTACTO, ID_TIENDA: Integer; const ID_EMPRESA: Integer; const CLIENTE: String): Boolean; var AConn : IDAConnection; dsData: IDADataset; @@ -69,7 +68,7 @@ var NumCuenta: Integer; RefTienda: String; NumTienda: Integer; - + IDCuenta: Integer; begin Result := False; @@ -101,6 +100,15 @@ begin RefTienda := format('%.2d', [NumTienda]); RefSubCuenta := IntToStr(REFERENCIA_CLIENTES) + RefTienda + RefSubCuenta; dsData := NIL; + + dsData := schContabilidad.NewDataset(AConn, 'DarIDCuenta', ['ID_EJERCICIO', 'REFERENCIA'], [darEjercicioActivo(ID_EMPRESA), REFERENCIA_CLIENTES]); + dsData.Active := True; + + if VarIsNull(dsData.FieldValues[0]) then + IDCuenta := 0 + else + IDCuenta := dsData.FieldValues[0]; + AConn.CommitTransaction; except @@ -111,16 +119,14 @@ begin dsData := NIL; end; -// AConn := dmServer.ConnectionManager.NewConnection(dmServer.ConnectionManager.GetDefaultConnectionName); - try try dsCommand := schContabilidad.NewCommand(AConn, 'AnadirSubCuenta'); with dsCommand do begin ParamByName('REFERENCIA').AsString := RefSubCuenta; - ParamByName('DESCRIPCION').AsString := 'Cuenta de Clieeeeeeeeeeeeeeeeeeeeeeente'; - ParamByName('ID_CUENTA').AsInteger := 1; + ParamByName('DESCRIPCION').AsString := 'Cuenta de cliente ' + CLIENTE; + ParamByName('ID_CUENTA').AsInteger := IDCuenta; ParamByName('ID_EJERCICIO').AsInteger := darEjercicioActivo(ID_EMPRESA); ParamByName('ID_CONTACTO').AsInteger := ID_CONTACTO; end; @@ -136,9 +142,88 @@ begin end; end; -function TsrvContabilidad.AnadirSubCuentaProveedor(const ID_CONTACTO, ID_TIENDA: Integer; const ID_EMPRESA: Integer): Boolean; +function TsrvContabilidad.AnadirSubCuentaProveedor(const ID_CONTACTO, ID_TIENDA: Integer; const ID_EMPRESA: Integer; const PROVEEDOR: String): Boolean; +var + AConn : IDAConnection; + dsData: IDADataset; + dsCommand: IDASQLCommand; + + RefSubCuenta: String; + NumCuenta: Integer; + RefTienda: String; + NumTienda: Integer; + IDCuenta: Integer; + begin - Result := True; + Result := False; + + AConn := dmServer.ConnectionManager.NewConnection(dmServer.ConnectionManager.GetDefaultConnectionName); + + try + try + dsData := schContabilidad.NewDataset(AConn, 'DarMaxRefSubCuenta', ['ID_EJERCICIO', 'REF_CUENTA'], [darEjercicioActivo(ID_EMPRESA), REFERENCIA_PROVEEDORES]); + dsData.Active := True; + + if VarIsNull(dsData.FieldValues[0]) then + NumCuenta := 0 + else + NumCuenta := dsData.FieldValues[0]; + + Inc(NumCuenta); + RefSubCuenta := format('%.5d', [NumCuenta]); + dsData := NIL; + + dsData := schContabilidad.NewDataset(AConn, 'DarCodigoContableTienda', ['ID_EMPRESA', 'ID_TIENDA'], [ID_EMPRESA, ID_TIENDA]); + dsData.Active := True; + + if VarIsNull(dsData.FieldValues[0]) then + NumTienda := 0 + else + NumTienda := dsData.FieldValues[0]; + + RefTienda := format('%.2d', [NumTienda]); + RefSubCuenta := IntToStr(REFERENCIA_PROVEEDORES) + RefTienda + RefSubCuenta; + dsData := NIL; + + dsData := schContabilidad.NewDataset(AConn, 'DarIDCuenta', ['ID_EJERCICIO', 'REFERENCIA'], [darEjercicioActivo(ID_EMPRESA), REFERENCIA_PROVEEDORES]); + dsData.Active := True; + + if VarIsNull(dsData.FieldValues[0]) then + IDCuenta := 0 + else + IDCuenta := dsData.FieldValues[0]; + + AConn.CommitTransaction; + + except + RaiseError('Error al buscar nueva referencia para la subcuenta'); + AConn.RollbackTransaction; + end; + finally + dsData := NIL; + end; + + try + try + dsCommand := schContabilidad.NewCommand(AConn, 'AnadirSubCuenta'); + with dsCommand do + begin + ParamByName('REFERENCIA').AsString := RefSubCuenta; + ParamByName('DESCRIPCION').AsString := 'Cuenta de proveedor ' + PROVEEDOR; + ParamByName('ID_CUENTA').AsInteger := IDCuenta; + ParamByName('ID_EJERCICIO').AsInteger := darEjercicioActivo(ID_EMPRESA); + ParamByName('ID_CONTACTO').AsInteger := ID_CONTACTO; + end; + dsCommand.Execute; + AConn.CommitTransaction; + Result := True; + except + RaiseError('Error al crear la nueva subcuenta en tablas'); + AConn.RollbackTransaction; + end; + finally + dsCommand := NIL; + end; end; function TsrvContabilidad.darEjercicioActivo(const ID_EMPRESA: Integer): Integer; diff --git a/Source/Modulos/Contabilidad/Views/Contabilidad_view.dpk b/Source/Modulos/Contabilidad/Views/Contabilidad_view.dpk index f1409a04..5a0044f9 100644 --- a/Source/Modulos/Contabilidad/Views/Contabilidad_view.dpk +++ b/Source/Modulos/Contabilidad/Views/Contabilidad_view.dpk @@ -29,7 +29,23 @@ requires GUIBase, ApplicationBase, Contabilidad_model, - Contabilidad_controller; + Contabilidad_controller, + vcl, + rtl, + dbrtl, + DataAbstract_Core_D11, + vcldb, + dsnap, + adortl, + RemObjects_Core_D11, + cxLibraryD11, + dxThemeD11, + dxGDIPlusD11, + cxEditorsD11, + cxDataD11, + vcljpg, + dxLayoutControlD11, + dxComnD11; contains uEditorBalance in 'uEditorBalance.pas' {fEditorBalance: TfEditorBalances}, @@ -61,6 +77,7 @@ contains uViewApuntes in 'uViewApuntes.pas' {frViewApuntes: TFrame}, uEditorAsiento in 'uEditorAsiento.pas' {fEditorAsiento: TfEditorEjercicios}, uEditorApunte in 'uEditorApunte.pas' {fEditorApunte: TfEditorEjercicios}, - uEditorElegirSubCuentas in 'uEditorElegirSubCuentas.pas' {fEditorElegirSubCuentas: TfEditorEjercicios}; + uEditorElegirSubCuentas in 'uEditorElegirSubCuentas.pas' {fEditorElegirSubCuentas: TfEditorEjercicios}, + uViewCajasBancos in 'uViewCajasBancos.pas' {frViewCajasBancos: TFrame}; end. diff --git a/Source/Modulos/Contabilidad/Views/Contabilidad_view.dproj b/Source/Modulos/Contabilidad/Views/Contabilidad_view.dproj index 359fb8bf..86646d53 100644 --- a/Source/Modulos/Contabilidad/Views/Contabilidad_view.dproj +++ b/Source/Modulos/Contabilidad/Views/Contabilidad_view.dproj @@ -48,10 +48,23 @@ MainSource - - - - + + + + + + + + + + + + + + + + +
frViewEpigrafes
TFrame @@ -140,6 +153,10 @@
frViewBalances
TFrame
+ +
frViewApunte
+ TFrame +
frViewCuenta
TFrame @@ -172,6 +189,9 @@
frViewSubCuentas
TFrame
+ + +