ExtensionesSeries.cs
1 using System;
2 using System.Data;
3 using System.Linq;
4 using sage.ew.db;
5 using sage.ew.docscompra;
6 using sage.ew.docsven;
7 using sage.ew.docventatpv;
8 using sage.ew.global;
9 
10 namespace sage.ew.serie
11 {
12 
16  public static class ExtensionesSerie
17  {
18 
19  #region Extensiones DocVentaTPV
20 
25  public static void __FozarComprobacionSeriesLineaFacturable(this sage.ew.docventatpv.ewDocVentaLinTPV toLinea)
26  {
27  if (toLinea._UsaSeries && toLinea._Unidades != 0.0M)
28  {
29  //Cargo las series asiciadas a la línea
31  {
32  _Lineas = toLinea //Asigno la linea actual
33  };
34  loLinVenDetSer._Load(); //Cargo los datos
35 
36  bool llLineaFacturable = Math.Abs(toLinea._Unidades) == loLinVenDetSer._lisCodigos.Count(ele => !string.IsNullOrEmpty(ele._Codigo));
37  toLinea._LineaFacturable = llLineaFacturable;
38  if (llLineaFacturable)
39  toLinea._Evaluar_Documento_Facturable();
40  }
41  }
42 
49  public static bool __Contiene_Series(this sage.ew.docscompra.DocsCompra.ewDocCompraLin toDocLinea, ref DataTable toComser)
50  {
51  //Creo la sentencia
52  string lcSql = string.Empty;
53  bool llOk = false;
54  DataTable ldtSeries = new DataTable();
55  lcSql = "SELECT COUNT(EMPRESA) AS TOTAL FROM" + DB.SQLDatabase("GESTION", "COMSER") +
56  " WHERE EMPRESA =" + DB.SQLString(toDocLinea._Empresa) + " AND " +
57  " ALBARAN =" + DB.SQLString(toDocLinea._Numero) + " AND " +
58  " PROVEEDOR =" + DB.SQLString(toDocLinea._Proveedor);
59  llOk = DB.SQLExec(lcSql, ref ldtSeries);
60 
61  if (llOk && Convert.ToInt32(ldtSeries.Rows[0]["TOTAL"]) > 0)
62  {
63  Serie loSerie = new Serie();
64  string tcEmpresa = toDocLinea._Empresa;
65  string tcNumero = toDocLinea._Numero;
66  string tcLetra = toDocLinea._Letra;
67  int tnLinea = toDocLinea._LineaReal;
68  loSerie._Lineas = toDocLinea;
69  bool llOk2 = loSerie._ConsultarComser(tcEmpresa, tcNumero, tcLetra, tnLinea, ref toComser);
70  if (llOk2 && toComser.Rows.Count > 0)
71  return true;
72  return false;
73  }
74  else return false;
75  }
76 
81  public static bool __Contiene_Series(this sage.ew.docventatpv.ewDocVentaTPV toDocVentaTPV)
82  {
83  //Creo la sentencia
84  string lcSql = string.Empty;
85  bool llOk = false;
86  DataTable ldtSeries = new DataTable();
87  lcSql = "SELECT COUNT(EMPRESA) AS TOTAL FROM" + DB.SQLDatabase("GESTION", "VENSER") +
88  " WHERE EMPRESA =" + DB.SQLString(toDocVentaTPV._Empresa) + " AND " +
89  " ALBARAN =" + DB.SQLString(toDocVentaTPV._Numero) + " AND " +
90  " LETRA =" + DB.SQLString(toDocVentaTPV._Letra);
91  llOk = DB.SQLExec(lcSql, ref ldtSeries);
92 
93  if (llOk && Convert.ToInt32(ldtSeries.Rows[0]["TOTAL"]) > 0) return true;
94  else return false;
95  }
96 
97 
102  public static bool __Contiene_Series(this sage.ew.docventatpv.ewDocVentaLinTPV toDocVentaLinTPV)
103  {
104  DataTable toVenser = new DataTable();
105  return toDocVentaLinTPV.__Contiene_Series(ref toVenser);
106 
107  }
108 
115  public static bool __Contiene_Series(this sage.ew.docventatpv.ewDocVentaLinTPV toDocVentaLinTPV, ref DataTable toVenser)
116  {
117  Serie loSerie = new Serie();
118  string tcEmpresa = toDocVentaLinTPV._Empresa;
119  string tcNumero = toDocVentaLinTPV._Numero;
120  string tcLetra = toDocVentaLinTPV._Letra;
121  int tnLinea = toDocVentaLinTPV._LineaReal;
122  bool llOk = loSerie._ConsultarVenser(tcEmpresa, tcNumero, tcLetra, tnLinea, ref toVenser);
123  if (llOk && toVenser.Rows.Count > 0)
124  return true;
125  return false;
126  }
127 
134  public static bool __Contiene_Series(this sage.ew.docsven.ewDocVentaLinPRESUP toLin, ref DataTable toVenser)
135  {
136  Montaje loMontaje = new Montaje();
137  string tcEmpresa = toLin._Empresa;
138  string tcNumero = toLin._Numero;
139  string tcLetra = toLin._Letra;
140  int tnLinea = toLin._LineaReal;
141  bool llOk = loMontaje._ConsultarMontajesPresupuesto(tcEmpresa, tcNumero, tcLetra, tnLinea, ref toVenser);
142  if (llOk && toVenser.Rows.Count > 0)
143  return true;
144  return false;
145  }
146 
151  public static bool __Contiene_Series_Factura(this sage.ew.docsven.ewDocVentaFRA toDocVentaFRA)
152  {
153  //Creo la sentencia
154  string lcSql = string.Empty;
155  bool llOk = false;
156  DataTable ldtSeries = new DataTable();
157 
158  lcSql = "SELECT COUNT(C.EMPRESA) AS TOTAL FROM" + DB.SQLDatabase("GESTION", "VENSER") + " V " +
159  "INNER JOIN " + DB.SQLDatabase("GESTION", "C_ALBVEN") + " C ON V.EMPRESA = C.EMPRESA AND V.ALBARAN = C.NUMERO AND V.LETRA=C.LETRA " +
160  " WHERE C.EMPRESA =" + DB.SQLString(toDocVentaFRA._Empresa) + " AND " +
161  " C.FACTURA = " + DB.SQLString(toDocVentaFRA._Letra + toDocVentaFRA._Numero);
162 
163  llOk = DB.SQLExec(lcSql, ref ldtSeries);
164 
165  if (llOk && Convert.ToInt32(ldtSeries.Rows[0]["TOTAL"]) > 0)
166  return true;
167  else
168  return false;
169 
170  }
171 
177  public static bool __Documento_Facturable(this sage.ew.docventatpv.ewDocVentaTPV toDocVentaTPV)
178  {
179  //PE-85554 Opcflag No controlar series para facturar albaran
180  bool llFacturarSinSerie = Convert.ToBoolean(EW_GLOBAL._GetVariable("wl_facturaser"));
181  if (llFacturarSinSerie) return toDocVentaTPV._Cabecera._Facturable; //No aplica. Devuelvo lo que ya tiene
182  else
183  {
184  Serie loSerie = new Serie();
185  return (loSerie._Documento_Facturable(toDocVentaTPV));
186  }
187  }
188 
197  public static bool __Cambio_Series_Documento_Venta(this docventatpv.ewDocVentaTPV toDocOrigen, string tcNuevaEmpresa = "", string tcNuevoNumero = "", string tcNuevaLetra = "")
198  {
199  bool llOk = false;
200  //Si no hay documento o no tiene lineas acabo
201 
202  if (toDocOrigen == null || toDocOrigen._Lineas == null || toDocOrigen._Lineas.Count == 0) return llOk;
203  //Si no tengo documento nuevo acabo
204  if (string.IsNullOrWhiteSpace(tcNuevaEmpresa) || string.IsNullOrWhiteSpace(tcNuevoNumero)) return llOk;
205 
206  Serie loSerie = new Serie();
207  return (loSerie._Cambio_Documento_Venta(toDocOrigen, tcNuevaEmpresa, tcNuevoNumero, tcNuevaLetra));
208  }
209 
217  public static bool __Modificar_Reserva_Series(this docventatpv.ewDocVentaTPV toDocOrigen, string tcNumero, string tcNumero2)
218  {
219  bool llOk = false;
220  //Si no hay documento o no tiene lineas acabo
221 
222  if (toDocOrigen == null || toDocOrigen._Lineas == null || toDocOrigen._Lineas.Count == 0) return llOk;
223 
224  //Si no tengo documento nuevo acabo
225  if (string.IsNullOrWhiteSpace(tcNumero) || string.IsNullOrWhiteSpace(tcNumero2)) return llOk;
226 
227  Serie loSerie = new Serie();
228  return (loSerie._Modificar_Reserva_Venta(toDocOrigen, tcNumero, tcNumero2));
229  }
230 
231  #endregion Extensiones DocVentaTPV
232 
233  #region Extensiones DocVentaLinTPV
234 
240  public static bool __Documento_Facturable(this sage.ew.docventatpv.ewDocVentaLinTPV toDocVentaLinTPV)
241  {
242  //PE-85554 Opcflag No controlar series para facturar albaran
243  bool llFacturarSinSerie = Convert.ToBoolean(EW_GLOBAL._GetVariable("wl_facturaser"));
244  if (llFacturarSinSerie) return toDocVentaLinTPV.DocVenta._Cabecera._Facturable; //No aplica. Devuelvo lo que ya tiene
245  else
246  {
247  Serie loSerie = new Serie();
248  return (loSerie._Documento_Facturable(toDocVentaLinTPV.DocVenta));
249  }
250  }
251 
257  public static bool __Regularizar_Venta_VFP(this sage.ew.docventatpv.ewDocVentaLinTPV toDocVentaLinTPV, string tcSerie)
258  {
259  Serie loSerie = new Serie(tcSerie, toDocVentaLinTPV);
260  bool llOk = false;
261 
262  if (toDocVentaLinTPV._Unidades > 0) llOk = loSerie._Vender_Serie(toDocVentaLinTPV);
263  else llOk = loSerie._Abonar_Serie(toDocVentaLinTPV);
264 
265  return (llOk);
266  }
267 
268  #endregion Extensiones DocVentaLinTPV
269 
270  #region Extensiones
271 
278  public static bool __Contiene_Series_Deposito(this ewDocVentaLinDEPOSITO toDocVentaLinDeposito, ref DataTable toVenser)
279  {
280  bool llOk = false;
281 
282  //Es modelo / montaje?
283  bool llModelo = false;
284  if (toDocVentaLinDeposito._oArticulo != null)
285  llModelo = toDocVentaLinDeposito._oArticulo._EsMontaje;
286 
287  if (!llModelo)
288  {
289  //Serie
290  Serie loSerie = new Serie();
291  llOk = loSerie._ConsultarDepser(toDocVentaLinDeposito, ref toVenser);
292  }
293  else
294  {
295  //Montaje
296  Montaje loMontaje = new Montaje();
297  llOk = loMontaje._ConsultarDepser(toDocVentaLinDeposito, ref toVenser);
298  }
299 
300  if (llOk && toVenser.Rows.Count > 0)
301  return true;
302  return false;
303  }
304 
309  public static bool __Contiene_Series_Deposito(this ewDocVentaDEPOSITO toDocDeposito)
310  {
311  //Creo la sentencia
312  string lcSql = string.Empty;
313  bool llOk = false;
314  DataTable ldtSeries = new DataTable();
315  lcSql = "SELECT COUNT(EMPRESA) AS TOTAL FROM" + DB.SQLDatabase("GESTION", "DEPSER") +
316  " WHERE EMPRESA =" + DB.SQLString(toDocDeposito._Empresa) + " AND " +
317  " DEPOSITO =" + DB.SQLString(toDocDeposito._Numero) + " AND " +
318  " LETRA =" + DB.SQLString(toDocDeposito._Letra);
319  llOk = DB.SQLExec(lcSql, ref ldtSeries);
320 
321  if (llOk && Convert.ToInt32(ldtSeries.Rows[0]["TOTAL"]) > 0) return true;
322  else return false;
323  }
324 
330  public static bool __Comprobaciones_Borrado_Series_DepoVen(this ewDocVentaDEPOSITO toDocDeposito)
331  {
332  return true;
333  // SerieDocVentaDeposito._Comprobaciones_Borrado_Series(toDocDeposito);
334  }
335 
336 
337  #endregion
338 
339  #region Extensiones DocCompra
340 
345  public static bool __Contiene_Series_Compra(this ewDocCompraALBARAN toDocCompra)
346  {
347  //Creo la sentencia
348  string lcSql = string.Empty;
349  bool llOk = false;
350  DataTable ldtSeries = new DataTable();
351  lcSql = "SELECT COUNT(EMPRESA) AS TOTAL FROM" + DB.SQLDatabase("GESTION", "COMSER") +
352  " WHERE EMPRESA =" + DB.SQLString(toDocCompra._Empresa) + " AND " +
353  " ALBARAN =" + DB.SQLString(toDocCompra._Numero) + " AND " +
354  " PROVEEDOR =" + DB.SQLString(toDocCompra._Cabecera._Proveedor);
355  llOk = DB.SQLExec(lcSql, ref ldtSeries);
356 
357  if (llOk && Convert.ToInt32(ldtSeries.Rows[0]["TOTAL"]) > 0) return true;
358  else return false;
359  }
360 
365  public static bool __Contiene_Series_Compra(this ewDocCompraDEPOSITO toDocCompra)
366  {
367  //Creo la sentencia
368  string lcSql = string.Empty;
369  bool llOk = false;
370  DataTable ldtSeries = new DataTable();
371  lcSql = "SELECT COUNT(EMPRESA) AS TOTAL FROM" + DB.SQLDatabase("GESTION", "DEPCSER") +
372  " WHERE EMPRESA =" + DB.SQLString(toDocCompra._Empresa) + " AND " +
373  " ALBARAN =" + DB.SQLString(toDocCompra._Numero);
374  llOk = DB.SQLExec(lcSql, ref ldtSeries);
375 
376  if (llOk && Convert.ToInt32(ldtSeries.Rows[0]["TOTAL"]) > 0) return true;
377  else return false;
378  }
379 
386  public static bool __Comprobaciones_Borrado_Series(this ewDocCompraDEPOSITO toDocCompra, ref string tcMensaje)
387  {
388  return SerieDocCompraDeposito._Comprobaciones_Borrado_Series(toDocCompra, ref tcMensaje);
389  }
390 
397  public static bool __Comprobaciones_Borrado_Series(this ewDocCompraALBARAN toDocCompra, ref string tcMensaje)
398  {
399  return SerieDocCompra._Comprobaciones_Borrado_Series(toDocCompra, ref tcMensaje);
400  }
401 
402  #endregion Extensiones DocCompra
403 
404  #region Extensiones Clientes
405 
413  public static DataTable __Series_Vendidas(this sage.ew.cliente.Cliente toCliente, String tcFamilia = "")
414  {
415  Serie loSerie = new Serie();
416  return loSerie._Series_Vendidas(toCliente._Codigo, tcFamilia);
417  }
418 
426  public static DataTable __Series_Vendidas_con_Depositos(this sage.ew.cliente.Cliente toCliente, String tcFamilia = "")
427  {
428  Serie loSerie = new Serie();
429  return loSerie._Series_Vendidas_con_Depositos(toCliente._Codigo, tcFamilia);
430  }
431 
439  public static DataTable __Series_Vendidas_Familia(this sage.ew.cliente.Cliente toCliente, String tcFamilia = "")
440  {
441  Serie loSerie = new Serie();
442  return loSerie._Series_Vendidas_Familia(toCliente._Codigo, tcFamilia);
443  }
444 
445 
446  #endregion Extensiones Clientes
447 
448  #region Extensiones String
449 
456  public static string __ToConcatenableQuery(this string tcQuery)
457  {
458  //Si esta vacia no hago nada
459  if (string.IsNullOrWhiteSpace(tcQuery))
460  return "";
461 
462  //Elimino espacios en blanco que pudiera tener
463  tcQuery = tcQuery.TrimEnd();
464 
465  //Sino termina en ; lo añado
466  if (!tcQuery.TrimEnd().EndsWith(";"))
467  tcQuery += "; ";
468 
469  return tcQuery;
470  }
471 
472  private static string __ToBDString(this string tcCampo)
473  {
474  return DB.SQLString(tcCampo);
475  }
476 
477  #endregion Extensiones String
478 
479  }
480 }
virtual string _Numero
Número del document
Definition: DocsVen.cs:2356
Clase linea del presupuesto
Definition: DocsPresup.cs:3366
string _Empresa
Codi d'emrpesa
Definition: DocsVen.cs:2327
bool _Load()
Cargará todas las series/lotes asignadas a una linea del documento de venta
Definition: LinVenDet.cs:677
Clase documento de DEPOSITO DE COMPRA
Clase documento de venta TPV
Definition: DocVentaTpv.cs:47
Classe documento Factura de venta
Definition: DocsVentaFra.cs:61
virtual string _Letra
Lletra
Definition: DocsVen.cs:2340
virtual Articulo _oArticulo
Objeto Articulo
Definition: DocsVen.cs:16423
Clase linea de documento de venta TPV
Clase documento de ALBARANES DE COMPRA
Linies de documents de compra
Definition: DocsCompra.cs:1896
BindingList< T > _lisCodigos
Códigos de series/lotes asignados a una linea del documento de venta
Definition: LinVenDet.cs:557
Classe base dels documents de compra
Definition: DocsCompra.cs:414
Clase de documentos DEPOSITO
Definition: DocsDeposito.cs:33
Clase que gestiona las series/lotes asignados a una linea de un documento de venta ...
Definition: LinVenDet.cs:534