BBnepal-Accounts/account/application/controllers/inventory/Purchases.php
Sampanna Rimal c16163bf01 daterange
2024-07-26 12:50:15 +05:45

110 lines
4.7 KiB
PHP

<?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']),
'discount' => filter_var($_POST['discountpercentage']),
'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':
//
$data['fiscalStart'] = NepaliDate($this->session->userdata['FiscalYear']->fiscalyear_from);
$data['fiscalEnd'] = NepaliDate($this->session->userdata['FiscalYear']->fiscalyear_to);
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);
break;
case 'getunitbyitem':
$id = $this->uri->segment(4);
$unit = $this->MStocks->getUnitByItemId($id);
echo json_encode($unit);
break;
default:
$data['PurchaseRecords'] = $this->MPurchases->getPurchaseRecords();
loadView("inventory/purchases/list", $data);
}
}
}