455 lines
19 KiB
PHP
Executable File
455 lines
19 KiB
PHP
Executable File
<?php if(!defined('BASEPATH')) exit('No direct script access allowed');
|
|
|
|
require APPPATH . '/libraries/BaseController.php';
|
|
|
|
/**
|
|
* Class : RawMaterial (PurchaseorderController)
|
|
* User Class to control all user related operations.
|
|
* @author : Gandhimathi
|
|
* @version : 1.1
|
|
* @since : 12 Apr 2017
|
|
*/
|
|
class rawmaterialdetails extends BaseController
|
|
{
|
|
/**
|
|
* This is default constructor of the class
|
|
*/
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->load->model('rawmaterialdetails_model');
|
|
$this->load->library('pagination');
|
|
$this->load->library('form_validation');
|
|
$this->load->library('Excel');
|
|
|
|
$this->isLoggedIn();
|
|
}
|
|
/**
|
|
* This function used to load the first screen of the user
|
|
*/
|
|
public function index()
|
|
{
|
|
$this->global['pageTitle'] = 'Siddharth : RawMaterialDetails';
|
|
|
|
$this->loadViews("rawmaterialListing", $this->global, NULL , NULL);
|
|
}
|
|
|
|
/**
|
|
* This function is used to load the RawMaterialDetails list
|
|
*/
|
|
function rawmaterialListing()
|
|
{
|
|
|
|
$this->load->model('rawmaterialdetails_model');
|
|
|
|
$data['userRecords'] = $this->rawmaterialdetails_model->rawmaterialListing();
|
|
|
|
$this->global['pageTitle'] = 'Siddharth : RawMaterial Listing';
|
|
|
|
$this->loadViews("rawmaterialListing", $this->global, $data, NULL);
|
|
|
|
}
|
|
/**
|
|
* This function is used to load the add new cost */
|
|
function addRawMaterial()
|
|
{
|
|
|
|
$this->load->model('rawmaterialdetails_model');
|
|
$data['material'] = $this->rawmaterialdetails_model->getmaterialType();
|
|
$data['materialcategory'] = $this->rawmaterialdetails_model->getmaterialCategory();
|
|
$data['UOM'] = $this->rawmaterialdetails_model->getUOM();
|
|
$data['assetcode'] = $this->rawmaterialdetails_model->getAssetcode();
|
|
$data['costcentercode'] =$this->rawmaterialdetails_model->getcostcentercode();
|
|
$data['cfUOM'] = $this->rawmaterialdetails_model->getConversionfactorUOM();
|
|
$this->global['pageTitle'] = 'siddharth : AddNew RawMaterial';
|
|
$this->loadViews("addRawMaterial", $this->global, $data, NULL);
|
|
|
|
}
|
|
|
|
/* Validation for Material Type Dropdown */
|
|
function MaterialType_validate($selectValue)
|
|
{
|
|
//echo 'select_validate method called';
|
|
//'none' is the first option and the text says something like "-Choose one-"
|
|
if($selectValue == '-1')
|
|
{
|
|
$this->form_validation->set_message('MaterialType_validate', 'Please Select Material Type.');
|
|
return false;
|
|
}
|
|
else // user picked something
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
|
|
/* Validation for Material Type Dropdown */
|
|
function UOM_validate($selectValue)
|
|
{
|
|
//echo 'select_validate method called';
|
|
// 'none' is the first option and the text says something like "-Choose one-"
|
|
if($selectValue == '-1')
|
|
{
|
|
$this->form_validation->set_message('UOM_validate', 'Please Select UOM.');
|
|
return false;
|
|
}
|
|
else // user picked something
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
|
|
/* Validation for Material Category Dropdown */
|
|
function materialcategory_validate($selectValue)
|
|
{
|
|
|
|
if($selectValue == '0')
|
|
{
|
|
$this->form_validation->set_message('materialcategory_validate', 'Please Select Material Category.');
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
function addNewRawMaterial()
|
|
{
|
|
|
|
$this->form_validation->set_rules('MaterialName','Material Name','trim|required|');
|
|
$this->form_validation->set_rules('MaterialType','MaterialType','trim|callback_MaterialType_validate');
|
|
$this->form_validation->set_rules('MaterialCategory','MaterialCategory','trim|callback_materialcategory_validate');
|
|
$this->form_validation->set_rules('UOM','UOM','trim|callback_UOM_validate');
|
|
|
|
if($this->form_validation->run() == FALSE)
|
|
{
|
|
$this->addRawMaterial();
|
|
}
|
|
else
|
|
{
|
|
$MaterialName = $this->input->post('MaterialName');//print_r($MaterialName);
|
|
$MaterialType = $this->input->post('MaterialType');
|
|
$UOM = $this->input->post('UOM');
|
|
$MaterialCategory = $this->input->post('MaterialCategory');
|
|
$Remarks = $this->input->post('remarks');
|
|
$asset = $this->input->post('Assetcode');//print_r($AssetCode);
|
|
$costcentercode = $this->input->post('Costcenter');//print_r($CostCenterCode);
|
|
$ConversionFactor = $this->input->post('conversionfactor');
|
|
$cfuom = $this->input->post('conversionfactorUOM');//print_r( $ConversionFactorUOM);
|
|
$HSN = $this->input->post('HSNcode');//print_r($HSNcode);
|
|
$CreatedBy = $this->session->userdata('userId');
|
|
|
|
$chked = $this->input->post('isactive');
|
|
if($asset == '0')
|
|
{
|
|
$AssetCode = null;
|
|
}
|
|
else
|
|
{
|
|
$AssetCode = $asset;
|
|
}
|
|
if($costcentercode == '0')
|
|
{
|
|
$CostCenterCode = null;
|
|
}
|
|
else
|
|
{
|
|
$CostCenterCode = $costcentercode;
|
|
}
|
|
if($cfuom == '0')
|
|
{
|
|
$ConversionFactorUOM = null;
|
|
}
|
|
else
|
|
{
|
|
$ConversionFactorUOM = $cfuom;
|
|
}
|
|
if($HSN == '')
|
|
{
|
|
$HSNcode = null;
|
|
}
|
|
else
|
|
{
|
|
$HSNcode = $HSN;
|
|
}
|
|
|
|
|
|
if( $chked != '')
|
|
{
|
|
$IsActive = '1';
|
|
}
|
|
else
|
|
{
|
|
$IsActive = '0';
|
|
}
|
|
|
|
$RawMaterial = array('MaterialName'=>$MaterialName, 'MaterialType'=>$MaterialType, 'UOM'=>$UOM,'Category'=>$MaterialCategory, 'CreatedBy'=>$CreatedBy,'IsActive' => $IsActive,'assetcode'=>$AssetCode,'CostCenterCode'=>$CostCenterCode,'ConversionFactorUnit'=>$ConversionFactor,'ConversionFactorUOM'=>$ConversionFactorUOM,'Remarks'=>$Remarks,'HSNCODE'=>$HSNcode);
|
|
//print_r($RawMaterial);die();
|
|
$result = $this->rawmaterialdetails_model->addNewRawMaterial($RawMaterial);
|
|
|
|
if($result > 0)
|
|
{
|
|
|
|
|
|
echo "<script>alert('RawMaterial Created successfully!');</script>";redirect('rawmaterialListing','refresh');
|
|
|
|
}
|
|
else
|
|
{
|
|
|
|
echo "<script>alert('RawMaterial Not Created!');</script>";
|
|
redirect('rawmaterialListing','refresh');
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
function viewRawmaterial($RID= '')
|
|
{
|
|
$MaterialType = '';
|
|
$UOM = '';
|
|
$MaterialCategory = '';
|
|
|
|
|
|
if($RID == '')
|
|
{
|
|
$RawMaterialID = $_GET['RID'];
|
|
$MaterialType = $_GET['MType'];
|
|
$UOM = $_GET['UOM'];
|
|
}
|
|
else
|
|
{
|
|
$RawMaterialID = $RID;
|
|
}
|
|
|
|
$data['materialDetails'] = $this->rawmaterialdetails_model->getMaterialDetails($RawMaterialID);
|
|
$data['materialType'] = $this->rawmaterialdetails_model->getmaterialType($MaterialType );
|
|
$data['materialCategory'] = $this->rawmaterialdetails_model->getmaterialCategory($MaterialCategory);
|
|
$data['UOMList'] = $this->rawmaterialdetails_model->getUOM($UOM);
|
|
$data['costcentercode'] =$this->rawmaterialdetails_model->getCostCenterCode();
|
|
$data['cfUOM'] = $this->rawmaterialdetails_model->getConversionfactorUOM();
|
|
$data['assetcode'] = $this->rawmaterialdetails_model->getAssetcode();
|
|
$this->global['pageTitle'] = 'Siddharth : Edit Material Master';
|
|
$this->loadViews("editOldRawmaterial", $this->global,$data, NULL);
|
|
}
|
|
|
|
|
|
/**
|
|
* This function is used to edit the user information
|
|
*/
|
|
function editRawmaterial()
|
|
{
|
|
if($this->isAdmin() == TRUE)
|
|
{
|
|
$this->loadThis();
|
|
}
|
|
else
|
|
{
|
|
$RawmaterialID = $this->input->post('MaterialCode');
|
|
$this->form_validation->set_rules('MaterialName','Material Name','trim|required|');
|
|
$this->form_validation->set_rules('MaterialType','MaterialType','trim');
|
|
$this->form_validation->set_rules('UOM','UOM','trim');
|
|
|
|
|
|
if($this->form_validation->run() == FALSE)
|
|
{
|
|
$this->viewRawmaterial($RawmaterialID);
|
|
|
|
}
|
|
else
|
|
{
|
|
$MaterialCode = $this->input->post('MaterialCode');
|
|
$MaterialName = $this->input->post('MaterialName');
|
|
$MaterialType = $this->input->post('MaterialType');
|
|
$MaterialCategory =$this->input->post('MaterialCategory');
|
|
$UOM = $this->input->post('UOM');
|
|
$rmcode = $this->input->post('RMcode');
|
|
$Remarks = $this->input->post('remarks');
|
|
$asset = $this->input->post('Assetcode');
|
|
$costcentercode = $this->input->post('Costcenter');
|
|
$ConversionFactor = $this->input->post('conversionfactor');
|
|
$cfuom = $this->input->post('conversionfactorUOM');
|
|
$HSN = $this->input->post('HSNcode');
|
|
$UpdatedBy = $this->session->userdata ('userId');
|
|
$chked = $this->input->post('isactive');
|
|
if($asset == '0')
|
|
{
|
|
$AssetCode = null;
|
|
}
|
|
else
|
|
{
|
|
$AssetCode = $asset;
|
|
}
|
|
if($costcentercode == '0')
|
|
{
|
|
$CostCenterCode = null;
|
|
}
|
|
else
|
|
{
|
|
$CostCenterCode = $costcentercode;
|
|
}
|
|
if($cfuom == '0')
|
|
{
|
|
$ConversionFactorUOM = null;
|
|
}
|
|
else
|
|
{
|
|
$ConversionFactorUOM = $cfuom;
|
|
}
|
|
if($HSN == '')
|
|
{
|
|
$HSNcode = null;
|
|
}
|
|
else
|
|
{
|
|
$HSNcode = $HSN;
|
|
}
|
|
|
|
if( $chked != '')
|
|
{
|
|
$IsActive = '1';
|
|
}
|
|
else
|
|
{
|
|
$IsActive = '0';
|
|
}
|
|
|
|
$RawMaterial = array();
|
|
$RawMaterial = array('MaterialName'=>$MaterialName,'MaterialType'=>$MaterialType,'UpdatedBy'=>$UpdatedBy, 'UOM'=>$UOM,'IsActive' => $IsActive,'Category'=>$MaterialCategory,'ConversionFactorUnit'=>$ConversionFactor,'ConversionFactorUOM'=>$ConversionFactorUOM,'Remarks'=>$Remarks,'assetcode'=>$AssetCode,'CostCenterCode'=>$CostCenterCode,'HSNCODE'=>$HSNcode);//,'RMCode'=>$rmcode);
|
|
//print_r($RawMaterial);//die();
|
|
$result = $this->rawmaterialdetails_model->editRawmaterial($RawMaterial, $MaterialCode);
|
|
|
|
if($result == true)
|
|
{
|
|
echo "<script>alert('RawMaterial Updated successfully!');</script>"; redirect('rawmaterialListing','refresh');
|
|
}
|
|
else
|
|
{
|
|
|
|
echo "<script>alert('RawMaterial Record Not updated!');</script>";redirect('rawmaterialListing','refresh');
|
|
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
/** this function can be use for excel report **/
|
|
|
|
function export_material(){
|
|
|
|
|
|
$this->load->library('excel');
|
|
//$this->excel->setActiveSheetIndex(0)->mergeCells('D3:J3');
|
|
$this->excel->setActiveSheetIndex(0)->mergeCells('F3:M3');
|
|
$this->excel->setActiveSheetIndex(0)->getStyle('F3')->getAlignment()->applyFromArray(array('horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,));
|
|
|
|
$this->excel->getActiveSheet()->setTitle('Material Master');
|
|
|
|
$this->excel->getActiveSheet()->setCellValue('F3', 'SIDDHARTH INDUSTRIES Material Master');
|
|
$this->excel->getActiveSheet()->setCellValue('C5', 'MaterialCode');
|
|
$this->excel->getActiveSheet()->setCellValue('D5', 'MaterialName');
|
|
$this->excel->getActiveSheet()->setCellValue('E5', 'MaterialType');
|
|
$this->excel->getActiveSheet()->setCellValue('F5', 'UOM');
|
|
$this->excel->getActiveSheet()->setCellValue('G5', 'RMCode');
|
|
$this->excel->getActiveSheet()->setCellValue('H5', 'Category');
|
|
$this->excel->getActiveSheet()->setCellValue('I5', 'assetcode');
|
|
$this->excel->getActiveSheet()->setCellValue('J5', 'CostCenterCode');
|
|
$this->excel->getActiveSheet()->setCellValue('K5', 'ConversionFactorUnit');
|
|
$this->excel->getActiveSheet()->setCellValue('L5', 'ConversionFactorUOM');
|
|
$this->excel->getActiveSheet()->setCellValue('M5', 'HSNCode');
|
|
$this->excel->getActiveSheet()->setCellValue('N5', 'Remarks');
|
|
$this->excel->getActiveSheet()->setCellValue('O5', 'Created by');
|
|
$this->excel->getActiveSheet()->setCellValue('P5', 'Updated By');
|
|
$this->excel->getActiveSheet()->setCellValue('Q5', 'IsActive');
|
|
|
|
|
|
|
|
|
|
$this->excel->getActiveSheet()->getStyle('F3')->getFont()->setSize(14);
|
|
$this->excel->getActiveSheet()->getStyle('F3')->getFont()->setBold(true);
|
|
$this->excel->getActiveSheet()->getStyle('C5')->getFont()->setSize(12);
|
|
$this->excel->getActiveSheet()->getStyle('C5')->getFont()->setBold(true);
|
|
$this->excel->getActiveSheet()->getStyle('D5')->getFont()->setSize(12);
|
|
$this->excel->getActiveSheet()->getStyle('D5')->getFont()->setBold(true);
|
|
$this->excel->getActiveSheet()->getStyle('E5')->getFont()->setSize(12);
|
|
$this->excel->getActiveSheet()->getStyle('E5')->getFont()->setBold(true);
|
|
$this->excel->getActiveSheet()->getStyle('F5')->getFont()->setSize(12);
|
|
$this->excel->getActiveSheet()->getStyle('F5')->getFont()->setBold(true);
|
|
$this->excel->getActiveSheet()->getStyle('G5')->getFont()->setSize(12);
|
|
$this->excel->getActiveSheet()->getStyle('G5')->getFont()->setBold(true);
|
|
$this->excel->getActiveSheet()->getStyle('H5')->getFont()->setSize(12);
|
|
$this->excel->getActiveSheet()->getStyle('H5')->getFont()->setBold(true);
|
|
$this->excel->getActiveSheet()->getStyle('I5')->getFont()->setSize(12);
|
|
$this->excel->getActiveSheet()->getStyle('I5')->getFont()->setBold(true);
|
|
$this->excel->getActiveSheet()->getStyle('J5')->getFont()->setSize(12);
|
|
$this->excel->getActiveSheet()->getStyle('J5')->getFont()->setBold(true);
|
|
$this->excel->getActiveSheet()->getStyle('K5')->getFont()->setSize(12);
|
|
$this->excel->getActiveSheet()->getStyle('K5')->getFont()->setBold(true);
|
|
$this->excel->getActiveSheet()->getStyle('L5')->getFont()->setSize(12);
|
|
$this->excel->getActiveSheet()->getStyle('L5')->getFont()->setBold(true);
|
|
$this->excel->getActiveSheet()->getStyle('M5')->getFont()->setSize(12);
|
|
$this->excel->getActiveSheet()->getStyle('M5')->getFont()->setBold(true);
|
|
$this->excel->getActiveSheet()->getStyle('N5')->getFont()->setSize(12);
|
|
$this->excel->getActiveSheet()->getStyle('N5')->getFont()->setBold(true);
|
|
$this->excel->getActiveSheet()->getStyle('O5')->getFont()->setSize(12);
|
|
$this->excel->getActiveSheet()->getStyle('O5')->getFont()->setBold(true);
|
|
$this->excel->getActiveSheet()->getStyle('P5')->getFont()->setSize(12);
|
|
$this->excel->getActiveSheet()->getStyle('P5')->getFont()->setBold(true);
|
|
$this->excel->getActiveSheet()->getStyle('Q5')->getFont()->setSize(12);
|
|
$this->excel->getActiveSheet()->getStyle('Q5')->getFont()->setBold(true);
|
|
|
|
|
|
$exportData = $this->rawmaterialdetails_model->export_excel();
|
|
// print_r($exportData);die();
|
|
if ($exportData) {
|
|
$i = 6;
|
|
$s = 1;
|
|
foreach ($exportData as $data) {
|
|
|
|
$this->excel->getActiveSheet()->setCellValue('C' . $i,$data['MaterialCode']);
|
|
$this->excel->getActiveSheet()->setCellValue('D' . $i,$data['MaterialName']);
|
|
$this->excel->getActiveSheet()->setCellValue('E' . $i,$data['MaterialType']);
|
|
$this->excel->getActiveSheet()->setCellValue('F' . $i,$data['UOM']);
|
|
$this->excel->getActiveSheet()->setCellValue('G' . $i,$data['RMCode']);
|
|
$this->excel->getActiveSheet()->setCellValue('H' . $i,$data['Category']);
|
|
$this->excel->getActiveSheet()->setCellValue('I' . $i,$data['assetcode']);
|
|
$this->excel->getActiveSheet()->setCellValue('J' . $i,$data['CostCenterCode']);
|
|
$this->excel->getActiveSheet()->setCellValue('K' . $i,$data['ConversionFactorUnit']);
|
|
$this->excel->getActiveSheet()->setCellValue('L' . $i,$data['ConversionFactorUOM']);
|
|
$this->excel->getActiveSheet()->setCellValue('M' . $i,$data['HSNCODE']);
|
|
$this->excel->getActiveSheet()->setCellValue('N' . $i,$data['Remarks']);
|
|
$this->excel->getActiveSheet()->setCellValue('O' . $i,$data['firstname']);
|
|
$this->excel->getActiveSheet()->setCellValue('P' . $i,$data['Updated_By']);
|
|
$this->excel->getActiveSheet()->setCellValue('Q' . $i,$data['IsActive']);
|
|
|
|
|
|
$i++;
|
|
$s++;
|
|
}
|
|
}
|
|
|
|
$filename = 'MaterialMaster' .' '. '.xls'; //save our workbook as this file name
|
|
header('Content-Type: application/vnd.ms-excel'); //mime type
|
|
header('Content-Disposition: attachment;filename="' . $filename . '"'); //tell browser what's the file name
|
|
header('Cache-Control: max-age=0'); //no cache
|
|
$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');
|
|
if (ob_get_contents()) ob_end_clean();
|
|
ob_start();
|
|
$objWriter->save('php://output');
|
|
|
|
|
|
}
|
|
|
|
function pageNotFound()
|
|
{
|
|
$this->global['pageTitle'] = 'Siddharth : 404 - Page Not Found';
|
|
|
|
$this->loadViews("404", $this->global, NULL, NULL);
|
|
}
|
|
}
|
|
|
|
?>
|