Hi, I'm using symfony 1.2, I generated modules admin-generator and want to
create an application to generate and control sales.

Sampling of the schema.yml

 propel:
  _attributes:
    package: lib.model
    defaultIdMethod: native
  articulos:
    _attributes: { phpName: Articulos }
    id_articulo: { type: INTEGER, size: '10', primaryKey: true,
autoIncrement: true, required: true }
    id_familia: { type: INTEGER, size: '10', required: true, foreignTable:
familias, foreignReference: id_familia, onDelete: CASCADE, onUpdate: CASCADE
}
    referencia: { type: VARCHAR, size: '25', required: true }
    nombre: { type: VARCHAR, size: '255', required: true }
    descripcion: { type: LONGVARCHAR, required: true }
    datos_producto: { type: VARCHAR, size: '255', required: true }
    bultos: { type: INTEGER, size: '10', required: true }
    imagen: { type: VARCHAR, size: '255', required: true }
    borrado: { type: TINYINT, size: '4', required: true }
    updated_at: { type: TIMESTAMP, required: true, defaultValue:
CURRENT_TIMESTAMP }
    created_at: { type: TIMESTAMP, required: true, defaultValue: '0000-00-00
00:00:00' }
    _indexes: { FK_articulos_1: [id_familia] }
[.....]
  estado_ventas:
    _attributes: { phpName: EstadoVentas }
    id_estado_venta: { type: INTEGER, size: '10', primaryKey: true,
autoIncrement: true, required: true }
    nombre: { type: VARCHAR, size: '45', required: true }
[.....]
linea_ventas:
    _attributes: { phpName: LineaVentas }
    id_venta: { type: INTEGER, size: '10', primaryKey: true, required: true,
foreignTable: ventas, foreignReference: id_venta, onDelete: CASCADE,
onUpdate: CASCADE }
    id_articulo: { type: INTEGER, size: '10', primaryKey: true, required:
true, foreignTable: articulos, foreignReference: id_articulo, onDelete:
CASCADE, onUpdate: CASCADE }
    cantidad: { type: INTEGER, size: '10', required: true }
    _indexes: { FK_linea_ventas_2: [id_articulo] }
ventas:
    _attributes: { phpName: Ventas }
    id_venta: { type: INTEGER, size: '10', primaryKey: true, autoIncrement:
true, required: true }
    id_cliente: { type: INTEGER, size: '10', required: true, foreignTable:
clientes, foreignReference: id_cliente, onDelete: CASCADE, onUpdate: CASCADE
}
    id_estado_venta: { type: INTEGER, size: '10', required: true,
foreignTable: estado_ventas, foreignReference: id_estado_venta, onDelete:
CASCADE, onUpdate: CASCADE }
    codigo: { type: VARCHAR, size: '15', required: true }
    updated_at: { type: TIMESTAMP, required: true, defaultValue:
CURRENT_TIMESTAMP }
    created_at: { type: TIMESTAMP, required: true, defaultValue: '0000-00-00
00:00:00' }
    _indexes: { FK_ventas_1: [id_cliente], FK_ventas_2: [id_estado_venta] }

I create sales, and add to that sale selling new lines, but in the edit
form, I can only delete lines sales can not edit or create new ones.

I show you the code.

/lib/form/VentasForm

  public function configure()
  {
      // Quitamos los widgets de las fechas y las lineas de ventas
      unset($this['updated_at']);
      unset($this['created_at']);
      unset($this['linea_ventas_list']);

      // Cargamos los helpers necesarios para ajax y jquery

sfContext::getInstance()->getConfiguration()->loadHelpers(array('jQuery','Asset','Tag','Url'));

      // Acciones cuando el formulario es NEW
      if(sfContext::getInstance()->getActionName() == 'new')
      {
        // Inicializamos el indice de las lineas de venta a cero
        $num_lineas = 0;

        // Establecemos N1added a 1
        sfContext::getInstance()->getUser()->setAttribute('N1added',1);

        // Obtenemos el numero de lineas añadidas para la venta, en el
formulario NEW es siempre 1
        $a =
sfContext::getInstance()->getUser()->getAttribute('N1added'.$this->getObject()->getIdVenta());

        // Limite de lineas, si es nuevo 1, sino el max($a y las
num_lineas+1)
        $more =
$this->getObject()->isNew()?max(1,$a-$num_lineas):($a>($num_lineas+1)?$a-$num_lineas:1);

        // Creamos una nuevo objeto LineaVentas
        $linea_ventas = new LineaVentas();
        // Establecemos el Id de la venta en el objeto LineaVentas
        $linea_ventas->setIdVenta($this->getObject()->getIdVenta());
        // Embebemos el formulario LineasVentas en el formulario Ventas
        $this->embedForm('linea_venta_'.++$num_lineas, new
LineaVentasForm($linea_ventas));
        // Establecemos el nombre a la etiqueta
        $this->widgetSchema->setLabel('linea_venta_'.$num_lineas,"Línea
$num_lineas");

        // Para la última línea añadimos un botón añadir nueva línea
        $label = "Línea
$num_lineas".jq_link_to_remote(image_tag('/sf/sf_admin/images/add'), array(
        'url'     =>
'ventas/addLineaVenta?id_venta='.$this->getObject()->getIdVenta().'&num_lineas='.$num_lineas,
        'update'  =>  'sf_fieldset_none',
        'position'=>  'bottom',
      ));
      $this->widgetSchema->setLabel('linea_venta_'.$num_lineas,$label);

      }
      // Acciones cuando el formulario es CREATE
      elseif(sfContext::getInstance()->getActionName() == 'create')
      {
        // Inicializamos el indice de las lineas a cero
        $num_lineas = 0;

        // Obtenemos el numero de lineas añadidas para la venta en la accion
del formulario NEW
        $a =
sfContext::getInstance()->getUser()->getAttribute('N1added'.$this->getObject()->getIdVenta());

        // Limite de lineas, si es nuevo 1, sino el max($a y las
num_lineas+1)
        $more =
$this->getObject()->isNew()?max(1,$a-$num_lineas):($a>($num_lineas+1)?$a-$num_lineas:1);

        // Para todas lineas
        for($i=0;$i<$more;$i++)
        {
            // Creamos un nuevo objeto LineaVentas
          $linea_ventas = new LineaVentas();
          // Establecemos el Id de la venta en el objeto LineaVentas
          $linea_ventas->setIdVenta($this->getObject()->getIdVenta());
          // Embebemos el formulario LineasVentas en el formulario Ventas
          $this->embedForm('linea_venta_'.++$num_lineas, new
LineaVentasForm($linea_ventas));
          // Establecemos el nombre a la etiqueta
          $this->widgetSchema->setLabel('linea_venta_'.$num_lineas,"Línea
$num_lineas");
        }

        // Para la última línea añadimos un botón añadir nueva línea
        $label = "Línea
$num_lineas".jq_link_to_remote(image_tag('/sf/sf_admin/images/add'), array(
        'url'     =>
'ventas/addLineaVenta?id_venta='.$this->getObject()->getIdVenta().'&num_lineas='.$num_lineas,
        'update'  =>  'sf_fieldset_none',
        'position'=>  'bottom',
      ));
      $this->widgetSchema->setLabel('linea_venta_'.$num_lineas,$label);

      // Establecemos la variable N1added para el id de venta al numero de
linea añadidas

sfContext::getInstance()->getUser()->setAttribute('N1added'.$this->getObject()->getIdVenta(),
$num_lineas);
      }
      // Acciones cuando el formulario es UPDATE
      elseif(sfContext::getInstance()->getActionName() == 'update')
      {
        // Inicializamos el indice de las lineas a cero
        $num_lineas = 0;

        // Obtenemos el array de todas las linea_ventas de la BD
        $ar_lin_ventas = $this->getObject()->getLineaVentass();

        // Obtenemos el numero de lineas añadidas para la venta que estan
guardadas segun el id de la venta
        $a =
sfContext::getInstance()->getUser()->getAttribute('N1added'.$this->getObject()->getIdVenta());

        // Limite de lineas, si es nuevo 1, sino el max($a y las
num_lineas+1)
        $more =
$this->getObject()->isNew()?max(1,$a-$num_lineas):($a>($num_lineas+1)?$a-$num_lineas:1);

        // Para todas las lineas
        for($i=0;$i<$more;$i++)
        {
            // Creamos un nuevo objeto LineaVentas
          $linea_ventas = new LineaVentas();
          // Establecemos el Id de la venta en el objeto LineaVentas
?????????????Meter la cantidad?????????????????????
          $linea_ventas->setIdVenta($this->getObject()->getIdVenta());
          // Embebemos el formulario LineasVentas en el formulario Ventas
          $this->embedForm('linea_venta_'.++$num_lineas, new
LineaVentasForm($linea_ventas));
          // Establecemos el nombre a la etiqueta
          $this->widgetSchema->setLabel('linea_venta_'.$num_lineas,"Línea
$num_lineas");
        }

        // Para la última línea añadimos un botón añadir nueva línea
??????? ELIMINARLO??????????
        $label = "Línea
$num_lineas".jq_link_to_remote(image_tag('/sf/sf_admin/images/add'), array(
        'url'     =>
'ventas/addLineaVenta?id_venta='.$this->getObject()->getIdVenta().'&num_lineas='.$num_lineas,
        'update'  =>  'sf_fieldset_none',
        'position'=>  'bottom',
      ));
      $this->widgetSchema->setLabel('linea_venta_'.$num_lineas,$label);

      // Establecemos la variable N1added para el id de venta al numero de
linea añadidas

sfContext::getInstance()->getUser()->setAttribute('N1added'.$this->getObject()->getIdVenta(),
$num_lineas);
    }
    // Acciones cuando el formulario es EDIT
      elseif(sfContext::getInstance()->getActionName() == 'edit')
      {
        // Inicializamos el indice de las lineas a cero
        $num_lineas = 0;

        // Obtenemos el array de todas las linea_ventas de la BD
        $ar_lin_ventas = $this->getObject()->getLineaVentass();

        // Obtenemos el numero de lineas añadidas para la venta que estan
guardadas segun el id de la venta
        $a =
sfContext::getInstance()->getUser()->getAttribute('N1added'.$this->getObject()->getIdVenta());

        // Limite de lineas, si es nuevo 1, sino el max($a y las
num_lineas+1)
        $more =
$this->getObject()->isNew()?max(1,$a-$num_lineas):($a>($num_lineas+1)?$a-$num_lineas:1);

        // Para cada linea de Venta guardada en la BD, creamos un boton para
eliminar una por una las lineas
        foreach($ar_lin_ventas as $linea)
        {
          // Obtenemos el id del articulo de la linea de Venta
          $id_articulo = $linea->getIdArticulo();

          // Embebemos en el formulario un nuevo formulario de LineaVentas,
con los datos de la linea
          $this->embedForm('linea_venta_'.++$num_lineas, new
LineaVentasForm($linea));

          // Establecemos una etiqueta para ese nuevo formulario, y le
agregamos el boton Borrar
          $label = "Línea
$num_lineas".link_to(image_tag('/sf/sf_admin/images/delete'),

'ventas/deleteLineaVenta?id_venta='.$this->getObject()->getIdVenta().'&id_articulo='.$id_articulo,

            array('confirm' => 'Estás seguro???'));
          $this->widgetSchema->setLabel('linea_venta_'.$num_lineas,$label);
        }

        // Obtenemos el numero de lineas añadidas para la venta que estan
guardadas segun el id de la venta
        $a =
sfContext::getInstance()->getUser()->getAttribute('N1added'.$this->getObject()->getIdVenta());

        // Limite de lineas, si es nuevo 1, sino el max($a y las
num_lineas+1)
        $more =
$this->getObject()->isNew()?max(1,$a-$num_lineas):($a>($num_lineas+1)?$a-$num_lineas:1);

        // Creamos una ultima nueva linea_venta hasta el limite de lineas
marcado,1, añadiendo un boton agregar
        for($i=0;$i<$more;$i++)
        {
            // Creamos un nuevo objeto LineaVentas
        $linea_ventas = new LineaVentas();
        // Establecemos el Id de la venta en el objeto LineaVentas
        $linea_ventas->setIdVenta($this->getObject()->getIdVenta());
        // Embebemos el formulario LineasVentas en el formulario Ventas
        $this->embedForm('linea_venta_'.++$num_lineas, new
LineaVentasForm($linea_ventas));
        // Establecemos el nombre a la etiqueta
        $this->widgetSchema->setLabel('linea_venta_'.$num_lineas,"Línea
$num_lineas");
      }

      // Para la última línea añadimos un botón añadir nueva línea
      $label = "Línea
$num_lineas".jq_link_to_remote(image_tag('/sf/sf_admin/images/add'), array(
        'url'     =>
'ventas/addLineaVenta?id_venta='.$this->getObject()->getIdVenta().'&num_lineas='.$num_lineas,
        'update'  =>  'sf_fieldset_none',
        'position'=>  'bottom',
      ));
      $this->widgetSchema->setLabel('linea_venta_'.$num_lineas,$label);

      // Establecemos la variable N1added para el id de venta al numero de
linea añadidas

sfContext::getInstance()->getUser()->setAttribute('N1added'.$this->getObject()->getIdVenta(),
$num_lineas);
      }
  }

  public function bind(array $taintedValues = null, array $taintedFiles =
null)
  {
      // Obtenemos el objeto Venta
      $venta_form = $this->getObject();

        // Para cada linea guardada en N1added segun el id de la venta

for($i=1;$i<=sfContext::getInstance()->getUser()->getAttribute('N1added'.$this->getObject()->getIdVenta());$i++)
      {
          // Si la linea_venta no tiene datos o el id de la venta está vacio
          if(!isset($taintedValues["linea_venta_$i"]) ||
empty($taintedValues["linea_venta_$i"]['id_venta']))
          {
            // Si estamos en el formulario NEW
            if($venta_form->isNew())
            {
                // Guardamos los formularios embebidos

$this->embeddedForms['linea_venta_'.$i]->getObject()->setVentas($this->getObject());
            }
            else
            {
                // Guardamos los formularios embebidos

$this->embeddedForms['linea_venta_'.$i]->getObject()->setVentas($this->getObject());
            }
        }
        else
        {
          // Guardamos los formularios embebidos

$this->embeddedForms['linea_venta_'.$i]->getObject()->setVentas($this->getObject());
          // Eliminamos los formularios embebidos

$this->embeddedForms['linea_venta_'.$i]->getObject()->setDeleted(true);
          // Quitamos la linea y el formulario

unset($this->embeddedForms["linea_venta_$i"],$this->validatorSchema["linea_venta_$i"]);
          unset($taintedValues['linea_venta_'.$i]);
        }
      }

    // Establecemos la variable N1added al valor correcto
    if(sfContext::getInstance()->getActionName() == 'create')
    {

sfContext::getInstance()->getUser()->setAttribute('N1added'.$this->getObject()->getIdVenta(),
sfContext::getInstance()->getUser()->getAttribute('N1added'));
    }
    elseif(sfContext::getInstance()->getActionName() == 'new')
    {
      sfContext::getInstance()->getUser()->setAttribute('N1added', 1);
    }

    return parent::bind($taintedValues,$taintedFiles);
  }


/modules/ventas/actions/actions.class.php

  public function executeDeleteLineaVenta(sfWebRequest $request)
  {

sfContext::getInstance()->getConfiguration()->loadHelpers(array('jQuery','Asset','Tag','Url'));
    $sub_category =
LineaVentasPeer::retrieveByPK($request->getParameter('id_venta'),$request->getParameter('id_articulo'));
    if (!$sub_category)
    {
      return $this->renderText('Error '.$request->getParameter('id_venta'));
    }
    $sub_category->delete();
    if (!$this->getRequest()->isXmlHttpRequest())
    {

$this->redirect('ventas/edit?id_venta='.$sub_category->getVentas()->getIdVenta());
    }

    return $this->renderText('');
  }

  public function executeAddLineaVenta(sfWebRequest $request)
  {

sfContext::getInstance()->getConfiguration()->loadHelpers(array('jQuery','Asset','Tag','Url'));
      // Obtenemos el id de la Venta
    $id_venta = $request->getParameter('id_venta');

    // Obtenemos el numero de lineas segun el id de la venta
    $num_lineas =
sfContext::getInstance()->getUser()->getAttribute('N1added'.$id_venta);

    // Cargamos los helpers de Ajax necesarios
    sfLoader::loadHelpers(array('jQuery','Asset','Tag','Url'));

    // Creamos un nuevo formulario Ventas
    $ventasForm = new VentasForm();
    // Escondemos el id de la venta
    $ventasForm->setWidgets(array('id_venta' => new
sfWidgetFormInputHidden()));
    $ventasForm->setValidators(array(
      'id_venta' => new sfValidatorPropelChoice(
      array('model' => 'Ventas', 'column' => 'id_venta', 'required' =>
false)))
    );

    // Obtenemos los widget del formulario Ventas ???
    $widgetSchema = $ventasForm->getWidgetSchema();
    $widgetSchema->setNameFormat('ventas[%s]');

    // Creamos una nueva linea venta
    for($i=0;$i<1;$i++){
      $linea_ventas = new LineaVentas();
      if($id_venta) $linea_ventas->setIdVenta($id_venta);
      $ventasForm->embedForm('linea_venta_'.++$num_lineas, new
LineaVentasForm($linea_ventas));
      $widgetSchema->setLabel('linea_venta_'.$num_lineas,"Línea
$num_lineas");
    }

    // Agregamos un boton agregar a la ultima linea
    $label = "Línea
$num_lineas".jq_link_to_remote(image_tag('/sf/sf_admin/images/add'), array(
      'url'     =>
'ventas/addLineaVenta?id_venta='.$id_venta.'&num_lineas='.$num_lineas,
      'update'  =>  'sf_fieldset_none',
      'position'=>  'bottom',
    ));
    $widgetSchema->setLabel('linea_venta_'.$num_lineas,$label);

    // Establecemos el numero de linea ventas para ese id de venta
    sfContext::getInstance()->getUser()->setAttribute('N1added'.$id_venta,
$num_lineas);

    // Asignamos el nuevo ventasForm al formulario
    $this->form = $ventasForm;

    return $this->renderPartial('ventas/lineas');
  }

/modules/ventas/templates/_lineas.php

<?php foreach($configuration->getFormFields($form, 'new') as $fields): ?>
 <?php foreach ($fields as $name => $field): ?>
 <?php if ((isset($form[$name]) && $form[$name]->isHidden()) ||
(!isset($form[$name]) && $field->isReal())) continue ?>
 <?php include_partial('ventas/form_field', array(
  'name'       => $name,
  'attributes' => $field->getConfig('attributes', array()),
  'label'      => $field->getConfig('label'),
  'help'       => $field->getConfig('help'),
  'form'       => $form,
  'field'      => $field,
  'class'      => 'sf_admin_form_row
sf_admin_'.strtolower($field->getType()).' sf_admin_form_field_'.$name,
 )) ?>
 <?php endforeach; ?>
<?php endforeach; ?>

How can I do? where is the problem? As do I add and edit lines in the form
to edit?

Sorry for my English and thank you very much for everything and I hope as
you could help me.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"symfony users" group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to 
symfony-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/symfony-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to