Exemple #1
0
 public static function expense_item_tax($expense_id, $line_item_tax_id, $unit_price, $quantity, $action = "")
 {
     global $logger;
     global $db;
     $logger->log("Exp ITEM :: Key: " . $key . " Value: " . $value, Zend_Log::INFO);
     //if editing invoice delete all tax info then insert first then do insert again
     //probably can be done without delete - someone to look into this if required - TODO
     if ($action == "update") {
         $sql_delete = "DELETE from\n                                " . TB_PREFIX . "expense_item_tax\n                           WHERE\n                                expense_id = :expense_id";
         $logger->log("Expense item: " . $expense_id . " tax lines deleted", Zend_Log::INFO);
         $db->query($sql_delete, ':expense_id', $expense_id);
     }
     foreach ($line_item_tax_id as $key => $value) {
         if ($value !== "") {
             $tax = getTaxRate($value);
             $logger->log("Expense - item tax :: Key: " . $key . " Value: " . $value, Zend_Log::INFO);
             $logger->log('Expense - item tax :: tax rate: ' . $tax['tax_percentage'], Zend_Log::INFO);
             $tax_amount = lineItemTaxCalc($tax, $unit_price, $quantity);
             //get Total tax for line item
             $tax_total = $tax_total + $tax_amount;
             $logger->log('Expense - item tax :: Qty: ' . $quantity . ' Unit price: ' . $unit_price, Zend_Log::INFO);
             $logger->log('Expense - item tax :: Tax rate: ' . $tax[tax_percentage] . ' Tax type: ' . $tax['type'] . ' Tax $: ' . $tax_amount, Zend_Log::INFO);
             $sql = "INSERT \n                            INTO \n                        " . TB_PREFIX . "expense_item_tax \n                        (\n                            expense_id, \n                            tax_id, \n                            tax_type, \n                            tax_rate, \n                            tax_amount\n                        ) \n                        VALUES \n                        (\n                            :expense_id, \n                            :tax_id,\n                            :tax_type,\n                            :tax_rate,\n                            :tax_amount\n                        )";
             $db->query($sql, ':expense_id', $expense_id, ':tax_id', $tax[tax_id], ':tax_type', $tax[type], ':tax_rate', $tax[tax_percentage], ':tax_amount', $tax_amount);
         }
     }
     //TODO fix this
     return true;
 }
function getTaxesPerLineItem($line_item_tax_id,$quantity, $unit_price)
{
    global $logger;
    
    $SI_TAX = new SimpleInvoices_Db_Table_Tax();
    
    foreach($line_item_tax_id as $key => $value)
    {
        $logger->log("Key: ".$key." Value: ".$value, Zend_Log::INFO);
        $tax = $SI_TAX->getTaxRateById($value);
        $logger->log('tax rate: '.$tax['tax_percentage'], Zend_Log::INFO);

        $tax_amount = lineItemTaxCalc($tax,$unit_price,$quantity);
        //get Total tax for line item
        $tax_total = $tax_total + $tax_amount;

        //$logger->log('Qty: '.$quantity.' Unit price: '.$unit_price, Zend_Log::INFO);
        //$logger->log('Tax rate: '.$tax[tax_percentage].' Tax type: '.$tax['tax_type'].' Tax $: '.$tax_amount, Zend_Log::INFO);

    }
    return $tax_total;
}
function invoice_item_tax($invoice_item_id, $line_item_tax_id, $unit_price, $quantity, $action = '', $domain_id = '')
{
    global $logger;
    $domain_id = domain_id::get($domain_id);
    //if editing invoice delete all tax info then insert first then do insert again
    //probably can be done without delete - someone to look into this if required - TODO
    if ($action == "update") {
        $sql_delete = "DELETE from\n\t\t\t\t\t\t\t" . TB_PREFIX . "invoice_item_tax\n\t\t\t\t\t   WHERE\n\t\t\t\t\t\t\tinvoice_item_id = :invoice_item_id";
        $logger->log("Invoice item: " . $invoice_item_id . " tax lines deleted", Zend_Log::INFO);
        dbQuery($sql_delete, ':invoice_item_id', $invoice_item_id);
    }
    foreach ($line_item_tax_id as $key => $value) {
        if ($value !== "") {
            $tax = getTaxRate($value, $domain_id);
            $logger->log("ITEM :: Key: " . $key . " Value: " . $value, Zend_Log::INFO);
            $logger->log('ITEM :: tax rate: ' . $tax['tax_percentage'], Zend_Log::INFO);
            $logger->log('ITEM :: domain_id: ' . $domain_id, Zend_Log::INFO);
            $tax_amount = lineItemTaxCalc($tax, $unit_price, $quantity);
            //get Total tax for line item (unused here)
            // $tax_total = $tax_total + $tax_amount;
            $logger->log('ITEM :: Qty: ' . $quantity . ' Unit price: ' . $unit_price, Zend_Log::INFO);
            $logger->log('ITEM :: Tax rate: ' . $tax[tax_percentage] . ' Tax type: ' . $tax['type'] . ' Tax $: ' . $tax_amount, Zend_Log::INFO);
            $sql = "INSERT \n\t\t\t\t\t\tINTO \n\t\t\t\t\t" . TB_PREFIX . "invoice_item_tax \n\t\t\t\t\t(\n\t\t\t\t\t\tinvoice_item_id, \n\t\t\t\t\t\ttax_id, \n\t\t\t\t\t\ttax_type, \n\t\t\t\t\t\ttax_rate, \n\t\t\t\t\t\ttax_amount\n\t\t\t\t\t) \n\t\t\t\t\tVALUES \n\t\t\t\t\t(\n\t\t\t\t\t\t:invoice_item_id, \n\t\t\t\t\t\t:tax_id,\n\t\t\t\t\t\t:tax_type,\n\t\t\t\t\t\t:tax_rate,\n\t\t\t\t\t\t:tax_amount\n\t\t\t\t\t)";
            dbQuery($sql, ':invoice_item_id', $invoice_item_id, ':tax_id', $tax['tax_id'], ':tax_type', $tax['type'], ':tax_rate', $tax['tax_percentage'], ':tax_amount', $tax_amount);
        }
    }
    //TODO fix this
    return true;
}
function invoice_item_tax($invoice_item_id,$line_item_tax_id,$unit_price,$quantity,$action="") {

	global $logger;

    $SI_TAX = new SimpleInvoices_Db_Table_Tax();
    
	//if editing invoice delete all tax info then insert first then do insert again
	//probably can be done without delete - someone to look into this if required - TODO
	if ($action =="update")
	{

		$sql_delete = "DELETE from
							".TB_PREFIX."invoice_item_tax
					   WHERE
							invoice_item_id = :invoice_item_id";
		$logger->log("Invoice item: ".$invoice_item_id." tax lines deleted", Zend_Log::INFO);

		dbQuery($sql_delete,':invoice_item_id',$invoice_item_id);


	}

	foreach($line_item_tax_id as $key => $value)
	{
		if($value !== "")
		{
			$tax = $SI_TAX->getTaxRateById($value);

			$logger->log("ITEM :: Key: ".$key." Value: ".$value, Zend_Log::INFO);
			$logger->log('ITEM :: tax rate: '.$tax['tax_percentage'], Zend_Log::INFO);

			$tax_amount = lineItemTaxCalc($tax,$unit_price,$quantity);
			//get Total tax for line item
			$tax_total = $tax_total + $tax_amount;

			$logger->log('ITEM :: Qty: '.$quantity.' Unit price: '.$unit_price, Zend_Log::INFO);
			$logger->log('ITEM :: Tax rate: '.$tax['tax_percentage'].' Tax type: '.$tax['type'].' Tax $: '.$tax_amount, Zend_Log::INFO);

			$sql = "INSERT
						INTO
					".TB_PREFIX."invoice_item_tax
					(
						invoice_item_id,
						tax_id,
						tax_type,
						tax_rate,
						tax_amount
					)
					VALUES
					(
						:invoice_item_id,
						:tax_id,
						:tax_type,
						:tax_rate,
						:tax_amount
					)";

			dbQuery($sql,
				':invoice_item_id', $invoice_item_id,
				':tax_id', $tax['tax_id'],
				':tax_type', $tax['type'],
				':tax_rate', $tax['tax_percentage'],
				':tax_amount', $tax_amount
				);
		}
	}
	//TODO fix this
	return true;
}