diff --git a/Database/scripts/factuges.sql b/Database/scripts/factuges.sql index 47195c96..7d912e77 100644 --- a/Database/scripts/factuges.sql +++ b/Database/scripts/factuges.sql @@ -3355,7 +3355,7 @@ SELECT RECIBOS_CLIENTE.ID, COALESCE(RECIBOS_CLIENTE.IMPORTE, 0) + COALESCE(RECIBOS_CLIENTE.OTROS_GASTOS, 0) + COALESCE(V_REC_CLI_COMPENSADOS.IMPORTE_TOTAL_COMPENSADO, 0), FACTURAS_CLIENTE.FECHA_FACTURA, FORMAS_PAGO.DESCRIPCION, FACTURAS_CLIENTE.IMPORTE_TOTAL, - FACTURAS_CLIENTE.ID_EMPRESA, + RECIBOS_CLIENTE.ID_EMPRESA, CONTACTOS.ID as ID_CLIENTE, CONTACTOS.NOMBRE, CONTACTOS.NIF_CIF, CONTACTOS_DATOS_BANCO.ENTIDAD, CONTACTOS_DATOS_BANCO.SUCURSAL, CONTACTOS_DATOS_BANCO.DC, CONTACTOS_DATOS_BANCO.CUENTA, diff --git a/Source/Modulos/Recibos de cliente/Controller/uRecibosClienteController.pas b/Source/Modulos/Recibos de cliente/Controller/uRecibosClienteController.pas index acd69d50..c69c8283 100644 --- a/Source/Modulos/Recibos de cliente/Controller/uRecibosClienteController.pas +++ b/Source/Modulos/Recibos de cliente/Controller/uRecibosClienteController.pas @@ -714,36 +714,52 @@ var begin Result := False; - ANuevoReciboCliente := NIL; - ImporteRestante := 0; - - if ValidarReciboCliente(ARecibosCliente) then + if ARecibosCliente.EsNuevo then begin + if ValidarReciboCliente(ARecibosCliente) then + begin ShowHourglassCursor; try - //Si el importe ha cambiado se debe hacer un recibo nuevo con el importe restante - if ImporteTotalModificado(ARecibosCliente, ImporteRestante) then - begin - ANuevoReciboCliente := Duplicar(ARecibosCliente); - ANuevoReciboCliente.Edit; - ANuevoReciboCliente.REFERENCIA := DarNuevaReferencia(ARecibosCliente.ID_FACTURA, ARecibosCliente.REFERENCIA); - ANuevoReciboCliente.IMPORTE := ImporteRestante; - ANuevoReciboCliente.DESCRIPCION := 'RECIBO ' + ANuevoReciboCliente.REFERENCIA + ' - ' + CifraToLetras(ImporteRestante); - ANuevoReciboCliente.Post; - end; - - //Primero debemos hacer el ApplyUpdates del recibo inicial por si fallase - //Así no se haría el nuevo ARecibosCliente.DataTable.ApplyUpdates; - - if Assigned(ANuevoReciboCliente) then - ANuevoReciboCliente.DataTable.ApplyUpdates; - Result := True; finally - ANuevoReciboCliente := NIL; HideHourglassCursor; end; + end; + end + else + begin + ANuevoReciboCliente := NIL; + ImporteRestante := 0; + + if ValidarReciboCliente(ARecibosCliente) then + begin + ShowHourglassCursor; + try + //Si el importe ha cambiado se debe hacer un recibo nuevo con el importe restante + if ImporteTotalModificado(ARecibosCliente, ImporteRestante) then + begin + ANuevoReciboCliente := Duplicar(ARecibosCliente); + ANuevoReciboCliente.Edit; + ANuevoReciboCliente.REFERENCIA := DarNuevaReferencia(ARecibosCliente.ID_FACTURA, ARecibosCliente.REFERENCIA); + ANuevoReciboCliente.IMPORTE := ImporteRestante; + ANuevoReciboCliente.DESCRIPCION := 'RECIBO ' + ANuevoReciboCliente.REFERENCIA + ' - ' + CifraToLetras(ImporteRestante); + ANuevoReciboCliente.Post; + end; + + //Primero debemos hacer el ApplyUpdates del recibo inicial por si fallase + //Así no se haría el nuevo + ARecibosCliente.DataTable.ApplyUpdates; + + if Assigned(ANuevoReciboCliente) then + ANuevoReciboCliente.DataTable.ApplyUpdates; + + Result := True; + finally + ANuevoReciboCliente := NIL; + HideHourglassCursor; + end; + end; end; end; diff --git a/Source/Modulos/Recibos de cliente/Model/uBizRecibosCliente.pas b/Source/Modulos/Recibos de cliente/Model/uBizRecibosCliente.pas index 0aa6167e..fe2aef48 100644 --- a/Source/Modulos/Recibos de cliente/Model/uBizRecibosCliente.pas +++ b/Source/Modulos/Recibos de cliente/Model/uBizRecibosCliente.pas @@ -109,7 +109,7 @@ implementation { TBizRecibosCliente } uses - SysUtils, uDataTableUtils, schContactosClient_Intf; + SysUtils, uDataTableUtils, schContactosClient_Intf, uFactuGES_App, uBizEmpresasTiendas; function TBizRecibosCliente.GetCliente: IBizCliente; begin @@ -200,6 +200,10 @@ begin FECHA_EMISION := Date; IMPORTE := 0; OTROS_GASTOS := 0; + ID_EMPRESA := AppFactuGES.EmpresaActiva.ID; + USUARIO := AppFactuGES.UsuarioActivo.UserName; + ID_TIENDA := CTE_ID_TODAS; +// TIENDA := CTE_TODAS; end; procedure TBizRecibosCliente.OnNewRecord(Sender: TDADataTable);