I am trying to add a custom button that pass some info to a form that once submitted generate an invoice in a form of pdf.
I have added the following into …app/Template/project_header/views.php
<li>
<?= $this->url->icon('file-pdf-o', t('Invoice'), 'InvoiceController', 'create', array('project_id' => $project['id'], 'search' => $filters['search']), false, 'view-listing', t('Keyboard shortcut: "%s"', 'v i')) ?>
</li>
Then once I click that button I would need to generate a form through the custom controller with the method create()
public function create()
{
$status = array(TaskModel::STATUS_OPEN);
$project = $this->getProject();
$task_ids = $this->db
->table(TaskModel::TABLE)
->eq(TaskModel::TABLE.'.project_id', $project['id'])
->in(TaskModel::TABLE.'.is_active', $status)
->asc(TaskModel::TABLE.'.id')
->findAllByColumn(TaskModel::TABLE.'.id');
$this->response->html($this->template->render('invoice/create', array(
'project' => $project,
'values' => array(
'invRef' => $project['name'],
'invFrom' => implode(',', array('My Company','Address line 1','Address line 2','City and zip','Country','VAT number')),
'invTo' => implode(',', array('My Client','Address line 1','Address line 2','City and zip','Country','VAT number')),
'invDate' => '',
'invDue' => '',
'invAdd' => implode(',',$task_ids),
)
)));
}
That should populate the below form:
<div class="page-header">
<h2><?= 'Invoice for Project: '. $project['name'] ?></h2>
</div>
<form action="<?= $this->url->href('InvoiceController', 'create', array('project_id' => $project['id'])) ?>" method="post" autocomplete="off">
<?= $this->form->csrf() ?>
<?= $this->form->label(t('Reference'), 'invRef') ?>
<?= $this->form->text('invRef', $values, array('required')) ?>
<br><br>
<?= $this->form->label(t('From'), 'invFrom') ?>
<?= $this->form->text('invFrom', $values, array('required')) ?>
<br><br>
<?= $this->form->label(t('To'), 'invTo') ?>
<?= $this->form->text('invTo', $values, array('required')) ?>
<br><br>
<?= $this->form->label(t('Date'), 'invDate') ?>
<?= $this->form->text('invDate', $values, array('required')) ?>
<br><br>
<?= $this->form->label(t('Due'), 'invDue') ?>
<?= $this->form->text('invDue', $values, array('required')) ?>
<br><br>
<?= $this->form->label(t('Add'), 'invAdd') ?>
<?= $this->form->text('invAdd', $values, array('required')) ?>
<?= $this->modal->submitButtons() ?>
</form>
However, the form does not appear as a modal but a brand new webpage, which is not what I would like to have. The point is to have a form with pre-filled info that I can fill to generate an invoice, based on the project and related tasks.
I am quite n000b with PHP and I would love your help here.
Best,
Teo