siddharth_application/application/controllers/assetdetails.php

561 lines
22 KiB
PHP
Executable File

<?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 assetdetails extends BaseController
{
/**
* This is default constructor of the class
*/
public function __construct()
{
parent::__construct();
$this->load->model('assetdetails_model');
$this->load->library('form_validation');
$this->isLoggedIn();
}
/**
* This function used to load the first screen of the user
*/
public function index()
{
$this->global['pageTitle'] = 'Siddharth : Asset Details';
$this->loadViews("assetListing", $this->global, NULL , NULL);
}
/**
* This function is used to load the Supplier list
*/
function assetListing()
{
$this->load->model('assetdetails_model');
$data['userRecords'] = $this->assetdetails_model->assetListing();
$this->global['pageTitle'] = 'Siddharth : Asset List';
//print_r($data);die();
$this->loadViews("assetListing", $this->global, $data, NULL);
}
/**
* This function is used to load the add new supplier */
function addasset()
{
$data['AssetStatus'] = $this->assetdetails_model->getConfigValue('C015');
$data['po'] = $this->assetdetails_model->getPO();
//print_r($data);die();
$this->global['pageTitle'] = 'siddharth : Add Asset';
$this->loadViews("addasset", $this->global, $data, NULL);
}
function getpodetails()
{
$PO= $this->input->post('PONO');
$data = $this->assetdetails_model->getpodetails($PO);
//print_r($data);die();
$HTML = "<option value='0'>SelectMaterialCode</option>";
if(count($data) > 0)
{
for ($j = 0; $j < count($data); $j++)
{
$Code = $data[$j]->LineItemNo;
$Name = $data[$j]->MaterialCode;
$HTML .="<option value='".$Code."'>".$Code."-".$Name."</option>";
}
}
//echo $HTML;
die(json_encode(array($HTML)));
//echo json_encode($data);
//die();
}
function getline()
{
$line = $this->input->post('line');
$type = $this->assetdetails_model->gettyp($line);
$data='';
if(!empty($type)){
foreach($type as $item){
$data = $item->POType;
}
}
if($data=='SERVICE'){
$ser= $this->assetdetails_model->getlineitemser($line);
}
elseif($data=='REVENUE'){
$ser = $this->assetdetails_model->getlineitemre($line);
}
elseif($data=='IMPORT'){
$ser = $this->assetdetails_model->getlineitemimport($line);
}
elseif($data=='CAPITAL'){
$ser = $this->assetdetails_model->getlineitemcap($line);
}
//print_r($ser);die();
//print_r($data);die();
//$data = $this->getDateformat($data);
echo json_encode($ser);
die();
}
// function getlin(){
// $line = $this->input->post('line');
// }
/* Validation for Department Dropdown
*/
function Department_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('Department_validate', 'Please Select Department.');
return false;
}
else // user picked something
{
return true;
}
}
/* Validation for Supplier Dropdown
*/
function Supplier_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('Supplier_validate', 'Please Select Supplier.');
return false;
}
else // user picked something
{
return true;
}
}
/* Validation for Supplier Dropdown
*/
function Asset_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('Asset_validate', 'Please Select Asset Status.');
return false;
}
else // user picked something
{
return true;
}
}
/**
* This function is used to add new user to the system
*/
function addNewasset()
{
$this->form_validation->set_rules('AssetName','AssetName','trim|required');
//$this->form_validation->set_rules('Description','Description','trim|required');
$this->form_validation->set_rules('Department','Department','trim|callback_Department_validate');
$this->form_validation->set_rules('Location','Location','trim|required');
$this->form_validation->set_rules('User','User','trim|required');
$this->form_validation->set_rules('SupplierName','SupplierName','trim|callback_Supplier_validate');
$this->form_validation->set_rules('DateOfCommission','DateOfCommission','trim|required');
$this->form_validation->set_rules('Assetvalue','Assetvalue','trim|required');
$this->form_validation->set_rules('AssetStatus','AssetStatus','trim|callback_Asset_validate');
if($this->form_validation->run() == FALSE)
{
$this->addasset();
}
else
{
$AssetName = strtoupper($this->input->post('AssetName'));
$Description = $this->input->post('Description');
$Department = $this->input->post('AssetDept');
$Location = $this->input->post('Location');
$User = $this->input->post('User');
$SupplierName = $this->input->post('SupplierName');
$DateOfCommission = $this->input->post('DateOfCommission');
$CreatedBy = $this->session->userdata('userId');
$DateOfPurchase = $this->input->post('DateOfPurchase');
if($DateOfPurchase != '')
{
$DOpurchase = $this->getDateformat($DateOfPurchase);
}
$AssetValue = $this->input->post('Assetvalue');
if($DateOfCommission != '')
{
$DOCommission= $this->getDateformat($DateOfCommission);
//$DOCommission= $this->getDateformat($DateOfCommission);
}
$AssetStatus = $this->input->post('AssetStatus');
$Remarks = $this->input->post('Remarks');
$PONO = $this->input->post('PONO');
$lineitem = $this->input->post('lineitem');
$MaterialCode = $this->input->post('MaterialCode');
$Quantity = $this->input->post('Quantity');
$chked = $this->input->post('isactive');
if( $chked != '')
{
$IsActive = '1';
}
else
{
$IsActive = '0';
}
$asset = array();
$asset = array('AssetName'=>$AssetName, 'Description'=>$Description,'DEPCode'=>$Department,'Location'=>$Location,'UserName'=>$User,'SupplierCode'=>$SupplierName,'DateOfPurchase'=>$DOpurchase,'DateOfCommison'=>$DOCommission,'AssetValue'=>$AssetValue,'AssetStatus'=>$AssetStatus,'IsActive'=>$IsActive,'Remarks'=>$Remarks,'CreatedBy'=>$CreatedBy,'PONO'=>$PONO,'POLineItem'=>$lineitem,'MaterialCode'=>$MaterialCode,'Quantity'=>$Quantity);
$result = $this->assetdetails_model->addNewasset($asset);
if($result > 0)
{
// $this->session->set_flashdata('success', 'New Asset created successfully');
echo "<script>alert('Asset Created successfully!');</script>";
redirect('assetListing','refresh');
}
else
{
echo "<script>alert('Asset Not Created!');</script>";
redirect('assetListing','refresh');
}
}
}
/**
* This function is used load user edit information
* @param number $userId : Optional : This is user id
*/
/*function ech(){
echo $this->input->post('Asset_Code');
}*/
function editOldasset($AssetCode = '',$PO='')
{
$SupplierName = $this->input->post('SupplierName');
$AssetStatus = $this->input->post('AssetStatus');
$Department = $this->input->post('Department');
if($AssetCode == '')
{
$AssetID = $_GET['AssetID'];
}
else
{
$AssetID = $AssetCode;
}
//echo $AssetID;
$data['assetList'] = $this->assetdetails_model->getAssetDetails($AssetID);
// $data['SupplierList'] = $this->assetdetails_model->getSupplierName($SupplierName);
// $data['DepartmentList'] = $this->assetdetails_model->getDepartment($Department);
$data['AssetStatusList'] = $this->assetdetails_model->getConfigValue('C015');
$data['PO'] = $this->assetdetails_model->getPO($PO);
//print_r($data);die();
$this->global['pageTitle'] = 'Siddharth : Edit Asset';
$this->loadViews("editOldasset", $this->global, $data,NULL);
}
/**
* This function is used to edit the user information
*/
function editasset()
{
$Asset_Code = $this->input->post('AssetCode');
$this->form_validation->set_rules('AssetName','AssetName','trim|required');
$this->form_validation->set_rules('Description','Description','trim|required');
$this->form_validation->set_rules('Department','Department','trim|callback_Department_validate');
$this->form_validation->set_rules('Location','Location','trim|required');
$this->form_validation->set_rules('User','User','trim|required');
$this->form_validation->set_rules('SupplierName','SupplierName','trim|callback_Supplier_validate');
$this->form_validation->set_rules('DateOfCommission','DateOfCommission','trim|required');
$this->form_validation->set_rules('Assetvalue','Assetvalue','trim|required');
$this->form_validation->set_rules('AssetStatus','AssetStatus','trim|callback_Asset_validate');
if($this->form_validation->run() == FALSE)
{
$this->editOldasset($Asset_Code);
}
else
{
$Asset_Code = $this->input->post('AssetCode');
$AssetName = strtoupper( $this->input->post('AssetName'));
$Description = $this->input->post('Description');
$Department = $this->input->post('AssetDept');
$Location = $this->input->post('Location');
$User = $this->input->post('User');
$SupplierName = $this->input->post('SupplierName');
$DateOfPurchase = $this->input->post('DateOfPurchase');
if($DateOfPurchase != '')
{
$DOpurchase = $this->getDateformat($DateOfPurchase);
}
$DateOfCommission = $this->input->post('DateOfCommission');
$UpdatedBy = $this->session->userdata('userId');
$Assetvalue = $this->input->post('Assetvalue');
if($DateOfCommission != '')
{
$DOCommission= $this->getDateformat($DateOfCommission);
//$DOCommission= $this->dateformat($DateOfCommission);
}
$AssetStatus = $this->input->post('AssetStatus');
$Remarks = $this->input->post('Remarks');
$PONO = $this->input->post('PONO');
$lineitem = $this->input->post('lineitem');
$MaterialCode = $this->input->post('MaterialCode');
$Quantity = $this->input->post('Quantity');
$chked = $this->input->post('isactive');
if( $chked != '')
{
$IsActive = '1';
}
else
{
$IsActive = '0';
}
$asset = array();
$asset = array('AssetName'=>$AssetName, 'Description'=>$Description,'DEPCode'=>$Department,'Location'=>$Location,'UserName'=>$User,'SupplierCode'=>$SupplierName,'DateOfPurchase'=>$DOpurchase,'DateOfCommison'=>$DOCommission,'AssetValue'=>$Assetvalue,'AssetStatus'=>$AssetStatus,'IsActive'=>$IsActive,'Remarks'=>$Remarks,'UpdatedBy'=>$UpdatedBy,'PONO'=>$PONO,'POLineItem'=>$lineitem,'MaterialCode'=>$MaterialCode,'Quantity'=>$Quantity);
$result = $this->assetdetails_model->editasset($asset, $Asset_Code);
if($result == true)
{echo "<script>alert('Asset updated successfully!');</script>";
redirect('assetListing','refresh');
}
else
{echo "<script>alert('Asset Not updated !');</script>";
redirect('assetListing','refresh');
}
}
}
function getDateformat($Val)
{
$date = new DateTime($Val);
$retDate = $date->format('Y-m-d H:i:s');
return $retDate;
}
//this function used to dateformat to store in db
function dateformat($DateValue)
{
$date = DateTime::createFromFormat('d/m/Y', $DateValue);//we should give the date as per DatePicker format.
//if the date picker format is mismatched means it display as invalid date so that we can use this "IF" Conditions (i.e) If the above format returns false then the date is not formatted correctly
if ($date === false) {
return false;
//return null;
}
$retDate = $date->format('Y-m-d'); //in this line using the parsed date., we can create a new formatting for storing value to datebase ("we choosing date value based on datepicker")
// echo "<script>alert($retDate);</script>";
return $retDate;
}
function export_asset(){
$this->load->library('excel');
$this->excel->setActiveSheetIndex(0)->mergeCells('G3:M3');
$this->excel->setActiveSheetIndex(0)->getStyle('G3')->getAlignment()->applyFromArray(
array('horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,)
);
$this->excel->getActiveSheet()->setTitle('Asset Details');
$this->excel->getActiveSheet()->setCellValue('G3', 'SIDDHARTH INDUSTRIES Asset Details');
$this->excel->getActiveSheet()->setCellValue('C5', 'AssetCode');
$this->excel->getActiveSheet()->setCellValue('D5', 'AssetName');
$this->excel->getActiveSheet()->setCellValue('E5', 'AssetDescription');
$this->excel->getActiveSheet()->setCellValue('F5', 'DepartmentName');
$this->excel->getActiveSheet()->setCellValue('G5', 'Location');
$this->excel->getActiveSheet()->setCellValue('H5', 'PONO');
$this->excel->getActiveSheet()->setCellValue('I5', 'POLineItem');
$this->excel->getActiveSheet()->setCellValue('J5', 'MaterialName');
$this->excel->getActiveSheet()->setCellValue('K5', 'Quanity');
$this->excel->getActiveSheet()->setCellValue('L5', 'UserName');
$this->excel->getActiveSheet()->setCellValue('M5', 'SupplierName');
$this->excel->getActiveSheet()->setCellValue('N5', 'DateOfPurchase');
$this->excel->getActiveSheet()->setCellValue('O5', 'DateOfCommison');
$this->excel->getActiveSheet()->setCellValue('P5', 'AssetValue');
$this->excel->getActiveSheet()->setCellValue('Q5', 'AssetStatus');
$this->excel->getActiveSheet()->setCellValue('R5', 'IsActive');
$this->excel->getActiveSheet()->setCellValue('S5', 'Remarks');
$this->excel->getActiveSheet()->setCellValue('T5', 'CreatedBy');
$this->excel->getActiveSheet()->setCellValue('U5', 'UpdatedBy');
$this->excel->getActiveSheet()->getStyle('G3')->getFont()->setSize(14);
$this->excel->getActiveSheet()->getStyle('G3')->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);
$this->excel->getActiveSheet()->getStyle('R5')->getFont()->setSize(12);
$this->excel->getActiveSheet()->getStyle('R5')->getFont()->setBold(true);
$this->excel->getActiveSheet()->getStyle('S5')->getFont()->setSize(12);
$this->excel->getActiveSheet()->getStyle('S5')->getFont()->setBold(true);
$this->excel->getActiveSheet()->getStyle('T5')->getFont()->setSize(12);
$this->excel->getActiveSheet()->getStyle('T5')->getFont()->setBold(true);
$this->excel->getActiveSheet()->getStyle('U5')->getFont()->setSize(12);
$this->excel->getActiveSheet()->getStyle('U5')->getFont()->setBold(true);
$exportData = $this->assetdetails_model->export_excel();
//print_r($exportData);die();
if ($exportData) {
$i = 6;
$s = 1;
foreach ($exportData as $data) {
$this->excel->getActiveSheet()->setCellValue('C'. $i,$data['AssetCode']);
$this->excel->getActiveSheet()->setCellValue('D'. $i,$data[ 'AssetName']);
$this->excel->getActiveSheet()->setCellValue('E'. $i,$data[ 'Description']);
$this->excel->getActiveSheet()->setCellValue('F'. $i,$data[ 'DEPCode']);
$this->excel->getActiveSheet()->setCellValue('G'. $i,$data[ 'Location']);
$this->excel->getActiveSheet()->setCellValue('H'. $i,$data[ 'PONO']);
$this->excel->getActiveSheet()->setCellValue('I'. $i,$data[ 'POLineItem']);
$this->excel->getActiveSheet()->setCellValue('J'. $i,$data[ 'MaterialName']);
$this->excel->getActiveSheet()->setCellValue('K'. $i,$data[ 'Quantity']);
$this->excel->getActiveSheet()->setCellValue('L'. $i,$data[ 'UserName']);
$this->excel->getActiveSheet()->setCellValue('M'. $i,$data[ 'SupplierName']);
$this->excel->getActiveSheet()->setCellValue('N'. $i,$data[ 'DateOfPurchase']);
$this->excel->getActiveSheet()->setCellValue('O'. $i,$data[ 'DateOfCommison']);
$this->excel->getActiveSheet()->setCellValue('P'. $i,$data[ 'AssetValue']);
$this->excel->getActiveSheet()->setCellValue('Q'. $i,$data[ 'AssetStatus']);
$this->excel->getActiveSheet()->setCellValue('R'. $i,$data[ 'IsActive']);
$this->excel->getActiveSheet()->setCellValue('S'. $i,$data[ 'Remarks']);
$this->excel->getActiveSheet()->setCellValue('T'. $i,$data[ 'firstname']);
$this->excel->getActiveSheet()->setCellValue('U'. $i,$data[ 'Updated_By']);
$i++;
$s++;
}
}
$filename = 'Asset_details' .' '. '.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'] = 'CodeInsect : 404 - Page Not Found';
$this->loadViews("404", $this->global, NULL, NULL);
}
}
?>