2010-03-08 19:09:51 +00:00
unit uDetallesPedidoClienteController;
2010-02-17 10:44:34 +00:00
interface
uses
uDADataTable, uControllerDetallesArticulos, uBizDetallesPedidoCliente, uIDataModulePedidosCliente,
uBizArticulos, uBizContactos;
type
IDetallesPedidoClienteController = interface( IControllerDetallesArticulos)
[ '{8D1D3559-E695-4962-9999-404B26B50D6C}' ]
2010-03-04 19:11:24 +00:00
procedure AnadirArticulos( ADetalles: IDAStronglyTypedDataTable; ACliente: IBizCliente; const ANuevaFila : Boolean = True ; const ACantidad: Integer = 1 ) ; overload ;
2010-02-17 10:44:34 +00:00
procedure ActualizarDetalles( ADetalles: IDAStronglyTypedDataTable; ACliente: IBizCliente) ; overload ;
procedure DesglosarPorteDetalles( ImportePorte: Currency ; ADetalles: IDAStronglyTypedDataTable) ;
function DarTotalPorteTotal( ADetalles: IDAStronglyTypedDataTable) : Double ;
2010-03-04 19:11:24 +00:00
procedure ModificarCantidadColores( ADetalles: IDAStronglyTypedDataTable) ;
2010-03-19 13:03:33 +00:00
function ArticulosPendientes( const ID : Integer ) : IBizPedidoClienteArticulosPend;
function ArtColoresPendientes( const ID : Integer ) : IBizPedidoClienteArtColoresPend;
2010-02-17 10:44:34 +00:00
end ;
TDetallesPedidoClienteController = class( TControllerDetallesArticulos, IDetallesPedidoClienteController)
private
FDataModule : IDataModulePedidosCliente;
protected
procedure RellenarOtros( ADetalles: IDAStronglyTypedDataTable; AArticulos: IBizArticulo) ; overload ; override ;
procedure RellenarImportes( ADetalles: IDAStronglyTypedDataTable; AArticulos: IBizArticulo) ; override ;
procedure AsignarController; override ;
//Si sobreescribimos este m<> todo podremos tener en cuenta otras columnas para el calculo del importe total de un concepto
function CalcularImporteTotalConcepto( DataTable: TDADataTable) : Double ; override ;
procedure ValidarCampos( DataTable: TDADataTable) ; override ;
procedure DesglosarPorteDetalles( ImportePorte: Currency ; ADetalles: IDAStronglyTypedDataTable) ;
function DarTotalPorteTotal( ADetalles: IDAStronglyTypedDataTable) : Double ;
public
2010-03-04 19:11:24 +00:00
procedure AnadirArticulos( ADetalles: IDAStronglyTypedDataTable; ACliente: IBizCliente; const ANuevaFila : Boolean = True ; const ACantidad: Integer = 1 ) ; overload ;
2010-02-17 10:44:34 +00:00
procedure ActualizarDetalles( ADetalles: IDAStronglyTypedDataTable; ACliente: IBizCliente) ; overload ;
2010-03-04 19:11:24 +00:00
procedure ModificarCantidadColores( ADetalles: IDAStronglyTypedDataTable) ;
2010-03-19 13:03:33 +00:00
function ArticulosPendientes( const ID : Integer ) : IBizPedidoClienteArticulosPend;
function ArtColoresPendientes( const ID : Integer ) : IBizPedidoClienteArtColoresPend;
2010-02-17 10:44:34 +00:00
constructor Create; override ;
destructor Destroy; override ;
end ;
implementation
2010-03-19 13:03:33 +00:00
uses Dialogs, cxControls, uDAInterfaces, Controls, uDialogUtils, Variants, uControllerDetallesBase, uEditorColores,
uDataModulePedidosCliente, uArticulosPedidoClienteController, uDataTableUtils, uCalculosUtils,
schPedidosClienteClient_Intf;
2010-02-17 10:44:34 +00:00
{ TDetallesPedidoClienteController }
procedure TDetallesPedidoClienteController. ActualizarDetalles( ADetalles: IDAStronglyTypedDataTable; ACliente: IBizCliente) ;
var
AArticulos : IBizArticulo;
begin
if Assigned( ADetalles) then
begin
try
AArticulos : = ( FArticulosController. BuscarTodos( ACliente) as IBizArticulo) ;
ActualizarDetalles( ADetalles, AArticulos) ;
2010-03-04 19:11:24 +00:00
// ShowInfoMessage('Se han actualizado los descuentos para el cliente seleccionado');
2010-02-17 10:44:34 +00:00
finally
AArticulos : = Nil ;
end ;
end ;
end ;
2010-03-04 19:11:24 +00:00
procedure TDetallesPedidoClienteController. AnadirArticulos( ADetalles: IDAStronglyTypedDataTable; ACliente: IBizCliente; const ANuevaFila : Boolean = True ; const ACantidad: Integer = 1 ) ;
2010-02-17 10:44:34 +00:00
var
AArticulos: IBizArticulo;
begin
if Assigned( ADetalles) then
begin
try
AArticulos : = ( FArticulosController. BuscarTodos( ACliente) as IBizArticulo) ;
2010-03-04 19:11:24 +00:00
2010-02-17 10:44:34 +00:00
//Si nueva fila es false, quiere decir que se sustituye un determinado art<72> culo, por ello la lista a seleccionar no debe ser multiselect
if ANuevaFila then
begin
AArticulos : = ( FArticulosController as IArticulosPedidoClienteController) . ElegirArticulos( AArticulos, 'Elija los art<72> culos que desea a<> adir a este presupuesto de cliente' , True ) ;
2010-03-04 19:11:24 +00:00
Add( ADetalles, AArticulos, ACantidad)
2010-02-17 10:44:34 +00:00
end
else
begin
AArticulos : = ( FArticulosController as IArticulosPedidoClienteController) . ElegirArticulos( AArticulos, 'Elija el art<72> culo que desea a<> adir a este presupuesto de cliente' , False ) ;
2010-03-04 19:11:24 +00:00
RellenarDetalle( ADetalles, AArticulos, ACantidad) ;
2010-02-17 10:44:34 +00:00
end ;
finally
AArticulos : = Nil ;
end ;
end ;
end ;
2010-03-19 13:03:33 +00:00
function TDetallesPedidoClienteController. ArtColoresPendientes( const ID: Integer ) : IBizPedidoClienteArtColoresPend;
var
Condicion: TDAWhereExpression;
begin
ShowHourglassCursor;
try
Result : = FDataModule. GetArtColoresPendientes;
with Result . DataTable. DynamicWhere do
begin
// (ID_PEDIDO >= ID)
Condicion : = NewBinaryExpression( NewField( '' , fld_PedidoCliente_Art_Colores_PendientesID_PEDIDO) , NewConstant( ID, datInteger) , dboEqual) ;
if IsEmpty then
Expression : = Condicion
else
Expression : = NewBinaryExpression( Expression, Condicion, dboAnd) ;
end ;
finally
HideHourglassCursor;
end ;
end ;
function TDetallesPedidoClienteController. ArticulosPendientes(
const ID: Integer ) : IBizPedidoClienteArticulosPend;
begin
Result : = FDataModule. GetArticulosPendientes( ID) ;
end ;
2010-02-17 10:44:34 +00:00
procedure TDetallesPedidoClienteController. AsignarController;
begin
FArticulosController : = TArticulosPedidoClienteController. Create;
end ;
function TDetallesPedidoClienteController. CalcularImporteTotalConcepto( DataTable: TDADataTable) : Double ;
begin
Result : = CalcularLineaConcepto( DataTable) ;
end ;
constructor TDetallesPedidoClienteController. Create;
begin
inherited ;
FDataModule : = TDataModulePedidosCliente. Create( Nil ) ;
end ;
function TDetallesPedidoClienteController. DarTotalPorteTotal( ADetalles: IDAStronglyTypedDataTable) : Double ;
begin
Result : = DarTotalPorte( ADetalles) ;
end ;
procedure TDetallesPedidoClienteController. DesglosarPorteDetalles( ImportePorte: Currency ; ADetalles: IDAStronglyTypedDataTable) ;
begin
DesglosarPorte( ImportePorte, ADetalles) ;
ActualizarTotales( ADetalles) ;
end ;
destructor TDetallesPedidoClienteController. Destroy;
begin
FDataModule : = Nil ;
inherited ;
end ;
2010-03-04 19:11:24 +00:00
procedure TDetallesPedidoClienteController. ModificarCantidadColores( ADetalles: IDAStronglyTypedDataTable) ;
var
ADetallesAux: IBizDetallesPedidoCliente;
begin
if Assigned( ADetalles) then
begin
ADetallesAux : = ( ADetalles as IBizDetallesPedidoCliente) ;
with TfEditorColores. Create( NIL ) do
try
dsDataTable. DataTable : = ADetallesAux. DetalleColores. DataTable;
Referencia : = ADetallesAux. REFERENCIA;
Descripcion : = ADetallesAux. CONCEPTO;
if ( ShowModal = mrOK) then
begin
if ADetallesAux. DetalleColores. DataTable. Editing then
ADetallesAux. DetalleColores. DataTable. Post;
if not ADetallesAux. DataTable. Editing then
ADetallesAux. DataTable. Edit;
ADetallesAux. CANTIDAD : = Total;
if ADetallesAux. DataTable. Editing then
ADetallesAux. DataTable. post;
ActualizarTotales( ADetalles) ;
end
else
ADetallesAux. DetalleColores. DataTable. Cancel;
finally
Release;
end ;
end ;
end ;
2010-02-17 10:44:34 +00:00
procedure TDetallesPedidoClienteController. RellenarOtros( ADetalles: IDAStronglyTypedDataTable; AArticulos: IBizArticulo) ;
begin
2010-03-04 19:11:24 +00:00
//Solo para albaranes que es donde se distingue entre colores para tema de stock
2010-02-17 10:44:34 +00:00
if Assigned( AArticulos) then
2010-03-04 19:11:24 +00:00
ModificarCantidadColores( ADetalles) ;
2010-02-17 10:44:34 +00:00
end ;
procedure TDetallesPedidoClienteController. ValidarCampos( DataTable: TDADataTable) ;
begin
inherited ;
ValidarCamposLineaConcepto( DataTable) ;
end ;
procedure TDetallesPedidoClienteController. RellenarImportes( ADetalles: IDAStronglyTypedDataTable; AArticulos: IBizArticulo) ;
begin
2010-03-04 19:11:24 +00:00
//Como en noviseda no hay descuento por linea de detalle, solo recuperamos nuevamente el valor del articulo cuando el detalle no tenga niguno
//de esta forma evitamos que al cambiar de cliente se quiten los importes que se hubiesen establecido para los articulos.
if ADetalles. DataTable. FieldByName( CAMPO_IMPORTE_UNIDAD) . IsNull then
if Assigned( AArticulos) then
ADetalles. DataTable. FieldByName( CAMPO_IMPORTE_UNIDAD) . AsVariant : = AArticulos. PRECIO
else
ADetalles. DataTable. FieldByName( CAMPO_IMPORTE_UNIDAD) . AsVariant : = Null;
2010-02-17 10:44:34 +00:00
end ;
end .