Exemplo n.º 1
0
 function updateInvoiceItem($id, $quantity, $product_id, $tax_id, $description, $attr1 = "", $attr2 = "", $attr3 = "", $unit_price = "")
 {
     $attr1 = explode("-", $attr1);
     $attr1 = $attr1[2];
     //echo "Attr1: ".$attr1." ";
     $attr2 = explode("-", $attr2);
     $attr2 = $attr2[2];
     //echo "Attr2 : ".$attr2." ";
     $attr3 = explode("-", $attr3);
     $attr3 = $attr3[2];
     //echo "Attr3 : ".$attr3;
     //echo "<br /><br />";
     $product = getProduct($product_id);
     $unit_price == "" ? $product_unit_price = $product['unit_price'] : ($product_unit_price = $unit_price);
     $tax = getTaxRate($tax_id);
     $total_invoice_item_tax = $product_unit_price * $tax['tax_percentage'] / 100;
     //:100?
     $tax_amount = $total_invoice_item_tax * $quantity;
     $total_invoice_item = $total_invoice_item_tax + $product_unit_price;
     $total = $total_invoice_item * $quantity;
     $gross_total = $product_unit_price * $quantity;
     if ($db_server == 'mysql' && !_invoice_items_check_fk(null, $product_id, $tax_id, 'update')) {
         return null;
     }
     $sql = "UPDATE " . TB_PREFIX . "invoice_items \r\n\t\tSET quantity =  :quantity,\r\n\t\tproduct_id = :product_id,\r\n\t\tunit_price = :unit_price,\r\n\t\ttax_id = :tax_id,\r\n\t\ttax = :tax,\r\n\t\ttax_amount = :tax_amount,\r\n\t\tgross_total = :gross_total,\r\n\t\tdescription = :description,\r\n\t\ttotal = :total,\t\t\t\r\n\t\tattribute_1 = :attr1,\t\t\t\r\n\t\tattribute_2 = :attr2,\t\t\t\r\n\t\tattribute_3 = :attr3\t\t\t\r\n\t\tWHERE id = :id";
     //echo $sql;
     return dbQuery($sql, ':quantity', $quantity, ':product_id', $product_id, ':unit_price', $product_unit_price, ':tax_id', $tax_id, ':tax', $tax[tax_percentage], ':tax_amount', $tax_amount, ':gross_total', $gross_total, ':description', $description, ':total', $total, ':id', $id, ':attr1', $attr1, ':attr2', $attr2, ':attr3', $attr3);
 }
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;
}
Exemplo n.º 3
0
	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;
	}
Exemplo n.º 4
0
	function updateInvoiceItem($id,$quantity,$product_id,$tax_id,$description,$attr1="",$attr2="",$attr3="", $unit_price="") {
        
        $SI_PRODUCTS = new SimpleInvoices_Db_Table_Products();
        $SI_TAX = new SimpleInvoices_Db_Table_Tax();
        
			$attr1 = explode("-",$attr1);
			$attr1 = $attr1[2];
			//echo "Attr1: ".$attr1." ";

			$attr2 = explode("-",$attr2);
			$attr2 = $attr2[2];
			//echo "Attr2 : ".$attr2." ";

			$attr3 = explode("-",$attr3);
			$attr3 = $attr3[2];
			//echo "Attr3 : ".$attr3;
			//echo "<br /><br />";


		$product = $SI_PRODUCTS->getProductById($product_id);
		($unit_price == "") ? $product_unit_price = $product['unit_price'] : $product_unit_price = $unit_price ;
		$tax = $SI_TAX->getTaxRateById($tax_id);
		
		$total_invoice_item_tax = $product_unit_price * $tax['tax_percentage'] / 100;	//:100?
		$tax_amount = $total_invoice_item_tax * $quantity;
		$total_invoice_item = $total_invoice_item_tax + $product_unit_price;
		$total = $total_invoice_item * $quantity;
		$gross_total = $product_unit_price * $quantity;
		
		if ($db_server == 'mysql' && !_invoice_items_check_fk(
			null, $product_id, $tax_id, 'update')) {
			return null;
		}

		$sql = "UPDATE ".TB_PREFIX."invoice_items 
		SET quantity =  :quantity,
		product_id = :product_id,
		unit_price = :unit_price,
		tax_id = :tax_id,
		tax = :tax,
		tax_amount = :tax_amount,
		gross_total = :gross_total,
		description = :description,
		total = :total,			
		attribute_1 = :attr1,			
		attribute_2 = :attr2,			
		attribute_3 = :attr3			
		WHERE id = :id";
		
		//echo $sql;
			
		return dbQuery($sql,
			':quantity', $quantity,
			':product_id', $product_id,
			':unit_price', $product_unit_price,
			':tax_id', $tax_id,
			':tax', $tax[tax_percentage],
			':tax_amount', $tax_amount,
			':gross_total', $gross_total,
			':description', $description,
			':total', $total,
			':id', $id,
			':attr1', $attr1,
			':attr2', $attr2,
			':attr3', $attr3
			);
	}
Exemplo n.º 5
0
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;
}