LoteDocVentaDeposito.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using sage.ew.interficies;
6 using sage.ew.db;
7 using System.Data;
8 using sage.ew.global;
9 using sage.ew.docsven;
10 using sage.ew.ewbase;
11 using sage.ew.functions;
12 
13 namespace sage.ew.lote.Clases
14 {
18  public class LoteDocVentaDeposito : Lote, IVentasExtendidas, ILinVenDetOperable
19  {
20  #region Constructores
21 
26  {
27  _lDocEntrada = false;
28  }
29 
35  public LoteDocVentaDeposito(string tcLote, IDocumentLinea toDocumentoLin = null)
36  {
37  _lDocEntrada = false;
38  }
39 
40  #endregion Constructores
41 
45  protected override void _ComprobarBloqueos()
46  {
47  bool _lSoloLectura = false;
48 
49  _lSoloLectura = _oDocLin.DocVenta._Solo_Lectura;
50 
51  // Si tenemos servidas, y no estamos traspasando, no dejamos modificar los lotes
52  if (_oDocLin._Servidas != 0 && _oDocLin._Traspasar_Unidades == 0) _lSoloLectura = true; // 102543
53 
54  _ReadOnly = _ReadOnly || _lSoloLectura;
55  }
56 
57 
62  protected override void _Consultar_Lotes_Documento()
63  {
64  string lcSql = string.Empty;
65 
66  // Consultem els lots asociats al document
67  lcSql = "SELECT EMPRESA,LETRA,NUMERO,FECHA,ARTICULO,LINIA,LOTE,UNIDADES, " +
68  " PERIODO,ALMACEN,CADUCIDAD,UBICA,FECHA2,PESO, " +
69  " TALLA,COLOR,ASI, " +
70  " UNIDADES AS UNIASIG, 0.00000000000 AS UNI2, PESO AS PESASIG, 0.00000000000 AS PES2, " +
71  " 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 " +
72  "FROM " + DB.SQLDatabase("LOTES", "LTDEPVE") + " " +
73  " WHERE PERIODO = " + DB.SQLString(_cPeriodo) + " " +
74  " AND EMPRESA = " + DB.SQLString(_oDocLin._Empresa) +
75  " AND NUMERO = " + DB.SQLString(_oDocLin._Numero) +
76  " AND LETRA = " + DB.SQLString(_oDocLin._Letra) +
77  " AND LINIA = " + DB.SQLString(_oDocLin._LineaReal);
78 
79  if (_oDocLin._Unidades - _oDocLin._Servidas != 0)
80  {
81  lcSql += " AND TRASPAS = " + DB.SQLString(0);
82  }
83 
84  DB.SQLExec(lcSql, ref _oDataTable);
85  }
86 
90  protected override void _Nueva_Asignacion_Buscar_Stock()
91  {
92  if (_oRestricciones is IDictionary<string, string> && ((IDictionary<string, string>)_oRestricciones).Count == 4)
93  {
94  string lcSql = string.Empty;
95 
96  // Consultem els lots asociats al document
97  lcSql = "SELECT *, " +
98  " 0.00000000000 AS UNIASIG, 0.00000000000 AS UNI2, 0.00000000000 AS PESASIG, 0.00000000000 AS PES2, space(20) as ASI, " +
99  " 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 " +
100  "FROM " + DB.SQLDatabase("LOTES", "LTDEPVE") + " " +
101  " WHERE PERIODO = " + DB.SQLString(_cPeriodo) + " ";
102 
103  if (((IDictionary<string, string>)_oRestricciones).ContainsKey("Empresa"))
104  {
105  lcSql += " AND EMPRESA = " + DB.SQLString(((IDictionary<string, string>)_oRestricciones)["Empresa"]);
106  }
107 
108  if (((IDictionary<string, string>)_oRestricciones).ContainsKey("Numero"))
109  {
110  lcSql += " AND NUMERO = " + DB.SQLString(((IDictionary<string, string>)_oRestricciones)["Numero"]);
111  }
112 
113  if (((IDictionary<string, string>)_oRestricciones).ContainsKey("Letra"))
114  {
115  lcSql += " AND LETRA = " + DB.SQLString(((IDictionary<string, string>)_oRestricciones)["Letra"]);
116  }
117 
118  if (((IDictionary<string, string>)_oRestricciones).ContainsKey("Linia"))
119  {
120  lcSql += " AND LINIA = " + DB.SQLString(((IDictionary<string, string>)_oRestricciones)["Linia"]);
121  }
122 
123  lcSql += " AND TRASPAS = " + DB.SQLString(0);
124 
125  DB.SQLExec(lcSql, ref _oDataTable);
126  }
127  else
128  {
129  base._Nueva_Asignacion_Buscar_Stock();
130  }
131  }
132 
137  protected override void _Consultar_Stock_Disponible(ref DataTable tdtStockLote)
138  {
139  string lcSql = string.Empty;
140 
141  string lcOn = EW_GLOBAL._Consolida("a.EMPRESA", true, false);
142 
143  // Consultem el Stock disponible de l'article
144  lcSql = "SELECT a.LOTE, a.CADUCIDAD, a.UNIDADES, a.PESO, a.UBICA, a.TALLA, a.COLOR, " +
145  " 0.00000000000 AS UNIASIG,0.00000000000 AS PESASIG, 0.00000000000 AS UNI2, 0.00000000000 AS PES2, space(20) as ASI, " +
146  " 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 " +
147  "FROM " + DB.SQLDatabase("LOTES", "STOCKLOTES") + " a " +
148  " LEFT JOIN " + DB.SQLDatabase("LOTES", "LTDEPVE") + " b " +
149  " ON " + lcOn +
150  " AND a.ALMACEN = b.ALMACEN " +
151  " AND a.ARTICULO = b.ARTICULO " +
152  " AND a.LOTE = b.LOTE " +
153  " AND a.UBICA = b.UBICA " +
154  " AND a.TALLA = b.TALLA " +
155  " AND a.COLOR = b.COLOR " +
156  " AND b.NUMERO = " + DB.SQLString(_oDocLin._Numero) +
157  " AND b.LETRA = " + DB.SQLString(_oDocLin._Letra) +
158  " AND b.LINIA = " + DB.SQLString(_oDocLin._LineaReal) +
159  " WHERE " + lcOn +
160  " AND a.TALLA = " + DB.SQLString(_oDocLin._Talla) +
161  " AND a.COLOR = " + DB.SQLString(_oDocLin._Color) +
162  " AND a.ARTICULO = " + DB.SQLString(_oDocLin._Articulo) +
163  " AND a.ALMACEN = " + DB.SQLString(_oDocLin._Almacen) +
164  //" AND a.FECHA <= " + DB.SQLString(_oDocLin._Fecha) +
165  " AND b.LOTE = null " +
166  " AND b.UBICA = null ";
167 
168  DB.SQLExec(lcSql, ref tdtStockLote);
169  }
170 
175  public override bool _Desactivar_Control_Stock()
176  {
177  return _oLotesConfig._SinMov_Ltdepve;
178  }
179 
184  protected override bool _Autoasignacion()
185  {
186  return _oLotesConfig._Auto_Venta;
187  }
188 
192  protected override void _DeleteLinDocStockLotes(LinVenDetLotes toDetCodigo)
193  {
194  // Taula LOTES!LTDEPVE
195  string lcSql = " AND PERIODO = " + DB.SQLString(_cPeriodo) + " " +
196  " AND EMPRESA = " + DB.SQLString(_oDocLin._Empresa) + " " +
197  " AND NUMERO = " + DB.SQLString(_oDocLin._Numero) +
198  " AND LETRA = " + DB.SQLString(_oDocLin._Letra) +
199  " AND LINIA = " + DB.SQLString(_oDocLin._LineaReal) + " " +
200  " AND LOTE = " + DB.SQLString(toDetCodigo._Codigo) + " " +
201  " AND UBICA = " + DB.SQLString(toDetCodigo._Ubicacion) + " " +
202  " AND TALLA = " + DB.SQLString(_oDocLin._Talla) + " " +
203  " AND COLOR = " + DB.SQLString(_oDocLin._Color) + " ";
204 
205  _dOldCreated = Convert.ToDateTime(DB.SQLValor("LTDEPVE", "1=1 " + lcSql + " AND '' ", "", "CREATED", "LOTES"));
206 
207  lcSql = "DELETE FROM " + DB.SQLDatabase("LOTES", "LTDEPVE") + " WHERE 1=1 " + lcSql;
208 
209  //Executo la consulta
210  DB.SQLExec(lcSql);
211  }
212 
216  protected override void _InsertLinDocStockLotes(LinVenDetLotes toDetCodigo)
217  {
218  string lcSql = string.Empty;
219 
220  if (_oRestricciones is IDictionary<string, string> && ((IDictionary<string, string>)_oRestricciones).Count == 4)
221  {
222  string lcSqlFiltro = string.Empty;
223  string lcSet = string.Empty;
224  string lcAsi = string.Empty;
225 
226  if (((IDictionary<string, string>)_oRestricciones).ContainsKey("Empresa"))
227  {
228  lcSqlFiltro += " AND EMPRESA = " + DB.SQLString(((IDictionary<string, string>)_oRestricciones)["Empresa"]);
229  }
230 
231  if (((IDictionary<string, string>)_oRestricciones).ContainsKey("Numero"))
232  {
233  lcSqlFiltro += " AND NUMERO = " + DB.SQLString(((IDictionary<string, string>)_oRestricciones)["Numero"]);
234  }
235 
236  if (((IDictionary<string, string>)_oRestricciones).ContainsKey("Letra"))
237  {
238  lcSqlFiltro += " AND LETRA = " + DB.SQLString(((IDictionary<string, string>)_oRestricciones)["Letra"]);
239  }
240 
241  if (((IDictionary<string, string>)_oRestricciones).ContainsKey("Linia"))
242  {
243  lcSqlFiltro += " AND LINIA = " + DB.SQLString(((IDictionary<string, string>)_oRestricciones)["Linia"]);
244  }
245 
246 
247  DataTable ldtDatos = new DataTable();
248 
249  lcSql = " SELECT * FROM " + DB.SQLDatabase("LOTES", "LTDEPVE") + " " +
250  " WHERE PERIODO = " + DB.SQLString(_cPeriodo) +
251  lcSqlFiltro +
252  " AND TALLA = " + DB.SQLString(_oDocLin._Talla) +
253  " AND COLOR = " + DB.SQLString(_oDocLin._Color) +
254  " AND LOTE = " + DB.SQLString(toDetCodigo._Codigo) +
255  " AND UBICA = " + DB.SQLString(toDetCodigo._Ubicacion);
256 
257  DB.SQLExec(lcSql, ref ldtDatos);
258 
259  int lnTraspas = ldtDatos.AsEnumerable().Max(lin => lin.Field<int>("traspas"));
260 
261 
262  // Filtrem pels que no estan traspassats
263  lcSql = " SELECT * FROM " + DB.SQLDatabase("LOTES", "LTDEPVE") + " " +
264  " WHERE PERIODO = " + DB.SQLString(_cPeriodo) +
265  lcSqlFiltro +
266  " AND TALLA = " + DB.SQLString(_oDocLin._Talla) +
267  " AND COLOR = " + DB.SQLString(_oDocLin._Color) +
268  " AND LOTE = " + DB.SQLString(toDetCodigo._Codigo) +
269  " AND UBICA = " + DB.SQLString(toDetCodigo._Ubicacion) +
270  " AND TRASPAS = " + DB.SQLString(0);
271  DB.SQLExec(lcSql, ref ldtDatos);
272 
273  decimal lnDocUnidades = ldtDatos.AsEnumerable().Sum(lin => lin.Field<decimal>("unidades"));
274  decimal lnDocPeso = ldtDatos.AsEnumerable().Sum(lin => lin.Field<decimal>("peso"));
275 
276  if (ldtDatos.Rows.Count > 0)
277  {
278  foreach (DataRow ldr in ldtDatos.Rows)
279  {
280  lnTraspas += 1;
281  lcSet = string.Empty;
282 
283  lcAsi = FUNCTIONS._Random_Asi(20);
284 
285  if (lnDocUnidades > Math.Abs(toDetCodigo._Unidades))
286  {
287  lcSet = " ,unidades = " + DB.SQLString(Math.Abs(toDetCodigo._Unidades)) + ", peso = " + DB.SQLString(Math.Abs(toDetCodigo._Peso)) + " ";
288  }
289  lcSet += " ,tfecha = null ";
290 
291  // Actualizar el lote original que se ha devuelto
292  lcSql = " UPDATE " + DB.SQLDatabase("LOTES", "LTDEPVE") + " " +
293  " SET TRASPAS = " + DB.SQLString(lnTraspas) +
294  " , ASI = " + DB.SQLString(lcAsi) +
295  lcSet +
296  " WHERE PERIODO = " + DB.SQLString(_cPeriodo) +
297  lcSqlFiltro +
298  " AND TALLA = " + DB.SQLString(toDetCodigo._Talla) +
299  " AND COLOR = " + DB.SQLString(toDetCodigo._Color) +
300  " AND LOTE = " + DB.SQLString(toDetCodigo._Codigo) +
301  " AND UBICA = " + DB.SQLString(toDetCodigo._Ubicacion) +
302  " AND TRASPAS = " + DB.SQLString(0);
303 
304  DB.SQLExec(lcSql);
305 
306 
307  if (lnDocUnidades > Math.Abs(toDetCodigo._Unidades))
308  {
309  ldr["unidades"] = lnDocUnidades - Math.Abs(toDetCodigo._Unidades);
310  ldr["peso"] = lnDocPeso - Math.Abs(toDetCodigo._Peso);
311 
312  // Nuevo registro si no se ha asignado la totalidad del lote
313  lcSql = "INSERT INTO " + DB.SQLDatabase("LOTES", "LTDEPVE") + " " +
314  "(EMPRESA,LETRA,NUMERO,FECHA,ARTICULO,LINIA,LOTE,UNIDADES,PERIODO,ALMACEN,CADUCIDAD,UBICA,FECHA2,PESO,TALLA,COLOR,ASI) " +
315  "VALUES (" +
316  DB.SQLString(ldr["Empresa"]) + ", " +
317  DB.SQLString(ldr["Letra"]) + ", " +
318  DB.SQLString(ldr["Numero"]) + ", " +
319  DB.SQLString(ldr["Fecha"]) + ", " +
320  DB.SQLString(ldr["Articulo"]) + ", " +
321  DB.SQLString(ldr["Linia"]) + ", " +
322  DB.SQLString(ldr["Lote"]) + ", " +
323  DB.SQLString(ldr["Unidades"]) + ", " +
324  DB.SQLString(ldr["Periodo"]) + ", " +
325  DB.SQLString(ldr["Almacen"]) + ", " +
326  DB.SQLString(ldr["Caducidad"]) + ", " +
327  DB.SQLString(ldr["Ubica"]) + ", " +
328  DB.SQLString(ldr["Fecha2"]) + ", " +
329  DB.SQLString(ldr["Peso"]) + ", " +
330  DB.SQLString(ldr["Talla"]) + ", " +
331  DB.SQLString(ldr["Color"]) + ", " +
332  DB.SQLString(string.Empty) + ") ";
333 
334  DB.SQLExec(lcSql);
335  }
336 
337  // Registro para el depósito de la devolución
338  lcSql = "INSERT INTO " + DB.SQLDatabase("LOTES", "LTDEPVE") + " " +
339  "(EMPRESA,LETRA,NUMERO,FECHA,ARTICULO,LINIA,LOTE,UNIDADES,PERIODO,ALMACEN,CADUCIDAD,UBICA,FECHA2,PESO,TALLA,COLOR,ASI,TRASPAS" +
340  (_dOldCreated == DateTime.MinValue ? "" : ",CREATED") +
341  ") " +
342  "VALUES (" +
343  DB.SQLString(_oDocLin._Empresa) + ", " +
344  DB.SQLString(_oDocLin._Letra) + ", " +
345  DB.SQLString(_oDocLin._Numero) + ", " +
346  DB.SQLString(_oDocLin._Fecha) + ", " +
347  DB.SQLString(_oDocLin._Articulo) + ", " +
348  DB.SQLString(_oDocLin._LineaReal) + ", " +
349  DB.SQLString(toDetCodigo._Codigo) + ", " +
350  DB.SQLString(toDetCodigo._Unidades) + ", " +
351  DB.SQLString(_cPeriodo) + ", " +
352  DB.SQLString(_oDocLin._Almacen) + ", " +
353  DB.SQLString(toDetCodigo._Caducidad) + ", " +
354  DB.SQLString(toDetCodigo._Ubicacion) + ", " +
355  DB.SQLString(DateTime.Now) + ", " +
356  DB.SQLString(toDetCodigo._Peso) + ", " +
357  DB.SQLString(_oDocLin._Talla) + ", " +
358  DB.SQLString(_oDocLin._Color) + ", " +
359  DB.SQLString(lcAsi) + ", " +
360  DB.SQLString(lnTraspas) + " " +
361  (_dOldCreated == DateTime.MinValue ? "" : ", " + DB.SQLString(_dOldCreated)) +
362  ") ";
363 
364  DB.SQLExec(lcSql);
365  }
366  }
367  }
368  else
369  {
370  lcSql = "INSERT INTO " + DB.SQLDatabase("LOTES", "LTDEPVE") + " " +
371  "(EMPRESA,LETRA,NUMERO,FECHA,ARTICULO,LINIA,LOTE,UNIDADES,PERIODO,ALMACEN,CADUCIDAD,UBICA,FECHA2,PESO,TALLA,COLOR,ASI" +
372  (_dOldCreated == DateTime.MinValue ? "" : ",CREATED") +
373  ") " +
374  "VALUES (" +
375  DB.SQLString(_oDocLin._Empresa) + ", " +
376  DB.SQLString(_oDocLin._Letra) + ", " +
377  DB.SQLString(_oDocLin._Numero) + ", " +
378  DB.SQLString(_oDocLin._Fecha) + ", " +
379  DB.SQLString(_oDocLin._Articulo) + ", " +
380  DB.SQLString(_oDocLin._LineaReal) + ", " +
381  DB.SQLString(toDetCodigo._Codigo) + ", " +
382  DB.SQLString(toDetCodigo._Unidades) + ", " +
383  DB.SQLString(_cPeriodo) + ", " +
384  DB.SQLString(_oDocLin._Almacen) + ", " +
385  DB.SQLString(toDetCodigo._Caducidad) + ", " +
386  DB.SQLString(toDetCodigo._Ubicacion) + ", " +
387  DB.SQLString(DateTime.Now) + ", " +
388  DB.SQLString(toDetCodigo._Peso) + ", " +
389  DB.SQLString(_oDocLin._Talla) + ", " +
390  DB.SQLString(_oDocLin._Color) + ", " +
391  DB.SQLString(toDetCodigo._Asi) + " " +
392  (_dOldCreated == DateTime.MinValue ? "" : ", " + DB.SQLString(_dOldCreated)) +
393  ") ";
394 
395 
396  DB.SQLExec(lcSql);
397  }
398  }
399 
404  protected override bool _Es_Documento_Entrada()
405  {
406  return _Es_Documento_Devolucion_Deposito();
407  }
408 
413  protected override bool _Es_Documento_Devolucion_Deposito()
414  {
415  return (_oDocLin._Unidades < 0);
416  }
417 
422  protected override string _Obtener_Nombre_Articulo()
423  {
424  return _oDocLin._Definicion;
425  }
426 
427 
432  protected override decimal _Get_Unidades_Linea()
433  {
434  return _oDocLin._Unidades - _oDocLin._Servidas;
435  }
436 
441  protected override decimal _Get_Peso_Linea()
442  {
443  if (_oDocLin._Servidas != 0 && (_oDocLin._Unidades - _oDocLin._Servidas) != 0)
444  return _oDocLin._Peso / (_oDocLin._Unidades - _oDocLin._Servidas);
445  else
446  return (_oDocLin._Peso);
447  }
448 
449 
450  #region IStockDocVenta
451 
452 
453 
454 
455 
456 
463  public bool _Delete(string tcLote, IDocumentLinea toLinea)
464  {
465  return true;
466  }
467 
475  public bool _Show(object toPadre, IDocumentLinea toLinea, bool tlReadOnly = false)
476  {
477  return true;
478  }
479 
480  #endregion IStockDocVenta
481 
482 
486  public override bool _Delete_Linial(dynamic toDocumentoLin)
487  {
488  DataTable ldtOldDades = new DataTable();
489  string lcSql = string.Empty;
490 
491  _Delete_Linial_Revisar_Depositos(toDocumentoLin);
492 
493  // Taula LOTES!LTDEPVE
494  lcSql = "SELECT DISTINCT ARTICULO, ALMACEN, TALLA, COLOR FROM " + DB.SQLDatabase("LOTES", "LTDEPVE") + " " +
495  " WHERE PERIODO = " + DB.SQLString(_cPeriodo) + " " +
496  " AND EMPRESA = " + DB.SQLString(toDocumentoLin._Empresa) + " " +
497  " AND NUMERO = " + DB.SQLString(toDocumentoLin._Numero) + " " +
498  " AND LETRA = " + DB.SQLString(toDocumentoLin._Letra) + " " +
499  " AND LINIA = " + DB.SQLString(toDocumentoLin._LineaReal);
500 
501  //Executo la consulta
502  if (!DB.SQLExec(lcSql, ref ldtOldDades))
503  return false;
504 
505  if (_Viene_Ejercicio_Anterior(toDocumentoLin))
506  {
507  int lnPeriodoAnterior = Convert.ToInt32(_cPeriodo) - 1;
508 
509  // Taula LOTES!LTDEPVE
510  lcSql = " UPDATE " + DB.SQLDatabase("LOTES", "LTDEPVE") +
511  " SET PERIODO = " + DB.SQLString(lnPeriodoAnterior) +
512  " WHERE PERIODO = " + DB.SQLString(_cPeriodo) +
513  " AND EMPRESA = " + DB.SQLString(toDocumentoLin._Empresa) +
514  " AND NUMERO = " + DB.SQLString(toDocumentoLin._Numero) +
515  " AND LETRA = " + DB.SQLString(toDocumentoLin._Letra) +
516  " AND LINIA = " + DB.SQLString(toDocumentoLin._LineaReal);
517  }
518  else
519  {
520  // Taula LOTES!LTDEPVE
521  lcSql = "DELETE FROM " + DB.SQLDatabase("LOTES", "LTDEPVE") + " " +
522  " WHERE PERIODO = " + DB.SQLString(_cPeriodo) + " " +
523  " AND EMPRESA = " + DB.SQLString(toDocumentoLin._Empresa) + " " +
524  " AND NUMERO = " + DB.SQLString(toDocumentoLin._Numero) + " " +
525  " AND LETRA = " + DB.SQLString(toDocumentoLin._Letra) + " " +
526  " AND LINIA = " + DB.SQLString(toDocumentoLin._LineaReal);
527  }
528 
529  //Executo la consulta
530  if (!DB.SQLExec(lcSql))
531  return false;
532 
533 
534  string lcArticulo = string.Empty;
535  string lcAlmacen = string.Empty;
536  string lcTalla = string.Empty;
537  string lcColor = string.Empty;
538 
539  if (ldtOldDades.Rows.Count > 0)
540  {
541  lcArticulo = ldtOldDades.Rows[0]["ARTICULO"].ToString().Trim();
542  lcAlmacen = ldtOldDades.Rows[0]["ALMACEN"].ToString().Trim();
543  lcTalla = ldtOldDades.Rows[0]["TALLA"].ToString().Trim();
544  lcColor = ldtOldDades.Rows[0]["COLOR"].ToString().Trim();
545 
546  this._Refrescar_Stocks(lcArticulo, lcAlmacen, lcTalla, lcColor); // Valors anteriors
547  }
548 
549 
550 
551  // si els valors son identics, no m'ho cal tornar a fer.
552  if (lcArticulo != toDocumentoLin._Articulo.Trim() || lcAlmacen != toDocumentoLin._Almacen.Trim() || lcTalla != toDocumentoLin._Talla.Trim() || lcColor != toDocumentoLin._Color.Trim())
553  this._Refrescar_Stocks(toDocumentoLin._Articulo, toDocumentoLin._Almacen, toDocumentoLin._Talla, toDocumentoLin._Color); // Valors actuals
554 
555 
556  return true;
557  }
558 
564  protected override bool _Viene_Ejercicio_Anterior(dynamic toDocumentoLinea)
565  {
566  if (_Existe_Ejercicio_Anterior())
567  {
568  DataTable ldtDatos = new DataTable();
569  string lcSql = string.Empty;
570 
571  lcSql = " SELECT * FROM " + DB.SQLDatabase("GESTION-1", "C_ALBDEP") +
572  " WHERE TRASPASADO = 1 " +
573  " AND EMPRESA = " + DB.SQLString(toDocumentoLinea._Empresa) +
574  " AND NUMERO = " + DB.SQLString(toDocumentoLinea._Numero) +
575  " AND LETRA = " + DB.SQLString(toDocumentoLinea._Letra);
576 
577  //Executo la consulta
578  DB.SQLExec(lcSql, ref ldtDatos);
579 
580  return ldtDatos.Rows.Count > 0;
581  }
582 
583  return false;
584  }
585 
586  private void _Delete_Linial_Revisar_Depositos(dynamic toDocumentoLinea)
587  {
588  // 100330
589  DataTable ldtLotes = new DataTable();
590  DataTable ldtRegs = new DataTable();
591  string lcSql = string.Empty;
592  string lcSet = string.Empty;
593 
594  if (toDocumentoLinea._Doc == 2)
595  {
596  lcSql = "SELECT * FROM " + DB.SQLDatabase("LOTES", "LTDEPVE") + " " +
597  " WHERE PERIODO = " + DB.SQLString(_cPeriodo) + " " +
598  " AND EMPRESA = " + DB.SQLString(toDocumentoLinea._Empresa) + " " +
599  " AND NUMERO = " + DB.SQLString(toDocumentoLinea._Numero) + " " +
600  " AND LETRA = " + DB.SQLString(toDocumentoLinea._Letra) + " " +
601  " AND LINIA = " + DB.SQLString(toDocumentoLinea._LineaReal);
602 
603  //Executo la consulta
604  DB.SQLExec(lcSql, ref ldtLotes);
605 
606  foreach (DataRow ldr in ldtLotes.Rows)
607  {
608  // Si ja tinc un registre a la taula, amb la mateixa clau primaria, acumulo les unitats/pes
609  lcSql = "SELECT * FROM " + DB.SQLDatabase("LOTES", "LTDEPVE") + " " +
610  " WHERE PERIODO = " + DB.SQLString(_cPeriodo) + " " +
611  " AND EMPRESA = " + DB.SQLString(toDocumentoLinea._Empresa) + " " +
612  " AND NUMERO = " + DB.SQLString(toDocumentoLinea._Doc_Num.Substring(0, 10)) + " " +
613  " AND LETRA = " + DB.SQLString(toDocumentoLinea._Doc_Num.Substring(10, 2)) + " " +
614  " AND LINIA = " + DB.SQLString(toDocumentoLinea._Doc_Lin) + " " +
615  " AND LOTE = " + DB.SQLString(ldr["lote"]) + " " +
616  " AND UBICA = " + DB.SQLString(ldr["ubica"]) + " " +
617  " AND TALLA = " + DB.SQLString(ldr["talla"]) + " " +
618  " AND COLOR = " + DB.SQLString(ldr["color"]) + " " +
619  " AND TRASPAS = " + DB.SQLString(0);
620  DB.SQLExec(lcSql, ref ldtRegs);
621 
622 
623  if (ldtRegs != null && ldtRegs.Rows.Count > 0)
624  {
625  foreach (DataRow ldrow in ldtRegs.Rows)
626  {
627  lcSet = ", UNIDADES = UNIDADES + " + DB.SQLString(ldtRegs.Rows[0].Field<decimal>("unidades"));
628  lcSet += ", PESO = PESO + " + DB.SQLString(ldtRegs.Rows[0].Field<decimal>("peso"));
629 
630  lcSql = " DELETE FROM " + DB.SQLDatabase("LOTES", "LTDEPVE") + " " +
631  " WHERE PERIODO = " + DB.SQLString(_cPeriodo) + " " +
632  " AND EMPRESA = " + DB.SQLString(toDocumentoLinea._Empresa) + " " +
633  " AND NUMERO = " + DB.SQLString(toDocumentoLinea._Doc_Num.Substring(0, 10)) + " " +
634  " AND LETRA = " + DB.SQLString(toDocumentoLinea._Doc_Num.Substring(10, 2)) + " " +
635  " AND LINIA = " + DB.SQLString(toDocumentoLinea._Doc_Lin) + " " +
636  " AND LOTE = " + DB.SQLString(ldrow["lote"]) + " " +
637  " AND UBICA = " + DB.SQLString(ldrow["ubica"]) + " " +
638  " AND TALLA = " + DB.SQLString(ldrow["talla"]) + " " +
639  " AND COLOR = " + DB.SQLString(ldrow["color"]) + " " +
640  " AND TRASPAS = " + DB.SQLString(0);
641  DB.SQLExec(lcSql);
642  }
643  }
644 
645  // ASI = '',
646  lcSql = "UPDATE " + DB.SQLDatabase("LOTES", "LTDEPVE") + " SET TRASPAS = 0, TFECHA = null " + lcSet +
647  " WHERE ASI = " + DB.SQLString(ldr["asi"]) + " ";
648  DB.SQLExec(lcSql);
649 
650  lcSet = string.Empty; // 101632
651  }
652  }
653  // fi 100330
654  }
655 
656  #region IVentasExtendidas
657 
664  public bool _Delete(Docsven.IDocVentaLin toLinea, bool tlAbono)
665  {
666  // 102334
667  bool llOk = true;
668 
669  if (toLinea._UsaLotes)
670  llOk = _Delete_Linial(toLinea);
671 
672  return llOk;
673  // fi 102334
674  }
675 
682  private bool _Eliminar_Series_Deposito_Venta(Docsven.IDocVentaLin toLinea, bool tlAbono)
683  {
684  return true;
685  }
686 
693  public bool _Obtener_Detalle(Docsven.IDocVentaLin toLinea, ref DataTable tdtResultados)
694  {
695  //Consulto datos de la tabla DEPSER filtrados por linea
696  //return _ConsultarDepser(toLinea, ref tdtResultados, true);
697  return true;
698  }
699 
705  public bool _Se_Puede_Borrar(Docsven.IDocVentaLin toLinea)
706  {
707  //return _Comprobaciones_Borrado_Series_Lineal(toLinea);
708  return true;
709  }
710 
719  public bool _Operacion_Permitida(Docsven.IDocVentaLin toLinea, CampsDocVentaLin teCampo, object toValue, ref string tcMensajeRespuesta)
720  {
721  bool llCondicion = false;
722 
723  // 103484
724  llCondicion = llCondicion || teCampo == CampsDocVentaLin.Articulo && !String.IsNullOrWhiteSpace(toLinea._Articulo) && String.Compare(toLinea._Articulo, (string)toValue) != 0;
725  llCondicion = llCondicion || teCampo == CampsDocVentaLin.Talla && !String.IsNullOrWhiteSpace(toLinea._Talla) && String.Compare(toLinea._Talla, (string)toValue) != 0;
726  llCondicion = llCondicion || teCampo == CampsDocVentaLin.Color && !String.IsNullOrWhiteSpace(toLinea._Color) && String.Compare(toLinea._Color, (string)toValue) != 0;
727  // fi 103484
728 
729 
730  //Sin restricciones específicas => Operaciones permitidas
731  if (llCondicion)
732  {
733  string lcDef = Convert.ToString(EW_GLOBAL._GetVariable("wc_deflote"));
734 
735  tcMensajeRespuesta = "No se permite modificar el artículo, trabaja con " + lcDef + ". " + Environment.NewLine +
736  "Pruebe a borrar el artículo e introducir uno de nuevo.";
737  return false;
738  }
739 
740  return true;
741 
742 
743  }
744 
750  public static bool _Comprobaciones_Borrado_Series(ewDocVentaDEPOSITO toDocumento)
751  {
752  return true;
753  }
754 
764  public bool _Show(Docsven.IDocVentaLin toLinea, CampsDocVentaLin teCampo, object toValue, object toRestricciones, ref string tcMensajeError)
765  {
766  bool llGestionEspecial = false;
767 
768  switch (teCampo)
769  {
770  case CampsDocVentaLin.Unidades:
771  case CampsDocVentaLin.Peso:
772  case CampsDocVentaLin.Cajas:
773  case CampsDocVentaLin.Talla:
774  case CampsDocVentaLin.Color:
775 
776  _oRestricciones = toRestricciones;
777 
778  // Control especial para saber si el documento se consulta de sólo lectura (PE-90431)
779  if (toValue == null) _ReadOnly = true;
780 
781  // Si el objecte toValue es false, vol dir que venim des del botó
782  if ((toValue is bool && (bool)toValue == false) || _ReadOnly) // PE-90431
783  _Iniciar_Asignacion_Lotes(toLinea, false);
784  else
785  _Iniciar_Asignacion_Lotes(toLinea, true);
786 
787  tcMensajeError = _Error_Message;
788  llGestionEspecial = true;
789  break;
790 
791  default:
792  break;
793  }
794 
795  return llGestionEspecial;
796  }
797 
803  public bool _Update(Docsven.IDocVentaLin toLinea)
804  {
805  throw new NotImplementedException();
806  }
807 
808  #endregion IVentasExtendidas
809 
810 
819  public bool _Update(docsven.Docsven.IDocVentaCab toCabecera, IEnumerable<docsven.Docsven.IDocVentaLin> toLineas, CampsDocVentaCab teCampo, object toValue)
820  {
821 
822  if (teCampo == CampsDocVentaCab.Fecha)
823  {
824  string lcSql = String.Empty;
825  ewCampo loFecha = (ewCampo)toValue;
826 
827  lcSql = "UPDATE " + DB.SQLDatabase("LOTES", "LTDEPVE") + " " +
828  " SET PERIODO = " + DB.SQLString(_cPeriodo) + ",FECHA = " + DB.SQLString(loFecha._NewVal) +
829  " WHERE PERIODO = " + DB.SQLString(_cPeriodo) + " " +
830  " AND EMPRESA = " + DB.SQLString(toLineas.FirstOrDefault()._Empresa) +
831  " AND NUMERO = " + DB.SQLString(toLineas.FirstOrDefault()._Numero) +
832  " AND LETRA = " + DB.SQLString(toLineas.FirstOrDefault()._Letra);
833  DB.SQLExec(lcSql);
834  }
835 
836  return true;
837  }
838 
845  {
846  //TODO Implementar obtención del coste
847  return _oLotesConfig._Coste;
848  }
849  }
850 
851 
856  {
857  private string _cPeriodo = Convert.ToString(EW_GLOBAL._GetVariable("wc_any"));
858 
863  {
864 
865  }
866 
867 
875  {
876  DataTable table = new DataTable();
877 
878  DB.SQLExec(" SELECT 1 FROM " + DB.SQLDatabase("LOTES", "LTDEPVE") + " " +
879  " WHERE PERIODO = " + DB.SQLString(_cPeriodo) +
880  " AND EMPRESA = " + DB.SQLString(toLinea._Empresa) +
881  " AND LETRA = " + DB.SQLString(toLinea._Letra) +
882  " AND NUMERO = " + DB.SQLString(toLinea._Numero) +
883  " AND LINIA = " + DB.SQLString(toLinea._LineaReal) +
884  " AND LOTE = " + DB.SQLString(toLote._Lote) +
885  " AND UBICA = " + DB.SQLString("") +
886  " AND TALLA = " + DB.SQLString(toLinea._Talla) +
887  " AND COLOR = " + DB.SQLString(toLinea._Color), ref table);
888 
889  if (table.Rows.Count == 0)
890  {
891 
892  DB.SQLExec("INSERT INTO " + DB.SQLDatabase("LOTES", "LTDEPVE") + " " +
893  "(EMPRESA,LETRA,NUMERO,FECHA,ARTICULO,LINIA,LOTE,UNIDADES,PERIODO,ALMACEN,CADUCIDAD,UBICA,FECHA2,PESO,TALLA,COLOR,ASI) " +
894  "VALUES (" +
895  DB.SQLString(toLinea._Empresa) + ", " +
896  DB.SQLString(toLinea._Letra) + ", " +
897  DB.SQLString(toLinea._Numero) + ", " +
898  DB.SQLString(toLinea._Fecha) + ", " +
899  DB.SQLString(toLote._Articulo) + ", " +
900  DB.SQLString(toLinea._LineaReal) + ", " +
901  DB.SQLString(toLote._Lote) + ", " +
902  DB.SQLString(toLote._Unidades) + ", " +
903  DB.SQLString(_cPeriodo) + ", " +
904  DB.SQLString(toLinea._Almacen) + ", " +
905  DB.SQLString(toLote._Caducidad) + ", " +
906  DB.SQLString(toLote._Ubicacion) + ", " +
907  DB.SQLString(DateTime.Now) + ", " +
908  DB.SQLString(toLote._Peso) + ", " +
909  DB.SQLString(toLinea._Talla) + ", " +
910  DB.SQLString(toLinea._Color) + ", " +
911  DB.SQLString(toLote._Asi) + ") ");
912  }
913 
914  return true;
915  }
916  }
917 }
bool _Delete(Docsven.IDocVentaLin toLinea, bool tlAbono)
Método delete
bool _Delete(string tcLote, IDocumentLinea toLinea)
Operaciones de borrado
Clase para controlar toda la gestion de venta de un lote/ubicacion de artículo
override bool _Autoasignacion()
Indica si está activada la autoasignación dependiendo del tipo de documento
override void _Consultar_Stock_Disponible(ref DataTable tdtStockLote)
Consultar stock disponible
bool _ObtenerCosteLinea(Docsven.IDocVentaLin toLinea)
Obtiene el coste de la línea
Clase para la gestión de los lotes
Definition: Lote.cs:37
override void _InsertLinDocStockLotes(LinVenDetLotes toDetCodigo)
Nou metode buit que es sobreescriurà per cada document, per insertar 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
string _Talla
Codigo de la talla
Interficie mínima de las líneas (Mantener lo mas reducida posible)
Definition: IDocument.cs:186
Clase de lotes para depositos de venta (depoven)
bool _Asignar_Articulos_Lote(sage.ew.lote.Clases.Lote toLote, IDocumentLinea toLinea)
Insertar la información en la tabla LOTES!LTDEPVE
override decimal _Get_Unidades_Linea()
Obtener las unidades en función del tipo de operación
override string _Obtener_Nombre_Articulo()
Obtener el nombre del artículo de la linea actual
Classe campo para las entidades, que permitirá comprobar si se ha cambiado su valor ...
Definition: clsEwBase.cs:676
Nullable< DateTime > _Caducidad
Fecha de caducidad del lote (Accepta NULL)
bool _Obtener_Detalle(Docsven.IDocVentaLin toLinea, ref DataTable tdtResultados)
Método para obtener detalle
bool _Se_Puede_Borrar(Docsven.IDocVentaLin toLinea)
Método lineal para comprobar si la línea se puede borrar
override bool _Desactivar_Control_Stock()
Nou metode buit que es sobreescriurà per cada document, per verificar el control d&#39;stock ...
bool _Show(Docsven.IDocVentaLin toLinea, CampsDocVentaLin teCampo, object toValue, object toRestricciones, ref string tcMensajeError)
Método show
override bool _Delete_Linial(dynamic toDocumentoLin)
Borra el lote de la tabla LTDEPVE
bool _Update(Docsven.IDocVentaLin toLinea)
Método update
Classe Robot (Comportamiento) para los depositos de venta
CampsDocVentaLin
Enumera todos los nombres de propiedades (SET) de la LINEA
Definition: DocsVen.cs:214
CampsDocVentaCab
Enumera todos los nombres de propiedades (SET) de la CABECERA
Definition: DocsVen.cs:79
string _Codigo
Código de lote asociado
LoteDocVentaDeposito()
Constructor de la clase LoteDocVentaDeposito
override void _Consultar_Lotes_Documento()
Nou metode buit que es sobreescriurà per cada document
Classe base dels documents.
Definition: DocsVen.cs:684
override bool _Viene_Ejercicio_Anterior(dynamic toDocumentoLinea)
Comprobamos si el documento viene del ejercicio anterior
override bool _Es_Documento_Devolucion_Deposito()
Indica si es un documento de depósito
override void _Nueva_Asignacion_Buscar_Stock()
Buscamos el stock a seleccionar, en los lotes asignados en el deposito
object _NewVal
Valor nuevo
Definition: clsEwBase.cs:712
override void _ComprobarBloqueos()
Comprobar si existe alguna restricción, para que se abra el formulario de asignación de lotes...
override bool _Es_Documento_Entrada()
Nos devuelve si el documento es de entrada o salida de stock
decimal _Peso
Peso asignado a la venta
string _Ubicacion
Código de la ubicación
Interficie para operaciones extendidas de lineas de venta
string _Asi
Asi del registro
Interficie de les linies
Definition: DocsVen.cs:907
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
override void _DeleteLinDocStockLotes(LinVenDetLotes toDetCodigo)
Nou metode buit que es sobreescriurà per cada document, per eliminar els moviments a les taules de lo...
override decimal _Get_Peso_Linea()
Obtener el peso en función del tipo de operación
static bool _Comprobaciones_Borrado_Series(ewDocVentaDEPOSITO toDocumento)
Realiza las comprobaciones de borrado de documentos relativas al trabajo con series ...
decimal _Unidades
Unidades asignadas a la venta
bool _Operacion_Permitida(Docsven.IDocVentaLin toLinea, CampsDocVentaLin teCampo, object toValue, ref string tcMensajeRespuesta)
Método de comprobación de operaciones permitidas
bool _Update(docsven.Docsven.IDocVentaCab toCabecera, IEnumerable< docsven.Docsven.IDocVentaLin > toLineas, CampsDocVentaCab teCampo, object toValue)
Update general por cambios en campos de la cabecera
LoteDocVentaDeposito(string tcLote, IDocumentLinea toDocumentoLin=null)
Constructor con parámetros (utiliza el constructor base)
Clase de documentos DEPOSITO
Definition: DocsDeposito.cs:33