/** * Creates a new receipt and belonging receipt-items * * @param $snapshot a snapshot object * @param $snapshot_line_ids an array with the IDs of the snapshot lines to be used for creation * @param $parameters an assoc. array of creation parameters TODO: to be defined * * @return TRUE if successfull, FALSE otherwise. In that case, the $parameters['error'] contains an error message */ public static function createFromSnapshot($snapshot, $snapshot_line_ids, &$parameters) { // get all tokens form SnapshotReceipt $snapshot_receipt = $snapshot->getSnapshotReceipt($snapshot_line_ids, FALSE); $tokens = $snapshot_receipt->getAllTokens(); // error if no tokens found if (empty($tokens)) { $parameters['is_error'] = "snapshot-line-ids does not exist."; return FALSE; } // update tokens from parameters $tokens = array_merge($tokens, $parameters); // create receipt $result = self::_createReceiptFromTokens($tokens); // create receipt-items $lastId = CRM_Core_DAO::singleValueQuery('SELECT LAST_INSERT_ID()'); foreach ($tokens['lines'] as $lid => $line_tokens) { $params = array_merge($tokens, $line_tokens); $params['issued_in'] = $lastId; $params['receipt_id'] = $snapshot->getReceiptID(); CRM_Donrec_Logic_ReceiptItem::create($params); } return new self($lastId); }