function addCustomLines($custom_lines){ if(!is_array($custom_lines) || count($custom_lines) <= 0){ return TRUE; } $lines = array(); foreach($custom_lines as $new_line){ if(!isset($new_line['item_code_id']) || $new_line['item_code_id'] <= 0 || !isset($new_line['quantity']) || !isset($new_line['description']) || !isset($new_line['price'])) continue; if($new_line['quantity'] <= 0) continue; $il = new SI_InvoiceLine(); $il->invoice_id = $this->id; $il->item_code_id = $new_line['item_code_id']; $il->quantity = $new_line['quantity']; $il->unit_price = floatval($new_line['price']); $il->description = $new_line['description']; $il->addTax(); $lines[] = $il; } if(!$this->_lines) $this->_lines = array(); foreach($lines as $line){ if($line->add() === FALSE){ $this->error = "SI_Invoice::addCustomLines(): Error adding line item: ".$line->getLastError(); return FALSE; } $this->_lines[] = $line; } return TRUE; }
$ill = new SI_InvoiceLineLink(); $ill->task_activity_id = $_REQUEST['ta_id']; $ill->invoice_line_id = $line->id; if($line->unit_price > 0 && $ill->getUnitPrice() != $line->unit_price){ fatal_error("You can not add this task activity to this line because it has a different unit price!"); }else{ if($line->unit_price <= 0) $line->unit_price = $ill->getUnitPrice(); if($line->description == '') $line->description = $ill->getDescription(); } if($ill->add() === FALSE){ $error_msg .= "Could not add task activity to invoice!"; debug_message($ill->getLastError()); }else{ $line->quantity += $ill->getQuantity(); $line->addTax(); if($line->update() === FALSE){ $error_msg .= "Could not update quantity on line item!"; debug_message($line->getLastError()); }else{ $ct = new SI_CompanyTransaction(); if($ct->get($invoice->trans_id) === FALSE){ $error_msg .= "Error getting transaction for invoice!"; debug_message($ct->getLastError()); }else{ $ct->amount += $ill->getPrice(); if($ct->update() === FALSE){ $error_msg .= "Error updating company transaction with new price"; debug_message($ct->getLastError()); }else{ header('Location: '.getCurrentURL(null, false).'?mode=edit&id='.$line->id."\r\n");