dongyun7897 2016-09-12 16:25
浏览 45

它没有关闭对话框但保存正常

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

enter image description here

enter image description here

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

  • 写回答

1条回答 默认 最新

  • doupo5178 2016-09-14 13:49
    关注

    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

    评论

报告相同问题?

悬赏问题

  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)