问题描述:

I have the follow code

<?php

if (!empty($errors)) { ?>

<div class="errors">

<h5>Hay <?php echo count($errors); ?> Errores:</h5>

<ul>

<?php foreach ($errors as $field => $error) { ?>

<li style="color:red;"><?php echo $error[0]; ?></li>

<?php } ?>

</ul>

</div>

<?php }

echo $this->Form->create('Pagos');

$i = 0; ?>

<div class="data">

<!-- venc.ref, venc.proveedor, venc.moneda,

venc.vencimiento, venc.pago, venc.monto, venc.concepto, venc.id -->

<table class="table">

<thead>

<tr>

<th>Referencia</th>

<th>Proveedor</th>

<th>Moneda</th>

<th>vencimiento</th>

<th>Status</th>

<th>Monto</th>

<th>Concepto</th>

<th>Seleccione</th>

</tr>

</thead>

<tbody>

<?php foreach ($datos as $d) : ?>

<tr>

<td><?php echo $d['venc']['ref']; ?></td>

<td><?php echo $d['venc']['proveedor']; ?></td>

<td><?php echo $d['venc']['moneda']; ?></td>

<td><?php echo implode('/', array_reverse(explode('-', $d['venc']['vencimiento']))); ?></td>

<td><?php echo $d['venc']['pago']; ?></td>

<td><?php echo number_format($d['venc']['monto'],2,',','.'); ?></td>

<td><?php echo $d['venc']['concepto']; ?></td>

<td><?php

echo $this->Form->input('Pagos][.id',

array('label' => false, 'type' => 'hidden',

'value' => $d['venc']['id']));

echo $this->Form->input('Pagos][.monto',

array('label' => false, 'type' => 'hidden',

'value' => $d['venc']['monto']));

echo $this->Form->input('Pagos][.moneda_id',

array('label' => false, 'type' => 'hidden',

'value' => (strlen($d['venc']['moneda'])>1)?2:1 ));

echo $this->Form->input('Pagos][.selec', array('type' => 'checkbox',

'label' => false));

?></td>

</tr>

<?php endforeach; ?>

</tbody>

</table>

</div>

<div class="row-form">

<div class="span2 offset3">

<?php echo $this->Js->submit('Pagar',

array('class' => 'btn btn-info',

'update' => '#contentWrap', 'id' => 'pagar')); ?>

</div>

</div>

<?php

if (false != $saved)

echo "<script> $('#dialogModal4').dialog('close'); </script>";

echo $this->Form->end();

echo $this->Js->writeBuffer();

//assuming this view is rendered without the default layout, make sure you write out the JS buffer at the bottom of the page

?>

and this is my controller function

function addpag() {

$consulta = 'SELECT venc.ref, venc.proveedor, venc.moneda,

venc.vencimiento, venc.pago, venc.monto, venc.concepto, venc.id

FROM v_vencimientos venc

Where (venc.vencimiento between "2015-12-12" and curdate()

and venc.pago <> "Vencida") or (venc.pago = "Vencida") ';

$datos = $this->ComprobantesCompra->query($consulta);

if (!isset($saved)) {

$this->set('saved', false);

} else {

$this->set('saved', $saved);

}

$this->set('datos', $datos);

$this->layout = 'ajax';

App::import('Model', 'Pago');

App::import('Model', 'PagosDetalle');

App::import('Model', 'FormasPago');

App::import('Model', 'ComprobantesComprasAsociado');

if (!empty($this->request->data)) {

$this->set('saved', true);

$Pagos['Pago'] = $this->request->data['Pagos'];

$i = 0;

$aux = array();

while ($i < sizeof($Pagos['Pago']) )

{

if (isset($Pagos['Pago'][$i+4]['selec'])) {

$valor = true;

} else {

$valor = false;

}

$aux[] =array( 'id' => $Pagos['Pago'][$i]['id'],

'monto' => $Pagos['Pago'][$i+1]['monto'],

'moneda_id' => $Pagos['Pago'][$i+2]['moneda_id']

'selec' => $valor,

'fecha' => date('Y-m-d'),

'pago_cuenta' => 0

);

if ($valor) {

$i += 5;

} else {

$i+=4;

}

}

$consecutivo = 0;

foreach ($aux as $detalle) {

//si se selecciono para ser pagado ingrese y realice el pago

if ($detalle['selec']) {

$consecutivo++;

$pag = new Pago();

$pag->create();

$pag->set('numero', date('Ymd') . $consecutivo);

$pag->set('proveedor_id', $this->ComprobantesCompra->getProveedorCompra($detalle['id']));

$pag->set('moneda_id', $detalle['moneda_id']);

$pag->set('pago_cuenta', $detalle['pago_cuenta']);

$pag->set('fecha', $detalle['fecha']);

$pag->set('monto', trim($detalle['monto']));

if (!$pag->save()) {

debug($pag->validationErrors);

} else {

$this->set('saved', true);

}

$id_pago = $pag->getInsertID();

$fpp = new FormasPago();

$fpp->create();

$fpp->set('tipo_pago', 'Efectivo');

$fpp->set('tipo_comprobante', 'P');

$fpp->set('moneda_id', $detalle['moneda_id']);

$fpp->set('cant_pagos', 1);

$fpp->set('importe', trim($detalle['monto']));

$fpp->set('comprobante_id', $id_pago);

if (!$fpp->save()) {

debug($fpp->validationErrors);

}

$pagdet = new PagosDetalle();

$pagdet->create();

$pagdet->set('pagos_id', $id_pago);

$pagdet->set('comprobantes_compra_id', $detalle['id']);

$pagdet->set('monto', trim($detalle['monto']));

if (!$pagdet->save()) {

debug($pagdet->validationErrors);

}

$cca = new ComprobantesComprasAsociado();

$pgd = new PagosDetalle();

//1ERO OBTENEMOS EL COMPROBANTE

$comprobante = $this->ComprobantesCompra->read(null, $detalle['id']);

$comprobante->id = $detalle['id'];

//2DO SUMAMOS RECIBOS

$sumarc = $pgd->find('all', array('conditions' =>

array('PagosDetalle.comprobantes_compra_id' => $detalle['id']),

'fields' => array('sum(PagosDetalle.monto) AS suma')));

$recibos = $sumarc[0][0]['suma'];

//3ERO SUMAMOS NOTAS DE CREDITO ASOCIADAS AL COMPROBANTE

$ncreditos = $cca->sumarNC($detalle['id']);

//4TO ACTUALIZAMOS

$saldo = $comprobante['ComprobantesCompra']['monto_total'] - $recibos - $ncreditos;

if ($saldo <= 0) {

$estado = 'Paga';

} else {

if ($comprobante['ComprobantesCompra']['monto_total'] == $saldo) {

$estado = 'Pendiente';

} else {

$estado = 'Parcialmente';

}

}

$comprobante->set('estado', $estado);

$comprobante->set('saldo', $saldo);

if (!$comprobante->save()) {

$this->set('errors', $comprobante->validationErrors);

}

}

}

$this->set('saved', true);

}

}

Here is the thing, i open with ajax a dialog and load that form inside, it saves all correct. But the fact is that doens't close the dialog

I really have no idea why this is happening, any idea/suggestion will be highly appreciated. I just need to close the dialog. The save part is done. Thanks in advance

网友答案:

I already fix this, the thing is that in the ctp the 'update' was bad selected, i choose the wrong id, my fault. This codes works of, hope this help somebody

相关阅读:
Top