LoteDocTransformacion.cs
1 using sage.ew.db;
2 using sage.ew.global;
3 using sage.ew.interficies;
4 using System;
5 using System.Collections.Generic;
6 using System.Data;
7 using System.Linq;
8 using System.Text;
9 
10 namespace sage.ew.lote.Clases
11 {
16  {
17  #region Constructor
18 
23  {
24  _lDocEntrada = true;
25  }
26 
32  public LoteDocTransformacion(string tcLote, IDocLineaFabricacion toLinea = null)
33  {
34  _lDocEntrada = true;
35  }
36 
37  #endregion Constructor
38 
39 
43  protected override void _ComprobarBloqueos()
44  {
45  _ReadOnly = _ReadOnly || _oDocLin._Solo_Lectura;
46  }
47 
52  protected override bool _Es_Documento_Fabricacion()
53  {
54  return true;
55  }
56 
61  protected override void _Consultar_Lotes_Documento()
62  {
63  string lcSql = string.Empty;
64 
65  // Consultem els lots asociats al document
66  lcSql = "SELECT EMPRESA,space(2) as LETRA,NUMERO,FECHA,ARTICULO,LINIA,LOTE,UNIDADES, " +
67  " PERIODO,ALMACEN,CADUCIDAD,UBICA,FECHA2,PESO, " +
68  " TALLA,COLOR,ASI, " +
69  " UNIDADES AS UNIASIG, 0.00000000000 AS UNI2, PESO AS PESASIG, 0.00000000000 AS PES2, " +
70  " cast(1 as bit) as SEL, cast(0 as bit) as AJENO, cast(0 as bit) as REGULA, space(80) as ORIGEN, 0.00000000000 AS COSTE " +
71  "FROM " + DB.SQLDatabase("LOTES", "LTDTRAN") + " " +
72  " WHERE PERIODO = " + DB.SQLString(_cPeriodo) + " " +
73  " AND EMPRESA = " + DB.SQLString(_oDocLin._Empresa) +
74  " AND NUMERO = " + DB.SQLString(_oDocLin._Numero) +
75  " AND LINIA = " + DB.SQLString(_oDocLin._LineaReal);
76 
77  DB.SQLExec(lcSql, ref _oDataTable);
78  }
79 
84  protected override void _Consultar_Stock_Disponible(ref DataTable tdtStockLote)
85  {
86  string lcSql = string.Empty;
87 
88  string lcOn = EW_GLOBAL._Consolida("a.EMPRESA", true, false); // 99489
89 
90  // Consultem el Stock disponible de l'article
91  lcSql = "SELECT a.LOTE, a.CADUCIDAD, a.UNIDADES, a.PESO, a.UBICA, a.TALLA, a.COLOR, " +
92  " 0.00000000000 AS UNIASIG,0.00000000000 AS PESASIG, 0.00000000000 AS UNI2, 0.00000000000 AS PES2, space(20) as ASI, " +
93  " cast(0 as bit) as SEL, cast(0 as bit) as AJENO, cast(0 as bit) as REGULA, space(80) as ORIGEN, 0.00000000000 AS COSTE " +
94  "FROM " + DB.SQLDatabase("LOTES", "STOCKLOTES") + " a " +
95  " LEFT JOIN " + DB.SQLDatabase("LOTES", "LTDTRAN") + " b " +
96  " ON " + lcOn + // 99489
97  " AND a.ALMACEN = b.ALMACEN " +
98  " AND a.ARTICULO = b.ARTICULO " +
99  " AND a.LOTE = b.LOTE " +
100  " AND a.UBICA = b.UBICA " +
101  " AND a.TALLA = b.TALLA " +
102  " AND a.COLOR = b.COLOR " +
103  " AND b.NUMERO = " + DB.SQLString(_oDocLin._Numero) +
104  " AND b.LINIA = " + DB.SQLString(_oDocLin._LineaReal) +
105  " WHERE " + lcOn + // 99489
106  " AND a.TALLA = " + DB.SQLString(_oDocLin._Talla) +
107  " AND a.COLOR = " + DB.SQLString(_oDocLin._Color) +
108  " AND a.ARTICULO = " + DB.SQLString(_oDocLin._Articulo) +
109  " AND a.ALMACEN = " + DB.SQLString(_oDocLin._Almacen) +
110  " AND a.FECHA <= " + DB.SQLString(_oDocLin._Fecha) +
111  " AND b.LOTE = null " +
112  " AND b.UBICA = null ";
113 
114  DB.SQLExec(lcSql, ref tdtStockLote);
115  }
116 
121  public override bool _Desactivar_Control_Stock()
122  {
123  return _oLotesConfig._SinMov_Ltdtran;
124  }
125 
129  protected override void _DeleteLinDocStockLotes(LinVenDetLotes toDetCodigo)
130  {
131  // Taula LOTES!LTDTRAN
132  string lcSql = " AND PERIODO = " + DB.SQLString(_cPeriodo) + " " +
133  " AND EMPRESA = " + DB.SQLString(_oDocLin._Empresa) + " " +
134  " AND NUMERO = " + DB.SQLString(_oDocLin._Numero) + " " +
135  " AND LINIA = " + DB.SQLString(_oDocLin._LineaReal) + " " +
136  " AND LOTE = " + DB.SQLString(toDetCodigo._Codigo) + " " +
137  " AND UBICA = " + DB.SQLString(toDetCodigo._Ubicacion) + " " +
138  " AND TALLA = " + DB.SQLString(toDetCodigo._Talla) + " " +
139  " AND COLOR = " + DB.SQLString(toDetCodigo._Color) + " ";
140 
141  _dOldCreated = Convert.ToDateTime(DB.SQLValor("LTDTRAN", "1=1 " + lcSql + " AND '' ", "", "CREATED", "LOTES"));
142 
143  lcSql = "DELETE FROM " + DB.SQLDatabase("LOTES", "LTDTRAN") + " WHERE 1=1 " + lcSql;
144 
145  //Executo la consulta
146  DB.SQLExec(lcSql);
147  }
148 
152  protected override void _InsertLinDocStockLotes(LinVenDetLotes toDetCodigo)
153  {
154  string lcSql = string.Empty;
155 
156  lcSql = "INSERT INTO " + DB.SQLDatabase("LOTES", "LTDTRAN") + " " +
157  "(EMPRESA,NUMERO,FECHA,ARTICULO,LINIA,LOTE,UNIDADES,PERIODO,ALMACEN,CADUCIDAD,UBICA,FECHA2,PESO,TALLA,COLOR,ASI" +
158  (_dOldCreated == DateTime.MinValue ? "" : ",CREATED") +
159  ") " +
160  "VALUES (" +
161  DB.SQLString(_oDocLin._Empresa) + ", " +
162  DB.SQLString(_oDocLin._Numero) + ", " +
163  DB.SQLString(_oDocLin._Fecha) + ", " +
164  DB.SQLString(_oDocLin._Articulo) + ", " +
165  DB.SQLString(_oDocLin._LineaReal) + ", " +
166  DB.SQLString(toDetCodigo._Codigo) + ", " +
167  DB.SQLString(toDetCodigo._Unidades) + ", " +
168  DB.SQLString(_cPeriodo) + ", " +
169  DB.SQLString(_oDocLin._Almacen) + ", " +
170  DB.SQLString(toDetCodigo._Caducidad) + ", " +
171  DB.SQLString(toDetCodigo._Ubicacion) + ", " +
172  DB.SQLString(DateTime.Now) + ", " +
173  DB.SQLString(toDetCodigo._Peso) + ", " +
174  DB.SQLString(_oDocLin._Talla) + ", " +
175  DB.SQLString(_oDocLin._Color) + ", " +
176  DB.SQLString(toDetCodigo._Asi) + " " +
177  (_dOldCreated == DateTime.MinValue ? "" : ", " + DB.SQLString(_dOldCreated)) +
178  ") ";
179 
180  DB.SQLExec(lcSql);
181  }
182 
187  protected override string _Obtener_Nombre_Articulo()
188  {
189  return _oDocLin._NombreArticulo;
190  }
191 
198  {
199  if (_oLotesConfig._Coste_Lote)
200  {
201  DataTable dtLotesDeLaLinea = new DataTable();
202  if (_Obtener_Detalle(toLinea, ref dtLotesDeLaLinea) && dtLotesDeLaLinea.Rows.Count > 0) //Obtengo los lotes de la línea
203  {
204  decimal costes = 0.0M;
205  var detalleLotes = dtLotesDeLaLinea.AsEnumerable().Where(loEle => !string.IsNullOrWhiteSpace(loEle.Field<string>("CODIGO"))).ToList();
206 
207  if (detalleLotes.Any())
208  {
209  var totalUnidades = decimal.Zero;
210 
211  foreach (var item in detalleLotes)
212  {
213  var codigoLote = item.Field<string>("CODIGO").TrimEnd();
214  var unidades = item.Field<decimal>("UNIDADES");
215  var costeUnitario = _Coste_Articulo_Lote(toLinea._Articulo, codigoLote, toLinea._Fecha, toLinea._Talla, toLinea._Color);
216  totalUnidades += unidades;
217  costes += (costeUnitario * unidades);
218  }
219  if (costes != 0.0M)
220  {
221  toLinea._Coste = costes / (totalUnidades != 0 ? totalUnidades : 1);
222  return true;
223  }
224  }
225 
226  }
227  }
228  return false;
229  }
230 
237  public bool _OperacionesDeCierre(IDocLineaFabricacion toLinea, bool deshacerCierre = false)
238  {
239  //TODO => Evaluar si hay que hacer algo
240  return true;
241  }
242 
248  protected override void _Preparar_UpdateSilent_Unidades(decimal tnValor, ref Dictionary<String, Object> toDic)
249  {
250  //ewCampo loValor = new ewCampo();
251 
252  //loValor._OldVal = loValor._NewVal = tnValor;
253  toDic.Add("_privateUnidades", tnValor);
254  }
255 
261  protected override void _Preparar_UpdateSilent_Peso(decimal tnValor, ref Dictionary<String, Object> toDic)
262  {
263  //ewCampo loValor = new ewCampo();
264 
265  //loValor._OldVal = loValor._NewVal = tnValor;
266  toDic.Add("_privatePeso", tnValor);
267  }
268 
269 
275  protected override void _Preparar_UpdateSilent_Cajas(decimal tnValor, ref Dictionary<string, object> toDic)
276  {
277  // En los traspaso de depositos, no tiene que modificar las cajas.
278  }
279 
284  protected override bool _Es_Documento_Entrada()
285  {
286  return _lDocEntrada;
287  }
288 
289  #region IStockExtRegulari
290 
291 
292 
293 
299  public bool _Delete(IDocLineaFabricacion toLinea)
300  {
301  bool llOk = true;
302  string lcSql = "";
303 
304  lcSql = "Delete From " + DB.SQLDatabase("LOTES", "LTDTRAN") +
305  " Where empresa = " + DB.SQLString(toLinea._Empresa) +
306  " And numero = " + DB.SQLString(toLinea._Numero) +
307  " And linia = " + DB.SQLString(toLinea._LineaReal) +
308  " And periodo = " + DB.SQLString(_cPeriodo);
309 
310  llOk = DB.SQLExec(lcSql);
311 
312  _Refrescar_Stocks(toLinea._Articulo, toLinea._Almacen, toLinea._Talla, toLinea._Color);
313 
314  return llOk;
315  }
316 
323  public bool _Delete(string tcLote, IDocumentLinea toLinea)
324  {
325  return true;
326  }
327 
335  public bool _Show(object toPadre, IDocumentLinea toLinea, bool tlReadOnly = false)
336  {
337  return true;
338  }
339 
348  public bool _Show(IDocLineaFabricacion toLinea, eCampoDocumentLinea teCampo, object toValue, ref string tcMensajeError)
349  {
350  bool llGestionEspecial = false;
351 
352  switch (teCampo)
353  {
354  case eCampoDocumentLinea.Unidades:
355  case eCampoDocumentLinea.Peso:
356  case eCampoDocumentLinea.Cajas:
357  case eCampoDocumentLinea.Talla:
358  case eCampoDocumentLinea.Color:
359 
360  // Control especial para saber si el documento se consulta de sólo lectura (PE-90431)
361  if (toValue == null) this._ReadOnly = true;
362 
363  // Si el objecte toValue es false, vol dir que venim des del botó
364  if ((toValue is Boolean && (bool)toValue == false) || this._ReadOnly) // PE-90431
365  _Iniciar_Asignacion_Lotes(toLinea, false);
366  else
367  _Iniciar_Asignacion_Lotes(toLinea, true);
368 
369  tcMensajeError = _Error_Message;
370  llGestionEspecial = true;
371  break;
372 
373  default:
374  break;
375  }
376 
377  return llGestionEspecial;
378  }
379 
385  public bool _Update(IDocLineaFabricacion toLinea)
386  {
387  string lcSql = "Update " + DB.SQLDatabase("LOTES", "LTDTRAN") +
388  " Set fecha = " + DB.SQLString(toLinea._Fecha) +
389  " Where empresa = " + DB.SQLString(toLinea._Empresa) +
390  " And numero = " + DB.SQLString(toLinea._Numero) +
391  " And linia = " + DB.SQLString(toLinea._Linea) +
392  " And periodo = " + DB.SQLString(_cPeriodo);
393 
394  DB.SQLExec(lcSql);
395 
396  _Refrescar_Stocks(toLinea._Articulo, toLinea._Almacen, toLinea._Talla, toLinea._Color);
397 
398  return true;
399  }
400 
407  public bool _Obtener_Detalle(IDocLineaFabricacion toLinea, ref DataTable tdtResultados)
408  {
409  bool llOk = false;
410  string lcSql = String.Empty;
411 
412  lcSql = "SELECT LOTE AS CODIGO, UNIDADES, PESO " +
413  "FROM " + DB.SQLDatabase("LOTES", "LTDTRAN") + " " +
414  "WHERE EMPRESA = " + DB.SQLString(toLinea._Empresa) +
415  " AND NUMERO = " + DB.SQLString(toLinea._Numero) +
416  " AND LINIA = " + DB.SQLString(toLinea._LineaReal) +
417  " AND PERIODO = " + DB.SQLString(_cPeriodo);
418  llOk = DB.SQLExec(lcSql, ref tdtResultados);
419 
420  return llOk;
421  }
422 
431  public bool _Operacion_Permitida(IDocLineaFabricacion toLinea, eCampoDocumentLinea teCampo, object toValue, ref string tcMensajeRespuesta)
432  {
433  bool llCondicion = false;
434 
435  // 103484
436  llCondicion = llCondicion || teCampo == eCampoDocumentLinea.Articulo && !String.IsNullOrWhiteSpace(toLinea._Articulo) && String.Compare(toLinea._Articulo, (string)toValue) != 0;
437  llCondicion = llCondicion || teCampo == eCampoDocumentLinea.Talla && !String.IsNullOrWhiteSpace(toLinea._Talla) && String.Compare(toLinea._Talla, (string)toValue) != 0;
438  llCondicion = llCondicion || teCampo == eCampoDocumentLinea.Color && !String.IsNullOrWhiteSpace(toLinea._Color) && String.Compare(toLinea._Color, (string)toValue) != 0;
439  // fi 103484
440 
441 
442  //Sin restricciones específicas => Operaciones permitidas
443  if (llCondicion)
444  {
445  string lcDef = Convert.ToString(EW_GLOBAL._GetVariable("wc_deflote"));
446 
447  tcMensajeRespuesta = "No se permite modificar el artículo, trabaja con " + lcDef + ". " + Environment.NewLine +
448  "Pruebe a borrar el artículo e introducir uno de nuevo.";
449  return false;
450  }
451  else
452  return true;
453  }
454 
461  {
462  return true;
463  }
464 
471  public bool _SePuedeAbrir(IDocLineaFabricacion toLinea, bool hayFormulario = false)
472  {
473  return true;
474  }
475 
476  #endregion IStockExtRegulari
477  }
478 }
bool _Update(IDocLineaFabricacion toLinea)
Método _Update para documentos de regularización
bool _OperacionesDeCierre(IDocLineaFabricacion toLinea, bool deshacerCierre=false)
Método para llamar a la función de operaciones de cierre
override void _Preparar_UpdateSilent_Unidades(decimal tnValor, ref Dictionary< String, Object > toDic)
Preparar las unidades a utilizar en el _UpdateSilent
bool _Show(IDocLineaFabricacion toLinea, eCampoDocumentLinea teCampo, object toValue, ref string tcMensajeError)
Método para tratar los cambios de valor en los campos
Clase para controlar toda la gestion de venta de un lote/ubicacion de artículo
override bool _Es_Documento_Entrada()
Nos devuelve si el documento es de entrada o salida de stock
bool _Se_Puede_Borrar(IDocLineaFabricacion toLinea)
Método lineal para comprobar si la línea se puede borrar
override void _ComprobarBloqueos()
Comprobar si existe alguna restricción, para que se abra el formulario de asignación de lotes...
bool _Delete(IDocLineaFabricacion toLinea)
Método delete en documentos de regularización
Clase para la gestión de los lotes
Definition: Lote.cs:37
string _Talla
Codigo de la talla
Interficie mínima de las líneas (Mantener lo mas reducida posible)
Definition: IDocument.cs:186
override void _InsertLinDocStockLotes(LinVenDetLotes toDetCodigo)
Nou metode buit que es sobreescriurà per cada document, per insertar els moviments a les taules de lo...
eCampoDocumentLinea
Definición del enumerado de los campos de una linea de documento
Definition: IDocument.cs:134
Clase de lotes para documentos de fabricación (transformación)
override void _Preparar_UpdateSilent_Cajas(decimal tnValor, ref Dictionary< string, object > toDic)
Preparar las cajas a utilizar en el _UpdateSilent
Nullable< DateTime > _Caducidad
Fecha de caducidad del lote (Accepta NULL)
bool _Delete(string tcLote, IDocumentLinea toLinea)
Operaciones de borrado
override void _DeleteLinDocStockLotes(LinVenDetLotes toDetCodigo)
Nou metode buit que es sobreescriurà per cada document, per eliminar els moviments a les taules de lo...
bool _Show(object toPadre, IDocumentLinea toLinea, bool tlReadOnly=false)
Nos presenta el formulario para visualizar/operar con las series
bool _Obtener_Detalle(IDocLineaFabricacion toLinea, ref DataTable tdtResultados)
Método que obtiene los lotes asociados a la línea
Interficie para operaciones extendidas de fabricación
LoteDocTransformacion(string tcLote, IDocLineaFabricacion toLinea=null)
Constructor de la clase LoteDocProduccion con parametros
bool _Operacion_Permitida(IDocLineaFabricacion toLinea, eCampoDocumentLinea teCampo, object toValue, ref string tcMensajeRespuesta)
Método de comprobación de operaciones permitidas
override void _Consultar_Stock_Disponible(ref DataTable tdtStockLote)
Consultar stock disponible
string _Codigo
Código de lote asociado
override void _Consultar_Lotes_Documento()
Nou metode buit que es sobreescriurà per cada document
LoteDocTransformacion()
Constructor de la clase LoteDocProduccion
decimal _Peso
Peso asignado a la venta
string _Ubicacion
Código de la ubicación
override bool _Desactivar_Control_Stock()
Nou metode buit que es sobreescriurà per cada document, per verificar el control d&#39;stock ...
Definición de la interfície necesaria para los objetos de documento utilizados en el formulario FormD...
string _Asi
Asi del registro
bool _ObtenerCosteLinea(IDocLineaFabricacion toLinea)
Obtiene el coste de la línea
int _LineaReal
Devuelve el campo linia: para todos los documentos sera el mismo valor que la linea pero en el docume...
Definition: IDocument.cs:207
decimal _Unidades
Unidades asignadas a la venta
override string _Obtener_Nombre_Articulo()
Obtener el nombre del artículo de la linea actual
bool _SePuedeAbrir(IDocLineaFabricacion toLinea, bool hayFormulario=false)
Método para comprobar si se puede abrir
override void _Preparar_UpdateSilent_Peso(decimal tnValor, ref Dictionary< String, Object > toDic)
Preparar el peso a utilizar en el _UpdateSilent
override bool _Es_Documento_Fabricacion()
Indica si es un documento de fabricacion (Producción, Transformación)