Ejemplo n.º 1
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
			);
	}
Ejemplo n.º 2
0
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;
}
Ejemplo n.º 3
0
    public static function expense_item_tax($expense_id,$line_item_tax_id,$unit_price,$quantity,$action="") {
        
        global $logger;
        global $db;
        
        $SI_TAX = new SimpleInvoices_Db_Table_Tax();
        
        $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
                                ".TB_PREFIX."expense_item_tax
                           WHERE
                                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 = $SI_TAX->getTaxRateById($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 
                            INTO 
                        ".TB_PREFIX."expense_item_tax 
                        (
                            expense_id, 
                            tax_id, 
                            tax_type, 
                            tax_rate, 
                            tax_amount
                        ) 
                        VALUES 
                        (
                            :expense_id, 
                            :tax_id,
                            :tax_type,
                            :tax_rate,
                            :tax_amount
                        )";

                $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;
    }
Ejemplo n.º 4
0
$SI_TAX = new SimpleInvoices_Db_Table_Tax();

#table

jsBegin();
jsFormValidationBegin("frmpost");
jsValidateRequired("tax_description",$LANG['tax_description']);
jsValidateifNum("tax_percentage",$LANG['tax_percentage']);
jsFormValidationEnd();
jsEnd();



#get the invoice id
$tax_rate_id = $_GET['id'];

$tax = $SI_TAX->getTaxRateById($tax_rate_id);

$types = $types = array(
    '%' => '%',
    '$' => '$'
);

$smarty -> assign("tax",$tax);
$smarty -> assign("types",$types);
$smarty -> assign('pageActive', 'tax_rate');
$subPageActive = $_GET['action'] =="view"  ? "tax_rates_view" : "tax_rates_edit" ;
$smarty -> assign('subPageActive', $subPageActive);
$smarty -> assign('active_tab', '#setting');
?>
Ejemplo n.º 5
0
<?php
//stop the direct browsing to this file - let index.php handle which files get displayed
checkLogin();

#get the invoice id
$product_id = $_GET['id'];

$SI_SYSTEM_DEFAULTS = new SimpleInvoices_Db_Table_SystemDefaults();
$SI_PRODUCTS = new SimpleInvoices_Db_Table_Products();
$SI_TAX = new SimpleInvoices_Db_Table_Tax();
$SI_CUSTOM_FIELDS = new SimpleInvoices_Db_Table_CustomFields();

$product = $SI_PRODUCTS->getProductById($product_id);

#get custom field labels
$customFieldLabel = $SI_CUSTOM_FIELDS->getLabels();
$taxes = $SI_TAX->fetchAllActive();
$tax_selected = $SI_TAX->getTaxRateById($product['default_tax_id']);

$smarty -> assign("defaults",$SI_SYSTEM_DEFAULTS->fetchAll());
$smarty -> assign('product',$product);
$smarty -> assign('taxes',$taxes);
$smarty -> assign('tax_selected',$tax_selected);
$smarty -> assign('customFieldLabel',$customFieldLabel);

$smarty -> assign('pageActive', 'product_manage');
$subPageActive = $_GET['action'] =="view"  ? "product_view" : "product_edit" ;
$smarty -> assign('subPageActive', $subPageActive);
$smarty -> assign('active_tab', '#product');
?>