/** * Save a current invoice item as a template item * * @param $id invoice id */ public function actionSaveItemAsTemplate($id) { $model = $this->loadModel($id); // only proceed if params are present if ($model && isset($_POST['item_description']) && isset($_POST['item_unit_price'])) { $invoiceItemTemplate = new LbInvoiceItemTemplate(); $invoiceItemTemplate->lb_item_unit_price = $_POST['item_unit_price']; // split the posted description into title and description $split_description = explode("\n", $_POST['item_description']); if (count($split_description) > 1) { $invoiceItemTemplate->lb_item_title = $split_description[0]; for ($i = 1; $i < count($split_description); $i++) { $invoiceItemTemplate->lb_item_description .= $split_description[$i]; if ($i + 1 < count($split_description)) { $invoiceItemTemplate->lb_item_description .= "\n"; } } } else { $invoiceItemTemplate->lb_item_title = ""; $invoiceItemTemplate->lb_item_description = $_POST['item_description']; } if ($invoiceItemTemplate->save()) { LBApplication::renderPlain($this, array('content' => SUCCESS)); } else { LBApplication::renderPlain($this, array('content' => FAILURE)); } } }
/** * check if item exists * logic: exact match of title and description * * @return bool */ protected function itemExists() { $items = LbInvoiceItemTemplate::model()->findAll('lb_item_title = :title AND lb_item_description = :description', array(':title' => $this->lb_item_title, ':description' => $this->lb_item_description)); if (count($items)) { return true; } return false; }