162 lines
6.0 KiB
PHP
162 lines
6.0 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_Quote_Items
|
|
*/
|
|
class Mdl_Quote_Items extends Response_Model
|
|
{
|
|
public $table = 'ip_quote_items';
|
|
public $primary_key = 'ip_quote_items.item_id';
|
|
public $date_created_field = 'item_date_added';
|
|
|
|
public function default_select()
|
|
{
|
|
// $this->db->select('ip_quote_item_amounts.*, ip_quote_items.*, item_tax_rates.tax_rate_percent AS item_tax_rate_percent,item_sgst_amt,
|
|
// item_cgst_amt,item_igst_amt');
|
|
|
|
$this->db->select('ip_quote_item_amounts.*, ip_products.*, ip_quote_items.*,
|
|
Sgst_item_tax_rates.tax_rate_percent AS Sgst_item_tax_rate_percent,
|
|
Sgst_item_tax_rates.tax_rate_name AS Sgst_item_tax_rate_name,(((ip_quote_items.item_quantity * ip_quote_items.item_price) - (ip_quote_items.item_quantity * ip_quote_items.item_discount_amount)) * Sgst_item_tax_rates.tax_rate_percent /100) AS Sgst_item_tax_rate_amount,Cgst_item_tax_rates.tax_rate_percent AS Cgst_item_tax_rate_percent,
|
|
Cgst_item_tax_rates.tax_rate_name AS Cgst_item_tax_rate_name,(((ip_quote_items.item_quantity * ip_quote_items.item_price) - (ip_quote_items.item_quantity * ip_quote_items.item_discount_amount)) * Cgst_item_tax_rates.tax_rate_percent /100) AS Cgst_item_tax_rate_amount,Igst_item_tax_rates.tax_rate_percent AS Igst_item_tax_rate_percent,
|
|
Igst_item_tax_rates.tax_rate_name AS Igst_item_tax_rate_name,(((ip_quote_items.item_quantity * ip_quote_items.item_price) - (ip_quote_items.item_quantity * ip_quote_items.item_discount_amount)) * Igst_item_tax_rates.tax_rate_percent /100) AS Igst_item_tax_rate_amount');
|
|
}
|
|
|
|
public function default_order_by()
|
|
{
|
|
$this->db->order_by('ip_quote_items.item_order');
|
|
}
|
|
|
|
public function default_join()
|
|
{
|
|
// $this->db->join('ip_quote_item_amounts', 'ip_quote_item_amounts.item_id = ip_quote_items.item_id', 'left');
|
|
// $this->db->join('ip_tax_rates AS item_tax_rates', 'item_tax_rates.tax_rate_id = ip_quote_items.item_tax_rate_id', 'left');
|
|
|
|
$this->db->join('ip_quote_item_amounts', 'ip_quote_item_amounts.item_id = ip_quote_items.item_id', 'left');
|
|
$this->db->join('ip_tax_rates AS Sgst_item_tax_rates', 'Sgst_item_tax_rates.tax_rate_id = ip_quote_items.Sgst_item_tax_rate_id', 'left');
|
|
$this->db->join('ip_tax_rates AS Cgst_item_tax_rates', 'Cgst_item_tax_rates.tax_rate_id = ip_quote_items.Cgst_item_tax_rate_id', 'left');
|
|
$this->db->join('ip_tax_rates AS Igst_item_tax_rates', 'Igst_item_tax_rates.tax_rate_id = ip_quote_items.Igst_item_tax_rate_id', 'left');
|
|
$this->db->join('ip_products', 'ip_products.product_id = ip_quote_items.item_product_id', 'left');
|
|
|
|
}
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
public function validation_rules()
|
|
{
|
|
return array(
|
|
'quote_id' => array(
|
|
'field' => 'quote_id',
|
|
'label' => trans('quote'),
|
|
'rules' => 'required'
|
|
),
|
|
'item_name' => array(
|
|
'field' => 'item_name',
|
|
'label' => trans('item_name'),
|
|
'rules' => 'required'
|
|
),
|
|
'item_description' => array(
|
|
'field' => 'item_description',
|
|
'label' => trans('description')
|
|
),
|
|
'item_quantity' => array(
|
|
'field' => 'item_quantity',
|
|
'label' => trans('quantity'),
|
|
),
|
|
'item_price' => array(
|
|
'field' => 'item_price',
|
|
'label' => trans('price'),
|
|
),
|
|
'item_tax_rate_id' => array(
|
|
'field' => 'item_tax_rate_id',
|
|
'label' => trans('item_tax_rate')
|
|
),
|
|
'item_product_id' => array(
|
|
'field' => 'item_product_id',
|
|
'label' => trans('original_product')
|
|
),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @param null $id
|
|
* @param null $db_array
|
|
* @return int|null
|
|
*/
|
|
public function save($id = null, $db_array = null)
|
|
{
|
|
$id = parent::save($id, $db_array);
|
|
|
|
|
|
|
|
$this->load->model('quotes/mdl_quote_item_amounts');
|
|
$this->mdl_quote_item_amounts->calculate($id);
|
|
|
|
$this->load->model('quotes/mdl_quote_amounts');
|
|
|
|
if (is_object($db_array) && isset($db_array->quote_id)) {
|
|
$this->mdl_quote_amounts->calculate($db_array->quote_id);
|
|
} elseif (is_array($db_array) && isset($db_array['quote_id'])) {
|
|
$this->mdl_quote_amounts->calculate($db_array['quote_id']);
|
|
}
|
|
|
|
return $id;
|
|
}
|
|
|
|
/**
|
|
* @param int $item_id
|
|
*/
|
|
public function delete($item_id)
|
|
{
|
|
// Get the quote id so we can recalculate quote amounts
|
|
$this->db->select('quote_id');
|
|
$this->db->where('item_id', $item_id);
|
|
$quote_id = $this->db->get('ip_quote_items')->row()->quote_id;
|
|
|
|
// Delete the item
|
|
parent::delete($item_id);
|
|
|
|
// Delete the item amounts
|
|
$this->db->where('item_id', $item_id);
|
|
$this->db->delete('ip_quote_item_amounts');
|
|
|
|
// Recalculate quote amounts
|
|
$this->load->model('quotes/mdl_quote_amounts');
|
|
$this->mdl_quote_amounts->calculate($quote_id);
|
|
}
|
|
|
|
|
|
public function getquotepono($quote_id)
|
|
{
|
|
$subQuery = "select quote_pono,po_date_created from ip_quotes where quote_id =?";
|
|
|
|
$query = $this->db->query($subQuery,array($quote_id));
|
|
|
|
return $query->result();
|
|
}
|
|
|
|
|
|
public function Save_customarray($custom_array)
|
|
{
|
|
|
|
$this->db->trans_start();
|
|
$this->db->insert('ip_invoice_custom',$custom_array);
|
|
$insert_id = $this->db->affected_rows();
|
|
|
|
$this->db->trans_complete();
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
}
|