siddharth_application/application/controllers/supplier.php
saravanakumar_kandasami 749478c0e4 new code
2017-03-13 14:24:41 +05:30

263 lines
9.5 KiB
PHP

<?php if(!defined('BASEPATH')) exit('No direct script access allowed');
require APPPATH . '/libraries/BaseController.php';
/**
* Class : purchaseorder (PurchaseorderController)
* User Class to control all user related operations.
* @author : VenbaMail Mali
* @version : 1.1
* @since : 15 Feb 2016
*/
class supplier extends BaseController
{
/**
* This is default constructor of the class
*/
public function __construct()
{
parent::__construct();
$this->load->model('supplier_model');
$this->isLoggedIn();
}
/**
* This function used to load the first screen of the user
*/
public function index()
{
$this->global['pageTitle'] = 'Siddharth : Supplier';
$this->loadViews("supplierlisting", $this->global, NULL , NULL);
}
/**
* This function is used to load the Supplier list
*/
function supplierListing()
{
if($this->isAdmin() == TRUE)
{
$this->loadThis();
}
else
{
$this->load->model('supplier_model');
$searchText = $this->input->post('searchText');
$data['searchText'] = $searchText;
$this->load->library('pagination');
$count = $this->supplier_model->supplierListingCount($searchText);
$returns = $this->paginationCompress ( "supplierListing/", $count, 5 );
$data['userRecords'] = $this->supplier_model->supplierListing($searchText, $returns["page"], $returns["segment"]);
$this->global['pageTitle'] = 'Siddharth : Supplier Listing';
$this->loadViews("supplierListing", $this->global, $data, NULL);
}
}
/**
* This function is used to load the add new supplier */
function addsupplier()
{
if($this->isAdmin() == TRUE)
{
$this->loadThis();
}
else
{
$this->load->model('supplier_model');
//$data['SupplierName'] = $this->purchaseorder_model->getSupplierName();
//$data['users'] = $this->purchaseorder_model->getusers();
$this->global['pageTitle'] = 'siddharth : AddNew Supplier';
$this->loadViews("addsupplier", $this->global, NULL);
}
}
/**
* This function is used to add new user to the system
*/
function addNewsupplier()
{
if($this->isAdmin() == TRUE)
{
$this->loadThis();
}
else
{
$this->load->library('form_validation');
$PO = $this->input->post('SupplierID');
$this->form_validation->set_rules('SupplierName','Supplier Name','trim');
$this->form_validation->set_rules('Address','Address','trim|required|');
$this->form_validation->set_rules('ContactNumber','Contact Number','trim||numeric');
$this->form_validation->set_rules('AlternateContactNumber','Alternate Contact Number','trim||numeric');
$this->form_validation->set_rules('EmailAddress','Email Address|valid_email|xss_clean|max_length[128]');
$this->form_validation->set_rules('TIN','TIN','trim|required');
$this->form_validation->set_rules('PAN','PAN','required');
if($this->form_validation->run() == FALSE)
{
$this->addsupplier();
}
else
{
$SupplierName = ucwords(strtolower($this->input->post('SupplierName')));
$Address = $this->input->post('Address');
$ContactNumber = $this->input->post('ContactNumber');
$AlternateContactNumber = $this->input->post('AlternateContactNumber');
$EmailAddress = $this->input->post('EmailAddress');
$TIN = $this->input->post('TIN');
$PAN = $this->input->post('PAN');
$supplier = array('SupplierName'=>$SupplierName, 'Address'=>$Address, 'ContactNumber'=>$ContactNumber, 'AlternateContactNumber'=> $AlternateContactNumber,'EmailAddress'=>$EmailAddress,'TIN'=>$TIN,'PAN'=>$PAN,'createdDate'=>date('Y-m-d H:i:sa'));
$this->load->model('supplier_model');
$result = $this->supplier_model->addNewsupplier($supplier);
if($result > 0)
{
$this->session->set_flashdata('success', 'New PO created successfully');
}
else
{
$this->session->set_flashdata('error', 'PO Not Create');
}
redirect('supplierlisting');
}
}
}
/**
* This function is used load user edit information
* @param number $userId : Optional : This is user id
*/
function editOldsupplier($supplierID = NULL)
{
if($this->isAdmin() == TRUE || $supplierID == 1)
{
$this->loadThis();
}
else
{
if($supplierID == null)
{
redirect('');
}
//$data['SupplierName'] = $this->purchaseorder_model->getSupplierName();
//$data['users'] = $this->purchaseorder_model->getusers();
$this->global['pageTitle'] = 'Siddharth : Edit User';
$this->loadViews("editOldsupplier", $this->global, NULL);
}
}
/**
* This function is used to edit the user information
*/
function editsupplier()
{
if($this->isAdmin() == TRUE)
{
$this->loadThis();
}
else
{
$this->load->library('form_validation');
$PO = $this->input->post('PO');
$this->form_validation->set_rules('POType','PO Type','trim|required|');
$this->form_validation->set_rules('PODate','PO Date','trim|required|');
$this->form_validation->set_rules('SupplierID','SupplierID','trim|required|');
$this->form_validation->set_rules('SpecialOrder','Special Requirement of order','|max_length[20]');
$this->form_validation->set_rules('role','UserID','trim||numeric');
$this->form_validation->set_rules('reemail','Requester email','trim|valid_email|xss_clean|max_length[128]');
$this->form_validation->set_rules('rephone','Requester ph','required|min_length[10]|xss_clean');
$this->form_validation->set_rules('reDate','Requested Date','required');
$this->form_validation->set_rules('budmanager','Budget Manager');
$this->form_validation->set_rules('budmanagerde','Budget Manager Department','trim');
$this->form_validation->set_rules('PurchasingCategory','Purchasing Category','trim');
if($this->form_validation->run() == FALSE)
{
$this->editPO();
}
else
{
$POType = ucwords(strtolower($this->input->post('POType')));
$PODate = $this->input->post('PODate');
$SupplierID = $this->input->post('SupplierID');
$SpecialOrder = $this->input->post('SpecialOrder');
$role = $this->input->post('role');
$reemail = $this->input->post('reemail');
$rephone = $this->input->post('rephone');
$reDate = $this->input->post('reDate');
$budmanager = $this->input->post('budmanager');
$budmanagerde = $this->input->post('budmanagerde');
$Purcategory = $this->input->post('PurchasingCategory');
$supplier = array('POType'=>$POType, 'PODate'=>$PODate, 'SupplierID'=>$SupplierID, 'SpecialOrder'=> $SpecialOrder,'UserID'=>$role,'RequestedDate'=>$reDate,'RequesterEmail'=>$reemail,'RequesterPh'=>$rephone, 'PurchasingCategory'=>$Purcategory,'BudgetManager'=>$budmanager,'BudgetManagerDepartment'=>$budmanagerde,'createdBy'=>$this->vendorId, 'createdDtm'=>date('Y-m-d H:i:sa'));
$supplier = array();
$result = $this->supplier_model->editPO($supplier, $supplierID);
if($result == true)
{
$this->session->set_flashdata('success', 'PO updated successfully');
}
else
{
$this->session->set_flashdata('error', 'PO updation failed');
}
redirect('supplierListing');
}
}
}
/**
* This function is used to delete the user using userId
* @return boolean $result : TRUE / FALSE
*/
function deleteUser()
{
if($this->isAdmin() == TRUE)
{
echo(json_encode(array('status'=>'access')));
}
else
{
$userId = $this->input->post('userId');
$userInfo = array('isDeleted'=>1,'updatedBy'=>$this->vendorId, 'updatedDtm'=>date('Y-m-d H:i:sa'));
$result = $this->user_model->deleteUser($userId, $userInfo);
if ($result > 0) { echo(json_encode(array('status'=>TRUE))); }
else { echo(json_encode(array('status'=>FALSE))); }
}
}
function pageNotFound()
{
$this->global['pageTitle'] = 'CodeInsect : 404 - Page Not Found';
$this->loadViews("404", $this->global, NULL, NULL);
}
}
?>