2024-07-10 12:43:19 +00:00
|
|
|
<?php
|
|
|
|
defined('BASEPATH') or exit('No direct script access allowed');
|
|
|
|
class Purchases extends CI_Controller
|
|
|
|
{
|
|
|
|
function __construct()
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
$this->load->model('MStocks');
|
|
|
|
$this->load->model('MPurchases');
|
|
|
|
checkLogin();
|
|
|
|
}
|
|
|
|
public function _remap($alias = "", $params = array())
|
|
|
|
{
|
|
|
|
|
|
|
|
$data['dataValue'] = $this->session;
|
|
|
|
|
|
|
|
$data['pageTitle'] = "Purchase";
|
|
|
|
|
|
|
|
switch ($alias) {
|
|
|
|
case 'details':
|
|
|
|
$id = $this->uri->segment(4);
|
|
|
|
$this->db->where('purchase_id', $id);
|
|
|
|
$data['Purchase'] = $this->db->get("tbl_purchases")->row();
|
|
|
|
$this->db->where('purchases_id', $id);
|
|
|
|
$data['PurchaseDetails'] = $this->db->get("tbl_purchasedetails")->result();
|
|
|
|
$data['pageTitle'] = "View Purchase";
|
|
|
|
loadView("inventory/purchases/view", $data);
|
|
|
|
break;
|
|
|
|
case 'create':
|
|
|
|
// print_r($_POST);die;
|
|
|
|
if (isset($_POST['accounts_id'])) {
|
|
|
|
$TableData = array(
|
|
|
|
'transaction_type' => "Purchase Entry",
|
|
|
|
'accounts_id' => filter_var($_POST['accounts_id']),
|
|
|
|
'purchase_date' => filter_var($_POST['purchase_date']),
|
2024-07-16 06:58:55 +00:00
|
|
|
'discount' => filter_var($_POST['discountpercentage']),
|
2024-07-10 12:43:19 +00:00
|
|
|
'created_on' => date('Y-m-d H:i:s'),
|
|
|
|
'created_by' => 'admin',
|
|
|
|
'remarks' => '',
|
|
|
|
'status' => 1,
|
|
|
|
);
|
|
|
|
$this->db->insert('tbl_purchases', $TableData);
|
|
|
|
$purchase_id = $this->db->insert_id();
|
|
|
|
$a = 0;
|
|
|
|
foreach ($_POST['item_id'] as $item) {
|
|
|
|
$TableData = array(
|
|
|
|
'purchases_id' => $purchase_id,
|
|
|
|
'items_id' => $item,
|
|
|
|
'qty' => $_POST['quantity'][$a],
|
|
|
|
'rate' => $_POST['rate'][$a],
|
|
|
|
'created_on' => date('Y-m-d H:i:s'),
|
|
|
|
'created_by' => 'admin',
|
|
|
|
'remarks' => '',
|
|
|
|
'status' => 1,
|
|
|
|
);
|
|
|
|
$this->db->insert('tbl_purchasedetails', $TableData);
|
|
|
|
$a += 1;
|
|
|
|
}
|
|
|
|
$this->MStocks->addPurchaseToStock($this->db->where("purchases_id", $purchase_id)->get("tbl_purchasedetails")->result());
|
|
|
|
redirect("inventory/purchases/list");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'add':
|
|
|
|
//
|
|
|
|
if (isset($_POST['submit'])) {
|
|
|
|
$TableData = array(
|
|
|
|
'transaction_type' => filter_var($_POST['transaction_type']),
|
|
|
|
'accounts_id' => filter_var($_POST['accounts_id']),
|
|
|
|
'purchase_date' => filter_var($_POST['purchase_date']),
|
|
|
|
'created_on' => date('Y-m-d H:i:s'),
|
|
|
|
'created_by' => 'admin',
|
|
|
|
'remarks' => filter_var($_POST['remarks']),
|
|
|
|
'status' => 1,
|
|
|
|
);
|
|
|
|
pre($_POST);
|
|
|
|
die;
|
|
|
|
//$this->db->insert('tbl_purchases', $TableData);
|
|
|
|
redirect("inventory/purchases/list");
|
|
|
|
}
|
|
|
|
loadView("inventory/purchases/create", $data);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'delete':
|
|
|
|
$id = $this->uri->segment(4);
|
|
|
|
$this->db->where('purchase_id', $id);
|
|
|
|
$this->db->delete('tbl_purchases');
|
|
|
|
$this->db->where('purchases_id', $id);
|
|
|
|
$this->db->delete('tbl_purchasedetails');
|
|
|
|
redirect("inventory/purchases/list");
|
|
|
|
break;
|
|
|
|
case 'purchase_register':
|
|
|
|
$data['PurchaseRecords'] = $this->MPurchases->getPurchaseRecords();
|
|
|
|
loadView("inventory/purchases/register", $data);
|
2024-07-12 12:12:29 +00:00
|
|
|
break;
|
2024-07-16 06:58:55 +00:00
|
|
|
|
|
|
|
case 'getunitbyitem':
|
|
|
|
$id = $this->uri->segment(4);
|
|
|
|
$unit = $this->MStocks->getUnitByItemId($id);
|
|
|
|
echo json_encode($unit);
|
|
|
|
break;
|
|
|
|
|
2024-07-10 12:43:19 +00:00
|
|
|
default:
|
|
|
|
$data['PurchaseRecords'] = $this->MPurchases->getPurchaseRecords();
|
|
|
|
loadView("inventory/purchases/list", $data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|