2010-08-11 10:53:06 +00:00
unit uGenerarFacturasCliAlbCliUtils;
interface
uses
Windows, SysUtils, Classes, uBizAlbaranesCliente, uBizFacturasCliente, pngimage, JSDialog;
type
TdmGenerarFacturasCliAlbCli = class( TDataModule)
JsListaFacturasGeneradas: TJSDialog;
2014-01-17 16:36:10 +00:00
JsCambioSucursalCentral: TJSDialog;
2010-08-11 10:53:06 +00:00
end ;
2014-01-17 16:36:10 +00:00
function GenerarFacturaCliAlb : Boolean ; overload ;
function GenerarFacturaCliAlb( AAlbaran : IBizAlbaranCliente; const CopiarDetalles: Boolean = True ) : Boolean ; overload ;
2010-08-11 10:53:06 +00:00
function GenerarFacturaCliAlb( const IDAlbaran : Integer ; const CopiarDetalles: Boolean = True ) : Boolean ; overload ;
2010-10-06 10:32:34 +00:00
function GenerarFacturaCliAlb( AAlbaran : IBizAlbaranCliente; FechaFacturaNueva: TDateTime; const CopiarDetalles: Boolean = True ) : Boolean ; overload ;
2014-01-17 16:36:10 +00:00
2010-08-11 10:53:06 +00:00
2010-10-06 10:32:34 +00:00
function GenerarFacturas( AFacturas : IBizFacturaCliente; AListaAlbaranes : IBizAlbaranCliente; FechaFacturaNueva: TDateTime; const CopiarDetalles: Boolean = True ) : Boolean ;
2010-08-11 10:53:06 +00:00
implementation
{$R *.dfm}
uses
2010-10-06 10:32:34 +00:00
DB, uDialogUtils, uDADataTable, uControllerDetallesBase, uEditorFechaFactura,
2010-08-11 10:53:06 +00:00
uBizDetallesFacturaCliente, uBizDetallesAlbaranCliente,
uAlbaranesClienteController, uDetallesFacturaClienteController,
2014-01-17 16:36:10 +00:00
uFacturasClienteController, schFacturasClienteClient_Intf, schAlbaranesClienteClient_Intf,
uClientesController, uBizContactos, Controls;
2010-08-11 10:53:06 +00:00
// ,
// , uProveedoresController,
// , uControllerDetallesBase,
// , uBizContactos, ,
// ;
var
dmGenerarFacturasCliAlbCli: TdmGenerarFacturasCliAlbCli;
AFacturasClienteController : IFacturasClienteController;
AAlbaranesClienteController : IAlbaranesClienteController;
ADetallesAlbaranesClienteController : IDetallesFacturaClienteController;
{ M<> todos auxiliares }
2014-01-17 16:36:10 +00:00
procedure _CambiarFacturasClientesConSucursales( AListaFacturas : IBizFacturaCliente) ;
var
Respuesta, i: integer ;
AClientesController : IClientesController;
ACliente, ACentral : IBizCliente;
begin
if Assigned( AListaFacturas) then
begin
AListaFacturas. Open;
AListaFacturas. First;
try
AClientesController : = TClientesController. Create;
while not AListaFacturas. EOF do
begin
ACliente : = AClientesController. Buscar( AListaFacturas. ID_CLIENTE) as IBizCliente;
ACliente. Open;
if AClientesController. TieneClienteCentral( ACliente) then
begin
ACentral : = AClientesController. Buscar( ACliente. ID_CENTRAL) as IBizCliente;
ACentral. Open;
with dmGenerarFacturasCliAlbCli. JsCambioSucursalCentral do
begin
Instruction. Text : = 'Cambio de cliente en la factura generada' ;
2014-02-06 18:44:21 +00:00
Content. Text : = 'El cliente "' + ACliente. NOMBRE + '" tiene como sucursal central a "' + ACentral. NOMBRE + '". Puede cambiar la factura para cambiar el cliente a la central, se aplicar<61> n los descuentos de la central.' ;
2014-01-17 16:36:10 +00:00
CustomButtons[ 0 ] . Caption : = 'No cambiar la factura' ;
CustomButtons[ 0 ] . Info. Clear;
CustomButtons[ 0 ] . Info. Add( 'La factura es para el cliente "' + ACliente. NOMBRE + '".' ) ;
CustomButtons[ 0 ] . Value : = 0 ;
CustomButtons[ 1 ] . Caption : = 'Cambiar la factura' ;
CustomButtons[ 1 ] . Info. Clear;
CustomButtons[ 1 ] . Info. Add( 'Facturar al cliente "' + ACentral. NOMBRE + '".' ) ;
CustomButtons[ 1 ] . Value : = 1 ;
end ;
Respuesta : = dmGenerarFacturasCliAlbCli. JsCambioSucursalCentral. Execute;
if dmGenerarFacturasCliAlbCli. JsCambioSucursalCentral. CustomButtonResult = 1 then
begin
AListaFacturas. Cliente : = ACentral;
2014-02-06 18:44:21 +00:00
2014-01-17 16:36:10 +00:00
AFacturasClienteController. Guardar( AListaFacturas) ;
end ;
end ;
AListaFacturas. Next;
end ;
finally
AClientesController : = NIL ;
ACentral : = NIL ;
ACliente : = NIL ;
end ;
end ;
end ;
2010-08-11 10:53:06 +00:00
{ procedure CopiarPedidoAAlbaran( AAlbaran: IBizPedidoCliente;
AAlbaran : IBizAlbaranProveedor) ;
begin
if not Assigned( AAlbaran) then
raise Exception. Create ( 'Albar<61> n no asignado (CopiarPedidoAAlbaran)' ) ;
if not Assigned( AAlbaran) then
raise Exception. Create ( 'Pedido no asignado (CopiarPedidoAAlbaran)' ) ;
if not AAlbaran. DataTable. Active then
AAlbaran. DataTable. Active : = True ;
// El albar<61> n tiene que venir ya abierto y posicionado donde hay que copiar
AAlbaran. ID_CLIENTE : = AAlbaran. ID_CLIENTE;
AAlbaran. ID_PEDIDO : = AAlbaran. ID;
AAlbaran. CALLE : = AAlbaran. CALLE;
AAlbaran. CODIGO_POSTAL : = AAlbaran. CODIGO_POSTAL;
AAlbaran. POBLACION : = AAlbaran. POBLACION;
AAlbaran. PROVINCIA : = AAlbaran. PROVINCIA;
AAlbaran. PERSONA_CONTACTO : = AAlbaran. PERSONA_CONTACTO;
AAlbaran. TELEFONO : = AAlbaran. TELEFONO;
AAlbaran. IMPORTE_NETO : = AAlbaran. IMPORTE_NETO;
AAlbaran. IMPORTE_PORTE : = AAlbaran. IMPORTE_PORTE;
AAlbaran. DESCUENTO : = AAlbaran. DESCUENTO;
AAlbaran. IMPORTE_DESCUENTO : = AAlbaran. IMPORTE_DESCUENTO;
AAlbaran. BASE_IMPONIBLE : = AAlbaran. BASE_IMPONIBLE;
AAlbaran. IVA : = AAlbaran. IVA;
AAlbaran. IMPORTE_IVA : = AAlbaran. IMPORTE_IVA;
AAlbaran. IMPORTE_TOTAL : = AAlbaran. IMPORTE_TOTAL;
AAlbaran. DataTable. FieldByName( fld_AlbaranesClienteOBSERVACIONES) . AsVariant : = AAlbaran. DataTable. FieldByName( fld_PedidosClienteOBSERVACIONES) . AsVariant;
AAlbaran. ID_FORMA_PAGO : = AAlbaran. ID_FORMA_PAGO;
end ;
procedure CopiarArticulosPendAAlbaran(
AAlbaran: IBizPedidoCliente;
AAlbaran: IBizAlbaranProveedor;
AArticulosPendientes: IBizPedidoClienteArticulosPend) ;
var
i : integer ;
ADetalles : IBizDetallesFacturaClieedor;
ADetallesController : IDetallesFacturaClieedorController;
begin
if not Assigned( AAlbaran) then
raise Exception. Create ( 'Albar<61> n no asignado (CopiarArticulosPendAAlbaran)' ) ;
if not Assigned( AAlbaran) then
raise Exception. Create ( 'Pedido no asignado (CopiarArticulosPendAAlbaran)' ) ;
if not Assigned( AArticulosPendientes) then
raise Exception. Create ( 'Art<72> culos pendientes no asignado (CopiarArticulosPendAAlbaran)' ) ;
if not AArticulosPendientes. DataTable. Active then
AArticulosPendientes. DataTable. Active : = True ;
// El albar<61> n tiene que venir ya abierto y posicionado donde hay que copiar
ADetalles : = AAlbaran. Detalles;
ADetallesController : = TDetallesFacturaClieedorController. Create;
try
//OJO IMPORTANTE
//Siempre que vayamos a trabajar con los detalles debemos hacer un beginupdate de los mismos y un endupdate para
//obligarle siempre a recalcular los detalles una sola vez
ADetallesController. BeginUpdate( ADetalles) ;
AArticulosPendientes. DataTable. First;
for i : = 0 to AArticulosPendientes. DataTable. RecordCount - 1 do
begin
AAlbaran. Detalles. First;
if ( AAlbaran. Detalles. Locate( 'ID_ARTICULO' , AArticulosPendientes. ID_ARTICULO, [ ] ) ) then
if ( AArticulosPendientes. CANTIDAD_PENDIENTE > 0 ) then
begin
ADetallesController. Add( ADetalles, TIPO_DETALLE_CONCEPTO) ;
ADetalles. Edit;
ADetalles. REFERENCIA : = AAlbaran. Detalles. REFERENCIA;
ADetalles. ID_ARTICULO : = AAlbaran. Detalles. ID_ARTICULO;
ADetalles. CONCEPTO : = AAlbaran. Detalles. CONCEPTO;
ADetalles. CANTIDAD : = AArticulosPendientes. CANTIDAD_PENDIENTE;
ADetalles. IMPORTE_UNIDAD : = AAlbaran. Detalles. IMPORTE_UNIDAD;
ADetalles. IMPORTE_TOTAL : = AAlbaran. Detalles. IMPORTE_TOTAL;
ADetalles. DESCUENTO : = AAlbaran. Detalles. DESCUENTO;
ADetalles. IMPORTE_PORTE : = AAlbaran. Detalles. IMPORTE_PORTE;
ADetalles. VISIBLE : = AAlbaran. Detalles. VISIBLE;
ADetalles. REFERENCIA_PROVEEDOR : = AAlbaran. Detalles. REFERENCIA_PROVEEDOR;
ADetalles. Post;
AArticulosPendientes. Next;
end ;
end ;
finally
ADetallesController. EndUpdate( ADetalles) ;
ADetallesController : = NIL ;
end ;
end ; }
procedure CopiarArticulosAlbaran( AOrigen: IBizDetallesAlbaranCliente;
ADestino : IBizDetallesFacturaCliente) ;
var
i : integer ;
ADetallesController : IDetallesFacturaClienteController;
begin
if not Assigned( AOrigen) then
raise Exception. Create ( 'Origen no asignado (CopiarArticulosAlbaran)' ) ;
if not Assigned( ADestino) then
raise Exception. Create ( 'Destino no asignado (CopiarArticulosAlbaran)' ) ;
if not AOrigen. DataTable. Active then
AOrigen. DataTable. Active : = True ;
if not ADestino. DataTable. Active then
ADestino. DataTable. Active : = True ;
ADetallesController : = TDetallesFacturaClienteController. Create;
try
//OJO IMPORTANTE
//Siempre que vayamos a trabajar con los detalles debemos hacer un beginupdate de los mismos y un endupdate para
//obligarle siempre a recalcular los detalles una sola vez
ADetallesController. BeginUpdate( ADestino) ;
AOrigen. DataTable. First;
for i : = 0 to AOrigen. DataTable. RecordCount - 1 do
begin
ADetallesController. Add( ADestino, TIPO_DETALLE_CONCEPTO) ;
ADestino. Edit;
// ADestino.REFERENCIA := AOrigen.REFERENCIA;
if AOrigen. ID_ARTICULO > 0 then
ADestino. ID_ARTICULO : = AOrigen. ID_ARTICULO;
ADestino. CONCEPTO : = AOrigen. CONCEPTO;
ADestino. CANTIDAD : = AOrigen. CANTIDAD;
ADestino. IMPORTE_UNIDAD : = AOrigen. IMPORTE_UNIDAD;
ADestino. IMPORTE_TOTAL : = AOrigen. IMPORTE_TOTAL;
ADestino. DESCUENTO : = AOrigen. DESCUENTO;
ADestino. IMPORTE_PORTE : = AOrigen. IMPORTE_PORTE;
ADestino. VISIBLE : = AOrigen. VISIBLE;
// ADestino.REFERENCIA_PROVEEDOR := AOrigen.REFERENCIA_PROVEEDOR;
ADestino. Post;
AOrigen. Next;
end ;
finally
ADetallesController. EndUpdate( ADestino) ;
ADetallesController : = NIL ;
end ;
end ;
procedure Inicializar;
begin
dmGenerarFacturasCliAlbCli : = TdmGenerarFacturasCliAlbCli. Create( nil ) ;
AFacturasClienteController : = TFacturasClienteController. Create;
AAlbaranesClienteController : = TAlbaranesClienteController. Create;
ADetallesAlbaranesClienteController : = TDetallesFacturaClienteController. Create;
// AProveedoresController := TProveedoresController.Create;
end ;
procedure Finalizar;
begin
FreeAndNIL( dmGenerarFacturasCliAlbCli) ;
AFacturasClienteController : = nil ;
AAlbaranesClienteController : = nil ;
ADetallesAlbaranesClienteController : = nil ;
// AProveedoresController := nil;
end ;
2014-01-17 16:36:10 +00:00
function GenerarFacturaCliAlb( AAlbaran : IBizAlbaranCliente; const CopiarDetalles: Boolean = True ) : Boolean ; overload ;
var
AFechaFactura: TDateTime;
begin
if Assigned( AAlbaran) then
begin
//Preguntamos la fecha que deseamos tengan las facturas a generar
with TfEditorFechaFactura. Create( Nil ) do
begin
ShowModal;
AFechaFactura : = eFechaFactura. Date;
Free;
end ;
Result : = GenerarFacturaCliAlb( AAlbaran, AFechaFactura) ;
end ;
end ;
function GenerarFacturaCliAlb : Boolean ; overload ;
var
AAlbaranes : IBizAlbaranCliente;
begin
Result : = False ;
try
if not Assigned( AAlbaranesClienteController) then
Inicializar;
AAlbaranes : = AAlbaranesClienteController. ElegirAlbaranes( AAlbaranesClienteController. BuscarSinFacturar,
2014-03-07 12:28:28 +00:00
'Elija el albar<61> n/orden dev. o albaranes/ordenes de cliente que desea utilizar para dar de alta la factura.'
+ #10 #13 + 'Si elige albaranes/ordenes de clientes diferentes se dar<61> de alta una factura por cada uno de ellos.' , True ) ;
2014-01-17 16:36:10 +00:00
if Assigned( AAlbaranes) then
Result : = GenerarFacturaCliAlb( AAlbaranes) ;
if Assigned( AAlbaranesClienteController) then
Finalizar;
finally
AAlbaranes : = Nil ;
end ;
end ;
2010-08-11 10:53:06 +00:00
function GenerarFacturaCliAlb( const IDAlbaran : Integer ; const CopiarDetalles: Boolean = True ) : Boolean ; overload ;
var
AAlbaran : IBizAlbaranCliente;
begin
Result : = False ;
try
if not Assigned( AAlbaranesClienteController) then
Inicializar;
AAlbaran : = AAlbaranesClienteController. Buscar( IDAlbaran) ;
if Assigned( AAlbaran) then
2014-01-17 16:36:10 +00:00
Result : = GenerarFacturaCliAlb( AAlbaran, Date, CopiarDetalles) ;
2010-08-11 10:53:06 +00:00
if Assigned( AAlbaranesClienteController) then
Finalizar;
finally
AAlbaran : = NIL ;
end ;
end ;
2010-10-06 10:32:34 +00:00
function GenerarFacturaCliAlb( AAlbaran : IBizAlbaranCliente; FechaFacturaNueva: TDateTime; const CopiarDetalles: Boolean = True ) : Boolean ; overload ;
2010-08-11 10:53:06 +00:00
var
AFacturasNuevas : IBizFacturaCliente;
i: Integer ;
begin
Result : = False ;
if not Assigned( AAlbaran) then
raise Exception. Create( 'Albar<61> n de proveedor no asignado (GenerarFacturaCliAlb)' ) ;
if not AAlbaran. DataTable. Active then
AAlbaran. DataTable. Active : = True ;
if not Assigned( AAlbaranesClienteController) then
Inicializar;
try
AFacturasNuevas : = AFacturasClienteController. Nuevo( False ) ;
2010-10-06 10:32:34 +00:00
if GenerarFacturas( AFacturasNuevas, AAlbaran, FechaFacturaNueva, CopiarDetalles) then
2010-08-11 10:53:06 +00:00
begin
if AFacturasNuevas. DataTable. RecordCount = 1 then
begin
if AFacturasNuevas. TIPO = CTE_TIPO_FACTURA then
ShowInfoMessage( 'La factura se ha dado de alta con el c<> digo ' + AFacturasNuevas. REFERENCIA)
else
ShowInfoMessage( 'El abono se ha dado de alta con el c<> digo ' + AFacturasNuevas. REFERENCIA) ;
end
else begin
with dmGenerarFacturasCliAlbCli. JsListaFacturasGeneradas. Content do
begin
Clear;
AFacturasNuevas. DataTable. Last;
for i : = 0 to AFacturasNuevas. DataTable. RecordCount - 1 do
begin
if Length( AFacturasNuevas. REFERENCIA) > 0 then
Add( AFacturasNuevas. REFERENCIA + ': ' + AFacturasNuevas. NOMBRE) ;
AFacturasNuevas. DataTable. Prior;
end ;
end ;
dmGenerarFacturasCliAlbCli. JsListaFacturasGeneradas. Execute;
end ;
Result : = True ;
end ;
finally
AFacturasNuevas : = NIL ;
if Assigned( AAlbaranesClienteController) then
Finalizar;
end ;
end ;
2010-10-06 10:32:34 +00:00
function GenerarFacturas( AFacturas : IBizFacturaCliente; AListaAlbaranes : IBizAlbaranCliente; FechaFacturaNueva: TDateTime; const CopiarDetalles: Boolean = True ) : Boolean ;
2010-08-11 10:53:06 +00:00
var
AFacturaActual : IBizFacturaCliente;
AAlbaranesController : IAlbaranesClienteController;
I: Integer ;
bEnEdicion : Boolean ;
begin
// ATENCI<43> N!!! AFacturas tiene que estar vacio para no pisar facturas
// ya generadas.
if not Assigned( AFacturas) then
raise Exception. Create ( 'Factura no asignada (Anadir)' ) ;
if not Assigned( AListaAlbaranes) then
raise Exception. Create ( 'Albaranes no asignados (Anadir)' ) ;
if not AFacturas. DataTable. Active then
AFacturas. DataTable. Active : = True ;
if not AListaAlbaranes. DataTable. Active then
AListaAlbaranes. DataTable. Active : = True ;
AAlbaranesController : = TAlbaranesClienteController. Create;
try
// Ordenar por fecha de albaran
AListaAlbaranes. DataTable. Sort( [ fld_AlbaranesClienteFECHA_ALBARAN] , [ uDADataTable. sdAscending] ) ;
AListaAlbaranes. First;
for I : = 0 to AListaAlbaranes. DataTable. RecordCount - 1 do
begin
AListaAlbaranes. _Cliente : = NIL ;
AFacturaActual : = NIL ;
// Busco si hay alguna factura ya hecha de ese cliente
AFacturas. DataTable. First;
if AFacturas. DataTable. Locate( fld_FacturasClienteID_CLIENTE, AListaAlbaranes. ID_CLIENTE, [ ] ) then
begin
AFacturaActual : = AFacturas;
AFacturasClienteController. RecuperarCliente( AFacturaActual) ;
AFacturaActual. Cliente. DataTable. Active : = True ;
end
else begin
// No hay factura de ese cliente. Creo una nueva
AFacturasClienteController. Anadir( AFacturas) ;
2010-10-06 10:32:34 +00:00
//Asignamos a la factura la fecha pasada por parametro
AFacturas. FECHA_FACTURA : = FechaFacturaNueva;
2010-08-11 10:53:06 +00:00
AAlbaranesController. RecuperarCliente( AListaAlbaranes) ;
AListaAlbaranes. Cliente. DataTable. Active : = True ;
AFacturas. Cliente : = AListaAlbaranes. Cliente;
AFacturaActual : = AFacturas;
2013-12-02 18:23:44 +00:00
2014-01-17 16:36:10 +00:00
// Ya tengo la factura. Le a<> ado los conceptos del albar<61> n
AFacturaActual. Detalles. DataTable. Last;
2013-12-02 18:23:44 +00:00
2014-01-17 16:36:10 +00:00
// A<> ado una l<> nea en blanco
AFacturasClienteController. DetallesController. Add( AFacturaActual. Detalles, TIPO_DETALLE_CONCEPTO) ;
with AFacturaActual. Detalles do
begin
Edit;
CONCEPTO : = '' ;
Post;
end ;
2013-12-02 18:23:44 +00:00
2014-01-17 16:36:10 +00:00
AFacturasClienteController. Guardar( AFacturaActual) ;
2013-12-02 18:23:44 +00:00
2010-08-11 10:53:06 +00:00
end ;
// Ya tengo la factura. Le a<> ado los conceptos del albar<61> n
AFacturaActual. Detalles. DataTable. Last;
//Se pone la referencia del pedido y el total y nos olvidamos de los detalles
if not CopiarDetalles then
begin
AFacturasClienteController. DetallesController. Add( AFacturaActual. Detalles, TIPO_DETALLE_CONCEPTO) ;
with AFacturaActual. Detalles do
begin
Edit;
2014-03-07 12:28:28 +00:00
if ( AListaAlbaranes. TIPO = CTE_TIPO_ALBARAN_DEV) then
CONCEPTO : = 'Orden Dev. ' + AListaAlbaranes. REFERENCIA + ' (Ref.Cliente: ' + AListaAlbaranes. REFERENCIA_CLIENTE + ') del ' + DateToStr( AListaAlbaranes. FECHA_ALBARAN)
else
CONCEPTO : = 'Albar<61> n ' + AListaAlbaranes. REFERENCIA + ' (Ref.Cliente: ' + AListaAlbaranes. REFERENCIA_CLIENTE + ') del ' + DateToStr( AListaAlbaranes. FECHA_ALBARAN) ;
2010-08-11 10:53:06 +00:00
CANTIDAD : = 1 ;
2014-03-07 12:28:28 +00:00
IMPORTE_UNIDAD : = AListaAlbaranes. BASE_IMPONIBLE;
2010-08-11 10:53:06 +00:00
Post;
end ;
end
//Se copian los detalles del pedido a la factura
else
begin
// A<> ado el t<> tulo
AFacturasClienteController. DetallesController. Add( AFacturaActual. Detalles, TIPO_DETALLE_TITULO) ;
with AFacturaActual. Detalles do
begin
Edit;
2014-03-07 12:28:28 +00:00
if ( AListaAlbaranes. TIPO = CTE_TIPO_ALBARAN_DEV) then
CONCEPTO : = 'Orden Dev. ' + AListaAlbaranes. REFERENCIA + ' (Ref.Cliente: ' + AListaAlbaranes. REFERENCIA_CLIENTE + ') del ' + DateToStr( AListaAlbaranes. FECHA_ALBARAN)
else
CONCEPTO : = 'Albar<61> n ' + AListaAlbaranes. REFERENCIA + ' (Ref.Cliente: ' + AListaAlbaranes. REFERENCIA_CLIENTE + ') del ' + DateToStr( AListaAlbaranes. FECHA_ALBARAN) ;
2010-08-11 10:53:06 +00:00
Post;
end ;
// A<> ado el contenido del albar<61> n
CopiarArticulosAlbaran( AListaAlbaranes. Detalles, AFacturaActual. Detalles) ;
AFacturasClienteController. DetallesController. Add( AFacturaActual. Detalles, TIPO_DETALLE_CONCEPTO) ;
with AFacturaActual. Detalles do
begin
Edit;
CONCEPTO : = 'Porte del albar<61> n' ;
CANTIDAD : = 1 ;
IMPORTE_UNIDAD : = AListaAlbaranes. IMPORTE_PORTE;
Post;
end ;
// A<> ado el resumen
AFacturasClienteController. DetallesController. Add( AFacturaActual. Detalles, TIPO_DETALLE_SUBTOTAL) ;
with AFacturaActual. Detalles do
begin
Edit;
2014-03-07 12:28:28 +00:00
if ( AListaAlbaranes. TIPO = CTE_TIPO_ALBARAN_DEV) then
CONCEPTO : = 'Total de la orden dev. ' + AListaAlbaranes. REFERENCIA
else
CONCEPTO : = 'Total del albar<61> n ' + AListaAlbaranes. REFERENCIA;
2010-08-11 10:53:06 +00:00
Post;
end ;
end ;
// A<> ado una l<> nea en blanco
AFacturasClienteController. DetallesController. Add( AFacturaActual. Detalles, TIPO_DETALLE_CONCEPTO) ;
with AFacturaActual. Detalles do
begin
Edit;
CONCEPTO : = '' ;
Post;
end ;
// Guardo la factura que acabo de generar o editar
AFacturaActual. CalcularImporteTotal;
2014-03-07 12:28:28 +00:00
bEnEdicion : = ( AFacturas. DataTable. State in dsEditModes) ;
if not bEnEdicion then
AFacturas. Edit;
//Si la factura tiene importe negativo establecemos el tipo abono
if ( AFacturaActual. IMPORTE_TOTAL < 0 ) then
AFacturas. TIPO : = CTE_TIPO_ABONO
else
AFacturas. TIPO : = CTE_TIPO_FACTURA;
AFacturas. Post;
if bEnEdicion then
AFacturas. Edit;
2010-08-11 10:53:06 +00:00
AFacturasClienteController. Guardar( AFacturaActual) ;
2014-01-17 16:36:10 +00:00
2010-08-11 10:53:06 +00:00
// Asocio la factura con el albar<61> n
AListaAlbaranes. Edit;
AListaAlbaranes. ID_FACTURA : = AFacturaActual. ID;
AListaAlbaranes. Post;
AAlbaranesController. Guardar( AListaAlbaranes) ;
AListaAlbaranes. Next;
end ;
Result : = True ;
finally
AAlbaranesController : = NIL ;
// HideHourglassCursor
end ;
2014-01-17 16:36:10 +00:00
// Comprobar la lista de facturas generadas por si alg<6C> n cliente es una
// sucursal de otro cliente "central".
_CambiarFacturasClientesConSucursales( AFacturaActual) ;
2010-08-11 10:53:06 +00:00
end ;
end .