73 lines
2.2 KiB
PHP
73 lines
2.2 KiB
PHP
<?php
|
|
if (!defined('BASEPATH')) exit('No direct script access allowed');
|
|
|
|
/*
|
|
* InvoicePlane
|
|
*
|
|
* @author InvoicePlane Developers & Contributors
|
|
* @copyright Copyright (c) 2012 - 2017 InvoicePlane.com
|
|
* @license https://invoiceplane.com/license.txt
|
|
* @link https://invoiceplane.com
|
|
*/
|
|
|
|
/**
|
|
* Class Mdl_Item_Amounts
|
|
*/
|
|
class Mdl_Item_Amounts extends CI_Model
|
|
{
|
|
/**
|
|
* item_amount_id
|
|
* item_id
|
|
* item_subtotal (item_quantity * item_price)
|
|
* item_tax_total
|
|
* item_total ((item_quantity * item_price) + item_tax_total)
|
|
*
|
|
* @param $item_id
|
|
*/
|
|
public function calculate($item_id)
|
|
{
|
|
|
|
// echo("<script>console.log('PHP: ".$item_id."');</script>");
|
|
|
|
// die();
|
|
|
|
$amount='';
|
|
$this->load->model('invoices/mdl_items');
|
|
$item = $this->mdl_items->get_by_id($item_id);
|
|
|
|
$item_subtotal = $item->item_quantity * $item->item_price;
|
|
$amount = $item->item_subtotal - $item->item_discount;
|
|
$item_tax_total = $amount * (($item->Sgst_item_tax_rate_percent + $item->Cgst_item_tax_rate_percent +$item->Igst_item_tax_rate_percent) / 100);
|
|
$item_discount_total = $item->item_discount_amount * $item->item_quantity;
|
|
$item_total = $item_subtotal + $item_tax_total - $item_discount_total;
|
|
|
|
$item_cgst= $amount * ($item->Cgst_item_tax_rate_percent)/100;
|
|
$item_sgst= $amount * ($item->Sgst_item_tax_rate_percent)/100;
|
|
$item_igst= $amount * ($item->Igst_item_tax_rate_percent)/100;
|
|
|
|
|
|
|
|
$db_array = array(
|
|
'item_id' => $item_id,
|
|
'item_subtotal' => $item_subtotal,
|
|
'item_tax_total' => $item_tax_total,
|
|
'item_discount' => $item_discount_total,
|
|
'item_total' => $item_total,
|
|
'item_cgst_amt'=> $item_cgst,
|
|
'item_sgst_amt'=> $item_sgst,
|
|
'item_igst_amt'=> $item_igst
|
|
|
|
|
|
);
|
|
|
|
$this->db->where('item_id', $item_id);
|
|
if ($this->db->get('ip_invoice_item_amounts')->num_rows()) {
|
|
$this->db->where('item_id', $item_id);
|
|
$this->db->update('ip_invoice_item_amounts', $db_array);
|
|
} else {
|
|
$this->db->insert('ip_invoice_item_amounts', $db_array);
|
|
}
|
|
}
|
|
|
|
}
|