//**********************************************************
//Cancelando total o parcial en tanto y cuanto
//exista remanente del importe pagado
//*********************************************************
Dec{2} Deuda
Long Filas_Deudas
Long n
n = 0
Filas_Deudas = dw_detalle.RowCount()
Importe_Pago = Dec(em_pago.text)
ls_selected_data_caja.importe_ingreso = Importe_Pago
ls_pendientes_pago.importe_pagado = Importe_Pago
Deuda = dw_detalle.Object.total_pendiente[Filas_Deudas]
If Importe_Pago > Deuda Then
MessageBox("Cobranzas" ,""+ "Se Ingreso Un Importe Mayor que el Total de la Deuda" &
+ " ~n~r" &
+ " ~n~r" &
+ "Deuda : $ " + String (Deuda) &
+ " ~n~r" &
+"Importe Ingresado : $ " + String ( Importe_Pago) ,Information!)
Return 1
End If
For n=1 To Filas_Deudas
Glob_Factura_Deuda = dw_detalle.Object.mask_comprobante[n]
Importe_Factura = dw_detalle.Object.importe_pendiente[n]
Importe_Pagado = dw_detalle.Object.importe_pagado[n]
Choose Case Importe_Pago
Case Is< Importe_Factura
Importe_Remanente = Importe_Factura - Importe_pago
Recibo_Aplicado = dw_detalle.Object.recibo_relacionado[n]
dw_detalle.Object.importe_pagado[n] = Importe_Pago
dw_detalle.Object.importe_pendiente[n] = Importe_Factura - Importe_Pago
dw_detalle.Object.estado[n] = "Parcial"
ls_data_cta_corriente.status = "Parcial"
Glob_Importe_Deuda = Importe_Factura
Glob_Importe_Pagado = Importe_Pagado
Glob_Importe_Remanente = Importe_Remanente
// MessageBox("No Hay Remanente NO SE Continua Aplicando Pagos" ,"" + String(Importe_Remanente))
Continua_Aplicando = False
Case Is> Importe_Factura
Importe_Remanente = Importe_Pago - Importe_Factura
dw_detalle.Object.importe_pendiente[n] = 0.00
dw_detalle.Object.importe_pagado[n] = Importe_Factura
dw_detalle.Object.estado[n] = "Cancelado"
ls_data_cta_corriente.status = "Cancelado"
Glob_Importe_Deuda = Importe_Factura
Glob_Importe_Pagado = Importe_Pagado
Glob_Importe_Remanente = Importe_Remanente
// MessageBox("Hay Remanente Continua Aplicando Pagos" ,"" + String(Importe_Remanente))
Continua_Aplicando = True
Case Else
// MessageBox("Ok Importe Exacto No hay mas Pagos " ,"")
dw_detalle.Object.importe_pagado[n] = Importe_Pago + Importe_Pagado
dw_detalle.Object.importe_pendiente[n] = 0.00
dw_detalle.Object.estado[n] = "Cancelado"
ls_data_cta_corriente.status = "Cancelado"
Glob_Importe_Deuda = Importe_Factura
Glob_Importe_Pagado = Importe_Pagado
Glob_Importe_Remanente = Importe_Remanente
Continua_Aplicando = False
End Choose
If Continua_Aplicando = False Then
pb_caja.Enabled =True
pb_pencil.Enabled =False
Return 1 // Fundamental Break
Else
Importe_Pago = Importe_Remanente
End If
Next
pb_caja.Enabled=True
pb_pencil.Enabled=False