Cursor aIds = querySql("SELECT DISTINCT CLiente, FechaCobro FROM " + SqliteDB.DBhelper.TABLE_NAME_DETALLECLIENTE + " WHERE " + SqliteDB.DBhelper.COLUMN_NAME_Status + " = " + " '" + true + "'", null); SimpleDateFormat DateFormatterd = new SimpleDateFormat("E MMM dd HH:mm:ss Z yyyy", Locale.ENGLISH); int cont = aIds.getCount(); if (aIds.getCount() > 0) { while (aIds.moveToNext()) { int _Cliente = aIds.getInt(aIds.getColumnIndex(SqliteDB.DBhelper.COLUMN_NAME_CLiente)); Date _Fecha = null; try { _Fecha = (DateFormatterd.parse(aIds.getString(aIds.getColumnIndex(SqliteDB.DBhelper.COLUMN_NAME_FechaCobro)))); } catch (ParseException e) { e.printStackTrace(); }
Cursor aIds = querySql("SELECT DISTINCT CLiente, FechaCobro FROM " + SqliteDB.DBhelper.TABLE_NAME_DETALLECLIENTE + " WHERE " + SqliteDB.DBhelper.COLUMN_NAME_Status + " = " + " '" + true + "'", null);
SimpleDateFormat DateFormatterd = new SimpleDateFormat("E MMM dd HH:mm:ss Z yyyy", Locale.ENGLISH);
int cont = aIds.getCount();
if (aIds.getCount() > 0) {
while (aIds.moveToNext()) {
int _Cliente = aIds.getInt(aIds.getColumnIndex(SqliteDB.DBhelper.COLUMN_NAME_CLiente));
Date _Fecha = null;
try {
_Fecha = (DateFormatterd.parse(aIds.getString(aIds.getColumnIndex(SqliteDB.DBhelper.COLUMN_NAME_FechaCobro))));
} catch (ParseException e) {
e.printStackTrace();
}
Cursor aRs = querySql("SELECT * FROM " + SqliteDB.DBhelper.TABLE_NAME_DETALLECLIENTE + " WHERE " + SqliteDB.DBhelper.COLUMN_NAME_Status + " = " + " '" + true + "'" + " AND CLiente=" + _Cliente + " AND FechaCobro " + "=" + "'" + _Fecha + "'" , null);
SimpleDateFormat DateFormatterD = new SimpleDateFormat("E MMM dd HH:mm:ss Z yyyy", Locale.ENGLISH);
if (aRs.getCount() > 0 || aRs.getCount() == _Cliente) {
while (aRs.moveToNext()) {
Id = aRs.getInt(aRs.getColumnIndex(SqliteDB.DBhelper.COLUMN_NAME_ID));
Folio = aRs.getString(aRs.getColumnIndex(SqliteDB.DBhelper.COLUMN_NAME_Folio));
ClientClave = aRs.getInt(aRs.getColumnIndex(SqliteDB.DBhelper.COLUMN_NAME_CLiente));
try {
Date Fecha = DateFormatterD.parse(aRs.getString(aRs.getColumnIndex(SqliteDB.DBhelper.COLUMN_NAME_Fecha)));
} catch (ParseException e) {
e.printStackTrace();
}
DocumentoD = aRs.getInt(aRs.getColumnIndex(SqliteDB.DBhelper.COLUMN_NAME_Documento));
DocumentoDescripcion = aRs.getString(aRs.getColumnIndex(SqliteDB.DBhelper.COLUMN_NAME_DocumentoDescripcion));
IdCliente = aRs.getInt(aRs.getColumnIndex(SqliteDB.DBhelper.COLUMN_NAME_CLiente));
MonedaD = aRs.getInt(aRs.getColumnIndex(SqliteDB.DBhelper.COLUMN_NAME_MonedaD));
ImporteD = aRs.getDouble(aRs.getColumnIndex(SqliteDB.DBhelper.COLUMN_NAME_Importe));
DescuentoD = aRs.getDouble(aRs.getColumnIndex(SqliteDB.DBhelper.COLUMN_NAME_Descuento));
SubTotalD = aRs.getDouble(aRs.getColumnIndex(SqliteDB.DBhelper.COLUMN_NAME_SubTotal));
Retencion1D = aRs.getDouble(aRs.getColumnIndex(SqliteDB.DBhelper.COLUMN_NAME_Retencion1));
Retencion2D = aRs.getDouble(aRs.getColumnIndex(SqliteDB.DBhelper.COLUMN_NAME_Retencion2));
IEPSD = aRs.getDouble(aRs.getColumnIndex(SqliteDB.DBhelper.COLUMN_NAME_IEPS));
IVAD = aRs.getDouble(aRs.getColumnIndex(SqliteDB.DBhelper.COLUMN_NAME_IVA));
TotalD = aRs.getDouble(aRs.getColumnIndex(SqliteDB.DBhelper.COLUMN_NAME_Total));
Saldo = aRs.getDouble(aRs.getColumnIndex(SqliteDB.DBhelper.COLUMN_NAME_SaldoD));
Double SaldoVencido = aRs.getDouble(aRs.getColumnIndex(SqliteDB.DBhelper.COLUMN_NAME_SaldovencidoD));
String ParcialidadD = aRs.getString(aRs.getColumnIndex(SqliteDB.DBhelper.COLUMN_NAME_Parcialidad));
Double ParcialidadTotal = aRs.getDouble(aRs.getColumnIndex(SqliteDB.DBhelper.COLUMN_NAME_ParcialidadTotal));
String PagoCondicionDescripcion = aRs.getString(aRs.getColumnIndex(SqliteDB.DBhelper.COLUMN_NAME_PagoCondicionDescripcion));
UltimoCobroObservacion = aRs.getString(aRs.getColumnIndex(SqliteDB.DBhelper.COLUMN_NAME_UltimoCobroObservacion));
TotalAplicado += aRs.getDouble(aRs.getColumnIndex(SqliteDB.DBhelper.COLUMN_NAME_TotalApli));
TotalApli = aRs.getDouble(aRs.getColumnIndex(SqliteDB.DBhelper.COLUMN_NAME_TotalApli));
UrlD = aRs.getString(aRs.getColumnIndex(SqliteDB.DBhelper.COLUMN_NAME_URL));
DireccionD = aRs.getString(aRs.getColumnIndex(SqliteDB.DBhelper.COLUMN_NAME_Direccion));
}
if (aRs.getCount() > 1)
{
if (TotalAplicado > 0 || TotalAplicado == 0 ) {
Factor = TotalAplicado / TotalD;
Importe += ImporteD * Factor;
Descuento += DescuentoD * Factor;
SubTotal += SubTotalD * Factor;
IVA += IVAD * Factor;
Retencion1 += Retencion1D * Factor;
Retencion2 += Retencion2D * Factor;
IEPS += IEPSD * Factor;
Total += TotalD * Factor;
Url = UrlD;
Direccion = DireccionD;
Cliente = IdCliente;
Moneda = MonedaD;
Observaciones = UltimoCobroObservacion;
O_ResultadoEncabezado = O_WS.LLenarEncabezadoCXCP("I", //Accion I
0, //Id = 0
"",
new Date(),
Cliente,
0,
Moneda,
1.0, //Tipo de Cambio por default 1
0, //Cuenta Bancaria
1, //Pago Forma
Total, //Saldo
Importe, //Importe
0, //Financiamiento
Descuento,
SubTotal,
Retencion1,
Retencion2,
IEPS,
IVA,
0, //ISH,
Total, //Total
Total, //totalaplicado,
"A", //status,
"", //usucariocancela,
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, //Numero1...Numero10
Url, //Texto1
Direccion, //Texto2
"", "", "", "", "", "", "", "", //Texto1...Texto10
new Date(), new Date(), new Date(), new Date(), new Date(), new Date(), //Fecha1...Texto6
Observaciones, //Observacion
0, 0, 0, 0, 0, 0, //Catalogo1...Catalogo6
"", //ordencompra
0, //concepto
"", //observacioncancelacion
0, //origenventacompra,
0 //origeninventario
);
}
}else{
if (TotalApli > 0 || TotalApli == 0) {
Factor = TotalApli / TotalD;
Importe += ImporteD * Factor;
Descuento += DescuentoD * Factor;
SubTotal += SubTotalD * Factor;
IVA += IVAD * Factor;
Retencion1 += Retencion1D * Factor;
Retencion2 += Retencion2D * Factor;
IEPS += IEPSD * Factor;
Total += TotalD * Factor;
Url = UrlD;
Direccion = DireccionD;
Cliente = IdCliente;
Moneda = MonedaD;
Observaciones = UltimoCobroObservacion;
O_ResultadoEncabezado = O_WS.LLenarEncabezadoCXCP("I", //Accion I
0, //Id = 0
"",
new Date(),
Cliente,
0,
Moneda,
1.0, //Tipo de Cambio por default 1
0, //Cuenta Bancaria
1, //Pago Forma
Total, //Saldo
Importe, //Importe
0, //Financiamiento
Descuento,
SubTotal,
Retencion1,
Retencion2,
IEPS,
IVA,
0, //ISH,
Total, //Total
Total, //totalaplicado,
"A", //status,
"", //usucariocancela,
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, //Numero1...Numero10
Url, //Texto1
Direccion, //Texto2
"", "", "", "", "", "", "", "", //Texto1...Texto10
new Date(), new Date(), new Date(), new Date(), new Date(), new Date(), //Fecha1...Texto6
Observaciones, //Observacion
0, 0, 0, 0, 0, 0, //Catalogo1...Catalogo6
"", //ordencompra
0, //concepto
"", //observacioncancelacion
0, //origenventacompra,
0 //origeninventario
);
}
}
}
if (O_ResultadoEncabezado.ErrorId == 0) {
aRs.moveToFirst();
while (aRs.moveToNext()) {
if (aRs.getDouble(aRs.getColumnIndex(SqliteDB.DBhelper.COLUMN_NAME_TotalApli)) > 0 || aRs.getDouble(aRs.getColumnIndex(SqliteDB.DBhelper.COLUMN_NAME_TotalApli)) == 0)
{
DFactor = aRs.getDouble(aRs.getColumnIndex(SqliteDB.DBhelper.COLUMN_NAME_TotalApli)) / aRs.getDouble(aRs.getColumnIndex(SqliteDB.DBhelper.COLUMN_NAME_Total));
Resultado = Integer.parseInt(O_WS.LLenarDetalleCXCP
("I", //Accion
0, //id
Id, //Origen
aRs.getInt(aRs.getColumnIndex(SqliteDB.DBhelper.COLUMN_NAME_Documento)), //OrigenDocumento
aRs.getDouble(aRs.getColumnIndex(SqliteDB.DBhelper.COLUMN_NAME_Importe)) * DFactor, //Importe
(Double) 0.0, //Financiamiento
aRs.getDouble(aRs.getColumnIndex(SqliteDB.DBhelper.COLUMN_NAME_Descuento)), //Descuento
aRs.getDouble(aRs.getColumnIndex(SqliteDB.DBhelper.COLUMN_NAME_SubTotal)) * DFactor, //Subtotal
aRs.getDouble(aRs.getColumnIndex(SqliteDB.DBhelper.COLUMN_NAME_Retencion1)) * DFactor, //Retencion1
aRs.getDouble(aRs.getColumnIndex(SqliteDB.DBhelper.COLUMN_NAME_Retencion2)) * DFactor, //Retencion2
aRs.getDouble(aRs.getColumnIndex(SqliteDB.DBhelper.COLUMN_NAME_IEPS)) * DFactor, //IEPS
aRs.getDouble(aRs.getColumnIndex(SqliteDB.DBhelper.COLUMN_NAME_IVA)) * DFactor, //IVA
(Double) 0.0, //ISH
aRs.getDouble(aRs.getColumnIndex(SqliteDB.DBhelper.COLUMN_NAME_Total)) * DFactor, //Total
aRs.getDouble(aRs.getColumnIndex(SqliteDB.DBhelper.COLUMN_NAME_SaldoD)),//Saldo
"Android App Desconectado" //Referencia
));
}
}
}
webService.STR_Resultado O_Resultado = null;
if (Resultado == 0) {
ArrayList<DetalleMenu> ArrayMenu = new ArrayList<DetalleMenu>();
Cursor arS = querySql("SELECT * FROM " + SqliteDB.DBhelper.TABLE_NAME_Menu , null);
if (arS.getCount() > 0) {
while (arS.moveToNext()) {
DetalleMenu newDetalle = new DetalleMenu(
(arS.getInt(arS.getColumnIndex(SqliteDB.DBhelper.COLUMN_NAME_IdMenu))),
(arS.getInt(arS.getColumnIndex(SqliteDB.DBhelper.COLUMN_NAME_EmpresaM))),
(arS.getString(arS.getColumnIndex(SqliteDB.DBhelper.COLUMN_NAME_DescripcionMenu))),
(arS.getString(arS.getColumnIndex(SqliteDB.DBhelper.COLUMN_NAME_Evento))),
(arS.getInt(arS.getColumnIndex(SqliteDB.DBhelper.COLUMN_NAME_Modulo))),
(arS.getInt(arS.getColumnIndex(SqliteDB.DBhelper.COLUMN_NAME_Operacion))),
(arS.getInt(arS.getColumnIndex(SqliteDB.DBhelper.COLIMN_NAME_Documento))));
ArrayMenu.add(newDetalle);
}
}
for (int i=0; i< ArrayMenu.size();i++)
{
Modulo = ((DetalleMenu)ArrayMenu.get(i)).getModulo();
Operacion = ((DetalleMenu)ArrayMenu.get(i)).getOperacion();
Documento = ((DetalleMenu)ArrayMenu.get(i)).getDocumento();
}
O_Resultado = O_WS.GrabarCxCP(Modulo, //Modulo
Operacion, //Operacion
Documento, //Documento
0, //OrigenId
0); //OrigenDocumento
}
//Se inicializan Variables
ImporteD = 0.0;
DescuentoD = 0.0;
SubTotalD = 0.0;
IVAD = 0.0;
TotalD = 0.0;
Importe = 0.0;
Descuento = 0.0;
SubTotal = 0.0;
IVA = 0.0;
Total = 0.0;
TotalAplicado = 0.0;
}