ok
Direktori : /home2/selectio/www/mm-tailor-billing/app/models/ |
Current File : //home2/selectio/www/mm-tailor-billing/app/models/Incomes_model.php |
<?php if (!defined('BASEPATH')) { exit('No direct script access allowed'); } class Incomes_model extends CI_Model { public function __construct() { parent::__construct(); } public function addIncomesRowBased($date,$amount,$category,$sub_category,$notes,$created_by) { for($e=0;$e<count($date);$e++) { $this->db->insert('tec_incomes', ['date' => $date[$e], 'amount' => $amount[$e], 'category' => $category, 'sub_category' => $sub_category[$e], 'note' => $notes[$e], 'created_by' => $created_by]); } return true; } public function deletePurchase($id) { $purchase = $this->getPurchaseByID($id); if ($purchase->received) { $oitems = $this->getAllPurchaseItems($id); foreach ($oitems as $oitem) { if ($product = $this->site->getProductByID($oitem->product_id)) { $this->setStoreQuantity($oitem->product_id, $purchase->store_id, (0 - $oitem->quantity)); } } } if ($this->db->delete('purchases', ['id' => $id]) && $this->db->delete('purchase_items', ['purchase_id' => $id])) { return true; } return false; } public function getAllPurchaseItems($purchase_id) { $this->db->select('purchase_items.*, products.code as product_code, products.name as product_name') ->join('products', 'products.id=purchase_items.product_id', 'left') ->group_by('purchase_items.id') ->order_by('id', 'asc'); $q = $this->db->get_where('purchase_items', ['purchase_id' => $purchase_id]); if ($q->num_rows() > 0) { foreach (($q->result()) as $row) { $data[] = $row; } return $data; } return false; } public function getExpenseByID($id) { $q = $this->db->get_where('incomes', ['id' => $id], 1); if ($q->num_rows() > 0) { return $q->row(); } return false; } public function getProductByID($id) { $q = $this->db->get_where('products', ['id' => $id], 1); if ($q->num_rows() > 0) { return $q->row(); } return false; } public function getPurchaseByID($id) { $q = $this->db->get_where('purchases', ['id' => $id], 1); if ($q->num_rows() > 0) { return $q->row(); } return false; } // Income Starts Here public function addIncome($data = []) { if ($this->db->insert('incomes', $data)) { return true; } return false; } // Purchase Filter Starts Here public function getTotalIncomes($category, $sub_category = null, $start_date = null, $end_date = null) { if ($start_date && $end_date) { $this->db->where('date >=', $start_date); $this->db->where('date <=', $end_date); } if ($sub_category) { $this->db->where('sub_category', $sub_category); } $q = $this->db->get_where('incomes', ['category' => $category]); if ($q->num_rows() > 0) { return $q->row(); } return false; } // Purchase Filter Ends Here public function deleteIncomes($id) { if ($this->db->delete('incomes', ['id' => $id])) { return true; } return false; } public function getIncomesByID($id) { $q = $this->db->get_where('incomes', ['id' => $id], 1); if ($q->num_rows() > 0) { return $q->row(); } return false; } public function updateIncomes($id, $data = []) { if ($this->db->update('incomes', $data, ['id' => $id])) { return true; } return false; } // Income Ends Here }