PF
Erro ao gravar parcelamentos
Quando tento rodar a rotina abaixo apenas o primeiro e ultimo registro de um parcelamento (Exemplo 5 parcelas) gravam no banco.
public function onSave($param)
{
try
{
TTransaction::open('sysgestocon'); // open a transaction
/**
// Enable Debug logger for SQL operations inside the transaction
TTransaction::setLogger(new TLoggerSTD); // standard output
TTransaction::setLogger(new TLoggerTXT('log.txt')); // file
**/
$this->form->validate(); // validate form data
$data = $this->form->getData(); // get form data as array
$movimento = new movimentos_os; // create an empty object
$movimento->fromArray( (array) $data);
$novovalor = $param['valor']/$param['parcelas'];
$novadata = new DateTime(TDate::date2us($movimento->vencimento));
$interval = new DateInterval('P1M');
for ($i = 1; $i <= $param['parcelas']; $i++)
{
$movimento->fromArray( (array) $data);
$movimento->vencimento = $novadata->format('Y-m-d');
$movimento->valor = $novovalor;
$movimento->descricao = $movimento->descricao. ' - Parcela '.$i.'/'.$param['parcelas'];
$movimento->store();
$novadata->add($interval);
}
// close the transaction
TTransaction::close();
$act_ok = new TAction(array('OrdensServicosList', 'onReload'));
new TMessage('info', TAdiantiCoreTranslator::translate('Record saved'), $act_ok);
}
catch (Exception $e) // in case of exception
{
new TMessage('error', $e->getMessage()); // shows the exception error message
$this->form->setData( $this->form->getData() ); // keep form data
TTransaction::rollback(); // undo all pending operations
}
}
public function onSave($param)
{
try
{
TTransaction::open('sysgestocon'); // open a transaction
/**
// Enable Debug logger for SQL operations inside the transaction
TTransaction::setLogger(new TLoggerSTD); // standard output
TTransaction::setLogger(new TLoggerTXT('log.txt')); // file
**/
$this->form->validate(); // validate form data
$data = $this->form->getData(); // get form data as array
$movimento = new movimentos_os; // create an empty object
$movimento->fromArray( (array) $data);
$novovalor = $param['valor']/$param['parcelas'];
$novadata = new DateTime(TDate::date2us($movimento->vencimento));
$interval = new DateInterval('P1M');
for ($i = 1; $i <= $param['parcelas']; $i++)
{
$movimento->fromArray( (array) $data);
$movimento->vencimento = $novadata->format('Y-m-d');
$movimento->valor = $novovalor;
$movimento->descricao = $movimento->descricao. ' - Parcela '.$i.'/'.$param['parcelas'];
$movimento->store();
$novadata->add($interval);
}
// close the transaction
TTransaction::close();
$act_ok = new TAction(array('OrdensServicosList', 'onReload'));
new TMessage('info', TAdiantiCoreTranslator::translate('Record saved'), $act_ok);
}
catch (Exception $e) // in case of exception
{
new TMessage('error', $e->getMessage()); // shows the exception error message
$this->form->setData( $this->form->getData() ); // keep form data
TTransaction::rollback(); // undo all pending operations
}
}
Pessoal, depois de tentar de várias formas, consegui assim:
public function onSave($param)
{
try
{
TTransaction::open('sysgestocon'); // open a transaction
/**
// Enable Debug logger for SQL operations inside the transaction
TTransaction::setLogger(new TLoggerSTD); // standard output
TTransaction::setLogger(new TLoggerTXT('log.txt')); // file
**/
$this->form->validate(); // validate form data
$data = $this->form->getData(); // get form data as array
$movimento = new movimentos_os; // create an empty object
$movimento->fromArray( (array) $data);
$novovalor = $param['valor']/$param['parcelas'];
$novadata = new DateTime(TDate::date2us($movimento->vencimento));
$interval = new DateInterval('P1M');
$movimentos = array();
for ($i = 1; $i <= $param['parcelas']; $i++)
{
$movimento->fromArray( (array) $data);
$movimento->vencimento = $novadata->format('Y-m-d');
$movimento->valor = $novovalor;
$movimento->descricao = $movimento->descricao. ' - Parcela '.$i.'/'.$param['parcelas'];
$movimentos[$i] = $movimento->toArray();
$novadata->add($interval);
}
for ($i = 1; $i <= $param['parcelas']; $i++ )
{
$movimento = new movimentos_os;
$movimento->fromArray($movimentos[$i]);
$movimento->store();
}
TTransaction::close();
$act_ok = new TAction(array('OrdensServicosList', 'onReload'));
new TMessage('info', TAdiantiCoreTranslator::translate('Record saved'), $act_ok);
}
catch (Exception $e) // in case of exception
{
new TMessage('error', $e->getMessage()); // shows the exception error message
$this->form->setData( $this->form->getData() ); // keep form data
TTransaction::rollback(); // undo all pending operations
}
}
Pessoal, depois de tentar de várias formas, consegui assim:
public function onSave($param)
{
try
{
TTransaction::open('sysgestocon'); // open a transaction
/**
// Enable Debug logger for SQL operations inside the transaction
TTransaction::setLogger(new TLoggerSTD); // standard output
TTransaction::setLogger(new TLoggerTXT('log.txt')); // file
**/
$this->form->validate(); // validate form data
$data = $this->form->getData(); // get form data as array
$movimento = new movimentos_os; // create an empty object
$movimento->fromArray( (array) $data);
$novovalor = $param['valor']/$param['parcelas'];
$novadata = new DateTime(TDate::date2us($movimento->vencimento));
$interval = new DateInterval('P1M');
$movimentos = array();
for ($i = 1; $i <= $param['parcelas']; $i++)
{
$movimento->fromArray( (array) $data);
$movimento->vencimento = $novadata->format('Y-m-d');
$movimento->valor = $novovalor;
$movimento->descricao = $movimento->descricao. ' - Parcela '.$i.'/'.$param['parcelas'];
$movimentos[$i] = $movimento->toArray();
$novadata->add($interval);
}
for ($i = 1; $i <= $param['parcelas']; $i++ )
{
$movimento = new movimentos_os;
$movimento->fromArray($movimentos[$i]);
$movimento->store();
}
TTransaction::close();
$act_ok = new TAction(array('OrdensServicosList', 'onReload'));
new TMessage('info', TAdiantiCoreTranslator::translate('Record saved'), $act_ok);
}
catch (Exception $e) // in case of exception
{
new TMessage('error', $e->getMessage()); // shows the exception error message
$this->form->setData( $this->form->getData() ); // keep form data
TTransaction::rollback(); // undo all pending operations
}
}
Pessoal, depois de tentar de várias formas, consegui assim:
public function onSave($param)
{
try
{
TTransaction::open('sysgestocon'); // open a transaction
/**
// Enable Debug logger for SQL operations inside the transaction
TTransaction::setLogger(new TLoggerSTD); // standard output
TTransaction::setLogger(new TLoggerTXT('log.txt')); // file
**/
$this->form->validate(); // validate form data
$data = $this->form->getData(); // get form data as array
$movimento = new movimentos_os; // create an empty object
$movimento->fromArray( (array) $data);
$novovalor = $param['valor']/$param['parcelas'];
$novadata = new DateTime(TDate::date2us($movimento->vencimento));
$interval = new DateInterval('P1M');
$movimentos = array();
for ($i = 1; $i <= $param['parcelas']; $i++)
{
$movimento->fromArray( (array) $data);
$movimento->vencimento = $novadata->format('Y-m-d');
$movimento->valor = $novovalor;
$movimento->descricao = $movimento->descricao. ' - Parcela '.$i.'/'.$param['parcelas'];
$movimentos[$i] = $movimento->toArray();
$novadata->add($interval);
}
for ($i = 1; $i <= $param['parcelas']; $i++ )
{
$movimento = new movimentos_os;
$movimento->fromArray($movimentos[$i]);
$movimento->store();
}
TTransaction::close();
$act_ok = new TAction(array('OrdensServicosList', 'onReload'));
new TMessage('info', TAdiantiCoreTranslator::translate('Record saved'), $act_ok);
}
catch (Exception $e) // in case of exception
{
new TMessage('error', $e->getMessage()); // shows the exception error message
$this->form->setData( $this->form->getData() ); // keep form data
TTransaction::rollback(); // undo all pending operations
}
}