public function insert_item()
	{

        global $LANG;

        $tax_total = getTaxesPerLineItem($this->line_item_tax_id,$this->quantity, $this->unit_price);

        //line item gross total
        $gross_total = $this->unit_price * $this->quantity;

        //line item total
        $total = $gross_total + $tax_total;

        //Remove jquery auto-fill description - refer jquery.conf.js.tpl autofill section
        if ($this->description == $LANG['description'])
        {
            $this->description ="";
        }

        if ($db_server == 'mysql' && !_invoice_items_check_fk(
            $invoice_id, $product_id, $tax['tax_id'])) {
            return null;
        }

		$sql = "INSERT INTO ".TB_PREFIX."invoice_items
				(
					invoice_id,
					quantity,
					product_id,
					unit_price,
					tax_amount,
					gross_total,
					description,
					total
				)
				VALUES
				(
					:invoice_id,
					:quantity,
					:product_id,
					:unit_price,
					:tax_amount,
					:gross_total,
					:description,
					:total
				)";

		//echo $sql;
		dbQuery($sql,
			':invoice_id', $this->invoice_id,
			':quantity', $this->quantity,
			':product_id', $this->product_id,
			':unit_price', $this->unit_price,
		//	':tax_id', $tax[tax_id],
		//	':tax_percentage', $tax[tax_percentage],
            ':tax_amount', $tax_total,
            ':gross_total', $gross_total,
            ':description', $this->description,
            ':total', $total

			);

		invoice_item_tax(lastInsertId(),$this->tax,$this->unit_price,$this->quantity,"insert");

        return true;
	}
function updateInvoiceItem($id, $quantity, $product_id, $line_number, $line_item_tax_id, $description, $unit_price, $attribute = "", $domain_id = '')
{
    global $logger;
    global $LANG;
    global $db_server;
    $domain_id = domain_id::get($domain_id);
    //$product = getProduct($product_id);
    //$tax = getTaxRate($tax_id);
    $attr = array();
    $logger->log('Line item attributes: ' . var_export($attribute, true), Zend_Log::INFO);
    foreach ($attribute as $k => $v) {
        if ($attribute[$v] !== '') {
            $attr[$k] = $v;
        }
    }
    $tax_total = getTaxesPerLineItem($line_item_tax_id, $quantity, $unit_price);
    $logger->log('Invoice: ' . $invoice_id . ' Tax ' . $line_item_tax_id . ' for line item ' . $line_number . ': ' . $tax_total, Zend_Log::INFO);
    $logger->log('Description: ' . $description, Zend_Log::INFO);
    $logger->log(' ', Zend_Log::INFO);
    //line item gross total
    $gross_total = $unit_price * $quantity;
    //line item total
    $total = $gross_total + $tax_total;
    //Remove jquery auto-fill description - refer jquery.conf.js.tpl autofill section
    if ($description == $LANG['description']) {
        $description = "";
    }
    if ($db_server == 'mysql' && !_invoice_items_check_fk(null, $product_id, $tax_id, 'update')) {
        return null;
    }
    $sql = "UPDATE " . TB_PREFIX . "invoice_items \n\tSET quantity =  :quantity,\n\tproduct_id = :product_id,\n\tunit_price = :unit_price,\n\ttax_amount = :tax_amount,\n\tgross_total = :gross_total,\n\tdescription = :description,\n\ttotal = :total,\t\t\t\n\tattribute = :attribute\t\t\t\n\tWHERE id = :id AND domain_id = :domain_id";
    dbQuery($sql, ':quantity', $quantity, ':product_id', $product_id, ':unit_price', $unit_price, ':tax_amount', $tax_total, ':gross_total', $gross_total, ':description', $description, ':total', $total, ':attribute', json_encode($attr), ':id', $id, ':domain_id', $domain_id);
    //if from a new invoice item in the edit page user lastInsertId()
    $id == null ? $id = lastInsertId() : ($id = $id);
    invoice_item_tax($id, $line_item_tax_id, $unit_price, $quantity, "update");
    return true;
}
function updateInvoiceItem($id, $quantity, $product_id, $line_number, $line_item_tax_id, $description, $unit_price)
{
    global $logger;
    global $LANG;
    //$product = getProduct($product_id);
    //$tax = getTaxRate($tax_id);
    $tax_total = getTaxesPerLineItem($line_item_tax_id, $quantity, $unit_price);
    $logger->log('Invoice: ' . $invoice_id . ' Tax ' . $line_item_tax_id . ' for line item ' . $line_number . ': ' . $tax_total, Zend_Log::INFO);
    $logger->log('Description: ' . $description, Zend_Log::INFO);
    $logger->log(' ', Zend_Log::INFO);
    //line item gross total
    $gross_total = $unit_price * $quantity;
    //line item total
    $total = $gross_total + $tax_total;
    //Remove jquery auto-fill description - refer jquery.conf.js.tpl autofill section
    if ($description == $LANG['description']) {
        $description = "";
    }
    if ($db_server == 'mysql' && !_invoice_items_check_fk(null, $product_id, $tax_id, 'update')) {
        return null;
    }
    $sql = "UPDATE " . TB_PREFIX . "invoice_items \n\tSET quantity =  :quantity,\n\tproduct_id = :product_id,\n\tunit_price = :unit_price,\n\ttax_amount = :tax_amount,\n\tgross_total = :gross_total,\n\tdescription = :description,\n\ttotal = :total\t\t\t\n\tWHERE id = :id";
    //echo $sql;
    dbQuery($sql, ':quantity', $quantity, ':product_id', $product_id, ':unit_price', $unit_price, ':tax_amount', $tax_total, ':gross_total', $gross_total, ':description', $description, ':total', $total, ':id', $id);
    //if from a new invoice item in the edit page user lastInsertId()
    $id == null ? $id = lastInsertId() : ($id = $id);
    invoice_item_tax($id, $line_item_tax_id, $unit_price, $quantity, "update");
    return true;
}