Closed abbasgholia closed 7 years ago
you want to duplicate a entry ?
The picture attach
have the ability to copy entries. copies of the entries can be saved.
please help me!!
You will have to customize it by looking at the code. Its not that hard.
i could not if it is possible, please some help me
is it possible for there tips?
I can do it but I will take some charge for it since it is specifically for you.
but in my country can not afford. how much does it cost? the answer you very much
What exactly you want the copy to do ? open the create entry with the fields auto filed as the one copied from or create a duplicate entry
create a duplicate entry registered. there may be many similar entries and some entries have hundreds of rows. copy entries passed to the accountant can help in registration of new entries. In all there are financial accounting software. im a supporter of the country's largest accounting software and many ideas can be added in the application. im programming with amateur cakephp and now I am reading this Framework. im trying to build it if God wants to do regard abbasgholia
excuse me, I ask too much what is wrong with this code? function copy($entrytypeLabel = null , $id = null){ $entryitem = $this->Entryitem->findByentry_id($id); $entry = $this->Entry->findById($id); unset($entry['Entry']['id'],$entryitem['Entryitem']['entry_id']); $this->Entry->create(); $this->Entry->saveAll($entry);
return $this->redirect(array('plugin' => 'webzash', 'controller' => 'entries', 'action' => 'index'));
}
Use the edit entry code, just dont set the entry number.
Or you could just copy the database rows for entries, entryitems. This will be really simple to implement.
convenient for you. I do not know framework cakephp :) In this framework amateur am. If the php maybe it was just now thank you answer Indians i love ;)
I will send you the code by this weekend.
thank you so much
Method to clone entry
https://gist.github.com/prashants/5f2cce6979dcec4684bb4f363a11926c
it came to my mind. thank you for taking me.
The above code with automatic entry numbers:
`public function eclone($entrytypeLabel = null, $id = null) {
/* Check for valid entry type */
if (!$entrytypeLabel) {
$this->Session->setFlash(__d('webzash', 'Entry type not specified.'), 'danger');
return $this->redirect(array('plugin' => 'webzash', 'controller' => 'entries', 'action' => 'index'));
}
$entrytype = $this->Entrytype->find('first', array('conditions' => array('Entrytype.label' => $entrytypeLabel)));
if (!$entrytype) {
$this->Session->setFlash(__d('webzash', 'Entry type not found.'), 'danger');
return $this->redirect(array('plugin' => 'webzash', 'controller' => 'entries', 'action' => 'index'));
}
$this->set('entrytype', $entrytype);
$this->set('title_for_layout', __d('webzash', 'View %s Entry', $entrytype['Entrytype']['name']));
/* Check for valid entry id */
if (empty($id)) {
$this->Session->setFlash(__d('webzash', 'Entry not specified.'), 'danger');
return $this->redirect(array('plugin' => 'webzash', 'controller' => 'entries', 'action' => 'index'));
}
$entry = $this->Entry->findById($id);
if (!$entry) {
$this->Session->setFlash(__d('webzash', 'Entry not found.'), 'danger');
return $this->redirect(array('plugin' => 'webzash', 'controller' => 'entries', 'action' => 'index'));
}
/* Fetch entry items */
$entryitems = $this->Entryitem->find('all', array(
'conditions' => array('Entryitem.entry_id' => $id),
));
if ($entrytype['Entrytype']['numbering'] == 1) {
/* Auto */
if (empty($this->request->data['Entry']['number'])) {
$clone_entry['Entry']['number'] = $this->Entry->nextNumber($entrytype['Entrytype']['id']);
} else {
$clone_entry['Entry']['number'] = $this->request->data['Entry']['number'];
}
} else if ($entrytype['Entrytype']['numbering'] == 2) {
/* Manual + Required */
if (empty($this->request->data['Entry']['number'])) {
$this->Session->setFlash(__d('webzash', 'Entry number cannot be empty.'), 'danger');
return;
} else {
$clone_entry['Entry']['number'] = $this->request->data['Entry']['number'];
}
} else {
/* Manual + Optional */
$clone_entry['Entry']['number'] = $this->request->data['Entry']['number'];
}
/* Create clone entry */
$clone_entry['Entry']['tag_id'] = $entry['Entry']['tag_id'];
$clone_entry['Entry']['entrytype_id'] = $entry['Entry']['entrytype_id'];
//$clone_entry['Entry']['number'] = 10000;
$clone_entry['Entry']['date'] = $entry['Entry']['date'];
$clone_entry['Entry']['dr_total'] = $entry['Entry']['dr_total'];
$clone_entry['Entry']['cr_total'] = $entry['Entry']['cr_total'];
$clone_entry['Entry']['narration'] = $entry['Entry']['narration'];
/* Save entry */
$ds = $this->Entry->getDataSource();
$ds->begin();
$this->Entry->create();
if ($this->Entry->save($clone_entry)) {
/* Save entry items */
foreach ($entryitems as $row => $data) {
$entryitem['Entryitem'] = array(
'entry_id' => $this->Entry->id,
'ledger_id' => $data['Entryitem']['ledger_id'],
'amount' => $data['Entryitem']['amount'],
'dc' => $data['Entryitem']['dc'],
);
$this->Entryitem->create();
if (!$this->Entryitem->save($entryitem)) {
foreach ($this->Entryitem->validationErrors as $field => $msg) {
$errmsg = $msg[0];
break;
}
$ds->rollback();
$this->Session->setFlash(__d('webzash', 'Failed to save entry ledgers. Error is : %s', $errmsg), 'danger');
return;
}
}
} else {
$ds->rollback();
$this->Session->setFlash(__d('webzash', 'Failed to clone entry. Please, try again.'), 'danger');
return;
}
$ds->commit();
$this->Session->setFlash(__d('webzash', 'یک سند از نوع %s کپی شد.لطفا شماره سند را اپدیت کرده و ذخیره نمایید', $entrytype['Entrytype']['name']), 'success');
return $this->redirect(array('plugin' => 'webzash', 'controller' => 'entries', 'action' => 'edit', $entrytypeLabel, $this->Entry->id));
}`
regard abbasgholia
hi please help me? regard Abbasgholia